@cmssy/react 0.5.6 → 0.7.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 -8
- package/dist/client.d.cts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/{commerce-queries-Dx6EW4Sr.d.cts → commerce-queries-CA8_5lMX.d.cts} +3 -1
- package/dist/{commerce-queries-Dx6EW4Sr.d.ts → commerce-queries-CA8_5lMX.d.ts} +3 -1
- package/dist/index.cjs +23 -7
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +23 -7
- package/package.json +1 -1
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-
|
|
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-CA8_5lMX.cjs';
|
|
3
|
+
export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-CA8_5lMX.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-
|
|
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-CA8_5lMX.js';
|
|
3
|
+
export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-CA8_5lMX.js';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
|
|
6
6
|
interface EditBridgeConfig {
|
|
@@ -6,7 +6,6 @@ import { ComponentType } from 'react';
|
|
|
6
6
|
* staging deployments override it via config.
|
|
7
7
|
*/
|
|
8
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
9
|
declare function resolveApiUrl(apiUrl: string | undefined): string;
|
|
11
10
|
interface CmssyClientConfig {
|
|
12
11
|
/** Full GraphQL delivery endpoint. Defaults to {@link DEFAULT_CMSSY_API_URL}. */
|
|
@@ -26,6 +25,9 @@ type FetchLike = (url: string, init: {
|
|
|
26
25
|
}) => Promise<FetchLikeResponse>;
|
|
27
26
|
interface FetchPageOptions {
|
|
28
27
|
previewSecret?: string;
|
|
28
|
+
devPreview?: boolean;
|
|
29
|
+
devToken?: string;
|
|
30
|
+
workspaceId?: string;
|
|
29
31
|
fetch?: FetchLike;
|
|
30
32
|
signal?: AbortSignal;
|
|
31
33
|
}
|
|
@@ -6,7 +6,6 @@ import { ComponentType } from 'react';
|
|
|
6
6
|
* staging deployments override it via config.
|
|
7
7
|
*/
|
|
8
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
9
|
declare function resolveApiUrl(apiUrl: string | undefined): string;
|
|
11
10
|
interface CmssyClientConfig {
|
|
12
11
|
/** Full GraphQL delivery endpoint. Defaults to {@link DEFAULT_CMSSY_API_URL}. */
|
|
@@ -26,6 +25,9 @@ type FetchLike = (url: string, init: {
|
|
|
26
25
|
}) => Promise<FetchLikeResponse>;
|
|
27
26
|
interface FetchPageOptions {
|
|
28
27
|
previewSecret?: string;
|
|
28
|
+
devPreview?: boolean;
|
|
29
|
+
devToken?: string;
|
|
30
|
+
workspaceId?: string;
|
|
29
31
|
fetch?: FetchLike;
|
|
30
32
|
signal?: AbortSignal;
|
|
31
33
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -290,10 +290,14 @@ function parseEditorMessage(data, origin, expectedOrigin) {
|
|
|
290
290
|
// src/content/content-client.ts
|
|
291
291
|
var DEFAULT_CMSSY_API_URL = "https://api.cmssy.io/graphql";
|
|
292
292
|
function resolveApiUrl(apiUrl) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
+
}
|
|
299
|
+
var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String, $devPreview: Boolean) {
|
|
300
|
+
publicPage(workspaceSlug: $workspaceSlug, slug: $slug, previewSecret: $previewSecret, devPreview: $devPreview) {
|
|
297
301
|
id
|
|
298
302
|
blocks { id type content }
|
|
299
303
|
publishedBlocks { id type content }
|
|
@@ -346,15 +350,27 @@ async function fetchPage(config, path, options = {}) {
|
|
|
346
350
|
}
|
|
347
351
|
const trimmedSecret = options.previewSecret?.trim();
|
|
348
352
|
const previewSecret = trimmedSecret ? trimmedSecret : null;
|
|
353
|
+
const devToken = options.devToken?.trim();
|
|
354
|
+
const devPreview = Boolean(options.devPreview && devToken);
|
|
355
|
+
const headers = {
|
|
356
|
+
"content-type": "application/json"
|
|
357
|
+
};
|
|
358
|
+
if (devPreview && devToken) {
|
|
359
|
+
headers["authorization"] = `Bearer ${devToken}`;
|
|
360
|
+
if (options.workspaceId) {
|
|
361
|
+
headers["x-workspace-id"] = options.workspaceId;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
349
364
|
const response = await doFetch(resolveApiUrl(config.apiUrl), {
|
|
350
365
|
method: "POST",
|
|
351
|
-
headers
|
|
366
|
+
headers,
|
|
352
367
|
body: JSON.stringify({
|
|
353
368
|
query: PUBLIC_PAGE_QUERY,
|
|
354
369
|
variables: {
|
|
355
370
|
workspaceSlug: config.workspaceSlug,
|
|
356
371
|
slug,
|
|
357
|
-
previewSecret
|
|
372
|
+
previewSecret,
|
|
373
|
+
devPreview: devPreview ? true : null
|
|
358
374
|
}
|
|
359
375
|
}),
|
|
360
376
|
signal: options.signal
|
|
@@ -383,7 +399,7 @@ async function fetchPage(config, path, options = {}) {
|
|
|
383
399
|
}
|
|
384
400
|
const page = json.data?.publicPage;
|
|
385
401
|
if (!page) return null;
|
|
386
|
-
const draft = previewSecret !== null;
|
|
402
|
+
const draft = previewSecret !== null || devPreview;
|
|
387
403
|
const blocks = (draft ? page.blocks : page.publishedBlocks) ?? [];
|
|
388
404
|
return { id: page.id, blocks };
|
|
389
405
|
}
|
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 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-
|
|
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-CA8_5lMX.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-CA8_5lMX.cjs';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import 'react';
|
|
5
5
|
|
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 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-
|
|
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-CA8_5lMX.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-CA8_5lMX.js';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import 'react';
|
|
5
5
|
|
package/dist/index.js
CHANGED
|
@@ -288,10 +288,14 @@ function parseEditorMessage(data, origin, expectedOrigin) {
|
|
|
288
288
|
// src/content/content-client.ts
|
|
289
289
|
var DEFAULT_CMSSY_API_URL = "https://api.cmssy.io/graphql";
|
|
290
290
|
function resolveApiUrl(apiUrl) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
+
}
|
|
297
|
+
var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String, $devPreview: Boolean) {
|
|
298
|
+
publicPage(workspaceSlug: $workspaceSlug, slug: $slug, previewSecret: $previewSecret, devPreview: $devPreview) {
|
|
295
299
|
id
|
|
296
300
|
blocks { id type content }
|
|
297
301
|
publishedBlocks { id type content }
|
|
@@ -344,15 +348,27 @@ async function fetchPage(config, path, options = {}) {
|
|
|
344
348
|
}
|
|
345
349
|
const trimmedSecret = options.previewSecret?.trim();
|
|
346
350
|
const previewSecret = trimmedSecret ? trimmedSecret : null;
|
|
351
|
+
const devToken = options.devToken?.trim();
|
|
352
|
+
const devPreview = Boolean(options.devPreview && devToken);
|
|
353
|
+
const headers = {
|
|
354
|
+
"content-type": "application/json"
|
|
355
|
+
};
|
|
356
|
+
if (devPreview && devToken) {
|
|
357
|
+
headers["authorization"] = `Bearer ${devToken}`;
|
|
358
|
+
if (options.workspaceId) {
|
|
359
|
+
headers["x-workspace-id"] = options.workspaceId;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
347
362
|
const response = await doFetch(resolveApiUrl(config.apiUrl), {
|
|
348
363
|
method: "POST",
|
|
349
|
-
headers
|
|
364
|
+
headers,
|
|
350
365
|
body: JSON.stringify({
|
|
351
366
|
query: PUBLIC_PAGE_QUERY,
|
|
352
367
|
variables: {
|
|
353
368
|
workspaceSlug: config.workspaceSlug,
|
|
354
369
|
slug,
|
|
355
|
-
previewSecret
|
|
370
|
+
previewSecret,
|
|
371
|
+
devPreview: devPreview ? true : null
|
|
356
372
|
}
|
|
357
373
|
}),
|
|
358
374
|
signal: options.signal
|
|
@@ -381,7 +397,7 @@ async function fetchPage(config, path, options = {}) {
|
|
|
381
397
|
}
|
|
382
398
|
const page = json.data?.publicPage;
|
|
383
399
|
if (!page) return null;
|
|
384
|
-
const draft = previewSecret !== null;
|
|
400
|
+
const draft = previewSecret !== null || devPreview;
|
|
385
401
|
const blocks = (draft ? page.blocks : page.publishedBlocks) ?? [];
|
|
386
402
|
return { id: page.id, blocks };
|
|
387
403
|
}
|