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