@proveanything/smartlinks 2.2.3 → 2.2.4

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.
@@ -25,6 +25,9 @@ export declare function channel(scope: RealtimeScope & {
25
25
  * records, products). Filter by `type` ('product' | 'proof' | 'asset' | 'record' | 'collection' |
26
26
  * 'collection.apps' | 'settings'), `id`, `appId`, `recordType`, `productId`, `proofId`.
27
27
  *
28
+ * A change with no `id` means many things of that type changed (an import): a `{ type, id }` filter
29
+ * hears it too, so check `change.id` before assuming it is yours.
30
+ *
28
31
  * ```ts
29
32
  * const off = realtime.onChange({ collectionId }, { type: "record", appId, recordType: "entry" }, () => refetch())
30
33
  * ```
@@ -194,8 +194,13 @@ export function channel(scope, name) {
194
194
  }
195
195
  function matches(change, filter) {
196
196
  for (const k of ["type", "id", "appId", "recordType", "productId", "proofId", "kind"]) {
197
- if (filter[k] !== undefined && change[k] !== filter[k])
198
- return false;
197
+ if (filter[k] === undefined || change[k] === filter[k])
198
+ continue;
199
+ // A change that names no id is about many things of its type (an import sends one
200
+ // { type: 'product' } in place of thousands): whoever follows one of them by type and id hears it.
201
+ if (k === "id" && change.id == null && filter.type !== undefined)
202
+ continue;
203
+ return false;
199
204
  }
200
205
  return true;
201
206
  }
@@ -206,6 +211,9 @@ function matches(change, filter) {
206
211
  * records, products). Filter by `type` ('product' | 'proof' | 'asset' | 'record' | 'collection' |
207
212
  * 'collection.apps' | 'settings'), `id`, `appId`, `recordType`, `productId`, `proofId`.
208
213
  *
214
+ * A change with no `id` means many things of that type changed (an import): a `{ type, id }` filter
215
+ * hears it too, so check `change.id` before assuming it is yours.
216
+ *
209
217
  * ```ts
210
218
  * const off = realtime.onChange({ collectionId }, { type: "record", appId, recordType: "entry" }, () => refetch())
211
219
  * ```
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 2.2.3 | Generated: 2026-12-02T13:03:18.253Z
3
+ Version: 2.2.4 | Generated: 2026-12-02T15:08:47.460Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -16547,7 +16547,7 @@ Reset rate limit for a user
16547
16547
  One of your app's declared channels (manifest `realtime.channels`). ```ts const draw = realtime.channel({ collectionId, appId }, "draw") const off = draw.subscribe("status", (m) => setStatus(m.data)) await draw.publish("status", { phase: "spinning" }) // if the channel lets this viewer publish ```
16548
16548
 
16549
16549
  **onChange**(scope: RealtimeScope, filter: RealtimeChangeFilter, onChangeFn: (change: RealtimeChangeEvent) → `void`
16550
- Something changed: refetch it. IDs only — never data. Admins of the collection see every change; everyone else sees changes to public things (public app records, products). Filter by `type` ('product' | 'proof' | 'asset' | 'record' | 'collection' | 'collection.apps' | 'settings'), `id`, `appId`, `recordType`, `productId`, `proofId`. ```ts const off = realtime.onChange({ collectionId }, { type: "record", appId, recordType: "entry" }, () => refetch()) ```
16550
+ Something changed: refetch it. IDs only — never data. Admins of the collection see every change; everyone else sees changes to public things (public app records, products). Filter by `type` ('product' | 'proof' | 'asset' | 'record' | 'collection' | 'collection.apps' | 'settings'), `id`, `appId`, `recordType`, `productId`, `proofId`. A change with no `id` means many things of that type changed (an import): a `{ type, id }` filter hears it too, so check `change.id` before assuming it is yours. ```ts const off = realtime.onChange({ collectionId }, { type: "record", appId, recordType: "entry" }, () => refetch()) ```
16551
16551
 
16552
16552
  **onStaffChange**(scope: RealtimeScope & { appId: string }, filter: RealtimeChangeFilter, onChangeFn: (change: RealtimeChangeEvent) → `void`
16553
16553
  Something this APP works on changed: one of its work orders, a container or stock it moved, or one of its own records. For the people who use the app, admins or not: someone hears these when they are in one of the app's user groups (the ones its server functions are limited to, or `realtime.staff` in its manifest), and so does a collection admin. IDs only — refetch through your own API. Types: 'workOrder' (`id`, `appId`), 'container' (`id`, `kind` = its container type), 'stock' (`id` = the container, `productId`), 'record' (`id`, `recordType`). Filter as with `onChange`; an empty filter hears them all. ```ts // A production app's screens refetch when anything on the floor changes. useEffect(() => realtime.onStaffChange({ collectionId, appId }, {}, () => queryClient.invalidateQueries()), [collectionId, appId]) ```
@@ -1,91 +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.
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.
@@ -31,6 +31,10 @@ off()
31
31
  installed, removed or switched), `settings`.
32
32
  - **Filter fields:** `type`, `id`, `appId`, `recordType`, `productId`, `proofId`. Every field you give
33
33
  must match.
34
+ - **Many at once:** a large import doesn't send thousands of product changes. After the first few it
35
+ sends one `{ type: 'product' }` with no `id`, meaning "many products changed". A listener that follows
36
+ one thing, `{ type: 'product', id }`, hears that too (from SDK 2.2.4), since its product may be among
37
+ them. Read again as usual; `change.id` is empty, so don't rely on it.
34
38
  - **Who hears what:**
35
39
  - a collection's **admins** hear every change;
36
40
  - **everyone else** hears changes to public things (public app records, products).
@@ -62,6 +62,7 @@ export interface RealtimeChangeEvent {
62
62
  * and, on an app's staff feed (`onStaffChange`): 'workOrder' | 'container' | 'stock'.
63
63
  */
64
64
  type: string;
65
+ /** The thing that changed. Absent when many of this type changed at once (an import): read them all again. */
65
66
  id?: string;
66
67
  appId?: string;
67
68
  recordType?: string;
@@ -73,7 +74,10 @@ export interface RealtimeChangeEvent {
73
74
  kind?: string;
74
75
  at: number;
75
76
  }
76
- /** Which changes to hear about — every field given must match. */
77
+ /**
78
+ * Which changes to hear about — every field given must match. One exception: with `type` and `id`
79
+ * given, a change of that type that names no id ("many changed") is heard too.
80
+ */
77
81
  export interface RealtimeChangeFilter {
78
82
  type?: string;
79
83
  id?: string;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "2.2.3";
1
+ export declare const SDK_VERSION = "2.2.4";
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.3";
2
+ export const SDK_VERSION = "2.2.4";
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 2.2.3 | Generated: 2026-12-02T13:03:18.253Z
3
+ Version: 2.2.4 | Generated: 2026-12-02T15:08:47.460Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -16547,7 +16547,7 @@ Reset rate limit for a user
16547
16547
  One of your app's declared channels (manifest `realtime.channels`). ```ts const draw = realtime.channel({ collectionId, appId }, "draw") const off = draw.subscribe("status", (m) => setStatus(m.data)) await draw.publish("status", { phase: "spinning" }) // if the channel lets this viewer publish ```
16548
16548
 
16549
16549
  **onChange**(scope: RealtimeScope, filter: RealtimeChangeFilter, onChangeFn: (change: RealtimeChangeEvent) → `void`
16550
- Something changed: refetch it. IDs only — never data. Admins of the collection see every change; everyone else sees changes to public things (public app records, products). Filter by `type` ('product' | 'proof' | 'asset' | 'record' | 'collection' | 'collection.apps' | 'settings'), `id`, `appId`, `recordType`, `productId`, `proofId`. ```ts const off = realtime.onChange({ collectionId }, { type: "record", appId, recordType: "entry" }, () => refetch()) ```
16550
+ Something changed: refetch it. IDs only — never data. Admins of the collection see every change; everyone else sees changes to public things (public app records, products). Filter by `type` ('product' | 'proof' | 'asset' | 'record' | 'collection' | 'collection.apps' | 'settings'), `id`, `appId`, `recordType`, `productId`, `proofId`. A change with no `id` means many things of that type changed (an import): a `{ type, id }` filter hears it too, so check `change.id` before assuming it is yours. ```ts const off = realtime.onChange({ collectionId }, { type: "record", appId, recordType: "entry" }, () => refetch()) ```
16551
16551
 
16552
16552
  **onStaffChange**(scope: RealtimeScope & { appId: string }, filter: RealtimeChangeFilter, onChangeFn: (change: RealtimeChangeEvent) → `void`
16553
16553
  Something this APP works on changed: one of its work orders, a container or stock it moved, or one of its own records. For the people who use the app, admins or not: someone hears these when they are in one of the app's user groups (the ones its server functions are limited to, or `realtime.staff` in its manifest), and so does a collection admin. IDs only — refetch through your own API. Types: 'workOrder' (`id`, `appId`), 'container' (`id`, `kind` = its container type), 'stock' (`id` = the container, `productId`), 'record' (`id`, `recordType`). Filter as with `onChange`; an empty filter hears them all. ```ts // A production app's screens refetch when anything on the floor changes. useEffect(() => realtime.onStaffChange({ collectionId, appId }, {}, () => queryClient.invalidateQueries()), [collectionId, appId]) ```
@@ -1,91 +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.
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.
package/docs/realtime.md CHANGED
@@ -31,6 +31,10 @@ off()
31
31
  installed, removed or switched), `settings`.
32
32
  - **Filter fields:** `type`, `id`, `appId`, `recordType`, `productId`, `proofId`. Every field you give
33
33
  must match.
34
+ - **Many at once:** a large import doesn't send thousands of product changes. After the first few it
35
+ sends one `{ type: 'product' }` with no `id`, meaning "many products changed". A listener that follows
36
+ one thing, `{ type: 'product', id }`, hears that too (from SDK 2.2.4), since its product may be among
37
+ them. Read again as usual; `change.id` is empty, so don't rely on it.
34
38
  - **Who hears what:**
35
39
  - a collection's **admins** hear every change;
36
40
  - **everyone else** hears changes to public things (public app records, products).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proveanything/smartlinks",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",