@cmssy/react 0.13.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 +2 -2
- package/dist/client.cjs +9 -9
- package/dist/client.d.cts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +9 -9
- package/dist/{commerce-queries-ClCU8FZN.d.cts → commerce-queries-D9lXIaCQ.d.cts} +23 -4
- package/dist/{commerce-queries-ClCU8FZN.d.ts → commerce-queries-D9lXIaCQ.d.ts} +23 -4
- package/dist/index.cjs +50 -37
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +50 -38
- package/package.json +1 -1
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.cjs
CHANGED
|
@@ -485,12 +485,8 @@ function getBlockContentForLanguage(content, locale, defaultLocale = "en", avail
|
|
|
485
485
|
const chosen = localeMap[locale] ?? localeMap[defaultLocale] ?? localeMap[fallbackKey];
|
|
486
486
|
return { ...nonTranslatable, ...chosen };
|
|
487
487
|
}
|
|
488
|
-
function
|
|
489
|
-
return {
|
|
490
|
-
...content,
|
|
491
|
-
...isPlainObject(style) ? style : {},
|
|
492
|
-
...isPlainObject(advanced) ? advanced : {}
|
|
493
|
-
};
|
|
488
|
+
function asBucket(value) {
|
|
489
|
+
return isPlainObject(value) ? value : {};
|
|
494
490
|
}
|
|
495
491
|
var WARN_CAP = 256;
|
|
496
492
|
var warned = /* @__PURE__ */ new Set();
|
|
@@ -514,8 +510,7 @@ function CmssyBlock({
|
|
|
514
510
|
}) {
|
|
515
511
|
const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
|
|
516
512
|
const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
517
|
-
const
|
|
518
|
-
const content = mergeBlockValues(resolved, block.style, block.advanced);
|
|
513
|
+
const content = patchedContent ? { ...base, ...patchedContent } : base;
|
|
519
514
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
520
515
|
"div",
|
|
521
516
|
{
|
|
@@ -524,7 +519,12 @@ function CmssyBlock({
|
|
|
524
519
|
"data-layout-position": layoutPosition,
|
|
525
520
|
draggable: editable || void 0,
|
|
526
521
|
style: Component ? void 0 : { display: "none" },
|
|
527
|
-
children: Component ? react.createElement(Component, {
|
|
522
|
+
children: Component ? react.createElement(Component, {
|
|
523
|
+
content,
|
|
524
|
+
style: asBucket(block.style),
|
|
525
|
+
advanced: asBucket(block.advanced),
|
|
526
|
+
context
|
|
527
|
+
}) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
|
|
528
528
|
}
|
|
529
529
|
);
|
|
530
530
|
}
|
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-
|
|
3
|
-
export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-
|
|
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-
|
|
3
|
-
export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-
|
|
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
|
|
package/dist/client.js
CHANGED
|
@@ -483,12 +483,8 @@ function getBlockContentForLanguage(content, locale, defaultLocale = "en", avail
|
|
|
483
483
|
const chosen = localeMap[locale] ?? localeMap[defaultLocale] ?? localeMap[fallbackKey];
|
|
484
484
|
return { ...nonTranslatable, ...chosen };
|
|
485
485
|
}
|
|
486
|
-
function
|
|
487
|
-
return {
|
|
488
|
-
...content,
|
|
489
|
-
...isPlainObject(style) ? style : {},
|
|
490
|
-
...isPlainObject(advanced) ? advanced : {}
|
|
491
|
-
};
|
|
486
|
+
function asBucket(value) {
|
|
487
|
+
return isPlainObject(value) ? value : {};
|
|
492
488
|
}
|
|
493
489
|
var WARN_CAP = 256;
|
|
494
490
|
var warned = /* @__PURE__ */ new Set();
|
|
@@ -512,8 +508,7 @@ function CmssyBlock({
|
|
|
512
508
|
}) {
|
|
513
509
|
const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
|
|
514
510
|
const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
515
|
-
const
|
|
516
|
-
const content = mergeBlockValues(resolved, block.style, block.advanced);
|
|
511
|
+
const content = patchedContent ? { ...base, ...patchedContent } : base;
|
|
517
512
|
return /* @__PURE__ */ jsx(
|
|
518
513
|
"div",
|
|
519
514
|
{
|
|
@@ -522,7 +517,12 @@ function CmssyBlock({
|
|
|
522
517
|
"data-layout-position": layoutPosition,
|
|
523
518
|
draggable: editable || void 0,
|
|
524
519
|
style: Component ? void 0 : { display: "none" },
|
|
525
|
-
children: Component ? createElement(Component, {
|
|
520
|
+
children: Component ? createElement(Component, {
|
|
521
|
+
content,
|
|
522
|
+
style: asBucket(block.style),
|
|
523
|
+
advanced: asBucket(block.advanced),
|
|
524
|
+
context
|
|
525
|
+
}) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
|
|
526
526
|
}
|
|
527
527
|
);
|
|
528
528
|
}
|
|
@@ -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
|
-
/**
|
|
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
|
|
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;
|
|
@@ -340,11 +353,13 @@ interface BlockDefinition {
|
|
|
340
353
|
loader?: BlockLoader;
|
|
341
354
|
component: ComponentType<{
|
|
342
355
|
content: Record<string, unknown>;
|
|
356
|
+
style?: Record<string, unknown>;
|
|
357
|
+
advanced?: Record<string, unknown>;
|
|
343
358
|
context?: CmssyBlockContext;
|
|
344
359
|
data?: unknown;
|
|
345
360
|
}>;
|
|
346
361
|
}
|
|
347
|
-
declare function defineBlock<C extends Record<string, unknown>, D = unknown>(def: {
|
|
362
|
+
declare function defineBlock<C extends Record<string, unknown>, D = unknown, S extends Record<string, unknown> = Record<string, unknown>, A extends Record<string, unknown> = Record<string, unknown>>(def: {
|
|
348
363
|
type: string;
|
|
349
364
|
label?: string;
|
|
350
365
|
category?: string;
|
|
@@ -358,12 +373,16 @@ declare function defineBlock<C extends Record<string, unknown>, D = unknown>(def
|
|
|
358
373
|
}) => Promise<D> | D;
|
|
359
374
|
component: ComponentType<{
|
|
360
375
|
content: C;
|
|
376
|
+
style?: S;
|
|
377
|
+
advanced?: A;
|
|
361
378
|
context?: CmssyBlockContext;
|
|
362
379
|
data?: D;
|
|
363
380
|
}>;
|
|
364
381
|
}): BlockDefinition;
|
|
365
382
|
type BlockMap = Record<string, ComponentType<{
|
|
366
383
|
content: Record<string, unknown>;
|
|
384
|
+
style?: Record<string, unknown>;
|
|
385
|
+
advanced?: Record<string, unknown>;
|
|
367
386
|
context?: CmssyBlockContext;
|
|
368
387
|
data?: unknown;
|
|
369
388
|
}>>;
|
|
@@ -469,4 +488,4 @@ interface CmssyOrder {
|
|
|
469
488
|
createdAt?: string;
|
|
470
489
|
}
|
|
471
490
|
|
|
472
|
-
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
|
-
/**
|
|
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
|
|
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;
|
|
@@ -340,11 +353,13 @@ interface BlockDefinition {
|
|
|
340
353
|
loader?: BlockLoader;
|
|
341
354
|
component: ComponentType<{
|
|
342
355
|
content: Record<string, unknown>;
|
|
356
|
+
style?: Record<string, unknown>;
|
|
357
|
+
advanced?: Record<string, unknown>;
|
|
343
358
|
context?: CmssyBlockContext;
|
|
344
359
|
data?: unknown;
|
|
345
360
|
}>;
|
|
346
361
|
}
|
|
347
|
-
declare function defineBlock<C extends Record<string, unknown>, D = unknown>(def: {
|
|
362
|
+
declare function defineBlock<C extends Record<string, unknown>, D = unknown, S extends Record<string, unknown> = Record<string, unknown>, A extends Record<string, unknown> = Record<string, unknown>>(def: {
|
|
348
363
|
type: string;
|
|
349
364
|
label?: string;
|
|
350
365
|
category?: string;
|
|
@@ -358,12 +373,16 @@ declare function defineBlock<C extends Record<string, unknown>, D = unknown>(def
|
|
|
358
373
|
}) => Promise<D> | D;
|
|
359
374
|
component: ComponentType<{
|
|
360
375
|
content: C;
|
|
376
|
+
style?: S;
|
|
377
|
+
advanced?: A;
|
|
361
378
|
context?: CmssyBlockContext;
|
|
362
379
|
data?: D;
|
|
363
380
|
}>;
|
|
364
381
|
}): BlockDefinition;
|
|
365
382
|
type BlockMap = Record<string, ComponentType<{
|
|
366
383
|
content: Record<string, unknown>;
|
|
384
|
+
style?: Record<string, unknown>;
|
|
385
|
+
advanced?: Record<string, unknown>;
|
|
367
386
|
context?: CmssyBlockContext;
|
|
368
387
|
data?: unknown;
|
|
369
388
|
}>>;
|
|
@@ -469,4 +488,4 @@ interface CmssyOrder {
|
|
|
469
488
|
createdAt?: string;
|
|
470
489
|
}
|
|
471
490
|
|
|
472
|
-
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
|
@@ -101,12 +101,8 @@ function getBlockContentForLanguage(content, locale, defaultLocale = "en", avail
|
|
|
101
101
|
const chosen = localeMap[locale] ?? localeMap[defaultLocale] ?? localeMap[fallbackKey];
|
|
102
102
|
return { ...nonTranslatable, ...chosen };
|
|
103
103
|
}
|
|
104
|
-
function
|
|
105
|
-
return {
|
|
106
|
-
...content,
|
|
107
|
-
...isPlainObject(style) ? style : {},
|
|
108
|
-
...isPlainObject(advanced) ? advanced : {}
|
|
109
|
-
};
|
|
104
|
+
function asBucket(value) {
|
|
105
|
+
return isPlainObject(value) ? value : {};
|
|
110
106
|
}
|
|
111
107
|
|
|
112
108
|
// src/components/block-context.ts
|
|
@@ -136,20 +132,25 @@ function UnknownBlock({ type }) {
|
|
|
136
132
|
function renderResolvedBlock(block, map, locale, defaultLocale, options = {}) {
|
|
137
133
|
const { context, data, resolvedContent, enabledLocales } = options;
|
|
138
134
|
const Component = Object.hasOwn(map, block.type) ? map[block.type] : void 0;
|
|
139
|
-
const
|
|
135
|
+
const content = resolvedContent ?? getBlockContentForLanguage(
|
|
140
136
|
block.content,
|
|
141
137
|
locale,
|
|
142
138
|
defaultLocale,
|
|
143
139
|
enabledLocales?.length ? enabledLocales : void 0
|
|
144
140
|
);
|
|
145
|
-
const content = mergeBlockValues(resolved, block.style, block.advanced);
|
|
146
141
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
147
142
|
"div",
|
|
148
143
|
{
|
|
149
144
|
"data-block-id": block.id,
|
|
150
145
|
"data-block-type": block.type,
|
|
151
146
|
style: Component ? void 0 : { display: "none" },
|
|
152
|
-
children: Component ? react.createElement(Component, {
|
|
147
|
+
children: Component ? react.createElement(Component, {
|
|
148
|
+
content,
|
|
149
|
+
style: asBucket(block.style),
|
|
150
|
+
advanced: asBucket(block.advanced),
|
|
151
|
+
context,
|
|
152
|
+
data
|
|
153
|
+
}) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
|
|
153
154
|
},
|
|
154
155
|
block.id
|
|
155
156
|
);
|
|
@@ -315,6 +316,10 @@ function resolveApiUrl(apiUrl) {
|
|
|
315
316
|
const fromEnv = env?.CMSSY_API_URL?.trim() ?? "";
|
|
316
317
|
return fromEnv.length > 0 ? fromEnv : DEFAULT_CMSSY_API_URL;
|
|
317
318
|
}
|
|
319
|
+
function resolvePublicUrl(config) {
|
|
320
|
+
const base = resolveApiUrl(config.apiUrl).replace(/\/graphql\/?$/, "");
|
|
321
|
+
return `${base}/public/${config.org}/${config.workspaceSlug}/graphql`;
|
|
322
|
+
}
|
|
318
323
|
var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String) {
|
|
319
324
|
public {
|
|
320
325
|
page {
|
|
@@ -411,7 +416,7 @@ async function fetchPage(config, path, options = {}) {
|
|
|
411
416
|
headers["x-workspace-id"] = options.workspaceId;
|
|
412
417
|
}
|
|
413
418
|
}
|
|
414
|
-
const response = await doFetch(
|
|
419
|
+
const response = await doFetch(resolvePublicUrl(config), {
|
|
415
420
|
method: "POST",
|
|
416
421
|
headers,
|
|
417
422
|
body: JSON.stringify({
|
|
@@ -460,7 +465,7 @@ async function fetchPageById(config, pageId, options = {}) {
|
|
|
460
465
|
"cmssy: no fetch implementation available - pass options.fetch"
|
|
461
466
|
);
|
|
462
467
|
}
|
|
463
|
-
const response = await doFetch(
|
|
468
|
+
const response = await doFetch(resolvePublicUrl(config), {
|
|
464
469
|
method: "POST",
|
|
465
470
|
headers: { "content-type": "application/json" },
|
|
466
471
|
body: JSON.stringify({
|
|
@@ -504,7 +509,7 @@ async function fetchPages(config, options = {}) {
|
|
|
504
509
|
"cmssy: no fetch implementation available - pass options.fetch"
|
|
505
510
|
);
|
|
506
511
|
}
|
|
507
|
-
const response = await doFetch(
|
|
512
|
+
const response = await doFetch(resolvePublicUrl(config), {
|
|
508
513
|
method: "POST",
|
|
509
514
|
headers: { "content-type": "application/json" },
|
|
510
515
|
body: JSON.stringify({
|
|
@@ -536,7 +541,7 @@ async function fetchPageMeta(config, path, options = {}) {
|
|
|
536
541
|
"cmssy: no fetch implementation available - pass options.fetch"
|
|
537
542
|
);
|
|
538
543
|
}
|
|
539
|
-
const response = await doFetch(
|
|
544
|
+
const response = await doFetch(resolvePublicUrl(config), {
|
|
540
545
|
method: "POST",
|
|
541
546
|
headers: { "content-type": "application/json" },
|
|
542
547
|
body: JSON.stringify({
|
|
@@ -570,7 +575,7 @@ async function fetchLayouts(config, path, options = {}) {
|
|
|
570
575
|
}
|
|
571
576
|
const trimmedSecret = options.previewSecret?.trim();
|
|
572
577
|
const previewSecret = trimmedSecret ? trimmedSecret : null;
|
|
573
|
-
const response = await doFetch(
|
|
578
|
+
const response = await doFetch(resolvePublicUrl(config), {
|
|
574
579
|
method: "POST",
|
|
575
580
|
headers: { "content-type": "application/json" },
|
|
576
581
|
body: JSON.stringify({
|
|
@@ -607,7 +612,8 @@ async function graphqlRequest(config, query, variables, options = {}, label = "r
|
|
|
607
612
|
"cmssy: no fetch implementation available - pass options.fetch"
|
|
608
613
|
);
|
|
609
614
|
}
|
|
610
|
-
const
|
|
615
|
+
const url = options.public ? resolvePublicUrl(config) : resolveApiUrl(config.apiUrl);
|
|
616
|
+
const response = await doFetch(url, {
|
|
611
617
|
method: "POST",
|
|
612
618
|
headers: { "content-type": "application/json", ...options.headers },
|
|
613
619
|
body: JSON.stringify({ query, variables }),
|
|
@@ -640,20 +646,22 @@ async function graphqlRequest(config, query, variables, options = {}, label = "r
|
|
|
640
646
|
|
|
641
647
|
// src/data/queries.ts
|
|
642
648
|
var SITE_CONFIG_QUERY = `query PublicSiteConfig($workspaceSlug: String!) {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
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
|
+
}
|
|
657
665
|
}
|
|
658
666
|
}
|
|
659
667
|
}`;
|
|
@@ -699,10 +707,10 @@ async function fetchSiteConfig(config, options = {}) {
|
|
|
699
707
|
config,
|
|
700
708
|
SITE_CONFIG_QUERY,
|
|
701
709
|
{ workspaceSlug: config.workspaceSlug },
|
|
702
|
-
options,
|
|
710
|
+
{ ...options, public: true },
|
|
703
711
|
"site config query"
|
|
704
712
|
);
|
|
705
|
-
return data.
|
|
713
|
+
return data.public?.siteConfig ?? null;
|
|
706
714
|
}
|
|
707
715
|
async function resolveWorkspaceId(config, options = {}) {
|
|
708
716
|
const siteConfig = await fetchSiteConfig(config, options);
|
|
@@ -805,7 +813,7 @@ var TTL_MS = 6e4;
|
|
|
805
813
|
var MAX_ENTRIES = 64;
|
|
806
814
|
var cache = /* @__PURE__ */ new Map();
|
|
807
815
|
async function resolveSiteLocales(config, options) {
|
|
808
|
-
const key = `${resolveApiUrl(config.apiUrl)}::${config.workspaceSlug}`;
|
|
816
|
+
const key = `${resolveApiUrl(config.apiUrl)}::${config.org}::${config.workspaceSlug}`;
|
|
809
817
|
const cached = cache.get(key);
|
|
810
818
|
if (cached && cached.expires > Date.now()) return cached.value;
|
|
811
819
|
cache.delete(key);
|
|
@@ -815,10 +823,10 @@ async function resolveSiteLocales(config, options) {
|
|
|
815
823
|
config,
|
|
816
824
|
SITE_CONFIG_QUERY,
|
|
817
825
|
{ workspaceSlug: config.workspaceSlug },
|
|
818
|
-
options,
|
|
826
|
+
{ ...options, public: true },
|
|
819
827
|
"site config"
|
|
820
828
|
);
|
|
821
|
-
const siteConfig = data.
|
|
829
|
+
const siteConfig = data.public?.siteConfig ?? null;
|
|
822
830
|
const defaultLocale = siteConfig?.defaultLanguage || "en";
|
|
823
831
|
const enabled = siteConfig?.enabledLanguages ?? [];
|
|
824
832
|
value = {
|
|
@@ -897,8 +905,7 @@ function CmssyBlock({
|
|
|
897
905
|
}) {
|
|
898
906
|
const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
|
|
899
907
|
const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
900
|
-
const
|
|
901
|
-
const content = mergeBlockValues(resolved, block.style, block.advanced);
|
|
908
|
+
const content = patchedContent ? { ...base, ...patchedContent } : base;
|
|
902
909
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
903
910
|
"div",
|
|
904
911
|
{
|
|
@@ -907,7 +914,12 @@ function CmssyBlock({
|
|
|
907
914
|
"data-layout-position": layoutPosition,
|
|
908
915
|
draggable: editable || void 0,
|
|
909
916
|
style: Component ? void 0 : { display: "none" },
|
|
910
|
-
children: Component ? react.createElement(Component, {
|
|
917
|
+
children: Component ? react.createElement(Component, {
|
|
918
|
+
content,
|
|
919
|
+
style: asBucket(block.style),
|
|
920
|
+
advanced: asBucket(block.advanced),
|
|
921
|
+
context
|
|
922
|
+
}) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
|
|
911
923
|
}
|
|
912
924
|
);
|
|
913
925
|
}
|
|
@@ -953,6 +965,7 @@ exports.parseEditorMessage = parseEditorMessage;
|
|
|
953
965
|
exports.postToEditor = postToEditor;
|
|
954
966
|
exports.resolveApiUrl = resolveApiUrl;
|
|
955
967
|
exports.resolveForms = resolveForms;
|
|
968
|
+
exports.resolvePublicUrl = resolvePublicUrl;
|
|
956
969
|
exports.resolveSiteLocales = resolveSiteLocales;
|
|
957
970
|
exports.resolveWorkspaceId = resolveWorkspaceId;
|
|
958
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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
|
@@ -99,12 +99,8 @@ function getBlockContentForLanguage(content, locale, defaultLocale = "en", avail
|
|
|
99
99
|
const chosen = localeMap[locale] ?? localeMap[defaultLocale] ?? localeMap[fallbackKey];
|
|
100
100
|
return { ...nonTranslatable, ...chosen };
|
|
101
101
|
}
|
|
102
|
-
function
|
|
103
|
-
return {
|
|
104
|
-
...content,
|
|
105
|
-
...isPlainObject(style) ? style : {},
|
|
106
|
-
...isPlainObject(advanced) ? advanced : {}
|
|
107
|
-
};
|
|
102
|
+
function asBucket(value) {
|
|
103
|
+
return isPlainObject(value) ? value : {};
|
|
108
104
|
}
|
|
109
105
|
|
|
110
106
|
// src/components/block-context.ts
|
|
@@ -134,20 +130,25 @@ function UnknownBlock({ type }) {
|
|
|
134
130
|
function renderResolvedBlock(block, map, locale, defaultLocale, options = {}) {
|
|
135
131
|
const { context, data, resolvedContent, enabledLocales } = options;
|
|
136
132
|
const Component = Object.hasOwn(map, block.type) ? map[block.type] : void 0;
|
|
137
|
-
const
|
|
133
|
+
const content = resolvedContent ?? getBlockContentForLanguage(
|
|
138
134
|
block.content,
|
|
139
135
|
locale,
|
|
140
136
|
defaultLocale,
|
|
141
137
|
enabledLocales?.length ? enabledLocales : void 0
|
|
142
138
|
);
|
|
143
|
-
const content = mergeBlockValues(resolved, block.style, block.advanced);
|
|
144
139
|
return /* @__PURE__ */ jsx(
|
|
145
140
|
"div",
|
|
146
141
|
{
|
|
147
142
|
"data-block-id": block.id,
|
|
148
143
|
"data-block-type": block.type,
|
|
149
144
|
style: Component ? void 0 : { display: "none" },
|
|
150
|
-
children: Component ? createElement(Component, {
|
|
145
|
+
children: Component ? createElement(Component, {
|
|
146
|
+
content,
|
|
147
|
+
style: asBucket(block.style),
|
|
148
|
+
advanced: asBucket(block.advanced),
|
|
149
|
+
context,
|
|
150
|
+
data
|
|
151
|
+
}) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
|
|
151
152
|
},
|
|
152
153
|
block.id
|
|
153
154
|
);
|
|
@@ -313,6 +314,10 @@ function resolveApiUrl(apiUrl) {
|
|
|
313
314
|
const fromEnv = env?.CMSSY_API_URL?.trim() ?? "";
|
|
314
315
|
return fromEnv.length > 0 ? fromEnv : DEFAULT_CMSSY_API_URL;
|
|
315
316
|
}
|
|
317
|
+
function resolvePublicUrl(config) {
|
|
318
|
+
const base = resolveApiUrl(config.apiUrl).replace(/\/graphql\/?$/, "");
|
|
319
|
+
return `${base}/public/${config.org}/${config.workspaceSlug}/graphql`;
|
|
320
|
+
}
|
|
316
321
|
var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String) {
|
|
317
322
|
public {
|
|
318
323
|
page {
|
|
@@ -409,7 +414,7 @@ async function fetchPage(config, path, options = {}) {
|
|
|
409
414
|
headers["x-workspace-id"] = options.workspaceId;
|
|
410
415
|
}
|
|
411
416
|
}
|
|
412
|
-
const response = await doFetch(
|
|
417
|
+
const response = await doFetch(resolvePublicUrl(config), {
|
|
413
418
|
method: "POST",
|
|
414
419
|
headers,
|
|
415
420
|
body: JSON.stringify({
|
|
@@ -458,7 +463,7 @@ async function fetchPageById(config, pageId, options = {}) {
|
|
|
458
463
|
"cmssy: no fetch implementation available - pass options.fetch"
|
|
459
464
|
);
|
|
460
465
|
}
|
|
461
|
-
const response = await doFetch(
|
|
466
|
+
const response = await doFetch(resolvePublicUrl(config), {
|
|
462
467
|
method: "POST",
|
|
463
468
|
headers: { "content-type": "application/json" },
|
|
464
469
|
body: JSON.stringify({
|
|
@@ -502,7 +507,7 @@ async function fetchPages(config, options = {}) {
|
|
|
502
507
|
"cmssy: no fetch implementation available - pass options.fetch"
|
|
503
508
|
);
|
|
504
509
|
}
|
|
505
|
-
const response = await doFetch(
|
|
510
|
+
const response = await doFetch(resolvePublicUrl(config), {
|
|
506
511
|
method: "POST",
|
|
507
512
|
headers: { "content-type": "application/json" },
|
|
508
513
|
body: JSON.stringify({
|
|
@@ -534,7 +539,7 @@ async function fetchPageMeta(config, path, options = {}) {
|
|
|
534
539
|
"cmssy: no fetch implementation available - pass options.fetch"
|
|
535
540
|
);
|
|
536
541
|
}
|
|
537
|
-
const response = await doFetch(
|
|
542
|
+
const response = await doFetch(resolvePublicUrl(config), {
|
|
538
543
|
method: "POST",
|
|
539
544
|
headers: { "content-type": "application/json" },
|
|
540
545
|
body: JSON.stringify({
|
|
@@ -568,7 +573,7 @@ async function fetchLayouts(config, path, options = {}) {
|
|
|
568
573
|
}
|
|
569
574
|
const trimmedSecret = options.previewSecret?.trim();
|
|
570
575
|
const previewSecret = trimmedSecret ? trimmedSecret : null;
|
|
571
|
-
const response = await doFetch(
|
|
576
|
+
const response = await doFetch(resolvePublicUrl(config), {
|
|
572
577
|
method: "POST",
|
|
573
578
|
headers: { "content-type": "application/json" },
|
|
574
579
|
body: JSON.stringify({
|
|
@@ -605,7 +610,8 @@ async function graphqlRequest(config, query, variables, options = {}, label = "r
|
|
|
605
610
|
"cmssy: no fetch implementation available - pass options.fetch"
|
|
606
611
|
);
|
|
607
612
|
}
|
|
608
|
-
const
|
|
613
|
+
const url = options.public ? resolvePublicUrl(config) : resolveApiUrl(config.apiUrl);
|
|
614
|
+
const response = await doFetch(url, {
|
|
609
615
|
method: "POST",
|
|
610
616
|
headers: { "content-type": "application/json", ...options.headers },
|
|
611
617
|
body: JSON.stringify({ query, variables }),
|
|
@@ -638,20 +644,22 @@ async function graphqlRequest(config, query, variables, options = {}, label = "r
|
|
|
638
644
|
|
|
639
645
|
// src/data/queries.ts
|
|
640
646
|
var SITE_CONFIG_QUERY = `query PublicSiteConfig($workspaceSlug: String!) {
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
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
|
+
}
|
|
655
663
|
}
|
|
656
664
|
}
|
|
657
665
|
}`;
|
|
@@ -697,10 +705,10 @@ async function fetchSiteConfig(config, options = {}) {
|
|
|
697
705
|
config,
|
|
698
706
|
SITE_CONFIG_QUERY,
|
|
699
707
|
{ workspaceSlug: config.workspaceSlug },
|
|
700
|
-
options,
|
|
708
|
+
{ ...options, public: true },
|
|
701
709
|
"site config query"
|
|
702
710
|
);
|
|
703
|
-
return data.
|
|
711
|
+
return data.public?.siteConfig ?? null;
|
|
704
712
|
}
|
|
705
713
|
async function resolveWorkspaceId(config, options = {}) {
|
|
706
714
|
const siteConfig = await fetchSiteConfig(config, options);
|
|
@@ -803,7 +811,7 @@ var TTL_MS = 6e4;
|
|
|
803
811
|
var MAX_ENTRIES = 64;
|
|
804
812
|
var cache = /* @__PURE__ */ new Map();
|
|
805
813
|
async function resolveSiteLocales(config, options) {
|
|
806
|
-
const key = `${resolveApiUrl(config.apiUrl)}::${config.workspaceSlug}`;
|
|
814
|
+
const key = `${resolveApiUrl(config.apiUrl)}::${config.org}::${config.workspaceSlug}`;
|
|
807
815
|
const cached = cache.get(key);
|
|
808
816
|
if (cached && cached.expires > Date.now()) return cached.value;
|
|
809
817
|
cache.delete(key);
|
|
@@ -813,10 +821,10 @@ async function resolveSiteLocales(config, options) {
|
|
|
813
821
|
config,
|
|
814
822
|
SITE_CONFIG_QUERY,
|
|
815
823
|
{ workspaceSlug: config.workspaceSlug },
|
|
816
|
-
options,
|
|
824
|
+
{ ...options, public: true },
|
|
817
825
|
"site config"
|
|
818
826
|
);
|
|
819
|
-
const siteConfig = data.
|
|
827
|
+
const siteConfig = data.public?.siteConfig ?? null;
|
|
820
828
|
const defaultLocale = siteConfig?.defaultLanguage || "en";
|
|
821
829
|
const enabled = siteConfig?.enabledLanguages ?? [];
|
|
822
830
|
value = {
|
|
@@ -895,8 +903,7 @@ function CmssyBlock({
|
|
|
895
903
|
}) {
|
|
896
904
|
const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
|
|
897
905
|
const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
898
|
-
const
|
|
899
|
-
const content = mergeBlockValues(resolved, block.style, block.advanced);
|
|
906
|
+
const content = patchedContent ? { ...base, ...patchedContent } : base;
|
|
900
907
|
return /* @__PURE__ */ jsx(
|
|
901
908
|
"div",
|
|
902
909
|
{
|
|
@@ -905,9 +912,14 @@ function CmssyBlock({
|
|
|
905
912
|
"data-layout-position": layoutPosition,
|
|
906
913
|
draggable: editable || void 0,
|
|
907
914
|
style: Component ? void 0 : { display: "none" },
|
|
908
|
-
children: Component ? createElement(Component, {
|
|
915
|
+
children: Component ? createElement(Component, {
|
|
916
|
+
content,
|
|
917
|
+
style: asBucket(block.style),
|
|
918
|
+
advanced: asBucket(block.advanced),
|
|
919
|
+
context
|
|
920
|
+
}) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
|
|
909
921
|
}
|
|
910
922
|
);
|
|
911
923
|
}
|
|
912
924
|
|
|
913
|
-
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 };
|