@cycleplatform/api-client-typescript 0.1.7 → 0.1.10

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 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` etc.
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` etc.
12
12
 
13
13
  ## Usage
14
14
 
@@ -30,8 +30,7 @@ import {
30
30
  setAuthToken("secret_MY-API-KEY");
31
31
  setHubScope("myhubid");
32
32
 
33
-
34
- const resp = await client.get("/v1/containers/{containerId}", {
33
+ const resp = await client.GET("/v1/containers/{containerId}", {
35
34
  params: { query: {}, path: { containerId: "abc123" } },
36
35
  });
37
36
 
@@ -47,24 +46,22 @@ import {
47
46
  client,
48
47
  setAuthToken,
49
48
  setHubScope,
50
- setBaseUrl
49
+ setBaseUrl,
51
50
  } from "@cycleplatform/api-client-typescript";
52
51
 
53
52
  // Add this
54
- setBaseUrl("https://api.my-company.cycle.io")
53
+ setBaseUrl("https://api.my-company.cycle.io");
55
54
 
56
55
  setAuthToken("secret_MY-API-KEY");
57
56
  setHubScope("myhubid");
58
57
 
59
-
60
- const resp = await client.get("/v1/containers/{containerId}", {
58
+ const resp = await client.GET("/v1/containers/{containerId}", {
61
59
  params: { query: {}, path: { containerId: "abc123" } },
62
60
  });
63
61
 
64
62
  console.log(test.data, test.error);
65
63
  ```
66
64
 
67
-
68
65
  ## Development
69
66
 
70
67
  ### Cloning submodules
package/dist/index.mjs ADDED
@@ -0,0 +1,129 @@
1
+ const O = {
2
+ "Content-Type": "application/json"
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
+ });
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 };
30
+ }
31
+ return {
32
+ /** Call a GET endpoint */
33
+ async GET(n, o) {
34
+ return u(n, { ...o, method: "GET" });
35
+ },
36
+ /** Call a PUT endpoint */
37
+ async PUT(n, o) {
38
+ return u(n, { ...o, method: "PUT" });
39
+ },
40
+ /** Call a POST endpoint */
41
+ async POST(n, o) {
42
+ return u(n, { ...o, method: "POST" });
43
+ },
44
+ /** Call a DELETE endpoint */
45
+ async DELETE(n, o) {
46
+ return u(n, { ...o, method: "DELETE" });
47
+ },
48
+ /** Call a OPTIONS endpoint */
49
+ async OPTIONS(n, o) {
50
+ return u(n, { ...o, method: "OPTIONS" });
51
+ },
52
+ /** Call a HEAD endpoint */
53
+ async HEAD(n, o) {
54
+ return u(n, { ...o, method: "HEAD" });
55
+ },
56
+ /** Call a PATCH endpoint */
57
+ async PATCH(n, o) {
58
+ return u(n, { ...o, method: "PATCH" });
59
+ },
60
+ /** Call a TRACE endpoint */
61
+ async TRACE(n, o) {
62
+ return u(n, { ...o, method: "TRACE" });
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;
101
+ }
102
+ function I(t) {
103
+ b = t;
104
+ }
105
+ function k(t) {
106
+ U = t;
107
+ }
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];
115
+ }
116
+ });
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();
122
+ }
123
+ export {
124
+ q as client,
125
+ B as querySerializer,
126
+ D as setAuthToken,
127
+ k as setBaseUrl,
128
+ I as setHubScope
129
+ };
@@ -0,0 +1 @@
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,10 +1,9 @@
1
1
  {
2
2
  "name": "@cycleplatform/api-client-typescript",
3
- "version": "0.1.7",
3
+ "version": "0.1.10",
4
4
  "description": "A Cycle API client for the web/nodejs",
5
5
  "main": "./dist/index.umd.cjs",
6
6
  "module": "./dist/index.js",
7
- "type": "module",
8
7
  "exports": {
9
8
  ".": {
10
9
  "import": "./dist/index.js",
@@ -36,13 +35,13 @@
36
35
  },
37
36
  "homepage": "https://github.com/cycleplatform/api-client-typescript#readme",
38
37
  "dependencies": {
39
- "openapi-fetch": "^0.1.4"
38
+ "openapi-fetch": "0.7.2"
40
39
  },
41
40
  "devDependencies": {
42
- "msw": "^1.2.1",
43
- "openapi-typescript": "^6.2.4",
41
+ "msw": "1.2.3",
42
+ "openapi-typescript": "6.4.4",
44
43
  "typescript": "^5.0.4",
45
- "vite": "^4.3.7",
46
- "vitest": "^0.31.0"
44
+ "vite": "4.4.7",
45
+ "vitest": "0.33.0"
47
46
  }
48
47
  }