@things-factory/integration-marketplace 5.0.0-alpha.38 → 5.0.0-alpha.39

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 (118) 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/magento/apis/get-store-order.js +20 -0
  4. package/dist-server/controllers/magento/apis/get-store-order.js.map +1 -0
  5. package/dist-server/controllers/magento/apis/get-store-orders.js +34 -4
  6. package/dist-server/controllers/magento/apis/get-store-orders.js.map +1 -1
  7. package/dist-server/controllers/magento/apis/get-store-product-categories.js +47 -0
  8. package/dist-server/controllers/magento/apis/get-store-product-categories.js.map +1 -0
  9. package/dist-server/controllers/magento/apis/get-store-products.js +29 -11
  10. package/dist-server/controllers/magento/apis/get-store-products.js.map +1 -1
  11. package/dist-server/controllers/magento/apis/get-store-stock-item.js +1 -1
  12. package/dist-server/controllers/magento/apis/get-store-stock-item.js.map +1 -1
  13. package/dist-server/controllers/magento/apis/index.js +5 -0
  14. package/dist-server/controllers/magento/apis/index.js.map +1 -1
  15. package/dist-server/controllers/magento/apis/update-order-status.js +82 -0
  16. package/dist-server/controllers/magento/apis/update-order-status.js.map +1 -0
  17. package/dist-server/controllers/magento/apis/update-store-product-price.js +28 -0
  18. package/dist-server/controllers/magento/apis/update-store-product-price.js.map +1 -0
  19. package/dist-server/controllers/magento/apis/update-store-product-stock.js +1 -1
  20. package/dist-server/controllers/magento/apis/update-store-product-stock.js.map +1 -1
  21. package/dist-server/controllers/magento/apis/update-store-product-variation-price.js +28 -0
  22. package/dist-server/controllers/magento/apis/update-store-product-variation-price.js.map +1 -0
  23. package/dist-server/controllers/magento/apis/update-store-product-variation-stock.js +1 -1
  24. package/dist-server/controllers/magento/apis/update-store-product-variation-stock.js.map +1 -1
  25. package/dist-server/controllers/magento/magento.js +4 -4
  26. package/dist-server/controllers/magento/magento.js.map +1 -1
  27. package/dist-server/controllers/magento/platform-action.js +1 -0
  28. package/dist-server/controllers/magento/platform-action.js.map +1 -1
  29. package/dist-server/controllers/store-api/index.js +14 -0
  30. package/dist-server/controllers/store-api/index.js.map +1 -1
  31. package/dist-server/controllers/tiktok/apis/echo.js +19 -0
  32. package/dist-server/controllers/tiktok/apis/echo.js.map +1 -0
  33. package/dist-server/controllers/tiktok/apis/get-store-order-document.js +27 -0
  34. package/dist-server/controllers/tiktok/apis/get-store-order-document.js.map +1 -0
  35. package/dist-server/controllers/tiktok/apis/get-store-order-package.js +47 -0
  36. package/dist-server/controllers/tiktok/apis/get-store-order-package.js.map +1 -0
  37. package/dist-server/controllers/tiktok/apis/get-store-order-packages.js +39 -0
  38. package/dist-server/controllers/tiktok/apis/get-store-order-packages.js.map +1 -0
  39. package/dist-server/controllers/tiktok/apis/get-store-order.js +138 -0
  40. package/dist-server/controllers/tiktok/apis/get-store-order.js.map +1 -0
  41. package/dist-server/controllers/tiktok/apis/get-store-orders.js +48 -0
  42. package/dist-server/controllers/tiktok/apis/get-store-orders.js.map +1 -0
  43. package/dist-server/controllers/tiktok/apis/get-store-product-attributes.js +30 -0
  44. package/dist-server/controllers/tiktok/apis/get-store-product-attributes.js.map +1 -0
  45. package/dist-server/controllers/tiktok/apis/get-store-product-categories.js +28 -0
  46. package/dist-server/controllers/tiktok/apis/get-store-product-categories.js.map +1 -0
  47. package/dist-server/controllers/tiktok/apis/get-store-product.js +91 -0
  48. package/dist-server/controllers/tiktok/apis/get-store-product.js.map +1 -0
  49. package/dist-server/controllers/tiktok/apis/get-store-products.js +36 -0
  50. package/dist-server/controllers/tiktok/apis/get-store-products.js.map +1 -0
  51. package/dist-server/controllers/tiktok/apis/index.js +30 -0
  52. package/dist-server/controllers/tiktok/apis/index.js.map +1 -0
  53. package/dist-server/controllers/tiktok/apis/update-order-status.js +28 -0
  54. package/dist-server/controllers/tiktok/apis/update-order-status.js.map +1 -0
  55. package/dist-server/controllers/tiktok/apis/update-store-product-variation-price.js +28 -0
  56. package/dist-server/controllers/tiktok/apis/update-store-product-variation-price.js.map +1 -0
  57. package/dist-server/controllers/tiktok/apis/update-store-product-variation-stock.js +32 -0
  58. package/dist-server/controllers/tiktok/apis/update-store-product-variation-stock.js.map +1 -0
  59. package/dist-server/controllers/tiktok/client/index.js +19 -0
  60. package/dist-server/controllers/tiktok/client/index.js.map +1 -0
  61. package/dist-server/controllers/tiktok/client/signature.js +63 -0
  62. package/dist-server/controllers/tiktok/client/signature.js.map +1 -0
  63. package/dist-server/controllers/tiktok/client/tiktok.js +113 -0
  64. package/dist-server/controllers/tiktok/client/tiktok.js.map +1 -0
  65. package/dist-server/controllers/tiktok/client/types.js +3 -0
  66. package/dist-server/controllers/tiktok/client/types.js.map +1 -0
  67. package/dist-server/controllers/tiktok/index.js +34 -0
  68. package/dist-server/controllers/tiktok/index.js.map +1 -0
  69. package/dist-server/controllers/tiktok/platform-action.js +50 -0
  70. package/dist-server/controllers/tiktok/platform-action.js.map +1 -0
  71. package/dist-server/controllers/woocommerce/apis/get-store-orders.js +2 -1
  72. package/dist-server/controllers/woocommerce/apis/get-store-orders.js.map +1 -1
  73. package/dist-server/controllers/woocommerce/apis/get-store-products.js +19 -8
  74. package/dist-server/controllers/woocommerce/apis/get-store-products.js.map +1 -1
  75. package/dist-server/controllers/woocommerce/apis/update-order-status.js +17 -15
  76. package/dist-server/controllers/woocommerce/apis/update-order-status.js.map +1 -1
  77. package/dist-server/controllers/woocommerce/apis/update-store-product-variation-price.js +1 -1
  78. package/dist-server/controllers/woocommerce/apis/update-store-product-variation-price.js.map +1 -1
  79. package/package.json +15 -15
  80. package/server/controllers/index.ts +1 -0
  81. package/server/controllers/magento/apis/get-store-order.ts +15 -0
  82. package/server/controllers/magento/apis/get-store-orders.ts +36 -4
  83. package/server/controllers/magento/apis/get-store-product-categories.ts +43 -0
  84. package/server/controllers/magento/apis/get-store-products.ts +35 -11
  85. package/server/controllers/magento/apis/get-store-stock-item.ts +1 -1
  86. package/server/controllers/magento/apis/index.ts +5 -0
  87. package/server/controllers/magento/apis/update-order-status.ts +81 -0
  88. package/server/controllers/magento/apis/update-store-product-price.ts +24 -0
  89. package/server/controllers/magento/apis/update-store-product-stock.ts +1 -1
  90. package/server/controllers/magento/apis/update-store-product-variation-price.ts +24 -0
  91. package/server/controllers/magento/apis/update-store-product-variation-stock.ts +1 -1
  92. package/server/controllers/magento/magento.ts +5 -4
  93. package/server/controllers/magento/platform-action.ts +1 -0
  94. package/server/controllers/store-api/index.ts +6 -0
  95. package/server/controllers/tiktok/apis/echo.ts +14 -0
  96. package/server/controllers/tiktok/apis/get-store-order-document.ts +26 -0
  97. package/server/controllers/tiktok/apis/get-store-order-package.ts +46 -0
  98. package/server/controllers/tiktok/apis/get-store-order-packages.ts +43 -0
  99. package/server/controllers/tiktok/apis/get-store-order.ts +171 -0
  100. package/server/controllers/tiktok/apis/get-store-orders.ts +53 -0
  101. package/server/controllers/tiktok/apis/get-store-product-attributes.ts +29 -0
  102. package/server/controllers/tiktok/apis/get-store-product-categories.ts +27 -0
  103. package/server/controllers/tiktok/apis/get-store-product.ts +95 -0
  104. package/server/controllers/tiktok/apis/get-store-products.ts +38 -0
  105. package/server/controllers/tiktok/apis/index.ts +13 -0
  106. package/server/controllers/tiktok/apis/update-order-status.ts +24 -0
  107. package/server/controllers/tiktok/apis/update-store-product-variation-price.ts +24 -0
  108. package/server/controllers/tiktok/apis/update-store-product-variation-stock.ts +28 -0
  109. package/server/controllers/tiktok/client/index.ts +2 -0
  110. package/server/controllers/tiktok/client/signature.ts +78 -0
  111. package/server/controllers/tiktok/client/tiktok.ts +153 -0
  112. package/server/controllers/tiktok/client/types.ts +20 -0
  113. package/server/controllers/tiktok/index.ts +8 -0
  114. package/server/controllers/tiktok/platform-action.ts +54 -0
  115. package/server/controllers/woocommerce/apis/get-store-orders.ts +2 -1
  116. package/server/controllers/woocommerce/apis/get-store-products.ts +35 -24
  117. package/server/controllers/woocommerce/apis/update-order-status.ts +18 -14
  118. package/server/controllers/woocommerce/apis/update-store-product-variation-price.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/integration-marketplace",
3
- "version": "5.0.0-alpha.38",
3
+ "version": "5.0.0-alpha.39",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -25,19 +25,19 @@
25
25
  "test": "DEBUG=things-factory:* NODE_ENV=development npx mocha -r ts-node/register ./test/**/*spec.ts"
26
26
  },
27
27
  "dependencies": {
28
- "@things-factory/apptool-ui": "^5.0.0-alpha.38",
29
- "@things-factory/auth-ui": "^5.0.0-alpha.38",
30
- "@things-factory/biz-base": "^5.0.0-alpha.38",
31
- "@things-factory/code-ui": "^5.0.0-alpha.38",
32
- "@things-factory/context-ui": "^5.0.0-alpha.38",
33
- "@things-factory/grist-ui": "^5.0.0-alpha.38",
34
- "@things-factory/i18n-base": "^5.0.0-alpha.38",
35
- "@things-factory/integration-lmd": "^5.0.0-alpha.38",
36
- "@things-factory/integration-ui": "^5.0.0-alpha.38",
37
- "@things-factory/more-ui": "^5.0.0-alpha.38",
38
- "@things-factory/resource-ui": "^5.0.0-alpha.38",
39
- "@things-factory/setting-ui": "^5.0.0-alpha.38",
40
- "@things-factory/system-ui": "^5.0.0-alpha.38",
28
+ "@things-factory/apptool-ui": "^5.0.0-alpha.39",
29
+ "@things-factory/auth-ui": "^5.0.0-alpha.39",
30
+ "@things-factory/biz-base": "^5.0.0-alpha.39",
31
+ "@things-factory/code-ui": "^5.0.0-alpha.39",
32
+ "@things-factory/context-ui": "^5.0.0-alpha.39",
33
+ "@things-factory/grist-ui": "^5.0.0-alpha.39",
34
+ "@things-factory/i18n-base": "^5.0.0-alpha.39",
35
+ "@things-factory/integration-lmd": "^5.0.0-alpha.39",
36
+ "@things-factory/integration-ui": "^5.0.0-alpha.39",
37
+ "@things-factory/more-ui": "^5.0.0-alpha.39",
38
+ "@things-factory/resource-ui": "^5.0.0-alpha.39",
39
+ "@things-factory/setting-ui": "^5.0.0-alpha.39",
40
+ "@things-factory/system-ui": "^5.0.0-alpha.39",
41
41
  "debug": "^4.1.1",
42
42
  "node-fetch": "^2.6.0",
43
43
  "querystring": "^0.2.1"
@@ -52,5 +52,5 @@
52
52
  "nock": "^13.0.2",
53
53
  "should": "^13.2.3"
54
54
  },
55
- "gitHead": "b5e6badbf7bfb3e509c5d065da635da7c084ffce"
55
+ "gitHead": "23e58562a4724f157c3bc492cdedb7e32efee6a1"
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,15 @@
1
+ export function getStoreOrder() {
2
+ return {
3
+ path: '/orders/{id}',
4
+ method: 'get',
5
+ denormalize(req) {
6
+ let { id } = req
7
+ return {
8
+ resource: { id }
9
+ }
10
+ },
11
+ normalize(res) {
12
+ return res
13
+ }
14
+ }
15
+ }
@@ -63,7 +63,7 @@ export function getStoreOrders() {
63
63
  let docRefNo = orderNo
64
64
 
65
65
  let orderItems = items.map(item => {
66
- var { item_id: name, product_id, qty_ordered: qty, price } = item
66
+ var { item_id: name, product_id, qty_ordered: qty, price, original_price, price, tax_amount, tax_invoiced } = item
67
67
 
68
68
  return {
69
69
  name,
@@ -71,7 +71,11 @@ export function getStoreOrders() {
71
71
  qty,
72
72
  paidPrice: price,
73
73
  orderNo,
74
- docRefNo
74
+ docRefNo,
75
+ total: price,
76
+ totalTax: tax_invoiced,
77
+ subtotal: original_price,
78
+ subtotalTax: tax_amount
75
79
  }
76
80
  })
77
81
 
@@ -110,17 +114,45 @@ export function getStoreOrders() {
110
114
  postCode: postcode,
111
115
  city,
112
116
  country: country_id === 'MY' ? 'Malaysia' : country_id,
113
- collectionCurrency: null,
117
+ collectionCurrency: order.order_currency_code,
114
118
  attentionTo: `${firstname} ${middlename} ${lastname}`
115
119
  }
116
120
 
117
121
  result.orderShipping = orderShipping
122
+
123
+ // For SC mapping
124
+ result.shipping = {
125
+ address_1: street,
126
+ postcode: postcode,
127
+ country: country_id,
128
+ city,
129
+ first_name: firstname,
130
+ last_name: lastname,
131
+ phone: telephone,
132
+ email: order.customer_email
133
+ }
134
+ let billingAddress = order?.billing_address
135
+ result.billing = {
136
+ address_1: billingAddress.street,
137
+ postcode: billingAddress.postcode,
138
+ country: billingAddress.country_id,
139
+ city: billingAddress.city,
140
+ first_name: billingAddress.firstname,
141
+ last_name: billingAddress.lastname,
142
+ phone: billingAddress.telephone,
143
+ email: billingAddress.email
144
+ }
145
+ result.firstName = order.customer_firstname
146
+ result.lastName = order.customer_lastname
147
+ result.isSOF = true
118
148
  }
119
149
 
120
150
  return result
121
151
  })
