From 8276fd407efc9333f1990dbd9c99865d922ecac3 Mon Sep 17 00:00:00 2001 From: William Calderipe Date: Fri, 19 Jan 2024 11:20:33 +0100 Subject: [PATCH 1/2] Code static analysis per project (#21) * Add make recipe to lint & format code per project * Format the whole codebase * Remove main Makefile from CIs trigger target files * Fix orchestration E2E tests --- .github/dependabot.yml | 6 +- .github/workflows/authz_ci.yml | 9 +- .github/workflows/authz_shared_ci.yml | 12 +- .github/workflows/orchestration_ci.yml | 9 +- .../transaction_request_intent_ci.yml | 12 +- Makefile | 17 ++- apps/authz/Makefile | 14 ++ apps/authz/README.md | 10 ++ apps/authz/src/app/opa/poc/entities.json | 130 +++++++++--------- .../opa/poc/input_admin_transfer_token.json | 86 ++++++------ .../meta_permissions/user_permissions.json | 44 +++--- apps/documentation/babel.config.js | 4 +- .../docs/tutorial-basics/create-a-document.md | 8 +- .../docs/tutorial-basics/create-a-page.md | 6 +- .../tutorial-basics/markdown-features.mdx | 13 +- .../tutorial-extras/manage-docs-versions.md | 12 +- .../tutorial-extras/translate-your-site.md | 18 +-- apps/documentation/project.json | 2 +- .../src/components/HomepageFeatures/index.tsx | 42 +++--- apps/documentation/src/pages/index.tsx | 30 ++-- apps/orchestration/Makefile | 14 ++ apps/orchestration/README.md | 12 +- .../policy-engine/__test__/e2e/facade.spec.ts | 1 - .../rest/dto/sign-transaction-request.dto.ts | 17 ++- .../schema/sign-transaction-request.schema.ts | 2 +- apps/orchestration/tsconfig.spec.json | 7 +- apps/orchestration/webpack.config.js | 6 +- doc/prefixed-test-ethereum-accounts.md | 26 ++-- packages/authz-shared/Makefile | 16 +++ packages/authz-shared/README.md | 10 ++ .../tsconfig.spec.json | 7 +- packages/transaction-request-intent/Makefile | 20 ++- packages/transaction-request-intent/README.md | 10 ++ 33 files changed, 360 insertions(+), 272 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index aff82a102..db9ba4179 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,6 +1,6 @@ version: 2 updates: - - package-ecosystem: "npm" - directory: "/" + - package-ecosystem: 'npm' + directory: '/' schedule: - interval: "weekly" + interval: 'weekly' diff --git a/.github/workflows/authz_ci.yml b/.github/workflows/authz_ci.yml index 28b1304bb..3209a0a37 100644 --- a/.github/workflows/authz_ci.yml +++ b/.github/workflows/authz_ci.yml @@ -1,11 +1,10 @@ -name: "@app/authz CI" +name: '@app/authz CI' on: push: paths: - apps/authz/** - .github/workflows/authz_ci.yml - - Makefile - jest.config.ts - jest.preset.js - .eslintrc.json @@ -60,8 +59,8 @@ jobs: - name: Code format shell: bash run: | - make format/check - make lint/check + make authz/format/check + make authz/lint/check # TODO: Finish once the authz-node has a database. - name: Setup database and Prisma types @@ -101,7 +100,7 @@ jobs: uses: 8398a7/action-slack@v3 with: username: GitHub - author_name: "@app/authz CI failed" + author_name: '@app/authz CI failed' status: ${{ job.status }} fields: message,commit,author env: diff --git a/.github/workflows/authz_shared_ci.yml b/.github/workflows/authz_shared_ci.yml index 734e55158..7cf90011c 100644 --- a/.github/workflows/authz_shared_ci.yml +++ b/.github/workflows/authz_shared_ci.yml @@ -1,11 +1,10 @@ -name: "@narval/authz-shared CI" +name: '@narval/authz-shared CI' on: push: paths: - packages/authz-shared/** - .github/workflows/authz_shared_ci.yml - - Makefile - jest.config.ts - jest.preset.js - .eslintrc.json @@ -35,22 +34,21 @@ jobs: - name: Code format shell: bash run: | - make format/check - make lint/check + make authz-shared/format/check + make authz-shared/lint/check - name: Test unit shell: bash run: | - make authz-shared/test/unit + make authz-shared/test/unit - name: Send Slack notification on failure if: failure() uses: 8398a7/action-slack@v3 with: username: GitHub - author_name: "@narval/authz-shared CI failed" + author_name: '@narval/authz-shared CI failed' status: ${{ job.status }} fields: message,commit,author env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} - diff --git a/.github/workflows/orchestration_ci.yml b/.github/workflows/orchestration_ci.yml index 1638aa7e8..72514eb66 100644 --- a/.github/workflows/orchestration_ci.yml +++ b/.github/workflows/orchestration_ci.yml @@ -1,11 +1,10 @@ -name: "@app/orchestration CI" +name: '@app/orchestration CI' on: push: paths: - apps/orchestration/** - .github/workflows/orchestration_ci.yml - - Makefile - jest.config.ts - jest.preset.js - .eslintrc.json @@ -60,8 +59,8 @@ jobs: - name: Code format shell: bash run: | - make format/check - make lint/check + make orchestration/format/check + make orchestration/lint/check - name: Setup database and Prisma types shell: bash @@ -97,7 +96,7 @@ jobs: uses: 8398a7/action-slack@v3 with: username: GitHub - author_name: "@app/orchestration CI failed" + author_name: '@app/orchestration CI failed' status: ${{ job.status }} fields: message,commit,author env: diff --git a/.github/workflows/transaction_request_intent_ci.yml b/.github/workflows/transaction_request_intent_ci.yml index f5ce5b95a..37821583c 100644 --- a/.github/workflows/transaction_request_intent_ci.yml +++ b/.github/workflows/transaction_request_intent_ci.yml @@ -1,11 +1,10 @@ -name: "@narval/transaction-request-intent CI" +name: '@narval/transaction-request-intent CI' on: push: paths: - packages/transaction-request-intent/** - .github/workflows/transaction_request_intent_ci.yml - - Makefile - jest.config.ts - jest.preset.js - .eslintrc.json @@ -35,22 +34,21 @@ jobs: - name: Code format shell: bash run: | - make format/check - make lint/check + make transaction-request-intent/format/check + make transaction-request-intent/lint/check - name: Test unit shell: bash run: | - make transaction-request-intent/test/unit + make transaction-request-intent/test/unit - name: Send Slack notification on failure if: failure() uses: 8398a7/action-slack@v3 with: username: GitHub - author_name: "@narval/transaction-request-intent CI failed" + author_name: '@narval/transaction-request-intent CI failed' status: ${{ job.status }} fields: message,commit,author env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} - diff --git a/Makefile b/Makefile index 5839b060f..521c228c9 100644 --- a/Makefile +++ b/Makefile @@ -7,12 +7,16 @@ include ./packages/transaction-request-intent/Makefile TERM_NO_COLOR := \033[0m TERM_GREEN := \033[0;32m +# == Install == + install: npm install install/ci: npm ci +# == Setup == + setup: make install make docker/up @@ -22,19 +26,21 @@ setup: @echo "${TERM_GREEN}Orchestration & AuthZ applications are ready 🐋${TERM_NO_COLOR}" @echo "${TERM_GREEN}Run 'make orchestration/start/dev' or/and 'make authz/start/dev' to get them running.${TERM_NO_COLOR}" +# == Docker == + docker/stop: docker-compose stop docker/up: docker-compose up --detach +# == Code format == + format: - npx prettier \ - --write "apps/**/*.ts" "packages/**/*.ts" "./*.{js,json}" + npx nx format:write --all format/check: - npx prettier \ - --check "apps/**/*.ts" "packages/**/*.ts" "./*.{js,json}" + npx nx format:check --all lint: npx nx run-many \ @@ -42,5 +48,4 @@ lint: --fix lint/check: - npx nx run-many \ - --target lint + npx nx run-many --target lint diff --git a/apps/authz/Makefile b/apps/authz/Makefile index 2a9a633d3..b04f29aaa 100644 --- a/apps/authz/Makefile +++ b/apps/authz/Makefile @@ -15,6 +15,20 @@ authz/copy-default-env: cp ${AUTHZ_PROJECT_DIR}/.env.default ${AUTHZ_PROJECT_DIR}/.env cp ${AUTHZ_PROJECT_DIR}/.env.test.default ${AUTHZ_PROJECT_DIR}/.env.test +# == Code format == + +authz/format: + npx nx format:write --projects ${AUTHZ_PROJECT_NAME} + +authz/lint: + npx nx lint ${AUTHZ_PROJECT_NAME} -- --fix + +authz/format/check: + npx nx format:check --projects ${AUTHZ_PROJECT_NAME} + +authz/lint/check: + npx nx lint ${AUTHZ_PROJECT_NAME} + # === Testing === authz/test/type: diff --git a/apps/authz/README.md b/apps/authz/README.md index f7cf789c6..c026c2ad8 100644 --- a/apps/authz/README.md +++ b/apps/authz/README.md @@ -24,3 +24,13 @@ make authz/test/unit make authz/test/integration make authz/test/e2e ``` + +## Formatting + +```bash +make authz/format +make authz/lint + +make authz/format/check +make authz/lint/check +``` diff --git a/apps/authz/src/app/opa/poc/entities.json b/apps/authz/src/app/opa/poc/entities.json index 23d384213..9e41557da 100644 --- a/apps/authz/src/app/opa/poc/entities.json +++ b/apps/authz/src/app/opa/poc/entities.json @@ -1,65 +1,69 @@ { - "entities":{ - "users": { - "test-bob-uid": { - "uid": "test-bob-uid", - "role": "root" - }, - "test-alice-uid": { - "uid": "test-alice-uid", - "role": "member" - }, - "test-foo-uid": { - "uid": "test-foo-uid", - "role": "admin" - }, - "0xaaa8ee1cbaa1856f4550c6fc24abb16c5c9b2a43": { - "uid": "0xaaa8ee1cbaa1856f4550c6fc24abb16c5c9b2a43", - "role": "admin" - } - }, - "wallets": {"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e": { - "uid": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", - "address": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", - "accountType": "eoa", - "assignees": ["test-bob-uid", "test-bar-uid"] - }}, - "user_groups": { - "test-user-group-one-uid": { - "uid": "test-user-group-one-uid", - "name": "dev", - "users": ["test-bob-uid", "test-bar-uid"] - }, - "test-user-group-two-uid": { - "uid": "test-user-group-two-uid", - "name": "finance", - "users": ["test-bob-uid", "test-bar-uid"] - } - }, - "wallet_groups": {"test-wallet-group-one-uid": { - "uid": "test-wallet-group-one-uid", - "name": "dev", - "wallets": ["eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"] - }}, - "address_book": { - "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3": { - "uid": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3", - "address": "0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3", - "chain_id": 137, - "classification": "internal" - }, - "eip155:137:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e": { - "uid": "eip155:137:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", - "address": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", - "chain_id": 137, - "classification": "wallet" - }, - "eip155:1:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e": { - "uid": "eip155:1:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", - "address": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", - "chain_id": 1, - "classification": "wallet" - } - } + "entities": { + "users": { + "test-bob-uid": { + "uid": "test-bob-uid", + "role": "root" + }, + "test-alice-uid": { + "uid": "test-alice-uid", + "role": "member" + }, + "test-foo-uid": { + "uid": "test-foo-uid", + "role": "admin" + }, + "0xaaa8ee1cbaa1856f4550c6fc24abb16c5c9b2a43": { + "uid": "0xaaa8ee1cbaa1856f4550c6fc24abb16c5c9b2a43", + "role": "admin" + } + }, + "wallets": { + "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e": { + "uid": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", + "address": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", + "accountType": "eoa", + "assignees": ["test-bob-uid", "test-bar-uid"] + } + }, + "user_groups": { + "test-user-group-one-uid": { + "uid": "test-user-group-one-uid", + "name": "dev", + "users": ["test-bob-uid", "test-bar-uid"] + }, + "test-user-group-two-uid": { + "uid": "test-user-group-two-uid", + "name": "finance", + "users": ["test-bob-uid", "test-bar-uid"] + } + }, + "wallet_groups": { + "test-wallet-group-one-uid": { + "uid": "test-wallet-group-one-uid", + "name": "dev", + "wallets": ["eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"] + } + }, + "address_book": { + "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3": { + "uid": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3", + "address": "0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3", + "chain_id": 137, + "classification": "internal" + }, + "eip155:137:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e": { + "uid": "eip155:137:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", + "address": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", + "chain_id": 137, + "classification": "wallet" + }, + "eip155:1:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e": { + "uid": "eip155:1:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", + "address": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", + "chain_id": 1, + "classification": "wallet" + } } -} \ No newline at end of file + } +} diff --git a/apps/authz/src/app/opa/poc/input_admin_transfer_token.json b/apps/authz/src/app/opa/poc/input_admin_transfer_token.json index a7445df3b..cbba4df8c 100644 --- a/apps/authz/src/app/opa/poc/input_admin_transfer_token.json +++ b/apps/authz/src/app/opa/poc/input_admin_transfer_token.json @@ -1,52 +1,52 @@ { "action": "signTransaction", - "principal": {"uid": "test-bob-uid"}, - "resource": {"uid": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}, + "principal": { "uid": "test-bob-uid" }, + "resource": { "uid": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e" }, "request": { - "type": "eip1559", - "chain_id": 137, - "max_fee_per_gas": "20000000000", - "max_priority_fee_per_gas": "3000000000", - "gas": "21000", - "nonce": 1, - "from": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", - "to": "0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3" + "type": "eip1559", + "chain_id": 137, + "max_fee_per_gas": "20000000000", + "max_priority_fee_per_gas": "3000000000", + "gas": "21000", + "nonce": 1, + "from": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", + "to": "0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3" }, "intent": { - "type": "transferToken", - "from": { - "uid": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", - "address": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e" - }, - "to": { - "uid": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3", - "chain_id": 137, - "address": "0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3" - }, - "amount": 1000000000000000000, - "token": { - "uid": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174", - "address": "0x2791bca1f2de4661ed88a30c99a7a9449aa84174", - "chainId": 137, - "classification": "internal" - } + "type": "transferToken", + "from": { + "uid": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", + "address": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e" + }, + "to": { + "uid": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3", + "chain_id": 137, + "address": "0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3" + }, + "amount": 1000000000000000000, + "token": { + "uid": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174", + "address": "0x2791bca1f2de4661ed88a30c99a7a9449aa84174", + "chainId": 137, + "classification": "internal" + } }, "signatures": [ - { - "signer": "test-bob-uid", - "hash": "0x894ee391f2fb86469042159c46084add956d1d1f997bb4c43d9c8d2a52970a615b790c416077ec5d199ede5ae0fc925859c80c52c5c74328e25d9e9d5195e3981c" - }, - { - "signer": "test-alice-uid", - "hash": "0x894ee391f2fb86469042159c46084add956d1d1f997bb4c43d9c8d2a52970a615b790c416077ec5d199ede5ae0fc925859c80c52c5c74328e25d9e9d5195e3981c" - }, - { - "signer": "test-foo-uid", - "hash": "0x894ee391f2fb86469042159c46084add956d1d1f997bb4c43d9c8d2a52970a615b790c416077ec5d199ede5ae0fc925859c80c52c5c74328e25d9e9d5195e3981c" - }, - { - "signer": "0xaaa8ee1cbaa1856f4550c6fc24abb16c5c9b2a43", - "hash": "0x894ee391f2fb86469042159c46084add956d1d1f997bb4c43d9c8d2a52970a615b790c416077ec5d199ede5ae0fc925859c80c52c5c74328e25d9e9d5195e3981c" - } + { + "signer": "test-bob-uid", + "hash": "0x894ee391f2fb86469042159c46084add956d1d1f997bb4c43d9c8d2a52970a615b790c416077ec5d199ede5ae0fc925859c80c52c5c74328e25d9e9d5195e3981c" + }, + { + "signer": "test-alice-uid", + "hash": "0x894ee391f2fb86469042159c46084add956d1d1f997bb4c43d9c8d2a52970a615b790c416077ec5d199ede5ae0fc925859c80c52c5c74328e25d9e9d5195e3981c" + }, + { + "signer": "test-foo-uid", + "hash": "0x894ee391f2fb86469042159c46084add956d1d1f997bb4c43d9c8d2a52970a615b790c416077ec5d199ede5ae0fc925859c80c52c5c74328e25d9e9d5195e3981c" + }, + { + "signer": "0xaaa8ee1cbaa1856f4550c6fc24abb16c5c9b2a43", + "hash": "0x894ee391f2fb86469042159c46084add956d1d1f997bb4c43d9c8d2a52970a615b790c416077ec5d199ede5ae0fc925859c80c52c5c74328e25d9e9d5195e3981c" + } ] } diff --git a/apps/authz/src/app/opa/poc/meta_permissions/user_permissions.json b/apps/authz/src/app/opa/poc/meta_permissions/user_permissions.json index 17416386f..b9b9aa9ee 100644 --- a/apps/authz/src/app/opa/poc/meta_permissions/user_permissions.json +++ b/apps/authz/src/app/opa/poc/meta_permissions/user_permissions.json @@ -1,25 +1,25 @@ { - "action": "user:create", - "principal": { - "uid": "0xbbb7be636c3ad8cf9d08ba8bdba4abd2ef29bd23" + "action": "user:create", + "principal": { + "uid": "0xbbb7be636c3ad8cf9d08ba8bdba4abd2ef29bd23" + }, + "resource": { + "user": { + "uid": "0xaaa8ee1cbaa1856f4550c6fc24abb16c5c9b2a43" + } + }, + "signatures": [ + { + "signer": "0x54d48e47e85e5dec57fa913c4c4f6e74fe3cc930", + "hash": "0x894ee391f2fb86469042159c46084add956d1d1f997bb4c43d9c8d2a52970a615b790c416077ec5d199ede5ae0fc925859c80c52c5c74328e25d9e9d5195e3981c" }, - "resource": { - "user": { - "uid": "0xaaa8ee1cbaa1856f4550c6fc24abb16c5c9b2a43" - } + { + "signer": "0xf0938535e0d64f1e148676adf6f0d82662d778a1", + "hash": "0x894ee391f2fb86469042159c46084add956d1d1f997bb4c43d9c8d2a52970a615b790c416077ec5d199ede5ae0fc925859c80c52c5c74328e25d9e9d5195e3981c" }, - "signatures": [ - { - "signer": "0x54d48e47e85e5dec57fa913c4c4f6e74fe3cc930", - "hash": "0x894ee391f2fb86469042159c46084add956d1d1f997bb4c43d9c8d2a52970a615b790c416077ec5d199ede5ae0fc925859c80c52c5c74328e25d9e9d5195e3981c" - }, - { - "signer": "0xf0938535e0d64f1e148676adf6f0d82662d778a1", - "hash": "0x894ee391f2fb86469042159c46084add956d1d1f997bb4c43d9c8d2a52970a615b790c416077ec5d199ede5ae0fc925859c80c52c5c74328e25d9e9d5195e3981c" - }, - { - "signer": "0xbbb7be636c3ad8cf9d08ba8bdba4abd2ef29bd23", - "hash": "0x894ee391f2fb86469042159c46084add956d1d1f997bb4c43d9c8d2a52970a615b790c416077ec5d199ede5ae0fc925859c80c52c5c74328e25d9e9d5195e3981c" - } - ] - } \ No newline at end of file + { + "signer": "0xbbb7be636c3ad8cf9d08ba8bdba4abd2ef29bd23", + "hash": "0x894ee391f2fb86469042159c46084add956d1d1f997bb4c43d9c8d2a52970a615b790c416077ec5d199ede5ae0fc925859c80c52c5c74328e25d9e9d5195e3981c" + } + ] +} diff --git a/apps/documentation/babel.config.js b/apps/documentation/babel.config.js index e00595dae..14e5baf05 100644 --- a/apps/documentation/babel.config.js +++ b/apps/documentation/babel.config.js @@ -1,3 +1,3 @@ module.exports = { - presets: [require.resolve('@docusaurus/core/lib/babel/preset')], -}; + presets: [require.resolve('@docusaurus/core/lib/babel/preset')] +} diff --git a/apps/documentation/docs/tutorial-basics/create-a-document.md b/apps/documentation/docs/tutorial-basics/create-a-document.md index c22fe2944..f33028a36 100644 --- a/apps/documentation/docs/tutorial-basics/create-a-document.md +++ b/apps/documentation/docs/tutorial-basics/create-a-document.md @@ -50,8 +50,8 @@ export default { { type: 'category', label: 'Tutorial', - items: ['tutorial-basics/create-a-document'], - }, - ], -}; + items: ['tutorial-basics/create-a-document'] + } + ] +} ``` diff --git a/apps/documentation/docs/tutorial-basics/create-a-page.md b/apps/documentation/docs/tutorial-basics/create-a-page.md index 20e2ac300..36f46ce0c 100644 --- a/apps/documentation/docs/tutorial-basics/create-a-page.md +++ b/apps/documentation/docs/tutorial-basics/create-a-page.md @@ -15,8 +15,8 @@ Add **Markdown or React** files to `src/pages` to create a **standalone page**: Create a file at `src/pages/my-react-page.js`: ```jsx title="src/pages/my-react-page.js" -import React from 'react'; -import Layout from '@theme/Layout'; +import React from 'react' +import Layout from '@theme/Layout' export default function MyReactPage() { return ( @@ -24,7 +24,7 @@ export default function MyReactPage() {

My React page

This is a React page

- ); + ) } ``` diff --git a/apps/documentation/docs/tutorial-basics/markdown-features.mdx b/apps/documentation/docs/tutorial-basics/markdown-features.mdx index 0337f34d6..200e6310a 100644 --- a/apps/documentation/docs/tutorial-basics/markdown-features.mdx +++ b/apps/documentation/docs/tutorial-basics/markdown-features.mdx @@ -71,7 +71,7 @@ Markdown code blocks are supported with Syntax highlighting. ```jsx title="src/components/HelloDocusaurus.js" function HelloDocusaurus() { - return

Hello, Docusaurus!

; + return

Hello, Docusaurus!

} ``` @@ -129,21 +129,22 @@ This is Docusaurus green ! This is Facebook blue ! ``` -export const Highlight = ({children, color}) => ( +export const Highlight = ({ children, color }) => ( { - alert(`You clicked the color ${color} with label ${children}`); - }}> + alert(`You clicked the color ${color} with label ${children}`) + }} + > {children} -); +) This is Docusaurus green ! diff --git a/apps/documentation/docs/tutorial-extras/manage-docs-versions.md b/apps/documentation/docs/tutorial-extras/manage-docs-versions.md index ccda0b907..5c00b5cd3 100644 --- a/apps/documentation/docs/tutorial-extras/manage-docs-versions.md +++ b/apps/documentation/docs/tutorial-extras/manage-docs-versions.md @@ -34,13 +34,13 @@ export default { items: [ // highlight-start { - type: 'docsVersionDropdown', - }, + type: 'docsVersionDropdown' + } // highlight-end - ], - }, - }, -}; + ] + } + } +} ``` The docs version dropdown appears in your navbar: diff --git a/apps/documentation/docs/tutorial-extras/translate-your-site.md b/apps/documentation/docs/tutorial-extras/translate-your-site.md index b5a644abd..598b6737b 100644 --- a/apps/documentation/docs/tutorial-extras/translate-your-site.md +++ b/apps/documentation/docs/tutorial-extras/translate-your-site.md @@ -14,9 +14,9 @@ Modify `docusaurus.config.js` to add support for the `fr` locale: export default { i18n: { defaultLocale: 'en', - locales: ['en', 'fr'], - }, -}; + locales: ['en', 'fr'] + } +} ``` ## Translate a doc @@ -60,13 +60,13 @@ export default { items: [ // highlight-start { - type: 'localeDropdown', - }, + type: 'localeDropdown' + } // highlight-end - ], - }, - }, -}; + ] + } + } +} ``` The locale dropdown now appears in your navbar: diff --git a/apps/documentation/project.json b/apps/documentation/project.json index f1d776fbf..ca8f7f6ac 100644 --- a/apps/documentation/project.json +++ b/apps/documentation/project.json @@ -13,7 +13,7 @@ "serve": { "executor": "@nx-plus/docusaurus:dev-server", "options": { - "port": 3003 + "port": 3003 } } }, diff --git a/apps/documentation/src/components/HomepageFeatures/index.tsx b/apps/documentation/src/components/HomepageFeatures/index.tsx index 50a9e6f4c..f109ce59c 100644 --- a/apps/documentation/src/components/HomepageFeatures/index.tsx +++ b/apps/documentation/src/components/HomepageFeatures/index.tsx @@ -1,12 +1,12 @@ -import clsx from 'clsx'; -import Heading from '@theme/Heading'; -import styles from './styles.module.css'; +import Heading from '@theme/Heading' +import clsx from 'clsx' +import styles from './styles.module.css' type FeatureItem = { - title: string; - Svg: React.ComponentType>; - description: JSX.Element; -}; + title: string + Svg: React.ComponentType> + description: JSX.Element +} const FeatureList: FeatureItem[] = [ { @@ -14,34 +14,34 @@ const FeatureList: FeatureItem[] = [ Svg: require('@site/static/img/undraw_docusaurus_mountain.svg').default, description: ( <> - Docusaurus was designed from the ground up to be easily installed and - used to get your website up and running quickly. + Docusaurus was designed from the ground up to be easily installed and used to get your website up and running + quickly. - ), + ) }, { title: 'Focus on What Matters', Svg: require('@site/static/img/undraw_docusaurus_tree.svg').default, description: ( <> - Docusaurus lets you focus on your docs, and we'll do the chores. Go - ahead and move your docs into the docs directory. + Docusaurus lets you focus on your docs, and we'll do the chores. Go ahead and move your docs into the{' '} + docs directory. - ), + ) }, { title: 'Powered by React', Svg: require('@site/static/img/undraw_docusaurus_react.svg').default, description: ( <> - Extend or customize your website layout by reusing React. Docusaurus can - be extended while reusing the same header and footer. + Extend or customize your website layout by reusing React. Docusaurus can be extended while reusing the same + header and footer. - ), - }, -]; + ) + } +] -function Feature({title, Svg, description}: FeatureItem) { +function Feature({ title, Svg, description }: FeatureItem) { return (
@@ -52,7 +52,7 @@ function Feature({title, Svg, description}: FeatureItem) {

{description}

- ); + ) } export default function HomepageFeatures(): JSX.Element { @@ -66,5 +66,5 @@ export default function HomepageFeatures(): JSX.Element { - ); + ) } diff --git a/apps/documentation/src/pages/index.tsx b/apps/documentation/src/pages/index.tsx index 400a3e19a..4bca319f1 100644 --- a/apps/documentation/src/pages/index.tsx +++ b/apps/documentation/src/pages/index.tsx @@ -1,14 +1,14 @@ -import clsx from 'clsx'; -import Link from '@docusaurus/Link'; -import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; -import Layout from '@theme/Layout'; -import HomepageFeatures from '@site/src/components/HomepageFeatures'; -import Heading from '@theme/Heading'; +import Link from '@docusaurus/Link' +import useDocusaurusContext from '@docusaurus/useDocusaurusContext' +import HomepageFeatures from '@site/src/components/HomepageFeatures' +import Heading from '@theme/Heading' +import Layout from '@theme/Layout' +import clsx from 'clsx' -import styles from './index.module.css'; +import styles from './index.module.css' function HomepageHeader() { - const {siteConfig} = useDocusaurusContext(); + const { siteConfig } = useDocusaurusContext() return (
@@ -17,27 +17,23 @@ function HomepageHeader() {

{siteConfig.tagline}

- + Docusaurus Tutorial - 5min ⏱️
- ); + ) } export default function Home(): JSX.Element { - const {siteConfig} = useDocusaurusContext(); + const { siteConfig } = useDocusaurusContext() return ( - +
- ); + ) } diff --git a/apps/orchestration/Makefile b/apps/orchestration/Makefile index 01029a0dd..20112c818 100644 --- a/apps/orchestration/Makefile +++ b/apps/orchestration/Makefile @@ -18,6 +18,20 @@ orchestration/copy-default-env: cp ${ORCHESTRATION_PROJECT_DIR}/.env.default ${ORCHESTRATION_PROJECT_DIR}/.env cp ${ORCHESTRATION_PROJECT_DIR}/.env.test.default ${ORCHESTRATION_PROJECT_DIR}/.env.test +# == Code format == + +orchestration/format: + npx nx format:write --projects ${ORCHESTRATION_PROJECT_NAME} + +orchestration/lint: + npx nx lint ${ORCHESTRATION_PROJECT_NAME} -- --fix + +orchestration/format/check: + npx nx format:check --projects ${ORCHESTRATION_PROJECT_NAME} + +orchestration/lint/check: + npx nx lint ${ORCHESTRATION_PROJECT_NAME} + # === Database === orchestration/db/generate-types: diff --git a/apps/orchestration/README.md b/apps/orchestration/README.md index 80001119b..31d860282 100644 --- a/apps/orchestration/README.md +++ b/apps/orchestration/README.md @@ -4,7 +4,7 @@ ```bash # Boot PostgreSQL and Redis -make docker/up +make docker/up make orchestration/setup ``` @@ -46,3 +46,13 @@ make orchestration/test/e2e/watch make orchestration/db/migrate make orchestration/db/create-migration NAME=your-migration-name ``` + +## Formatting + +```bash +make orchestration/format +make orchestration/lint + +make orchestration/format/check +make orchestration/lint/check +``` diff --git a/apps/orchestration/src/policy-engine/__test__/e2e/facade.spec.ts b/apps/orchestration/src/policy-engine/__test__/e2e/facade.spec.ts index 506cea87e..5099c2bbe 100644 --- a/apps/orchestration/src/policy-engine/__test__/e2e/facade.spec.ts +++ b/apps/orchestration/src/policy-engine/__test__/e2e/facade.spec.ts @@ -171,7 +171,6 @@ describe('Policy Engine Cluster Facade', () => { it('evaluates a partial sign transaction authorization request', async () => { const signTransactionRequest = { from: '0xaaa8ee1cbaa1856f4550c6fc24abb16c5c9b2a43', - nonce: 0, chainId: 1 } const payload = { diff --git a/apps/orchestration/src/policy-engine/http/rest/dto/sign-transaction-request.dto.ts b/apps/orchestration/src/policy-engine/http/rest/dto/sign-transaction-request.dto.ts index c7d60a608..658afaf68 100644 --- a/apps/orchestration/src/policy-engine/http/rest/dto/sign-transaction-request.dto.ts +++ b/apps/orchestration/src/policy-engine/http/rest/dto/sign-transaction-request.dto.ts @@ -1,9 +1,8 @@ -import { Address, Hex, TransactionType } from '@narval/authz-shared' +import { Address, Hex } from '@narval/authz-shared' import { ApiProperty } from '@nestjs/swagger' import { Transform } from 'class-transformer' import { IsDefined, - IsEnum, IsEthereumAddress, IsInt, IsNumber, @@ -53,12 +52,16 @@ export class SignTransactionRequestDto { }) from: Address + // @TODO (@wcalderipe, 19/01/24): Are we accepting the transaction without a + // nonce? @IsNumber() + @IsOptional() @Min(0) @ApiProperty({ - minimum: 0 + minimum: 0, + required: false }) - nonce: number + nonce?: number @IsOptional() @ValidateNested() @@ -98,13 +101,13 @@ export class SignTransactionRequestDto { }) to?: Address | null - @IsEnum(TransactionType) + @IsString() @IsOptional() @ApiProperty({ - enum: TransactionType, + default: '2', required: false }) - type?: `${TransactionType}` + type?: '2' @IsString() @IsOptional() diff --git a/apps/orchestration/src/policy-engine/persistence/schema/sign-transaction-request.schema.ts b/apps/orchestration/src/policy-engine/persistence/schema/sign-transaction-request.schema.ts index c49290258..a84259f14 100644 --- a/apps/orchestration/src/policy-engine/persistence/schema/sign-transaction-request.schema.ts +++ b/apps/orchestration/src/policy-engine/persistence/schema/sign-transaction-request.schema.ts @@ -50,7 +50,7 @@ const accessListSchema = z.object({ export const readSignTransactionRequestSchema = z.object({ chainId: z.coerce.number(), from: addressSchema, - nonce: z.coerce.number(), + nonce: z.coerce.number().optional(), accessList: z.array(accessListSchema).optional(), data: hexSchema.optional(), gas: z.coerce.bigint().optional(), diff --git a/apps/orchestration/tsconfig.spec.json b/apps/orchestration/tsconfig.spec.json index 9b2a121d1..f6d8ffcc9 100644 --- a/apps/orchestration/tsconfig.spec.json +++ b/apps/orchestration/tsconfig.spec.json @@ -5,10 +5,5 @@ "module": "commonjs", "types": ["jest", "node"] }, - "include": [ - "jest.config.ts", - "src/**/*.test.ts", - "src/**/*.spec.ts", - "src/**/*.d.ts" - ] + "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"] } diff --git a/apps/orchestration/webpack.config.js b/apps/orchestration/webpack.config.js index 81db92b95..bb8d268d2 100644 --- a/apps/orchestration/webpack.config.js +++ b/apps/orchestration/webpack.config.js @@ -1,8 +1,8 @@ -const { composePlugins, withNx } = require('@nx/webpack'); +const { composePlugins, withNx } = require('@nx/webpack') // Nx plugins for webpack. module.exports = composePlugins(withNx(), (config) => { // Update the webpack config as needed here. // e.g. `config.plugins.push(new MyPlugin())` - return config; -}); + return config +}) diff --git a/doc/prefixed-test-ethereum-accounts.md b/doc/prefixed-test-ethereum-accounts.md index 5a7dc6c6b..dde40fb0d 100644 --- a/doc/prefixed-test-ethereum-accounts.md +++ b/doc/prefixed-test-ethereum-accounts.md @@ -41,30 +41,26 @@ To generate new prefixed accounts, you can use the snippet below. It depends on [viem](https://viem.sh/) API, so make sure you have it installed. ```typescript -import { - PrivateKeyAccount, - generatePrivateKey, - privateKeyToAccount, -} from "viem/accounts"; +import { PrivateKeyAccount, generatePrivateKey, privateKeyToAccount } from 'viem/accounts' -const MAX_ATTEMPTS = 1_000_000; -const DESIRED_PREFIX = "0xbbb"; +const MAX_ATTEMPTS = 1_000_000 +const DESIRED_PREFIX = '0xbbb' -let account: PrivateKeyAccount; -let attempts = 0; +let account: PrivateKeyAccount +let attempts = 0 while (attempts <= MAX_ATTEMPTS) { - const privateKey = generatePrivateKey(); - account = privateKeyToAccount(privateKey); - const prefix = account.address.toLowerCase().substring(0, 5); - attempts++; + const privateKey = generatePrivateKey() + account = privateKeyToAccount(privateKey) + const prefix = account.address.toLowerCase().substring(0, 5) + attempts++ if (prefix === DESIRED_PREFIX) { console.log({ address: account.address, publicKey: account.publicKey, - privateKey: privateKey, - }); + privateKey: privateKey + }) } } ``` diff --git a/packages/authz-shared/Makefile b/packages/authz-shared/Makefile index ebccd8b33..4f614de0d 100644 --- a/packages/authz-shared/Makefile +++ b/packages/authz-shared/Makefile @@ -1,5 +1,21 @@ AUTHZ_SHARED_PROJECT_NAME := authz-shared +# == Code format == + +authz-shared/format: + npx nx format:write --projects ${AUTHZ_SHARED_PROJECT_NAME} + +authz-shared/lint: + npx nx lint ${AUTHZ_SHARED_PROJECT_NAME} -- --fix + +authz-shared/format/check: + npx nx format:check --projects ${AUTHZ_SHARED_PROJECT_NAME} + +authz-shared/lint/check: + npx nx lint ${AUTHZ_SHARED_PROJECT_NAME} + +# == Testing == + authz-shared/test/unit: npx nx test:unit ${AUTHZ_SHARED_PROJECT_NAME} -- ${ARGS} diff --git a/packages/authz-shared/README.md b/packages/authz-shared/README.md index 542dab80f..03a5ca9e0 100644 --- a/packages/authz-shared/README.md +++ b/packages/authz-shared/README.md @@ -9,3 +9,13 @@ AuthZ application. make authz-shared/test/unit make authz-shared/test/unit/watch ``` + +## Formatting + +```bash +make authz-shared/format +make authz-shared/lint + +make authz-shared/format/check +make authz-shared/lint/check +``` diff --git a/packages/transaction-engine-module/tsconfig.spec.json b/packages/transaction-engine-module/tsconfig.spec.json index 9b2a121d1..f6d8ffcc9 100644 --- a/packages/transaction-engine-module/tsconfig.spec.json +++ b/packages/transaction-engine-module/tsconfig.spec.json @@ -5,10 +5,5 @@ "module": "commonjs", "types": ["jest", "node"] }, - "include": [ - "jest.config.ts", - "src/**/*.test.ts", - "src/**/*.spec.ts", - "src/**/*.d.ts" - ] + "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"] } diff --git a/packages/transaction-request-intent/Makefile b/packages/transaction-request-intent/Makefile index 02e3de499..69af35c74 100644 --- a/packages/transaction-request-intent/Makefile +++ b/packages/transaction-request-intent/Makefile @@ -1,7 +1,23 @@ -TRANSACTION_REQUEST_INTENT_PROJECT_NAME := transaction-request-intent +TRI_PROJECT_NAME := transaction-request-intent + +# == Code format == + +transaction-request-intent/format: + npx nx format:write --projects ${TRI_PROJECT_NAME} + +transaction-request-intent/lint: + npx nx lint ${TRI_PROJECT_NAME} -- --fix + +transaction-request-intent/format/check: + npx nx format:check --projects ${TRI_PROJECT_NAME} + +transaction-request-intent/lint/check: + npx nx lint ${TRI_PROJECT_NAME} + +# == Testing == transaction-request-intent/test/unit: - npx nx test:unit ${TRANSACTION_REQUEST_INTENT_PROJECT_NAME} -- ${ARGS} + npx nx test:unit ${TRI_PROJECT_NAME} -- ${ARGS} transaction-request-intent/test/unit/watch: make transaction-request-intent/test/unit ARGS=--watch diff --git a/packages/transaction-request-intent/README.md b/packages/transaction-request-intent/README.md index 2c89fb657..aef1dbeb8 100644 --- a/packages/transaction-request-intent/README.md +++ b/packages/transaction-request-intent/README.md @@ -12,3 +12,13 @@ into an object with granular information. make transaction-request-intent/test/unit make transaction-request-intent/test/unit/watch ``` + +## Formatting + +```bash +make transaction-request-intent/format +make transaction-request-intent/lint + +make transaction-request-intent/format/check +make transaction-request-intent/lint/check +``` From 9aec427889e275d8a174235e5f4d790d908f1793 Mon Sep 17 00:00:00 2001 From: William Calderipe Date: Fri, 19 Jan 2024 11:22:44 +0100 Subject: [PATCH 2/2] Persist inbound approvals --- .../policy-engine/core/type/domain.type.ts | 11 ++++- .../http/rest/dto/signature.dto.ts | 2 +- .../src/policy-engine/http/rest/util.ts | 10 ++++- .../authorization-request.repository.ts | 44 +++++++++++++------ 4 files changed, 49 insertions(+), 18 deletions(-) diff --git a/apps/orchestration/src/policy-engine/core/type/domain.type.ts b/apps/orchestration/src/policy-engine/core/type/domain.type.ts index 83d285656..7fad6edea 100644 --- a/apps/orchestration/src/policy-engine/core/type/domain.type.ts +++ b/apps/orchestration/src/policy-engine/core/type/domain.type.ts @@ -1,5 +1,5 @@ import { Action, TransactionRequest } from '@narval/authz-shared' -import { SetOptional } from 'type-fest' +import { OverrideProperties, SetOptional } from 'type-fest' /** * AuthZ actions currently supported by the Orchestration. @@ -69,7 +69,14 @@ export type SignMessageAuthorizationRequest = SharedAuthorizationRequest & { export type AuthorizationRequest = SignTransactionAuthorizationRequest | SignMessageAuthorizationRequest -export type CreateAuthorizationRequest = SetOptional +export type CreateApproval = SetOptional + +export type CreateAuthorizationRequest = OverrideProperties< + SetOptional, + { + approvals: CreateApproval[] + } +> export function isSignTransaction(request: AuthorizationRequest): request is SignTransactionAuthorizationRequest { return (request as SignTransactionAuthorizationRequest).action === SupportedAction.SIGN_TRANSACTION diff --git a/apps/orchestration/src/policy-engine/http/rest/dto/signature.dto.ts b/apps/orchestration/src/policy-engine/http/rest/dto/signature.dto.ts index bb460f596..46b744f07 100644 --- a/apps/orchestration/src/policy-engine/http/rest/dto/signature.dto.ts +++ b/apps/orchestration/src/policy-engine/http/rest/dto/signature.dto.ts @@ -19,5 +19,5 @@ export class SignatureDto { enum: ['ES256K'], required: false }) - alg?: string = 'ES256K' + alg: string = 'ES256K' } diff --git a/apps/orchestration/src/policy-engine/http/rest/util.ts b/apps/orchestration/src/policy-engine/http/rest/util.ts index d3c97ae6f..0bfdffbcd 100644 --- a/apps/orchestration/src/policy-engine/http/rest/util.ts +++ b/apps/orchestration/src/policy-engine/http/rest/util.ts @@ -1,4 +1,8 @@ -import { CreateAuthorizationRequest, SupportedAction } from '@app/orchestration/policy-engine/core/type/domain.type' +import { + CreateApproval, + CreateAuthorizationRequest, + SupportedAction +} from '@app/orchestration/policy-engine/core/type/domain.type' import { AuthorizationRequestDto } from '@app/orchestration/policy-engine/http/rest/dto/authorization-request.dto' import { plainToInstance } from 'class-transformer' @@ -10,11 +14,13 @@ export const toCreateAuthorizationRequest = ( body: AuthorizationRequestDto ): CreateAuthorizationRequest => { const dto = plainToInstance(AuthorizationRequestDto, body) + const approvals: CreateApproval[] = dto.approvals + const shared = { orgId, initiatorId: '97389cac-20f0-4d02-a3a9-b27c564ffd18', hash: dto.hash, - approvals: [], + approvals, evaluations: [] } diff --git a/apps/orchestration/src/policy-engine/persistence/repository/authorization-request.repository.ts b/apps/orchestration/src/policy-engine/persistence/repository/authorization-request.repository.ts index d349dc6e2..5997d7b1f 100644 --- a/apps/orchestration/src/policy-engine/persistence/repository/authorization-request.repository.ts +++ b/apps/orchestration/src/policy-engine/persistence/repository/authorization-request.repository.ts @@ -12,15 +12,7 @@ import { import { PrismaService } from '@app/orchestration/shared/module/persistence/service/prisma.service' import { Injectable } from '@nestjs/common' import { EvaluationLog } from '@prisma/client/orchestration' - -const toEvaluationLogs = (orgId?: string, evaluations?: Evaluation[]): Omit[] => { - return orgId && evaluations?.length - ? evaluations.map((evaluation) => ({ - ...evaluation, - orgId - })) - : [] -} +import { v4 as uuid } from 'uuid' @Injectable() export class AuthorizationRequestRepository { @@ -28,13 +20,13 @@ export class AuthorizationRequestRepository { async create(input: CreateAuthorizationRequest): Promise { const { id, action, request, orgId, hash, status, idempotencyKey, createdAt, updatedAt, evaluations, approvals } = - createAuthorizationRequestSchema.parse(input) - const evaluationLogs = toEvaluationLogs(orgId, evaluations) + createAuthorizationRequestSchema.parse(this.getDefaults(input)) + const evaluationLogs = this.toEvaluationLogs(orgId, evaluations) const model = await this.prismaService.authorizationRequest.create({ data: { - status: status || AuthorizationRequestStatus.CREATED, id, + status, orgId, action, request, @@ -77,7 +69,7 @@ export class AuthorizationRequestRepository { ): Promise { const { id } = input const { orgId, status, evaluations, approvals } = updateAuthorizationRequestSchema.parse(input) - const evaluationLogs = toEvaluationLogs(orgId, evaluations) + const evaluationLogs = this.toEvaluationLogs(orgId, evaluations) const model = await this.prismaService.authorizationRequest.update({ where: { id }, @@ -137,4 +129,30 @@ export class AuthorizationRequestRepository { // decoding of all models. return models.map(decodeAuthorizationRequest) } + + private getDefaults(input: CreateAuthorizationRequest): AuthorizationRequest { + const now = new Date() + + return { + ...input, + id: input.id || uuid(), + status: input.status || AuthorizationRequestStatus.CREATED, + createdAt: input.createdAt || now, + updatedAt: input.updatedAt || now, + approvals: input.approvals.map((approval) => ({ + ...approval, + id: approval.id || uuid(), + createdAt: approval.createdAt || now + })) + } + } + + private toEvaluationLogs(orgId?: string, evaluations?: Evaluation[]): Omit[] { + return orgId && evaluations?.length + ? evaluations.map((evaluation) => ({ + ...evaluation, + orgId + })) + : [] + } }