@declarion/react 0.188.0 → 0.189.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-lib/api/client.js +73 -73
- package/package.json +1 -1
package/dist-lib/api/client.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ApiError as e, NetworkError as t, errorCodeOf as n, readProblem as r } from "../types/api.js";
|
|
2
2
|
import { loginPathForCurrentLocation as i } from "./auth-redirect.js";
|
|
3
3
|
import { observe as a } from "../lib/versionTracker.js";
|
|
4
|
-
import { awaitEmbedToken as
|
|
5
|
-
import { REFRESH_TIMEOUT_MS as
|
|
6
|
-
import { clearAccessExpiry as f, recordAccessExpiry as p } from "./access-expiry.js";
|
|
4
|
+
import { awaitEmbedToken as ee, clearEmbedToken as o, getEmbedToken as s, isEmbedTokenMode as c } from "../embed/token.js";
|
|
5
|
+
import { REFRESH_TIMEOUT_MS as l, requestTimeoutMs as u } from "./request-bounds.js";
|
|
6
|
+
import { clearAccessExpiry as d, clearSignOut as f, recordAccessExpiry as p } from "./access-expiry.js";
|
|
7
7
|
import { sameAudience as m } from "./audience.js";
|
|
8
8
|
// src/api/client.ts
|
|
9
9
|
var h = (e) => JSON.stringify(e ?? {}), g = null, _ = "declarion.auth.refresh.result", v = "declarion.auth.refresh";
|
|
@@ -31,7 +31,7 @@ function x(e) {
|
|
|
31
31
|
async function S() {
|
|
32
32
|
let e = navigator.locks;
|
|
33
33
|
if (!e) {
|
|
34
|
-
await
|
|
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
|
|
46
|
+
access_expires_at: await F()
|
|
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 || (
|
|
68
|
+
return O || (I = null, c() || p(e), typeof window > "u") ? Promise.resolve() : T().then((t) => t.scheduleRenewal(e), () => void 0);
|
|
69
69
|
}
|
|
70
70
|
function D() {
|
|
71
|
-
|
|
71
|
+
d(), w?.then((e) => e.cancelRenewal());
|
|
72
72
|
}
|
|
73
73
|
var O = !1;
|
|
74
|
-
function
|
|
74
|
+
function k() {
|
|
75
75
|
O = !0, D();
|
|
76
76
|
}
|
|
77
|
-
function
|
|
77
|
+
function A() {
|
|
78
78
|
return O;
|
|
79
79
|
}
|
|
80
|
-
function
|
|
81
|
-
return O = !1,
|
|
80
|
+
function j(e) {
|
|
81
|
+
return O = !1, f(), L += 1, E(e);
|
|
82
82
|
}
|
|
83
83
|
typeof window < "u" && window.addEventListener("storage", (e) => {
|
|
84
|
-
if (e.key !== _ ||
|
|
84
|
+
if (e.key !== _ || c()) 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
|
|
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,145 +98,145 @@ async function j(e, n, r) {
|
|
|
98
98
|
clearTimeout(a);
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
async function
|
|
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
|
|
109
|
-
return
|
|
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
|
+
}, l);
|
|
115
115
|
}
|
|
116
|
-
async function
|
|
117
|
-
let t = await
|
|
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
|
|
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
|
|
127
|
+
let n = await N(t);
|
|
128
128
|
return E(n), n;
|
|
129
129
|
}
|
|
130
|
-
var
|
|
131
|
-
function
|
|
130
|
+
var I = null, L = 0, R = /* @__PURE__ */ new Set(["auth.token_refresh_needed", "auth.unauthorized"]);
|
|
131
|
+
function z(n) {
|
|
132
132
|
return n instanceof t || n instanceof e;
|
|
133
133
|
}
|
|
134
|
-
async function
|
|
134
|
+
async function B() {
|
|
135
135
|
if (O) throw new C(401);
|
|
136
|
-
if (
|
|
136
|
+
if (I !== null) throw new C(I);
|
|
137
137
|
if (g) return g;
|
|
138
|
-
let e =
|
|
138
|
+
let e = L;
|
|
139
139
|
return g = S().catch((t) => {
|
|
140
|
-
throw t instanceof C && e ===
|
|
140
|
+
throw t instanceof C && e === L && (I = t.status), t;
|
|
141
141
|
}).finally(() => {
|
|
142
142
|
g = null;
|
|
143
143
|
}), g;
|
|
144
144
|
}
|
|
145
|
-
var
|
|
145
|
+
var V = () => {
|
|
146
146
|
if (typeof window > "u") return;
|
|
147
147
|
let { pathname: e } = window.location;
|
|
148
148
|
e.startsWith("/login") || e.startsWith("/signup") || e === "/reset" || e === "/forgot" || e === "/2fa" || (window.location.href = i());
|
|
149
149
|
};
|
|
150
|
-
function
|
|
151
|
-
let t =
|
|
152
|
-
return
|
|
150
|
+
function H(e) {
|
|
151
|
+
let t = V;
|
|
152
|
+
return V = e, t;
|
|
153
153
|
}
|
|
154
|
-
function
|
|
155
|
-
return
|
|
154
|
+
function U() {
|
|
155
|
+
return V;
|
|
156
156
|
}
|
|
157
|
-
var
|
|
157
|
+
var W = ({ status: e, code: t, message: n }) => {
|
|
158
158
|
console.error(`[API ${e}] ${t}: ${n}`);
|
|
159
159
|
};
|
|
160
|
-
function
|
|
160
|
+
function G(e, t, n, r) {
|
|
161
161
|
let i = new Headers(e);
|
|
162
162
|
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;
|
|
163
163
|
}
|
|
164
|
-
var
|
|
165
|
-
function
|
|
166
|
-
|
|
164
|
+
var K = null, q;
|
|
165
|
+
function J(e) {
|
|
166
|
+
q = e, K && e !== void 0 && !m(K.reader, e) && (K = null);
|
|
167
167
|
}
|
|
168
|
-
function
|
|
169
|
-
(
|
|
168
|
+
function te(e, t) {
|
|
169
|
+
(q === void 0 || m(e, q)) && (K = t ? {
|
|
170
170
|
language: t,
|
|
171
171
|
reader: e
|
|
172
172
|
} : null);
|
|
173
173
|
}
|
|
174
|
-
function
|
|
175
|
-
|
|
174
|
+
function ne(e) {
|
|
175
|
+
K = e ? {
|
|
176
176
|
language: e,
|
|
177
|
-
reader:
|
|
177
|
+
reader: q ?? null
|
|
178
178
|
} : null;
|
|
179
179
|
}
|
|
180
180
|
function Y() {
|
|
181
|
-
return
|
|
181
|
+
return K?.language ?? null;
|
|
182
182
|
}
|
|
183
183
|
function X(e) {
|
|
184
184
|
let t = Y();
|
|
185
185
|
return !t || !e.startsWith("/api/") || /[?&]language=/.test(e) ? e : `${e}${e.includes("?") ? "&" : "?"}language=${encodeURIComponent(t)}`;
|
|
186
186
|
}
|
|
187
|
-
async function Z(t, i,
|
|
188
|
-
let
|
|
187
|
+
async function Z(t, i, l, d) {
|
|
188
|
+
let f = X(t), p = c(), m = p ? "omit" : i.credentials ?? "include", h = p || m !== "omit", g = G(i.headers, !!i.body, l, p ? s() : null), _ = u(t, i), v = L, y = await M(f, {
|
|
189
189
|
...i,
|
|
190
|
-
headers:
|
|
191
|
-
credentials:
|
|
192
|
-
},
|
|
193
|
-
if (a(
|
|
194
|
-
let { raw: t, body: a } = await r(
|
|
195
|
-
if (
|
|
190
|
+
headers: g,
|
|
191
|
+
credentials: m
|
|
192
|
+
}, _);
|
|
193
|
+
if (a(y.headers), !y.ok) {
|
|
194
|
+
let { raw: t, body: a } = await r(y), s = n(a.type), c = a.title ?? "";
|
|
195
|
+
if (h && y.status === 401 && R.has(s)) try {
|
|
196
196
|
let t = null;
|
|
197
|
-
|
|
198
|
-
let a =
|
|
197
|
+
p ? (o(), t = await ee()) : await B();
|
|
198
|
+
let a = G(i.headers, !!i.body, l, t), s = await M(f, {
|
|
199
199
|
...i,
|
|
200
200
|
headers: a,
|
|
201
|
-
credentials:
|
|
202
|
-
},
|
|
203
|
-
if (!
|
|
204
|
-
let t = await r(
|
|
205
|
-
throw !
|
|
201
|
+
credentials: m
|
|
202
|
+
}, _);
|
|
203
|
+
if (!s.ok) {
|
|
204
|
+
let t = await r(s);
|
|
205
|
+
throw !p && v === L && s.status === 401 && R.has(n(t.body.type)) && (I = 401), s.status === 401 && !l.isSessionProbe && V(), new e(s.status, t.body, t.raw);
|
|
206
206
|
}
|
|
207
|
-
return
|
|
207
|
+
return d(s);
|
|
208
208
|
} catch (n) {
|
|
209
|
-
throw
|
|
209
|
+
throw z(n) ? n : (l.isSessionProbe || V(), new e(401, a, t));
|
|
210
210
|
}
|
|
211
|
-
throw
|
|
212
|
-
status:
|
|
213
|
-
code:
|
|
214
|
-
message:
|
|
215
|
-
}), new e(
|
|
211
|
+
throw h && y.status === 401 && !l.isSessionProbe && V(), W({
|
|
212
|
+
status: y.status,
|
|
213
|
+
code: s,
|
|
214
|
+
message: c
|
|
215
|
+
}), new e(y.status, a, t);
|
|
216
216
|
}
|
|
217
|
-
return
|
|
217
|
+
return d(y);
|
|
218
218
|
}
|
|
219
219
|
function Q(e) {
|
|
220
220
|
return e.status === 204 ? Promise.resolve(void 0) : e.json();
|
|
221
221
|
}
|
|
222
|
-
async function
|
|
222
|
+
async function re(e, t = {}, { isSessionProbe: n = !1 } = {}) {
|
|
223
223
|
return Z(e, t, {
|
|
224
224
|
setAccept: !1,
|
|
225
225
|
isSessionProbe: n
|
|
226
226
|
}, Q);
|
|
227
227
|
}
|
|
228
|
-
async function
|
|
228
|
+
async function ie(e) {
|
|
229
229
|
return {
|
|
230
230
|
blob: await e.blob(),
|
|
231
231
|
filename: $(e.headers),
|
|
232
232
|
headers: e.headers
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
|
-
async function
|
|
235
|
+
async function ae(e, t = {}) {
|
|
236
236
|
return Z(e, t, {
|
|
237
237
|
setAccept: !0,
|
|
238
238
|
isSessionProbe: !1
|
|
239
|
-
},
|
|
239
|
+
}, ie);
|
|
240
240
|
}
|
|
241
241
|
function $(e) {
|
|
242
242
|
let t = e.get("Content-Disposition");
|
|
@@ -248,7 +248,7 @@ function $(e) {
|
|
|
248
248
|
let r = t.match(/filename\s*=\s*("([^"]+)"|([^;]+))/i);
|
|
249
249
|
return r ? (r[2] ?? r[3] ?? "").trim() : "";
|
|
250
250
|
}
|
|
251
|
-
async function
|
|
251
|
+
async function oe(e, t = {}, { isSessionProbe: n = !1, keepalive: r = !1, credentials: i } = {}) {
|
|
252
252
|
return (await Z(`/api/actions/${encodeURIComponent(e)}`, {
|
|
253
253
|
method: "POST",
|
|
254
254
|
body: h(t),
|
|
@@ -259,4 +259,4 @@ async function ae(e, t = {}, { isSessionProbe: n = !1, keepalive: r = !1, creden
|
|
|
259
259
|
isSessionProbe: n
|
|
260
260
|
}, Q)).result;
|
|
261
261
|
}
|
|
262
|
-
export { C as RefreshDeadError,
|
|
262
|
+
export { C as RefreshDeadError, re as apiFetch, ae as apiFetchBlob, j as beginSessionInPage, oe as callHandler, D as cancelProactiveRefresh, Y as currentPublishedLanguage, k as endSessionInPage, B as ensureRefresh, U as getPersistentAuthFailureHandler, A as isSignedOutInPage, z as isTransientFailure, $ as parseContentDispositionFilename, ne as publishLanguage, te as publishLanguageFor, E as scheduleProactiveRefresh, J as setLanguageReader, H as setPersistentAuthFailureHandler, X as withPublishedLanguage };
|