@cycleplatform/api-client-typescript 0.1.15 → 0.2.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/README.md +25 -22
- package/dist/index.js +275 -90
- package/dist/index.umd.cjs +1 -1
- package/package.json +45 -45
- package/src/generated/types.ts +6834 -5569
- package/src/index.ts +24 -55
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ _This is an auto-generated API client based on the [OpenAPI Spec for Cycle](http
|
|
|
8
8
|
|
|
9
9
|
This client utilizes [openapi-typescript](https://github.com/drwpow/openapi-typescript) to generate the type definitions for our client. The client itself is a pre-built [openapi-fetch](https://github.com/drwpow/openapi-typescript/tree/main/packages/openapi-fetch) client for convenience.
|
|
10
10
|
|
|
11
|
-
Every request should be typesafe, and only endpoints described in the spec will be valid in Typescript as the first parameter to `GET`, `POST`, `PATCH`
|
|
11
|
+
Every request should be typesafe, and only endpoints described in the spec will be valid in Typescript as the first parameter to `GET`, `POST`, `PATCH`, or `DELETE`
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
@@ -21,20 +21,22 @@ npm i @cycleplatform/api-client-typescript
|
|
|
21
21
|
### Making a Request
|
|
22
22
|
|
|
23
23
|
```ts
|
|
24
|
-
import {
|
|
25
|
-
client,
|
|
26
|
-
setAuthToken,
|
|
27
|
-
setHubScope,
|
|
28
|
-
} from "@cycleplatform/api-client-typescript";
|
|
24
|
+
import { client } from "@cycleplatform/api-client-typescript";
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
const client = getClient({
|
|
27
|
+
apiKey: "<your-api-key>",
|
|
28
|
+
hubId: "<your-hub-id>",
|
|
29
|
+
});
|
|
32
30
|
|
|
33
31
|
const resp = await client.GET("/v1/containers/{containerId}", {
|
|
34
|
-
|
|
32
|
+
params: {
|
|
33
|
+
path: {
|
|
34
|
+
containerId: "<container-id>",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
35
37
|
});
|
|
36
38
|
|
|
37
|
-
console.log(
|
|
39
|
+
console.log(resp.data, resp.error);
|
|
38
40
|
```
|
|
39
41
|
|
|
40
42
|
### Overriding the Base URL
|
|
@@ -42,24 +44,25 @@ console.log(test.data, test.error);
|
|
|
42
44
|
In some cases it may be necessary to override the default URL of `https://api.cycle.io`. For example, if you are running a custom Cycle core, your API endpoint will be different than the default.
|
|
43
45
|
|
|
44
46
|
```ts
|
|
45
|
-
import {
|
|
46
|
-
client,
|
|
47
|
-
setAuthToken,
|
|
48
|
-
setHubScope,
|
|
49
|
-
setBaseUrl,
|
|
50
|
-
} from "@cycleplatform/api-client-typescript";
|
|
47
|
+
import { client } from "@cycleplatform/api-client-typescript";
|
|
51
48
|
|
|
52
|
-
|
|
53
|
-
setBaseUrl("https://api.my-company.cycle.io");
|
|
49
|
+
const baseUrl = "https://api.my-company.cycle.io";
|
|
54
50
|
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
const client = getClient({
|
|
52
|
+
baseUrl,
|
|
53
|
+
apiKey: "<your-api-key>",
|
|
54
|
+
hubId: "<your-hub-id>",
|
|
55
|
+
});
|
|
57
56
|
|
|
58
57
|
const resp = await client.GET("/v1/containers/{containerId}", {
|
|
59
|
-
|
|
58
|
+
params: {
|
|
59
|
+
path: {
|
|
60
|
+
containerId: "<container-id>",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
60
63
|
});
|
|
61
64
|
|
|
62
|
-
console.log(
|
|
65
|
+
console.log(resp.data, resp.error);
|
|
63
66
|
```
|
|
64
67
|
|
|
65
68
|
## Development
|
package/dist/index.js
CHANGED
|
@@ -1,129 +1,314 @@
|
|
|
1
|
-
const
|
|
1
|
+
const D = {
|
|
2
2
|
"Content-Type": "application/json"
|
|
3
|
-
},
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
}, H = /\{[^{}]+\}/g;
|
|
4
|
+
function U(n) {
|
|
5
|
+
let {
|
|
6
|
+
baseUrl: t = "",
|
|
7
|
+
fetch: e = globalThis.fetch,
|
|
8
|
+
querySerializer: s,
|
|
9
|
+
bodySerializer: r,
|
|
10
|
+
headers: i,
|
|
11
|
+
...a
|
|
12
|
+
} = { ...n };
|
|
13
|
+
t.endsWith("/") && (t = t.substring(0, t.length - 1)), i = z(D, i);
|
|
14
|
+
const c = [];
|
|
15
|
+
async function u(o, l) {
|
|
16
|
+
let {
|
|
17
|
+
fetch: m = e,
|
|
18
|
+
headers: q,
|
|
19
|
+
params: p = {},
|
|
20
|
+
parseAs: j = "json",
|
|
21
|
+
querySerializer: w,
|
|
22
|
+
bodySerializer: S = r ?? I,
|
|
23
|
+
...C
|
|
24
|
+
} = l || {}, $ = typeof s == "function" ? s : T(s);
|
|
25
|
+
w && ($ = typeof w == "function" ? w : T({
|
|
26
|
+
...typeof s == "object" ? s : {},
|
|
27
|
+
...w
|
|
28
|
+
}));
|
|
29
|
+
const h = {
|
|
30
|
+
redirect: "follow",
|
|
31
|
+
...a,
|
|
32
|
+
...C,
|
|
33
|
+
headers: z(i, q, p.header)
|
|
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
|
|
46
|
+
};
|
|
47
|
+
for (const d of c)
|
|
48
|
+
if (d && typeof d == "object" && typeof d.onRequest == "function") {
|
|
49
|
+
b.schemaPath = o, b.params = p;
|
|
50
|
+
const y = await d.onRequest(b, E);
|
|
51
|
+
if (y) {
|
|
52
|
+
if (!(y instanceof Request))
|
|
53
|
+
throw new Error(
|
|
54
|
+
"Middleware must return new Request() when modifying the request"
|
|
55
|
+
);
|
|
56
|
+
b = y;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
let f = await m(b);
|
|
60
|
+
for (let d = c.length - 1; d >= 0; d--) {
|
|
61
|
+
const y = c[d];
|
|
62
|
+
if (y && typeof y == "object" && typeof y.onResponse == "function") {
|
|
63
|
+
const A = await y.onResponse(f, E);
|
|
64
|
+
if (A) {
|
|
65
|
+
if (!(A instanceof Response))
|
|
66
|
+
throw new Error(
|
|
67
|
+
"Middleware must return new Response() when modifying the response"
|
|
68
|
+
);
|
|
69
|
+
f = A;
|
|
70
|
+
}
|
|
20
71
|
}
|
|
21
|
-
return { data: m, response: s };
|
|
22
72
|
}
|
|
23
|
-
|
|
73
|
+
if (f.status === 204 || f.headers.get("Content-Length") === "0")
|
|
74
|
+
return f.ok ? { data: {}, response: f } : { error: {}, response: f };
|
|
75
|
+
if (f.ok)
|
|
76
|
+
return j === "stream" ? { data: f.body, response: f } : { data: await f[j](), response: f };
|
|
77
|
+
let g = await f.text();
|
|
24
78
|
try {
|
|
25
|
-
|
|
79
|
+
g = JSON.parse(g);
|
|
26
80
|
} catch {
|
|
27
|
-
d = await s.clone().text();
|
|
28
81
|
}
|
|
29
|
-
return { error:
|
|
82
|
+
return { error: g, response: f };
|
|
30
83
|
}
|
|
31
84
|
return {
|
|
32
85
|
/** Call a GET endpoint */
|
|
33
|
-
async GET(
|
|
34
|
-
return u(
|
|
86
|
+
async GET(o, l) {
|
|
87
|
+
return u(o, { ...l, method: "GET" });
|
|
35
88
|
},
|
|
36
89
|
/** Call a PUT endpoint */
|
|
37
|
-
async PUT(
|
|
38
|
-
return u(
|
|
90
|
+
async PUT(o, l) {
|
|
91
|
+
return u(o, { ...l, method: "PUT" });
|
|
39
92
|
},
|
|
40
93
|
/** Call a POST endpoint */
|
|
41
|
-
async POST(
|
|
42
|
-
return u(
|
|
94
|
+
async POST(o, l) {
|
|
95
|
+
return u(o, { ...l, method: "POST" });
|
|
43
96
|
},
|
|
44
97
|
/** Call a DELETE endpoint */
|
|
45
|
-
async DELETE(
|
|
46
|
-
return u(
|
|
98
|
+
async DELETE(o, l) {
|
|
99
|
+
return u(o, { ...l, method: "DELETE" });
|
|
47
100
|
},
|
|
48
101
|
/** Call a OPTIONS endpoint */
|
|
49
|
-
async OPTIONS(
|
|
50
|
-
return u(
|
|
102
|
+
async OPTIONS(o, l) {
|
|
103
|
+
return u(o, { ...l, method: "OPTIONS" });
|
|
51
104
|
},
|
|
52
105
|
/** Call a HEAD endpoint */
|
|
53
|
-
async HEAD(
|
|
54
|
-
return u(
|
|
106
|
+
async HEAD(o, l) {
|
|
107
|
+
return u(o, { ...l, method: "HEAD" });
|
|
55
108
|
},
|
|
56
109
|
/** Call a PATCH endpoint */
|
|
57
|
-
async PATCH(
|
|
58
|
-
return u(
|
|
110
|
+
async PATCH(o, l) {
|
|
111
|
+
return u(o, { ...l, method: "PATCH" });
|
|
59
112
|
},
|
|
60
113
|
/** Call a TRACE endpoint */
|
|
61
|
-
async TRACE(
|
|
62
|
-
return u(
|
|
114
|
+
async TRACE(o, l) {
|
|
115
|
+
return u(o, { ...l, method: "TRACE" });
|
|
116
|
+
},
|
|
117
|
+
/** Register middleware */
|
|
118
|
+
use(...o) {
|
|
119
|
+
for (const l of o)
|
|
120
|
+
if (l) {
|
|
121
|
+
if (typeof l != "object" || !("onRequest" in l || "onResponse" in l))
|
|
122
|
+
throw new Error(
|
|
123
|
+
"Middleware must be an object with one of `onRequest()` or `onResponse()`"
|
|
124
|
+
);
|
|
125
|
+
c.push(l);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
/** Unregister middleware */
|
|
129
|
+
eject(...o) {
|
|
130
|
+
for (const l of o) {
|
|
131
|
+
const m = c.indexOf(l);
|
|
132
|
+
m !== -1 && c.splice(m, 1);
|
|
133
|
+
}
|
|
63
134
|
}
|
|
64
135
|
};
|
|
65
136
|
}
|
|
66
|
-
function
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
137
|
+
function R(n, t, e) {
|
|
138
|
+
if (t == null)
|
|
139
|
+
return "";
|
|
140
|
+
if (typeof t == "object")
|
|
141
|
+
throw new Error(
|
|
142
|
+
"Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these."
|
|
143
|
+
);
|
|
144
|
+
return `${n}=${(e == null ? void 0 : e.allowReserved) === !0 ? t : encodeURIComponent(t)}`;
|
|
72
145
|
}
|
|
73
|
-
function
|
|
74
|
-
|
|
146
|
+
function x(n, t, e) {
|
|
147
|
+
if (!t || typeof t != "object")
|
|
148
|
+
return "";
|
|
149
|
+
const s = [], r = {
|
|
150
|
+
simple: ",",
|
|
151
|
+
label: ".",
|
|
152
|
+
matrix: ";"
|
|
153
|
+
}[e.style] || "&";
|
|
154
|
+
if (e.style !== "deepObject" && e.explode === !1) {
|
|
155
|
+
for (const c in t)
|
|
156
|
+
s.push(
|
|
157
|
+
c,
|
|
158
|
+
e.allowReserved === !0 ? t[c] : encodeURIComponent(t[c])
|
|
159
|
+
);
|
|
160
|
+
const a = s.join(",");
|
|
161
|
+
switch (e.style) {
|
|
162
|
+
case "form":
|
|
163
|
+
return `${n}=${a}`;
|
|
164
|
+
case "label":
|
|
165
|
+
return `.${a}`;
|
|
166
|
+
case "matrix":
|
|
167
|
+
return `;${n}=${a}`;
|
|
168
|
+
default:
|
|
169
|
+
return a;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
for (const a in t) {
|
|
173
|
+
const c = e.style === "deepObject" ? `${n}[${a}]` : a;
|
|
174
|
+
s.push(R(c, t[a], e));
|
|
175
|
+
}
|
|
176
|
+
const i = s.join(r);
|
|
177
|
+
return e.style === "label" || e.style === "matrix" ? `${r}${i}` : i;
|
|
75
178
|
}
|
|
76
|
-
function
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
179
|
+
function O(n, t, e) {
|
|
180
|
+
if (!Array.isArray(t))
|
|
181
|
+
return "";
|
|
182
|
+
if (e.explode === !1) {
|
|
183
|
+
const i = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[e.style] || ",", a = (e.allowReserved === !0 ? t : t.map((c) => encodeURIComponent(c))).join(i);
|
|
184
|
+
switch (e.style) {
|
|
185
|
+
case "simple":
|
|
186
|
+
return a;
|
|
187
|
+
case "label":
|
|
188
|
+
return `.${a}`;
|
|
189
|
+
case "matrix":
|
|
190
|
+
return `;${n}=${a}`;
|
|
191
|
+
case "spaceDelimited":
|
|
192
|
+
case "pipeDelimited":
|
|
193
|
+
default:
|
|
194
|
+
return `${n}=${a}`;
|
|
195
|
+
}
|
|
84
196
|
}
|
|
85
|
-
|
|
197
|
+
const s = { simple: ",", label: ".", matrix: ";" }[e.style] || "&", r = [];
|
|
198
|
+
for (const i of t)
|
|
199
|
+
e.style === "simple" || e.style === "label" ? r.push(e.allowReserved === !0 ? i : encodeURIComponent(i)) : r.push(R(n, i, e));
|
|
200
|
+
return e.style === "label" || e.style === "matrix" ? `${s}${r.join(s)}` : r.join(s);
|
|
86
201
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (
|
|
202
|
+
function T(n) {
|
|
203
|
+
return function(e) {
|
|
204
|
+
const s = [];
|
|
205
|
+
if (e && typeof e == "object")
|
|
206
|
+
for (const r in e) {
|
|
207
|
+
const i = e[r];
|
|
208
|
+
if (i != null) {
|
|
209
|
+
if (Array.isArray(i)) {
|
|
210
|
+
s.push(
|
|
211
|
+
O(r, i, {
|
|
212
|
+
style: "form",
|
|
213
|
+
explode: !0,
|
|
214
|
+
...n == null ? void 0 : n.array,
|
|
215
|
+
allowReserved: (n == null ? void 0 : n.allowReserved) || !1
|
|
216
|
+
})
|
|
217
|
+
);
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (typeof i == "object") {
|
|
221
|
+
s.push(
|
|
222
|
+
x(r, i, {
|
|
223
|
+
style: "deepObject",
|
|
224
|
+
explode: !0,
|
|
225
|
+
...n == null ? void 0 : n.object,
|
|
226
|
+
allowReserved: (n == null ? void 0 : n.allowReserved) || !1
|
|
227
|
+
})
|
|
228
|
+
);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
s.push(R(r, i, n));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return s.join("&");
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function P(n, t) {
|
|
238
|
+
let e = n;
|
|
239
|
+
for (const s of n.match(H) ?? []) {
|
|
240
|
+
let r = s.substring(1, s.length - 1), i = !1, a = "simple";
|
|
241
|
+
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)
|
|
91
242
|
continue;
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
243
|
+
const c = t[r];
|
|
244
|
+
if (Array.isArray(c)) {
|
|
245
|
+
e = e.replace(
|
|
246
|
+
s,
|
|
247
|
+
O(r, c, { style: a, explode: i })
|
|
248
|
+
);
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (typeof c == "object") {
|
|
252
|
+
e = e.replace(
|
|
253
|
+
s,
|
|
254
|
+
x(r, c, { style: a, explode: i })
|
|
255
|
+
);
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (a === "matrix") {
|
|
259
|
+
e = e.replace(
|
|
260
|
+
s,
|
|
261
|
+
`;${R(r, c)}`
|
|
262
|
+
);
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
e = e.replace(s, a === "label" ? `.${c}` : c);
|
|
95
266
|
}
|
|
96
|
-
return
|
|
97
|
-
}
|
|
98
|
-
let h, b, U = "https://api.cycle.io";
|
|
99
|
-
function D(t) {
|
|
100
|
-
h = t;
|
|
267
|
+
return e;
|
|
101
268
|
}
|
|
102
|
-
function I(
|
|
103
|
-
|
|
269
|
+
function I(n) {
|
|
270
|
+
return JSON.stringify(n);
|
|
104
271
|
}
|
|
105
|
-
function
|
|
106
|
-
|
|
272
|
+
function L(n, t) {
|
|
273
|
+
var r;
|
|
274
|
+
let e = `${t.baseUrl}${n}`;
|
|
275
|
+
(r = t.params) != null && r.path && (e = P(e, t.params.path));
|
|
276
|
+
let s = t.querySerializer(t.params.query ?? {});
|
|
277
|
+
return s.startsWith("?") && (s = s.substring(1)), s && (e += `?${s}`), e;
|
|
107
278
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
279
|
+
function z(...n) {
|
|
280
|
+
const t = new Headers();
|
|
281
|
+
for (const e of n) {
|
|
282
|
+
if (!e || typeof e != "object")
|
|
283
|
+
continue;
|
|
284
|
+
const s = e instanceof Headers ? e.entries() : Object.entries(e);
|
|
285
|
+
for (const [r, i] of s)
|
|
286
|
+
if (i === null)
|
|
287
|
+
t.delete(r);
|
|
288
|
+
else if (Array.isArray(i))
|
|
289
|
+
for (const a of i)
|
|
290
|
+
t.append(r, a);
|
|
291
|
+
else
|
|
292
|
+
i !== void 0 && t.set(r, i);
|
|
115
293
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
294
|
+
return t;
|
|
295
|
+
}
|
|
296
|
+
function k({
|
|
297
|
+
apiKey: n,
|
|
298
|
+
baseUrl: t = "https://api.cycle.io",
|
|
299
|
+
hubId: e,
|
|
300
|
+
fetch: s
|
|
301
|
+
}) {
|
|
302
|
+
const r = U({
|
|
303
|
+
baseUrl: t,
|
|
304
|
+
fetch: s || fetch
|
|
305
|
+
}), i = {
|
|
306
|
+
async onRequest(a) {
|
|
307
|
+
return a.headers.set("Authorization", `Bearer ${n}`), a.headers.set("X-Hub-Id", e), a;
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
return r.use(i), r;
|
|
122
311
|
}
|
|
123
312
|
export {
|
|
124
|
-
|
|
125
|
-
B as querySerializer,
|
|
126
|
-
D as setAuthToken,
|
|
127
|
-
k as setBaseUrl,
|
|
128
|
-
I as setHubScope
|
|
313
|
+
k as getClient
|
|
129
314
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(h,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(h=typeof globalThis<"u"?globalThis:h||self,b(h["Cycle API Client"]={}))})(this,function(h){"use strict";const b={"Content-Type":"application/json"},P=/\{[^{}]+\}/g;function D(n){let{baseUrl:t="",fetch:e=globalThis.fetch,querySerializer:i,bodySerializer:r,headers:s,...a}={...n};t.endsWith("/")&&(t=t.substring(0,t.length-1)),s=O(b,s);const o=[];async function u(c,l){let{fetch:p=e,headers:M,params:g={},parseAs:$="json",querySerializer:j,bodySerializer:C=r??U,...k}=l||{},A=typeof i=="function"?i:z(i);j&&(A=typeof j=="function"?j:z({...typeof i=="object"?i:{},...j}));const m={redirect:"follow",...a,...k,headers:O(s,M,g.header)};m.body&&(m.body=C(m.body)),m.body instanceof FormData&&m.headers.delete("Content-Type");let w=new Request(I(c,{baseUrl:t,params:g,querySerializer:A}),m);const q={baseUrl:t,fetch:p,parseAs:$,querySerializer:A,bodySerializer:C};for(const d of o)if(d&&typeof d=="object"&&typeof d.onRequest=="function"){w.schemaPath=c,w.params=g;const y=await d.onRequest(w,q);if(y){if(!(y instanceof Request))throw new Error("Middleware must return new Request() when modifying the request");w=y}}let f=await p(w);for(let d=o.length-1;d>=0;d--){const y=o[d];if(y&&typeof y=="object"&&typeof y.onResponse=="function"){const T=await y.onResponse(f,q);if(T){if(!(T instanceof Response))throw new Error("Middleware must return new Response() when modifying the response");f=T}}}if(f.status===204||f.headers.get("Content-Length")==="0")return f.ok?{data:{},response:f}:{error:{},response:f};if(f.ok)return $==="stream"?{data:f.body,response:f}:{data:await f[$](),response:f};let S=await f.text();try{S=JSON.parse(S)}catch{}return{error:S,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()`");o.push(l)}},eject(...c){for(const l of c){const p=o.indexOf(l);p!==-1&&o.splice(p,1)}}}}function R(n,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`${n}=${(e==null?void 0:e.allowReserved)===!0?t:encodeURIComponent(t)}`}function E(n,t,e){if(!t||typeof t!="object")return"";const i=[],r={simple:",",label:".",matrix:";"}[e.style]||"&";if(e.style!=="deepObject"&&e.explode===!1){for(const o in t)i.push(o,e.allowReserved===!0?t[o]:encodeURIComponent(t[o]));const a=i.join(",");switch(e.style){case"form":return`${n}=${a}`;case"label":return`.${a}`;case"matrix":return`;${n}=${a}`;default:return a}}for(const a in t){const o=e.style==="deepObject"?`${n}[${a}]`:a;i.push(R(o,t[a],e))}const s=i.join(r);return e.style==="label"||e.style==="matrix"?`${r}${s}`:s}function x(n,t,e){if(!Array.isArray(t))return"";if(e.explode===!1){const s={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[e.style]||",",a=(e.allowReserved===!0?t:t.map(o=>encodeURIComponent(o))).join(s);switch(e.style){case"simple":return a;case"label":return`.${a}`;case"matrix":return`;${n}=${a}`;case"spaceDelimited":case"pipeDelimited":default:return`${n}=${a}`}}const i={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(R(n,s,e));return e.style==="label"||e.style==="matrix"?`${i}${r.join(i)}`:r.join(i)}function z(n){return function(e){const i=[];if(e&&typeof e=="object")for(const r in e){const s=e[r];if(s!=null){if(Array.isArray(s)){i.push(x(r,s,{style:"form",explode:!0,...n==null?void 0:n.array,allowReserved:(n==null?void 0:n.allowReserved)||!1}));continue}if(typeof s=="object"){i.push(E(r,s,{style:"deepObject",explode:!0,...n==null?void 0:n.object,allowReserved:(n==null?void 0:n.allowReserved)||!1}));continue}i.push(R(r,s,n))}}return i.join("&")}}function H(n,t){let e=n;for(const i of n.match(P)??[]){let r=i.substring(1,i.length-1),s=!1,a="simple";if(r.endsWith("*")&&(s=!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)continue;const o=t[r];if(Array.isArray(o)){e=e.replace(i,x(r,o,{style:a,explode:s}));continue}if(typeof o=="object"){e=e.replace(i,E(r,o,{style:a,explode:s}));continue}if(a==="matrix"){e=e.replace(i,`;${R(r,o)}`);continue}e=e.replace(i,a==="label"?`.${o}`:o)}return e}function U(n){return JSON.stringify(n)}function I(n,t){var r;let e=`${t.baseUrl}${n}`;(r=t.params)!=null&&r.path&&(e=H(e,t.params.path));let i=t.querySerializer(t.params.query??{});return i.startsWith("?")&&(i=i.substring(1)),i&&(e+=`?${i}`),e}function O(...n){const t=new Headers;for(const e of n){if(!e||typeof e!="object")continue;const i=e instanceof Headers?e.entries():Object.entries(e);for(const[r,s]of i)if(s===null)t.delete(r);else if(Array.isArray(s))for(const a of s)t.append(r,a);else s!==void 0&&t.set(r,s)}return t}function L({apiKey:n,baseUrl:t="https://api.cycle.io",hubId:e,fetch:i}){const r=D({baseUrl:t,fetch:i||fetch}),s={async onRequest(a){return a.headers.set("Authorization",`Bearer ${n}`),a.headers.set("X-Hub-Id",e),a}};return r.use(s),r}h.getClient=L,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
"name": "@cycleplatform/api-client-typescript",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A Cycle API client for the web/nodejs with type safety.",
|
|
5
|
+
"main": "./dist/index.umd.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.umd.cjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"types": "./src/index.ts",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "vitest",
|
|
17
|
+
"test:ts": "tsc --noEmit",
|
|
18
|
+
"build:spec": "(cd api-spec; npm run build:platform)",
|
|
19
|
+
"build:client": "npm run build:spec && npx openapi-typescript ./api-spec/dist/platform.yml --output ./src/generated/types.ts",
|
|
20
|
+
"build:lib": "npm run build:client && vite build",
|
|
21
|
+
"prepublishOnly": "npm run build:lib"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/cycleplatform/api-client-typescript.git"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"cycleplatform",
|
|
29
|
+
"api",
|
|
30
|
+
"client"
|
|
31
|
+
],
|
|
32
|
+
"author": "Petrichor Holdings, Inc.",
|
|
33
|
+
"license": "Apache-2.0",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/cycleplatform/api-client-typescript/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/cycleplatform/api-client-typescript#readme",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"openapi-fetch": "0.9.3"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"msw": "2.2.13",
|
|
43
|
+
"openapi-typescript": "6.7.5",
|
|
44
|
+
"typescript": "^5.4.4",
|
|
45
|
+
"vite": "5.2.8",
|
|
46
|
+
"vitest": "1.4.0"
|
|
12
47
|
}
|
|
13
|
-
},
|
|
14
|
-
"types": "./src/index.ts",
|
|
15
|
-
"scripts": {
|
|
16
|
-
"test": "vitest",
|
|
17
|
-
"test:ts": "tsc --noEmit",
|
|
18
|
-
"build:spec": "(cd api-spec; npm run build:public && npm run build:internal)",
|
|
19
|
-
"build:client": "npm run build:spec && npx openapi-typescript ./api-spec/dist/public-api.yml --output ./src/generated/types.ts",
|
|
20
|
-
"build:lib": "npm run build:client && vite build",
|
|
21
|
-
"prepublishOnly": "npm run build:lib"
|
|
22
|
-
},
|
|
23
|
-
"repository": {
|
|
24
|
-
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/cycleplatform/api-client-typescript.git"
|
|
26
|
-
},
|
|
27
|
-
"keywords": [
|
|
28
|
-
"cycleplatform",
|
|
29
|
-
"api",
|
|
30
|
-
"client"
|
|
31
|
-
],
|
|
32
|
-
"author": "Petrichor Holdings, Inc.",
|
|
33
|
-
"license": "Apache-2.0",
|
|
34
|
-
"bugs": {
|
|
35
|
-
"url": "https://github.com/cycleplatform/api-client-typescript/issues"
|
|
36
|
-
},
|
|
37
|
-
"homepage": "https://github.com/cycleplatform/api-client-typescript#readme",
|
|
38
|
-
"dependencies": {
|
|
39
|
-
"openapi-fetch": "0.7.2"
|
|
40
|
-
},
|
|
41
|
-
"devDependencies": {
|
|
42
|
-
"msw": "1.2.3",
|
|
43
|
-
"openapi-typescript": "6.4.4",
|
|
44
|
-
"typescript": "^5.0.4",
|
|
45
|
-
"vite": "4.4.11",
|
|
46
|
-
"vitest": "0.33.0"
|
|
47
|
-
}
|
|
48
48
|
}
|