@things-factory/integration-marketplace 5.0.0-alpha.51 → 5.0.0-alpha.55

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 (106) hide show
  1. package/dist-server/controllers/lazada/apis/get-store-orders.js +3 -3
  2. package/dist-server/controllers/lazada/apis/get-store-orders.js.map +1 -1
  3. package/dist-server/controllers/lazada/apis/update-store-product-stock.js +2 -2
  4. package/dist-server/controllers/lazada/apis/update-store-product-stock.js.map +1 -1
  5. package/dist-server/controllers/lazada/apis/update-store-product-variation-stock.js +2 -2
  6. package/dist-server/controllers/lazada/apis/update-store-product-variation-stock.js.map +1 -1
  7. package/dist-server/controllers/magento/apis/get-store-orders.js +5 -4
  8. package/dist-server/controllers/magento/apis/get-store-orders.js.map +1 -1
  9. package/dist-server/controllers/magento/apis/update-order-status.js +1 -21
  10. package/dist-server/controllers/magento/apis/update-order-status.js.map +1 -1
  11. package/dist-server/controllers/shopee/apis/get-store-order-payout-dates.js +3 -3
  12. package/dist-server/controllers/shopee/apis/get-store-order-payout-dates.js.map +1 -1
  13. package/dist-server/controllers/shopee/apis/get-store-orders.js +3 -3
  14. package/dist-server/controllers/shopee/apis/get-store-orders.js.map +1 -1
  15. package/dist-server/controllers/shopify/apis/get-store-orders.js +72 -12
  16. package/dist-server/controllers/shopify/apis/get-store-orders.js.map +1 -1
  17. package/dist-server/controllers/shopify/apis/get-store-product-variation-stock.js +23 -0
  18. package/dist-server/controllers/shopify/apis/get-store-product-variation-stock.js.map +1 -0
  19. package/dist-server/controllers/shopify/apis/get-store-products.js +38 -3
  20. package/dist-server/controllers/shopify/apis/get-store-products.js.map +1 -1
  21. package/dist-server/controllers/shopify/apis/index.js +4 -0
  22. package/dist-server/controllers/shopify/apis/index.js.map +1 -1
  23. package/dist-server/controllers/shopify/apis/update-order-status.js +15 -5
  24. package/dist-server/controllers/shopify/apis/update-order-status.js.map +1 -1
  25. package/dist-server/controllers/shopify/apis/update-store-product-price.js +29 -0
  26. package/dist-server/controllers/shopify/apis/update-store-product-price.js.map +1 -0
  27. package/dist-server/controllers/shopify/apis/update-store-product-stock.js +24 -0
  28. package/dist-server/controllers/shopify/apis/update-store-product-stock.js.map +1 -0
  29. package/dist-server/controllers/shopify/apis/update-store-product-variation-price.js +29 -0
  30. package/dist-server/controllers/shopify/apis/update-store-product-variation-price.js.map +1 -0
  31. package/dist-server/controllers/shopify/apis/update-store-product-variation-stock.js +1 -1
  32. package/dist-server/controllers/shopify/apis/update-store-product-variation-stock.js.map +1 -1
  33. package/dist-server/controllers/shopify/shopify.js +36 -0
  34. package/dist-server/controllers/shopify/shopify.js.map +1 -1
  35. package/dist-server/controllers/store-api/index.js +7 -0
  36. package/dist-server/controllers/store-api/index.js.map +1 -1
  37. package/dist-server/controllers/tiktok/apis/get-store-order.js +5 -3
  38. package/dist-server/controllers/tiktok/apis/get-store-order.js.map +1 -1
  39. package/dist-server/controllers/tiktok/apis/get-store-orders.js +22 -21
  40. package/dist-server/controllers/tiktok/apis/get-store-orders.js.map +1 -1
  41. package/dist-server/controllers/tiktok/apis/get-store-products.js +7 -2
  42. package/dist-server/controllers/tiktok/apis/get-store-products.js.map +1 -1
  43. package/dist-server/controllers/tiktok/client/tiktok.js +3 -7
  44. package/dist-server/controllers/tiktok/client/tiktok.js.map +1 -1
  45. package/dist-server/controllers/tiktok/platform-action.js +3 -0
  46. package/dist-server/controllers/tiktok/platform-action.js.map +1 -1
  47. package/dist-server/controllers/woocommerce/apis/get-store-orders.js +6 -5
  48. package/dist-server/controllers/woocommerce/apis/get-store-orders.js.map +1 -1
  49. package/dist-server/controllers/woocommerce/apis/get-store-products.js +17 -1
  50. package/dist-server/controllers/woocommerce/apis/get-store-products.js.map +1 -1
  51. package/dist-server/graphql/resolvers/marketplace-store/lazada/generate-lazada-access-token.js +2 -5
  52. package/dist-server/graphql/resolvers/marketplace-store/lazada/generate-lazada-access-token.js.map +1 -1
  53. package/dist-server/graphql/resolvers/marketplace-store/magento/activate-magento-store.js +2 -2
  54. package/dist-server/graphql/resolvers/marketplace-store/magento/activate-magento-store.js.map +1 -1
  55. package/dist-server/graphql/resolvers/marketplace-store/shopee/generate-shopee-access-token.js +2 -2
  56. package/dist-server/graphql/resolvers/marketplace-store/shopee/generate-shopee-access-token.js.map +1 -1
  57. package/dist-server/graphql/resolvers/marketplace-store/zalora/generate-zalora-access-token.js +2 -5
  58. package/dist-server/graphql/resolvers/marketplace-store/zalora/generate-zalora-access-token.js.map +1 -1
  59. package/dist-server/graphql/resolvers/marketplace-transporter/create-marketplace-transporter.js +2 -5
  60. package/dist-server/graphql/resolvers/marketplace-transporter/create-marketplace-transporter.js.map +1 -1
  61. package/dist-server/routers/magento-private-router.js +2 -2
  62. package/dist-server/routers/magento-private-router.js.map +1 -1
  63. package/dist-server/routers/shopify-install-private-router.js +2 -2
  64. package/dist-server/routers/shopify-install-private-router.js.map +1 -1
  65. package/dist-server/routers/shopify-private-router.js +2 -2
  66. package/dist-server/routers/shopify-private-router.js.map +1 -1
  67. package/dist-server/routers/shopify-public-router.js +2 -2
  68. package/dist-server/routers/shopify-public-router.js.map +1 -1
  69. package/dist-server/routers/woocommerce-router.js +2 -2
  70. package/dist-server/routers/woocommerce-router.js.map +1 -1
  71. package/package.json +15 -15
  72. package/server/controllers/lazada/apis/get-store-orders.ts +3 -3
  73. package/server/controllers/lazada/apis/update-store-product-stock.ts +2 -2
  74. package/server/controllers/lazada/apis/update-store-product-variation-stock.ts +2 -2
  75. package/server/controllers/magento/apis/get-store-orders.ts +5 -4
  76. package/server/controllers/magento/apis/update-order-status.ts +1 -26
  77. package/server/controllers/shopee/apis/get-store-order-payout-dates.ts +3 -3
  78. package/server/controllers/shopee/apis/get-store-orders.ts +3 -3
  79. package/server/controllers/shopify/apis/get-store-orders.ts +74 -13
  80. package/server/controllers/shopify/apis/get-store-product-variation-stock.ts +17 -0
  81. package/server/controllers/shopify/apis/get-store-products.ts +38 -3
  82. package/server/controllers/shopify/apis/index.ts +4 -0
  83. package/server/controllers/shopify/apis/update-order-status.ts +17 -5
  84. package/server/controllers/shopify/apis/update-store-product-price.ts +26 -0
  85. package/server/controllers/shopify/apis/update-store-product-stock.ts +20 -0
  86. package/server/controllers/shopify/apis/update-store-product-variation-price.ts +26 -0
  87. package/server/controllers/shopify/apis/update-store-product-variation-stock.ts +1 -1
  88. package/server/controllers/shopify/shopify.ts +41 -0
  89. package/server/controllers/store-api/index.ts +3 -0
  90. package/server/controllers/tiktok/apis/get-store-order.ts +6 -3
  91. package/server/controllers/tiktok/apis/get-store-orders.ts +24 -22
  92. package/server/controllers/tiktok/apis/get-store-products.ts +9 -2
  93. package/server/controllers/tiktok/client/tiktok.ts +3 -6
  94. package/server/controllers/tiktok/platform-action.ts +18 -0
  95. package/server/controllers/woocommerce/apis/get-store-orders.ts +7 -5
  96. package/server/controllers/woocommerce/apis/get-store-products.ts +16 -0
  97. package/server/graphql/resolvers/marketplace-store/lazada/generate-lazada-access-token.ts +2 -2
  98. package/server/graphql/resolvers/marketplace-store/magento/activate-magento-store.ts +2 -2
  99. package/server/graphql/resolvers/marketplace-store/shopee/generate-shopee-access-token.ts +2 -2
  100. package/server/graphql/resolvers/marketplace-store/zalora/generate-zalora-access-token.ts +2 -2
  101. package/server/graphql/resolvers/marketplace-transporter/create-marketplace-transporter.ts +2 -2
  102. package/server/routers/magento-private-router.ts +2 -2
  103. package/server/routers/shopify-install-private-router.ts +2 -2
  104. package/server/routers/shopify-private-router.ts +2 -2
  105. package/server/routers/shopify-public-router.ts +2 -2
  106. package/server/routers/woocommerce-router.ts +2 -2
