@cmssy/react 0.5.3 → 0.5.5

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.cjs CHANGED
@@ -447,7 +447,7 @@ function useDragAgent(config) {
447
447
  }
448
448
 
449
449
  // src/components/block-context.ts
450
- function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, forms) {
450
+ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, forms, extra) {
451
451
  return {
452
452
  locale: {
453
453
  current: locale,
@@ -455,7 +455,9 @@ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, for
455
455
  enabled: enabledLocales && enabledLocales.length > 0 ? enabledLocales : Array.from(/* @__PURE__ */ new Set([defaultLocale, locale]))
456
456
  },
457
457
  isPreview: isPreview ?? false,
458
- forms
458
+ forms,
459
+ ...{},
460
+ ...{}
459
461
  };
460
462
  }
461
463
 
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-BIiXoA6A.cjs';
3
- export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-BIiXoA6A.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-D4tjQ9BL.cjs';
3
+ export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-D4tjQ9BL.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-BIiXoA6A.js';
3
- export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-BIiXoA6A.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-D4tjQ9BL.js';
3
+ export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-D4tjQ9BL.js';
4
4
  import { ReactNode } from 'react';
5
5
 
6
6
  interface EditBridgeConfig {
package/dist/client.js CHANGED
@@ -445,7 +445,7 @@ function useDragAgent(config) {
445
445
  }
446
446
 
447
447
  // src/components/block-context.ts
448
- function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, forms) {
448
+ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, forms, extra) {
449
449
  return {
450
450
  locale: {
451
451
  current: locale,
@@ -453,7 +453,9 @@ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, for
453
453
  enabled: enabledLocales && enabledLocales.length > 0 ? enabledLocales : Array.from(/* @__PURE__ */ new Set([defaultLocale, locale]))
454
454
  },
455
455
  isPreview: isPreview ?? false,
456
- forms
456
+ forms,
457
+ ...{},
458
+ ...{}
457
459
  };
458
460
  }
459
461
 
@@ -50,6 +50,15 @@ interface CmssyPageSummary {
50
50
  publishedAt: string | null;
51
51
  }
52
52
  declare function fetchPages(config: CmssyClientConfig, options?: Pick<FetchPageOptions, "fetch" | "signal">): Promise<CmssyPageSummary[]>;
