@commercetools/ts-client
Advanced tools
Comparing version 3.0.2 to 3.0.3
# @commercetools/ts-client | ||
## 3.0.3 | ||
### Patch Changes | ||
- [#920](https://github.com/commercetools/commercetools-sdk-typescript/pull/920) [`9e7987d`](https://github.com/commercetools/commercetools-sdk-typescript/commit/9e7987dc70ece91ce372acdc41864ada789cec16) Thanks [@ajimae](https://github.com/ajimae)! - Remove the `Accept-Encoding` http header entry | ||
## 3.0.2 | ||
@@ -4,0 +10,0 @@ |
@@ -177,5 +177,3 @@ 'use strict'; | ||
headers: { | ||
...rest.headers, | ||
// axios header encoding | ||
'Accept-Encoding': 'application/json' | ||
...rest.headers | ||
}, | ||
@@ -1277,3 +1275,3 @@ // for axios | ||
name: "@commercetools/ts-client", | ||
version: "3.0.2", | ||
version: "3.0.3", | ||
engines: { | ||
@@ -1280,0 +1278,0 @@ node: ">=18" |
@@ -173,5 +173,3 @@ function _toPrimitive(t, r) { | ||
headers: { | ||
...rest.headers, | ||
// axios header encoding | ||
'Accept-Encoding': 'application/json' | ||
...rest.headers | ||
}, | ||
@@ -1273,3 +1271,3 @@ // for axios | ||
name: "@commercetools/ts-client", | ||
version: "3.0.2", | ||
version: "3.0.3", | ||
engines: { | ||
@@ -1276,0 +1274,0 @@ node: ">=18" |
@@ -177,5 +177,3 @@ 'use strict'; | ||
headers: { | ||
...rest.headers, | ||
// axios header encoding | ||
'Accept-Encoding': 'application/json' | ||
...rest.headers | ||
}, | ||
@@ -1277,3 +1275,3 @@ // for axios | ||
name: "@commercetools/ts-client", | ||
version: "3.0.2", | ||
version: "3.0.3", | ||
engines: { | ||
@@ -1280,0 +1278,0 @@ node: ">=18" |
@@ -177,5 +177,3 @@ 'use strict'; | ||
headers: { | ||
...rest.headers, | ||
// axios header encoding | ||
'Accept-Encoding': 'application/json' | ||
...rest.headers | ||
}, | ||
@@ -1277,3 +1275,3 @@ // for axios | ||
name: "@commercetools/ts-client", | ||
version: "3.0.2", | ||
version: "3.0.3", | ||
engines: { | ||
@@ -1280,0 +1278,0 @@ node: ">=18" |
@@ -173,5 +173,3 @@ function _toPrimitive(t, r) { | ||
headers: { | ||
...rest.headers, | ||
// axios header encoding | ||
'Accept-Encoding': 'application/json' | ||
...rest.headers | ||
}, | ||
@@ -1273,3 +1271,3 @@ // for axios | ||
name: "@commercetools/ts-client", | ||
version: "3.0.2", | ||
version: "3.0.3", | ||
engines: { | ||
@@ -1276,0 +1274,0 @@ node: ">=18" |
@@ -1,1 +0,1 @@ | ||
var window;(window||={})["@commercetools/ts-client"]=(()=>{var ue=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var Ie=Object.getOwnPropertyNames;var je=Object.prototype.hasOwnProperty;var ce=(e,t)=>{for(var r in t)ue(e,r,{get:t[r],enumerable:!0})},Ne=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ie(t))!je.call(e,i)&&i!==r&&ue(e,i,{get:()=>t[i],enumerable:!(o=Fe(t,i))||o.enumerable});return e};var Ue=e=>Ne(ue({},"__esModule",{value:!0}),e);var ft={};ce(ft,{ClientBuilder:()=>L,Process:()=>de,createAuthMiddlewareForAnonymousSessionFlow:()=>H,createAuthMiddlewareForClientCredentialsFlow:()=>v,createAuthMiddlewareForExistingTokenFlow:()=>_,createAuthMiddlewareForPasswordFlow:()=>K,createAuthMiddlewareForRefreshTokenFlow:()=>B,createClient:()=>S,createConcurrentModificationMiddleware:()=>Q,createCorrelationIdMiddleware:()=>J,createHttpMiddleware:()=>V,createLoggerMiddleware:()=>G,createQueueMiddleware:()=>Y,createUserAgentMiddleware:()=>W});var Re={};ce(Re,{createAuthMiddlewareForAnonymousSessionFlow:()=>H,createAuthMiddlewareForClientCredentialsFlow:()=>v,createAuthMiddlewareForExistingTokenFlow:()=>_,createAuthMiddlewareForPasswordFlow:()=>K,createAuthMiddlewareForRefreshTokenFlow:()=>B,createConcurrentModificationMiddleware:()=>Q,createCorrelationIdMiddleware:()=>J,createErrorMiddleware:()=>Ce,createHttpMiddleware:()=>V,createLoggerMiddleware:()=>G,createQueueMiddleware:()=>Y,createUserAgentMiddleware:()=>W});function N(e){return e&&typeof e=="string"?e.normalize("NFD").length.toString():e&&e instanceof Uint8Array?new TextDecoder().decode(e).length.toString():e&&typeof e=="object"?new TextEncoder().encode(JSON.stringify(e)).length.toString():"0"}var C={};ce(C,{CONCURRENCT_REQUEST:()=>He,CTP_API_URL:()=>ve,CTP_AUTH_URL:()=>_e,DEFAULT_HEADERS:()=>he,HEADERS_CONTENT_TYPES:()=>qe});var qe=["application/json","application/graphql"],He=20,ve="https://api.europe-west1.gcp.commercetools.com",_e="https://auth.europe-west1.gcp.commercetools.com",he=["content-type","access-control-allow-origin","access-control-allow-headers","access-control-allow-methods","access-control-expose-headers","access-control-max-ag","x-correlation-id","server-timing","date","server","transfer-encoding","access-control-max-age","content-encoding","x-envoy-upstream-service-time","via","alt-svc","connection"];function x(e,t,r={}){this.status=this.statusCode=this.code=e,this.message=t,Object.assign(this,r),this.name=this.constructor.name,this.constructor.prototype.__proto__=Error.prototype,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}function Ae(...e){x.call(this,0,...e)}function be(...e){x.call(this,...e)}function Ke(...e){x.call(this,400,...e)}function Be(...e){x.call(this,401,...e)}function Le(...e){x.call(this,403,...e)}function De(...e){x.call(this,404,...e)}function $e(...e){x.call(this,409,...e)}function ze(...e){x.call(this,500,...e)}function Qe(...e){x.call(this,503,...e)}function pe(e){switch(e){case 0:return Ae;case 400:return Ke;case 401:return Be;case 403:return Le;case 404:return De;case 409:return $e;case 500:return ze;case 503:return Qe;default:return}}function Je({statusCode:e,message:t,...r}){let o=t||"Unexpected non-JSON error response";e===404&&(o=`URI not found: ${r.originalRequest?.uri||r.uri}`);let i=pe(e);return i?new i(o,r):new be(e,o,r)}var U=Je;function Ve(e,t){return[503,...e].includes(t?.status||t?.statusCode)}async function Ge(e,t){async function r(){return await e({...t,headers:{...t.headers}})}return r().catch(o=>Promise.reject(o))}async function q(e){let{url:t,httpClient:r,...o}=e;return await Ge(async n=>{let{enableRetry:a,retryConfig:s,timeout:u,getAbortController:l}=o,{retryCodes:d=[],maxDelay:p=1/0,maxRetries:g=3,backoff:R=!0,retryDelay:c=200,retryOnAbort:F=!0}=s||{},w,f,m=0,I;we(d);async function O(){return r(t,{...n,...o,headers:{...o.headers,"Accept-Encoding":"application/json"},...o.body?{data:o.body}:{},withCredentials:n.credentialsMode==="include"})}function X(){let M=(l?l():null)||new AbortController;return o.abortController=M,o.signal=M.signal,M}async function j(){let M=async(ee,Se)=>{let $={};if(u){let E=X();I=setTimeout(()=>{E.abort(),E=X()},u)}try{if($=await O(),$.status>399&&Ve(ee,$))return{_response:$,shouldRetry:!0}}catch(E){if((E.name.includes("AbortError")||E.name.includes("TimeoutError"))&&Se)return{_response:E,shouldRetry:!0};throw E}finally{clearTimeout(I)}return{_response:$,shouldRetry:!1}},{_response:D,shouldRetry:Z}=await M(d,F);for(;a&&Z&&m<g;){m++,await re(te({retryCount:m,retryDelay:c,maxRetries:g,backoff:R,maxDelay:p}));let ee=await M(d,F);D=ee._response,Z=ee.shouldRetry}return D}let y=await j();try{y.text&&typeof y.text=="function"?(w=await y.text()||JSON.stringify(y[Object.getOwnPropertySymbols(y)[1]]),f=JSON.parse(w)):f=y.data||y}catch(M){throw M}return{data:f,retryCount:m,statusCode:y.status||y.statusCode||f.statusCode,headers:y.headers}},{validateStatus:n=>!0})}function oe(){return("1000000-1000-4000-8000"+-1e11).replace(/[018]/g,e=>(parseInt(e)^Math.floor(Math.random()*256)&15>>parseInt(e)/4).toString(16))}function Ye(e){return he.reduce((t,r)=>{let o=e[r]?e[r]:typeof e.get=="function"?e.get(r):null;return o&&(t[r]=o),t},{})}function A(e){if(!e)return null;if(e.raw&&typeof e.raw=="function")return e.raw();if(!e.forEach)return Ye(e);let t={};return e.forEach((r,o)=>t[o]=r),t}function z(e){return e!=null&&e.constructor!=null&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e)}function P(e){let t=JSON.parse(JSON.stringify(e));return t?.headers&&(t.headers.Authorization&&(t.headers.Authorization="Bearer ********"),t.headers.authorization&&(t.headers.authorization="Bearer ********")),t}function h(e,t){return{...t,headers:{...t.headers,Authorization:`Bearer ${e}`}}}var fe=["ACL","BIND","CHECKOUT","CONNECT","COPY","DELETE","GET","HEAD","LINK","LOCK","M-SEARCH","MERGE","MKACTIVITY","MKCALENDAR","MKCOL","MOVE","NOTIFY","OPTIONS","PATCH","POST","PROPFIND","PROPPATCH","PURGE","PUT","REBIND","REPORT","SEARCH","SOURCE","SUBSCRIBE","TRACE","UNBIND","UNLINK","UNLOCK","UNSUBSCRIBE"];function te({retryCount:e,retryDelay:t,backoff:r,maxDelay:o}){return r&&e!==0?Math.min(Math.round((Math.random()+1)*t*2**e),o):t}Math.min(Math.round((Math.random()+1)*200*2**10),1/0);function re(e){return new Promise(t=>{setTimeout(t,e)})}function b(e){if(!e?.credentials?.clientId||!e.projectKey||!e.host)throw new Error("Missing required options.");return{clientId:e.credentials.clientId,host:e.host,projectKey:e.projectKey}}function ie(e){return Date.now()+e*1e3-5*60*1e3}function T(e){let t=e;return{get:r=>t,set:(r,o)=>{t=r}}}function Te(e){return typeof e<"u"&&e!==null}function We(e){return Te(e)?typeof e=="string"?e:Object.fromEntries(Object.entries(e).filter(([t,r])=>![null,void 0,""].includes(r))):""}function Xe(e){let t={},r=new URLSearchParams(e);for(let o of r.keys())r.getAll(o).length>1?t[o]=r.getAll(o):t[o]=r.get(o);return t}function Ze(e){if(e=We(e),!e)return"";let t=new URLSearchParams(e);for(let[r,o]of Object.entries(e))Array.isArray(o)&&(t.delete(r),o.filter(Te).forEach(i=>t.append(r,i)));return t.toString()}function me(e,t=Xe){return t(e)}function ne(e,t=Ze){return t(e)}var et=()=>typeof window<"u"&&window.document&&window.document.nodeType===9;function tt(){if(et())return window.navigator.userAgent;let e=process?.version.slice(1)||"unknow",t=`(${process.platform}; ${process.arch})`;return`node.js/${e} ${t}`}function ae(e){let t=null,r=null;if(!e)throw new Error("Missing required option `name`");let o=e.version?`${e.name}/${e.version}`:e.name;e.libraryName&&!e.libraryVersion?t=e.libraryName:e.libraryName&&e.libraryVersion&&(t=`${e.libraryName}/${e.libraryVersion}`),e.contactUrl&&!e.contactEmail?r=`(+${e.contactUrl})`:!e.contactUrl&&e.contactEmail?r=`(+${e.contactEmail})`:e.contactUrl&&e.contactEmail&&(r=`(+${e.contactUrl}; +${e.contactEmail})`);let i=tt(),n=e.customAgent||"";return[o,i,t,r,n].filter(Boolean).join(" ")}function ye(e){if(!e.host)throw new Error("Request `host` or `url` is missing or invalid, please pass in a valid host e.g `host: http://a-valid-host-url`");if(!e.httpClient&&typeof e.httpClient!="function")throw new Error("An `httpClient` is not available, please pass in a `fetch` or `axios` instance as an option or have them globally available.");if(e.httpClientOptions&&Object.prototype.toString.call(e.httpClientOptions)!=="[object Object]")throw new Error("`httpClientOptions` must be an object type")}function we(e){if(!Array.isArray(e))throw new Error("`retryCodes` option must be an array of retry status (error) codes and/or messages.")}function Me(e){if(!e)throw new Error("Missing required options");if(e.middlewares&&!Array.isArray(e.middlewares))throw new Error("Middlewares should be an array");if(!e.middlewares||!Array.isArray(e.middlewares)||!e.middlewares.length)throw new Error("You need to provide at least one middleware")}function se(e,t,r={allowedMethods:fe}){if(!t)throw new Error(`The "${e}" function requires a "Request" object as an argument. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest`);if(typeof t.uri!="string")throw new Error(`The "${e}" Request object requires a valid uri. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest`);if(!r.allowedMethods.includes(t.method))throw new Error(`The "${e}" Request object requires a valid method. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest`)}function ge(e){if(!e)throw new Error("Missing required options");if(!e.host)throw new Error("Missing required option (host)");if(!e.projectKey)throw new Error("Missing required option (projectKey)");if(!e.credentials)throw new Error("Missing required option (credentials)");let{clientId:t,clientSecret:r}=e.credentials||{};if(!(t&&r))throw new Error("Missing required credentials (clientId, clientSecret)");let o=e.scopes?e.scopes.join(" "):void 0,i=btoa(`${t}:${r}`),n=e.oauthUri||"/oauth/token",a=e.host.replace(/\/$/,"")+n,s=`grant_type=client_credentials${o?`&scope=${o}`:""}`;return{url:a,body:s,basicAuth:i}}function xe(e){if(!e)throw new Error("Missing required options");if(!e.projectKey)throw new Error("Missing required option (projectKey)");let t=e.projectKey;e.oauthUri=e.oauthUri||`/oauth/${t}/anonymous/token`;let r=ge(e);return e.credentials.anonymousId&&(r.body+=`&anonymous_id=${e.credentials.anonymousId}`),{...r}}function le(e){if(!e)throw new Error("Missing required options");if(!e.host)throw new Error("Missing required option (host)");if(!e.projectKey)throw new Error("Missing required option (projectKey)");if(!e.credentials)throw new Error("Missing required option (credentials)");if(!e.refreshToken)throw new Error("Missing required option (refreshToken)");let{clientId:t,clientSecret:r}=e.credentials;if(!(t&&r))throw new Error("Missing required credentials (clientId, clientSecret)");let o=btoa(`${t}:${r}`),i=e.oauthUri||"/oauth/token",n=e.host.replace(/\/$/,"")+i,a=`grant_type=refresh_token&refresh_token=${encodeURIComponent(e.refreshToken)}`;return{basicAuth:o,url:n,body:a}}function Oe(e){if(!e)throw new Error("Missing required options");if(!e.host)throw new Error("Missing required option (host)");if(!e.projectKey)throw new Error("Missing required option (projectKey)");if(!e.credentials)throw new Error("Missing required option (credentials)");let{clientId:t,clientSecret:r,user:o}=e.credentials,i=e.projectKey;if(!(t&&r&&o))throw new Error("Missing required credentials (clientId, clientSecret, user)");let{username:n,password:a}=o;if(!(n&&a))throw new Error("Missing required user credentials (username, password)");let s=(e.scopes||[]).join(" "),u=s?`&scope=${s}`:"",l=btoa(`${t}:${r}`),d=e.oauthUri||`/oauth/${i}/customers/token`,p=e.host.replace(/\/$/,"")+d,g=`grant_type=password&username=${encodeURIComponent(n)}&password=${encodeURIComponent(a)}${u}`;return{basicAuth:l,url:p,body:g}}async function k(e){let{httpClient:t,httpClientOptions:r,tokenCache:o,userOption:i,tokenCacheObject:n}=e,a=e.url,s=e.body,u=e.basicAuth;if(!t||typeof t!="function")throw new Error("an `httpClient` is not available, please pass in a `fetch` or `axios` instance as an option or have them globally available.");if(n&&n.refreshToken&&(!n.token||n.token&&Date.now()>n.expirationTime)){if(!i)throw new Error("Missing required options.");let d={...le({...i,refreshToken:n.refreshToken})};a=d.url,s=d.body,u=d.basicAuth}let l;try{if(l=await q({url:a,method:"POST",headers:{Authorization:`Basic ${u}`,"Content-Type":"application/x-www-form-urlencoded","Content-Length":N(s)},httpClient:t,httpClientOptions:r,body:s}),l.statusCode>=200&&l.statusCode<300){let{access_token:d,expires_in:p,refresh_token:g}=l?.data,R=ie(p);return o.set({token:d,expirationTime:R,refreshToken:g}),Promise.resolve(!0)}throw U({code:l.data.error,statusCode:l.data.statusCode,message:l.data.message,error:l.data.errors})}catch(d){throw d}}function H(e){let t=e.tokenCache||T({token:"",expirationTime:-1}),r,o=null,i=b(e);return n=>async a=>{if(a.headers&&(a.headers.Authorization||a.headers.authorization))return n(a);if(r=t.get(i),r&&r.token&&Date.now()<r.expirationTime)return n(h(r.token,a));let s={request:a,tokenCache:t,tokenCacheKey:i,httpClient:e.httpClient||fetch,httpClientOptions:e.httpClientOptions,...xe(e),userOption:e,next:n};return o?await o:(o=k(s),await o,o=null),r=t.get(i),n(h(r.token,a))}}function v(e){let t=e.tokenCache||T({token:"",expirationTime:-1}),r,o=null,i=b(e);return n=>async a=>{if(a.headers&&(a.headers.Authorization||a.headers.authorization))return n(a);if(r=t.get(i),r&&r.token&&Date.now()<r.expirationTime)return n(h(r.token,a));let s={request:a,tokenCache:t,tokenCacheKey:i,tokenCacheObject:r,httpClient:e.httpClient||fetch,httpClientOptions:e.httpClientOptions,...ge(e),next:n};return o?await o:(o=k(s),await o,o=null),r=t.get(i),n(h(r.token,a))}}function _(e,t){return r=>async o=>{if(typeof e!="string")throw new Error("authorization must be a string");let i=t?.force===void 0?!0:t.force;if(!e||o.headers&&(o.headers.Authorization||o.headers.authorization)&&i===!1)return r(o);let n={...o,headers:{...o.headers,Authorization:e}};return r(n)}}function K(e){let t=e.tokenCache||T({token:"",expirationTime:-1}),r,o=null,i=b(e);return n=>async a=>{if(a.headers&&(a.headers.Authorization||a.headers.authorization))return n(a);if(r=t.get(i),r&&r.token&&Date.now()<r.expirationTime)return n(h(r.token,a));let s={request:a,tokenCache:t,tokenCacheKey:i,httpClient:e.httpClient||fetch,httpClientOptions:e.httpClientOptions,...Oe(e),userOption:e,next:n};return o?await o:(o=k(s),await o,o=null),r=t.get(i),n(h(r.token,a))}}function B(e){let t=e.tokenCache||T({token:"",tokenCacheKey:null}),r,o=null,i=b(e);return n=>async a=>{if(a.headers&&(a.headers.Authorization||a.headers.authorization))return n(a);if(r=t.get(i),r&&r.token&&Date.now()<r.expirationTime)return n(h(r.token,a));let s={request:a,tokenCache:t,httpClient:e.httpClient||fetch,httpClientOptions:e.httpClientOptions,...le(e),next:n};return o?await o:(o=k(s),await o,o=null),r=t.get(i),n(h(r.token,a))}}function Q(e){return t=>async r=>{let o=await t(r);if(o.statusCode==409){let i=o.error.body?.errors?.[0]?.currentVersion;if(i)return e&&typeof e=="function"?r.body=await e(i,r,o):r.body=typeof r.body=="string"?{...JSON.parse(r.body),version:i}:{...r.body,version:i},t(r)}return o}}function J(e){return t=>r=>{let o={...r,headers:{...r.headers,"X-Correlation-ID":e.generate&&typeof e.generate=="function"?e.generate():oe()}};return t(o)}}function Ce(e){return t=>async r=>{let o=await t(r);if(o.error){let{error:i}=o;return{...o,statusCode:i.statusCode||0,headers:i.headers||A({}),error:{...i,body:i.data||i}}}return o}}async function rt({url:e,httpClient:t,clientOptions:r}){let{request:o,maskSensitiveHeaderData:i,includeRequestInErrorResponse:n,includeResponseHeaders:a}=r;try{let s=await q({url:e,...r,httpClient:t,method:r.method,...r.body?{body:r.body}:{}});if(a||(s.headers=null),s.statusCode>=200&&s.statusCode<300)return r.method=="HEAD"?{body:null,statusCode:s.statusCode,retryCount:s.retryCount,headers:A(s.headers)}:{body:s.data,statusCode:s.statusCode,retryCount:s.retryCount,headers:A(s.headers)};let u=U({message:s?.data?.message||s?.message,statusCode:s.statusCode||s?.data?.statusCode,headers:A(s.headers),method:r.method,body:s.data,retryCount:s.retryCount,...n?{originalRequest:i?P(o):o}:{uri:o.uri}});return{body:s.data,code:s.statusCode,statusCode:s.statusCode,headers:A(s.headers),error:u}}catch(s){let u=a?A(s.response?.headers):null,l=s.response?.status||s.response?.data0||0,d=s.response?.data?.message;throw{body:null,error:U({statusCode:l,code:l,status:l,message:d||s.message,headers:u,body:s.response?.data||s,error:s.response?.data,...n?{originalRequest:i?P(o):o}:{uri:o.uri}})}}}function V(e){ye(e);let{host:t,credentialsMode:r,httpClient:o,timeout:i,enableRetry:n,retryConfig:a,getAbortController:s,includeOriginalRequest:u,includeRequestInErrorResponse:l=!0,includeResponseHeaders:d=!0,maskSensitiveHeaderData:p,httpClientOptions:g}=e;return R=>async c=>{let F=t.replace(/\/$/,"")+c.uri,w={...c.headers};Object.prototype.hasOwnProperty.call(w,"Content-Type")||Object.prototype.hasOwnProperty.call(w,"content-type")||(w["Content-Type"]="application/json"),w["Content-Type"]===null&&delete w["Content-Type"];let f=C.HEADERS_CONTENT_TYPES.indexOf(w["Content-Type"])>-1&&typeof c.body=="string"||z(c.body)?c.body:JSON.stringify(c.body||void 0);f&&(typeof f=="string"||z(f))&&(w["Content-Length"]=N(f));let m={enableRetry:n,retryConfig:a,request:c,method:c.method,headers:w,includeRequestInErrorResponse:l,maskSensitiveHeaderData:p,includeResponseHeaders:d,...g};r&&(m.credentialsMode=r),i&&(m.timeout=i,m.getAbortController=s),f&&(m.body=f);let I=await rt({url:F,clientOptions:m,httpClient:o}),O={...c,includeOriginalRequest:u,maskSensitiveHeaderData:p,response:I};return R(O)}}function G(e){return t=>async r=>{let o=await t(r),i=Object.assign({},o),{loggerFn:n=console.log}=e||{};return n&&typeof n=="function"&&n(o),i}}function Y({concurrency:e=20}){let t=0,r=[],o=()=>0>=e?Promise.resolve():new Promise(n=>{let a=()=>{t<e?(t++,n()):r.push(a)};a()}),i=()=>{if(t--,r.length>0){let n=r.shift();n&&n()}};return n=>a=>o().then(()=>{let s={...a,resolve(u){a.resolve(u),i()},reject(u){a.reject(u),i()}};return n(s).finally(()=>{i()})})}var ke={name:"@commercetools/ts-client",version:"3.0.2",engines:{node:">=18"},description:"commercetools Composable Commerce TypeScript SDK client.",keywords:["commercetools","composable commerce","sdk","typescript","client","middleware","http","oauth","auth"],homepage:"https://github.com/commercetools/commercetools-sdk-typescript",license:"MIT",directories:{lib:"lib",test:"test"},publishConfig:{access:"public"},repository:{type:"git",url:"git+https://github.com/commercetools/commercetools-sdk-typescript.git"},bugs:{url:"https://github.com/commercetools/commercetools-sdk-typescript/issues"},dependencies:{buffer:"^6.0.3"},files:["dist","CHANGELOG.md"],author:"Chukwuemeka Ajima <meeky.ae@gmail.com>",main:"dist/commercetools-ts-client.cjs.js",module:"dist/commercetools-ts-client.esm.js",browser:{"./dist/commercetools-ts-client.cjs.js":"./dist/commercetools-ts-client.browser.cjs.js","./dist/commercetools-ts-client.esm.js":"./dist/commercetools-ts-client.browser.esm.js"},devDependencies:{"common-tags":"1.8.2",dotenv:"16.4.7",jest:"29.7.0",nock:"^14.0.0-beta.19","organize-imports-cli":"0.10.0"},scripts:{organize_imports:"find src -type f -name '*.ts' | xargs organize-imports-cli",postbuild:"yarn organize_imports",post_process_generate:"yarn organize_imports",docs:"typedoc --out docs"}};function W(e){return t=>async r=>{let o=ae({...e,name:`${e.name?e.name+"/":""}commercetools-sdk-javascript-v3/${ke.version}`}),i={...r,headers:{...r.headers,"User-Agent":o}};return t(i)}}function it({middlewares:e}){return e.length===1?e[0]:e.slice().reduce((r,o)=>(...i)=>r(o.apply(null,i)))}var Ee;function de(e,t,r){if(se("process",e,{allowedMethods:["GET"]}),typeof t!="function")throw new Error('The "process" function accepts a "Function" as a second argument that returns a Promise. See https://commercetools.github.io/nodejs/sdk/api/sdkClient.html#processrequest-processfn-options');let o={total:Number.POSITIVE_INFINITY,accumulate:!0,...r};return new Promise((i,n)=>{let a,s="";if(e&&e.uri){let[R,c]=e.uri.split("?");a=R,s=c}let l={limit:20,...{...me(s)}},d=o.total,p=!1,g=async(R,c=[])=>{let F=l.limit<d?l.limit:d,w=ne({...l,limit:F}),f={sort:"id asc",withTotal:!1,...R?{where:`id > "${R}"`}:{}},m=ne(f),I={...e,uri:`${a}?${m}&${w}`};try{let O=await S(Ee).execute(I),{results:X,count:j}=O?.body||{};if(!j&&p)return i(c||[]);let y=await Promise.resolve(t(O)),M;if(p=!0,o.accumulate&&(M=c.concat(y||[])),d-=j,j<l.limit||!d)return i(M||[]);let D=X[j-1],Z=D&&D.id;g(Z,M)}catch(O){n(O)}};g()})}function S(e){Ee=e,Me(e);let t=!1,r={async resolve(i){let{response:n,includeOriginalRequest:a,maskSensitiveHeaderData:s,...u}=i,{retryCount:l,...d}=n;return t=s,{body:null,error:null,reject:i.reject,resolve:i.resolve,...d,...a?{originalRequest:u}:{},...n?.retryCount?{retryCount:n.retryCount}:{}}}},o=it(e)(r.resolve);return{process:de,execute(i){return se("exec",i),new Promise(async(n,a)=>{try{let s=await o({reject:a,resolve:n,...i});if(s.error)return a(s.error);s.originalRequest&&t&&(s.originalRequest=P(s.originalRequest)),n(s)}catch(s){a(s)}})}}}var{createAuthMiddlewareForPasswordFlow:nt,createAuthMiddlewareForAnonymousSessionFlow:at,createAuthMiddlewareForClientCredentialsFlow:st,createAuthMiddlewareForRefreshTokenFlow:lt,createAuthMiddlewareForExistingTokenFlow:dt,createCorrelationIdMiddleware:ut,createHttpMiddleware:ct,createLoggerMiddleware:ht,createQueueMiddleware:pt,createUserAgentMiddleware:Pe,createConcurrentModificationMiddleware:wt}=Re,L=class{projectKey;authMiddleware;httpMiddleware;userAgentMiddleware;correlationIdMiddleware;loggerMiddleware;queueMiddleware;concurrentMiddleware;telemetryMiddleware;beforeMiddleware;afterMiddleware;middlewares=[];constructor(){this.userAgentMiddleware=Pe({})}withProjectKey(t){return this.projectKey=t,this}defaultClient(t,r,o,i,n,a){return this.withClientCredentialsFlow({host:o,projectKey:i||this.projectKey,credentials:r,httpClient:a||fetch,scopes:n}).withHttpMiddleware({host:t,httpClient:a||fetch})}withAuthMiddleware(t){return this.authMiddleware=t,this}withMiddleware(t){return this.middlewares.push(t),this}withClientCredentialsFlow(t){return this.withAuthMiddleware(st({host:t.host||C.CTP_AUTH_URL,projectKey:t.projectKey||this.projectKey,credentials:{clientId:t.credentials.clientId||null,clientSecret:t.credentials.clientSecret||null},oauthUri:t.oauthUri||null,scopes:t.scopes,httpClient:t.httpClient||fetch,...t}))}withPasswordFlow(t){return this.withAuthMiddleware(nt({host:t.host||C.CTP_AUTH_URL,projectKey:t.projectKey||this.projectKey,credentials:{clientId:t.credentials.clientId||null,clientSecret:t.credentials.clientSecret||null,user:{username:t.credentials.user.username||null,password:t.credentials.user.password||null}},httpClient:t.httpClient||fetch,...t}))}withAnonymousSessionFlow(t){return this.withAuthMiddleware(at({host:t.host||C.CTP_AUTH_URL,projectKey:this.projectKey||t.projectKey,credentials:{clientId:t.credentials.clientId||null,clientSecret:t.credentials.clientSecret||null,anonymousId:t.credentials.anonymousId||null},httpClient:t.httpClient||fetch,...t}))}withRefreshTokenFlow(t){return this.withAuthMiddleware(lt({host:t.host||C.CTP_AUTH_URL,projectKey:this.projectKey||t.projectKey,credentials:{clientId:t.credentials.clientId||null,clientSecret:t.credentials.clientSecret||null},httpClient:t.httpClient||fetch,refreshToken:t.refreshToken||null,...t}))}withExistingTokenFlow(t,r){return this.withAuthMiddleware(dt(t,{force:r.force||!0,...r}))}withHttpMiddleware(t){return this.httpMiddleware=ct({host:t.host||C.CTP_API_URL,httpClient:t.httpClient||fetch,...t}),this}withUserAgentMiddleware(t){return this.userAgentMiddleware=Pe(t),this}withQueueMiddleware(t){return this.queueMiddleware=pt({concurrency:t.concurrency||C.CONCURRENCT_REQUEST,...t}),this}withLoggerMiddleware(t){return this.loggerMiddleware=ht(t),this}withCorrelationIdMiddleware(t){return this.correlationIdMiddleware=ut({generate:t?.generate,...t}),this}withConcurrentModificationMiddleware(t){return this.concurrentMiddleware=wt(t?.concurrentModificationHandlerFn),this}withTelemetryMiddleware(t){let{createTelemetryMiddleware:r,...o}=t;return this.withUserAgentMiddleware({customAgent:o?.userAgent||"typescript-sdk-apm-middleware"}),this.telemetryMiddleware=r(o),this}withBeforeExecutionMiddleware(t){let{middleware:r,...o}=t||{};return this.beforeMiddleware=t.middleware(o),this}withAfterExecutionMiddleware(t){let{middleware:r,...o}=t||{};return this.afterMiddleware=t.middleware(o),this}build(){let t=this.middlewares.slice();return this.telemetryMiddleware&&t.push(this.telemetryMiddleware),this.correlationIdMiddleware&&t.push(this.correlationIdMiddleware),this.userAgentMiddleware&&t.push(this.userAgentMiddleware),this.authMiddleware&&t.push(this.authMiddleware),this.beforeMiddleware&&t.push(this.beforeMiddleware),this.queueMiddleware&&t.push(this.queueMiddleware),this.loggerMiddleware&&t.push(this.loggerMiddleware),this.concurrentMiddleware&&t.push(this.concurrentMiddleware),this.httpMiddleware&&t.push(this.httpMiddleware),this.afterMiddleware&&t.push(this.afterMiddleware),S({middlewares:t})}};return Ue(ft);})(); | ||
var window;(window||={})["@commercetools/ts-client"]=(()=>{var ue=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var Ie=Object.getOwnPropertyNames;var je=Object.prototype.hasOwnProperty;var ce=(e,t)=>{for(var r in t)ue(e,r,{get:t[r],enumerable:!0})},Ne=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ie(t))!je.call(e,i)&&i!==r&&ue(e,i,{get:()=>t[i],enumerable:!(o=Fe(t,i))||o.enumerable});return e};var Ue=e=>Ne(ue({},"__esModule",{value:!0}),e);var ft={};ce(ft,{ClientBuilder:()=>L,Process:()=>de,createAuthMiddlewareForAnonymousSessionFlow:()=>H,createAuthMiddlewareForClientCredentialsFlow:()=>v,createAuthMiddlewareForExistingTokenFlow:()=>_,createAuthMiddlewareForPasswordFlow:()=>K,createAuthMiddlewareForRefreshTokenFlow:()=>B,createClient:()=>S,createConcurrentModificationMiddleware:()=>Q,createCorrelationIdMiddleware:()=>J,createHttpMiddleware:()=>V,createLoggerMiddleware:()=>G,createQueueMiddleware:()=>Y,createUserAgentMiddleware:()=>W});var Re={};ce(Re,{createAuthMiddlewareForAnonymousSessionFlow:()=>H,createAuthMiddlewareForClientCredentialsFlow:()=>v,createAuthMiddlewareForExistingTokenFlow:()=>_,createAuthMiddlewareForPasswordFlow:()=>K,createAuthMiddlewareForRefreshTokenFlow:()=>B,createConcurrentModificationMiddleware:()=>Q,createCorrelationIdMiddleware:()=>J,createErrorMiddleware:()=>Ce,createHttpMiddleware:()=>V,createLoggerMiddleware:()=>G,createQueueMiddleware:()=>Y,createUserAgentMiddleware:()=>W});function N(e){return e&&typeof e=="string"?e.normalize("NFD").length.toString():e&&e instanceof Uint8Array?new TextDecoder().decode(e).length.toString():e&&typeof e=="object"?new TextEncoder().encode(JSON.stringify(e)).length.toString():"0"}var C={};ce(C,{CONCURRENCT_REQUEST:()=>He,CTP_API_URL:()=>ve,CTP_AUTH_URL:()=>_e,DEFAULT_HEADERS:()=>he,HEADERS_CONTENT_TYPES:()=>qe});var qe=["application/json","application/graphql"],He=20,ve="https://api.europe-west1.gcp.commercetools.com",_e="https://auth.europe-west1.gcp.commercetools.com",he=["content-type","access-control-allow-origin","access-control-allow-headers","access-control-allow-methods","access-control-expose-headers","access-control-max-ag","x-correlation-id","server-timing","date","server","transfer-encoding","access-control-max-age","content-encoding","x-envoy-upstream-service-time","via","alt-svc","connection"];function x(e,t,r={}){this.status=this.statusCode=this.code=e,this.message=t,Object.assign(this,r),this.name=this.constructor.name,this.constructor.prototype.__proto__=Error.prototype,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}function be(...e){x.call(this,0,...e)}function Ae(...e){x.call(this,...e)}function Ke(...e){x.call(this,400,...e)}function Be(...e){x.call(this,401,...e)}function Le(...e){x.call(this,403,...e)}function De(...e){x.call(this,404,...e)}function $e(...e){x.call(this,409,...e)}function ze(...e){x.call(this,500,...e)}function Qe(...e){x.call(this,503,...e)}function pe(e){switch(e){case 0:return be;case 400:return Ke;case 401:return Be;case 403:return Le;case 404:return De;case 409:return $e;case 500:return ze;case 503:return Qe;default:return}}function Je({statusCode:e,message:t,...r}){let o=t||"Unexpected non-JSON error response";e===404&&(o=`URI not found: ${r.originalRequest?.uri||r.uri}`);let i=pe(e);return i?new i(o,r):new Ae(e,o,r)}var U=Je;function Ve(e,t){return[503,...e].includes(t?.status||t?.statusCode)}async function Ge(e,t){async function r(){return await e({...t,headers:{...t.headers}})}return r().catch(o=>Promise.reject(o))}async function q(e){let{url:t,httpClient:r,...o}=e;return await Ge(async n=>{let{enableRetry:a,retryConfig:s,timeout:u,getAbortController:l}=o,{retryCodes:d=[],maxDelay:p=1/0,maxRetries:g=3,backoff:R=!0,retryDelay:c=200,retryOnAbort:F=!0}=s||{},w,f,m=0,I;we(d);async function O(){return r(t,{...n,...o,headers:{...o.headers},...o.body?{data:o.body}:{},withCredentials:n.credentialsMode==="include"})}function X(){let M=(l?l():null)||new AbortController;return o.abortController=M,o.signal=M.signal,M}async function j(){let M=async(ee,Se)=>{let $={};if(u){let E=X();I=setTimeout(()=>{E.abort(),E=X()},u)}try{if($=await O(),$.status>399&&Ve(ee,$))return{_response:$,shouldRetry:!0}}catch(E){if((E.name.includes("AbortError")||E.name.includes("TimeoutError"))&&Se)return{_response:E,shouldRetry:!0};throw E}finally{clearTimeout(I)}return{_response:$,shouldRetry:!1}},{_response:D,shouldRetry:Z}=await M(d,F);for(;a&&Z&&m<g;){m++,await re(te({retryCount:m,retryDelay:c,maxRetries:g,backoff:R,maxDelay:p}));let ee=await M(d,F);D=ee._response,Z=ee.shouldRetry}return D}let y=await j();try{y.text&&typeof y.text=="function"?(w=await y.text()||JSON.stringify(y[Object.getOwnPropertySymbols(y)[1]]),f=JSON.parse(w)):f=y.data||y}catch(M){throw M}return{data:f,retryCount:m,statusCode:y.status||y.statusCode||f.statusCode,headers:y.headers}},{validateStatus:n=>!0})}function oe(){return("1000000-1000-4000-8000"+-1e11).replace(/[018]/g,e=>(parseInt(e)^Math.floor(Math.random()*256)&15>>parseInt(e)/4).toString(16))}function Ye(e){return he.reduce((t,r)=>{let o=e[r]?e[r]:typeof e.get=="function"?e.get(r):null;return o&&(t[r]=o),t},{})}function b(e){if(!e)return null;if(e.raw&&typeof e.raw=="function")return e.raw();if(!e.forEach)return Ye(e);let t={};return e.forEach((r,o)=>t[o]=r),t}function z(e){return e!=null&&e.constructor!=null&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e)}function P(e){let t=JSON.parse(JSON.stringify(e));return t?.headers&&(t.headers.Authorization&&(t.headers.Authorization="Bearer ********"),t.headers.authorization&&(t.headers.authorization="Bearer ********")),t}function h(e,t){return{...t,headers:{...t.headers,Authorization:`Bearer ${e}`}}}var fe=["ACL","BIND","CHECKOUT","CONNECT","COPY","DELETE","GET","HEAD","LINK","LOCK","M-SEARCH","MERGE","MKACTIVITY","MKCALENDAR","MKCOL","MOVE","NOTIFY","OPTIONS","PATCH","POST","PROPFIND","PROPPATCH","PURGE","PUT","REBIND","REPORT","SEARCH","SOURCE","SUBSCRIBE","TRACE","UNBIND","UNLINK","UNLOCK","UNSUBSCRIBE"];function te({retryCount:e,retryDelay:t,backoff:r,maxDelay:o}){return r&&e!==0?Math.min(Math.round((Math.random()+1)*t*2**e),o):t}Math.min(Math.round((Math.random()+1)*200*2**10),1/0);function re(e){return new Promise(t=>{setTimeout(t,e)})}function A(e){if(!e?.credentials?.clientId||!e.projectKey||!e.host)throw new Error("Missing required options.");return{clientId:e.credentials.clientId,host:e.host,projectKey:e.projectKey}}function ie(e){return Date.now()+e*1e3-5*60*1e3}function T(e){let t=e;return{get:r=>t,set:(r,o)=>{t=r}}}function Te(e){return typeof e<"u"&&e!==null}function We(e){return Te(e)?typeof e=="string"?e:Object.fromEntries(Object.entries(e).filter(([t,r])=>![null,void 0,""].includes(r))):""}function Xe(e){let t={},r=new URLSearchParams(e);for(let o of r.keys())r.getAll(o).length>1?t[o]=r.getAll(o):t[o]=r.get(o);return t}function Ze(e){if(e=We(e),!e)return"";let t=new URLSearchParams(e);for(let[r,o]of Object.entries(e))Array.isArray(o)&&(t.delete(r),o.filter(Te).forEach(i=>t.append(r,i)));return t.toString()}function me(e,t=Xe){return t(e)}function ne(e,t=Ze){return t(e)}var et=()=>typeof window<"u"&&window.document&&window.document.nodeType===9;function tt(){if(et())return window.navigator.userAgent;let e=process?.version.slice(1)||"unknow",t=`(${process.platform}; ${process.arch})`;return`node.js/${e} ${t}`}function ae(e){let t=null,r=null;if(!e)throw new Error("Missing required option `name`");let o=e.version?`${e.name}/${e.version}`:e.name;e.libraryName&&!e.libraryVersion?t=e.libraryName:e.libraryName&&e.libraryVersion&&(t=`${e.libraryName}/${e.libraryVersion}`),e.contactUrl&&!e.contactEmail?r=`(+${e.contactUrl})`:!e.contactUrl&&e.contactEmail?r=`(+${e.contactEmail})`:e.contactUrl&&e.contactEmail&&(r=`(+${e.contactUrl}; +${e.contactEmail})`);let i=tt(),n=e.customAgent||"";return[o,i,t,r,n].filter(Boolean).join(" ")}function ye(e){if(!e.host)throw new Error("Request `host` or `url` is missing or invalid, please pass in a valid host e.g `host: http://a-valid-host-url`");if(!e.httpClient&&typeof e.httpClient!="function")throw new Error("An `httpClient` is not available, please pass in a `fetch` or `axios` instance as an option or have them globally available.");if(e.httpClientOptions&&Object.prototype.toString.call(e.httpClientOptions)!=="[object Object]")throw new Error("`httpClientOptions` must be an object type")}function we(e){if(!Array.isArray(e))throw new Error("`retryCodes` option must be an array of retry status (error) codes and/or messages.")}function Me(e){if(!e)throw new Error("Missing required options");if(e.middlewares&&!Array.isArray(e.middlewares))throw new Error("Middlewares should be an array");if(!e.middlewares||!Array.isArray(e.middlewares)||!e.middlewares.length)throw new Error("You need to provide at least one middleware")}function se(e,t,r={allowedMethods:fe}){if(!t)throw new Error(`The "${e}" function requires a "Request" object as an argument. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest`);if(typeof t.uri!="string")throw new Error(`The "${e}" Request object requires a valid uri. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest`);if(!r.allowedMethods.includes(t.method))throw new Error(`The "${e}" Request object requires a valid method. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest`)}function ge(e){if(!e)throw new Error("Missing required options");if(!e.host)throw new Error("Missing required option (host)");if(!e.projectKey)throw new Error("Missing required option (projectKey)");if(!e.credentials)throw new Error("Missing required option (credentials)");let{clientId:t,clientSecret:r}=e.credentials||{};if(!(t&&r))throw new Error("Missing required credentials (clientId, clientSecret)");let o=e.scopes?e.scopes.join(" "):void 0,i=btoa(`${t}:${r}`),n=e.oauthUri||"/oauth/token",a=e.host.replace(/\/$/,"")+n,s=`grant_type=client_credentials${o?`&scope=${o}`:""}`;return{url:a,body:s,basicAuth:i}}function xe(e){if(!e)throw new Error("Missing required options");if(!e.projectKey)throw new Error("Missing required option (projectKey)");let t=e.projectKey;e.oauthUri=e.oauthUri||`/oauth/${t}/anonymous/token`;let r=ge(e);return e.credentials.anonymousId&&(r.body+=`&anonymous_id=${e.credentials.anonymousId}`),{...r}}function le(e){if(!e)throw new Error("Missing required options");if(!e.host)throw new Error("Missing required option (host)");if(!e.projectKey)throw new Error("Missing required option (projectKey)");if(!e.credentials)throw new Error("Missing required option (credentials)");if(!e.refreshToken)throw new Error("Missing required option (refreshToken)");let{clientId:t,clientSecret:r}=e.credentials;if(!(t&&r))throw new Error("Missing required credentials (clientId, clientSecret)");let o=btoa(`${t}:${r}`),i=e.oauthUri||"/oauth/token",n=e.host.replace(/\/$/,"")+i,a=`grant_type=refresh_token&refresh_token=${encodeURIComponent(e.refreshToken)}`;return{basicAuth:o,url:n,body:a}}function Oe(e){if(!e)throw new Error("Missing required options");if(!e.host)throw new Error("Missing required option (host)");if(!e.projectKey)throw new Error("Missing required option (projectKey)");if(!e.credentials)throw new Error("Missing required option (credentials)");let{clientId:t,clientSecret:r,user:o}=e.credentials,i=e.projectKey;if(!(t&&r&&o))throw new Error("Missing required credentials (clientId, clientSecret, user)");let{username:n,password:a}=o;if(!(n&&a))throw new Error("Missing required user credentials (username, password)");let s=(e.scopes||[]).join(" "),u=s?`&scope=${s}`:"",l=btoa(`${t}:${r}`),d=e.oauthUri||`/oauth/${i}/customers/token`,p=e.host.replace(/\/$/,"")+d,g=`grant_type=password&username=${encodeURIComponent(n)}&password=${encodeURIComponent(a)}${u}`;return{basicAuth:l,url:p,body:g}}async function k(e){let{httpClient:t,httpClientOptions:r,tokenCache:o,userOption:i,tokenCacheObject:n}=e,a=e.url,s=e.body,u=e.basicAuth;if(!t||typeof t!="function")throw new Error("an `httpClient` is not available, please pass in a `fetch` or `axios` instance as an option or have them globally available.");if(n&&n.refreshToken&&(!n.token||n.token&&Date.now()>n.expirationTime)){if(!i)throw new Error("Missing required options.");let d={...le({...i,refreshToken:n.refreshToken})};a=d.url,s=d.body,u=d.basicAuth}let l;try{if(l=await q({url:a,method:"POST",headers:{Authorization:`Basic ${u}`,"Content-Type":"application/x-www-form-urlencoded","Content-Length":N(s)},httpClient:t,httpClientOptions:r,body:s}),l.statusCode>=200&&l.statusCode<300){let{access_token:d,expires_in:p,refresh_token:g}=l?.data,R=ie(p);return o.set({token:d,expirationTime:R,refreshToken:g}),Promise.resolve(!0)}throw U({code:l.data.error,statusCode:l.data.statusCode,message:l.data.message,error:l.data.errors})}catch(d){throw d}}function H(e){let t=e.tokenCache||T({token:"",expirationTime:-1}),r,o=null,i=A(e);return n=>async a=>{if(a.headers&&(a.headers.Authorization||a.headers.authorization))return n(a);if(r=t.get(i),r&&r.token&&Date.now()<r.expirationTime)return n(h(r.token,a));let s={request:a,tokenCache:t,tokenCacheKey:i,httpClient:e.httpClient||fetch,httpClientOptions:e.httpClientOptions,...xe(e),userOption:e,next:n};return o?await o:(o=k(s),await o,o=null),r=t.get(i),n(h(r.token,a))}}function v(e){let t=e.tokenCache||T({token:"",expirationTime:-1}),r,o=null,i=A(e);return n=>async a=>{if(a.headers&&(a.headers.Authorization||a.headers.authorization))return n(a);if(r=t.get(i),r&&r.token&&Date.now()<r.expirationTime)return n(h(r.token,a));let s={request:a,tokenCache:t,tokenCacheKey:i,tokenCacheObject:r,httpClient:e.httpClient||fetch,httpClientOptions:e.httpClientOptions,...ge(e),next:n};return o?await o:(o=k(s),await o,o=null),r=t.get(i),n(h(r.token,a))}}function _(e,t){return r=>async o=>{if(typeof e!="string")throw new Error("authorization must be a string");let i=t?.force===void 0?!0:t.force;if(!e||o.headers&&(o.headers.Authorization||o.headers.authorization)&&i===!1)return r(o);let n={...o,headers:{...o.headers,Authorization:e}};return r(n)}}function K(e){let t=e.tokenCache||T({token:"",expirationTime:-1}),r,o=null,i=A(e);return n=>async a=>{if(a.headers&&(a.headers.Authorization||a.headers.authorization))return n(a);if(r=t.get(i),r&&r.token&&Date.now()<r.expirationTime)return n(h(r.token,a));let s={request:a,tokenCache:t,tokenCacheKey:i,httpClient:e.httpClient||fetch,httpClientOptions:e.httpClientOptions,...Oe(e),userOption:e,next:n};return o?await o:(o=k(s),await o,o=null),r=t.get(i),n(h(r.token,a))}}function B(e){let t=e.tokenCache||T({token:"",tokenCacheKey:null}),r,o=null,i=A(e);return n=>async a=>{if(a.headers&&(a.headers.Authorization||a.headers.authorization))return n(a);if(r=t.get(i),r&&r.token&&Date.now()<r.expirationTime)return n(h(r.token,a));let s={request:a,tokenCache:t,httpClient:e.httpClient||fetch,httpClientOptions:e.httpClientOptions,...le(e),next:n};return o?await o:(o=k(s),await o,o=null),r=t.get(i),n(h(r.token,a))}}function Q(e){return t=>async r=>{let o=await t(r);if(o.statusCode==409){let i=o.error.body?.errors?.[0]?.currentVersion;if(i)return e&&typeof e=="function"?r.body=await e(i,r,o):r.body=typeof r.body=="string"?{...JSON.parse(r.body),version:i}:{...r.body,version:i},t(r)}return o}}function J(e){return t=>r=>{let o={...r,headers:{...r.headers,"X-Correlation-ID":e.generate&&typeof e.generate=="function"?e.generate():oe()}};return t(o)}}function Ce(e){return t=>async r=>{let o=await t(r);if(o.error){let{error:i}=o;return{...o,statusCode:i.statusCode||0,headers:i.headers||b({}),error:{...i,body:i.data||i}}}return o}}async function rt({url:e,httpClient:t,clientOptions:r}){let{request:o,maskSensitiveHeaderData:i,includeRequestInErrorResponse:n,includeResponseHeaders:a}=r;try{let s=await q({url:e,...r,httpClient:t,method:r.method,...r.body?{body:r.body}:{}});if(a||(s.headers=null),s.statusCode>=200&&s.statusCode<300)return r.method=="HEAD"?{body:null,statusCode:s.statusCode,retryCount:s.retryCount,headers:b(s.headers)}:{body:s.data,statusCode:s.statusCode,retryCount:s.retryCount,headers:b(s.headers)};let u=U({message:s?.data?.message||s?.message,statusCode:s.statusCode||s?.data?.statusCode,headers:b(s.headers),method:r.method,body:s.data,retryCount:s.retryCount,...n?{originalRequest:i?P(o):o}:{uri:o.uri}});return{body:s.data,code:s.statusCode,statusCode:s.statusCode,headers:b(s.headers),error:u}}catch(s){let u=a?b(s.response?.headers):null,l=s.response?.status||s.response?.data0||0,d=s.response?.data?.message;throw{body:null,error:U({statusCode:l,code:l,status:l,message:d||s.message,headers:u,body:s.response?.data||s,error:s.response?.data,...n?{originalRequest:i?P(o):o}:{uri:o.uri}})}}}function V(e){ye(e);let{host:t,credentialsMode:r,httpClient:o,timeout:i,enableRetry:n,retryConfig:a,getAbortController:s,includeOriginalRequest:u,includeRequestInErrorResponse:l=!0,includeResponseHeaders:d=!0,maskSensitiveHeaderData:p,httpClientOptions:g}=e;return R=>async c=>{let F=t.replace(/\/$/,"")+c.uri,w={...c.headers};Object.prototype.hasOwnProperty.call(w,"Content-Type")||Object.prototype.hasOwnProperty.call(w,"content-type")||(w["Content-Type"]="application/json"),w["Content-Type"]===null&&delete w["Content-Type"];let f=C.HEADERS_CONTENT_TYPES.indexOf(w["Content-Type"])>-1&&typeof c.body=="string"||z(c.body)?c.body:JSON.stringify(c.body||void 0);f&&(typeof f=="string"||z(f))&&(w["Content-Length"]=N(f));let m={enableRetry:n,retryConfig:a,request:c,method:c.method,headers:w,includeRequestInErrorResponse:l,maskSensitiveHeaderData:p,includeResponseHeaders:d,...g};r&&(m.credentialsMode=r),i&&(m.timeout=i,m.getAbortController=s),f&&(m.body=f);let I=await rt({url:F,clientOptions:m,httpClient:o}),O={...c,includeOriginalRequest:u,maskSensitiveHeaderData:p,response:I};return R(O)}}function G(e){return t=>async r=>{let o=await t(r),i=Object.assign({},o),{loggerFn:n=console.log}=e||{};return n&&typeof n=="function"&&n(o),i}}function Y({concurrency:e=20}){let t=0,r=[],o=()=>0>=e?Promise.resolve():new Promise(n=>{let a=()=>{t<e?(t++,n()):r.push(a)};a()}),i=()=>{if(t--,r.length>0){let n=r.shift();n&&n()}};return n=>a=>o().then(()=>{let s={...a,resolve(u){a.resolve(u),i()},reject(u){a.reject(u),i()}};return n(s).finally(()=>{i()})})}var ke={name:"@commercetools/ts-client",version:"3.0.3",engines:{node:">=18"},description:"commercetools Composable Commerce TypeScript SDK client.",keywords:["commercetools","composable commerce","sdk","typescript","client","middleware","http","oauth","auth"],homepage:"https://github.com/commercetools/commercetools-sdk-typescript",license:"MIT",directories:{lib:"lib",test:"test"},publishConfig:{access:"public"},repository:{type:"git",url:"git+https://github.com/commercetools/commercetools-sdk-typescript.git"},bugs:{url:"https://github.com/commercetools/commercetools-sdk-typescript/issues"},dependencies:{buffer:"^6.0.3"},files:["dist","CHANGELOG.md"],author:"Chukwuemeka Ajima <meeky.ae@gmail.com>",main:"dist/commercetools-ts-client.cjs.js",module:"dist/commercetools-ts-client.esm.js",browser:{"./dist/commercetools-ts-client.cjs.js":"./dist/commercetools-ts-client.browser.cjs.js","./dist/commercetools-ts-client.esm.js":"./dist/commercetools-ts-client.browser.esm.js"},devDependencies:{"common-tags":"1.8.2",dotenv:"16.4.7",jest:"29.7.0",nock:"^14.0.0-beta.19","organize-imports-cli":"0.10.0"},scripts:{organize_imports:"find src -type f -name '*.ts' | xargs organize-imports-cli",postbuild:"yarn organize_imports",post_process_generate:"yarn organize_imports",docs:"typedoc --out docs"}};function W(e){return t=>async r=>{let o=ae({...e,name:`${e.name?e.name+"/":""}commercetools-sdk-javascript-v3/${ke.version}`}),i={...r,headers:{...r.headers,"User-Agent":o}};return t(i)}}function it({middlewares:e}){return e.length===1?e[0]:e.slice().reduce((r,o)=>(...i)=>r(o.apply(null,i)))}var Ee;function de(e,t,r){if(se("process",e,{allowedMethods:["GET"]}),typeof t!="function")throw new Error('The "process" function accepts a "Function" as a second argument that returns a Promise. See https://commercetools.github.io/nodejs/sdk/api/sdkClient.html#processrequest-processfn-options');let o={total:Number.POSITIVE_INFINITY,accumulate:!0,...r};return new Promise((i,n)=>{let a,s="";if(e&&e.uri){let[R,c]=e.uri.split("?");a=R,s=c}let l={limit:20,...{...me(s)}},d=o.total,p=!1,g=async(R,c=[])=>{let F=l.limit<d?l.limit:d,w=ne({...l,limit:F}),f={sort:"id asc",withTotal:!1,...R?{where:`id > "${R}"`}:{}},m=ne(f),I={...e,uri:`${a}?${m}&${w}`};try{let O=await S(Ee).execute(I),{results:X,count:j}=O?.body||{};if(!j&&p)return i(c||[]);let y=await Promise.resolve(t(O)),M;if(p=!0,o.accumulate&&(M=c.concat(y||[])),d-=j,j<l.limit||!d)return i(M||[]);let D=X[j-1],Z=D&&D.id;g(Z,M)}catch(O){n(O)}};g()})}function S(e){Ee=e,Me(e);let t=!1,r={async resolve(i){let{response:n,includeOriginalRequest:a,maskSensitiveHeaderData:s,...u}=i,{retryCount:l,...d}=n;return t=s,{body:null,error:null,reject:i.reject,resolve:i.resolve,...d,...a?{originalRequest:u}:{},...n?.retryCount?{retryCount:n.retryCount}:{}}}},o=it(e)(r.resolve);return{process:de,execute(i){return se("exec",i),new Promise(async(n,a)=>{try{let s=await o({reject:a,resolve:n,...i});if(s.error)return a(s.error);s.originalRequest&&t&&(s.originalRequest=P(s.originalRequest)),n(s)}catch(s){a(s)}})}}}var{createAuthMiddlewareForPasswordFlow:nt,createAuthMiddlewareForAnonymousSessionFlow:at,createAuthMiddlewareForClientCredentialsFlow:st,createAuthMiddlewareForRefreshTokenFlow:lt,createAuthMiddlewareForExistingTokenFlow:dt,createCorrelationIdMiddleware:ut,createHttpMiddleware:ct,createLoggerMiddleware:ht,createQueueMiddleware:pt,createUserAgentMiddleware:Pe,createConcurrentModificationMiddleware:wt}=Re,L=class{projectKey;authMiddleware;httpMiddleware;userAgentMiddleware;correlationIdMiddleware;loggerMiddleware;queueMiddleware;concurrentMiddleware;telemetryMiddleware;beforeMiddleware;afterMiddleware;middlewares=[];constructor(){this.userAgentMiddleware=Pe({})}withProjectKey(t){return this.projectKey=t,this}defaultClient(t,r,o,i,n,a){return this.withClientCredentialsFlow({host:o,projectKey:i||this.projectKey,credentials:r,httpClient:a||fetch,scopes:n}).withHttpMiddleware({host:t,httpClient:a||fetch})}withAuthMiddleware(t){return this.authMiddleware=t,this}withMiddleware(t){return this.middlewares.push(t),this}withClientCredentialsFlow(t){return this.withAuthMiddleware(st({host:t.host||C.CTP_AUTH_URL,projectKey:t.projectKey||this.projectKey,credentials:{clientId:t.credentials.clientId||null,clientSecret:t.credentials.clientSecret||null},oauthUri:t.oauthUri||null,scopes:t.scopes,httpClient:t.httpClient||fetch,...t}))}withPasswordFlow(t){return this.withAuthMiddleware(nt({host:t.host||C.CTP_AUTH_URL,projectKey:t.projectKey||this.projectKey,credentials:{clientId:t.credentials.clientId||null,clientSecret:t.credentials.clientSecret||null,user:{username:t.credentials.user.username||null,password:t.credentials.user.password||null}},httpClient:t.httpClient||fetch,...t}))}withAnonymousSessionFlow(t){return this.withAuthMiddleware(at({host:t.host||C.CTP_AUTH_URL,projectKey:this.projectKey||t.projectKey,credentials:{clientId:t.credentials.clientId||null,clientSecret:t.credentials.clientSecret||null,anonymousId:t.credentials.anonymousId||null},httpClient:t.httpClient||fetch,...t}))}withRefreshTokenFlow(t){return this.withAuthMiddleware(lt({host:t.host||C.CTP_AUTH_URL,projectKey:this.projectKey||t.projectKey,credentials:{clientId:t.credentials.clientId||null,clientSecret:t.credentials.clientSecret||null},httpClient:t.httpClient||fetch,refreshToken:t.refreshToken||null,...t}))}withExistingTokenFlow(t,r){return this.withAuthMiddleware(dt(t,{force:r.force||!0,...r}))}withHttpMiddleware(t){return this.httpMiddleware=ct({host:t.host||C.CTP_API_URL,httpClient:t.httpClient||fetch,...t}),this}withUserAgentMiddleware(t){return this.userAgentMiddleware=Pe(t),this}withQueueMiddleware(t){return this.queueMiddleware=pt({concurrency:t.concurrency||C.CONCURRENCT_REQUEST,...t}),this}withLoggerMiddleware(t){return this.loggerMiddleware=ht(t),this}withCorrelationIdMiddleware(t){return this.correlationIdMiddleware=ut({generate:t?.generate,...t}),this}withConcurrentModificationMiddleware(t){return this.concurrentMiddleware=wt(t?.concurrentModificationHandlerFn),this}withTelemetryMiddleware(t){let{createTelemetryMiddleware:r,...o}=t;return this.withUserAgentMiddleware({customAgent:o?.userAgent||"typescript-sdk-apm-middleware"}),this.telemetryMiddleware=r(o),this}withBeforeExecutionMiddleware(t){let{middleware:r,...o}=t||{};return this.beforeMiddleware=t.middleware(o),this}withAfterExecutionMiddleware(t){let{middleware:r,...o}=t||{};return this.afterMiddleware=t.middleware(o),this}build(){let t=this.middlewares.slice();return this.telemetryMiddleware&&t.push(this.telemetryMiddleware),this.correlationIdMiddleware&&t.push(this.correlationIdMiddleware),this.userAgentMiddleware&&t.push(this.userAgentMiddleware),this.authMiddleware&&t.push(this.authMiddleware),this.beforeMiddleware&&t.push(this.beforeMiddleware),this.queueMiddleware&&t.push(this.queueMiddleware),this.loggerMiddleware&&t.push(this.loggerMiddleware),this.concurrentMiddleware&&t.push(this.concurrentMiddleware),this.httpMiddleware&&t.push(this.httpMiddleware),this.afterMiddleware&&t.push(this.afterMiddleware),S({middlewares:t})}};return Ue(ft);})(); |
{ | ||
"name": "@commercetools/ts-client", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=18" |
338511
8601