@proveanything/smartlinks 2.1.30 → 2.1.31
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/api/translations.d.ts +20 -0
- package/dist/api/translations.js +63 -0
- package/dist/docs/API_SUMMARY.md +13 -2
- package/dist/docs/translations.md +17 -0
- package/dist/http.js +3 -0
- package/dist/openapi.yaml +32 -0
- package/docs/API_SUMMARY.md +13 -2
- package/docs/translations.md +17 -0
- package/openapi.yaml +32 -0
- package/package.json +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { TranslationActivity } from '../translationActivity.js';
|
|
2
2
|
import type { ResolvedTranslationResponse, TranslationHashOptions, TranslationListParams, TranslationListResponse, TranslationLookupRequest, TranslationLookupResponse, TranslationRecord, TranslationResolveOptions, TranslationUpdateRequest } from '../types/translations.js';
|
|
3
|
+
/** @internal tests only */
|
|
4
|
+
export declare function _resetRevisionChecks(): void;
|
|
3
5
|
export declare namespace translations {
|
|
4
6
|
function hashText(text: string, options?: TranslationHashOptions): Promise<string>;
|
|
5
7
|
function hashTexts(texts: string[], options?: TranslationHashOptions): Promise<string[]>;
|
|
@@ -23,5 +25,23 @@ export declare namespace translations {
|
|
|
23
25
|
function list(collectionId: string, params?: TranslationListParams): Promise<TranslationListResponse>;
|
|
24
26
|
function get(collectionId: string, translationId: string): Promise<TranslationRecord>;
|
|
25
27
|
function update(collectionId: string, translationId: string, body: TranslationUpdateRequest): Promise<TranslationRecord>;
|
|
28
|
+
/** Admin: how many translations exist per language, and how many a person has edited. */
|
|
29
|
+
function summary(collectionId: string): Promise<{
|
|
30
|
+
languages: Array<{
|
|
31
|
+
language: string;
|
|
32
|
+
total: number;
|
|
33
|
+
edited: number;
|
|
34
|
+
}>;
|
|
35
|
+
}>;
|
|
36
|
+
/** Admin: where translated text appears for one language (context keys), with counts. */
|
|
37
|
+
function places(collectionId: string, targetLanguage: string): Promise<{
|
|
38
|
+
places: Array<{
|
|
39
|
+
contextKey: string;
|
|
40
|
+
total: number;
|
|
41
|
+
edited: number;
|
|
42
|
+
}>;
|
|
43
|
+
}>;
|
|
44
|
+
/** Admin: undo a person's edit with a fresh machine translation. */
|
|
45
|
+
function reset(collectionId: string, translationId: string): Promise<TranslationRecord>;
|
|
26
46
|
function clearLocalCache(collectionId?: string): Promise<void>;
|
|
27
47
|
}
|
package/dist/api/translations.js
CHANGED
|
@@ -49,6 +49,52 @@ function toResolvedItem(item, index, cacheSource) {
|
|
|
49
49
|
return Object.assign(Object.assign({}, item), { index,
|
|
50
50
|
cacheSource });
|
|
51
51
|
}
|
|
52
|
+
// A person can correct a translation in Studio. Visitors' browsers keep translations for weeks, so
|
|
53
|
+
// once per page per collection we ask the server when its translations were last edited, and drop
|
|
54
|
+
// the local copies if that changed since we last looked. The answer is cheap (no AI) and never
|
|
55
|
+
// blocks for long: on a slow or failed answer the local copies are used as before.
|
|
56
|
+
const REVISION_KEY = 'smartlinks:translations:revision:';
|
|
57
|
+
const REVISION_WAIT_MS = 1500;
|
|
58
|
+
const revisionChecks = new Map();
|
|
59
|
+
function readStoredRevision(collectionId) {
|
|
60
|
+
try {
|
|
61
|
+
return typeof localStorage !== 'undefined' ? localStorage.getItem(REVISION_KEY + collectionId) : null;
|
|
62
|
+
}
|
|
63
|
+
catch (_a) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function storeRevision(collectionId, revision) {
|
|
68
|
+
try {
|
|
69
|
+
if (typeof localStorage !== 'undefined')
|
|
70
|
+
localStorage.setItem(REVISION_KEY + collectionId, revision);
|
|
71
|
+
}
|
|
72
|
+
catch ( /* ignore */_a) { /* ignore */ }
|
|
73
|
+
}
|
|
74
|
+
async function checkRevision(collectionId) {
|
|
75
|
+
const res = await request(`/public/collection/${encodeURIComponent(collectionId)}/translations/revision`);
|
|
76
|
+
const revision = typeof (res === null || res === void 0 ? void 0 : res.revision) === 'string' ? res.revision : null;
|
|
77
|
+
if (!revision)
|
|
78
|
+
return;
|
|
79
|
+
const stored = readStoredRevision(collectionId);
|
|
80
|
+
// First look ever: copies saved before this check existed may predate an edit, unless nothing was ever edited.
|
|
81
|
+
const changed = stored === null ? revision !== '0' : stored !== revision;
|
|
82
|
+
if (changed)
|
|
83
|
+
await clearCachedTranslations(collectionId);
|
|
84
|
+
storeRevision(collectionId, revision);
|
|
85
|
+
}
|
|
86
|
+
function refreshIfEdited(collectionId) {
|
|
87
|
+
let check = revisionChecks.get(collectionId);
|
|
88
|
+
if (!check) {
|
|
89
|
+
check = checkRevision(collectionId).catch(() => undefined);
|
|
90
|
+
revisionChecks.set(collectionId, check);
|
|
91
|
+
}
|
|
92
|
+
return Promise.race([check, new Promise((resolve) => setTimeout(resolve, REVISION_WAIT_MS))]);
|
|
93
|
+
}
|
|
94
|
+
/** @internal tests only */
|
|
95
|
+
export function _resetRevisionChecks() {
|
|
96
|
+
revisionChecks.clear();
|
|
97
|
+
}
|
|
52
98
|
export var translations;
|
|
53
99
|
(function (translations) {
|
|
54
100
|
async function hashText(text, options) {
|
|
@@ -135,6 +181,8 @@ export var translations;
|
|
|
135
181
|
items: passthroughItems,
|
|
136
182
|
};
|
|
137
183
|
}
|
|
184
|
+
if (useLocalCache && !refreshLocalCache)
|
|
185
|
+
await refreshIfEdited(collectionId);
|
|
138
186
|
const cachedByHash = useLocalCache && !refreshLocalCache
|
|
139
187
|
? await getCachedTranslations({
|
|
140
188
|
collectionId,
|
|
@@ -242,6 +290,21 @@ export var translations;
|
|
|
242
290
|
return patch(path, body);
|
|
243
291
|
}
|
|
244
292
|
translations.update = update;
|
|
293
|
+
/** Admin: how many translations exist per language, and how many a person has edited. */
|
|
294
|
+
async function summary(collectionId) {
|
|
295
|
+
return request(`/admin/collection/${encodeURIComponent(collectionId)}/translations/summary`);
|
|
296
|
+
}
|
|
297
|
+
translations.summary = summary;
|
|
298
|
+
/** Admin: where translated text appears for one language (context keys), with counts. */
|
|
299
|
+
async function places(collectionId, targetLanguage) {
|
|
300
|
+
return request(`/admin/collection/${encodeURIComponent(collectionId)}/translations/places?targetLanguage=${encodeURIComponent(targetLanguage)}`);
|
|
301
|
+
}
|
|
302
|
+
translations.places = places;
|
|
303
|
+
/** Admin: undo a person's edit with a fresh machine translation. */
|
|
304
|
+
async function reset(collectionId, translationId) {
|
|
305
|
+
return post(`/admin/collection/${encodeURIComponent(collectionId)}/translations/${encodeURIComponent(translationId)}/reset`, {});
|
|
306
|
+
}
|
|
307
|
+
translations.reset = reset;
|
|
245
308
|
async function clearLocalCache(collectionId) {
|
|
246
309
|
await clearCachedTranslations(collectionId);
|
|
247
310
|
}
|
package/dist/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.31 | Generated: 2026-11-20T11:12:32.109Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -15491,6 +15491,8 @@ Invoke ONE built-in server tool directly — no model in the loop. This is the "
|
|
|
15491
15491
|
|
|
15492
15492
|
### translations
|
|
15493
15493
|
|
|
15494
|
+
**_resetRevisionChecks**() → `void`
|
|
15495
|
+
|
|
15494
15496
|
**hashText**(text: string, options?: TranslationHashOptions) → `Promise<string>`
|
|
15495
15497
|
|
|
15496
15498
|
**hashTexts**(texts: string[], options?: TranslationHashOptions) → `Promise<string[]>`
|
|
@@ -15527,8 +15529,17 @@ Whether a first-time translation is under way right now (see onActivity).
|
|
|
15527
15529
|
body: TranslationUpdateRequest) → `Promise<TranslationRecord>`
|
|
15528
15530
|
Whether a first-time translation is under way right now (see onActivity).
|
|
15529
15531
|
|
|
15532
|
+
**summary**(collectionId: string) → `Promise<`
|
|
15533
|
+
Admin: how many translations exist per language, and how many a person has edited.
|
|
15534
|
+
|
|
15535
|
+
**places**(collectionId: string, targetLanguage: string) → `Promise<`
|
|
15536
|
+
Admin: where translated text appears for one language (context keys), with counts.
|
|
15537
|
+
|
|
15538
|
+
**reset**(collectionId: string, translationId: string) → `Promise<TranslationRecord>`
|
|
15539
|
+
Admin: undo a person's edit with a fresh machine translation.
|
|
15540
|
+
|
|
15530
15541
|
**clearLocalCache**(collectionId?: string) → `Promise<void>`
|
|
15531
|
-
|
|
15542
|
+
Admin: undo a person's edit with a fresh machine translation.
|
|
15532
15543
|
|
|
15533
15544
|
### tts
|
|
15534
15545
|
|
|
@@ -340,6 +340,23 @@ const updated = await translations.update('collection-123', 'translation-id', {
|
|
|
340
340
|
})
|
|
341
341
|
```
|
|
342
342
|
|
|
343
|
+
### Summary, places and reset (Studio's Translations screen)
|
|
344
|
+
|
|
345
|
+
```ts
|
|
346
|
+
await translations.summary(collectionId) // { languages: [{ language, total, edited }] }
|
|
347
|
+
await translations.places(collectionId, 'de') // { places: [{ contextKey, total, edited }] }
|
|
348
|
+
await translations.update(collectionId, id, { translatedText: 'Zum Warenkorb' }) // a person's edit: kept, never overwritten
|
|
349
|
+
await translations.reset(collectionId, id) // put a fresh machine translation back
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### Corrections reach returning visitors
|
|
353
|
+
|
|
354
|
+
`resolve()` keeps translations in the browser for weeks. Once per page per collection it asks
|
|
355
|
+
`GET /public/collection/:id/translations/revision`, which changes only when a person edits a
|
|
356
|
+
translation or puts a machine one back. When it has changed, that collection's saved translations are
|
|
357
|
+
dropped and fetched again (from the server's store, no AI). A slow or failed answer never holds the
|
|
358
|
+
page for more than 1.5 s, and the saved copies are used as before.
|
|
359
|
+
|
|
343
360
|
## Recommended Usage Pattern
|
|
344
361
|
|
|
345
362
|
For front-end rendering:
|
package/dist/http.js
CHANGED
|
@@ -219,6 +219,9 @@ function shouldSkipCache(path) {
|
|
|
219
219
|
// Bookings change by the second (places left, busy times, a booking's status) — never serve them stale.
|
|
220
220
|
if (/\/app\/[^/]+\/bookings(\/|\?|$)/i.test(path))
|
|
221
221
|
return true;
|
|
222
|
+
// A collection's translation revision is how visitors' browsers learn of a correction — never stale.
|
|
223
|
+
if (/\/translations\/revision(\?|$)/i.test(path))
|
|
224
|
+
return true;
|
|
222
225
|
// Tag ranges change as tags are programmed, and carry the tags' keys — never cached, never persisted.
|
|
223
226
|
if (/\/claimSet\/[^/]+\/ranges(\/|\?|$)/i.test(path))
|
|
224
227
|
return true;
|
package/dist/openapi.yaml
CHANGED
|
@@ -9472,6 +9472,38 @@ paths:
|
|
|
9472
9472
|
application/json:
|
|
9473
9473
|
schema:
|
|
9474
9474
|
$ref: "#/components/schemas/TranslationUpdateRequest"
|
|
9475
|
+
/admin/collection/{collectionId}/translations/{translationId}/reset:
|
|
9476
|
+
post:
|
|
9477
|
+
tags:
|
|
9478
|
+
- translations
|
|
9479
|
+
summary: "Admin: undo a person's edit with a fresh machine translation."
|
|
9480
|
+
operationId: translations_reset
|
|
9481
|
+
security:
|
|
9482
|
+
- bearerAuth: []
|
|
9483
|
+
parameters:
|
|
9484
|
+
- name: collectionId
|
|
9485
|
+
in: path
|
|
9486
|
+
required: true
|
|
9487
|
+
schema:
|
|
9488
|
+
type: string
|
|
9489
|
+
- name: translationId
|
|
9490
|
+
in: path
|
|
9491
|
+
required: true
|
|
9492
|
+
schema:
|
|
9493
|
+
type: string
|
|
9494
|
+
responses:
|
|
9495
|
+
200:
|
|
9496
|
+
description: Success
|
|
9497
|
+
content:
|
|
9498
|
+
application/json:
|
|
9499
|
+
schema:
|
|
9500
|
+
$ref: "#/components/schemas/TranslationRecord"
|
|
9501
|
+
400:
|
|
9502
|
+
description: Bad request
|
|
9503
|
+
401:
|
|
9504
|
+
description: Unauthorized
|
|
9505
|
+
404:
|
|
9506
|
+
description: Not found
|
|
9475
9507
|
/admin/collection/{collectionId}/updateUserAccess:
|
|
9476
9508
|
post:
|
|
9477
9509
|
tags:
|
package/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.31 | Generated: 2026-11-20T11:12:32.109Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -15491,6 +15491,8 @@ Invoke ONE built-in server tool directly — no model in the loop. This is the "
|
|
|
15491
15491
|
|
|
15492
15492
|
### translations
|
|
15493
15493
|
|
|
15494
|
+
**_resetRevisionChecks**() → `void`
|
|
15495
|
+
|
|
15494
15496
|
**hashText**(text: string, options?: TranslationHashOptions) → `Promise<string>`
|
|
15495
15497
|
|
|
15496
15498
|
**hashTexts**(texts: string[], options?: TranslationHashOptions) → `Promise<string[]>`
|
|
@@ -15527,8 +15529,17 @@ Whether a first-time translation is under way right now (see onActivity).
|
|
|
15527
15529
|
body: TranslationUpdateRequest) → `Promise<TranslationRecord>`
|
|
15528
15530
|
Whether a first-time translation is under way right now (see onActivity).
|
|
15529
15531
|
|
|
15532
|
+
**summary**(collectionId: string) → `Promise<`
|
|
15533
|
+
Admin: how many translations exist per language, and how many a person has edited.
|
|
15534
|
+
|
|
15535
|
+
**places**(collectionId: string, targetLanguage: string) → `Promise<`
|
|
15536
|
+
Admin: where translated text appears for one language (context keys), with counts.
|
|
15537
|
+
|
|
15538
|
+
**reset**(collectionId: string, translationId: string) → `Promise<TranslationRecord>`
|
|
15539
|
+
Admin: undo a person's edit with a fresh machine translation.
|
|
15540
|
+
|
|
15530
15541
|
**clearLocalCache**(collectionId?: string) → `Promise<void>`
|
|
15531
|
-
|
|
15542
|
+
Admin: undo a person's edit with a fresh machine translation.
|
|
15532
15543
|
|
|
15533
15544
|
### tts
|
|
15534
15545
|
|
package/docs/translations.md
CHANGED
|
@@ -340,6 +340,23 @@ const updated = await translations.update('collection-123', 'translation-id', {
|
|
|
340
340
|
})
|
|
341
341
|
```
|
|
342
342
|
|
|
343
|
+
### Summary, places and reset (Studio's Translations screen)
|
|
344
|
+
|
|
345
|
+
```ts
|
|
346
|
+
await translations.summary(collectionId) // { languages: [{ language, total, edited }] }
|
|
347
|
+
await translations.places(collectionId, 'de') // { places: [{ contextKey, total, edited }] }
|
|
348
|
+
await translations.update(collectionId, id, { translatedText: 'Zum Warenkorb' }) // a person's edit: kept, never overwritten
|
|
349
|
+
await translations.reset(collectionId, id) // put a fresh machine translation back
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### Corrections reach returning visitors
|
|
353
|
+
|
|
354
|
+
`resolve()` keeps translations in the browser for weeks. Once per page per collection it asks
|
|
355
|
+
`GET /public/collection/:id/translations/revision`, which changes only when a person edits a
|
|
356
|
+
translation or puts a machine one back. When it has changed, that collection's saved translations are
|
|
357
|
+
dropped and fetched again (from the server's store, no AI). A slow or failed answer never holds the
|
|
358
|
+
page for more than 1.5 s, and the saved copies are used as before.
|
|
359
|
+
|
|
343
360
|
## Recommended Usage Pattern
|
|
344
361
|
|
|
345
362
|
For front-end rendering:
|
package/openapi.yaml
CHANGED
|
@@ -9472,6 +9472,38 @@ paths:
|
|
|
9472
9472
|
application/json:
|
|
9473
9473
|
schema:
|
|
9474
9474
|
$ref: "#/components/schemas/TranslationUpdateRequest"
|
|
9475
|
+
/admin/collection/{collectionId}/translations/{translationId}/reset:
|
|
9476
|
+
post:
|
|
9477
|
+
tags:
|
|
9478
|
+
- translations
|
|
9479
|
+
summary: "Admin: undo a person's edit with a fresh machine translation."
|
|
9480
|
+
operationId: translations_reset
|
|
9481
|
+
security:
|
|
9482
|
+
- bearerAuth: []
|
|
9483
|
+
parameters:
|
|
9484
|
+
- name: collectionId
|
|
9485
|
+
in: path
|
|
9486
|
+
required: true
|
|
9487
|
+
schema:
|
|
9488
|
+
type: string
|
|
9489
|
+
- name: translationId
|
|
9490
|
+
in: path
|
|
9491
|
+
required: true
|
|
9492
|
+
schema:
|
|
9493
|
+
type: string
|
|
9494
|
+
responses:
|
|
9495
|
+
200:
|
|
9496
|
+
description: Success
|
|
9497
|
+
content:
|
|
9498
|
+
application/json:
|
|
9499
|
+
schema:
|
|
9500
|
+
$ref: "#/components/schemas/TranslationRecord"
|
|
9501
|
+
400:
|
|
9502
|
+
description: Bad request
|
|
9503
|
+
401:
|
|
9504
|
+
description: Unauthorized
|
|
9505
|
+
404:
|
|
9506
|
+
description: Not found
|
|
9475
9507
|
/admin/collection/{collectionId}/updateUserAccess:
|
|
9476
9508
|
post:
|
|
9477
9509
|
tags:
|