@meindesk/auth-config 0.1.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/dist/index.d.ts +3188 -0
- package/dist/index.js +595 -0
- package/dist/index.js.map +1 -0
- package/package.json +33 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// src/schema.ts
|
|
4
|
+
var EXPERIENCE_IDS = [
|
|
5
|
+
"signIn",
|
|
6
|
+
"signUp",
|
|
7
|
+
"forgotPassword",
|
|
8
|
+
"resetPassword",
|
|
9
|
+
"magicLink",
|
|
10
|
+
"emailVerification",
|
|
11
|
+
"mfa",
|
|
12
|
+
"organizationSelection",
|
|
13
|
+
"organizationCreation"
|
|
14
|
+
];
|
|
15
|
+
var PROVIDER_IDS = [
|
|
16
|
+
"google",
|
|
17
|
+
"github",
|
|
18
|
+
"discord",
|
|
19
|
+
"apple",
|
|
20
|
+
"facebook",
|
|
21
|
+
"microsoft"
|
|
22
|
+
];
|
|
23
|
+
var PROFILE_FIELD_IDS = [
|
|
24
|
+
"email",
|
|
25
|
+
"password",
|
|
26
|
+
"firstName",
|
|
27
|
+
"lastName",
|
|
28
|
+
"username",
|
|
29
|
+
"phoneNumber"
|
|
30
|
+
];
|
|
31
|
+
var RADIUS_OPTIONS = ["small", "medium", "large"];
|
|
32
|
+
var CARD_STYLES = ["flat", "bordered", "elevated"];
|
|
33
|
+
var LAYOUT_OPTIONS = ["centered", "minimal"];
|
|
34
|
+
var PROVIDER_POSITIONS = ["before", "after"];
|
|
35
|
+
var LOGO_ALIGNMENTS = ["left", "center", "right"];
|
|
36
|
+
var profileFieldSchema = z.object({
|
|
37
|
+
id: z.enum(PROFILE_FIELD_IDS),
|
|
38
|
+
enabled: z.boolean().default(true),
|
|
39
|
+
required: z.boolean().default(true),
|
|
40
|
+
showLabel: z.boolean().default(true),
|
|
41
|
+
label: z.string().default(""),
|
|
42
|
+
placeholder: z.string().optional(),
|
|
43
|
+
showPasswordToggle: z.boolean().optional()
|
|
44
|
+
});
|
|
45
|
+
var experienceCopySchema = z.object({
|
|
46
|
+
title: z.string().default(""),
|
|
47
|
+
subtitle: z.string().default(""),
|
|
48
|
+
buttonText: z.string().default("Continue"),
|
|
49
|
+
loadingText: z.string().default("Please wait\u2026"),
|
|
50
|
+
showSignUpLink: z.boolean().optional(),
|
|
51
|
+
signUpLinkText: z.string().optional(),
|
|
52
|
+
showSignInLink: z.boolean().optional(),
|
|
53
|
+
signInLinkText: z.string().optional(),
|
|
54
|
+
forgotPasswordEnabled: z.boolean().optional(),
|
|
55
|
+
forgotPasswordText: z.string().optional(),
|
|
56
|
+
dividerEnabled: z.boolean().optional(),
|
|
57
|
+
dividerText: z.string().optional(),
|
|
58
|
+
fields: z.array(profileFieldSchema).optional()
|
|
59
|
+
});
|
|
60
|
+
var providerConfigSchema = z.object({
|
|
61
|
+
id: z.enum(PROVIDER_IDS),
|
|
62
|
+
enabled: z.boolean().default(false),
|
|
63
|
+
buttonLabel: z.string().optional(),
|
|
64
|
+
position: z.enum(PROVIDER_POSITIONS).default("before")
|
|
65
|
+
});
|
|
66
|
+
var methodsSchema = z.object({
|
|
67
|
+
emailPassword: z.boolean().default(true),
|
|
68
|
+
magicLink: z.boolean().default(false),
|
|
69
|
+
passkeys: z.boolean().default(false),
|
|
70
|
+
phone: z.boolean().default(false)
|
|
71
|
+
});
|
|
72
|
+
var appearanceSchema = z.object({
|
|
73
|
+
primaryColor: z.string().default("#0f172a"),
|
|
74
|
+
backgroundColor: z.string().default("#ffffff"),
|
|
75
|
+
foregroundColor: z.string().default("#0f172a"),
|
|
76
|
+
mutedColor: z.string().default("#64748b"),
|
|
77
|
+
borderColor: z.string().default("#e2e8f0"),
|
|
78
|
+
surfaceColor: z.string().default("#f8fafc"),
|
|
79
|
+
radius: z.enum(RADIUS_OPTIONS).default("medium"),
|
|
80
|
+
fontFamily: z.string().default(
|
|
81
|
+
'ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif'
|
|
82
|
+
),
|
|
83
|
+
headingSize: z.string().default("1.35rem"),
|
|
84
|
+
bodySize: z.string().default("0.925rem"),
|
|
85
|
+
logoUrl: z.string().nullable().default(null),
|
|
86
|
+
logoSize: z.number().int().positive().default(40),
|
|
87
|
+
logoAlignment: z.enum(LOGO_ALIGNMENTS).default("center"),
|
|
88
|
+
showAppName: z.boolean().default(true),
|
|
89
|
+
showMeindeskBranding: z.boolean().default(true),
|
|
90
|
+
cardStyle: z.enum(CARD_STYLES).default("elevated"),
|
|
91
|
+
layout: z.enum(LAYOUT_OPTIONS).default("centered")
|
|
92
|
+
});
|
|
93
|
+
var experiencesSchema = z.object({
|
|
94
|
+
signIn: experienceCopySchema,
|
|
95
|
+
signUp: experienceCopySchema,
|
|
96
|
+
forgotPassword: experienceCopySchema,
|
|
97
|
+
resetPassword: experienceCopySchema,
|
|
98
|
+
magicLink: experienceCopySchema,
|
|
99
|
+
emailVerification: experienceCopySchema,
|
|
100
|
+
mfa: experienceCopySchema,
|
|
101
|
+
organizationSelection: experienceCopySchema,
|
|
102
|
+
organizationCreation: experienceCopySchema
|
|
103
|
+
});
|
|
104
|
+
var authExperienceConfigSchema = z.object({
|
|
105
|
+
version: z.literal(1).default(1),
|
|
106
|
+
applicationName: z.string().optional(),
|
|
107
|
+
methods: methodsSchema,
|
|
108
|
+
providers: z.array(providerConfigSchema),
|
|
109
|
+
appearance: appearanceSchema,
|
|
110
|
+
experiences: experiencesSchema
|
|
111
|
+
});
|
|
112
|
+
var FORM_TYPE_TO_EXPERIENCE = {
|
|
113
|
+
sign_in: "signIn",
|
|
114
|
+
sign_up: "signUp",
|
|
115
|
+
forgot_password: "forgotPassword",
|
|
116
|
+
reset_password: "resetPassword",
|
|
117
|
+
magic_link: "magicLink",
|
|
118
|
+
email_verification: "emailVerification",
|
|
119
|
+
mfa: "mfa",
|
|
120
|
+
organization_selection: "organizationSelection",
|
|
121
|
+
organization_creation: "organizationCreation"
|
|
122
|
+
};
|
|
123
|
+
var EXPERIENCE_TO_FORM_TYPE = {
|
|
124
|
+
signIn: "sign_in",
|
|
125
|
+
signUp: "sign_up",
|
|
126
|
+
forgotPassword: "forgot_password",
|
|
127
|
+
resetPassword: "reset_password",
|
|
128
|
+
magicLink: "magic_link",
|
|
129
|
+
emailVerification: "email_verification",
|
|
130
|
+
mfa: "mfa",
|
|
131
|
+
organizationSelection: "organization_selection",
|
|
132
|
+
organizationCreation: "organization_creation"
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// src/defaults.ts
|
|
136
|
+
function field(id, overrides = {}) {
|
|
137
|
+
const labels = {
|
|
138
|
+
email: "Email address",
|
|
139
|
+
password: "Password",
|
|
140
|
+
firstName: "First name",
|
|
141
|
+
lastName: "Last name",
|
|
142
|
+
username: "Username",
|
|
143
|
+
phoneNumber: "Phone number"
|
|
144
|
+
};
|
|
145
|
+
const placeholders = {
|
|
146
|
+
email: "you@example.com",
|
|
147
|
+
password: "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",
|
|
148
|
+
firstName: "",
|
|
149
|
+
lastName: "",
|
|
150
|
+
username: "",
|
|
151
|
+
phoneNumber: "+1 555 000 0000"
|
|
152
|
+
};
|
|
153
|
+
return {
|
|
154
|
+
id,
|
|
155
|
+
enabled: true,
|
|
156
|
+
required: true,
|
|
157
|
+
showLabel: true,
|
|
158
|
+
label: labels[id],
|
|
159
|
+
placeholder: placeholders[id] ?? "",
|
|
160
|
+
showPasswordToggle: id === "password" ? true : void 0,
|
|
161
|
+
...overrides
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
var defaultSignIn = {
|
|
165
|
+
title: "Welcome back",
|
|
166
|
+
subtitle: "Sign in to continue",
|
|
167
|
+
buttonText: "Continue",
|
|
168
|
+
loadingText: "Signing in\u2026",
|
|
169
|
+
showSignUpLink: true,
|
|
170
|
+
signUpLinkText: "Don't have an account? Sign up",
|
|
171
|
+
forgotPasswordEnabled: true,
|
|
172
|
+
forgotPasswordText: "Forgot password?",
|
|
173
|
+
dividerEnabled: true,
|
|
174
|
+
dividerText: "OR",
|
|
175
|
+
fields: [
|
|
176
|
+
field("email"),
|
|
177
|
+
field("password", { showPasswordToggle: true })
|
|
178
|
+
]
|
|
179
|
+
};
|
|
180
|
+
var defaultSignUp = {
|
|
181
|
+
title: "Create your account",
|
|
182
|
+
subtitle: "Sign up to get started",
|
|
183
|
+
buttonText: "Continue",
|
|
184
|
+
loadingText: "Creating account\u2026",
|
|
185
|
+
showSignInLink: true,
|
|
186
|
+
signInLinkText: "Already have an account? Sign in",
|
|
187
|
+
dividerEnabled: true,
|
|
188
|
+
dividerText: "OR",
|
|
189
|
+
fields: [
|
|
190
|
+
field("firstName"),
|
|
191
|
+
field("lastName"),
|
|
192
|
+
field("email"),
|
|
193
|
+
field("password", { showPasswordToggle: true }),
|
|
194
|
+
field("username", { enabled: false, required: false }),
|
|
195
|
+
field("phoneNumber", { enabled: false, required: false })
|
|
196
|
+
]
|
|
197
|
+
};
|
|
198
|
+
var defaultForgotPassword = {
|
|
199
|
+
title: "Forgot password?",
|
|
200
|
+
subtitle: "Enter your email and we'll send a reset link",
|
|
201
|
+
buttonText: "Continue",
|
|
202
|
+
loadingText: "Sending\u2026",
|
|
203
|
+
showSignInLink: true,
|
|
204
|
+
signInLinkText: "Back to sign in",
|
|
205
|
+
fields: [field("email")]
|
|
206
|
+
};
|
|
207
|
+
var defaultResetPassword = {
|
|
208
|
+
title: "Reset password",
|
|
209
|
+
subtitle: "Choose a new password for your account",
|
|
210
|
+
buttonText: "Reset password",
|
|
211
|
+
loadingText: "Resetting\u2026",
|
|
212
|
+
fields: [
|
|
213
|
+
field("password", { label: "New password", showPasswordToggle: true })
|
|
214
|
+
]
|
|
215
|
+
};
|
|
216
|
+
var defaultMagicLink = {
|
|
217
|
+
title: "Continue with email",
|
|
218
|
+
subtitle: "We'll email you a magic link for a password-free sign in",
|
|
219
|
+
buttonText: "Continue with Magic Link",
|
|
220
|
+
loadingText: "Sending link\u2026",
|
|
221
|
+
showSignInLink: true,
|
|
222
|
+
signInLinkText: "Back to sign in",
|
|
223
|
+
fields: [field("email")]
|
|
224
|
+
};
|
|
225
|
+
var defaultEmailVerification = {
|
|
226
|
+
title: "Verify your email",
|
|
227
|
+
subtitle: "Enter the verification code we sent to your email",
|
|
228
|
+
buttonText: "Verify",
|
|
229
|
+
loadingText: "Verifying\u2026",
|
|
230
|
+
fields: []
|
|
231
|
+
};
|
|
232
|
+
var defaultMfa = {
|
|
233
|
+
title: "Two-factor authentication",
|
|
234
|
+
subtitle: "Enter the code from your authenticator app",
|
|
235
|
+
buttonText: "Verify",
|
|
236
|
+
loadingText: "Verifying\u2026",
|
|
237
|
+
fields: []
|
|
238
|
+
};
|
|
239
|
+
var defaultOrgSelection = {
|
|
240
|
+
title: "Choose an organization",
|
|
241
|
+
subtitle: "Select which organization to continue with",
|
|
242
|
+
buttonText: "Continue",
|
|
243
|
+
loadingText: "Loading\u2026",
|
|
244
|
+
fields: []
|
|
245
|
+
};
|
|
246
|
+
var defaultOrgCreation = {
|
|
247
|
+
title: "Create an organization",
|
|
248
|
+
subtitle: "Set up a new organization for your team",
|
|
249
|
+
buttonText: "Create organization",
|
|
250
|
+
loadingText: "Creating\u2026",
|
|
251
|
+
fields: []
|
|
252
|
+
};
|
|
253
|
+
var DEFAULT_EXPERIENCES = {
|
|
254
|
+
signIn: defaultSignIn,
|
|
255
|
+
signUp: defaultSignUp,
|
|
256
|
+
forgotPassword: defaultForgotPassword,
|
|
257
|
+
resetPassword: defaultResetPassword,
|
|
258
|
+
magicLink: defaultMagicLink,
|
|
259
|
+
emailVerification: defaultEmailVerification,
|
|
260
|
+
mfa: defaultMfa,
|
|
261
|
+
organizationSelection: defaultOrgSelection,
|
|
262
|
+
organizationCreation: defaultOrgCreation
|
|
263
|
+
};
|
|
264
|
+
var DEFAULT_APPEARANCE = {
|
|
265
|
+
primaryColor: "#0f172a",
|
|
266
|
+
backgroundColor: "#ffffff",
|
|
267
|
+
foregroundColor: "#0f172a",
|
|
268
|
+
mutedColor: "#64748b",
|
|
269
|
+
borderColor: "#e2e8f0",
|
|
270
|
+
surfaceColor: "#f8fafc",
|
|
271
|
+
radius: "medium",
|
|
272
|
+
fontFamily: 'ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
|
|
273
|
+
headingSize: "1.35rem",
|
|
274
|
+
bodySize: "0.925rem",
|
|
275
|
+
logoUrl: null,
|
|
276
|
+
logoSize: 40,
|
|
277
|
+
logoAlignment: "center",
|
|
278
|
+
showAppName: true,
|
|
279
|
+
showMeindeskBranding: true,
|
|
280
|
+
cardStyle: "elevated",
|
|
281
|
+
layout: "centered"
|
|
282
|
+
};
|
|
283
|
+
var DEFAULT_PROVIDER_LABELS = {
|
|
284
|
+
google: "Continue with Google",
|
|
285
|
+
github: "Continue with GitHub",
|
|
286
|
+
discord: "Continue with Discord",
|
|
287
|
+
apple: "Continue with Apple",
|
|
288
|
+
facebook: "Continue with Facebook",
|
|
289
|
+
microsoft: "Continue with Microsoft"
|
|
290
|
+
};
|
|
291
|
+
function defaultProviders(enabled = {}) {
|
|
292
|
+
return PROVIDER_IDS.map((id) => ({
|
|
293
|
+
id,
|
|
294
|
+
enabled: enabled[id] ?? (id === "google" || id === "github"),
|
|
295
|
+
buttonLabel: DEFAULT_PROVIDER_LABELS[id],
|
|
296
|
+
position: "before"
|
|
297
|
+
}));
|
|
298
|
+
}
|
|
299
|
+
function createDefaultAuthExperienceConfig(overrides = {}) {
|
|
300
|
+
return {
|
|
301
|
+
version: 1,
|
|
302
|
+
applicationName: overrides.applicationName,
|
|
303
|
+
methods: {
|
|
304
|
+
emailPassword: true,
|
|
305
|
+
magicLink: false,
|
|
306
|
+
passkeys: false,
|
|
307
|
+
phone: false,
|
|
308
|
+
...overrides.methods
|
|
309
|
+
},
|
|
310
|
+
providers: overrides.providers ?? defaultProviders(),
|
|
311
|
+
appearance: {
|
|
312
|
+
...DEFAULT_APPEARANCE,
|
|
313
|
+
...overrides.appearance
|
|
314
|
+
},
|
|
315
|
+
experiences: {
|
|
316
|
+
...DEFAULT_EXPERIENCES,
|
|
317
|
+
...overrides.experiences,
|
|
318
|
+
signIn: {
|
|
319
|
+
...DEFAULT_EXPERIENCES.signIn,
|
|
320
|
+
...overrides.experiences?.signIn
|
|
321
|
+
},
|
|
322
|
+
signUp: {
|
|
323
|
+
...DEFAULT_EXPERIENCES.signUp,
|
|
324
|
+
...overrides.experiences?.signUp
|
|
325
|
+
},
|
|
326
|
+
forgotPassword: {
|
|
327
|
+
...DEFAULT_EXPERIENCES.forgotPassword,
|
|
328
|
+
...overrides.experiences?.forgotPassword
|
|
329
|
+
},
|
|
330
|
+
resetPassword: {
|
|
331
|
+
...DEFAULT_EXPERIENCES.resetPassword,
|
|
332
|
+
...overrides.experiences?.resetPassword
|
|
333
|
+
},
|
|
334
|
+
magicLink: {
|
|
335
|
+
...DEFAULT_EXPERIENCES.magicLink,
|
|
336
|
+
...overrides.experiences?.magicLink
|
|
337
|
+
},
|
|
338
|
+
emailVerification: {
|
|
339
|
+
...DEFAULT_EXPERIENCES.emailVerification,
|
|
340
|
+
...overrides.experiences?.emailVerification
|
|
341
|
+
},
|
|
342
|
+
mfa: {
|
|
343
|
+
...DEFAULT_EXPERIENCES.mfa,
|
|
344
|
+
...overrides.experiences?.mfa
|
|
345
|
+
},
|
|
346
|
+
organizationSelection: {
|
|
347
|
+
...DEFAULT_EXPERIENCES.organizationSelection,
|
|
348
|
+
...overrides.experiences?.organizationSelection
|
|
349
|
+
},
|
|
350
|
+
organizationCreation: {
|
|
351
|
+
...DEFAULT_EXPERIENCES.organizationCreation,
|
|
352
|
+
...overrides.experiences?.organizationCreation
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/validation.ts
|
|
359
|
+
function parseAuthExperienceConfig(input) {
|
|
360
|
+
return authExperienceConfigSchema.parse(input);
|
|
361
|
+
}
|
|
362
|
+
function safeParseAuthExperienceConfig(input) {
|
|
363
|
+
const result = authExperienceConfigSchema.safeParse(input);
|
|
364
|
+
if (result.success) {
|
|
365
|
+
return { success: true, data: result.data };
|
|
366
|
+
}
|
|
367
|
+
return {
|
|
368
|
+
success: false,
|
|
369
|
+
error: result.error.issues.map((i) => i.message).join("; ")
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
function mergeAuthExperienceConfig(partial) {
|
|
373
|
+
const base = createDefaultAuthExperienceConfig();
|
|
374
|
+
if (!partial || typeof partial !== "object") {
|
|
375
|
+
return base;
|
|
376
|
+
}
|
|
377
|
+
const p = partial;
|
|
378
|
+
const merged = createDefaultAuthExperienceConfig({
|
|
379
|
+
applicationName: p.applicationName ?? base.applicationName,
|
|
380
|
+
methods: { ...base.methods, ...p.methods },
|
|
381
|
+
providers: p.providers ?? base.providers,
|
|
382
|
+
appearance: { ...base.appearance, ...p.appearance },
|
|
383
|
+
experiences: {
|
|
384
|
+
signIn: { ...base.experiences.signIn, ...p.experiences?.signIn },
|
|
385
|
+
signUp: { ...base.experiences.signUp, ...p.experiences?.signUp },
|
|
386
|
+
forgotPassword: {
|
|
387
|
+
...base.experiences.forgotPassword,
|
|
388
|
+
...p.experiences?.forgotPassword
|
|
389
|
+
},
|
|
390
|
+
resetPassword: {
|
|
391
|
+
...base.experiences.resetPassword,
|
|
392
|
+
...p.experiences?.resetPassword
|
|
393
|
+
},
|
|
394
|
+
magicLink: {
|
|
395
|
+
...base.experiences.magicLink,
|
|
396
|
+
...p.experiences?.magicLink
|
|
397
|
+
},
|
|
398
|
+
emailVerification: {
|
|
399
|
+
...base.experiences.emailVerification,
|
|
400
|
+
...p.experiences?.emailVerification
|
|
401
|
+
},
|
|
402
|
+
mfa: { ...base.experiences.mfa, ...p.experiences?.mfa },
|
|
403
|
+
organizationSelection: {
|
|
404
|
+
...base.experiences.organizationSelection,
|
|
405
|
+
...p.experiences?.organizationSelection
|
|
406
|
+
},
|
|
407
|
+
organizationCreation: {
|
|
408
|
+
...base.experiences.organizationCreation,
|
|
409
|
+
...p.experiences?.organizationCreation
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
return parseAuthExperienceConfig(merged);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// src/migrate.ts
|
|
417
|
+
function mapFieldTypeToProfileId(field2) {
|
|
418
|
+
const key = (field2.name ?? field2.id ?? "").toString();
|
|
419
|
+
if (PROFILE_FIELD_IDS.includes(key)) {
|
|
420
|
+
return key;
|
|
421
|
+
}
|
|
422
|
+
if (field2.type === "email") return "email";
|
|
423
|
+
if (field2.type === "password") return "password";
|
|
424
|
+
if (field2.type === "phone" || field2.type === "tel") return "phoneNumber";
|
|
425
|
+
if (key === "first_name") return "firstName";
|
|
426
|
+
if (key === "last_name") return "lastName";
|
|
427
|
+
if (key === "phone") return "phoneNumber";
|
|
428
|
+
return null;
|
|
429
|
+
}
|
|
430
|
+
function legacyFieldsToProfileFields(fields, fallback) {
|
|
431
|
+
const base = fallback ?? PROFILE_FIELD_IDS.map((id) => ({
|
|
432
|
+
id,
|
|
433
|
+
enabled: false,
|
|
434
|
+
required: false,
|
|
435
|
+
showLabel: true,
|
|
436
|
+
label: id,
|
|
437
|
+
placeholder: ""
|
|
438
|
+
}));
|
|
439
|
+
if (!fields?.length) return base;
|
|
440
|
+
const byId = /* @__PURE__ */ new Map();
|
|
441
|
+
for (const b of base) {
|
|
442
|
+
byId.set(b.id, { ...b, enabled: false });
|
|
443
|
+
}
|
|
444
|
+
const order = [];
|
|
445
|
+
for (const f of fields) {
|
|
446
|
+
const id = mapFieldTypeToProfileId(f);
|
|
447
|
+
if (!id) continue;
|
|
448
|
+
order.push(id);
|
|
449
|
+
const prev = byId.get(id);
|
|
450
|
+
byId.set(id, {
|
|
451
|
+
id,
|
|
452
|
+
enabled: f.enabled ?? true,
|
|
453
|
+
required: f.required ?? true,
|
|
454
|
+
showLabel: f.showLabel ?? true,
|
|
455
|
+
label: f.label ?? prev?.label ?? id,
|
|
456
|
+
placeholder: f.placeholder ?? prev?.placeholder ?? "",
|
|
457
|
+
showPasswordToggle: id === "password" ? f.showPasswordToggle ?? true : void 0
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
const ordered = [];
|
|
461
|
+
const seen = /* @__PURE__ */ new Set();
|
|
462
|
+
for (const id of order) {
|
|
463
|
+
if (seen.has(id)) continue;
|
|
464
|
+
seen.add(id);
|
|
465
|
+
const cfg = byId.get(id);
|
|
466
|
+
if (cfg) ordered.push(cfg);
|
|
467
|
+
}
|
|
468
|
+
for (const id of PROFILE_FIELD_IDS) {
|
|
469
|
+
if (seen.has(id)) continue;
|
|
470
|
+
const cfg = byId.get(id);
|
|
471
|
+
if (cfg) ordered.push(cfg);
|
|
472
|
+
}
|
|
473
|
+
return ordered;
|
|
474
|
+
}
|
|
475
|
+
function legacySchemaToExperience(schema, experienceId) {
|
|
476
|
+
const defaults = DEFAULT_EXPERIENCES[experienceId];
|
|
477
|
+
if (!schema) return { ...defaults };
|
|
478
|
+
if (schema.experience) {
|
|
479
|
+
return {
|
|
480
|
+
...defaults,
|
|
481
|
+
...schema.experience,
|
|
482
|
+
fields: schema.experience.fields?.length ? schema.experience.fields : defaults.fields
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
return {
|
|
486
|
+
...defaults,
|
|
487
|
+
title: schema.title ?? defaults.title,
|
|
488
|
+
subtitle: schema.subtitle ?? schema.description ?? defaults.subtitle,
|
|
489
|
+
buttonText: schema.buttonText ?? schema.submitLabel ?? defaults.buttonText,
|
|
490
|
+
loadingText: schema.loadingText ?? defaults.loadingText,
|
|
491
|
+
showSignUpLink: schema.showSignUpLink ?? defaults.showSignUpLink,
|
|
492
|
+
signUpLinkText: schema.signUpLinkText ?? defaults.signUpLinkText,
|
|
493
|
+
showSignInLink: schema.showSignInLink ?? defaults.showSignInLink,
|
|
494
|
+
signInLinkText: schema.signInLinkText ?? defaults.signInLinkText,
|
|
495
|
+
forgotPasswordEnabled: schema.forgotPasswordEnabled ?? defaults.forgotPasswordEnabled,
|
|
496
|
+
forgotPasswordText: schema.forgotPasswordText ?? defaults.forgotPasswordText,
|
|
497
|
+
dividerEnabled: schema.dividerEnabled ?? defaults.dividerEnabled,
|
|
498
|
+
dividerText: schema.dividerText ?? defaults.dividerText,
|
|
499
|
+
fields: legacyFieldsToProfileFields(schema.fields, defaults.fields)
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
function assembleAuthExperienceConfig(input) {
|
|
503
|
+
const base = createDefaultAuthExperienceConfig({
|
|
504
|
+
applicationName: input.applicationName
|
|
505
|
+
});
|
|
506
|
+
const experiences = { ...base.experiences };
|
|
507
|
+
for (const form of input.forms ?? []) {
|
|
508
|
+
const expKey = FORM_TYPE_TO_EXPERIENCE[form.type];
|
|
509
|
+
if (!expKey) continue;
|
|
510
|
+
experiences[expKey] = legacySchemaToExperience(
|
|
511
|
+
form.schema,
|
|
512
|
+
expKey
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
const providerMap = new Map(
|
|
516
|
+
(input.providers ?? []).map((p) => [p.provider, p])
|
|
517
|
+
);
|
|
518
|
+
const sortedProviders = [...input.providers ?? []].sort(
|
|
519
|
+
(a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0)
|
|
520
|
+
);
|
|
521
|
+
const orderedIds = [];
|
|
522
|
+
for (const p of sortedProviders) {
|
|
523
|
+
if (PROVIDER_IDS.includes(p.provider)) {
|
|
524
|
+
orderedIds.push(p.provider);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
for (const id of PROVIDER_IDS) {
|
|
528
|
+
if (!orderedIds.includes(id)) orderedIds.push(id);
|
|
529
|
+
}
|
|
530
|
+
const providers = orderedIds.map((id) => {
|
|
531
|
+
const row = providerMap.get(id);
|
|
532
|
+
const fallback = base.providers.find((p) => p.id === id);
|
|
533
|
+
return {
|
|
534
|
+
id,
|
|
535
|
+
enabled: row?.enabled ?? fallback.enabled,
|
|
536
|
+
buttonLabel: row?.buttonLabel ?? fallback.buttonLabel,
|
|
537
|
+
position: row?.position === "after" || row?.position === "before" ? row.position : fallback.position
|
|
538
|
+
};
|
|
539
|
+
});
|
|
540
|
+
return mergeAuthExperienceConfig({
|
|
541
|
+
applicationName: input.applicationName ?? base.applicationName,
|
|
542
|
+
methods: {
|
|
543
|
+
emailPassword: input.settings?.passwordEnabled ?? true,
|
|
544
|
+
magicLink: input.settings?.magicLinkEnabled ?? false,
|
|
545
|
+
passkeys: input.settings?.passkeysEnabled ?? false,
|
|
546
|
+
phone: input.settings?.phoneEnabled ?? false
|
|
547
|
+
},
|
|
548
|
+
providers,
|
|
549
|
+
appearance: {
|
|
550
|
+
...base.appearance,
|
|
551
|
+
...input.appearance ?? {}
|
|
552
|
+
},
|
|
553
|
+
experiences
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
function experienceToFormSchema(experienceId, copy) {
|
|
557
|
+
const formType = EXPERIENCE_TO_FORM_TYPE[experienceId];
|
|
558
|
+
return {
|
|
559
|
+
id: formType,
|
|
560
|
+
title: copy.title,
|
|
561
|
+
description: copy.subtitle,
|
|
562
|
+
subtitle: copy.subtitle,
|
|
563
|
+
submitLabel: copy.buttonText,
|
|
564
|
+
buttonText: copy.buttonText,
|
|
565
|
+
loadingText: copy.loadingText,
|
|
566
|
+
showSignUpLink: copy.showSignUpLink,
|
|
567
|
+
signUpLinkText: copy.signUpLinkText,
|
|
568
|
+
showSignInLink: copy.showSignInLink,
|
|
569
|
+
signInLinkText: copy.signInLinkText,
|
|
570
|
+
forgotPasswordEnabled: copy.forgotPasswordEnabled,
|
|
571
|
+
forgotPasswordText: copy.forgotPasswordText,
|
|
572
|
+
dividerEnabled: copy.dividerEnabled,
|
|
573
|
+
dividerText: copy.dividerText,
|
|
574
|
+
experience: copy,
|
|
575
|
+
fields: (copy.fields ?? []).filter((f) => f.enabled).map((f) => ({
|
|
576
|
+
id: f.id,
|
|
577
|
+
name: f.id,
|
|
578
|
+
type: f.id === "email" ? "email" : f.id === "password" ? "password" : f.id === "phoneNumber" ? "tel" : "text",
|
|
579
|
+
label: f.label,
|
|
580
|
+
placeholder: f.placeholder,
|
|
581
|
+
required: f.required,
|
|
582
|
+
showLabel: f.showLabel,
|
|
583
|
+
showPasswordToggle: f.showPasswordToggle
|
|
584
|
+
}))
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
function radiusToPx(radius) {
|
|
588
|
+
if (radius === "small") return "6px";
|
|
589
|
+
if (radius === "large") return "16px";
|
|
590
|
+
return "10px";
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
export { CARD_STYLES, DEFAULT_APPEARANCE, DEFAULT_EXPERIENCES, EXPERIENCE_IDS, EXPERIENCE_TO_FORM_TYPE, FORM_TYPE_TO_EXPERIENCE, LAYOUT_OPTIONS, LOGO_ALIGNMENTS, PROFILE_FIELD_IDS, PROVIDER_IDS, PROVIDER_POSITIONS, RADIUS_OPTIONS, appearanceSchema, assembleAuthExperienceConfig, authExperienceConfigSchema, createDefaultAuthExperienceConfig, defaultProviders, experienceCopySchema, experienceToFormSchema, experiencesSchema, mergeAuthExperienceConfig, methodsSchema, parseAuthExperienceConfig, profileFieldSchema, providerConfigSchema, radiusToPx, safeParseAuthExperienceConfig };
|
|
594
|
+
//# sourceMappingURL=index.js.map
|
|
595
|
+
//# sourceMappingURL=index.js.map
|