@atlasauth/js 0.10.0 → 0.11.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 +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/initial-state.d.ts +34 -0
- package/dist/initial-state.js +53 -0
- package/dist/initial-state.js.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlasauth/js changelog
|
|
2
2
|
|
|
3
|
+
## 0.11.0
|
|
4
|
+
- **New: `fetchAtlasInitialState({ publishableKey, frontendApi, fetchImpl?, init?, timeoutMs? })`** →
|
|
5
|
+
`Promise<AtlasInitialState>` (`{ appearance?: unknown; environment?: unknown }`). Fetches `/v1/appearance` and
|
|
6
|
+
`/v1/client/environment` in parallel on the server, for a provider's `initialState`. Never throws: a part that
|
|
7
|
+
fails or takes longer than `timeoutMs` (default 1500) is left out. `init` is passed to both requests (for example
|
|
8
|
+
`{ next: { revalidate: 60 } }`).
|
|
9
|
+
- New types `AtlasInitialState` and `FetchInitialStateOptions`.
|
|
10
|
+
|
|
3
11
|
## 0.10.0
|
|
4
12
|
- **New: `planFirstFactor(offered)`** → `{ password: boolean; email: ('email_code' | 'email_link')[]; autoSend: 'email_code' | 'email_link' | null }`.
|
|
5
13
|
The rule every prebuilt sign-in form follows: a password field only when the server offers `password`; with no
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __exportStar(require("./token-cache"), exports);
|
|
|
24
24
|
__exportStar(require("./tab-election"), exports);
|
|
25
25
|
__exportStar(require("./attempt"), exports);
|
|
26
26
|
__exportStar(require("./first-factor"), exports);
|
|
27
|
+
__exportStar(require("./initial-state"), exports);
|
|
27
28
|
// Server errors in the app's language (`error.<reason>` catalog keys).
|
|
28
29
|
__exportStar(require("./errors"), exports);
|
|
29
30
|
__exportStar(require("./redirect"), 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,iDAA+B;AAC/B,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"}
|
|
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,iDAA+B;AAC/B,kDAAgC;AAChC,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"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The public, per-instance data a sign-in panel needs before it can paint: the
|
|
3
|
+
* dashboard design and sign-in settings (`GET /v1/appearance`) and the enabled
|
|
4
|
+
* sign-in methods and social buttons (`GET /v1/client/environment`).
|
|
5
|
+
*
|
|
6
|
+
* Fetched on the SERVER and handed to the provider (`initialState`), the panel
|
|
7
|
+
* renders fully styled, with its social buttons, in the first HTML — no
|
|
8
|
+
* round trips from the browser before it looks right. Both responses are public
|
|
9
|
+
* and identical for every visitor of an instance, so they cache well.
|
|
10
|
+
*
|
|
11
|
+
* Never throws: a part that can't be fetched is left out and the browser fetches
|
|
12
|
+
* it as before, so a slow or unreachable API can't break the page render.
|
|
13
|
+
*/
|
|
14
|
+
export interface AtlasInitialState {
|
|
15
|
+
/** The raw `GET /v1/appearance` body. */
|
|
16
|
+
appearance?: unknown;
|
|
17
|
+
/** The raw `GET /v1/client/environment` body. */
|
|
18
|
+
environment?: unknown;
|
|
19
|
+
}
|
|
20
|
+
export interface FetchInitialStateOptions {
|
|
21
|
+
publishableKey: string;
|
|
22
|
+
/** The Frontend API origin, e.g. `https://auth.example.com`. */
|
|
23
|
+
frontendApi: string;
|
|
24
|
+
/** Defaults to the global `fetch`. */
|
|
25
|
+
fetchImpl?: typeof fetch;
|
|
26
|
+
/**
|
|
27
|
+
* Extra `fetch` options for both requests — e.g. `{ next: { revalidate: 60 } }`
|
|
28
|
+
* on Next.js to cache them between renders.
|
|
29
|
+
*/
|
|
30
|
+
init?: RequestInit & Record<string, unknown>;
|
|
31
|
+
/** Give up on a request after this long and leave it to the browser. Default 1500 ms. */
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
}
|
|
34
|
+
export declare function fetchAtlasInitialState(options: FetchInitialStateOptions): Promise<AtlasInitialState>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The public, per-instance data a sign-in panel needs before it can paint: the
|
|
4
|
+
* dashboard design and sign-in settings (`GET /v1/appearance`) and the enabled
|
|
5
|
+
* sign-in methods and social buttons (`GET /v1/client/environment`).
|
|
6
|
+
*
|
|
7
|
+
* Fetched on the SERVER and handed to the provider (`initialState`), the panel
|
|
8
|
+
* renders fully styled, with its social buttons, in the first HTML — no
|
|
9
|
+
* round trips from the browser before it looks right. Both responses are public
|
|
10
|
+
* and identical for every visitor of an instance, so they cache well.
|
|
11
|
+
*
|
|
12
|
+
* Never throws: a part that can't be fetched is left out and the browser fetches
|
|
13
|
+
* it as before, so a slow or unreachable API can't break the page render.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.fetchAtlasInitialState = fetchAtlasInitialState;
|
|
17
|
+
async function fetchAtlasInitialState(options) {
|
|
18
|
+
const doFetch = options.fetchImpl ?? (typeof fetch === 'function' ? fetch : undefined);
|
|
19
|
+
if (!doFetch || !options.publishableKey || !options.frontendApi)
|
|
20
|
+
return {};
|
|
21
|
+
const base = options.frontendApi.replace(/\/+$/, '');
|
|
22
|
+
const timeoutMs = options.timeoutMs ?? 1500;
|
|
23
|
+
const get = async (path) => {
|
|
24
|
+
const controller = typeof AbortController === 'function' ? new AbortController() : null;
|
|
25
|
+
const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : null;
|
|
26
|
+
try {
|
|
27
|
+
const res = await doFetch(`${base}${path}`, {
|
|
28
|
+
...options.init,
|
|
29
|
+
method: 'GET',
|
|
30
|
+
headers: { accept: 'application/json', 'x-publishable-key': options.publishableKey },
|
|
31
|
+
...(controller ? { signal: controller.signal } : {}),
|
|
32
|
+
});
|
|
33
|
+
if (!res.ok)
|
|
34
|
+
return undefined;
|
|
35
|
+
return (await res.json());
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
if (timer)
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const [appearance, environment] = await Promise.all([get('/v1/appearance'), get('/v1/client/environment')]);
|
|
46
|
+
const state = {};
|
|
47
|
+
if (appearance && typeof appearance === 'object')
|
|
48
|
+
state.appearance = appearance;
|
|
49
|
+
if (environment && typeof environment === 'object')
|
|
50
|
+
state.environment = environment;
|
|
51
|
+
return state;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=initial-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initial-state.js","sourceRoot":"","sources":["../src/initial-state.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAwBH,wDA8BC;AA9BM,KAAK,UAAU,sBAAsB,CAAC,OAAiC;IAC5E,MAAM,OAA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