@tempoxyz/id 0.0.0-pr-523.sha-e149f6b → 0.0.0-pr-523.sha-c981aec
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/internal/core.js +1 -1
- package/dist/internal/core.js.map +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +52 -39
- package/dist/react/index.js.map +1 -1
- package/dist/react/restore.machine.d.ts +84 -0
- package/dist/react/restore.machine.d.ts.map +1 -0
- package/dist/react/restore.machine.js +110 -0
- package/dist/react/restore.machine.js.map +1 -0
- package/package.json +1 -1
- package/src/internal/core.ts +1 -1
- package/src/react/index.ts +60 -40
- package/src/react/restore.machine.ts +154 -0
package/dist/internal/core.js
CHANGED
|
@@ -215,8 +215,8 @@ export async function getSession(context, options) {
|
|
|
215
215
|
}
|
|
216
216
|
/** The reasons of a refusal that only an interactive sign-in resolves, which `getSession` returns as no session. */
|
|
217
217
|
const interactive = new Set([
|
|
218
|
+
// `rejected` also covers an app's registration or scope, which no sign-in resolves, so it throws.
|
|
218
219
|
'reauthentication_required',
|
|
219
|
-
'rejected',
|
|
220
220
|
'upgrade_required',
|
|
221
221
|
'webauthn_required',
|
|
222
222
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/internal/core.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,OAAO,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AACxD,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAA;AAI5C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;;GAIG;AACH,MAAM,UAAU,SAAS,CACvB,OAAuB,EACvB,UAAU,GAAyB,EAAE;IAErC,4EAA4E;IAC5E,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,GA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GAAG,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAA;QACvD,CAAC,CAAC,CAAA;IACJ,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,KAAK,IAAI,MAAM,qBAAqB,CAAA;AAChD,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,KAAK,KAAK,OAAO,MAAM,eAAe,CAAA;AAG7C;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAC,OAAO,GAAE,KAAK,CAAC,OAAY;IAwEzC;;;;;;OAMG;kBACW,UAAU,CAAC,UAAU;GAoB1C;AAED,MAAM,CAAC,OAAO,WAAW,KAAK,CAAC;IAC7B,KAAK,OAAO,GAAG;QACb;;;;;;;;WAQG;QACH,kBAAkB,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,aAAa,CAAC,CAAA;KAC/D,CAAA;CACF;AAED,MAAM,CAAC,OAAO,WAAW,UAAU,CAAC;IAClC,kFAAkF;IAClF,KAAK,UAAU,GAAG;SACf,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,OAAO,CAC3C,OAAO,CAAC,MAAM,EACd;YAAE,MAAM,EAAE,MAAM,CAAA;SAAE,CACnB,GAAG;YACF,qGAAqG;YACrG,SAAS,EAAE,MAAM,SAAS,SAAS,GAAG,IAAI,GAAG,KAAK,CAAA;YAClD,4FAA4F;YAC5F,eAAe,EAAE,MAAM,SAAS,eAAe,GAAG,IAAI,GAAG,KAAK,CAAA;YAC9D,wCAAwC;YACxC,UAAU,EAAE,MAAM,SAAS,UAAU,GAAG,IAAI,GAAG,KAAK,CAAA;YACpD,yCAAyC;YACzC,WAAW,EAAE,MAAM,SAAS,WAAW,GAAG,IAAI,GAAG,KAAK,CAAA;SACvD;KACF,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAA;CAC5B"}
|
package/dist/react/index.js
CHANGED
|
@@ -10,8 +10,10 @@
|
|
|
10
10
|
*/
|
|
11
11
|
/* istanbul ignore file -- The hook runs only in a React render in a browser, which only an app drives. */
|
|
12
12
|
import * as React from 'react';
|
|
13
|
+
import { createActor, fromPromise, waitFor } from 'xstate';
|
|
13
14
|
import * as ClientId from '../internal/clientId.js';
|
|
14
15
|
import * as Plugin from '../Plugin.js';
|
|
16
|
+
import * as RestoreMachine from './restore.machine.js';
|
|
15
17
|
/**
|
|
16
18
|
* Returns the plugin of React, which adds `tempoId.useSession()`.
|
|
17
19
|
*
|
|
@@ -35,46 +37,57 @@ export function react(options = {}) {
|
|
|
35
37
|
const defaulted = options.reauthorizeOnMount === undefined &&
|
|
36
38
|
typeof document !== 'undefined' &&
|
|
37
39
|
!ClientId.thirdParty(instance.config.clientId);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
// The machine decides whether a mount authorizes, and shares one restore between the mounts
|
|
41
|
+
// that arrive while it runs. It skips the authorization only for a page that the plugin's own
|
|
42
|
+
// authorization found signed out, so it moves no signed-out page back to `pending`, which
|
|
43
|
+
// could unmount and mount that page's components again without end.
|
|
44
|
+
const actor = createActor(RestoreMachine.machine.provide({
|
|
45
|
+
actors: {
|
|
46
|
+
restore: fromPromise(async (args) => {
|
|
47
|
+
// Whether the default authorization failed transiently, such as while Tempo ID is
|
|
48
|
+
// unreachable, which the next mount retries. A refusal that repeats at every
|
|
49
|
+
// attempt, such as `webauthn_required`, is a decline.
|
|
50
|
+
let failed = false;
|
|
51
|
+
const reauthorize = defaulted
|
|
52
|
+
? async () => {
|
|
53
|
+
const result = await instance
|
|
54
|
+
.authorize()
|
|
55
|
+
.catch((error) => {
|
|
56
|
+
failed = RestoreMachine.transient(error);
|
|
57
|
+
return undefined;
|
|
58
|
+
});
|
|
59
|
+
if (!result)
|
|
60
|
+
return undefined;
|
|
61
|
+
const { upgradeAvailable: _, ...session } = result;
|
|
62
|
+
return session;
|
|
63
|
+
}
|
|
64
|
+
: options.reauthorizeOnMount;
|
|
65
|
+
await instance.session
|
|
66
|
+
.get(args.input.reauthorize ? { reauthorize } : {})
|
|
67
|
+
.catch((error) => {
|
|
68
|
+
// A sign-out or a newer sign-in overtook the restore, and the status shows it.
|
|
69
|
+
// The class lives in `Id.js`, which this entry does not load, so its name
|
|
70
|
+
// identifies it.
|
|
71
|
+
if (error instanceof Error &&
|
|
72
|
+
error.name === 'Id.SupersededError')
|
|
73
|
+
return undefined;
|
|
74
|
+
throw error;
|
|
75
|
+
});
|
|
76
|
+
const declined = !failed &&
|
|
77
|
+
instance.session.status.get().status === 'signedOut';
|
|
78
|
+
return { declined };
|
|
79
|
+
}),
|
|
80
|
+
},
|
|
81
|
+
})).start();
|
|
82
|
+
// A sign-in or a sign-out after a decline lets the next mount authorize again.
|
|
83
|
+
instance.session.status.subscribe(() => actor.send({ type: 'status' }));
|
|
84
|
+
/** Restores the session at a mount, and throws the error of a restore that failed. */
|
|
85
|
+
async function restore() {
|
|
86
|
+
actor.send({ type: 'mount' });
|
|
87
|
+
const snapshot = await waitFor(actor, (snapshot) => !RestoreMachine.running(snapshot));
|
|
88
|
+
if (snapshot.context.error !== undefined)
|
|
89
|
+
throw snapshot.context.error;
|
|
50
90
|
}
|
|
51
|
-
// The first renders of the components that mount together share one restore. A later mount
|
|
52
|
-
// restores again, so it checks the expiry of the session's access key, and renews it. It skips
|
|
53
|
-
// the authorization only while the status is the `signedOut` that this plugin's own
|
|
54
|
-
// authorization returned, so it moves no signed-out page back to `pending`, which could
|
|
55
|
-
// unmount and mount that page's components again without end. `status.get` returns the same
|
|
56
|
-
// object until the status changes, so a later sign-in or sign-out authorizes again.
|
|
57
|
-
let declined;
|
|
58
|
-
let restoring;
|
|
59
|
-
const restore = () => {
|
|
60
|
-
const skip = instance.session.status.get() === declined;
|
|
61
|
-
return (restoring ??= instance.session
|
|
62
|
-
.get(skip ? {} : { reauthorize })
|
|
63
|
-
.then(() => {
|
|
64
|
-
const status = instance.session.status.get();
|
|
65
|
-
if (!skip && status.status === 'signedOut')
|
|
66
|
-
declined = status;
|
|
67
|
-
}, (error) => {
|
|
68
|
-
// A sign-out or a newer sign-in overtook the restore, and the status shows it. The
|
|
69
|
-
// class lives in `Id.js`, which this entry does not load, so its name identifies it.
|
|
70
|
-
if (error instanceof Error && error.name === 'Id.SupersededError')
|
|
71
|
-
return undefined;
|
|
72
|
-
throw error;
|
|
73
|
-
})
|
|
74
|
-
.finally(() => {
|
|
75
|
-
restoring = undefined;
|
|
76
|
-
}));
|
|
77
|
-
};
|
|
78
91
|
return {
|
|
79
92
|
/**
|
|
80
93
|
* Returns the session's status and the session to show, and renders again at each change.
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,0GAA0G;AAC1G,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,0GAA0G;AAC1G,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAE1D,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAA;AAEnD,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AAEtC,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAA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OAAO,CAAC,MAAM,CAAC,GAAG,EAC3B,GAAG,EAAE,CAAC,OAAO,CACd,CAAA;oBACD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAA;oBAChE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAW,CAAA;oBAEnD,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;wBACnB,OAAO,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;oBAC3B,CAAC,EAAE,EAAE,CAAC,CAAA;oBAEN,IAAI,KAAK;wBAAE,MAAM,KAAK,CAAA;oBACtB,OAAO,OAAO,CAAA;gBAChB,CAAC;aACF,CAAA;QACH,CAAC;QACD,EAAE,EAAE,OAAO;KACZ,CAAC,CAAA;AACJ,CAAC;AAoCD,qCAAqC;AACrC,MAAM,OAAO,GAAmB,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,CAAA;AAEzE,oDAAoD;AACpD,SAAS,SAAS,CAAC,MAAsB;IACvC,OAAO;QACL,GAAG,MAAM;QACT,SAAS,EAAE,MAAM,CAAC,MAAM,KAAK,SAAS;QACtC,eAAe,EAAE,MAAM,CAAC,MAAM,KAAK,eAAe;QAClD,UAAU,EAAE,MAAM,CAAC,MAAM,KAAK,UAAU;QACxC,WAAW,EAAE,MAAM,CAAC,MAAM,KAAK,WAAW;QAC1C,+EAA+E;KACvD,CAAA;AAC5B,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The state machine of the React plugin's restore: whether a mount authorizes the browser's Tempo
|
|
3
|
+
* ID session, which mounts share one run, and when a page that the authorization found signed out
|
|
4
|
+
* stays so. It holds no I/O. `react/index.ts` provides the `restore` actor and runs the machine.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { type Actor as XStateActor } from 'xstate';
|
|
8
|
+
/** The context of the machine. */
|
|
9
|
+
export type Context = {
|
|
10
|
+
/** The error of the last restore, which every mount that awaited it throws. Absent after a success. */
|
|
11
|
+
error: unknown;
|
|
12
|
+
};
|
|
13
|
+
/** An event of the machine. */
|
|
14
|
+
export type Event = {
|
|
15
|
+
/** A component that reads the session mounted, and restores it. */
|
|
16
|
+
type: 'mount';
|
|
17
|
+
} | {
|
|
18
|
+
/** The session's status changed, such as at a sign-in, so a later mount authorizes again. */
|
|
19
|
+
type: 'status';
|
|
20
|
+
};
|
|
21
|
+
/** The input of a restore. */
|
|
22
|
+
export type Input = {
|
|
23
|
+
/** Whether the restore authorizes the browser's Tempo ID session when it finds no session. */
|
|
24
|
+
reauthorize: boolean;
|
|
25
|
+
};
|
|
26
|
+
/** The output of a restore. */
|
|
27
|
+
export type Output = {
|
|
28
|
+
/**
|
|
29
|
+
* Whether the restore left the page signed out with no failure, so the next mount skips the
|
|
30
|
+
* authorization. A failure that the restore swallowed, such as an unreachable Tempo ID, is no
|
|
31
|
+
* decline, so the next mount retries.
|
|
32
|
+
*/
|
|
33
|
+
declined: boolean;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* The machine.
|
|
37
|
+
*
|
|
38
|
+
* | State | A mount |
|
|
39
|
+
* | ------------- | ------------------------------------------- |
|
|
40
|
+
* | `idle` | Starts a restore that authorizes. |
|
|
41
|
+
* | `authorizing` | Shares the restore in progress. |
|
|
42
|
+
* | `declined` | Starts a restore that does not authorize. |
|
|
43
|
+
* | `checking` | Shares the restore in progress. |
|
|
44
|
+
*/
|
|
45
|
+
export declare const machine: import("xstate").StateMachine<Context, Event, {
|
|
46
|
+
[x: string]: import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<Output, Input, import("xstate").EventObject>> | undefined;
|
|
47
|
+
}, {
|
|
48
|
+
src: "restore";
|
|
49
|
+
logic: import("xstate").PromiseActorLogic<Output, Input, import("xstate").EventObject>;
|
|
50
|
+
id: string | undefined;
|
|
51
|
+
}, {
|
|
52
|
+
type: "fail";
|
|
53
|
+
params: {
|
|
54
|
+
error: unknown;
|
|
55
|
+
};
|
|
56
|
+
} | {
|
|
57
|
+
type: "start";
|
|
58
|
+
params: import("xstate").NonReducibleUnknown;
|
|
59
|
+
}, {
|
|
60
|
+
type: "declined";
|
|
61
|
+
params: Output;
|
|
62
|
+
}, never, "authorizing" | "checking" | "declined" | "idle", string, import("xstate").NonReducibleUnknown, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, {
|
|
63
|
+
id: "restore";
|
|
64
|
+
states: {
|
|
65
|
+
readonly authorizing: {};
|
|
66
|
+
readonly checking: {};
|
|
67
|
+
readonly declined: {};
|
|
68
|
+
readonly idle: {};
|
|
69
|
+
};
|
|
70
|
+
}, import("xstate").MetaObject>;
|
|
71
|
+
/** A running instance of {@link machine}. */
|
|
72
|
+
export type Actor = XStateActor<typeof machine>;
|
|
73
|
+
/** A snapshot of {@link machine}. */
|
|
74
|
+
export type Snapshot = ReturnType<Actor['getSnapshot']>;
|
|
75
|
+
/** Returns whether a restore is in progress, which a mount awaits. */
|
|
76
|
+
export declare function running(snapshot: Snapshot): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Returns whether a failure of the default authorization is transient, so the next mount retries:
|
|
79
|
+
* an error without Tempo ID's answer, a server error, or a refusal for load. Any other refusal,
|
|
80
|
+
* such as `webauthn_required`, repeats at every attempt, so it is a decline. The entry loads no
|
|
81
|
+
* error class, so the error's name and fields identify a `RequestError`.
|
|
82
|
+
*/
|
|
83
|
+
export declare function transient(error: unknown): boolean;
|
|
84
|
+
//# sourceMappingURL=restore.machine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restore.machine.d.ts","sourceRoot":"","sources":["../../src/react/restore.machine.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,KAAK,KAAK,IAAI,WAAW,EAA8B,MAAM,QAAQ,CAAA;AAE9E,kCAAkC;AAClC,MAAM,MAAM,OAAO,GAAG;IACpB,uGAAuG;IACvG,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAED,+BAA+B;AAC/B,MAAM,MAAM,KAAK,GACb;IACE,mEAAmE;IACnE,IAAI,EAAE,OAAO,CAAA;CACd,GACD;IACE,6FAA6F;IAC7F,IAAI,EAAE,QAAQ,CAAA;CACf,CAAA;AAEL,8BAA8B;AAC9B,MAAM,MAAM,KAAK,GAAG;IAClB,8FAA8F;IAC9F,WAAW,EAAE,OAAO,CAAA;CACrB,CAAA;AAED,+BAA+B;AAC/B,MAAM,MAAM,MAAM,GAAG;IACnB;;;;OAIG;IACH,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO;;;;;;;;;eAGkB,OAAO;;;;;;;;;;;;;;;;+BAwE3C,CAAA;AAEF,6CAA6C;AAC7C,MAAM,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,OAAO,CAAC,CAAA;AAE/C,qCAAqC;AACrC,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAA;AAEvD,sEAAsE;AACtE,wBAAgB,OAAO,CAAC,QAAQ,EAAE,QAAQ,WAEzC;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,WAQvC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The state machine of the React plugin's restore: whether a mount authorizes the browser's Tempo
|
|
3
|
+
* ID session, which mounts share one run, and when a page that the authorization found signed out
|
|
4
|
+
* stays so. It holds no I/O. `react/index.ts` provides the `restore` actor and runs the machine.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { assign, fromPromise, setup } from 'xstate';
|
|
8
|
+
/**
|
|
9
|
+
* The machine.
|
|
10
|
+
*
|
|
11
|
+
* | State | A mount |
|
|
12
|
+
* | ------------- | ------------------------------------------- |
|
|
13
|
+
* | `idle` | Starts a restore that authorizes. |
|
|
14
|
+
* | `authorizing` | Shares the restore in progress. |
|
|
15
|
+
* | `declined` | Starts a restore that does not authorize. |
|
|
16
|
+
* | `checking` | Shares the restore in progress. |
|
|
17
|
+
*/
|
|
18
|
+
export const machine = setup({
|
|
19
|
+
actions: {
|
|
20
|
+
/** Records the error of the restore. */
|
|
21
|
+
fail: assign((_, params) => ({ error: params.error })),
|
|
22
|
+
/** Clears the error of the last restore. */
|
|
23
|
+
start: assign({ error: undefined }),
|
|
24
|
+
},
|
|
25
|
+
actors: {
|
|
26
|
+
/** Restores the session. `react/index.ts` provides it. */
|
|
27
|
+
restore: fromPromise(() => Promise.resolve({ declined: false })),
|
|
28
|
+
},
|
|
29
|
+
guards: {
|
|
30
|
+
/** Whether the restore left the page signed out with no failure. */
|
|
31
|
+
declined: (_, params) => params.declined,
|
|
32
|
+
},
|
|
33
|
+
types: {
|
|
34
|
+
context: {},
|
|
35
|
+
events: {},
|
|
36
|
+
},
|
|
37
|
+
}).createMachine({
|
|
38
|
+
context: { error: undefined },
|
|
39
|
+
id: 'restore',
|
|
40
|
+
initial: 'idle',
|
|
41
|
+
states: {
|
|
42
|
+
authorizing: {
|
|
43
|
+
entry: 'start',
|
|
44
|
+
invoke: {
|
|
45
|
+
input: { reauthorize: true },
|
|
46
|
+
onDone: [
|
|
47
|
+
{
|
|
48
|
+
guard: { params: (args) => args.event.output, type: 'declined' },
|
|
49
|
+
target: 'declined',
|
|
50
|
+
},
|
|
51
|
+
{ target: 'idle' },
|
|
52
|
+
],
|
|
53
|
+
onError: {
|
|
54
|
+
actions: {
|
|
55
|
+
params: (args) => ({ error: args.event.error }),
|
|
56
|
+
type: 'fail',
|
|
57
|
+
},
|
|
58
|
+
target: 'idle',
|
|
59
|
+
},
|
|
60
|
+
src: 'restore',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
checking: {
|
|
64
|
+
entry: 'start',
|
|
65
|
+
invoke: {
|
|
66
|
+
input: { reauthorize: false },
|
|
67
|
+
onDone: [
|
|
68
|
+
{
|
|
69
|
+
guard: { params: (args) => args.event.output, type: 'declined' },
|
|
70
|
+
target: 'declined',
|
|
71
|
+
},
|
|
72
|
+
{ target: 'idle' },
|
|
73
|
+
],
|
|
74
|
+
onError: {
|
|
75
|
+
actions: {
|
|
76
|
+
params: (args) => ({ error: args.event.error }),
|
|
77
|
+
type: 'fail',
|
|
78
|
+
},
|
|
79
|
+
target: 'idle',
|
|
80
|
+
},
|
|
81
|
+
src: 'restore',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
declined: {
|
|
85
|
+
on: { mount: 'checking', status: 'idle' },
|
|
86
|
+
},
|
|
87
|
+
idle: {
|
|
88
|
+
on: { mount: 'authorizing' },
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
/** Returns whether a restore is in progress, which a mount awaits. */
|
|
93
|
+
export function running(snapshot) {
|
|
94
|
+
return snapshot.matches('authorizing') || snapshot.matches('checking');
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Returns whether a failure of the default authorization is transient, so the next mount retries:
|
|
98
|
+
* an error without Tempo ID's answer, a server error, or a refusal for load. Any other refusal,
|
|
99
|
+
* such as `webauthn_required`, repeats at every attempt, so it is a decline. The entry loads no
|
|
100
|
+
* error class, so the error's name and fields identify a `RequestError`.
|
|
101
|
+
*/
|
|
102
|
+
export function transient(error) {
|
|
103
|
+
if (!(error instanceof Error) || error.name !== 'Id.RequestError')
|
|
104
|
+
return true;
|
|
105
|
+
const { reason, status } = error;
|
|
106
|
+
if (status === undefined || status === 0 || status >= 500)
|
|
107
|
+
return true;
|
|
108
|
+
return reason === 'rate_limited' || reason === 'upstream_unavailable';
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=restore.machine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restore.machine.js","sourceR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KG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB;QAAE,OAAO,IAAI,CAAA;IAC9E,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAG1B,CAAA;IACD,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,CAAC,IAAI,MAAM,IAAI,GAAG;QAAE,OAAO,IAAI,CAAA;IACtE,OAAO,MAAM,KAAK,cAAc,IAAI,MAAM,KAAK,sBAAsB,CAAA;AACvE,CAAC"}
|
package/package.json
CHANGED
package/src/internal/core.ts
CHANGED
|
@@ -280,8 +280,8 @@ export async function getSession(
|
|
|
280
280
|
|
|
281
281
|
/** The reasons of a refusal that only an interactive sign-in resolves, which `getSession` returns as no session. */
|
|
282
282
|
const interactive = new Set<RequestError.Reason>([
|
|
283
|
+
// `rejected` also covers an app's registration or scope, which no sign-in resolves, so it throws.
|
|
283
284
|
'reauthentication_required',
|
|
284
|
-
'rejected',
|
|
285
285
|
'upgrade_required',
|
|
286
286
|
'webauthn_required',
|
|
287
287
|
])
|
package/src/react/index.ts
CHANGED
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
*/
|
|
11
11
|
/* istanbul ignore file -- The hook runs only in a React render in a browser, which only an app drives. */
|
|
12
12
|
import * as React from 'react'
|
|
13
|
+
import { createActor, fromPromise, waitFor } from 'xstate'
|
|
13
14
|
import type * as Id from '../Id.js'
|
|
14
15
|
import * as ClientId from '../internal/clientId.js'
|
|
15
16
|
import type * as Core from '../internal/core.js'
|
|
16
17
|
import * as Plugin from '../Plugin.js'
|
|
17
18
|
import type * as Session from '../Session.js'
|
|
19
|
+
import * as RestoreMachine from './restore.machine.js'
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
22
|
* Returns the plugin of React, which adds `tempoId.useSession()`.
|
|
@@ -40,48 +42,66 @@ export function react(options: react.Options = {}) {
|
|
|
40
42
|
options.reauthorizeOnMount === undefined &&
|
|
41
43
|
typeof document !== 'undefined' &&
|
|
42
44
|
!ClientId.thirdParty(instance.config.clientId)
|
|
43
|
-
const reauthorize = defaulted ? quiet : options.reauthorizeOnMount
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
46
|
+
// The machine decides whether a mount authorizes, and shares one restore between the mounts
|
|
47
|
+
// that arrive while it runs. It skips the authorization only for a page that the plugin's own
|
|
48
|
+
// authorization found signed out, so it moves no signed-out page back to `pending`, which
|
|
49
|
+
// could unmount and mount that page's components again without end.
|
|
50
|
+
const actor = createActor(
|
|
51
|
+
RestoreMachine.machine.provide({
|
|
52
|
+
actors: {
|
|
53
|
+
restore: fromPromise<RestoreMachine.Output, RestoreMachine.Input>(
|
|
54
|
+
async (args) => {
|
|
55
|
+
// Whether the default authorization failed transiently, such as while Tempo ID is
|
|
56
|
+
// unreachable, which the next mount retries. A refusal that repeats at every
|
|
57
|
+
// attempt, such as `webauthn_required`, is a decline.
|
|
58
|
+
let failed = false
|
|
59
|
+
const reauthorize = defaulted
|
|
60
|
+
? async () => {
|
|
61
|
+
const result = await instance
|
|
62
|
+
.authorize()
|
|
63
|
+
.catch((error: unknown) => {
|
|
64
|
+
failed = RestoreMachine.transient(error)
|
|
65
|
+
return undefined
|
|
66
|
+
})
|
|
67
|
+
if (!result) return undefined
|
|
68
|
+
const { upgradeAvailable: _, ...session } = result
|
|
69
|
+
return session
|
|
70
|
+
}
|
|
71
|
+
: options.reauthorizeOnMount
|
|
72
|
+
await instance.session
|
|
73
|
+
.get(args.input.reauthorize ? { reauthorize } : {})
|
|
74
|
+
.catch((error: unknown) => {
|
|
75
|
+
// A sign-out or a newer sign-in overtook the restore, and the status shows it.
|
|
76
|
+
// The class lives in `Id.js`, which this entry does not load, so its name
|
|
77
|
+
// identifies it.
|
|
78
|
+
if (
|
|
79
|
+
error instanceof Error &&
|
|
80
|
+
error.name === 'Id.SupersededError'
|
|
81
|
+
)
|
|
82
|
+
return undefined
|
|
83
|
+
throw error
|
|
84
|
+
})
|
|
85
|
+
const declined =
|
|
86
|
+
!failed &&
|
|
87
|
+
instance.session.status.get().status === 'signedOut'
|
|
88
|
+
return { declined }
|
|
89
|
+
},
|
|
90
|
+
),
|
|
91
|
+
},
|
|
92
|
+
}),
|
|
93
|
+
).start()
|
|
94
|
+
// A sign-in or a sign-out after a decline lets the next mount authorize again.
|
|
95
|
+
instance.session.status.subscribe(() => actor.send({ type: 'status' }))
|
|
56
96
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const restore = () => {
|
|
66
|
-
const skip = instance.session.status.get() === declined
|
|
67
|
-
return (restoring ??= instance.session
|
|
68
|
-
.get(skip ? {} : { reauthorize })
|
|
69
|
-
.then(
|
|
70
|
-
() => {
|
|
71
|
-
const status = instance.session.status.get()
|
|
72
|
-
if (!skip && status.status === 'signedOut') declined = status
|
|
73
|
-
},
|
|
74
|
-
(error: unknown) => {
|
|
75
|
-
// A sign-out or a newer sign-in overtook the restore, and the status shows it. The
|
|
76
|
-
// class lives in `Id.js`, which this entry does not load, so its name identifies it.
|
|
77
|
-
if (error instanceof Error && error.name === 'Id.SupersededError')
|
|
78
|
-
return undefined
|
|
79
|
-
throw error
|
|
80
|
-
},
|
|
81
|
-
)
|
|
82
|
-
.finally(() => {
|
|
83
|
-
restoring = undefined
|
|
84
|
-
}))
|
|
97
|
+
/** Restores the session at a mount, and throws the error of a restore that failed. */
|
|
98
|
+
async function restore() {
|
|
99
|
+
actor.send({ type: 'mount' })
|
|
100
|
+
const snapshot = await waitFor(
|
|
101
|
+
actor,
|
|
102
|
+
(snapshot) => !RestoreMachine.running(snapshot),
|
|
103
|
+
)
|
|
104
|
+
if (snapshot.context.error !== undefined) throw snapshot.context.error
|
|
85
105
|
}
|
|
86
106
|
|
|
87
107
|
return {
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The state machine of the React plugin's restore: whether a mount authorizes the browser's Tempo
|
|
3
|
+
* ID session, which mounts share one run, and when a page that the authorization found signed out
|
|
4
|
+
* stays so. It holds no I/O. `react/index.ts` provides the `restore` actor and runs the machine.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { type Actor as XStateActor, assign, fromPromise, setup } from 'xstate'
|
|
8
|
+
|
|
9
|
+
/** The context of the machine. */
|
|
10
|
+
export type Context = {
|
|
11
|
+
/** The error of the last restore, which every mount that awaited it throws. Absent after a success. */
|
|
12
|
+
error: unknown
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** An event of the machine. */
|
|
16
|
+
export type Event =
|
|
17
|
+
| {
|
|
18
|
+
/** A component that reads the session mounted, and restores it. */
|
|
19
|
+
type: 'mount'
|
|
20
|
+
}
|
|
21
|
+
| {
|
|
22
|
+
/** The session's status changed, such as at a sign-in, so a later mount authorizes again. */
|
|
23
|
+
type: 'status'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The input of a restore. */
|
|
27
|
+
export type Input = {
|
|
28
|
+
/** Whether the restore authorizes the browser's Tempo ID session when it finds no session. */
|
|
29
|
+
reauthorize: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The output of a restore. */
|
|
33
|
+
export type Output = {
|
|
34
|
+
/**
|
|
35
|
+
* Whether the restore left the page signed out with no failure, so the next mount skips the
|
|
36
|
+
* authorization. A failure that the restore swallowed, such as an unreachable Tempo ID, is no
|
|
37
|
+
* decline, so the next mount retries.
|
|
38
|
+
*/
|
|
39
|
+
declined: boolean
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The machine.
|
|
44
|
+
*
|
|
45
|
+
* | State | A mount |
|
|
46
|
+
* | ------------- | ------------------------------------------- |
|
|
47
|
+
* | `idle` | Starts a restore that authorizes. |
|
|
48
|
+
* | `authorizing` | Shares the restore in progress. |
|
|
49
|
+
* | `declined` | Starts a restore that does not authorize. |
|
|
50
|
+
* | `checking` | Shares the restore in progress. |
|
|
51
|
+
*/
|
|
52
|
+
export const machine = setup({
|
|
53
|
+
actions: {
|
|
54
|
+
/** Records the error of the restore. */
|
|
55
|
+
fail: assign((_, params: { error: unknown }) => ({ error: params.error })),
|
|
56
|
+
/** Clears the error of the last restore. */
|
|
57
|
+
start: assign({ error: undefined }),
|
|
58
|
+
},
|
|
59
|
+
actors: {
|
|
60
|
+
/** Restores the session. `react/index.ts` provides it. */
|
|
61
|
+
restore: fromPromise<Output, Input>(() =>
|
|
62
|
+
Promise.resolve({ declined: false }),
|
|
63
|
+
),
|
|
64
|
+
},
|
|
65
|
+
guards: {
|
|
66
|
+
/** Whether the restore left the page signed out with no failure. */
|
|
67
|
+
declined: (_, params: Output) => params.declined,
|
|
68
|
+
},
|
|
69
|
+
types: {
|
|
70
|
+
context: {} as Context,
|
|
71
|
+
events: {} as Event,
|
|
72
|
+
},
|
|
73
|
+
}).createMachine({
|
|
74
|
+
context: { error: undefined },
|
|
75
|
+
id: 'restore',
|
|
76
|
+
initial: 'idle',
|
|
77
|
+
states: {
|
|
78
|
+
authorizing: {
|
|
79
|
+
entry: 'start',
|
|
80
|
+
invoke: {
|
|
81
|
+
input: { reauthorize: true },
|
|
82
|
+
onDone: [
|
|
83
|
+
{
|
|
84
|
+
guard: { params: (args) => args.event.output, type: 'declined' },
|
|
85
|
+
target: 'declined',
|
|
86
|
+
},
|
|
87
|
+
{ target: 'idle' },
|
|
88
|
+
],
|
|
89
|
+
onError: {
|
|
90
|
+
actions: {
|
|
91
|
+
params: (args) => ({ error: args.event.error }),
|
|
92
|
+
type: 'fail',
|
|
93
|
+
},
|
|
94
|
+
target: 'idle',
|
|
95
|
+
},
|
|
96
|
+
src: 'restore',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
checking: {
|
|
100
|
+
entry: 'start',
|
|
101
|
+
invoke: {
|
|
102
|
+
input: { reauthorize: false },
|
|
103
|
+
onDone: [
|
|
104
|
+
{
|
|
105
|
+
guard: { params: (args) => args.event.output, type: 'declined' },
|
|
106
|
+
target: 'declined',
|
|
107
|
+
},
|
|
108
|
+
{ target: 'idle' },
|
|
109
|
+
],
|
|
110
|
+
onError: {
|
|
111
|
+
actions: {
|
|
112
|
+
params: (args) => ({ error: args.event.error }),
|
|
113
|
+
type: 'fail',
|
|
114
|
+
},
|
|
115
|
+
target: 'idle',
|
|
116
|
+
},
|
|
117
|
+
src: 'restore',
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
declined: {
|
|
121
|
+
on: { mount: 'checking', status: 'idle' },
|
|
122
|
+
},
|
|
123
|
+
idle: {
|
|
124
|
+
on: { mount: 'authorizing' },
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
/** A running instance of {@link machine}. */
|
|
130
|
+
export type Actor = XStateActor<typeof machine>
|
|
131
|
+
|
|
132
|
+
/** A snapshot of {@link machine}. */
|
|
133
|
+
export type Snapshot = ReturnType<Actor['getSnapshot']>
|
|
134
|
+
|
|
135
|
+
/** Returns whether a restore is in progress, which a mount awaits. */
|
|
136
|
+
export function running(snapshot: Snapshot) {
|
|
137
|
+
return snapshot.matches('authorizing') || snapshot.matches('checking')
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Returns whether a failure of the default authorization is transient, so the next mount retries:
|
|
142
|
+
* an error without Tempo ID's answer, a server error, or a refusal for load. Any other refusal,
|
|
143
|
+
* such as `webauthn_required`, repeats at every attempt, so it is a decline. The entry loads no
|
|
144
|
+
* error class, so the error's name and fields identify a `RequestError`.
|
|
145
|
+
*/
|
|
146
|
+
export function transient(error: unknown) {
|
|
147
|
+
if (!(error instanceof Error) || error.name !== 'Id.RequestError') return true
|
|
148
|
+
const { reason, status } = error as Error & {
|
|
149
|
+
reason?: string | undefined
|
|
150
|
+
status?: number | undefined
|
|
151
|
+
}
|
|
152
|
+
if (status === undefined || status === 0 || status >= 500) return true
|
|
153
|
+
return reason === 'rate_limited' || reason === 'upstream_unavailable'
|
|
154
|
+
}
|