@things-factory/integration-sellercraft 5.0.0-alpha.3 → 5.0.0-alpha.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist-server/constants/index.js +1 -0
  2. package/dist-server/constants/index.js.map +1 -1
  3. package/dist-server/constants/order-status-mapping.js +10 -0
  4. package/dist-server/constants/order-status-mapping.js.map +1 -0
  5. package/dist-server/controllers/index.js +2 -0
  6. package/dist-server/controllers/index.js.map +1 -1
  7. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.js +18 -20
  8. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.js.map +1 -1
  9. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js +17 -14
  10. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js.map +1 -1
  11. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js +23 -43
  12. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js.map +1 -1
  13. package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js +1 -1
  14. package/dist-server/routers/sellercraft-router.js +29 -13
  15. package/dist-server/routers/sellercraft-router.js.map +1 -1
  16. package/dist-server/service/index.js +5 -1
  17. package/dist-server/service/index.js.map +1 -1
  18. package/dist-server/service/marketplace-channel/index.js +9 -0
  19. package/dist-server/service/marketplace-channel/index.js.map +1 -0
  20. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +150 -0
  21. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js.map +1 -0
  22. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js +149 -0
  23. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -0
  24. package/dist-server/service/marketplace-channel/marketplace-channel.js +83 -0
  25. package/dist-server/service/marketplace-channel/marketplace-channel.js.map +1 -0
  26. package/dist-server/service/sellercraft/sellercraft.js +1 -1
  27. package/package.json +15 -15
  28. package/server/constants/index.ts +2 -1
  29. package/server/constants/order-status-mapping.ts +6 -0
  30. package/server/controllers/index.ts +2 -0
  31. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.ts +18 -20
  32. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +18 -14
  33. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.ts +27 -47
  34. package/server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.ts +1 -1
  35. package/server/routers/sellercraft-router.ts +32 -14
  36. package/server/service/index.ts +6 -1
  37. package/server/service/marketplace-channel/index.ts +6 -0
  38. package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +182 -0
  39. package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +161 -0
  40. package/server/service/marketplace-channel/marketplace-channel.ts +64 -0
  41. package/server/service/sellercraft/sellercraft.ts +1 -1
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.MarketplaceChannelOrderMutation = void 0;
16
+ const type_graphql_1 = require("type-graphql");
17
+ const typeorm_1 = require("typeorm");
18
+ const marketplace_channel_1 = require("./marketplace-channel");
19
+ const env_1 = require("@things-factory/env");
20
+ const integration_marketplace_1 = require("@things-factory/integration-marketplace");
21
+ const sellercraft_channel_integration_api_1 = require("../../controllers/sellercraft-channel-integration-api");
22
+ let MarketplaceChannelOrderMutation = class MarketplaceChannelOrderMutation {
23
+ async syncAllMarketplaceChannelOrders(fromDate, toDate, context) {
24
+ const sellercraftChannelIntegrationConfig = env_1.config.get('sellercraftChannelIntegrationConfig', {});
25
+ const { tokenCraftApiKey: apiKey, getShopsTokenCraftUrl } = sellercraftChannelIntegrationConfig;
26
+ const channels = await (0, typeorm_1.getRepository)(marketplace_channel_1.MarketplaceChannel).find();
27
+ for (var i = 0; i < channels.length; i++) {
28
+ var channelsFullPath = getShopsTokenCraftUrl + '?channel_id=' + channels[i].channelId;
29
+ const channelResponse = await fetch(channelsFullPath, {
30
+ method: 'get',
31
+ headers: {
32
+ 'Content-Type': 'application/json',
33
+ 'x-api-key': apiKey
34
+ }
35
+ });
36
+ if (!channelResponse.ok) {
37
+ throw new Error(channelResponse);
38
+ }
39
+ var shopsResponse = await channelResponse.json();
40
+ var shops = shopsResponse.shops;
41
+ for (var j = 0; j < shops.length; j++) {
42
+ var store = {
43
+ accessKey: shops[j].credential.consumer_key,
44
+ accessSecret: shops[j].credential.consumer_secret,
45
+ storeURL: shops[j].credential.store_url,
46
+ platform: channels[i].name,
47
+ accessToken: shops[j].credential.access_token // Magento+
48
+ };
49
+ // let countryCode = shops[j].country_code
50
+ // let channelCode = shops[j].org_prefix
51
+ let organisationId = shops[j].account_id;
52
+ let channelShopId = shops[j].channel_shop_id;
53
+ const orderReq = {
54
+ fromDate: fromDate,
55
+ toDate: toDate
56
+ };
57
+ const orderResult = await integration_marketplace_1.StoreAPI.getStoreOrders(store, orderReq);
58
+ var sellercraftStore = Object.assign(Object.assign({}, store), { platform: 'sellercraftChannelIntegration' });
59
+ let mappedOrderResult = orderResult.results.map(order => {
60
+ let { firstName: custFirstName, lastName: custLastName, orderCreatedAt: createdAt, orderUpdatedAt: updatedAt, orderNo: id, status } = order;
61
+ let { first_name: billFirstName, last_name: billLastName, address_1: billAddress1, address_2: billAddress2, address_3: billAddress3, address_4: billAddress4, address_5: billAddress5, city: billCity, postcode: billPostalCode, country: billCountry, phone: billPhone1, phone_2: billPhone2 } = order === null || order === void 0 ? void 0 : order.billing;
62
+ let { first_name: shipFirstName, last_name: shipLastName, address_1: shipAddress1, address_2: shipAddress2, address_3: shipAddress3, address_4: shipAddress4, address_5: shipAddress5, city: shipCity, postcode: shipPostalCode, country: shipCountry, phone: shipPhone1, phone_2: shipPhone2 } = order.shipping;
63
+ let orderItems = order.orderItems.map(item => {
64
+ let { name: id, variationId: variationId, slaExpiresAt, total, totalTax, subtotal, subtotalTax, qty } = item;
65
+ return {
66
+ id,
67
+ variationId,
68
+ currency: order.orderShipping.collectionCurrency,
69
+ createdAt: order.orderCreatedAt,
70
+ updatedAt: order.orderUpdatedAt,
71
+ charges: [
72
+ {
73
+ name: 'PRICE_NORMAL_SELLING',
74
+ grossAmount: total,
75
+ nettAmount: subtotal
76
+ },
77
+ {
78
+ name: 'TAXES',
79
+ grossAmount: totalTax,
80
+ nettAmount: subtotalTax
81
+ }
82
+ ],
83
+ slaExpiresAt,
84
+ qty
85
+ };
86
+ });
87
+ let mappedOrderItems = [];
88
+ orderItems.map(oi => {
89
+ for (let i = 0; i < oi.qty; i++) {
90
+ mappedOrderItems.push(Object.assign(Object.assign({}, oi), { id: `${oi.id}-${i + 1}` }));
91
+ }
92
+ });
93
+ return {
94
+ custFirstName,
95
+ custLastName,
96
+ createdAt,
97
+ updatedAt,
98
+ id,
99
+ billFirstName,
100
+ billLastName,
101
+ billAddress1: billAddress1.toString() || shipAddress1.toString(),
102
+ billAddress2: billAddress2 || shipAddress2,
103
+ billAddress3: billAddress3 || shipAddress3,
104
+ billAddress4: billAddress4 || shipAddress4,
105
+ billAddress5: billAddress5 || shipAddress5,
106
+ billCity: billCity || shipCity,
107
+ billPostalCode: billPostalCode || shipPostalCode,
108
+ billCountry: billCountry || shipCountry,
109
+ billPhone1: billPhone1 || shipPhone1,
110
+ billPhone2: billPhone2 || shipPhone2,
111
+ shipFirstName,
112
+ shipLastName,
113
+ shipAddress1: shipAddress1.toString(),
114
+ shipAddress2,
115
+ shipAddress3,
116
+ shipAddress4,
117
+ shipAddress5,
118
+ shipCity,
119
+ shipPostalCode,
120
+ shipCountry,
121
+ shipPhone1,
122
+ shipPhone2,
123
+ mappedOrderItems,
124
+ channelShopId,
125
+ organisationId,
126
+ status
127
+ };
128
+ });
129
+ if (mappedOrderResult.length > 0) {
130
+ await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelOrder(sellercraftStore, { orders: mappedOrderResult });
131
+ }
132
+ }
133
+ return true;
134
+ }
135
+ }
136
+ };
137
+ __decorate([
138
+ (0, type_graphql_1.Mutation)(returns => Boolean),
139
+ __param(0, (0, type_graphql_1.Arg)('fromDate')),
140
+ __param(1, (0, type_graphql_1.Arg)('toDate')),
141
+ __param(2, (0, type_graphql_1.Ctx)()),
142
+ __metadata("design:type", Function),
143
+ __metadata("design:paramtypes", [String, String, Object]),
144
+ __metadata("design:returntype", Promise)
145
+ ], MarketplaceChannelOrderMutation.prototype, "syncAllMarketplaceChannelOrders", null);
146
+ MarketplaceChannelOrderMutation = __decorate([
147
+ (0, type_graphql_1.Resolver)()
148
+ ], MarketplaceChannelOrderMutation);
149
+ exports.MarketplaceChannelOrderMutation = MarketplaceChannelOrderMutation;
150
+ //# sourceMappingURL=marketplace-channel-order-mutation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marketplace-channel-order-mutation.js","sourceRoot":"","sources":["../../../server/service/marketplace-channel/marketplace-channel-order-mutation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAA2D;AAC3D,qCAAuC;AAEvC,+DAA0D;AAE1D,6CAA4C;AAC5C,qFAAkE;AAClE,+GAAwG;AAGxG,IAAa,+BAA+B,GAA5C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AAG,EAAC,QAAQ,CAAC,CAAA;IACb,WAAA,IAAA,kBAAG,GAAE,CAAA;;;;sFAqKP;AA1KU,+BAA+B;IAD3C,IAAA,uBAAQ,GAAE;GACE,+BAA+B,CA2K3C;AA3KY,0EAA+B"}
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.MarketplaceChannelProductMutation = void 0;
16
+ const type_graphql_1 = require("type-graphql");
17
+ const typeorm_1 = require("typeorm");
18
+ const marketplace_channel_1 = require("./marketplace-channel");
19
+ const env_1 = require("@things-factory/env");
20
+ const integration_marketplace_1 = require("@things-factory/integration-marketplace");
21
+ const sellercraft_channel_integration_api_1 = require("../../controllers/sellercraft-channel-integration-api");
22
+ let MarketplaceChannelProductMutation = class MarketplaceChannelProductMutation {
23
+ async syncAllMarketplaceChannelProducts(context) {
24
+ const sellercraftChannelIntegrationConfig = env_1.config.get('sellercraftChannelIntegrationConfig', {});
25
+ const { tokenCraftApiKey: apiKey, getShopsTokenCraftUrl } = sellercraftChannelIntegrationConfig;
26
+ const channels = await (0, typeorm_1.getRepository)(marketplace_channel_1.MarketplaceChannel).find();
27
+ for (var i = 0; i < channels.length; i++) {
28
+ var channelsFullPath = getShopsTokenCraftUrl + '?channel_id=' + channels[i].channelId;
29
+ const channelResponse = await fetch(channelsFullPath, {
30
+ method: 'get',
31
+ headers: {
32
+ 'Content-Type': 'application/json',
33
+ 'x-api-key': apiKey
34
+ }
35
+ });
36
+ if (!channelResponse.ok) {
37
+ throw new Error(channelResponse);
38
+ }
39
+ var shopsResponse = await channelResponse.json();
40
+ var shops = shopsResponse.shops;
41
+ for (var j = 0; j < shops.length; j++) {
42
+ var store = {
43
+ accessKey: shops[j].credential.consumer_key,
44
+ accessSecret: shops[j].credential.consumer_secret,
45
+ storeURL: shops[j].credential.store_url,
46
+ platform: channels[i].name,
47
+ accessToken: shops[j].credential.access_token // Magento+
48
+ };
49
+ let countryCode = shops[j].country_code;
50
+ let channelCode = shops[j].org_prefix;
51
+ let organisationId = shops[j].account_id;
52
+ let channelShopId = shops[j].channel_shop_id;
53
+ var sellercraftStore = Object.assign(Object.assign({}, store), { platform: 'sellercraftChannelIntegration' });
54
+ const productResult = await integration_marketplace_1.StoreAPI.getStoreProducts(store, {});
55
+ const categoryResult = await integration_marketplace_1.StoreAPI.getStoreProductCategories(store, {});
56
+ let mappedProducts = productResult.results.map(item => {
57
+ let { categoryId, itemId: productId, name, brand, isVerified, images, attributes, variations } = item;
58
+ variations = variations.map(variation => {
59
+ let { variationSku, variationId, name, isEnabled: isEnabled, isEnabled: isSellable, attributes, stockLocked, qty: stockReported, costPrice: fullPrice, sellPrice: priceDiscounted, length, width, height, weight } = variation;
60
+ return {
61
+ variationSku,
62
+ variationId,
63
+ name,
64
+ isEnabled,
65
+ isSellable,
66
+ attributes,
67
+ stockLocked,
68
+ stockReported,
69
+ fullPrice,
70
+ priceDiscounted,
71
+ inventoryProducts: [
72
+ {
73
+ qty: stockReported,
74
+ name: `${name} - ${variationSku}`,
75
+ sku: variationSku,
76
+ productVersions: [
77
+ {
78
+ label: 'Default',
79
+ packageLengthMM: length,
80
+ packageWidthMM: width,
81
+ packageHeightMM: height,
82
+ packageWeightGram: weight,
83
+ qty: 1
84
+ }
85
+ ]
86
+ }
87
+ ]
88
+ };
89
+ });
90
+ images = images === null || images === void 0 ? void 0 : images.map(image => {
91
+ return {
92
+ url: image
93
+ };
94
+ });
95
+ return {
96
+ organisationId,
97
+ channelShopId: channelShopId,
98
+ channelCode: channels[i].channelCode,
99
+ channelCountry: shops[j].country_code,
100
+ categoryId,
101
+ productId,
102
+ name,
103
+ brand,
104
+ isVerified,
105
+ images,
106
+ attributes,
107
+ variations
108
+ };
109
+ });
110
+ let mappedCategories = categoryResult.results.map(category => {
111
+ let { id: categoryId, name: categoryName, parent, isActive } = category;
112
+ return {
113
+ categoryId,
114
+ categoryName,
115
+ parent,
116
+ isLeaf: parent == 0 ? false : true,
117
+ isActive: isActive || true,
118
+ channelCode,
119
+ countryCode,
120
+ childrenCategories: []
121
+ };
122
+ });
123
+ mappedCategories = mappedCategories.map(category => {
124
+ if (mappedCategories.filter(e => e.parent == category.categoryId).length > 0) {
125
+ category.childrenCategories = mappedCategories.filter(e => e.parent == category.categoryId);
126
+ }
127
+ return category;
128
+ });
129
+ await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelCategories(sellercraftStore, {
130
+ categories: mappedCategories
131
+ });
132
+ await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelProduct(sellercraftStore, { products: mappedProducts });
133
+ }
134
+ return true;
135
+ }
136
+ }
137
+ };
138
+ __decorate([
139
+ (0, type_graphql_1.Mutation)(returns => Boolean),
140
+ __param(0, (0, type_graphql_1.Ctx)()),
141
+ __metadata("design:type", Function),
142
+ __metadata("design:paramtypes", [Object]),
143
+ __metadata("design:returntype", Promise)
144
+ ], MarketplaceChannelProductMutation.prototype, "syncAllMarketplaceChannelProducts", null);
145
+ MarketplaceChannelProductMutation = __decorate([
146
+ (0, type_graphql_1.Resolver)()
147
+ ], MarketplaceChannelProductMutation);
148
+ exports.MarketplaceChannelProductMutation = MarketplaceChannelProductMutation;
149
+ //# sourceMappingURL=marketplace-channel-product-mutation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marketplace-channel-product-mutation.js","sourceRoot":"","sources":["../../../server/service/marketplace-channel/marketplace-channel-product-mutation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAAsD;AACtD,qCAAuC;AAEvC,+DAA0D;AAE1D,6CAA4C;AAC5C,qFAAkE;AAClE,+GAAwG;AAGxG,IAAa,iCAAiC,GAA9C,MAAa,iCAAiC;IAE5C,KAAK,CAAC,iCAAiC,CAAQ,OAAY;QACzD,MAAM,mCAAmC,GAAG,YAAM,CAAC,GAAG,CAAC,qCAAqC,EAAE,EAAE,CAAC,CAAA;QACjG,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,qBAAqB,EAAE,GAAG,mCAAmC,CAAA;QAE/F,MAAM,QAAQ,GAAyB,MAAM,IAAA,uBAAa,EAAC,wCAAkB,CAAC,CAAC,IAAI,EAAE,CAAA;QAErF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACxC,IAAI,gBAAgB,GAAG,qBAAqB,GAAG,cAAc,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;YACrF,MAAM,eAAe,GAAQ,MAAM,KAAK,CAAC,gBAAgB,EAAE;gBACzD,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;oBAClC,WAAW,EAAE,MAAM;iBACpB;aACF,CAAC,CAAA;YAEF,IAAI,CAAC,eAAe,CAAC,EAAE,EAAE;gBACvB,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;aACjC;YACD,IAAI,aAAa,GAAG,MAAM,eAAe,CAAC,IAAI,EAAE,CAAA;YAChD,IAAI,KAAK,GAAG,aAAa,CAAC,KAAK,CAAA;YAE/B,KAAK,IAAI,CAAC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WAAA,IAAA,kBAAG,GAAE,CAAA;;;;0FAmJ7C;AArJU,iCAAiC;IAD7C,IAAA,uBAAQ,GAAE;GACE,iCAAiC,CAsJ7C;AAtJY,8EAAiC"}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var _a, _b, _c;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.MarketplaceChannel = void 0;
14
+ const type_graphql_1 = require("type-graphql");
15
+ const typeorm_1 = require("typeorm");
16
+ const auth_base_1 = require("@things-factory/auth-base");
17
+ const shell_1 = require("@things-factory/shell");
18
+ let MarketplaceChannel = class MarketplaceChannel {
19
+ };
20
+ __decorate([
21
+ (0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
22
+ (0, type_graphql_1.Field)(type => type_graphql_1.ID),
23
+ __metadata("design:type", String)
24
+ ], MarketplaceChannel.prototype, "id", void 0);
25
+ __decorate([
26
+ (0, typeorm_1.ManyToOne)(type => shell_1.Domain),
27
+ (0, type_graphql_1.Field)({ nullable: true }),
28
+ __metadata("design:type", typeof (_a = typeof shell_1.Domain !== "undefined" && shell_1.Domain) === "function" ? _a : Object)
29
+ ], MarketplaceChannel.prototype, "domain", void 0);
30
+ __decorate([
31
+ (0, typeorm_1.RelationId)((marketplaceChannel) => marketplaceChannel.domain),
32
+ __metadata("design:type", String)
33
+ ], MarketplaceChannel.prototype, "domainId", void 0);
34
+ __decorate([
35
+ (0, typeorm_1.Column)(),
36
+ (0, type_graphql_1.Field)(),
37
+ __metadata("design:type", String)
38
+ ], MarketplaceChannel.prototype, "name", void 0);
39
+ __decorate([
40
+ (0, typeorm_1.Column)(),
41
+ (0, type_graphql_1.Field)(),
42
+ __metadata("design:type", String)
43
+ ], MarketplaceChannel.prototype, "channelCode", void 0);
44
+ __decorate([
45
+ (0, typeorm_1.Column)(),
46
+ (0, type_graphql_1.Field)(),
47
+ __metadata("design:type", String)
48
+ ], MarketplaceChannel.prototype, "channelId", void 0);
49
+ __decorate([
50
+ (0, typeorm_1.CreateDateColumn)(),
51
+ (0, type_graphql_1.Field)({ nullable: true }),
52
+ __metadata("design:type", Date)
53
+ ], MarketplaceChannel.prototype, "createdAt", void 0);
54
+ __decorate([
55
+ (0, typeorm_1.UpdateDateColumn)(),
56
+ (0, type_graphql_1.Field)({ nullable: true }),
57
+ __metadata("design:type", Date)
58
+ ], MarketplaceChannel.prototype, "updatedAt", void 0);
59
+ __decorate([
60
+ (0, typeorm_1.ManyToOne)(type => auth_base_1.User, { nullable: true }),
61
+ (0, type_graphql_1.Field)({ nullable: true }),
62
+ __metadata("design:type", typeof (_b = typeof auth_base_1.User !== "undefined" && auth_base_1.User) === "function" ? _b : Object)
63
+ ], MarketplaceChannel.prototype, "creator", void 0);
64
+ __decorate([
65
+ (0, typeorm_1.RelationId)((marketplaceChannel) => marketplaceChannel.creator),
66
+ __metadata("design:type", String)
67
+ ], MarketplaceChannel.prototype, "creatorId", void 0);
68
+ __decorate([
69
+ (0, typeorm_1.ManyToOne)(type => auth_base_1.User, { nullable: true }),
70
+ (0, type_graphql_1.Field)({ nullable: true }),
71
+ __metadata("design:type", typeof (_c = typeof auth_base_1.User !== "undefined" && auth_base_1.User) === "function" ? _c : Object)
72
+ ], MarketplaceChannel.prototype, "updater", void 0);
73
+ __decorate([
74
+ (0, typeorm_1.RelationId)((marketplaceChannel) => marketplaceChannel.updater),
75
+ __metadata("design:type", String)
76
+ ], MarketplaceChannel.prototype, "updaterId", void 0);
77
+ MarketplaceChannel = __decorate([
78
+ (0, typeorm_1.Entity)(),
79
+ (0, typeorm_1.Index)('ix_marketplace_channel_0 ', (marketplaceChannel) => [marketplaceChannel.domain, marketplaceChannel.name], { unique: true }),
80
+ (0, type_graphql_1.ObjectType)({ description: 'Entity for Marketplace Channel' })
81
+ ], MarketplaceChannel);
82
+ exports.MarketplaceChannel = MarketplaceChannel;
83
+ //# sourceMappingURL=marketplace-channel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marketplace-channel.js","sourceRoot":"","sources":["../../../server/service/marketplace-channel/marketplace-channel.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,+CAAoD;AACpD,qCASgB;AAEhB,yDAAgD;AAChD,iDAA8C;AAK9C,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;CA6C9B,CAAA;AA1CC;IAFC,IAAA,gCAAsB,EAAC,MAAM,CAAC;IAC9B,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAE,CAAC;;8CACC;AAInB;IAFC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,CAAC;IACzB,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;kDACjB,cAAM,oBAAN,cAAM;kDAAA;AAGf;IADC,IAAA,oBAAU,EAAC,CAAC,kBAAsC,EAAE,EAAE,CAAC,kBAAkB,CAAC,MAAM,CAAC;;oDACjE;AAIjB;IAFC,IAAA,gBAAM,GAAE;IACR,IAAA,oBAAK,GAAE;;gDACI;AAIZ;IAFC,IAAA,gBAAM,GAAE;IACR,IAAA,oBAAK,GAAE;;uDACW;AAInB;IAFC,IAAA,gBAAM,GAAE;IACR,IAAA,oBAAK,GAAE;;qDACS;AAIjB;IAFC,IAAA,0BAAgB,GAAE;IAClB,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;8BACd,IAAI;qDAAA;AAIhB;IAFC,IAAA,0BAAgB,GAAE;IAClB,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;8BACd,IAAI;qDAAA;AAIhB;IAFC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC3C,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;kDAChB,gBAAI,oBAAJ,gBAAI;mDAAA;AAGd;IADC,IAAA,oBAAU,EAAC,CAAC,kBAAsC,EAAE,EAAE,CAAC,kBAAkB,CAAC,OAAO,CAAC;;qDACjE;AAIlB;IAFC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC3C,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;kDAChB,gBAAI,oBAAJ,gBAAI;mDAAA;AAGd;IADC,IAAA,oBAAU,EAAC,CAAC,kBAAsC,EAAE,EAAE,CAAC,kBAAkB,CAAC,OAAO,CAAC;;qDACjE;AA5CP,kBAAkB;IAH9B,IAAA,gBAAM,GAAE;IACR,IAAA,eAAK,EAAC,2BAA2B,EAAE,CAAC,kBAAsC,EAAE,EAAE,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IACtJ,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC;GACjD,kBAAkB,CA6C9B;AA7CY,gDAAkB"}
@@ -99,7 +99,7 @@ __decorate([
99
99
  __metadata("design:type", typeof (_c = typeof auth_base_1.User !== "undefined" && auth_base_1.User) === "function" ? _c : Object)
100
100
  ], Sellercraft.prototype, "updater", void 0);
101
101
  __decorate([
102
- (0, typeorm_1.RelationId)((sellercraft) => sellercraft.creator),
102
+ (0, typeorm_1.RelationId)((sellercraft) => sellercraft.updater),
103
103
  __metadata("design:type", String)
104
104
  ], Sellercraft.prototype, "updaterId", void 0);
105
105
  Sellercraft = __decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/integration-sellercraft",
3
- "version": "5.0.0-alpha.3",
3
+ "version": "5.0.0-alpha.32",
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.3",
28
- "@things-factory/auth-ui": "^5.0.0-alpha.3",
29
- "@things-factory/biz-base": "^5.0.0-alpha.3",
30
- "@things-factory/code-ui": "^5.0.0-alpha.3",
31
- "@things-factory/context-ui": "^5.0.0-alpha.3",
32
- "@things-factory/grist-ui": "^5.0.0-alpha.3",
33
- "@things-factory/i18n-base": "^5.0.0-alpha.3",
34
- "@things-factory/integration-marketplace": "^5.0.0-alpha.3",
35
- "@things-factory/integration-ui": "^5.0.0-alpha.3",
36
- "@things-factory/more-ui": "^5.0.0-alpha.3",
37
- "@things-factory/resource-ui": "^5.0.0-alpha.3",
38
- "@things-factory/setting-ui": "^5.0.0-alpha.3",
39
- "@things-factory/system-ui": "^5.0.0-alpha.3",
27
+ "@things-factory/apptool-ui": "^5.0.0-alpha.32",
28
+ "@things-factory/auth-ui": "^5.0.0-alpha.32",
29
+ "@things-factory/biz-base": "^5.0.0-alpha.32",
30
+ "@things-factory/code-ui": "^5.0.0-alpha.32",
31
+ "@things-factory/context-ui": "^5.0.0-alpha.32",
32
+ "@things-factory/grist-ui": "^5.0.0-alpha.32",
33
+ "@things-factory/i18n-base": "^5.0.0-alpha.32",
34
+ "@things-factory/integration-marketplace": "^5.0.0-alpha.32",
35
+ "@things-factory/integration-ui": "^5.0.0-alpha.32",
36
+ "@things-factory/more-ui": "^5.0.0-alpha.32",
37
+ "@things-factory/resource-ui": "^5.0.0-alpha.32",
38
+ "@things-factory/setting-ui": "^5.0.0-alpha.32",
39
+ "@things-factory/system-ui": "^5.0.0-alpha.32",
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": "0584a36ba889ff0b426cc87c0d9c8f14ffa2f677"
54
+ "gitHead": "c29fd7ecf652108bc3a333a6e0a766c11e1ea9f0"
55
55
  }
@@ -1 +1,2 @@
1
- export * from './platform'
1
+ export * from './platform'
2
+ export * from './order-status-mapping'
@@ -0,0 +1,6 @@
1
+ export const ORDER_STATUS = {
2
+ pending: 'PAYMENT_PENDING',
3
+ processing: 'CONFIRMED',
4
+ completed: 'DELIVERED',
5
+ cancelled: 'CANCELLED'
6
+ }
@@ -1,3 +1,5 @@
1
1
  import './sellercraft'
2
2
 
3
3
  export * from './sellercraft-api'
4
+ export * from './sellercraft-channel-integration'
5
+ export * from './sellercraft-channel-integration-api'
@@ -7,28 +7,10 @@ export function ingestChannelCategories() {
7
7
  denormalize(req) {
8
8
  const { categories } = req
9
9
 
10
- let newCategories = categories.map(category => {
11
- return {
12
- channel_id: category.channelId,
13
- native_category_id: category.categoryId,
14
- category_name: category.categoryName,
15
- is_leaf: category.isLeaf,
16
- is_active: category.isActive,
17
- children_categories: category.childrenCategories.map(childrenCategory => {
18
- return {
19
- channel_id: childrenCategory.channelId,
20
- native_category_id: childrenCategory.categoryId,
21
- category_name: childrenCategory.categoryName,
22
- is_leaf: childrenCategory.isLeaf,
23
- is_active: childrenCategory.isActive,
24
- children_categories: {}
25
- }
26
- })
27
- }
28
- })
10
+ let newCategories = mapCategories(categories)
29
11
 
30
12
  return {
31
- payload: { newCategories }
13
+ payload: [...newCategories]
32
14
  }
33
15
  },
34
16
  normalize(res) {
@@ -36,3 +18,19 @@ export function ingestChannelCategories() {
36
18
  }
37
19
  }
38
20
  }
