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.
Files changed (247) hide show
  1. package/README.md +40 -10
  2. package/bin/create-tempest-app.e2e.test.mjs +31 -0
  3. package/bin/create-tempest-app.mjs +11 -1
  4. package/bin/lib/component/generate.test.mjs +13 -1
  5. package/bin/lib/doctor/doctor.e2e.test.mjs +29 -0
  6. package/bin/lib/doctor/vitest.mjs +120 -0
  7. package/bin/lib/doctor/vitest.test.mjs +139 -0
  8. package/bin/lib/fs/contain.mjs +7 -0
  9. package/bin/lib/openapi/escape.mjs +68 -4
  10. package/bin/lib/openapi/generate.hostile.test.mjs +150 -1
  11. package/bin/lib/openapi/generate.mjs +78 -13
  12. package/bin/lib/openapi/generate.test.mjs +13 -1
  13. package/bin/lib/openapi/pattern-risk.mjs +134 -0
  14. package/bin/lib/openapi/pattern-risk.test.mjs +45 -0
  15. package/bin/tempest-gen.test.mjs +100 -0
  16. package/bin/tempest.mjs +24 -8
  17. package/dist/access/use-can.cjs +1 -1
  18. package/dist/access/use-can.cjs.map +1 -1
  19. package/dist/access/use-can.js +25 -28
  20. package/dist/access/use-can.js.map +1 -1
  21. package/dist/auth/create-tempest-auth.cjs +1 -1
  22. package/dist/auth/create-tempest-auth.cjs.map +1 -1
  23. package/dist/auth/create-tempest-auth.js +234 -122
  24. package/dist/auth/create-tempest-auth.js.map +1 -1
  25. package/dist/auth/session-identity.cjs +2 -0
  26. package/dist/auth/session-identity.cjs.map +1 -0
  27. package/dist/auth/session-identity.js +12 -0
  28. package/dist/auth/session-identity.js.map +1 -0
  29. package/dist/br/boleto.cjs +1 -1
  30. package/dist/br/boleto.cjs.map +1 -1
  31. package/dist/br/boleto.js +2 -1
  32. package/dist/br/boleto.js.map +1 -1
  33. package/dist/br.d.ts +22 -3
  34. package/dist/components/AuthForm/AuthFieldControl.cjs +2 -0
  35. package/dist/components/AuthForm/AuthFieldControl.cjs.map +1 -0
  36. package/dist/components/AuthForm/AuthFieldControl.js +85 -0
  37. package/dist/components/AuthForm/AuthFieldControl.js.map +1 -0
  38. package/dist/components/AuthForm/AuthForm.cjs +2 -0
  39. package/dist/components/AuthForm/AuthForm.cjs.map +1 -0
  40. package/dist/components/AuthForm/AuthForm.js +83 -0
  41. package/dist/components/AuthForm/AuthForm.js.map +1 -0
  42. package/dist/components/AuthForm/AuthForm.module.cjs +3 -0
  43. package/dist/components/AuthForm/AuthForm.module.cjs.map +1 -0
  44. package/dist/components/AuthForm/AuthForm.module.js +14 -0
  45. package/dist/components/AuthForm/AuthForm.module.js.map +1 -0
  46. package/dist/components/AuthForm/AuthLinks.cjs +2 -0
  47. package/dist/components/AuthForm/AuthLinks.cjs.map +1 -0
  48. package/dist/components/AuthForm/AuthLinks.js +32 -0
  49. package/dist/components/AuthForm/AuthLinks.js.map +1 -0
  50. package/dist/components/AuthForm/ForgotPasswordForm.cjs +2 -0
  51. package/dist/components/AuthForm/ForgotPasswordForm.cjs.map +1 -0
  52. package/dist/components/AuthForm/ForgotPasswordForm.js +32 -0
  53. package/dist/components/AuthForm/ForgotPasswordForm.js.map +1 -0
  54. package/dist/components/AuthForm/LoginForm.cjs +2 -0
  55. package/dist/components/AuthForm/LoginForm.cjs.map +1 -0
  56. package/dist/components/AuthForm/LoginForm.js +39 -0
  57. package/dist/components/AuthForm/LoginForm.js.map +1 -0
  58. package/dist/components/AuthForm/ResetPasswordForm.cjs +2 -0
  59. package/dist/components/AuthForm/ResetPasswordForm.cjs.map +1 -0
  60. package/dist/components/AuthForm/ResetPasswordForm.js +39 -0
  61. package/dist/components/AuthForm/ResetPasswordForm.js.map +1 -0
  62. package/dist/components/AuthForm/SignUpForm.cjs +2 -0
  63. package/dist/components/AuthForm/SignUpForm.cjs.map +1 -0
  64. package/dist/components/AuthForm/SignUpForm.js +32 -0
  65. package/dist/components/AuthForm/SignUpForm.js.map +1 -0
  66. package/dist/components/AuthForm/auth-defaults.cjs +2 -0
  67. package/dist/components/AuthForm/auth-defaults.cjs.map +1 -0
  68. package/dist/components/AuthForm/auth-defaults.js +54 -0
  69. package/dist/components/AuthForm/auth-defaults.js.map +1 -0
  70. package/dist/components/AuthForm/auth-schemas.cjs +2 -0
  71. package/dist/components/AuthForm/auth-schemas.cjs.map +1 -0
  72. package/dist/components/AuthForm/auth-schemas.js +26 -0
  73. package/dist/components/AuthForm/auth-schemas.js.map +1 -0
  74. package/dist/components/AuthPage/AuthPage.cjs +2 -0
  75. package/dist/components/AuthPage/AuthPage.cjs.map +1 -0
  76. package/dist/components/AuthPage/AuthPage.js +97 -0
  77. package/dist/components/AuthPage/AuthPage.js.map +1 -0
  78. package/dist/components/AuthPage/AuthPage.module.cjs +3 -0
  79. package/dist/components/AuthPage/AuthPage.module.cjs.map +1 -0
  80. package/dist/components/AuthPage/AuthPage.module.js +24 -0
  81. package/dist/components/AuthPage/AuthPage.module.js.map +1 -0
  82. package/dist/components/Breadcrumbs/Breadcrumbs.cjs +1 -1
  83. package/dist/components/Breadcrumbs/Breadcrumbs.cjs.map +1 -1
  84. package/dist/components/Breadcrumbs/Breadcrumbs.js +22 -21
  85. package/dist/components/Breadcrumbs/Breadcrumbs.js.map +1 -1
  86. package/dist/components/Button/Button.cjs +1 -1
  87. package/dist/components/Button/Button.cjs.map +1 -1
  88. package/dist/components/Button/Button.js +41 -40
  89. package/dist/components/Button/Button.js.map +1 -1
  90. package/dist/components/Chat/ChatAttachments.cjs +1 -1
  91. package/dist/components/Chat/ChatAttachments.cjs.map +1 -1
  92. package/dist/components/Chat/ChatAttachments.js +38 -38
  93. package/dist/components/FilterBar/filter-apply.cjs +1 -1
  94. package/dist/components/FilterBar/filter-apply.cjs.map +1 -1
  95. package/dist/components/FilterBar/filter-apply.js +7 -7
  96. package/dist/components/Form/Form.cjs +1 -1
  97. package/dist/components/Form/Form.cjs.map +1 -1
  98. package/dist/components/Form/Form.js +30 -32
  99. package/dist/components/Form/Form.js.map +1 -1
  100. package/dist/components/Layout/Layout.cjs +1 -1
  101. package/dist/components/Layout/Layout.cjs.map +1 -1
  102. package/dist/components/Layout/Layout.js +25 -24
  103. package/dist/components/Layout/Layout.js.map +1 -1
  104. package/dist/components/Layout/gap.cjs +2 -0
  105. package/dist/components/Layout/gap.cjs.map +1 -0
  106. package/dist/components/Layout/gap.js +15 -0
  107. package/dist/components/Layout/gap.js.map +1 -0
  108. package/dist/components/NavigationMenu/NavigationMenu.cjs +1 -1
  109. package/dist/components/NavigationMenu/NavigationMenu.cjs.map +1 -1
  110. package/dist/components/NavigationMenu/NavigationMenu.js +71 -70
  111. package/dist/components/NavigationMenu/NavigationMenu.js.map +1 -1
  112. package/dist/components/Sidebar/Sidebar.cjs.map +1 -1
  113. package/dist/components/Sidebar/Sidebar.js.map +1 -1
  114. package/dist/components/Sidebar/SidebarEntry.cjs +1 -1
  115. package/dist/components/Sidebar/SidebarEntry.cjs.map +1 -1
  116. package/dist/components/Sidebar/SidebarEntry.js +30 -29
  117. package/dist/components/Sidebar/SidebarEntry.js.map +1 -1
  118. package/dist/data/create-data-provider.cjs +1 -1
  119. package/dist/data/create-data-provider.cjs.map +1 -1
  120. package/dist/data/create-data-provider.js +1 -2
  121. package/dist/data/create-data-provider.js.map +1 -1
  122. package/dist/forms/index.js +7 -7
  123. package/dist/forms/masked-inputs.cjs +1 -1
  124. package/dist/forms/masked-inputs.cjs.map +1 -1
  125. package/dist/forms/masked-inputs.js +15 -15
  126. package/dist/forms/validate-form.cjs +1 -1
  127. package/dist/forms/validate-form.cjs.map +1 -1
  128. package/dist/forms/validate-form.js +6 -1
  129. package/dist/forms/validate-form.js.map +1 -1
  130. package/dist/forms/zod-resolver.cjs +1 -1
  131. package/dist/forms/zod-resolver.cjs.map +1 -1
  132. package/dist/forms/zod-resolver.js +8 -3
  133. package/dist/forms/zod-resolver.js.map +1 -1
  134. package/dist/http/api-client.cjs +1 -1
  135. package/dist/http/api-client.cjs.map +1 -1
  136. package/dist/http/api-client.js +137 -116
  137. package/dist/http/api-client.js.map +1 -1
  138. package/dist/http/credential-scope.cjs +1 -1
  139. package/dist/http/credential-scope.cjs.map +1 -1
  140. package/dist/http/credential-scope.js +33 -9
  141. package/dist/http/credential-scope.js.map +1 -1
  142. package/dist/http/presigned-post.cjs.map +1 -1
  143. package/dist/http/presigned-post.js.map +1 -1
  144. package/dist/http/resumable-upload.cjs +1 -1
  145. package/dist/http/resumable-upload.cjs.map +1 -1
  146. package/dist/http/resumable-upload.js +140 -134
  147. package/dist/http/resumable-upload.js.map +1 -1
  148. package/dist/http/upload-with-progress.cjs +1 -1
  149. package/dist/http/upload-with-progress.cjs.map +1 -1
  150. package/dist/http/upload-with-progress.js +17 -17
  151. package/dist/http/upload-with-progress.js.map +1 -1
  152. package/dist/http/use-describe-api-error.cjs +1 -1
  153. package/dist/http/use-describe-api-error.cjs.map +1 -1
  154. package/dist/http/use-describe-api-error.js +9 -9
  155. package/dist/oauth/GoogleSignIn.cjs +1 -1
  156. package/dist/oauth/GoogleSignIn.cjs.map +1 -1
  157. package/dist/oauth/GoogleSignIn.js +5 -4
  158. package/dist/oauth/GoogleSignIn.js.map +1 -1
  159. package/dist/offline/create-offline-sync.cjs +1 -1
  160. package/dist/offline/create-offline-sync.cjs.map +1 -1
  161. package/dist/offline/create-offline-sync.js +108 -68
  162. package/dist/offline/create-offline-sync.js.map +1 -1
  163. package/dist/query/offline-persistence.cjs +1 -1
  164. package/dist/query/offline-persistence.cjs.map +1 -1
  165. package/dist/query/offline-persistence.js +54 -44
  166. package/dist/query/offline-persistence.js.map +1 -1
  167. package/dist/sse/create-event-stream.cjs +1 -1
  168. package/dist/sse/create-event-stream.cjs.map +1 -1
  169. package/dist/sse/create-event-stream.js +48 -41
  170. package/dist/sse/create-event-stream.js.map +1 -1
  171. package/dist/sse/ticket-event-stream.cjs +1 -1
  172. package/dist/sse/ticket-event-stream.cjs.map +1 -1
  173. package/dist/sse/ticket-event-stream.js +48 -19
  174. package/dist/sse/ticket-event-stream.js.map +1 -1
  175. package/dist/sse/use-event-stream.cjs +1 -1
  176. package/dist/sse/use-event-stream.cjs.map +1 -1
  177. package/dist/sse/use-event-stream.js +19 -14
  178. package/dist/sse/use-event-stream.js.map +1 -1
  179. package/dist/styles/AuthForm.css +2 -0
  180. package/dist/styles/AuthPage.css +2 -0
  181. package/dist/styles/component/AuthForm.css +9 -0
  182. package/dist/styles/component/AuthPage.css +29 -0
  183. package/dist/styles/forms.css +36 -0
  184. package/dist/styles/manifest.json +63 -0
  185. package/dist/styles.css +1 -1
  186. package/dist/sw/background-sync.cjs +1 -1
  187. package/dist/sw/background-sync.cjs.map +1 -1
  188. package/dist/sw/background-sync.js +132 -112
  189. package/dist/sw/background-sync.js.map +1 -1
  190. package/dist/sw/cache.cjs +1 -1
  191. package/dist/sw/cache.cjs.map +1 -1
  192. package/dist/sw/cache.js +36 -30
  193. package/dist/sw/cache.js.map +1 -1
  194. package/dist/sw/create-push-handler.cjs +1 -1
  195. package/dist/sw/create-push-handler.cjs.map +1 -1
  196. package/dist/sw/create-push-handler.js +20 -10
  197. package/dist/sw/create-push-handler.js.map +1 -1
  198. package/dist/sw.d.ts +93 -28
  199. package/dist/tabular/compact.cjs +1 -1
  200. package/dist/tabular/compact.cjs.map +1 -1
  201. package/dist/tabular/compact.js +35 -16
  202. package/dist/tabular/compact.js.map +1 -1
  203. package/dist/tabular/manifest.cjs +1 -1
  204. package/dist/tabular/manifest.cjs.map +1 -1
  205. package/dist/tabular/manifest.js +33 -15
  206. package/dist/tabular/manifest.js.map +1 -1
  207. package/dist/tabular.d.ts +11 -1
  208. package/dist/tempest-react-sdk.cjs +1 -1
  209. package/dist/tempest-react-sdk.d.ts +1057 -83
  210. package/dist/tempest-react-sdk.js +373 -365
  211. package/dist/theme/initial-theme.cjs +4 -4
  212. package/dist/theme/initial-theme.cjs.map +1 -1
  213. package/dist/theme/initial-theme.js +8 -5
  214. package/dist/theme/initial-theme.js.map +1 -1
  215. package/dist/utils/compressed-storage.cjs +1 -1
  216. package/dist/utils/compressed-storage.cjs.map +1 -1
  217. package/dist/utils/compressed-storage.js +13 -7
  218. package/dist/utils/compressed-storage.js.map +1 -1
  219. package/dist/utils/format.cjs +1 -1
  220. package/dist/utils/format.cjs.map +1 -1
  221. package/dist/utils/format.js +25 -25
  222. package/dist/utils/numbers.cjs +1 -1
  223. package/dist/utils/numbers.cjs.map +1 -1
  224. package/dist/utils/numbers.js +7 -7
  225. package/dist/utils/objects.cjs +1 -1
  226. package/dist/utils/objects.cjs.map +1 -1
  227. package/dist/utils/objects.js +13 -7
  228. package/dist/utils/objects.js.map +1 -1
  229. package/dist/utils/safe-url.cjs +1 -1
  230. package/dist/utils/safe-url.cjs.map +1 -1
  231. package/dist/utils/safe-url.js +4 -1
  232. package/dist/utils/safe-url.js.map +1 -1
  233. package/dist/webrtc/peer-mesh.cjs +1 -1
  234. package/dist/webrtc/peer-mesh.cjs.map +1 -1
  235. package/dist/webrtc/peer-mesh.js +7 -1
  236. package/dist/webrtc/peer-mesh.js.map +1 -1
  237. package/dist/ws/create-web-socket.cjs +1 -1
  238. package/dist/ws/create-web-socket.cjs.map +1 -1
  239. package/dist/ws/create-web-socket.js +77 -61
  240. package/dist/ws/create-web-socket.js.map +1 -1
  241. package/dist/ws/use-web-socket.cjs +1 -1
  242. package/dist/ws/use-web-socket.cjs.map +1 -1
  243. package/dist/ws/use-web-socket.js +4 -3
  244. package/dist/ws/use-web-socket.js.map +1 -1
  245. package/package.json +1 -1
  246. package/template-pwa/src/pwa.tsx +42 -0
  247. package/template-pwa/src/sw.ts +15 -10
@@ -1,18 +1,19 @@
1
- import { bytesToBase64 as e } from "../utils/base64.js";
2
- import { isTrustedCredentialTarget as t, reportSuppressedCredential as n } from "./credential-scope.js";
3
- import { csrfHeaders as r } from "./csrf.js";
4
- import { TempestApiError as i, buildApiError as a, isApiError as o, isRetriableStatus as s } from "./errors.js";
5
- import { retry as c } from "./retry.js";
6
- import { ownerFingerprint as l } from "../utils/owner-fingerprint.js";
1
+ import { TempestApiError as e, buildApiError as t, isApiError as n, isRetriableStatus as r } from "./errors.js";
2
+ import { bytesToBase64 as i } from "../utils/base64.js";
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";
7
8
  import { generateIdempotencyKey as ee } from "./idempotency.js";
8
9
  //#region src/http/resumable-upload.ts
9
- var u = "1.0.0", d = 5242880, f = class extends Error {
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
- }, p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new WeakMap();
15
- function h(e) {
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,19 +22,19 @@ function h(e) {
21
22
  return !1;
22
23
  }
23
24
  }
24
- function g(t) {
25
- return e(new TextEncoder().encode(t));
25
+ function v(e) {
26
+ return i(new TextEncoder().encode(e));
26
27
  }
27
- function _(e) {
28
+ function te(e) {
28
29
  if (!e) return null;
29
- let t = Object.entries(e).map(([e, t]) => `${e} ${g(t)}`);
30
+ let t = Object.entries(e).map(([e, t]) => `${e} ${v(t)}`);
30
31
  return t.length > 0 ? t.join(",") : null;
31
32
  }
32
- function v(e, t) {
33
+ function y(e, t) {
33
34
  let n = t, r = typeof n.name == "string" ? n.name : "blob", i = typeof n.lastModified == "number" ? n.lastModified : 0;
34
35
  return `${e}|${r}|${t.size}|${t.type}|${i}`;
35
36
  }
36
- function y(e = "tempest-upload:") {
37
+ function b(e = "tempest-upload:") {
37
38
  function t() {
38
39
  try {
39
40
  return typeof localStorage > "u" ? null : localStorage;
@@ -58,45 +59,45 @@ function y(e = "tempest-upload:") {
58
59
  t()?.removeItem(e + n);
59
60
  },
60
61
  clear() {
61
- p.set(e, (p.get(e) ?? 0) + 1);
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) && h(n.getItem(i)) && r.push(i);
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 m.set(n, () => p.get(e) ?? 0), n;
73
+ return g.set(n, () => h.get(e) ?? 0), n;
73
74
  }
74
- function b(e) {
75
- return new Promise((t, n) => {
76
- let r = new XMLHttpRequest();
77
- r.open(e.method, e.url), r.withCredentials = e.withCredentials;
78
- for (let [t, n] of Object.entries(e.headers)) r.setRequestHeader(t, n);
79
- if (e.onProgress) {
80
- let t = e.onProgress;
81
- r.upload.onprogress = (e) => t(e.loaded);
75
+ function x(t) {
76
+ return new Promise((n, r) => {
77
+ let i = new XMLHttpRequest();
78
+ i.open(t.method, t.url), i.withCredentials = t.withCredentials;
79
+ for (let [e, n] of Object.entries(t.headers)) i.setRequestHeader(e, n);
80
+ if (t.onProgress) {
81
+ let e = t.onProgress;
82
+ i.upload.onprogress = (t) => e(t.loaded);
82
83
  }
83
- r.onload = () => t({
84
- status: r.status,
85
- text: r.responseText,
86
- header: (e) => r.getResponseHeader(e)
87
- }), r.onerror = () => n(new i({
84
+ i.onload = () => n({
85
+ status: i.status,
86
+ text: i.responseText,
87
+ header: (e) => i.getResponseHeader(e)
88
+ }), i.onerror = () => r(new e({
88
89
  status: 0,
89
90
  detail: "Falha de rede no upload resumível."
90
- })), r.onabort = () => n(new DOMException("Aborted", "AbortError")), e.register(r), r.send(e.body);
91
+ })), i.onabort = () => r(new DOMException("Aborted", "AbortError")), t.register(i), i.send(t.body);
91
92
  });
92
93
  }
93
- function x(e) {
94
+ function S(e) {
94
95
  let t = e.header("Upload-Offset");
95
96
  if (t === null) return null;
96
97
  let n = Number(t);
97
98
  return Number.isFinite(n) && n >= 0 ? n : null;
98
99
  }
99
- function S(e) {
100
+ function C(e) {
100
101
  if (!e) return null;
101
102
  try {
102
103
  return JSON.parse(e);
@@ -104,162 +105,167 @@ function S(e) {
104
105
  return e;
105
106
  }
106
107
  }
107
- var C = /* @__PURE__ */ new Set([409, 412]);
108
- function w(e) {
109
- return !o(e) || C.has(e.status) ? !0 : s(e.status);
108
+ var w = /* @__PURE__ */ new Set([409, 412]);
109
+ function ne(e) {
110
+ return !n(e) || w.has(e.status) ? !0 : r(e.status);
110
111
  }
111
- function T(e, t) {
112
- let n = S(e.text), r = a(e.status, n, { get: e.header }), o = typeof n == "object" && !!n && ("detail" in n || "message" in n);
113
- return new i({
114
- ...r,
115
- detail: o ? r.detail : t
112
+ function T(n, r) {
113
+ let i = C(n.text), a = t(n.status, i, { get: n.header }), o = typeof i == "object" && !!i && ("detail" in i || "message" in i);
114
+ return new e({
115
+ ...a,
116
+ detail: o ? a.detail : r
116
117
  });
117
118
  }
118
- function E(e) {
119
- let t = typeof window > "u" ? void 0 : window.location.href;
119
+ function re(e, t) {
120
120
  try {
121
- return new URL(e, t).href;
121
+ return new URL(e, s(t) ?? void 0).href;
122
122
  } catch {
123
123
  return e;
124
124
  }
125
125
  }
126
- function D(e) {
127
- let { endpoint: a, file: o, chunkSize: s = d, metadata: p, headers: h = {}, getToken: g, getPrincipal: S, trustedOrigins: C, withCredentials: D = !1, csrf: O, key: k = v(a, o), storage: A = y(), retry: j, onProgress: M, onStateChange: N } = e, P = "idle", F = 0, I = null, L = null, R, z = !1, B = A ? m.get(A) : void 0, V = B?.() ?? 0;
126
+ function E(t) {
127
+ let { endpoint: n, file: r, chunkSize: i = p, metadata: s, headers: h = {}, getToken: _, getPrincipal: v, trustedOrigins: C, withCredentials: w = !1, csrf: E, key: D = y(n, r), storage: O = b(), retry: k, onProgress: A, onStateChange: j } = t, M = v ?? u(_)?.current, N = "idle", P = 0, F = null, I = null, L, R = !1, z = O ? g.get(O) : void 0, B = z?.() ?? 0;
128
+ function V() {
129
+ if (M) return d("p", M());
130
+ if (_) return d("t", _());
131
+ }
128
132
  function H() {
129
- if (S && l("p", S()) !== R) throw new f("principal");
130
- if (B && B() !== V) throw new f("cleared");
133
+ if (M && d("p", M()) !== L) throw new m("principal");
134
+ if (z && z() !== B) throw new m("cleared");
131
135
  }
132
136
  let U = null, W = null, G = 0;
133
137
  function K(e) {
134
- P !== e && (P = e, N?.(e));
138
+ N !== e && (N = e, j?.(e));
135
139
  }
136
140
  function q(e) {
137
- M?.({
141
+ A?.({
138
142
  loaded: e,
139
- total: o.size,
140
- fraction: o.size === 0 ? 1 : e / o.size,
143
+ total: r.size,
144
+ fraction: r.size === 0 ? 1 : e / r.size,
141
145
  resumedFrom: G
142
146
  });
143
147
  }
144
- function J(e, i) {
145
- let o = {
146
- ...h,
147
- "Tus-Resumable": u
148
- }, s = g?.();
149
- return s && !("Authorization" in o) && (t(e, a, C) ? o.Authorization = `Bearer ${s}` : n(e, a)), Object.assign(o, r({
150
- method: i,
148
+ function J(e, t) {
149
+ let r = a(e, n, C), i = {
150
+ ...r ? h : {},
151
+ "Tus-Resumable": f
152
+ }, s = _?.();
153
+ return s && !("Authorization" in h) && (r ? i.Authorization = `Bearer ${s}` : o(e, n)), Object.assign(i, c({
154
+ method: t,
151
155
  url: e,
152
- reference: a,
153
- csrf: O,
156
+ reference: n,
157
+ csrf: E,
154
158
  trustedOrigins: C,
155
159
  headers: h
156
- })), o;
160
+ })), i;
157
161
  }
158
162
  function Y(e) {
159
163
  W = e;
160
164
  }
161
165
  async function X() {
162
- A && I && L && (H(), await A.set(k, {
163
- url: I,
164
- offset: F,
165
- size: o.size,
166
- idempotencyKey: L,
166
+ O && F && I && (H(), L = V(), await O.set(D, {
167
+ url: F,
168
+ offset: P,
169
+ size: r.size,
170
+ idempotencyKey: I,
167
171
  updatedAt: Date.now(),
168
- ...R === void 0 ? {} : { owner: R }
172
+ ...L === void 0 ? {} : { owner: L }
169
173
  }));
170
174
  }
171
- async function Z(e) {
172
- let t = await b({
175
+ async function Z(t) {
176
+ let n = await x({
173
177
  method: "HEAD",
174
- url: e,
175
- headers: J(e, "HEAD"),
176
- withCredentials: D,
178
+ url: t,
179
+ headers: J(t, "HEAD"),
180
+ withCredentials: w,
177
181
  register: Y
178
182
  });
179
- if (t.status === 404 || t.status === 410) throw new i({
180
- status: t.status,
183
+ if (n.status === 404 || n.status === 410) throw new e({
184
+ status: n.status,
181
185
  detail: "O upload expirou no servidor. Comece de novo."
182
186
  });
183
- let n = x(t);
184
- if (n === null) throw T(t, "HEAD sem Upload-Offset.");
185
- return n;
187
+ let r = S(n);
188
+ if (r === null) throw T(n, "HEAD sem Upload-Offset.");
189
+ return r;
186
190
  }
187
- async function te() {
188
- let e = S ? l("p", S()) : void 0;
189
- z && e !== R && (L = null), R = e, z = !0, V = B?.() ?? 0;
190
- let t = A ? await A.get(k) : null;
191
- if (t && R !== void 0 && t.owner !== R && (await A?.delete(k), t = null), t && t.size === o.size && (L = t.idempotencyKey, t.url)) try {
192
- return F = await Z(t.url), I = t.url, t.url;
191
+ async function ie() {
192
+ let e = V();
193
+ R && M && e !== L && (I = null);
194
+ let t = R && !M ? F : null;
195
+ L = e, R = !0, B = z?.() ?? 0;
196
+ let i = O ? await O.get(D) : null, a = i !== null && t !== null && i.url === t;
197
+ if (i && L !== void 0 && i.owner !== L && !a && (await O?.delete(D), i = null), i && i.size === r.size && (I = i.idempotencyKey, i.url)) try {
198
+ return P = await Z(i.url), F = i.url, i.url;
193
199
  } catch {
194
- F = 0;
200
+ P = 0;
195
201
  }
196
- K("creating"), L ??= ee(), I = null, F = 0, A && await A.set(k, {
202
+ K("creating"), I ??= ee(), F = null, P = 0, O && await O.set(D, {
197
203
  url: "",
198
204
  offset: 0,
199
- size: o.size,
200
- idempotencyKey: L,
205
+ size: r.size,
206
+ idempotencyKey: I,
201
207
  updatedAt: Date.now(),
202
- ...R === void 0 ? {} : { owner: R }
208
+ ...L === void 0 ? {} : { owner: L }
203
209
  });
204
- let n = {
205
- ...J(a, "POST"),
206
- "Upload-Length": String(o.size),
207
- "Idempotency-Key": L
208
- }, r = _(p);
209
- r && (n["Upload-Metadata"] = r);
210
- let i = await b({
210
+ let o = {
211
+ ...J(n, "POST"),
212
+ "Upload-Length": String(r.size),
213
+ "Idempotency-Key": I
214
+ }, c = te(s);
215
+ c && (o["Upload-Metadata"] = c);
216
+ let l = await x({
211
217
  method: "POST",
212
- url: a,
213
- headers: n,
214
- withCredentials: D,
218
+ url: n,
219
+ headers: o,
220
+ withCredentials: w,
215
221
  register: Y
216
222
  });
217
- if (i.status !== 201) throw T(i, "Criação do upload recusada.");
218
- let s = i.header("Location");
219
- if (!s) throw T(i, "Criação do upload sem cabeçalho Location.");
220
- return I = E(s), await X(), I;
223
+ if (l.status !== 201) throw T(l, "Criação do upload recusada.");
224
+ let u = l.header("Location");
225
+ if (!u) throw T(l, "Criação do upload sem cabeçalho Location.");
226
+ return F = re(u, n), await X(), F;
221
227
  }
222
- async function ne(e, t) {
223
- if (H(), t.needed && (F = await Z(e), t.needed = !1, q(F), await X(), F >= o.size)) return;
224
- let n = Math.min(F + s, o.size), r = F, i = await b({
228
+ async function ae(e, t) {
229
+ if (H(), t.needed && (P = await Z(e), t.needed = !1, q(P), await X(), P >= r.size)) return;
230
+ let n = Math.min(P + i, r.size), a = P, o = await x({
225
231
  method: "PATCH",
226
232
  url: e,
227
233
  headers: {
228
234
  ...J(e, "PATCH"),
229
235
  "Content-Type": "application/offset+octet-stream",
230
- "Upload-Offset": String(r)
236
+ "Upload-Offset": String(a)
231
237
  },
232
- body: o.slice(r, n),
233
- withCredentials: D,
234
- onProgress: (e) => q(Math.min(r + e, o.size)),
238
+ body: r.slice(a, n),
239
+ withCredentials: w,
240
+ onProgress: (e) => q(Math.min(a + e, r.size)),
235
241
  register: Y
236
242
  });
237
- if (i.status === 409 || i.status === 412) throw t.needed = !0, T(i, "Offset divergente — o servidor já tinha esses bytes.");
238
- if (i.status !== 204 && i.status !== 200) throw T(i, "Chunk recusado pelo servidor.");
239
- F = x(i) ?? n, q(F), await X();
243
+ if (o.status === 409 || o.status === 412) throw t.needed = !0, T(o, "Offset divergente — o servidor já tinha esses bytes.");
244
+ if (o.status !== 204 && o.status !== 200) throw T(o, "Chunk recusado pelo servidor.");
245
+ P = S(o) ?? n, q(P), await X();
240
246
  }
241
- async function re() {
247
+ async function oe() {
242
248
  U = null;
243
- let e = await te();
244
- G = F, K("uploading"), q(F);
249
+ let e = await ie();
250
+ G = P, K("uploading"), q(P);
245
251
  let t = { needed: !1 };
246
- for (; F < o.size && !U;) await c(() => ne(e, t), {
252
+ for (; P < r.size && !U;) await l(() => ae(e, t), {
247
253
  retries: 5,
248
- ...j,
254
+ ...k,
249
255
  shouldRetry: (e, n) => {
250
- if (U || e instanceof f || e instanceof DOMException && e.name === "AbortError") return !1;
251
- let r = j?.shouldRetry?.(e, n) ?? w(e);
256
+ if (U || e instanceof m || e instanceof DOMException && e.name === "AbortError") return !1;
257
+ let r = k?.shouldRetry?.(e, n) ?? ne(e);
252
258
  return r && (t.needed = !0), r;
253
259
  }
254
260
  });
255
- return U === "pause" ? (K("paused"), null) : U === "abort" ? (K("aborted"), null) : (K("done"), A && await A.delete(k), {
261
+ return U === "pause" ? (K("paused"), null) : U === "abort" ? (K("aborted"), null) : (K("done"), O && await O.delete(D), {
256
262
  url: e,
257
- size: o.size
263
+ size: r.size
258
264
  });
259
265
  }
260
266
  async function Q() {
261
267
  try {
262
- return await re();
268
+ return await oe();
263
269
  } catch (e) {
264
270
  if (U !== null || e instanceof DOMException && e.name === "AbortError") return K(U === "abort" ? "aborted" : "paused"), null;
265
271
  throw K("error"), e;
@@ -275,27 +281,27 @@ function D(e) {
275
281
  resume: Q,
276
282
  pause: () => $("pause"),
277
283
  abort: async ({ discard: e = !1 } = {}) => {
278
- $("abort"), K("aborted"), e && (I && await b({
284
+ $("abort"), K("aborted"), e && (F && await x({
279
285
  method: "DELETE",
280
- url: I,
281
- headers: J(I, "DELETE"),
282
- withCredentials: D,
286
+ url: F,
287
+ headers: J(F, "DELETE"),
288
+ withCredentials: w,
283
289
  register: () => void 0
284
- }).catch(() => void 0), A && await A.delete(k));
290
+ }).catch(() => void 0), O && await O.delete(D));
285
291
  },
286
292
  get state() {
287
- return P;
293
+ return N;
288
294
  },
289
295
  get offset() {
290
- return F;
296
+ return P;
291
297
  },
292
298
  get url() {
293
- return I;
299
+ return F;
294
300
  },
295
- key: k
301
+ key: D
296
302
  };
297
303
  }
298
304
  //#endregion
299
- export { d as DEFAULT_CHUNK_SIZE, f as ResumableUploadSupersededError, u as TUS_VERSION, y as createLocalUploadStorage, D as createResumableUpload, v as uploadFingerprint };
305
+ export { p as DEFAULT_CHUNK_SIZE, m as ResumableUploadSupersededError, f as TUS_VERSION, b as createLocalUploadStorage, E as createResumableUpload, y as uploadFingerprint };
300
306
 
301
307
  //# sourceMappingURL=resumable-upload.js.map