@cmssy/react 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { B as BlockSchema, a as BlockMeta, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, d as CmssyLayoutGroup, e as CmssyLocaleContext, f as CmssyCart, g as CmssyOrder, h as CmssyProduct } from './commerce-queries-CqCdTD31.cjs';
3
- export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-CqCdTD31.cjs';
2
+ import { B as BlockSchema, a as BlockMeta, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, d as CmssyLayoutGroup, e as CmssyLocaleContext, f as CmssyCart, g as CmssyOrder, h as CmssyProduct } from './commerce-queries-MXclVwc1.cjs';
3
+ export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-MXclVwc1.cjs';
4
4
  import { ReactNode } from 'react';
5
5
 
6
6
  interface EditBridgeConfig {
package/dist/client.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { B as BlockSchema, a as BlockMeta, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, d as CmssyLayoutGroup, e as CmssyLocaleContext, f as CmssyCart, g as CmssyOrder, h as CmssyProduct } from './commerce-queries-CqCdTD31.js';
3
- export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-CqCdTD31.js';
2
+ import { B as BlockSchema, a as BlockMeta, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, d as CmssyLayoutGroup, e as CmssyLocaleContext, f as CmssyCart, g as CmssyOrder, h as CmssyProduct } from './commerce-queries-MXclVwc1.js';
3
+ export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-MXclVwc1.js';
4
4
  import { ReactNode } from 'react';
5
5
 
6
6
  interface EditBridgeConfig {
@@ -42,6 +42,13 @@ interface CmssyLayoutGroup {
42
42
  }
43
43
  declare function normalizeSlug(path: string | string[] | undefined): string;
44
44
  declare function fetchPage(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyPageData | null>;
45
+ declare function fetchPageById(config: CmssyClientConfig, pageId: string, options?: Pick<FetchPageOptions, "fetch" | "signal">): Promise<CmssyPageData | null>;
46
+ interface CmssyPageSummary {
47
+ slug: string;
48
+ updatedAt: string | null;
49
+ publishedAt: string | null;
50
+ }
51
+ declare function fetchPages(config: CmssyClientConfig, options?: Pick<FetchPageOptions, "fetch" | "signal">): Promise<CmssyPageSummary[]>;
45
52
  declare function fetchLayouts(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyLayoutGroup[]>;
46
53
 
47
54
  interface CmssyBranding {
@@ -408,4 +415,4 @@ interface CmssyOrder {
408
415
  createdAt?: string;
409
416
  }
410
417
 
411
- export { defineBlock as $, type AppToEditorMessage as A, type BlockSchema as B, type CmssyPageData as C, type CmssyRecordList as D, type EditorToAppMessage as E, type FieldDefinition as F, type CmssySiteConfig as G, FORM_QUERY as H, type FetchLikeResponse as I, type FetchPageOptions as J, type FieldType as K, MODEL_RECORDS_QUERY as L, MODEL_DEFINITIONS_QUERY as M, type ParentReadyMessage as N, type PatchMessage as O, PROTOCOL_VERSION as P, type RawLayoutBlock as Q, type RawBlock as R, type ReadyMessage as S, SITE_CONFIG_QUERY as T, SUBMIT_FORM_MUTATION as U, type SelectMessage as V, type SubmitFormInput as W, blocksToMeta as X, blocksToSchemas as Y, buildBlockContext as Z, buildBlockMap as _, type BlockMeta as a, fetchLayouts as a0, fetchPage as a1, isProtocolCompatible as a2, normalizeSlug as a3, type BlockDefinition as b, type CmssyFormDefinition as c, type CmssyLayoutGroup as d, type CmssyLocaleContext as e, type CmssyCart as f, type CmssyOrder as g, type CmssyProduct as h, type CmssyCartDiscount as i, type CmssyCartItem as j, type CmssyCartItemSnapshot as k, type CmssyOrderItem as l, type CmssyProductVariant as m, type FetchLike as n, type CmssyClientConfig as o, type BlockMap as p, type CmssyBlockContext as q, type BlockRect as r, type BoundsMessage as s, type ClickMessage as t, type CmssyBranding as u, type CmssyFormField as v, type CmssyFormSettings as w, type CmssyFormSubmitResponse as x, type CmssyModelDefinition as y, type CmssyModelRecord as z };
418
+ export { buildBlockMap as $, type AppToEditorMessage as A, type BlockSchema as B, type CmssyPageData as C, type CmssyModelRecord as D, type EditorToAppMessage as E, type FieldDefinition as F, type CmssyPageSummary as G, type CmssyRecordList as H, FORM_QUERY as I, type FetchLikeResponse as J, type FetchPageOptions as K, type FieldType as L, MODEL_DEFINITIONS_QUERY as M, MODEL_RECORDS_QUERY as N, type ParentReadyMessage as O, PROTOCOL_VERSION as P, type PatchMessage as Q, type RawBlock as R, type RawLayoutBlock as S, type ReadyMessage as T, SITE_CONFIG_QUERY as U, SUBMIT_FORM_MUTATION as V, type SelectMessage as W, type SubmitFormInput as X, blocksToMeta as Y, blocksToSchemas as Z, buildBlockContext as _, type BlockMeta as a, defineBlock as a0, fetchLayouts as a1, fetchPage as a2, fetchPageById as a3, fetchPages as a4, isProtocolCompatible as a5, normalizeSlug as a6, type BlockDefinition as b, type CmssyFormDefinition as c, type CmssyLayoutGroup as d, type CmssyLocaleContext as e, type CmssyCart as f, type CmssyOrder as g, type CmssyProduct as h, type CmssyCartDiscount as i, type CmssyCartItem as j, type CmssyCartItemSnapshot as k, type CmssyOrderItem as l, type CmssyProductVariant as m, type FetchLike as n, type CmssyClientConfig as o, type CmssySiteConfig as p, type BlockMap as q, type CmssyBlockContext as r, type BlockRect as s, type BoundsMessage as t, type ClickMessage as u, type CmssyBranding as v, type CmssyFormField as w, type CmssyFormSettings as x, type CmssyFormSubmitResponse as y, type CmssyModelDefinition as z };
@@ -42,6 +42,13 @@ interface CmssyLayoutGroup {
42
42
  }
43
43
  declare function normalizeSlug(path: string | string[] | undefined): string;
44
44
  declare function fetchPage(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyPageData | null>;
45
+ declare function fetchPageById(config: CmssyClientConfig, pageId: string, options?: Pick<FetchPageOptions, "fetch" | "signal">): Promise<CmssyPageData | null>;
46
+ interface CmssyPageSummary {
47
+ slug: string;
48
+ updatedAt: string | null;
49
+ publishedAt: string | null;
50
+ }
51
+ declare function fetchPages(config: CmssyClientConfig, options?: Pick<FetchPageOptions, "fetch" | "signal">): Promise<CmssyPageSummary[]>;
45
52
  declare function fetchLayouts(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyLayoutGroup[]>;
46
53
 
47
54
  interface CmssyBranding {
@@ -408,4 +415,4 @@ interface CmssyOrder {
408
415
  createdAt?: string;
409
416
  }
410
417
 
411
- export { defineBlock as $, type AppToEditorMessage as A, type BlockSchema as B, type CmssyPageData as C, type CmssyRecordList as D, type EditorToAppMessage as E, type FieldDefinition as F, type CmssySiteConfig as G, FORM_QUERY as H, type FetchLikeResponse as I, type FetchPageOptions as J, type FieldType as K, MODEL_RECORDS_QUERY as L, MODEL_DEFINITIONS_QUERY as M, type ParentReadyMessage as N, type PatchMessage as O, PROTOCOL_VERSION as P, type RawLayoutBlock as Q, type RawBlock as R, type ReadyMessage as S, SITE_CONFIG_QUERY as T, SUBMIT_FORM_MUTATION as U, type SelectMessage as V, type SubmitFormInput as W, blocksToMeta as X, blocksToSchemas as Y, buildBlockContext as Z, buildBlockMap as _, type BlockMeta as a, fetchLayouts as a0, fetchPage as a1, isProtocolCompatible as a2, normalizeSlug as a3, type BlockDefinition as b, type CmssyFormDefinition as c, type CmssyLayoutGroup as d, type CmssyLocaleContext as e, type CmssyCart as f, type CmssyOrder as g, type CmssyProduct as h, type CmssyCartDiscount as i, type CmssyCartItem as j, type CmssyCartItemSnapshot as k, type CmssyOrderItem as l, type CmssyProductVariant as m, type FetchLike as n, type CmssyClientConfig as o, type BlockMap as p, type CmssyBlockContext as q, type BlockRect as r, type BoundsMessage as s, type ClickMessage as t, type CmssyBranding as u, type CmssyFormField as v, type CmssyFormSettings as w, type CmssyFormSubmitResponse as x, type CmssyModelDefinition as y, type CmssyModelRecord as z };
418
+ export { buildBlockMap as $, type AppToEditorMessage as A, type BlockSchema as B, type CmssyPageData as C, type CmssyModelRecord as D, type EditorToAppMessage as E, type FieldDefinition as F, type CmssyPageSummary as G, type CmssyRecordList as H, FORM_QUERY as I, type FetchLikeResponse as J, type FetchPageOptions as K, type FieldType as L, MODEL_DEFINITIONS_QUERY as M, MODEL_RECORDS_QUERY as N, type ParentReadyMessage as O, PROTOCOL_VERSION as P, type PatchMessage as Q, type RawBlock as R, type RawLayoutBlock as S, type ReadyMessage as T, SITE_CONFIG_QUERY as U, SUBMIT_FORM_MUTATION as V, type SelectMessage as W, type SubmitFormInput as X, blocksToMeta as Y, blocksToSchemas as Z, buildBlockContext as _, type BlockMeta as a, defineBlock as a0, fetchLayouts as a1, fetchPage as a2, fetchPageById as a3, fetchPages as a4, isProtocolCompatible as a5, normalizeSlug as a6, type BlockDefinition as b, type CmssyFormDefinition as c, type CmssyLayoutGroup as d, type CmssyLocaleContext as e, type CmssyCart as f, type CmssyOrder as g, type CmssyProduct as h, type CmssyCartDiscount as i, type CmssyCartItem as j, type CmssyCartItemSnapshot as k, type CmssyOrderItem as l, type CmssyProductVariant as m, type FetchLike as n, type CmssyClientConfig as o, type CmssySiteConfig as p, type BlockMap as q, type CmssyBlockContext as r, type BlockRect as s, type BoundsMessage as t, type ClickMessage as u, type CmssyBranding as v, type CmssyFormField as w, type CmssyFormSettings as x, type CmssyFormSubmitResponse as y, type CmssyModelDefinition as z };
package/dist/index.cjs CHANGED
@@ -290,6 +290,19 @@ var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String
290
290
  publishedBlocks { id type content }
291
291
  }
292
292
  }`;
293
+ var PUBLIC_PAGE_BY_ID_QUERY = `query PublicPageById($workspaceSlug: String!, $pageId: ID!) {
294
+ publicPageById(workspaceSlug: $workspaceSlug, pageId: $pageId) {
295
+ id
296
+ publishedBlocks { id type content }
297
+ }
298
+ }`;
299
+ var PUBLIC_PAGES_QUERY = `query PublicPages($workspaceSlug: String!) {
300
+ publicPages(workspaceSlug: $workspaceSlug) {
301
+ slug
302
+ updatedAt
303
+ publishedAt
304
+ }
305
+ }`;
293
306
  var PUBLIC_PAGE_LAYOUTS_QUERY = `query PublicPageLayouts($workspaceSlug: String!, $pageSlug: String!, $previewSecret: String) {
294
307
  publicPageLayouts(workspaceSlug: $workspaceSlug, pageSlug: $pageSlug, previewSecret: $previewSecret) {
295
308
  position
@@ -355,6 +368,81 @@ async function fetchPage(config, path, options = {}) {
355
368
  const blocks = (draft ? page.blocks : page.publishedBlocks) ?? [];
356
369
  return { id: page.id, blocks };
357
370
  }
371
+ async function fetchPageById(config, pageId, options = {}) {
372
+ const doFetch = options.fetch ?? globalThis.fetch;
373
+ if (typeof doFetch !== "function") {
374
+ throw new Error(
375
+ "cmssy: no fetch implementation available - pass options.fetch"
376
+ );
377
+ }
378
+ const response = await doFetch(config.apiUrl, {
379
+ method: "POST",
380
+ headers: { "content-type": "application/json" },
381
+ body: JSON.stringify({
382
+ query: PUBLIC_PAGE_BY_ID_QUERY,
383
+ variables: { workspaceSlug: config.workspaceSlug, pageId }
384
+ }),
385
+ signal: options.signal
386
+ });
387
+ if (!response.ok) {
388
+ let detail = "";
389
+ try {
390
+ const body = await response.json();
391
+ if (body.errors && body.errors.length > 0) {
392
+ detail = ` - ${body.errors.map((error) => error.message ?? "GraphQL error").join("; ")}`;
393
+ }
394
+ } catch {
395
+ detail = "";
396
+ }
397
+ throw new Error(
398
+ `cmssy: page-by-id fetch failed (${response.status})${detail}`
399
+ );
400
+ }
401
+ let json;
402
+ try {
403
+ json = await response.json();
404
+ } catch {
405
+ throw new Error("cmssy: invalid JSON response from the page-by-id query");
406
+ }
407
+ if (json.errors && json.errors.length > 0) {
408
+ const message = json.errors.map((error) => error.message ?? "GraphQL error").join("; ");
409
+ throw new Error(`cmssy: page-by-id fetch error - ${message}`);
410
+ }
411
+ const page = json.data?.publicPageById;
412
+ if (!page) return null;
413
+ return { id: page.id, blocks: page.publishedBlocks ?? [] };
414
+ }
415
+ async function fetchPages(config, options = {}) {
416
+ const doFetch = options.fetch ?? globalThis.fetch;
417
+ if (typeof doFetch !== "function") {
418
+ throw new Error(
419
+ "cmssy: no fetch implementation available - pass options.fetch"
420
+ );
421
+ }
422
+ const response = await doFetch(config.apiUrl, {
423
+ method: "POST",
424
+ headers: { "content-type": "application/json" },
425
+ body: JSON.stringify({
426
+ query: PUBLIC_PAGES_QUERY,
427
+ variables: { workspaceSlug: config.workspaceSlug }
428
+ }),
429
+ signal: options.signal
430
+ });
431
+ if (!response.ok) {
432
+ throw new Error(`cmssy: pages fetch failed (${response.status})`);
433
+ }
434
+ let json;
435
+ try {
436
+ json = await response.json();
437
+ } catch {
438
+ throw new Error("cmssy: invalid JSON response from the pages query");
439
+ }
440
+ if (json.errors && json.errors.length > 0) {
441
+ const message = json.errors.map((error) => error.message ?? "GraphQL error").join("; ");
442
+ throw new Error(`cmssy: pages fetch error - ${message}`);
443
+ }
444
+ return json.data?.publicPages ?? [];
445
+ }
358
446
  async function fetchLayouts(config, path, options = {}) {
359
447
  const pageSlug = normalizeSlug(path);
360
448
  const doFetch = options.fetch ?? globalThis.fetch;
@@ -722,6 +810,9 @@ exports.createCmssyClient = createCmssyClient;
722
810
  exports.defineBlock = defineBlock;
723
811
  exports.fetchLayouts = fetchLayouts;
724
812
  exports.fetchPage = fetchPage;
813
+ exports.fetchPageById = fetchPageById;
814
+ exports.fetchPages = fetchPages;
815
+ exports.fetchSiteConfig = fetchSiteConfig;
725
816
  exports.fields = fields;
726
817
  exports.getBlockContentForLanguage = getBlockContentForLanguage;
727
818
  exports.graphqlRequest = graphqlRequest;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, d as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, n as FetchLike, o as CmssyClientConfig, R as RawBlock, e as CmssyLocaleContext, p as BlockMap, q as CmssyBlockContext } from './commerce-queries-CqCdTD31.cjs';
2
- export { a as BlockMeta, r as BlockRect, B as BlockSchema, s as BoundsMessage, t as ClickMessage, u as CmssyBranding, f as CmssyCart, i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, v as CmssyFormField, w as CmssyFormSettings, x as CmssyFormSubmitResponse, y as CmssyModelDefinition, z as CmssyModelRecord, g as CmssyOrder, h as CmssyProduct, m as CmssyProductVariant, D as CmssyRecordList, G as CmssySiteConfig, H as FORM_QUERY, I as FetchLikeResponse, J as FetchPageOptions, K as FieldType, M as MODEL_DEFINITIONS_QUERY, L as MODEL_RECORDS_QUERY, P as PROTOCOL_VERSION, N as ParentReadyMessage, O as PatchMessage, Q as RawLayoutBlock, S as ReadyMessage, T as SITE_CONFIG_QUERY, U as SUBMIT_FORM_MUTATION, V as SelectMessage, W as SubmitFormInput, X as blocksToMeta, Y as blocksToSchemas, Z as buildBlockContext, _ as buildBlockMap, $ as defineBlock, a0 as fetchLayouts, a1 as fetchPage, a2 as isProtocolCompatible, a3 as normalizeSlug } from './commerce-queries-CqCdTD31.cjs';
1
+ import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, d as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, n as FetchLike, o as CmssyClientConfig, p as CmssySiteConfig, R as RawBlock, e as CmssyLocaleContext, q as BlockMap, r as CmssyBlockContext } from './commerce-queries-MXclVwc1.cjs';
2
+ export { a as BlockMeta, s as BlockRect, B as BlockSchema, t as BoundsMessage, u as ClickMessage, v as CmssyBranding, f as CmssyCart, i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, w as CmssyFormField, x as CmssyFormSettings, y as CmssyFormSubmitResponse, z as CmssyModelDefinition, D as CmssyModelRecord, g as CmssyOrder, G as CmssyPageSummary, h as CmssyProduct, m as CmssyProductVariant, H as CmssyRecordList, I as FORM_QUERY, J as FetchLikeResponse, K as FetchPageOptions, L as FieldType, M as MODEL_DEFINITIONS_QUERY, N as MODEL_RECORDS_QUERY, P as PROTOCOL_VERSION, O as ParentReadyMessage, Q as PatchMessage, S as RawLayoutBlock, T as ReadyMessage, U as SITE_CONFIG_QUERY, V as SUBMIT_FORM_MUTATION, W as SelectMessage, X as SubmitFormInput, Y as blocksToMeta, Z as blocksToSchemas, _ as buildBlockContext, $ as buildBlockMap, a0 as defineBlock, a1 as fetchLayouts, a2 as fetchPage, a3 as fetchPageById, a4 as fetchPages, a5 as isProtocolCompatible, a6 as normalizeSlug } from './commerce-queries-MXclVwc1.cjs';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import 'react';
5
5
 
@@ -65,6 +65,7 @@ interface GraphqlRequestOptions {
65
65
  }
66
66
  declare function graphqlRequest<T>(config: CmssyClientConfig, query: string, variables: Record<string, unknown>, options?: GraphqlRequestOptions, label?: string): Promise<T>;
67
67
 
68
+ declare function fetchSiteConfig(config: CmssyClientConfig, options?: GraphqlRequestOptions): Promise<CmssySiteConfig | null>;
68
69
  declare function resolveWorkspaceId(config: CmssyClientConfig, options?: GraphqlRequestOptions): Promise<string>;
69
70
 
70
71
  interface QueryScopedOptions extends GraphqlRequestOptions {
@@ -125,4 +126,4 @@ interface UnknownBlockProps {
125
126
  }
126
127
  declare function UnknownBlock({ type }: UnknownBlockProps): react_jsx_runtime.JSX.Element;
127
128
 
128
- export { AppToEditorMessage, BlockDefinition, BlockMap, CmssyBlock, CmssyBlockContext, type CmssyBlockProps, type CmssyClient, CmssyClientConfig, CmssyFormDefinition, CmssyLayoutGroup, CmssyLocaleContext, CmssyPageData, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, type CmssySiteLocales, EditorToAppMessage, FetchLike, type FieldControl, FieldDefinition, type GraphqlRequestOptions, type PostTarget, type QueryScopedOptions, RawBlock, UnknownBlock, type UnknownBlockProps, buildLocaleSwitchHref, collectFormIds, createCmssyClient, fields, getBlockContentForLanguage, graphqlRequest, localizeHref, localizeHtmlLinks, normalizeOrigin, parseEditorMessage, postToEditor, resolveForms, resolveSiteLocales, resolveWorkspaceId, splitLocaleFromPath };
129
+ export { AppToEditorMessage, BlockDefinition, BlockMap, CmssyBlock, CmssyBlockContext, type CmssyBlockProps, type CmssyClient, CmssyClientConfig, CmssyFormDefinition, CmssyLayoutGroup, CmssyLocaleContext, CmssyPageData, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, CmssySiteConfig, type CmssySiteLocales, EditorToAppMessage, FetchLike, type FieldControl, FieldDefinition, type GraphqlRequestOptions, type PostTarget, type QueryScopedOptions, RawBlock, UnknownBlock, type UnknownBlockProps, buildLocaleSwitchHref, collectFormIds, createCmssyClient, fetchSiteConfig, fields, getBlockContentForLanguage, graphqlRequest, localizeHref, localizeHtmlLinks, normalizeOrigin, parseEditorMessage, postToEditor, resolveForms, resolveSiteLocales, resolveWorkspaceId, splitLocaleFromPath };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, d as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, n as FetchLike, o as CmssyClientConfig, R as RawBlock, e as CmssyLocaleContext, p as BlockMap, q as CmssyBlockContext } from './commerce-queries-CqCdTD31.js';
2
- export { a as BlockMeta, r as BlockRect, B as BlockSchema, s as BoundsMessage, t as ClickMessage, u as CmssyBranding, f as CmssyCart, i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, v as CmssyFormField, w as CmssyFormSettings, x as CmssyFormSubmitResponse, y as CmssyModelDefinition, z as CmssyModelRecord, g as CmssyOrder, h as CmssyProduct, m as CmssyProductVariant, D as CmssyRecordList, G as CmssySiteConfig, H as FORM_QUERY, I as FetchLikeResponse, J as FetchPageOptions, K as FieldType, M as MODEL_DEFINITIONS_QUERY, L as MODEL_RECORDS_QUERY, P as PROTOCOL_VERSION, N as ParentReadyMessage, O as PatchMessage, Q as RawLayoutBlock, S as ReadyMessage, T as SITE_CONFIG_QUERY, U as SUBMIT_FORM_MUTATION, V as SelectMessage, W as SubmitFormInput, X as blocksToMeta, Y as blocksToSchemas, Z as buildBlockContext, _ as buildBlockMap, $ as defineBlock, a0 as fetchLayouts, a1 as fetchPage, a2 as isProtocolCompatible, a3 as normalizeSlug } from './commerce-queries-CqCdTD31.js';
1
+ import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, d as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, n as FetchLike, o as CmssyClientConfig, p as CmssySiteConfig, R as RawBlock, e as CmssyLocaleContext, q as BlockMap, r as CmssyBlockContext } from './commerce-queries-MXclVwc1.js';
2
+ export { a as BlockMeta, s as BlockRect, B as BlockSchema, t as BoundsMessage, u as ClickMessage, v as CmssyBranding, f as CmssyCart, i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, w as CmssyFormField, x as CmssyFormSettings, y as CmssyFormSubmitResponse, z as CmssyModelDefinition, D as CmssyModelRecord, g as CmssyOrder, G as CmssyPageSummary, h as CmssyProduct, m as CmssyProductVariant, H as CmssyRecordList, I as FORM_QUERY, J as FetchLikeResponse, K as FetchPageOptions, L as FieldType, M as MODEL_DEFINITIONS_QUERY, N as MODEL_RECORDS_QUERY, P as PROTOCOL_VERSION, O as ParentReadyMessage, Q as PatchMessage, S as RawLayoutBlock, T as ReadyMessage, U as SITE_CONFIG_QUERY, V as SUBMIT_FORM_MUTATION, W as SelectMessage, X as SubmitFormInput, Y as blocksToMeta, Z as blocksToSchemas, _ as buildBlockContext, $ as buildBlockMap, a0 as defineBlock, a1 as fetchLayouts, a2 as fetchPage, a3 as fetchPageById, a4 as fetchPages, a5 as isProtocolCompatible, a6 as normalizeSlug } from './commerce-queries-MXclVwc1.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import 'react';
5
5
 
@@ -65,6 +65,7 @@ interface GraphqlRequestOptions {
65
65
  }
66
66
  declare function graphqlRequest<T>(config: CmssyClientConfig, query: string, variables: Record<string, unknown>, options?: GraphqlRequestOptions, label?: string): Promise<T>;
67
67
 
68
+ declare function fetchSiteConfig(config: CmssyClientConfig, options?: GraphqlRequestOptions): Promise<CmssySiteConfig | null>;
68
69
  declare function resolveWorkspaceId(config: CmssyClientConfig, options?: GraphqlRequestOptions): Promise<string>;
69
70
 
70
71
  interface QueryScopedOptions extends GraphqlRequestOptions {
@@ -125,4 +126,4 @@ interface UnknownBlockProps {
125
126
  }
126
127
  declare function UnknownBlock({ type }: UnknownBlockProps): react_jsx_runtime.JSX.Element;
127
128
 
128
- export { AppToEditorMessage, BlockDefinition, BlockMap, CmssyBlock, CmssyBlockContext, type CmssyBlockProps, type CmssyClient, CmssyClientConfig, CmssyFormDefinition, CmssyLayoutGroup, CmssyLocaleContext, CmssyPageData, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, type CmssySiteLocales, EditorToAppMessage, FetchLike, type FieldControl, FieldDefinition, type GraphqlRequestOptions, type PostTarget, type QueryScopedOptions, RawBlock, UnknownBlock, type UnknownBlockProps, buildLocaleSwitchHref, collectFormIds, createCmssyClient, fields, getBlockContentForLanguage, graphqlRequest, localizeHref, localizeHtmlLinks, normalizeOrigin, parseEditorMessage, postToEditor, resolveForms, resolveSiteLocales, resolveWorkspaceId, splitLocaleFromPath };
129
+ export { AppToEditorMessage, BlockDefinition, BlockMap, CmssyBlock, CmssyBlockContext, type CmssyBlockProps, type CmssyClient, CmssyClientConfig, CmssyFormDefinition, CmssyLayoutGroup, CmssyLocaleContext, CmssyPageData, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, CmssySiteConfig, type CmssySiteLocales, EditorToAppMessage, FetchLike, type FieldControl, FieldDefinition, type GraphqlRequestOptions, type PostTarget, type QueryScopedOptions, RawBlock, UnknownBlock, type UnknownBlockProps, buildLocaleSwitchHref, collectFormIds, createCmssyClient, fetchSiteConfig, fields, getBlockContentForLanguage, graphqlRequest, localizeHref, localizeHtmlLinks, normalizeOrigin, parseEditorMessage, postToEditor, resolveForms, resolveSiteLocales, resolveWorkspaceId, splitLocaleFromPath };
package/dist/index.js CHANGED
@@ -288,6 +288,19 @@ var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String
288
288
  publishedBlocks { id type content }
289
289
  }
290
290
  }`;
291
+ var PUBLIC_PAGE_BY_ID_QUERY = `query PublicPageById($workspaceSlug: String!, $pageId: ID!) {
292
+ publicPageById(workspaceSlug: $workspaceSlug, pageId: $pageId) {
293
+ id
294
+ publishedBlocks { id type content }
295
+ }
296
+ }`;
297
+ var PUBLIC_PAGES_QUERY = `query PublicPages($workspaceSlug: String!) {
298
+ publicPages(workspaceSlug: $workspaceSlug) {
299
+ slug
300
+ updatedAt
301
+ publishedAt
302
+ }
303
+ }`;
291
304
  var PUBLIC_PAGE_LAYOUTS_QUERY = `query PublicPageLayouts($workspaceSlug: String!, $pageSlug: String!, $previewSecret: String) {
292
305
  publicPageLayouts(workspaceSlug: $workspaceSlug, pageSlug: $pageSlug, previewSecret: $previewSecret) {
293
306
  position
@@ -353,6 +366,81 @@ async function fetchPage(config, path, options = {}) {
353
366
  const blocks = (draft ? page.blocks : page.publishedBlocks) ?? [];
354
367
  return { id: page.id, blocks };
355
368
  }
369
+ async function fetchPageById(config, pageId, options = {}) {
370
+ const doFetch = options.fetch ?? globalThis.fetch;
371
+ if (typeof doFetch !== "function") {
372
+ throw new Error(
373
+ "cmssy: no fetch implementation available - pass options.fetch"
374
+ );
375
+ }
376
+ const response = await doFetch(config.apiUrl, {
377
+ method: "POST",
378
+ headers: { "content-type": "application/json" },
379
+ body: JSON.stringify({
380
+ query: PUBLIC_PAGE_BY_ID_QUERY,
381
+ variables: { workspaceSlug: config.workspaceSlug, pageId }
382
+ }),
383
+ signal: options.signal
384
+ });
385
+ if (!response.ok) {
386
+ let detail = "";
387
+ try {
388
+ const body = await response.json();
389
+ if (body.errors && body.errors.length > 0) {
390
+ detail = ` - ${body.errors.map((error) => error.message ?? "GraphQL error").join("; ")}`;
391
+ }
392
+ } catch {
393
+ detail = "";
394
+ }
395
+ throw new Error(
396
+ `cmssy: page-by-id fetch failed (${response.status})${detail}`
397
+ );
398
+ }
399
+ let json;
400
+ try {
401
+ json = await response.json();
402
+ } catch {
403
+ throw new Error("cmssy: invalid JSON response from the page-by-id query");
404
+ }
405
+ if (json.errors && json.errors.length > 0) {
406
+ const message = json.errors.map((error) => error.message ?? "GraphQL error").join("; ");
407
+ throw new Error(`cmssy: page-by-id fetch error - ${message}`);
408
+ }
409
+ const page = json.data?.publicPageById;
410
+ if (!page) return null;
411
+ return { id: page.id, blocks: page.publishedBlocks ?? [] };
412
+ }
413
+ async function fetchPages(config, options = {}) {
414
+ const doFetch = options.fetch ?? globalThis.fetch;
415
+ if (typeof doFetch !== "function") {
416
+ throw new Error(
417
+ "cmssy: no fetch implementation available - pass options.fetch"
418
+ );
419
+ }
420
+ const response = await doFetch(config.apiUrl, {
421
+ method: "POST",
422
+ headers: { "content-type": "application/json" },
423
+ body: JSON.stringify({
424
+ query: PUBLIC_PAGES_QUERY,
425
+ variables: { workspaceSlug: config.workspaceSlug }
426
+ }),
427
+ signal: options.signal
428
+ });
429
+ if (!response.ok) {
430
+ throw new Error(`cmssy: pages fetch failed (${response.status})`);
431
+ }
432
+ let json;
433
+ try {
434
+ json = await response.json();
435
+ } catch {
436
+ throw new Error("cmssy: invalid JSON response from the pages query");
437
+ }
438
+ if (json.errors && json.errors.length > 0) {
439
+ const message = json.errors.map((error) => error.message ?? "GraphQL error").join("; ");
440
+ throw new Error(`cmssy: pages fetch error - ${message}`);
441
+ }
442
+ return json.data?.publicPages ?? [];
443
+ }
356
444
  async function fetchLayouts(config, path, options = {}) {
357
445
  const pageSlug = normalizeSlug(path);
358
446
  const doFetch = options.fetch ?? globalThis.fetch;
@@ -700,4 +788,4 @@ function CmssyBlock({
700
788
  );
701
789
  }
702
790
 
703
- export { CmssyBlock, CmssyServerLayout, CmssyServerPage, FORM_QUERY, MODEL_DEFINITIONS_QUERY, MODEL_RECORDS_QUERY, PROTOCOL_VERSION, SITE_CONFIG_QUERY, SUBMIT_FORM_MUTATION, UnknownBlock, blocksToMeta, blocksToSchemas, buildBlockContext, buildBlockMap, buildLocaleSwitchHref, collectFormIds, createCmssyClient, defineBlock, fetchLayouts, fetchPage, fields, getBlockContentForLanguage, graphqlRequest, isProtocolCompatible, localizeHref, localizeHtmlLinks, normalizeOrigin, normalizeSlug, parseEditorMessage, postToEditor, resolveForms, resolveSiteLocales, resolveWorkspaceId, splitLocaleFromPath };
791
+ export { CmssyBlock, CmssyServerLayout, CmssyServerPage, FORM_QUERY, MODEL_DEFINITIONS_QUERY, MODEL_RECORDS_QUERY, PROTOCOL_VERSION, SITE_CONFIG_QUERY, SUBMIT_FORM_MUTATION, UnknownBlock, blocksToMeta, blocksToSchemas, buildBlockContext, buildBlockMap, buildLocaleSwitchHref, collectFormIds, createCmssyClient, defineBlock, fetchLayouts, fetchPage, fetchPageById, fetchPages, fetchSiteConfig, fields, getBlockContentForLanguage, graphqlRequest, isProtocolCompatible, localizeHref, localizeHtmlLinks, normalizeOrigin, normalizeSlug, parseEditorMessage, postToEditor, resolveForms, resolveSiteLocales, resolveWorkspaceId, splitLocaleFromPath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/react",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
5
5
  "keywords": [
6
6
  "cmssy",