idosell 0.4.32 → 0.4.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +16 -0
- package/dist/enums.d.ts +175 -0
- package/dist/enums.js +175 -0
- package/dist/gates.js +1 -1
- package/dist/gateways.d.ts +42 -43
- package/dist/methods/getProductsAttachmentsGetContent.js +1 -0
- package/dist/methods/searchProductsCategoriesIdosell.js +1 -2
- package/dist/reqparams.d.ts +241 -206
- package/dist/request.js +1 -1
- package/dist/responses.d.ts +377 -54
- package/dist/utils.d.ts +12 -0
- package/dist/utils.js +20 -1
- package/package.json +2 -2
- package/tests/utilMapProductParameters.test.js +97 -0
- package/tests/utilTestData.ts +238 -1
package/dist/utils.d.ts
CHANGED
|
@@ -11,6 +11,16 @@ type GetLangDataFunction = <T extends {
|
|
|
11
11
|
langId: string;
|
|
12
12
|
}>(_array: T[], _langId?: string) => T | undefined;
|
|
13
13
|
type ClearParametersLangDataFunction = (_products: SearchProductsResponse['results'], _langId?: string) => SearchProductsResponse['results'];
|
|
14
|
+
type MappedParameterValue = {
|
|
15
|
+
valueId: number;
|
|
16
|
+
value: string;
|
|
17
|
+
};
|
|
18
|
+
type MappedParameter = {
|
|
19
|
+
id: number;
|
|
20
|
+
name: string;
|
|
21
|
+
values: MappedParameterValue[];
|
|
22
|
+
};
|
|
23
|
+
type MapProductParametersFunction = (_product: IdosellProduct, _langId?: string) => MappedParameter[];
|
|
14
24
|
declare const _default: {
|
|
15
25
|
/** @description The method allows you to build an IAI code from the product ID and size ID. */
|
|
16
26
|
getIaiCode: GetIaICodeFunction;
|
|
@@ -30,5 +40,7 @@ declare const _default: {
|
|
|
30
40
|
clearParametersLangData: ClearParametersLangDataFunction;
|
|
31
41
|
/** @description Removes attachments to RMA that are returned by default, helps to reduce data if serialized or forwarded */
|
|
32
42
|
removeRmaAttachments: (rmaResponse: GetRmaResponse) => GetRmaResponse;
|
|
43
|
+
/** @description Maps product parameters to a simplified structure for a given language. Skips parameters with no values. */
|
|
44
|
+
mapProductParameters: MapProductParametersFunction;
|
|
33
45
|
};
|
|
34
46
|
export default _default;
|
package/dist/utils.js
CHANGED
|
@@ -269,6 +269,23 @@ const removeRmaAttachments = (rmaResponse) => {
|
|
|
269
269
|
}
|
|
270
270
|
return rmaResponse;
|
|
271
271
|
};
|
|
272
|
+
const mapProductParameters = (product, langId = 'pol') => {
|
|
273
|
+
if (!product.productParameters)
|
|
274
|
+
return [];
|
|
275
|
+
return product.productParameters.reduce((acc, param) => {
|
|
276
|
+
if (!param.parameterValues?.length)
|
|
277
|
+
return acc;
|
|
278
|
+
const name = param.parameterDescriptionsLangData.find((l) => l.langId === langId)?.parameterName ?? '';
|
|
279
|
+
const values = param.parameterValues.reduce((valAcc, pv) => {
|
|
280
|
+
const value = pv.parameterValueDescriptionsLangData.find((l) => l.langId === langId)
|
|
281
|
+
?.parameterValueName ?? '';
|
|
282
|
+
valAcc.push({ valueId: pv.parameterValueId, value });
|
|
283
|
+
return valAcc;
|
|
284
|
+
}, []);
|
|
285
|
+
acc.push({ id: param.parameterId, name, values });
|
|
286
|
+
return acc;
|
|
287
|
+
}, []);
|
|
288
|
+
};
|
|
272
289
|
export default {
|
|
273
290
|
/** @description The method allows you to build an IAI code from the product ID and size ID. */
|
|
274
291
|
getIaiCode,
|
|
@@ -287,5 +304,7 @@ export default {
|
|
|
287
304
|
/** @description Modifies product response by removing all parameter names nad values that are not in selected langId */
|
|
288
305
|
clearParametersLangData,
|
|
289
306
|
/** @description Removes attachments to RMA that are returned by default, helps to reduce data if serialized or forwarded */
|
|
290
|
-
removeRmaAttachments
|
|
307
|
+
removeRmaAttachments,
|
|
308
|
+
/** @description Maps product parameters to a simplified structure for a given language. Skips parameters with no values. */
|
|
309
|
+
mapProductParameters,
|
|
291
310
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "idosell",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.38",
|
|
4
4
|
"description": "Idosell 3 REST connector",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/gateways.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://idosell-converter.vercel.app",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"axios": "^1.
|
|
26
|
+
"axios": "^1.17.0"
|
|
27
27
|
},
|
|
28
28
|
"type": "module"
|
|
29
29
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { utils } from '../dist/index';
|
|
2
|
+
import { PARAMETER_PRODUCT, PARAMETER_PRODUCT_RESULT } from './utilTestData';
|
|
3
|
+
|
|
4
|
+
// mapProductParameters.test.ts
|
|
5
|
+
import { describe, it, expect } from 'vitest';
|
|
6
|
+
|
|
7
|
+
const makeLangData = (langId, name) => ({
|
|
8
|
+
langId,
|
|
9
|
+
parameterName: name,
|
|
10
|
+
parameterDescription: '',
|
|
11
|
+
parameterShopsData: [],
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const makeValueLangData = (langId, valueName) => ({
|
|
15
|
+
langId,
|
|
16
|
+
parameterValueName: valueName,
|
|
17
|
+
parameterValueDescription: '',
|
|
18
|
+
parameterValueShopsData: [],
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const makeParam = (id, name, values, langId = 'pol') => ({
|
|
22
|
+
parameterId: id,
|
|
23
|
+
parameterType: 'parameter',
|
|
24
|
+
parameterDescriptionsLangData: [makeLangData(langId, name)],
|
|
25
|
+
parameterValues: values.map((v) => ({
|
|
26
|
+
parameterValueId: v.id,
|
|
27
|
+
parameterValueDescriptionsLangData: [makeValueLangData(langId, v.name)],
|
|
28
|
+
})),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('mapProductParameters', () => {
|
|
32
|
+
it('returns [] when productParameters is undefined', () => {
|
|
33
|
+
expect(utils.mapProductParameters({})).toEqual([]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('returns [] when productParameters is empty', () => {
|
|
37
|
+
expect(utils.mapProductParameters({ productParameters: [] })).toEqual([]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('skips parameters with null parameterValues', () => {
|
|
41
|
+
const product = {
|
|
42
|
+
productParameters: [
|
|
43
|
+
{ ...makeParam(1, 'Color', [{ id: 10, name: 'Red' }]), parameterValues: null },
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
expect(utils.mapProductParameters(product)).toEqual([]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('skips parameters with empty parameterValues', () => {
|
|
50
|
+
const product = {
|
|
51
|
+
productParameters: [{ ...makeParam(1, 'Color', []), parameterValues: [] }],
|
|
52
|
+
};
|
|
53
|
+
expect(utils.mapProductParameters(product)).toEqual([]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('maps a single parameter with values using default lang (pol)', () => {
|
|
57
|
+
const product = {
|
|
58
|
+
productParameters: [makeParam(1, 'Color', [{ id: 10, name: 'Red' }])],
|
|
59
|
+
};
|
|
60
|
+
expect(utils.mapProductParameters(product)).toEqual([
|
|
61
|
+
{ id: 1, name: 'Color', values: [{ valueId: 10, value: 'Red' }] },
|
|
62
|
+
]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('maps multiple parameters and multiple values', () => {
|
|
66
|
+
const product = {
|
|
67
|
+
productParameters: [
|
|
68
|
+
makeParam(1, 'Color', [{ id: 10, name: 'Red' }, { id: 11, name: 'Blue' }]),
|
|
69
|
+
makeParam(2, 'Size', [{ id: 20, name: 'M' }, { id: 21, name: 'L' }]),
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
expect(utils.mapProductParameters(product)).toEqual([
|
|
73
|
+
{ id: 1, name: 'Color', values: [{ valueId: 10, value: 'Red' }, { valueId: 11, value: 'Blue' }] },
|
|
74
|
+
{ id: 2, name: 'Size', values: [{ valueId: 20, value: 'M' }, { valueId: 21, value: 'L' }] },
|
|
75
|
+
]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('uses provided langId instead of default', () => {
|
|
79
|
+
const product = {
|
|
80
|
+
productParameters: [makeParam(1, 'Kolor', [{ id: 10, name: 'Czerwony' }], 'eng')],
|
|
81
|
+
};
|
|
82
|
+
expect(utils.mapProductParameters(product, 'eng')).toEqual([
|
|
83
|
+
{ id: 1, name: 'Kolor', values: [{ valueId: 10, value: 'Czerwony' }] },
|
|
84
|
+
]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('falls back to empty string when langId has no matching entry', () => {
|
|
88
|
+
const product = {
|
|
89
|
+
productParameters: [makeParam(1, 'Color', [{ id: 10, name: 'Red' }], 'pol')],
|
|
90
|
+
};
|
|
91
|
+
expect(utils.mapProductParameters(product, 'deu')).toEqual([
|
|
92
|
+
{ id: 1, name: '', values: [{ valueId: 10, value: '' }] },
|
|
93
|
+
]);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
expect(utils.mapProductParameters(PARAMETER_PRODUCT)).toEqual(PARAMETER_PRODUCT_RESULT)
|
|
97
|
+
});
|
package/tests/utilTestData.ts
CHANGED
|
@@ -341,4 +341,241 @@ export const STOCK_PRODUCT: SearchProductsResponse['results'][number] = {
|
|
|
341
341
|
"sizePanelName": "XL"
|
|
342
342
|
}
|
|
343
343
|
]
|
|
344
|
-
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export const PARAMETER_PRODUCT: SearchProductsResponse['results'][number] = {
|
|
347
|
+
"productId": 356,
|
|
348
|
+
"productParameters": [
|
|
349
|
+
{
|
|
350
|
+
"parameterId": 326,
|
|
351
|
+
"parameterType": "parameter",
|
|
352
|
+
"parameterDescriptionsLangData": [
|
|
353
|
+
{
|
|
354
|
+
"langId": "eng",
|
|
355
|
+
"parameterName": "Kolor akcentów",
|
|
356
|
+
"parameterDescription": "",
|
|
357
|
+
"parameterShopsData": []
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
"langId": "ger",
|
|
361
|
+
"parameterName": "Kolor akcentów",
|
|
362
|
+
"parameterDescription": "",
|
|
363
|
+
"parameterShopsData": []
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
"langId": "pol",
|
|
367
|
+
"parameterName": "Kolor akcentów",
|
|
368
|
+
"parameterDescription": "",
|
|
369
|
+
"parameterShopsData": []
|
|
370
|
+
}
|
|
371
|
+
],
|
|
372
|
+
"parameterValues": [
|
|
373
|
+
{
|
|
374
|
+
"parameterValueId": 399,
|
|
375
|
+
"parameterValueDescriptionsLangData": [
|
|
376
|
+
{
|
|
377
|
+
"langId": "eng",
|
|
378
|
+
"parameterValueName": "Czarny",
|
|
379
|
+
"parameterValueDescription": "",
|
|
380
|
+
"parameterValueShopsData": []
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
"langId": "ger",
|
|
384
|
+
"parameterValueName": "Czarny",
|
|
385
|
+
"parameterValueDescription": "",
|
|
386
|
+
"parameterValueShopsData": []
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
"langId": "pol",
|
|
390
|
+
"parameterValueName": "Czarny",
|
|
391
|
+
"parameterValueDescription": "",
|
|
392
|
+
"parameterValueShopsData": []
|
|
393
|
+
}
|
|
394
|
+
]
|
|
395
|
+
}
|
|
396
|
+
]
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
"parameterId": 173,
|
|
400
|
+
"parameterType": "parameter",
|
|
401
|
+
"parameterDescriptionsLangData": [
|
|
402
|
+
{
|
|
403
|
+
"langId": "eng",
|
|
404
|
+
"parameterName": "Waga całkowita",
|
|
405
|
+
"parameterDescription": "",
|
|
406
|
+
"parameterShopsData": []
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
"langId": "ger",
|
|
410
|
+
"parameterName": "Waga całkowita",
|
|
411
|
+
"parameterDescription": "",
|
|
412
|
+
"parameterShopsData": []
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
"langId": "pol",
|
|
416
|
+
"parameterName": "Waga całkowita",
|
|
417
|
+
"parameterDescription": "",
|
|
418
|
+
"parameterShopsData": []
|
|
419
|
+
}
|
|
420
|
+
],
|
|
421
|
+
"parameterValues": [
|
|
422
|
+
{
|
|
423
|
+
"parameterValueId": 522,
|
|
424
|
+
"parameterValueDescriptionsLangData": [
|
|
425
|
+
{
|
|
426
|
+
"langId": "eng",
|
|
427
|
+
"parameterValueName": "100g",
|
|
428
|
+
"parameterValueDescription": "",
|
|
429
|
+
"parameterValueShopsData": []
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
"langId": "ger",
|
|
433
|
+
"parameterValueName": "100g",
|
|
434
|
+
"parameterValueDescription": "",
|
|
435
|
+
"parameterValueShopsData": []
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
"langId": "pol",
|
|
439
|
+
"parameterValueName": "100g",
|
|
440
|
+
"parameterValueDescription": "",
|
|
441
|
+
"parameterValueShopsData": []
|
|
442
|
+
}
|
|
443
|
+
]
|
|
444
|
+
}
|
|
445
|
+
]
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
"parameterId": 521,
|
|
449
|
+
"parameterType": "section",
|
|
450
|
+
"parameterDescriptionsLangData": [
|
|
451
|
+
{
|
|
452
|
+
"langId": "eng",
|
|
453
|
+
"parameterName": "XCut",
|
|
454
|
+
"parameterDescription": "",
|
|
455
|
+
"parameterShopsData": []
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
"langId": "ger",
|
|
459
|
+
"parameterName": "XCut",
|
|
460
|
+
"parameterDescription": "",
|
|
461
|
+
"parameterShopsData": []
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
"langId": "pol",
|
|
465
|
+
"parameterName": "XCut",
|
|
466
|
+
"parameterDescription": "",
|
|
467
|
+
"parameterShopsData": []
|
|
468
|
+
}
|
|
469
|
+
]
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
"parameterId": 26,
|
|
473
|
+
"parameterType": "parameter",
|
|
474
|
+
"parameterDescriptionsLangData": [
|
|
475
|
+
{
|
|
476
|
+
"langId": "eng",
|
|
477
|
+
"parameterName": "Color",
|
|
478
|
+
"parameterDescription": "",
|
|
479
|
+
"parameterShopsData": []
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
"langId": "ger",
|
|
483
|
+
"parameterName": "Kolor",
|
|
484
|
+
"parameterDescription": "",
|
|
485
|
+
"parameterShopsData": []
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
"langId": "pol",
|
|
489
|
+
"parameterName": "Kolor",
|
|
490
|
+
"parameterDescription": "",
|
|
491
|
+
"parameterShopsData": []
|
|
492
|
+
}
|
|
493
|
+
],
|
|
494
|
+
"parameterValues": [
|
|
495
|
+
{
|
|
496
|
+
"parameterValueId": 48,
|
|
497
|
+
"parameterValueDescriptionsLangData": [
|
|
498
|
+
{
|
|
499
|
+
"langId": "eng",
|
|
500
|
+
"parameterValueName": "Black",
|
|
501
|
+
"parameterValueDescription": "",
|
|
502
|
+
"parameterValueShopsData": []
|
|
503
|
+
},
|
|
504
|
+
{
|
|
505
|
+
"langId": "ger",
|
|
506
|
+
"parameterValueName": "czarny",
|
|
507
|
+
"parameterValueDescription": "",
|
|
508
|
+
"parameterValueShopsData": []
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
"langId": "pol",
|
|
512
|
+
"parameterValueName": "czarny",
|
|
513
|
+
"parameterValueDescription": "",
|
|
514
|
+
"parameterValueShopsData": []
|
|
515
|
+
}
|
|
516
|
+
]
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
"parameterValueId": 96,
|
|
520
|
+
"parameterValueDescriptionsLangData": [
|
|
521
|
+
{
|
|
522
|
+
"langId": "eng",
|
|
523
|
+
"parameterValueName": "red",
|
|
524
|
+
"parameterValueDescription": "",
|
|
525
|
+
"parameterValueShopsData": []
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
"langId": "ger",
|
|
529
|
+
"parameterValueName": "czerwony",
|
|
530
|
+
"parameterValueDescription": "",
|
|
531
|
+
"parameterValueShopsData": []
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
"langId": "pol",
|
|
535
|
+
"parameterValueName": "czerwony",
|
|
536
|
+
"parameterValueDescription": "",
|
|
537
|
+
"parameterValueShopsData": []
|
|
538
|
+
}
|
|
539
|
+
]
|
|
540
|
+
}
|
|
541
|
+
]
|
|
542
|
+
}
|
|
543
|
+
]
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
export const PARAMETER_PRODUCT_RESULT = [
|
|
547
|
+
{
|
|
548
|
+
"id": 326,
|
|
549
|
+
"name": "Kolor akcentów",
|
|
550
|
+
"values": [
|
|
551
|
+
{
|
|
552
|
+
"valueId": 399,
|
|
553
|
+
"value": "Czarny"
|
|
554
|
+
}
|
|
555
|
+
]
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
"id": 173,
|
|
559
|
+
"name": "Waga całkowita",
|
|
560
|
+
"values": [
|
|
561
|
+
{
|
|
562
|
+
"valueId": 522,
|
|
563
|
+
"value": "100g"
|
|
564
|
+
}
|
|
565
|
+
]
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
"id": 26,
|
|
569
|
+
"name": "Kolor",
|
|
570
|
+
"values": [
|
|
571
|
+
{
|
|
572
|
+
"valueId": 48,
|
|
573
|
+
"value": "czarny"
|
|
574
|
+
},
|
|
575
|
+
{
|
|
576
|
+
"valueId": 96,
|
|
577
|
+
"value": "czerwony"
|
|
578
|
+
}
|
|
579
|
+
]
|
|
580
|
+
}
|
|
581
|
+
]
|