@wildix/xbees-connect 1.0.4-alpha.10 → 1.0.4

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildix/xbees-connect",
3
- "version": "1.0.4-alpha.1",
3
+ "version": "1.0.4-alpha.10",
4
4
  "description": "This library provides easy communication between x-bees and integrated web applications",
5
5
  "author": "dimitri.chernykh <dimitri.chernykh@wildix.com>",
6
6
  "homepage": "",
@@ -23,7 +23,7 @@
23
23
  ],
24
24
  "repository": {
25
25
  "type": "git",
26
- "url": "git@git.wildix.com:dimitri.chernykh/sdk-ui.git"
26
+ "url": "git@git.wildix.com:xbs/sdk-ui.git"
27
27
  },
28
28
  "publishConfig": {
29
29
  "access": "public"
@@ -34,7 +34,9 @@
34
34
  "typescript": "^5.2.2"
35
35
  },
36
36
  "parserOptions": {
37
- "project": ["./tsconfig.json"]
37
+ "project": [
38
+ "./tsconfig.json"
39
+ ]
38
40
  },
39
41
  "engines": {
40
42
  "node": ">=16"
@@ -14,6 +14,20 @@ export class Client {
14
14
  }
15
15
  return this.instance;
16
16
  }
17
+ static initialize(renderer) {
18
+ if (this.getInstance().showsUi()) {
19
+ try {
20
+ void renderer();
21
+ }
22
+ catch (error) {
23
+ console.error('Error on init rendering widget:', error);
24
+ }
25
+ }
26
+ else {
27
+ console.log('run daemon');
28
+ void this.getInstance().ready();
29
+ }
30
+ }
17
31
  worker;
18
32
  listeners = [];
19
33
  useSubscription = false;
