@zlooks.cn/password-auth-server 1.0.9 → 1.1.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 (33) hide show
  1. package/.hile-rsc/{build-mu2ebvjj-b7c71e74/client-browser/src-plugin-password-form-3bd63d69e5-4TOGMUOJ.js → build-mu41ll5m-02df9102/client-browser/src-plugin-password-form-3bd63d69e5-MO3JJSBS.js} +92 -86
  2. package/.hile-rsc/{build-mu2ebvjj-b7c71e74/client-ssr/src-plugin-password-form-3bd63d69e5-S65T2FFP.js → build-mu41ll5m-02df9102/client-ssr/src-plugin-password-form-3bd63d69e5-MWQ7H3E5.js} +92 -86
  3. package/.hile-rsc/{build-mu2ebvjj-b7c71e74 → build-mu41ll5m-02df9102}/plugin.json +9 -9
  4. package/.hile-rsc/{build-mu2ebvjj-b7c71e74 → build-mu41ll5m-02df9102}/server-rsc/index.js +94 -88
  5. package/dist/password/password-authenticator.d.ts +4 -1
  6. package/dist/password/password-authenticator.d.ts.map +1 -1
  7. package/dist/password/password-authenticator.js +62 -9
  8. package/dist/password/password-authenticator.js.map +1 -1
  9. package/dist/password/typeorm-credential-repository.d.ts.map +1 -1
  10. package/dist/password/typeorm-credential-repository.js +11 -46
  11. package/dist/password/typeorm-credential-repository.js.map +1 -1
  12. package/dist/persistence/entities.d.ts +1 -12
  13. package/dist/persistence/entities.d.ts.map +1 -1
  14. package/dist/persistence/entities.js +0 -16
  15. package/dist/persistence/entities.js.map +1 -1
  16. package/dist/services/application.service.d.ts.map +1 -1
  17. package/dist/services/application.service.js +2 -1
  18. package/dist/services/application.service.js.map +1 -1
  19. package/dist/services/password-runtime.service.d.ts.map +1 -1
  20. package/dist/services/password-runtime.service.js +7 -17
  21. package/dist/services/password-runtime.service.js.map +1 -1
  22. package/package.json +8 -6
  23. package/dist/password/credential-lifecycle-outbox.d.ts +0 -42
  24. package/dist/password/credential-lifecycle-outbox.d.ts.map +0 -1
  25. package/dist/password/credential-lifecycle-outbox.js +0 -120
  26. package/dist/password/credential-lifecycle-outbox.js.map +0 -1
  27. /package/.hile-rsc/{build-mu2ebvjj-b7c71e74 → build-mu41ll5m-02df9102}/client-browser/chunks/chunk-ZV6MPT36.js +0 -0
  28. /package/.hile-rsc/{build-mu2ebvjj-b7c71e74 → build-mu41ll5m-02df9102}/client-browser/src-plugin-page-frame-07c4de56a6-24L24OGL.js +0 -0
  29. /package/.hile-rsc/{build-mu2ebvjj-b7c71e74 → build-mu41ll5m-02df9102}/client-browser/src-plugin-page-frame-07c4de56a6-3F24AYCH.css +0 -0
  30. /package/.hile-rsc/{build-mu2ebvjj-b7c71e74 → build-mu41ll5m-02df9102}/client-browser/src-plugin-password-form-3bd63d69e5-TRYMJX4F.css +0 -0
  31. /package/.hile-rsc/{build-mu2ebvjj-b7c71e74 → build-mu41ll5m-02df9102}/client-ssr/chunks/chunk-EWBYMJX4.js +0 -0
  32. /package/.hile-rsc/{build-mu2ebvjj-b7c71e74 → build-mu41ll5m-02df9102}/client-ssr/src-plugin-page-frame-07c4de56a6-LN2W67ZP.js +0 -0
  33. /package/.hile-rsc/{build-mu2ebvjj-b7c71e74 → build-mu41ll5m-02df9102}/styles/4b3193c4f2b317ffed425ccf401342a4bdd6ccfd5f9c42def3315e776f166975.css +0 -0
