@storystick/client 0.2.0-rc.0 → 0.2.0-rc.2

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/client API contract
2
2
 
3
- Install this candidate explicitly with `@storystick/client@0.2.0-rc.0` 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/client@0.2.0-rc.2` 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.0, cohort `sdk-0.2.0-rc.0`. ESM distribution; no CommonJS or universal Edge compatibility is promised.
5
+ Version 0.2.0-rc.2, cohort `sdk-0.2.0-rc.2`. ESM distribution; no CommonJS or universal Edge compatibility is promised.
6
6
 
7
7
  This package is a product integration facade. 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
 
package/dist/.source-hash CHANGED
@@ -1 +1 @@
1
- e9b1f5ad508349c6004d7e10c0272e3d09bbce936e2556b3c8e7d474d778c994
1
+ e84684ca7440a20c446216db7c677941f4f4df2daab67911c8f0e9a1f2876aca
@@ -1,7 +1,7 @@
1
1
  import { StorystickError } from './errors.js';
2
2
  import { getInternalClientRuntime } from './query-client.js';
3
3
  import { LOCALE_ROUTE_COLLISION } from '@storystick/types/errors/codes/locale-lifecycle';
4
- import { samePublicReadIdentity } from '@storystick/types/public-delivery';
4
+ import { hasUsablePreviewToken } from './preview-scope.js';
5
5
  import { attachPublicRouteIdentity } from './public-delivery.js';
6
6
  export async function publishedLocaleRoutes(client, storyTypes) {
7
7
  if (storyTypes.length === 0)
@@ -11,22 +11,20 @@ export async function publishedLocaleRoutes(client, storyTypes) {
11
11
  const seenCursors = new Set();
12
12
  let cursor = null;
13
13
  let identity;
14
- let witnessed;
14
+ const preview = hasUsablePreviewToken(runtime.requestContext);
15
15
  for (let page = 0; page < 10_000; page += 1) {
16
16
  const response = await runtime.transport.request({
17
17
  udfPath: 'queries:listPublishedLocaleRoutes',
18
- args: { storyTypes: [...storyTypes], cursor, numItems: 500 },
18
+ args: { storyTypes: [...storyTypes], ...(preview ? { cursor, numItems: 500 } : {}) },
19
19
  options: undefined,
20
20
  requestContext: runtime.requestContext,
21
21
  });
22
- if (witnessed !== undefined && (witnessed !== Boolean(response.publicReadIdentity) ||
23
- (identity && response.publicReadIdentity && !samePublicReadIdentity(identity, response.publicReadIdentity))))
24
- throw new StorystickError('The public route inventory changed during pagination.', {
25
- code: 'storystick/QUERY_GENERATION_CHANGED', category: 'system', retryable: true,
26
- });
27
- witnessed = Boolean(response.publicReadIdentity);
28
22
  identity = response.publicReadIdentity;
29
23
  const result = response.data;
24
+ if (!result || !Array.isArray(result.page) || (!preview && (!result.isDone || result.continueCursor !== '' || result.page.length > 10_000)))
25
+ throw new StorystickError('Public route inventory is not a complete bounded snapshot.', {
26
+ code: 'storystick/QUERY_PROTOCOL', category: 'system', retryable: false,
27
+ });
30
28
  routes.push(...result.page.map((route) => ({
31
29
  ...route,
32
30
  seo: route.seo ?? { indexable: true },
@@ -42,11 +42,14 @@ export async function resolveStorystickPage(client, input) {
42
42
  }
43
43
  const canonical = normalizePathname(input.pathname);
44
44
  const runtime = getInternalClientRuntime(client);
45
+ const publicOrigins = input.publicOrigins ?? runtime.localeRouting?.publicOrigins;
45
46
  // Dispatch a single cross-storytype call via the configured client's
46
47
  // transport. We don't go through a generated story query because this helper
47
48
  // isn't bound to a single storytype — the backend resolves any URL-routable
48
49
  // type that matches the canonical pathname (ADR-094 §1.bis).
49
50
  const args = { pathname: canonical, ...(input.locale ? { locale: input.locale } : {}) };
51
+ if (input.dataQueries !== undefined && !hasUsablePreviewToken(runtime.requestContext))
52
+ args.data = input.dataQueries;
50
53
  if (input.storyTypes && input.storyTypes.length > 0) {
51
54
  args.storyTypes = [...input.storyTypes];
52
55
  }
@@ -55,7 +58,8 @@ export async function resolveStorystickPage(client, input) {
55
58
  cacheKey: createPreviewProvenanceReadCacheKey('resolved-route', {
56
59
  pathname: canonical,
57
60
  locale: input.locale,
58
- publicOrigins: runtime.localeRouting?.publicOrigins,
61
+ publicOrigins,
62
+ dataQueries: input.dataQueries,
59
63
  storyTypes: input.storyTypes ? [...input.storyTypes].sort() : undefined,
60
64
  }),
61
65
  executeRaw: async () => {
@@ -72,17 +76,21 @@ export async function resolveStorystickPage(client, input) {
72
76
  if ('notFound' in data) {
73
77
  return {
74
78
  type: 'notFound',
75
- ...(data.localeContext ? { localeContext: siteLocaleContext(data.localeContext, runtime.localeRouting?.publicOrigins) } : {}),
79
+ ...(data.localeContext ? { localeContext: siteLocaleContext(data.localeContext, publicOrigins) } : {}),
76
80
  };
77
81
  }
78
82
  if ('redirectTo' in data) {
79
83
  let redirectTo = data.redirectTo;
80
- if (runtime.localeRouting?.publicOrigins && redirectTo.startsWith('/') && !redirectTo.startsWith('//')) {
81
- const resolved = resolveLocalePathname(redirectTo, runtime.localeRouting);
84
+ if (publicOrigins && redirectTo.startsWith('/') && !redirectTo.startsWith('//')) {
85
+ const settings = data.localeSettings ?? runtime.localeRouting;
86
+ if (!settings)
87
+ throw new TypeError('Published redirect is missing its locale settings.');
88
+ const routing = { ...settings, publicOrigins };
89
+ const resolved = resolveLocalePathname(redirectTo, routing);
82
90
  if (!resolved.ok)
83
91
  throw new TypeError('Invalid published redirect locale.');
84
92
  const suffix = redirectTo.match(/[?#].*$/)?.[0] ?? '';
85
- redirectTo = publicHrefForLocale(resolved.pathname, resolved.locale, runtime.localeRouting) + suffix;
93
+ redirectTo = publicHrefForLocale(resolved.pathname, resolved.locale, routing) + suffix;
86
94
  }
87
95
  return {
88
96
  type: 'redirect',
@@ -101,10 +109,23 @@ export async function resolveStorystickPage(client, input) {
101
109
  ...previewAssetDependenciesFromValue(data.document),
102
110
  ]);
103
111
  }
104
- const localeContext = siteLocaleContext(data.localeContext, runtime.localeRouting?.publicOrigins);
112
+ const localeContext = siteLocaleContext(data.localeContext, publicOrigins);
105
113
  attachDocumentLocaleRouting(data.document, localeContext);
106
- if (!hasUsablePreviewToken(runtime.requestContext))
114
+ if (!hasUsablePreviewToken(runtime.requestContext)) {
107
115
  attachPublicRouteIdentity(data.document, response.publicReadIdentity);
116
+ if (input.dataQueries !== undefined) {
117
+ if (!data.data || Object.keys(data.data).length !== Object.keys(input.dataQueries).length ||
118
+ !Object.keys(input.dataQueries).every(key => Object.hasOwn(data.data, key) && Array.isArray(data.data[key])))
119
+ throw new TypeError('The public route is missing its composed page data.');
120
+ attachPublicRouteIdentity(data.data, response.publicReadIdentity);
121
+ for (const rows of Object.values(data.data)) {
122
+ attachDocumentLocaleRouting(rows, localeContext);
123
+ attachPublicRouteIdentity(rows, response.publicReadIdentity);
124
+ for (const row of rows)
125
+ attachPublicRouteIdentity(row, response.publicReadIdentity);
126
+ }
127
+ }
128
+ }
108
129
  return {
109
130
  type: 'document',
110
131
  document: data.document,
@@ -115,6 +136,7 @@ export async function resolveStorystickPage(client, input) {
115
136
  primaryLocale: data.primaryLocale,
116
137
  alternates: data.alternates,
117
138
  seo: data.seo ?? { indexable: true },
139
+ ...(data.data ? { data: data.data } : {}),
118
140
  };
119
141
  },
120
142
  });
package/dist/transport.js CHANGED
@@ -55,7 +55,8 @@ export function createHttpTransportV2(opts) {
55
55
  async function request(input) {
56
56
  assertProjectMatch(input.expectedProjectId ?? opts.projectId, opts.projectId);
57
57
  const { udfPath, args, options, requestContext, signal: signalArg } = input;
58
- const { method, path } = endpointForUdf(udfPath);
58
+ const { method: endpointMethod, path } = endpointForUdf(udfPath);
59
+ const method = udfPath === 'queries:getRouteByPathname' && args.data !== undefined ? 'POST' : endpointMethod;
59
60
  // Use the shared `hasUsablePreviewToken` predicate so the builder's
60
61
  // `assertPreviewIntent` guard and this preview-path switch agree on
61
62
  // what counts as "bound": a non-empty string. `previewToken: ''`
@@ -69,7 +70,7 @@ export function createHttpTransportV2(opts) {
69
70
  ? opts.deliveryEndpoint : endpoint;
70
71
  const url = buildUrl({ endpoint: readEndpoint, path, method, args, options, isPreview });
71
72
  const body = method === 'POST'
72
- ? buildPostBody(args, options, isPreview, udfPath !== 'queries:queryV2')
73
+ ? buildPostBody(args, options, isPreview, udfPath !== 'queries:queryV2' && udfPath !== 'queries:getRouteByPathname')
73
74
  : undefined;
74
75
  const signal = signalArg ?? options?.signal;
75
76
  const fetchInit = buildFetchInit({
@@ -140,7 +141,7 @@ export function createHttpTransportV2(opts) {
140
141
  }
141
142
  }
142
143
  let publicReadIdentity;
143
- if (!isPreview && ['queries:queryV2', 'queries:getRouteByPathname', 'queries:listPublishedLocaleRoutes'].includes(input.udfPath) && response.headers.has(PUBLIC_DELIVERY_IDENTITY_HEADER)) {
144
+ if (!isPreview && ['queries:queryV2', 'queries:getRouteByPathname', 'queries:listPublishedLocaleRoutes', 'locales:get'].includes(input.udfPath) && response.headers.has(PUBLIC_DELIVERY_IDENTITY_HEADER)) {
144
145
  let value = null;
145
146
  try {
146
147
  value = JSON.parse(response.headers.get(PUBLIC_DELIVERY_IDENTITY_HEADER));
@@ -211,7 +212,7 @@ async function fetchTransportResponse(fetchFn, url, init) {
211
212
  }
212
213
  }
213
214
  function queryResponseMetadata(udfPath, response) {
214
- if (udfPath !== 'queries:queryV2')
215
+ if (udfPath !== 'queries:queryV2' && udfPath !== 'queries:getRouteByPathname')
215
216
  return {};
216
217
  const queryHash = response.headers.get('X-Storystick-Query-Hash');
217
218
  const readScopeIdentity = response.headers.get('X-Storystick-Read-Scope-Identity');
package/dist/types.d.ts CHANGED
@@ -25,6 +25,7 @@ export type ResolvedRoute = {
25
25
  primaryLocale: string;
26
26
  alternates: Readonly<Record<string, string>>;
27
27
  seo: PublicationSeo;
28
+ data?: Record<string, QueryResult[]>;
28
29
  } | {
29
30
  type: 'redirect';
30
31
  redirectTo: string;
@@ -53,6 +54,8 @@ export interface QueryResult extends DeliveryDocumentV1 {
53
54
  resolved?: Record<string, QueryResult | QueryResult[] | null>;
54
55
  }
55
56
  export interface ResolveRouteInput {
57
+ publicOrigins?: import('./locale-routing.js').PublicLocaleOrigins;
58
+ dataQueries?: import('@storystick/types/delivery-contract').PublicRouteDataQueries;
56
59
  /** Explicit locale: pathname is canonical and unprefixed (domain deployments). */
57
60
  locale?: string;
58
61
  pathname: string | string[] | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storystick/client",
3
- "version": "0.2.0-rc.0",
3
+ "version": "0.2.0-rc.2",
4
4
  "license": "FSL-1.1-MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -43,8 +43,8 @@
43
43
  "tag": "beta"
44
44
  },
45
45
  "dependencies": {
46
- "@storystick/types": "0.1.0-rc.0",
47
- "@storystick/media": "0.2.0-rc.0"
46
+ "@storystick/media": "0.2.0-rc.2",
47
+ "@storystick/types": "0.1.0-rc.2"
48
48
  },
49
49
  "devDependencies": {
50
50
  "typescript": "^5.8.2",