@things-factory/integration-marketplace 5.0.0-alpha.9 → 5.0.0-y.0
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.
- package/dist-server/controllers/index.js +1 -0
- package/dist-server/controllers/index.js.map +1 -1
- package/dist-server/controllers/lazada/apis/get-store-orders.js +3 -3
- package/dist-server/controllers/lazada/apis/get-store-orders.js.map +1 -1
- package/dist-server/controllers/lazada/apis/update-store-product-stock.js +2 -2
- package/dist-server/controllers/lazada/apis/update-store-product-stock.js.map +1 -1
- package/dist-server/controllers/lazada/apis/update-store-product-variation-stock.js +2 -2
- package/dist-server/controllers/lazada/apis/update-store-product-variation-stock.js.map +1 -1
- package/dist-server/controllers/magento/apis/get-store-order.js +20 -0
- package/dist-server/controllers/magento/apis/get-store-order.js.map +1 -0
- package/dist-server/controllers/magento/apis/get-store-orders.js +38 -7
- package/dist-server/controllers/magento/apis/get-store-orders.js.map +1 -1
- package/dist-server/controllers/magento/apis/get-store-product-categories.js +47 -0
- package/dist-server/controllers/magento/apis/get-store-product-categories.js.map +1 -0
- package/dist-server/controllers/magento/apis/get-store-products.js +29 -11
- package/dist-server/controllers/magento/apis/get-store-products.js.map +1 -1
- package/dist-server/controllers/magento/apis/get-store-stock-item.js +1 -1
- package/dist-server/controllers/magento/apis/get-store-stock-item.js.map +1 -1
- package/dist-server/controllers/magento/apis/index.js +5 -0
- package/dist-server/controllers/magento/apis/index.js.map +1 -1
- package/dist-server/controllers/magento/apis/update-order-status.js +62 -0
- package/dist-server/controllers/magento/apis/update-order-status.js.map +1 -0
- package/dist-server/controllers/magento/apis/update-store-product-price.js +28 -0
- package/dist-server/controllers/magento/apis/update-store-product-price.js.map +1 -0
- package/dist-server/controllers/magento/apis/update-store-product-stock.js +1 -1
- package/dist-server/controllers/magento/apis/update-store-product-stock.js.map +1 -1
- package/dist-server/controllers/magento/apis/update-store-product-variation-price.js +28 -0
- package/dist-server/controllers/magento/apis/update-store-product-variation-price.js.map +1 -0
- package/dist-server/controllers/magento/apis/update-store-product-variation-stock.js +1 -1
- package/dist-server/controllers/magento/apis/update-store-product-variation-stock.js.map +1 -1
- package/dist-server/controllers/magento/magento.js +4 -4
- package/dist-server/controllers/magento/magento.js.map +1 -1
- package/dist-server/controllers/magento/platform-action.js +1 -0
- package/dist-server/controllers/magento/platform-action.js.map +1 -1
- package/dist-server/controllers/shopee/apis/get-store-order-payout-dates.js +3 -3
- package/dist-server/controllers/shopee/apis/get-store-order-payout-dates.js.map +1 -1
- package/dist-server/controllers/shopee/apis/get-store-orders.js +3 -3
- package/dist-server/controllers/shopee/apis/get-store-orders.js.map +1 -1
- package/dist-server/controllers/shopify/apis/get-store-orders.js +72 -12
- package/dist-server/controllers/shopify/apis/get-store-orders.js.map +1 -1
- package/dist-server/controllers/shopify/apis/get-store-product-variation-stock.js +23 -0
- package/dist-server/controllers/shopify/apis/get-store-product-variation-stock.js.map +1 -0
- package/dist-server/controllers/shopify/apis/get-store-products.js +38 -3
- package/dist-server/controllers/shopify/apis/get-store-products.js.map +1 -1
- package/dist-server/controllers/shopify/apis/index.js +4 -0
- package/dist-server/controllers/shopify/apis/index.js.map +1 -1
- package/dist-server/controllers/shopify/apis/update-order-status.js +15 -5
- package/dist-server/controllers/shopify/apis/update-order-status.js.map +1 -1
- package/dist-server/controllers/shopify/apis/update-store-product-price.js +29 -0
- package/dist-server/controllers/shopify/apis/update-store-product-price.js.map +1 -0
- package/dist-server/controllers/shopify/apis/update-store-product-stock.js +24 -0
- package/dist-server/controllers/shopify/apis/update-store-product-stock.js.map +1 -0
- package/dist-server/controllers/shopify/apis/update-store-product-variation-price.js +29 -0
- package/dist-server/controllers/shopify/apis/update-store-product-variation-price.js.map +1 -0
- package/dist-server/controllers/shopify/apis/update-store-product-variation-stock.js +1 -1
- package/dist-server/controllers/shopify/apis/update-store-product-variation-stock.js.map +1 -1
- package/dist-server/controllers/shopify/shopify.js +36 -0
- package/dist-server/controllers/shopify/shopify.js.map +1 -1
- package/dist-server/controllers/store-api/index.js +21 -0
- package/dist-server/controllers/store-api/index.js.map +1 -1
- package/dist-server/controllers/tiktok/apis/echo.js +19 -0
- package/dist-server/controllers/tiktok/apis/echo.js.map +1 -0
- package/dist-server/controllers/tiktok/apis/get-store-order-document.js +27 -0
- package/dist-server/controllers/tiktok/apis/get-store-order-document.js.map +1 -0
- package/dist-server/controllers/tiktok/apis/get-store-order-package.js +47 -0
- package/dist-server/controllers/tiktok/apis/get-store-order-package.js.map +1 -0
- package/dist-server/controllers/tiktok/apis/get-store-order-packages.js +39 -0
- package/dist-server/controllers/tiktok/apis/get-store-order-packages.js.map +1 -0
- package/dist-server/controllers/tiktok/apis/get-store-order.js +140 -0
- package/dist-server/controllers/tiktok/apis/get-store-order.js.map +1 -0
- package/dist-server/controllers/tiktok/apis/get-store-orders.js +49 -0
- package/dist-server/controllers/tiktok/apis/get-store-orders.js.map +1 -0
- package/dist-server/controllers/tiktok/apis/get-store-product-attributes.js +30 -0
- package/dist-server/controllers/tiktok/apis/get-store-product-attributes.js.map +1 -0
- package/dist-server/controllers/tiktok/apis/get-store-product-categories.js +28 -0
- package/dist-server/controllers/tiktok/apis/get-store-product-categories.js.map +1 -0
- package/dist-server/controllers/tiktok/apis/get-store-product.js +91 -0
- package/dist-server/controllers/tiktok/apis/get-store-product.js.map +1 -0
- package/dist-server/controllers/tiktok/apis/get-store-products.js +41 -0
- package/dist-server/controllers/tiktok/apis/get-store-products.js.map +1 -0
- package/dist-server/controllers/tiktok/apis/index.js +30 -0
- package/dist-server/controllers/tiktok/apis/index.js.map +1 -0
- package/dist-server/controllers/tiktok/apis/update-order-status.js +28 -0
- package/dist-server/controllers/tiktok/apis/update-order-status.js.map +1 -0
- package/dist-server/controllers/tiktok/apis/update-store-product-variation-price.js +28 -0
- package/dist-server/controllers/tiktok/apis/update-store-product-variation-price.js.map +1 -0
- package/dist-server/controllers/tiktok/apis/update-store-product-variation-stock.js +32 -0
- package/dist-server/controllers/tiktok/apis/update-store-product-variation-stock.js.map +1 -0
- package/dist-server/controllers/tiktok/client/index.js +19 -0
- package/dist-server/controllers/tiktok/client/index.js.map +1 -0
- package/dist-server/controllers/tiktok/client/signature.js +63 -0
- package/dist-server/controllers/tiktok/client/signature.js.map +1 -0
- package/dist-server/controllers/tiktok/client/tiktok.js +109 -0
- package/dist-server/controllers/tiktok/client/tiktok.js.map +1 -0
- package/dist-server/controllers/tiktok/client/types.js +3 -0
- package/dist-server/controllers/tiktok/client/types.js.map +1 -0
- package/dist-server/controllers/tiktok/index.js +34 -0
- package/dist-server/controllers/tiktok/index.js.map +1 -0
- package/dist-server/controllers/tiktok/platform-action.js +53 -0
- package/dist-server/controllers/tiktok/platform-action.js.map +1 -0
- package/dist-server/controllers/woocommerce/apis/get-store-orders.js +8 -6
- package/dist-server/controllers/woocommerce/apis/get-store-orders.js.map +1 -1
- package/dist-server/controllers/woocommerce/apis/get-store-products.js +38 -11
- package/dist-server/controllers/woocommerce/apis/get-store-products.js.map +1 -1
- package/dist-server/controllers/woocommerce/apis/update-order-status.js +17 -15
- package/dist-server/controllers/woocommerce/apis/update-order-status.js.map +1 -1
- package/dist-server/controllers/woocommerce/apis/update-store-product-variation-price.js +1 -1
- package/dist-server/controllers/woocommerce/apis/update-store-product-variation-price.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-store/lazada/generate-lazada-access-token.js +2 -5
- package/dist-server/graphql/resolvers/marketplace-store/lazada/generate-lazada-access-token.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-store/magento/activate-magento-store.js +2 -2
- package/dist-server/graphql/resolvers/marketplace-store/magento/activate-magento-store.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-store/shopee/generate-shopee-access-token.js +2 -2
- package/dist-server/graphql/resolvers/marketplace-store/shopee/generate-shopee-access-token.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-store/zalora/generate-zalora-access-token.js +2 -5
- package/dist-server/graphql/resolvers/marketplace-store/zalora/generate-zalora-access-token.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-transporter/create-marketplace-transporter.js +2 -5
- package/dist-server/graphql/resolvers/marketplace-transporter/create-marketplace-transporter.js.map +1 -1
- package/dist-server/routers/magento-private-router.js +2 -2
- package/dist-server/routers/magento-private-router.js.map +1 -1
- package/dist-server/routers/shopify-install-private-router.js +2 -2
- package/dist-server/routers/shopify-install-private-router.js.map +1 -1
- package/dist-server/routers/shopify-private-router.js +2 -2
- package/dist-server/routers/shopify-private-router.js.map +1 -1
- package/dist-server/routers/shopify-public-router.js +2 -2
- package/dist-server/routers/shopify-public-router.js.map +1 -1
- package/dist-server/routers/woocommerce-router.js +2 -2
- package/dist-server/routers/woocommerce-router.js.map +1 -1
- package/package.json +15 -15
- package/server/controllers/index.ts +1 -0
- package/server/controllers/lazada/apis/get-store-orders.ts +3 -3
- package/server/controllers/lazada/apis/update-store-product-stock.ts +2 -2
- package/server/controllers/lazada/apis/update-store-product-variation-stock.ts +2 -2
- package/server/controllers/magento/apis/get-store-order.ts +15 -0
- package/server/controllers/magento/apis/get-store-orders.ts +40 -7
- package/server/controllers/magento/apis/get-store-product-categories.ts +43 -0
- package/server/controllers/magento/apis/get-store-products.ts +35 -11
- package/server/controllers/magento/apis/get-store-stock-item.ts +1 -1
- package/server/controllers/magento/apis/index.ts +5 -0
- package/server/controllers/magento/apis/update-order-status.ts +56 -0
- package/server/controllers/magento/apis/update-store-product-price.ts +24 -0
- package/server/controllers/magento/apis/update-store-product-stock.ts +1 -1
- package/server/controllers/magento/apis/update-store-product-variation-price.ts +24 -0
- package/server/controllers/magento/apis/update-store-product-variation-stock.ts +1 -1
- package/server/controllers/magento/magento.ts +5 -4
- package/server/controllers/magento/platform-action.ts +1 -0
- package/server/controllers/shopee/apis/get-store-order-payout-dates.ts +3 -3
- package/server/controllers/shopee/apis/get-store-orders.ts +3 -3
- package/server/controllers/shopify/apis/get-store-orders.ts +74 -13
- package/server/controllers/shopify/apis/get-store-product-variation-stock.ts +17 -0
- package/server/controllers/shopify/apis/get-store-products.ts +38 -3
- package/server/controllers/shopify/apis/index.ts +4 -0
- package/server/controllers/shopify/apis/update-order-status.ts +17 -5
- package/server/controllers/shopify/apis/update-store-product-price.ts +26 -0
- package/server/controllers/shopify/apis/update-store-product-stock.ts +20 -0
- package/server/controllers/shopify/apis/update-store-product-variation-price.ts +26 -0
- package/server/controllers/shopify/apis/update-store-product-variation-stock.ts +1 -1
- package/server/controllers/shopify/shopify.ts +41 -0
- package/server/controllers/store-api/index.ts +9 -0
- package/server/controllers/tiktok/apis/echo.ts +14 -0
- package/server/controllers/tiktok/apis/get-store-order-document.ts +26 -0
- package/server/controllers/tiktok/apis/get-store-order-package.ts +46 -0
- package/server/controllers/tiktok/apis/get-store-order-packages.ts +43 -0
- package/server/controllers/tiktok/apis/get-store-order.ts +174 -0
- package/server/controllers/tiktok/apis/get-store-orders.ts +55 -0
- package/server/controllers/tiktok/apis/get-store-product-attributes.ts +29 -0
- package/server/controllers/tiktok/apis/get-store-product-categories.ts +27 -0
- package/server/controllers/tiktok/apis/get-store-product.ts +95 -0
- package/server/controllers/tiktok/apis/get-store-products.ts +45 -0
- package/server/controllers/tiktok/apis/index.ts +13 -0
- package/server/controllers/tiktok/apis/update-order-status.ts +24 -0
- package/server/controllers/tiktok/apis/update-store-product-variation-price.ts +24 -0
- package/server/controllers/tiktok/apis/update-store-product-variation-stock.ts +28 -0
- package/server/controllers/tiktok/client/index.ts +2 -0
- package/server/controllers/tiktok/client/signature.ts +78 -0
- package/server/controllers/tiktok/client/tiktok.ts +150 -0
- package/server/controllers/tiktok/client/types.ts +20 -0
- package/server/controllers/tiktok/index.ts +8 -0
- package/server/controllers/tiktok/platform-action.ts +72 -0
- package/server/controllers/woocommerce/apis/get-store-orders.ts +9 -6
- package/server/controllers/woocommerce/apis/get-store-products.ts +47 -20
- package/server/controllers/woocommerce/apis/update-order-status.ts +18 -14
- package/server/controllers/woocommerce/apis/update-store-product-variation-price.ts +1 -1
- package/server/graphql/resolvers/marketplace-store/lazada/generate-lazada-access-token.ts +2 -2
- package/server/graphql/resolvers/marketplace-store/magento/activate-magento-store.ts +2 -2
- package/server/graphql/resolvers/marketplace-store/shopee/generate-shopee-access-token.ts +2 -2
- package/server/graphql/resolvers/marketplace-store/zalora/generate-zalora-access-token.ts +2 -2
- package/server/graphql/resolvers/marketplace-transporter/create-marketplace-transporter.ts +2 -2
- package/server/routers/magento-private-router.ts +2 -2
- package/server/routers/shopify-install-private-router.ts +2 -2
- package/server/routers/shopify-private-router.ts +2 -2
- package/server/routers/shopify-public-router.ts +2 -2
- package/server/routers/woocommerce-router.ts +2 -2
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import fetch from 'node-fetch'
|
|
2
|
+
|
|
3
|
+
import { makePublicRequestParameters } from './signature'
|
|
4
|
+
import { Parameter } from './types'
|
|
5
|
+
|
|
6
|
+
const debug = require('debug')('things-factory:integration-marketplace:tiktok')
|
|
7
|
+
|
|
8
|
+
export type TiktokConfig = {
|
|
9
|
+
appKey: string
|
|
10
|
+
appSecret: string
|
|
11
|
+
accessToken: string
|
|
12
|
+
channelShopId: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class Tiktok {
|
|
16
|
+
private config: TiktokConfig
|
|
17
|
+
|
|
18
|
+
constructor(config: TiktokConfig) {
|
|
19
|
+
this.config = {
|
|
20
|
+
...config
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getBaseURL() {
|
|
25
|
+
return `https://open-api.tiktokglobalshop.com`
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @summary Get Method
|
|
30
|
+
* @description Using v3 API, map the consumer_key, consumer_secret to the endpoint path.
|
|
31
|
+
* X-WP-Total is to get the total items from the response
|
|
32
|
+
*/
|
|
33
|
+
async get(path: string, params: Parameter) {
|
|
34
|
+
const { appKey, appSecret, accessToken, channelShopId } = this.config
|
|
35
|
+
|
|
36
|
+
const qs = Object.entries({
|
|
37
|
+
...params,
|
|
38
|
+
...makePublicRequestParameters(appKey, appSecret, path, accessToken, channelShopId, params)
|
|
39
|
+
})
|
|
40
|
+
.map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`)
|
|
41
|
+
.join('&')
|
|
42
|
+
|
|
43
|
+
const endpoint = `${this.getBaseURL()}${path}?${qs ? qs : ''}`
|
|
44
|
+
debug('endpoint', endpoint)
|
|
45
|
+
|
|
46
|
+
const response = await fetch(endpoint, {
|
|
47
|
+
headers: {
|
|
48
|
+
'Content-Type': 'application/json'
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
var result: any = {}
|
|
53
|
+
const resResult: any = await response.json()
|
|
54
|
+
|
|
55
|
+
debug('response result', resResult)
|
|
56
|
+
|
|
57
|
+
return resResult
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async post(path: string, data: any = {}) {
|
|
61
|
+
const { appKey, appSecret, accessToken, channelShopId } = this.config
|
|
62
|
+
|
|
63
|
+
debug('data', data)
|
|
64
|
+
|
|
65
|
+
const jsondata = JSON.stringify(data)
|
|
66
|
+
|
|
67
|
+
const { app_key, timestamp, access_token, sign, shop_id } = makePublicRequestParameters(
|
|
68
|
+
appKey,
|
|
69
|
+
appSecret,
|
|
70
|
+
path,
|
|
71
|
+
accessToken,
|
|
72
|
+
channelShopId
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
const qs = Object.entries({
|
|
76
|
+
app_key,
|
|
77
|
+
timestamp,
|
|
78
|
+
access_token,
|
|
79
|
+
sign,
|
|
80
|
+
shop_id
|
|
81
|
+
})
|
|
82
|
+
.map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`)
|
|
83
|
+
.join('&')
|
|
84
|
+
|
|
85
|
+
const endpoint = `${this.getBaseURL()}${path}?${qs ? '&' + qs : ''}`
|
|
86
|
+
const response = await fetch(endpoint, {
|
|
87
|
+
method: 'post',
|
|
88
|
+
headers: {
|
|
89
|
+
'Content-Type': 'application/json'
|
|
90
|
+
},
|
|
91
|
+
body: jsondata
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
if (response.ok) {
|
|
95
|
+
let result = await response.json()
|
|
96
|
+
result.requiredDocument = true
|
|
97
|
+
return result
|
|
98
|
+
} else {
|
|
99
|
+
const result = await response.json()
|
|
100
|
+
throw new Error(`(${result.code}) ${result.message}`)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async put(path: string, data: any = {}) {
|
|
105
|
+
const { appKey, appSecret, accessToken, channelShopId } = this.config
|
|
106
|
+
|
|
107
|
+
debug('data', data)
|
|
108
|
+
|
|
109
|
+
const jsondata = JSON.stringify(data)
|
|
110
|
+
|
|
111
|
+
const { app_key, timestamp, access_token, sign, shop_id } = makePublicRequestParameters(
|
|
112
|
+
appKey,
|
|
113
|
+
appSecret,
|
|
114
|
+
path,
|
|
115
|
+
accessToken,
|
|
116
|
+
channelShopId
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
const qs = Object.entries({
|
|
120
|
+
app_key,
|
|
121
|
+
timestamp,
|
|
122
|
+
access_token,
|
|
123
|
+
sign,
|
|
124
|
+
shop_id
|
|
125
|
+
})
|
|
126
|
+
.map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`)
|
|
127
|
+
.join('&')
|
|
128
|
+
|
|
129
|
+
const endpoint = `${this.getBaseURL()}${path}?${qs ? '&' + qs : ''}`
|
|
130
|
+
const response = await fetch(endpoint, {
|
|
131
|
+
method: 'put',
|
|
132
|
+
headers: {
|
|
133
|
+
'Content-Type': 'application/json'
|
|
134
|
+
},
|
|
135
|
+
body: jsondata
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
if (response.ok) {
|
|
139
|
+
const result = await response.json()
|
|
140
|
+
if (result?.code == 0) {
|
|
141
|
+
return result
|
|
142
|
+
} else {
|
|
143
|
+
throw new Error(`(${result.code}) ${result.message}`)
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
const result = await response.json()
|
|
147
|
+
throw new Error(`(${result.code}) ${result.message}`)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type Parameter = {
|
|
2
|
+
[key: string]: any
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tiktok Open Platform Public Request Parameters
|
|
7
|
+
* @typedef PublicRequestParameters
|
|
8
|
+
* @property {string} timestamp :mandatory
|
|
9
|
+
* @property {string} app_key :mandatory
|
|
10
|
+
* @property {string} access_token :mandatory
|
|
11
|
+
* @property {string} shop_id :mandatory
|
|
12
|
+
* @property {string} sign :mandatory
|
|
13
|
+
*/
|
|
14
|
+
export interface PublicRequestParameters {
|
|
15
|
+
timestamp: string
|
|
16
|
+
app_key: string
|
|
17
|
+
access_token: string
|
|
18
|
+
sign: string
|
|
19
|
+
shop_id?: string
|
|
20
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { createPayloadLog } from '@things-factory/integration-base'
|
|
2
|
+
|
|
3
|
+
import { Tiktok } from './client/tiktok'
|
|
4
|
+
|
|
5
|
+
function substitute(path, obj) {
|
|
6
|
+
var props = []
|
|
7
|
+
var re = /{([^}]+)}/g
|
|
8
|
+
var text
|
|
9
|
+
|
|
10
|
+
while ((text = re.exec(path))) {
|
|
11
|
+
props.push(text[1])
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
var result = path
|
|
15
|
+
props.forEach(prop => {
|
|
16
|
+
let value = obj[prop.trim()]
|
|
17
|
+
result = result.replace(`{${prop}}`, value === undefined ? '' : value)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
return result
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @summary Building Path Method and Payload
|
|
25
|
+
* @description After denormalise of data is done,
|
|
26
|
+
* platform API method will be called with its path and payload,
|
|
27
|
+
* this section is to build path and substitution of the resource in url as well as the payload for body request.
|
|
28
|
+
* Every Tiktok API call requires consumer_key, consumer_secret, access_token.
|
|
29
|
+
* consumer_key, consumer_secret, access_token are retrieved from tokencraft
|
|
30
|
+
* to avoid permission error from TikTok.
|
|
31
|
+
*/
|
|
32
|
+
export const action = async ({ store, method = 'get', path, request }) => {
|
|
33
|
+
const client = new Tiktok({
|
|
34
|
+
appKey: store.accessKey || '5p6q6g',
|
|
35
|
+
appSecret: store.accessSecret || 'c30cf452265ab418514bb81fa49fc333aecbf081',
|
|
36
|
+
accessToken: store.accessToken,
|
|
37
|
+
channelShopId: store.channelShopId
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const { resource = {}, payload = {}, requiredAPICall = true } = request
|
|
41
|
+
|
|
42
|
+
let response: any
|
|
43
|
+
if (requiredAPICall) {
|
|
44
|
+
path = substitute(path, resource)
|
|
45
|
+
|
|
46
|
+
response = await client[method](path, payload)
|
|
47
|
+
} else {
|
|
48
|
+
response = { code: 0, message: 'Success' }
|
|
49
|
+
}
|
|
50
|
+
|
|
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
|
+
|
|
60
|
+
throw response
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
createPayloadLog(
|
|
64
|
+
store.channelShopId,
|
|
65
|
+
path,
|
|
66
|
+
request,
|
|
67
|
+
response,
|
|
68
|
+
request?.context ? request.context : { state: { domain: null } }
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
return response
|
|
72
|
+
}
|
|
@@ -8,11 +8,11 @@ export function getStoreOrders() {
|
|
|
8
8
|
method: 'get',
|
|
9
9
|
path: '/orders',
|
|
10
10
|
denormalize(req) {
|
|
11
|
-
var { pagination,
|
|
11
|
+
var { pagination, fromCreatedDate, toCreatedDate } = req || {}
|
|
12
12
|
var { page = 0, limit = 100 } = pagination || {}
|
|
13
13
|
|
|
14
|
-
var after = new Date(
|
|
15
|
-
var before = new Date(
|
|
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
|
|
|
@@ -166,7 +168,8 @@ export function getStoreOrders() {
|
|
|
166
168
|
billing,
|
|
167
169
|
shipping,
|
|
168
170
|
firstName,
|
|
169
|
-
lastName
|
|
171
|
+
lastName,
|
|
172
|
+
isSOF: true
|
|
170
173
|
})
|
|
171
174
|
}
|
|
172
175
|
|
|
@@ -17,7 +17,6 @@ export function getStoreProducts() {
|
|
|
17
17
|
return { payload }
|
|
18
18
|
},
|
|
19
19
|
async normalize(res, { store }) {
|
|
20
|
-
|
|
21
20
|
const { items, totalItems: totalProducts } = res
|
|
22
21
|
|
|
23
22
|
let results: any[] = []
|
|
@@ -36,13 +35,25 @@ export function getStoreProducts() {
|
|
|
36
35
|
images: product.images.map(image => {
|
|
37
36
|
return image.src
|
|
38
37
|
}),
|
|
39
|
-
attributes:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
attributes:
|
|
39
|
+
product?.attributes?.map(attribute => {
|
|
40
|
+
return {
|
|
41
|
+
attributeId: attribute.id,
|
|
42
|
+
name: attribute.name,
|
|
43
|
+
originalValue: attribute.options,
|
|
44
|
+
native_attribute_id: attribute.id,
|
|
45
|
+
attribute_key: attribute.name,
|
|
46
|
+
values: attribute.options
|
|
47
|
+
}
|
|
48
|
+
}) || [],
|
|
49
|
+
sellercraftAttributes: [
|
|
50
|
+
{
|
|
51
|
+
native_attribute_id: 'description',
|
|
52
|
+
attribute_key: 'description',
|
|
53
|
+
display_name: 'Description',
|
|
54
|
+
values: [product.description]
|
|
44
55
|
}
|
|
45
|
-
|
|
56
|
+
],
|
|
46
57
|
isVerified: product.purchasable,
|
|
47
58
|
variations:
|
|
48
59
|
productVariations.length === 0
|
|
@@ -55,15 +66,19 @@ export function getStoreProducts() {
|
|
|
55
66
|
qty: product.manage_stock === true ? parseFloat(product.stock_quantity) : null,
|
|
56
67
|
primaryUnit: 'N/A',
|
|
57
68
|
primaryUnitValue: product.weight === '' ? null : parseFloat(product.weight),
|
|
58
|
-
costPrice: product.price === '' ? null : parseFloat(product.
|
|
69
|
+
costPrice: product.price === '' ? null : parseFloat(product.regular_price),
|
|
59
70
|
sellPrice: product.sale_price === '' ? null : parseFloat(product.sale_price),
|
|
60
|
-
attributes:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
71
|
+
attributes:
|
|
72
|
+
product?.attributes?.map(attribute => {
|
|
73
|
+
return {
|
|
74
|
+
attributeId: attribute.id,
|
|
75
|
+
name: attribute.name,
|
|
76
|
+
originalValue: attribute.options,
|
|
77
|
+
native_attribute_id: attribute.id,
|
|
78
|
+
attribute_key: attribute.name,
|
|
79
|
+
values: attribute.options
|
|
80
|
+
}
|
|
81
|
+
}) || [],
|
|
67
82
|
isEnabled: product.purchasable,
|
|
68
83
|
length: product.dimensions.length * 10,
|
|
69
84
|
width: product.dimensions.width * 10,
|
|
@@ -81,15 +96,27 @@ export function getStoreProducts() {
|
|
|
81
96
|
qty: variant.manage_stock === true ? parseFloat(variant.stock_quantity) : null,
|
|
82
97
|
primaryUnit: 'N/A',
|
|
83
98
|
primaryUnitValue: variant.weight === '' ? null : parseFloat(variant.weight),
|
|
84
|
-
costPrice: variant.price === '' ? null : parseFloat(variant.
|
|
99
|
+
costPrice: variant.price === '' ? null : parseFloat(variant.regular_price),
|
|
85
100
|
sellPrice: variant.sale_price === '' ? null : parseFloat(variant.sale_price),
|
|
86
|
-
attributes:
|
|
101
|
+
attributes:
|
|
102
|
+
variant?.attributes?.map(attribute => {
|
|
103
|
+
return {
|
|
104
|
+
attributeId: attribute.id,
|
|
105
|
+
name: attribute.name,
|
|
106
|
+
originalValue: attribute.options,
|
|
107
|
+
native_attribute_id: attribute.id,
|
|
108
|
+
attribute_key: attribute.name,
|
|
109
|
+
values: [attribute.option]
|
|
110
|
+
}
|
|
111
|
+
}) || [],
|
|
112
|
+
sellercraftAttributes: variant?.attributes?.map(attribute => {
|
|
87
113
|
return {
|
|
88
|
-
native_attribute_id: attribute.
|
|
114
|
+
native_attribute_id: attribute.name,
|
|
89
115
|
attribute_key: attribute.name,
|
|
90
|
-
|
|
116
|
+
display_name: attribute.name,
|
|
117
|
+
values: [attribute.option]
|
|
91
118
|
}
|
|
92
|
-
}),
|
|
119
|
+
}) || [],
|
|
93
120
|
isEnabled: variant.purchasable,
|
|
94
121
|
length: variant.dimensions.length * 10,
|
|
95
122
|
width: variant.dimensions.width * 10,
|
|
@@ -3,6 +3,23 @@
|
|
|
3
3
|
|
|
4
4
|
import { StoreAPI } from '../../store-api'
|
|
5
5
|
|
|
6
|
+
const ORDER_STATUS = {
|
|
7
|
+
PAYMENT_PENDING: 'pending',
|
|
8
|
+
PROCESSING: 'processing',
|
|
9
|
+
PACKED: 'processing',
|
|
10
|
+
READY_TO_SHIP: 'processing',
|
|
11
|
+
SHIPPED: 'processing',
|
|
12
|
+
CONFIRMED: 'processing',
|
|
13
|
+
DELIVERED: 'completed',
|
|
14
|
+
CLOSED: 'completed',
|
|
15
|
+
CANCELLED: 'cancelled',
|
|
16
|
+
REFUND_COMPLETE: 'refunded',
|
|
17
|
+
RETURN_COMPLETE: 'refunded',
|
|
18
|
+
REVERSE_SHIPMENT_FAILED: 'failed',
|
|
19
|
+
SHIPMENT_LOST_OR_DAMAGED: 'failed',
|
|
20
|
+
PAYMENT_PENDING_TIMEOUT: 'failed'
|
|
21
|
+
}
|
|
22
|
+
|
|
6
23
|
export function updateOrderStatus(req) {
|
|
7
24
|
return {
|
|
8
25
|
method: 'put',
|
|
@@ -12,20 +29,7 @@ export function updateOrderStatus(req) {
|
|
|
12
29
|
|
|
13
30
|
const order = await StoreAPI.getStoreOrder(store, { orderId })
|
|
14
31
|
|
|
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
|
-
}
|
|
32
|
+
let orderStatus = ORDER_STATUS[`${status}`] || order.status
|
|
29
33
|
|
|
30
34
|
return { resource: { orderId: orderId }, payload: { status: orderStatus } }
|
|
31
35
|
},
|
|
@@ -10,7 +10,7 @@ export function updateStoreProductVariationPrice(req) {
|
|
|
10
10
|
|
|
11
11
|
return {
|
|
12
12
|
resource: { itemId: parseInt(productId), variantId: parseInt(variationId) },
|
|
13
|
-
payload: { regular_price: costPrice?.toString(), sale_price: sellPrice?.toString() }
|
|
13
|
+
payload: { regular_price: costPrice?.toString(), sale_price: sellPrice?.toString(), on_sale: costPrice != sellPrice ? true : false }
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
normalize(res) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
2
2
|
|
|
3
3
|
import { config } from '@things-factory/env'
|
|
4
4
|
|
|
@@ -42,7 +42,7 @@ export const generateLazadaAccessToken = {
|
|
|
42
42
|
|
|
43
43
|
if (!foundMarketplaceSetting) {
|
|
44
44
|
const marketplaceSetting = new MarketplaceSetting()
|
|
45
|
-
marketplaceSetting.name =
|
|
45
|
+
marketplaceSetting.name = uuidv4()
|
|
46
46
|
marketplaceSetting.marketplaceStore = marketplaceStore
|
|
47
47
|
marketplaceSetting.value = '100'
|
|
48
48
|
marketplaceSetting.category = category
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fetch from 'node-fetch'
|
|
2
|
-
import
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
3
3
|
|
|
4
4
|
import { MarketplaceSetting, MarketplaceStore } from '../../../../entities'
|
|
5
5
|
import { STORE_STATUS } from '../../../constants'
|
|
@@ -65,7 +65,7 @@ export const activateMagentoStore = {
|
|
|
65
65
|
|
|
66
66
|
if (!foundMarketplaceSetting) {
|
|
67
67
|
const marketplaceSetting = new MarketplaceSetting()
|
|
68
|
-
marketplaceSetting.name =
|
|
68
|
+
marketplaceSetting.name = uuidv4()
|
|
69
69
|
marketplaceSetting.marketplaceStore = marketplaceStore
|
|
70
70
|
marketplaceSetting.value = '100'
|
|
71
71
|
marketplaceSetting.category = category
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import crypto from 'crypto'
|
|
2
2
|
import Debug from 'debug'
|
|
3
3
|
import fetch from 'node-fetch'
|
|
4
|
-
import
|
|
4
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
5
5
|
|
|
6
6
|
import { config } from '@things-factory/env'
|
|
7
7
|
|
|
@@ -77,7 +77,7 @@ export const generateShopeeAccessToken = {
|
|
|
77
77
|
|
|
78
78
|
if (!foundMarketplaceSetting) {
|
|
79
79
|
const marketplaceSetting = new MarketplaceSetting()
|
|
80
|
-
marketplaceSetting.name =
|
|
80
|
+
marketplaceSetting.name = uuidv4()
|
|
81
81
|
marketplaceSetting.marketplaceStore = marketplaceStore
|
|
82
82
|
marketplaceSetting.value = '100'
|
|
83
83
|
marketplaceSetting.category = category
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
2
2
|
|
|
3
3
|
import { MarketplaceSetting, MarketplaceStore } from '../../../../entities'
|
|
4
4
|
import { STORE_STATUS } from '../../../constants'
|
|
@@ -36,7 +36,7 @@ export const generateZaloraAccessToken = {
|
|
|
36
36
|
|
|
37
37
|
if (!foundMarketplaceSetting) {
|
|
38
38
|
const marketplaceSetting = new MarketplaceSetting()
|
|
39
|
-
marketplaceSetting.name =
|
|
39
|
+
marketplaceSetting.name = uuidv4()
|
|
40
40
|
marketplaceSetting.marketplaceStore = marketplaceStore
|
|
41
41
|
marketplaceSetting.value = '100'
|
|
42
42
|
marketplaceSetting.category = category
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CourierService } from '@things-factory/integration-lmd'
|
|
2
|
-
import
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
3
3
|
import { MarketplaceStore, MarketplaceTransporter } from '../../../entities'
|
|
4
4
|
|
|
5
5
|
export const createMarketplaceTransporter = {
|
|
@@ -7,7 +7,7 @@ export const createMarketplaceTransporter = {
|
|
|
7
7
|
const { domain, user, tx } = context.state
|
|
8
8
|
|
|
9
9
|
return await tx.getRepository(MarketplaceTransporter).save({
|
|
10
|
-
name:
|
|
10
|
+
name: uuidv4().toString(),
|
|
11
11
|
marketplaceStore: await tx.getRepository(MarketplaceStore).findOne(marketplaceStoreId),
|
|
12
12
|
deliveryTransporter: await tx.getRepository(CourierService).findOne(deliveryTransporter),
|
|
13
13
|
pickupTransporter: await tx.getRepository(CourierService).findOne(deliveryTransporter),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Router from 'koa-router'
|
|
2
2
|
import fetch from 'node-fetch'
|
|
3
3
|
import { getRepository } from 'typeorm'
|
|
4
|
-
import
|
|
4
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
5
5
|
|
|
6
6
|
import { config } from '@things-factory/env'
|
|
7
7
|
import { getRedirectSubdomainPath } from '@things-factory/shell'
|
|
@@ -173,7 +173,7 @@ magentoPrivateRouter.get(
|
|
|
173
173
|
|
|
174
174
|
if (!foundMarketplaceSetting) {
|
|
175
175
|
const marketplaceSetting = new MarketplaceSetting()
|
|
176
|
-
marketplaceSetting.name =
|
|
176
|
+
marketplaceSetting.name = uuidv4()
|
|
177
177
|
marketplaceSetting.marketplaceStore = marketplaceStore
|
|
178
178
|
marketplaceSetting.value = '100'
|
|
179
179
|
marketplaceSetting.category = category
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Router from 'koa-router'
|
|
2
2
|
import { getRepository } from 'typeorm'
|
|
3
|
-
import
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
4
4
|
|
|
5
5
|
import { config } from '@things-factory/env'
|
|
6
6
|
import { getRedirectSubdomainPath } from '@things-factory/shell'
|
|
@@ -76,7 +76,7 @@ shopifyInstallPrivateRouter.get(
|
|
|
76
76
|
|
|
77
77
|
if (!foundMarketplaceSetting) {
|
|
78
78
|
const marketplaceSetting = new MarketplaceSetting()
|
|
79
|
-
marketplaceSetting.name =
|
|
79
|
+
marketplaceSetting.name = uuidv4()
|
|
80
80
|
marketplaceSetting.marketplaceStore = marketplaceStore
|
|
81
81
|
marketplaceSetting.value = '100'
|
|
82
82
|
marketplaceSetting.category = category
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Router from 'koa-router'
|
|
2
2
|
import { getRepository } from 'typeorm'
|
|
3
|
-
import
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
4
4
|
import { config } from '@things-factory/env'
|
|
5
5
|
import { getUrlFromContext } from '@things-factory/shell'
|
|
6
6
|
import { VerificationToken, VerificationTokenType } from '@things-factory/auth-base'
|
|
@@ -52,7 +52,7 @@ shopifyPrivateRouter.get(
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
const marketplaceSetting = new MarketplaceSetting()
|
|
55
|
-
marketplaceSetting.name =
|
|
55
|
+
marketplaceSetting.name = uuidv4()
|
|
56
56
|
marketplaceSetting.marketplaceStore = marketplaceStore
|
|
57
57
|
marketplaceSetting.value = '100'
|
|
58
58
|
marketplaceSetting.category = 'stock_allocation'
|
|
@@ -4,7 +4,7 @@ import { getRedirectSubdomainPath } from '@things-factory/shell'
|
|
|
4
4
|
import Router from 'koa-router'
|
|
5
5
|
import fetch from 'node-fetch'
|
|
6
6
|
import { getRepository } from 'typeorm'
|
|
7
|
-
import
|
|
7
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
8
8
|
import { StoreAPI } from '../controllers/store-api'
|
|
9
9
|
import { MarketplaceSetting, MarketplaceStore } from '../entities'
|
|
10
10
|
import { STORE_STATUS } from '../graphql/constants'
|
|
@@ -84,7 +84,7 @@ shopifyPublicRouter.get('/callback-shopify', async (context, next) => {
|
|
|
84
84
|
})
|
|
85
85
|
|
|
86
86
|
const marketplaceSetting = new MarketplaceSetting()
|
|
87
|
-
marketplaceSetting.name =
|
|
87
|
+
marketplaceSetting.name = uuidv4()
|
|
88
88
|
marketplaceSetting.marketplaceStore = store
|
|
89
89
|
marketplaceSetting.value = '100'
|
|
90
90
|
marketplaceSetting.category = 'stock_allocation'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Router from 'koa-router'
|
|
2
2
|
import { getRepository } from 'typeorm'
|
|
3
|
-
import
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
4
4
|
|
|
5
5
|
import { MarketplaceSetting, MarketplaceStore } from '../entities'
|
|
6
6
|
import { STORE_STATUS } from '../graphql/constants'
|
|
@@ -55,7 +55,7 @@ async function saveWoocommerceAccessInfo(accessInfo: WoocommerAccessInfo): Promi
|
|
|
55
55
|
|
|
56
56
|
if (!foundMarketplaceSetting) {
|
|
57
57
|
const marketplaceSetting = new MarketplaceSetting()
|
|
58
|
-
marketplaceSetting.name =
|
|
58
|
+
marketplaceSetting.name = uuidv4()
|
|
59
59
|
marketplaceSetting.marketplaceStore = marketplaceStore
|
|
60
60
|
marketplaceSetting.value = '100'
|
|
61
61
|
marketplaceSetting.category = category
|