@sommpicks/sommpicks-shopify 24.12.12 → 24.12.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"ShopifyUtils.d.ts","sourceRoot":"","sources":["../../shopify/ShopifyUtils.ts"],"names":[],"mappings":"AAEA,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAI7C,MAAM,WAAW,qBAAsB,SAAQ,aAAa;IACxD,YAAY,EAAE,MAAM;QAAE,0BAA0B,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAC;KAAC,CAAC;CAClJ;AAED,qBAAa,YAAY;IAErB,OAAc,gBAAgB,SAAU,MAAM,SAAS,MAAM,WAAW,MAAM,YAAY,MAAM,WAAW,aAAa,KAAG,qBAAqB,CAoD9I;CACL"}
1
+ {"version":3,"file":"ShopifyUtils.d.ts","sourceRoot":"","sources":["../../shopify/ShopifyUtils.ts"],"names":[],"mappings":"AAEA,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAI7C,MAAM,WAAW,qBAAsB,SAAQ,aAAa;IACxD,YAAY,EAAE,MAAM;QAAE,0BAA0B,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAC;KAAC,CAAC;CAClJ;AAED,qBAAa,YAAY;IAErB,OAAc,gBAAgB,SAAU,MAAM,SAAS,MAAM,WAAW,MAAM,YAAY,MAAM,WAAW,aAAa,KAAG,qBAAqB,CAqD9I;CACL"}
@@ -67,8 +67,9 @@ ShopifyUtils.getAxiosInstance = (shop, token, api_key, password, options) => {
67
67
  // || (typeof status === 'number' && status >= 500 && status <= 599)
68
68
  // || status === 429;
69
69
  return axios_retry_1.default.isNetworkOrIdempotentRequestError(error) ||
70
- (error.response && error.response.status >= 500 && error.response.status <= 599) ||
71
- (error.response && error.response.status === 429);
70
+ error.code === 'ECONNABORTED'
71
+ || (error.response && error.response.status >= 500 && error.response.status <= 599)
72
+ || (error.response && error.response.status === 429);
72
73
  }
73
74
  });
74
75
  const axiosRateLimit = new sommpicks_shopify_rate_limit_1.default(client, { maxRequests: options.max_requests_per_sec, timeFrameInMillsForCalls: 1000 }, 50);
