@rimori/client 2.5.32 → 2.5.33

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.
Files changed (28) hide show
  1. package/dist/cli/scripts/init/dev-registration.js +118 -136
  2. package/dist/cli/scripts/init/main.js +116 -127
  3. package/dist/cli/scripts/init/package-setup.js +15 -2
  4. package/dist/cli/scripts/release/detect-translation-languages.js +24 -35
  5. package/dist/cli/scripts/release/release-config-upload.js +87 -100
  6. package/dist/cli/scripts/release/release-db-update.js +70 -81
  7. package/dist/cli/scripts/release/release-file-upload.js +75 -91
  8. package/dist/cli/scripts/release/release-prompts-upload.js +60 -72
  9. package/dist/cli/scripts/release/release.js +20 -31
  10. package/dist/controller/AccomplishmentController.js +12 -12
  11. package/dist/controller/AudioController.js +15 -33
  12. package/dist/controller/TranslationController.js +108 -118
  13. package/dist/fromRimori/EventBus.js +20 -31
  14. package/dist/plugin/CommunicationHandler.js +73 -81
  15. package/dist/plugin/Logger.js +71 -83
  16. package/dist/plugin/RimoriClient.js +31 -31
  17. package/dist/plugin/StandaloneClient.js +81 -98
  18. package/dist/plugin/TTS/ChunkedAudioPlayer.js +31 -41
  19. package/dist/plugin/TTS/MessageSender.js +28 -37
  20. package/dist/plugin/module/AIModule.js +215 -237
  21. package/dist/plugin/module/DbModule.js +22 -31
  22. package/dist/plugin/module/EventModule.js +23 -32
  23. package/dist/plugin/module/ExerciseModule.js +42 -56
  24. package/dist/plugin/module/PluginModule.js +97 -106
  25. package/dist/plugin/module/SharedContentController.js +170 -207
  26. package/dist/plugin/module/StorageModule.js +18 -29
  27. package/dist/worker/WorkerSetup.js +23 -34
  28. package/package.json +1 -1
