@rimori/client 2.5.33 → 2.5.34

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.
@@ -74,13 +74,8 @@ export class Translator {
74
74
  return this.initializationPromise;
75
75
  }
76
76
  getTranslationUrl(language) {
77
- const baseUrl = this.translationUrl || window.location.origin;
78
- // For localhost development, use local- prefix for non-English languages
79
- if (window.location.hostname === 'localhost' || new URL(baseUrl).hostname === 'localhost') {
80
- const filename = language !== 'en' ? `local-${language}` : language;
81
- return `${baseUrl}/locales/${filename}.json`;
82
- }
83
- return `${baseUrl}/locales/${language}.json`;
77
+ const baseUrl = (this.translationUrl || window.location.origin).replace(/\/+$/, '');
78
+ return `${baseUrl}locales/${language}.json`;
84
79
  }
85
80
  usePlugin(plugin) {
86
81
  if (!this.i18n) {
@@ -99,21 +94,32 @@ export class Translator {
99
94
  * @param language - Language code to fetch
100
95
  * @returns Promise with translation data
101
96
  */
102
- async fetchTranslations(language) {
97
+ async fetchTranslations(language, attempt = 0) {
103
98
  try {
104
99
  const response = await fetch(this.getTranslationUrl(language));
105
100
  if (!response.ok) {
106
- throw new Error(`Failed to fetch translations for ${language}`);
101
+ throw new Error(`Failed to fetch translations for ${language}: ${response.status}`);
102
+ }
103
+ const data = (await response.json());
104
+ // If the result is empty, treat it as a failure and retry once to handle transient errors
105
+ if (Object.keys(data).length === 0 && attempt === 0) {
106
+ await new Promise((resolve) => setTimeout(resolve, 300));
107
+ return this.fetchTranslations(language, 1);
107
108
  }
108
- return (await response.json());
109
+ return data;
109
110
  }
110
111
  catch (error) {
112
+ if (attempt === 0) {
113
+ // Retry once after a short delay to handle transient network/CDN errors
114
+ await new Promise((resolve) => setTimeout(resolve, 300));
115
+ return this.fetchTranslations(language, 1);
116
+ }
111
117
  console.warn(`Failed to fetch translations for ${language}:`, error);
112
118
  if (language === 'en')
113
119
  return {};
114
120
  // Fallback to English
115
- return this.fetchTranslations('en').catch((error) => {
116
- console.error('Failed to fetch fallback translations:', error);
121
+ return this.fetchTranslations('en').catch((fallbackError) => {
122
+ console.error('Failed to fetch fallback translations:', fallbackError);
117
123
  return {};
118
124
  });
119
125
  }
@@ -207,18 +207,11 @@ export class EventModule {
207
207
  const listeningActions = Array.isArray(actionsToListen) ? actionsToListen : [actionsToListen];
208
208
  // Register the listener BEFORE emitting the request, so the synchronous response
209
209
  // from the bridge/responder is captured (emit → bridge outbound → host respond → bridge inbound is synchronous).
210
- console.log('[EventModule] onSidePanelAction: setting up listener for', this.pluginId, 'listening to:', listeningActions);
211
210
  const listener = this.on('action.requestSidebar', ({ data }) => {
212
- console.log('[EventModule] onSidePanelAction: received event', { data, listeningActions });
213
211
  if (listeningActions.length === 0 || listeningActions.includes(data.action)) {
214
- console.log('[EventModule] onSidePanelAction: action matched, calling callback');
215
212
  callback(data);
216
213
  }
217
- else {
218
- console.log('[EventModule] onSidePanelAction: action NOT matched. Got:', data.action, 'expected:', listeningActions);
219
- }
220
214
  });
221
- console.log('[EventModule] onSidePanelAction: emitting action.requestSidebar for', this.pluginId);
222
215
  this.emit('action.requestSidebar');
223
216
  // Bridge is connected at this point — request current session token in case
224
217
  // an exercise was already active before this sidebar plugin mounted.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimori/client",
3
- "version": "2.5.33",
3
+ "version": "2.5.34",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {