oneentry 1.0.65 → 1.0.67

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.
Files changed (59) hide show
  1. package/README.md +304 -243
  2. package/dist/_cjs/admins/adminsApi.d.ts +1 -1
  3. package/dist/admins/adminsApi.d.ts +6 -4
  4. package/dist/admins/adminsApi.js +6 -6
  5. package/dist/attribute-sets/attributeSetsApi.d.ts +6 -4
  6. package/dist/attribute-sets/attributeSetsApi.js +7 -7
  7. package/dist/auth-provider/authProviderApi.d.ts +6 -4
  8. package/dist/auth-provider/authProviderApi.js +14 -10
  9. package/dist/auth-provider/authProvidersInterfaces.d.ts +2 -2
  10. package/dist/base/asyncModules.d.ts +16 -0
  11. package/dist/base/asyncModules.js +164 -0
  12. package/dist/base/modules.d.ts +14 -0
  13. package/dist/base/modules.js +173 -0
  14. package/dist/base/oneEntry.d.ts +0 -23
  15. package/dist/base/oneEntry.js +74 -236
  16. package/dist/base/stateModule.d.ts +10 -0
  17. package/dist/base/stateModule.js +13 -0
  18. package/dist/base/syncModules.d.ts +14 -0
  19. package/dist/base/syncModules.js +72 -0
  20. package/dist/blocks/blocksApi.d.ts +9 -6
  21. package/dist/blocks/blocksApi.js +17 -16
  22. package/dist/blocks/blocksInterfaces.d.ts +3 -2
  23. package/dist/events/eventsApi.d.ts +6 -4
  24. package/dist/events/eventsApi.js +5 -5
  25. package/dist/file-uploding/fileUploadingApi.d.ts +6 -4
  26. package/dist/file-uploding/fileUploadingApi.js +6 -6
  27. package/dist/forms/formsApi.d.ts +7 -5
  28. package/dist/forms/formsApi.js +8 -8
  29. package/dist/formsData/formsDataApi.d.ts +8 -6
  30. package/dist/formsData/formsDataApi.js +10 -10
  31. package/dist/general-types/typesApi.d.ts +6 -4
  32. package/dist/general-types/typesApi.js +5 -5
  33. package/dist/index.js +22 -20
  34. package/dist/locales/localesApi.d.ts +6 -4
  35. package/dist/locales/localesApi.js +5 -5
  36. package/dist/menus/menusApi.d.ts +7 -5
  37. package/dist/menus/menusApi.js +7 -7
  38. package/dist/orders/ordersApi.d.ts +6 -4
  39. package/dist/orders/ordersApi.js +10 -10
  40. package/dist/pages/pagesApi.d.ts +6 -4
  41. package/dist/pages/pagesApi.js +16 -19
  42. package/dist/payments/paymentsApi.d.ts +6 -10
  43. package/dist/payments/paymentsApi.js +5 -14
  44. package/dist/payments/paymentsInterfaces.d.ts +0 -2
  45. package/dist/product-statuses/productStatusesApi.d.ts +6 -4
  46. package/dist/product-statuses/productStatusesApi.js +8 -8
  47. package/dist/products/productsApi.d.ts +107 -52
  48. package/dist/products/productsApi.js +119 -65
  49. package/dist/products/productsInterfaces.d.ts +16 -8
  50. package/dist/system/systemApi.d.ts +6 -4
  51. package/dist/system/systemApi.js +5 -5
  52. package/dist/templates/templatesApi.d.ts +9 -6
  53. package/dist/templates/templatesApi.js +9 -9
  54. package/dist/templates/templatesInterfaces.d.ts +2 -1
  55. package/dist/templates-preview/templatesPreviewApi.d.ts +8 -6
  56. package/dist/templates-preview/templatesPreviewApi.js +10 -10
  57. package/dist/users/usersApi.d.ts +6 -4
  58. package/dist/users/usersApi.js +7 -7
  59. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import OneEntry from "../base/oneEntry";
