@cycleplatform/api-client-typescript 0.1.3 → 0.1.5

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 ADDED
@@ -0,0 +1,94 @@
1
+ const T = {
2
+ "Content-Type": "application/json"
3
+ };
4
+ function S(n) {
5
+ const o = new Headers({
6
+ ...T,
7
+ ...(n == null ? void 0 : n.headers) ?? {}
8
+ });
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
+ if (c.path)
13
+ for (const [a, i] of Object.entries(c.path))
14
+ d = d.replace(`{${a}}`, encodeURIComponent(String(i)));
15
+ c.query && Object.keys(c.query).length && (d += `?${p(c.query)}`);
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
+ redirect: "follow",
21
+ ...n,
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
+ }
28
+ return {
29
+ /** Call a GET endpoint */
30
+ async get(t, e) {
31
+ return r(t, { ...e, method: "GET" });
32
+ },
33
+ /** Call a PUT endpoint */
34
+ async put(t, e) {
35
+ return r(t, { ...e, method: "PUT" });
36
+ },
37
+ /** Call a POST endpoint */
38
+ async post(t, e) {
39
+ return r(t, { ...e, method: "POST" });
40
+ },
41
+ /** Call a DELETE endpoint */
42
+ async del(t, e) {
43
+ return r(t, { ...e, method: "DELETE" });
44
+ },
45
+ /** Call a OPTIONS endpoint */
46
+ async options(t, e) {
47
+ return r(t, { ...e, method: "OPTIONS" });
48
+ },
49
+ /** Call a HEAD endpoint */
50
+ async head(t, e) {
51
+ return r(t, { ...e, method: "HEAD" });
52
+ },
53
+ /** Call a PATCH endpoint */
54
+ async patch(t, e) {
55
+ return r(t, { ...e, method: "PATCH" });
56
+ },
57
+ /** Call a TRACE endpoint */
58
+ async trace(t, e) {
59
+ return r(t, { ...e, method: "TRACE" });
60
+ }
61
+ };
62
+ }
63
+ let l, y, m = "https://api.cycle.io";
64
+ function H(n) {
65
+ l = n;
66
+ }
67
+ function C(n) {
68
+ y = n;
69
+ }
70
+ function O(n) {
71
+ m = n;
72
+ }
73
+ const E = S(), U = new Proxy(E, {
74
+ get(n, o) {
75
+ const r = {};
76
+ return l && (r.Authorization = `Bearer ${l}`), y && (r["X-Hub-Id"] = y), S({
77
+ headers: r,
78
+ baseUrl: m
79
+ })[o];
80
+ }
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
+ }
88
+ export {
89
+ U as client,
90
+ j as querySerializer,
91
+ H as setAuthToken,
92
+ O as setBaseUrl,
93
+ C as setHubScope
94
+ };
@@ -0,0 +1 @@
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,9 +1,16 @@
1
1
  {
2
2
  "name": "@cycleplatform/api-client-typescript",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "A Cycle API client for the web/nodejs",
5
- "main": "./dist/index.umd.js",
6
- "module": "./dist/index.mjs",
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
+ },
7
14
  "types": "./src/index.ts",
8
15
  "scripts": {
9
16
  "test": "vitest",