@cycleplatform/api-client-typescript 0.3.0 → 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 +314 -175
- package/dist/index.umd.cjs +1 -1
- package/package.json +7 -8
- package/src/generated/types.ts +3641 -1019
- package/src/index.ts +3 -1
- package/src/jobs.ts +167 -0
package/dist/index.js
CHANGED
|
@@ -1,316 +1,455 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
super(t, e);
|
|
7
|
-
for (const n in e)
|
|
8
|
-
n in this || (this[n] = e[n]);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
function P() {
|
|
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() {
|
|
12
6
|
return Math.random().toString(36).slice(2, 11);
|
|
13
7
|
}
|
|
14
|
-
function
|
|
8
|
+
function W(r) {
|
|
15
9
|
let {
|
|
16
10
|
baseUrl: t = "",
|
|
17
|
-
|
|
11
|
+
Request: e = globalThis.Request,
|
|
12
|
+
fetch: s = globalThis.fetch,
|
|
18
13
|
querySerializer: n,
|
|
19
|
-
bodySerializer:
|
|
14
|
+
bodySerializer: o,
|
|
20
15
|
headers: i,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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) {
|
|
26
22
|
const {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
37
|
...typeof n == "object" ? n : {},
|
|
38
|
-
...
|
|
38
|
+
...j
|
|
39
39
|
}));
|
|
40
|
-
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 = {
|
|
41
47
|
redirect: "follow",
|
|
42
|
-
...
|
|
43
|
-
...
|
|
44
|
-
|
|
48
|
+
...y,
|
|
49
|
+
...x,
|
|
50
|
+
body: q,
|
|
51
|
+
headers: X(L, i, J, g.header)
|
|
45
52
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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({
|
|
50
58
|
baseUrl: t,
|
|
51
|
-
fetch:
|
|
52
|
-
parseAs:
|
|
53
|
-
querySerializer:
|
|
54
|
-
bodySerializer:
|
|
59
|
+
fetch: I,
|
|
60
|
+
parseAs: A,
|
|
61
|
+
querySerializer: z,
|
|
62
|
+
bodySerializer: k
|
|
55
63
|
});
|
|
56
|
-
for (const
|
|
57
|
-
if (
|
|
58
|
-
const
|
|
59
|
-
request:
|
|
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,
|
|
60
68
|
schemaPath: c,
|
|
61
|
-
params:
|
|
62
|
-
options:
|
|
63
|
-
id:
|
|
69
|
+
params: g,
|
|
70
|
+
options: S,
|
|
71
|
+
id: E
|
|
64
72
|
});
|
|
65
|
-
if (
|
|
66
|
-
if (!(
|
|
73
|
+
if (d) {
|
|
74
|
+
if (!(d instanceof e))
|
|
67
75
|
throw new Error("onRequest: must return new Request() when modifying the request");
|
|
68
|
-
|
|
76
|
+
b = d;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
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
|
+
}
|
|
69
108
|
}
|
|
70
109
|
}
|
|
110
|
+
if (d)
|
|
111
|
+
throw d;
|
|
71
112
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
request: w,
|
|
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,
|
|
79
119
|
response: f,
|
|
80
120
|
schemaPath: c,
|
|
81
|
-
params:
|
|
82
|
-
options:
|
|
83
|
-
id:
|
|
121
|
+
params: g,
|
|
122
|
+
options: S,
|
|
123
|
+
id: E
|
|
84
124
|
});
|
|
85
|
-
if (
|
|
86
|
-
if (!(
|
|
125
|
+
if (w) {
|
|
126
|
+
if (!(w instanceof Response))
|
|
87
127
|
throw new Error("onResponse: must return new Response() when modifying the response");
|
|
88
|
-
f =
|
|
128
|
+
f = w;
|
|
89
129
|
}
|
|
90
130
|
}
|
|
91
131
|
}
|
|
92
132
|
if (f.status === 204 || f.headers.get("Content-Length") === "0")
|
|
93
|
-
return f.ok ? { data:
|
|
133
|
+
return f.ok ? { data: void 0, response: f } : { error: void 0, response: f };
|
|
94
134
|
if (f.ok)
|
|
95
|
-
return
|
|
96
|
-
let
|
|
135
|
+
return A === "stream" ? { data: f.body, response: f } : { data: await f[A](), response: f };
|
|
136
|
+
let C = await f.text();
|
|
97
137
|
try {
|
|
98
|
-
|
|
138
|
+
C = JSON.parse(C);
|
|
99
139
|
} catch {
|
|
100
140
|
}
|
|
101
|
-
return { error:
|
|
141
|
+
return { error: C, response: f };
|
|
102
142
|
}
|
|
103
143
|
return {
|
|
144
|
+
request(c, a, m) {
|
|
145
|
+
return p(a, { ...m, method: c.toUpperCase() });
|
|
146
|
+
},
|
|
104
147
|
/** Call a GET endpoint */
|
|
105
|
-
|
|
106
|
-
return
|
|
148
|
+
GET(c, a) {
|
|
149
|
+
return p(c, { ...a, method: "GET" });
|
|
107
150
|
},
|
|
108
151
|
/** Call a PUT endpoint */
|
|
109
|
-
|
|
110
|
-
return
|
|
152
|
+
PUT(c, a) {
|
|
153
|
+
return p(c, { ...a, method: "PUT" });
|
|
111
154
|
},
|
|
112
155
|
/** Call a POST endpoint */
|
|
113
|
-
|
|
114
|
-
return
|
|
156
|
+
POST(c, a) {
|
|
157
|
+
return p(c, { ...a, method: "POST" });
|
|
115
158
|
},
|
|
116
159
|
/** Call a DELETE endpoint */
|
|
117
|
-
|
|
118
|
-
return
|
|
160
|
+
DELETE(c, a) {
|
|
161
|
+
return p(c, { ...a, method: "DELETE" });
|
|
119
162
|
},
|
|
120
163
|
/** Call a OPTIONS endpoint */
|
|
121
|
-
|
|
122
|
-
return
|
|
164
|
+
OPTIONS(c, a) {
|
|
165
|
+
return p(c, { ...a, method: "OPTIONS" });
|
|
123
166
|
},
|
|
124
167
|
/** Call a HEAD endpoint */
|
|
125
|
-
|
|
126
|
-
return
|
|
168
|
+
HEAD(c, a) {
|
|
169
|
+
return p(c, { ...a, method: "HEAD" });
|
|
127
170
|
},
|
|
128
171
|
/** Call a PATCH endpoint */
|
|
129
|
-
|
|
130
|
-
return
|
|
172
|
+
PATCH(c, a) {
|
|
173
|
+
return p(c, { ...a, method: "PATCH" });
|
|
131
174
|
},
|
|
132
175
|
/** Call a TRACE endpoint */
|
|
133
|
-
|
|
134
|
-
return
|
|
176
|
+
TRACE(c, a) {
|
|
177
|
+
return p(c, { ...a, method: "TRACE" });
|
|
135
178
|
},
|
|
136
179
|
/** Register middleware */
|
|
137
180
|
use(...c) {
|
|
138
|
-
for (const
|
|
139
|
-
if (
|
|
140
|
-
if (typeof
|
|
141
|
-
throw new Error("Middleware must be an object with one of `onRequest()` or `
|
|
142
|
-
|
|
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);
|
|
143
186
|
}
|
|
144
187
|
},
|
|
145
188
|
/** Unregister middleware */
|
|
146
189
|
eject(...c) {
|
|
147
|
-
for (const
|
|
148
|
-
const
|
|
149
|
-
|
|
190
|
+
for (const a of c) {
|
|
191
|
+
const m = h.indexOf(a);
|
|
192
|
+
m !== -1 && h.splice(m, 1);
|
|
150
193
|
}
|
|
151
194
|
}
|
|
152
195
|
};
|
|
153
196
|
}
|
|
154
|
-
function
|
|
197
|
+
function $(r, t, e) {
|
|
155
198
|
if (t == null)
|
|
156
199
|
return "";
|
|
157
200
|
if (typeof t == "object")
|
|
158
201
|
throw new Error(
|
|
159
202
|
"Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these."
|
|
160
203
|
);
|
|
161
|
-
return `${
|
|
204
|
+
return `${r}=${(e == null ? void 0 : e.allowReserved) === !0 ? t : encodeURIComponent(t)}`;
|
|
162
205
|
}
|
|
163
|
-
function
|
|
206
|
+
function H(r, t, e) {
|
|
164
207
|
if (!t || typeof t != "object")
|
|
165
208
|
return "";
|
|
166
|
-
const
|
|
209
|
+
const s = [], n = {
|
|
167
210
|
simple: ",",
|
|
168
211
|
label: ".",
|
|
169
212
|
matrix: ";"
|
|
170
213
|
}[e.style] || "&";
|
|
171
214
|
if (e.style !== "deepObject" && e.explode === !1) {
|
|
172
215
|
for (const l in t)
|
|
173
|
-
|
|
174
|
-
const
|
|
216
|
+
s.push(l, e.allowReserved === !0 ? t[l] : encodeURIComponent(t[l]));
|
|
217
|
+
const i = s.join(",");
|
|
175
218
|
switch (e.style) {
|
|
176
219
|
case "form":
|
|
177
|
-
return `${
|
|
220
|
+
return `${r}=${i}`;
|
|
178
221
|
case "label":
|
|
179
|
-
return `.${
|
|
222
|
+
return `.${i}`;
|
|
180
223
|
case "matrix":
|
|
181
|
-
return `;${
|
|
224
|
+
return `;${r}=${i}`;
|
|
182
225
|
default:
|
|
183
|
-
return
|
|
226
|
+
return i;
|
|
184
227
|
}
|
|
185
228
|
}
|
|
186
|
-
for (const
|
|
187
|
-
const l = e.style === "deepObject" ? `${
|
|
188
|
-
|
|
229
|
+
for (const i in t) {
|
|
230
|
+
const l = e.style === "deepObject" ? `${r}[${i}]` : i;
|
|
231
|
+
s.push($(l, t[i], e));
|
|
189
232
|
}
|
|
190
|
-
const
|
|
191
|
-
return e.style === "label" || e.style === "matrix" ? `${
|
|
233
|
+
const o = s.join(n);
|
|
234
|
+
return e.style === "label" || e.style === "matrix" ? `${n}${o}` : o;
|
|
192
235
|
}
|
|
193
|
-
function
|
|
236
|
+
function P(r, t, e) {
|
|
194
237
|
if (!Array.isArray(t))
|
|
195
238
|
return "";
|
|
196
239
|
if (e.explode === !1) {
|
|
197
|
-
const
|
|
240
|
+
const o = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[e.style] || ",", i = (e.allowReserved === !0 ? t : t.map((l) => encodeURIComponent(l))).join(o);
|
|
198
241
|
switch (e.style) {
|
|
199
242
|
case "simple":
|
|
200
|
-
return
|
|
243
|
+
return i;
|
|
201
244
|
case "label":
|
|
202
|
-
return `.${
|
|
245
|
+
return `.${i}`;
|
|
203
246
|
case "matrix":
|
|
204
|
-
return `;${
|
|
247
|
+
return `;${r}=${i}`;
|
|
248
|
+
// case "spaceDelimited":
|
|
249
|
+
// case "pipeDelimited":
|
|
205
250
|
default:
|
|
206
|
-
return `${
|
|
251
|
+
return `${r}=${i}`;
|
|
207
252
|
}
|
|
208
253
|
}
|
|
209
|
-
const
|
|
210
|
-
for (const
|
|
211
|
-
e.style === "simple" || e.style === "label" ?
|
|
212
|
-
return e.style === "label" || e.style === "matrix" ? `${
|
|
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);
|
|
213
258
|
}
|
|
214
|
-
function
|
|
259
|
+
function O(r) {
|
|
215
260
|
return function(e) {
|
|
216
|
-
const
|
|
261
|
+
const s = [];
|
|
217
262
|
if (e && typeof e == "object")
|
|
218
|
-
for (const
|
|
219
|
-
const
|
|
220
|
-
if (
|
|
221
|
-
if (Array.isArray(
|
|
222
|
-
|
|
223
|
-
|
|
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;
|
|
269
|
+
s.push(
|
|
270
|
+
P(n, o, {
|
|
224
271
|
style: "form",
|
|
225
272
|
explode: !0,
|
|
226
|
-
...
|
|
227
|
-
allowReserved: (
|
|
273
|
+
...r == null ? void 0 : r.array,
|
|
274
|
+
allowReserved: (r == null ? void 0 : r.allowReserved) || !1
|
|
228
275
|
})
|
|
229
276
|
);
|
|
230
277
|
continue;
|
|
231
278
|
}
|
|
232
|
-
if (typeof
|
|
233
|
-
|
|
234
|
-
|
|
279
|
+
if (typeof o == "object") {
|
|
280
|
+
s.push(
|
|
281
|
+
H(n, o, {
|
|
235
282
|
style: "deepObject",
|
|
236
283
|
explode: !0,
|
|
237
|
-
...
|
|
238
|
-
allowReserved: (
|
|
284
|
+
...r == null ? void 0 : r.object,
|
|
285
|
+
allowReserved: (r == null ? void 0 : r.allowReserved) || !1
|
|
239
286
|
})
|
|
240
287
|
);
|
|
241
288
|
continue;
|
|
242
289
|
}
|
|
243
|
-
|
|
290
|
+
s.push($(n, o, r));
|
|
244
291
|
}
|
|
245
292
|
}
|
|
246
|
-
return
|
|
293
|
+
return s.join("&");
|
|
247
294
|
};
|
|
248
295
|
}
|
|
249
|
-
function
|
|
250
|
-
let e =
|
|
251
|
-
for (const
|
|
252
|
-
let
|
|
253
|
-
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)
|
|
254
301
|
continue;
|
|
255
|
-
const l = t[
|
|
302
|
+
const l = t[n];
|
|
256
303
|
if (Array.isArray(l)) {
|
|
257
|
-
e = e.replace(
|
|
304
|
+
e = e.replace(s, P(n, l, { style: i, explode: o }));
|
|
258
305
|
continue;
|
|
259
306
|
}
|
|
260
307
|
if (typeof l == "object") {
|
|
261
|
-
e = e.replace(
|
|
308
|
+
e = e.replace(s, H(n, l, { style: i, explode: o }));
|
|
262
309
|
continue;
|
|
263
310
|
}
|
|
264
|
-
if (
|
|
265
|
-
e = e.replace(
|
|
311
|
+
if (i === "matrix") {
|
|
312
|
+
e = e.replace(s, `;${$(n, l)}`);
|
|
266
313
|
continue;
|
|
267
314
|
}
|
|
268
|
-
e = e.replace(
|
|
315
|
+
e = e.replace(s, i === "label" ? `.${encodeURIComponent(l)}` : encodeURIComponent(l));
|
|
269
316
|
}
|
|
270
317
|
return e;
|
|
271
318
|
}
|
|
272
|
-
function
|
|
273
|
-
return JSON.stringify(
|
|
319
|
+
function Q(r) {
|
|
320
|
+
return r instanceof FormData ? r : JSON.stringify(r);
|
|
274
321
|
}
|
|
275
|
-
function
|
|
276
|
-
var
|
|
277
|
-
let e = `${t.baseUrl}${
|
|
278
|
-
(
|
|
279
|
-
let
|
|
280
|
-
return
|
|
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));
|
|
326
|
+
let s = t.querySerializer(t.params.query ?? {});
|
|
327
|
+
return s.startsWith("?") && (s = s.substring(1)), s && (e += `?${s}`), e;
|
|
281
328
|
}
|
|
282
|
-
function
|
|
329
|
+
function X(...r) {
|
|
283
330
|
const t = new Headers();
|
|
284
|
-
for (const e of
|
|
331
|
+
for (const e of r) {
|
|
285
332
|
if (!e || typeof e != "object")
|
|
286
333
|
continue;
|
|
287
|
-
const
|
|
288
|
-
for (const [
|
|
289
|
-
if (
|
|
290
|
-
t.delete(
|
|
291
|
-
else if (Array.isArray(
|
|
292
|
-
for (const
|
|
293
|
-
t.append(
|
|
294
|
-
else
|
|
334
|
+
const s = e instanceof Headers ? e.entries() : Object.entries(e);
|
|
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);
|
|
295
342
|
}
|
|
296
343
|
return t;
|
|
297
344
|
}
|
|
298
|
-
function
|
|
299
|
-
|
|
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,
|
|
300
437
|
baseUrl: t = "https://api.cycle.io",
|
|
301
438
|
hubId: e,
|
|
302
|
-
fetch:
|
|
439
|
+
fetch: s
|
|
303
440
|
}) {
|
|
304
|
-
const
|
|
441
|
+
const n = W({
|
|
305
442
|
baseUrl: t,
|
|
306
|
-
fetch:
|
|
307
|
-
}),
|
|
308
|
-
async onRequest({ request:
|
|
309
|
-
return
|
|
443
|
+
fetch: s || fetch
|
|
444
|
+
}), o = {
|
|
445
|
+
async onRequest({ request: i }) {
|
|
446
|
+
return i.headers.set("Authorization", `Bearer ${r}`), i.headers.set("X-Hub-Id", e), i;
|
|
310
447
|
}
|
|
311
448
|
};
|
|
312
|
-
return
|
|
449
|
+
return n.use(o), n;
|
|
313
450
|
}
|
|
314
451
|
export {
|
|
315
|
-
|
|
452
|
+
te as getClient,
|
|
453
|
+
V as getJobProgress,
|
|
454
|
+
ee as trackJob
|
|
316
455
|
};
|