orbital-ds 0.27.0 → 0.29.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.
Files changed (76) hide show
  1. package/AGENTS.md +289 -273
  2. package/components.manifest.json +550 -8
  3. package/dist/hooks/use-ds-messages.d.ts +225 -0
  4. package/dist/lib/auth-better-auth.d.ts +29 -0
  5. package/dist/lib/auth-better-auth.js +60 -0
  6. package/dist/lib/auth-flow.d.ts +59 -0
  7. package/dist/lib/auth-flow.js +135 -0
  8. package/dist/lib/auth-providers.d.ts +194 -0
  9. package/dist/lib/auth-providers.js +64 -0
  10. package/dist/lib/auth.d.ts +68 -0
  11. package/dist/lib/auth.js +110 -0
  12. package/dist/lib/i18n.d.ts +225 -0
  13. package/dist/lib/i18n.js +684 -3
  14. package/dist/styles.css +467 -3
  15. package/dist/themes/lagoon.css +8 -8
  16. package/dist/themes/lagoon.meta.json +3 -2
  17. package/dist/themes/lagoon.scoped.css +8 -8
  18. package/dist/ui/auth-backdrop.d.ts +20 -0
  19. package/dist/ui/auth-backdrop.js +137 -0
  20. package/dist/ui/auth-form.d.ts +107 -0
  21. package/dist/ui/auth-form.js +526 -0
  22. package/dist/ui/auth-layout.d.ts +70 -0
  23. package/dist/ui/auth-layout.js +283 -0
  24. package/dist/ui/auth-parts.d.ts +43 -0
  25. package/dist/ui/auth-parts.js +159 -0
  26. package/dist/ui/auth-status.d.ts +23 -0
  27. package/dist/ui/auth-status.js +99 -0
  28. package/dist/ui/command-palette.d.ts +36 -0
  29. package/dist/ui/command-palette.js +111 -0
  30. package/dist/ui/connected-accounts.d.ts +25 -0
  31. package/dist/ui/connected-accounts.js +89 -0
  32. package/dist/ui/dropzone.d.ts +3 -1
  33. package/dist/ui/dropzone.js +3 -1
  34. package/dist/ui/empty-state.d.ts +10 -1
  35. package/dist/ui/empty-state.js +28 -7
  36. package/dist/ui/error-page.d.ts +28 -0
  37. package/dist/ui/error-page.js +138 -0
  38. package/dist/ui/file-upload.d.ts +42 -0
  39. package/dist/ui/file-upload.js +175 -0
  40. package/dist/ui/filter-bar.js +8 -0
  41. package/dist/ui/icon-tile.d.ts +1 -1
  42. package/dist/ui/input-otp.js +2 -1
  43. package/dist/ui/mfa-challenge.d.ts +33 -0
  44. package/dist/ui/mfa-challenge.js +214 -0
  45. package/dist/ui/mfa-setup.d.ts +29 -0
  46. package/dist/ui/mfa-setup.js +196 -0
  47. package/dist/ui/oauth-consent.d.ts +54 -0
  48. package/dist/ui/oauth-consent.js +208 -0
  49. package/dist/ui/page-header.js +13 -2
  50. package/dist/ui/page-loader.d.ts +23 -0
  51. package/dist/ui/page-loader.js +163 -0
  52. package/dist/ui/passkey-list.d.ts +17 -0
  53. package/dist/ui/passkey-list.js +112 -0
  54. package/dist/ui/password-input.d.ts +5 -0
  55. package/dist/ui/password-input.js +77 -0
  56. package/dist/ui/session-list.d.ts +19 -0
  57. package/dist/ui/session-list.js +70 -0
  58. package/dist/ui/session-timeout.d.ts +13 -0
  59. package/dist/ui/session-timeout.js +87 -0
  60. package/dist/ui/sidebar.d.ts +12 -4
  61. package/dist/ui/sidebar.js +35 -5
  62. package/dist/ui/sign-out-dialog.d.ts +17 -0
  63. package/dist/ui/sign-out-dialog.js +82 -0
  64. package/dist/ui/stat-group.d.ts +1 -1
  65. package/dist/ui/stat-group.js +6 -2
  66. package/dist/ui/stat.d.ts +24 -5
  67. package/dist/ui/stat.js +124 -19
  68. package/dist/ui/status-badge.d.ts +1 -1
  69. package/docs/CONTRACT.md +1 -1
  70. package/docs/designer/patrones.md +21 -0
  71. package/docs/designer/revision.md +8 -0
  72. package/package.json +187 -187
  73. package/scripts/brand-core.d.mts +2 -0
  74. package/scripts/brand-core.mjs +21 -1
  75. package/scripts/doctor.mjs +3 -0
  76. package/scripts/init.mjs +7 -3
