@techelusive/nest-auth 0.0.0-stage → 0.2.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/CHANGELOG.md +64 -0
- package/LICENSE +21 -0
- package/README.md +204 -2
- package/api/openapi.json +4399 -0
- package/api/techelusive-authentication.postman_collection.json +3178 -0
- package/dist/auth-options.d.ts +156 -0
- package/dist/auth-options.js +3 -0
- package/dist/auth-options.js.map +1 -0
- package/dist/auth-options.validation.d.ts +9 -0
- package/dist/auth-options.validation.js +74 -0
- package/dist/auth-options.validation.js.map +1 -0
- package/dist/auth.module.d.ts +38 -0
- package/dist/auth.module.js +173 -0
- package/dist/auth.module.js.map +1 -0
- package/dist/common/auth-error.d.ts +16 -0
- package/dist/common/auth-error.js +23 -0
- package/dist/common/auth-error.js.map +1 -0
- package/dist/common/auth-exception.filter.d.ts +24 -0
- package/dist/common/auth-exception.filter.js +66 -0
- package/dist/common/auth-exception.filter.js.map +1 -0
- package/dist/common/crypto/jwt.d.ts +89 -0
- package/dist/common/crypto/jwt.js +144 -0
- package/dist/common/crypto/jwt.js.map +1 -0
- package/dist/common/crypto/random-secrets.d.ts +78 -0
- package/dist/common/crypto/random-secrets.js +113 -0
- package/dist/common/crypto/random-secrets.js.map +1 -0
- package/dist/common/crypto/remote-public-keys.d.ts +49 -0
- package/dist/common/crypto/remote-public-keys.js +105 -0
- package/dist/common/crypto/remote-public-keys.js.map +1 -0
- package/dist/common/crypto/totp.d.ts +68 -0
- package/dist/common/crypto/totp.js +148 -0
- package/dist/common/crypto/totp.js.map +1 -0
- package/dist/common/encryption.service.d.ts +36 -0
- package/dist/common/encryption.service.js +111 -0
- package/dist/common/encryption.service.js.map +1 -0
- package/dist/common/identifiers.d.ts +48 -0
- package/dist/common/identifiers.js +89 -0
- package/dist/common/identifiers.js.map +1 -0
- package/dist/common/network-safety.d.ts +19 -0
- package/dist/common/network-safety.js +72 -0
- package/dist/common/network-safety.js.map +1 -0
- package/dist/common/rate-limiter.service.d.ts +63 -0
- package/dist/common/rate-limiter.service.js +158 -0
- package/dist/common/rate-limiter.service.js.map +1 -0
- package/dist/common/refresh-token-cookie.d.ts +78 -0
- package/dist/common/refresh-token-cookie.js +185 -0
- package/dist/common/refresh-token-cookie.js.map +1 -0
- package/dist/common/request-context.d.ts +14 -0
- package/dist/common/request-context.js +22 -0
- package/dist/common/request-context.js.map +1 -0
- package/dist/common/strict-validation.pipe.d.ts +8 -0
- package/dist/common/strict-validation.pipe.js +16 -0
- package/dist/common/strict-validation.pipe.js.map +1 -0
- package/dist/common/time.d.ts +15 -0
- package/dist/common/time.js +34 -0
- package/dist/common/time.js.map +1 -0
- package/dist/constants.d.ts +1326 -0
- package/dist/constants.js +1142 -0
- package/dist/constants.js.map +1 -0
- package/dist/database/create-auth-tables.migration.d.ts +26 -0
- package/dist/database/create-auth-tables.migration.js +291 -0
- package/dist/database/create-auth-tables.migration.js.map +1 -0
- package/dist/database/email-change-and-retention.migration.d.ts +25 -0
- package/dist/database/email-change-and-retention.migration.js +54 -0
- package/dist/database/email-change-and-retention.migration.js.map +1 -0
- package/dist/database/entities/api-key.entity.d.ts +17 -0
- package/dist/database/entities/api-key.entity.js +80 -0
- package/dist/database/entities/api-key.entity.js.map +1 -0
- package/dist/database/entities/audit-log.entity.d.ts +13 -0
- package/dist/database/entities/audit-log.entity.js +64 -0
- package/dist/database/entities/audit-log.entity.js.map +1 -0
- package/dist/database/entities/backup-code.entity.d.ts +9 -0
- package/dist/database/entities/backup-code.entity.js +52 -0
- package/dist/database/entities/backup-code.entity.js.map +1 -0
- package/dist/database/entities/index.d.ts +43 -0
- package/dist/database/entities/index.js +82 -0
- package/dist/database/entities/index.js.map +1 -0
- package/dist/database/entities/json-object.d.ts +12 -0
- package/dist/database/entities/json-object.js +3 -0
- package/dist/database/entities/json-object.js.map +1 -0
- package/dist/database/entities/link-token.entity.d.ts +15 -0
- package/dist/database/entities/link-token.entity.js +64 -0
- package/dist/database/entities/link-token.entity.js.map +1 -0
- package/dist/database/entities/one-time-code.entity.d.ts +16 -0
- package/dist/database/entities/one-time-code.entity.js +69 -0
- package/dist/database/entities/one-time-code.entity.js.map +1 -0
- package/dist/database/entities/organization-invitation.entity.d.ts +14 -0
- package/dist/database/entities/organization-invitation.entity.js +73 -0
- package/dist/database/entities/organization-invitation.entity.js.map +1 -0
- package/dist/database/entities/organization-member.entity.d.ts +9 -0
- package/dist/database/entities/organization-member.entity.js +48 -0
- package/dist/database/entities/organization-member.entity.js.map +1 -0
- package/dist/database/entities/organization.entity.d.ts +12 -0
- package/dist/database/entities/organization.entity.js +58 -0
- package/dist/database/entities/organization.entity.js.map +1 -0
- package/dist/database/entities/passkey.entity.d.ts +19 -0
- package/dist/database/entities/passkey.entity.js +78 -0
- package/dist/database/entities/passkey.entity.js.map +1 -0
- package/dist/database/entities/password.entity.d.ts +6 -0
- package/dist/database/entities/password.entity.js +36 -0
- package/dist/database/entities/password.entity.js.map +1 -0
- package/dist/database/entities/refresh-token.entity.d.ts +9 -0
- package/dist/database/entities/refresh-token.entity.js +53 -0
- package/dist/database/entities/refresh-token.entity.js.map +1 -0
- package/dist/database/entities/session.entity.d.ts +20 -0
- package/dist/database/entities/session.entity.js +87 -0
- package/dist/database/entities/session.entity.js.map +1 -0
- package/dist/database/entities/settings.entity.d.ts +7 -0
- package/dist/database/entities/settings.entity.js +41 -0
- package/dist/database/entities/settings.entity.js.map +1 -0
- package/dist/database/entities/sign-in-challenge.entity.d.ts +23 -0
- package/dist/database/entities/sign-in-challenge.entity.js +80 -0
- package/dist/database/entities/sign-in-challenge.entity.js.map +1 -0
- package/dist/database/entities/signing-key.entity.d.ts +11 -0
- package/dist/database/entities/signing-key.entity.js +54 -0
- package/dist/database/entities/signing-key.entity.js.map +1 -0
- package/dist/database/entities/social-account.entity.d.ts +13 -0
- package/dist/database/entities/social-account.entity.js +54 -0
- package/dist/database/entities/social-account.entity.js.map +1 -0
- package/dist/database/entities/two-factor-secret.entity.d.ts +10 -0
- package/dist/database/entities/two-factor-secret.entity.js +48 -0
- package/dist/database/entities/two-factor-secret.entity.js.map +1 -0
- package/dist/database/entities/user.entity.d.ts +34 -0
- package/dist/database/entities/user.entity.js +129 -0
- package/dist/database/entities/user.entity.js.map +1 -0
- package/dist/database/entities/webhook-delivery.entity.d.ts +17 -0
- package/dist/database/entities/webhook-delivery.entity.js +79 -0
- package/dist/database/entities/webhook-delivery.entity.js.map +1 -0
- package/dist/database/entities/webhook.entity.d.ts +12 -0
- package/dist/database/entities/webhook.entity.js +58 -0
- package/dist/database/entities/webhook.entity.js.map +1 -0
- package/dist/database/typeorm-row.d.ts +21 -0
- package/dist/database/typeorm-row.js +29 -0
- package/dist/database/typeorm-row.js.map +1 -0
- package/dist/features/account/account.controller.d.ts +259 -0
- package/dist/features/account/account.controller.js +372 -0
- package/dist/features/account/account.controller.js.map +1 -0
- package/dist/features/account/account.dto.d.ts +16 -0
- package/dist/features/account/account.dto.js +61 -0
- package/dist/features/account/account.dto.js.map +1 -0
- package/dist/features/account/data-export.service.d.ts +85 -0
- package/dist/features/account/data-export.service.js +125 -0
- package/dist/features/account/data-export.service.js.map +1 -0
- package/dist/features/account/health.service.d.ts +30 -0
- package/dist/features/account/health.service.js +59 -0
- package/dist/features/account/health.service.js.map +1 -0
- package/dist/features/admin/admin.controller.d.ts +382 -0
- package/dist/features/admin/admin.controller.js +623 -0
- package/dist/features/admin/admin.controller.js.map +1 -0
- package/dist/features/admin/admin.dto.d.ts +61 -0
- package/dist/features/admin/admin.dto.js +253 -0
- package/dist/features/admin/admin.dto.js.map +1 -0
- package/dist/features/admin/admin.service.d.ts +142 -0
- package/dist/features/admin/admin.service.js +227 -0
- package/dist/features/admin/admin.service.js.map +1 -0
- package/dist/features/api-keys/api-keys.service.d.ts +67 -0
- package/dist/features/api-keys/api-keys.service.js +144 -0
- package/dist/features/api-keys/api-keys.service.js.map +1 -0
- package/dist/features/email-change/email-change.controller.d.ts +38 -0
- package/dist/features/email-change/email-change.controller.js +85 -0
- package/dist/features/email-change/email-change.controller.js.map +1 -0
- package/dist/features/email-change/email-change.dto.d.ts +10 -0
- package/dist/features/email-change/email-change.dto.js +43 -0
- package/dist/features/email-change/email-change.dto.js.map +1 -0
- package/dist/features/email-change/email-change.service.d.ts +74 -0
- package/dist/features/email-change/email-change.service.js +179 -0
- package/dist/features/email-change/email-change.service.js.map +1 -0
- package/dist/features/email-links/email-verification.service.d.ts +46 -0
- package/dist/features/email-links/email-verification.service.js +94 -0
- package/dist/features/email-links/email-verification.service.js.map +1 -0
- package/dist/features/email-links/link-tokens.service.d.ts +44 -0
- package/dist/features/email-links/link-tokens.service.js +122 -0
- package/dist/features/email-links/link-tokens.service.js.map +1 -0
- package/dist/features/events/auth-events.service.d.ts +52 -0
- package/dist/features/events/auth-events.service.js +117 -0
- package/dist/features/events/auth-events.service.js.map +1 -0
- package/dist/features/maintenance/data-retention.service.d.ts +60 -0
- package/dist/features/maintenance/data-retention.service.js +182 -0
- package/dist/features/maintenance/data-retention.service.js.map +1 -0
- package/dist/features/notifications/notifications.service.d.ts +40 -0
- package/dist/features/notifications/notifications.service.js +94 -0
- package/dist/features/notifications/notifications.service.js.map +1 -0
- package/dist/features/one-time-codes/one-time-codes.service.d.ts +40 -0
- package/dist/features/one-time-codes/one-time-codes.service.js +102 -0
- package/dist/features/one-time-codes/one-time-codes.service.js.map +1 -0
- package/dist/features/organizations/organizations.controller.d.ts +220 -0
- package/dist/features/organizations/organizations.controller.js +337 -0
- package/dist/features/organizations/organizations.controller.js.map +1 -0
- package/dist/features/organizations/organizations.dto.d.ts +31 -0
- package/dist/features/organizations/organizations.dto.js +100 -0
- package/dist/features/organizations/organizations.dto.js.map +1 -0
- package/dist/features/organizations/organizations.service.d.ts +274 -0
- package/dist/features/organizations/organizations.service.js +481 -0
- package/dist/features/organizations/organizations.service.js.map +1 -0
- package/dist/features/passkeys/passkeys.controller.d.ts +92 -0
- package/dist/features/passkeys/passkeys.controller.js +183 -0
- package/dist/features/passkeys/passkeys.controller.js.map +1 -0
- package/dist/features/passkeys/passkeys.dto.d.ts +13 -0
- package/dist/features/passkeys/passkeys.dto.js +50 -0
- package/dist/features/passkeys/passkeys.dto.js.map +1 -0
- package/dist/features/passkeys/passkeys.service.d.ts +159 -0
- package/dist/features/passkeys/passkeys.service.js +350 -0
- package/dist/features/passkeys/passkeys.service.js.map +1 -0
- package/dist/features/passwordless/passwordless-auth.service.d.ts +152 -0
- package/dist/features/passwordless/passwordless-auth.service.js +304 -0
- package/dist/features/passwordless/passwordless-auth.service.js.map +1 -0
- package/dist/features/passwordless/passwordless.controller.d.ts +75 -0
- package/dist/features/passwordless/passwordless.controller.js +163 -0
- package/dist/features/passwordless/passwordless.controller.js.map +1 -0
- package/dist/features/passwordless/passwordless.dto.d.ts +29 -0
- package/dist/features/passwordless/passwordless.dto.js +101 -0
- package/dist/features/passwordless/passwordless.dto.js.map +1 -0
- package/dist/features/passwords/password-auth.service.d.ts +154 -0
- package/dist/features/passwords/password-auth.service.js +317 -0
- package/dist/features/passwords/password-auth.service.js.map +1 -0
- package/dist/features/passwords/password-policy.service.d.ts +63 -0
- package/dist/features/passwords/password-policy.service.js +175 -0
- package/dist/features/passwords/password-policy.service.js.map +1 -0
- package/dist/features/passwords/password.controller.d.ts +95 -0
- package/dist/features/passwords/password.controller.js +193 -0
- package/dist/features/passwords/password.controller.js.map +1 -0
- package/dist/features/passwords/password.dto.d.ts +36 -0
- package/dist/features/passwords/password.dto.js +140 -0
- package/dist/features/passwords/password.dto.js.map +1 -0
- package/dist/features/sessions/session.service.d.ts +132 -0
- package/dist/features/sessions/session.service.js +308 -0
- package/dist/features/sessions/session.service.js.map +1 -0
- package/dist/features/sessions/session.types.d.ts +34 -0
- package/dist/features/sessions/session.types.js +3 -0
- package/dist/features/sessions/session.types.js.map +1 -0
- package/dist/features/settings/settings.defaults.d.ts +2 -0
- package/dist/features/settings/settings.defaults.js +7 -0
- package/dist/features/settings/settings.defaults.js.map +1 -0
- package/dist/features/settings/settings.service.d.ts +44 -0
- package/dist/features/settings/settings.service.js +112 -0
- package/dist/features/settings/settings.service.js.map +1 -0
- package/dist/features/settings/settings.types.d.ts +133 -0
- package/dist/features/settings/settings.types.js +3 -0
- package/dist/features/settings/settings.types.js.map +1 -0
- package/dist/features/settings/settings.validation.d.ts +33 -0
- package/dist/features/settings/settings.validation.js +614 -0
- package/dist/features/settings/settings.validation.js.map +1 -0
- package/dist/features/sign-in/sign-in-challenges.service.d.ts +54 -0
- package/dist/features/sign-in/sign-in-challenges.service.js +104 -0
- package/dist/features/sign-in/sign-in-challenges.service.js.map +1 -0
- package/dist/features/sign-in/sign-in.service.d.ts +127 -0
- package/dist/features/sign-in/sign-in.service.js +248 -0
- package/dist/features/sign-in/sign-in.service.js.map +1 -0
- package/dist/features/sign-in/sign-in.types.d.ts +22 -0
- package/dist/features/sign-in/sign-in.types.js +3 -0
- package/dist/features/sign-in/sign-in.types.js.map +1 -0
- package/dist/features/signing-keys/jwks.controller.d.ts +17 -0
- package/dist/features/signing-keys/jwks.controller.js +51 -0
- package/dist/features/signing-keys/jwks.controller.js.map +1 -0
- package/dist/features/signing-keys/signing-keys.service.d.ts +67 -0
- package/dist/features/signing-keys/signing-keys.service.js +142 -0
- package/dist/features/signing-keys/signing-keys.service.js.map +1 -0
- package/dist/features/social/social-auth.service.d.ts +100 -0
- package/dist/features/social/social-auth.service.js +232 -0
- package/dist/features/social/social-auth.service.js.map +1 -0
- package/dist/features/social/social-providers.service.d.ts +97 -0
- package/dist/features/social/social-providers.service.js +214 -0
- package/dist/features/social/social-providers.service.js.map +1 -0
- package/dist/features/social/social.controller.d.ts +54 -0
- package/dist/features/social/social.controller.js +124 -0
- package/dist/features/social/social.controller.js.map +1 -0
- package/dist/features/social/social.dto.d.ts +11 -0
- package/dist/features/social/social.dto.js +38 -0
- package/dist/features/social/social.dto.js.map +1 -0
- package/dist/features/two-factor/two-factor.controller.d.ts +84 -0
- package/dist/features/two-factor/two-factor.controller.js +174 -0
- package/dist/features/two-factor/two-factor.controller.js.map +1 -0
- package/dist/features/two-factor/two-factor.dto.d.ts +10 -0
- package/dist/features/two-factor/two-factor.dto.js +37 -0
- package/dist/features/two-factor/two-factor.dto.js.map +1 -0
- package/dist/features/two-factor/two-factor.service.d.ts +171 -0
- package/dist/features/two-factor/two-factor.service.js +348 -0
- package/dist/features/two-factor/two-factor.service.js.map +1 -0
- package/dist/features/users/sign-in-methods.service.d.ts +40 -0
- package/dist/features/users/sign-in-methods.service.js +81 -0
- package/dist/features/users/sign-in-methods.service.js.map +1 -0
- package/dist/features/users/sign-up-rules.d.ts +12 -0
- package/dist/features/users/sign-up-rules.js +29 -0
- package/dist/features/users/sign-up-rules.js.map +1 -0
- package/dist/features/users/users.service.d.ts +246 -0
- package/dist/features/users/users.service.js +509 -0
- package/dist/features/users/users.service.js.map +1 -0
- package/dist/features/users/users.types.d.ts +24 -0
- package/dist/features/users/users.types.js +3 -0
- package/dist/features/users/users.types.js.map +1 -0
- package/dist/features/webhooks/webhook-delivery.worker.d.ts +55 -0
- package/dist/features/webhooks/webhook-delivery.worker.js +175 -0
- package/dist/features/webhooks/webhook-delivery.worker.js.map +1 -0
- package/dist/features/webhooks/webhook-signature.d.ts +28 -0
- package/dist/features/webhooks/webhook-signature.js +85 -0
- package/dist/features/webhooks/webhook-signature.js.map +1 -0
- package/dist/features/webhooks/webhooks.service.d.ts +144 -0
- package/dist/features/webhooks/webhooks.service.js +238 -0
- package/dist/features/webhooks/webhooks.service.js.map +1 -0
- package/dist/guards/auth.decorators.d.ts +65 -0
- package/dist/guards/auth.decorators.js +68 -0
- package/dist/guards/auth.decorators.js.map +1 -0
- package/dist/guards/auth.guard.d.ts +47 -0
- package/dist/guards/auth.guard.js +132 -0
- package/dist/guards/auth.guard.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +95 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/console-email-sender.d.ts +15 -0
- package/dist/integrations/console-email-sender.js +26 -0
- package/dist/integrations/console-email-sender.js.map +1 -0
- package/dist/integrations/msg91-sms-sender.d.ts +28 -0
- package/dist/integrations/msg91-sms-sender.js +46 -0
- package/dist/integrations/msg91-sms-sender.js.map +1 -0
- package/docs/README.md +39 -0
- package/docs/admin-api-keys-webhooks.md +147 -0
- package/docs/api-reference.md +175 -0
- package/docs/architecture.md +119 -0
- package/docs/client-integration.md +192 -0
- package/docs/code-walkthrough.md +273 -0
- package/docs/configuration.md +229 -0
- package/docs/endpoints/README.md +151 -0
- package/docs/endpoints/account.md +363 -0
- package/docs/endpoints/admin.md +422 -0
- package/docs/endpoints/email-password.md +261 -0
- package/docs/endpoints/organizations.md +192 -0
- package/docs/endpoints/passkeys.md +195 -0
- package/docs/endpoints/passwordless.md +214 -0
- package/docs/endpoints/social.md +116 -0
- package/docs/endpoints/two-factor.md +146 -0
- package/docs/error-codes.md +100 -0
- package/docs/events.md +83 -0
- package/docs/getting-started.md +139 -0
- package/docs/manual-testing.md +215 -0
- package/docs/organizations.md +86 -0
- package/docs/production-checklist.md +60 -0
- package/docs/protecting-routes.md +147 -0
- package/docs/security.md +61 -0
- package/docs/sign-in-flows.md +294 -0
- package/package.json +92 -4
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SwitchOrganizationInput = exports.AcceptInvitationInput = exports.ChangeMemberRoleInput = exports.InviteMemberInput = exports.UpdateOrganizationInput = exports.CreateOrganizationInput = void 0;
|
|
13
|
+
const class_validator_1 = require("class-validator");
|
|
14
|
+
const constants_1 = require("../../constants.js");
|
|
15
|
+
/** POST /auth/organizations */
|
|
16
|
+
class CreateOrganizationInput {
|
|
17
|
+
name;
|
|
18
|
+
/** Unique handle: lowercase letters, digits and dashes, e.g. "acme-india". */
|
|
19
|
+
slug;
|
|
20
|
+
}
|
|
21
|
+
exports.CreateOrganizationInput = CreateOrganizationInput;
|
|
22
|
+
__decorate([
|
|
23
|
+
(0, class_validator_1.IsString)(),
|
|
24
|
+
(0, class_validator_1.MaxLength)(constants_1.ORGANIZATION_NAME_MAX_LENGTH),
|
|
25
|
+
__metadata("design:type", String)
|
|
26
|
+
], CreateOrganizationInput.prototype, "name", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, class_validator_1.IsString)(),
|
|
29
|
+
(0, class_validator_1.Matches)(constants_1.ORGANIZATION_SLUG_PATTERN),
|
|
30
|
+
__metadata("design:type", String)
|
|
31
|
+
], CreateOrganizationInput.prototype, "slug", void 0);
|
|
32
|
+
/** PATCH /auth/organizations/:organizationId */
|
|
33
|
+
class UpdateOrganizationInput {
|
|
34
|
+
name;
|
|
35
|
+
slug;
|
|
36
|
+
metadata;
|
|
37
|
+
}
|
|
38
|
+
exports.UpdateOrganizationInput = UpdateOrganizationInput;
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, class_validator_1.IsOptional)(),
|
|
41
|
+
(0, class_validator_1.IsString)(),
|
|
42
|
+
(0, class_validator_1.MaxLength)(constants_1.ORGANIZATION_NAME_MAX_LENGTH),
|
|
43
|
+
__metadata("design:type", String)
|
|
44
|
+
], UpdateOrganizationInput.prototype, "name", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, class_validator_1.IsOptional)(),
|
|
47
|
+
(0, class_validator_1.IsString)(),
|
|
48
|
+
(0, class_validator_1.Matches)(constants_1.ORGANIZATION_SLUG_PATTERN),
|
|
49
|
+
__metadata("design:type", String)
|
|
50
|
+
], UpdateOrganizationInput.prototype, "slug", void 0);
|
|
51
|
+
__decorate([
|
|
52
|
+
(0, class_validator_1.IsOptional)(),
|
|
53
|
+
(0, class_validator_1.IsObject)(),
|
|
54
|
+
__metadata("design:type", Object)
|
|
55
|
+
], UpdateOrganizationInput.prototype, "metadata", void 0);
|
|
56
|
+
/** POST /auth/organizations/:organizationId/invitations */
|
|
57
|
+
class InviteMemberInput {
|
|
58
|
+
email;
|
|
59
|
+
role;
|
|
60
|
+
}
|
|
61
|
+
exports.InviteMemberInput = InviteMemberInput;
|
|
62
|
+
__decorate([
|
|
63
|
+
(0, class_validator_1.IsString)(),
|
|
64
|
+
(0, class_validator_1.MaxLength)(constants_1.EMAIL_MAX_LENGTH),
|
|
65
|
+
__metadata("design:type", String)
|
|
66
|
+
], InviteMemberInput.prototype, "email", void 0);
|
|
67
|
+
__decorate([
|
|
68
|
+
(0, class_validator_1.IsIn)(constants_1.ORGANIZATION_ROLES),
|
|
69
|
+
__metadata("design:type", String)
|
|
70
|
+
], InviteMemberInput.prototype, "role", void 0);
|
|
71
|
+
/** PATCH /auth/organizations/:organizationId/members/:userId */
|
|
72
|
+
class ChangeMemberRoleInput {
|
|
73
|
+
role;
|
|
74
|
+
}
|
|
75
|
+
exports.ChangeMemberRoleInput = ChangeMemberRoleInput;
|
|
76
|
+
__decorate([
|
|
77
|
+
(0, class_validator_1.IsIn)(constants_1.ORGANIZATION_ROLES),
|
|
78
|
+
__metadata("design:type", String)
|
|
79
|
+
], ChangeMemberRoleInput.prototype, "role", void 0);
|
|
80
|
+
/** POST /auth/organizations/invitations/accept */
|
|
81
|
+
class AcceptInvitationInput {
|
|
82
|
+
token;
|
|
83
|
+
}
|
|
84
|
+
exports.AcceptInvitationInput = AcceptInvitationInput;
|
|
85
|
+
__decorate([
|
|
86
|
+
(0, class_validator_1.IsString)(),
|
|
87
|
+
(0, class_validator_1.MaxLength)(constants_1.RANDOM_TOKEN_INPUT_MAX_LENGTH),
|
|
88
|
+
__metadata("design:type", String)
|
|
89
|
+
], AcceptInvitationInput.prototype, "token", void 0);
|
|
90
|
+
/** POST /auth/organizations/switch. Send null to work outside any organization. */
|
|
91
|
+
class SwitchOrganizationInput {
|
|
92
|
+
organizationId;
|
|
93
|
+
}
|
|
94
|
+
exports.SwitchOrganizationInput = SwitchOrganizationInput;
|
|
95
|
+
__decorate([
|
|
96
|
+
(0, class_validator_1.ValidateIf)((input) => input.organizationId !== null),
|
|
97
|
+
(0, class_validator_1.IsUUID)(),
|
|
98
|
+
__metadata("design:type", Object)
|
|
99
|
+
], SwitchOrganizationInput.prototype, "organizationId", void 0);
|
|
100
|
+
//# sourceMappingURL=organizations.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"organizations.dto.js","sourceRoot":"","sources":["../../../src/features/organizations/organizations.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAA+G;AAC/G,2CAOqB;AAGrB,+BAA+B;AAC/B,MAAa,uBAAuB;IAElC,IAAI,CAAS;IAEb,8EAA8E;IAE9E,IAAI,CAAS;CACd;AAPD,0DAOC;AALC;IADC,IAAA,0BAAQ,GAAE;IAAE,IAAA,2BAAS,EAAC,wCAA4B,CAAC;;qDACvC;AAIb;IADC,IAAA,0BAAQ,GAAE;IAAE,IAAA,yBAAO,EAAC,qCAAyB,CAAC;;qDAClC;AAGf,gDAAgD;AAChD,MAAa,uBAAuB;IAElC,IAAI,CAAU;IAGd,IAAI,CAAU;IAGd,QAAQ,CAAc;CACvB;AATD,0DASC;AAPC;IADC,IAAA,4BAAU,GAAE;IAAE,IAAA,0BAAQ,GAAE;IAAE,IAAA,2BAAS,EAAC,wCAA4B,CAAC;;qDACpD;AAGd;IADC,IAAA,4BAAU,GAAE;IAAE,IAAA,0BAAQ,GAAE;IAAE,IAAA,yBAAO,EAAC,qCAAyB,CAAC;;qDAC/C;AAGd;IADC,IAAA,4BAAU,GAAE;IAAE,IAAA,0BAAQ,GAAE;;yDACH;AAGxB,2DAA2D;AAC3D,MAAa,iBAAiB;IAE5B,KAAK,CAAS;IAGd,IAAI,CAAmB;CACxB;AAND,8CAMC;AAJC;IADC,IAAA,0BAAQ,GAAE;IAAE,IAAA,2BAAS,EAAC,4BAAgB,CAAC;;gDAC1B;AAGd;IADC,IAAA,sBAAI,EAAC,8BAAkB,CAAC;;+CACF;AAGzB,gEAAgE;AAChE,MAAa,qBAAqB;IAEhC,IAAI,CAAmB;CACxB;AAHD,sDAGC;AADC;IADC,IAAA,sBAAI,EAAC,8BAAkB,CAAC;;mDACF;AAGzB,kDAAkD;AAClD,MAAa,qBAAqB;IAEhC,KAAK,CAAS;CACf;AAHD,sDAGC;AADC;IADC,IAAA,0BAAQ,GAAE;IAAE,IAAA,2BAAS,EAAC,yCAA6B,CAAC;;oDACvC;AAGhB,mFAAmF;AACnF,MAAa,uBAAuB;IAGlC,cAAc,CAAgB;CAC/B;AAJD,0DAIC;AADC;IAFC,IAAA,4BAAU,EAAC,CAAC,KAA8B,EAAE,EAAE,CAAC,KAAK,CAAC,cAAc,KAAK,IAAI,CAAC;IAC7E,IAAA,wBAAM,GAAE;;+DACqB"}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { AuthOptions } from '../../auth-options.js';
|
|
2
|
+
import { RequestContext } from '../../common/request-context.js';
|
|
3
|
+
import { OrganizationRole } from '../../constants.js';
|
|
4
|
+
import { OrganizationEntity } from '../../database/entities/index.js';
|
|
5
|
+
import { AuthEventsService } from '../events/auth-events.service.js';
|
|
6
|
+
import { NotificationsService } from '../notifications/notifications.service.js';
|
|
7
|
+
import { SessionService } from '../sessions/session.service.js';
|
|
8
|
+
import { SettingsService } from '../settings/settings.service.js';
|
|
9
|
+
import type { JsonObject } from '../../database/entities/json-object.js';
|
|
10
|
+
export interface OrganizationChanges {
|
|
11
|
+
name?: string;
|
|
12
|
+
slug?: string;
|
|
13
|
+
metadata?: JsonObject;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Organizations (companies, teams, workspaces) and their members.
|
|
17
|
+
*
|
|
18
|
+
* Roles inside an organization:
|
|
19
|
+
* owner - everything, including deleting the organization and managing other owners
|
|
20
|
+
* admin - manage members and invitations (but not owners)
|
|
21
|
+
* member - belongs to the organization
|
|
22
|
+
*
|
|
23
|
+
* A user picks the organization they are working in with switchActiveOrganization(); their access
|
|
24
|
+
* token then carries "org_id" and "org_role", so your API can scope data with one check.
|
|
25
|
+
*/
|
|
26
|
+
export declare class OrganizationsService {
|
|
27
|
+
private readonly settingsService;
|
|
28
|
+
private readonly sessions;
|
|
29
|
+
private readonly notifications;
|
|
30
|
+
private readonly events;
|
|
31
|
+
private readonly database;
|
|
32
|
+
constructor(options: AuthOptions, settingsService: SettingsService, sessions: SessionService, notifications: NotificationsService, events: AuthEventsService);
|
|
33
|
+
/**
|
|
34
|
+
* Creates an organization; the creator becomes its owner.
|
|
35
|
+
*
|
|
36
|
+
* @param userId - The creator.
|
|
37
|
+
* @param details - Name and URL-friendly slug.
|
|
38
|
+
* @param isAppAdmin - Lets app admins create one even when users may not.
|
|
39
|
+
* @param request - Who is asking (for the audit log).
|
|
40
|
+
* @returns The new organization.
|
|
41
|
+
* @throws AuthError FORBIDDEN when users may not create organizations.
|
|
42
|
+
* @throws AuthError ORGANIZATION_SLUG_TAKEN when the slug is in use.
|
|
43
|
+
* @throws AuthError VALIDATION_ERROR when the user is already in too many organizations.
|
|
44
|
+
*/
|
|
45
|
+
createOrganization(userId: string, details: Required<Pick<OrganizationChanges, 'name' | 'slug'>>, isAppAdmin: boolean, request: RequestContext): Promise<{
|
|
46
|
+
name: string;
|
|
47
|
+
slug: string;
|
|
48
|
+
metadata: {};
|
|
49
|
+
createdByUserId: string;
|
|
50
|
+
} & OrganizationEntity>;
|
|
51
|
+
/**
|
|
52
|
+
* The organizations the user belongs to, with their role in each.
|
|
53
|
+
*
|
|
54
|
+
* @param userId - The signed-in user.
|
|
55
|
+
* @returns The organizations, sorted by name.
|
|
56
|
+
*/
|
|
57
|
+
listMyOrganizations(userId: string): Promise<{
|
|
58
|
+
id: any;
|
|
59
|
+
name: any;
|
|
60
|
+
slug: any;
|
|
61
|
+
metadata: any;
|
|
62
|
+
role: OrganizationRole;
|
|
63
|
+
joinedAt: string;
|
|
64
|
+
}[]>;
|
|
65
|
+
/**
|
|
66
|
+
* @param organizationId - The organization.
|
|
67
|
+
* @param userId - The signed-in user, who must be a member.
|
|
68
|
+
* @returns The organization plus `myRole`.
|
|
69
|
+
* @throws AuthError NOT_FOUND when it doesn't exist or the user isn't a member.
|
|
70
|
+
*/
|
|
71
|
+
getOrganization(organizationId: string, userId: string): Promise<{
|
|
72
|
+
myRole: OrganizationRole;
|
|
73
|
+
id: string;
|
|
74
|
+
name: string;
|
|
75
|
+
slug: string;
|
|
76
|
+
metadata: JsonObject;
|
|
77
|
+
createdByUserId: string | null;
|
|
78
|
+
createdAt: Date;
|
|
79
|
+
updatedAt: Date;
|
|
80
|
+
}>;
|
|
81
|
+
/**
|
|
82
|
+
* Changes the name, slug or metadata. Admins and owners only.
|
|
83
|
+
*
|
|
84
|
+
* @param organizationId - The organization.
|
|
85
|
+
* @param userId - The signed-in user.
|
|
86
|
+
* @param changes - The fields to change.
|
|
87
|
+
* @param request - Who is asking (for the audit log).
|
|
88
|
+
* @returns The updated organization.
|
|
89
|
+
* @throws AuthError FORBIDDEN for plain members.
|
|
90
|
+
* @throws AuthError ORGANIZATION_SLUG_TAKEN when the new slug is in use.
|
|
91
|
+
*/
|
|
92
|
+
updateOrganization(organizationId: string, userId: string, changes: OrganizationChanges, request: RequestContext): Promise<OrganizationEntity>;
|
|
93
|
+
/**
|
|
94
|
+
* Deletes the organization. Owners only. Members, invitations and API keys of the organization go with it.
|
|
95
|
+
*
|
|
96
|
+
* @param organizationId - The organization.
|
|
97
|
+
* @param userId - The signed-in user.
|
|
98
|
+
* @param request - Who is asking (for the audit log).
|
|
99
|
+
* @returns `{ success: true }`.
|
|
100
|
+
* @throws AuthError FORBIDDEN unless the user is an owner.
|
|
101
|
+
*/
|
|
102
|
+
deleteOrganization(organizationId: string, userId: string, request: RequestContext): Promise<{
|
|
103
|
+
success: true;
|
|
104
|
+
}>;
|
|
105
|
+
/**
|
|
106
|
+
* @param organizationId - The organization.
|
|
107
|
+
* @param userId - The signed-in user, who must be a member.
|
|
108
|
+
* @returns The members with their names, emails and roles, oldest first.
|
|
109
|
+
*/
|
|
110
|
+
listMembers(organizationId: string, userId: string): Promise<{
|
|
111
|
+
userId: any;
|
|
112
|
+
email: any;
|
|
113
|
+
firstName: any;
|
|
114
|
+
lastName: any;
|
|
115
|
+
role: OrganizationRole;
|
|
116
|
+
joinedAt: string;
|
|
117
|
+
}[]>;
|
|
118
|
+
/**
|
|
119
|
+
* Changes a member's role. Admins manage members and admins; only owners can make or unmake owners.
|
|
120
|
+
*
|
|
121
|
+
* @param organizationId - The organization.
|
|
122
|
+
* @param actorUserId - The signed-in user doing it.
|
|
123
|
+
* @param targetUserId - The member whose role changes.
|
|
124
|
+
* @param newRole - "owner", "admin" or "member".
|
|
125
|
+
* @param request - Who is asking (for the audit log).
|
|
126
|
+
* @returns `{ success: true }`.
|
|
127
|
+
* @throws AuthError FORBIDDEN when the actor may not make this change.
|
|
128
|
+
* @throws AuthError LAST_OWNER when this would leave the organization without an owner.
|
|
129
|
+
*/
|
|
130
|
+
changeMemberRole(organizationId: string, actorUserId: string, targetUserId: string, newRole: OrganizationRole, request: RequestContext): Promise<{
|
|
131
|
+
success: true;
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Removes a member. Anyone may leave by removing themselves (unless they are the last owner).
|
|
135
|
+
* The member's devices stop working in this organization.
|
|
136
|
+
*
|
|
137
|
+
* @param organizationId - The organization.
|
|
138
|
+
* @param actorUserId - The signed-in user doing it.
|
|
139
|
+
* @param targetUserId - The member to remove (the actor themselves to leave).
|
|
140
|
+
* @param request - Who is asking (for the audit log).
|
|
141
|
+
* @returns `{ success: true }`.
|
|
142
|
+
* @throws AuthError FORBIDDEN when the actor may not remove this member.
|
|
143
|
+
* @throws AuthError LAST_OWNER when removing the last owner.
|
|
144
|
+
*/
|
|
145
|
+
removeMember(organizationId: string, actorUserId: string, targetUserId: string, request: RequestContext): Promise<{
|
|
146
|
+
success: true;
|
|
147
|
+
}>;
|
|
148
|
+
/**
|
|
149
|
+
* Emails an invitation link. The invited person accepts it after signing in with that email.
|
|
150
|
+
* A new invitation replaces any open one for the same email.
|
|
151
|
+
*
|
|
152
|
+
* @param organizationId - The organization.
|
|
153
|
+
* @param actorUserId - The signed-in user doing it.
|
|
154
|
+
* @param typedEmail - Who to invite.
|
|
155
|
+
* @param role - The role they get when they accept.
|
|
156
|
+
* @param request - Who is asking (for the audit log).
|
|
157
|
+
* @returns `{ success: true }`.
|
|
158
|
+
* @throws AuthError FORBIDDEN for plain members, or when an admin tries to invite an owner.
|
|
159
|
+
*/
|
|
160
|
+
inviteMember(organizationId: string, actorUserId: string, typedEmail: unknown, role: OrganizationRole, request: RequestContext): Promise<{
|
|
161
|
+
success: true;
|
|
162
|
+
}>;
|
|
163
|
+
/**
|
|
164
|
+
* @param organizationId - The organization.
|
|
165
|
+
* @param actorUserId - The signed-in user, who must be an admin or owner.
|
|
166
|
+
* @returns Open invitations (not accepted or revoked), newest first, without their token hashes.
|
|
167
|
+
*/
|
|
168
|
+
listInvitations(organizationId: string, actorUserId: string): Promise<{
|
|
169
|
+
id: string;
|
|
170
|
+
organizationId: string;
|
|
171
|
+
email: string;
|
|
172
|
+
role: OrganizationRole;
|
|
173
|
+
invitedByUserId: string;
|
|
174
|
+
expiresAt: Date;
|
|
175
|
+
acceptedAt: Date | null;
|
|
176
|
+
revokedAt: Date | null;
|
|
177
|
+
createdAt: Date;
|
|
178
|
+
}[]>;
|
|
179
|
+
/**
|
|
180
|
+
* Cancels an open invitation; its link stops working.
|
|
181
|
+
*
|
|
182
|
+
* @param organizationId - The organization.
|
|
183
|
+
* @param actorUserId - The signed-in user doing it.
|
|
184
|
+
* @param invitationId - The invitation.
|
|
185
|
+
* @returns `{ success: true }`.
|
|
186
|
+
* @throws AuthError NOT_FOUND when there is no open invitation with this id.
|
|
187
|
+
*/
|
|
188
|
+
revokeInvitation(organizationId: string, actorUserId: string, invitationId: string): Promise<{
|
|
189
|
+
success: true;
|
|
190
|
+
}>;
|
|
191
|
+
/**
|
|
192
|
+
* Accepts an invitation. The signed-in user's VERIFIED email must be the invited email, so a
|
|
193
|
+
* forwarded or leaked link can't be used by someone else.
|
|
194
|
+
*
|
|
195
|
+
* @param userId - The signed-in user.
|
|
196
|
+
* @param invitationToken - The token from the invitation link.
|
|
197
|
+
* @param request - Who is asking (for the audit log).
|
|
198
|
+
* @returns The organization joined and the role given.
|
|
199
|
+
* @throws AuthError INVALID_TOKEN when the link is unknown, used, expired or for another email.
|
|
200
|
+
* @throws AuthError ALREADY_MEMBER when the user is already in the organization.
|
|
201
|
+
*/
|
|
202
|
+
acceptInvitation(userId: string, invitationToken: unknown, request: RequestContext): Promise<{
|
|
203
|
+
success: true;
|
|
204
|
+
organizationId: string;
|
|
205
|
+
role: OrganizationRole;
|
|
206
|
+
}>;
|
|
207
|
+
/**
|
|
208
|
+
* Picks the organization this device works in. The new access token carries "org_id" and "org_role".
|
|
209
|
+
*
|
|
210
|
+
* @param userId - The signed-in user.
|
|
211
|
+
* @param sessionId - This device's session.
|
|
212
|
+
* @param organizationId - The organization to switch to, or null for none.
|
|
213
|
+
* @returns A new access token and its lifetime.
|
|
214
|
+
* @throws AuthError NOT_FOUND when the user isn't a member of that organization.
|
|
215
|
+
*/
|
|
216
|
+
switchActiveOrganization(userId: string, sessionId: string, organizationId: string | null): Promise<{
|
|
217
|
+
success: true;
|
|
218
|
+
accessToken: string;
|
|
219
|
+
expiresIn: number;
|
|
220
|
+
organizationId: string | null;
|
|
221
|
+
}>;
|
|
222
|
+
/**
|
|
223
|
+
* @returns The current settings.
|
|
224
|
+
* @throws AuthError FEATURE_DISABLED when organizations are turned off.
|
|
225
|
+
*/
|
|
226
|
+
private assertOrganizationsEnabled;
|
|
227
|
+
/**
|
|
228
|
+
* @param organizationId - The organization.
|
|
229
|
+
* @param userId - The user.
|
|
230
|
+
* @returns The membership row, or null if the user isn't a member.
|
|
231
|
+
*/
|
|
232
|
+
private findMembership;
|
|
233
|
+
/**
|
|
234
|
+
* Checks that the user is a member with at least `minimumRole` (owner > admin > member).
|
|
235
|
+
*
|
|
236
|
+
* @param organizationId - The organization.
|
|
237
|
+
* @param userId - The user.
|
|
238
|
+
* @param minimumRole - The lowest role allowed.
|
|
239
|
+
* @returns The user's membership.
|
|
240
|
+
* @throws AuthError NOT_FOUND when the user is not a member (so outsiders can't probe which organizations exist).
|
|
241
|
+
* @throws AuthError FORBIDDEN when their role is too low.
|
|
242
|
+
*/
|
|
243
|
+
private requireRole;
|
|
244
|
+
/**
|
|
245
|
+
* Admins may act on members and admins; anything touching an owner needs an owner.
|
|
246
|
+
*
|
|
247
|
+
* @param actorRole - The role of the user making the change.
|
|
248
|
+
* @param currentRole - The target's role now.
|
|
249
|
+
* @param newRole - The target's role after the change.
|
|
250
|
+
* @throws AuthError FORBIDDEN when the actor may not make this change.
|
|
251
|
+
*/
|
|
252
|
+
private assertMayManage;
|
|
253
|
+
/**
|
|
254
|
+
* @param organizationId - The organization.
|
|
255
|
+
* @throws AuthError LAST_OWNER when the organization has only one owner left.
|
|
256
|
+
*/
|
|
257
|
+
private assertNotLastOwner;
|
|
258
|
+
/**
|
|
259
|
+
* A removed member's devices stop working in that organization.
|
|
260
|
+
*
|
|
261
|
+
* @param userId - The removed member.
|
|
262
|
+
* @param organizationId - The organization they left.
|
|
263
|
+
*/
|
|
264
|
+
private clearActiveOrganization;
|
|
265
|
+
/**
|
|
266
|
+
* Runs a database write and turns a "duplicate value" error into a friendly AuthError.
|
|
267
|
+
*
|
|
268
|
+
* @param operation - The write to wait for.
|
|
269
|
+
* @param errorOnDuplicate - The error to throw when Postgres refuses a duplicate.
|
|
270
|
+
* @returns What the write returned.
|
|
271
|
+
* @throws AuthError `errorOnDuplicate` on a duplicate; any other error is re-thrown as is.
|
|
272
|
+
*/
|
|
273
|
+
private translateUniqueViolation;
|
|
274
|
+
}
|