@@ -21,7 +35,7 @@ export class Client {
21
35
  variant = null;
22
36
  constructor() {
23
37
  const params = new URLSearchParams(window.location.search);
24
- this.iframeId = params.get('iframeId') ?? undefined;
38
+ this.iframeId = params.get('iframeId');
25
39
  this.variant = params.get('variant');
26
40
  // @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
27
41
  this.worker = window.ReactNativeWebView
@@ -109,11 +123,11 @@ export class Client {
109
123
  toClipboard(payload) {
110
124
  return this.sendAsync({ type: ClientEventType.TO_CLIPBOARD, payload });
111
125
  }
112
- isNotAuthorized(payload) {
113
- return this.sendAsync({ type: ClientEventType.NOT_AUTHORIZED, payload });
126
+ isNotAuthorized() {
127
+ return this.sendAsync({ type: ClientEventType.NOT_AUTHORIZED });
114
128
  }
115
- isAuthorized(payload) {
116
- return this.sendAsync({ type: ClientEventType.AUTHORIZED, payload });
129
+ isAuthorized() {
130
+ return this.sendAsync({ type: ClientEventType.AUTHORIZED });
117
131
  }
118
132
  getContactsAutoSuggest(payload) {
119
133
  return this.sendAsync({
@@ -126,9 +140,7 @@ export class Client {
126
140
  this.useSubscription = true;
127
141
  window.addEventListener('message', this.onMessage.bind(this));
128
142
  }
129
- const foundThisEvent = this.listeners.find(({ eventName: _eventName, callback: _callback }) => {
130
- return eventName === _eventName && Object.is(callback, _callback);
131
- });
143
+ const foundThisEvent = this.listeners.find(({ eventName: _eventName, callback: _callback }) => eventName === _eventName && Object.is(callback, _callback));
132
144
  if (!foundThisEvent) {
133
145
  this.listeners.push({ eventName, callback });
134
146
  }
@@ -137,10 +149,8 @@ export class Client {
137
149
  };
138
150
  }
139
151
  removeEventListener(eventName, callback) {
140
- this.listeners = this.listeners.filter(({ eventName: _eventName, callback: _callback }) => {
141
- return !(Object.is(callback, _callback) &&
142
- (!eventName ? true : eventName === _eventName));
143
- });
152
+ this.listeners = this.listeners.filter(({ eventName: _eventName, callback: _callback }) => !(Object.is(callback, _callback) &&
153
+ (!eventName ? true : eventName === _eventName)));
144
154
  if (this.useSubscription && !this.listeners.length) {
145
155
  this.useSubscription = false;
146
156
  window.removeEventListener('message', this.onMessage.bind(this));
@@ -160,15 +170,13 @@ export class Client {
160
170
  }
161
171
  onSuggestContacts(callback) {
162
172
  return this.addEventListener(EventType.GET_CONTACTS_AUTO_SUGGEST, (query) => {
163
- const resolve = (contacts) => {
164
- return this.sendAsync({
165
- type: ClientEventType.CONTACTS_AUTO_SUGGEST,
166
- payload: {
167
- contacts,
168
- query,
169
- },
170
- });
171
- };
173
+ const resolve = (contacts) => this.sendAsync({
174
+ type: ClientEventType.CONTACTS_AUTO_SUGGEST,
175
+ payload: {
176
+ contacts,
177
+ query,
178
+ },
179
+ });
172
180
  const reject = (reason) => {
173
181
  console.debug(reason);
174
182
  };
@@ -5,11 +5,12 @@ import { AutoSuggestResult, Callback, ConnectClient, EventType, Reject, RemoveEv
5
5
  * */
6
6
  export declare class Client implements ConnectClient {
7
7
  private static instance;
8
- static getInstance(): ConnectClient;
8
+ static getInstance(): Client;
9
+ static initialize(renderer: () => Promise<void>): void;
9
10
  private worker;
10
11
  private listeners;
11
12
  private useSubscription;
12
- private readonly iframeId?;
13
+ private readonly iframeId;
13
14
  private readonly variant;
14
15
  constructor();
15
16
  private sendAsync;
@@ -27,8 +28,8 @@ export declare class Client implements ConnectClient {
27
28
  reboot(): Promise<Response>;
28
29
  setViewport(payload: ViewPortSize): Promise<Response>;
29
30
  toClipboard(payload: string): Promise<Response>;
30
- isNotAuthorized(payload: string): Promise<Response>;
31
- isAuthorized(payload: string): Promise<Response>;
31
+ isNotAuthorized(): Promise<Response>;
32
+ isAuthorized(): Promise<Response>;
32
33
  getContactsAutoSuggest(payload: AutoSuggestResult): Promise<Response>;
33
34
  addEventListener<T extends EventType = EventType>(eventName: T, callback: Callback<T>): RemoveEventListener;
34
35
  removeEventListener<T extends EventType = EventType>(eventName: T | null, callback: Callback<T>): void;
@@ -50,7 +50,7 @@ export type Message<T extends MessageType = MessageType> = {
50
50
  payload?: EventPayload<T>;
51
51
  };
52
52
  export type MessageResponse<T extends MessageType = MessageType> = Message<T> & {
53
- iframeId?: string;
53
+ iframeId: string;
54
54
  };
55
55
  export type Payload = string | Record<string, string> | ThemeChangePayload;
56
56
  export type Response<T extends Payload = Payload> = {
@@ -167,10 +167,10 @@ export interface ConnectClient {
167
167
  getContactsAutoSuggest: (payload: AutoSuggestResult) => Promise<Response>;
168
168
  /**
169
169
  * pushes to x-bees message that user is authorized and no more actions required */
170
- isAuthorized: (payload: string) => Promise<Response>;
170
+ isAuthorized: () => Promise<Response>;
171
171
  /**
172
172
  * pushes to x-bees message that user actions required */
173
- isNotAuthorized: (payload: string) => Promise<Response>;
173
+ isNotAuthorized: () => Promise<Response>;
174
174
  /**
175
175
  * Starts listen for one of the events of the x-bees and handle with the provided callback */
176
176
  addEventListener: <T extends EventType = EventType>(eventName: T, callback: Callback<T>) => RemoveEventListener;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildix/xbees-connect",
3
- "version": "1.0.4-alpha.10",
3
+ "version": "1.0.4",
4
4
  "description": "This library provides easy communication between x-bees and integrated web applications",
5
5
  "author": "dimitri.chernykh <dimitri.chernykh@wildix.com>",
6
6
  "homepage": "",
@@ -23,7 +23,7 @@
23
23
  ],
24
24
  "repository": {
25
25
  "type": "git",
26
- "url": "git@git.wildix.com:dimitri.chernykh/sdk-ui.git"
26
+ "url": "git@git.wildix.com:xbs/sdk-ui.git"
27
27
  },
28
28
  "publishConfig": {
29
29
  "access": "public"
@@ -41,5 +41,5 @@
41
41
  "engines": {
42
42
  "node": ">=16"
43
43
  },
44
- "gitHead": "2a4305e68084729846257fbee0d565c4beb0272c"
44
+ "gitHead": "e98842e62bf2e122084d24b473c266f314df1a1c"
45
45
  }