oneentry 1.0.68 → 1.0.70

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
@@ -1,6 +1,6 @@
1
- # AsyncModules SDK
1
+ # OneEntry SDK
2
2
 
3
- AsyncModules Headless CMS SDK is an SDK that provides an easy way to interact with the AsyncModules Headless CMS API.
3
+ OneEntry Headless CMS SDK is an SDK that provides an easy way to interact with the OneEntry Headless CMS API.
4
4
 
5
5
  ## Official Site
6
6
 
@@ -52,12 +52,54 @@ Or
52
52
  ```js
53
53
  const api = defineOneEntry('your-url');
54
54
  ```
55
+ ---
56
+
57
+ ### Config
58
+ The second parameter of the constructor takes the 'config'. It contains the following values:
59
+
60
+ - 'token' - Set the token key if your project secure "Security API Token". If you are using certificate protection, do not pass this variable. You can read more about the security of your project [here](https://oneentry.cloud/instructions).
61
+
62
+ - 'langCode' - 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".
63
+
64
+ - 'traficLimit' - 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 "true" for this parameter to save traffic and decide for yourself what data you need. The default value "false".
65
+
66
+ - 'auth' - An object with authorization settings. By default, the SDK is configured to work with tokens inside the user's session and does not require any additional work from you. At the same time, the SDK does not store the session state between sessions. If you are satisfied with such settings, do not pass the variable 'auth' at all.
67
+
68
+ The 'auth' contains the following settings:
69
+
70
+ - 'refreshToken' - The user's refresh token. Transfer it here from the repository to restore the user's session during initialization.
71
+
72
+ - 'saveFunction' - A function that works with the update refresh token. If you want to store the token between sessions, for example in local storage, pass a function here that does this. The function must accept a parameter to which the string with the token will be passed.
73
+
74
+ - 'customAuth' - If you want to configure authorization and work with tokens yourself, set this flag to true. If you want to use the sdk settings, set it to false or do not transfer it at all.
75
+
76
+ An example of a configuration with token protection and automatic authentication that stores state between sessions
77
+ ```js
78
+ const tokenFunction = (token) => {
79
+ localStorage.setItem('refreshToken', token)
80
+ }
81
+
82
+ const api = defineOneEntry('https://my-project.oneentry.cloud', {
83
+ token:'my-token',
84
+ langCode:'en_US',
85
+ auth: {
86
+ refreshToken: localStorage.getItem('refreshToken'),
87
+ saveFunction: tokenFunction
88
+ }
89
+ })
90
+ ```
91
+
92
+ An example of a configuration that is protected with a certificate allows you to configure the authorization system yourself and saves data on requests.
93
+ ```js
94
+ const api = defineOneEntry('https://my-project.oneentry.cloud', {
95
+ langCode:'en_US',
96
+ traficLimit: true,
97
+ auth: {
98
+ customAuth: true
99
+ }
100
+ })
101
+ ```
55
102
 
56
- The second parameter of the function takes a configuration object with the keys "token", "langCode" and "multipleResponse".
57
- Set the token key if your project secure "Security API Token"
58
- If your project uses user authorization, pass the user REFRESH TOKEN to the "userToken" variable to use methods that require authorization.
59
- 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"
60
- 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"
61
103
 
62
104
  >If you chose token protection to ensure connection security, just pass your token to the function as an optional parameter.
63
105
 
@@ -70,14 +112,22 @@ You can get a token as follows
70
112
  6) Get and copy the token of your project
71
113
 
72
114
  You can also connect a tls certificate to protect your project. In this case, do not pass the "token" at all. When using the certificate, set up a proxy in your project. Pass an empty string as an url parameter.
