@things-factory/integration-marketplace 4.2.5 → 4.2.7

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 (55) hide show
  1. package/dist-server/controllers/index.js +1 -0
  2. package/dist-server/controllers/index.js.map +1 -1
  3. package/dist-server/controllers/tiktok/apis/echo.js +19 -0
  4. package/dist-server/controllers/tiktok/apis/echo.js.map +1 -0
  5. package/dist-server/controllers/tiktok/apis/get-store-order.js +113 -0
  6. package/dist-server/controllers/tiktok/apis/get-store-order.js.map +1 -0
  7. package/dist-server/controllers/tiktok/apis/get-store-orders.js +48 -0
  8. package/dist-server/controllers/tiktok/apis/get-store-orders.js.map +1 -0
  9. package/dist-server/controllers/tiktok/apis/get-store-product-attributes.js +30 -0
  10. package/dist-server/controllers/tiktok/apis/get-store-product-attributes.js.map +1 -0
  11. package/dist-server/controllers/tiktok/apis/get-store-product-categories.js +28 -0
  12. package/dist-server/controllers/tiktok/apis/get-store-product-categories.js.map +1 -0
  13. package/dist-server/controllers/tiktok/apis/get-store-product.js +91 -0
  14. package/dist-server/controllers/tiktok/apis/get-store-product.js.map +1 -0
  15. package/dist-server/controllers/tiktok/apis/get-store-products.js +36 -0
  16. package/dist-server/controllers/tiktok/apis/get-store-products.js.map +1 -0
  17. package/dist-server/controllers/tiktok/apis/index.js +23 -0
  18. package/dist-server/controllers/tiktok/apis/index.js.map +1 -0
  19. package/dist-server/controllers/tiktok/apis/update-order-status.js +24 -0
  20. package/dist-server/controllers/tiktok/apis/update-order-status.js.map +1 -0
  21. package/dist-server/controllers/tiktok/apis/update-store-product-variation-price.js +28 -0
  22. package/dist-server/controllers/tiktok/apis/update-store-product-variation-price.js.map +1 -0
  23. package/dist-server/controllers/tiktok/apis/update-store-product-variation-stock.js +32 -0
  24. package/dist-server/controllers/tiktok/apis/update-store-product-variation-stock.js.map +1 -0
  25. package/dist-server/controllers/tiktok/client/index.js +15 -0
  26. package/dist-server/controllers/tiktok/client/index.js.map +1 -0
  27. package/dist-server/controllers/tiktok/client/signature.js +63 -0
  28. package/dist-server/controllers/tiktok/client/signature.js.map +1 -0
  29. package/dist-server/controllers/tiktok/client/tiktok.js +93 -0
  30. package/dist-server/controllers/tiktok/client/tiktok.js.map +1 -0
  31. package/dist-server/controllers/tiktok/client/types.js +3 -0
  32. package/dist-server/controllers/tiktok/client/types.js.map +1 -0
  33. package/dist-server/controllers/tiktok/index.js +30 -0
  34. package/dist-server/controllers/tiktok/index.js.map +1 -0
  35. package/dist-server/controllers/tiktok/platform-action.js +44 -0
  36. package/dist-server/controllers/tiktok/platform-action.js.map +1 -0
  37. package/package.json +2 -2
  38. package/server/controllers/index.ts +1 -0
  39. package/server/controllers/tiktok/apis/echo.ts +14 -0
  40. package/server/controllers/tiktok/apis/get-store-order.ts +133 -0
  41. package/server/controllers/tiktok/apis/get-store-orders.ts +52 -0
  42. package/server/controllers/tiktok/apis/get-store-product-attributes.ts +29 -0
  43. package/server/controllers/tiktok/apis/get-store-product-categories.ts +27 -0
  44. package/server/controllers/tiktok/apis/get-store-product.ts +95 -0
  45. package/server/controllers/tiktok/apis/get-store-products.ts +38 -0
  46. package/server/controllers/tiktok/apis/index.ts +10 -0
  47. package/server/controllers/tiktok/apis/update-order-status.ts +20 -0
  48. package/server/controllers/tiktok/apis/update-store-product-variation-price.ts +24 -0
  49. package/server/controllers/tiktok/apis/update-store-product-variation-stock.ts +28 -0
  50. package/server/controllers/tiktok/client/index.ts +2 -0
  51. package/server/controllers/tiktok/client/signature.ts +78 -0
  52. package/server/controllers/tiktok/client/tiktok.ts +139 -0
  53. package/server/controllers/tiktok/client/types.ts +20 -0
  54. package/server/controllers/tiktok/index.ts +8 -0
  55. package/server/controllers/tiktok/platform-action.ts +48 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature.js","sourceRoot":"","sources":["../../../../server/controllers/tiktok/client/signature.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAG3B;;;;GAIG;AACH,M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AE,WAAW;KAC1B,CAAA;IAED,IAAI,eAAe,GAAQ;QACzB,OAAO,EAAE,mBAAmB,CAAC,OAAO;QACpC,SAAS,EAAE,mBAAmB,CAAC,SAAS;KACzC,CAAA;IAED,IAAI,MAAM,EAAE;QACV,mBAAmB,CAAC,OAAO,GAAG,MAAM,CAAA;QAEpC,eAAe,CAAC,OAAO,GAAG,MAAM,CAAA;KACjC;IAED,uCACK,mBAAmB,KACtB,IAAI,EAAE,IAAA,mBAAW,EAAC,SAAS,EAAE,OAAO,kCAAO,OAAO,GAAK,eAAe,EAAG,IAC1E;AACH,CAAC;AApCD,kEAoCC"}
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Tiktok = void 0;
7
+ const node_fetch_1 = __importDefault(require("node-fetch"));
8
+ const signature_1 = require("./signature");
9
+ const debug = require('debug')('things-factory:integration-marketplace:tiktok');
10
+ class Tiktok {
11
+ constructor(config) {
12
+ this.config = Object.assign({}, config);
13
+ }
14
+ getBaseURL() {
15
+ return `https://open-api.tiktokglobalshop.com`;
16
+ }
17
+ /**
18
+ * @summary Get Method
19
+ * @description Using v3 API, map the consumer_key, consumer_secret to the endpoint path.
20
+ * X-WP-Total is to get the total items from the response
21
+ */
22
+ async get(path, params) {
23
+ const { appKey, appSecret, accessToken, channelShopId } = this.config;
24
+ const qs = Object.entries(Object.assign(Object.assign({}, params), (0, signature_1.makePublicRequestParameters)(appKey, appSecret, path, accessToken, channelShopId, params)))
25
+ .map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`)
26
+ .join('&');
27
+ const endpoint = `${this.getBaseURL()}${path}?${qs ? qs : ''}`;
28
+ debug('endpoint', endpoint);
29
+ const response = await (0, node_fetch_1.default)(endpoint, {
30
+ headers: {
31
+ 'Content-Type': 'application/json'
32
+ }
33
+ });
34
+ var result = {};
35
+ const resResult = await response.json();
36
+ result.data = resResult.data;
37
+ debug('response result', result);
38
+ return result;
39
+ }
40
+ async post(path, data = {}) {
41
+ const { appKey, appSecret, accessToken, channelShopId } = this.config;
42
+ debug('data', data);
43
+ const jsondata = JSON.stringify(data);
44
+ const { app_key, timestamp, access_token, sign, shop_id } = (0, signature_1.makePublicRequestParameters)(appKey, appSecret, path, accessToken, channelShopId);
45
+ const qs = Object.entries({
46
+ app_key,
47
+ timestamp,
48
+ access_token,
49
+ sign,
50
+ shop_id
51
+ })
52
+ .map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`)
53
+ .join('&');
54
+ const endpoint = `${this.getBaseURL()}${path}?${qs ? '&' + qs : ''}`;
55
+ const response = await (0, node_fetch_1.default)(endpoint, {
56
+ method: 'post',
57
+ headers: {
58
+ 'Content-Type': 'application/json'
59
+ },
60
+ body: jsondata
61
+ });
62
+ const result = await response.json();
63
+ debug('response result', result);
64
+ return result;
65
+ }
66
+ async put(path, data = {}) {
67
+ const { appKey, appSecret, accessToken, channelShopId } = this.config;
68
+ debug('data', data);
69
+ const jsondata = JSON.stringify(data);
70
+ const { app_key, timestamp, access_token, sign } = (0, signature_1.makePublicRequestParameters)(appKey, appSecret, path, accessToken, channelShopId);
71
+ const qs = Object.entries({
72
+ app_key,
73
+ timestamp,
74
+ access_token,
75
+ sign
76
+ })
77
+ .map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`)
78
+ .join('&');
79
+ const endpoint = `${this.getBaseURL()}${path}?${qs ? '&' + qs : ''}`;
80
+ const response = await (0, node_fetch_1.default)(endpoint, {
81
+ method: 'put',
82
+ headers: {
83
+ 'Content-Type': 'application/json'
84
+ },
85
+ body: jsondata
86
+ });
87
+ const result = await response.json();
88
+ debug('response result', result);
89
+ return result;
90
+ }
91
+ }
92
+ exports.Tiktok = Tiktok;
93
+ //# sourceMappingURL=tiktok.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiktok.js","sourceRoot":"","sources":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iBAAiB,EAAE,MAAM,CAAC,CAAA;QAEhC,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AA5HD,wBA4HC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../server/controllers/tiktok/client/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ var __importStar = (this && this.__importStar) || function (mod) {
18
+ if (mod && mod.__esModule) return mod;
19
+ var result = {};
20
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
21
+ __setModuleDefault(result, mod);
22
+ return result;
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ __exportStar(require("./client"), exports);
26
+ const store_api_1 = require("../store-api");
27
+ const platform_action_1 = require("./platform-action");
28
+ const APIS = __importStar(require("./apis"));
29
+ store_api_1.StoreAPI.registerPlatform('tiktok', platform_action_1.action, APIS);
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/controllers/tiktok/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAwB;AAExB,4CAAuC;AAEvC,uDAA0C;AAC1C,6CAA8B;AAE9B,oBAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,wBAAM,EAAE,IAAI,CAAC,CAAA"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.action = void 0;
4
+ const tiktok_1 = require("./client/tiktok");
5
+ function substitute(path, obj) {
6
+ var props = [];
7
+ var re = /{([^}]+)}/g;
8
+ var text;
9
+ while ((text = re.exec(path))) {
10
+ props.push(text[1]);
11
+ }
12
+ var result = path;
13
+ props.forEach(prop => {
14
+ let value = obj[prop.trim()];
15
+ result = result.replace(`{${prop}}`, value === undefined ? '' : value);
16
+ });
17
+ return result;
18
+ }
19
+ /**
20
+ * @summary Building Path Method and Payload
21
+ * @description After denormalise of data is done,
22
+ * platform API method will be called with its path and payload,
23
+ * this section is to build path and substitution of the resource in url as well as the payload for body request.
24
+ * Every Tiktok API call requires consumer_key, consumer_secret, access_token.
25
+ * consumer_key, consumer_secret, access_token are retrieved from tokencraft
26
+ * to avoid permission error from TikTok.
27
+ */
28
+ const action = async ({ store, method = 'get', path, request }) => {
29
+ const client = new tiktok_1.Tiktok({
30
+ appKey: store.accessKey || '5p6q6g',
31
+ appSecret: store.accessSecret || 'c30cf452265ab418514bb81fa49fc333aecbf081',
32
+ accessToken: store.accessToken,
33
+ channelShopId: store.channelShopId
34
+ });
35
+ const { resource = {}, payload = {} } = request;
36
+ path = substitute(path, resource);
37
+ var response = await client[method](path, payload);
38
+ if (response.code) {
39
+ throw response;
40
+ }
41
+ return response;
42
+ };
43
+ exports.action = action;
44
+ //# sourceMappingURL=platform-action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform-action.js","sourceRoot":"","sources":["../../../server/controllers/tiktok/platform-action.ts"],"names":[],"mappings":";;;AAAA,4CAAwC;AAExC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,OAAO,CAAC,CAAA;IAClD,IAAI,QAAQ,CAAC,IAAI,EAAE;QACjB,MAAM,QAAQ,CAAA;KACf;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAlBY,QAAA,MAAM,UAkBlB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/integration-marketplace",
3
- "version": "4.2.5",
3
+ "version": "4.2.7",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -52,5 +52,5 @@
52
52
  "nock": "^13.0.2",
53
53
  "should": "^13.2.3"
54
54
  },
55
- "gitHead": "e1447c2e0c5c1ad9375e84291f688b7ecdbeee40"
55
+ "gitHead": "7a65abffbd9d05961b83bb31153b1c021ab607eb"
56
56
  }
@@ -3,6 +3,7 @@ import './shopee'
3
3
  import './shopify'
4
4
  import './zalora'
5
5
  import './woocommerce'
6
+ import './tiktok'
6
7
 
7
8
  export * from './shopify'
8
9
  export * from './store-api'
@@ -0,0 +1,14 @@
1
+ export function echo() {
2
+ return {
3
+ path: '/echo',
4
+ denormalize(req) {
5
+ return { ...req }
6
+ },
7
+ normalize(res) {
8
+ return { ...res }
9
+ },
10
+ action({ store, method, path, request, platformAction }) {
11
+ return { ...request }
12
+ }
13
+ }
14
+ }
@@ -0,0 +1,133 @@
1
+ /* https://bytedance.feishu.cn/docs/doccnDyz5Bbk26iOdejbBRBlLrb#ytBXoS */
2
+
3
+ export function getStoreOrder() {
4
+ return {
5
+ method: 'post',
6
+ path: '/api/orders/detail/query',
7
+ denormalize(req) {
8
+ var { orderIdList } = req || {}
9
+
10
+ return { payload: { order_id_list: orderIdList } }
11
+ },
12
+ async normalize(res) {
13
+ const { data } = res
14
+ const orderList = data.order_list
15
+
16
+ let results: any[] = []
17
+ for (let i = 0; i < orderList.length; i++) {
18
+ const order: any = orderList[i]
19
+ const {
20
+ order_id: name,
21
+ order_id: orderNo,
22
+ payment_method: paymentMethod,
23
+ payment_info: paymentInfo,
24
+ order_status: status,
25
+ ext_status: extStatus,
26
+ create_time,
27
+ update_time,
28
+ rts_sla,
29
+ recipient_address: recipientAddress,
30
+ item_list: itemList
31
+ } = order
32
+
33
+ let orderStatus: string = `ttk_${status}`
34
+ switch (extStatus) {
35
+ case 201:
36
+ case 203:
37
+ orderStatus = `ttk_${extStatus}`
38
+ break
39
+ default:
40
+ orderStatus = `ttk_${status}`
41
+ }
42
+
43
+ var orderUpdatedAt = new Date(update_time * 1000)
44
+ var orderCreatedAt = new Date(Number(create_time))
45
+ var slaExpiresAt = new Date(rts_sla * 1000)
46
+ let docRefNo = orderNo
47
+
48
+ let orderItems = itemList.map(item => {
49
+ var { product_id: name, sku_id, quantity: qty, sku_original_price, sku_sale_price } = item
50
+
51
+ return {
52
+ name,
53
+ variationId: sku_id,
54
+ qty,
55
+ paidPrice: sku_sale_price,
56
+ orderNo,
57
+ docRefNo,
58
+ total: sku_sale_price,
59
+ totalTax: 0,
60
+ subtotal: sku_original_price,
61
+ subtotalTax: 0,
62
+ slaExpiresAt
63
+ }
64
+ })
65
+
66
+ const { full_address, phone, zipcode, city, region: country, name: firstName } = recipientAddress
67
+
68
+ let billing = {
69
+ address_1: full_address,
70
+ address_2: null,
71
+ address_3: null,
72
+ address_4: null,
73
+ address_5: null,
74
+ phone,
75
+ phone_2: null,
76
+ postcode: zipcode,
77
+ city,
78
+ country,
79
+ first_name: firstName,
80
+ last_name: null
81
+ }
82
+
83
+ let shipping = {
84
+ address_1: full_address,
85
+ address_2: null,
86
+ address_3: null,
87
+ address_4: null,
88
+ address_5: null,
89
+ phone,
90
+ phone_2: null,
91
+ postcode: zipcode,
92
+ city,
93
+ country,
94
+ first_name: firstName,
95
+ last_name: null
96
+ }
97
+
98
+ let orderShipping = {
99
+ address1: shipping.address_1,
100
+ address2: null,
101
+ address3: null,
102
+ address4: null,
103
+ address5: null,
104
+ phone1: shipping.phone,
105
+ phone2: null,
106
+ postCode: shipping.postcode,
107
+ city: shipping.city,
108
+ country: shipping.country,
109
+ collectionCurrency: paymentInfo.currency,
110
+ attentionTo: shipping.first_name
111
+ }
112
+
113
+ results.push({
114
+ name,
115
+ orderNo,
116
+ status: `ttk_${status}`,
117
+ orderCreatedAt,
118
+ orderUpdatedAt,
119
+ totalAmount: paymentInfo.total_amount,
120
+ itemCount: itemList.length,
121
+ orderItems,
122
+ orderShipping,
123
+ billing,
124
+ shipping,
125
+ firstName,
126
+ lastName: null
127
+ })
128
+ }
129
+
130
+ return results
131
+ }
132
+ }
133
+ }
@@ -0,0 +1,52 @@
1
+ /* https://bytedance.feishu.cn/wiki/wikcntMLczW460imZUfYqaa1Dng#jIY8hJ */
2
+
3
+ import { StoreAPI } from '../../store-api'
4
+
5
+ export function getStoreOrders() {
6
+ return {
7
+ method: 'post',
8
+ path: '/api/orders/search',
9
+ denormalize(req) {
10
+ var { pagination, fromDate, toDate, nextCursor } = req || {}
11
+ var { page, limit } = pagination || { page: 0, limit: 100 }
12
+
13
+ var create_time_from = Math.floor(new Date(fromDate).getTime() / 1000)
14
+ var create_time_to = Math.floor(new Date(toDate).getTime() / 1000)
15
+
16
+ var payload = {
17
+ page_size: limit,
18
+ cursor: nextCursor,
19
+ create_time_from,
20
+ create_time_to
21
+ }
22
+
23
+ return { payload }
24
+ },
25
+ async normalize(res, { store }) {
26
+ const { data } = res
27
+
28
+ var more: boolean = data?.more || false
29
+ var nextCursor: string = more ? data.next_cursor : null
30
+ const orderList: any[] = data?.order_list || []
31
+ debugger
32
+ let results: any[] = []
33
+ let orderIds: any = []
34
+ for (let i = 0; i < orderList.length; i++) {
35
+ const order: any = orderList[i]
36
+ orderIds.push({ ...order })
37
+
38
+ if (orderIds.length <= 20) {
39
+ const orderIdList: any = orderIds.map(orderId => orderId.order_id)
40
+ const orderDetails: any[] = await StoreAPI.getStoreOrder(store, { orderIdList })
41
+ orderDetails.map(orderDetail => {
42
+ results.push({ ...orderDetail })
43
+ })
44
+
45
+ orderIds = []
46
+ }
47
+ }
48
+
49
+ return { results, more, nextCursor }
50
+ }
51
+ }
52
+ }
@@ -0,0 +1,29 @@
1
+ /* https://bytedance.feishu.cn/docs/doccnDyz5Bbk26iOdejbBRBlLrb#WBz4V0 */
2
+
3
+ export function getStoreProductAttributes() {
4
+ return {
5
+ method: 'get',
6
+ path: '/api/products/attributes',
7
+ denormalize(req) {
8
+ const { categoryId } = req
9
+ return { payload: { category_id: categoryId } }
10
+ },
11
+ normalize(res) {
12
+ const { data } = res
13
+
14
+ let results: any = []
15
+ data.attributes.map(item => {
16
+ let result: any = {
17
+ id: item.id,
18
+ name: item.local_display_name,
19
+ attributeType: item.attribute_type,
20
+ parent: !item.is_leaf ? 0 : item.parent_id
21
+ }
22
+
23
+ results.push(result)
24
+ })
25
+
26
+ return results
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,27 @@
1
+ /* https://bytedance.feishu.cn/docs/doccnDyz5Bbk26iOdejbBRBlLrb#jIY8hJ */
2
+
3
+ export function getStoreProductCategories() {
4
+ return {
5
+ method: 'get',
6
+ path: '/api/products/categories',
7
+ denormalize(req) {
8
+ return { payload: {} }
9
+ },
10
+ normalize(res) {
11
+ const { data } = res
12
+
13
+ let results: any = []
14
+ data.category_list.map(item => {
15
+ let result: any = {
16
+ id: item.id,
17
+ name: item.local_display_name,
18
+ parent: item.is_leaf ? item.parent_id : 0
19
+ }
20
+
21
+ results.push(result)
22
+ })
23
+
24
+ return { results, total: 1 }
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,95 @@
1
+ /* https://bytedance.feishu.cn/docs/doccnDyz5Bbk26iOdejbBRBlLrb#ytBXoS */
2
+
3
+ /* status: 0-all, 1-draft, 2-pending, 3-failed, 4-live, 5-seller_deactivated,
4
+ 6-platform-deactivated, 7-freeze, 8-deleted
5
+ */
6
+
7
+ export function getStoreProduct() {
8
+ return {
9
+ method: 'get',
10
+ path: '/api/products/details',
11
+ denormalize(req) {
12
+ var { productId } = req || {}
13
+
14
+ return { payload: { product_id: productId } }
15
+ },
16
+ async normalize(res) {
17
+ const { data } = res
18
+
19
+ const productVariations: any[] = data.skus
20
+
21
+ let variants: any[] = []
22
+ if (productVariations && productVariations?.length > 0) {
23
+ variants = productVariations.map(variant => {
24
+ let totalProductQty: number = 0
25
+ let stockInfos = variant.stock_infos
26
+ stockInfos.map(stockInfo => {
27
+ totalProductQty += stockInfo.available_stock
28
+ })
29
+
30
+ return {
31
+ variationId: variant.id,
32
+ variationSku: variant.seller_sku || variant.id.toString(),
33
+ channelSku: variant.seller_sku || variant.id.toString(),
34
+ name: data.product_name,
35
+ qty: totalProductQty,
36
+ primaryUnit: 'N/A',
37
+ primaryUnitValue: data.package_weight === '' ? null : parseFloat(data.package_weight),
38
+ costPrice: variant.price.original_price === '' ? null : parseFloat(variant.price.original_price),
39
+ sellPrice: variant.price.original_price === '' ? null : parseFloat(variant.price.original_price),
40
+ isEnabled: data.product_status == 4 ? true : false,
41
+ length: data?.package_length ? data.package_length * 10 : 1,
42
+ width: data?.package_width ? data.package_width * 10 : 1,
43
+ height: data?.package_height ? data.package_height * 10 : 1,
44
+ weight: data.package_weight === '' ? null : parseFloat(data.package_weight)
45
+ }
46
+ })
47
+ } else {
48
+ variants = [
49
+ {
50
+ variationId: data.product_id,
51
+ variationSku: data.product_name,
52
+ channelSku: data.product_name,
53
+ name: data.product_name,
54
+ qty: 0,
55
+ primaryUnit: 'N/A',
56
+ primaryUnitValue: data.package_weight === '' ? null : parseFloat(data.package_weight),
57
+ costPrice: null,
58
+ sellPrice: null,
59
+ isEnabled: data.product_status == 4 ? true : false,
60
+ length: data?.package_length ? data.package_length * 10 : 1,
61
+ width: data?.package_width ? data.package_width * 10 : 1,
62
+ height: data?.package_height ? data.package_height * 10 : 1,
63
+ weight: data.package_weight === '' ? null : parseFloat(data.package_weight)
64
+ }
65
+ ]
66
+ }
67
+
68
+ const result = {
69
+ itemId: data.product_id,
70
+ name: data.product_name,
71
+ brand: data?.brand?.name || null,
72
+ isVerified: data.product_status == 4 ? true : false,
73
+ categoryId: data?.category_list?.length > 0 ? data.category_list[0].id : '',
74
+ images: getImageUrl(data.images),
75
+ variations: variants
76
+ }
77
+
78
+ return result
79
+ }
80
+ }
81
+ }
82
+
83
+ function getImageUrl(images) {
84
+ let imageSrc: any = []
85
+
86
+ if (images) {
87
+ images.map(image => {
88
+ image.url_list.map(url => {
89
+ imageSrc.push(url)
90
+ })
91
+ })
92
+ }
93
+
94
+ return imageSrc
95
+ }
@@ -0,0 +1,38 @@
1
+ /* https://bytedance.feishu.cn/docs/doccnDyz5Bbk26iOdejbBRBlLrb#ytBXoS */
2
+
3
+ /* status: 0-all, 1-draft, 2-pending, 3-failed, 4-live, 5-seller_deactivated,
4
+ 6-platform-deactivated, 7-freeze, 8-deleted
5
+ */
6
+
7
+ import { StoreAPI } from '../../store-api'
8
+
9
+ export function getStoreProducts() {
10
+ return {
11
+ method: 'post',
12
+ path: '/api/products/search',
13
+ denormalize(req) {
14
+ var { pagination } = req || {}
15
+ var { page, limit } = pagination || { page: 0, limit: 100 }
16
+
17
+ return {
18
+ payload: { page_size: limit, page_number: page + 1, search_status: 0 },
19
+ resource: {}
20
+ }
21
+ },
22
+ async normalize(res, { store }) {
23
+ const { data } = res
24
+
25
+ const products: any[] = data?.products || []
26
+ const total: number = data?.total || 0
27
+
28
+ let results: any[] = []
29
+ for (let i = 0; i < products.length; i++) {
30
+ const product: any = products[i]
31
+ const productDetails = await StoreAPI.getStoreProduct(store, { productId: product.id })
32
+ results.push({ ...productDetails })
33
+ }
34
+
35
+ return { results, total }
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,10 @@
1
+ export * from './echo'
2
+ export * from './get-store-order'
3
+ export * from './get-store-orders'
4
+ export * from './get-store-product-attributes'
5
+ export * from './get-store-product-categories'
6
+ export * from './get-store-product'
7
+ export * from './get-store-products'
8
+ export * from './update-store-product-variation-stock'
9
+ export * from './update-store-product-variation-price'
10
+ export * from './update-order-status'
@@ -0,0 +1,20 @@
1
+ export function updateOrderStatus() {
2
+ return {
3
+ path: '/api/order/rts',
4
+ method: 'post',
5
+ async denormalize(req, { store }) {
6
+ let { orderId, status } = req
7
+
8
+ if (status == 'READY_TO_SHIP') {
9
+ return {
10
+ payload: {
11
+ order_id: orderId
12
+ }
13
+ }
14
+ }
15
+ },
16
+ normalize(res) {
17
+ return res
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,24 @@
1
+ export function updateStoreProductVariationPrice() {
2
+ return {
3
+ path: '/api/products/prices',
4
+ method: 'put',
5
+ denormalize(req) {
6
+ const { variationId, sellPrice, productId } = (Array.isArray(req) ? req[0] : req) || {}
7
+
8
+ return {
9
+ payload: {
10
+ product_id: productId,
11
+ skus: [
12
+ {
13
+ id: variationId,
14
+ original_price: sellPrice.toString()
15
+ }
16
+ ]
17
+ }
18
+ }
19
+ },
20
+ normalize(res) {
21
+ return res
22
+ }
23
+ }
24
+ }