@rimori/client 2.4.0 → 2.5.0-next.1

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 (70) hide show
  1. package/dist/cli/scripts/init/dev-registration.js +4 -2
  2. package/dist/cli/scripts/init/main.js +1 -0
  3. package/dist/cli/scripts/release/release.js +0 -0
  4. package/dist/controller/SettingsController.d.ts +1 -1
  5. package/dist/controller/SharedContentController.d.ts +1 -1
  6. package/dist/fromRimori/EventBus.js +1 -1
  7. package/dist/index.d.ts +2 -2
  8. package/dist/plugin/CommunicationHandler.d.ts +13 -8
  9. package/dist/plugin/CommunicationHandler.js +44 -59
  10. package/dist/plugin/RimoriClient.d.ts +11 -195
  11. package/dist/plugin/RimoriClient.js +16 -298
  12. package/dist/plugin/StandaloneClient.d.ts +1 -1
  13. package/dist/plugin/StandaloneClient.js +3 -2
  14. package/dist/plugin/module/AIModule.d.ts +49 -0
  15. package/dist/plugin/module/AIModule.js +81 -0
  16. package/dist/plugin/module/DbModule.d.ts +30 -0
  17. package/dist/plugin/module/DbModule.js +51 -0
  18. package/dist/plugin/module/EventModule.d.ts +99 -0
  19. package/dist/plugin/module/EventModule.js +162 -0
  20. package/dist/{controller/ExerciseController.d.ts → plugin/module/ExerciseModule.d.ts} +20 -16
  21. package/dist/{controller/ExerciseController.js → plugin/module/ExerciseModule.js} +27 -20
  22. package/dist/plugin/module/PluginModule.d.ts +76 -0
  23. package/dist/plugin/module/PluginModule.js +88 -0
  24. package/package.json +8 -3
  25. package/.github/workflows/pre-release.yml +0 -126
  26. package/.prettierignore +0 -35
  27. package/eslint.config.js +0 -53
  28. package/example/docs/devdocs.md +0 -241
  29. package/example/docs/overview.md +0 -29
  30. package/example/docs/userdocs.md +0 -126
  31. package/example/rimori.config.ts +0 -91
  32. package/example/worker/vite.config.ts +0 -26
  33. package/example/worker/worker.ts +0 -11
  34. package/prettier.config.js +0 -8
  35. package/src/cli/scripts/init/dev-registration.ts +0 -189
  36. package/src/cli/scripts/init/env-setup.ts +0 -44
  37. package/src/cli/scripts/init/file-operations.ts +0 -58
  38. package/src/cli/scripts/init/html-cleaner.ts +0 -45
  39. package/src/cli/scripts/init/main.ts +0 -175
  40. package/src/cli/scripts/init/package-setup.ts +0 -113
  41. package/src/cli/scripts/init/router-transformer.ts +0 -332
  42. package/src/cli/scripts/init/tailwind-config.ts +0 -66
  43. package/src/cli/scripts/init/vite-config.ts +0 -73
  44. package/src/cli/scripts/release/detect-translation-languages.ts +0 -37
  45. package/src/cli/scripts/release/release-config-upload.ts +0 -119
  46. package/src/cli/scripts/release/release-db-update.ts +0 -97
  47. package/src/cli/scripts/release/release-file-upload.ts +0 -138
  48. package/src/cli/scripts/release/release.ts +0 -85
  49. package/src/cli/types/DatabaseTypes.ts +0 -125
  50. package/src/controller/AIController.ts +0 -295
  51. package/src/controller/AccomplishmentController.ts +0 -188
  52. package/src/controller/AudioController.ts +0 -64
  53. package/src/controller/ExerciseController.ts +0 -117
  54. package/src/controller/ObjectController.ts +0 -120
  55. package/src/controller/SettingsController.ts +0 -186
  56. package/src/controller/SharedContentController.ts +0 -365
  57. package/src/controller/TranslationController.ts +0 -136
  58. package/src/controller/VoiceController.ts +0 -33
  59. package/src/fromRimori/EventBus.ts +0 -382
  60. package/src/fromRimori/PluginTypes.ts +0 -214
  61. package/src/fromRimori/readme.md +0 -2
  62. package/src/index.ts +0 -19
  63. package/src/plugin/CommunicationHandler.ts +0 -310
  64. package/src/plugin/Logger.ts +0 -394
  65. package/src/plugin/RimoriClient.ts +0 -530
  66. package/src/plugin/StandaloneClient.ts +0 -125
  67. package/src/utils/difficultyConverter.ts +0 -15
  68. package/src/utils/endpoint.ts +0 -3
  69. package/src/worker/WorkerSetup.ts +0 -35
  70. package/tsconfig.json +0 -17
