@cycleplatform/api-client-typescript 0.1.7 → 0.1.9
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 +99 -64
- package/dist/index.umd.cjs +1 -1
- package/package.json +6 -6
- package/src/generated/types.ts +1136 -1136
package/dist/index.js
CHANGED
|
@@ -1,94 +1,129 @@
|
|
|
1
|
-
const
|
|
1
|
+
const O = {
|
|
2
2
|
"Content-Type": "application/json"
|
|
3
|
-
}
|
|
4
|
-
function
|
|
5
|
-
const
|
|
6
|
-
...
|
|
7
|
-
...
|
|
3
|
+
}, j = /\/*$/;
|
|
4
|
+
function E(t = {}) {
|
|
5
|
+
const { fetch: r = globalThis.fetch, querySerializer: e, bodySerializer: a, ...i } = t, c = new Headers({
|
|
6
|
+
...O,
|
|
7
|
+
...i.headers ?? {}
|
|
8
8
|
});
|
|
9
|
-
async function
|
|
10
|
-
const { headers:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
9
|
+
async function u(n, o) {
|
|
10
|
+
const { headers: H, body: S, params: p = {}, parseAs: f = "json", querySerializer: w = e ?? z, bodySerializer: A = a ?? L, ...g } = o || {}, C = P(n, { baseUrl: i.baseUrl, params: p, querySerializer: w }), T = R(c, H, p.header), l = { redirect: "follow", ...i, ...g, headers: T };
|
|
11
|
+
S && (l.body = A(S)), l.body instanceof FormData && T.delete("Content-Type");
|
|
12
|
+
const s = await r(C, l);
|
|
13
|
+
if (s.status === 204 || s.headers.get("Content-Length") === "0")
|
|
14
|
+
return s.ok ? { data: {}, response: s } : { error: {}, response: s };
|
|
15
|
+
if (s.ok) {
|
|
16
|
+
let m = s.body;
|
|
17
|
+
if (f !== "stream") {
|
|
18
|
+
const y = s.clone();
|
|
19
|
+
m = typeof y[f] == "function" ? await y[f]() : await y.text();
|
|
20
|
+
}
|
|
21
|
+
return { data: m, response: s };
|
|
22
|
+
}
|
|
23
|
+
let d = {};
|
|
24
|
+
try {
|
|
25
|
+
d = await s.clone().json();
|
|
26
|
+
} catch {
|
|
27
|
+
d = await s.clone().text();
|
|
28
|
+
}
|
|
29
|
+
return { error: d, response: s };
|
|
27
30
|
}
|
|
28
31
|
return {
|
|
29
32
|
/** Call a GET endpoint */
|
|
30
|
-
async
|
|
31
|
-
return
|
|
33
|
+
async GET(n, o) {
|
|
34
|
+
return u(n, { ...o, method: "GET" });
|
|
32
35
|
},
|
|
33
36
|
/** Call a PUT endpoint */
|
|
34
|
-
async
|
|
35
|
-
return
|
|
37
|
+
async PUT(n, o) {
|
|
38
|
+
return u(n, { ...o, method: "PUT" });
|
|
36
39
|
},
|
|
37
40
|
/** Call a POST endpoint */
|
|
38
|
-
async
|
|
39
|
-
return
|
|
41
|
+
async POST(n, o) {
|
|
42
|
+
return u(n, { ...o, method: "POST" });
|
|
40
43
|
},
|
|
41
44
|
/** Call a DELETE endpoint */
|
|
42
|
-
async
|
|
43
|
-
return
|
|
45
|
+
async DELETE(n, o) {
|
|
46
|
+
return u(n, { ...o, method: "DELETE" });
|
|
44
47
|
},
|
|
45
48
|
/** Call a OPTIONS endpoint */
|
|
46
|
-
async
|
|
47
|
-
return
|
|
49
|
+
async OPTIONS(n, o) {
|
|
50
|
+
return u(n, { ...o, method: "OPTIONS" });
|
|
48
51
|
},
|
|
49
52
|
/** Call a HEAD endpoint */
|
|
50
|
-
async
|
|
51
|
-
return
|
|
53
|
+
async HEAD(n, o) {
|
|
54
|
+
return u(n, { ...o, method: "HEAD" });
|
|
52
55
|
},
|
|
53
56
|
/** Call a PATCH endpoint */
|
|
54
|
-
async
|
|
55
|
-
return
|
|
57
|
+
async PATCH(n, o) {
|
|
58
|
+
return u(n, { ...o, method: "PATCH" });
|
|
56
59
|
},
|
|
57
60
|
/** Call a TRACE endpoint */
|
|
58
|
-
async
|
|
59
|
-
return
|
|
61
|
+
async TRACE(n, o) {
|
|
62
|
+
return u(n, { ...o, method: "TRACE" });
|
|
60
63
|
}
|
|
61
64
|
};
|
|
62
65
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
function z(t) {
|
|
67
|
+
const r = new URLSearchParams();
|
|
68
|
+
if (t && typeof t == "object")
|
|
69
|
+
for (const [e, a] of Object.entries(t))
|
|
70
|
+
a != null && r.set(e, a);
|
|
71
|
+
return r.toString();
|
|
72
|
+
}
|
|
73
|
+
function L(t) {
|
|
74
|
+
return JSON.stringify(t);
|
|
75
|
+
}
|
|
76
|
+
function P(t, r) {
|
|
77
|
+
let e = `${r.baseUrl ? r.baseUrl.replace(j, "") : ""}${t}`;
|
|
78
|
+
if (r.params.path)
|
|
79
|
+
for (const [a, i] of Object.entries(r.params.path))
|
|
80
|
+
e = e.replace(`{${a}}`, encodeURIComponent(String(i)));
|
|
81
|
+
if (r.params.query) {
|
|
82
|
+
const a = r.querySerializer(r.params.query);
|
|
83
|
+
a && (e += `?${a}`);
|
|
84
|
+
}
|
|
85
|
+
return e;
|
|
86
|
+
}
|
|
87
|
+
function R(...t) {
|
|
88
|
+
const r = new Headers();
|
|
89
|
+
for (const e of t) {
|
|
90
|
+
if (!e || typeof e != "object")
|
|
91
|
+
continue;
|
|
92
|
+
const a = e instanceof Headers ? e.entries() : Object.entries(e);
|
|
93
|
+
for (const [i, c] of a)
|
|
94
|
+
c != null && r.set(i, c);
|
|
95
|
+
}
|
|
96
|
+
return r;
|
|
97
|
+
}
|
|
98
|
+
let h, b, U = "https://api.cycle.io";
|
|
99
|
+
function D(t) {
|
|
100
|
+
h = t;
|
|
66
101
|
}
|
|
67
|
-
function
|
|
68
|
-
|
|
102
|
+
function I(t) {
|
|
103
|
+
b = t;
|
|
69
104
|
}
|
|
70
|
-
function
|
|
71
|
-
|
|
105
|
+
function k(t) {
|
|
106
|
+
U = t;
|
|
72
107
|
}
|
|
73
|
-
const
|
|
74
|
-
get(
|
|
75
|
-
const
|
|
76
|
-
return
|
|
77
|
-
headers:
|
|
78
|
-
baseUrl:
|
|
79
|
-
})[
|
|
108
|
+
const $ = E(), q = new Proxy($, {
|
|
109
|
+
get(t, r) {
|
|
110
|
+
const e = {};
|
|
111
|
+
return h && (e.Authorization = `Bearer ${h}`), b && (e["X-Hub-Id"] = b), E({
|
|
112
|
+
headers: e,
|
|
113
|
+
baseUrl: U
|
|
114
|
+
})[r];
|
|
80
115
|
}
|
|
81
116
|
});
|
|
82
|
-
function
|
|
83
|
-
const
|
|
84
|
-
(
|
|
85
|
-
),
|
|
86
|
-
return new URLSearchParams(
|
|
117
|
+
function B(t) {
|
|
118
|
+
const r = Object.entries(t).reduce((e, [a, i]) => typeof i == "string" ? (e[a] = i, e) : (i && typeof i == "object" && Object.keys(i).forEach(
|
|
119
|
+
(c) => e[`${a}[${c}]`] = i[c]
|
|
120
|
+
), e), {});
|
|
121
|
+
return new URLSearchParams(r).toString();
|
|
87
122
|
}
|
|
88
123
|
export {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
124
|
+
q as client,
|
|
125
|
+
B as querySerializer,
|
|
126
|
+
D as setAuthToken,
|
|
127
|
+
k as setBaseUrl,
|
|
128
|
+
I as setHubScope
|
|
94
129
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(c,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(c=typeof globalThis<"u"?globalThis:c||self,l(c["Cycle API Client"]={}))})(this,function(c){"use strict";const l={"Content-Type":"application/json"},g=/\/*$/;function p(t={}){const{fetch:n=globalThis.fetch,querySerializer:e,bodySerializer:i,...a}=t,u=new Headers({...l,...a.headers??{}});async function f(r,o){const{headers:k,body:E,params:U={},parseAs:h="json",querySerializer:q=e??C,bodySerializer:D=i??j,...B}=o||{},F=w(r,{baseUrl:a.baseUrl,params:U,querySerializer:q}),A=O(u,k,U.header),b={redirect:"follow",...a,...B,headers:A};E&&(b.body=D(E)),b.body instanceof FormData&&A.delete("Content-Type");const s=await n(F,b);if(s.status===204||s.headers.get("Content-Length")==="0")return s.ok?{data:{},response:s}:{error:{},response:s};if(s.ok){let H=s.body;if(h!=="stream"){const T=s.clone();H=typeof T[h]=="function"?await T[h]():await T.text()}return{data:H,response:s}}let S={};try{S=await s.clone().json()}catch{S=await s.clone().text()}return{error:S,response:s}}return{async GET(r,o){return f(r,{...o,method:"GET"})},async PUT(r,o){return f(r,{...o,method:"PUT"})},async POST(r,o){return f(r,{...o,method:"POST"})},async DELETE(r,o){return f(r,{...o,method:"DELETE"})},async OPTIONS(r,o){return f(r,{...o,method:"OPTIONS"})},async HEAD(r,o){return f(r,{...o,method:"HEAD"})},async PATCH(r,o){return f(r,{...o,method:"PATCH"})},async TRACE(r,o){return f(r,{...o,method:"TRACE"})}}}function C(t){const n=new URLSearchParams;if(t&&typeof t=="object")for(const[e,i]of Object.entries(t))i!=null&&n.set(e,i);return n.toString()}function j(t){return JSON.stringify(t)}function w(t,n){let e=`${n.baseUrl?n.baseUrl.replace(g,""):""}${t}`;if(n.params.path)for(const[i,a]of Object.entries(n.params.path))e=e.replace(`{${i}}`,encodeURIComponent(String(a)));if(n.params.query){const i=n.querySerializer(n.params.query);i&&(e+=`?${i}`)}return e}function O(...t){const n=new Headers;for(const e of t){if(!e||typeof e!="object")continue;const i=e instanceof Headers?e.entries():Object.entries(e);for(const[a,u]of i)u!=null&&n.set(a,u)}return n}let d,y,m="https://api.cycle.io";function P(t){d=t}function z(t){y=t}function L(t){m=t}const R=p(),I=new Proxy(R,{get(t,n){const e={};return d&&(e.Authorization=`Bearer ${d}`),y&&(e["X-Hub-Id"]=y),p({headers:e,baseUrl:m})[n]}});function $(t){const n=Object.entries(t).reduce((e,[i,a])=>typeof a=="string"?(e[i]=a,e):(a&&typeof a=="object"&&Object.keys(a).forEach(u=>e[`${i}[${u}]`]=a[u]),e),{});return new URLSearchParams(n).toString()}c.client=I,c.querySerializer=$,c.setAuthToken=P,c.setBaseUrl=L,c.setHubScope=z,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cycleplatform/api-client-typescript",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "A Cycle API client for the web/nodejs",
|
|
5
5
|
"main": "./dist/index.umd.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://github.com/cycleplatform/api-client-typescript#readme",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"openapi-fetch": "
|
|
39
|
+
"openapi-fetch": "0.7.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"msw": "
|
|
43
|
-
"openapi-typescript": "
|
|
42
|
+
"msw": "1.2.3",
|
|
43
|
+
"openapi-typescript": "6.3.9",
|
|
44
44
|
"typescript": "^5.0.4",
|
|
45
|
-
"vite": "
|
|
46
|
-
"vitest": "
|
|
45
|
+
"vite": "4.4.7",
|
|
46
|
+
"vitest": "0.33.0"
|
|
47
47
|
}
|
|
48
48
|
}
|