@swishapp/api-client 0.25.0 → 0.26.0
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/client.d.ts +12 -6
- package/dist/index.js +3 -3
- package/dist/types.d.ts +6 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import type { SwishClientConfig, SwishClientOptions, ApiResponse, PaginatedApiResponse } from "./types";
|
|
2
2
|
import type * as types from "./openapi/types.gen";
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
3
|
+
export declare const defaultApiVersion = "2025-10";
|
|
4
|
+
export declare const defaultProxyBaseUrl = "/apps/wishlist/api";
|
|
5
5
|
export declare const createApiClient: (options: SwishClientOptions) => SwishClient;
|
|
6
6
|
export type { SwishClient };
|
|
7
7
|
declare class SwishClient {
|
|
8
8
|
private authToken?;
|
|
9
9
|
private profile?;
|
|
10
|
-
private
|
|
10
|
+
private useProxy;
|
|
11
|
+
private version;
|
|
12
|
+
private readonly proxyClient;
|
|
13
|
+
private readonly directClient;
|
|
11
14
|
constructor(options: SwishClientOptions);
|
|
12
15
|
setProfile(profile: string): void;
|
|
13
16
|
getProfile(): string | undefined;
|
|
14
17
|
setAuthToken(authToken: string): void;
|
|
15
|
-
setConfig(config: SwishClientConfig): void;
|
|
16
|
-
|
|
18
|
+
setConfig({ proxyBaseUrl, baseUrl, useProxy, ...config }: SwishClientConfig): void;
|
|
19
|
+
proxyRequestInterceptor(request: Request): Request;
|
|
20
|
+
directRequestInterceptor(request: Request): Request;
|
|
17
21
|
readonly items: {
|
|
18
22
|
list: (query?: types.ItemControllerFindData["query"]) => Promise<PaginatedApiResponse<types.Item>>;
|
|
19
23
|
create: (items: types.CreateItemInput) => Promise<ApiResponse<types.Item>>;
|
|
@@ -36,7 +40,9 @@ declare class SwishClient {
|
|
|
36
40
|
};
|
|
37
41
|
readonly profiles: {
|
|
38
42
|
customerAccountsVersion: () => Promise<ApiResponse<types.AccountsVersionResult>>;
|
|
39
|
-
createToken: (body?: types.CreateProfileTokenInput
|
|
43
|
+
createToken: (body?: types.CreateProfileTokenInput, options?: {
|
|
44
|
+
useProxy?: boolean;
|
|
45
|
+
}) => Promise<ApiResponse<types.CreateProfileTokenResult>>;
|
|
40
46
|
identify: (body: types.IdentifyProfileInput) => Promise<ApiResponse<types.IdentifyProfileResult>>;
|
|
41
47
|
};
|
|
42
48
|
private readonly handleRequest;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var Se=Object.defineProperty;var
|
|
1
|
+
var Se=Object.defineProperty;var s=(e,t)=>Se(e,"name",{value:t,configurable:!0});var v={bodySerializer:s(e=>JSON.stringify(e,(t,r)=>typeof r=="bigint"?r.toString():r),"bodySerializer")};var Ee={$body_:"body",$headers_:"headers",$path_:"path",$query_:"query"},He=Object.entries(Ee);var _=s(({onRequest:e,onSseError:t,onSseEvent:r,responseTransformer:n,responseValidator:o,sseDefaultRetryDelay:p,sseMaxRetryAttempts:d,sseMaxRetryDelay:a,sseSleepFn:l,url:u,...i})=>{let h,L=l??(c=>new Promise(m=>setTimeout(m,c)));return{stream:s(async function*(){let c=p??3e3,m=0,R=i.signal??new AbortController().signal;for(;!R.aborted;){m++;let q=i.headers instanceof Headers?i.headers:new Headers(i.headers);h!==void 0&&q.set("Last-Event-ID",h);try{let T={redirect:"follow",...i,body:i.serializedBody,headers:q,signal:R},g=new Request(u,T);e&&(g=await e(u,T));let C=await(i.fetch??globalThis.fetch)(g);if(!C.ok)throw new Error(`SSE failed: ${C.status} ${C.statusText}`);if(!C.body)throw new Error("No body in SSE response");let b=C.body.pipeThrough(new TextDecoderStream).getReader(),j="",V=s(()=>{try{b.cancel()}catch{}},"abortHandler");R.addEventListener("abort",V);try{for(;;){let{done:xe,value:Re}=await b.read();if(xe)break;j+=Re;let M=j.split(`
|
|
2
2
|
|
|
3
3
|
`);j=M.pop()??"";for(let Te of M){let we=Te.split(`
|
|
4
|
-
`),A=[],W;for(let I of we)if(I.startsWith("data:"))A.push(I.replace(/^data:\s*/,""));else if(I.startsWith("event:"))W=I.replace(/^event:\s*/,"");else if(I.startsWith("id:"))
|
|
5
|
-
`);try{w=JSON.parse(I),Q=!0}catch{w=I}}Q&&(i&&await i(w),o&&(w=await o(w))),r==null||r({data:w,event:W,id:f,retry:c}),A.length&&(yield w)}}}finally{R.removeEventListener("abort",V),O.releaseLock()}break}catch(T){if(t==null||t(T),d!==void 0&&m>=d)break;let g=Math.min(c*2**(m-1),a??3e4);await E(g)}}},"createStream")()}},"createSseClient");var Ee=n(e=>{switch(e){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},"separatorArrayExplode"),Le=n(e=>{switch(e){case"form":return",";case"pipeDelimited":return"|";case"spaceDelimited":return"%20";default:return","}},"separatorArrayNoExplode"),De=n(e=>{switch(e){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},"separatorObjectExplode"),B=n(({allowReserved:e,explode:t,name:r,style:o,value:i})=>{if(!t){let a=(e?i:i.map(l=>encodeURIComponent(l))).join(Le(o));switch(o){case"label":return`.${a}`;case"matrix":return`;${r}=${a}`;case"simple":return a;default:return`${r}=${a}`}}let p=Ee(o),d=i.map(a=>o==="label"||o==="simple"?e?a:encodeURIComponent(a):x({allowReserved:e,name:r,value:a})).join(p);return o==="label"||o==="matrix"?p+d:d},"serializeArrayParam"),x=n(({allowReserved:e,name:t,value:r})=>{if(r==null)return"";if(typeof r=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return`${t}=${e?r:encodeURIComponent(r)}`},"serializePrimitiveParam"),P=n(({allowReserved:e,explode:t,name:r,style:o,value:i,valueOnly:p})=>{if(i instanceof Date)return p?i.toISOString():`${r}=${i.toISOString()}`;if(o!=="deepObject"&&!t){let l=[];Object.entries(i).forEach(([s,f])=>{l=[...l,s,e?f:encodeURIComponent(f)]});let u=l.join(",");switch(o){case"form":return`${r}=${u}`;case"label":return`.${u}`;case"matrix":return`;${r}=${u}`;default:return u}}let d=De(o),a=Object.entries(i).map(([l,u])=>x({allowReserved:e,name:o==="deepObject"?`${r}[${l}]`:l,value:u})).join(d);return o==="label"||o==="matrix"?d+a:a},"serializeObjectParam");var qe=/\{[^{}]+\}/g,ke=n(({path:e,url:t})=>{let r=t,o=t.match(qe);if(o)for(let i of o){let p=!1,d=i.substring(1,i.length-1),a="simple";d.endsWith("*")&&(p=!0,d=d.substring(0,d.length-1)),d.startsWith(".")?(d=d.substring(1),a="label"):d.startsWith(";")&&(d=d.substring(1),a="matrix");let l=e[d];if(l==null)continue;if(Array.isArray(l)){r=r.replace(i,B({explode:p,name:d,style:a,value:l}));continue}if(typeof l=="object"){r=r.replace(i,P({explode:p,name:d,style:a,value:l,valueOnly:!0}));continue}if(a==="matrix"){r=r.replace(i,`;${x({name:d,value:l})}`);continue}let u=encodeURIComponent(a==="label"?`.${l}`:l);r=r.replace(i,u)}return r},"defaultPathSerializer"),K=n(({baseUrl:e,path:t,query:r,querySerializer:o,url:i})=>{let p=i.startsWith("/")?i:`/${i}`,d=(e??"")+p;t&&(d=ke({path:t,url:d}));let a=r?o(r):"";return a.startsWith("?")&&(a=a.substring(1)),a&&(d+=`?${a}`),d},"getUrl");function G(e){let t=e.body!==void 0;if(t&&e.bodySerializer)return"serializedBody"in e?e.serializedBody!==void 0&&e.serializedBody!==""?e.serializedBody:null:e.body!==""?e.body:null;if(t)return e.body}n(G,"getValidRequestBody");var X=n(async(e,t)=>{let r=typeof t=="function"?await t(e):t;if(r)return e.scheme==="bearer"?`Bearer ${r}`:e.scheme==="basic"?`Basic ${btoa(r)}`:r},"getAuthToken");var Y=n(({allowReserved:e,array:t,object:r}={})=>n(i=>{let p=[];if(i&&typeof i=="object")for(let d in i){let a=i[d];if(a!=null)if(Array.isArray(a)){let l=B({allowReserved:e,explode:!0,name:d,style:"form",value:a,...t});l&&p.push(l)}else if(typeof a=="object"){let l=P({allowReserved:e,explode:!0,name:d,style:"deepObject",value:a,...r});l&&p.push(l)}else{let l=x({allowReserved:e,name:d,value:a});l&&p.push(l)}}return p.join("&")},"querySerializer"),"createQuerySerializer"),Z=n(e=>{var r;if(!e)return"stream";let t=(r=e.split(";")[0])==null?void 0:r.trim();if(t){if(t.startsWith("application/json")||t.endsWith("+json"))return"json";if(t==="multipart/form-data")return"formData";if(["application/","audio/","image/","video/"].some(o=>t.startsWith(o)))return"blob";if(t.startsWith("text/"))return"text"}},"getParseAs"),Ae=n((e,t)=>{var r,o;return t?!!(e.headers.has(t)||(r=e.query)!=null&&r[t]||(o=e.headers.get("Cookie"))!=null&&o.includes(`${t}=`)):!1},"checkForExistence"),ee=n(async({security:e,...t})=>{for(let r of e){if(Ae(t,r.name))continue;let o=await X(r,t.auth);if(!o)continue;let i=r.name??"Authorization";switch(r.in){case"query":t.query||(t.query={}),t.query[i]=o;break;case"cookie":t.headers.append("Cookie",`${i}=${o}`);break;case"header":default:t.headers.set(i,o);break}}},"setAuthParams"),v=n(e=>K({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:Y(e.querySerializer),url:e.url}),"buildUrl"),U=n((e,t)=>{var o;let r={...e,...t};return(o=r.baseUrl)!=null&&o.endsWith("/")&&(r.baseUrl=r.baseUrl.substring(0,r.baseUrl.length-1)),r.headers=z(e.headers,t.headers),r},"mergeConfigs"),Be=n(e=>{let t=[];return e.forEach((r,o)=>{t.push([o,r])}),t},"headersEntries"),z=n((...e)=>{let t=new Headers;for(let r of e){if(!r)continue;let o=r instanceof Headers?Be(r):Object.entries(r);for(let[i,p]of o)if(p===null)t.delete(i);else if(Array.isArray(p))for(let d of p)t.append(i,d);else p!==void 0&&t.set(i,typeof p=="object"?JSON.stringify(p):p)}return t},"mergeHeaders"),$=class ${constructor(){this.fns=[]}clear(){this.fns=[]}eject(t){let r=this.getInterceptorIndex(t);this.fns[r]&&(this.fns[r]=null)}exists(t){let r=this.getInterceptorIndex(t);return!!this.fns[r]}getInterceptorIndex(t){return typeof t=="number"?this.fns[t]?t:-1:this.fns.indexOf(t)}update(t,r){let o=this.getInterceptorIndex(t);return this.fns[o]?(this.fns[o]=r,t):!1}use(t){return this.fns.push(t),this.fns.length-1}};n($,"Interceptors");var D=$,te=n(()=>({error:new D,request:new D,response:new D}),"createInterceptors"),Pe=Y({allowReserved:!1,array:{explode:!0,style:"form"},object:{explode:!0,style:"deepObject"}}),ze={"Content-Type":"application/json"},S=n((e={})=>({...F,headers:ze,parseAs:"auto",querySerializer:Pe,...e}),"createConfig");var q=n((e={})=>{let t=U(S(),e),r=n(()=>({...t}),"getConfig"),o=n(u=>(t=U(t,u),r()),"setConfig"),i=te(),p=n(async u=>{let s={...t,...u,fetch:u.fetch??t.fetch??globalThis.fetch,headers:z(t.headers,u.headers),serializedBody:void 0};s.security&&await ee({...s,security:s.security}),s.requestValidator&&await s.requestValidator(s),s.body!==void 0&&s.bodySerializer&&(s.serializedBody=s.bodySerializer(s.body)),(s.body===void 0||s.serializedBody==="")&&s.headers.delete("Content-Type");let f=v(s);return{opts:s,url:f}},"beforeRequest"),d=n(async u=>{let{opts:s,url:f}=await p(u),E={redirect:"follow",...s,body:G(s)},b=new Request(f,E);for(let h of i.request.fns)h&&(b=await h(b,s));let k=s.fetch,c=await k(b);for(let h of i.response.fns)h&&(c=await h(c,b,s));let m={request:b,response:c};if(c.ok){let h=(s.parseAs==="auto"?Z(c.headers.get("Content-Type")):s.parseAs)??"json";if(c.status===204||c.headers.get("Content-Length")==="0"){let O;switch(h){case"arrayBuffer":case"blob":case"text":O=await c[h]();break;case"formData":O=new FormData;break;case"stream":O=c.body;break;case"json":default:O={};break}return s.responseStyle==="data"?O:{data:O,...m}}let C;switch(h){case"arrayBuffer":case"blob":case"formData":case"json":case"text":C=await c[h]();break;case"stream":return s.responseStyle==="data"?c.body:{data:c.body,...m}}return h==="json"&&(s.responseValidator&&await s.responseValidator(C),s.responseTransformer&&(C=await s.responseTransformer(C))),s.responseStyle==="data"?C:{data:C,...m}}let R=await c.text(),L;try{L=JSON.parse(R)}catch{}let T=L??R,g=T;for(let h of i.error.fns)h&&(g=await h(T,c,b,s));if(g=g||{},s.throwOnError)throw g;return s.responseStyle==="data"?void 0:{error:g,...m}},"request"),a=n(u=>s=>d({...s,method:u}),"makeMethodFn"),l=n(u=>async s=>{let{opts:f,url:E}=await p(s);return _({...f,body:f.body,headers:f.headers,method:u,onRequest:n(async(b,k)=>{let c=new Request(b,k);for(let m of i.request.fns)m&&(c=await m(c,f));return c},"onRequest"),url:E})},"makeSseFn");return{buildUrl:v,connect:a("CONNECT"),delete:a("DELETE"),get:a("GET"),getConfig:r,head:a("HEAD"),interceptors:i,options:a("OPTIONS"),patch:a("PATCH"),post:a("POST"),put:a("PUT"),request:d,setConfig:o,sse:{connect:l("CONNECT"),delete:l("DELETE"),get:l("GET"),head:l("HEAD"),options:l("OPTIONS"),patch:l("PATCH"),post:l("POST"),put:l("PUT"),trace:l("TRACE")},trace:a("TRACE")}},"createClient");var y=q(S({baseUrl:"https://swish.app/api/2025-10"}));var re=n(e=>((e==null?void 0:e.client)??y).get({security:[{scheme:"bearer",type:"http"}],url:"/lists",...e}),"listControllerFind"),ne=n(e=>(e.client??y).post({security:[{scheme:"bearer",type:"http"}],url:"/lists",...e,headers:{"Content-Type":"application/json",...e.headers}}),"listControllerCreate"),oe=n(e=>(e.client??y).delete({security:[{scheme:"bearer",type:"http"}],url:"/lists/{listId}",...e}),"listControllerDeleteById"),se=n(e=>(e.client??y).get({security:[{scheme:"bearer",type:"http"}],url:"/lists/{listId}",...e}),"listControllerFindById"),ie=n(e=>(e.client??y).patch({security:[{scheme:"bearer",type:"http"}],url:"/lists/{listId}",...e,headers:{"Content-Type":"application/json",...e.headers}}),"listControllerUpdateById"),ae=n(e=>(e.client??y).put({security:[{scheme:"bearer",type:"http"}],url:"/lists/{listId}/items/order",...e,headers:{"Content-Type":"application/json",...e.headers}}),"listControllerSetListItemsOrder"),le=n(e=>(e.client??y).post({security:[{scheme:"bearer",type:"http"}],url:"/lists/{listId}/items",...e,headers:{"Content-Type":"application/json",...e.headers}}),"listControllerAddItemsToList"),de=n(e=>(e.client??y).delete({security:[{scheme:"bearer",type:"http"}],url:"/lists/{listId}/items/{itemId}",...e}),"listControllerRemoveItemFromList"),pe=n(e=>(e.client??y).delete({security:[{scheme:"bearer",type:"http"}],url:"/items",...e,headers:{"Content-Type":"application/json",...e.headers}}),"itemControllerDelete"),ce=n(e=>((e==null?void 0:e.client)??y).get({security:[{scheme:"bearer",type:"http"}],url:"/items",...e}),"itemControllerFind"),ue=n(e=>(e.client??y).post({security:[{scheme:"bearer",type:"http"}],url:"/items",...e,headers:{"Content-Type":"application/json",...e.headers}}),"itemControllerCreate"),ye=n(e=>((e==null?void 0:e.client)??y).get({security:[{scheme:"bearer",type:"http"}],url:"/items/count",...e}),"itemControllerCount"),fe=n(e=>(e.client??y).delete({security:[{scheme:"bearer",type:"http"}],url:"/items/{itemId}",...e}),"itemControllerDeleteById"),he=n(e=>(e.client??y).get({security:[{scheme:"bearer",type:"http"}],url:"/items/{itemId}",...e}),"itemControllerFindById"),me=n(e=>(e.client??y).patch({security:[{scheme:"bearer",type:"http"}],url:"/items/{itemId}",...e,headers:{"Content-Type":"application/json",...e.headers}}),"itemControllerUpdateById"),Ce=n(e=>(e.client??y).put({security:[{scheme:"bearer",type:"http"}],url:"/items/{itemId}/lists",...e,headers:{"Content-Type":"application/json",...e.headers}}),"itemControllerSetListsById"),Ie=n(e=>((e==null?void 0:e.client)??y).get({security:[{scheme:"bearer",type:"http"}],url:"/profiles/accounts-version",...e}),"profileControllerCustomerAccountsVersion"),ge=n(e=>(e.client??y).post({security:[{scheme:"bearer",type:"http"}],url:"/profiles/identify",...e,headers:{"Content-Type":"application/json",...e.headers}}),"profileControllerIdentify"),Oe=n(e=>(e.client??y).post({security:[{scheme:"bearer",type:"http"}],url:"/profiles/token",...e,headers:{"Content-Type":"application/json",...e.headers}}),"profileControllerCreateToken");var Fe="2025-10",ve=`https://swish.app/api/${Fe}`,xt=n(e=>new N(e),"createApiClient"),H=class H{constructor(t){this.client=q(S({baseUrl:ve}));this.items={list:n(t=>this.handlePaginatedRequest(ce({query:t,client:this.client})),"list"),create:n(t=>this.handleRequest(ue({body:t,client:this.client})),"create"),delete:n(t=>this.handleRequest(pe({body:{itemIds:t},client:this.client})),"delete"),findById:n(t=>this.handleRequest(he({path:{itemId:t},client:this.client})),"findById"),updateById:n((t,r)=>this.handleRequest(me({body:r,path:{itemId:t},client:this.client})),"updateById"),deleteById:n(t=>this.handleRequest(fe({path:{itemId:t},client:this.client})),"deleteById"),setListsById:n((t,r)=>this.handleRequest(Ce({body:{listIds:r},path:{itemId:t},client:this.client})),"setListsById"),count:n(()=>this.handleRequest(ye({client:this.client})),"count")};this.lists={list:n(t=>this.handlePaginatedRequest(re({query:t,client:this.client})),"list"),create:n(t=>this.handleRequest(ne({body:t,client:this.client})),"create"),findById:n(t=>this.handleRequest(se({path:{listId:t},client:this.client})),"findById"),updateById:n((t,r)=>this.handleRequest(ie({body:r,path:{listId:t},client:this.client})),"updateById"),deleteById:n(t=>this.handleRequest(oe({path:{listId:t},client:this.client})),"deleteById"),orderItems:n((t,r)=>this.handleRequest(ae({body:{itemIds:r},path:{listId:t},client:this.client})),"orderItems"),addItemsToList:n((t,r)=>this.handleRequest(le({body:{itemIds:r},path:{listId:t},client:this.client})),"addItemsToList"),removeItemFromList:n((t,r)=>this.handleRequest(de({path:{listId:t,itemId:r},client:this.client})),"removeItemFromList")};this.profiles={customerAccountsVersion:n(()=>this.handleRequest(Ie({client:this.client})),"customerAccountsVersion"),createToken:n((t={})=>this.handleRequest(Oe({body:t,client:this.client})),"createToken"),identify:n(t=>this.handleRequest(ge({body:t,client:this.client})),"identify")};this.handleRequest=n(async t=>{let{data:r,error:o}=await t;return o!=null&&o.error?{error:o.error}:{data:r==null?void 0:r.data}},"handleRequest");this.handlePaginatedRequest=n(async t=>{var i;let{data:r,error:o}=await t;return o!=null&&o.error?{error:o.error}:{data:(r==null?void 0:r.data)??[],pageInfo:(r==null?void 0:r.pageInfo)??{next:null,previous:null,totalCount:((i=r==null?void 0:r.data)==null?void 0:i.length)??0}}},"handlePaginatedRequest");this.profile=t.profile,t.authToken&&(this.authToken=t.authToken),t.config&&this.client.setConfig(t.config),this.client.interceptors.request.use(this.requestInterceptor.bind(this)),t.requestInterceptor&&this.client.interceptors.request.use(t.requestInterceptor),t.responseInterceptor&&this.client.interceptors.response.use(t.responseInterceptor)}setProfile(t){this.profile=t}getProfile(){return this.profile}setAuthToken(t){this.authToken=t}setConfig(t){this.client.setConfig(t)}requestInterceptor(t){return this.authToken&&t.headers.set("Authorization",`Bearer ${this.authToken}`),this.profile&&t.headers.set("Profile",this.profile),t}};n(H,"SwishClient");var N=H;export{Fe as apiVersion,ve as baseUrl,xt as createApiClient};
|
|
4
|
+
`),A=[],W;for(let I of we)if(I.startsWith("data:"))A.push(I.replace(/^data:\s*/,""));else if(I.startsWith("event:"))W=I.replace(/^event:\s*/,"");else if(I.startsWith("id:"))h=I.replace(/^id:\s*/,"");else if(I.startsWith("retry:")){let J=Number.parseInt(I.replace(/^retry:\s*/,""),10);Number.isNaN(J)||(c=J)}let w,Q=!1;if(A.length){let I=A.join(`
|
|
5
|
+
`);try{w=JSON.parse(I),Q=!0}catch{w=I}}Q&&(o&&await o(w),n&&(w=await n(w))),r==null||r({data:w,event:W,id:h,retry:c}),A.length&&(yield w)}}}finally{R.removeEventListener("abort",V),b.releaseLock()}break}catch(T){if(t==null||t(T),d!==void 0&&m>=d)break;let g=Math.min(c*2**(m-1),a??3e4);await L(g)}}},"createStream")()}},"createSseClient");var Le=s(e=>{switch(e){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},"separatorArrayExplode"),qe=s(e=>{switch(e){case"form":return",";case"pipeDelimited":return"|";case"spaceDelimited":return"%20";default:return","}},"separatorArrayNoExplode"),De=s(e=>{switch(e){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},"separatorObjectExplode"),P=s(({allowReserved:e,explode:t,name:r,style:n,value:o})=>{if(!t){let a=(e?o:o.map(l=>encodeURIComponent(l))).join(qe(n));switch(n){case"label":return`.${a}`;case"matrix":return`;${r}=${a}`;case"simple":return a;default:return`${r}=${a}`}}let p=Le(n),d=o.map(a=>n==="label"||n==="simple"?e?a:encodeURIComponent(a):S({allowReserved:e,name:r,value:a})).join(p);return n==="label"||n==="matrix"?p+d:d},"serializeArrayParam"),S=s(({allowReserved:e,name:t,value:r})=>{if(r==null)return"";if(typeof r=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return`${t}=${e?r:encodeURIComponent(r)}`},"serializePrimitiveParam"),B=s(({allowReserved:e,explode:t,name:r,style:n,value:o,valueOnly:p})=>{if(o instanceof Date)return p?o.toISOString():`${r}=${o.toISOString()}`;if(n!=="deepObject"&&!t){let l=[];Object.entries(o).forEach(([i,h])=>{l=[...l,i,e?h:encodeURIComponent(h)]});let u=l.join(",");switch(n){case"form":return`${r}=${u}`;case"label":return`.${u}`;case"matrix":return`;${r}=${u}`;default:return u}}let d=De(n),a=Object.entries(o).map(([l,u])=>S({allowReserved:e,name:n==="deepObject"?`${r}[${l}]`:l,value:u})).join(d);return n==="label"||n==="matrix"?d+a:a},"serializeObjectParam");var ke=/\{[^{}]+\}/g,Ae=s(({path:e,url:t})=>{let r=t,n=t.match(ke);if(n)for(let o of n){let p=!1,d=o.substring(1,o.length-1),a="simple";d.endsWith("*")&&(p=!0,d=d.substring(0,d.length-1)),d.startsWith(".")?(d=d.substring(1),a="label"):d.startsWith(";")&&(d=d.substring(1),a="matrix");let l=e[d];if(l==null)continue;if(Array.isArray(l)){r=r.replace(o,P({explode:p,name:d,style:a,value:l}));continue}if(typeof l=="object"){r=r.replace(o,B({explode:p,name:d,style:a,value:l,valueOnly:!0}));continue}if(a==="matrix"){r=r.replace(o,`;${S({name:d,value:l})}`);continue}let u=encodeURIComponent(a==="label"?`.${l}`:l);r=r.replace(o,u)}return r},"defaultPathSerializer"),K=s(({baseUrl:e,path:t,query:r,querySerializer:n,url:o})=>{let p=o.startsWith("/")?o:`/${o}`,d=(e??"")+p;t&&(d=Ae({path:t,url:d}));let a=r?n(r):"";return a.startsWith("?")&&(a=a.substring(1)),a&&(d+=`?${a}`),d},"getUrl");function G(e){let t=e.body!==void 0;if(t&&e.bodySerializer)return"serializedBody"in e?e.serializedBody!==void 0&&e.serializedBody!==""?e.serializedBody:null:e.body!==""?e.body:null;if(t)return e.body}s(G,"getValidRequestBody");var X=s(async(e,t)=>{let r=typeof t=="function"?await t(e):t;if(r)return e.scheme==="bearer"?`Bearer ${r}`:e.scheme==="basic"?`Basic ${btoa(r)}`:r},"getAuthToken");var Y=s(({allowReserved:e,array:t,object:r}={})=>s(o=>{let p=[];if(o&&typeof o=="object")for(let d in o){let a=o[d];if(a!=null)if(Array.isArray(a)){let l=P({allowReserved:e,explode:!0,name:d,style:"form",value:a,...t});l&&p.push(l)}else if(typeof a=="object"){let l=B({allowReserved:e,explode:!0,name:d,style:"deepObject",value:a,...r});l&&p.push(l)}else{let l=S({allowReserved:e,name:d,value:a});l&&p.push(l)}}return p.join("&")},"querySerializer"),"createQuerySerializer"),Z=s(e=>{var r;if(!e)return"stream";let t=(r=e.split(";")[0])==null?void 0:r.trim();if(t){if(t.startsWith("application/json")||t.endsWith("+json"))return"json";if(t==="multipart/form-data")return"formData";if(["application/","audio/","image/","video/"].some(n=>t.startsWith(n)))return"blob";if(t.startsWith("text/"))return"text"}},"getParseAs"),Pe=s((e,t)=>{var r,n;return t?!!(e.headers.has(t)||(r=e.query)!=null&&r[t]||(n=e.headers.get("Cookie"))!=null&&n.includes(`${t}=`)):!1},"checkForExistence"),ee=s(async({security:e,...t})=>{for(let r of e){if(Pe(t,r.name))continue;let n=await X(r,t.auth);if(!n)continue;let o=r.name??"Authorization";switch(r.in){case"query":t.query||(t.query={}),t.query[o]=n;break;case"cookie":t.headers.append("Cookie",`${o}=${n}`);break;case"header":default:t.headers.set(o,n);break}}},"setAuthParams"),F=s(e=>K({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:Y(e.querySerializer),url:e.url}),"buildUrl"),U=s((e,t)=>{var n;let r={...e,...t};return(n=r.baseUrl)!=null&&n.endsWith("/")&&(r.baseUrl=r.baseUrl.substring(0,r.baseUrl.length-1)),r.headers=z(e.headers,t.headers),r},"mergeConfigs"),Be=s(e=>{let t=[];return e.forEach((r,n)=>{t.push([n,r])}),t},"headersEntries"),z=s((...e)=>{let t=new Headers;for(let r of e){if(!r)continue;let n=r instanceof Headers?Be(r):Object.entries(r);for(let[o,p]of n)if(p===null)t.delete(o);else if(Array.isArray(p))for(let d of p)t.append(o,d);else p!==void 0&&t.set(o,typeof p=="object"?JSON.stringify(p):p)}return t},"mergeHeaders"),$=class ${constructor(){this.fns=[]}clear(){this.fns=[]}eject(t){let r=this.getInterceptorIndex(t);this.fns[r]&&(this.fns[r]=null)}exists(t){let r=this.getInterceptorIndex(t);return!!this.fns[r]}getInterceptorIndex(t){return typeof t=="number"?this.fns[t]?t:-1:this.fns.indexOf(t)}update(t,r){let n=this.getInterceptorIndex(t);return this.fns[n]?(this.fns[n]=r,t):!1}use(t){return this.fns.push(t),this.fns.length-1}};s($,"Interceptors");var D=$,te=s(()=>({error:new D,request:new D,response:new D}),"createInterceptors"),ze=Y({allowReserved:!1,array:{explode:!0,style:"form"},object:{explode:!0,style:"deepObject"}}),je={"Content-Type":"application/json"},x=s((e={})=>({...v,headers:je,parseAs:"auto",querySerializer:ze,...e}),"createConfig");var E=s((e={})=>{let t=U(x(),e),r=s(()=>({...t}),"getConfig"),n=s(u=>(t=U(t,u),r()),"setConfig"),o=te(),p=s(async u=>{let i={...t,...u,fetch:u.fetch??t.fetch??globalThis.fetch,headers:z(t.headers,u.headers),serializedBody:void 0};i.security&&await ee({...i,security:i.security}),i.requestValidator&&await i.requestValidator(i),i.body!==void 0&&i.bodySerializer&&(i.serializedBody=i.bodySerializer(i.body)),(i.body===void 0||i.serializedBody==="")&&i.headers.delete("Content-Type");let h=F(i);return{opts:i,url:h}},"beforeRequest"),d=s(async u=>{let{opts:i,url:h}=await p(u),L={redirect:"follow",...i,body:G(i)},O=new Request(h,L);for(let f of o.request.fns)f&&(O=await f(O,i));let k=i.fetch,c=await k(O);for(let f of o.response.fns)f&&(c=await f(c,O,i));let m={request:O,response:c};if(c.ok){let f=(i.parseAs==="auto"?Z(c.headers.get("Content-Type")):i.parseAs)??"json";if(c.status===204||c.headers.get("Content-Length")==="0"){let b;switch(f){case"arrayBuffer":case"blob":case"text":b=await c[f]();break;case"formData":b=new FormData;break;case"stream":b=c.body;break;case"json":default:b={};break}return i.responseStyle==="data"?b:{data:b,...m}}let C;switch(f){case"arrayBuffer":case"blob":case"formData":case"json":case"text":C=await c[f]();break;case"stream":return i.responseStyle==="data"?c.body:{data:c.body,...m}}return f==="json"&&(i.responseValidator&&await i.responseValidator(C),i.responseTransformer&&(C=await i.responseTransformer(C))),i.responseStyle==="data"?C:{data:C,...m}}let R=await c.text(),q;try{q=JSON.parse(R)}catch{}let T=q??R,g=T;for(let f of o.error.fns)f&&(g=await f(T,c,O,i));if(g=g||{},i.throwOnError)throw g;return i.responseStyle==="data"?void 0:{error:g,...m}},"request"),a=s(u=>i=>d({...i,method:u}),"makeMethodFn"),l=s(u=>async i=>{let{opts:h,url:L}=await p(i);return _({...h,body:h.body,headers:h.headers,method:u,onRequest:s(async(O,k)=>{let c=new Request(O,k);for(let m of o.request.fns)m&&(c=await m(c,h));return c},"onRequest"),url:L})},"makeSseFn");return{buildUrl:F,connect:a("CONNECT"),delete:a("DELETE"),get:a("GET"),getConfig:r,head:a("HEAD"),interceptors:o,options:a("OPTIONS"),patch:a("PATCH"),post:a("POST"),put:a("PUT"),request:d,setConfig:n,sse:{connect:l("CONNECT"),delete:l("DELETE"),get:l("GET"),head:l("HEAD"),options:l("OPTIONS"),patch:l("PATCH"),post:l("POST"),put:l("PUT"),trace:l("TRACE")},trace:a("TRACE")}},"createClient");var y=E(x({baseUrl:"https://swish.app/api/2025-10"}));var re=s(e=>((e==null?void 0:e.client)??y).get({security:[{scheme:"bearer",type:"http"}],url:"/lists",...e}),"listControllerFind"),se=s(e=>(e.client??y).post({security:[{scheme:"bearer",type:"http"}],url:"/lists",...e,headers:{"Content-Type":"application/json",...e.headers}}),"listControllerCreate"),ne=s(e=>(e.client??y).delete({security:[{scheme:"bearer",type:"http"}],url:"/lists/{listId}",...e}),"listControllerDeleteById"),oe=s(e=>(e.client??y).get({security:[{scheme:"bearer",type:"http"}],url:"/lists/{listId}",...e}),"listControllerFindById"),ie=s(e=>(e.client??y).patch({security:[{scheme:"bearer",type:"http"}],url:"/lists/{listId}",...e,headers:{"Content-Type":"application/json",...e.headers}}),"listControllerUpdateById"),ae=s(e=>(e.client??y).put({security:[{scheme:"bearer",type:"http"}],url:"/lists/{listId}/items/order",...e,headers:{"Content-Type":"application/json",...e.headers}}),"listControllerSetListItemsOrder"),le=s(e=>(e.client??y).post({security:[{scheme:"bearer",type:"http"}],url:"/lists/{listId}/items",...e,headers:{"Content-Type":"application/json",...e.headers}}),"listControllerAddItemsToList"),de=s(e=>(e.client??y).delete({security:[{scheme:"bearer",type:"http"}],url:"/lists/{listId}/items/{itemId}",...e}),"listControllerRemoveItemFromList"),pe=s(e=>(e.client??y).delete({security:[{scheme:"bearer",type:"http"}],url:"/items",...e,headers:{"Content-Type":"application/json",...e.headers}}),"itemControllerDelete"),ce=s(e=>((e==null?void 0:e.client)??y).get({security:[{scheme:"bearer",type:"http"}],url:"/items",...e}),"itemControllerFind"),ue=s(e=>(e.client??y).post({security:[{scheme:"bearer",type:"http"}],url:"/items",...e,headers:{"Content-Type":"application/json",...e.headers}}),"itemControllerCreate"),ye=s(e=>((e==null?void 0:e.client)??y).get({security:[{scheme:"bearer",type:"http"}],url:"/items/count",...e}),"itemControllerCount"),he=s(e=>(e.client??y).delete({security:[{scheme:"bearer",type:"http"}],url:"/items/{itemId}",...e}),"itemControllerDeleteById"),fe=s(e=>(e.client??y).get({security:[{scheme:"bearer",type:"http"}],url:"/items/{itemId}",...e}),"itemControllerFindById"),me=s(e=>(e.client??y).patch({security:[{scheme:"bearer",type:"http"}],url:"/items/{itemId}",...e,headers:{"Content-Type":"application/json",...e.headers}}),"itemControllerUpdateById"),Ce=s(e=>(e.client??y).put({security:[{scheme:"bearer",type:"http"}],url:"/items/{itemId}/lists",...e,headers:{"Content-Type":"application/json",...e.headers}}),"itemControllerSetListsById"),Ie=s(e=>((e==null?void 0:e.client)??y).get({security:[{scheme:"bearer",type:"http"}],url:"/profiles/accounts-version",...e}),"profileControllerCustomerAccountsVersion"),ge=s(e=>(e.client??y).post({security:[{scheme:"bearer",type:"http"}],url:"/profiles/identify",...e,headers:{"Content-Type":"application/json",...e.headers}}),"profileControllerIdentify"),be=s(e=>(e.client??y).post({security:[{scheme:"bearer",type:"http"}],url:"/profiles/token",...e,headers:{"Content-Type":"application/json",...e.headers}}),"profileControllerCreateToken");var Fe="2025-10",Oe="/apps/wishlist/api",Et=s(e=>new N(e),"createApiClient"),H=class H{constructor(t){this.useProxy=!1;this.version=Fe;this.items={list:s(t=>this.handlePaginatedRequest(ce({query:t,client:this.useProxy?this.proxyClient:this.directClient})),"list"),create:s(t=>this.handleRequest(ue({body:t,client:this.useProxy?this.proxyClient:this.directClient})),"create"),delete:s(t=>this.handleRequest(pe({body:{itemIds:t},client:this.useProxy?this.proxyClient:this.directClient})),"delete"),findById:s(t=>this.handleRequest(fe({path:{itemId:t},client:this.useProxy?this.proxyClient:this.directClient})),"findById"),updateById:s((t,r)=>this.handleRequest(me({body:r,path:{itemId:t},client:this.useProxy?this.proxyClient:this.directClient})),"updateById"),deleteById:s(t=>this.handleRequest(he({path:{itemId:t},client:this.useProxy?this.proxyClient:this.directClient})),"deleteById"),setListsById:s((t,r)=>this.handleRequest(Ce({body:{listIds:r},path:{itemId:t},client:this.useProxy?this.proxyClient:this.directClient})),"setListsById"),count:s(()=>this.handleRequest(ye({client:this.useProxy?this.proxyClient:this.directClient})),"count")};this.lists={list:s(t=>this.handlePaginatedRequest(re({query:t,client:this.useProxy?this.proxyClient:this.directClient})),"list"),create:s(t=>this.handleRequest(se({body:t,client:this.useProxy?this.proxyClient:this.directClient})),"create"),findById:s(t=>this.handleRequest(oe({path:{listId:t},client:this.useProxy?this.proxyClient:this.directClient})),"findById"),updateById:s((t,r)=>this.handleRequest(ie({body:r,path:{listId:t},client:this.useProxy?this.proxyClient:this.directClient})),"updateById"),deleteById:s(t=>this.handleRequest(ne({path:{listId:t},client:this.useProxy?this.proxyClient:this.directClient})),"deleteById"),orderItems:s((t,r)=>this.handleRequest(ae({body:{itemIds:r},path:{listId:t},client:this.useProxy?this.proxyClient:this.directClient})),"orderItems"),addItemsToList:s((t,r)=>this.handleRequest(le({body:{itemIds:r},path:{listId:t},client:this.useProxy?this.proxyClient:this.directClient})),"addItemsToList"),removeItemFromList:s((t,r)=>this.handleRequest(de({path:{listId:t,itemId:r},client:this.useProxy?this.proxyClient:this.directClient})),"removeItemFromList")};this.profiles={customerAccountsVersion:s(()=>this.handleRequest(Ie({client:this.useProxy?this.proxyClient:this.directClient})),"customerAccountsVersion"),createToken:s((t={},r)=>this.handleRequest(be({body:t,client:this.useProxy||r!=null&&r.useProxy?this.proxyClient:this.directClient})),"createToken"),identify:s(t=>this.handleRequest(ge({body:t,client:this.useProxy?this.proxyClient:this.directClient})),"identify")};this.handleRequest=s(async t=>{let{data:r,error:n}=await t;return n!=null&&n.error?{error:n.error}:{data:r==null?void 0:r.data}},"handleRequest");this.handlePaginatedRequest=s(async t=>{var o;let{data:r,error:n}=await t;return n!=null&&n.error?{error:n.error}:{data:(r==null?void 0:r.data)??[],pageInfo:(r==null?void 0:r.pageInfo)??{next:null,previous:null,totalCount:((o=r==null?void 0:r.data)==null?void 0:o.length)??0}}},"handlePaginatedRequest");var r;this.profile=t.profile,(r=t.config)!=null&&r.version&&(this.version=t.config.version),this.directClient=E(x({baseUrl:`https://swish.app/api/${this.version}`})),this.proxyClient=E(x({baseUrl:Oe})),t.authToken&&(this.authToken=t.authToken),t.config&&this.setConfig(t.config),t.requestInterceptor&&(this.proxyClient.interceptors.request.use(t.requestInterceptor),this.directClient.interceptors.request.use(t.requestInterceptor)),t.responseInterceptor&&(this.proxyClient.interceptors.response.use(t.responseInterceptor),this.directClient.interceptors.response.use(t.responseInterceptor)),this.proxyClient.interceptors.request.use(this.proxyRequestInterceptor.bind(this)),this.directClient.interceptors.request.use(this.directRequestInterceptor.bind(this))}setProfile(t){this.profile=t}getProfile(){return this.profile}setAuthToken(t){this.authToken=t}setConfig({proxyBaseUrl:t=Oe,baseUrl:r,useProxy:n=!1,...o}){this.useProxy=n,this.proxyClient.setConfig({...o,baseUrl:t}),this.directClient.setConfig({...o})}proxyRequestInterceptor(t){return this.profile&&(t.headers.set("Profile",this.profile),t.headers.set("Swish-Api-Version",this.version)),t}directRequestInterceptor(t){return this.authToken&&t.headers.set("Authorization",`Bearer ${this.authToken}`),t}};s(H,"SwishClient");var N=H;export{Et as createApiClient,Fe as defaultApiVersion,Oe as defaultProxyBaseUrl};
|
package/dist/types.d.ts
CHANGED
|
@@ -5,11 +5,16 @@ export type { SwishClient };
|
|
|
5
5
|
export interface SwishClientOptions {
|
|
6
6
|
authToken?: string;
|
|
7
7
|
profile?: string;
|
|
8
|
+
proxyMode?: boolean;
|
|
8
9
|
config?: SwishClientConfig;
|
|
9
10
|
requestInterceptor?: Parameters<Client["interceptors"]["request"]["use"]>[0];
|
|
10
11
|
responseInterceptor?: Parameters<Client["interceptors"]["response"]["use"]>[0];
|
|
11
12
|
}
|
|
12
|
-
export type SwishClientConfig = Config<ClientOptions
|
|
13
|
+
export type SwishClientConfig = Config<ClientOptions> & {
|
|
14
|
+
proxyBaseUrl?: string;
|
|
15
|
+
useProxy?: boolean;
|
|
16
|
+
version?: string;
|
|
17
|
+
};
|
|
13
18
|
export type ListItemsResponse = Awaited<ReturnType<SwishClient["items"]["list"]>>;
|
|
14
19
|
export type CreateItemResponse = Awaited<ReturnType<SwishClient["items"]["create"]>>;
|
|
15
20
|
export type DeleteItemsResponse = Awaited<ReturnType<SwishClient["items"]["delete"]>>;
|