@zlooks.cn/password-auth-server 1.0.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.
Files changed (116) hide show
  1. package/.hile-rsc/build-mtie8wg2-ca38f847/client-browser/chunks/chunk-Q3WJINFG.js +48386 -0
  2. package/.hile-rsc/build-mtie8wg2-ca38f847/client-browser/src-plugin-page-frame-07c4de56a6-3F24AYCH.css +170 -0
  3. package/.hile-rsc/build-mtie8wg2-ca38f847/client-browser/src-plugin-page-frame-07c4de56a6-OCDODDFY.js +440 -0
  4. package/.hile-rsc/build-mtie8wg2-ca38f847/client-browser/src-plugin-password-form-3bd63d69e5-CCNUYY62.js +706 -0
  5. package/.hile-rsc/build-mtie8wg2-ca38f847/client-browser/src-plugin-password-form-3bd63d69e5-TRYMJX4F.css +195 -0
  6. package/.hile-rsc/build-mtie8wg2-ca38f847/client-ssr/chunks/chunk-36DACA7C.js +155814 -0
  7. package/.hile-rsc/build-mtie8wg2-ca38f847/client-ssr/src-plugin-page-frame-07c4de56a6-SYE4RRNX.js +441 -0
  8. package/.hile-rsc/build-mtie8wg2-ca38f847/client-ssr/src-plugin-password-form-3bd63d69e5-YVCPJXLL.js +708 -0
  9. package/.hile-rsc/build-mtie8wg2-ca38f847/plugin.json +90 -0
  10. package/.hile-rsc/build-mtie8wg2-ca38f847/server-rsc/index.js +15298 -0
  11. package/.hile-rsc/build-mtie8wg2-ca38f847/styles/4b3193c4f2b317ffed425ccf401342a4bdd6ccfd5f9c42def3315e776f166975.css +385 -0
  12. package/dist/command/index.d.ts +3 -0
  13. package/dist/command/index.d.ts.map +1 -0
  14. package/dist/command/index.js +24 -0
  15. package/dist/command/index.js.map +1 -0
  16. package/dist/config/schema.d.ts +72 -0
  17. package/dist/config/schema.d.ts.map +1 -0
  18. package/dist/config/schema.js +48 -0
  19. package/dist/config/schema.js.map +1 -0
  20. package/dist/email/nodemailer-verification-email-sender.d.ts +11 -0
  21. package/dist/email/nodemailer-verification-email-sender.d.ts.map +1 -0
  22. package/dist/email/nodemailer-verification-email-sender.js +54 -0
  23. package/dist/email/nodemailer-verification-email-sender.js.map +1 -0
  24. package/dist/email/verification-code-rate-limiter.d.ts +14 -0
  25. package/dist/email/verification-code-rate-limiter.d.ts.map +1 -0
  26. package/dist/email/verification-code-rate-limiter.js +27 -0
  27. package/dist/email/verification-code-rate-limiter.js.map +1 -0
  28. package/dist/email/verification-email-sender.d.ts +10 -0
  29. package/dist/email/verification-email-sender.d.ts.map +1 -0
  30. package/dist/email/verification-email-sender.js +2 -0
  31. package/dist/email/verification-email-sender.js.map +1 -0
  32. package/dist/messages/auth-extension/begin.msg.d.ts +3 -0
  33. package/dist/messages/auth-extension/begin.msg.d.ts.map +1 -0
  34. package/dist/messages/auth-extension/begin.msg.js +8 -0
  35. package/dist/messages/auth-extension/begin.msg.js.map +1 -0
  36. package/dist/messages/auth-extension/complete.msg.d.ts +3 -0
  37. package/dist/messages/auth-extension/complete.msg.d.ts.map +1 -0
  38. package/dist/messages/auth-extension/complete.msg.js +8 -0
  39. package/dist/messages/auth-extension/complete.msg.js.map +1 -0
  40. package/dist/migrations/index.d.ts +3 -0
  41. package/dist/migrations/index.d.ts.map +1 -0
  42. package/dist/migrations/index.js +2 -0
  43. package/dist/migrations/index.js.map +1 -0
  44. package/dist/password/attempt-coordinator.d.ts +12 -0
  45. package/dist/password/attempt-coordinator.d.ts.map +1 -0
  46. package/dist/password/attempt-coordinator.js +25 -0
  47. package/dist/password/attempt-coordinator.js.map +1 -0
  48. package/dist/password/credential-lifecycle-outbox.d.ts +42 -0
  49. package/dist/password/credential-lifecycle-outbox.d.ts.map +1 -0
  50. package/dist/password/credential-lifecycle-outbox.js +119 -0
  51. package/dist/password/credential-lifecycle-outbox.js.map +1 -0
  52. package/dist/password/credential-repository.d.ts +41 -0
  53. package/dist/password/credential-repository.d.ts.map +1 -0
  54. package/dist/password/credential-repository.js +64 -0
  55. package/dist/password/credential-repository.js.map +1 -0
  56. package/dist/password/password-authenticator.d.ts +59 -0
  57. package/dist/password/password-authenticator.d.ts.map +1 -0
  58. package/dist/password/password-authenticator.js +184 -0
  59. package/dist/password/password-authenticator.js.map +1 -0
  60. package/dist/password/typeorm-credential-repository.d.ts +15 -0
  61. package/dist/password/typeorm-credential-repository.d.ts.map +1 -0
  62. package/dist/password/typeorm-credential-repository.js +125 -0
  63. package/dist/password/typeorm-credential-repository.js.map +1 -0
  64. package/dist/persistence/entities.d.ts +29 -0
  65. package/dist/persistence/entities.d.ts.map +1 -0
  66. package/dist/persistence/entities.js +49 -0
  67. package/dist/persistence/entities.js.map +1 -0
  68. package/dist/runtime/auth-announcement-publisher.d.ts +18 -0
  69. package/dist/runtime/auth-announcement-publisher.d.ts.map +1 -0
  70. package/dist/runtime/auth-announcement-publisher.js +106 -0
  71. package/dist/runtime/auth-announcement-publisher.js.map +1 -0
  72. package/dist/runtime/password-auth-runtime.d.ts +33 -0
  73. package/dist/runtime/password-auth-runtime.d.ts.map +1 -0
  74. package/dist/runtime/password-auth-runtime.js +218 -0
  75. package/dist/runtime/password-auth-runtime.js.map +1 -0
  76. package/dist/runtime/password-state-store.d.ts +49 -0
  77. package/dist/runtime/password-state-store.d.ts.map +1 -0
  78. package/dist/runtime/password-state-store.js +130 -0
  79. package/dist/runtime/password-state-store.js.map +1 -0
  80. package/dist/service-identity.d.ts +2 -0
  81. package/dist/service-identity.d.ts.map +1 -0
  82. package/dist/service-identity.js +2 -0
  83. package/dist/service-identity.js.map +1 -0
  84. package/dist/services/application.service.d.ts +8 -0
  85. package/dist/services/application.service.d.ts.map +1 -0
  86. package/dist/services/application.service.js +22 -0
  87. package/dist/services/application.service.js.map +1 -0
  88. package/dist/services/config.service.d.ts +63 -0
  89. package/dist/services/config.service.d.ts.map +1 -0
  90. package/dist/services/config.service.js +20 -0
  91. package/dist/services/config.service.js.map +1 -0
  92. package/dist/services/database.service.d.ts +3 -0
  93. package/dist/services/database.service.d.ts.map +1 -0
  94. package/dist/services/database.service.js +23 -0
  95. package/dist/services/database.service.js.map +1 -0
  96. package/dist/services/email.service.d.ts +4 -0
  97. package/dist/services/email.service.d.ts.map +1 -0
  98. package/dist/services/email.service.js +37 -0
  99. package/dist/services/email.service.js.map +1 -0
  100. package/dist/services/logger.service.d.ts +4 -0
  101. package/dist/services/logger.service.d.ts.map +1 -0
  102. package/dist/services/logger.service.js +8 -0
  103. package/dist/services/logger.service.js.map +1 -0
  104. package/dist/services/password-auth.boot.d.ts +3 -0
  105. package/dist/services/password-auth.boot.d.ts.map +1 -0
  106. package/dist/services/password-auth.boot.js +4 -0
  107. package/dist/services/password-auth.boot.js.map +1 -0
  108. package/dist/services/password-runtime.service.d.ts +4 -0
  109. package/dist/services/password-runtime.service.d.ts.map +1 -0
  110. package/dist/services/password-runtime.service.js +135 -0
  111. package/dist/services/password-runtime.service.js.map +1 -0
  112. package/dist/services/redis.service.d.ts +4 -0
  113. package/dist/services/redis.service.d.ts.map +1 -0
  114. package/dist/services/redis.service.js +18 -0
  115. package/dist/services/redis.service.js.map +1 -0
  116. package/package.json +91 -0
