oneentry 1.0.36 → 1.0.39

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.
@@ -9,7 +9,7 @@ export default abstract class OneEntry {
9
9
  constructor(url: string, token?: string);
10
10
  protected _getFullPath(path: string): string;
11
11
  protected _fetchGet(path: string): Promise<any>;
12
- protected _fetchPost(path: string, data: object): Promise<any>;
12
+ protected _fetchPost(path: string, data: any): Promise<any>;
13
13
  protected _fetchDelete(path: string): Promise<any>;
14
14
  protected _queryParamsToString(query: IProductsQuery | IUploadingQuery): string;
15
15
  protected _parseLangFromString(str: string, lang: string): string;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const https = require('https');
4
3
  class OneEntry {
5
4
  constructor(url, token) {
6
5
  this._LANGCODE_KEY = '$LANGCODE';
@@ -30,6 +29,7 @@ class OneEntry {
30
29
  return result;
31
30
  }
32
31
  else {
32
+ const https = require('https');
33
33
  return new Promise((resolve, reject) => {
34
34
  const req = https.get(this._getFullPath(path), options, (res) => {
35
35
  let data = '';
@@ -50,18 +50,22 @@ class OneEntry {
50
50
  const options = {
51
51
  method: 'POST',
52
52
  headers: {
53
- 'Content-Type': 'application/json',
54
53
  'x-app-token': this._token,
54
+ 'Content-Type': 'application/json'
55
55
  }
56
56
  };
57
+ if (data instanceof FormData) {
58
+ delete options.headers['Content-Type'];
59
+ }
57
60
  if (!this._NO_FETCH) {
58
61
  const response = await fetch(this._getFullPath(path), {
59
62
  ...options,
60
- body: JSON.stringify(data)
63
+ body: data
61
64
  });
62
65
  return await response.json();
63
66
  }
64
67
  else {
68
+ const https = require('https');
65
69
  return new Promise((resolve, reject) => {
66
70
  const req = https.request(this._getFullPath(path), options, (res) => {
67
71
  let responseData = '';
@@ -75,7 +79,7 @@ class OneEntry {
75
79
  req.on('error', (error) => {
76
80
  reject(error);
77
81
  });
78
- req.write(JSON.stringify(data));
82
+ req.write(data);
79
83
  req.end();
80
84
  });
81
85
  }
@@ -94,6 +98,7 @@ class OneEntry {
94
98
  return result;
95
99
  }
96
100
  else {
101
+ const https = require('https');
97
102
  return new Promise((resolve, reject) => {
98
103
  const req = https.get(this._getFullPath(path), options, (res) => {
99
104
  let data = '';
@@ -65,4 +65,4 @@ interface IAttributeSetEntity {
65
65
  }
66
66
  type LangType = string | Array<string>;
67
67
  type LocalizeType = ILocalizeInfos | ILocalizeInfo;
68
- export { LocalizeType, ILocalizeInfos, Types, IAttributeSetEntity, LangType, AttributeType, IAttributeValues, IAttributes };
68
+ export { LocalizeType, ILocalizeInfos, ILocalizeInfo, Types, IAttributeSetEntity, LangType, AttributeType, IAttributeValues, IAttributes };
@@ -9,19 +9,19 @@ export default class FileUploadingApi extends OneEntry implements IFileUploading
9
9
  /**
10
10
  * Upload file function.
11
11
  *
12
- * @param {Event} [data] Array of Express.Multer.File objects
12
+ * @param {File} [data] File objects. Get data as File from your unput as e.target.files[0]
13
13
  *
14
14
  * @param {IUploadingQuery} [fileQuery] - Optional set query parameters.
15
- * @param {string} [fileQuery.type] - Type, determines the folder name in the storage. Example : "page"
16
- * @param {string} [fileQuery.entity] - Entity name from which the file is uploaded, determines the folder name in the storage. Example : "editor"
17
- * @param {number} [fileQuery.id] - Identifier of the object from which the file is uploaded, determines the folder name in the storage. Example : 3787
15
+ * @param {string} fileQuery.type - Type, determines the folder name in the storage. Example : "page"
16
+ * @param {string} fileQuery.entity - Entity name from which the file is uploaded, determines the folder name in the storage. Example : "editor"
17
+ * @param {number} fileQuery.id - Identifier of the object from which the file is uploaded, determines the folder name in the storage. Example : 3787
18
18
  * @param {number} [fileQuery.width] - Optional width parameter. Example : 0
19
19
  * @param {number} [fileQuery.height] - Optional height parameter. Example : 0
20
20
  * @param {boolean} [fileQuery.compress] - Optional flag of optimization (compression) for images. Example : true
21
21
  *
22
22
  * @returns Uploads a file to an Amazon S3-compatible cloud file storage
23
23
  */
24
- upload(data: Event, fileQuery?: IUploadingQuery): Promise<IUploadingReturns>;
24
+ upload(data: File, fileQuery?: IUploadingQuery): Promise<IUploadingReturns>;
25
25
  /**
26
26
  * Deletes a file from the cloud file storage.
27
27
  *
@@ -20,12 +20,12 @@ class FileUploadingApi extends oneEntry_1.default {
20
20
  /**
21
21
  * Upload file function.
22
22
  *
23
- * @param {Event} [data] Array of Express.Multer.File objects
23
+ * @param {File} [data] File objects. Get data as File from your unput as e.target.files[0]
24
24
  *
25
25
  * @param {IUploadingQuery} [fileQuery] - Optional set query parameters.
26
- * @param {string} [fileQuery.type] - Type, determines the folder name in the storage. Example : "page"
27
- * @param {string} [fileQuery.entity] - Entity name from which the file is uploaded, determines the folder name in the storage. Example : "editor"
28
- * @param {number} [fileQuery.id] - Identifier of the object from which the file is uploaded, determines the folder name in the storage. Example : 3787
26
+ * @param {string} fileQuery.type - Type, determines the folder name in the storage. Example : "page"
27
+ * @param {string} fileQuery.entity - Entity name from which the file is uploaded, determines the folder name in the storage. Example : "editor"
28
+ * @param {number} fileQuery.id - Identifier of the object from which the file is uploaded, determines the folder name in the storage. Example : 3787
29
29
  * @param {number} [fileQuery.width] - Optional width parameter. Example : 0
30
30
  * @param {number} [fileQuery.height] - Optional height parameter. Example : 0
31
31
  * @param {boolean} [fileQuery.compress] - Optional flag of optimization (compression) for images. Example : true
@@ -34,7 +34,9 @@ class FileUploadingApi extends oneEntry_1.default {
34
34
  */
35
35
  async upload(data, fileQuery) {
36
36
  const query = { ...this._defaultQuery, ...fileQuery };
37
- const result = await this._fetchPost('?' + this._queryParamsToString(query), data);
37
+ const body = new FormData();
38
+ body.append('files', data);
39
+ const result = await this._fetchPost('?' + this._queryParamsToString(query), body);
38
40
  return result;
39
41
  }
40
42
  /**
@@ -6,7 +6,7 @@
6
6
  * @property {function} getFile - Get file by parameters.
7
7
  */
8
8
  interface IFileUploading {
9
- upload(data: Event, fileQuery?: IUploadingQuery): Promise<IUploadingReturns>;
9
+ upload(data: File, fileQuery?: IUploadingQuery): Promise<IUploadingReturns>;
10
10
  delete(filename: string, fileQuery?: IUploadingQuery): Promise<any>;
11
11
  getFile(id: number, type: string, entity: string, filename?: string): Promise<IFileEntity>;
12
12
  }
@@ -23,9 +23,9 @@ interface IFileEntity {
23
23
  * @property {boolean} [compress] - Flag of optimization (compression) for images.
24
24
  */
25
25
  interface IUploadingQuery {
26
- type?: string | null;
27
- entity?: string | null;
28
- id?: number | null;
26
+ type: string | null;
27
+ entity: string | null;
28
+ id: number | null;
29
29
  width?: number | null;
30
30
  height?: string | null;
31
31
  compress?: boolean | null;
@@ -20,7 +20,7 @@ class FormsDataApi extends oneEntry_1.default {
20
20
  */
21
21
  async getFormsData(langCode = 'en_US', offset = 0, limit = 30) {
22
22
  const result = await this._fetchGet(`?langCode=${langCode}&offset=${offset}&limit=${limit}`);
23
- return this._normalizeData(result);
23
+ return this._normalizeData(result.items);
24
24
  }
25
25
  /**
26
26
  * Find all product page objects with pagination and multiple filtering.
@@ -41,7 +41,7 @@ class FormsDataApi extends oneEntry_1.default {
41
41
  * @returns - Returns created FormData objects.
42
42
  */
43
43
  async postFormsData(data) {
44
- const result = await this._fetchPost('', data);
44
+ const result = await this._fetchPost('', JSON.stringify(data));
45
45
  return this._normalizeData(result);
46
46
  }
47
47
  /**
@@ -18,13 +18,22 @@ class MenusApi extends oneEntry_1.default {
18
18
  */
19
19
  async getMenusByMarker(marker) {
20
20
  const result = await this._fetchGet(`/marker/${marker}`);
21
- const pages = result.pages;
22
- pages.forEach(page => {
21
+ let pages = result.pages;
22
+ pages = pages.map(page => {
23
+ page = this._normalizeData(page);
24
+ for (const key in page.localizeInfos) {
25
+ if (key !== 'menuTitle') {
26
+ delete page.localizeInfos[key];
27
+ }
28
+ }
23
29
  const children = pages.filter(child => child.parentId === page.id);
24
30
  if (children.length) {
25
- page.children = children;
31
+ const normalizeChildren = children.map(child => this._normalizeData(child));
32
+ page.children = normalizeChildren;
26
33
  }
34
+ return page;
27
35
  });
36
+ result.pages = pages;
28
37
  return this._normalizeData(result);
29
38
  }
30
39
  }
@@ -1,4 +1,4 @@
1
- import { ILocalizeInfos } from "../base/utils";
1
+ import { ILocalizeInfo } from "../base/utils";
2
2
  /**
3
3
  * Represents an interface object of Menus Api.
4
4
  *
@@ -14,7 +14,7 @@ interface IMenus {
14
14
  * @property {Array<IMenusPages>} children - The optional parameter. Contains array with child page objects.
15
15
  * @property {number} id - The unique identifier of the menu.
16
16
  * @property {string} pageUrl - The page url string.
17
- * @property {ILocalizeInfos} localizeInfos - The menu data, taking into account localization.
17
+ * @property {ILocalizeInfo} localizeInfos - The menu data, taking into account localization.
18
18
  * @property {number} position - The menu position.
19
19
  * @property {number | null} parentId - The menu parent id.
20
20
  */
@@ -22,7 +22,7 @@ interface IMenusPages {
22
22
  children?: Array<IMenusPages>;
23
23
  id: number;
24
24
  pageUrl: string;
25
- localizeInfos: ILocalizeInfos;
25
+ localizeInfos: ILocalizeInfo;
26
26
  position: number;
27
27
  parentId: number | null;
28
28
  }
@@ -38,7 +38,7 @@ interface IMenusPages {
38
38
  interface IMenusEntity {
39
39
  id: number;
40
40
  identifier: string;
41
- localizeInfos: ILocalizeInfos;
41
+ localizeInfos: ILocalizeInfo;
42
42
  pages: Array<IMenusPages>;
43
43
  }
44
44
  export { IMenus, IMenusEntity };
@@ -223,7 +223,7 @@ class ProductApi extends oneEntry_1.default {
223
223
  async filterProduct(data, langCode = 'en_US', userQuery) {
224
224
  const query = { ...this._defaultQuery, ...userQuery };
225
225
  if (typeof langCode === 'string') {
226
- const response = await this._fetchPost(`/conditions-filter?langCode=${langCode}&` + this._queryParamsToString(query), data);
226
+ const response = await this._fetchPost(`/conditions-filter?langCode=${langCode}&` + this._queryParamsToString(query), JSON.stringify(data));
227
227
  const products = response.items;
228
228
  const result = products.map(item => this._normalizeData(item));
229
229
  return result;
@@ -231,7 +231,7 @@ class ProductApi extends oneEntry_1.default {
231
231
  else {
232
232
  const productList = [];
233
233
  await Promise.all(langCode.map(async (lang) => {
234
- const response = await this._fetchPost(`/conditions-filter?langCode=${lang}&` + this._queryParamsToString(query), data);
234
+ const response = await this._fetchPost(`/conditions-filter?langCode=${lang}&` + this._queryParamsToString(query), JSON.stringify(data));
235
235
  productList.push(response.items);
236
236
  }));
237
237
  const result = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneentry",
3
- "version": "1.0.36",
3
+ "version": "1.0.39",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",