oneentry 1.0.49 → 1.0.51

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.
@@ -19,8 +19,8 @@ class AdminsApi extends oneEntry_1.default {
19
19
  * @returns Returns all AdminEntity user objects
20
20
  */
21
21
  async getAdminsInfo(langCode = this._defaultLangCode, offset = 0, limit = 30) {
22
- const result = await this._fetchGet(`?langCode=${langCode}&offset=${offset}&limit=${limit}`);
23
- return this._normalizeData(result, langCode);
22
+ const response = await this._fetchGet(`?langCode=${langCode}&offset=${offset}&limit=${limit}`);
23
+ return this._normalizeData(response, langCode);
24
24
  }
25
25
  }
26
26
  exports.default = AdminsApi;
@@ -19,7 +19,7 @@ class AttributesSetsApi extends oneEntry_1.default {
19
19
  */
20
20
  async getAttributesByMarker(marker, langCode = this._defaultLangCode) {
21
21
  const result = await this._fetchGet(`/${marker}/attributes?langCode=${langCode}`);
22
- return this._normalizeData(result, langCode);
22
+ return this._dataPostProcess(result, langCode);
23
23
  }
24
24
  /**
25
25
  * Get a single attribute with data from the attribute sets.
@@ -41,6 +41,6 @@ interface IAttributesSetsEntity {
41
41
  position: string | number | null;
42
42
  extendedValue: string | number | null;
43
43
  extendedValueType: string | number | null;
44
- }>;
44
+ }> | Record<string, any>;
45
45
  }
46
46
  export { IAttributesSets, IAttributesSetsEntity };
@@ -14,4 +14,6 @@ export default abstract class OneEntry {
14
14
  protected _fetchDelete(path: string): Promise<any>;
15
15
  protected _queryParamsToString(query: IProductsQuery | IUploadingQuery): string;
16
16
  protected _normalizeData(data: any, langCode?: string): any;
17
+ protected _clearArray(data: Record<string, any>): any;
18
+ protected _dataPostProcess(data: any, langCode?: string): any;
17
19
  }
@@ -26,8 +26,8 @@ class OneEntry {
26
26
  };
27
27
  if (!this._NO_FETCH) {
28
28
  const response = await fetch(this._getFullPath(path), options);
29
- const result = await response.json();
30
- return result;
29
+ // const result = await response.json()
30
+ return await response.json();
31
31
  }
32
32
  else {
33
33
  return new Promise((resolve, reject) => {
@@ -37,6 +37,7 @@ class OneEntry {
37
37
  data += chunk;
38
38
  });
39
39
  res.on('end', () => {
40
+ // const result = new Result(JSON.parse(data))
40
41
  resolve(JSON.parse(data));
41
42
  });
42
43
  });
@@ -142,5 +143,30 @@ class OneEntry {
142
143
  return normalizeData;
143
144
  }
144
145
  }
146
+ _clearArray(data) {
147
+ if (Array.isArray(data)) {
148
+ return data.map(item => this._clearArray(item));
149
+ }
150
+ else {
151
+ const dataWithoutArray = {};
152
+ for (let key in data) {
153
+ if (Array.isArray(data[key]) && data[key].length === 1) {
154
+ dataWithoutArray[key] = data[key][0];
155
+ }
156
+ else if (typeof data[key] === 'object' && data[key] && !Array.isArray(data[key])) {
157
+ dataWithoutArray[key] = this._clearArray(data[key]);
158
+ }
159
+ else {
160
+ dataWithoutArray[key] = data[key];
161
+ }
162
+ }
163
+ return dataWithoutArray;
164
+ }
165
+ }
166
+ _dataPostProcess(data, langCode = this._defaultLangCode) {
167
+ const normalize = this._normalizeData(data, langCode);
168
+ const result = this._clearArray(normalize);
169
+ return result;
170
+ }
145
171
  }
146
172
  exports.default = OneEntry;
@@ -0,0 +1,8 @@
1
+ export default class Result {
2
+ body: any;
3
+ constructor(data: Response | string);
4
+ blob(): Promise<Result>;
5
+ json(): Promise<Result>;
6
+ makeDataWithoutLang(langCode: string, data?: any): any;
7
+ makeDataWithoutArray(data?: any): any;
8
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class Result {
4
+ constructor(data) {
5
+ this.body = data;
6
+ }
7
+ async blob() {
8
+ this.body = await this.body.blob();
9
+ return this;
10
+ }
11
+ async json() {
12
+ this.body = await typeof this.body === 'string' ? JSON.parse(this.body) : this.body.json();
13
+ return this;
14
+ }
15
+ makeDataWithoutLang(langCode, data) {
16
+ if (data) {
17
+ if (Array.isArray(data)) {
18
+ return data.map((item) => this.makeDataWithoutLang(langCode, item));
19
+ }
20
+ else {
21
+ for (let key in data) {
22
+ if (typeof data[key] === 'object' && data[key] && langCode in data[key]) {
23
+ data[key] = data[key][langCode];
24
+ }
25
+ else if (typeof data[key] === 'object' && data[key] != null) {
26
+ data[key] = this.makeDataWithoutLang(langCode, data[key]);
27
+ }
28
+ else if (Array.isArray(data[key])) {
29
+ data[key] = data.map((item) => this.makeDataWithoutLang(langCode, item));
30
+ }
31
+ }
32
+ return data;
33
+ }
34
+ }
35
+ else {
36
+ if (Array.isArray(this.body)) {
37
+ this.body = this.body.map((item) => this.makeDataWithoutLang(langCode, item));
38
+ }
39
+ else {
40
+ for (let key in this.body) {
41
+ if (typeof this.body[key] === 'object' && this.body[key] && langCode in this.body[key]) {
42
+ this.body[key] = this.body[key][langCode];
43
+ }
44
+ else if (typeof this.body[key] === 'object' && this.body[key] != null) {
45
+ this.body[key] = this.makeDataWithoutLang(langCode, this.body[key]);
46
+ }
47
+ else if (Array.isArray(this.body[key])) {
48
+ this.body[key] = this.body[key].map((item) => this.makeDataWithoutLang(langCode, item));
49
+ }
50
+ }
51
+ }
52
+ return this;
53
+ }
54
+ }
55
+ makeDataWithoutArray(data) {
56
+ if (data) {
57
+ if (Array.isArray(data)) {
58
+ return data.map(item => this.makeDataWithoutArray(item));
59
+ }
60
+ else {
61
+ for (let key in data) {
62
+ if (Array.isArray(data[key]) && data[key].length === 1) {
63
+ data[key] = data[key][0];
64
+ }
65
+ else if (typeof data[key] === 'object' && data[key] && !Array.isArray(data[key])) {
66
+ data[key] = this.makeDataWithoutArray(data[key]);
67
+ }
68
+ }
69
+ return data;
70
+ }
71
+ }
72
+ else {
73
+ if (Array.isArray(this.body)) {
74
+ return this.body.map(item => this.makeDataWithoutArray(item));
75
+ }
76
+ else {
77
+ for (let key in this.body) {
78
+ if (Array.isArray(this.body[key]) && this.body[key].length === 1) {
79
+ this.body[key] = this.body[key][0];
80
+ }
81
+ else if (typeof this.body[key] === 'object' && this.body[key] && !Array.isArray(this.body[key])) {
82
+ this.body[key] = this.makeDataWithoutArray(this.body[key]);
83
+ }
84
+ }
85
+ return this;
86
+ }
87
+ }
88
+ }
89
+ }
90
+ exports.default = Result;
@@ -57,7 +57,7 @@ interface IAttributeSetEntity {
57
57
  identifier: string;
58
58
  typeId: number;
59
59
  localizeInfos: LocalizeType;
60
- schema: object;
60
+ schema: Record<string, any>;
61
61
  position: {
62
62
  id: number;
63
63
  objectId: number;
@@ -32,7 +32,7 @@ class BlocksApi extends oneEntry_1.default {
32
32
  */
33
33
  async getBlockByMarker(marker, langCode = this._defaultLangCode) {
34
34
  const result = await this._fetchGet(`/marker/${marker}?langCode=${langCode}`);
35
- return this._normalizeData(result, langCode);
35
+ return this._dataPostProcess(result, langCode);
36
36
  }
37
37
  }
