tempest-react-sdk 0.79.0 → 0.81.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.
Files changed (131) hide show
  1. package/README.md +35 -4
  2. package/bin/lib/component/generate.test.mjs +13 -1
  3. package/bin/lib/openapi/generate.hostile.test.mjs +58 -5
  4. package/bin/lib/openapi/generate.mjs +145 -34
  5. package/bin/lib/openapi/generate.test.mjs +216 -5
  6. package/bin/lib/openapi/schema-to-zod.mjs +4 -3
  7. package/dist/auth/create-tempest-auth.cjs +1 -1
  8. package/dist/auth/create-tempest-auth.cjs.map +1 -1
  9. package/dist/auth/create-tempest-auth.js +172 -103
  10. package/dist/auth/create-tempest-auth.js.map +1 -1
  11. package/dist/br/boleto.cjs +1 -1
  12. package/dist/br/boleto.cjs.map +1 -1
  13. package/dist/br/boleto.js +2 -1
  14. package/dist/br/boleto.js.map +1 -1
  15. package/dist/br.d.ts +22 -3
  16. package/dist/components/AuthForm/AuthFieldControl.cjs +2 -0
  17. package/dist/components/AuthForm/AuthFieldControl.cjs.map +1 -0
  18. package/dist/components/AuthForm/AuthFieldControl.js +85 -0
  19. package/dist/components/AuthForm/AuthFieldControl.js.map +1 -0
  20. package/dist/components/AuthForm/AuthForm.cjs +2 -0
  21. package/dist/components/AuthForm/AuthForm.cjs.map +1 -0
  22. package/dist/components/AuthForm/AuthForm.js +83 -0
  23. package/dist/components/AuthForm/AuthForm.js.map +1 -0
  24. package/dist/components/AuthForm/AuthForm.module.cjs +3 -0
  25. package/dist/components/AuthForm/AuthForm.module.cjs.map +1 -0
  26. package/dist/components/AuthForm/AuthForm.module.js +14 -0
  27. package/dist/components/AuthForm/AuthForm.module.js.map +1 -0
  28. package/dist/components/AuthForm/AuthLinks.cjs +2 -0
  29. package/dist/components/AuthForm/AuthLinks.cjs.map +1 -0
  30. package/dist/components/AuthForm/AuthLinks.js +29 -0
  31. package/dist/components/AuthForm/AuthLinks.js.map +1 -0
  32. package/dist/components/AuthForm/ForgotPasswordForm.cjs +2 -0
  33. package/dist/components/AuthForm/ForgotPasswordForm.cjs.map +1 -0
  34. package/dist/components/AuthForm/ForgotPasswordForm.js +32 -0
  35. package/dist/components/AuthForm/ForgotPasswordForm.js.map +1 -0
  36. package/dist/components/AuthForm/LoginForm.cjs +2 -0
  37. package/dist/components/AuthForm/LoginForm.cjs.map +1 -0
  38. package/dist/components/AuthForm/LoginForm.js +39 -0
  39. package/dist/components/AuthForm/LoginForm.js.map +1 -0
  40. package/dist/components/AuthForm/ResetPasswordForm.cjs +2 -0
  41. package/dist/components/AuthForm/ResetPasswordForm.cjs.map +1 -0
  42. package/dist/components/AuthForm/ResetPasswordForm.js +39 -0
  43. package/dist/components/AuthForm/ResetPasswordForm.js.map +1 -0
  44. package/dist/components/AuthForm/SignUpForm.cjs +2 -0
  45. package/dist/components/AuthForm/SignUpForm.cjs.map +1 -0
  46. package/dist/components/AuthForm/SignUpForm.js +32 -0
  47. package/dist/components/AuthForm/SignUpForm.js.map +1 -0
  48. package/dist/components/AuthForm/auth-defaults.cjs +2 -0
  49. package/dist/components/AuthForm/auth-defaults.cjs.map +1 -0
  50. package/dist/components/AuthForm/auth-defaults.js +54 -0
  51. package/dist/components/AuthForm/auth-defaults.js.map +1 -0
  52. package/dist/components/AuthForm/auth-schemas.cjs +2 -0
  53. package/dist/components/AuthForm/auth-schemas.cjs.map +1 -0
  54. package/dist/components/AuthForm/auth-schemas.js +26 -0
  55. package/dist/components/AuthForm/auth-schemas.js.map +1 -0
  56. package/dist/components/AuthPage/AuthPage.cjs +2 -0
  57. package/dist/components/AuthPage/AuthPage.cjs.map +1 -0
  58. package/dist/components/AuthPage/AuthPage.js +91 -0
  59. package/dist/components/AuthPage/AuthPage.js.map +1 -0
  60. package/dist/components/AuthPage/AuthPage.module.cjs +3 -0
  61. package/dist/components/AuthPage/AuthPage.module.cjs.map +1 -0
  62. package/dist/components/AuthPage/AuthPage.module.js +24 -0
  63. package/dist/components/AuthPage/AuthPage.module.js.map +1 -0
  64. package/dist/components/FilterBar/filter-apply.cjs +1 -1
  65. package/dist/components/FilterBar/filter-apply.cjs.map +1 -1
  66. package/dist/components/FilterBar/filter-apply.js +7 -7
  67. package/dist/forms/index.js +7 -7
  68. package/dist/forms/masked-inputs.cjs +1 -1
  69. package/dist/forms/masked-inputs.cjs.map +1 -1
  70. package/dist/forms/masked-inputs.js +15 -15
  71. package/dist/http/api-client.cjs +1 -1
  72. package/dist/http/api-client.cjs.map +1 -1
  73. package/dist/http/api-client.js +104 -97
  74. package/dist/http/api-client.js.map +1 -1
  75. package/dist/http/build-url.cjs +1 -1
  76. package/dist/http/build-url.cjs.map +1 -1
  77. package/dist/http/build-url.js +3 -1
  78. package/dist/http/build-url.js.map +1 -1
  79. package/dist/http/presigned-post.cjs +2 -0
  80. package/dist/http/presigned-post.cjs.map +1 -0
  81. package/dist/http/presigned-post.js +73 -0
  82. package/dist/http/presigned-post.js.map +1 -0
  83. package/dist/http/resumable-upload.cjs +1 -1
  84. package/dist/http/resumable-upload.cjs.map +1 -1
  85. package/dist/http/resumable-upload.js +97 -97
  86. package/dist/http/resumable-upload.js.map +1 -1
  87. package/dist/http/upload-with-progress.cjs +1 -1
  88. package/dist/http/upload-with-progress.cjs.map +1 -1
  89. package/dist/http/upload-with-progress.js +12 -12
  90. package/dist/http/use-describe-api-error.cjs +1 -1
  91. package/dist/http/use-describe-api-error.cjs.map +1 -1
  92. package/dist/http/use-describe-api-error.js +9 -9
  93. package/dist/offline/create-offline-sync.cjs +1 -1
  94. package/dist/offline/create-offline-sync.cjs.map +1 -1
  95. package/dist/offline/create-offline-sync.js +78 -56
  96. package/dist/offline/create-offline-sync.js.map +1 -1
  97. package/dist/sse/create-event-stream.cjs +1 -1
  98. package/dist/sse/create-event-stream.cjs.map +1 -1
  99. package/dist/sse/create-event-stream.js +44 -30
  100. package/dist/sse/create-event-stream.js.map +1 -1
  101. package/dist/sse/ticket-event-stream.cjs +2 -0
  102. package/dist/sse/ticket-event-stream.cjs.map +1 -0
  103. package/dist/sse/ticket-event-stream.js +41 -0
  104. package/dist/sse/ticket-event-stream.js.map +1 -0
  105. package/dist/sse/use-event-stream.cjs +1 -1
  106. package/dist/sse/use-event-stream.cjs.map +1 -1
  107. package/dist/sse/use-event-stream.js +7 -4
  108. package/dist/sse/use-event-stream.js.map +1 -1
  109. package/dist/styles/AuthForm.css +2 -0
  110. package/dist/styles/AuthPage.css +2 -0
  111. package/dist/styles/component/AuthForm.css +9 -0
  112. package/dist/styles/component/AuthPage.css +29 -0
  113. package/dist/styles/forms.css +36 -0
  114. package/dist/styles/manifest.json +63 -0
  115. package/dist/styles.css +1 -1
  116. package/dist/sw/background-sync.cjs +1 -1
  117. package/dist/sw/background-sync.cjs.map +1 -1
  118. package/dist/sw/background-sync.js +124 -106
  119. package/dist/sw/background-sync.js.map +1 -1
  120. package/dist/sw.d.ts +49 -15
  121. package/dist/tempest-react-sdk.cjs +1 -1
  122. package/dist/tempest-react-sdk.d.ts +809 -22
  123. package/dist/tempest-react-sdk.js +373 -363
  124. package/dist/utils/format.cjs +1 -1
  125. package/dist/utils/format.cjs.map +1 -1
  126. package/dist/utils/format.js +25 -25
  127. package/dist/utils/numbers.cjs +1 -1
  128. package/dist/utils/numbers.cjs.map +1 -1
  129. package/dist/utils/numbers.js +7 -7
  130. package/package.json +1 -1
  131. package/template-pwa/src/sw.ts +10 -6
