@declarion/react 0.154.0 → 0.162.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.
@@ -22,10 +22,11 @@ function r() {
22
22
  return null;
23
23
  }
24
24
  }
25
- function i(e, t) {
26
- return e === null ? "probe-first" : e > t ? "first-wave" : "refresh-first";
25
+ var i = "/login/sso-callback";
26
+ function a(e, t, n = !1) {
27
+ return n ? "first-wave" : e === null ? "probe-first" : e > t ? "first-wave" : "refresh-first";
27
28
  }
28
- function a() {
29
- return i(r(), Date.now());
29
+ function o() {
30
+ return a(r(), Date.now(), window.location.pathname === i);
30
31
  }
31
- export { n as clearAccessExpiry, t as recordAccessExpiry, i as startOrder, a as startOrderNow };
32
+ export { i as SSO_RETURN_PATH, n as clearAccessExpiry, t as recordAccessExpiry, a as startOrder, o as startOrderNow };
@@ -1,76 +1,85 @@
1
1
  import { beginSessionInPage as e, callHandler as t, scheduleProactiveRefresh as n } from "./client.js";
2
2
  // src/api/auth.ts
3
- async function r() {
4
- return t("auth.check_setup");
3
+ var r;
4
+ async function i() {
5
+ await r?.catch(() => void 0);
5
6
  }
6
- async function i(n, r, i = !0) {
7
- let a = await t("auth.login", {
7
+ async function a() {
8
+ return t("auth.check_setup", {}, { credentials: "omit" });
9
+ }
10
+ async function o(n, r, a = !0) {
11
+ await i();
12
+ let o = await t("auth.login", {
8
13
  email: n,
9
14
  password: r,
10
- remember: i
15
+ remember: a
11
16
  });
12
- return e(a.expires_at), a;
17
+ return e(o.expires_at), o;
13
18
  }
14
- async function a(n, r, i) {
15
- let a = await t("auth.signup", {
19
+ async function s(n, r, a) {
20
+ await i();
21
+ let o = await t("auth.signup", {
16
22
  email: n,
17
23
  password: r,
18
- display_name: i
24
+ display_name: a
19
25
  });
20
- return a.verification_required || e(a.expires_at), a;
26
+ return o.verification_required || e(o.expires_at), o;
21
27
  }
22
- async function o(n, r) {
23
- let i = await t("auth.confirm_signup", {
28
+ async function c(n, r) {
29
+ await i();
30
+ let a = await t("auth.confirm_signup", {
24
31
  email: n,
25
32
  code: r
26
33
  });
27
- return e(i.expires_at), i;
34
+ return e(a.expires_at), a;
28
35
  }
29
- async function s(e) {
36
+ async function l(e) {
30
37
  return t("auth.resend_signup_code", { email: e });
31
38
  }
32
- async function c() {
39
+ async function u() {
33
40
  return t("auth.me");
34
41
  }
35
- async function l() {
42
+ async function d() {
36
43
  return t("auth.me", {}, { isSessionProbe: !0 });
37
44
  }
38
- async function u() {
45
+ async function f() {
39
46
  return (await t("auth.list_tenants")).tenants;
40
47
  }
41
- async function d(e) {
48
+ async function p(e) {
42
49
  let r = await t("auth.switch_tenant", { tenant_id: e });
43
50
  return n(r.expires_at), r;
44
51
  }
45
- async function f() {
46
- await t("auth.logout", {}, { keepalive: !0 });
52
+ function m() {
53
+ return r ??= t("auth.logout", {}, { keepalive: !0 }).then(() => void 0).finally(() => {
54
+ r = void 0;
55
+ }), r;
47
56
  }
48
- async function p(e) {
49
- return (await t("auth.list_identity_providers", e ? { tenant_code: e } : {})).providers;
57
+ async function h(e) {
58
+ return (await t("auth.list_identity_providers", e ? { tenant_code: e } : {}, { credentials: "omit" })).providers;
50
59
  }
51
- function m(e, t, n) {
60
+ function g(e, t, n) {
52
61
  let r = new URLSearchParams();
53
62
  t && r.set("tenant", t), n && r.set("redirect", n);
54
63
  let i = r.toString();
55
64
  return `/api/auth/sso/authorize/${encodeURIComponent(e)}${i ? `?${i}` : ""}`;
56
65
  }
57
- async function h(e, n, r) {
66
+ async function _(e, n, r) {
58
67
  let i = {
59
68
  target_user_id: e,
60
69
  reason: n
61
70
  };
62
71
  return r != null && (i.duration_minutes = r), t("impersonation.start", i);
63
72
  }
64
- async function g() {
73
+ async function v() {
65
74
  return t("impersonation.stop");
66
75
  }
67
- async function _(e) {
76
+ async function y(e) {
68
77
  await t("impersonation.revoke", { session_id: e });
69
78
  }
70
- async function v(e, n) {
79
+ async function b(e, n) {
71
80
  await t("auth.change_password", {
72
81
  current_password: e,
73
82
  new_password: n
74
83
  });
75
84
  }
76
- export { v as changePassword, r as checkSetup, o as confirmSignup, c as getMe, _ as impersonationRevoke, h as impersonationStart, g as impersonationStop, p as listIdentityProviders, u as listTenants, i as login, f as logout, l as probeSession, s as resendSignupCode, a as signup, m as ssoAuthorizeUrl, d as switchTenant };
85
+ export { b as changePassword, a as checkSetup, c as confirmSignup, u as getMe, y as impersonationRevoke, _ as impersonationStart, v as impersonationStop, h as listIdentityProviders, f as listTenants, o as login, m as logout, d as probeSession, l as resendSignupCode, s as signup, g as ssoAuthorizeUrl, p as switchTenant, i as waitForLogout };
@@ -31,7 +31,7 @@ function x(e) {
31
31
  async function S() {
32
32
  let e = navigator.locks;
33
33
  if (!e) {
34
- await P();
34
+ await F();
35
35
  return;
36
36
  }
37
37
  let t = Date.now();
@@ -43,7 +43,7 @@ async function S() {
43
43
  } else try {
44
44
  b({
45
45
  ok: !0,
46
- access_expires_at: await P()
46
+ access_expires_at: await F()
47
47
  });
48
48
  } catch (e) {
49
49
  throw e instanceof C && b({
@@ -65,7 +65,7 @@ function T() {
65
65
  }), w;
66
66
  }
67
67
  function E(e) {
68
- return O || (F = null, l() || p(e), typeof window > "u") ? Promise.resolve() : T().then((t) => t.scheduleRenewal(e), () => void 0);
68
+ return O || (I = null, l() || p(e), typeof window > "u") ? Promise.resolve() : T().then((t) => t.scheduleRenewal(e), () => void 0);
69
69
  }
70
70
  function D() {
71
71
  f(), w?.then((e) => e.cancelRenewal());
@@ -74,10 +74,10 @@ var O = !1;
74
74
  function k() {
75
75
  O = !0, D();
76
76
  }
77
- function ee() {
77
+ function A() {
78
78
  return O;
79
79
  }
80
- function A(e) {
80
+ function j(e) {
81
81
  return O = !1, E(e);
82
82
  }
83
83
  typeof window < "u" && window.addEventListener("storage", (e) => {
@@ -85,7 +85,7 @@ typeof window < "u" && window.addEventListener("storage", (e) => {
85
85
  let t = y(() => e.newValue);
86
86
  t?.ok && t.access_expires_at && E(t.access_expires_at);
87
87
  });
88
- async function j(e, n, r) {
88
+ async function M(e, n, r) {
89
89
  let i = new AbortController(), a = setTimeout(() => i.abort(), r);
90
90
  try {
91
91
  return await fetch(e, {
@@ -98,121 +98,121 @@ async function j(e, n, r) {
98
98
  clearTimeout(a);
99
99
  }
100
100
  }
101
- async function M(e) {
101
+ async function N(e) {
102
102
  try {
103
103
  return (await e.json())?.result?.expires_at;
104
104
  } catch {
105
105
  return;
106
106
  }
107
107
  }
108
- function N() {
109
- return j("/api/actions/auth.refresh", {
108
+ function P() {
109
+ return M("/api/actions/auth.refresh", {
110
110
  method: "POST",
111
111
  credentials: "include",
112
112
  headers: { "Content-Type": "application/json" },
113
113
  body: h({})
114
114
  }, u);
115
115
  }
116
- async function P() {
117
- let t = await N();
116
+ async function F() {
117
+ let t = await P();
118
118
  if (t.status === 429) {
119
119
  let e = parseInt(t.headers.get("Retry-After") || "1", 10);
120
- await r(t), await new Promise((t) => setTimeout(t, e * 1e3)), t = await N();
120
+ await r(t), await new Promise((t) => setTimeout(t, e * 1e3)), t = await P();
121
121
  }
122
122
  if (t.status >= 500) {
123
123
  let n = await r(t);
124
124
  throw new e(t.status, n.body, n.raw);
125
125
  }
126
126
  if (!t.ok) throw await r(t), new C(t.status);
127
- let n = await M(t);
127
+ let n = await N(t);
128
128
  return E(n), n;
129
129
  }
130
- var F = null, I = /* @__PURE__ */ new Set(["auth.token_refresh_needed", "auth.unauthorized"]);
131
- function L(n) {
130
+ var I = null, L = /* @__PURE__ */ new Set(["auth.token_refresh_needed", "auth.unauthorized"]);
131
+ function R(n) {
132
132
  return n instanceof t || n instanceof e;
133
133
  }
134
- async function R() {
134
+ async function z() {
135
135
  if (O) throw new C(401);
136
- if (F !== null) throw new C(F);
136
+ if (I !== null) throw new C(I);
137
137
  return g || (g = S().catch((e) => {
138
- throw e instanceof C && (F = e.status), e;
138
+ throw e instanceof C && (I = e.status), e;
139
139
  }).finally(() => {
140
140
  g = null;
141
141
  }), g);
142
142
  }
143
- var z = () => {
143
+ var B = () => {
144
144
  if (typeof window > "u") return;
145
145
  let { pathname: e } = window.location;
146
146
  e.startsWith("/login") || e.startsWith("/signup") || e === "/reset" || e === "/forgot" || e === "/2fa" || (window.location.href = i());
147
147
  };
148
- function B(e) {
149
- let t = z;
150
- return z = e, t;
148
+ function V(e) {
149
+ let t = B;
150
+ return B = e, t;
151
151
  }
152
- function V() {
153
- return z;
152
+ function H() {
153
+ return B;
154
154
  }
155
- var H = ({ status: e, code: t, message: n }) => {
155
+ var U = ({ status: e, code: t, message: n }) => {
156
156
  console.error(`[API ${e}] ${t}: ${n}`);
157
157
  };
158
- function U(e, t, n, r) {
158
+ function W(e, t, n, r) {
159
159
  let i = new Headers(e);
160
160
  return !i.has("Content-Type") && t && i.set("Content-Type", "application/json"), n.setAccept && !i.has("Accept") && i.set("Accept", "*/*"), r && i.set("Authorization", `Bearer ${r}`), i;
161
161
  }
162
- var W = null, G;
163
- function K(e) {
164
- G = e, W && e !== void 0 && !m(W.reader, e) && (W = null);
162
+ var G = null, K;
163
+ function q(e) {
164
+ K = e, G && e !== void 0 && !m(G.reader, e) && (G = null);
165
165
  }
166
- function q(e, t) {
167
- (G === void 0 || m(e, G)) && (W = t ? {
166
+ function J(e, t) {
167
+ (K === void 0 || m(e, K)) && (G = t ? {
168
168
  language: t,
169
169
  reader: e
170
170
  } : null);
171
171
  }
172
- function J(e) {
173
- W = e ? {
172
+ function ee(e) {
173
+ G = e ? {
174
174
  language: e,
175
- reader: G ?? null
175
+ reader: K ?? null
176
176
  } : null;
177
177
  }
178
178
  function Y() {
179
- return W?.language ?? null;
179
+ return G?.language ?? null;
180
180
  }
181
181
  function X(e) {
182
182
  let t = Y();
183
183
  return !t || !e.startsWith("/api/") || /[?&]language=/.test(e) ? e : `${e}${e.includes("?") ? "&" : "?"}language=${encodeURIComponent(t)}`;
184
184
  }
185
185
  async function Z(t, i, u, f) {
186
- let p = X(t), m = l(), h = m ? "omit" : "include", g = U(i.headers, !!i.body, u, m ? c() : null), _ = d(t, i), v = await j(p, {
186
+ let p = X(t), m = l(), h = m ? "omit" : i.credentials ?? "include", g = m || h !== "omit", _ = W(i.headers, !!i.body, u, m ? c() : null), v = d(t, i), y = await M(p, {
187
187
  ...i,
188
- headers: g,
188
+ headers: _,
189
189
  credentials: h
190
- }, _);
191
- if (a(v.headers), !v.ok) {
192
- let { raw: t, body: a } = await r(v), c = n(a.type), l = a.title ?? "";
193
- if (v.status === 401 && I.has(c)) try {
190
+ }, v);
191
+ if (a(y.headers), !y.ok) {
192
+ let { raw: t, body: a } = await r(y), c = n(a.type), l = a.title ?? "";
193
+ if (g && y.status === 401 && L.has(c)) try {
194
194
  let t = null;
195
- m ? (s(), t = await o()) : await R();
196
- let a = U(i.headers, !!i.body, u, t), c = await j(p, {
195
+ m ? (s(), t = await o()) : await z();
196
+ let a = W(i.headers, !!i.body, u, t), c = await M(p, {
197
197
  ...i,
198
198
  headers: a,
199
199
  credentials: h
200
- }, _);
200
+ }, v);
201
201
  if (!c.ok) {
202
202
  let t = await r(c);
203
- throw !m && c.status === 401 && I.has(n(t.body.type)) && (F = 401), c.status === 401 && !u.isSessionProbe && z(), new e(c.status, t.body, t.raw);
203
+ throw !m && c.status === 401 && L.has(n(t.body.type)) && (I = 401), c.status === 401 && !u.isSessionProbe && B(), new e(c.status, t.body, t.raw);
204
204
  }
205
205
  return f(c);
206
206
  } catch (n) {
207
- throw L(n) ? n : (u.isSessionProbe || z(), new e(401, a, t));
207
+ throw R(n) ? n : (u.isSessionProbe || B(), new e(401, a, t));
208
208
  }
209
- throw v.status === 401 && !u.isSessionProbe && z(), H({
210
- status: v.status,
209
+ throw g && y.status === 401 && !u.isSessionProbe && B(), U({
210
+ status: y.status,
211
211
  code: c,
212
212
  message: l
213
- }), new e(v.status, a, t);
213
+ }), new e(y.status, a, t);
214
214
  }
215
- return f(v);
215
+ return f(y);
216
216
  }
217
217
  function Q(e) {
218
218
  return e.status === 204 ? Promise.resolve(void 0) : e.json();
@@ -246,14 +246,15 @@ function $(e) {
246
246
  let r = t.match(/filename\s*=\s*("([^"]+)"|([^;]+))/i);
247
247
  return r ? (r[2] ?? r[3] ?? "").trim() : "";
248
248
  }
249
- async function ie(e, t = {}, { isSessionProbe: n = !1, keepalive: r = !1 } = {}) {
249
+ async function ie(e, t = {}, { isSessionProbe: n = !1, keepalive: r = !1, credentials: i } = {}) {
250
250
  return (await Z(`/api/actions/${encodeURIComponent(e)}`, {
251
251
  method: "POST",
252
252
  body: h(t),
253
- keepalive: r
253
+ keepalive: r,
254
+ credentials: i
254
255
  }, {
255
256
  setAccept: !1,
256
257
  isSessionProbe: n
257
258
  }, Q)).result;
258
259
  }
259
- export { C as RefreshDeadError, te as apiFetch, re as apiFetchBlob, A as beginSessionInPage, ie as callHandler, D as cancelProactiveRefresh, Y as currentPublishedLanguage, k as endSessionInPage, R as ensureRefresh, V as getPersistentAuthFailureHandler, ee as isSignedOutInPage, L as isTransientFailure, $ as parseContentDispositionFilename, J as publishLanguage, q as publishLanguageFor, E as scheduleProactiveRefresh, K as setLanguageReader, B as setPersistentAuthFailureHandler, X as withPublishedLanguage };
260
+ export { C as RefreshDeadError, te as apiFetch, re as apiFetchBlob, j as beginSessionInPage, ie as callHandler, D as cancelProactiveRefresh, Y as currentPublishedLanguage, k as endSessionInPage, z as ensureRefresh, H as getPersistentAuthFailureHandler, A as isSignedOutInPage, R as isTransientFailure, $ as parseContentDispositionFilename, ee as publishLanguage, J as publishLanguageFor, E as scheduleProactiveRefresh, q as setLanguageReader, V as setPersistentAuthFailureHandler, X as withPublishedLanguage };
@@ -0,0 +1,12 @@
1
+ import { callHandler as e } from "./client.js";
2
+ // src/api/oauth.ts
3
+ async function t(t) {
4
+ return e("oauth.authorization_continue", { transaction_id: t });
5
+ }
6
+ async function n(t, n) {
7
+ return e("oauth.authorization_decide", {
8
+ transaction_id: t,
9
+ decision: n
10
+ });
11
+ }
12
+ export { t as continueAuthorization, n as decideAuthorization };
@@ -1,70 +1,73 @@
1
- import { apiFetch as e, publishLanguageFor as t } from "./client.js";
2
- import { recordActionTimeouts as n } from "./request-bounds.js";
3
- import { OrderedMap as r } from "../types/ordmap.js";
1
+ import { apiFetch as e, isSignedOutInPage as t, publishLanguageFor as n } from "./client.js";
2
+ import { recordActionTimeouts as r } from "./request-bounds.js";
3
+ import { OrderedMap as i } from "../types/ordmap.js";
4
4
  // src/api/schema.ts
5
- function i(e) {
5
+ function a(e) {
6
6
  return {
7
7
  ...e,
8
- params: e.params ? r.fromWire(e.params) : void 0
8
+ params: e.params ? i.fromWire(e.params) : void 0
9
9
  };
10
10
  }
11
- function a(e) {
11
+ function o(e) {
12
12
  return {
13
13
  ...e,
14
- resolved_params: e.resolved_params ? r.fromWire(e.resolved_params) : void 0
14
+ resolved_params: e.resolved_params ? i.fromWire(e.resolved_params) : void 0
15
15
  };
16
16
  }
17
- function o(e) {
17
+ function s(e) {
18
18
  let t = {};
19
- if (e.handlers) for (let [n, r] of Object.entries(e.handlers)) t[n] = i(r);
19
+ if (e.handlers) for (let [n, r] of Object.entries(e.handlers)) t[n] = a(r);
20
20
  let n = {};
21
- if (e.actions) for (let [t, r] of Object.entries(e.actions)) n[t] = a(r);
21
+ if (e.actions) for (let [t, r] of Object.entries(e.actions)) n[t] = o(r);
22
22
  return {
23
23
  ...e,
24
- fields: r.fromWire(e.fields),
25
- files: e.files ? r.fromWire(e.files) : void 0,
26
- variants: e.variants ? r.fromWire(e.variants) : void 0,
24
+ fields: i.fromWire(e.fields),
25
+ files: e.files ? i.fromWire(e.files) : void 0,
26
+ variants: e.variants ? i.fromWire(e.variants) : void 0,
27
27
  handlers: e.handlers ? t : void 0,
28
28
  actions: e.actions ? n : void 0
29
29
  };
30
30
  }
31
- function s(e) {
31
+ function c(e) {
32
32
  let t = {};
33
- if (e.entities) for (let [n, r] of Object.entries(e.entities)) t[n] = o(r);
33
+ if (e.entities) for (let [n, r] of Object.entries(e.entities)) t[n] = s(r);
34
34
  let n = {};
35
- if (e.structures) for (let [t, i] of Object.entries(e.structures)) n[t] = {
36
- ...i,
37
- fields: r.fromWire(i.fields)
35
+ if (e.structures) for (let [t, r] of Object.entries(e.structures)) n[t] = {
36
+ ...r,
37
+ fields: i.fromWire(r.fields)
38
38
  };
39
- let s = {};
40
- if (e.handlers) for (let [t, n] of Object.entries(e.handlers)) s[t] = i(n);
39
+ let r = {};
40
+ if (e.handlers) for (let [t, n] of Object.entries(e.handlers)) r[t] = a(n);
41
41
  let c = {};
42
- if (e.actions) for (let [t, n] of Object.entries(e.actions)) c[t] = a(n);
42
+ if (e.actions) for (let [t, n] of Object.entries(e.actions)) c[t] = o(n);
43
43
  let l = { ...e.screens };
44
44
  for (let [e, t] of Object.entries(l)) {
45
45
  let n = t;
46
46
  l[e] = {
47
47
  ...t,
48
- variants: n.variants ? r.fromWire(n.variants) : void 0
48
+ variants: n.variants ? i.fromWire(n.variants) : void 0
49
49
  };
50
50
  }
51
51
  return {
52
52
  ...e,
53
53
  entities: t,
54
54
  structures: n,
55
- handlers: s,
55
+ handlers: r,
56
56
  actions: c,
57
57
  screens: l
58
58
  };
59
59
  }
60
- async function c() {
61
- let r = performance.now(), { audience: i, ...a } = await e("/api/schema", { cache: "no-cache" });
62
- if (i === void 0) throw Error("/api/schema answered without its audience");
63
- let o = s(a);
64
- return t(i, o.language), n(o), {
65
- schema: o,
66
- audience: i,
67
- requestedAt: r
60
+ async function l() {
61
+ let i = performance.now(), { audience: a, ...o } = await e("/api/schema", {
62
+ cache: "no-cache",
63
+ credentials: t() ? "omit" : void 0
64
+ });
65
+ if (a === void 0) throw Error("/api/schema answered without its audience");
66
+ let s = c(o);
67
+ return n(a, s.language), r(s), {
68
+ schema: s,
69
+ audience: a,
70
+ requestedAt: i
68
71
  };
69
72
  }
70
- export { c as fetchSchema };
73
+ export { l as fetchSchema };