@cycleplatform/api-client-typescript 0.2.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +166 -164
- package/dist/index.umd.cjs +1 -1
- package/package.json +8 -9
- package/src/generated/types.ts +19910 -16020
- package/src/index.ts +4 -4
- package/tsconfig.json +4 -2
package/dist/index.js
CHANGED
|
@@ -1,314 +1,316 @@
|
|
|
1
|
-
const
|
|
1
|
+
const H = {
|
|
2
2
|
"Content-Type": "application/json"
|
|
3
|
-
},
|
|
4
|
-
|
|
3
|
+
}, D = /\{[^{}]+\}/g;
|
|
4
|
+
class I extends Request {
|
|
5
|
+
constructor(t, e) {
|
|
6
|
+
super(t, e);
|
|
7
|
+
for (const n in e)
|
|
8
|
+
n in this || (this[n] = e[n]);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function P() {
|
|
12
|
+
return Math.random().toString(36).slice(2, 11);
|
|
13
|
+
}
|
|
14
|
+
function L(s) {
|
|
5
15
|
let {
|
|
6
16
|
baseUrl: t = "",
|
|
7
17
|
fetch: e = globalThis.fetch,
|
|
8
|
-
querySerializer:
|
|
18
|
+
querySerializer: n,
|
|
9
19
|
bodySerializer: r,
|
|
10
20
|
headers: i,
|
|
11
21
|
...a
|
|
12
|
-
} = { ...
|
|
13
|
-
t.endsWith("/") && (t = t.substring(0, t.length - 1)), i =
|
|
14
|
-
const
|
|
15
|
-
async function u(
|
|
16
|
-
|
|
17
|
-
fetch:
|
|
18
|
-
headers:
|
|
19
|
-
params:
|
|
22
|
+
} = { ...s };
|
|
23
|
+
t.endsWith("/") && (t = t.substring(0, t.length - 1)), i = x(H, i);
|
|
24
|
+
const l = [];
|
|
25
|
+
async function u(c, o) {
|
|
26
|
+
const {
|
|
27
|
+
fetch: b = e,
|
|
28
|
+
headers: O,
|
|
29
|
+
params: m = {},
|
|
20
30
|
parseAs: j = "json",
|
|
21
|
-
querySerializer:
|
|
22
|
-
bodySerializer:
|
|
23
|
-
...
|
|
24
|
-
} =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
...
|
|
31
|
+
querySerializer: R,
|
|
32
|
+
bodySerializer: z = r ?? F,
|
|
33
|
+
...U
|
|
34
|
+
} = o || {};
|
|
35
|
+
let g = typeof n == "function" ? n : T(n);
|
|
36
|
+
R && (g = typeof R == "function" ? R : T({
|
|
37
|
+
...typeof n == "object" ? n : {},
|
|
38
|
+
...R
|
|
28
39
|
}));
|
|
29
40
|
const h = {
|
|
30
41
|
redirect: "follow",
|
|
31
42
|
...a,
|
|
32
|
-
...
|
|
33
|
-
headers:
|
|
43
|
+
...U,
|
|
44
|
+
headers: x(i, O, m.header)
|
|
34
45
|
};
|
|
35
|
-
h.body && (h.body =
|
|
36
|
-
let
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
)
|
|
56
|
-
|
|
46
|
+
h.body && (h.body = z(h.body)), h.body instanceof FormData && h.headers.delete("Content-Type");
|
|
47
|
+
let $, A, w = new I(N(c, { baseUrl: t, params: m, querySerializer: g }), h);
|
|
48
|
+
if (l.length) {
|
|
49
|
+
$ = P(), A = Object.freeze({
|
|
50
|
+
baseUrl: t,
|
|
51
|
+
fetch: b,
|
|
52
|
+
parseAs: j,
|
|
53
|
+
querySerializer: g,
|
|
54
|
+
bodySerializer: z
|
|
55
|
+
});
|
|
56
|
+
for (const d of l)
|
|
57
|
+
if (d && typeof d == "object" && typeof d.onRequest == "function") {
|
|
58
|
+
const y = await d.onRequest({
|
|
59
|
+
request: w,
|
|
60
|
+
schemaPath: c,
|
|
61
|
+
params: m,
|
|
62
|
+
options: A,
|
|
63
|
+
id: $
|
|
64
|
+
});
|
|
65
|
+
if (y) {
|
|
66
|
+
if (!(y instanceof Request))
|
|
67
|
+
throw new Error("onRequest: must return new Request() when modifying the request");
|
|
68
|
+
w = y;
|
|
69
|
+
}
|
|
57
70
|
}
|
|
58
|
-
|
|
59
|
-
let f = await
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
}
|
|
72
|
+
let f = await b(w);
|
|
73
|
+
if (l.length)
|
|
74
|
+
for (let d = l.length - 1; d >= 0; d--) {
|
|
75
|
+
const y = l[d];
|
|
76
|
+
if (y && typeof y == "object" && typeof y.onResponse == "function") {
|
|
77
|
+
const E = await y.onResponse({
|
|
78
|
+
request: w,
|
|
79
|
+
response: f,
|
|
80
|
+
schemaPath: c,
|
|
81
|
+
params: m,
|
|
82
|
+
options: A,
|
|
83
|
+
id: $
|
|
84
|
+
});
|
|
85
|
+
if (E) {
|
|
86
|
+
if (!(E instanceof Response))
|
|
87
|
+
throw new Error("onResponse: must return new Response() when modifying the response");
|
|
88
|
+
f = E;
|
|
89
|
+
}
|
|
70
90
|
}
|
|
71
91
|
}
|
|
72
|
-
}
|
|
73
92
|
if (f.status === 204 || f.headers.get("Content-Length") === "0")
|
|
74
93
|
return f.ok ? { data: {}, response: f } : { error: {}, response: f };
|
|
75
94
|
if (f.ok)
|
|
76
95
|
return j === "stream" ? { data: f.body, response: f } : { data: await f[j](), response: f };
|
|
77
|
-
let
|
|
96
|
+
let S = await f.text();
|
|
78
97
|
try {
|
|
79
|
-
|
|
98
|
+
S = JSON.parse(S);
|
|
80
99
|
} catch {
|
|
81
100
|
}
|
|
82
|
-
return { error:
|
|
101
|
+
return { error: S, response: f };
|
|
83
102
|
}
|
|
84
103
|
return {
|
|
85
104
|
/** Call a GET endpoint */
|
|
86
|
-
async GET(
|
|
87
|
-
return u(
|
|
105
|
+
async GET(c, o) {
|
|
106
|
+
return u(c, { ...o, method: "GET" });
|
|
88
107
|
},
|
|
89
108
|
/** Call a PUT endpoint */
|
|
90
|
-
async PUT(
|
|
91
|
-
return u(
|
|
109
|
+
async PUT(c, o) {
|
|
110
|
+
return u(c, { ...o, method: "PUT" });
|
|
92
111
|
},
|
|
93
112
|
/** Call a POST endpoint */
|
|
94
|
-
async POST(
|
|
95
|
-
return u(
|
|
113
|
+
async POST(c, o) {
|
|
114
|
+
return u(c, { ...o, method: "POST" });
|
|
96
115
|
},
|
|
97
116
|
/** Call a DELETE endpoint */
|
|
98
|
-
async DELETE(
|
|
99
|
-
return u(
|
|
117
|
+
async DELETE(c, o) {
|
|
118
|
+
return u(c, { ...o, method: "DELETE" });
|
|
100
119
|
},
|
|
101
120
|
/** Call a OPTIONS endpoint */
|
|
102
|
-
async OPTIONS(
|
|
103
|
-
return u(
|
|
121
|
+
async OPTIONS(c, o) {
|
|
122
|
+
return u(c, { ...o, method: "OPTIONS" });
|
|
104
123
|
},
|
|
105
124
|
/** Call a HEAD endpoint */
|
|
106
|
-
async HEAD(
|
|
107
|
-
return u(
|
|
125
|
+
async HEAD(c, o) {
|
|
126
|
+
return u(c, { ...o, method: "HEAD" });
|
|
108
127
|
},
|
|
109
128
|
/** Call a PATCH endpoint */
|
|
110
|
-
async PATCH(
|
|
111
|
-
return u(
|
|
129
|
+
async PATCH(c, o) {
|
|
130
|
+
return u(c, { ...o, method: "PATCH" });
|
|
112
131
|
},
|
|
113
132
|
/** Call a TRACE endpoint */
|
|
114
|
-
async TRACE(
|
|
115
|
-
return u(
|
|
133
|
+
async TRACE(c, o) {
|
|
134
|
+
return u(c, { ...o, method: "TRACE" });
|
|
116
135
|
},
|
|
117
136
|
/** Register middleware */
|
|
118
|
-
use(...
|
|
119
|
-
for (const
|
|
120
|
-
if (
|
|
121
|
-
if (typeof
|
|
122
|
-
throw new Error(
|
|
123
|
-
|
|
124
|
-
);
|
|
125
|
-
c.push(l);
|
|
137
|
+
use(...c) {
|
|
138
|
+
for (const o of c)
|
|
139
|
+
if (o) {
|
|
140
|
+
if (typeof o != "object" || !("onRequest" in o || "onResponse" in o))
|
|
141
|
+
throw new Error("Middleware must be an object with one of `onRequest()` or `onResponse()`");
|
|
142
|
+
l.push(o);
|
|
126
143
|
}
|
|
127
144
|
},
|
|
128
145
|
/** Unregister middleware */
|
|
129
|
-
eject(...
|
|
130
|
-
for (const
|
|
131
|
-
const
|
|
132
|
-
|
|
146
|
+
eject(...c) {
|
|
147
|
+
for (const o of c) {
|
|
148
|
+
const b = l.indexOf(o);
|
|
149
|
+
b !== -1 && l.splice(b, 1);
|
|
133
150
|
}
|
|
134
151
|
}
|
|
135
152
|
};
|
|
136
153
|
}
|
|
137
|
-
function
|
|
154
|
+
function p(s, t, e) {
|
|
138
155
|
if (t == null)
|
|
139
156
|
return "";
|
|
140
157
|
if (typeof t == "object")
|
|
141
158
|
throw new Error(
|
|
142
159
|
"Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these."
|
|
143
160
|
);
|
|
144
|
-
return `${
|
|
161
|
+
return `${s}=${(e == null ? void 0 : e.allowReserved) === !0 ? t : encodeURIComponent(t)}`;
|
|
145
162
|
}
|
|
146
|
-
function
|
|
163
|
+
function q(s, t, e) {
|
|
147
164
|
if (!t || typeof t != "object")
|
|
148
165
|
return "";
|
|
149
|
-
const
|
|
166
|
+
const n = [], r = {
|
|
150
167
|
simple: ",",
|
|
151
168
|
label: ".",
|
|
152
169
|
matrix: ";"
|
|
153
170
|
}[e.style] || "&";
|
|
154
171
|
if (e.style !== "deepObject" && e.explode === !1) {
|
|
155
|
-
for (const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
e.allowReserved === !0 ? t[c] : encodeURIComponent(t[c])
|
|
159
|
-
);
|
|
160
|
-
const a = s.join(",");
|
|
172
|
+
for (const l in t)
|
|
173
|
+
n.push(l, e.allowReserved === !0 ? t[l] : encodeURIComponent(t[l]));
|
|
174
|
+
const a = n.join(",");
|
|
161
175
|
switch (e.style) {
|
|
162
176
|
case "form":
|
|
163
|
-
return `${
|
|
177
|
+
return `${s}=${a}`;
|
|
164
178
|
case "label":
|
|
165
179
|
return `.${a}`;
|
|
166
180
|
case "matrix":
|
|
167
|
-
return `;${
|
|
181
|
+
return `;${s}=${a}`;
|
|
168
182
|
default:
|
|
169
183
|
return a;
|
|
170
184
|
}
|
|
171
185
|
}
|
|
172
186
|
for (const a in t) {
|
|
173
|
-
const
|
|
174
|
-
|
|
187
|
+
const l = e.style === "deepObject" ? `${s}[${a}]` : a;
|
|
188
|
+
n.push(p(l, t[a], e));
|
|
175
189
|
}
|
|
176
|
-
const i =
|
|
190
|
+
const i = n.join(r);
|
|
177
191
|
return e.style === "label" || e.style === "matrix" ? `${r}${i}` : i;
|
|
178
192
|
}
|
|
179
|
-
function
|
|
193
|
+
function C(s, t, e) {
|
|
180
194
|
if (!Array.isArray(t))
|
|
181
195
|
return "";
|
|
182
196
|
if (e.explode === !1) {
|
|
183
|
-
const i = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[e.style] || ",", a = (e.allowReserved === !0 ? t : t.map((
|
|
197
|
+
const i = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[e.style] || ",", a = (e.allowReserved === !0 ? t : t.map((l) => encodeURIComponent(l))).join(i);
|
|
184
198
|
switch (e.style) {
|
|
185
199
|
case "simple":
|
|
186
200
|
return a;
|
|
187
201
|
case "label":
|
|
188
202
|
return `.${a}`;
|
|
189
203
|
case "matrix":
|
|
190
|
-
return `;${
|
|
191
|
-
case "spaceDelimited":
|
|
192
|
-
case "pipeDelimited":
|
|
204
|
+
return `;${s}=${a}`;
|
|
193
205
|
default:
|
|
194
|
-
return `${
|
|
206
|
+
return `${s}=${a}`;
|
|
195
207
|
}
|
|
196
208
|
}
|
|
197
|
-
const
|
|
209
|
+
const n = { simple: ",", label: ".", matrix: ";" }[e.style] || "&", r = [];
|
|
198
210
|
for (const i of t)
|
|
199
|
-
e.style === "simple" || e.style === "label" ? r.push(e.allowReserved === !0 ? i : encodeURIComponent(i)) : r.push(
|
|
200
|
-
return e.style === "label" || e.style === "matrix" ? `${
|
|
211
|
+
e.style === "simple" || e.style === "label" ? r.push(e.allowReserved === !0 ? i : encodeURIComponent(i)) : r.push(p(s, i, e));
|
|
212
|
+
return e.style === "label" || e.style === "matrix" ? `${n}${r.join(n)}` : r.join(n);
|
|
201
213
|
}
|
|
202
|
-
function T(
|
|
214
|
+
function T(s) {
|
|
203
215
|
return function(e) {
|
|
204
|
-
const
|
|
216
|
+
const n = [];
|
|
205
217
|
if (e && typeof e == "object")
|
|
206
218
|
for (const r in e) {
|
|
207
219
|
const i = e[r];
|
|
208
220
|
if (i != null) {
|
|
209
221
|
if (Array.isArray(i)) {
|
|
210
|
-
|
|
211
|
-
|
|
222
|
+
n.push(
|
|
223
|
+
C(r, i, {
|
|
212
224
|
style: "form",
|
|
213
225
|
explode: !0,
|
|
214
|
-
...
|
|
215
|
-
allowReserved: (
|
|
226
|
+
...s == null ? void 0 : s.array,
|
|
227
|
+
allowReserved: (s == null ? void 0 : s.allowReserved) || !1
|
|
216
228
|
})
|
|
217
229
|
);
|
|
218
230
|
continue;
|
|
219
231
|
}
|
|
220
232
|
if (typeof i == "object") {
|
|
221
|
-
|
|
222
|
-
|
|
233
|
+
n.push(
|
|
234
|
+
q(r, i, {
|
|
223
235
|
style: "deepObject",
|
|
224
236
|
explode: !0,
|
|
225
|
-
...
|
|
226
|
-
allowReserved: (
|
|
237
|
+
...s == null ? void 0 : s.object,
|
|
238
|
+
allowReserved: (s == null ? void 0 : s.allowReserved) || !1
|
|
227
239
|
})
|
|
228
240
|
);
|
|
229
241
|
continue;
|
|
230
242
|
}
|
|
231
|
-
|
|
243
|
+
n.push(p(r, i, s));
|
|
232
244
|
}
|
|
233
245
|
}
|
|
234
|
-
return
|
|
246
|
+
return n.join("&");
|
|
235
247
|
};
|
|
236
248
|
}
|
|
237
|
-
function
|
|
238
|
-
let e =
|
|
239
|
-
for (const
|
|
240
|
-
let r =
|
|
249
|
+
function k(s, t) {
|
|
250
|
+
let e = s;
|
|
251
|
+
for (const n of s.match(D) ?? []) {
|
|
252
|
+
let r = n.substring(1, n.length - 1), i = !1, a = "simple";
|
|
241
253
|
if (r.endsWith("*") && (i = !0, r = r.substring(0, r.length - 1)), r.startsWith(".") ? (a = "label", r = r.substring(1)) : r.startsWith(";") && (a = "matrix", r = r.substring(1)), !t || t[r] === void 0 || t[r] === null)
|
|
242
254
|
continue;
|
|
243
|
-
const
|
|
244
|
-
if (Array.isArray(
|
|
245
|
-
e = e.replace(
|
|
246
|
-
s,
|
|
247
|
-
O(r, c, { style: a, explode: i })
|
|
248
|
-
);
|
|
255
|
+
const l = t[r];
|
|
256
|
+
if (Array.isArray(l)) {
|
|
257
|
+
e = e.replace(n, C(r, l, { style: a, explode: i }));
|
|
249
258
|
continue;
|
|
250
259
|
}
|
|
251
|
-
if (typeof
|
|
252
|
-
e = e.replace(
|
|
253
|
-
s,
|
|
254
|
-
x(r, c, { style: a, explode: i })
|
|
255
|
-
);
|
|
260
|
+
if (typeof l == "object") {
|
|
261
|
+
e = e.replace(n, q(r, l, { style: a, explode: i }));
|
|
256
262
|
continue;
|
|
257
263
|
}
|
|
258
264
|
if (a === "matrix") {
|
|
259
|
-
e = e.replace(
|
|
260
|
-
s,
|
|
261
|
-
`;${R(r, c)}`
|
|
262
|
-
);
|
|
265
|
+
e = e.replace(n, `;${p(r, l)}`);
|
|
263
266
|
continue;
|
|
264
267
|
}
|
|
265
|
-
e = e.replace(
|
|
268
|
+
e = e.replace(n, a === "label" ? `.${encodeURIComponent(l)}` : encodeURIComponent(l));
|
|
266
269
|
}
|
|
267
270
|
return e;
|
|
268
271
|
}
|
|
269
|
-
function
|
|
270
|
-
return JSON.stringify(
|
|
272
|
+
function F(s) {
|
|
273
|
+
return JSON.stringify(s);
|
|
271
274
|
}
|
|
272
|
-
function
|
|
275
|
+
function N(s, t) {
|
|
273
276
|
var r;
|
|
274
|
-
let e = `${t.baseUrl}${
|
|
275
|
-
(r = t.params) != null && r.path && (e =
|
|
276
|
-
let
|
|
277
|
-
return
|
|
277
|
+
let e = `${t.baseUrl}${s}`;
|
|
278
|
+
(r = t.params) != null && r.path && (e = k(e, t.params.path));
|
|
279
|
+
let n = t.querySerializer(t.params.query ?? {});
|
|
280
|
+
return n.startsWith("?") && (n = n.substring(1)), n && (e += `?${n}`), e;
|
|
278
281
|
}
|
|
279
|
-
function
|
|
282
|
+
function x(...s) {
|
|
280
283
|
const t = new Headers();
|
|
281
|
-
for (const e of
|
|
284
|
+
for (const e of s) {
|
|
282
285
|
if (!e || typeof e != "object")
|
|
283
286
|
continue;
|
|
284
|
-
const
|
|
285
|
-
for (const [r, i] of
|
|
287
|
+
const n = e instanceof Headers ? e.entries() : Object.entries(e);
|
|
288
|
+
for (const [r, i] of n)
|
|
286
289
|
if (i === null)
|
|
287
290
|
t.delete(r);
|
|
288
291
|
else if (Array.isArray(i))
|
|
289
292
|
for (const a of i)
|
|
290
293
|
t.append(r, a);
|
|
291
|
-
else
|
|
292
|
-
i !== void 0 && t.set(r, i);
|
|
294
|
+
else i !== void 0 && t.set(r, i);
|
|
293
295
|
}
|
|
294
296
|
return t;
|
|
295
297
|
}
|
|
296
|
-
function
|
|
297
|
-
apiKey:
|
|
298
|
+
function W({
|
|
299
|
+
apiKey: s,
|
|
298
300
|
baseUrl: t = "https://api.cycle.io",
|
|
299
301
|
hubId: e,
|
|
300
|
-
fetch:
|
|
302
|
+
fetch: n
|
|
301
303
|
}) {
|
|
302
|
-
const r =
|
|
304
|
+
const r = L({
|
|
303
305
|
baseUrl: t,
|
|
304
|
-
fetch:
|
|
306
|
+
fetch: n || fetch
|
|
305
307
|
}), i = {
|
|
306
|
-
async onRequest(a) {
|
|
307
|
-
return a.headers.set("Authorization", `Bearer ${
|
|
308
|
+
async onRequest({ request: a }) {
|
|
309
|
+
return a.headers.set("Authorization", `Bearer ${s}`), a.headers.set("X-Hub-Id", e), a;
|
|
308
310
|
}
|
|
309
311
|
};
|
|
310
312
|
return r.use(i), r;
|
|
311
313
|
}
|
|
312
314
|
export {
|
|
313
|
-
|
|
315
|
+
W as getClient
|
|
314
316
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(h,
|
|
1
|
+
(function(h,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(h=typeof globalThis<"u"?globalThis:h||self,m(h["Cycle API Client"]={}))})(this,function(h){"use strict";const m={"Content-Type":"application/json"},H=/\{[^{}]+\}/g;class I extends Request{constructor(t,e){super(t,e);for(const n in e)n in this||(this[n]=e[n])}}function D(){return Math.random().toString(36).slice(2,11)}function P(i){let{baseUrl:t="",fetch:e=globalThis.fetch,querySerializer:n,bodySerializer:r,headers:s,...o}={...i};t.endsWith("/")&&(t=t.substring(0,t.length-1)),s=q(m,s);const a=[];async function u(c,l){const{fetch:R=e,headers:M,params:w={},parseAs:S="json",querySerializer:j,bodySerializer:U=r??k,...N}=l||{};let $=typeof n=="function"?n:O(n);j&&($=typeof j=="function"?j:O({...typeof n=="object"?n:{},...j}));const b={redirect:"follow",...o,...N,headers:q(s,M,w.header)};b.body&&(b.body=U(b.body)),b.body instanceof FormData&&b.headers.delete("Content-Type");let A,T,g=new I(v(c,{baseUrl:t,params:w,querySerializer:$}),b);if(a.length){A=D(),T=Object.freeze({baseUrl:t,fetch:R,parseAs:S,querySerializer:$,bodySerializer:U});for(const d of a)if(d&&typeof d=="object"&&typeof d.onRequest=="function"){const y=await d.onRequest({request:g,schemaPath:c,params:w,options:T,id:A});if(y){if(!(y instanceof Request))throw new Error("onRequest: must return new Request() when modifying the request");g=y}}}let f=await R(g);if(a.length)for(let d=a.length-1;d>=0;d--){const y=a[d];if(y&&typeof y=="object"&&typeof y.onResponse=="function"){const x=await y.onResponse({request:g,response:f,schemaPath:c,params:w,options:T,id:A});if(x){if(!(x instanceof Response))throw new Error("onResponse: must return new Response() when modifying the response");f=x}}}if(f.status===204||f.headers.get("Content-Length")==="0")return f.ok?{data:{},response:f}:{error:{},response:f};if(f.ok)return S==="stream"?{data:f.body,response:f}:{data:await f[S](),response:f};let E=await f.text();try{E=JSON.parse(E)}catch{}return{error:E,response:f}}return{async GET(c,l){return u(c,{...l,method:"GET"})},async PUT(c,l){return u(c,{...l,method:"PUT"})},async POST(c,l){return u(c,{...l,method:"POST"})},async DELETE(c,l){return u(c,{...l,method:"DELETE"})},async OPTIONS(c,l){return u(c,{...l,method:"OPTIONS"})},async HEAD(c,l){return u(c,{...l,method:"HEAD"})},async PATCH(c,l){return u(c,{...l,method:"PATCH"})},async TRACE(c,l){return u(c,{...l,method:"TRACE"})},use(...c){for(const l of c)if(l){if(typeof l!="object"||!("onRequest"in l||"onResponse"in l))throw new Error("Middleware must be an object with one of `onRequest()` or `onResponse()`");a.push(l)}},eject(...c){for(const l of c){const R=a.indexOf(l);R!==-1&&a.splice(R,1)}}}}function p(i,t,e){if(t==null)return"";if(typeof t=="object")throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${i}=${(e==null?void 0:e.allowReserved)===!0?t:encodeURIComponent(t)}`}function z(i,t,e){if(!t||typeof t!="object")return"";const n=[],r={simple:",",label:".",matrix:";"}[e.style]||"&";if(e.style!=="deepObject"&&e.explode===!1){for(const a in t)n.push(a,e.allowReserved===!0?t[a]:encodeURIComponent(t[a]));const o=n.join(",");switch(e.style){case"form":return`${i}=${o}`;case"label":return`.${o}`;case"matrix":return`;${i}=${o}`;default:return o}}for(const o in t){const a=e.style==="deepObject"?`${i}[${o}]`:o;n.push(p(a,t[o],e))}const s=n.join(r);return e.style==="label"||e.style==="matrix"?`${r}${s}`:s}function C(i,t,e){if(!Array.isArray(t))return"";if(e.explode===!1){const s={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[e.style]||",",o=(e.allowReserved===!0?t:t.map(a=>encodeURIComponent(a))).join(s);switch(e.style){case"simple":return o;case"label":return`.${o}`;case"matrix":return`;${i}=${o}`;default:return`${i}=${o}`}}const n={simple:",",label:".",matrix:";"}[e.style]||"&",r=[];for(const s of t)e.style==="simple"||e.style==="label"?r.push(e.allowReserved===!0?s:encodeURIComponent(s)):r.push(p(i,s,e));return e.style==="label"||e.style==="matrix"?`${n}${r.join(n)}`:r.join(n)}function O(i){return function(e){const n=[];if(e&&typeof e=="object")for(const r in e){const s=e[r];if(s!=null){if(Array.isArray(s)){n.push(C(r,s,{style:"form",explode:!0,...i==null?void 0:i.array,allowReserved:(i==null?void 0:i.allowReserved)||!1}));continue}if(typeof s=="object"){n.push(z(r,s,{style:"deepObject",explode:!0,...i==null?void 0:i.object,allowReserved:(i==null?void 0:i.allowReserved)||!1}));continue}n.push(p(r,s,i))}}return n.join("&")}}function L(i,t){let e=i;for(const n of i.match(H)??[]){let r=n.substring(1,n.length-1),s=!1,o="simple";if(r.endsWith("*")&&(s=!0,r=r.substring(0,r.length-1)),r.startsWith(".")?(o="label",r=r.substring(1)):r.startsWith(";")&&(o="matrix",r=r.substring(1)),!t||t[r]===void 0||t[r]===null)continue;const a=t[r];if(Array.isArray(a)){e=e.replace(n,C(r,a,{style:o,explode:s}));continue}if(typeof a=="object"){e=e.replace(n,z(r,a,{style:o,explode:s}));continue}if(o==="matrix"){e=e.replace(n,`;${p(r,a)}`);continue}e=e.replace(n,o==="label"?`.${encodeURIComponent(a)}`:encodeURIComponent(a))}return e}function k(i){return JSON.stringify(i)}function v(i,t){var r;let e=`${t.baseUrl}${i}`;(r=t.params)!=null&&r.path&&(e=L(e,t.params.path));let n=t.querySerializer(t.params.query??{});return n.startsWith("?")&&(n=n.substring(1)),n&&(e+=`?${n}`),e}function q(...i){const t=new Headers;for(const e of i){if(!e||typeof e!="object")continue;const n=e instanceof Headers?e.entries():Object.entries(e);for(const[r,s]of n)if(s===null)t.delete(r);else if(Array.isArray(s))for(const o of s)t.append(r,o);else s!==void 0&&t.set(r,s)}return t}function F({apiKey:i,baseUrl:t="https://api.cycle.io",hubId:e,fetch:n}){const r=P({baseUrl:t,fetch:n||fetch}),s={async onRequest({request:o}){return o.headers.set("Authorization",`Bearer ${i}`),o.headers.set("X-Hub-Id",e),o}};return r.use(s),r}h.getClient=F,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cycleplatform/api-client-typescript",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A Cycle API client for the web/nodejs with type safety.",
|
|
5
5
|
"main": "./dist/index.umd.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -21,8 +21,7 @@
|
|
|
21
21
|
"scripts": {
|
|
22
22
|
"test": "vitest",
|
|
23
23
|
"test:ts": "tsc --noEmit",
|
|
24
|
-
"build:
|
|
25
|
-
"build:client": "npm run build:spec && npx openapi-typescript ./api-spec/dist/platform.yml --output ./src/generated/types.ts",
|
|
24
|
+
"build:client": "openapi-typescript ./api-spec/platform/api.yml --output ./src/generated/types.ts",
|
|
26
25
|
"build:lib": "npm run build:client && vite build",
|
|
27
26
|
"prepublishOnly": "npm run build:lib"
|
|
28
27
|
},
|
|
@@ -42,13 +41,13 @@
|
|
|
42
41
|
},
|
|
43
42
|
"homepage": "https://github.com/cycleplatform/api-client-typescript#readme",
|
|
44
43
|
"dependencies": {
|
|
45
|
-
"openapi-fetch": "0.
|
|
44
|
+
"openapi-fetch": "0.10.2"
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
|
-
"msw": "2.2
|
|
49
|
-
"openapi-typescript": "
|
|
50
|
-
"typescript": "^5.
|
|
51
|
-
"vite": "5.
|
|
52
|
-
"vitest": "
|
|
47
|
+
"msw": "^2.3.2",
|
|
48
|
+
"openapi-typescript": "^7.0.4",
|
|
49
|
+
"typescript": "^5.5.3",
|
|
50
|
+
"vite": "^5.3.4",
|
|
51
|
+
"vitest": "^2.0.3"
|
|
53
52
|
}
|
|
54
53
|
}
|