@rimori/client 2.5.18-next.1 → 2.5.18-next.2

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.
@@ -2,6 +2,7 @@ import { RimoriClient } from '../plugin/RimoriClient';
2
2
  /**
3
3
  * Sets up the web worker for the plugin to be able receive and send messages to Rimori.
4
4
  * @param pluginId - The id of the plugin to setup the worker for.
5
- * @param init - The function containing the initialization logic.
5
+ * @param init - The function containing the initialization logic. The init must be completed within 5s. For long running tasks use the init event (e.g. onboarding.triggerInitPlugin) or run the work async.
6
+ * @returns A promise that resolves when the worker is setup.
6
7
  */
7
8
  export declare function setupWorker(pluginId: string, init: (client: RimoriClient) => void | Promise<void>): Promise<void>;
@@ -12,7 +12,8 @@ import { EventBusHandler } from '../fromRimori/EventBus';
12
12
  /**
13
13
  * Sets up the web worker for the plugin to be able receive and send messages to Rimori.
14
14
  * @param pluginId - The id of the plugin to setup the worker for.
15
- * @param init - The function containing the initialization logic.
15
+ * @param init - The function containing the initialization logic. The init must be completed within 5s. For long running tasks use the init event (e.g. onboarding.triggerInitPlugin) or run the work async.
16
+ * @returns A promise that resolves when the worker is setup.
16
17
  */
17
18
  export function setupWorker(pluginId, init) {
18
19
  return __awaiter(this, void 0, void 0, function* () {
@@ -27,10 +28,15 @@ export function setupWorker(pluginId, init) {
27
28
  };
28
29
  // Assign the mock to globalThis.
29
30
  Object.assign(globalThis, { window: mockWindow });
30
- EventBusHandler.getInstance('Worker EventBus');
31
+ EventBusHandler.getInstance('Worker ' + pluginId + ' EventBus');
31
32
  const rimoriClient = yield RimoriClient.getInstance(pluginId);
32
33
  console.debug('[Worker] RimoriClient initialized.');
33
- yield init(rimoriClient);
34
+ const timoutError = new Error('[Worker ' +
35
+ pluginId +
36
+ '] Worker setup must complete within 5s. Use init event (e.g. onboarding.triggerInitPlugin) or run work async.');
37
+ const initPromise = Promise.resolve(init(rimoriClient));
38
+ const timeout = new Promise((_, reject) => setTimeout(() => reject(timoutError), 5000));
39
+ yield Promise.race([initPromise, timeout]);
34
40
  console.debug('[Worker] Worker initialized.');
35
41
  rimoriClient.event.emit('self.rimori.triggerInitFinished');
36
42
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimori/client",
3
- "version": "2.5.18-next.1",
3
+ "version": "2.5.18-next.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {