@rimori/client 2.4.0 → 2.5.0-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.
- package/dist/cli/scripts/init/dev-registration.js +4 -2
- package/dist/cli/scripts/init/main.js +1 -0
- package/dist/cli/scripts/release/release.js +0 -0
- package/dist/controller/SettingsController.d.ts +1 -1
- package/dist/controller/SharedContentController.d.ts +1 -1
- package/dist/fromRimori/EventBus.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/plugin/CommunicationHandler.d.ts +13 -8
- package/dist/plugin/CommunicationHandler.js +44 -59
- package/dist/plugin/RimoriClient.d.ts +11 -195
- package/dist/plugin/RimoriClient.js +17 -298
- package/dist/plugin/StandaloneClient.d.ts +1 -1
- package/dist/plugin/StandaloneClient.js +3 -2
- package/dist/plugin/module/AIModule.d.ts +49 -0
- package/dist/plugin/module/AIModule.js +81 -0
- package/dist/plugin/module/DbModule.d.ts +30 -0
- package/dist/plugin/module/DbModule.js +51 -0
- package/dist/plugin/module/EventModule.d.ts +99 -0
- package/dist/plugin/module/EventModule.js +162 -0
- package/dist/{controller/ExerciseController.d.ts → plugin/module/ExerciseModule.d.ts} +20 -16
- package/dist/{controller/ExerciseController.js → plugin/module/ExerciseModule.js} +27 -20
- package/dist/plugin/module/PluginModule.d.ts +76 -0
- package/dist/plugin/module/PluginModule.js +88 -0
- package/package.json +8 -3
- package/.github/workflows/pre-release.yml +0 -126
- package/.prettierignore +0 -35
- package/eslint.config.js +0 -53
- package/example/docs/devdocs.md +0 -241
- package/example/docs/overview.md +0 -29
- package/example/docs/userdocs.md +0 -126
- package/example/rimori.config.ts +0 -91
- package/example/worker/vite.config.ts +0 -26
- package/example/worker/worker.ts +0 -11
- package/prettier.config.js +0 -8
- package/src/cli/scripts/init/dev-registration.ts +0 -189
- package/src/cli/scripts/init/env-setup.ts +0 -44
- package/src/cli/scripts/init/file-operations.ts +0 -58
- package/src/cli/scripts/init/html-cleaner.ts +0 -45
- package/src/cli/scripts/init/main.ts +0 -175
- package/src/cli/scripts/init/package-setup.ts +0 -113
- package/src/cli/scripts/init/router-transformer.ts +0 -332
- package/src/cli/scripts/init/tailwind-config.ts +0 -66
- package/src/cli/scripts/init/vite-config.ts +0 -73
- package/src/cli/scripts/release/detect-translation-languages.ts +0 -37
- package/src/cli/scripts/release/release-config-upload.ts +0 -119
- package/src/cli/scripts/release/release-db-update.ts +0 -97
- package/src/cli/scripts/release/release-file-upload.ts +0 -138
- package/src/cli/scripts/release/release.ts +0 -85
- package/src/cli/types/DatabaseTypes.ts +0 -125
- package/src/controller/AIController.ts +0 -295
- package/src/controller/AccomplishmentController.ts +0 -188
- package/src/controller/AudioController.ts +0 -64
- package/src/controller/ExerciseController.ts +0 -117
- package/src/controller/ObjectController.ts +0 -120
- package/src/controller/SettingsController.ts +0 -186
- package/src/controller/SharedContentController.ts +0 -365
- package/src/controller/TranslationController.ts +0 -136
- package/src/controller/VoiceController.ts +0 -33
- package/src/fromRimori/EventBus.ts +0 -382
- package/src/fromRimori/PluginTypes.ts +0 -214
- package/src/fromRimori/readme.md +0 -2
- package/src/index.ts +0 -19
- package/src/plugin/CommunicationHandler.ts +0 -310
- package/src/plugin/Logger.ts +0 -394
- package/src/plugin/RimoriClient.ts +0 -530
- package/src/plugin/StandaloneClient.ts +0 -125
- package/src/utils/difficultyConverter.ts +0 -15
- package/src/utils/endpoint.ts +0 -3
- package/src/worker/WorkerSetup.ts +0 -35
- package/tsconfig.json +0 -17
package/src/plugin/Logger.ts
DELETED
|
@@ -1,394 +0,0 @@
|
|
|
1
|
-
import { RimoriClient } from './RimoriClient';
|
|
2
|
-
|
|
3
|
-
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
4
|
-
|
|
5
|
-
interface LogEntry {
|
|
6
|
-
id: string;
|
|
7
|
-
timestamp: string;
|
|
8
|
-
level: LogLevel;
|
|
9
|
-
message: string;
|
|
10
|
-
data?: any;
|
|
11
|
-
context?: {
|
|
12
|
-
url: string;
|
|
13
|
-
userAgent: string;
|
|
14
|
-
browserInfo: BrowserInfo;
|
|
15
|
-
screenshot?: string;
|
|
16
|
-
mousePosition?: MousePosition;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface BrowserInfo {
|
|
21
|
-
userAgent: string;
|
|
22
|
-
language: string;
|
|
23
|
-
cookieEnabled: boolean;
|
|
24
|
-
onLine: boolean;
|
|
25
|
-
screenResolution: string;
|
|
26
|
-
windowSize: string;
|
|
27
|
-
timestamp: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface MousePosition {
|
|
31
|
-
x: number;
|
|
32
|
-
y: number;
|
|
33
|
-
timestamp: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Singleton Logger class for Rimori client plugins.
|
|
38
|
-
* Handles all logging levels, production filtering, and log transmission to Rimori.
|
|
39
|
-
* Overrides console methods globally for seamless integration.
|
|
40
|
-
*/
|
|
41
|
-
export class Logger {
|
|
42
|
-
private static instance: Logger;
|
|
43
|
-
private isProduction: boolean;
|
|
44
|
-
private logs: LogEntry[] = [];
|
|
45
|
-
private logIdCounter = 0;
|
|
46
|
-
private originalConsole: {
|
|
47
|
-
log: typeof console.log;
|
|
48
|
-
info: typeof console.info;
|
|
49
|
-
warn: typeof console.warn;
|
|
50
|
-
error: typeof console.error;
|
|
51
|
-
debug: typeof console.debug;
|
|
52
|
-
};
|
|
53
|
-
private mousePosition: MousePosition | null = null;
|
|
54
|
-
|
|
55
|
-
private constructor(rimori: RimoriClient, isProduction?: boolean) {
|
|
56
|
-
this.isProduction = this.validateIsProduction(isProduction);
|
|
57
|
-
|
|
58
|
-
// Store original console methods
|
|
59
|
-
this.originalConsole = {
|
|
60
|
-
log: console.log,
|
|
61
|
-
info: console.info,
|
|
62
|
-
warn: console.warn,
|
|
63
|
-
error: console.error,
|
|
64
|
-
debug: console.debug,
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// Override console methods globally
|
|
68
|
-
this.overrideConsoleMethods();
|
|
69
|
-
|
|
70
|
-
// Track mouse position
|
|
71
|
-
this.trackMousePosition();
|
|
72
|
-
|
|
73
|
-
// Expose logs to global scope for DevTools access
|
|
74
|
-
this.exposeToDevTools();
|
|
75
|
-
|
|
76
|
-
// Set up navigation clearing
|
|
77
|
-
this.setupNavigationClearing();
|
|
78
|
-
|
|
79
|
-
rimori.event.respond('logging.requestPluginLogs', async () => {
|
|
80
|
-
this.addLogEntry(await this.createLogEntry('info', 'Screenshot capture', undefined, true));
|
|
81
|
-
const logs = {
|
|
82
|
-
logs: this.logs,
|
|
83
|
-
pluginId: rimori.plugin.pluginId,
|
|
84
|
-
timestamp: new Date().toISOString(),
|
|
85
|
-
};
|
|
86
|
-
this.logs = [];
|
|
87
|
-
this.logIdCounter = 0;
|
|
88
|
-
return logs;
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Initialize the Logger singleton and override console methods globally.
|
|
94
|
-
* @param rimori - Rimori client instance
|
|
95
|
-
* @param isProduction - Whether the environment is production
|
|
96
|
-
* @returns Logger instance
|
|
97
|
-
*/
|
|
98
|
-
public static getInstance(rimori: RimoriClient, isProduction?: boolean): Logger {
|
|
99
|
-
if (!Logger.instance) {
|
|
100
|
-
Logger.instance = new Logger(rimori, isProduction);
|
|
101
|
-
}
|
|
102
|
-
return Logger.instance;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private validateIsProduction(isProduction?: boolean): boolean {
|
|
106
|
-
if (isProduction !== undefined) {
|
|
107
|
-
return isProduction;
|
|
108
|
-
}
|
|
109
|
-
if (typeof window !== 'undefined' && window.location.href) {
|
|
110
|
-
return !window.location.href.includes('localhost');
|
|
111
|
-
}
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Expose log access to global scope for DevTools console access.
|
|
116
|
-
*/
|
|
117
|
-
private exposeToDevTools(): void {
|
|
118
|
-
if (typeof window !== 'undefined') {
|
|
119
|
-
// Expose a global function to access logs from DevTools console
|
|
120
|
-
(window as any).getRimoriLogs = () => this.logs;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Set up navigation event listeners to clear logs on page changes.
|
|
126
|
-
*/
|
|
127
|
-
private setupNavigationClearing(): void {
|
|
128
|
-
if (typeof window === 'undefined' || typeof history === 'undefined') return;
|
|
129
|
-
|
|
130
|
-
// Clear logs on browser back/forward
|
|
131
|
-
window.addEventListener('popstate', () => (this.logs = []));
|
|
132
|
-
|
|
133
|
-
// Override history methods to clear logs on programmatic navigation
|
|
134
|
-
const originalPushState = history.pushState;
|
|
135
|
-
const originalReplaceState = history.replaceState;
|
|
136
|
-
|
|
137
|
-
history.pushState = (...args) => {
|
|
138
|
-
originalPushState.apply(history, args);
|
|
139
|
-
this.logs = [];
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
history.replaceState = (...args) => {
|
|
143
|
-
originalReplaceState.apply(history, args);
|
|
144
|
-
this.logs = [];
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
// Listen for URL changes (works with React Router and other SPAs)
|
|
148
|
-
let currentUrl = window.location.href;
|
|
149
|
-
const checkUrlChange = () => {
|
|
150
|
-
if (window.location.href !== currentUrl) {
|
|
151
|
-
currentUrl = window.location.href;
|
|
152
|
-
this.logs = [];
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
// Check for URL changes periodically
|
|
157
|
-
setInterval(checkUrlChange, 100);
|
|
158
|
-
|
|
159
|
-
// Also listen for hash changes (for hash-based routing)
|
|
160
|
-
window.addEventListener('hashchange', () => (this.logs = []));
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Override console methods globally to capture all console calls.
|
|
165
|
-
*/
|
|
166
|
-
private overrideConsoleMethods(): void {
|
|
167
|
-
// Override console.log
|
|
168
|
-
console.log = (...args: any[]) => {
|
|
169
|
-
const { location, style } = this.getCallerLocation();
|
|
170
|
-
this.originalConsole.log(location, style, ...args);
|
|
171
|
-
this.handleConsoleCall('info', args);
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
// Override console.info
|
|
175
|
-
console.info = (...args: any[]) => {
|
|
176
|
-
const { location, style } = this.getCallerLocation();
|
|
177
|
-
this.originalConsole.info(location, style, ...args);
|
|
178
|
-
this.handleConsoleCall('info', args);
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
// Override console.warn
|
|
182
|
-
console.warn = (...args: any[]) => {
|
|
183
|
-
const { location, style } = this.getCallerLocation();
|
|
184
|
-
this.originalConsole.warn(location, style, ...args);
|
|
185
|
-
this.handleConsoleCall('warn', args);
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
// Override console.error
|
|
189
|
-
console.error = (...args: any[]) => {
|
|
190
|
-
const { location, style } = this.getCallerLocation();
|
|
191
|
-
this.originalConsole.error(location, style, ...args);
|
|
192
|
-
this.handleConsoleCall('error', args);
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
// Override console.debug
|
|
196
|
-
console.debug = (...args: any[]) => {
|
|
197
|
-
const { location, style } = this.getCallerLocation();
|
|
198
|
-
this.originalConsole.debug(location, style, ...args);
|
|
199
|
-
this.handleConsoleCall('debug', args);
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Get caller information from stack trace.
|
|
205
|
-
* @returns Object with location string and CSS style, or empty values for production
|
|
206
|
-
*/
|
|
207
|
-
private getCallerLocation(): { location: string; style: string } {
|
|
208
|
-
const emptyResult = { location: '', style: '' };
|
|
209
|
-
const style = 'color: #0063A2; font-weight: bold;';
|
|
210
|
-
|
|
211
|
-
if (this.isProduction) return emptyResult;
|
|
212
|
-
|
|
213
|
-
try {
|
|
214
|
-
const stack = new Error().stack;
|
|
215
|
-
if (!stack) return emptyResult;
|
|
216
|
-
|
|
217
|
-
const stackLines = stack.split('\n');
|
|
218
|
-
// Skip the first 3 lines: Error, getCallerLocation, overrideConsoleMethods wrapper
|
|
219
|
-
const callerLine = stackLines[3];
|
|
220
|
-
|
|
221
|
-
if (!callerLine) return emptyResult;
|
|
222
|
-
|
|
223
|
-
// Extract file name and line number from stack trace
|
|
224
|
-
// Format: "at functionName (file:line:column)" or "at file:line:column"
|
|
225
|
-
const match = callerLine.match(/(?:at\s+.*?\s+\()?([^/\\(]+\.(?:ts|tsx|js|jsx)):(\d+):(\d+)\)?/);
|
|
226
|
-
|
|
227
|
-
if (match) {
|
|
228
|
-
const [, fileName, lineNumber] = match;
|
|
229
|
-
return { style, location: `%c[${fileName}:${lineNumber}]` };
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Fallback: try to extract just the file name
|
|
233
|
-
const simpleMatch = callerLine.match(/([^/\\]+\.(?:ts|tsx|js|jsx))/);
|
|
234
|
-
if (simpleMatch) {
|
|
235
|
-
return { style, location: `%c[${simpleMatch[1]}]` };
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return emptyResult;
|
|
239
|
-
} catch (error) {
|
|
240
|
-
return emptyResult;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Track mouse position for screenshot context.
|
|
246
|
-
*/
|
|
247
|
-
private trackMousePosition(): void {
|
|
248
|
-
if (typeof window !== 'undefined') {
|
|
249
|
-
const updateMousePosition = (event: MouseEvent) => {
|
|
250
|
-
this.mousePosition = {
|
|
251
|
-
x: event.clientX,
|
|
252
|
-
y: event.clientY,
|
|
253
|
-
timestamp: new Date().toISOString(),
|
|
254
|
-
};
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
window.addEventListener('mousemove', updateMousePosition);
|
|
258
|
-
window.addEventListener('click', updateMousePosition);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Handle console method calls and create log entries.
|
|
264
|
-
* @param level - Log level
|
|
265
|
-
* @param args - Console arguments
|
|
266
|
-
*/
|
|
267
|
-
private async handleConsoleCall(level: LogLevel, args: any[]): Promise<void> {
|
|
268
|
-
// Skip if this is a production log that shouldn't be stored
|
|
269
|
-
if (this.isProduction && (level === 'debug' || level === 'info')) {
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// Convert console arguments to message and data
|
|
274
|
-
const message = args
|
|
275
|
-
.map((arg) => {
|
|
276
|
-
if (typeof arg !== 'object') return arg;
|
|
277
|
-
try {
|
|
278
|
-
return JSON.stringify(arg);
|
|
279
|
-
} catch (error: any) {
|
|
280
|
-
return 'Error adding object to log: ' + error.message + ' ' + String(arg);
|
|
281
|
-
}
|
|
282
|
-
})
|
|
283
|
-
.join(' ');
|
|
284
|
-
|
|
285
|
-
const data = args.length > 1 ? args.slice(1) : undefined;
|
|
286
|
-
|
|
287
|
-
const entry = await this.createLogEntry(level, message, data);
|
|
288
|
-
this.addLogEntry(entry);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Get browser and system information for debugging.
|
|
293
|
-
* @returns Object with browser and system information
|
|
294
|
-
*/
|
|
295
|
-
private getBrowserInfo(): BrowserInfo {
|
|
296
|
-
return {
|
|
297
|
-
userAgent: navigator.userAgent,
|
|
298
|
-
language: navigator.language,
|
|
299
|
-
cookieEnabled: navigator.cookieEnabled,
|
|
300
|
-
onLine: navigator.onLine,
|
|
301
|
-
screenResolution: `${screen.width}x${screen.height}`,
|
|
302
|
-
windowSize: `${window.innerWidth}x${window.innerHeight}`,
|
|
303
|
-
timestamp: new Date().toISOString(),
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Capture a screenshot of the current page.
|
|
309
|
-
* Dynamically imports html2canvas only in browser environments.
|
|
310
|
-
* @returns Promise resolving to base64 screenshot or null if failed
|
|
311
|
-
*/
|
|
312
|
-
private async captureScreenshot(): Promise<string | null> {
|
|
313
|
-
// Only attempt to capture screenshot in browser environments
|
|
314
|
-
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
315
|
-
return null;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
try {
|
|
319
|
-
// Dynamically import html2canvas only when window is available
|
|
320
|
-
// html2canvas is an optional peer dependency - provided by @rimori/react-client
|
|
321
|
-
// In worker builds, this import should be marked as external to prevent bundling
|
|
322
|
-
const html2canvas = (await import('html2canvas')).default;
|
|
323
|
-
const canvas = await html2canvas(document.body);
|
|
324
|
-
const screenshot = canvas.toDataURL('image/png');
|
|
325
|
-
// this.originalConsole.log("screenshot captured", screenshot)
|
|
326
|
-
return screenshot;
|
|
327
|
-
} catch (error) {
|
|
328
|
-
// html2canvas may not be available (e.g., in workers or when not installed)
|
|
329
|
-
// Silently fail to avoid breaking logging functionality
|
|
330
|
-
return null;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Create a log entry with context information.
|
|
336
|
-
* @param level - Log level
|
|
337
|
-
* @param message - Log message
|
|
338
|
-
* @param data - Additional data
|
|
339
|
-
* @returns Log entry
|
|
340
|
-
*/
|
|
341
|
-
private async createLogEntry(
|
|
342
|
-
level: LogLevel,
|
|
343
|
-
message: string,
|
|
344
|
-
data?: any,
|
|
345
|
-
forceScreenshot?: boolean,
|
|
346
|
-
): Promise<LogEntry> {
|
|
347
|
-
const context: Partial<LogEntry['context']> = {};
|
|
348
|
-
|
|
349
|
-
// Add URL if available
|
|
350
|
-
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
351
|
-
return {
|
|
352
|
-
id: `log_${++this.logIdCounter}_${Date.now()}`,
|
|
353
|
-
timestamp: new Date().toISOString(),
|
|
354
|
-
level,
|
|
355
|
-
message,
|
|
356
|
-
data,
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
context.url = window.location.href;
|
|
361
|
-
|
|
362
|
-
// Add browser info (this method now handles worker context internally)
|
|
363
|
-
context.browserInfo = this.getBrowserInfo();
|
|
364
|
-
context.userAgent = context.browserInfo.userAgent;
|
|
365
|
-
|
|
366
|
-
// Add screenshot and mouse position if level is error or warn
|
|
367
|
-
if (level === 'error' || level === 'warn' || forceScreenshot) {
|
|
368
|
-
context.screenshot = (await this.captureScreenshot()) || undefined;
|
|
369
|
-
context.mousePosition = this.mousePosition || undefined;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
return {
|
|
373
|
-
id: `log_${++this.logIdCounter}_${Date.now()}`,
|
|
374
|
-
timestamp: new Date().toISOString(),
|
|
375
|
-
level,
|
|
376
|
-
message,
|
|
377
|
-
data,
|
|
378
|
-
context: context as LogEntry['context'],
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Add a log entry to the internal log array.
|
|
384
|
-
* @param entry - Log entry to add
|
|
385
|
-
*/
|
|
386
|
-
private addLogEntry(entry: LogEntry): void {
|
|
387
|
-
this.logs.push(entry);
|
|
388
|
-
|
|
389
|
-
// Maintain log size limit (1000 entries)
|
|
390
|
-
if (this.logs.length > 1000) {
|
|
391
|
-
this.logs = this.logs.slice(-1000);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|