@tempoxyz/id 0.0.0-pr-985.sha-a4ce0a5 → 0.0.0-pr-841.sha-bd4d6dd
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/{Connections-2E4BWWP5.js → Connections-DK2SIMV5.js} +2 -2
- package/dist/{File-2S37TTJC.js → File-OL4F35BO.js} +26 -7
- package/dist/{Server-HCO3RVEL.js → Server-CARQOWST.js} +123 -35
- package/dist/{Sheet-MZX2D6ND.js → Sheet-ZAJ3CTUV.js} +2 -2
- package/dist/{chunk-XQZWIEU4.js → chunk-6YB3Z2ZN.js} +96 -24
- package/dist/{chunk-L55QOJ7W.js → chunk-7KIOFUO2.js} +1 -1
- package/dist/{chunk-4GPVTVJG.js → chunk-AVGHKMEM.js} +1 -1
- package/dist/{chunk-2CQJ2L34.js → chunk-DS4YLNUJ.js} +26 -16
- package/dist/{chunk-5ORZ6MUI.js → chunk-LN2RXYYW.js} +102 -26
- package/dist/{chunk-ACXN2G4C.js → chunk-N5H6SUAV.js} +18 -17
- package/dist/{chunk-PGTIKJYS.js → chunk-Y5ESRTOA.js} +223 -69
- package/dist/commands/login.js +7 -7
- package/dist/commands/logout.js +7 -7
- package/dist/commands/whoami.js +7 -7
- package/dist/{dialog-IV35LHFX.js → dialog-LOM5ZTPY.js} +43 -7
- package/dist/{passkey-UV2I7HJ5.js → passkey-DFH2IY4D.js} +2 -2
- package/package.json +1 -1
|
@@ -2,9 +2,9 @@ import {
|
|
|
2
2
|
attach,
|
|
3
3
|
create,
|
|
4
4
|
pending
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-7KIOFUO2.js";
|
|
6
6
|
import "./chunk-FWGE6HXK.js";
|
|
7
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-Y5ESRTOA.js";
|
|
8
8
|
import "./chunk-FHXDPKTL.js";
|
|
9
9
|
import "./chunk-MLKGABMK.js";
|
|
10
10
|
export {
|
|
@@ -72,19 +72,21 @@ function create(path) {
|
|
|
72
72
|
const target = resolve();
|
|
73
73
|
await Fs.mkdir(Path2.dirname(target), { mode: 448, recursive: true });
|
|
74
74
|
return await locked(target, async (check) => {
|
|
75
|
-
const entries = await read();
|
|
75
|
+
const [entries] = await Promise.all([read(), sweep(target)]);
|
|
76
76
|
const result = fn(entries);
|
|
77
77
|
for (const [key, entry] of Object.entries(entries))
|
|
78
78
|
if (expired(entry)) delete entries[key];
|
|
79
79
|
const temporary = `${target}.${crypto.randomUUID()}.tmp`;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
await Fs.
|
|
80
|
+
const text = stringify(entries);
|
|
81
|
+
await (async () => {
|
|
82
|
+
await Fs.writeFile(temporary, text, { mode: 384 });
|
|
83
|
+
await check();
|
|
84
|
+
await Fs.rename(temporary, target);
|
|
85
|
+
})().catch(async (error) => {
|
|
86
|
+
await Fs.rm(temporary, { force: true }).catch(() => void 0);
|
|
87
|
+
await check();
|
|
85
88
|
throw error;
|
|
86
89
|
});
|
|
87
|
-
await Fs.rename(temporary, target);
|
|
88
90
|
return await check().then(
|
|
89
91
|
() => result,
|
|
90
92
|
() => void 0
|
|
@@ -202,6 +204,23 @@ async function takeOver(lock, options) {
|
|
|
202
204
|
await Fs.link(moved, lock).catch(() => void 0);
|
|
203
205
|
await Fs.rm(moved, { force: true });
|
|
204
206
|
}
|
|
207
|
+
async function sweep(target) {
|
|
208
|
+
const { Fs, Path } = node();
|
|
209
|
+
const folder = Path.dirname(target);
|
|
210
|
+
const names = await Fs.readdir(folder).catch(() => []);
|
|
211
|
+
const prefix = `${Path.basename(target)}.`;
|
|
212
|
+
await Promise.all(
|
|
213
|
+
names.filter(
|
|
214
|
+
(name) => name.startsWith(prefix) && temporaryName.test(name.slice(prefix.length))
|
|
215
|
+
).map(async (name) => {
|
|
216
|
+
const file = Path.join(folder, name);
|
|
217
|
+
const stat = await Fs.stat(file).catch(() => void 0);
|
|
218
|
+
if (stat && Date.now() - stat.mtimeMs > staleLock)
|
|
219
|
+
await Fs.rm(file, { force: true }).catch(() => void 0);
|
|
220
|
+
})
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
var temporaryName = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}\.tmp$/;
|
|
205
224
|
var staleLock = 1e4;
|
|
206
225
|
export {
|
|
207
226
|
InvalidFileError,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
InvalidError
|
|
3
3
|
} from "./chunk-2T7V6ASK.js";
|
|
4
|
-
import "./chunk-
|
|
4
|
+
import "./chunk-AVGHKMEM.js";
|
|
5
5
|
import {
|
|
6
6
|
authPath,
|
|
7
7
|
basePath,
|
|
@@ -9,8 +9,10 @@ import {
|
|
|
9
9
|
} from "./chunk-FWGE6HXK.js";
|
|
10
10
|
import {
|
|
11
11
|
PendingNotFoundError,
|
|
12
|
-
RequestError
|
|
13
|
-
|
|
12
|
+
RequestError,
|
|
13
|
+
key,
|
|
14
|
+
siwe
|
|
15
|
+
} from "./chunk-Y5ESRTOA.js";
|
|
14
16
|
import "./chunk-FHXDPKTL.js";
|
|
15
17
|
import "./chunk-MLKGABMK.js";
|
|
16
18
|
|
|
@@ -49,6 +51,13 @@ function get(request, options) {
|
|
|
49
51
|
}
|
|
50
52
|
return void 0;
|
|
51
53
|
}
|
|
54
|
+
function bearer(request) {
|
|
55
|
+
const [scheme, value] = (request.headers.get("authorization") ?? "").split(
|
|
56
|
+
" "
|
|
57
|
+
);
|
|
58
|
+
if (scheme?.toLowerCase() !== "bearer" || !value) return void 0;
|
|
59
|
+
return /^[\w-]{43}$/.test(value) ? value : void 0;
|
|
60
|
+
}
|
|
52
61
|
function list(request, options) {
|
|
53
62
|
const header = request.headers.get("cookie");
|
|
54
63
|
if (!header) return [];
|
|
@@ -102,8 +111,15 @@ var relayScript = `(() => {
|
|
|
102
111
|
setTimeout(() => location.replace('/?error=invalid_request'), 500)
|
|
103
112
|
})()`;
|
|
104
113
|
function create(options) {
|
|
105
|
-
const { backend, siwe } = options;
|
|
114
|
+
const { backend, siwe: siwe2 } = options;
|
|
115
|
+
const operations = backend[key];
|
|
106
116
|
const base = (options.basePath ?? "").replace(/\/+$/, "");
|
|
117
|
+
const settings = siwe2?.[siwe];
|
|
118
|
+
const token = settings?.token === true;
|
|
119
|
+
const pageOrigins = token ? settings?.origins : void 0;
|
|
120
|
+
function bearer2(request) {
|
|
121
|
+
return token ? bearer(request) : void 0;
|
|
122
|
+
}
|
|
107
123
|
function redirectUri(request) {
|
|
108
124
|
return options.redirectUri ?? `${new URL(request.url).origin}${base}/callback`;
|
|
109
125
|
}
|
|
@@ -264,7 +280,11 @@ function create(options) {
|
|
|
264
280
|
const { id } = options2;
|
|
265
281
|
const session2 = await (async () => {
|
|
266
282
|
try {
|
|
267
|
-
return await
|
|
283
|
+
return await operations.complete({
|
|
284
|
+
id,
|
|
285
|
+
replace: () => replace(request, { id }),
|
|
286
|
+
url: options2.url
|
|
287
|
+
});
|
|
268
288
|
} catch (error) {
|
|
269
289
|
if (error instanceof PendingNotFoundError)
|
|
270
290
|
return { stale: true };
|
|
@@ -273,7 +293,6 @@ function create(options) {
|
|
|
273
293
|
}
|
|
274
294
|
})();
|
|
275
295
|
if ("refusal" in session2 || "stale" in session2) return session2;
|
|
276
|
-
await replace(request, { id });
|
|
277
296
|
return { id, session: session2 };
|
|
278
297
|
}
|
|
279
298
|
async function replace(request, options2) {
|
|
@@ -286,10 +305,11 @@ function create(options) {
|
|
|
286
305
|
).catch(() => void 0);
|
|
287
306
|
}
|
|
288
307
|
async function siweChallenge(request, actions) {
|
|
289
|
-
const refusal = foreign(request);
|
|
308
|
+
const refusal = foreign(request, { origins: pageOrigins });
|
|
290
309
|
if (refusal) return refusal;
|
|
291
310
|
const body = await request.json().catch(() => void 0);
|
|
292
311
|
const address = body?.address;
|
|
312
|
+
const chainId = body?.chainId;
|
|
293
313
|
if (address !== void 0 && (typeof address !== "string" || !Address.validate(address, { strict: false })))
|
|
294
314
|
return Response.json(
|
|
295
315
|
{
|
|
@@ -298,17 +318,32 @@ function create(options) {
|
|
|
298
318
|
},
|
|
299
319
|
{ status: 400 }
|
|
300
320
|
);
|
|
301
|
-
|
|
321
|
+
if (chainId !== void 0 && (typeof chainId !== "number" || !Number.isSafeInteger(chainId)))
|
|
322
|
+
return Response.json(
|
|
323
|
+
{
|
|
324
|
+
error: "invalid_request",
|
|
325
|
+
error_description: "Invalid body: `chainId` is not a chain ID. Send the ID of the chain to sign in on, or no `chainId`."
|
|
326
|
+
},
|
|
327
|
+
{ status: 400 }
|
|
328
|
+
);
|
|
329
|
+
const started = await actions.start({ address, chainId, request }).catch((error) => {
|
|
302
330
|
if (invalid(error)) return error;
|
|
303
331
|
throw error;
|
|
304
332
|
});
|
|
305
|
-
if ("reason" in started)
|
|
333
|
+
if ("reason" in started) {
|
|
334
|
+
if (started.reason === "chain")
|
|
335
|
+
return Response.json(
|
|
336
|
+
{ error: "invalid_request", error_description: started.message },
|
|
337
|
+
{ status: 400 }
|
|
338
|
+
);
|
|
306
339
|
return Response.json(
|
|
307
340
|
{ error: "forbidden", error_description: started.message },
|
|
308
341
|
{ status: 403 }
|
|
309
342
|
);
|
|
343
|
+
}
|
|
310
344
|
const { id, message } = started;
|
|
311
345
|
const headers = new Headers({ "cache-control": "no-store" });
|
|
346
|
+
if (token) return Response.json({ id, message }, { headers });
|
|
312
347
|
headers.append(
|
|
313
348
|
"set-cookie",
|
|
314
349
|
serialize({
|
|
@@ -320,27 +355,39 @@ function create(options) {
|
|
|
320
355
|
return Response.json({ message }, { headers });
|
|
321
356
|
}
|
|
322
357
|
async function siweVerify(request, actions) {
|
|
323
|
-
const refusal = foreign(request);
|
|
358
|
+
const refusal = foreign(request, { origins: pageOrigins });
|
|
324
359
|
if (refusal) return refusal;
|
|
325
360
|
const body = await request.json().catch(() => void 0);
|
|
326
|
-
const { address, message, signature } = body ?? {};
|
|
327
|
-
|
|
361
|
+
const { address, keyAuthorization, message, signature } = body ?? {};
|
|
362
|
+
const proof = (() => {
|
|
363
|
+
if (typeof signature === "string" && Hex.validate(signature))
|
|
364
|
+
return { signature };
|
|
365
|
+
if (typeof keyAuthorization === "object" && keyAuthorization !== null && !Array.isArray(keyAuthorization))
|
|
366
|
+
return {
|
|
367
|
+
keyAuthorization,
|
|
368
|
+
request
|
|
369
|
+
};
|
|
370
|
+
return void 0;
|
|
371
|
+
})();
|
|
372
|
+
if (token && typeof body?.id !== "string" || typeof address !== "string" || typeof message !== "string" || !proof || !Address.validate(address, { strict: false }))
|
|
328
373
|
return Response.json(
|
|
329
374
|
{
|
|
330
375
|
error: "invalid_request",
|
|
331
|
-
error_description: "Invalid body: send the signed message as `message`, its signature as `signature`, and the address of the account that signed as `address`."
|
|
376
|
+
error_description: token ? "Invalid body: send the challenge\u2019s `id`, the signed message as `message`, its signature as `signature` or the key authorization that binds it as `keyAuthorization`, and the address of the account that signed as `address`." : "Invalid body: send the signed message as `message`, its signature as `signature` or the key authorization that binds it as `keyAuthorization`, and the address of the account that signed as `address`."
|
|
332
377
|
},
|
|
333
378
|
{ status: 400 }
|
|
334
379
|
);
|
|
335
|
-
const headers = new Headers({
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
380
|
+
const headers = new Headers({ "cache-control": "no-store" });
|
|
381
|
+
if (!token)
|
|
382
|
+
headers.set(
|
|
383
|
+
"set-cookie",
|
|
384
|
+
serialize({ name: names.siwe })
|
|
385
|
+
);
|
|
386
|
+
const id = token ? body?.id : get(request, { name: names.siwe });
|
|
340
387
|
const session2 = await (async () => {
|
|
341
388
|
if (!id) return void 0;
|
|
342
389
|
try {
|
|
343
|
-
return await actions.complete({ address, id, message,
|
|
390
|
+
return await actions.complete({ address, id, message, ...proof });
|
|
344
391
|
} catch (error) {
|
|
345
392
|
if (invalid(error)) return error;
|
|
346
393
|
throw error;
|
|
@@ -356,14 +403,22 @@ function create(options) {
|
|
|
356
403
|
{ headers, status: signer ? 403 : 400 }
|
|
357
404
|
);
|
|
358
405
|
}
|
|
406
|
+
if (token)
|
|
407
|
+
return Response.json(
|
|
408
|
+
{ session: pageSession(session2), token: session2.id },
|
|
409
|
+
{ headers }
|
|
410
|
+
);
|
|
359
411
|
await replace(request, { id: session2.id });
|
|
360
412
|
headers.append("set-cookie", sessionCookie(session2));
|
|
361
413
|
return Response.json({ session: pageSession(session2) }, { headers });
|
|
362
414
|
}
|
|
363
415
|
async function logout(request) {
|
|
364
|
-
const
|
|
416
|
+
const held = bearer2(request);
|
|
417
|
+
const refusal = foreign(request, {
|
|
418
|
+
origins: held ? pageOrigins : void 0
|
|
419
|
+
});
|
|
365
420
|
if (refusal) return refusal;
|
|
366
|
-
const id = get(request, { name: names.session });
|
|
421
|
+
const id = get(request, { name: names.session }) ?? held;
|
|
367
422
|
const headers = new Headers({
|
|
368
423
|
"set-cookie": serialize({
|
|
369
424
|
name: names.session
|
|
@@ -419,20 +474,25 @@ function create(options) {
|
|
|
419
474
|
return new Response(null, { headers, status: 200 });
|
|
420
475
|
}
|
|
421
476
|
async function session(request) {
|
|
422
|
-
const
|
|
423
|
-
|
|
477
|
+
const cookie = get(request, {
|
|
478
|
+
name: names.session
|
|
479
|
+
});
|
|
480
|
+
const held = cookie ? void 0 : bearer2(request);
|
|
481
|
+
const id = cookie ?? held;
|
|
482
|
+
const read2 = id ? await backend.get({ id }).catch((error) => {
|
|
424
483
|
if (error instanceof RequestError) return error;
|
|
425
484
|
throw error;
|
|
426
485
|
}) : void 0;
|
|
486
|
+
const current = held && (read2 instanceof RequestError || read2?.method !== "siwe") ? void 0 : read2;
|
|
427
487
|
const headers = new Headers({ "cache-control": "no-store" });
|
|
428
488
|
if (current instanceof RequestError && transient(current))
|
|
429
489
|
return Response.json(
|
|
430
490
|
{ error: "temporarily_unavailable" },
|
|
431
491
|
{ headers, status: 503 }
|
|
432
492
|
);
|
|
433
|
-
if (
|
|
434
|
-
await backend.end({ id }).catch(() => void 0);
|
|
435
|
-
if (
|
|
493
|
+
if (cookie && current instanceof RequestError)
|
|
494
|
+
await backend.end({ id: cookie }).catch(() => void 0);
|
|
495
|
+
if (cookie && (!current || current instanceof RequestError))
|
|
436
496
|
headers.set(
|
|
437
497
|
"set-cookie",
|
|
438
498
|
serialize({ name: names.session })
|
|
@@ -450,26 +510,53 @@ function create(options) {
|
|
|
450
510
|
[`${base}/login`]: { GET: login, POST: dialogLogin },
|
|
451
511
|
[`${base}/logout`]: { POST: logout },
|
|
452
512
|
[`${base}/session`]: { GET: session },
|
|
453
|
-
...
|
|
513
|
+
...siwe2 ? {
|
|
514
|
+
// `siwe({ auth: '/api/auth/siwe' })` on the page posts its signature to the challenge
|
|
515
|
+
// route's parent. `/siwe/verify` serves `dialog({ backend: true })` and earlier releases.
|
|
516
|
+
[`${base}/siwe`]: {
|
|
517
|
+
POST: (request) => siweVerify(request, siwe2)
|
|
518
|
+
},
|
|
454
519
|
[`${base}/siwe/challenge`]: {
|
|
455
|
-
POST: (request) => siweChallenge(request,
|
|
520
|
+
POST: (request) => siweChallenge(request, siwe2)
|
|
456
521
|
},
|
|
457
522
|
[`${base}/siwe/verify`]: {
|
|
458
|
-
POST: (request) => siweVerify(request,
|
|
523
|
+
POST: (request) => siweVerify(request, siwe2)
|
|
459
524
|
}
|
|
460
525
|
} : {}
|
|
461
526
|
};
|
|
527
|
+
const shared = new Set(
|
|
528
|
+
["/logout", "/session", "/siwe", "/siwe/challenge", "/siwe/verify"].map(
|
|
529
|
+
(path) => `${base}${path}`
|
|
530
|
+
)
|
|
531
|
+
);
|
|
462
532
|
return from({
|
|
463
533
|
async fetch(request) {
|
|
464
|
-
const
|
|
534
|
+
const { pathname } = new URL(request.url);
|
|
535
|
+
const route = routes[pathname];
|
|
465
536
|
if (!route) return Response.json({ error: "not_found" }, { status: 404 });
|
|
537
|
+
const origin = request.headers.get("origin");
|
|
538
|
+
const cors = origin && pageOrigins?.includes(origin) && shared.has(pathname) ? { "access-control-allow-origin": origin, vary: "origin" } : void 0;
|
|
539
|
+
if (cors && request.method === "OPTIONS")
|
|
540
|
+
return new Response(null, {
|
|
541
|
+
headers: {
|
|
542
|
+
...cors,
|
|
543
|
+
"access-control-allow-headers": "authorization, content-type, dpop",
|
|
544
|
+
"access-control-allow-methods": Object.keys(route).join(", "),
|
|
545
|
+
"access-control-max-age": "600"
|
|
546
|
+
},
|
|
547
|
+
status: 204
|
|
548
|
+
});
|
|
466
549
|
const fn = route[request.method];
|
|
467
550
|
if (!fn)
|
|
468
551
|
return Response.json(
|
|
469
552
|
{ error: "method_not_allowed" },
|
|
470
553
|
{ headers: { allow: Object.keys(route).join(", ") }, status: 405 }
|
|
471
554
|
);
|
|
472
|
-
|
|
555
|
+
const response = await fn(request);
|
|
556
|
+
if (cors)
|
|
557
|
+
for (const [name, value] of Object.entries(cors))
|
|
558
|
+
response.headers.set(name, value);
|
|
559
|
+
return response;
|
|
473
560
|
}
|
|
474
561
|
});
|
|
475
562
|
}
|
|
@@ -616,9 +703,10 @@ function decode(value) {
|
|
|
616
703
|
return void 0;
|
|
617
704
|
}
|
|
618
705
|
}
|
|
619
|
-
function foreign(request) {
|
|
620
|
-
|
|
621
|
-
|
|
706
|
+
function foreign(request, options = {}) {
|
|
707
|
+
const origin = request.headers.get("origin");
|
|
708
|
+
if (origin === new URL(request.url).origin) return void 0;
|
|
709
|
+
if (origin && options.origins?.includes(origin)) return void 0;
|
|
622
710
|
return Response.json(
|
|
623
711
|
{
|
|
624
712
|
error: "forbidden",
|
|
@@ -748,7 +836,7 @@ function create2(options) {
|
|
|
748
836
|
"/login",
|
|
749
837
|
"/logout",
|
|
750
838
|
"/session",
|
|
751
|
-
...options.siwe ? ["/siwe/challenge", "/siwe/verify"] : []
|
|
839
|
+
...options.siwe ? ["/siwe", "/siwe/challenge", "/siwe/verify"] : []
|
|
752
840
|
].map((path) => `${auth}${path}`)
|
|
753
841
|
);
|
|
754
842
|
return from({
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
openPopup,
|
|
4
4
|
received,
|
|
5
5
|
watchPopup
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-Y5ESRTOA.js";
|
|
7
7
|
|
|
8
8
|
// ../../accounts/src/internal/Sheet.ts
|
|
9
9
|
import {
|
|
@@ -277,6 +277,9 @@ function create(options) {
|
|
|
277
277
|
dialog.inert = true;
|
|
278
278
|
dialog.setAttribute("data-closing", "");
|
|
279
279
|
},
|
|
280
|
+
arm: ({ context }) => {
|
|
281
|
+
primary.disabled = context.current?.popupUrl === void 0;
|
|
282
|
+
},
|
|
280
283
|
blocked: () => {
|
|
281
284
|
text.textContent = "The browser blocked the window. Allow pop-ups for this site, and select Continue again.";
|
|
282
285
|
},
|
|
@@ -293,9 +296,10 @@ function create(options) {
|
|
|
293
296
|
origin
|
|
294
297
|
);
|
|
295
298
|
},
|
|
296
|
-
offer: ({ event }) => {
|
|
299
|
+
offer: ({ context, event }) => {
|
|
297
300
|
assertEvent(event, "fallback");
|
|
298
301
|
frame.remove();
|
|
302
|
+
primary.disabled = context.current?.popupUrl === void 0;
|
|
299
303
|
text.textContent = event.reason === "popup" ? "Continue in a new window to finish signing in." : "Sign in with Tempo in a new window.";
|
|
300
304
|
dialog.appendChild(panel);
|
|
301
305
|
},
|
|
@@ -312,15 +316,26 @@ function create(options) {
|
|
|
312
316
|
primary.remove();
|
|
313
317
|
},
|
|
314
318
|
post: ({ context }) => {
|
|
315
|
-
if (!context.current
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
319
|
+
if (!context.current) return;
|
|
320
|
+
if (context.request !== void 0)
|
|
321
|
+
frame.contentWindow?.postMessage(
|
|
322
|
+
{
|
|
323
|
+
...context.current.deferred ? { deferred: true } : {},
|
|
324
|
+
id: context.current.id,
|
|
325
|
+
request: context.request,
|
|
326
|
+
type: "tempo-id:embed.request"
|
|
327
|
+
},
|
|
328
|
+
origin
|
|
329
|
+
);
|
|
330
|
+
if (context.challenge !== void 0)
|
|
331
|
+
frame.contentWindow?.postMessage(
|
|
332
|
+
{
|
|
333
|
+
id: context.current.id,
|
|
334
|
+
request: context.challenge,
|
|
335
|
+
type: "tempo-id:embed.challenge"
|
|
336
|
+
},
|
|
337
|
+
origin
|
|
338
|
+
);
|
|
324
339
|
},
|
|
325
340
|
remove: () => {
|
|
326
341
|
dialog.close();
|
|
@@ -397,12 +412,22 @@ function create(options) {
|
|
|
397
412
|
actor.send({ animate: animate(), type: "hide" });
|
|
398
413
|
return true;
|
|
399
414
|
},
|
|
415
|
+
challenge(value) {
|
|
416
|
+
actor.send({
|
|
417
|
+
id: value.id,
|
|
418
|
+
popupUrl: value.popupUrl,
|
|
419
|
+
request: value.request,
|
|
420
|
+
type: "challenge"
|
|
421
|
+
});
|
|
422
|
+
},
|
|
400
423
|
received() {
|
|
401
424
|
actor.send({ type: "received" });
|
|
402
425
|
},
|
|
403
426
|
show(value) {
|
|
427
|
+
const id = crypto.randomUUID();
|
|
404
428
|
actor.send({
|
|
405
|
-
|
|
429
|
+
deferred: value.deferred === true,
|
|
430
|
+
id,
|
|
406
431
|
onCallback: value.onCallback,
|
|
407
432
|
onClose: value.onClose,
|
|
408
433
|
popupUrl: value.popupUrl,
|
|
@@ -410,6 +435,7 @@ function create(options) {
|
|
|
410
435
|
timeout: value.timeout,
|
|
411
436
|
type: "show"
|
|
412
437
|
});
|
|
438
|
+
return id;
|
|
413
439
|
},
|
|
414
440
|
trusted: () => machines.trusted(actor.getSnapshot()),
|
|
415
441
|
usable: () => dialog.isConnected && !machines.failed(actor.getSnapshot())
|
|
@@ -554,9 +580,13 @@ function load(options) {
|
|
|
554
580
|
let state = { phase: "hidden" };
|
|
555
581
|
const handlers = () => state.phase === "shown" ? state.handlers : void 0;
|
|
556
582
|
let report = { phase: "none" };
|
|
557
|
-
let cover = options.covered ? "held" : "free";
|
|
583
|
+
let cover = options.covered || options.deferred ? "held" : "free";
|
|
584
|
+
let challenge;
|
|
558
585
|
const uncover = () => element.contentWindow?.postMessage(
|
|
559
|
-
{
|
|
586
|
+
{
|
|
587
|
+
...challenge !== void 0 ? { challenge } : {},
|
|
588
|
+
type: "tempo-id:embed.uncover"
|
|
589
|
+
},
|
|
560
590
|
origin
|
|
561
591
|
);
|
|
562
592
|
const offer = (popup = {}) => {
|
|
@@ -665,7 +695,9 @@ function load(options) {
|
|
|
665
695
|
dialog.inert = false;
|
|
666
696
|
dialog.showModal();
|
|
667
697
|
},
|
|
668
|
-
uncover: () => {
|
|
698
|
+
uncover: (value = {}) => {
|
|
699
|
+
if (cover === "free") return;
|
|
700
|
+
challenge = value.challenge;
|
|
669
701
|
if (cover === "listening") uncover();
|
|
670
702
|
cover = "free";
|
|
671
703
|
for (const child of dialog.children)
|
|
@@ -733,11 +765,21 @@ var machines;
|
|
|
733
765
|
/** Plays the dialog's exit, and keeps the frame from input. `Sheet.ts` provides it. */
|
|
734
766
|
animate: () => {
|
|
735
767
|
},
|
|
768
|
+
/**
|
|
769
|
+
* Lets the offer of a popup take a click only while the current request holds its popup's URL,
|
|
770
|
+
* which a deferred request receives with `challenge`. `Sheet.ts` provides it.
|
|
771
|
+
*/
|
|
772
|
+
arm: () => {
|
|
773
|
+
},
|
|
736
774
|
/** Shows that the browser blocked the popup. `Sheet.ts` provides it. */
|
|
737
775
|
blocked: () => {
|
|
738
776
|
},
|
|
739
777
|
/** Ends the current request. */
|
|
740
|
-
clear: assign({
|
|
778
|
+
clear: assign({
|
|
779
|
+
challenge: void 0,
|
|
780
|
+
current: void 0,
|
|
781
|
+
request: void 0
|
|
782
|
+
}),
|
|
741
783
|
/** Takes the dialog out of the top layer, the accessibility tree, and focus. `Sheet.ts` provides it. */
|
|
742
784
|
conceal: () => {
|
|
743
785
|
},
|
|
@@ -761,7 +803,7 @@ var machines;
|
|
|
761
803
|
/** Shows that the popup opened, and removes Continue. `Sheet.ts` provides it. */
|
|
762
804
|
opened: () => {
|
|
763
805
|
},
|
|
764
|
-
/** Posts `context.request` to the page. `Sheet.ts` provides it. */
|
|
806
|
+
/** Posts `context.request`, then `context.challenge`, to the page. `Sheet.ts` provides it. */
|
|
765
807
|
post: () => {
|
|
766
808
|
},
|
|
767
809
|
/** Stops the popup's watch, and keeps the popup open. */
|
|
@@ -775,13 +817,15 @@ var machines;
|
|
|
775
817
|
/** Shows the dialog, and admits it to the accessibility tree and to focus. `Sheet.ts` provides it. */
|
|
776
818
|
reveal: () => {
|
|
777
819
|
},
|
|
778
|
-
/** Marks the request posted. */
|
|
779
|
-
sent: assign({ request: void 0 }),
|
|
820
|
+
/** Marks the request and its challenge posted. */
|
|
821
|
+
sent: assign({ challenge: void 0, request: void 0 }),
|
|
780
822
|
/** Starts the request of `show`. */
|
|
781
823
|
start: assign(({ event }) => {
|
|
782
824
|
if (event.type !== "show") return {};
|
|
783
825
|
return {
|
|
826
|
+
challenge: void 0,
|
|
784
827
|
current: {
|
|
828
|
+
deferred: event.deferred,
|
|
785
829
|
handlers: {
|
|
786
830
|
onCallback: event.onCallback,
|
|
787
831
|
onClose: event.onClose
|
|
@@ -793,6 +837,14 @@ var machines;
|
|
|
793
837
|
request: event.request
|
|
794
838
|
};
|
|
795
839
|
}),
|
|
840
|
+
/** Takes the challenge of the deferred request, and its popup's URL. */
|
|
841
|
+
supply: assign(({ context, event }) => {
|
|
842
|
+
if (event.type !== "challenge" || !context.current) return {};
|
|
843
|
+
return {
|
|
844
|
+
challenge: event.request,
|
|
845
|
+
current: { ...context.current, popupUrl: event.popupUrl }
|
|
846
|
+
};
|
|
847
|
+
}),
|
|
796
848
|
/** Holds the trust that the loaded page reports. */
|
|
797
849
|
trust: assign(({ event }) => {
|
|
798
850
|
if (event.type !== "embed.loaded") return {};
|
|
@@ -826,14 +878,21 @@ var machines;
|
|
|
826
878
|
// A message about a request names its ID, so one about an earlier sign-in in the same frame
|
|
827
879
|
// acts on nothing.
|
|
828
880
|
ours: ({ context, event }) => "id" in event && event.id === context.current?.id,
|
|
829
|
-
|
|
881
|
+
// A popup opens only for a request whose URL arrived.
|
|
882
|
+
ready: ({ context }) => context.current?.popupUrl !== void 0,
|
|
883
|
+
unsent: ({ context }) => context.current !== void 0 && (context.request !== void 0 || context.challenge !== void 0)
|
|
830
884
|
},
|
|
831
885
|
types: {
|
|
832
886
|
context: {},
|
|
833
887
|
events: {}
|
|
834
888
|
}
|
|
835
889
|
}).createMachine({
|
|
836
|
-
context: {
|
|
890
|
+
context: {
|
|
891
|
+
challenge: void 0,
|
|
892
|
+
current: void 0,
|
|
893
|
+
request: void 0,
|
|
894
|
+
trusted: void 0
|
|
895
|
+
},
|
|
837
896
|
id: "sheet",
|
|
838
897
|
initial: "open",
|
|
839
898
|
states: {
|
|
@@ -846,6 +905,15 @@ var machines;
|
|
|
846
905
|
open: {
|
|
847
906
|
exit: "unlisten",
|
|
848
907
|
on: {
|
|
908
|
+
// A loaded frame shows the deferred request already, so its challenge follows at once. A
|
|
909
|
+
// dialog that offers a popup takes the challenge too, whose full request the popup opens.
|
|
910
|
+
challenge: [
|
|
911
|
+
{
|
|
912
|
+
actions: ["supply", "arm", "post", "sent"],
|
|
913
|
+
guard: and(["ours", "loaded"])
|
|
914
|
+
},
|
|
915
|
+
{ actions: ["supply", "arm"], guard: "ours" }
|
|
916
|
+
],
|
|
849
917
|
close: [
|
|
850
918
|
{ guard: "animate", target: "closing" },
|
|
851
919
|
{ target: "closed" }
|
|
@@ -888,7 +956,7 @@ var machines;
|
|
|
888
956
|
// out of view and takes the request.
|
|
889
957
|
show: [
|
|
890
958
|
{
|
|
891
|
-
actions: ["conceal", "start"],
|
|
959
|
+
actions: ["conceal", "start", "arm"],
|
|
892
960
|
guard: "failed",
|
|
893
961
|
target: "revealed"
|
|
894
962
|
},
|
|
@@ -940,7 +1008,11 @@ var machines;
|
|
|
940
1008
|
{ actions: ["clear", "conceal"], target: ".idle" }
|
|
941
1009
|
],
|
|
942
1010
|
show: [
|
|
943
|
-
{
|
|
1011
|
+
{
|
|
1012
|
+
actions: ["start", "arm"],
|
|
1013
|
+
guard: "failed",
|
|
1014
|
+
target: ".revealed"
|
|
1015
|
+
},
|
|
944
1016
|
{
|
|
945
1017
|
actions: ["start", "post", "sent"],
|
|
946
1018
|
guard: "loaded",
|
|
@@ -958,7 +1030,7 @@ var machines;
|
|
|
958
1030
|
states: {
|
|
959
1031
|
offered: {
|
|
960
1032
|
on: {
|
|
961
|
-
"popup.open": { guard: "
|
|
1033
|
+
"popup.open": { guard: "ready", target: "popup" }
|
|
962
1034
|
}
|
|
963
1035
|
},
|
|
964
1036
|
popup: {
|