oneentry 1.0.97 → 1.0.99

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
@@ -1190,6 +1190,42 @@ Example return:
1190
1190
  const { Events } = defineOneEntry('your-url');
1191
1191
  ```
1192
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
+
1193
1229
  ### Events.subscribeByMarker(marker, userId, productId)
1194
1230
 
1195
1231
  ```js
@@ -168,6 +168,16 @@ class AsyncModules extends syncModules_1.default {
168
168
  this.state.errorsFunctions["400"](await response.json());
169
169
  }
170
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
+ }
171
181
  else if (response.status == 404) {
172
182
  if (this.state.errorsFunctions["404"]) {
173
183
  this.state.errorsFunctions["404"](await response.json());
@@ -182,7 +192,8 @@ class AsyncModules extends syncModules_1.default {
182
192
  return await response.json();
183
193
  }
184
194
  else {
185
- throw await response.json();
195
+ const error = await response.json();
196
+ throw error;
186
197
  }
187
198
  }
188
199
  }
@@ -11,8 +11,10 @@ export default class StateModule {
11
11
  _https: any;
12
12
  isShell: boolean;
13
13
  errorsFunctions: {
14
- 404?: (data: IError) => any | null;
15
14
  400?: (data: IError) => any | null;
15
+ 401?: (data: IError) => any | null;
16
+ 403?: (data: IError) => any | null;
17
+ 404?: (data: IError) => any | null;
16
18
  500?: (data: IError) => any | null;
17
19
  };
18
20
  saveFunction: (param: string) => void | null;
@@ -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, _j, _k, _l, _m;
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;
@@ -12,9 +12,13 @@ class StateModule {
12
12
  this.saveFunction = (_h = (_g = config.auth) === null || _g === void 0 ? void 0 : _g.saveFunction) !== null && _h !== void 0 ? _h : null;
13
13
  if (config.errors) {
14
14
  this.isShell = (_j = config.errors.isShell) !== null && _j !== void 0 ? _j : true;
15
- this.errorsFunctions["400"] = (_k = config.errors.customErrors["400"]) !== null && _k !== void 0 ? _k : null;
16
- this.errorsFunctions["404"] = (_l = config.errors.customErrors["400"]) !== null && _l !== void 0 ? _l : null;
17
- this.errorsFunctions["500"] = (_m = config.errors.customErrors["400"]) !== null && _m !== void 0 ? _m : null;
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
+ }
18
22
  }
19
23
  else {
20
24
  this.isShell = false;
@@ -41,11 +41,13 @@ interface IConfig {
41
41
  refreshToken?: string;
42
42
  saveFunction?: (refreshToken: string) => void;
43
43
  };
44
- errors: {
44
+ errors?: {
45
45
  isShell?: boolean;
46
- customErrors: {
47
- 404?: (data?: IError) => any;
46
+ customErrors?: {
48
47
  400?: (data?: IError) => any;
48
+ 401?: (data?: IError) => any;
49
+ 403?: (data?: IError) => any;
50
+ 404?: (data?: IError) => any;
49
51
  500?: (data?: IError) => any;
50
52
  };
51
53
  };
@@ -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 };
@@ -52,7 +52,7 @@ class UsersApi extends asyncModules_1.default {
52
52
  async updateUser(data, langCode = this.state.lang) {
53
53
  if (!('langCode' in data))
54
54
  data['langCode'] = langCode;
55
- const result = await this._fetchPut('/me', this._normalizePostBody(data, langCode));
55
+ const result = await this._fetchPut('/me', data.hasOwnProperty('formData') ? this._normalizePostBody(data, langCode) : data);
56
56
  return result;
57
57
  }
58
58
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneentry",
3
- "version": "1.0.97",
3
+ "version": "1.0.99",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",