@things-factory/integration-sellercraft 5.0.0-alpha.50 → 5.0.0-alpha.54
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 +3 -0
- package/dist-server/constants/order-status-mapping.js.map +1 -1
- package/dist-server/constants/platform.js +2 -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-product.js +5 -3
- 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 +11 -4
- package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js.map +1 -1
- package/dist-server/routers/sellercraft-router.js +85 -135
- package/dist-server/routers/sellercraft-router.js.map +1 -1
- package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +59 -57
- 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 +162 -157
- package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.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 +3 -0
- package/server/constants/platform.ts +2 -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-product.ts +4 -3
- package/server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.ts +9 -4
- package/server/routers/sellercraft-router.ts +91 -145
- package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +62 -56
- package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +186 -183
- 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
@@ -11,20 +11,17 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
13
13
|
};
|
14
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
15
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
16
|
-
};
|
17
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
18
15
|
exports.SellercraftMutation = void 0;
|
19
16
|
const type_graphql_1 = require("type-graphql");
|
20
17
|
const typeorm_1 = require("typeorm");
|
21
|
-
const
|
18
|
+
const uuid_1 = require("uuid");
|
22
19
|
const sellercraft_1 = require("./sellercraft");
|
23
20
|
const sellercraft_type_1 = require("./sellercraft-type");
|
24
21
|
let SellercraftMutation = class SellercraftMutation {
|
25
22
|
async createSellercraft(sellercraft, context) {
|
26
23
|
const { domain, user, tx } = context.state;
|
27
|
-
return await tx.getRepository(sellercraft_1.Sellercraft).save(Object.assign(Object.assign({}, sellercraft), { name: (0,
|
24
|
+
return await tx.getRepository(sellercraft_1.Sellercraft).save(Object.assign(Object.assign({}, sellercraft), { name: (0, uuid_1.v4)(), domain, creator: user, updater: user }));
|
28
25
|
}
|
29
26
|
async updateSellercraft(id, patch, context) {
|
30
27
|
const { user, tx } = context.state;
|
@@ -41,7 +38,7 @@ let SellercraftMutation = class SellercraftMutation {
|
|
41
38
|
if (_createRecords.length > 0) {
|
42
39
|
for (let i = 0; i < _createRecords.length; i++) {
|
43
40
|
const newRecord = _createRecords[i];
|
44
|
-
const result = await sellercraftRepo.save(Object.assign(Object.assign({}, newRecord), { domain, name: (0,
|
41
|
+
const result = await sellercraftRepo.save(Object.assign(Object.assign({}, newRecord), { domain, name: (0, uuid_1.v4)(), status: sellercraft_1.SellercraftStatus.ACTIVE, platform: sellercraft_1.SellercraftPlatform.SELLERCRAFT, creator: user, updater: user }));
|
45
42
|
results.push(Object.assign(Object.assign({}, result), { cuFlag: '+' }));
|
46
43
|
}
|
47
44
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sellercraft-mutation.js","sourceRoot":"","sources":["../../../server/service/sellercraft/sellercraft-mutation.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"sellercraft-mutation.js","sourceRoot":"","sources":["../../../server/service/sellercraft/sellercraft-mutation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAAsE;AACtE,qCAA4B;AAC5B,+BAAmC;AAEnC,+CAAmF;AACnF,yDAAqE;AAGrE,IAAa,mBAAmB,GAAhC,MAAa,mBAAmB;IAG9B,KAAK,CAAC,iBAAiB,CAAqB,WAA2B,EAAS,OAAY;QAC1F,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,OAAO,MAAM,EAAE,CAAC,aAAa,CAAC,yBAAW,CAAC,CAAC,IAAI,iCAC1C,WAAW,KACd,IAAI,EAAE,IAAA,SAAM,GAAE,EACd,MAAM,EACN,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,IAAI,IACb,CAAA;IACJ,CAAC;IAID,KAAK,CAAC,iBAAiB,CACV,EAAU,EACP,KAAuB,EAC9B,OAAY;QAEnB,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAElC,MAAM,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,yBAAW,CAAC,CA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C,IAAI,CAAC,CAAA;IAAc,WAAA,IAAA,kBAAG,GAAE,CAAA;;;;4DAKpD;AAID;IAFC,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,iCAAiC,EAAE,CAAC;IACvD,WAAA,IAAA,kBAAG,EAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAAiB,WAAA,IAAA,kBAAG,GAAE,CAAA;;;;6DAc3E;AA5GU,mBAAmB;IAD/B,IAAA,uBAAQ,EAAC,yBAAW,CAAC;GACT,mBAAmB,CA6G/B;AA7GY,kDAAmB"}
|
@@ -26,7 +26,7 @@ let SellercraftQuery = class SellercraftQuery {
|
|
26
26
|
}
|
27
27
|
async sellercrafts(params, context) {
|
28
28
|
const { domain } = context.state;
|
29
|
-
const convertedParams = (0, shell_1.convertListParams)(params, domain
|
29
|
+
const convertedParams = (0, shell_1.convertListParams)(params, { domain });
|
30
30
|
const [items, total] = await (0, typeorm_1.getRepository)(sellercraft_1.Sellercraft).findAndCount(convertedParams);
|
31
31
|
return { items, total };
|
32
32
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sellercraft-query.js","sourceRoot":"","sources":["../../../server/service/sellercraft/sellercraft-query.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAAmF;AACnF,qCAAuC;AAEvC,yDAAgD;AAChD,iDAA4E;AAE5E,+CAA2C;AAC3C,yDAAoD;AAGpD,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IAE3B,KAAK,CAAC,WAAW,CAAY,EAAU,EAAS,OAAY;QAC1D,OAAO,MAAM,IAAA,uBAAa,EAAC,yBAAW,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IACrD,CAAC;IAGD,KAAK,CAAC,YAAY,CAAS,MAAiB,EAAS,OAAY;QAC/D,MAAM,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OAAO,MAAM,IAAA,uBAAa,EAAC,gBAAI,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAA;IACjE,CAAC;CACF,CAAA;AA5BC;IADC,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,yBAAW,EAAE,EAAE,WAAW,EAAE,wBAAwB,EAAE,CAAC;IACtD,WAAA,IAAA,kBAAG,EAAC,IAAI,CAAC,CAAA;IAAc,WAAA,IAAA,kBAAG,GAAE,CAAA;;;;mDAE9C;AAGD;IADC,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,kCAAe,EAAE,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC;IACjE,WAAA,IAAA,mBAAI,GAAE,CAAA;IAAqB,WAAA,IAAA,kBAAG,GAAE,CAAA;;yDAAjB,iBAAS,oBAAT,iBAAS;;oDAO3C;AAGD;IADC,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,CAAC;IAChB,WAAA,IAAA,mBAAI,GAAE,CAAA;;qCAAc,yBAAW;;8CAE5C;AAGD;IADC,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,CAAC;IACb,WAAA,IAAA,mBAAI,GAAE,CAAA;;qCAAc,yBAAW;;+CAE7C;AAGD;IADC,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,CAAC;IACb,WAAA,IAAA,mBAAI,GAAE,CAAA;;qCAAc,yBAAW;;+CAE7C;AA7BU,gBAAgB;IAD5B,IAAA,uBAAQ,EAAC,yBAAW,CAAC;GACT,gBAAgB,CA8B5B;AA9BY,4CAAgB"}
|
@@ -0,0 +1,63 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getShops = exports.getShop = void 0;
|
4
|
+
const env_1 = require("@things-factory/env");
|
5
|
+
const constants_1 = require("../constants");
|
6
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
7
|
+
async function getShop(context, channelId, shopId) {
|
8
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
9
|
+
const sellercraftChannelIntegrationConfig = env_1.config.get('sellercraftChannelIntegrationConfig', {});
|
10
|
+
const { tokenCraftApiKey: apiKey, tokenCraftUrl } = sellercraftChannelIntegrationConfig;
|
11
|
+
const xApiKey = context.headers['x-api-key'];
|
12
|
+
if (apiKey !== xApiKey)
|
13
|
+
context.throw(400, 'api key validation failed');
|
14
|
+
var fullPath = `${tokenCraftUrl}?channel_id=${channelId}&shop_id=${shopId}`;
|
15
|
+
const response = await fetch(fullPath, {
|
16
|
+
method: 'get',
|
17
|
+
headers: {
|
18
|
+
'Content-Type': 'application/json',
|
19
|
+
'x-api-key': apiKey
|
20
|
+
}
|
21
|
+
});
|
22
|
+
if (response.ok) {
|
23
|
+
let store = await response.json();
|
24
|
+
let mappedStore = {
|
25
|
+
accessKey: ((_b = (_a = store.shop) === null || _a === void 0 ? void 0 : _a.credential) === null || _b === void 0 ? void 0 : _b.consumer_key) || '',
|
26
|
+
accessSecret: ((_d = (_c = store.shop) === null || _c === void 0 ? void 0 : _c.credential) === null || _d === void 0 ? void 0 : _d.consumer_secret) || '',
|
27
|
+
storeURL: (_f = (_e = store.shop) === null || _e === void 0 ? void 0 : _e.credential) === null || _f === void 0 ? void 0 : _f.store_url,
|
28
|
+
platform: constants_1.PLATFORM[`${store.shop.org_prefix}`],
|
29
|
+
accessToken: (_h = (_g = store.shop) === null || _g === void 0 ? void 0 : _g.credential) === null || _h === void 0 ? void 0 : _h.access_token,
|
30
|
+
channelShopId: (_j = store.shop) === null || _j === void 0 ? void 0 : _j.channel_shop_id,
|
31
|
+
storeId: (_l = (_k = store.shop) === null || _k === void 0 ? void 0 : _k.credential) === null || _l === void 0 ? void 0 : _l.store_url
|
32
|
+
};
|
33
|
+
return mappedStore;
|
34
|
+
}
|
35
|
+
else {
|
36
|
+
(0, integration_base_1.createPayloadLog)(shopId, tokenCraftUrl, `channel_id=${channelId}&shop_id=${shopId}`, (response === null || response === void 0 ? void 0 : response.statusText) || 500, {
|
37
|
+
state: { domain: null }
|
38
|
+
});
|
39
|
+
}
|
40
|
+
}
|
41
|
+
exports.getShop = getShop;
|
42
|
+
async function getShops(channelId) {
|
43
|
+
const sellercraftChannelIntegrationConfig = env_1.config.get('sellercraftChannelIntegrationConfig', {});
|
44
|
+
const { tokenCraftApiKey: apiKey, getShopsTokenCraftUrl } = sellercraftChannelIntegrationConfig;
|
45
|
+
var channelsFullPath = getShopsTokenCraftUrl + '?channel_id=' + channelId;
|
46
|
+
const channelResponse = await fetch(channelsFullPath, {
|
47
|
+
method: 'get',
|
48
|
+
headers: {
|
49
|
+
'Content-Type': 'application/json',
|
50
|
+
'x-api-key': apiKey
|
51
|
+
}
|
52
|
+
});
|
53
|
+
if (!channelResponse.ok) {
|
54
|
+
(0, integration_base_1.createPayloadLog)(channelId, getShopsTokenCraftUrl, `channel_id=${channelId}`, (channelResponse === null || channelResponse === void 0 ? void 0 : channelResponse.statusText) || 500, {
|
55
|
+
state: { domain: null }
|
56
|
+
});
|
57
|
+
throw new Error(channelResponse);
|
58
|
+
}
|
59
|
+
var shopsResponse = await channelResponse.json();
|
60
|
+
return shopsResponse.shops;
|
61
|
+
}
|
62
|
+
exports.getShops = getShops;
|
63
|
+
//# sourceMappingURL=tokencraft-util.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"tokencraft-util.js","sourceRoot":"","sources":["../../server/utils/tokencraft-util.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAC5C,4CAAuC;AACvC,uEAAmE;AAE5D,KAAK,UAAU,OAAO,CAAC,OAAY,EAAE,SAAiB,EAAE,MAAc;;IAC3E,MAAM,mCAAmC,GAAG,YAAM,CAAC,GAAG,CAAC,qCAAqC,EAAE,EAAE,CAAC,CAAA;IACjG,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,mCAAmC,CA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aAAR,QAAQ,uBAAR,QAAQ,CAAE,UAAU,KAAI,GAAG,EAAE;YAChH,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;SACxB,CAAC,CAAA;KACH;AACH,CAAC;AAhCD,0BAgCC;AAEM,KAAK,UAAU,QAAQ,CAAC,SAAiB;IAC9C,MAAM,mCAAmC,GAAG,YAAM,CAAC,GAAG,CAAC,qCAAqC,EAAE,EAAE,CAAC,CAAA;IACjG,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,qBAAqB,EAAE,GAAG,mCAAmC,CAAA;IAE/F,IAAI,gBAAgB,GAAG,qBAAqB,GAAG,cAAc,GAAG,SAAS,CAAA;IACzE,MAAM,eAAe,GAAQ,MAAM,KAAK,CAAC,gBAAgB,EAAE;QACzD,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,WAAW,EAAE,MAAM;SACpB;KACF,CAAC,CAAA;IAEF,IAAI,CAAC,eAAe,CAAC,EAAE,EAAE;QACrB,IAAA,mCAAgB,EAAC,SAAS,EAAE,qBAAqB,EAAE,cAAc,SAAS,EAAE,EAAE,CAAA,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,UAAU,KAAI,GAAG,EAAE;YAChH,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;SACxB,CAAC,CAAA;QACJ,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;KACnC;IACC,IAAI,aAAa,GAAG,MAAM,eAAe,CAAC,IAAI,EAAE,CAAA;IAChD,OAAO,aAAa,CAAC,KAAK,CAAA;AAC5B,CAAC;AArBD,4BAqBC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@things-factory/integration-sellercraft",
|
3
|
-
"version": "5.0.0-alpha.
|
3
|
+
"version": "5.0.0-alpha.54",
|
4
4
|
"main": "dist-server/index.js",
|
5
5
|
"browser": "client/index.js",
|
6
6
|
"things-factory": true,
|
@@ -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": "^5.0.0-alpha.
|
28
|
-
"@things-factory/auth-ui": "^5.0.0-alpha.
|
29
|
-
"@things-factory/biz-base": "^5.0.0-alpha.
|
30
|
-
"@things-factory/code-ui": "^5.0.0-alpha.
|
31
|
-
"@things-factory/context-ui": "^5.0.0-alpha.
|
32
|
-
"@things-factory/grist-ui": "^5.0.0-alpha.
|
33
|
-
"@things-factory/i18n-base": "^5.0.0-alpha.
|
34
|
-
"@things-factory/integration-marketplace": "^5.0.0-alpha.
|
35
|
-
"@things-factory/integration-ui": "^5.0.0-alpha.
|
36
|
-
"@things-factory/more-ui": "^5.0.0-alpha.
|
37
|
-
"@things-factory/resource-ui": "^5.0.0-alpha.
|
38
|
-
"@things-factory/setting-ui": "^5.0.0-alpha.
|
39
|
-
"@things-factory/system-ui": "^5.0.0-alpha.
|
27
|
+
"@things-factory/apptool-ui": "^5.0.0-alpha.54",
|
28
|
+
"@things-factory/auth-ui": "^5.0.0-alpha.54",
|
29
|
+
"@things-factory/biz-base": "^5.0.0-alpha.54",
|
30
|
+
"@things-factory/code-ui": "^5.0.0-alpha.54",
|
31
|
+
"@things-factory/context-ui": "^5.0.0-alpha.54",
|
32
|
+
"@things-factory/grist-ui": "^5.0.0-alpha.54",
|
33
|
+
"@things-factory/i18n-base": "^5.0.0-alpha.54",
|
34
|
+
"@things-factory/integration-marketplace": "^5.0.0-alpha.54",
|
35
|
+
"@things-factory/integration-ui": "^5.0.0-alpha.54",
|
36
|
+
"@things-factory/more-ui": "^5.0.0-alpha.54",
|
37
|
+
"@things-factory/resource-ui": "^5.0.0-alpha.54",
|
38
|
+
"@things-factory/setting-ui": "^5.0.0-alpha.54",
|
39
|
+
"@things-factory/system-ui": "^5.0.0-alpha.54",
|
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": "0274aad474b254a6215fdf54d4f553c5b45becd8"
|
55
55
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import fetch from 'node-fetch'
|
2
|
-
import
|
2
|
+
import { v4 as uuidv4 } from 'uuid'
|
3
3
|
|
4
4
|
const debug = require('debug')('things-factory:integration-sellercraft:sellercraft')
|
5
5
|
|
@@ -21,7 +21,7 @@ export class Sellercraft {
|
|
21
21
|
}
|
22
22
|
|
23
23
|
generateRequestId() {
|
24
|
-
return
|
24
|
+
return uuidv4()
|
25
25
|
}
|
26
26
|
|
27
27
|
async post(path: string, data: any = {}) {
|
@@ -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 })
|
@@ -20,7 +20,7 @@ export function ingestChannelProduct() {
|
|
20
20
|
? variant?.attributes.map(attribute => {
|
21
21
|
return {
|
22
22
|
...attribute,
|
23
|
-
native_attribute_id: attribute
|
23
|
+
native_attribute_id: attribute?.native_attribute_id?.toString()
|
24
24
|
}
|
25
25
|
})
|
26
26
|
: [],
|
@@ -51,7 +51,8 @@ export function ingestChannelProduct() {
|
|
51
51
|
: []
|
52
52
|
}
|
53
53
|
})
|
54
|
-
: []
|
54
|
+
: [],
|
55
|
+
extra_metadata: variant?.extraMetadata
|
55
56
|
}
|
56
57
|
})
|
57
58
|
|
@@ -65,7 +66,7 @@ export function ingestChannelProduct() {
|
|
65
66
|
label: product.name,
|
66
67
|
brand: product.brand || '',
|
67
68
|
is_verified: product.isVerified || true,
|
68
|
-
flexible_attributes: product.channelCode == 'WCM' || product.channelCode == 'MGT' ? true : false, // add channels that do not support category_attributes ingestion
|
69
|
+
flexible_attributes: product.channelCode == 'WCM' || product.channelCode == 'MGT' || product.channelCode == 'SPF' ? true : false, // add channels that do not support category_attributes ingestion
|
69
70
|
images:
|
70
71
|
product?.images?.map(image => {
|
71
72
|
return {
|
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,11 +44,15 @@ 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
|
-
const result = await response.json()
|
48
54
|
return result
|
49
55
|
} else {
|
50
|
-
const result = await response.json()
|
51
56
|
throw new Error(`(${response.status}) ${result.detail}`)
|
52
57
|
}
|
53
58
|
}
|
@@ -1,67 +1,41 @@
|
|
1
1
|
import Router from 'koa-router'
|
2
|
-
import
|
2
|
+
import { v4 as uuidv4 } from 'uuid'
|
3
3
|
|
4
4
|
import { config } from '@things-factory/env'
|
5
5
|
import { StoreAPI } from '@things-factory/integration-marketplace'
|
6
|
+
import { getShop } from '../utils/tokencraft-util'
|
6
7
|
|
7
|
-
import {
|
8
|
+
import { SHIPPING_TYPE } from '../constants'
|
8
9
|
|
9
10
|
const debug = require('debug')('things-factory:integration-sellercraft:sellercraft-router')
|
10
11
|
|
11
12
|
export const sellercraftRouter = new Router()
|
12
13
|
|
13
14
|
sellercraftRouter.post('/sellercraft/store/update-product-price', async (context, next) => {
|
14
|
-
const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
|
15
|
-
const { tokenCraftApiKey: apiKey, tokenCraftUrl } = sellercraftChannelIntegrationConfig
|
16
|
-
|
17
|
-
const xApiKey = context.headers['x-api-key']
|
18
|
-
|
19
|
-
if (apiKey !== xApiKey) context.throw(400, 'api key validation failed')
|
20
|
-
|
21
15
|
const requestBody = context.request.body
|
22
16
|
|
23
17
|
for (var i = 0; i < requestBody.length; i++) {
|
24
|
-
|
18
|
+
let mappedStore: any = await getShop(context, requestBody[i].channel_id, requestBody[i].shop_id)
|
25
19
|
var result
|
26
20
|
|
27
|
-
// https://staging-tokencraft.sellercraft.co/v1/get-shop?channel_id=4bfb3362-d57c-47f8-8781-007316d179bf&shop_id=dd9cf3b7-114f-4d74-a7e2-7b524ae086f2
|
28
|
-
var fullPath = `${tokenCraftUrl}?channel_id=${requestBody[i].channel_id}&shop_id=${requestBody[i].shop_id}`
|
29
|
-
const response: any = await fetch(fullPath, {
|
30
|
-
method: 'get',
|
31
|
-
headers: {
|
32
|
-
'Content-Type': 'application/json',
|
33
|
-
'x-api-key': apiKey
|
34
|
-
}
|
35
|
-
})
|
36
|
-
if (response.ok) {
|
37
|
-
store = await response.json()
|
38
|
-
}
|
39
|
-
|
40
|
-
let mappedStore: any = {
|
41
|
-
accessKey: store.shop?.credential?.consumer_key || '',
|
42
|
-
accessSecret: store.shop?.credential?.consumer_secret || '',
|
43
|
-
storeURL: store.shop?.credential?.store_url,
|
44
|
-
platform: PLATFORM[`${store.shop.org_prefix}`],
|
45
|
-
accessToken: store.shop?.credential?.access_token,
|
46
|
-
channelShopId: store.shop?.channel_shop_id
|
47
|
-
}
|
48
|
-
|
49
21
|
try {
|
50
|
-
if (requestBody[i].native_variant_id != requestBody[i].native_product_id) {
|
22
|
+
if (requestBody[i].variant.native_variant_id != requestBody[i].native_product_id) {
|
51
23
|
const req = {
|
52
|
-
costPrice: requestBody[i].full_price,
|
53
|
-
sellPrice: requestBody[i].sale_price,
|
24
|
+
costPrice: requestBody[i].variant.full_price,
|
25
|
+
sellPrice: requestBody[i].variant.sale_price,
|
54
26
|
productId: requestBody[i].native_product_id,
|
55
|
-
variationId: requestBody[i].native_variant_id,
|
56
|
-
variationSku: requestBody[i].sku
|
27
|
+
variationId: requestBody[i].variant.native_variant_id,
|
28
|
+
variationSku: requestBody[i].variant.sku,
|
29
|
+
context: { state: { domain: null } }
|
57
30
|
}
|
58
31
|
result = await StoreAPI.updateStoreProductVariationPrice(mappedStore, req)
|
59
32
|
} else {
|
60
33
|
const req = {
|
61
|
-
costPrice: requestBody[i].full_price,
|
62
|
-
sellPrice: requestBody[i].sale_price,
|
34
|
+
costPrice: requestBody[i].variant.full_price,
|
35
|
+
sellPrice: requestBody[i].variant.sale_price,
|
63
36
|
productId: requestBody[i].native_product_id,
|
64
|
-
variationSku: requestBody[i].sku
|
37
|
+
variationSku: requestBody[i].variant.sku,
|
38
|
+
context: { state: { domain: null } }
|
65
39
|
}
|
66
40
|
result = await StoreAPI.updateStoreProductPrice(mappedStore, req)
|
67
41
|
}
|
@@ -80,56 +54,36 @@ sellercraftRouter.post('/sellercraft/store/update-product-price', async (context
|
|
80
54
|
})
|
81
55
|
|
82
56
|
sellercraftRouter.post('/sellercraft/store/update-product-stock', async (context, next) => {
|
83
|
-
const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
|
84
|
-
const { tokenCraftApiKey: apiKey, tokenCraftUrl } = sellercraftChannelIntegrationConfig
|
85
|
-
|
86
|
-
const xApiKey = context.headers['x-api-key']
|
87
|
-
|
88
|
-
if (apiKey !== xApiKey) context.throw(400, 'api key validation failed')
|
89
|
-
|
90
57
|
const requestBody = context.request.body
|
91
58
|
for (var i = 0; i < requestBody.length; i++) {
|
92
|
-
|
59
|
+
let mappedStore: any = await getShop(context, requestBody[i].channel_id, requestBody[i].shop_id)
|
93
60
|
var result
|
94
61
|
|
95
|
-
// https://staging-tokencraft.sellercraft.co/v1/get-shop?channel_id=4bfb3362-d57c-47f8-8781-007316d179bf&shop_id=dd9cf3b7-114f-4d74-a7e2-7b524ae086f2
|
96
|
-
var fullPath = `${tokenCraftUrl}?channel_id=${requestBody[i].channel_id}&shop_id=${requestBody[i].shop_id}`
|
97
|
-
const response: any = await fetch(fullPath, {
|
98
|
-
method: 'get',
|
99
|
-
headers: {
|
100
|
-
'Content-Type': 'application/json',
|
101
|
-
'x-api-key': apiKey
|
102
|
-
}
|
103
|
-
})
|
104
|
-
if (response.ok) {
|
105
|
-
store = await response.json()
|
106
|
-
}
|
107
|
-
|
108
|
-
let mappedStore: any = {
|
109
|
-
accessKey: store.shop?.credential?.consumer_key || '',
|
110
|
-
accessSecret: store.shop?.credential?.consumer_secret || '',
|
111
|
-
storeURL: store.shop?.credential?.store_url,
|
112
|
-
platform: PLATFORM[`${store.shop.org_prefix}`],
|
113
|
-
accessToken: store.shop?.credential?.access_token,
|
114
|
-
channelShopId: store.shop?.channel_shop_id
|
115
|
-
}
|
116
|
-
|
117
62
|
try {
|
118
|
-
if (requestBody[i].native_variant_id != requestBody[i].native_product_id) {
|
63
|
+
if (requestBody[i].variant.native_variant_id != requestBody[i].native_product_id) {
|
119
64
|
const req = {
|
120
|
-
qty: requestBody[i].stock,
|
65
|
+
qty: requestBody[i].variant.stock,
|
121
66
|
itemId: requestBody[i].native_product_id,
|
122
|
-
variationId: requestBody[i].native_variant_id,
|
67
|
+
variationId: requestBody[i].variant.native_variant_id,
|
123
68
|
distributors: requestBody[i].distributors || [], // for Magento
|
124
|
-
variationSku: requestBody[i].sku
|
69
|
+
variationSku: requestBody[i].variant.sku,
|
70
|
+
locationId: requestBody[i]?.variant?.extra_metadata?.locationId, // for Shopify
|
71
|
+
inventoryItemId: requestBody[i]?.variant?.extra_metadata?.inventoryItemId, // for Shopify
|
72
|
+
context: { state: { domain: null } }
|
73
|
+
}
|
74
|
+
if (req.locationId) {
|
75
|
+
let location = JSON.parse(req.locationId)
|
76
|
+
req.qty -= await StoreAPI.getStoreProductVariationStock(mappedStore, { variantId: req.variationId })
|
77
|
+
req.locationId = location[0].location_id
|
125
78
|
}
|
126
79
|
result = await StoreAPI.updateStoreProductVariationStock(mappedStore, req)
|
127
80
|
} else {
|
128
81
|
const req = {
|
129
|
-
qty: requestBody[i].stock,
|
82
|
+
qty: requestBody[i].variant.stock,
|
130
83
|
itemId: requestBody[i].native_product_id,
|
131
84
|
distributors: requestBody[i].distributors || [], // for Magento
|
132
|
-
variationSku: requestBody[i].sku
|
85
|
+
variationSku: requestBody[i].variant.sku,
|
86
|
+
context: { state: { domain: null } }
|
133
87
|
}
|
134
88
|
result = await StoreAPI.updateStoreProductStock(mappedStore, req)
|
135
89
|
}
|
@@ -149,54 +103,39 @@ sellercraftRouter.post('/sellercraft/store/update-product-stock', async (context
|
|
149
103
|
|
150
104
|
sellercraftRouter.post('/sellercraft/store/update-order-status', async (context, next) => {
|
151
105
|
try {
|
152
|
-
const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
|
153
|
-
const { tokenCraftApiKey: apiKey, tokenCraftUrl } = sellercraftChannelIntegrationConfig
|
154
|
-
|
155
|
-
const xApiKey = context.headers['x-api-key']
|
156
|
-
|
157
|
-
if (apiKey !== xApiKey) context.throw(400, 'api key validation failed')
|
158
|
-
|
159
106
|
const requestBody = context.request.body
|
160
|
-
var result
|
161
|
-
|
162
|
-
|
163
|
-
// https://staging-tokencraft.sellercraft.co/v1/get-shop?channel_id=4bfb3362-d57c-47f8-8781-007316d179bf&shop_id=dd9cf3b7-114f-4d74-a7e2-7b524ae086f2
|
164
|
-
var fullPath = `${tokenCraftUrl}?channel_id=${requestBody.channel_id}&shop_id=${requestBody.shop_id}`
|
165
|
-
const response: any = await fetch(fullPath, {
|
166
|
-
method: 'get',
|
167
|
-
headers: {
|
168
|
-
'Content-Type': 'application/json',
|
169
|
-
'x-api-key': apiKey
|
170
|
-
}
|
171
|
-
})
|
172
|
-
if (response.ok) {
|
173
|
-
store = await response.json()
|
174
|
-
}
|
175
|
-
|
176
|
-
let mappedStore: any = {
|
177
|
-
accessKey: store.shop?.credential?.consumer_key || '',
|
178
|
-
accessSecret: store.shop?.credential?.consumer_secret || '',
|
179
|
-
storeURL: store.shop?.credential?.store_url,
|
180
|
-
platform: PLATFORM[`${store.shop.org_prefix}`],
|
181
|
-
accessToken: store.shop?.credential?.access_token,
|
182
|
-
channelShopId: store.shop?.channel_shop_id
|
183
|
-
}
|
107
|
+
var result: any = {}
|
108
|
+
let mappedStore: any = await getShop(context, requestBody.channel_id, requestBody.shop_id)
|
184
109
|
|
185
110
|
const reqBody = {
|
186
111
|
orderId: requestBody.native_order_id,
|
187
112
|
status: requestBody.order_status,
|
188
113
|
carrier: requestBody?.shipper_last_mile,
|
189
114
|
trackingNo: requestBody?.tracking_number,
|
190
|
-
orderItems:
|
191
|
-
|
115
|
+
orderItems: unmapOrderItems(
|
116
|
+
requestBody?.order_items.map(oi => {
|
117
|
+
return oi.native_order_item_id
|
118
|
+
}) || []
|
119
|
+
),
|
120
|
+
isSOF: requestBody?.seller_logistics,
|
121
|
+
locations:
|
122
|
+
mappedStore.platform == 'shopify'
|
123
|
+
? requestBody?.order_items.map(oi => {
|
124
|
+
let jsonLocation = oi.extra_metadata.locationId
|
125
|
+
return JSON.parse(jsonLocation)[0].location_id
|
126
|
+
})
|
127
|
+
: null,
|
128
|
+
context: { state: { domain: null } }
|
192
129
|
}
|
193
130
|
|
194
|
-
let responseBody: any = { operation_id:
|
131
|
+
let responseBody: any = { operation_id: uuidv4() }
|
195
132
|
try {
|
196
133
|
try {
|
197
|
-
result = await StoreAPI.updateOrderStatus(mappedStore, reqBody)
|
134
|
+
result = (await StoreAPI.updateOrderStatus(mappedStore, reqBody)) || {}
|
198
135
|
debug(result)
|
199
|
-
} catch (e) {
|
136
|
+
} catch (e) {
|
137
|
+
if (e?.requiredDocument) result.requiredDocument = e.requiredDocument
|
138
|
+
}
|
200
139
|
|
201
140
|
if (result?.requiredDocument) {
|
202
141
|
// call document api and ingest channel order package
|
@@ -231,7 +170,7 @@ sellercraftRouter.post('/sellercraft/store/update-order-status', async (context,
|
|
231
170
|
is_cod_supported: orderPackage?.isCodSupport ? orderPackage.isCodSupport : false
|
232
171
|
},
|
233
172
|
documents:
|
234
|
-
orderDocument
|
173
|
+
orderDocument?.map(doc => {
|
235
174
|
return {
|
236
175
|
file: doc.file,
|
237
176
|
file_type_value: doc.fileTypeValue,
|
@@ -242,7 +181,11 @@ sellercraftRouter.post('/sellercraft/store/update-order-status', async (context,
|
|
242
181
|
name: orderPackage.shippingProvider,
|
243
182
|
is_cod_supported: orderPackage?.isCodSupport ? orderPackage.isCodSupport : false
|
244
183
|
},
|
245
|
-
order_item_ids: orderPackage?.orderListIdList
|
184
|
+
order_item_ids: orderPackage?.orderListIdList
|
185
|
+
? orderPackage.orderListIdList
|
186
|
+
: reqBody.orderItems.map(oi => {
|
187
|
+
return oi.order_item_id
|
188
|
+
})
|
246
189
|
} || {}
|
247
190
|
|
248
191
|
responseBody.package = newOrderPackage
|
@@ -270,37 +213,8 @@ sellercraftRouter.post('/sellercraft/store/update-order-status', async (context,
|
|
270
213
|
})
|
271
214
|
|
272
215
|
sellercraftRouter.post('/sellercraft/store/update-product-attribute', async (context, next) => {
|
273
|
-
const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
|
274
|
-
const { tokenCraftApiKey: apiKey, tokenCraftUrl } = sellercraftChannelIntegrationConfig
|
275
|
-
|
276
|
-
const xApiKey = context.headers['x-api-key']
|
277
|
-
|
278
|
-
if (apiKey !== xApiKey) context.throw(400, 'api key validation failed')
|
279
|
-
|
280
216
|
const requestBody = context.request.body
|
281
|
-
|
282
|
-
|
283
|
-
// https://staging-tokencraft.sellercraft.co/v1/get-shop?channel_id=4bfb3362-d57c-47f8-8781-007316d179bf&shop_id=dd9cf3b7-114f-4d74-a7e2-7b524ae086f2
|
284
|
-
var fullPath = `${tokenCraftUrl}?channel_id=${requestBody.channel_id}&shop_id=${requestBody.shop_id}`
|
285
|
-
const response: any = await fetch(fullPath, {
|
286
|
-
method: 'get',
|
287
|
-
headers: {
|
288
|
-
'Content-Type': 'application/json',
|
289
|
-
'x-api-key': apiKey
|
290
|
-
}
|
291
|
-
})
|
292
|
-
if (response.ok) {
|
293
|
-
store = await response.json()
|
294
|
-
}
|
295
|
-
|
296
|
-
let mappedStore: any = {
|
297
|
-
accessKey: store.shop?.credential?.consumer_key || '',
|
298
|
-
accessSecret: store.shop?.credential?.consumer_secret || '',
|
299
|
-
storeURL: store.shop?.credential?.store_url,
|
300
|
-
platform: PLATFORM[`${store.shop.org_prefix}`],
|
301
|
-
accessToken: store.shop?.credential?.access_token,
|
302
|
-
channelShopId: store.shop?.channel_shop_id
|
303
|
-
}
|
217
|
+
let mappedStore: any = await getShop(context, requestBody.channel_id, requestBody.shop_id)
|
304
218
|
|
305
219
|
let { product_sku: productSku, native_product_id: itemId, variants } = requestBody
|
306
220
|
|
@@ -327,7 +241,12 @@ sellercraftRouter.post('/sellercraft/store/update-product-attribute', async (con
|
|
327
241
|
for (var i = 0; i < variants.length; i++) {
|
328
242
|
try {
|
329
243
|
let variant = variants[i]
|
330
|
-
await StoreAPI.updateProductAttribute(mappedStore, {
|
244
|
+
await StoreAPI.updateProductAttribute(mappedStore, {
|
245
|
+
productSku,
|
246
|
+
itemId,
|
247
|
+
variant,
|
248
|
+
context: { state: { domain: null } }
|
249
|
+
})
|
331
250
|
context.type = 'application/json'
|
332
251
|
context.status = 200
|
333
252
|
context.body = 'Succeeded'
|
@@ -338,3 +257,30 @@ sellercraftRouter.post('/sellercraft/store/update-product-attribute', async (con
|
|
338
257
|
}
|
339
258
|
}
|
340
259
|
})
|
260
|
+
|
261
|
+
function unmapOrderItems(orderItems) {
|
262
|
+
let itemsList = []
|
263
|
+
let res = orderItems.map(e => {
|
264
|
+
return e.split('-')[0]
|
265
|
+
})
|
266
|
+
|
267
|
+
for (let item of res) {
|
268
|
+
let count = 0
|
269
|
+
|
270
|
+
res.forEach(element => {
|
271
|
+
if (element === item) {
|
272
|
+
count += 1
|
273
|
+
}
|
274
|
+
})
|
275
|
+
|
276
|
+
itemsList.push({
|
277
|
+
order_item_id: item,
|
278
|
+
qty: count
|
279
|
+
})
|
280
|
+
}
|
281
|
+
|
282
|
+
itemsList = itemsList.filter(
|
283
|
+
(value, index, self) => index === self.findIndex(t => t.order_item_id === value.order_item_id)
|
284
|
+
)
|
285
|
+
return itemsList
|
286
|
+
}
|