@cycleplatform/api-client-typescript 0.2.5 → 0.3.4
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/index.js +327 -186
- package/dist/index.umd.cjs +1 -1
- package/package.json +8 -10
- package/src/generated/types.ts +22548 -16036
- package/src/index.ts +6 -4
- package/src/jobs.ts +167 -0
- package/tsconfig.json +4 -2
package/dist/index.js
CHANGED
|
@@ -1,314 +1,455 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
const B = /\{[^{}]+\}/g, F = () => {
|
|
2
|
+
var r, t;
|
|
3
|
+
return typeof process == "object" && Number.parseInt((t = (r = process == null ? void 0 : process.versions) == null ? void 0 : r.node) == null ? void 0 : t.substring(0, 2)) >= 18 && process.versions.undici;
|
|
4
|
+
};
|
|
5
|
+
function M() {
|
|
6
|
+
return Math.random().toString(36).slice(2, 11);
|
|
7
|
+
}
|
|
8
|
+
function W(r) {
|
|
5
9
|
let {
|
|
6
10
|
baseUrl: t = "",
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
Request: e = globalThis.Request,
|
|
12
|
+
fetch: s = globalThis.fetch,
|
|
13
|
+
querySerializer: n,
|
|
14
|
+
bodySerializer: o,
|
|
10
15
|
headers: i,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
...
|
|
16
|
+
requestInitExt: l = void 0,
|
|
17
|
+
...y
|
|
18
|
+
} = { ...r };
|
|
19
|
+
l = F() ? l : void 0, t = U(t);
|
|
20
|
+
const h = [];
|
|
21
|
+
async function p(c, a) {
|
|
22
|
+
const {
|
|
23
|
+
baseUrl: m,
|
|
24
|
+
fetch: I = s,
|
|
25
|
+
Request: Y = e,
|
|
26
|
+
headers: J,
|
|
27
|
+
params: g = {},
|
|
28
|
+
parseAs: A = "json",
|
|
29
|
+
querySerializer: j,
|
|
30
|
+
bodySerializer: k = o ?? Q,
|
|
31
|
+
body: v,
|
|
32
|
+
...x
|
|
33
|
+
} = a || {};
|
|
34
|
+
m && (t = U(m));
|
|
35
|
+
let z = typeof n == "function" ? n : O(n);
|
|
36
|
+
j && (z = typeof j == "function" ? j : O({
|
|
37
|
+
...typeof n == "object" ? n : {},
|
|
38
|
+
...j
|
|
28
39
|
}));
|
|
29
|
-
const
|
|
40
|
+
const q = v === void 0 ? void 0 : k(v), L = (
|
|
41
|
+
// with no body, we should not to set Content-Type
|
|
42
|
+
q === void 0 || // if serialized body is FormData; browser will correctly set Content-Type & boundary expression
|
|
43
|
+
q instanceof FormData ? {} : {
|
|
44
|
+
"Content-Type": "application/json"
|
|
45
|
+
}
|
|
46
|
+
), N = {
|
|
30
47
|
redirect: "follow",
|
|
31
|
-
...
|
|
32
|
-
...
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
h.body && (h.body = S(h.body)), h.body instanceof FormData && h.headers.delete("Content-Type");
|
|
36
|
-
let b = new Request(
|
|
37
|
-
L(o, { baseUrl: t, params: p, querySerializer: $ }),
|
|
38
|
-
h
|
|
39
|
-
);
|
|
40
|
-
const E = {
|
|
41
|
-
baseUrl: t,
|
|
42
|
-
fetch: m,
|
|
43
|
-
parseAs: j,
|
|
44
|
-
querySerializer: $,
|
|
45
|
-
bodySerializer: S
|
|
48
|
+
...y,
|
|
49
|
+
...x,
|
|
50
|
+
body: q,
|
|
51
|
+
headers: X(L, i, J, g.header)
|
|
46
52
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
let E, S, b = new e(_(c, { baseUrl: t, params: g, querySerializer: z }), N);
|
|
54
|
+
for (const u in x)
|
|
55
|
+
u in b || (b[u] = x[u]);
|
|
56
|
+
if (h.length) {
|
|
57
|
+
E = M(), S = Object.freeze({
|
|
58
|
+
baseUrl: t,
|
|
59
|
+
fetch: I,
|
|
60
|
+
parseAs: A,
|
|
61
|
+
querySerializer: z,
|
|
62
|
+
bodySerializer: k
|
|
63
|
+
});
|
|
64
|
+
for (const u of h)
|
|
65
|
+
if (u && typeof u == "object" && typeof u.onRequest == "function") {
|
|
66
|
+
const d = await u.onRequest({
|
|
67
|
+
request: b,
|
|
68
|
+
schemaPath: c,
|
|
69
|
+
params: g,
|
|
70
|
+
options: S,
|
|
71
|
+
id: E
|
|
72
|
+
});
|
|
73
|
+
if (d) {
|
|
74
|
+
if (!(d instanceof e))
|
|
75
|
+
throw new Error("onRequest: must return new Request() when modifying the request");
|
|
76
|
+
b = d;
|
|
77
|
+
}
|
|
57
78
|
}
|
|
58
|
-
|
|
59
|
-
let f
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
79
|
+
}
|
|
80
|
+
let f;
|
|
81
|
+
try {
|
|
82
|
+
f = await I(b, l);
|
|
83
|
+
} catch (u) {
|
|
84
|
+
let d = u;
|
|
85
|
+
if (h.length)
|
|
86
|
+
for (let w = h.length - 1; w >= 0; w--) {
|
|
87
|
+
const T = h[w];
|
|
88
|
+
if (T && typeof T == "object" && typeof T.onError == "function") {
|
|
89
|
+
const R = await T.onError({
|
|
90
|
+
request: b,
|
|
91
|
+
error: d,
|
|
92
|
+
schemaPath: c,
|
|
93
|
+
params: g,
|
|
94
|
+
options: S,
|
|
95
|
+
id: E
|
|
96
|
+
});
|
|
97
|
+
if (R) {
|
|
98
|
+
if (R instanceof Response) {
|
|
99
|
+
d = void 0, f = R;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
if (R instanceof Error) {
|
|
103
|
+
d = R;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
throw new Error("onError: must return new Response() or instance of Error");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
70
109
|
}
|
|
71
|
-
|
|
110
|
+
if (d)
|
|
111
|
+
throw d;
|
|
72
112
|
}
|
|
113
|
+
if (h.length)
|
|
114
|
+
for (let u = h.length - 1; u >= 0; u--) {
|
|
115
|
+
const d = h[u];
|
|
116
|
+
if (d && typeof d == "object" && typeof d.onResponse == "function") {
|
|
117
|
+
const w = await d.onResponse({
|
|
118
|
+
request: b,
|
|
119
|
+
response: f,
|
|
120
|
+
schemaPath: c,
|
|
121
|
+
params: g,
|
|
122
|
+
options: S,
|
|
123
|
+
id: E
|
|
124
|
+
});
|
|
125
|
+
if (w) {
|
|
126
|
+
if (!(w instanceof Response))
|
|
127
|
+
throw new Error("onResponse: must return new Response() when modifying the response");
|
|
128
|
+
f = w;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
73
132
|
if (f.status === 204 || f.headers.get("Content-Length") === "0")
|
|
74
|
-
return f.ok ? { data:
|
|
133
|
+
return f.ok ? { data: void 0, response: f } : { error: void 0, response: f };
|
|
75
134
|
if (f.ok)
|
|
76
|
-
return
|
|
77
|
-
let
|
|
135
|
+
return A === "stream" ? { data: f.body, response: f } : { data: await f[A](), response: f };
|
|
136
|
+
let C = await f.text();
|
|
78
137
|
try {
|
|
79
|
-
|
|
138
|
+
C = JSON.parse(C);
|
|
80
139
|
} catch {
|
|
81
140
|
}
|
|
82
|
-
return { error:
|
|
141
|
+
return { error: C, response: f };
|
|
83
142
|
}
|
|
84
143
|
return {
|
|
144
|
+
request(c, a, m) {
|
|
145
|
+
return p(a, { ...m, method: c.toUpperCase() });
|
|
146
|
+
},
|
|
85
147
|
/** Call a GET endpoint */
|
|
86
|
-
|
|
87
|
-
return
|
|
148
|
+
GET(c, a) {
|
|
149
|
+
return p(c, { ...a, method: "GET" });
|
|
88
150
|
},
|
|
89
151
|
/** Call a PUT endpoint */
|
|
90
|
-
|
|
91
|
-
return
|
|
152
|
+
PUT(c, a) {
|
|
153
|
+
return p(c, { ...a, method: "PUT" });
|
|
92
154
|
},
|
|
93
155
|
/** Call a POST endpoint */
|
|
94
|
-
|
|
95
|
-
return
|
|
156
|
+
POST(c, a) {
|
|
157
|
+
return p(c, { ...a, method: "POST" });
|
|
96
158
|
},
|
|
97
159
|
/** Call a DELETE endpoint */
|
|
98
|
-
|
|
99
|
-
return
|
|
160
|
+
DELETE(c, a) {
|
|
161
|
+
return p(c, { ...a, method: "DELETE" });
|
|
100
162
|
},
|
|
101
163
|
/** Call a OPTIONS endpoint */
|
|
102
|
-
|
|
103
|
-
return
|
|
164
|
+
OPTIONS(c, a) {
|
|
165
|
+
return p(c, { ...a, method: "OPTIONS" });
|
|
104
166
|
},
|
|
105
167
|
/** Call a HEAD endpoint */
|
|
106
|
-
|
|
107
|
-
return
|
|
168
|
+
HEAD(c, a) {
|
|
169
|
+
return p(c, { ...a, method: "HEAD" });
|
|
108
170
|
},
|
|
109
171
|
/** Call a PATCH endpoint */
|
|
110
|
-
|
|
111
|
-
return
|
|
172
|
+
PATCH(c, a) {
|
|
173
|
+
return p(c, { ...a, method: "PATCH" });
|
|
112
174
|
},
|
|
113
175
|
/** Call a TRACE endpoint */
|
|
114
|
-
|
|
115
|
-
return
|
|
176
|
+
TRACE(c, a) {
|
|
177
|
+
return p(c, { ...a, method: "TRACE" });
|
|
116
178
|
},
|
|
117
179
|
/** Register middleware */
|
|
118
|
-
use(...
|
|
119
|
-
for (const
|
|
120
|
-
if (
|
|
121
|
-
if (typeof
|
|
122
|
-
throw new Error(
|
|
123
|
-
|
|
124
|
-
);
|
|
125
|
-
c.push(l);
|
|
180
|
+
use(...c) {
|
|
181
|
+
for (const a of c)
|
|
182
|
+
if (a) {
|
|
183
|
+
if (typeof a != "object" || !("onRequest" in a || "onResponse" in a || "onError" in a))
|
|
184
|
+
throw new Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");
|
|
185
|
+
h.push(a);
|
|
126
186
|
}
|
|
127
187
|
},
|
|
128
188
|
/** Unregister middleware */
|
|
129
|
-
eject(...
|
|
130
|
-
for (const
|
|
131
|
-
const m =
|
|
132
|
-
m !== -1 &&
|
|
189
|
+
eject(...c) {
|
|
190
|
+
for (const a of c) {
|
|
191
|
+
const m = h.indexOf(a);
|
|
192
|
+
m !== -1 && h.splice(m, 1);
|
|
133
193
|
}
|
|
134
194
|
}
|
|
135
195
|
};
|
|
136
196
|
}
|
|
137
|
-
function
|
|
197
|
+
function $(r, t, e) {
|
|
138
198
|
if (t == null)
|
|
139
199
|
return "";
|
|
140
200
|
if (typeof t == "object")
|
|
141
201
|
throw new Error(
|
|
142
202
|
"Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these."
|
|
143
203
|
);
|
|
144
|
-
return `${
|
|
204
|
+
return `${r}=${(e == null ? void 0 : e.allowReserved) === !0 ? t : encodeURIComponent(t)}`;
|
|
145
205
|
}
|
|
146
|
-
function
|
|
206
|
+
function H(r, t, e) {
|
|
147
207
|
if (!t || typeof t != "object")
|
|
148
208
|
return "";
|
|
149
|
-
const s = [],
|
|
209
|
+
const s = [], n = {
|
|
150
210
|
simple: ",",
|
|
151
211
|
label: ".",
|
|
152
212
|
matrix: ";"
|
|
153
213
|
}[e.style] || "&";
|
|
154
214
|
if (e.style !== "deepObject" && e.explode === !1) {
|
|
155
|
-
for (const
|
|
156
|
-
s.push(
|
|
157
|
-
|
|
158
|
-
e.allowReserved === !0 ? t[c] : encodeURIComponent(t[c])
|
|
159
|
-
);
|
|
160
|
-
const a = s.join(",");
|
|
215
|
+
for (const l in t)
|
|
216
|
+
s.push(l, e.allowReserved === !0 ? t[l] : encodeURIComponent(t[l]));
|
|
217
|
+
const i = s.join(",");
|
|
161
218
|
switch (e.style) {
|
|
162
219
|
case "form":
|
|
163
|
-
return `${
|
|
220
|
+
return `${r}=${i}`;
|
|
164
221
|
case "label":
|
|
165
|
-
return `.${
|
|
222
|
+
return `.${i}`;
|
|
166
223
|
case "matrix":
|
|
167
|
-
return `;${
|
|
224
|
+
return `;${r}=${i}`;
|
|
168
225
|
default:
|
|
169
|
-
return
|
|
226
|
+
return i;
|
|
170
227
|
}
|
|
171
228
|
}
|
|
172
|
-
for (const
|
|
173
|
-
const
|
|
174
|
-
s.push(
|
|
229
|
+
for (const i in t) {
|
|
230
|
+
const l = e.style === "deepObject" ? `${r}[${i}]` : i;
|
|
231
|
+
s.push($(l, t[i], e));
|
|
175
232
|
}
|
|
176
|
-
const
|
|
177
|
-
return e.style === "label" || e.style === "matrix" ? `${
|
|
233
|
+
const o = s.join(n);
|
|
234
|
+
return e.style === "label" || e.style === "matrix" ? `${n}${o}` : o;
|
|
178
235
|
}
|
|
179
|
-
function
|
|
236
|
+
function P(r, t, e) {
|
|
180
237
|
if (!Array.isArray(t))
|
|
181
238
|
return "";
|
|
182
239
|
if (e.explode === !1) {
|
|
183
|
-
const
|
|
240
|
+
const o = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[e.style] || ",", i = (e.allowReserved === !0 ? t : t.map((l) => encodeURIComponent(l))).join(o);
|
|
184
241
|
switch (e.style) {
|
|
185
242
|
case "simple":
|
|
186
|
-
return
|
|
243
|
+
return i;
|
|
187
244
|
case "label":
|
|
188
|
-
return `.${
|
|
245
|
+
return `.${i}`;
|
|
189
246
|
case "matrix":
|
|
190
|
-
return `;${
|
|
191
|
-
case "spaceDelimited":
|
|
192
|
-
case "pipeDelimited":
|
|
247
|
+
return `;${r}=${i}`;
|
|
248
|
+
// case "spaceDelimited":
|
|
249
|
+
// case "pipeDelimited":
|
|
193
250
|
default:
|
|
194
|
-
return `${
|
|
251
|
+
return `${r}=${i}`;
|
|
195
252
|
}
|
|
196
253
|
}
|
|
197
|
-
const s = { simple: ",", label: ".", matrix: ";" }[e.style] || "&",
|
|
198
|
-
for (const
|
|
199
|
-
e.style === "simple" || e.style === "label" ?
|
|
200
|
-
return e.style === "label" || e.style === "matrix" ? `${s}${
|
|
254
|
+
const s = { simple: ",", label: ".", matrix: ";" }[e.style] || "&", n = [];
|
|
255
|
+
for (const o of t)
|
|
256
|
+
e.style === "simple" || e.style === "label" ? n.push(e.allowReserved === !0 ? o : encodeURIComponent(o)) : n.push($(r, o, e));
|
|
257
|
+
return e.style === "label" || e.style === "matrix" ? `${s}${n.join(s)}` : n.join(s);
|
|
201
258
|
}
|
|
202
|
-
function
|
|
259
|
+
function O(r) {
|
|
203
260
|
return function(e) {
|
|
204
261
|
const s = [];
|
|
205
262
|
if (e && typeof e == "object")
|
|
206
|
-
for (const
|
|
207
|
-
const
|
|
208
|
-
if (
|
|
209
|
-
if (Array.isArray(
|
|
263
|
+
for (const n in e) {
|
|
264
|
+
const o = e[n];
|
|
265
|
+
if (o != null) {
|
|
266
|
+
if (Array.isArray(o)) {
|
|
267
|
+
if (o.length === 0)
|
|
268
|
+
continue;
|
|
210
269
|
s.push(
|
|
211
|
-
|
|
270
|
+
P(n, o, {
|
|
212
271
|
style: "form",
|
|
213
272
|
explode: !0,
|
|
214
|
-
...
|
|
215
|
-
allowReserved: (
|
|
273
|
+
...r == null ? void 0 : r.array,
|
|
274
|
+
allowReserved: (r == null ? void 0 : r.allowReserved) || !1
|
|
216
275
|
})
|
|
217
276
|
);
|
|
218
277
|
continue;
|
|
219
278
|
}
|
|
220
|
-
if (typeof
|
|
279
|
+
if (typeof o == "object") {
|
|
221
280
|
s.push(
|
|
222
|
-
|
|
281
|
+
H(n, o, {
|
|
223
282
|
style: "deepObject",
|
|
224
283
|
explode: !0,
|
|
225
|
-
...
|
|
226
|
-
allowReserved: (
|
|
284
|
+
...r == null ? void 0 : r.object,
|
|
285
|
+
allowReserved: (r == null ? void 0 : r.allowReserved) || !1
|
|
227
286
|
})
|
|
228
287
|
);
|
|
229
288
|
continue;
|
|
230
289
|
}
|
|
231
|
-
s.push(
|
|
290
|
+
s.push($(n, o, r));
|
|
232
291
|
}
|
|
233
292
|
}
|
|
234
293
|
return s.join("&");
|
|
235
294
|
};
|
|
236
295
|
}
|
|
237
|
-
function
|
|
238
|
-
let e =
|
|
239
|
-
for (const s of
|
|
240
|
-
let
|
|
241
|
-
if (
|
|
296
|
+
function G(r, t) {
|
|
297
|
+
let e = r;
|
|
298
|
+
for (const s of r.match(B) ?? []) {
|
|
299
|
+
let n = s.substring(1, s.length - 1), o = !1, i = "simple";
|
|
300
|
+
if (n.endsWith("*") && (o = !0, n = n.substring(0, n.length - 1)), n.startsWith(".") ? (i = "label", n = n.substring(1)) : n.startsWith(";") && (i = "matrix", n = n.substring(1)), !t || t[n] === void 0 || t[n] === null)
|
|
242
301
|
continue;
|
|
243
|
-
const
|
|
244
|
-
if (Array.isArray(
|
|
245
|
-
e = e.replace(
|
|
246
|
-
s,
|
|
247
|
-
O(r, c, { style: a, explode: i })
|
|
248
|
-
);
|
|
302
|
+
const l = t[n];
|
|
303
|
+
if (Array.isArray(l)) {
|
|
304
|
+
e = e.replace(s, P(n, l, { style: i, explode: o }));
|
|
249
305
|
continue;
|
|
250
306
|
}
|
|
251
|
-
if (typeof
|
|
252
|
-
e = e.replace(
|
|
253
|
-
s,
|
|
254
|
-
x(r, c, { style: a, explode: i })
|
|
255
|
-
);
|
|
307
|
+
if (typeof l == "object") {
|
|
308
|
+
e = e.replace(s, H(n, l, { style: i, explode: o }));
|
|
256
309
|
continue;
|
|
257
310
|
}
|
|
258
|
-
if (
|
|
259
|
-
e = e.replace(
|
|
260
|
-
s,
|
|
261
|
-
`;${R(r, c)}`
|
|
262
|
-
);
|
|
311
|
+
if (i === "matrix") {
|
|
312
|
+
e = e.replace(s, `;${$(n, l)}`);
|
|
263
313
|
continue;
|
|
264
314
|
}
|
|
265
|
-
e = e.replace(s,
|
|
315
|
+
e = e.replace(s, i === "label" ? `.${encodeURIComponent(l)}` : encodeURIComponent(l));
|
|
266
316
|
}
|
|
267
317
|
return e;
|
|
268
318
|
}
|
|
269
|
-
function
|
|
270
|
-
return JSON.stringify(
|
|
319
|
+
function Q(r) {
|
|
320
|
+
return r instanceof FormData ? r : JSON.stringify(r);
|
|
271
321
|
}
|
|
272
|
-
function
|
|
273
|
-
var
|
|
274
|
-
let e = `${t.baseUrl}${
|
|
275
|
-
(
|
|
322
|
+
function _(r, t) {
|
|
323
|
+
var n;
|
|
324
|
+
let e = `${t.baseUrl}${r}`;
|
|
325
|
+
(n = t.params) != null && n.path && (e = G(e, t.params.path));
|
|
276
326
|
let s = t.querySerializer(t.params.query ?? {});
|
|
277
327
|
return s.startsWith("?") && (s = s.substring(1)), s && (e += `?${s}`), e;
|
|
278
328
|
}
|
|
279
|
-
function
|
|
329
|
+
function X(...r) {
|
|
280
330
|
const t = new Headers();
|
|
281
|
-
for (const e of
|
|
331
|
+
for (const e of r) {
|
|
282
332
|
if (!e || typeof e != "object")
|
|
283
333
|
continue;
|
|
284
334
|
const s = e instanceof Headers ? e.entries() : Object.entries(e);
|
|
285
|
-
for (const [
|
|
286
|
-
if (
|
|
287
|
-
t.delete(
|
|
288
|
-
else if (Array.isArray(
|
|
289
|
-
for (const
|
|
290
|
-
t.append(
|
|
291
|
-
else
|
|
292
|
-
i !== void 0 && t.set(r, i);
|
|
335
|
+
for (const [n, o] of s)
|
|
336
|
+
if (o === null)
|
|
337
|
+
t.delete(n);
|
|
338
|
+
else if (Array.isArray(o))
|
|
339
|
+
for (const i of o)
|
|
340
|
+
t.append(n, i);
|
|
341
|
+
else o !== void 0 && t.set(n, o);
|
|
293
342
|
}
|
|
294
343
|
return t;
|
|
295
344
|
}
|
|
296
|
-
function
|
|
297
|
-
|
|
345
|
+
function U(r) {
|
|
346
|
+
return r.endsWith("/") ? r.substring(0, r.length - 1) : r;
|
|
347
|
+
}
|
|
348
|
+
class Z extends EventTarget {
|
|
349
|
+
constructor(t, e, s) {
|
|
350
|
+
super(), this.promise = this.track(t, e, s);
|
|
351
|
+
}
|
|
352
|
+
async track(t, e, s) {
|
|
353
|
+
const n = typeof e == "object" ? e.id : e, o = {
|
|
354
|
+
pollingInterval: 2e3,
|
|
355
|
+
...s
|
|
356
|
+
};
|
|
357
|
+
let i = 0;
|
|
358
|
+
for (; ; ) {
|
|
359
|
+
const l = await t.GET("/v1/jobs/{jobId}", {
|
|
360
|
+
params: { path: { jobId: n } }
|
|
361
|
+
});
|
|
362
|
+
if (l.error) {
|
|
363
|
+
if (i < 5 && l.error.error.code === "404.job") {
|
|
364
|
+
i++, await this.delay(o.pollingInterval);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
throw l.error;
|
|
368
|
+
}
|
|
369
|
+
const y = l.data.data, h = V(y);
|
|
370
|
+
if (this.dispatchEvent(
|
|
371
|
+
new CustomEvent("progress", {
|
|
372
|
+
detail: { ...h, state: y.state.current }
|
|
373
|
+
})
|
|
374
|
+
), K(y)) {
|
|
375
|
+
if (y.state.current === "error")
|
|
376
|
+
throw y;
|
|
377
|
+
return this.dispatchEvent(
|
|
378
|
+
new CustomEvent("done", {
|
|
379
|
+
detail: y
|
|
380
|
+
})
|
|
381
|
+
), y;
|
|
382
|
+
}
|
|
383
|
+
await this.delay(o.pollingInterval);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
delay(t = 2e3) {
|
|
387
|
+
return new Promise((e) => setTimeout(e, t));
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
function K(r) {
|
|
391
|
+
return [
|
|
392
|
+
"completed",
|
|
393
|
+
"error",
|
|
394
|
+
"expired"
|
|
395
|
+
].includes(r.state.current);
|
|
396
|
+
}
|
|
397
|
+
const D = "0001-01-01T00:00:00Z";
|
|
398
|
+
function V(r) {
|
|
399
|
+
if (!r.tasks || r.tasks.length === 0)
|
|
400
|
+
return { total: 0, completed: 0, failed: 0, percent: 100 };
|
|
401
|
+
const t = r.tasks.reduce(
|
|
402
|
+
(e, s) => {
|
|
403
|
+
var o, i, l;
|
|
404
|
+
const n = ((o = s.steps) == null ? void 0 : o.length) || 1;
|
|
405
|
+
if (e.total += n, s.state.current === "pending")
|
|
406
|
+
return e;
|
|
407
|
+
if (!((i = s.steps) != null && i.length)) {
|
|
408
|
+
switch (s.state.current) {
|
|
409
|
+
case "completed":
|
|
410
|
+
e.completed += 1;
|
|
411
|
+
break;
|
|
412
|
+
case "error":
|
|
413
|
+
e.failed += 1;
|
|
414
|
+
}
|
|
415
|
+
return e;
|
|
416
|
+
}
|
|
417
|
+
return (l = s.steps) == null || l.forEach((y) => {
|
|
418
|
+
if (y.completed !== D) {
|
|
419
|
+
e.completed += 1;
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
["error", "completed"].includes(s.state.current || "") && y.started !== D && (e.failed += 1);
|
|
423
|
+
}), e;
|
|
424
|
+
},
|
|
425
|
+
{ total: 0, completed: 0, failed: 0 }
|
|
426
|
+
);
|
|
427
|
+
return {
|
|
428
|
+
...t,
|
|
429
|
+
percent: t.completed / t.total * 100
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
function ee(r, t, e) {
|
|
433
|
+
return new Z(r, t, e);
|
|
434
|
+
}
|
|
435
|
+
function te({
|
|
436
|
+
apiKey: r,
|
|
298
437
|
baseUrl: t = "https://api.cycle.io",
|
|
299
438
|
hubId: e,
|
|
300
439
|
fetch: s
|
|
301
440
|
}) {
|
|
302
|
-
const
|
|
441
|
+
const n = W({
|
|
303
442
|
baseUrl: t,
|
|
304
443
|
fetch: s || fetch
|
|
305
|
-
}),
|
|
306
|
-
async onRequest(
|
|
307
|
-
return
|
|
444
|
+
}), o = {
|
|
445
|
+
async onRequest({ request: i }) {
|
|
446
|
+
return i.headers.set("Authorization", `Bearer ${r}`), i.headers.set("X-Hub-Id", e), i;
|
|
308
447
|
}
|
|
309
448
|
};
|
|
310
|
-
return
|
|
449
|
+
return n.use(o), n;
|
|
311
450
|
}
|
|
312
451
|
export {
|
|
313
|
-
|
|
452
|
+
te as getClient,
|
|
453
|
+
V as getJobProgress,
|
|
454
|
+
ee as trackJob
|
|
314
455
|
};
|