@cmssy/react 0.5.5 → 0.6.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,10 +39,7 @@ the CMS at runtime.
39
39
  ```tsx
40
40
  import { fetchPage, CmssyServerPage } from "@cmssy/react";
41
41
 
42
- const page = await fetchPage(
43
- { apiUrl: "https://api.cmssy.io/graphql", workspaceSlug: "acme" },
44
- pathSegments,
45
- );
42
+ const page = await fetchPage({ workspaceSlug: "acme" }, pathSegments);
46
43
 
47
44
  return <CmssyServerPage page={page} blocks={blocks} locale="en" />;
48
45
  ```
@@ -59,10 +56,7 @@ the exported documents):
59
56
  ```ts
60
57
  import { createCmssyClient, MODEL_RECORDS_QUERY } from "@cmssy/react";
61
58
 
62
- const cmssy = createCmssyClient({
63
- apiUrl: "https://api.cmssy.io/graphql",
64
- workspaceSlug: "acme",
65
- });
59
+ const cmssy = createCmssyClient({ workspaceSlug: "acme" });
66
60
 
67
61
  // raw query (you own scoping)
68
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-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-Ct37AIeC.cjs';
3
+ export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-Ct37AIeC.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-Ct37AIeC.js';
3
+ export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-Ct37AIeC.js';
4
4
  import { ReactNode } from 'react';
5
5
 
6
6
  interface EditBridgeConfig {
@@ -1,7 +1,15 @@
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
+ declare function resolveApiUrl(apiUrl: string | undefined): string;
3
10
  interface CmssyClientConfig {
4
- apiUrl: string;
11
+ /** Full GraphQL delivery endpoint. Defaults to {@link DEFAULT_CMSSY_API_URL}. */
12
+ apiUrl?: string;
5
13
  workspaceSlug: string;
6
14
  }
7
15
  interface FetchLikeResponse {
@@ -443,4 +451,4 @@ interface CmssyOrder {
443
451
  createdAt?: string;
444
452
  }
445
453
 
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 };
454
+ 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,15 @@
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
+ declare function resolveApiUrl(apiUrl: string | undefined): string;
3
10
  interface CmssyClientConfig {
4
- apiUrl: string;
11
+ /** Full GraphQL delivery endpoint. Defaults to {@link DEFAULT_CMSSY_API_URL}. */
12
+ apiUrl?: string;
5
13
  workspaceSlug: string;
6
14
  }
7
15
  interface FetchLikeResponse {
@@ -443,4 +451,4 @@ interface CmssyOrder {
443
451
  createdAt?: string;
444
452
  }
445
453
 
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 };
454
+ 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,14 @@ 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
+ const explicit = apiUrl?.trim();
294
+ if (explicit) return explicit;
295
+ const env = globalThis.process?.env;
296
+ const fromEnv = env?.CMSSY_API_URL?.trim() ?? "";
297
+ return fromEnv.length > 0 ? fromEnv : DEFAULT_CMSSY_API_URL;
298
+ }
291
299
  var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String) {
292
300
  publicPage(workspaceSlug: $workspaceSlug, slug: $slug, previewSecret: $previewSecret) {
293
301
  id
@@ -342,7 +350,7 @@ async function fetchPage(config, path, options = {}) {
342
350
  }
343
351
  const trimmedSecret = options.previewSecret?.trim();
344
352
  const previewSecret = trimmedSecret ? trimmedSecret : null;
345
- const response = await doFetch(config.apiUrl, {
353
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
346
354
  method: "POST",
347
355
  headers: { "content-type": "application/json" },
348
356
  body: JSON.stringify({
@@ -390,7 +398,7 @@ async function fetchPageById(config, pageId, options = {}) {
390
398
  "cmssy: no fetch implementation available - pass options.fetch"
391
399
  );
392
400
  }
393
- const response = await doFetch(config.apiUrl, {
401
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
394
402
  method: "POST",
395
403
  headers: { "content-type": "application/json" },
396
404
  body: JSON.stringify({
@@ -434,7 +442,7 @@ async function fetchPages(config, options = {}) {
434
442
  "cmssy: no fetch implementation available - pass options.fetch"
435
443
  );
436
444
  }
437
- const response = await doFetch(config.apiUrl, {
445
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
438
446
  method: "POST",
439
447
  headers: { "content-type": "application/json" },
440
448
  body: JSON.stringify({
@@ -466,7 +474,7 @@ async function fetchPageMeta(config, path, options = {}) {
466
474
  "cmssy: no fetch implementation available - pass options.fetch"
467
475
  );
468
476
  }
469
- const response = await doFetch(config.apiUrl, {
477
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
470
478
  method: "POST",
471
479
  headers: { "content-type": "application/json" },
472
480
  body: JSON.stringify({
@@ -500,7 +508,7 @@ async function fetchLayouts(config, path, options = {}) {
500
508
  }
501
509
  const trimmedSecret = options.previewSecret?.trim();
502
510
  const previewSecret = trimmedSecret ? trimmedSecret : null;
503
- const response = await doFetch(config.apiUrl, {
511
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
504
512
  method: "POST",
505
513
  headers: { "content-type": "application/json" },
506
514
  body: JSON.stringify({
@@ -537,7 +545,7 @@ async function graphqlRequest(config, query, variables, options = {}, label = "r
537
545
  "cmssy: no fetch implementation available - pass options.fetch"
538
546
  );
539
547
  }
540
- const response = await doFetch(config.apiUrl, {
548
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
541
549
  method: "POST",
542
550
  headers: { "content-type": "application/json", ...options.headers },
543
551
  body: JSON.stringify({ query, variables }),
@@ -645,7 +653,11 @@ async function resolveWorkspaceId(config, options = {}) {
645
653
  }
646
654
 
647
655
  // src/data/client.ts
648
- function createCmssyClient(config) {
656
+ function createCmssyClient(input) {
657
+ const config = {
658
+ ...input,
659
+ apiUrl: resolveApiUrl(input.apiUrl)
660
+ };
649
661
  let cachedWorkspaceId;
650
662
  let inFlight;
651
663
  function resolveWorkspaceId2(options) {
@@ -731,7 +743,7 @@ var TTL_MS = 6e4;
731
743
  var MAX_ENTRIES = 64;
732
744
  var cache = /* @__PURE__ */ new Map();
733
745
  async function resolveSiteLocales(config, options) {
734
- const key = `${config.apiUrl}::${config.workspaceSlug}`;
746
+ const key = `${resolveApiUrl(config.apiUrl)}::${config.workspaceSlug}`;
735
747
  const cached = cache.get(key);
736
748
  if (cached && cached.expires > Date.now()) return cached.value;
737
749
  cache.delete(key);
@@ -840,6 +852,7 @@ function CmssyBlock({
840
852
  exports.CmssyBlock = CmssyBlock;
841
853
  exports.CmssyServerLayout = CmssyServerLayout;
842
854
  exports.CmssyServerPage = CmssyServerPage;
855
+ exports.DEFAULT_CMSSY_API_URL = DEFAULT_CMSSY_API_URL;
843
856
  exports.FORM_QUERY = FORM_QUERY;
844
857
  exports.MODEL_DEFINITIONS_QUERY = MODEL_DEFINITIONS_QUERY;
845
858
  exports.MODEL_RECORDS_QUERY = MODEL_RECORDS_QUERY;
@@ -871,6 +884,7 @@ exports.normalizeOrigin = normalizeOrigin;
871
884
  exports.normalizeSlug = normalizeSlug;
872
885
  exports.parseEditorMessage = parseEditorMessage;
873
886
  exports.postToEditor = postToEditor;
887
+ exports.resolveApiUrl = resolveApiUrl;
874
888
  exports.resolveForms = resolveForms;
875
889
  exports.resolveSiteLocales = resolveSiteLocales;
876
890
  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-Ct37AIeC.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-Ct37AIeC.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-Ct37AIeC.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-Ct37AIeC.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,14 @@ 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
+ const explicit = apiUrl?.trim();
292
+ if (explicit) return explicit;
293
+ const env = globalThis.process?.env;
294
+ const fromEnv = env?.CMSSY_API_URL?.trim() ?? "";
295
+ return fromEnv.length > 0 ? fromEnv : DEFAULT_CMSSY_API_URL;
296
+ }
289
297
  var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String) {
290
298
  publicPage(workspaceSlug: $workspaceSlug, slug: $slug, previewSecret: $previewSecret) {
291
299
  id
@@ -340,7 +348,7 @@ async function fetchPage(config, path, options = {}) {
340
348
  }
341
349
  const trimmedSecret = options.previewSecret?.trim();
342
350
  const previewSecret = trimmedSecret ? trimmedSecret : null;
343
- const response = await doFetch(config.apiUrl, {
351
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
344
352
  method: "POST",
345
353
  headers: { "content-type": "application/json" },
346
354
  body: JSON.stringify({
@@ -388,7 +396,7 @@ async function fetchPageById(config, pageId, options = {}) {
388
396
  "cmssy: no fetch implementation available - pass options.fetch"
389
397
  );
390
398
  }
391
- const response = await doFetch(config.apiUrl, {
399
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
392
400
  method: "POST",
393
401
  headers: { "content-type": "application/json" },
394
402
  body: JSON.stringify({
@@ -432,7 +440,7 @@ async function fetchPages(config, options = {}) {
432
440
  "cmssy: no fetch implementation available - pass options.fetch"
433
441
  );
434
442
  }
435
- const response = await doFetch(config.apiUrl, {
443
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
436
444
  method: "POST",
437
445
  headers: { "content-type": "application/json" },
438
446
  body: JSON.stringify({
@@ -464,7 +472,7 @@ async function fetchPageMeta(config, path, options = {}) {
464
472
  "cmssy: no fetch implementation available - pass options.fetch"
465
473
  );
466
474
  }
467
- const response = await doFetch(config.apiUrl, {
475
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
468
476
  method: "POST",
469
477
  headers: { "content-type": "application/json" },
470
478
  body: JSON.stringify({
@@ -498,7 +506,7 @@ async function fetchLayouts(config, path, options = {}) {
498
506
  }
499
507
  const trimmedSecret = options.previewSecret?.trim();
500
508
  const previewSecret = trimmedSecret ? trimmedSecret : null;
501
- const response = await doFetch(config.apiUrl, {
509
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
502
510
  method: "POST",
503
511
  headers: { "content-type": "application/json" },
504
512
  body: JSON.stringify({
@@ -535,7 +543,7 @@ async function graphqlRequest(config, query, variables, options = {}, label = "r
535
543
  "cmssy: no fetch implementation available - pass options.fetch"
536
544
  );
537
545
  }
538
- const response = await doFetch(config.apiUrl, {
546
+ const response = await doFetch(resolveApiUrl(config.apiUrl), {
539
547
  method: "POST",
540
548
  headers: { "content-type": "application/json", ...options.headers },
541
549
  body: JSON.stringify({ query, variables }),
@@ -643,7 +651,11 @@ async function resolveWorkspaceId(config, options = {}) {
643
651
  }
644
652
 
645
653
  // src/data/client.ts
646
- function createCmssyClient(config) {
654
+ function createCmssyClient(input) {
655
+ const config = {
656
+ ...input,
657
+ apiUrl: resolveApiUrl(input.apiUrl)
658
+ };
647
659
  let cachedWorkspaceId;
648
660
  let inFlight;
649
661
  function resolveWorkspaceId2(options) {
@@ -729,7 +741,7 @@ var TTL_MS = 6e4;
729
741
  var MAX_ENTRIES = 64;
730
742
  var cache = /* @__PURE__ */ new Map();
731
743
  async function resolveSiteLocales(config, options) {
732
- const key = `${config.apiUrl}::${config.workspaceSlug}`;
744
+ const key = `${resolveApiUrl(config.apiUrl)}::${config.workspaceSlug}`;
733
745
  const cached = cache.get(key);
734
746
  if (cached && cached.expires > Date.now()) return cached.value;
735
747
  cache.delete(key);
@@ -835,4 +847,4 @@ function CmssyBlock({
835
847
  );
836
848
  }
837
849
 
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 };
850
+ 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.6.0",
4
4
  "description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
5
5
  "keywords": [
6
6
  "cmssy",