tempest-react-sdk 0.80.0 → 0.82.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/README.md +40 -10
- package/bin/create-tempest-app.e2e.test.mjs +31 -0
- package/bin/create-tempest-app.mjs +11 -1
- package/bin/lib/component/generate.test.mjs +13 -1
- package/bin/lib/doctor/doctor.e2e.test.mjs +29 -0
- package/bin/lib/doctor/vitest.mjs +120 -0
- package/bin/lib/doctor/vitest.test.mjs +139 -0
- package/bin/lib/fs/contain.mjs +7 -0
- package/bin/lib/openapi/escape.mjs +68 -4
- package/bin/lib/openapi/generate.hostile.test.mjs +150 -1
- package/bin/lib/openapi/generate.mjs +78 -13
- package/bin/lib/openapi/generate.test.mjs +13 -1
- package/bin/lib/openapi/pattern-risk.mjs +134 -0
- package/bin/lib/openapi/pattern-risk.test.mjs +45 -0
- package/bin/tempest-gen.test.mjs +100 -0
- package/bin/tempest.mjs +24 -8
- package/dist/access/use-can.cjs +1 -1
- package/dist/access/use-can.cjs.map +1 -1
- package/dist/access/use-can.js +25 -28
- package/dist/access/use-can.js.map +1 -1
- package/dist/auth/create-tempest-auth.cjs +1 -1
- package/dist/auth/create-tempest-auth.cjs.map +1 -1
- package/dist/auth/create-tempest-auth.js +234 -122
- package/dist/auth/create-tempest-auth.js.map +1 -1
- package/dist/auth/session-identity.cjs +2 -0
- package/dist/auth/session-identity.cjs.map +1 -0
- package/dist/auth/session-identity.js +12 -0
- package/dist/auth/session-identity.js.map +1 -0
- package/dist/br/boleto.cjs +1 -1
- package/dist/br/boleto.cjs.map +1 -1
- package/dist/br/boleto.js +2 -1
- package/dist/br/boleto.js.map +1 -1
- package/dist/br.d.ts +22 -3
- package/dist/components/AuthForm/AuthFieldControl.cjs +2 -0
- package/dist/components/AuthForm/AuthFieldControl.cjs.map +1 -0
- package/dist/components/AuthForm/AuthFieldControl.js +85 -0
- package/dist/components/AuthForm/AuthFieldControl.js.map +1 -0
- package/dist/components/AuthForm/AuthForm.cjs +2 -0
- package/dist/components/AuthForm/AuthForm.cjs.map +1 -0
- package/dist/components/AuthForm/AuthForm.js +83 -0
- package/dist/components/AuthForm/AuthForm.js.map +1 -0
- package/dist/components/AuthForm/AuthForm.module.cjs +3 -0
- package/dist/components/AuthForm/AuthForm.module.cjs.map +1 -0
- package/dist/components/AuthForm/AuthForm.module.js +14 -0
- package/dist/components/AuthForm/AuthForm.module.js.map +1 -0
- package/dist/components/AuthForm/AuthLinks.cjs +2 -0
- package/dist/components/AuthForm/AuthLinks.cjs.map +1 -0
- package/dist/components/AuthForm/AuthLinks.js +32 -0
- package/dist/components/AuthForm/AuthLinks.js.map +1 -0
- package/dist/components/AuthForm/ForgotPasswordForm.cjs +2 -0
- package/dist/components/AuthForm/ForgotPasswordForm.cjs.map +1 -0
- package/dist/components/AuthForm/ForgotPasswordForm.js +32 -0
- package/dist/components/AuthForm/ForgotPasswordForm.js.map +1 -0
- package/dist/components/AuthForm/LoginForm.cjs +2 -0
- package/dist/components/AuthForm/LoginForm.cjs.map +1 -0
- package/dist/components/AuthForm/LoginForm.js +39 -0
- package/dist/components/AuthForm/LoginForm.js.map +1 -0
- package/dist/components/AuthForm/ResetPasswordForm.cjs +2 -0
- package/dist/components/AuthForm/ResetPasswordForm.cjs.map +1 -0
- package/dist/components/AuthForm/ResetPasswordForm.js +39 -0
- package/dist/components/AuthForm/ResetPasswordForm.js.map +1 -0
- package/dist/components/AuthForm/SignUpForm.cjs +2 -0
- package/dist/components/AuthForm/SignUpForm.cjs.map +1 -0
- package/dist/components/AuthForm/SignUpForm.js +32 -0
- package/dist/components/AuthForm/SignUpForm.js.map +1 -0
- package/dist/components/AuthForm/auth-defaults.cjs +2 -0
- package/dist/components/AuthForm/auth-defaults.cjs.map +1 -0
- package/dist/components/AuthForm/auth-defaults.js +54 -0
- package/dist/components/AuthForm/auth-defaults.js.map +1 -0
- package/dist/components/AuthForm/auth-schemas.cjs +2 -0
- package/dist/components/AuthForm/auth-schemas.cjs.map +1 -0
- package/dist/components/AuthForm/auth-schemas.js +26 -0
- package/dist/components/AuthForm/auth-schemas.js.map +1 -0
- package/dist/components/AuthPage/AuthPage.cjs +2 -0
- package/dist/components/AuthPage/AuthPage.cjs.map +1 -0
- package/dist/components/AuthPage/AuthPage.js +97 -0
- package/dist/components/AuthPage/AuthPage.js.map +1 -0
- package/dist/components/AuthPage/AuthPage.module.cjs +3 -0
- package/dist/components/AuthPage/AuthPage.module.cjs.map +1 -0
- package/dist/components/AuthPage/AuthPage.module.js +24 -0
- package/dist/components/AuthPage/AuthPage.module.js.map +1 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.cjs +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.cjs.map +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.js +22 -21
- package/dist/components/Breadcrumbs/Breadcrumbs.js.map +1 -1
- package/dist/components/Button/Button.cjs +1 -1
- package/dist/components/Button/Button.cjs.map +1 -1
- package/dist/components/Button/Button.js +41 -40
- package/dist/components/Button/Button.js.map +1 -1
- package/dist/components/Chat/ChatAttachments.cjs +1 -1
- package/dist/components/Chat/ChatAttachments.cjs.map +1 -1
- package/dist/components/Chat/ChatAttachments.js +38 -38
- package/dist/components/FilterBar/filter-apply.cjs +1 -1
- package/dist/components/FilterBar/filter-apply.cjs.map +1 -1
- package/dist/components/FilterBar/filter-apply.js +7 -7
- package/dist/components/Form/Form.cjs +1 -1
- package/dist/components/Form/Form.cjs.map +1 -1
- package/dist/components/Form/Form.js +30 -32
- package/dist/components/Form/Form.js.map +1 -1
- package/dist/components/Layout/Layout.cjs +1 -1
- package/dist/components/Layout/Layout.cjs.map +1 -1
- package/dist/components/Layout/Layout.js +25 -24
- package/dist/components/Layout/Layout.js.map +1 -1
- package/dist/components/Layout/gap.cjs +2 -0
- package/dist/components/Layout/gap.cjs.map +1 -0
- package/dist/components/Layout/gap.js +15 -0
- package/dist/components/Layout/gap.js.map +1 -0
- package/dist/components/NavigationMenu/NavigationMenu.cjs +1 -1
- package/dist/components/NavigationMenu/NavigationMenu.cjs.map +1 -1
- package/dist/components/NavigationMenu/NavigationMenu.js +71 -70
- package/dist/components/NavigationMenu/NavigationMenu.js.map +1 -1
- package/dist/components/Sidebar/Sidebar.cjs.map +1 -1
- package/dist/components/Sidebar/Sidebar.js.map +1 -1
- package/dist/components/Sidebar/SidebarEntry.cjs +1 -1
- package/dist/components/Sidebar/SidebarEntry.cjs.map +1 -1
- package/dist/components/Sidebar/SidebarEntry.js +30 -29
- package/dist/components/Sidebar/SidebarEntry.js.map +1 -1
- package/dist/data/create-data-provider.cjs +1 -1
- package/dist/data/create-data-provider.cjs.map +1 -1
- package/dist/data/create-data-provider.js +1 -2
- package/dist/data/create-data-provider.js.map +1 -1
- package/dist/forms/index.js +7 -7
- package/dist/forms/masked-inputs.cjs +1 -1
- package/dist/forms/masked-inputs.cjs.map +1 -1
- package/dist/forms/masked-inputs.js +15 -15
- package/dist/forms/validate-form.cjs +1 -1
- package/dist/forms/validate-form.cjs.map +1 -1
- package/dist/forms/validate-form.js +6 -1
- package/dist/forms/validate-form.js.map +1 -1
- package/dist/forms/zod-resolver.cjs +1 -1
- package/dist/forms/zod-resolver.cjs.map +1 -1
- package/dist/forms/zod-resolver.js +8 -3
- package/dist/forms/zod-resolver.js.map +1 -1
- package/dist/http/api-client.cjs +1 -1
- package/dist/http/api-client.cjs.map +1 -1
- package/dist/http/api-client.js +137 -116
- package/dist/http/api-client.js.map +1 -1
- package/dist/http/credential-scope.cjs +1 -1
- package/dist/http/credential-scope.cjs.map +1 -1
- package/dist/http/credential-scope.js +33 -9
- package/dist/http/credential-scope.js.map +1 -1
- package/dist/http/presigned-post.cjs.map +1 -1
- package/dist/http/presigned-post.js.map +1 -1
- package/dist/http/resumable-upload.cjs +1 -1
- package/dist/http/resumable-upload.cjs.map +1 -1
- package/dist/http/resumable-upload.js +140 -134
- package/dist/http/resumable-upload.js.map +1 -1
- package/dist/http/upload-with-progress.cjs +1 -1
- package/dist/http/upload-with-progress.cjs.map +1 -1
- package/dist/http/upload-with-progress.js +17 -17
- package/dist/http/upload-with-progress.js.map +1 -1
- package/dist/http/use-describe-api-error.cjs +1 -1
- package/dist/http/use-describe-api-error.cjs.map +1 -1
- package/dist/http/use-describe-api-error.js +9 -9
- package/dist/oauth/GoogleSignIn.cjs +1 -1
- package/dist/oauth/GoogleSignIn.cjs.map +1 -1
- package/dist/oauth/GoogleSignIn.js +5 -4
- package/dist/oauth/GoogleSignIn.js.map +1 -1
- package/dist/offline/create-offline-sync.cjs +1 -1
- package/dist/offline/create-offline-sync.cjs.map +1 -1
- package/dist/offline/create-offline-sync.js +108 -68
- package/dist/offline/create-offline-sync.js.map +1 -1
- package/dist/query/offline-persistence.cjs +1 -1
- package/dist/query/offline-persistence.cjs.map +1 -1
- package/dist/query/offline-persistence.js +54 -44
- package/dist/query/offline-persistence.js.map +1 -1
- package/dist/sse/create-event-stream.cjs +1 -1
- package/dist/sse/create-event-stream.cjs.map +1 -1
- package/dist/sse/create-event-stream.js +48 -41
- package/dist/sse/create-event-stream.js.map +1 -1
- package/dist/sse/ticket-event-stream.cjs +1 -1
- package/dist/sse/ticket-event-stream.cjs.map +1 -1
- package/dist/sse/ticket-event-stream.js +48 -19
- package/dist/sse/ticket-event-stream.js.map +1 -1
- package/dist/sse/use-event-stream.cjs +1 -1
- package/dist/sse/use-event-stream.cjs.map +1 -1
- package/dist/sse/use-event-stream.js +19 -14
- package/dist/sse/use-event-stream.js.map +1 -1
- package/dist/styles/AuthForm.css +2 -0
- package/dist/styles/AuthPage.css +2 -0
- package/dist/styles/component/AuthForm.css +9 -0
- package/dist/styles/component/AuthPage.css +29 -0
- package/dist/styles/forms.css +36 -0
- package/dist/styles/manifest.json +63 -0
- package/dist/styles.css +1 -1
- package/dist/sw/background-sync.cjs +1 -1
- package/dist/sw/background-sync.cjs.map +1 -1
- package/dist/sw/background-sync.js +132 -112
- package/dist/sw/background-sync.js.map +1 -1
- package/dist/sw/cache.cjs +1 -1
- package/dist/sw/cache.cjs.map +1 -1
- package/dist/sw/cache.js +36 -30
- package/dist/sw/cache.js.map +1 -1
- package/dist/sw/create-push-handler.cjs +1 -1
- package/dist/sw/create-push-handler.cjs.map +1 -1
- package/dist/sw/create-push-handler.js +20 -10
- package/dist/sw/create-push-handler.js.map +1 -1
- package/dist/sw.d.ts +93 -28
- package/dist/tabular/compact.cjs +1 -1
- package/dist/tabular/compact.cjs.map +1 -1
- package/dist/tabular/compact.js +35 -16
- package/dist/tabular/compact.js.map +1 -1
- package/dist/tabular/manifest.cjs +1 -1
- package/dist/tabular/manifest.cjs.map +1 -1
- package/dist/tabular/manifest.js +33 -15
- package/dist/tabular/manifest.js.map +1 -1
- package/dist/tabular.d.ts +11 -1
- package/dist/tempest-react-sdk.cjs +1 -1
- package/dist/tempest-react-sdk.d.ts +1057 -83
- package/dist/tempest-react-sdk.js +373 -365
- package/dist/theme/initial-theme.cjs +4 -4
- package/dist/theme/initial-theme.cjs.map +1 -1
- package/dist/theme/initial-theme.js +8 -5
- package/dist/theme/initial-theme.js.map +1 -1
- package/dist/utils/compressed-storage.cjs +1 -1
- package/dist/utils/compressed-storage.cjs.map +1 -1
- package/dist/utils/compressed-storage.js +13 -7
- package/dist/utils/compressed-storage.js.map +1 -1
- package/dist/utils/format.cjs +1 -1
- package/dist/utils/format.cjs.map +1 -1
- package/dist/utils/format.js +25 -25
- package/dist/utils/numbers.cjs +1 -1
- package/dist/utils/numbers.cjs.map +1 -1
- package/dist/utils/numbers.js +7 -7
- package/dist/utils/objects.cjs +1 -1
- package/dist/utils/objects.cjs.map +1 -1
- package/dist/utils/objects.js +13 -7
- package/dist/utils/objects.js.map +1 -1
- package/dist/utils/safe-url.cjs +1 -1
- package/dist/utils/safe-url.cjs.map +1 -1
- package/dist/utils/safe-url.js +4 -1
- package/dist/utils/safe-url.js.map +1 -1
- package/dist/webrtc/peer-mesh.cjs +1 -1
- package/dist/webrtc/peer-mesh.cjs.map +1 -1
- package/dist/webrtc/peer-mesh.js +7 -1
- package/dist/webrtc/peer-mesh.js.map +1 -1
- package/dist/ws/create-web-socket.cjs +1 -1
- package/dist/ws/create-web-socket.cjs.map +1 -1
- package/dist/ws/create-web-socket.js +77 -61
- package/dist/ws/create-web-socket.js.map +1 -1
- package/dist/ws/use-web-socket.cjs +1 -1
- package/dist/ws/use-web-socket.cjs.map +1 -1
- package/dist/ws/use-web-socket.js +4 -3
- package/dist/ws/use-web-socket.js.map +1 -1
- package/package.json +1 -1
- package/template-pwa/src/pwa.tsx +42 -0
- package/template-pwa/src/sw.ts +15 -10
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { isDevBuild as e } from "../utils/dev-mode.js";
|
|
2
|
-
import {
|
|
2
|
+
import { isTrustedCredentialTarget as t } from "../http/credential-scope.js";
|
|
3
|
+
import { DEFAULT_CREDENTIAL_HEADERS as n, credentialHeaderSet as r } from "./credential-headers.js";
|
|
3
4
|
//#region src/sw/background-sync.ts
|
|
4
|
-
function
|
|
5
|
+
function i() {
|
|
5
6
|
return globalThis;
|
|
6
7
|
}
|
|
7
|
-
var
|
|
8
|
-
function
|
|
8
|
+
var a = "tempest-bg-sync", o = 2, s = "requests", c = "meta", l = "epoch", u = "tempest:bg-sync-credentials", d = 3e3, f = d * 2;
|
|
9
|
+
function p(e, t) {
|
|
9
10
|
let n = [], r = [];
|
|
10
11
|
for (let [i, a] of e) t.has(i.toLowerCase()) ? r.push(i.toLowerCase()) : n.push([i, a]);
|
|
11
12
|
return {
|
|
@@ -13,12 +14,12 @@ function f(e, t) {
|
|
|
13
14
|
stripped: r
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
+
function m(e, t) {
|
|
17
18
|
let n = e.openCursor();
|
|
18
19
|
n.onsuccess = () => {
|
|
19
20
|
let e = n.result;
|
|
20
21
|
if (!e) return;
|
|
21
|
-
let r = e.value, { kept: i, stripped: a } =
|
|
22
|
+
let r = e.value, { kept: i, stripped: a } = p(r.headers, t);
|
|
22
23
|
e.update({
|
|
23
24
|
...r,
|
|
24
25
|
headers: i,
|
|
@@ -27,64 +28,64 @@ function p(e, t) {
|
|
|
27
28
|
}), e.continue();
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
|
-
function
|
|
31
|
+
function h(e, t = r()) {
|
|
31
32
|
return new Promise((n, r) => {
|
|
32
|
-
let i = indexedDB.open(e,
|
|
33
|
+
let i = indexedDB.open(e, o);
|
|
33
34
|
i.onupgradeneeded = (e) => {
|
|
34
35
|
let n = i.result;
|
|
35
|
-
n.objectStoreNames.contains(
|
|
36
|
+
n.objectStoreNames.contains(s) ? e.oldVersion < 2 && i.transaction && m(i.transaction.objectStore(s), t) : n.createObjectStore(s, {
|
|
36
37
|
keyPath: "id",
|
|
37
38
|
autoIncrement: !0
|
|
38
|
-
}), n.objectStoreNames.contains(
|
|
39
|
+
}), n.objectStoreNames.contains(c) || n.createObjectStore(c);
|
|
39
40
|
}, i.onsuccess = () => {
|
|
40
41
|
let e = i.result;
|
|
41
42
|
e.onversionchange = () => e.close(), n(e);
|
|
42
43
|
}, i.onerror = () => r(i.error);
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
|
-
function
|
|
46
|
+
function g(e) {
|
|
46
47
|
return new Promise((t, n) => {
|
|
47
48
|
e.oncomplete = () => t(), e.onerror = () => n(e.error), e.onabort = () => n(e.error);
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
|
-
async function
|
|
51
|
-
let n = await
|
|
52
|
-
return await
|
|
51
|
+
async function _(e, t) {
|
|
52
|
+
let n = await h(e, t), r = n.transaction(c, "readonly"), i = r.objectStore(c).get(l);
|
|
53
|
+
return await g(r), n.close(), i.result ?? 0;
|
|
53
54
|
}
|
|
54
|
-
async function
|
|
55
|
-
let i = await
|
|
55
|
+
async function v(e, t, n, r) {
|
|
56
|
+
let i = await h(e, r), a = i.transaction([s, c], "readwrite"), o, u = a.objectStore(c).get(l);
|
|
56
57
|
return u.onsuccess = () => {
|
|
57
58
|
if ((u.result ?? 0) !== n) return;
|
|
58
|
-
let e = a.objectStore(
|
|
59
|
+
let e = a.objectStore(s).add(t);
|
|
59
60
|
e.onsuccess = () => {
|
|
60
|
-
|
|
61
|
+
o = e.result;
|
|
61
62
|
};
|
|
62
|
-
}, await
|
|
63
|
+
}, await g(a), i.close(), o;
|
|
63
64
|
}
|
|
64
|
-
async function
|
|
65
|
-
let i = await
|
|
65
|
+
async function y(e, t, n, r) {
|
|
66
|
+
let i = await h(e), a = i.transaction(s, "readwrite"), o = a.objectStore(s), c = o.get(t);
|
|
66
67
|
c.onsuccess = () => {
|
|
67
68
|
let e = c.result;
|
|
68
|
-
e && (e.ownerState = n, n === "bound" && (e.owner = r ?? null),
|
|
69
|
-
}, await
|
|
69
|
+
e && (e.ownerState = n, n === "bound" && (e.owner = r ?? null), o.put(e));
|
|
70
|
+
}, await g(a), i.close();
|
|
70
71
|
}
|
|
71
|
-
async function
|
|
72
|
-
let n = await
|
|
73
|
-
let n = r.objectStore(
|
|
72
|
+
async function b(e, t) {
|
|
73
|
+
let n = await h(e, t), r = n.transaction(s, "readonly"), i = await new Promise((e, t) => {
|
|
74
|
+
let n = r.objectStore(s).getAll();
|
|
74
75
|
n.onsuccess = () => e(n.result), n.onerror = () => t(n.error);
|
|
75
76
|
});
|
|
76
77
|
return n.close(), i;
|
|
77
78
|
}
|
|
78
|
-
async function b(e, t) {
|
|
79
|
-
let n = await m(e), r = n.transaction(o, "readonly"), i = r.objectStore(o).count(t);
|
|
80
|
-
return await h(r), n.close(), i.result > 0;
|
|
81
|
-
}
|
|
82
79
|
async function x(e, t) {
|
|
83
|
-
let n = await
|
|
84
|
-
|
|
80
|
+
let n = await h(e), r = n.transaction(s, "readonly"), i = r.objectStore(s).count(t);
|
|
81
|
+
return await g(r), n.close(), i.result > 0;
|
|
85
82
|
}
|
|
86
|
-
async function S(e, t
|
|
87
|
-
let
|
|
83
|
+
async function S(e, t) {
|
|
84
|
+
let n = await h(e), r = n.transaction(s, "readwrite");
|
|
85
|
+
r.objectStore(s).delete(t), await g(r), n.close();
|
|
86
|
+
}
|
|
87
|
+
async function C(e, t, n, r) {
|
|
88
|
+
let i = await e.clone().arrayBuffer(), { kept: a, stripped: o } = p(e.headers.entries(), n);
|
|
88
89
|
return {
|
|
89
90
|
url: e.url,
|
|
90
91
|
method: e.method,
|
|
@@ -96,8 +97,8 @@ async function S(e, t, n, r) {
|
|
|
96
97
|
ownerState: r
|
|
97
98
|
};
|
|
98
99
|
}
|
|
99
|
-
function
|
|
100
|
-
let { kept: n, stripped: r } =
|
|
100
|
+
function w(e, t) {
|
|
101
|
+
let { kept: n, stripped: r } = p(e.headers, t);
|
|
101
102
|
return {
|
|
102
103
|
request: new Request(e.url, {
|
|
103
104
|
method: e.method,
|
|
@@ -108,10 +109,10 @@ function C(e, t) {
|
|
|
108
109
|
strippedHeaders: [.../* @__PURE__ */ new Set([...e.strippedHeaders ?? [], ...r])]
|
|
109
110
|
};
|
|
110
111
|
}
|
|
111
|
-
async function
|
|
112
|
+
async function T(e, t, n) {
|
|
112
113
|
let r = new MessageChannel(), i = await Promise.race([new Promise((n) => {
|
|
113
114
|
r.port1.onmessage = (e) => n(e.data), e.postMessage({
|
|
114
|
-
type:
|
|
115
|
+
type: u,
|
|
115
116
|
...t
|
|
116
117
|
}, [r.port2]);
|
|
117
118
|
}), n.then(() => void 0)]);
|
|
@@ -123,50 +124,54 @@ async function w(e, t, n) {
|
|
|
123
124
|
owner: s ? o : null
|
|
124
125
|
};
|
|
125
126
|
}
|
|
126
|
-
function
|
|
127
|
+
function E() {
|
|
127
128
|
let e;
|
|
128
129
|
return {
|
|
129
130
|
promise: new Promise((t) => {
|
|
130
|
-
e = setTimeout(t,
|
|
131
|
+
e = setTimeout(t, d);
|
|
131
132
|
}),
|
|
132
133
|
cancel: () => clearTimeout(e)
|
|
133
134
|
};
|
|
134
135
|
}
|
|
135
|
-
async function
|
|
136
|
+
async function D(e, t) {
|
|
136
137
|
let n = await e.clients?.matchAll({ type: "window" }) ?? [];
|
|
137
138
|
if (n.length === 0) return [];
|
|
138
|
-
let r =
|
|
139
|
+
let r = E(), i = await Promise.all(n.map((e) => T(e, t, r.promise)));
|
|
139
140
|
return r.cancel(), i.filter((e) => e !== void 0);
|
|
140
141
|
}
|
|
141
|
-
function
|
|
142
|
-
let n = /* @__PURE__ */ new Map(), r = !1;
|
|
142
|
+
function O(t) {
|
|
143
|
+
let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set(), i = !1;
|
|
143
144
|
return {
|
|
144
145
|
ask(e) {
|
|
145
146
|
let r = `${e.method} ${e.url}`, i = n.get(r);
|
|
146
|
-
return i || (i =
|
|
147
|
+
return i || (i = D(t, {
|
|
147
148
|
url: e.url,
|
|
148
149
|
method: e.method,
|
|
149
150
|
phase: "replay"
|
|
150
151
|
}), n.set(r, i)), i;
|
|
151
152
|
},
|
|
152
153
|
warnNoAnswer() {
|
|
153
|
-
!
|
|
154
|
+
!i && e() && (i = !0, console.warn("[tempest-react-sdk/sw] background-sync: a queued request needs an open page to confirm who is signed in or to supply the current credentials, and no open page answered. Call provideBackgroundSyncCredentials() in the page; the entry stays pending."));
|
|
155
|
+
},
|
|
156
|
+
warnOutOfScope(t) {
|
|
157
|
+
let n = new URL(t).origin;
|
|
158
|
+
!r.has(n) && e() && (r.add(n), console.warn(`[tempest-react-sdk/sw] background-sync: dropped a credentialed request to ${n}; list it in trustedOrigins to replay it.`));
|
|
154
159
|
}
|
|
155
160
|
};
|
|
156
161
|
}
|
|
157
|
-
function
|
|
162
|
+
function k(e, t) {
|
|
158
163
|
switch (t.ownerState) {
|
|
159
164
|
case "bound": return e.find((e) => e.hasPrincipal && e.owner === t.owner);
|
|
160
165
|
case "unknown": return e.every((e) => !e.hasPrincipal) ? e[0] : void 0;
|
|
161
166
|
case "unbound": return e.find((e) => !e.hasPrincipal) ?? e[0];
|
|
162
167
|
}
|
|
163
168
|
}
|
|
164
|
-
async function
|
|
169
|
+
async function A(e, t, n, r) {
|
|
165
170
|
let i = n.strippedHeaders.length > 0, a = n.ownerState === "unbound" || r === "lenient" && n.ownerState === "unknown";
|
|
166
171
|
if (!i && a) return t;
|
|
167
172
|
let o = await e.ask(t);
|
|
168
173
|
if (o.length === 0) throw e.warnNoAnswer(), Error("background-sync: no client answered");
|
|
169
|
-
let s =
|
|
174
|
+
let s = k(o, n);
|
|
170
175
|
if (!s) return null;
|
|
171
176
|
if (!i) return t;
|
|
172
177
|
if (s.headers === null) return null;
|
|
@@ -176,118 +181,133 @@ async function k(e, t, n, r) {
|
|
|
176
181
|
for (let e of n.strippedHeaders) l.set(e, c.get(e));
|
|
177
182
|
return new Request(t, { headers: l });
|
|
178
183
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
184
|
+
function j(e, t) {
|
|
185
|
+
return [...e.headers.keys()].some((e) => t.has(e));
|
|
186
|
+
}
|
|
187
|
+
async function M(e, t) {
|
|
188
|
+
let { sw: n, name: r, maxRetentionMs: i, credentialHeaders: a, beforeReplay: o, ownerPolicy: s, inCredentialScope: c } = e, l = O(n), u = o ?? ((e, t) => A(l, e, t, s)), d = await b(r, a), p = 0;
|
|
189
|
+
for (let e of d) {
|
|
182
190
|
if (e.id === void 0) continue;
|
|
183
191
|
if (t - e.timestamp > i) {
|
|
184
|
-
await
|
|
192
|
+
await S(r, e.id);
|
|
185
193
|
continue;
|
|
186
194
|
}
|
|
187
195
|
let n = e.ownerState ?? "unknown";
|
|
188
|
-
if (n === "pending" && t - e.timestamp <
|
|
189
|
-
|
|
196
|
+
if (n === "pending" && t - e.timestamp < f) {
|
|
197
|
+
p += 1;
|
|
190
198
|
continue;
|
|
191
199
|
}
|
|
192
200
|
let o = n === "pending" ? "unknown" : n;
|
|
193
201
|
try {
|
|
194
|
-
let { request: t, strippedHeaders: n } =
|
|
202
|
+
let { request: t, strippedHeaders: n } = w(e, a);
|
|
203
|
+
if (n.length > 0 && !c(t.url)) {
|
|
204
|
+
l.warnOutOfScope(t.url), await S(r, e.id);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
let i = await u(t, {
|
|
195
208
|
queuedAt: e.timestamp,
|
|
196
209
|
strippedHeaders: n,
|
|
197
210
|
ownerState: o,
|
|
198
211
|
owner: o === "bound" ? e.owner ?? null : void 0
|
|
199
212
|
});
|
|
200
|
-
if (!await
|
|
213
|
+
if (!await x(r, e.id)) continue;
|
|
201
214
|
if (i === null) {
|
|
202
|
-
await
|
|
215
|
+
await S(r, e.id);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (j(i, a) && !c(i.url)) {
|
|
219
|
+
l.warnOutOfScope(i.url), await S(r, e.id);
|
|
203
220
|
continue;
|
|
204
221
|
}
|
|
205
222
|
let s = await fetch(i);
|
|
206
|
-
s.ok || s.status >= 400 && s.status < 500 ? await
|
|
223
|
+
s.ok || s.status >= 400 && s.status < 500 ? await S(r, e.id) : p += 1;
|
|
207
224
|
} catch {
|
|
208
|
-
|
|
225
|
+
p += 1;
|
|
209
226
|
}
|
|
210
227
|
}
|
|
211
|
-
if (
|
|
228
|
+
if (p > 0) throw Error(`background-sync: ${p} request(s) still pending`);
|
|
212
229
|
}
|
|
213
|
-
var
|
|
214
|
-
function
|
|
215
|
-
let t =
|
|
230
|
+
var N = /* @__PURE__ */ new Map();
|
|
231
|
+
function P(e) {
|
|
232
|
+
let t = N.get(e.name);
|
|
216
233
|
if (t) return t;
|
|
217
|
-
let n =
|
|
218
|
-
|
|
234
|
+
let n = M(e, Date.now()).finally(() => {
|
|
235
|
+
N.delete(e.name);
|
|
219
236
|
});
|
|
220
|
-
return
|
|
237
|
+
return N.set(e.name, n), n;
|
|
221
238
|
}
|
|
222
|
-
function
|
|
239
|
+
function F(e, t, n) {
|
|
223
240
|
return e ? typeof e == "function" ? e(t, n) : e.test(t.href) : !0;
|
|
224
241
|
}
|
|
225
|
-
async function
|
|
226
|
-
let i =
|
|
242
|
+
async function I(e, t, n, r) {
|
|
243
|
+
let i = E(), a = await T(n, {
|
|
227
244
|
url: r.url,
|
|
228
245
|
method: r.method,
|
|
229
246
|
phase: "enqueue"
|
|
230
247
|
}, i.promise);
|
|
231
|
-
i.cancel(), await
|
|
248
|
+
i.cancel(), await y(e, t, a ? a.hasPrincipal ? "bound" : "unbound" : "unknown", a?.owner);
|
|
232
249
|
}
|
|
233
|
-
function
|
|
234
|
-
let
|
|
235
|
-
sw:
|
|
236
|
-
name:
|
|
237
|
-
maxRetentionMs:
|
|
238
|
-
credentialHeaders:
|
|
239
|
-
beforeReplay:
|
|
240
|
-
ownerPolicy:
|
|
250
|
+
function L(e = {}) {
|
|
251
|
+
let o = i(), { match: s, queueName: c = a, maxRetentionMinutes: l = 1440, periodicSyncTag: u = `${e.queueName ?? a}-periodic`, credentialHeaders: d = n, beforeReplay: f, ownerPolicy: p = "strict", trustedOrigins: m = [] } = e, h = r(d), g = globalThis.location?.href ?? "", y = {
|
|
252
|
+
sw: o,
|
|
253
|
+
name: c,
|
|
254
|
+
maxRetentionMs: l * 60 * 1e3,
|
|
255
|
+
credentialHeaders: h,
|
|
256
|
+
beforeReplay: f,
|
|
257
|
+
ownerPolicy: p,
|
|
258
|
+
inCredentialScope: (e) => t(e, g, m)
|
|
241
259
|
};
|
|
242
|
-
|
|
260
|
+
o.addEventListener("fetch", (e) => {
|
|
243
261
|
let t = e.request;
|
|
244
262
|
if (t.method === "GET" || t.method === "HEAD") return;
|
|
245
263
|
let n = new URL(t.url);
|
|
246
|
-
if (!
|
|
247
|
-
let r =
|
|
264
|
+
if (!F(s, n, t)) return;
|
|
265
|
+
let r = _(c, h);
|
|
248
266
|
r.catch(() => void 0);
|
|
249
|
-
let i = fetch(t.clone()),
|
|
250
|
-
let n = e.clientId ? await
|
|
251
|
-
if (
|
|
267
|
+
let i = fetch(t.clone()), a = i.then(() => void 0, async () => {
|
|
268
|
+
let n = e.clientId ? await o.clients?.get(e.clientId) : void 0, i = await C(t, Date.now(), h, n ? "pending" : "unknown"), a = await v(c, i, await r, h);
|
|
269
|
+
if (a !== void 0) {
|
|
252
270
|
try {
|
|
253
|
-
await
|
|
271
|
+
await o.registration.sync?.register(c);
|
|
254
272
|
} catch {}
|
|
255
273
|
return n ? {
|
|
256
|
-
id:
|
|
274
|
+
id: a,
|
|
257
275
|
issuer: n
|
|
258
276
|
} : void 0;
|
|
259
277
|
}
|
|
260
278
|
});
|
|
261
279
|
e.respondWith(i.catch(async (e) => {
|
|
262
|
-
throw await
|
|
263
|
-
})), e.waitUntil(
|
|
264
|
-
}),
|
|
265
|
-
e.tag ===
|
|
266
|
-
}),
|
|
267
|
-
e.tag ===
|
|
268
|
-
}),
|
|
269
|
-
|
|
280
|
+
throw await a, e;
|
|
281
|
+
})), e.waitUntil(a.then((e) => e ? I(c, e.id, e.issuer, t) : void 0).catch(() => void 0));
|
|
282
|
+
}), o.addEventListener("sync", (e) => {
|
|
283
|
+
e.tag === c && e.waitUntil(P(y));
|
|
284
|
+
}), o.addEventListener("periodicsync", (e) => {
|
|
285
|
+
e.tag === u && e.waitUntil(P(y).catch(() => void 0));
|
|
286
|
+
}), o.addEventListener("fetch", (e) => {
|
|
287
|
+
o.registration.sync || e.request.method === "GET" && e.waitUntil(P(y).catch(() => void 0));
|
|
270
288
|
});
|
|
271
289
|
}
|
|
272
|
-
async function
|
|
290
|
+
async function R(e = a) {
|
|
273
291
|
if (typeof indexedDB > "u") return !1;
|
|
274
|
-
let t = await
|
|
275
|
-
n.objectStore(
|
|
276
|
-
let r = n.objectStore(
|
|
277
|
-
return
|
|
278
|
-
r.put((
|
|
279
|
-
}, await
|
|
292
|
+
let t = await h(e), n = t.transaction([s, c], "readwrite");
|
|
293
|
+
n.objectStore(s).clear();
|
|
294
|
+
let r = n.objectStore(c), i = r.get(l);
|
|
295
|
+
return i.onsuccess = () => {
|
|
296
|
+
r.put((i.result ?? 0) + 1, l);
|
|
297
|
+
}, await g(n), t.close(), !0;
|
|
280
298
|
}
|
|
281
|
-
async function
|
|
299
|
+
async function z(e) {
|
|
282
300
|
if (e == null || e === "") return null;
|
|
283
301
|
let t = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`tempest-bg-sync:${e}`));
|
|
284
302
|
return [...new Uint8Array(t)].map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
285
303
|
}
|
|
286
|
-
function
|
|
304
|
+
function B(t, n = {}) {
|
|
287
305
|
if (typeof navigator > "u" || !navigator.serviceWorker) return () => void 0;
|
|
288
|
-
let
|
|
289
|
-
|
|
290
|
-
|
|
306
|
+
let r = navigator.serviceWorker, { getPrincipal: i } = n;
|
|
307
|
+
!i && e() && console.warn("[tempest-react-sdk/sw] provideBackgroundSyncCredentials() without `getPrincipal`: queued mutations are not bound to the account that made them and replay with whichever session answers next, unless clearSessionData() runs on logout. Pass { getPrincipal: () => currentUserId } to bind them.");
|
|
308
|
+
let a = (e) => {
|
|
309
|
+
let n = e.data, r = e.ports[0];
|
|
310
|
+
if (n?.type !== "tempest:bg-sync-credentials" || !r) return;
|
|
291
311
|
let a = {
|
|
292
312
|
url: String(n.url),
|
|
293
313
|
method: String(n.method),
|
|
@@ -295,16 +315,16 @@ function R(e, t = {}) {
|
|
|
295
315
|
};
|
|
296
316
|
(async () => {
|
|
297
317
|
try {
|
|
298
|
-
let
|
|
299
|
-
|
|
318
|
+
let e = { headers: a.phase === "enqueue" ? null : await t(a) };
|
|
319
|
+
i && (e.owner = await z(await i())), r.postMessage(e);
|
|
300
320
|
} catch {
|
|
301
|
-
|
|
321
|
+
r.postMessage({ error: !0 });
|
|
302
322
|
}
|
|
303
323
|
})();
|
|
304
324
|
};
|
|
305
|
-
return
|
|
325
|
+
return r.addEventListener("message", a), () => r.removeEventListener("message", a);
|
|
306
326
|
}
|
|
307
327
|
//#endregion
|
|
308
|
-
export {
|
|
328
|
+
export { u as BACKGROUND_SYNC_CREDENTIALS_MESSAGE, R as clearBackgroundSyncQueue, L as installBackgroundSync, B as provideBackgroundSyncCredentials };
|
|
309
329
|
|
|
310
330
|
//# sourceMappingURL=background-sync.js.map
|