@rimori/client 2.1.7 → 2.2.0

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.
@@ -42,8 +42,10 @@ export interface DbColumnDefinition {
42
42
  restrict?: {
43
43
  /** Restrictions for the user */
44
44
  user: Partial<Omit<DbPermissionDefinition, 'delete'>>;
45
- /** Restrictions for the moderator */
46
- moderator?: Partial<Omit<DbPermissionDefinition, 'delete'>>;
45
+ /** Restrictions for the guild moderator */
46
+ guild_moderator?: Partial<Omit<DbPermissionDefinition, 'delete'>>;
47
+ /** Restrictions for the language moderator */
48
+ lang_moderator?: Partial<Omit<DbPermissionDefinition, 'delete'>>;
47
49
  };
48
50
  }
49
51
  /**
@@ -69,8 +71,12 @@ export interface DbTableDefinition {
69
71
  description: string;
70
72
  /** Permissions for the table */
71
73
  permissions: {
74
+ /** Permissions for the user */
72
75
  user: DbPermissionDefinition;
73
- moderator?: DbPermissionDefinition;
76
+ /** Permissions for the guild moderator */
77
+ guild_moderator?: DbPermissionDefinition;
78
+ /** Permissions for the language moderator */
79
+ lang_moderator?: DbPermissionDefinition;
74
80
  };
75
81
  /** Column definitions for the table */
