@puzzle-ui/fullstack 0.0.0-stage → 0.5.1
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/README.md +65 -2
- package/dist/LICENSE +21 -0
- package/dist/auth/client/auth.css +206 -0
- package/dist/auth/client/experience.cjs +340 -0
- package/dist/auth/client/experience.cjs.map +1 -0
- package/dist/auth/client/experience.d.cts +67 -0
- package/dist/auth/client/experience.d.ts +67 -0
- package/dist/auth/client/experience.js +340 -0
- package/dist/auth/client/experience.js.map +1 -0
- package/dist/auth/client/index.cjs +234 -0
- package/dist/auth/client/index.cjs.map +1 -0
- package/dist/auth/client/index.d.cts +48 -0
- package/dist/auth/client/index.d.ts +48 -0
- package/dist/auth/client/index.js +216 -0
- package/dist/auth/client/index.js.map +1 -0
- package/dist/auth/client/messages.cjs +80 -0
- package/dist/auth/client/messages.cjs.map +1 -0
- package/dist/auth/client/messages.d.cts +92 -0
- package/dist/auth/client/messages.d.ts +92 -0
- package/dist/auth/client/messages.js +79 -0
- package/dist/auth/client/messages.js.map +1 -0
- package/dist/auth/client/passkeys.cjs +43 -0
- package/dist/auth/client/passkeys.cjs.map +1 -0
- package/dist/auth/client/passkeys.d.cts +23 -0
- package/dist/auth/client/passkeys.d.ts +23 -0
- package/dist/auth/client/passkeys.js +40 -0
- package/dist/auth/client/passkeys.js.map +1 -0
- package/dist/auth/client/react.cjs +859 -0
- package/dist/auth/client/react.cjs.map +1 -0
- package/dist/auth/client/react.d.cts +72 -0
- package/dist/auth/client/react.d.ts +72 -0
- package/dist/auth/client/react.js +850 -0
- package/dist/auth/client/react.js.map +1 -0
- package/dist/auth/next/index.cjs +40 -0
- package/dist/auth/next/index.cjs.map +1 -0
- package/dist/auth/next/index.d.cts +12 -0
- package/dist/auth/next/index.d.ts +12 -0
- package/dist/auth/next/index.js +38 -0
- package/dist/auth/next/index.js.map +1 -0
- package/dist/auth/server/health.cjs +51 -0
- package/dist/auth/server/health.cjs.map +1 -0
- package/dist/auth/server/health.d.cts +15 -0
- package/dist/auth/server/health.d.ts +15 -0
- package/dist/auth/server/health.js +51 -0
- package/dist/auth/server/health.js.map +1 -0
- package/dist/auth/server/index.cjs +108 -0
- package/dist/auth/server/index.cjs.map +1 -0
- package/dist/auth/server/index.d.cts +22 -0
- package/dist/auth/server/index.d.ts +22 -0
- package/dist/auth/server/index.js +88 -0
- package/dist/auth/server/index.js.map +1 -0
- package/dist/auth/server/lifecycle.cjs +126 -0
- package/dist/auth/server/lifecycle.cjs.map +1 -0
- package/dist/auth/server/lifecycle.d.cts +20 -0
- package/dist/auth/server/lifecycle.d.ts +20 -0
- package/dist/auth/server/lifecycle.js +126 -0
- package/dist/auth/server/lifecycle.js.map +1 -0
- package/dist/auth/server/mfa.cjs +682 -0
- package/dist/auth/server/mfa.cjs.map +1 -0
- package/dist/auth/server/mfa.d.cts +90 -0
- package/dist/auth/server/mfa.d.ts +90 -0
- package/dist/auth/server/mfa.js +673 -0
- package/dist/auth/server/mfa.js.map +1 -0
- package/dist/auth/server/session.cjs +58 -0
- package/dist/auth/server/session.cjs.map +1 -0
- package/dist/auth/server/session.d.cts +14 -0
- package/dist/auth/server/session.d.ts +14 -0
- package/dist/auth/server/session.js +53 -0
- package/dist/auth/server/session.js.map +1 -0
- package/dist/auth/shared/index.cjs +0 -0
- package/dist/auth/shared/index.d.cts +64 -0
- package/dist/auth/shared/index.d.ts +64 -0
- package/dist/auth/shared/index.js +1 -0
- package/dist/auth/tanstack/index.cjs +34 -0
- package/dist/auth/tanstack/index.cjs.map +1 -0
- package/dist/auth/tanstack/index.d.cts +7 -0
- package/dist/auth/tanstack/index.d.ts +7 -0
- package/dist/auth/tanstack/index.js +32 -0
- package/dist/auth/tanstack/index.js.map +1 -0
- package/package.json +113 -4
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/auth/client/messages.ts
|
|
2
|
+
const englishMessages = {
|
|
3
|
+
signIn: "Sign in",
|
|
4
|
+
signUp: "Create account",
|
|
5
|
+
email: "Email address",
|
|
6
|
+
password: "Password",
|
|
7
|
+
name: "Name",
|
|
8
|
+
confirmPassword: "Confirm password",
|
|
9
|
+
submit: "Continue",
|
|
10
|
+
signingIn: "Signing in...",
|
|
11
|
+
signingUp: "Creating account...",
|
|
12
|
+
forgotPassword: "Forgot password?",
|
|
13
|
+
createAccount: "Create an account",
|
|
14
|
+
existingAccount: "Already have an account?",
|
|
15
|
+
noAccount: "Don't have an account?",
|
|
16
|
+
mfaTitle: "Verify your identity",
|
|
17
|
+
mfaDescription: "Enter your authentication code to continue.",
|
|
18
|
+
verificationCode: "Authentication code",
|
|
19
|
+
recoveryCode: "Recovery code",
|
|
20
|
+
verify: "Verify",
|
|
21
|
+
verifying: "Verifying...",
|
|
22
|
+
useRecoveryCode: "Use a recovery code",
|
|
23
|
+
useAuthenticator: "Use authenticator app",
|
|
24
|
+
usePasskey: "Continue with passkey",
|
|
25
|
+
passkeyUnavailable: "Passkeys are unavailable in this browser.",
|
|
26
|
+
loading: "Loading...",
|
|
27
|
+
signOut: "Sign out",
|
|
28
|
+
unexpectedError: "Something went wrong. Please try again.",
|
|
29
|
+
invalidCredentials: "The email or password is incorrect.",
|
|
30
|
+
passwordMismatch: "Passwords do not match.",
|
|
31
|
+
passwordRequired: "A password is required.",
|
|
32
|
+
requestPasswordReset: "Request password reset",
|
|
33
|
+
resetPassword: "Reset password",
|
|
34
|
+
newPassword: "New password",
|
|
35
|
+
sendResetLink: "Send reset link",
|
|
36
|
+
passwordResetSent: "Password reset link sent",
|
|
37
|
+
verificationSent: "Verification email sent",
|
|
38
|
+
verifyEmail: "Verify email",
|
|
39
|
+
changePassword: "Change password",
|
|
40
|
+
passwordChanged: "Password changed",
|
|
41
|
+
emailRequired: "An email address is required.",
|
|
42
|
+
nameRequired: "A name is required.",
|
|
43
|
+
authenticated: "You are signed in.",
|
|
44
|
+
mfaSettings: "Security settings",
|
|
45
|
+
addTotp: "Add authenticator",
|
|
46
|
+
addPasskey: "Add passkey",
|
|
47
|
+
removeFactor: "Remove",
|
|
48
|
+
recoveryCodes: "Recovery codes",
|
|
49
|
+
saveRecoveryCodes: "Save these codes somewhere safe.",
|
|
50
|
+
currentPassword: "Current password",
|
|
51
|
+
totpSecret: "Authenticator secret",
|
|
52
|
+
verifyTotp: "Verify authenticator",
|
|
53
|
+
cancel: "Cancel"
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Resolves a locale against the locales supplied by the application.
|
|
57
|
+
*
|
|
58
|
+
* The English locale is always supported.
|
|
59
|
+
* Unknown locales and locales without a supplied message set fall back to
|
|
60
|
+
* English.
|
|
61
|
+
*/
|
|
62
|
+
const getAuthLocale = (locale, availableMessages) => {
|
|
63
|
+
if (!locale || locale === "en") return "en";
|
|
64
|
+
if (availableMessages && Object.prototype.hasOwnProperty.call(availableMessages, locale)) return locale;
|
|
65
|
+
return "en";
|
|
66
|
+
};
|
|
67
|
+
function resolveAuthMessages(locale = "en", localeMessages, overrides) {
|
|
68
|
+
const englishOverrides = localeMessages?.en;
|
|
69
|
+
const localizedMessages = locale === "en" ? void 0 : localeMessages?.[locale];
|
|
70
|
+
return {
|
|
71
|
+
...englishMessages,
|
|
72
|
+
...englishOverrides,
|
|
73
|
+
...localizedMessages,
|
|
74
|
+
...overrides
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
exports.getAuthLocale = getAuthLocale;
|
|
78
|
+
exports.resolveAuthMessages = resolveAuthMessages;
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=messages.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.cjs","names":[],"sources":["../../../src/auth/client/messages.ts"],"sourcesContent":["export type AuthLocale<TCustomLocales extends string = never> =\n | \"en\"\n | TCustomLocales;\n\nexport type AuthMessages = {\n readonly signIn: string;\n readonly signUp: string;\n readonly email: string;\n readonly password: string;\n readonly name: string;\n readonly confirmPassword: string;\n readonly submit: string;\n readonly signingIn: string;\n readonly signingUp: string;\n readonly forgotPassword: string;\n readonly createAccount: string;\n readonly existingAccount: string;\n readonly noAccount: string;\n readonly mfaTitle: string;\n readonly mfaDescription: string;\n readonly verificationCode: string;\n readonly recoveryCode: string;\n readonly verify: string;\n readonly verifying: string;\n readonly useRecoveryCode: string;\n readonly useAuthenticator: string;\n readonly usePasskey: string;\n readonly passkeyUnavailable: string;\n readonly loading: string;\n readonly signOut: string;\n readonly unexpectedError: string;\n readonly invalidCredentials: string;\n readonly passwordMismatch: string;\n readonly passwordRequired: string;\n readonly requestPasswordReset: string;\n readonly resetPassword: string;\n readonly newPassword: string;\n readonly sendResetLink: string;\n readonly passwordResetSent: string;\n readonly verificationSent: string;\n readonly verifyEmail: string;\n readonly changePassword: string;\n readonly passwordChanged: string;\n readonly emailRequired: string;\n readonly nameRequired: string;\n readonly authenticated: string;\n readonly mfaSettings: string;\n readonly addTotp: string;\n readonly addPasskey: string;\n readonly removeFactor: string;\n readonly recoveryCodes: string;\n readonly saveRecoveryCodes: string;\n readonly currentPassword: string;\n readonly totpSecret: string;\n readonly verifyTotp: string;\n readonly cancel: string;\n};\n\n/**\n * A complete set of messages for every custom locale.\n *\n * English is optional because the built-in English messages are always\n * available as a fallback.\n *\n * Every custom locale must provide a complete AuthMessages object.\n */\nexport type AuthLocaleMessages<TCustomLocales extends string = never> = {\n readonly en?: AuthMessages;\n} & {\n readonly [Locale in TCustomLocales]: AuthMessages;\n};\n\n/**\n * Partial overrides for the currently resolved locale.\n */\nexport type AuthMessageOverrides = Partial<AuthMessages>;\n\nconst englishMessages: AuthMessages = {\n signIn: \"Sign in\",\n signUp: \"Create account\",\n email: \"Email address\",\n password: \"Password\",\n name: \"Name\",\n confirmPassword: \"Confirm password\",\n submit: \"Continue\",\n signingIn: \"Signing in...\",\n signingUp: \"Creating account...\",\n forgotPassword: \"Forgot password?\",\n createAccount: \"Create an account\",\n existingAccount: \"Already have an account?\",\n noAccount: \"Don't have an account?\",\n mfaTitle: \"Verify your identity\",\n mfaDescription: \"Enter your authentication code to continue.\",\n verificationCode: \"Authentication code\",\n recoveryCode: \"Recovery code\",\n verify: \"Verify\",\n verifying: \"Verifying...\",\n useRecoveryCode: \"Use a recovery code\",\n useAuthenticator: \"Use authenticator app\",\n usePasskey: \"Continue with passkey\",\n passkeyUnavailable: \"Passkeys are unavailable in this browser.\",\n loading: \"Loading...\",\n signOut: \"Sign out\",\n unexpectedError: \"Something went wrong. Please try again.\",\n invalidCredentials: \"The email or password is incorrect.\",\n passwordMismatch: \"Passwords do not match.\",\n passwordRequired: \"A password is required.\",\n requestPasswordReset: \"Request password reset\",\n resetPassword: \"Reset password\",\n newPassword: \"New password\",\n sendResetLink: \"Send reset link\",\n passwordResetSent: \"Password reset link sent\",\n verificationSent: \"Verification email sent\",\n verifyEmail: \"Verify email\",\n changePassword: \"Change password\",\n passwordChanged: \"Password changed\",\n emailRequired: \"An email address is required.\",\n nameRequired: \"A name is required.\",\n authenticated: \"You are signed in.\",\n mfaSettings: \"Security settings\",\n addTotp: \"Add authenticator\",\n addPasskey: \"Add passkey\",\n removeFactor: \"Remove\",\n recoveryCodes: \"Recovery codes\",\n saveRecoveryCodes: \"Save these codes somewhere safe.\",\n currentPassword: \"Current password\",\n totpSecret: \"Authenticator secret\",\n verifyTotp: \"Verify authenticator\",\n cancel: \"Cancel\",\n};\n\n/**\n * Resolves a locale against the locales supplied by the application.\n *\n * The English locale is always supported.\n * Unknown locales and locales without a supplied message set fall back to\n * English.\n */\nexport const getAuthLocale = <TCustomLocales extends string = never>(\n locale?: string | null,\n availableMessages?: AuthLocaleMessages<TCustomLocales>,\n): AuthLocale<TCustomLocales> => {\n if (!locale || locale === \"en\") {\n return \"en\";\n }\n\n if (\n availableMessages &&\n Object.prototype.hasOwnProperty.call(availableMessages, locale)\n ) {\n return locale as AuthLocale<TCustomLocales>;\n }\n\n return \"en\";\n};\n\n/**\n * Resolves the messages for the requested locale.\n *\n * Resolution order:\n * 1. Built-in English messages.\n * 2. Optional application-provided English messages.\n * 3. Messages for the requested custom locale.\n * 4. Optional per-message overrides.\n *\n * When custom locales are declared, their complete message sets are\n * required by the type system.\n */\nexport function resolveAuthMessages(): AuthMessages;\n\nexport function resolveAuthMessages(\n locale: \"en\",\n localeMessages?: AuthLocaleMessages,\n overrides?: AuthMessageOverrides,\n): AuthMessages;\n\nexport function resolveAuthMessages<TCustomLocales extends string>(\n locale: AuthLocale<TCustomLocales>,\n localeMessages: AuthLocaleMessages<TCustomLocales>,\n overrides?: AuthMessageOverrides,\n): AuthMessages;\n\nexport function resolveAuthMessages<TCustomLocales extends string>(\n locale: AuthLocale<TCustomLocales> = \"en\",\n localeMessages?: AuthLocaleMessages<TCustomLocales>,\n overrides?: AuthMessageOverrides,\n): AuthMessages {\n const englishOverrides = localeMessages?.en;\n\n const localizedMessages =\n locale === \"en\" ? undefined : localeMessages?.[locale as TCustomLocales];\n\n return {\n ...englishMessages,\n ...englishOverrides,\n ...localizedMessages,\n ...overrides,\n };\n}\n"],"mappings":";AA6EA,MAAM,kBAAgC;CACpC,QAAQ;CACR,QAAQ;CACR,OAAO;CACP,UAAU;CACV,MAAM;CACN,iBAAiB;CACjB,QAAQ;CACR,WAAW;CACX,WAAW;CACX,gBAAgB;CAChB,eAAe;CACf,iBAAiB;CACjB,WAAW;CACX,UAAU;CACV,gBAAgB;CAChB,kBAAkB;CAClB,cAAc;CACd,QAAQ;CACR,WAAW;CACX,iBAAiB;CACjB,kBAAkB;CAClB,YAAY;CACZ,oBAAoB;CACpB,SAAS;CACT,SAAS;CACT,iBAAiB;CACjB,oBAAoB;CACpB,kBAAkB;CAClB,kBAAkB;CAClB,sBAAsB;CACtB,eAAe;CACf,aAAa;CACb,eAAe;CACf,mBAAmB;CACnB,kBAAkB;CAClB,aAAa;CACb,gBAAgB;CAChB,iBAAiB;CACjB,eAAe;CACf,cAAc;CACd,eAAe;CACf,aAAa;CACb,SAAS;CACT,YAAY;CACZ,cAAc;CACd,eAAe;CACf,mBAAmB;CACnB,iBAAiB;CACjB,YAAY;CACZ,YAAY;CACZ,QAAQ;AACV;;;;;;;;AASA,MAAa,iBACX,QACA,sBAC+B;CAC/B,IAAI,CAAC,UAAU,WAAW,MACxB,OAAO;CAGT,IACE,qBACA,OAAO,UAAU,eAAe,KAAK,mBAAmB,MAAM,GAE9D,OAAO;CAGT,OAAO;AACT;AA4BA,SAAgB,oBACd,SAAqC,MACrC,gBACA,WACc;CACd,MAAM,mBAAmB,gBAAgB;CAEzC,MAAM,oBACJ,WAAW,OAAO,KAAA,IAAY,iBAAiB;CAEjD,OAAO;EACL,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;CACL;AACF"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export type AuthLocale<TCustomLocales extends string = never> = "en" | TCustomLocales;
|
|
2
|
+
export type AuthMessages = {
|
|
3
|
+
readonly signIn: string;
|
|
4
|
+
readonly signUp: string;
|
|
5
|
+
readonly email: string;
|
|
6
|
+
readonly password: string;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly confirmPassword: string;
|
|
9
|
+
readonly submit: string;
|
|
10
|
+
readonly signingIn: string;
|
|
11
|
+
readonly signingUp: string;
|
|
12
|
+
readonly forgotPassword: string;
|
|
13
|
+
readonly createAccount: string;
|
|
14
|
+
readonly existingAccount: string;
|
|
15
|
+
readonly noAccount: string;
|
|
16
|
+
readonly mfaTitle: string;
|
|
17
|
+
readonly mfaDescription: string;
|
|
18
|
+
readonly verificationCode: string;
|
|
19
|
+
readonly recoveryCode: string;
|
|
20
|
+
readonly verify: string;
|
|
21
|
+
readonly verifying: string;
|
|
22
|
+
readonly useRecoveryCode: string;
|
|
23
|
+
readonly useAuthenticator: string;
|
|
24
|
+
readonly usePasskey: string;
|
|
25
|
+
readonly passkeyUnavailable: string;
|
|
26
|
+
readonly loading: string;
|
|
27
|
+
readonly signOut: string;
|
|
28
|
+
readonly unexpectedError: string;
|
|
29
|
+
readonly invalidCredentials: string;
|
|
30
|
+
readonly passwordMismatch: string;
|
|
31
|
+
readonly passwordRequired: string;
|
|
32
|
+
readonly requestPasswordReset: string;
|
|
33
|
+
readonly resetPassword: string;
|
|
34
|
+
readonly newPassword: string;
|
|
35
|
+
readonly sendResetLink: string;
|
|
36
|
+
readonly passwordResetSent: string;
|
|
37
|
+
readonly verificationSent: string;
|
|
38
|
+
readonly verifyEmail: string;
|
|
39
|
+
readonly changePassword: string;
|
|
40
|
+
readonly passwordChanged: string;
|
|
41
|
+
readonly emailRequired: string;
|
|
42
|
+
readonly nameRequired: string;
|
|
43
|
+
readonly authenticated: string;
|
|
44
|
+
readonly mfaSettings: string;
|
|
45
|
+
readonly addTotp: string;
|
|
46
|
+
readonly addPasskey: string;
|
|
47
|
+
readonly removeFactor: string;
|
|
48
|
+
readonly recoveryCodes: string;
|
|
49
|
+
readonly saveRecoveryCodes: string;
|
|
50
|
+
readonly currentPassword: string;
|
|
51
|
+
readonly totpSecret: string;
|
|
52
|
+
readonly verifyTotp: string;
|
|
53
|
+
readonly cancel: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* A complete set of messages for every custom locale.
|
|
57
|
+
*
|
|
58
|
+
* English is optional because the built-in English messages are always
|
|
59
|
+
* available as a fallback.
|
|
60
|
+
*
|
|
61
|
+
* Every custom locale must provide a complete AuthMessages object.
|
|
62
|
+
*/
|
|
63
|
+
export type AuthLocaleMessages<TCustomLocales extends string = never> = {
|
|
64
|
+
readonly en?: AuthMessages;
|
|
65
|
+
} & { readonly [Locale in TCustomLocales]: AuthMessages; };
|
|
66
|
+
/**
|
|
67
|
+
* Partial overrides for the currently resolved locale.
|
|
68
|
+
*/
|
|
69
|
+
export type AuthMessageOverrides = Partial<AuthMessages>;
|
|
70
|
+
/**
|
|
71
|
+
* Resolves a locale against the locales supplied by the application.
|
|
72
|
+
*
|
|
73
|
+
* The English locale is always supported.
|
|
74
|
+
* Unknown locales and locales without a supplied message set fall back to
|
|
75
|
+
* English.
|
|
76
|
+
*/
|
|
77
|
+
export declare const getAuthLocale: <TCustomLocales extends string = never>(locale?: string | null, availableMessages?: AuthLocaleMessages<TCustomLocales>) => AuthLocale<TCustomLocales>;
|
|
78
|
+
/**
|
|
79
|
+
* Resolves the messages for the requested locale.
|
|
80
|
+
*
|
|
81
|
+
* Resolution order:
|
|
82
|
+
* 1. Built-in English messages.
|
|
83
|
+
* 2. Optional application-provided English messages.
|
|
84
|
+
* 3. Messages for the requested custom locale.
|
|
85
|
+
* 4. Optional per-message overrides.
|
|
86
|
+
*
|
|
87
|
+
* When custom locales are declared, their complete message sets are
|
|
88
|
+
* required by the type system.
|
|
89
|
+
*/
|
|
90
|
+
export declare function resolveAuthMessages(): AuthMessages;
|
|
91
|
+
export declare function resolveAuthMessages(locale: "en", localeMessages?: AuthLocaleMessages, overrides?: AuthMessageOverrides): AuthMessages;
|
|
92
|
+
export declare function resolveAuthMessages<TCustomLocales extends string>(locale: AuthLocale<TCustomLocales>, localeMessages: AuthLocaleMessages<TCustomLocales>, overrides?: AuthMessageOverrides): AuthMessages;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export type AuthLocale<TCustomLocales extends string = never> = "en" | TCustomLocales;
|
|
2
|
+
export type AuthMessages = {
|
|
3
|
+
readonly signIn: string;
|
|
4
|
+
readonly signUp: string;
|
|
5
|
+
readonly email: string;
|
|
6
|
+
readonly password: string;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly confirmPassword: string;
|
|
9
|
+
readonly submit: string;
|
|
10
|
+
readonly signingIn: string;
|
|
11
|
+
readonly signingUp: string;
|
|
12
|
+
readonly forgotPassword: string;
|
|
13
|
+
readonly createAccount: string;
|
|
14
|
+
readonly existingAccount: string;
|
|
15
|
+
readonly noAccount: string;
|
|
16
|
+
readonly mfaTitle: string;
|
|
17
|
+
readonly mfaDescription: string;
|
|
18
|
+
readonly verificationCode: string;
|
|
19
|
+
readonly recoveryCode: string;
|
|
20
|
+
readonly verify: string;
|
|
21
|
+
readonly verifying: string;
|
|
22
|
+
readonly useRecoveryCode: string;
|
|
23
|
+
readonly useAuthenticator: string;
|
|
24
|
+
readonly usePasskey: string;
|
|
25
|
+
readonly passkeyUnavailable: string;
|
|
26
|
+
readonly loading: string;
|
|
27
|
+
readonly signOut: string;
|
|
28
|
+
readonly unexpectedError: string;
|
|
29
|
+
readonly invalidCredentials: string;
|
|
30
|
+
readonly passwordMismatch: string;
|
|
31
|
+
readonly passwordRequired: string;
|
|
32
|
+
readonly requestPasswordReset: string;
|
|
33
|
+
readonly resetPassword: string;
|
|
34
|
+
readonly newPassword: string;
|
|
35
|
+
readonly sendResetLink: string;
|
|
36
|
+
readonly passwordResetSent: string;
|
|
37
|
+
readonly verificationSent: string;
|
|
38
|
+
readonly verifyEmail: string;
|
|
39
|
+
readonly changePassword: string;
|
|
40
|
+
readonly passwordChanged: string;
|
|
41
|
+
readonly emailRequired: string;
|
|
42
|
+
readonly nameRequired: string;
|
|
43
|
+
readonly authenticated: string;
|
|
44
|
+
readonly mfaSettings: string;
|
|
45
|
+
readonly addTotp: string;
|
|
46
|
+
readonly addPasskey: string;
|
|
47
|
+
readonly removeFactor: string;
|
|
48
|
+
readonly recoveryCodes: string;
|
|
49
|
+
readonly saveRecoveryCodes: string;
|
|
50
|
+
readonly currentPassword: string;
|
|
51
|
+
readonly totpSecret: string;
|
|
52
|
+
readonly verifyTotp: string;
|
|
53
|
+
readonly cancel: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* A complete set of messages for every custom locale.
|
|
57
|
+
*
|
|
58
|
+
* English is optional because the built-in English messages are always
|
|
59
|
+
* available as a fallback.
|
|
60
|
+
*
|
|
61
|
+
* Every custom locale must provide a complete AuthMessages object.
|
|
62
|
+
*/
|
|
63
|
+
export type AuthLocaleMessages<TCustomLocales extends string = never> = {
|
|
64
|
+
readonly en?: AuthMessages;
|
|
65
|
+
} & { readonly [Locale in TCustomLocales]: AuthMessages; };
|
|
66
|
+
/**
|
|
67
|
+
* Partial overrides for the currently resolved locale.
|
|
68
|
+
*/
|
|
69
|
+
export type AuthMessageOverrides = Partial<AuthMessages>;
|
|
70
|
+
/**
|
|
71
|
+
* Resolves a locale against the locales supplied by the application.
|
|
72
|
+
*
|
|
73
|
+
* The English locale is always supported.
|
|
74
|
+
* Unknown locales and locales without a supplied message set fall back to
|
|
75
|
+
* English.
|
|
76
|
+
*/
|
|
77
|
+
export declare const getAuthLocale: <TCustomLocales extends string = never>(locale?: string | null, availableMessages?: AuthLocaleMessages<TCustomLocales>) => AuthLocale<TCustomLocales>;
|
|
78
|
+
/**
|
|
79
|
+
* Resolves the messages for the requested locale.
|
|
80
|
+
*
|
|
81
|
+
* Resolution order:
|
|
82
|
+
* 1. Built-in English messages.
|
|
83
|
+
* 2. Optional application-provided English messages.
|
|
84
|
+
* 3. Messages for the requested custom locale.
|
|
85
|
+
* 4. Optional per-message overrides.
|
|
86
|
+
*
|
|
87
|
+
* When custom locales are declared, their complete message sets are
|
|
88
|
+
* required by the type system.
|
|
89
|
+
*/
|
|
90
|
+
export declare function resolveAuthMessages(): AuthMessages;
|
|
91
|
+
export declare function resolveAuthMessages(locale: "en", localeMessages?: AuthLocaleMessages, overrides?: AuthMessageOverrides): AuthMessages;
|
|
92
|
+
export declare function resolveAuthMessages<TCustomLocales extends string>(locale: AuthLocale<TCustomLocales>, localeMessages: AuthLocaleMessages<TCustomLocales>, overrides?: AuthMessageOverrides): AuthMessages;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// src/auth/client/messages.ts
|
|
2
|
+
const englishMessages = {
|
|
3
|
+
signIn: "Sign in",
|
|
4
|
+
signUp: "Create account",
|
|
5
|
+
email: "Email address",
|
|
6
|
+
password: "Password",
|
|
7
|
+
name: "Name",
|
|
8
|
+
confirmPassword: "Confirm password",
|
|
9
|
+
submit: "Continue",
|
|
10
|
+
signingIn: "Signing in...",
|
|
11
|
+
signingUp: "Creating account...",
|
|
12
|
+
forgotPassword: "Forgot password?",
|
|
13
|
+
createAccount: "Create an account",
|
|
14
|
+
existingAccount: "Already have an account?",
|
|
15
|
+
noAccount: "Don't have an account?",
|
|
16
|
+
mfaTitle: "Verify your identity",
|
|
17
|
+
mfaDescription: "Enter your authentication code to continue.",
|
|
18
|
+
verificationCode: "Authentication code",
|
|
19
|
+
recoveryCode: "Recovery code",
|
|
20
|
+
verify: "Verify",
|
|
21
|
+
verifying: "Verifying...",
|
|
22
|
+
useRecoveryCode: "Use a recovery code",
|
|
23
|
+
useAuthenticator: "Use authenticator app",
|
|
24
|
+
usePasskey: "Continue with passkey",
|
|
25
|
+
passkeyUnavailable: "Passkeys are unavailable in this browser.",
|
|
26
|
+
loading: "Loading...",
|
|
27
|
+
signOut: "Sign out",
|
|
28
|
+
unexpectedError: "Something went wrong. Please try again.",
|
|
29
|
+
invalidCredentials: "The email or password is incorrect.",
|
|
30
|
+
passwordMismatch: "Passwords do not match.",
|
|
31
|
+
passwordRequired: "A password is required.",
|
|
32
|
+
requestPasswordReset: "Request password reset",
|
|
33
|
+
resetPassword: "Reset password",
|
|
34
|
+
newPassword: "New password",
|
|
35
|
+
sendResetLink: "Send reset link",
|
|
36
|
+
passwordResetSent: "Password reset link sent",
|
|
37
|
+
verificationSent: "Verification email sent",
|
|
38
|
+
verifyEmail: "Verify email",
|
|
39
|
+
changePassword: "Change password",
|
|
40
|
+
passwordChanged: "Password changed",
|
|
41
|
+
emailRequired: "An email address is required.",
|
|
42
|
+
nameRequired: "A name is required.",
|
|
43
|
+
authenticated: "You are signed in.",
|
|
44
|
+
mfaSettings: "Security settings",
|
|
45
|
+
addTotp: "Add authenticator",
|
|
46
|
+
addPasskey: "Add passkey",
|
|
47
|
+
removeFactor: "Remove",
|
|
48
|
+
recoveryCodes: "Recovery codes",
|
|
49
|
+
saveRecoveryCodes: "Save these codes somewhere safe.",
|
|
50
|
+
currentPassword: "Current password",
|
|
51
|
+
totpSecret: "Authenticator secret",
|
|
52
|
+
verifyTotp: "Verify authenticator",
|
|
53
|
+
cancel: "Cancel"
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Resolves a locale against the locales supplied by the application.
|
|
57
|
+
*
|
|
58
|
+
* The English locale is always supported.
|
|
59
|
+
* Unknown locales and locales without a supplied message set fall back to
|
|
60
|
+
* English.
|
|
61
|
+
*/
|
|
62
|
+
const getAuthLocale = (locale, availableMessages) => {
|
|
63
|
+
if (!locale || locale === "en") return "en";
|
|
64
|
+
if (availableMessages && Object.prototype.hasOwnProperty.call(availableMessages, locale)) return locale;
|
|
65
|
+
return "en";
|
|
66
|
+
};
|
|
67
|
+
function resolveAuthMessages(locale = "en", localeMessages, overrides) {
|
|
68
|
+
const englishOverrides = localeMessages?.en;
|
|
69
|
+
const localizedMessages = locale === "en" ? void 0 : localeMessages?.[locale];
|
|
70
|
+
return {
|
|
71
|
+
...englishMessages,
|
|
72
|
+
...englishOverrides,
|
|
73
|
+
...localizedMessages,
|
|
74
|
+
...overrides
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export { getAuthLocale, resolveAuthMessages };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","names":[],"sources":["../../../src/auth/client/messages.ts"],"sourcesContent":["export type AuthLocale<TCustomLocales extends string = never> =\n | \"en\"\n | TCustomLocales;\n\nexport type AuthMessages = {\n readonly signIn: string;\n readonly signUp: string;\n readonly email: string;\n readonly password: string;\n readonly name: string;\n readonly confirmPassword: string;\n readonly submit: string;\n readonly signingIn: string;\n readonly signingUp: string;\n readonly forgotPassword: string;\n readonly createAccount: string;\n readonly existingAccount: string;\n readonly noAccount: string;\n readonly mfaTitle: string;\n readonly mfaDescription: string;\n readonly verificationCode: string;\n readonly recoveryCode: string;\n readonly verify: string;\n readonly verifying: string;\n readonly useRecoveryCode: string;\n readonly useAuthenticator: string;\n readonly usePasskey: string;\n readonly passkeyUnavailable: string;\n readonly loading: string;\n readonly signOut: string;\n readonly unexpectedError: string;\n readonly invalidCredentials: string;\n readonly passwordMismatch: string;\n readonly passwordRequired: string;\n readonly requestPasswordReset: string;\n readonly resetPassword: string;\n readonly newPassword: string;\n readonly sendResetLink: string;\n readonly passwordResetSent: string;\n readonly verificationSent: string;\n readonly verifyEmail: string;\n readonly changePassword: string;\n readonly passwordChanged: string;\n readonly emailRequired: string;\n readonly nameRequired: string;\n readonly authenticated: string;\n readonly mfaSettings: string;\n readonly addTotp: string;\n readonly addPasskey: string;\n readonly removeFactor: string;\n readonly recoveryCodes: string;\n readonly saveRecoveryCodes: string;\n readonly currentPassword: string;\n readonly totpSecret: string;\n readonly verifyTotp: string;\n readonly cancel: string;\n};\n\n/**\n * A complete set of messages for every custom locale.\n *\n * English is optional because the built-in English messages are always\n * available as a fallback.\n *\n * Every custom locale must provide a complete AuthMessages object.\n */\nexport type AuthLocaleMessages<TCustomLocales extends string = never> = {\n readonly en?: AuthMessages;\n} & {\n readonly [Locale in TCustomLocales]: AuthMessages;\n};\n\n/**\n * Partial overrides for the currently resolved locale.\n */\nexport type AuthMessageOverrides = Partial<AuthMessages>;\n\nconst englishMessages: AuthMessages = {\n signIn: \"Sign in\",\n signUp: \"Create account\",\n email: \"Email address\",\n password: \"Password\",\n name: \"Name\",\n confirmPassword: \"Confirm password\",\n submit: \"Continue\",\n signingIn: \"Signing in...\",\n signingUp: \"Creating account...\",\n forgotPassword: \"Forgot password?\",\n createAccount: \"Create an account\",\n existingAccount: \"Already have an account?\",\n noAccount: \"Don't have an account?\",\n mfaTitle: \"Verify your identity\",\n mfaDescription: \"Enter your authentication code to continue.\",\n verificationCode: \"Authentication code\",\n recoveryCode: \"Recovery code\",\n verify: \"Verify\",\n verifying: \"Verifying...\",\n useRecoveryCode: \"Use a recovery code\",\n useAuthenticator: \"Use authenticator app\",\n usePasskey: \"Continue with passkey\",\n passkeyUnavailable: \"Passkeys are unavailable in this browser.\",\n loading: \"Loading...\",\n signOut: \"Sign out\",\n unexpectedError: \"Something went wrong. Please try again.\",\n invalidCredentials: \"The email or password is incorrect.\",\n passwordMismatch: \"Passwords do not match.\",\n passwordRequired: \"A password is required.\",\n requestPasswordReset: \"Request password reset\",\n resetPassword: \"Reset password\",\n newPassword: \"New password\",\n sendResetLink: \"Send reset link\",\n passwordResetSent: \"Password reset link sent\",\n verificationSent: \"Verification email sent\",\n verifyEmail: \"Verify email\",\n changePassword: \"Change password\",\n passwordChanged: \"Password changed\",\n emailRequired: \"An email address is required.\",\n nameRequired: \"A name is required.\",\n authenticated: \"You are signed in.\",\n mfaSettings: \"Security settings\",\n addTotp: \"Add authenticator\",\n addPasskey: \"Add passkey\",\n removeFactor: \"Remove\",\n recoveryCodes: \"Recovery codes\",\n saveRecoveryCodes: \"Save these codes somewhere safe.\",\n currentPassword: \"Current password\",\n totpSecret: \"Authenticator secret\",\n verifyTotp: \"Verify authenticator\",\n cancel: \"Cancel\",\n};\n\n/**\n * Resolves a locale against the locales supplied by the application.\n *\n * The English locale is always supported.\n * Unknown locales and locales without a supplied message set fall back to\n * English.\n */\nexport const getAuthLocale = <TCustomLocales extends string = never>(\n locale?: string | null,\n availableMessages?: AuthLocaleMessages<TCustomLocales>,\n): AuthLocale<TCustomLocales> => {\n if (!locale || locale === \"en\") {\n return \"en\";\n }\n\n if (\n availableMessages &&\n Object.prototype.hasOwnProperty.call(availableMessages, locale)\n ) {\n return locale as AuthLocale<TCustomLocales>;\n }\n\n return \"en\";\n};\n\n/**\n * Resolves the messages for the requested locale.\n *\n * Resolution order:\n * 1. Built-in English messages.\n * 2. Optional application-provided English messages.\n * 3. Messages for the requested custom locale.\n * 4. Optional per-message overrides.\n *\n * When custom locales are declared, their complete message sets are\n * required by the type system.\n */\nexport function resolveAuthMessages(): AuthMessages;\n\nexport function resolveAuthMessages(\n locale: \"en\",\n localeMessages?: AuthLocaleMessages,\n overrides?: AuthMessageOverrides,\n): AuthMessages;\n\nexport function resolveAuthMessages<TCustomLocales extends string>(\n locale: AuthLocale<TCustomLocales>,\n localeMessages: AuthLocaleMessages<TCustomLocales>,\n overrides?: AuthMessageOverrides,\n): AuthMessages;\n\nexport function resolveAuthMessages<TCustomLocales extends string>(\n locale: AuthLocale<TCustomLocales> = \"en\",\n localeMessages?: AuthLocaleMessages<TCustomLocales>,\n overrides?: AuthMessageOverrides,\n): AuthMessages {\n const englishOverrides = localeMessages?.en;\n\n const localizedMessages =\n locale === \"en\" ? undefined : localeMessages?.[locale as TCustomLocales];\n\n return {\n ...englishMessages,\n ...englishOverrides,\n ...localizedMessages,\n ...overrides,\n };\n}\n"],"mappings":";AA6EA,MAAM,kBAAgC;CACpC,QAAQ;CACR,QAAQ;CACR,OAAO;CACP,UAAU;CACV,MAAM;CACN,iBAAiB;CACjB,QAAQ;CACR,WAAW;CACX,WAAW;CACX,gBAAgB;CAChB,eAAe;CACf,iBAAiB;CACjB,WAAW;CACX,UAAU;CACV,gBAAgB;CAChB,kBAAkB;CAClB,cAAc;CACd,QAAQ;CACR,WAAW;CACX,iBAAiB;CACjB,kBAAkB;CAClB,YAAY;CACZ,oBAAoB;CACpB,SAAS;CACT,SAAS;CACT,iBAAiB;CACjB,oBAAoB;CACpB,kBAAkB;CAClB,kBAAkB;CAClB,sBAAsB;CACtB,eAAe;CACf,aAAa;CACb,eAAe;CACf,mBAAmB;CACnB,kBAAkB;CAClB,aAAa;CACb,gBAAgB;CAChB,iBAAiB;CACjB,eAAe;CACf,cAAc;CACd,eAAe;CACf,aAAa;CACb,SAAS;CACT,YAAY;CACZ,cAAc;CACd,eAAe;CACf,mBAAmB;CACnB,iBAAiB;CACjB,YAAY;CACZ,YAAY;CACZ,QAAQ;AACV;;;;;;;;AASA,MAAa,iBACX,QACA,sBAC+B;CAC/B,IAAI,CAAC,UAAU,WAAW,MACxB,OAAO;CAGT,IACE,qBACA,OAAO,UAAU,eAAe,KAAK,mBAAmB,MAAM,GAE9D,OAAO;CAGT,OAAO;AACT;AA4BA,SAAgB,oBACd,SAAqC,MACrC,gBACA,WACc;CACd,MAAM,mBAAmB,gBAAgB;CAEzC,MAAM,oBACJ,WAAW,OAAO,KAAA,IAAY,iBAAiB;CAEjD,OAAO;EACL,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;CACL;AACF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
let _simplewebauthn_browser = require("@simplewebauthn/browser");
|
|
2
|
+
// src/auth/client/passkeys.ts
|
|
3
|
+
const defaultAdapter = {
|
|
4
|
+
startRegistration: (input) => (0, _simplewebauthn_browser.startRegistration)(input),
|
|
5
|
+
startAuthentication: (input) => (0, _simplewebauthn_browser.startAuthentication)(input)
|
|
6
|
+
};
|
|
7
|
+
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
8
|
+
const assertOptions = (optionsJSON) => {
|
|
9
|
+
if (!isRecord(optionsJSON) || typeof optionsJSON.challenge !== "string" || optionsJSON.challenge.length < 32) throw new Error("The server returned invalid WebAuthn options.");
|
|
10
|
+
};
|
|
11
|
+
const isSupported = () => {
|
|
12
|
+
if (typeof navigator === "undefined") return false;
|
|
13
|
+
return typeof navigator.credentials !== "undefined" && typeof navigator.credentials.create === "function" && typeof navigator.credentials.get === "function";
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Creates passkey browser helpers.
|
|
17
|
+
*
|
|
18
|
+
* The adapter argument makes the browser boundary independently testable.
|
|
19
|
+
* The default adapter uses @simplewebauthn/browser.
|
|
20
|
+
*/
|
|
21
|
+
const createPasskeyBrowserHelpers = (adapter = defaultAdapter) => ({
|
|
22
|
+
isSupported,
|
|
23
|
+
startRegistration: async (optionsJSON) => {
|
|
24
|
+
if (!isSupported()) throw new Error("Passkeys are not supported in this browser.");
|
|
25
|
+
assertOptions(optionsJSON);
|
|
26
|
+
return adapter.startRegistration({ optionsJSON });
|
|
27
|
+
},
|
|
28
|
+
startAuthentication: async (optionsJSON) => {
|
|
29
|
+
if (!isSupported()) throw new Error("Passkeys are not supported in this browser.");
|
|
30
|
+
assertOptions(optionsJSON);
|
|
31
|
+
return adapter.startAuthentication({ optionsJSON });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const defaultHelpers = createPasskeyBrowserHelpers();
|
|
35
|
+
const isPasskeySupported = () => defaultHelpers.isSupported();
|
|
36
|
+
const startPasskeyRegistration = (optionsJSON) => defaultHelpers.startRegistration(optionsJSON);
|
|
37
|
+
const startPasskeyAuthentication = (optionsJSON) => defaultHelpers.startAuthentication(optionsJSON);
|
|
38
|
+
exports.createPasskeyBrowserHelpers = createPasskeyBrowserHelpers;
|
|
39
|
+
exports.isPasskeySupported = isPasskeySupported;
|
|
40
|
+
exports.startPasskeyAuthentication = startPasskeyAuthentication;
|
|
41
|
+
exports.startPasskeyRegistration = startPasskeyRegistration;
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=passkeys.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"passkeys.cjs","names":["startRegistration","startAuthentication"],"sources":["../../../src/auth/client/passkeys.ts"],"sourcesContent":["import {\n startAuthentication,\n startRegistration,\n} from \"@simplewebauthn/browser\";\n\ntype StartRegistrationInput = Parameters<typeof startRegistration>[0];\ntype StartAuthenticationInput = Parameters<typeof startAuthentication>[0];\n\nexport type PasskeyBrowserAdapter = {\n readonly startRegistration: (\n input: StartRegistrationInput,\n ) => Promise<unknown>;\n\n readonly startAuthentication: (\n input: StartAuthenticationInput,\n ) => Promise<unknown>;\n};\n\nexport type PasskeyBrowserHelpers = {\n readonly startRegistration: (\n optionsJSON: Readonly<Record<string, unknown>>,\n ) => Promise<unknown>;\n\n readonly startAuthentication: (\n optionsJSON: Readonly<Record<string, unknown>>,\n ) => Promise<unknown>;\n\n readonly isSupported: () => boolean;\n};\n\nconst defaultAdapter: PasskeyBrowserAdapter = {\n startRegistration: (input) => startRegistration(input),\n startAuthentication: (input) => startAuthentication(input),\n};\n\nconst isRecord = (value: unknown): value is Readonly<Record<string, unknown>> =>\n typeof value === \"object\" && value !== null;\n\nconst assertOptions = (\n optionsJSON: Readonly<Record<string, unknown>>,\n): void => {\n if (\n !isRecord(optionsJSON) ||\n typeof optionsJSON.challenge !== \"string\" ||\n optionsJSON.challenge.length < 32\n ) {\n throw new Error(\"The server returned invalid WebAuthn options.\");\n }\n};\n\nconst isSupported = (): boolean => {\n if (typeof navigator === \"undefined\") {\n return false;\n }\n\n return (\n typeof navigator.credentials !== \"undefined\" &&\n typeof navigator.credentials.create === \"function\" &&\n typeof navigator.credentials.get === \"function\"\n );\n};\n\n/**\n * Creates passkey browser helpers.\n *\n * The adapter argument makes the browser boundary independently testable.\n * The default adapter uses @simplewebauthn/browser.\n */\nexport const createPasskeyBrowserHelpers = (\n adapter: PasskeyBrowserAdapter = defaultAdapter,\n): PasskeyBrowserHelpers => ({\n isSupported,\n\n startRegistration: async (optionsJSON) => {\n if (!isSupported()) {\n throw new Error(\"Passkeys are not supported in this browser.\");\n }\n\n assertOptions(optionsJSON);\n\n return adapter.startRegistration({\n optionsJSON:\n optionsJSON as unknown as StartRegistrationInput[\"optionsJSON\"],\n });\n },\n\n startAuthentication: async (optionsJSON) => {\n if (!isSupported()) {\n throw new Error(\"Passkeys are not supported in this browser.\");\n }\n\n assertOptions(optionsJSON);\n\n return adapter.startAuthentication({\n optionsJSON:\n optionsJSON as unknown as StartAuthenticationInput[\"optionsJSON\"],\n });\n },\n});\n\nconst defaultHelpers = createPasskeyBrowserHelpers();\n\nexport const isPasskeySupported = (): boolean => defaultHelpers.isSupported();\n\nexport const startPasskeyRegistration = (\n optionsJSON: Readonly<Record<string, unknown>>,\n): Promise<unknown> => defaultHelpers.startRegistration(optionsJSON);\n\nexport const startPasskeyAuthentication = (\n optionsJSON: Readonly<Record<string, unknown>>,\n): Promise<unknown> => defaultHelpers.startAuthentication(optionsJSON);\n"],"mappings":";;AA8BA,MAAM,iBAAwC;CAC5C,oBAAoB,WAAA,GAAUA,wBAAAA,kBAAAA,CAAkB,KAAK;CACrD,sBAAsB,WAAA,GAAUC,wBAAAA,oBAAAA,CAAoB,KAAK;AAC3D;AAEA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU;AAEzC,MAAM,iBACJ,gBACS;CACT,IACE,CAAC,SAAS,WAAW,KACrB,OAAO,YAAY,cAAc,YACjC,YAAY,UAAU,SAAS,IAE/B,MAAM,IAAI,MAAM,+CAA+C;AAEnE;AAEA,MAAM,oBAA6B;CACjC,IAAI,OAAO,cAAc,aACvB,OAAO;CAGT,OACE,OAAO,UAAU,gBAAgB,eACjC,OAAO,UAAU,YAAY,WAAW,cACxC,OAAO,UAAU,YAAY,QAAQ;AAEzC;;;;;;;AAQA,MAAa,+BACX,UAAiC,oBACN;CAC3B;CAEA,mBAAmB,OAAO,gBAAgB;EACxC,IAAI,CAAC,YAAY,GACf,MAAM,IAAI,MAAM,6CAA6C;EAG/D,cAAc,WAAW;EAEzB,OAAO,QAAQ,kBAAkB,EAE7B,YACJ,CAAC;CACH;CAEA,qBAAqB,OAAO,gBAAgB;EAC1C,IAAI,CAAC,YAAY,GACf,MAAM,IAAI,MAAM,6CAA6C;EAG/D,cAAc,WAAW;EAEzB,OAAO,QAAQ,oBAAoB,EAE/B,YACJ,CAAC;CACH;AACF;AAEA,MAAM,iBAAiB,4BAA4B;AAEnD,MAAa,2BAAoC,eAAe,YAAY;AAE5E,MAAa,4BACX,gBACqB,eAAe,kBAAkB,WAAW;AAEnE,MAAa,8BACX,gBACqB,eAAe,oBAAoB,WAAW"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { startAuthentication, startRegistration } from "@simplewebauthn/browser";
|
|
2
|
+
type StartRegistrationInput = Parameters<typeof startRegistration>[0];
|
|
3
|
+
type StartAuthenticationInput = Parameters<typeof startAuthentication>[0];
|
|
4
|
+
export type PasskeyBrowserAdapter = {
|
|
5
|
+
readonly startRegistration: (input: StartRegistrationInput) => Promise<unknown>;
|
|
6
|
+
readonly startAuthentication: (input: StartAuthenticationInput) => Promise<unknown>;
|
|
7
|
+
};
|
|
8
|
+
export type PasskeyBrowserHelpers = {
|
|
9
|
+
readonly startRegistration: (optionsJSON: Readonly<Record<string, unknown>>) => Promise<unknown>;
|
|
10
|
+
readonly startAuthentication: (optionsJSON: Readonly<Record<string, unknown>>) => Promise<unknown>;
|
|
11
|
+
readonly isSupported: () => boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Creates passkey browser helpers.
|
|
15
|
+
*
|
|
16
|
+
* The adapter argument makes the browser boundary independently testable.
|
|
17
|
+
* The default adapter uses @simplewebauthn/browser.
|
|
18
|
+
*/
|
|
19
|
+
export declare const createPasskeyBrowserHelpers: (adapter?: PasskeyBrowserAdapter) => PasskeyBrowserHelpers;
|
|
20
|
+
export declare const isPasskeySupported: () => boolean;
|
|
21
|
+
export declare const startPasskeyRegistration: (optionsJSON: Readonly<Record<string, unknown>>) => Promise<unknown>;
|
|
22
|
+
export declare const startPasskeyAuthentication: (optionsJSON: Readonly<Record<string, unknown>>) => Promise<unknown>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { startAuthentication, startRegistration } from "@simplewebauthn/browser";
|
|
2
|
+
type StartRegistrationInput = Parameters<typeof startRegistration>[0];
|
|
3
|
+
type StartAuthenticationInput = Parameters<typeof startAuthentication>[0];
|
|
4
|
+
export type PasskeyBrowserAdapter = {
|
|
5
|
+
readonly startRegistration: (input: StartRegistrationInput) => Promise<unknown>;
|
|
6
|
+
readonly startAuthentication: (input: StartAuthenticationInput) => Promise<unknown>;
|
|
7
|
+
};
|
|
8
|
+
export type PasskeyBrowserHelpers = {
|
|
9
|
+
readonly startRegistration: (optionsJSON: Readonly<Record<string, unknown>>) => Promise<unknown>;
|
|
10
|
+
readonly startAuthentication: (optionsJSON: Readonly<Record<string, unknown>>) => Promise<unknown>;
|
|
11
|
+
readonly isSupported: () => boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Creates passkey browser helpers.
|
|
15
|
+
*
|
|
16
|
+
* The adapter argument makes the browser boundary independently testable.
|
|
17
|
+
* The default adapter uses @simplewebauthn/browser.
|
|
18
|
+
*/
|
|
19
|
+
export declare const createPasskeyBrowserHelpers: (adapter?: PasskeyBrowserAdapter) => PasskeyBrowserHelpers;
|
|
20
|
+
export declare const isPasskeySupported: () => boolean;
|
|
21
|
+
export declare const startPasskeyRegistration: (optionsJSON: Readonly<Record<string, unknown>>) => Promise<unknown>;
|
|
22
|
+
export declare const startPasskeyAuthentication: (optionsJSON: Readonly<Record<string, unknown>>) => Promise<unknown>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { startAuthentication, startRegistration } from "@simplewebauthn/browser";
|
|
2
|
+
// src/auth/client/passkeys.ts
|
|
3
|
+
const defaultAdapter = {
|
|
4
|
+
startRegistration: (input) => startRegistration(input),
|
|
5
|
+
startAuthentication: (input) => startAuthentication(input)
|
|
6
|
+
};
|
|
7
|
+
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
8
|
+
const assertOptions = (optionsJSON) => {
|
|
9
|
+
if (!isRecord(optionsJSON) || typeof optionsJSON.challenge !== "string" || optionsJSON.challenge.length < 32) throw new Error("The server returned invalid WebAuthn options.");
|
|
10
|
+
};
|
|
11
|
+
const isSupported = () => {
|
|
12
|
+
if (typeof navigator === "undefined") return false;
|
|
13
|
+
return typeof navigator.credentials !== "undefined" && typeof navigator.credentials.create === "function" && typeof navigator.credentials.get === "function";
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Creates passkey browser helpers.
|
|
17
|
+
*
|
|
18
|
+
* The adapter argument makes the browser boundary independently testable.
|
|
19
|
+
* The default adapter uses @simplewebauthn/browser.
|
|
20
|
+
*/
|
|
21
|
+
const createPasskeyBrowserHelpers = (adapter = defaultAdapter) => ({
|
|
22
|
+
isSupported,
|
|
23
|
+
startRegistration: async (optionsJSON) => {
|
|
24
|
+
if (!isSupported()) throw new Error("Passkeys are not supported in this browser.");
|
|
25
|
+
assertOptions(optionsJSON);
|
|
26
|
+
return adapter.startRegistration({ optionsJSON });
|
|
27
|
+
},
|
|
28
|
+
startAuthentication: async (optionsJSON) => {
|
|
29
|
+
if (!isSupported()) throw new Error("Passkeys are not supported in this browser.");
|
|
30
|
+
assertOptions(optionsJSON);
|
|
31
|
+
return adapter.startAuthentication({ optionsJSON });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const defaultHelpers = createPasskeyBrowserHelpers();
|
|
35
|
+
const isPasskeySupported = () => defaultHelpers.isSupported();
|
|
36
|
+
const startPasskeyRegistration = (optionsJSON) => defaultHelpers.startRegistration(optionsJSON);
|
|
37
|
+
const startPasskeyAuthentication = (optionsJSON) => defaultHelpers.startAuthentication(optionsJSON);
|
|
38
|
+
export { createPasskeyBrowserHelpers, isPasskeySupported, startPasskeyAuthentication, startPasskeyRegistration };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=passkeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"passkeys.js","names":[],"sources":["../../../src/auth/client/passkeys.ts"],"sourcesContent":["import {\n startAuthentication,\n startRegistration,\n} from \"@simplewebauthn/browser\";\n\ntype StartRegistrationInput = Parameters<typeof startRegistration>[0];\ntype StartAuthenticationInput = Parameters<typeof startAuthentication>[0];\n\nexport type PasskeyBrowserAdapter = {\n readonly startRegistration: (\n input: StartRegistrationInput,\n ) => Promise<unknown>;\n\n readonly startAuthentication: (\n input: StartAuthenticationInput,\n ) => Promise<unknown>;\n};\n\nexport type PasskeyBrowserHelpers = {\n readonly startRegistration: (\n optionsJSON: Readonly<Record<string, unknown>>,\n ) => Promise<unknown>;\n\n readonly startAuthentication: (\n optionsJSON: Readonly<Record<string, unknown>>,\n ) => Promise<unknown>;\n\n readonly isSupported: () => boolean;\n};\n\nconst defaultAdapter: PasskeyBrowserAdapter = {\n startRegistration: (input) => startRegistration(input),\n startAuthentication: (input) => startAuthentication(input),\n};\n\nconst isRecord = (value: unknown): value is Readonly<Record<string, unknown>> =>\n typeof value === \"object\" && value !== null;\n\nconst assertOptions = (\n optionsJSON: Readonly<Record<string, unknown>>,\n): void => {\n if (\n !isRecord(optionsJSON) ||\n typeof optionsJSON.challenge !== \"string\" ||\n optionsJSON.challenge.length < 32\n ) {\n throw new Error(\"The server returned invalid WebAuthn options.\");\n }\n};\n\nconst isSupported = (): boolean => {\n if (typeof navigator === \"undefined\") {\n return false;\n }\n\n return (\n typeof navigator.credentials !== \"undefined\" &&\n typeof navigator.credentials.create === \"function\" &&\n typeof navigator.credentials.get === \"function\"\n );\n};\n\n/**\n * Creates passkey browser helpers.\n *\n * The adapter argument makes the browser boundary independently testable.\n * The default adapter uses @simplewebauthn/browser.\n */\nexport const createPasskeyBrowserHelpers = (\n adapter: PasskeyBrowserAdapter = defaultAdapter,\n): PasskeyBrowserHelpers => ({\n isSupported,\n\n startRegistration: async (optionsJSON) => {\n if (!isSupported()) {\n throw new Error(\"Passkeys are not supported in this browser.\");\n }\n\n assertOptions(optionsJSON);\n\n return adapter.startRegistration({\n optionsJSON:\n optionsJSON as unknown as StartRegistrationInput[\"optionsJSON\"],\n });\n },\n\n startAuthentication: async (optionsJSON) => {\n if (!isSupported()) {\n throw new Error(\"Passkeys are not supported in this browser.\");\n }\n\n assertOptions(optionsJSON);\n\n return adapter.startAuthentication({\n optionsJSON:\n optionsJSON as unknown as StartAuthenticationInput[\"optionsJSON\"],\n });\n },\n});\n\nconst defaultHelpers = createPasskeyBrowserHelpers();\n\nexport const isPasskeySupported = (): boolean => defaultHelpers.isSupported();\n\nexport const startPasskeyRegistration = (\n optionsJSON: Readonly<Record<string, unknown>>,\n): Promise<unknown> => defaultHelpers.startRegistration(optionsJSON);\n\nexport const startPasskeyAuthentication = (\n optionsJSON: Readonly<Record<string, unknown>>,\n): Promise<unknown> => defaultHelpers.startAuthentication(optionsJSON);\n"],"mappings":";;AA8BA,MAAM,iBAAwC;CAC5C,oBAAoB,UAAU,kBAAkB,KAAK;CACrD,sBAAsB,UAAU,oBAAoB,KAAK;AAC3D;AAEA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU;AAEzC,MAAM,iBACJ,gBACS;CACT,IACE,CAAC,SAAS,WAAW,KACrB,OAAO,YAAY,cAAc,YACjC,YAAY,UAAU,SAAS,IAE/B,MAAM,IAAI,MAAM,+CAA+C;AAEnE;AAEA,MAAM,oBAA6B;CACjC,IAAI,OAAO,cAAc,aACvB,OAAO;CAGT,OACE,OAAO,UAAU,gBAAgB,eACjC,OAAO,UAAU,YAAY,WAAW,cACxC,OAAO,UAAU,YAAY,QAAQ;AAEzC;;;;;;;AAQA,MAAa,+BACX,UAAiC,oBACN;CAC3B;CAEA,mBAAmB,OAAO,gBAAgB;EACxC,IAAI,CAAC,YAAY,GACf,MAAM,IAAI,MAAM,6CAA6C;EAG/D,cAAc,WAAW;EAEzB,OAAO,QAAQ,kBAAkB,EAE7B,YACJ,CAAC;CACH;CAEA,qBAAqB,OAAO,gBAAgB;EAC1C,IAAI,CAAC,YAAY,GACf,MAAM,IAAI,MAAM,6CAA6C;EAG/D,cAAc,WAAW;EAEzB,OAAO,QAAQ,oBAAoB,EAE/B,YACJ,CAAC;CACH;AACF;AAEA,MAAM,iBAAiB,4BAA4B;AAEnD,MAAa,2BAAoC,eAAe,YAAY;AAE5E,MAAa,4BACX,gBACqB,eAAe,kBAAkB,WAAW;AAEnE,MAAa,8BACX,gBACqB,eAAe,oBAAoB,WAAW"}
|