@@ -0,0 +1,99 @@
1
+ import { MainPanelAction } from '../../fromRimori/PluginTypes';
2
+ import { AccomplishmentPayload } from '../../controller/AccomplishmentController';
3
+ import { EventBusMessage, EventHandler, EventPayload, EventListener } from '../../fromRimori/EventBus';
4
+ /**
5
+ * Event module for plugin event bus operations.
6
+ * Provides methods for emitting, listening to, and responding to events.
7
+ */
8
+ export declare class EventModule {
9
+ private pluginId;
10
+ private accomplishmentController;
11
+ constructor(pluginId: string);
12
+ getGlobalEventTopic(preliminaryTopic: string): string;
13
+ /**
14
+ * Emit an event to Rimori or a plugin.
15
+ * The topic schema is:
16
+ * {pluginId}.{eventId}
17
+ * Check out the event bus documentation for more information.
18
+ * For triggering events from Rimori like context menu actions use the "global" keyword.
19
+ * @param topic The topic to emit the event on.
20
+ * @param data The data to emit.
21
+ * @param eventId The event id.
22
+ */
23
+ emit(topic: string, data?: any, eventId?: number): void;
24
+ /**
25
+ * Request an event.
26
+ * @param topic The topic to request the event on.
27
+ * @param data The data to request.
28
+ * @returns The response from the event.
29
+ */
30
+ request<T>(topic: string, data?: any): Promise<EventBusMessage<T>>;
31
+ /**
32
+ * Subscribe to an event.
33
+ * @param topic The topic to subscribe to.
34
+ * @param callback The callback to call when the event is emitted.
35
+ * @returns An EventListener object containing an off() method to unsubscribe the listeners.
36
+ */
37
+ on<T = EventPayload>(topic: string | string[], callback: EventHandler<T>): EventListener;
38
+ /**
39
+ * Subscribe to an event once.
40
+ * @param topic The topic to subscribe to.
41
+ * @param callback The callback to call when the event is emitted.
42
+ */
43
+ once<T = EventPayload>(topic: string, callback: EventHandler<T>): void;
44
+ /**
45
+ * Respond to an event.
46
+ * @param topic The topic to respond to.
47
+ * @param data The data to respond with.
48
+ */
49
+ respond<T = EventPayload>(topic: string | string[], data: EventPayload | ((data: EventBusMessage<T>) => EventPayload | Promise<EventPayload>)): void;
50
+ /**
51
+ * Emit an accomplishment.
52
+ * @param payload The payload to emit.
53
+ */
54
+ emitAccomplishment(payload: AccomplishmentPayload): void;
55
+ /**
56
+ * Subscribe to an accomplishment.
57
+ * @param accomplishmentTopic The topic to subscribe to.
58
+ * @param callback The callback to call when the accomplishment is emitted.
59
+ */
60
+ onAccomplishment(accomplishmentTopic: string, callback: (payload: EventBusMessage<AccomplishmentPayload>) => void): void;
61
+ /**
62
+ * Trigger an action that opens the sidebar and triggers an action in the designated plugin.
63
+ * @param pluginId The id of the plugin to trigger the action for.
64
+ * @param actionKey The key of the action to trigger.
65
+ * @param text Optional text to be used for the action like for example text that the translator would look up.
66
+ */
67
+ emitSidebarAction(pluginId: string, actionKey: string, text?: string): void;
68
+ /**
69
+ * Subscribe to main panel actions triggered by the user from the dashboard.
70
+ * @param callback Handler function that receives the action data when a matching action is triggered.
71
+ * @param actionsToListen Optional filter to listen only to specific action keys. If empty or not provided, all actions will trigger the callback.
72
+ * @returns An EventListener object with an `off()` method for cleanup.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * const listener = client.event.onMainPanelAction((data) => {
77
+ * console.log('Action received:', data.action_key);
78
+ * }, ['startSession', 'pauseSession']);
79
+ *
80
+ * // Clean up when component unmounts to prevent events from firing
81
+ * // when navigating away or returning to the page
82
+ * useEffect(() => {
83
+ * return () => listener.off();
84
+ * }, []);
85
+ * ```
86
+ *
87
+ * **Important:** Always call `listener.off()` when your component unmounts or when you no longer need to listen.
88
+ * This prevents the event handler from firing when navigating away from or returning to the page, which could
89
+ * cause unexpected behavior or duplicate event handling.
90
+ */
91
+ onMainPanelAction(callback: (data: MainPanelAction) => void, actionsToListen?: string | string[]): EventListener;
92
+ /**
93
+ * Subscribe to side panel actions triggered by the user from the dashboard.
94
+ * @param callback Handler function that receives the action data when a matching action is triggered.
95
+ * @param actionsToListen Optional filter to listen only to specific action keys. If empty or not provided, all actions will trigger the callback.
96
+ * @returns An EventListener object with an `off()` method for cleanup.
97
+ */
98
+ onSidePanelAction(callback: (data: MainPanelAction) => void, actionsToListen?: string | string[]): EventListener;
99
+ }
@@ -0,0 +1,162 @@
1
+ import { AccomplishmentController } from '../../controller/AccomplishmentController';
2
+ import { EventBus } from '../../fromRimori/EventBus';
3
+ /**
4
+ * Event module for plugin event bus operations.
5
+ * Provides methods for emitting, listening to, and responding to events.
6
+ */
7
+ export class EventModule {
8
+ constructor(pluginId) {
9
+ this.pluginId = pluginId;
10
+ this.accomplishmentController = new AccomplishmentController(pluginId);
11
+ }
12
+ getGlobalEventTopic(preliminaryTopic) {
13
+ var _a;
14
+ if (preliminaryTopic.startsWith('global.')) {
15
+ return preliminaryTopic;
16
+ }
17
+ if (preliminaryTopic.startsWith('self.')) {
18
+ return preliminaryTopic;
19
+ }
20
+ const topicParts = preliminaryTopic.split('.');
21
+ if (topicParts.length === 3) {
22
+ if (!topicParts[0].startsWith('pl') && topicParts[0] !== 'global') {
23
+ throw new Error("The event topic must start with the plugin id or 'global'.");
24
+ }
25
+ return preliminaryTopic;
26
+ }
27
+ else if (topicParts.length > 3) {
28
+ throw new Error(`The event topic must consist of 3 parts. <pluginId>.<topic area>.<action>. Received: ${preliminaryTopic}`);
29
+ }
30
+ const topicRoot = (_a = this.pluginId) !== null && _a !== void 0 ? _a : 'global';
31
+ return `${topicRoot}.${preliminaryTopic}`;
32
+ }
33
+ /**
34
+ * Emit an event to Rimori or a plugin.
35
+ * The topic schema is:
36
+ * {pluginId}.{eventId}
37
+ * Check out the event bus documentation for more information.
38
+ * For triggering events from Rimori like context menu actions use the "global" keyword.
39
+ * @param topic The topic to emit the event on.
40
+ * @param data The data to emit.
41
+ * @param eventId The event id.
42
+ */
43
+ emit(topic, data, eventId) {
44
+ const globalTopic = this.getGlobalEventTopic(topic);
45
+ EventBus.emit(this.pluginId, globalTopic, data, eventId);
46
+ }
47
+ /**
48
+ * Request an event.
49
+ * @param topic The topic to request the event on.
50
+ * @param data The data to request.
51
+ * @returns The response from the event.
52
+ */
53
+ request(topic, data) {
54
+ const globalTopic = this.getGlobalEventTopic(topic);
55
+ return EventBus.request(this.pluginId, globalTopic, data);
56
+ }
57
+ /**
58
+ * Subscribe to an event.
59
+ * @param topic The topic to subscribe to.
60
+ * @param callback The callback to call when the event is emitted.
61
+ * @returns An EventListener object containing an off() method to unsubscribe the listeners.
62
+ */
63
+ on(topic, callback) {
64
+ const topics = Array.isArray(topic) ? topic : [topic];
65
+ return EventBus.on(topics.map((t) => this.getGlobalEventTopic(t)), callback);
66
+ }
67
+ /**
68
+ * Subscribe to an event once.
69
+ * @param topic The topic to subscribe to.
70
+ * @param callback The callback to call when the event is emitted.
71
+ */
72
+ once(topic, callback) {
73
+ EventBus.once(this.getGlobalEventTopic(topic), callback);
74
+ }
75
+ /**
76
+ * Respond to an event.
77
+ * @param topic The topic to respond to.
78
+ * @param data The data to respond with.
79
+ */
80
+ respond(topic, data) {
81
+ const topics = Array.isArray(topic) ? topic : [topic];
82
+ EventBus.respond(this.pluginId, topics.map((t) => this.getGlobalEventTopic(t)), data);
83
+ }
84
+ /**
85
+ * Emit an accomplishment.
86
+ * @param payload The payload to emit.
87
+ */
88
+ emitAccomplishment(payload) {
89
+ this.accomplishmentController.emitAccomplishment(payload);
90
+ }
91
+ /**
92
+ * Subscribe to an accomplishment.
93
+ * @param accomplishmentTopic The topic to subscribe to.
94
+ * @param callback The callback to call when the accomplishment is emitted.
95
+ */
96
+ onAccomplishment(accomplishmentTopic, callback) {
97
+ this.accomplishmentController.subscribe(accomplishmentTopic, callback);
98
+ }
99
+ /**
100
+ * Trigger an action that opens the sidebar and triggers an action in the designated plugin.
101
+ * @param pluginId The id of the plugin to trigger the action for.
102
+ * @param actionKey The key of the action to trigger.
103
+ * @param text Optional text to be used for the action like for example text that the translator would look up.
104
+ */
105
+ emitSidebarAction(pluginId, actionKey, text) {
106
+ this.emit('global.sidebar.triggerAction', { plugin_id: pluginId, action_key: actionKey, text });
107
+ }
108
+ /**
109
+ * Subscribe to main panel actions triggered by the user from the dashboard.
110
+ * @param callback Handler function that receives the action data when a matching action is triggered.
111
+ * @param actionsToListen Optional filter to listen only to specific action keys. If empty or not provided, all actions will trigger the callback.
112
+ * @returns An EventListener object with an `off()` method for cleanup.
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * const listener = client.event.onMainPanelAction((data) => {
117
+ * console.log('Action received:', data.action_key);
118
+ * }, ['startSession', 'pauseSession']);
119
+ *
120
+ * // Clean up when component unmounts to prevent events from firing
121
+ * // when navigating away or returning to the page
122
+ * useEffect(() => {
123
+ * return () => listener.off();
124
+ * }, []);
125
+ * ```
126
+ *
127
+ * **Important:** Always call `listener.off()` when your component unmounts or when you no longer need to listen.
128
+ * This prevents the event handler from firing when navigating away from or returning to the page, which could
129
+ * cause unexpected behavior or duplicate event handling.
130
+ */
131
+ onMainPanelAction(callback, actionsToListen = []) {
132
+ const listeningActions = Array.isArray(actionsToListen) ? actionsToListen : [actionsToListen];
133
+ // this needs to be a emit and on because the main panel action is triggered by the user and not by the plugin
134
+ this.emit('action.requestMain');
135
+ return this.on('action.requestMain', ({ data }) => {
136
+ // console.log('Received action for main panel ' + data.action_key);
137
+ // console.log('Listening to actions', listeningActions);
138
+ if (listeningActions.length === 0 || listeningActions.includes(data.action_key)) {
139
+ callback(data);
140
+ }
141
+ });
142
+ }
143
+ /**
144
+ * Subscribe to side panel actions triggered by the user from the dashboard.
145
+ * @param callback Handler function that receives the action data when a matching action is triggered.
146
+ * @param actionsToListen Optional filter to listen only to specific action keys. If empty or not provided, all actions will trigger the callback.
147
+ * @returns An EventListener object with an `off()` method for cleanup.
148
+ */
149
+ onSidePanelAction(callback, actionsToListen = []) {
150
+ const listeningActions = Array.isArray(actionsToListen) ? actionsToListen : [actionsToListen];
151
+ // this needs to be a emit and on because the main panel action is triggered by the user and not by the plugin
152
+ this.emit('action.requestSidebar');
153
+ return this.on('action.requestSidebar', ({ data }) => {
154
+ // console.log("eventHandler .onSidePanelAction", data);
155
+ // console.log('Received action for sidebar ' + data.action);
156
+ // console.log('Listening to actions', listeningActions);
157
+ if (listeningActions.length === 0 || listeningActions.includes(data.action)) {
158
+ callback(data);
159
+ }
160
+ });
161
+ }
162
+ }
@@ -1,5 +1,6 @@
1
- import { SupabaseClient } from '@supabase/supabase-js';
2
- import { RimoriClient } from '../plugin/RimoriClient';
1
+ import { SupabaseClient } from '../CommunicationHandler';
2
+ import { RimoriCommunicationHandler, RimoriInfo } from '../CommunicationHandler';
3
+ import { EventModule } from './EventModule';
3
4
  export type TriggerAction = {
4
5
  action_key: string;
5
6
  } & Record<string, string | number | boolean>;
