@things-factory/integration-sellercraft 5.0.0-alpha.8 → 5.0.0-alpha.9

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 +7 -5
  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 -37
  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 +25 -9
  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 +142 -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 +138 -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 +7 -5
  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 +23 -43
  34. package/server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.ts +1 -1
  35. package/server/routers/sellercraft-router.ts +41 -11
  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 +167 -0
  40. package/server/service/marketplace-channel/marketplace-channel.ts +64 -0
  41. package/server/service/sellercraft/sellercraft.ts +1 -1
@@ -0,0 +1,138 @@
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
+ };
48
+ let countryCode = shops[j].country_code;
49
+ let channelCode = shops[j].org_prefix;
50
+ let organisationId = shops[j].credential.account_id;
51
+ let channelShopId = shops[j].credential.channel_shop_id;
52
+ var sellercraftStore = Object.assign(Object.assign({}, store), { platform: 'sellercraftChannelIntegration' });
53
+ const productResult = await integration_marketplace_1.StoreAPI.getStoreProducts(store, {});
54
+ const categoryResult = await integration_marketplace_1.StoreAPI.getStoreProductCategories(store, {});
55
+ let mappedProducts = productResult.results.map((item) => {
56
+ let { categoryId, itemId: productId, name, brand, isVerified, images, attributes, variations } = item;
57
+ variations = variations.map(variation => {
58
+ let { variationSku, variationId, name, isEnabled: isEnabled, isEnabled: isSellable, attributes, stockLocked, qty: stockReported, costPrice: fullPrice, sellPrice: priceDiscounted, length, width, height, weight } = variation;
59
+ return {
60
+ variationSku,
61
+ variationId,
62
+ name,
63
+ isEnabled,
64
+ isSellable,
65
+ attributes,
66
+ stockLocked,
67
+ stockReported,
68
+ fullPrice,
69
+ priceDiscounted,
70
+ inventoryProducts: [{
71
+ qty: stockReported,
72
+ name: `${name} - ${variationSku}`,
73
+ sku: variationSku,
74
+ productVersions: [{
75
+ label: 'Default',
76
+ packageLengthMM: length,
77
+ packageWidthMM: width,
78
+ packageHeightMM: height,
79
+ packageWeightGram: weight,
80
+ qty: 1
81
+ }]
82
+ }]
83
+ };
84
+ });
85
+ images = images.map(image => {
86
+ return {
87
+ url: image
88
+ };
89
+ });
90
+ return {
91
+ organisationId,
92
+ channelShopId: channelShopId,
93
+ channelCode: channels[i].channelCode,
94
+ channelCountry: shops[j].country_code,
95
+ categoryId,
96
+ productId,
97
+ name,
98
+ brand,
99
+ isVerified,
100
+ images,
101
+ attributes,
102
+ variations
103
+ };
104
+ });
105
+ let mappedCategories = categoryResult.results.map((category) => {
106
+ let { id: categoryId, name: categoryName, parent, isActive } = category;
107
+ return {
108
+ categoryId,
109
+ categoryName,
110
+ parent,
111
+ isLeaf: parent == 0 ? false : true,
112
+ isActive: isActive || true,
113
+ channelCode,
114
+ countryCode
115
+ };
116
+ });
117
+ mappedCategories.map((category) => {
118
+ category.childrenCategories = mappedCategories.filter(e => e.parent == category.categoryId);
119
+ });
120
+ const ingestCategory = await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelCategories(sellercraftStore, { categories: mappedCategories });
121
+ const ingestProduct = await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelProduct(sellercraftStore, { products: mappedProducts });
122
+ }
123
+ return true;
124
+ }
125
+ }
126
+ };
127
+ __decorate([
128
+ (0, type_graphql_1.Mutation)(returns => Boolean),
129
+ __param(0, (0, type_graphql_1.Ctx)()),
130
+ __metadata("design:type", Function),
131
+ __metadata("design:paramtypes", [Object]),
132
+ __metadata("design:returntype", Promise)
133
+ ], MarketplaceChannelProductMutation.prototype, "syncAllMarketplaceChannelProducts", null);
134
+ MarketplaceChannelProductMutation = __decorate([
135
+ (0, type_graphql_1.Resolver)()
136
+ ], MarketplaceChannelProductMutation);
137
+ exports.MarketplaceChannelProductMutation = MarketplaceChannelProductMutation;
138
+ //# 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,CAC9B,OAAY;QAEnB,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,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AA,IAAA,kBAAG,GAAE,CAAA;;;;0FAwJP;AA3JU,iCAAiC;IAD7C,IAAA,uBAAQ,GAAE;GACE,iCAAiC,CA4J7C;AA5JY,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.8",
3
+ "version": "5.0.0-alpha.9",
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.8",
28
- "@things-factory/auth-ui": "^5.0.0-alpha.8",
29
- "@things-factory/biz-base": "^5.0.0-alpha.8",
30
- "@things-factory/code-ui": "^5.0.0-alpha.8",
31
- "@things-factory/context-ui": "^5.0.0-alpha.8",
32
- "@things-factory/grist-ui": "^5.0.0-alpha.8",
33
- "@things-factory/i18n-base": "^5.0.0-alpha.8",
34
- "@things-factory/integration-marketplace": "^5.0.0-alpha.8",
35
- "@things-factory/integration-ui": "^5.0.0-alpha.8",
36
- "@things-factory/more-ui": "^5.0.0-alpha.8",
37
- "@things-factory/resource-ui": "^5.0.0-alpha.8",
38
- "@things-factory/setting-ui": "^5.0.0-alpha.8",
39
- "@things-factory/system-ui": "^5.0.0-alpha.8",
27
+ "@things-factory/apptool-ui": "^5.0.0-alpha.9",
28
+ "@things-factory/auth-ui": "^5.0.0-alpha.9",
29
+ "@things-factory/biz-base": "^5.0.0-alpha.9",
30
+ "@things-factory/code-ui": "^5.0.0-alpha.9",
31
+ "@things-factory/context-ui": "^5.0.0-alpha.9",
32
+ "@things-factory/grist-ui": "^5.0.0-alpha.9",
33
+ "@things-factory/i18n-base": "^5.0.0-alpha.9",
34
+ "@things-factory/integration-marketplace": "^5.0.0-alpha.9",
35
+ "@things-factory/integration-ui": "^5.0.0-alpha.9",
36
+ "@things-factory/more-ui": "^5.0.0-alpha.9",
37
+ "@things-factory/resource-ui": "^5.0.0-alpha.9",
38
+ "@things-factory/setting-ui": "^5.0.0-alpha.9",
39
+ "@things-factory/system-ui": "^5.0.0-alpha.9",
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": "45da542dc9c876c0a1fa1837f1606210ae600b73"
54
+ "gitHead": "c0f2f0758f80724cae6bbd56bbea43feef0f8a1c"
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: 'PENDING_PAYMENT',
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'
@@ -9,15 +9,17 @@ export function ingestChannelCategories() {
9
9
 
10
10
  let newCategories = categories.map(category => {
11
11
  return {
12
- channel_id: category.channelId,
13
- native_category_id: category.categoryId,
12
+ native_category_id: category.categoryId.toString(),
13
+ channel_code: category.channelCode,
14
+ channel_country: category.countryCode,
14
15
  category_name: category.categoryName,
15
16
  is_leaf: category.isLeaf,
16
17
  is_active: category.isActive,
17
18
  children_categories: category.childrenCategories.map(childrenCategory => {
18
19
  return {
19
- channel_id: childrenCategory.channelId,
20
- native_category_id: childrenCategory.categoryId,
20
+ native_category_id: category.categoryId.toString(),
21
+ channel_code: category.channelCode,
22
+ channel_country: category.countryCode,
21
23
  category_name: childrenCategory.categoryName,
22
24
  is_leaf: childrenCategory.isLeaf,
23
25
  is_active: childrenCategory.isActive,
@@ -28,7 +30,7 @@ export function ingestChannelCategories() {
28
30
  })
29
31
 
30
32
  return {
31
- payload: { newCategories }
33
+ payload: [ ...newCategories ]
32
34
  }
33
35
  },
34
36
  normalize(res) {
@@ -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) {
@@ -11,31 +11,21 @@ export function ingestChannelProduct() {
11
11
  let productVariations: any[] = product.variations.map(variant => {
12
12
  return {
13
13
  seller_sku: variant.variationSku,
14
- native_variant_id: variant.variationId,
14
+ native_variant_id: variant.variationId.toString(),
15
15
  label: variant.name,
16
16
  is_enabled: variant.isEnabled,
17
17
  is_sellable: variant.isSellable,
18
- variant_attributes: variant?.attributes
19
- ? variant.attributes.map(attribute => {
20
- return {
21
- attribute_key: attribute.id,
22
- values: []
23
- }
24
- })
25
- : [],
18
+ is_deleted: false, // default
19
+ // variant_attributes: variant?.attributes.map(attribute => {
20
+ // return {
21
+ // ...attribute,
22
+ // native_attribute_id: attribute.native_attribute_id.toString()
23
+ // }
24
+ // }) || [],
26
25
  stock_locked: variant?.stockLocked ? variant.stockLocked : 0,
27
26
  native_stock_reported: variant?.stockReported ? variant.stockReported : 0,
28
- price_full: variant.fullPrice,
29
- price_discounted: variant.priceDiscounted,
30
- price_discounts: variant?.product_discounts
31
- ? variant.product_discounts.map(discount => {
32
- return {
33
- price_discounted: discount.priceDiscounted,
34
- native_discount_id: discount.id,
35
- name: discount.name
36
- }
37
- })
38
- : [],
27
+ price_full: variant.fullPrice || 0,
28
+ price_discounted: variant.priceDiscounted || variant.fullPrice || 0,
39
29
  inventory_products: variant?.inventoryProducts
40
30
  ? variant.inventoryProducts.map(inventoryProduct => {
41
31
  return {
@@ -53,7 +43,7 @@ export function ingestChannelProduct() {
53
43
  package_weight_gram: productVersion?.packageWeightGram
54
44
  ? productVersion.packageWeightGram
55
45
  : 0,
56
- stock_available: productVersion.qty
46
+ stock_available: productVersion.qty || 0
57
47
  }
58
48
  })
59
49
  : []
@@ -68,43 +58,33 @@ export function ingestChannelProduct() {
68
58
  channel_shop_id: product.channelShopId,
69
59
  channel_code: product.channelCode,
70
60
  channel_country: product.channelCountry,
71
- native_category_id: product.categoryId,
72
- native_product_id: product.productId,
61
+ native_category_id: product.categoryId.toString(),
62
+ native_product_id: product.productId.toString(),
73
63
  label: product.name,
74
64
  brand: product.brand,
75
65
  is_verified: product.isVerified,
66
+ flexible_attributes: product.channelCode == 'WCM' ? true : false, // add channels that do not support category_attributes ingestion
76
67
  images: product.images.map(image => {
77
68
  return {
78
69
  file_url: image.url
79
70
  }
80
71
  }),
81
- product_attributes: product.attributes.map(attribute => {
82
- return {
83
- native_attribute_id: attribute.id,
84
- values: []
85
- }
86
- })
72
+ // product_attributes: product.attributes.map(attribute => {
73
+ // return {
74
+ // ...attribute,
75
+ // native_attribute_id: attribute.native_attribute_id.toString()
76
+ // }
77
+ // }),
78
+ variants: productVariations
87
79
  }
88
80
  })
89
81
 
90
82
  return {
91
- payload: {}
83
+ payload: [...newProducts]
92
84
  }
93
85
  },
94
86
  normalize(res) {
95
- const {
96
- handover_type: handOverType,
97
- pickup_time: pickupTime,
98
- pickup_address: pickupAddress,
99
- dropoff_address: dropoffAddress
100
- } = res.data
101
-
102
- return {
103
- handOverType,
104
- pickupTime,
105
- pickupAddress,
106
- dropoffAddress
107
- }
87
+ return res
108
88
  }
109
89
  }
110
90
  }
@@ -38,7 +38,7 @@ export class SellercraftChannelIntegration {
38
38
  headers: {
39
39
  'Content-Type': 'application/json',
40
40
  request_id: requestId,
41
- 'x-api-key': apiKey
41
+ 'X-Api-Key': apiKey
42
42
  },
43
43
  body: jsondata
44
44
  })
@@ -10,7 +10,7 @@ export const sellercraftRouter = new Router()
10
10
 
11
11
  sellercraftRouter.post('/sellercraft/store/update-product-price', async (context, next) => {
12
12
  const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
13
- const { apiKey, tokenCraftUrl } = sellercraftChannelIntegrationConfig
13
+ const { tokenCraftApiKey: apiKey, tokenCraftUrl } = sellercraftChannelIntegrationConfig
14
14
 
15
15
  const xApiKey = context.headers['x-api-key']
16
16
 
@@ -67,7 +67,7 @@ sellercraftRouter.post('/sellercraft/store/update-product-price', async (context
67
67
 
68
68
  sellercraftRouter.post('/sellercraft/store/update-product-stock', async (context, next) => {
69
69
  const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
70
- const { apiKey, tokenCraftUrl } = sellercraftChannelIntegrationConfig
70
+ const { tokenCraftApiKey: apiKey, tokenCraftUrl } = sellercraftChannelIntegrationConfig
71
71
 
72
72
  const xApiKey = context.headers['x-api-key']
73
73
 
@@ -120,7 +120,7 @@ sellercraftRouter.post('/sellercraft/store/update-product-stock', async (context
120
120
 
121
121
  sellercraftRouter.post('/sellercraft/store/update-order-status', async (context, next) => {
122
122
  const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
123
- const { apiKey, tokenCraftUrl } = sellercraftChannelIntegrationConfig
123
+ const { tokenCraftApiKey: apiKey, tokenCraftUrl } = sellercraftChannelIntegrationConfig
124
124
 
125
125
  const xApiKey = context.headers['x-api-key']
126
126
 
@@ -160,7 +160,7 @@ sellercraftRouter.post('/sellercraft/store/update-order-status', async (context,
160
160
 
161
161
  sellercraftRouter.post('/sellercraft/store/update-product-attribute', async (context, next) => {
162
162
  const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
163
- const { apiKey, tokenCraftUrl } = sellercraftChannelIntegrationConfig
163
+ const { tokenCraftApiKey: apiKey, tokenCraftUrl } = sellercraftChannelIntegrationConfig
164
164
 
165
165
  const xApiKey = context.headers['x-api-key']
166
166
 
@@ -168,7 +168,6 @@ sellercraftRouter.post('/sellercraft/store/update-product-attribute', async (con
168
168
 
169
169
  const requestBody = context.request.body
170
170
  var store: any = {}
171
- const attributes: any[] = requestBody.attributes
172
171
 
173
172
  // https://staging-tokencraft.sellercraft.co/v1/get-shop?channel_id=4bfb3362-d57c-47f8-8781-007316d179bf&shop_id=dd9cf3b7-114f-4d74-a7e2-7b524ae086f2
174
173
  var fullPath = tokenCraftUrl + '?channel_id=4bfb3362-d57c-47f8-8781-007316d179bf&shop_id=' + requestBody.shop_id
@@ -190,13 +189,44 @@ sellercraftRouter.post('/sellercraft/store/update-product-attribute', async (con
190
189
  platform: PLATFORM[`${store.shop.org_prefix}`]
191
190
  }
192
191
 
193
- await Promise.all(
194
- attributes.map(async attribute => {
195
- const attributeReqBody = { attributeId: attribute.native_attribute_id, name: attribute.attribute_key }
196
-
197
- await StoreAPI.updateProductAttribute(mappedStore, attributeReqBody)
192
+ let {
193
+ product_sku: productSku,
194
+ native_product_id: itemId,
195
+ variants
196
+ } = requestBody
197
+
198
+ variants.map(variant => {
199
+ let {
200
+ variant_sku: variantSku,
201
+ native_variant_id: variantId,
202
+ attributes
203
+ } = variant
204
+
205
+ attributes.map(attribute => {
206
+ let {
207
+ native_attribute_id: id,
208
+ attribute_key: name,
209
+ attribute_value: value
210
+ } = attribute
211
+
212
+ return {
213
+ id,
214
+ name,
215
+ value
216
+ }
198
217
  })
199
- )
218
+
219
+ return {
220
+ variantSku,
221
+ variantId,
222
+ attributes
223
+ }
224
+ })
225
+
226
+ for (var i = 0; i < variants.length; i++) {
227
+ let variant = variants[i]
228
+ await StoreAPI.updateProductAttribute(mappedStore, { productSku, itemId, variant })
229
+ }
200
230
 
201
231
  context.status = 200
202
232
  })
@@ -3,10 +3,12 @@ export * from './sellercraft/sellercraft'
3
3
 
4
4
  /* IMPORT ENTITIES AND RESOLVERS */
5
5
  import { entities as SellercraftEntities, resolvers as SellercraftResolvers } from './sellercraft'
6
+ import { entities as MarketplaceChannelEntities, resolvers as MarketplaceSellercraftResolvers } from './marketplace-channel'
6
7
 
7
8
  export const entities = [
8
9
  /* ENTITIES */
9
10
  ...SellercraftEntities,
11
+ ...MarketplaceChannelEntities
10
12
  ]
11
13
 
12
14
 
@@ -14,5 +16,8 @@ export const schema = {
14
16
  resolverClasses: [
15
17
  /* RESOLVER CLASSES */
16
18
  ...SellercraftResolvers,
17
- ]
19
+ ...MarketplaceSellercraftResolvers
20
+ ]
18
21
  }
22
+
23
+ export { MarketplaceSellercraftResolvers }