alepha 0.13.2 → 0.13.4

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 (91) hide show
  1. package/README.md +7 -7
  2. package/dist/api-files/index.browser.js +80 -0
  3. package/dist/api-files/index.browser.js.map +1 -0
  4. package/dist/api-files/index.d.ts +175 -175
  5. package/dist/api-jobs/index.browser.js +56 -0
  6. package/dist/api-jobs/index.browser.js.map +1 -0
  7. package/dist/api-jobs/index.d.ts +156 -156
  8. package/dist/api-notifications/index.browser.js +382 -0
  9. package/dist/api-notifications/index.browser.js.map +1 -0
  10. package/dist/api-notifications/index.d.ts +221 -166
  11. package/dist/api-notifications/index.js +107 -55
  12. package/dist/api-notifications/index.js.map +1 -1
  13. package/dist/api-parameters/index.browser.js +29 -0
  14. package/dist/api-parameters/index.browser.js.map +1 -0
  15. package/dist/api-users/index.d.ts +16 -3
  16. package/dist/api-users/index.js +75 -28
  17. package/dist/api-users/index.js.map +1 -1
  18. package/dist/api-verifications/index.browser.js +52 -0
  19. package/dist/api-verifications/index.browser.js.map +1 -0
  20. package/dist/api-verifications/index.d.ts +120 -98
  21. package/dist/api-verifications/index.js +1 -1
  22. package/dist/api-verifications/index.js.map +1 -1
  23. package/dist/batch/index.js +0 -5
  24. package/dist/batch/index.js.map +1 -1
  25. package/dist/bucket/index.js +7 -5
  26. package/dist/bucket/index.js.map +1 -1
  27. package/dist/cli/{dist-Dl9Vl7Ur.js → dist-lGnqsKpu.js} +11 -15
  28. package/dist/cli/dist-lGnqsKpu.js.map +1 -0
  29. package/dist/cli/index.d.ts +26 -45
  30. package/dist/cli/index.js +40 -58
  31. package/dist/cli/index.js.map +1 -1
  32. package/dist/command/index.d.ts +1 -0
  33. package/dist/command/index.js +9 -0
  34. package/dist/command/index.js.map +1 -1
  35. package/dist/core/index.browser.js +5 -1
  36. package/dist/core/index.browser.js.map +1 -1
  37. package/dist/core/index.d.ts +221 -219
  38. package/dist/core/index.js +5 -1
  39. package/dist/core/index.js.map +1 -1
  40. package/dist/core/index.native.js +5 -1
  41. package/dist/core/index.native.js.map +1 -1
  42. package/dist/email/index.d.ts +4 -4
  43. package/dist/email/index.js +5 -0
  44. package/dist/email/index.js.map +1 -1
  45. package/dist/orm/index.d.ts +19 -19
  46. package/dist/orm/index.js +3 -3
  47. package/dist/orm/index.js.map +1 -1
  48. package/dist/redis/index.d.ts +10 -10
  49. package/dist/security/index.d.ts +28 -28
  50. package/dist/security/index.js +3 -3
  51. package/dist/security/index.js.map +1 -1
  52. package/dist/server/index.d.ts +9 -9
  53. package/dist/server-auth/index.d.ts +152 -152
  54. package/dist/server-cookies/index.js +2 -2
  55. package/dist/server-cookies/index.js.map +1 -1
  56. package/dist/server-links/index.d.ts +33 -33
  57. package/dist/server-security/index.d.ts +9 -9
  58. package/dist/server-static/index.js +18 -2
  59. package/dist/server-static/index.js.map +1 -1
  60. package/package.json +16 -6
  61. package/src/api-files/index.browser.ts +17 -0
  62. package/src/api-jobs/index.browser.ts +15 -0
  63. package/src/api-notifications/controllers/NotificationController.ts +26 -1
  64. package/src/api-notifications/index.browser.ts +17 -0
  65. package/src/api-notifications/index.ts +1 -0
  66. package/src/api-notifications/schemas/notificationQuerySchema.ts +13 -0
  67. package/src/api-notifications/services/NotificationService.ts +45 -2
  68. package/src/api-parameters/index.browser.ts +12 -0
  69. package/src/api-users/atoms/realmAuthSettingsAtom.ts +3 -1
  70. package/src/api-users/controllers/UserController.ts +21 -1
  71. package/src/api-users/primitives/$userRealm.ts +33 -10
  72. package/src/api-users/providers/UserRealmProvider.ts +1 -0
  73. package/src/api-users/services/SessionService.ts +2 -0
  74. package/src/api-users/services/UserService.ts +56 -16
  75. package/src/api-verifications/index.browser.ts +15 -0
  76. package/src/api-verifications/index.ts +1 -0
  77. package/src/batch/providers/BatchProvider.ts +0 -7
  78. package/src/bucket/index.ts +7 -5
  79. package/src/cli/apps/AlephaCli.ts +27 -1
  80. package/src/cli/apps/AlephaPackageBuilderCli.ts +3 -0
  81. package/src/cli/commands/CoreCommands.ts +6 -2
  82. package/src/cli/commands/ViteCommands.ts +2 -1
  83. package/src/cli/services/ProjectUtils.ts +40 -75
  84. package/src/command/helpers/Asker.ts +10 -0
  85. package/src/core/Alepha.ts +14 -0
  86. package/src/core/primitives/$module.ts +1 -1
  87. package/src/email/index.ts +13 -5
  88. package/src/orm/providers/drivers/NodeSqliteProvider.ts +3 -3
  89. package/src/server-cookies/providers/ServerCookiesProvider.ts +2 -1
  90. package/src/server-static/providers/ServerStaticProvider.ts +18 -3
  91. package/dist/cli/dist-Dl9Vl7Ur.js.map +0 -1
