@proveanything/smartlinks 2.2.0 → 2.2.3
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/dataChanged.d.ts +74 -0
- package/dist/dataChanged.js +162 -0
- package/dist/docs/API_SUMMARY.md +3 -3
- package/dist/docs/caching.md +32 -3
- package/dist/docs/data-changed.md +91 -0
- package/dist/docs/i18n.md +41 -287
- package/dist/docs/iframe-responder.md +11 -0
- package/dist/docs/overview.md +1 -0
- package/dist/docs/realtime.md +6 -0
- package/dist/docs/standard-query.md +12 -3
- package/dist/http.d.ts +6 -3
- package/dist/http.js +48 -19
- package/dist/i18n.d.ts +14 -2
- package/dist/i18n.js +23 -6
- package/dist/iframeResponder.d.ts +7 -0
- package/dist/iframeResponder.js +10 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/API_SUMMARY.md +3 -3
- package/docs/caching.md +32 -3
- package/docs/data-changed.md +91 -0
- package/docs/i18n.md +41 -287
- package/docs/iframe-responder.md +11 -0
- package/docs/overview.md +1 -0
- package/docs/realtime.md +6 -0
- package/docs/standard-query.md +12 -3
- package/package.json +1 -1
package/dist/i18n.d.ts
CHANGED
|
@@ -10,6 +10,12 @@ export interface I18nInitOptions {
|
|
|
10
10
|
catalogs?: Record<string, Catalog>;
|
|
11
11
|
/** The app's source language. Default 'en'. */
|
|
12
12
|
sourceLanguage?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The languages the site has turned on (its collection's languages). Languages are the business's
|
|
15
|
+
* choice: with no language from the host or the page, the browser's is used only when it is one of
|
|
16
|
+
* these; otherwise the app stays in its source language. Not given: never the browser's.
|
|
17
|
+
*/
|
|
18
|
+
languages?: string[];
|
|
13
19
|
}
|
|
14
20
|
/**
|
|
15
21
|
* The text direction for a language: 'rtl' for Arabic, Hebrew, Persian, Urdu and the like, else 'ltr'.
|
|
@@ -19,8 +25,12 @@ export interface I18nInitOptions {
|
|
|
19
25
|
export declare function textDirection(code: string | null | undefined): 'rtl' | 'ltr';
|
|
20
26
|
/** The language the host asked for, in a normal form ('zh-hans' -> 'zh-Hans', 'FR' -> 'fr'). */
|
|
21
27
|
export declare function normalizeLanguage(code: string | null | undefined): string | null;
|
|
22
|
-
/**
|
|
23
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Which language to start in: what the host passed, else the page's, else the browser's when the site
|
|
30
|
+
* has turned that language on (`approved`), else the source. A language the business hasn't chosen is
|
|
31
|
+
* never picked from the browser alone.
|
|
32
|
+
*/
|
|
33
|
+
export declare function detectLanguage(approved?: string[]): string;
|
|
24
34
|
/**
|
|
25
35
|
* Load the source catalog and the current language's. Call once before the first render; safe to
|
|
26
36
|
* call again. Never throws: with nothing found, `t` returns the keys' English or the keys.
|
|
@@ -50,6 +60,8 @@ export declare const format: {
|
|
|
50
60
|
number: (n: number, opts?: Intl.NumberFormatOptions) => string;
|
|
51
61
|
date: (d: Date | string | number, opts?: Intl.DateTimeFormatOptions) => string;
|
|
52
62
|
dateTime: (d: Date | string | number, opts?: Intl.DateTimeFormatOptions) => string;
|
|
63
|
+
/** Minor units as money in the current language: `money(129950, 'EUR')` → "1.299,50 €" in German. */
|
|
64
|
+
money: (minor: number, currency: string) => string;
|
|
53
65
|
};
|
|
54
66
|
/** Forget loaded catalogs and listeners (tests). */
|
|
55
67
|
export declare function _reset(): void;
|
package/dist/i18n.js
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
// Nested keys are read with dots. `{{name}}` is replaced from the values. With `count`, the plural
|
|
29
29
|
// form for the language is picked (`_one`, `_other`, …; Chinese has only `_other`).
|
|
30
30
|
import { readContext } from './context.js';
|
|
31
|
+
import { formatMinor } from './utils/money.js';
|
|
31
32
|
let source = 'en';
|
|
32
33
|
let current = 'en';
|
|
33
34
|
let base = null;
|
|
@@ -94,8 +95,12 @@ function candidates(lang) {
|
|
|
94
95
|
out.push(l);
|
|
95
96
|
return Array.from(new Set(out));
|
|
96
97
|
}
|
|
97
|
-
/**
|
|
98
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Which language to start in: what the host passed, else the page's, else the browser's when the site
|
|
100
|
+
* has turned that language on (`approved`), else the source. A language the business hasn't chosen is
|
|
101
|
+
* never picked from the browser alone.
|
|
102
|
+
*/
|
|
103
|
+
export function detectLanguage(approved) {
|
|
99
104
|
try {
|
|
100
105
|
const fromHost = normalizeLanguage(readContext().lang);
|
|
101
106
|
if (fromHost)
|
|
@@ -106,15 +111,25 @@ export function detectLanguage() {
|
|
|
106
111
|
if (fromPage)
|
|
107
112
|
return fromPage;
|
|
108
113
|
}
|
|
109
|
-
if (typeof navigator !== 'undefined') {
|
|
114
|
+
if (approved && approved.length && typeof navigator !== 'undefined') {
|
|
110
115
|
const fromBrowser = normalizeLanguage(navigator.language);
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
const match = fromBrowser && pickApproved(fromBrowser, approved);
|
|
117
|
+
if (match)
|
|
118
|
+
return match;
|
|
113
119
|
}
|
|
114
120
|
}
|
|
115
121
|
catch ( /* not in a browser */_a) { /* not in a browser */ }
|
|
116
122
|
return source;
|
|
117
123
|
}
|
|
124
|
+
/** The approved language `lang` stands for: exact, else the same base language ("fr-CA" -> "fr"). */
|
|
125
|
+
function pickApproved(lang, approved) {
|
|
126
|
+
const list = approved.map((l) => normalizeLanguage(l)).filter((l) => !!l);
|
|
127
|
+
const exact = list.find((l) => l.toLowerCase() === lang.toLowerCase());
|
|
128
|
+
if (exact)
|
|
129
|
+
return exact;
|
|
130
|
+
const base = lang.toLowerCase().split('-')[0];
|
|
131
|
+
return list.find((l) => l.toLowerCase().split('-')[0] === base) || null;
|
|
132
|
+
}
|
|
118
133
|
/** Mark the page with the language in use (screen readers, fonts), where there is a page. */
|
|
119
134
|
function setPageLanguage(lang) {
|
|
120
135
|
try {
|
|
@@ -177,7 +192,7 @@ export async function init(options = {}) {
|
|
|
177
192
|
const key = normalizeLanguage(lang) || lang;
|
|
178
193
|
supplied.set(key, cat);
|
|
179
194
|
}
|
|
180
|
-
current = normalizeLanguage(options.language) || detectLanguage();
|
|
195
|
+
current = normalizeLanguage(options.language) || detectLanguage(options.languages);
|
|
181
196
|
listen();
|
|
182
197
|
await Promise.all([fetchCatalog(source), current === source ? null : fetchCatalog(current)]);
|
|
183
198
|
setPageLanguage(current);
|
|
@@ -295,6 +310,8 @@ export const format = {
|
|
|
295
310
|
return String(d);
|
|
296
311
|
}
|
|
297
312
|
},
|
|
313
|
+
/** Minor units as money in the current language: `money(129950, 'EUR')` → "1.299,50 €" in German. */
|
|
314
|
+
money: (minor, currency) => formatMinor(minor, currency, current),
|
|
298
315
|
};
|
|
299
316
|
/** Forget loaded catalogs and listeners (tests). */
|
|
300
317
|
export function _reset() {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IframeResponderOptions, CachedData } from './types/iframeResponder.js';
|
|
2
|
+
import type { DataChangedMessage } from './dataChanged.js';
|
|
2
3
|
/**
|
|
3
4
|
* Parent-side iframe responder for SmartLinks microapp embedding.
|
|
4
5
|
*
|
|
@@ -63,6 +64,12 @@ export declare class IframeResponder {
|
|
|
63
64
|
params?: Record<string, string>;
|
|
64
65
|
highlight?: string;
|
|
65
66
|
}): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Tell the app that records changed behind its back (an assistant's change applied, a save in another
|
|
69
|
+
* app): its SDK forgets the reads it kept and its open screen reads again. Leave `changes` out when you
|
|
70
|
+
* can't say what changed. See docs/data-changed.md.
|
|
71
|
+
*/
|
|
72
|
+
dataChanged(message?: DataChangedMessage): void;
|
|
66
73
|
/** True once the app has said it follows `smartlinks:navigate`. */
|
|
67
74
|
get isNavigable(): boolean;
|
|
68
75
|
/**
|
package/dist/iframeResponder.js
CHANGED
|
@@ -5,6 +5,7 @@ import * as cache from './cache.js';
|
|
|
5
5
|
import { collection } from './api/collection.js';
|
|
6
6
|
import { getBaseURL, hasAuthCredentials } from './http.js';
|
|
7
7
|
import { trackTranslation } from './translationActivity.js';
|
|
8
|
+
import { postDataChanged } from './dataChanged.js';
|
|
8
9
|
/**
|
|
9
10
|
* Parent-side iframe responder for SmartLinks microapp embedding.
|
|
10
11
|
*
|
|
@@ -110,6 +111,15 @@ export class IframeResponder {
|
|
|
110
111
|
return false;
|
|
111
112
|
}
|
|
112
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Tell the app that records changed behind its back (an assistant's change applied, a save in another
|
|
116
|
+
* app): its SDK forgets the reads it kept and its open screen reads again. Leave `changes` out when you
|
|
117
|
+
* can't say what changed. See docs/data-changed.md.
|
|
118
|
+
*/
|
|
119
|
+
dataChanged(message = {}) {
|
|
120
|
+
var _a;
|
|
121
|
+
postDataChanged((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, message);
|
|
122
|
+
}
|
|
113
123
|
/** True once the app has said it follows `smartlinks:navigate`. */
|
|
114
124
|
get isNavigable() {
|
|
115
125
|
return this.navigable;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export { readContext } from "./context.js";
|
|
|
6
6
|
export * as i18n from "./i18n.js";
|
|
7
7
|
export * as adminViews from "./adminViews.js";
|
|
8
8
|
export type { NavigateRequest, NavigateTarget, OpenAppRequest, Destination, DestinationInfo, DestinationAbout, OpenParams, OpenResult } from "./adminViews.js";
|
|
9
|
+
export { onDataChanged, postDataChanged } from "./dataChanged.js";
|
|
10
|
+
export type { DataChange, DataChangedEvent, DataChangedMessage } from "./dataChanged.js";
|
|
9
11
|
export { widgetStyleVars, widgetStyleControls, readableOn, WIDGET_STYLE_VARS } from "./widgetStyle.js";
|
|
10
12
|
export type { WidgetStyling } from "./widgetStyle.js";
|
|
11
13
|
export type { SmartLinksContext } from "./context.js";
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,8 @@ import * as i18n_1 from "./i18n.js";
|
|
|
11
11
|
export { i18n_1 as i18n };
|
|
12
12
|
import * as adminViews_1 from "./adminViews.js";
|
|
13
13
|
export { adminViews_1 as adminViews };
|
|
14
|
+
// Data changed: the host tells an open screen to read again (docs/data-changed.md)
|
|
15
|
+
export { onDataChanged, postDataChanged } from "./dataChanged.js";
|
|
14
16
|
export { widgetStyleVars, widgetStyleControls, readableOn, WIDGET_STYLE_VARS } from "./widgetStyle.js";
|
|
15
17
|
import * as cache_1 from './cache.js';
|
|
16
18
|
export { cache_1 as cache };
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.2.
|
|
1
|
+
export declare const SDK_VERSION = "2.2.3";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by scripts/write-version.mjs from package.json. Do not edit.
|
|
2
|
-
export const SDK_VERSION = "2.2.
|
|
2
|
+
export const SDK_VERSION = "2.2.3";
|
package/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 2.2.
|
|
3
|
+
Version: 2.2.3 | Generated: 2026-12-02T13:03:18.253Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -260,7 +260,7 @@ Returns true if the SDK currently has any auth credential set (bearer token or A
|
|
|
260
260
|
serveStaleOnOffline?: boolean
|
|
261
261
|
clearOnPageLoad?: boolean
|
|
262
262
|
}) → `void`
|
|
263
|
-
Configure the SDK's built-in in-memory GET cache. The cache is transparent — it sits inside the HTTP layer and requires no changes to your existing API calls.
|
|
263
|
+
Configure the SDK's built-in in-memory GET cache. The cache is transparent — it sits inside the HTTP layer and requires no changes to your existing API calls. Public GET requests benefit automatically. Admin GETs (`/admin/...`) are never kept, whatever is set here: see docs/caching.md. Per-resource rules (collections/products → 1 h, proofs → 30 s, etc.) override this value. in-memory only (`'none'`, default). Ignored in Node.js. fallback, from the original fetch time (default: 7 days). `SmartlinksOfflineError` with stale data instead of propagating the network error. caches on page load/refresh. IndexedDB persists for offline. ```ts // Enable IndexedDB persistence for offline support configureSdkCache({ persistence: 'indexeddb' }) // Disable cache entirely in test environments configureSdkCache({ enabled: false }) // Keep caches across page refreshes (not recommended for production) configureSdkCache({ clearOnPageLoad: false }) ```
|
|
264
264
|
|
|
265
265
|
**invalidateCache**(urlPattern?: string, options?: InvalidateCacheOptions) → `void`
|
|
266
266
|
Manually invalidate entries in the SDK's GET cache. Note: the GET cache is **in-memory, per page load** (with an optional L2 IndexedDB layer when persistence is enabled) — it does not persist across reloads unless you opt into persistence, so it rarely needs disabling "for correctness". *contains* this string is removed). With `{ exact: true }`, matches the path precisely. Omit to wipe the entire cache. ```ts invalidateCache() // clear everything invalidateCache('/collection/abc123') // that collection AND everything under it invalidateCache('/collection/abc123', { exact: true }) // ONLY that collection entry invalidateCache('/products/') // all canonical plural product responses ```
|
|
@@ -271,7 +271,7 @@ Manually invalidate entries in the SDK's GET cache. Note: the GET cache is **in-
|
|
|
271
271
|
Upload a FormData payload via proxy with progress events using chunked postMessage. Parent is expected to implement the counterpart protocol.
|
|
272
272
|
|
|
273
273
|
**request**(path: string) → `Promise<T>`
|
|
274
|
-
Internal helper that performs a GET request to `${baseURL}${path}`, injecting headers for apiKey or bearerToken if present. Cache pipeline (when caching is not skipped): L1 hit → return from memory (no I/O) L2 hit → return from IndexedDB, promote to L1 (no network) Miss → fetch from network, store in L1 + L2 Offline → serve stale L2 entry via SmartlinksOfflineError (if persistence enabled) Concurrent identical GETs share one in-flight promise (deduplication). Node-safe: IndexedDB calls are no-ops when IDB is unavailable.
|
|
274
|
+
Internal helper that performs a GET request to `${baseURL}${path}`, injecting headers for apiKey or bearerToken if present. Cache pipeline (when caching is not skipped): L1 hit → return from memory (no I/O) L2 hit → return from IndexedDB, promote to L1 (no network) Miss → fetch from network, store in L1 + L2 Offline → serve stale L2 entry via SmartlinksOfflineError (if persistence enabled) Admin paths (`/admin/...`) are never kept (see isAdminPath): every call goes to the network. Concurrent identical GETs share one in-flight promise (deduplication), admin ones included. Node-safe: IndexedDB calls are no-ops when IDB is unavailable.
|
|
275
275
|
|
|
276
276
|
**post**(path: string,
|
|
277
277
|
body: any,
|
package/docs/caching.md
CHANGED
|
@@ -23,7 +23,7 @@ This ensures that **page refreshes always fetch fresh data from the server**, wh
|
|
|
23
23
|
### How It Works
|
|
24
24
|
|
|
25
25
|
1. **During browsing (same page load)**:
|
|
26
|
-
- API requests are cached in memory and sessionStorage
|
|
26
|
+
- Public API requests are cached in memory and sessionStorage (admin requests never are, see below)
|
|
27
27
|
- Subsequent identical requests serve from cache (fast!)
|
|
28
28
|
- TTL rules determine cache freshness (30s - 1h depending on resource)
|
|
29
29
|
|
|
@@ -99,9 +99,35 @@ configureSdkCache({
|
|
|
99
99
|
- **Only used as offline fallback**, not for normal requests
|
|
100
100
|
- ~50MB+ quota
|
|
101
101
|
|
|
102
|
+
## Admin reads are never kept
|
|
103
|
+
|
|
104
|
+
Since 2.2.2, a GET on an admin path (`/admin/...`) always goes to the network. Its answer is not kept in
|
|
105
|
+
memory and not written to IndexedDB, whatever `configureSdkCache` says.
|
|
106
|
+
|
|
107
|
+
Why: an admin screen is where records change, and not only through your page. Another app in another
|
|
108
|
+
frame, the assistant, or another person may have saved since you last read. Each frame has its own cache
|
|
109
|
+
and a write only forgets reads of its own address, so a kept admin answer showed old data. Worse, code
|
|
110
|
+
that reads a record, changes part of it and saves the whole wrote the old data back over the newer.
|
|
111
|
+
|
|
112
|
+
What this means for an admin app:
|
|
113
|
+
|
|
114
|
+
- `products.get(collectionId, productId, true)`, `proof.get(..., true)`, `appConfiguration.getConfig({ admin: true })`
|
|
115
|
+
and every other admin read return what the server has now.
|
|
116
|
+
- You no longer need `invalidateCache(...)` before a read that feeds a save or fills an edit form. Calls
|
|
117
|
+
already in your code are harmless.
|
|
118
|
+
- Identical admin GETs asked at the same moment still share one network call, so several components
|
|
119
|
+
mounting together do not multiply requests.
|
|
120
|
+
- Your own page state is still yours: a query library's `staleTime`, or a form filled once on load, will
|
|
121
|
+
show what it loaded until you re-read. Re-read before a save that replaces a whole record.
|
|
122
|
+
- To hear that a record changed behind your page's back (the assistant applied a change, another app
|
|
123
|
+
saved), use `onDataChanged`: see `docs/data-changed.md`. The SDK forgets the reads it kept for what
|
|
124
|
+
changed before it tells you.
|
|
125
|
+
|
|
126
|
+
Public reads (`/public/...`) keep the rules below.
|
|
127
|
+
|
|
102
128
|
## TTL Rules
|
|
103
129
|
|
|
104
|
-
Different API resources have different cache lifetimes:
|
|
130
|
+
Different public API resources have different cache lifetimes:
|
|
105
131
|
|
|
106
132
|
| Resource | TTL | Reason |
|
|
107
133
|
|----------|-----|--------|
|
|
@@ -110,7 +136,10 @@ Different API resources have different cache lifetimes:
|
|
|
110
136
|
| `/product/*` | 1 hour | Products are relatively stable |
|
|
111
137
|
| `/variant/*` | 1 hour | Variants rarely change |
|
|
112
138
|
| `/collection/*` | 1 hour | Collections are stable |
|
|
113
|
-
| Everything else |
|
|
139
|
+
| Everything else | 15 seconds | Default safety |
|
|
140
|
+
|
|
141
|
+
Never kept, on any path: every `/admin/...` read (above), sign-in and account calls, `/me` calls, bookings,
|
|
142
|
+
user groups, option pickers, tag ranges, realtime tokens and a collection's translation revision.
|
|
114
143
|
|
|
115
144
|
## Manual Cache Control
|
|
116
145
|
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Data changed: an open screen reads again
|
|
2
|
+
|
|
3
|
+
Since 2.2.3.
|
|
4
|
+
|
|
5
|
+
An admin screen is not the only thing that changes records. The assistant applies a change, another app
|
|
6
|
+
saves, another person edits. The screen that is open keeps showing what it loaded, and the person has to
|
|
7
|
+
reload to see the change. **Data changed** is the host telling the app, so it can read again.
|
|
8
|
+
|
|
9
|
+
It is one message, host to app:
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
{ type: 'smartlinks:data-changed', collectionId: 'acme', changes: [{ type: 'product', id: 'p_1', status: 'updated' }], source: 'assistant' }
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Ids only, never data. The app reads again through the normal API, with the normal permissions.
|
|
16
|
+
|
|
17
|
+
## In an app
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import * as SL from '@proveanything/smartlinks'
|
|
21
|
+
|
|
22
|
+
useEffect(() => SL.onDataChanged((e) => {
|
|
23
|
+
if (e.collectionId && e.collectionId !== collectionId) return
|
|
24
|
+
if (e.touches({ type: 'product' })) queryClient.invalidateQueries({ queryKey: ['products'] })
|
|
25
|
+
if (e.touches({ type: 'product', id: productId })) queryClient.invalidateQueries({ queryKey: ['product', collectionId, productId] })
|
|
26
|
+
}), [collectionId, productId])
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- `SL.onDataChanged(listener)` returns a function that stops listening. It does nothing outside a frame.
|
|
30
|
+
- Before your listener runs, the SDK has already forgotten the reads it kept for what changed, so the
|
|
31
|
+
next read returns what the server has now. This happens even in an app that never calls `onDataChanged`.
|
|
32
|
+
- `e.changes` is what changed. It is **empty when the host can't say**: treat everything you show from
|
|
33
|
+
the collection as possibly changed.
|
|
34
|
+
- `e.touches({ type, id })` answers "might this be about my record?". It is true when a change matches
|
|
35
|
+
every field you give, and always true when `e.changes` is empty.
|
|
36
|
+
- `e.source` is who made the change when the host knows (`'assistant'`, `'app'`, `'person'`).
|
|
37
|
+
|
|
38
|
+
### A form the person is filling in
|
|
39
|
+
|
|
40
|
+
Reading again must not throw away typing.
|
|
41
|
+
|
|
42
|
+
- **Untouched form:** fill it again from the new record.
|
|
43
|
+
- **Form with changes in it:** keep what the person typed. Say plainly that the record was changed
|
|
44
|
+
elsewhere, and offer to load the new version. Do not save the old copy over the new one without asking.
|
|
45
|
+
|
|
46
|
+
Compare the record you loaded with the one you just read (its `updatedAt`, or the fields the form shows)
|
|
47
|
+
before saying anything: "something changed" is not always about the record on screen.
|
|
48
|
+
|
|
49
|
+
### One change word per kind of record
|
|
50
|
+
|
|
51
|
+
`type` uses the same words as realtime changes (`docs/realtime.md`): `product`, `proof`, `asset`, `record`,
|
|
52
|
+
`collection`, `collection.apps`, `settings`. A host may also send its own words for other records
|
|
53
|
+
(`contact`, `appConfig`). `id` is the record's id; `productId`, `proofId`, `appId` and `recordType` say
|
|
54
|
+
where it lives when that helps.
|
|
55
|
+
|
|
56
|
+
## In a host
|
|
57
|
+
|
|
58
|
+
Send it after a change the app did not make itself.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
// Any host
|
|
62
|
+
SL.postDataChanged(iframe.contentWindow, { collectionId, changes: [{ type: 'product', id }], source: 'assistant' })
|
|
63
|
+
|
|
64
|
+
// With IframeResponder
|
|
65
|
+
responder.dataChanged({ collectionId, changes: [{ type: 'product', id }] })
|
|
66
|
+
|
|
67
|
+
// When you can't say what changed
|
|
68
|
+
SL.postDataChanged(iframe.contentWindow, { collectionId })
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Studio sends it to every open app frame when an assistant change set is applied or undone, when the
|
|
72
|
+
assistant finishes a step that writes, and when its turn ends.
|
|
73
|
+
|
|
74
|
+
## What it is not
|
|
75
|
+
|
|
76
|
+
- It is not the realtime feed. `SL.realtime.onChange` (`docs/realtime.md`) is the server telling a page
|
|
77
|
+
that something changed, over a live connection. Data changed is the host passing a change it already
|
|
78
|
+
knows about into a frame, with no connection of the app's own. A host that listens to the realtime
|
|
79
|
+
feed can pass those changes on with the same message, so an app needs only `onDataChanged`.
|
|
80
|
+
- It does not carry data and it is not a save. Nothing is written by sending or hearing it.
|
|
81
|
+
|
|
82
|
+
## What the SDK forgets
|
|
83
|
+
|
|
84
|
+
| The host says | The SDK forgets |
|
|
85
|
+
|---|---|
|
|
86
|
+
| Only products and proofs changed | Everything kept under that collection's products (the product, its lists, its proofs) |
|
|
87
|
+
| Anything else, or nothing specific | Everything kept for that collection |
|
|
88
|
+
| No collection given | Everything kept |
|
|
89
|
+
|
|
90
|
+
Admin reads are never kept in the first place (`docs/caching.md`), so this matters for public reads an
|
|
91
|
+
admin screen makes, and for apps on an SDK before 2.2.2.
|