@cmssy/react 0.14.0 → 0.16.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/README.md CHANGED
@@ -39,7 +39,7 @@ the CMS at runtime.
39
39
  ```tsx
40
40
  import { fetchPage, CmssyServerPage } from "@cmssy/react";
41
41
 
42
- const page = await fetchPage({ workspaceSlug: "acme" }, pathSegments);
42
+ const page = await fetchPage({ org: "acme-org", workspaceSlug: "acme" }, pathSegments);
43
43
 
44
44
  return <CmssyServerPage page={page} blocks={blocks} locale="en" />;
45
45
  ```
@@ -56,7 +56,7 @@ the exported documents):
56
56
  ```ts
57
57
  import { createCmssyClient, MODEL_RECORDS_QUERY } from "@cmssy/react";
58
58
 
59
- const cmssy = createCmssyClient({ workspaceSlug: "acme" });
59
+ const cmssy = createCmssyClient({ org: "acme-org", workspaceSlug: "acme" });
60
60
 
61
61
  // raw query (you own scoping)
62
62
  await cmssy.query(MY_QUERY, vars);
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-D5duQ6QF.cjs';
3
- export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-D5duQ6QF.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-D9lXIaCQ.cjs';
3
+ export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-D9lXIaCQ.cjs';
4
4
  import { ReactNode } from 'react';
5
5
  import '@cmssy/types';
6
6
 
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-D5duQ6QF.js';
3
- export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-D5duQ6QF.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-D9lXIaCQ.js';
3
+ export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-D9lXIaCQ.js';
4
4
  import { ReactNode } from 'react';
5
5
  import '@cmssy/types';
6
6
 
@@ -8,9 +8,22 @@ import { FieldConditionGroup, FieldType } from '@cmssy/types';
8
8
  */
9
9
  declare const DEFAULT_CMSSY_API_URL = "https://api.cmssy.io/graphql";
10
10
  declare function resolveApiUrl(apiUrl: string | undefined): string;
11
+ /**
12
+ * Public delivery endpoint for a workspace: the org-scoped path
13
+ * `{base}/public/{orgSlug}/{workspaceSlug}/graphql`. `apiUrl` is the GraphQL
14
+ * base (its trailing `/graphql` is stripped); the org path is what tells the
15
+ * backend which workspace to serve, so slugs only need to be unique per org.
16
+ */
17
+ declare function resolvePublicUrl(config: CmssyClientConfig): string;
11
18
  interface CmssyClientConfig {
12
- /** Full GraphQL delivery endpoint. Defaults to {@link DEFAULT_CMSSY_API_URL}. */
19
+ /**
20
+ * Full GraphQL endpoint (used as-is for authenticated requests). Defaults to
21
+ * {@link DEFAULT_CMSSY_API_URL}. Public reads strip its trailing `/graphql`
22
+ * and append the org-scoped path (see {@link resolvePublicUrl}).
23
+ */
13
24
  apiUrl?: string;
25
+ /** Organization slug - part of the org-scoped delivery path. */
26
+ org: string;
14
27
  workspaceSlug: string;
15
28
  }
16
29
  interface FetchLikeResponse {
@@ -94,7 +107,7 @@ interface CmssySiteConfig {
94
107
  previewUrl: string | null;
95
108
  branding: CmssyBranding | null;
96
109
  }
97
- declare const SITE_CONFIG_QUERY = "query PublicSiteConfig($workspaceSlug: String!) {\n publicSiteConfig(workspaceSlug: $workspaceSlug) {\n id\n workspaceId\n siteName\n defaultLanguage\n enabledLanguages\n enabledFeatures\n notFoundPageId\n previewUrl\n branding {\n brandName\n logoUrl\n faviconUrl\n ogImageUrl\n }\n }\n}";
110
+ declare const SITE_CONFIG_QUERY = "query PublicSiteConfig($workspaceSlug: String!) {\n public {\n siteConfig(workspaceSlug: $workspaceSlug) {\n id\n workspaceId\n siteName\n defaultLanguage\n enabledLanguages\n enabledFeatures\n notFoundPageId\n previewUrl\n branding {\n brandName\n logoUrl\n faviconUrl\n ogImageUrl\n }\n }\n }\n}";
98
111
  interface CmssyModelDefinition {
99
112
  id: string;
100
113
  name: string;
@@ -475,4 +488,4 @@ interface CmssyOrder {
475
488
  createdAt?: string;
476
489
  }
477
490
 
478
- 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, DEFAULT_CMSSY_API_URL as O, FORM_QUERY as P, type FetchLikeResponse as Q, type RawBlock as R, type FetchPageOptions 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, resolveApiUrl as ae, 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 };
491
+ 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, DEFAULT_CMSSY_API_URL as O, FORM_QUERY as P, type FetchLikeResponse as Q, type RawBlock as R, type FetchPageOptions 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, resolveApiUrl as ae, resolvePublicUrl as af, 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 };
@@ -8,9 +8,22 @@ import { FieldConditionGroup, FieldType } from '@cmssy/types';
8
8
  */
9
9
  declare const DEFAULT_CMSSY_API_URL = "https://api.cmssy.io/graphql";
10
10
  declare function resolveApiUrl(apiUrl: string | undefined): string;
11
+ /**
12
+ * Public delivery endpoint for a workspace: the org-scoped path
13
+ * `{base}/public/{orgSlug}/{workspaceSlug}/graphql`. `apiUrl` is the GraphQL
14
+ * base (its trailing `/graphql` is stripped); the org path is what tells the
15
+ * backend which workspace to serve, so slugs only need to be unique per org.
16
+ */
17
+ declare function resolvePublicUrl(config: CmssyClientConfig): string;
11
18
  interface CmssyClientConfig {
12
- /** Full GraphQL delivery endpoint. Defaults to {@link DEFAULT_CMSSY_API_URL}. */
19
+ /**
20
+ * Full GraphQL endpoint (used as-is for authenticated requests). Defaults to
21
+ * {@link DEFAULT_CMSSY_API_URL}. Public reads strip its trailing `/graphql`
22
+ * and append the org-scoped path (see {@link resolvePublicUrl}).
23
+ */
13
24
  apiUrl?: string;
25
+ /** Organization slug - part of the org-scoped delivery path. */
26
+ org: string;
14
27
  workspaceSlug: string;
15
28
  }
16
29
  interface FetchLikeResponse {
@@ -94,7 +107,7 @@ interface CmssySiteConfig {
94
107
  previewUrl: string | null;
95
108
  branding: CmssyBranding | null;
96
109
  }
97
- declare const SITE_CONFIG_QUERY = "query PublicSiteConfig($workspaceSlug: String!) {\n publicSiteConfig(workspaceSlug: $workspaceSlug) {\n id\n workspaceId\n siteName\n defaultLanguage\n enabledLanguages\n enabledFeatures\n notFoundPageId\n previewUrl\n branding {\n brandName\n logoUrl\n faviconUrl\n ogImageUrl\n }\n }\n}";
110
+ declare const SITE_CONFIG_QUERY = "query PublicSiteConfig($workspaceSlug: String!) {\n public {\n siteConfig(workspaceSlug: $workspaceSlug) {\n id\n workspaceId\n siteName\n defaultLanguage\n enabledLanguages\n enabledFeatures\n notFoundPageId\n previewUrl\n branding {\n brandName\n logoUrl\n faviconUrl\n ogImageUrl\n }\n }\n }\n}";
98
111
  interface CmssyModelDefinition {
99
112
  id: string;
100
113
  name: string;
@@ -475,4 +488,4 @@ interface CmssyOrder {
475
488
  createdAt?: string;
476
489
  }
477
490
 
478
- 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, DEFAULT_CMSSY_API_URL as O, FORM_QUERY as P, type FetchLikeResponse as Q, type RawBlock as R, type FetchPageOptions 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, resolveApiUrl as ae, 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 };
491
+ 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, DEFAULT_CMSSY_API_URL as O, FORM_QUERY as P, type FetchLikeResponse as Q, type RawBlock as R, type FetchPageOptions 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, resolveApiUrl as ae, resolvePublicUrl as af, 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
@@ -316,6 +316,10 @@ function resolveApiUrl(apiUrl) {
316
316
  const fromEnv = env?.CMSSY_API_URL?.trim() ?? "";
317
317
  return fromEnv.length > 0 ? fromEnv : DEFAULT_CMSSY_API_URL;
318
318
  }
319
+ function resolvePublicUrl(config) {
320
+ const base = resolveApiUrl(config.apiUrl).replace(/\/graphql\/?$/, "");
321
+ return `${base}/public/${config.org}/${config.workspaceSlug}/graphql`;
322
+ }
319
323
  var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String) {
320
324
  public {
321
325
  page {
@@ -412,7 +416,7 @@ async function fetchPage(config, path, options = {}) {
412
416
  headers["x-workspace-id"] = options.workspaceId;
413
417
  }
414
418
  }
415
- const response = await doFetch(resolveApiUrl(config.apiUrl), {
419
+ const response = await doFetch(resolvePublicUrl(config), {
416
420
  method: "POST",
417
421
  headers,
418
422
  body: JSON.stringify({
@@ -461,7 +465,7 @@ async function fetchPageById(config, pageId, options = {}) {
461
465
  "cmssy: no fetch implementation available - pass options.fetch"
462
466
  );
463
467
  }
464
- const response = await doFetch(resolveApiUrl(config.apiUrl), {
468
+ const response = await doFetch(resolvePublicUrl(config), {
465
469
  method: "POST",
466
470
  headers: { "content-type": "application/json" },
467
471
  body: JSON.stringify({
@@ -505,7 +509,7 @@ async function fetchPages(config, options = {}) {
505
509
  "cmssy: no fetch implementation available - pass options.fetch"
506
510
  );
507
511
  }
508
- const response = await doFetch(resolveApiUrl(config.apiUrl), {
512
+ const response = await doFetch(resolvePublicUrl(config), {
509
513
  method: "POST",
510
514
  headers: { "content-type": "application/json" },
511
515
  body: JSON.stringify({
@@ -537,7 +541,7 @@ async function fetchPageMeta(config, path, options = {}) {
537
541
  "cmssy: no fetch implementation available - pass options.fetch"
538
542
  );
539
543
  }
540
- const response = await doFetch(resolveApiUrl(config.apiUrl), {
544
+ const response = await doFetch(resolvePublicUrl(config), {
541
545
  method: "POST",
542
546
  headers: { "content-type": "application/json" },
543
547
  body: JSON.stringify({
@@ -571,7 +575,7 @@ async function fetchLayouts(config, path, options = {}) {
571
575
  }
572
576
  const trimmedSecret = options.previewSecret?.trim();
573
577
  const previewSecret = trimmedSecret ? trimmedSecret : null;
574
- const response = await doFetch(resolveApiUrl(config.apiUrl), {
578
+ const response = await doFetch(resolvePublicUrl(config), {
575
579
  method: "POST",
576
580
  headers: { "content-type": "application/json" },
577
581
  body: JSON.stringify({
@@ -608,7 +612,8 @@ async function graphqlRequest(config, query, variables, options = {}, label = "r
608
612
  "cmssy: no fetch implementation available - pass options.fetch"
609
613
  );
610
614
  }
611
- const response = await doFetch(resolveApiUrl(config.apiUrl), {
615
+ const url = options.public ? resolvePublicUrl(config) : resolveApiUrl(config.apiUrl);
616
+ const response = await doFetch(url, {
612
617
  method: "POST",
613
618
  headers: { "content-type": "application/json", ...options.headers },
614
619
  body: JSON.stringify({ query, variables }),
@@ -641,20 +646,22 @@ async function graphqlRequest(config, query, variables, options = {}, label = "r
641
646
 
642
647
  // src/data/queries.ts
643
648
  var SITE_CONFIG_QUERY = `query PublicSiteConfig($workspaceSlug: String!) {
644
- publicSiteConfig(workspaceSlug: $workspaceSlug) {
645
- id
646
- workspaceId
647
- siteName
648
- defaultLanguage
649
- enabledLanguages
650
- enabledFeatures
651
- notFoundPageId
652
- previewUrl
653
- branding {
654
- brandName
655
- logoUrl
656
- faviconUrl
657
- ogImageUrl
649
+ public {
650
+ siteConfig(workspaceSlug: $workspaceSlug) {
651
+ id
652
+ workspaceId
653
+ siteName
654
+ defaultLanguage
655
+ enabledLanguages
656
+ enabledFeatures
657
+ notFoundPageId
658
+ previewUrl
659
+ branding {
660
+ brandName
661
+ logoUrl
662
+ faviconUrl
663
+ ogImageUrl
664
+ }
658
665
  }
659
666
  }
660
667
  }`;
@@ -700,10 +707,10 @@ async function fetchSiteConfig(config, options = {}) {
700
707
  config,
701
708
  SITE_CONFIG_QUERY,
702
709
  { workspaceSlug: config.workspaceSlug },
703
- options,
710
+ { ...options, public: true },
704
711
  "site config query"
705
712
  );
706
- return data.publicSiteConfig ?? null;
713
+ return data.public?.siteConfig ?? null;
707
714
  }
708
715
  async function resolveWorkspaceId(config, options = {}) {
709
716
  const siteConfig = await fetchSiteConfig(config, options);
@@ -806,7 +813,7 @@ var TTL_MS = 6e4;
806
813
  var MAX_ENTRIES = 64;
807
814
  var cache = /* @__PURE__ */ new Map();
808
815
  async function resolveSiteLocales(config, options) {
809
- const key = `${resolveApiUrl(config.apiUrl)}::${config.workspaceSlug}`;
816
+ const key = `${resolveApiUrl(config.apiUrl)}::${config.org}::${config.workspaceSlug}`;
810
817
  const cached = cache.get(key);
811
818
  if (cached && cached.expires > Date.now()) return cached.value;
812
819
  cache.delete(key);
@@ -816,10 +823,10 @@ async function resolveSiteLocales(config, options) {
816
823
  config,
817
824
  SITE_CONFIG_QUERY,
818
825
  { workspaceSlug: config.workspaceSlug },
819
- options,
826
+ { ...options, public: true },
820
827
  "site config"
821
828
  );
822
- const siteConfig = data.publicSiteConfig;
829
+ const siteConfig = data.public?.siteConfig ?? null;
823
830
  const defaultLocale = siteConfig?.defaultLanguage || "en";
824
831
  const enabled = siteConfig?.enabledLanguages ?? [];
825
832
  value = {
@@ -958,6 +965,7 @@ exports.parseEditorMessage = parseEditorMessage;
958
965
  exports.postToEditor = postToEditor;
959
966
  exports.resolveApiUrl = resolveApiUrl;
960
967
  exports.resolveForms = resolveForms;
968
+ exports.resolvePublicUrl = resolvePublicUrl;
961
969
  exports.resolveSiteLocales = resolveSiteLocales;
962
970
  exports.resolveWorkspaceId = resolveWorkspaceId;
963
971
  exports.splitLocaleFromPath = splitLocaleFromPath;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
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-D5duQ6QF.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 DEFAULT_CMSSY_API_URL, P as FORM_QUERY, Q as FetchLikeResponse, S as FetchPageOptions, 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, ae as resolveApiUrl } from './commerce-queries-D5duQ6QF.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-D9lXIaCQ.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 DEFAULT_CMSSY_API_URL, P as FORM_QUERY, Q as FetchLikeResponse, S as FetchPageOptions, 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, ae as resolveApiUrl, af as resolvePublicUrl } from './commerce-queries-D9lXIaCQ.cjs';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  export { FieldCondition, FieldConditionGroup, FieldConditionLogic, FieldType, evaluateFieldConditionGroup } from '@cmssy/types';
5
5
  import 'react';
@@ -76,6 +76,12 @@ interface GraphqlRequestOptions {
76
76
  fetch?: FetchLike;
77
77
  signal?: AbortSignal;
78
78
  headers?: Record<string, string>;
79
+ /**
80
+ * Route through the org-scoped public delivery path instead of the base
81
+ * `/graphql` endpoint. Set for unauthenticated public queries so the backend
82
+ * resolves the workspace from the URL rather than a global slug lookup.
83
+ */
84
+ public?: boolean;
79
85
  }
80
86
  declare function graphqlRequest<T>(config: CmssyClientConfig, query: string, variables: Record<string, unknown>, options?: GraphqlRequestOptions, label?: string): Promise<T>;
81
87
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
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-D5duQ6QF.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 DEFAULT_CMSSY_API_URL, P as FORM_QUERY, Q as FetchLikeResponse, S as FetchPageOptions, 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, ae as resolveApiUrl } from './commerce-queries-D5duQ6QF.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-D9lXIaCQ.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 DEFAULT_CMSSY_API_URL, P as FORM_QUERY, Q as FetchLikeResponse, S as FetchPageOptions, 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, ae as resolveApiUrl, af as resolvePublicUrl } from './commerce-queries-D9lXIaCQ.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  export { FieldCondition, FieldConditionGroup, FieldConditionLogic, FieldType, evaluateFieldConditionGroup } from '@cmssy/types';
5
5
  import 'react';
@@ -76,6 +76,12 @@ interface GraphqlRequestOptions {
76
76
  fetch?: FetchLike;
77
77
  signal?: AbortSignal;
78
78
  headers?: Record<string, string>;
79
+ /**
80
+ * Route through the org-scoped public delivery path instead of the base
81
+ * `/graphql` endpoint. Set for unauthenticated public queries so the backend
82
+ * resolves the workspace from the URL rather than a global slug lookup.
83
+ */
84
+ public?: boolean;
79
85
  }
80
86
  declare function graphqlRequest<T>(config: CmssyClientConfig, query: string, variables: Record<string, unknown>, options?: GraphqlRequestOptions, label?: string): Promise<T>;
81
87
 
package/dist/index.js CHANGED
@@ -314,6 +314,10 @@ function resolveApiUrl(apiUrl) {
314
314
  const fromEnv = env?.CMSSY_API_URL?.trim() ?? "";
315
315
  return fromEnv.length > 0 ? fromEnv : DEFAULT_CMSSY_API_URL;
316
316
  }
317
+ function resolvePublicUrl(config) {
318
+ const base = resolveApiUrl(config.apiUrl).replace(/\/graphql\/?$/, "");
319
+ return `${base}/public/${config.org}/${config.workspaceSlug}/graphql`;
320
+ }
317
321
  var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String) {
318
322
  public {
319
323
  page {
@@ -410,7 +414,7 @@ async function fetchPage(config, path, options = {}) {
410
414
  headers["x-workspace-id"] = options.workspaceId;
411
415
  }
412
416
  }
413
- const response = await doFetch(resolveApiUrl(config.apiUrl), {
417
+ const response = await doFetch(resolvePublicUrl(config), {
414
418
  method: "POST",
415
419
  headers,
416
420
  body: JSON.stringify({
@@ -459,7 +463,7 @@ async function fetchPageById(config, pageId, options = {}) {
459
463
  "cmssy: no fetch implementation available - pass options.fetch"
460
464
  );
461
465
  }
462
- const response = await doFetch(resolveApiUrl(config.apiUrl), {
466
+ const response = await doFetch(resolvePublicUrl(config), {
463
467
  method: "POST",
464
468
  headers: { "content-type": "application/json" },
465
469
  body: JSON.stringify({
@@ -503,7 +507,7 @@ async function fetchPages(config, options = {}) {
503
507
  "cmssy: no fetch implementation available - pass options.fetch"
504
508
  );
505
509
  }
506
- const response = await doFetch(resolveApiUrl(config.apiUrl), {
510
+ const response = await doFetch(resolvePublicUrl(config), {
507
511
  method: "POST",
508
512
  headers: { "content-type": "application/json" },
509
513
  body: JSON.stringify({
@@ -535,7 +539,7 @@ async function fetchPageMeta(config, path, options = {}) {
535
539
  "cmssy: no fetch implementation available - pass options.fetch"
536
540
  );
537
541
  }
538
- const response = await doFetch(resolveApiUrl(config.apiUrl), {
542
+ const response = await doFetch(resolvePublicUrl(config), {
539
543
  method: "POST",
540
544
  headers: { "content-type": "application/json" },
541
545
  body: JSON.stringify({
@@ -569,7 +573,7 @@ async function fetchLayouts(config, path, options = {}) {
569
573
  }
570
574
  const trimmedSecret = options.previewSecret?.trim();
571
575
  const previewSecret = trimmedSecret ? trimmedSecret : null;
572
- const response = await doFetch(resolveApiUrl(config.apiUrl), {
576
+ const response = await doFetch(resolvePublicUrl(config), {
573
577
  method: "POST",
574
578
  headers: { "content-type": "application/json" },
575
579
  body: JSON.stringify({
@@ -606,7 +610,8 @@ async function graphqlRequest(config, query, variables, options = {}, label = "r
606
610
  "cmssy: no fetch implementation available - pass options.fetch"
607
611
  );
608
612
  }
609
- const response = await doFetch(resolveApiUrl(config.apiUrl), {
613
+ const url = options.public ? resolvePublicUrl(config) : resolveApiUrl(config.apiUrl);
614
+ const response = await doFetch(url, {
610
615
  method: "POST",
611
616
  headers: { "content-type": "application/json", ...options.headers },
612
617
  body: JSON.stringify({ query, variables }),
@@ -639,20 +644,22 @@ async function graphqlRequest(config, query, variables, options = {}, label = "r
639
644
 
640
645
  // src/data/queries.ts
641
646
  var SITE_CONFIG_QUERY = `query PublicSiteConfig($workspaceSlug: String!) {
642
- publicSiteConfig(workspaceSlug: $workspaceSlug) {
643
- id
644
- workspaceId
645
- siteName
646
- defaultLanguage
647
- enabledLanguages
648
- enabledFeatures
649
- notFoundPageId
650
- previewUrl
651
- branding {
652
- brandName
653
- logoUrl
654
- faviconUrl
655
- ogImageUrl
647
+ public {
648
+ siteConfig(workspaceSlug: $workspaceSlug) {
649
+ id
650
+ workspaceId
651
+ siteName
652
+ defaultLanguage
653
+ enabledLanguages
654
+ enabledFeatures
655
+ notFoundPageId
656
+ previewUrl
657
+ branding {
658
+ brandName
659
+ logoUrl
660
+ faviconUrl
661
+ ogImageUrl
662
+ }
656
663
  }
657
664
  }
658
665
  }`;
@@ -698,10 +705,10 @@ async function fetchSiteConfig(config, options = {}) {
698
705
  config,
699
706
  SITE_CONFIG_QUERY,
700
707
  { workspaceSlug: config.workspaceSlug },
701
- options,
708
+ { ...options, public: true },
702
709
  "site config query"
703
710
  );
704
- return data.publicSiteConfig ?? null;
711
+ return data.public?.siteConfig ?? null;
705
712
  }
706
713
  async function resolveWorkspaceId(config, options = {}) {
707
714
  const siteConfig = await fetchSiteConfig(config, options);
@@ -804,7 +811,7 @@ var TTL_MS = 6e4;
804
811
  var MAX_ENTRIES = 64;
805
812
  var cache = /* @__PURE__ */ new Map();
806
813
  async function resolveSiteLocales(config, options) {
807
- const key = `${resolveApiUrl(config.apiUrl)}::${config.workspaceSlug}`;
814
+ const key = `${resolveApiUrl(config.apiUrl)}::${config.org}::${config.workspaceSlug}`;
808
815
  const cached = cache.get(key);
809
816
  if (cached && cached.expires > Date.now()) return cached.value;
810
817
  cache.delete(key);
@@ -814,10 +821,10 @@ async function resolveSiteLocales(config, options) {
814
821
  config,
815
822
  SITE_CONFIG_QUERY,
816
823
  { workspaceSlug: config.workspaceSlug },
817
- options,
824
+ { ...options, public: true },
818
825
  "site config"
819
826
  );
820
- const siteConfig = data.publicSiteConfig;
827
+ const siteConfig = data.public?.siteConfig ?? null;
821
828
  const defaultLocale = siteConfig?.defaultLanguage || "en";
822
829
  const enabled = siteConfig?.enabledLanguages ?? [];
823
830
  value = {
@@ -915,4 +922,4 @@ function CmssyBlock({
915
922
  );
916
923
  }
917
924
 
918
- export { CmssyBlock, CmssyServerLayout, CmssyServerPage, DEFAULT_CMSSY_API_URL, 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, resolveApiUrl, resolveForms, resolveSiteLocales, resolveWorkspaceId, splitLocaleFromPath };
925
+ export { CmssyBlock, CmssyServerLayout, CmssyServerPage, DEFAULT_CMSSY_API_URL, 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, resolveApiUrl, resolveForms, resolvePublicUrl, resolveSiteLocales, resolveWorkspaceId, splitLocaleFromPath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/react",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
5
5
  "keywords": [
6
6
  "cmssy",