@cycleplatform/api-client-typescript 0.2.5 → 0.3.4

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.
@@ -1 +1 @@
1
- (function(h,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(h=typeof globalThis<"u"?globalThis:h||self,b(h["Cycle API Client"]={}))})(this,function(h){"use strict";const b={"Content-Type":"application/json"},P=/\{[^{}]+\}/g;function D(n){let{baseUrl:t="",fetch:e=globalThis.fetch,querySerializer:i,bodySerializer:r,headers:s,...a}={...n};t.endsWith("/")&&(t=t.substring(0,t.length-1)),s=O(b,s);const o=[];async function u(c,l){let{fetch:p=e,headers:M,params:g={},parseAs:$="json",querySerializer:j,bodySerializer:C=r??U,...k}=l||{},A=typeof i=="function"?i:z(i);j&&(A=typeof j=="function"?j:z({...typeof i=="object"?i:{},...j}));const m={redirect:"follow",...a,...k,headers:O(s,M,g.header)};m.body&&(m.body=C(m.body)),m.body instanceof FormData&&m.headers.delete("Content-Type");let w=new Request(I(c,{baseUrl:t,params:g,querySerializer:A}),m);const q={baseUrl:t,fetch:p,parseAs:$,querySerializer:A,bodySerializer:C};for(const d of o)if(d&&typeof d=="object"&&typeof d.onRequest=="function"){w.schemaPath=c,w.params=g;const y=await d.onRequest(w,q);if(y){if(!(y instanceof Request))throw new Error("Middleware must return new Request() when modifying the request");w=y}}let f=await p(w);for(let d=o.length-1;d>=0;d--){const y=o[d];if(y&&typeof y=="object"&&typeof y.onResponse=="function"){const T=await y.onResponse(f,q);if(T){if(!(T instanceof Response))throw new Error("Middleware must return new Response() when modifying the response");f=T}}}if(f.status===204||f.headers.get("Content-Length")==="0")return f.ok?{data:{},response:f}:{error:{},response:f};if(f.ok)return $==="stream"?{data:f.body,response:f}:{data:await f[$](),response:f};let S=await f.text();try{S=JSON.parse(S)}catch{}return{error:S,response:f}}return{async GET(c,l){return u(c,{...l,method:"GET"})},async PUT(c,l){return u(c,{...l,method:"PUT"})},async POST(c,l){return u(c,{...l,method:"POST"})},async DELETE(c,l){return u(c,{...l,method:"DELETE"})},async OPTIONS(c,l){return u(c,{...l,method:"OPTIONS"})},async HEAD(c,l){return u(c,{...l,method:"HEAD"})},async PATCH(c,l){return u(c,{...l,method:"PATCH"})},async TRACE(c,l){return u(c,{...l,method:"TRACE"})},use(...c){for(const l of c)if(l){if(typeof l!="object"||!("onRequest"in l||"onResponse"in l))throw new Error("Middleware must be an object with one of `onRequest()` or `onResponse()`");o.push(l)}},eject(...c){for(const l of c){const p=o.indexOf(l);p!==-1&&o.splice(p,1)}}}}function R(n,t,e){if(t==null)return"";if(typeof t=="object")throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${n}=${(e==null?void 0:e.allowReserved)===!0?t:encodeURIComponent(t)}`}function E(n,t,e){if(!t||typeof t!="object")return"";const i=[],r={simple:",",label:".",matrix:";"}[e.style]||"&";if(e.style!=="deepObject"&&e.explode===!1){for(const o in t)i.push(o,e.allowReserved===!0?t[o]:encodeURIComponent(t[o]));const a=i.join(",");switch(e.style){case"form":return`${n}=${a}`;case"label":return`.${a}`;case"matrix":return`;${n}=${a}`;default:return a}}for(const a in t){const o=e.style==="deepObject"?`${n}[${a}]`:a;i.push(R(o,t[a],e))}const s=i.join(r);return e.style==="label"||e.style==="matrix"?`${r}${s}`:s}function x(n,t,e){if(!Array.isArray(t))return"";if(e.explode===!1){const s={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[e.style]||",",a=(e.allowReserved===!0?t:t.map(o=>encodeURIComponent(o))).join(s);switch(e.style){case"simple":return a;case"label":return`.${a}`;case"matrix":return`;${n}=${a}`;case"spaceDelimited":case"pipeDelimited":default:return`${n}=${a}`}}const i={simple:",",label:".",matrix:";"}[e.style]||"&",r=[];for(const s of t)e.style==="simple"||e.style==="label"?r.push(e.allowReserved===!0?s:encodeURIComponent(s)):r.push(R(n,s,e));return e.style==="label"||e.style==="matrix"?`${i}${r.join(i)}`:r.join(i)}function z(n){return function(e){const i=[];if(e&&typeof e=="object")for(const r in e){const s=e[r];if(s!=null){if(Array.isArray(s)){i.push(x(r,s,{style:"form",explode:!0,...n==null?void 0:n.array,allowReserved:(n==null?void 0:n.allowReserved)||!1}));continue}if(typeof s=="object"){i.push(E(r,s,{style:"deepObject",explode:!0,...n==null?void 0:n.object,allowReserved:(n==null?void 0:n.allowReserved)||!1}));continue}i.push(R(r,s,n))}}return i.join("&")}}function H(n,t){let e=n;for(const i of n.match(P)??[]){let r=i.substring(1,i.length-1),s=!1,a="simple";if(r.endsWith("*")&&(s=!0,r=r.substring(0,r.length-1)),r.startsWith(".")?(a="label",r=r.substring(1)):r.startsWith(";")&&(a="matrix",r=r.substring(1)),!t||t[r]===void 0||t[r]===null)continue;const o=t[r];if(Array.isArray(o)){e=e.replace(i,x(r,o,{style:a,explode:s}));continue}if(typeof o=="object"){e=e.replace(i,E(r,o,{style:a,explode:s}));continue}if(a==="matrix"){e=e.replace(i,`;${R(r,o)}`);continue}e=e.replace(i,a==="label"?`.${o}`:o)}return e}function U(n){return JSON.stringify(n)}function I(n,t){var r;let e=`${t.baseUrl}${n}`;(r=t.params)!=null&&r.path&&(e=H(e,t.params.path));let i=t.querySerializer(t.params.query??{});return i.startsWith("?")&&(i=i.substring(1)),i&&(e+=`?${i}`),e}function O(...n){const t=new Headers;for(const e of n){if(!e||typeof e!="object")continue;const i=e instanceof Headers?e.entries():Object.entries(e);for(const[r,s]of i)if(s===null)t.delete(r);else if(Array.isArray(s))for(const a of s)t.append(r,a);else s!==void 0&&t.set(r,s)}return t}function L({apiKey:n,baseUrl:t="https://api.cycle.io",hubId:e,fetch:i}){const r=D({baseUrl:t,fetch:i||fetch}),s={async onRequest(a){return a.headers.set("Authorization",`Bearer ${n}`),a.headers.set("X-Hub-Id",e),a}};return r.use(s),r}h.getClient=L,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
1
+ (function(m,R){typeof exports=="object"&&typeof module<"u"?R(exports):typeof define=="function"&&define.amd?define(["exports"],R):(m=typeof globalThis<"u"?globalThis:m||self,R(m["Cycle API Client"]={}))})(this,function(m){"use strict";const R=/\{[^{}]+\}/g,N=()=>{var r,t;return typeof process=="object"&&Number.parseInt((t=(r=process==null?void 0:process.versions)==null?void 0:r.node)==null?void 0:t.substring(0,2))>=18&&process.versions.undici};function B(){return Math.random().toString(36).slice(2,11)}function F(r){let{baseUrl:t="",Request:e=globalThis.Request,fetch:o=globalThis.fetch,querySerializer:n,bodySerializer:s,headers:i,requestInitExt:l=void 0,...y}={...r};l=N()?l:void 0,t=D(t);const h=[];async function p(f,a){const{baseUrl:b,fetch:J=o,Request:re=e,headers:Y,params:j={},parseAs:z="json",querySerializer:T,bodySerializer:L=s??G,body:M,...q}=a||{};b&&(t=D(b));let x=typeof n=="function"?n:U(n);T&&(x=typeof T=="function"?T:U({...typeof n=="object"?n:{},...T}));const I=M===void 0?void 0:L(M),ee=I===void 0||I instanceof FormData?{}:{"Content-Type":"application/json"},te={redirect:"follow",...y,...q,body:I,headers:_(ee,i,Y,j.header)};let $,A,w=new e(Q(f,{baseUrl:t,params:j,querySerializer:x}),te);for(const u in q)u in w||(w[u]=q[u]);if(h.length){$=B(),A=Object.freeze({baseUrl:t,fetch:J,parseAs:z,querySerializer:x,bodySerializer:L});for(const u of h)if(u&&typeof u=="object"&&typeof u.onRequest=="function"){const d=await u.onRequest({request:w,schemaPath:f,params:j,options:A,id:$});if(d){if(!(d instanceof e))throw new Error("onRequest: must return new Request() when modifying the request");w=d}}}let c;try{c=await J(w,l)}catch(u){let d=u;if(h.length)for(let g=h.length-1;g>=0;g--){const C=h[g];if(C&&typeof C=="object"&&typeof C.onError=="function"){const E=await C.onError({request:w,error:d,schemaPath:f,params:j,options:A,id:$});if(E){if(E instanceof Response){d=void 0,c=E;break}if(E instanceof Error){d=E;continue}throw new Error("onError: must return new Response() or instance of Error")}}}if(d)throw d}if(h.length)for(let u=h.length-1;u>=0;u--){const d=h[u];if(d&&typeof d=="object"&&typeof d.onResponse=="function"){const g=await d.onResponse({request:w,response:c,schemaPath:f,params:j,options:A,id:$});if(g){if(!(g instanceof Response))throw new Error("onResponse: must return new Response() when modifying the response");c=g}}}if(c.status===204||c.headers.get("Content-Length")==="0")return c.ok?{data:void 0,response:c}:{error:void 0,response:c};if(c.ok)return z==="stream"?{data:c.body,response:c}:{data:await c[z](),response:c};let k=await c.text();try{k=JSON.parse(k)}catch{}return{error:k,response:c}}return{request(f,a,b){return p(a,{...b,method:f.toUpperCase()})},GET(f,a){return p(f,{...a,method:"GET"})},PUT(f,a){return p(f,{...a,method:"PUT"})},POST(f,a){return p(f,{...a,method:"POST"})},DELETE(f,a){return p(f,{...a,method:"DELETE"})},OPTIONS(f,a){return p(f,{...a,method:"OPTIONS"})},HEAD(f,a){return p(f,{...a,method:"HEAD"})},PATCH(f,a){return p(f,{...a,method:"PATCH"})},TRACE(f,a){return p(f,{...a,method:"TRACE"})},use(...f){for(const a of f)if(a){if(typeof a!="object"||!("onRequest"in a||"onResponse"in a||"onError"in a))throw new Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");h.push(a)}},eject(...f){for(const a of f){const b=h.indexOf(a);b!==-1&&h.splice(b,1)}}}}function S(r,t,e){if(t==null)return"";if(typeof t=="object")throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${r}=${(e==null?void 0:e.allowReserved)===!0?t:encodeURIComponent(t)}`}function v(r,t,e){if(!t||typeof t!="object")return"";const o=[],n={simple:",",label:".",matrix:";"}[e.style]||"&";if(e.style!=="deepObject"&&e.explode===!1){for(const l in t)o.push(l,e.allowReserved===!0?t[l]:encodeURIComponent(t[l]));const i=o.join(",");switch(e.style){case"form":return`${r}=${i}`;case"label":return`.${i}`;case"matrix":return`;${r}=${i}`;default:return i}}for(const i in t){const l=e.style==="deepObject"?`${r}[${i}]`:i;o.push(S(l,t[i],e))}const s=o.join(n);return e.style==="label"||e.style==="matrix"?`${n}${s}`:s}function O(r,t,e){if(!Array.isArray(t))return"";if(e.explode===!1){const s={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[e.style]||",",i=(e.allowReserved===!0?t:t.map(l=>encodeURIComponent(l))).join(s);switch(e.style){case"simple":return i;case"label":return`.${i}`;case"matrix":return`;${r}=${i}`;default:return`${r}=${i}`}}const o={simple:",",label:".",matrix:";"}[e.style]||"&",n=[];for(const s of t)e.style==="simple"||e.style==="label"?n.push(e.allowReserved===!0?s:encodeURIComponent(s)):n.push(S(r,s,e));return e.style==="label"||e.style==="matrix"?`${o}${n.join(o)}`:n.join(o)}function U(r){return function(e){const o=[];if(e&&typeof e=="object")for(const n in e){const s=e[n];if(s!=null){if(Array.isArray(s)){if(s.length===0)continue;o.push(O(n,s,{style:"form",explode:!0,...r==null?void 0:r.array,allowReserved:(r==null?void 0:r.allowReserved)||!1}));continue}if(typeof s=="object"){o.push(v(n,s,{style:"deepObject",explode:!0,...r==null?void 0:r.object,allowReserved:(r==null?void 0:r.allowReserved)||!1}));continue}o.push(S(n,s,r))}}return o.join("&")}}function W(r,t){let e=r;for(const o of r.match(R)??[]){let n=o.substring(1,o.length-1),s=!1,i="simple";if(n.endsWith("*")&&(s=!0,n=n.substring(0,n.length-1)),n.startsWith(".")?(i="label",n=n.substring(1)):n.startsWith(";")&&(i="matrix",n=n.substring(1)),!t||t[n]===void 0||t[n]===null)continue;const l=t[n];if(Array.isArray(l)){e=e.replace(o,O(n,l,{style:i,explode:s}));continue}if(typeof l=="object"){e=e.replace(o,v(n,l,{style:i,explode:s}));continue}if(i==="matrix"){e=e.replace(o,`;${S(n,l)}`);continue}e=e.replace(o,i==="label"?`.${encodeURIComponent(l)}`:encodeURIComponent(l))}return e}function G(r){return r instanceof FormData?r:JSON.stringify(r)}function Q(r,t){var n;let e=`${t.baseUrl}${r}`;(n=t.params)!=null&&n.path&&(e=W(e,t.params.path));let o=t.querySerializer(t.params.query??{});return o.startsWith("?")&&(o=o.substring(1)),o&&(e+=`?${o}`),e}function _(...r){const t=new Headers;for(const e of r){if(!e||typeof e!="object")continue;const o=e instanceof Headers?e.entries():Object.entries(e);for(const[n,s]of o)if(s===null)t.delete(n);else if(Array.isArray(s))for(const i of s)t.append(n,i);else s!==void 0&&t.set(n,s)}return t}function D(r){return r.endsWith("/")?r.substring(0,r.length-1):r}class X extends EventTarget{constructor(t,e,o){super(),this.promise=this.track(t,e,o)}async track(t,e,o){const n=typeof e=="object"?e.id:e,s={pollingInterval:2e3,...o};let i=0;for(;;){const l=await t.GET("/v1/jobs/{jobId}",{params:{path:{jobId:n}}});if(l.error){if(i<5&&l.error.error.code==="404.job"){i++,await this.delay(s.pollingInterval);continue}throw l.error}const y=l.data.data,h=P(y);if(this.dispatchEvent(new CustomEvent("progress",{detail:{...h,state:y.state.current}})),Z(y)){if(y.state.current==="error")throw y;return this.dispatchEvent(new CustomEvent("done",{detail:y})),y}await this.delay(s.pollingInterval)}}delay(t=2e3){return new Promise(e=>setTimeout(e,t))}}function Z(r){return["completed","error","expired"].includes(r.state.current)}const H="0001-01-01T00:00:00Z";function P(r){if(!r.tasks||r.tasks.length===0)return{total:0,completed:0,failed:0,percent:100};const t=r.tasks.reduce((e,o)=>{var s,i,l;const n=((s=o.steps)==null?void 0:s.length)||1;if(e.total+=n,o.state.current==="pending")return e;if(!((i=o.steps)!=null&&i.length)){switch(o.state.current){case"completed":e.completed+=1;break;case"error":e.failed+=1}return e}return(l=o.steps)==null||l.forEach(y=>{if(y.completed!==H){e.completed+=1;return}["error","completed"].includes(o.state.current||"")&&y.started!==H&&(e.failed+=1)}),e},{total:0,completed:0,failed:0});return{...t,percent:t.completed/t.total*100}}function K(r,t,e){return new X(r,t,e)}function V({apiKey:r,baseUrl:t="https://api.cycle.io",hubId:e,fetch:o}){const n=F({baseUrl:t,fetch:o||fetch}),s={async onRequest({request:i}){return i.headers.set("Authorization",`Bearer ${r}`),i.headers.set("X-Hub-Id",e),i}};return n.use(s),n}m.getClient=V,m.getJobProgress=P,m.trackJob=K,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cycleplatform/api-client-typescript",
3
- "version": "0.2.5",
3
+ "version": "0.3.4",
4
4
  "description": "A Cycle API client for the web/nodejs with type safety.",
5
5
  "main": "./dist/index.umd.cjs",
6
6
  "module": "./dist/index.js",
@@ -17,12 +17,10 @@
17
17
  }
18
18
  }
19
19
  },