73
- [Learn more about security](https://oneentry.ru/instructions.html#START)
115
+ [Learn more about security](https://oneentry.cloud/instructions)
74
116
 
75
117
 
76
118
  ```js
119
+ const saveTokenFromLocalStorage = (token) => {
120
+ localStorage.setItem('refreshToken', token)
121
+ }
122
+
77
123
  const api = defineOneEntry('your-url', {
78
124
  token: 'my-token',
79
- userToken: 'rerfesh.token',
80
125
  langCode:'my-langCode',
126
+ auth: {
127
+ customAuth: false,
128
+ userToken: 'rerfesh.token',
129
+ saveFunction: saveTokenFromLocalStorage
130
+ }
81
131
  })
82
132
  ```
83
133
 
@@ -215,15 +265,19 @@ Example return:
215
265
  "title": "red",
216
266
  "value": 1,
217
267
  "position": 1,
218
- "extendedValue": null,
219
- "extendedValueType": null
268
+ "extended": {
269
+ "value": null,
270
+ "type": null
271
+ }
220
272
  },
221
273
  {
222
274
  "title": "yellow",
223
275
  "value": 2,
224
276
  "position": 2,
225
- "extendedValue": null,
226
- "extendedValueType": null
277
+ "extended": {
278
+ "value": null,
279
+ "type": null
280
+ }
227
281
  }
228
282
  ]
229
283
  }
@@ -294,15 +348,19 @@ Example return:
294
348
  "title": "red",
295
349
  "value": 1,
296
350
  "position": 1,
297
- "extendedValue": null,
298
- "extendedValueType": null
351
+ "extended": {
352
+ "value": null,
353
+ "type": null
354
+ }
299
355
  },
300
356
  {
301
357
  "title": "yellow",
302
358
  "value": 2,
303
359
  "position": 2,
304
- "extendedValue": null,
305
- "extendedValueType": null
360
+ "extended": {
361
+ "value": null,
362
+ "type": null
363
+ }
306
364
  }
307
365
  ]
308
366
  }
@@ -316,8 +374,6 @@ example: list <br>
316
374
 
317
375
  **marker:** string <br>
318
376
  *textual identifier of the attribute (marker)* <br>
319
- Enum:
320
- [ string, text, textWithHeader, integer, real, float, dateTime, date, time, file, image, groupOfImages, radioButton, list, button ] <br>
321
377
  example: list1 <br>
322
378
 
323
379
  **position:** number <br>
