@things-factory/integration-sellercraft 5.0.0-alpha.4 → 5.0.0-alpha.42

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 (48) 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 +28 -0
  4. package/dist-server/constants/order-status-mapping.js.map +1 -0
  5. package/dist-server/constants/platform.js +3 -1
  6. package/dist-server/constants/platform.js.map +1 -1
  7. package/dist-server/controllers/index.js +2 -0
  8. package/dist-server/controllers/index.js.map +1 -1
  9. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.js +19 -20
  10. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.js.map +1 -1
  11. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.js +5 -2
  12. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.js.map +1 -1
  13. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js +29 -19
  14. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js.map +1 -1
  15. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js +24 -40
  16. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js.map +1 -1
  17. package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js +9 -5
  18. package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js.map +1 -1
  19. package/dist-server/routers/sellercraft-router.js +220 -84
  20. package/dist-server/routers/sellercraft-router.js.map +1 -1
  21. package/dist-server/service/index.js +5 -1
  22. package/dist-server/service/index.js.map +1 -1
  23. package/dist-server/service/marketplace-channel/index.js +9 -0
  24. package/dist-server/service/marketplace-channel/index.js.map +1 -0
  25. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +364 -0
  26. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js.map +1 -0
  27. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js +207 -0
  28. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -0
  29. package/dist-server/service/marketplace-channel/marketplace-channel.js +88 -0
  30. package/dist-server/service/marketplace-channel/marketplace-channel.js.map +1 -0
  31. package/dist-server/service/sellercraft/sellercraft.js +1 -1
  32. package/package.json +15 -15
  33. package/server/constants/index.ts +2 -1
  34. package/server/constants/order-status-mapping.ts +25 -0
  35. package/server/constants/platform.ts +3 -1
  36. package/server/controllers/index.ts +2 -0
  37. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.ts +19 -20
  38. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.ts +6 -2
  39. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +30 -19
  40. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.ts +32 -47
  41. package/server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.ts +9 -5
  42. package/server/routers/sellercraft-router.ts +225 -87
  43. package/server/service/index.ts +6 -1
  44. package/server/service/marketplace-channel/index.ts +6 -0
  45. package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +412 -0
  46. package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +218 -0
  47. package/server/service/marketplace-channel/marketplace-channel.ts +68 -0
  48. package/server/service/sellercraft/sellercraft.ts +1 -1
