oneentry 1.0.64 → 1.0.65

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
@@ -55,7 +55,7 @@ const api = defineOneEntry('your-url');
55
55
 
56
56
  The second parameter of the function takes a configuration object with the keys "token", "langCode" and "multipleResponse".
57
57
  Set the token key if your project secure "Security API Token"
58
-
58
+ If your project uses user authorization, pass the user access token to the "userToken" variable to use methods that require authorization.
59
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
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
61
 
@@ -74,8 +74,13 @@ You can also connect a tls certificate to protect your project. In this case, do
74
74
 
75
75
 
76
76
  ```js
77
- const api = defineOneEntry('your-url', {token: 'my-token', langCode:'my-langCode'})
77
+ const api = defineOneEntry('your-url', {
78
+ token: 'my-token',
79
+ userToken: 'user.token',
80
+ langCode:'my-langCode',
81
+ })
78
82
  ```
83
+
79
84
  Now you can use the following links to jump to specific entries:
80
85
  - [Admins](#admins)
81
86
  - [AttributesSets](#attributessets)
@@ -373,7 +378,7 @@ const data = {
373
378
  }
374
379
  }
375
380
 
376
- const value = await AuthProvider.getBlocks('en_US', 0, 30)
381
+ const value = await AuthProvider.signUp('email', data)
377
382
  ```
378
383
 
379
384
  > This method will register a new user. Returns the registered user's object.
@@ -510,10 +515,23 @@ Example return:
510
515
  true
511
516
  ```
512
517
 
513
- ### AuthProvider.auth(marker, login, password)
518
+ ### AuthProvider.auth(marker, data)
514
519
 
515
520
  ```js
516
- const value = await AuthProvider.auth('email', 'test@trer.com', '123456')
521
+ const data = {
522
+ authData: [
523
+ {
524
+ marker: "login",
525
+ value: "user@gmail.com"
526
+ },
527
+ {
528
+ marker: "password",
529
+ value: "12345"
530
+ }
531
+ ]
532
+ }
533
+
534
+ const value = await AuthProvider.auth('email', data)
517
535
  ```
518
536
 
519
537
  > This method performs user authorization. Returns an object with a set of tokens.
@@ -698,9 +716,7 @@ Example return:
698
716
  {
699
717
  "id": 1764,
700
718
  "localizeInfos": {
701
- "en_US": {
702
719
  "title": "My block"
703
- }
704
720
  },
705
721
  "version": 10,
706
722
  "identifier": "catalog",
@@ -1,6 +1,6 @@
1
1
  import OneEntry from "../base/oneEntry";
2
2
  import { IConfig } from "../base/utils";
3
- import { IAuthProvider, ISignUpData, ISignUpEntity, ICodeEntity, IAuthEntity, IAuthProvidersEntity } from "./authProvidersInterfaces";
3
+ import { IAuthProvider, ISignUpData, ISignUpEntity, ICodeEntity, IAuthEntity, IAuthProvidersEntity, IAuthPostBody } from "./authProvidersInterfaces";
4
4
  /**
5
5
  * Controllers for working with auth services.
6
6
  */
@@ -44,11 +44,6 @@ export default class AuthProviderApi extends OneEntry implements IAuthProvider {
44
44
  * Getting a user activation code
45
45
  * @param {string} marker - The text identifier of the authorization provider. Example - email
46
46
  * @param {string} userIdentifier - The text identifier of the user's object (user login)
47
- *
48
- * @example
49
- * const data = {
50
- * "userIdentifier": "test@test.com"
51
- * }
52
47
  */
53
48
  generateCode(marker: string, userIdentifier: string): Promise<ICodeEntity>;
54
49
  /**
@@ -61,11 +56,24 @@ export default class AuthProviderApi extends OneEntry implements IAuthProvider {
61
56
  /**
62
57
  * User authorization
63
58
  * @param {string} marker - The text identifier of the authorization provider. Example - email
64
- * @param {string} login - User login
65
- * @param {string} password - User password
59
+ * @param {IAuthPostBody} data - Array of objects contains auth information
60
+ *
61
+ * @example
62
+ * const data = {
63
+ * authData: [
64
+ * {
65
+ * marker: "login",
66
+ * value: "test"
67
+ * },
68
+ * {
69
+ * marker: "password",
70
+ * value: "12345"
71
+ * }
72
+ * ]
73
+ * }
66
74
  *
67
75
  */
68
- auth(marker: string, login: string, password: string): Promise<IAuthEntity>;
76
+ auth(marker: string, data: IAuthPostBody): Promise<IAuthEntity>;
69
77
  /**
70
78
  * Refresh token
71
79
  * @param {string} marker - The text identifier of the authorization provider. Example - email
@@ -94,7 +102,7 @@ export default class AuthProviderApi extends OneEntry implements IAuthProvider {
94
102
  * @param {number} [offset] - Parameter for pagination. Default 0
95
103
  * @param {number} [limit] - Parameter for pagination. Default 30
96
104
  */
97
- getAuthProviders(langCode: string, offset: number, limit: number): Promise<Array<IAuthProvidersEntity>>;
105
+ getAuthProviders(langCode?: string, offset?: number, limit?: number): Promise<Array<IAuthProvidersEntity>>;
98
106
  /**
99
107
  * Get one auth provider object by marker
100
108
  * @param {string} marker - The text identifier of the authorization provider. Example - email
@@ -43,18 +43,14 @@ class AuthProviderApi extends oneEntry_1.default {
43
43
  * }
44
44
  */
45
45
  async signUp(marker, data, langCode = this._defaultLangCode) {
46
- const result = await this._fetchPost(`/marker/${marker}/users/sign-up`, this._normalizePostBody(data, langCode));
46
+ const body = this._normalizePostBody(data, langCode);
47
+ const result = await this._fetchPost(`/marker/${marker}/users/sign-up`, body);
47
48
  return this._normalizeData(result);
48
49
  }
49
50
  /**
50
51
  * Getting a user activation code
51
52
  * @param {string} marker - The text identifier of the authorization provider. Example - email
52
53
  * @param {string} userIdentifier - The text identifier of the user's object (user login)
53
- *
54
- * @example
55
- * const data = {
56
- * "userIdentifier": "test@test.com"
57
- * }
58
54
  */
59
55
  async generateCode(marker, userIdentifier) {
60
56
  const data = {
@@ -80,22 +76,26 @@ class AuthProviderApi extends oneEntry_1.default {
80
76
  /**
81
77
  * User authorization
82
78
  * @param {string} marker - The text identifier of the authorization provider. Example - email
83
- * @param {string} login - User login
84
- * @param {string} password - User password
79
+ * @param {IAuthPostBody} data - Array of objects contains auth information
80
+ *
81
+ * @example
82
+ * const data = {
83
+ * authData: [
84
+ * {
85
+ * marker: "login",
86
+ * value: "test"
87
+ * },
88
+ * {
89
+ * marker: "password",
90
+ * value: "12345"
91
+ * }
92
+ * ]
93
+ * }
85
94
  *
86
95
  */
87
- async auth(marker, login, password) {
88
- const data = [
89
- {
90
- "marker": "login",
91
- "value": login
92
- },
93
- {
94
- "marker": "password",
95
- "value": password
96
- }
97
- ];
98
- const result = await this._fetchPost(`/marker/${marker}/users/activate`, data);
96
+ async auth(marker, data) {
97
+ const result = await this._fetchPost(`/marker/${marker}/users/auth`, data);
98
+ this._userToken = result.accessToken;
99
99
  return result;
100
100
  }
101
101
  /**
@@ -119,6 +119,9 @@ class AuthProviderApi extends oneEntry_1.default {
119
119
  "refreshToken": token
120
120
  };
121
121
  const result = await this._fetchPost(`/marker/${marker}/users/logout`, data);
122
+ if (result) {
123
+ this._userToken = null;
124
+ }
122
125
  return result;
123
126
  }
124
127
  /**
@@ -145,7 +148,7 @@ class AuthProviderApi extends oneEntry_1.default {
145
148
  * @param {number} [offset] - Parameter for pagination. Default 0
146
149
  * @param {number} [limit] - Parameter for pagination. Default 30
147
150
  */
148
- async getAuthProviders(langCode, offset, limit) {
151
+ async getAuthProviders(langCode = this._defaultLangCode, offset = 0, limit = 30) {
149
152
  const result = await this._fetchGet(`?langCode=${langCode}&offset=${offset}&limit=${limit}`);
150
153
  return this._normalizeData(result);
151
154
  }
@@ -154,7 +157,7 @@ class AuthProviderApi extends oneEntry_1.default {
154
157
  * @param {string} marker - The text identifier of the authorization provider. Example - email
155
158
  * @param {string} [langCode] - Optional parameter language code. Default "en_US"
156
159
  */
157
- async getMarker(marker, langCode) {
160
+ async getMarker(marker, langCode = this._defaultLangCode) {
158
161
  const result = await this._fetchGet(`/marker/${marker}?langCode=${langCode}`);
159
162
  return this._normalizeData(result);
160
163
  }
@@ -16,11 +16,11 @@ interface IAuthProvider {
16
16
  signUp(marker: string, data: ISignUpData, langCode?: string): Promise<ISignUpEntity>;
17
17
  generateCode(marker: string, userIdentifier: string): Promise<ICodeEntity>;
18
18
  activateUser(marker: string, userIdentifier: string, code: string): Promise<boolean>;
19
- auth(marker: string, login: string, password: string): Promise<IAuthEntity>;
19
+ auth(marker: string, data: IAuthPostBody): Promise<IAuthEntity>;
20
20
  refresh(marker: string, token: string): Promise<IAuthEntity>;
21
21
  logout(marker: string, token: string): Promise<boolean>;
22
22
  changePassword(marker: string, userIdentifier: string, code: string, newPassword: string, repeatPassword?: string): Promise<boolean>;
23
- getAuthProviders(langCode: string, offset: number, limit: number): Promise<Array<IAuthProvidersEntity>>;
23
+ getAuthProviders(langCode?: string, offset?: number, limit?: number): Promise<Array<IAuthProvidersEntity>>;
24
24
  getMarker(marker: string, langCode?: string): Promise<IAuthProvidersEntity>;
25
25
  }
26
26
  interface IAuthFormData {
@@ -78,4 +78,10 @@ interface IAuthProvidersEntity {
78
78
  type: string;
79
79
  formIdentifier: string | null;
80
80
  }
81
- export { IAuthProvider, IAuthFormData, ISignUpData, ISignUpEntity, ICodeEntity, IAuthEntity, IAuthProvidersEntity };
81
+ interface IAuthPostBody {
82
+ authData: Array<{
83
+ marker: string;
84
+ value: string | number;
85
+ }>;
86
+ }
87
+ export { IAuthProvider, IAuthFormData, ISignUpData, ISignUpEntity, ICodeEntity, IAuthEntity, IAuthProvidersEntity, IAuthPostBody };
@@ -4,6 +4,7 @@ import { IUploadingQuery } from "../file-uploding/fileUploadingInterfaces";
4
4
  export default abstract class OneEntry {
5
5
  protected _url: string;
6
6
  protected _token: string | undefined;
7
+ protected _userToken: string | undefined;
7
8
  protected _defaultLangCode: string;
8
9
  protected _multipleResponse: boolean;
9
10
  protected _NO_FETCH: boolean;
@@ -5,6 +5,7 @@ class OneEntry {
5
5
  var _a;
6
6
  this._url = url;
7
7
  this._token = config.token;
8
+ this._userToken = config.userToken;
8
9
  this._defaultLangCode = config.langCode ? config.langCode : 'en_US';
9
10
  this._multipleResponse = (_a = config.multipleRequests) !== null && _a !== void 0 ? _a : true;
10
11
  this._NO_FETCH = !!(typeof process === 'object' && process.versions);
@@ -24,6 +25,7 @@ class OneEntry {
24
25
  headers: {
25
26
  'Content-Type': 'application/json',
26
27
  'x-app-token': this._token,
28
+ 'Authorization': this._userToken
27
29
  }
28
30
  };
29
31
  if (!this._NO_FETCH) {
@@ -56,7 +58,8 @@ class OneEntry {
56
58
  method: 'POST',
57
59
  headers: {
58
60
  'x-app-token': this._token,
59
- 'Content-Type': 'application/json'
61
+ 'Content-Type': 'application/json',
62
+ 'Authorization': this._userToken ? 'Bearer ' + this._userToken : null
60
63
  }
61
64
  };
62
65
  if (data instanceof FormData || data instanceof Blob) {
@@ -65,7 +68,7 @@ class OneEntry {
65
68
  if (!this._NO_FETCH) {
66
69
  const response = await fetch(this._getFullPath(path), {
67
70
  ...options,
68
- body: data
71
+ body: JSON.stringify(data)
69
72
  });
70
73
  if (!response.ok) {
71
74
  const error = await response.json();
@@ -87,7 +90,7 @@ class OneEntry {
87
90
  req.on('error', (error) => {
88
91
  reject(error);
89
92
  });
90
- req.write(data);
93
+ req.write(JSON.stringify(data));
91
94
  req.end();
92
95
  });
93
96
  }
@@ -98,6 +101,7 @@ class OneEntry {
98
101
  headers: {
99
102
  'x-app-token': this._token,
100
103
  'Content-Type': 'application/json',
104
+ 'Authorization': this._userToken ? 'Bearer ' + this._userToken : null
101
105
  },
102
106
  };
103
107
  if (data instanceof FormData || data instanceof Blob) {
@@ -106,7 +110,7 @@ class OneEntry {
106
110
  if (!this._NO_FETCH) {
107
111
  const response = await fetch(this._getFullPath(path), {
108
112
  ...options,
109
- body: data,
113
+ body: JSON.stringify(data),
110
114
  });
111
115
  if (!response.ok) {
112
116
  const error = await response.json();
@@ -128,7 +132,7 @@ class OneEntry {
128
132
  req.on('error', (error) => {
129
133
  reject(error);
130
134
  });
131
- req.write(data);
135
+ req.write(JSON.stringify(data));
132
136
  req.end();
133
137
  });
134
138
  }
@@ -139,6 +143,7 @@ class OneEntry {
139
143
  headers: {
140
144
  'Content-Type': 'application/json',
141
145
  'x-app-token': this._token,
146
+ 'Authorization': this._userToken ? 'Bearer ' + this._userToken : null
142
147
  },
143
148
  body: data
144
149
  };
@@ -23,9 +23,11 @@ declare enum Types {
23
23
  * @param {string} [token] - If your project is protected by a token, specify this token in this parameter.
24
24
  * @param {string} [langCode] - specify the default language to avoid specifying it in every request.
25
25
  * @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 access token to the "userToken" variable to use methods that require authorization.
26
27
  */
27
28
  interface IConfig {
28
29
  token?: string;
30
+ userToken?: string;
29
31
  langCode?: string;
30
32
  multipleRequests?: boolean;
31
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneentry",
3
- "version": "1.0.64",
3
+ "version": "1.0.65",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "test": "jest"
12
12
  },
13
13
  "bin": {
14
- "lavss": "./configure.js"
14
+ "oneentry": "./configure.js"
15
15
  },
16
16
  "author": "ONEENTRY PORTAL CO.",
17
17
  "license": "ISC",