@@ -5,22 +5,28 @@ export function getStoreOrders() {
5
5
  method: 'get',
6
6
  path: '/orders.json',
7
7
  denormalize(req) {
8
- var { pagination, fromDate, toDate, lastOrderId } = req || {}
8
+ var { pagination, fromCreatedDate, toCreatedDate, fromUpdatedDate, toUpdatedDate, lastOrderId } = req || {}
9
9
  var { page = 0, limit = 100 } = pagination || {}
10
10
 
11
- var created_at_min = new Date(fromDate).toISOString()
12
- var created_at_max = new Date(toDate).toISOString()
13
- /* Must include only create_time or update_time in the request. */
14
- // var update_time_from = lastOneDay
15
- // var update_time_to = now
16
-
17
11
  var payload: any = {
18
12
  limit,
19
- created_at_min,
20
- created_at_max,
21
13
  status: 'any'
22
14
  }
23
15
 
16
+ if (fromCreatedDate && toCreatedDate) {
17
+ var created_at_min = new Date(fromCreatedDate).toISOString()
18
+ var created_at_max = new Date(toCreatedDate).toISOString()
19
+ payload.created_at_min = created_at_min
20
+ payload.created_at_max = created_at_max
21
+ }
22
+
23
+ if (fromUpdatedDate && toUpdatedDate) {
24
+ var updated_at_min = new Date(fromUpdatedDate).toISOString()
25
+ var updated_at_max = new Date(toUpdatedDate).toISOString()
26
+ payload.updated_at_min = updated_at_min
27
+ payload.updated_at_max = updated_at_max
28
+ }
29
+
24
30
  if (lastOrderId) payload.since_id = Number(lastOrderId)
25
31
 
26
32
  return { payload }
@@ -45,7 +51,9 @@ export function getStoreOrders() {
45
51
  .map(order => {
46
52
  const orderId = order.id
47
53
  const fulfillmentStatus = order.fulfillment_status
54
+ const paymentStatus = order?.financial_status || ''
48
55
  let orderStatus = order?.cancelled_at ? 'cancelled' : fulfillmentStatus ? fulfillmentStatus : 'unfulfilled'
56
+ let sellercraftStatus = getSellercraftStatus(fulfillmentStatus, paymentStatus)
49
57
 
50
58
  let itemCount: Number = 0
51
59
  let result: any
@@ -63,6 +71,7 @@ export function getStoreOrders() {
63
71
  orderUpdatedAt: new Date(order.updated_at).toUTCString(),
64
72
  discountValue: order.total_discounts,
65
73
  status: order.financial_status == 'pending' ? 'unpaid' : orderStatus,
74
+ sellercraftStatus,
66
75
  trackingNo: fulfillment.tracking_number,
67
76
  shippingProvider: fulfillment.tracking_company,
68
77
  recipientAddress:
@@ -78,7 +87,10 @@ export function getStoreOrders() {
78
87
  variationId: lineItem.product_exists === true ? lineItem.variant_id : lineItem.id.toString(),
79
88
  variationSku: lineItem.sku,
80
89
  channelSku: lineItem.sku,
81
- variationName: lineItem.name
90
+ variationName: lineItem.name,
91
+ originalPrice: lineItem.price,
92
+ total: lineItem.price,
93
+ subtotal: lineItem.price
82
94
  }
83
95
  })
84
96
  }
@@ -122,7 +134,8 @@ export function getStoreOrders() {
122
134
  variationId: lineItem.product_exists === true ? lineItem.variant_id : lineItem.id.toString(),
123
135
  variationSku: lineItem.sku,
124
136
  channelSku: lineItem.sku,
125
- variationName: lineItem.name
137
+ variationName: lineItem.name,
138
+ originalPrice: lineItem.price
126
139
  }
127
140
 
128
141
  lineItems.push(lineItem)
@@ -135,7 +148,8 @@ export function getStoreOrders() {
135
148
  variationId: lineItem.product_exists === true ? lineItem.variant_id : lineItem.id.toString(),
136
149
  variationSku: lineItem.sku,
137
150
  channelSku: lineItem.sku,
138
- variationName: lineItem.name
151
+ variationName: lineItem.name,
152
+ originalPrice: lineItem.price
139
153
  }
140
154
 
141
155
  if (lineItem.qty >= 0) lineItems.push(lineItem)
@@ -153,6 +167,7 @@ export function getStoreOrders() {
153
167
  discountValue: order.total_discounts,
154
168
  recipientAddress: order.billing_address,
155
169
  status: order.financial_status == 'pending' ? 'unpaid' : orderStatus,
170
+ sellercraftStatus,
156
171
  reason: order.cancel_reason,
157
172
  orderItems: lineItems
158
173
  }
@@ -183,11 +198,44 @@ export function getStoreOrders() {
183
198
  city,
184
199
  state,
185
200
  country: country === 'MY' ? 'Malaysia' : country,
186
- collectionCurrency: null,
201
+ collectionCurrency: order.currency,
187
202
  attentionTo: `${first_name} ${last_name}`
188
203
  }
189
204
 
190
205
  result.orderShipping = orderShipping
206
+
207
+ // For SC mapping
208
+
209
+ let shippingAddress = order?.shipping_address
210
+ let billingAddress = order?.billing_address || shippingAddress
211
+
212
+ result.shipping = {
213
+ address_1: shippingAddress.address1,
214
+ address_2: shippingAddress.address2,
215
+ address_3: shippingAddress.province,
216
+ postcode: shippingAddress.zip,
217
+ country: shippingAddress.country_code,
218
+ city: shippingAddress.city,
219
+ first_name: shippingAddress.first_name,
220
+ last_name: shippingAddress.last_name,
221
+ phone: shippingAddress.phone,
222
+ email: order.email
223
+ }
224
+ result.billing = {
225
+ address_1: billingAddress.address1,
226
+ address_2: billingAddress.address2,
227
+ address_3: billingAddress.province,
228
+ postcode: billingAddress.zip,
229
+ country: billingAddress.country_code,
230
+ city: billingAddress.city,
231
+ first_name: billingAddress.first_name,
232
+ last_name: billingAddress.last_name,
233
+ phone: billingAddress.phone,
234
+ email: order.email
235
+ }
236
+ result.isSOF = true
237
+ result.firstName = order?.customer?.first_name || ''
238
+ result.lastName = order?.customer?.last_name || ''
191
239
  }
192
240
 
193
241
  itemCount = result.orderItems.length
@@ -211,3 +259,16 @@ function checkNextPage(link) {
211
259
 
212
260
  return nextPage
213
261
  }
262
+
263
+ function getSellercraftStatus(fulfillmentStatus, paymentStatus) {
264
+ if (
265
+ (fulfillmentStatus == 'unfulfilled' || !fulfillmentStatus) &&
266
+ (paymentStatus == 'pending' || paymentStatus == 'unpaid')
267
+ )
268
+ return 'payment_pending'
269
+ if ((fulfillmentStatus == 'unfulfilled' || !fulfillmentStatus) && paymentStatus == 'paid') return 'processing'
270
+ if (fulfillmentStatus == 'fulfilled' && paymentStatus == 'paid') return 'shipped'
271
+ if (paymentStatus == 'refunded') return 'refunded'
272
+ if (paymentStatus == 'voided') return 'cancelled'
273
+ if (paymentStatus == 'overdue') return 'cancelled'
274
+ }
@@ -0,0 +1,17 @@
1
+ export function getStoreProductVariationStock() {
2
+ return {
3
+ path: '/variants/{variantId}.json',
4
+ method: 'get',
5
+ denormalize(req) {
6
+ let { variantId } = req
7
+ return {
8
+ resource: {
9
+ variantId
10
+ }
11
+ }
12
+ },
13
+ normalize(res) {
14
+ return res?.variant?.inventory_quantity
15
+ }
16
+ }
17
+ }
@@ -9,13 +9,18 @@ export function getStoreProducts() {
9
9
  method: 'get',
10
10
  path: '/products.json',
11
11
  denormalize(req) {
12
- var { pagination, pageInfo } = req || {}
12
+ var { pagination, pageInfo, fromUpdatedDate, toUpdatedDate } = req || {}
13
13
  var { page, limit } = pagination || { page: 0, limit: 100 }
14
14
 
15
15
  var payload: any = {
16
16
  limit: limit
17
17
  }
18
18
 
19
+ if (fromUpdatedDate && toUpdatedDate) {
20
+ payload.updated_at_max = toUpdatedDate
21
+ payload.updated_at_min = fromUpdatedDate
22
+ }
23
+
19
24
  if (pageInfo) payload.page_info = pageInfo
20
25
 
21
26
  return { payload }
@@ -72,7 +77,24 @@ export function getStoreProducts() {
72
77
  marketplaceStatus: product.status,
73
78
  hasVariation: true,
74
79
  categoryId: product?.collection_id ? product.collection_id : null,
75
- attributes: [],
80
+ attributes: product?.options?.map(option => {
81
+ return {
82
+ native_attribute_id: option.id,
83
+ attribute_key: option.name,
84
+ values: option.values
85
+ }
86
+ }) || [],
87
+ sellercraftAttributes: [
88
+ {
89
+ native_attribute_id: 'description',
90
+ attribute_key: 'description',
91
+ display_name: 'Description',
92
+ values: [product.body_html]
93
+ }
94
+ ],
95
+ images: product?.images?.map(image => {
96
+ return image.src
97
+ }) || [],
76
98
  variations: productVariations.map(variant => {
77
99
  return {
78
100
  variationId: variant.id,
@@ -83,10 +105,14 @@ export function getStoreProducts() {
83
105
  inventoryPolicy: variant.inventory_policy,
84
106
  inventoryItemId: variant.inventory_item_id,
85
107
  locationId: variant.location_id,
108
+ extraMetadata: {
109
+ inventoryItemId: variant.inventory_item_id,
110
+ locationId: variant.location_id,
111
+ },
86
112
  primaryUnit: variant.weight_unit,
87
113
  primaryUnitValue: variant.weight,
88
114
  costPrice: variant.price,
89
- sellPrice: variant.compare_at_price,
115
+ sellPrice: variant.compare_at_price || variant.price,
90
116
  attributes: [
91
117
  {
92
118
  attributeId: variant.option1,
@@ -101,6 +127,15 @@ export function getStoreProducts() {
101
127
  name: variant.option3
102
128
  }
103
129
  ],
130
+ sellercraftAttributes: product?.options.map(option => {
131
+ return {
132
+ native_attribute_id: option.name,
133
+ attribute_key: option.name,
134
+ display_name: option.name,
135
+ values: [variant[`option${option.position}`]]
136
+ }
137
+ }) || [],
138
+ weight: variant.grams,
104
139
  presentmentPrices: variant?.presentment_prices
105
140
  ? variant.presentment_prices.map(presentmentPrice => {
106
141
  return {
@@ -7,3 +7,7 @@ export * from './update-store-product-variation-stock'
7
7
  export * from './update-order-status'
8
8
  export * from './set-store-order-status-ready-to-ship'
9
9
  export * from './get-store-order'
10
+ export * from './update-store-product-variation-price'
11
+ export * from './update-store-product-price'
12
+ export * from './update-store-product-stock'
13
+ export * from './get-store-product-variation-stock'
@@ -1,15 +1,27 @@
1
- /* https://shopify.dev/api/admin-rest/2021-10/resources/fulfillment#[post]/admin/api/2021-10/orders/{order_id}/fulfillments/{fulfillment_id}/complete.json */
1
+ /* https://shopify.dev/api/admin-rest/2021-10/resources/fulfillment#[post]/admin/api/2021-10/fulfillments.json */
2
2
 
3
3
  export function updateOrderStatus() {
4
4
  return {
5
- path: '/orders/{orderId}/fulfillments/{fulfillmentId}/complete.json',
6
5
  method: 'post',
6
+ path: '/orders/{orderId}/fulfillments.json',
7
7
  denormalize(req) {
8
- const { orderId, fulfillmentId } = req
8
+ const { orderId, trackingNo, locations, carrier, status } = req || {}
9
+
10
+ if (status != 'READY_TO_SHIP') {
11
+ throw new Error('Shopify cannot create fulfillment, order status is not READY_TO_SHIP')
12
+ }
13
+
9
14
  return {
15
+ payload: {
16
+ fulfillment: {
17
+ location_id: locations[0],
18
+ tracking_number: trackingNo,
19
+ notify_customer: true,
20
+ tracking_company: carrier
21
+ }
22
+ },
10
23
  resource: {
11
- orderId: orderId,
12
- fulfillmentId: fulfillmentId.toString()
24
+ orderId
13
25
  }
14
26
  }
15
27
  },
@@ -0,0 +1,26 @@
1
+ /*https://shopify.dev/api/admin-rest/2021-10/resources/product-variant#put-variants-variant-id */
2
+
3
+ export function updateStoreProductPrice() {
4
+ return {
5
+ path: '/variants/{variantId}.json',
6
+ method: 'put',
7
+ denormalize(req) {
8
+ let { costPrice, sellPrice, variationId } = req
9
+
10
+ return {
11
+ payload: {
12
+ variant: {
13
+ price: costPrice,
14
+ compare_at_price: sellPrice
15
+ }
16
+ },
17
+ resource: {
18
+ variantId: variationId
19
+ }
20
+ }
21
+ },
22
+ normalize(res) {
23
+ return res
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,20 @@
1
+ export function updateStoreProductStock() {
2
+ return {
3
+ method: 'post',
4
+ path: '/inventory_levels/adjust.json',
5
+ denormalize(req) {
6
+ const { inventoryItemId, locationId: location_id, qty } = (Array.isArray(req) ? req[0] : req) || {}
7
+
8
+ return {
9
+ payload: {
10
+ inventory_item_id: parseInt(inventoryItemId),
11
+ location_id,
12
+ available_adjustment: parseInt(qty)
13
+ }
14
+ }
15
+ },
16
+ normalize(res) {
17
+ return res
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,26 @@
1
+ /*https://shopify.dev/api/admin-rest/2021-10/resources/product-variant#put-variants-variant-id */
2
+
3
+ export function updateStoreProductVariationPrice() {
4
+ return {
5
+ path: '/variants/{variantId}.json',
6
+ method: 'put',
7
+ denormalize(req) {
8
+ let { costPrice, sellPrice, variationId } = req
9
+
10
+ return {
11
+ payload: {
12
+ variant: {
13
+ price: costPrice,
14
+ compare_at_price: sellPrice
15
+ }
16
+ },
17
+ resource: {
18
+ variantId: variationId
19
+ }
20
+ }
21
+ },
22
+ normalize(res) {
23
+ return res
24
+ }
25
+ }
26
+ }
@@ -3,7 +3,7 @@ export function updateStoreProductVariationStock() {
3
3
  method: 'post',
4
4
  path: '/inventory_levels/adjust.json',
5
5
  denormalize(req) {
6
- const { inventoryItemId, locationId: location_id, qty } = req[0]
6
+ const { inventoryItemId, locationId: location_id, qty } = (Array.isArray(req) ? req[0] : req) || {}
7
7
 
8
8
  return {
9
9
  payload: {
@@ -2,6 +2,8 @@ import fetch from 'node-fetch'
2
2
  import crypto from 'crypto'
3
3
  import querystring from 'querystring'
4
4
 
5
+ import { createPayloadLog } from '@things-factory/integration-base'
6
+
5
7
  const debug = require('debug')('things-factory:integration-marketplace:shopify')
6
8
 
7
9
  export type ShopifyConfig = {
@@ -77,6 +79,11 @@ export class Shopify {
77
79
  var result = await response.json()
78
80
  result.link = link
79
81
 
82
+ try {
83
+ createPayloadLog(shop, path, qs || '', result, {
84
+ state: { domain: null }
85
+ })
86
+ } catch (e) {}
80
87
  debug('response result', result)
81
88
 
82
89
  return result
@@ -101,6 +108,40 @@ export class Shopify {
101
108
  })
102
109
 
103
110
  const result = await response.json()
111
+ try {
112
+ createPayloadLog(shop, path, jsondata, result, {
113
+ state: { domain: null }
114
+ })
115
+ } catch (e) {}
116
+ debug('response result', result)
117
+
118
+ return result
119
+ }
120
+
121
+ async put(path: string, data: any = {}) {
122
+ const { shop, accessToken } = this.config
123
+
124
+ debug('data', data)
125
+
126
+ const jsondata = JSON.stringify(data)
127
+
128
+ const endpoint = `https://${shop}.myshopify.com/admin/api/2020-01${path}`
129
+
130
+ const response = await fetch(endpoint, {
131
+ method: 'put',
132
+ headers: {
133
+ 'Content-Type': 'application/json',
134
+ 'X-Shopify-Access-Token': accessToken
135
+ },
136
+ body: jsondata
137
+ })
138
+
139
+ const result = await response.json()
140
+ try {
141
+ createPayloadLog(shop, path, jsondata, result, {
142
+ state: { domain: null }
143
+ })
144
+ } catch (e) {}
104
145
  debug('response result', result)
105
146
 
106
147
  return result
@@ -191,4 +191,7 @@ export class StoreAPI {
191
191
 
192
192
  @api
193
193
  static getStoreOrderPayoutDates(store, req): any {}
194
+
195
+ @api
196
+ static getStoreProductVariationStock(store, req): any {}
194
197
  }
@@ -20,8 +20,8 @@ export function getStoreOrder() {
20
20
  async normalize(res, { store }) {
21
21
  const { data } = res
22
22
  const orderList = data.order_list
23
-
24
23
  let results: any[] = []
24
+
25
25
  for (let i = 0; i < orderList.length; i++) {
26
26
  const order: any = orderList[i]
27
27
  const {
@@ -36,6 +36,7 @@ export function getStoreOrder() {
36
36
  rts_sla,
37
37
  recipient_address: recipientAddress,
38
38
  item_list: itemList,
39
+ order_line_list: orderLineList,
39
40
  package_list: packageList,
40
41
  delivery_option: deliveryOption
41
42
  } = order
@@ -52,13 +53,15 @@ export function getStoreOrder() {
52
53
 
53
54
  var orderUpdatedAt = new Date(update_time * 1000)
54
55
  var orderCreatedAt = new Date(Number(create_time))
55
- var slaExpiresAt = new Date(rts_sla * 1000)
56
+ var slaExpiresAt = Boolean(rts_sla) ? new Date(rts_sla * 1000) : null
56
57
  let docRefNo = orderNo
57
58
  let isSOF: boolean = false
58
59
  if (deliveryOption == 'SEND_BY_SELLER') isSOF = true
59
60
 
60
61
  let orderItems = itemList.map(item => {
61
- var { product_id: name, sku_id, quantity: qty, sku_original_price, sku_sale_price } = item
62
+ var { sku_id, quantity: qty, sku_original_price, sku_sale_price } = item
63
+ var matchedOrderLine = orderLineList.find(ol => ol.sku_id == sku_id)
64
+ var name = matchedOrderLine.order_line_id
62
65
 
63
66
  return {
64
67
  name,
@@ -7,16 +7,25 @@ export function getStoreOrders() {
7
7
  method: 'post',
8
8
  path: '/api/orders/search',
9
9
  denormalize(req) {
10
- var { pagination, fromDate, toDate, nextCursor } = req || {}
10
+ var { pagination, fromCreatedDate, toCreatedDate, fromUpdatedDate, toUpdatedDate, nextCursor } = req || {}
11
11
  var { page, limit } = pagination || { page: 0, limit: 100 }
12
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)
13
+ let payload: any = { page_size: limit }
15
14
 
16
- var payload: any = {
17
- page_size: limit,
18
- create_time_from,
19
- create_time_to
15
+ if (fromCreatedDate && toCreatedDate) {
16
+ const create_time_from = Math.floor(new Date(fromCreatedDate).getTime() / 1000)
17
+ const create_time_to = Math.floor(new Date(toCreatedDate).getTime() / 1000)
18
+
19
+ payload.create_time_from = create_time_from
20
+ payload.create_time_to = create_time_to
21
+ }
22
+
23
+ if (fromUpdatedDate && toUpdatedDate) {
24
+ const update_time_from = Math.floor(new Date(fromUpdatedDate).getTime() / 1000)
25
+ const update_time_to = Math.floor(new Date(toUpdatedDate).getTime() / 1000)
26
+
27
+ payload.update_time_from = update_time_from
28
+ payload.update_time_to = update_time_to
20
29
  }
21
30
 
22
31
  if (nextCursor) payload.cursor = nextCursor
@@ -28,23 +37,16 @@ export function getStoreOrders() {
28
37
 
29
38
  var more: boolean = data?.more || false
30
39
  var nextCursor: string = more ? data.next_cursor : null
31
- const orderList: any[] = data?.order_list || []
40
+ let orderList: any[] = data?.order_list || []
32
41
 
33
42
  let results: any[] = []
34
- let orderIds: any = []
35
- for (let i = 0; i < orderList.length; i++) {
36
- const order: any = orderList[i]
37
- orderIds.push({ ...order })
38
-
39
- if (orderIds.length <= 20) {
40
- const orderIdList: any = orderIds.map(orderId => orderId.order_id)
41
- const orderDetails: any[] = await StoreAPI.getStoreOrder(store, { orderId: orderIdList })
42
- orderDetails.map(orderDetail => {
43
- results.push({ ...orderDetail })
44
- })
45
-
46
- orderIds = []
47
- }
43
+ while (orderList.length > 0) {
44
+ let orderIds = orderList.splice(0, orderList.length >= 20 ? 20 : orderList.length)
45
+ const orderIdList: any = orderIds.map(orderId => orderId.order_id)
46
+ const orderDetails: any[] = await StoreAPI.getStoreOrder(store, { orderId: orderIdList })
47
+ orderDetails.map(orderDetail => {
48
+ results.push({ ...orderDetail })
49
+ })
48
50
  }
49
51
 
50
52
  return { results, more, nextCursor }
@@ -11,11 +11,18 @@ export function getStoreProducts() {
11
11
  method: 'post',
12
12
  path: '/api/products/search',
13
13
  denormalize(req) {
14
- var { pagination } = req || {}
14
+ var { pagination, fromUpdatedDate, toUpdatedDate } = req || {}
15
15
  var { page, limit } = pagination || { page: 0, limit: 100 }
16
16
 
17
+ var payload: any = { page_size: limit, page_number: page + 1, search_status: 0 }
18
+
19
+ if (fromUpdatedDate && toUpdatedDate) {
20
+ payload.update_time_from = Math.floor(new Date(fromUpdatedDate).getTime() / 1000)
21
+ payload.update_time_to = Math.floor(new Date(toUpdatedDate).getTime() / 1000)
22
+ }
23
+
17
24
  return {
18
- payload: { page_size: limit, page_number: page + 1, search_status: 0 },
25
+ payload,
19
26
  resource: {}
20
27
  }
21
28
  },
@@ -92,12 +92,9 @@ export class Tiktok {
92
92
  })
93
93
 
94
94
  if (response.ok) {
95
- const result = await response.json()
96
- if (result?.code == 0) {
97
- return result
98
- } else {
99
- throw new Error(`(${result.code}) ${result.message}`)
100
- }
95
+ let result = await response.json()
96
+ result.requiredDocument = true
97
+ return result
101
98
  } else {
102
99
  const result = await response.json()
103
100
  throw new Error(`(${result.code}) ${result.message}`)
@@ -1,3 +1,5 @@
1
+ import { createPayloadLog } from '@things-factory/integration-base'
2
+
1
3
  import { Tiktok } from './client/tiktok'
2
4
 
3
5
  function substitute(path, obj) {
@@ -47,8 +49,24 @@ export const action = async ({ store, method = 'get', path, request }) => {
47
49
  }
48
50
 
49
51
  if (response.code != 0) {
52
+ createPayloadLog(
53
+ store.channelShopId,
54
+ path,
55
+ request,
56
+ response,
57
+ request?.context ? request.context : { state: { domain: null } }
58
+ )
59
+
50
60
  throw response
51
61
  }
52
62
 
63
+ createPayloadLog(
64
+ store.channelShopId,
65
+ path,
66
+ request,
67
+ response,
68
+ request?.context ? request.context : { state: { domain: null } }
69
+ )
70
+
53
71
  return response
54
72
  }
@@ -8,11 +8,11 @@ export function getStoreOrders() {
8
8
  method: 'get',
9
9
  path: '/orders',
10
10
  denormalize(req) {
11
- var { pagination, fromDate, toDate } = req || {}
11
+ var { pagination, fromCreatedDate, toCreatedDate } = req || {}
12
12
  var { page = 0, limit = 100 } = pagination || {}
13
13
 
14
- var after = new Date(fromDate).toISOString()
15
- var before = new Date(toDate).toISOString()
14
+ var after = new Date(fromCreatedDate).toISOString()
15
+ var before = new Date(toCreatedDate).toISOString()
16
16
  /* Must include only create_time or update_time in the request. */
17
17
  // var update_time_from = lastOneDay
18
18
  // var update_time_to = now
@@ -81,7 +81,8 @@ export function getStoreOrders() {
81
81
  subtotal,
82
82
  subtotal_tax: subtotalTax,
83
83
  total,
84
- total_tax: totalTax
84
+ total_tax: totalTax,
85
+ originalPrice: subtotal
85
86
  } = item
86
87
 
87
88
  return {
@@ -96,7 +97,8 @@ export function getStoreOrders() {
96
97
  subtotal,
97
98
  subtotalTax,
98
99
  total,
99
- totalTax
100
+ totalTax,
101
+ originalPrice: subtotal
100
102
  }
101
103
  })
102
104