38
38
  exports.default = BlocksApi;
@@ -32,6 +32,6 @@ interface ICustomSetting {
32
32
  includes: string;
33
33
  keywords: string;
34
34
  strict: string;
35
- }>;
35
+ }> | Record<string, any>;
36
36
  }
37
37
  export { IBlocks, IBlocksEntity };
@@ -20,7 +20,7 @@ class FormsApi extends oneEntry_1.default {
20
20
  */
21
21
  async getAllForms(langCode = this._defaultLangCode, offset = 0, limit = 30) {
22
22
  const result = await this._fetchGet(`?langCode=${langCode}&offset=${offset}&limit=${limit}`);
23
- return this._normalizeData(result, langCode);
23
+ return this._dataPostProcess(result, langCode);
24
24
  }
25
25
  /**
26
26
  * Get one form by form marker.
@@ -32,7 +32,7 @@ class FormsApi extends oneEntry_1.default {
32
32
  */
33
33
  async getFormByMarker(marker, langCode = this._defaultLangCode) {
34
34
  const result = await this._fetchGet(`/marker/${marker}?langCode=${langCode}`);
35
- return this._normalizeData(result, langCode);
35
+ return this._dataPostProcess(result, langCode);
36
36
  }
37
37
  }
38
38
  exports.default = FormsApi;
