@things-factory/integration-sellercraft 4.2.5 → 4.2.9

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.
Files changed (28) hide show
  1. package/dist-server/constants/order-status-mapping.js +16 -2
  2. package/dist-server/constants/order-status-mapping.js.map +1 -1
  3. package/dist-server/constants/platform.js +2 -1
  4. package/dist-server/constants/platform.js.map +1 -1
  5. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.js +5 -2
  6. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.js.map +1 -1
  7. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js +2 -2
  8. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js.map +1 -1
  9. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js +5 -4
  10. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js.map +1 -1
  11. package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js +8 -4
  12. package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js.map +1 -1
  13. package/dist-server/routers/sellercraft-router.js +135 -88
  14. package/dist-server/routers/sellercraft-router.js.map +1 -1
  15. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +291 -245
  16. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js.map +1 -1
  17. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js +30 -16
  18. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -1
  19. package/package.json +3 -3
  20. package/server/constants/order-status-mapping.ts +16 -1
  21. package/server/constants/platform.ts +2 -1
  22. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.ts +6 -2
  23. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +2 -2
  24. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.ts +13 -11
  25. package/server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.ts +8 -4
  26. package/server/routers/sellercraft-router.ts +130 -91
  27. package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +343 -283
  28. package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +30 -28
@@ -15,12 +15,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.MarketplaceChannelProductMutation = void 0;
16
16
  const type_graphql_1 = require("type-graphql");
17
17
  const typeorm_1 = require("typeorm");
18
- const marketplace_channel_1 = require("./marketplace-channel");
19
18
  const env_1 = require("@things-factory/env");
20
19
  const integration_marketplace_1 = require("@things-factory/integration-marketplace");
21
20
  const sellercraft_channel_integration_api_1 = require("../../controllers/sellercraft-channel-integration-api");
