oneentry 1.0.57 → 1.0.58
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 +28 -59
- package/dist/base/oneEntry.d.ts +1 -0
- package/dist/base/oneEntry.js +15 -2
- package/dist/base/utils.d.ts +14 -1
- package/dist/blocks/blocksApi.d.ts +5 -4
- package/dist/blocks/blocksApi.js +52 -47
- package/dist/blocks/blocksInterfaces.d.ts +9 -23
- package/dist/pages/pagesApi.js +42 -3
- package/dist/products/productsApi.js +10 -7
- package/dist/products/productsInterfaces.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ To get started with OneEntry, sign up for an account at [https://account.oneentr
|
|
|
14
14
|
|
|
15
15
|
To install the OneEntry Headless CMS SDK in your project, run the following command:
|
|
16
16
|
|
|
17
|
-
```
|
|
17
|
+
```bash
|
|
18
18
|
npm install oneentry
|
|
19
19
|
```
|
|
20
20
|
|
|
@@ -37,7 +37,7 @@ const {
|
|
|
37
37
|
Menus,
|
|
38
38
|
Pages,
|
|
39
39
|
Products,
|
|
40
|
-
|
|
40
|
+
ProductStatuses,
|
|
41
41
|
System,
|
|
42
42
|
Templates,
|
|
43
43
|
TemplatePreviews
|
|
@@ -50,10 +50,11 @@ Or
|
|
|
50
50
|
const api = defineOneEntry('your-url')
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
The second parameter of the function takes a configuration object with the keys "token" and "
|
|
53
|
+
The second parameter of the function takes a configuration object with the keys "token", "langCode" and "multipleResponse".
|
|
54
54
|
Set the token key if your project secure "Security API Token"
|
|
55
55
|
|
|
56
56
|
Set the "langCode" to set the default language. By specifying this parameter once, you don't have to pass the langCode to the methods ONEENTRY API. If you have not passed the default language, it will be set "en_US"
|
|
57
|
+
Some methods use more than one request to the CMS so that the data you receive is complete and easy to work with. Pass the value "false" for this parameter to save traffic and decide for yourself what data you need. The default value "true"
|
|
57
58
|
|
|
58
59
|
>If you chose token protection to ensure connection security, just pass your token to the function as an optional parameter.
|
|
59
60
|
|
|
@@ -85,7 +86,7 @@ Now you can use the following links to jump to specific entries:
|
|
|
85
86
|
- [Menus](#menus)
|
|
86
87
|
- [Pages](#pages)
|
|
87
88
|
- [Products](#products)
|
|
88
|
-
- [
|
|
89
|
+
- [ProductStatuses](#productstatuses)
|
|
89
90
|
- [System](#system)
|
|
90
91
|
- [Templates](#templates)
|
|
91
92
|
- [TemplatePreviews](#templatepreviews)
|
|
@@ -464,50 +465,17 @@ Example return:
|
|
|
464
465
|
|
|
465
466
|
```json
|
|
466
467
|
{
|
|
467
|
-
"id":
|
|
468
|
+
"id": 1,
|
|
468
469
|
"localizeInfos": {
|
|
469
|
-
"title": "
|
|
470
|
+
"title": "Block"
|
|
470
471
|
},
|
|
471
472
|
"version": 0,
|
|
472
|
-
"position":
|
|
473
|
-
"identifier": "
|
|
474
|
-
"type": "
|
|
473
|
+
"position": 1,
|
|
474
|
+
"identifier": "block",
|
|
475
|
+
"type": "forTextBlock",
|
|
475
476
|
"templateIdentifier": null,
|
|
476
477
|
"isVisible": true,
|
|
477
|
-
"attributeValues": {}
|
|
478
|
-
"countElementsPerRow": 4,
|
|
479
|
-
"similarProducts": [
|
|
480
|
-
{
|
|
481
|
-
"id": 446,
|
|
482
|
-
"localizeInfos": {
|
|
483
|
-
"title": "new product 3"
|
|
484
|
-
},
|
|
485
|
-
"relatedIds": [1, 2],
|
|
486
|
-
"statusId": null,
|
|
487
|
-
"attributeSetId": 11,
|
|
488
|
-
"position": 3,
|
|
489
|
-
"templateIdentifier": null,
|
|
490
|
-
"shortDescTemplateIdentifier": null,
|
|
491
|
-
"price": 543,
|
|
492
|
-
"sku": "ggg",
|
|
493
|
-
"isSync": true,
|
|
494
|
-
"attributeValues": {
|
|
495
|
-
"sku": {
|
|
496
|
-
"type": "string",
|
|
497
|
-
"value": "ggg",
|
|
498
|
-
"position": 0,
|
|
499
|
-
"isProductPreview": false
|
|
500
|
-
},
|
|
501
|
-
"images": {
|
|
502
|
-
"type": "groupOfImages",
|
|
503
|
-
"value": {},
|
|
504
|
-
"position": 3,
|
|
505
|
-
"isProductPreview": false
|
|
506
|
-
}
|
|
507
|
-
},
|
|
508
|
-
"isVisible": true
|
|
509
|
-
}
|
|
510
|
-
]
|
|
478
|
+
"attributeValues": {}
|
|
511
479
|
}
|
|
512
480
|
```
|
|
513
481
|
|
|
@@ -574,29 +542,30 @@ Example return:
|
|
|
574
542
|
```json
|
|
575
543
|
[
|
|
576
544
|
{
|
|
577
|
-
"id":
|
|
545
|
+
"id": 2,
|
|
578
546
|
"localizeInfos": {
|
|
579
|
-
"title": "
|
|
547
|
+
"title": "Box"
|
|
580
548
|
},
|
|
581
|
-
"relatedIds": [
|
|
582
|
-
"statusId":
|
|
583
|
-
"
|
|
549
|
+
"relatedIds": [],
|
|
550
|
+
"statusId": 2,
|
|
551
|
+
"attributeSetId": 5,
|
|
552
|
+
"position": 1,
|
|
584
553
|
"templateIdentifier": null,
|
|
585
554
|
"shortDescTemplateIdentifier": null,
|
|
586
|
-
"price":
|
|
587
|
-
"sku":
|
|
555
|
+
"price": 150,
|
|
556
|
+
"sku": null,
|
|
588
557
|
"isSync": true,
|
|
589
558
|
"attributeValues": {
|
|
590
|
-
"
|
|
591
|
-
"type": "
|
|
592
|
-
"value": "
|
|
593
|
-
"position":
|
|
559
|
+
"price": {
|
|
560
|
+
"type": "integer",
|
|
561
|
+
"value": "150",
|
|
562
|
+
"position": 1,
|
|
594
563
|
"isProductPreview": false
|
|
595
564
|
},
|
|
596
|
-
"
|
|
597
|
-
"type": "
|
|
598
|
-
"value":
|
|
599
|
-
"position":
|
|
565
|
+
"product-name": {
|
|
566
|
+
"type": "string",
|
|
567
|
+
"value": "Box text",
|
|
568
|
+
"position": 0,
|
|
600
569
|
"isProductPreview": false
|
|
601
570
|
}
|
|
602
571
|
},
|
|
@@ -607,7 +576,7 @@ Example return:
|
|
|
607
576
|
|
|
608
577
|
|
|
609
578
|
|
|
610
|
-
### Blocks.
|
|
579
|
+
### Blocks.getProductsByBlockMarker(marker, langCode, offset, limit)
|
|
611
580
|
|
|
612
581
|
```js
|
|
613
582
|
const value = await Blocks.getProductsByBlockMarker('my-marker', 'en_US')
|
package/dist/base/oneEntry.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export default abstract class OneEntry {
|
|
|
5
5
|
protected _url: string;
|
|
6
6
|
protected _token: string | undefined;
|
|
7
7
|
protected _defaultLangCode: string;
|
|
8
|
+
protected _multipleResponse: boolean;
|
|
8
9
|
protected _NO_FETCH: boolean;
|
|
9
10
|
protected _https: any;
|
|
10
11
|
constructor(url: string, config?: IConfig);
|
package/dist/base/oneEntry.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
class OneEntry {
|
|
4
4
|
constructor(url, config = {}) {
|
|
5
|
+
var _a;
|
|
5
6
|
this._url = url;
|
|
6
7
|
this._token = config.token;
|
|
7
8
|
this._defaultLangCode = config.langCode ? config.langCode : 'en_US';
|
|
9
|
+
this._multipleResponse = (_a = config.multipleRequests) !== null && _a !== void 0 ? _a : true;
|
|
8
10
|
this._NO_FETCH = !!(typeof process === 'object' && process.versions);
|
|
9
11
|
try {
|
|
10
12
|
this._https = this._NO_FETCH ? require('https') : null;
|
|
@@ -26,6 +28,10 @@ class OneEntry {
|
|
|
26
28
|
};
|
|
27
29
|
if (!this._NO_FETCH) {
|
|
28
30
|
const response = await fetch(this._getFullPath(path), options);
|
|
31
|
+
if (!response.ok) {
|
|
32
|
+
const error = await response.json();
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
29
35
|
return await response.json();
|
|
30
36
|
}
|
|
31
37
|
else {
|
|
@@ -61,6 +67,10 @@ class OneEntry {
|
|
|
61
67
|
...options,
|
|
62
68
|
body: data
|
|
63
69
|
});
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
const error = await response.json();
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
64
74
|
return await response.json();
|
|
65
75
|
}
|
|
66
76
|
else {
|
|
@@ -92,8 +102,11 @@ class OneEntry {
|
|
|
92
102
|
};
|
|
93
103
|
if (!this._NO_FETCH) {
|
|
94
104
|
const response = await fetch(this._getFullPath(path), options);
|
|
95
|
-
|
|
96
|
-
|
|
105
|
+
if (!response.ok) {
|
|
106
|
+
const error = await response.json();
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
return await response.json();
|
|
97
110
|
}
|
|
98
111
|
else {
|
|
99
112
|
return new Promise((resolve, reject) => {
|
package/dist/base/utils.d.ts
CHANGED
|
@@ -19,9 +19,15 @@ declare enum Types {
|
|
|
19
19
|
forSlider = "forSlider",
|
|
20
20
|
service = "service"
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* @param {string} [token] - If your project is protected by a token, specify this token in this parameter.
|
|
24
|
+
* @param {string} [langCode] - specify the default language to avoid specifying it in every request.
|
|
25
|
+
* @param {boolean} [multipleRequests] - Some methods use multiple queries to make it easier to work with the API. Set this parameter to "false" to save traffic and decide for yourself what data you need.
|
|
26
|
+
*/
|
|
22
27
|
interface IConfig {
|
|
23
28
|
token?: string;
|
|
24
29
|
langCode?: string;
|
|
30
|
+
multipleRequests?: boolean;
|
|
25
31
|
}
|
|
26
32
|
interface IAttributes {
|
|
27
33
|
listTitles: Array<{
|
|
@@ -69,4 +75,11 @@ interface IAttributeSetEntity {
|
|
|
69
75
|
}
|
|
70
76
|
type LangType = string | Array<string>;
|
|
71
77
|
type LocalizeType = ILocalizeInfos | ILocalizeInfo;
|
|
72
|
-
|
|
78
|
+
interface IError {
|
|
79
|
+
message: string;
|
|
80
|
+
pageData: any;
|
|
81
|
+
statusCode: number;
|
|
82
|
+
timestamp: string;
|
|
83
|
+
[key: string]: any;
|
|
84
|
+
}
|
|
85
|
+
export { LocalizeType, ILocalizeInfos, ILocalizeInfo, Types, IAttributeSetEntity, LangType, AttributeType, IAttributeValues, IAttributes, IConfig, IError };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import OneEntry from "../base/oneEntry";
|
|
2
|
-
import { IBlocks,
|
|
2
|
+
import { IBlocks, IBlocksResponse, IBlockEntity } from "./blocksInterfaces";
|
|
3
|
+
import { IProductsEntity } from "../products/productsInterfaces";
|
|
3
4
|
import { IConfig } from "../base/utils";
|
|
4
5
|
/**
|
|
5
6
|
* Controllers for working with blocks
|
|
@@ -15,7 +16,7 @@ export default class BlocksApi extends OneEntry implements IBlocks {
|
|
|
15
16
|
*
|
|
16
17
|
* @returns Return array of BlocksEntity object.
|
|
17
18
|
*/
|
|
18
|
-
getBlocks(langCode?: string, offset?: number, limit?: number): Promise<Array<IBlockEntity>>;
|
|
19
|
+
getBlocks(langCode?: string, offset?: number, limit?: number): Promise<Array<IBlockEntity | IBlocksResponse>>;
|
|
19
20
|
/**
|
|
20
21
|
* Get block by marker.
|
|
21
22
|
*
|
|
@@ -35,7 +36,7 @@ export default class BlocksApi extends OneEntry implements IBlocks {
|
|
|
35
36
|
*
|
|
36
37
|
* @returns Return array of BlocksEntity object.
|
|
37
38
|
*/
|
|
38
|
-
getSimilarProducts(marker: string, langCode?: string, offset?: number, limit?: number): Promise<Array<
|
|
39
|
+
getSimilarProducts(marker: string, langCode?: string, offset?: number, limit?: number): Promise<Array<IProductsEntity>>;
|
|
39
40
|
/**
|
|
40
41
|
* Get products by block marker.
|
|
41
42
|
*
|
|
@@ -46,5 +47,5 @@ export default class BlocksApi extends OneEntry implements IBlocks {
|
|
|
46
47
|
*
|
|
47
48
|
* @returns Return array of BlocksEntity object.
|
|
48
49
|
*/
|
|
49
|
-
getProductsByBlockMarker(marker: string, langCode?: string, offset?: number, limit?: number): Promise<Array<
|
|
50
|
+
getProductsByBlockMarker(marker: string, langCode?: string, offset?: number, limit?: number): Promise<Array<IProductsEntity>>;
|
|
50
51
|
}
|
package/dist/blocks/blocksApi.js
CHANGED
|
@@ -20,40 +20,43 @@ class BlocksApi extends oneEntry_1.default {
|
|
|
20
20
|
*/
|
|
21
21
|
async getBlocks(langCode = 'en_US', offset = 0, limit = 30) {
|
|
22
22
|
const response = await this._fetchGet(`?langCode=${langCode}&offset=${offset}&limit=${limit}`);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
else {
|
|
30
|
-
block.countElementsPerRow = 0;
|
|
31
|
-
}
|
|
32
|
-
delete block.customSettings;
|
|
33
|
-
delete block.attributeSetId;
|
|
34
|
-
delete block.productPageUrls;
|
|
35
|
-
if (block.type === 'forSimilarProductBlock') {
|
|
36
|
-
try {
|
|
37
|
-
await this.getSimilarProducts(block.identifier, langCode, offset, limit).then((result) => {
|
|
38
|
-
block.similarProducts = result;
|
|
39
|
-
});
|
|
23
|
+
if (this._multipleResponse) {
|
|
24
|
+
const normalizeResponse = this._normalizeData(response);
|
|
25
|
+
await Promise.all(normalizeResponse.map(async (block) => {
|
|
26
|
+
const customSettings = block.customSettings;
|
|
27
|
+
if (customSettings && customSettings.hasOwnProperty('productConfig')) {
|
|
28
|
+
block.countElementsPerRow = customSettings.productConfig.countElementsPerRow ? (+customSettings.productConfig.countElementsPerRow) : 0;
|
|
40
29
|
}
|
|
41
|
-
|
|
42
|
-
block.
|
|
30
|
+
else {
|
|
31
|
+
block.countElementsPerRow = 0;
|
|
43
32
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
33
|
+
delete block.customSettings;
|
|
34
|
+
delete block.attributeSetId;
|
|
35
|
+
delete block.productPageUrls;
|
|
36
|
+
if (block.type === 'forSimilarProductBlock') {
|
|
37
|
+
try {
|
|
38
|
+
await this.getSimilarProducts(block.identifier, langCode, offset, limit).then((result) => {
|
|
39
|
+
block.similarProducts = result;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
block.similarProducts = [];
|
|
44
|
+
}
|
|
50
45
|
}
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
else if (block.type === 'forProductBlock') {
|
|
47
|
+
try {
|
|
48
|
+
await this.getProductsByBlockMarker(block.identifier, langCode, offset, limit).then((result) => {
|
|
49
|
+
block.products = result;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
block.products = [];
|
|
54
|
+
}
|
|
53
55
|
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
}));
|
|
57
|
+
return normalizeResponse;
|
|
58
|
+
}
|
|
59
|
+
return response;
|
|
57
60
|
}
|
|
58
61
|
/**
|
|
59
62
|
* Get block by marker.
|
|
@@ -76,24 +79,26 @@ class BlocksApi extends oneEntry_1.default {
|
|
|
76
79
|
delete normalizeResponse.customSettings;
|
|
77
80
|
delete normalizeResponse.attributeSetId;
|
|
78
81
|
delete normalizeResponse.productPageUrls;
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
normalizeResponse.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
else if (normalizeResponse.type === 'forProductBlock') {
|
|
90
|
-
try {
|
|
91
|
-
await this.getProductsByBlockMarker(normalizeResponse.identifier, langCode).then((result) => {
|
|
92
|
-
normalizeResponse.products = result;
|
|
93
|
-
});
|
|
82
|
+
if (this._multipleResponse) {
|
|
83
|
+
if (normalizeResponse.type === 'forSimilarProductBlock') {
|
|
84
|
+
try {
|
|
85
|
+
await this.getSimilarProducts(normalizeResponse.identifier, langCode).then((result) => {
|
|
86
|
+
normalizeResponse.similarProducts = result;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
normalizeResponse.similarProducts = [];
|
|
91
|
+
}
|
|
94
92
|
}
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
else if (normalizeResponse.type === 'forProductBlock') {
|
|
94
|
+
try {
|
|
95
|
+
await this.getProductsByBlockMarker(normalizeResponse.identifier, langCode).then((result) => {
|
|
96
|
+
normalizeResponse.products = result;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
normalizeResponse.products = [];
|
|
101
|
+
}
|
|
97
102
|
}
|
|
98
103
|
}
|
|
99
104
|
return normalizeResponse;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IProductsEntity } from "../products/productsInterfaces";
|
|
1
2
|
/**
|
|
2
3
|
* Represents a interface object of Blocks Api.
|
|
3
4
|
*
|
|
@@ -7,25 +8,10 @@
|
|
|
7
8
|
* @property {function} getProductsByBlockMarker - Get Array of products from product block.
|
|
8
9
|
*/
|
|
9
10
|
interface IBlocks {
|
|
10
|
-
getBlocks(langCode: string, offset?: number, limit?: number): Promise<Array<IBlockEntity>>;
|
|
11
|
+
getBlocks(langCode: string, offset?: number, limit?: number): Promise<Array<IBlockEntity | IBlocksResponse>>;
|
|
11
12
|
getBlockByMarker(marker: string, langCode: string): Promise<IBlockEntity>;
|
|
12
|
-
getSimilarProducts(marker: string, langCode?: string, offset?: number, limit?: number): Promise<Array<
|
|
13
|
-
getProductsByBlockMarker(marker: string, langCode?: string, offset?: number, limit?: number): Promise<Array<
|
|
14
|
-
}
|
|
15
|
-
interface IBlockProduct {
|
|
16
|
-
attributeSetId: number;
|
|
17
|
-
attributeValues: Record<string, any>;
|
|
18
|
-
id: number;
|
|
19
|
-
isSync: boolean;
|
|
20
|
-
isVisible: boolean;
|
|
21
|
-
localizeInfos: Record<string, any>;
|
|
22
|
-
position: number;
|
|
23
|
-
price: number;
|
|
24
|
-
relatedIds: Array<number>;
|
|
25
|
-
shortDescTemplateIdentifier: string | null;
|
|
26
|
-
sku: string;
|
|
27
|
-
statusId: number | null;
|
|
28
|
-
templateIdentifier: string | null;
|
|
13
|
+
getSimilarProducts(marker: string, langCode?: string, offset?: number, limit?: number): Promise<Array<IProductsEntity>>;
|
|
14
|
+
getProductsByBlockMarker(marker: string, langCode?: string, offset?: number, limit?: number): Promise<Array<IProductsEntity>>;
|
|
29
15
|
}
|
|
30
16
|
interface IBlocksResponse {
|
|
31
17
|
id: number;
|
|
@@ -41,8 +27,8 @@ interface IBlocksResponse {
|
|
|
41
27
|
templateIdentifier: string | null;
|
|
42
28
|
countElementsPerRow?: number;
|
|
43
29
|
productPageUrls: Array<any>;
|
|
44
|
-
similarProducts?: Array<
|
|
45
|
-
products?: Array<
|
|
30
|
+
similarProducts?: Array<IProductsEntity>;
|
|
31
|
+
products?: Array<IProductsEntity>;
|
|
46
32
|
}
|
|
47
33
|
interface IBlockEntity {
|
|
48
34
|
attributeValues: Record<string, any>;
|
|
@@ -54,8 +40,8 @@ interface IBlockEntity {
|
|
|
54
40
|
templateIdentifier: string | null;
|
|
55
41
|
type: string;
|
|
56
42
|
version: number;
|
|
57
|
-
similarProducts?: Array<
|
|
58
|
-
products?: Array<
|
|
43
|
+
similarProducts?: Array<IProductsEntity>;
|
|
44
|
+
products?: Array<IProductsEntity>;
|
|
59
45
|
countElementsPerRow: number;
|
|
60
46
|
}
|
|
61
47
|
interface ICustomSetting {
|
|
@@ -73,4 +59,4 @@ interface ICustomSetting {
|
|
|
73
59
|
}> | Record<string, any>;
|
|
74
60
|
[key: string]: any;
|
|
75
61
|
}
|
|
76
|
-
export { IBlocks, IBlockEntity, IBlocksResponse,
|
|
62
|
+
export { IBlocks, IBlockEntity, IBlocksResponse, ICustomSetting };
|
package/dist/pages/pagesApi.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const oneEntry_1 = require("../base/oneEntry");
|
|
4
|
+
const blocksApi_1 = require("../blocks/blocksApi");
|
|
4
5
|
/**
|
|
5
6
|
* Controllers for working with page objects, including catalog pages
|
|
6
7
|
*/
|
|
@@ -18,7 +19,6 @@ class PageApi extends oneEntry_1.default {
|
|
|
18
19
|
*/
|
|
19
20
|
async getRootPages(langCode = this._defaultLangCode) {
|
|
20
21
|
const result = await this._fetchGet(`/root?langCode=${langCode}`);
|
|
21
|
-
console.log(result);
|
|
22
22
|
return this._normalizeData(result, langCode);
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
@@ -109,8 +109,47 @@ class PageApi extends oneEntry_1.default {
|
|
|
109
109
|
* @returns Returns all blocks as an array of PositionBlock objects or an empty array [] (if there is no data) for the selected parent
|
|
110
110
|
*/
|
|
111
111
|
async getBlocksByPageUrl(url, langCode = this._defaultLangCode) {
|
|
112
|
-
const
|
|
113
|
-
|
|
112
|
+
const response = await this._fetchGet(`/${url}/blocks?langCode=${langCode}`);
|
|
113
|
+
const normalizeResponse = this._normalizeData(response);
|
|
114
|
+
normalizeResponse.map((item) => {
|
|
115
|
+
const customSettings = item.customSettings;
|
|
116
|
+
if (customSettings && customSettings.hasOwnProperty('productConfig')) {
|
|
117
|
+
item.countElementsPerRow = customSettings.productConfig.countElementsPerRow ? (+customSettings.productConfig.countElementsPerRow) : 0;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
item.countElementsPerRow = 0;
|
|
121
|
+
}
|
|
122
|
+
delete item.customSettings;
|
|
123
|
+
delete item.attributeSetId;
|
|
124
|
+
return item;
|
|
125
|
+
});
|
|
126
|
+
if (this._multipleResponse) {
|
|
127
|
+
const Blocks = new blocksApi_1.default(this._url.split('/api')[0], {
|
|
128
|
+
langCode: this._defaultLangCode,
|
|
129
|
+
token: this._token
|
|
130
|
+
});
|
|
131
|
+
if (normalizeResponse.type === 'forSimilarProductBlock') {
|
|
132
|
+
try {
|
|
133
|
+
await Blocks.getSimilarProducts(normalizeResponse.identifier, langCode).then((result) => {
|
|
134
|
+
normalizeResponse.similarProducts = result;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
normalizeResponse.similarProducts = [];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else if (normalizeResponse.type === 'forProductBlock') {
|
|
142
|
+
try {
|
|
143
|
+
await Blocks.getProductsByBlockMarker(normalizeResponse.identifier, langCode).then((result) => {
|
|
144
|
+
normalizeResponse.products = result;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
normalizeResponse.products = [];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return normalizeResponse;
|
|
114
153
|
}
|
|
115
154
|
/**
|
|
116
155
|
* Get settings for the page.
|
|
@@ -238,13 +238,16 @@ class ProductApi extends oneEntry_1.default {
|
|
|
238
238
|
*/
|
|
239
239
|
async searchProduct(name, langCode = this._defaultLangCode) {
|
|
240
240
|
const searchProducts = await this._fetchGet(`/quick/search?lang=${langCode}&name=${name}`);
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
await
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
241
|
+
if (this._multipleResponse) {
|
|
242
|
+
const productsList = [];
|
|
243
|
+
await Promise.all(searchProducts.map(async (product) => {
|
|
244
|
+
await this.getProductById(product.id, langCode).then((result) => {
|
|
245
|
+
productsList.push(result);
|
|
246
|
+
});
|
|
247
|
+
}));
|
|
248
|
+
return this._dataPostProcess(productsList, langCode);
|
|
249
|
+
}
|
|
250
|
+
return searchProducts;
|
|
248
251
|
}
|
|
249
252
|
}
|
|
250
253
|
exports.default = ProductApi;
|
|
@@ -119,6 +119,6 @@ interface IProductsEntity {
|
|
|
119
119
|
attributeValues: Record<string, any>;
|
|
120
120
|
position: number;
|
|
121
121
|
sku: string | null;
|
|
122
|
-
productPages
|
|
122
|
+
productPages?: Array<Record<string, any>> | Record<string, any>;
|
|
123
123
|
}
|
|
124
124
|
export { IFilterParams, IProductsQuery, IProductApi, IProductsEntity, };
|