printify-sdk-js
Advanced tools
Comparing version 1.1.0 to 1.2.0-beta
@@ -1,2 +0,2 @@ | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var e=t(require("axios"));function s(t,e,s,o){if("a"===s&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?o:"a"===s?o.call(t):o?o.value:e.get(t)}"function"==typeof SuppressedError&&SuppressedError;class o{constructor(t,e){this.listBlueprints=(t=>async()=>await t("/v1/catalog/blueprints.json",{method:"GET"}))(t),this.getBlueprint=(t=>async e=>await t(`/v1/catalog/blueprints/${e}.json`,{method:"GET"}))(t),this.getBlueprintProviders=(t=>async e=>await t(`/v1/catalog/blueprints/${e}/print_providers.json`,{method:"GET"}))(t),this.getBlueprintVariants=(t=>async(e,s)=>await t(`/v1/catalog/blueprints/${e}/print_providers/${s}/variants.json`,{method:"GET"}))(t),this.getVariantShipping=(t=>async(e,s)=>await t(`/v1/catalog/blueprints/${e}/print_providers/${s}/shipping.json`,{method:"GET"}))(t),this.listProviders=(t=>async()=>await t("/v1/catalog/print_providers.json",{method:"GET"}))(t),this.getProvider=(t=>async e=>await t(`/v1/catalog/print_providers/${e}.json`,{method:"GET"}))(t)}}class n{constructor(t,e){this.list=((t,e)=>async(s={})=>{const{page:o,limit:n,status:a,sku:i}=s,r=new URLSearchParams(Object.assign(Object.assign(Object.assign(Object.assign({},void 0!==o&&{page:o.toString()}),void 0!==n&&{limit:n.toString()}),void 0!==a&&{status:a}),void 0!==i&&{sku:i})).toString();return await t(`/v1/shops/${e}/orders.json${r?`?${r}`:""}`,{method:"GET"})})(t,e),this.getOne=((t,e)=>async s=>await t(`/v1/shops/${e}/orders/${s}.json`,{method:"GET"}))(t,e),this.submit=((t,e)=>async s=>await t(`/v1/shops/${e}/orders.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.submitExpress=((t,e)=>async s=>await t(`/v1/shops/${e}/express.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.sendToProduction=((t,e)=>async s=>await t(`/v1/shops/${e}/orders/${s}/send_to_production.json`,{method:"POST"}))(t,e),this.calculateShipping=((t,e)=>async s=>await t(`/v1/shops/${e}/orders/shipping.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.cancelUnpaid=((t,e)=>async s=>await t(`/v1/shops/${e}/orders/${s}/cancel.json`,{method:"POST"}))(t,e)}}class a{constructor(t,e){this.create=((t,e)=>async s=>await t(`/v1/shops/${e}/products.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.deleteOne=((t,e)=>async s=>{await t(`/v1/shops/${e}/products/${s}.json`,{method:"DELETE"})})(t,e),this.getOne=((t,e)=>async s=>await t(`/v1/shops/${e}/products/${s}.json`,{method:"GET"}))(t,e),this.list=((t,e)=>async(s={})=>{const{page:o,limit:n}=s,a=new URLSearchParams(Object.assign(Object.assign({},void 0!==o&&{page:o.toString()}),void 0!==n&&{limit:n.toString()})).toString(),i=a.toString()?`?${a.toString()}`:"";return await t(`/v1/shops/${e}/products.json${i}`,{method:"GET"})})(t,e),this.notifyUnpublished=((t,e)=>async s=>{await t(`/v1/shops/${e}/products/${s}/unpublish.json`,{method:"POST"})})(t,e),this.publishOne=((t,e)=>async(s,o)=>t(`/v1/shops/${e}/products/${s}/publish.json`,{method:"POST",data:JSON.stringify(o)}))(t,e),this.setPublishFailed=((t,e)=>async(s,o)=>{await t(`/v1/shops/${e}/products/${s}/publishing_failed.json`,{method:"POST",data:JSON.stringify(o)})})(t,e),this.setPublishSucceeded=((t,e)=>async(s,o)=>{await t(`/v1/shops/${e}/products/${s}/publishing_succeeded.json`,{method:"POST",data:JSON.stringify(o)})})(t,e),this.updateOne=((t,e)=>async(s,o)=>t(`/v1/shops/${e}/products/${s}.json`,{method:"PUT",data:JSON.stringify(o)}))(t,e)}}class i{constructor(t,e){this.deleteOne=((t,e)=>async s=>{await t(`/v1/shops/${s||e}/connection.json`,{method:"DELETE"})})(t,e),this.list=(t=>async()=>await t("/v1/shops.json",{method:"GET"}))(t)}}class r{constructor(t,e){this.archive=(t=>async e=>{await t(`/v1/uploads/${e}/archive.json`,{method:"POST"})})(t),this.getById=(t=>async e=>await t(`/v1/uploads/${e}.json`,{method:"GET"}))(t),this.list=(t=>async(e,s)=>{const o=new URLSearchParams;void 0!==e&&o.append("page",e.toString()),void 0!==s&&o.append("limit",s.toString());const n="/v1/uploads.json"+(o.toString()?`?${o.toString()}`:"");return t(n,{method:"GET"})})(t),this.uploadImage=(t=>async e=>await t("/v1/uploads/images.json",{method:"POST",data:JSON.stringify(e)}))(t)}}class c{constructor(t,e){this.list=((t,e)=>async()=>await t(`/v1/shops/${e}/webhooks.json`,{method:"GET"}))(t,e),this.create=((t,e)=>async s=>await t(`/v1/shops/${e}/webhooks.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.updateOne=((t,e)=>async(s,o)=>await t(`/v1/shops/${e}/webhooks/${s}.json`,{method:"PUT",data:JSON.stringify(o)}))(t,e),this.deleteOne=((t,e)=>async s=>await t(`/v1/shops/${e}/webhooks/${s}.json`,{method:"DELETE"}))(t,e)}}const d="https://api.printify.com";function h(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}const u=new Set(["ENOTFOUND","ENETUNREACH","UNABLE_TO_GET_ISSUER_CERT","UNABLE_TO_GET_CRL","UNABLE_TO_DECRYPT_CERT_SIGNATURE","UNABLE_TO_DECRYPT_CRL_SIGNATURE","UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY","CERT_SIGNATURE_FAILURE","CRL_SIGNATURE_FAILURE","CERT_NOT_YET_VALID","CERT_HAS_EXPIRED","CRL_NOT_YET_VALID","CRL_HAS_EXPIRED","ERROR_IN_CERT_NOT_BEFORE_FIELD","ERROR_IN_CERT_NOT_AFTER_FIELD","ERROR_IN_CRL_LAST_UPDATE_FIELD","ERROR_IN_CRL_NEXT_UPDATE_FIELD","OUT_OF_MEM","DEPTH_ZERO_SELF_SIGNED_CERT","SELF_SIGNED_CERT_IN_CHAIN","UNABLE_TO_GET_ISSUER_CERT_LOCALLY","UNABLE_TO_VERIFY_LEAF_SIGNATURE","CERT_CHAIN_TOO_LONG","CERT_REVOKED","INVALID_CA","PATH_LENGTH_EXCEEDED","INVALID_PURPOSE","CERT_UNTRUSTED","CERT_REJECTED","HOSTNAME_MISMATCH"]);var p=h((t=>!u.has(t&&t.code)));const l="axios-retry";function E(t){return!t.response&&(!!t.code&&(!["ERR_CANCELED","ECONNABORTED"].includes(t.code)&&p(t)))}const T=["get","head","options"],g=T.concat(["put","delete"]);function _(t){return"ECONNABORTED"!==t.code&&(!t.response||429===t.response.status||t.response.status>=500&&t.response.status<=599)}function y(t){return!!t.config?.method&&(_(t)&&-1!==g.indexOf(t.config.method))}function f(t){return E(t)||y(t)}function m(t=void 0){const e=t?.response?.headers["retry-after"];if(!e)return 0;let s=1e3*(Number(e)||0);return 0===s&&(s=(new Date(e).valueOf()||0)-Date.now()),Math.max(0,s)}const w={retries:3,retryCondition:f,retryDelay:function(t=0,e=void 0){return Math.max(0,m(e))},shouldResetTimeout:!1,onRetry:()=>{},onMaxRetryTimesExceeded:()=>{},validateResponse:null};function v(t,e,s=!1){const o=function(t,e){return{...w,...e,...t[l]}}(t,e||{});return o.retryCount=o.retryCount||0,o.lastRequestTime&&!s||(o.lastRequestTime=Date.now()),t[l]=o,o}const R=(t,e)=>{const s=t.interceptors.request.use((t=>(v(t,e,!0),t[l]?.validateResponse&&(t.validateStatus=()=>!1),t))),o=t.interceptors.response.use(null,(async s=>{const{config:o}=s;if(!o)return Promise.reject(s);const n=v(o,e);return s.response&&n.validateResponse?.(s.response)?s.response:await async function(t,e){const{retries:s,retryCondition:o}=t,n=(t.retryCount||0)<s&&o(e);if("object"==typeof n)try{return!1!==await n}catch(t){return!1}return n}(n,s)?async function(t,e,s,o){e.retryCount+=1;const{retryDelay:n,shouldResetTimeout:a,onRetry:i}=e,r=n(e.retryCount,s);if(function(t,e){t.defaults.agent===e.agent&&delete e.agent,t.defaults.httpAgent===e.httpAgent&&delete e.httpAgent,t.defaults.httpsAgent===e.httpsAgent&&delete e.httpsAgent}(t,o),!a&&o.timeout&&e.lastRequestTime){const t=Date.now()-e.lastRequestTime,n=o.timeout-t-r;if(n<=0)return Promise.reject(s);o.timeout=n}return o.transformRequest=[t=>t],await i(e.retryCount,s,o),o.signal?.aborted?Promise.resolve(t(o)):new Promise((e=>{const s=()=>{clearTimeout(n),e(t(o))},n=setTimeout((()=>{e(t(o)),o.signal?.removeEventListener&&o.signal.removeEventListener("abort",s)}),r);o.signal?.addEventListener&&o.signal.addEventListener("abort",s,{once:!0})}))}(t,n,s,o):(await async function(t,e){t.retryCount>=t.retries&&await t.onMaxRetryTimesExceeded(e,t.retryCount)}(n,s),Promise.reject(s))}));return{requestInterceptorId:s,responseInterceptorId:o}};var O;R.isNetworkError=E,R.isSafeRequestError=function(t){return!!t.config?.method&&(_(t)&&-1!==T.indexOf(t.config.method))},R.isIdempotentRequestError=y,R.isNetworkOrIdempotentRequestError=f,R.exponentialDelay=function(t=0,e=void 0,s=100){const o=2**t*s,n=Math.max(o,m(e));return n+.2*n*Math.random()},R.linearDelay=function(t=100){return(e=0,s=void 0)=>{const o=e*t;return Math.max(o,m(s))}},R.isRetryableError=_,R(e.default,{retries:3,retryDelay:R.exponentialDelay});O=new WeakMap,module.exports=class{constructor(t){var e;O.set(this,void 0),this.shopId=t.shopId,function(t,e,s,o,n){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===o?n.call(t,s):n?n.value=s:e.set(t,s)}(this,O,t.accessToken,"f"),this.enableLogging=null===(e=t.enableLogging)||void 0===e||e,this.catalog=new o(this.fetchData.bind(this),this.shopId),this.orders=new n(this.fetchData.bind(this),this.shopId),this.products=new a(this.fetchData.bind(this),this.shopId),this.shops=new i(this.fetchData.bind(this),this.shopId),this.uploads=new r(this.fetchData.bind(this),this.shopId),this.webhooks=new c(this.fetchData.bind(this),this.shopId)}logError(t){this.enableLogging&&console.error(t)}logRequest(t,e){this.enableLogging&&console.log(`Requesting ${t.toUpperCase()} ${d}${e}`)}async fetchData(t,o={}){var n,a,i;const r={"Content-Type":"application/json",Authorization:`Bearer ${s(this,O,"f")}`},c=Object.assign(Object.assign({},o.method?o:Object.assign(Object.assign({},o),{method:"GET"})),{baseURL:d,headers:Object.assign(Object.assign({},r),o.headers||{})}),h=(null===(n=o.method)||void 0===n?void 0:n.toLowerCase())||"get";this.logRequest(h,t);try{let s;switch(h){case"post":s=await e.default.post(t,o.data,c);break;case"put":s=await e.default.put(t,o.data,c);break;case"delete":s=await e.default.delete(t,c);break;case"patch":s=await e.default.patch(t,o.data,c);break;default:s=await e.default.get(t,c)}return s.data}catch(s){if(e.default.isAxiosError(s)){const e=`Printify SDK Error: ${null===(a=s.response)||void 0===a?void 0:a.status} ${null===(i=s.response)||void 0===i?void 0:i.statusText} - Requested URL: ${d}${t}`;throw this.logError(e),new Error(e)}{const t="Printify SDK Unknown Error";throw this.logError(t),new Error(t)}}}}; | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var e=t(require("axios"));function s(t,e,s,o){if("a"===s&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?o:"a"===s?o.call(t):o?o.value:e.get(t)}"function"==typeof SuppressedError&&SuppressedError;class o{constructor(t,e){this.listBlueprints=(t=>()=>t("/v1/catalog/blueprints.json",{method:"GET"}))(t),this.getBlueprint=(t=>async e=>await t(`/v1/catalog/blueprints/${e}.json`,{method:"GET"}))(t),this.getBlueprintProviders=(t=>async e=>await t(`/v1/catalog/blueprints/${e}/print_providers.json`,{method:"GET"}))(t),this.getBlueprintVariants=(t=>async(e,s)=>await t(`/v1/catalog/blueprints/${e}/print_providers/${s}/variants.json`,{method:"GET"}))(t),this.getVariantShipping=(t=>async(e,s)=>await t(`/v1/catalog/blueprints/${e}/print_providers/${s}/shipping.json`,{method:"GET"}))(t),this.listProviders=(t=>()=>t("/v1/catalog/print_providers.json",{method:"GET"}))(t),this.getProvider=(t=>async e=>await t(`/v1/catalog/print_providers/${e}.json`,{method:"GET"}))(t)}}class n{constructor(t,e){this.list=((t,e)=>(s={})=>{const{page:o,limit:n,status:r,sku:i}=s,a=new URLSearchParams(Object.assign(Object.assign(Object.assign(Object.assign({},void 0!==o&&{page:o.toString()}),void 0!==n&&{limit:n.toString()}),void 0!==r&&{status:r}),void 0!==i&&{sku:i})).toString();return t(`/v1/shops/${e}/orders.json${a?`?${a}`:""}`,{method:"GET"})})(t,e),this.getOne=((t,e)=>async s=>await t(`/v1/shops/${e}/orders/${s}.json`,{method:"GET"}))(t,e),this.submit=((t,e)=>async s=>await t(`/v1/shops/${e}/orders.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.submitExpress=((t,e)=>async s=>await t(`/v1/shops/${e}/express.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.sendToProduction=((t,e)=>async s=>await t(`/v1/shops/${e}/orders/${s}/send_to_production.json`,{method:"POST"}))(t,e),this.calculateShipping=((t,e)=>async s=>await t(`/v1/shops/${e}/orders/shipping.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.cancelUnpaid=((t,e)=>async s=>await t(`/v1/shops/${e}/orders/${s}/cancel.json`,{method:"POST"}))(t,e)}}class r{constructor(t,e){this.create=((t,e)=>s=>t(`/v1/shops/${e}/products.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.deleteOne=((t,e)=>async s=>{await t(`/v1/shops/${e}/products/${s}.json`,{method:"DELETE"})})(t,e),this.getOne=((t,e)=>async s=>await t(`/v1/shops/${e}/products/${s}.json`,{method:"GET"}))(t,e),this.list=((t,e)=>(s={})=>{const{page:o,limit:n}=s,r=new URLSearchParams(Object.assign(Object.assign({},void 0!==o&&{page:o.toString()}),void 0!==n&&{limit:n.toString()})).toString(),i=r.toString()?`?${r.toString()}`:"";return t(`/v1/shops/${e}/products.json${i}`,{method:"GET"})})(t,e),this.notifyUnpublished=((t,e)=>async s=>{await t(`/v1/shops/${e}/products/${s}/unpublish.json`,{method:"POST"})})(t,e),this.publishOne=((t,e)=>async(s,o)=>t(`/v1/shops/${e}/products/${s}/publish.json`,{method:"POST",data:JSON.stringify(o)}))(t,e),this.setPublishFailed=((t,e)=>async(s,o)=>t(`/v1/shops/${e}/products/${s}/publishing_failed.json`,{method:"POST",data:JSON.stringify(o)}))(t,e),this.setPublishSucceeded=((t,e)=>async(s,o)=>t(`/v1/shops/${e}/products/${s}/publishing_succeeded.json`,{method:"POST",data:JSON.stringify(o)}))(t,e),this.updateOne=((t,e)=>async(s,o)=>t(`/v1/shops/${e}/products/${s}.json`,{method:"PUT",data:JSON.stringify(o)}))(t,e)}}class i{constructor(t,e){this.deleteOne=((t,e)=>async s=>{await t(`/v1/shops/${s||e}/connection.json`,{method:"DELETE"})})(t,e),this.list=(t=>async()=>await t("/v1/shops.json",{method:"GET"}))(t)}}class a{constructor(t,e){this.archive=(t=>async e=>{await t(`/v1/uploads/${e}/archive.json`,{method:"POST"})})(t),this.getById=(t=>async e=>await t(`/v1/uploads/${e}.json`,{method:"GET"}))(t),this.list=(t=>async(e,s)=>{const o=new URLSearchParams;void 0!==e&&o.append("page",e.toString()),void 0!==s&&o.append("limit",s.toString());const n="/v1/uploads.json"+(o.toString()?`?${o.toString()}`:"");return t(n,{method:"GET"})})(t),this.uploadImage=(t=>e=>t("/v1/uploads/images.json",{method:"POST",data:JSON.stringify(e)}))(t)}}class d{constructor(t,e){this.list=((t,e)=>()=>t(`/v1/shops/${e}/webhooks.json`,{method:"GET"}))(t,e),this.create=((t,e)=>s=>t(`/v1/shops/${e}/webhooks.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.updateOne=((t,e)=>(s,o)=>t(`/v1/shops/${e}/webhooks/${s}.json`,{method:"PUT",data:JSON.stringify(o)}))(t,e),this.deleteOne=((t,e)=>s=>t(`/v1/shops/${e}/webhooks/${s}.json`,{method:"DELETE"}))(t,e)}}const c="https://api.printify.com";function h(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}const u=new Set(["ENOTFOUND","ENETUNREACH","UNABLE_TO_GET_ISSUER_CERT","UNABLE_TO_GET_CRL","UNABLE_TO_DECRYPT_CERT_SIGNATURE","UNABLE_TO_DECRYPT_CRL_SIGNATURE","UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY","CERT_SIGNATURE_FAILURE","CRL_SIGNATURE_FAILURE","CERT_NOT_YET_VALID","CERT_HAS_EXPIRED","CRL_NOT_YET_VALID","CRL_HAS_EXPIRED","ERROR_IN_CERT_NOT_BEFORE_FIELD","ERROR_IN_CERT_NOT_AFTER_FIELD","ERROR_IN_CRL_LAST_UPDATE_FIELD","ERROR_IN_CRL_NEXT_UPDATE_FIELD","OUT_OF_MEM","DEPTH_ZERO_SELF_SIGNED_CERT","SELF_SIGNED_CERT_IN_CHAIN","UNABLE_TO_GET_ISSUER_CERT_LOCALLY","UNABLE_TO_VERIFY_LEAF_SIGNATURE","CERT_CHAIN_TOO_LONG","CERT_REVOKED","INVALID_CA","PATH_LENGTH_EXCEEDED","INVALID_PURPOSE","CERT_UNTRUSTED","CERT_REJECTED","HOSTNAME_MISMATCH"]);var p=h((t=>!u.has(t&&t.code)));const l="axios-retry";function E(t){return!t.response&&(!!t.code&&(!["ERR_CANCELED","ECONNABORTED"].includes(t.code)&&p(t)))}const T=["get","head","options"],g=T.concat(["put","delete"]);function _(t){return"ECONNABORTED"!==t.code&&(!t.response||429===t.response.status||t.response.status>=500&&t.response.status<=599)}function f(t){return!!t.config?.method&&(_(t)&&-1!==g.indexOf(t.config.method))}function m(t){return E(t)||f(t)}function v(t=void 0){const e=t?.response?.headers["retry-after"];if(!e)return 0;let s=1e3*(Number(e)||0);return 0===s&&(s=(new Date(e).valueOf()||0)-Date.now()),Math.max(0,s)}const R={retries:3,retryCondition:m,retryDelay:function(t=0,e=void 0){return Math.max(0,v(e))},shouldResetTimeout:!1,onRetry:()=>{},onMaxRetryTimesExceeded:()=>{},validateResponse:null};function y(t,e,s=!1){const o=function(t,e){return{...R,...e,...t[l]}}(t,e||{});return o.retryCount=o.retryCount||0,o.lastRequestTime&&!s||(o.lastRequestTime=Date.now()),t[l]=o,o}const O=(t,e)=>{const s=t.interceptors.request.use((t=>(y(t,e,!0),t[l]?.validateResponse&&(t.validateStatus=()=>!1),t))),o=t.interceptors.response.use(null,(async s=>{const{config:o}=s;if(!o)return Promise.reject(s);const n=y(o,e);return s.response&&n.validateResponse?.(s.response)?s.response:await async function(t,e){const{retries:s,retryCondition:o}=t,n=(t.retryCount||0)<s&&o(e);if("object"==typeof n)try{return!1!==await n}catch(t){return!1}return n}(n,s)?async function(t,e,s,o){e.retryCount+=1;const{retryDelay:n,shouldResetTimeout:r,onRetry:i}=e,a=n(e.retryCount,s);if(function(t,e){t.defaults.agent===e.agent&&delete e.agent,t.defaults.httpAgent===e.httpAgent&&delete e.httpAgent,t.defaults.httpsAgent===e.httpsAgent&&delete e.httpsAgent}(t,o),!r&&o.timeout&&e.lastRequestTime){const t=Date.now()-e.lastRequestTime,n=o.timeout-t-a;if(n<=0)return Promise.reject(s);o.timeout=n}return o.transformRequest=[t=>t],await i(e.retryCount,s,o),o.signal?.aborted?Promise.resolve(t(o)):new Promise((e=>{const s=()=>{clearTimeout(n),e(t(o))},n=setTimeout((()=>{e(t(o)),o.signal?.removeEventListener&&o.signal.removeEventListener("abort",s)}),a);o.signal?.addEventListener&&o.signal.addEventListener("abort",s,{once:!0})}))}(t,n,s,o):(await async function(t,e){t.retryCount>=t.retries&&await t.onMaxRetryTimesExceeded(e,t.retryCount)}(n,s),Promise.reject(s))}));return{requestInterceptorId:s,responseInterceptorId:o}};var w;O.isNetworkError=E,O.isSafeRequestError=function(t){return!!t.config?.method&&(_(t)&&-1!==T.indexOf(t.config.method))},O.isIdempotentRequestError=f,O.isNetworkOrIdempotentRequestError=m,O.exponentialDelay=function(t=0,e=void 0,s=100){const o=2**t*s,n=Math.max(o,v(e));return n+.2*n*Math.random()},O.linearDelay=function(t=100){return(e=0,s=void 0)=>{const o=e*t;return Math.max(o,v(s))}},O.isRetryableError=_,O(e.default,{retries:3,retryDelay:O.exponentialDelay});w=new WeakMap,module.exports=class{constructor(t){var e;w.set(this,void 0),this.shopId=t.shopId,function(t,e,s,o,n){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===o?n.call(t,s):n?n.value=s:e.set(t,s)}(this,w,t.accessToken,"f"),this.enableLogging=null===(e=t.enableLogging)||void 0===e||e,this.catalog=new o(this.fetchData.bind(this),this.shopId),this.orders=new n(this.fetchData.bind(this),this.shopId),this.products=new r(this.fetchData.bind(this),this.shopId),this.shops=new i(this.fetchData.bind(this),this.shopId),this.uploads=new a(this.fetchData.bind(this),this.shopId),this.webhooks=new d(this.fetchData.bind(this),this.shopId)}logError(t){this.enableLogging&&console.error(t)}logRequest(t,e){this.enableLogging&&console.log(`Requesting ${t.toUpperCase()} ${c}${e}`)}async fetchData(t,o={}){var n,r,i;const a={"Content-Type":"application/json",Authorization:`Bearer ${s(this,w,"f")}`},d=Object.assign(Object.assign({},o.method?o:Object.assign(Object.assign({},o),{method:"GET"})),{baseURL:c,headers:Object.assign(Object.assign({},a),o.headers||{})}),h=(null===(n=o.method)||void 0===n?void 0:n.toLowerCase())||"get";this.logRequest(h,t);try{let s;switch(h){case"post":s=await e.default.post(t,o.data,d);break;case"put":s=await e.default.put(t,o.data,d);break;case"delete":s=await e.default.delete(t,d);break;default:s=await e.default.get(t,d)}return s.data}catch(s){if(e.default.isAxiosError(s)){const e=`Printify SDK Error: ${null===(r=s.response)||void 0===r?void 0:r.status} ${null===(i=s.response)||void 0===i?void 0:i.statusText} - Requested URL: ${c}${t}`;throw this.logError(e),new Error(e)}{const t="Printify SDK Unknown Error";throw this.logError(t),new Error(t)}}}}; | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
import t from"axios";function e(t,e,s,o){if("a"===s&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?o:"a"===s?o.call(t):o?o.value:e.get(t)}"function"==typeof SuppressedError&&SuppressedError;class s{constructor(t,e){this.listBlueprints=(t=>async()=>await t("/v1/catalog/blueprints.json",{method:"GET"}))(t),this.getBlueprint=(t=>async e=>await t(`/v1/catalog/blueprints/${e}.json`,{method:"GET"}))(t),this.getBlueprintProviders=(t=>async e=>await t(`/v1/catalog/blueprints/${e}/print_providers.json`,{method:"GET"}))(t),this.getBlueprintVariants=(t=>async(e,s)=>await t(`/v1/catalog/blueprints/${e}/print_providers/${s}/variants.json`,{method:"GET"}))(t),this.getVariantShipping=(t=>async(e,s)=>await t(`/v1/catalog/blueprints/${e}/print_providers/${s}/shipping.json`,{method:"GET"}))(t),this.listProviders=(t=>async()=>await t("/v1/catalog/print_providers.json",{method:"GET"}))(t),this.getProvider=(t=>async e=>await t(`/v1/catalog/print_providers/${e}.json`,{method:"GET"}))(t)}}class o{constructor(t,e){this.list=((t,e)=>async(s={})=>{const{page:o,limit:n,status:a,sku:i}=s,r=new URLSearchParams(Object.assign(Object.assign(Object.assign(Object.assign({},void 0!==o&&{page:o.toString()}),void 0!==n&&{limit:n.toString()}),void 0!==a&&{status:a}),void 0!==i&&{sku:i})).toString();return await t(`/v1/shops/${e}/orders.json${r?`?${r}`:""}`,{method:"GET"})})(t,e),this.getOne=((t,e)=>async s=>await t(`/v1/shops/${e}/orders/${s}.json`,{method:"GET"}))(t,e),this.submit=((t,e)=>async s=>await t(`/v1/shops/${e}/orders.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.submitExpress=((t,e)=>async s=>await t(`/v1/shops/${e}/express.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.sendToProduction=((t,e)=>async s=>await t(`/v1/shops/${e}/orders/${s}/send_to_production.json`,{method:"POST"}))(t,e),this.calculateShipping=((t,e)=>async s=>await t(`/v1/shops/${e}/orders/shipping.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.cancelUnpaid=((t,e)=>async s=>await t(`/v1/shops/${e}/orders/${s}/cancel.json`,{method:"POST"}))(t,e)}}class n{constructor(t,e){this.create=((t,e)=>async s=>await t(`/v1/shops/${e}/products.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.deleteOne=((t,e)=>async s=>{await t(`/v1/shops/${e}/products/${s}.json`,{method:"DELETE"})})(t,e),this.getOne=((t,e)=>async s=>await t(`/v1/shops/${e}/products/${s}.json`,{method:"GET"}))(t,e),this.list=((t,e)=>async(s={})=>{const{page:o,limit:n}=s,a=new URLSearchParams(Object.assign(Object.assign({},void 0!==o&&{page:o.toString()}),void 0!==n&&{limit:n.toString()})).toString(),i=a.toString()?`?${a.toString()}`:"";return await t(`/v1/shops/${e}/products.json${i}`,{method:"GET"})})(t,e),this.notifyUnpublished=((t,e)=>async s=>{await t(`/v1/shops/${e}/products/${s}/unpublish.json`,{method:"POST"})})(t,e),this.publishOne=((t,e)=>async(s,o)=>t(`/v1/shops/${e}/products/${s}/publish.json`,{method:"POST",data:JSON.stringify(o)}))(t,e),this.setPublishFailed=((t,e)=>async(s,o)=>{await t(`/v1/shops/${e}/products/${s}/publishing_failed.json`,{method:"POST",data:JSON.stringify(o)})})(t,e),this.setPublishSucceeded=((t,e)=>async(s,o)=>{await t(`/v1/shops/${e}/products/${s}/publishing_succeeded.json`,{method:"POST",data:JSON.stringify(o)})})(t,e),this.updateOne=((t,e)=>async(s,o)=>t(`/v1/shops/${e}/products/${s}.json`,{method:"PUT",data:JSON.stringify(o)}))(t,e)}}class a{constructor(t,e){this.deleteOne=((t,e)=>async s=>{await t(`/v1/shops/${s||e}/connection.json`,{method:"DELETE"})})(t,e),this.list=(t=>async()=>await t("/v1/shops.json",{method:"GET"}))(t)}}class i{constructor(t,e){this.archive=(t=>async e=>{await t(`/v1/uploads/${e}/archive.json`,{method:"POST"})})(t),this.getById=(t=>async e=>await t(`/v1/uploads/${e}.json`,{method:"GET"}))(t),this.list=(t=>async(e,s)=>{const o=new URLSearchParams;void 0!==e&&o.append("page",e.toString()),void 0!==s&&o.append("limit",s.toString());const n="/v1/uploads.json"+(o.toString()?`?${o.toString()}`:"");return t(n,{method:"GET"})})(t),this.uploadImage=(t=>async e=>await t("/v1/uploads/images.json",{method:"POST",data:JSON.stringify(e)}))(t)}}class r{constructor(t,e){this.list=((t,e)=>async()=>await t(`/v1/shops/${e}/webhooks.json`,{method:"GET"}))(t,e),this.create=((t,e)=>async s=>await t(`/v1/shops/${e}/webhooks.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.updateOne=((t,e)=>async(s,o)=>await t(`/v1/shops/${e}/webhooks/${s}.json`,{method:"PUT",data:JSON.stringify(o)}))(t,e),this.deleteOne=((t,e)=>async s=>await t(`/v1/shops/${e}/webhooks/${s}.json`,{method:"DELETE"}))(t,e)}}const c="https://api.printify.com";function h(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}const d=new Set(["ENOTFOUND","ENETUNREACH","UNABLE_TO_GET_ISSUER_CERT","UNABLE_TO_GET_CRL","UNABLE_TO_DECRYPT_CERT_SIGNATURE","UNABLE_TO_DECRYPT_CRL_SIGNATURE","UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY","CERT_SIGNATURE_FAILURE","CRL_SIGNATURE_FAILURE","CERT_NOT_YET_VALID","CERT_HAS_EXPIRED","CRL_NOT_YET_VALID","CRL_HAS_EXPIRED","ERROR_IN_CERT_NOT_BEFORE_FIELD","ERROR_IN_CERT_NOT_AFTER_FIELD","ERROR_IN_CRL_LAST_UPDATE_FIELD","ERROR_IN_CRL_NEXT_UPDATE_FIELD","OUT_OF_MEM","DEPTH_ZERO_SELF_SIGNED_CERT","SELF_SIGNED_CERT_IN_CHAIN","UNABLE_TO_GET_ISSUER_CERT_LOCALLY","UNABLE_TO_VERIFY_LEAF_SIGNATURE","CERT_CHAIN_TOO_LONG","CERT_REVOKED","INVALID_CA","PATH_LENGTH_EXCEEDED","INVALID_PURPOSE","CERT_UNTRUSTED","CERT_REJECTED","HOSTNAME_MISMATCH"]);var u=h((t=>!d.has(t&&t.code)));const p="axios-retry";function E(t){return!t.response&&(!!t.code&&(!["ERR_CANCELED","ECONNABORTED"].includes(t.code)&&u(t)))}const l=["get","head","options"],T=l.concat(["put","delete"]);function g(t){return"ECONNABORTED"!==t.code&&(!t.response||429===t.response.status||t.response.status>=500&&t.response.status<=599)}function _(t){return!!t.config?.method&&(g(t)&&-1!==T.indexOf(t.config.method))}function y(t){return E(t)||_(t)}function m(t=void 0){const e=t?.response?.headers["retry-after"];if(!e)return 0;let s=1e3*(Number(e)||0);return 0===s&&(s=(new Date(e).valueOf()||0)-Date.now()),Math.max(0,s)}const w={retries:3,retryCondition:y,retryDelay:function(t=0,e=void 0){return Math.max(0,m(e))},shouldResetTimeout:!1,onRetry:()=>{},onMaxRetryTimesExceeded:()=>{},validateResponse:null};function v(t,e,s=!1){const o=function(t,e){return{...w,...e,...t[p]}}(t,e||{});return o.retryCount=o.retryCount||0,o.lastRequestTime&&!s||(o.lastRequestTime=Date.now()),t[p]=o,o}const R=(t,e)=>{const s=t.interceptors.request.use((t=>(v(t,e,!0),t[p]?.validateResponse&&(t.validateStatus=()=>!1),t))),o=t.interceptors.response.use(null,(async s=>{const{config:o}=s;if(!o)return Promise.reject(s);const n=v(o,e);return s.response&&n.validateResponse?.(s.response)?s.response:await async function(t,e){const{retries:s,retryCondition:o}=t,n=(t.retryCount||0)<s&&o(e);if("object"==typeof n)try{return!1!==await n}catch(t){return!1}return n}(n,s)?async function(t,e,s,o){e.retryCount+=1;const{retryDelay:n,shouldResetTimeout:a,onRetry:i}=e,r=n(e.retryCount,s);if(function(t,e){t.defaults.agent===e.agent&&delete e.agent,t.defaults.httpAgent===e.httpAgent&&delete e.httpAgent,t.defaults.httpsAgent===e.httpsAgent&&delete e.httpsAgent}(t,o),!a&&o.timeout&&e.lastRequestTime){const t=Date.now()-e.lastRequestTime,n=o.timeout-t-r;if(n<=0)return Promise.reject(s);o.timeout=n}return o.transformRequest=[t=>t],await i(e.retryCount,s,o),o.signal?.aborted?Promise.resolve(t(o)):new Promise((e=>{const s=()=>{clearTimeout(n),e(t(o))},n=setTimeout((()=>{e(t(o)),o.signal?.removeEventListener&&o.signal.removeEventListener("abort",s)}),r);o.signal?.addEventListener&&o.signal.addEventListener("abort",s,{once:!0})}))}(t,n,s,o):(await async function(t,e){t.retryCount>=t.retries&&await t.onMaxRetryTimesExceeded(e,t.retryCount)}(n,s),Promise.reject(s))}));return{requestInterceptorId:s,responseInterceptorId:o}};var f;R.isNetworkError=E,R.isSafeRequestError=function(t){return!!t.config?.method&&(g(t)&&-1!==l.indexOf(t.config.method))},R.isIdempotentRequestError=_,R.isNetworkOrIdempotentRequestError=y,R.exponentialDelay=function(t=0,e=void 0,s=100){const o=2**t*s,n=Math.max(o,m(e));return n+.2*n*Math.random()},R.linearDelay=function(t=100){return(e=0,s=void 0)=>{const o=e*t;return Math.max(o,m(s))}},R.isRetryableError=g,R(t,{retries:3,retryDelay:R.exponentialDelay});class O{constructor(t){var e;f.set(this,void 0),this.shopId=t.shopId,function(t,e,s,o,n){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===o?n.call(t,s):n?n.value=s:e.set(t,s)}(this,f,t.accessToken,"f"),this.enableLogging=null===(e=t.enableLogging)||void 0===e||e,this.catalog=new s(this.fetchData.bind(this),this.shopId),this.orders=new o(this.fetchData.bind(this),this.shopId),this.products=new n(this.fetchData.bind(this),this.shopId),this.shops=new a(this.fetchData.bind(this),this.shopId),this.uploads=new i(this.fetchData.bind(this),this.shopId),this.webhooks=new r(this.fetchData.bind(this),this.shopId)}logError(t){this.enableLogging&&console.error(t)}logRequest(t,e){this.enableLogging&&console.log(`Requesting ${t.toUpperCase()} ${c}${e}`)}async fetchData(s,o={}){var n,a,i;const r={"Content-Type":"application/json",Authorization:`Bearer ${e(this,f,"f")}`},h=Object.assign(Object.assign({},o.method?o:Object.assign(Object.assign({},o),{method:"GET"})),{baseURL:c,headers:Object.assign(Object.assign({},r),o.headers||{})}),d=(null===(n=o.method)||void 0===n?void 0:n.toLowerCase())||"get";this.logRequest(d,s);try{let e;switch(d){case"post":e=await t.post(s,o.data,h);break;case"put":e=await t.put(s,o.data,h);break;case"delete":e=await t.delete(s,h);break;case"patch":e=await t.patch(s,o.data,h);break;default:e=await t.get(s,h)}return e.data}catch(e){if(t.isAxiosError(e)){const t=`Printify SDK Error: ${null===(a=e.response)||void 0===a?void 0:a.status} ${null===(i=e.response)||void 0===i?void 0:i.statusText} - Requested URL: ${c}${s}`;throw this.logError(t),new Error(t)}{const t="Printify SDK Unknown Error";throw this.logError(t),new Error(t)}}}}f=new WeakMap;export{O as default}; | ||
import t from"axios";function e(t,e,s,o){if("a"===s&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?o:"a"===s?o.call(t):o?o.value:e.get(t)}"function"==typeof SuppressedError&&SuppressedError;class s{constructor(t,e){this.listBlueprints=(t=>()=>t("/v1/catalog/blueprints.json",{method:"GET"}))(t),this.getBlueprint=(t=>async e=>await t(`/v1/catalog/blueprints/${e}.json`,{method:"GET"}))(t),this.getBlueprintProviders=(t=>async e=>await t(`/v1/catalog/blueprints/${e}/print_providers.json`,{method:"GET"}))(t),this.getBlueprintVariants=(t=>async(e,s)=>await t(`/v1/catalog/blueprints/${e}/print_providers/${s}/variants.json`,{method:"GET"}))(t),this.getVariantShipping=(t=>async(e,s)=>await t(`/v1/catalog/blueprints/${e}/print_providers/${s}/shipping.json`,{method:"GET"}))(t),this.listProviders=(t=>()=>t("/v1/catalog/print_providers.json",{method:"GET"}))(t),this.getProvider=(t=>async e=>await t(`/v1/catalog/print_providers/${e}.json`,{method:"GET"}))(t)}}class o{constructor(t,e){this.list=((t,e)=>(s={})=>{const{page:o,limit:n,status:r,sku:i}=s,a=new URLSearchParams(Object.assign(Object.assign(Object.assign(Object.assign({},void 0!==o&&{page:o.toString()}),void 0!==n&&{limit:n.toString()}),void 0!==r&&{status:r}),void 0!==i&&{sku:i})).toString();return t(`/v1/shops/${e}/orders.json${a?`?${a}`:""}`,{method:"GET"})})(t,e),this.getOne=((t,e)=>async s=>await t(`/v1/shops/${e}/orders/${s}.json`,{method:"GET"}))(t,e),this.submit=((t,e)=>async s=>await t(`/v1/shops/${e}/orders.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.submitExpress=((t,e)=>async s=>await t(`/v1/shops/${e}/express.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.sendToProduction=((t,e)=>async s=>await t(`/v1/shops/${e}/orders/${s}/send_to_production.json`,{method:"POST"}))(t,e),this.calculateShipping=((t,e)=>async s=>await t(`/v1/shops/${e}/orders/shipping.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.cancelUnpaid=((t,e)=>async s=>await t(`/v1/shops/${e}/orders/${s}/cancel.json`,{method:"POST"}))(t,e)}}class n{constructor(t,e){this.create=((t,e)=>s=>t(`/v1/shops/${e}/products.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.deleteOne=((t,e)=>async s=>{await t(`/v1/shops/${e}/products/${s}.json`,{method:"DELETE"})})(t,e),this.getOne=((t,e)=>async s=>await t(`/v1/shops/${e}/products/${s}.json`,{method:"GET"}))(t,e),this.list=((t,e)=>(s={})=>{const{page:o,limit:n}=s,r=new URLSearchParams(Object.assign(Object.assign({},void 0!==o&&{page:o.toString()}),void 0!==n&&{limit:n.toString()})).toString(),i=r.toString()?`?${r.toString()}`:"";return t(`/v1/shops/${e}/products.json${i}`,{method:"GET"})})(t,e),this.notifyUnpublished=((t,e)=>async s=>{await t(`/v1/shops/${e}/products/${s}/unpublish.json`,{method:"POST"})})(t,e),this.publishOne=((t,e)=>async(s,o)=>t(`/v1/shops/${e}/products/${s}/publish.json`,{method:"POST",data:JSON.stringify(o)}))(t,e),this.setPublishFailed=((t,e)=>async(s,o)=>t(`/v1/shops/${e}/products/${s}/publishing_failed.json`,{method:"POST",data:JSON.stringify(o)}))(t,e),this.setPublishSucceeded=((t,e)=>async(s,o)=>t(`/v1/shops/${e}/products/${s}/publishing_succeeded.json`,{method:"POST",data:JSON.stringify(o)}))(t,e),this.updateOne=((t,e)=>async(s,o)=>t(`/v1/shops/${e}/products/${s}.json`,{method:"PUT",data:JSON.stringify(o)}))(t,e)}}class r{constructor(t,e){this.deleteOne=((t,e)=>async s=>{await t(`/v1/shops/${s||e}/connection.json`,{method:"DELETE"})})(t,e),this.list=(t=>async()=>await t("/v1/shops.json",{method:"GET"}))(t)}}class i{constructor(t,e){this.archive=(t=>async e=>{await t(`/v1/uploads/${e}/archive.json`,{method:"POST"})})(t),this.getById=(t=>async e=>await t(`/v1/uploads/${e}.json`,{method:"GET"}))(t),this.list=(t=>async(e,s)=>{const o=new URLSearchParams;void 0!==e&&o.append("page",e.toString()),void 0!==s&&o.append("limit",s.toString());const n="/v1/uploads.json"+(o.toString()?`?${o.toString()}`:"");return t(n,{method:"GET"})})(t),this.uploadImage=(t=>e=>t("/v1/uploads/images.json",{method:"POST",data:JSON.stringify(e)}))(t)}}class a{constructor(t,e){this.list=((t,e)=>()=>t(`/v1/shops/${e}/webhooks.json`,{method:"GET"}))(t,e),this.create=((t,e)=>s=>t(`/v1/shops/${e}/webhooks.json`,{method:"POST",data:JSON.stringify(s)}))(t,e),this.updateOne=((t,e)=>(s,o)=>t(`/v1/shops/${e}/webhooks/${s}.json`,{method:"PUT",data:JSON.stringify(o)}))(t,e),this.deleteOne=((t,e)=>s=>t(`/v1/shops/${e}/webhooks/${s}.json`,{method:"DELETE"}))(t,e)}}const h="https://api.printify.com";function c(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}const d=new Set(["ENOTFOUND","ENETUNREACH","UNABLE_TO_GET_ISSUER_CERT","UNABLE_TO_GET_CRL","UNABLE_TO_DECRYPT_CERT_SIGNATURE","UNABLE_TO_DECRYPT_CRL_SIGNATURE","UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY","CERT_SIGNATURE_FAILURE","CRL_SIGNATURE_FAILURE","CERT_NOT_YET_VALID","CERT_HAS_EXPIRED","CRL_NOT_YET_VALID","CRL_HAS_EXPIRED","ERROR_IN_CERT_NOT_BEFORE_FIELD","ERROR_IN_CERT_NOT_AFTER_FIELD","ERROR_IN_CRL_LAST_UPDATE_FIELD","ERROR_IN_CRL_NEXT_UPDATE_FIELD","OUT_OF_MEM","DEPTH_ZERO_SELF_SIGNED_CERT","SELF_SIGNED_CERT_IN_CHAIN","UNABLE_TO_GET_ISSUER_CERT_LOCALLY","UNABLE_TO_VERIFY_LEAF_SIGNATURE","CERT_CHAIN_TOO_LONG","CERT_REVOKED","INVALID_CA","PATH_LENGTH_EXCEEDED","INVALID_PURPOSE","CERT_UNTRUSTED","CERT_REJECTED","HOSTNAME_MISMATCH"]);var u=c((t=>!d.has(t&&t.code)));const p="axios-retry";function E(t){return!t.response&&(!!t.code&&(!["ERR_CANCELED","ECONNABORTED"].includes(t.code)&&u(t)))}const l=["get","head","options"],T=l.concat(["put","delete"]);function g(t){return"ECONNABORTED"!==t.code&&(!t.response||429===t.response.status||t.response.status>=500&&t.response.status<=599)}function _(t){return!!t.config?.method&&(g(t)&&-1!==T.indexOf(t.config.method))}function m(t){return E(t)||_(t)}function v(t=void 0){const e=t?.response?.headers["retry-after"];if(!e)return 0;let s=1e3*(Number(e)||0);return 0===s&&(s=(new Date(e).valueOf()||0)-Date.now()),Math.max(0,s)}const R={retries:3,retryCondition:m,retryDelay:function(t=0,e=void 0){return Math.max(0,v(e))},shouldResetTimeout:!1,onRetry:()=>{},onMaxRetryTimesExceeded:()=>{},validateResponse:null};function y(t,e,s=!1){const o=function(t,e){return{...R,...e,...t[p]}}(t,e||{});return o.retryCount=o.retryCount||0,o.lastRequestTime&&!s||(o.lastRequestTime=Date.now()),t[p]=o,o}const f=(t,e)=>{const s=t.interceptors.request.use((t=>(y(t,e,!0),t[p]?.validateResponse&&(t.validateStatus=()=>!1),t))),o=t.interceptors.response.use(null,(async s=>{const{config:o}=s;if(!o)return Promise.reject(s);const n=y(o,e);return s.response&&n.validateResponse?.(s.response)?s.response:await async function(t,e){const{retries:s,retryCondition:o}=t,n=(t.retryCount||0)<s&&o(e);if("object"==typeof n)try{return!1!==await n}catch(t){return!1}return n}(n,s)?async function(t,e,s,o){e.retryCount+=1;const{retryDelay:n,shouldResetTimeout:r,onRetry:i}=e,a=n(e.retryCount,s);if(function(t,e){t.defaults.agent===e.agent&&delete e.agent,t.defaults.httpAgent===e.httpAgent&&delete e.httpAgent,t.defaults.httpsAgent===e.httpsAgent&&delete e.httpsAgent}(t,o),!r&&o.timeout&&e.lastRequestTime){const t=Date.now()-e.lastRequestTime,n=o.timeout-t-a;if(n<=0)return Promise.reject(s);o.timeout=n}return o.transformRequest=[t=>t],await i(e.retryCount,s,o),o.signal?.aborted?Promise.resolve(t(o)):new Promise((e=>{const s=()=>{clearTimeout(n),e(t(o))},n=setTimeout((()=>{e(t(o)),o.signal?.removeEventListener&&o.signal.removeEventListener("abort",s)}),a);o.signal?.addEventListener&&o.signal.addEventListener("abort",s,{once:!0})}))}(t,n,s,o):(await async function(t,e){t.retryCount>=t.retries&&await t.onMaxRetryTimesExceeded(e,t.retryCount)}(n,s),Promise.reject(s))}));return{requestInterceptorId:s,responseInterceptorId:o}};var O;f.isNetworkError=E,f.isSafeRequestError=function(t){return!!t.config?.method&&(g(t)&&-1!==l.indexOf(t.config.method))},f.isIdempotentRequestError=_,f.isNetworkOrIdempotentRequestError=m,f.exponentialDelay=function(t=0,e=void 0,s=100){const o=2**t*s,n=Math.max(o,v(e));return n+.2*n*Math.random()},f.linearDelay=function(t=100){return(e=0,s=void 0)=>{const o=e*t;return Math.max(o,v(s))}},f.isRetryableError=g,f(t,{retries:3,retryDelay:f.exponentialDelay});class w{constructor(t){var e;O.set(this,void 0),this.shopId=t.shopId,function(t,e,s,o,n){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===o?n.call(t,s):n?n.value=s:e.set(t,s)}(this,O,t.accessToken,"f"),this.enableLogging=null===(e=t.enableLogging)||void 0===e||e,this.catalog=new s(this.fetchData.bind(this),this.shopId),this.orders=new o(this.fetchData.bind(this),this.shopId),this.products=new n(this.fetchData.bind(this),this.shopId),this.shops=new r(this.fetchData.bind(this),this.shopId),this.uploads=new i(this.fetchData.bind(this),this.shopId),this.webhooks=new a(this.fetchData.bind(this),this.shopId)}logError(t){this.enableLogging&&console.error(t)}logRequest(t,e){this.enableLogging&&console.log(`Requesting ${t.toUpperCase()} ${h}${e}`)}async fetchData(s,o={}){var n,r,i;const a={"Content-Type":"application/json",Authorization:`Bearer ${e(this,O,"f")}`},c=Object.assign(Object.assign({},o.method?o:Object.assign(Object.assign({},o),{method:"GET"})),{baseURL:h,headers:Object.assign(Object.assign({},a),o.headers||{})}),d=(null===(n=o.method)||void 0===n?void 0:n.toLowerCase())||"get";this.logRequest(d,s);try{let e;switch(d){case"post":e=await t.post(s,o.data,c);break;case"put":e=await t.put(s,o.data,c);break;case"delete":e=await t.delete(s,c);break;default:e=await t.get(s,c)}return e.data}catch(e){if(t.isAxiosError(e)){const t=`Printify SDK Error: ${null===(r=e.response)||void 0===r?void 0:r.status} ${null===(i=e.response)||void 0===i?void 0:i.statusText} - Requested URL: ${h}${s}`;throw this.logError(t),new Error(t)}{const t="Printify SDK Unknown Error";throw this.logError(t),new Error(t)}}}}O=new WeakMap;export{w as default}; | ||
//# sourceMappingURL=index.esm.js.map |
# Printify SDK Documentation (Node.js) | ||
## Introduction | ||
The Printify SDK for Node.js. A basic TypeScript wrapper for the Printify REST API (v1). Guidelines and source endpoints can be found here: | ||
[developers.printify.com](https://developers.printify.com/). | ||
## Usage | ||
```sh | ||
# generate a token: https://printify.com/app/account/api | ||
export PRINTIFY_API_TOKEN="asdfASDFasdfASDFasdfASDF" | ||
# fetch your shopId | ||
curl -X GET https://api.printify.com/v1/shops.json --header "Authorization: Bearer $PRINTIFY_API_TOKEN" | ||
# Expected response: [{"id":1234567,"title":"My Store Name","sales_channel":"custom_integration"}] | ||
# store for process.env.PRINTIFY_API_TOKEN | ||
echo "PRINTIFY_API_TOKEN=\"$PRINTIFY_API_TOKEN\"" >> .env | ||
``` | ||
```js | ||
import Printify from 'printify-sdk-js'; | ||
// const Printify = require('printify-sdk-js'); // CommonJS | ||
const printify = new Printify({ | ||
shopId: '123456', // global query by shop_id | ||
accessToken: process.env.PRINTIFY_API_TOKEN, | ||
enableLogging: true, // on by default | ||
}); | ||
const orderData = { | ||
label: 'order_123456', | ||
line_items: [ | ||
{ | ||
print_provider_id: '12345', | ||
blueprint_id: '67890', | ||
variant_id: '112233', | ||
print_areas: { | ||
front: 'https://example.com/path/to/sticker.png', // **must be public | ||
}, | ||
quantity: 1, | ||
}, | ||
// ... | ||
], | ||
shipping_method: 1, | ||
is_printify_express: false, | ||
is_economy_shipping: false, | ||
send_shipping_notification: true, // send email | ||
address_to: { | ||
first_name: 'John', | ||
last_name: 'Doe', | ||
email: 'johndoe@gmail.com', | ||
phone: '0574 69 21 90', | ||
country: 'US', | ||
region: 'NY', | ||
address1: '123 Main Street', | ||
address2: '', | ||
city: 'New York', | ||
zip: '10001', | ||
}, | ||
}; | ||
try { | ||
const result = await printify.orders.submit(orderData); | ||
console.log(result); // { "id": "5a96f649b2439217d070f507" } | ||
} catch (error) { | ||
console.error('Error submitting order:', error); | ||
} | ||
``` | ||
## API | ||
- [Shops](#shops) | ||
@@ -75,0 +4,0 @@ - [Catalog](#catalog) |
{ | ||
"name": "printify-sdk-js", | ||
"version": "1.1.0", | ||
"description": "Printify SDK for JavaScript. Client for Node.js", | ||
"version": "1.2.0-beta", | ||
"description": "Node.js SDK for the Printify API.", | ||
"author": "Spencer Lepine <spencer.sayhello@gmail.com>", | ||
@@ -63,3 +63,2 @@ "license": "MIT", | ||
"dependencies": { | ||
"@types/jest": "^29.5.14", | ||
"axios": "^1.7.7", | ||
@@ -72,2 +71,3 @@ "axios-retry": "^4.5.0" | ||
"devDependencies": { | ||
"@types/jest": "^29.5.14", | ||
"@jest/types": "^29.6.3", | ||
@@ -98,2 +98,2 @@ "@rollup/plugin-commonjs": "^26.0.1", | ||
} | ||
} | ||
} |
132
README.md
@@ -7,21 +7,26 @@ # Printify SDK for TypeScript (Node.js) | ||
Printify SDK for Node.js. A basic TypeScript wrapper for the Printify REST API (v1). Guidelines and source endpoints can be found here: | ||
[developers.printify.com](https://developers.printify.com). | ||
The Printify Node SDK provides convenient access to the Printify API from applications written in server-side JavaScript. | ||
## Getting started | ||
Guidelines and source endpoints can be found here: [developers.printify.com](https://developers.printify.com). | ||
### Prerequisites | ||
> 📢 Note: This SDK currently supports V1 API endpoints only. A 2.0.0 release is planned once the majority of V2 endpoints have been migrated. | ||
- Printify Personal Access Token (create one [here](https://printify.com/app/account/api)) | ||
## Documentation | ||
### Installation | ||
See the [`printify-sdk-js` API docs](./docs/API.md) for Node.js | ||
- [Shops](./docs/API.md#shops) - `printify.shops.*` | ||
- [Catalog](./docs/API.md#catalog) - `printify.catalog.*` | ||
- [Products](./docs/API.md#products) - `printify.products.*` | ||
- [Orders](./docs/API.md#orders) - `printify.orders.*` | ||
- [Uploads](./docs/API.md#uploads) - `printify.uploads.*` | ||
- [Webhooks](./docs/API.md#webhooks) - `printify.webhooks.*` | ||
## Installation | ||
```sh | ||
# Npm | ||
npm install printify-sdk-js | ||
# Yarn | ||
# or | ||
yarn add printify-sdk-js | ||
# Pnpm | ||
# or | ||
pnpm add printify-sdk-js | ||
@@ -32,77 +37,64 @@ ``` | ||
> ⚠️ For security purposes, this is intended only for server-side use, the API does not support CORS and will not process requests from a frontend application | ||
The package needs to be configured with your account's Personal Access Token (create one [here](https://printify.com/app/account/api)). | ||
```sh | ||
# generate a token: https://printify.com/app/account/api | ||
export PRINTIFY_API_TOKEN="asdfASDFasdfASDFasdfASDF" | ||
```js | ||
import Printify from 'printify-sdk-js'; | ||
# fetch your shopId | ||
curl -X GET https://api.printify.com/v1/shops.json --header "Authorization: Bearer $PRINTIFY_API_TOKEN" | ||
# Expected response: [{"id":1234567,"title":"My Store Name","sales_channel":"custom_integration"}] | ||
const printify = new Printify({ | ||
shopId: '123456', // (optional) find using printify.shops.list() | ||
accessToken: process.env.PRINTIFY_API_TOKEN, // generate a token: https://printify.com/app/account/api | ||
enableLogging: true, // (optional) enabled by default | ||
}); | ||
# store for process.env.PRINTIFY_API_TOKEN | ||
echo "PRINTIFY_API_TOKEN=\"$PRINTIFY_API_TOKEN\"" >> .env | ||
const orders = await printify.orders.list({ limit: 5, status: 'fulfilled' }); | ||
console.log(orders); // { current_page: 1, data: [{ id: "5a9", address_to: {}, line_items: [], total_price: 2200, status: "fulfilled" } ] | ||
``` | ||
```js | ||
### Usage with TypeScript | ||
```typescript | ||
import Printify from 'printify-sdk-js'; | ||
// const Printify = require('printify-sdk-js'); // CommonJS | ||
import type { ListWebhooksResponse, Webhook } from 'printify-sdk-js'; | ||
const printify = new Printify({ shopId: '123456', accessToken: process.env.PRINTIFY_API_TOKEN }); | ||
const result: ListWebhooksResponse = await printify.webhooks.list(); | ||
const webhook: Webhook = result[0]; | ||
console.log(webhook); // { "topic": "order:created", "url": "https://example.com/webhooks/order/created", "shop_id": "1", "id": "5cb87a8cd490a2ccb256cec4" } | ||
``` | ||
### Usage with CommonJS | ||
```js | ||
const Printify = require('printify-sdk-js'); | ||
const printify = new Printify({ | ||
shopId: '123456', // global query by shop_id | ||
shopId: '123456', | ||
accessToken: process.env.PRINTIFY_API_TOKEN, | ||
enableLogging: true, // on by default | ||
enableLogging: true, | ||
}); | ||
const orderData = { | ||
label: order_123456, | ||
line_items: [ | ||
{ | ||
print_provider_id: '12345', | ||
blueprint_id: '67890', | ||
variant_id: '112233', | ||
print_areas: { | ||
front: 'https://example.com/path/to/sticker.png', // **must be public | ||
}, | ||
quantity: 1, | ||
}, | ||
// ... | ||
], | ||
shipping_method: 1, | ||
is_printify_express: false, | ||
is_economy_shipping: false, | ||
send_shipping_notification: true, // send email | ||
address_to: { | ||
first_name: 'John', | ||
last_name: 'Doe', | ||
email: 'johndoe@gmail.com', | ||
phone: '0574 69 21 90', | ||
country: 'US', | ||
region: 'NY', | ||
address1: '123 Main Street', | ||
address2: '', | ||
city: 'New York', | ||
zip: '10001', | ||
}, | ||
}; | ||
printify.orders | ||
.list({ limit: 5, status: 'fulfilled' }) | ||
.then(orders => console.log(orders)) | ||
.catch(error => console.error(error)); | ||
``` | ||
try { | ||
const result = await printify.orders.submit(orderData); | ||
console.log(result); // { "id": "5a96f649b2439217d070f507" } | ||
} catch (error) { | ||
console.error('Error submitting order:', error); | ||
} | ||
## Development | ||
```sh | ||
yarn install | ||
yarn test | ||
``` | ||
## API | ||
> If you do not have yarn installed, you can get it with `npm install --global yarn`. | ||
For the full documentation, please see [`API.md`](./docs/API.md) | ||
```sh | ||
# (optional) test the bundle locally | ||
yarn build | ||
mv dist examples/development | ||
cd examples/development | ||
yarn start | ||
``` | ||
- [Shops](./docs/API.md#shops) - `printify.shops.*` | ||
- [Catalog](./docs/API.md#catalog) - `printify.catalog.*` | ||
- [Products](./docs/API.md#products) - `printify.products.*` | ||
- [Orders](./docs/API.md#orders) - `printify.orders.*` | ||
- [Uploads](./docs/API.md#uploads) - `printify.uploads.*` | ||
- [Webhooks](./docs/API.md#webhooks) - `printify.webhooks.*` | ||
## Contributing | ||
@@ -109,0 +101,0 @@ |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
124866
3
22
82
2
110
- Removed@types/jest@^29.5.14
- Removed@babel/code-frame@7.26.2(transitive)
- Removed@babel/helper-validator-identifier@7.25.9(transitive)
- Removed@jest/expect-utils@29.7.0(transitive)
- Removed@jest/schemas@29.6.3(transitive)
- Removed@jest/types@29.6.3(transitive)
- Removed@sinclair/typebox@0.27.8(transitive)
- Removed@types/istanbul-lib-coverage@2.0.6(transitive)
- Removed@types/istanbul-lib-report@3.0.3(transitive)
- Removed@types/istanbul-reports@3.0.4(transitive)
- Removed@types/jest@29.5.14(transitive)
- Removed@types/node@22.13.4(transitive)
- Removed@types/stack-utils@2.0.3(transitive)
- Removed@types/yargs@17.0.33(transitive)
- Removed@types/yargs-parser@21.0.3(transitive)
- Removedansi-styles@4.3.05.2.0(transitive)
- Removedbraces@3.0.3(transitive)
- Removedchalk@4.1.2(transitive)
- Removedci-info@3.9.0(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removeddiff-sequences@29.6.3(transitive)
- Removedescape-string-regexp@2.0.0(transitive)
- Removedexpect@29.7.0(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedis-number@7.0.0(transitive)
- Removedjest-diff@29.7.0(transitive)
- Removedjest-get-type@29.6.3(transitive)
- Removedjest-matcher-utils@29.7.0(transitive)
- Removedjest-message-util@29.7.0(transitive)
- Removedjest-util@29.7.0(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removedpicocolors@1.1.1(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedpretty-format@29.7.0(transitive)
- Removedreact-is@18.3.1(transitive)
- Removedslash@3.0.0(transitive)
- Removedstack-utils@2.0.6(transitive)
- Removedsupports-color@7.2.0(transitive)
- Removedto-regex-range@5.0.1(transitive)
- Removedundici-types@6.20.0(transitive)