@storystick/preview 0.2.0-rc.2 → 0.2.0-rc.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.
package/PUBLIC-API.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @storystick/preview API contract
2
2
 
3
- Install this candidate explicitly with `@storystick/preview@0.2.0-rc.2` after registry bootstrap and publication. This repository alone does not make the candidate or beta channel available on npm.
3
+ Install this candidate explicitly with `@storystick/preview@0.2.0-rc.4` after registry bootstrap and publication. This repository alone does not make the candidate or beta channel available on npm.
4
4
 
5
- Version 0.2.0-rc.2, cohort `sdk-0.2.0-rc.2`. ESM distribution; no CommonJS or universal Edge compatibility is promised.
5
+ Version 0.2.0-rc.4, cohort `sdk-0.2.0-rc.4`. ESM distribution; no CommonJS or universal Edge compatibility is promised.
6
6
 
7
7
  This package supports the integration facades; installing it directly is an advanced use. Reserved contracts are required between SDK packages and must be upgraded with the same cohort. Their public export paths do not promise independent stability.
8
8
 
@@ -49,7 +49,7 @@ This package supports the integration facades; installing it directly is an adva
49
49
  | `./provenance/render-context` | Reserved SDK contract |
50
50
  | `./provenance/slice-model` | Reserved SDK contract |
51
51
 
52
- The qualified toolchain is Node 24.19.0 and pnpm 9.15.9. Next uses App Router 15.5.28, Sharp 0.35.5 and React/React DOM 19.2.8; Astro uses 7.4.4 with the Node adapter 11.1.9. Browser delivery is verified by bundling; hosted Preview activation and cross-browser behavior require the staging manual check. Source/CLI are Node tools, server entries belong on the server, and browser entries must never receive a server API key.
52
+ Supported consumer Node versions: `^22.13.0 || ^24.19.0`. The release build toolchain remains Node 24.19.0 and pnpm 9.15.9. Next uses App Router 15.5.28, Sharp 0.35.5 and React/React DOM 19.2.8; Astro uses 7.4.4 with the Node adapter 11.1.9. Browser delivery is verified by bundling; hosted Preview activation and cross-browser behavior require the staging manual check. Source/CLI are Node tools, server entries belong on the server, and browser entries must never receive a server API key.
53
53
 
54
54
  This is a support/tooling contract. It does not independently grant project access or permission to perform effects.
55
55
 
package/README.md CHANGED
@@ -39,5 +39,7 @@ early provenance script, and suspends its bindings across pagehide/session chang
39
39
  ## Candidate distribution contract
40
40
 
41
41
  See [PUBLIC-API.md](./PUBLIC-API.md) for supported entries, reserved SDK contracts,
