@atlasauth/js 0.8.0 → 0.9.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/CHANGELOG.md +20 -0
- package/dist/api-keys.d.ts +9 -1
- package/dist/api-keys.js +14 -2
- package/dist/api-keys.js.map +1 -1
- package/dist/attempt.d.ts +13 -0
- package/dist/attempt.js +10 -1
- package/dist/attempt.js.map +1 -1
- package/dist/errors.d.ts +58 -0
- package/dist/errors.js +143 -0
- package/dist/errors.js.map +1 -0
- package/dist/fapi.d.ts +17 -0
- package/dist/fapi.js +20 -1
- package/dist/fapi.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/reauth.d.ts +3 -1
- package/dist/reauth.js +14 -2
- package/dist/reauth.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @atlasauth/js changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
- **Added `reason?: string` and `meta?: Record<string, unknown>` to `FieldError`**, parsed from the Frontend API
|
|
5
|
+
error envelope (`{ code, message, reason?, param?, meta? }`). `code` is unchanged. A network failure now carries
|
|
6
|
+
the client-side reason `network`.
|
|
7
|
+
- **Added `reason?: string` and `meta?: Record<string, unknown>` to `ApiKeyRequestError`** (new optional
|
|
8
|
+
constructor arguments `reason`, `meta` after `param`). `reauthenticate()` errors carry `.reason` too.
|
|
9
|
+
- **New: `localizedErrorMessage(error, strings?, fallback?)`** → the text to show for a server error: the catalog
|
|
10
|
+
string `error.<reason>` (placeholders filled from `meta`), else the server's `message`, else `error.generic`,
|
|
11
|
+
else an English generic sentence — never blank. `strings` is a flat catalog or a `(key) => string | undefined`
|
|
12
|
+
lookup (a lookup that echoes the key counts as missing). `ErrorStrings` accepts any object, so an
|
|
13
|
+
`interface`-typed bundle such as `esES` from `@atlasauth/localizations` passes without a cast.
|
|
14
|
+
- **New: `ERROR_REASONS`** (the 38 reasons the shipped catalogs translate), type **`ErrorReason`**,
|
|
15
|
+
**`errorReasonKey(reason)`** (`error.<reason>`), types **`ErrorLike`** and **`ErrorStrings`**, and
|
|
16
|
+
**`catalogLocale(catalog)`** (a bundle's own `locale` tag).
|
|
17
|
+
- **New: `FapiClientOptions.locale?: string`** — sent as `Accept-Language` on every request so the server's
|
|
18
|
+
`message` comes back in that language; `FapiClient.locale` getter and **`acceptLanguageFor(tag)`** (normalises
|
|
19
|
+
`pt_BR` → `pt-BR`, rejects anything that is not a plain BCP-47 tag). **`ReauthOptions.locale?: string`** does the
|
|
20
|
+
same for `reauthenticate()`.
|
|
21
|
+
|
|
22
|
+
|
|
3
23
|
## 0.8.0
|
|
4
24
|
- **New: `SignOutGuard`** — the safer sign-out every framework provider now drives, so they all behave like
|
|
5
25
|
`@atlasauth/react`: `new SignOutGuard({ request, frontendApi?, store?, tombstones?, retryDelaysMs?,
|
package/dist/api-keys.d.ts
CHANGED
|
@@ -62,7 +62,15 @@ export declare class ApiKeyRequestError extends Error {
|
|
|
62
62
|
readonly code: string;
|
|
63
63
|
readonly status: number;
|
|
64
64
|
readonly param?: string;
|
|
65
|
-
|
|
65
|
+
/**
|
|
66
|
+
* The server's stable reason (`too_many_attempts`, …), when it sent one: the
|
|
67
|
+
* catalog key `error.<reason>` a UI shows instead of `message`. See
|
|
68
|
+
* `localizedErrorMessage`.
|
|
69
|
+
*/
|
|
70
|
+
readonly reason?: string;
|
|
71
|
+
/** The server's `meta` detail for this error, when it sent one. */
|
|
72
|
+
readonly meta?: Record<string, unknown>;
|
|
73
|
+
constructor(status: number, code: string, message: string, param?: string, reason?: string, meta?: Record<string, unknown>);
|
|
66
74
|
/** True when the action needs a fresh re-authentication first. */
|
|
67
75
|
get needsReverification(): boolean;
|
|
68
76
|
}
|
package/dist/api-keys.js
CHANGED
|
@@ -10,12 +10,24 @@ class ApiKeyRequestError extends Error {
|
|
|
10
10
|
code;
|
|
11
11
|
status;
|
|
12
12
|
param;
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The server's stable reason (`too_many_attempts`, …), when it sent one: the
|
|
15
|
+
* catalog key `error.<reason>` a UI shows instead of `message`. See
|
|
16
|
+
* `localizedErrorMessage`.
|
|
17
|
+
*/
|
|
18
|
+
reason;
|
|
19
|
+
/** The server's `meta` detail for this error, when it sent one. */
|
|
20
|
+
meta;
|
|
21
|
+
constructor(status, code, message, param, reason, meta) {
|
|
14
22
|
super(message);
|
|
15
23
|
this.name = 'ApiKeyRequestError';
|
|
16
24
|
this.status = status;
|
|
17
25
|
this.code = code;
|
|
18
26
|
this.param = param;
|
|
27
|
+
if (reason)
|
|
28
|
+
this.reason = reason;
|
|
29
|
+
if (meta)
|
|
30
|
+
this.meta = meta;
|
|
19
31
|
}
|
|
20
32
|
/** True when the action needs a fresh re-authentication first. */
|
|
21
33
|
get needsReverification() {
|
|
@@ -28,7 +40,7 @@ async function call(client, path, init = {}) {
|
|
|
28
40
|
const res = await client.request(path, init);
|
|
29
41
|
if (!res.ok || !res.data) {
|
|
30
42
|
const first = res.errors[0];
|
|
31
|
-
throw new ApiKeyRequestError(res.status, first?.code ?? 'UNKNOWN', first?.message ?? 'The request failed.', first?.param);
|
|
43
|
+
throw new ApiKeyRequestError(res.status, first?.code ?? 'UNKNOWN', first?.message ?? 'The request failed.', first?.param, first?.reason, first?.meta);
|
|
32
44
|
}
|
|
33
45
|
return res.data;
|
|
34
46
|
}
|
package/dist/api-keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-keys.js","sourceRoot":"","sources":["../src/api-keys.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"api-keys.js","sourceRoot":"","sources":["../src/api-keys.ts"],"names":[],"mappings":";;;AAyHA,kCAqBC;AAGD,oCAYC;AAGD,oCASC;AAGD,oCASC;AApHD,mEAAmE;AACnE,MAAa,kBAAmB,SAAQ,KAAK;IACl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,MAAM,CAAC;IAC3D,IAAI,KAAK,CAAC,cAAc,KAAK,SAAS;QAAE,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC,cAAc,CAAC;IACpF,OAAO,IAAI,CAAoB,MAAM,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC/F,CAAC;AAED,6CAA6C;AACtC,KAAK,UAAU,YAAY,CAChC,MAAkB,EAClB,EAAU,EACV,KAA8B;IAE9B,OAAO,IAAI,CAAa,MAAM,EAAE,GAAG,IAAI,IAAI,kBAAkB,CAAC,EAAE,CAAC,EAAE,EAAE;QACnE,MAAM,EAAE,OAAO;QACf,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;KAC3C,CAAC,CAAC;AACL,CAAC;AAED,6CAA6C;AACtC,KAAK,UAAU,YAAY,CAChC,MAAkB,EAClB,EAAU;IAEV,OAAO,IAAI,CACT,MAAM,EACN,GAAG,IAAI,IAAI,kBAAkB,CAAC,EAAE,CAAC,SAAS,EAC1C,EAAE,MAAM,EAAE,MAAM,EAAE,CACnB,CAAC;AACJ,CAAC"}
|
package/dist/attempt.d.ts
CHANGED
|
@@ -78,6 +78,19 @@ export interface FieldError {
|
|
|
78
78
|
code: string;
|
|
79
79
|
message: string;
|
|
80
80
|
param?: string;
|
|
81
|
+
/**
|
|
82
|
+
* The server's stable, machine-readable reason for this error
|
|
83
|
+
* (`form_password_incorrect`, `too_many_attempts`, …), finer-grained than
|
|
84
|
+
* `code`. Prebuilt UIs look it up as the catalog key `error.<reason>` to show
|
|
85
|
+
* the message in the app's language; see `localizedErrorMessage`. Absent on
|
|
86
|
+
* servers that predate it and on errors raised client-side.
|
|
87
|
+
*/
|
|
88
|
+
reason?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Extra machine-readable detail the server attached (`min_length`,
|
|
91
|
+
* `providers`, …); also the interpolation values for `error.<reason>`.
|
|
92
|
+
*/
|
|
93
|
+
meta?: Record<string, unknown>;
|
|
81
94
|
}
|
|
82
95
|
export declare function fieldErrors(body: unknown): FieldError[];
|
|
83
96
|
/** Errors for one field, so a form can render them inline. */
|
package/dist/attempt.js
CHANGED
|
@@ -76,7 +76,16 @@ function fieldErrors(body) {
|
|
|
76
76
|
.filter((error) => {
|
|
77
77
|
return Boolean(error) && typeof error.message === 'string';
|
|
78
78
|
})
|
|
79
|
-
.map((error) =>
|
|
79
|
+
.map((error) => {
|
|
80
|
+
const out = { code: error.code, message: error.message, param: error.param };
|
|
81
|
+
const reason = error.reason;
|
|
82
|
+
if (typeof reason === 'string' && reason !== '')
|
|
83
|
+
out.reason = reason;
|
|
84
|
+
const meta = error.meta;
|
|
85
|
+
if (meta && typeof meta === 'object' && !Array.isArray(meta))
|
|
86
|
+
out.meta = meta;
|
|
87
|
+
return out;
|
|
88
|
+
});
|
|
80
89
|
}
|
|
81
90
|
/** Errors for one field, so a form can render them inline. */
|
|
82
91
|
function errorsFor(errors, param) {
|
package/dist/attempt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attempt.js","sourceRoot":"","sources":["../src/attempt.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAkDH,4BAqDC;AAGD,gCAEC;
|
|
1
|
+
{"version":3,"file":"attempt.js","sourceRoot":"","sources":["../src/attempt.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAkDH,4BAqDC;AAGD,gCAEC;AA6BD,kCAiBC;AAGD,8BAEC;AAGD,gCAEC;AAlHD,SAAgB,QAAQ,CAAC,OAAoB;IAC3C,QAAQ,OAAO,CAAC,MAAuB,EAAE,CAAC;QACxC,KAAK,kBAAkB;YACrB,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,CAAC;QAExC,KAAK,oBAAoB;YACvB,OAAO;gBACL,IAAI,EAAE,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
* Server errors in the app's language.
|
|
3
|
+
*
|
|
4
|
+
* A Frontend API error carries a human `message` (in English unless the request
|
|
5
|
+
* sent an `Accept-Language` the server has strings for) and, on current
|
|
6
|
+
* servers, a stable `reason` such as `form_password_incorrect`. A prebuilt form
|
|
7
|
+
* looks the reason up as the catalog key `error.<reason>`, so a Spanish form
|
|
8
|
+
* shows a Spanish sentence even when the server answered in English, and an
|
|
9
|
+
* app can reword any error by overriding that one key.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* The reasons the Frontend API sends that every shipped catalog translates, as
|
|
13
|
+
* `error.<reason>` keys. Listed for docs and coverage checks; a reason missing
|
|
14
|
+
* from this list still renders (as the server's `message`).
|
|
15
|
+
*/
|
|
16
|
+
export declare const ERROR_REASONS: readonly ["form_password_incorrect", "form_code_incorrect", "form_code_already_used", "form_code_expired", "form_code_max_attempts", "form_link_invalid", "form_identifier_not_found", "form_identifier_exists", "form_password_pwned", "form_password_too_short", "form_password_too_long", "form_password_requires_uppercase", "form_password_requires_lowercase", "form_password_requires_number", "form_password_requires_symbol", "form_password_not_allowed", "form_password_contains_identifier", "form_password_same_as_current", "form_password_reused", "password_expired", "email_not_verified", "sign_in_token_invalid", "too_many_attempts", "too_many_requests", "captcha_required", "captcha_failed", "captcha_unavailable", "email_delivery_unavailable", "strategy_disabled", "sign_up_restricted", "waitlisted", "identifier_not_allowed", "disposable_email_blocked", "sso_required", "sign_ins_disabled", "sign_ups_disabled", "high_risk_blocked", "sms_region_blocked"];
|
|
17
|
+
/** A reason with a string in every shipped catalog. */
|
|
18
|
+
export type ErrorReason = (typeof ERROR_REASONS)[number];
|
|
19
|
+
/** The catalog key for a reason: `error.<reason>`. */
|
|
20
|
+
export declare function errorReasonKey(reason: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* What {@link localizedErrorMessage} reads strings from: a flat catalog object
|
|
23
|
+
* (`{ 'error.too_many_attempts': '…' }`, or a bundle such as `esES` from
|
|
24
|
+
* `@atlasauth/localizations`) or a lookup function. A function may answer a
|
|
25
|
+
* missing key with `undefined`, `null`, `''` or the key itself (the convention
|
|
26
|
+
* of the prebuilt UIs' `translate`); all four count as "no string". Typed as
|
|
27
|
+
* `object` so an `interface`-typed bundle is accepted without a cast.
|
|
28
|
+
*/
|
|
29
|
+
export type ErrorStrings = ((key: string) => string | null | undefined) | object;
|
|
30
|
+
/** Anything error-shaped: a `FieldError`, an `ApiKeyRequestError`, an `Error`, a server error object. */
|
|
31
|
+
export interface ErrorLike {
|
|
32
|
+
reason?: string | null;
|
|
33
|
+
message?: string | null;
|
|
34
|
+
code?: string | null;
|
|
35
|
+
/** Interpolation values for the catalog string (`{min_length}` ← `meta.min_length`). */
|
|
36
|
+
meta?: Readonly<Record<string, unknown>> | null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The message to show for a server error, in the app's language:
|
|
40
|
+
*
|
|
41
|
+
* 1. the catalog string `error.<reason>`, when the error has a reason and
|
|
42
|
+
* `strings` has that key, with `{placeholders}` filled from the error's
|
|
43
|
+
* `meta` (a placeholder `meta` cannot fill skips to step 2);
|
|
44
|
+
* 2. else the server's `message` (localised by the server when the client sent
|
|
45
|
+
* `Accept-Language` — see `FapiClientOptions.locale`);
|
|
46
|
+
* 3. else the catalog's `error.generic`, else an English generic sentence.
|
|
47
|
+
*
|
|
48
|
+
* Never returns an empty string. `fallback`, when given, is consulted for
|
|
49
|
+
* `error.generic` after `strings` — handy when `strings` is a language layer
|
|
50
|
+
* without the English defaults underneath it.
|
|
51
|
+
*/
|
|
52
|
+
export declare function localizedErrorMessage(error: ErrorLike | string | null | undefined, strings?: ErrorStrings | null, fallback?: ErrorStrings | null): string;
|
|
53
|
+
/**
|
|
54
|
+
* The BCP-47 tag a catalog declares for itself (`@atlasauth/localizations`
|
|
55
|
+
* bundles carry `locale: 'es-ES'`), or undefined. Prebuilt UIs that take a
|
|
56
|
+
* `localization` bundle use it as the `Accept-Language` they send.
|
|
57
|
+
*/
|
|
58
|
+
export declare function catalogLocale(catalog: object | null | undefined): string | undefined;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Server errors in the app's language.
|
|
4
|
+
*
|
|
5
|
+
* A Frontend API error carries a human `message` (in English unless the request
|
|
6
|
+
* sent an `Accept-Language` the server has strings for) and, on current
|
|
7
|
+
* servers, a stable `reason` such as `form_password_incorrect`. A prebuilt form
|
|
8
|
+
* looks the reason up as the catalog key `error.<reason>`, so a Spanish form
|
|
9
|
+
* shows a Spanish sentence even when the server answered in English, and an
|
|
10
|
+
* app can reword any error by overriding that one key.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.ERROR_REASONS = void 0;
|
|
14
|
+
exports.errorReasonKey = errorReasonKey;
|
|
15
|
+
exports.localizedErrorMessage = localizedErrorMessage;
|
|
16
|
+
exports.catalogLocale = catalogLocale;
|
|
17
|
+
/**
|
|
18
|
+
* The reasons the Frontend API sends that every shipped catalog translates, as
|
|
19
|
+
* `error.<reason>` keys. Listed for docs and coverage checks; a reason missing
|
|
20
|
+
* from this list still renders (as the server's `message`).
|
|
21
|
+
*/
|
|
22
|
+
exports.ERROR_REASONS = Object.freeze([
|
|
23
|
+
'form_password_incorrect',
|
|
24
|
+
'form_code_incorrect',
|
|
25
|
+
'form_code_already_used',
|
|
26
|
+
'form_code_expired',
|
|
27
|
+
'form_code_max_attempts',
|
|
28
|
+
'form_link_invalid',
|
|
29
|
+
'form_identifier_not_found',
|
|
30
|
+
'form_identifier_exists',
|
|
31
|
+
'form_password_pwned',
|
|
32
|
+
'form_password_too_short',
|
|
33
|
+
'form_password_too_long',
|
|
34
|
+
'form_password_requires_uppercase',
|
|
35
|
+
'form_password_requires_lowercase',
|
|
36
|
+
'form_password_requires_number',
|
|
37
|
+
'form_password_requires_symbol',
|
|
38
|
+
'form_password_not_allowed',
|
|
39
|
+
'form_password_contains_identifier',
|
|
40
|
+
'form_password_same_as_current',
|
|
41
|
+
'form_password_reused',
|
|
42
|
+
'password_expired',
|
|
43
|
+
'email_not_verified',
|
|
44
|
+
'sign_in_token_invalid',
|
|
45
|
+
'too_many_attempts',
|
|
46
|
+
'too_many_requests',
|
|
47
|
+
'captcha_required',
|
|
48
|
+
'captcha_failed',
|
|
49
|
+
'captcha_unavailable',
|
|
50
|
+
'email_delivery_unavailable',
|
|
51
|
+
'strategy_disabled',
|
|
52
|
+
'sign_up_restricted',
|
|
53
|
+
'waitlisted',
|
|
54
|
+
'identifier_not_allowed',
|
|
55
|
+
'disposable_email_blocked',
|
|
56
|
+
'sso_required',
|
|
57
|
+
'sign_ins_disabled',
|
|
58
|
+
'sign_ups_disabled',
|
|
59
|
+
'high_risk_blocked',
|
|
60
|
+
'sms_region_blocked',
|
|
61
|
+
]);
|
|
62
|
+
/** The catalog key for a reason: `error.<reason>`. */
|
|
63
|
+
function errorReasonKey(reason) {
|
|
64
|
+
return `error.${reason}`;
|
|
65
|
+
}
|
|
66
|
+
/** The English fallback of last resort, so the result is never blank. */
|
|
67
|
+
const GENERIC_ERROR = 'Something went wrong. Please try again.';
|
|
68
|
+
/** A reason is a lower-case token; anything else is never used as a key. */
|
|
69
|
+
const REASON = /^[a-z][a-z0-9_]{0,63}$/;
|
|
70
|
+
/**
|
|
71
|
+
* Fill `{name}` from `meta` (string or finite-number values). Null when a
|
|
72
|
+
* placeholder has no usable value: a sentence with a hole in it is worse than
|
|
73
|
+
* the server's own message, which the server has already filled.
|
|
74
|
+
*/
|
|
75
|
+
function interpolate(template, meta) {
|
|
76
|
+
let complete = true;
|
|
77
|
+
const text = template.replace(/\{(\w+)\}/g, (match, name) => {
|
|
78
|
+
const value = meta && Object.prototype.hasOwnProperty.call(meta, name) ? meta[name] : undefined;
|
|
79
|
+
if (typeof value === 'string' && value !== '')
|
|
80
|
+
return value;
|
|
81
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
82
|
+
return String(value);
|
|
83
|
+
complete = false;
|
|
84
|
+
return match;
|
|
85
|
+
});
|
|
86
|
+
return complete ? text : null;
|
|
87
|
+
}
|
|
88
|
+
function lookup(strings, key) {
|
|
89
|
+
if (!strings)
|
|
90
|
+
return null;
|
|
91
|
+
let value;
|
|
92
|
+
if (typeof strings === 'function') {
|
|
93
|
+
value = strings(key);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
value = Object.prototype.hasOwnProperty.call(strings, key)
|
|
97
|
+
? strings[key]
|
|
98
|
+
: undefined;
|
|
99
|
+
}
|
|
100
|
+
if (typeof value !== 'string')
|
|
101
|
+
return null;
|
|
102
|
+
const text = value.trim();
|
|
103
|
+
return text === '' || text === key ? null : value;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The message to show for a server error, in the app's language:
|
|
107
|
+
*
|
|
108
|
+
* 1. the catalog string `error.<reason>`, when the error has a reason and
|
|
109
|
+
* `strings` has that key, with `{placeholders}` filled from the error's
|
|
110
|
+
* `meta` (a placeholder `meta` cannot fill skips to step 2);
|
|
111
|
+
* 2. else the server's `message` (localised by the server when the client sent
|
|
112
|
+
* `Accept-Language` — see `FapiClientOptions.locale`);
|
|
113
|
+
* 3. else the catalog's `error.generic`, else an English generic sentence.
|
|
114
|
+
*
|
|
115
|
+
* Never returns an empty string. `fallback`, when given, is consulted for
|
|
116
|
+
* `error.generic` after `strings` — handy when `strings` is a language layer
|
|
117
|
+
* without the English defaults underneath it.
|
|
118
|
+
*/
|
|
119
|
+
function localizedErrorMessage(error, strings, fallback) {
|
|
120
|
+
const err = typeof error === 'string' ? { message: error } : (error ?? {});
|
|
121
|
+
const reason = typeof err.reason === 'string' ? err.reason : '';
|
|
122
|
+
if (reason && REASON.test(reason)) {
|
|
123
|
+
const template = lookup(strings, errorReasonKey(reason));
|
|
124
|
+
const text = template ? interpolate(template, err.meta) : null;
|
|
125
|
+
if (text)
|
|
126
|
+
return text;
|
|
127
|
+
}
|
|
128
|
+
if (typeof err.message === 'string' && err.message.trim() !== '')
|
|
129
|
+
return err.message;
|
|
130
|
+
return lookup(strings, 'error.generic') ?? lookup(fallback, 'error.generic') ?? GENERIC_ERROR;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The BCP-47 tag a catalog declares for itself (`@atlasauth/localizations`
|
|
134
|
+
* bundles carry `locale: 'es-ES'`), or undefined. Prebuilt UIs that take a
|
|
135
|
+
* `localization` bundle use it as the `Accept-Language` they send.
|
|
136
|
+
*/
|
|
137
|
+
function catalogLocale(catalog) {
|
|
138
|
+
if (!catalog || typeof catalog !== 'object')
|
|
139
|
+
return undefined;
|
|
140
|
+
const tag = catalog.locale;
|
|
141
|
+
return typeof tag === 'string' && tag.trim() !== '' ? tag : undefined;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAoDH,wCAEC;AAyED,sDAcC;AAOD,sCAIC;AAtJD;;;;GAIG;AACU,QAAA,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IACzC,yBAAyB;IACzB,qBAAqB;IACrB,wBAAwB;IACxB,mBAAmB;IACnB,wBAAwB;IACxB,mBAAmB;IACnB,2BAA2B;IAC3B,wBAAwB;IACxB,qBAAqB;IACrB,yBAAyB;IACzB,wBAAwB;IACxB,kCAAkC;IAClC,kCAAkC;IAClC,+BAA+B;IAC/B,+BAA+B;IAC/B,2BAA2B;IAC3B,mCAAmC;IACnC,+BAA+B;IAC/B,sBAAsB;IACtB,kBAAkB;IAClB,oBAAoB;IACpB,uBAAuB;IACvB,mBAAmB;IACnB,mBAAmB;IACnB,kBAAkB;IAClB,gBAAgB;IAChB,qBAAqB;IACrB,4BAA4B;IAC5B,mBAAmB;IACnB,oBAAoB;IACpB,YAAY;IACZ,wBAAwB;IACxB,0BAA0B;IAC1B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AAO,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,GAAG,CAAC,OAAO,CAAC;IACrF,OAAO,MAAM,CAAC,OAAO,EAAE,eAAe,CAAC,IAAI,MAAM,CAAC,QAAQ,EAAE,eAAe,CAAC,IAAI,aAAa,CAAC;AAChG,CAAC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,OAAkC;IAC9D,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAC9D,MAAM,GAAG,GAAI,OAAgC,CAAC,MAAM,CAAC;IACrD,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AACxE,CAAC"}
|
package/dist/fapi.d.ts
CHANGED
|
@@ -18,7 +18,22 @@ export interface FapiClientOptions {
|
|
|
18
18
|
/** The instance's FAPI origin. Empty for same-origin. */
|
|
19
19
|
baseUrl?: string;
|
|
20
20
|
fetchImpl?: typeof fetch;
|
|
21
|
+
/**
|
|
22
|
+
* The app's UI language as a BCP-47 tag (`"es"`, `"pt-BR"`). When set, every
|
|
23
|
+
* request carries it as `Accept-Language`, so the server writes its error
|
|
24
|
+
* `message`s in that language — the fallback a prebuilt form shows for an
|
|
25
|
+
* error whose `reason` its catalog has no string for. Unset sends no header
|
|
26
|
+
* (the browser's own `Accept-Language` applies). A malformed tag is ignored.
|
|
27
|
+
*/
|
|
28
|
+
locale?: string;
|
|
21
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* A locale tag normalised for the `Accept-Language` header (`pt_BR` → `pt-BR`),
|
|
32
|
+
* or null when it is not a plausible BCP-47 tag. Restricting it to letters,
|
|
33
|
+
* digits and hyphens keeps the header CORS-safelisted, so sending it never adds
|
|
34
|
+
* a preflight to a cross-origin Frontend API call.
|
|
35
|
+
*/
|
|
36
|
+
export declare function acceptLanguageFor(locale: string | null | undefined): string | null;
|
|
22
37
|
export interface FapiResponse<T> {
|
|
23
38
|
ok: boolean;
|
|
24
39
|
status: number;
|
|
@@ -28,6 +43,8 @@ export interface FapiResponse<T> {
|
|
|
28
43
|
export declare class FapiClient {
|
|
29
44
|
private readonly options;
|
|
30
45
|
constructor(options: FapiClientOptions);
|
|
46
|
+
/** The `Accept-Language` this client sends, or null when it sends none. */
|
|
47
|
+
get locale(): string | null;
|
|
31
48
|
/**
|
|
32
49
|
* The origin FAPI serves from — where an OAuth popup's callback page lives, so
|
|
33
50
|
* the popup flow can pin `postMessage`'s `event.origin` to it. Empty `baseUrl`
|
package/dist/fapi.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initialFlow = exports.FapiClient = void 0;
|
|
4
|
+
exports.acceptLanguageFor = acceptLanguageFor;
|
|
4
5
|
exports.getProviderToken = getProviderToken;
|
|
5
6
|
exports.requestForStep = requestForStep;
|
|
6
7
|
exports.flowFromPending = flowFromPending;
|
|
@@ -10,11 +11,27 @@ exports.prepareFactor = prepareFactor;
|
|
|
10
11
|
exports.pollAttempt = pollAttempt;
|
|
11
12
|
exports.shouldKeepPolling = shouldKeepPolling;
|
|
12
13
|
const attempt_1 = require("./attempt");
|
|
14
|
+
/**
|
|
15
|
+
* A locale tag normalised for the `Accept-Language` header (`pt_BR` → `pt-BR`),
|
|
16
|
+
* or null when it is not a plausible BCP-47 tag. Restricting it to letters,
|
|
17
|
+
* digits and hyphens keeps the header CORS-safelisted, so sending it never adds
|
|
18
|
+
* a preflight to a cross-origin Frontend API call.
|
|
19
|
+
*/
|
|
20
|
+
function acceptLanguageFor(locale) {
|
|
21
|
+
if (typeof locale !== 'string')
|
|
22
|
+
return null;
|
|
23
|
+
const tag = locale.trim().replace(/_/g, '-');
|
|
24
|
+
return /^[A-Za-z]{2,8}(-[A-Za-z0-9]{1,8})*$/.test(tag) ? tag : null;
|
|
25
|
+
}
|
|
13
26
|
class FapiClient {
|
|
14
27
|
options;
|
|
15
28
|
constructor(options) {
|
|
16
29
|
this.options = options;
|
|
17
30
|
}
|
|
31
|
+
/** The `Accept-Language` this client sends, or null when it sends none. */
|
|
32
|
+
get locale() {
|
|
33
|
+
return acceptLanguageFor(this.options.locale);
|
|
34
|
+
}
|
|
18
35
|
/**
|
|
19
36
|
* The origin FAPI serves from — where an OAuth popup's callback page lives, so
|
|
20
37
|
* the popup flow can pin `postMessage`'s `event.origin` to it. Empty `baseUrl`
|
|
@@ -33,6 +50,7 @@ class FapiClient {
|
|
|
33
50
|
}
|
|
34
51
|
async request(path, init = {}) {
|
|
35
52
|
const doFetch = this.options.fetchImpl ?? fetch;
|
|
53
|
+
const language = this.locale;
|
|
36
54
|
let response;
|
|
37
55
|
try {
|
|
38
56
|
response = await doFetch(`${this.options.baseUrl ?? ''}${path}`, {
|
|
@@ -42,6 +60,7 @@ class FapiClient {
|
|
|
42
60
|
credentials: 'include',
|
|
43
61
|
headers: {
|
|
44
62
|
'x-publishable-key': this.options.publishableKey,
|
|
63
|
+
...(language ? { 'accept-language': language } : {}),
|
|
45
64
|
...(init.body ? { 'content-type': 'application/json' } : {}),
|
|
46
65
|
...init.headers,
|
|
47
66
|
},
|
|
@@ -57,7 +76,7 @@ class FapiClient {
|
|
|
57
76
|
ok: false,
|
|
58
77
|
status: 0,
|
|
59
78
|
data: null,
|
|
60
|
-
errors: [{ code: 'NETWORK', message: 'We could not reach the server.' }],
|
|
79
|
+
errors: [{ code: 'NETWORK', reason: 'network', message: 'We could not reach the server.' }],
|
|
61
80
|
};
|
|
62
81
|
}
|
|
63
82
|
let body = null;
|
package/dist/fapi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fapi.js","sourceRoot":"","sources":["../src/fapi.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"fapi.js","sourceRoot":"","sources":["../src/fapi.ts"],"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,CAAC,CAAC;AAC5F,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -23,6 +23,8 @@ __exportStar(require("./sign-out-guard"), exports);
|
|
|
23
23
|
__exportStar(require("./token-cache"), exports);
|
|
24
24
|
__exportStar(require("./tab-election"), exports);
|
|
25
25
|
__exportStar(require("./attempt"), exports);
|
|
26
|
+
// Server errors in the app's language (`error.<reason>` catalog keys).
|
|
27
|
+
__exportStar(require("./errors"), exports);
|
|
26
28
|
__exportStar(require("./redirect"), exports);
|
|
27
29
|
// §oauth popup mode: the same-origin hand-back for a popup whose opener was severed.
|
|
28
30
|
__exportStar(require("./popup-channel"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6EAA6E;AAC7E,2CAAyB;AACzB,6CAA2B;AAC3B,sFAAsF;AACtF,mDAAiC;AACjC,gDAA8B;AAC9B,iDAA+B;AAC/B,4CAA0B;AAC1B,6CAA2B;AAC3B,qFAAqF;AACrF,kDAAgC;AAChC,yCAAuB;AACvB,2CAAyB;AACzB,mDAAiC;AACjC,4CAA0B;AAC1B,6CAA2B;AAC3B,yCAAuB;AACvB,8CAA4B;AAC5B,2CAAyB;AACzB,4DAA4D;AAC5D,6CAA2B;AAC3B,4CAA0B;AAC1B,mDAAiC;AACjC,kDAAgC;AAChC,sDAAsD;AACtD,wDAAsC;AACtC,+EAA+E;AAC/E,2EAA2E;AAC3E,4CAA0B;AAC1B,kFAAkF;AAClF,mDAAiC;AACjC,kFAAkF;AAClF,yEAAyE;AACzE,oEAAoE;AACpE,uDAAqC;AACrC,sDAAoC;AACpC,uEAAuE;AACvE,gDAA8B;AAC9B,0EAA0E;AAC1E,4EAA4E;AAC5E,0CAa0B;AARxB,iGAAA,QAAQ,OAAA;AACR,sGAAA,aAAa,OAAA;AACb,0GAAA,iBAAiB,OAAA;AACjB,uGAAA,cAAc,OAAA;AACd,yGAAA,gBAAgB,OAAA;AAChB,+GAAA,sBAAsB,OAAA;AACtB,kGAAA,SAAS,OAAA;AACT,wGAAA,eAAe,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6EAA6E;AAC7E,2CAAyB;AACzB,6CAA2B;AAC3B,sFAAsF;AACtF,mDAAiC;AACjC,gDAA8B;AAC9B,iDAA+B;AAC/B,4CAA0B;AAC1B,uEAAuE;AACvE,2CAAyB;AACzB,6CAA2B;AAC3B,qFAAqF;AACrF,kDAAgC;AAChC,yCAAuB;AACvB,2CAAyB;AACzB,mDAAiC;AACjC,4CAA0B;AAC1B,6CAA2B;AAC3B,yCAAuB;AACvB,8CAA4B;AAC5B,2CAAyB;AACzB,4DAA4D;AAC5D,6CAA2B;AAC3B,4CAA0B;AAC1B,mDAAiC;AACjC,kDAAgC;AAChC,sDAAsD;AACtD,wDAAsC;AACtC,+EAA+E;AAC/E,2EAA2E;AAC3E,4CAA0B;AAC1B,kFAAkF;AAClF,mDAAiC;AACjC,kFAAkF;AAClF,yEAAyE;AACzE,oEAAoE;AACpE,uDAAqC;AACrC,sDAAoC;AACpC,uEAAuE;AACvE,gDAA8B;AAC9B,0EAA0E;AAC1E,4EAA4E;AAC5E,0CAa0B;AARxB,iGAAA,QAAQ,OAAA;AACR,sGAAA,aAAa,OAAA;AACb,0GAAA,iBAAiB,OAAA;AACjB,uGAAA,cAAc,OAAA;AACd,yGAAA,gBAAgB,OAAA;AAChB,+GAAA,sBAAsB,OAAA;AACtB,kGAAA,SAAS,OAAA;AACT,wGAAA,eAAe,OAAA"}
|
package/dist/reauth.d.ts
CHANGED
|
@@ -20,10 +20,12 @@ export interface ReauthOptions {
|
|
|
20
20
|
api: string;
|
|
21
21
|
publishableKey: string;
|
|
22
22
|
fetchImpl?: typeof fetch;
|
|
23
|
+
/** The app's UI language, sent as `Accept-Language` (see `FapiClientOptions.locale`). */
|
|
24
|
+
locale?: string;
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* Re-authenticate the current session. Resolves on success; throws with the
|
|
26
|
-
* server's message (and a `.code`) on failure — `STEP_UP_REQUIRED` cannot recur
|
|
28
|
+
* server's message (and a `.code`, plus `.reason` when the server sent one) on failure — `STEP_UP_REQUIRED` cannot recur
|
|
27
29
|
* here, but a wrong password surfaces as a 401.
|
|
28
30
|
*/
|
|
29
31
|
export declare function reauthenticate(input: ReauthInput, opts: ReauthOptions): Promise<void>;
|
package/dist/reauth.js
CHANGED
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.reauthenticate = reauthenticate;
|
|
13
|
+
const fapi_1 = require("./fapi");
|
|
13
14
|
/**
|
|
14
15
|
* Re-authenticate the current session. Resolves on success; throws with the
|
|
15
|
-
* server's message (and a `.code`) on failure — `STEP_UP_REQUIRED` cannot recur
|
|
16
|
+
* server's message (and a `.code`, plus `.reason` when the server sent one) on failure — `STEP_UP_REQUIRED` cannot recur
|
|
16
17
|
* here, but a wrong password surfaces as a 401.
|
|
17
18
|
*/
|
|
18
19
|
async function reauthenticate(input, opts) {
|
|
@@ -20,25 +21,36 @@ async function reauthenticate(input, opts) {
|
|
|
20
21
|
? { strategy: 'password', password: input.password }
|
|
21
22
|
: { strategy: 'id_token', provider: input.provider, id_token: input.idToken };
|
|
22
23
|
const doFetch = opts.fetchImpl ?? fetch;
|
|
24
|
+
const language = (0, fapi_1.acceptLanguageFor)(opts.locale);
|
|
23
25
|
const res = await doFetch(`${opts.api}/v1/client/me/reauthenticate`, {
|
|
24
26
|
method: 'POST',
|
|
25
|
-
headers: {
|
|
27
|
+
headers: {
|
|
28
|
+
'content-type': 'application/json',
|
|
29
|
+
'x-publishable-key': opts.publishableKey,
|
|
30
|
+
...(language ? { 'accept-language': language } : {}),
|
|
31
|
+
},
|
|
26
32
|
credentials: 'include',
|
|
27
33
|
body: JSON.stringify(body),
|
|
28
34
|
});
|
|
29
35
|
if (!res.ok) {
|
|
30
36
|
let message = 'Re-authentication failed.';
|
|
31
37
|
let code;
|
|
38
|
+
let reason;
|
|
32
39
|
try {
|
|
33
40
|
const parsed = (await res.json());
|
|
34
41
|
message = parsed.errors?.[0]?.message ?? message;
|
|
35
42
|
code = parsed.errors?.[0]?.code;
|
|
43
|
+
const sent = parsed.errors?.[0]?.reason;
|
|
44
|
+
if (typeof sent === 'string' && sent !== '')
|
|
45
|
+
reason = sent;
|
|
36
46
|
}
|
|
37
47
|
catch {
|
|
38
48
|
/* keep the default */
|
|
39
49
|
}
|
|
40
50
|
const err = new Error(message);
|
|
41
51
|
err.code = code;
|
|
52
|
+
if (reason)
|
|
53
|
+
err.reason = reason;
|
|
42
54
|
throw err;
|
|
43
55
|
}
|
|
44
56
|
}
|
package/dist/reauth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reauth.js","sourceRoot":"","sources":["../src/reauth.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;
|
|
1
|
+
{"version":3,"file":"reauth.js","sourceRoot":"","sources":["../src/reauth.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AAsBH,wCAoCC;AAxDD,iCAA2C;AAe3C;;;;GAIG;AACI,KAAK,UAAU,cAAc,CAAC,KAAkB,EAAE,IAAmB;IAC1E,MAAM,IAAI,GACR,KAAK,CAAC,QAAQ,KAAK,UAAU;QAC3B,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE;QACpD,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IAElF,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,I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