@cmssy/react 0.6.0 → 0.7.1

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
@@ -303,6 +303,13 @@ var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String
303
303
  publishedBlocks { id type content }
304
304
  }
305
305
  }`;
306
+ var PUBLIC_PAGE_DEV_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String, $devPreview: Boolean) {
307
+ publicPage(workspaceSlug: $workspaceSlug, slug: $slug, previewSecret: $previewSecret, devPreview: $devPreview) {
308
+ id
309
+ blocks { id type content }
310
+ publishedBlocks { id type content }
311
+ }
312
+ }`;
306
313
  var PUBLIC_PAGE_BY_ID_QUERY = `query PublicPageById($workspaceSlug: String!, $pageId: ID!) {
307
314
  publicPageById(workspaceSlug: $workspaceSlug, pageId: $pageId) {
308
315
  id
@@ -350,15 +357,27 @@ async function fetchPage(config, path, options = {}) {
350
357
  }
351
358
  const trimmedSecret = options.previewSecret?.trim();
352
359
  const previewSecret = trimmedSecret ? trimmedSecret : null;
360
+ const devToken = options.devToken?.trim();
361
+ const devPreview = Boolean(options.devPreview && devToken);
362
+ const headers = {
363
+ "content-type": "application/json"
364
+ };
365
+ if (devPreview && devToken) {
366
+ headers["authorization"] = `Bearer ${devToken}`;
367
+ if (options.workspaceId) {
368
+ headers["x-workspace-id"] = options.workspaceId;
369
+ }
370
+ }
353
371
  const response = await doFetch(resolveApiUrl(config.apiUrl), {
354
372
  method: "POST",
355
- headers: { "content-type": "application/json" },
373
+ headers,
356
374
  body: JSON.stringify({
357
- query: PUBLIC_PAGE_QUERY,
375
+ query: devPreview ? PUBLIC_PAGE_DEV_QUERY : PUBLIC_PAGE_QUERY,
358
376
  variables: {
359
377
  workspaceSlug: config.workspaceSlug,
360
378
  slug,
361
- previewSecret
379
+ previewSecret,
380
+ ...devPreview ? { devPreview: true } : {}
362
381
  }
363
382
  }),
364
383
  signal: options.signal
@@ -387,7 +406,7 @@ async function fetchPage(config, path, options = {}) {
387
406
  }
388
407
  const page = json.data?.publicPage;
389
408
  if (!page) return null;
390
- const draft = previewSecret !== null;
409
+ const draft = previewSecret !== null || devPreview;
391
410
  const blocks = (draft ? page.blocks : page.publishedBlocks) ?? [];
392
411
  return { id: page.id, blocks };
393
412
  }
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
@@ -301,6 +301,13 @@ var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String
301
301
  publishedBlocks { id type content }
302
302
  }
303
303
  }`;
304
+ var PUBLIC_PAGE_DEV_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String, $devPreview: Boolean) {
305
+ publicPage(workspaceSlug: $workspaceSlug, slug: $slug, previewSecret: $previewSecret, devPreview: $devPreview) {
306
+ id
307
+ blocks { id type content }
308
+ publishedBlocks { id type content }
309
+ }
310
+ }`;
304
311
  var PUBLIC_PAGE_BY_ID_QUERY = `query PublicPageById($workspaceSlug: String!, $pageId: ID!) {
305
312
  publicPageById(workspaceSlug: $workspaceSlug, pageId: $pageId) {
306
313
  id
@@ -348,15 +355,27 @@ async function fetchPage(config, path, options = {}) {
348
355
  }
349
356
  const trimmedSecret = options.previewSecret?.trim();
350
357
  const previewSecret = trimmedSecret ? trimmedSecret : null;
358
+ const devToken = options.devToken?.trim();
359
+ const devPreview = Boolean(options.devPreview && devToken);
360
+ const headers = {
361
+ "content-type": "application/json"
362
+ };
363
+ if (devPreview && devToken) {
364
+ headers["authorization"] = `Bearer ${devToken}`;
365
+ if (options.workspaceId) {
366
+ headers["x-workspace-id"] = options.workspaceId;
367
+ }
368
+ }
351
369
  const response = await doFetch(resolveApiUrl(config.apiUrl), {
352
370
  method: "POST",
353
- headers: { "content-type": "application/json" },
371
+ headers,
354
372
  body: JSON.stringify({
355
- query: PUBLIC_PAGE_QUERY,
373
+ query: devPreview ? PUBLIC_PAGE_DEV_QUERY : PUBLIC_PAGE_QUERY,
356
374
  variables: {
357
375
  workspaceSlug: config.workspaceSlug,
358
376
  slug,
359
- previewSecret
377
+ previewSecret,
378
+ ...devPreview ? { devPreview: true } : {}
360
379
  }
361
380
  }),
362
381
  signal: options.signal
@@ -385,7 +404,7 @@ async function fetchPage(config, path, options = {}) {
385
404
  }
386
405
  const page = json.data?.publicPage;
387
406
  if (!page) return null;
388
- const draft = previewSecret !== null;
407
+ const draft = previewSecret !== null || devPreview;
389
408
  const blocks = (draft ? page.blocks : page.publishedBlocks) ?? [];
390
409
  return { id: page.id, blocks };
391
410
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/react",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
5
5
  "keywords": [
6
6
  "cmssy",