@@ -1,13 +1,6 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  export class SharedContentController {
2
+ supabase;
3
+ rimoriClient;
11
4
  constructor(supabase, rimoriClient) {
12
5
  this.supabase = supabase;
13
6
  this.rimoriClient = rimoriClient;
@@ -29,30 +22,28 @@ export class SharedContentController {
29
22
  * @param params.ignoreSkillLevel - If true, don't filter by skill level or add skill level guidance to AI instructions
30
23
  * @returns Existing or newly generated shared content item
31
24
  */
32
- getNew(params) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- // Generate new content via backend endpoint
35
- const response = yield this.rimoriClient.runtime.fetchBackend('/shared-content/generate', {
36
- method: 'POST',
37
- body: JSON.stringify({
38
- tableName: params.table,
39
- skillType: params.skillType,
40
- placeholders: params.placeholders,
41
- filter: params.filter,
42
- customFields: params.customFields,
43
- tool: params.tool,
44
- options: {
45
- skipDbSave: params.skipDbSave,
46
- isPrivate: params.isPrivate,
47
- ignoreSkillLevel: params.ignoreSkillLevel,
48
- },
49
- }),
50
- });
51
- if (!response.ok) {
52
- throw new Error(`Failed to generate shared content: ${response.statusText}`);
53
- }
54
- return yield response.json();
25
+ async getNew(params) {
26
+ // Generate new content via backend endpoint
27
+ const response = await this.rimoriClient.runtime.fetchBackend('/shared-content/generate', {
28
+ method: 'POST',
29
+ body: JSON.stringify({
30
+ tableName: params.table,
31
+ skillType: params.skillType,
32
+ placeholders: params.placeholders,
33
+ filter: params.filter,
34
+ customFields: params.customFields,
35
+ tool: params.tool,
36
+ options: {
37
+ skipDbSave: params.skipDbSave,
38
+ isPrivate: params.isPrivate,
39
+ ignoreSkillLevel: params.ignoreSkillLevel,
40
+ },
41
+ }),
55
42
  });
43
+ if (!response.ok) {
44
+ throw new Error(`Failed to generate shared content: ${response.statusText}`);
45
+ }
46
+ return await response.json();
56
47
  }
57
48
  /**
58
49
  * Search for shared content by topic using RAG (semantic similarity).
@@ -62,21 +53,19 @@ export class SharedContentController {
62
53
  * @param limit - Maximum number of results to return (default: 10)
63
54
  * @returns Matching shared content
64
55
  */
65
- searchByTopic(tableName_1, topic_1) {
66
- return __awaiter(this, arguments, void 0, function* (tableName, topic, limit = 10) {
67
- const response = yield this.rimoriClient.runtime.fetchBackend('/shared-content/get-by-topic', {
68
- method: 'POST',
69
- body: JSON.stringify({
70
- tableName,
71
- limit,
72
- filter: { title: { filterType: 'rag', value: topic } },
73
- }),
74
- });
75
- if (!response.ok) {
76
- throw new Error(`Failed to search shared content: ${response.statusText}`);
77
- }
78
- return (yield response.json());
56
+ async searchByTopic(tableName, topic, limit = 10) {
57
+ const response = await this.rimoriClient.runtime.fetchBackend('/shared-content/get-by-topic', {
58
+ method: 'POST',
59
+ body: JSON.stringify({
60
+ tableName,
61
+ limit,
62
+ filter: { title: { filterType: 'rag', value: topic } },
63
+ }),
79
64
  });
65
+ if (!response.ok) {
66
+ throw new Error(`Failed to search shared content: ${response.statusText}`);
67
+ }
68
+ return (await response.json());
80
69
  }
81
70
  /**
82
71
  * Get bookmarked shared content.
@@ -84,21 +73,19 @@ export class SharedContentController {
84
73
  * @param limit - Maximum number of results
85
74
  * @returns Array of bookmarked content
86
75
  */
87
- getBookmarked(tableName_1) {
88
- return __awaiter(this, arguments, void 0, function* (tableName, limit = 30) {
89
- const fullTableName = this.getTableName(tableName);
90
- const completedTableName = this.getCompletedTableName(tableName);
91
- const { data, error } = yield this.supabase
92
- .from(fullTableName)
93
- .select(`*, completed:${completedTableName}!inner(*)`)
94
- .eq(`completed.bookmarked`, true)
95
- .limit(limit);
96
- if (error) {
97
- console.error('Error fetching bookmarked content:', error);
98
- throw new Error('Error fetching bookmarked content');
99
- }
100
- return (data || []);
101
- });
76
+ async getBookmarked(tableName, limit = 30) {
77
+ const fullTableName = this.getTableName(tableName);
78
+ const completedTableName = this.getCompletedTableName(tableName);
79
+ const { data, error } = await this.supabase
80
+ .from(fullTableName)
81
+ .select(`*, completed:${completedTableName}!inner(*)`)
82
+ .eq(`completed.bookmarked`, true)
83
+ .limit(limit);
84
+ if (error) {
85
+ console.error('Error fetching bookmarked content:', error);
86
+ throw new Error('Error fetching bookmarked content');
87
+ }
88
+ return (data || []);
102
89
  }
103
90
  /**
104
91
  * Get ongoing shared content.
@@ -106,21 +93,19 @@ export class SharedContentController {
106
93
  * @param limit - Maximum number of results
107
94
  * @returns Array of ongoing content
108
95
  */
109
- getOngoing(tableName_1) {
110
- return __awaiter(this, arguments, void 0, function* (tableName, limit = 30) {
111
- const fullTableName = this.getTableName(tableName);
112
- const completedTableName = this.getCompletedTableName(tableName);
113
- const { data, error } = yield this.supabase
114
- .from(fullTableName)
115
- .select(`*, completed:${completedTableName}!inner(*)`)
116
- .eq(`completed.state`, 'ongoing')
117
- .limit(limit);
118
- if (error) {
119
- console.error('Error fetching ongoing content:', error);
120
- throw new Error('Error fetching ongoing content');
121
- }
122
- return (data || []);
123
- });
96
+ async getOngoing(tableName, limit = 30) {
97
+ const fullTableName = this.getTableName(tableName);
98
+ const completedTableName = this.getCompletedTableName(tableName);
99
+ const { data, error } = await this.supabase
100
+ .from(fullTableName)
101
+ .select(`*, completed:${completedTableName}!inner(*)`)
102
+ .eq(`completed.state`, 'ongoing')
103
+ .limit(limit);
104
+ if (error) {
105
+ console.error('Error fetching ongoing content:', error);
106
+ throw new Error('Error fetching ongoing content');
107
+ }
108
+ return (data || []);
124
109
  }
125
110
  /**
126
111
  * Get completed shared content.
@@ -128,39 +113,35 @@ export class SharedContentController {
128
113
  * @param limit - Maximum number of results
129
114
  * @returns Array of completed content
130
115
  */
131
- getCompleted(tableName_1) {
132
- return __awaiter(this, arguments, void 0, function* (tableName, limit = 30) {
133
- const fullTableName = this.getTableName(tableName);
134
- const completedTableName = this.getCompletedTableName(tableName);
135
- const { data, error } = yield this.supabase
136
- .from(fullTableName)
137
- .select(`*, completed:${completedTableName}!inner(*)`)
138
- .eq(`completed.state`, 'completed')
139
- .limit(limit);
140
- if (error) {
141
- console.error('Error fetching completed content:', error);
142
- throw new Error('Error fetching completed content');
143
- }
144
- return (data || []);
145
- });
116
+ async getCompleted(tableName, limit = 30) {
117
+ const fullTableName = this.getTableName(tableName);
118
+ const completedTableName = this.getCompletedTableName(tableName);
119
+ const { data, error } = await this.supabase
120
+ .from(fullTableName)
121
+ .select(`*, completed:${completedTableName}!inner(*)`)
122
+ .eq(`completed.state`, 'completed')
123
+ .limit(limit);
124
+ if (error) {
125
+ console.error('Error fetching completed content:', error);
126
+ throw new Error('Error fetching completed content');
127
+ }
128
+ return (data || []);
146
129
  }
147
130
  /**
148
131
  * Mark shared content as completed.
149
132
  * @param tableName - Name of the shared content table
150
133
  * @param contentId - ID of the content to mark as completed
151
134
  */
152
- complete(tableName, contentId) {
153
- return __awaiter(this, void 0, void 0, function* () {
154
- const completedTableName = this.getCompletedTableName(tableName);
155
- const { error } = yield this.supabase.from(completedTableName).upsert({
156
- content_id: contentId,
157
- state: 'completed',
158
- }, { onConflict: 'content_id,user_id' });
159
- if (error) {
160
- console.error('Error completing shared content:', error);
161
- throw new Error('Error completing shared content');
162
- }
163
- });
135
+ async complete(tableName, contentId) {
136
+ const completedTableName = this.getCompletedTableName(tableName);
137
+ const { error } = await this.supabase.from(completedTableName).upsert({
138
+ content_id: contentId,
139
+ state: 'completed',
140
+ }, { onConflict: 'content_id,user_id' });
141
+ if (error) {
142
+ console.error('Error completing shared content:', error);
143
+ throw new Error('Error completing shared content');
144
+ }
164
145
  }
165
146
  /**
166
147
  * Update the state of shared content.
@@ -168,18 +149,16 @@ export class SharedContentController {
168
149
  * @param contentId - ID of the content
169
150
  * @param state - New state
170
151
  */
171
- updateState(tableName, contentId, state) {
172
- return __awaiter(this, void 0, void 0, function* () {
173
- const completedTableName = this.getCompletedTableName(tableName);
174
- const { error } = yield this.supabase.from(completedTableName).upsert({
175
- content_id: contentId,
176
- state,
177
- }, { onConflict: 'content_id,user_id' });
178
- if (error) {
179
- console.error('Error updating content state:', error);
180
- throw new Error('Error updating content state');
181
- }
182
- });
152
+ async updateState(tableName, contentId, state) {
153
+ const completedTableName = this.getCompletedTableName(tableName);
154
+ const { error } = await this.supabase.from(completedTableName).upsert({
155
+ content_id: contentId,
156
+ state,
157
+ }, { onConflict: 'content_id,user_id' });
158
+ if (error) {
159
+ console.error('Error updating content state:', error);
160
+ throw new Error('Error updating content state');
161
+ }
183
162
  }
184
163
  /**
185
164
  * Bookmark or unbookmark shared content.
@@ -187,18 +166,16 @@ export class SharedContentController {
187
166
  * @param contentId - ID of the content
188
167
  * @param bookmarked - Whether to bookmark or unbookmark
189
168
  */
190
- bookmark(tableName, contentId, bookmarked) {
191
- return __awaiter(this, void 0, void 0, function* () {
192
- const completedTableName = this.getCompletedTableName(tableName);
193
- const { error } = yield this.supabase.from(completedTableName).upsert({
194
- content_id: contentId,
195
- bookmarked,
196
- }, { onConflict: 'content_id,user_id' });
197
- if (error) {
198
- console.error('Error bookmarking content:', error);
199
- throw new Error('Error bookmarking content');
200
- }
201
- });
169
+ async bookmark(tableName, contentId, bookmarked) {
170
+ const completedTableName = this.getCompletedTableName(tableName);
171
+ const { error } = await this.supabase.from(completedTableName).upsert({
172
+ content_id: contentId,
173
+ bookmarked,
174
+ }, { onConflict: 'content_id,user_id' });
175
+ if (error) {
176
+ console.error('Error bookmarking content:', error);
177
+ throw new Error('Error bookmarking content');
178
+ }
202
179
  }
203
180
  /**
204
181
  * React to shared content with like/dislike.
@@ -206,18 +183,16 @@ export class SharedContentController {
206
183
  * @param contentId - ID of the content
207
184
  * @param reaction - Reaction type or null to remove reaction
208
185
  */
209
- react(tableName, contentId, reaction) {
210
- return __awaiter(this, void 0, void 0, function* () {
211
- const completedTableName = this.getCompletedTableName(tableName);
212
- const { error } = yield this.supabase.from(completedTableName).upsert({
213
- content_id: contentId,
214
- reaction,
215
- }, { onConflict: 'content_id,user_id' });
216
- if (error) {
217
- console.error('Error reacting to content:', error);
218
- throw new Error('Error reacting to content');
219
- }
220
- });
186
+ async react(tableName, contentId, reaction) {
187
+ const completedTableName = this.getCompletedTableName(tableName);
188
+ const { error } = await this.supabase.from(completedTableName).upsert({
189
+ content_id: contentId,
190
+ reaction,
191
+ }, { onConflict: 'content_id,user_id' });
192
+ if (error) {
193
+ console.error('Error reacting to content:', error);
194
+ throw new Error('Error reacting to content');
195
+ }
221
196
  }
222
197
  /**
223
198
  * Get a specific shared content item by ID.
@@ -225,16 +200,14 @@ export class SharedContentController {
225
200
  * @param contentId - ID of the content
226
201
  * @returns The shared content item
227
202
  */
228
- get(tableName, contentId) {
229
- return __awaiter(this, void 0, void 0, function* () {
230
- const fullTableName = this.getTableName(tableName);
231
- const { data, error } = yield this.supabase.from(fullTableName).select('*').eq('id', contentId).single();
232
- if (error) {
233
- console.error('Error fetching shared content:', error);
234
- throw new Error('Error fetching shared content');
235
- }
236
- return data;
237
- });
203
+ async get(tableName, contentId) {
204
+ const fullTableName = this.getTableName(tableName);
205
+ const { data, error } = await this.supabase.from(fullTableName).select('*').eq('id', contentId).single();
206
+ if (error) {
207
+ console.error('Error fetching shared content:', error);
208
+ throw new Error('Error fetching shared content');
209
+ }
210
+ return data;
238
211
  }
239
212
  /**
240
213
  * Fetch all shared content items.
@@ -242,16 +215,14 @@ export class SharedContentController {
242
215
  * @param limit - Maximum number of results (default: 100)
243
216
  * @returns Array of all shared content items
244
217
  */
245
- getAll(tableName_1) {
246
- return __awaiter(this, arguments, void 0, function* (tableName, limit = 100) {
247
- const fullTableName = this.getTableName(tableName);
248
- const { data, error } = yield this.supabase.from(fullTableName).select('*').limit(limit);
249
- if (error) {
250
- console.error('Error fetching all shared content:', error);
251
- throw new Error('Error fetching all shared content');
252
- }
253
- return (data || []);
254
- });
218
+ async getAll(tableName, limit = 100) {
219
+ const fullTableName = this.getTableName(tableName);
220
+ const { data, error } = await this.supabase.from(fullTableName).select('*').limit(limit);
221
+ if (error) {
222
+ console.error('Error fetching all shared content:', error);
223
+ throw new Error('Error fetching all shared content');
224
+ }
225
+ return (data || []);
255
226
  }
256
227
  /**
257
228
  * Create new shared content manually.
@@ -259,16 +230,14 @@ export class SharedContentController {
259
230
  * @param content - Content to create
260
231
  * @returns Created content
261
232
  */
262
- create(tableName, content) {
263
- return __awaiter(this, void 0, void 0, function* () {
264
- const fullTableName = this.getTableName(tableName);
265
- const { data, error } = yield this.supabase.from(fullTableName).insert(content).select().single();
266
- if (error) {
267
- console.error('Error creating shared content:', error);
268
- throw new Error('Error creating shared content');
269
- }
270
- return data;
271
- });
233
+ async create(tableName, content) {
234
+ const fullTableName = this.getTableName(tableName);
235
+ const { data, error } = await this.supabase.from(fullTableName).insert(content).select().single();
236
+ if (error) {
237
+ console.error('Error creating shared content:', error);
238
+ throw new Error('Error creating shared content');
239
+ }
240
+ return data;
272
241
  }
273
242
  /**
274
243
  * Update existing shared content via backend.
@@ -279,22 +248,20 @@ export class SharedContentController {
279
248
  * @param updates - Updates to apply
280
249
  * @returns Updated content
281
250
  */
282
- update(tableName, contentId, updates) {
283
- return __awaiter(this, void 0, void 0, function* () {
284
- const response = yield this.rimoriClient.runtime.fetchBackend('/shared-content/update', {
285
- method: 'POST',
286
- body: JSON.stringify({
287
- tableName,
288
- contentId,
289
- updates,
290
- }),
291
- });
292
- if (!response.ok) {
293
- console.error('Error updating shared content:', response.statusText);
294
- throw new Error(`Failed to update shared content: ${response.statusText}`);
295
- }
296
- return (yield response.json());
251
+ async update(tableName, contentId, updates) {
252
+ const response = await this.rimoriClient.runtime.fetchBackend('/shared-content/update', {
253
+ method: 'POST',
254
+ body: JSON.stringify({
255
+ tableName,
256
+ contentId,
257
+ updates,
258
+ }),
297
259
  });
260
+ if (!response.ok) {
261
+ console.error('Error updating shared content:', response.statusText);
262
+ throw new Error(`Failed to update shared content: ${response.statusText}`);
263
+ }
264
+ return (await response.json());
298
265
  }
299
266
  /**
300
267
  * Request validation for shared content.
@@ -304,36 +271,32 @@ export class SharedContentController {
304
271
  * @param contentId - ID of the content to validate
305
272
  * @returns Validation result with new content_status
306
273
  */
307
- validate(tableName, contentId) {
308
- return __awaiter(this, void 0, void 0, function* () {
309
- const response = yield this.rimoriClient.runtime.fetchBackend('/shared-content/validate', {
310
- method: 'POST',
311
- body: JSON.stringify({
312
- tableName,
313
- contentId,
314
- }),
315
- });
316
- if (!response.ok) {
317
- console.error('Error validating shared content:', response.statusText);
318
- throw new Error(`Failed to validate shared content: ${response.statusText}`);
319
- }
320
- return yield response.json();
274
+ async validate(tableName, contentId) {
275
+ const response = await this.rimoriClient.runtime.fetchBackend('/shared-content/validate', {
276
+ method: 'POST',
277
+ body: JSON.stringify({
278
+ tableName,
279
+ contentId,
280
+ }),
321
281
  });
282
+ if (!response.ok) {
283
+ console.error('Error validating shared content:', response.statusText);
284
+ throw new Error(`Failed to validate shared content: ${response.statusText}`);
285
+ }
286
+ return await response.json();
322
287
  }
323
288
  /**
324
289
  * Delete shared content.
325
290
  * @param tableName - Name of the shared content table
326
291
  * @param contentId - ID of the content to delete
327
292
  */
328
- remove(tableName, contentId) {
329
- return __awaiter(this, void 0, void 0, function* () {
330
- const fullTableName = this.getTableName(tableName);
331
- const { error } = yield this.supabase.from(fullTableName).delete().eq('id', contentId);
332
- if (error) {
333
- console.error('Error deleting shared content:', error);
334
- throw new Error('Error deleting shared content');
335
- }
336
- });
293
+ async remove(tableName, contentId) {
294
+ const fullTableName = this.getTableName(tableName);
295
+ const { error } = await this.supabase.from(fullTableName).delete().eq('id', contentId);
296
+ if (error) {
297
+ console.error('Error deleting shared content:', error);
298
+ throw new Error('Error deleting shared content');
299
+ }
337
300
  }
338
301
  getCompletedTableName(tableName) {
339
302
  return this.getTableName(tableName) + '_completed';
@@ -1,13 +1,5 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  export class StorageModule {
2
+ controller;
11
3
  constructor(controller) {
12
4
  this.controller = controller;
13
5
  }
@@ -20,26 +12,23 @@ export class StorageModule {
20
12
  *
21
13
  * @returns `{ data: { url, path } }` on success, `{ error }` on failure.
22
14
  */
23
- uploadImage(pngBlob) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- var _a;
26
- const formData = new FormData();
27
- formData.append('file', pngBlob, 'image.png');
28
- try {
29
- const response = yield this.controller.fetchBackend('/plugin-images/upload', {
30
- method: 'POST',
31
- body: formData,
32
- });
33
- if (!response.ok) {
34
- const body = (yield response.json().catch(() => ({})));
35
- return { error: new Error((_a = body.message) !== null && _a !== void 0 ? _a : `Upload failed (${response.status})`) };
36
- }
37
- const result = (yield response.json());
38
- return { data: result };
15
+ async uploadImage(pngBlob) {
16
+ const formData = new FormData();
17
+ formData.append('file', pngBlob, 'image.png');
18
+ try {
19
+ const response = await this.controller.fetchBackend('/plugin-images/upload', {
20
+ method: 'POST',
21
+ body: formData,
22
+ });
23
+ if (!response.ok) {
24
+ const body = (await response.json().catch(() => ({})));
25
+ return { error: new Error(body.message ?? `Upload failed (${response.status})`) };
39
26
  }
40
- catch (err) {
41
- return { error: err instanceof Error ? err : new Error(String(err)) };
42
- }
43
- });
27
+ const result = (await response.json());
28
+ return { data: result };
29
+ }
30
+ catch (err) {
31
+ return { error: err instanceof Error ? err : new Error(String(err)) };
32
+ }
44
33
  }
45
34
  }
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { RimoriClient } from '../plugin/RimoriClient';
11
2
  import { EventBusHandler } from '../fromRimori/EventBus';
12
3
  /**
@@ -15,29 +6,27 @@ import { EventBusHandler } from '../fromRimori/EventBus';
15
6
  * @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
7
  * @returns A promise that resolves when the worker is setup.
17
8
  */
18
- export function setupWorker(pluginId, init) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- // Mock of the window object for the worker context to be able to use the PluginController.
21
- const mockWindow = {
22
- isWorker: true,
23
- location: {},
24
- parent: {
25
- postMessage: () => { },
26
- },
27
- addEventListener: () => { },
28
- };
29
- // Assign the mock to globalThis.
30
- Object.assign(globalThis, { window: mockWindow });
31
- EventBusHandler.getInstance('Worker ' + pluginId + ' EventBus');
32
- const rimoriClient = yield RimoriClient.getInstance(pluginId);
33
- console.debug('[Worker] RimoriClient initialized.');
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]);
40
- console.debug('[Worker] Worker initialized.');
41
- rimoriClient.event.emit('self.rimori.triggerInitFinished');
42
- });
9
+ export async function setupWorker(pluginId, init) {
10
+ // Mock of the window object for the worker context to be able to use the PluginController.
11
+ const mockWindow = {
12
+ isWorker: true,
13
+ location: {},
14
+ parent: {
15
+ postMessage: () => { },
16
+ },
17
+ addEventListener: () => { },
18
+ };
19
+ // Assign the mock to globalThis.
20
+ Object.assign(globalThis, { window: mockWindow });
21
+ EventBusHandler.getInstance('Worker ' + pluginId + ' EventBus');
22
+ const rimoriClient = await RimoriClient.getInstance(pluginId);
23
+ console.debug('[Worker] RimoriClient initialized.');
24
+ const timoutError = new Error('[Worker ' +
25
+ pluginId +
26
+ '] Worker setup must complete within 5s. Use init event (e.g. onboarding.triggerInitPlugin) or run work async.');
27
+ const initPromise = Promise.resolve(init(rimoriClient));
28
+ const timeout = new Promise((_, reject) => setTimeout(() => reject(timoutError), 5000));
29
+ await Promise.race([initPromise, timeout]);
30
+ console.debug('[Worker] Worker initialized.');
31
+ rimoriClient.event.emit('self.rimori.triggerInitFinished');
43
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimori/client",
3
- "version": "2.5.32",
3
+ "version": "2.5.33",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {