tempest-react-sdk 0.81.0 → 0.83.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 +9 -10
- package/bin/create-tempest-app.e2e.test.mjs +31 -0
- package/bin/create-tempest-app.mjs +11 -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 +228 -0
- package/bin/lib/openapi/generate.mjs +119 -15
- 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 +189 -143
- 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.map +1 -1
- package/dist/br/boleto.js.map +1 -1
- package/dist/components/AuthForm/AuthLinks.cjs +1 -1
- package/dist/components/AuthForm/AuthLinks.cjs.map +1 -1
- package/dist/components/AuthForm/AuthLinks.js +18 -15
- package/dist/components/AuthForm/AuthLinks.js.map +1 -1
- package/dist/components/AuthPage/AuthPage.cjs +1 -1
- package/dist/components/AuthPage/AuthPage.cjs.map +1 -1
- package/dist/components/AuthPage/AuthPage.js +58 -52
- package/dist/components/AuthPage/AuthPage.js.map +1 -1
- 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/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/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 +90 -72
- 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 +167 -112
- 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 +100 -44
- package/dist/http/upload-with-progress.js.map +1 -1
- 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 +87 -69
- 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 +67 -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/sw/background-sync.cjs +1 -1
- package/dist/sw/background-sync.cjs.map +1 -1
- package/dist/sw/background-sync.js +10 -8
- 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 +111 -55
- 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 +65 -14
- 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 +543 -70
- package/dist/tempest-react-sdk.js +224 -224
- 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/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/vite/base-url.cjs +1 -1
- package/dist/vite/base-url.cjs.map +1 -1
- package/dist/vite/base-url.js +5 -1
- package/dist/vite/base-url.js.map +1 -1
- package/dist/vite/tempest-pwa-dev-sw.cjs +1 -1
- package/dist/vite/tempest-pwa-dev-sw.cjs.map +1 -1
- package/dist/vite/tempest-pwa-dev-sw.js +96 -31
- package/dist/vite/tempest-pwa-dev-sw.js.map +1 -1
- package/dist/vite/tempest-pwa-manifest.cjs +2 -2
- package/dist/vite/tempest-pwa-manifest.cjs.map +1 -1
- package/dist/vite/tempest-pwa-manifest.js +32 -16
- package/dist/vite/tempest-pwa-manifest.js.map +1 -1
- package/dist/vite.cjs +1 -1
- package/dist/vite.d.ts +63 -12
- package/dist/vite.js +4 -4
- 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 +5 -4
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { TempestApiError as e, buildApiError as t, isApiError as n, isRetriableStatus as r } from "./errors.js";
|
|
2
2
|
import { bytesToBase64 as i } from "../utils/base64.js";
|
|
3
|
-
import { isTrustedCredentialTarget as a, reportSuppressedCredential as o } from "./credential-scope.js";
|
|
4
|
-
import { csrfHeaders as
|
|
5
|
-
import { retry as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import { isTrustedCredentialTarget as a, reportSuppressedCredential as o, resolveRequestUrl as s } from "./credential-scope.js";
|
|
4
|
+
import { csrfHeaders as c } from "./csrf.js";
|
|
5
|
+
import { retry as l } from "./retry.js";
|
|
6
|
+
import { sessionIdentityOf as u } from "../auth/session-identity.js";
|
|
7
|
+
import { ownerFingerprint as d } from "../utils/owner-fingerprint.js";
|
|
8
|
+
import { generateIdempotencyKey as ee } from "./idempotency.js";
|
|
8
9
|
//#region src/http/resumable-upload.ts
|
|
9
|
-
var
|
|
10
|
+
var f = "1.0.0", p = 5242880, m = class extends Error {
|
|
10
11
|
reason;
|
|
11
12
|
constructor(e) {
|
|
12
13
|
super(e === "principal" ? "O usuário mudou durante o upload resumível." : "Os registros de upload resumível foram limpos durante o upload."), this.name = "ResumableUploadSupersededError", this.reason = e;
|
|
13
14
|
}
|
|
14
|
-
},
|
|
15
|
-
function
|
|
15
|
+
}, h = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
function _(e) {
|
|
16
17
|
if (!e) return !1;
|
|
17
18
|
try {
|
|
18
19
|
let t = JSON.parse(e);
|
|
@@ -21,12 +22,12 @@ function g(e) {
|
|
|
21
22
|
return !1;
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
|
-
function
|
|
25
|
+
function v(e) {
|
|
25
26
|
return i(new TextEncoder().encode(e));
|
|
26
27
|
}
|
|
27
|
-
function
|
|
28
|
+
function te(e) {
|
|
28
29
|
if (!e) return null;
|
|
29
|
-
let t = Object.entries(e).map(([e, t]) => `${e} ${
|
|
30
|
+
let t = Object.entries(e).map(([e, t]) => `${e} ${v(t)}`);
|
|
30
31
|
return t.length > 0 ? t.join(",") : null;
|
|
31
32
|
}
|
|
32
33
|
function y(e, t) {
|
|
@@ -58,20 +59,55 @@ function b(e = "tempest-upload:") {
|
|
|
58
59
|
t()?.removeItem(e + n);
|
|
59
60
|
},
|
|
60
61
|
clear() {
|
|
61
|
-
|
|
62
|
+
h.set(e, (h.get(e) ?? 0) + 1);
|
|
62
63
|
let n = t();
|
|
63
64
|
if (!n) return;
|
|
64
65
|
let r = [];
|
|
65
66
|
for (let t = 0; t < n.length; t += 1) {
|
|
66
67
|
let i = n.key(t);
|
|
67
|
-
i?.startsWith(e) &&
|
|
68
|
+
i?.startsWith(e) && _(n.getItem(i)) && r.push(i);
|
|
68
69
|
}
|
|
69
70
|
for (let e of r) n.removeItem(e);
|
|
70
71
|
}
|
|
71
72
|
};
|
|
72
|
-
return
|
|
73
|
+
return g.set(n, () => h.get(e) ?? 0), n;
|
|
73
74
|
}
|
|
74
|
-
|
|
75
|
+
var x = "REDIRECT_REFUSED", S = "UPLOAD_OFFSET_STALLED";
|
|
76
|
+
function C(e) {
|
|
77
|
+
return e.holdRedirects ? w(e) : T(e);
|
|
78
|
+
}
|
|
79
|
+
async function w(t) {
|
|
80
|
+
let n = new AbortController();
|
|
81
|
+
t.register(n);
|
|
82
|
+
let r;
|
|
83
|
+
try {
|
|
84
|
+
r = await fetch(t.url, {
|
|
85
|
+
method: t.method,
|
|
86
|
+
headers: t.headers,
|
|
87
|
+
body: t.body,
|
|
88
|
+
credentials: t.withCredentials ? "include" : "same-origin",
|
|
89
|
+
redirect: "manual",
|
|
90
|
+
signal: n.signal
|
|
91
|
+
});
|
|
92
|
+
} catch {
|
|
93
|
+
throw n.signal.aborted ? new DOMException("Aborted", "AbortError") : new e({
|
|
94
|
+
status: 0,
|
|
95
|
+
detail: "Falha de rede no upload resumível."
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (r.type === "opaqueredirect" || r.status >= 300 && r.status < 400 && r.status !== 304) throw new e({
|
|
99
|
+
status: r.status,
|
|
100
|
+
code: x,
|
|
101
|
+
detail: "Redirect não seguido: a requisição do upload levava os headers fixos."
|
|
102
|
+
});
|
|
103
|
+
let i = t.method === "HEAD" ? "" : await r.text();
|
|
104
|
+
return {
|
|
105
|
+
status: r.status,
|
|
106
|
+
text: i,
|
|
107
|
+
header: (e) => r.headers.get(e)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function T(t) {
|
|
75
111
|
return new Promise((n, r) => {
|
|
76
112
|
let i = new XMLHttpRequest();
|
|
77
113
|
i.open(t.method, t.url), i.withCredentials = t.withCredentials;
|
|
@@ -90,13 +126,13 @@ function x(t) {
|
|
|
90
126
|
})), i.onabort = () => r(new DOMException("Aborted", "AbortError")), t.register(i), i.send(t.body);
|
|
91
127
|
});
|
|
92
128
|
}
|
|
93
|
-
function
|
|
129
|
+
function E(e) {
|
|
94
130
|
let t = e.header("Upload-Offset");
|
|
95
131
|
if (t === null) return null;
|
|
96
132
|
let n = Number(t);
|
|
97
133
|
return Number.isFinite(n) && n >= 0 ? n : null;
|
|
98
134
|
}
|
|
99
|
-
function
|
|
135
|
+
function D(e) {
|
|
100
136
|
if (!e) return null;
|
|
101
137
|
try {
|
|
102
138
|
return JSON.parse(e);
|
|
@@ -104,37 +140,40 @@ function C(e) {
|
|
|
104
140
|
return e;
|
|
105
141
|
}
|
|
106
142
|
}
|
|
107
|
-
var
|
|
108
|
-
function
|
|
109
|
-
return
|
|
143
|
+
var O = /* @__PURE__ */ new Set([409, 412]);
|
|
144
|
+
function ne(e) {
|
|
145
|
+
return n(e) ? e.code === x ? !1 : e.code === S || O.has(e.status) ? !0 : r(e.status) : !0;
|
|
110
146
|
}
|
|
111
|
-
function
|
|
112
|
-
let i =
|
|
147
|
+
function k(n, r) {
|
|
148
|
+
let i = D(n.text), a = t(n.status, i, { get: n.header }), o = typeof i == "object" && !!i && ("detail" in i || "message" in i);
|
|
113
149
|
return new e({
|
|
114
150
|
...a,
|
|
115
151
|
detail: o ? a.detail : r
|
|
116
152
|
});
|
|
117
153
|
}
|
|
118
|
-
function
|
|
119
|
-
let t = typeof window > "u" ? void 0 : window.location.href;
|
|
154
|
+
function re(e, t) {
|
|
120
155
|
try {
|
|
121
|
-
return new URL(e, t).href;
|
|
156
|
+
return new URL(e, s(t) ?? void 0).href;
|
|
122
157
|
} catch {
|
|
123
158
|
return e;
|
|
124
159
|
}
|
|
125
160
|
}
|
|
126
|
-
function
|
|
127
|
-
let { endpoint: n, file: r, chunkSize: i =
|
|
161
|
+
function A(t) {
|
|
162
|
+
let { endpoint: n, file: r, chunkSize: i = p, metadata: s, headers: h = {}, getToken: _, getPrincipal: v, trustedOrigins: x, withCredentials: w = !1, csrf: T, key: D = y(n, r), storage: O = b(), retry: A, onProgress: ie, onStateChange: ae } = t, j = v ?? u(_)?.current, M = "idle", N = 0, P = null, F = null, I, L = !1, R = !1, z = O ? g.get(O) : void 0, B = z?.() ?? 0;
|
|
163
|
+
function V() {
|
|
164
|
+
if (j) return d("p", j());
|
|
165
|
+
if (_) return d("t", _());
|
|
166
|
+
}
|
|
128
167
|
function H() {
|
|
129
|
-
if (
|
|
130
|
-
if (
|
|
168
|
+
if (j && d("p", j()) !== I) throw new m("principal");
|
|
169
|
+
if (z && z() !== B) throw new m("cleared");
|
|
131
170
|
}
|
|
132
171
|
let U = null, W = null, G = 0;
|
|
133
172
|
function K(e) {
|
|
134
|
-
|
|
173
|
+
M !== e && (M = e, ae?.(e));
|
|
135
174
|
}
|
|
136
175
|
function q(e) {
|
|
137
|
-
|
|
176
|
+
ie?.({
|
|
138
177
|
loaded: e,
|
|
139
178
|
total: r.size,
|
|
140
179
|
fraction: r.size === 0 ? 1 : e / r.size,
|
|
@@ -142,124 +181,139 @@ function D(t) {
|
|
|
142
181
|
});
|
|
143
182
|
}
|
|
144
183
|
function J(e, t) {
|
|
145
|
-
let r = {
|
|
146
|
-
...
|
|
147
|
-
"Tus-Resumable":
|
|
148
|
-
},
|
|
149
|
-
return
|
|
184
|
+
let r = a(e, n, x), i = {
|
|
185
|
+
...r ? h : {},
|
|
186
|
+
"Tus-Resumable": f
|
|
187
|
+
}, s = _?.();
|
|
188
|
+
return s && !("Authorization" in h) && (r ? i.Authorization = `Bearer ${s}` : o(e, n)), Object.assign(i, c({
|
|
150
189
|
method: t,
|
|
151
190
|
url: e,
|
|
152
191
|
reference: n,
|
|
153
|
-
csrf:
|
|
154
|
-
trustedOrigins:
|
|
155
|
-
headers:
|
|
156
|
-
})),
|
|
192
|
+
csrf: T,
|
|
193
|
+
trustedOrigins: x,
|
|
194
|
+
headers: h
|
|
195
|
+
})), i;
|
|
157
196
|
}
|
|
158
197
|
function Y(e) {
|
|
159
198
|
W = e;
|
|
160
199
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
200
|
+
function X(e) {
|
|
201
|
+
return Object.keys(h).length > 0 && a(e, n, x);
|
|
202
|
+
}
|
|
203
|
+
async function Z() {
|
|
204
|
+
O && P && F && (H(), I = V(), await O.set(D, {
|
|
205
|
+
url: P,
|
|
206
|
+
offset: N,
|
|
165
207
|
size: r.size,
|
|
166
|
-
idempotencyKey:
|
|
208
|
+
idempotencyKey: F,
|
|
167
209
|
updatedAt: Date.now(),
|
|
168
|
-
...
|
|
210
|
+
...I === void 0 ? {} : { owner: I }
|
|
169
211
|
}));
|
|
170
212
|
}
|
|
171
|
-
async function
|
|
172
|
-
let n = await
|
|
213
|
+
async function Q(t) {
|
|
214
|
+
let n = await C({
|
|
173
215
|
method: "HEAD",
|
|
174
216
|
url: t,
|
|
175
217
|
headers: J(t, "HEAD"),
|
|
176
|
-
withCredentials:
|
|
177
|
-
register: Y
|
|
218
|
+
withCredentials: w,
|
|
219
|
+
register: Y,
|
|
220
|
+
holdRedirects: X(t)
|
|
178
221
|
});
|
|
179
222
|
if (n.status === 404 || n.status === 410) throw new e({
|
|
180
223
|
status: n.status,
|
|
181
224
|
detail: "O upload expirou no servidor. Comece de novo."
|
|
182
225
|
});
|
|
183
|
-
let r =
|
|
184
|
-
if (r === null) throw
|
|
226
|
+
let r = E(n);
|
|
227
|
+
if (r === null) throw k(n, "HEAD sem Upload-Offset.");
|
|
185
228
|
return r;
|
|
186
229
|
}
|
|
187
|
-
async function
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
230
|
+
async function oe() {
|
|
231
|
+
R && (R = !1, L = !1, P = null, F = null);
|
|
232
|
+
let e = V();
|
|
233
|
+
L && j && e !== I && (F = null);
|
|
234
|
+
let t = L && !j ? P : null;
|
|
235
|
+
I = e, L = !0, B = z?.() ?? 0;
|
|
236
|
+
let i = O ? await O.get(D) : null, a = i !== null && t !== null && i.url === t;
|
|
237
|
+
if (i && I !== void 0 && i.owner !== I && !a && (await O?.delete(D), i = null), i && i.size === r.size && (F = i.idempotencyKey, i.url)) try {
|
|
238
|
+
return N = await Q(i.url), P = i.url, i.url;
|
|
193
239
|
} catch {
|
|
194
|
-
|
|
240
|
+
N = 0;
|
|
195
241
|
}
|
|
196
|
-
K("creating"),
|
|
242
|
+
K("creating"), F ??= ee(), P = null, N = 0, O && await O.set(D, {
|
|
197
243
|
url: "",
|
|
198
244
|
offset: 0,
|
|
199
245
|
size: r.size,
|
|
200
|
-
idempotencyKey:
|
|
246
|
+
idempotencyKey: F,
|
|
201
247
|
updatedAt: Date.now(),
|
|
202
|
-
...
|
|
248
|
+
...I === void 0 ? {} : { owner: I }
|
|
203
249
|
});
|
|
204
|
-
let
|
|
250
|
+
let o = {
|
|
205
251
|
...J(n, "POST"),
|
|
206
252
|
"Upload-Length": String(r.size),
|
|
207
|
-
"Idempotency-Key":
|
|
208
|
-
},
|
|
209
|
-
|
|
210
|
-
let
|
|
253
|
+
"Idempotency-Key": F
|
|
254
|
+
}, c = te(s);
|
|
255
|
+
c && (o["Upload-Metadata"] = c);
|
|
256
|
+
let l = await C({
|
|
211
257
|
method: "POST",
|
|
212
258
|
url: n,
|
|
213
|
-
headers:
|
|
214
|
-
withCredentials:
|
|
215
|
-
register: Y
|
|
259
|
+
headers: o,
|
|
260
|
+
withCredentials: w,
|
|
261
|
+
register: Y,
|
|
262
|
+
holdRedirects: X(n)
|
|
216
263
|
});
|
|
217
|
-
if (
|
|
218
|
-
let
|
|
219
|
-
if (!
|
|
220
|
-
return
|
|
264
|
+
if (l.status !== 201) throw k(l, "Criação do upload recusada.");
|
|
265
|
+
let u = l.header("Location");
|
|
266
|
+
if (!u) throw k(l, "Criação do upload sem cabeçalho Location.");
|
|
267
|
+
return P = re(u, n), await Z(), P;
|
|
221
268
|
}
|
|
222
|
-
async function
|
|
223
|
-
if (H(),
|
|
224
|
-
let
|
|
269
|
+
async function se(t, n) {
|
|
270
|
+
if (H(), n.needed && (N = await Q(t), n.needed = !1, q(N), await Z(), N >= r.size)) return;
|
|
271
|
+
let a = Math.min(N + i, r.size), o = N, s = await C({
|
|
225
272
|
method: "PATCH",
|
|
226
|
-
url:
|
|
273
|
+
url: t,
|
|
227
274
|
headers: {
|
|
228
|
-
...J(
|
|
275
|
+
...J(t, "PATCH"),
|
|
229
276
|
"Content-Type": "application/offset+octet-stream",
|
|
230
|
-
"Upload-Offset": String(
|
|
277
|
+
"Upload-Offset": String(o)
|
|
231
278
|
},
|
|
232
|
-
body: r.slice(
|
|
233
|
-
withCredentials:
|
|
234
|
-
onProgress: (e) => q(Math.min(
|
|
235
|
-
register: Y
|
|
279
|
+
body: r.slice(o, a),
|
|
280
|
+
withCredentials: w,
|
|
281
|
+
onProgress: (e) => q(Math.min(o + e, r.size)),
|
|
282
|
+
register: Y,
|
|
283
|
+
holdRedirects: X(t)
|
|
236
284
|
});
|
|
237
|
-
if (
|
|
238
|
-
if (
|
|
239
|
-
|
|
285
|
+
if (s.status === 409 || s.status === 412) throw n.needed = !0, k(s, "Offset divergente — o servidor já tinha esses bytes.");
|
|
286
|
+
if (s.status !== 204 && s.status !== 200) throw k(s, "Chunk recusado pelo servidor.");
|
|
287
|
+
let c = E(s);
|
|
288
|
+
if (c !== null && c <= o) throw new e({
|
|
289
|
+
status: s.status,
|
|
290
|
+
code: S,
|
|
291
|
+
detail: `O servidor confirmou o chunk sem avançar o Upload-Offset (${o} → ${c}).`
|
|
292
|
+
});
|
|
293
|
+
N = c ?? a, q(N), await Z();
|
|
240
294
|
}
|
|
241
|
-
async function
|
|
295
|
+
async function ce() {
|
|
242
296
|
U = null;
|
|
243
|
-
let e = await
|
|
244
|
-
G =
|
|
297
|
+
let e = await oe();
|
|
298
|
+
G = N, K("uploading"), q(N);
|
|
245
299
|
let t = { needed: !1 };
|
|
246
|
-
for (;
|
|
300
|
+
for (; N < r.size && !U;) await l(() => se(e, t), {
|
|
247
301
|
retries: 5,
|
|
248
|
-
...
|
|
302
|
+
...A,
|
|
249
303
|
shouldRetry: (e, n) => {
|
|
250
|
-
if (U || e instanceof
|
|
251
|
-
let r =
|
|
304
|
+
if (U || e instanceof m || e instanceof DOMException && e.name === "AbortError") return !1;
|
|
305
|
+
let r = A?.shouldRetry?.(e, n) ?? ne(e);
|
|
252
306
|
return r && (t.needed = !0), r;
|
|
253
307
|
}
|
|
254
308
|
});
|
|
255
|
-
return U === "pause" ? (K("paused"), null) : U === "abort" ? (K("aborted"), null) : (K("done"),
|
|
309
|
+
return U === "pause" ? (K("paused"), null) : U === "abort" ? (K("aborted"), null) : (K("done"), O && await O.delete(D), {
|
|
256
310
|
url: e,
|
|
257
311
|
size: r.size
|
|
258
312
|
});
|
|
259
313
|
}
|
|
260
|
-
async function
|
|
314
|
+
async function $() {
|
|
261
315
|
try {
|
|
262
|
-
return await
|
|
316
|
+
return await ce();
|
|
263
317
|
} catch (e) {
|
|
264
318
|
if (U !== null || e instanceof DOMException && e.name === "AbortError") return K(U === "abort" ? "aborted" : "paused"), null;
|
|
265
319
|
throw K("error"), e;
|
|
@@ -267,35 +321,36 @@ function D(t) {
|
|
|
267
321
|
W = null;
|
|
268
322
|
}
|
|
269
323
|
}
|
|
270
|
-
function
|
|
324
|
+
function le(e) {
|
|
271
325
|
U = e, W?.abort(), W = null;
|
|
272
326
|
}
|
|
273
327
|
return {
|
|
274
|
-
start:
|
|
275
|
-
resume:
|
|
276
|
-
pause: () =>
|
|
328
|
+
start: $,
|
|
329
|
+
resume: $,
|
|
330
|
+
pause: () => le("pause"),
|
|
277
331
|
abort: async ({ discard: e = !1 } = {}) => {
|
|
278
|
-
|
|
332
|
+
le("abort"), R = !0, K("aborted"), e && (P && await C({
|
|
279
333
|
method: "DELETE",
|
|
280
|
-
url:
|
|
281
|
-
headers: J(
|
|
282
|
-
withCredentials:
|
|
283
|
-
register: () => void 0
|
|
284
|
-
|
|
334
|
+
url: P,
|
|
335
|
+
headers: J(P, "DELETE"),
|
|
336
|
+
withCredentials: w,
|
|
337
|
+
register: () => void 0,
|
|
338
|
+
holdRedirects: X(P)
|
|
339
|
+
}).catch(() => void 0), O && await O.delete(D));
|
|
285
340
|
},
|
|
286
341
|
get state() {
|
|
287
|
-
return
|
|
342
|
+
return M;
|
|
288
343
|
},
|
|
289
344
|
get offset() {
|
|
290
|
-
return
|
|
345
|
+
return N;
|
|
291
346
|
},
|
|
292
347
|
get url() {
|
|
293
|
-
return
|
|
348
|
+
return P;
|
|
294
349
|
},
|
|
295
|
-
key:
|
|
350
|
+
key: D
|
|
296
351
|
};
|
|
297
352
|
}
|
|
298
353
|
//#endregion
|
|
299
|
-
export {
|
|
354
|
+
export { p as DEFAULT_CHUNK_SIZE, m as ResumableUploadSupersededError, f as TUS_VERSION, b as createLocalUploadStorage, A as createResumableUpload, y as uploadFingerprint };
|
|
300
355
|
|
|
301
356
|
//# sourceMappingURL=resumable-upload.js.map
|