@@ -0,0 +1,52 @@
1
+ import { $module, t } from "alepha";
2
+ import { $entity, pg } from "alepha/orm";
3
+
4
+ //#region src/api-verifications/schemas/verificationTypeEnumSchema.ts
5
+ const verificationTypeEnumSchema = t.enum(["code", "link"]);
6
+
7
+ //#endregion
8
+ //#region src/api-verifications/entities/verifications.ts
9
+ const verifications = $entity({
10
+ name: "verification",
11
+ schema: t.object({
12
+ id: pg.primaryKey(t.bigint()),
13
+ createdAt: pg.createdAt(),
14
+ updatedAt: pg.updatedAt(),
15
+ version: pg.version(),
16
+ type: verificationTypeEnumSchema,
17
+ target: t.text({ description: "Can be a phone (E.164 format) or email address" }),
18
+ code: t.text({ description: "Hashed verification token (n-digit code or UUID)" }),
19
+ verifiedAt: t.optional(t.datetime({ description: "When it was successfully verified" })),
20
+ attempts: pg.default(t.integer({ description: "Number of failed attempts (to prevent brute-force)" }), 0)
21
+ }),
22
+ indexes: ["createdAt", { columns: ["target", "code"] }]
23
+ });
24
+ const verificationEntitySchema = verifications.schema;
25
+ const verificationEntityInsertSchema = verifications.insertSchema;
26
+
27
+ //#endregion
28
+ //#region src/api-verifications/schemas/requestVerificationCodeResponseSchema.ts
29
+ const requestVerificationCodeResponseSchema = t.object({
30
+ token: t.string({ description: "The verification token (6-digit code for phone, UUID for email). The caller should send this to the user via their preferred notification method." }),
31
+ codeExpiration: t.integer({ description: "Time in seconds before your verification token expires." }),
32
+ verificationCooldown: t.integer({ description: "Cooldown period in seconds before you can request another verification." }),
33
+ maxVerificationAttempts: t.integer({ description: "Maximum number of verification attempts allowed before the token is locked." })
34
+ });
35
+
36
+ //#endregion
37
+ //#region src/api-verifications/schemas/validateVerificationCodeResponseSchema.ts
38
+ const validateVerificationCodeResponseSchema = t.object({
39
+ ok: t.boolean({ description: "Indicates whether the verification was successful." }),
40
+ alreadyVerified: t.optional(t.boolean({ description: "Indicates whether the target was already verified." }))
41
+ });
42
+
43
+ //#endregion
44
+ //#region src/api-verifications/index.browser.ts
45
+ const AlephaApiVerification = $module({
46
+ name: "alepha.api.verifications",
47
+ services: []
48
+ });
49
+
50
+ //#endregion
51
+ export { AlephaApiVerification, requestVerificationCodeResponseSchema, validateVerificationCodeResponseSchema, verificationEntityInsertSchema, verificationEntitySchema, verificationTypeEnumSchema, verifications };
52
+ //# sourceMappingURL=index.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.browser.js","names":[],"sources":["../../src/api-verifications/schemas/verificationTypeEnumSchema.ts","../../src/api-verifications/entities/verifications.ts","../../src/api-verifications/schemas/requestVerificationCodeResponseSchema.ts","../../src/api-verifications/schemas/validateVerificationCodeResponseSchema.ts","../../src/api-verifications/index.browser.ts"],"sourcesContent":["import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\n\nexport const verificationTypeEnumSchema = t.enum([\"code\", \"link\"]);\nexport type VerificationTypeEnum = Static<typeof verificationTypeEnumSchema>;\n","import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\nimport { $entity, pg } from \"alepha/orm\";\nimport { verificationTypeEnumSchema } from \"../schemas/verificationTypeEnumSchema.ts\";\n\nexport const verifications = $entity({\n name: \"verification\",\n schema: t.object({\n id: pg.primaryKey(t.bigint()),\n\n createdAt: pg.createdAt(),\n\n updatedAt: pg.updatedAt(),\n\n version: pg.version(),\n\n type: verificationTypeEnumSchema,\n\n target: t.text({\n description: \"Can be a phone (E.164 format) or email address\",\n }),\n\n code: t.text({\n description: \"Hashed verification token (n-digit code or UUID)\",\n }),\n\n verifiedAt: t.optional(\n t.datetime({\n description: \"When it was successfully verified\",\n }),\n ),\n\n attempts: pg.default(\n t.integer({\n description: \"Number of failed attempts (to prevent brute-force)\",\n }),\n 0,\n ),\n }),\n indexes: [\n \"createdAt\",\n {\n columns: [\"target\", \"code\"],\n },\n ],\n});\n\nexport const verificationEntitySchema = verifications.schema;\nexport const verificationEntityInsertSchema = verifications.insertSchema;\nexport type VerificationEntity = Static<typeof verifications.schema>;\n","import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\n\nexport const requestVerificationCodeResponseSchema = t.object({\n token: t.string({\n description:\n \"The verification token (6-digit code for phone, UUID for email). The caller should send this to the user via their preferred notification method.\",\n }),\n codeExpiration: t.integer({\n description: \"Time in seconds before your verification token expires.\",\n }),\n verificationCooldown: t.integer({\n description:\n \"Cooldown period in seconds before you can request another verification.\",\n }),\n maxVerificationAttempts: t.integer({\n description:\n \"Maximum number of verification attempts allowed before the token is locked.\",\n }),\n});\n\nexport type RequestVerificationResponse = Static<\n typeof requestVerificationCodeResponseSchema\n>;\n","import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\n\nexport const validateVerificationCodeResponseSchema = t.object({\n ok: t.boolean({\n description: \"Indicates whether the verification was successful.\",\n }),\n alreadyVerified: t.optional(\n t.boolean({\n description: \"Indicates whether the target was already verified.\",\n }),\n ),\n});\n\nexport type ValidateVerificationCodeResponse = Static<\n typeof validateVerificationCodeResponseSchema\n>;\n","import { $module } from \"alepha\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./entities/verifications.ts\";\nexport * from \"./schemas/requestVerificationCodeResponseSchema.ts\";\nexport * from \"./schemas/validateVerificationCodeResponseSchema.ts\";\nexport * from \"./schemas/verificationTypeEnumSchema.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport const AlephaApiVerification = $module({\n name: \"alepha.api.verifications\",\n services: [],\n});\n"],"mappings":";;;;AAGA,MAAa,6BAA6B,EAAE,KAAK,CAAC,QAAQ,OAAO,CAAC;;;;ACElE,MAAa,gBAAgB,QAAQ;CACnC,MAAM;CACN,QAAQ,EAAE,OAAO;EACf,IAAI,GAAG,WAAW,EAAE,QAAQ,CAAC;EAE7B,WAAW,GAAG,WAAW;EAEzB,WAAW,GAAG,WAAW;EAEzB,SAAS,GAAG,SAAS;EAErB,MAAM;EAEN,QAAQ,EAAE,KAAK,EACb,aAAa,kDACd,CAAC;EAEF,MAAM,EAAE,KAAK,EACX,aAAa,oDACd,CAAC;EAEF,YAAY,EAAE,SACZ,EAAE,SAAS,EACT,aAAa,qCACd,CAAC,CACH;EAED,UAAU,GAAG,QACX,EAAE,QAAQ,EACR,aAAa,sDACd,CAAC,EACF,EACD;EACF,CAAC;CACF,SAAS,CACP,aACA,EACE,SAAS,CAAC,UAAU,OAAO,EAC5B,CACF;CACF,CAAC;AAEF,MAAa,2BAA2B,cAAc;AACtD,MAAa,iCAAiC,cAAc;;;;AC7C5D,MAAa,wCAAwC,EAAE,OAAO;CAC5D,OAAO,EAAE,OAAO,EACd,aACE,qJACH,CAAC;CACF,gBAAgB,EAAE,QAAQ,EACxB,aAAa,2DACd,CAAC;CACF,sBAAsB,EAAE,QAAQ,EAC9B,aACE,2EACH,CAAC;CACF,yBAAyB,EAAE,QAAQ,EACjC,aACE,+EACH,CAAC;CACH,CAAC;;;;AChBF,MAAa,yCAAyC,EAAE,OAAO;CAC7D,IAAI,EAAE,QAAQ,EACZ,aAAa,sDACd,CAAC;CACF,iBAAiB,EAAE,SACjB,EAAE,QAAQ,EACR,aAAa,sDACd,CAAC,CACH;CACF,CAAC;;;;ACDF,MAAa,wBAAwB,QAAQ;CAC3C,MAAM;CACN,UAAU,EAAE;CACb,CAAC"}
@@ -1,4 +1,4 @@
1
- import * as alepha76 from "alepha";
1
+ import * as alepha52 from "alepha";
2
2
  import { Static } from "alepha";
3
3
  import * as alepha_server0 from "alepha/server";
4
4
  import { DateTimeProvider } from "alepha/datetime";
@@ -6,35 +6,57 @@ import * as alepha_logger0 from "alepha/logger";
6
6
  import * as alepha_orm56 from "alepha/orm";
7
7
 
8
8
  //#region src/api-verifications/entities/verifications.d.ts