@@ -1,11 +1,12 @@
1
1
  import { isDevBuild as e } from "../utils/dev-mode.js";
2
- import { DEFAULT_CREDENTIAL_HEADERS as t, credentialHeaderSet as n } from "./credential-headers.js";
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 r() {
5
+ function i() {
5
6
  return globalThis;
6
7
  }
7
- var i = "tempest-bg-sync", a = 2, o = "requests", s = "meta", c = "epoch", l = "tempest:bg-sync-credentials", u = 3e3, d = u * 2;
8
- function f(e, t) {
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 p(e, t) {
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 } = f(r.headers, t);
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 m(e, t = n()) {
31
+ function h(e, t = r()) {
31
32
  return new Promise((n, r) => {
32
- let i = indexedDB.open(e, a);
33
+ let i = indexedDB.open(e, o);
33
34
  i.onupgradeneeded = (e) => {
34
35
  let n = i.result;
35
- n.objectStoreNames.contains(o) ? e.oldVersion < 2 && i.transaction && p(i.transaction.objectStore(o), t) : n.createObjectStore(o, {
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(s) || n.createObjectStore(s);
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 h(e) {
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 g(e, t) {
51
- let n = await m(e, t), r = n.transaction(s, "readonly"), i = r.objectStore(s).get(c);
52
- return await h(r), n.close(), i.result ?? 0;
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 _(e, t, n, r) {
55
- let i = await m(e, r), a = i.transaction([o, s], "readwrite"), l, u = a.objectStore(s).get(c);
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(o).add(t);
59
+ let e = a.objectStore(s).add(t);
59
60
  e.onsuccess = () => {
60
- l = e.result;
61
+ o = e.result;
61
62
  };
62
- }, await h(a), i.close(), l;
63
+ }, await g(a), i.close(), o;
63
64
  }
64
- async function v(e, t, n, r) {
65
- let i = await m(e), a = i.transaction(o, "readwrite"), s = a.objectStore(o), c = s.get(t);
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), s.put(e));
69
- }, await h(a), i.close();
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 y(e, t) {
72
- let n = await m(e, t), r = n.transaction(o, "readonly"), i = await new Promise((e, t) => {
73
- let n = r.objectStore(o).getAll();
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 m(e), r = n.transaction(o, "readwrite");
84
- r.objectStore(o).delete(t), await h(r), n.close();
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, n, r) {
87
- let i = await e.clone().arrayBuffer(), { kept: a, stripped: o } = f(e.headers.entries(), n);
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 C(e, t) {
100
- let { kept: n, stripped: r } = f(e.headers, t);
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 w(e, t, n) {
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: l,
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 T() {
127
+ function E() {
127
128
  let e;
128
129
  return {
129
130
  promise: new Promise((t) => {
130
- e = setTimeout(t, u);
131
+ e = setTimeout(t, d);
131
132
  }),
132
133
  cancel: () => clearTimeout(e)
133
134
  };
134
135
  }
135
- async function E(e, t) {
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 = T(), i = await Promise.all(n.map((e) => w(e, t, r.promise)));
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 D(t) {
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 = E(t, {
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
- !r && e() && (r = !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."));
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 O(e, t) {
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 k(e, t, n, r) {
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 = O(o, n);
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,114 +181,127 @@ 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
- async function A(e, t) {
180
- let { sw: n, name: r, maxRetentionMs: i, credentialHeaders: a, beforeReplay: o, ownerPolicy: s } = e, c = D(n), l = o ?? ((e, t) => k(c, e, t, s)), u = await y(r, a), f = 0;
181
- for (let e of u) {
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 x(r, e.id);
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 < d) {
189
- f += 1;
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 } = C(e, a), i = await l(t, {
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 b(r, e.id)) continue;
213
+ if (!await x(r, e.id)) continue;
201
214
  if (i === null) {
202
- await x(r, e.id);
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 x(r, e.id) : f += 1;
223
+ s.ok || s.status >= 400 && s.status < 500 ? await S(r, e.id) : p += 1;
207
224
  } catch {
208
- f += 1;
225
+ p += 1;
209
226
  }
210
227
  }
211
- if (f > 0) throw Error(`background-sync: ${f} request(s) still pending`);
228
+ if (p > 0) throw Error(`background-sync: ${p} request(s) still pending`);
212
229
  }
213
- var j = /* @__PURE__ */ new Map();
214
- function M(e) {
215
- let t = j.get(e.name);
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 = A(e, Date.now()).finally(() => {
218
- j.delete(e.name);
234
+ let n = M(e, Date.now()).finally(() => {
235
+ N.delete(e.name);
219
236
  });
220
- return j.set(e.name, n), n;
237
+ return N.set(e.name, n), n;
221
238
  }
222
- function N(e, t, n) {
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 P(e, t, n, r) {
226
- let i = T(), a = await w(n, {
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 v(e, t, a ? a.hasPrincipal ? "bound" : "unbound" : "unknown", a?.owner);
248
+ i.cancel(), await y(e, t, a ? a.hasPrincipal ? "bound" : "unbound" : "unknown", a?.owner);
232
249
  }
233
- function F(e = {}) {
234
- let a = r(), { match: o, queueName: s = i, maxRetentionMinutes: c = 1440, periodicSyncTag: l = `${e.queueName ?? i}-periodic`, credentialHeaders: u = t, beforeReplay: d, ownerPolicy: f = "strict" } = e, p = n(u), m = {
235
- sw: a,
236
- name: s,
237
- maxRetentionMs: c * 60 * 1e3,
238
- credentialHeaders: p,
239
- beforeReplay: d,
240
- ownerPolicy: f
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
- a.addEventListener("fetch", (e) => {
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 (!N(o, n, t)) return;
247
- let r = g(s, p);
264
+ if (!F(s, n, t)) return;
265
+ let r = _(c, h);
248
266
  r.catch(() => void 0);
249
- let i = fetch(t.clone()), c = i.then(() => void 0, async () => {
250
- let n = e.clientId ? await a.clients?.get(e.clientId) : void 0, i = await S(t, Date.now(), p, n ? "pending" : "unknown"), o = await _(s, i, await r, p);
251
- if (o !== void 0) {
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 a.registration.sync?.register(s);
271
+ await o.registration.sync?.register(c);
254
272
  } catch {}
255
273
  return n ? {
256
- id: o,
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 c, e;
263
- })), e.waitUntil(c.then((e) => e ? P(s, e.id, e.issuer, t) : void 0).catch(() => void 0));
264
- }), a.addEventListener("sync", (e) => {
265
- e.tag === s && e.waitUntil(M(m));
266
- }), a.addEventListener("periodicsync", (e) => {
267
- e.tag === l && e.waitUntil(M(m).catch(() => void 0));
268
- }), a.addEventListener("fetch", (e) => {
269
- a.registration.sync || e.request.method === "GET" && e.waitUntil(M(m).catch(() => void 0));
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 I(e = i) {
290
+ async function R(e = a) {
273
291
  if (typeof indexedDB > "u") return !1;
274
- let t = await m(e), n = t.transaction([o, s], "readwrite");
275
- n.objectStore(o).clear();
276
- let r = n.objectStore(s), a = r.get(c);
277
- return a.onsuccess = () => {
278
- r.put((a.result ?? 0) + 1, c);
279
- }, await h(n), t.close(), !0;
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 L(e) {
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 R(e, t = {}) {
304
+ function B(e, t = {}) {
287
305
  if (typeof navigator > "u" || !navigator.serviceWorker) return () => void 0;
288
306
  let n = navigator.serviceWorker, { getPrincipal: r } = t, i = (t) => {
289
307
  let n = t.data, i = t.ports[0];
@@ -296,7 +314,7 @@ function R(e, t = {}) {
296
314
  (async () => {
297
315
  try {
298
316
  let t = { headers: a.phase === "enqueue" ? null : await e(a) };
299
- r && (t.owner = await L(await r())), i.postMessage(t);
317
+ r && (t.owner = await z(await r())), i.postMessage(t);
300
318
  } catch {
301
319
  i.postMessage({ error: !0 });
302
320
  }
@@ -305,6 +323,6 @@ function R(e, t = {}) {
305
323
  return n.addEventListener("message", i), () => n.removeEventListener("message", i);
306
324
  }
307
325
  //#endregion
308
- export { l as BACKGROUND_SYNC_CREDENTIALS_MESSAGE, I as clearBackgroundSyncQueue, F as installBackgroundSync, R as provideBackgroundSyncCredentials };
326
+ export { u as BACKGROUND_SYNC_CREDENTIALS_MESSAGE, R as clearBackgroundSyncQueue, L as installBackgroundSync, B as provideBackgroundSyncCredentials };
309
327
 
310
328
  //# sourceMappingURL=background-sync.js.map