@things-factory/integration-sellercraft 5.0.14 → 6.0.0-alpha.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. package/dist-server/controllers/sellercraft/sellercraft.js +6 -6
  2. package/dist-server/controllers/sellercraft/sellercraft.js.map +1 -1
  3. package/dist-server/controllers/sellercraft-api/decorators.js +12 -6
  4. package/dist-server/controllers/sellercraft-api/decorators.js.map +1 -1
  5. package/dist-server/controllers/sellercraft-api/index.js +2 -2
  6. package/dist-server/controllers/sellercraft-api/index.js.map +1 -1
  7. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js +5 -3
  8. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js.map +1 -1
  9. package/dist-server/controllers/sellercraft-channel-integration-api/index.js +2 -2
  10. package/dist-server/controllers/sellercraft-channel-integration-api/index.js.map +1 -1
  11. package/dist-server/routers/sellercraft-router.js +29 -3
  12. package/dist-server/routers/sellercraft-router.js.map +1 -1
  13. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +294 -258
  14. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js.map +1 -1
  15. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js +59 -16
  16. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -1
  17. package/dist-server/service/marketplace-channel/marketplace-channel.js +8 -4
  18. package/dist-server/service/marketplace-channel/marketplace-channel.js.map +1 -1
  19. package/dist-server/service/sellercraft/sellercraft-mutation.js +6 -4
  20. package/dist-server/service/sellercraft/sellercraft-mutation.js.map +1 -1
  21. package/dist-server/service/sellercraft/sellercraft-query.js +6 -8
  22. package/dist-server/service/sellercraft/sellercraft-query.js.map +1 -1
  23. package/dist-server/service/sellercraft/sellercraft.js +8 -4
  24. package/dist-server/service/sellercraft/sellercraft.js.map +1 -1
  25. package/dist-server/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +16 -16
  27. package/server/controllers/sellercraft/sellercraft.ts +6 -6
  28. package/server/controllers/sellercraft-api/decorators.ts +11 -6
  29. package/server/controllers/sellercraft-api/index.ts +1 -1
  30. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +5 -3
  31. package/server/controllers/sellercraft-channel-integration-api/index.ts +1 -1
  32. package/server/routers/sellercraft-router.ts +45 -4
  33. package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +348 -310
  34. package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +78 -17
  35. package/server/service/marketplace-channel/marketplace-channel.ts +4 -0
  36. package/server/service/sellercraft/sellercraft-mutation.ts +17 -9
  37. package/server/service/sellercraft/sellercraft-query.ts +7 -8
  38. package/server/service/sellercraft/sellercraft.ts +5 -1
@@ -34,8 +34,8 @@ class Sellercraft {
34
34
  return await response.json();
35
35
  }
36
36
  else {
37
- const result = await response.json();
38
- throw new Error(`(${response.status}) ${result.message}`);
37
+ const result = await response.text();
38
+ throw new Error(`(${response.status}) ${result}`);
39
39
  }
40
40
  }
41
41
  async put(path, data = {}) {
@@ -57,8 +57,8 @@ class Sellercraft {
57
57
  return await response.json();
58
58
  }
59
59
  else {
60
- const result = await response.json();
61
- throw new Error(`(${response.status}) ${result.message}`);
60
+ const result = await response.text();
61
+ throw new Error(`(${response.status}) ${result}`);
62
62
  }
63
63
  }
64
64
  async get(path, data = {}) {
@@ -82,8 +82,8 @@ class Sellercraft {
82
82
  return await response.json();
83
83
  }
84
84
  else {
85
- const result = await response.json();
86
- throw new Error(`(${response.status}) ${result.message}`);
85
+ const result = await response.text();
86
+ throw new Error(`(${response.status}) ${result}`);
87
87
  }
88
88
  }
