@techelusive/nest-auth 0.0.0-stage → 0.2.1
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 +71 -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,61 @@
|
|
|
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.UpdateMyProfileInput = exports.ReactivateAccountInput = exports.RefreshTokenInput = void 0;
|
|
13
|
+
const class_validator_1 = require("class-validator");
|
|
14
|
+
const constants_1 = require("../../constants.js");
|
|
15
|
+
/** POST /auth/refresh. Leave refreshToken out when it lives in the cookie (AuthOptions.refreshTokenCookie). */
|
|
16
|
+
class RefreshTokenInput {
|
|
17
|
+
refreshToken;
|
|
18
|
+
}
|
|
19
|
+
exports.RefreshTokenInput = RefreshTokenInput;
|
|
20
|
+
__decorate([
|
|
21
|
+
(0, class_validator_1.IsOptional)(),
|
|
22
|
+
(0, class_validator_1.IsString)(),
|
|
23
|
+
(0, class_validator_1.MaxLength)(constants_1.RANDOM_TOKEN_INPUT_MAX_LENGTH),
|
|
24
|
+
__metadata("design:type", String)
|
|
25
|
+
], RefreshTokenInput.prototype, "refreshToken", void 0);
|
|
26
|
+
/** POST /auth/reactivate */
|
|
27
|
+
class ReactivateAccountInput {
|
|
28
|
+
/** The reactivationToken from the ACCOUNT_DEACTIVATED sign-in response. */
|
|
29
|
+
reactivationToken;
|
|
30
|
+
}
|
|
31
|
+
exports.ReactivateAccountInput = ReactivateAccountInput;
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, class_validator_1.IsString)(),
|
|
34
|
+
(0, class_validator_1.MaxLength)(constants_1.RANDOM_TOKEN_INPUT_MAX_LENGTH),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], ReactivateAccountInput.prototype, "reactivationToken", void 0);
|
|
37
|
+
/** PATCH /auth/me. Users may change their name and app fields, never their roles or status. */
|
|
38
|
+
class UpdateMyProfileInput {
|
|
39
|
+
firstName;
|
|
40
|
+
lastName;
|
|
41
|
+
metadata;
|
|
42
|
+
}
|
|
43
|
+
exports.UpdateMyProfileInput = UpdateMyProfileInput;
|
|
44
|
+
__decorate([
|
|
45
|
+
(0, class_validator_1.IsOptional)(),
|
|
46
|
+
(0, class_validator_1.IsString)(),
|
|
47
|
+
(0, class_validator_1.MaxLength)(constants_1.DISPLAY_NAME_MAX_LENGTH),
|
|
48
|
+
__metadata("design:type", String)
|
|
49
|
+
], UpdateMyProfileInput.prototype, "firstName", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
(0, class_validator_1.IsOptional)(),
|
|
52
|
+
(0, class_validator_1.IsString)(),
|
|
53
|
+
(0, class_validator_1.MaxLength)(constants_1.DISPLAY_NAME_MAX_LENGTH),
|
|
54
|
+
__metadata("design:type", String)
|
|
55
|
+
], UpdateMyProfileInput.prototype, "lastName", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
(0, class_validator_1.IsOptional)(),
|
|
58
|
+
(0, class_validator_1.IsObject)(),
|
|
59
|
+
__metadata("design:type", Object)
|
|
60
|
+
], UpdateMyProfileInput.prototype, "metadata", void 0);
|
|
61
|
+
//# sourceMappingURL=account.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.dto.js","sourceRoot":"","sources":["../../../src/features/account/account.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAA4E;AAC5E,2CAAqF;AAGrF,+GAA+G;AAC/G,MAAa,iBAAiB;IAE5B,YAAY,CAAU;CACvB;AAHD,8CAGC;AADC;IADC,IAAA,4BAAU,GAAE;IAAE,IAAA,0BAAQ,GAAE;IAAE,IAAA,2BAAS,EAAC,yCAA6B,CAAC;;uDAC7C;AAGxB,4BAA4B;AAC5B,MAAa,sBAAsB;IACjC,2EAA2E;IAE3E,iBAAiB,CAAS;CAC3B;AAJD,wDAIC;AADC;IADC,IAAA,0BAAQ,GAAE;IAAE,IAAA,2BAAS,EAAC,yCAA6B,CAAC;;iEAC3B;AAG5B,+FAA+F;AAC/F,MAAa,oBAAoB;IAE/B,SAAS,CAAU;IAGnB,QAAQ,CAAU;IAGlB,QAAQ,CAAc;CACvB;AATD,oDASC;AAPC;IADC,IAAA,4BAAU,GAAE;IAAE,IAAA,0BAAQ,GAAE;IAAE,IAAA,2BAAS,EAAC,mCAAuB,CAAC;;uDAC1C;AAGnB;IADC,IAAA,4BAAU,GAAE;IAAE,IAAA,0BAAQ,GAAE;IAAE,IAAA,2BAAS,EAAC,mCAAuB,CAAC;;sDAC3C;AAGlB;IADC,IAAA,4BAAU,GAAE;IAAE,IAAA,0BAAQ,GAAE;;sDACH"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { AuthOptions } from '../../auth-options.js';
|
|
2
|
+
import { RateLimiterService } from '../../common/rate-limiter.service.js';
|
|
3
|
+
import { SettingsService } from '../settings/settings.service.js';
|
|
4
|
+
import { SignInMethodsService } from '../users/sign-in-methods.service.js';
|
|
5
|
+
import { UsersService } from '../users/users.service.js';
|
|
6
|
+
/**
|
|
7
|
+
* "Download my data" (GET /auth/me/export), for privacy laws such as India's DPDP Act and the GDPR.
|
|
8
|
+
*
|
|
9
|
+
* Everything this library stores about the user, in readable form: profile, sign-in methods,
|
|
10
|
+
* linked accounts, passkeys (names only), devices, organizations and their security history.
|
|
11
|
+
* Never included: password hashes, 2FA secrets, backup codes, tokens or keys.
|
|
12
|
+
* Your app adds its own data (orders, rides...) next to this in its own export.
|
|
13
|
+
*/
|
|
14
|
+
export declare class DataExportService {
|
|
15
|
+
private readonly settingsService;
|
|
16
|
+
private readonly users;
|
|
17
|
+
private readonly signInMethods;
|
|
18
|
+
private readonly rateLimiter;
|
|
19
|
+
private readonly database;
|
|
20
|
+
constructor(options: AuthOptions, settingsService: SettingsService, users: UsersService, signInMethods: SignInMethodsService, rateLimiter: RateLimiterService);
|
|
21
|
+
/**
|
|
22
|
+
* Collects everything this library stores about the user, in readable form.
|
|
23
|
+
* Secrets (password hashes, 2FA secrets, backup codes, tokens, keys) are never included.
|
|
24
|
+
*
|
|
25
|
+
* @param userId - The signed-in user.
|
|
26
|
+
* @returns Profile, sign-in methods, linked accounts, passkeys, devices, organizations and security history.
|
|
27
|
+
* @throws AuthError TOO_MANY_REQUESTS when exported too often.
|
|
28
|
+
*/
|
|
29
|
+
exportUserData(userId: string): Promise<{
|
|
30
|
+
success: true;
|
|
31
|
+
exportedAt: string;
|
|
32
|
+
profile: {
|
|
33
|
+
termsAcceptedAt: string | null;
|
|
34
|
+
privacyPolicyAcceptedAt: string | null;
|
|
35
|
+
onboardingCompletedAt: string | null;
|
|
36
|
+
updatedAt: string;
|
|
37
|
+
id: string;
|
|
38
|
+
email: string | null;
|
|
39
|
+
isEmailVerified: boolean;
|
|
40
|
+
phoneNumber: string | null;
|
|
41
|
+
isPhoneVerified: boolean;
|
|
42
|
+
firstName: string | null;
|
|
43
|
+
lastName: string | null;
|
|
44
|
+
roles: string[];
|
|
45
|
+
status: import("../../constants.js").AccountStatus;
|
|
46
|
+
pendingVerifications: import("../../constants.js").PendingVerification[];
|
|
47
|
+
onboardingCompleted: boolean;
|
|
48
|
+
isTwoFactorEnabled: boolean;
|
|
49
|
+
metadata: import("../../database/entities/index.js").JsonObject;
|
|
50
|
+
lastSignedInAt: string | null;
|
|
51
|
+
createdAt: string;
|
|
52
|
+
};
|
|
53
|
+
signInMethods: import("../users/sign-in-methods.service.js").UserSignInMethods;
|
|
54
|
+
linkedAccounts: {
|
|
55
|
+
provider: import("../../constants.js").SocialProvider;
|
|
56
|
+
email: string | null;
|
|
57
|
+
linkedAt: string;
|
|
58
|
+
}[];
|
|
59
|
+
passkeys: {
|
|
60
|
+
name: string;
|
|
61
|
+
createdAt: string;
|
|
62
|
+
lastUsedAt: string | null;
|
|
63
|
+
}[];
|
|
64
|
+
devices: {
|
|
65
|
+
signInMethod: string;
|
|
66
|
+
ipAddress: string | null;
|
|
67
|
+
userAgent: string | null;
|
|
68
|
+
signedInAt: string;
|
|
69
|
+
lastUsedAt: string;
|
|
70
|
+
endedAt: string | null;
|
|
71
|
+
}[];
|
|
72
|
+
organizations: {
|
|
73
|
+
name: string | null;
|
|
74
|
+
role: import("../../constants.js").OrganizationRole;
|
|
75
|
+
joinedAt: string;
|
|
76
|
+
}[];
|
|
77
|
+
securityHistory: {
|
|
78
|
+
event: string;
|
|
79
|
+
ipAddress: string | null;
|
|
80
|
+
userAgent: string | null;
|
|
81
|
+
details: import("../../database/entities/index.js").JsonObject;
|
|
82
|
+
at: string;
|
|
83
|
+
}[];
|
|
84
|
+
}>;
|
|
85
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.DataExportService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const typeorm_1 = require("typeorm");
|
|
18
|
+
const rate_limiter_service_1 = require("../../common/rate-limiter.service.js");
|
|
19
|
+
const constants_1 = require("../../constants.js");
|
|
20
|
+
const entities_1 = require("../../database/entities/index.js");
|
|
21
|
+
const settings_service_1 = require("../settings/settings.service.js");
|
|
22
|
+
const sign_in_methods_service_1 = require("../users/sign-in-methods.service.js");
|
|
23
|
+
const users_service_1 = require("../users/users.service.js");
|
|
24
|
+
/**
|
|
25
|
+
* "Download my data" (GET /auth/me/export), for privacy laws such as India's DPDP Act and the GDPR.
|
|
26
|
+
*
|
|
27
|
+
* Everything this library stores about the user, in readable form: profile, sign-in methods,
|
|
28
|
+
* linked accounts, passkeys (names only), devices, organizations and their security history.
|
|
29
|
+
* Never included: password hashes, 2FA secrets, backup codes, tokens or keys.
|
|
30
|
+
* Your app adds its own data (orders, rides...) next to this in its own export.
|
|
31
|
+
*/
|
|
32
|
+
let DataExportService = class DataExportService {
|
|
33
|
+
settingsService;
|
|
34
|
+
users;
|
|
35
|
+
signInMethods;
|
|
36
|
+
rateLimiter;
|
|
37
|
+
database;
|
|
38
|
+
constructor(options, settingsService, users, signInMethods, rateLimiter) {
|
|
39
|
+
this.settingsService = settingsService;
|
|
40
|
+
this.users = users;
|
|
41
|
+
this.signInMethods = signInMethods;
|
|
42
|
+
this.rateLimiter = rateLimiter;
|
|
43
|
+
this.database = options.dataSource;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Collects everything this library stores about the user, in readable form.
|
|
47
|
+
* Secrets (password hashes, 2FA secrets, backup codes, tokens, keys) are never included.
|
|
48
|
+
*
|
|
49
|
+
* @param userId - The signed-in user.
|
|
50
|
+
* @returns Profile, sign-in methods, linked accounts, passkeys, devices, organizations and security history.
|
|
51
|
+
* @throws AuthError TOO_MANY_REQUESTS when exported too often.
|
|
52
|
+
*/
|
|
53
|
+
async exportUserData(userId) {
|
|
54
|
+
await this.rateLimiter.consume(constants_1.RATE_LIMIT_KEY.exportDataPerUser(userId), constants_1.RATE_LIMITS.exportDataPerUser);
|
|
55
|
+
const settings = await this.settingsService.getSettings();
|
|
56
|
+
const user = await this.users.getUserOrThrow(userId);
|
|
57
|
+
const [signInMethods, socialAccounts, passkeys, sessions, memberships, history] = await Promise.all([
|
|
58
|
+
this.signInMethods.listSignInMethods(user, settings),
|
|
59
|
+
this.database.getRepository(entities_1.SocialAccountEntity).find({ where: { userId }, order: { createdAt: constants_1.SORT_ORDER.oldestFirst } }),
|
|
60
|
+
this.database.getRepository(entities_1.PasskeyEntity).find({ where: { userId }, order: { createdAt: constants_1.SORT_ORDER.oldestFirst } }),
|
|
61
|
+
this.database.getRepository(entities_1.SessionEntity).find({ where: { userId }, order: { createdAt: constants_1.SORT_ORDER.newestFirst } }),
|
|
62
|
+
this.database.getRepository(entities_1.OrganizationMemberEntity).find({ where: { userId }, order: { createdAt: constants_1.SORT_ORDER.oldestFirst } }),
|
|
63
|
+
this.database.getRepository(entities_1.AuditLogEntity).find({
|
|
64
|
+
where: { userId },
|
|
65
|
+
order: { createdAt: constants_1.SORT_ORDER.newestFirst },
|
|
66
|
+
take: constants_1.DATA_EXPORT_AUDIT_LOG_LIMIT,
|
|
67
|
+
}),
|
|
68
|
+
]);
|
|
69
|
+
const organizations = memberships.length
|
|
70
|
+
? await this.database.getRepository(entities_1.OrganizationEntity).findBy({ id: (0, typeorm_1.In)(memberships.map((membership) => membership.organizationId)) })
|
|
71
|
+
: [];
|
|
72
|
+
return {
|
|
73
|
+
success: true,
|
|
74
|
+
exportedAt: new Date().toISOString(),
|
|
75
|
+
profile: {
|
|
76
|
+
...this.users.toPublicProfile(user, settings),
|
|
77
|
+
termsAcceptedAt: user.termsAcceptedAt?.toISOString() ?? null,
|
|
78
|
+
privacyPolicyAcceptedAt: user.privacyPolicyAcceptedAt?.toISOString() ?? null,
|
|
79
|
+
onboardingCompletedAt: user.onboardingCompletedAt?.toISOString() ?? null,
|
|
80
|
+
updatedAt: user.updatedAt.toISOString(),
|
|
81
|
+
},
|
|
82
|
+
signInMethods,
|
|
83
|
+
linkedAccounts: socialAccounts.map((account) => ({
|
|
84
|
+
provider: account.provider,
|
|
85
|
+
email: account.email,
|
|
86
|
+
linkedAt: account.createdAt.toISOString(),
|
|
87
|
+
})),
|
|
88
|
+
passkeys: passkeys.map((passkey) => ({
|
|
89
|
+
name: passkey.name,
|
|
90
|
+
createdAt: passkey.createdAt.toISOString(),
|
|
91
|
+
lastUsedAt: passkey.lastUsedAt?.toISOString() ?? null,
|
|
92
|
+
})),
|
|
93
|
+
devices: sessions.map((session) => ({
|
|
94
|
+
signInMethod: session.signInMethod,
|
|
95
|
+
ipAddress: session.ipAddress,
|
|
96
|
+
userAgent: session.userAgent,
|
|
97
|
+
signedInAt: session.createdAt.toISOString(),
|
|
98
|
+
lastUsedAt: session.lastUsedAt.toISOString(),
|
|
99
|
+
endedAt: session.revokedAt?.toISOString() ?? null,
|
|
100
|
+
})),
|
|
101
|
+
organizations: memberships.map((membership) => ({
|
|
102
|
+
name: organizations.find((organization) => organization.id === membership.organizationId)?.name ?? null,
|
|
103
|
+
role: membership.role,
|
|
104
|
+
joinedAt: membership.createdAt.toISOString(),
|
|
105
|
+
})),
|
|
106
|
+
securityHistory: history.map((entry) => ({
|
|
107
|
+
event: entry.eventName,
|
|
108
|
+
ipAddress: entry.ipAddress,
|
|
109
|
+
userAgent: entry.userAgent,
|
|
110
|
+
details: entry.details,
|
|
111
|
+
at: entry.createdAt.toISOString(),
|
|
112
|
+
})),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
exports.DataExportService = DataExportService;
|
|
117
|
+
exports.DataExportService = DataExportService = __decorate([
|
|
118
|
+
(0, common_1.Injectable)(),
|
|
119
|
+
__param(0, (0, common_1.Inject)(constants_1.AUTH_OPTIONS_TOKEN)),
|
|
120
|
+
__metadata("design:paramtypes", [Object, settings_service_1.SettingsService,
|
|
121
|
+
users_service_1.UsersService,
|
|
122
|
+
sign_in_methods_service_1.SignInMethodsService,
|
|
123
|
+
rate_limiter_service_1.RateLimiterService])
|
|
124
|
+
], DataExportService);
|
|
125
|
+
//# sourceMappingURL=data-export.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-export.service.js","sourceRoot":"","sources":["../../../src/features/account/data-export.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAA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UAAU,EAAE,EAAE,CAAC,CAAC;gBAC9C,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,KAAK,UAAU,CAAC,cAAc,CAAC,EAAE,IAAI,IAAI,IAAI;gBACvG,IAAI,EAAE,UAAU,CAAC,IAAI;gBACrB,QAAQ,EAAE,UAAU,CAAC,SAAS,CAAC,WAAW,EAAE;aAC7C,CAAC,CAAC;YACH,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBACvC,KAAK,EAAE,KAAK,CAAC,SAAS;gBACtB,SAAS,EAAE,KAAK,CAAC,SAAS;gBAC1B,SAAS,EAAE,KAAK,CAAC,SAAS;gBAC1B,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE;aAClC,CAAC,CAAC;SACJ,CAAC;IACJ,CAAC;CACF,CAAA;AArFY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,eAAM,EAAC,8BAAkB,CAAC,CAAA;6CACO,kCAAe;QACzB,4BAAY;QACJ,8CAAoB;QACtB,yCAAkB;GARvC,iBAAiB,CAqF7B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AuthOptions } from '../../auth-options.js';
|
|
2
|
+
import { RateLimiterService } from '../../common/rate-limiter.service.js';
|
|
3
|
+
import { HealthStatus } from '../../constants.js';
|
|
4
|
+
export interface HealthReport {
|
|
5
|
+
/** True when everything the library needs is reachable. */
|
|
6
|
+
isHealthy: boolean;
|
|
7
|
+
checks: {
|
|
8
|
+
database: HealthStatus;
|
|
9
|
+
redis: HealthStatus;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Answers "can this server sign people in right now?" for load balancers and uptime monitors.
|
|
14
|
+
* Checks only what the library itself needs (PostgreSQL, and Redis when configured).
|
|
15
|
+
*/
|
|
16
|
+
export declare class HealthService {
|
|
17
|
+
private readonly rateLimiter;
|
|
18
|
+
private readonly database;
|
|
19
|
+
constructor(options: AuthOptions, rateLimiter: RateLimiterService);
|
|
20
|
+
/**
|
|
21
|
+
* Checks PostgreSQL and (when configured) Redis, each with a short timeout.
|
|
22
|
+
*
|
|
23
|
+
* @returns `isHealthy` plus the result of each check.
|
|
24
|
+
*/
|
|
25
|
+
check(): Promise<HealthReport>;
|
|
26
|
+
/**
|
|
27
|
+
* @returns "ok" when PostgreSQL answers a trivial query in time, otherwise "error".
|
|
28
|
+
*/
|
|
29
|
+
private checkDatabase;
|
|
30
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.HealthService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const rate_limiter_service_1 = require("../../common/rate-limiter.service.js");
|
|
18
|
+
const time_1 = require("../../common/time.js");
|
|
19
|
+
const constants_1 = require("../../constants.js");
|
|
20
|
+
/**
|
|
21
|
+
* Answers "can this server sign people in right now?" for load balancers and uptime monitors.
|
|
22
|
+
* Checks only what the library itself needs (PostgreSQL, and Redis when configured).
|
|
23
|
+
*/
|
|
24
|
+
let HealthService = class HealthService {
|
|
25
|
+
rateLimiter;
|
|
26
|
+
database;
|
|
27
|
+
constructor(options, rateLimiter) {
|
|
28
|
+
this.rateLimiter = rateLimiter;
|
|
29
|
+
this.database = options.dataSource;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Checks PostgreSQL and (when configured) Redis, each with a short timeout.
|
|
33
|
+
*
|
|
34
|
+
* @returns `isHealthy` plus the result of each check.
|
|
35
|
+
*/
|
|
36
|
+
async check() {
|
|
37
|
+
const [database, redis] = await Promise.all([this.checkDatabase(), this.rateLimiter.checkRedis()]);
|
|
38
|
+
return { isHealthy: database === constants_1.HEALTH_STATUS.ok && redis !== constants_1.HEALTH_STATUS.error, checks: { database, redis } };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @returns "ok" when PostgreSQL answers a trivial query in time, otherwise "error".
|
|
42
|
+
*/
|
|
43
|
+
async checkDatabase() {
|
|
44
|
+
try {
|
|
45
|
+
await (0, time_1.withTimeout)(this.database.query(constants_1.HEALTH_CHECK_QUERY), constants_1.HEALTH_CHECK_TIMEOUT_MS);
|
|
46
|
+
return constants_1.HEALTH_STATUS.ok;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return constants_1.HEALTH_STATUS.error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.HealthService = HealthService;
|
|
54
|
+
exports.HealthService = HealthService = __decorate([
|
|
55
|
+
(0, common_1.Injectable)(),
|
|
56
|
+
__param(0, (0, common_1.Inject)(constants_1.AUTH_OPTIONS_TOKEN)),
|
|
57
|
+
__metadata("design:paramtypes", [Object, rate_limiter_service_1.RateLimiterService])
|
|
58
|
+
], HealthService);
|
|
59
|
+
//# sourceMappingURL=health.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.service.js","sourceRoot":"","sources":["../../../src/features/account/health.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AAGpD,wEAAmE;AACnE,wCAA4C;AAC5C,2CAA2H;AAQ3H;;;GAGG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAa;IAKL;IAJF,QAAQ,CAAa;IAEtC,YAC8B,OAAoB,EAC/B,WAA+B;QAA/B,gBAAW,GAAX,WAAW,CAAoB;QAEhD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IACrC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;QACnG,OAAO,EAAE,SAAS,EAAE,QAAQ,KAAK,yBAAa,CAAC,EAAE,IAAI,KAAK,KAAK,yBAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC;IACpH,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,aAAa;QACzB,IAAI,CAAC;YACH,MAAM,IAAA,kBAAW,EAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,8BAAkB,CAAC,EAAE,mCAAuB,CAAC,CAAC;YACpF,OAAO,yBAAa,CAAC,EAAE,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,yBAAa,CAAC,KAAK,CAAC;QAC7B,CAAC;IACH,CAAC;CACF,CAAA;AA/BY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,eAAM,EAAC,8BAAkB,CAAC,CAAA;6CACG,yCAAkB;GALvC,aAAa,CA+BzB"}
|