@proveanything/smartlinks 2.1.29 → 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 +35 -0
- package/dist/api/translations.js +97 -2
- package/dist/docs/API_SUMMARY.md +26 -1
- package/dist/docs/translations.md +37 -0
- package/dist/http.js +3 -0
- package/dist/iframeResponder.js +26 -2
- package/dist/index.d.ts +1 -0
- package/dist/openapi.yaml +32 -0
- package/dist/translationActivity.d.ts +40 -0
- package/dist/translationActivity.js +212 -0
- package/docs/API_SUMMARY.md +26 -1
- package/docs/translations.md +37 -0
- package/openapi.yaml +32 -0
- package/package.json +1 -1
|
@@ -1,12 +1,47 @@
|
|
|
1
|
+
import type { TranslationActivity } from '../translationActivity.js';
|
|
1
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;
|
|
2
5
|
export declare namespace translations {
|
|
3
6
|
function hashText(text: string, options?: TranslationHashOptions): Promise<string>;
|
|
4
7
|
function hashTexts(texts: string[], options?: TranslationHashOptions): Promise<string[]>;
|
|
5
8
|
function normalizeText(text: string, options?: TranslationHashOptions): string;
|
|
6
9
|
function lookup(collectionId: string, body: TranslationLookupRequest): Promise<TranslationLookupResponse>;
|
|
10
|
+
/**
|
|
11
|
+
* Hear when content is being translated for the first time, in this window or in any app frame
|
|
12
|
+
* it embeds. Hosts use it to show a "translating this page" notice; apps never have to.
|
|
13
|
+
* Returns an unsubscribe function.
|
|
14
|
+
*/
|
|
15
|
+
function onActivity(cb: (activity: TranslationActivity) => void): () => void;
|
|
16
|
+
/** The "translating this page" line, in the language being translated into (for a host's banner). */
|
|
17
|
+
function translatingMessage(language: string | null | undefined): {
|
|
18
|
+
text: string;
|
|
19
|
+
lang: string;
|
|
20
|
+
dir: 'ltr' | 'rtl';
|
|
21
|
+
};
|
|
22
|
+
/** Whether a first-time translation is under way right now (see onActivity). */
|
|
23
|
+
function activity(): TranslationActivity;
|
|
7
24
|
function resolve(collectionId: string, body: TranslationLookupRequest, options?: TranslationResolveOptions): Promise<ResolvedTranslationResponse>;
|
|
8
25
|
function list(collectionId: string, params?: TranslationListParams): Promise<TranslationListResponse>;
|
|
9
26
|
function get(collectionId: string, translationId: string): Promise<TranslationRecord>;
|
|
10
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>;
|
|
11
46
|
function clearLocalCache(collectionId?: string): Promise<void>;
|
|
12
47
|
}
|
package/dist/api/translations.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { patch, post, request } from '../http.js';
|
|
1
|
+
import { isProxyEnabled, patch, post, request } from '../http.js';
|
|
2
2
|
import { clearCachedTranslations, deriveTranslationContextKey, getCachedTranslations, getDefaultTranslationCacheTtlMs, hashTranslationText, normalizeTranslationText, setCachedTranslations, } from '../translationCache.js';
|
|
3
|
+
import { trackTranslation, onActivity as onTranslationActivity, activity as translationActivity, translatingMessage as translatingLine } from '../translationActivity.js';
|
|
3
4
|
function normalizeLookupRequest(body) {
|
|
4
5
|
var _a, _b, _c;
|
|
5
6
|
const texts = Array.isArray(body.texts)
|
|
@@ -48,6 +49,52 @@ function toResolvedItem(item, index, cacheSource) {
|
|
|
48
49
|
return Object.assign(Object.assign({}, item), { index,
|
|
49
50
|
cacheSource });
|
|
50
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
|
+
}
|
|
51
98
|
export var translations;
|
|
52
99
|
(function (translations) {
|
|
53
100
|
async function hashText(text, options) {
|
|
@@ -65,9 +112,40 @@ export var translations;
|
|
|
65
112
|
async function lookup(collectionId, body) {
|
|
66
113
|
const path = `/public/collection/${encodeURIComponent(collectionId)}/translations/lookup`;
|
|
67
114
|
const normalized = normalizeLookupRequest(body);
|
|
68
|
-
|
|
115
|
+
// A request that may create translations can take a while the first time: say so, so a host
|
|
116
|
+
// (Portal, Hub) can show "translating…" without the app doing anything (translationActivity.ts).
|
|
117
|
+
// Through the parent (proxyMode), the host's IframeResponder counts it instead, so apps built on
|
|
118
|
+
// older SDKs are covered too and nothing is counted twice.
|
|
119
|
+
const settle = normalized.mode === 'cache-fill' && !isProxyEnabled() && !sameLanguage(normalized.sourceLanguage, normalized.targetLanguage)
|
|
120
|
+
? trackTranslation(normalized.targetLanguage, normalized.texts.length)
|
|
121
|
+
: null;
|
|
122
|
+
try {
|
|
123
|
+
return await post(path, normalized.requestBody);
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
settle === null || settle === void 0 ? void 0 : settle();
|
|
127
|
+
}
|
|
69
128
|
}
|
|
70
129
|
translations.lookup = lookup;
|
|
130
|
+
/**
|
|
131
|
+
* Hear when content is being translated for the first time, in this window or in any app frame
|
|
132
|
+
* it embeds. Hosts use it to show a "translating this page" notice; apps never have to.
|
|
133
|
+
* Returns an unsubscribe function.
|
|
134
|
+
*/
|
|
135
|
+
function onActivity(cb) {
|
|
136
|
+
return onTranslationActivity(cb);
|
|
137
|
+
}
|
|
138
|
+
translations.onActivity = onActivity;
|
|
139
|
+
/** The "translating this page" line, in the language being translated into (for a host's banner). */
|
|
140
|
+
function translatingMessage(language) {
|
|
141
|
+
return translatingLine(language);
|
|
142
|
+
}
|
|
143
|
+
translations.translatingMessage = translatingMessage;
|
|
144
|
+
/** Whether a first-time translation is under way right now (see onActivity). */
|
|
145
|
+
function activity() {
|
|
146
|
+
return translationActivity();
|
|
147
|
+
}
|
|
148
|
+
translations.activity = activity;
|
|
71
149
|
async function resolve(collectionId, body, options = {}) {
|
|
72
150
|
var _a, _b, _c;
|
|
73
151
|
const normalized = normalizeLookupRequest(body);
|
|
@@ -103,6 +181,8 @@ export var translations;
|
|
|
103
181
|
items: passthroughItems,
|
|
104
182
|
};
|
|
105
183
|
}
|
|
184
|
+
if (useLocalCache && !refreshLocalCache)
|
|
185
|
+
await refreshIfEdited(collectionId);
|
|
106
186
|
const cachedByHash = useLocalCache && !refreshLocalCache
|
|
107
187
|
? await getCachedTranslations({
|
|
108
188
|
collectionId,
|
|
@@ -210,6 +290,21 @@ export var translations;
|
|
|
210
290
|
return patch(path, body);
|
|
211
291
|
}
|
|
212
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;
|
|
213
308
|
async function clearLocalCache(collectionId) {
|
|
214
309
|
await clearCachedTranslations(collectionId);
|
|
215
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[]>`
|
|
@@ -15500,21 +15502,44 @@ Invoke ONE built-in server tool directly — no model in the loop. This is the "
|
|
|
15500
15502
|
**lookup**(collectionId: string,
|
|
15501
15503
|
body: TranslationLookupRequest) → `Promise<TranslationLookupResponse>`
|
|
15502
15504
|
|
|
15505
|
+
**onActivity**(cb: (activity: TranslationActivity) → `void`
|
|
15506
|
+
Hear when content is being translated for the first time, in this window or in any app frame it embeds. Hosts use it to show a "translating this page" notice; apps never have to. Returns an unsubscribe function.
|
|
15507
|
+
|
|
15508
|
+
**translatingMessage**(language: string | null | undefined) → ``
|
|
15509
|
+
The "translating this page" line, in the language being translated into (for a host's banner).
|
|
15510
|
+
|
|
15511
|
+
**activity**() → `TranslationActivity`
|
|
15512
|
+
Whether a first-time translation is under way right now (see onActivity).
|
|
15513
|
+
|
|
15503
15514
|
**resolve**(collectionId: string,
|
|
15504
15515
|
body: TranslationLookupRequest,
|
|
15505
15516
|
options: TranslationResolveOptions = {}) → `Promise<ResolvedTranslationResponse>`
|
|
15517
|
+
Whether a first-time translation is under way right now (see onActivity).
|
|
15506
15518
|
|
|
15507
15519
|
**list**(collectionId: string,
|
|
15508
15520
|
params?: TranslationListParams) → `Promise<TranslationListResponse>`
|
|
15521
|
+
Whether a first-time translation is under way right now (see onActivity).
|
|
15509
15522
|
|
|
15510
15523
|
**get**(collectionId: string,
|
|
15511
15524
|
translationId: string) → `Promise<TranslationRecord>`
|
|
15525
|
+
Whether a first-time translation is under way right now (see onActivity).
|
|
15512
15526
|
|
|
15513
15527
|
**update**(collectionId: string,
|
|
15514
15528
|
translationId: string,
|
|
15515
15529
|
body: TranslationUpdateRequest) → `Promise<TranslationRecord>`
|
|
15530
|
+
Whether a first-time translation is under way right now (see onActivity).
|
|
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.
|
|
15516
15540
|
|
|
15517
15541
|
**clearLocalCache**(collectionId?: string) → `Promise<void>`
|
|
15542
|
+
Admin: undo a person's edit with a fresh machine translation.
|
|
15518
15543
|
|
|
15519
15544
|
### tts
|
|
15520
15545
|
|
|
@@ -253,6 +253,26 @@ await translations.resolve('collection-123', {
|
|
|
253
253
|
|
|
254
254
|
The SDK derives a deterministic local cache key from `context` so browser-local entries do not collide across different UI surfaces.
|
|
255
255
|
|
|
256
|
+
## "Translating this page" notice (hosts)
|
|
257
|
+
|
|
258
|
+
The first visitor to see content in a new language waits while it is translated. Apps do not need
|
|
259
|
+
to show anything for this: when a `cache-fill` request is still unanswered after about 0.6 s, the
|
|
260
|
+
SDK announces it, and announces again when it settles. Inside a frame it posts
|
|
261
|
+
`{ _smartlinksIframeMessage: true, type: 'smartlinks:translating', payload: { active, targetLanguage, texts } }`
|
|
262
|
+
to the parent. Already-translated content answers well inside the delay, so nothing is announced.
|
|
263
|
+
|
|
264
|
+
Portal and Hub listen once and show a banner:
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
const stop = translations.onActivity(({ active, targetLanguage, texts }) => {
|
|
268
|
+
setBanner(active ? targetLanguage : null)
|
|
269
|
+
})
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
`onActivity` combines this window's own requests with those of every embedded app frame.
|
|
273
|
+
`translations.activity()` returns the state right now. An app that wants its own spinner can use the
|
|
274
|
+
same call.
|
|
275
|
+
|
|
256
276
|
## Hashing Helpers
|
|
257
277
|
|
|
258
278
|
The SDK also exposes the normalization and hashing helpers used by the local cache flow.
|
|
@@ -320,6 +340,23 @@ const updated = await translations.update('collection-123', 'translation-id', {
|
|
|
320
340
|
})
|
|
321
341
|
```
|
|
322
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
|
+
|
|
323
360
|
## Recommended Usage Pattern
|
|
324
361
|
|
|
325
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/iframeResponder.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import * as cache from './cache.js';
|
|
5
5
|
import { collection } from './api/collection.js';
|
|
6
6
|
import { getBaseURL, hasAuthCredentials } from './http.js';
|
|
7
|
+
import { trackTranslation } from './translationActivity.js';
|
|
7
8
|
/**
|
|
8
9
|
* Parent-side iframe responder for SmartLinks microapp embedding.
|
|
9
10
|
*
|
|
@@ -540,8 +541,17 @@ export class IframeResponder {
|
|
|
540
541
|
fetchOptions.body = JSON.stringify(proxyData.body);
|
|
541
542
|
fetchOptions.headers = Object.assign(Object.assign({}, fetchOptions.headers), { 'Content-Type': 'application/json' });
|
|
542
543
|
}
|
|
543
|
-
|
|
544
|
-
const
|
|
544
|
+
// An app's content translation: let the host show "translating this page" while it runs.
|
|
545
|
+
const settleTranslation = translationLookupTarget(proxyData.method, path, proxyData.body);
|
|
546
|
+
let fetchResponse;
|
|
547
|
+
let responseData;
|
|
548
|
+
try {
|
|
549
|
+
fetchResponse = await fetch(fullUrl, fetchOptions);
|
|
550
|
+
responseData = await fetchResponse.json().catch(() => null);
|
|
551
|
+
}
|
|
552
|
+
finally {
|
|
553
|
+
settleTranslation === null || settleTranslation === void 0 ? void 0 : settleTranslation();
|
|
554
|
+
}
|
|
545
555
|
if (!fetchResponse.ok) {
|
|
546
556
|
response.error = (responseData === null || responseData === void 0 ? void 0 : responseData.message) || (responseData === null || responseData === void 0 ? void 0 : responseData.errorText) || `Request failed with status ${fetchResponse.status}`;
|
|
547
557
|
response.statusCode = fetchResponse.status;
|
|
@@ -871,3 +881,17 @@ export function buildIframeSrc(options) {
|
|
|
871
881
|
path = '/' + path;
|
|
872
882
|
return `${base}/#${path}?${params.toString()}`.replace('/#/?', '/#?').replace('/#/', '/#/');
|
|
873
883
|
}
|
|
884
|
+
/** A proxied translations lookup that may create translations: start counting it (translationActivity.ts). */
|
|
885
|
+
function translationLookupTarget(method, path, body) {
|
|
886
|
+
if (String(method).toUpperCase() !== 'POST' || !/\/translations\/lookup(\?|$)/.test(path))
|
|
887
|
+
return null;
|
|
888
|
+
if (!body || typeof body !== 'object' || typeof body.targetLanguage !== 'string')
|
|
889
|
+
return null;
|
|
890
|
+
if (body.mode === 'cache-only')
|
|
891
|
+
return null;
|
|
892
|
+
const source = typeof body.sourceLanguage === 'string' ? body.sourceLanguage : 'en';
|
|
893
|
+
if (source.trim().toLowerCase() === body.targetLanguage.trim().toLowerCase())
|
|
894
|
+
return null;
|
|
895
|
+
const texts = Array.isArray(body.texts) ? body.texts.length : typeof body.text === 'string' ? 1 : 0;
|
|
896
|
+
return trackTranslation(body.targetLanguage, texts);
|
|
897
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export type { BroadcastSendRequest } from "./types/broadcasts.js";
|
|
|
36
36
|
export type { AppConfigOptions } from "./api/appConfiguration.js";
|
|
37
37
|
export type { AdditionalGtin, ISODateString, JsonPrimitive, JsonValue, ProductCreateRequest, ProductClaimCreateInput, ProductClaimCreateRequestBody, ProductClaimLookupInput, ProductFacetMap, ProductFacetValue, ProductImageUrlInput, ProductKey, ProductQueryRequest, ProductQueryResponse, ProductUpdateRequest, Product, ProductWriteInput, PublicProduct, } from "./types/product.js";
|
|
38
38
|
export type { TranslationLookupMode, TranslationContentType, TranslationQuality, TranslationItemStatus, TranslationContextValue, TranslationContext, TranslationLookupRequestBase, TranslationLookupSingleRequest, TranslationLookupBatchRequest, TranslationLookupRequest, TranslationLookupItem, TranslationLookupResponse, ResolvedTranslationItem, ResolvedTranslationResponse, TranslationHashOptions, TranslationResolveOptions, TranslationRecord, TranslationListParams, TranslationListResponse, TranslationUpdateRequest, } from "./types/translations.js";
|
|
39
|
+
export type { TranslationActivity } from "./translationActivity.js";
|
|
39
40
|
export type { FacetBucket, FacetDefinition, FacetDefinitionWriteInput, FacetGetParams, FacetListParams, FacetListResponse, FacetNamespaceListResponse, FacetQueryRequest, FacetQueryResponse, FacetValue, FacetValueDefinition, FacetValueGetParams, FacetValueListParams, FacetValueListResponse, FacetValueResponse, FacetValueWriteInput, PublicFacetListParams, } from "./types/facets.js";
|
|
40
41
|
export type { Collection, CollectionResponse, CollectionCreateRequest, CollectionUpdateRequest, DomainTarget, HubAvailabilityResponse, } from "./types/collection.js";
|
|
41
42
|
export type { Proof, ProofResponse, ProofWrite, ProofCreateRequest, ProofUpdateRequest, ProofClaimRequest, ProofGrant, GrantScope, GrantAudience, CreateGrantOptions, RedeemGrantOptions, RedeemGrantResult, ProofTransfer, ProofTransferType, ProofTransferState, TransferProofOptions, TransferProofResult, } from "./types/proof.js";
|
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:
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface TranslationActivity {
|
|
2
|
+
/** true while at least one fresh translation is under way (here or in an embedded app frame). */
|
|
3
|
+
active: boolean;
|
|
4
|
+
/** The language being translated into (the most recent one when several are under way). */
|
|
5
|
+
targetLanguage: string | null;
|
|
6
|
+
/** How many texts are waiting to be translated, across everything under way. */
|
|
7
|
+
texts: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const TRANSLATING_MESSAGE = "smartlinks:translating";
|
|
10
|
+
/**
|
|
11
|
+
* Mark a request that may create translations. Returns a function to call when it settles.
|
|
12
|
+
* Nothing is announced unless the request is still running after the delay.
|
|
13
|
+
* @internal used by translations.lookup
|
|
14
|
+
*/
|
|
15
|
+
export declare function trackTranslation(targetLanguage: string, texts: number): () => void;
|
|
16
|
+
/**
|
|
17
|
+
* Hear when content is being translated for the first time: requests made in this window and in
|
|
18
|
+
* every app frame embedded in it. The callback gets the combined state now and on every change.
|
|
19
|
+
* Returns an unsubscribe function.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* translations.onActivity(({ active, targetLanguage }) => setBanner(active ? targetLanguage : null))
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function onActivity(cb: (activity: TranslationActivity) => void): () => void;
|
|
26
|
+
/** The combined state right now. */
|
|
27
|
+
export declare function activity(): TranslationActivity;
|
|
28
|
+
/** @internal tests only */
|
|
29
|
+
export declare function _resetActivity(options?: {
|
|
30
|
+
showAfterMs?: number;
|
|
31
|
+
}): void;
|
|
32
|
+
/**
|
|
33
|
+
* The "translating this page" line in the language being translated into, with its text direction.
|
|
34
|
+
* zh-CN / zh-SG → Simplified, zh-TW / zh-HK → Traditional; unknown languages get English.
|
|
35
|
+
*/
|
|
36
|
+
export declare function translatingMessage(language: string | null | undefined): {
|
|
37
|
+
text: string;
|
|
38
|
+
lang: string;
|
|
39
|
+
dir: 'ltr' | 'rtl';
|
|
40
|
+
};
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// Translation activity: "this page is being translated for the first time".
|
|
2
|
+
//
|
|
3
|
+
// Every app's content translation goes through translations.lookup / resolve, so the SDK is the one
|
|
4
|
+
// place that knows a visitor is waiting on a fresh AI translation. When a request that may create
|
|
5
|
+
// translations ('cache-fill') is still unanswered after a short delay, the SDK announces it, and
|
|
6
|
+
// announces again when it settles. Answers already in the cache come back well inside the delay, so
|
|
7
|
+
// nothing shows for a page that is already translated.
|
|
8
|
+
//
|
|
9
|
+
// inside a frame → posts { _smartlinksIframeMessage, type: 'smartlinks:translating', payload } to the parent
|
|
10
|
+
// in any window → listeners from translations.onActivity() hear it directly
|
|
11
|
+
//
|
|
12
|
+
// A host (Portal, Hub) calls translations.onActivity(cb) once: it hears its own requests AND those
|
|
13
|
+
// of every app frame it embeds, combined into one state. Apps need do nothing.
|
|
14
|
+
export const TRANSLATING_MESSAGE = 'smartlinks:translating';
|
|
15
|
+
// One state per window, shared by every copy of the SDK loaded into it: an app drawn straight into
|
|
16
|
+
// the page usually bundles its own SDK, and the host's listener must still hear its requests.
|
|
17
|
+
const KEY = '__smartlinksTranslationActivity';
|
|
18
|
+
function fresh() {
|
|
19
|
+
return {
|
|
20
|
+
showAfterMs: 600,
|
|
21
|
+
sources: new Map(),
|
|
22
|
+
listeners: new Set(),
|
|
23
|
+
messageListening: false,
|
|
24
|
+
onMessage: null,
|
|
25
|
+
last: { active: false, targetLanguage: null, texts: 0 },
|
|
26
|
+
lastLang: null,
|
|
27
|
+
self: { count: 0, texts: 0, lang: null },
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function shared() {
|
|
31
|
+
const g = globalThis;
|
|
32
|
+
if (!g[KEY])
|
|
33
|
+
g[KEY] = fresh();
|
|
34
|
+
return g[KEY];
|
|
35
|
+
}
|
|
36
|
+
function current() {
|
|
37
|
+
let texts = 0;
|
|
38
|
+
let active = false;
|
|
39
|
+
for (const s of shared().sources.values()) {
|
|
40
|
+
if (s.count > 0) {
|
|
41
|
+
active = true;
|
|
42
|
+
texts += s.texts;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return { active, targetLanguage: active ? shared().lastLang : null, texts };
|
|
46
|
+
}
|
|
47
|
+
function notify() {
|
|
48
|
+
const st = shared();
|
|
49
|
+
const next = current();
|
|
50
|
+
const last = st.last;
|
|
51
|
+
if (next.active === last.active && next.texts === last.texts && next.targetLanguage === last.targetLanguage)
|
|
52
|
+
return;
|
|
53
|
+
st.last = next;
|
|
54
|
+
for (const cb of st.listeners) {
|
|
55
|
+
try {
|
|
56
|
+
cb(next);
|
|
57
|
+
}
|
|
58
|
+
catch ( /* a listener's fault is its own */_a) { /* a listener's fault is its own */ }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function inIframe() {
|
|
62
|
+
try {
|
|
63
|
+
return typeof window !== 'undefined' && !!window.parent && window.parent !== window;
|
|
64
|
+
}
|
|
65
|
+
catch (_a) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function postParent(payload) {
|
|
70
|
+
if (!inIframe())
|
|
71
|
+
return;
|
|
72
|
+
try {
|
|
73
|
+
window.parent.postMessage({ _smartlinksIframeMessage: true, type: TRANSLATING_MESSAGE, payload }, '*');
|
|
74
|
+
}
|
|
75
|
+
catch ( /* ignore */_a) { /* ignore */ }
|
|
76
|
+
}
|
|
77
|
+
function setSource(key, s) {
|
|
78
|
+
const st = shared();
|
|
79
|
+
if (s.count > 0) {
|
|
80
|
+
st.sources.set(key, s);
|
|
81
|
+
if (s.lang)
|
|
82
|
+
st.lastLang = s.lang;
|
|
83
|
+
}
|
|
84
|
+
else
|
|
85
|
+
st.sources.delete(key);
|
|
86
|
+
notify();
|
|
87
|
+
}
|
|
88
|
+
function publishSelf() {
|
|
89
|
+
setSource('self', Object.assign({}, shared().self));
|
|
90
|
+
// An app frame that is itself a host passes its whole state up, so nesting still reaches the top.
|
|
91
|
+
const all = current();
|
|
92
|
+
postParent({ active: all.active, targetLanguage: all.targetLanguage, texts: all.texts });
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Mark a request that may create translations. Returns a function to call when it settles.
|
|
96
|
+
* Nothing is announced unless the request is still running after the delay.
|
|
97
|
+
* @internal used by translations.lookup
|
|
98
|
+
*/
|
|
99
|
+
export function trackTranslation(targetLanguage, texts) {
|
|
100
|
+
let shown = false;
|
|
101
|
+
let done = false;
|
|
102
|
+
const st = shared();
|
|
103
|
+
const self = st.self;
|
|
104
|
+
const timer = setTimeout(() => {
|
|
105
|
+
if (done)
|
|
106
|
+
return;
|
|
107
|
+
shown = true;
|
|
108
|
+
self.count += 1;
|
|
109
|
+
self.texts += texts;
|
|
110
|
+
self.lang = targetLanguage;
|
|
111
|
+
publishSelf();
|
|
112
|
+
}, st.showAfterMs);
|
|
113
|
+
return () => {
|
|
114
|
+
if (done)
|
|
115
|
+
return;
|
|
116
|
+
done = true;
|
|
117
|
+
clearTimeout(timer);
|
|
118
|
+
if (!shown)
|
|
119
|
+
return;
|
|
120
|
+
self.count = Math.max(0, self.count - 1);
|
|
121
|
+
self.texts = Math.max(0, self.texts - texts);
|
|
122
|
+
publishSelf();
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function onMessage(event) {
|
|
126
|
+
const d = event === null || event === void 0 ? void 0 : event.data;
|
|
127
|
+
if (!d || typeof d !== 'object' || d.type !== TRANSLATING_MESSAGE)
|
|
128
|
+
return;
|
|
129
|
+
const p = d.payload || {};
|
|
130
|
+
const key = event.source || 'unknown-frame';
|
|
131
|
+
setSource(key, { count: p.active ? 1 : 0, texts: Number(p.texts) || 0, lang: typeof p.targetLanguage === 'string' ? p.targetLanguage : null });
|
|
132
|
+
// Pass it on when this window is itself inside a frame.
|
|
133
|
+
const all = current();
|
|
134
|
+
postParent({ active: all.active, targetLanguage: all.targetLanguage, texts: all.texts });
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Hear when content is being translated for the first time: requests made in this window and in
|
|
138
|
+
* every app frame embedded in it. The callback gets the combined state now and on every change.
|
|
139
|
+
* Returns an unsubscribe function.
|
|
140
|
+
*
|
|
141
|
+
* ```ts
|
|
142
|
+
* translations.onActivity(({ active, targetLanguage }) => setBanner(active ? targetLanguage : null))
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export function onActivity(cb) {
|
|
146
|
+
const st = shared();
|
|
147
|
+
st.listeners.add(cb);
|
|
148
|
+
if (!st.messageListening && typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
|
|
149
|
+
st.onMessage = onMessage;
|
|
150
|
+
window.addEventListener('message', onMessage);
|
|
151
|
+
st.messageListening = true;
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
cb(current());
|
|
155
|
+
}
|
|
156
|
+
catch ( /* ignore */_a) { /* ignore */ }
|
|
157
|
+
return () => { st.listeners.delete(cb); };
|
|
158
|
+
}
|
|
159
|
+
/** The combined state right now. */
|
|
160
|
+
export function activity() {
|
|
161
|
+
return current();
|
|
162
|
+
}
|
|
163
|
+
/** @internal tests only */
|
|
164
|
+
export function _resetActivity(options = {}) {
|
|
165
|
+
const g = globalThis;
|
|
166
|
+
const old = g[KEY];
|
|
167
|
+
if ((old === null || old === void 0 ? void 0 : old.onMessage) && typeof window !== 'undefined' && typeof window.removeEventListener === 'function')
|
|
168
|
+
window.removeEventListener('message', old.onMessage);
|
|
169
|
+
g[KEY] = fresh();
|
|
170
|
+
if (options.showAfterMs !== undefined)
|
|
171
|
+
g[KEY].showAfterMs = options.showAfterMs;
|
|
172
|
+
}
|
|
173
|
+
// The notice itself, in the language being translated into (the visitor asked for it, so they may not
|
|
174
|
+
// read English). Hosts show it as is; a language not listed gets the English line.
|
|
175
|
+
const TRANSLATING_TEXT = {
|
|
176
|
+
en: 'Translating this page. This only happens the first time.',
|
|
177
|
+
de: 'Diese Seite wird übersetzt. Das passiert nur beim ersten Mal.',
|
|
178
|
+
fr: 'Traduction de la page en cours. Cela n’arrive que la première fois.',
|
|
179
|
+
es: 'Traduciendo esta página. Solo ocurre la primera vez.',
|
|
180
|
+
it: 'Traduzione della pagina in corso. Succede solo la prima volta.',
|
|
181
|
+
pt: 'Traduzindo esta página. Isso só acontece na primeira vez.',
|
|
182
|
+
nl: 'Deze pagina wordt vertaald. Dit gebeurt alleen de eerste keer.',
|
|
183
|
+
pl: 'Trwa tłumaczenie strony. Dzieje się to tylko za pierwszym razem.',
|
|
184
|
+
sv: 'Sidan översätts. Det händer bara första gången.',
|
|
185
|
+
da: 'Siden oversættes. Det sker kun første gang.',
|
|
186
|
+
nb: 'Siden oversettes. Dette skjer bare første gang.',
|
|
187
|
+
no: 'Siden oversettes. Dette skjer bare første gang.',
|
|
188
|
+
fi: 'Sivua käännetään. Tämä tapahtuu vain ensimmäisellä kerralla.',
|
|
189
|
+
tr: 'Sayfa çevriliyor. Bu yalnızca ilk seferde olur.',
|
|
190
|
+
ru: 'Страница переводится. Это происходит только в первый раз.',
|
|
191
|
+
uk: 'Сторінка перекладається. Це відбувається лише першого разу.',
|
|
192
|
+
ar: 'جارٍ ترجمة هذه الصفحة. يحدث هذا في المرة الأولى فقط.',
|
|
193
|
+
he: 'הדף מתורגם. זה קורה רק בפעם הראשונה.',
|
|
194
|
+
ja: 'このページを翻訳しています。初回のみ少々お待ちください。',
|
|
195
|
+
ko: '이 페이지를 번역하는 중입니다. 처음 한 번만 잠시 기다려 주세요.',
|
|
196
|
+
'zh-Hans': '正在翻译此页面,仅首次需要稍候。',
|
|
197
|
+
'zh-Hant': '正在翻譯此頁面,僅首次需要稍候。',
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* The "translating this page" line in the language being translated into, with its text direction.
|
|
201
|
+
* zh-CN / zh-SG → Simplified, zh-TW / zh-HK → Traditional; unknown languages get English.
|
|
202
|
+
*/
|
|
203
|
+
export function translatingMessage(language) {
|
|
204
|
+
const raw = String(language || 'en').trim();
|
|
205
|
+
const lower = raw.toLowerCase();
|
|
206
|
+
let key = TRANSLATING_TEXT[raw] ? raw : '';
|
|
207
|
+
if (!key && lower.startsWith('zh'))
|
|
208
|
+
key = /hant|tw|hk|mo/.test(lower) ? 'zh-Hant' : 'zh-Hans';
|
|
209
|
+
if (!key)
|
|
210
|
+
key = TRANSLATING_TEXT[lower.split('-')[0]] ? lower.split('-')[0] : 'en';
|
|
211
|
+
return { text: TRANSLATING_TEXT[key], lang: key, dir: key === 'ar' || key === 'he' ? 'rtl' : 'ltr' };
|
|
212
|
+
}
|
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[]>`
|
|
@@ -15500,21 +15502,44 @@ Invoke ONE built-in server tool directly — no model in the loop. This is the "
|
|
|
15500
15502
|
**lookup**(collectionId: string,
|
|
15501
15503
|
body: TranslationLookupRequest) → `Promise<TranslationLookupResponse>`
|
|
15502
15504
|
|
|
15505
|
+
**onActivity**(cb: (activity: TranslationActivity) → `void`
|
|
15506
|
+
Hear when content is being translated for the first time, in this window or in any app frame it embeds. Hosts use it to show a "translating this page" notice; apps never have to. Returns an unsubscribe function.
|
|
15507
|
+
|
|
15508
|
+
**translatingMessage**(language: string | null | undefined) → ``
|
|
15509
|
+
The "translating this page" line, in the language being translated into (for a host's banner).
|
|
15510
|
+
|
|
15511
|
+
**activity**() → `TranslationActivity`
|
|
15512
|
+
Whether a first-time translation is under way right now (see onActivity).
|
|
15513
|
+
|
|
15503
15514
|
**resolve**(collectionId: string,
|
|
15504
15515
|
body: TranslationLookupRequest,
|
|
15505
15516
|
options: TranslationResolveOptions = {}) → `Promise<ResolvedTranslationResponse>`
|
|
15517
|
+
Whether a first-time translation is under way right now (see onActivity).
|
|
15506
15518
|
|
|
15507
15519
|
**list**(collectionId: string,
|
|
15508
15520
|
params?: TranslationListParams) → `Promise<TranslationListResponse>`
|
|
15521
|
+
Whether a first-time translation is under way right now (see onActivity).
|
|
15509
15522
|
|
|
15510
15523
|
**get**(collectionId: string,
|
|
15511
15524
|
translationId: string) → `Promise<TranslationRecord>`
|
|
15525
|
+
Whether a first-time translation is under way right now (see onActivity).
|
|
15512
15526
|
|
|
15513
15527
|
**update**(collectionId: string,
|
|
15514
15528
|
translationId: string,
|
|
15515
15529
|
body: TranslationUpdateRequest) → `Promise<TranslationRecord>`
|
|
15530
|
+
Whether a first-time translation is under way right now (see onActivity).
|
|
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.
|
|
15516
15540
|
|
|
15517
15541
|
**clearLocalCache**(collectionId?: string) → `Promise<void>`
|
|
15542
|
+
Admin: undo a person's edit with a fresh machine translation.
|
|
15518
15543
|
|
|
15519
15544
|
### tts
|
|
15520
15545
|
|
package/docs/translations.md
CHANGED
|
@@ -253,6 +253,26 @@ await translations.resolve('collection-123', {
|
|
|
253
253
|
|
|
254
254
|
The SDK derives a deterministic local cache key from `context` so browser-local entries do not collide across different UI surfaces.
|
|
255
255
|
|
|
256
|
+
## "Translating this page" notice (hosts)
|
|
257
|
+
|
|
258
|
+
The first visitor to see content in a new language waits while it is translated. Apps do not need
|
|
259
|
+
to show anything for this: when a `cache-fill` request is still unanswered after about 0.6 s, the
|
|
260
|
+
SDK announces it, and announces again when it settles. Inside a frame it posts
|
|
261
|
+
`{ _smartlinksIframeMessage: true, type: 'smartlinks:translating', payload: { active, targetLanguage, texts } }`
|
|
262
|
+
to the parent. Already-translated content answers well inside the delay, so nothing is announced.
|
|
263
|
+
|
|
264
|
+
Portal and Hub listen once and show a banner:
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
const stop = translations.onActivity(({ active, targetLanguage, texts }) => {
|
|
268
|
+
setBanner(active ? targetLanguage : null)
|
|
269
|
+
})
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
`onActivity` combines this window's own requests with those of every embedded app frame.
|
|
273
|
+
`translations.activity()` returns the state right now. An app that wants its own spinner can use the
|
|
274
|
+
same call.
|
|
275
|
+
|
|
256
276
|
## Hashing Helpers
|
|
257
277
|
|
|
258
278
|
The SDK also exposes the normalization and hashing helpers used by the local cache flow.
|
|
@@ -320,6 +340,23 @@ const updated = await translations.update('collection-123', 'translation-id', {
|
|
|
320
340
|
})
|
|
321
341
|
```
|
|
322
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
|
+
|
|
323
360
|
## Recommended Usage Pattern
|
|
324
361
|
|
|
325
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:
|