@warlock.js/auth 5.11.0 → 5.13.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 (185) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +88 -86
  3. package/esm/commands/auth-cleanup-command.mjs +1 -1
  4. package/esm/commands/auth-cleanup-command.mjs.map +1 -1
  5. package/esm/contracts/index.d.mts +4 -2
  6. package/esm/contracts/providers.d.mts +101 -0
  7. package/esm/contracts/providers.d.mts.map +1 -0
  8. package/esm/contracts/request-locals.d.mts +43 -0
  9. package/esm/contracts/request-locals.d.mts.map +1 -0
  10. package/esm/contracts/types.d.mts +159 -1
  11. package/esm/contracts/types.d.mts.map +1 -1
  12. package/esm/contracts/types.mjs.map +1 -1
  13. package/esm/errors/auth-provider-sdk-missing.error.d.mts +17 -0
  14. package/esm/errors/auth-provider-sdk-missing.error.d.mts.map +1 -0
  15. package/esm/errors/auth-provider-sdk-missing.error.mjs +22 -0
  16. package/esm/errors/auth-provider-sdk-missing.error.mjs.map +1 -0
  17. package/esm/errors/email-not-verified.error.d.mts +16 -0
  18. package/esm/errors/email-not-verified.error.d.mts.map +1 -0
  19. package/esm/errors/email-not-verified.error.mjs +20 -0
  20. package/esm/errors/email-not-verified.error.mjs.map +1 -0
  21. package/esm/errors/index.d.mts +7 -0
  22. package/esm/errors/index.mjs +9 -0
  23. package/esm/errors/invalid-one-time-token.error.d.mts +17 -0
  24. package/esm/errors/invalid-one-time-token.error.d.mts.map +1 -0
  25. package/esm/errors/invalid-one-time-token.error.mjs +21 -0
  26. package/esm/errors/invalid-one-time-token.error.mjs.map +1 -0
  27. package/esm/errors/invalid-passkey.error.d.mts +18 -0
  28. package/esm/errors/invalid-passkey.error.d.mts.map +1 -0
  29. package/esm/errors/invalid-passkey.error.mjs +23 -0
  30. package/esm/errors/invalid-passkey.error.mjs.map +1 -0
  31. package/esm/errors/invalid-provider-callback.error.d.mts +18 -0
  32. package/esm/errors/invalid-provider-callback.error.d.mts.map +1 -0
  33. package/esm/errors/invalid-provider-callback.error.mjs +23 -0
  34. package/esm/errors/invalid-provider-callback.error.mjs.map +1 -0
  35. package/esm/errors/notifications-unavailable.error.d.mts +15 -0
  36. package/esm/errors/notifications-unavailable.error.d.mts.map +1 -0
  37. package/esm/errors/notifications-unavailable.error.mjs +20 -0
  38. package/esm/errors/notifications-unavailable.error.mjs.map +1 -0
  39. package/esm/errors/provider-email-not-verified.error.d.mts +16 -0
  40. package/esm/errors/provider-email-not-verified.error.d.mts.map +1 -0
  41. package/esm/errors/provider-email-not-verified.error.mjs +20 -0
  42. package/esm/errors/provider-email-not-verified.error.mjs.map +1 -0
  43. package/esm/index.d.mts +31 -3
  44. package/esm/index.mjs +29 -1
  45. package/esm/middleware/auth.middleware.d.mts.map +1 -1
  46. package/esm/middleware/auth.middleware.mjs +13 -2
  47. package/esm/middleware/auth.middleware.mjs.map +1 -1
  48. package/esm/middleware/csrf-origin-check.d.mts +40 -0
  49. package/esm/middleware/csrf-origin-check.d.mts.map +1 -0
  50. package/esm/middleware/csrf-origin-check.mjs +105 -0
  51. package/esm/middleware/csrf-origin-check.mjs.map +1 -0
  52. package/esm/middleware/index.d.mts +5 -1
  53. package/esm/middleware/index.mjs +4 -0
  54. package/esm/middleware/one-time-token-throttle.middleware.d.mts +36 -0
  55. package/esm/middleware/one-time-token-throttle.middleware.d.mts.map +1 -0
  56. package/esm/middleware/one-time-token-throttle.middleware.mjs +53 -0
  57. package/esm/middleware/one-time-token-throttle.middleware.mjs.map +1 -0
  58. package/esm/middleware/otp-throttle.middleware.d.mts +30 -0
  59. package/esm/middleware/otp-throttle.middleware.d.mts.map +1 -0
  60. package/esm/middleware/otp-throttle.middleware.mjs +45 -0
  61. package/esm/middleware/otp-throttle.middleware.mjs.map +1 -0
  62. package/esm/middleware/require-verified-email.middleware.d.mts +18 -0
  63. package/esm/middleware/require-verified-email.middleware.d.mts.map +1 -0
  64. package/esm/middleware/require-verified-email.middleware.mjs +24 -0
  65. package/esm/middleware/require-verified-email.middleware.mjs.map +1 -0
  66. package/esm/models/access-token/access-token.model.d.mts +8 -0
  67. package/esm/models/access-token/access-token.model.d.mts.map +1 -1
  68. package/esm/models/access-token/access-token.model.mjs +3 -0
  69. package/esm/models/access-token/access-token.model.mjs.map +1 -1
  70. package/esm/models/index.d.mts +3 -1
  71. package/esm/models/index.d.mts.map +1 -1
  72. package/esm/models/index.mjs +16 -1
  73. package/esm/models/index.mjs.map +1 -1
  74. package/esm/models/one-time-token/index.d.mts +1 -0
  75. package/esm/models/one-time-token/index.mjs +3 -0
  76. package/esm/models/one-time-token/migration.mjs +31 -0
  77. package/esm/models/one-time-token/migration.mjs.map +1 -0
  78. package/esm/models/one-time-token/one-time-token.model.d.mts +173 -0
  79. package/esm/models/one-time-token/one-time-token.model.d.mts.map +1 -0
  80. package/esm/models/one-time-token/one-time-token.model.mjs +151 -0
  81. package/esm/models/one-time-token/one-time-token.model.mjs.map +1 -0
  82. package/esm/models/passkey-credential/index.d.mts +1 -0
  83. package/esm/models/passkey-credential/index.mjs +3 -0
  84. package/esm/models/passkey-credential/migration.mjs +25 -0
  85. package/esm/models/passkey-credential/migration.mjs.map +1 -0
  86. package/esm/models/passkey-credential/passkey-credential.model.d.mts +108 -0
  87. package/esm/models/passkey-credential/passkey-credential.model.d.mts.map +1 -0
  88. package/esm/models/passkey-credential/passkey-credential.model.mjs +70 -0
  89. package/esm/models/passkey-credential/passkey-credential.model.mjs.map +1 -0
  90. package/esm/models/provider-account/index.d.mts +1 -0
  91. package/esm/models/provider-account/index.mjs +3 -0
  92. package/esm/models/provider-account/migration.mjs +25 -0
  93. package/esm/models/provider-account/migration.mjs.map +1 -0
  94. package/esm/models/provider-account/provider-account.model.d.mts +75 -0
  95. package/esm/models/provider-account/provider-account.model.d.mts.map +1 -0
  96. package/esm/models/provider-account/provider-account.model.mjs +55 -0
  97. package/esm/models/provider-account/provider-account.model.mjs.map +1 -0
  98. package/esm/models/refresh-token/refresh-token.model.d.mts +7 -0
  99. package/esm/models/refresh-token/refresh-token.model.d.mts.map +1 -1
  100. package/esm/models/refresh-token/refresh-token.model.mjs +3 -0
  101. package/esm/models/refresh-token/refresh-token.model.mjs.map +1 -1
  102. package/esm/otp/index.d.mts +1 -0
  103. package/esm/otp/index.mjs +3 -0
  104. package/esm/otp/otp.d.mts +38 -0
  105. package/esm/otp/otp.d.mts.map +1 -0
  106. package/esm/otp/otp.mjs +105 -0
  107. package/esm/otp/otp.mjs.map +1 -0
  108. package/esm/passkeys/index.d.mts +3 -0
  109. package/esm/passkeys/index.mjs +4 -0
  110. package/esm/passkeys/passkey-authentication.d.mts +33 -0
  111. package/esm/passkeys/passkey-authentication.d.mts.map +1 -0
  112. package/esm/passkeys/passkey-authentication.mjs +93 -0
  113. package/esm/passkeys/passkey-authentication.mjs.map +1 -0
  114. package/esm/passkeys/passkey-challenges.mjs +53 -0
  115. package/esm/passkeys/passkey-challenges.mjs.map +1 -0
  116. package/esm/passkeys/passkey-registration.d.mts +29 -0
  117. package/esm/passkeys/passkey-registration.d.mts.map +1 -0
  118. package/esm/passkeys/passkey-registration.mjs +88 -0
  119. package/esm/passkeys/passkey-registration.mjs.map +1 -0
  120. package/esm/passkeys/simplewebauthn.d.mts +21 -0
  121. package/esm/passkeys/simplewebauthn.d.mts.map +1 -0
  122. package/esm/passkeys/simplewebauthn.mjs +13 -0
  123. package/esm/passkeys/simplewebauthn.mjs.map +1 -0
  124. package/esm/providers/google-provider.d.mts +40 -0
  125. package/esm/providers/google-provider.d.mts.map +1 -0
  126. package/esm/providers/google-provider.mjs +105 -0
  127. package/esm/providers/google-provider.mjs.map +1 -0
  128. package/esm/providers/index.d.mts +2 -0
  129. package/esm/providers/index.mjs +4 -0
  130. package/esm/providers/provider-login.d.mts +43 -0
  131. package/esm/providers/provider-login.d.mts.map +1 -0
  132. package/esm/providers/provider-login.mjs +86 -0
  133. package/esm/providers/provider-login.mjs.map +1 -0
  134. package/esm/providers/provider-state-cookie.mjs +63 -0
  135. package/esm/providers/provider-state-cookie.mjs.map +1 -0
  136. package/esm/providers/resolve-provider-user.mjs +45 -0
  137. package/esm/providers/resolve-provider-user.mjs.map +1 -0
  138. package/esm/services/auth-config.mjs +84 -0
  139. package/esm/services/auth-config.mjs.map +1 -1
  140. package/esm/services/auth.service.d.mts +59 -2
  141. package/esm/services/auth.service.d.mts.map +1 -1
  142. package/esm/services/auth.service.mjs +86 -1
  143. package/esm/services/auth.service.mjs.map +1 -1
  144. package/esm/services/current-user.d.mts +21 -0
  145. package/esm/services/current-user.d.mts.map +1 -0
  146. package/esm/services/current-user.mjs +24 -0
  147. package/esm/services/current-user.mjs.map +1 -0
  148. package/esm/services/email-verification.d.mts +35 -0
  149. package/esm/services/email-verification.d.mts.map +1 -0
  150. package/esm/services/email-verification.mjs +55 -0
  151. package/esm/services/email-verification.mjs.map +1 -0
  152. package/esm/services/index.d.mts +5 -1
  153. package/esm/services/index.mjs +4 -0
  154. package/esm/services/one-time-tokens.d.mts +32 -0
  155. package/esm/services/one-time-tokens.d.mts.map +1 -0
  156. package/esm/services/one-time-tokens.mjs +56 -0
  157. package/esm/services/one-time-tokens.mjs.map +1 -0
  158. package/esm/services/optional-peer.mjs +37 -0
  159. package/esm/services/optional-peer.mjs.map +1 -0
  160. package/esm/services/password-reset.d.mts +34 -0
  161. package/esm/services/password-reset.d.mts.map +1 -0
  162. package/esm/services/password-reset.mjs +81 -0
  163. package/esm/services/password-reset.mjs.map +1 -0
  164. package/esm/services/token-notifications.mjs +87 -0
  165. package/esm/services/token-notifications.mjs.map +1 -0
  166. package/esm/utils/auth-error-codes.d.mts +48 -1
  167. package/esm/utils/auth-error-codes.d.mts.map +1 -1
  168. package/esm/utils/auth-error-codes.mjs +41 -0
  169. package/esm/utils/auth-error-codes.mjs.map +1 -1
  170. package/esm/utils/index.mjs +1 -0
  171. package/esm/utils/safe-equal.d.mts +6 -0
  172. package/esm/utils/safe-equal.d.mts.map +1 -0
  173. package/esm/utils/safe-equal.mjs +13 -0
  174. package/esm/utils/safe-equal.mjs.map +1 -0
  175. package/llms-full.txt +402 -29
  176. package/llms.txt +2 -0
  177. package/package.json +21 -7
  178. package/skills/handle-login-and-logout/SKILL.md +1 -1
  179. package/skills/login-with-providers/SKILL.md +154 -0
  180. package/skills/manage-tokens/SKILL.md +7 -1
  181. package/skills/overview/SKILL.md +1 -1
  182. package/skills/protect-routes/SKILL.md +71 -13
  183. package/skills/register-user/SKILL.md +6 -8
  184. package/skills/run-auth-commands/SKILL.md +1 -1
  185. package/skills/verify-email-and-reset-password/SKILL.md +137 -0
