@nest-boot/auth 8.0.9-beta.0 → 8.0.9-beta.2
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 +74 -34
- package/dist/adapters/mikro-orm/adapter-config.d.ts +5 -0
- package/dist/adapters/mikro-orm/adapter-config.js +5 -0
- package/dist/adapters/mikro-orm/adapter-config.js.map +1 -1
- package/dist/adapters/mikro-orm/create-custom-adapter.d.ts +9 -0
- package/dist/adapters/mikro-orm/create-custom-adapter.js +9 -0
- package/dist/adapters/mikro-orm/create-custom-adapter.js.map +1 -1
- package/dist/adapters/mikro-orm/entity-metadata-resolver.d.ts +7 -0
- package/dist/adapters/mikro-orm/entity-metadata-resolver.js +7 -0
- package/dist/adapters/mikro-orm/entity-metadata-resolver.js.map +1 -1
- package/dist/adapters/mikro-orm/where-compiler.d.ts +7 -0
- package/dist/adapters/mikro-orm/where-compiler.js +11 -0
- package/dist/adapters/mikro-orm/where-compiler.js.map +1 -1
- package/dist/api-key-usage.interceptor.d.ts +10 -2
- package/dist/api-key-usage.interceptor.js +10 -2
- package/dist/api-key-usage.interceptor.js.map +1 -1
- package/dist/auth-handler.middleware.d.ts +14 -3
- package/dist/auth-handler.middleware.js +14 -3
- package/dist/auth-handler.middleware.js.map +1 -1
- package/dist/auth.ability.d.ts +11 -2
- package/dist/auth.ability.js +11 -2
- package/dist/auth.ability.js.map +1 -1
- package/dist/auth.constants.d.ts +4 -1
- package/dist/auth.constants.js +4 -1
- package/dist/auth.constants.js.map +1 -1
- package/dist/auth.guard.d.ts +0 -4
- package/dist/auth.guard.js +0 -4
- package/dist/auth.guard.js.map +1 -1
- package/dist/auth.middleware.d.ts +24 -8
- package/dist/auth.middleware.js +41 -25
- package/dist/auth.middleware.js.map +1 -1
- package/dist/auth.module.d.ts +0 -1
- package/dist/auth.module.js +5 -6
- package/dist/auth.module.js.map +1 -1
- package/dist/connections/index.d.ts +1 -1
- package/dist/connections/index.js +1 -1
- package/dist/connections/index.js.map +1 -1
- package/dist/connections/member-api-key.connection-definition.d.ts +13 -0
- package/dist/connections/{workspace-api-key.connection-definition.js → member-api-key.connection-definition.js} +11 -11
- package/dist/connections/member-api-key.connection-definition.js.map +1 -0
- package/dist/connections/member.connection-definition.js +1 -0
- package/dist/connections/member.connection-definition.js.map +1 -1
- package/dist/decorators/can.decorator.d.ts +6 -1
- package/dist/decorators/can.decorator.js +6 -1
- package/dist/decorators/can.decorator.js.map +1 -1
- package/dist/decorators/public.decorator.d.ts +5 -1
- package/dist/decorators/public.decorator.js +5 -1
- package/dist/decorators/public.decorator.js.map +1 -1
- package/dist/entities/account.entity.d.ts +4 -1
- package/dist/entities/account.entity.js +4 -1
- package/dist/entities/account.entity.js.map +1 -1
- package/dist/entities/auth-entity-map.d.ts +2 -2
- package/dist/entities/auth-entity-map.js +2 -2
- package/dist/entities/auth-entity-map.js.map +1 -1
- package/dist/entities/index.d.ts +3 -3
- package/dist/entities/index.js +3 -3
- package/dist/entities/index.js.map +1 -1
- package/dist/entities/invitation.entity.d.ts +4 -1
- package/dist/entities/invitation.entity.js +4 -1
- package/dist/entities/invitation.entity.js.map +1 -1
- package/dist/entities/{workspace-api-key.entity.d.ts → member-api-key.entity.d.ts} +14 -6
- package/dist/entities/{workspace-api-key.entity.js → member-api-key.entity.js} +44 -29
- package/dist/entities/member-api-key.entity.js.map +1 -0
- package/dist/entities/member.entity.d.ts +10 -3
- package/dist/entities/member.entity.js +19 -3
- package/dist/entities/member.entity.js.map +1 -1
- package/dist/enums/index.d.ts +2 -1
- package/dist/enums/index.js +2 -1
- package/dist/enums/index.js.map +1 -1
- package/dist/enums/{workspace-api-key-permission.enum.d.ts → member-api-key-permission.enum.d.ts} +2 -2
- package/dist/enums/{workspace-api-key-permission.enum.js → member-api-key-permission.enum.js} +4 -4
- package/dist/enums/member-api-key-permission.enum.js.map +1 -0
- package/dist/enums/member-type.enum.d.ts +7 -0
- package/dist/enums/member-type.enum.js +11 -0
- package/dist/enums/member-type.enum.js.map +1 -0
- package/dist/features/invitations/invitation.resolver.d.ts +43 -8
- package/dist/features/invitations/invitation.resolver.js +43 -8
- package/dist/features/invitations/invitation.resolver.js.map +1 -1
- package/dist/features/invitations/invitation.service.d.ts +75 -12
- package/dist/features/invitations/invitation.service.js +75 -12
- package/dist/features/invitations/invitation.service.js.map +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/api-key-authentication.service.d.ts +20 -4
- package/dist/infrastructure/api-key-authentication.service.js +45 -12
- package/dist/infrastructure/api-key-authentication.service.js.map +1 -1
- package/dist/infrastructure/api-key-lifecycle.d.ts +31 -5
- package/dist/infrastructure/api-key-lifecycle.js +31 -5
- package/dist/infrastructure/api-key-lifecycle.js.map +1 -1
- package/dist/infrastructure/auth-ability.factory.d.ts +14 -3
- package/dist/infrastructure/auth-ability.factory.js +31 -5
- package/dist/infrastructure/auth-ability.factory.js.map +1 -1
- package/dist/infrastructure/auth-enum-registry.d.ts +4 -1
- package/dist/infrastructure/auth-enum-registry.js +7 -4
- package/dist/infrastructure/auth-enum-registry.js.map +1 -1
- package/dist/infrastructure/auth-service.providers.d.ts +4 -1
- package/dist/infrastructure/auth-service.providers.js +4 -1
- package/dist/infrastructure/auth-service.providers.js.map +1 -1
- package/dist/infrastructure/better-auth-adapter.d.ts +6 -1
- package/dist/infrastructure/better-auth-adapter.js +2 -0
- package/dist/infrastructure/better-auth-adapter.js.map +1 -1
- package/dist/infrastructure/create-auth-instance.d.ts +20 -2
- package/dist/infrastructure/create-auth-instance.js +31 -4
- package/dist/infrastructure/create-auth-instance.js.map +1 -1
- package/dist/infrastructure/create-contextual-auth-service.d.ts +4 -0
- package/dist/infrastructure/create-contextual-auth-service.js +4 -0
- package/dist/infrastructure/create-contextual-auth-service.js.map +1 -1
- package/dist/infrastructure/request-identity.d.ts +89 -18
- package/dist/infrastructure/request-identity.js +113 -28
- package/dist/infrastructure/request-identity.js.map +1 -1
- package/dist/infrastructure/revoked-authentication.exception.d.ts +4 -1
- package/dist/infrastructure/revoked-authentication.exception.js +4 -1
- package/dist/infrastructure/revoked-authentication.exception.js.map +1 -1
- package/dist/inputs/add-member.input.d.ts +13 -2
- package/dist/inputs/add-member.input.js +34 -3
- package/dist/inputs/add-member.input.js.map +1 -1
- package/dist/inputs/{create-workspace-api-key.input.d.ts → create-member-api-key.input.d.ts} +6 -4
- package/dist/inputs/{create-workspace-api-key.input.js → create-member-api-key.input.js} +20 -13
- package/dist/inputs/create-member-api-key.input.js.map +1 -0
- package/dist/inputs/create-user-api-key.input.d.ts +1 -1
- package/dist/inputs/create-user-api-key.input.js +1 -1
- package/dist/inputs/create-user-api-key.input.js.map +1 -1
- package/dist/inputs/{update-workspace-api-key.input.d.ts → update-member-api-key.input.d.ts} +3 -3
- package/dist/inputs/{update-workspace-api-key.input.js → update-member-api-key.input.js} +11 -11
- package/dist/inputs/update-member-api-key.input.js.map +1 -0
- package/dist/interfaces/ability-context.interface.d.ts +3 -3
- package/dist/interfaces/add-member-options.interface.d.ts +1 -1
- package/dist/interfaces/auth-module-api-key-options.interface.d.ts +2 -2
- package/dist/interfaces/auth-module-api-key-scope-options.interface.d.ts +2 -2
- package/dist/interfaces/create-api-key-options.interface.d.ts +1 -1
- package/dist/interfaces/create-member-api-key-options.interface.d.ts +7 -0
- package/dist/interfaces/create-member-api-key-options.interface.js +2 -0
- package/dist/interfaces/create-member-api-key-options.interface.js.map +1 -0
- package/dist/interfaces/member-api-key-validation.interface.d.ts +17 -0
- package/dist/interfaces/member-api-key-validation.interface.js +2 -0
- package/dist/interfaces/member-api-key-validation.interface.js.map +1 -0
- package/dist/interfaces/request-identity-patch.interface.d.ts +4 -1
- package/dist/interfaces/request-permissions.interface.d.ts +5 -2
- package/dist/objects/{create-workspace-api-key-result.object.d.ts → create-member-api-key-result.object.d.ts} +3 -3
- package/dist/objects/{create-workspace-api-key-result.object.js → create-member-api-key-result.object.js} +10 -10
- package/dist/objects/create-member-api-key-result.object.js.map +1 -0
- package/dist/objects/member-api-key-permission-option.object.d.ts +10 -0
- package/dist/objects/{workspace-api-key-permission-option.object.js → member-api-key-permission-option.object.js} +12 -12
- package/dist/objects/member-api-key-permission-option.object.js.map +1 -0
- package/dist/policies/create-scope-policy.d.ts +7 -1
- package/dist/policies/create-scope-policy.js +7 -1
- package/dist/policies/create-scope-policy.js.map +1 -1
- package/dist/policies/user-scope.policy.d.ts +2 -0
- package/dist/policies/user-scope.policy.js +2 -0
- package/dist/policies/user-scope.policy.js.map +1 -1
- package/dist/policies/workspace-scope.policy.d.ts +2 -0
- package/dist/policies/workspace-scope.policy.js +2 -0
- package/dist/policies/workspace-scope.policy.js.map +1 -1
- package/dist/resolvers/auth.resolver.d.ts +85 -18
- package/dist/resolvers/auth.resolver.js +90 -18
- package/dist/resolvers/auth.resolver.js.map +1 -1
- package/dist/resolvers/member-api-key.resolver.d.ts +46 -0
- package/dist/resolvers/member-api-key.resolver.js +109 -0
- package/dist/resolvers/member-api-key.resolver.js.map +1 -0
- package/dist/resolvers/member.resolver.d.ts +26 -11
- package/dist/resolvers/member.resolver.js +37 -12
- package/dist/resolvers/member.resolver.js.map +1 -1
- package/dist/resolvers/session.resolver.d.ts +59 -12
- package/dist/resolvers/session.resolver.js +59 -12
- package/dist/resolvers/session.resolver.js.map +1 -1
- package/dist/resolvers/user-api-key.resolver.d.ts +26 -5
- package/dist/resolvers/user-api-key.resolver.js +26 -5
- package/dist/resolvers/user-api-key.resolver.js.map +1 -1
- package/dist/resolvers/user.resolver.d.ts +114 -19
- package/dist/resolvers/user.resolver.js +114 -19
- package/dist/resolvers/user.resolver.js.map +1 -1
- package/dist/resolvers/workspace.resolver.d.ts +39 -17
- package/dist/resolvers/workspace.resolver.js +42 -20
- package/dist/resolvers/workspace.resolver.js.map +1 -1
- package/dist/services/account.service.d.ts +11 -2
- package/dist/services/account.service.js +11 -2
- package/dist/services/account.service.js.map +1 -1
- package/dist/services/auth.service.d.ts +132 -27
- package/dist/services/auth.service.js +132 -27
- package/dist/services/auth.service.js.map +1 -1
- package/dist/services/member-api-key.service.d.ts +76 -0
- package/dist/services/{workspace-api-key.service.js → member-api-key.service.js} +117 -54
- package/dist/services/member-api-key.service.js.map +1 -0
- package/dist/services/member.service.d.ts +111 -20
- package/dist/services/member.service.js +153 -35
- package/dist/services/member.service.js.map +1 -1
- package/dist/services/session.service.d.ts +37 -10
- package/dist/services/session.service.js +69 -10
- package/dist/services/session.service.js.map +1 -1
- package/dist/services/user-api-key.service.d.ts +40 -7
- package/dist/services/user-api-key.service.js +43 -8
- package/dist/services/user-api-key.service.js.map +1 -1
- package/dist/services/user-deletion.service.d.ts +7 -1
- package/dist/services/user-deletion.service.js +7 -1
- package/dist/services/user-deletion.service.js.map +1 -1
- package/dist/services/user.service.d.ts +109 -20
- package/dist/services/user.service.js +109 -20
- package/dist/services/user.service.js.map +1 -1
- package/dist/services/workspace.service.d.ts +50 -11
- package/dist/services/workspace.service.js +51 -20
- package/dist/services/workspace.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/api-key-validation.type.d.ts +2 -2
- package/dist/types/api-key.type.d.ts +3 -3
- package/dist/types/lowercase-identifier.type.d.ts +4 -1
- package/dist/utils/api-key-credential.util.d.ts +12 -2
- package/dist/utils/api-key-credential.util.js +12 -2
- package/dist/utils/api-key-credential.util.js.map +1 -1
- package/dist/utils/api-key-permissions.util.d.ts +16 -4
- package/dist/utils/api-key-permissions.util.js +15 -3
- package/dist/utils/api-key-permissions.util.js.map +1 -1
- package/dist/utils/append-metadata.util.d.ts +6 -1
- package/dist/utils/append-metadata.util.js +6 -1
- package/dist/utils/append-metadata.util.js.map +1 -1
- package/dist/utils/apply-auth-response-cookies.util.d.ts +4 -1
- package/dist/utils/apply-auth-response-cookies.util.js +4 -1
- package/dist/utils/apply-auth-response-cookies.util.js.map +1 -1
- package/dist/utils/auth-role.util.d.ts +50 -8
- package/dist/utils/auth-role.util.js +50 -8
- package/dist/utils/auth-role.util.js.map +1 -1
- package/dist/utils/authorize.util.d.ts +6 -1
- package/dist/utils/authorize.util.js +6 -1
- package/dist/utils/authorize.util.js.map +1 -1
- package/dist/utils/build-request-ability.util.d.ts +5 -1
- package/dist/utils/build-request-ability.util.js +11 -17
- package/dist/utils/build-request-ability.util.js.map +1 -1
- package/dist/utils/can.util.d.ts +7 -1
- package/dist/utils/can.util.js +7 -1
- package/dist/utils/can.util.js.map +1 -1
- package/dist/utils/create-email-and-password-config.d.ts +8 -0
- package/dist/utils/create-email-and-password-config.js +8 -0
- package/dist/utils/create-email-and-password-config.js.map +1 -1
- package/dist/utils/create-email-verification-config.d.ts +6 -1
- package/dist/utils/create-email-verification-config.js +6 -1
- package/dist/utils/create-email-verification-config.js.map +1 -1
- package/dist/utils/create-generic-oauth-config.d.ts +7 -1
- package/dist/utils/create-generic-oauth-config.js +7 -1
- package/dist/utils/create-generic-oauth-config.js.map +1 -1
- package/dist/utils/create-oidc-config.d.ts +5 -0
- package/dist/utils/create-oidc-config.js +5 -0
- package/dist/utils/create-oidc-config.js.map +1 -1
- package/dist/utils/create-permission-enum.util.d.ts +5 -1
- package/dist/utils/create-permission-enum.util.js +5 -1
- package/dist/utils/create-permission-enum.util.js.map +1 -1
- package/dist/utils/create-social-provider-config.d.ts +7 -0
- package/dist/utils/create-social-provider-config.js +7 -0
- package/dist/utils/create-social-provider-config.js.map +1 -1
- package/dist/utils/create-social-providers-config.d.ts +6 -0
- package/dist/utils/create-social-providers-config.js +6 -0
- package/dist/utils/create-social-providers-config.js.map +1 -1
- package/dist/utils/create-user-config.d.ts +7 -1
- package/dist/utils/create-user-config.js +7 -1
- package/dist/utils/create-user-config.js.map +1 -1
- package/dist/utils/estimate-entropy.d.ts +0 -1
- package/dist/utils/estimate-entropy.js +0 -1
- package/dist/utils/estimate-entropy.js.map +1 -1
- package/dist/utils/extend-ability.util.d.ts +9 -1
- package/dist/utils/extend-ability.util.js +24 -1
- package/dist/utils/extend-ability.util.js.map +1 -1
- package/dist/utils/extract-api-key.util.d.ts +5 -1
- package/dist/utils/extract-api-key.util.js +5 -1
- package/dist/utils/extract-api-key.util.js.map +1 -1
- package/dist/utils/get-auth-ability.util.d.ts +1 -0
- package/dist/utils/get-auth-ability.util.js +1 -0
- package/dist/utils/get-auth-ability.util.js.map +1 -1
- package/dist/utils/get-current-api-key.util.d.ts +5 -1
- package/dist/utils/get-current-api-key.util.js +5 -1
- package/dist/utils/get-current-api-key.util.js.map +1 -1
- package/dist/utils/has-oidc-env-config.d.ts +4 -0
- package/dist/utils/has-oidc-env-config.js +4 -0
- package/dist/utils/has-oidc-env-config.js.map +1 -1
- package/dist/utils/has-social-provider-credential-env-config.d.ts +5 -0
- package/dist/utils/has-social-provider-credential-env-config.js +5 -0
- package/dist/utils/has-social-provider-credential-env-config.js.map +1 -1
- package/dist/utils/has-social-provider-env-config.d.ts +5 -0
- package/dist/utils/has-social-provider-env-config.js +5 -0
- package/dist/utils/has-social-provider-env-config.js.map +1 -1
- package/dist/utils/is-env-true.d.ts +5 -0
- package/dist/utils/is-env-true.js +5 -0
- package/dist/utils/is-env-true.js.map +1 -1
- package/dist/utils/omit-credentials.util.d.ts +7 -1
- package/dist/utils/omit-credentials.util.js +7 -1
- package/dist/utils/omit-credentials.util.js.map +1 -1
- package/dist/utils/permission-grants.util.d.ts +28 -4
- package/dist/utils/permission-grants.util.js +30 -4
- package/dist/utils/permission-grants.util.js.map +1 -1
- package/dist/utils/resolve-auth-catalog.util.d.ts +6 -1
- package/dist/utils/resolve-auth-catalog.util.js +6 -1
- package/dist/utils/resolve-auth-catalog.util.js.map +1 -1
- package/dist/utils/resolve-effective-permissions.util.d.ts +21 -3
- package/dist/utils/resolve-effective-permissions.util.js +21 -3
- package/dist/utils/resolve-effective-permissions.util.js.map +1 -1
- package/dist/utils/resolve-oidc-prompt.d.ts +4 -0
- package/dist/utils/resolve-oidc-prompt.js +4 -0
- package/dist/utils/resolve-oidc-prompt.js.map +1 -1
- package/dist/utils/resolve-oidc-scopes.d.ts +4 -0
- package/dist/utils/resolve-oidc-scopes.js +4 -0
- package/dist/utils/resolve-oidc-scopes.js.map +1 -1
- package/dist/utils/resolve-request-member.util.d.ts +7 -0
- package/dist/utils/resolve-request-member.util.js +27 -0
- package/dist/utils/resolve-request-member.util.js.map +1 -0
- package/dist/utils/resolve-request-permissions.util.d.ts +10 -2
- package/dist/utils/resolve-request-permissions.util.js +21 -18
- package/dist/utils/resolve-request-permissions.util.js.map +1 -1
- package/dist/utils/resolve-required-oidc-env.d.ts +5 -0
- package/dist/utils/resolve-required-oidc-env.js +5 -0
- package/dist/utils/resolve-required-oidc-env.js.map +1 -1
- package/dist/utils/resolve-required-social-provider-env.d.ts +6 -0
- package/dist/utils/resolve-required-social-provider-env.js +6 -0
- package/dist/utils/resolve-required-social-provider-env.js.map +1 -1
- package/dist/utils/resolve-secret.d.ts +5 -0
- package/dist/utils/resolve-secret.js +5 -0
- package/dist/utils/resolve-secret.js.map +1 -1
- package/dist/utils/resolve-social-provider-enabled.d.ts +5 -0
- package/dist/utils/resolve-social-provider-enabled.js +5 -0
- package/dist/utils/resolve-social-provider-enabled.js.map +1 -1
- package/dist/utils/run-auth-query.d.ts +3 -0
- package/dist/utils/run-auth-query.js +3 -0
- package/dist/utils/run-auth-query.js.map +1 -1
- package/dist/utils/serialize-ability-rules.util.d.ts +5 -1
- package/dist/utils/serialize-ability-rules.util.js +15 -1
- package/dist/utils/serialize-ability-rules.util.js.map +1 -1
- package/dist/utils/split-auth-providers.d.ts +5 -1
- package/dist/utils/split-auth-providers.js +6 -4
- package/dist/utils/split-auth-providers.js.map +1 -1
- package/dist/workspace.constants.d.ts +3 -3
- package/dist/workspace.constants.js +6 -2
- package/dist/workspace.constants.js.map +1 -1
- package/package.json +17 -23
- package/dist/connections/workspace-api-key.connection-definition.d.ts +0 -13
- package/dist/connections/workspace-api-key.connection-definition.js.map +0 -1
- package/dist/entities/workspace-api-key.entity.js.map +0 -1
- package/dist/enums/workspace-api-key-permission.enum.js.map +0 -1
- package/dist/inputs/create-workspace-api-key.input.js.map +0 -1
- package/dist/inputs/update-workspace-api-key.input.js.map +0 -1
- package/dist/interfaces/workspace-api-key-validation.interface.d.ts +0 -11
- package/dist/interfaces/workspace-api-key-validation.interface.js +0 -2
- package/dist/interfaces/workspace-api-key-validation.interface.js.map +0 -1
- package/dist/objects/create-workspace-api-key-result.object.js.map +0 -1
- package/dist/objects/workspace-api-key-permission-option.object.d.ts +0 -10
- package/dist/objects/workspace-api-key-permission-option.object.js.map +0 -1
- package/dist/resolvers/workspace-api-key.resolver.d.ts +0 -25
- package/dist/resolvers/workspace-api-key.resolver.js +0 -84
- package/dist/resolvers/workspace-api-key.resolver.js.map +0 -1
- package/dist/services/workspace-api-key.service.d.ts +0 -41
- package/dist/services/workspace-api-key.service.js.map +0 -1
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import type { createAuthInstance } from "./create-auth-instance.js";
|
|
2
2
|
type AuthInstance = ReturnType<typeof createAuthInstance>;
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* The upstream API surface consumed by application services.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
4
7
|
export type BetterAuthAdapter = Pick<AuthInstance, "$context"> & {
|
|
5
8
|
api: Pick<AuthInstance["api"], "accountInfo" | "changeEmail" | "changePassword" | "deleteUser" | "getAccessToken" | "getSession" | "linkSocialAccount" | "listSessions" | "listUserAccounts" | "refreshToken" | "requestPasswordReset" | "resetPassword" | "revokeOtherSessions" | "revokeSession" | "revokeSessions" | "sendVerificationEmail" | "setPassword" | "signInEmail" | "signInSocial" | "signOut" | "signUpEmail" | "unlinkAccount" | "updateUser" | "verifyPassword">;
|
|
6
9
|
};
|
|
7
10
|
/**
|
|
8
11
|
* Adapts the untyped Nest injection boundary once, using the factory's upstream types.
|
|
9
12
|
* Domain result normalization and response cookies remain in services and applyAuthResponseCookies.
|
|
13
|
+
* @param auth - Configured Better Auth instance.
|
|
14
|
+
* @returns Better Auth instance viewed through the internal adapter interface.
|
|
10
15
|
* @internal
|
|
11
16
|
*/
|
|
12
17
|
export declare function adaptBetterAuth(auth: unknown): BetterAuthAdapter;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Adapts the untyped Nest injection boundary once, using the factory's upstream types.
|
|
3
3
|
* Domain result normalization and response cookies remain in services and applyAuthResponseCookies.
|
|
4
|
+
* @param auth - Configured Better Auth instance.
|
|
5
|
+
* @returns Better Auth instance viewed through the internal adapter interface.
|
|
4
6
|
* @internal
|
|
5
7
|
*/
|
|
6
8
|
export function adaptBetterAuth(auth) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"better-auth-adapter.js","sourceRoot":"","sources":["../../src/infrastructure/better-auth-adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"better-auth-adapter.js","sourceRoot":"","sources":["../../src/infrastructure/better-auth-adapter.ts"],"names":[],"mappings":"AAsCA;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,IAAa;IAC3C,OAAO,IAAyB,CAAC;AACnC,CAAC"}
|
|
@@ -4,7 +4,25 @@ import type { Mailer } from "@nest-boot/mailer";
|
|
|
4
4
|
import { betterAuth, type BetterAuthOptions } from "better-auth";
|
|
5
5
|
import { type AuthModuleOptions } from "../auth-module-options.interface.js";
|
|
6
6
|
import type { UserDeletionService } from "../services/user-deletion.service.js";
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* Resolves framework configuration before constructing the upstream instance.
|
|
9
|
+
* @param options - Authentication module configuration.
|
|
10
|
+
* @param orm - MikroORM instance used for persistence.
|
|
11
|
+
* @param mailer - Mailer used to deliver authentication emails.
|
|
12
|
+
* @param hashService - Service for hashing and verifying passwords.
|
|
13
|
+
* @param userDeletionService - Service that deletes users and their related records.
|
|
14
|
+
* @returns Better Auth options assembled from the module configuration.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
8
17
|
export declare function resolveBetterAuthOptions(options: AuthModuleOptions, orm: MikroORM, mailer: Mailer, hashService: HashService, userDeletionService: UserDeletionService): BetterAuthOptions;
|
|
9
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Constructs the single BetterAuth instance used by Nest providers.
|
|
20
|
+
* @param options - Authentication module configuration.
|
|
21
|
+
* @param orm - MikroORM instance used for persistence.
|
|
22
|
+
* @param mailer - Mailer used to deliver authentication emails.
|
|
23
|
+
* @param hashService - Service for hashing and verifying passwords.
|
|
24
|
+
* @param userDeletionService - Service that deletes users and their related records.
|
|
25
|
+
* @returns Configured Better Auth instance.
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
10
28
|
export declare function createAuthInstance(options: AuthModuleOptions, orm: MikroORM, mailer: Mailer, hashService: HashService, userDeletionService: UserDeletionService): ReturnType<typeof betterAuth>;
|
|
@@ -20,7 +20,16 @@ import { runAuthQuery } from "../utils/run-auth-query.js";
|
|
|
20
20
|
import { splitAuthProviders } from "../utils/split-auth-providers.js";
|
|
21
21
|
import { DEFAULT_WORKSPACE_CREATOR_ROLE, DEFAULT_WORKSPACE_ROLE, } from "../workspace.constants.js";
|
|
22
22
|
import { RequestIdentity } from "./request-identity.js";
|
|
23
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Resolves framework configuration before constructing the upstream instance.
|
|
25
|
+
* @param options - Authentication module configuration.
|
|
26
|
+
* @param orm - MikroORM instance used for persistence.
|
|
27
|
+
* @param mailer - Mailer used to deliver authentication emails.
|
|
28
|
+
* @param hashService - Service for hashing and verifying passwords.
|
|
29
|
+
* @param userDeletionService - Service that deletes users and their related records.
|
|
30
|
+
* @returns Better Auth options assembled from the module configuration.
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
24
33
|
export function resolveBetterAuthOptions(options, orm, mailer, hashService, userDeletionService) {
|
|
25
34
|
validateAuthOptions(options);
|
|
26
35
|
const secret = resolveSecret(options);
|
|
@@ -66,10 +75,23 @@ export function resolveBetterAuthOptions(options, orm, mailer, hashService, user
|
|
|
66
75
|
copyBetterAuthOptions(betterAuthOptions, options);
|
|
67
76
|
return betterAuthOptions;
|
|
68
77
|
}
|
|
69
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* Constructs the single BetterAuth instance used by Nest providers.
|
|
80
|
+
* @param options - Authentication module configuration.
|
|
81
|
+
* @param orm - MikroORM instance used for persistence.
|
|
82
|
+
* @param mailer - Mailer used to deliver authentication emails.
|
|
83
|
+
* @param hashService - Service for hashing and verifying passwords.
|
|
84
|
+
* @param userDeletionService - Service that deletes users and their related records.
|
|
85
|
+
* @returns Configured Better Auth instance.
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
70
88
|
export function createAuthInstance(options, orm, mailer, hashService, userDeletionService) {
|
|
71
89
|
return betterAuth(resolveBetterAuthOptions(options, orm, mailer, hashService, userDeletionService));
|
|
72
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Validates authentication options before constructing Better Auth.
|
|
93
|
+
* @param options - Authentication module configuration.
|
|
94
|
+
*/
|
|
73
95
|
function validateAuthOptions(options) {
|
|
74
96
|
const { roles: userRoles, permissions: userPermissions } = resolveAuthCatalog(options, "user");
|
|
75
97
|
const { roles: workspaceRoles, permissions: workspacePermissions } = resolveAuthCatalog(options, "workspace");
|
|
@@ -78,9 +100,9 @@ function validateAuthOptions(options) {
|
|
|
78
100
|
if (options.apiKey &&
|
|
79
101
|
("defaultPermissions" in options.apiKey ||
|
|
80
102
|
"allowedPermissions" in options.apiKey)) {
|
|
81
|
-
throw new Error("Configure API key permissions under apiKey.user or apiKey.
|
|
103
|
+
throw new Error("Configure API key permissions under apiKey.user or apiKey.member");
|
|
82
104
|
}
|
|
83
|
-
for (const scope of ["user", "
|
|
105
|
+
for (const scope of ["user", "member"]) {
|
|
84
106
|
const { permissions: catalog, defaults } = resolveApiKeyPermissionCatalog(options, scope);
|
|
85
107
|
const configured = options.apiKey?.[scope];
|
|
86
108
|
const allowed = configured?.allowedPermissions ?? catalog;
|
|
@@ -93,6 +115,11 @@ function validateAuthOptions(options) {
|
|
|
93
115
|
assertAuthRolesExist(workspaceRoles, [options.workspace?.defaultRole ?? DEFAULT_WORKSPACE_ROLE], "workspace.defaultRole");
|
|
94
116
|
assertAuthRolesExist(workspaceRoles, [options.workspace?.creatorRole ?? DEFAULT_WORKSPACE_CREATOR_ROLE], "workspace.creatorRole");
|
|
95
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Copies supported module options into the Better Auth configuration.
|
|
120
|
+
* @param target - Object that receives the configuration.
|
|
121
|
+
* @param source - Source value to read from.
|
|
122
|
+
*/
|
|
96
123
|
function copyBetterAuthOptions(target, source) {
|
|
97
124
|
if (source.basePath !== undefined)
|
|
98
125
|
target.basePath = source.basePath;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-auth-instance.js","sourceRoot":"","sources":["../../src/infrastructure/create-auth-instance.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAA0B,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAElD,OAAO,EACL,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AACtF,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,4BAA4B,EAAE,MAAM,8CAA8C,CAAC;AAC5F,OAAO,EAAE,6BAA6B,EAAE,MAAM,8CAA8C,CAAC;AAC7F,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,2BAA2B,EAAE,MAAM,4CAA4C,CAAC;AACzF,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EACL,8BAA8B,EAC9B,sBAAsB,GACvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD
|
|
1
|
+
{"version":3,"file":"create-auth-instance.js","sourceRoot":"","sources":["../../src/infrastructure/create-auth-instance.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAA0B,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAElD,OAAO,EACL,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AACtF,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,4BAA4B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AQ,CAAC;IACrE,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS;QAAE,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IAClE,IAAI,MAAM,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;QACxC,MAAM,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;IAChD,CAAC;AACH,CAAC"}
|
|
@@ -4,6 +4,10 @@ type ExecutionContext = "authentication" | "invitation-identity";
|
|
|
4
4
|
* Installs the explicit infrastructure-owned execution boundaries for auth services.
|
|
5
5
|
* Domain methods only use their injected manager. Unlisted methods keep request RLS.
|
|
6
6
|
* Contextual instances are created per invocation, never by mutating a shared EM.
|
|
7
|
+
* @param em - Entity manager used for persistence.
|
|
8
|
+
* @param create - Mock implementation of the create operation.
|
|
9
|
+
* @param operations - Concurrent operations to execute.
|
|
10
|
+
* @returns Authentication service bound to the active request context.
|
|
7
11
|
* @internal
|
|
8
12
|
*/
|
|
9
13
|
export declare function createContextualAuthService<T extends object>(em: EntityManager, create: (em: EntityManager) => T, operations: Partial<Record<keyof T, ExecutionContext>>): T;
|
|
@@ -5,6 +5,10 @@ import { runAuthQuery } from "../utils/run-auth-query.js";
|
|
|
5
5
|
* Installs the explicit infrastructure-owned execution boundaries for auth services.
|
|
6
6
|
* Domain methods only use their injected manager. Unlisted methods keep request RLS.
|
|
7
7
|
* Contextual instances are created per invocation, never by mutating a shared EM.
|
|
8
|
+
* @param em - Entity manager used for persistence.
|
|
9
|
+
* @param create - Mock implementation of the create operation.
|
|
10
|
+
* @param operations - Concurrent operations to execute.
|
|
11
|
+
* @returns Authentication service bound to the active request context.
|
|
8
12
|
* @internal
|
|
9
13
|
*/
|
|
10
14
|
export function createContextualAuthService(em, create, operations) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-contextual-auth-service.js","sourceRoot":"","sources":["../../src/infrastructure/create-contextual-auth-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAI1D
|
|
1
|
+
{"version":3,"file":"create-contextual-auth-service.js","sourceRoot":"","sources":["../../src/infrastructure/create-contextual-auth-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAI1D;;;;;;;;;GASG;AACH,MAAM,UAAU,2BAA2B,CACzC,EAAiB,EACjB,MAAgC,EAChC,UAAsD;IAEtD,MAAM,OAAO,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IAC3B,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACzD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE;YACnC,YAAY,EAAE,IAAI;YAClB,KAAK,EAAE,KAAK,EAAE,GAAG,IAAe,EAAE,EAAE;gBAClC,MAAM,MAAM,GAAG,KAAK,EAAE,OAAsB,EAAE,EAAE;oBAC9C,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;oBACjC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAE7B,CAAC;oBACb,OAAO,MAAM,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;gBACrD,CAAC,CAAC;gBACF,IAAI,OAAO,KAAK,gBAAgB;oBAAE,OAAO,MAAM,YAAY,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;gBAExE,MAAM,OAAO,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;g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CACJ,CAAC;YACR,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -6,41 +6,112 @@ import { User } from "../entities/user.entity.js";
|
|
|
6
6
|
import { Workspace } from "../entities/workspace.entity.js";
|
|
7
7
|
import type { RequestIdentityPatch } from "../interfaces/request-identity-patch.interface.js";
|
|
8
8
|
import type { ApiKeyMetadata } from "../types/api-key-metadata.type.js";
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Owns request identity publication, authorization invalidation, and database scope.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
10
13
|
export declare class RequestIdentity {
|
|
11
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Returns the active request member, rejecting user API keys outside their membership.
|
|
16
|
+
* @returns Active member in the selected workspace, or null if unavailable.
|
|
17
|
+
*/
|
|
18
|
+
static getCurrentMember(): Member | null;
|
|
19
|
+
/**
|
|
20
|
+
* Throws unless the supplied user is the authenticated user.
|
|
21
|
+
* @param user - The user whose account is being accessed.
|
|
22
|
+
*/
|
|
12
23
|
static assertCurrentUser(user: User): void;
|
|
13
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Authorizes an explicit self-service path without granting a general resource ability.
|
|
26
|
+
* @param user - The user whose account is being accessed.
|
|
27
|
+
*/
|
|
14
28
|
static assertUserSession(user: User): void;
|
|
15
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Throws unless the supplied session is the authenticated session.
|
|
31
|
+
* @param session - Session whose metadata is being accessed.
|
|
32
|
+
*/
|
|
16
33
|
static assertCurrentSession(session: Session): void;
|
|
17
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Throws unless the supplied workspace is selected for the current request.
|
|
36
|
+
* @param workspace - The workspace that scopes this operation.
|
|
37
|
+
*/
|
|
18
38
|
static assertCurrentWorkspace(workspace: Workspace): void;
|
|
19
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Throws unless the supplied member is the current workspace member.
|
|
41
|
+
* @param member - The workspace membership to inspect or change.
|
|
42
|
+
*/
|
|
20
43
|
static assertCurrentMember(member: Member | null | undefined): void;
|
|
21
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Matches credentials by both table and ID.
|
|
46
|
+
* @param apiKey - API key whose metadata is being accessed.
|
|
47
|
+
* @returns Whether the key matches the credential authenticating this request.
|
|
48
|
+
*/
|
|
22
49
|
static isCurrentApiKey(apiKey: ApiKeyMetadata): boolean;
|
|
23
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Rejects publishing an authenticating credential before its outer transaction commits.
|
|
52
|
+
* @param em - Entity manager used for persistence.
|
|
53
|
+
* @param apiKey - API key whose metadata is being accessed.
|
|
54
|
+
*/
|
|
24
55
|
static assertApiKeyCanCommit(em: EntityManager, apiKey: ApiKeyMetadata): void;
|
|
25
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Publishes only changes to the user represented by this request.
|
|
58
|
+
* @param em - Entity manager used for persistence.
|
|
59
|
+
* @param options - Authentication module configuration.
|
|
60
|
+
* @param user - The user whose account is being accessed.
|
|
61
|
+
*/
|
|
26
62
|
static updateUser(em: EntityManager, options: AuthModuleOptions, user: User): void;
|
|
27
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Publishes only current membership changes, clearing departed workspace scope.
|
|
65
|
+
* @param em - Entity manager used for persistence.
|
|
66
|
+
* @param options - Authentication module configuration.
|
|
67
|
+
* @param member - The workspace membership to inspect or change.
|
|
68
|
+
*/
|
|
28
69
|
static updateMember(em: EntityManager, options: AuthModuleOptions, member: Member): void;
|
|
29
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* Publishes committed credential changes or revokes the entire request.
|
|
72
|
+
* @param em - Entity manager used for persistence.
|
|
73
|
+
* @param options - Authentication module configuration.
|
|
74
|
+
* @param apiKey - API key whose metadata is being accessed.
|
|
75
|
+
* @param deleted - Whether the API key has been deleted.
|
|
76
|
+
*/
|
|
30
77
|
static updateApiKey(em: EntityManager, options: AuthModuleOptions, apiKey: ApiKeyMetadata, deleted?: boolean): void;
|
|
31
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* Prepares the request ability once, failing closed when configuration rejects.
|
|
80
|
+
* @param options - Authentication module configuration.
|
|
81
|
+
*/
|
|
32
82
|
static prepare(options: AuthModuleOptions): void;
|
|
33
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* Stages identity while authentication is being resolved, before a guard can run.
|
|
85
|
+
* @param patch - Identity fields to replace.
|
|
86
|
+
*/
|
|
34
87
|
static stage(patch: RequestIdentityPatch): void;
|
|
35
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* Rebuilds one ability, never retaining old grants on failure.
|
|
90
|
+
* @param options - Authentication module configuration.
|
|
91
|
+
*/
|
|
36
92
|
static refresh(options: AuthModuleOptions): void;
|
|
37
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Publishes a committed identity change; failures revoke the request instead of retaining stale grants.
|
|
95
|
+
* @param em - Entity manager used for persistence.
|
|
96
|
+
* @param options - Authentication module configuration.
|
|
97
|
+
* @param patch - Identity fields to replace.
|
|
98
|
+
*/
|
|
38
99
|
static update(em: EntityManager, options: AuthModuleOptions, patch: RequestIdentityPatch): void;
|
|
39
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* Removes all credentials without falling back to another authentication method.
|
|
102
|
+
* @param em - Entity manager used for persistence.
|
|
103
|
+
*/
|
|
40
104
|
static clear(em: EntityManager): void;
|
|
41
|
-
/**
|
|
105
|
+
/**
|
|
106
|
+
* Revokes workspace rules and rebuilds the remaining user ability after a committed change.
|
|
107
|
+
* @param em - Entity manager used for persistence.
|
|
108
|
+
* @param options - Authentication module configuration.
|
|
109
|
+
*/
|
|
42
110
|
static clearWorkspace(em: EntityManager, options: AuthModuleOptions): void;
|
|
43
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* Synchronizes only identity values; database policies never receive application permissions.
|
|
113
|
+
* @param em - Entity manager used for persistence.
|
|
114
|
+
*/
|
|
44
115
|
static syncDatabase(em: EntityManager): void;
|
|
45
116
|
private static databaseScope;
|
|
46
117
|
}
|
|
@@ -3,16 +3,34 @@ import { BadRequestException, ForbiddenException } from "@nestjs/common";
|
|
|
3
3
|
import { AuthAbility } from "../auth.ability.js";
|
|
4
4
|
import { API_KEY } from "../auth.constants.js";
|
|
5
5
|
import { Member } from "../entities/member.entity.js";
|
|
6
|
+
import { MemberApiKey } from "../entities/member-api-key.entity.js";
|
|
6
7
|
import { Session } from "../entities/session.entity.js";
|
|
7
8
|
import { User } from "../entities/user.entity.js";
|
|
8
9
|
import { Workspace } from "../entities/workspace.entity.js";
|
|
9
|
-
import { WorkspaceApiKey } from "../entities/workspace-api-key.entity.js";
|
|
10
10
|
import { buildRequestAbility } from "../utils/build-request-ability.util.js";
|
|
11
11
|
import { getCurrentApiKey } from "../utils/get-current-api-key.util.js";
|
|
12
|
+
import { resolveRequestMember } from "../utils/resolve-request-member.util.js";
|
|
12
13
|
import { invalidateRequestPermissions } from "../utils/resolve-request-permissions.util.js";
|
|
13
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Owns request identity publication, authorization invalidation, and database scope.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
14
18
|
export class RequestIdentity {
|
|
15
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Returns the active request member, rejecting user API keys outside their membership.
|
|
21
|
+
* @returns Active member in the selected workspace, or null if unavailable.
|
|
22
|
+
*/
|
|
23
|
+
static getCurrentMember() {
|
|
24
|
+
const member = resolveRequestMember();
|
|
25
|
+
if (getCurrentApiKey() && RequestContext.get(User) && !member) {
|
|
26
|
+
throw new ForbiddenException("The API key owner is not a member of this workspace");
|
|
27
|
+
}
|
|
28
|
+
return member;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Throws unless the supplied user is the authenticated user.
|
|
32
|
+
* @param user - The user whose account is being accessed.
|
|
33
|
+
*/
|
|
16
34
|
static assertCurrentUser(user) {
|
|
17
35
|
const currentUser = RequestContext.isActive()
|
|
18
36
|
? RequestContext.get(User)
|
|
@@ -21,14 +39,20 @@ export class RequestIdentity {
|
|
|
21
39
|
throw new ForbiddenException("The operation belongs to another user");
|
|
22
40
|
}
|
|
23
41
|
}
|
|
24
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Authorizes an explicit self-service path without granting a general resource ability.
|
|
44
|
+
* @param user - The user whose account is being accessed.
|
|
45
|
+
*/
|
|
25
46
|
static assertUserSession(user) {
|
|
26
47
|
this.assertCurrentUser(user);
|
|
27
48
|
if (getCurrentApiKey()) {
|
|
28
49
|
throw new ForbiddenException("This self-service operation requires a user session");
|
|
29
50
|
}
|
|
30
51
|
}
|
|
31
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Throws unless the supplied session is the authenticated session.
|
|
54
|
+
* @param session - Session whose metadata is being accessed.
|
|
55
|
+
*/
|
|
32
56
|
static assertCurrentSession(session) {
|
|
33
57
|
const currentSession = RequestContext.isActive()
|
|
34
58
|
? RequestContext.get(Session)
|
|
@@ -37,7 +61,10 @@ export class RequestIdentity {
|
|
|
37
61
|
throw new ForbiddenException("The operation belongs to another session");
|
|
38
62
|
}
|
|
39
63
|
}
|
|
40
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* Throws unless the supplied workspace is selected for the current request.
|
|
66
|
+
* @param workspace - The workspace that scopes this operation.
|
|
67
|
+
*/
|
|
41
68
|
static assertCurrentWorkspace(workspace) {
|
|
42
69
|
const currentWorkspace = RequestContext.isActive()
|
|
43
70
|
? RequestContext.get(Workspace)
|
|
@@ -47,7 +74,10 @@ export class RequestIdentity {
|
|
|
47
74
|
throw new ForbiddenException("The operation belongs to another workspace");
|
|
48
75
|
}
|
|
49
76
|
}
|
|
50
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* Throws unless the supplied member is the current workspace member.
|
|
79
|
+
* @param member - The workspace membership to inspect or change.
|
|
80
|
+
*/
|
|
51
81
|
static assertCurrentMember(member) {
|
|
52
82
|
const currentMember = RequestContext.isActive()
|
|
53
83
|
? RequestContext.get(Member)
|
|
@@ -58,26 +88,44 @@ export class RequestIdentity {
|
|
|
58
88
|
throw new ForbiddenException("The operation belongs to another workspace member");
|
|
59
89
|
}
|
|
60
90
|
}
|
|
61
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* Matches credentials by both table and ID.
|
|
93
|
+
* @param apiKey - API key whose metadata is being accessed.
|
|
94
|
+
* @returns Whether the key matches the credential authenticating this request.
|
|
95
|
+
*/
|
|
62
96
|
static isCurrentApiKey(apiKey) {
|
|
63
97
|
const current = getCurrentApiKey();
|
|
64
98
|
return (!!current &&
|
|
65
99
|
current.constructor === apiKey.constructor &&
|
|
66
100
|
current.id === apiKey.id);
|
|
67
101
|
}
|
|
68
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* Rejects publishing an authenticating credential before its outer transaction commits.
|
|
104
|
+
* @param em - Entity manager used for persistence.
|
|
105
|
+
* @param apiKey - API key whose metadata is being accessed.
|
|
106
|
+
*/
|
|
69
107
|
static assertApiKeyCanCommit(em, apiKey) {
|
|
70
108
|
if (this.isCurrentApiKey(apiKey) && em.isInTransaction()) {
|
|
71
109
|
throw new BadRequestException("Change the authenticating API key outside an active transaction");
|
|
72
110
|
}
|
|
73
111
|
}
|
|
74
|
-
/**
|
|
112
|
+
/**
|
|
113
|
+
* Publishes only changes to the user represented by this request.
|
|
114
|
+
* @param em - Entity manager used for persistence.
|
|
115
|
+
* @param options - Authentication module configuration.
|
|
116
|
+
* @param user - The user whose account is being accessed.
|
|
117
|
+
*/
|
|
75
118
|
static updateUser(em, options, user) {
|
|
76
119
|
if (!RequestContext.isActive() || RequestContext.get(User)?.id !== user.id)
|
|
77
120
|
return;
|
|
78
121
|
this.update(em, options, { user });
|
|
79
122
|
}
|
|
80
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* Publishes only current membership changes, clearing departed workspace scope.
|
|
125
|
+
* @param em - Entity manager used for persistence.
|
|
126
|
+
* @param options - Authentication module configuration.
|
|
127
|
+
* @param member - The workspace membership to inspect or change.
|
|
128
|
+
*/
|
|
81
129
|
static updateMember(em, options, member) {
|
|
82
130
|
if (!RequestContext.isActive() ||
|
|
83
131
|
RequestContext.get(Member)?.id !== member.id)
|
|
@@ -87,7 +135,13 @@ export class RequestIdentity {
|
|
|
87
135
|
else
|
|
88
136
|
this.update(em, options, { member });
|
|
89
137
|
}
|
|
90
|
-
/**
|
|
138
|
+
/**
|
|
139
|
+
* Publishes committed credential changes or revokes the entire request.
|
|
140
|
+
* @param em - Entity manager used for persistence.
|
|
141
|
+
* @param options - Authentication module configuration.
|
|
142
|
+
* @param apiKey - API key whose metadata is being accessed.
|
|
143
|
+
* @param deleted - Whether the API key has been deleted.
|
|
144
|
+
*/
|
|
91
145
|
static updateApiKey(em, options, apiKey, deleted = false) {
|
|
92
146
|
if (!this.isCurrentApiKey(apiKey))
|
|
93
147
|
return;
|
|
@@ -98,13 +152,19 @@ export class RequestIdentity {
|
|
|
98
152
|
else
|
|
99
153
|
this.update(em, options, { apiKey });
|
|
100
154
|
}
|
|
101
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* Prepares the request ability once, failing closed when configuration rejects.
|
|
157
|
+
* @param options - Authentication module configuration.
|
|
158
|
+
*/
|
|
102
159
|
static prepare(options) {
|
|
103
160
|
if (!RequestContext.isActive() || RequestContext.get(AuthAbility))
|
|
104
161
|
return;
|
|
105
162
|
this.refresh(options);
|
|
106
163
|
}
|
|
107
|
-
/**
|
|
164
|
+
/**
|
|
165
|
+
* Stages identity while authentication is being resolved, before a guard can run.
|
|
166
|
+
* @param patch - Identity fields to replace.
|
|
167
|
+
*/
|
|
108
168
|
static stage(patch) {
|
|
109
169
|
if (!RequestContext.isActive())
|
|
110
170
|
return;
|
|
@@ -121,7 +181,10 @@ export class RequestIdentity {
|
|
|
121
181
|
invalidateRequestPermissions();
|
|
122
182
|
RequestContext.set(AuthAbility, null);
|
|
123
183
|
}
|
|
124
|
-
/**
|
|
184
|
+
/**
|
|
185
|
+
* Rebuilds one ability, never retaining old grants on failure.
|
|
186
|
+
* @param options - Authentication module configuration.
|
|
187
|
+
*/
|
|
125
188
|
static refresh(options) {
|
|
126
189
|
if (!RequestContext.isActive())
|
|
127
190
|
return;
|
|
@@ -129,16 +192,24 @@ export class RequestIdentity {
|
|
|
129
192
|
RequestContext.set(AuthAbility, new AuthAbility());
|
|
130
193
|
RequestContext.set(AuthAbility, buildRequestAbility(options));
|
|
131
194
|
}
|
|
132
|
-
/**
|
|
195
|
+
/**
|
|
196
|
+
* Publishes a committed identity change; failures revoke the request instead of retaining stale grants.
|
|
197
|
+
* @param em - Entity manager used for persistence.
|
|
198
|
+
* @param options - Authentication module configuration.
|
|
199
|
+
* @param patch - Identity fields to replace.
|
|
200
|
+
*/
|
|
133
201
|
static update(em, options, patch) {
|
|
134
202
|
if (!RequestContext.isActive())
|
|
135
203
|
return;
|
|
136
|
-
const previousScope = JSON.stringify(this.databaseScope());
|
|
137
204
|
this.stage(patch);
|
|
138
205
|
try {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
206
|
+
const currentScope = em.getSessionContext();
|
|
207
|
+
const scope = this.databaseScope();
|
|
208
|
+
// Compare with the published scope: ORM entities may already be mutated.
|
|
209
|
+
if (currentScope &&
|
|
210
|
+
(currentScope.role !== scope.role ||
|
|
211
|
+
Object.entries(scope.variables).some(([key, value]) => currentScope.variables?.[key] !== value)))
|
|
212
|
+
em.setSessionContext(scope);
|
|
142
213
|
this.refresh(options);
|
|
143
214
|
}
|
|
144
215
|
catch (error) {
|
|
@@ -146,7 +217,10 @@ export class RequestIdentity {
|
|
|
146
217
|
throw error;
|
|
147
218
|
}
|
|
148
219
|
}
|
|
149
|
-
/**
|
|
220
|
+
/**
|
|
221
|
+
* Removes all credentials without falling back to another authentication method.
|
|
222
|
+
* @param em - Entity manager used for persistence.
|
|
223
|
+
*/
|
|
150
224
|
static clear(em) {
|
|
151
225
|
this.stage({
|
|
152
226
|
user: null,
|
|
@@ -161,18 +235,29 @@ export class RequestIdentity {
|
|
|
161
235
|
if (em.getSessionContext())
|
|
162
236
|
em.setSessionContext({
|
|
163
237
|
role: "anonymous",
|
|
164
|
-
variables: {
|
|
238
|
+
variables: {
|
|
239
|
+
"app.user.id": "",
|
|
240
|
+
"app.workspace.id": "",
|
|
241
|
+
"app.member.id": "",
|
|
242
|
+
},
|
|
165
243
|
});
|
|
166
244
|
}
|
|
167
|
-
/**
|
|
245
|
+
/**
|
|
246
|
+
* Revokes workspace rules and rebuilds the remaining user ability after a committed change.
|
|
247
|
+
* @param em - Entity manager used for persistence.
|
|
248
|
+
* @param options - Authentication module configuration.
|
|
249
|
+
*/
|
|
168
250
|
static clearWorkspace(em, options) {
|
|
169
|
-
if (getCurrentApiKey() instanceof
|
|
251
|
+
if (getCurrentApiKey() instanceof MemberApiKey) {
|
|
170
252
|
this.clear(em);
|
|
171
253
|
return;
|
|
172
254
|
}
|
|
173
255
|
this.update(em, options, { member: null, workspace: null });
|
|
174
256
|
}
|
|
175
|
-
/**
|
|
257
|
+
/**
|
|
258
|
+
* Synchronizes only identity values; database policies never receive application permissions.
|
|
259
|
+
* @param em - Entity manager used for persistence.
|
|
260
|
+
*/
|
|
176
261
|
static syncDatabase(em) {
|
|
177
262
|
em.setSessionContext(this.databaseScope());
|
|
178
263
|
}
|
|
@@ -180,14 +265,14 @@ export class RequestIdentity {
|
|
|
180
265
|
const user = RequestContext.get(User);
|
|
181
266
|
const apiKey = getCurrentApiKey();
|
|
182
267
|
const workspace = RequestContext.get(Workspace);
|
|
183
|
-
const member =
|
|
268
|
+
const member = resolveRequestMember();
|
|
184
269
|
const authenticated = Boolean(user ?? apiKey);
|
|
185
|
-
const canUseWorkspace = Boolean(member ?? (apiKey && !user));
|
|
186
270
|
return {
|
|
187
271
|
role: authenticated ? "authenticated" : "anonymous",
|
|
188
272
|
variables: {
|
|
189
273
|
"app.user.id": user?.id ?? "",
|
|
190
|
-
"app.workspace.id": !authenticated ||
|
|
274
|
+
"app.workspace.id": !authenticated || member ? (workspace?.id ?? "") : "",
|
|
275
|
+
"app.member.id": member?.id ?? "",
|
|
191
276
|
},
|
|
192
277
|
};
|
|
193
278
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-identity.js","sourceRoot":"","sources":["../../src/infrastructure/request-identity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEzE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"request-identity.js","sourceRoot":"","sources":["../../src/infrastructure/request-identity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEzE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAA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