@sommpicks/sommpicks-shopify 24.12.14 → 24.12.15

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.
@@ -0,0 +1,42 @@
1
+ name: Publish Somm_Picks_Shopify
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ publish:
10
+ if: github.actor != 'github-actions[bot]'
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: write
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ with:
17
+ fetch-depth: 0
18
+ - uses: actions/setup-node@v4
19
+ with:
20
+ node-version: '20'
21
+ registry-url: 'https://registry.npmjs.org'
22
+ scope: '@sommpicks'
23
+ - run: npm ci
24
+ - run: npm run build --if-present
25
+ - name: Run tests (if configured)
26
+ run: |
27
+ test_script=$(node -p "(require('./package.json').scripts || {}).test || ''")
28
+ if [ -z "$test_script" ] || echo "$test_script" | grep -qi "no test specified"; then
29
+ echo "Skipping tests"
30
+ else
31
+ npm run test
32
+ fi
33
+ - run: npm version patch --no-git-tag-version
34
+ - run: |
35
+ git config user.name "github-actions[bot]"
36
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
37
+ git add package.json package-lock.json
38
+ git commit -m "ci: bump version [skip ci]"
39
+ git push
40
+ - run: npm publish
41
+ env:
42
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -1 +1 @@
1
- {"version":3,"file":"ShopifyInventoryService.d.ts","sourceRoot":"","sources":["../../shopify/ShopifyInventoryService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAMtC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,uBAAwB,SAAQ,eAAe;IAE5C,OAAO,CAAC,aAAa;gBAAb,aAAa,EAAE,aAAa;IAEhD;;;;;OAKG;IACI,WAAW,gBAAuB,MAAM,aAAa,OAAO,KAAG,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IAEF;;;;;;;OAOG;IACI,wBAAwB,mBAAyB,eAAe,KAAG,QAAQ,QAAQ,CAAC,CAsCzF;CAIL"}
@@ -140,7 +140,9 @@ class ShopifyInventoryService extends AbstractService_1.AbstractService {
140
140
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
141
141
  try {
142
142
  Logger_1.Logger.info(`setQuantity ${qty} in inventory ID ${inventoryId}`);
143
+ const startMs = Date.now();
143
144
  const response = yield this.axiosInstance.post('/inventory_levels/set.json', { location_id: locationId, inventory_item_id: inventoryId, available: qty });
145
+ Logger_1.Logger.info(`setQuantity completed in ${Date.now() - startMs}ms inventory ID ${inventoryId}`);
144
146
  resolve(response.data.inventory_level);
145
147
  }
146
148
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"ShopifyInventoryService.js","sourceRoot":"","sources":["../../shopify/ShopifyInventoryService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,sCAAmC;AACnC,oDAA6C;AAC7C,qCAAgC;AAChC,6CAA8B;AAC9B,sEAA+D;AAC/D,4DAAyD;AAEzD,MAAa,uBAAwB,SAAQ,iCAAe;IAExD,YAAoB,aAA4B;QAAI,KAAK,EAAE,CAAC;QAAxC,kBAAa,GAAb,aAAa,CAAe;QAEhD;;;;;WAKG;QACI,gBAAW,GAAG,CAAO,WAAmB,EAAE,SAAkB,EAA2B,EAAE;YAC5F,OAAO,IAAI,OAAO,CAAiB,CAAO,OAAO,EAAE,MAAM,EAAE,EAAE;gBACzD,IAAI;oBACA,eAAM,CAAC,IAAI,CAAC,sBAAsB,WAAW,EAAE,CAAC,CAAC;oBACjD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,oBAAoB,WAAW,OAAO,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;oBACnJ,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,cAAc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,CAAC;QACP,CAAC,CAAA,CAAC;IAhZ2D,CAAC;CAoZjE;AAtZD,0DAsZC","sourcesContent":["import { AxiosInstance } from 'axios';\nimport { Logger } from '../Logger';\nimport ErrorHelper from './base/ErrorHelper';\nimport { print } from 'graphql';\nimport gql from 'graphql-tag';\nimport InspiraShopifyError from './errors/InspiraShopifyError';\nimport { AbstractService } from './base/AbstractService';\n\nexport class ShopifyInventoryService extends AbstractService {\n\n constructor(private axiosInstance: AxiosInstance) { super(); }\n\n /**\n * \n * @param {number} inventoryId\n * @param {boolean} trackable. Inventory quantity is traqcked by shopify\n * @returns Promise\n */\n public setItemToBe = async (inventoryId: number, trackable: boolean): Promise<IInventoryItem> => {\n return new Promise<IInventoryItem>(async (resolve, reject) => {\n try {\n Logger.info(`setItemToTrackable ${inventoryId}`);\n const response = await this.axiosInstance.put(`/inventory_items/${inventoryId}.json`, { inventory_item: { id: inventoryId, tracked: trackable } });\n resolve(response.data.inventory_item);\n } catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n\n /**\n * Updates Inventory cost per item.\n * \n * @param {number} inventoryId\n * @param {number} cost. New cost per item\n * @returns Promise true if updated correctly\n */\n public setItemCostToBe = async (inventoryId: number, cost: number): Promise<boolean> => {\n const updatedInventoryItem = await this.setMultipleItemCostToBe([{ inventoryId: inventoryId, cost: cost }]);\n return updatedInventoryItem?.length === 1 ? true : false;\n };\n\n /**\n * Updates Inventory cost for multiple Inventory items\n * \n * @param {IIventoryItemCostChangeRequest[]} inventoryCostChanges\n * @returns Promise inventory item IDs updated\n */\n public setMultipleItemCostToBe = async (inventoryCostChanges: IIventoryItemCostChangeRequest[]): Promise<number[]> => {\n return new Promise<number[]>(async (resolve, reject) => {\n try {\n Logger.info(`Change Multiple Inventory costs: ${JSON.stringify(inventoryCostChanges)}`);\n\n const inventoryCostChangeschunks: IIventoryItemCostChangeRequest[][] = this.sliceIntoChunks(inventoryCostChanges, 50);\n\n if(inventoryCostChangeschunks && inventoryCostChangeschunks.length > 0) {\n Logger.info(`Created ${inventoryCostChangeschunks.length} chunks`);\n\n for(const inventoryCostChangeschunk of inventoryCostChangeschunks) {\n const query = gql`mutation {\n ${ inventoryCostChangeschunk.map((iv) => (`\n InventoryItem${iv.inventoryId}: inventoryItemUpdate(id: \"gid://shopify/InventoryItem/${iv.inventoryId}\", input: { cost: ${iv.cost} }) {\n inventoryItem {\n id\n }\n userErrors {\n field\n message\n }\n }`)).join('')\n}\n }`;\n const response = await this.axiosInstance.post('/graphql.json', { query: print(query) }, { query_cost: inventoryCostChangeschunk.length * 10 });\n if(response && response.data?.data){\n Logger.info(`Inventory chunks completed ${JSON.stringify(response.data.data)}`);\n const keys = Object.keys(response.data.data);\n const itemIDsUpdated: number[] = [];\n for(const key of keys) {\n const graphQLItemID = response.data.data[key].inventoryItem?.id;\n if(graphQLItemID){\n itemIDsUpdated.push(this.getIdFromGraphId(graphQLItemID));\n }\n }\n resolve(itemIDsUpdated);\n } else {\n Logger.error(`Inventory chunks failed ${JSON.stringify(response ? response.data : '')}`);\n resolve([]);\n }\n }\n } else {\n Logger.error(`No inventory changes sent! ${JSON.stringify(inventoryCostChanges)}`);\n resolve([]);\n }\n } catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n\n /**\n * Updates Inventory cost & sku per item.\n * \n * @param {number} inventoryId\n * @param {number} cost. New cost per item\n * @param {string} sku. New sku per item\n * @returns Promise\n */\n public setItemCostAndSkuToBe = async (inventoryId: number, cost: number, sku: string): Promise<IInventoryItem> => {\n return new Promise<IInventoryItem>(async (resolve, reject) => {\n try {\n Logger.info(`setItemCostAndSkuToBe ${inventoryId}`);\n const response = await this.axiosInstance.put(`/inventory_items/${inventoryId}.json`, { inventory_item: { id: inventoryId, cost: cost, sku: sku } });\n resolve(response.data.inventory_item);\n } catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n\n /**\n * Sets a quantity to the inventory level\n * \n * @param {number} inventoryId\n * @param {number} qty Absolute amount of Qty\n * @param {number} locationId\n * @returns Promise\n */\n public setQuantity = async (inventoryId: number, qty: number, locationId: number): Promise<IInventoryLevel> => {\n return new Promise<IInventoryLevel>(async (resolve, reject) => {\n try {\n Logger.info(`setQuantity ${qty} in inventory ID ${inventoryId}`);\n const response = await this.axiosInstance.post('/inventory_levels/set.json', { location_id: locationId, inventory_item_id: inventoryId, available: qty });\n resolve(response.data.inventory_level);\n } catch (error) {Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n\n /**\n * Adjusts quantity to the inventory level. So it adds or removes the quantity from the actual value\n * \n * @param {number} inventoryId\n * @param {number} qty Absolute amount of Qty\n * @param {number} locationId\n * @returns Promise\n */\n public adjustQuantity = async (inventoryId: number, qtyToAdjust: number, locationId: number): Promise<IInventoryLevel> => {\n return new Promise<IInventoryLevel>(async (resolve, reject) => {\n try {\n Logger.info(`adjustsQuantity ${qtyToAdjust} in inventory ID ${inventoryId}`);\n const response = await this.axiosInstance.post('/inventory_levels/adjust.json', { location_id: locationId, inventory_item_id: inventoryId, available_adjustment: qtyToAdjust });\n resolve(response.data.inventory_level);\n } catch (error) {Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n\n /**\n * Adjusts quantity to the inventory levels of variant. So it adds or removes the quantity from the actual value.\n * - If quantity is lower than the inventory level. It gets removed from it.\n * - If quantity is bigger from the inventory level but there are more than one level it tries to remove a bit of stock from each level.\n * - If quantity is bigger than the invenotry level and there isn't anymore levels then it removes the stock. A negative value will be placed\n * \n * @param {number} inventoryItemId\n * @param {number} qtyToAdjust Absolute amount of Qty\n * @returns Promise\n */\n public adjustQuantityOfInventoryItem = async (inventoryItemId: number, qtyToAdjust: number): Promise<void> => {\n return new Promise<void>(async (resolve, reject) => {\n try {\n Logger.info(`adjustsQuantity for inventoryItem ${inventoryItemId}`);\n const inventoryLevels = await this.getLevel(inventoryItemId);\n Logger.info(`Inventory levels ${JSON.stringify(inventoryLevels)}`);\n let dynamicQtyToAdjust = parseInt(qtyToAdjust.toString(), 10);\n for(const level of inventoryLevels) {\n if(level.available >= qtyToAdjust) {\n this.setQuantity(level.inventory_item_id, level.available - qtyToAdjust, level.location_id);\n dynamicQtyToAdjust = 0;\n break;\n }\n }\n if(dynamicQtyToAdjust > 0){\n Logger.info('Not enough stock in any of the levels. We will remove it from the first level');\n let levelIndex = 0;\n const levelNumber = inventoryLevels.length;\n for(const level of inventoryLevels) {\n Logger.info(`Level ${JSON.stringify(level)}`);\n if(level.available >= dynamicQtyToAdjust) {\n this.setQuantity(level.inventory_item_id, level.available - dynamicQtyToAdjust, level.location_id);\n dynamicQtyToAdjust = 0;\n Logger.info(`Removing all from 1st level. Missing Qty ${dynamicQtyToAdjust} & ${level.location_id}`);\n break;\n } else if (level.available < dynamicQtyToAdjust && levelIndex !== levelNumber - 1) { \n this.setQuantity(level.inventory_item_id, 0, level.location_id);\n dynamicQtyToAdjust = dynamicQtyToAdjust - level.available;\n Logger.info(`Removing part of it from ${level.inventory_item_id} level. Missing Qty ${dynamicQtyToAdjust} & ${level.location_id}`);\n } else if (level.available < dynamicQtyToAdjust && levelIndex === levelNumber - 1) { \n this.setQuantity(level.inventory_item_id, level.available - dynamicQtyToAdjust, level.location_id);\n dynamicQtyToAdjust = 0;\n Logger.info(`Removing the rest of it from ${level.inventory_item_id} level. Missing Qty ${dynamicQtyToAdjust} & ${level.location_id}`);\n break;\n } else {\n Logger.info('Option of level and stock not detected');\n }\n levelIndex +=1;\n }\n } else {\n Logger.info('All stock removed from one Level');\n }\n resolve();\n } catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n\n public getLevel = async (inventoryId: number): Promise<IInventoryLevel[]> => {\n return new Promise<IInventoryLevel[]>(async (resolve, reject) => {\n try {\n Logger.info(`getLevel for inventory ID ${inventoryId}`);\n const response = await this.axiosInstance.get(`/inventory_levels.json?inventory_item_ids=${inventoryId}`);\n resolve(response.data.inventory_levels);\n } catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n\n /**\n * Returns a list of all iventory Items of the product.\n * \n * @param {IProduct} product\n * @returns Promise\n */\n public getInventoryItemsOfProduct = async (product: IProduct): Promise<IInventoryItemWithVariantGQL[]> => {\n return new Promise<IInventoryItemWithVariantGQL[]>(async (resolve, reject) => {\n try {\n const productID = product ? product.id : 'empty product (no id)';\n Logger.info(`Get Inventory Items for product ID ${productID}`);\n if(!product || !product.variants) {\n Logger.info(`No variants for product ID ${productID}`);\n resolve([]);\n } else {\n const inventoryItemsWithVariant: IInventoryItemWithVariantGQL[] = [];\n const inventoryItemIds = product.variants.map(v => v.inventory_item_id).join(',');\n\n const queryIds = product.variants.map(v => this.getInventoryItemIdFromId(v.inventory_item_id));\n const query = gql` \n query getInventoryItems($queryIds: [ID!]!) { \n nodes(ids: $queryIds) { \n ... on InventoryItem { \n id \n measurement { \n id \n weight { \n unit \n value \n } \n } \n unitCost { \n amount \n currencyCode \n } \n requiresShipping \n tracked\n variant { \n id \n price \n } \n } \n } \n }\n `;\n \n const resp = await this.axiosInstance.post('/graphql.json', { query: print(query), variables: {queryIds: queryIds} });\n const inventoryItems: IInventoryItemGQL[] = resp.data.data.nodes;\n if(inventoryItemIds && inventoryItems.length > 0){\n for(const inventoryItem of inventoryItems) {\n const variant = product.variants.find(v => v.inventory_item_id === this.getIdFromGraphId(inventoryItem.id));\n const inventoryItemWithVariant: IInventoryItemWithVariantGQL = Object.assign(inventoryItem, { variant_price: parseFloat(variant.price), variant_id: variant.id });\n inventoryItemsWithVariant.push(inventoryItemWithVariant);\n }\n }\n Logger.info(`Inventory Items for product ID ${productID} is ${inventoryItemsWithVariant}`);\n resolve(inventoryItemsWithVariant);\n }\n } catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n \n /**\n * Returns a list of all iventory Levels of the product.\n * \n * @param {IProduct} product It must have its variants wioth its inventory items IDs.\n * @returns Promise {IInventoryLevel[]}\n */\n public getInventoryLevelsOfProduct = async (product: IProduct): Promise<IInventoryLevel[]> => {\n try {\n const productID = product ? product.id : 'empty product (no id)';\n Logger.info(`get Inventory Levels for product ID ${productID}`);\n if(!product || !product.variants) {\n Logger.info(`No variants for product ID ${productID}`);\n return [];\n } else {\n const inventoryItemIds = product.variants.map(v => v.inventory_item_id);\n const inventoryLevels: IInventoryLevel[] = await this.getInventoryLevelsOfInventoryItems(inventoryItemIds);\n return inventoryLevels;\n }\n } catch (error) { \n Logger.error('getInventoryLevelsOfProduct - ', error, ErrorHelper.getErrorFromResponse(error));\n throw new InspiraShopifyError(error);\n }\n };\n\n /**\n * Returns a list of all iventory Levels given a list of invenotry item IDs\n * \n * @param {number[]} inventoryItemsIds\n * @returns Promise {IInventoryLevel[]}\n */\n public getInventoryLevelsOfInventoryItems = async (inventoryItemsIds: number[]): Promise<IInventoryLevel[]> => {\n try {\n Logger.info(`get Inventory Levels for inventoryItemsIds ${inventoryItemsIds}`);\n if(!inventoryItemsIds || inventoryItemsIds.length === 0) {\n Logger.info(`No inventoryItemsIds ${inventoryItemsIds}`);\n return [];\n } else {\n const inventoryItemIds = inventoryItemsIds.join(',');\n const response = await this.axiosInstance.get(`/inventory_levels.json?inventory_item_ids=${inventoryItemIds}`);\n const inventoryLevels: IInventoryLevel[] = response.data.inventory_levels;\n return inventoryLevels;\n }\n } catch (error) {\n Logger.error('getInventoryLevelsOfInventoryItems - ', error.message, ErrorHelper.getErrorFromResponse(error));\n throw new InspiraShopifyError(error);\n }\n };\n\n /**\n * Returns a variant that is the parent of a inventory item\n * \n * @param {IInventoryItem} inventoryItem\n * @returns Promise\n */\n public getInventoryItemVariant = async(inventoryItem: IInventoryItem): Promise<IVariant> => {\n return new Promise<IVariant>(async (resolve, reject) => {\n try {\n Logger.info(`Get Inventory Variant for InventoryItem ${inventoryItem.id}`);\n const query = gql` { \n inventoryItem(id: \"gid://shopify/InventoryItem/${inventoryItem.id}\") {\n variant {\n id\n product {\n id\n }\n }\n }\n }`;\n const response = await this.axiosInstance.post('/graphql.json', { query: print(query) }, { query_cost: 3});\n if(response && response.data && response.data.data && response.data.data.inventoryItem && response.data.data.inventoryItem.variant){\n const inventoryItemGraph = response.data.data.inventoryItem;\n if(inventoryItemGraph.variant.length == 0) {\n resolve(null);\n }\n Logger.info(`Variant found with id of ${inventoryItemGraph.variant.id}`);\n inventoryItemGraph.variant.id = this.getIdFromGraphId(inventoryItemGraph.variant.id);\n inventoryItemGraph.variant.product_id = this.getIdFromGraphId(inventoryItemGraph.variant.product.id);\n resolve(inventoryItemGraph.variant);\n } else {\n Logger.error(`getInventoryItemVariant not the expected response. Data ${JSON.stringify(response.data.data)}. Error is ${JSON.stringify(response.data.errors)}` );\n resolve(null);\n }\n } catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n\n /**\n * Returns a variant that is the parent of a inventory level\n * We use the admin_graphql_api_id here as the Inventorylevel webhook kinda sucks and doesn't give us the InventoryLevel id???\n * \n * @param {IInventoryLevel} inventoryLevel\n * @returns Promise\n * TODO: Test (Not used yet)\n */\n public getInventoryLevelVariant = async(inventoryLevel: IInventoryLevel): Promise<IVariant> => {\n return new Promise<IVariant>(async (resolve, reject) => {\n try {\n Logger.info(inventoryLevel);\n Logger.info(`Get Inventory Variant for InventoryLevel ${inventoryLevel.inventory_item_id}`);\n if(inventoryLevel.inventory_item_id === undefined) {\n resolve(null);\n }\n const query = gql` { \n inventoryLevel(id: \"${inventoryLevel.admin_graphql_api_id}\") {\n id\n item{\n variant {\n id\n product {\n id\n }\n }\n }\n }\n }`;\n const response = await this.axiosInstance.post('/graphql.json', { query: print(query) }, { query_cost: 4 });\n Logger.info(response.data.data);\n if(response && response.data && response.data.data && response.data.data.inventoryLevel && response.data.data.inventoryLevel.item.variant){\n const inventoryItemGraph = response.data.data.inventoryLevel;\n if(inventoryItemGraph.item.variant.length == 0) {\n resolve(null);\n }\n Logger.info(`Variant found with id of ${this.getIdFromGraphId(inventoryItemGraph.item.variant.id)}`);\n inventoryItemGraph.item.variant.id = this.getIdFromGraphId(inventoryItemGraph.item.variant.id);\n inventoryItemGraph.item.variant.product_id = this.getIdFromGraphId(inventoryItemGraph.item.variant.product.id);\n resolve(inventoryItemGraph.item.variant);\n } else {\n Logger.error(`getInventoryLevelVariant not the expected response. Data ${JSON.stringify(response.data.data)}. Error is ${JSON.stringify(response.data.errors)}` );\n resolve(null);\n }\n } catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n \n\n\n}\n"]}
1
+ {"version":3,"file":"ShopifyInventoryService.js","sourceRoot":"","sources":["../../shopify/ShopifyInventoryService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,sCAAmC;AACnC,oDAA6C;AAC7C,qCAAgC;AAChC,6CAA8B;AAC9B,sEAA+D;AAC/D,4DAAyD;AAEzD,MAAa,uBAAwB,SAAQ,iCAAe;IAExD,YAAoB,aAA4B;QAAI,KAAK,EAAE,CAAC;QAAxC,kBAAa,GAAb,aAAa,CAAe;QAEhD;;;;;WAKG;QACI,gBAAW,GAAG,CAAO,WAAmB,EAAE,SAAkB,EAA2B,EAAE;YAC5F,OAAO,IAAI,OAAO,CAAiB,CAAO,OAAO,EAAE,MAAM,EAAE,EAAE;gBACzD,IAAI;oBACA,eAAM,CAAC,IAAI,CAAC,sBAAsB,WAAW,EAAE,CAAC,CAAC;oBACjD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,oBAAoB,WAAW,OAAO,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC,C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BACJ;gBAAC,OAAO,KAAK,EAAE;oBAAE,eAAM,CAAC,KAAK,CAAC,KAAK,EAAE,qBAAW,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC;oBAAC,MAAM,CAAC,IAAI,6BAAmB,CAAC,KAAK,CAAC,CAAC,CAAC;iBAAE;YAC7H,CAAC,CAAA,CAAC,CAAC;QACP,CAAC,CAAA,CAAC;IAlZ2D,CAAC;CAsZjE;AAxZD,0DAwZC","sourcesContent":["import { AxiosInstance } from 'axios';\nimport { Logger } from '../Logger';\nimport ErrorHelper from './base/ErrorHelper';\nimport { print } from 'graphql';\nimport gql from 'graphql-tag';\nimport InspiraShopifyError from './errors/InspiraShopifyError';\nimport { AbstractService } from './base/AbstractService';\n\nexport class ShopifyInventoryService extends AbstractService {\n\n constructor(private axiosInstance: AxiosInstance) { super(); }\n\n /**\n * \n * @param {number} inventoryId\n * @param {boolean} trackable. Inventory quantity is traqcked by shopify\n * @returns Promise\n */\n public setItemToBe = async (inventoryId: number, trackable: boolean): Promise<IInventoryItem> => {\n return new Promise<IInventoryItem>(async (resolve, reject) => {\n try {\n Logger.info(`setItemToTrackable ${inventoryId}`);\n const response = await this.axiosInstance.put(`/inventory_items/${inventoryId}.json`, { inventory_item: { id: inventoryId, tracked: trackable } });\n resolve(response.data.inventory_item);\n } catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n\n /**\n * Updates Inventory cost per item.\n * \n * @param {number} inventoryId\n * @param {number} cost. New cost per item\n * @returns Promise true if updated correctly\n */\n public setItemCostToBe = async (inventoryId: number, cost: number): Promise<boolean> => {\n const updatedInventoryItem = await this.setMultipleItemCostToBe([{ inventoryId: inventoryId, cost: cost }]);\n return updatedInventoryItem?.length === 1 ? true : false;\n };\n\n /**\n * Updates Inventory cost for multiple Inventory items\n * \n * @param {IIventoryItemCostChangeRequest[]} inventoryCostChanges\n * @returns Promise inventory item IDs updated\n */\n public setMultipleItemCostToBe = async (inventoryCostChanges: IIventoryItemCostChangeRequest[]): Promise<number[]> => {\n return new Promise<number[]>(async (resolve, reject) => {\n try {\n Logger.info(`Change Multiple Inventory costs: ${JSON.stringify(inventoryCostChanges)}`);\n\n const inventoryCostChangeschunks: IIventoryItemCostChangeRequest[][] = this.sliceIntoChunks(inventoryCostChanges, 50);\n\n if(inventoryCostChangeschunks && inventoryCostChangeschunks.length > 0) {\n Logger.info(`Created ${inventoryCostChangeschunks.length} chunks`);\n\n for(const inventoryCostChangeschunk of inventoryCostChangeschunks) {\n const query = gql`mutation {\n ${ inventoryCostChangeschunk.map((iv) => (`\n InventoryItem${iv.inventoryId}: inventoryItemUpdate(id: \"gid://shopify/InventoryItem/${iv.inventoryId}\", input: { cost: ${iv.cost} }) {\n inventoryItem {\n id\n }\n userErrors {\n field\n message\n }\n }`)).join('')\n}\n }`;\n const response = await this.axiosInstance.post('/graphql.json', { query: print(query) }, { query_cost: inventoryCostChangeschunk.length * 10 });\n if(response && response.data?.data){\n Logger.info(`Inventory chunks completed ${JSON.stringify(response.data.data)}`);\n const keys = Object.keys(response.data.data);\n const itemIDsUpdated: number[] = [];\n for(const key of keys) {\n const graphQLItemID = response.data.data[key].inventoryItem?.id;\n if(graphQLItemID){\n itemIDsUpdated.push(this.getIdFromGraphId(graphQLItemID));\n }\n }\n resolve(itemIDsUpdated);\n } else {\n Logger.error(`Inventory chunks failed ${JSON.stringify(response ? response.data : '')}`);\n resolve([]);\n }\n }\n } else {\n Logger.error(`No inventory changes sent! ${JSON.stringify(inventoryCostChanges)}`);\n resolve([]);\n }\n } catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n\n /**\n * Updates Inventory cost & sku per item.\n * \n * @param {number} inventoryId\n * @param {number} cost. New cost per item\n * @param {string} sku. New sku per item\n * @returns Promise\n */\n public setItemCostAndSkuToBe = async (inventoryId: number, cost: number, sku: string): Promise<IInventoryItem> => {\n return new Promise<IInventoryItem>(async (resolve, reject) => {\n try {\n Logger.info(`setItemCostAndSkuToBe ${inventoryId}`);\n const response = await this.axiosInstance.put(`/inventory_items/${inventoryId}.json`, { inventory_item: { id: inventoryId, cost: cost, sku: sku } });\n resolve(response.data.inventory_item);\n } catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n\n /**\n * Sets a quantity to the inventory level\n * \n * @param {number} inventoryId\n * @param {number} qty Absolute amount of Qty\n * @param {number} locationId\n * @returns Promise\n */\n public setQuantity = async (inventoryId: number, qty: number, locationId: number): Promise<IInventoryLevel> => {\n return new Promise<IInventoryLevel>(async (resolve, reject) => {\n try {\n Logger.info(`setQuantity ${qty} in inventory ID ${inventoryId}`);\n const startMs = Date.now();\n const response = await this.axiosInstance.post('/inventory_levels/set.json', { location_id: locationId, inventory_item_id: inventoryId, available: qty });\n Logger.info(`setQuantity completed in ${Date.now() - startMs}ms inventory ID ${inventoryId}`);\n resolve(response.data.inventory_level);\n } catch (error) {Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n\n /**\n * Adjusts quantity to the inventory level. So it adds or removes the quantity from the actual value\n * \n * @param {number} inventoryId\n * @param {number} qty Absolute amount of Qty\n * @param {number} locationId\n * @returns Promise\n */\n public adjustQuantity = async (inventoryId: number, qtyToAdjust: number, locationId: number): Promise<IInventoryLevel> => {\n return new Promise<IInventoryLevel>(async (resolve, reject) => {\n try {\n Logger.info(`adjustsQuantity ${qtyToAdjust} in inventory ID ${inventoryId}`);\n const response = await this.axiosInstance.post('/inventory_levels/adjust.json', { location_id: locationId, inventory_item_id: inventoryId, available_adjustment: qtyToAdjust });\n resolve(response.data.inventory_level);\n } catch (error) {Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n\n /**\n * Adjusts quantity to the inventory levels of variant. So it adds or removes the quantity from the actual value.\n * - If quantity is lower than the inventory level. It gets removed from it.\n * - If quantity is bigger from the inventory level but there are more than one level it tries to remove a bit of stock from each level.\n * - If quantity is bigger than the invenotry level and there isn't anymore levels then it removes the stock. A negative value will be placed\n * \n * @param {number} inventoryItemId\n * @param {number} qtyToAdjust Absolute amount of Qty\n * @returns Promise\n */\n public adjustQuantityOfInventoryItem = async (inventoryItemId: number, qtyToAdjust: number): Promise<void> => {\n return new Promise<void>(async (resolve, reject) => {\n try {\n Logger.info(`adjustsQuantity for inventoryItem ${inventoryItemId}`);\n const inventoryLevels = await this.getLevel(inventoryItemId);\n Logger.info(`Inventory levels ${JSON.stringify(inventoryLevels)}`);\n let dynamicQtyToAdjust = parseInt(qtyToAdjust.toString(), 10);\n for(const level of inventoryLevels) {\n if(level.available >= qtyToAdjust) {\n this.setQuantity(level.inventory_item_id, level.available - qtyToAdjust, level.location_id);\n dynamicQtyToAdjust = 0;\n break;\n }\n }\n if(dynamicQtyToAdjust > 0){\n Logger.info('Not enough stock in any of the levels. We will remove it from the first level');\n let levelIndex = 0;\n const levelNumber = inventoryLevels.length;\n for(const level of inventoryLevels) {\n Logger.info(`Level ${JSON.stringify(level)}`);\n if(level.available >= dynamicQtyToAdjust) {\n this.setQuantity(level.inventory_item_id, level.available - dynamicQtyToAdjust, level.location_id);\n dynamicQtyToAdjust = 0;\n Logger.info(`Removing all from 1st level. Missing Qty ${dynamicQtyToAdjust} & ${level.location_id}`);\n break;\n } else if (level.available < dynamicQtyToAdjust && levelIndex !== levelNumber - 1) { \n this.setQuantity(level.inventory_item_id, 0, level.location_id);\n dynamicQtyToAdjust = dynamicQtyToAdjust - level.available;\n Logger.info(`Removing part of it from ${level.inventory_item_id} level. Missing Qty ${dynamicQtyToAdjust} & ${level.location_id}`);\n } else if (level.available < dynamicQtyToAdjust && levelIndex === levelNumber - 1) { \n this.setQuantity(level.inventory_item_id, level.available - dynamicQtyToAdjust, level.location_id);\n dynamicQtyToAdjust = 0;\n Logger.info(`Removing the rest of it from ${level.inventory_item_id} level. Missing Qty ${dynamicQtyToAdjust} & ${level.location_id}`);\n break;\n } else {\n Logger.info('Option of level and stock not detected');\n }\n levelIndex +=1;\n }\n } else {\n Logger.info('All stock removed from one Level');\n }\n resolve();\n } catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n\n public getLevel = async (inventoryId: number): Promise<IInventoryLevel[]> => {\n return new Promise<IInventoryLevel[]>(async (resolve, reject) => {\n try {\n Logger.info(`getLevel for inventory ID ${inventoryId}`);\n const response = await this.axiosInstance.get(`/inventory_levels.json?inventory_item_ids=${inventoryId}`);\n resolve(response.data.inventory_levels);\n } catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n\n /**\n * Returns a list of all iventory Items of the product.\n * \n * @param {IProduct} product\n * @returns Promise\n */\n public getInventoryItemsOfProduct = async (product: IProduct): Promise<IInventoryItemWithVariantGQL[]> => {\n return new Promise<IInventoryItemWithVariantGQL[]>(async (resolve, reject) => {\n try {\n const productID = product ? product.id : 'empty product (no id)';\n Logger.info(`Get Inventory Items for product ID ${productID}`);\n if(!product || !product.variants) {\n Logger.info(`No variants for product ID ${productID}`);\n resolve([]);\n } else {\n const inventoryItemsWithVariant: IInventoryItemWithVariantGQL[] = [];\n const inventoryItemIds = product.variants.map(v => v.inventory_item_id).join(',');\n\n const queryIds = product.variants.map(v => this.getInventoryItemIdFromId(v.inventory_item_id));\n const query = gql` \n query getInventoryItems($queryIds: [ID!]!) { \n nodes(ids: $queryIds) { \n ... on InventoryItem { \n id \n measurement { \n id \n weight { \n unit \n value \n } \n } \n unitCost { \n amount \n currencyCode \n } \n requiresShipping \n tracked\n variant { \n id \n price \n } \n } \n } \n }\n `;\n \n const resp = await this.axiosInstance.post('/graphql.json', { query: print(query), variables: {queryIds: queryIds} });\n const inventoryItems: IInventoryItemGQL[] = resp.data.data.nodes;\n if(inventoryItemIds && inventoryItems.length > 0){\n for(const inventoryItem of inventoryItems) {\n const variant = product.variants.find(v => v.inventory_item_id === this.getIdFromGraphId(inventoryItem.id));\n const inventoryItemWithVariant: IInventoryItemWithVariantGQL = Object.assign(inventoryItem, { variant_price: parseFloat(variant.price), variant_id: variant.id });\n inventoryItemsWithVariant.push(inventoryItemWithVariant);\n }\n }\n Logger.info(`Inventory Items for product ID ${productID} is ${inventoryItemsWithVariant}`);\n resolve(inventoryItemsWithVariant);\n }\n } catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n \n /**\n * Returns a list of all iventory Levels of the product.\n * \n * @param {IProduct} product It must have its variants wioth its inventory items IDs.\n * @returns Promise {IInventoryLevel[]}\n */\n public getInventoryLevelsOfProduct = async (product: IProduct): Promise<IInventoryLevel[]> => {\n try {\n const productID = product ? product.id : 'empty product (no id)';\n Logger.info(`get Inventory Levels for product ID ${productID}`);\n if(!product || !product.variants) {\n Logger.info(`No variants for product ID ${productID}`);\n return [];\n } else {\n const inventoryItemIds = product.variants.map(v => v.inventory_item_id);\n const inventoryLevels: IInventoryLevel[] = await this.getInventoryLevelsOfInventoryItems(inventoryItemIds);\n return inventoryLevels;\n }\n } catch (error) { \n Logger.error('getInventoryLevelsOfProduct - ', error, ErrorHelper.getErrorFromResponse(error));\n throw new InspiraShopifyError(error);\n }\n };\n\n /**\n * Returns a list of all iventory Levels given a list of invenotry item IDs\n * \n * @param {number[]} inventoryItemsIds\n * @returns Promise {IInventoryLevel[]}\n */\n public getInventoryLevelsOfInventoryItems = async (inventoryItemsIds: number[]): Promise<IInventoryLevel[]> => {\n try {\n Logger.info(`get Inventory Levels for inventoryItemsIds ${inventoryItemsIds}`);\n if(!inventoryItemsIds || inventoryItemsIds.length === 0) {\n Logger.info(`No inventoryItemsIds ${inventoryItemsIds}`);\n return [];\n } else {\n const inventoryItemIds = inventoryItemsIds.join(',');\n const response = await this.axiosInstance.get(`/inventory_levels.json?inventory_item_ids=${inventoryItemIds}`);\n const inventoryLevels: IInventoryLevel[] = response.data.inventory_levels;\n return inventoryLevels;\n }\n } catch (error) {\n Logger.error('getInventoryLevelsOfInventoryItems - ', error.message, ErrorHelper.getErrorFromResponse(error));\n throw new InspiraShopifyError(error);\n }\n };\n\n /**\n * Returns a variant that is the parent of a inventory item\n * \n * @param {IInventoryItem} inventoryItem\n * @returns Promise\n */\n public getInventoryItemVariant = async(inventoryItem: IInventoryItem): Promise<IVariant> => {\n return new Promise<IVariant>(async (resolve, reject) => {\n try {\n Logger.info(`Get Inventory Variant for InventoryItem ${inventoryItem.id}`);\n const query = gql` { \n inventoryItem(id: \"gid://shopify/InventoryItem/${inventoryItem.id}\") {\n variant {\n id\n product {\n id\n }\n }\n }\n }`;\n const response = await this.axiosInstance.post('/graphql.json', { query: print(query) }, { query_cost: 3});\n if(response && response.data && response.data.data && response.data.data.inventoryItem && response.data.data.inventoryItem.variant){\n const inventoryItemGraph = response.data.data.inventoryItem;\n if(inventoryItemGraph.variant.length == 0) {\n resolve(null);\n }\n Logger.info(`Variant found with id of ${inventoryItemGraph.variant.id}`);\n inventoryItemGraph.variant.id = this.getIdFromGraphId(inventoryItemGraph.variant.id);\n inventoryItemGraph.variant.product_id = this.getIdFromGraphId(inventoryItemGraph.variant.product.id);\n resolve(inventoryItemGraph.variant);\n } else {\n Logger.error(`getInventoryItemVariant not the expected response. Data ${JSON.stringify(response.data.data)}. Error is ${JSON.stringify(response.data.errors)}` );\n resolve(null);\n }\n } catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n\n /**\n * Returns a variant that is the parent of a inventory level\n * We use the admin_graphql_api_id here as the Inventorylevel webhook kinda sucks and doesn't give us the InventoryLevel id???\n * \n * @param {IInventoryLevel} inventoryLevel\n * @returns Promise\n * TODO: Test (Not used yet)\n */\n public getInventoryLevelVariant = async(inventoryLevel: IInventoryLevel): Promise<IVariant> => {\n return new Promise<IVariant>(async (resolve, reject) => {\n try {\n Logger.info(inventoryLevel);\n Logger.info(`Get Inventory Variant for InventoryLevel ${inventoryLevel.inventory_item_id}`);\n if(inventoryLevel.inventory_item_id === undefined) {\n resolve(null);\n }\n const query = gql` { \n inventoryLevel(id: \"${inventoryLevel.admin_graphql_api_id}\") {\n id\n item{\n variant {\n id\n product {\n id\n }\n }\n }\n }\n }`;\n const response = await this.axiosInstance.post('/graphql.json', { query: print(query) }, { query_cost: 4 });\n Logger.info(response.data.data);\n if(response && response.data && response.data.data && response.data.data.inventoryLevel && response.data.data.inventoryLevel.item.variant){\n const inventoryItemGraph = response.data.data.inventoryLevel;\n if(inventoryItemGraph.item.variant.length == 0) {\n resolve(null);\n }\n Logger.info(`Variant found with id of ${this.getIdFromGraphId(inventoryItemGraph.item.variant.id)}`);\n inventoryItemGraph.item.variant.id = this.getIdFromGraphId(inventoryItemGraph.item.variant.id);\n inventoryItemGraph.item.variant.product_id = this.getIdFromGraphId(inventoryItemGraph.item.variant.product.id);\n resolve(inventoryItemGraph.item.variant);\n } else {\n Logger.error(`getInventoryLevelVariant not the expected response. Data ${JSON.stringify(response.data.data)}. Error is ${JSON.stringify(response.data.errors)}` );\n resolve(null);\n }\n } catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }\n });\n };\n \n\n\n}\n"]}
@@ -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;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"}
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,CAAkB;gBAEhC,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"}
@@ -140,5 +140,5 @@ class ShopifyProductPublicationsService extends AbstractService_1.AbstractServic
140
140
  }
141
141
  exports.ShopifyProductPublicationsService = ShopifyProductPublicationsService;
142
142
  ShopifyProductPublicationsService.publicationsCache = null;
143
- ShopifyProductPublicationsService.cacheTtlMs = 5 * 60 * 1000;
143
+ ShopifyProductPublicationsService.cacheTtlMs = 30 * 60 * 1000;
144
144
  //# sourceMappingURL=ShopifyProductPublicationsService.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ShopifyProductPublicationsService.js","sourceRoot":"","sources":["../../../shopify/product/ShopifyProductPublicationsService.ts"],"names":[],"m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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"]}
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,wBAAw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,aAAa,EAAE,CAAC,CAAC,EAAE,EAAC,CAAC,CAAC,EAAE,CAAC;gBAC1I,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,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;IA7G2D,CAAC;;AALlE,8EAmHC;AAjHkB,mDAAiB,GAAuE,IAAI,CAAC;AACpF,4CAAU,GAAG,EAAE,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 = 30 * 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.14",
3
+ "version": "24.12.15",
4
4
  "publishConfig": { "access": "restricted" },
5
5
  "description": "Shopify REST API & GraphQL calls",
6
6
  "main": "dist/index.js",
@@ -123,7 +123,9 @@ export class ShopifyInventoryService extends AbstractService {
123
123
  return new Promise<IInventoryLevel>(async (resolve, reject) => {
124
124
  try {
125
125
  Logger.info(`setQuantity ${qty} in inventory ID ${inventoryId}`);
126
+ const startMs = Date.now();
126
127
  const response = await this.axiosInstance.post('/inventory_levels/set.json', { location_id: locationId, inventory_item_id: inventoryId, available: qty });
128
+ Logger.info(`setQuantity completed in ${Date.now() - startMs}ms inventory ID ${inventoryId}`);
127
129
  resolve(response.data.inventory_level);
128
130
  } catch (error) {Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }
129
131
  });
@@ -8,7 +8,7 @@ import InspiraShopifyError from '../errors/InspiraShopifyError';
8
8
  export class ShopifyProductPublicationsService extends AbstractService {
9
9
 
10
10
  private static publicationsCache: { fetchedAt: number; publications: IProductPublications[] } | null = null;
11
- private static readonly cacheTtlMs = 5 * 60 * 1000;
11
+ private static readonly cacheTtlMs = 30 * 60 * 1000;
12
12
 
13
13
  constructor(private axiosInstance: AxiosInstance) { super(); }
14
14