oneentry 1.0.96 → 1.0.98

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
@@ -139,6 +139,34 @@ const api = defineOneEntry('your-url', {
139
139
  })
140
140
  ```
141
141
 
142
+ ### Errors
143
+
144
+ If you want to escape errors inside the sc, leave the "errors" property by default.
145
+ In this case, you will receive either the entity data or the error object.
146
+ You need to do a type check. for example, by checking the statusCode property with ".hasOwnProperty"
147
+
148
+ However, if you want to use the construction "try {} catch(e) {}", set the property "isShell" to the value "false".
149
+ In this case, you need to handle the error using "try {} catch(e) {}".
150
+
151
+ Also, you can pass custom functions that will be called inside the sdk with the appropriate error code.
152
+ These functions receive an error object as an argument. You can process it yourself.
153
+
154
+ ```js
155
+ const api = defineOneEntry('your-url', {
156
+ token: 'my-token',
157
+ langCode:'my-langCode',
158
+ errors: {
159
+ isShell: false,
160
+ customErrors: {
161
+ 400: (error) => console.error(error.message),
162
+ 404: (error) => console.error(error.message),
163
+ 500: (error) => console.error(error.message)
164
+ }
165
+ }
166
+ })
167
+ ```
168
+
169
+
142
170
  Now you can use the following links to jump to specific entries:
143
171
  - [Admins](#admins)
144
172
  - [AttributesSets](#attributessets)
@@ -1162,6 +1190,42 @@ Example return:
1162
1190
  const { Events } = defineOneEntry('your-url');
1163
1191
  ```
1164
1192
 
1193
+ ### Events.getAllSubscriptions(limit, offset)
1194
+
1195
+ ```js
1196
+ const value = await Events.getAllSubscriptions('test_event', 1, 1)
1197
+ ```
1198
+
1199
+ > This method return all subscriptions to product.
1200
+
1201
+ Example return:
1202
+ ```json
1203
+ {
1204
+ "total": 100,
1205
+ "items": [
1206
+ {
1207
+ "eventMarker": "string",
1208
+ "productId": 0
1209
+ }
1210
+ ]
1211
+ }
1212
+ ```
1213
+
1214
+ ><details>
1215
+ ><summary >Schema</summary>
1216
+ >
1217
+ >**total:** number <br>
1218
+ >*Total number of records found* <br>
1219
+ >
1220
+ >**eventMarker:** string <br>
1221
+ >*Event marker* <br>
1222
+ >
1223
+ >**productId** number <br>
1224
+ >*Product identifier* <br>
1225
+ >
1226
+ ></details>
1227
+
1228
+
1165
1229
  ### Events.subscribeByMarker(marker, userId, productId)
1166
1230
 