@@ -0,0 +1,87 @@
1
+ import { authConfig } from "./auth-config.mjs";
2
+ import { NotificationsUnavailableError } from "../errors/notifications-unavailable.error.mjs";
3
+
4
+ //#region ../auth/src/services/token-notifications.ts
5
+ /** Non-literal on purpose: keeps type-checkers and bundlers from requiring the optional peer. */
6
+ const NOTIFICATIONS_PACKAGE = "@warlock.js/notifications";
7
+ const defaults = /* @__PURE__ */ new Map();
8
+ /**
9
+ * Whether `error` (or an error it wraps as `cause`, as some loaders do) is the
10
+ * resolver saying the notifications package itself is absent. A missing
11
+ * TRANSITIVE dependency names a different package and is rethrown untouched.
12
+ */
13
+ function isPackageMissing(error) {
14
+ for (let current = error, depth = 0; current && depth < 5; depth++) {
15
+ const { code, message } = current;
16
+ if ((code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") && typeof message === "string" && message.includes(`'${NOTIFICATIONS_PACKAGE}'`)) return true;
17
+ current = current.cause;
18
+ }
19
+ return false;
20
+ }
21
+ async function loadNotifications() {
22
+ let notifications;
23
+ try {
24
+ notifications = await import(NOTIFICATIONS_PACKAGE);
25
+ } catch (error) {
26
+ if (isPackageMissing(error)) throw new NotificationsUnavailableError("not-installed", error);
27
+ throw error;
28
+ }
29
+ try {
30
+ notifications.getNotificationConfig();
31
+ } catch (error) {
32
+ throw new NotificationsUnavailableError("not-configured", error);
33
+ }
34
+ return notifications;
35
+ }
36
+ function escapeHtml(value) {
37
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
38
+ }
39
+ function mailBody(intro, data) {
40
+ const action = data.url ?? data.token;
41
+ const expires = data.expiresAt.toISOString();
42
+ return {
43
+ html: `<p>${intro}</p>` + (data.url ? `<p><a href="${escapeHtml(data.url)}">${escapeHtml(data.url)}</a></p>` : `<p><code>${escapeHtml(data.token)}</code></p>`) + `<p>This link expires at ${expires}. If you did not request it, ignore this email.</p>`,
44
+ text: `${intro}\n\n${action}\n\nThis link expires at ${expires}. If you did not request it, ignore this email.`
45
+ };
46
+ }
47
+ function defineDefault(notifications, type) {
48
+ if (type === "email-verification") return notifications.defineNotification({
49
+ type: "auth.email-verification",
50
+ via: ["mail"],
51
+ mail: (data) => ({
52
+ subject: "Verify your email address",
53
+ ...mailBody("Confirm your email address to finish setting up your account.", data)
54
+ })
55
+ });
56
+ return notifications.defineNotification({
57
+ type: "auth.password-reset",
58
+ via: ["mail"],
59
+ mail: (data) => ({
60
+ subject: "Reset your password",
61
+ ...mailBody("Use this to choose a new password.", data)
62
+ })
63
+ });
64
+ }
65
+ /**
66
+ * Resolve the notification a token of `type` is delivered through — the app's
67
+ * configured override, else auth's default mail notification.
68
+ *
69
+ * Always confirms `@warlock.js/notifications` is installed AND configured
70
+ * first, even when an override is set, so an app can never issue a token that
71
+ * silently goes nowhere. Throws {@link NotificationsUnavailableError}.
72
+ */
73
+ async function resolveTokenNotification(type) {
74
+ const notifications = await loadNotifications();
75
+ const override = type === "email-verification" ? authConfig.verification.notification() : authConfig.passwordReset.notification();
76
+ if (override) return override;
77
+ let notification = defaults.get(type);
78
+ if (!notification) {
79
+ notification = defineDefault(notifications, type);
80
+ defaults.set(type, notification);
81
+ }
82
+ return notification;
83
+ }
84
+
85
+ //#endregion
86
+ export { resolveTokenNotification };
87
+ //# sourceMappingURL=token-notifications.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-notifications.mjs","names":[],"sources":["../../../../../../../auth/src/services/token-notifications.ts"],"sourcesContent":["import type { AuthNotification, OneTimeTokenNotificationData } from \"../contracts/types\";\nimport { NotificationsUnavailableError } from \"../errors/notifications-unavailable.error\";\nimport { authConfig } from \"./auth-config\";\n\n/** Which token notification to resolve. */\nexport type TokenNotificationType = \"email-verification\" | \"password-reset\";\n\n/**\n * The slice of `@warlock.js/notifications` auth uses. Declared locally because\n * the package is an OPTIONAL peer: auth must type-check and load without it.\n */\ntype NotificationsModule = {\n getNotificationConfig: () => unknown;\n defineNotification: (definition: {\n type: string;\n via: string[];\n mail: (data: OneTimeTokenNotificationData) => { subject: string; html: string; text: string };\n }) => AuthNotification;\n};\n\n/** Non-literal on purpose: keeps type-checkers and bundlers from requiring the optional peer. */\nconst NOTIFICATIONS_PACKAGE: string = \"@warlock.js/notifications\";\n\nconst defaults = new Map<TokenNotificationType, AuthNotification>();\n\n/**\n * Whether `error` (or an error it wraps as `cause`, as some loaders do) is the\n * resolver saying the notifications package itself is absent. A missing\n * TRANSITIVE dependency names a different package and is rethrown untouched.\n */\nfunction isPackageMissing(error: unknown): boolean {\n for (let current = error, depth = 0; current && depth < 5; depth++) {\n const { code, message } = current as { code?: unknown; message?: unknown };\n\n if (\n (code === \"ERR_MODULE_NOT_FOUND\" || code === \"MODULE_NOT_FOUND\") &&\n typeof message === \"string\" &&\n message.includes(`'${NOTIFICATIONS_PACKAGE}'`)\n ) {\n return true;\n }\n\n current = (current as { cause?: unknown }).cause;\n }\n\n return false;\n}\n\nasync function loadNotifications(): Promise<NotificationsModule> {\n let notifications: NotificationsModule;\n\n try {\n notifications = (await import(NOTIFICATIONS_PACKAGE)) as NotificationsModule;\n } catch (error) {\n if (isPackageMissing(error)) {\n throw new NotificationsUnavailableError(\"not-installed\", error);\n }\n\n throw error;\n }\n\n try {\n notifications.getNotificationConfig();\n } catch (error) {\n throw new NotificationsUnavailableError(\"not-configured\", error);\n }\n\n return notifications;\n}\n\nfunction escapeHtml(value: string): string {\n return value\n .replace(/&/g, \"&amp;\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\")\n .replace(/\"/g, \"&quot;\");\n}\n\nfunction mailBody(intro: string, data: OneTimeTokenNotificationData) {\n const action = data.url ?? data.token;\n const expires = data.expiresAt.toISOString();\n\n return {\n html:\n `<p>${intro}</p>` +\n (data.url\n ? `<p><a href=\"${escapeHtml(data.url)}\">${escapeHtml(data.url)}</a></p>`\n : `<p><code>${escapeHtml(data.token)}</code></p>`) +\n `<p>This link expires at ${expires}. If you did not request it, ignore this email.</p>`,\n text: `${intro}\\n\\n${action}\\n\\nThis link expires at ${expires}. If you did not request it, ignore this email.`,\n };\n}\n\nfunction defineDefault(\n notifications: NotificationsModule,\n type: TokenNotificationType,\n): AuthNotification {\n if (type === \"email-verification\") {\n return notifications.defineNotification({\n type: \"auth.email-verification\",\n via: [\"mail\"],\n mail: (data) => ({\n subject: \"Verify your email address\",\n ...mailBody(\"Confirm your email address to finish setting up your account.\", data),\n }),\n });\n }\n\n return notifications.defineNotification({\n type: \"auth.password-reset\",\n via: [\"mail\"],\n mail: (data) => ({\n subject: \"Reset your password\",\n ...mailBody(\"Use this to choose a new password.\", data),\n }),\n });\n}\n\n/**\n * Resolve the notification a token of `type` is delivered through — the app's\n * configured override, else auth's default mail notification.\n *\n * Always confirms `@warlock.js/notifications` is installed AND configured\n * first, even when an override is set, so an app can never issue a token that\n * silently goes nowhere. Throws {@link NotificationsUnavailableError}.\n */\nexport async function resolveTokenNotification(\n type: TokenNotificationType,\n): Promise<AuthNotification> {\n const notifications = await loadNotifications();\n\n const override =\n type === \"email-verification\"\n ? authConfig.verification.notification()\n : authConfig.passwordReset.notification();\n\n if (override) return override;\n\n let notification = defaults.get(type);\n\n if (!notification) {\n notification = defineDefault(notifications, type);\n defaults.set(type, notification);\n }\n\n return notification;\n}\n"],"mappings":";;;;;AAqBA,MAAM,wBAAgC;AAEtC,MAAM,2BAAW,IAAI,IAA6C;;;;;;AAOlE,SAAS,iBAAiB,OAAyB;CACjD,KAAK,IAAI,UAAU,OAAO,QAAQ,GAAG,WAAW,QAAQ,GAAG,SAAS;EAClE,MAAM,EAAE,MAAM,YAAY;EAE1B,KACG,SAAS,0BAA0B,SAAS,uBAC7C,OAAO,YAAY,YACnB,QAAQ,SAAS,IAAI,sBAAsB,EAAE,GAE7C,OAAO;EAGT,UAAW,QAAgC;CAC7C;CAEA,OAAO;AACT;AAEA,eAAe,oBAAkD;CAC/D,IAAI;CAEJ,IAAI;EACF,gBAAiB,MAAM,OAAO;CAChC,SAAS,OAAO;EACd,IAAI,iBAAiB,KAAK,GACxB,MAAM,IAAI,8BAA8B,iBAAiB,KAAK;EAGhE,MAAM;CACR;CAEA,IAAI;EACF,cAAc,sBAAsB;CACtC,SAAS,OAAO;EACd,MAAM,IAAI,8BAA8B,kBAAkB,KAAK;CACjE;CAEA,OAAO;AACT;AAEA,SAAS,WAAW,OAAuB;CACzC,OAAO,MACJ,QAAQ,MAAM,OAAO,CAAC,CACtB,QAAQ,MAAM,MAAM,CAAC,CACrB,QAAQ,MAAM,MAAM,CAAC,CACrB,QAAQ,MAAM,QAAQ;AAC3B;AAEA,SAAS,SAAS,OAAe,MAAoC;CACnE,MAAM,SAAS,KAAK,OAAO,KAAK;CAChC,MAAM,UAAU,KAAK,UAAU,YAAY;CAE3C,OAAO;EACL,MACE,MAAM,MAAM,SACX,KAAK,MACF,eAAe,WAAW,KAAK,GAAG,EAAE,IAAI,WAAW,KAAK,GAAG,EAAE,YAC7D,YAAY,WAAW,KAAK,KAAK,EAAE,gBACvC,2BAA2B,QAAQ;EACrC,MAAM,GAAG,MAAM,MAAM,OAAO,2BAA2B,QAAQ;CACjE;AACF;AAEA,SAAS,cACP,eACA,MACkB;CAClB,IAAI,SAAS,sBACX,OAAO,cAAc,mBAAmB;EACtC,MAAM;EACN,KAAK,CAAC,MAAM;EACZ,OAAO,UAAU;GACf,SAAS;GACT,GAAG,SAAS,iEAAiE,IAAI;EACnF;CACF,CAAC;CAGH,OAAO,cAAc,mBAAmB;EACtC,MAAM;EACN,KAAK,CAAC,MAAM;EACZ,OAAO,UAAU;GACf,SAAS;GACT,GAAG,SAAS,sCAAsC,IAAI;EACxD;CACF,CAAC;AACH;;;;;;;;;AAUA,eAAsB,yBACpB,MAC2B;CAC3B,MAAM,gBAAgB,MAAM,kBAAkB;CAE9C,MAAM,WACJ,SAAS,uBACL,WAAW,aAAa,aAAa,IACrC,WAAW,cAAc,aAAa;CAE5C,IAAI,UAAU,OAAO;CAErB,IAAI,eAAe,SAAS,IAAI,IAAI;CAEpC,IAAI,CAAC,cAAc;EACjB,eAAe,cAAc,eAAe,IAAI;EAChD,SAAS,IAAI,MAAM,YAAY;CACjC;CAEA,OAAO;AACT"}
@@ -33,7 +33,54 @@ declare enum AuthErrorCodes {
33
33
  * `Error` thrown by `assertTokenType` (`services/jwt.ts`) so callers can
34
34
  * classify it as a credential failure without matching on the message.
35
35
  */
36
- InvalidTokenType = "EC005"
36
+ InvalidTokenType = "EC005",
37
+ // Error Code 005
38
+ /**
39
+ * CSRF Origin Mismatch Error Code EC006
40
+ * EC006 = a cookie-authenticated, unsafe-method (POST/PUT/PATCH/DELETE)
41
+ * request whose `Origin` (or, absent that, `Referer`) did not match the
42
+ * request's own origin or an entry in `auth.csrf.allowedOrigins`, or whose
43
+ * request carried neither header at all.
44
+ */
45
+ CsrfOriginMismatch = "EC006",
46
+ // Error Code 006
47
+ /**
48
+ * Email Not Verified Error Code EC007
49
+ * EC007 = the authenticated user has not verified their email address —
50
+ * thrown by `requireVerifiedEmail()` as `EmailNotVerifiedError` (403).
51
+ */
52
+ EmailNotVerified = "EC007",
53
+ // Error Code 007
54
+ /**
55
+ * Invalid One-Time Token Error Code EC008
56
+ * EC008 = an email-verification or password-reset token that is unknown,
57
+ * issued for the other purpose, expired, or already used. One code for all
58
+ * four on purpose: the caller learns nothing about which it was.
59
+ */
60
+ InvalidOneTimeToken = "EC008",
61
+ // Error Code 008
62
+ /**
63
+ * Invalid Provider Callback Error Code EC009
64
+ * EC009 = a redirect-provider callback was rejected: missing, forged or
65
+ * expired state cookie, `state` mismatch, failed code exchange, or an
66
+ * id_token with a bad signature, issuer, audience, expiry or nonce.
67
+ */
68
+ InvalidProviderCallback = "EC009",
69
+ // Error Code 009
70
+ /**
71
+ * Provider Email Not Verified Error Code EC010
72
+ * EC010 = the provider did not verify the email, so auth refused to link or
73
+ * create an account from it.
74
+ */
75
+ ProviderEmailNotVerified = "EC010",
76
+ // Error Code 010
77
+ /**
78
+ * Invalid Passkey Error Code EC011
79
+ * EC011 = a passkey ceremony was rejected: unknown, expired or used
80
+ * challenge, unknown credential, failed verification, or a signature counter
81
+ * that did not advance.
82
+ */
83
+ InvalidPasskey = "EC011"
37
84
  }
38
85
  //#endregion
39
86
  export { AuthErrorCodes };
@@ -1 +1 @@
1
- {"version":3,"file":"auth-error-codes.d.mts","names":[],"sources":["../../../../../../../auth/src/utils/auth-error-codes.ts"],"mappings":";aAAY,cAAA;EAAA;;;;EAKV,kBAAA;EAAA;EAKA;;;;EAAA,kBAAA;EAAA;EAoBgB;;;;EAfhB,YAAA;EAAA;;;;;;EAMA,eAAA;EAAA;;;;;;;;;EASA,gBAAA;AAAA"}
1
+ {"version":3,"file":"auth-error-codes.d.mts","names":[],"sources":["../../../../../../../auth/src/utils/auth-error-codes.ts"],"mappings":";aAAY,cAAA;EAAA;;;;EAKV,kBAAA;EAAA;EAKA;;;;EAAA,kBAAA;EAAA;EAkCA;;;;EA7BA,YAAA;EAAA;EAwDc;AAAA;;;;EAlDd,eAAA;EAAA;;;;;;;;;EASA,gBAAA;EAAA;;;;;;;;EAQA,kBAAA;EAAA;;;;;;EAMA,gBAAA;EAAA;;;;;;;EAOA,mBAAA;EAAA;;;;;;;EAOA,uBAAA;EAAA;;;;;;EAMA,wBAAA;EAAA;;;;;;;EAOA,cAAA;AAAA"}
@@ -30,6 +30,47 @@ let AuthErrorCodes = /* @__PURE__ */ function(AuthErrorCodes) {
30
30
  * classify it as a credential failure without matching on the message.
31
31
  */
32
32
  AuthErrorCodes["InvalidTokenType"] = "EC005";
33
+ /**
34
+ * CSRF Origin Mismatch Error Code EC006
35
+ * EC006 = a cookie-authenticated, unsafe-method (POST/PUT/PATCH/DELETE)
36
+ * request whose `Origin` (or, absent that, `Referer`) did not match the
37
+ * request's own origin or an entry in `auth.csrf.allowedOrigins`, or whose
38
+ * request carried neither header at all.
39
+ */
40
+ AuthErrorCodes["CsrfOriginMismatch"] = "EC006";
41
+ /**
42
+ * Email Not Verified Error Code EC007
43
+ * EC007 = the authenticated user has not verified their email address —
44
+ * thrown by `requireVerifiedEmail()` as `EmailNotVerifiedError` (403).
45
+ */
46
+ AuthErrorCodes["EmailNotVerified"] = "EC007";
47
+ /**
48
+ * Invalid One-Time Token Error Code EC008
49
+ * EC008 = an email-verification or password-reset token that is unknown,
50
+ * issued for the other purpose, expired, or already used. One code for all
51
+ * four on purpose: the caller learns nothing about which it was.
52
+ */
53
+ AuthErrorCodes["InvalidOneTimeToken"] = "EC008";
54
+ /**
55
+ * Invalid Provider Callback Error Code EC009
56
+ * EC009 = a redirect-provider callback was rejected: missing, forged or
57
+ * expired state cookie, `state` mismatch, failed code exchange, or an
58
+ * id_token with a bad signature, issuer, audience, expiry or nonce.
59
+ */
60
+ AuthErrorCodes["InvalidProviderCallback"] = "EC009";
61
+ /**
62
+ * Provider Email Not Verified Error Code EC010
63
+ * EC010 = the provider did not verify the email, so auth refused to link or
64
+ * create an account from it.
65
+ */
66
+ AuthErrorCodes["ProviderEmailNotVerified"] = "EC010";
67
+ /**
68
+ * Invalid Passkey Error Code EC011
69
+ * EC011 = a passkey ceremony was rejected: unknown, expired or used
70
+ * challenge, unknown credential, failed verification, or a signature counter
71
+ * that did not advance.
72
+ */
73
+ AuthErrorCodes["InvalidPasskey"] = "EC011";
33
74
  return AuthErrorCodes;
34
75
  }({});
35
76
 
@@ -1 +1 @@
1
- {"version":3,"file":"auth-error-codes.mjs","names":[],"sources":["../../../../../../../auth/src/utils/auth-error-codes.ts"],"sourcesContent":["export enum AuthErrorCodes {\r\n /**\r\n * Missing Access Token Error Code EC001\r\n * EC001 = Missing Access Token\r\n */\r\n MissingAccessToken = \"EC001\", // Error Code 001\r\n /**\r\n * Invalid Access Token Error Code EC002\r\n * EC002 = Invalid Access Token\r\n */\r\n InvalidAccessToken = \"EC002\", // Error Code 002\r\n /**\r\n * Unauthorized Error Code EC003\r\n * EC003 = Unauthorized\r\n */\r\n Unauthorized = \"EC003\", // Error Code 003\r\n /**\r\n * Too Many Attempts Error Code EC004\r\n * EC004 = Too Many Attempts — issued by the login-throttle middleware once\r\n * a per-account or per-IP failure counter trips its threshold.\r\n */\r\n TooManyAttempts = \"EC004\", // Error Code 004\r\n /**\r\n * Invalid Token Type Error Code EC005\r\n * EC005 = Invalid Token Type — the token's `tokenType` claim does not match\r\n * what the caller expects (e.g. a refresh token presented where an access\r\n * token is required, or vice versa). Carried on the `code` property of the\r\n * `Error` thrown by `assertTokenType` (`services/jwt.ts`) so callers can\r\n * classify it as a credential failure without matching on the message.\r\n */\r\n InvalidTokenType = \"EC005\", // Error Code 005\r\n}\r\n"],"mappings":";AAAA,IAAY,iBAAL;;;;;CAKL;;;;;CAKA;;;;;CAKA;;;;;;CAMA;;;;;;;;;CASA;;AACF"}
1
+ {"version":3,"file":"auth-error-codes.mjs","names":[],"sources":["../../../../../../../auth/src/utils/auth-error-codes.ts"],"sourcesContent":["export enum AuthErrorCodes {\r\n /**\r\n * Missing Access Token Error Code EC001\r\n * EC001 = Missing Access Token\r\n */\r\n MissingAccessToken = \"EC001\", // Error Code 001\r\n /**\r\n * Invalid Access Token Error Code EC002\r\n * EC002 = Invalid Access Token\r\n */\r\n InvalidAccessToken = \"EC002\", // Error Code 002\r\n /**\r\n * Unauthorized Error Code EC003\r\n * EC003 = Unauthorized\r\n */\r\n Unauthorized = \"EC003\", // Error Code 003\r\n /**\r\n * Too Many Attempts Error Code EC004\r\n * EC004 = Too Many Attempts — issued by the login-throttle middleware once\r\n * a per-account or per-IP failure counter trips its threshold.\r\n */\r\n TooManyAttempts = \"EC004\", // Error Code 004\r\n /**\r\n * Invalid Token Type Error Code EC005\r\n * EC005 = Invalid Token Type — the token's `tokenType` claim does not match\r\n * what the caller expects (e.g. a refresh token presented where an access\r\n * token is required, or vice versa). Carried on the `code` property of the\r\n * `Error` thrown by `assertTokenType` (`services/jwt.ts`) so callers can\r\n * classify it as a credential failure without matching on the message.\r\n */\r\n InvalidTokenType = \"EC005\", // Error Code 005\r\n /**\r\n * CSRF Origin Mismatch Error Code EC006\r\n * EC006 = a cookie-authenticated, unsafe-method (POST/PUT/PATCH/DELETE)\r\n * request whose `Origin` (or, absent that, `Referer`) did not match the\r\n * request's own origin or an entry in `auth.csrf.allowedOrigins`, or whose\r\n * request carried neither header at all.\r\n */\r\n CsrfOriginMismatch = \"EC006\", // Error Code 006\r\n /**\r\n * Email Not Verified Error Code EC007\r\n * EC007 = the authenticated user has not verified their email address —\r\n * thrown by `requireVerifiedEmail()` as `EmailNotVerifiedError` (403).\r\n */\r\n EmailNotVerified = \"EC007\", // Error Code 007\r\n /**\r\n * Invalid One-Time Token Error Code EC008\r\n * EC008 = an email-verification or password-reset token that is unknown,\r\n * issued for the other purpose, expired, or already used. One code for all\r\n * four on purpose: the caller learns nothing about which it was.\r\n */\r\n InvalidOneTimeToken = \"EC008\", // Error Code 008\r\n /**\r\n * Invalid Provider Callback Error Code EC009\r\n * EC009 = a redirect-provider callback was rejected: missing, forged or\r\n * expired state cookie, `state` mismatch, failed code exchange, or an\r\n * id_token with a bad signature, issuer, audience, expiry or nonce.\r\n */\r\n InvalidProviderCallback = \"EC009\", // Error Code 009\r\n /**\r\n * Provider Email Not Verified Error Code EC010\r\n * EC010 = the provider did not verify the email, so auth refused to link or\r\n * create an account from it.\r\n */\r\n ProviderEmailNotVerified = \"EC010\", // Error Code 010\r\n /**\r\n * Invalid Passkey Error Code EC011\r\n * EC011 = a passkey ceremony was rejected: unknown, expired or used\r\n * challenge, unknown credential, failed verification, or a signature counter\r\n * that did not advance.\r\n */\r\n InvalidPasskey = \"EC011\", // Error Code 011\r\n}\r\n"],"mappings":";AAAA,IAAY,iBAAL;;;;;CAKL;;;;;CAKA;;;;;CAKA;;;;;;CAMA;;;;;;;;;CASA;;;;;;;;CAQA;;;;;;CAMA;;;;;;;CAOA;;;;;;;CAOA;;;;;;CAMA;;;;;;;CAOA;;AACF"}
@@ -1,4 +1,5 @@
1
1
  import { isNeverExpiring, isUsableExpiry, tokenHasExpClaim } from "./token-expiry.mjs";
2
2
  import { AuthErrorCodes } from "./auth-error-codes.mjs";
3
+ import { safeEqual } from "./safe-equal.mjs";
3
4
 
4
5
  export { };
@@ -0,0 +1,6 @@
1
+ //#region ../auth/src/utils/safe-equal.d.ts
2
+ /** Constant-time string equality; strings of unequal length are simply unequal. */
3
+ declare function safeEqual(left: string, right: string): boolean;
4
+ //#endregion
5
+ export { safeEqual };
6
+ //# sourceMappingURL=safe-equal.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safe-equal.d.mts","names":[],"sources":["../../../../../../../auth/src/utils/safe-equal.ts"],"mappings":";;iBAGgB,SAAA,CAAU,IAAA,UAAc,KAAa"}
@@ -0,0 +1,13 @@
1
+ import { timingSafeEqual } from "node:crypto";
2
+
3
+ //#region ../auth/src/utils/safe-equal.ts
4
+ /** Constant-time string equality; strings of unequal length are simply unequal. */
5
+ function safeEqual(left, right) {
6
+ const a = Buffer.from(left);
7
+ const b = Buffer.from(right);
8
+ return a.length === b.length && timingSafeEqual(a, b);
9
+ }
10
+
11
+ //#endregion
12
+ export { safeEqual };
13
+ //# sourceMappingURL=safe-equal.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safe-equal.mjs","names":[],"sources":["../../../../../../../auth/src/utils/safe-equal.ts"],"sourcesContent":["import { timingSafeEqual } from \"node:crypto\";\n\n/** Constant-time string equality; strings of unequal length are simply unequal. */\nexport function safeEqual(left: string, right: string): boolean {\n const a = Buffer.from(left);\n const b = Buffer.from(right);\n\n return a.length === b.length && timingSafeEqual(a, b);\n}\n"],"mappings":";;;;AAGA,SAAgB,UAAU,MAAc,OAAwB;CAC9D,MAAM,IAAI,OAAO,KAAK,IAAI;CAC1B,MAAM,IAAI,OAAO,KAAK,KAAK;CAE3B,OAAO,EAAE,WAAW,EAAE,UAAU,gBAAgB,GAAG,CAAC;AACtD"}