@@ -26,33 +27,36 @@ export interface Exercise {
26
27
  created_at?: string;
27
28
  updated_at?: string;
28
29
  }
29
- export declare class ExerciseController {
30
+ /**
31
+ * Controller for exercise-related operations.
32
+ * Provides access to weekly exercises and exercise management.
33
+ */
34
+ export declare class ExerciseModule {
30
35
  private supabase;
31
- private rimoriClient;
32
- constructor(supabase: SupabaseClient, rimoriClient: RimoriClient);
36
+ private communicationHandler;
37
+ private eventModule;
38
+ private backendUrl;
39
+ private token;
40
+ constructor(supabase: SupabaseClient, communicationHandler: RimoriCommunicationHandler, info: RimoriInfo, eventModule: EventModule);
33
41
  /**
34
42
  * Fetches weekly exercises from the weekly_exercises view.
35
43
  * Shows exercises for the current week that haven't expired.
36
44
  * @returns Array of exercise objects.
37
45
  */
38
- viewWeeklyExercises(): Promise<Exercise[]>;
46
+ view(): Promise<Exercise[]>;
39
47
  /**
40
- * Creates multiple exercises via the backend API.
41
- * All requests are made in parallel but only one event is emitted.
42
- * @param token The token to use for authentication.
43
- * @param backendUrl The URL of the backend API.
44
- * @param exercises Exercise creation parameters.
48
+ * Creates a new exercise or multiple exercises via the backend API.
49
+ * When creating multiple exercises, all requests are made in parallel but only one event is emitted.
50
+ * @param params Exercise creation parameters (single or array).
45
51
  * @returns Created exercise objects.
46
52
  */
47
- addExercise(token: string, backendUrl: string, exercises: CreateExerciseParams[]): Promise<Exercise[]>;
53
+ add(params: CreateExerciseParams | CreateExerciseParams[]): Promise<Exercise[]>;
48
54
  /**
49
55
  * Deletes an exercise via the backend API.
50
- * @param token The token to use for authentication.
51
- * @param backendUrl The URL of the backend API.
52
- * @param exerciseId The exercise ID to delete.
56
+ * @param id The exercise ID to delete.
53
57
  * @returns Success status.
54
58
  */
55
- deleteExercise(token: string, backendUrl: string, id: string): Promise<{
59
+ delete(id: string): Promise<{
56
60
  success: boolean;
57
61
  message: string;
58
62
  }>;
@@ -7,17 +7,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- export class ExerciseController {
11
- constructor(supabase, rimoriClient) {
10
+ /**
11
+ * Controller for exercise-related operations.
12
+ * Provides access to weekly exercises and exercise management.
13
+ */
14
+ export class ExerciseModule {
15
+ constructor(supabase, communicationHandler, info, eventModule) {
12
16
  this.supabase = supabase;
13
- this.rimoriClient = rimoriClient;
17
+ this.communicationHandler = communicationHandler;
18
+ this.eventModule = eventModule;
19
+ this.token = info.token;
20
+ this.backendUrl = info.backendUrl;
21
+ this.communicationHandler.onUpdate((updatedInfo) => {
22
+ this.token = updatedInfo.token;
23
+ });
14
24
  }
15
25
  /**
16
26
  * Fetches weekly exercises from the weekly_exercises view.
17
27
  * Shows exercises for the current week that haven't expired.
18
28
  * @returns Array of exercise objects.
19
29
  */
20
- viewWeeklyExercises() {
30
+ view() {
21
31
  return __awaiter(this, void 0, void 0, function* () {
22
32
  const { data, error } = yield this.supabase.from('weekly_exercises').select('*');
23
33
  if (error) {
@@ -27,21 +37,20 @@ export class ExerciseController {
27
37
  });
28
38
  }
29
39
  /**
30
- * Creates multiple exercises via the backend API.
31
- * All requests are made in parallel but only one event is emitted.
32
- * @param token The token to use for authentication.
33
- * @param backendUrl The URL of the backend API.
34
- * @param exercises Exercise creation parameters.
40
+ * Creates a new exercise or multiple exercises via the backend API.
41
+ * When creating multiple exercises, all requests are made in parallel but only one event is emitted.
42
+ * @param params Exercise creation parameters (single or array).
35
43
  * @returns Created exercise objects.
36
44
  */
37
- addExercise(token, backendUrl, exercises) {
45
+ add(params) {
38
46
  return __awaiter(this, void 0, void 0, function* () {
47
+ const exercises = Array.isArray(params) ? params : [params];
39
48
  const responses = yield Promise.all(exercises.map((exercise) => __awaiter(this, void 0, void 0, function* () {
40
- const response = yield fetch(`${backendUrl}/exercises`, {
49
+ const response = yield fetch(`${this.backendUrl}/exercises`, {
41
50
  method: 'POST',
42
51
  headers: {
43
52
  'Content-Type': 'application/json',
44
- Authorization: `Bearer ${token}`,
53
+ Authorization: `Bearer ${this.token}`,
45
54
  },
46
55
  body: JSON.stringify(exercise),
47
56
  });
@@ -51,30 +60,28 @@ export class ExerciseController {
51
60
  }
52
61
  return yield response.json();
53
62
  })));
54
- this.rimoriClient.event.emit('global.exercises.triggerChange');
63
+ this.eventModule.emit('global.exercises.triggerChange');
55
64
  return responses;
56
65
  });
57
66
  }
58
67
  /**
59
68
  * Deletes an exercise via the backend API.
60
- * @param token The token to use for authentication.
61
- * @param backendUrl The URL of the backend API.
62
- * @param exerciseId The exercise ID to delete.
69
+ * @param id The exercise ID to delete.
63
70
  * @returns Success status.
64
71
  */
65
- deleteExercise(token, backendUrl, id) {
72
+ delete(id) {
66
73
  return __awaiter(this, void 0, void 0, function* () {
67
- const response = yield fetch(`${backendUrl}/exercises/${id}`, {
74
+ const response = yield fetch(`${this.backendUrl}/exercises/${id}`, {
68
75
  method: 'DELETE',
69
76
  headers: {
70
- Authorization: `Bearer ${token}`,
77
+ Authorization: `Bearer ${this.token}`,
71
78
  },
72
79
  });
73
80
  if (!response.ok) {
74
81
  const errorText = yield response.text();
75
82
  throw new Error(`Failed to delete exercise: ${errorText}`);
76
83
  }
77
- this.rimoriClient.event.emit('global.exercises.triggerChange');
84
+ this.eventModule.emit('global.exercises.triggerChange');
78
85
  return yield response.json();
79
86
  });
80
87
  }
@@ -0,0 +1,76 @@
1
+ import { UserInfo } from '../../controller/SettingsController';
2
+ import { RimoriCommunicationHandler, RimoriInfo } from '../CommunicationHandler';
3
+ import { Translator } from '../../controller/TranslationController';
4
+ import { ActivePlugin, Plugin } from '../../fromRimori/PluginTypes';
5
+ import { SupabaseClient } from '../CommunicationHandler';
6
+ type Theme = 'light' | 'dark';
7
+ type ApplicationMode = 'main' | 'sidebar' | 'settings';
8
+ /**
9
+ * Controller for plugin-related operations.
10
+ * Provides access to plugin settings, user info, and plugin information.
11
+ */
12
+ export declare class PluginModule {
13
+ private settingsController;
14
+ private communicationHandler;
15
+ private translator;
16
+ private rimoriInfo;
17
+ pluginId: string;
18
+ /**
19
+ * The release channel of this plugin installation.
20
+ * Determines which database schema is used for plugin tables.
21
+ */
22
+ releaseChannel: string;
23
+ applicationMode: ApplicationMode;
24
+ theme: Theme;
25
+ constructor(supabase: SupabaseClient, communicationHandler: RimoriCommunicationHandler, info: RimoriInfo);
26
+ /**
27
+ * Set the settings for the plugin.
28
+ * @param settings The settings to set.
29
+ */
30
+ setSettings(settings: any): Promise<void>;
31
+ /**
32
+ * Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
33
+ * @param defaultSettings The default settings to use if no settings are found.
34
+ * @returns The settings for the plugin.
35
+ */
36
+ getSettings<T extends object>(defaultSettings: T): Promise<T>;
37
+ /**
38
+ * Get the current user info.
39
+ * Note: For reactive updates in React components, use the userInfo from useRimori() hook instead.
40
+ * @returns The user info.
41
+ */
42
+ getUserInfo(): UserInfo;
43
+ /**
44
+ * Register a callback to be notified when RimoriInfo is updated.
45
+ * This is useful for reacting to changes in user info, tokens, or other rimori data.
46
+ * @param callback - Function to call with the new RimoriInfo
47
+ * @returns Cleanup function to unregister the callback
48
+ */
49
+ onRimoriInfoUpdate(callback: (info: RimoriInfo) => void): () => void;
50
+ /**
51
+ * Retrieves information about plugins, including:
52
+ * - All installed plugins
53
+ * - The currently active plugin in the main panel
54
+ * - The currently active plugin in the side panel
55
+ */
56
+ getPluginInfo(): {
57
+ /**
58
+ * All installed plugins.
59
+ */
60
+ installedPlugins: Plugin[];
61
+ /**
62
+ * The plugin that is loaded in the main panel.
63
+ */
64
+ mainPanelPlugin?: ActivePlugin;
65
+ /**
66
+ * The plugin that is loaded in the side panel.
67
+ */
68
+ sidePanelPlugin?: ActivePlugin;
69
+ };
70
+ /**
71
+ * Get the translator for the plugin.
72
+ * @returns The translator for the plugin.
73
+ */
74
+ getTranslator(): Promise<Translator>;
75
+ }
76
+ export {};
@@ -0,0 +1,88 @@
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
+ import { SettingsController } from '../../controller/SettingsController';
11
+ import { Translator } from '../../controller/TranslationController';
12
+ /**
13
+ * Controller for plugin-related operations.
14
+ * Provides access to plugin settings, user info, and plugin information.
15
+ */
16
+ export class PluginModule {
17
+ constructor(supabase, communicationHandler, info) {
18
+ this.rimoriInfo = info;
19
+ this.communicationHandler = communicationHandler;
20
+ this.pluginId = info.pluginId;
21
+ this.releaseChannel = info.releaseChannel;
22
+ this.settingsController = new SettingsController(supabase, info.pluginId, info.guild);
23
+ const currentPlugin = info.installedPlugins.find((plugin) => plugin.id === info.pluginId);
24
+ this.translator = new Translator(info.interfaceLanguage, (currentPlugin === null || currentPlugin === void 0 ? void 0 : currentPlugin.endpoint) || '');
25
+ this.communicationHandler.onUpdate((updatedInfo) => (this.rimoriInfo = updatedInfo));
26
+ this.applicationMode = this.communicationHandler.getQueryParam('applicationMode');
27
+ this.theme = this.communicationHandler.getQueryParam('rm_theme') || 'light';
28
+ }
29
+ /**
30
+ * Set the settings for the plugin.
31
+ * @param settings The settings to set.
32
+ */
33
+ setSettings(settings) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ yield this.settingsController.setSettings(settings);
36
+ });
37
+ }
38
+ /**
39
+ * Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
40
+ * @param defaultSettings The default settings to use if no settings are found.
41
+ * @returns The settings for the plugin.
42
+ */
43
+ getSettings(defaultSettings) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ return yield this.settingsController.getSettings(defaultSettings);
46
+ });
47
+ }
48
+ /**
49
+ * Get the current user info.
50
+ * Note: For reactive updates in React components, use the userInfo from useRimori() hook instead.
51
+ * @returns The user info.
52
+ */
53
+ getUserInfo() {
54
+ return this.rimoriInfo.profile;
55
+ }
56
+ /**
57
+ * Register a callback to be notified when RimoriInfo is updated.
58
+ * This is useful for reacting to changes in user info, tokens, or other rimori data.
59
+ * @param callback - Function to call with the new RimoriInfo
60
+ * @returns Cleanup function to unregister the callback
61
+ */
62
+ onRimoriInfoUpdate(callback) {
63
+ return this.communicationHandler.onUpdate(callback);
64
+ }
65
+ /**
66
+ * Retrieves information about plugins, including:
67
+ * - All installed plugins
68
+ * - The currently active plugin in the main panel
69
+ * - The currently active plugin in the side panel
70
+ */
71
+ getPluginInfo() {
72
+ return {
73
+ installedPlugins: this.rimoriInfo.installedPlugins,
74
+ mainPanelPlugin: this.rimoriInfo.mainPanelPlugin,
75
+ sidePanelPlugin: this.rimoriInfo.sidePanelPlugin,
76
+ };
77
+ }
78
+ /**
79
+ * Get the translator for the plugin.
80
+ * @returns The translator for the plugin.
81
+ */
82
+ getTranslator() {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ yield this.translator.initialize();
85
+ return this.translator;
86
+ });
87
+ }
88
+ }
package/package.json CHANGED
@@ -1,18 +1,22 @@
1
1
  {
2
2
  "name": "@rimori/client",
3
- "version": "2.4.0",
3
+ "version": "2.5.0-next.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/rimori-org/rimori-client.git"
9
9
  },
10
- "license": "apache-2.0",
10
+ "license": "Apache-2.0",
11
11
  "bin": {
12
12
  "rimori-release": "./dist/cli/scripts/release/release.js",
13
13
  "rimori-init": "./dist/cli/scripts/init/main.js"
14
14
  },
15
15
  "type": "module",
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
16
20
  "exports": {
17
21
  ".": {
18
22
  "types": "./dist/index.d.ts",
@@ -27,12 +31,13 @@
27
31
  "format": "prettier --write ."
28
32
  },
29
33
  "dependencies": {
30
- "@supabase/supabase-js": "2.49.4",
34
+ "@supabase/postgrest-js": "^2.87.1",
31
35
  "dotenv": "16.5.0",
32
36
  "i18next": "^25.6.0"
33
37
  },
34
38
  "devDependencies": {
35
39
  "@eslint/js": "^9.37.0",
40
+ "@types/node": "^25.0.1",
36
41
  "eslint-config-prettier": "^10.1.8",
37
42
  "eslint-plugin-prettier": "^5.5.4",
38
43
  "eslint-plugin-react-hooks": "^7.0.0",