ddd-ts-kit 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -3
- package/dist/check/catalogue/architecture-rules.d.ts.map +1 -1
- package/dist/check/catalogue/architecture-rules.js +2 -0
- package/dist/check/catalogue/architecture-rules.js.map +1 -1
- package/dist/check/errors/kit-error-codes.d.ts.map +1 -1
- package/dist/check/errors/kit-error-codes.js +1 -0
- package/dist/check/errors/kit-error-codes.js.map +1 -1
- package/dist/check/explain/authz-docs.d.ts.map +1 -1
- package/dist/check/explain/authz-docs.js +12 -0
- package/dist/check/explain/authz-docs.js.map +1 -1
- package/dist/check/explain/errors-docs.js +1 -1
- package/dist/check/explain/errors-docs.js.map +1 -1
- package/dist/check/explain/tenancy-docs.d.ts.map +1 -1
- package/dist/check/explain/tenancy-docs.js +3 -1
- package/dist/check/explain/tenancy-docs.js.map +1 -1
- package/dist/check/fixtures/authz-fixtures.d.ts.map +1 -1
- package/dist/check/fixtures/authz-fixtures.js +38 -1
- package/dist/check/fixtures/authz-fixtures.js.map +1 -1
- package/dist/check/fixtures/tenancy-fixtures.d.ts.map +1 -1
- package/dist/check/fixtures/tenancy-fixtures.js +28 -0
- package/dist/check/fixtures/tenancy-fixtures.js.map +1 -1
- package/dist/check/rules/authz-fields-by-schema.d.ts +3 -0
- package/dist/check/rules/authz-fields-by-schema.d.ts.map +1 -0
- package/dist/check/rules/authz-fields-by-schema.js +33 -0
- package/dist/check/rules/authz-fields-by-schema.js.map +1 -0
- package/dist/check/tenancy/knex-unscoped.d.ts +6 -1
- package/dist/check/tenancy/knex-unscoped.d.ts.map +1 -1
- package/dist/check/tenancy/knex-unscoped.js +19 -6
- package/dist/check/tenancy/knex-unscoped.js.map +1 -1
- package/dist/check/tenancy/raw-reaches-rows.d.ts +8 -0
- package/dist/check/tenancy/raw-reaches-rows.d.ts.map +1 -0
- package/dist/check/tenancy/raw-reaches-rows.js +91 -0
- package/dist/check/tenancy/raw-reaches-rows.js.map +1 -0
- package/dist/check/tenancy/raw-sql-text.d.ts +9 -0
- package/dist/check/tenancy/raw-sql-text.d.ts.map +1 -0
- package/dist/check/tenancy/raw-sql-text.js +29 -0
- package/dist/check/tenancy/raw-sql-text.js.map +1 -0
- package/dist/commands/generate.js +2 -0
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +13 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/parse-stack.d.ts.map +1 -1
- package/dist/config/parse-stack.js +3 -1
- package/dist/config/parse-stack.js.map +1 -1
- package/dist/config/stack.d.ts +14 -0
- package/dist/config/stack.d.ts.map +1 -1
- package/dist/config/stack.js +2 -0
- package/dist/config/stack.js.map +1 -1
- package/dist/declared/injection/laid-out-calls.d.ts +7 -0
- package/dist/declared/injection/laid-out-calls.d.ts.map +1 -0
- package/dist/declared/injection/laid-out-calls.js +14 -0
- package/dist/declared/injection/laid-out-calls.js.map +1 -0
- package/dist/declared/render-barrel.d.ts.map +1 -1
- package/dist/declared/render-barrel.js +2 -1
- package/dist/declared/render-barrel.js.map +1 -1
- package/dist/declared/render-dependencies-file.d.ts.map +1 -1
- package/dist/declared/render-dependencies-file.js +2 -1
- package/dist/declared/render-dependencies-file.js.map +1 -1
- package/dist/describe/context-description.d.ts +6 -0
- package/dist/describe/context-description.d.ts.map +1 -1
- package/dist/describe/format-description.js +9 -1
- package/dist/describe/format-description.js.map +1 -1
- package/dist/describe/presentation-of-route.d.ts +4 -0
- package/dist/describe/presentation-of-route.d.ts.map +1 -0
- package/dist/describe/presentation-of-route.js +15 -0
- package/dist/describe/presentation-of-route.js.map +1 -0
- package/dist/describe/read-controllers.d.ts.map +1 -1
- package/dist/describe/read-controllers.js +4 -1
- package/dist/describe/read-controllers.js.map +1 -1
- package/dist/describe/read-routes.d.ts.map +1 -1
- package/dist/describe/read-routes.js +2 -0
- package/dist/describe/read-routes.js.map +1 -1
- package/dist/generate/kind.d.ts +2 -0
- package/dist/generate/kind.d.ts.map +1 -1
- package/dist/generate/kinds/context-kind.d.ts.map +1 -1
- package/dist/generate/kinds/context-kind.js +13 -6
- package/dist/generate/kinds/context-kind.js.map +1 -1
- package/dist/generate/kinds/form-kind.d.ts +3 -0
- package/dist/generate/kinds/form-kind.d.ts.map +1 -0
- package/dist/generate/kinds/form-kind.js +38 -0
- package/dist/generate/kinds/form-kind.js.map +1 -0
- package/dist/generate/kinds/next-adr-number.d.ts +4 -0
- package/dist/generate/kinds/next-adr-number.d.ts.map +1 -0
- package/dist/generate/kinds/next-adr-number.js +7 -0
- package/dist/generate/kinds/next-adr-number.js.map +1 -0
- package/dist/generate/kinds/presentation/controller-of.d.ts +10 -0
- package/dist/generate/kinds/presentation/controller-of.d.ts.map +1 -0
- package/dist/generate/kinds/presentation/controller-of.js +13 -0
- package/dist/generate/kinds/presentation/controller-of.js.map +1 -0
- package/dist/generate/kinds/presentation/controller-source.d.ts +13 -0
- package/dist/generate/kinds/presentation/controller-source.d.ts.map +1 -0
- package/dist/generate/kinds/presentation/controller-source.js +44 -0
- package/dist/generate/kinds/presentation/controller-source.js.map +1 -0
- package/dist/generate/kinds/representation-kind.d.ts +3 -0
- package/dist/generate/kinds/representation-kind.d.ts.map +1 -0
- package/dist/generate/kinds/representation-kind.js +54 -0
- package/dist/generate/kinds/representation-kind.js.map +1 -0
- package/dist/generate/kinds/write-adr.js +3 -6
- package/dist/generate/kinds/write-adr.js.map +1 -1
- package/dist/generate/kinds.d.ts.map +1 -1
- package/dist/generate/kinds.js +4 -0
- package/dist/generate/kinds.js.map +1 -1
- package/dist/help/usage.d.ts +1 -1
- package/dist/help/usage.d.ts.map +1 -1
- package/dist/help/usage.js +3 -2
- package/dist/help/usage.js.map +1 -1
- package/dist/init/files/platform-files.js +3 -1
- package/dist/init/files/platform-files.js.map +1 -1
- package/dist/init/manifest/versions.js +24 -24
- package/dist/init/run-init.d.ts +2 -0
- package/dist/init/run-init.d.ts.map +1 -1
- package/dist/init/run-init.js +15 -1
- package/dist/init/run-init.js.map +1 -1
- package/dist/init/stack/resolve-stack.d.ts.map +1 -1
- package/dist/init/stack/resolve-stack.js +15 -1
- package/dist/init/stack/resolve-stack.js.map +1 -1
- package/dist/init/stack/stack-options.d.ts +2 -0
- package/dist/init/stack/stack-options.d.ts.map +1 -1
- package/dist/presets/apply-preset.d.ts +15 -0
- package/dist/presets/apply-preset.d.ts.map +1 -0
- package/dist/presets/apply-preset.js +94 -0
- package/dist/presets/apply-preset.js.map +1 -0
- package/dist/presets/grant-to-signed-in.d.ts +9 -0
- package/dist/presets/grant-to-signed-in.d.ts.map +1 -0
- package/dist/presets/grant-to-signed-in.js +61 -0
- package/dist/presets/grant-to-signed-in.js.map +1 -0
- package/dist/presets/identity-preset.d.ts +9 -0
- package/dist/presets/identity-preset.d.ts.map +1 -0
- package/dist/presets/identity-preset.js +44 -0
- package/dist/presets/identity-preset.js.map +1 -0
- package/dist/presets/identity-refusal.d.ts +5 -0
- package/dist/presets/identity-refusal.d.ts.map +1 -0
- package/dist/presets/identity-refusal.js +29 -0
- package/dist/presets/identity-refusal.js.map +1 -0
- package/dist/presets/identity-terms.d.ts +4 -0
- package/dist/presets/identity-terms.d.ts.map +1 -0
- package/dist/presets/identity-terms.js +57 -0
- package/dist/presets/identity-terms.js.map +1 -0
- package/dist/presets/no-flags.d.ts +4 -0
- package/dist/presets/no-flags.d.ts.map +1 -0
- package/dist/presets/no-flags.js +18 -0
- package/dist/presets/no-flags.js.map +1 -0
- package/dist/presets/organisations-as-tenants.d.ts +9 -0
- package/dist/presets/organisations-as-tenants.d.ts.map +1 -0
- package/dist/presets/organisations-as-tenants.js +43 -0
- package/dist/presets/organisations-as-tenants.js.map +1 -0
- package/dist/presets/preset-decision.d.ts +8 -0
- package/dist/presets/preset-decision.d.ts.map +1 -0
- package/dist/presets/preset-decision.js +19 -0
- package/dist/presets/preset-decision.js.map +1 -0
- package/dist/presets/preset-file.d.ts +13 -0
- package/dist/presets/preset-file.d.ts.map +1 -0
- package/dist/presets/preset-file.js +2 -0
- package/dist/presets/preset-file.js.map +1 -0
- package/dist/presets/preset-files.d.ts +9 -0
- package/dist/presets/preset-files.d.ts.map +1 -0
- package/dist/presets/preset-files.js +34 -0
- package/dist/presets/preset-files.js.map +1 -0
- package/dist/presets/preset-named.d.ts +3 -0
- package/dist/presets/preset-named.d.ts.map +1 -0
- package/dist/presets/preset-named.js +12 -0
- package/dist/presets/preset-named.js.map +1 -0
- package/dist/presets/preset-refusal.d.ts +6 -0
- package/dist/presets/preset-refusal.d.ts.map +1 -0
- package/dist/presets/preset-refusal.js +2 -0
- package/dist/presets/preset-refusal.js.map +1 -0
- package/dist/presets/preset-step.d.ts +8 -0
- package/dist/presets/preset-step.d.ts.map +1 -0
- package/dist/presets/preset-step.js +2 -0
- package/dist/presets/preset-step.js.map +1 -0
- package/dist/presets/preset.d.ts +36 -0
- package/dist/presets/preset.d.ts.map +1 -0
- package/dist/presets/preset.js +2 -0
- package/dist/presets/preset.js.map +1 -0
- package/dist/presets/with-authorizer-import.d.ts +6 -0
- package/dist/presets/with-authorizer-import.d.ts.map +1 -0
- package/dist/presets/with-authorizer-import.js +27 -0
- package/dist/presets/with-authorizer-import.js.map +1 -0
- package/dist/stack/stack-vars.js +19 -2
- package/dist/stack/stack-vars.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/workspace/workspace.d.ts +2 -0
- package/dist/workspace/workspace.d.ts.map +1 -1
- package/dist/workspace/workspace.js +4 -0
- package/dist/workspace/workspace.js.map +1 -1
- package/package.json +2 -2
- package/templates/docs/openapi.json.tpl +15 -0
- package/templates/init/CLAUDE.md.tpl +2 -2
- package/templates/init/platform/auth/http-boundary.ts.tpl +20 -3
- package/templates/init/platform/compose-application.manual.ts.tpl +18 -0
- package/templates/init/platform/compose-application.tsyringe.ts.tpl +23 -0
- package/templates/init/platform/http/presentation-of.ts.tpl +27 -0
- package/templates/init/platform/http/start-http-server.express.ts.tpl +1 -1
- package/templates/init/platform/http/start-http-server.fastify.ts.tpl +1 -1
- package/templates/init/platform/http/start-http-server.hono.ts.tpl +1 -1
- package/templates/init/platform/http/start-http-server.nest.ts.tpl +2 -2
- package/templates/init/platform/http/with-documentation.ts.tpl +13 -3
- package/templates/init/platform/http/with-forms.ts.tpl +7 -0
- package/templates/init/rules/application.md.tpl +1 -1
- package/templates/init/rules/presentation.md.tpl +1 -1
- package/templates/init/scripts/openapi.ts.tpl +27 -6
- package/templates/pipeline/biome.json.tpl +1 -0
- package/templates/pipeline/package-scripts.json +1 -1
- package/templates/presets/identity/context/application/authorization/__context__.permissions.ts.tpl +23 -0
- package/templates/presets/identity/context/application/authorization/change-member-roles.policy.ts.tpl +17 -0
- package/templates/presets/identity/context/application/authorization/grant-delegations.policy.ts.tpl +17 -0
- package/templates/presets/identity/context/application/authorization/invite-members.policy.ts.tpl +17 -0
- package/templates/presets/identity/context/application/authorization/read-members.policy.ts.tpl +17 -0
- package/templates/presets/identity/context/application/authorization/remove-members.policy.ts.tpl +17 -0
- package/templates/presets/identity/context/application/authorization/revoke-delegations.policy.ts.tpl +17 -0
- package/templates/presets/identity/context/application/authorization/revoke-invitations.policy.ts.tpl +17 -0
- package/templates/presets/identity/context/application/commands/accept-invitation/accept-invitation.command.ts.tpl +14 -0
- package/templates/presets/identity/context/application/commands/accept-invitation/accept-invitation.handler.ts.tpl +56 -0
- package/templates/presets/identity/context/application/commands/change-member-role/change-member-role.command.ts.tpl +17 -0
- package/templates/presets/identity/context/application/commands/change-member-role/change-member-role.handler.ts.tpl +82 -0
- package/templates/presets/identity/context/application/commands/deactivate-account/deactivate-account.command.ts.tpl +7 -0
- package/templates/presets/identity/context/application/commands/deactivate-account/deactivate-account.handler.ts.tpl +69 -0
- package/templates/presets/identity/context/application/commands/decline-invitation/decline-invitation.command.ts.tpl +14 -0
- package/templates/presets/identity/context/application/commands/decline-invitation/decline-invitation.handler.ts.tpl +36 -0
- package/templates/presets/identity/context/application/commands/grant-delegation/grant-delegation.command.ts.tpl +21 -0
- package/templates/presets/identity/context/application/commands/grant-delegation/grant-delegation.handler.ts.tpl +43 -0
- package/templates/presets/identity/context/application/commands/invite-member/invite-member.command.ts.tpl +16 -0
- package/templates/presets/identity/context/application/commands/invite-member/invite-member.handler.ts.tpl +53 -0
- package/templates/presets/identity/context/application/commands/open-organisation/open-organisation.command.ts.tpl +14 -0
- package/templates/presets/identity/context/application/commands/open-organisation/open-organisation.handler.ts.tpl +50 -0
- package/templates/presets/identity/context/application/commands/provision-account/provision-account.command.ts.tpl +14 -0
- package/templates/presets/identity/context/application/commands/provision-account/provision-account.handler.ts.tpl +41 -0
- package/templates/presets/identity/context/application/commands/remove-member/remove-member.command.ts.tpl +15 -0
- package/templates/presets/identity/context/application/commands/remove-member/remove-member.handler.ts.tpl +79 -0
- package/templates/presets/identity/context/application/commands/revoke-delegation/revoke-delegation.command.ts.tpl +15 -0
- package/templates/presets/identity/context/application/commands/revoke-delegation/revoke-delegation.handler.ts.tpl +39 -0
- package/templates/presets/identity/context/application/commands/revoke-invitation/revoke-invitation.command.ts.tpl +15 -0
- package/templates/presets/identity/context/application/commands/revoke-invitation/revoke-invitation.handler.ts.tpl +42 -0
- package/templates/presets/identity/context/application/integration/handlers/account-deactivated.integration-handler.ts.tpl +19 -0
- package/templates/presets/identity/context/application/integration/handlers/member-joined.integration-handler.ts.tpl +33 -0
- package/templates/presets/identity/context/application/integration/handlers/member-removed.integration-handler.ts.tpl +30 -0
- package/templates/presets/identity/context/application/integration/handlers/organisation-opened.integration-handler.ts.tpl +19 -0
- package/templates/presets/identity/context/application/integration/publishers/account-deactivated.publisher.ts.tpl +24 -0
- package/templates/presets/identity/context/application/integration/publishers/delegation-granted.publisher.ts.tpl +36 -0
- package/templates/presets/identity/context/application/integration/publishers/delegation-revoked.publisher.ts.tpl +33 -0
- package/templates/presets/identity/context/application/integration/publishers/member-joined.publisher.ts.tpl +33 -0
- package/templates/presets/identity/context/application/integration/publishers/member-removed.publisher.ts.tpl +33 -0
- package/templates/presets/identity/context/application/integration/publishers/member-role-changed.publisher.ts.tpl +35 -0
- package/templates/presets/identity/context/application/integration/publishers/organisation-opened.publisher.ts.tpl +32 -0
- package/templates/presets/identity/context/application/ports/identity-provider-admin.port.ts.tpl +17 -0
- package/templates/presets/identity/context/application/ports/identity-provider-connection.port.ts.tpl +14 -0
- package/templates/presets/identity/context/application/ports/invitation-tokens.port.ts.tpl +7 -0
- package/templates/presets/identity/context/application/ports/search-members-reader.port.ts.tpl +10 -0
- package/templates/presets/identity/context/application/queries/search-members/search-members.handler.ts.tpl +33 -0
- package/templates/presets/identity/context/application/queries/search-members/search-members.query.ts.tpl +19 -0
- package/templates/presets/identity/context/application/queries/search-members/search-members.result.ts.tpl +17 -0
- package/templates/presets/identity/context/domain/aggregates/account.aggregate.ts.tpl +92 -0
- package/templates/presets/identity/context/domain/aggregates/delegation.aggregate.ts.tpl +117 -0
- package/templates/presets/identity/context/domain/aggregates/invitation.aggregate.ts.tpl +128 -0
- package/templates/presets/identity/context/domain/aggregates/member.aggregate.ts.tpl +149 -0
- package/templates/presets/identity/context/domain/aggregates/organisation.aggregate.ts.tpl +52 -0
- package/templates/presets/identity/context/domain/errors/account.error.ts.tpl +40 -0
- package/templates/presets/identity/context/domain/errors/delegation.error.ts.tpl +45 -0
- package/templates/presets/identity/context/domain/errors/invitation.error.ts.tpl +30 -0
- package/templates/presets/identity/context/domain/errors/member.error.ts.tpl +50 -0
- package/templates/presets/identity/context/domain/errors/organisation.error.ts.tpl +32 -0
- package/templates/presets/identity/context/domain/events/account-deactivated.event.ts.tpl +13 -0
- package/templates/presets/identity/context/domain/events/account-provisioned.event.ts.tpl +17 -0
- package/templates/presets/identity/context/domain/events/delegation-granted.event.ts.tpl +22 -0
- package/templates/presets/identity/context/domain/events/delegation-revoked.event.ts.tpl +18 -0
- package/templates/presets/identity/context/domain/events/invitation-accepted.event.ts.tpl +17 -0
- package/templates/presets/identity/context/domain/events/invitation-declined.event.ts.tpl +16 -0
- package/templates/presets/identity/context/domain/events/invitation-issued.event.ts.tpl +22 -0
- package/templates/presets/identity/context/domain/events/invitation-revoked.event.ts.tpl +16 -0
- package/templates/presets/identity/context/domain/events/member-joined.event.ts.tpl +19 -0
- package/templates/presets/identity/context/domain/events/member-removed.event.ts.tpl +19 -0
- package/templates/presets/identity/context/domain/events/member-role-changed.event.ts.tpl +22 -0
- package/templates/presets/identity/context/domain/events/organisation-opened.event.ts.tpl +17 -0
- package/templates/presets/identity/context/domain/repositories/account.repository.ts.tpl +5 -0
- package/templates/presets/identity/context/domain/repositories/delegation.repository.ts.tpl +10 -0
- package/templates/presets/identity/context/domain/repositories/invitation.repository.ts.tpl +7 -0
- package/templates/presets/identity/context/domain/repositories/member.repository.ts.tpl +13 -0
- package/templates/presets/identity/context/domain/repositories/organisation.repository.ts.tpl +5 -0
- package/templates/presets/identity/context/domain/services/role-rights.service.ts.tpl +59 -0
- package/templates/presets/identity/context/domain/value-objects/delegation-period.vo.ts.tpl +42 -0
- package/templates/presets/identity/context/domain/value-objects/display-name.vo.ts.tpl +29 -0
- package/templates/presets/identity/context/domain/value-objects/email-address.vo.ts.tpl +31 -0
- package/templates/presets/identity/context/domain/value-objects/organisation-name.vo.ts.tpl +29 -0
- package/templates/presets/identity/context/domain/value-objects/organisation-rights.vo.ts.tpl +43 -0
- package/templates/presets/identity/context/domain/value-objects/organisation-slug.vo.ts.tpl +30 -0
- package/templates/presets/identity/context/domain/vocabularies/account-status.vocabulary.ts.tpl +7 -0
- package/templates/presets/identity/context/domain/vocabularies/invitation-status.vocabulary.ts.tpl +9 -0
- package/templates/presets/identity/context/domain/vocabularies/member-right.vocabulary.ts.tpl +9 -0
- package/templates/presets/identity/context/domain/vocabularies/member-role.vocabulary.ts.tpl +8 -0
- package/templates/presets/identity/context/infrastructure/external/crypto-invitation-tokens.adapter.ts.tpl +20 -0
- package/templates/presets/identity/context/infrastructure/external/environment-identity-provider-connection.adapter.ts.tpl +37 -0
- package/templates/presets/identity/context/infrastructure/external/keycloak-identity-provider-admin.adapter.ts.tpl +149 -0
- package/templates/presets/identity/context/infrastructure/persistence/__context__.schema.drizzle.ts.tpl +102 -0
- package/templates/presets/identity/context/infrastructure/persistence/account-row.schema.knex.ts.tpl +15 -0
- package/templates/presets/identity/context/infrastructure/persistence/account.mapper.drizzle.ts.tpl +38 -0
- package/templates/presets/identity/context/infrastructure/persistence/account.mapper.knex.ts.tpl +33 -0
- package/templates/presets/identity/context/infrastructure/persistence/create-__context__-tables.schema.knex.ts.tpl +107 -0
- package/templates/presets/identity/context/infrastructure/persistence/delegation-row.schema.knex.ts.tpl +17 -0
- package/templates/presets/identity/context/infrastructure/persistence/delegation.mapper.drizzle.ts.tpl +50 -0
- package/templates/presets/identity/context/infrastructure/persistence/delegation.mapper.knex.ts.tpl +45 -0
- package/templates/presets/identity/context/infrastructure/persistence/drizzle-account.repository.drizzle.ts.tpl +59 -0
- package/templates/presets/identity/context/infrastructure/persistence/drizzle-delegation.repository.drizzle.ts.tpl +77 -0
- package/templates/presets/identity/context/infrastructure/persistence/drizzle-invitation.repository.drizzle.ts.tpl +65 -0
- package/templates/presets/identity/context/infrastructure/persistence/drizzle-member.repository.drizzle.ts.tpl +84 -0
- package/templates/presets/identity/context/infrastructure/persistence/drizzle-organisation.repository.drizzle.ts.tpl +59 -0
- package/templates/presets/identity/context/infrastructure/persistence/drizzle-search-members-reader.repository.drizzle.ts.tpl +53 -0
- package/templates/presets/identity/context/infrastructure/persistence/invitation-row.schema.knex.ts.tpl +20 -0
- package/templates/presets/identity/context/infrastructure/persistence/invitation.mapper.drizzle.ts.tpl +45 -0
- package/templates/presets/identity/context/infrastructure/persistence/invitation.mapper.knex.ts.tpl +40 -0
- package/templates/presets/identity/context/infrastructure/persistence/knex-account.repository.knex.ts.tpl +61 -0
- package/templates/presets/identity/context/infrastructure/persistence/knex-delegation.repository.knex.ts.tpl +80 -0
- package/templates/presets/identity/context/infrastructure/persistence/knex-invitation.repository.knex.ts.tpl +67 -0
- package/templates/presets/identity/context/infrastructure/persistence/knex-member.repository.knex.ts.tpl +82 -0
- package/templates/presets/identity/context/infrastructure/persistence/knex-organisation.repository.knex.ts.tpl +61 -0
- package/templates/presets/identity/context/infrastructure/persistence/knex-search-members-reader.repository.knex.ts.tpl +77 -0
- package/templates/presets/identity/context/infrastructure/persistence/member-row.schema.knex.ts.tpl +15 -0
- package/templates/presets/identity/context/infrastructure/persistence/member.mapper.drizzle.ts.tpl +36 -0
- package/templates/presets/identity/context/infrastructure/persistence/member.mapper.knex.ts.tpl +31 -0
- package/templates/presets/identity/context/infrastructure/persistence/organisation-row.schema.knex.ts.tpl +12 -0
- package/templates/presets/identity/context/infrastructure/persistence/organisation.mapper.drizzle.ts.tpl +28 -0
- package/templates/presets/identity/context/infrastructure/persistence/organisation.mapper.knex.ts.tpl +26 -0
- package/templates/presets/identity/context/presentation/http/accounts/deactivate-account/deactivate-account.accepted.class-validator.per-route.ts.tpl +6 -0
- package/templates/presets/identity/context/presentation/http/accounts/deactivate-account/deactivate-account.controller.ts.tpl +71 -0
- package/templates/presets/identity/context/presentation/http/accounts/provision-account/provision-account.accepted.class-validator.per-route.ts.tpl +6 -0
- package/templates/presets/identity/context/presentation/http/accounts/provision-account/provision-account.body.class-validator.ts.tpl +9 -0
- package/templates/presets/identity/context/presentation/http/accounts/provision-account/provision-account.controller.ts.tpl +85 -0
- package/templates/presets/identity/context/presentation/http/accounts.routes.ts.tpl +5 -0
- package/templates/presets/identity/context/presentation/http/invitations/accept-invitation/accept-invitation.accepted.class-validator.per-route.ts.tpl +6 -0
- package/templates/presets/identity/context/presentation/http/invitations/accept-invitation/accept-invitation.body.class-validator.per-route.ts.tpl +8 -0
- package/templates/presets/identity/context/presentation/http/invitations/accept-invitation/accept-invitation.controller.ts.tpl +100 -0
- package/templates/presets/identity/context/presentation/http/invitations/decline-invitation/decline-invitation.accepted.class-validator.per-route.ts.tpl +6 -0
- package/templates/presets/identity/context/presentation/http/invitations/decline-invitation/decline-invitation.body.class-validator.per-route.ts.tpl +8 -0
- package/templates/presets/identity/context/presentation/http/invitations/decline-invitation/decline-invitation.controller.ts.tpl +98 -0
- package/templates/presets/identity/context/presentation/http/invitations.routes.ts.tpl +5 -0
- package/templates/presets/identity/context/presentation/http/organisations/change-member-role/change-member-role.accepted.class-validator.per-route.ts.tpl +6 -0
- package/templates/presets/identity/context/presentation/http/organisations/change-member-role/change-member-role.body.class-validator.ts.tpl +7 -0
- package/templates/presets/identity/context/presentation/http/organisations/change-member-role/change-member-role.controller.ts.tpl +83 -0
- package/templates/presets/identity/context/presentation/http/organisations/change-member-role/change-member-role.params.class-validator.ts.tpl +11 -0
- package/templates/presets/identity/context/presentation/http/organisations/grant-delegation/grant-delegation.accepted.class-validator.per-route.ts.tpl +6 -0
- package/templates/presets/identity/context/presentation/http/organisations/grant-delegation/grant-delegation.body.class-validator.ts.tpl +18 -0
- package/templates/presets/identity/context/presentation/http/organisations/grant-delegation/grant-delegation.controller.ts.tpl +103 -0
- package/templates/presets/identity/context/presentation/http/organisations/grant-delegation/grant-delegation.params.class-validator.ts.tpl +7 -0
- package/templates/presets/identity/context/presentation/http/organisations/invite-member/invite-member.accepted.class-validator.ts.tpl +10 -0
- package/templates/presets/identity/context/presentation/http/organisations/invite-member/invite-member.body.class-validator.ts.tpl +10 -0
- package/templates/presets/identity/context/presentation/http/organisations/invite-member/invite-member.controller.ts.tpl +65 -0
- package/templates/presets/identity/context/presentation/http/organisations/invite-member/invite-member.params.class-validator.ts.tpl +7 -0
- package/templates/presets/identity/context/presentation/http/organisations/open-organisation/open-organisation.accepted.class-validator.per-route.ts.tpl +6 -0
- package/templates/presets/identity/context/presentation/http/organisations/open-organisation/open-organisation.body.class-validator.ts.tpl +12 -0
- package/templates/presets/identity/context/presentation/http/organisations/open-organisation/open-organisation.controller.ts.tpl +79 -0
- package/templates/presets/identity/context/presentation/http/organisations/remove-member/remove-member.accepted.class-validator.per-route.ts.tpl +6 -0
- package/templates/presets/identity/context/presentation/http/organisations/remove-member/remove-member.controller.ts.tpl +73 -0
- package/templates/presets/identity/context/presentation/http/organisations/remove-member/remove-member.params.class-validator.ts.tpl +11 -0
- package/templates/presets/identity/context/presentation/http/organisations/revoke-delegation/revoke-delegation.accepted.class-validator.per-route.ts.tpl +6 -0
- package/templates/presets/identity/context/presentation/http/organisations/revoke-delegation/revoke-delegation.controller.ts.tpl +73 -0
- package/templates/presets/identity/context/presentation/http/organisations/revoke-delegation/revoke-delegation.params.class-validator.ts.tpl +11 -0
- package/templates/presets/identity/context/presentation/http/organisations/revoke-invitation/revoke-invitation.accepted.class-validator.per-route.ts.tpl +6 -0
- package/templates/presets/identity/context/presentation/http/organisations/revoke-invitation/revoke-invitation.controller.ts.tpl +73 -0
- package/templates/presets/identity/context/presentation/http/organisations/revoke-invitation/revoke-invitation.params.class-validator.ts.tpl +11 -0
- package/templates/presets/identity/context/presentation/http/organisations/search-members/search-members.controller.ts.tpl +86 -0
- package/templates/presets/identity/context/presentation/http/organisations/search-members/search-members.line.class-validator.ts.tpl +22 -0
- package/templates/presets/identity/context/presentation/http/organisations/search-members/search-members.params.class-validator.ts.tpl +7 -0
- package/templates/presets/identity/context/presentation/http/organisations.routes.ts.tpl +5 -0
- package/templates/presets/identity/context/presentation/http/shared/invitation-token.schema.class-validator.shared.ts.tpl +9 -0
- package/templates/presets/identity/context/presentation/http/shared/invitation-token.schema.zod.shared.ts.tpl +9 -0
- package/templates/presets/identity/context/published-language/account-deactivated.v1.integration-event.ts.tpl +33 -0
- package/templates/presets/identity/context/published-language/account-deactivated.v1.payload.class-validator.ts.tpl +7 -0
- package/templates/presets/identity/context/published-language/delegation-granted.v1.integration-event.ts.tpl +39 -0
- package/templates/presets/identity/context/published-language/delegation-granted.v1.payload.class-validator.ts.tpl +28 -0
- package/templates/presets/identity/context/published-language/delegation-revoked.v1.integration-event.ts.tpl +36 -0
- package/templates/presets/identity/context/published-language/delegation-revoked.v1.payload.class-validator.ts.tpl +16 -0
- package/templates/presets/identity/context/published-language/member-joined.v1.integration-event.ts.tpl +36 -0
- package/templates/presets/identity/context/published-language/member-joined.v1.payload.class-validator.ts.tpl +16 -0
- package/templates/presets/identity/context/published-language/member-removed.v1.integration-event.ts.tpl +36 -0
- package/templates/presets/identity/context/published-language/member-removed.v1.payload.class-validator.ts.tpl +18 -0
- package/templates/presets/identity/context/published-language/member-role-changed.v1.integration-event.ts.tpl +38 -0
- package/templates/presets/identity/context/published-language/member-role-changed.v1.payload.class-validator.ts.tpl +24 -0
- package/templates/presets/identity/context/published-language/organisation-opened.v1.integration-event.ts.tpl +35 -0
- package/templates/presets/identity/context/published-language/organisation-opened.v1.payload.class-validator.ts.tpl +13 -0
- package/templates/presets/identity/context/test/builders/account.builder.ts.tpl +59 -0
- package/templates/presets/identity/context/test/builders/delegation.builder.ts.tpl +67 -0
- package/templates/presets/identity/context/test/builders/invitation.builder.ts.tpl +60 -0
- package/templates/presets/identity/context/test/builders/member.builder.ts.tpl +59 -0
- package/templates/presets/identity/context/test/builders/organisation.builder.ts.tpl +44 -0
- package/templates/presets/identity/context/test/fakes/account.repository.fake.ts.tpl +10 -0
- package/templates/presets/identity/context/test/fakes/delegation.repository.fake.ts.tpl +26 -0
- package/templates/presets/identity/context/test/fakes/identity-provider-admin.fake.ts.tpl +41 -0
- package/templates/presets/identity/context/test/fakes/invitation-tokens.fake.ts.tpl +18 -0
- package/templates/presets/identity/context/test/fakes/invitation.repository.fake.ts.tpl +14 -0
- package/templates/presets/identity/context/test/fakes/member.repository.fake.ts.tpl +29 -0
- package/templates/presets/identity/context/test/fakes/organisation.repository.fake.ts.tpl +10 -0
- package/templates/presets/identity/context/test/fakes/search-members-reader.fake.ts.tpl +25 -0
- package/templates/presets/identity/context/test/integration/account.repository.contract.spec.ts.tpl +48 -0
- package/templates/presets/identity/context/test/integration/delegation.repository.contract.spec.ts.tpl +84 -0
- package/templates/presets/identity/context/test/integration/invitation.repository.contract.spec.ts.tpl +76 -0
- package/templates/presets/identity/context/test/integration/keycloak-identity-provider-admin.adapter.spec.ts.tpl +123 -0
- package/templates/presets/identity/context/test/integration/member.repository.contract.spec.ts.tpl +92 -0
- package/templates/presets/identity/context/test/integration/organisation.repository.contract.spec.ts.tpl +46 -0
- package/templates/presets/identity/context/test/integration/search-members-reader.spec.ts.tpl +86 -0
- package/templates/presets/identity/context/test/unit/accept-invitation.controller.spec.ts.tpl +57 -0
- package/templates/presets/identity/context/test/unit/accept-invitation.handler.spec.ts.tpl +69 -0
- package/templates/presets/identity/context/test/unit/account-deactivated.integration-handler.spec.ts.tpl +24 -0
- package/templates/presets/identity/context/test/unit/account-deactivated.publisher.spec.ts.tpl +25 -0
- package/templates/presets/identity/context/test/unit/account.aggregate.spec.ts.tpl +72 -0
- package/templates/presets/identity/context/test/unit/change-member-role.controller.spec.ts.tpl +57 -0
- package/templates/presets/identity/context/test/unit/change-member-role.handler.spec.ts.tpl +135 -0
- package/templates/presets/identity/context/test/unit/crypto-invitation-tokens.adapter.spec.ts.tpl +15 -0
- package/templates/presets/identity/context/test/unit/deactivate-account.controller.spec.ts.tpl +44 -0
- package/templates/presets/identity/context/test/unit/deactivate-account.handler.spec.ts.tpl +106 -0
- package/templates/presets/identity/context/test/unit/decline-invitation.controller.spec.ts.tpl +57 -0
- package/templates/presets/identity/context/test/unit/decline-invitation.handler.spec.ts.tpl +40 -0
- package/templates/presets/identity/context/test/unit/delegation-granted.publisher.spec.ts.tpl +36 -0
- package/templates/presets/identity/context/test/unit/delegation-period.vo.spec.ts.tpl +32 -0
- package/templates/presets/identity/context/test/unit/delegation-revoked.publisher.spec.ts.tpl +35 -0
- package/templates/presets/identity/context/test/unit/delegation.aggregate.spec.ts.tpl +111 -0
- package/templates/presets/identity/context/test/unit/display-name.vo.spec.ts.tpl +13 -0
- package/templates/presets/identity/context/test/unit/email-address.vo.spec.ts.tpl +24 -0
- package/templates/presets/identity/context/test/unit/environment-identity-provider-connection.adapter.spec.ts.tpl +41 -0
- package/templates/presets/identity/context/test/unit/grant-delegation.controller.spec.ts.tpl +57 -0
- package/templates/presets/identity/context/test/unit/grant-delegation.handler.spec.ts.tpl +66 -0
- package/templates/presets/identity/context/test/unit/identity-application.ts.tpl +79 -0
- package/templates/presets/identity/context/test/unit/invitation.aggregate.spec.ts.tpl +118 -0
- package/templates/presets/identity/context/test/unit/invite-member.controller.spec.ts.tpl +57 -0
- package/templates/presets/identity/context/test/unit/invite-member.handler.spec.ts.tpl +110 -0
- package/templates/presets/identity/context/test/unit/member-joined.integration-handler.spec.ts.tpl +38 -0
- package/templates/presets/identity/context/test/unit/member-joined.publisher.spec.ts.tpl +36 -0
- package/templates/presets/identity/context/test/unit/member-removed.integration-handler.spec.ts.tpl +45 -0
- package/templates/presets/identity/context/test/unit/member-removed.publisher.spec.ts.tpl +35 -0
- package/templates/presets/identity/context/test/unit/member-role-changed.publisher.spec.ts.tpl +36 -0
- package/templates/presets/identity/context/test/unit/member.aggregate.spec.ts.tpl +142 -0
- package/templates/presets/identity/context/test/unit/open-organisation.controller.spec.ts.tpl +57 -0
- package/templates/presets/identity/context/test/unit/open-organisation.handler.spec.ts.tpl +52 -0
- package/templates/presets/identity/context/test/unit/organisation-name.vo.spec.ts.tpl +13 -0
- package/templates/presets/identity/context/test/unit/organisation-opened.integration-handler.spec.ts.tpl +24 -0
- package/templates/presets/identity/context/test/unit/organisation-opened.publisher.spec.ts.tpl +35 -0
- package/templates/presets/identity/context/test/unit/organisation-rights.vo.spec.ts.tpl +23 -0
- package/templates/presets/identity/context/test/unit/organisation-slug.vo.spec.ts.tpl +17 -0
- package/templates/presets/identity/context/test/unit/organisation.aggregate.spec.ts.tpl +33 -0
- package/templates/presets/identity/context/test/unit/provision-account.controller.spec.ts.tpl +73 -0
- package/templates/presets/identity/context/test/unit/provision-account.handler.spec.ts.tpl +65 -0
- package/templates/presets/identity/context/test/unit/remove-member.controller.spec.ts.tpl +44 -0
- package/templates/presets/identity/context/test/unit/remove-member.handler.spec.ts.tpl +125 -0
- package/templates/presets/identity/context/test/unit/revoke-delegation.controller.spec.ts.tpl +44 -0
- package/templates/presets/identity/context/test/unit/revoke-delegation.handler.spec.ts.tpl +51 -0
- package/templates/presets/identity/context/test/unit/revoke-invitation.controller.spec.ts.tpl +44 -0
- package/templates/presets/identity/context/test/unit/revoke-invitation.handler.spec.ts.tpl +44 -0
- package/templates/presets/identity/context/test/unit/role-rights.service.spec.ts.tpl +54 -0
- package/templates/presets/identity/context/test/unit/search-members.controller.spec.ts.tpl +43 -0
- package/templates/presets/identity/context/test/unit/search-members.handler.spec.ts.tpl +38 -0
- package/templates/presets/identity/decision.md.tpl +37 -0
- package/templates/presets/identity/design.md.tpl +71 -0
- package/templates/presets/signed-in-grants.ts.tpl +12 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
import { stampCreation, stampUpdate, type Clock, type ExecutionScope } from '@ddd-ts-kit/kernel';
|
|
3
|
+
import { Repository } from '@ddd-ts-kit/kernel/declarations';
|
|
4
|
+
import { type KnexContext, auditRow, insertIgnoringConflict, optimisticUpdate } from '@ddd-ts-kit/knex';
|
|
5
|
+
import type { Invitation } from '{{alias.context}}/domain/aggregates/invitation.aggregate{{alias.ext}}';
|
|
6
|
+
import { InvitationRepository } from '{{alias.context}}/domain/repositories/invitation.repository{{alias.ext}}';
|
|
7
|
+
import { {{context.constant}}_SCHEMA } from '{{alias.context}}/infrastructure/persistence/{{context.kebab}}.schema{{alias.ext}}';
|
|
8
|
+
import { InvitationMapper } from '{{alias.context}}/infrastructure/persistence/invitation.mapper{{alias.ext}}';
|
|
9
|
+
import type { InvitationColumns, InvitationRow } from '{{alias.context}}/infrastructure/persistence/invitation-row.schema{{alias.ext}}';
|
|
10
|
+
|
|
11
|
+
type VersionedInvitation = InvitationColumns & { readonly version: number };
|
|
12
|
+
|
|
13
|
+
@Repository(InvitationRepository)
|
|
14
|
+
export class KnexInvitationRepository implements InvitationRepository {
|
|
15
|
+
constructor(
|
|
16
|
+
private readonly database: KnexContext,
|
|
17
|
+
private readonly scope: ExecutionScope,
|
|
18
|
+
private readonly clock: Clock,
|
|
19
|
+
) {}
|
|
20
|
+
|
|
21
|
+
async findById(id: string): Promise<Invitation | undefined> {
|
|
22
|
+
const row = await tableOf(this.database).where({ id }).first();
|
|
23
|
+
|
|
24
|
+
return row === undefined ? undefined : InvitationMapper.toDomain(row);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async findByTokenHash(tokenHash: string): Promise<Invitation | undefined> {
|
|
28
|
+
const row = await tableOf(this.database).where({ token_hash: tokenHash }).first();
|
|
29
|
+
|
|
30
|
+
return row === undefined ? undefined : InvitationMapper.toDomain(row);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async save(saved: Invitation): Promise<void> {
|
|
34
|
+
await optimisticUpdate(saved, async ({ expected, next }) => {
|
|
35
|
+
const state = { ...InvitationMapper.toRow(saved), version: next };
|
|
36
|
+
|
|
37
|
+
return expected === 0 ? this.insert(state) : this.update(state, expected);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private async insert(state: VersionedInvitation): Promise<number> {
|
|
42
|
+
const row = { ...state, ...auditRow(stampCreation(this.scope, this.clock)) };
|
|
43
|
+
|
|
44
|
+
const inserted = await insertIgnoringConflict(this.database.executor(), tableOf(this.database), {
|
|
45
|
+
row,
|
|
46
|
+
conflict: 'id',
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return inserted ? 1 : 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private async update(state: VersionedInvitation, expected: number): Promise<number> {
|
|
53
|
+
return tableOf(this.database)
|
|
54
|
+
.where({ id: state.id, version: expected })
|
|
55
|
+
.update({ ...state, ...auditRow(stampUpdate(this.scope, this.clock)) });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** A function and not a method: a query builder is thenable, and a method that answers one is read as asynchronous by whatever wraps the adapter (tracing), which then answers a promise. */
|
|
60
|
+
function tableOf(database: KnexContext): Knex.QueryBuilder<InvitationRow, InvitationRow[]> {
|
|
61
|
+
{{#if tenancy.any}}
|
|
62
|
+
// ddd-ts-kit-disable-next-line tenancy/scoped-statement -- {{preset.adr}}: the {{context.kebab}} context is the control plane of the tenants, and its rows belong to none of them.
|
|
63
|
+
{{/if}}
|
|
64
|
+
const table = database.executor()<InvitationRow, InvitationRow[]>('invitations');
|
|
65
|
+
|
|
66
|
+
return table.withSchema({{context.constant}}_SCHEMA);
|
|
67
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
import { stampCreation, stampUpdate, type Clock, type ExecutionScope } from '@ddd-ts-kit/kernel';
|
|
3
|
+
import { Repository } from '@ddd-ts-kit/kernel/declarations';
|
|
4
|
+
import { type KnexContext, auditRow, insertIgnoringConflict, optimisticUpdate } from '@ddd-ts-kit/knex';
|
|
5
|
+
import type { Member } from '{{alias.context}}/domain/aggregates/member.aggregate{{alias.ext}}';
|
|
6
|
+
import { MemberRepository } from '{{alias.context}}/domain/repositories/member.repository{{alias.ext}}';
|
|
7
|
+
import { MemberRole } from '{{alias.context}}/domain/vocabularies/member-role.vocabulary{{alias.ext}}';
|
|
8
|
+
import { {{context.constant}}_SCHEMA } from '{{alias.context}}/infrastructure/persistence/{{context.kebab}}.schema{{alias.ext}}';
|
|
9
|
+
import { MemberMapper } from '{{alias.context}}/infrastructure/persistence/member.mapper{{alias.ext}}';
|
|
10
|
+
import type { MemberColumns, MemberRow } from '{{alias.context}}/infrastructure/persistence/member-row.schema{{alias.ext}}';
|
|
11
|
+
|
|
12
|
+
type VersionedMember = MemberColumns & { readonly version: number };
|
|
13
|
+
|
|
14
|
+
@Repository(MemberRepository)
|
|
15
|
+
export class KnexMemberRepository implements MemberRepository {
|
|
16
|
+
constructor(
|
|
17
|
+
private readonly database: KnexContext,
|
|
18
|
+
private readonly scope: ExecutionScope,
|
|
19
|
+
private readonly clock: Clock,
|
|
20
|
+
) {}
|
|
21
|
+
|
|
22
|
+
async findById(id: string): Promise<Member | undefined> {
|
|
23
|
+
const row = await tableOf(this.database).where({ id }).first();
|
|
24
|
+
|
|
25
|
+
return row === undefined ? undefined : MemberMapper.toDomain(row);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async findOf(organisationId: string, accountId: string): Promise<Member | undefined> {
|
|
29
|
+
const current = { organisation_id: organisationId, account_id: accountId };
|
|
30
|
+
const row = await tableOf(this.database).where(current).whereNull('removed_at').first();
|
|
31
|
+
|
|
32
|
+
return row === undefined ? undefined : MemberMapper.toDomain(row);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async searchCurrentOf(accountId: string): Promise<readonly Member[]> {
|
|
36
|
+
const rows = await tableOf(this.database).where({ account_id: accountId }).whereNull('removed_at').orderBy('id');
|
|
37
|
+
|
|
38
|
+
return rows.map((row) => MemberMapper.toDomain(row));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async countOwners(organisationId: string): Promise<number> {
|
|
42
|
+
const owners = { organisation_id: organisationId, role: MemberRole.Owner };
|
|
43
|
+
const counted = await tableOf(this.database).where(owners).whereNull('removed_at').count({ total: '*' }).first();
|
|
44
|
+
|
|
45
|
+
return Number(counted?.total ?? 0);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async save(saved: Member): Promise<void> {
|
|
49
|
+
await optimisticUpdate(saved, async ({ expected, next }) => {
|
|
50
|
+
const state = { ...MemberMapper.toRow(saved), version: next };
|
|
51
|
+
|
|
52
|
+
return expected === 0 ? this.insert(state) : this.update(state, expected);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private async insert(state: VersionedMember): Promise<number> {
|
|
57
|
+
const row = { ...state, ...auditRow(stampCreation(this.scope, this.clock)) };
|
|
58
|
+
|
|
59
|
+
const inserted = await insertIgnoringConflict(this.database.executor(), tableOf(this.database), {
|
|
60
|
+
row,
|
|
61
|
+
conflict: 'id',
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return inserted ? 1 : 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private async update(state: VersionedMember, expected: number): Promise<number> {
|
|
68
|
+
return tableOf(this.database)
|
|
69
|
+
.where({ id: state.id, version: expected })
|
|
70
|
+
.update({ ...state, ...auditRow(stampUpdate(this.scope, this.clock)) });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** A function and not a method: a query builder is thenable, and a method that answers one is read as asynchronous by whatever wraps the adapter (tracing), which then answers a promise. */
|
|
75
|
+
function tableOf(database: KnexContext): Knex.QueryBuilder<MemberRow, MemberRow[]> {
|
|
76
|
+
{{#if tenancy.any}}
|
|
77
|
+
// ddd-ts-kit-disable-next-line tenancy/scoped-statement -- {{preset.adr}}: the {{context.kebab}} context is the control plane of the tenants, and its rows belong to none of them.
|
|
78
|
+
{{/if}}
|
|
79
|
+
const table = database.executor()<MemberRow, MemberRow[]>('members');
|
|
80
|
+
|
|
81
|
+
return table.withSchema({{context.constant}}_SCHEMA);
|
|
82
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
import { stampCreation, stampUpdate, type Clock, type ExecutionScope } from '@ddd-ts-kit/kernel';
|
|
3
|
+
import { Repository } from '@ddd-ts-kit/kernel/declarations';
|
|
4
|
+
import { type KnexContext, auditRow, insertIgnoringConflict, optimisticUpdate } from '@ddd-ts-kit/knex';
|
|
5
|
+
import type { Organisation } from '{{alias.context}}/domain/aggregates/organisation.aggregate{{alias.ext}}';
|
|
6
|
+
import { OrganisationRepository } from '{{alias.context}}/domain/repositories/organisation.repository{{alias.ext}}';
|
|
7
|
+
import { {{context.constant}}_SCHEMA } from '{{alias.context}}/infrastructure/persistence/{{context.kebab}}.schema{{alias.ext}}';
|
|
8
|
+
import { OrganisationMapper } from '{{alias.context}}/infrastructure/persistence/organisation.mapper{{alias.ext}}';
|
|
9
|
+
import type { OrganisationColumns, OrganisationRow } from '{{alias.context}}/infrastructure/persistence/organisation-row.schema{{alias.ext}}';
|
|
10
|
+
|
|
11
|
+
type VersionedOrganisation = OrganisationColumns & { readonly version: number };
|
|
12
|
+
|
|
13
|
+
@Repository(OrganisationRepository)
|
|
14
|
+
export class KnexOrganisationRepository implements OrganisationRepository {
|
|
15
|
+
constructor(
|
|
16
|
+
private readonly database: KnexContext,
|
|
17
|
+
private readonly scope: ExecutionScope,
|
|
18
|
+
private readonly clock: Clock,
|
|
19
|
+
) {}
|
|
20
|
+
|
|
21
|
+
async findById(id: string): Promise<Organisation | undefined> {
|
|
22
|
+
const row = await tableOf(this.database).where({ id }).first();
|
|
23
|
+
|
|
24
|
+
return row === undefined ? undefined : OrganisationMapper.toDomain(row);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async save(saved: Organisation): Promise<void> {
|
|
28
|
+
await optimisticUpdate(saved, async ({ expected, next }) => {
|
|
29
|
+
const state = { ...OrganisationMapper.toRow(saved), version: next };
|
|
30
|
+
|
|
31
|
+
return expected === 0 ? this.insert(state) : this.update(state, expected);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private async insert(state: VersionedOrganisation): Promise<number> {
|
|
36
|
+
const row = { ...state, ...auditRow(stampCreation(this.scope, this.clock)) };
|
|
37
|
+
|
|
38
|
+
const inserted = await insertIgnoringConflict(this.database.executor(), tableOf(this.database), {
|
|
39
|
+
row,
|
|
40
|
+
conflict: 'id',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return inserted ? 1 : 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private async update(state: VersionedOrganisation, expected: number): Promise<number> {
|
|
47
|
+
return tableOf(this.database)
|
|
48
|
+
.where({ id: state.id, version: expected })
|
|
49
|
+
.update({ ...state, ...auditRow(stampUpdate(this.scope, this.clock)) });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A function and not a method: a query builder is thenable, and a method that answers one is read as asynchronous by whatever wraps the adapter (tracing), which then answers a promise. */
|
|
54
|
+
function tableOf(database: KnexContext): Knex.QueryBuilder<OrganisationRow, OrganisationRow[]> {
|
|
55
|
+
{{#if tenancy.any}}
|
|
56
|
+
// ddd-ts-kit-disable-next-line tenancy/scoped-statement -- {{preset.adr}}: the {{context.kebab}} context is the control plane of the tenants, and its rows belong to none of them.
|
|
57
|
+
{{/if}}
|
|
58
|
+
const table = database.executor()<OrganisationRow, OrganisationRow[]>('organisations');
|
|
59
|
+
|
|
60
|
+
return table.withSchema({{context.constant}}_SCHEMA);
|
|
61
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
import { InvalidPageRequestError, pageOf, type PageRequest } from '@ddd-ts-kit/kernel';
|
|
3
|
+
import { Repository } from '@ddd-ts-kit/kernel/declarations';
|
|
4
|
+
import type { KnexContext } from '@ddd-ts-kit/knex';
|
|
5
|
+
import { SearchMembersReader } from '{{alias.context}}/application/ports/search-members-reader.port{{alias.ext}}';
|
|
6
|
+
import type {
|
|
7
|
+
SearchMembersItem,
|
|
8
|
+
SearchMembersResult,
|
|
9
|
+
SearchMembersSort,
|
|
10
|
+
} from '{{alias.context}}/application/queries/search-members/search-members.result{{alias.ext}}';
|
|
11
|
+
import { {{context.constant}}_SCHEMA } from '{{alias.context}}/infrastructure/persistence/{{context.kebab}}.schema{{alias.ext}}';
|
|
12
|
+
import type { MemberRow } from '{{alias.context}}/infrastructure/persistence/member-row.schema{{alias.ext}}';
|
|
13
|
+
|
|
14
|
+
interface MemberLine extends Pick<MemberRow, 'id' | 'account_id' | 'role' | 'joined_at'> {
|
|
15
|
+
readonly display_name: string;
|
|
16
|
+
readonly email: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const COLUMNS = [
|
|
20
|
+
'members.id',
|
|
21
|
+
'members.account_id',
|
|
22
|
+
'members.role',
|
|
23
|
+
'members.joined_at',
|
|
24
|
+
'accounts.display_name',
|
|
25
|
+
'accounts.email',
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
/** The current members of an organisation joined to the profile of their account: one statement, the page applied by the database. */
|
|
29
|
+
@Repository(SearchMembersReader)
|
|
30
|
+
export class KnexSearchMembersReader implements SearchMembersReader {
|
|
31
|
+
constructor(private readonly database: KnexContext) {}
|
|
32
|
+
|
|
33
|
+
async search(organisationId: string, page: PageRequest<SearchMembersSort>): Promise<SearchMembersResult> {
|
|
34
|
+
if (page.kind !== 'offset') {
|
|
35
|
+
throw new InvalidPageRequestError('The members of an organisation are read by offset');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const direction = page.sort[0]?.direction ?? 'asc';
|
|
39
|
+
const current = { 'members.organisation_id': organisationId, 'members.removed_at': null };
|
|
40
|
+
|
|
41
|
+
const rows = await membersOf(this.database)
|
|
42
|
+
.select<MemberLine[]>(COLUMNS)
|
|
43
|
+
.join('accounts', 'accounts.id', 'members.account_id')
|
|
44
|
+
.where(current)
|
|
45
|
+
.orderBy([
|
|
46
|
+
{ column: 'members.joined_at', order: direction },
|
|
47
|
+
{ column: 'members.id', order: direction },
|
|
48
|
+
])
|
|
49
|
+
.limit(page.limit)
|
|
50
|
+
.offset(page.offset);
|
|
51
|
+
|
|
52
|
+
const counted = await membersOf(this.database).where(current).count<{ total: string | number }[]>({ total: '*' }).first();
|
|
53
|
+
|
|
54
|
+
return pageOf(rows.map(toItem), { total: Number(counted?.total ?? 0) });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A function and not a method: a query builder is thenable, and a method that answers one is read as asynchronous by whatever wraps the adapter (tracing), which then answers a promise. */
|
|
59
|
+
function membersOf(database: KnexContext): Knex.QueryBuilder<MemberLine, MemberLine[]> {
|
|
60
|
+
{{#if tenancy.any}}
|
|
61
|
+
// ddd-ts-kit-disable-next-line tenancy/scoped-statement -- {{preset.adr}}: the {{context.kebab}} context is the control plane of the tenants, and its rows belong to none of them.
|
|
62
|
+
{{/if}}
|
|
63
|
+
const members = database.executor()<MemberLine, MemberLine[]>('members');
|
|
64
|
+
|
|
65
|
+
return members.withSchema({{context.constant}}_SCHEMA);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function toItem(line: MemberLine): SearchMembersItem {
|
|
69
|
+
return {
|
|
70
|
+
memberId: line.id,
|
|
71
|
+
accountId: line.account_id,
|
|
72
|
+
displayName: line.display_name,
|
|
73
|
+
email: line.email,
|
|
74
|
+
role: line.role,
|
|
75
|
+
joinedAt: line.joined_at,
|
|
76
|
+
};
|
|
77
|
+
}
|
package/templates/presets/identity/context/infrastructure/persistence/member-row.schema.knex.ts.tpl
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AuditRow } from '@ddd-ts-kit/knex';
|
|
2
|
+
import type { MemberRole } from '{{alias.context}}/domain/vocabularies/member-role.vocabulary{{alias.ext}}';
|
|
3
|
+
|
|
4
|
+
export interface MemberColumns {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly organisation_id: string;
|
|
7
|
+
readonly account_id: string;
|
|
8
|
+
readonly role: MemberRole;
|
|
9
|
+
readonly joined_at: Date;
|
|
10
|
+
readonly removed_at: Date | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface MemberRow extends MemberColumns, AuditRow {
|
|
14
|
+
readonly version: number;
|
|
15
|
+
}
|
package/templates/presets/identity/context/infrastructure/persistence/member.mapper.drizzle.ts.tpl
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AuditStamp } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { Member } from '{{alias.context}}/domain/aggregates/member.aggregate{{alias.ext}}';
|
|
3
|
+
import type { members } from '{{alias.context}}/infrastructure/persistence/{{context.kebab}}.schema{{alias.ext}}';
|
|
4
|
+
|
|
5
|
+
type MemberRow = typeof members.$inferSelect;
|
|
6
|
+
|
|
7
|
+
export type MemberColumns = Omit<MemberRow, 'version' | keyof AuditStamp>;
|
|
8
|
+
|
|
9
|
+
export const MemberMapper = {
|
|
10
|
+
toDomain(row: MemberRow): Member {
|
|
11
|
+
const loaded = Member.rehydrate(row.id, {
|
|
12
|
+
organisationId: row.organisationId,
|
|
13
|
+
accountId: row.accountId,
|
|
14
|
+
role: row.role,
|
|
15
|
+
joinedAt: row.joinedAt,
|
|
16
|
+
removedAt: row.removedAt ?? undefined,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
loaded.version = row.version;
|
|
20
|
+
|
|
21
|
+
return loaded;
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
toRow(saved: Member): MemberColumns {
|
|
25
|
+
const state = saved.toState();
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
id: saved.id,
|
|
29
|
+
organisationId: state.organisationId,
|
|
30
|
+
accountId: state.accountId,
|
|
31
|
+
role: state.role,
|
|
32
|
+
joinedAt: state.joinedAt,
|
|
33
|
+
removedAt: state.removedAt ?? null,
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
};
|
package/templates/presets/identity/context/infrastructure/persistence/member.mapper.knex.ts.tpl
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Member } from '{{alias.context}}/domain/aggregates/member.aggregate{{alias.ext}}';
|
|
2
|
+
import type { MemberColumns, MemberRow } from '{{alias.context}}/infrastructure/persistence/member-row.schema{{alias.ext}}';
|
|
3
|
+
|
|
4
|
+
export const MemberMapper = {
|
|
5
|
+
toDomain(row: MemberRow): Member {
|
|
6
|
+
const loaded = Member.rehydrate(row.id, {
|
|
7
|
+
organisationId: row.organisation_id,
|
|
8
|
+
accountId: row.account_id,
|
|
9
|
+
role: row.role,
|
|
10
|
+
joinedAt: row.joined_at,
|
|
11
|
+
removedAt: row.removed_at ?? undefined,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
loaded.version = row.version;
|
|
15
|
+
|
|
16
|
+
return loaded;
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
toRow(saved: Member): MemberColumns {
|
|
20
|
+
const state = saved.toState();
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
id: saved.id,
|
|
24
|
+
organisation_id: state.organisationId,
|
|
25
|
+
account_id: state.accountId,
|
|
26
|
+
role: state.role,
|
|
27
|
+
joined_at: state.joinedAt,
|
|
28
|
+
removed_at: state.removedAt ?? null,
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AuditRow } from '@ddd-ts-kit/knex';
|
|
2
|
+
|
|
3
|
+
export interface OrganisationColumns {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly opened_by: string;
|
|
7
|
+
readonly opened_at: Date;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface OrganisationRow extends OrganisationColumns, AuditRow {
|
|
11
|
+
readonly version: number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AuditStamp } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { Organisation } from '{{alias.context}}/domain/aggregates/organisation.aggregate{{alias.ext}}';
|
|
3
|
+
import { OrganisationName } from '{{alias.context}}/domain/value-objects/organisation-name.vo{{alias.ext}}';
|
|
4
|
+
import type { organisations } from '{{alias.context}}/infrastructure/persistence/{{context.kebab}}.schema{{alias.ext}}';
|
|
5
|
+
|
|
6
|
+
type OrganisationRow = typeof organisations.$inferSelect;
|
|
7
|
+
|
|
8
|
+
export type OrganisationColumns = Omit<OrganisationRow, 'version' | keyof AuditStamp>;
|
|
9
|
+
|
|
10
|
+
export const OrganisationMapper = {
|
|
11
|
+
toDomain(row: OrganisationRow): Organisation {
|
|
12
|
+
const loaded = Organisation.rehydrate(row.id, {
|
|
13
|
+
name: OrganisationName.create(row.name),
|
|
14
|
+
openedBy: row.openedBy,
|
|
15
|
+
openedAt: row.openedAt,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
loaded.version = row.version;
|
|
19
|
+
|
|
20
|
+
return loaded;
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
toRow(saved: Organisation): OrganisationColumns {
|
|
24
|
+
const state = saved.toState();
|
|
25
|
+
|
|
26
|
+
return { id: saved.id, name: state.name.value, openedBy: state.openedBy, openedAt: state.openedAt };
|
|
27
|
+
},
|
|
28
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Organisation } from '{{alias.context}}/domain/aggregates/organisation.aggregate{{alias.ext}}';
|
|
2
|
+
import { OrganisationName } from '{{alias.context}}/domain/value-objects/organisation-name.vo{{alias.ext}}';
|
|
3
|
+
import type {
|
|
4
|
+
OrganisationColumns,
|
|
5
|
+
OrganisationRow,
|
|
6
|
+
} from '{{alias.context}}/infrastructure/persistence/organisation-row.schema{{alias.ext}}';
|
|
7
|
+
|
|
8
|
+
export const OrganisationMapper = {
|
|
9
|
+
toDomain(row: OrganisationRow): Organisation {
|
|
10
|
+
const loaded = Organisation.rehydrate(row.id, {
|
|
11
|
+
name: OrganisationName.create(row.name),
|
|
12
|
+
openedBy: row.opened_by,
|
|
13
|
+
openedAt: row.opened_at,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
loaded.version = row.version;
|
|
17
|
+
|
|
18
|
+
return loaded;
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
toRow(saved: Organisation): OrganisationColumns {
|
|
22
|
+
const state = saved.toState();
|
|
23
|
+
|
|
24
|
+
return { id: saved.id, name: state.name.value, opened_by: state.openedBy, opened_at: state.openedAt };
|
|
25
|
+
},
|
|
26
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{{#if validation.classValidator}}
|
|
2
|
+
{{#if schemas.shared}}
|
|
3
|
+
import { acceptedSchema, Controller, type Accepted, type HttpRequest } from '@ddd-ts-kit/http';
|
|
4
|
+
{{/if}}
|
|
5
|
+
{{#if schemas.perRoute}}
|
|
6
|
+
import { Controller, type HttpRequest } from '@ddd-ts-kit/http';
|
|
7
|
+
{{/if}}
|
|
8
|
+
import type { CommandBus } from '@ddd-ts-kit/kernel';
|
|
9
|
+
{{#if schemas.perRoute}}
|
|
10
|
+
import { classSchema } from '@ddd-ts-kit/validation/class-validator';
|
|
11
|
+
{{/if}}
|
|
12
|
+
import { DeactivateAccountCommand } from '{{alias.context}}/application/commands/deactivate-account/deactivate-account.command{{alias.ext}}';
|
|
13
|
+
{{#if schemas.perRoute}}
|
|
14
|
+
import { DeactivateAccountAccepted } from '{{alias.context}}/presentation/http/accounts/deactivate-account/deactivate-account.accepted{{alias.ext}}';
|
|
15
|
+
{{/if}}
|
|
16
|
+
import { AccountsRoutes } from '{{alias.context}}/presentation/http/accounts.routes{{alias.ext}}';
|
|
17
|
+
{{/if}}
|
|
18
|
+
{{#if validation.zod}}
|
|
19
|
+
{{#if schemas.perRoute}}
|
|
20
|
+
import { z } from 'zod';
|
|
21
|
+
{{/if}}
|
|
22
|
+
{{#if schemas.shared}}
|
|
23
|
+
import { acceptedSchema, Controller, type Accepted, type HttpRequest } from '@ddd-ts-kit/http';
|
|
24
|
+
{{/if}}
|
|
25
|
+
{{#if schemas.perRoute}}
|
|
26
|
+
import { Controller, type HttpRequest } from '@ddd-ts-kit/http';
|
|
27
|
+
{{/if}}
|
|
28
|
+
import type { CommandBus } from '@ddd-ts-kit/kernel';
|
|
29
|
+
{{#if schemas.perRoute}}
|
|
30
|
+
import type { Infer } from '@ddd-ts-kit/validation';
|
|
31
|
+
{{/if}}
|
|
32
|
+
{{#if schemas.perRoute}}
|
|
33
|
+
import { zodSchema } from '@ddd-ts-kit/validation/zod';
|
|
34
|
+
{{/if}}
|
|
35
|
+
import { DeactivateAccountCommand } from '{{alias.context}}/application/commands/deactivate-account/deactivate-account.command{{alias.ext}}';
|
|
36
|
+
import { AccountsRoutes } from '{{alias.context}}/presentation/http/accounts.routes{{alias.ext}}';
|
|
37
|
+
{{/if}}
|
|
38
|
+
|
|
39
|
+
{{#if validation.classValidator}}
|
|
40
|
+
{{#if schemas.perRoute}}
|
|
41
|
+
const accepted = classSchema(DeactivateAccountAccepted);
|
|
42
|
+
{{/if}}
|
|
43
|
+
{{/if}}
|
|
44
|
+
{{#if validation.zod}}
|
|
45
|
+
{{#if schemas.perRoute}}
|
|
46
|
+
const accepted = zodSchema(z.object({ id: z.string() }), { io: 'output' });
|
|
47
|
+
{{/if}}
|
|
48
|
+
{{/if}}
|
|
49
|
+
|
|
50
|
+
@Controller({
|
|
51
|
+
group: AccountsRoutes,
|
|
52
|
+
method: 'POST',
|
|
53
|
+
path: '/me/deactivation',
|
|
54
|
+
summary: 'Deactivate my account',
|
|
55
|
+
response: { status: 200, description: 'The account is deactivated; the body carries its identifier.', body: {{#if schemas.shared}}acceptedSchema{{/if}}{{#if schemas.perRoute}}accepted{{/if}} },
|
|
56
|
+
errors: ['ACCOUNT_NOT_FOUND', 'ACCOUNT_ALREADY_DEACTIVATED', 'ORGANISATION_NOT_FOUND', 'LAST_OWNER'],
|
|
57
|
+
})
|
|
58
|
+
export class DeactivateAccountController {
|
|
59
|
+
constructor(private readonly commands: CommandBus) {}
|
|
60
|
+
|
|
61
|
+
{{#if validation.classValidator}}
|
|
62
|
+
async handle(request: HttpRequest<object>): Promise<{{#if schemas.shared}}Accepted{{/if}}{{#if schemas.perRoute}}DeactivateAccountAccepted{{/if}}> {
|
|
63
|
+
{{/if}}
|
|
64
|
+
{{#if validation.zod}}
|
|
65
|
+
async handle(request: HttpRequest<object>): Promise<{{#if schemas.shared}}Accepted{{/if}}{{#if schemas.perRoute}}Infer<typeof accepted>{{/if}}> {
|
|
66
|
+
{{/if}}
|
|
67
|
+
const id = await this.commands.execute(new DeactivateAccountCommand(request.actor));
|
|
68
|
+
|
|
69
|
+
return { id };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
|
2
|
+
|
|
3
|
+
export class ProvisionAccountBody {
|
|
4
|
+
/** Left out, the name the token gives; the email address is always the one of the token. */
|
|
5
|
+
@IsOptional()
|
|
6
|
+
@IsString()
|
|
7
|
+
@IsNotEmpty()
|
|
8
|
+
displayName?: string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{{#if validation.classValidator}}
|
|
2
|
+
{{#if schemas.shared}}
|
|
3
|
+
import { acceptedSchema, Controller, type Accepted, type HttpRequest } from '@ddd-ts-kit/http';
|
|
4
|
+
{{/if}}
|
|
5
|
+
{{#if schemas.perRoute}}
|
|
6
|
+
import { Controller, type HttpRequest } from '@ddd-ts-kit/http';
|
|
7
|
+
{{/if}}
|
|
8
|
+
import type { Actor, CommandBus } from '@ddd-ts-kit/kernel';
|
|
9
|
+
import { classSchema } from '@ddd-ts-kit/validation/class-validator';
|
|
10
|
+
import { ProvisionAccountCommand } from '{{alias.context}}/application/commands/provision-account/provision-account.command{{alias.ext}}';
|
|
11
|
+
import { ProvisionAccountBody } from '{{alias.context}}/presentation/http/accounts/provision-account/provision-account.body{{alias.ext}}';
|
|
12
|
+
{{#if schemas.perRoute}}
|
|
13
|
+
import { ProvisionAccountAccepted } from '{{alias.context}}/presentation/http/accounts/provision-account/provision-account.accepted{{alias.ext}}';
|
|
14
|
+
{{/if}}
|
|
15
|
+
import { AccountsRoutes } from '{{alias.context}}/presentation/http/accounts.routes{{alias.ext}}';
|
|
16
|
+
{{/if}}
|
|
17
|
+
{{#if validation.zod}}
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
{{#if schemas.shared}}
|
|
20
|
+
import { acceptedSchema, Controller, type Accepted, type HttpRequest } from '@ddd-ts-kit/http';
|
|
21
|
+
{{/if}}
|
|
22
|
+
{{#if schemas.perRoute}}
|
|
23
|
+
import { Controller, type HttpRequest } from '@ddd-ts-kit/http';
|
|
24
|
+
{{/if}}
|
|
25
|
+
import type { Actor, CommandBus } from '@ddd-ts-kit/kernel';
|
|
26
|
+
import type { Infer } from '@ddd-ts-kit/validation';
|
|
27
|
+
import { zodSchema } from '@ddd-ts-kit/validation/zod';
|
|
28
|
+
import { ProvisionAccountCommand } from '{{alias.context}}/application/commands/provision-account/provision-account.command{{alias.ext}}';
|
|
29
|
+
import { AccountsRoutes } from '{{alias.context}}/presentation/http/accounts.routes{{alias.ext}}';
|
|
30
|
+
{{/if}}
|
|
31
|
+
|
|
32
|
+
{{#if validation.classValidator}}
|
|
33
|
+
const body = classSchema(ProvisionAccountBody);
|
|
34
|
+
{{#if schemas.perRoute}}
|
|
35
|
+
const accepted = classSchema(ProvisionAccountAccepted);
|
|
36
|
+
{{/if}}
|
|
37
|
+
{{/if}}
|
|
38
|
+
{{#if validation.zod}}
|
|
39
|
+
const body = zodSchema(
|
|
40
|
+
z.object({
|
|
41
|
+
displayName: z.string().min(1).optional(),
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
{{#if schemas.perRoute}}
|
|
46
|
+
const accepted = zodSchema(z.object({ id: z.string() }), { io: 'output' });
|
|
47
|
+
{{/if}}
|
|
48
|
+
{{/if}}
|
|
49
|
+
|
|
50
|
+
@Controller({
|
|
51
|
+
group: AccountsRoutes,
|
|
52
|
+
method: 'PUT',
|
|
53
|
+
path: '/me',
|
|
54
|
+
summary: 'Provision my account',
|
|
55
|
+
body,
|
|
56
|
+
response: { status: 200, description: 'The account, provisioned or refreshed; the body carries its identifier.', body: {{#if schemas.shared}}acceptedSchema{{/if}}{{#if schemas.perRoute}}accepted{{/if}} },
|
|
57
|
+
errors: ['EMAIL_NOT_VERIFIED', 'INVALID_EMAIL_ADDRESS', 'INVALID_DISPLAY_NAME', 'ACCOUNT_DEACTIVATED'],
|
|
58
|
+
})
|
|
59
|
+
export class ProvisionAccountController {
|
|
60
|
+
constructor(private readonly commands: CommandBus) {}
|
|
61
|
+
|
|
62
|
+
{{#if validation.classValidator}}
|
|
63
|
+
async handle(request: HttpRequest<{ body: ProvisionAccountBody }>): Promise<{{#if schemas.shared}}Accepted{{/if}}{{#if schemas.perRoute}}ProvisionAccountAccepted{{/if}}> {
|
|
64
|
+
{{/if}}
|
|
65
|
+
{{#if validation.zod}}
|
|
66
|
+
async handle(request: HttpRequest<{ body: Infer<typeof body> }>): Promise<{{#if schemas.shared}}Accepted{{/if}}{{#if schemas.perRoute}}Infer<typeof accepted>{{/if}}> {
|
|
67
|
+
{{/if}}
|
|
68
|
+
const id = await this.commands.execute(new ProvisionAccountCommand(request.actor, profileOf(request.actor, request.body.displayName)));
|
|
69
|
+
|
|
70
|
+
return { id };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The token is the authority on who the person is: their address comes from it, never from the
|
|
76
|
+
* body, and with whether the provider verified it (`email_verified`), so that nobody accepts an
|
|
77
|
+
* invitation sent to someone else by registering their address unverified.
|
|
78
|
+
*/
|
|
79
|
+
function profileOf(actor: Actor, displayName: string | undefined): ProvisionAccountCommand['profile'] {
|
|
80
|
+
const { email, emailVerified, username } = actor.attributes;
|
|
81
|
+
const address = typeof email === 'string' ? email : '';
|
|
82
|
+
const named = displayName ?? (typeof username === 'string' ? username : address);
|
|
83
|
+
|
|
84
|
+
return { email: address, emailVerified: emailVerified === true, displayName: named };
|
|
85
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Authenticated, RouteGroup } from '@ddd-ts-kit/http';
|
|
2
|
+
|
|
3
|
+
/** The account of the person who calls: every route is about the caller, named by their token. */
|
|
4
|
+
@RouteGroup({ prefix: '/accounts', tags: ['{{context.kebab}}'], guards: [Authenticated], errors: ['FORBIDDEN'] })
|
|
5
|
+
export class AccountsRoutes {}
|