@nauth-toolkit/client 0.7.4 → 0.8.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.cjs +52 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +39 -7
- package/dist/index.d.ts +39 -7
- package/dist/index.mjs +52 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -161,6 +161,10 @@ interface AuthUserSummary {
|
|
|
161
161
|
isPhoneVerified?: boolean;
|
|
162
162
|
socialProviders?: string[] | null;
|
|
163
163
|
hasPasswordHash?: boolean;
|
|
164
|
+
/** User's preferred IANA timezone, when set. */
|
|
165
|
+
timezone?: string;
|
|
166
|
+
/** User's preferred BCP 47 locale, when set. */
|
|
167
|
+
locale?: string;
|
|
164
168
|
}
|
|
165
169
|
/**
|
|
166
170
|
* Token response returned by refresh endpoint.
|
|
@@ -188,6 +192,10 @@ interface SignupRequest {
|
|
|
188
192
|
* - If required by server but not provided, request will fail with RECAPTCHA_REQUIRED error
|
|
189
193
|
*/
|
|
190
194
|
recaptchaToken?: string;
|
|
195
|
+
/** IANA timezone (e.g. 'Europe/Dublin'). Auto-detected from the browser unless supplied. */
|
|
196
|
+
timezone?: string;
|
|
197
|
+
/** BCP 47 locale (e.g. 'en-GB'). Auto-detected from the browser unless supplied. */
|
|
198
|
+
locale?: string;
|
|
191
199
|
}
|
|
192
200
|
/**
|
|
193
201
|
* Login request payload.
|
|
@@ -404,6 +412,10 @@ interface AuthUser {
|
|
|
404
412
|
sessionAuthMethod?: string | null;
|
|
405
413
|
createdAt: string | Date;
|
|
406
414
|
updatedAt: string | Date;
|
|
415
|
+
/** User's preferred IANA timezone, or null if never set. */
|
|
416
|
+
timezone?: string | null;
|
|
417
|
+
/** User's preferred BCP 47 locale, or null if never set. */
|
|
418
|
+
locale?: string | null;
|
|
407
419
|
}
|
|
408
420
|
/**
|
|
409
421
|
* Profile update request.
|
|
@@ -413,6 +425,10 @@ interface UpdateProfileRequest {
|
|
|
413
425
|
lastName?: string;
|
|
414
426
|
email?: string;
|
|
415
427
|
phone?: string;
|
|
428
|
+
/** IANA timezone (e.g. 'Europe/Dublin'). */
|
|
429
|
+
timezone?: string;
|
|
430
|
+
/** BCP 47 locale (e.g. 'en-GB'). */
|
|
431
|
+
locale?: string;
|
|
416
432
|
}
|
|
417
433
|
/**
|
|
418
434
|
* Change password request.
|
|
@@ -469,7 +485,7 @@ interface ResetPasswordWithCodeResponse {
|
|
|
469
485
|
/**
|
|
470
486
|
* Social provider identifiers.
|
|
471
487
|
*/
|
|
472
|
-
type SocialProvider = 'google' | 'apple' | 'facebook';
|
|
488
|
+
type SocialProvider = 'google' | 'apple' | 'facebook' | 'microsoft';
|
|
473
489
|
/**
|
|
474
490
|
* Options for starting a redirect-first social login flow.
|
|
475
491
|
*
|
|
@@ -567,6 +583,7 @@ declare enum NAuthErrorCode {
|
|
|
567
583
|
SOCIAL_CONFIG_MISSING = "SOCIAL_CONFIG_MISSING",
|
|
568
584
|
SOCIAL_EMAIL_REQUIRED = "SOCIAL_EMAIL_REQUIRED",
|
|
569
585
|
SOCIAL_ACCOUNT_NOT_FOUND = "SOCIAL_ACCOUNT_NOT_FOUND",
|
|
586
|
+
SOCIAL_ACCESS_DENIED = "SOCIAL_ACCESS_DENIED",
|
|
570
587
|
CHALLENGE_EXPIRED = "CHALLENGE_EXPIRED",
|
|
571
588
|
CHALLENGE_INVALID = "CHALLENGE_INVALID",
|
|
572
589
|
CHALLENGE_TYPE_MISMATCH = "CHALLENGE_TYPE_MISMATCH",
|
|
@@ -1096,6 +1113,18 @@ interface NAuthClientConfig {
|
|
|
1096
1113
|
headerName?: string;
|
|
1097
1114
|
storageKey?: string;
|
|
1098
1115
|
};
|
|
1116
|
+
/**
|
|
1117
|
+
* Send the browser's timezone and locale when creating an account. Default: true
|
|
1118
|
+
*
|
|
1119
|
+
* The values are read from `Intl` and `navigator.language` and included with signup and
|
|
1120
|
+
* with the social redirect start, so a new user's notification emails are formatted in
|
|
1121
|
+
* their own time from the first message. They are stored as editable preferences, not
|
|
1122
|
+
* as tracking — the user or an admin can change them afterwards.
|
|
1123
|
+
*
|
|
1124
|
+
* Set to false to opt out; an explicitly supplied `timezone`/`locale` always wins over
|
|
1125
|
+
* detection regardless of this setting.
|
|
1126
|
+
*/
|
|
1127
|
+
autoDetectLocale?: boolean;
|
|
1099
1128
|
/** Additional headers to include in all requests. */
|
|
1100
1129
|
headers?: Record<string, string>;
|
|
1101
1130
|
/** Request timeout in milliseconds. Default: 30000 */
|
|
@@ -1484,7 +1513,7 @@ interface AdminSignupSocialRequest {
|
|
|
1484
1513
|
/**
|
|
1485
1514
|
* Social provider name
|
|
1486
1515
|
*/
|
|
1487
|
-
provider: 'google' | 'apple' | 'facebook';
|
|
1516
|
+
provider: 'google' | 'apple' | 'facebook' | 'microsoft';
|
|
1488
1517
|
/**
|
|
1489
1518
|
* Provider's unique user identifier
|
|
1490
1519
|
*/
|
|
@@ -2509,6 +2538,7 @@ type ResolvedNAuthClientConfig = Omit<NAuthClientConfig, 'endpoints' | 'storage'
|
|
|
2509
2538
|
headerName: string;
|
|
2510
2539
|
storageKey: string;
|
|
2511
2540
|
};
|
|
2541
|
+
autoDetectLocale: boolean;
|
|
2512
2542
|
headers: Record<string, string>;
|
|
2513
2543
|
timeout: number;
|
|
2514
2544
|
admin?: {
|
|
@@ -3796,14 +3826,16 @@ declare class NAuthClient {
|
|
|
3796
3826
|
*/
|
|
3797
3827
|
confirmForgotPassword(identifier: string, code: string, newPassword: string): Promise<ConfirmForgotPasswordResponse>;
|
|
3798
3828
|
/**
|
|
3799
|
-
*
|
|
3829
|
+
* Complete an admin-initiated password reset with a verification code.
|
|
3800
3830
|
*
|
|
3801
3831
|
* NOTE:
|
|
3802
|
-
* -
|
|
3803
|
-
*
|
|
3832
|
+
* - Admin-initiated only. A self-service "forgot password" code (from {@link forgotPassword}) is NOT
|
|
3833
|
+
* accepted here — use {@link confirmForgotPassword} for that flow instead. The two codes are validated
|
|
3834
|
+
* against different token types server-side and are not interchangeable, even though the emailed link
|
|
3835
|
+
* format is identical between the two flows (`...?code=123456`, no distinguishing marker).
|
|
3804
3836
|
*
|
|
3805
|
-
* WHY:
|
|
3806
|
-
*
|
|
3837
|
+
* WHY: Posts to the admin-reset confirm endpoint (`confirmAdminResetPassword`), which only recognizes
|
|
3838
|
+
* codes generated by an admin's `adminResetPassword` call.
|
|
3807
3839
|
*
|
|
3808
3840
|
* @param identifier - User identifier (email, username, phone)
|
|
3809
3841
|
* @param code - Verification code from email/SMS (6-10 digits)
|
package/dist/index.d.ts
CHANGED
|
@@ -161,6 +161,10 @@ interface AuthUserSummary {
|
|
|
161
161
|
isPhoneVerified?: boolean;
|
|
162
162
|
socialProviders?: string[] | null;
|
|
163
163
|
hasPasswordHash?: boolean;
|
|
164
|
+
/** User's preferred IANA timezone, when set. */
|
|
165
|
+
timezone?: string;
|
|
166
|
+
/** User's preferred BCP 47 locale, when set. */
|
|
167
|
+
locale?: string;
|
|
164
168
|
}
|
|
165
169
|
/**
|
|
166
170
|
* Token response returned by refresh endpoint.
|
|
@@ -188,6 +192,10 @@ interface SignupRequest {
|
|
|
188
192
|
* - If required by server but not provided, request will fail with RECAPTCHA_REQUIRED error
|
|
189
193
|
*/
|
|
190
194
|
recaptchaToken?: string;
|
|
195
|
+
/** IANA timezone (e.g. 'Europe/Dublin'). Auto-detected from the browser unless supplied. */
|
|
196
|
+
timezone?: string;
|
|
197
|
+
/** BCP 47 locale (e.g. 'en-GB'). Auto-detected from the browser unless supplied. */
|
|
198
|
+
locale?: string;
|
|
191
199
|
}
|
|
192
200
|
/**
|
|
193
201
|
* Login request payload.
|
|
@@ -404,6 +412,10 @@ interface AuthUser {
|
|
|
404
412
|
sessionAuthMethod?: string | null;
|
|
405
413
|
createdAt: string | Date;
|
|
406
414
|
updatedAt: string | Date;
|
|
415
|
+
/** User's preferred IANA timezone, or null if never set. */
|
|
416
|
+
timezone?: string | null;
|
|
417
|
+
/** User's preferred BCP 47 locale, or null if never set. */
|
|
418
|
+
locale?: string | null;
|
|
407
419
|
}
|
|
408
420
|
/**
|
|
409
421
|
* Profile update request.
|
|
@@ -413,6 +425,10 @@ interface UpdateProfileRequest {
|
|
|
413
425
|
lastName?: string;
|
|
414
426
|
email?: string;
|
|
415
427
|
phone?: string;
|
|
428
|
+
/** IANA timezone (e.g. 'Europe/Dublin'). */
|
|
429
|
+
timezone?: string;
|
|
430
|
+
/** BCP 47 locale (e.g. 'en-GB'). */
|
|
431
|
+
locale?: string;
|
|
416
432
|
}
|
|
417
433
|
/**
|
|
418
434
|
* Change password request.
|
|
@@ -469,7 +485,7 @@ interface ResetPasswordWithCodeResponse {
|
|
|
469
485
|
/**
|
|
470
486
|
* Social provider identifiers.
|
|
471
487
|
*/
|
|
472
|
-
type SocialProvider = 'google' | 'apple' | 'facebook';
|
|
488
|
+
type SocialProvider = 'google' | 'apple' | 'facebook' | 'microsoft';
|
|
473
489
|
/**
|
|
474
490
|
* Options for starting a redirect-first social login flow.
|
|
475
491
|
*
|
|
@@ -567,6 +583,7 @@ declare enum NAuthErrorCode {
|
|
|
567
583
|
SOCIAL_CONFIG_MISSING = "SOCIAL_CONFIG_MISSING",
|
|
568
584
|
SOCIAL_EMAIL_REQUIRED = "SOCIAL_EMAIL_REQUIRED",
|
|
569
585
|
SOCIAL_ACCOUNT_NOT_FOUND = "SOCIAL_ACCOUNT_NOT_FOUND",
|
|
586
|
+
SOCIAL_ACCESS_DENIED = "SOCIAL_ACCESS_DENIED",
|
|
570
587
|
CHALLENGE_EXPIRED = "CHALLENGE_EXPIRED",
|
|
571
588
|
CHALLENGE_INVALID = "CHALLENGE_INVALID",
|
|
572
589
|
CHALLENGE_TYPE_MISMATCH = "CHALLENGE_TYPE_MISMATCH",
|
|
@@ -1096,6 +1113,18 @@ interface NAuthClientConfig {
|
|
|
1096
1113
|
headerName?: string;
|
|
1097
1114
|
storageKey?: string;
|
|
1098
1115
|
};
|
|
1116
|
+
/**
|
|
1117
|
+
* Send the browser's timezone and locale when creating an account. Default: true
|
|
1118
|
+
*
|
|
1119
|
+
* The values are read from `Intl` and `navigator.language` and included with signup and
|
|
1120
|
+
* with the social redirect start, so a new user's notification emails are formatted in
|
|
1121
|
+
* their own time from the first message. They are stored as editable preferences, not
|
|
1122
|
+
* as tracking — the user or an admin can change them afterwards.
|
|
1123
|
+
*
|
|
1124
|
+
* Set to false to opt out; an explicitly supplied `timezone`/`locale` always wins over
|
|
1125
|
+
* detection regardless of this setting.
|
|
1126
|
+
*/
|
|
1127
|
+
autoDetectLocale?: boolean;
|
|
1099
1128
|
/** Additional headers to include in all requests. */
|
|
1100
1129
|
headers?: Record<string, string>;
|
|
1101
1130
|
/** Request timeout in milliseconds. Default: 30000 */
|
|
@@ -1484,7 +1513,7 @@ interface AdminSignupSocialRequest {
|
|
|
1484
1513
|
/**
|
|
1485
1514
|
* Social provider name
|
|
1486
1515
|
*/
|
|
1487
|
-
provider: 'google' | 'apple' | 'facebook';
|
|
1516
|
+
provider: 'google' | 'apple' | 'facebook' | 'microsoft';
|
|
1488
1517
|
/**
|
|
1489
1518
|
* Provider's unique user identifier
|
|
1490
1519
|
*/
|
|
@@ -2509,6 +2538,7 @@ type ResolvedNAuthClientConfig = Omit<NAuthClientConfig, 'endpoints' | 'storage'
|
|
|
2509
2538
|
headerName: string;
|
|
2510
2539
|
storageKey: string;
|
|
2511
2540
|
};
|
|
2541
|
+
autoDetectLocale: boolean;
|
|
2512
2542
|
headers: Record<string, string>;
|
|
2513
2543
|
timeout: number;
|
|
2514
2544
|
admin?: {
|
|
@@ -3796,14 +3826,16 @@ declare class NAuthClient {
|
|
|
3796
3826
|
*/
|
|
3797
3827
|
confirmForgotPassword(identifier: string, code: string, newPassword: string): Promise<ConfirmForgotPasswordResponse>;
|
|
3798
3828
|
/**
|
|
3799
|
-
*
|
|
3829
|
+
* Complete an admin-initiated password reset with a verification code.
|
|
3800
3830
|
*
|
|
3801
3831
|
* NOTE:
|
|
3802
|
-
* -
|
|
3803
|
-
*
|
|
3832
|
+
* - Admin-initiated only. A self-service "forgot password" code (from {@link forgotPassword}) is NOT
|
|
3833
|
+
* accepted here — use {@link confirmForgotPassword} for that flow instead. The two codes are validated
|
|
3834
|
+
* against different token types server-side and are not interchangeable, even though the emailed link
|
|
3835
|
+
* format is identical between the two flows (`...?code=123456`, no distinguishing marker).
|
|
3804
3836
|
*
|
|
3805
|
-
* WHY:
|
|
3806
|
-
*
|
|
3837
|
+
* WHY: Posts to the admin-reset confirm endpoint (`confirmAdminResetPassword`), which only recognizes
|
|
3838
|
+
* codes generated by an admin's `adminResetPassword` call.
|
|
3807
3839
|
*
|
|
3808
3840
|
* @param identifier - User identifier (email, username, phone)
|
|
3809
3841
|
* @param code - Verification code from email/SMS (6-10 digits)
|
package/dist/index.mjs
CHANGED
|
@@ -47,6 +47,7 @@ var NAuthErrorCode = /* @__PURE__ */ ((NAuthErrorCode2) => {
|
|
|
47
47
|
NAuthErrorCode2["SOCIAL_CONFIG_MISSING"] = "SOCIAL_CONFIG_MISSING";
|
|
48
48
|
NAuthErrorCode2["SOCIAL_EMAIL_REQUIRED"] = "SOCIAL_EMAIL_REQUIRED";
|
|
49
49
|
NAuthErrorCode2["SOCIAL_ACCOUNT_NOT_FOUND"] = "SOCIAL_ACCOUNT_NOT_FOUND";
|
|
50
|
+
NAuthErrorCode2["SOCIAL_ACCESS_DENIED"] = "SOCIAL_ACCESS_DENIED";
|
|
50
51
|
NAuthErrorCode2["CHALLENGE_EXPIRED"] = "CHALLENGE_EXPIRED";
|
|
51
52
|
NAuthErrorCode2["CHALLENGE_INVALID"] = "CHALLENGE_INVALID";
|
|
52
53
|
NAuthErrorCode2["CHALLENGE_TYPE_MISMATCH"] = "CHALLENGE_TYPE_MISMATCH";
|
|
@@ -203,6 +204,7 @@ var resolveConfig = (config, defaultAdapter) => {
|
|
|
203
204
|
cookieName: config.csrf?.cookieName ?? "nauth_csrf_token",
|
|
204
205
|
headerName: config.csrf?.headerName ?? "x-csrf-token"
|
|
205
206
|
},
|
|
207
|
+
autoDetectLocale: config.autoDetectLocale ?? true,
|
|
206
208
|
deviceTrust: {
|
|
207
209
|
headerName: config.deviceTrust?.headerName ?? "X-Device-Token",
|
|
208
210
|
storageKey: config.deviceTrust?.storageKey ?? "nauth_device_token"
|
|
@@ -2098,6 +2100,42 @@ var OIDCOperations = class {
|
|
|
2098
2100
|
}
|
|
2099
2101
|
};
|
|
2100
2102
|
|
|
2103
|
+
// src/core/environment.ts
|
|
2104
|
+
function hasBrowserEnvironment() {
|
|
2105
|
+
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
2106
|
+
}
|
|
2107
|
+
function detectTimezone() {
|
|
2108
|
+
if (!hasBrowserEnvironment()) return void 0;
|
|
2109
|
+
try {
|
|
2110
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone || void 0;
|
|
2111
|
+
} catch {
|
|
2112
|
+
return void 0;
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
function detectLocale() {
|
|
2116
|
+
if (!hasBrowserEnvironment()) return void 0;
|
|
2117
|
+
try {
|
|
2118
|
+
const preferred = typeof navigator !== "undefined" ? navigator.language : void 0;
|
|
2119
|
+
if (preferred) return preferred;
|
|
2120
|
+
return Intl.DateTimeFormat().resolvedOptions().locale || void 0;
|
|
2121
|
+
} catch {
|
|
2122
|
+
return void 0;
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
function withDetectedPreferences(supplied, enabled) {
|
|
2126
|
+
if (!enabled) return supplied;
|
|
2127
|
+
const result = { ...supplied };
|
|
2128
|
+
if (!("timezone" in supplied)) {
|
|
2129
|
+
const timezone = detectTimezone();
|
|
2130
|
+
if (timezone) result.timezone = timezone;
|
|
2131
|
+
}
|
|
2132
|
+
if (!("locale" in supplied)) {
|
|
2133
|
+
const locale = detectLocale();
|
|
2134
|
+
if (locale) result.locale = locale;
|
|
2135
|
+
}
|
|
2136
|
+
return result;
|
|
2137
|
+
}
|
|
2138
|
+
|
|
2101
2139
|
// src/core/client.ts
|
|
2102
2140
|
var USER_KEY2 = "nauth_user";
|
|
2103
2141
|
var CHALLENGE_KEY2 = "nauth_challenge_session";
|
|
@@ -2276,6 +2314,7 @@ var NAuthClient = class {
|
|
|
2276
2314
|
* Signup with credentials.
|
|
2277
2315
|
*/
|
|
2278
2316
|
async signup(payload) {
|
|
2317
|
+
payload = withDetectedPreferences(payload, this.config.autoDetectLocale);
|
|
2279
2318
|
this.eventEmitter.emit({ type: "auth:signup", data: { email: payload.email }, timestamp: Date.now() });
|
|
2280
2319
|
try {
|
|
2281
2320
|
const response = await this.post(this.config.endpoints.signup, payload);
|
|
@@ -2622,14 +2661,16 @@ var NAuthClient = class {
|
|
|
2622
2661
|
return result;
|
|
2623
2662
|
}
|
|
2624
2663
|
/**
|
|
2625
|
-
*
|
|
2664
|
+
* Complete an admin-initiated password reset with a verification code.
|
|
2626
2665
|
*
|
|
2627
2666
|
* NOTE:
|
|
2628
|
-
* -
|
|
2629
|
-
*
|
|
2667
|
+
* - Admin-initiated only. A self-service "forgot password" code (from {@link forgotPassword}) is NOT
|
|
2668
|
+
* accepted here — use {@link confirmForgotPassword} for that flow instead. The two codes are validated
|
|
2669
|
+
* against different token types server-side and are not interchangeable, even though the emailed link
|
|
2670
|
+
* format is identical between the two flows (`...?code=123456`, no distinguishing marker).
|
|
2630
2671
|
*
|
|
2631
|
-
* WHY:
|
|
2632
|
-
*
|
|
2672
|
+
* WHY: Posts to the admin-reset confirm endpoint (`confirmAdminResetPassword`), which only recognizes
|
|
2673
|
+
* codes generated by an admin's `adminResetPassword` call.
|
|
2633
2674
|
*
|
|
2634
2675
|
* @param identifier - User identifier (email, username, phone)
|
|
2635
2676
|
* @param code - Verification code from email/SMS (6-10 digits)
|
|
@@ -2990,6 +3031,12 @@ var NAuthClient = class {
|
|
|
2990
3031
|
if (typeof options?.appState === "string" && options.appState.trim() !== "") {
|
|
2991
3032
|
startUrl.searchParams.set("appState", options.appState);
|
|
2992
3033
|
}
|
|
3034
|
+
if (this.config.autoDetectLocale) {
|
|
3035
|
+
const timezone = detectTimezone();
|
|
3036
|
+
const locale = detectLocale();
|
|
3037
|
+
if (timezone) startUrl.searchParams.set("timezone", timezone);
|
|
3038
|
+
if (locale) startUrl.searchParams.set("locale", locale);
|
|
3039
|
+
}
|
|
2993
3040
|
if (options?.oauthParams && Object.keys(options.oauthParams).length > 0) {
|
|
2994
3041
|
startUrl.searchParams.set("oauthParams", JSON.stringify(options.oauthParams));
|
|
2995
3042
|
}
|