@@ -1 +1 @@
1
- {"version":3,"file":"ShopifyUtils.js","sourceRoot":"","sources":["../../shopify/ShopifyUtils.ts"],"names":[],"mappings":";;;AAAA,6CAAqC;AACrC,0FAAqE;AACrE,iCAA6C;AAC7C,qEAAyE;AACzE,kDAA2C;AAM3C,MAAa,YAAY;;AAAzB,oCAuDC;AArDiB,6BAAgB,GAAG,CAAC,IAAY,EAAE,KAAa,EAAE,OAAe,EAAE,QAAgB,EAAE,OAAsB,EAAyB,EAAE;IAC/I,IAAI,CAAC,OAAO,EAAE;QAAE,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC;QAAC,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC;QAAC,OAAO,CAAC,OAAO,GAAG,CAAC,CAAC;QAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;QAAC,OAAO,CAAC,oBAAoB,GAAG,CAAC,CAAC;KAAE;IACrJ,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;QAAE,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC;KAAE;IAClD,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;QAAE,OAAO,CAAC,OAAO,GAAG,CAAC,CAAC;KAAE;IAC9C,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;QAAE,OAAO,CAAC,OAAO,GAAG,CAAC,CAAC;KAAE;IAC9C,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE;QAAE,OAAO,CAAC,WAAW,GAAG,KAAK,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,CAAC,iCAAiC,CAAC,KAAK,CAAC;gBACnE,CAAC,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,IAAI,GAAG,CAAC;gBAChF,CAAC,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC;QACtD,CAAC;KACJ,CAAC,CAAC;IACH,MAAM,cAAc,GAAG,IAAI,sCAAc,CACrC,MAAM,EACN,EAAE,WAAW,EAAE,OAAO,CAAC,oBAAoB,EAAE,wBAAwB,EAAE,IAAI,EAAE,EAC7E,EAAE,CACL,CAAC;IACF,IAAG,OAAO,CAAC,WAAW,EAAE;QACpB,MAAM,GAAG,IAAA,oCAAU,EAAC,cAAc,CAAC,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,IAAA,4CAAkB,EAAC,IAAI,EAAE,OAAO,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC;KAC9I;IACD,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC;AACvE,CAAC,CAAC","sourcesContent":["import axiosRetry from 'axios-retry';\nimport AxiosRateLimit from '@sommpicks/sommpicks-shopify-rate-limit';\nimport axios, { AxiosInstance } from 'axios';\nimport { setupCache, buildMemoryStorage } from 'axios-cache-interceptor';\nimport APIVersion from './base/APIVersion';\n\nexport interface AxiosInstanceExtended extends AxiosInstance {\n getQueueInfo: () => { request_within_last_second: number; apiQueue: number; graphQueue: number; apiProcessed: number; graphProcessed: number;};\n}\n\nexport class ShopifyUtils {\n\n public static getAxiosInstance = (shop: string, token: string, api_key: string, password: string, options: IRest_Options): AxiosInstanceExtended => {\n if (!options) { options.enableCache = false; options.timeout = 30000; options.retries = 3; options.logger = null; options.max_requests_per_sec = 2; }\n if (!options.timeout) { options.timeout = 30000; }\n if (!options.retries) { options.retries = 5; }\n if (!options.retries) { options.retries = 5; }\n if (!options.enableCache) { options.enableCache = false; }\n if (!options.max_requests_per_sec) { options.max_requests_per_sec = 2; }\n let client;\n if (token) {\n client = axios.create({\n baseURL: `https://${shop}/admin/${APIVersion.API_URL}`,\n timeout: options.timeout,\n headers: {\n 'X-Shopify-Access-Token': token,\n 'Content-Type': 'application/json;charset=UTF-8'\n }\n });\n } else if (api_key && password) {\n client = axios.create({\n baseURL: `https://${api_key}:${password}@${shop}/admin/${APIVersion.API_URL}`,\n timeout: options.timeout,\n headers: { 'Content-Type': 'application/json;charset=UTF-8' }\n });\n } else {\n throw 'No acces token defined AND no private app key and password set so it is not possible to build the admin shop url';\n }\n (axiosRetry as any)(client, {\n retries: options.retries,\n retryDelay: (retryCount: number) => {\n if (options.logger && retryCount === options.retries) options.logger.error(`Retry ${retryCount} ...`);\n return retryCount * (retryCount > 3 ? 2000 : 500);\n },\n shouldResetTimeout: true,\n retryCondition: (error: any) => {\n // const status = error?.response?.status;\n // return (axiosRetry as any).isNetworkOrIdempotentRequestError(error)\n // || (typeof status === 'number' && status >= 500 && status <= 599)\n // || status === 429;\n return (axiosRetry as any).isNetworkOrIdempotentRequestError(error) || \n (error.response && error.response.status >= 500 && error.response.status <= 599) || \n (error.response && error.response.status === 429);\n }\n });\n const axiosRateLimit = new AxiosRateLimit(\n client,\n { maxRequests: options.max_requests_per_sec, timeFrameInMillsForCalls: 1000 },\n 50\n );\n if(options.enableCache) {\n client = setupCache(axiosRateLimit.getInstance(), { methods: ['get'], storage: buildMemoryStorage(true, options.cacheTimeInMiliseconds) });\n }\n return options.enableCache ? client : axiosRateLimit.getInstance();\n };\n}\n"]}
1
+ {"version":3,"file":"ShopifyUtils.js","sourceRoot":"","sources":["../../shopify/ShopifyUtils.ts"],"names":[],"mappings":";;;AAAA,6CAAqC;AACrC,0FAAqE;AACrE,iCAA6C;AAC7C,qEAAyE;AACzE,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AAG,OAAO,CAAC,WAAW,EAAE;QACpB,MAAM,GAAG,IAAA,oCAAU,EAAC,cAAc,CAAC,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,IAAA,4CAAkB,EAAC,IAAI,EAAE,OAAO,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC;KAC9I;IACD,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC;AACvE,CAAC,CAAC","sourcesContent":["import axiosRetry from 'axios-retry';\nimport AxiosRateLimit from '@sommpicks/sommpicks-shopify-rate-limit';\nimport axios, { AxiosInstance } from 'axios';\nimport { setupCache, buildMemoryStorage } from 'axios-cache-interceptor';\nimport APIVersion from './base/APIVersion';\n\nexport interface AxiosInstanceExtended extends AxiosInstance {\n getQueueInfo: () => { request_within_last_second: number; apiQueue: number; graphQueue: number; apiProcessed: number; graphProcessed: number;};\n}\n\nexport class ShopifyUtils {\n\n public static getAxiosInstance = (shop: string, token: string, api_key: string, password: string, options: IRest_Options): AxiosInstanceExtended => {\n if (!options) { options.enableCache = false; options.timeout = 30000; options.retries = 3; options.logger = null; options.max_requests_per_sec = 2; }\n if (!options.timeout) { options.timeout = 30000; }\n if (!options.retries) { options.retries = 5; }\n if (!options.retries) { options.retries = 5; }\n if (!options.enableCache) { options.enableCache = false; }\n if (!options.max_requests_per_sec) { options.max_requests_per_sec = 2; }\n let client;\n if (token) {\n client = axios.create({\n baseURL: `https://${shop}/admin/${APIVersion.API_URL}`,\n timeout: options.timeout,\n headers: {\n 'X-Shopify-Access-Token': token,\n 'Content-Type': 'application/json;charset=UTF-8'\n }\n });\n } else if (api_key && password) {\n client = axios.create({\n baseURL: `https://${api_key}:${password}@${shop}/admin/${APIVersion.API_URL}`,\n timeout: options.timeout,\n headers: { 'Content-Type': 'application/json;charset=UTF-8' }\n });\n } else {\n throw 'No acces token defined AND no private app key and password set so it is not possible to build the admin shop url';\n }\n (axiosRetry as any)(client, {\n retries: options.retries,\n retryDelay: (retryCount: number) => {\n if (options.logger && retryCount === options.retries) options.logger.error(`Retry ${retryCount} ...`);\n return retryCount * (retryCount > 3 ? 2000 : 500);\n },\n shouldResetTimeout: true,\n retryCondition: (error: any) => {\n // const status = error?.response?.status;\n // return (axiosRetry as any).isNetworkOrIdempotentRequestError(error)\n // || (typeof status === 'number' && status >= 500 && status <= 599)\n // || status === 429;\n return (axiosRetry as any).isNetworkOrIdempotentRequestError(error) || \n error.code ==='ECONNABORTED'\n || (error.response && error.response.status >= 500 && error.response.status <= 599) \n || (error.response && error.response.status === 429);\n }\n });\n const axiosRateLimit = new AxiosRateLimit(\n client,\n { maxRequests: options.max_requests_per_sec, timeFrameInMillsForCalls: 1000 },\n 50\n );\n if(options.enableCache) {\n client = setupCache(axiosRateLimit.getInstance(), { methods: ['get'], storage: buildMemoryStorage(true, options.cacheTimeInMiliseconds) });\n }\n return options.enableCache ? client : axiosRateLimit.getInstance();\n };\n}\n"]}
@@ -2,6 +2,8 @@ import { AxiosInstance } from 'axios';
2
2
  import { AbstractService } from '../base/AbstractService';