@@ -446,7 +502,7 @@ example: OrderedMap { "en_US": List [ OrderedMap { "marker": "naimenovanie_1", "
446
502
 
447
503
  **notificationData:** UserNotificationDataType <br>
448
504
  *data for notifying the user* <br>
449
- example: OrderedMap { "email": "test@test.ru", "phonePush": "", "phoneSMS": "+79991234567" } <br>
505
+ example: OrderedMap { "email": "test@test.zone", "phonePush": "", "phoneSMS": "+79991234567" } <br>
450
506
 
451
507
  **systemCode:** string <br>
452
508
  *system code for performing official actions (password reset, activation)* <br>
@@ -474,37 +530,28 @@ example: 1 <br>
474
530
  const value = await AuthProvider.generateCode('email', 'test@trer.com')
475
531
  ```
476
532
 
477
- > This method receives a code to activate the user. Returns the object with the code.
533
+ > This method receives a code to activate the user. The code is returned via the appropriate user notification method
478
534
 
479
- Example return:
480
535
 
481
- ```json
482
- {
483
- "code": "90ВDCX",
484
- "expiredDate": "2024-05-07T21:02:00.000Z"
485
- }
486
- ```
536
+ ### AuthProvider.checkCode(marker, userIdentifier, code)
487
537
 
488
- <details>
489
- <summary>Schema</summary>
538
+ ```js
539
+ const value = await AuthProvider.checkCode('email', 'example@oneentry.cloud', 'WTGC9E')
540
+ ```
490
541
 
491
- **code:** string <br>
492
- *code for performing official actions (password reset, activation)*
493
- example: 90ВDCX <br>
542
+ > This method checks the user's code. Returns true (if the code is correct) or false (if it is incorrect).
494
543
 
495
- **expiredDate:** string <br>
496
- *object modification date* <br>
544
+ Example return:
497
545
 
498
- **expiredDate:** string <br>
499
- *the time and date until which the code is valid* <br>
500
- example: 2024-05-07T21:02:00.000Z <br>
501
- </details>
546
+ ```json
547
+ true
548
+ ```
502
549
 
503
550
 
504
551
  ### AuthProvider.activateUser(marker, userIdentifier, code)
505
552
 
506
553
  ```js
507
- const value = await AuthProvider.activateUser('email', 'test@trer.com', 'WTGC9E')
554
+ const value = await AuthProvider.activateUser('email', 'example@oneentry.cloud', 'WTGC9E')
508
555
  ```
509
556
 
510
557
  > This method activates the user by code. If successful, it will return true.
@@ -522,7 +569,7 @@ const data = {
522
569
  authData: [
523
570
  {
524
571
  marker: "login",
525
- value: "user@gmail.com"
572
+ value: "example@oneentry.cloud"
526
573
  },
527
574
  {
528
575
  marker: "password",
@@ -540,7 +587,7 @@ Example return:
540
587
 
541
588
  ```json
542
589
  {
543
- "userIdentifier": "test@test.ru",
590
+ "userIdentifier": "example@oneentry.cloud",
544
591
  "authProviderIdentifier": "email",
545
592
  "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiYXV0aFByb3ZpZGVySWRlbnRpZmllciI6ImVtYWlsIiwidXNlcklkZW50aWZpZXIiOiJ0ZXN0QHRlc3QucnUiLCJ1c2VyQWdlbnQiOiJQb3N0bWFuUnVudGltZS83LjM3LjMiLCJpYXQiOjE3MTQ1NTc2NzAsImV4cCI6MTcxNDU2MTI3MH0.vm74Ha-S37462CAF3QiDpO9b0OhlJFNDMKq4eEyoaB8",
546
593
  "refreshToken": "1714557670334-cb85112d-618d-4b2a-bad5-137b19c135b9"
@@ -551,7 +598,7 @@ Example return:
551
598
 
552
599
  **userIdentifier:** string <br>
553
600
  *user identifier*
554
- example: test@test.ru <br>
601
+ example: example@oneentry.cloud <br>
555
602
 
556
603
  **authProviderIdentifier:** string <br>
557
604
  *auth provider identifier* <br>
@@ -580,7 +627,7 @@ Example return:
580
627
 
581
628
  ```json
582
629
  {
583
- "userIdentifier": "test@test.ru",
630
+ "userIdentifier": "example@oneentry.cloud",
584
631
  "authProviderIdentifier": "email",
585
632
  "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiYXV0aFByb3ZpZGVySWRlbnRpZmllciI6ImVtYWlsIiwidXNlcklkZW50aWZpZXIiOiJ0ZXN0QHRlc3QucnUiLCJ1c2VyQWdlbnQiOiJQb3N0bWFuUnVudGltZS83LjM3LjMiLCJpYXQiOjE3MTQ1NTc2NzAsImV4cCI6MTcxNDU2MTI3MH0.vm74Ha-S37462CAF3QiDpO9b0OhlJFNDMKq4eEyoaB8",
586
633
  "refreshToken": "1714557670334-cb85112d-618d-4b2a-bad5-137b19c135b9"
@@ -591,7 +638,7 @@ Example return:
591
638
 
592
639
  **userIdentifier:** string <br>
593
640
  *user identifier*
594
- example: test@test.ru <br>
641
+ example: example@oneentry.cloud <br>
595
642
 
596
643
  **authProviderIdentifier:** string <br>
597
644
  *auth provider identifier* <br>
@@ -625,7 +672,7 @@ true
625
672
  ### AuthProvider.changePassword(marker, userIdentifier, code, newPassword, repeatPassword)
626
673
 
627
674
  ```js
628
- const value = await AuthProvider.changePassword('email', 'test@test.com', 'EW32RF', 654321, 654321)
675
+ const value = await AuthProvider.changePassword('email', 'example@oneentry.cloud', 'EW32RF', 654321, 654321)
629
676
  ```
630
677
 
631
678
  > This method changes the password of an authorized user. If successful, it will return true.
@@ -5707,7 +5754,7 @@ const data = {
5707
5754
  }
5708
5755
  ],
5709
5756
  "notificationData": {
5710
- "email": "test@test.com",
5757
+ "email": "example@oneentry.cloud",
5711
5758
  "phonePush": "",
5712
5759
  "phoneSMS": "+99999999999"
5713
5760
  }
@@ -5740,6 +5787,6 @@ example: List [ OrderedMap { "marker": "password", "value": "12345" } ] <br>
5740
5787
 
5741
5788
  **notificationData** UserNotificationDataType <br>
5742
5789
  *Data for notifying the user* <br>
5743
- example: OrderedMap { "email": "test@test.com", "phonePush": "", "phoneSMS": "+9999999999" } <br>
5790
+ example: OrderedMap { "email": "example@oneentry.cloud", "phonePush": "", "phoneSMS": "+9999999999" } <br>
5744
5791
 
5745
5792
  </details>
@@ -1,4 +1,3 @@
1
- import { Types } from "../base/utils";
2
1
  /**
3
2
  * Represents an interface object of AttributesSets Api.
4
3
  *
@@ -14,14 +13,17 @@ interface IListTitle {
14
13
  title: string;
15
14
  value: number | string;
16
15
  position: string | number | null;
17
- extendedValue: string | number | null;
18
- extendedValueType: string | number | null;
16
+ extended: {
17
+ value: string | null;
18
+ type: string | null;
19
+ };
19
20
  }
21
+ type AttributeType = 'string' | 'text' | 'textWithHeader' | 'integer' | 'real' | 'float' | 'dateTime' | 'date' | 'time' | 'file' | 'image' | 'groupOfImages' | 'radioButton' | 'list' | 'button';
20
22
  /**
21
23
  * Represents a template entity object.
22
24
  *
23
25
  * @interface
24
- * @property {Types} type - Attribute type.
26
+ * @property {AttributeType} type - Attribute type.
25
27
  * @property {string} marker - Textual identifier of the attribute (marker).
26
28
  * @property {number} position - Position number for sorting.
27
29
  * @property {Record<string, any>} validators - Set of validators for validation.
@@ -30,7 +32,7 @@ interface IListTitle {
30
32
  *
31
33
  */
32
34
  interface IAttributesSetsEntity {
33
- type: Types;
35
+ type: AttributeType;
34
36
  marker: string;
35
37
  position: number;
36
38
  validators: {
@@ -44,4 +46,4 @@ interface IAttributesSetsEntity {
44
46
  localizeInfos: Record<string, any>;
45
47
  listTitles: Array<IListTitle> | Record<string, any>;
46
48
  }
47
- export { IAttributesSets, IAttributesSetsEntity, IListTitle };
49
+ export { IAttributesSets, IAttributesSetsEntity, IListTitle, AttributeType };
@@ -1,5 +1,5 @@
1
1
  import AsyncModules from "../base/asyncModules";
2
- import { IAuthProvider, ISignUpData, ISignUpEntity, ICodeEntity, IAuthEntity, IAuthProvidersEntity, IAuthPostBody } from "./authProvidersInterfaces";
2
+ import { IAuthProvider, ISignUpData, ISignUpEntity, IAuthEntity, IAuthProvidersEntity, IAuthPostBody } from "./authProvidersInterfaces";
3
3
  import StateModule from "../base/stateModule";
4
4
  /**
5
5
  * Controllers for working with auth services.
@@ -20,7 +20,7 @@ export default class AuthProviderApi extends AsyncModules implements IAuthProvid
20
20
  * "authData": [
21
21
  * {
22
22
  * "marker": "login",
23
- * "value": "test@test.com"
23
+ * "value": "example@oneentry.cloud"
24
24
  * },
25
25
  * {
26
26
  * "marker": "password",
@@ -35,7 +35,7 @@ export default class AuthProviderApi extends AsyncModules implements IAuthProvid
35
35
  * }
36
36
  * ],
37
37
  * "notificationData": {
38
- * "email": "test@test.com",
38
+ * "email": "example@oneentry.cloud",
39
39
  * "phonePush": "+99999999999",
40
40
  * "phoneSMS": "+99999999999"
41
41
  * }
@@ -43,11 +43,18 @@ export default class AuthProviderApi extends AsyncModules implements IAuthProvid
43
43
  */
44
44
  signUp(marker: string, data: ISignUpData, langCode?: string): Promise<ISignUpEntity>;
45
45
  /**
46
- * Getting a user activation code
46
+ * Getting a user activation code. The code is returned via the appropriate user notification method
47
47
  * @param {string} marker - The text identifier of the authorization provider. Example - email
48
48
  * @param {string} userIdentifier - The text identifier of the user's object (user login)
49
49
  */
50
- generateCode(marker: string, userIdentifier: string): Promise<ICodeEntity>;
50
+ generateCode(marker: string, userIdentifier: string): Promise<void>;
51
+ /**
52
+ * User activation code verification. Returns true (if the code is correct) or false (if it is incorrect).
53
+ * @param {string} marker - The text identifier of the authorization provider. Example - email
54
+ * @param {string} userIdentifier - The text identifier of the user's object (user login)
55
+ * @param {string} code - Service code
56
+ */
57
+ checkCode(marker: string, userIdentifier: string, code: string): Promise<boolean>;
51
58
  /**
52
59
  * User activate.
53
60
  * @param {string} marker - The text identifier of the authorization provider. Example - email
@@ -21,7 +21,7 @@ class AuthProviderApi extends asyncModules_1.default {
21
21
  * "authData": [
22
22
  * {
23
23
  * "marker": "login",
24
- * "value": "test@test.com"
24
+ * "value": "example@oneentry.cloud"
25
25
  * },
26
26
  * {
27
27
  * "marker": "password",
@@ -36,7 +36,7 @@ class AuthProviderApi extends asyncModules_1.default {
36
36
  * }
37
37
  * ],
38
38
  * "notificationData": {
39
- * "email": "test@test.com",
39
+ * "email": "example@oneentry.cloud",
40
40
  * "phonePush": "+99999999999",
41
41
  * "phoneSMS": "+99999999999"
42
42
  * }
@@ -49,7 +49,7 @@ class AuthProviderApi extends asyncModules_1.default {
49
49
  return this._normalizeData(result);
50
50
  }
51
51
  /**
52
- * Getting a user activation code
52
+ * Getting a user activation code. The code is returned via the appropriate user notification method
53
53
  * @param {string} marker - The text identifier of the authorization provider. Example - email
54
54
  * @param {string} userIdentifier - The text identifier of the user's object (user login)
55
55
  */
@@ -58,6 +58,19 @@ class AuthProviderApi extends asyncModules_1.default {
58
58
  "userIdentifier": userIdentifier
59
59
  };
60
60
  const result = await this._fetchPost(`/marker/${marker}/users/generate-code`, data);
61
+ }
62
+ /**
63
+ * User activation code verification. Returns true (if the code is correct) or false (if it is incorrect).
64
+ * @param {string} marker - The text identifier of the authorization provider. Example - email
65
+ * @param {string} userIdentifier - The text identifier of the user's object (user login)
66
+ * @param {string} code - Service code
67
+ */
68
+ async checkCode(marker, userIdentifier, code) {
69
+ const data = {
70
+ "userIdentifier": userIdentifier,
71
+ "code": code
72
+ };
73
+ const result = await this._fetchPost(`/marker/${marker}/users/check-code`, data);
61
74
  return result;
62
75
  }
63
76
  /**
@@ -98,6 +111,9 @@ class AuthProviderApi extends asyncModules_1.default {
98
111
  const result = await this._fetchPost(`/marker/${marker}/users/auth`, data);
99
112
  this.state.accessToken = result.accessToken;
100
113
  this.state.refreshToken = result.refreshToken;
114
+ if (this.state.saveFunction) {
115
+ this.state.saveFunction(result.refreshToken);
116
+ }
101
117
  return result;
102
118
  }
103
119
  /**
@@ -111,6 +127,9 @@ class AuthProviderApi extends asyncModules_1.default {
111
127
  const result = await this._fetchPost(`/marker/${marker}/users/refresh`, data);
112
128
  this.state.accessToken = result.accessToken;
113
129
  this.state.refreshToken = result.refreshToken;
130
+ if (this.state.saveFunction) {
131
+ this.state.saveFunction(result.refreshToken);
132
+ }
114
133
  return result;
115
134
  }
116
135
  /**
@@ -126,6 +145,9 @@ class AuthProviderApi extends asyncModules_1.default {
126
145
  if (result) {
127
146
  this.state.accessToken = undefined;
128
147
  this.state.refreshToken = undefined;
148
+ if (this.state.saveFunction) {
149
+ this.state.saveFunction('');
150
+ }
129
151
  }
130
152
  return result;
131
153
  }
@@ -4,6 +4,7 @@ import { ILocalizeInfo } from "../base/utils";
4
4
  *
5
5
  * @property {function} signUp - User registration.
6
6
  * @property {function} generateCode - Getting a user activation code.
7
+ * @property {function} checkCode - User activation code verification.
7
8
  * @property {function} activateUser - User activate.
8
9
  * @property {function} auth - User authorization.
9
10
  * @property {function} refresh - Refresh token.
@@ -14,7 +15,8 @@ import { ILocalizeInfo } from "../base/utils";
14
15
  */
15
16
  interface IAuthProvider {
16
17
  signUp(marker: string, data: ISignUpData, langCode?: string): Promise<ISignUpEntity>;
17
- generateCode(marker: string, userIdentifier: string): Promise<ICodeEntity>;
18
+ generateCode(marker: string, userIdentifier: string): Promise<void>;
19
+ checkCode(marker: string, userIdentifier: string, code: string): Promise<boolean>;
18
20
  activateUser(marker: string, userIdentifier: string, code: string): Promise<boolean>;
19
21
  auth(marker: string, data: IAuthPostBody): Promise<IAuthEntity>;
20
22
  refresh(marker: string, token: string): Promise<IAuthEntity>;
@@ -119,6 +119,9 @@ class AsyncModules extends syncModules_1.default {
119
119
  const result = await response.json();
120
120
  this.state.refreshToken = result.refreshToken;
121
121
  this.state.accessToken = result.accessToken;
122
+ if (this.state.saveFunction) {
123
+ this.state.saveFunction(result.refreshToken);
124
+ }
122
125
  return true;
123
126
  }
124
127
  else {
@@ -146,7 +149,7 @@ class AsyncModules extends syncModules_1.default {
146
149
  }
147
150
  async browserResponse(path, options) {
148
151
  const response = await fetch(this._getFullPath(path), options);
149
- if (response.status == 401) {
152
+ if (response.status == 401 && !this.state.customAuth) {
150
153
  const refresh = await this.refreshToken();
151
154
  if (refresh) {
152
155
  options.headers['Authorization'] = 'Bearer ' + this.state.accessToken;
@@ -6,5 +6,7 @@ export default class StateModule {
6
6
  accessToken: string | undefined;
7
7
  multipleResponse: boolean;
8
8
  refreshToken: string | undefined;
9
+ customAuth: boolean;
10
+ saveFunction: (param: string) => void | null;
9
11
  constructor(url: string, config: IConfig);
10
12
  }
@@ -2,12 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class StateModule {
4
4
  constructor(url, config) {
5
- var _a, _b;
5
+ var _a, _b, _c, _d, _e, _f, _g, _h;
6
6
  this.url = url;
7
7
  this.lang = (_a = config.langCode) !== null && _a !== void 0 ? _a : 'en_US';
8
8
  this.token = config.token;
9
- this.multipleResponse = (_b = config.multipleRequests) !== null && _b !== void 0 ? _b : true;
10
- this.refreshToken = config.userToken;
9
+ this.multipleResponse = !!((_b = config.traficLimit) !== null && _b !== void 0 ? _b : false);
10
+ this.refreshToken = (_d = (_c = config.auth) === null || _c === void 0 ? void 0 : _c.refreshToken) !== null && _d !== void 0 ? _d : undefined;
11
+ this.customAuth = (_f = (_e = config.auth) === null || _e === void 0 ? void 0 : _e.customAuth) !== null && _f !== void 0 ? _f : false;
12
+ this.saveFunction = (_h = (_g = config.auth) === null || _g === void 0 ? void 0 : _g.saveFunction) !== null && _h !== void 0 ? _h : null;
11
13
  }
12
14
  }
13
15
  exports.default = StateModule;
@@ -1,35 +1,39 @@
1
- declare enum Types {
2
- forCatalogProducts = "forCatalogProducts",
3
- forBasketPage = "forBasketPage",
4
- forErrorPage = "forErrorPage",
5
- forCatalogPages = "forCatalogPages",
6
- forProductPreview = "forProductPreview",
7
- forProductPage = "forProductPage",
8
- forSimilarProductBlock = "forSimilarProductBlock",
9
- forStatisticProductBlock = "forStatisticProductBlock",
10
- forProductBlock = "forProductBlock",
11
- forForm = "forForm",
12
- forFormField = "forFormField",
13
- forNewsPage = "forNewsPage",
14
- forNewsBlock = "forNewsBlock",
15
- forNewsPreview = "forNewsPreview",
16
- forOneNewsPage = "forOneNewsPage",
17
- forUsualPage = "forUsualPage",
18
- forTextBlock = "forTextBlock",
19
- forSlider = "forSlider",
20
- service = "service"
21
- }
1
+ type Types = 'forCatalogProducts' | 'forBasketPage' | 'forErrorPage' | 'forCatalogPages' | 'forProductPreview' | 'forProductPage' | 'forSimilarProductBlock' | 'forStatisticProductBlock' | 'forProductBlock' | 'forForm' | 'forFormField' | 'forNewsPage' | 'forNewsBlock' | 'forNewsPreview' | 'forOneNewsPage' | 'forUsualPage' | 'forTextBlock' | 'forSlider' | 'forOrder' | 'service' | 'none';
22
2
  /**
23
3
  * @param {string} [token] - If your project is protected by a token, specify this token in this parameter.
24
4
  * @param {string} [langCode] - specify the default language to avoid specifying it in every request.
25
5
  * @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
- * @param {boolean} [userToken] - If your project uses user authorization, pass the user refresh token to the "userToken" variable to use methods that require authorization.
6
+ * @param {boolean} [auth] - An object with authorization settings
7
+ * @param {boolean} [auth.customAuth] - Set this flag to true if you want to configure the authorization process yourself. Set the flag to false, or do not pass it at all to have automatic authorization and token renewal
8
+ * @param {boolean} [auth.refreshToken] - Transfer the refresh token here, for example from the local storage, to resume the user's session. Otherwise, the user will need to log in every time a new session is created
9
+ * @param {boolean} [auth.saveFunction] - If you want to store the token between sessions, for example in local storage, create a custom function that takes refreshToken as a parameter and executes the necessary instructions. This function will be called every time the tokens are updated
10
+ *
11
+ * @example
12
+ * const saveToken = (token) => {
13
+ * localStorage.setItem('refresh', token)
14
+ * }
15
+ *
16
+ * const config = {
17
+ * token: 'project.token.here',
18
+ * langCode: 'en_US',
19
+ * multipleRequests: true,
20
+ * auth: {
21
+ * customAuth: false,
22
+ * refreshToken: 'user.refresh.token',
23
+ * saveFunction: saveToken
24
+ * }
25
+ * }
26
+ *
27
27
  */
28
28
  interface IConfig {
29
29
  token?: string;
30
- userToken?: string;
31
30
  langCode?: string;
32
- multipleRequests?: boolean;
31
+ traficLimit?: boolean;
32
+ auth?: {
33
+ customAuth?: boolean;
34
+ refreshToken?: string;
35
+ saveFunction?: (refreshToken: string) => void;
36
+ };
33
37
  }
34
38
  interface IAttributes {
35
39
  listTitles: Array<{
@@ -1,25 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Types = void 0;
4
- var Types;
5
- (function (Types) {
6
- Types["forCatalogProducts"] = "forCatalogProducts";
7
- Types["forBasketPage"] = "forBasketPage";
8
- Types["forErrorPage"] = "forErrorPage";
9
- Types["forCatalogPages"] = "forCatalogPages";
10
- Types["forProductPreview"] = "forProductPreview";
11
- Types["forProductPage"] = "forProductPage";
12
- Types["forSimilarProductBlock"] = "forSimilarProductBlock";
13
- Types["forStatisticProductBlock"] = "forStatisticProductBlock";
14
- Types["forProductBlock"] = "forProductBlock";
15
- Types["forForm"] = "forForm";
16
- Types["forFormField"] = "forFormField";
17
- Types["forNewsPage"] = "forNewsPage";
18
- Types["forNewsBlock"] = "forNewsBlock";
19
- Types["forNewsPreview"] = "forNewsPreview";
20
- Types["forOneNewsPage"] = "forOneNewsPage";
21
- Types["forUsualPage"] = "forUsualPage";
22
- Types["forTextBlock"] = "forTextBlock";
23
- Types["forSlider"] = "forSlider";
24
- Types["service"] = "service";
25
- })(Types || (exports.Types = Types = {}));
@@ -66,7 +66,7 @@ class ProductApi extends asyncModules_1.default {
66
66
  */
67
67
  async getProducts(body = [], langCode = this.state.lang, userQuery) {
68
68
  const query = { ...this._defaultQuery, ...userQuery, langCode };
69
- const result = await this._fetchPost(`/all?` + this._queryParamsToString(query), body);
69
+ const result = await this._fetchPost(`/all?langCode=${langCode}&` + this._queryParamsToString(query), body);
70
70
  return this._dataPostProcess(result.items, langCode);
71
71
  }
72
72
  /**
@@ -144,7 +144,7 @@ class ProductApi extends asyncModules_1.default {
144
144
  */
145
145
  async getProductsByPageId(id, body = [], langCode = this.state.lang, userQuery) {
146
146
  const query = { ...this._defaultQuery, ...userQuery };
147
- const result = await this._fetchPost(`/page/${id}?` + this._queryParamsToString(query), body);
147
+ const result = await this._fetchPost(`/page/${id}?langCode=${langCode}&` + this._queryParamsToString(query), body);
148
148
  return this._dataPostProcess(result.items, langCode);
149
149
  }
150
150
  /**
@@ -221,7 +221,7 @@ class ProductApi extends asyncModules_1.default {
221
221
  */
222
222
  async getProductsByPageUrl(url, body = [], langCode = this.state.lang, userQuery) {
223
223
  const query = { ...this._defaultQuery, ...userQuery };
224
- const result = await this._fetchPost(`/page/url/${url}?` + this._queryParamsToString(query), body);
224
+ const result = await this._fetchPost(`/page/url/${url}?langCode=${langCode}&` + this._queryParamsToString(query), body);
225
225
  return this._dataPostProcess(result.items, langCode);
226
226
  }
227
227
  /**
@@ -279,7 +279,7 @@ class ProductApi extends asyncModules_1.default {
279
279
  * @returns Array with ProductEntity objects
280
280
  */
281
281
  async searchProduct(name, langCode = this.state.lang) {
282
- const searchProducts = await this._fetchGet(`/quick/search?lang=${langCode}&name=${name}`);
282
+ const searchProducts = await this._fetchGet(`/quick/search?langCode=${langCode}&name=${name}`);
283
283
  if (this.state.multipleResponse) {
284
284
  const productsList = [];
285
285
  await Promise.all(searchProducts.map(async (product) => {
@@ -33,7 +33,7 @@ export default class UsersApi extends AsyncModules implements IUsers {
33
33
  * "value": "Username"
34
34
  * },
35
35
  * "notificationData": {
36
- * "email": "test@test.com",
36
+ * "email": "example@oneentry.cloud",
37
37
  * "phonePush": "",
38
38
  * "phoneSMS": "+99999999999"
39
39
  * }
@@ -37,7 +37,7 @@ class UsersApi extends asyncModules_1.default {
37
37
  * "value": "Username"
38
38
  * },
39
39
  * "notificationData": {
40
- * "email": "test@test.com",
40
+ * "email": "example@oneentry.cloud",
41
41
  * "phonePush": "",
42
42
  * "phoneSMS": "+99999999999"
43
43
  * }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneentry",
3
- "version": "1.0.68",
3
+ "version": "1.0.70",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",