@things-factory/integration-sellercraft 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/constants/order-status-mapping.js +24 -3
- package/dist-server/constants/order-status-mapping.js.map +1 -1
- package/dist-server/constants/platform.js +4 -1
- package/dist-server/constants/platform.js.map +1 -1
- package/dist-server/controllers/sellercraft/sellercraft.js +2 -2
- package/dist-server/controllers/sellercraft/sellercraft.js.map +1 -1
- package/dist-server/controllers/sellercraft-api/decorators.js +2 -0
- package/dist-server/controllers/sellercraft-api/decorators.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.js +18 -21
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.js +5 -2
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js +21 -14
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js +23 -23
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js +17 -6
- package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js.map +1 -1
- package/dist-server/routers/sellercraft-router.js +204 -134
- package/dist-server/routers/sellercraft-router.js.map +1 -1
- package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +327 -103
- 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 +173 -99
- package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -1
- package/dist-server/service/marketplace-channel/marketplace-channel.js +5 -0
- package/dist-server/service/marketplace-channel/marketplace-channel.js.map +1 -1
- package/dist-server/service/sellercraft/sellercraft-mutation.js +3 -6
- package/dist-server/service/sellercraft/sellercraft-mutation.js.map +1 -1
- package/dist-server/service/sellercraft/sellercraft-query.js +1 -1
- package/dist-server/service/sellercraft/sellercraft-query.js.map +1 -1
- package/dist-server/utils/tokencraft-util.js +63 -0
- package/dist-server/utils/tokencraft-util.js.map +1 -0
- package/package.json +15 -15
- package/server/constants/order-status-mapping.ts +24 -2
- package/server/constants/platform.ts +4 -1
- package/server/controllers/sellercraft/sellercraft.ts +2 -2
- package/server/controllers/sellercraft-api/decorators.ts +3 -0
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.ts +19 -22
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.ts +6 -2
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +22 -15
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.ts +32 -26
- package/server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.ts +15 -6
- package/server/routers/sellercraft-router.ts +218 -164
- package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +392 -156
- package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +199 -145
- package/server/service/marketplace-channel/marketplace-channel.ts +4 -0
- package/server/service/sellercraft/sellercraft-mutation.ts +3 -3
- package/server/service/sellercraft/sellercraft-query.ts +1 -1
- package/server/utils/tokencraft-util.ts +60 -0
@@ -2,6 +2,7 @@ import Debug from 'debug'
|
|
2
2
|
const debug = Debug('things-factory:integration-marketplace:store-api-decorator')
|
3
3
|
|
4
4
|
import { Sellercraft } from '../../service'
|
5
|
+
import { createPayloadLog } from '@things-factory/integration-base'
|
5
6
|
|
6
7
|
const NOOP = v => v
|
7
8
|
|
@@ -35,6 +36,8 @@ export const api = (target: Object, property: string, descriptor: TypedPropertyD
|
|
35
36
|
{ store, method: httpMethod, path, request: denormalized, platformAction }
|
36
37
|
])
|
37
38
|
|
39
|
+
createPayloadLog(store.accountId, path, denormalized, response, request?.context)
|
40
|
+
|
38
41
|
debug('response', response)
|
39
42
|
|
40
43
|
return await normalize(response, { store })
|
package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.ts
CHANGED
@@ -7,30 +7,10 @@ export function ingestChannelCategories() {
|
|
7
7
|
denormalize(req) {
|
8
8
|
const { categories } = req
|
9
9
|
|
10
|
-
let newCategories = categories
|
11
|
-
return {
|
12
|
-
native_category_id: category.categoryId.toString(),
|
13
|
-
channel_code: category.channelCode,
|
14
|
-
channel_country: category.countryCode,
|
15
|
-
category_name: category.categoryName,
|
16
|
-
is_leaf: category.isLeaf,
|
17
|
-
is_active: category.isActive,
|
18
|
-
children_categories: category.childrenCategories.map(childrenCategory => {
|
19
|
-
return {
|
20
|
-
native_category_id: category.categoryId.toString(),
|
21
|
-
channel_code: category.channelCode,
|
22
|
-
channel_country: category.countryCode,
|
23
|
-
category_name: childrenCategory.categoryName,
|
24
|
-
is_leaf: childrenCategory.isLeaf,
|
25
|
-
is_active: childrenCategory.isActive,
|
26
|
-
children_categories: {}
|
27
|
-
}
|
28
|
-
})
|
29
|
-
}
|
30
|
-
})
|
10
|
+
let newCategories = mapCategories(categories)
|
31
11
|
|
32
12
|
return {
|
33
|
-
payload: [
|
13
|
+
payload: [...newCategories]
|
34
14
|
}
|
35
15
|
},
|
36
16
|
normalize(res) {
|
@@ -38,3 +18,20 @@ export function ingestChannelCategories() {
|
|
38
18
|
}
|
39
19
|
}
|
40
20
|
}
|
21
|
+
|
22
|
+
function mapCategories(categories) {
|
23
|
+
if (!categories) return null
|
24
|
+
categories = categories.map(category => {
|
25
|
+
let children_categories = mapCategories(category.childrenCategories)
|
26
|
+
return {
|
27
|
+
native_category_id: category.categoryId.toString(),
|
28
|
+
channel_code: category.channelCode,
|
29
|
+
channel_country: category.countryCode,
|
30
|
+
category_name: category.categoryName,
|
31
|
+
is_leaf: children_categories.length == 0 ? true : false,
|
32
|
+
is_active: category.isActive,
|
33
|
+
children_categories
|
34
|
+
}
|
35
|
+
})
|
36
|
+
return categories
|
37
|
+
}
|
package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.ts
CHANGED
@@ -38,10 +38,10 @@ export function ingestChannelOrderPackage() {
|
|
38
38
|
name: shipper_last_mile.name
|
39
39
|
}
|
40
40
|
|
41
|
-
|
41
|
+
let newOrderPackage: any = {
|
42
42
|
channel_shop_id,
|
43
43
|
native_order_id,
|
44
|
-
native_package_id,
|
44
|
+
native_package_id: native_package_id.toString(),
|
45
45
|
shipping_tracking_code,
|
46
46
|
shipping_type_value,
|
47
47
|
warehouse_code,
|
@@ -50,6 +50,10 @@ export function ingestChannelOrderPackage() {
|
|
50
50
|
shipper_last_mile,
|
51
51
|
order_item_ids
|
52
52
|
}
|
53
|
+
|
54
|
+
return {
|
55
|
+
payload: { ...newOrderPackage }
|
56
|
+
}
|
53
57
|
},
|
54
58
|
normalize(res) {
|
55
59
|
return res
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/* https://docs.sellercraft.co/docs/api-integrations/
|
1
|
+
/* https://docs.sellercraft.co/docs/api-integrations/b3A6MjQzODQ4OTg-ingest-channel-order */
|
2
2
|
|
3
3
|
import { ORDER_STATUS } from '../../../constants'
|
4
4
|
|
@@ -13,14 +13,20 @@ export function ingestChannelOrder() {
|
|
13
13
|
return {
|
14
14
|
organisation_id: order.organisationId,
|
15
15
|
channel_shop_id: order.channelShopId,
|
16
|
-
native_order_id: order.id,
|
17
|
-
ordered_at_date: new Date(order.createdAt).toISOString(),
|
18
|
-
ordered_at_time: new Date(order.createdAt).toISOString(),
|
19
|
-
updated_at_date: new Date(order.updatedAt).toISOString(),
|
20
|
-
updated_at_time: new Date(order.updatedAt).toISOString(),
|
16
|
+
native_order_id: order.id.toString(),
|
17
|
+
ordered_at_date: new Date(order.createdAt).toISOString().slice(0, -5) + 'Z',
|
18
|
+
ordered_at_time: new Date(order.createdAt).toISOString().slice(0, -5) + 'Z',
|
19
|
+
updated_at_date: new Date(order.updatedAt).toISOString().slice(0, -5) + 'Z',
|
20
|
+
updated_at_time: new Date(order.updatedAt).toISOString().slice(0, -5) + 'Z',
|
21
21
|
customer_first_name: order.custFirstName,
|
22
22
|
customer_last_name: order.custLastName,
|
23
|
-
charges:
|
23
|
+
charges: order.charges.map(charge => {
|
24
|
+
return {
|
25
|
+
charge_type_value: charge.name,
|
26
|
+
amount_gross: parseFloat(charge.grossAmount) || 0,
|
27
|
+
amount_nett: parseFloat(charge.nettAmount) || 0
|
28
|
+
}
|
29
|
+
}),
|
24
30
|
address_shipping: {
|
25
31
|
first_name: order.shipFirstName,
|
26
32
|
last_name: order.shipLastName,
|
@@ -49,16 +55,16 @@ export function ingestChannelOrder() {
|
|
49
55
|
phone_1: order.billPhone1,
|
50
56
|
phone_2: order.billPhone2
|
51
57
|
},
|
52
|
-
order_items: order.
|
58
|
+
order_items: order.mappedOrderItems.map(orderItem => {
|
53
59
|
return {
|
54
60
|
native_item_id: orderItem.id.toString(),
|
55
61
|
native_variant_id: orderItem.variationId.toString(),
|
56
62
|
currency_code: orderItem.currency,
|
57
|
-
ordered_at_date: new Date(order.createdAt).toISOString(),
|
58
|
-
ordered_at_time: new Date(order.createdAt).toISOString(),
|
59
|
-
updated_at_date: new Date(order.updatedAt).toISOString(),
|
60
|
-
updated_at_time: new Date(order.updatedAt).toISOString(),
|
61
|
-
sla_expires_at:
|
63
|
+
ordered_at_date: new Date(order.createdAt).toISOString().slice(0, -5) + 'Z',
|
64
|
+
ordered_at_time: new Date(order.createdAt).toISOString().slice(0, -5) + 'Z',
|
65
|
+
updated_at_date: new Date(order.updatedAt).toISOString().slice(0, -5) + 'Z',
|
66
|
+
updated_at_time: new Date(order.updatedAt).toISOString().slice(0, -5) + 'Z',
|
67
|
+
sla_expires_at: orderItem?.slaExpiresAt ? new Date(orderItem.slaExpiresAt).toISOString() : null,
|
62
68
|
charges: orderItem.charges.map(charge => {
|
63
69
|
return {
|
64
70
|
charge_type_value: charge.name,
|
@@ -68,12 +74,13 @@ export function ingestChannelOrder() {
|
|
68
74
|
}),
|
69
75
|
order_status_value: ORDER_STATUS[`${order.status}`]
|
70
76
|
}
|
71
|
-
})
|
77
|
+
}),
|
78
|
+
seller_logistics: order?.isSOF
|
72
79
|
}
|
73
80
|
})
|
74
81
|
|
75
82
|
return {
|
76
|
-
payload: [
|
83
|
+
payload: [...newOrders]
|
77
84
|
}
|
78
85
|
},
|
79
86
|
normalize(res) {
|
@@ -13,15 +13,17 @@ export function ingestChannelProduct() {
|
|
13
13
|
seller_sku: variant.variationSku,
|
14
14
|
native_variant_id: variant.variationId.toString(),
|
15
15
|
label: variant.name,
|
16
|
-
is_enabled: variant.isEnabled,
|
17
|
-
is_sellable: variant.isSellable,
|
16
|
+
is_enabled: variant.isEnabled || true,
|
17
|
+
is_sellable: variant.isSellable || true,
|
18
18
|
is_deleted: false, // default
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
variant_attributes: variant?.attributes
|
20
|
+
? variant?.attributes.map(attribute => {
|
21
|
+
return {
|
22
|
+
...attribute,
|
23
|
+
native_attribute_id: attribute?.native_attribute_id?.toString()
|
24
|
+
}
|
25
|
+
})
|
26
|
+
: [],
|
25
27
|
stock_locked: variant?.stockLocked ? variant.stockLocked : 0,
|
26
28
|
native_stock_reported: variant?.stockReported ? variant.stockReported : 0,
|
27
29
|
price_full: variant.fullPrice || 0,
|
@@ -29,7 +31,7 @@ export function ingestChannelProduct() {
|
|
29
31
|
inventory_products: variant?.inventoryProducts
|
30
32
|
? variant.inventoryProducts.map(inventoryProduct => {
|
31
33
|
return {
|
32
|
-
quantity: inventoryProduct.qty,
|
34
|
+
quantity: inventoryProduct.qty || 0,
|
33
35
|
name: inventoryProduct.name,
|
34
36
|
inventory_sku: inventoryProduct.sku,
|
35
37
|
product_versions: inventoryProduct?.productVersions
|
@@ -43,13 +45,14 @@ export function ingestChannelProduct() {
|
|
43
45
|
package_weight_gram: productVersion?.packageWeightGram
|
44
46
|
? productVersion.packageWeightGram
|
45
47
|
: 0,
|
46
|
-
stock_available: productVersion.qty
|
48
|
+
stock_available: productVersion.qty
|
47
49
|
}
|
48
50
|
})
|
49
51
|
: []
|
50
52
|
}
|
51
53
|
})
|
52
|
-
: []
|
54
|
+
: [],
|
55
|
+
extra_metadata: variant?.extraMetadata
|
53
56
|
}
|
54
57
|
})
|
55
58
|
|
@@ -61,21 +64,24 @@ export function ingestChannelProduct() {
|
|
61
64
|
native_category_id: product.categoryId.toString(),
|
62
65
|
native_product_id: product.productId.toString(),
|
63
66
|
label: product.name,
|
64
|
-
brand: product.brand,
|
65
|
-
is_verified: product.isVerified,
|
66
|
-
flexible_attributes: product.channelCode == 'WCM' ? true : false, // add channels that do not support category_attributes ingestion
|
67
|
-
images:
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
67
|
+
brand: product.brand || '',
|
68
|
+
is_verified: product.isVerified || true,
|
69
|
+
flexible_attributes: product.channelCode == 'WCM' || product.channelCode == 'MGT' || product.channelCode == 'SPF' ? true : false, // add channels that do not support category_attributes ingestion
|
70
|
+
images:
|
71
|
+
product?.images?.map(image => {
|
72
|
+
return {
|
73
|
+
file_url: image.url
|
74
|
+
}
|
75
|
+
}) || [],
|
76
|
+
product_attributes:
|
77
|
+
product?.attributes?.map(attribute => {
|
78
|
+
return {
|
79
|
+
...attribute,
|
80
|
+
native_attribute_id: attribute.native_attribute_id.toString()
|
81
|
+
}
|
82
|
+
}) || [],
|
83
|
+
variants: productVariations,
|
84
|
+
has_all_variants: product.channelCode == 'MGT' ? false : true
|
79
85
|
}
|
80
86
|
})
|
81
87
|
|
package/server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import fetch from 'node-fetch'
|
2
|
-
import
|
2
|
+
import { v4 as uuidv4 } from 'uuid'
|
3
|
+
import { createPayloadLog } from '@things-factory/integration-base'
|
3
4
|
|
4
5
|
const debug = require('debug')('things-factory:integration-sellercraft:sellercraft')
|
5
6
|
|
@@ -21,7 +22,7 @@ export class SellercraftChannelIntegration {
|
|
21
22
|
}
|
22
23
|
|
23
24
|
generateRequestId() {
|
24
|
-
return
|
25
|
+
return uuidv4()
|
25
26
|
}
|
26
27
|
|
27
28
|
async post(path: string, data: any = {}) {
|
@@ -43,10 +44,16 @@ export class SellercraftChannelIntegration {
|
|
43
44
|
body: jsondata
|
44
45
|
})
|
45
46
|
|
47
|
+
const result = await response.json()
|
48
|
+
try {
|
49
|
+
createPayloadLog(JSON.parse(jsondata)[0]?.channel_shop_id || requestId, fullPath, jsondata, result, {
|
50
|
+
state: { domain: null }
|
51
|
+
})
|
52
|
+
} catch (e) {}
|
46
53
|
if (response.ok) {
|
47
|
-
return
|
54
|
+
return result
|
48
55
|
} else {
|
49
|
-
throw new Error(`
|
56
|
+
throw new Error(`(${response.status}) ${result.detail}`)
|
50
57
|
}
|
51
58
|
}
|
52
59
|
|
@@ -71,7 +78,8 @@ export class SellercraftChannelIntegration {
|
|
71
78
|
if (response.ok) {
|
72
79
|
return await response.json()
|
73
80
|
} else {
|
74
|
-
|
81
|
+
const result = await response.json()
|
82
|
+
throw new Error(`(${response.status}) ${result.message}`)
|
75
83
|
}
|
76
84
|
}
|
77
85
|
|
@@ -100,7 +108,8 @@ export class SellercraftChannelIntegration {
|
|
100
108
|
if (response.ok) {
|
101
109
|
return await response.json()
|
102
110
|
} else {
|
103
|
-
|
111
|
+
const result = await response.json()
|
112
|
+
throw new Error(`(${response.status}) ${result.message}`)
|
104
113
|
}
|
105
114
|
}
|
106
115
|
}
|