76
82
  columns: {
@@ -81,11 +87,13 @@ export interface DbTableDefinition {
81
87
  * Permission definition for a database table.
82
88
  * NONE means the action is not allowed.
83
89
  * OWN means only do the action on your own records.
90
+ * GUILD means do the action on all records in the guild.
91
+ * LANG means do the action on all records in the language.
84
92
  * ALL means do the action on all records.
85
93
  *
86
94
  * Defines the permissions for a database table.
87
95
  */
88
- export type DbPermission = 'NONE' | 'OWN' | 'ALL';
96
+ export type DbPermission = 'NONE' | 'OWN' | 'GUILD' | 'LANG' | 'ALL';
89
97
  /**
90
98
  * Permission definition for a database table.
91
99
  * Defines the permissions for a database table.
@@ -6,7 +6,9 @@ export class AccomplishmentController {
6
6
  }
7
7
  emitAccomplishment(payload) {
8
8
  const accomplishmentPayload = Object.assign(Object.assign({}, payload), { type: 'durationMinutes' in payload ? 'macro' : 'micro' });
9
- this.validateAccomplishment(accomplishmentPayload);
9
+ if (!this.validateAccomplishment(accomplishmentPayload)) {
10
+ return;
11
+ }
10
12
  const sanitizedPayload = this.sanitizeAccomplishment(accomplishmentPayload);
11
13
  const topic = 'global.accomplishment.trigger' + (accomplishmentPayload.type === 'macro' ? 'Macro' : 'Micro');
12
14
  EventBus.emit(this.pluginId, topic, sanitizedPayload);
@@ -29,7 +31,8 @@ export class AccomplishmentController {
29
31
  }
30
32
  //durationMinutes is required
31
33
  if (payload.type === 'macro' && payload.durationMinutes < 4) {
32
- throw new Error('The duration must be at least 4 minutes');
34
+ console.warn('The duration must be at least 4 minutes');
35
+ return false;
33
36
  }
34
37
  //errorRatio is required
35
38
  if (payload.type === 'macro' && (payload.errorRatio < 0 || payload.errorRatio > 1)) {
@@ -43,6 +46,7 @@ export class AccomplishmentController {
43
46
  }
44
47
  });
45
48
  }
49
+ return true;
46
50
  }
47
51
  sanitizeAccomplishment(payload) {
48
52
  var _a;
@@ -28,31 +28,34 @@ export class SharedContentController {
28
28
  //this filter is there if the content should be filtered additionally by a column and value
29
29
  filter, options) {
30
30
  return __awaiter(this, void 0, void 0, function* () {
31
- let query = this.supabase
32
- .from('shared_content')
33
- .select('*, scc:shared_content_completed(id, state)')
34
- .eq('content_type', contentType)
35
- .not('scc.state', 'in', '("completed","ongoing","hidden")')
36
- .is('deleted_at', null);
37
- if ((options === null || options === void 0 ? void 0 : options.excludeIds) && options.excludeIds.length > 0) {
38
- const excludeIds = options.excludeIds.filter((id) => !id.startsWith('internal-temp-id-'));
39
- // Supabase expects raw PostgREST syntax like '("id1","id2")'.
40
- const excludeList = `(${excludeIds.map((id) => `"${id}"`).join(',')})`;
41
- query = query.not('id', 'in', excludeList);
42
- }
43
- if (filter) {
44
- query.contains('data', filter);
45
- }
46
- const { data: newAssignments, error } = yield query.limit(30);
47
- if (error) {
48
- console.error('error fetching new assignments:', error);
49
- throw new Error('error fetching new assignments');
50
- }
51
- // console.log('newAssignments:', newAssignments);
52
- if (!(options === null || options === void 0 ? void 0 : options.alwaysGenerateNew) && newAssignments.length > 0) {
53
- const index = Math.floor(Math.random() * newAssignments.length);
54
- return newAssignments[index];
55
- }
31
+ // The db cache of the shared content is temporary disabled until the new shared content implementation is completed
32
+ // if (false) {
33
+ // let query = this.supabase
34
+ // .from('shared_content')
35
+ // .select('*, scc:shared_content_completed(id, state)')
36
+ // .eq('content_type', contentType)
37
+ // .not('scc.state', 'in', '("completed","ongoing","hidden")')
38
+ // .is('deleted_at', null);
39
+ // if (options?.excludeIds?.length ?? 0 > 0) {
40
+ // const excludeIds = options.excludeIds.filter((id) => !id.startsWith('internal-temp-id-'));
41
+ // // Supabase expects raw PostgREST syntax like '("id1","id2")'.
42
+ // const excludeList = `(${excludeIds.map((id) => `"${id}"`).join(',')})`;
43
+ // query = query.not('id', 'in', excludeList);
44
+ // }
45
+ // if (filter) {
46
+ // query.contains('data', filter);
47
+ // }
48
+ // const { data: newAssignments, error } = await query.limit(30);
49
+ // if (error) {
50
+ // console.error('error fetching new assignments:', error);
51
+ // throw new Error('error fetching new assignments');
52
+ // }
53
+ // // console.log('newAssignments:', newAssignments);
54
+ // if (!options?.alwaysGenerateNew && newAssignments.length > 0) {
55
+ // const index = Math.floor(Math.random() * newAssignments.length);
56
+ // return newAssignments[index];
57
+ // }
58
+ // }
56
59
  const instructions = yield this.generateNewAssignment(contentType, generatorInstructions, filter);
57
60
  console.log('instructions:', instructions);
58
61
  //create the shared content object
@@ -31,7 +31,7 @@ export interface MenuEntry {
31
31
  plugin_id: string;
32
32
  action_key: string;
33
33
  text: string;
34
- icon?: React.ReactNode;
34
+ iconUrl?: string;
35
35
  }
36
36
  export type MainPanelAction = {
37
37
  plugin_id: string;
@@ -2,9 +2,16 @@ import { SupabaseClient } from '@supabase/supabase-js';
2
2
  import { UserInfo } from '../controller/SettingsController';
3
3
  import { ActivePlugin, Plugin } from '../fromRimori/PluginTypes';
4
4
  export interface Guild {
5
- id: string;
6
- longTermGoalOverride: string;
7
5
  allowUserPluginSettings: boolean;
6
+ city: string | null;
7
+ country: string | null;
8
+ description: string | null;
9
+ id: string;
10
+ isPublic: boolean;
11
+ name: string;
12
+ ownerId: string;
13
+ primaryLanguage: string;
14
+ scope: string;
8
15
  }
9
16
  export interface RimoriInfo {
10
17
  url: string;
@@ -19,6 +26,7 @@ export interface RimoriInfo {
19
26
  profile: UserInfo;
20
27
  mainPanelPlugin?: ActivePlugin;
21
28
  sidePanelPlugin?: ActivePlugin;
29
+ interfaceLanguage: string;
22
30
  }
23
31
  export declare class RimoriCommunicationHandler {
24
32
  private port;
@@ -131,7 +131,8 @@ export declare class RimoriClient {
131
131
  * @param text Optional text to be used for the action like for example text that the translator would look up.
132
132
  */
133
133
  emitSidebarAction: (pluginId: string, actionKey: string, text?: string) => void;
134
- onMainPanelAction: (callback: (data: MainPanelAction) => void, actionsToListen?: string[]) => void;
134
+ onMainPanelAction: (callback: (data: MainPanelAction) => void, actionsToListen?: string | string[]) => void;
135
+ onSidePanelAction: (callback: (data: MainPanelAction) => void, actionsToListen?: string | string[]) => void;
135
136
  };
136
137
  navigation: {
137
138
  toDashboard: () => void;
@@ -97,10 +97,25 @@ export class RimoriClient {
97
97
  this.event.emit('global.sidebar.triggerAction', { plugin_id: pluginId, action_key: actionKey, text });
98
98
  },
99
99
  onMainPanelAction: (callback, actionsToListen = []) => {
100
+ const listeningActions = Array.isArray(actionsToListen) ? actionsToListen : [actionsToListen];
100
101
  // this needs to be a emit and on because the main panel action is triggered by the user and not by the plugin
101
102
  this.event.emit('action.requestMain');
102
103
  this.event.on('action.requestMain', ({ data }) => {
103
- if (actionsToListen.includes(data.action)) {
104
+ console.log('Received action ' + data.action);
105
+ console.log('Listening to actions', listeningActions);
106
+ if (actionsToListen.length === 0 || actionsToListen.includes(data.action)) {
107
+ callback(data);
108
+ }
109
+ });
110
+ },
111
+ onSidePanelAction: (callback, actionsToListen = []) => {
112
+ const listeningActions = Array.isArray(actionsToListen) ? actionsToListen : [actionsToListen];
113
+ // this needs to be a emit and on because the main panel action is triggered by the user and not by the plugin
114
+ this.event.emit('action.requestSidebar');
115
+ this.event.on('action.requestSidebar', ({ data }) => {
116
+ console.log('Received action ' + data.action);
117
+ console.log('Listening to actions', listeningActions);
118
+ if (actionsToListen.length === 0 || actionsToListen.includes(data.action)) {
104
119
  callback(data);
105
120
  }
106
121
  });
@@ -261,7 +276,7 @@ export class RimoriClient {
261
276
  this.accomplishmentHandler = new AccomplishmentController(info.pluginId);
262
277
  this.settingsController = new SettingsController(supabase, info.pluginId, info.guild);
263
278
  this.sharedContentController = new SharedContentController(supabase, this);
264
- this.translator = new Translator(info.profile.mother_tongue.code);
279
+ this.translator = new Translator(info.interfaceLanguage);
265
280
  //only init logger in workers and on main plugin pages
266
281
  if (this.getQueryParam('applicationMode') !== 'sidebar') {
267
282
  Logger.getInstance(this);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimori/client",
3
- "version": "2.1.7",
3
+ "version": "2.2.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "bin": {
@@ -3,14 +3,7 @@
3
3
  /**
4
4
  * Supported database column data types for table schema definitions.
5
5
  */
6
- type DbColumnType =
7
- | 'decimal'
8
- | 'integer'
9
- | 'text'
10
- | 'boolean'
11
- | 'json'
12
- | 'timestamp'
13
- | 'uuid';
6
+ type DbColumnType = 'decimal' | 'integer' | 'text' | 'boolean' | 'json' | 'timestamp' | 'uuid';
14
7
 
15
8
  /**
16
9
  * Foreign key relationship configuration with cascade delete support.
@@ -55,10 +48,12 @@ export interface DbColumnDefinition {
55
48
  restrict?: {
56
49
  /** Restrictions for the user */
57
50
  user: Partial<Omit<DbPermissionDefinition, 'delete'>>;
58
- /** Restrictions for the moderator */
59
- moderator?: Partial<Omit<DbPermissionDefinition, 'delete'>>;
51
+ /** Restrictions for the guild moderator */
52
+ guild_moderator?: Partial<Omit<DbPermissionDefinition, 'delete'>>;
53
+ /** Restrictions for the language moderator */
54
+ lang_moderator?: Partial<Omit<DbPermissionDefinition, 'delete'>>;
60
55
  /** Restrictions for the maintainer */
61
- // maintainer?: Partial<DbPermissionDefinition>,
56
+ // maintainer?: Partial<Omit<DbPermissionDefinition, 'delete'>>;
62
57
  };
63
58
  }
64
59
 
@@ -86,9 +81,14 @@ export interface DbTableDefinition {
86
81
  description: string;
87
82
  /** Permissions for the table */
88
83
  permissions: {
84
+ /** Permissions for the user */
89
85
  user: DbPermissionDefinition;
90
- moderator?: DbPermissionDefinition;
91
- // maintainer?: DbPermissionDefinition,
86
+ /** Permissions for the guild moderator */
87
+ guild_moderator?: DbPermissionDefinition;
88
+ /** Permissions for the language moderator */
89
+ lang_moderator?: DbPermissionDefinition;
90
+ /** Permissions for the maintainer */
91
+ // maintainer?: DbPermissionDefinition;
92
92
  };
93
93
  /** Column definitions for the table */
94
94
  columns: {
@@ -100,11 +100,13 @@ export interface DbTableDefinition {
100
100
  * Permission definition for a database table.
101
101
  * NONE means the action is not allowed.
102
102
  * OWN means only do the action on your own records.
103
+ * GUILD means do the action on all records in the guild.
104
+ * LANG means do the action on all records in the language.
103
105
  * ALL means do the action on all records.
104
106
  *
105
107
  * Defines the permissions for a database table.
106
108
  */
107
- export type DbPermission = 'NONE' | 'OWN' | 'ALL';
109
+ export type DbPermission = 'NONE' | 'OWN' | 'GUILD' | 'LANG' | 'ALL';
108
110
 
109
111
  /**
110
112
  * Permission definition for a database table.
@@ -120,5 +122,4 @@ export interface DbPermissionDefinition {
120
122
  /**
121
123
  * Full table definition that includes automatically generated fields.
122
124
  */
123
- export type FullTable<T extends Record<string, DbColumnDefinition>> = T &
124
- BaseTableStructure;
125
+ export type FullTable<T extends Record<string, DbColumnDefinition>> = T & BaseTableStructure;
@@ -49,7 +49,9 @@ export class AccomplishmentController {
49
49
  type: 'durationMinutes' in payload ? 'macro' : 'micro',
50
50
  } as AccomplishmentPayload;
51
51
 
52
- this.validateAccomplishment(accomplishmentPayload);
52
+ if (!this.validateAccomplishment(accomplishmentPayload)) {
53
+ return;
54
+ }
53
55
 
54
56
  const sanitizedPayload = this.sanitizeAccomplishment(accomplishmentPayload);
55
57
 
@@ -58,7 +60,7 @@ export class AccomplishmentController {
58
60
  EventBus.emit(this.pluginId, topic, sanitizedPayload);
59
61
  }
60
62
 
61
- private validateAccomplishment(payload: AccomplishmentPayload) {
63
+ private validateAccomplishment(payload: AccomplishmentPayload): boolean {
62
64
  if (!skillCategories.includes(payload.skillCategory)) {
63
65
  throw new Error(`Invalid skill category: ${payload.skillCategory}`);
64
66
  }
@@ -82,7 +84,8 @@ export class AccomplishmentController {
82
84
 
83
85
  //durationMinutes is required
84
86
  if (payload.type === 'macro' && payload.durationMinutes < 4) {
85
- throw new Error('The duration must be at least 4 minutes');
87
+ console.warn('The duration must be at least 4 minutes');
88
+ return false;
86
89
  }
87
90
 
88
91
  //errorRatio is required
@@ -98,6 +101,7 @@ export class AccomplishmentController {
98
101
  }
99
102
  });
100
103
  }
104
+ return true;
101
105
  }
102
106
 
103
107
  private sanitizeAccomplishment(payload: AccomplishmentPayload) {
@@ -36,38 +36,40 @@ export class SharedContentController {
36
36
  filter?: SharedContentFilter,
37
37
  options?: { privateTopic?: boolean; skipDbSave?: boolean; alwaysGenerateNew?: boolean; excludeIds?: string[] },
38
38
  ): Promise<SharedContent<T>> {
39
- let query = this.supabase
40
- .from('shared_content')
41
- .select('*, scc:shared_content_completed(id, state)')
42
- .eq('content_type', contentType)
43
- .not('scc.state', 'in', '("completed","ongoing","hidden")')
44
- .is('deleted_at', null);
45
-
46
- if (options?.excludeIds && options.excludeIds.length > 0) {
47
- const excludeIds = options.excludeIds.filter((id) => !id.startsWith('internal-temp-id-'));
48
- // Supabase expects raw PostgREST syntax like '("id1","id2")'.
49
- const excludeList = `(${excludeIds.map((id) => `"${id}"`).join(',')})`;
50
- query = query.not('id', 'in', excludeList);
51
- }
52
-
53
- if (filter) {
54
- query.contains('data', filter);
55
- }
56
-
57
- const { data: newAssignments, error } = await query.limit(30);
58
-
59
- if (error) {
60
- console.error('error fetching new assignments:', error);
61
- throw new Error('error fetching new assignments');
62
- }
63
-
64
- // console.log('newAssignments:', newAssignments);
65
-
66
- if (!options?.alwaysGenerateNew && newAssignments.length > 0) {
67
- const index = Math.floor(Math.random() * newAssignments.length);
68
- return newAssignments[index];
69
- }
70
-
39
+ // The db cache of the shared content is temporary disabled until the new shared content implementation is completed
40
+ // if (false) {
41
+ // let query = this.supabase
42
+ // .from('shared_content')
43
+ // .select('*, scc:shared_content_completed(id, state)')
44
+ // .eq('content_type', contentType)
45
+ // .not('scc.state', 'in', '("completed","ongoing","hidden")')
46
+ // .is('deleted_at', null);
47
+
48
+ // if (options?.excludeIds?.length ?? 0 > 0) {
49
+ // const excludeIds = options.excludeIds.filter((id) => !id.startsWith('internal-temp-id-'));
50
+ // // Supabase expects raw PostgREST syntax like '("id1","id2")'.
51
+ // const excludeList = `(${excludeIds.map((id) => `"${id}"`).join(',')})`;
52
+ // query = query.not('id', 'in', excludeList);
53
+ // }
54
+
55
+ // if (filter) {
56
+ // query.contains('data', filter);
57
+ // }
58
+
59
+ // const { data: newAssignments, error } = await query.limit(30);
60
+
61
+ // if (error) {
62
+ // console.error('error fetching new assignments:', error);
63
+ // throw new Error('error fetching new assignments');
64
+ // }
65
+
66
+ // // console.log('newAssignments:', newAssignments);
67
+
68
+ // if (!options?.alwaysGenerateNew && newAssignments.length > 0) {
69
+ // const index = Math.floor(Math.random() * newAssignments.length);
70
+ // return newAssignments[index];
71
+ // }
72
+ // }
71
73
  const instructions = await this.generateNewAssignment(contentType, generatorInstructions, filter);
72
74
 
73
75
  console.log('instructions:', instructions);
@@ -49,7 +49,7 @@ export interface MenuEntry {
49
49
  // text of the menu entry. Shown in the context menu
50
50
  text: string;
51
51
  // icon of the menu entry. Shown in the context menu
52
- icon?: React.ReactNode;
52
+ iconUrl?: string;
53
53
  }
54
54
 
55
55
  // an action from the main panel that can be triggered and performs an action in the main panel
@@ -7,9 +7,16 @@ import { ActivePlugin, Plugin } from '../fromRimori/PluginTypes';
7
7
  declare const WorkerGlobalScope: any;
8
8
 
9
9
  export interface Guild {
10
- id: string;
11
- longTermGoalOverride: string;
12
10
  allowUserPluginSettings: boolean;
11
+ city: string | null;
12
+ country: string | null;
13
+ description: string | null;
14
+ id: string;
15
+ isPublic: boolean;
16
+ name: string;
17
+ ownerId: string;
18
+ primaryLanguage: string;
19
+ scope: string;
13
20
  }
14
21
 
15
22
  export interface RimoriInfo {
@@ -25,6 +32,7 @@ export interface RimoriInfo {
25
32
  profile: UserInfo;
26
33
  mainPanelPlugin?: ActivePlugin;
27
34
  sidePanelPlugin?: ActivePlugin;
35
+ interfaceLanguage: string;
28
36
  }
29
37
 
30
38
  export class RimoriCommunicationHandler {
@@ -43,7 +43,7 @@ export class RimoriClient {
43
43
  this.accomplishmentHandler = new AccomplishmentController(info.pluginId);
44
44
  this.settingsController = new SettingsController(supabase, info.pluginId, info.guild);
45
45
  this.sharedContentController = new SharedContentController(supabase, this);
46
- this.translator = new Translator(info.profile.mother_tongue.code);
46
+ this.translator = new Translator(info.interfaceLanguage);
47
47
 
48
48
  //only init logger in workers and on main plugin pages
49
49
  if (this.getQueryParam('applicationMode') !== 'sidebar') {
@@ -238,11 +238,27 @@ export class RimoriClient {
238
238
  this.event.emit('global.sidebar.triggerAction', { plugin_id: pluginId, action_key: actionKey, text });
239
239
  },
240
240
 
241
- onMainPanelAction: (callback: (data: MainPanelAction) => void, actionsToListen: string[] = []) => {
241
+ onMainPanelAction: (callback: (data: MainPanelAction) => void, actionsToListen: string | string[] = []) => {
242
+ const listeningActions = Array.isArray(actionsToListen) ? actionsToListen : [actionsToListen];
242
243
  // this needs to be a emit and on because the main panel action is triggered by the user and not by the plugin
243
244
  this.event.emit('action.requestMain');
244
245
  this.event.on<MainPanelAction>('action.requestMain', ({ data }) => {
245
- if (actionsToListen.includes(data.action)) {
246
+ console.log('Received action ' + data.action);
247
+ console.log('Listening to actions', listeningActions);
248
+ if (actionsToListen.length === 0 || actionsToListen.includes(data.action)) {
249
+ callback(data);
250
+ }
251
+ });
252
+ },
253
+
254
+ onSidePanelAction: (callback: (data: MainPanelAction) => void, actionsToListen: string | string[] = []) => {
255
+ const listeningActions = Array.isArray(actionsToListen) ? actionsToListen : [actionsToListen];
256
+ // this needs to be a emit and on because the main panel action is triggered by the user and not by the plugin
257
+ this.event.emit('action.requestSidebar');
258
+ this.event.on<MainPanelAction>('action.requestSidebar', ({ data }) => {
259
+ console.log('Received action ' + data.action);
260
+ console.log('Listening to actions', listeningActions);
261
+ if (actionsToListen.length === 0 || actionsToListen.includes(data.action)) {
246
262
  callback(data);
247
263
  }
248
264
  });