@things-factory/integration-sellercraft 5.0.14 → 6.0.0-alpha.3
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/sellercraft/sellercraft.js +6 -6
- package/dist-server/controllers/sellercraft/sellercraft.js.map +1 -1
- package/dist-server/controllers/sellercraft-api/decorators.js +12 -6
- package/dist-server/controllers/sellercraft-api/decorators.js.map +1 -1
- package/dist-server/controllers/sellercraft-api/index.js +2 -2
- package/dist-server/controllers/sellercraft-api/index.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js +5 -3
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration-api/index.js +2 -2
- package/dist-server/controllers/sellercraft-channel-integration-api/index.js.map +1 -1
- package/dist-server/routers/sellercraft-router.js +29 -3
- package/dist-server/routers/sellercraft-router.js.map +1 -1
- package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +294 -258
- package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js.map +1 -1
- package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js +59 -16
- package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -1
- package/dist-server/service/marketplace-channel/marketplace-channel.js +8 -4
- package/dist-server/service/marketplace-channel/marketplace-channel.js.map +1 -1
- package/dist-server/service/sellercraft/sellercraft-mutation.js +6 -4
- package/dist-server/service/sellercraft/sellercraft-mutation.js.map +1 -1
- package/dist-server/service/sellercraft/sellercraft-query.js +6 -8
- package/dist-server/service/sellercraft/sellercraft-query.js.map +1 -1
- package/dist-server/service/sellercraft/sellercraft.js +8 -4
- package/dist-server/service/sellercraft/sellercraft.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -16
- package/server/controllers/sellercraft/sellercraft.ts +6 -6
- package/server/controllers/sellercraft-api/decorators.ts +11 -6
- package/server/controllers/sellercraft-api/index.ts +1 -1
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +5 -3
- package/server/controllers/sellercraft-channel-integration-api/index.ts +1 -1
- package/server/routers/sellercraft-router.ts +45 -4
- package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +348 -310
- package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +78 -17
- package/server/service/marketplace-channel/marketplace-channel.ts +4 -0
- package/server/service/sellercraft/sellercraft-mutation.ts +17 -9
- package/server/service/sellercraft/sellercraft-query.ts +7 -8
- package/server/service/sellercraft/sellercraft.ts +5 -1
package/package.json
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "@things-factory/integration-sellercraft",
|
3
|
-
"version": "
|
3
|
+
"version": "6.0.0-alpha.3",
|
4
4
|
"main": "dist-server/index.js",
|
5
5
|
"browser": "client/index.js",
|
6
6
|
"things-factory": true,
|
7
7
|
"license": "MIT",
|
8
|
-
"author": "heartyoh",
|
8
|
+
"author": "heartyoh <heartyoh@hatiolab.com>",
|
9
9
|
"description": "A microservice that manage integration with sellercraft ecommerce omnichannel app",
|
10
10
|
"publishConfig": {
|
11
11
|
"access": "public",
|
@@ -24,19 +24,19 @@
|
|
24
24
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
|
25
25
|
},
|
26
26
|
"dependencies": {
|
27
|
-
"@things-factory/apptool-ui": "^
|
28
|
-
"@things-factory/auth-ui": "^
|
29
|
-
"@things-factory/biz-base": "^
|
30
|
-
"@things-factory/code-ui": "^
|
31
|
-
"@things-factory/context-ui": "^
|
32
|
-
"@things-factory/grist-ui": "^
|
33
|
-
"@things-factory/i18n-base": "^
|
34
|
-
"@things-factory/integration-marketplace": "^
|
35
|
-
"@things-factory/integration-ui": "^
|
36
|
-
"@things-factory/more-ui": "^
|
37
|
-
"@things-factory/resource-ui": "^
|
38
|
-
"@things-factory/setting-ui": "^
|
39
|
-
"@things-factory/system-ui": "^
|
27
|
+
"@things-factory/apptool-ui": "^6.0.0-alpha.3",
|
28
|
+
"@things-factory/auth-ui": "^6.0.0-alpha.3",
|
29
|
+
"@things-factory/biz-base": "^6.0.0-alpha.3",
|
30
|
+
"@things-factory/code-ui": "^6.0.0-alpha.3",
|
31
|
+
"@things-factory/context-ui": "^6.0.0-alpha.3",
|
32
|
+
"@things-factory/grist-ui": "^6.0.0-alpha.3",
|
33
|
+
"@things-factory/i18n-base": "^6.0.0-alpha.3",
|
34
|
+
"@things-factory/integration-marketplace": "^6.0.0-alpha.3",
|
35
|
+
"@things-factory/integration-ui": "^6.0.0-alpha.3",
|
36
|
+
"@things-factory/more-ui": "^6.0.0-alpha.3",
|
37
|
+
"@things-factory/resource-ui": "^6.0.0-alpha.3",
|
38
|
+
"@things-factory/setting-ui": "^6.0.0-alpha.3",
|
39
|
+
"@things-factory/system-ui": "^6.0.0-alpha.3",
|
40
40
|
"debug": "^4.1.1",
|
41
41
|
"node-fetch": "^2.6.0",
|
42
42
|
"querystring": "^0.2.1"
|
@@ -51,5 +51,5 @@
|
|
51
51
|
"nock": "^13.0.2",
|
52
52
|
"should": "^13.2.3"
|
53
53
|
},
|
54
|
-
"gitHead": "
|
54
|
+
"gitHead": "1e273b6485662da938cae8fdca035d994ef4a95d"
|
55
55
|
}
|
@@ -46,8 +46,8 @@ export class Sellercraft {
|
|
46
46
|
if (response.ok) {
|
47
47
|
return await response.json()
|
48
48
|
} else {
|
49
|
-
const result = await response.
|
50
|
-
throw new Error(`(${response.status}) ${result
|
49
|
+
const result = await response.text()
|
50
|
+
throw new Error(`(${response.status}) ${result}`)
|
51
51
|
}
|
52
52
|
}
|
53
53
|
|
@@ -72,8 +72,8 @@ export class Sellercraft {
|
|
72
72
|
if (response.ok) {
|
73
73
|
return await response.json()
|
74
74
|
} else {
|
75
|
-
const result = await response.
|
76
|
-
throw new Error(`(${response.status}) ${result
|
75
|
+
const result = await response.text()
|
76
|
+
throw new Error(`(${response.status}) ${result}`)
|
77
77
|
}
|
78
78
|
}
|
79
79
|
|
@@ -102,8 +102,8 @@ export class Sellercraft {
|
|
102
102
|
if (response.ok) {
|
103
103
|
return await response.json()
|
104
104
|
} else {
|
105
|
-
const result = await response.
|
106
|
-
throw new Error(`(${response.status}) ${result
|
105
|
+
const result = await response.text()
|
106
|
+
throw new Error(`(${response.status}) ${result}`)
|
107
107
|
}
|
108
108
|
}
|
109
109
|
}
|
@@ -32,15 +32,20 @@ export const api = (target: Object, property: string, descriptor: TypedPropertyD
|
|
32
32
|
var denormalized = await denormalize(request || {}, { store })
|
33
33
|
debug('request', denormalized)
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
try {
|
36
|
+
var response = await action.apply(this, [
|
37
|
+
{ store, method: httpMethod, path, request: denormalized, platformAction }
|
38
|
+
])
|
38
39
|
|
39
|
-
|
40
|
+
createPayloadLog(store.accountId, path, denormalized, response, request?.context)
|
40
41
|
|
41
|
-
|
42
|
+
debug('response', response)
|
42
43
|
|
43
|
-
|
44
|
+
return await normalize(response, { store })
|
45
|
+
} catch (error) {
|
46
|
+
createPayloadLog(store.accountId, path, denormalized, error, request?.context)
|
47
|
+
throw error
|
48
|
+
}
|
44
49
|
}
|
45
50
|
|
46
51
|
return descriptor
|
@@ -14,6 +14,7 @@ export function ingestChannelOrder() {
|
|
14
14
|
organisation_id: order.organisationId,
|
15
15
|
channel_shop_id: order.channelShopId,
|
16
16
|
native_order_id: order.id.toString(),
|
17
|
+
native_order_display_id: order?.sellercraftDisplayOrderNo,
|
17
18
|
ordered_at_date: new Date(order.createdAt).toISOString().slice(0, -5) + 'Z',
|
18
19
|
ordered_at_time: new Date(order.createdAt).toISOString().slice(0, -5) + 'Z',
|
19
20
|
updated_at_date: new Date(order.updatedAt).toISOString().slice(0, -5) + 'Z',
|
@@ -27,7 +28,7 @@ export function ingestChannelOrder() {
|
|
27
28
|
amount_nett: parseFloat(charge.nettAmount) || 0
|
28
29
|
}
|
29
30
|
}),
|
30
|
-
address_shipping: {
|
31
|
+
address_shipping: order?.shipAddress1 ? {
|
31
32
|
first_name: order.shipFirstName,
|
32
33
|
last_name: order.shipLastName,
|
33
34
|
line_1: order.shipAddress1,
|
@@ -40,7 +41,7 @@ export function ingestChannelOrder() {
|
|
40
41
|
country: order.shipCountry,
|
41
42
|
phone_1: order.shipPhone1,
|
42
43
|
phone_2: order.shipPhone2
|
43
|
-
},
|
44
|
+
} : null,
|
44
45
|
address_billing: {
|
45
46
|
first_name: order.billFirstName,
|
46
47
|
last_name: order.billLastName,
|
@@ -75,7 +76,8 @@ export function ingestChannelOrder() {
|
|
75
76
|
order_status_value: ORDER_STATUS[`${order.status}`]
|
76
77
|
}
|
77
78
|
}),
|
78
|
-
seller_logistics: order?.isSOF
|
79
|
+
seller_logistics: order?.isSOF,
|
80
|
+
shipping_type: order?.shipAddress1 ? 'DROP_SHIPPING' : 'SELF_PICKUP'
|
79
81
|
}
|
80
82
|
})
|
81
83
|
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import Router from 'koa-router'
|
2
2
|
import { v4 as uuidv4 } from 'uuid'
|
3
3
|
|
4
|
-
import { config } from '@things-factory/env'
|
5
4
|
import { StoreAPI } from '@things-factory/integration-marketplace'
|
6
|
-
import {
|
5
|
+
import { createPayloadLog, PayloadType } from '@things-factory/integration-base'
|
6
|
+
import { sleep } from '@things-factory/utils'
|
7
7
|
|
8
8
|
import { SHIPPING_TYPE } from '../constants'
|
9
|
+
import { getShop } from '../utils/tokencraft-util'
|
9
10
|
|
10
11
|
const debug = require('debug')('things-factory:integration-sellercraft:sellercraft-router')
|
11
12
|
|
@@ -106,6 +107,12 @@ sellercraftRouter.post('/sellercraft/store/update-order-status', async (context,
|
|
106
107
|
const requestBody = context.request.body
|
107
108
|
var result: any = {}
|
108
109
|
let mappedStore: any = await getShop(context, requestBody.channel_id, requestBody.shop_id)
|
110
|
+
let packageIds: any =
|
111
|
+
mappedStore.platform == 'tiktok'
|
112
|
+
? requestBody?.order_items.map(oi => {
|
113
|
+
return oi.package_id
|
114
|
+
})
|
115
|
+
: []
|
109
116
|
|
110
117
|
const reqBody = {
|
111
118
|
orderId: requestBody.native_order_id,
|
@@ -118,6 +125,7 @@ sellercraftRouter.post('/sellercraft/store/update-order-status', async (context,
|
|
118
125
|
}) || []
|
119
126
|
),
|
120
127
|
isSOF: requestBody?.seller_logistics,
|
128
|
+
packageIds: [...new Set(packageIds)] || [],
|
121
129
|
locations:
|
122
130
|
mappedStore.platform == 'shopify'
|
123
131
|
? requestBody?.order_items.map(oi => {
|
@@ -131,7 +139,14 @@ sellercraftRouter.post('/sellercraft/store/update-order-status', async (context,
|
|
131
139
|
let responseBody: any = { operation_id: uuidv4() }
|
132
140
|
try {
|
133
141
|
try {
|
134
|
-
|
142
|
+
if (mappedStore.platform == 'tiktok') {
|
143
|
+
for (let packageId of reqBody.packageIds) {
|
144
|
+
result = (await StoreAPI.updateOrderStatus(mappedStore, { packageId, status: reqBody.status })) || {}
|
145
|
+
}
|
146
|
+
} else {
|
147
|
+
result = (await StoreAPI.updateOrderStatus(mappedStore, reqBody)) || {}
|
148
|
+
}
|
149
|
+
|
135
150
|
debug(result)
|
136
151
|
} catch (e) {
|
137
152
|
if (e?.requiredDocument) result.requiredDocument = e.requiredDocument
|
@@ -147,12 +162,15 @@ sellercraftRouter.post('/sellercraft/store/update-order-status', async (context,
|
|
147
162
|
let orderDocument: any = orderPackage.orderDocument
|
148
163
|
if (orderDocument?.length == 0) {
|
149
164
|
let hasDocument: boolean = false
|
150
|
-
|
165
|
+
let retries = 0
|
166
|
+
while (!hasDocument && retries < 10) {
|
151
167
|
orderDocument = await StoreAPI.getStoreOrderDocument(mappedStore, { packageId, documentType: 1 })
|
152
168
|
if (orderDocument?.length > 0) {
|
153
169
|
hasDocument = true
|
154
170
|
break
|
155
171
|
}
|
172
|
+
await sleep(1000)
|
173
|
+
retries++
|
156
174
|
}
|
157
175
|
}
|
158
176
|
|
@@ -196,6 +214,18 @@ sellercraftRouter.post('/sellercraft/store/update-order-status', async (context,
|
|
196
214
|
|
197
215
|
responseBody.time = Math.floor(new Date(new Date().toUTCString()).getTime() / 1000)
|
198
216
|
|
217
|
+
try {
|
218
|
+
createPayloadLog(
|
219
|
+
mappedStore.channelShopId,
|
220
|
+
'/sellercraft/store/update-order-status',
|
221
|
+
requestBody,
|
222
|
+
responseBody,
|
223
|
+
null,
|
224
|
+
PayloadType.INGESTION,
|
225
|
+
'hub-api'
|
226
|
+
)
|
227
|
+
} catch (e) {}
|
228
|
+
|
199
229
|
context.type = 'application/json'
|
200
230
|
context.status = 200
|
201
231
|
context.body = responseBody
|
@@ -208,6 +238,17 @@ sellercraftRouter.post('/sellercraft/store/update-order-status', async (context,
|
|
208
238
|
context.type = 'application/json'
|
209
239
|
context.status = 500
|
210
240
|
context.body = responseBody
|
241
|
+
try {
|
242
|
+
createPayloadLog(
|
243
|
+
mappedStore?.channelShopId,
|
244
|
+
'/sellercraft/store/update-order-status',
|
245
|
+
requestBody,
|
246
|
+
responseBody,
|
247
|
+
null,
|
248
|
+
PayloadType.INGESTION,
|
249
|
+
'hub-api'
|
250
|
+
)
|
251
|
+
} catch (e) {}
|
211
252
|
}
|
212
253
|
} catch (e) {}
|
213
254
|
})
|