@proveanything/smartlinks 2.1.29 → 2.1.30

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.
@@ -1,9 +1,24 @@
1
+ import type { TranslationActivity } from '../translationActivity.js';
1
2
  import type { ResolvedTranslationResponse, TranslationHashOptions, TranslationListParams, TranslationListResponse, TranslationLookupRequest, TranslationLookupResponse, TranslationRecord, TranslationResolveOptions, TranslationUpdateRequest } from '../types/translations.js';
2
3
  export declare namespace translations {
3
4
  function hashText(text: string, options?: TranslationHashOptions): Promise<string>;
4
5
  function hashTexts(texts: string[], options?: TranslationHashOptions): Promise<string[]>;
5
6
  function normalizeText(text: string, options?: TranslationHashOptions): string;
6
7
  function lookup(collectionId: string, body: TranslationLookupRequest): Promise<TranslationLookupResponse>;
8
+ /**
9
+ * Hear when content is being translated for the first time, in this window or in any app frame
10
+ * it embeds. Hosts use it to show a "translating this page" notice; apps never have to.
11
+ * Returns an unsubscribe function.
12
+ */
13
+ function onActivity(cb: (activity: TranslationActivity) => void): () => void;
14
+ /** The "translating this page" line, in the language being translated into (for a host's banner). */
15
+ function translatingMessage(language: string | null | undefined): {
16
+ text: string;
17
+ lang: string;
18
+ dir: 'ltr' | 'rtl';
19
+ };
20
+ /** Whether a first-time translation is under way right now (see onActivity). */
21
+ function activity(): TranslationActivity;
7
22
  function resolve(collectionId: string, body: TranslationLookupRequest, options?: TranslationResolveOptions): Promise<ResolvedTranslationResponse>;
8
23
  function list(collectionId: string, params?: TranslationListParams): Promise<TranslationListResponse>;
9
24
  function get(collectionId: string, translationId: string): Promise<TranslationRecord>;
@@ -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)
@@ -65,9 +66,40 @@ export var translations;
65
66
  async function lookup(collectionId, body) {
66
67
  const path = `/public/collection/${encodeURIComponent(collectionId)}/translations/lookup`;
67
68
  const normalized = normalizeLookupRequest(body);
68
- return post(path, normalized.requestBody);
69
+ // A request that may create translations can take a while the first time: say so, so a host
70
+ // (Portal, Hub) can show "translating…" without the app doing anything (translationActivity.ts).
71
+ // Through the parent (proxyMode), the host's IframeResponder counts it instead, so apps built on
72
+ // older SDKs are covered too and nothing is counted twice.
73
+ const settle = normalized.mode === 'cache-fill' && !isProxyEnabled() && !sameLanguage(normalized.sourceLanguage, normalized.targetLanguage)
74
+ ? trackTranslation(normalized.targetLanguage, normalized.texts.length)
75
+ : null;
76
+ try {
77
+ return await post(path, normalized.requestBody);
78
+ }
79
+ finally {
80
+ settle === null || settle === void 0 ? void 0 : settle();
81
+ }
69
82
  }
70
83
  translations.lookup = lookup;
