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