20
- "types": "./src/index.ts",
21
20
  "scripts": {
22
21
  "test": "vitest",
23
22
  "test:ts": "tsc --noEmit",
24
- "build:spec": "(cd api-spec; npm run build:platform)",
25
- "build:client": "npm run build:spec && npx openapi-typescript ./api-spec/dist/platform.yml --output ./src/generated/types.ts",
23
+ "build:client": "openapi-typescript ./api-spec/platform/api.yml --output ./src/generated/types.ts",
26
24
  "build:lib": "npm run build:client && vite build",
27
25
  "prepublishOnly": "npm run build:lib"
28
26
  },
@@ -42,13 +40,13 @@
42
40
  },
43
41
  "homepage": "https://github.com/cycleplatform/api-client-typescript#readme",
44
42
  "dependencies": {
45
- "openapi-fetch": "0.9.3"
43
+ "openapi-fetch": "0.13.4"
46
44
  },
47
45
  "devDependencies": {
48
- "msw": "2.2.13",
49
- "openapi-typescript": "6.7.5",
50
- "typescript": "^5.4.4",
51
- "vite": "5.2.8",
52
- "vitest": "1.4.0"
46
+ "msw": "2.7.0",
47
+ "openapi-typescript": "7.6.0",
48
+ "typescript": "5.7.3",
49
+ "vite": "6.0.11",
50
+ "vitest": "3.0.4"
53
51
  }
54
52
  }