1167
1231
  ```js
@@ -163,11 +163,47 @@ class AsyncModules extends syncModules_1.default {
163
163
  return await secondResponse.json();
164
164
  }
165
165
  }
166
- return await response.json();
166
+ else if (response.status == 400) {
167
+ if (this.state.errorsFunctions["400"]) {
168
+ this.state.errorsFunctions["400"](await response.json());
169
+ }
170
+ }
171
+ else if (response.status == 401) {
172
+ if (this.state.errorsFunctions["401"]) {
173
+ this.state.errorsFunctions["401"](await response.json());
174
+ }
175
+ }
176
+ else if (response.status == 403) {
177
+ if (this.state.errorsFunctions["403"]) {
178
+ this.state.errorsFunctions["403"](await response.json());
179
+ }
180
+ }
181
+ else if (response.status == 404) {
182
+ if (this.state.errorsFunctions["404"]) {
183
+ this.state.errorsFunctions["404"](await response.json());
184
+ }
185
+ }
186
+ else if (response.status == 500) {
187
+ if (this.state.errorsFunctions["500"]) {
188
+ this.state.errorsFunctions["500"](await response.json());
189
+ }
190
+ }
191
+ if (this.state.isShell) {
192
+ return await response.json();
193
+ }
194
+ else {
195
+ const error = await response.json();
196
+ throw error;
197
+ }
167
198
  }
168
199
  }
169
200
  catch (e) {
170
- return e;
201
+ if (this.state.isShell) {
202
+ return e;
203
+ }
204
+ else {
205
+ throw e;
206
+ }
171
207
  }
172
208
  }
173
209
  }
@@ -1,4 +1,4 @@
1
- import { IConfig } from "./utils";
1
+ import { IConfig, IError } from "./utils";
2
2
  export default class StateModule {
3
3
  url: string | undefined;
4
4
  lang: string | undefined;
@@ -9,6 +9,14 @@ export default class StateModule {
9
9
  customAuth: boolean;
10
10
  _NO_FETCH: boolean;
11
11
  _https: any;
12
+ isShell: boolean;
13
+ errorsFunctions: {
14
+ 400?: (data: IError) => any | null;
15
+ 401?: (data: IError) => any | null;
16
+ 403?: (data: IError) => any | null;
17
+ 404?: (data: IError) => any | null;
18
+ 500?: (data: IError) => any | null;
19
+ };
12
20
  saveFunction: (param: string) => void | null;
13
21
  constructor(url: string, config: IConfig);
14
22
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class StateModule {
4
4
  constructor(url, config) {
5
- var _a, _b, _c, _d, _e, _f, _g, _h;
5
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
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;
@@ -10,6 +10,19 @@ class StateModule {
10
10
  this.refreshToken = (_d = (_c = config.auth) === null || _c === void 0 ? void 0 : _c.refreshToken) !== null && _d !== void 0 ? _d : undefined;
11
11
  this.customAuth = (_f = (_e = config.auth) === null || _e === void 0 ? void 0 : _e.customAuth) !== null && _f !== void 0 ? _f : false;
12
12
  this.saveFunction = (_h = (_g = config.auth) === null || _g === void 0 ? void 0 : _g.saveFunction) !== null && _h !== void 0 ? _h : null;
13
+ if (config.errors) {
14
+ this.isShell = (_j = config.errors.isShell) !== null && _j !== void 0 ? _j : true;
15
+ if (config.errors.customErrors) {
16
+ this.errorsFunctions["400"] = (_k = config.errors.customErrors["400"]) !== null && _k !== void 0 ? _k : null;
17
+ this.errorsFunctions["401"] = (_l = config.errors.customErrors["401"]) !== null && _l !== void 0 ? _l : null;
18
+ this.errorsFunctions["403"] = (_m = config.errors.customErrors["403"]) !== null && _m !== void 0 ? _m : null;
19
+ this.errorsFunctions["404"] = (_o = config.errors.customErrors["404"]) !== null && _o !== void 0 ? _o : null;
20
+ this.errorsFunctions["500"] = (_p = config.errors.customErrors["400"]) !== null && _p !== void 0 ? _p : null;
21
+ }
22
+ }
23
+ else {
24
+ this.isShell = false;
25
+ }
13
26
  try {
14
27
  if (typeof process === 'object' && +process.versions.node.split('.')[0] < 18) {
15
28
  try {
@@ -21,6 +21,13 @@ type Types = 'forCatalogProducts' | 'forBasketPage' | 'forErrorPage' | 'forCatal
21
21
  * customAuth: false,
22
22
  * refreshToken: 'user.refresh.token',
23
23
  * saveFunction: saveToken
24
+ * },
25
+ * errors: {
26
+ * isShell: true,
27
+ * customErrors: {
28
+ * '404': notFoundFunction,
29
+ * '400': errorFunction
30
+ * }
24
31
  * }
25
32
  * }
26
33
  *
@@ -34,6 +41,16 @@ interface IConfig {
34
41
  refreshToken?: string;
35
42
  saveFunction?: (refreshToken: string) => void;
36
43
  };
44
+ errors?: {
45
+ isShell?: boolean;
46
+ customErrors?: {
47
+ 400?: (data?: IError) => any;
48
+ 401?: (data?: IError) => any;
49
+ 403?: (data?: IError) => any;
50
+ 404?: (data?: IError) => any;
51
+ 500?: (data?: IError) => any;
52
+ };
53
+ };
37
54
  }
38
55
  interface IAttributes {
39
56
  listTitles: Array<{
@@ -2,6 +2,7 @@ import AsyncModules from "../base/asyncModules";
2
2
  import { IEvents } from "./eventsInterfaces";
3
3
  import StateModule from "../base/stateModule";
4
4
  import { IError } from "../base/utils";
5
+ import { ISubscriptions } from "./eventsInterfaces";
5
6
  /**
6
7
  * Controllers for working with events
7
8
  */
@@ -9,6 +10,13 @@ export default class EventsApi extends AsyncModules implements IEvents {
9
10
  protected state: StateModule;
10
11
  protected _url: string;
11
12
  constructor(state: StateModule);
13
+ /**
14
+ * Return all subscriptions to product.
15
+ *
16
+ * @param {number} limit - Event marker.
17
+ * @param {number} offset - Language code.
18
+ */
19
+ getAllSubscriptions(limit?: number, offset?: number): Promise<ISubscriptions | IError>;
12
20
  /**
13
21
  * Subscribing to an event on a product.
14
22
  *
@@ -9,6 +9,16 @@ class EventsApi extends asyncModules_1.default {
9
9
  super(state);
10
10
  this._url = state.url + '/api/content/events';
11
11
  }
12
+ /**
13
+ * Return all subscriptions to product.
14
+ *
15
+ * @param {number} limit - Event marker.
16
+ * @param {number} offset - Language code.
17
+ */
18
+ async getAllSubscriptions(limit = 30, offset = 0) {
19
+ const result = await this._fetchGet(`/subscriptions`);
20
+ return result;
21
+ }
12
22
  /**
13
23
  * Subscribing to an event on a product.
14
24
  *
@@ -2,11 +2,20 @@ import { IError } from "../base/utils";
2
2
  /**
3
3
  * Represents a interface object of Events Api.
4
4
  *
5
+ * @property {function} getAllSubscriptions - Return all subscriptions to product.
5
6
  * @property {function} subscribeByMarker - Subscribing to an event on a product.
6
7
  * @property {function} unsubscribeByMarker - Unsubscribing to an event on a product.
7
8
  */
8
9
  interface IEvents {
10
+ getAllSubscriptions(limit?: number, offset?: number): Promise<ISubscriptions | IError>;
9
11
  subscribeByMarker(marker: string, productId: number, langCode: string): Promise<any | IError>;
10
12
  unsubscribeByMarker(marker: string, productId: number, langCode: string): Promise<any | IError>;
11
13
  }
12
- export { IEvents };
14
+ interface ISubscriptions {
15
+ total: number;
16
+ items: Array<{
17
+ eventMarker: string;
18
+ productId: number;
19
+ }>;
20
+ }
21
+ export { IEvents, ISubscriptions };
@@ -28,16 +28,16 @@ interface IUserEntity {
28
28
  interface IUserBody {
29
29
  formIdentifier: string;
30
30
  langCode?: string;
31
- authData: Array<{
31
+ authData?: Array<{
32
32
  marker: string;
33
33
  value: string;
34
34
  }>;
35
35
  formData?: IAuthFormData | Array<IAuthFormData>;
36
- notificationData: {
36
+ notificationData?: {
37
37
  email: string;
38
38
  phonePush: Array<string>;
39
39
  phoneSMS: string;
40
40
  };
41
- state: Record<string, any>;
41
+ state?: Record<string, any>;
42
42
  }
43
43
  export { IUsers, IUserEntity, IUserBody, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneentry",
3
- "version": "1.0.96",
3
+ "version": "1.0.98",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",