oneentry 1.0.68 → 1.0.69

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.
@@ -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.69",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",