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,11 +1,12 @@
1
1
  import { isDevBuild as e } from "../utils/dev-mode.js";
2
2
  import { SessionSupersededError as t } from "../http/errors.js";
3
3
  import { createApiClient as n } from "../http/api-client.js";
4
- import { createAuthStore as r } from "./create-auth-store.js";
5
- import { createRefreshQueue as i } from "./refresh-queue.js";
4
+ import { bindSessionIdentity as r } from "./session-identity.js";
5
+ import { createAuthStore as i } from "./create-auth-store.js";
6
+ import { createRefreshQueue as a } from "./refresh-queue.js";
6
7
  //#region src/auth/create-tempest-auth.ts
7
- var a = 1e4;
8
- function o(e, t) {
8
+ var o = 1e4, s = 1e4;
9
+ function c(e, t) {
9
10
  return e.length === 0 ? Promise.resolve() : new Promise((n) => {
10
11
  let r = setTimeout(n, t);
11
12
  Promise.allSettled(e).then(() => {
@@ -13,49 +14,67 @@ function o(e, t) {
13
14
  });
14
15
  });
15
16
  }
16
- function s(e) {
17
+ function ee() {
18
+ let e = globalThis.crypto;
19
+ return typeof e?.randomUUID == "function" ? e.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
20
+ }
21
+ var te = "unlineaged", l = /* @__PURE__ */ new Set();
22
+ function ne(t) {
23
+ e() && !l.has(t) && (l.add(t), console.warn("[tempest-react-sdk] createTempestAuth: withCredentials is set without logoutPath. logout() cannot clear the HttpOnly refresh cookie, so the next refresh() — the boot restore — signs the same account back in. Pass logoutPath (the backend's cookie logout route) so the server revokes it."));
24
+ }
25
+ function re(e) {
17
26
  let t = e ?? {};
18
27
  return {
19
28
  token: t.access_token,
20
29
  refreshToken: t.refresh_token
21
30
  };
22
31
  }
23
- function c(c) {
24
- let { baseURL: l, prefix: u, loginPath: d = "/api/auth/login", refreshPath: ee = "/api/auth/refresh", logoutPath: f, onLogoutError: te, mePath: p, storeName: m = "tempest-auth", storage: h = "local", withCredentials: g = !1, csrf: _, fetcher: v, parseTokens: y = s, parseUser: b, refreshBody: x = (e) => e ? { refresh_token: e } : void 0, retry: ne, redirectTo: S, onSessionEnd: C } = c, w = r({
32
+ function u(l) {
33
+ let { baseURL: u, prefix: d, loginPath: ie = "/api/auth/login", refreshPath: ae = "/api/auth/refresh", logoutPath: f, onLogoutError: oe, mePath: p, storeName: m = "tempest-auth", storage: h = "local", withCredentials: g = !1, csrf: _, fetcher: se, parseTokens: v = re, parseUser: ce, refreshBody: y = (e) => e ? { refresh_token: e } : void 0, retry: le, redirectTo: b, onSessionEnd: x } = l;
34
+ g && !f && ne(m);
35
+ let S = i({
25
36
  name: m,
26
37
  storage: h
27
- }), T = `${m}-refresh`;
28
- function E() {
38
+ }), C = `${m}-refresh`;
39
+ function w() {
29
40
  return typeof window > "u" ? null : h === "session" ? window.sessionStorage : window.localStorage;
30
41
  }
31
- function D() {
32
- return E()?.getItem(T) ?? null;
42
+ function T() {
43
+ return w()?.getItem(C) ?? null;
44
+ }
45
+ let E = T();
46
+ function D(e) {
47
+ E = e;
48
+ let t = w();
49
+ t && (e ? t.setItem(C, e) : t.removeItem(C));
33
50
  }
34
- function O(e) {
35
- let t = E();
36
- t && (e ? t.setItem(T, e) : t.removeItem(T));
51
+ let O = `${m}-lineage`, ue = `tempest-react-sdk:${m}:refresh`, k = w()?.getItem(O) ?? null;
52
+ function A(e) {
53
+ k = e;
54
+ let t = w();
55
+ t && (e ? t.setItem(O, e) : t.removeItem(O));
37
56
  }
38
- let k = () => w.getState(), A = () => k().token;
39
- async function j() {
40
- if (!p) return k().user;
41
- let e = M, n;
57
+ let j = () => S.getState(), M = () => j().token;
58
+ async function de() {
59
+ if (!p) return j().user;
60
+ let e = N, n;
42
61
  try {
43
- n = await $.get(p, { skipAuthRetry: !0 });
62
+ n = await Q.get(p, { skipAuthRetry: !0 });
44
63
  } catch (n) {
45
- throw M === e ? n : new t();
64
+ throw N === e ? n : new t();
46
65
  }
47
- if (M !== e) throw new t();
48
- return k().setUser(n), n;
66
+ if (N !== e || !Z().continues) throw new t();
67
+ return j().setUser(n), n;
49
68
  }
50
- let M = 0, N = Promise.resolve(), P = 0, F = /* @__PURE__ */ new Set(), I = /* @__PURE__ */ new Set(), L = /* @__PURE__ */ new Set(), R = /* @__PURE__ */ new Set();
51
- function z(e) {
69
+ let N = 0, P = Promise.resolve(), F = 0, I = /* @__PURE__ */ new Set(), L = /* @__PURE__ */ new Set(), R = /* @__PURE__ */ new Set(), z = /* @__PURE__ */ new Set();
70
+ function B(e) {
52
71
  let t = e.then(() => void 0, () => void 0);
53
- return L.add(t), t.then(() => L.delete(t)), e;
72
+ return R.add(t), t.then(() => R.delete(t)), e;
54
73
  }
55
- function B(t) {
74
+ function fe(t) {
56
75
  e() && console.warn("[tempest-react-sdk] createTempestAuth: logoutPath revocation failed", t);
57
76
  try {
58
- te?.(t);
77
+ oe?.(t);
59
78
  } catch {
60
79
  return;
61
80
  }
@@ -65,156 +84,249 @@ function c(c) {
65
84
  try {
66
85
  await e();
67
86
  } catch (e) {
68
- B(e);
87
+ fe(e);
69
88
  }
70
89
  })();
71
- return I.add(t), t.then(() => I.delete(t)), t;
90
+ return L.add(t), t.then(() => L.delete(t)), t;
72
91
  }
73
92
  function H(e, t) {
74
- f && !g && t && V(() => U(e).post(f, { body: x(t) }));
93
+ f && !g && t && V(() => U(e).post(f, { body: y(t) }));
75
94
  }
76
95
  function U(e) {
77
96
  return n({
78
- baseURL: l,
79
- prefix: u,
97
+ baseURL: u,
98
+ prefix: d,
80
99
  withCredentials: g,
81
100
  csrf: _,
82
- fetcher: v,
101
+ fetcher: se,
83
102
  getToken: () => e
84
103
  });
85
104
  }
86
105
  function W() {
87
- M += 1, K = i(G);
106
+ N += 1, K = a(G);
88
107
  }
89
108
  async function G() {
90
- let e = M;
91
- R.add(e);
109
+ let e = M(), t = N;
110
+ z.add(t);
92
111
  try {
93
- let n;
94
- try {
95
- n = await z($.post(ee, {
96
- body: x(D()),
97
- skipAuth: !0
98
- }));
99
- } catch (n) {
100
- throw M === e ? n : new t();
101
- }
102
- let { token: r, refreshToken: i } = y(n);
103
- if (M !== e) throw H(r ?? null, i), new t();
104
- k().setToken(r), i && O(i);
112
+ await pe(() => me(e));
105
113
  } finally {
106
- R.delete(e);
114
+ z.delete(t);
107
115
  }
108
116
  }
109
- let K = i(G);
117
+ async function pe(e) {
118
+ let t = h === "local" && typeof navigator < "u" ? navigator.locks : void 0;
119
+ if (!t) return e();
120
+ let n = new AbortController(), r = setTimeout(() => n.abort(), s), i = !1;
121
+ try {
122
+ await t.request(ue, { signal: n.signal }, async () => {
123
+ i = !0, clearTimeout(r), await e();
124
+ });
125
+ } catch (t) {
126
+ if (i) throw t;
127
+ clearTimeout(r), await e();
128
+ }
129
+ }
130
+ async function me(e) {
131
+ let n = e !== null || j().user !== null || E !== null, r = Z();
132
+ if (!n && M() !== null) return;
133
+ if (!r.continues) throw new t();
134
+ if (M() !== e) return;
135
+ let i = N, a;
136
+ try {
137
+ a = await B(Q.post(ae, {
138
+ body: y(T()),
139
+ skipAuth: !0
140
+ }));
141
+ } catch (e) {
142
+ throw N === i ? e : new t();
143
+ }
144
+ let { token: o, refreshToken: s } = v(a);
145
+ if (N !== i || !Z().continues) throw H(o ?? null, s), new t();
146
+ j().setToken(o), s && D(s);
147
+ }
148
+ let K = a(G);
110
149
  function q(e) {
111
- let t = A();
150
+ let t = M();
112
151
  return t === null ? !1 : e.token === null || e.token !== t;
113
152
  }
114
153
  function J() {
115
- return A() === null && D() === null;
154
+ return M() === null && T() === null;
116
155
  }
117
- async function Y() {
118
- if (!(F.size > 0 && P === 0 && (await Promise.allSettled([...F]), A() !== null))) throw Error("anonymous 401 with no session");
156
+ async function he() {
157
+ if (!(I.size > 0 && F === 0 && (await Promise.allSettled([...I]), M() !== null))) throw Error("anonymous 401 with no session");
119
158
  }
120
- async function X(e) {
121
- if (e.epoch !== null && e.epoch !== M) throw new t();
159
+ async function ge(e) {
160
+ if (e.epoch !== null && e.epoch !== N) throw new t();
122
161
  if (q(e)) {
123
162
  if (e.token === null) throw Error("anonymous 401 under a live session");
124
- } else return e.token === null && J() ? R.has(M) ? K() : Y() : K();
163
+ } else return e.token === null && J() ? z.has(N) ? K() : he() : K();
125
164
  }
126
- async function Z(e, n) {
127
- if (n.epoch !== null && n.epoch !== M) throw new t();
128
- q(n) || n.token === null && J() || await se();
165
+ async function _e(e, n) {
166
+ if (n.epoch !== null && n.epoch !== N || !Z().continues) throw new t();
167
+ q(n) || n.token === null && J() || await Ce();
129
168
  }
130
- async function re(e) {
131
- I.size > 0 && await o([...I], a);
132
- let t = ie(e);
133
- F.add(t);
169
+ async function ve(e) {
170
+ L.size > 0 && await c([...L], o);
171
+ let t = ye(e);
172
+ I.add(t);
134
173
  try {
135
174
  return await t;
136
175
  } finally {
137
- F.delete(t);
176
+ I.delete(t);
138
177
  }
139
178
  }
140
- async function ie(e) {
141
- let n = M, r = await z($.post(d, {
179
+ async function ye(e) {
180
+ let n = N, r = await B(Q.post(ie, {
142
181
  body: e,
143
182
  skipAuth: !0
144
- })), { token: i, refreshToken: a } = y(r);
145
- if (M !== n) throw H(i ?? null, a), new t();
146
- let { done: o } = Q("switch"), s = M;
147
- if (await o.catch(() => void 0), M !== s) throw new t();
148
- k().setToken(i), O(a ?? null);
149
- let c = b?.(r);
150
- return c == null ? j() : (k().setUser(c), c);
151
- }
152
- function Q(e) {
153
- let { user: t, token: n } = k(), r = n !== null || t !== null || D() !== null;
154
- if ((r || e !== "expired") && W(), k().logout(), O(null), !r) return {
183
+ })), { token: i, refreshToken: a } = v(r);
184
+ if (N !== n) throw H(i ?? null, a), new t();
185
+ H(M(), T() ?? void 0);
186
+ let { done: o } = Y("switch"), s = N;
187
+ if (await o.catch(() => void 0), N !== s) throw new t();
188
+ A(ee()), j().setToken(i), D(a ?? null);
189
+ let c = ce?.(r);
190
+ return c == null ? de() : (j().setUser(c), c);
191
+ }
192
+ function Y(e) {
193
+ let { user: t, token: n } = j(), r = n !== null || t !== null || T() !== null;
194
+ return (r || e !== "expired") && W(), j().logout(), D(null), A(null), r ? {
155
195
  live: r,
156
- done: e === "switch" || P === 0 ? N : Promise.resolve()
157
- };
158
- if (!C) return {
196
+ done: X({
197
+ reason: e,
198
+ user: t,
199
+ token: n,
200
+ elsewhere: !1
201
+ })
202
+ } : {
159
203
  live: r,
160
- done: Promise.resolve()
204
+ done: e === "switch" || F === 0 ? P : Promise.resolve()
161
205
  };
162
- let i = U(n);
163
- P += 1;
164
- let a = (async () => {
206
+ }
207
+ function X(e) {
208
+ if (!x) return Promise.resolve();
209
+ let t = U(e.token);
210
+ F += 1;
211
+ let n = (async () => {
165
212
  try {
166
- await C({
167
- reason: e,
168
- user: t,
169
- token: n,
170
- api: i
213
+ await x({
214
+ ...e,
215
+ api: t
171
216
  });
172
217
  } finally {
173
- --P;
218
+ --F;
174
219
  }
175
220
  })();
176
- return N = a.then(() => void 0, () => void 0), {
177
- live: r,
178
- done: a.then(() => void 0)
221
+ return P = n.then(() => void 0, () => void 0), n.then(() => void 0);
222
+ }
223
+ function be() {
224
+ let e = w();
225
+ if (!e) return null;
226
+ let t = e.getItem(C), n = e.getItem(O), r = e.getItem(m);
227
+ if (!r) return {
228
+ user: null,
229
+ token: null,
230
+ refreshToken: t,
231
+ lineage: n
232
+ };
233
+ try {
234
+ let e = JSON.parse(r);
235
+ return {
236
+ user: e.state?.user ?? null,
237
+ token: e.state?.token ?? null,
238
+ refreshToken: t,
239
+ lineage: n
240
+ };
241
+ } catch {
242
+ return {
243
+ user: null,
244
+ token: null,
245
+ refreshToken: t,
246
+ lineage: n
247
+ };
248
+ }
249
+ }
250
+ function Z() {
251
+ let e = be(), { user: t, token: n } = j();
252
+ if (e === null) return {
253
+ continues: !0,
254
+ done: Promise.resolve()
255
+ };
256
+ let r = JSON.stringify(e.user) === JSON.stringify(t);
257
+ if (e.token === n && e.refreshToken === E && e.lineage === k && r) return {
258
+ continues: !0,
259
+ done: Promise.resolve()
260
+ };
261
+ let i = e.lineage !== null || k !== null ? e.lineage === k : e.token === n || n !== null && r, a = e.token !== null && i, o = n !== null || t !== null || E !== null;
262
+ if (a || W(), E = e.refreshToken, k = e.lineage, S.setState({
263
+ user: e.user,
264
+ token: e.token,
265
+ isAuthenticated: e.token !== null
266
+ }), a || !o) return {
267
+ continues: a,
268
+ done: Promise.resolve()
269
+ };
270
+ let s = X({
271
+ reason: e.token === null ? "logout" : "switch",
272
+ user: t,
273
+ token: n,
274
+ elsewhere: !0
275
+ });
276
+ return s.catch(() => void 0), {
277
+ continues: a,
278
+ done: s
179
279
  };
180
280
  }
181
- function ae() {
281
+ function xe() {
182
282
  if (!f) return null;
183
- let e = f, { token: t, user: n } = k(), r = D();
283
+ let e = f, { token: t, user: n } = j(), r = T();
184
284
  if (!g && t === null && n === null && r === null) return null;
185
- let i = g ? [...L] : [];
186
- return V(async () => (await o(i, a), U(t).post(e, { body: x(r) })));
285
+ let i = g ? [...R] : [];
286
+ return V(async () => (await c(i, o), U(t).post(e, { body: y(r) })));
187
287
  }
188
- function oe() {
189
- let e = ae(), { done: t } = Q("logout");
190
- return e ? Promise.all([e, t]).then(() => void 0) : t;
288
+ function Se() {
289
+ let e = Z();
290
+ if (!e.continues) return e.done;
291
+ let t = xe(), { done: n } = Y("logout");
292
+ return t ? Promise.all([t, n]).then(() => void 0) : n;
191
293
  }
192
- async function se() {
193
- let { live: e, done: t } = Q("expired");
194
- await t.catch(() => void 0), e && S && typeof window < "u" && window.location.assign(S);
294
+ async function Ce() {
295
+ let { live: e, done: t } = Y("expired");
296
+ await t.catch(() => void 0), e && b && typeof window < "u" && window.location.assign(b);
195
297
  }
196
- let $ = n({
197
- baseURL: l,
198
- prefix: u,
298
+ let Q = n({
299
+ baseURL: u,
300
+ prefix: d,
199
301
  withCredentials: g,
200
302
  csrf: _,
201
- fetcher: v,
202
- getToken: A,
203
- getSessionEpoch: () => M,
204
- refresh: X,
205
- retry: ne,
206
- onUnauthorized: Z
207
- });
208
- return {
209
- useAuthStore: w,
210
- api: $,
211
- login: re,
212
- logout: oe,
213
- refresh: () => K(),
214
- getToken: A
303
+ fetcher: se,
304
+ getToken: M,
305
+ getSessionEpoch: () => N,
306
+ refresh: ge,
307
+ retry: le,
308
+ onUnauthorized: _e
309
+ }), we = () => K(), Te = () => M() === null ? null : k ?? te, Ee = {
310
+ current: Te,
311
+ subscribe: (e) => S.subscribe(e)
312
+ };
313
+ r(Q, Ee), r(M, Ee);
314
+ function De(e) {
315
+ e.storageArea === w() && (e.key === null || e.key === m || e.key === C || e.key === O) && Z();
316
+ }
317
+ let $ = typeof window > "u" ? null : window;
318
+ return $?.addEventListener("storage", De), {
319
+ useAuthStore: S,
320
+ api: Q,
321
+ login: ve,
322
+ logout: Se,
323
+ refresh: we,
324
+ getToken: M,
325
+ sessionKey: Te,
326
+ dispose: () => $?.removeEventListener("storage", De)
215
327
  };
216
328
  }
217
329
  //#endregion
218
- export { c as createTempestAuth };
330
+ export { u as createTempestAuth };
219
331
 
220
332
  //# sourceMappingURL=create-tempest-auth.js.map