3
3
  export declare class ShopifyProductPublicationsService extends AbstractService {
4
4
  private axiosInstance;
5
+ private static publicationsCache;
6
+ private static readonly cacheTtlMs;
5
7
  constructor(axiosInstance: AxiosInstance);
6
8
  /**
7
9
  * Returns a max of 15 publications
@@ -1 +1 @@
1
- {"version":3,"file":"ShopifyProductPublicationsService.d.ts","sourceRoot":"","sources":["../../../shopify/product/ShopifyProductPublicationsService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAItC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D,qBAAa,iCAAkC,SAAQ,eAAe;IAEtD,OAAO,CAAC,aAAa;gBAAb,aAAa,EAAE,aAAa;IAEhD;;;;OAIG;IACI,eAAe,QAAa,QAAQ,oBAAoB,EAAE,CAAC,CAwBhE;IAEF;;;;;OAKG;IACI,OAAO,cAAqB,MAAM,KAAG,QAAQ,qBAAqB,CAAC,CA+BxE;IAEF;;;;;OAKG;IACI,SAAS,cAAqB,MAAM,KAAG,QAAQ,uBAAuB,CAAC,CAuB5E;CACL"}
1
+ {"version":3,"file":"ShopifyProductPublicationsService.d.ts","sourceRoot":"","sources":["../../../shopify/product/ShopifyProductPublicationsService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAItC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D,qBAAa,iCAAkC,SAAQ,eAAe;IAKtD,OAAO,CAAC,aAAa;IAHjC,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAA4E;IAC5G,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAiB;gBAE/B,aAAa,EAAE,aAAa;IAEhD;;;;OAIG;IACI,eAAe,QAAa,QAAQ,oBAAoB,EAAE,CAAC,CAgChE;IAEF;;;;;OAKG;IACI,OAAO,cAAqB,MAAM,KAAG,QAAQ,qBAAqB,CAAC,CA+BxE;IAEF;;;;;OAKG;IACI,SAAS,cAAqB,MAAM,KAAG,QAAQ,uBAAuB,CAAC,CAuB5E;CACL"}
@@ -27,6 +27,10 @@ class ShopifyProductPublicationsService extends AbstractService_1.AbstractServic
27
27
  this.getPublications = () => __awaiter(this, void 0, void 0, function* () {
28
28
  try {
29
29
  Logger_1.Logger.info('Get product publications');
30
+ const cached = ShopifyProductPublicationsService.publicationsCache;
31
+ if (cached && Date.now() - cached.fetchedAt < ShopifyProductPublicationsService.cacheTtlMs) {
32
+ return cached.publications;
33
+ }
30
34
  const query = (0, graphql_tag_1.default) `{
31
35
  publications(first: 15) {
32
36
  edges {
@@ -43,6 +47,10 @@ class ShopifyProductPublicationsService extends AbstractService_1.AbstractServic
43
47
  if (response && response.data && response.data.data && response.data.data.publications) {
44
48
  const productPublicationsGraph = response.data.data.publications.edges;
45
49
  const productPublications = productPublicationsGraph.map((p) => p.node);
50
+ ShopifyProductPublicationsService.publicationsCache = {
51
+ fetchedAt: Date.now(),
52
+ publications: productPublications
53
+ };
46
54
  return productPublications;
47
55
  }
48
56
  else {
@@ -131,4 +139,6 @@ class ShopifyProductPublicationsService extends AbstractService_1.AbstractServic
131
139
  }
132
140
  }
133
141
  exports.ShopifyProductPublicationsService = ShopifyProductPublicationsService;
142
+ ShopifyProductPublicationsService.publicationsCache = null;
143
+ ShopifyProductPublicationsService.cacheTtlMs = 5 * 60 * 1000;
134
144
  //# sourceMappingURL=ShopifyProductPublicationsService.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ShopifyProductPublicationsService.js","sourceRoot":"","sources":["../../../shopify/product/ShopifyProductPublicationsService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qCAAgC;AAChC,6CAA8B;AAC9B,yCAAsC;AACtC,6DAA0D;AAC1D,uEAAgE;AAEhE,MAAa,iCAAkC,SAAQ,iCAAe;IAElE,YAAoB,aAA4B;QAAI,KAAK,EAAE,CAAC;QAAxC,kBAAa,GAAb,aAAa,CAAe;QAEhD;;;;WAIG;QACI,oBAAe,GAAG,GAA0C,EAAE;YACjE,IAAI;gBACA,eAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;gBACxC,MAAM,KAAK,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;cAWf,CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,KAAK,EAAE,IAAA,eAAK,EAAC,KAAK,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC7G,IAAI,QAAQ,IAAI,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;oBACpF,MAAM,wBAAwB,GA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,CAAC,eAAe,EAAE,EAAE,KAAK,EAAE,IAAA,eAAK,EAAC,YAAY,CAAC,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;gBACvJ,IAAI,QAAQ,IAAI,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;oBACxF,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC;iBAC5B;qBAAM;oBACH,MAAM,IAAI,6BAAmB,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;iBACpF;aACJ;YAAC,OAAO,KAAK,EAAE;gBAAE,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;aAAE;QACrD,CAAC,CAAA,CAAC;IArG2D,CAAC;CAsGjE;AAxGD,8EAwGC","sourcesContent":["import { AxiosInstance } from 'axios';\nimport { print } from 'graphql';\nimport gql from 'graphql-tag';\nimport { Logger } from '../../Logger';\nimport { AbstractService } from '../base/AbstractService';\nimport InspiraShopifyError from '../errors/InspiraShopifyError';\n\nexport class ShopifyProductPublicationsService extends AbstractService {\n\n constructor(private axiosInstance: AxiosInstance) { super(); }\n\n /**\n * Returns a max of 15 publications\n * \n * @returns {IProductPublications[]} list of publications in store.\n */\n public getPublications = async (): Promise<IProductPublications[]> => {\n try {\n Logger.info('Get product publications');\n const query = gql`{\n publications(first: 15) {\n edges {\n node {\n id\n name\n autoPublish\n supportsFuturePublishing\n }\n }\n }\n }`;\n const response = await this.axiosInstance.post('/graphql.json', { query: print(query) }, { query_cost: 15 });\n if (response && response.data && response.data.data && response.data.data.publications) {\n const productPublicationsGraph: { node: IProductPublications }[] = response.data.data.publications.edges;\n const productPublications: IProductPublications[] = productPublicationsGraph.map((p) => p.node);\n return productPublications;\n } else {\n throw new InspiraShopifyError({ message: JSON.stringify(response.data.errors) });\n }\n } catch (error) { this.logErrorAndThrow(error); }\n };\n \n /**\n * Publishes product to all publication channels.\n * \n * @param {number} productId \n * @returns {IProductPublishResult}\n */\n public publish = async (productId: number): Promise<IProductPublishResult> => {\n try {\n Logger.info(`Publish product with id ${productId} to all publications`);\n const publishQuery = gql`mutation productPublish($input: ProductPublishInput!) {\n productPublish(input: $input) {\n product {\n id\n }\n productPublications {\n isPublished\n channel {\n name\n }\n }\n userErrors {\n field\n message\n }\n }\n }`;\n const publications = await this.getPublications();\n const inputParams = { id: this.getGraphProductIdFromId(productId), productPublications: publications.map(p => ({ publicationId: p.id})) };\n const response = await this.axiosInstance.post('/graphql.json', { query: print(publishQuery), variables: { input: inputParams } }, { query_cost: 10 });\n if (response && response.data && response.data.data && response.data.data.productPublish) {\n const productPublications: { isPublished: boolean; channel: { name: string;} } []= response.data.data.productPublish.productPublications;\n \n return { id: productId, productPublications: productPublications.filter(pp => pp.isPublished).map(pp => pp.channel) };\n } else {\n throw new InspiraShopifyError({ message: JSON.stringify(response.data.errors) });\n }\n } catch (error) { this.logErrorAndThrow(error); }\n };\n\n /**\n * Unpublishes product to all publication channels.\n * \n * @param {number} productId \n * @returns {IProductUnpublishResult}\n */\n public unPublish = async (productId: number): Promise<IProductUnpublishResult> => {\n try {\n Logger.info(`Unpublish product with id ${productId} to all publications`);\n const publishQuery = gql`mutation productUnpublish($input: ProductUnpublishInput!) {\n productUnpublish(input: $input) {\n product {\n id\n }\n userErrors {\n field\n message\n }\n }\n }`;\n const publications = await this.getPublications();\n const inputParams = { id: this.getGraphProductIdFromId(productId), productPublications: publications.map(p => ({ publicationId: p.id})) };\n const response = await this.axiosInstance.post('/graphql.json', { query: print(publishQuery), variables: { input: inputParams } }, { query_cost: 10 });\n if (response && response.data && response.data.data && response.data.data.productUnpublish) {\n return { id: productId };\n } else {\n throw new InspiraShopifyError({ message: JSON.stringify(response.data.errors) });\n }\n } catch (error) { this.logErrorAndThrow(error); }\n };\n}"]}