122
152
 
123
- return { results }
153
+ let more = res.search_criteria.page_size * res.search_criteria.current_page < res.total_count || false
154
+
155
+ return { results, more }
124
156
  }
125
157
  }
126
158
  }
@@ -0,0 +1,43 @@
1
+ export function getStoreProductCategories() {
2
+ return {
3
+ method: 'get',
4
+ path: '/categories/list',
5
+ denormalize(req) {
6
+ var { pagination } = req || {}
7
+ var { page = 0, limit = 100 } = pagination || {}
8
+
9
+ const resource: any = {}
10
+ const payload: any = {
11
+ pageSize: limit,
12
+ currentPage: page
13
+ }
14
+ return { resource, payload }
15
+ },
16
+ normalize(res) {
17
+ let results = res.items
18
+ results = mapCategories(results, [])
19
+ results = results.map(result => {
20
+ let { id, name, parent_id, is_active, children_data } = result
21
+ return {
22
+ id,
23
+ name,
24
+ parent: parent_id,
25
+ isActive: is_active
26
+ // childrenCategories: children_data
27
+ }
28
+ })
29
+ results = results.filter(cat => cat.parent != 0)
30
+ return { results: results }
31
+ }
32
+ }
33
+ }
34
+
35
+ function mapCategories(results, arr) {
36
+ for (let result of results) {
37
+ if (result.children_data?.length > 0) {
38
+ mapCategories(result.children_data, arr)
39
+ }
40
+ arr.push(result)
41
+ }
42
+ return arr
43
+ }
@@ -21,6 +21,8 @@ export function getStoreProducts() {
21
21
  // return res.products
22
22
  let { items, total_count } = res
23
23
 
24
+ let parentLinkList = items.map(e => {return {id: e.id, children: e.extension_attributes.configurable_product_links}})?.filter(e => e.children)
25
+
24
26
  let activeMarketplaceDistributors: any[] = []
25
27
  if (store?.marketplaceDistributors) {
26
28
  activeMarketplaceDistributors = store.marketplaceDistributors.filter(
@@ -32,17 +34,21 @@ export function getStoreProducts() {
32
34
 
33
35
  for (var i = 0; i < items.length; i++) {
34
36
  const product: any = items[i]
35
- const stockItems: any[] = await StoreAPI.getStoreStockItem(store, {
36
- sku: product.sku,
37
- distributors: activeMarketplaceDistributors
38
- })
39
37
 
40
38
  let totalProductQty: number = 0
41
- stockItems.map(stockItem => {
42
- if (stockItem.sku === product.sku) {
43
- totalProductQty += stockItem.qty
44
- }
45
- })
39
+
40
+ try {
41
+ const stockItems: any[] = await StoreAPI.getStoreStockItem(store, {
42
+ sku: product.sku,
43
+ distributors: activeMarketplaceDistributors
44
+ })
45
+
46
+ stockItems.map(stockItem => {
47
+ if (stockItem.sku === product.sku) {
48
+ totalProductQty += stockItem.qty
49
+ }
50
+ })
51
+ } catch (e) {}
46
52
  const productVariations: any[] = await StoreAPI.getStoreProductVariations(store, { sku: product.sku })
47
53
 
48
54
  const result = {
@@ -52,6 +58,14 @@ export function getStoreProducts() {
52
58
  type: product.type_id,
53
59
  hasVariation: false,
54
60
  attributes: [],
61
+ images: product?.custom_attributes?.find(att => att.attribute_code == 'image')?.value
62
+ ? [
63
+ `${store.storeURL}pub/media/catalog/product${
64
+ product?.custom_attributes?.find(att => att.attribute_code == 'image')?.value
65
+ }`
66
+ ]
67
+ : [],
68
+ categoryId: product?.custom_attributes?.find(att => att.attribute_code == 'category_ids').value[0],
55
69
  variations:
56
70
  productVariations.length > 0
57
71
  ? productVariations.map(variant => {
@@ -82,7 +96,17 @@ export function getStoreProducts() {
82
96
  sellPrice: product.price,
83
97
  marketplaceStatus: product.status,
84
98
  primaryUnit: 'lbs',
85
- primaryUnitValue: product.weight
99
+ primaryUnitValue: product.weight,
100
+ length:
101
+ product?.custom_attributes?.find(att => att.attribute_code == 'ts_dimensions_length')?.value *
102
+ 25.4 || 0,
103
+ width:
104
+ product?.custom_attributes?.find(att => att.attribute_code == 'ts_dimensions_width')?.value *
105
+ 25.4 || 0,
106
+ height:
107
+ product?.custom_attributes?.find(att => att.attribute_code == 'ts_dimensions_height')?.value *
108
+ 25.4 || 0,
109
+ weight: product.weight * 453.59237 || 0
86
110
  }
87
111
  ]
88
112
  }
@@ -90,7 +114,7 @@ export function getStoreProducts() {
90
114
  results.push({ ...result })
91
115
  }
92
116
 
93
- return { results, total: total_count }
117
+ return { results, total: total_count, parentLinkList }
94
118
  }
95
119
  }
96
120
  }
@@ -19,7 +19,7 @@ export function getStoreStockItem() {
19
19
  }
20
20
  ]
21
21
 
22
- if (distributors) {
22
+ if (distributors.length > 0) {
23
23
  const distributorsArr = distributors.map(distributor => distributor.name)
24
24
 
25
25
  filterGroups.push({
@@ -9,3 +9,8 @@ export * from './create-order-refund'
9
9
  export * from './create-order-ship'
10
10
  export * from './update-store-product-stock'
11
11
  export * from './update-store-product-variation-stock'
12
+ export * from './get-store-product-categories'
13
+ export * from './update-order-status'
14
+ export * from './get-store-order'
15
+ export * from './update-store-product-price'
16
+ export * from './update-store-product-variation-price'
@@ -0,0 +1,81 @@
1
+ import { StoreAPI } from '../../store-api'
2
+
3
+ export function updateOrderStatus() {
4
+ return {
5
+ method: 'post',
6
+ path: '/{subpath}',
7
+ denormalize(req) {
8
+ let { orderId, status, trackingNo, carrier, orderItems, isSOF } = req
9
+ let pr: any
10
+ if (status == 'READY_TO_SHIP') {
11
+ pr = {
12
+ resource: {
13
+ subpath: `order/${orderId}/ship`
14
+ },
15
+ payload: {
16
+ items: unmapOrderItems(orderItems),
17
+ tracks: isSOF && trackingNo ? [
18
+ {
19
+ carrier_code: carrier,
20
+ track_number: trackingNo,
21
+ title: carrier
22
+ }
23
+ ] : [],
24
+ arguments: {
25
+ extension_attributes: {
26
+ source_code: 'default'
27
+ }
28
+ }
29
+ }
30
+ }
31
+ } else if (status == 'DELIVERED') {
32
+ pr = {
33
+ resource: {
34
+ subpath: `order/${orderId}/invoice`
35
+ }
36
+ }
37
+ } else if (status == 'REFUND_COMPLETE') {
38
+ pr = {
39
+ resource: {
40
+ subpath: `order/${orderId}/refund`
41
+ }
42
+ }
43
+ } else if (status == 'CANCELLED') {
44
+ pr = {
45
+ resource: {
46
+ subpath: `orders/${orderId}/cancel`
47
+ }
48
+ }
49
+ }
50
+ return pr
51
+ },
52
+ normalize(res) {
53
+ return res
54
+ }
55
+ }
56
+ }
57
+
58
+ function unmapOrderItems(orderItems) {
59
+ let itemsList = []
60
+ let res = orderItems.map(e => {
61
+ return e.split('-')[0]
62
+ })
63
+
64
+ for (let item of res) {
65
+ let count = 0
66
+
67
+ res.forEach(element => {
68
+ if (element === item) {
69
+ count += 1
70
+ }
71
+ })
72
+
73
+ itemsList.push({
74
+ order_item_id: item,
75
+ qty: count
76
+ })
77
+ }
78
+
79
+ itemsList = itemsList.filter((value, index, self) => index === self.findIndex(t => t.order_item_id === value.order_item_id))
80
+ return itemsList
81
+ }
@@ -0,0 +1,24 @@
1
+ export function updateStoreProductPrice() {
2
+ return {
3
+ path: '/products/base-prices',
4
+ method: 'post',
5
+ denormalize(req) {
6
+ let { sellPrice, variationSku } = req
7
+
8
+ return {
9
+ payload: {
10
+ prices: [
11
+ {
12
+ price: sellPrice,
13
+ sku: variationSku,
14
+ store_id: 0
15
+ }
16
+ ]
17
+ }
18
+ }
19
+ },
20
+ normalize(res) {
21
+ return res
22
+ }
23
+ }
24
+ }
@@ -6,7 +6,7 @@ export function updateStoreProductStock() {
6
6
  method: 'post',
7
7
  path: '/inventory/source-items',
8
8
  denormalize(req) {
9
- const { variationSku, qty, distributors } = req[0]
9
+ const { variationSku, qty, distributors } = (Array.isArray(req) ? req[0] : req) || {}
10
10
 
11
11
  let sourceItems: any[] = []
12
12
 
@@ -0,0 +1,24 @@
1
+ export function updateStoreProductVariationPrice() {
2
+ return {
3
+ path: '/products/base-prices',
4
+ method: 'post',
5
+ denormalize(req) {
6
+ let { sellPrice, variationSku } = req
7
+
8
+ return {
9
+ payload: {
10
+ prices: [
11
+ {
12
+ price: sellPrice,
13
+ sku: variationSku,
14
+ store_id: 0
15
+ }
16
+ ]
17
+ }
18
+ }
19
+ },
20
+ normalize(res) {
21
+ return res
22
+ }
23
+ }
24
+ }
@@ -6,7 +6,7 @@ export function updateStoreProductVariationStock() {
6
6
  method: 'post',
7
7
  path: '/inventory/source-items',
8
8
  denormalize(req) {
9
- const { variationSku, qty, distributors } = req[0]
9
+ const { variationSku, qty, distributors } = (Array.isArray(req) ? req[0] : req) || {}
10
10
 
11
11
  let sourceItems: any[] = []
12
12
 
@@ -11,6 +11,7 @@ export type MagentoConfig = {
11
11
  oauthConsumerKey: string
12
12
  oauthConsumerSecret: string
13
13
  shop: string
14
+ storeId?: string
14
15
  accessToken?: string
15
16
  }
16
17
 
@@ -154,11 +155,11 @@ export class Magento {
154
155
  }
155
156
 
156
157
  async get(path: string, data: any) {
157
- const { shop, accessToken } = this.config
158
+ const { shop, accessToken, storeId } = this.config
158
159
 
159
160
  const qs = this.objectToMultiarray(data)
160
161
 
161
- const endpoint = `${shop}/rest/V1${path}${qs ? '?' + qs : ''}`
162
+ const endpoint = `${shop}/rest${storeId ? `/${storeId}` : ''}/V1${path}${qs ? '?' + qs : ''}`
162
163
  debug('endpoint', endpoint)
163
164
 
164
165
  const response = await fetch(endpoint, {
@@ -176,13 +177,13 @@ export class Magento {
176
177
  }
177
178
 
178
179
  async post(path: string, data: any = {}) {
179
- const { shop, accessToken } = this.config
180
+ const { shop, accessToken, storeId } = this.config
180
181
 
181
182
  debug('data', data)
182
183
 
183
184
  const jsondata = JSON.stringify(data)
184
185
 
185
- const endpoint = `${shop}/rest/V1${path}`
186
+ const endpoint = `${shop}/rest${storeId ? `/${storeId}` : ''}/V1${path}`
186
187
 
187
188
  const response = await fetch(endpoint, {
188
189
  method: 'post',
@@ -27,6 +27,7 @@ export const action = async ({ store, method = 'get', path, request }) => {
27
27
  oauthConsumerKey,
28
28
  oauthConsumerSecret,
29
29
  shop: store.storeURL,
30
+ storeId: store.storeId,
30
31
  accessToken: store.accessToken
31
32
  })
32
33
 
@@ -66,6 +66,12 @@ export class StoreAPI {
66
66
  @api
67
67
  static getStoreOrder(store, req): any {}
68
68
 
69
+ @api
70
+ static getStoreOrderPackages(store, req): any {}
71
+
72
+ @api
73
+ static getStoreOrderPackage(store, req): any {}
74
+
69
75
  @api
70
76
  static getStoreOrderItems(store, req): any {}
71
77
 
@@ -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,26 @@
1
+ /* https://bytedance.feishu.cn/docs/doccnDyz5Bbk26iOdejbBRBlLrb#ytBXoS */
2
+
3
+ export function getStoreOrderDocument() {
4
+ return {
5
+ method: 'get',
6
+ path: '/api/fulfillment/shipping_document',
7
+ denormalize(req) {
8
+ var { packageId, documentType } = req || {}
9
+
10
+ return { payload: { package_id: packageId, document_type: documentType } }
11
+ },
12
+ async normalize(res) {
13
+ const { data } = res
14
+
15
+ let result: any[] = [
16
+ {
17
+ file: data.doc_url,
18
+ fileTypeValue: 'AWB',
19
+ mimeType: 'application/pdf'
20
+ }
21
+ ]
22
+
23
+ return result
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,46 @@
1
+ /* https://bytedance.feishu.cn/docs/doccnDyz5Bbk26iOdejbBRBlLrb#ytBXoS */
2
+
3
+ export function getStoreOrderPackage() {
4
+ return {
5
+ method: 'get',
6
+ path: '/api/fulfillment/detail',
7
+ denormalize(req) {
8
+ var { packageId } = req || {}
9
+
10
+ return { payload: { package_id: packageId } }
11
+ },
12
+ async normalize(res) {
13
+ const { data } = res
14
+
15
+ let result: any = {
16
+ packageId: data.package_id,
17
+ orderInfoList: data.order_info_list.map(itm => {
18
+ return {
19
+ orderId: itm.order_id,
20
+ skuList: itm.sku_list.map(sku => {
21
+ return {
22
+ skuId: sku.sku_id,
23
+ skuName: sku.sku_name,
24
+ skuImage: sku.sku_image,
25
+ quantity: sku.quantity
26
+ }
27
+ })
28
+ }
29
+ }),
30
+ packageStatus: data.package_status,
31
+ deliveryOption: data.delivery_option,
32
+ shippingProvider: data.shipping_provider,
33
+ shippingProviderId: data.shipping_provider_id,
34
+ trackingNumber: data.tracking_number,
35
+ orderListIdList: data.order_line_id_list,
36
+ pickUpType: data.pick_up_type,
37
+ pickUpStartTime: data.pick_up_start_time,
38
+ pickupEndTime: data.pick_up_end_time,
39
+ createTime: data.create_time,
40
+ updateTime: data.update_time
41
+ }
42
+
43
+ return result
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,43 @@
1
+ /* https://bytedance.feishu.cn/wiki/wikcntMLczW460imZUfYqaa1Dng#jIY8hJ */
2
+
3
+ import { StoreAPI } from '../../store-api'
4
+
5
+ export function getStoreOrderPackages() {
6
+ return {
7
+ method: 'post',
8
+ path: '/api/fulfillment/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 packageList: any[] = data?.package_list || []
31
+
32
+ let results: any[] = []
33
+ for (let i = 0; i < packageList.length; i++) {
34
+ const packageObj: any = packageList[i]
35
+ const packageDetail: any = await StoreAPI.getStoreOrderPackage(store, { packageId: packageObj.package_id })
36
+
37
+ results.push({ ...packageDetail })
38
+ }
39
+
40
+ return { results, more, nextCursor }
41
+ }
42
+ }
43
+ }