21
+
22
+ function mapCategories(categories) {
23
+ if (!categories) return null
24
+ categories = categories.map(category => {
25
+ return {
26
+ native_category_id: category.categoryId.toString(),
27
+ channel_code: category.channelCode,
28
+ channel_country: category.countryCode,
29
+ category_name: category.categoryName,
30
+ is_leaf: category.isLeaf,
31
+ is_active: category.isActive,
32
+ children_categories: mapCategories(category.childrenCategories)
33
+ }
34
+ })
35
+ return categories
36
+ }
@@ -1,5 +1,7 @@
1
1
  /* https://docs.sellercraft.co/docs/api-integrations/b3A6MTY4NjQxODU-initiate-order-shipment */
2
2
 
3
+ import { ORDER_STATUS } from '../../../constants'
4
+
3
5
  export function ingestChannelOrder() {
4
6
  return {
5
7
  method: 'post',
@@ -12,12 +14,13 @@ export function ingestChannelOrder() {
12
14
  organisation_id: order.organisationId,
13
15
  channel_shop_id: order.channelShopId,
14
16
  native_order_id: order.id,
15
- ordered_at_date: order.createdAt,
16
- ordered_at_time: order.createdAt,
17
- updated_at_date: order.updatedAt,
18
- updated_at_time: order.updatedAt,
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(),
19
21
  customer_first_name: order.custFirstName,
20
22
  customer_last_name: order.custLastName,
23
+ charges: [],
21
24
  address_shipping: {
22
25
  first_name: order.shipFirstName,
23
26
  last_name: order.shipLastName,
@@ -48,28 +51,29 @@ export function ingestChannelOrder() {
48
51
  },
49
52
  order_items: order.orderItems.map(orderItem => {
50
53
  return {
51
- native_item_id: orderItem.id,
52
- native_variant_id: orderItem.variationId,
54
+ native_item_id: orderItem.id.toString(),
55
+ native_variant_id: orderItem.variationId.toString(),
53
56
  currency_code: orderItem.currency,
54
- ordered_at_date: order.createdAt,
55
- ordered_at_time: order.createdAt,
56
- updated_at_date: order.updatedAt,
57
- updated_at_time: order.updatedAt,
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(),
58
61
  sla_expires_at: order?.slaExpiresAt,
59
62
  charges: orderItem.charges.map(charge => {
60
63
  return {
61
64
  charge_type_value: charge.name,
62
- amount_gross: charge.grossAmount,
63
- amount_nett: charge.nettAmount
65
+ amount_gross: parseFloat(charge.grossAmount) || 0,
66
+ amount_nett: parseFloat(charge.nettAmount) || 0
64
67
  }
65
- })
68
+ }),
69
+ order_status_value: ORDER_STATUS[`${order.status}`]
66
70
  }
67
71
  })
68
72
  }
69
73
  })
70
74
 
71
75
  return {
72
- payload: { newOrders }
76
+ payload: [ ...newOrders ]
73
77
  }
74
78
  },
75
79
  normalize(res) {