oneentry 1.0.74 → 1.0.75

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
@@ -18,7 +18,7 @@ To install the AsyncModules Headless CMS SDK in your project, run the following
18
18
  npm install oneentry
19
19
  ```
20
20
 
21
- # Usage
21
+ ## Get Started
22
22
 
23
23
  To use the AsyncModules Headless CMS SDK in your project, import the defineOneEntry function:
24
24
  ```js
@@ -101,6 +101,12 @@ const api = defineOneEntry('https://my-project.oneentry.cloud', {
101
101
  })
102
102
  ```
103
103
 
104
+ If you have chosen to configure tokens yourself, you can pass the token to the method as follows.
105
+ The intermediate method allows you to pass an access token to the request. Then call the required method.
106
+ This method (setAccessToken) should not be called if the method does not require user authorization.
107
+ ```js
108
+ const user = api.Users.setAccessToken('my.access.token').getUser()
109
+ ```
104
110
 
105
111
  >If you chose token protection to ensure connection security, just pass your token to the function as an optional parameter.
106
112
 
@@ -6,16 +6,19 @@ class AsyncModules extends syncModules_1.default {
6
6
  super(state);
7
7
  this._url = this.state.url;
8
8
  this.state = state;
9
- this._NO_FETCH = !!(typeof process === 'object' && process.versions);
10
9
  try {
11
- try {
12
- this._https = this._NO_FETCH ? require('https') : null;
10
+ if (typeof process === 'object' && +process.versions.node.split('.')[0] < 18) {
11
+ this._NO_FETCH = true;
12
+ this._https = require('https');
13
13
  }
14
- catch (e) {
14
+ else {
15
+ this._NO_FETCH = false;
15
16
  this._https = null;
16
17
  }
17
18
  }
18
19
  catch (e) {
20
+ this._NO_FETCH = false;
21
+ this._https = null;
19
22
  }
20
23
  }
21
24
  async _fetchGet(path) {
@@ -11,4 +11,6 @@ export default abstract class SyncModules {
11
11
  protected _normalizePostBody(body: any, langCode?: string): any;
12
12
  protected _clearArray(data: Record<string, any>): any;
13
13
  protected _dataPostProcess(data: any, langCode?: string): any;
14
+ setAccessToken(accessToken: string): this;
15
+ setRefreshToken(refreshToken: string): this;
14
16
  }
@@ -68,5 +68,13 @@ class SyncModules {
68
68
  const result = this._clearArray(normalize);
69
69
  return result;
70
70
  }
71
+ setAccessToken(accessToken) {
72
+ this.state.accessToken = accessToken;
73
+ return this;
74
+ }
75
+ setRefreshToken(refreshToken) {
76
+ this.state.refreshToken = refreshToken;
77
+ return this;
78
+ }
71
79
  }
72
80
  exports.default = SyncModules;
@@ -6,6 +6,7 @@
6
6
  * @property {function} updateOrderByMarkerAndId - Changing an order in the order store.
7
7
  * @property {function} getAllOrders - Getting all the order storage objects.
8
8
  * @property {function} getAllOrdersByMarker - Getting one order storage object by marker.
9
+ * @property {function} setAccessToken - Only for custom authorization. An intermediate method for setting up an access token.
9
10
 
10
11
  */
11
12
  interface IOrdersApi {
@@ -14,6 +15,7 @@ interface IOrdersApi {
14
15
  updateOrderByMarkerAndId(marker: string, id: number, data: IOrderData, langCode?: string): Promise<IBaseOrdersEntity>;
15
16
  getAllOrders(langCode?: string, limit?: number, offset?: number): Promise<Array<IOrdersEntity>>;
16
17
  getAllOrdersByMarker(marker: string, langCode?: string, limit?: number, offset?: number): Promise<Array<IOrdersByMarkersEntity>>;
18
+ setAccessToken(accessToken: string): IOrdersApi;
17
19
  }
18
20
  /**
19
21
  * @property {string} filename
@@ -31,9 +33,9 @@ interface IOrderProducts {
31
33
  id: number;
32
34
  title: string;
33
35
  sku: string | null;
34
- price: string;
36
+ price: number;
35
37
  quantity: number | null;
36
- previewImage: IPicture;
38
+ previewImage: Array<IPicture>;
37
39
  }
38
40
  /**
39
41
  * @property {string} marker - Marker of form field.
@@ -42,7 +44,7 @@ interface IOrderProducts {
42
44
  */
43
45
  interface IOrdersFormData {
44
46
  marker: string;
45
- value: string;
47
+ value: any;
46
48
  type: string;
47
49
  }
48
50
  /**
@@ -8,7 +8,7 @@
8
8
  * @property {function} getAccounts - Get all payment accounts as an array.
9
9
  * @property {function} getAccountById - Get a single payment account object by its identifier.
10
10
  * @property {function} webhookStripe - Webhook for Stripe.
11
- *
11
+ * @property {function} setAccessToken - Only for custom authorization. An intermediate method for setting up an access token.
12
12
  */
13
13
  interface IPaymentsApi {
14
14
  getSessions(limit: number, offset: number): Promise<Array<ISessionEntity>>;
@@ -18,6 +18,7 @@ interface IPaymentsApi {
18
18
  getAccounts(): Promise<Array<IAccountsEntity>>;
19
19
  getAccountById(id: number): Promise<IAccountsEntity>;
20
20
  webhookStripe(): Promise<boolean>;
21
+ setAccessToken(accessToken: string): IPaymentsApi;
21
22
  }
22
23
  /**
23
24
  *
@@ -4,10 +4,12 @@ import { IAuthFormData } from "../auth-provider/authProvidersInterfaces";
4
4
  *
5
5
  * @property {function} subscribeByMarker - Getting the data of an authorized user.
6
6
  * @property {function} unsubscribeByMarker - Updating a single user object.
7
+ * @property {function} setAccessToken - Only for custom authorization. An intermediate method for setting up an access token.
7
8
  */
8
9
  interface IUsers {
9
10
  getUser(langCode?: string): Promise<IUserEntity>;
10
11
  updateUser(data: IUserBody, langCode?: string): Promise<boolean>;
12
+ setAccessToken(accessToken: string): IUsers;
11
13
  }
12
14
  interface IUserEntity {
13
15
  id: number;
@@ -0,0 +1,11 @@
1
+ import AsyncModules from "../base/asyncModules";
2
+ import StateModule from "../base/stateModule";
3
+ /**
4
+ * Controllers for working with users
5
+ */
6
+ export default class UsersApi extends AsyncModules {
7
+ protected state: StateModule;
8
+ protected _url: string;
9
+ constructor(state: StateModule);
10
+ connect(): Promise<import("socket.io-client").Socket<import("@socket.io/component-emitter").DefaultEventsMap, import("@socket.io/component-emitter").DefaultEventsMap>>;
11
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const asyncModules_1 = require("../base/asyncModules");
4
+ const socket_io_client_1 = require("socket.io-client");
5
+ /**
6
+ * Controllers for working with users
7
+ */
8
+ class UsersApi extends asyncModules_1.default {
9
+ constructor(state) {
10
+ super(state);
11
+ this._url = state.url + '/api/content/ws';
12
+ }
13
+ async connect() {
14
+ const socket = (0, socket_io_client_1.io)(this._url, {
15
+ extraHeaders: {
16
+ "Authorization": this.state.accessToken,
17
+ "x-app-token": this.state.token
18
+ }
19
+ });
20
+ return socket;
21
+ }
22
+ }
23
+ exports.default = UsersApi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneentry",
3
- "version": "1.0.74",
3
+ "version": "1.0.75",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,6 +22,7 @@
22
22
  "@types/jest": "^29.5.11",
23
23
  "@types/node": "^20.10.5",
24
24
  "jest": "^29.7.0",
25
+ "socket.io-client": "^4.7.5",
25
26
  "ts-jest": "^29.1.1",
26
27
  "typescript": "^5.3.3"
27
28
  }