@swishapp/api-client 0.13.4 → 0.15.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/README.md CHANGED
@@ -11,9 +11,9 @@ npm install @swishapp/api-client
11
11
  ## Usage
12
12
 
13
13
  ```ts
14
- import { SwishClient } from "@swishapp/api-client";
14
+ import { createApiClient } from "@swishapp/api-client";
15
15
 
16
- const swish = createClient({
16
+ const swish = createApiClient({
17
17
  authToken: "swish-api-token",
18
18
  profile: "gid://shopify/Customer/12345",
19
19
  });
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { SwishClientConfig, SwishClientOptions, ApiError } from "./types";
1
+ import type { SwishClientConfig, SwishClientOptions, ApiResponse } from "./types";
2
2
  import type * as types from "./openapi/types.gen";
3
3
  export declare const createApiClient: (options: SwishClientOptions) => SwishClient;
4
4
  export type { SwishClient };
@@ -12,115 +12,26 @@ declare class SwishClient {
12
12
  setConfig(config: SwishClientConfig): void;
13
13
  requestInterceptor(request: Request): Request;
14
14
  readonly items: {
15
- list: (query?: types.ItemControllerFindData["query"]) => Promise<{
16
- data: null;
17
- error: ApiError;
18
- } | {
19
- data: types.Item[];
20
- error: null;
21
- }>;
22
- create: (items: types.CreateItemInput) => Promise<{
23
- data: null;
24
- error: ApiError;
25
- } | {
26
- data: types.Item;
27
- error: null;
28
- }>;
29
- delete: (itemIds: types.DeleteItemsInput["itemIds"]) => Promise<{
30
- data: null;
31
- error: ApiError;
32
- } | {
33
- data: unknown;
34
- error: null;
35
- }>;
36
- findById: (itemId: string) => Promise<{
37
- data: null;
38
- error: ApiError;
39
- } | {
40
- data: types.ItemDetail;
41
- error: null;
42
- }>;
43
- updateById: (itemId: string, body: types.UpdateItemInput) => Promise<{
44
- data: null;
45
- error: ApiError;
46
- } | {
47
- data: types.Item;
48
- error: null;
49
- }>;
50
- deleteById: (itemId: string) => Promise<{
51
- data: null;
52
- error: ApiError;
53
- } | {
54
- data: unknown;
55
- error: null;
56
- }>;
15
+ list: (query?: types.ItemControllerFindData["query"]) => Promise<ApiResponse<types.Item[]>>;
16
+ create: (items: types.CreateItemInput) => Promise<ApiResponse<types.Item>>;
17
+ delete: (itemIds: types.DeleteItemsInput["itemIds"]) => Promise<ApiResponse<unknown>>;
18
+ findById: (itemId: string) => Promise<ApiResponse<types.ItemDetail>>;
19
+ updateById: (itemId: string, body: types.UpdateItemInput) => Promise<ApiResponse<types.Item>>;
20
+ deleteById: (itemId: string) => Promise<ApiResponse<unknown>>;
21
+ setListsById: (itemId: string, listIds: types.SetItemListsInput["listIds"]) => Promise<ApiResponse<unknown>>;
57
22
  };
58
23
  readonly lists: {
59
- list: (query?: types.ListControllerFindData["query"]) => Promise<{
60
- data: null;
61
- error: ApiError;
62
- } | {
63
- data: types.List[];
64
- error: null;
65
- }>;
66
- create: (list: types.CreateListInput) => Promise<{
67
- data: null;
68
- error: ApiError;
69
- } | {
70
- data: types.List;
71
- error: null;
72
- }>;
73
- findById: (listId: string, query?: types.ListControllerFindByIdData["query"]) => Promise<{
74
- data: null;
75
- error: ApiError;
76
- } | {
77
- data: types.ListDetail;
78
- error: null;
79
- }>;
80
- updateById: (listId: string, body: types.UpdateListInput) => Promise<{
81
- data: null;
82
- error: ApiError;
83
- } | {
84
- data: types.List;
85
- error: null;
86
- }>;
87
- deleteById: (listId: string) => Promise<{
88
- data: null;
89
- error: ApiError;
90
- } | {
91
- data: unknown;
92
- error: null;
93
- }>;
94
- orderItems: (listId: string, itemIds: types.SetListItemsOrderInput["itemIds"]) => Promise<{
95
- data: null;
96
- error: ApiError;
97
- } | {
98
- data: types.List;
99
- error: null;
100
- }>;
24
+ list: (query?: types.ListControllerFindData["query"]) => Promise<ApiResponse<types.List[]>>;
25
+ create: (list: types.CreateListInput) => Promise<ApiResponse<types.List>>;
26
+ findById: (listId: string, query?: types.ListControllerFindByIdData["query"]) => Promise<ApiResponse<types.ListDetail>>;
27
+ updateById: (listId: string, body: types.UpdateListInput) => Promise<ApiResponse<types.List>>;
28
+ deleteById: (listId: string) => Promise<ApiResponse<unknown>>;
29
+ orderItems: (listId: string, itemIds: types.SetListItemsOrderInput["itemIds"]) => Promise<ApiResponse<types.List>>;
101
30
  };
102
31
  readonly profiles: {
103
- customerAccountsVersion: () => Promise<{
104
- data: null;
105
- error: ApiError;
106
- } | {
107
- data: types.AccountsVersionResult;
108
- error: null;
109
- }>;
110
- createToken: (body?: types.CreateProfileTokenInput) => Promise<{
111
- data: null;
112
- error: ApiError;
113
- } | {
114
- data: types.CreateProfileTokenResult;
115
- error: null;
116
- }>;
117
- identify: (body: types.IdentifyProfileInput) => Promise<{
118
- data: null;
119
- error: ApiError;
120
- } | {
121
- data: types.IdentifyProfileResult;
122
- error: null;
123
- }>;
32
+ customerAccountsVersion: () => Promise<ApiResponse<types.AccountsVersionResult>>;
33
+ createToken: (body?: types.CreateProfileTokenInput) => Promise<ApiResponse<types.CreateProfileTokenResult>>;
34
+ identify: (body: types.IdentifyProfileInput) => Promise<ApiResponse<types.IdentifyProfileResult>>;
124
35
  };
125
36
  private readonly handleRequest;
126
37
  }
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var Q=Object.defineProperty;var o=(e,r)=>Q(e,"name",{value:r,configurable:!0});var K=o(async(e,r)=>{let t=typeof r=="function"?await r(e):r;if(t)return e.scheme==="bearer"?`Bearer ${t}`:e.scheme==="basic"?`Basic ${btoa(t)}`:t},"A");var M={bodySerializer:o(e=>JSON.stringify(e,(r,t)=>typeof t=="bigint"?t.toString():t),"bodySerializer")};var X=o(e=>{switch(e){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},"U"),Y=o(e=>{switch(e){case"form":return",";case"pipeDelimited":return"|";case"spaceDelimited":return"%20";default:return","}},"_"),Z=o(e=>{switch(e){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},"D"),g=o(({allowReserved:e,explode:r,name:t,style:s,value:i})=>{if(!r){let l=(e?i:i.map(d=>encodeURIComponent(d))).join(Y(s));switch(s){case"label":return`.${l}`;case"matrix":return`;${t}=${l}`;case"simple":return l;default:return`${t}=${l}`}}let a=X(s),n=i.map(l=>s==="label"||s==="simple"?e?l:encodeURIComponent(l):w({allowReserved:e,name:t,value:l})).join(a);return s==="label"||s==="matrix"?a+n:n},"O"),w=o(({allowReserved:e,name:r,value:t})=>{if(t==null)return"";if(typeof t=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return`${r}=${e?t:encodeURIComponent(t)}`},"y"),L=o(({allowReserved:e,explode:r,name:t,style:s,value:i})=>{if(i instanceof Date)return`${t}=${i.toISOString()}`;if(s!=="deepObject"&&!r){let l=[];Object.entries(i).forEach(([f,h])=>{l=[...l,f,e?h:encodeURIComponent(h)]});let d=l.join(",");switch(s){case"form":return`${t}=${d}`;case"label":return`.${d}`;case"matrix":return`;${t}=${d}`;default:return d}}let a=Z(s),n=Object.entries(i).map(([l,d])=>w({allowReserved:e,name:s==="deepObject"?`${t}[${l}]`:l,value:d})).join(a);return s==="label"||s==="matrix"?a+n:n},"q"),ee=/\{[^{}]+\}/g,re=o(({path:e,url:r})=>{let t=r,s=r.match(ee);if(s)for(let i of s){let a=!1,n=i.substring(1,i.length-1),l="simple";n.endsWith("*")&&(a=!0,n=n.substring(0,n.length-1)),n.startsWith(".")?(n=n.substring(1),l="label"):n.startsWith(";")&&(n=n.substring(1),l="matrix");let d=e[n];if(d==null)continue;if(Array.isArray(d)){t=t.replace(i,g({explode:a,name:n,style:l,value:d}));continue}if(typeof d=="object"){t=t.replace(i,L({explode:a,name:n,style:l,value:d}));continue}if(l==="matrix"){t=t.replace(i,`;${w({name:n,value:d})}`);continue}let f=encodeURIComponent(l==="label"?`.${d}`:d);t=t.replace(i,f)}return t},"B"),S=o(({allowReserved:e,array:r,object:t}={})=>s=>{let i=[];if(s&&typeof s=="object")for(let a in s){let n=s[a];if(n!=null){if(Array.isArray(n)){i=[...i,g({allowReserved:e,explode:!0,name:a,style:"form",value:n,...r})];continue}if(typeof n=="object"){i=[...i,L({allowReserved:e,explode:!0,name:a,style:"deepObject",value:n,...t})];continue}i=[...i,w({allowReserved:e,name:a,value:n})]}}return i.join("&")},"E"),te=o(e=>{var t;if(!e)return"stream";let r=(t=e.split(";")[0])==null?void 0:t.trim();if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return"json";if(r==="multipart/form-data")return"formData";if(["application/","audio/","image/","video/"].some(s=>r.startsWith(s)))return"blob";if(r.startsWith("text/"))return"text"}},"P"),oe=o(async({security:e,...r})=>{for(let t of e){let s=await K(t,r.auth);if(!s)continue;let i=t.name??"Authorization";switch(t.in){case"query":r.query||(r.query={}),r.query[i]=s;break;case"header":default:r.headers.set(i,s);break}return}},"I"),B=o(e=>ne({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:S(e.querySerializer),url:e.url}),"S"),ne=o(({baseUrl:e,path:r,query:t,querySerializer:s,url:i})=>{let a=i.startsWith("/")?i:`/${i}`,n=(e??"")+a;r&&(n=re({path:r,url:n}));let l=t?s(t):"";return l.startsWith("?")&&(l=l.substring(1)),l&&(n+=`?${l}`),n},"W"),R=o((e,r)=>{var s;let t={...e,...r};return(s=t.baseUrl)!=null&&s.endsWith("/")&&(t.baseUrl=t.baseUrl.substring(0,t.baseUrl.length-1)),t.headers=q(e.headers,r.headers),t},"C"),q=o((...e)=>{let r=new Headers;for(let t of e){if(!t||typeof t!="object")continue;let s=t instanceof Headers?t.entries():Object.entries(t);for(let[i,a]of s)if(a===null)r.delete(i);else if(Array.isArray(a))for(let n of a)r.append(i,n);else a!==void 0&&r.set(i,typeof a=="object"?JSON.stringify(a):a)}return r},"x"),C,b=(C=class{_fns;constructor(){this._fns=[]}clear(){this._fns=[]}exists(r){return this._fns.indexOf(r)!==-1}eject(r){let t=this._fns.indexOf(r);t!==-1&&(this._fns=[...this._fns.slice(0,t),...this._fns.slice(t+1)])}use(r){this._fns=[...this._fns,r]}},o(C,"m"),C),le=o(()=>({error:new b,request:new b,response:new b}),"T"),se=S({allowReserved:!1,array:{explode:!0,style:"form"},object:{explode:!0,style:"deepObject"}}),ie={"Content-Type":"application/json"},m=o((e={})=>({...M,headers:ie,parseAs:"auto",querySerializer:se,...e}),"w"),E=o((e={})=>{let r=R(m(),e),t=o(()=>({...r}),"e"),s=o(n=>(r=R(r,n),t()),"a"),i=le(),a=o(async n=>{let l={...r,...n,fetch:n.fetch??r.fetch??globalThis.fetch,headers:q(r.headers,n.headers)};l.security&&await oe({...l,security:l.security}),l.body&&l.bodySerializer&&(l.body=l.bodySerializer(l.body)),(l.body===void 0||l.body==="")&&l.headers.delete("Content-Type");let d=B(l),f={redirect:"follow",...l},h=new Request(d,f);for(let c of i.request._fns)h=await c(h,l);let G=l.fetch,u=await G(h);for(let c of i.response._fns)u=await c(u,h,l);let I={request:h,response:u};if(u.ok){if(u.status===204||u.headers.get("Content-Length")==="0")return{data:{},...I};let c=(l.parseAs==="auto"?te(u.headers.get("Content-Type")):l.parseAs)??"json";if(c==="stream")return{data:u.body,...I};let T=await u[c]();return c==="json"&&(l.responseValidator&&await l.responseValidator(T),l.responseTransformer&&(T=await l.responseTransformer(T))),{data:T,...I}}let O=await u.text();try{O=JSON.parse(O)}catch{}let y=O;for(let c of i.error._fns)y=await c(O,u,h,l);if(y=y||{},l.throwOnError)throw y;return{error:y,...I}},"o");return{buildUrl:B,connect:o(n=>a({...n,method:"CONNECT"}),"connect"),delete:o(n=>a({...n,method:"DELETE"}),"delete"),get:o(n=>a({...n,method:"GET"}),"get"),getConfig:t,head:o(n=>a({...n,method:"HEAD"}),"head"),interceptors:i,options:o(n=>a({...n,method:"OPTIONS"}),"options"),patch:o(n=>a({...n,method:"PATCH"}),"patch"),post:o(n=>a({...n,method:"POST"}),"post"),put:o(n=>a({...n,method:"PUT"}),"put"),request:a,setConfig:s,trace:o(n=>a({...n,method:"TRACE"}),"trace")}},"J");var p=E(m({baseUrl:"https://swish.app/api/2025-04"}));var k=o(e=>((e==null?void 0:e.client)??p).get({url:"/lists",...e}),"listControllerFind"),j=o(e=>(e.client??p).post({url:"/lists",...e,headers:{"Content-Type":"application/json",...e==null?void 0:e.headers}}),"listControllerCreate"),F=o(e=>(e.client??p).delete({url:"/lists/{listId}",...e}),"listControllerDeleteById"),U=o(e=>(e.client??p).get({url:"/lists/{listId}",...e}),"listControllerFindById"),v=o(e=>(e.client??p).patch({url:"/lists/{listId}",...e,headers:{"Content-Type":"application/json",...e==null?void 0:e.headers}}),"listControllerUpdateById"),A=o(e=>(e.client??p).put({url:"/lists/{listId}/items/order",...e,headers:{"Content-Type":"application/json",...e==null?void 0:e.headers}}),"listControllerSetListItemsOrder"),P=o(e=>(e.client??p).delete({url:"/items",...e,headers:{"Content-Type":"application/json",...e==null?void 0:e.headers}}),"itemControllerDelete"),$=o(e=>((e==null?void 0:e.client)??p).get({url:"/items",...e}),"itemControllerFind"),z=o(e=>(e.client??p).post({url:"/items",...e,headers:{"Content-Type":"application/json",...e==null?void 0:e.headers}}),"itemControllerCreate"),_=o(e=>(e.client??p).delete({url:"/items/{itemId}",...e}),"itemControllerDeleteById"),V=o(e=>(e.client??p).get({url:"/items/{itemId}",...e}),"itemControllerFindById"),W=o(e=>(e.client??p).patch({url:"/items/{itemId}",...e,headers:{"Content-Type":"application/json",...e==null?void 0:e.headers}}),"itemControllerUpdateById");var N=o(e=>((e==null?void 0:e.client)??p).get({url:"/profiles/accounts-version",...e}),"profileControllerCustomerAccountsVersion"),J=o(e=>(e.client??p).post({url:"/profiles/identify",...e,headers:{"Content-Type":"application/json",...e==null?void 0:e.headers}}),"profileControllerIdentify"),H=o(e=>(e.client??p).post({url:"/profiles/token",...e,headers:{"Content-Type":"application/json",...e==null?void 0:e.headers}}),"profileControllerCreateToken");var Te=o(e=>new D(e),"createApiClient"),x=class x{constructor(r){this.client=E(m({baseUrl:"https://swish.app/api/2025-04"}));this.items={list:o(r=>this.handleRequest($({query:r,client:this.client})),"list"),create:o(r=>this.handleRequest(z({body:r,client:this.client})),"create"),delete:o(r=>this.handleRequest(P({body:{itemIds:r},client:this.client})),"delete"),findById:o(r=>this.handleRequest(V({path:{itemId:r},client:this.client})),"findById"),updateById:o((r,t)=>this.handleRequest(W({body:t,path:{itemId:r},client:this.client})),"updateById"),deleteById:o(r=>this.handleRequest(_({path:{itemId:r},client:this.client})),"deleteById")};this.lists={list:o(r=>this.handleRequest(k({query:r,client:this.client})),"list"),create:o(r=>this.handleRequest(j({body:r,client:this.client})),"create"),findById:o((r,t)=>this.handleRequest(U({path:{listId:r},query:t??{sort:"recently_saved"},client:this.client})),"findById"),updateById:o((r,t)=>this.handleRequest(v({body:t,path:{listId:r},client:this.client})),"updateById"),deleteById:o(r=>this.handleRequest(F({path:{listId:r},client:this.client})),"deleteById"),orderItems:o((r,t)=>this.handleRequest(A({body:{itemIds:t},path:{listId:r},client:this.client})),"orderItems")};this.profiles={customerAccountsVersion:o(()=>this.handleRequest(N({client:this.client})),"customerAccountsVersion"),createToken:o((r={})=>this.handleRequest(H({body:r,client:this.client})),"createToken"),identify:o(r=>this.handleRequest(J({body:r,client:this.client})),"identify")};this.handleRequest=o(async r=>{let{data:t,error:s}=await r;return s!=null&&s.error?{data:null,error:s==null?void 0:s.error}:t!=null&&t.data?{data:t.data,error:null}:{data:null,error:null}},"handleRequest");this.profile=r.profile,r.authToken&&(this.authToken=r.authToken),r.config&&this.client.setConfig(r.config),this.client.interceptors.request.use(this.requestInterceptor.bind(this)),r.requestInterceptor&&this.client.interceptors.request.use(r.requestInterceptor),r.responseInterceptor&&this.client.interceptors.response.use(r.responseInterceptor)}setProfile(r){this.profile=r}setAuthToken(r){this.authToken=r}setConfig(r){this.client.setConfig(r)}requestInterceptor(r){return this.authToken&&r.headers.set("Authorization",`Bearer ${this.authToken}`),this.profile&&r.headers.set("Profile",this.profile),r}};o(x,"SwishClient");var D=x;export{Te as createApiClient};
1
+ var K=Object.defineProperty;var o=(e,r)=>K(e,"name",{value:r,configurable:!0});var M=o(async(e,r)=>{let t=typeof r=="function"?await r(e):r;if(t)return e.scheme==="bearer"?`Bearer ${t}`:e.scheme==="basic"?`Basic ${btoa(t)}`:t},"A");var X={bodySerializer:o(e=>JSON.stringify(e,(r,t)=>typeof t=="bigint"?t.toString():t),"bodySerializer")};var Y=o(e=>{switch(e){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},"U"),Z=o(e=>{switch(e){case"form":return",";case"pipeDelimited":return"|";case"spaceDelimited":return"%20";default:return","}},"_"),ee=o(e=>{switch(e){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},"D"),g=o(({allowReserved:e,explode:r,name:t,style:s,value:a})=>{if(!r){let l=(e?a:a.map(d=>encodeURIComponent(d))).join(Z(s));switch(s){case"label":return`.${l}`;case"matrix":return`;${t}=${l}`;case"simple":return l;default:return`${t}=${l}`}}let i=Y(s),n=a.map(l=>s==="label"||s==="simple"?e?l:encodeURIComponent(l):E({allowReserved:e,name:t,value:l})).join(i);return s==="label"||s==="matrix"?i+n:n},"O"),E=o(({allowReserved:e,name:r,value:t})=>{if(t==null)return"";if(typeof t=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return`${r}=${e?t:encodeURIComponent(t)}`},"y"),B=o(({allowReserved:e,explode:r,name:t,style:s,value:a})=>{if(a instanceof Date)return`${t}=${a.toISOString()}`;if(s!=="deepObject"&&!r){let l=[];Object.entries(a).forEach(([y,u])=>{l=[...l,y,e?u:encodeURIComponent(u)]});let d=l.join(",");switch(s){case"form":return`${t}=${d}`;case"label":return`.${d}`;case"matrix":return`;${t}=${d}`;default:return d}}let i=ee(s),n=Object.entries(a).map(([l,d])=>E({allowReserved:e,name:s==="deepObject"?`${t}[${l}]`:l,value:d})).join(i);return s==="label"||s==="matrix"?i+n:n},"q"),re=/\{[^{}]+\}/g,te=o(({path:e,url:r})=>{let t=r,s=r.match(re);if(s)for(let a of s){let i=!1,n=a.substring(1,a.length-1),l="simple";n.endsWith("*")&&(i=!0,n=n.substring(0,n.length-1)),n.startsWith(".")?(n=n.substring(1),l="label"):n.startsWith(";")&&(n=n.substring(1),l="matrix");let d=e[n];if(d==null)continue;if(Array.isArray(d)){t=t.replace(a,g({explode:i,name:n,style:l,value:d}));continue}if(typeof d=="object"){t=t.replace(a,B({explode:i,name:n,style:l,value:d}));continue}if(l==="matrix"){t=t.replace(a,`;${E({name:n,value:d})}`);continue}let y=encodeURIComponent(l==="label"?`.${d}`:d);t=t.replace(a,y)}return t},"B"),S=o(({allowReserved:e,array:r,object:t}={})=>s=>{let a=[];if(s&&typeof s=="object")for(let i in s){let n=s[i];if(n!=null){if(Array.isArray(n)){a=[...a,g({allowReserved:e,explode:!0,name:i,style:"form",value:n,...r})];continue}if(typeof n=="object"){a=[...a,B({allowReserved:e,explode:!0,name:i,style:"deepObject",value:n,...t})];continue}a=[...a,E({allowReserved:e,name:i,value:n})]}}return a.join("&")},"E"),oe=o(e=>{var t;if(!e)return"stream";let r=(t=e.split(";")[0])==null?void 0:t.trim();if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return"json";if(r==="multipart/form-data")return"formData";if(["application/","audio/","image/","video/"].some(s=>r.startsWith(s)))return"blob";if(r.startsWith("text/"))return"text"}},"P"),ne=o(async({security:e,...r})=>{for(let t of e){let s=await M(t,r.auth);if(!s)continue;let a=t.name??"Authorization";switch(t.in){case"query":r.query||(r.query={}),r.query[a]=s;break;case"header":default:r.headers.set(a,s);break}return}},"I"),R=o(e=>le({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:S(e.querySerializer),url:e.url}),"S"),le=o(({baseUrl:e,path:r,query:t,querySerializer:s,url:a})=>{let i=a.startsWith("/")?a:`/${a}`,n=(e??"")+i;r&&(n=te({path:r,url:n}));let l=t?s(t):"";return l.startsWith("?")&&(l=l.substring(1)),l&&(n+=`?${l}`),n},"W"),x=o((e,r)=>{var s;let t={...e,...r};return(s=t.baseUrl)!=null&&s.endsWith("/")&&(t.baseUrl=t.baseUrl.substring(0,t.baseUrl.length-1)),t.headers=A(e.headers,r.headers),t},"C"),A=o((...e)=>{let r=new Headers;for(let t of e){if(!t||typeof t!="object")continue;let s=t instanceof Headers?t.entries():Object.entries(t);for(let[a,i]of s)if(i===null)r.delete(a);else if(Array.isArray(i))for(let n of i)r.append(a,n);else i!==void 0&&r.set(a,typeof i=="object"?JSON.stringify(i):i)}return r},"x"),C,b=(C=class{_fns;constructor(){this._fns=[]}clear(){this._fns=[]}exists(r){return this._fns.indexOf(r)!==-1}eject(r){let t=this._fns.indexOf(r);t!==-1&&(this._fns=[...this._fns.slice(0,t),...this._fns.slice(t+1)])}use(r){this._fns=[...this._fns,r]}},o(C,"m"),C),se=o(()=>({error:new b,request:new b,response:new b}),"T"),ae=S({allowReserved:!1,array:{explode:!0,style:"form"},object:{explode:!0,style:"deepObject"}}),ie={"Content-Type":"application/json"},m=o((e={})=>({...X,headers:ie,parseAs:"auto",querySerializer:ae,...e}),"w"),T=o((e={})=>{let r=x(m(),e),t=o(()=>({...r}),"e"),s=o(n=>(r=x(r,n),t()),"a"),a=se(),i=o(async n=>{let l={...r,...n,fetch:n.fetch??r.fetch??globalThis.fetch,headers:A(r.headers,n.headers)};l.security&&await ne({...l,security:l.security}),l.body&&l.bodySerializer&&(l.body=l.bodySerializer(l.body)),(l.body===void 0||l.body==="")&&l.headers.delete("Content-Type");let d=R(l),y={redirect:"follow",...l},u=new Request(d,y);for(let h of a.request._fns)u=await h(u,l);let Q=l.fetch,c=await Q(u);for(let h of a.response._fns)c=await h(c,u,l);let I={request:u,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return{data:{},...I};let h=(l.parseAs==="auto"?oe(c.headers.get("Content-Type")):l.parseAs)??"json";if(h==="stream")return{data:c.body,...I};let w=await c[h]();return h==="json"&&(l.responseValidator&&await l.responseValidator(w),l.responseTransformer&&(w=await l.responseTransformer(w))),{data:w,...I}}let O=await c.text();try{O=JSON.parse(O)}catch{}let f=O;for(let h of a.error._fns)f=await h(O,c,u,l);if(f=f||{},l.throwOnError)throw f;return{error:f,...I}},"o");return{buildUrl:R,connect:o(n=>i({...n,method:"CONNECT"}),"connect"),delete:o(n=>i({...n,method:"DELETE"}),"delete"),get:o(n=>i({...n,method:"GET"}),"get"),getConfig:t,head:o(n=>i({...n,method:"HEAD"}),"head"),interceptors:a,options:o(n=>i({...n,method:"OPTIONS"}),"options"),patch:o(n=>i({...n,method:"PATCH"}),"patch"),post:o(n=>i({...n,method:"POST"}),"post"),put:o(n=>i({...n,method:"PUT"}),"put"),request:i,setConfig:s,trace:o(n=>i({...n,method:"TRACE"}),"trace")}},"J");var p=T(m({baseUrl:"https://swish.app/api/2025-04"}));var q=o(e=>((e==null?void 0:e.client)??p).get({url:"/lists",...e}),"listControllerFind"),k=o(e=>(e.client??p).post({url:"/lists",...e,headers:{"Content-Type":"application/json",...e==null?void 0:e.headers}}),"listControllerCreate"),v=o(e=>(e.client??p).delete({url:"/lists/{listId}",...e}),"listControllerDeleteById"),j=o(e=>(e.client??p).get({url:"/lists/{listId}",...e}),"listControllerFindById"),F=o(e=>(e.client??p).patch({url:"/lists/{listId}",...e,headers:{"Content-Type":"application/json",...e==null?void 0:e.headers}}),"listControllerUpdateById"),U=o(e=>(e.client??p).put({url:"/lists/{listId}/items/order",...e,headers:{"Content-Type":"application/json",...e==null?void 0:e.headers}}),"listControllerSetListItemsOrder"),P=o(e=>(e.client??p).delete({url:"/items",...e,headers:{"Content-Type":"application/json",...e==null?void 0:e.headers}}),"itemControllerDelete"),$=o(e=>((e==null?void 0:e.client)??p).get({url:"/items",...e}),"itemControllerFind"),z=o(e=>(e.client??p).post({url:"/items",...e,headers:{"Content-Type":"application/json",...e==null?void 0:e.headers}}),"itemControllerCreate"),N=o(e=>(e.client??p).delete({url:"/items/{itemId}",...e}),"itemControllerDeleteById"),_=o(e=>(e.client??p).get({url:"/items/{itemId}",...e}),"itemControllerFindById"),V=o(e=>(e.client??p).patch({url:"/items/{itemId}",...e,headers:{"Content-Type":"application/json",...e==null?void 0:e.headers}}),"itemControllerUpdateById"),W=o(e=>(e.client??p).put({url:"/items/{itemId}/lists",...e,headers:{"Content-Type":"application/json",...e==null?void 0:e.headers}}),"itemControllerSetListsById"),J=o(e=>((e==null?void 0:e.client)??p).get({url:"/profiles/accounts-version",...e}),"profileControllerCustomerAccountsVersion"),H=o(e=>(e.client??p).post({url:"/profiles/identify",...e,headers:{"Content-Type":"application/json",...e==null?void 0:e.headers}}),"profileControllerIdentify"),G=o(e=>(e.client??p).post({url:"/profiles/token",...e,headers:{"Content-Type":"application/json",...e==null?void 0:e.headers}}),"profileControllerCreateToken");var Ee=o(e=>new D(e),"createApiClient"),L=class L{constructor(r){this.client=T(m({baseUrl:"https://swish.app/api/2025-04"}));this.items={list:o(r=>this.handleRequest($({query:r,client:this.client})),"list"),create:o(r=>this.handleRequest(z({body:r,client:this.client})),"create"),delete:o(r=>this.handleRequest(P({body:{itemIds:r},client:this.client})),"delete"),findById:o(r=>this.handleRequest(_({path:{itemId:r},client:this.client})),"findById"),updateById:o((r,t)=>this.handleRequest(V({body:t,path:{itemId:r},client:this.client})),"updateById"),deleteById:o(r=>this.handleRequest(N({path:{itemId:r},client:this.client})),"deleteById"),setListsById:o((r,t)=>this.handleRequest(W({body:{listIds:t},path:{itemId:r},client:this.client})),"setListsById")};this.lists={list:o(r=>this.handleRequest(q({query:r,client:this.client})),"list"),create:o(r=>this.handleRequest(k({body:r,client:this.client})),"create"),findById:o((r,t)=>this.handleRequest(j({path:{listId:r},query:t??{sort:"recently_saved"},client:this.client})),"findById"),updateById:o((r,t)=>this.handleRequest(F({body:t,path:{listId:r},client:this.client})),"updateById"),deleteById:o(r=>this.handleRequest(v({path:{listId:r},client:this.client})),"deleteById"),orderItems:o((r,t)=>this.handleRequest(U({body:{itemIds:t},path:{listId:r},client:this.client})),"orderItems")};this.profiles={customerAccountsVersion:o(()=>this.handleRequest(J({client:this.client})),"customerAccountsVersion"),createToken:o((r={})=>this.handleRequest(G({body:r,client:this.client})),"createToken"),identify:o(r=>this.handleRequest(H({body:r,client:this.client})),"identify")};this.handleRequest=o(async r=>{let{data:t,error:s}=await r;if(s!=null&&s.error)return{data:null,error:s==null?void 0:s.error};if(t!=null&&t.data){let a={data:t.data,error:null};return t.pageInfo&&(a.pageInfo=t.pageInfo),a}return{data:null,error:null}},"handleRequest");this.profile=r.profile,r.authToken&&(this.authToken=r.authToken),r.config&&this.client.setConfig(r.config),this.client.interceptors.request.use(this.requestInterceptor.bind(this)),r.requestInterceptor&&this.client.interceptors.request.use(r.requestInterceptor),r.responseInterceptor&&this.client.interceptors.response.use(r.responseInterceptor)}setProfile(r){this.profile=r}setAuthToken(r){this.authToken=r}setConfig(r){this.client.setConfig(r)}requestInterceptor(r){return this.authToken&&r.headers.set("Authorization",`Bearer ${this.authToken}`),this.profile&&r.headers.set("Profile",this.profile),r}};o(L,"SwishClient");var D=L;export{Ee as createApiClient};
@@ -1,5 +1,5 @@
1
1
  import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch';
2
- import type { ListControllerFindData, ListControllerFindError, ListControllerCreateData, ListControllerCreateError, ListControllerDeleteByIdData, ListControllerDeleteByIdError, ListControllerFindByIdData, ListControllerFindByIdError, ListControllerUpdateByIdData, ListControllerUpdateByIdError, ListControllerSetListItemsOrderData, ListControllerSetListItemsOrderError, ItemControllerDeleteData, ItemControllerDeleteError, ItemControllerFindData, ItemControllerFindError, ItemControllerCreateData, ItemControllerCreateError, ItemControllerDeleteByIdData, ItemControllerDeleteByIdError, ItemControllerFindByIdData, ItemControllerFindByIdError, ItemControllerUpdateByIdData, ItemControllerUpdateByIdError, ItemControllerSetListsByIdData, ItemControllerSetListsByIdError, ProfileControllerCustomerAccountsVersionData, ProfileControllerCustomerAccountsVersionError, ProfileControllerIdentifyData, ProfileControllerIdentifyError, ProfileControllerCreateTokenData, ProfileControllerCreateTokenError } from './types.gen';
2
+ import type { ListControllerFindData, ListControllerFindError, ListControllerCreateData, ListControllerCreateError, ListControllerDeleteByIdData, ListControllerDeleteByIdError, ListControllerFindByIdData, ListControllerFindByIdError, ListControllerUpdateByIdData, ListControllerUpdateByIdError, ListControllerSetListItemsOrderData, ListControllerSetListItemsOrderError, ItemControllerDeleteData, ItemControllerDeleteError, ItemControllerFindData, ItemControllerFindError, ItemControllerCreateData, ItemControllerCreateError, ItemControllerDeleteByIdData, ItemControllerDeleteByIdError, ItemControllerFindByIdData, ItemControllerFindByIdError, ItemControllerUpdateByIdData, ItemControllerUpdateByIdError, ItemControllerSetListsByIdData, ItemControllerSetListsByIdError, ProfileControllerCustomerAccountsVersionData, ProfileControllerCustomerAccountsVersionError, ProfileControllerIdentifyData, ProfileControllerIdentifyError, ProfileControllerCreateTokenData, ProfileControllerCreateTokenError, AnalyticsControllerLoadSavedItemsData, AnalyticsControllerLoadSavedItemsError, AnalyticsControllerLoadSessionsData, AnalyticsControllerLoadSessionsError, AnalyticsControllerLoadNewListsData, AnalyticsControllerLoadNewListsError } from './types.gen';
3
3
  export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & {
4
4
  /**
5
5
  * You can provide a client instance returned by `createClient()` instead of
@@ -53,3 +53,12 @@ export declare const profileControllerIdentify: <ThrowOnError extends boolean =
53
53
  export declare const profileControllerCreateToken: <ThrowOnError extends boolean = false>(options: Options<ProfileControllerCreateTokenData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen").Response & {
54
54
  data?: import("./types.gen").CreateProfileTokenResult;
55
55
  }, ProfileControllerCreateTokenError, ThrowOnError>;
56
+ export declare const analyticsControllerLoadSavedItems: <ThrowOnError extends boolean = false>(options: Options<AnalyticsControllerLoadSavedItemsData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen").Response & {
57
+ data?: Array<import("./types.gen").Analytics>;
58
+ }, AnalyticsControllerLoadSavedItemsError, ThrowOnError>;
59
+ export declare const analyticsControllerLoadSessions: <ThrowOnError extends boolean = false>(options: Options<AnalyticsControllerLoadSessionsData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen").Response & {
60
+ data?: Array<import("./types.gen").Analytics>;
61
+ }, AnalyticsControllerLoadSessionsError, ThrowOnError>;
62
+ export declare const analyticsControllerLoadNewLists: <ThrowOnError extends boolean = false>(options: Options<AnalyticsControllerLoadNewListsData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen").Response & {
63
+ data?: Array<import("./types.gen").Analytics>;
64
+ }, AnalyticsControllerLoadNewListsError, ThrowOnError>;
@@ -235,6 +235,16 @@ export type CreateProfileTokenInput = {
235
235
  */
236
236
  session?: string;
237
237
  };
238
+ export type Analytics = {
239
+ /**
240
+ * The timeframe for this data point (e.g., "2024-01-01 - 2024-01-10")
241
+ */
242
+ timeframe: string;
243
+ /**
244
+ * Total number of events for this timeframe
245
+ */
246
+ total: number;
247
+ };
238
248
  export type ListControllerFindData = {
239
249
  body?: never;
240
250
  path?: never;
@@ -408,11 +418,11 @@ export type ListControllerFindByIdData = {
408
418
  */
409
419
  listId: string;
410
420
  };
411
- query: {
421
+ query?: {
412
422
  /**
413
423
  * The sort order of the items in the list
414
424
  */
415
- sort: 'recently_saved' | 'custom';
425
+ sort?: 'recently_saved' | 'custom';
416
426
  };
417
427
  url: '/lists/{listId}';
418
428
  };
@@ -1148,6 +1158,219 @@ export type ProfileControllerCreateTokenResponses = {
1148
1158
  };
1149
1159
  };
1150
1160
  export type ProfileControllerCreateTokenResponse = ProfileControllerCreateTokenResponses[keyof ProfileControllerCreateTokenResponses];
1161
+ export type AnalyticsControllerLoadSavedItemsData = {
1162
+ body?: never;
1163
+ path?: never;
1164
+ query: {
1165
+ /**
1166
+ * The granularity of the data
1167
+ */
1168
+ granularity?: string;
1169
+ /**
1170
+ * The start date
1171
+ */
1172
+ start: string;
1173
+ /**
1174
+ * The end date
1175
+ */
1176
+ end: string;
1177
+ /**
1178
+ * Filter by product or variant ID
1179
+ */
1180
+ merchandiseId?: string;
1181
+ };
1182
+ url: '/analytics/saved-items';
1183
+ };
1184
+ export type AnalyticsControllerLoadSavedItemsErrors = {
1185
+ /**
1186
+ * Bad Request
1187
+ */
1188
+ 400: ErrorResponse & {
1189
+ error?: {
1190
+ statusCode?: number;
1191
+ error?: string;
1192
+ };
1193
+ };
1194
+ /**
1195
+ * Unauthorized
1196
+ */
1197
+ 401: ErrorResponse & {
1198
+ error?: {
1199
+ statusCode?: number;
1200
+ error?: string;
1201
+ };
1202
+ };
1203
+ /**
1204
+ * Forbidden
1205
+ */
1206
+ 403: ErrorResponse & {
1207
+ error?: {
1208
+ statusCode?: number;
1209
+ error?: string;
1210
+ };
1211
+ };
1212
+ /**
1213
+ * Not Found
1214
+ */
1215
+ 404: ErrorResponse & {
1216
+ error?: {
1217
+ statusCode?: number;
1218
+ error?: string;
1219
+ };
1220
+ };
1221
+ };
1222
+ export type AnalyticsControllerLoadSavedItemsError = AnalyticsControllerLoadSavedItemsErrors[keyof AnalyticsControllerLoadSavedItemsErrors];
1223
+ export type AnalyticsControllerLoadSavedItemsResponses = {
1224
+ /**
1225
+ * Returns saved items analytics
1226
+ */
1227
+ 200: Response & {
1228
+ data?: Array<Analytics>;
1229
+ };
1230
+ };
1231
+ export type AnalyticsControllerLoadSavedItemsResponse = AnalyticsControllerLoadSavedItemsResponses[keyof AnalyticsControllerLoadSavedItemsResponses];
1232
+ export type AnalyticsControllerLoadSessionsData = {
1233
+ body?: never;
1234
+ path?: never;
1235
+ query: {
1236
+ /**
1237
+ * The granularity of the data
1238
+ */
1239
+ granularity?: string;
1240
+ /**
1241
+ * The start date
1242
+ */
1243
+ start: string;
1244
+ /**
1245
+ * The end date
1246
+ */
1247
+ end: string;
1248
+ /**
1249
+ * Filter by product or variant ID
1250
+ */
1251
+ merchandiseId?: string;
1252
+ };
1253
+ url: '/analytics/sessions';
1254
+ };
1255
+ export type AnalyticsControllerLoadSessionsErrors = {
1256
+ /**
1257
+ * Bad Request
1258
+ */
1259
+ 400: ErrorResponse & {
1260
+ error?: {
1261
+ statusCode?: number;
1262
+ error?: string;
1263
+ };
1264
+ };
1265
+ /**
1266
+ * Unauthorized
1267
+ */
1268
+ 401: ErrorResponse & {
1269
+ error?: {
1270
+ statusCode?: number;
1271
+ error?: string;
1272
+ };
1273
+ };
1274
+ /**
1275
+ * Forbidden
1276
+ */
1277
+ 403: ErrorResponse & {
1278
+ error?: {
1279
+ statusCode?: number;
1280
+ error?: string;
1281
+ };
1282
+ };
1283
+ /**
1284
+ * Not Found
1285
+ */
1286
+ 404: ErrorResponse & {
1287
+ error?: {
1288
+ statusCode?: number;
1289
+ error?: string;
1290
+ };
1291
+ };
1292
+ };
1293
+ export type AnalyticsControllerLoadSessionsError = AnalyticsControllerLoadSessionsErrors[keyof AnalyticsControllerLoadSessionsErrors];
1294
+ export type AnalyticsControllerLoadSessionsResponses = {
1295
+ /**
1296
+ * Returns sessions analytics
1297
+ */
1298
+ 200: Response & {
1299
+ data?: Array<Analytics>;
1300
+ };
1301
+ };
1302
+ export type AnalyticsControllerLoadSessionsResponse = AnalyticsControllerLoadSessionsResponses[keyof AnalyticsControllerLoadSessionsResponses];
1303
+ export type AnalyticsControllerLoadNewListsData = {
1304
+ body?: never;
1305
+ path?: never;
1306
+ query: {
1307
+ /**
1308
+ * The granularity of the data
1309
+ */
1310
+ granularity?: string;
1311
+ /**
1312
+ * The start date
1313
+ */
1314
+ start: string;
1315
+ /**
1316
+ * The end date
1317
+ */
1318
+ end: string;
1319
+ /**
1320
+ * Filter by product or variant ID
1321
+ */
1322
+ merchandiseId?: string;
1323
+ };
1324
+ url: '/analytics/new-lists';
1325
+ };
1326
+ export type AnalyticsControllerLoadNewListsErrors = {
1327
+ /**
1328
+ * Bad Request
1329
+ */
1330
+ 400: ErrorResponse & {
1331
+ error?: {
1332
+ statusCode?: number;
1333
+ error?: string;
1334
+ };
1335
+ };
1336
+ /**
1337
+ * Unauthorized
1338
+ */
1339
+ 401: ErrorResponse & {
1340
+ error?: {
1341
+ statusCode?: number;
1342
+ error?: string;
1343
+ };
1344
+ };
1345
+ /**
1346
+ * Forbidden
1347
+ */
1348
+ 403: ErrorResponse & {
1349
+ error?: {
1350
+ statusCode?: number;
1351
+ error?: string;
1352
+ };
1353
+ };
1354
+ /**
1355
+ * Not Found
1356
+ */
1357
+ 404: ErrorResponse & {
1358
+ error?: {
1359
+ statusCode?: number;
1360
+ error?: string;
1361
+ };
1362
+ };
1363
+ };
1364
+ export type AnalyticsControllerLoadNewListsError = AnalyticsControllerLoadNewListsErrors[keyof AnalyticsControllerLoadNewListsErrors];
1365
+ export type AnalyticsControllerLoadNewListsResponses = {
1366
+ /**
1367
+ * Returns new lists analytics
1368
+ */
1369
+ 200: Response & {
1370
+ data?: Array<Analytics>;
1371
+ };
1372
+ };
1373
+ export type AnalyticsControllerLoadNewListsResponse = AnalyticsControllerLoadNewListsResponses[keyof AnalyticsControllerLoadNewListsResponses];
1151
1374
  export type ClientOptions = {
1152
1375
  baseUrl: 'https://swish.app/api/2025-04' | (string & {});
1153
1376
  };
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { ClientOptions, Config } from "@hey-api/client-fetch";
2
2
  import type { SwishClient } from "./client";
3
+ import { PageInfo } from "./openapi/types.gen";
3
4
  export type { SwishClient };
4
5
  export interface SwishClientOptions {
5
6
  authToken?: string;
@@ -21,6 +22,7 @@ export type CreateListResponse = Awaited<ReturnType<SwishClient["lists"]["create
21
22
  export type DeleteListByIdResponse = Awaited<ReturnType<SwishClient["lists"]["deleteById"]>>;
22
23
  export type UpdateListByIdResponse = Awaited<ReturnType<SwishClient["lists"]["updateById"]>>;
23
24
  export type OrderItemsResponse = Awaited<ReturnType<SwishClient["lists"]["orderItems"]>>;
25
+ export type SetListsByIdResponse = Awaited<ReturnType<SwishClient["items"]["setListsById"]>>;
24
26
  export type CustomerAccountsVersionResponse = Awaited<ReturnType<SwishClient["profiles"]["customerAccountsVersion"]>>;
25
27
  export type CreateProfileTokenResponse = Awaited<ReturnType<SwishClient["profiles"]["createToken"]>>;
26
28
  export type IdentifyProfileResponse = Awaited<ReturnType<SwishClient["profiles"]["identify"]>>;
@@ -30,3 +32,17 @@ export interface ApiError {
30
32
  requestId: string;
31
33
  statusCode: number;
32
34
  }
35
+ export type ApiResponse<TData> = {
36
+ data: TData | null;
37
+ error: ApiError | null;
38
+ pageInfo?: PageInfo;
39
+ };
40
+ export type ApiRequestResponse<TData> = Promise<{
41
+ data?: {
42
+ data?: TData;
43
+ pageInfo?: PageInfo;
44
+ } | void;
45
+ error?: {
46
+ error: unknown;
47
+ };
48
+ }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swishapp/api-client",
3
- "version": "0.13.4",
3
+ "version": "0.15.0",
4
4
  "description": "A lightweight JS client for the Swish REST API.",
5
5
  "homepage": "https://developers.swish.app/libraries/api-client",
6
6
  "type": "module",