@arcadeai/design-system 3.5.4 → 3.5.6
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/arcade/arcade.d.ts +3 -4
- package/dist/lib/arcade/arcade.js +1466 -5
- package/dist/lib/arcade/arcade.test.js +31 -21
- package/package.json +10 -10
- package/dist/arcade-CHE48l2C.js +0 -1469
package/dist/arcade-CHE48l2C.js
DELETED
|
@@ -1,1469 +0,0 @@
|
|
|
1
|
-
import { k as _e, s as Qe, g as Ge, F as de, f as Je, a as Ye, b as Ze } from "./web-sgv-FK6q.js";
|
|
2
|
-
import { TOOLKIT_CATALOGUE as et } from "./metadata/toolkits.js";
|
|
3
|
-
import { r as he } from "./utils-Db4QWi-E.js";
|
|
4
|
-
const J = "RFC3986", Y = {
|
|
5
|
-
RFC1738: (t) => String(t).replace(/%20/g, "+"),
|
|
6
|
-
RFC3986: (t) => String(t)
|
|
7
|
-
}, tt = "RFC1738", nt = Array.isArray, _ = (() => {
|
|
8
|
-
const t = [];
|
|
9
|
-
for (let e = 0; e < 256; ++e)
|
|
10
|
-
t.push("%" + ((e < 16 ? "0" : "") + e.toString(16)).toUpperCase());
|
|
11
|
-
return t;
|
|
12
|
-
})(), W = 1024, rt = (t, e, n, r, s) => {
|
|
13
|
-
if (t.length === 0)
|
|
14
|
-
return t;
|
|
15
|
-
let o = t;
|
|
16
|
-
if (typeof t == "symbol" ? o = Symbol.prototype.toString.call(t) : typeof t != "string" && (o = String(t)), n === "iso-8859-1")
|
|
17
|
-
return escape(o).replace(/%u[0-9a-f]{4}/gi, function(l) {
|
|
18
|
-
return "%26%23" + parseInt(l.slice(2), 16) + "%3B";
|
|
19
|
-
});
|
|
20
|
-
let i = "";
|
|
21
|
-
for (let l = 0; l < o.length; l += W) {
|
|
22
|
-
const c = o.length >= W ? o.slice(l, l + W) : o, u = [];
|
|
23
|
-
for (let p = 0; p < c.length; ++p) {
|
|
24
|
-
let a = c.charCodeAt(p);
|
|
25
|
-
if (a === 45 || // -
|
|
26
|
-
a === 46 || // .
|
|
27
|
-
a === 95 || // _
|
|
28
|
-
a === 126 || // ~
|
|
29
|
-
a >= 48 && a <= 57 || // 0-9
|
|
30
|
-
a >= 65 && a <= 90 || // a-z
|
|
31
|
-
a >= 97 && a <= 122 || // A-Z
|
|
32
|
-
s === tt && (a === 40 || a === 41)) {
|
|
33
|
-
u[u.length] = c.charAt(p);
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (a < 128) {
|
|
37
|
-
u[u.length] = _[a];
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
if (a < 2048) {
|
|
41
|
-
u[u.length] = _[192 | a >> 6] + _[128 | a & 63];
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
if (a < 55296 || a >= 57344) {
|
|
45
|
-
u[u.length] = _[224 | a >> 12] + _[128 | a >> 6 & 63] + _[128 | a & 63];
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
p += 1, a = 65536 + ((a & 1023) << 10 | c.charCodeAt(p) & 1023), u[u.length] = _[240 | a >> 18] + _[128 | a >> 12 & 63] + _[128 | a >> 6 & 63] + _[128 | a & 63];
|
|
49
|
-
}
|
|
50
|
-
i += u.join("");
|
|
51
|
-
}
|
|
52
|
-
return i;
|
|
53
|
-
};
|
|
54
|
-
function st(t) {
|
|
55
|
-
return !t || typeof t != "object" ? !1 : !!(t.constructor && t.constructor.isBuffer && t.constructor.isBuffer(t));
|
|
56
|
-
}
|
|
57
|
-
function pe(t, e) {
|
|
58
|
-
if (nt(t)) {
|
|
59
|
-
const n = [];
|
|
60
|
-
for (let r = 0; r < t.length; r += 1)
|
|
61
|
-
n.push(e(t[r]));
|
|
62
|
-
return n;
|
|
63
|
-
}
|
|
64
|
-
return e(t);
|
|
65
|
-
}
|
|
66
|
-
const ot = Object.prototype.hasOwnProperty, Ae = {
|
|
67
|
-
brackets(t) {
|
|
68
|
-
return String(t) + "[]";
|
|
69
|
-
},
|
|
70
|
-
comma: "comma",
|
|
71
|
-
indices(t, e) {
|
|
72
|
-
return String(t) + "[" + e + "]";
|
|
73
|
-
},
|
|
74
|
-
repeat(t) {
|
|
75
|
-
return String(t);
|
|
76
|
-
}
|
|
77
|
-
}, A = Array.isArray, it = Array.prototype.push, Se = function(t, e) {
|
|
78
|
-
it.apply(t, A(e) ? e : [e]);
|
|
79
|
-
}, at = Date.prototype.toISOString, y = {
|
|
80
|
-
addQueryPrefix: !1,
|
|
81
|
-
allowDots: !1,
|
|
82
|
-
allowEmptyArrays: !1,
|
|
83
|
-
arrayFormat: "indices",
|
|
84
|
-
charset: "utf-8",
|
|
85
|
-
charsetSentinel: !1,
|
|
86
|
-
delimiter: "&",
|
|
87
|
-
encode: !0,
|
|
88
|
-
encodeDotInKeys: !1,
|
|
89
|
-
encoder: rt,
|
|
90
|
-
encodeValuesOnly: !1,
|
|
91
|
-
format: J,
|
|
92
|
-
formatter: Y[J],
|
|
93
|
-
/** @deprecated */
|
|
94
|
-
indices: !1,
|
|
95
|
-
serializeDate(t) {
|
|
96
|
-
return at.call(t);
|
|
97
|
-
},
|
|
98
|
-
skipNulls: !1,
|
|
99
|
-
strictNullHandling: !1
|
|
100
|
-
};
|
|
101
|
-
function ct(t) {
|
|
102
|
-
return typeof t == "string" || typeof t == "number" || typeof t == "boolean" || typeof t == "symbol" || typeof t == "bigint";
|
|
103
|
-
}
|
|
104
|
-
const V = {};
|
|
105
|
-
function Re(t, e, n, r, s, o, i, l, c, u, p, a, h, m, b, E, S, z) {
|
|
106
|
-
let f = t, D = z, U = 0, ce = !1;
|
|
107
|
-
for (; (D = D.get(V)) !== void 0 && !ce; ) {
|
|
108
|
-
const g = D.get(t);
|
|
109
|
-
if (U += 1, typeof g < "u") {
|
|
110
|
-
if (g === U)
|
|
111
|
-
throw new RangeError("Cyclic object value");
|
|
112
|
-
ce = !0;
|
|
113
|
-
}
|
|
114
|
-
typeof D.get(V) > "u" && (U = 0);
|
|
115
|
-
}
|
|
116
|
-
if (typeof u == "function" ? f = u(e, f) : f instanceof Date ? f = h?.(f) : n === "comma" && A(f) && (f = pe(f, function(g) {
|
|
117
|
-
return g instanceof Date ? h?.(g) : g;
|
|
118
|
-
})), f === null) {
|
|
119
|
-
if (o)
|
|
120
|
-
return c && !E ? (
|
|
121
|
-
// @ts-expect-error
|
|
122
|
-
c(e, y.encoder, S, "key", m)
|
|
123
|
-
) : e;
|
|
124
|
-
f = "";
|
|
125
|
-
}
|
|
126
|
-
if (ct(f) || st(f)) {
|
|
127
|
-
if (c) {
|
|
128
|
-
const g = E ? e : c(e, y.encoder, S, "key", m);
|
|
129
|
-
return [
|
|
130
|
-
b?.(g) + "=" + // @ts-expect-error
|
|
131
|
-
b?.(c(f, y.encoder, S, "value", m))
|
|
132
|
-
];
|
|
133
|
-
}
|
|
134
|
-
return [b?.(e) + "=" + b?.(String(f))];
|
|
135
|
-
}
|
|
136
|
-
const X = [];
|
|
137
|
-
if (typeof f > "u")
|
|
138
|
-
return X;
|
|
139
|
-
let I;
|
|
140
|
-
if (n === "comma" && A(f))
|
|
141
|
-
E && c && (f = pe(f, c)), I = [{ value: f.length > 0 ? f.join(",") || null : void 0 }];
|
|
142
|
-
else if (A(u))
|
|
143
|
-
I = u;
|
|
144
|
-
else {
|
|
145
|
-
const g = Object.keys(f);
|
|
146
|
-
I = p ? g.sort(p) : g;
|
|
147
|
-
}
|
|
148
|
-
const ue = l ? String(e).replace(/\./g, "%2E") : String(e), $ = r && A(f) && f.length === 1 ? ue + "[]" : ue;
|
|
149
|
-
if (s && A(f) && f.length === 0)
|
|
150
|
-
return $ + "[]";
|
|
151
|
-
for (let g = 0; g < I.length; ++g) {
|
|
152
|
-
const k = I[g], le = (
|
|
153
|
-
// @ts-ignore
|
|
154
|
-
typeof k == "object" && typeof k.value < "u" ? k.value : f[k]
|
|
155
|
-
);
|
|
156
|
-
if (i && le === null)
|
|
157
|
-
continue;
|
|
158
|
-
const K = a && l ? k.replace(/\./g, "%2E") : k, Ve = A(f) ? typeof n == "function" ? n($, K) : $ : $ + (a ? "." + K : "[" + K + "]");
|
|
159
|
-
z.set(t, U);
|
|
160
|
-
const fe = /* @__PURE__ */ new WeakMap();
|
|
161
|
-
fe.set(V, z), Se(X, Re(
|
|
162
|
-
le,
|
|
163
|
-
Ve,
|
|
164
|
-
n,
|
|
165
|
-
r,
|
|
166
|
-
s,
|
|
167
|
-
o,
|
|
168
|
-
i,
|
|
169
|
-
l,
|
|
170
|
-
// @ts-ignore
|
|
171
|
-
n === "comma" && E && A(f) ? null : c,
|
|
172
|
-
u,
|
|
173
|
-
p,
|
|
174
|
-
a,
|
|
175
|
-
h,
|
|
176
|
-
m,
|
|
177
|
-
b,
|
|
178
|
-
E,
|
|
179
|
-
S,
|
|
180
|
-
fe
|
|
181
|
-
));
|
|
182
|
-
}
|
|
183
|
-
return X;
|
|
184
|
-
}
|
|
185
|
-
function ut(t = y) {
|
|
186
|
-
if (typeof t.allowEmptyArrays < "u" && typeof t.allowEmptyArrays != "boolean")
|
|
187
|
-
throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");
|
|
188
|
-
if (typeof t.encodeDotInKeys < "u" && typeof t.encodeDotInKeys != "boolean")
|
|
189
|
-
throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");
|
|
190
|
-
if (t.encoder !== null && typeof t.encoder < "u" && typeof t.encoder != "function")
|
|
191
|
-
throw new TypeError("Encoder has to be a function.");
|
|
192
|
-
const e = t.charset || y.charset;
|
|
193
|
-
if (typeof t.charset < "u" && t.charset !== "utf-8" && t.charset !== "iso-8859-1")
|
|
194
|
-
throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");
|
|
195
|
-
let n = J;
|
|
196
|
-
if (typeof t.format < "u") {
|
|
197
|
-
if (!ot.call(Y, t.format))
|
|
198
|
-
throw new TypeError("Unknown format option provided.");
|
|
199
|
-
n = t.format;
|
|
200
|
-
}
|
|
201
|
-
const r = Y[n];
|
|
202
|
-
let s = y.filter;
|
|
203
|
-
(typeof t.filter == "function" || A(t.filter)) && (s = t.filter);
|
|
204
|
-
let o;
|
|
205
|
-
if (t.arrayFormat && t.arrayFormat in Ae ? o = t.arrayFormat : "indices" in t ? o = t.indices ? "indices" : "repeat" : o = y.arrayFormat, "commaRoundTrip" in t && typeof t.commaRoundTrip != "boolean")
|
|
206
|
-
throw new TypeError("`commaRoundTrip` must be a boolean, or absent");
|
|
207
|
-
const i = typeof t.allowDots > "u" ? t.encodeDotInKeys ? !0 : y.allowDots : !!t.allowDots;
|
|
208
|
-
return {
|
|
209
|
-
addQueryPrefix: typeof t.addQueryPrefix == "boolean" ? t.addQueryPrefix : y.addQueryPrefix,
|
|
210
|
-
// @ts-ignore
|
|
211
|
-
allowDots: i,
|
|
212
|
-
allowEmptyArrays: typeof t.allowEmptyArrays == "boolean" ? !!t.allowEmptyArrays : y.allowEmptyArrays,
|
|
213
|
-
arrayFormat: o,
|
|
214
|
-
charset: e,
|
|
215
|
-
charsetSentinel: typeof t.charsetSentinel == "boolean" ? t.charsetSentinel : y.charsetSentinel,
|
|
216
|
-
commaRoundTrip: !!t.commaRoundTrip,
|
|
217
|
-
delimiter: typeof t.delimiter > "u" ? y.delimiter : t.delimiter,
|
|
218
|
-
encode: typeof t.encode == "boolean" ? t.encode : y.encode,
|
|
219
|
-
encodeDotInKeys: typeof t.encodeDotInKeys == "boolean" ? t.encodeDotInKeys : y.encodeDotInKeys,
|
|
220
|
-
encoder: typeof t.encoder == "function" ? t.encoder : y.encoder,
|
|
221
|
-
encodeValuesOnly: typeof t.encodeValuesOnly == "boolean" ? t.encodeValuesOnly : y.encodeValuesOnly,
|
|
222
|
-
filter: s,
|
|
223
|
-
format: n,
|
|
224
|
-
formatter: r,
|
|
225
|
-
serializeDate: typeof t.serializeDate == "function" ? t.serializeDate : y.serializeDate,
|
|
226
|
-
skipNulls: typeof t.skipNulls == "boolean" ? t.skipNulls : y.skipNulls,
|
|
227
|
-
// @ts-ignore
|
|
228
|
-
sort: typeof t.sort == "function" ? t.sort : null,
|
|
229
|
-
strictNullHandling: typeof t.strictNullHandling == "boolean" ? t.strictNullHandling : y.strictNullHandling
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
function lt(t, e = {}) {
|
|
233
|
-
let n = t;
|
|
234
|
-
const r = ut(e);
|
|
235
|
-
let s, o;
|
|
236
|
-
typeof r.filter == "function" ? (o = r.filter, n = o("", n)) : A(r.filter) && (o = r.filter, s = o);
|
|
237
|
-
const i = [];
|
|
238
|
-
if (typeof n != "object" || n === null)
|
|
239
|
-
return "";
|
|
240
|
-
const l = Ae[r.arrayFormat], c = l === "comma" && r.commaRoundTrip;
|
|
241
|
-
s || (s = Object.keys(n)), r.sort && s.sort(r.sort);
|
|
242
|
-
const u = /* @__PURE__ */ new WeakMap();
|
|
243
|
-
for (let h = 0; h < s.length; ++h) {
|
|
244
|
-
const m = s[h];
|
|
245
|
-
r.skipNulls && n[m] === null || Se(i, Re(
|
|
246
|
-
n[m],
|
|
247
|
-
m,
|
|
248
|
-
// @ts-expect-error
|
|
249
|
-
l,
|
|
250
|
-
c,
|
|
251
|
-
r.allowEmptyArrays,
|
|
252
|
-
r.strictNullHandling,
|
|
253
|
-
r.skipNulls,
|
|
254
|
-
r.encodeDotInKeys,
|
|
255
|
-
r.encode ? r.encoder : null,
|
|
256
|
-
r.filter,
|
|
257
|
-
r.sort,
|
|
258
|
-
r.allowDots,
|
|
259
|
-
r.serializeDate,
|
|
260
|
-
r.format,
|
|
261
|
-
r.formatter,
|
|
262
|
-
r.encodeValuesOnly,
|
|
263
|
-
r.charset,
|
|
264
|
-
u
|
|
265
|
-
));
|
|
266
|
-
}
|
|
267
|
-
const p = i.join(r.delimiter);
|
|
268
|
-
let a = r.addQueryPrefix === !0 ? "?" : "";
|
|
269
|
-
return r.charsetSentinel && (r.charset === "iso-8859-1" ? a += "utf8=%26%2310003%3B&" : a += "utf8=%E2%9C%93&"), p.length > 0 ? a + p : "";
|
|
270
|
-
}
|
|
271
|
-
const T = "1.10.0";
|
|
272
|
-
class P extends Error {
|
|
273
|
-
}
|
|
274
|
-
class w extends P {
|
|
275
|
-
constructor(e, n, r, s) {
|
|
276
|
-
super(`${w.makeMessage(e, n, r)}`), this.status = e, this.headers = s, this.error = n;
|
|
277
|
-
}
|
|
278
|
-
static makeMessage(e, n, r) {
|
|
279
|
-
const s = n?.message ? typeof n.message == "string" ? n.message : JSON.stringify(n.message) : n ? JSON.stringify(n) : r;
|
|
280
|
-
return e && s ? `${e} ${s}` : e ? `${e} status code (no body)` : s || "(no status code or body)";
|
|
281
|
-
}
|
|
282
|
-
static generate(e, n, r, s) {
|
|
283
|
-
if (!e || !s)
|
|
284
|
-
return new F({ message: r, cause: ee(n) });
|
|
285
|
-
const o = n;
|
|
286
|
-
return e === 400 ? new Pe(e, o, r, s) : e === 401 ? new ke(e, o, r, s) : e === 403 ? new Te(e, o, r, s) : e === 404 ? new Ce(e, o, r, s) : e === 409 ? new ve(e, o, r, s) : e === 422 ? new Ie(e, o, r, s) : e === 429 ? new Le(e, o, r, s) : e >= 500 ? new Oe(e, o, r, s) : new w(e, o, r, s);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
class Z extends w {
|
|
290
|
-
constructor({ message: e } = {}) {
|
|
291
|
-
super(void 0, void 0, e || "Request was aborted.", void 0);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
class F extends w {
|
|
295
|
-
constructor({ message: e, cause: n }) {
|
|
296
|
-
super(void 0, void 0, e || "Connection error.", void 0), n && (this.cause = n);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
class Ee extends F {
|
|
300
|
-
constructor({ message: e } = {}) {
|
|
301
|
-
super({ message: e ?? "Request timed out." });
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
class Pe extends w {
|
|
305
|
-
}
|
|
306
|
-
class ke extends w {
|
|
307
|
-
}
|
|
308
|
-
class Te extends w {
|
|
309
|
-
}
|
|
310
|
-
class Ce extends w {
|
|
311
|
-
}
|
|
312
|
-
class ve extends w {
|
|
313
|
-
}
|
|
314
|
-
class Ie extends w {
|
|
315
|
-
}
|
|
316
|
-
class Le extends w {
|
|
317
|
-
}
|
|
318
|
-
class Oe extends w {
|
|
319
|
-
}
|
|
320
|
-
const De = () => {
|
|
321
|
-
_e || Qe(Ge(), { auto: !0 });
|
|
322
|
-
};
|
|
323
|
-
De();
|
|
324
|
-
const ft = (t) => t != null && typeof t == "object" && typeof t.url == "string" && typeof t.blob == "function", dt = (t) => t != null && typeof t == "object" && typeof t.name == "string" && typeof t.lastModified == "number" && q(t), q = (t) => t != null && typeof t == "object" && typeof t.size == "number" && typeof t.type == "string" && typeof t.text == "function" && typeof t.slice == "function" && typeof t.arrayBuffer == "function";
|
|
325
|
-
async function ht(t, e, n) {
|
|
326
|
-
if (t = await t, dt(t))
|
|
327
|
-
return t;
|
|
328
|
-
if (ft(t)) {
|
|
329
|
-
const s = await t.blob();
|
|
330
|
-
e || (e = new URL(t.url).pathname.split(/[\\/]/).pop() ?? "unknown_file");
|
|
331
|
-
const o = q(s) ? [await s.arrayBuffer()] : [s];
|
|
332
|
-
return new de(o, e, n);
|
|
333
|
-
}
|
|
334
|
-
const r = await pt(t);
|
|
335
|
-
if (e || (e = mt(t) ?? "unknown_file"), !n?.type) {
|
|
336
|
-
const s = r[0]?.type;
|
|
337
|
-
typeof s == "string" && (n = { ...n, type: s });
|
|
338
|
-
}
|
|
339
|
-
return new de(r, e, n);
|
|
340
|
-
}
|
|
341
|
-
async function pt(t) {
|
|
342
|
-
let e = [];
|
|
343
|
-
if (typeof t == "string" || ArrayBuffer.isView(t) || // includes Uint8Array, Buffer, etc.
|
|
344
|
-
t instanceof ArrayBuffer)
|
|
345
|
-
e.push(t);
|
|
346
|
-
else if (q(t))
|
|
347
|
-
e.push(await t.arrayBuffer());
|
|
348
|
-
else if (gt(t))
|
|
349
|
-
for await (const n of t)
|
|
350
|
-
e.push(n);
|
|
351
|
-
else
|
|
352
|
-
throw new Error(`Unexpected data type: ${typeof t}; constructor: ${t?.constructor?.name}; props: ${yt(t)}`);
|
|
353
|
-
return e;
|
|
354
|
-
}
|
|
355
|
-
function yt(t) {
|
|
356
|
-
return `[${Object.getOwnPropertyNames(t).map((n) => `"${n}"`).join(", ")}]`;
|
|
357
|
-
}
|
|
358
|
-
function mt(t) {
|
|
359
|
-
return Q(t.name) || Q(t.filename) || // For fs.ReadStream
|
|
360
|
-
Q(t.path)?.split(/[\\/]/).pop();
|
|
361
|
-
}
|
|
362
|
-
const Q = (t) => {
|
|
363
|
-
if (typeof t == "string")
|
|
364
|
-
return t;
|
|
365
|
-
if (typeof Buffer < "u" && t instanceof Buffer)
|
|
366
|
-
return String(t);
|
|
367
|
-
}, gt = (t) => t != null && typeof t == "object" && typeof t[Symbol.asyncIterator] == "function", ye = (t) => t && typeof t == "object" && t.body && t[Symbol.toStringTag] === "MultipartBody";
|
|
368
|
-
var Ue = function(t, e, n, r, s) {
|
|
369
|
-
if (r === "m") throw new TypeError("Private method is not writable");
|
|
370
|
-
if (r === "a" && !s) throw new TypeError("Private accessor was defined without a setter");
|
|
371
|
-
if (typeof e == "function" ? t !== e || !s : !e.has(t)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
372
|
-
return r === "a" ? s.call(t, n) : s ? s.value = n : e.set(t, n), n;
|
|
373
|
-
}, $e = function(t, e, n, r) {
|
|
374
|
-
if (n === "a" && !r) throw new TypeError("Private accessor was defined without a getter");
|
|
375
|
-
if (typeof e == "function" ? t !== e || !r : !e.has(t)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
376
|
-
return n === "m" ? r : n === "a" ? r.call(t) : r ? r.value : e.get(t);
|
|
377
|
-
}, M, j;
|
|
378
|
-
De();
|
|
379
|
-
async function je(t) {
|
|
380
|
-
const { response: e } = t;
|
|
381
|
-
if (e.status === 204)
|
|
382
|
-
return null;
|
|
383
|
-
if (t.options.__binaryResponse)
|
|
384
|
-
return e;
|
|
385
|
-
const r = e.headers.get("content-type")?.split(";")[0]?.trim();
|
|
386
|
-
if (r?.includes("application/json") || r?.endsWith("+json")) {
|
|
387
|
-
const i = await e.json();
|
|
388
|
-
return L("response", e.status, e.url, e.headers, i), i;
|
|
389
|
-
}
|
|
390
|
-
const o = await e.text();
|
|
391
|
-
return L("response", e.status, e.url, e.headers, o), o;
|
|
392
|
-
}
|
|
393
|
-
class B extends Promise {
|
|
394
|
-
constructor(e, n = je) {
|
|
395
|
-
super((r) => {
|
|
396
|
-
r(null);
|
|
397
|
-
}), this.responsePromise = e, this.parseResponse = n;
|
|
398
|
-
}
|
|
399
|
-
_thenUnwrap(e) {
|
|
400
|
-
return new B(this.responsePromise, async (n) => e(await this.parseResponse(n), n));
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Gets the raw `Response` instance instead of parsing the response
|
|
404
|
-
* data.
|
|
405
|
-
*
|
|
406
|
-
* If you want to parse the response body but still get the `Response`
|
|
407
|
-
* instance, you can use {@link withResponse()}.
|
|
408
|
-
*
|
|
409
|
-
* 👋 Getting the wrong TypeScript type for `Response`?
|
|
410
|
-
* Try setting `"moduleResolution": "NodeNext"` if you can,
|
|
411
|
-
* or add one of these imports before your first `import … from '@arcadeai/arcadejs'`:
|
|
412
|
-
* - `import '@arcadeai/arcadejs/shims/node'` (if you're running on Node)
|
|
413
|
-
* - `import '@arcadeai/arcadejs/shims/web'` (otherwise)
|
|
414
|
-
*/
|
|
415
|
-
asResponse() {
|
|
416
|
-
return this.responsePromise.then((e) => e.response);
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* Gets the parsed response data and the raw `Response` instance.
|
|
420
|
-
*
|
|
421
|
-
* If you just want to get the raw `Response` instance without parsing it,
|
|
422
|
-
* you can use {@link asResponse()}.
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
* 👋 Getting the wrong TypeScript type for `Response`?
|
|
426
|
-
* Try setting `"moduleResolution": "NodeNext"` if you can,
|
|
427
|
-
* or add one of these imports before your first `import … from '@arcadeai/arcadejs'`:
|
|
428
|
-
* - `import '@arcadeai/arcadejs/shims/node'` (if you're running on Node)
|
|
429
|
-
* - `import '@arcadeai/arcadejs/shims/web'` (otherwise)
|
|
430
|
-
*/
|
|
431
|
-
async withResponse() {
|
|
432
|
-
const [e, n] = await Promise.all([this.parse(), this.asResponse()]);
|
|
433
|
-
return { data: e, response: n };
|
|
434
|
-
}
|
|
435
|
-
parse() {
|
|
436
|
-
return this.parsedPromise || (this.parsedPromise = this.responsePromise.then(this.parseResponse)), this.parsedPromise;
|
|
437
|
-
}
|
|
438
|
-
then(e, n) {
|
|
439
|
-
return this.parse().then(e, n);
|
|
440
|
-
}
|
|
441
|
-
catch(e) {
|
|
442
|
-
return this.parse().catch(e);
|
|
443
|
-
}
|
|
444
|
-
finally(e) {
|
|
445
|
-
return this.parse().finally(e);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
class wt {
|
|
449
|
-
constructor({
|
|
450
|
-
baseURL: e,
|
|
451
|
-
baseURLOverridden: n,
|
|
452
|
-
maxRetries: r = 2,
|
|
453
|
-
timeout: s = 6e4,
|
|
454
|
-
// 1 minute
|
|
455
|
-
httpAgent: o,
|
|
456
|
-
fetch: i
|
|
457
|
-
}) {
|
|
458
|
-
M.set(this, void 0), this.baseURL = e, Ue(this, M, n, "f"), this.maxRetries = G("maxRetries", r), this.timeout = G("timeout", s), this.httpAgent = o, this.fetch = i ?? Je;
|
|
459
|
-
}
|
|
460
|
-
authHeaders(e) {
|
|
461
|
-
return {};
|
|
462
|
-
}
|
|
463
|
-
/**
|
|
464
|
-
* Override this to add your own default headers, for example:
|
|
465
|
-
*
|
|
466
|
-
* {
|
|
467
|
-
* ...super.defaultHeaders(),
|
|
468
|
-
* Authorization: 'Bearer 123',
|
|
469
|
-
* }
|
|
470
|
-
*/
|
|
471
|
-
defaultHeaders(e) {
|
|
472
|
-
return {
|
|
473
|
-
Accept: "application/json",
|
|
474
|
-
...["head", "get"].includes(e.method) ? {} : { "Content-Type": "application/json" },
|
|
475
|
-
"User-Agent": this.getUserAgent(),
|
|
476
|
-
...Et(),
|
|
477
|
-
...this.authHeaders(e)
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
/**
|
|
481
|
-
* Override this to add your own headers validation:
|
|
482
|
-
*/
|
|
483
|
-
validateHeaders(e, n) {
|
|
484
|
-
}
|
|
485
|
-
defaultIdempotencyKey() {
|
|
486
|
-
return `stainless-node-retry-${vt()}`;
|
|
487
|
-
}
|
|
488
|
-
get(e, n) {
|
|
489
|
-
return this.methodRequest("get", e, n);
|
|
490
|
-
}
|
|
491
|
-
post(e, n) {
|
|
492
|
-
return this.methodRequest("post", e, n);
|
|
493
|
-
}
|
|
494
|
-
patch(e, n) {
|
|
495
|
-
return this.methodRequest("patch", e, n);
|
|
496
|
-
}
|
|
497
|
-
put(e, n) {
|
|
498
|
-
return this.methodRequest("put", e, n);
|
|
499
|
-
}
|
|
500
|
-
delete(e, n) {
|
|
501
|
-
return this.methodRequest("delete", e, n);
|
|
502
|
-
}
|
|
503
|
-
methodRequest(e, n, r) {
|
|
504
|
-
return this.request(Promise.resolve(r).then(async (s) => {
|
|
505
|
-
const o = s && q(s?.body) ? new DataView(await s.body.arrayBuffer()) : s?.body instanceof DataView ? s.body : s?.body instanceof ArrayBuffer ? new DataView(s.body) : s && ArrayBuffer.isView(s?.body) ? new DataView(s.body.buffer) : s?.body;
|
|
506
|
-
return { method: e, path: n, ...s, body: o };
|
|
507
|
-
}));
|
|
508
|
-
}
|
|
509
|
-
getAPIList(e, n, r) {
|
|
510
|
-
return this.requestAPIList(n, { method: "get", path: e, ...r });
|
|
511
|
-
}
|
|
512
|
-
calculateContentLength(e) {
|
|
513
|
-
if (typeof e == "string") {
|
|
514
|
-
if (typeof Buffer < "u")
|
|
515
|
-
return Buffer.byteLength(e, "utf8").toString();
|
|
516
|
-
if (typeof TextEncoder < "u")
|
|
517
|
-
return new TextEncoder().encode(e).length.toString();
|
|
518
|
-
} else if (ArrayBuffer.isView(e))
|
|
519
|
-
return e.byteLength.toString();
|
|
520
|
-
return null;
|
|
521
|
-
}
|
|
522
|
-
async buildRequest(e, { retryCount: n = 0 } = {}) {
|
|
523
|
-
const r = { ...e }, { method: s, path: o, query: i, defaultBaseURL: l, headers: c = {} } = r, u = ArrayBuffer.isView(r.body) || r.__binaryRequest && typeof r.body == "string" ? r.body : ye(r.body) ? r.body.body : r.body ? JSON.stringify(r.body, null, 2) : null, p = this.calculateContentLength(u), a = this.buildURL(o, i, l);
|
|
524
|
-
"timeout" in r && G("timeout", r.timeout), r.timeout = r.timeout ?? this.timeout;
|
|
525
|
-
const h = r.httpAgent ?? this.httpAgent ?? Ye(a), m = r.timeout + 1e3;
|
|
526
|
-
typeof h?.options?.timeout == "number" && m > (h.options.timeout ?? 0) && (h.options.timeout = m), this.idempotencyHeader && s !== "get" && (e.idempotencyKey || (e.idempotencyKey = this.defaultIdempotencyKey()), c[this.idempotencyHeader] = e.idempotencyKey);
|
|
527
|
-
const b = this.buildHeaders({ options: r, headers: c, contentLength: p, retryCount: n });
|
|
528
|
-
return { req: {
|
|
529
|
-
method: s,
|
|
530
|
-
...u && { body: u },
|
|
531
|
-
headers: b,
|
|
532
|
-
...h && { agent: h },
|
|
533
|
-
// @ts-ignore node-fetch uses a custom AbortSignal type that is
|
|
534
|
-
// not compatible with standard web types
|
|
535
|
-
signal: r.signal ?? null
|
|
536
|
-
}, url: a, timeout: r.timeout };
|
|
537
|
-
}
|
|
538
|
-
buildHeaders({ options: e, headers: n, contentLength: r, retryCount: s }) {
|
|
539
|
-
const o = {};
|
|
540
|
-
r && (o["content-length"] = r);
|
|
541
|
-
const i = this.defaultHeaders(e);
|
|
542
|
-
return be(o, i), be(o, n), ye(e.body) && _e !== "node" && delete o["content-type"], N(i, "x-stainless-retry-count") === void 0 && N(n, "x-stainless-retry-count") === void 0 && (o["x-stainless-retry-count"] = String(s)), N(i, "x-stainless-timeout") === void 0 && N(n, "x-stainless-timeout") === void 0 && e.timeout && (o["x-stainless-timeout"] = String(Math.trunc(e.timeout / 1e3))), this.validateHeaders(o, n), o;
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* Used as a callback for mutating the given `FinalRequestOptions` object.
|
|
546
|
-
*/
|
|
547
|
-
async prepareOptions(e) {
|
|
548
|
-
}
|
|
549
|
-
/**
|
|
550
|
-
* Used as a callback for mutating the given `RequestInit` object.
|
|
551
|
-
*
|
|
552
|
-
* This is useful for cases where you want to add certain headers based off of
|
|
553
|
-
* the request properties, e.g. `method` or `url`.
|
|
554
|
-
*/
|
|
555
|
-
async prepareRequest(e, { url: n, options: r }) {
|
|
556
|
-
}
|
|
557
|
-
parseHeaders(e) {
|
|
558
|
-
return e ? Symbol.iterator in e ? Object.fromEntries(Array.from(e).map((n) => [...n])) : { ...e } : {};
|
|
559
|
-
}
|
|
560
|
-
makeStatusError(e, n, r, s) {
|
|
561
|
-
return w.generate(e, n, r, s);
|
|
562
|
-
}
|
|
563
|
-
request(e, n = null) {
|
|
564
|
-
return new B(this.makeRequest(e, n));
|
|
565
|
-
}
|
|
566
|
-
async makeRequest(e, n) {
|
|
567
|
-
const r = await e, s = r.maxRetries ?? this.maxRetries;
|
|
568
|
-
n == null && (n = s), await this.prepareOptions(r);
|
|
569
|
-
const { req: o, url: i, timeout: l } = await this.buildRequest(r, {
|
|
570
|
-
retryCount: s - n
|
|
571
|
-
});
|
|
572
|
-
if (await this.prepareRequest(o, { url: i, options: r }), L("request", i, r, o.headers), r.signal?.aborted)
|
|
573
|
-
throw new Z();
|
|
574
|
-
const c = new AbortController(), u = await this.fetchWithTimeout(i, o, l, c).catch(ee);
|
|
575
|
-
if (u instanceof Error) {
|
|
576
|
-
if (r.signal?.aborted)
|
|
577
|
-
throw new Z();
|
|
578
|
-
if (n)
|
|
579
|
-
return this.retryRequest(r, n);
|
|
580
|
-
throw u.name === "AbortError" ? new Ee() : new F({ cause: u });
|
|
581
|
-
}
|
|
582
|
-
const p = _t(u.headers);
|
|
583
|
-
if (!u.ok) {
|
|
584
|
-
if (n && this.shouldRetry(u)) {
|
|
585
|
-
const S = `retrying, ${n} attempts remaining`;
|
|
586
|
-
return L(`response (error; ${S})`, u.status, i, p), this.retryRequest(r, n, p);
|
|
587
|
-
}
|
|
588
|
-
const a = await u.text().catch((S) => ee(S).message), h = Pt(a), m = h ? void 0 : a;
|
|
589
|
-
throw L(`response (error; ${n ? "(error; no more retries left)" : "(error; not retryable)"})`, u.status, i, p, m), this.makeStatusError(u.status, h, m, p);
|
|
590
|
-
}
|
|
591
|
-
return { response: u, options: r, controller: c };
|
|
592
|
-
}
|
|
593
|
-
requestAPIList(e, n) {
|
|
594
|
-
const r = this.makeRequest(n, null);
|
|
595
|
-
return new bt(this, r, e);
|
|
596
|
-
}
|
|
597
|
-
buildURL(e, n, r) {
|
|
598
|
-
const s = !$e(this, M, "f") && r || this.baseURL, o = Tt(e) ? new URL(e) : new URL(s + (s.endsWith("/") && e.startsWith("/") ? e.slice(1) : e)), i = this.defaultQuery();
|
|
599
|
-
return Ne(i) || (n = { ...i, ...n }), typeof n == "object" && n && !Array.isArray(n) && (o.search = this.stringifyQuery(n)), o.toString();
|
|
600
|
-
}
|
|
601
|
-
stringifyQuery(e) {
|
|
602
|
-
return Object.entries(e).filter(([n, r]) => typeof r < "u").map(([n, r]) => {
|
|
603
|
-
if (typeof r == "string" || typeof r == "number" || typeof r == "boolean")
|
|
604
|
-
return `${encodeURIComponent(n)}=${encodeURIComponent(r)}`;
|
|
605
|
-
if (r === null)
|
|
606
|
-
return `${encodeURIComponent(n)}=`;
|
|
607
|
-
throw new P(`Cannot stringify type ${typeof r}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`);
|
|
608
|
-
}).join("&");
|
|
609
|
-
}
|
|
610
|
-
async fetchWithTimeout(e, n, r, s) {
|
|
611
|
-
const { signal: o, ...i } = n || {};
|
|
612
|
-
o && o.addEventListener("abort", () => s.abort());
|
|
613
|
-
const l = setTimeout(() => s.abort(), r), c = {
|
|
614
|
-
signal: s.signal,
|
|
615
|
-
...i
|
|
616
|
-
};
|
|
617
|
-
return c.method && (c.method = c.method.toUpperCase()), // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
|
|
618
|
-
this.fetch.call(void 0, e, c).finally(() => {
|
|
619
|
-
clearTimeout(l);
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
shouldRetry(e) {
|
|
623
|
-
const n = e.headers.get("x-should-retry");
|
|
624
|
-
return n === "true" ? !0 : n === "false" ? !1 : e.status === 408 || e.status === 409 || e.status === 429 || e.status >= 500;
|
|
625
|
-
}
|
|
626
|
-
async retryRequest(e, n, r) {
|
|
627
|
-
let s;
|
|
628
|
-
const o = r?.["retry-after-ms"];
|
|
629
|
-
if (o) {
|
|
630
|
-
const l = parseFloat(o);
|
|
631
|
-
Number.isNaN(l) || (s = l);
|
|
632
|
-
}
|
|
633
|
-
const i = r?.["retry-after"];
|
|
634
|
-
if (i && !s) {
|
|
635
|
-
const l = parseFloat(i);
|
|
636
|
-
Number.isNaN(l) ? s = Date.parse(i) - Date.now() : s = l * 1e3;
|
|
637
|
-
}
|
|
638
|
-
if (!(s && 0 <= s && s < 60 * 1e3)) {
|
|
639
|
-
const l = e.maxRetries ?? this.maxRetries;
|
|
640
|
-
s = this.calculateDefaultRetryTimeoutMillis(n, l);
|
|
641
|
-
}
|
|
642
|
-
return await Ct(s), this.makeRequest(e, n - 1);
|
|
643
|
-
}
|
|
644
|
-
calculateDefaultRetryTimeoutMillis(e, n) {
|
|
645
|
-
const o = n - e, i = Math.min(0.5 * Math.pow(2, o), 8), l = 1 - Math.random() * 0.25;
|
|
646
|
-
return i * l * 1e3;
|
|
647
|
-
}
|
|
648
|
-
getUserAgent() {
|
|
649
|
-
return `${this.constructor.name}/JS ${T}`;
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
M = /* @__PURE__ */ new WeakMap();
|
|
653
|
-
class xt {
|
|
654
|
-
constructor(e, n, r, s) {
|
|
655
|
-
j.set(this, void 0), Ue(this, j, e, "f"), this.options = s, this.response = n, this.body = r;
|
|
656
|
-
}
|
|
657
|
-
hasNextPage() {
|
|
658
|
-
return this.getPaginatedItems().length ? this.nextPageInfo() != null : !1;
|
|
659
|
-
}
|
|
660
|
-
async getNextPage() {
|
|
661
|
-
const e = this.nextPageInfo();
|
|
662
|
-
if (!e)
|
|
663
|
-
throw new P("No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.");
|
|
664
|
-
const n = { ...this.options };
|
|
665
|
-
if ("params" in e && typeof n.query == "object")
|
|
666
|
-
n.query = { ...n.query, ...e.params };
|
|
667
|
-
else if ("url" in e) {
|
|
668
|
-
const r = [...Object.entries(n.query || {}), ...e.url.searchParams.entries()];
|
|
669
|
-
for (const [s, o] of r)
|
|
670
|
-
e.url.searchParams.set(s, o);
|
|
671
|
-
n.query = void 0, n.path = e.url.toString();
|
|
672
|
-
}
|
|
673
|
-
return await $e(this, j, "f").requestAPIList(this.constructor, n);
|
|
674
|
-
}
|
|
675
|
-
async *iterPages() {
|
|
676
|
-
let e = this;
|
|
677
|
-
for (yield e; e.hasNextPage(); )
|
|
678
|
-
e = await e.getNextPage(), yield e;
|
|
679
|
-
}
|
|
680
|
-
async *[(j = /* @__PURE__ */ new WeakMap(), Symbol.asyncIterator)]() {
|
|
681
|
-
for await (const e of this.iterPages())
|
|
682
|
-
for (const n of e.getPaginatedItems())
|
|
683
|
-
yield n;
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
class bt extends B {
|
|
687
|
-
constructor(e, n, r) {
|
|
688
|
-
super(n, async (s) => new r(e, s.response, await je(s), s.options));
|
|
689
|
-
}
|
|
690
|
-
/**
|
|
691
|
-
* Allow auto-paginating iteration on an unawaited list call, eg:
|
|
692
|
-
*
|
|
693
|
-
* for await (const item of client.items.list()) {
|
|
694
|
-
* console.log(item)
|
|
695
|
-
* }
|
|
696
|
-
*/
|
|
697
|
-
async *[Symbol.asyncIterator]() {
|
|
698
|
-
const e = await this;
|
|
699
|
-
for await (const n of e)
|
|
700
|
-
yield n;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
const _t = (t) => new Proxy(Object.fromEntries(
|
|
704
|
-
// @ts-ignore
|
|
705
|
-
t.entries()
|
|
706
|
-
), {
|
|
707
|
-
get(e, n) {
|
|
708
|
-
const r = n.toString();
|
|
709
|
-
return e[r.toLowerCase()] || e[r];
|
|
710
|
-
}
|
|
711
|
-
}), At = {
|
|
712
|
-
method: !0,
|
|
713
|
-
path: !0,
|
|
714
|
-
query: !0,
|
|
715
|
-
body: !0,
|
|
716
|
-
headers: !0,
|
|
717
|
-
defaultBaseURL: !0,
|
|
718
|
-
maxRetries: !0,
|
|
719
|
-
stream: !0,
|
|
720
|
-
timeout: !0,
|
|
721
|
-
httpAgent: !0,
|
|
722
|
-
signal: !0,
|
|
723
|
-
idempotencyKey: !0,
|
|
724
|
-
__binaryRequest: !0,
|
|
725
|
-
__binaryResponse: !0
|
|
726
|
-
}, R = (t) => typeof t == "object" && t !== null && !Ne(t) && Object.keys(t).every((e) => Me(At, e)), St = () => {
|
|
727
|
-
if (typeof Deno < "u" && Deno.build != null)
|
|
728
|
-
return {
|
|
729
|
-
"X-Stainless-Lang": "js",
|
|
730
|
-
"X-Stainless-Package-Version": T,
|
|
731
|
-
"X-Stainless-OS": ge(Deno.build.os),
|
|
732
|
-
"X-Stainless-Arch": me(Deno.build.arch),
|
|
733
|
-
"X-Stainless-Runtime": "deno",
|
|
734
|
-
"X-Stainless-Runtime-Version": typeof Deno.version == "string" ? Deno.version : Deno.version?.deno ?? "unknown"
|
|
735
|
-
};
|
|
736
|
-
if (typeof EdgeRuntime < "u")
|
|
737
|
-
return {
|
|
738
|
-
"X-Stainless-Lang": "js",
|
|
739
|
-
"X-Stainless-Package-Version": T,
|
|
740
|
-
"X-Stainless-OS": "Unknown",
|
|
741
|
-
"X-Stainless-Arch": `other:${EdgeRuntime}`,
|
|
742
|
-
"X-Stainless-Runtime": "edge",
|
|
743
|
-
"X-Stainless-Runtime-Version": process.version
|
|
744
|
-
};
|
|
745
|
-
if (Object.prototype.toString.call(typeof process < "u" ? process : 0) === "[object process]")
|
|
746
|
-
return {
|
|
747
|
-
"X-Stainless-Lang": "js",
|
|
748
|
-
"X-Stainless-Package-Version": T,
|
|
749
|
-
"X-Stainless-OS": ge(process.platform),
|
|
750
|
-
"X-Stainless-Arch": me(process.arch),
|
|
751
|
-
"X-Stainless-Runtime": "node",
|
|
752
|
-
"X-Stainless-Runtime-Version": process.version
|
|
753
|
-
};
|
|
754
|
-
const t = Rt();
|
|
755
|
-
return t ? {
|
|
756
|
-
"X-Stainless-Lang": "js",
|
|
757
|
-
"X-Stainless-Package-Version": T,
|
|
758
|
-
"X-Stainless-OS": "Unknown",
|
|
759
|
-
"X-Stainless-Arch": "unknown",
|
|
760
|
-
"X-Stainless-Runtime": `browser:${t.browser}`,
|
|
761
|
-
"X-Stainless-Runtime-Version": t.version
|
|
762
|
-
} : {
|
|
763
|
-
"X-Stainless-Lang": "js",
|
|
764
|
-
"X-Stainless-Package-Version": T,
|
|
765
|
-
"X-Stainless-OS": "Unknown",
|
|
766
|
-
"X-Stainless-Arch": "unknown",
|
|
767
|
-
"X-Stainless-Runtime": "unknown",
|
|
768
|
-
"X-Stainless-Runtime-Version": "unknown"
|
|
769
|
-
};
|
|
770
|
-
};
|
|
771
|
-
function Rt() {
|
|
772
|
-
if (typeof navigator > "u" || !navigator)
|
|
773
|
-
return null;
|
|
774
|
-
const t = [
|
|
775
|
-
{ key: "edge", pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
776
|
-
{ key: "ie", pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
777
|
-
{ key: "ie", pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
778
|
-
{ key: "chrome", pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
779
|
-
{ key: "firefox", pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
780
|
-
{ key: "safari", pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ }
|
|
781
|
-
];
|
|
782
|
-
for (const { key: e, pattern: n } of t) {
|
|
783
|
-
const r = n.exec(navigator.userAgent);
|
|
784
|
-
if (r) {
|
|
785
|
-
const s = r[1] || 0, o = r[2] || 0, i = r[3] || 0;
|
|
786
|
-
return { browser: e, version: `${s}.${o}.${i}` };
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
return null;
|
|
790
|
-
}
|
|
791
|
-
const me = (t) => t === "x32" ? "x32" : t === "x86_64" || t === "x64" ? "x64" : t === "arm" ? "arm" : t === "aarch64" || t === "arm64" ? "arm64" : t ? `other:${t}` : "unknown", ge = (t) => (t = t.toLowerCase(), t.includes("ios") ? "iOS" : t === "android" ? "Android" : t === "darwin" ? "MacOS" : t === "win32" ? "Windows" : t === "freebsd" ? "FreeBSD" : t === "openbsd" ? "OpenBSD" : t === "linux" ? "Linux" : t ? `Other:${t}` : "Unknown");
|
|
792
|
-
let we;
|
|
793
|
-
const Et = () => we ?? (we = St()), Pt = (t) => {
|
|
794
|
-
try {
|
|
795
|
-
return JSON.parse(t);
|
|
796
|
-
} catch {
|
|
797
|
-
return;
|
|
798
|
-
}
|
|
799
|
-
}, kt = /^[a-z][a-z0-9+.-]*:/i, Tt = (t) => kt.test(t), Ct = (t) => new Promise((e) => setTimeout(e, t)), G = (t, e) => {
|
|
800
|
-
if (typeof e != "number" || !Number.isInteger(e))
|
|
801
|
-
throw new P(`${t} must be an integer`);
|
|
802
|
-
if (e < 0)
|
|
803
|
-
throw new P(`${t} must be a positive integer`);
|
|
804
|
-
return e;
|
|
805
|
-
}, ee = (t) => {
|
|
806
|
-
if (t instanceof Error)
|
|
807
|
-
return t;
|
|
808
|
-
if (typeof t == "object" && t !== null)
|
|
809
|
-
try {
|
|
810
|
-
return new Error(JSON.stringify(t));
|
|
811
|
-
} catch {
|
|
812
|
-
}
|
|
813
|
-
return new Error(t);
|
|
814
|
-
}, xe = (t) => {
|
|
815
|
-
if (typeof process < "u")
|
|
816
|
-
return process.env?.[t]?.trim() ?? void 0;
|
|
817
|
-
if (typeof Deno < "u")
|
|
818
|
-
return Deno.env?.get?.(t)?.trim();
|
|
819
|
-
};
|
|
820
|
-
function Ne(t) {
|
|
821
|
-
if (!t)
|
|
822
|
-
return !0;
|
|
823
|
-
for (const e in t)
|
|
824
|
-
return !1;
|
|
825
|
-
return !0;
|
|
826
|
-
}
|
|
827
|
-
function Me(t, e) {
|
|
828
|
-
return Object.prototype.hasOwnProperty.call(t, e);
|
|
829
|
-
}
|
|
830
|
-
function be(t, e) {
|
|
831
|
-
for (const n in e) {
|
|
832
|
-
if (!Me(e, n))
|
|
833
|
-
continue;
|
|
834
|
-
const r = n.toLowerCase();
|
|
835
|
-
if (!r)
|
|
836
|
-
continue;
|
|
837
|
-
const s = e[n];
|
|
838
|
-
s === null ? delete t[r] : s !== void 0 && (t[r] = s);
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
function L(t, ...e) {
|
|
842
|
-
typeof process < "u" && process?.env?.DEBUG === "true" && console.log(`Arcade:DEBUG:${t}`, ...e);
|
|
843
|
-
}
|
|
844
|
-
const vt = () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (t) => {
|
|
845
|
-
const e = Math.random() * 16 | 0;
|
|
846
|
-
return (t === "x" ? e : e & 3 | 8).toString(16);
|
|
847
|
-
}), It = (t) => typeof t?.get == "function", N = (t, e) => {
|
|
848
|
-
const n = e.toLowerCase();
|
|
849
|
-
if (It(t)) {
|
|
850
|
-
const r = e[0]?.toUpperCase() + e.substring(1).replace(/([^\w])(\w)/g, (s, o, i) => o + i.toUpperCase());
|
|
851
|
-
for (const s of [e, n, e.toUpperCase(), r]) {
|
|
852
|
-
const o = t.get(s);
|
|
853
|
-
if (o)
|
|
854
|
-
return o;
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
for (const [r, s] of Object.entries(t))
|
|
858
|
-
if (r.toLowerCase() === n)
|
|
859
|
-
return Array.isArray(s) ? (s.length <= 1 || console.warn(`Received ${s.length} entries for the ${e} header, using the first entry.`), s[0]) : s;
|
|
860
|
-
};
|
|
861
|
-
class O extends xt {
|
|
862
|
-
constructor(e, n, r, s) {
|
|
863
|
-
super(e, n, r, s), this.items = r.items || [], this.total_count = r.total_count || 0, this.offset = r.offset || 0;
|
|
864
|
-
}
|
|
865
|
-
getPaginatedItems() {
|
|
866
|
-
return this.items ?? [];
|
|
867
|
-
}
|
|
868
|
-
// @deprecated Please use `nextPageInfo()` instead
|
|
869
|
-
nextPageParams() {
|
|
870
|
-
const e = this.nextPageInfo();
|
|
871
|
-
if (!e)
|
|
872
|
-
return null;
|
|
873
|
-
if ("params" in e)
|
|
874
|
-
return e.params;
|
|
875
|
-
const n = Object.fromEntries(e.url.searchParams);
|
|
876
|
-
return Object.keys(n).length ? n : null;
|
|
877
|
-
}
|
|
878
|
-
nextPageInfo() {
|
|
879
|
-
const e = this.offset;
|
|
880
|
-
if (!e)
|
|
881
|
-
return null;
|
|
882
|
-
const n = this.getPaginatedItems().length, r = e + n, s = this.total_count;
|
|
883
|
-
return s && r < s ? { params: { offset: r } } : null;
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
class x {
|
|
887
|
-
constructor(e) {
|
|
888
|
-
this._client = e;
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
class Fe extends x {
|
|
892
|
-
/**
|
|
893
|
-
* Create a new auth provider
|
|
894
|
-
*/
|
|
895
|
-
create(e, n) {
|
|
896
|
-
return this._client.post("/v1/admin/auth_providers", { body: e, ...n });
|
|
897
|
-
}
|
|
898
|
-
/**
|
|
899
|
-
* List a page of auth providers that are available to the caller
|
|
900
|
-
*/
|
|
901
|
-
list(e) {
|
|
902
|
-
return this._client.get("/v1/admin/auth_providers", e);
|
|
903
|
-
}
|
|
904
|
-
/**
|
|
905
|
-
* Delete a specific auth provider
|
|
906
|
-
*/
|
|
907
|
-
delete(e, n) {
|
|
908
|
-
return this._client.delete(`/v1/admin/auth_providers/${e}`, n);
|
|
909
|
-
}
|
|
910
|
-
/**
|
|
911
|
-
* Get the details of a specific auth provider
|
|
912
|
-
*/
|
|
913
|
-
get(e, n) {
|
|
914
|
-
return this._client.get(`/v1/admin/auth_providers/${e}`, n);
|
|
915
|
-
}
|
|
916
|
-
/**
|
|
917
|
-
* Patch an existing auth provider
|
|
918
|
-
*/
|
|
919
|
-
patch(e, n, r) {
|
|
920
|
-
return this._client.patch(`/v1/admin/auth_providers/${e}`, { body: n, ...r });
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
class qe extends x {
|
|
924
|
-
/**
|
|
925
|
-
* List all secrets that are visible to the caller
|
|
926
|
-
*/
|
|
927
|
-
list(e) {
|
|
928
|
-
return this._client.get("/v1/admin/secrets", e);
|
|
929
|
-
}
|
|
930
|
-
/**
|
|
931
|
-
* Delete a secret by its ID
|
|
932
|
-
*/
|
|
933
|
-
delete(e, n) {
|
|
934
|
-
return this._client.delete(`/v1/admin/secrets/${e}`, {
|
|
935
|
-
...n,
|
|
936
|
-
headers: { Accept: "*/*", ...n?.headers }
|
|
937
|
-
});
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
class te extends x {
|
|
941
|
-
list(e = {}, n) {
|
|
942
|
-
return R(e) ? this.list({}, e) : this._client.getAPIList("/v1/admin/user_connections", ne, {
|
|
943
|
-
query: e,
|
|
944
|
-
...n
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
/**
|
|
948
|
-
* Delete a user/auth provider connection
|
|
949
|
-
*/
|
|
950
|
-
delete(e, n) {
|
|
951
|
-
return this._client.delete(`/v1/admin/user_connections/${e}`, {
|
|
952
|
-
...n,
|
|
953
|
-
headers: { Accept: "*/*", ...n?.headers }
|
|
954
|
-
});
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
class ne extends O {
|
|
958
|
-
}
|
|
959
|
-
te.UserConnectionResponsesOffsetPage = ne;
|
|
960
|
-
class C extends x {
|
|
961
|
-
constructor() {
|
|
962
|
-
super(...arguments), this.userConnections = new te(this._client), this.authProviders = new Fe(this._client), this.secrets = new qe(this._client);
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
C.UserConnections = te;
|
|
966
|
-
C.UserConnectionResponsesOffsetPage = ne;
|
|
967
|
-
C.AuthProviders = Fe;
|
|
968
|
-
C.Secrets = qe;
|
|
969
|
-
const Lt = 45;
|
|
970
|
-
class Ot extends Error {
|
|
971
|
-
constructor(e) {
|
|
972
|
-
super(e), this.name = "AuthorizationError";
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
class Be extends x {
|
|
976
|
-
/**
|
|
977
|
-
* Starts the authorization process for a given provider and scopes.
|
|
978
|
-
* @param userId - The user ID for which authorization is being requested
|
|
979
|
-
* @param provider - The authorization provider (e.g., 'github', 'google', 'linkedin', 'microsoft', 'slack', 'spotify', 'x', 'zoom')
|
|
980
|
-
* @param options - Optional parameters
|
|
981
|
-
* @param options.providerType - The type of authorization provider. Defaults to 'oauth2'
|
|
982
|
-
* @param options.scopes - A list of scopes required for authorization, if any. Defaults to []
|
|
983
|
-
* @returns The authorization response
|
|
984
|
-
*
|
|
985
|
-
* Example:
|
|
986
|
-
* ```ts
|
|
987
|
-
* const authResponse = await client.auth.start("user@example.com", "github");
|
|
988
|
-
* ```
|
|
989
|
-
*/
|
|
990
|
-
start(e, n, r = {}) {
|
|
991
|
-
const { providerType: s = "oauth2", scopes: o = [] } = r, i = {
|
|
992
|
-
provider_id: n,
|
|
993
|
-
provider_type: s,
|
|
994
|
-
oauth2: {
|
|
995
|
-
scopes: o
|
|
996
|
-
}
|
|
997
|
-
};
|
|
998
|
-
return this.authorize({
|
|
999
|
-
auth_requirement: i,
|
|
1000
|
-
user_id: e
|
|
1001
|
-
});
|
|
1002
|
-
}
|
|
1003
|
-
/**
|
|
1004
|
-
* Starts the authorization process for given authorization requirements
|
|
1005
|
-
*/
|
|
1006
|
-
authorize(e, n) {
|
|
1007
|
-
return this._client.post("/v1/auth/authorize", { body: e, ...n });
|
|
1008
|
-
}
|
|
1009
|
-
/**
|
|
1010
|
-
* Confirms a user's details during an authorization flow
|
|
1011
|
-
*/
|
|
1012
|
-
confirmUser(e, n) {
|
|
1013
|
-
return this._client.post("/v1/auth/confirm_user", { body: e, ...n });
|
|
1014
|
-
}
|
|
1015
|
-
/**
|
|
1016
|
-
* Checks the status of an ongoing authorization process for a specific tool. If
|
|
1017
|
-
* 'wait' param is present, does not respond until either the auth status becomes
|
|
1018
|
-
* completed or the timeout is reached.
|
|
1019
|
-
*/
|
|
1020
|
-
status(e, n) {
|
|
1021
|
-
return this._client.get("/v1/auth/status", { query: e, ...n });
|
|
1022
|
-
}
|
|
1023
|
-
/**
|
|
1024
|
-
* Waits for the authorization process to complete.
|
|
1025
|
-
* @param authResponseOrId - The authorization response or ID to wait for completion
|
|
1026
|
-
* @returns The completed authorization response
|
|
1027
|
-
* @throws {AuthorizationError} When the authorization ID is missing or invalid
|
|
1028
|
-
*
|
|
1029
|
-
* Example:
|
|
1030
|
-
* ```ts
|
|
1031
|
-
* const authResponse = await client.auth.start("user@example.com", "github");
|
|
1032
|
-
* try {
|
|
1033
|
-
* const completedAuth = await client.auth.waitForCompletion(authResponse);
|
|
1034
|
-
* console.log('Authorization completed:', completedAuth);
|
|
1035
|
-
* } catch (error) {
|
|
1036
|
-
* if (error instanceof AuthorizationError) {
|
|
1037
|
-
* console.error('Authorization failed:', error.message);
|
|
1038
|
-
* }
|
|
1039
|
-
* }
|
|
1040
|
-
* ```
|
|
1041
|
-
*/
|
|
1042
|
-
async waitForCompletion(e) {
|
|
1043
|
-
let n, r;
|
|
1044
|
-
if (typeof e == "string")
|
|
1045
|
-
n = e, r = { status: "pending" };
|
|
1046
|
-
else {
|
|
1047
|
-
if (!e.id)
|
|
1048
|
-
throw new Ot("Authorization ID is required");
|
|
1049
|
-
n = e.id, r = e;
|
|
1050
|
-
}
|
|
1051
|
-
for (; r.status !== "completed"; )
|
|
1052
|
-
r = await this.status({
|
|
1053
|
-
id: n,
|
|
1054
|
-
wait: Lt
|
|
1055
|
-
});
|
|
1056
|
-
return r;
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
class He extends x {
|
|
1060
|
-
/**
|
|
1061
|
-
* Talk to different LLM Chat APIs via OpenAI's API
|
|
1062
|
-
*/
|
|
1063
|
-
create(e, n) {
|
|
1064
|
-
return this._client.post("/v1/chat/completions", { body: e, ...n });
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
class re extends x {
|
|
1068
|
-
constructor() {
|
|
1069
|
-
super(...arguments), this.completions = new He(this._client);
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
re.Completions = He;
|
|
1073
|
-
class ze extends x {
|
|
1074
|
-
/**
|
|
1075
|
-
* Engine Health
|
|
1076
|
-
*/
|
|
1077
|
-
check(e) {
|
|
1078
|
-
return this._client.get("/v1/health", e);
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
class se extends x {
|
|
1082
|
-
list(e = {}, n) {
|
|
1083
|
-
return R(e) ? this.list({}, e) : this._client.getAPIList("/v1/formatted_tools", oe, {
|
|
1084
|
-
query: e,
|
|
1085
|
-
...n
|
|
1086
|
-
});
|
|
1087
|
-
}
|
|
1088
|
-
get(e, n = {}, r) {
|
|
1089
|
-
return R(n) ? this.get(e, {}, n) : this._client.get(`/v1/formatted_tools/${e}`, { query: n, ...r });
|
|
1090
|
-
}
|
|
1091
|
-
}
|
|
1092
|
-
class oe extends O {
|
|
1093
|
-
}
|
|
1094
|
-
se.FormattedListResponsesOffsetPage = oe;
|
|
1095
|
-
class Xe extends x {
|
|
1096
|
-
list(e = {}, n) {
|
|
1097
|
-
return R(e) ? this.list({}, e) : this._client.getAPIList("/v1/scheduled_tools", Dt, { query: e, ...n });
|
|
1098
|
-
}
|
|
1099
|
-
/**
|
|
1100
|
-
* Returns the details for a specific scheduled tool execution
|
|
1101
|
-
*/
|
|
1102
|
-
get(e, n) {
|
|
1103
|
-
return this._client.get(`/v1/scheduled_tools/${e}`, n);
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
class v extends x {
|
|
1107
|
-
constructor() {
|
|
1108
|
-
super(...arguments), this.scheduled = new Xe(this._client), this.formatted = new se(this._client);
|
|
1109
|
-
}
|
|
1110
|
-
list(e = {}, n) {
|
|
1111
|
-
return R(e) ? this.list({}, e) : this._client.getAPIList("/v1/tools", H, { query: e, ...n });
|
|
1112
|
-
}
|
|
1113
|
-
/**
|
|
1114
|
-
* Authorizes a user for a specific tool by name
|
|
1115
|
-
*/
|
|
1116
|
-
authorize(e, n) {
|
|
1117
|
-
return this._client.post("/v1/tools/authorize", { body: e, ...n });
|
|
1118
|
-
}
|
|
1119
|
-
/**
|
|
1120
|
-
* Executes a tool by name and arguments
|
|
1121
|
-
*/
|
|
1122
|
-
execute(e, n) {
|
|
1123
|
-
return this._client.post("/v1/tools/execute", { body: e, ...n });
|
|
1124
|
-
}
|
|
1125
|
-
get(e, n = {}, r) {
|
|
1126
|
-
return R(n) ? this.get(e, {}, n) : this._client.get(`/v1/tools/${e}`, { query: n, ...r });
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
class H extends O {
|
|
1130
|
-
}
|
|
1131
|
-
class Dt extends O {
|
|
1132
|
-
}
|
|
1133
|
-
v.ToolDefinitionsOffsetPage = H;
|
|
1134
|
-
v.Scheduled = Xe;
|
|
1135
|
-
v.Formatted = se;
|
|
1136
|
-
v.FormattedListResponsesOffsetPage = oe;
|
|
1137
|
-
class ie extends x {
|
|
1138
|
-
/**
|
|
1139
|
-
* Create a worker
|
|
1140
|
-
*/
|
|
1141
|
-
create(e, n) {
|
|
1142
|
-
return this._client.post("/v1/workers", { body: e, ...n });
|
|
1143
|
-
}
|
|
1144
|
-
/**
|
|
1145
|
-
* Update a worker
|
|
1146
|
-
*/
|
|
1147
|
-
update(e, n, r) {
|
|
1148
|
-
return this._client.patch(`/v1/workers/${e}`, { body: n, ...r });
|
|
1149
|
-
}
|
|
1150
|
-
list(e = {}, n) {
|
|
1151
|
-
return R(e) ? this.list({}, e) : this._client.getAPIList("/v1/workers", ae, { query: e, ...n });
|
|
1152
|
-
}
|
|
1153
|
-
/**
|
|
1154
|
-
* Delete a worker
|
|
1155
|
-
*/
|
|
1156
|
-
delete(e, n) {
|
|
1157
|
-
return this._client.delete(`/v1/workers/${e}`, {
|
|
1158
|
-
...n,
|
|
1159
|
-
headers: { Accept: "*/*", ...n?.headers }
|
|
1160
|
-
});
|
|
1161
|
-
}
|
|
1162
|
-
/**
|
|
1163
|
-
* Get a worker by ID
|
|
1164
|
-
*/
|
|
1165
|
-
get(e, n) {
|
|
1166
|
-
return this._client.get(`/v1/workers/${e}`, n);
|
|
1167
|
-
}
|
|
1168
|
-
/**
|
|
1169
|
-
* Get the health of a worker
|
|
1170
|
-
*/
|
|
1171
|
-
health(e, n) {
|
|
1172
|
-
return this._client.get(`/v1/workers/${e}/health`, n);
|
|
1173
|
-
}
|
|
1174
|
-
tools(e, n = {}, r) {
|
|
1175
|
-
return R(n) ? this.tools(e, {}, n) : this._client.getAPIList(`/v1/workers/${e}/tools`, H, {
|
|
1176
|
-
query: n,
|
|
1177
|
-
...r
|
|
1178
|
-
});
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
class ae extends O {
|
|
1182
|
-
}
|
|
1183
|
-
ie.WorkerResponsesOffsetPage = ae;
|
|
1184
|
-
var Ke, We;
|
|
1185
|
-
class d extends wt {
|
|
1186
|
-
/**
|
|
1187
|
-
* API Client for interfacing with the Arcade API.
|
|
1188
|
-
*
|
|
1189
|
-
* @param {string | undefined} [opts.apiKey=process.env['ARCADE_API_KEY'] ?? undefined]
|
|
1190
|
-
* @param {string} [opts.baseURL=process.env['ARCADE_BASE_URL'] ?? https://api.arcade.dev] - Override the default base URL for the API.
|
|
1191
|
-
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
1192
|
-
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
|
|
1193
|
-
* @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
1194
|
-
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
|
|
1195
|
-
* @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
|
|
1196
|
-
* @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
1197
|
-
*/
|
|
1198
|
-
constructor({ baseURL: e = xe("ARCADE_BASE_URL"), apiKey: n = xe("ARCADE_API_KEY"), ...r } = {}) {
|
|
1199
|
-
if (n === void 0)
|
|
1200
|
-
throw new P("The ARCADE_API_KEY environment variable is missing or empty; either provide it, or instantiate the Arcade client with an apiKey option, like new Arcade({ apiKey: 'My API Key' }).");
|
|
1201
|
-
const s = {
|
|
1202
|
-
apiKey: n,
|
|
1203
|
-
...r,
|
|
1204
|
-
baseURL: e || "https://api.arcade.dev"
|
|
1205
|
-
};
|
|
1206
|
-
super({
|
|
1207
|
-
baseURL: s.baseURL,
|
|
1208
|
-
baseURLOverridden: e ? e !== "https://api.arcade.dev" : !1,
|
|
1209
|
-
timeout: s.timeout ?? 6e4,
|
|
1210
|
-
httpAgent: s.httpAgent,
|
|
1211
|
-
maxRetries: s.maxRetries,
|
|
1212
|
-
fetch: s.fetch
|
|
1213
|
-
}), Ke.add(this), this.admin = new C(this), this.auth = new Be(this), this.health = new ze(this), this.chat = new re(this), this.tools = new v(this), this.workers = new ie(this), this._options = s, this.idempotencyHeader = "Idempotency-Key", this.apiKey = n;
|
|
1214
|
-
}
|
|
1215
|
-
defaultQuery() {
|
|
1216
|
-
return this._options.defaultQuery;
|
|
1217
|
-
}
|
|
1218
|
-
defaultHeaders(e) {
|
|
1219
|
-
return {
|
|
1220
|
-
...super.defaultHeaders(e),
|
|
1221
|
-
...this._options.defaultHeaders
|
|
1222
|
-
};
|
|
1223
|
-
}
|
|
1224
|
-
authHeaders(e) {
|
|
1225
|
-
return { Authorization: this.apiKey };
|
|
1226
|
-
}
|
|
1227
|
-
stringifyQuery(e) {
|
|
1228
|
-
return lt(e, { arrayFormat: "comma" });
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
We = d, Ke = /* @__PURE__ */ new WeakSet();
|
|
1232
|
-
d.Arcade = We;
|
|
1233
|
-
d.DEFAULT_TIMEOUT = 6e4;
|
|
1234
|
-
d.ArcadeError = P;
|
|
1235
|
-
d.APIError = w;
|
|
1236
|
-
d.APIConnectionError = F;
|
|
1237
|
-
d.APIConnectionTimeoutError = Ee;
|
|
1238
|
-
d.APIUserAbortError = Z;
|
|
1239
|
-
d.NotFoundError = Ce;
|
|
1240
|
-
d.ConflictError = ve;
|
|
1241
|
-
d.RateLimitError = Le;
|
|
1242
|
-
d.BadRequestError = Pe;
|
|
1243
|
-
d.AuthenticationError = ke;
|
|
1244
|
-
d.InternalServerError = Oe;
|
|
1245
|
-
d.PermissionDeniedError = Te;
|
|
1246
|
-
d.UnprocessableEntityError = Ie;
|
|
1247
|
-
d.toFile = ht;
|
|
1248
|
-
d.fileFromPath = Ze;
|
|
1249
|
-
d.Admin = C;
|
|
1250
|
-
d.Auth = Be;
|
|
1251
|
-
d.Health = ze;
|
|
1252
|
-
d.Chat = re;
|
|
1253
|
-
d.Tools = v;
|
|
1254
|
-
d.ToolDefinitionsOffsetPage = H;
|
|
1255
|
-
d.Workers = ie;
|
|
1256
|
-
d.WorkerResponsesOffsetPage = ae;
|
|
1257
|
-
const Ut = /[._\-\s]+/, $t = /([a-z])([A-Z])/g, jt = /\s+/;
|
|
1258
|
-
class qt {
|
|
1259
|
-
#e;
|
|
1260
|
-
constructor(e) {
|
|
1261
|
-
const { accessToken: n, apiKey: r, arcadeClientId: s, baseURL: o } = e, i = r ?? he("ARCADE_API_KEY"), l = !!i, c = {};
|
|
1262
|
-
s && (c["Arcade-Client-Id"] = s), !l && n && (c.Authorization = `Bearer ${n}`);
|
|
1263
|
-
const u = {
|
|
1264
|
-
baseURL: o ?? he("ARCADE_BASE_URL"),
|
|
1265
|
-
defaultHeaders: c,
|
|
1266
|
-
apiKey: i ?? ""
|
|
1267
|
-
};
|
|
1268
|
-
this.#e = new d(u);
|
|
1269
|
-
}
|
|
1270
|
-
static create(e) {
|
|
1271
|
-
return new d(e);
|
|
1272
|
-
}
|
|
1273
|
-
async getAllTools(e = {}) {
|
|
1274
|
-
const { limit: n = 1e3, offset: r = 0, toolkit: s } = e;
|
|
1275
|
-
return (await this.#e.tools.list({
|
|
1276
|
-
limit: n,
|
|
1277
|
-
offset: r,
|
|
1278
|
-
toolkit: s
|
|
1279
|
-
})).items;
|
|
1280
|
-
}
|
|
1281
|
-
async groupToolsBy(e) {
|
|
1282
|
-
const n = await this.getAllTools(), r = /* @__PURE__ */ new Map();
|
|
1283
|
-
for (const s of n) {
|
|
1284
|
-
const o = s[e];
|
|
1285
|
-
typeof o == "string" && r.set(o, s);
|
|
1286
|
-
}
|
|
1287
|
-
return r;
|
|
1288
|
-
}
|
|
1289
|
-
async getToolkits() {
|
|
1290
|
-
const e = await this.getAllTools(), n = /* @__PURE__ */ new Map();
|
|
1291
|
-
for (const r of e) {
|
|
1292
|
-
const s = r.toolkit.name;
|
|
1293
|
-
let o = n.get(s);
|
|
1294
|
-
o || (o = {
|
|
1295
|
-
...r.toolkit,
|
|
1296
|
-
tools: [],
|
|
1297
|
-
requirements: {
|
|
1298
|
-
met: !0,
|
|
1299
|
-
secrets: [],
|
|
1300
|
-
authorization: [],
|
|
1301
|
-
scopes: {}
|
|
1302
|
-
}
|
|
1303
|
-
}, n.set(s, o)), o.tools.push(r), r.requirements && this.applyToolRequirements(o, r.requirements);
|
|
1304
|
-
}
|
|
1305
|
-
return n;
|
|
1306
|
-
}
|
|
1307
|
-
async getToolsForToolkit(e) {
|
|
1308
|
-
return (await this.#e.tools.list({
|
|
1309
|
-
toolkit: e,
|
|
1310
|
-
limit: 1e3
|
|
1311
|
-
})).items;
|
|
1312
|
-
}
|
|
1313
|
-
applyToolRequirements(e, n) {
|
|
1314
|
-
if (!n)
|
|
1315
|
-
return;
|
|
1316
|
-
e.requirements.secrets = this.mergeSecrets(
|
|
1317
|
-
n.secrets ?? [],
|
|
1318
|
-
e.requirements.secrets ?? []
|
|
1319
|
-
), e.requirements.authorization = this.mergeAuthorizations(
|
|
1320
|
-
n.authorization,
|
|
1321
|
-
e.requirements.authorization ?? []
|
|
1322
|
-
);
|
|
1323
|
-
const r = n.authorization?.provider_id, s = n.authorization?.oauth2?.scopes ?? [];
|
|
1324
|
-
r && s.length && (e.requirements.scopes = this.mergeScopes(
|
|
1325
|
-
r,
|
|
1326
|
-
s,
|
|
1327
|
-
e.requirements.scopes ?? {}
|
|
1328
|
-
)), e.requirements.met = !!(e.requirements.met && (n.met ?? !0));
|
|
1329
|
-
}
|
|
1330
|
-
mergeSecrets(e = [], n = []) {
|
|
1331
|
-
if (e.length === 0)
|
|
1332
|
-
return n;
|
|
1333
|
-
const r = /* @__PURE__ */ new Map();
|
|
1334
|
-
for (const s of n)
|
|
1335
|
-
r.set(s.key, { ...s });
|
|
1336
|
-
for (const s of e) {
|
|
1337
|
-
const o = r.get(s.key);
|
|
1338
|
-
if (!o) {
|
|
1339
|
-
r.set(s.key, { ...s });
|
|
1340
|
-
continue;
|
|
1341
|
-
}
|
|
1342
|
-
const i = !!(o.met || s.met), l = s.status_reason ?? o.status_reason;
|
|
1343
|
-
r.set(s.key, { key: s.key, met: i, status_reason: l });
|
|
1344
|
-
}
|
|
1345
|
-
return Array.from(r.values());
|
|
1346
|
-
}
|
|
1347
|
-
mergeAuthorizations(e, n = []) {
|
|
1348
|
-
if (!e?.provider_id)
|
|
1349
|
-
return n;
|
|
1350
|
-
const r = new Map(n.map((i) => [i.provider_id, { ...i }])), s = r.get(e.provider_id);
|
|
1351
|
-
if (!s)
|
|
1352
|
-
return r.set(e.provider_id, { ...e }), Array.from(r.values());
|
|
1353
|
-
const o = new Set(s.oauth2?.scopes ?? []);
|
|
1354
|
-
for (const i of e.oauth2?.scopes ?? [])
|
|
1355
|
-
o.add(i);
|
|
1356
|
-
return r.set(e.provider_id, {
|
|
1357
|
-
...s,
|
|
1358
|
-
oauth2: {
|
|
1359
|
-
...s.oauth2 ?? {},
|
|
1360
|
-
scopes: Array.from(o)
|
|
1361
|
-
}
|
|
1362
|
-
}), Array.from(r.values());
|
|
1363
|
-
}
|
|
1364
|
-
mergeScopes(e, n = [], r = {}) {
|
|
1365
|
-
if (!e || n.length === 0)
|
|
1366
|
-
return r;
|
|
1367
|
-
const s = new Set(r[e] ?? []);
|
|
1368
|
-
for (const o of n)
|
|
1369
|
-
s.add(o);
|
|
1370
|
-
return { ...r, [e]: Array.from(s) };
|
|
1371
|
-
}
|
|
1372
|
-
/**
|
|
1373
|
-
* Pre-compute requirements summary for optimal UI performance.
|
|
1374
|
-
* This eliminates the need for runtime transformation in UI components.
|
|
1375
|
-
*/
|
|
1376
|
-
computeRequirementsSummary(e) {
|
|
1377
|
-
const n = e?.secrets?.length ? {
|
|
1378
|
-
configured: e.secrets.filter((s) => s.met === !0).map((s) => s.key),
|
|
1379
|
-
pending: e.secrets.filter((s) => s.met === !1).map((s) => s.key)
|
|
1380
|
-
} : void 0, r = e?.authorization?.length ? {
|
|
1381
|
-
providers: e.authorization.filter((s) => s.provider_id || s.id).map((s) => ({
|
|
1382
|
-
id: s.provider_id || s.id || "",
|
|
1383
|
-
status: s.status,
|
|
1384
|
-
scopes: s.oauth2?.scopes || []
|
|
1385
|
-
}))
|
|
1386
|
-
} : void 0;
|
|
1387
|
-
return { secrets: n, oauth: r };
|
|
1388
|
-
}
|
|
1389
|
-
/**
|
|
1390
|
-
* Process raw toolkit data into an optimized collection with pre-computed search indices.
|
|
1391
|
-
*
|
|
1392
|
-
* @returns ToolkitCollection with:
|
|
1393
|
-
* - Pre-computed searchable text for fast filtering
|
|
1394
|
-
* - Pre-computed requirement badges (no runtime processing needed)
|
|
1395
|
-
* - Search indices for O(1) lookups
|
|
1396
|
-
* - Toolkit/tool mapping for quick relationships
|
|
1397
|
-
*/
|
|
1398
|
-
async getProcessedToolkitCollection() {
|
|
1399
|
-
const e = await this.getToolkits(), n = [], r = [], s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), i = {
|
|
1400
|
-
toolkitsByName: /* @__PURE__ */ new Map(),
|
|
1401
|
-
toolsByName: /* @__PURE__ */ new Map()
|
|
1402
|
-
};
|
|
1403
|
-
for (const [l, c] of e.entries()) {
|
|
1404
|
-
const u = this.normalizeText([
|
|
1405
|
-
c.name,
|
|
1406
|
-
c.description ?? "",
|
|
1407
|
-
c.version ?? ""
|
|
1408
|
-
]), p = this.computeRequirementsSummary(
|
|
1409
|
-
c.requirements
|
|
1410
|
-
), a = {
|
|
1411
|
-
...c,
|
|
1412
|
-
searchableText: u,
|
|
1413
|
-
requirementsSummary: p,
|
|
1414
|
-
metadata: et[c.name]
|
|
1415
|
-
};
|
|
1416
|
-
n.push(a), s.set(l, a), i.toolkitsByName.set(l.toLowerCase(), a);
|
|
1417
|
-
for (const h of c.tools) {
|
|
1418
|
-
const m = this.normalizeText([
|
|
1419
|
-
h.name,
|
|
1420
|
-
h.fully_qualified_name,
|
|
1421
|
-
h.description ?? "",
|
|
1422
|
-
c.name,
|
|
1423
|
-
c.description ?? ""
|
|
1424
|
-
]), b = {
|
|
1425
|
-
...h,
|
|
1426
|
-
searchableText: m
|
|
1427
|
-
};
|
|
1428
|
-
r.push(b), o.set(h.fully_qualified_name, l), i.toolsByName.set(
|
|
1429
|
-
h.fully_qualified_name.toLowerCase(),
|
|
1430
|
-
b
|
|
1431
|
-
);
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
return {
|
|
1435
|
-
toolkits: n,
|
|
1436
|
-
tools: r,
|
|
1437
|
-
toolkitMap: s,
|
|
1438
|
-
toolToToolkitMap: o,
|
|
1439
|
-
searchIndex: i
|
|
1440
|
-
};
|
|
1441
|
-
}
|
|
1442
|
-
/**
|
|
1443
|
-
* Helper function to create normalized searchable text from multiple strings.
|
|
1444
|
-
* Separates compound terms (like Gmail.List_emails) into individual searchable components.
|
|
1445
|
-
* Handles camelCase, snake_case, kebab-case, and dot.notation.
|
|
1446
|
-
*/
|
|
1447
|
-
normalizeText(e) {
|
|
1448
|
-
const n = /* @__PURE__ */ new Set();
|
|
1449
|
-
for (const r of e) {
|
|
1450
|
-
if (!r)
|
|
1451
|
-
continue;
|
|
1452
|
-
const s = r.toLowerCase();
|
|
1453
|
-
n.add(s);
|
|
1454
|
-
const o = r.split(Ut);
|
|
1455
|
-
for (const i of o) {
|
|
1456
|
-
if (i.length <= 1)
|
|
1457
|
-
continue;
|
|
1458
|
-
const c = i.replace($t, "$1 $2").split(jt);
|
|
1459
|
-
for (const u of c)
|
|
1460
|
-
u.length > 1 && n.add(u.toLowerCase());
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
return Array.from(n).join(" ");
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
export {
|
|
1467
|
-
qt as A,
|
|
1468
|
-
d as a
|
|
1469
|
-
};
|