42
- the qualified runtime matrix and the candidate cohort. Upgrade Storystick
43
- packages together.
42
+ the qualified runtime matrix and the candidate cohort. Keep communicating
43
+ Preview contracts compatible. Independent changes can use the
44
+ [targeted package release path](../../release/README.md#prepare-only-the-required-scope);
45
+ do not republish every package solely because one adapter changed.
package/dist/.source-hash CHANGED
@@ -1 +1 @@
1
- a5f163aae4bf2733892f4674626e581304e6173491f17c8ccdfea4886b0fa0a9
1
+ 2860ff9dd781c6c748e99446abe4586964283410949a77842883c7b6dc5f5604
@@ -1,3 +1,4 @@
1
+ import { decodePreviewProvenanceText, encodePreviewProvenanceText } from '@storystick/types/internal/preview-provenance';
1
2
  import { PREVIEW_LIVE_QUERY_MAX_QUERIES, PREVIEW_NAMESPACE, PREVIEW_PROTOCOL_VERSION, validatePreviewEnvelope, } from '@storystick/transport-allowlist';
2
3
  import { estimatePreviewPayloadBytes, recordPreviewPerfMetric, } from './perf-metrics.js';
3
4
  import { createPreviewRequestId } from './request-id.js';
@@ -94,9 +95,15 @@ export function createPreviewLiveQueryOverlayRuntime(options = {}) {
94
95
  return;
95
96
  const hadProjection = slot.projection !== null;
96
97
  slot.receiptId = receiptId;
97
- slot.projection = null;
98
- if (hadProjection)
99
- notify(slot);
98
+ // A receipt refresh does not change this query/context identity. Keep
99
+ // the already received rendering while Studio reauthorizes new sends;
100
+ // otherwise an older confirmed read briefly replaces a newer edit.
101
+ // Losing the receipt, capability, context or final retain still clears it.
102
+ if (receiptId === null) {
103
+ slot.projection = null;
104
+ if (hadProjection)
105
+ notify(slot);
106
+ }
100
107
  if (receiptId !== null)
101
108
  sendRegister(slot);
102
109
  },
@@ -323,6 +330,10 @@ function updateProjectedPath(root, segments, entry) {
323
330
  return root;
324
331
  if (tail.length === 0) {
325
332
  const hasCurrent = Object.prototype.hasOwnProperty.call(root, head);
333
+ // Model sidecars are keyed by authored path. Moving/replacing modeled
334
+ // slices needs a confirmed read with matching sidecars, not a field overlay.
335
+ if (modelReferences(root[head]) !== modelReferences(entry.present ? entry.value : undefined))
336
+ return root;
326
337
  if (!entry.present) {
327
338
  if (!hasCurrent)
328
339
  return root;
@@ -332,7 +343,7 @@ function updateProjectedPath(root, segments, entry) {
332
343
  }
333
344
  if (hasCurrent && Object.is(root[head], entry.value))
334
345
  return root;
335
- return { ...root, [head]: entry.value };
346
+ return { ...root, [head]: carryTextAddresses(root[head], entry.value) };
336
347
  }
337
348
  const current = root[head];
338
349
  if (!isRecord(current) && !entry.present)
@@ -343,3 +354,54 @@ function updateProjectedPath(root, segments, entry) {
343
354
  function isRecord(value) {
344
355
  return value !== null && typeof value === 'object' && !Array.isArray(value);
345
356
  }
357
+ function modelReferences(value) {
358
+ const references = [];
359
+ const visit = (item, path) => {
360
+ if (Array.isArray(item))
361
+ item.forEach((child, index) => visit(child, `${path}[${index}]`));
362
+ else if (isRecord(item)) {
363
+ if (typeof item._model === 'string')
364
+ references.push([path, item._key, item._type, item._model, item._variation]);
365
+ for (const key of Object.keys(item).sort())
366
+ visit(item[key], `${path}.${key}`);
367
+ }
368
+ };
369
+ visit(value, '');
370
+ return JSON.stringify(references);
371
+ }
372
+ /** Retain an existing complete-field edit address, never infer one for new data.
373
+ * Array items must keep their authored key and type; indexes are not identities. */
374
+ function carryTextAddresses(previous, next) {
375
+ if (typeof previous === 'string' && typeof next === 'string') {
376
+ const { segments } = decodePreviewProvenanceText(previous);
377
+ const segment = segments.length === 1 ? segments[0] : undefined;
378
+ return segment?.markerStart === 0 && segment.markerEnd === previous.length
379
+ ? encodePreviewProvenanceText(segment.markerId, decodePreviewProvenanceText(next).text)
380
+ : next;
381
+ }
382
+ if (Array.isArray(previous) && Array.isArray(next)) {
383
+ const keyOf = (value) => isRecord(value) && typeof value._key === 'string'
384
+ ? JSON.stringify([value._key, value._type ?? null]) : null;
385
+ const items = new Map();
386
+ const ambiguous = new Set();
387
+ for (const item of previous) {
388
+ const key = keyOf(item);
389
+ if (key === null)
390
+ continue;
391
+ if (items.has(key))
392
+ ambiguous.add(key);
393
+ items.set(key, item);
394
+ }
395
+ return next.map(item => {
396
+ const key = keyOf(item);
397
+ return key !== null && !ambiguous.has(key) ? carryTextAddresses(items.get(key), item) : item;
398
+ });
399
+ }
400
+ if (isRecord(previous) && isRecord(next)) {
401
+ // A replacement model/variation has different field ownership.
402
+ if (previous._type !== next._type || previous._model !== next._model || previous._variation !== next._variation)
403
+ return next;
404
+ return Object.fromEntries(Object.entries(next).map(([key, value]) => [key, carryTextAddresses(previous[key], value)]));
405
+ }
406
+ return next;
407
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storystick/preview",
3
- "version": "0.2.0-rc.2",
3
+ "version": "0.2.0-rc.4",
4
4
  "license": "FSL-1.1-MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -181,9 +181,9 @@
181
181
  },
182
182
  "dependencies": {
183
183
  "convex": "1.42.3",
184
- "@storystick/client": "0.2.0-rc.2",
185
- "@storystick/transport-allowlist": "0.1.0-rc.2",
186
- "@storystick/types": "0.1.0-rc.2"
184
+ "@storystick/client": "0.2.0-rc.4",
185
+ "@storystick/types": "0.1.0-rc.3",
186
+ "@storystick/transport-allowlist": "0.1.0-rc.3"
187
187
  },
188
188
  "devDependencies": {
189
189
  "fake-indexeddb": "^6.2.5",
@@ -193,7 +193,7 @@
193
193
  "@types/node": "^22.13.10"
194
194
  },
195
195
  "engines": {
196
- "node": ">=24.19.0 <25"
196
+ "node": "^22.13.0 || ^24.19.0"
197
197
  },
198
198
  "repository": {
199
199
  "type": "git",