@cmssy/react 0.5.5 → 0.5.6

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-D4tjQ9BL.cjs';
3
- export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-D4tjQ9BL.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-Dx6EW4Sr.cjs';
3
+ export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-Dx6EW4Sr.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-D4tjQ9BL.js';
3
- export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-D4tjQ9BL.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-Dx6EW4Sr.js';
3
+ export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-Dx6EW4Sr.js';
4
4
  import { ReactNode } from 'react';
5
5
 
6
6
  interface EditBridgeConfig {
@@ -1,7 +1,16 @@
1
1
  import { ComponentType } from 'react';
2
2
 
3
+ /**
4
+ * The cmssy cloud GraphQL delivery endpoint. It is the same for every workspace,
5
+ * so consumers never need to set it - `apiUrl` defaults to this. Self-hosted /
6
+ * staging deployments override it via config.
7
+ */
8
+ declare const DEFAULT_CMSSY_API_URL = "https://api.cmssy.io/graphql";
9
+ /** Resolves `apiUrl`, falling back to the cmssy cloud endpoint when unset. */
10
+ declare function resolveApiUrl(apiUrl: string | undefined): string;
3
11
  interface CmssyClientConfig {
4
- apiUrl: string;
12
+ /** Full GraphQL delivery endpoint. Defaults to {@link DEFAULT_CMSSY_API_URL}. */
13
+ apiUrl?: string;
5
14
  workspaceSlug: string;
6
15
  }
7
16
  interface FetchLikeResponse {
@@ -443,4 +452,4 @@ interface CmssyOrder {
443
452
  createdAt?: string;
444
453
  }
445
454
 
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 };
455
+ export { SITE_CONFIG_QUERY 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, type FieldType as T, MODEL_DEFINITIONS_QUERY as U, MODEL_RECORDS_QUERY as V, PROTOCOL_VERSION as W, type ParentReadyMessage as X, type PatchMessage as Y, type RawLayoutBlock as Z, type ReadyMessage as _, type BlockMeta as a, SUBMIT_FORM_MUTATION as a0, type SelectMessage as a1, type SubmitFormInput as a2, blocksToMeta as a3, blocksToSchemas as a4, buildBlockContext as a5, buildBlockMap as a6, defineBlock as a7, fetchLayouts as a8, fetchPage as a9, fetchPageById as aa, fetchPageMeta as ab, fetchPages as ac, isProtocolCompatible as ad, normalizeSlug as ae, resolveApiUrl 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 };
@@ -1,7 +1,16 @@
1
1
  import { ComponentType } from 'react';
2
2
 
3
+ /**
4
+ * The cmssy cloud GraphQL delivery endpoint. It is the same for every workspace,
5
+ * so consumers never need to set it - `apiUrl` defaults to this. Self-hosted /
6
+ * staging deployments override it via config.
7
+ */
8
+ declare const DEFAULT_CMSSY_API_URL = "https://api.cmssy.io/graphql";
9
+ /** Resolves `apiUrl`, falling back to the cmssy cloud endpoint when unset. */
10
+ declare function resolveApiUrl(apiUrl: string | undefined): string;
3
11
  interface CmssyClientConfig {
4
- apiUrl: string;
12
+ /** Full GraphQL delivery endpoint. Defaults to {@link DEFAULT_CMSSY_API_URL}. */
13
+ apiUrl?: string;
5
14
  workspaceSlug: string;
6
15
  }
7
16
  interface FetchLikeResponse {
@@ -443,4 +452,4 @@ interface CmssyOrder {
443
452
  createdAt?: string;
444
453
  }
445
454
 
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 };
455
+ export { SITE_CONFIG_QUERY 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, type FieldType as T, MODEL_DEFINITIONS_QUERY as U, MODEL_RECORDS_QUERY as V, PROTOCOL_VERSION as W, type ParentReadyMessage as X, type PatchMessage as Y, type RawLayoutBlock as Z, type ReadyMessage as _, type BlockMeta as a, SUBMIT_FORM_MUTATION as a0, type SelectMessage as a1, type SubmitFormInput as a2, blocksToMeta as a3, blocksToSchemas as a4, buildBlockContext as a5, buildBlockMap as a6, defineBlock as a7, fetchLayouts as a8, fetchPage as a9, fetchPageById as aa, fetchPageMeta as ab, fetchPages as ac, isProtocolCompatible as ad, normalizeSlug as ae, resolveApiUrl 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
@@ -288,6 +288,10 @@ function parseEditorMessage(data, origin, expectedOrigin) {
288
288
  }
289
289
 
290
290
  // src/content/content-client.ts
291
+ var DEFAULT_CMSSY_API_URL = "https://api.cmssy.io/graphql";
292
+ function resolveApiUrl(apiUrl) {
293
+ return apiUrl && apiUrl.length > 0 ? apiUrl : DEFAULT_CMSSY_API_URL;
294
+ }
291
295
  var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String) {
292
296
  publicPage(workspaceSlug: $workspaceSlug, slug: $slug, previewSecret: $previewSecret) {
293
297
  id
@@ -342,7 +346,7 @@ async function fetchPage(config, path, options = {}) {
342
346
  }
343
347
  const trimmedSecret = options.previewSecret?.trim();
344
348
  const previewSecret = trimmedSecret ? trimmedSecret : null;
345
- const response = await doFetch(config.apiUrl, {
349
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
346
350
  method: "POST",
347
351
  headers: { "content-type": "application/json" },
348
352
  body: JSON.stringify({
@@ -390,7 +394,7 @@ async function fetchPageById(config, pageId, options = {}) {
390
394
  "cmssy: no fetch implementation available - pass options.fetch"
391
395
  );
392
396
  }
393
- const response = await doFetch(config.apiUrl, {
397
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
394
398
  method: "POST",
395
399
  headers: { "content-type": "application/json" },
396
400
  body: JSON.stringify({
@@ -434,7 +438,7 @@ async function fetchPages(config, options = {}) {
434
438
  "cmssy: no fetch implementation available - pass options.fetch"
435
439
  );
436
440
  }
437
- const response = await doFetch(config.apiUrl, {
441
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
438
442
  method: "POST",
439
443
  headers: { "content-type": "application/json" },
440
444
  body: JSON.stringify({
@@ -466,7 +470,7 @@ async function fetchPageMeta(config, path, options = {}) {
466
470
  "cmssy: no fetch implementation available - pass options.fetch"
467
471
  );
468
472
  }
469
- const response = await doFetch(config.apiUrl, {
473
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
470
474
  method: "POST",
471
475
  headers: { "content-type": "application/json" },
472
476
  body: JSON.stringify({
@@ -500,7 +504,7 @@ async function fetchLayouts(config, path, options = {}) {
500
504
  }
501
505
  const trimmedSecret = options.previewSecret?.trim();
502
506
  const previewSecret = trimmedSecret ? trimmedSecret : null;
503
- const response = await doFetch(config.apiUrl, {
507
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
504
508
  method: "POST",
505
509
  headers: { "content-type": "application/json" },
506
510
  body: JSON.stringify({
@@ -537,7 +541,7 @@ async function graphqlRequest(config, query, variables, options = {}, label = "r
537
541
  "cmssy: no fetch implementation available - pass options.fetch"
538
542
  );
539
543
  }
540
- const response = await doFetch(config.apiUrl, {
544
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
541
545
  method: "POST",
542
546
  headers: { "content-type": "application/json", ...options.headers },
543
547
  body: JSON.stringify({ query, variables }),
@@ -645,7 +649,11 @@ async function resolveWorkspaceId(config, options = {}) {
645
649
  }
646
650
 
647
651
  // src/data/client.ts
648
- function createCmssyClient(config) {
652
+ function createCmssyClient(input) {
653
+ const config = {
654
+ ...input,
655
+ apiUrl: resolveApiUrl(input.apiUrl)
656
+ };
649
657
  let cachedWorkspaceId;
650
658
  let inFlight;
651
659
  function resolveWorkspaceId2(options) {
@@ -731,7 +739,7 @@ var TTL_MS = 6e4;
731
739
  var MAX_ENTRIES = 64;
732
740
  var cache = /* @__PURE__ */ new Map();
733
741
  async function resolveSiteLocales(config, options) {
734
- const key = `${config.apiUrl}::${config.workspaceSlug}`;
742
+ const key = `${resolveApiUrl(config.apiUrl)}::${config.workspaceSlug}`;
735
743
  const cached = cache.get(key);
736
744
  if (cached && cached.expires > Date.now()) return cached.value;
737
745
  cache.delete(key);
@@ -840,6 +848,7 @@ function CmssyBlock({
840
848
  exports.CmssyBlock = CmssyBlock;
841
849
  exports.CmssyServerLayout = CmssyServerLayout;
842
850
  exports.CmssyServerPage = CmssyServerPage;
851
+ exports.DEFAULT_CMSSY_API_URL = DEFAULT_CMSSY_API_URL;
843
852
  exports.FORM_QUERY = FORM_QUERY;
844
853
  exports.MODEL_DEFINITIONS_QUERY = MODEL_DEFINITIONS_QUERY;
845
854
  exports.MODEL_RECORDS_QUERY = MODEL_RECORDS_QUERY;
@@ -871,6 +880,7 @@ exports.normalizeOrigin = normalizeOrigin;
871
880
  exports.normalizeSlug = normalizeSlug;
872
881
  exports.parseEditorMessage = parseEditorMessage;
873
882
  exports.postToEditor = postToEditor;
883
+ exports.resolveApiUrl = resolveApiUrl;
874
884
  exports.resolveForms = resolveForms;
875
885
  exports.resolveSiteLocales = resolveSiteLocales;
876
886
  exports.resolveWorkspaceId = resolveWorkspaceId;
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-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';
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-Dx6EW4Sr.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 FieldType, U as MODEL_DEFINITIONS_QUERY, V as MODEL_RECORDS_QUERY, W as PROTOCOL_VERSION, X as ParentReadyMessage, Y as PatchMessage, Z as RawLayoutBlock, _ as ReadyMessage, $ as SITE_CONFIG_QUERY, a0 as SUBMIT_FORM_MUTATION, a1 as SelectMessage, a2 as SubmitFormInput, a3 as blocksToMeta, a4 as blocksToSchemas, a5 as buildBlockContext, a6 as buildBlockMap, a7 as defineBlock, a8 as fetchLayouts, a9 as fetchPage, aa as fetchPageById, ab as fetchPageMeta, ac as fetchPages, ad as isProtocolCompatible, ae as normalizeSlug, af as resolveApiUrl } from './commerce-queries-Dx6EW4Sr.cjs';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import 'react';
5
5
 
@@ -81,7 +81,7 @@ interface CmssyClient {
81
81
  queryScoped<T = unknown>(document: string, variables?: Record<string, unknown>, options?: QueryScopedOptions): Promise<T>;
82
82
  resolveWorkspaceId(options?: GraphqlRequestOptions): Promise<string>;
83
83
  }
84
- declare function createCmssyClient(config: CmssyClientConfig): CmssyClient;
84
+ declare function createCmssyClient(input: CmssyClientConfig): CmssyClient;
85
85
 
86
86
  declare function collectFormIds(blocks: RawBlock[], locale: string, defaultLocale: string): string[];
87
87
  declare function resolveForms(config: CmssyClientConfig, blocks: RawBlock[], locale: string, defaultLocale: string, options?: QueryScopedOptions): Promise<Record<string, CmssyFormDefinition>>;
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-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';
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-Dx6EW4Sr.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 FieldType, U as MODEL_DEFINITIONS_QUERY, V as MODEL_RECORDS_QUERY, W as PROTOCOL_VERSION, X as ParentReadyMessage, Y as PatchMessage, Z as RawLayoutBlock, _ as ReadyMessage, $ as SITE_CONFIG_QUERY, a0 as SUBMIT_FORM_MUTATION, a1 as SelectMessage, a2 as SubmitFormInput, a3 as blocksToMeta, a4 as blocksToSchemas, a5 as buildBlockContext, a6 as buildBlockMap, a7 as defineBlock, a8 as fetchLayouts, a9 as fetchPage, aa as fetchPageById, ab as fetchPageMeta, ac as fetchPages, ad as isProtocolCompatible, ae as normalizeSlug, af as resolveApiUrl } from './commerce-queries-Dx6EW4Sr.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import 'react';
5
5
 
@@ -81,7 +81,7 @@ interface CmssyClient {
81
81
  queryScoped<T = unknown>(document: string, variables?: Record<string, unknown>, options?: QueryScopedOptions): Promise<T>;
82
82
  resolveWorkspaceId(options?: GraphqlRequestOptions): Promise<string>;
83
83
  }
84
- declare function createCmssyClient(config: CmssyClientConfig): CmssyClient;
84
+ declare function createCmssyClient(input: CmssyClientConfig): CmssyClient;
85
85
 
86
86
  declare function collectFormIds(blocks: RawBlock[], locale: string, defaultLocale: string): string[];
87
87
  declare function resolveForms(config: CmssyClientConfig, blocks: RawBlock[], locale: string, defaultLocale: string, options?: QueryScopedOptions): Promise<Record<string, CmssyFormDefinition>>;
package/dist/index.js CHANGED
@@ -286,6 +286,10 @@ function parseEditorMessage(data, origin, expectedOrigin) {
286
286
  }
287
287
 
288
288
  // src/content/content-client.ts
289
+ var DEFAULT_CMSSY_API_URL = "https://api.cmssy.io/graphql";
290
+ function resolveApiUrl(apiUrl) {
291
+ return apiUrl && apiUrl.length > 0 ? apiUrl : DEFAULT_CMSSY_API_URL;
292
+ }
289
293
  var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String) {
290
294
  publicPage(workspaceSlug: $workspaceSlug, slug: $slug, previewSecret: $previewSecret) {
291
295
  id
@@ -340,7 +344,7 @@ async function fetchPage(config, path, options = {}) {
340
344
  }
341
345
  const trimmedSecret = options.previewSecret?.trim();
342
346
  const previewSecret = trimmedSecret ? trimmedSecret : null;
343
- const response = await doFetch(config.apiUrl, {
347
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
344
348
  method: "POST",
345
349
  headers: { "content-type": "application/json" },
346
350
  body: JSON.stringify({
@@ -388,7 +392,7 @@ async function fetchPageById(config, pageId, options = {}) {
388
392
  "cmssy: no fetch implementation available - pass options.fetch"
389
393
  );
390
394
  }
391
- const response = await doFetch(config.apiUrl, {
395
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
392
396
  method: "POST",
393
397
  headers: { "content-type": "application/json" },
394
398
  body: JSON.stringify({
@@ -432,7 +436,7 @@ async function fetchPages(config, options = {}) {
432
436
  "cmssy: no fetch implementation available - pass options.fetch"
433
437
  );
434
438
  }
435
- const response = await doFetch(config.apiUrl, {
439
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
436
440
  method: "POST",
437
441
  headers: { "content-type": "application/json" },
438
442
  body: JSON.stringify({
@@ -464,7 +468,7 @@ async function fetchPageMeta(config, path, options = {}) {
464
468
  "cmssy: no fetch implementation available - pass options.fetch"
465
469
  );
466
470
  }
467
- const response = await doFetch(config.apiUrl, {
471
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
468
472
  method: "POST",
469
473
  headers: { "content-type": "application/json" },
470
474
  body: JSON.stringify({
@@ -498,7 +502,7 @@ async function fetchLayouts(config, path, options = {}) {
498
502
  }
499
503
  const trimmedSecret = options.previewSecret?.trim();
500
504
  const previewSecret = trimmedSecret ? trimmedSecret : null;
501
- const response = await doFetch(config.apiUrl, {
505
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
502
506
  method: "POST",
503
507
  headers: { "content-type": "application/json" },
504
508
  body: JSON.stringify({
@@ -535,7 +539,7 @@ async function graphqlRequest(config, query, variables, options = {}, label = "r
535
539
  "cmssy: no fetch implementation available - pass options.fetch"
536
540
  );
537
541
  }
538
- const response = await doFetch(config.apiUrl, {
542
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
539
543
  method: "POST",
540
544
  headers: { "content-type": "application/json", ...options.headers },
541
545
  body: JSON.stringify({ query, variables }),
@@ -643,7 +647,11 @@ async function resolveWorkspaceId(config, options = {}) {
643
647
  }
644
648
 
645
649
  // src/data/client.ts
646
- function createCmssyClient(config) {
650
+ function createCmssyClient(input) {
651
+ const config = {
652
+ ...input,
653
+ apiUrl: resolveApiUrl(input.apiUrl)
654
+ };
647
655
  let cachedWorkspaceId;
648
656
  let inFlight;
649
657
  function resolveWorkspaceId2(options) {
@@ -729,7 +737,7 @@ var TTL_MS = 6e4;
729
737
  var MAX_ENTRIES = 64;
730
738
  var cache = /* @__PURE__ */ new Map();
731
739
  async function resolveSiteLocales(config, options) {
732
- const key = `${config.apiUrl}::${config.workspaceSlug}`;
740
+ const key = `${resolveApiUrl(config.apiUrl)}::${config.workspaceSlug}`;
733
741
  const cached = cache.get(key);
734
742
  if (cached && cached.expires > Date.now()) return cached.value;
735
743
  cache.delete(key);
@@ -835,4 +843,4 @@ function CmssyBlock({
835
843
  );
836
844
  }
837
845
 
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 };
846
+ 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/react",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
4
4
  "description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
5
5
  "keywords": [
6
6
  "cmssy",