@@ -1,120 +0,0 @@
1
- import { createExecutionContext } from '@hile/context';
2
- import { Scheduler } from '@hile/schedule';
3
- import { parseUserCredentialLifecycleResponse, USER_CREDENTIAL_LIFECYCLE_OPERATION, USER_CREDENTIAL_LIFECYCLE_PROTOCOL, USER_SERVICE_NAMESPACE, } from '@zlooks.cn/user-shared';
4
- import { LessThanOrEqual } from 'typeorm';
5
- import { PasswordCredentialLifecycleOutboxEntity, } from '../persistence/entities.js';
6
- import { PASSWORD_AUTH_EXTENSION_ID, PASSWORD_AUTH_METHOD_ID, } from '../service-identity.js';
7
- export class TypeOrmPasswordCredentialLifecycleOutboxStore {
8
- dataSource;
9
- constructor(dataSource) {
10
- this.dataSource = dataSource;
11
- }
12
- async readDue(now, limit) {
13
- return this.dataSource.getRepository(PasswordCredentialLifecycleOutboxEntity).find({
14
- where: { nextAttemptAt: LessThanOrEqual(now) },
15
- order: { createdAt: 'ASC' },
16
- take: limit,
17
- select: {
18
- transactionId: true,
19
- kind: true,
20
- subject: true,
21
- identifier: true,
22
- occurredAt: true,
23
- attempts: true,
24
- },
25
- });
26
- }
27
- async acknowledge(transactionId) {
28
- await this.dataSource.getRepository(PasswordCredentialLifecycleOutboxEntity).delete({ transactionId });
29
- }
30
- async recordFailure(transactionId, attempts, nextAttemptAt) {
31
- await this.dataSource.getRepository(PasswordCredentialLifecycleOutboxEntity).update({ transactionId }, { attempts, nextAttemptAt });
32
- }
33
- }
34
- export class PasswordCredentialLifecyclePublisher {
35
- options;
36
- #scheduler = new Scheduler();
37
- #clock;
38
- #inFlight = new Set();
39
- #controllers = new Set();
40
- #closing = false;
41
- constructor(options) {
42
- this.options = options;
43
- this.#clock = options.clock ?? (() => new Date());
44
- }
45
- start() {
46
- this.#scheduler.add('credential-lifecycle-outbox', '*/2 * * * * *', async () => {
47
- await this.flush();
48
- }, {
49
- distributed: {
50
- redis: this.options.redis,
51
- ttl: 30_000,
52
- namespace: 'zlooks.password-auth',
53
- policy: 'skip-if-locked',
54
- renew: true,
55
- },
56
- onError: (error) => this.options.onError?.(error),
57
- });
58
- }
59
- async close() {
60
- this.#closing = true;
61
- this.#scheduler.stop();
62
- for (const controller of this.#controllers)
63
- controller.abort();
64
- await Promise.allSettled(this.#inFlight);
65
- }
66
- async flush() {
67
- if (this.#closing)
68
- return;
69
- const operation = this.runFlush();
70
- this.#inFlight.add(operation);
71
- try {
72
- await operation;
73
- }
74
- finally {
75
- this.#inFlight.delete(operation);
76
- }
77
- }
78
- async runFlush() {
79
- const controller = new AbortController();
80
- this.#controllers.add(controller);
81
- try {
82
- const events = await this.options.store.readDue(this.#clock(), 20);
83
- for (let offset = 0; offset < events.length && !controller.signal.aborted; offset += 5) {
84
- await Promise.all(events.slice(offset, offset + 5).map((event) => this.publish(event, controller.signal)));
85
- }
86
- }
87
- finally {
88
- this.#controllers.delete(controller);
89
- }
90
- }
91
- async publish(event, signal) {
92
- try {
93
- const payload = {
94
- protocol: USER_CREDENTIAL_LIFECYCLE_PROTOCOL,
95
- kind: event.kind,
96
- authenticationTransactionId: event.transactionId,
97
- extensionId: PASSWORD_AUTH_EXTENSION_ID,
98
- methodId: PASSWORD_AUTH_METHOD_ID,
99
- subject: event.subject,
100
- email: event.identifier,
101
- occurredAt: event.occurredAt.toISOString(),
102
- };
103
- parseUserCredentialLifecycleResponse(await this.options.application.call(USER_SERVICE_NAMESPACE, USER_CREDENTIAL_LIFECYCLE_OPERATION, payload, {
104
- context: createExecutionContext({}),
105
- timeout: 5_000,
106
- retries: 0,
107
- signal,
108
- }));
109
- await this.options.store.acknowledge(event.transactionId);
110
- }
111
- catch (error) {
112
- const attempts = event.attempts + 1;
113
- const delayMs = Math.min(60_000, 1_000 * (2 ** Math.min(attempts, 6)));
114
- await this.options.store.recordFailure(event.transactionId, attempts, new Date(this.#clock().getTime() + delayMs));
115
- if (!signal.aborted)
116
- this.options.onError?.(error, event);
117
- }
118
- }
119
- }
120
- //# sourceMappingURL=credential-lifecycle-outbox.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"credential-lifecycle-outbox.js","sourceRoot":"","sources":["../../src/password/credential-lifecycle-outbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAyB,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACL,oCAAoC,EACpC,mCAAmC,EACnC,kCAAkC,EAClC,sBAAsB,GAEvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,eAAe,EAAmB,MAAM,SAAS,CAAC;AAC3D,OAAO,EACL,uCAAuC,GAExC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,0BAA0B,EAC1B,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