@@ -26,12 +26,12 @@ interface IForms {
26
26
  */
27
27
  interface IFormsEntity {
28
28
  attributeSetId: number | null;
29
- attributes: Array<IAttributes>;
29
+ attributes: Array<IAttributes> | Record<string, any>;
30
30
  id: number;
31
31
  identifier: string;
32
32
  localizeInfos: Record<string, any>;
33
33
  position: number;
34
- processingData: object | string;
34
+ processingData: Record<string, any> | string;
35
35
  processingType: string;
36
36
  version: number;
37
37
  }
@@ -20,7 +20,7 @@ class FormsDataApi extends oneEntry_1.default {
20
20
  */
21
21
  async getFormsData(langCode = this._defaultLangCode, offset = 0, limit = 30) {
22
22
  const result = await this._fetchGet(`?langCode=${langCode}&offset=${offset}&limit=${limit}`);
23
- return this._normalizeData(result.items, langCode);
23
+ return this._dataPostProcess(result.items, langCode);
24
24
  }
25
25
  /**
26
26
  * Find all product page objects with pagination and multiple filtering.
@@ -42,7 +42,7 @@ class FormsDataApi extends oneEntry_1.default {
42
42
  */
43
43
  async postFormsData(data) {
44
44
  const result = await this._fetchPost('', JSON.stringify(data));
45
- return this._normalizeData(result);
45
+ return this._dataPostProcess(result);
46
46
  }
47
47
  /**
48
48
  * Get one object of form data by marker.
@@ -56,7 +56,7 @@ class FormsDataApi extends oneEntry_1.default {
56
56
  */
57
57
  async getFormsDataByMarker(marker, langCode = this._defaultLangCode, offset = 0, limit = 30) {
58
58
  const result = await this._fetchGet(`/marker/${marker}?langCode=${langCode}&offset=${offset}&limit=${limit}`);
59
- return this._normalizeData(result.items, langCode);
59
+ return this._dataPostProcess(result.items, langCode);
60
60
  }
61
61
  }
62
62
  exports.default = FormsDataApi;
@@ -47,7 +47,10 @@ interface IFormData {
47
47
  [langcode: string]: Array<{
48
48
  marker?: string;
49
49
  value?: string;
50
- }>;
50
+ }> | {
51
+ marker?: string;
52
+ value?: string;
53
+ };
51
54
  }
52
55
  /**
53
56
  * interface to create an object of information about saving data using the form
@@ -35,7 +35,7 @@ class MenusApi extends oneEntry_1.default {
35
35
  return page;
36
36
  });
37
37
  result.pages = pages;
38
- return this._normalizeData(result, langCode);
38
+ return this._dataPostProcess(result, langCode);
39
39
  }
40
40
  }
41
41
  exports.default = MenusApi;
@@ -18,7 +18,7 @@ interface IMenus {
18
18
  * @property {number | null} parentId - The menu parent id.
19
19
  */