53
+ type CmssyLocalizedValue = Record<string, string> | string | null;
54
+ interface CmssyPageMeta {
55
+ id: string;
56
+ seoTitle: CmssyLocalizedValue;
57
+ seoDescription: CmssyLocalizedValue;
58
+ seoKeywords: string[] | null;
59
+ displayName: CmssyLocalizedValue;
60
+ }
61
+ declare function fetchPageMeta(config: CmssyClientConfig, path: string | string[] | undefined, options?: Pick<FetchPageOptions, "fetch" | "signal">): Promise<CmssyPageMeta | null>;
53
62
  declare function fetchLayouts(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyLayoutGroup[]>;
54
63
 
55
64
  interface CmssyBranding {
@@ -146,12 +155,30 @@ interface CmssyLocaleContext {
146
155
  default: string;
147
156
  enabled: string[];
148
157
  }
158
+ interface CmssyBlockMember {
159
+ recordId: string;
160
+ email: string;
161
+ }
162
+ interface CmssyBlockAuthContext {
163
+ isAuthenticated: boolean;
164
+ member: CmssyBlockMember | null;
165
+ }
166
+ interface CmssyBlockWorkspace {
167
+ id: string;
168
+ slug: string;
169
+ }
149
170
  interface CmssyBlockContext {
150
171
  locale: CmssyLocaleContext;
151
172
  isPreview: boolean;
152
173
  forms?: Record<string, CmssyFormDefinition>;
174
+ auth?: CmssyBlockAuthContext;
175
+ workspace?: CmssyBlockWorkspace;
176
+ }
177
+ interface BuildBlockContextExtra {
178
+ auth?: CmssyBlockAuthContext;
179
+ workspace?: CmssyBlockWorkspace;
153
180
  }
154
- declare function buildBlockContext(locale: string, defaultLocale: string, enabledLocales?: string[], isPreview?: boolean, forms?: Record<string, CmssyFormDefinition>): CmssyBlockContext;
181
+ declare function buildBlockContext(locale: string, defaultLocale: string, enabledLocales?: string[], isPreview?: boolean, forms?: Record<string, CmssyFormDefinition>, extra?: BuildBlockContextExtra): CmssyBlockContext;
155
182
 
156
183
  declare const PROTOCOL_VERSION = 1;
157
184
  type FieldType = "singleLine" | "multiLine" | "richText" | "numeric" | "date" | "media" | "link" | "select" | "multiselect" | "boolean" | "color" | "repeater";
@@ -416,4 +443,4 @@ interface CmssyOrder {
416
443
  createdAt?: string;
417
444
  }
418
445
 
419
- 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 };
446
+ export { SUBMIT_FORM_MUTATION as $, type AppToEditorMessage as A, type BlockSchema as B, type CmssyPageData as C, type CmssyFormField as D, type EditorToAppMessage as E, type FieldDefinition as F, type CmssyFormSettings as G, type CmssyFormSubmitResponse as H, type CmssyLocalizedValue as I, type CmssyModelDefinition as J, type CmssyModelRecord as K, type CmssyPageMeta as L, type CmssyPageSummary as M, type CmssyRecordList as N, FORM_QUERY as O, type FetchLikeResponse as P, type FetchPageOptions as Q, type RawBlock as R, type FieldType as S, MODEL_DEFINITIONS_QUERY as T, MODEL_RECORDS_QUERY as U, PROTOCOL_VERSION as V, type ParentReadyMessage as W, type PatchMessage as X, type RawLayoutBlock as Y, type ReadyMessage as Z, SITE_CONFIG_QUERY as _, type BlockMeta as a, type SelectMessage as a0, type SubmitFormInput as a1, blocksToMeta as a2, blocksToSchemas as a3, buildBlockContext as a4, buildBlockMap as a5, defineBlock as a6, fetchLayouts as a7, fetchPage as a8, fetchPageById as a9, fetchPageMeta as aa, fetchPages as ab, isProtocolCompatible as ac, normalizeSlug as ad, 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 CmssyBlockAuthContext as n, type CmssyBlockWorkspace as o, type FetchLike as p, type CmssyClientConfig as q, type CmssySiteConfig as r, type BlockMap as s, type CmssyBlockContext as t, type BlockRect as u, type BoundsMessage as v, type BuildBlockContextExtra as w, type ClickMessage as x, type CmssyBlockMember as y, type CmssyBranding as z };
@@ -50,6 +50,15 @@ interface CmssyPageSummary {
50
50
  publishedAt: string | null;
51
51
  }
52
52
  declare function fetchPages(config: CmssyClientConfig, options?: Pick<FetchPageOptions, "fetch" | "signal">): Promise<CmssyPageSummary[]>;
53
+ type CmssyLocalizedValue = Record<string, string> | string | null;
54
+ interface CmssyPageMeta {
55
+ id: string;
56
+ seoTitle: CmssyLocalizedValue;
57
+ seoDescription: CmssyLocalizedValue;
58
+ seoKeywords: string[] | null;
59
+ displayName: CmssyLocalizedValue;
60
+ }
61
+ declare function fetchPageMeta(config: CmssyClientConfig, path: string | string[] | undefined, options?: Pick<FetchPageOptions, "fetch" | "signal">): Promise<CmssyPageMeta | null>;
53
62
  declare function fetchLayouts(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyLayoutGroup[]>;
54
63
 
55
64
  interface CmssyBranding {
@@ -146,12 +155,30 @@ interface CmssyLocaleContext {
146
155
  default: string;
147
156
  enabled: string[];
148
157
  }
158
+ interface CmssyBlockMember {
159
+ recordId: string;
160
+ email: string;
161
+ }
162
+ interface CmssyBlockAuthContext {
163
+ isAuthenticated: boolean;
164
+ member: CmssyBlockMember | null;
165
+ }
166
+ interface CmssyBlockWorkspace {
167
+ id: string;
168
+ slug: string;
169
+ }
149
170
  interface CmssyBlockContext {
150
171
  locale: CmssyLocaleContext;
151
172
  isPreview: boolean;
152
173
  forms?: Record<string, CmssyFormDefinition>;
174
+ auth?: CmssyBlockAuthContext;
175
+ workspace?: CmssyBlockWorkspace;
176
+ }
177
+ interface BuildBlockContextExtra {
178
+ auth?: CmssyBlockAuthContext;
179
+ workspace?: CmssyBlockWorkspace;
153
180
  }
154
- declare function buildBlockContext(locale: string, defaultLocale: string, enabledLocales?: string[], isPreview?: boolean, forms?: Record<string, CmssyFormDefinition>): CmssyBlockContext;
181
+ declare function buildBlockContext(locale: string, defaultLocale: string, enabledLocales?: string[], isPreview?: boolean, forms?: Record<string, CmssyFormDefinition>, extra?: BuildBlockContextExtra): CmssyBlockContext;
155
182
 
156
183
  declare const PROTOCOL_VERSION = 1;
157
184
  type FieldType = "singleLine" | "multiLine" | "richText" | "numeric" | "date" | "media" | "link" | "select" | "multiselect" | "boolean" | "color" | "repeater";
@@ -416,4 +443,4 @@ interface CmssyOrder {
416
443
  createdAt?: string;
417
444
  }
418
445
 
419
- 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 };
446
+ export { SUBMIT_FORM_MUTATION as $, type AppToEditorMessage as A, type BlockSchema as B, type CmssyPageData as C, type CmssyFormField as D, type EditorToAppMessage as E, type FieldDefinition as F, type CmssyFormSettings as G, type CmssyFormSubmitResponse as H, type CmssyLocalizedValue as I, type CmssyModelDefinition as J, type CmssyModelRecord as K, type CmssyPageMeta as L, type CmssyPageSummary as M, type CmssyRecordList as N, FORM_QUERY as O, type FetchLikeResponse as P, type FetchPageOptions as Q, type RawBlock as R, type FieldType as S, MODEL_DEFINITIONS_QUERY as T, MODEL_RECORDS_QUERY as U, PROTOCOL_VERSION as V, type ParentReadyMessage as W, type PatchMessage as X, type RawLayoutBlock as Y, type ReadyMessage as Z, SITE_CONFIG_QUERY as _, type BlockMeta as a, type SelectMessage as a0, type SubmitFormInput as a1, blocksToMeta as a2, blocksToSchemas as a3, buildBlockContext as a4, buildBlockMap as a5, defineBlock as a6, fetchLayouts as a7, fetchPage as a8, fetchPageById as a9, fetchPageMeta as aa, fetchPages as ab, isProtocolCompatible as ac, normalizeSlug as ad, 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 CmssyBlockAuthContext as n, type CmssyBlockWorkspace as o, type FetchLike as p, type CmssyClientConfig as q, type CmssySiteConfig as r, type BlockMap as s, type CmssyBlockContext as t, type BlockRect as u, type BoundsMessage as v, type BuildBlockContextExtra as w, type ClickMessage as x, type CmssyBlockMember as y, type CmssyBranding as z };
package/dist/index.cjs CHANGED
@@ -92,7 +92,7 @@ function getBlockContentForLanguage(content, locale, defaultLocale = "en", avail
92
92
  }
93
93
 
94
94
  // src/components/block-context.ts
95
- function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, forms) {
95
+ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, forms, extra) {
96
96
  return {
97
97
  locale: {
98
98
  current: locale,
@@ -100,7 +100,9 @@ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, for
100
100
  enabled: enabledLocales && enabledLocales.length > 0 ? enabledLocales : Array.from(/* @__PURE__ */ new Set([defaultLocale, locale]))
101
101
  },
102
102
  isPreview: isPreview ?? false,
103
- forms
103
+ forms,
104
+ ...extra?.auth ? { auth: extra.auth } : {},
105
+ ...extra?.workspace ? { workspace: extra.workspace } : {}
104
106
  };
105
107
  }
106
108
  var WARN_CAP = 256;
@@ -139,7 +141,9 @@ async function CmssyServerPage({
139
141
  locale = "en",
140
142
  defaultLocale = "en",
141
143
  enabledLocales,
142
- forms
144
+ forms,
145
+ auth,
146
+ workspace
143
147
  }) {
144
148
  if (!page) return null;
145
149
  const map = buildBlockMap(blocks);
@@ -149,7 +153,8 @@ async function CmssyServerPage({
149
153
  defaultLocale,
150
154
  enabledLocales,
151
155
  false,
152
- forms
156
+ forms,
157
+ { auth, workspace }
153
158
  );
154
159
  const resolved = await Promise.all(
155
160
  page.blocks.map(async (block) => {
@@ -304,6 +309,15 @@ var PUBLIC_PAGES_QUERY = `query PublicPages($workspaceSlug: String!) {
304
309
  publishedAt
305
310
  }
306
311
  }`;
312
+ var PUBLIC_PAGE_META_QUERY = `query PublicPageMeta($workspaceSlug: String!, $slug: String!) {
313
+ publicPage(workspaceSlug: $workspaceSlug, slug: $slug) {
314
+ id
315
+ seoTitle
316
+ seoDescription
317
+ seoKeywords
318
+ displayName
319
+ }
320
+ }`;
307
321
  var PUBLIC_PAGE_LAYOUTS_QUERY = `query PublicPageLayouts($workspaceSlug: String!, $pageSlug: String!, $previewSecret: String) {
308
322
  publicPageLayouts(workspaceSlug: $workspaceSlug, pageSlug: $pageSlug, previewSecret: $previewSecret) {
309
323
  position
@@ -444,6 +458,38 @@ async function fetchPages(config, options = {}) {
444
458
  }
445
459
  return json.data?.publicPages ?? [];
446
460
  }
461
+ async function fetchPageMeta(config, path, options = {}) {
462
+ const slug = normalizeSlug(path);
463
+ const doFetch = options.fetch ?? globalThis.fetch;
464
+ if (typeof doFetch !== "function") {
465
+ throw new Error(
466
+ "cmssy: no fetch implementation available - pass options.fetch"
467
+ );
468
+ }
469
+ const response = await doFetch(config.apiUrl, {
470
+ method: "POST",
471
+ headers: { "content-type": "application/json" },
472
+ body: JSON.stringify({
473
+ query: PUBLIC_PAGE_META_QUERY,
474
+ variables: { workspaceSlug: config.workspaceSlug, slug }
475
+ }),
476
+ signal: options.signal
477
+ });
478
+ if (!response.ok) {
479
+ throw new Error(`cmssy: page meta fetch failed (${response.status})`);
480
+ }
481
+ let json;
482
+ try {
483
+ json = await response.json();
484
+ } catch {
485
+ throw new Error("cmssy: invalid JSON response from the page meta query");
486
+ }
487
+ if (json.errors && json.errors.length > 0) {
488
+ const message = json.errors.map((error) => error.message ?? "GraphQL error").join("; ");
489
+ throw new Error(`cmssy: page meta fetch error - ${message}`);
490
+ }
491
+ return json.data?.publicPage ?? null;
492
+ }
447
493
  async function fetchLayouts(config, path, options = {}) {
448
494
  const pageSlug = normalizeSlug(path);
449
495
  const doFetch = options.fetch ?? globalThis.fetch;
@@ -812,6 +858,7 @@ exports.defineBlock = defineBlock;
812
858
  exports.fetchLayouts = fetchLayouts;
813
859
  exports.fetchPage = fetchPage;
814
860
  exports.fetchPageById = fetchPageById;
861
+ exports.fetchPageMeta = fetchPageMeta;
815
862
  exports.fetchPages = fetchPages;
816
863
  exports.fetchSiteConfig = fetchSiteConfig;
817
864
  exports.fields = fields;
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, p as CmssySiteConfig, R as RawBlock, e as CmssyLocaleContext, q as BlockMap, r as CmssyBlockContext } from './commerce-queries-BIiXoA6A.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-BIiXoA6A.cjs';
1
+ import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, n as CmssyBlockAuthContext, o as CmssyBlockWorkspace, d as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, p as FetchLike, q as CmssyClientConfig, r as CmssySiteConfig, R as RawBlock, e as CmssyLocaleContext, s as BlockMap, t as CmssyBlockContext } from './commerce-queries-D4tjQ9BL.cjs';
2
+ export { a as BlockMeta, u as BlockRect, B as BlockSchema, v as BoundsMessage, w as BuildBlockContextExtra, x as ClickMessage, y as CmssyBlockMember, z as CmssyBranding, f as CmssyCart, i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, D as CmssyFormField, G as CmssyFormSettings, H as CmssyFormSubmitResponse, I as CmssyLocalizedValue, J as CmssyModelDefinition, K as CmssyModelRecord, g as CmssyOrder, L as CmssyPageMeta, M as CmssyPageSummary, h as CmssyProduct, m as CmssyProductVariant, N as CmssyRecordList, O as FORM_QUERY, P as FetchLikeResponse, Q as FetchPageOptions, S as FieldType, T as MODEL_DEFINITIONS_QUERY, U as MODEL_RECORDS_QUERY, V as PROTOCOL_VERSION, W as ParentReadyMessage, X as PatchMessage, Y as RawLayoutBlock, Z as ReadyMessage, _ as SITE_CONFIG_QUERY, $ as SUBMIT_FORM_MUTATION, a0 as SelectMessage, a1 as SubmitFormInput, a2 as blocksToMeta, a3 as blocksToSchemas, a4 as buildBlockContext, a5 as buildBlockMap, a6 as defineBlock, a7 as fetchLayouts, a8 as fetchPage, a9 as fetchPageById, aa as fetchPageMeta, ab as fetchPages, ac as isProtocolCompatible, ad as normalizeSlug } from './commerce-queries-D4tjQ9BL.cjs';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import 'react';
5
5
 
@@ -30,13 +30,17 @@ interface CmssyServerPageProps {
30
30
  enabledLocales?: string[];
31
31
  /** Form definitions referenced by page blocks, exposed via context.forms. */
32
32
  forms?: Record<string, CmssyFormDefinition>;
33
+ /** Member auth state, exposed via context.auth. Resolved by createCmssyPage. */
34
+ auth?: CmssyBlockAuthContext;
35
+ /** Workspace identity, exposed via context.workspace. Resolved by createCmssyPage. */
36
+ workspace?: CmssyBlockWorkspace;
33
37
  }
34
38
  /**
35
39
  * Async React Server Component (Next.js App Router / RSC). It runs each block's
36
40
  * loader server-side before rendering, so it must be rendered in a server
37
41
  * component tree (as `createCmssyPage` does) - not in a client component.
38
42
  */
39
- declare function CmssyServerPage({ page, blocks, locale, defaultLocale, enabledLocales, forms, }: CmssyServerPageProps): Promise<react_jsx_runtime.JSX.Element | null>;
43
+ declare function CmssyServerPage({ page, blocks, locale, defaultLocale, enabledLocales, forms, auth, workspace, }: CmssyServerPageProps): Promise<react_jsx_runtime.JSX.Element | null>;
40
44
 
41
45
  interface CmssyServerLayoutProps {
42
46
  groups: CmssyLayoutGroup[];
@@ -126,4 +130,4 @@ interface UnknownBlockProps {
126
130
  }
127
131
  declare function UnknownBlock({ type }: UnknownBlockProps): react_jsx_runtime.JSX.Element;
128
132
 
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 };
133
+ export { AppToEditorMessage, BlockDefinition, BlockMap, CmssyBlock, CmssyBlockAuthContext, CmssyBlockContext, type CmssyBlockProps, CmssyBlockWorkspace, 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, p as CmssySiteConfig, R as RawBlock, e as CmssyLocaleContext, q as BlockMap, r as CmssyBlockContext } from './commerce-queries-BIiXoA6A.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-BIiXoA6A.js';
1
+ import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, n as CmssyBlockAuthContext, o as CmssyBlockWorkspace, d as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, p as FetchLike, q as CmssyClientConfig, r as CmssySiteConfig, R as RawBlock, e as CmssyLocaleContext, s as BlockMap, t as CmssyBlockContext } from './commerce-queries-D4tjQ9BL.js';
2
+ export { a as BlockMeta, u as BlockRect, B as BlockSchema, v as BoundsMessage, w as BuildBlockContextExtra, x as ClickMessage, y as CmssyBlockMember, z as CmssyBranding, f as CmssyCart, i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, D as CmssyFormField, G as CmssyFormSettings, H as CmssyFormSubmitResponse, I as CmssyLocalizedValue, J as CmssyModelDefinition, K as CmssyModelRecord, g as CmssyOrder, L as CmssyPageMeta, M as CmssyPageSummary, h as CmssyProduct, m as CmssyProductVariant, N as CmssyRecordList, O as FORM_QUERY, P as FetchLikeResponse, Q as FetchPageOptions, S as FieldType, T as MODEL_DEFINITIONS_QUERY, U as MODEL_RECORDS_QUERY, V as PROTOCOL_VERSION, W as ParentReadyMessage, X as PatchMessage, Y as RawLayoutBlock, Z as ReadyMessage, _ as SITE_CONFIG_QUERY, $ as SUBMIT_FORM_MUTATION, a0 as SelectMessage, a1 as SubmitFormInput, a2 as blocksToMeta, a3 as blocksToSchemas, a4 as buildBlockContext, a5 as buildBlockMap, a6 as defineBlock, a7 as fetchLayouts, a8 as fetchPage, a9 as fetchPageById, aa as fetchPageMeta, ab as fetchPages, ac as isProtocolCompatible, ad as normalizeSlug } from './commerce-queries-D4tjQ9BL.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import 'react';
5
5
 
@@ -30,13 +30,17 @@ interface CmssyServerPageProps {
30
30
  enabledLocales?: string[];
31
31
  /** Form definitions referenced by page blocks, exposed via context.forms. */
32
32
  forms?: Record<string, CmssyFormDefinition>;
33
+ /** Member auth state, exposed via context.auth. Resolved by createCmssyPage. */
34
+ auth?: CmssyBlockAuthContext;
35
+ /** Workspace identity, exposed via context.workspace. Resolved by createCmssyPage. */
36
+ workspace?: CmssyBlockWorkspace;
33
37
  }
34
38
  /**
35
39
  * Async React Server Component (Next.js App Router / RSC). It runs each block's
36
40
  * loader server-side before rendering, so it must be rendered in a server
37
41
  * component tree (as `createCmssyPage` does) - not in a client component.
38
42
  */
39
- declare function CmssyServerPage({ page, blocks, locale, defaultLocale, enabledLocales, forms, }: CmssyServerPageProps): Promise<react_jsx_runtime.JSX.Element | null>;
43
+ declare function CmssyServerPage({ page, blocks, locale, defaultLocale, enabledLocales, forms, auth, workspace, }: CmssyServerPageProps): Promise<react_jsx_runtime.JSX.Element | null>;
40
44
 
41
45
  interface CmssyServerLayoutProps {
42
46
  groups: CmssyLayoutGroup[];
@@ -126,4 +130,4 @@ interface UnknownBlockProps {
126
130
  }
127
131
  declare function UnknownBlock({ type }: UnknownBlockProps): react_jsx_runtime.JSX.Element;
128
132
 
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 };
133
+ export { AppToEditorMessage, BlockDefinition, BlockMap, CmssyBlock, CmssyBlockAuthContext, CmssyBlockContext, type CmssyBlockProps, CmssyBlockWorkspace, 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
@@ -90,7 +90,7 @@ function getBlockContentForLanguage(content, locale, defaultLocale = "en", avail
90
90
  }
91
91
 
92
92
  // src/components/block-context.ts
93
- function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, forms) {
93
+ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, forms, extra) {
94
94
  return {
95
95
  locale: {
96
96
  current: locale,
@@ -98,7 +98,9 @@ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, for
98
98
  enabled: enabledLocales && enabledLocales.length > 0 ? enabledLocales : Array.from(/* @__PURE__ */ new Set([defaultLocale, locale]))
99
99
  },
100
100
  isPreview: isPreview ?? false,
101
- forms
101
+ forms,
102
+ ...extra?.auth ? { auth: extra.auth } : {},
103
+ ...extra?.workspace ? { workspace: extra.workspace } : {}
102
104
  };
103
105
  }
104
106
  var WARN_CAP = 256;
@@ -137,7 +139,9 @@ async function CmssyServerPage({
137
139
  locale = "en",
138
140
  defaultLocale = "en",
139
141
  enabledLocales,
140
- forms
142
+ forms,
143
+ auth,
144
+ workspace
141
145
  }) {
142
146
  if (!page) return null;
143
147
  const map = buildBlockMap(blocks);
@@ -147,7 +151,8 @@ async function CmssyServerPage({
147
151
  defaultLocale,
148
152
  enabledLocales,
149
153
  false,
150
- forms
154
+ forms,
155
+ { auth, workspace }
151
156
  );
152
157
  const resolved = await Promise.all(
153
158
  page.blocks.map(async (block) => {
@@ -302,6 +307,15 @@ var PUBLIC_PAGES_QUERY = `query PublicPages($workspaceSlug: String!) {
302
307
  publishedAt
303
308
  }
304
309
  }`;
310
+ var PUBLIC_PAGE_META_QUERY = `query PublicPageMeta($workspaceSlug: String!, $slug: String!) {
311
+ publicPage(workspaceSlug: $workspaceSlug, slug: $slug) {
312
+ id
313
+ seoTitle
314
+ seoDescription
315
+ seoKeywords
316
+ displayName
317
+ }
318
+ }`;
305
319
  var PUBLIC_PAGE_LAYOUTS_QUERY = `query PublicPageLayouts($workspaceSlug: String!, $pageSlug: String!, $previewSecret: String) {
306
320
  publicPageLayouts(workspaceSlug: $workspaceSlug, pageSlug: $pageSlug, previewSecret: $previewSecret) {
307
321
  position
@@ -442,6 +456,38 @@ async function fetchPages(config, options = {}) {
442
456
  }
443
457
  return json.data?.publicPages ?? [];
444
458
  }
459
+ async function fetchPageMeta(config, path, options = {}) {
460
+ const slug = normalizeSlug(path);
461
+ const doFetch = options.fetch ?? globalThis.fetch;
462
+ if (typeof doFetch !== "function") {
463
+ throw new Error(
464
+ "cmssy: no fetch implementation available - pass options.fetch"
465
+ );
466
+ }
467
+ const response = await doFetch(config.apiUrl, {
468
+ method: "POST",
469
+ headers: { "content-type": "application/json" },
470
+ body: JSON.stringify({
471
+ query: PUBLIC_PAGE_META_QUERY,
472
+ variables: { workspaceSlug: config.workspaceSlug, slug }
473
+ }),
474
+ signal: options.signal
475
+ });
476
+ if (!response.ok) {
477
+ throw new Error(`cmssy: page meta fetch failed (${response.status})`);
478
+ }
479
+ let json;
480
+ try {
481
+ json = await response.json();
482
+ } catch {
483
+ throw new Error("cmssy: invalid JSON response from the page meta query");
484
+ }
485
+ if (json.errors && json.errors.length > 0) {
486
+ const message = json.errors.map((error) => error.message ?? "GraphQL error").join("; ");
487
+ throw new Error(`cmssy: page meta fetch error - ${message}`);
488
+ }
489
+ return json.data?.publicPage ?? null;
490
+ }
445
491
  async function fetchLayouts(config, path, options = {}) {
446
492
  const pageSlug = normalizeSlug(path);
447
493
  const doFetch = options.fetch ?? globalThis.fetch;
@@ -789,4 +835,4 @@ function CmssyBlock({
789
835
  );
790
836
  }
791
837
 
792
- 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 };
838
+ 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, fetchPageMeta, 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.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
5
5
  "keywords": [
6
6
  "cmssy",