oneentry 1.0.53 → 1.0.55

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/README.md CHANGED
@@ -348,7 +348,6 @@ Example return:
348
348
  [
349
349
  {
350
350
  "id": 4,
351
- "attributeSetId": 14,
352
351
  "localizeInfos": {
353
352
  "title": "Name"
354
353
  },
@@ -356,7 +355,6 @@ Example return:
356
355
  "position": 3,
357
356
  "identifier": "product",
358
357
  "type": "forProductBlock",
359
- "productPageUrls": [],
360
358
  "templateIdentifier": null,
361
359
  "isVisible": true,
362
360
  "attributeValues": {
@@ -467,7 +465,6 @@ Example return:
467
465
  ```json
468
466
  {
469
467
  "id": 3,
470
- "attributeSetId": null,
471
468
  "localizeInfos": {
472
469
  "title": "test"
473
470
  },
@@ -475,7 +472,6 @@ Example return:
475
472
  "position": 4,
476
473
  "identifier": "test",
477
474
  "type": "forSimilarProductBlock",
478
- "productPageUrls": [],
479
475
  "templateIdentifier": null,
480
476
  "isVisible": true,
481
477
  "attributeValues": {},
@@ -564,7 +560,7 @@ example: null <br>
564
560
  </details>
565
561
  ---
566
562
 
567
- ## Blocks.getSimilarProducts(marker, langCode, offset, limit)
563
+ ### Blocks.getSimilarProducts(marker, langCode, offset, limit)
568
564
 
569
565
 
570
566
  ```js
@@ -584,7 +580,6 @@ Example return:
584
580
  },
585
581
  "relatedIds": [1, 2],
586
582
  "statusId": null,
587
- "attributeSetId": 11,
588
583
  "position": 3,
589
584
  "templateIdentifier": null,
590
585
  "shortDescTemplateIdentifier": null,
@@ -612,7 +607,7 @@ Example return:
612
607
 
613
608
 
614
609
 
615
- ## Blocks.getSimilarProducts(marker, langCode, offset, limit)
610
+ ### Blocks.getSimilarProducts(marker, langCode, offset, limit)
616
611
 
617
612
  ```js
618
613
  const value = await Blocks.getProductsByBlockMarker('my-marker', 'en_US')
@@ -631,7 +626,6 @@ Example return:
631
626
  },
632
627
  "relatedIds": [1, 2],
633
628
  "statusId": null,
634
- "attributeSetId": 11,
635
629
  "position": 3,
636
630
  "templateIdentifier": null,
637
631
  "shortDescTemplateIdentifier": null,
@@ -1,5 +1,5 @@
1
1
  import OneEntry from "../base/oneEntry";
2
- import { IBlocks, IBlocksEntity } from "./blocksInterfaces";
2
+ import { IBlocks, IBlockEntity, IBlockProduct } from "./blocksInterfaces";
3
3
  import { IConfig } from "../base/utils";
4
4
  /**
5
5
  * Controllers for working with blocks
@@ -15,7 +15,7 @@ export default class BlocksApi extends OneEntry implements IBlocks {
15
15
  *
16
16
  * @returns Return array of BlocksEntity object.
17
17
  */
18
- getBlocks(langCode?: string, offset?: number, limit?: number): Promise<Array<IBlocksEntity>>;
18
+ getBlocks(langCode?: string, offset?: number, limit?: number): Promise<Array<IBlockEntity>>;
19
19
  /**
20
20
  * Get block by marker.
21
21
  *
@@ -24,7 +24,7 @@ export default class BlocksApi extends OneEntry implements IBlocks {
24
24
  *
25
25
  * @returns Return BlocksEntity object.
26
26
  */
27
- getBlockByMarker(marker: string, langCode?: string): Promise<IBlocksEntity>;
27
+ getBlockByMarker(marker: string, langCode?: string): Promise<IBlockEntity>;
28
28
  /**
29
29
  * Get similar products by block marker.
30
30
  *
@@ -35,7 +35,7 @@ export default class BlocksApi extends OneEntry implements IBlocks {
35
35
  *
36
36
  * @returns Return array of BlocksEntity object.
37
37
  */
38
- getSimilarProducts(marker: string, langCode?: string, offset?: number, limit?: number): Promise<any>;
38
+ getSimilarProducts(marker: string, langCode?: string, offset?: number, limit?: number): Promise<Array<IBlockProduct>>;
39
39
  /**
40
40
  * Get products by block marker.
41
41
  *
@@ -46,5 +46,5 @@ export default class BlocksApi extends OneEntry implements IBlocks {
46
46
  *
47
47
  * @returns Return array of BlocksEntity object.
48
48
  */
49
- getProductsByBlockMarker(marker: string, langCode?: string, offset?: number, limit?: number): Promise<any>;
49
+ getProductsByBlockMarker(marker: string, langCode?: string, offset?: number, limit?: number): Promise<Array<IBlockProduct>>;
50
50
  }
@@ -23,19 +23,34 @@ class BlocksApi extends oneEntry_1.default {
23
23
  const normalizeResponse = this._normalizeData(response);
24
24
  await Promise.all(normalizeResponse.map(async (block) => {
25
25
  const customSettings = block.customSettings;
26
- if (customSettings.hasOwnProperty('productConfig')) {
27
- block.countElementsPerRow = Number(customSettings.productConfig.countElementsPerRow);
26
+ if (customSettings && customSettings.hasOwnProperty('productConfig')) {
27
+ block.countElementsPerRow = customSettings.productConfig.countElementsPerRow ? (+customSettings.productConfig.countElementsPerRow) : 0;
28
+ }
29
+ else {
30
+ block.countElementsPerRow = 0;
28
31
  }
29
32
  delete block.customSettings;
33
+ delete block.attributeSetId;
34
+ delete block.productPageUrls;
30
35
  if (block.type === 'forSimilarProductBlock') {
31
- await this.getSimilarProducts(block.identifier, langCode, offset, limit).then((result) => {
32
- block.similarProducts = result;
33
- });
36
+ try {
37
+ await this.getSimilarProducts(block.identifier, langCode, offset, limit).then((result) => {
38
+ block.similarProducts = result;
39
+ });
40
+ }
41
+ catch {
42
+ block.similarProducts = [];
43
+ }
34
44
  }
35
45
  else if (block.type === 'forProductBlock') {
36
- await this.getProductsByBlockMarker(block.identifier, langCode, offset, limit).then((result) => {
37
- block.products = result;
38
- });
46
+ try {
47
+ await this.getProductsByBlockMarker(block.identifier, langCode, offset, limit).then((result) => {
48
+ block.products = result;
49
+ });
50
+ }
51
+ catch {
52
+ block.products = [];
53
+ }
39
54
  }
40
55
  }));
41
56
  return normalizeResponse;
@@ -52,19 +67,34 @@ class BlocksApi extends oneEntry_1.default {
52
67
  const response = await this._fetchGet(`/marker/${marker}?langCode=${langCode}`);
53
68
  const normalizeResponse = this._normalizeData(response);
54
69
  const customSettings = normalizeResponse.customSettings;
55
- if (customSettings.hasOwnProperty('productConfig')) {
56
- normalizeResponse.countElementsPerRow = Number(customSettings.productConfig.countElementsPerRow);
70
+ if (customSettings && customSettings.hasOwnProperty('productConfig')) {
71
+ normalizeResponse.countElementsPerRow = customSettings.productConfig.countElementsPerRow ? (+customSettings.productConfig.countElementsPerRow) : 0;
72
+ }
73
+ else {
74
+ normalizeResponse.countElementsPerRow = 0;
57
75
  }
58
76
  delete normalizeResponse.customSettings;
77
+ delete normalizeResponse.attributeSetId;
78
+ delete normalizeResponse.productPageUrls;
59
79
  if (normalizeResponse.type === 'forSimilarProductBlock') {
60
- await this.getSimilarProducts(normalizeResponse.identifier, langCode).then((result) => {
61
- normalizeResponse.similarProducts = result;
62
- });
80
+ try {
81
+ await this.getSimilarProducts(normalizeResponse.identifier, langCode).then((result) => {
82
+ normalizeResponse.similarProducts = result;
83
+ });
84
+ }
85
+ catch {
86
+ normalizeResponse.similarProducts = [];
87
+ }
63
88
  }
64
89
  else if (normalizeResponse.type === 'forProductBlock') {
65
- await this.getProductsByBlockMarker(normalizeResponse.identifier, langCode).then((result) => {
66
- normalizeResponse.products = result;
67
- });
90
+ try {
91
+ await this.getProductsByBlockMarker(normalizeResponse.identifier, langCode).then((result) => {
92
+ normalizeResponse.products = result;
93
+ });
94
+ }
95
+ catch {
96
+ normalizeResponse.products = [];
97
+ }
68
98
  }
69
99
  return normalizeResponse;
70
100
  }
@@ -7,12 +7,12 @@
7
7
  * @property {function} getProductsByBlockMarker - Get Array of products from product block.
8
8
  */
9
9
  interface IBlocks {
10
- getBlocks(langCode: string, offset?: number, limit?: number): Promise<Array<IBlocksEntity>>;
11
- getBlockByMarker(marker: string, langCode: string): Promise<IBlocksEntity>;
12
- getSimilarProducts(marker: string, langCode?: string, offset?: number, limit?: number): Promise<Array<ISimilarProduct>>;
13
- getProductsByBlockMarker(marker: string, langCode?: string, offset?: number, limit?: number): Promise<Array<ISimilarProduct>>;
10
+ getBlocks(langCode: string, offset?: number, limit?: number): Promise<Array<IBlockEntity>>;
11
+ getBlockByMarker(marker: string, langCode: string): Promise<IBlockEntity>;
12
+ getSimilarProducts(marker: string, langCode?: string, offset?: number, limit?: number): Promise<Array<IBlockProduct>>;
13
+ getProductsByBlockMarker(marker: string, langCode?: string, offset?: number, limit?: number): Promise<Array<IBlockProduct>>;
14
14
  }
15
- interface ISimilarProduct {
15
+ interface IBlockProduct {
16
16
  attributeSetId: number;
17
17
  attributeValues: Record<string, any>;
18
18
  id: number;
@@ -27,7 +27,7 @@ interface ISimilarProduct {
27
27
  statusId: number | null;
28
28
  templateIdentifier: string | null;
29
29
  }
30
- interface IBlocksEntity {
30
+ interface IBlocksResponse {
31
31
  id: number;
32
32
  attributeSetId: number | null;
33
33
  localizeInfos: Record<string, any>;
@@ -40,8 +40,23 @@ interface IBlocksEntity {
40
40
  type: string;
41
41
  templateIdentifier: string | null;
42
42
  countElementsPerRow?: number;
43
- similarProducts?: Array<ISimilarProduct>;
44
- products?: Array<ISimilarProduct>;
43
+ productPageUrls: Array<any>;
44
+ similarProducts?: Array<IBlockProduct>;
45
+ products?: Array<IBlockProduct>;
46
+ }
47
+ interface IBlockEntity {
48
+ attributeValues: Record<string, any>;
49
+ id: number;
50
+ identifier: string;
51
+ isVisible: boolean;
52
+ localizeInfos: Record<string, any>;
53
+ position: number;
54
+ templateIdentifier: string | null;
55
+ type: string;
56
+ version: number;
57
+ similarProducts?: Array<IBlockProduct>;
58
+ products?: Array<IBlockProduct>;
59
+ countElementsPerRow: number;
45
60
  }
46
61
  interface ICustomSetting {
47
62
  sliderDelay: number;
@@ -58,4 +73,4 @@ interface ICustomSetting {
58
73
  }> | Record<string, any>;
59
74
  [key: string]: any;
60
75
  }
61
- export { IBlocks, IBlocksEntity };
76
+ export { IBlocks, IBlockEntity, IBlocksResponse, IBlockProduct };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneentry",
3
- "version": "1.0.53",
3
+ "version": "1.0.55",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",