20
20
  interface IMenusPages {
21
- children?: Array<IMenusPages>;
21
+ children?: Array<IMenusPages> | IMenusPages;
22
22
  id: number;
23
23
  pageUrl: string;
24
24
  localizeInfos: Record<string, any>;
@@ -38,6 +38,6 @@ interface IMenusEntity {
38
38
  id: number;
39
39
  identifier: string;
40
40
  localizeInfos: Record<string, any>;
41
- pages: Array<IMenusPages>;
41
+ pages: Array<IMenusPages> | IMenusPages;
42
42
  }
43
43
  export { IMenus, IMenusEntity };
@@ -62,11 +62,11 @@ interface IPositionForm {
62
62
  id: number;
63
63
  version: number;
64
64
  identifier: string;
65
- attributes: Array<IAttributes>;
65
+ attributes: Array<IAttributes> | IAttributes;
66
66
  attributeSetId: number;
67
67
  processingType: string;
68
68
  localizeInfos: Record<string, any>;
69
- processingData: object;
69
+ processingData: Record<string, any>;
70
70
  position: number;
71
71
  }
72
72
  /**
@@ -133,7 +133,7 @@ export default class ProductApi extends OneEntry implements IProductApi {
133
133
  *
134
134
  * @param {number} [id] - Product id.
135
135
  *
136
- * @param {string} [langCode] Language code parameter. Default "en_US". You can also pass several language parameters ['en_US', 'it_IT']
136
+ * @param {string} [langCode] Language code parameter. Default "en_US".
137
137
  *
138
138
  * @returns ProductEntity object.
139
139
  */
@@ -45,7 +45,7 @@ class ProductApi extends oneEntry_1.default {
45
45
  async getProducts(langCode = this._defaultLangCode, userQuery) {
46
46
  const query = { ...this._defaultQuery, ...userQuery };
47
47
  const result = await this._fetchGet(`?langCode=${langCode}&` + this._queryParamsToString(query));
48
- return this._normalizeData(result.items, langCode);
48
+ return this._dataPostProcess(result.items, langCode);
49
49
  }
50
50
  /**
51
51
  * Search for all product page objects with pagination that do not have a category.
@@ -73,7 +73,7 @@ class ProductApi extends oneEntry_1.default {
73
73
  async getProductsEmptyPage(langCode = this._defaultLangCode, userQuery) {
74
74
  const query = { ...this._defaultQuery, ...userQuery };
75
75
  const result = await this._fetchGet(`/empty-page?langCode=${langCode}&` + this._queryParamsToString(query));
76
- return this._normalizeData(result.items, langCode);
76
+ return this._dataPostProcess(result.items, langCode);
77
77
  }
78
78
  /**
79
79
  * Search for all product page objects with pagination for the selected category.
@@ -104,7 +104,7 @@ class ProductApi extends oneEntry_1.default {
104
104
  async getProductsPageById(id, langCode = this._defaultLangCode, userQuery) {
105
105
  const query = { ...this._defaultQuery, ...userQuery };
106
106
  const result = await this._fetchGet(`/page/${id}?langCode=${langCode}&` + this._queryParamsToString(query));
107
- return this._normalizeData(result.items, langCode);
107
+ return this._dataPostProcess(result.items, langCode);
108
108
  }
109
109
  /**
110
110
  * Search for all product page objects with pagination for the selected category (by its URL).
@@ -135,7 +135,7 @@ class ProductApi extends oneEntry_1.default {
135
135
  async getProductsPageByUrl(url = this._defaultLangCode, langCode, userQuery) {
136
136
  const query = { ...this._defaultQuery, ...userQuery };
137
137
  const result = await this._fetchGet(`/page/url/${url}?langCode=${langCode}&` + this._queryParamsToString(query));
138
- return this._normalizeData(result.items, langCode);
138
+ return this._dataPostProcess(result.items, langCode);
139
139
  }
140
140
  /**
141
141
  * Find all related product page objects.
@@ -158,20 +158,20 @@ class ProductApi extends oneEntry_1.default {
158
158
  async getRelatedProductsById(id, langCode = this._defaultLangCode, userQuery) {
159
159
  const query = { ...this._defaultQuery, ...userQuery };
160
160
  const result = await this._fetchGet(`/${id}/related?langCode=${langCode}&` + this._queryParamsToString(query));
161
- return this._normalizeData(result.items, langCode);
161
+ return this._dataPostProcess(result.items, langCode);
162
162
  }
163
163
  /**
164
164
  * Retrieve one product object.
165
165
  *
166
166
  * @param {number} [id] - Product id.
167
167
  *
168
- * @param {string} [langCode] Language code parameter. Default "en_US". You can also pass several language parameters ['en_US', 'it_IT']
168
+ * @param {string} [langCode] Language code parameter. Default "en_US".
169
169
  *
170
170
  * @returns ProductEntity object.
171
171
  */
172
172
  async getProductById(id, langCode = this._defaultLangCode) {
173
173
  const result = await this._fetchGet(`/${id}?langCode=${langCode}`);
174
- return this._normalizeData(result, langCode);
174
+ return this._dataPostProcess(result, langCode);
175
175
  }
176
176
  /**
177
177
  * Find all product page objects with pagination and multiple filtering.
@@ -244,7 +244,7 @@ class ProductApi extends oneEntry_1.default {
244
244
  productsList.push(result);
245
245
  });
246
246
  }));
247
- return this._normalizeData(productsList, langCode);
247
+ return this._dataPostProcess(productsList, langCode);
248
248
  }
249
249
  }
250
250
  exports.default = ProductApi;
@@ -117,6 +117,6 @@ interface IProductsEntity {
117
117
  shortDescTemplateIdentifier: string;
118
118
  attributeValues: Record<string, any>;
119
119
  position: number;
120
- productPages: Array<Object>;
120
+ productPages: Array<Record<string, any>> | Record<string, any>;
121
121
  }
122
122
  export { IFilterParams, IProductsQuery, IProductApi, IProductsEntity };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneentry",
3
- "version": "1.0.49",
3
+ "version": "1.0.51",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",