@declarion/react 0.177.0 → 0.182.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.
@@ -14,7 +14,29 @@ function n() {
14
14
  return;
15
15
  }
16
16
  }
17
- function r() {
17
+ var r = "declarion.auth.signed_out";
18
+ function i() {
19
+ try {
20
+ window.localStorage.setItem(r, "1");
21
+ } catch {
22
+ return;
23
+ }
24
+ }
25
+ function a() {
26
+ try {
27
+ window.localStorage.removeItem(r);
28
+ } catch {
29
+ return;
30
+ }
31
+ }
32
+ function o() {
33
+ try {
34
+ return window.localStorage.getItem(r) === "1";
35
+ } catch {
36
+ return !1;
37
+ }
38
+ }
39
+ function s() {
18
40
  try {
19
41
  let t = Date.parse(window.localStorage.getItem(e) ?? "");
20
42
  return Number.isNaN(t) ? null : t;
@@ -22,11 +44,11 @@ function r() {
22
44
  return null;
23
45
  }
24
46
  }
25
- var i = "/login/sso-callback";
26
- function a(e, t, n = !1) {
47
+ var c = "/login/sso-callback";
48
+ function l(e, t, n = !1) {
27
49
  return n ? "first-wave" : e === null ? "probe-first" : e > t ? "first-wave" : "refresh-first";
28
50
  }
29
- function o() {
30
- return a(r(), Date.now(), window.location.pathname === i);
51
+ function u() {
52
+ return l(s(), Date.now(), window.location.pathname === c);
31
53
  }
32
- export { i as SSO_RETURN_PATH, n as clearAccessExpiry, t as recordAccessExpiry, a as startOrder, o as startOrderNow };
54
+ export { c as SSO_RETURN_PATH, n as clearAccessExpiry, a as clearSignOut, t as recordAccessExpiry, i as recordSignOut, o as signedOutExplicitly, l as startOrder, u as startOrderNow };
@@ -82,14 +82,25 @@ async function p(e) {
82
82
  });
83
83
  }
84
84
  async function m(e) {
85
- return h("agent_message", {
86
- filters: [{
87
- field: "conversation_id",
88
- op: "eq",
89
- value: e
90
- }],
91
- sort: "seq:asc"
92
- });
85
+ let n = [];
86
+ for (let r = 1;; r += 1) {
87
+ let i = await t("agent_message", {
88
+ filters: [{
89
+ field: "conversation_id",
90
+ op: "eq",
91
+ value: e
92
+ }],
93
+ sort: "seq:asc",
94
+ page: r,
95
+ per_page: 1e3
96
+ }), a = i.data ?? [];
97
+ if (n.push(...a.map((e) => ({
98
+ ...e,
99
+ bot: e.bot_id ? i.$refs?.agent_bot?.[e.bot_id]?.display_name : void 0,
100
+ sender_user: e.sender_user_id ? i.$refs?.user?.[e.sender_user_id]?.display_name : void 0
101
+ }))), i.meta?.has_more !== !0) return n;
102
+ if (a.length === 0) throw Error("agent_message pagination did not advance");
103
+ }
93
104
  }
94
105
  async function h(e, n) {
95
106
  let r = [];
@@ -1,6 +1,6 @@
1
1
  // src/api/audience.ts
2
2
  function e(e) {
3
- if (!e.isLoading) return !e.isAuthenticated || !e.user ? null : {
3
+ if (!e.isLoading || e.signedOutPresumed) return !e.isAuthenticated || !e.user ? null : {
4
4
  user_id: e.user.id,
5
5
  tenant_id: e.activeTenant?.id ?? ""
6
6
  };
@@ -1,85 +1,86 @@
1
- import { beginSessionInPage as e, callHandler as t, scheduleProactiveRefresh as n } from "./client.js";
1
+ import { recordSignOut as e, signedOutExplicitly as t } from "./access-expiry.js";
2
+ import { beginSessionInPage as n, callHandler as r, scheduleProactiveRefresh as i } from "./client.js";
2
3
  // src/api/auth.ts
3
- var r;
4
- async function i() {
5
- await r?.catch(() => void 0);
6
- }
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", {
13
- email: n,
14
- password: r,
15
- remember: a
4
+ var a;
5
+ async function o() {
6
+ await a?.catch(() => void 0);
7
+ }
8
+ async function s() {
9
+ return r("auth.check_setup", {}, { credentials: "omit" });
10
+ }
11
+ async function c(e, t, i = !0) {
12
+ await o();
13
+ let a = await r("auth.login", {
14
+ email: e,
15
+ password: t,
16
+ remember: i
16
17
  });
17
- return e(o.expires_at), o;
18
- }
19
- async function s(n, r, a) {
20
- await i();
21
- let o = await t("auth.signup", {
22
- email: n,
23
- password: r,
24
- display_name: a
18
+ return n(a.expires_at), a;
19
+ }
20
+ async function l(e, t, i) {
21
+ await o();
22
+ let a = await r("auth.signup", {
23
+ email: e,
24
+ password: t,
25
+ display_name: i
25
26
  });
26
- return o.verification_required || e(o.expires_at), o;
27
+ return a.verification_required || n(a.expires_at), a;
27
28
  }
28
- async function c(n, r) {
29
- await i();
30
- let a = await t("auth.confirm_signup", {
31
- email: n,
32
- code: r
29
+ async function u(e, t) {
30
+ await o();
31
+ let i = await r("auth.confirm_signup", {
32
+ email: e,
33
+ code: t
33
34
  });
34
- return e(a.expires_at), a;
35
+ return n(i.expires_at), i;
35
36
  }
36
- async function l(e) {
37
- return t("auth.resend_signup_code", { email: e });
38
- }
39
- async function u() {
40
- return t("auth.me");
41
- }
42
- async function d() {
43
- return t("auth.me", {}, { isSessionProbe: !0 });
37
+ async function d(e) {
38
+ return r("auth.resend_signup_code", { email: e });
44
39
  }
45
40
  async function f() {
46
- return (await t("auth.list_tenants")).tenants;
41
+ return r("auth.me");
47
42
  }
48
- async function p(e) {
49
- let r = await t("auth.switch_tenant", { tenant_id: e });
50
- return n(r.expires_at), r;
43
+ async function p() {
44
+ return r("auth.me", {}, { isSessionProbe: !0 });
51
45
  }
52
- function m() {
53
- return r ??= t("auth.logout", {}, { keepalive: !0 }).then(() => void 0).finally(() => {
54
- r = void 0;
55
- }), r;
46
+ async function m() {
47
+ return (await r("auth.list_tenants")).tenants;
56
48
  }
57
49
  async function h(e) {
58
- return (await t("auth.list_identity_providers", e ? { tenant_code: e } : {}, { credentials: "omit" })).providers;
50
+ let t = await r("auth.switch_tenant", { tenant_id: e });
51
+ return i(t.expires_at), t;
52
+ }
53
+ function g() {
54
+ return e(), a ??= r("auth.logout", {}, { keepalive: !0 }).then(() => void 0).finally(() => {
55
+ a = void 0;
56
+ }), a;
57
+ }
58
+ async function _(e) {
59
+ return (await r("auth.list_identity_providers", e ? { tenant_code: e } : {}, { credentials: "omit" })).providers;
59
60
  }
60
- function g(e, t, n) {
61
- let r = new URLSearchParams();
62
- t && r.set("tenant", t), n && r.set("redirect", n);
63
- let i = r.toString();
64
- return `/api/auth/sso/authorize/${encodeURIComponent(e)}${i ? `?${i}` : ""}`;
61
+ function v(e, n, r) {
62
+ let i = new URLSearchParams();
63
+ n && i.set("tenant", n), r && i.set("redirect", r), t() && i.set("after_sign_out", "1");
64
+ let a = i.toString();
65
+ return `/api/auth/sso/authorize/${encodeURIComponent(e)}${a ? `?${a}` : ""}`;
65
66
  }
66
- async function _(e, n, r) {
67
+ async function y(e, t, n) {
67
68
  let i = {
68
69
  target_user_id: e,
69
- reason: n
70
+ reason: t
70
71
  };
71
- return r != null && (i.duration_minutes = r), t("impersonation.start", i);
72
+ return n != null && (i.duration_minutes = n), r("impersonation.start", i);
72
73
  }
73
- async function v() {
74
- return t("impersonation.stop");
74
+ async function b() {
75
+ return r("impersonation.stop");
75
76
  }
76
- async function y(e) {
77
- await t("impersonation.revoke", { session_id: e });
77
+ async function x(e) {
78
+ await r("impersonation.revoke", { session_id: e });
78
79
  }
79
- async function b(e, n) {
80
- await t("auth.change_password", {
80
+ async function S(e, t) {
81
+ await r("auth.change_password", {
81
82
  current_password: e,
82
- new_password: n
83
+ new_password: t
83
84
  });
84
85
  }
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 };
86
+ export { S as changePassword, s as checkSetup, u as confirmSignup, f as getMe, x as impersonationRevoke, y as impersonationStart, b as impersonationStop, _ as listIdentityProviders, m as listTenants, c as login, g as logout, p as probeSession, d as resendSignupCode, l as signup, v as ssoAuthorizeUrl, h as switchTenant, o 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 F();
34
+ await P();
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 F()
46
+ access_expires_at: await P()
47
47
  });
48
48
  } catch (e) {
49
49
  throw e instanceof C && b({
@@ -65,27 +65,27 @@ function T() {
65
65
  }), w;
66
66
  }
67
67
  function E(e) {
68
- return O || (I = null, l() || p(e), typeof window > "u") ? Promise.resolve() : T().then((t) => t.scheduleRenewal(e), () => void 0);
68
+ return O || (F = 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());
72
72
  }
73
73
  var O = !1;
74
- function k() {
74
+ function ee() {
75
75
  O = !0, D();
76
76
  }
77
- function A() {
77
+ function k() {
78
78
  return O;
79
79
  }
80
- function j(e) {
81
- return O = !1, E(e);
80
+ function A(e) {
81
+ return O = !1, I += 1, E(e);
82
82
  }
83
83
  typeof window < "u" && window.addEventListener("storage", (e) => {
84
84
  if (e.key !== _ || l()) return;
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 M(e, n, r) {
88
+ async function j(e, n, r) {
89
89
  let i = new AbortController(), a = setTimeout(() => i.abort(), r);
90
90
  try {
91
91
  return await fetch(e, {
@@ -98,47 +98,49 @@ async function M(e, n, r) {
98
98
  clearTimeout(a);
99
99
  }
100
100
  }
101
- async function N(e) {
101
+ async function M(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 P() {
109
- return M("/api/actions/auth.refresh", {
108
+ function N() {
109
+ return j("/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 F() {
117
- let t = await P();
116
+ async function P() {
117
+ let t = await N();
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 P();
120
+ await r(t), await new Promise((t) => setTimeout(t, e * 1e3)), t = await N();
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 N(t);
127
+ let n = await M(t);
128
128
  return E(n), n;
129
129
  }
130
- var I = null, L = /* @__PURE__ */ new Set(["auth.token_refresh_needed", "auth.unauthorized"]);
130
+ var F = null, I = 0, L = /* @__PURE__ */ new Set(["auth.token_refresh_needed", "auth.unauthorized"]);
131
131
  function R(n) {
132
132
  return n instanceof t || n instanceof e;
133
133
  }
134
134
  async function z() {
135
135
  if (O) throw new C(401);
136
- if (I !== null) throw new C(I);
137
- return g || (g = S().catch((e) => {
138
- throw e instanceof C && (I = e.status), e;
136
+ if (F !== null) throw new C(F);
137
+ if (g) return g;
138
+ let e = I;
139
+ return g = S().catch((t) => {
140
+ throw t instanceof C && e === I && (F = t.status), t;
139
141
  }).finally(() => {
140
142
  g = null;
141
- }), g);
143
+ }), g;
142
144
  }
143
145
  var B = () => {
144
146
  if (typeof window > "u") return;
@@ -169,7 +171,7 @@ function J(e, t) {
169
171
  reader: e
170
172
  } : null);
171
173
  }
172
- function ee(e) {
174
+ function te(e) {
173
175
  G = e ? {
174
176
  language: e,
175
177
  reader: K ?? null
@@ -183,58 +185,58 @@ function X(e) {
183
185
  return !t || !e.startsWith("/api/") || /[?&]language=/.test(e) ? e : `${e}${e.includes("?") ? "&" : "?"}language=${encodeURIComponent(t)}`;
184
186
  }
185
187
  async function Z(t, i, u, f) {
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, {
188
+ 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 = I, b = await j(p, {
187
189
  ...i,
188
190
  headers: _,
189
191
  credentials: h
190
192
  }, 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 {
193
+ if (a(b.headers), !b.ok) {
194
+ let { raw: t, body: a } = await r(b), c = n(a.type), l = a.title ?? "";
195
+ if (g && b.status === 401 && L.has(c)) try {
194
196
  let t = null;
195
197
  m ? (s(), t = await o()) : await z();
196
- let a = W(i.headers, !!i.body, u, t), c = await M(p, {
198
+ let a = W(i.headers, !!i.body, u, t), c = await j(p, {
197
199
  ...i,
198
200
  headers: a,
199
201
  credentials: h
200
202
  }, v);
201
203
  if (!c.ok) {
202
204
  let t = await r(c);
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);
205
+ throw !m && y === I && c.status === 401 && L.has(n(t.body.type)) && (F = 401), c.status === 401 && !u.isSessionProbe && B(), new e(c.status, t.body, t.raw);
204
206
  }
205
207
  return f(c);
206
208
  } catch (n) {
207
209
  throw R(n) ? n : (u.isSessionProbe || B(), new e(401, a, t));
208
210
  }
209
- throw g && y.status === 401 && !u.isSessionProbe && B(), U({
210
- status: y.status,
211
+ throw g && b.status === 401 && !u.isSessionProbe && B(), U({
212
+ status: b.status,
211
213
  code: c,
212
214
  message: l
213
- }), new e(y.status, a, t);
215
+ }), new e(b.status, a, t);
214
216
  }
215
- return f(y);
217
+ return f(b);
216
218
  }
217
219
  function Q(e) {
218
220
  return e.status === 204 ? Promise.resolve(void 0) : e.json();
219
221
  }
220
- async function te(e, t = {}, { isSessionProbe: n = !1 } = {}) {
222
+ async function ne(e, t = {}, { isSessionProbe: n = !1 } = {}) {
221
223
  return Z(e, t, {
222
224
  setAccept: !1,
223
225
  isSessionProbe: n
224
226
  }, Q);
225
227
  }
226
- async function ne(e) {
228
+ async function re(e) {
227
229
  return {
228
230
  blob: await e.blob(),
229
231
  filename: $(e.headers),
230
232
  headers: e.headers
231
233
  };
232
234
  }
233
- async function re(e, t = {}) {
235
+ async function ie(e, t = {}) {
234
236
  return Z(e, t, {
235
237
  setAccept: !0,
236
238
  isSessionProbe: !1
237
- }, ne);
239
+ }, re);
238
240
  }
239
241
  function $(e) {
240
242
  let t = e.get("Content-Disposition");
@@ -246,7 +248,7 @@ function $(e) {
246
248
  let r = t.match(/filename\s*=\s*("([^"]+)"|([^;]+))/i);
247
249
  return r ? (r[2] ?? r[3] ?? "").trim() : "";
248
250
  }
249
- async function ie(e, t = {}, { isSessionProbe: n = !1, keepalive: r = !1, credentials: i } = {}) {
251
+ async function ae(e, t = {}, { isSessionProbe: n = !1, keepalive: r = !1, credentials: i } = {}) {
250
252
  return (await Z(`/api/actions/${encodeURIComponent(e)}`, {
251
253
  method: "POST",
252
254
  body: h(t),
@@ -257,4 +259,4 @@ async function ie(e, t = {}, { isSessionProbe: n = !1, keepalive: r = !1, creden
257
259
  isSessionProbe: n
258
260
  }, Q)).result;
259
261
  }
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 };
262
+ export { C as RefreshDeadError, ne as apiFetch, ie as apiFetchBlob, A as beginSessionInPage, ae as callHandler, D as cancelProactiveRefresh, Y as currentPublishedLanguage, ee as endSessionInPage, z as ensureRefresh, H as getPersistentAuthFailureHandler, k as isSignedOutInPage, R as isTransientFailure, $ as parseContentDispositionFilename, te as publishLanguage, J as publishLanguageFor, E as scheduleProactiveRefresh, q as setLanguageReader, V as setPersistentAuthFailureHandler, X as withPublishedLanguage };