@cycleplatform/api-client-typescript 0.1.4 → 0.1.7
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 +52 -45
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
- package/src/generated/types.ts +1392 -591
- package/src/index.ts +25 -0
- package/cycleplatform-api-client-typescript-0.1.3.tgz +0 -0
package/dist/index.js
CHANGED
|
@@ -1,87 +1,94 @@
|
|
|
1
|
-
const
|
|
1
|
+
const T = {
|
|
2
2
|
"Content-Type": "application/json"
|
|
3
3
|
};
|
|
4
|
-
function
|
|
5
|
-
const
|
|
6
|
-
...
|
|
4
|
+
function S(n) {
|
|
5
|
+
const o = new Headers({
|
|
6
|
+
...T,
|
|
7
7
|
...(n == null ? void 0 : n.headers) ?? {}
|
|
8
8
|
});
|
|
9
|
-
async function r(
|
|
10
|
-
const { headers:
|
|
11
|
-
let d = `${(n == null ? void 0 : n.baseUrl) ?? ""}${
|
|
9
|
+
async function r(t, e) {
|
|
10
|
+
const { headers: u, body: h, params: c = {}, querySerializer: p = (a) => new URLSearchParams(a).toString(), ...g } = e || {};
|
|
11
|
+
let d = `${(n == null ? void 0 : n.baseUrl) ?? ""}${t}`;
|
|
12
12
|
if (c.path)
|
|
13
|
-
for (const [
|
|
14
|
-
d = d.replace(`{${
|
|
13
|
+
for (const [a, i] of Object.entries(c.path))
|
|
14
|
+
d = d.replace(`{${a}}`, encodeURIComponent(String(i)));
|
|
15
15
|
c.query && Object.keys(c.query).length && (d += `?${p(c.query)}`);
|
|
16
|
-
const
|
|
17
|
-
for (const [
|
|
18
|
-
|
|
19
|
-
const
|
|
16
|
+
const f = new Headers(o), w = new Headers(u);
|
|
17
|
+
for (const [a, i] of w.entries())
|
|
18
|
+
i == null ? f.delete(a) : f.set(a, i);
|
|
19
|
+
const s = await fetch(d, {
|
|
20
20
|
redirect: "follow",
|
|
21
21
|
...n,
|
|
22
|
-
...
|
|
23
|
-
headers:
|
|
24
|
-
body: typeof
|
|
25
|
-
}),
|
|
26
|
-
return
|
|
22
|
+
...g,
|
|
23
|
+
headers: f,
|
|
24
|
+
body: typeof h == "string" ? h : JSON.stringify(h)
|
|
25
|
+
}), b = s.status === 204 || s.headers.get("Content-Length") === "0" ? {} : await s.json();
|
|
26
|
+
return s.ok ? { data: b, response: s } : { error: b, response: s };
|
|
27
27
|
}
|
|
28
28
|
return {
|
|
29
29
|
/** Call a GET endpoint */
|
|
30
|
-
async get(
|
|
31
|
-
return r(
|
|
30
|
+
async get(t, e) {
|
|
31
|
+
return r(t, { ...e, method: "GET" });
|
|
32
32
|
},
|
|
33
33
|
/** Call a PUT endpoint */
|
|
34
|
-
async put(
|
|
35
|
-
return r(
|
|
34
|
+
async put(t, e) {
|
|
35
|
+
return r(t, { ...e, method: "PUT" });
|
|
36
36
|
},
|
|
37
37
|
/** Call a POST endpoint */
|
|
38
|
-
async post(
|
|
39
|
-
return r(
|
|
38
|
+
async post(t, e) {
|
|
39
|
+
return r(t, { ...e, method: "POST" });
|
|
40
40
|
},
|
|
41
41
|
/** Call a DELETE endpoint */
|
|
42
|
-
async del(
|
|
43
|
-
return r(
|
|
42
|
+
async del(t, e) {
|
|
43
|
+
return r(t, { ...e, method: "DELETE" });
|
|
44
44
|
},
|
|
45
45
|
/** Call a OPTIONS endpoint */
|
|
46
|
-
async options(
|
|
47
|
-
return r(
|
|
46
|
+
async options(t, e) {
|
|
47
|
+
return r(t, { ...e, method: "OPTIONS" });
|
|
48
48
|
},
|
|
49
49
|
/** Call a HEAD endpoint */
|
|
50
|
-
async head(
|
|
51
|
-
return r(
|
|
50
|
+
async head(t, e) {
|
|
51
|
+
return r(t, { ...e, method: "HEAD" });
|
|
52
52
|
},
|
|
53
53
|
/** Call a PATCH endpoint */
|
|
54
|
-
async patch(
|
|
55
|
-
return r(
|
|
54
|
+
async patch(t, e) {
|
|
55
|
+
return r(t, { ...e, method: "PATCH" });
|
|
56
56
|
},
|
|
57
57
|
/** Call a TRACE endpoint */
|
|
58
|
-
async trace(
|
|
59
|
-
return r(
|
|
58
|
+
async trace(t, e) {
|
|
59
|
+
return r(t, { ...e, method: "TRACE" });
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
63
|
let l, y, m = "https://api.cycle.io";
|
|
64
|
-
function
|
|
64
|
+
function H(n) {
|
|
65
65
|
l = n;
|
|
66
66
|
}
|
|
67
|
-
function
|
|
67
|
+
function C(n) {
|
|
68
68
|
y = n;
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function O(n) {
|
|
71
71
|
m = n;
|
|
72
72
|
}
|
|
73
|
-
const
|
|
74
|
-
get(n,
|
|
73
|
+
const E = S(), U = new Proxy(E, {
|
|
74
|
+
get(n, o) {
|
|
75
75
|
const r = {};
|
|
76
|
-
return l && (r.Authorization = `Bearer ${l}`), y && (r["X-Hub-Id"] = y),
|
|
76
|
+
return l && (r.Authorization = `Bearer ${l}`), y && (r["X-Hub-Id"] = y), S({
|
|
77
77
|
headers: r,
|
|
78
78
|
baseUrl: m
|
|
79
|
-
})[
|
|
79
|
+
})[o];
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
|
+
function j(n) {
|
|
83
|
+
const o = Object.entries(n).reduce((r, [t, e]) => typeof e == "string" ? (r[t] = e, r) : (e && typeof e == "object" && Object.keys(e).forEach(
|
|
84
|
+
(u) => r[`${t}[${u}]`] = e[u]
|
|
85
|
+
), r), {});
|
|
86
|
+
return new URLSearchParams(o).toString();
|
|
87
|
+
}
|
|
82
88
|
export {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
U as client,
|
|
90
|
+
j as querySerializer,
|
|
91
|
+
H as setAuthToken,
|
|
92
|
+
O as setBaseUrl,
|
|
93
|
+
C as setHubScope
|
|
87
94
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s,
|
|
1
|
+
(function(s,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(s=typeof globalThis<"u"?globalThis:s||self,i(s["Cycle API Client"]={}))})(this,function(s){"use strict";const i={"Content-Type":"application/json"};function m(r){const c=new Headers({...i,...(r==null?void 0:r.headers)??{}});async function n(t,e){const{headers:f,body:b,params:u={},querySerializer:U=a=>new URLSearchParams(a).toString(),...j}=e||{};let l=`${(r==null?void 0:r.baseUrl)??""}${t}`;if(u.path)for(const[a,d]of Object.entries(u.path))l=l.replace(`{${a}}`,encodeURIComponent(String(d)));u.query&&Object.keys(u.query).length&&(l+=`?${U(u.query)}`);const S=new Headers(c),A=new Headers(f);for(const[a,d]of A.entries())d==null?S.delete(a):S.set(a,d);const o=await fetch(l,{redirect:"follow",...r,...j,headers:S,body:typeof b=="string"?b:JSON.stringify(b)}),T=o.status===204||o.headers.get("Content-Length")==="0"?{}:await o.json();return o.ok?{data:T,response:o}:{error:T,response:o}}return{async get(t,e){return n(t,{...e,method:"GET"})},async put(t,e){return n(t,{...e,method:"PUT"})},async post(t,e){return n(t,{...e,method:"POST"})},async del(t,e){return n(t,{...e,method:"DELETE"})},async options(t,e){return n(t,{...e,method:"OPTIONS"})},async head(t,e){return n(t,{...e,method:"HEAD"})},async patch(t,e){return n(t,{...e,method:"PATCH"})},async trace(t,e){return n(t,{...e,method:"TRACE"})}}}let h,y,p="https://api.cycle.io";function g(r){h=r}function w(r){y=r}function C(r){p=r}const H=m(),E=new Proxy(H,{get(r,c){const n={};return h&&(n.Authorization=`Bearer ${h}`),y&&(n["X-Hub-Id"]=y),m({headers:n,baseUrl:p})[c]}});function O(r){const c=Object.entries(r).reduce((n,[t,e])=>typeof e=="string"?(n[t]=e,n):(e&&typeof e=="object"&&Object.keys(e).forEach(f=>n[`${t}[${f}]`]=e[f]),n),{});return new URLSearchParams(c).toString()}s.client=E,s.querySerializer=O,s.setAuthToken=g,s.setBaseUrl=C,s.setHubScope=w,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|