@cmssy/react 0.6.0 → 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/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-Ct37AIeC.cjs';
3
- export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-Ct37AIeC.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-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-Ct37AIeC.js';
3
- export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-Ct37AIeC.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-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 {
@@ -25,6 +25,9 @@ type FetchLike = (url: string, init: {
25
25
  }) => Promise<FetchLikeResponse>;
26
26
  interface FetchPageOptions {
27
27
  previewSecret?: string;
28
+ devPreview?: boolean;
29
+ devToken?: string;
30
+ workspaceId?: string;
28
31
  fetch?: FetchLike;
29
32
  signal?: AbortSignal;
30
33
  }
@@ -25,6 +25,9 @@ type FetchLike = (url: string, init: {
25
25
  }) => Promise<FetchLikeResponse>;
26
26
  interface FetchPageOptions {
27
27
  previewSecret?: string;
28
+ devPreview?: boolean;
29
+ devToken?: string;
30
+ workspaceId?: string;
28
31
  fetch?: FetchLike;
29
32
  signal?: AbortSignal;
30
33
  }
package/dist/index.cjs CHANGED
@@ -296,8 +296,8 @@ function resolveApiUrl(apiUrl) {
296
296
  const fromEnv = env?.CMSSY_API_URL?.trim() ?? "";
297
297
  return fromEnv.length > 0 ? fromEnv : DEFAULT_CMSSY_API_URL;
298
298
  }
299
- var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String) {
300
- publicPage(workspaceSlug: $workspaceSlug, slug: $slug, previewSecret: $previewSecret) {
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) {
301
301
  id
302
302
  blocks { id type content }
303
303
  publishedBlocks { id type content }
@@ -350,15 +350,27 @@ async function fetchPage(config, path, options = {}) {
350
350
  }
351
351
  const trimmedSecret = options.previewSecret?.trim();
352
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
+ }
353
364
  const response = await doFetch(resolveApiUrl(config.apiUrl), {
354
365
  method: "POST",
355
- headers: { "content-type": "application/json" },
366
+ headers,
356
367
  body: JSON.stringify({
357
368
  query: PUBLIC_PAGE_QUERY,
358
369
  variables: {
359
370
  workspaceSlug: config.workspaceSlug,
360
371
  slug,
361
- previewSecret
372
+ previewSecret,
373
+ devPreview: devPreview ? true : null
362
374
  }
363
375
  }),
364
376
  signal: options.signal
@@ -387,7 +399,7 @@ async function fetchPage(config, path, options = {}) {
387
399
  }
388
400
  const page = json.data?.publicPage;
389
401
  if (!page) return null;
390
- const draft = previewSecret !== null;
402
+ const draft = previewSecret !== null || devPreview;
391
403
  const blocks = (draft ? page.blocks : page.publishedBlocks) ?? [];
392
404
  return { id: page.id, blocks };
393
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-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';
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-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';
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
@@ -294,8 +294,8 @@ function resolveApiUrl(apiUrl) {
294
294
  const fromEnv = env?.CMSSY_API_URL?.trim() ?? "";
295
295
  return fromEnv.length > 0 ? fromEnv : DEFAULT_CMSSY_API_URL;
296
296
  }
297
- var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String) {
298
- publicPage(workspaceSlug: $workspaceSlug, slug: $slug, previewSecret: $previewSecret) {
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) {
299
299
  id
300
300
  blocks { id type content }
301
301
  publishedBlocks { id type content }
@@ -348,15 +348,27 @@ async function fetchPage(config, path, options = {}) {
348
348
  }
349
349
  const trimmedSecret = options.previewSecret?.trim();
350
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
+ }
351
362
  const response = await doFetch(resolveApiUrl(config.apiUrl), {
352
363
  method: "POST",
353
- headers: { "content-type": "application/json" },
364
+ headers,
354
365
  body: JSON.stringify({
355
366
  query: PUBLIC_PAGE_QUERY,
356
367
  variables: {
357
368
  workspaceSlug: config.workspaceSlug,
358
369
  slug,
359
- previewSecret
370
+ previewSecret,
371
+ devPreview: devPreview ? true : null
360
372
  }
361
373
  }),
362
374
  signal: options.signal
@@ -385,7 +397,7 @@ async function fetchPage(config, path, options = {}) {
385
397
  }
386
398
  const page = json.data?.publicPage;
387
399
  if (!page) return null;
388
- const draft = previewSecret !== null;
400
+ const draft = previewSecret !== null || devPreview;
389
401
  const blocks = (draft ? page.blocks : page.publishedBlocks) ?? [];
390
402
  return { id: page.id, blocks };
391
403
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/react",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
5
5
  "keywords": [
6
6
  "cmssy",