@authsome/ui-core 0.1.0 → 0.1.2
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 +2 -0
- package/dist/adapters/index.d.mts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/index.d.mts +198 -8
- package/dist/index.d.ts +198 -8
- package/dist/index.js +197 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +195 -22
- package/dist/index.mjs.map +1 -1
- package/dist/{provider-DXf_a2WT.d.mts → provider-C8km9A8U.d.mts} +41 -1
- package/dist/{provider-DXf_a2WT.d.ts → provider-C8km9A8U.d.ts} +41 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +16 -12
package/dist/index.js
CHANGED
|
@@ -214,16 +214,176 @@ function isMFARequiredError(error) {
|
|
|
214
214
|
return false;
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
// src/locale/en.ts
|
|
218
|
+
var enLocale = {
|
|
219
|
+
common: {
|
|
220
|
+
loading: "Loading...",
|
|
221
|
+
submit: "Submit",
|
|
222
|
+
cancel: "Cancel",
|
|
223
|
+
continue: "Continue",
|
|
224
|
+
back: "Back",
|
|
225
|
+
or: "or",
|
|
226
|
+
optional: "optional"
|
|
227
|
+
},
|
|
228
|
+
auth: {
|
|
229
|
+
signIn: "Sign In",
|
|
230
|
+
signUp: "Sign Up",
|
|
231
|
+
signOut: "Sign Out",
|
|
232
|
+
email: "Email",
|
|
233
|
+
password: "Password",
|
|
234
|
+
confirmPassword: "Confirm Password",
|
|
235
|
+
username: "Username",
|
|
236
|
+
phone: "Phone",
|
|
237
|
+
rememberMe: "Remember me",
|
|
238
|
+
forgotPassword: "Forgot password?",
|
|
239
|
+
continueWith: "Continue with {provider}",
|
|
240
|
+
orContinueWith: "Or continue with"
|
|
241
|
+
},
|
|
242
|
+
oauth: {
|
|
243
|
+
google: "Google",
|
|
244
|
+
github: "GitHub",
|
|
245
|
+
microsoft: "Microsoft",
|
|
246
|
+
facebook: "Facebook",
|
|
247
|
+
apple: "Apple",
|
|
248
|
+
discord: "Discord",
|
|
249
|
+
twitter: "Twitter",
|
|
250
|
+
linkedin: "LinkedIn",
|
|
251
|
+
chooseProvider: "Choose Your Provider",
|
|
252
|
+
signInPreferred: "Sign in with your preferred account"
|
|
253
|
+
},
|
|
254
|
+
magicLink: {
|
|
255
|
+
sendLink: "Send magic link",
|
|
256
|
+
checkEmail: "Check your email",
|
|
257
|
+
linkSent: "Magic link sent! Check your email to continue.",
|
|
258
|
+
enterEmail: "Enter your email to receive a magic link"
|
|
259
|
+
},
|
|
260
|
+
phone: {
|
|
261
|
+
enterPhone: "Enter your phone number",
|
|
262
|
+
sendCode: "Send code",
|
|
263
|
+
enterCode: "Enter verification code",
|
|
264
|
+
verifyPhone: "Verify phone number",
|
|
265
|
+
codeLabel: "Verification code"
|
|
266
|
+
},
|
|
267
|
+
mfa: {
|
|
268
|
+
required: "Two-factor authentication required",
|
|
269
|
+
selectMethod: "Select verification method",
|
|
270
|
+
verify: "Verify",
|
|
271
|
+
enterCode: "Enter verification code",
|
|
272
|
+
sms: "SMS",
|
|
273
|
+
authenticator: "Authenticator app",
|
|
274
|
+
email: "Email"
|
|
275
|
+
},
|
|
276
|
+
passkey: {
|
|
277
|
+
signInWith: "Sign in with passkey",
|
|
278
|
+
register: "Register passkey",
|
|
279
|
+
usePasskey: "Use passkey"
|
|
280
|
+
},
|
|
281
|
+
signUp: {
|
|
282
|
+
title: "Create Account",
|
|
283
|
+
subtitle: "Get started with your account",
|
|
284
|
+
haveAccount: "Already have an account?",
|
|
285
|
+
signInLink: "Sign in",
|
|
286
|
+
agreeToTerms: "I agree to the {terms}",
|
|
287
|
+
terms: "terms and conditions"
|
|
288
|
+
},
|
|
289
|
+
signIn: {
|
|
290
|
+
title: "Sign In",
|
|
291
|
+
subtitle: "Enter your email to continue",
|
|
292
|
+
noAccount: "Don't have an account?",
|
|
293
|
+
signUpLink: "Sign up",
|
|
294
|
+
enterEmail: "Enter your email to continue"
|
|
295
|
+
},
|
|
296
|
+
validation: {
|
|
297
|
+
emailRequired: "Email is required",
|
|
298
|
+
emailInvalid: "Invalid email address",
|
|
299
|
+
passwordRequired: "Password is required",
|
|
300
|
+
passwordTooShort: "Password must be at least {min} characters",
|
|
301
|
+
passwordRequireUppercase: "Password must contain an uppercase letter",
|
|
302
|
+
passwordRequireLowercase: "Password must contain a lowercase letter",
|
|
303
|
+
passwordRequireNumber: "Password must contain a number",
|
|
304
|
+
passwordRequireSpecial: "Password must contain a special character",
|
|
305
|
+
passwordMismatch: "Passwords do not match",
|
|
306
|
+
usernameRequired: "Username is required",
|
|
307
|
+
usernameInvalid: "Username must be 3-30 characters and contain only letters, numbers, underscores, and hyphens",
|
|
308
|
+
phoneRequired: "Phone number is required",
|
|
309
|
+
phoneInvalid: "Invalid phone number",
|
|
310
|
+
codeRequired: "Verification code is required",
|
|
311
|
+
codeInvalid: "Invalid verification code",
|
|
312
|
+
fieldRequired: "{field} is required",
|
|
313
|
+
termsRequired: "You must agree to the terms and conditions"
|
|
314
|
+
},
|
|
315
|
+
errors: {
|
|
316
|
+
invalidCredentials: "Invalid email or password",
|
|
317
|
+
userNotFound: "User not found",
|
|
318
|
+
userExists: "User already exists",
|
|
319
|
+
invalidToken: "Invalid or expired token",
|
|
320
|
+
tokenExpired: "Token has expired",
|
|
321
|
+
networkError: "Network error. Please try again.",
|
|
322
|
+
mfaRequired: "Two-factor authentication required",
|
|
323
|
+
emailNotVerified: "Email not verified",
|
|
324
|
+
phoneNotVerified: "Phone number not verified",
|
|
325
|
+
rateLimitExceeded: "Too many attempts. Please try again later.",
|
|
326
|
+
unknownError: "An unknown error occurred",
|
|
327
|
+
generic: "Something went wrong. Please try again."
|
|
328
|
+
},
|
|
329
|
+
success: {
|
|
330
|
+
signedIn: "Successfully signed in",
|
|
331
|
+
signedUp: "Account created successfully",
|
|
332
|
+
signedOut: "Successfully signed out",
|
|
333
|
+
linkSent: "Link sent successfully",
|
|
334
|
+
codeSent: "Verification code sent",
|
|
335
|
+
verified: "Successfully verified",
|
|
336
|
+
welcome: "Welcome, {name}!"
|
|
337
|
+
},
|
|
338
|
+
placeholders: {
|
|
339
|
+
email: "john@example.com",
|
|
340
|
+
password: "Enter your password",
|
|
341
|
+
confirmPassword: "Confirm your password",
|
|
342
|
+
username: "johndoe",
|
|
343
|
+
phone: "+1234567890",
|
|
344
|
+
code: "123456",
|
|
345
|
+
fullName: "John Doe"
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
// src/locale/utils.ts
|
|
350
|
+
var defaultLocale = enLocale;
|
|
351
|
+
function deepMerge(target, source) {
|
|
352
|
+
const result = { ...target };
|
|
353
|
+
for (const key in source) {
|
|
354
|
+
if (source[key] !== void 0) {
|
|
355
|
+
if (typeof source[key] === "object" && source[key] !== null && !Array.isArray(source[key]) && typeof result[key] === "object" && result[key] !== null) {
|
|
356
|
+
result[key] = deepMerge(result[key], source[key]);
|
|
357
|
+
} else {
|
|
358
|
+
result[key] = source[key];
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return result;
|
|
363
|
+
}
|
|
364
|
+
function createLocale(overrides) {
|
|
365
|
+
if (!overrides) {
|
|
366
|
+
return defaultLocale;
|
|
367
|
+
}
|
|
368
|
+
return deepMerge(defaultLocale, overrides);
|
|
369
|
+
}
|
|
370
|
+
function interpolate(template, values) {
|
|
371
|
+
return template.replace(/\{(\w+)\}/g, (match, key) => {
|
|
372
|
+
return values[key] !== void 0 ? String(values[key]) : match;
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
|
|
217
376
|
// src/utils/validation.ts
|
|
218
377
|
var EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
219
378
|
var PHONE_REGEX = /^\+?[1-9]\d{1,14}$/;
|
|
220
379
|
var USERNAME_REGEX = /^[a-zA-Z0-9_-]{3,30}$/;
|
|
221
|
-
function validateEmail(email) {
|
|
380
|
+
function validateEmail(email, locale) {
|
|
381
|
+
const messages = locale?.validation || defaultLocale.validation;
|
|
222
382
|
if (!email) {
|
|
223
|
-
return { field: "email", message:
|
|
383
|
+
return { field: "email", message: messages.emailRequired };
|
|
224
384
|
}
|
|
225
385
|
if (!EMAIL_REGEX.test(email)) {
|
|
226
|
-
return { field: "email", message:
|
|
386
|
+
return { field: "email", message: messages.emailInvalid };
|
|
227
387
|
}
|
|
228
388
|
return null;
|
|
229
389
|
}
|
|
@@ -233,76 +393,85 @@ function validatePassword(password, options = {}) {
|
|
|
233
393
|
requireUppercase = true,
|
|
234
394
|
requireLowercase = true,
|
|
235
395
|
requireNumber = true,
|
|
236
|
-
requireSpecial = false
|
|
396
|
+
requireSpecial = false,
|
|
397
|
+
locale
|
|
237
398
|
} = options;
|
|
399
|
+
const messages = locale?.validation || defaultLocale.validation;
|
|
238
400
|
if (!password) {
|
|
239
|
-
return { field: "password", message:
|
|
401
|
+
return { field: "password", message: messages.passwordRequired };
|
|
240
402
|
}
|
|
241
403
|
if (password.length < minLength) {
|
|
242
404
|
return {
|
|
243
405
|
field: "password",
|
|
244
|
-
message:
|
|
406
|
+
message: interpolate(messages.passwordTooShort, { min: minLength.toString() })
|
|
245
407
|
};
|
|
246
408
|
}
|
|
247
409
|
if (requireUppercase && !/[A-Z]/.test(password)) {
|
|
248
410
|
return {
|
|
249
411
|
field: "password",
|
|
250
|
-
message:
|
|
412
|
+
message: messages.passwordRequireUppercase
|
|
251
413
|
};
|
|
252
414
|
}
|
|
253
415
|
if (requireLowercase && !/[a-z]/.test(password)) {
|
|
254
416
|
return {
|
|
255
417
|
field: "password",
|
|
256
|
-
message:
|
|
418
|
+
message: messages.passwordRequireLowercase
|
|
257
419
|
};
|
|
258
420
|
}
|
|
259
421
|
if (requireNumber && !/\d/.test(password)) {
|
|
260
|
-
return { field: "password", message:
|
|
422
|
+
return { field: "password", message: messages.passwordRequireNumber };
|
|
261
423
|
}
|
|
262
424
|
if (requireSpecial && !/[!@#$%^&*(),.?":{}|<>]/.test(password)) {
|
|
263
425
|
return {
|
|
264
426
|
field: "password",
|
|
265
|
-
message:
|
|
427
|
+
message: messages.passwordRequireSpecial
|
|
266
428
|
};
|
|
267
429
|
}
|
|
268
430
|
return null;
|
|
269
431
|
}
|
|
270
|
-
function validatePhone(phone) {
|
|
432
|
+
function validatePhone(phone, locale) {
|
|
433
|
+
const messages = locale?.validation || defaultLocale.validation;
|
|
271
434
|
if (!phone) {
|
|
272
|
-
return { field: "phone", message:
|
|
435
|
+
return { field: "phone", message: messages.phoneRequired };
|
|
273
436
|
}
|
|
274
437
|
if (!PHONE_REGEX.test(phone)) {
|
|
275
438
|
return {
|
|
276
439
|
field: "phone",
|
|
277
|
-
message:
|
|
440
|
+
message: messages.phoneInvalid
|
|
278
441
|
};
|
|
279
442
|
}
|
|
280
443
|
return null;
|
|
281
444
|
}
|
|
282
|
-
function validateUsername(username) {
|
|
445
|
+
function validateUsername(username, locale) {
|
|
446
|
+
const messages = locale?.validation || defaultLocale.validation;
|
|
283
447
|
if (!username) {
|
|
284
|
-
return { field: "username", message:
|
|
448
|
+
return { field: "username", message: messages.usernameRequired };
|
|
285
449
|
}
|
|
286
450
|
if (!USERNAME_REGEX.test(username)) {
|
|
287
451
|
return {
|
|
288
452
|
field: "username",
|
|
289
|
-
message:
|
|
453
|
+
message: messages.usernameInvalid
|
|
290
454
|
};
|
|
291
455
|
}
|
|
292
456
|
return null;
|
|
293
457
|
}
|
|
294
|
-
function validate2FACode(code) {
|
|
458
|
+
function validate2FACode(code, locale) {
|
|
459
|
+
const messages = locale?.validation || defaultLocale.validation;
|
|
295
460
|
if (!code) {
|
|
296
|
-
return { field: "code", message:
|
|
461
|
+
return { field: "code", message: messages.codeRequired };
|
|
297
462
|
}
|
|
298
463
|
if (!/^\d{6}$/.test(code)) {
|
|
299
|
-
return { field: "code", message:
|
|
464
|
+
return { field: "code", message: messages.codeInvalid };
|
|
300
465
|
}
|
|
301
466
|
return null;
|
|
302
467
|
}
|
|
303
|
-
function validateRequired(value, fieldName) {
|
|
468
|
+
function validateRequired(value, fieldName, locale) {
|
|
469
|
+
const messages = locale?.validation || defaultLocale.validation;
|
|
304
470
|
if (!value || typeof value === "string" && !value.trim()) {
|
|
305
|
-
return {
|
|
471
|
+
return {
|
|
472
|
+
field: fieldName,
|
|
473
|
+
message: interpolate(messages.fieldRequired, { field: fieldName })
|
|
474
|
+
};
|
|
306
475
|
}
|
|
307
476
|
return null;
|
|
308
477
|
}
|
|
@@ -435,6 +604,10 @@ var BaseAuthProvider = class {
|
|
|
435
604
|
|
|
436
605
|
// src/client.ts
|
|
437
606
|
var AuthClient = class {
|
|
607
|
+
// Expose adapter for accessing provider-specific methods
|
|
608
|
+
get adapter() {
|
|
609
|
+
return this.provider;
|
|
610
|
+
}
|
|
438
611
|
constructor(config) {
|
|
439
612
|
this.provider = config.provider;
|
|
440
613
|
this.autoRefresh = config.autoRefresh ?? true;
|
|
@@ -1430,7 +1603,10 @@ exports.TokenManager = TokenManager;
|
|
|
1430
1603
|
exports.TwoFactorMethod = TwoFactorMethod;
|
|
1431
1604
|
exports.completeSignUpFlow = completeSignUpFlow;
|
|
1432
1605
|
exports.createAuthError = createAuthError;
|
|
1606
|
+
exports.createLocale = createLocale;
|
|
1607
|
+
exports.defaultLocale = defaultLocale;
|
|
1433
1608
|
exports.getFlowConfig = getFlowConfig;
|
|
1609
|
+
exports.interpolate = interpolate;
|
|
1434
1610
|
exports.isAuthError = isAuthError;
|
|
1435
1611
|
exports.isMFARequiredError = isMFARequiredError;
|
|
1436
1612
|
exports.isNetworkError = isNetworkError;
|