@storystick/types 0.1.0-rc.1 → 0.1.0-rc.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/PUBLIC-API.md +3 -3
- package/README.md +4 -2
- package/dist/content-plane-lens.d.ts +44 -0
- package/dist/content-plane-lens.js +56 -0
- package/dist/content-shape.d.ts +7 -0
- package/dist/content-shape.js +14 -0
- package/dist/delivery-contract.d.ts +35 -0
- package/dist/delivery-contract.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/public-delivery.d.ts +27 -4
- package/dist/public-delivery.js +23 -2
- package/dist/public-endpoints.d.ts +14 -1
- package/dist/public-endpoints.js +56 -1
- package/dist/public-read.d.ts +58 -0
- package/dist/public-read.js +56 -0
- package/dist/route-data.d.ts +12 -0
- package/dist/route-data.js +120 -0
- package/package.json +2 -2
package/PUBLIC-API.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @storystick/types API contract
|
|
2
2
|
|
|
3
|
-
Install this candidate explicitly with `@storystick/types@0.1.0-rc.
|
|
3
|
+
Install this candidate explicitly with `@storystick/types@0.1.0-rc.3` after registry bootstrap and publication. This repository alone does not make the candidate or beta channel available on npm.
|
|
4
4
|
|
|
5
|
-
Version 0.1.0-rc.
|
|
5
|
+
Version 0.1.0-rc.3, cohort `sdk-0.2.0-rc.3`. 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
|
|
|
@@ -47,7 +47,7 @@ This package supports the integration facades; installing it directly is an adva
|
|
|
47
47
|
| `./internal/richtext-embeds` | Reserved SDK contract |
|
|
48
48
|
| `./public-endpoints` | Supported beta entry |
|
|
49
49
|
|
|
50
|
-
The
|
|
50
|
+
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.
|
|
51
51
|
|
|
52
52
|
This is a support/tooling contract. It does not independently grant project access or permission to perform effects.
|
|
53
53
|
|
package/README.md
CHANGED
|
@@ -17,5 +17,7 @@ Licensed under [FSL-1.1-MIT](./LICENSE).
|
|
|
17
17
|
## Candidate distribution contract
|
|
18
18
|
|
|
19
19
|
See [PUBLIC-API.md](./PUBLIC-API.md) for supported entries, reserved SDK contracts,
|
|
20
|
-
the qualified runtime matrix and the candidate cohort.
|
|
21
|
-
|
|
20
|
+
the qualified runtime matrix and the candidate cohort. Keep shared contracts
|
|
21
|
+
compatible. Use the [release guide](../../release/README.md) to select the
|
|
22
|
+
packages and consumers that need an update; an independent adapter fix does
|
|
23
|
+
not require republishing every package.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export declare const CONTENT_LENS_VALIDATOR_VERSION_V1 = "ck005f.content-lens-validator.v1";
|
|
2
|
+
export declare const CONTENT_LENS_VALIDATOR_STATUS_V1 = "content-lens-validator-v1";
|
|
3
|
+
export declare function normalizeContentPlaneLensVersions(lens: Record<string, unknown>): Record<string, unknown>;
|
|
4
|
+
/** Hash material shared by Central and the projector; hashing stays at the
|
|
5
|
+
* runtime boundary. An ACK is never needed to derive the expected lens.
|
|
6
|
+
*/
|
|
7
|
+
export declare function contentPlaneLensHashMaterials(schema: Record<string, unknown>, lens: Record<string, unknown>, storiesHash: string): {
|
|
8
|
+
semantic: {
|
|
9
|
+
materialVersion: string;
|
|
10
|
+
scope: string;
|
|
11
|
+
sourceSchema: {
|
|
12
|
+
[k: string]: unknown;
|
|
13
|
+
};
|
|
14
|
+
schema: {
|
|
15
|
+
formatVersion: number | null;
|
|
16
|
+
stories: unknown;
|
|
17
|
+
zoneMappings: unknown;
|
|
18
|
+
fieldBindings: unknown;
|
|
19
|
+
};
|
|
20
|
+
lens: {
|
|
21
|
+
contractVersion: number | null;
|
|
22
|
+
versions: Record<string, unknown>;
|
|
23
|
+
descriptors: unknown[];
|
|
24
|
+
unionAttributes: unknown[];
|
|
25
|
+
unsupported: unknown[];
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
display: {
|
|
29
|
+
materialVersion: string;
|
|
30
|
+
scope: string;
|
|
31
|
+
lens: {
|
|
32
|
+
descriptors: {
|
|
33
|
+
[k: string]: unknown;
|
|
34
|
+
}[];
|
|
35
|
+
unionAttributes: {
|
|
36
|
+
[k: string]: unknown;
|
|
37
|
+
}[];
|
|
38
|
+
unsupported: {
|
|
39
|
+
[k: string]: unknown;
|
|
40
|
+
}[];
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export declare function contentPlaneLensHash(schema: Record<string, unknown>, lens: Record<string, unknown>): Promise<string>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { digestCanonicalConversationJson } from './canonical-json.js';
|
|
2
|
+
export const CONTENT_LENS_VALIDATOR_VERSION_V1 = 'ck005f.content-lens-validator.v1';
|
|
3
|
+
export const CONTENT_LENS_VALIDATOR_STATUS_V1 = 'content-lens-validator-v1';
|
|
4
|
+
const record = (v) => v && typeof v === 'object' && !Array.isArray(v) ? v : {};
|
|
5
|
+
const array = (v) => Array.isArray(v) ? v : [];
|
|
6
|
+
const text = (v) => typeof v === 'string' && v.length ? v : undefined;
|
|
7
|
+
const number = (v) => typeof v === 'number' && Number.isFinite(v) ? v : undefined;
|
|
8
|
+
const defined = (v) => Object.fromEntries(Object.entries(v).filter(([, value]) => value !== undefined));
|
|
9
|
+
const displayKeys = new Set(['label', 'group', 'display', 'displayHash', 'description']);
|
|
10
|
+
const identityKeys = new Set(['lensId', 'lensHash', 'semanticHash', 'displayHash', 'derivationStatus', 'contentLensValidator']);
|
|
11
|
+
function canonical(value, semantic = false) {
|
|
12
|
+
if (Array.isArray(value))
|
|
13
|
+
return value.map(child => canonical(child, semantic));
|
|
14
|
+
if (!value || typeof value !== 'object')
|
|
15
|
+
return value;
|
|
16
|
+
return Object.fromEntries(Object.entries(value).filter(([key, child]) => child !== undefined &&
|
|
17
|
+
(!semantic || (!displayKeys.has(key) && !identityKeys.has(key))))
|
|
18
|
+
.sort(([a], [b]) => a.localeCompare(b)).map(([key, child]) => [key, canonical(child, semantic)]));
|
|
19
|
+
}
|
|
20
|
+
export function normalizeContentPlaneLensVersions(lens) {
|
|
21
|
+
const versions = record(lens.versions);
|
|
22
|
+
return defined({ descriptorVersion: number(versions.descriptorVersion) ?? number(lens.descriptorVersion),
|
|
23
|
+
...Object.fromEntries(['extractorVersion', 'normalizationVersion', 'operatorRegistryVersion', 'systemRegistryVersion',
|
|
24
|
+
'referenceExtractorVersion', 'modelPolicyVersion', 'emptyPolicyVersion', 'queryReadCapabilityVersion']
|
|
25
|
+
.map(key => [key, text(versions[key]) ?? text(lens[key])])),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** Hash material shared by Central and the projector; hashing stays at the
|
|
29
|
+
* runtime boundary. An ACK is never needed to derive the expected lens.
|
|
30
|
+
*/
|
|
31
|
+
export function contentPlaneLensHashMaterials(schema, lens, storiesHash) {
|
|
32
|
+
const display = (value) => {
|
|
33
|
+
const row = record(value);
|
|
34
|
+
return defined({ id: text(row.id), schemaKey: text(row.schemaKey), storyType: text(row.storyType), path: text(row.path),
|
|
35
|
+
label: row.label, group: row.group, display: row.display, displayHash: text(record(row.compatibility).displayHash) });
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
semantic: { materialVersion: CONTENT_LENS_VALIDATOR_VERSION_V1, scope: 'exported-schema-and-lens-subset',
|
|
39
|
+
sourceSchema: defined({ source: text(schema.source) ?? 'schemas', schemaVersion: text(schema.schemaVersion), storiesHash }),
|
|
40
|
+
schema: { formatVersion: number(schema.formatVersion) ?? null, stories: canonical(schema.stories ?? null),
|
|
41
|
+
zoneMappings: canonical(schema.zoneMappings ?? {}), fieldBindings: canonical(schema.fieldBindings ?? {}) },
|
|
42
|
+
lens: { contractVersion: number(lens.contractVersion) ?? null, versions: normalizeContentPlaneLensVersions(lens),
|
|
43
|
+
descriptors: array(lens.descriptors).map(v => canonical(v, true)),
|
|
44
|
+
unionAttributes: array(lens.unionAttributes).map(v => canonical(v, true)),
|
|
45
|
+
unsupported: array(lens.unsupported).map(v => canonical(v, true)) } },
|
|
46
|
+
display: { materialVersion: CONTENT_LENS_VALIDATOR_VERSION_V1, scope: 'display-only-lens-subset',
|
|
47
|
+
lens: { descriptors: array(lens.descriptors).map(display), unionAttributes: array(lens.unionAttributes).map(display),
|
|
48
|
+
unsupported: array(lens.unsupported).map(display) } },
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export async function contentPlaneLensHash(schema, lens) {
|
|
52
|
+
const material = contentPlaneLensHashMaterials(schema, lens, `sha256:${await digestCanonicalConversationJson(schema.stories ?? null)}`);
|
|
53
|
+
const semanticHash = `semhash.${CONTENT_LENS_VALIDATOR_STATUS_V1}.${await digestCanonicalConversationJson(material.semantic)}`;
|
|
54
|
+
const displayHash = `displayhash.${CONTENT_LENS_VALIDATOR_STATUS_V1}.${await digestCanonicalConversationJson(material.display)}`;
|
|
55
|
+
return `lenshash.${CONTENT_LENS_VALIDATOR_STATUS_V1}.${await digestCanonicalConversationJson({ semanticHash, displayHash })}`;
|
|
56
|
+
}
|
package/dist/content-shape.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export interface ContentAuthorityWitness {
|
|
|
32
32
|
generationId: string | null;
|
|
33
33
|
transferRevision: number;
|
|
34
34
|
}
|
|
35
|
+
export declare function contentAuthorityMatches(observed: ContentAuthorityWitness, current: ContentAuthorityWitness): boolean;
|
|
35
36
|
export declare function isContentAuthorityWitness(value: unknown): value is ContentAuthorityWitness;
|
|
36
37
|
export interface ContentShapeClientDescriptor {
|
|
37
38
|
protocolVersion: number;
|
|
@@ -40,4 +41,10 @@ export interface ContentShapeClientDescriptor {
|
|
|
40
41
|
surface: ContentShapeSurface;
|
|
41
42
|
buildId: string;
|
|
42
43
|
}
|
|
44
|
+
/** The descriptor accompanying a signed human editor admission. */
|
|
45
|
+
export type StudioContentShapeDescriptor = ContentShapeClientDescriptor & {
|
|
46
|
+
surface: 'studio';
|
|
47
|
+
contentAuthority: ContentAuthorityWitness;
|
|
48
|
+
};
|
|
49
|
+
export declare function isStudioContentShapeDescriptor(value: unknown): value is StudioContentShapeDescriptor;
|
|
43
50
|
export declare function contentShapeCapabilityHeaders(surface: ContentShapeSurface, capability?: string, applicationBuildId?: string): Record<string, string>;
|
package/dist/content-shape.js
CHANGED
|
@@ -29,6 +29,9 @@ export function isContentShapeBuildId(value) {
|
|
|
29
29
|
value.length <= 255 &&
|
|
30
30
|
/^app:[A-Za-z0-9][A-Za-z0-9._-]*$/.test(value);
|
|
31
31
|
}
|
|
32
|
+
export function contentAuthorityMatches(observed, current) {
|
|
33
|
+
return observed.generationId === current.generationId && observed.transferRevision === current.transferRevision;
|
|
34
|
+
}
|
|
32
35
|
export function isContentAuthorityWitness(value) {
|
|
33
36
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
34
37
|
return false;
|
|
@@ -36,6 +39,17 @@ export function isContentAuthorityWitness(value) {
|
|
|
36
39
|
return (witness.generationId === null || (typeof witness.generationId === 'string' && witness.generationId.length > 0)) &&
|
|
37
40
|
Number.isSafeInteger(witness.transferRevision) && witness.transferRevision >= 0;
|
|
38
41
|
}
|
|
42
|
+
export function isStudioContentShapeDescriptor(value) {
|
|
43
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
44
|
+
return false;
|
|
45
|
+
const descriptor = value;
|
|
46
|
+
return Object.keys(descriptor).length === 5 &&
|
|
47
|
+
Number.isSafeInteger(descriptor.protocolVersion) &&
|
|
48
|
+
(descriptor.observedEpoch === 'legacy-additive' || descriptor.observedEpoch === 'sidecar-only') &&
|
|
49
|
+
descriptor.surface === 'studio' &&
|
|
50
|
+
typeof descriptor.buildId === 'string' && descriptor.buildId.length > 0 &&
|
|
51
|
+
isContentAuthorityWitness(descriptor.contentAuthority);
|
|
52
|
+
}
|
|
39
53
|
export function contentShapeCapabilityHeaders(surface, capability, applicationBuildId) {
|
|
40
54
|
if (applicationBuildId !== undefined &&
|
|
41
55
|
(surface !== 'api' || !isContentShapeBuildId(applicationBuildId))) {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { isPublicReadResult, type PublicReadResult, type PublicRoute, type PublicRouteSettings, type PublicRouteLocaleContext, type PublicRouteResolution } from './public-read.js';
|
|
1
2
|
import { type StorystickExternalImage } from './external-image.js';
|
|
3
|
+
export { contentPlaneLensHashMaterials, contentPlaneLensHash, normalizeContentPlaneLensVersions, CONTENT_LENS_VALIDATOR_VERSION_V1, CONTENT_LENS_VALIDATOR_STATUS_V1 } from './content-plane-lens.js';
|
|
2
4
|
import { type ContentRenderPlan } from './content-render.js';
|
|
3
5
|
import type { DocumentDisplayNameSource } from './document-display-name.js';
|
|
4
6
|
import type { ReferencedDocumentsSidecar } from './link-attrs.js';
|
|
@@ -106,6 +108,39 @@ export interface DeliveryDocumentsRequestV2 {
|
|
|
106
108
|
assetDeliveryOrigin?: string;
|
|
107
109
|
budgets: DeliveryResolverBudgetsV2;
|
|
108
110
|
}
|
|
111
|
+
/** Bounded public composition. Only Central may supply the physical authority.
|
|
112
|
+
* Route selection and declared queries resolve their locale in the SQL snapshot.
|
|
113
|
+
*/
|
|
114
|
+
export type PublicRouteDataQueries = Record<string, {
|
|
115
|
+
query: CompiledQueryV2;
|
|
116
|
+
/** Total rows requested; pages are read inside the same SQL transaction. */
|
|
117
|
+
limit?: number;
|
|
118
|
+
for?: Array<string | {
|
|
119
|
+
storyType: string;
|
|
120
|
+
}>;
|
|
121
|
+
}>;
|
|
122
|
+
export interface DeliveryPublicReadRequestV1 {
|
|
123
|
+
requestVersion: 1;
|
|
124
|
+
projectId: string;
|
|
125
|
+
expectedLensHash: string;
|
|
126
|
+
generatedSchemaFingerprint: string;
|
|
127
|
+
minimumProjectionSeq: number;
|
|
128
|
+
expectedProjection?: DeliveryProjectionIdentityV1;
|
|
129
|
+
assetDeliveryOrigin?: string;
|
|
130
|
+
read: {
|
|
131
|
+
kind: 'route';
|
|
132
|
+
pathname: string;
|
|
133
|
+
locale?: string;
|
|
134
|
+
storyTypes?: string[];
|
|
135
|
+
fallbackPolicy: 'none' | 'explicit';
|
|
136
|
+
data?: PublicRouteDataQueries;
|
|
137
|
+
} | {
|
|
138
|
+
kind: 'routes';
|
|
139
|
+
storyTypes?: string[];
|
|
140
|
+
} | {
|
|
141
|
+
kind: 'locales';
|
|
142
|
+
};
|
|
143
|
+
}
|
|
109
144
|
/** Exact public client-to-gateway body. It contains logical intent only. */
|
|
110
145
|
export interface QueryGatewayRequestV2 {
|
|
111
146
|
requestVersion: 2;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { isPublicReadResult } from './public-read.js';
|
|
1
2
|
import { isStorystickExternalImage } from './external-image.js';
|
|
3
|
+
export { contentPlaneLensHashMaterials, contentPlaneLensHash, normalizeContentPlaneLensVersions, CONTENT_LENS_VALIDATOR_VERSION_V1, CONTENT_LENS_VALIDATOR_STATUS_V1 } from './content-plane-lens.js';
|
|
2
4
|
import { isLinkLocaleResolution } from './link-locale.js';
|
|
3
5
|
import { isContentRenderPlan } from './content-render.js';
|
|
4
6
|
import { isExactCompiledQueryV2, } from './query-contract.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type { PathnameAvailability, RouteAvailabilityConflict } from './route-av
|
|
|
19
19
|
export { effectiveSchemaFieldType, type SchemaFieldTypeLike, } from './schema-field-semantics.js';
|
|
20
20
|
export { MEDIA_UPLOAD_ALLOWED_EXT_BY_TYPE, MEDIA_UPLOAD_ALLOWED_MIME_BY_TYPE, MEDIA_UPLOAD_MAX_BYTES, MEDIA_UPLOAD_TOO_LARGE_MESSAGE, inferMediaUploadAssetType, mediaUploadExtension, normalizeMediaUploadMime, preflightMediaUpload, type MediaUploadAssetType, type MediaUploadPolicyIssueCode, type MediaUploadPolicyResult, } from './asset-upload-policy.js';
|
|
21
21
|
export { getStorystickAssetSidecar, lookupStorystickAsset, storystickAssetOriginalDownloadUrl, storystickAssetOriginalUrl, type StorystickAssetLookup, } from './asset-sidecar.js';
|
|
22
|
-
export { CONTENT_SHAPE_BUILD_HEADER, CONTENT_SHAPE_BUILD_IDS, CONTENT_SHAPE_CAPABILITY_HEADER, LEGACY_UNVERSIONED_SCHEMA_VERSION, CONTENT_SHAPE_PROTOCOL_HEADER, CONTENT_SHAPE_PROTOCOL_VERSION, contentShapeCapabilityHeaders, isContentShapeBuildId, type ContentShapeClientDescriptor, type ContentAuthorityWitness, isContentAuthorityWitness, type ContentShapeEpoch, type ContentShapeSurface, } from './content-shape.js';
|
|
22
|
+
export { CONTENT_SHAPE_BUILD_HEADER, CONTENT_SHAPE_BUILD_IDS, CONTENT_SHAPE_CAPABILITY_HEADER, LEGACY_UNVERSIONED_SCHEMA_VERSION, CONTENT_SHAPE_PROTOCOL_HEADER, CONTENT_SHAPE_PROTOCOL_VERSION, contentShapeCapabilityHeaders, contentAuthorityMatches, isStudioContentShapeDescriptor, type StudioContentShapeDescriptor, isContentShapeBuildId, type ContentShapeClientDescriptor, type ContentAuthorityWitness, isContentAuthorityWitness, type ContentShapeEpoch, type ContentShapeSurface, } from './content-shape.js';
|
|
23
23
|
export { previewObjectMarkerAttrs, type PreviewObjectMarker, type PreviewObjectMarkerAttrs, type PreviewObjectMarkerCarrier, } from './preview-object-marker.js';
|
|
24
24
|
export type { PathnameLiteralSegment, PathnameReferenceSegment, PathnameSegment, PathnameValue, } from './pathname-value.js';
|
|
25
25
|
export { resolveSafeHref, safeHref, type SafeHrefResolution, type SafeHrefStatus, } from './safe-href.js';
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
export { effectiveSchemaFieldType, } from './schema-field-semantics.js';
|
|
17
17
|
export { MEDIA_UPLOAD_ALLOWED_EXT_BY_TYPE, MEDIA_UPLOAD_ALLOWED_MIME_BY_TYPE, MEDIA_UPLOAD_MAX_BYTES, MEDIA_UPLOAD_TOO_LARGE_MESSAGE, inferMediaUploadAssetType, mediaUploadExtension, normalizeMediaUploadMime, preflightMediaUpload, } from './asset-upload-policy.js';
|
|
18
18
|
export { getStorystickAssetSidecar, lookupStorystickAsset, storystickAssetOriginalDownloadUrl, storystickAssetOriginalUrl, } from './asset-sidecar.js';
|
|
19
|
-
export { CONTENT_SHAPE_BUILD_HEADER, CONTENT_SHAPE_BUILD_IDS, CONTENT_SHAPE_CAPABILITY_HEADER, LEGACY_UNVERSIONED_SCHEMA_VERSION, CONTENT_SHAPE_PROTOCOL_HEADER, CONTENT_SHAPE_PROTOCOL_VERSION, contentShapeCapabilityHeaders, isContentShapeBuildId, isContentAuthorityWitness, } from './content-shape.js';
|
|
19
|
+
export { CONTENT_SHAPE_BUILD_HEADER, CONTENT_SHAPE_BUILD_IDS, CONTENT_SHAPE_CAPABILITY_HEADER, LEGACY_UNVERSIONED_SCHEMA_VERSION, CONTENT_SHAPE_PROTOCOL_HEADER, CONTENT_SHAPE_PROTOCOL_VERSION, contentShapeCapabilityHeaders, contentAuthorityMatches, isStudioContentShapeDescriptor, isContentShapeBuildId, isContentAuthorityWitness, } from './content-shape.js';
|
|
20
20
|
export { previewObjectMarkerAttrs, } from './preview-object-marker.js';
|
|
21
21
|
export { resolveSafeHref, safeHref, } from './safe-href.js';
|
|
22
22
|
export { readLinkLocaleIntent, isLinkLocaleResolution } from './link-locale.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type DeliveryProjectionIdentityV1 } from './delivery-contract.js';
|
|
2
|
+
export { collectRouteDocumentSliceTypes, routeDataMatches, type RouteDataCondition } from './route-data.js';
|
|
2
3
|
export declare const PUBLIC_DELIVERY_LEASE_MS = 5000;
|
|
3
4
|
export declare const PUBLIC_DELIVERY_CONTENT_TTL_SECONDS = 300;
|
|
4
5
|
export declare const PUBLIC_DELIVERY_SERVICE_HEADER = "x-storystick-delivery-service";
|
|
@@ -15,17 +16,39 @@ export interface PublicReadIdentityV1 {
|
|
|
15
16
|
projection: DeliveryProjectionIdentityV1;
|
|
16
17
|
assetDeliveryOrigin: string | null;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
+
/** Central's allowed read domain and causal floor, independent of an ACK.
|
|
20
|
+
* This is not a credential and must only be supplied by the trusted gateway.
|
|
21
|
+
* The projection actually read is still returned as a PublicReadIdentityV1.
|
|
22
|
+
*/
|
|
23
|
+
export interface PublicReadAuthorityV1 {
|
|
19
24
|
version: 1;
|
|
25
|
+
projectId: string;
|
|
26
|
+
projectShortId: string;
|
|
27
|
+
generationId: string | null;
|
|
28
|
+
buildId: string;
|
|
29
|
+
schemaFingerprint: string;
|
|
30
|
+
storageProjectId: string;
|
|
31
|
+
lensHash: string;
|
|
32
|
+
minimumProjectionSeq: number;
|
|
33
|
+
assetDeliveryOrigin: string | null;
|
|
34
|
+
}
|
|
35
|
+
export interface PublicReadAdmissionV2 {
|
|
36
|
+
version: 2;
|
|
20
37
|
issuedAt: number;
|
|
21
38
|
expiresAt: number;
|
|
22
|
-
|
|
39
|
+
authority: PublicReadAuthorityV1;
|
|
40
|
+
cacheIdentity: PublicReadIdentityV1 | null;
|
|
23
41
|
}
|
|
42
|
+
export declare function isPublicReadAuthority(value: unknown): value is PublicReadAuthorityV1;
|
|
43
|
+
/** Fresh reads can advance within an authorized domain; they cannot cross it.
|
|
44
|
+
* Exact cache equality remains samePublicReadIdentity, including both hashes.
|
|
45
|
+
*/
|
|
46
|
+
export declare function publicReadAuthorityAllowsObservation(authority: PublicReadAuthorityV1, observed: PublicReadIdentityV1): boolean;
|
|
24
47
|
export declare function isPublicReadIdentity(value: unknown): value is PublicReadIdentityV1;
|
|
25
|
-
export declare function isPublicReadAdmission(value: unknown): value is
|
|
48
|
+
export declare function isPublicReadAdmission(value: unknown): value is PublicReadAdmissionV2;
|
|
26
49
|
export declare function samePublicReadIdentity(a: PublicReadIdentityV1, b: PublicReadIdentityV1): boolean;
|
|
27
50
|
/** Strict absolute expiry; a future or malformed lease is never authority. */
|
|
28
|
-
export declare function isPublicReadAdmissionCurrent(value: unknown, now: number):
|
|
51
|
+
export declare function isPublicReadAdmissionCurrent(value: unknown, now: number): boolean;
|
|
29
52
|
export declare const PUBLIC_RENDER_CHALLENGE_HEADER = "x-storystick-render-challenge";
|
|
30
53
|
export declare const isPublicRenderChallenge: (value: unknown) => value is string;
|
|
31
54
|
export declare const PUBLIC_RENDER_RECEIPT_ID = "storystick-public-render";
|
package/dist/public-delivery.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isDeliveryProjectionIdentity, sameDeliveryProjection } from './delivery-contract.js';
|
|
2
|
+
export { collectRouteDocumentSliceTypes, routeDataMatches } from './route-data.js';
|
|
2
3
|
export const PUBLIC_DELIVERY_LEASE_MS = 5_000;
|
|
3
4
|
export const PUBLIC_DELIVERY_CONTENT_TTL_SECONDS = 300;
|
|
4
5
|
export const PUBLIC_DELIVERY_SERVICE_HEADER = 'x-storystick-delivery-service';
|
|
@@ -7,6 +8,25 @@ export const PUBLIC_DELIVERY_FRESH_HEADER = 'x-storystick-delivery-fresh';
|
|
|
7
8
|
const record = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
8
9
|
const text = (v) => typeof v === 'string' && v.length > 0 && v.length <= 1024;
|
|
9
10
|
const exact = (v, fields) => Object.keys(v).length === fields.length && fields.every(k => Object.hasOwn(v, k));
|
|
11
|
+
export function isPublicReadAuthority(value) {
|
|
12
|
+
return record(value) && exact(value, ['version', 'projectId', 'projectShortId', 'generationId', 'buildId',
|
|
13
|
+
'schemaFingerprint', 'storageProjectId', 'lensHash', 'minimumProjectionSeq', 'assetDeliveryOrigin']) &&
|
|
14
|
+
value.version === 1 && text(value.projectId) && text(value.projectShortId) &&
|
|
15
|
+
(value.generationId === null || text(value.generationId)) && text(value.buildId) &&
|
|
16
|
+
text(value.schemaFingerprint) && text(value.storageProjectId) && text(value.lensHash) &&
|
|
17
|
+
Number.isSafeInteger(value.minimumProjectionSeq) && value.minimumProjectionSeq >= 0 &&
|
|
18
|
+
(value.assetDeliveryOrigin === null || text(value.assetDeliveryOrigin));
|
|
19
|
+
}
|
|
20
|
+
/** Fresh reads can advance within an authorized domain; they cannot cross it.
|
|
21
|
+
* Exact cache equality remains samePublicReadIdentity, including both hashes.
|
|
22
|
+
*/
|
|
23
|
+
export function publicReadAuthorityAllowsObservation(authority, observed) {
|
|
24
|
+
return authority.projectId === observed.projectId && authority.projectShortId === observed.projectShortId &&
|
|
25
|
+
authority.generationId === observed.generationId && authority.buildId === observed.buildId &&
|
|
26
|
+
authority.schemaFingerprint === observed.schemaFingerprint && authority.assetDeliveryOrigin === observed.assetDeliveryOrigin &&
|
|
27
|
+
authority.storageProjectId === observed.projection.storageProjectId && authority.lensHash === observed.projection.lensHash &&
|
|
28
|
+
observed.projection.projectedThroughSeq >= authority.minimumProjectionSeq;
|
|
29
|
+
}
|
|
10
30
|
export function isPublicReadIdentity(value) {
|
|
11
31
|
return record(value) && exact(value, ['version', 'projectId', 'projectShortId', 'generationId', 'buildId', 'schemaFingerprint', 'projection', 'assetDeliveryOrigin']) &&
|
|
12
32
|
(value.requestToken === undefined || isPublicRenderChallenge(value.requestToken)) &&
|
|
@@ -15,10 +35,11 @@ export function isPublicReadIdentity(value) {
|
|
|
15
35
|
isDeliveryProjectionIdentity(value.projection) && (value.assetDeliveryOrigin === null || text(value.assetDeliveryOrigin));
|
|
16
36
|
}
|
|
17
37
|
export function isPublicReadAdmission(value) {
|
|
18
|
-
return record(value) && exact(value, ['version', 'issuedAt', 'expiresAt', '
|
|
38
|
+
return record(value) && exact(value, ['version', 'issuedAt', 'expiresAt', 'authority', 'cacheIdentity']) && value.version === 2 &&
|
|
19
39
|
Number.isSafeInteger(value.issuedAt) && Number.isSafeInteger(value.expiresAt) &&
|
|
20
40
|
value.issuedAt >= 0 && value.expiresAt > value.issuedAt &&
|
|
21
|
-
value.expiresAt - value.issuedAt <= PUBLIC_DELIVERY_LEASE_MS &&
|
|
41
|
+
value.expiresAt - value.issuedAt <= PUBLIC_DELIVERY_LEASE_MS && isPublicReadAuthority(value.authority) &&
|
|
42
|
+
(value.cacheIdentity === null || (isPublicReadIdentity(value.cacheIdentity) && publicReadAuthorityAllowsObservation(value.authority, value.cacheIdentity)));
|
|
22
43
|
}
|
|
23
44
|
export function samePublicReadIdentity(a, b) {
|
|
24
45
|
return a.version === b.version && a.projectId === b.projectId && a.projectShortId === b.projectShortId &&
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Production defaults. Alternate services are explicit complete configurations. */
|
|
2
2
|
export declare const STORYSTICK_GATEWAY_ORIGIN = "https://api.storystick.app";
|
|
3
3
|
export declare const STORYSTICK_STUDIO_ORIGIN = "https://storystick.app";
|
|
4
|
+
export interface ServiceConnection {
|
|
5
|
+
readonly studioOrigin: string;
|
|
6
|
+
readonly apiOrigin: string;
|
|
7
|
+
readonly syncOrigin: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const DEFAULT_SERVICE_CONNECTION: ServiceConnection;
|
|
10
|
+
/** Origins only; credential-bearing URLs, paths and implicit protocol upgrades are forbidden. */
|
|
11
|
+
export declare function serviceOrigin(value: unknown): string;
|
|
12
|
+
/** Strict projection keeps internal profile fields and secrets out of the browser. */
|
|
13
|
+
export declare function parseServiceConnection(value: unknown): ServiceConnection;
|
|
14
|
+
/** Caller supplies the process environment; this pure helper never reads files. */
|
|
15
|
+
export declare function serviceConnectionFromEnv(env: Record<string, string | undefined>): ServiceConnection | undefined;
|
|
16
|
+
export declare function assertServiceOrigin(actual: string | undefined, expected: string): void;
|
package/dist/public-endpoints.js
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Production defaults. Alternate services are explicit complete configurations. */
|
|
2
2
|
export const STORYSTICK_GATEWAY_ORIGIN = 'https://api.storystick.app';
|
|
3
3
|
export const STORYSTICK_STUDIO_ORIGIN = 'https://storystick.app';
|
|
4
|
+
export const DEFAULT_SERVICE_CONNECTION = Object.freeze({
|
|
5
|
+
studioOrigin: STORYSTICK_STUDIO_ORIGIN,
|
|
6
|
+
apiOrigin: STORYSTICK_GATEWAY_ORIGIN,
|
|
7
|
+
syncOrigin: 'https://sync.storystick.app',
|
|
8
|
+
});
|
|
9
|
+
/** Origins only; credential-bearing URLs, paths and implicit protocol upgrades are forbidden. */
|
|
10
|
+
export function serviceOrigin(value) {
|
|
11
|
+
if (typeof value !== 'string' || !value || value !== value.trim())
|
|
12
|
+
throw new TypeError('Invalid service origin.');
|
|
13
|
+
let url;
|
|
14
|
+
try {
|
|
15
|
+
url = new URL(value);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
throw new TypeError('Invalid service origin.');
|
|
19
|
+
}
|
|
20
|
+
const loopback = url.protocol === 'http:' && ['127.0.0.1', 'localhost', '[::1]'].includes(url.hostname);
|
|
21
|
+
if ((!loopback && url.protocol !== 'https:') || url.username || url.password || url.search || url.hash || url.pathname !== '/') {
|
|
22
|
+
throw new TypeError('Service origins require HTTPS (HTTP loopback is allowed), without credentials, path, query or fragment.');
|
|
23
|
+
}
|
|
24
|
+
return url.origin;
|
|
25
|
+
}
|
|
26
|
+
/** Strict projection keeps internal profile fields and secrets out of the browser. */
|
|
27
|
+
export function parseServiceConnection(value) {
|
|
28
|
+
if (typeof value === 'string') {
|
|
29
|
+
try {
|
|
30
|
+
value = JSON.parse(value);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
throw new TypeError('Invalid service configuration JSON.');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
37
|
+
throw new TypeError('Invalid service configuration.');
|
|
38
|
+
const input = value;
|
|
39
|
+
const fields = ['studioOrigin', 'apiOrigin', 'syncOrigin'];
|
|
40
|
+
if (Object.keys(input).length !== fields.length || Object.keys(input).some(key => !fields.includes(key))) {
|
|
41
|
+
throw new TypeError('A complete service configuration requires only Studio, API and sync origins.');
|
|
42
|
+
}
|
|
43
|
+
return Object.freeze({ studioOrigin: serviceOrigin(input.studioOrigin), apiOrigin: serviceOrigin(input.apiOrigin), syncOrigin: serviceOrigin(input.syncOrigin) });
|
|
44
|
+
}
|
|
45
|
+
/** Caller supplies the process environment; this pure helper never reads files. */
|
|
46
|
+
export function serviceConnectionFromEnv(env) {
|
|
47
|
+
if (env.STORYSTICK_ENVIRONMENT !== undefined || env.NEXT_PUBLIC_STORYSTICK_ENVIRONMENT !== undefined) {
|
|
48
|
+
throw new TypeError('Obsolete service selection. Reconnect the project and use the operator launcher for an alternate service.');
|
|
49
|
+
}
|
|
50
|
+
const raw = env.STORYSTICK_SERVICE_CONFIG;
|
|
51
|
+
if (raw !== undefined)
|
|
52
|
+
return parseServiceConnection(raw);
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
export function assertServiceOrigin(actual, expected) {
|
|
56
|
+
if (actual !== undefined && serviceOrigin(actual) !== expected)
|
|
57
|
+
throw new TypeError('Service configuration conflicts with an explicit origin.');
|
|
58
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type DeliveryDocumentsResponseV2, type DeliveryProjectionIdentityV1 } from './delivery-contract.js';
|
|
2
|
+
import type { LocaleRoutingSettings } from './locale-routing.js';
|
|
3
|
+
export interface PublicRouteSettings extends LocaleRoutingSettings {
|
|
4
|
+
projectId: string;
|
|
5
|
+
synthetic: boolean;
|
|
6
|
+
fallbackChains: {
|
|
7
|
+
locale: string;
|
|
8
|
+
chain: string[];
|
|
9
|
+
}[];
|
|
10
|
+
}
|
|
11
|
+
export interface PublicRoute {
|
|
12
|
+
documentId: string;
|
|
13
|
+
storyType: string;
|
|
14
|
+
locale: string;
|
|
15
|
+
pathname: string;
|
|
16
|
+
publicPathname: string;
|
|
17
|
+
defaultLocale: string;
|
|
18
|
+
primaryLocale: string;
|
|
19
|
+
seo: {
|
|
20
|
+
indexable: boolean;
|
|
21
|
+
canonicalUrl?: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface PublicRouteLocaleContext extends LocaleRoutingSettings {
|
|
25
|
+
locale: string;
|
|
26
|
+
pathname: string;
|
|
27
|
+
publicPathname: string;
|
|
28
|
+
}
|
|
29
|
+
export type PublicRouteResolution = {
|
|
30
|
+
kind: 'redirect';
|
|
31
|
+
redirectTo: string;
|
|
32
|
+
permanent: true;
|
|
33
|
+
} | {
|
|
34
|
+
kind: 'notFound';
|
|
35
|
+
localeContext?: PublicRouteLocaleContext;
|
|
36
|
+
} | {
|
|
37
|
+
kind: 'document';
|
|
38
|
+
route: PublicRoute;
|
|
39
|
+
localeContext: PublicRouteLocaleContext;
|
|
40
|
+
alternates: Record<string, string>;
|
|
41
|
+
};
|
|
42
|
+
export type PublicReadResult = {
|
|
43
|
+
resultVersion: 1;
|
|
44
|
+
projection: DeliveryProjectionIdentityV1;
|
|
45
|
+
settings: PublicRouteSettings;
|
|
46
|
+
} & ({
|
|
47
|
+
kind: 'locales';
|
|
48
|
+
} | {
|
|
49
|
+
kind: 'routes';
|
|
50
|
+
routes: PublicRoute[];
|
|
51
|
+
} | {
|
|
52
|
+
kind: 'route';
|
|
53
|
+
route: PublicRouteResolution;
|
|
54
|
+
content?: DeliveryDocumentsResponseV2;
|
|
55
|
+
data?: Record<string, DeliveryDocumentsResponseV2>;
|
|
56
|
+
});
|
|
57
|
+
/** Closed response boundary. All graphs must attest this operation's SQL view. */
|
|
58
|
+
export declare function isPublicReadResult(v: unknown): v is PublicReadResult;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { isDeliveryProjectionIdentity, isExactDeliveryDocumentsResponseV2 } from './delivery-contract.js';
|
|
2
|
+
const record = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
3
|
+
const text = (v) => typeof v === 'string' && v.length > 0 && v.length <= 4096;
|
|
4
|
+
const keys = (v, allowed) => Object.keys(v).every(k => allowed.includes(k));
|
|
5
|
+
const path = (v) => typeof v === 'string' && v.length <= 2048 && !/[\\?#\u0000-\u0020]/.test(v) && !v.startsWith('//');
|
|
6
|
+
const strings = (v) => Array.isArray(v) && v.length <= 128 && v.every(text);
|
|
7
|
+
function routing(v) {
|
|
8
|
+
return text(v.defaultLocale) && Array.isArray(v.locales) && v.locales.length <= 128 && v.locales.every(row => record(row) && keys(row, ['code', 'enabled', 'label', 'isDefault']) && text(row.code) && typeof row.enabled === 'boolean' &&
|
|
9
|
+
(row.label === undefined || typeof row.label === 'string') && (row.isDefault === undefined || typeof row.isDefault === 'boolean')) &&
|
|
10
|
+
record(v.localeRouting) && keys(v.localeRouting, ['strategy', 'prefixDefault']) && v.localeRouting.strategy === 'prefix' &&
|
|
11
|
+
typeof v.localeRouting.prefixDefault === 'boolean' && (v.synthetic === undefined || typeof v.synthetic === 'boolean');
|
|
12
|
+
}
|
|
13
|
+
function localeContext(v) {
|
|
14
|
+
return record(v) && keys(v, ['locale', 'pathname', 'publicPathname', 'defaultLocale', 'locales', 'localeRouting', 'synthetic']) &&
|
|
15
|
+
routing(v) && text(v.locale) && path(v.pathname) && path(v.publicPathname);
|
|
16
|
+
}
|
|
17
|
+
function route(v) {
|
|
18
|
+
return record(v) && keys(v, ['documentId', 'storyType', 'locale', 'pathname', 'publicPathname', 'defaultLocale', 'primaryLocale', 'seo']) &&
|
|
19
|
+
['documentId', 'storyType', 'locale', 'defaultLocale', 'primaryLocale'].every(k => text(v[k])) &&
|
|
20
|
+
path(v.pathname) && path(v.publicPathname) && record(v.seo) && keys(v.seo, ['indexable', 'canonicalUrl']) &&
|
|
21
|
+
typeof v.seo.indexable === 'boolean' && (v.seo.canonicalUrl === undefined || text(v.seo.canonicalUrl));
|
|
22
|
+
}
|
|
23
|
+
/** Closed response boundary. All graphs must attest this operation's SQL view. */
|
|
24
|
+
export function isPublicReadResult(v) {
|
|
25
|
+
if (!record(v) || v.resultVersion !== 1 || !isDeliveryProjectionIdentity(v.projection) || !record(v.settings) ||
|
|
26
|
+
!keys(v.settings, ['projectId', 'defaultLocale', 'locales', 'localeRouting', 'synthetic', 'fallbackChains']) ||
|
|
27
|
+
v.settings.projectId !== v.projection.storageProjectId || typeof v.settings.synthetic !== 'boolean' || !routing(v.settings) ||
|
|
28
|
+
!Array.isArray(v.settings.fallbackChains) || v.settings.fallbackChains.length > 128 || !v.settings.fallbackChains.every(row => record(row) && keys(row, ['locale', 'chain']) && text(row.locale) && strings(row.chain)))
|
|
29
|
+
return false;
|
|
30
|
+
const base = ['resultVersion', 'projection', 'settings', 'kind'];
|
|
31
|
+
if (v.kind === 'locales')
|
|
32
|
+
return keys(v, base);
|
|
33
|
+
if (v.kind === 'routes')
|
|
34
|
+
return keys(v, [...base, 'routes']) && Array.isArray(v.routes) && v.routes.length <= 10_000 && v.routes.every(route);
|
|
35
|
+
if (v.kind !== 'route' || !record(v.route))
|
|
36
|
+
return false;
|
|
37
|
+
const r = v.route;
|
|
38
|
+
if (r.kind === 'redirect')
|
|
39
|
+
return keys(v, [...base, 'route']) && keys(r, ['kind', 'redirectTo', 'permanent']) &&
|
|
40
|
+
path(r.redirectTo) && r.redirectTo.startsWith('/') && r.permanent === true;
|
|
41
|
+
if (r.kind === 'notFound')
|
|
42
|
+
return keys(v, [...base, 'route']) && keys(r, ['kind', 'localeContext']) &&
|
|
43
|
+
(r.localeContext === undefined || localeContext(r.localeContext));
|
|
44
|
+
if (r.kind !== 'document' || !keys(r, ['kind', 'route', 'localeContext', 'alternates']) || !route(r.route) ||
|
|
45
|
+
!localeContext(r.localeContext) || !record(r.alternates) || !Object.values(r.alternates).every(path) ||
|
|
46
|
+
!keys(v, [...base, 'route', 'content', 'data']) || !record(v.data) || Object.keys(v.data).length > 32)
|
|
47
|
+
return false;
|
|
48
|
+
const projection = v.projection;
|
|
49
|
+
const graph = (value) => isExactDeliveryDocumentsResponseV2(value) &&
|
|
50
|
+
value.envelope.exactness === 'exact' && value.envelope.consistency.projectedThroughSeq === projection.projectedThroughSeq &&
|
|
51
|
+
value.readSession.lensHash === projection.lensHash && value.readSession.projectionHash === projection.projectionHash &&
|
|
52
|
+
value.executionIdentity.sourceIdentityKey === projection.sourceIdentity;
|
|
53
|
+
return graph(v.content) && v.content.envelope.data.length === 1 &&
|
|
54
|
+
v.content.envelope.data[0]?.documentId === r.route.documentId && v.content.envelope.data[0]?.storyType === r.route.storyType &&
|
|
55
|
+
Object.entries(v.data).every(([key, value]) => !['__proto__', 'prototype', 'constructor'].includes(key) && graph(value));
|
|
56
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type RouteDataCondition = string | {
|
|
2
|
+
readonly storyType: string;
|
|
3
|
+
};
|
|
4
|
+
export declare function routeDataMatches(conditions: readonly RouteDataCondition[] | undefined, storyType: string, sliceTypes: () => ReadonlySet<string>): boolean;
|
|
5
|
+
/** The route-data condition inventory shared by SQL and render adapters.
|
|
6
|
+
* Mirrors the actual route slice scopes, including mapped zones and rich text
|
|
7
|
+
* embeds, without importing Preview provenance or a framework into the reader.
|
|
8
|
+
*/
|
|
9
|
+
export declare function collectRouteDocumentSliceTypes(document: {
|
|
10
|
+
fields?: unknown;
|
|
11
|
+
_zoneMappings?: unknown;
|
|
12
|
+
}): ReadonlySet<string>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { CONTENT_RENDER_MAX_DEPTH, ContentRenderDepthError } from './content-render.js';
|
|
2
|
+
import { RICHTEXT_EMBED_STORE_FIELD } from './richtext-embeds.js';
|
|
3
|
+
export function routeDataMatches(conditions, storyType, sliceTypes) {
|
|
4
|
+
return !conditions?.length || conditions.some(condition => typeof condition === 'string'
|
|
5
|
+
? sliceTypes().has(condition) : condition.storyType === storyType);
|
|
6
|
+
}
|
|
7
|
+
const record = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
8
|
+
const sliceArray = (v) => Array.isArray(v) && v.some(item => record(item) && typeof item._type === 'string' && typeof item._key === 'string');
|
|
9
|
+
/** The route-data condition inventory shared by SQL and render adapters.
|
|
10
|
+
* Mirrors the actual route slice scopes, including mapped zones and rich text
|
|
11
|
+
* embeds, without importing Preview provenance or a framework into the reader.
|
|
12
|
+
*/
|
|
13
|
+
export function collectRouteDocumentSliceTypes(document) {
|
|
14
|
+
const fields = record(document.fields) ? document.fields : {};
|
|
15
|
+
const mappings = record(document._zoneMappings) ? document._zoneMappings : {};
|
|
16
|
+
const sidecars = new Map();
|
|
17
|
+
const raw = fields[RICHTEXT_EMBED_STORE_FIELD];
|
|
18
|
+
if (Array.isArray(raw))
|
|
19
|
+
for (const item of raw) {
|
|
20
|
+
if (record(item) && typeof item._key === 'string' && !sidecars.has(item._key))
|
|
21
|
+
sidecars.set(item._key, item);
|
|
22
|
+
}
|
|
23
|
+
const mappingPaths = (slice) => {
|
|
24
|
+
const mapping = typeof slice._type === 'string' ? mappings[slice._type] : undefined;
|
|
25
|
+
return record(mapping) ? Object.values(mapping).filter((v) => typeof v === 'string' && v.length > 0) : [];
|
|
26
|
+
};
|
|
27
|
+
const embeds = (value) => {
|
|
28
|
+
if (typeof value === 'string') {
|
|
29
|
+
if (!value.trim().startsWith('{'))
|
|
30
|
+
return [];
|
|
31
|
+
try {
|
|
32
|
+
value = JSON.parse(value);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const out = [];
|
|
39
|
+
const visit = (node, index, depth) => {
|
|
40
|
+
if (depth > CONTENT_RENDER_MAX_DEPTH)
|
|
41
|
+
throw new ContentRenderDepthError();
|
|
42
|
+
if (!record(node))
|
|
43
|
+
return;
|
|
44
|
+
if (node.type === 'sliceEmbed' && record(node.attrs) && typeof node.attrs._type === 'string') {
|
|
45
|
+
const attrs = node.attrs;
|
|
46
|
+
const key = typeof attrs._key === 'string' ? attrs._key : `rt-${index}`;
|
|
47
|
+
out.push({ _type: attrs._type, _key: key,
|
|
48
|
+
...(record(attrs.data) ? attrs.data : sidecars.get(key) ?? {}) });
|
|
49
|
+
}
|
|
50
|
+
if (Array.isArray(node.content))
|
|
51
|
+
node.content.forEach((child, i) => visit(child, i, depth + 1));
|
|
52
|
+
};
|
|
53
|
+
visit(value, 0, 0);
|
|
54
|
+
return out;
|
|
55
|
+
};
|
|
56
|
+
const targetFields = new Set();
|
|
57
|
+
const scanned = new Set();
|
|
58
|
+
const visitTargets = (slices, depth) => {
|
|
59
|
+
if (depth > CONTENT_RENDER_MAX_DEPTH)
|
|
60
|
+
throw new ContentRenderDepthError();
|
|
61
|
+
if (scanned.has(slices))
|
|
62
|
+
return;
|
|
63
|
+
scanned.add(slices);
|
|
64
|
+
for (const slice of slices)
|
|
65
|
+
if (record(slice)) {
|
|
66
|
+
for (const path of mappingPaths(slice))
|
|
67
|
+
targetFields.add(path);
|
|
68
|
+
for (const value of Object.values(slice))
|
|
69
|
+
if (sliceArray(value))
|
|
70
|
+
visitTargets(value, depth + 1);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
for (const value of Object.values(fields))
|
|
74
|
+
visitTargets(sliceArray(value) ? value : embeds(value), 0);
|
|
75
|
+
const out = new Set();
|
|
76
|
+
const addTypes = (slices) => {
|
|
77
|
+
for (const slice of slices)
|
|
78
|
+
if (record(slice) && typeof slice._type === 'string' && slice._type.length)
|
|
79
|
+
out.add(slice._type);
|
|
80
|
+
};
|
|
81
|
+
const readField = (path) => {
|
|
82
|
+
if (Object.hasOwn(fields, path))
|
|
83
|
+
return fields[path];
|
|
84
|
+
let value = fields;
|
|
85
|
+
for (const part of path.split('.'))
|
|
86
|
+
value = record(value) ? value[part] : undefined;
|
|
87
|
+
return value;
|
|
88
|
+
};
|
|
89
|
+
const visited = new Set();
|
|
90
|
+
const visitZone = (slices, depth) => {
|
|
91
|
+
if (depth > CONTENT_RENDER_MAX_DEPTH)
|
|
92
|
+
throw new ContentRenderDepthError();
|
|
93
|
+
if (visited.has(slices))
|
|
94
|
+
return;
|
|
95
|
+
visited.add(slices);
|
|
96
|
+
addTypes(slices);
|
|
97
|
+
for (const slice of slices)
|
|
98
|
+
if (record(slice) && typeof slice._type === 'string' && typeof slice._key === 'string' && slice._key) {
|
|
99
|
+
for (const path of mappingPaths(slice)) {
|
|
100
|
+
const value = readField(path);
|
|
101
|
+
if (sliceArray(value))
|
|
102
|
+
visitZone(value, depth + 1);
|
|
103
|
+
else
|
|
104
|
+
addTypes(embeds(value));
|
|
105
|
+
}
|
|
106
|
+
for (const [key, value] of Object.entries(slice))
|
|
107
|
+
if (!key.startsWith('_'))
|
|
108
|
+
addTypes(embeds(value));
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
112
|
+
if (targetFields.has(key))
|
|
113
|
+
continue;
|
|
114
|
+
if (sliceArray(value))
|
|
115
|
+
visitZone(value, 0);
|
|
116
|
+
else if (key !== RICHTEXT_EMBED_STORE_FIELD)
|
|
117
|
+
addTypes(embeds(value));
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storystick/types",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.3",
|
|
4
4
|
"license": "FSL-1.1-MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -177,7 +177,7 @@
|
|
|
177
177
|
"@types/node": "^22.13.10"
|
|
178
178
|
},
|
|
179
179
|
"engines": {
|
|
180
|
-
"node": "
|
|
180
|
+
"node": "^22.13.0 || ^24.19.0"
|
|
181
181
|
},
|
|
182
182
|
"repository": {
|
|
183
183
|
"type": "git",
|