1
+ import OneEntry from "../base/modules";
2
2
  import { IAdminEntity, IAdmins } from "./adminsInterfaces";
3
3
  /**
4
4
  * Controllers for working with users - admins
@@ -1,11 +1,13 @@
1
- import OneEntry from "../base/oneEntry";
1
+ import AsyncModules from "../base/asyncModules";
2
2
  import { IAdminEntity, IAdmins } from "./adminsInterfaces";
3
- import { IConfig } from "../base/utils";
3
+ import StateModule from "../base/stateModule";
4
4
  /**
5
5
  * Controllers for working with users - admins
6
6
  */
7
- export default class AdminsApi extends OneEntry implements IAdmins {
8
- constructor(url: string, config: IConfig);
7
+ export default class AdminsApi extends AsyncModules implements IAdmins {
8
+ protected state: StateModule;
9
+ protected _url: string;
10
+ constructor(state: StateModule);
9
11
  /**
10
12
  * Get all user objects - admins.
11
13
  *
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const oneEntry_1 = require("../base/oneEntry");
3
+ const asyncModules_1 = require("../base/asyncModules");
4
4
  /**
5
5
  * Controllers for working with users - admins
6
6
  */
7
- class AdminsApi extends oneEntry_1.default {
8
- constructor(url, config) {
9
- super(url, config);
10
- this._url += '/api/content/admins';
7
+ class AdminsApi extends asyncModules_1.default {
8
+ constructor(state) {
9
+ super(state);
10
+ this._url = state.url + '/api/content/admins';
11
11
  }
12
12
  /**
13
13
  * Get all user objects - admins.
@@ -18,7 +18,7 @@ class AdminsApi extends oneEntry_1.default {
18
18
  *
19
19
  * @returns Returns all AdminEntity user objects
20
20
  */
21
- async getAdminsInfo(langCode = this._defaultLangCode, offset = 0, limit = 30) {
21
+ async getAdminsInfo(langCode = this.state.lang, offset = 0, limit = 30) {
22
22
  const response = await this._fetchGet(`?langCode=${langCode}&offset=${offset}&limit=${limit}`);
23
23
  return this._normalizeData(response, langCode);
24
24
  }
@@ -1,11 +1,13 @@
1
- import OneEntry from "../base/oneEntry";
1
+ import AsyncModules from "../base/asyncModules";
2
2
  import { IAttributesSets, IAttributesSetsEntity } from "./attributeSetsInterfaces";
3
- import { IConfig } from "../base/utils";
3
+ import StateModule from "../base/stateModule";
4
4
  /**
5
5
  * Controllers for working with attributes.
6
6
  */
7
- export default class AttributesSetsApi extends OneEntry implements IAttributesSets {
8
- constructor(url: string, config: IConfig);
7
+ export default class AttributesSetsApi extends AsyncModules implements IAttributesSets {
8
+ protected state: StateModule;
9
+ protected _url: string;
10
+ constructor(state: StateModule);
9
11
  /**
10
12
  * Get all attributes with data from the attribute sets.
11
13
  *
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const oneEntry_1 = require("../base/oneEntry");
3
+ const asyncModules_1 = require("../base/asyncModules");
4
4
  /**
5
5
  * Controllers for working with attributes.
6
6
  */
7
- class AttributesSetsApi extends oneEntry_1.default {
8
- constructor(url, config) {
9
- super(url, config);
10
- this._url += '/api/content/attributes-sets';
7
+ class AttributesSetsApi extends asyncModules_1.default {
8
+ constructor(state) {
9
+ super(state);
10
+ this._url = state.url + '/api/content/attributes-sets';
11
11
  }
12
12
  /**
13
13
  * Get all attributes with data from the attribute sets.
@@ -17,7 +17,7 @@ class AttributesSetsApi extends oneEntry_1.default {
17
17
  *
18
18
  * @returns Returns an array of AttributeInSet objects.
19
19
  */
20
- async getAttributesByMarker(marker, langCode = this._defaultLangCode) {
20
+ async getAttributesByMarker(marker, langCode = this.state.lang) {
21
21
  const result = await this._fetchGet(`/${marker}/attributes?langCode=${langCode}`);
22
22
  return this._dataPostProcess(result, langCode);
23
23
  }
@@ -30,7 +30,7 @@ class AttributesSetsApi extends oneEntry_1.default {
30
30
  *
31
31
  * @returns Returns a AttributeInSet object.
32
32
  */
33
- async getSingleAttributeByMarkerSet(attributeMarker, setMarker, langCode = this._defaultLangCode) {
33
+ async getSingleAttributeByMarkerSet(attributeMarker, setMarker, langCode = this.state.lang) {
34
34
  const result = await this._fetchGet(`/${setMarker}/attributes/${attributeMarker}?langCode=${langCode}`);
35
35
  return result;
36
36
  }
@@ -1,11 +1,13 @@
1
- import OneEntry from "../base/oneEntry";
2
- import { IConfig } from "../base/utils";
1
+ import AsyncModules from "../base/asyncModules";
3
2
  import { IAuthProvider, ISignUpData, ISignUpEntity, ICodeEntity, IAuthEntity, IAuthProvidersEntity, IAuthPostBody } from "./authProvidersInterfaces";
3
+ import StateModule from "../base/stateModule";
4
4
  /**
5
5
  * Controllers for working with auth services.
6
6
  */
7
- export default class AuthProviderApi extends OneEntry implements IAuthProvider {
8
- constructor(url: string, config: IConfig);
7
+ export default class AuthProviderApi extends AsyncModules implements IAuthProvider {
8
+ protected state: StateModule;
9
+ protected _url: string;
10
+ constructor(state: StateModule);
9
11
  /**
10
12
  * User registration
11
13
  * @param {string} marker - The text identifier of the authorization provider. Example - email
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const oneEntry_1 = require("../base/oneEntry");
3
+ const asyncModules_1 = require("../base/asyncModules");
4
4
  /**
5
5
  * Controllers for working with auth services.
6
6
  */
7
- class AuthProviderApi extends oneEntry_1.default {
8
- constructor(url, config) {
9
- super(url, config);
10
- this._url += '/api/content/users-auth-providers';
7
+ class AuthProviderApi extends asyncModules_1.default {
8
+ constructor(state) {
9
+ super(state);
10
+ this._url = state.url + '/api/content/users-auth-providers';
11
11
  }
12
12
  /**
13
13
  * User registration
@@ -42,7 +42,7 @@ class AuthProviderApi extends oneEntry_1.default {
42
42
  * }
43
43
  * }
44
44
  */
45
- async signUp(marker, data, langCode = this._defaultLangCode) {
45
+ async signUp(marker, data, langCode = this.state.lang) {
46
46
  const body = this._normalizePostBody(data, langCode);
47
47
  const result = await this._fetchPost(`/marker/${marker}/users/sign-up`, body);
48
48
  return this._normalizeData(result);
@@ -95,7 +95,8 @@ class AuthProviderApi extends oneEntry_1.default {
95
95
  */
96
96
  async auth(marker, data) {
97
97
  const result = await this._fetchPost(`/marker/${marker}/users/auth`, data);
98
- this._userToken = result.accessToken;
98
+ this.state.userToken = result.accessToken;
99
+ this.state.refreshToken = result.refreshToken;
99
100
  return result;
100
101
  }
101
102
  /**
@@ -107,6 +108,8 @@ class AuthProviderApi extends oneEntry_1.default {
107
108
  async refresh(marker, token) {
108
109
  const data = { refreshToken: token };
109
110
  const result = await this._fetchPost(`/marker/${marker}/users/refresh`, data);
111
+ this.state.userToken = result.accessToken;
112
+ this.state.refreshToken = result.refreshToken;
110
113
  return result;
111
114
  }
112
115
  /**
@@ -120,7 +123,8 @@ class AuthProviderApi extends oneEntry_1.default {
120
123
  };
121
124
  const result = await this._fetchPost(`/marker/${marker}/users/logout`, data);
122
125
  if (result) {
123
- this._userToken = null;
126
+ this.state.userToken = undefined;
127
+ this.state.refreshToken = undefined;
124
128
  }
125
129
  return result;
126
130
  }
@@ -148,7 +152,7 @@ class AuthProviderApi extends oneEntry_1.default {
148
152
  * @param {number} [offset] - Parameter for pagination. Default 0
149
153
  * @param {number} [limit] - Parameter for pagination. Default 30
150
154
  */
151
- async getAuthProviders(langCode = this._defaultLangCode, offset = 0, limit = 30) {
155
+ async getAuthProviders(langCode = this.state.lang, offset = 0, limit = 30) {
152
156
  const result = await this._fetchGet(`?langCode=${langCode}&offset=${offset}&limit=${limit}`);
153
157
  return this._normalizeData(result);
154
158
  }
@@ -157,7 +161,7 @@ class AuthProviderApi extends oneEntry_1.default {
157
161
  * @param {string} marker - The text identifier of the authorization provider. Example - email
158
162
  * @param {string} [langCode] - Optional parameter language code. Default "en_US"
159
163
  */
160
- async getMarker(marker, langCode = this._defaultLangCode) {
164
+ async getMarker(marker, langCode = this.state.lang) {
161
165
  const result = await this._fetchGet(`/marker/${marker}?langCode=${langCode}`);
162
166
  return this._normalizeData(result);
163
167
  }
@@ -31,7 +31,7 @@ interface IAuthFormData {
31
31
  interface ISignUpData {
32
32
  formIdentifier: string;
33
33
  authData: Array<{
34
- marker: 'login' | 'password';
34
+ marker: string;
35
35
  value: string;
36
36
  }>;
37
37
  formData: IAuthFormData | Array<IAuthFormData>;
@@ -49,7 +49,7 @@ interface ISignUpEntity {
49
49
  isActive: boolean;
50
50
  authProviderId: number;
51
51
  formData: Array<{
52
- marker: 'login' | 'password';
52
+ marker: string;
53
53
  value: string;
54
54
  }>;
55
55
  notificationData: IAuthFormData | Array<IAuthFormData>;
@@ -0,0 +1,16 @@
1
+ import SyncModules from "./syncModules";
2
+ import StateModule from "./stateModule";
3
+ export default abstract class AsyncModules extends SyncModules {
4
+ protected state: StateModule;
5
+ protected _NO_FETCH: boolean;
6
+ protected _https: any;
7
+ protected _url: string;
8
+ protected constructor(state: StateModule);
9
+ protected _fetchGet(path: string): Promise<any>;
10
+ protected _fetchPost(path: string, data: any): Promise<any>;
11
+ protected _fetchPut(path: string, data: any): Promise<any>;
12
+ protected _fetchDelete(path: string, data?: any): Promise<any>;
13
+ protected refreshToken(): Promise<boolean>;
14
+ private makeOptions;
15
+ private browserResponse;
16
+ }
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const syncModules_1 = require("./syncModules");
4
+ class AsyncModules extends syncModules_1.default {
5
+ constructor(state) {
6
+ super(state);
7
+ this._url = this.state.url;
8
+ this.state = state;
9
+ this._NO_FETCH = !!(typeof process === 'object' && process.versions);
10
+ try {
11
+ this._https = this._NO_FETCH ? require('https') : null;
12
+ }
13
+ catch (e) {
14
+ this._https = null;
15
+ }
16
+ }
17
+ async _fetchGet(path) {
18
+ const options = this.makeOptions('GET');
19
+ if (!this._NO_FETCH) {
20
+ return await this.browserResponse(path, options);
21
+ }
22
+ else {
23
+ return new Promise((resolve, reject) => {
24
+ const req = this._https.get(this._getFullPath(path), options, (res) => {
25
+ let data = '';
26
+ res.on('data', (chunk) => {
27
+ data += chunk;
28
+ });
29
+ res.on('end', () => {
30
+ resolve(JSON.parse(data));
31
+ });
32
+ });
33
+ req.on('error', (error) => {
34
+ reject(error);
35
+ });
36
+ });
37
+ }
38
+ }
39
+ async _fetchPost(path, data) {
40
+ const options = this.makeOptions('POST', data);
41
+ if (!this._NO_FETCH) {
42
+ return await this.browserResponse(path, options);
43
+ }
44
+ else {
45
+ return new Promise((resolve, reject) => {
46
+ const req = this._https.request(this._getFullPath(path), options, (res) => {
47
+ let responseData = '';
48
+ res.on('data', (chunk) => {
49
+ responseData += chunk;
50
+ });
51
+ res.on('end', () => {
52
+ resolve(JSON.parse(responseData));
53
+ });
54
+ });
55
+ req.on('error', (error) => {
56
+ reject(error);
57
+ });
58
+ req.write(JSON.stringify(data));
59
+ req.end();
60
+ });
61
+ }
62
+ }
63
+ async _fetchPut(path, data) {
64
+ const options = this.makeOptions('PUT', data);
65
+ if (!this._NO_FETCH) {
66
+ return await this.browserResponse(path, options);
67
+ }
68
+ else {
69
+ return new Promise((resolve, reject) => {
70
+ const req = this._https.request(this._getFullPath(path), options, (res) => {
71
+ let responseData = '';
72
+ res.on('data', (chunk) => {
73
+ responseData += chunk;
74
+ });
75
+ res.on('end', () => {
76
+ resolve(JSON.parse(responseData));
77
+ });
78
+ });
79
+ req.on('error', (error) => {
80
+ reject(error);
81
+ });
82
+ req.write(JSON.stringify(data));
83
+ req.end();
84
+ });
85
+ }
86
+ }
87
+ async _fetchDelete(path, data) {
88
+ const options = this.makeOptions('DELETE');
89
+ if (!this._NO_FETCH) {
90
+ return await this.browserResponse(path, options);
91
+ }
92
+ else {
93
+ return new Promise((resolve, reject) => {
94
+ const req = this._https.delete(this._getFullPath(path), options, (res) => {
95
+ let data = '';
96
+ res.on('data', (chunk) => {
97
+ data += chunk;
98
+ });
99
+ res.on('end', () => {
100
+ resolve(JSON.parse(data));
101
+ });
102
+ });
103
+ req.on('error', (error) => {
104
+ reject(error);
105
+ });
106
+ });
107
+ }
108
+ }
109
+ async refreshToken() {
110
+ console.log('ref token', this.state.refreshToken);
111
+ const response = await fetch(this.state.url + `/api/content/users-auth-providers/marker/email/users/refresh`, {
112
+ method: 'POST',
113
+ headers: {
114
+ 'Content-Type': 'application/json',
115
+ 'x-app-token': this.state.token
116
+ },
117
+ body: JSON.stringify({ refreshToken: this.state.refreshToken })
118
+ });
119
+ if (response.ok) {
120
+ const result = await response.json();
121
+ this.state.refreshToken = result.refreshToken;
122
+ this.state.userToken = result.accessToken;
123
+ return true;
124
+ }
125
+ else {
126
+ return false;
127
+ }
128
+ }
129
+ makeOptions(method, data) {
130
+ const options = {
131
+ method: method,
132
+ headers: {
133
+ 'Content-Type': 'application/json',
134
+ 'x-app-token': this.state.token,
135
+ }
136
+ };
137
+ if (data instanceof FormData || data instanceof Blob) {
138
+ delete options.headers['Content-Type'];
139
+ }
140
+ if (data) {
141
+ options['body'] = JSON.stringify(data);
142
+ }
143
+ if (this.state.userToken) {
144
+ options.headers['Authorization'] = 'Bearer ' + this.state.userToken;
145
+ }
146
+ return options;
147
+ }
148
+ async browserResponse(path, options) {
149
+ const response = await fetch(this._getFullPath(path), options);
150
+ if (response.status == 401) {
151
+ const refresh = await this.refreshToken();
152
+ if (refresh) {
153
+ const secondResponse = await fetch(this._getFullPath(path), options);
154
+ return await secondResponse.json();
155
+ }
156
+ }
157
+ if (!response.ok) {
158
+ const error = await response.json();
159
+ throw error;
160
+ }
161
+ return await response.json();
162
+ }
163
+ }
164
+ exports.default = AsyncModules;
@@ -0,0 +1,14 @@
1
+ import { IConfig } from "./utils";
2
+ import SyncModules from "./syncModules";
3
+ export default abstract class Modules extends SyncModules {
4
+ protected _token: string | undefined;
5
+ protected _userToken: string | undefined;
6
+ protected _multipleResponse: boolean;
7
+ protected _NO_FETCH: boolean;
8
+ protected _https: any;
9
+ constructor(url: string, config?: IConfig);
10
+ protected _fetchGet(path: string): Promise<any>;
11
+ protected _fetchPost(path: string, data: any): Promise<any>;
12
+ protected _fetchPut(path: string, data: any): Promise<any>;
13
+ protected _fetchDelete(path: string, data?: any): Promise<any>;
14
+ }
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const syncModules_1 = require("./syncModules");
4
+ class Modules extends syncModules_1.default {
5
+ constructor(url, config = {}) {
6
+ var _a;
7
+ super(url, config);
8
+ this._token = config.token;
9
+ this._userToken = config.userToken;
10
+ this._multipleResponse = (_a = config.multipleRequests) !== null && _a !== void 0 ? _a : true;
11
+ this._NO_FETCH = !!(typeof process === 'object' && process.versions);
12
+ try {
13
+ this._https = this._NO_FETCH ? require('https') : null;
14
+ }
15
+ catch (e) {
16
+ this._https = null;
17
+ }
18
+ }
19
+ async _fetchGet(path) {
20
+ const options = {
21
+ method: 'GET',
22
+ headers: {
23
+ 'Content-Type': 'application/json',
24
+ 'x-app-token': this._token,
25
+ 'Authorization': this._userToken
26
+ }
27
+ };
28
+ if (!this._NO_FETCH) {
29
+ const response = await fetch(this._getFullPath(path), options);
30
+ if (!response.ok) {
31
+ const error = await response.json();
32
+ throw error;
33
+ }
34
+ return await response.json();
35
+ }
36
+ else {
37
+ return new Promise((resolve, reject) => {
38
+ const req = this._https.get(this._getFullPath(path), options, (res) => {
39
+ let data = '';
40
+ res.on('data', (chunk) => {
41
+ data += chunk;
42
+ });
43
+ res.on('end', () => {
44
+ resolve(JSON.parse(data));
45
+ });
46
+ });
47
+ req.on('error', (error) => {
48
+ reject(error);
49
+ });
50
+ });
51
+ }
52
+ }
53
+ async _fetchPost(path, data) {
54
+ const options = {
55
+ method: 'POST',
56
+ headers: {
57
+ 'x-app-token': this._token,
58
+ 'Content-Type': 'application/json',
59
+ 'Authorization': this._userToken ? 'Bearer ' + this._userToken : null
60
+ }
61
+ };
62
+ if (data instanceof FormData || data instanceof Blob) {
63
+ delete options.headers['Content-Type'];
64
+ }
65
+ if (!this._NO_FETCH) {
66
+ const response = await fetch(this._getFullPath(path), {
67
+ ...options,
68
+ body: JSON.stringify(data)
69
+ });
70
+ if (!response.ok) {
71
+ const error = await response.json();
72
+ throw error;
73
+ }
74
+ return await response.json();
75
+ }
76
+ else {
77
+ return new Promise((resolve, reject) => {
78
+ const req = this._https.request(this._getFullPath(path), options, (res) => {
79
+ let responseData = '';
80
+ res.on('data', (chunk) => {
81
+ responseData += chunk;
82
+ });
83
+ res.on('end', () => {
84
+ resolve(JSON.parse(responseData));
85
+ });
86
+ });
87
+ req.on('error', (error) => {
88
+ reject(error);
89
+ });
90
+ req.write(JSON.stringify(data));
91
+ req.end();
92
+ });
93
+ }
94
+ }
95
+ async _fetchPut(path, data) {
96
+ const options = {
97
+ method: 'PUT',
98
+ headers: {
99
+ 'x-app-token': this._token,
100
+ 'Content-Type': 'application/json',
101
+ 'Authorization': this._userToken ? 'Bearer ' + this._userToken : null
102
+ },
103
+ };
104
+ if (data instanceof FormData || data instanceof Blob) {
105
+ delete options.headers['Content-Type'];
106
+ }
107
+ if (!this._NO_FETCH) {
108
+ const response = await fetch(this._getFullPath(path), {
109
+ ...options,
110
+ body: JSON.stringify(data),
111
+ });
112
+ if (!response.ok) {
113
+ const error = await response.json();
114
+ throw error;
115
+ }
116
+ return await response.json();
117
+ }
118
+ else {
119
+ return new Promise((resolve, reject) => {
120
+ const req = this._https.request(this._getFullPath(path), options, (res) => {
121
+ let responseData = '';
122
+ res.on('data', (chunk) => {
123
+ responseData += chunk;
124
+ });
125
+ res.on('end', () => {
126
+ resolve(JSON.parse(responseData));
127
+ });
128
+ });
129
+ req.on('error', (error) => {
130
+ reject(error);
131
+ });
132
+ req.write(JSON.stringify(data));
133
+ req.end();
134
+ });
135
+ }
136
+ }
137
+ async _fetchDelete(path, data) {
138
+ const options = {
139
+ method: 'DELETE',
140
+ headers: {
141
+ 'Content-Type': 'application/json',
142
+ 'x-app-token': this._token,
143
+ 'Authorization': this._userToken ? 'Bearer ' + this._userToken : null
144
+ },
145
+ body: data
146
+ };
147
+ if (!this._NO_FETCH) {
148
+ const response = await fetch(this._getFullPath(path), options);
149
+ if (!response.ok) {
150
+ const error = await response.json();
151
+ throw error;
152
+ }
153
+ return await response.json();
154
+ }
155
+ else {
156
+ return new Promise((resolve, reject) => {
157
+ const req = this._https.delete(this._getFullPath(path), options, (res) => {
158
+ let data = '';
159
+ res.on('data', (chunk) => {
160
+ data += chunk;
161
+ });
162
+ res.on('end', () => {
163
+ resolve(JSON.parse(data));
164
+ });
165
+ });
166
+ req.on('error', (error) => {
167
+ reject(error);
168
+ });
169
+ });
170
+ }
171
+ }
172
+ }
173
+ exports.default = Modules;
@@ -1,23 +0,0 @@
1
- import { IProductsQuery } from '../products/productsInterfaces';
2
- import { IConfig } from "./utils";
3
- import { IUploadingQuery } from "../file-uploding/fileUploadingInterfaces";
4
- export default abstract class OneEntry {
5
- protected _url: string;
6
- protected _token: string | undefined;
7
- protected _userToken: string | undefined;
8
- protected _defaultLangCode: string;
9
- protected _multipleResponse: boolean;
10
- protected _NO_FETCH: boolean;
11
- protected _https: any;
12
- constructor(url: string, config?: IConfig);
13
- protected _getFullPath(path: string): string;
14
- protected _fetchGet(path: string): Promise<any>;
15
- protected _fetchPost(path: string, data: any): Promise<any>;
16
- protected _fetchPut(path: string, data: any): Promise<any>;
17
- protected _fetchDelete(path: string, data?: any): Promise<any>;
18
- protected _queryParamsToString(query: IProductsQuery | IUploadingQuery): string;
19
- protected _normalizeData(data: any, langCode?: string): any;
20
- protected _normalizePostBody(body: any, langCode?: string): any;
21
- protected _clearArray(data: Record<string, any>): any;
22
- protected _dataPostProcess(data: any, langCode?: string): any;
23
- }