@@ -0,0 +1,364 @@
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 env_1 = require("@things-factory/env");
19
+ const integration_marketplace_1 = require("@things-factory/integration-marketplace");
20
+ const constants_1 = require("../../constants");
21
+ const sellercraft_channel_integration_api_1 = require("../../controllers/sellercraft-channel-integration-api");
22
+ const marketplace_channel_1 = require("./marketplace-channel");
23
+ let MarketplaceChannelOrderMutation = class MarketplaceChannelOrderMutation {
24
+ async syncAllMarketplaceChannelOrders(fromDate, toDate, context) {
25
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
26
+ const sellercraftChannelIntegrationConfig = env_1.config.get('sellercraftChannelIntegrationConfig', {});
27
+ const { tokenCraftApiKey: apiKey, getShopsTokenCraftUrl } = sellercraftChannelIntegrationConfig;
28
+ const channels = await (0, typeorm_1.getRepository)(marketplace_channel_1.MarketplaceChannel).find({ where: { isActive: true } });
29
+ for (var i = 0; i < channels.length; i++) {
30
+ try {
31
+ const channel = channels[i];
32
+ var channelsFullPath = getShopsTokenCraftUrl + '?channel_id=' + channel.channelId;
33
+ const channelResponse = await fetch(channelsFullPath, {
34
+ method: 'get',
35
+ headers: {
36
+ 'Content-Type': 'application/json',
37
+ 'x-api-key': apiKey
38
+ }
39
+ });
40
+ if (!channelResponse.ok) {
41
+ throw new Error(channelResponse);
42
+ }
43
+ var shopsResponse = await channelResponse.json();
44
+ var shops = shopsResponse.shops;
45
+ for (var j = 0; j < shops.length; j++) {
46
+ try {
47
+ var store = {
48
+ accessKey: ((_b = (_a = shops[j]) === null || _a === void 0 ? void 0 : _a.credential) === null || _b === void 0 ? void 0 : _b.consumer_key) || '',
49
+ accessSecret: ((_d = (_c = shops[j]) === null || _c === void 0 ? void 0 : _c.credential) === null || _d === void 0 ? void 0 : _d.consumer_secret) || '',
50
+ storeURL: ((_f = (_e = shops[j]) === null || _e === void 0 ? void 0 : _e.credential) === null || _f === void 0 ? void 0 : _f.store_url) || '',
51
+ platform: channel.name,
52
+ accessToken: (_h = (_g = shops[j]) === null || _g === void 0 ? void 0 : _g.credential) === null || _h === void 0 ? void 0 : _h.access_token,
53
+ channelShopId: (_j = shops[j]) === null || _j === void 0 ? void 0 : _j.channel_shop_id
54
+ };
55
+ // let countryCode = shops[j].country_code
56
+ // let channelCode = shops[j].org_prefix
57
+ let organisationId = shops[j].account_id;
58
+ let channelShopId = shops[j].channel_shop_id;
59
+ let orderResult = [];
60
+ let page = store.platform == 'magento' ? 1 : 0;
61
+ let hasMorePage = true;
62
+ let lastOrderId;
63
+ let cursor;
64
+ var limit = 50;
65
+ while (hasMorePage) {
66
+ const { results: marketplaceOrders, more, nextCursor } = await integration_marketplace_1.StoreAPI.getStoreOrders(store, {
67
+ fromDate,
68
+ toDate,
69
+ pagination: { page, limit },
70
+ lastOrderId,
71
+ nextCursor: cursor
72
+ });
73
+ orderResult.push(...marketplaceOrders);
74
+ if (more)
75
+ page++;
76
+ hasMorePage = more;
77
+ cursor = nextCursor;
78
+ }
79
+ var sellercraftStore = Object.assign(Object.assign({}, store), { platform: 'sellercraftChannelIntegration' });
80
+ let mappedOrderResult = orderResult.map(order => {
81
+ let id = store.platform == 'magento' ? order.name : order.orderNo;
82
+ let { firstName: custFirstName, lastName: custLastName, orderCreatedAt: createdAt, orderUpdatedAt: updatedAt, status, isSOF } = order;
83
+ 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;
84
+ 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;
85
+ let orderPackage = (order === null || order === void 0 ? void 0 : order.orderPackage) || {};
86
+ let orderItems = order.orderItems.map(item => {
87
+ let { name: id, variationId: variationId, slaExpiresAt, total, totalTax, subtotal, subtotalTax, qty } = item;
88
+ return {
89
+ id,
90
+ variationId,
91
+ currency: order.orderShipping.collectionCurrency,
92
+ createdAt: order.orderCreatedAt,
93
+ updatedAt: order.orderUpdatedAt,
94
+ charges: [
95
+ {
96
+ name: 'CHARGES_MARKETING',
97
+ grossAmount: 0,
98
+ nettAmount: 0
99
+ },
100
+ {
101
+ name: 'CLAIMS_DAMAGE',
102
+ grossAmount: 0,
103
+ nettAmount: 0
104
+ },
105
+ {
106
+ name: 'CLAIMS_LOST',
107
+ grossAmount: 0,
108
+ nettAmount: 0
109
+ },
110
+ {
111
+ name: 'COMMISSION_PLATFORM',
112
+ grossAmount: 0,
113
+ nettAmount: 0
114
+ },
115
+ {
116
+ name: 'DEPOSIT_PRESALE',
117
+ grossAmount: 0,
118
+ nettAmount: 0
119
+ },
120
+ {
121
+ name: 'FEE_MISCELLANEOUS',
122
+ grossAmount: 0,
123
+ nettAmount: 0
124
+ },
125
+ {
126
+ name: 'FEE_TRANSACTION',
127
+ grossAmount: 0,
128
+ nettAmount: 0
129
+ },
130
+ {
131
+ name: 'PRICE_NORMAL_SELLING',
132
+ grossAmount: total,
133
+ nettAmount: subtotal
134
+ },
135
+ {
136
+ name: 'PRICE_RECOMMENDED_RETAIL',
137
+ grossAmount: 0,
138
+ nettAmount: 0
139
+ },
140
+ {
141
+ name: 'PROMOTIONS_CUSTOMER_RECEIVED',
142
+ grossAmount: 0,
143
+ nettAmount: 0
144
+ },
145
+ {
146
+ name: 'PROMOTIONS_REBATE_PLATFORM',
147
+ grossAmount: 0,
148
+ nettAmount: 0
149
+ },
150
+ {
151
+ name: 'PROMOTIONS_REBATE_SELLER',
152
+ grossAmount: 0,
153
+ nettAmount: 0
154
+ },
155
+ {
156
+ name: 'REVERSAL_CHARGES_MARKETING',
157
+ grossAmount: 0,
158
+ nettAmount: 0
159
+ },
160
+ {
161
+ name: 'REVERSAL_COMMISSION',
162
+ grossAmount: 0,
163
+ nettAmount: 0
164
+ },
165
+ {
166
+ name: 'REVERSAL_FEE_MISCELLANEOUS',
167
+ grossAmount: 0,
168
+ nettAmount: 0
169
+ },
170
+ {
171
+ name: 'REVERSAL_PROMOTIONS_CUSTOMER_RECEIVED',
172
+ grossAmount: 0,
173
+ nettAmount: 0
174
+ },
175
+ {
176
+ name: 'REVERSAL_SELLER_RETURN_REFUND_AMOUNT',
177
+ grossAmount: 0,
178
+ nettAmount: 0
179
+ },
180
+ {
181
+ name: 'REVERSAL_SHIPPING_CUSTOMER_PAID',
182
+ grossAmount: 0,
183
+ nettAmount: 0
184
+ },
185
+ {
186
+ name: 'REVERSAL_SHIPPING_REBATE_PLATFORM',
187
+ grossAmount: 0,
188
+ nettAmount: 0
189
+ },
190
+ {
191
+ name: 'REVERSAL_SHIPPING_SELLER_PAID',
192
+ grossAmount: 0,
193
+ nettAmount: 0
194
+ },
195
+ {
196
+ name: 'SHIPPING_COST_TOTAL',
197
+ grossAmount: 0,
198
+ nettAmount: 0
199
+ },
200
+ {
201
+ name: 'SHIPPING_CUSTOMER_PAID',
202
+ grossAmount: 0,
203
+ nettAmount: 0
204
+ },
205
+ {
206
+ name: 'SHIPPING_REBATE_PLATFORM',
207
+ grossAmount: 0,
208
+ nettAmount: 0
209
+ },
210
+ {
211
+ name: 'SHIPPING_SELLER_PAID',
212
+ grossAmount: 0,
213
+ nettAmount: 0
214
+ },
215
+ {
216
+ name: 'TAXES',
217
+ grossAmount: totalTax,
218
+ nettAmount: subtotalTax
219
+ },
220
+ {
221
+ name: 'VOUCHERS_CUSTOMER_RECEIVED',
222
+ grossAmount: 0,
223
+ nettAmount: 0
224
+ },
225
+ {
226
+ name: 'VOUCHERS_REBATE_PLATFORM',
227
+ grossAmount: 0,
228
+ nettAmount: 0
229
+ },
230
+ {
231
+ name: 'VOUCHERS_REBATE_SELLER',
232
+ grossAmount: 0,
233
+ nettAmount: 0
234
+ }
235
+ ],
236
+ slaExpiresAt,
237
+ qty
238
+ };
239
+ });
240
+ let mappedOrderItems = [];
241
+ orderItems.map(oi => {
242
+ for (let i = 0; i < oi.qty; i++) {
243
+ mappedOrderItems.push(Object.assign(Object.assign({}, oi), { id: `${oi.id}-${i + 1}` }));
244
+ }
245
+ });
246
+ return {
247
+ custFirstName,
248
+ custLastName,
249
+ createdAt,
250
+ updatedAt,
251
+ id,
252
+ billFirstName,
253
+ billLastName,
254
+ billAddress1: billAddress1.toString() || shipAddress1.toString(),
255
+ billAddress2: billAddress2 || shipAddress2,
256
+ billAddress3: billAddress3 || shipAddress3,
257
+ billAddress4: billAddress4 || shipAddress4,
258
+ billAddress5: billAddress5 || shipAddress5,
259
+ billCity: billCity || shipCity,
260
+ billPostalCode: billPostalCode || shipPostalCode,
261
+ billCountry: billCountry || shipCountry,
262
+ billPhone1: billPhone1 || shipPhone1,
263
+ billPhone2: billPhone2 || shipPhone2,
264
+ shipFirstName,
265
+ shipLastName,
266
+ shipAddress1: shipAddress1.toString(),
267
+ shipAddress2,
268
+ shipAddress3,
269
+ shipAddress4,
270
+ shipAddress5,
271
+ shipCity,
272
+ shipPostalCode,
273
+ shipCountry,
274
+ shipPhone1,
275
+ shipPhone2,
276
+ mappedOrderItems,
277
+ channelShopId,
278
+ organisationId,
279
+ status,
280
+ isSOF: isSOF ? isSOF : false,
281
+ orderPackage,
282
+ charges: getOrderCharges(mappedOrderItems)
283
+ };
284
+ });
285
+ if (mappedOrderResult.length > 0) {
286
+ await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelOrder(sellercraftStore, {
287
+ orders: mappedOrderResult
288
+ });
289
+ await Promise.all(mappedOrderResult.map(async (result) => {
290
+ var _a;
291
+ if (!(result === null || result === void 0 ? void 0 : result.isSOF) && ((_a = result === null || result === void 0 ? void 0 : result.orderPackage) === null || _a === void 0 ? void 0 : _a.packageId)) {
292
+ let orderPackage = result.orderPackage;
293
+ let newOrderPackage = {
294
+ channelShopId,
295
+ nativeOrderId: result.id,
296
+ nativePackageId: orderPackage.packageId,
297
+ shippingTrackingCode: orderPackage.trackingNumber,
298
+ shippingTypeValue: (orderPackage === null || orderPackage === void 0 ? void 0 : orderPackage.shippingType)
299
+ ? orderPackage.shippingType
300
+ : constants_1.SHIPPING_TYPE.DROP_SHIPPING,
301
+ warehouseCode: constants_1.SHIPPING_TYPE.DROP_SHIPPING,
302
+ shipper: {
303
+ name: orderPackage.shippingProvider,
304
+ isCodSupported: (orderPackage === null || orderPackage === void 0 ? void 0 : orderPackage.isCodSupport) ? orderPackage.isCodSupport : false
305
+ },
306
+ documents: (orderPackage === null || orderPackage === void 0 ? void 0 : orderPackage.orderDocument) || [],
307
+ shipperLastMile: {
308
+ name: orderPackage.shippingProvider,
309
+ isCodSupported: (orderPackage === null || orderPackage === void 0 ? void 0 : orderPackage.isCodSupport) ? orderPackage.isCodSupport : false
310
+ },
311
+ orderItemIds: (orderPackage === null || orderPackage === void 0 ? void 0 : orderPackage.orderListIdList)
312
+ ? orderPackage.orderListIdList
313
+ : result.mappedOrderItems.map(orderItem => orderItem.id)
314
+ };
315
+ await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelOrderPackage(sellercraftStore, newOrderPackage);
316
+ }
317
+ }));
318
+ }
319
+ }
320
+ catch (e) { }
321
+ }
322
+ }
323
+ catch (e) { }
324
+ }
325
+ return true;
326
+ }
327
+ };
328
+ __decorate([
329
+ (0, type_graphql_1.Mutation)(returns => Boolean),
330
+ __param(0, (0, type_graphql_1.Arg)('fromDate')),
331
+ __param(1, (0, type_graphql_1.Arg)('toDate')),
332
+ __param(2, (0, type_graphql_1.Ctx)()),
333
+ __metadata("design:type", Function),
334
+ __metadata("design:paramtypes", [String, String, Object]),
335
+ __metadata("design:returntype", Promise)
336
+ ], MarketplaceChannelOrderMutation.prototype, "syncAllMarketplaceChannelOrders", null);
337
+ MarketplaceChannelOrderMutation = __decorate([
338
+ (0, type_graphql_1.Resolver)()
339
+ ], MarketplaceChannelOrderMutation);
340
+ exports.MarketplaceChannelOrderMutation = MarketplaceChannelOrderMutation;
341
+ function getOrderCharges(mappedOrderItems) {
342
+ let chargesList = [];
343
+ for (let i = 0; i < mappedOrderItems.length; i++) {
344
+ for (let j = 0; j < mappedOrderItems[i].charges.length; j++) {
345
+ let charge = mappedOrderItems[i].charges[j];
346
+ let foundCharge = chargesList.find(cl => cl.name == charge.name);
347
+ if (foundCharge) {
348
+ foundCharge.grossAmount = parseFloat(foundCharge.grossAmount) + parseFloat(charge.grossAmount);
349
+ foundCharge.nettAmount = parseFloat(foundCharge.nettAmount) + parseFloat(charge.nettAmount);
350
+ chargesList = chargesList.filter(cl => cl.name != charge.name);
351
+ }
352
+ else {
353
+ foundCharge = {
354
+ name: charge.name,
355
+ grossAmount: charge.grossAmount,
356
+ nettAmount: charge.nettAmount
357
+ };
358
+ }
359
+ chargesList.push(foundCharge);
360
+ }
361
+ }
362
+ return chargesList;
363
+ }
364
+ //# 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,6CAA4C;AAC5C,qFAAkE;AAElE,+CAA+C;AAC/C,+GAAwG;AACxG,+DAA0D;AAG1D,IAAa,+BAA+B,GAA5C,MAAa,+BAA+B;IAE1C,KAAK,CAAC,+BAA+B,CAClB,QAAgB,EAClB,MAAc,EACtB,OAAY;;QAEnB,MAAM,mCAAmC,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AO,WAAW,CAAA;AACpB,CAAC"}
@@ -0,0 +1,207 @@
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 env_1 = require("@things-factory/env");
19
+ const integration_marketplace_1 = require("@things-factory/integration-marketplace");
20
+ const sellercraft_channel_integration_api_1 = require("../../controllers/sellercraft-channel-integration-api");
21
+ const marketplace_channel_1 = require("./marketplace-channel");
22
+ let MarketplaceChannelProductMutation = class MarketplaceChannelProductMutation {
23
+ async syncAllMarketplaceChannelProducts(context) {
24
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
25
+ const sellercraftChannelIntegrationConfig = env_1.config.get('sellercraftChannelIntegrationConfig', {});
26
+ const { tokenCraftApiKey: apiKey, getShopsTokenCraftUrl } = sellercraftChannelIntegrationConfig;
27
+ const channels = await (0, typeorm_1.getRepository)(marketplace_channel_1.MarketplaceChannel).find({ where: { isActive: true } });
28
+ for (var i = 0; i < channels.length; i++) {
29
+ var channelsFullPath = getShopsTokenCraftUrl + '?channel_id=' + channels[i].channelId;
30
+ const channelResponse = await fetch(channelsFullPath, {
31
+ method: 'get',
32
+ headers: {
33
+ 'Content-Type': 'application/json',
34
+ 'x-api-key': apiKey
35
+ }
36
+ });
37
+ if (!channelResponse.ok) {
38
+ throw new Error(channelResponse);
39
+ }
40
+ var shopsResponse = await channelResponse.json();
41
+ var shops = shopsResponse.shops;
42
+ for (var j = 0; j < shops.length; j++) {
43
+ var store = {
44
+ accessKey: ((_b = (_a = shops[j]) === null || _a === void 0 ? void 0 : _a.credential) === null || _b === void 0 ? void 0 : _b.consumer_key) || '',
45
+ accessSecret: ((_d = (_c = shops[j]) === null || _c === void 0 ? void 0 : _c.credential) === null || _d === void 0 ? void 0 : _d.consumer_secret) || '',
46
+ storeURL: ((_f = (_e = shops[j]) === null || _e === void 0 ? void 0 : _e.credential) === null || _f === void 0 ? void 0 : _f.store_url) || '',
47
+ platform: channels[i].name,
48
+ accessToken: (_h = (_g = shops[j]) === null || _g === void 0 ? void 0 : _g.credential) === null || _h === void 0 ? void 0 : _h.access_token,
49
+ channelShopId: (_j = shops[j]) === null || _j === void 0 ? void 0 : _j.channel_shop_id
50
+ };
51
+ let countryCode = shops[j].country_code;
52
+ let channelCode = shops[j].org_prefix;
53
+ let organisationId = shops[j].account_id;
54
+ let channelShopId = shops[j].channel_shop_id;
55
+ var sellercraftStore = Object.assign(Object.assign({}, store), { platform: 'sellercraftChannelIntegration' });
56
+ const productResult = [];
57
+ let totalPages = 1;
58
+ let limit = 50;
59
+ let parentLinks = [];
60
+ for (let page = 0; page < totalPages; page++) {
61
+ const { results, total, parentLinkList } = await integration_marketplace_1.StoreAPI.getStoreProducts(store, {
62
+ pagination: { page, limit }
63
+ });
64
+ totalPages = Math.ceil(total / limit);
65
+ productResult.push(...results);
66
+ if (store.platform == 'magento')
67
+ parentLinks.push(...parentLinkList);
68
+ }
69
+ const categoryResult = [];
70
+ let totalPagesCategory = 1;
71
+ let limitCategory = 100;
72
+ for (let page = 0; page < totalPagesCategory; page++) {
73
+ const { results, total } = await integration_marketplace_1.StoreAPI.getStoreProductCategories(store, {
74
+ pagination: { page, limitCategory }
75
+ });
76
+ totalPagesCategory = Math.ceil(total / limitCategory);
77
+ categoryResult.push(...results);
78
+ }
79
+ let mappedProducts = productResult.map(item => {
80
+ var _a;
81
+ let { categoryId, itemId: productId, name, brand, isVerified, images, attributes, variations } = item;
82
+ variations = variations.map(variation => {
83
+ let { variationSku, variationId, name, isEnabled: isEnabled, isSellable: isSellable, attributes, stockLocked, qty: stockReported, costPrice: fullPrice, sellPrice: priceDiscounted, length, width, height, weight } = variation;
84
+ return {
85
+ variationSku,
86
+ variationId,
87
+ name,
88
+ isEnabled,
89
+ isSellable,
90
+ attributes,
91
+ stockLocked,
92
+ stockReported,
93
+ fullPrice,
94
+ priceDiscounted,
95
+ inventoryProducts: [
96
+ {
97
+ qty: 1,
98
+ name: `${name} - ${variationSku}`,
99
+ sku: variationSku,
100
+ productVersions: [
101
+ {
102
+ label: 'Default',
103
+ packageLengthMM: length,
104
+ packageWidthMM: width,
105
+ packageHeightMM: height,
106
+ packageWeightGram: weight,
107
+ qty: stockReported
108
+ }
109
+ ]
110
+ }
111
+ ]
112
+ };
113
+ });
114
+ images = images === null || images === void 0 ? void 0 : images.map(image => {
115
+ return {
116
+ url: image
117
+ };
118
+ });
119
+ return {
120
+ organisationId,
121
+ channelShopId: channelShopId,
122
+ channelCode: channels[i].channelCode,
123
+ channelCountry: shops[j].country_code,
124
+ categoryId,
125
+ productId: ((_a = parentLinks.find(e => e.children.includes(productId))) === null || _a === void 0 ? void 0 : _a.id) || productId,
126
+ name,
127
+ brand,
128
+ isVerified,
129
+ images,
130
+ attributes,
131
+ variations
132
+ };
133
+ });
134
+ let mappedCategories = categoryResult.map(category => {
135
+ let { id: categoryId, name: categoryName, parent, isActive } = category;
136
+ return {
137
+ categoryId,
138
+ categoryName,
139
+ parent,
140
+ isActive: isActive || true,
141
+ channelCode,
142
+ countryCode,
143
+ childrenCategories: []
144
+ };
145
+ });
146
+ if (store.platform == 'magento') {
147
+ let newList = [];
148
+ for (let np of mappedProducts) {
149
+ if (np.productId == np.variations[0].variationId) {
150
+ let vars = mappedProducts
151
+ .filter(e => e.productId == np.productId)
152
+ .map(e => {
153
+ return e.variations[0];
154
+ });
155
+ np.variations = vars;
156
+ if (np.variations.length > 1) {
157
+ np.variations = np.variations.filter(v => v.variationId != np.productId);
158
+ }
159
+ newList.push(np);
160
+ }
161
+ }
162
+ mappedProducts = newList;
163
+ }
164
+ try {
165
+ let filterList = [];
166
+ mappedCategories = mappedCategories.map(category => {
167
+ if (mappedCategories.filter(e => e.parent == category.categoryId).length > 0) {
168
+ category.childrenCategories = mappedCategories.filter(e => e.parent == category.categoryId);
169
+ filterList.push(...mappedCategories.filter(e => e.parent == category.categoryId));
170
+ }
171
+ return category;
172
+ });
173
+ mappedCategories = mappedCategories.map(mc => {
174
+ if (filterList.indexOf(mc) == -1) {
175
+ return mc;
176
+ }
177
+ }).filter(e => e);
178
+ await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelCategories(sellercraftStore, {
179
+ categories: mappedCategories
180
+ });
181
+ }
182
+ catch (e) { }
183
+ try {
184
+ for (let k = 0, l = mappedProducts.length; k < l; k++) {
185
+ await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelProduct(sellercraftStore, {
186
+ products: [mappedProducts[k]]
187
+ });
188
+ }
189
+ }
190
+ catch (e) { }
191
+ }
192
+ }
193
+ return true;
194
+ }
195
+ };
196
+ __decorate([
197
+ (0, type_graphql_1.Mutation)(returns => Boolean),
198
+ __param(0, (0, type_graphql_1.Ctx)()),
199
+ __metadata("design:type", Function),
200
+ __metadata("design:paramtypes", [Object]),
201
+ __metadata("design:returntype", Promise)
202
+ ], MarketplaceChannelProductMutation.prototype, "syncAllMarketplaceChannelProducts", null);
203
+ MarketplaceChannelProductMutation = __decorate([
204
+ (0, type_graphql_1.Resolver)()
205
+ ], MarketplaceChannelProductMutation);
206
+ exports.MarketplaceChannelProductMutation = MarketplaceChannelProductMutation;
207
+ //# 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,6CAA4C;AAC5C,qFAAkE;AAElE,+GAAwG;AACxG,+DAA0D;AAG1D,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,CAAC,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;QAElH,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;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