9
- declare const verifications: alepha_orm56.EntityPrimitive<alepha76.TObject<{
10
- id: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha76.TString, typeof alepha_orm56.PG_PRIMARY_KEY>, typeof alepha_orm56.PG_DEFAULT>;
11
- createdAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha76.TString, typeof alepha_orm56.PG_CREATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
12
- updatedAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha76.TString, typeof alepha_orm56.PG_UPDATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
13
- version: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha76.TInteger, typeof alepha_orm56.PG_VERSION>, typeof alepha_orm56.PG_DEFAULT>;
14
- type: alepha76.TUnsafe<"link" | "code">;
15
- target: alepha76.TString;
16
- code: alepha76.TString;
17
- verifiedAt: alepha76.TOptional<alepha76.TString>;
18
- attempts: alepha_orm56.PgAttr<alepha76.TInteger, typeof alepha_orm56.PG_DEFAULT>;
9
+ declare const verifications: alepha_orm56.EntityPrimitive<alepha52.TObject<{
10
+ id: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_PRIMARY_KEY>, typeof alepha_orm56.PG_DEFAULT>;
11
+ createdAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_CREATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
12
+ updatedAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_UPDATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
13
+ version: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TInteger, typeof alepha_orm56.PG_VERSION>, typeof alepha_orm56.PG_DEFAULT>;
14
+ type: alepha52.TUnsafe<"code" | "link">;
15
+ target: alepha52.TString;
16
+ code: alepha52.TString;
17
+ verifiedAt: alepha52.TOptional<alepha52.TString>;
18
+ attempts: alepha_orm56.PgAttr<alepha52.TInteger, typeof alepha_orm56.PG_DEFAULT>;
19
+ }>>;
20
+ declare const verificationEntitySchema: alepha52.TObject<{
21
+ id: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_PRIMARY_KEY>, typeof alepha_orm56.PG_DEFAULT>;
22
+ createdAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_CREATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
23
+ updatedAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_UPDATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
24
+ version: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TInteger, typeof alepha_orm56.PG_VERSION>, typeof alepha_orm56.PG_DEFAULT>;
25
+ type: alepha52.TUnsafe<"code" | "link">;
26
+ target: alepha52.TString;
27
+ code: alepha52.TString;
28
+ verifiedAt: alepha52.TOptional<alepha52.TString>;
29
+ attempts: alepha_orm56.PgAttr<alepha52.TInteger, typeof alepha_orm56.PG_DEFAULT>;
30
+ }>;
31
+ declare const verificationEntityInsertSchema: alepha_orm56.TObjectInsert<alepha52.TObject<{
32
+ id: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_PRIMARY_KEY>, typeof alepha_orm56.PG_DEFAULT>;
33
+ createdAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_CREATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
34
+ updatedAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_UPDATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
35
+ version: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TInteger, typeof alepha_orm56.PG_VERSION>, typeof alepha_orm56.PG_DEFAULT>;
36
+ type: alepha52.TUnsafe<"code" | "link">;
37
+ target: alepha52.TString;
38
+ code: alepha52.TString;
39
+ verifiedAt: alepha52.TOptional<alepha52.TString>;
40
+ attempts: alepha_orm56.PgAttr<alepha52.TInteger, typeof alepha_orm56.PG_DEFAULT>;
19
41
  }>>;
20
42
  type VerificationEntity = Static<typeof verifications.schema>;
21
43
  //#endregion
22
44
  //#region src/api-verifications/schemas/verificationSettingsSchema.d.ts
23
- declare const verificationSettingsSchema: alepha76.TObject<{
24
- code: alepha76.TObject<{
25
- maxAttempts: alepha76.TInteger;
26
- codeLength: alepha76.TInteger;
27
- codeExpiration: alepha76.TInteger;
28
- verificationCooldown: alepha76.TInteger;
29
- limitPerDay: alepha76.TInteger;
45
+ declare const verificationSettingsSchema: alepha52.TObject<{
46
+ code: alepha52.TObject<{
47
+ maxAttempts: alepha52.TInteger;
48
+ codeLength: alepha52.TInteger;
49
+ codeExpiration: alepha52.TInteger;
50
+ verificationCooldown: alepha52.TInteger;
51
+ limitPerDay: alepha52.TInteger;
30
52
  }>;
31
- link: alepha76.TObject<{
32
- maxAttempts: alepha76.TInteger;
33
- codeExpiration: alepha76.TInteger;
34
- verificationCooldown: alepha76.TInteger;
35
- limitPerDay: alepha76.TInteger;
53
+ link: alepha52.TObject<{
54
+ maxAttempts: alepha52.TInteger;
55
+ codeExpiration: alepha52.TInteger;
56
+ verificationCooldown: alepha52.TInteger;
57
+ limitPerDay: alepha52.TInteger;
36
58
  }>;
37
- purgeDays: alepha76.TInteger;
59
+ purgeDays: alepha52.TInteger;
38
60
  }>;
39
61
  type VerificationSettings = Static<typeof verificationSettingsSchema>;
40
62
  //#endregion
@@ -42,21 +64,21 @@ type VerificationSettings = Static<typeof verificationSettingsSchema>;
42
64
  /**
43
65
  * Verification settings configuration atom
44
66
  */
45
- declare const verificationOptions: alepha76.Atom<alepha76.TObject<{
46
- code: alepha76.TObject<{
47
- maxAttempts: alepha76.TInteger;
48
- codeLength: alepha76.TInteger;
49
- codeExpiration: alepha76.TInteger;
50
- verificationCooldown: alepha76.TInteger;
51
- limitPerDay: alepha76.TInteger;
67
+ declare const verificationOptions: alepha52.Atom<alepha52.TObject<{
68
+ code: alepha52.TObject<{
69
+ maxAttempts: alepha52.TInteger;
70
+ codeLength: alepha52.TInteger;
71
+ codeExpiration: alepha52.TInteger;
72
+ verificationCooldown: alepha52.TInteger;
73
+ limitPerDay: alepha52.TInteger;
52
74
  }>;
53
- link: alepha76.TObject<{
54
- maxAttempts: alepha76.TInteger;
55
- codeExpiration: alepha76.TInteger;
56
- verificationCooldown: alepha76.TInteger;
57
- limitPerDay: alepha76.TInteger;
75
+ link: alepha52.TObject<{
76
+ maxAttempts: alepha52.TInteger;
77
+ codeExpiration: alepha52.TInteger;
78
+ verificationCooldown: alepha52.TInteger;
79
+ limitPerDay: alepha52.TInteger;
58
80
  }>;
59
- purgeDays: alepha76.TInteger;
81
+ purgeDays: alepha52.TInteger;
60
82
  }>, "alepha.api.verifications.options">;
61
83
  type VerificationOptions = Static<typeof verificationOptions.schema>;
62
84
  declare module "alepha" {
@@ -66,17 +88,17 @@ declare module "alepha" {
66
88
  }
67
89
  declare class VerificationParameters {
68
90
  protected readonly options: Readonly<{
69
- link: {
91
+ code: {
70
92
  codeExpiration: number;
71
93
  verificationCooldown: number;
72
94
  maxAttempts: number;
95
+ codeLength: number;
73
96
  limitPerDay: number;
74
97
  };
75
- code: {
98
+ link: {
76
99
  codeExpiration: number;
77
100
  verificationCooldown: number;
78
101
  maxAttempts: number;
79
- codeLength: number;
80
102
  limitPerDay: number;
81
103
  };
82
104
  purgeDays: number;
@@ -85,23 +107,23 @@ declare class VerificationParameters {
85
107
  }
86
108
  //#endregion
87
109
  //#region src/api-verifications/schemas/requestVerificationCodeResponseSchema.d.ts
88
- declare const requestVerificationCodeResponseSchema: alepha76.TObject<{
89
- token: alepha76.TString;
90
- codeExpiration: alepha76.TInteger;
91
- verificationCooldown: alepha76.TInteger;
92
- maxVerificationAttempts: alepha76.TInteger;
110
+ declare const requestVerificationCodeResponseSchema: alepha52.TObject<{
111
+ token: alepha52.TString;
112
+ codeExpiration: alepha52.TInteger;
113
+ verificationCooldown: alepha52.TInteger;
114
+ maxVerificationAttempts: alepha52.TInteger;
93
115
  }>;
94
116
  type RequestVerificationResponse = Static<typeof requestVerificationCodeResponseSchema>;
95
117
  //#endregion
96
118
  //#region src/api-verifications/schemas/validateVerificationCodeResponseSchema.d.ts
97
- declare const validateVerificationCodeResponseSchema: alepha76.TObject<{
98
- ok: alepha76.TBoolean;
99
- alreadyVerified: alepha76.TOptional<alepha76.TBoolean>;
119
+ declare const validateVerificationCodeResponseSchema: alepha52.TObject<{
120
+ ok: alepha52.TBoolean;
121
+ alreadyVerified: alepha52.TOptional<alepha52.TBoolean>;
100
122
  }>;
101
123
  type ValidateVerificationCodeResponse = Static<typeof validateVerificationCodeResponseSchema>;
102
124
  //#endregion
103
125
  //#region src/api-verifications/schemas/verificationTypeEnumSchema.d.ts
104
- declare const verificationTypeEnumSchema: alepha76.TUnsafe<"link" | "code">;
126
+ declare const verificationTypeEnumSchema: alepha52.TUnsafe<"code" | "link">;
105
127
  type VerificationTypeEnum = Static<typeof verificationTypeEnumSchema>;
106
128
  //#endregion
107
129
  //#region src/api-verifications/services/VerificationService.d.ts
@@ -109,38 +131,38 @@ declare class VerificationService {
109
131
  protected readonly log: alepha_logger0.Logger;
110
132
  protected readonly dateTimeProvider: DateTimeProvider;
111
133
  protected readonly verificationParameters: VerificationParameters;
112
- protected readonly verificationRepository: alepha_orm56.Repository<alepha76.TObject<{
113
- id: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha76.TString, typeof alepha_orm56.PG_PRIMARY_KEY>, typeof alepha_orm56.PG_DEFAULT>;
114
- createdAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha76.TString, typeof alepha_orm56.PG_CREATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
115
- updatedAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha76.TString, typeof alepha_orm56.PG_UPDATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
116
- version: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha76.TInteger, typeof alepha_orm56.PG_VERSION>, typeof alepha_orm56.PG_DEFAULT>;
117
- type: alepha76.TUnsafe<"link" | "code">;
118
- target: alepha76.TString;
119
- code: alepha76.TString;
120
- verifiedAt: alepha76.TOptional<alepha76.TString>;
121
- attempts: alepha_orm56.PgAttr<alepha76.TInteger, typeof alepha_orm56.PG_DEFAULT>;
134
+ protected readonly verificationRepository: alepha_orm56.Repository<alepha52.TObject<{
135
+ id: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_PRIMARY_KEY>, typeof alepha_orm56.PG_DEFAULT>;
136
+ createdAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_CREATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
137
+ updatedAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_UPDATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
138
+ version: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TInteger, typeof alepha_orm56.PG_VERSION>, typeof alepha_orm56.PG_DEFAULT>;
139
+ type: alepha52.TUnsafe<"code" | "link">;
140
+ target: alepha52.TString;
141
+ code: alepha52.TString;
142
+ verifiedAt: alepha52.TOptional<alepha52.TString>;
143
+ attempts: alepha_orm56.PgAttr<alepha52.TInteger, typeof alepha_orm56.PG_DEFAULT>;
122
144
  }>>;
123
145
  findByEntry(entry: VerificationEntry): Promise<VerificationEntity>;
124
- findRecentsByEntry(entry: VerificationEntry): Promise<alepha_orm56.PgStatic<alepha76.TObject<{
125
- id: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha76.TString, typeof alepha_orm56.PG_PRIMARY_KEY>, typeof alepha_orm56.PG_DEFAULT>;
126
- createdAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha76.TString, typeof alepha_orm56.PG_CREATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
127
- updatedAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha76.TString, typeof alepha_orm56.PG_UPDATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
128
- version: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha76.TInteger, typeof alepha_orm56.PG_VERSION>, typeof alepha_orm56.PG_DEFAULT>;
129
- type: alepha76.TUnsafe<"link" | "code">;
130
- target: alepha76.TString;
131
- code: alepha76.TString;
132
- verifiedAt: alepha76.TOptional<alepha76.TString>;
133
- attempts: alepha_orm56.PgAttr<alepha76.TInteger, typeof alepha_orm56.PG_DEFAULT>;
134
- }>, alepha_orm56.PgRelationMap<alepha76.TObject<{
135
- id: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha76.TString, typeof alepha_orm56.PG_PRIMARY_KEY>, typeof alepha_orm56.PG_DEFAULT>;
136
- createdAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha76.TString, typeof alepha_orm56.PG_CREATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
137
- updatedAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha76.TString, typeof alepha_orm56.PG_UPDATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
138
- version: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha76.TInteger, typeof alepha_orm56.PG_VERSION>, typeof alepha_orm56.PG_DEFAULT>;
139
- type: alepha76.TUnsafe<"link" | "code">;
140
- target: alepha76.TString;
141
- code: alepha76.TString;
142
- verifiedAt: alepha76.TOptional<alepha76.TString>;
143
- attempts: alepha_orm56.PgAttr<alepha76.TInteger, typeof alepha_orm56.PG_DEFAULT>;
146
+ findRecentsByEntry(entry: VerificationEntry): Promise<alepha_orm56.PgStatic<alepha52.TObject<{
147
+ id: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_PRIMARY_KEY>, typeof alepha_orm56.PG_DEFAULT>;
148
+ createdAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_CREATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
149
+ updatedAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_UPDATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
150
+ version: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TInteger, typeof alepha_orm56.PG_VERSION>, typeof alepha_orm56.PG_DEFAULT>;
151
+ type: alepha52.TUnsafe<"code" | "link">;
152
+ target: alepha52.TString;
153
+ code: alepha52.TString;
154
+ verifiedAt: alepha52.TOptional<alepha52.TString>;
155
+ attempts: alepha_orm56.PgAttr<alepha52.TInteger, typeof alepha_orm56.PG_DEFAULT>;
156
+ }>, alepha_orm56.PgRelationMap<alepha52.TObject<{
157
+ id: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_PRIMARY_KEY>, typeof alepha_orm56.PG_DEFAULT>;
158
+ createdAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_CREATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
159
+ updatedAt: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TString, typeof alepha_orm56.PG_UPDATED_AT>, typeof alepha_orm56.PG_DEFAULT>;
160
+ version: alepha_orm56.PgAttr<alepha_orm56.PgAttr<alepha52.TInteger, typeof alepha_orm56.PG_VERSION>, typeof alepha_orm56.PG_DEFAULT>;
161
+ type: alepha52.TUnsafe<"code" | "link">;
162
+ target: alepha52.TString;
163
+ code: alepha52.TString;
164
+ verifiedAt: alepha52.TOptional<alepha52.TString>;
165
+ attempts: alepha_orm56.PgAttr<alepha52.TInteger, typeof alepha_orm56.PG_DEFAULT>;
144
166
  }>>>[]>;
145
167
  /**
146
168
  * Creates a verification entry and returns the token.
@@ -163,30 +185,30 @@ declare class VerificationController {
163
185
  readonly url = "/verifications";
164
186
  readonly group = "verifications";
165
187
  readonly requestVerificationCode: alepha_server0.ActionPrimitiveFn<{
166
- params: alepha76.TObject<{
167
- type: alepha76.TUnsafe<"link" | "code">;
188
+ params: alepha52.TObject<{
189
+ type: alepha52.TUnsafe<"code" | "link">;
168
190
  }>;
169
- body: alepha76.TObject<{
170
- target: alepha76.TString;
191
+ body: alepha52.TObject<{
192
+ target: alepha52.TString;
171
193
  }>;
172
- response: alepha76.TObject<{
173
- token: alepha76.TString;
174
- codeExpiration: alepha76.TInteger;
175
- verificationCooldown: alepha76.TInteger;
176
- maxVerificationAttempts: alepha76.TInteger;
194
+ response: alepha52.TObject<{
195
+ token: alepha52.TString;
196
+ codeExpiration: alepha52.TInteger;
197
+ verificationCooldown: alepha52.TInteger;
198
+ maxVerificationAttempts: alepha52.TInteger;
177
199
  }>;
178
200
  }>;
179
201
  readonly validateVerificationCode: alepha_server0.ActionPrimitiveFn<{
180
- params: alepha76.TObject<{
181
- type: alepha76.TUnsafe<"link" | "code">;
202
+ params: alepha52.TObject<{
203
+ type: alepha52.TUnsafe<"code" | "link">;
182
204
  }>;
183
- body: alepha76.TObject<{
184
- target: alepha76.TString;
185
- token: alepha76.TString;
205
+ body: alepha52.TObject<{
206
+ target: alepha52.TString;
207
+ token: alepha52.TString;
186
208
  }>;
187
- response: alepha76.TObject<{
188
- ok: alepha76.TBoolean;
189
- alreadyVerified: alepha76.TOptional<alepha76.TBoolean>;
209
+ response: alepha52.TObject<{
210
+ ok: alepha52.TBoolean;
211
+ alreadyVerified: alepha52.TOptional<alepha52.TBoolean>;
190
212
  }>;
191
213
  }>;
192
214
  }
@@ -201,7 +223,7 @@ declare class VerificationController {
201
223
  *
202
224
  * @module alepha.api.verifications
203
225
  */
204
- declare const AlephaApiVerification: alepha76.Service<alepha76.Module>;
226
+ declare const AlephaApiVerification: alepha52.Service<alepha52.Module>;
205
227
  //#endregion
206
- export { AlephaApiVerification, RequestVerificationResponse, ValidateVerificationCodeResponse, VerificationController, VerificationEntry, VerificationService, VerificationTypeEnum, requestVerificationCodeResponseSchema, validateVerificationCodeResponseSchema, verificationTypeEnumSchema };
228
+ export { AlephaApiVerification, RequestVerificationResponse, ValidateVerificationCodeResponse, VerificationController, VerificationEntity, VerificationEntry, VerificationService, VerificationTypeEnum, requestVerificationCodeResponseSchema, validateVerificationCodeResponseSchema, verificationEntityInsertSchema, verificationEntitySchema, verificationTypeEnumSchema, verifications };
207
229
  //# sourceMappingURL=index.d.ts.map
@@ -398,5 +398,5 @@ const AlephaApiVerification = $module({
398
398
  });
399
399
 
400
400
  //#endregion
401
- export { AlephaApiVerification, VerificationController, VerificationService, requestVerificationCodeResponseSchema, validateVerificationCodeResponseSchema, verificationTypeEnumSchema };
401
+ export { AlephaApiVerification, VerificationController, VerificationService, requestVerificationCodeResponseSchema, validateVerificationCodeResponseSchema, verificationEntityInsertSchema, verificationEntitySchema, verificationTypeEnumSchema, verifications };
402
402
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/api-verifications/schemas/requestVerificationCodeResponseSchema.ts","../../src/api-verifications/schemas/validateVerificationCodeResponseSchema.ts","../../src/api-verifications/schemas/verificationTypeEnumSchema.ts","../../src/api-verifications/entities/verifications.ts","../../src/api-verifications/schemas/verificationSettingsSchema.ts","../../src/api-verifications/parameters/VerificationParameters.ts","../../src/api-verifications/services/VerificationService.ts","../../src/api-verifications/controllers/VerificationController.ts","../../src/api-verifications/jobs/VerificationJobs.ts","../../src/api-verifications/index.ts"],"sourcesContent":["import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\n\nexport const requestVerificationCodeResponseSchema = t.object({\n token: t.string({\n description:\n \"The verification token (6-digit code for phone, UUID for email). The caller should send this to the user via their preferred notification method.\",\n }),\n codeExpiration: t.integer({\n description: \"Time in seconds before your verification token expires.\",\n }),\n verificationCooldown: t.integer({\n description:\n \"Cooldown period in seconds before you can request another verification.\",\n }),\n maxVerificationAttempts: t.integer({\n description:\n \"Maximum number of verification attempts allowed before the token is locked.\",\n }),\n});\n\nexport type RequestVerificationResponse = Static<\n typeof requestVerificationCodeResponseSchema\n>;\n","import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\n\nexport const validateVerificationCodeResponseSchema = t.object({\n ok: t.boolean({\n description: \"Indicates whether the verification was successful.\",\n }),\n alreadyVerified: t.optional(\n t.boolean({\n description: \"Indicates whether the target was already verified.\",\n }),\n ),\n});\n\nexport type ValidateVerificationCodeResponse = Static<\n typeof validateVerificationCodeResponseSchema\n>;\n","import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\n\nexport const verificationTypeEnumSchema = t.enum([\"code\", \"link\"]);\nexport type VerificationTypeEnum = Static<typeof verificationTypeEnumSchema>;\n","import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\nimport { $entity, pg } from \"alepha/orm\";\nimport { verificationTypeEnumSchema } from \"../schemas/verificationTypeEnumSchema.ts\";\n\nexport const verifications = $entity({\n name: \"verification\",\n schema: t.object({\n id: pg.primaryKey(t.bigint()),\n\n createdAt: pg.createdAt(),\n\n updatedAt: pg.updatedAt(),\n\n version: pg.version(),\n\n type: verificationTypeEnumSchema,\n\n target: t.text({\n description: \"Can be a phone (E.164 format) or email address\",\n }),\n\n code: t.text({\n description: \"Hashed verification token (n-digit code or UUID)\",\n }),\n\n verifiedAt: t.optional(\n t.datetime({\n description: \"When it was successfully verified\",\n }),\n ),\n\n attempts: pg.default(\n t.integer({\n description: \"Number of failed attempts (to prevent brute-force)\",\n }),\n 0,\n ),\n }),\n indexes: [\n \"createdAt\",\n {\n columns: [\"target\", \"code\"],\n },\n ],\n});\n\nexport const verificationEntitySchema = verifications.schema;\nexport const verificationEntityInsertSchema = verifications.insertSchema;\nexport type VerificationEntity = Static<typeof verifications.schema>;\n","import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\n\nexport const verificationSettingsSchema = t.object({\n code: t.object(\n {\n maxAttempts: t.integer({\n description:\n \"Maximum number of attempts before locking the verification.\",\n minimum: 1,\n maximum: 10,\n }),\n codeLength: t.integer({\n description: \"Length of the verification code.\",\n minimum: 4,\n maximum: 12,\n }),\n codeExpiration: t.integer({\n description: \"Time in seconds before the verification code expires.\",\n minimum: 60, // 1 minute\n maximum: 3600, // 1 hour\n }),\n verificationCooldown: t.integer({\n description: \"Cooldown period in seconds after a request verification.\",\n minimum: 0,\n maximum: 3600, // 1 hour\n }),\n limitPerDay: t.integer({\n description:\n \"Maximum number of verification requests per day for one entry.\",\n minimum: 1,\n maximum: 100,\n }),\n },\n {\n description: \"Settings specific to code verifications.\",\n },\n ),\n link: t.object(\n {\n maxAttempts: t.integer({\n description:\n \"Maximum number of attempts before locking the verification.\",\n minimum: 1,\n maximum: 10,\n }),\n codeExpiration: t.integer({\n description: \"Time in seconds before the verification token expires.\",\n minimum: 60, // 1 minute\n maximum: 7200, // 2 hours\n }),\n verificationCooldown: t.integer({\n description: \"Cooldown period in seconds after a request verification.\",\n minimum: 0,\n maximum: 3600, // 1 hour\n }),\n limitPerDay: t.integer({\n description:\n \"Maximum number of verification requests per day for one entry.\",\n minimum: 1,\n maximum: 100,\n }),\n },\n {\n description: \"Settings specific to link verifications.\",\n },\n ),\n purgeDays: t.integer({\n description:\n \"Number of days after which expired verifications are automatically deleted. Set to 0 to disable auto-deletion.\",\n minimum: 0,\n maximum: 365,\n }),\n});\n\nexport type VerificationSettings = Static<typeof verificationSettingsSchema>;\n","import { $atom, $use, type Static } from \"alepha\";\nimport {\n type VerificationSettings,\n verificationSettingsSchema,\n} from \"../schemas/verificationSettingsSchema.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Verification settings configuration atom\n */\nexport const verificationOptions = $atom({\n name: \"alepha.api.verifications.options\",\n schema: verificationSettingsSchema,\n default: {\n code: {\n maxAttempts: 5,\n codeLength: 6,\n codeExpiration: 300, // 5 minutes\n verificationCooldown: 90,\n limitPerDay: 10,\n },\n link: {\n maxAttempts: 3, // Lower since UUIDs are harder to guess\n codeExpiration: 1800, // 30 minutes\n verificationCooldown: 90,\n limitPerDay: 10,\n },\n purgeDays: 1,\n },\n});\n\nexport type VerificationOptions = Static<typeof verificationOptions.schema>;\n\ndeclare module \"alepha\" {\n interface State {\n [verificationOptions.key]: VerificationOptions;\n }\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport class VerificationParameters {\n protected readonly options = $use(verificationOptions);\n\n public get<K extends keyof VerificationSettings>(\n key: K,\n ): VerificationSettings[K] {\n return this.options[key];\n }\n}\n","import { createHash, randomInt, randomUUID } from \"node:crypto\";\nimport { $inject } from \"alepha\";\nimport { DateTimeProvider } from \"alepha/datetime\";\nimport { $logger } from \"alepha/logger\";\nimport { $repository } from \"alepha/orm\";\nimport { BadRequestError, NotFoundError } from \"alepha/server\";\nimport {\n type VerificationEntity,\n verifications,\n} from \"../entities/verifications.ts\";\nimport { VerificationParameters } from \"../parameters/VerificationParameters.ts\";\nimport type { RequestVerificationResponse } from \"../schemas/requestVerificationCodeResponseSchema.ts\";\nimport type { ValidateVerificationCodeResponse } from \"../schemas/validateVerificationCodeResponseSchema.ts\";\nimport type { VerificationTypeEnum } from \"../schemas/verificationTypeEnumSchema.ts\";\n\nexport class VerificationService {\n protected readonly log = $logger();\n protected readonly dateTimeProvider = $inject(DateTimeProvider);\n protected readonly verificationParameters = $inject(VerificationParameters);\n protected readonly verificationRepository = $repository(verifications);\n\n public async findByEntry(\n entry: VerificationEntry,\n ): Promise<VerificationEntity> {\n this.log.trace(\"Finding verification by entry\", {\n type: entry.type,\n target: entry.target,\n });\n\n const results = await this.verificationRepository.findMany({\n limit: 1, // only need the most recent entry\n orderBy: {\n column: \"createdAt\",\n direction: \"desc\",\n },\n where: {\n type: { eq: entry.type },\n target: { eq: entry.target },\n },\n });\n\n if (results.length === 0) {\n this.log.debug(\"Verification entry not found\", {\n type: entry.type,\n target: entry.target,\n });\n throw new NotFoundError(\"Verification entry not found\");\n }\n\n this.log.debug(\"Verification entry found\", {\n id: results[0].id,\n type: entry.type,\n target: entry.target,\n });\n\n return results[0];\n }\n\n public findRecentsByEntry(entry: VerificationEntry) {\n this.log.trace(\"Finding recent verifications by entry\", {\n type: entry.type,\n target: entry.target,\n });\n\n return this.verificationRepository.findMany({\n orderBy: {\n column: \"createdAt\",\n direction: \"desc\",\n },\n where: {\n type: { eq: entry.type },\n target: { eq: entry.target },\n createdAt: {\n gte: this.dateTimeProvider.now().startOf(\"day\").toISOString(),\n },\n },\n });\n }\n\n /**\n * Creates a verification entry and returns the token.\n * The caller is responsible for sending notifications with the token.\n * This allows for context-specific notifications (e.g., password reset vs email verification).\n */\n public async createVerification(\n entry: VerificationEntry,\n ): Promise<RequestVerificationResponse> {\n this.log.trace(\"Creating verification\", {\n type: entry.type,\n target: entry.target,\n });\n\n const settings = this.verificationParameters.get(entry.type);\n\n const recents = await this.findRecentsByEntry(entry);\n if (recents.length >= settings.limitPerDay) {\n this.log.warn(\"Daily verification limit reached\", {\n type: entry.type,\n target: entry.target,\n limit: settings.limitPerDay,\n count: recents.length,\n });\n throw new BadRequestError(\n `Maximum number of verification requests per day reached (${settings.limitPerDay})`,\n );\n }\n\n const existingVerification = recents[0];\n if (existingVerification) {\n const nowSec = this.dateTimeProvider.now().unix();\n const createdAtSec = this.dateTimeProvider\n .of(existingVerification.createdAt)\n .unix();\n\n const diffSec = nowSec - createdAtSec;\n if (diffSec < settings.verificationCooldown) {\n const remainingCooldown = Math.floor(\n settings.verificationCooldown - diffSec,\n );\n this.log.debug(\"Verification on cooldown\", {\n type: entry.type,\n target: entry.target,\n remainingSeconds: remainingCooldown,\n });\n throw new BadRequestError(\n `Verification is on cooldown for ${remainingCooldown} seconds`,\n );\n }\n }\n\n const token = this.generateToken(entry.type);\n\n const verification = await this.verificationRepository.create({\n type: entry.type,\n target: entry.target,\n code: this.hashCode(token),\n });\n\n this.log.info(\"Verification created\", {\n id: verification.id,\n type: entry.type,\n target: entry.target,\n expiresInSeconds: settings.codeExpiration,\n });\n\n return {\n token,\n codeExpiration: settings.codeExpiration,\n verificationCooldown: settings.verificationCooldown,\n maxVerificationAttempts: settings.maxAttempts,\n };\n }\n\n public async verifyCode(\n entry: VerificationEntry,\n code: string,\n ): Promise<ValidateVerificationCodeResponse> {\n this.log.trace(\"Verifying code\", {\n type: entry.type,\n target: entry.target,\n });\n\n const settings = this.verificationParameters.get(entry.type);\n\n const verification = await this.findByEntry(entry);\n if (verification.verifiedAt) {\n this.log.debug(\"Verification already verified\", {\n id: verification.id,\n type: entry.type,\n target: entry.target,\n verifiedAt: verification.verifiedAt,\n });\n return { ok: true, alreadyVerified: true };\n }\n\n // DO NOT DELETE THE VERIFICATION WHEN IT IS REJECTED,\n // or we won't be able to cooldown the verification\n\n const now = this.dateTimeProvider.now();\n const expirationDate = this.dateTimeProvider\n .of(verification.createdAt)\n .add(settings.codeExpiration, \"seconds\");\n\n if (now > expirationDate) {\n this.log.warn(\"Verification code expired\", {\n id: verification.id,\n type: entry.type,\n target: entry.target,\n createdAt: verification.createdAt,\n expiredAt: expirationDate.toISOString(),\n });\n throw new BadRequestError(\"Verification code has expired\");\n }\n\n if (verification.attempts >= settings.maxAttempts) {\n this.log.warn(\"Verification locked due to max attempts\", {\n id: verification.id,\n type: entry.type,\n target: entry.target,\n attempts: verification.attempts,\n maxAttempts: settings.maxAttempts,\n });\n throw new BadRequestError(\n \"Maximum number of attempts reached - verification is locked\",\n );\n }\n\n if (verification.code !== this.hashCode(code)) {\n const newAttempts = verification.attempts + 1;\n this.log.warn(\"Invalid verification code\", {\n id: verification.id,\n type: entry.type,\n target: entry.target,\n attempts: newAttempts,\n maxAttempts: settings.maxAttempts,\n });\n await this.verificationRepository.updateById(verification.id, {\n attempts: newAttempts,\n });\n throw new BadRequestError(\"Invalid verification code\");\n }\n\n await this.verificationRepository.updateById(verification.id, {\n verifiedAt: this.dateTimeProvider.nowISOString(),\n });\n\n this.log.info(\"Verification code verified\", {\n id: verification.id,\n type: entry.type,\n target: entry.target,\n });\n\n return { ok: true };\n }\n\n public hashCode(code: string): string {\n return createHash(\"sha256\").update(code).digest(\"hex\");\n }\n\n public generateToken(type: VerificationTypeEnum): string {\n if (type === \"code\") {\n const settings = this.verificationParameters.get(\"code\");\n return randomInt(0, 1_000_000)\n .toString()\n .padStart(settings.codeLength, \"0\");\n } else if (type === \"link\") {\n return randomUUID();\n }\n\n throw new BadRequestError(`Invalid verification type: ${type}`);\n }\n}\n\nexport interface VerificationEntry {\n type: VerificationTypeEnum;\n target: string;\n}\n","import { $inject, t } from \"alepha\";\nimport { $action } from \"alepha/server\";\nimport { requestVerificationCodeResponseSchema } from \"../schemas/requestVerificationCodeResponseSchema.ts\";\nimport { validateVerificationCodeResponseSchema } from \"../schemas/validateVerificationCodeResponseSchema.ts\";\nimport { verificationTypeEnumSchema } from \"../schemas/verificationTypeEnumSchema.ts\";\nimport { VerificationService } from \"../services/VerificationService.ts\";\n\nexport class VerificationController {\n protected readonly verificationService = $inject(VerificationService);\n\n public readonly url = \"/verifications\";\n public readonly group = \"verifications\";\n\n public readonly requestVerificationCode = $action({\n path: `${this.url}/:type`,\n group: this.group,\n method: \"POST\",\n schema: {\n params: t.object({\n type: verificationTypeEnumSchema,\n }),\n body: t.object({\n target: t.text(),\n }),\n response: requestVerificationCodeResponseSchema,\n },\n handler: async ({ body, params }) => {\n return await this.verificationService.createVerification({\n type: params.type,\n target: body.target,\n });\n },\n });\n\n public readonly validateVerificationCode = $action({\n path: `${this.url}/:type/validate`,\n group: this.group,\n method: \"POST\",\n schema: {\n params: t.object({\n type: verificationTypeEnumSchema,\n }),\n body: t.object({\n target: t.text(),\n token: t.text({\n description:\n \"The verification token (6-digit code for phone, UUID for email).\",\n }),\n }),\n response: validateVerificationCodeResponseSchema,\n },\n handler: async ({ body, params }) => {\n return this.verificationService.verifyCode(\n {\n type: params.type,\n target: body.target,\n },\n body.token,\n );\n },\n });\n}\n","import { $inject } from \"alepha\";\nimport { DateTimeProvider } from \"alepha/datetime\";\nimport { $repository } from \"alepha/orm\";\nimport { $scheduler } from \"alepha/scheduler\";\nimport { verifications } from \"../entities/verifications.ts\";\nimport { VerificationParameters } from \"../parameters/VerificationParameters.ts\";\n\nexport class VerificationJobs {\n protected readonly verificationRepository = $repository(verifications);\n protected readonly verificationParameters = $inject(VerificationParameters);\n protected readonly dateTimeProvider = $inject(DateTimeProvider);\n\n public readonly cleanExpired = $scheduler({\n cron: \"0 0 * * *\", // Every day at midnight\n description: \"Clean expired verifications\",\n handler: async () => {\n const purgeDays = this.verificationParameters.get(\"purgeDays\");\n if (purgeDays <= 0) {\n return; // Auto deletion is disabled\n }\n\n const dayMs = 24 * 60 * 60 * 1000;\n const purgeThreshold = Date.now() - purgeDays * dayMs;\n\n await this.verificationRepository.deleteMany({\n createdAt: {\n lt: this.dateTimeProvider.of(purgeThreshold).toISOString(),\n },\n });\n },\n });\n}\n","import { $module } from \"alepha\";\nimport { VerificationController } from \"./controllers/VerificationController.ts\";\nimport { VerificationJobs } from \"./jobs/VerificationJobs.ts\";\nimport { VerificationService } from \"./services/VerificationService.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./controllers/VerificationController.ts\";\nexport * from \"./schemas/requestVerificationCodeResponseSchema.ts\";\nexport * from \"./schemas/validateVerificationCodeResponseSchema.ts\";\nexport * from \"./schemas/verificationTypeEnumSchema.ts\";\nexport * from \"./services/VerificationService.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Provides email/phone verification management API endpoints for Alepha applications.\n *\n * This module includes verification code generation, validation,\n * and related functionalities. Notifications are handled by the consuming module\n * (e.g., api-users) for context-specific messaging.\n *\n * @module alepha.api.verifications\n */\nexport const AlephaApiVerification = $module({\n name: \"alepha.api.verifications\",\n services: [VerificationController, VerificationJobs, VerificationService],\n});\n"],"mappings":";;;;;;;;;AAGA,MAAa,wCAAwC,EAAE,OAAO;CAC5D,OAAO,EAAE,OAAO,EACd,aACE,qJACH,CAAC;CACF,gBAAgB,EAAE,QAAQ,EACxB,aAAa,2DACd,CAAC;CACF,sBAAsB,EAAE,QAAQ,EAC9B,aACE,2EACH,CAAC;CACF,yBAAyB,EAAE,QAAQ,EACjC,aACE,+EACH,CAAC;CACH,CAAC;;;;AChBF,MAAa,yCAAyC,EAAE,OAAO;CAC7D,IAAI,EAAE,QAAQ,EACZ,aAAa,sDACd,CAAC;CACF,iBAAiB,EAAE,SACjB,EAAE,QAAQ,EACR,aAAa,sDACd,CAAC,CACH;CACF,CAAC;;;;ACTF,MAAa,6BAA6B,EAAE,KAAK,CAAC,QAAQ,OAAO,CAAC;;;;ACElE,MAAa,gBAAgB,QAAQ;CACnC,MAAM;CACN,QAAQ,EAAE,OAAO;EACf,IAAI,GAAG,WAAW,EAAE,QAAQ,CAAC;EAE7B,WAAW,GAAG,WAAW;EAEzB,WAAW,GAAG,WAAW;EAEzB,SAAS,GAAG,SAAS;EAErB,MAAM;EAEN,QAAQ,EAAE,KAAK,EACb,aAAa,kDACd,CAAC;EAEF,MAAM,EAAE,KAAK,EACX,aAAa,oDACd,CAAC;EAEF,YAAY,EAAE,SACZ,EAAE,SAAS,EACT,aAAa,qCACd,CAAC,CACH;EAED,UAAU,GAAG,QACX,EAAE,QAAQ,EACR,aAAa,sDACd,CAAC,EACF,EACD;EACF,CAAC;CACF,SAAS,CACP,aACA,EACE,SAAS,CAAC,UAAU,OAAO,EAC5B,CACF;CACF,CAAC;AAEF,MAAa,2BAA2B,cAAc;AACtD,MAAa,iCAAiC,cAAc;;;;AC7C5D,MAAa,6BAA6B,EAAE,OAAO;CACjD,MAAM,EAAE,OACN;EACE,aAAa,EAAE,QAAQ;GACrB,aACE;GACF,SAAS;GACT,SAAS;G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mBAAmB,QAAQ,iBAAiB;CAE/D,AAAgB,eAAe,WAAW;EACxC,MAAM;EACN,aAAa;EACb,SAAS,YAAY;GACnB,MAAM,YAAY,KAAK,uBAAuB,IAAI,YAAY;AAC9D,OAAI,aAAa,EACf;GAIF,MAAM,iBAAiB,KAAK,KAAK,GAAG,aADtB,OAAU,KAAK;AAG7B,SAAM,KAAK,uBAAuB,WAAW,EAC3C,WAAW,EACT,IAAI,KAAK,iBAAiB,GAAG,eAAe,CAAC,aAAa,EAC3D,EACF,CAAC;;EAEL,CAAC;;;;;;;;;;;;;;ACNJ,MAAa,wBAAwB,QAAQ;CAC3C,MAAM;CACN,UAAU;EAAC;EAAwB;EAAkB;EAAoB;CAC1E,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/api-verifications/schemas/requestVerificationCodeResponseSchema.ts","../../src/api-verifications/schemas/validateVerificationCodeResponseSchema.ts","../../src/api-verifications/schemas/verificationTypeEnumSchema.ts","../../src/api-verifications/entities/verifications.ts","../../src/api-verifications/schemas/verificationSettingsSchema.ts","../../src/api-verifications/parameters/VerificationParameters.ts","../../src/api-verifications/services/VerificationService.ts","../../src/api-verifications/controllers/VerificationController.ts","../../src/api-verifications/jobs/VerificationJobs.ts","../../src/api-verifications/index.ts"],"sourcesContent":["import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\n\nexport const requestVerificationCodeResponseSchema = t.object({\n token: t.string({\n description:\n \"The verification token (6-digit code for phone, UUID for email). The caller should send this to the user via their preferred notification method.\",\n }),\n codeExpiration: t.integer({\n description: \"Time in seconds before your verification token expires.\",\n }),\n verificationCooldown: t.integer({\n description:\n \"Cooldown period in seconds before you can request another verification.\",\n }),\n maxVerificationAttempts: t.integer({\n description:\n \"Maximum number of verification attempts allowed before the token is locked.\",\n }),\n});\n\nexport type RequestVerificationResponse = Static<\n typeof requestVerificationCodeResponseSchema\n>;\n","import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\n\nexport const validateVerificationCodeResponseSchema = t.object({\n ok: t.boolean({\n description: \"Indicates whether the verification was successful.\",\n }),\n alreadyVerified: t.optional(\n t.boolean({\n description: \"Indicates whether the target was already verified.\",\n }),\n ),\n});\n\nexport type ValidateVerificationCodeResponse = Static<\n typeof validateVerificationCodeResponseSchema\n>;\n","import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\n\nexport const verificationTypeEnumSchema = t.enum([\"code\", \"link\"]);\nexport type VerificationTypeEnum = Static<typeof verificationTypeEnumSchema>;\n","import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\nimport { $entity, pg } from \"alepha/orm\";\nimport { verificationTypeEnumSchema } from \"../schemas/verificationTypeEnumSchema.ts\";\n\nexport const verifications = $entity({\n name: \"verification\",\n schema: t.object({\n id: pg.primaryKey(t.bigint()),\n\n createdAt: pg.createdAt(),\n\n updatedAt: pg.updatedAt(),\n\n version: pg.version(),\n\n type: verificationTypeEnumSchema,\n\n target: t.text({\n description: \"Can be a phone (E.164 format) or email address\",\n }),\n\n code: t.text({\n description: \"Hashed verification token (n-digit code or UUID)\",\n }),\n\n verifiedAt: t.optional(\n t.datetime({\n description: \"When it was successfully verified\",\n }),\n ),\n\n attempts: pg.default(\n t.integer({\n description: \"Number of failed attempts (to prevent brute-force)\",\n }),\n 0,\n ),\n }),\n indexes: [\n \"createdAt\",\n {\n columns: [\"target\", \"code\"],\n },\n ],\n});\n\nexport const verificationEntitySchema = verifications.schema;\nexport const verificationEntityInsertSchema = verifications.insertSchema;\nexport type VerificationEntity = Static<typeof verifications.schema>;\n","import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\n\nexport const verificationSettingsSchema = t.object({\n code: t.object(\n {\n maxAttempts: t.integer({\n description:\n \"Maximum number of attempts before locking the verification.\",\n minimum: 1,\n maximum: 10,\n }),\n codeLength: t.integer({\n description: \"Length of the verification code.\",\n minimum: 4,\n maximum: 12,\n }),\n codeExpiration: t.integer({\n description: \"Time in seconds before the verification code expires.\",\n minimum: 60, // 1 minute\n maximum: 3600, // 1 hour\n }),\n verificationCooldown: t.integer({\n description: \"Cooldown period in seconds after a request verification.\",\n minimum: 0,\n maximum: 3600, // 1 hour\n }),\n limitPerDay: t.integer({\n description:\n \"Maximum number of verification requests per day for one entry.\",\n minimum: 1,\n maximum: 100,\n }),\n },\n {\n description: \"Settings specific to code verifications.\",\n },\n ),\n link: t.object(\n {\n maxAttempts: t.integer({\n description:\n \"Maximum number of attempts before locking the verification.\",\n minimum: 1,\n maximum: 10,\n }),\n codeExpiration: t.integer({\n description: \"Time in seconds before the verification token expires.\",\n minimum: 60, // 1 minute\n maximum: 7200, // 2 hours\n }),\n verificationCooldown: t.integer({\n description: \"Cooldown period in seconds after a request verification.\",\n minimum: 0,\n maximum: 3600, // 1 hour\n }),\n limitPerDay: t.integer({\n description:\n \"Maximum number of verification requests per day for one entry.\",\n minimum: 1,\n maximum: 100,\n }),\n },\n {\n description: \"Settings specific to link verifications.\",\n },\n ),\n purgeDays: t.integer({\n description:\n \"Number of days after which expired verifications are automatically deleted. Set to 0 to disable auto-deletion.\",\n minimum: 0,\n maximum: 365,\n }),\n});\n\nexport type VerificationSettings = Static<typeof verificationSettingsSchema>;\n","import { $atom, $use, type Static } from \"alepha\";\nimport {\n type VerificationSettings,\n verificationSettingsSchema,\n} from \"../schemas/verificationSettingsSchema.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Verification settings configuration atom\n */\nexport const verificationOptions = $atom({\n name: \"alepha.api.verifications.options\",\n schema: verificationSettingsSchema,\n default: {\n code: {\n maxAttempts: 5,\n codeLength: 6,\n codeExpiration: 300, // 5 minutes\n verificationCooldown: 90,\n limitPerDay: 10,\n },\n link: {\n maxAttempts: 3, // Lower since UUIDs are harder to guess\n codeExpiration: 1800, // 30 minutes\n verificationCooldown: 90,\n limitPerDay: 10,\n },\n purgeDays: 1,\n },\n});\n\nexport type VerificationOptions = Static<typeof verificationOptions.schema>;\n\ndeclare module \"alepha\" {\n interface State {\n [verificationOptions.key]: VerificationOptions;\n }\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport class VerificationParameters {\n protected readonly options = $use(verificationOptions);\n\n public get<K extends keyof VerificationSettings>(\n key: K,\n ): VerificationSettings[K] {\n return this.options[key];\n }\n}\n","import { createHash, randomInt, randomUUID } from \"node:crypto\";\nimport { $inject } from \"alepha\";\nimport { DateTimeProvider } from \"alepha/datetime\";\nimport { $logger } from \"alepha/logger\";\nimport { $repository } from \"alepha/orm\";\nimport { BadRequestError, NotFoundError } from \"alepha/server\";\nimport {\n type VerificationEntity,\n verifications,\n} from \"../entities/verifications.ts\";\nimport { VerificationParameters } from \"../parameters/VerificationParameters.ts\";\nimport type { RequestVerificationResponse } from \"../schemas/requestVerificationCodeResponseSchema.ts\";\nimport type { ValidateVerificationCodeResponse } from \"../schemas/validateVerificationCodeResponseSchema.ts\";\nimport type { VerificationTypeEnum } from \"../schemas/verificationTypeEnumSchema.ts\";\n\nexport class VerificationService {\n protected readonly log = $logger();\n protected readonly dateTimeProvider = $inject(DateTimeProvider);\n protected readonly verificationParameters = $inject(VerificationParameters);\n protected readonly verificationRepository = $repository(verifications);\n\n public async findByEntry(\n entry: VerificationEntry,\n ): Promise<VerificationEntity> {\n this.log.trace(\"Finding verification by entry\", {\n type: entry.type,\n target: entry.target,\n });\n\n const results = await this.verificationRepository.findMany({\n limit: 1, // only need the most recent entry\n orderBy: {\n column: \"createdAt\",\n direction: \"desc\",\n },\n where: {\n type: { eq: entry.type },\n target: { eq: entry.target },\n },\n });\n\n if (results.length === 0) {\n this.log.debug(\"Verification entry not found\", {\n type: entry.type,\n target: entry.target,\n });\n throw new NotFoundError(\"Verification entry not found\");\n }\n\n this.log.debug(\"Verification entry found\", {\n id: results[0].id,\n type: entry.type,\n target: entry.target,\n });\n\n return results[0];\n }\n\n public findRecentsByEntry(entry: VerificationEntry) {\n this.log.trace(\"Finding recent verifications by entry\", {\n type: entry.type,\n target: entry.target,\n });\n\n return this.verificationRepository.findMany({\n orderBy: {\n column: \"createdAt\",\n direction: \"desc\",\n },\n where: {\n type: { eq: entry.type },\n target: { eq: entry.target },\n createdAt: {\n gte: this.dateTimeProvider.now().startOf(\"day\").toISOString(),\n },\n },\n });\n }\n\n /**\n * Creates a verification entry and returns the token.\n * The caller is responsible for sending notifications with the token.\n * This allows for context-specific notifications (e.g., password reset vs email verification).\n */\n public async createVerification(\n entry: VerificationEntry,\n ): Promise<RequestVerificationResponse> {\n this.log.trace(\"Creating verification\", {\n type: entry.type,\n target: entry.target,\n });\n\n const settings = this.verificationParameters.get(entry.type);\n\n const recents = await this.findRecentsByEntry(entry);\n if (recents.length >= settings.limitPerDay) {\n this.log.warn(\"Daily verification limit reached\", {\n type: entry.type,\n target: entry.target,\n limit: settings.limitPerDay,\n count: recents.length,\n });\n throw new BadRequestError(\n `Maximum number of verification requests per day reached (${settings.limitPerDay})`,\n );\n }\n\n const existingVerification = recents[0];\n if (existingVerification) {\n const nowSec = this.dateTimeProvider.now().unix();\n const createdAtSec = this.dateTimeProvider\n .of(existingVerification.createdAt)\n .unix();\n\n const diffSec = nowSec - createdAtSec;\n if (diffSec < settings.verificationCooldown) {\n const remainingCooldown = Math.floor(\n settings.verificationCooldown - diffSec,\n );\n this.log.debug(\"Verification on cooldown\", {\n type: entry.type,\n target: entry.target,\n remainingSeconds: remainingCooldown,\n });\n throw new BadRequestError(\n `Verification is on cooldown for ${remainingCooldown} seconds`,\n );\n }\n }\n\n const token = this.generateToken(entry.type);\n\n const verification = await this.verificationRepository.create({\n type: entry.type,\n target: entry.target,\n code: this.hashCode(token),\n });\n\n this.log.info(\"Verification created\", {\n id: verification.id,\n type: entry.type,\n target: entry.target,\n expiresInSeconds: settings.codeExpiration,\n });\n\n return {\n token,\n codeExpiration: settings.codeExpiration,\n verificationCooldown: settings.verificationCooldown,\n maxVerificationAttempts: settings.maxAttempts,\n };\n }\n\n public async verifyCode(\n entry: VerificationEntry,\n code: string,\n ): Promise<ValidateVerificationCodeResponse> {\n this.log.trace(\"Verifying code\", {\n type: entry.type,\n target: entry.target,\n });\n\n const settings = this.verificationParameters.get(entry.type);\n\n const verification = await this.findByEntry(entry);\n if (verification.verifiedAt) {\n this.log.debug(\"Verification already verified\", {\n id: verification.id,\n type: entry.type,\n target: entry.target,\n verifiedAt: verification.verifiedAt,\n });\n return { ok: true, alreadyVerified: true };\n }\n\n // DO NOT DELETE THE VERIFICATION WHEN IT IS REJECTED,\n // or we won't be able to cooldown the verification\n\n const now = this.dateTimeProvider.now();\n const expirationDate = this.dateTimeProvider\n .of(verification.createdAt)\n .add(settings.codeExpiration, \"seconds\");\n\n if (now > expirationDate) {\n this.log.warn(\"Verification code expired\", {\n id: verification.id,\n type: entry.type,\n target: entry.target,\n createdAt: verification.createdAt,\n expiredAt: expirationDate.toISOString(),\n });\n throw new BadRequestError(\"Verification code has expired\");\n }\n\n if (verification.attempts >= settings.maxAttempts) {\n this.log.warn(\"Verification locked due to max attempts\", {\n id: verification.id,\n type: entry.type,\n target: entry.target,\n attempts: verification.attempts,\n maxAttempts: settings.maxAttempts,\n });\n throw new BadRequestError(\n \"Maximum number of attempts reached - verification is locked\",\n );\n }\n\n if (verification.code !== this.hashCode(code)) {\n const newAttempts = verification.attempts + 1;\n this.log.warn(\"Invalid verification code\", {\n id: verification.id,\n type: entry.type,\n target: entry.target,\n attempts: newAttempts,\n maxAttempts: settings.maxAttempts,\n });\n await this.verificationRepository.updateById(verification.id, {\n attempts: newAttempts,\n });\n throw new BadRequestError(\"Invalid verification code\");\n }\n\n await this.verificationRepository.updateById(verification.id, {\n verifiedAt: this.dateTimeProvider.nowISOString(),\n });\n\n this.log.info(\"Verification code verified\", {\n id: verification.id,\n type: entry.type,\n target: entry.target,\n });\n\n return { ok: true };\n }\n\n public hashCode(code: string): string {\n return createHash(\"sha256\").update(code).digest(\"hex\");\n }\n\n public generateToken(type: VerificationTypeEnum): string {\n if (type === \"code\") {\n const settings = this.verificationParameters.get(\"code\");\n return randomInt(0, 1_000_000)\n .toString()\n .padStart(settings.codeLength, \"0\");\n } else if (type === \"link\") {\n return randomUUID();\n }\n\n throw new BadRequestError(`Invalid verification type: ${type}`);\n }\n}\n\nexport interface VerificationEntry {\n type: VerificationTypeEnum;\n target: string;\n}\n","import { $inject, t } from \"alepha\";\nimport { $action } from \"alepha/server\";\nimport { requestVerificationCodeResponseSchema } from \"../schemas/requestVerificationCodeResponseSchema.ts\";\nimport { validateVerificationCodeResponseSchema } from \"../schemas/validateVerificationCodeResponseSchema.ts\";\nimport { verificationTypeEnumSchema } from \"../schemas/verificationTypeEnumSchema.ts\";\nimport { VerificationService } from \"../services/VerificationService.ts\";\n\nexport class VerificationController {\n protected readonly verificationService = $inject(VerificationService);\n\n public readonly url = \"/verifications\";\n public readonly group = \"verifications\";\n\n public readonly requestVerificationCode = $action({\n path: `${this.url}/:type`,\n group: this.group,\n method: \"POST\",\n schema: {\n params: t.object({\n type: verificationTypeEnumSchema,\n }),\n body: t.object({\n target: t.text(),\n }),\n response: requestVerificationCodeResponseSchema,\n },\n handler: async ({ body, params }) => {\n return await this.verificationService.createVerification({\n type: params.type,\n target: body.target,\n });\n },\n });\n\n public readonly validateVerificationCode = $action({\n path: `${this.url}/:type/validate`,\n group: this.group,\n method: \"POST\",\n schema: {\n params: t.object({\n type: verificationTypeEnumSchema,\n }),\n body: t.object({\n target: t.text(),\n token: t.text({\n description:\n \"The verification token (6-digit code for phone, UUID for email).\",\n }),\n }),\n response: validateVerificationCodeResponseSchema,\n },\n handler: async ({ body, params }) => {\n return this.verificationService.verifyCode(\n {\n type: params.type,\n target: body.target,\n },\n body.token,\n );\n },\n });\n}\n","import { $inject } from \"alepha\";\nimport { DateTimeProvider } from \"alepha/datetime\";\nimport { $repository } from \"alepha/orm\";\nimport { $scheduler } from \"alepha/scheduler\";\nimport { verifications } from \"../entities/verifications.ts\";\nimport { VerificationParameters } from \"../parameters/VerificationParameters.ts\";\n\nexport class VerificationJobs {\n protected readonly verificationRepository = $repository(verifications);\n protected readonly verificationParameters = $inject(VerificationParameters);\n protected readonly dateTimeProvider = $inject(DateTimeProvider);\n\n public readonly cleanExpired = $scheduler({\n cron: \"0 0 * * *\", // Every day at midnight\n description: \"Clean expired verifications\",\n handler: async () => {\n const purgeDays = this.verificationParameters.get(\"purgeDays\");\n if (purgeDays <= 0) {\n return; // Auto deletion is disabled\n }\n\n const dayMs = 24 * 60 * 60 * 1000;\n const purgeThreshold = Date.now() - purgeDays * dayMs;\n\n await this.verificationRepository.deleteMany({\n createdAt: {\n lt: this.dateTimeProvider.of(purgeThreshold).toISOString(),\n },\n });\n },\n });\n}\n","import { $module } from \"alepha\";\nimport { VerificationController } from \"./controllers/VerificationController.ts\";\nimport { VerificationJobs } from \"./jobs/VerificationJobs.ts\";\nimport { VerificationService } from \"./services/VerificationService.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./controllers/VerificationController.ts\";\nexport * from \"./entities/verifications.ts\";\nexport * from \"./schemas/requestVerificationCodeResponseSchema.ts\";\nexport * from \"./schemas/validateVerificationCodeResponseSchema.ts\";\nexport * from \"./schemas/verificationTypeEnumSchema.ts\";\nexport * from \"./services/VerificationService.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Provides email/phone verification management API endpoints for Alepha applications.\n *\n * This module includes verification code generation, validation,\n * and related functionalities. Notifications are handled by the consuming module\n * (e.g., api-users) for context-specific messaging.\n *\n * @module alepha.api.verifications\n */\nexport const AlephaApiVerification = $module({\n name: \"alepha.api.verifications\",\n services: [VerificationController, VerificationJobs, VerificationService],\n});\n"],"mappings":";;;;;;;;;AAGA,MAAa,wCAAwC,EAAE,OAAO;CAC5D,OAAO,EAAE,OAAO,EACd,aACE,qJACH,CAAC;CACF,gBAAgB,EAAE,QAAQ,EACxB,aAAa,2DACd,CAAC;CACF,sBAAsB,EAAE,QAAQ,EAC9B,aACE,2EACH,CAAC;CACF,yBAAyB,EAAE,QAAQ,EACjC,aACE,+EACH,CAAC;CACH,CAAC;;;;AChBF,M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AC;;;;;;;;;;;;;;ACLJ,MAAa,wBAAwB,QAAQ;CAC3C,MAAM;CACN,UAAU;EAAC;EAAwB;EAAkB;EAAoB;CAC1E,CAAC"}
@@ -67,11 +67,6 @@ var BatchProvider = class {
67
67
  partitionKey,
68
68
  status: "pending"
69
69
  };
70
- this.log.trace("Pushing item to batch", {
71
- id,
72
- partitionKey,
73
- item
74
- });
75
70
  context.itemStates.set(id, itemState);
76
71
  if (!context.partitions.has(partitionKey)) context.partitions.set(partitionKey, {
77
72
  itemIds: [],