@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.
- package/CHANGELOG.md +65 -0
- package/README.md +88 -86
- package/esm/commands/auth-cleanup-command.mjs +1 -1
- package/esm/commands/auth-cleanup-command.mjs.map +1 -1
- package/esm/contracts/index.d.mts +4 -2
- package/esm/contracts/providers.d.mts +101 -0
- package/esm/contracts/providers.d.mts.map +1 -0
- package/esm/contracts/request-locals.d.mts +43 -0
- package/esm/contracts/request-locals.d.mts.map +1 -0
- package/esm/contracts/types.d.mts +159 -1
- package/esm/contracts/types.d.mts.map +1 -1
- package/esm/contracts/types.mjs.map +1 -1
- package/esm/errors/auth-provider-sdk-missing.error.d.mts +17 -0
- package/esm/errors/auth-provider-sdk-missing.error.d.mts.map +1 -0
- package/esm/errors/auth-provider-sdk-missing.error.mjs +22 -0
- package/esm/errors/auth-provider-sdk-missing.error.mjs.map +1 -0
- package/esm/errors/email-not-verified.error.d.mts +16 -0
- package/esm/errors/email-not-verified.error.d.mts.map +1 -0
- package/esm/errors/email-not-verified.error.mjs +20 -0
- package/esm/errors/email-not-verified.error.mjs.map +1 -0
- package/esm/errors/index.d.mts +7 -0
- package/esm/errors/index.mjs +9 -0
- package/esm/errors/invalid-one-time-token.error.d.mts +17 -0
- package/esm/errors/invalid-one-time-token.error.d.mts.map +1 -0
- package/esm/errors/invalid-one-time-token.error.mjs +21 -0
- package/esm/errors/invalid-one-time-token.error.mjs.map +1 -0
- package/esm/errors/invalid-passkey.error.d.mts +18 -0
- package/esm/errors/invalid-passkey.error.d.mts.map +1 -0
- package/esm/errors/invalid-passkey.error.mjs +23 -0
- package/esm/errors/invalid-passkey.error.mjs.map +1 -0
- package/esm/errors/invalid-provider-callback.error.d.mts +18 -0
- package/esm/errors/invalid-provider-callback.error.d.mts.map +1 -0
- package/esm/errors/invalid-provider-callback.error.mjs +23 -0
- package/esm/errors/invalid-provider-callback.error.mjs.map +1 -0
- package/esm/errors/notifications-unavailable.error.d.mts +15 -0
- package/esm/errors/notifications-unavailable.error.d.mts.map +1 -0
- package/esm/errors/notifications-unavailable.error.mjs +20 -0
- package/esm/errors/notifications-unavailable.error.mjs.map +1 -0
- package/esm/errors/provider-email-not-verified.error.d.mts +16 -0
- package/esm/errors/provider-email-not-verified.error.d.mts.map +1 -0
- package/esm/errors/provider-email-not-verified.error.mjs +20 -0
- package/esm/errors/provider-email-not-verified.error.mjs.map +1 -0
- package/esm/index.d.mts +31 -3
- package/esm/index.mjs +29 -1
- package/esm/middleware/auth.middleware.d.mts.map +1 -1
- package/esm/middleware/auth.middleware.mjs +13 -2
- package/esm/middleware/auth.middleware.mjs.map +1 -1
- package/esm/middleware/csrf-origin-check.d.mts +40 -0
- package/esm/middleware/csrf-origin-check.d.mts.map +1 -0
- package/esm/middleware/csrf-origin-check.mjs +105 -0
- package/esm/middleware/csrf-origin-check.mjs.map +1 -0
- package/esm/middleware/index.d.mts +5 -1
- package/esm/middleware/index.mjs +4 -0
- package/esm/middleware/one-time-token-throttle.middleware.d.mts +36 -0
- package/esm/middleware/one-time-token-throttle.middleware.d.mts.map +1 -0
- package/esm/middleware/one-time-token-throttle.middleware.mjs +53 -0
- package/esm/middleware/one-time-token-throttle.middleware.mjs.map +1 -0
- package/esm/middleware/otp-throttle.middleware.d.mts +30 -0
- package/esm/middleware/otp-throttle.middleware.d.mts.map +1 -0
- package/esm/middleware/otp-throttle.middleware.mjs +45 -0
- package/esm/middleware/otp-throttle.middleware.mjs.map +1 -0
- package/esm/middleware/require-verified-email.middleware.d.mts +18 -0
- package/esm/middleware/require-verified-email.middleware.d.mts.map +1 -0
- package/esm/middleware/require-verified-email.middleware.mjs +24 -0
- package/esm/middleware/require-verified-email.middleware.mjs.map +1 -0
- package/esm/models/access-token/access-token.model.d.mts +8 -0
- package/esm/models/access-token/access-token.model.d.mts.map +1 -1
- package/esm/models/access-token/access-token.model.mjs +3 -0
- package/esm/models/access-token/access-token.model.mjs.map +1 -1
- package/esm/models/index.d.mts +3 -1
- package/esm/models/index.d.mts.map +1 -1
- package/esm/models/index.mjs +16 -1
- package/esm/models/index.mjs.map +1 -1
- package/esm/models/one-time-token/index.d.mts +1 -0
- package/esm/models/one-time-token/index.mjs +3 -0
- package/esm/models/one-time-token/migration.mjs +31 -0
- package/esm/models/one-time-token/migration.mjs.map +1 -0
- package/esm/models/one-time-token/one-time-token.model.d.mts +173 -0
- package/esm/models/one-time-token/one-time-token.model.d.mts.map +1 -0
- package/esm/models/one-time-token/one-time-token.model.mjs +151 -0
- package/esm/models/one-time-token/one-time-token.model.mjs.map +1 -0
- package/esm/models/passkey-credential/index.d.mts +1 -0
- package/esm/models/passkey-credential/index.mjs +3 -0
- package/esm/models/passkey-credential/migration.mjs +25 -0
- package/esm/models/passkey-credential/migration.mjs.map +1 -0
- package/esm/models/passkey-credential/passkey-credential.model.d.mts +108 -0
- package/esm/models/passkey-credential/passkey-credential.model.d.mts.map +1 -0
- package/esm/models/passkey-credential/passkey-credential.model.mjs +70 -0
- package/esm/models/passkey-credential/passkey-credential.model.mjs.map +1 -0
- package/esm/models/provider-account/index.d.mts +1 -0
- package/esm/models/provider-account/index.mjs +3 -0
- package/esm/models/provider-account/migration.mjs +25 -0
- package/esm/models/provider-account/migration.mjs.map +1 -0
- package/esm/models/provider-account/provider-account.model.d.mts +75 -0
- package/esm/models/provider-account/provider-account.model.d.mts.map +1 -0
- package/esm/models/provider-account/provider-account.model.mjs +55 -0
- package/esm/models/provider-account/provider-account.model.mjs.map +1 -0
- package/esm/models/refresh-token/refresh-token.model.d.mts +7 -0
- package/esm/models/refresh-token/refresh-token.model.d.mts.map +1 -1
- package/esm/models/refresh-token/refresh-token.model.mjs +3 -0
- package/esm/models/refresh-token/refresh-token.model.mjs.map +1 -1
- package/esm/otp/index.d.mts +1 -0
- package/esm/otp/index.mjs +3 -0
- package/esm/otp/otp.d.mts +38 -0
- package/esm/otp/otp.d.mts.map +1 -0
- package/esm/otp/otp.mjs +105 -0
- package/esm/otp/otp.mjs.map +1 -0
- package/esm/passkeys/index.d.mts +3 -0
- package/esm/passkeys/index.mjs +4 -0
- package/esm/passkeys/passkey-authentication.d.mts +33 -0
- package/esm/passkeys/passkey-authentication.d.mts.map +1 -0
- package/esm/passkeys/passkey-authentication.mjs +93 -0
- package/esm/passkeys/passkey-authentication.mjs.map +1 -0
- package/esm/passkeys/passkey-challenges.mjs +53 -0
- package/esm/passkeys/passkey-challenges.mjs.map +1 -0
- package/esm/passkeys/passkey-registration.d.mts +29 -0
- package/esm/passkeys/passkey-registration.d.mts.map +1 -0
- package/esm/passkeys/passkey-registration.mjs +88 -0
- package/esm/passkeys/passkey-registration.mjs.map +1 -0
- package/esm/passkeys/simplewebauthn.d.mts +21 -0
- package/esm/passkeys/simplewebauthn.d.mts.map +1 -0
- package/esm/passkeys/simplewebauthn.mjs +13 -0
- package/esm/passkeys/simplewebauthn.mjs.map +1 -0
- package/esm/providers/google-provider.d.mts +40 -0
- package/esm/providers/google-provider.d.mts.map +1 -0
- package/esm/providers/google-provider.mjs +105 -0
- package/esm/providers/google-provider.mjs.map +1 -0
- package/esm/providers/index.d.mts +2 -0
- package/esm/providers/index.mjs +4 -0
- package/esm/providers/provider-login.d.mts +43 -0
- package/esm/providers/provider-login.d.mts.map +1 -0
- package/esm/providers/provider-login.mjs +86 -0
- package/esm/providers/provider-login.mjs.map +1 -0
- package/esm/providers/provider-state-cookie.mjs +63 -0
- package/esm/providers/provider-state-cookie.mjs.map +1 -0
- package/esm/providers/resolve-provider-user.mjs +45 -0
- package/esm/providers/resolve-provider-user.mjs.map +1 -0
- package/esm/services/auth-config.mjs +84 -0
- package/esm/services/auth-config.mjs.map +1 -1
- package/esm/services/auth.service.d.mts +59 -2
- package/esm/services/auth.service.d.mts.map +1 -1
- package/esm/services/auth.service.mjs +86 -1
- package/esm/services/auth.service.mjs.map +1 -1
- package/esm/services/current-user.d.mts +21 -0
- package/esm/services/current-user.d.mts.map +1 -0
- package/esm/services/current-user.mjs +24 -0
- package/esm/services/current-user.mjs.map +1 -0
- package/esm/services/email-verification.d.mts +35 -0
- package/esm/services/email-verification.d.mts.map +1 -0
- package/esm/services/email-verification.mjs +55 -0
- package/esm/services/email-verification.mjs.map +1 -0
- package/esm/services/index.d.mts +5 -1
- package/esm/services/index.mjs +4 -0
- package/esm/services/one-time-tokens.d.mts +32 -0
- package/esm/services/one-time-tokens.d.mts.map +1 -0
- package/esm/services/one-time-tokens.mjs +56 -0
- package/esm/services/one-time-tokens.mjs.map +1 -0
- package/esm/services/optional-peer.mjs +37 -0
- package/esm/services/optional-peer.mjs.map +1 -0
- package/esm/services/password-reset.d.mts +34 -0
- package/esm/services/password-reset.d.mts.map +1 -0
- package/esm/services/password-reset.mjs +81 -0
- package/esm/services/password-reset.mjs.map +1 -0
- package/esm/services/token-notifications.mjs +87 -0
- package/esm/services/token-notifications.mjs.map +1 -0
- package/esm/utils/auth-error-codes.d.mts +48 -1
- package/esm/utils/auth-error-codes.d.mts.map +1 -1
- package/esm/utils/auth-error-codes.mjs +41 -0
- package/esm/utils/auth-error-codes.mjs.map +1 -1
- package/esm/utils/index.mjs +1 -0
- package/esm/utils/safe-equal.d.mts +6 -0
- package/esm/utils/safe-equal.d.mts.map +1 -0
- package/esm/utils/safe-equal.mjs +13 -0
- package/esm/utils/safe-equal.mjs.map +1 -0
- package/llms-full.txt +402 -29
- package/llms.txt +2 -0
- package/package.json +21 -7
- package/skills/handle-login-and-logout/SKILL.md +1 -1
- package/skills/login-with-providers/SKILL.md +154 -0
- package/skills/manage-tokens/SKILL.md +7 -1
- package/skills/overview/SKILL.md +1 -1
- package/skills/protect-routes/SKILL.md +71 -13
- package/skills/register-user/SKILL.md +6 -8
- package/skills/run-auth-commands/SKILL.md +1 -1
- 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, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
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, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\");\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;
|
|
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"}
|
package/esm/utils/index.mjs
CHANGED
|
@@ -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"}
|