1
+ {"version":3,"file":"ShopifyProductPublicationsService.js","sourceRoot":"","sources":["../../../shopify/product/ShopifyProductPublicationsService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qCAAgC;AAChC,6CAA8B;AAC9B,yCAAsC;AACtC,6DAA0D;AAC1D,uEAAgE;AAEhE,MAAa,iCAAkC,SAAQ,iCAAe;IAKlE,YAAoB,aAA4B;QAAI,KAAK,EAAE,CAAC;QAAxC,kBAAa,GAAb,aAAa,CAAe;QAEhD;;;;WAIG;QACI,oBAAe,GAAG,GAA0C,EAAE;YACjE,IAAI;gBACA,eAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;gBACxC,MAAM,MAAM,GAAG,iCAAiC,CAAC,iBAAiB,CAAC;gBACnE,IAAI,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,GAAG,iCAAiC,CAAC,UAAU,EAAE;oBACxF,OAAO,MAAM,CAAC,YAAY,CAAC;iBAC9B;gBACD,MAAM,KAAK,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;cAWf,CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,KAAK,EAAE,IAAA,eAAK,EAAC,KAAK,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC7G,IAAI,QAAQ,IAAI,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;oBACpF,MAAM,wBAAwB,GAAqC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;oBACzG,MAAM,mBAAmB,GAA2B,wBAAwB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC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EAAE,IAAA,eAAK,EAAC,YAAY,CAAC,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;gBACvJ,IAAI,QAAQ,IAAI,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;oBACxF,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC;iBAC5B;qBAAM;oBACH,MAAM,IAAI,6BAAmB,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;iBACpF;aACJ;YAAC,OAAO,KAAK,EAAE;gBAAE,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;aAAE;QACrD,CAAC,CAAA,CAAC;IA7G2D,CAAC;;AALlE,8EAmHC;AAjHkB,mDAAiB,GAAuE,IAAI,CAAC;AACpF,4CAAU,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC","sourcesContent":["import { AxiosInstance } from 'axios';\nimport { print } from 'graphql';\nimport gql from 'graphql-tag';\nimport { Logger } from '../../Logger';\nimport { AbstractService } from '../base/AbstractService';\nimport InspiraShopifyError from '../errors/InspiraShopifyError';\n\nexport class ShopifyProductPublicationsService extends AbstractService {\n\n private static publicationsCache: { fetchedAt: number; publications: IProductPublications[] } | null = null;\n private static readonly cacheTtlMs = 5 * 60 * 1000;\n\n constructor(private axiosInstance: AxiosInstance) { super(); }\n\n /**\n * Returns a max of 15 publications\n * \n * @returns {IProductPublications[]} list of publications in store.\n */\n public getPublications = async (): Promise<IProductPublications[]> => {\n try {\n Logger.info('Get product publications');\n const cached = ShopifyProductPublicationsService.publicationsCache;\n if (cached && Date.now() - cached.fetchedAt < ShopifyProductPublicationsService.cacheTtlMs) {\n return cached.publications;\n }\n const query = gql`{\n publications(first: 15) {\n edges {\n node {\n id\n name\n autoPublish\n supportsFuturePublishing\n }\n }\n }\n }`;\n const response = await this.axiosInstance.post('/graphql.json', { query: print(query) }, { query_cost: 15 });\n if (response && response.data && response.data.data && response.data.data.publications) {\n const productPublicationsGraph: { node: IProductPublications }[] = response.data.data.publications.edges;\n const productPublications: IProductPublications[] = productPublicationsGraph.map((p) => p.node);\n ShopifyProductPublicationsService.publicationsCache = {\n fetchedAt: Date.now(),\n publications: productPublications\n };\n return productPublications;\n } else {\n throw new InspiraShopifyError({ message: JSON.stringify(response.data.errors) });\n }\n } catch (error) { this.logErrorAndThrow(error); }\n };\n \n /**\n * Publishes product to all publication channels.\n * \n * @param {number} productId \n * @returns {IProductPublishResult}\n */\n public publish = async (productId: number): Promise<IProductPublishResult> => {\n try {\n Logger.info(`Publish product with id ${productId} to all publications`);\n const publishQuery = gql`mutation productPublish($input: ProductPublishInput!) {\n productPublish(input: $input) {\n product {\n id\n }\n productPublications {\n isPublished\n channel {\n name\n }\n }\n userErrors {\n field\n message\n }\n }\n }`;\n const publications = await this.getPublications();\n const inputParams = { id: this.getGraphProductIdFromId(productId), productPublications: publications.map(p => ({ publicationId: p.id})) };\n const response = await this.axiosInstance.post('/graphql.json', { query: print(publishQuery), variables: { input: inputParams } }, { query_cost: 10 });\n if (response && response.data && response.data.data && response.data.data.productPublish) {\n const productPublications: { isPublished: boolean; channel: { name: string;} } []= response.data.data.productPublish.productPublications;\n \n return { id: productId, productPublications: productPublications.filter(pp => pp.isPublished).map(pp => pp.channel) };\n } else {\n throw new InspiraShopifyError({ message: JSON.stringify(response.data.errors) });\n }\n } catch (error) { this.logErrorAndThrow(error); }\n };\n\n /**\n * Unpublishes product to all publication channels.\n * \n * @param {number} productId \n * @returns {IProductUnpublishResult}\n */\n public unPublish = async (productId: number): Promise<IProductUnpublishResult> => {\n try {\n Logger.info(`Unpublish product with id ${productId} to all publications`);\n const publishQuery = gql`mutation productUnpublish($input: ProductUnpublishInput!) {\n productUnpublish(input: $input) {\n product {\n id\n }\n userErrors {\n field\n message\n }\n }\n }`;\n const publications = await this.getPublications();\n const inputParams = { id: this.getGraphProductIdFromId(productId), productPublications: publications.map(p => ({ publicationId: p.id})) };\n const response = await this.axiosInstance.post('/graphql.json', { query: print(publishQuery), variables: { input: inputParams } }, { query_cost: 10 });\n if (response && response.data && response.data.data && response.data.data.productUnpublish) {\n return { id: productId };\n } else {\n throw new InspiraShopifyError({ message: JSON.stringify(response.data.errors) });\n }\n } catch (error) { this.logErrorAndThrow(error); }\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sommpicks/sommpicks-shopify",
3
- "version": "24.12.12",
3
+ "version": "24.12.14",
4
4
  "publishConfig": { "access": "restricted" },
5
5
  "description": "Shopify REST API & GraphQL calls",
6
6
  "main": "dist/index.js",
@@ -49,8 +49,9 @@ export class ShopifyUtils {
49
49
  // || (typeof status === 'number' && status >= 500 && status <= 599)
50
50
  // || status === 429;
51
51
  return (axiosRetry as any).isNetworkOrIdempotentRequestError(error) ||
52
- (error.response && error.response.status >= 500 && error.response.status <= 599) ||
53
- (error.response && error.response.status === 429);
52
+ error.code ==='ECONNABORTED'
53
+ || (error.response && error.response.status >= 500 && error.response.status <= 599)
54
+ || (error.response && error.response.status === 429);
54
55
  }
55
56
  });
56
57
  const axiosRateLimit = new AxiosRateLimit(
@@ -7,6 +7,9 @@ import InspiraShopifyError from '../errors/InspiraShopifyError';
7
7
 
8
8
  export class ShopifyProductPublicationsService extends AbstractService {
9
9
 
10
+ private static publicationsCache: { fetchedAt: number; publications: IProductPublications[] } | null = null;
11
+ private static readonly cacheTtlMs = 5 * 60 * 1000;
12
+
10
13
  constructor(private axiosInstance: AxiosInstance) { super(); }
11
14
 
12
15
  /**
@@ -17,6 +20,10 @@ export class ShopifyProductPublicationsService extends AbstractService {
17
20
  public getPublications = async (): Promise<IProductPublications[]> => {
18
21
  try {
19
22
  Logger.info('Get product publications');
23
+ const cached = ShopifyProductPublicationsService.publicationsCache;
24
+ if (cached && Date.now() - cached.fetchedAt < ShopifyProductPublicationsService.cacheTtlMs) {
25
+ return cached.publications;
26
+ }
20
27
  const query = gql`{
21
28
  publications(first: 15) {
22
29
  edges {
@@ -33,6 +40,10 @@ export class ShopifyProductPublicationsService extends AbstractService {
33
40
  if (response && response.data && response.data.data && response.data.data.publications) {
34
41
  const productPublicationsGraph: { node: IProductPublications }[] = response.data.data.publications.edges;
35
42
  const productPublications: IProductPublications[] = productPublicationsGraph.map((p) => p.node);
43
+ ShopifyProductPublicationsService.publicationsCache = {
44
+ fetchedAt: Date.now(),
45
+ publications: productPublications
46
+ };
36
47
  return productPublications;
37
48
  } else {
38
49
  throw new InspiraShopifyError({ message: JSON.stringify(response.data.errors) });
@@ -109,4 +120,4 @@ export class ShopifyProductPublicationsService extends AbstractService {
109
120
  }
110
121
  } catch (error) { this.logErrorAndThrow(error); }
111
122
  };
112
- }
123
+ }