@things-factory/integration-marketplace 4.0.7 → 4.0.12

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 (89) hide show
  1. package/client/pages/marketplace-store-woocommerce.js +4 -2
  2. package/dist-server/controllers/lazada/apis/get-store-order-item-transaction-details.js +88 -0
  3. package/dist-server/controllers/lazada/apis/get-store-order-item-transaction-details.js.map +1 -0
  4. package/dist-server/controllers/lazada/apis/get-store-order-items.js +52 -6
  5. package/dist-server/controllers/lazada/apis/get-store-order-items.js.map +1 -1
  6. package/dist-server/controllers/lazada/apis/get-store-orders.js +15 -3
  7. package/dist-server/controllers/lazada/apis/get-store-orders.js.map +1 -1
  8. package/dist-server/controllers/lazada/apis/get-store-refund-orders.js +50 -0
  9. package/dist-server/controllers/lazada/apis/get-store-refund-orders.js.map +1 -0
  10. package/dist-server/controllers/lazada/apis/index.js +2 -0
  11. package/dist-server/controllers/lazada/apis/index.js.map +1 -1
  12. package/dist-server/controllers/lazada/client/lazada.js +24 -4
  13. package/dist-server/controllers/lazada/client/lazada.js.map +1 -1
  14. package/dist-server/controllers/lazada/platform-action.js +19 -4
  15. package/dist-server/controllers/lazada/platform-action.js.map +1 -1
  16. package/dist-server/controllers/shopee/apis/get-store-order-transaction-details.js +32 -0
  17. package/dist-server/controllers/shopee/apis/get-store-order-transaction-details.js.map +1 -0
  18. package/dist-server/controllers/shopee/apis/get-store-order.js +25 -10
  19. package/dist-server/controllers/shopee/apis/get-store-order.js.map +1 -1
  20. package/dist-server/controllers/shopee/apis/get-store-refund-order-details.js +40 -0
  21. package/dist-server/controllers/shopee/apis/get-store-refund-order-details.js.map +1 -0
  22. package/dist-server/controllers/shopee/apis/get-store-refund-orders.js +43 -0
  23. package/dist-server/controllers/shopee/apis/get-store-refund-orders.js.map +1 -0
  24. package/dist-server/controllers/shopee/apis/index.js +3 -0
  25. package/dist-server/controllers/shopee/apis/index.js.map +1 -1
  26. package/dist-server/controllers/shopify/apis/get-store-orders.js +50 -11
  27. package/dist-server/controllers/shopify/apis/get-store-orders.js.map +1 -1
  28. package/dist-server/controllers/shopify/apis/get-store-products.js +2 -1
  29. package/dist-server/controllers/shopify/apis/get-store-products.js.map +1 -1
  30. package/dist-server/controllers/store-api/index.js +63 -0
  31. package/dist-server/controllers/store-api/index.js.map +1 -1
  32. package/dist-server/controllers/woocommerce/apis/get-store-order.js +21 -0
  33. package/dist-server/controllers/woocommerce/apis/get-store-order.js.map +1 -0
  34. package/dist-server/controllers/woocommerce/apis/get-store-product-categories.js +8 -44
  35. package/dist-server/controllers/woocommerce/apis/get-store-product-categories.js.map +1 -1
  36. package/dist-server/controllers/woocommerce/apis/index.js +10 -0
  37. package/dist-server/controllers/woocommerce/apis/index.js.map +1 -1
  38. package/dist-server/controllers/woocommerce/apis/update-order.js +37 -0
  39. package/dist-server/controllers/woocommerce/apis/update-order.js.map +1 -0
  40. package/dist-server/controllers/woocommerce/apis/update-product-attribute.js +20 -0
  41. package/dist-server/controllers/woocommerce/apis/update-product-attribute.js.map +1 -0
  42. package/dist-server/controllers/woocommerce/apis/update-store-product-price.js +23 -0
  43. package/dist-server/controllers/woocommerce/apis/update-store-product-price.js.map +1 -0
  44. package/dist-server/controllers/woocommerce/apis/update-store-product-stock.js +2 -2
  45. package/dist-server/controllers/woocommerce/apis/update-store-product-stock.js.map +1 -1
  46. package/dist-server/controllers/woocommerce/apis/update-store-product-variant-price.js +20 -0
  47. package/dist-server/controllers/woocommerce/apis/update-store-product-variant-price.js.map +1 -0
  48. package/dist-server/controllers/woocommerce/apis/update-store-product-variant-stock.js +20 -0
  49. package/dist-server/controllers/woocommerce/apis/update-store-product-variant-stock.js.map +1 -0
  50. package/dist-server/controllers/woocommerce/apis/update-store-product-variation-price.js +23 -0
  51. package/dist-server/controllers/woocommerce/apis/update-store-product-variation-price.js.map +1 -0
  52. package/dist-server/controllers/woocommerce/apis/update-store-product-variation-stock.js +3 -3
  53. package/dist-server/controllers/woocommerce/apis/update-store-product-variation-stock.js.map +1 -1
  54. package/dist-server/controllers/woocommerce/platform-action.js +9 -3
  55. package/dist-server/controllers/woocommerce/platform-action.js.map +1 -1
  56. package/dist-server/controllers/woocommerce/woocommerce.js +7 -2
  57. package/dist-server/controllers/woocommerce/woocommerce.js.map +1 -1
  58. package/dist-server/routers/woocommerce-router.js +0 -7
  59. package/dist-server/routers/woocommerce-router.js.map +1 -1
  60. package/package.json +15 -15
  61. package/server/controllers/lazada/apis/get-store-order-item-transaction-details.ts +65 -0
  62. package/server/controllers/lazada/apis/get-store-order-items.ts +92 -5
  63. package/server/controllers/lazada/apis/get-store-orders.ts +17 -2
  64. package/server/controllers/lazada/apis/get-store-refund-orders.ts +52 -0
  65. package/server/controllers/lazada/apis/index.ts +2 -0
  66. package/server/controllers/lazada/client/lazada.ts +42 -12
  67. package/server/controllers/lazada/platform-action.ts +21 -2
  68. package/server/controllers/shopee/apis/get-store-order-transaction-details.ts +29 -0
  69. package/server/controllers/shopee/apis/get-store-order.ts +32 -7
  70. package/server/controllers/shopee/apis/get-store-refund-order-details.ts +41 -0
  71. package/server/controllers/shopee/apis/get-store-refund-orders.ts +47 -0
  72. package/server/controllers/shopee/apis/index.ts +3 -0
  73. package/server/controllers/shopify/apis/get-store-orders.ts +54 -12
  74. package/server/controllers/shopify/apis/get-store-products.ts +3 -1
  75. package/server/controllers/store-api/index.ts +28 -0
  76. package/server/controllers/woocommerce/apis/get-store-order.ts +17 -0
  77. package/server/controllers/woocommerce/apis/get-store-product-categories.ts +6 -48
  78. package/server/controllers/woocommerce/apis/index.ts +10 -0
  79. package/server/controllers/woocommerce/apis/update-order.ts +36 -0
  80. package/server/controllers/woocommerce/apis/update-product-attribute.ts +17 -0
  81. package/server/controllers/woocommerce/apis/update-store-product-price.ts +20 -0
  82. package/server/controllers/woocommerce/apis/update-store-product-stock.ts +2 -2
  83. package/server/controllers/woocommerce/apis/update-store-product-variant-price.ts +17 -0
  84. package/server/controllers/woocommerce/apis/update-store-product-variant-stock.ts +18 -0
  85. package/server/controllers/woocommerce/apis/update-store-product-variation-price.ts +20 -0
  86. package/server/controllers/woocommerce/apis/update-store-product-variation-stock.ts +3 -3
  87. package/server/controllers/woocommerce/platform-action.ts +9 -5
  88. package/server/controllers/woocommerce/woocommerce.ts +7 -2
  89. package/server/routers/woocommerce-router.ts +5 -7
@@ -1,58 +1,16 @@
1
1
  /* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#list-all-products /wp-json/wc/v3/categoriess */
2
2
 
3
- export function getStoreProducts() {
3
+ export function getStoreProductCategories() {
4
4
  return {
5
5
  method: 'get',
6
- path: '/categories',
6
+ path: '/products/categories',
7
7
  denormalize(req) {
8
- var { pagination } = req || {}
9
- var { page, limit } = pagination || { page: 0, limit: 100 }
10
-
11
- var payload: any = {
12
- per_page: limit,
13
- offset: page * limit
14
- }
15
-
16
- return { payload }
8
+ return { payload: {} }
17
9
  },
18
- async normalize(res, { store }) {
19
- // return res.products
20
-
21
- let results: any[] = []
22
- const totalProducts = res.totalProducts
23
-
24
- for (var i = 0; i < res.products.length; i++) {
25
- const product: any = res.products[i]
26
- const productVariations: any[] = product.variations
27
-
28
- const result = {
29
- itemId: product.id,
30
- name: product.name,
31
- type: product.type,
32
- description: product.description,
33
- hasVariation: true,
34
- categoryId: product?.categories.length > 0 ? product.categories[0].id : null,
35
- attributes: [],
36
- variations: productVariations.map(variant => {
37
- return {
38
- variationId: variant.id,
39
- variationSku: variant.sku,
40
- channelSku: variant.sku,
41
- name: product.name + ' (' + variant.attributes[0].options + ')',
42
- qty: variant.stock_quantity,
43
- primaryUnit: 'N/A',
44
- primaryUnitValue: variant.weight,
45
- costPrice: variant.price,
46
- sellPrice: variant.sale_price,
47
- attributes: variant.attributes
48
- }
49
- })
50
- }
51
-
52
- results.push({ ...result })
53
- }
10
+ normalize(res, { store }) {
11
+ const { items, totalItems } = res
54
12
 
55
- return { results, total: totalProducts }
13
+ return { results: items, total: totalItems }
56
14
  }
57
15
  }
58
16
  }
@@ -1,7 +1,17 @@
1
1
  export * from './echo'
2
2
  export * from './create-order-note'
3
+ export * from './get-store-product-categories'
3
4
  export * from './get-store-products'
4
5
  export * from './get-store-product-variations'
5
6
  export * from './get-store-orders'
6
7
  export * from './update-store-product-stock'
7
8
  export * from './update-store-product-variation-stock'
9
+ export * from './get-store-product-categories'
10
+ export * from './update-order'
11
+ export * from './update-product-attribute'
12
+ export * from './update-store-product-price'
13
+ export * from './update-store-product-variation-price'
14
+ export * from './get-store-order'
15
+ export * from './update-store-product-price'
16
+ export * from './update-store-product-variant-stock'
17
+ export * from './update-store-product-variant-price'
@@ -0,0 +1,36 @@
1
+ /* https://woocommerce.github.io/woocommerce-rest-api-docs/#update-an-order */
2
+ /* /wp-json/wc/v3/orders/<id> */
3
+
4
+ import { StoreAPI } from '../../store-api'
5
+
6
+ export function updateOrder(req) {
7
+ return {
8
+ method: 'put',
9
+ path: '/orders/{orderId}',
10
+ async denormalize(req, { store }) {
11
+ var { status, orderId } = req || {}
12
+
13
+ const order = await StoreAPI.getStoreOrder(store, { orderId })
14
+
15
+ let orderStatus = status
16
+ if (orderStatus == 'PACKED') {
17
+ if (order.status == 'pending') {
18
+ orderStatus = 'on-hold'
19
+ } else {
20
+ orderStatus = order.status
21
+ }
22
+ }
23
+ if (orderStatus == 'READY_TO_SHIP') {
24
+ orderStatus = 'completed'
25
+ }
26
+ if (orderStatus == 'CANCELLED') {
27
+ orderStatus = 'cancelled'
28
+ }
29
+
30
+ return { resource: { orderId: orderId }, payload: { status: orderStatus } }
31
+ },
32
+ normalize(res) {
33
+ return res.items
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,17 @@
1
+ /* https://woocommerce.github.io/woocommerce-rest-api-docs/#update-a-product-attribute */
2
+ /* /wp-json/wc/v3/attributes/<id> */
3
+
4
+ export function updateProductAttribute(req) {
5
+ return {
6
+ method: 'put',
7
+ path: '/products/attributes/{attributeId}',
8
+ denormalize(req) {
9
+ var { name, attributeId } = req || {}
10
+
11
+ return { resource: { attributeId: attributeId }, payload: { name } }
12
+ },
13
+ normalize(res) {
14
+ return res
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,20 @@
1
+ /* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#update-a-product */
2
+ /* /wp-json/wc/v3/products/<id> */
3
+
4
+ export function updateStoreProductPrice(req) {
5
+ return {
6
+ method: 'put',
7
+ path: '/products/{itemId}',
8
+ denormalize(req) {
9
+ var { costPrice, sellPrice, productId } = req || {}
10
+
11
+ return {
12
+ resource: { itemId: parseInt(productId) },
13
+ payload: { regular_price: costPrice?.toString(), sale_price: sellPrice?.toString() }
14
+ }
15
+ },
16
+ normalize(res) {
17
+ return res
18
+ }
19
+ }
20
+ }
@@ -6,12 +6,12 @@ export function updateStoreProductStock(req) {
6
6
  method: 'put',
7
7
  path: '/products/{itemId}',
8
8
  denormalize(req) {
9
- var { qty, itemId } = req[0] || {}
9
+ var { qty, itemId } = req || {}
10
10
 
11
11
  return { resource: { itemId: parseInt(itemId) }, payload: { stock_quantity: qty, manage_stock: true } }
12
12
  },
13
13
  normalize(res) {
14
- return res.items
14
+ return res
15
15
  }
16
16
  }
17
17
  }
@@ -0,0 +1,17 @@
1
+ /* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#update-a-product-variation */
2
+ /* /wp-json/wc/v3/products/<product_id>/variations/<id> */
3
+
4
+ export function updateStoreProductVariantPrice(req) {
5
+ return {
6
+ method: 'put',
7
+ path: '/products/{itemId}/variations/{variantId}',
8
+ denormalize(req) {
9
+ var { cost_price, sell_price, product_id, variant_id } = req[0] || {}
10
+
11
+ return { resource: { itemId: parseInt(product_id), variantId: parseInt(variant_id) }, payload: { price: cost_price, sale_price: sell_price } }
12
+ },
13
+ normalize(res) {
14
+ return res.items
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,18 @@
1
+ /* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#update-a-product-variation */
2
+ /* /wp-json/wc/v3/products/<product_id>/variations/<id> */
3
+
4
+ export function updateStoreProductVariantStock(req) {
5
+ return {
6
+ method: 'put',
7
+ path: '/products/{itemId}/variations/{variantId}',
8
+ denormalize(req) {
9
+ var { qty, product_id, variant_id } = req[0] || {}
10
+
11
+ return { resource: { itemId: parseInt(product_id), variantId: parseInt(variant_id) }, payload: { stock_quantity: qty, manage_stock: true } }
12
+ },
13
+ normalize(res) {
14
+ return res.items
15
+ }
16
+ }
17
+ }
18
+
@@ -0,0 +1,20 @@
1
+ /* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#update-a-product-variation */
2
+ /* /wp-json/wc/v3/products/<product_id>/variations/<id> */
3
+
4
+ export function updateStoreProductVariationPrice(req) {
5
+ return {
6
+ method: 'put',
7
+ path: '/products/{itemId}/variations/{variantId}',
8
+ denormalize(req) {
9
+ var { costPrice, sellPrice, productId, variationId } = req || {}
10
+
11
+ return {
12
+ resource: { itemId: parseInt(productId), variantId: parseInt(variationId) },
13
+ payload: { regular_price: costPrice?.toString(), sale_price: sellPrice?.toString() }
14
+ }
15
+ },
16
+ normalize(res) {
17
+ return res
18
+ }
19
+ }
20
+ }
@@ -1,4 +1,4 @@
1
- /* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#update-a-product */
1
+ /* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#update-a-product-variation */
2
2
  /* /wp-json/wc/v3/products/<product_id>/variations/<id> */
3
3
 
4
4
  export function updateStoreProductVariationStock(req) {
@@ -6,7 +6,7 @@ export function updateStoreProductVariationStock(req) {
6
6
  method: 'put',
7
7
  path: '/products/{itemId}/variations/{variationId}',
8
8
  denormalize(req) {
9
- var { qty, itemId, variationId } = req[0] || {}
9
+ var { qty, itemId, variationId } = req || {}
10
10
 
11
11
  return {
12
12
  resource: { itemId: parseInt(itemId), variationId: parseInt(variationId) },
@@ -14,7 +14,7 @@ export function updateStoreProductVariationStock(req) {
14
14
  }
15
15
  },
16
16
  normalize(res) {
17
- return res.items
17
+ return res
18
18
  }
19
19
  }
20
20
  }
@@ -1,10 +1,5 @@
1
- import { config } from '@things-factory/env'
2
-
3
1
  import { Woocommerce } from './woocommerce'
4
2
 
5
- const woocommerceConfig = config.get('marketplaceIntegrationWoocommerce', {})
6
- const { key_id, user_id, consumer_key, consumer_secret } = woocommerceConfig
7
-
8
3
  function substitute(path, obj) {
9
4
  var props = []
10
5
  var re = /{([^}]+)}/g
@@ -23,6 +18,15 @@ function substitute(path, obj) {
23
18
  return result
24
19
  }
25
20
 
21
+ /**
22
+ * @summary Building Path Method and Payload
23
+ * @description After denormalise of data is done,
24
+ * platform API method will be called with its path and payload,
25
+ * this section is to build path and substitution of the resource in url as well as the payload for body request.
26
+ * Every woocommerce API call requires consumer_key, consumer_secret, storeUrl, queryStringAuth.
27
+ * consumer_key, consumer_secret, storeUrl are retrieved from database, queryStringAuth must always set to true
28
+ * to avoid permission error from Woocommerce.
29
+ */
26
30
  export const action = async ({ store, method = 'get', path, request }) => {
27
31
  const client = new Woocommerce({
28
32
  consumer_key: store.accessKey,
@@ -18,14 +18,19 @@ export class Woocommerce {
18
18
  }
19
19
  }
20
20
 
21
+ /**
22
+ * @summary Get Method
23
+ * @description Using v3 API, map the consumer_key, consumer_secret to the endpoint path.
24
+ * X-WP-Total is to get the total items from the response
25
+ */
21
26
  async get(path: string, data: any) {
22
- const { consumer_key, consumer_secret, storeURL } = this.config
27
+ const { consumer_key, consumer_secret, storeURL, queryStringAuth } = this.config
23
28
 
24
29
  const qs = Object.entries(data)
25
30
  .map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`)
26
31
  .join('&')
27
32
 
28
- const endpoint = `${storeURL}/wp-json/wc/v3${path}?consumer_key=${consumer_key}&consumer_secret=${consumer_secret}${
33
+ const endpoint = `${storeURL}/wp-json/wc/v3${path}?consumer_key=${consumer_key}&consumer_secret=${consumer_secret}&query_string_auth=${queryStringAuth}&${
29
34
  qs ? '&' + qs : ''
30
35
  }`
31
36
  debug('endpoint', endpoint)
@@ -7,6 +7,11 @@ import { STORE_STATUS } from '../graphql/constants'
7
7
 
8
8
  export const woocommerceRouter = new Router()
9
9
 
10
+ /**
11
+ * @summary Callback After Authentication
12
+ * @description When the callback is triggered, we will receive key_id, user_id, consumer_key and consumer_secret
13
+ * from Woocommerce. We store them into database for easy retrieval.
14
+ */
10
15
  export type WoocommerAccessInfo = {
11
16
  key_id: number
12
17
  user_id: string
@@ -17,13 +22,6 @@ export type WoocommerAccessInfo = {
17
22
 
18
23
  woocommerceRouter.post('/callback-woocommerce', async (context, next) => {
19
24
  try {
20
- // {
21
- // "key_id": 1,
22
- // "user_id": 123,
23
- // "consumer_key": "ck_xxxxxxxxxxxxxxxx",
24
- // "consumer_secret": "cs_xxxxxxxxxxxxxxxx",
25
- // "key_permissions": "read_write"
26
- // }
27
25
  const accessInfo: WoocommerAccessInfo = context.request.body
28
26
  await saveWoocommerceAccessInfo(accessInfo)
29
27
  context.status = 200