89
89
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sellercraft.js","sourceRoot":"","sources":["../../../server/controllers/sellercraft/sellercraft.ts"],"names":[],"mappings":";;;;AAAA,oEAA8B;AAC9B,+BAAmC;AAEnC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oDAAoD,CAAC,CAAA;AAMpF,MAAa,WAAW;IAGtB,YAAY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EAAE,EAAE,CAAA;QACnD,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;QAE3B,MAAM,SAAS,GAAW,IAAI,CAAC,iBAAiB,EAAE,CAAA;QAElD,MAAM,QAAQ,GAAQ,MAAM,IAAA,oBAAK,EAAC,QAAQ,EAAE;YAC1C,MAAM,EAAE,KAAK;YACb,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,UAAU,EAAE,SAAS;gBACrB,WAAW,EAAE,MAAM;aACpB;SACF,CAAC,CAAA;QAEF,IAAI,QAAQ,CAAC,EAAE,EAAE;YACf,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;SAC7B;aAAM;YACL,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;YACpC,MAAM,IAAI,KAAK,CAAC,IAAI,QAAQ,CAAC,MAAM,KAAK,MAAM,CAAC,OAAO,EAAE,CAAC,CAAA;SAC1D;IACH,CAAC;CACF;AAnGD,kCAmGC","sourcesContent":["import fetch from 'node-fetch'\nimport { v4 as uuidv4 } from 'uuid'\n\nconst debug = require('debug')('things-factory:integration-sellercraft:sellercraft')\n\nexport type SellercraftConfig = {\n apiKey: string\n}\n\nexport class Sellercraft {\n private config: SellercraftConfig\n\n constructor(config: SellercraftConfig) {\n this.config = {\n ...config\n }\n }\n\n getBaseUrl() {\n return `https://open.sellercraft.co/v1`\n }\n\n generateRequestId() {\n return uuidv4()\n }\n\n async post(path: string, data: any = {}) {\n const { apiKey } = this.config\n\n debug('data', data)\n\n const jsondata = JSON.stringify(data)\n const requestId: string = this.generateRequestId()\n const fullPath: string = `${this.getBaseUrl()}${path}`\n\n const response: any = await fetch(fullPath, {\n method: 'post',\n headers: {\n 'Content-Type': 'application/json',\n request_id: requestId,\n 'x-api-key': apiKey\n },\n body: jsondata\n })\n\n if (response.ok) {\n return await response.json()\n } else {\n const result = await response.json()\n throw new Error(`(${response.status}) ${result.message}`)\n }\n }\n\n async put(path: string, data: any = {}) {\n const { apiKey } = this.config\n\n const jsondata = JSON.stringify(data)\n const requestId: string = this.generateRequestId()\n const fullPath: string = `${this.getBaseUrl()}${path}`\n debug('data', data)\n\n const response: any = await fetch(fullPath, {\n method: 'put',\n headers: {\n 'Content-Type': 'application/json',\n request_id: requestId,\n 'x-api-key': apiKey\n },\n body: jsondata\n })\n\n if (response.ok) {\n return await response.json()\n } else {\n const result = await response.json()\n throw new Error(`(${response.status}) ${result.message}`)\n }\n }\n\n async get(path: string, data: any = {}) {\n const { apiKey } = this.config\n\n const qs = Object.entries(data)\n .map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`)\n .join('&')\n\n const fullPath: string = `${this.getBaseUrl()}${path}`\n const endpoint = `${fullPath}${qs ? '?' + qs : ''}`\n debug('endpoint', endpoint)\n\n const requestId: string = this.generateRequestId()\n\n const response: any = await fetch(endpoint, {\n method: 'get',\n headers: {\n 'Content-Type': 'application/json',\n request_id: requestId,\n 'x-api-key': apiKey\n }\n })\n\n if (response.ok) {\n return await response.json()\n } else {\n const result = await response.json()\n throw new Error(`(${response.status}) ${result.message}`)\n }\n }\n}\n"]}
1
+ {"version":3,"file":"sellercraft.js","sourceRoot":"","sources":["../../../server/controllers/sellercraft/sellercraft.ts"],"names":[],"mappings":";;;;AAAA,oEAA8B;AAC9B,+BAAmC;AAEnC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oDAAoD,CAAC,CAAA;AAMpF,MAAa,WAAW;IAGtB,YAAY,MAAyB;QACnC,IAAI,CAAC,MAAM,qBACN,MAAM,CACV,CAAA;IACH,CAAC;IAED,UAAU;QACR,OAAO,gCAAgC,CAAA;IACzC,CAAC;IAED,iBAAiB;QACf,OAAO,IAAA,SAAM,GAAE,CAAA;IACjB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAY,EAAE,OAAY,EAAE;QACrC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;QAE9B,KAAK,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AAA;QAEF,IAAI,QAAQ,CAAC,EAAE,EAAE;YACf,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;SAC7B;aAAM;YACL,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;YACpC,MAAM,IAAI,KAAK,CAAC,IAAI,QAAQ,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC,CAAA;SAClD;IACH,CAAC;CACF;AAnGD,kCAmGC","sourcesContent":["import fetch from 'node-fetch'\nimport { v4 as uuidv4 } from 'uuid'\n\nconst debug = require('debug')('things-factory:integration-sellercraft:sellercraft')\n\nexport type SellercraftConfig = {\n apiKey: string\n}\n\nexport class Sellercraft {\n private config: SellercraftConfig\n\n constructor(config: SellercraftConfig) {\n this.config = {\n ...config\n }\n }\n\n getBaseUrl() {\n return `https://open.sellercraft.co/v1`\n }\n\n generateRequestId() {\n return uuidv4()\n }\n\n async post(path: string, data: any = {}) {\n const { apiKey } = this.config\n\n debug('data', data)\n\n const jsondata = JSON.stringify(data)\n const requestId: string = this.generateRequestId()\n const fullPath: string = `${this.getBaseUrl()}${path}`\n\n const response: any = await fetch(fullPath, {\n method: 'post',\n headers: {\n 'Content-Type': 'application/json',\n request_id: requestId,\n 'x-api-key': apiKey\n },\n body: jsondata\n })\n\n if (response.ok) {\n return await response.json()\n } else {\n const result = await response.text()\n throw new Error(`(${response.status}) ${result}`)\n }\n }\n\n async put(path: string, data: any = {}) {\n const { apiKey } = this.config\n\n const jsondata = JSON.stringify(data)\n const requestId: string = this.generateRequestId()\n const fullPath: string = `${this.getBaseUrl()}${path}`\n debug('data', data)\n\n const response: any = await fetch(fullPath, {\n method: 'put',\n headers: {\n 'Content-Type': 'application/json',\n request_id: requestId,\n 'x-api-key': apiKey\n },\n body: jsondata\n })\n\n if (response.ok) {\n return await response.json()\n } else {\n const result = await response.text()\n throw new Error(`(${response.status}) ${result}`)\n }\n }\n\n async get(path: string, data: any = {}) {\n const { apiKey } = this.config\n\n const qs = Object.entries(data)\n .map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`)\n .join('&')\n\n const fullPath: string = `${this.getBaseUrl()}${path}`\n const endpoint = `${fullPath}${qs ? '?' + qs : ''}`\n debug('endpoint', endpoint)\n\n const requestId: string = this.generateRequestId()\n\n const response: any = await fetch(endpoint, {\n method: 'get',\n headers: {\n 'Content-Type': 'application/json',\n request_id: requestId,\n 'x-api-key': apiKey\n }\n })\n\n if (response.ok) {\n return await response.json()\n } else {\n const result = await response.text()\n throw new Error(`(${response.status}) ${result}`)\n }\n }\n}\n"]}
@@ -19,12 +19,18 @@ const api = (target, property, descriptor) => {
19
19
  var { path, method: httpMethod = 'post', denormalize = NOOP, normalize = NOOP, action = platformAction } = m.apply(this, [request]);
20
20
  var denormalized = await denormalize(request || {}, { store });
21
21
  debug('request', denormalized);
22
- var response = await action.apply(this, [
23
- { store, method: httpMethod, path, request: denormalized, platformAction }
24
- ]);
25
- (0, integration_base_1.createPayloadLog)(store.accountId, path, denormalized, response, request === null || request === void 0 ? void 0 : request.context);
26
- debug('response', response);
27
- return await normalize(response, { store });
22
+ try {
23
+ var response = await action.apply(this, [
24
+ { store, method: httpMethod, path, request: denormalized, platformAction }
25
+ ]);
26
+ (0, integration_base_1.createPayloadLog)(store.accountId, path, denormalized, response, request === null || request === void 0 ? void 0 : request.context);
27
+ debug('response', response);
28
+ return await normalize(response, { store });
29
+ }
30
+ catch (error) {
31
+ (0, integration_base_1.createPayloadLog)(store.accountId, path, denormalized, error, request === null || request === void 0 ? void 0 : request.context);
32
+ throw error;
33
+ }
28
34
  };
29
35
  return descriptor;
30
36
  };
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../server/controllers/sellercraft-api/decorators.ts"],"names":[],"mappings":";;;;AAAA,0DAAyB;AACzB,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,4DAA4D,CAAC,CAAA;AAGjF,uEAAmE;AAEnE,MAAM,IAAI,GAAG,CAAC,CA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AAO,CAAE,OAAO,CAAC,CAAA;QAEjF,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;QAE3B,OAAO,MAAM,SAAS,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IAC7C,CAAC,CAAA;IAED,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA;AAtCY,QAAA,GAAG,OAsCf","sourcesContent":["import Debug from 'debug'\nconst debug = Debug('things-factory:integration-marketplace:store-api-decorator')\n\nimport { Sellercraft } from '../../service'\nimport { createPayloadLog } from '@things-factory/integration-base'\n\nconst NOOP = v => v\n\nexport const api = (target: Object, property: string, descriptor: TypedPropertyDescriptor<any>): any => {\n const method = descriptor.value\n\n descriptor.value = async function (store: Sellercraft, request) {\n const SellercraftAPI = this\n\n var { platform } = store\n\n var { action: platformAction, apis } = SellercraftAPI.getPlatform(platform)\n\n var m = apis[method.name]\n if (!m) {\n throw Error(`Sellercraft doesn't have API ${method.name}`)\n }\n\n var {\n path,\n method: httpMethod = 'post',\n denormalize = NOOP,\n normalize = NOOP,\n action = platformAction\n } = m.apply(this, [request])\n\n var denormalized = await denormalize(request || {}, { store })\n debug('request', denormalized)\n\n var response = await action.apply(this, [\n { store, method: httpMethod, path, request: denormalized, platformAction }\n ])\n\n createPayloadLog(store.accountId, path, denormalized, response, request?.context)\n\n debug('response', response)\n\n return await normalize(response, { store })\n }\n\n return descriptor\n}\n"]}
1
+ {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../server/controllers/sellercraft-api/decorators.ts"],"names":[],"mappings":";;;;AAAA,0DAAyB;AACzB,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,4DAA4D,CAAC,CAAA;AAGjF,uEAAmE;AAEnE,MAAM,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AAEZ,MAAM,GAAG,GAAG,CAAC,MAAc,EAAE,QAAgB,EAAE,UAAwC,EAAO,EAAE;IACrG,MAAM,MAAM,GAAG,UAAU,CAA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AAE,KAAK,EAAE,CAAC,CAAA;SAC5C;QAAC,OAAO,KAAK,EAAE;YACd,IAAA,mCAAgB,EAAC,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAA;YAC9E,MAAM,KAAK,CAAA;SACZ;IACH,CAAC,CAAA;IAED,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA;AA3CY,QAAA,GAAG,OA2Cf","sourcesContent":["import Debug from 'debug'\nconst debug = Debug('things-factory:integration-marketplace:store-api-decorator')\n\nimport { Sellercraft } from '../../service'\nimport { createPayloadLog } from '@things-factory/integration-base'\n\nconst NOOP = v => v\n\nexport const api = (target: Object, property: string, descriptor: TypedPropertyDescriptor<any>): any => {\n const method = descriptor.value\n\n descriptor.value = async function (store: Sellercraft, request) {\n const SellercraftAPI = this\n\n var { platform } = store\n\n var { action: platformAction, apis } = SellercraftAPI.getPlatform(platform)\n\n var m = apis[method.name]\n if (!m) {\n throw Error(`Sellercraft doesn't have API ${method.name}`)\n }\n\n var {\n path,\n method: httpMethod = 'post',\n denormalize = NOOP,\n normalize = NOOP,\n action = platformAction\n } = m.apply(this, [request])\n\n var denormalized = await denormalize(request || {}, { store })\n debug('request', denormalized)\n\n try {\n var response = await action.apply(this, [\n { store, method: httpMethod, path, request: denormalized, platformAction }\n ])\n\n createPayloadLog(store.accountId, path, denormalized, response, request?.context)\n\n debug('response', response)\n\n return await normalize(response, { store })\n } catch (error) {\n createPayloadLog(store.accountId, path, denormalized, error, request?.context)\n throw error\n }\n }\n\n return descriptor\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SellercraftAPI = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const typeorm_1 = require("typeorm");
5
+ const shell_1 = require("@things-factory/shell");
6
6
  const service_1 = require("../../service");
7
7
  const decorators_1 = require("./decorators");
8
8
  class SellercraftAPI {
@@ -16,7 +16,7 @@ class SellercraftAPI {
16
16
  return SellercraftAPI.platforms[name];
17
17
  }
18
18
  static async getSellercraft(id) {
19
- const repository = (0, typeorm_1.getRepository)(service_1.Sellercraft);
19
+ const repository = (0, shell_1.getRepository)(service_1.Sellercraft);
20
20
  return await repository.findOne({
21
21
  where: { id },
22
22
  relations: ['domain']
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/controllers/sellercraft-api/index.ts"],"names":[],"mappings":";;;;AAAA,qCAAuC;AAEvC,2CAA2C;AAC3C,6CAAkC;AAElC,MAAa,cAAc;IAGzB,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI;QACxC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG;YAC/B,MAAM;YACN,IAAI;SACL,CAAA;IACH,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,IAAI;QACrB,OAAO,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IACvC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;QAC5B,MAAM,UAAU,GAAG,IAAA,uBAAa,EAAC,qBAAW,CAAC,CAAA;QAC7C,OAAO,MAAM,UAAU,CAAC,OAAO,CAAC;YAC9B,KAAK,EAAE,EAAE,EAAE,EAAE;YACb,SAAS,EAAE,CAAC,QAAQ,CAAC;SACtB,CAAC,CAAA;IACJ,CAAC;IAGD,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;IAGrC,MAAM,CAAC,eAAe,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;IAGhD,MAAM,CAAC,kBAAkB,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;IAGnD,MAAM,CAAC,qBAAqB,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;IAGtD,MAAM,CAAC,qBAAqB,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;IAGtD,MAAM,CAAC,oBAAoB,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;IAGrD,MAAM,CAAC,sBAAsB,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;IAGvD,MAAM,CAAC,aAAa,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;;AA3CvC,wBAAS,GAAG,EAAE,CAAA;AAsBrB;IADC,gBAAG;;;;gCACiC;AAGrC;IADC,gBAAG;;;;2CAC4C;AAGhD;IADC,gBAAG;;;;8CAC+C;AAGnD;IADC,gBAAG;;;;iDACkD;AAGtD;IADC,gBAAG;;;;iDACkD;AAGtD;IADC,gBAAG;;;;gDACiD;AAGrD;IADC,gBAAG;;;;kDACmD;AAGvD;IADC,gBAAG;;;;yCAC0C;AA5ChD,wCA6CC","sourcesContent":["import { getRepository } from 'typeorm'\n\nimport { Sellercraft } from '../../service'\nimport { api } from './decorators'\n\nexport class SellercraftAPI {\n static platforms = {}\n\n static registerPlatform(name, action, apis) {\n SellercraftAPI.platforms[name] = {\n action,\n apis\n }\n }\n\n static getPlatform(name) {\n return SellercraftAPI.platforms[name]\n }\n\n static async getSellercraft(id) {\n const repository = getRepository(Sellercraft)\n return await repository.findOne({\n where: { id },\n relations: ['domain']\n })\n }\n\n @api\n static echo(sellercraft, req): any {}\n\n @api\n static addInboundOrder(sellercraft, req): any {}\n\n @api\n static fetchOrderDocument(sellercraft, req): any {}\n\n @api\n static initiateOrderDocument(sellercraft, req): any {}\n\n @api\n static initiateOrderShipment(sellercraft, req): any {}\n\n @api\n static packMarketplaceOrder(sellercraft, req): any {}\n\n @api\n static updateMarketplaceOrder(sellercraft, req): any {}\n\n @api\n static updateProduct(sellercraft, req): any {}\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/controllers/sellercraft-api/index.ts"],"names":[],"mappings":";;;;AAAA,iDAAqD;AAErD,2CAA2C;AAC3C,6CAAkC;AAElC,MAAa,cAAc;IAGzB,MAAM,CAAC,gBAAgB,CAAC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;;;;kDACmD;AAGvD;IADC,gBAAG;;;;yCAC0C;AA5ChD,wCA6CC","sourcesContent":["import { getRepository } from '@things-factory/shell'\n\nimport { Sellercraft } from '../../service'\nimport { api } from './decorators'\n\nexport class SellercraftAPI {\n static platforms = {}\n\n static registerPlatform(name, action, apis) {\n SellercraftAPI.platforms[name] = {\n action,\n apis\n }\n }\n\n static getPlatform(name) {\n return SellercraftAPI.platforms[name]\n }\n\n static async getSellercraft(id) {\n const repository = getRepository(Sellercraft)\n return await repository.findOne({\n where: { id },\n relations: ['domain']\n })\n }\n\n @api\n static echo(sellercraft, req): any {}\n\n @api\n static addInboundOrder(sellercraft, req): any {}\n\n @api\n static fetchOrderDocument(sellercraft, req): any {}\n\n @api\n static initiateOrderDocument(sellercraft, req): any {}\n\n @api\n static initiateOrderShipment(sellercraft, req): any {}\n\n @api\n static packMarketplaceOrder(sellercraft, req): any {}\n\n @api\n static updateMarketplaceOrder(sellercraft, req): any {}\n\n @api\n static updateProduct(sellercraft, req): any {}\n}\n"]}
@@ -14,6 +14,7 @@ function ingestChannelOrder() {
14
14
  organisation_id: order.organisationId,
15
15
  channel_shop_id: order.channelShopId,
16
16
  native_order_id: order.id.toString(),
17
+ native_order_display_id: order === null || order === void 0 ? void 0 : order.sellercraftDisplayOrderNo,
17
18
  ordered_at_date: new Date(order.createdAt).toISOString().slice(0, -5) + 'Z',
18
19
  ordered_at_time: new Date(order.createdAt).toISOString().slice(0, -5) + 'Z',
19
20
  updated_at_date: new Date(order.updatedAt).toISOString().slice(0, -5) + 'Z',
@@ -27,7 +28,7 @@ function ingestChannelOrder() {
27
28
  amount_nett: parseFloat(charge.nettAmount) || 0
28
29
  };
29
30
  }),
30
- address_shipping: {
31
+ address_shipping: (order === null || order === void 0 ? void 0 : order.shipAddress1) ? {
31
32
  first_name: order.shipFirstName,
32
33
  last_name: order.shipLastName,
33
34
  line_1: order.shipAddress1,
@@ -40,7 +41,7 @@ function ingestChannelOrder() {
40
41
  country: order.shipCountry,
41
42
  phone_1: order.shipPhone1,
42
43
  phone_2: order.shipPhone2
43
- },
44
+ } : null,
44
45
  address_billing: {
45
46
  first_name: order.billFirstName,
46
47
  last_name: order.billLastName,
@@ -75,7 +76,8 @@ function ingestChannelOrder() {
75
76
  order_status_value: constants_1.ORDER_STATUS[`${order.status}`]
76
77
  };
77
78
  }),
78
- seller_logistics: order === null || order === void 0 ? void 0 : order.isSOF
79
+ seller_logistics: order === null || order === void 0 ? void 0 : order.isSOF,
80
+ shipping_type: (order === null || order === void 0 ? void 0 : order.shipAddress1) ? 'DROP_SHIPPING' : 'SELF_PICKUP'
79
81
  };
80
82
  });
81
83
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"ingest-channel-order.js","sourceRoot":"","sources":["../../../../server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts"],"names":[],"mappings":";AAAA,4FAA4F;;;AAE5F,kDAAiD;AAEjD,SAAgB,kBAAkB;IAChC,OAAO;QACL,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,uBAAuB;QAC7B,WAAW,CAAC,GAAG;YACb,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAA;YAEtB,IAAI,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;gBACjC,OAAO;oBACL,eAAe,EAAE,KAAK,CAAC,cAAc;oBACrC,eAAe,EAAE,KAAK,CAAC,aAAa;oBACpC,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE;oBACpC,eAAe,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG;oBAC3E,eAAe,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG;oBAC3E,eAAe,EAAE,IAAI,IA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AAY,EAAC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI;4BAC/F,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;gCACtC,OAAO;oCACL,iBAAiB,EAAE,MAAM,CAAC,IAAI;oCAC9B,YAAY,EAAE,UAAU,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;oCACjD,WAAW,EAAE,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC;iCAChD,CAAA;4BACH,CAAC,CAAC;4BACF,kBAAkB,EAAE,wBAAY,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;yBACpD,CAAA;oBACH,CAAC,CAAC;oBACF,gBAAgB,EAAE,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK;iBAC/B,CAAA;YACH,CAAC,CAAC,CAAA;YAEF,OAAO;gBACL,OAAO,EAAE,CAAC,GAAG,SAAS,CAAC;aACxB,CAAA;QACH,CAAC;QACD,SAAS,CAAC,GAAG;YACX,OAAO,GAAG,CAAA;QACZ,CAAC;KACF,CAAA;AACH,CAAC;AArFD,gDAqFC","sourcesContent":["/* https://docs.sellercraft.co/docs/api-integrations/b3A6MjQzODQ4OTg-ingest-channel-order */\n\nimport { ORDER_STATUS } from '../../../constants'\n\nexport function ingestChannelOrder() {\n return {\n method: 'post',\n path: '/channel/ingest/order',\n denormalize(req) {\n const { orders } = req\n\n let newOrders = orders.map(order => {\n return {\n organisation_id: order.organisationId,\n channel_shop_id: order.channelShopId,\n native_order_id: order.id.toString(),\n ordered_at_date: new Date(order.createdAt).toISOString().slice(0, -5) + 'Z',\n ordered_at_time: new Date(order.createdAt).toISOString().slice(0, -5) + 'Z',\n updated_at_date: new Date(order.updatedAt).toISOString().slice(0, -5) + 'Z',\n updated_at_time: new Date(order.updatedAt).toISOString().slice(0, -5) + 'Z',\n customer_first_name: order.custFirstName,\n customer_last_name: order.custLastName,\n charges: order.charges.map(charge => {\n return {\n charge_type_value: charge.name,\n amount_gross: parseFloat(charge.grossAmount) || 0,\n amount_nett: parseFloat(charge.nettAmount) || 0\n }\n }),\n address_shipping: {\n first_name: order.shipFirstName,\n last_name: order.shipLastName,\n line_1: order.shipAddress1,\n line_2: order.shipAddress2,\n line_3: order.shipAddress3,\n line_4: order.shipAddress4,\n line_5: order.shipAddress5,\n city: order.shipCity,\n postal_code: order.shipPostalCode,\n country: order.shipCountry,\n phone_1: order.shipPhone1,\n phone_2: order.shipPhone2\n },\n address_billing: {\n first_name: order.billFirstName,\n last_name: order.billLastName,\n line_1: order.billAddress1,\n line_2: order.billAddress2,\n line_3: order.billAddress3,\n line_4: order.billAddress4,\n line_5: order.billAddress5,\n city: order.billCity,\n postal_code: order.billPostalCode,\n country: order.billCountry,\n phone_1: order.billPhone1,\n phone_2: order.billPhone2\n },\n order_items: order.mappedOrderItems.map(orderItem => {\n return {\n native_item_id: orderItem.id.toString(),\n native_variant_id: orderItem.variationId.toString(),\n currency_code: orderItem.currency,\n ordered_at_date: new Date(order.createdAt).toISOString().slice(0, -5) + 'Z',\n ordered_at_time: new Date(order.createdAt).toISOString().slice(0, -5) + 'Z',\n updated_at_date: new Date(order.updatedAt).toISOString().slice(0, -5) + 'Z',\n updated_at_time: new Date(order.updatedAt).toISOString().slice(0, -5) + 'Z',\n sla_expires_at: orderItem?.slaExpiresAt ? new Date(orderItem.slaExpiresAt).toISOString() : null,\n charges: orderItem.charges.map(charge => {\n return {\n charge_type_value: charge.name,\n amount_gross: parseFloat(charge.grossAmount) || 0,\n amount_nett: parseFloat(charge.nettAmount) || 0\n }\n }),\n order_status_value: ORDER_STATUS[`${order.status}`]\n }\n }),\n seller_logistics: order?.isSOF\n }\n })\n\n return {\n payload: [...newOrders]\n }\n },\n normalize(res) {\n return res\n }\n }\n}\n"]}
1
+ {"version":3,"file":"ingest-channel-order.js","sourceRoot":"","sources":["../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,WAAW,EAAE,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC;iCAChD,CAAA;4BACH,CAAC,CAAC;4BACF,kBAAkB,EAAE,wBAAY,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;yBACpD,CAAA;oBACH,CAAC,CAAC;oBACF,gBAAgB,EAAE,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK;oBAC9B,aAAa,EAAE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,YAAY,EAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,aAAa;iBACrE,CAAA;YACH,CAAC,CAAC,CAAA;YAEF,OAAO;gBACL,OAAO,EAAE,CAAC,GAAG,SAAS,CAAC;aACxB,CAAA;QACH,CAAC;QACD,SAAS,CAAC,GAAG;YACX,OAAO,GAAG,CAAA;QACZ,CAAC;KACF,CAAA;AACH,CAAC;AAvFD,gDAuFC","sourcesContent":["/* https://docs.sellercraft.co/docs/api-integrations/b3A6MjQzODQ4OTg-ingest-channel-order */\n\nimport { ORDER_STATUS } from '../../../constants'\n\nexport function ingestChannelOrder() {\n return {\n method: 'post',\n path: '/channel/ingest/order',\n denormalize(req) {\n const { orders } = req\n\n let newOrders = orders.map(order => {\n return {\n organisation_id: order.organisationId,\n channel_shop_id: order.channelShopId,\n native_order_id: order.id.toString(),\n native_order_display_id: order?.sellercraftDisplayOrderNo,\n ordered_at_date: new Date(order.createdAt).toISOString().slice(0, -5) + 'Z',\n ordered_at_time: new Date(order.createdAt).toISOString().slice(0, -5) + 'Z',\n updated_at_date: new Date(order.updatedAt).toISOString().slice(0, -5) + 'Z',\n updated_at_time: new Date(order.updatedAt).toISOString().slice(0, -5) + 'Z',\n customer_first_name: order.custFirstName,\n customer_last_name: order.custLastName,\n charges: order.charges.map(charge => {\n return {\n charge_type_value: charge.name,\n amount_gross: parseFloat(charge.grossAmount) || 0,\n amount_nett: parseFloat(charge.nettAmount) || 0\n }\n }),\n address_shipping: order?.shipAddress1 ? {\n first_name: order.shipFirstName,\n last_name: order.shipLastName,\n line_1: order.shipAddress1,\n line_2: order.shipAddress2,\n line_3: order.shipAddress3,\n line_4: order.shipAddress4,\n line_5: order.shipAddress5,\n city: order.shipCity,\n postal_code: order.shipPostalCode,\n country: order.shipCountry,\n phone_1: order.shipPhone1,\n phone_2: order.shipPhone2\n } : null,\n address_billing: {\n first_name: order.billFirstName,\n last_name: order.billLastName,\n line_1: order.billAddress1,\n line_2: order.billAddress2,\n line_3: order.billAddress3,\n line_4: order.billAddress4,\n line_5: order.billAddress5,\n city: order.billCity,\n postal_code: order.billPostalCode,\n country: order.billCountry,\n phone_1: order.billPhone1,\n phone_2: order.billPhone2\n },\n order_items: order.mappedOrderItems.map(orderItem => {\n return {\n native_item_id: orderItem.id.toString(),\n native_variant_id: orderItem.variationId.toString(),\n currency_code: orderItem.currency,\n ordered_at_date: new Date(order.createdAt).toISOString().slice(0, -5) + 'Z',\n ordered_at_time: new Date(order.createdAt).toISOString().slice(0, -5) + 'Z',\n updated_at_date: new Date(order.updatedAt).toISOString().slice(0, -5) + 'Z',\n updated_at_time: new Date(order.updatedAt).toISOString().slice(0, -5) + 'Z',\n sla_expires_at: orderItem?.slaExpiresAt ? new Date(orderItem.slaExpiresAt).toISOString() : null,\n charges: orderItem.charges.map(charge => {\n return {\n charge_type_value: charge.name,\n amount_gross: parseFloat(charge.grossAmount) || 0,\n amount_nett: parseFloat(charge.nettAmount) || 0\n }\n }),\n order_status_value: ORDER_STATUS[`${order.status}`]\n }\n }),\n seller_logistics: order?.isSOF,\n shipping_type: order?.shipAddress1 ? 'DROP_SHIPPING' : 'SELF_PICKUP'\n }\n })\n\n return {\n payload: [...newOrders]\n }\n },\n normalize(res) {\n return res\n }\n }\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SellercraftChannelIntegrationAPI = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const typeorm_1 = require("typeorm");
5
+ const shell_1 = require("@things-factory/shell");
6
6
  const service_1 = require("../../service");
7
7
  const decorators_1 = require("./decorators");
8
8
  class SellercraftChannelIntegrationAPI {
@@ -16,7 +16,7 @@ class SellercraftChannelIntegrationAPI {
16
16
  return SellercraftChannelIntegrationAPI.platforms[name];
17
17
  }
18
18
  static async getSellercraft(id) {
19
- const repository = (0, typeorm_1.getRepository)(service_1.Sellercraft);
19
+ const repository = (0, shell_1.getRepository)(service_1.Sellercraft);
20
20
  return await repository.findOne({
21
21
  where: { id },
22
22
  relations: ['domain']
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/controllers/sellercraft-channel-integration-api/index.ts"],"names":[],"mappings":";;;;AAAA,qCAAuC;AAEvC,2CAA2C;AAC3C,6CAAkC;AAElC,MAAa,gCAAgC;IAG3C,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI;QACxC,gCAAgC,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG;YACjD,MAAM;YACN,IAAI;SACL,CAAA;IACH,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,IAAI;QACrB,OAAO,gCAAgC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IACzD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;QAC5B,MAAM,UAAU,GAAG,IAAA,uBAAa,EAAC,qBAAW,CAAC,CAAA;QAC7C,OAAO,MAAM,UAAU,CAAC,OAAO,CAAC;YAC9B,KAAK,EAAE,EAAE,EAAE,EAAE;YACb,SAAS,EAAE,CAAC,QAAQ,CAAC;SACtB,CAAC,CAAA;IACJ,CAAC;IAGD,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;IAGrC,MAAM,CAAC,uBAAuB,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;IAGxD,MAAM,CAAC,+BAA+B,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;IAGhE,MAAM,CAAC,yBAAyB,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;IAG1D,MAAM,CAAC,kBAAkB,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;IAGnD,MAAM,CAAC,oBAAoB,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;;AArC9C,0CAAS,GAAG,EAAE,CAAA;AAsBrB;IADC,gBAAG;;;;kDACiC;AAGrC;IADC,gBAAG;;;;qEACoD;AAGxD;IADC,gBAAG;;;;6EAC4D;AAGhE;IADC,gBAAG;;;;uEACsD;AAG1D;IADC,gBAAG;;;;gEAC+C;AAGnD;IADC,gBAAG;;;;kEACiD;AAtCvD,4EAuCC","sourcesContent":["import { getRepository } from 'typeorm'\n\nimport { Sellercraft } from '../../service'\nimport { api } from './decorators'\n\nexport class SellercraftChannelIntegrationAPI {\n static platforms = {}\n\n static registerPlatform(name, action, apis) {\n SellercraftChannelIntegrationAPI.platforms[name] = {\n action,\n apis\n }\n }\n\n static getPlatform(name) {\n return SellercraftChannelIntegrationAPI.platforms[name]\n }\n\n static async getSellercraft(id) {\n const repository = getRepository(Sellercraft)\n return await repository.findOne({\n where: { id },\n relations: ['domain']\n })\n }\n\n @api\n static echo(sellercraft, req): any {}\n\n @api\n static ingestChannelCategories(sellercraft, req): any {}\n\n @api\n static ingestChannelCategoryAttributes(sellercraft, req): any {}\n\n @api\n static ingestChannelOrderPackage(sellercraft, req): any {}\n\n @api\n static ingestChannelOrder(sellercraft, req): any {}\n\n @api\n static ingestChannelProduct(sellercraft, req): any {}\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/controllers/sellercraft-channel-integration-api/index.ts"],"names":[],"mappings":";;;;AAAA,iDAAqD;AAErD,2CAA2C;AAC3C,6CAAkC;AAElC,MAAa,gCAAgC;IAG3C,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI;QACxC,gCAAgC,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG;YACjD,MAAM;YACN,IAAI;SACL,CAAA;IACH,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,IAAI;QACrB,OAAO,gCAAgC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IACzD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;QAC5B,MAAM,UAAU,GAAG,IAAA,qBAAa,EAAC,qBAAW,CAAC,CAAA;QAC7C,OAAO,MAAM,UAAU,CAAC,OAAO,CAAC;YAC9B,KAAK,EAAE,EAAE,EAAE,EAAE;YACb,SAAS,EAAE,CAAC,QAAQ,CAAC;SACtB,CAAC,CAAA;IACJ,CAAC;IAGD,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;IAGrC,MAAM,CAAC,uBAAuB,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;IAGxD,MAAM,CAAC,+BAA+B,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;IAGhE,MAAM,CAAC,yBAAyB,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;IAG1D,MAAM,CAAC,kBAAkB,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;IAGnD,MAAM,CAAC,oBAAoB,CAAC,WAAW,EAAE,GAAG,IAAQ,CAAC;;AArC9C,0CAAS,GAAG,EAAE,CAAA;AAsBrB;IADC,gBAAG;;;;kDACiC;AAGrC;IADC,gBAAG;;;;qEACoD;AAGxD;IADC,gBAAG;;;;6EAC4D;AAGhE;IADC,gBAAG;;;;uEACsD;AAG1D;IADC,gBAAG;;;;gEAC+C;AAGnD;IADC,gBAAG;;;;kEACiD;AAtCvD,4EAuCC","sourcesContent":["import { getRepository } from '@things-factory/shell'\n\nimport { Sellercraft } from '../../service'\nimport { api } from './decorators'\n\nexport class SellercraftChannelIntegrationAPI {\n static platforms = {}\n\n static registerPlatform(name, action, apis) {\n SellercraftChannelIntegrationAPI.platforms[name] = {\n action,\n apis\n }\n }\n\n static getPlatform(name) {\n return SellercraftChannelIntegrationAPI.platforms[name]\n }\n\n static async getSellercraft(id) {\n const repository = getRepository(Sellercraft)\n return await repository.findOne({\n where: { id },\n relations: ['domain']\n })\n }\n\n @api\n static echo(sellercraft, req): any {}\n\n @api\n static ingestChannelCategories(sellercraft, req): any {}\n\n @api\n static ingestChannelCategoryAttributes(sellercraft, req): any {}\n\n @api\n static ingestChannelOrderPackage(sellercraft, req): any {}\n\n @api\n static ingestChannelOrder(sellercraft, req): any {}\n\n @api\n static ingestChannelProduct(sellercraft, req): any {}\n}\n"]}
@@ -5,8 +5,10 @@ const tslib_1 = require("tslib");
5
5
  const koa_router_1 = tslib_1.__importDefault(require("koa-router"));
6
6
  const uuid_1 = require("uuid");
7
7
  const integration_marketplace_1 = require("@things-factory/integration-marketplace");
8
- const tokencraft_util_1 = require("../utils/tokencraft-util");
8
+ const integration_base_1 = require("@things-factory/integration-base");
9
+ const utils_1 = require("@things-factory/utils");
9
10
  const constants_1 = require("../constants");
11
+ const tokencraft_util_1 = require("../utils/tokencraft-util");
10
12
  const debug = require('debug')('things-factory:integration-sellercraft:sellercraft-router');
11
13
  exports.sellercraftRouter = new koa_router_1.default();
12
14
  exports.sellercraftRouter.post('/sellercraft/store/update-product-price', async (context, next) => {
@@ -101,6 +103,11 @@ exports.sellercraftRouter.post('/sellercraft/store/update-order-status', async (
101
103
  const requestBody = context.request.body;
102
104
  var result = {};
103
105
  let mappedStore = await (0, tokencraft_util_1.getShop)(context, requestBody.channel_id, requestBody.shop_id);
106
+ let packageIds = mappedStore.platform == 'tiktok'
107
+ ? requestBody === null || requestBody === void 0 ? void 0 : requestBody.order_items.map(oi => {
108
+ return oi.package_id;
109
+ })
110
+ : [];
104
111
  const reqBody = {
105
112
  orderId: requestBody.native_order_id,
106
113
  status: requestBody.order_status,
@@ -110,6 +117,7 @@ exports.sellercraftRouter.post('/sellercraft/store/update-order-status', async (
110
117
  return oi.native_order_item_id;
111
118
  })) || []),
112
119
  isSOF: requestBody === null || requestBody === void 0 ? void 0 : requestBody.seller_logistics,
120
+ packageIds: [...new Set(packageIds)] || [],
113
121
  locations: mappedStore.platform == 'shopify'
114
122
  ? requestBody === null || requestBody === void 0 ? void 0 : requestBody.order_items.map(oi => {
115
123
  let jsonLocation = oi.extra_metadata.locationId;
@@ -121,7 +129,14 @@ exports.sellercraftRouter.post('/sellercraft/store/update-order-status', async (
121
129
  let responseBody = { operation_id: (0, uuid_1.v4)() };
122
130
  try {
123
131
  try {
124
- result = (await integration_marketplace_1.StoreAPI.updateOrderStatus(mappedStore, reqBody)) || {};
132
+ if (mappedStore.platform == 'tiktok') {
133
+ for (let packageId of reqBody.packageIds) {
134
+ result = (await integration_marketplace_1.StoreAPI.updateOrderStatus(mappedStore, { packageId, status: reqBody.status })) || {};
135
+ }
136
+ }
137
+ else {
138
+ result = (await integration_marketplace_1.StoreAPI.updateOrderStatus(mappedStore, reqBody)) || {};
139
+ }
125
140
  debug(result);
126
141
  }
127
142
  catch (e) {
@@ -137,12 +152,15 @@ exports.sellercraftRouter.post('/sellercraft/store/update-order-status', async (
137
152
  let orderDocument = orderPackage.orderDocument;
138
153
  if ((orderDocument === null || orderDocument === void 0 ? void 0 : orderDocument.length) == 0) {
139
154
  let hasDocument = false;
140
- while (!hasDocument) {
155
+ let retries = 0;
156
+ while (!hasDocument && retries < 10) {
141
157
  orderDocument = await integration_marketplace_1.StoreAPI.getStoreOrderDocument(mappedStore, { packageId, documentType: 1 });
142
158
  if ((orderDocument === null || orderDocument === void 0 ? void 0 : orderDocument.length) > 0) {
143
159
  hasDocument = true;
144
160
  break;
145
161
  }
162
+ await (0, utils_1.sleep)(1000);
163
+ retries++;
146
164
  }
147
165
  }
148
166
  // Order Package Payload
@@ -180,6 +198,10 @@ exports.sellercraftRouter.post('/sellercraft/store/update-order-status', async (
180
198
  responseBody.message = 'Success';
181
199
  }
182
200
  responseBody.time = Math.floor(new Date(new Date().toUTCString()).getTime() / 1000);
201
+ try {
202
+ (0, integration_base_1.createPayloadLog)(mappedStore.channelShopId, '/sellercraft/store/update-order-status', requestBody, responseBody, null, integration_base_1.PayloadType.INGESTION, 'hub-api');
203
+ }
204
+ catch (e) { }
183
205
  context.type = 'application/json';
184
206
  context.status = 200;
185
207
  context.body = responseBody;
@@ -191,6 +213,10 @@ exports.sellercraftRouter.post('/sellercraft/store/update-order-status', async (
191
213
  context.type = 'application/json';
192
214
  context.status = 500;
193
215
  context.body = responseBody;
216
+ try {
217
+ (0, integration_base_1.createPayloadLog)(mappedStore === null || mappedStore === void 0 ? void 0 : mappedStore.channelShopId, '/sellercraft/store/update-order-status', requestBody, responseBody, null, integration_base_1.PayloadType.INGESTION, 'hub-api');
218
+ }
219
+ catch (e) { }
194
220
  }
195
221
  }
196
222
  catch (e) { }
@@ -1 +1 @@
1
- {"version":3,"file":"sellercraft-router.js","sourceRoot":"","sources":["../../server/routers/sellercraft-router.ts"],"names":[],"mappings":";;;;AAAA,oEAA+B;AAC/B,+BAAmC;AAGnC,qFAAkE;AAClE,8DAAkD;AAElD,4CAA4C;AAE5C,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,2DAA2D,CAAC,CAAA;AAE9E,QAAA,iBAAiB,GAAG,IAAI,oBAAM,EAAE,CAAA;AAE7C,yBAAiB,CAAC,IAAI,CAAC,yCAAyC,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;IACxF,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAA;IAExC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC3C,IAAI,WAAW,GAAQ,MAAM,IAAA,yBAAO,EAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;QAChG,IAAI,MAAM,CAAA;QAEV,IAAI;YACF,IAAI,WAAW,CA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B,OAAO,CAAC,IAAI,GAAG,WAAW,CAAA;SAC3B;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,IAAI,GAAG,kBAAkB,CAAA;YACjC,OAAO,CAAC,MAAM,GAAG,GAAG,CAAA;YACpB,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,OAAO,CAAA;SACzB;KACF;AACH,CAAC,CAAC,CAAA;AAEF,SAAS,eAAe,CAAC,UAAU;IACjC,IAAI,SAAS,GAAG,EAAE,CAAA;IAClB,IAAI,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;QAC3B,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IACxB,CAAC,CAAC,CAAA;IAEF,KAAK,IAAI,IAAI,IAAI,GAAG,EAAE;QACpB,IAAI,KAAK,GAAG,CAAC,CAAA;QAEb,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YACpB,IAAI,OAAO,KAAK,IAAI,EAAE;gBACpB,KAAK,IAAI,CAAC,CAAA;aACX;QACH,CAAC,CAAC,CAAA;QAEF,SAAS,CAAC,IAAI,CAAC;YACb,aAAa,EAAE,IAAI;YACnB,GAAG,EAAE,KAAK;SACX,CAAC,CAAA;KACH;IAED,SAAS,GAAG,SAAS,CAAC,MAAM,CAC1B,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,KAAK,KAAK,CAAC,aAAa,CAAC,CAC/F,CAAA;IACD,OAAO,SAAS,CAAA;AAClB,CAAC","sourcesContent":["import Router from 'koa-router'\nimport { v4 as uuidv4 } from 'uuid'\n\nimport { config } from '@things-factory/env'\nimport { StoreAPI } from '@things-factory/integration-marketplace'\nimport { getShop } from '../utils/tokencraft-util'\n\nimport { SHIPPING_TYPE } from '../constants'\n\nconst debug = require('debug')('things-factory:integration-sellercraft:sellercraft-router')\n\nexport const sellercraftRouter = new Router()\n\nsellercraftRouter.post('/sellercraft/store/update-product-price', async (context, next) => {\n const requestBody = context.request.body\n\n for (var i = 0; i < requestBody.length; i++) {\n let mappedStore: any = await getShop(context, requestBody[i].channel_id, requestBody[i].shop_id)\n var result\n\n try {\n if (requestBody[i].variant.native_variant_id != requestBody[i].native_product_id) {\n const req = {\n costPrice: requestBody[i].variant.full_price,\n sellPrice: requestBody[i].variant.sale_price,\n productId: requestBody[i].native_product_id,\n variationId: requestBody[i].variant.native_variant_id,\n variationSku: requestBody[i].variant.sku,\n context: { state: { domain: null } }\n }\n result = await StoreAPI.updateStoreProductVariationPrice(mappedStore, req)\n } else {\n const req = {\n costPrice: requestBody[i].variant.full_price,\n sellPrice: requestBody[i].variant.sale_price,\n productId: requestBody[i].native_product_id,\n variationSku: requestBody[i].variant.sku,\n context: { state: { domain: null } }\n }\n result = await StoreAPI.updateStoreProductPrice(mappedStore, req)\n }\n\n debug(result)\n\n context.type = 'application/json'\n context.status = 200\n context.body = 'Succeeded'\n } catch (e) {\n context.type = 'application/json'\n context.status = 500\n context.body = e.message\n }\n }\n})\n\nsellercraftRouter.post('/sellercraft/store/update-product-stock', async (context, next) => {\n const requestBody = context.request.body\n for (var i = 0; i < requestBody.length; i++) {\n let mappedStore: any = await getShop(context, requestBody[i].channel_id, requestBody[i].shop_id)\n var result\n\n try {\n if (requestBody[i].variant.native_variant_id != requestBody[i].native_product_id) {\n const req = {\n qty: requestBody[i].variant.stock,\n itemId: requestBody[i].native_product_id,\n variationId: requestBody[i].variant.native_variant_id,\n distributors: requestBody[i].distributors || [], // for Magento\n variationSku: requestBody[i].variant.sku,\n locationId: requestBody[i]?.variant?.extra_metadata?.locationId, // for Shopify\n inventoryItemId: requestBody[i]?.variant?.extra_metadata?.inventoryItemId, // for Shopify\n context: { state: { domain: null } }\n }\n if (req.locationId) {\n let location = JSON.parse(req.locationId)\n req.qty -= await StoreAPI.getStoreProductVariationStock(mappedStore, { variantId: req.variationId })\n req.locationId = location[0].location_id\n }\n result = await StoreAPI.updateStoreProductVariationStock(mappedStore, req)\n } else {\n const req = {\n qty: requestBody[i].variant.stock,\n itemId: requestBody[i].native_product_id,\n distributors: requestBody[i].distributors || [], // for Magento\n variationSku: requestBody[i].variant.sku,\n context: { state: { domain: null } }\n }\n result = await StoreAPI.updateStoreProductStock(mappedStore, req)\n }\n\n debug(result)\n\n context.type = 'application/json'\n context.status = 200\n context.body = 'Succeeded'\n } catch (e) {\n context.type = 'application/json'\n context.status = 500\n context.body = e.message\n }\n }\n})\n\nsellercraftRouter.post('/sellercraft/store/update-order-status', async (context, next) => {\n try {\n const requestBody = context.request.body\n var result: any = {}\n let mappedStore: any = await getShop(context, requestBody.channel_id, requestBody.shop_id)\n\n const reqBody = {\n orderId: requestBody.native_order_id,\n status: requestBody.order_status,\n carrier: requestBody?.shipper_last_mile,\n trackingNo: requestBody?.tracking_number,\n orderItems: unmapOrderItems(\n requestBody?.order_items.map(oi => {\n return oi.native_order_item_id\n }) || []\n ),\n isSOF: requestBody?.seller_logistics,\n locations:\n mappedStore.platform == 'shopify'\n ? requestBody?.order_items.map(oi => {\n let jsonLocation = oi.extra_metadata.locationId\n return JSON.parse(jsonLocation)[0].location_id\n })\n : null,\n context: { state: { domain: null } }\n }\n\n let responseBody: any = { operation_id: uuidv4() }\n try {\n try {\n result = (await StoreAPI.updateOrderStatus(mappedStore, reqBody)) || {}\n debug(result)\n } catch (e) {\n if (e?.requiredDocument) result.requiredDocument = e.requiredDocument\n }\n\n if (result?.requiredDocument) {\n // call document api and ingest channel order package\n const order: any = await StoreAPI.getStoreOrder(mappedStore, { orderId: reqBody.orderId })\n let orderPackage: any = order ? (order[0]?.orderPackage ? order[0].orderPackage : {}) : {}\n if (orderPackage) {\n const packageId: string = orderPackage.packageId\n\n let orderDocument: any = orderPackage.orderDocument\n if (orderDocument?.length == 0) {\n let hasDocument: boolean = false\n while (!hasDocument) {\n orderDocument = await StoreAPI.getStoreOrderDocument(mappedStore, { packageId, documentType: 1 })\n if (orderDocument?.length > 0) {\n hasDocument = true\n break\n }\n }\n }\n\n // Order Package Payload\n let newOrderPackage: any =\n {\n channel_shop_id: mappedStore.channelShopId,\n native_order_id: reqBody.orderId,\n native_package_id: orderPackage.packageId.toString(),\n shipping_tracking_code: orderPackage.trackingNumber,\n shipping_type_value: orderPackage?.shippingType ? orderPackage.shippingType : SHIPPING_TYPE.DROP_SHIPPING,\n warehouse_code: SHIPPING_TYPE.DROP_SHIPPING,\n shipper: {\n name: orderPackage.shippingProvider,\n is_cod_supported: orderPackage?.isCodSupport ? orderPackage.isCodSupport : false\n },\n documents:\n orderDocument?.map(doc => {\n return {\n file: doc.file,\n file_type_value: doc.fileTypeValue,\n mime_type: doc.mimeType\n }\n }) || [],\n shipper_last_mile: {\n name: orderPackage.shippingProvider,\n is_cod_supported: orderPackage?.isCodSupport ? orderPackage.isCodSupport : false\n },\n order_item_ids: orderPackage?.orderListIdList\n ? orderPackage.orderListIdList\n : reqBody.orderItems.map(oi => {\n return oi.order_item_id\n })\n } || {}\n\n responseBody.package = newOrderPackage\n }\n responseBody.response_code = 'E0'\n responseBody.message = 'Success'\n }\n\n responseBody.time = Math.floor(new Date(new Date().toUTCString()).getTime() / 1000)\n\n context.type = 'application/json'\n context.status = 200\n context.body = responseBody\n\n await next()\n } catch (e) {\n responseBody.response_code = 'E1'\n responseBody.message = e.message\n\n context.type = 'application/json'\n context.status = 500\n context.body = responseBody\n }\n } catch (e) {}\n})\n\nsellercraftRouter.post('/sellercraft/store/update-product-attribute', async (context, next) => {\n const requestBody = context.request.body\n let mappedStore: any = await getShop(context, requestBody.channel_id, requestBody.shop_id)\n\n let { product_sku: productSku, native_product_id: itemId, variants } = requestBody\n\n variants.map(variant => {\n let { variant_sku: variantSku, native_variant_id: variantId, attributes } = variant\n\n attributes.map(attribute => {\n let { native_attribute_id: id, attribute_key: name, attribute_value: value } = attribute\n\n return {\n id,\n name,\n value\n }\n })\n\n return {\n variantSku,\n variantId,\n attributes\n }\n })\n\n for (var i = 0; i < variants.length; i++) {\n try {\n let variant = variants[i]\n await StoreAPI.updateProductAttribute(mappedStore, {\n productSku,\n itemId,\n variant,\n context: { state: { domain: null } }\n })\n context.type = 'application/json'\n context.status = 200\n context.body = 'Succeeded'\n } catch (e) {\n context.type = 'application/json'\n context.status = 500\n context.body = e.message\n }\n }\n})\n\nfunction unmapOrderItems(orderItems) {\n let itemsList = []\n let res = orderItems.map(e => {\n return e.split('-')[0]\n })\n\n for (let item of res) {\n let count = 0\n\n res.forEach(element => {\n if (element === item) {\n count += 1\n }\n })\n\n itemsList.push({\n order_item_id: item,\n qty: count\n })\n }\n\n itemsList = itemsList.filter(\n (value, index, self) => index === self.findIndex(t => t.order_item_id === value.order_item_id)\n )\n return itemsList\n}\n"]}
1
+ {"version":3,"file":"sellercraft-router.js","sourceRoot":"","sources":["../../server/routers/sellercraft-router.ts"],"names":[],"mappings":";;;;AAAA,oEAA+B;AAC/B,+BAAmC;AAEnC,qFAAkE;AAClE,uEAAgF;AAChF,iDAA6C;AAE7C,4CAA4C;AAC5C,8DAAkD;AAElD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,2DAA2D,CAAC,CAAA;AAE9E,QAAA,iBAAiB,GAAG,IAAI,oBAAM,EAAE,CAAA;AAE7C,yBAAiB,CAAC,IAAI,CAAC,yCAAyC,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;IACxF,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAA;IAExC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC3C,IAAI,WAAW,GAAQ,MAAM,IAAA,yBAAO,EAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC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AAW,CAAA;SAC3B;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,IAAI,GAAG,kBAAkB,CAAA;YACjC,OAAO,CAAC,MAAM,GAAG,GAAG,CAAA;YACpB,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,OAAO,CAAA;SACzB;KACF;AACH,CAAC,CAAC,CAAA;AAEF,SAAS,eAAe,CAAC,UAAU;IACjC,IAAI,SAAS,GAAG,EAAE,CAAA;IAClB,IAAI,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;QAC3B,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IACxB,CAAC,CAAC,CAAA;IAEF,KAAK,IAAI,IAAI,IAAI,GAAG,EAAE;QACpB,IAAI,KAAK,GAAG,CAAC,CAAA;QAEb,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YACpB,IAAI,OAAO,KAAK,IAAI,EAAE;gBACpB,KAAK,IAAI,CAAC,CAAA;aACX;QACH,CAAC,CAAC,CAAA;QAEF,SAAS,CAAC,IAAI,CAAC;YACb,aAAa,EAAE,IAAI;YACnB,GAAG,EAAE,KAAK;SACX,CAAC,CAAA;KACH;IAED,SAAS,GAAG,SAAS,CAAC,MAAM,CAC1B,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,KAAK,KAAK,CAAC,aAAa,CAAC,CAC/F,CAAA;IACD,OAAO,SAAS,CAAA;AAClB,CAAC","sourcesContent":["import Router from 'koa-router'\nimport { v4 as uuidv4 } from 'uuid'\n\nimport { StoreAPI } from '@things-factory/integration-marketplace'\nimport { createPayloadLog, PayloadType } from '@things-factory/integration-base'\nimport { sleep } from '@things-factory/utils'\n\nimport { SHIPPING_TYPE } from '../constants'\nimport { getShop } from '../utils/tokencraft-util'\n\nconst debug = require('debug')('things-factory:integration-sellercraft:sellercraft-router')\n\nexport const sellercraftRouter = new Router()\n\nsellercraftRouter.post('/sellercraft/store/update-product-price', async (context, next) => {\n const requestBody = context.request.body\n\n for (var i = 0; i < requestBody.length; i++) {\n let mappedStore: any = await getShop(context, requestBody[i].channel_id, requestBody[i].shop_id)\n var result\n\n try {\n if (requestBody[i].variant.native_variant_id != requestBody[i].native_product_id) {\n const req = {\n costPrice: requestBody[i].variant.full_price,\n sellPrice: requestBody[i].variant.sale_price,\n productId: requestBody[i].native_product_id,\n variationId: requestBody[i].variant.native_variant_id,\n variationSku: requestBody[i].variant.sku,\n context: { state: { domain: null } }\n }\n result = await StoreAPI.updateStoreProductVariationPrice(mappedStore, req)\n } else {\n const req = {\n costPrice: requestBody[i].variant.full_price,\n sellPrice: requestBody[i].variant.sale_price,\n productId: requestBody[i].native_product_id,\n variationSku: requestBody[i].variant.sku,\n context: { state: { domain: null } }\n }\n result = await StoreAPI.updateStoreProductPrice(mappedStore, req)\n }\n\n debug(result)\n\n context.type = 'application/json'\n context.status = 200\n context.body = 'Succeeded'\n } catch (e) {\n context.type = 'application/json'\n context.status = 500\n context.body = e.message\n }\n }\n})\n\nsellercraftRouter.post('/sellercraft/store/update-product-stock', async (context, next) => {\n const requestBody = context.request.body\n for (var i = 0; i < requestBody.length; i++) {\n let mappedStore: any = await getShop(context, requestBody[i].channel_id, requestBody[i].shop_id)\n var result\n\n try {\n if (requestBody[i].variant.native_variant_id != requestBody[i].native_product_id) {\n const req = {\n qty: requestBody[i].variant.stock,\n itemId: requestBody[i].native_product_id,\n variationId: requestBody[i].variant.native_variant_id,\n distributors: requestBody[i].distributors || [], // for Magento\n variationSku: requestBody[i].variant.sku,\n locationId: requestBody[i]?.variant?.extra_metadata?.locationId, // for Shopify\n inventoryItemId: requestBody[i]?.variant?.extra_metadata?.inventoryItemId, // for Shopify\n context: { state: { domain: null } }\n }\n if (req.locationId) {\n let location = JSON.parse(req.locationId)\n req.qty -= await StoreAPI.getStoreProductVariationStock(mappedStore, { variantId: req.variationId })\n req.locationId = location[0].location_id\n }\n result = await StoreAPI.updateStoreProductVariationStock(mappedStore, req)\n } else {\n const req = {\n qty: requestBody[i].variant.stock,\n itemId: requestBody[i].native_product_id,\n distributors: requestBody[i].distributors || [], // for Magento\n variationSku: requestBody[i].variant.sku,\n context: { state: { domain: null } }\n }\n result = await StoreAPI.updateStoreProductStock(mappedStore, req)\n }\n\n debug(result)\n\n context.type = 'application/json'\n context.status = 200\n context.body = 'Succeeded'\n } catch (e) {\n context.type = 'application/json'\n context.status = 500\n context.body = e.message\n }\n }\n})\n\nsellercraftRouter.post('/sellercraft/store/update-order-status', async (context, next) => {\n try {\n const requestBody = context.request.body\n var result: any = {}\n let mappedStore: any = await getShop(context, requestBody.channel_id, requestBody.shop_id)\n let packageIds: any =\n mappedStore.platform == 'tiktok'\n ? requestBody?.order_items.map(oi => {\n return oi.package_id\n })\n : []\n\n const reqBody = {\n orderId: requestBody.native_order_id,\n status: requestBody.order_status,\n carrier: requestBody?.shipper_last_mile,\n trackingNo: requestBody?.tracking_number,\n orderItems: unmapOrderItems(\n requestBody?.order_items.map(oi => {\n return oi.native_order_item_id\n }) || []\n ),\n isSOF: requestBody?.seller_logistics,\n packageIds: [...new Set(packageIds)] || [],\n locations:\n mappedStore.platform == 'shopify'\n ? requestBody?.order_items.map(oi => {\n let jsonLocation = oi.extra_metadata.locationId\n return JSON.parse(jsonLocation)[0].location_id\n })\n : null,\n context: { state: { domain: null } }\n }\n\n let responseBody: any = { operation_id: uuidv4() }\n try {\n try {\n if (mappedStore.platform == 'tiktok') {\n for (let packageId of reqBody.packageIds) {\n result = (await StoreAPI.updateOrderStatus(mappedStore, { packageId, status: reqBody.status })) || {}\n }\n } else {\n result = (await StoreAPI.updateOrderStatus(mappedStore, reqBody)) || {}\n }\n\n debug(result)\n } catch (e) {\n if (e?.requiredDocument) result.requiredDocument = e.requiredDocument\n }\n\n if (result?.requiredDocument) {\n // call document api and ingest channel order package\n const order: any = await StoreAPI.getStoreOrder(mappedStore, { orderId: reqBody.orderId })\n let orderPackage: any = order ? (order[0]?.orderPackage ? order[0].orderPackage : {}) : {}\n if (orderPackage) {\n const packageId: string = orderPackage.packageId\n\n let orderDocument: any = orderPackage.orderDocument\n if (orderDocument?.length == 0) {\n let hasDocument: boolean = false\n let retries = 0\n while (!hasDocument && retries < 10) {\n orderDocument = await StoreAPI.getStoreOrderDocument(mappedStore, { packageId, documentType: 1 })\n if (orderDocument?.length > 0) {\n hasDocument = true\n break\n }\n await sleep(1000)\n retries++\n }\n }\n\n // Order Package Payload\n let newOrderPackage: any =\n {\n channel_shop_id: mappedStore.channelShopId,\n native_order_id: reqBody.orderId,\n native_package_id: orderPackage.packageId.toString(),\n shipping_tracking_code: orderPackage.trackingNumber,\n shipping_type_value: orderPackage?.shippingType ? orderPackage.shippingType : SHIPPING_TYPE.DROP_SHIPPING,\n warehouse_code: SHIPPING_TYPE.DROP_SHIPPING,\n shipper: {\n name: orderPackage.shippingProvider,\n is_cod_supported: orderPackage?.isCodSupport ? orderPackage.isCodSupport : false\n },\n documents:\n orderDocument?.map(doc => {\n return {\n file: doc.file,\n file_type_value: doc.fileTypeValue,\n mime_type: doc.mimeType\n }\n }) || [],\n shipper_last_mile: {\n name: orderPackage.shippingProvider,\n is_cod_supported: orderPackage?.isCodSupport ? orderPackage.isCodSupport : false\n },\n order_item_ids: orderPackage?.orderListIdList\n ? orderPackage.orderListIdList\n : reqBody.orderItems.map(oi => {\n return oi.order_item_id\n })\n } || {}\n\n responseBody.package = newOrderPackage\n }\n responseBody.response_code = 'E0'\n responseBody.message = 'Success'\n }\n\n responseBody.time = Math.floor(new Date(new Date().toUTCString()).getTime() / 1000)\n\n try {\n createPayloadLog(\n mappedStore.channelShopId,\n '/sellercraft/store/update-order-status',\n requestBody,\n responseBody,\n null,\n PayloadType.INGESTION,\n 'hub-api'\n )\n } catch (e) {}\n\n context.type = 'application/json'\n context.status = 200\n context.body = responseBody\n\n await next()\n } catch (e) {\n responseBody.response_code = 'E1'\n responseBody.message = e.message\n\n context.type = 'application/json'\n context.status = 500\n context.body = responseBody\n try {\n createPayloadLog(\n mappedStore?.channelShopId,\n '/sellercraft/store/update-order-status',\n requestBody,\n responseBody,\n null,\n PayloadType.INGESTION,\n 'hub-api'\n )\n } catch (e) {}\n }\n } catch (e) {}\n})\n\nsellercraftRouter.post('/sellercraft/store/update-product-attribute', async (context, next) => {\n const requestBody = context.request.body\n let mappedStore: any = await getShop(context, requestBody.channel_id, requestBody.shop_id)\n\n let { product_sku: productSku, native_product_id: itemId, variants } = requestBody\n\n variants.map(variant => {\n let { variant_sku: variantSku, native_variant_id: variantId, attributes } = variant\n\n attributes.map(attribute => {\n let { native_attribute_id: id, attribute_key: name, attribute_value: value } = attribute\n\n return {\n id,\n name,\n value\n }\n })\n\n return {\n variantSku,\n variantId,\n attributes\n }\n })\n\n for (var i = 0; i < variants.length; i++) {\n try {\n let variant = variants[i]\n await StoreAPI.updateProductAttribute(mappedStore, {\n productSku,\n itemId,\n variant,\n context: { state: { domain: null } }\n })\n context.type = 'application/json'\n context.status = 200\n context.body = 'Succeeded'\n } catch (e) {\n context.type = 'application/json'\n context.status = 500\n context.body = e.message\n }\n }\n})\n\nfunction unmapOrderItems(orderItems) {\n let itemsList = []\n let res = orderItems.map(e => {\n return e.split('-')[0]\n })\n\n for (let item of res) {\n let count = 0\n\n res.forEach(element => {\n if (element === item) {\n count += 1\n }\n })\n\n itemsList.push({\n order_item_id: item,\n qty: count\n })\n }\n\n itemsList = itemsList.filter(\n (value, index, self) => index === self.findIndex(t => t.order_item_id === value.order_item_id)\n )\n return itemsList\n}\n"]}