21
+ const marketplace_channel_1 = require("./marketplace-channel");
22
22
  let MarketplaceChannelProductMutation = class MarketplaceChannelProductMutation {
23
23
  async syncAllMarketplaceChannelProducts(context) {
24
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
24
25
  const sellercraftChannelIntegrationConfig = env_1.config.get('sellercraftChannelIntegrationConfig', {});
25
26
  const { tokenCraftApiKey: apiKey, getShopsTokenCraftUrl } = sellercraftChannelIntegrationConfig;
26
27
  const channels = await (0, typeorm_1.getRepository)(marketplace_channel_1.MarketplaceChannel).find();
@@ -40,11 +41,12 @@ let MarketplaceChannelProductMutation = class MarketplaceChannelProductMutation
40
41
  var shops = shopsResponse.shops;
41
42
  for (var j = 0; j < shops.length; j++) {
42
43
  var store = {
43
- accessKey: shops[j].credential.consumer_key,
44
- accessSecret: shops[j].credential.consumer_secret,
45
- storeURL: shops[j].credential.store_url,
44
+ accessKey: ((_b = (_a = shops[j]) === null || _a === void 0 ? void 0 : _a.credential) === null || _b === void 0 ? void 0 : _b.consumer_key) || '',
45
+ accessSecret: ((_d = (_c = shops[j]) === null || _c === void 0 ? void 0 : _c.credential) === null || _d === void 0 ? void 0 : _d.consumer_secret) || '',
46
+ storeURL: ((_f = (_e = shops[j]) === null || _e === void 0 ? void 0 : _e.credential) === null || _f === void 0 ? void 0 : _f.store_url) || '',
46
47
  platform: channels[i].name,
47
- accessToken: shops[j].credential.access_token // Magento+
48
+ accessToken: (_h = (_g = shops[j]) === null || _g === void 0 ? void 0 : _g.credential) === null || _h === void 0 ? void 0 : _h.access_token,
49
+ channelShopId: (_j = shops[j]) === null || _j === void 0 ? void 0 : _j.channel_shop_id
48
50
  };
49
51
  let countryCode = shops[j].country_code;
50
52
  let channelCode = shops[j].org_prefix;
@@ -68,7 +70,9 @@ let MarketplaceChannelProductMutation = class MarketplaceChannelProductMutation
68
70
  let totalPagesCategory = 1;
69
71
  let limitCategory = 100;
70
72
  for (let page = 0; page < totalPagesCategory; page++) {
71
- const { results, total } = await integration_marketplace_1.StoreAPI.getStoreProductCategories(store, { pagination: { page, limitCategory } });
73
+ const { results, total } = await integration_marketplace_1.StoreAPI.getStoreProductCategories(store, {
74
+ pagination: { page, limitCategory }
75
+ });
72
76
  totalPagesCategory = Math.ceil(total / limitCategory);
73
77
  categoryResult.push(...results);
74
78
  }
@@ -76,7 +80,7 @@ let MarketplaceChannelProductMutation = class MarketplaceChannelProductMutation
76
80
  var _a;
77
81
  let { categoryId, itemId: productId, name, brand, isVerified, images, attributes, variations } = item;
78
82
  variations = variations.map(variation => {
79
- let { variationSku, variationId, name, isEnabled: isEnabled, isEnabled: isSellable, attributes, stockLocked, qty: stockReported, costPrice: fullPrice, sellPrice: priceDiscounted, length, width, height, weight } = variation;
83
+ let { variationSku, variationId, name, isEnabled: isEnabled, isSellable: isSellable, attributes, stockLocked, qty: stockReported, costPrice: fullPrice, sellPrice: priceDiscounted, length, width, height, weight } = variation;
80
84
  return {
81
85
  variationSku,
82
86
  variationId,
@@ -140,16 +144,26 @@ let MarketplaceChannelProductMutation = class MarketplaceChannelProductMutation
140
144
  childrenCategories: []
141
145
  };
142
146
  });
143
- mappedCategories = mappedCategories.map(category => {
144
- if (mappedCategories.filter(e => e.parent == category.categoryId).length > 0) {
145
- category.childrenCategories = mappedCategories.filter(e => e.parent == category.categoryId);
147
+ try {
148
+ mappedCategories = mappedCategories.map(category => {
149
+ if (mappedCategories.filter(e => e.parent == category.categoryId).length > 0) {
150
+ category.childrenCategories = mappedCategories.filter(e => e.parent == category.categoryId);
151
+ }
152
+ return category;
153
+ });
154
+ await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelCategories(sellercraftStore, {
155
+ categories: mappedCategories
156
+ });
157
+ }
158
+ catch (e) { }
159
+ try {
160
+ for (let k = 0, l = mappedProducts.length; k < l; k++) {
161
+ await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelProduct(sellercraftStore, {
162
+ products: [mappedProducts[k]]
163
+ });
146
164
  }
147
- return category;
148
- });
149
- await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelCategories(sellercraftStore, {
150
- categories: mappedCategories
151
- });
152
- await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelProduct(sellercraftStore, { products: mappedProducts });
165
+ }
166
+ catch (e) { }
153
167
  }
154
168
  return true;
155
169
  }
@@ -1 +1 @@
1
- {"version":3,"file":"marketplace-channel-product-mutation.js","sourceRoot":"","sources":["../../../server/service/marketplace-channel/marketplace-channel-product-mutation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAAsD;AACtD,qCAAuC;AAEvC,+DAA0D;AAE1D,6CAA4C;AAC5C,qFAAkE;AAClE,+GAAwG;AAGxG,IAAa,iCAAiC,GAA9C,MAAa,iCAAiC;IAE5C,KAAK,CAAC,iCAAiC,CAAQ,OAAY;QACzD,MAAM,mCAAmC,GAAG,YAAM,CAAC,GAAG,CAAC,qCAAqC,EAAE,EAAE,CAAC,CAAA;QACjG,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,qBAAqB,EAAE,GAAG,mCAAmC,CAAA;QAE/F,MAAM,QAAQ,GAAyB,MAAM,IAAA,uBAAa,EAAC,wCAAkB,CAAC,CAAC,IAAI,EAA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,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAA;qBAC5F;oBACD,OAAO,QAAQ,CAAA;gBACjB,CAAC,CAAC,CAAA;gBAEF,MAAM,sEAAgC,CAAC,uBAAuB,CAAC,gBAAgB,EAAE;oBAC/E,UAAU,EAAE,gBAAgB;iBAC7B,CAAC,CAAA;gBAEF,MAAM,sEAAgC,CAAC,oBAAoB,CAAC,gBAAgB,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC,CAAA;aAC5G;YAED,OAAO,IAAI,CAAA;SACZ;IACH,CAAC;CACF,CAAA;AAjLC;IADC,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC;IACY,WAAA,IAAA,kBAAG,GAAE,CAAA;;;;0FAgL7C;AAlLU,iCAAiC;IAD7C,IAAA,uBAAQ,GAAE;GACE,iCAAiC,CAmL7C;AAnLY,8EAAiC"}
1
+ {"version":3,"file":"marketplace-channel-product-mutation.js","sourceRoot":"","sources":["../../../server/service/marketplace-channel/marketplace-channel-product-mutation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAAsD;AACtD,qCAAuC;AAEvC,6CAA4C;AAC5C,qFAAkE;AAElE,+GAAwG;AACxG,+DAA0D;AAG1D,IAAa,iCAAiC,GAA9C,MAAa,iCAAiC;IAE5C,KAAK,CAAC,iCAAiC,CAAQ,OAAY;;QACzD,MAAM,mCAAmC,GAAG,YAAM,CAAC,GAAG,CAAC,qCAAqC,EAAE,EAAE,CAAC,CAAA;QACjG,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,qBAAqB,EAAE,GAAG,mCAAmC,CAAA;QAE/F,MAAM,QAAQ,GAAyB,MAAM,IAAA,uBAAa,EAAC,wCAAkB,CAAC,CAAC,IAAI,EAAE,CAAA;QAErF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE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,CAAC,EAAE;4BAC5E,QAAQ,CAAC,kBAAkB,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAA;yBAC5F;wBACD,OAAO,QAAQ,CAAA;oBACjB,CAAC,CAAC,CAAA;oBAEF,MAAM,sEAAgC,CAAC,uBAAuB,CAAC,gBAAgB,EAAE;wBAC/E,UAAU,EAAE,gBAAgB;qBAC7B,CAAC,CAAA;iBACH;gBAAC,OAAO,CAAC,EAAE,GAAE;gBAEd,IAAI;oBACF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;wBACrD,MAAM,sEAAgC,CAAC,oBAAoB,CAAC,gBAAgB,EAAE;4BAC5E,QAAQ,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;yBAC9B,CAAC,CAAA;qBACH;iBACF;gBAAC,OAAO,CAAC,EAAE,GAAE;aACf;YAED,OAAO,IAAI,CAAA;SACZ;IACH,CAAC;CACF,CAAA;AAnLC;IADC,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC;IACY,WAAA,IAAA,kBAAG,GAAE,CAAA;;;;0FAkL7C;AApLU,iCAAiC;IAD7C,IAAA,uBAAQ,GAAE;GACE,iCAAiC,CAqL7C;AArLY,8EAAiC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/integration-sellercraft",
3
- "version": "4.2.5",
3
+ "version": "4.2.9",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -31,7 +31,7 @@
31
31
  "@things-factory/context-ui": "^4.1.40",
32
32
  "@things-factory/grist-ui": "^4.1.40",
33
33
  "@things-factory/i18n-base": "^4.1.40",
34
- "@things-factory/integration-marketplace": "^4.2.5",
34
+ "@things-factory/integration-marketplace": "^4.2.9",
35
35
  "@things-factory/integration-ui": "^4.1.40",
36
36
  "@things-factory/more-ui": "^4.1.40",
37
37
  "@things-factory/resource-ui": "^4.1.40",
@@ -51,5 +51,5 @@
51
51
  "nock": "^13.0.2",
52
52
  "should": "^13.2.3"
53
53
  },
54
- "gitHead": "e1447c2e0c5c1ad9375e84291f688b7ecdbeee40"
54
+ "gitHead": "1d2a0b987ce31cc207e1c70e75d53ba65acee61a"
55
55
  }
@@ -6,5 +6,20 @@ export const ORDER_STATUS = {
6
6
  canceled: 'CANCELLED',
7
7
  refunded: 'REFUND_COMPLETE',
8
8
  failed: 'SHIPMENT_LOST_OR_DAMAGED',
9
- refund: 'REFUND_COMPLETE'
9
+ refund: 'REFUND_COMPLETE',
10
+ ttk_100: 'PAYMENT_PENDING', // UNPAID
11
+ ttk_111: 'CONFIRMED', // AWAITING_SHIPMENT
12
+ ttk_112: 'READY_TO_SHIP', // AWAITING_COLLECTION
13
+ ttk_121: 'SHIPPED', // IN_TRANSIT
14
+ ttk_122: 'DELIVERED', // DELIVERED
15
+ ttk_130: 'CLOSED', // COMPLETED
16
+ ttk_140: 'CANCELLED', // CANCELLED
17
+ ttk_201: 'INITIATED_CANCELLATION', // CANCEL_PENDING
18
+ ttk_202: '', // CANCEL_REJECT
19
+ ttk_203: 'CANCELLED' // CANCEL_COMPLETED
20
+ }
21
+
22
+ export const SHIPPING_TYPE = {
23
+ DROP_SHIPPING: 'DROP_SHIPPING',
24
+ CROSS_DOCKING_PICKUP: 'CROSS_DOCKING_PICKUP'
10
25
  }
@@ -1,4 +1,5 @@
1
1
  export const PLATFORM = {
2
2
  WCM: 'woocommerce',
3
- MGT: 'magento'
3
+ MGT: 'magento',
4
+ TTK: 'tiktok'
4
5
  }
@@ -38,10 +38,10 @@ export function ingestChannelOrderPackage() {
38
38
  name: shipper_last_mile.name
39
39
  }
40
40
 
41
- return {
41
+ let newOrderPackage: any = {
42
42
  channel_shop_id,
43
43
  native_order_id,
44
- native_package_id,
44
+ native_package_id: native_package_id.toString(),
45
45
  shipping_tracking_code,
46
46
  shipping_type_value,
47
47
  warehouse_code,
@@ -50,6 +50,10 @@ export function ingestChannelOrderPackage() {
50
50
  shipper_last_mile,
51
51
  order_item_ids
52
52
  }
53
+
54
+ return {
55
+ payload: { ...newOrderPackage }
56
+ }
53
57
  },
54
58
  normalize(res) {
55
59
  return res
@@ -13,7 +13,7 @@ export function ingestChannelOrder() {
13
13
  return {
14
14
  organisation_id: order.organisationId,
15
15
  channel_shop_id: order.channelShopId,
16
- native_order_id: order.id,
16
+ native_order_id: order.id.toString(),
17
17
  ordered_at_date: new Date(order.createdAt).toISOString(),
18
18
  ordered_at_time: new Date(order.createdAt).toISOString(),
19
19
  updated_at_date: new Date(order.updatedAt).toISOString(),
@@ -58,7 +58,7 @@ export function ingestChannelOrder() {
58
58
  ordered_at_time: new Date(order.createdAt).toISOString(),
59
59
  updated_at_date: new Date(order.updatedAt).toISOString(),
60
60
  updated_at_time: new Date(order.updatedAt).toISOString(),
61
- sla_expires_at: order?.slaExpiresAt,
61
+ sla_expires_at: orderItem?.slaExpiresAt ? new Date(orderItem.slaExpiresAt).toISOString() : null,
62
62
  charges: orderItem.charges.map(charge => {
63
63
  return {
64
64
  charge_type_value: charge.name,
@@ -66,17 +66,19 @@ export function ingestChannelProduct() {
66
66
  brand: product.brand || '',
67
67
  is_verified: product.isVerified || true,
68
68
  flexible_attributes: product.channelCode == 'WCM' || product.channelCode == 'MGT' ? true : false, // add channels that do not support category_attributes ingestion
69
- images: product?.images.map(image => {
70
- return {
71
- file_url: image.url
72
- }
73
- }),
74
- product_attributes: product?.attributes.map(attribute => {
75
- return {
76
- ...attribute,
77
- native_attribute_id: attribute.native_attribute_id.toString()
78
- }
79
- }),
69
+ images:
70
+ product?.images?.map(image => {
71
+ return {
72
+ file_url: image.url
73
+ }
74
+ }) || [],
75
+ product_attributes:
76
+ product?.attributes?.map(attribute => {
77
+ return {
78
+ ...attribute,
79
+ native_attribute_id: attribute.native_attribute_id.toString()
80
+ }
81
+ }) || [],
80
82
  variants: productVariations,
81
83
  has_all_variants: product.channelCode == 'MGT' ? false : true
82
84
  }
@@ -44,9 +44,11 @@ export class SellercraftChannelIntegration {
44
44
  })
45
45
 
46
46
  if (response.ok) {
47
- return await response.json()
47
+ const result = await response.json()
48
+ return result
48
49
  } else {
49
- throw new Error(`response code - ${response.status}, ${response.statusText}`)
50
+ const result = await response.json()
51
+ throw new Error(`(${response.status}) ${result.message}`)
50
52
  }
51
53
  }
52
54
 
@@ -71,7 +73,8 @@ export class SellercraftChannelIntegration {
71
73
  if (response.ok) {
72
74
  return await response.json()
73
75
  } else {
74
- throw new Error(`response code - ${response.status}, ${response.statusText}`)
76
+ const result = await response.json()
77
+ throw new Error(`(${response.status}) ${result.message}`)
75
78
  }
76
79
  }
77
80
 
@@ -100,7 +103,8 @@ export class SellercraftChannelIntegration {
100
103
  if (response.ok) {
101
104
  return await response.json()
102
105
  } else {
103
- throw new Error(`response code - ${response.status}, ${response.statusText}`)
106
+ const result = await response.json()
107
+ throw new Error(`(${response.status}) ${result.message}`)
104
108
  }
105
109
  }
106
110
  }
@@ -2,6 +2,7 @@ import Router from 'koa-router'
2
2
 
3
3
  import { config } from '@things-factory/env'
4
4
  import { StoreAPI } from '@things-factory/integration-marketplace'
5
+
5
6
  import { PLATFORM } from '../constants'
6
7
 
7
8
  const debug = require('debug')('things-factory:integration-sellercraft:sellercraft-router')
@@ -36,36 +37,45 @@ sellercraftRouter.post('/sellercraft/store/update-product-price', async (context
36
37
  }
37
38
 
38
39
  let mappedStore: any = {
39
- accessKey: store.shop.credential.consumer_key,
40
- accessSecret: store.shop.credential.consumer_secret,
41
- storeURL: store.shop.credential.store_url,
40
+ accessKey: store.shop?.credential?.consumer_key || '',
41
+ accessSecret: store.shop?.credential?.consumer_secret || '',
42
+ storeURL: store.shop?.credential?.store_url,
42
43
  platform: PLATFORM[`${store.shop.org_prefix}`],
43
- accessToken: store.shop.credential.access_token
44
+ accessToken: store.shop?.credential?.access_token,
45
+ channelShopId: store.shop?.channel_shop_id
44
46
  }
45
47
 
46
- if (requestBody[i].native_variant_id != requestBody[i].native_product_id) {
47
- const req = {
48
- costPrice: requestBody[i].full_price,
49
- sellPrice: requestBody[i].sale_price,
50
- productId: requestBody[i].native_product_id,
51
- variationId: requestBody[i].native_variant_id,
52
- variationSku: requestBody[i].sku
53
- }
54
- result = await StoreAPI.updateStoreProductVariationPrice(mappedStore, req)
55
- } else {
56
- const req = {
57
- costPrice: requestBody[i].full_price,
58
- sellPrice: requestBody[i].sale_price,
59
- productId: requestBody[i].native_product_id,
60
- variationSku: requestBody[i].sku
48
+ try {
49
+ if (requestBody[i].native_variant_id != requestBody[i].native_product_id) {
50
+ const req = {
51
+ costPrice: requestBody[i].full_price,
52
+ sellPrice: requestBody[i].sale_price,
53
+ productId: requestBody[i].native_product_id,
54
+ variationId: requestBody[i].native_variant_id,
55
+ variationSku: requestBody[i].sku
56
+ }
57
+ result = await StoreAPI.updateStoreProductVariationPrice(mappedStore, req)
58
+ } else {
59
+ const req = {
60
+ costPrice: requestBody[i].full_price,
61
+ sellPrice: requestBody[i].sale_price,
62
+ productId: requestBody[i].native_product_id,
63
+ variationSku: requestBody[i].sku
64
+ }
65
+ result = await StoreAPI.updateStoreProductPrice(mappedStore, req)
61
66
  }
62
- result = await StoreAPI.updateStoreProductPrice(mappedStore, req)
63
- }
64
67
 
65
- debug(result)
66
- }
68
+ debug(result)
67
69
 
68
- context.status = 200
70
+ context.type = 'application/json'
71
+ context.status = 200
72
+ context.body = 'Succeeded'
73
+ } catch (e) {
74
+ context.type = 'application/json'
75
+ context.status = 500
76
+ context.body = e.message
77
+ }
78
+ }
69
79
  })
70
80
 
71
81
  sellercraftRouter.post('/sellercraft/store/update-product-stock', async (context, next) => {
@@ -95,82 +105,103 @@ sellercraftRouter.post('/sellercraft/store/update-product-stock', async (context
95
105
  }
96
106
 
97
107
  let mappedStore: any = {
98
- accessKey: store.shop.credential.consumer_key,
99
- accessSecret: store.shop.credential.consumer_secret,
100
- storeURL: store.shop.credential.store_url,
108
+ accessKey: store.shop?.credential?.consumer_key || '',
109
+ accessSecret: store.shop?.credential?.consumer_secret || '',
110
+ storeURL: store.shop?.credential?.store_url,
101
111
  platform: PLATFORM[`${store.shop.org_prefix}`],
102
- accessToken: store.shop.credential.access_token
112
+ accessToken: store.shop?.credential?.access_token,
113
+ channelShopId: store.shop?.channel_shop_id
103
114
  }
104
115
 
105
- if (requestBody[i].native_variant_id != requestBody[i].native_product_id) {
106
- const req = {
107
- qty: requestBody[i].stock,
108
- itemId: requestBody[i].native_product_id,
109
- variationId: requestBody[i].native_variant_id,
110
- distributors: requestBody[i].distributors || [], // for Magento
111
- variationSku: requestBody[i].sku
112
- }
113
- result = await StoreAPI.updateStoreProductVariationStock(mappedStore, req)
114
- } else {
115
- const req = {
116
- qty: requestBody[i].stock,
117
- itemId: requestBody[i].native_product_id,
118
- distributors: requestBody[i].distributors || [], // for Magento
119
- variationSku: requestBody[i].sku
116
+ try {
117
+ if (requestBody[i].native_variant_id != requestBody[i].native_product_id) {
118
+ const req = {
119
+ qty: requestBody[i].stock,
120
+ itemId: requestBody[i].native_product_id,
121
+ variationId: requestBody[i].native_variant_id,
122
+ distributors: requestBody[i].distributors || [], // for Magento
123
+ variationSku: requestBody[i].sku
124
+ }
125
+ result = await StoreAPI.updateStoreProductVariationStock(mappedStore, req)
126
+ } else {
127
+ const req = {
128
+ qty: requestBody[i].stock,
129
+ itemId: requestBody[i].native_product_id,
130
+ distributors: requestBody[i].distributors || [], // for Magento
131
+ variationSku: requestBody[i].sku
132
+ }
133
+ result = await StoreAPI.updateStoreProductStock(mappedStore, req)
120
134
  }
121
- result = await StoreAPI.updateStoreProductStock(mappedStore, req)
122
- }
123
135
 
124
- debug(result)
136
+ debug(result)
137
+
138
+ context.type = 'application/json'
139
+ context.status = 200
140
+ context.body = 'Succeeded'
141
+ } catch (e) {
142
+ context.type = 'application/json'
143
+ context.status = 500
144
+ context.body = e.message
145
+ }
125
146
  }
126
- context.status = 200
127
147
  })
128
148
 
129
149
  sellercraftRouter.post('/sellercraft/store/update-order-status', async (context, next) => {
130
- const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
131
- const { tokenCraftApiKey: apiKey, tokenCraftUrl } = sellercraftChannelIntegrationConfig
150
+ try {
151
+ const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
152
+ const { tokenCraftApiKey: apiKey, tokenCraftUrl } = sellercraftChannelIntegrationConfig
132
153
 
133
- const xApiKey = context.headers['x-api-key']
154
+ const xApiKey = context.headers['x-api-key']
134
155
 
135
- if (apiKey !== xApiKey) context.throw(400, 'api key validation failed')
156
+ if (apiKey !== xApiKey) context.throw(400, 'api key validation failed')
136
157
 
137
- const requestBody = context.request.body
138
- var result
139
- var store: any = {}
158
+ const requestBody = context.request.body
159
+ var result
160
+ var store: any = {}
140
161
 
141
- // https://staging-tokencraft.sellercraft.co/v1/get-shop?channel_id=4bfb3362-d57c-47f8-8781-007316d179bf&shop_id=dd9cf3b7-114f-4d74-a7e2-7b524ae086f2
142
- var fullPath = `${tokenCraftUrl}?channel_id=${requestBody.channel_id}&shop_id=${requestBody.shop_id}`
143
- const response: any = await fetch(fullPath, {
144
- method: 'get',
145
- headers: {
146
- 'Content-Type': 'application/json',
147
- 'x-api-key': apiKey
162
+ // https://staging-tokencraft.sellercraft.co/v1/get-shop?channel_id=4bfb3362-d57c-47f8-8781-007316d179bf&shop_id=dd9cf3b7-114f-4d74-a7e2-7b524ae086f2
163
+ var fullPath = `${tokenCraftUrl}?channel_id=${requestBody.channel_id}&shop_id=${requestBody.shop_id}`
164
+ const response: any = await fetch(fullPath, {
165
+ method: 'get',
166
+ headers: {
167
+ 'Content-Type': 'application/json',
168
+ 'x-api-key': apiKey
169
+ }
170
+ })
171
+ if (response.ok) {
172
+ store = await response.json()
148
173
  }
149
- })
150
- if (response.ok) {
151
- store = await response.json()
152
- }
153
174
 
154
- let mappedStore: any = {
155
- accessKey: store.shop.credential.consumer_key,
156
- accessSecret: store.shop.credential.consumer_secret,
157
- storeURL: store.shop.credential.store_url,
158
- platform: PLATFORM[`${store.shop.org_prefix}`],
159
- accessToken: store.shop.credential.access_token
160
- }
161
-
162
- const reqBody = {
163
- orderId: requestBody.native_order_id,
164
- status: requestBody.order_status,
165
- carrier: requestBody?.shipper_last_mile,
166
- trackingNo: requestBody?.tracking_number,
167
- orderItems: requestBody?.order_item_ids
168
- }
175
+ let mappedStore: any = {
176
+ accessKey: store.shop?.credential?.consumer_key || '',
177
+ accessSecret: store.shop?.credential?.consumer_secret || '',
178
+ storeURL: store.shop?.credential?.store_url,
179
+ platform: PLATFORM[`${store.shop.org_prefix}`],
180
+ accessToken: store.shop?.credential?.access_token,
181
+ channelShopId: store.shop?.channel_shop_id
182
+ }
169
183
 
170
- result = await StoreAPI.updateOrderStatus(mappedStore, reqBody)
171
- debug(result)
184
+ const reqBody = {
185
+ orderId: requestBody.native_order_id,
186
+ status: requestBody.order_status,
187
+ carrier: requestBody?.shipper_last_mile,
188
+ trackingNo: requestBody?.tracking_number,
189
+ orderItems: requestBody?.order_item_ids
190
+ }
172
191
 
173
- context.status = 200
192
+ try {
193
+ result = await StoreAPI.updateOrderStatus(mappedStore, reqBody)
194
+ debug(result)
195
+
196
+ context.type = 'application/json'
197
+ context.status = 200
198
+ context.body = 'Succeeded'
199
+ } catch (e) {
200
+ context.type = 'application/json'
201
+ context.status = 500
202
+ context.body = e.message
203
+ }
204
+ } catch (e) {}
174
205
  })
175
206
 
176
207
  sellercraftRouter.post('/sellercraft/store/update-product-attribute', async (context, next) => {
@@ -198,11 +229,12 @@ sellercraftRouter.post('/sellercraft/store/update-product-attribute', async (con
198
229
  }
199
230
 
200
231
  let mappedStore: any = {
201
- accessKey: store.shop.credential.consumer_key,
202
- accessSecret: store.shop.credential.consumer_secret,
203
- storeURL: store.shop.credential.store_url,
232
+ accessKey: store.shop?.credential?.consumer_key || '',
233
+ accessSecret: store.shop?.credential?.consumer_secret || '',
234
+ storeURL: store.shop?.credential?.store_url,
204
235
  platform: PLATFORM[`${store.shop.org_prefix}`],
205
- accessToken: store.shop.credential.access_token
236
+ accessToken: store.shop?.credential?.access_token,
237
+ channelShopId: store.shop?.channel_shop_id
206
238
  }
207
239
 
208
240
  let { product_sku: productSku, native_product_id: itemId, variants } = requestBody
@@ -228,9 +260,16 @@ sellercraftRouter.post('/sellercraft/store/update-product-attribute', async (con
228
260
  })
229
261
 
230
262
  for (var i = 0; i < variants.length; i++) {
231
- let variant = variants[i]
232
- await StoreAPI.updateProductAttribute(mappedStore, { productSku, itemId, variant })
263
+ try {
264
+ let variant = variants[i]
265
+ await StoreAPI.updateProductAttribute(mappedStore, { productSku, itemId, variant })
266
+ context.type = 'application/json'
267
+ context.status = 200
268
+ context.body = 'Succeeded'
269
+ } catch (e) {
270
+ context.type = 'application/json'
271
+ context.status = 500
272
+ context.body = e.message
273
+ }
233
274
  }
234
-
235
- context.status = 200
236
275
  })