@@ -20,6 +20,11 @@ declare const DsMessagesContext: React.Context<{
20
20
  carouselNext: string;
21
21
  commandTitle: string;
22
22
  commandDescription: string;
23
+ commandPaletteGoPlaceholder: string;
24
+ commandPaletteActionsPlaceholder: string;
25
+ commandPaletteSearchPlaceholder: string;
26
+ commandPaletteEmpty: string;
27
+ commandPaletteLoading: string;
23
28
  scrollToEnd: string;
24
29
  scrollToStart: string;
25
30
  sidebarToggle: string;
@@ -39,6 +44,12 @@ declare const DsMessagesContext: React.Context<{
39
44
  dateRangePlaceholder: string;
40
45
  dropzoneTitle: string;
41
46
  dropzoneHint: string;
47
+ fileUploadAttach: string;
48
+ fileUploadUploading: string;
49
+ fileUploadDone: string;
50
+ fileUploadFailed: string;
51
+ fileUploadRetry: string;
52
+ fileUploadRemove: string;
42
53
  dropzoneTooLarge: string;
43
54
  dropzoneWrongType: string;
44
55
  dataTableSearch: string;
@@ -78,6 +89,24 @@ declare const DsMessagesContext: React.Context<{
78
89
  emptyErrorBody: string;
79
90
  emptyForbiddenTitle: string;
80
91
  emptyForbiddenBody: string;
92
+ errorPageNotFoundTitle: string;
93
+ errorPageNotFoundBody: string;
94
+ errorPageServerTitle: string;
95
+ errorPageServerBody: string;
96
+ errorPageOfflineTitle: string;
97
+ errorPageOfflineBody: string;
98
+ errorPageMaintenanceTitle: string;
99
+ errorPageMaintenanceBody: string;
100
+ errorPageNotFoundPlayfulTitle: string;
101
+ errorPageNotFoundPlayfulBody: string;
102
+ errorPageForbiddenPlayfulTitle: string;
103
+ errorPageForbiddenPlayfulBody: string;
104
+ errorPageServerPlayfulTitle: string;
105
+ errorPageServerPlayfulBody: string;
106
+ errorPageOfflinePlayfulTitle: string;
107
+ errorPageOfflinePlayfulBody: string;
108
+ errorPageMaintenancePlayfulTitle: string;
109
+ errorPageMaintenancePlayfulBody: string;
81
110
  confirmActionConfirm: string;
82
111
  confirmActionCancel: string;
83
112
  confirmActionTyped: string;
@@ -97,6 +126,7 @@ declare const DsMessagesContext: React.Context<{
97
126
  statIncrease: string;
98
127
  statDecrease: string;
99
128
  statNoChange: string;
129
+ statOfTarget: string;
100
130
  notificationsForYou: string;
101
131
  notificationsGeneral: string;
102
132
  notificationsHistory: string;
@@ -146,6 +176,201 @@ declare const DsMessagesContext: React.Context<{
146
176
  weekLabel: string;
147
177
  weekPrevious: string;
148
178
  weekNext: string;
179
+ authOr: string;
180
+ authContinueWith: string;
181
+ authLastUsed: string;
182
+ authPasskey: string;
183
+ authShowPassword: string;
184
+ authHidePassword: string;
185
+ authCapsLock: string;
186
+ authSignInTitle: string;
187
+ authSignInDescription: string;
188
+ authSignUpTitle: string;
189
+ authSignUpDescription: string;
190
+ authMagicLinkTitle: string;
191
+ authMagicLinkDescription: string;
192
+ authEmailCodeTitle: string;
193
+ authEmailCodeDescription: string;
194
+ authSsoTitle: string;
195
+ authSsoDescription: string;
196
+ authSsoOrgDescription: string;
197
+ authForgotTitle: string;
198
+ authForgotDescription: string;
199
+ authResetTitle: string;
200
+ authResetDescription: string;
201
+ authSignInSubmit: string;
202
+ authSignUpSubmit: string;
203
+ authSendLink: string;
204
+ authSendCode: string;
205
+ authSsoSubmit: string;
206
+ authSendReset: string;
207
+ authResetSubmit: string;
208
+ authContinue: string;
209
+ authEmail: string;
210
+ authUsername: string;
211
+ authEmailOrUsername: string;
212
+ authName: string;
213
+ authPassword: string;
214
+ authNewPassword: string;
215
+ authConfirmPassword: string;
216
+ authWorkEmail: string;
217
+ authOrganization: string;
218
+ authRemember: string;
219
+ authForgotLink: string;
220
+ authTermsAccept: string;
221
+ authTermsLink: string;
222
+ authAnd: string;
223
+ authPrivacyLink: string;
224
+ authRequired: string;
225
+ authInvalidEmail: string;
226
+ authPasswordMismatch: string;
227
+ authTermsRequired: string;
228
+ authPasswordRules: string;
229
+ authRuleMinLength: string;
230
+ authRuleLowercase: string;
231
+ authRuleUppercase: string;
232
+ authRuleNumber: string;
233
+ authRuleSymbol: string;
234
+ authRuleMet: string;
235
+ authRulePending: string;
236
+ authCheckEmailTitle: string;
237
+ authLinkSentBody: string;
238
+ authResetSentBody: string;
239
+ authCodeSentBody: string;
240
+ authResend: string;
241
+ authResendIn: string;
242
+ authUseDifferentEmail: string;
243
+ authCode: string;
244
+ authVerify: string;
245
+ authChooseOrganization: string;
246
+ authSsoRedirecting: string;
247
+ authChange: string;
248
+ authUseSso: string;
249
+ authBackToSignIn: string;
250
+ authNoAccount: string;
251
+ authSignUpLink: string;
252
+ authNoAccess: string;
253
+ authRequestAccessLink: string;
254
+ authHaveAccount: string;
255
+ authSignInLink: string;
256
+ authMfaTitle: string;
257
+ authMfaTotpBody: string;
258
+ authMfaSmsBody: string;
259
+ authMfaEmailBody: string;
260
+ authMfaBackupBody: string;
261
+ authMfaPasskeyBody: string;
262
+ authMfaPasskeyAction: string;
263
+ authMfaTrustDevice: string;
264
+ authMfaTryAnother: string;
265
+ authMfaMethodTotp: string;
266
+ authMfaMethodSms: string;
267
+ authMfaMethodEmail: string;
268
+ authMfaMethodBackup: string;
269
+ authMfaMethodPasskey: string;
270
+ authBackupCode: string;
271
+ authBack: string;
272
+ authCancel: string;
273
+ authMfaBackupTitle: string;
274
+ authMfaBackupSetupBody: string;
275
+ authCopyAll: string;
276
+ authDownload: string;
277
+ authMfaBackupConfirm: string;
278
+ authDone: string;
279
+ authMfaSetupTotpTitle: string;
280
+ authMfaSetupTotpStep1: string;
281
+ authMfaSetupManual: string;
282
+ authMfaSetupTotpStep2: string;
283
+ authActivate: string;
284
+ authMfaSetupSmsTitle: string;
285
+ authMfaSetupSmsBody: string;
286
+ authPhone: string;
287
+ authSignedOutTitle: string;
288
+ authSignedOutBody: string;
289
+ authSignInAgain: string;
290
+ authSessionExpiredTitle: string;
291
+ authSessionExpiredBody: string;
292
+ authVerifyEmailTitle: string;
293
+ authVerifyEmailBody: string;
294
+ authEmailVerifiedTitle: string;
295
+ authEmailVerifiedBody: string;
296
+ authPasswordChangedTitle: string;
297
+ authPasswordChangedBody: string;
298
+ authAccountLockedTitle: string;
299
+ authAccountLockedBody: string;
300
+ authResetPasswordAction: string;
301
+ authLinkExpiredTitle: string;
302
+ authLinkExpiredBody: string;
303
+ authRequestNewLink: string;
304
+ authAccessDeniedTitle: string;
305
+ authAccessDeniedBody: string;
306
+ authBackHome: string;
307
+ authSignOutTitle: string;
308
+ authSignOutBody: string;
309
+ authSignOutAllDevices: string;
310
+ authSignOut: string;
311
+ authSessionTimeoutTitle: string;
312
+ authSessionTimeoutBody: string;
313
+ authSessionTimeoutLeft: string;
314
+ authSocialDescription: string;
315
+ authContinueWithEmail: string;
316
+ authOauthTitle: string;
317
+ authOauthBody: string;
318
+ authOauthMcpTitle: string;
319
+ authOauthMcpBody: string;
320
+ authOauthDeviceTitle: string;
321
+ authOauthDeviceBody: string;
322
+ authOauthDeviceCode: string;
323
+ authOauthDeviceConfirm: string;
324
+ authOauthVerified: string;
325
+ authOauthSwitchAccount: string;
326
+ authOauthUnverified: string;
327
+ authOauthPermissions: string;
328
+ authOauthSensitive: string;
329
+ authOauthAllow: string;
330
+ authOauthDeny: string;
331
+ authOauthRedirect: string;
332
+ authOauthRevokeNote: string;
333
+ authConnConnected: string;
334
+ authConnExpired: string;
335
+ authConnError: string;
336
+ authConnNotConnected: string;
337
+ authConnConnect: string;
338
+ authConnPending: string;
339
+ authConnReconnect: string;
340
+ authConnDisconnect: string;
341
+ authConnLastMethod: string;
342
+ authSessionActiveNow: string;
343
+ authSessionLastActive: string;
344
+ authSessionUnknownDevice: string;
345
+ authSessionCurrent: string;
346
+ authSessionRevoke: string;
347
+ authSessionRevokeOthers: string;
348
+ authPasskeysAdd: string;
349
+ authPasskeysEmptyTitle: string;
350
+ authPasskeysEmptyBody: string;
351
+ authPasskeysCreated: string;
352
+ authPasskeysLastUsed: string;
353
+ authPasskeysName: string;
354
+ authPasskeysSave: string;
355
+ authPasskeysRename: string;
356
+ authPasskeysDelete: string;
357
+ authPasskeysSynced: string;
358
+ authStaySignedIn: string;
359
+ authErrorInvalidCredentials: string;
360
+ authErrorAccountLocked: string;
361
+ authErrorTooManyAttempts: string;
362
+ authErrorEmailNotVerified: string;
363
+ authErrorEmailTaken: string;
364
+ authErrorWeakPassword: string;
365
+ authErrorPasswordReused: string;
366
+ authErrorInvalidCode: string;
367
+ authErrorExpiredCode: string;
368
+ authErrorLinkExpired: string;
369
+ authErrorSessionExpired: string;
370
+ authErrorProviderFailed: string;
371
+ authErrorPasskeyFailed: string;
372
+ authErrorNetwork: string;
373
+ authErrorUnknown: string;
149
374
  }>;
150
375
  /** Textos de los componentes en el idioma activo. */
151
376
  declare function useDsMessages(): DsMessages;
@@ -0,0 +1,29 @@
1
+ import { AuthErrorCode } from './auth.js';
2
+ import 'react';
3
+ import './i18n.js';
4
+
5
+ /** Error tal como lo devuelve Better Auth (cliente o API). */
6
+ type BetterAuthError = {
7
+ code?: string;
8
+ message?: string;
9
+ status?: number;
10
+ statusText?: string;
11
+ } | null | undefined;
12
+ /** Traduce un error de Better Auth a `AuthErrorCode` (desconocido → `unknown`). */
13
+ declare function betterAuthErrorCode(error: BetterAuthError): AuthErrorCode;
14
+ /**
15
+ * Convierte una respuesta `{ data, error }` en lo que esperan los callbacks de orbital-ds:
16
+ * sin error → `undefined` (el componente sigue su flujo); con error → `{ error: AuthErrorCode }`.
17
+ * Si la cuenta tiene 2FA, Better Auth responde `twoFactorRedirect`: llévala a MfaChallenge.
18
+ */
19
+ declare function fromBetterAuth(result: {
20
+ error?: BetterAuthError;
21
+ } | null | undefined): {
22
+ error: AuthErrorCode;
23
+ } | undefined;
24
+ /** ¿Pide Better Auth el segundo factor? (`data.twoFactorRedirect`). */
25
+ declare function needsTwoFactor(result: {
26
+ data?: unknown;
27
+ } | null | undefined): boolean;
28
+
29
+ export { type BetterAuthError, betterAuthErrorCode, fromBetterAuth, needsTwoFactor };
@@ -0,0 +1,60 @@
1
+ const CODES = {
2
+ INVALID_EMAIL_OR_PASSWORD: "invalid-credentials",
3
+ INVALID_USERNAME_OR_PASSWORD: "invalid-credentials",
4
+ INVALID_PASSWORD: "invalid-credentials",
5
+ INVALID_EMAIL: "invalid-credentials",
6
+ USER_NOT_FOUND: "invalid-credentials",
7
+ CREDENTIAL_ACCOUNT_NOT_FOUND: "invalid-credentials",
8
+ USER_ALREADY_EXISTS: "email-taken",
9
+ USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: "email-taken",
10
+ USERNAME_IS_ALREADY_TAKEN: "email-taken",
11
+ EMAIL_NOT_VERIFIED: "email-not-verified",
12
+ PASSWORD_TOO_SHORT: "weak-password",
13
+ PASSWORD_TOO_LONG: "weak-password",
14
+ PASSWORD_COMPROMISED: "weak-password",
15
+ BANNED_USER: "account-locked",
16
+ USER_BANNED: "account-locked",
17
+ INVALID_TOKEN: "link-expired",
18
+ TOKEN_EXPIRED: "link-expired",
19
+ INVALID_CODE: "invalid-code",
20
+ INVALID_OTP: "invalid-code",
21
+ INVALID_TWO_FACTOR_CODE: "invalid-code",
22
+ INVALID_BACKUP_CODE: "invalid-code",
23
+ OTP_EXPIRED: "expired-code",
24
+ TOO_MANY_ATTEMPTS: "too-many-attempts",
25
+ TOO_MANY_ATTEMPTS_REQUEST_NEW_CODE: "too-many-attempts",
26
+ SESSION_EXPIRED: "session-expired",
27
+ FAILED_TO_GET_SESSION: "session-expired",
28
+ PROVIDER_NOT_FOUND: "provider-failed",
29
+ FAILED_TO_GET_USER_INFO: "provider-failed",
30
+ SOCIAL_ACCOUNT_ALREADY_LINKED: "provider-failed",
31
+ ACCOUNT_NOT_LINKED: "provider-failed",
32
+ SSO_PROVIDER_NOT_FOUND: "provider-failed",
33
+ AUTHENTICATION_FAILED: "passkey-failed",
34
+ CHALLENGE_NOT_FOUND: "passkey-failed",
35
+ PASSKEY_NOT_FOUND: "passkey-failed",
36
+ FAILED_TO_VERIFY_REGISTRATION: "passkey-failed"
37
+ };
38
+ function betterAuthErrorCode(error) {
39
+ if (!error) return "unknown";
40
+ if (error.status === 429) return "too-many-attempts";
41
+ const code = error.code?.toUpperCase();
42
+ if (code && CODES[code]) return CODES[code];
43
+ if (code?.includes("PASSKEY")) return "passkey-failed";
44
+ if (code?.includes("OTP") || code?.includes("CODE")) return "invalid-code";
45
+ if (error.status === 401) return "invalid-credentials";
46
+ if (error.status === 0 || error.status === void 0 && !code) return "network";
47
+ return "unknown";
48
+ }
49
+ function fromBetterAuth(result) {
50
+ return result?.error ? { error: betterAuthErrorCode(result.error) } : void 0;
51
+ }
52
+ function needsTwoFactor(result) {
53
+ const data = result?.data;
54
+ return !!data?.twoFactorRedirect;
55
+ }
56
+ export {
57
+ betterAuthErrorCode,
58
+ fromBetterAuth,
59
+ needsTwoFactor
60
+ };
@@ -0,0 +1,59 @@
1
+ import { AuthProviderId } from './auth-providers.js';
2
+ import { MfaMethod } from './auth.js';
3
+ import 'react';
4
+ import './i18n.js';
5
+
6
+ type AuthFlowPreset = "standard" | "social" | "passwordless" | "partner" | "enterprise" | "hybrid" | "sso-only";
7
+ type AuthAudience = "internal" | "external" | "mixed";
8
+ type AuthSignUp = "open" | "invite" | "none";
9
+ type AuthSignInMethod = "password" | "social" | "passkey" | "magic-link" | "email-code" | "sso";
10
+ type AuthFlowConfig = {
11
+ preset: AuthFlowPreset;
12
+ /** Para quién es la puerta: plantilla (internal), gente de fuera (external) o las dos (mixed). */
13
+ audience: AuthAudience;
14
+ /** Métodos ofrecidos para entrar, en orden de preferencia. */
15
+ methods: AuthSignInMethod[];
16
+ /** Proveedores sociales (ids de Better Auth). */
17
+ providers: AuthProviderId[];
18
+ /** Preset de AuthForm para la pantalla de entrada. */
19
+ signIn: "sign-in" | "social" | "magic-link" | "email-code" | "sso";
20
+ /** Identificador primero (home realm discovery). */
21
+ identifierFirst: boolean;
22
+ /** Dominios de la plantilla (sin @): su correo va al SSO corporativo. Obligatorio en `mixed`. */
23
+ internalDomains: string[];
24
+ /** Cómo se crean las cuentas: registro abierto, por invitación o desde el directorio (SSO). */
25
+ signUp: AuthSignUp;
26
+ mfa: {
27
+ required: boolean;
28
+ methods: MfaMethod[];
29
+ };
30
+ /** Props de AuthLayout. */
31
+ layout: {
32
+ preset?: "centered" | "split" | "cover" | "banner" | "minimal";
33
+ surface?: "solid" | "glass" | "elevated" | "plain";
34
+ shape?: "rounded" | "soft" | "sharp";
35
+ backdrop?: "none" | "dots" | "grid" | "aurora" | "mesh" | "glow" | "rings" | "beams" | "image";
36
+ /** Cristal esmerilado sobre el fondo («mesh + glass»). */
37
+ backdropGlass?: boolean;
38
+ motion?: "full" | "entrance" | "off";
39
+ mediaTint?: "none" | "brand" | "duotone";
40
+ };
41
+ };
42
+ type FlowDefaults = Omit<AuthFlowConfig, "preset">;
43
+ declare const AUTH_FLOW_PRESETS: Record<AuthFlowPreset, FlowDefaults>;
44
+ /** Flujo a partir de un preset; cualquier valor explícito lo sobrescribe. */
45
+ declare function defineAuthFlow(preset: AuthFlowPreset, overrides?: Partial<Omit<AuthFlowConfig, "preset">>): AuthFlowConfig;
46
+ /** ¿Es de la plantilla? Compara el dominio del correo (y sus subdominios) con `internalDomains`. */
47
+ declare function isInternalIdentifier(flow: Pick<AuthFlowConfig, "internalDomains">, identifier: string): boolean;
48
+ /**
49
+ * Ruta por defecto para `AuthForm onIdentify`: la plantilla (o una puerta interna) va al SSO; el
50
+ * resto, al primer método de cuenta propia del flujo. Para dominios de clientes con su propio SSO
51
+ * (enterprise, partner), la app consulta antes a su proveedor y cae aquí si no lo encuentra.
52
+ */
53
+ declare function routeAuthIdentifier(flow: Pick<AuthFlowConfig, "audience" | "methods" | "internalDomains">, identifier: string): {
54
+ method: "password" | "sso" | "passkey" | "email-code" | "magic-link";
55
+ };
56
+ /** Problemas de un flujo (vacío = válido). Mensajes en inglés, como `dsWarn`. */
57
+ declare function validateAuthFlow(flow: AuthFlowConfig): string[];
58
+
59
+ export { AUTH_FLOW_PRESETS, type AuthAudience, type AuthFlowConfig, type AuthFlowPreset, type AuthSignInMethod, type AuthSignUp, defineAuthFlow, isInternalIdentifier, routeAuthIdentifier, validateAuthFlow };
@@ -0,0 +1,135 @@
1
+ const AUTH_FLOW_PRESETS = {
2
+ standard: {
3
+ audience: "external",
4
+ methods: ["password", "social", "passkey"],
5
+ providers: ["google", "microsoft"],
6
+ signIn: "sign-in",
7
+ identifierFirst: false,
8
+ internalDomains: [],
9
+ signUp: "open",
10
+ mfa: { required: false, methods: ["totp", "passkey", "backup-code"] },
11
+ layout: { preset: "centered", surface: "solid", backdrop: "glow", motion: "full" }
12
+ },
13
+ social: {
14
+ audience: "external",
15
+ methods: ["social", "passkey", "email-code"],
16
+ providers: ["google", "apple", "microsoft"],
17
+ signIn: "social",
18
+ identifierFirst: false,
19
+ internalDomains: [],
20
+ signUp: "open",
21
+ mfa: { required: false, methods: ["passkey"] },
22
+ layout: { preset: "split", surface: "plain", motion: "full" }
23
+ },
24
+ passwordless: {
25
+ audience: "external",
26
+ methods: ["email-code", "passkey", "social"],
27
+ providers: ["google"],
28
+ signIn: "email-code",
29
+ identifierFirst: false,
30
+ internalDomains: [],
31
+ signUp: "open",
32
+ mfa: { required: false, methods: ["passkey"] },
33
+ layout: { preset: "centered", surface: "glass", backdrop: "aurora", motion: "full" }
34
+ },
35
+ partner: {
36
+ audience: "external",
37
+ methods: ["email-code", "password", "passkey", "sso"],
38
+ providers: [],
39
+ signIn: "sign-in",
40
+ identifierFirst: true,
41
+ internalDomains: [],
42
+ signUp: "invite",
43
+ mfa: { required: true, methods: ["totp", "passkey", "backup-code"] },
44
+ layout: { preset: "centered", surface: "elevated", backdrop: "dots", motion: "entrance" }
45
+ },
46
+ enterprise: {
47
+ audience: "external",
48
+ methods: ["sso", "passkey", "password"],
49
+ providers: [],
50
+ signIn: "sign-in",
51
+ identifierFirst: true,
52
+ internalDomains: [],
53
+ signUp: "none",
54
+ mfa: { required: true, methods: ["totp", "passkey", "backup-code"] },
55
+ layout: { preset: "split", surface: "plain", motion: "entrance" }
56
+ },
57
+ hybrid: {
58
+ audience: "mixed",
59
+ methods: ["sso", "email-code", "password", "passkey"],
60
+ providers: [],
61
+ signIn: "sign-in",
62
+ identifierFirst: true,
63
+ internalDomains: [],
64
+ signUp: "invite",
65
+ mfa: { required: true, methods: ["totp", "passkey", "backup-code"] },
66
+ layout: { preset: "split", surface: "plain", motion: "entrance" }
67
+ },
68
+ "sso-only": {
69
+ audience: "internal",
70
+ methods: ["sso"],
71
+ providers: [],
72
+ signIn: "sso",
73
+ identifierFirst: false,
74
+ internalDomains: [],
75
+ signUp: "none",
76
+ mfa: { required: false, methods: [] },
77
+ layout: { preset: "minimal", surface: "plain", motion: "entrance" }
78
+ }
79
+ };
80
+ function defineAuthFlow(preset, overrides = {}) {
81
+ const base = AUTH_FLOW_PRESETS[preset];
82
+ return {
83
+ ...base,
84
+ ...overrides,
85
+ preset,
86
+ mfa: { ...base.mfa, ...overrides.mfa },
87
+ layout: { ...base.layout, ...overrides.layout }
88
+ };
89
+ }
90
+ function isInternalIdentifier(flow, identifier) {
91
+ const domain = identifier.trim().toLowerCase().split("@")[1];
92
+ if (!domain) return false;
93
+ return flow.internalDomains.some((d) => {
94
+ const base = d.trim().toLowerCase().replace(/^@/, "");
95
+ return domain === base || domain.endsWith(`.${base}`);
96
+ });
97
+ }
98
+ function routeAuthIdentifier(flow, identifier) {
99
+ if (flow.methods.includes("sso") && (flow.audience === "internal" || isInternalIdentifier(flow, identifier))) return { method: "sso" };
100
+ const own = flow.methods.find(
101
+ (m) => m === "password" || m === "email-code" || m === "magic-link" || m === "passkey"
102
+ );
103
+ return { method: own ?? "sso" };
104
+ }
105
+ function validateAuthFlow(flow) {
106
+ const issues = [];
107
+ const has = (m) => flow.methods.includes(m);
108
+ const ownAccount = has("password") || has("email-code") || has("magic-link") || has("social") || has("passkey");
109
+ if (!flow.methods.length) issues.push("No sign-in method.");
110
+ if (has("social") && !flow.providers.length) issues.push('"social" method without `providers`.');
111
+ if (flow.signIn === "social" && !has("social") && !has("passkey")) issues.push('signIn "social" needs the "social" or "passkey" method.');
112
+ if (flow.signIn === "sso" && !has("sso")) issues.push('signIn "sso" needs the "sso" method.');
113
+ if (flow.identifierFirst && flow.methods.length < 2) issues.push("identifierFirst only makes sense with two or more methods.");
114
+ if (flow.mfa.required && !flow.mfa.methods.length) issues.push("MFA required without `mfa.methods`.");
115
+ if (flow.mfa.required && !flow.mfa.methods.includes("backup-code")) issues.push("MFA required without backup codes: people could be locked out.");
116
+ if (flow.signUp !== "none" && flow.methods.length === 1 && has("sso")) issues.push("Sign-up with SSO only: accounts come from the identity provider.");
117
+ if (flow.audience === "internal" && flow.signUp === "open") issues.push("Internal audience with open sign-up: staff accounts come from the directory.");
118
+ if (flow.audience === "internal" && !has("sso")) issues.push('Internal audience without the "sso" method.');
119
+ if (flow.audience === "external" && !ownAccount) issues.push("External audience with SSO only: outside people rarely have your identity provider.");
120
+ if (flow.audience === "mixed") {
121
+ if (!has("sso")) issues.push('Mixed audience without the "sso" method for staff.');
122
+ if (!ownAccount) issues.push("Mixed audience without a method for external people.");
123
+ if (!flow.internalDomains.length) issues.push("Mixed audience without `internalDomains`: staff cannot be routed to SSO.");
124
+ if (!flow.identifierFirst) issues.push("Mixed audience works best with identifierFirst: the email decides the door.");
125
+ }
126
+ if (flow.audience === "external" && flow.internalDomains.length) issues.push('`internalDomains` on an external audience: use "mixed" if staff also sign in here.');
127
+ return issues;
128
+ }
129
+ export {
130
+ AUTH_FLOW_PRESETS,
131
+ defineAuthFlow,
132
+ isInternalIdentifier,
133
+ routeAuthIdentifier,
134
+ validateAuthFlow
135
+ };