@@ -0,0 +1,41 @@
1
+ export interface PasswordCredential {
2
+ readonly subject: string;
3
+ readonly identifier: string;
4
+ readonly passwordHash: string;
5
+ readonly failedAttempts?: number;
6
+ readonly lockedUntil?: Date;
7
+ readonly emailVerifiedAt?: Date;
8
+ readonly passwordChangedAt?: Date;
9
+ readonly registrationTransactionId?: string;
10
+ readonly passwordChangedTransactionId?: string;
11
+ }
12
+ export interface PasswordCredentialLifecycleEvent {
13
+ readonly transactionId: string;
14
+ readonly kind: 'registration' | 'recovery';
15
+ readonly subject: string;
16
+ readonly identifier: string;
17
+ readonly occurredAt: Date;
18
+ }
19
+ export interface PasswordCredentialRepository {
20
+ findByIdentifier(identifier: string): Promise<PasswordCredential | undefined>;
21
+ create(credential: PasswordCredential): Promise<boolean>;
22
+ createWithLifecycleEvent(credential: PasswordCredential, event: PasswordCredentialLifecycleEvent): Promise<boolean>;
23
+ recordFailure(identifier: string, lockedUntil?: Date): Promise<void>;
24
+ recordSuccess(identifier: string): Promise<void>;
25
+ markEmailVerified(identifier: string, verifiedAt: Date): Promise<void>;
26
+ updatePassword(identifier: string, passwordHash: string, changedAt: Date): Promise<void>;
27
+ updatePasswordWithLifecycleEvent(identifier: string, passwordHash: string, changedAt: Date, event: PasswordCredentialLifecycleEvent): Promise<void>;
28
+ }
29
+ /** Test and local-development implementation; not a production persistence boundary. */
30
+ export declare class InMemoryPasswordCredentialRepository implements PasswordCredentialRepository {
31
+ #private;
32
+ findByIdentifier(identifier: string): Promise<PasswordCredential | undefined>;
33
+ create(credential: PasswordCredential): Promise<boolean>;
34
+ createWithLifecycleEvent(credential: PasswordCredential, event: PasswordCredentialLifecycleEvent): Promise<boolean>;
35
+ recordFailure(identifier: string, lockedUntil?: Date): Promise<void>;
36
+ recordSuccess(identifier: string): Promise<void>;
37
+ markEmailVerified(identifier: string, verifiedAt: Date): Promise<void>;
38
+ updatePassword(identifier: string, passwordHash: string, changedAt: Date): Promise<void>;
39
+ updatePasswordWithLifecycleEvent(identifier: string, passwordHash: string, changedAt: Date, event: PasswordCredentialLifecycleEvent): Promise<void>;
40
+ }
41
+ //# sourceMappingURL=credential-repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-repository.d.ts","sourceRoot":"","sources":["../../src/password/credential-repository.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC;IAC5B,QAAQ,CAAC,eAAe,CAAC,EAAE,IAAI,CAAC;IAChC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,IAAI,CAAC;IAClC,QAAQ,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a,oCAAqC,YAAW,4BAA4B;;IAG1E,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAGzF;IAEY,MAAM,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,CAIpE;IAEY,wBAAwB,CACnC,UAAU,EAAE,kBAAkB,EAC9B,KAAK,EAAE,gCAAgC,GACtC,OAAO,CAAC,OAAO,CAAC,CAElB;IAEY,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAQhF;IAEY,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAK5D;IAEY,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAIlF;IAEY,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAepG;IAEY,gCAAgC,CAC3C,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,IAAI,EACf,KAAK,EAAE,gCAAgC,GACtC,OAAO,CAAC,IAAI,CAAC,CASf;CACF"}
@@ -0,0 +1,64 @@
1
+ /** Test and local-development implementation; not a production persistence boundary. */
2
+ export class InMemoryPasswordCredentialRepository {
3
+ #credentials = new Map();
4
+ async findByIdentifier(identifier) {
5
+ const value = this.#credentials.get(identifier);
6
+ return value ? structuredClone(value) : undefined;
7
+ }
8
+ async create(credential) {
9
+ if (this.#credentials.has(credential.identifier))
10
+ return false;
11
+ this.#credentials.set(credential.identifier, structuredClone(credential));
12
+ return true;
13
+ }
14
+ async createWithLifecycleEvent(credential, event) {
15
+ return this.create({ ...credential, registrationTransactionId: event.transactionId });
16
+ }
17
+ async recordFailure(identifier, lockedUntil) {
18
+ const credential = this.#credentials.get(identifier);
19
+ if (!credential)
20
+ return;
21
+ this.#credentials.set(identifier, {
22
+ ...credential,
23
+ failedAttempts: (credential.failedAttempts ?? 0) + 1,
24
+ ...(lockedUntil ? { lockedUntil } : {}),
25
+ });
26
+ }
27
+ async recordSuccess(identifier) {
28
+ const credential = this.#credentials.get(identifier);
29
+ if (!credential)
30
+ return;
31
+ const { lockedUntil: _lockedUntil, ...rest } = credential;
32
+ this.#credentials.set(identifier, { ...rest, failedAttempts: 0 });
33
+ }
34
+ async markEmailVerified(identifier, verifiedAt) {
35
+ const credential = this.#credentials.get(identifier);
36
+ if (!credential)
37
+ return;
38
+ this.#credentials.set(identifier, { ...credential, emailVerifiedAt: verifiedAt });
39
+ }
40
+ async updatePassword(identifier, passwordHash, changedAt) {
41
+ const credential = this.#credentials.get(identifier);
42
+ if (!credential)
43
+ return;
44
+ const { lockedUntil: _lockedUntil, passwordChangedTransactionId: _passwordChangedTransactionId, ...rest } = credential;
45
+ this.#credentials.set(identifier, {
46
+ ...rest,
47
+ passwordHash,
48
+ passwordChangedAt: changedAt,
49
+ emailVerifiedAt: credential.emailVerifiedAt ?? changedAt,
50
+ failedAttempts: 0,
51
+ });
52
+ }
53
+ async updatePasswordWithLifecycleEvent(identifier, passwordHash, changedAt, event) {
54
+ await this.updatePassword(identifier, passwordHash, changedAt);
55
+ const credential = this.#credentials.get(identifier);
56
+ if (credential) {
57
+ this.#credentials.set(identifier, {
58
+ ...credential,
59
+ passwordChangedTransactionId: event.transactionId,
60
+ });
61
+ }
62
+ }
63
+ }
64
+ //# sourceMappingURL=credential-repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-repository.js","sourceRoot":"","sources":["../../src/password/credential-repository.ts"],"names":[],"mappings":"AAuCA,wFAAwF;AACxF,MAAM,OAAO,oCAAoC;IACtC,YAAY,GAAG,IAAI,GAAG,EAA8B,CAAC;IAEvD,KAAK,CAAC,gBAAgB,CAAC,UAAkB;QAC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,CAAC;YACf,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,EAAE;gBAChC,GAAG,UAAU;gBACb,4BAA4B,EAAE,KAAK,CAAC,aAAa;aAClD,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,59 @@
1
+ import type { PasswordAuthConfig } from '../config/schema.js';
2
+ import type { PasswordCredentialRepository } from './credential-repository.js';
3
+ import type { PasswordAttemptCoordinator } from './attempt-coordinator.js';
4
+ type PasswordPolicy = PasswordAuthConfig['password'];
5
+ export type RegistrationResult = {
6
+ readonly ok: true;
7
+ readonly subject: string;
8
+ readonly identifier: string;
9
+ } | {
10
+ readonly ok: false;
11
+ readonly code: 'registration-rejected';
12
+ };
13
+ export type VerificationResult = {
14
+ readonly ok: true;
15
+ readonly subject: string;
16
+ readonly identifier: string;
17
+ readonly emailVerified: boolean;
18
+ } | {
19
+ readonly ok: false;
20
+ readonly code: 'invalid-credentials';
21
+ };
22
+ export declare class PasswordAuthenticator {
23
+ private readonly repository;
24
+ private readonly policy;
25
+ private readonly unknownCredentialHash;
26
+ private readonly clock;
27
+ private readonly attemptCoordinator?;
28
+ private constructor();
29
+ static create(repository: PasswordCredentialRepository, policy: PasswordPolicy, clock?: () => Date, attemptCoordinator?: PasswordAttemptCoordinator): Promise<PasswordAuthenticator>;
30
+ register(input: {
31
+ readonly identifier: string;
32
+ readonly password: string;
33
+ }): Promise<RegistrationResult>;
34
+ private registerCredential;
35
+ private recoverRegistration;
36
+ verify(input: {
37
+ readonly identifier: string;
38
+ readonly password: string;
39
+ }): Promise<VerificationResult>;
40
+ private verifyCredential;
41
+ inspectIdentifier(value: string): Promise<Readonly<{
42
+ identifier?: string;
43
+ exists: boolean;
44
+ }>>;
45
+ registerVerified(input: {
46
+ readonly transactionId: string;
47
+ readonly identifier: string;
48
+ readonly password: string;
49
+ }): Promise<RegistrationResult>;
50
+ verifyEmailIdentity(value: string): Promise<VerificationResult>;
51
+ resetPassword(input: {
52
+ readonly transactionId: string;
53
+ readonly identifier: string;
54
+ readonly password: string;
55
+ }): Promise<VerificationResult>;
56
+ }
57
+ export declare function normalizeEmailIdentifier(value: string): string | undefined;
58
+ export {};
59
+ //# sourceMappingURL=password-authenticator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-authenticator.d.ts","sourceRoot":"","sources":["../../src/password/password-authenticator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAE3E,KAAK,cAAc,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;AAErD,MAAM,MAAM,kBAAkB,GAC1B;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAC5E;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAA;CAAE,CAAC;AAEnE,MAAM,MAAM,kBAAkB,GAC1B;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAA;CAAE,GAC7G;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAA;CAAE,CAAC;AAEjE,qBAAa,qBAAqB;IAE9B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,qBAAqB;I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C;QAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;KAC3B,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA6B9B;CACF;AAaD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG1E"}
@@ -0,0 +1,184 @@
1
+ import { randomBytes, randomUUID } from 'node:crypto';
2
+ import { hash, verify } from '@node-rs/argon2';
3
+ import { z } from 'zod';
4
+ export class PasswordAuthenticator {
5
+ repository;
6
+ policy;
7
+ unknownCredentialHash;
8
+ clock;
9
+ attemptCoordinator;
10
+ constructor(repository, policy, unknownCredentialHash, clock, attemptCoordinator) {
11
+ this.repository = repository;
12
+ this.policy = policy;
13
+ this.unknownCredentialHash = unknownCredentialHash;
14
+ this.clock = clock;
15
+ this.attemptCoordinator = attemptCoordinator;
16
+ }
17
+ static async create(repository, policy, clock = () => new Date(), attemptCoordinator) {
18
+ const unknownCredentialHash = await hash(randomBytes(32), argonOptions(policy));
19
+ return new PasswordAuthenticator(repository, policy, unknownCredentialHash, clock, attemptCoordinator);
20
+ }
21
+ async register(input) {
22
+ const identifier = normalizeEmailIdentifier(input.identifier);
23
+ if (!identifier || !validPassword(input.password, this.policy)) {
24
+ return { ok: false, code: 'registration-rejected' };
25
+ }
26
+ const operation = () => this.registerCredential(identifier, input.password);
27
+ return this.attemptCoordinator ? this.attemptCoordinator.run(identifier, operation) : operation();
28
+ }
29
+ async registerCredential(identifier, password) {
30
+ const existing = await this.repository.findByIdentifier(identifier);
31
+ if (existing)
32
+ return this.recoverRegistration(identifier, password);
33
+ const passwordHash = await hash(password, argonOptions(this.policy));
34
+ const subject = randomUUID();
35
+ const created = await this.repository.create({
36
+ subject,
37
+ identifier,
38
+ passwordHash,
39
+ });
40
+ if (!created)
41
+ return this.recoverRegistration(identifier, password);
42
+ return { ok: true, subject, identifier };
43
+ }
44
+ async recoverRegistration(identifier, password) {
45
+ const verified = await this.verifyCredential(identifier, password);
46
+ return verified.ok
47
+ ? {
48
+ ok: true,
49
+ subject: verified.subject,
50
+ identifier: verified.identifier,
51
+ }
52
+ : { ok: false, code: 'registration-rejected' };
53
+ }
54
+ async verify(input) {
55
+ const identifier = normalizeEmailIdentifier(input.identifier);
56
+ if (identifier && this.attemptCoordinator) {
57
+ return this.attemptCoordinator.run(identifier, async () => this.verifyCredential(identifier, input.password));
58
+ }
59
+ return this.verifyCredential(identifier, input.password);
60
+ }
61
+ async verifyCredential(identifier, password) {
62
+ const credential = identifier
63
+ ? await this.repository.findByIdentifier(identifier)
64
+ : undefined;
65
+ const valid = await verify(credential?.passwordHash ?? this.unknownCredentialHash, password).catch(() => false);
66
+ if (!credential)
67
+ return { ok: false, code: 'invalid-credentials' };
68
+ const now = this.clock();
69
+ if (credential.lockedUntil && credential.lockedUntil > now) {
70
+ return { ok: false, code: 'invalid-credentials' };
71
+ }
72
+ if (!valid) {
73
+ const failures = (credential.failedAttempts ?? 0) + 1;
74
+ await this.repository.recordFailure(identifier, failures >= this.policy.maxFailedAttempts
75
+ ? new Date(now.getTime() + this.policy.lockoutMs)
76
+ : undefined);
77
+ return { ok: false, code: 'invalid-credentials' };
78
+ }
79
+ await this.repository.recordSuccess(identifier);
80
+ return {
81
+ ok: true,
82
+ subject: credential.subject,
83
+ identifier: credential.identifier,
84
+ emailVerified: credential.emailVerifiedAt !== undefined,
85
+ };
86
+ }
87
+ async inspectIdentifier(value) {
88
+ const identifier = normalizeEmailIdentifier(value);
89
+ if (!identifier)
90
+ return { exists: false };
91
+ return { identifier, exists: (await this.repository.findByIdentifier(identifier)) !== undefined };
92
+ }
93
+ async registerVerified(input) {
94
+ const identifier = normalizeEmailIdentifier(input.identifier);
95
+ if (!identifier || !validPassword(input.password, this.policy)) {
96
+ return { ok: false, code: 'registration-rejected' };
97
+ }
98
+ const operation = async () => {
99
+ const existing = await this.repository.findByIdentifier(identifier);
100
+ if (existing?.registrationTransactionId === input.transactionId) {
101
+ return await verify(existing.passwordHash, input.password).catch(() => false)
102
+ ? { ok: true, subject: existing.subject, identifier }
103
+ : { ok: false, code: 'registration-rejected' };
104
+ }
105
+ if (existing) {
106
+ return { ok: false, code: 'registration-rejected' };
107
+ }
108
+ const now = this.clock();
109
+ const subject = randomUUID();
110
+ const created = await this.repository.createWithLifecycleEvent({
111
+ subject,
112
+ identifier,
113
+ passwordHash: await hash(input.password, argonOptions(this.policy)),
114
+ emailVerifiedAt: now,
115
+ passwordChangedAt: now,
116
+ }, {
117
+ transactionId: input.transactionId,
118
+ kind: 'registration',
119
+ subject,
120
+ identifier,
121
+ occurredAt: now,
122
+ });
123
+ if (!created)
124
+ return { ok: false, code: 'registration-rejected' };
125
+ const credential = await this.repository.findByIdentifier(identifier);
126
+ if (!credential)
127
+ throw new Error('Created password credential is unavailable');
128
+ return { ok: true, subject: credential.subject, identifier };
129
+ };
130
+ return this.attemptCoordinator ? this.attemptCoordinator.run(identifier, operation) : operation();
131
+ }
132
+ async verifyEmailIdentity(value) {
133
+ const identifier = normalizeEmailIdentifier(value);
134
+ const credential = identifier ? await this.repository.findByIdentifier(identifier) : undefined;
135
+ if (!identifier || !credential)
136
+ return { ok: false, code: 'invalid-credentials' };
137
+ await this.repository.markEmailVerified(identifier, this.clock());
138
+ return { ok: true, subject: credential.subject, identifier, emailVerified: true };
139
+ }
140
+ async resetPassword(input) {
141
+ const identifier = normalizeEmailIdentifier(input.identifier);
142
+ if (!identifier || !validPassword(input.password, this.policy)) {
143
+ return { ok: false, code: 'invalid-credentials' };
144
+ }
145
+ const operation = async () => {
146
+ const credential = await this.repository.findByIdentifier(identifier);
147
+ if (!credential)
148
+ return { ok: false, code: 'invalid-credentials' };
149
+ if (credential.passwordChangedTransactionId === input.transactionId) {
150
+ return await verify(credential.passwordHash, input.password).catch(() => false)
151
+ ? { ok: true, subject: credential.subject, identifier, emailVerified: true }
152
+ : { ok: false, code: 'invalid-credentials' };
153
+ }
154
+ const changedAt = this.clock();
155
+ await this.repository.updatePasswordWithLifecycleEvent(identifier, await hash(input.password, argonOptions(this.policy)), changedAt, {
156
+ transactionId: input.transactionId,
157
+ kind: 'recovery',
158
+ subject: credential.subject,
159
+ identifier,
160
+ occurredAt: changedAt,
161
+ });
162
+ return { ok: true, subject: credential.subject, identifier, emailVerified: true };
163
+ };
164
+ return this.attemptCoordinator ? this.attemptCoordinator.run(identifier, operation) : operation();
165
+ }
166
+ }
167
+ function argonOptions(policy) {
168
+ return {
169
+ memoryCost: policy.memoryCostKiB,
170
+ timeCost: policy.timeCost,
171
+ parallelism: policy.parallelism,
172
+ outputLen: 32,
173
+ };
174
+ }
175
+ const emailIdentifierSchema = z.email().max(320);
176
+ export function normalizeEmailIdentifier(value) {
177
+ const normalized = value.trim().normalize('NFKC').toLocaleLowerCase('en-US');
178
+ return emailIdentifierSchema.safeParse(normalized).success ? normalized : undefined;
179
+ }
180
+ function validPassword(password, policy) {
181
+ const bytes = new TextEncoder().encode(password).byteLength;
182
+ return bytes >= policy.minLength && bytes <= policy.maxLength;
183
+ }
184
+ //# sourceMappingURL=password-authenticator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-authenticator.js","sourceRoot":"","sources":["../../src/password/password-authenticator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAexB,MAAM,OAAO,qBAAqB;IAEb,UAAU;IACV,MAAM;IACN,qBAAqB;IACrB,KAAK;IACL,kBAAkB;IALrC,YACmB,UAAwC,EACxC,MAAsB,EACtB,qBAA6B,EAC7B,KAAiB,EACjB,kBAA+C;0BAJ/C,UAAU;sBACV,MAAM;qCACN,qBAAqB;qBACrB,KAAK;kCACL,kBAAkB;IAClC,CAAC;IAEG,MAAM,CAAC,KAAK,CAAC,MAAM,CACxB,UAAwC,EACxC,MAAsB,EACtB,KAA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AiB,CAAC,OAAO,CAAC,CAAC;IAC7E,OAAO,qBAAqB,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;AACtF,CAAC;AAED,SAAS,aAAa,CAAC,QAAgB,EAAE,MAAsB;IAC7D,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC;IAC5D,OAAO,KAAK,IAAI,MAAM,CAAC,SAAS,IAAI,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC;AAChE,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { type DataSource } from 'typeorm';
2
+ import type { PasswordCredential, PasswordCredentialLifecycleEvent, PasswordCredentialRepository } from './credential-repository.js';
3
+ export declare class TypeOrmPasswordCredentialRepository implements PasswordCredentialRepository {
4
+ private readonly dataSource;
5
+ constructor(dataSource: DataSource);
6
+ findByIdentifier(identifier: string): Promise<PasswordCredential | undefined>;
7
+ create(credential: PasswordCredential): Promise<boolean>;
8
+ createWithLifecycleEvent(credential: PasswordCredential, event: PasswordCredentialLifecycleEvent): Promise<boolean>;
9
+ recordFailure(identifier: string, lockedUntil?: Date): Promise<void>;
10
+ recordSuccess(identifier: string): Promise<void>;
11
+ markEmailVerified(identifier: string, verifiedAt: Date): Promise<void>;
12
+ updatePassword(identifier: string, passwordHash: string, changedAt: Date): Promise<void>;
13
+ updatePasswordWithLifecycleEvent(identifier: string, passwordHash: string, changedAt: Date, event: PasswordCredentialLifecycleEvent): Promise<void>;
14
+ }
15
+ //# sourceMappingURL=typeorm-credential-repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeorm-credential-repository.d.ts","sourceRoot":"","sources":["../../src/password/typeorm-credential-repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAKlD,OAAO,KAAK,EACV,kBAAkB,EAClB,gCAAgC,EAChC,4BAA4B,EAC7B,MAAM,4BAA4B,CAAC;AAEpC,qBAAa,mCAAoC,YAAW,4BAA4B;IACnE,OAAO,CAAC,QAAQ,CAAC,UAAU;IAA9C,YAAoC,UAAU,EAAE,UAAU,EAAI;IAEjD,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAiBzF;IAEY,MAAM,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,CAkBpE;IAEY,wBAAwB,CACnC,UAAU,EAAE,kBAAkB,EAC9B,KAAK,EAAE,gCAAgC,GACtC,OAAO,CAAC,OAAO,CAAC,CAqBlB;IAEY,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAMhF;IAEY,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAK5D;IAEY,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAKlF;IAEY,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAYpG;IAEY,gCAAgC,CAC3C,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,IAAI,EACf,KAAK,EAAE,gCAAgC,GACtC,OAAO,CAAC,IAAI,CAAC,CAgBf;CACF"}
@@ -0,0 +1,125 @@
1
+ import { IsNull } from 'typeorm';
2
+ import { PasswordCredentialEntity, PasswordCredentialLifecycleOutboxEntity, } from '../persistence/entities.js';
3
+ export class TypeOrmPasswordCredentialRepository {
4
+ dataSource;
5
+ constructor(dataSource) {
6
+ this.dataSource = dataSource;
7
+ }
8
+ async findByIdentifier(identifier) {
9
+ const row = await this.dataSource.getRepository(PasswordCredentialEntity).findOneBy({ identifier });
10
+ return row ? {
11
+ subject: row.subject,
12
+ identifier: row.identifier,
13
+ passwordHash: row.passwordHash,
14
+ failedAttempts: row.failedAttempts,
15
+ ...(row.lockedUntil ? { lockedUntil: row.lockedUntil } : {}),
16
+ ...(row.emailVerifiedAt ? { emailVerifiedAt: row.emailVerifiedAt } : {}),
17
+ ...(row.passwordChangedAt ? { passwordChangedAt: row.passwordChangedAt } : {}),
18
+ ...(row.registrationTransactionId
19
+ ? { registrationTransactionId: row.registrationTransactionId }
20
+ : {}),
21
+ ...(row.passwordChangedTransactionId
22
+ ? { passwordChangedTransactionId: row.passwordChangedTransactionId }
23
+ : {}),
24
+ } : undefined;
25
+ }
26
+ async create(credential) {
27
+ try {
28
+ await this.dataSource.getRepository(PasswordCredentialEntity).insert({
29
+ subject: credential.subject,
30
+ identifier: credential.identifier,
31
+ passwordHash: credential.passwordHash,
32
+ failedAttempts: 0,
33
+ lockedUntil: null,
34
+ emailVerifiedAt: credential.emailVerifiedAt ?? null,
35
+ passwordChangedAt: credential.passwordChangedAt ?? null,
36
+ registrationTransactionId: credential.registrationTransactionId ?? null,
37
+ passwordChangedTransactionId: credential.passwordChangedTransactionId ?? null,
38
+ });
39
+ return true;
40
+ }
41
+ catch (error) {
42
+ if (isUniqueViolation(error))
43
+ return false;
44
+ throw error;
45
+ }
46
+ }
47
+ async createWithLifecycleEvent(credential, event) {
48
+ try {
49
+ await this.dataSource.transaction(async (manager) => {
50
+ await manager.getRepository(PasswordCredentialEntity).insert({
51
+ subject: credential.subject,
52
+ identifier: credential.identifier,
53
+ passwordHash: credential.passwordHash,
54
+ failedAttempts: 0,
55
+ lockedUntil: null,
56
+ emailVerifiedAt: credential.emailVerifiedAt ?? null,
57
+ passwordChangedAt: credential.passwordChangedAt ?? null,
58
+ registrationTransactionId: event.transactionId,
59
+ passwordChangedTransactionId: credential.passwordChangedTransactionId ?? null,
60
+ });
61
+ await manager.getRepository(PasswordCredentialLifecycleOutboxEntity).insert(toOutboxRow(event));
62
+ });
63
+ return true;
64
+ }
65
+ catch (error) {
66
+ if (isUniqueViolation(error))
67
+ return false;
68
+ throw error;
69
+ }
70
+ }
71
+ async recordFailure(identifier, lockedUntil) {
72
+ await this.dataSource.transaction(async (manager) => {
73
+ const repository = manager.getRepository(PasswordCredentialEntity);
74
+ await repository.increment({ identifier }, 'failedAttempts', 1);
75
+ if (lockedUntil)
76
+ await repository.update({ identifier }, { lockedUntil });
77
+ });
78
+ }
79
+ async recordSuccess(identifier) {
80
+ await this.dataSource.getRepository(PasswordCredentialEntity).update({ identifier }, { failedAttempts: 0, lockedUntil: null });
81
+ }
82
+ async markEmailVerified(identifier, verifiedAt) {
83
+ await this.dataSource.getRepository(PasswordCredentialEntity).update({ identifier, emailVerifiedAt: IsNull() }, { emailVerifiedAt: verifiedAt });
84
+ }
85
+ async updatePassword(identifier, passwordHash, changedAt) {
86
+ await this.dataSource.getRepository(PasswordCredentialEntity).update({ identifier }, {
87
+ passwordHash,
88
+ passwordChangedAt: changedAt,
89
+ emailVerifiedAt: changedAt,
90
+ passwordChangedTransactionId: null,
91
+ failedAttempts: 0,
92
+ lockedUntil: null,
93
+ });
94
+ }
95
+ async updatePasswordWithLifecycleEvent(identifier, passwordHash, changedAt, event) {
96
+ await this.dataSource.transaction(async (manager) => {
97
+ const updated = await manager.getRepository(PasswordCredentialEntity).update({ identifier }, {
98
+ passwordHash,
99
+ passwordChangedAt: changedAt,
100
+ emailVerifiedAt: changedAt,
101
+ failedAttempts: 0,
102
+ lockedUntil: null,
103
+ passwordChangedTransactionId: event.transactionId,
104
+ });
105
+ if (updated.affected !== 1)
106
+ throw new Error('Password credential is unavailable');
107
+ await manager.getRepository(PasswordCredentialLifecycleOutboxEntity).insert(toOutboxRow(event));
108
+ });
109
+ }
110
+ }
111
+ function toOutboxRow(event) {
112
+ return {
113
+ transactionId: event.transactionId,
114
+ kind: event.kind,
115
+ subject: event.subject,
116
+ identifier: event.identifier,
117
+ occurredAt: event.occurredAt,
118
+ attempts: 0,
119
+ nextAttemptAt: event.occurredAt,
120
+ };
121
+ }
122
+ function isUniqueViolation(error) {
123
+ return typeof error === 'object' && error !== null && 'code' in error && error.code === '23505';
124
+ }
125
+ //# sourceMappingURL=typeorm-credential-repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeorm-credential-repository.js","sourceRoot":"","sources":["../../src/password/typeorm-credential-repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmB,MAAM,SAAS,CAAC;AAClD,OAAO,EACL,wBAAwB,EACxB,uCAAuC,GACxC,MAAM,4BAA4B,CAAC;AAOpC,MAAM,OAAO,mCAAmC;IACV,UAAU;IAA9C,YAAoC,UAAsB;0BAAtB,UAAU;IAAe,CAAC;IAEvD,KAAK,CAAC,gBAAgB,CAAC,UAAkB;QAC9C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,wBAAwB,CAAC,CAAC,SAAS,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;QACpG,OAAO,GAAG,CAAC,CAAC,CAAC;YACX,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,YAAY,EAAE,GAAG,CAAC,YAAY;YAC9B,cAAc,EAAE,GAAG,CAAC,cAAc;YAClC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5D,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,GAAG,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACxE,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC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AClF,MAAM,OAAO,CAAC,aAAa,CAAC,uCAAuC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;QAClG,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,SAAS,WAAW,CAAC,KAAuC;IAC1D,OAAO;QACL,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,QAAQ,EAAE,CAAC;QACX,aAAa,EAAE,KAAK,CAAC,UAAU;KAChC,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc;IACvC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC;AAClG,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { EntitySchema } from 'typeorm';
2
+ export interface PasswordCredentialRow {
3
+ subject: string;
4
+ identifier: string;
5
+ passwordHash: string;
6
+ failedAttempts: number;
7
+ lockedUntil: Date | null;
8
+ emailVerifiedAt: Date | null;
9
+ passwordChangedAt: Date | null;
10
+ registrationTransactionId: string | null;
11
+ passwordChangedTransactionId: string | null;
12
+ createdAt: Date;
13
+ updatedAt: Date;
14
+ version: number;
15
+ }
16
+ export interface PasswordCredentialLifecycleOutboxRow {
17
+ transactionId: string;
18
+ kind: 'registration' | 'recovery';
19
+ subject: string;
20
+ identifier: string;
21
+ occurredAt: Date;
22
+ attempts: number;
23
+ nextAttemptAt: Date;
24
+ createdAt: Date;
25
+ }
26
+ export declare const PasswordCredentialEntity: EntitySchema<PasswordCredentialRow>;
27
+ export declare const PasswordCredentialLifecycleOutboxEntity: EntitySchema<PasswordCredentialLifecycleOutboxRow>;
28
+ export declare const passwordAuthEntities: readonly [EntitySchema<PasswordCredentialRow>, EntitySchema<PasswordCredentialLifecycleOutboxRow>];
29
+ //# sourceMappingURL=entities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../src/persistence/entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,IAAI,GAAG,IAAI,CAAC;IACzB,eAAe,EAAE,IAAI,GAAG,IAAI,CAAC;IAC7B,iBAAiB,EAAE,IAAI,GAAG,IAAI,CAAC;IAC/B,yBAAyB,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,4BAA4B,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5C,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,oCAAoC;IACnD,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,cAAc,GAAG,UAAU,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,IAAI,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,IAAI,CAAC;IACpB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,eAAO,MAAM,wBAAwB,qCA2BnC,CAAC;AAEH,eAAO,MAAM,uCAAuC,oDAclD,CAAC;AAEH,eAAO,MAAM,oBAAoB,oGAGvB,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { EntitySchema } from 'typeorm';
2
+ export const PasswordCredentialEntity = new EntitySchema({
3
+ name: 'PasswordCredential',
4
+ tableName: 'password_credentials',
5
+ columns: {
6
+ subject: { type: 'uuid', primary: true },
7
+ identifier: { type: 'varchar', length: 320, unique: true },
8
+ passwordHash: { name: 'password_hash', type: 'text' },
9
+ failedAttempts: { name: 'failed_attempts', type: 'integer', default: 0 },
10
+ lockedUntil: { name: 'locked_until', type: 'timestamptz', nullable: true },
11
+ emailVerifiedAt: { name: 'email_verified_at', type: 'timestamptz', nullable: true },
12
+ passwordChangedAt: { name: 'password_changed_at', type: 'timestamptz', nullable: true },
13
+ registrationTransactionId: {
14
+ name: 'registration_transaction_id',
15
+ type: 'uuid',
16
+ unique: true,
17
+ nullable: true,
18
+ },
19
+ passwordChangedTransactionId: {
20
+ name: 'password_changed_transaction_id',
21
+ type: 'uuid',
22
+ unique: true,
23
+ nullable: true,
24
+ },
25
+ createdAt: { name: 'created_at', type: 'timestamptz', createDate: true },
26
+ updatedAt: { name: 'updated_at', type: 'timestamptz', updateDate: true },
27
+ version: { type: 'integer', version: true },
28
+ },
29
+ });
30
+ export const PasswordCredentialLifecycleOutboxEntity = new EntitySchema({
31
+ name: 'PasswordCredentialLifecycleOutbox',
32
+ tableName: 'password_credential_lifecycle_outbox',
33
+ columns: {
34
+ transactionId: { name: 'transaction_id', type: 'uuid', primary: true },
35
+ kind: { type: 'varchar', length: 16 },
36
+ subject: { type: 'uuid' },
37
+ identifier: { type: 'varchar', length: 320 },
38
+ occurredAt: { name: 'occurred_at', type: 'timestamptz' },
39
+ attempts: { type: 'integer', default: 0 },
40
+ nextAttemptAt: { name: 'next_attempt_at', type: 'timestamptz' },
41
+ createdAt: { name: 'created_at', type: 'timestamptz', createDate: true },
42
+ },
43
+ indices: [{ name: 'idx_password_credential_lifecycle_due', columns: ['nextAttemptAt'] }],
44
+ });
45
+ export const passwordAuthEntities = [
46
+ PasswordCredentialEntity,
47
+ PasswordCredentialLifecycleOutboxEntity,
48
+ ];
49
+ //# sourceMappingURL=entities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entities.js","sourceRoot":"","sources":["../../src/persistence/entities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