i18n-keyless-core 2.4.0 → 2.4.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "i18n-keyless-core",
3
3
  "private": false,
4
- "version": "2.4.0",
4
+ "version": "2.4.2",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
package/dist/service.d.ts CHANGED
@@ -46,11 +46,11 @@ export declare function getAllTranslationsFromLanguage(targetLanguage: Lang, sto
46
46
  *
47
47
  * It's called on lib initialization
48
48
  * and everytime the language is set
49
- * @param translationsUsage - The translations usage to send to the API
49
+ * @param translationsUsageByNamespace - Usage keyed by namespace (default under "default")
50
50
  * @param store - The translation store
51
51
  * @returns Promise resolving to the translation response or void if failed
52
52
  */
53
- export declare function sendTranslationsUsageToI18nKeyless(translationsUsage: TranslationsUsage, store: FetchTranslationParams): Promise<{
53
+ export declare function sendTranslationsUsageToI18nKeyless(translationsUsageByNamespace: Record<string, TranslationsUsage>, store: FetchTranslationParams): Promise<{
54
54
  ok: boolean;
55
55
  message: string;
56
56
  } | void>;
package/dist/service.js CHANGED
@@ -223,22 +223,27 @@ export async function getAllTranslationsFromLanguage(targetLanguage, store, name
223
223
  *
224
224
  * It's called on lib initialization
225
225
  * and everytime the language is set
226
- * @param translationsUsage - The translations usage to send to the API
226
+ * @param translationsUsageByNamespace - Usage keyed by namespace (default under "default")
227
227
  * @param store - The translation store
228
228
  * @returns Promise resolving to the translation response or void if failed
229
229
  */
230
- export async function sendTranslationsUsageToI18nKeyless(translationsUsage, store) {
230
+ export async function sendTranslationsUsageToI18nKeyless(translationsUsageByNamespace, store) {
231
231
  const config = store.config;
232
232
  if (!config.API_KEY) {
233
233
  console.error("i18n-keyless: No config found");
234
234
  return;
235
235
  }
236
- if (Object.keys(translationsUsage).length === 0) {
236
+ if (Object.keys(translationsUsageByNamespace).length === 0) {
237
237
  return;
238
238
  }
239
+ const requestBody = {
240
+ primaryLanguage: config.languages.primary,
241
+ translationsUsageByNamespace,
242
+ };
239
243
  try {
240
244
  const response = config.sendTranslationsUsage
241
- ? await config.sendTranslationsUsage(translationsUsage)
245
+ ? // custom handlers keep their flat signature: hand them the default-namespace bucket
246
+ await config.sendTranslationsUsage(translationsUsageByNamespace.default ?? {})
242
247
  : await api
243
248
  .postLastUsedTranslations(`${config.API_URL || "https://api.i18n-keyless.com"}/translate/last-used-translations`, {
244
249
  method: "POST",
@@ -247,10 +252,7 @@ export async function sendTranslationsUsageToI18nKeyless(translationsUsage, stor
247
252
  Authorization: `Bearer ${config.API_KEY}`,
248
253
  Version: packageJson.version,
249
254
  },
250
- body: JSON.stringify({
251
- primaryLanguage: config.languages.primary,
252
- translationsUsage,
253
- }),
255
+ body: JSON.stringify(requestBody),
254
256
  })
255
257
  .then((res) => res);
256
258
  if (response.message) {
package/dist/types.d.ts CHANGED
@@ -114,7 +114,15 @@ export interface I18nKeylessRequestBody {
114
114
  }
115
115
  export interface I18nKeylessTranslationsUsageRequestBody {
116
116
  primaryLanguage: LanguagesConfig["primary"];
117
- translationsUsage: TranslationsUsage;
117
+ /**
118
+ * Usage keyed by namespace: `{ "<namespace>": { "key__context": "YYYY-MM-DD" } }`. The
119
+ * default namespace is included under the key "default". The backend marks `last_used` on
120
+ * the exact `(key, context, namespace)` row.
121
+ *
122
+ * (Clients < 2.4.0 instead send a flat `translationsUsage` with no namespace; the backend
123
+ * treats that as the "default" namespace.) `unpersistedNamespace` namespaces are excluded.
124
+ */
125
+ translationsUsageByNamespace: Record<string, TranslationsUsage>;
118
126
  }
119
127
  export interface I18nKeylessResponse {
120
128
  ok: boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "i18n-keyless-core",
3
3
  "private": false,
4
- "version": "2.4.0",
4
+ "version": "2.4.2",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",