84
+ /**
85
+ * Hear when content is being translated for the first time, in this window or in any app frame
86
+ * it embeds. Hosts use it to show a "translating this page" notice; apps never have to.
87
+ * Returns an unsubscribe function.
88
+ */
89
+ function onActivity(cb) {
90
+ return onTranslationActivity(cb);
91
+ }
92
+ translations.onActivity = onActivity;
93
+ /** The "translating this page" line, in the language being translated into (for a host's banner). */
94
+ function translatingMessage(language) {
95
+ return translatingLine(language);
96
+ }
97
+ translations.translatingMessage = translatingMessage;
98
+ /** Whether a first-time translation is under way right now (see onActivity). */
99
+ function activity() {
100
+ return translationActivity();
101
+ }
102
+ translations.activity = activity;
71
103
  async function resolve(collectionId, body, options = {}) {
72
104
  var _a, _b, _c;
73
105
  const normalized = normalizeLookupRequest(body);
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 2.1.29 | Generated: 2026-11-20T10:17:06.171Z
3
+ Version: 2.1.30 | Generated: 2026-11-20T10:29:26.751Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -15500,21 +15500,35 @@ Invoke ONE built-in server tool directly — no model in the loop. This is the "
15500
15500
  **lookup**(collectionId: string,
15501
15501
  body: TranslationLookupRequest) → `Promise<TranslationLookupResponse>`
15502
15502
 
15503
+ **onActivity**(cb: (activity: TranslationActivity) → `void`
15504
+ 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.
15505
+
15506
+ **translatingMessage**(language: string | null | undefined) → ``
15507
+ The "translating this page" line, in the language being translated into (for a host's banner).
15508
+
15509
+ **activity**() → `TranslationActivity`
15510
+ Whether a first-time translation is under way right now (see onActivity).
15511
+
15503
15512
  **resolve**(collectionId: string,
15504
15513
  body: TranslationLookupRequest,
15505
15514
  options: TranslationResolveOptions = {}) → `Promise<ResolvedTranslationResponse>`
15515
+ Whether a first-time translation is under way right now (see onActivity).
15506
15516
 
15507
15517
  **list**(collectionId: string,
15508
15518
  params?: TranslationListParams) → `Promise<TranslationListResponse>`
15519
+ Whether a first-time translation is under way right now (see onActivity).
15509
15520
 
15510
15521
  **get**(collectionId: string,
15511
15522
  translationId: string) → `Promise<TranslationRecord>`
15523
+ Whether a first-time translation is under way right now (see onActivity).
15512
15524
 
15513
15525
  **update**(collectionId: string,
15514
15526
  translationId: string,
15515
15527
  body: TranslationUpdateRequest) → `Promise<TranslationRecord>`
15528
+ Whether a first-time translation is under way right now (see onActivity).
15516
15529
 
15517
15530
  **clearLocalCache**(collectionId?: string) → `Promise<void>`
15531
+ Whether a first-time translation is under way right now (see onActivity).
15518
15532
 
15519
15533
  ### tts
15520
15534
 
@@ -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.
@@ -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
- const fetchResponse = await fetch(fullUrl, fetchOptions);
544
- const responseData = await fetchResponse.json().catch(() => null);
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";
@@ -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
+ }
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 2.1.29 | Generated: 2026-11-20T10:17:06.171Z
3
+ Version: 2.1.30 | Generated: 2026-11-20T10:29:26.751Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -15500,21 +15500,35 @@ Invoke ONE built-in server tool directly — no model in the loop. This is the "
15500
15500
  **lookup**(collectionId: string,
15501
15501
  body: TranslationLookupRequest) → `Promise<TranslationLookupResponse>`
15502
15502
 
15503
+ **onActivity**(cb: (activity: TranslationActivity) → `void`
15504
+ 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.
15505
+
15506
+ **translatingMessage**(language: string | null | undefined) → ``
15507
+ The "translating this page" line, in the language being translated into (for a host's banner).
15508
+
15509
+ **activity**() → `TranslationActivity`
15510
+ Whether a first-time translation is under way right now (see onActivity).
15511
+
15503
15512
  **resolve**(collectionId: string,
15504
15513
  body: TranslationLookupRequest,
15505
15514
  options: TranslationResolveOptions = {}) → `Promise<ResolvedTranslationResponse>`
15515
+ Whether a first-time translation is under way right now (see onActivity).
15506
15516
 
15507
15517
  **list**(collectionId: string,
15508
15518
  params?: TranslationListParams) → `Promise<TranslationListResponse>`
15519
+ Whether a first-time translation is under way right now (see onActivity).
15509
15520
 
15510
15521
  **get**(collectionId: string,
15511
15522
  translationId: string) → `Promise<TranslationRecord>`
15523
+ Whether a first-time translation is under way right now (see onActivity).
15512
15524
 
15513
15525
  **update**(collectionId: string,
15514
15526
  translationId: string,
15515
15527
  body: TranslationUpdateRequest) → `Promise<TranslationRecord>`
15528
+ Whether a first-time translation is under way right now (see onActivity).
15516
15529
 
15517
15530
  **clearLocalCache**(collectionId?: string) → `Promise<void>`
15531
+ Whether a first-time translation is under way right now (see onActivity).
15518
15532
 
15519
15533
  ### tts
15520
15534
 
@@ -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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proveanything/smartlinks",
3
- "version": "2.1.29",
3
+ "version": "2.1.30",
4
4
  "description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",