@cmssy/next 0.5.6 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,11 +26,10 @@ export default createCmssyPage(cmssy, blocks, { editor: CmssyEditor });
26
26
  import type { CmssyNextConfig } from "@cmssy/next";
27
27
 
28
28
  export const cmssy: CmssyNextConfig = {
29
- apiUrl: process.env.CMSSY_API_URL ?? "", // public GraphQL delivery endpoint
30
29
  workspaceSlug: process.env.CMSSY_WORKSPACE_SLUG ?? "",
31
30
  draftSecret: process.env.CMSSY_DRAFT_SECRET ?? "", // edit-mode preview handshake
32
- editorOrigin: process.env.CMSSY_EDITOR_ORIGIN ?? "", // only needed in edit mode
33
31
  defaultLocale: "en",
32
+ // apiUrl + editorOrigin default to cmssy cloud; set them only for self-host/staging.
34
33
  };
35
34
  ```
36
35
 
package/dist/index.cjs CHANGED
@@ -71,14 +71,29 @@ function sessionCookieOptions() {
71
71
  }
72
72
 
73
73
  // src/config.ts
74
- var DEFAULT_CMSSY_EDITOR_ORIGIN = "https://www.cmssy.io";
74
+ var DEFAULT_CMSSY_EDITOR_ORIGINS = [
75
+ "https://cmssy.io",
76
+ "https://www.cmssy.io"
77
+ ];
78
+ function parseEditorOriginEnv(raw) {
79
+ if (!raw) return void 0;
80
+ const parts = raw.split(",").map((o) => o.trim()).filter((o) => o.length > 0);
81
+ if (parts.length === 0) return void 0;
82
+ return parts.length === 1 ? parts[0] : parts;
83
+ }
84
+ function isDevelopment() {
85
+ return typeof process !== "undefined" && process.env.NODE_ENV === "development";
86
+ }
75
87
  function resolveEditorOrigin(editorOrigin) {
76
- if (editorOrigin === void 0) return DEFAULT_CMSSY_EDITOR_ORIGIN;
77
- if (Array.isArray(editorOrigin)) {
78
- const cleaned = editorOrigin.filter((o) => o && o.trim().length > 0);
79
- return cleaned.length > 0 ? cleaned : DEFAULT_CMSSY_EDITOR_ORIGIN;
88
+ const value = editorOrigin ?? (typeof process !== "undefined" ? parseEditorOriginEnv(process.env.CMSSY_EDITOR_ORIGIN) : void 0);
89
+ if (value === void 0) {
90
+ return isDevelopment() ? "*" : DEFAULT_CMSSY_EDITOR_ORIGINS;
91
+ }
92
+ if (Array.isArray(value)) {
93
+ const cleaned = value.filter((o) => o && o.trim().length > 0);
94
+ return cleaned.length > 0 ? cleaned : DEFAULT_CMSSY_EDITOR_ORIGINS;
80
95
  }
81
- return editorOrigin.trim().length > 0 ? editorOrigin : DEFAULT_CMSSY_EDITOR_ORIGIN;
96
+ return value.trim().length > 0 ? value : DEFAULT_CMSSY_EDITOR_ORIGINS;
82
97
  }
83
98
  function assertAuthConfig(config) {
84
99
  const auth = config.auth;
@@ -286,9 +301,9 @@ function resolveBridgeOrigin(editorOrigin) {
286
301
  );
287
302
  }
288
303
  const origin = toCspOrigin(origins[0].trim());
289
- if (origin === "*") {
304
+ if (origin === "*" && !isDevelopment()) {
290
305
  throw new Error(
291
- "cmssy: editorOrigin '*' is not allowed for the live-edit bridge; set the concrete editor origin (e.g. https://www.cmssy.io)"
306
+ "cmssy: editorOrigin '*' is only allowed in development; set a concrete editor origin (e.g. https://cmssy.io) for production"
292
307
  );
293
308
  }
294
309
  return origin;
@@ -1631,7 +1646,7 @@ exports.CMSSY_EDIT_HEADER = CMSSY_EDIT_HEADER;
1631
1646
  exports.CMSSY_LOCALE_HEADER = CMSSY_LOCALE_HEADER;
1632
1647
  exports.CMSSY_SESSION_COOKIE = CMSSY_SESSION_COOKIE;
1633
1648
  exports.CmssyWebhookError = CmssyWebhookError;
1634
- exports.DEFAULT_CMSSY_EDITOR_ORIGIN = DEFAULT_CMSSY_EDITOR_ORIGIN;
1649
+ exports.DEFAULT_CMSSY_EDITOR_ORIGINS = DEFAULT_CMSSY_EDITOR_ORIGINS;
1635
1650
  exports.SESSION_MAX_AGE_SECONDS = SESSION_MAX_AGE_SECONDS;
1636
1651
  exports.applyCmssyCsp = applyCmssyCsp;
1637
1652
  exports.assertAuthConfig = assertAuthConfig;
package/dist/index.d.cts CHANGED
@@ -6,13 +6,7 @@ import { EditBridgeConfig } from '@cmssy/react/client';
6
6
  import { MetadataRoute, Metadata } from 'next';
7
7
  import { NextRequest, NextResponse } from 'next/server';
8
8
 
9
- /**
10
- * Origin of the cmssy admin/editor that frames your site (postMessage source +
11
- * CSP `frame-ancestors`). Identical for every workspace on cmssy cloud, so
12
- * `editorOrigin` defaults to this. Self-hosted admins override it via config.
13
- */
14
- declare const DEFAULT_CMSSY_EDITOR_ORIGIN = "https://www.cmssy.io";
15
- /** Resolves `editorOrigin`, falling back to the cmssy cloud admin when unset. */
9
+ declare const DEFAULT_CMSSY_EDITOR_ORIGINS: string[];
16
10
  declare function resolveEditorOrigin(editorOrigin: string | string[] | undefined): string | string[];
17
11
  interface CmssyAuthConfig {
18
12
  modelSlug: string;
@@ -28,7 +22,7 @@ interface CmssyNextConfig {
28
22
  draftSecret: string;
29
23
  /**
30
24
  * Origin allowed to frame your app in the editor. Defaults to
31
- * {@link DEFAULT_CMSSY_EDITOR_ORIGIN}; set it only for self-hosted admins.
25
+ * {@link DEFAULT_CMSSY_EDITOR_ORIGINS}; set it only for self-hosted admins.
32
26
  */
33
27
  editorOrigin?: string | string[];
34
28
  /**
@@ -346,4 +340,4 @@ declare class CmssyWebhookError extends Error {
346
340
  */
347
341
  declare function verifyCmssyWebhook(options: VerifyCmssyWebhookOptions): CmssyWebhookEvent;
348
342
 
349
- export { type BuildCmssyMetadataOptions, CMSSY_CART_COOKIE, CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, CMSSY_SESSION_COOKIE, type CmssyAuthConfig, type CmssyAuthMiddleware, type CmssyAuthRouteHandlers, type CmssyCartRouteHandlers, type CmssyCspOptions, type CmssyDraftRouteConfig, type CmssyEditorProps, type CmssyNextConfig, type CmssyOrdersRouteHandlers, type CmssySessionPayload, type CmssySessionUser, CmssyWebhookError, type CmssyWebhookEvent, type CmssyWebhookOrder, type CreateCmssyNotFoundOptions, type CreateCmssyPageOptions, type CreateCmssyRobotsOptions, type CreateCmssySitemapOptions, DEFAULT_CMSSY_EDITOR_ORIGIN, type FetchProductOptions, type FetchProductsOptions, type MyOrdersResult, SESSION_MAX_AGE_SECONDS, type SessionCookieOptions, type VerifyCmssyWebhookOptions, applyCmssyCsp, assertAuthConfig, buildCmssyMetadata, cmssyCspHeaders, createCmssyAuthMiddleware, createCmssyAuthRoute, createCmssyCartRoute, createCmssyLocaleMiddleware, createCmssyNotFound, createCmssyOrdersRoute, createCmssyPage, createCmssyRobots, createCmssySitemap, createDraftRoute, fetchProduct, fetchProducts, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, resolveEditorOrigin, resolveLocaleFromPathname, sealSession, sessionCookieOptions, splitCmssyLocale, verifyCmssyWebhook };
343
+ export { type BuildCmssyMetadataOptions, CMSSY_CART_COOKIE, CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, CMSSY_SESSION_COOKIE, type CmssyAuthConfig, type CmssyAuthMiddleware, type CmssyAuthRouteHandlers, type CmssyCartRouteHandlers, type CmssyCspOptions, type CmssyDraftRouteConfig, type CmssyEditorProps, type CmssyNextConfig, type CmssyOrdersRouteHandlers, type CmssySessionPayload, type CmssySessionUser, CmssyWebhookError, type CmssyWebhookEvent, type CmssyWebhookOrder, type CreateCmssyNotFoundOptions, type CreateCmssyPageOptions, type CreateCmssyRobotsOptions, type CreateCmssySitemapOptions, DEFAULT_CMSSY_EDITOR_ORIGINS, type FetchProductOptions, type FetchProductsOptions, type MyOrdersResult, SESSION_MAX_AGE_SECONDS, type SessionCookieOptions, type VerifyCmssyWebhookOptions, applyCmssyCsp, assertAuthConfig, buildCmssyMetadata, cmssyCspHeaders, createCmssyAuthMiddleware, createCmssyAuthRoute, createCmssyCartRoute, createCmssyLocaleMiddleware, createCmssyNotFound, createCmssyOrdersRoute, createCmssyPage, createCmssyRobots, createCmssySitemap, createDraftRoute, fetchProduct, fetchProducts, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, resolveEditorOrigin, resolveLocaleFromPathname, sealSession, sessionCookieOptions, splitCmssyLocale, verifyCmssyWebhook };
package/dist/index.d.ts CHANGED
@@ -6,13 +6,7 @@ import { EditBridgeConfig } from '@cmssy/react/client';
6
6
  import { MetadataRoute, Metadata } from 'next';
7
7
  import { NextRequest, NextResponse } from 'next/server';
8
8
 
9
- /**
10
- * Origin of the cmssy admin/editor that frames your site (postMessage source +
11
- * CSP `frame-ancestors`). Identical for every workspace on cmssy cloud, so
12
- * `editorOrigin` defaults to this. Self-hosted admins override it via config.
13
- */
14
- declare const DEFAULT_CMSSY_EDITOR_ORIGIN = "https://www.cmssy.io";
15
- /** Resolves `editorOrigin`, falling back to the cmssy cloud admin when unset. */
9
+ declare const DEFAULT_CMSSY_EDITOR_ORIGINS: string[];
16
10
  declare function resolveEditorOrigin(editorOrigin: string | string[] | undefined): string | string[];
17
11
  interface CmssyAuthConfig {
18
12
  modelSlug: string;
@@ -28,7 +22,7 @@ interface CmssyNextConfig {
28
22
  draftSecret: string;
29
23
  /**
30
24
  * Origin allowed to frame your app in the editor. Defaults to
31
- * {@link DEFAULT_CMSSY_EDITOR_ORIGIN}; set it only for self-hosted admins.
25
+ * {@link DEFAULT_CMSSY_EDITOR_ORIGINS}; set it only for self-hosted admins.
32
26
  */
33
27
  editorOrigin?: string | string[];
34
28
  /**
@@ -346,4 +340,4 @@ declare class CmssyWebhookError extends Error {
346
340
  */
347
341
  declare function verifyCmssyWebhook(options: VerifyCmssyWebhookOptions): CmssyWebhookEvent;
348
342
 
349
- export { type BuildCmssyMetadataOptions, CMSSY_CART_COOKIE, CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, CMSSY_SESSION_COOKIE, type CmssyAuthConfig, type CmssyAuthMiddleware, type CmssyAuthRouteHandlers, type CmssyCartRouteHandlers, type CmssyCspOptions, type CmssyDraftRouteConfig, type CmssyEditorProps, type CmssyNextConfig, type CmssyOrdersRouteHandlers, type CmssySessionPayload, type CmssySessionUser, CmssyWebhookError, type CmssyWebhookEvent, type CmssyWebhookOrder, type CreateCmssyNotFoundOptions, type CreateCmssyPageOptions, type CreateCmssyRobotsOptions, type CreateCmssySitemapOptions, DEFAULT_CMSSY_EDITOR_ORIGIN, type FetchProductOptions, type FetchProductsOptions, type MyOrdersResult, SESSION_MAX_AGE_SECONDS, type SessionCookieOptions, type VerifyCmssyWebhookOptions, applyCmssyCsp, assertAuthConfig, buildCmssyMetadata, cmssyCspHeaders, createCmssyAuthMiddleware, createCmssyAuthRoute, createCmssyCartRoute, createCmssyLocaleMiddleware, createCmssyNotFound, createCmssyOrdersRoute, createCmssyPage, createCmssyRobots, createCmssySitemap, createDraftRoute, fetchProduct, fetchProducts, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, resolveEditorOrigin, resolveLocaleFromPathname, sealSession, sessionCookieOptions, splitCmssyLocale, verifyCmssyWebhook };
343
+ export { type BuildCmssyMetadataOptions, CMSSY_CART_COOKIE, CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, CMSSY_SESSION_COOKIE, type CmssyAuthConfig, type CmssyAuthMiddleware, type CmssyAuthRouteHandlers, type CmssyCartRouteHandlers, type CmssyCspOptions, type CmssyDraftRouteConfig, type CmssyEditorProps, type CmssyNextConfig, type CmssyOrdersRouteHandlers, type CmssySessionPayload, type CmssySessionUser, CmssyWebhookError, type CmssyWebhookEvent, type CmssyWebhookOrder, type CreateCmssyNotFoundOptions, type CreateCmssyPageOptions, type CreateCmssyRobotsOptions, type CreateCmssySitemapOptions, DEFAULT_CMSSY_EDITOR_ORIGINS, type FetchProductOptions, type FetchProductsOptions, type MyOrdersResult, SESSION_MAX_AGE_SECONDS, type SessionCookieOptions, type VerifyCmssyWebhookOptions, applyCmssyCsp, assertAuthConfig, buildCmssyMetadata, cmssyCspHeaders, createCmssyAuthMiddleware, createCmssyAuthRoute, createCmssyCartRoute, createCmssyLocaleMiddleware, createCmssyNotFound, createCmssyOrdersRoute, createCmssyPage, createCmssyRobots, createCmssySitemap, createDraftRoute, fetchProduct, fetchProducts, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, resolveEditorOrigin, resolveLocaleFromPathname, sealSession, sessionCookieOptions, splitCmssyLocale, verifyCmssyWebhook };
package/dist/index.js CHANGED
@@ -70,14 +70,29 @@ function sessionCookieOptions() {
70
70
  }
71
71
 
72
72
  // src/config.ts
73
- var DEFAULT_CMSSY_EDITOR_ORIGIN = "https://www.cmssy.io";
73
+ var DEFAULT_CMSSY_EDITOR_ORIGINS = [
74
+ "https://cmssy.io",
75
+ "https://www.cmssy.io"
76
+ ];
77
+ function parseEditorOriginEnv(raw) {
78
+ if (!raw) return void 0;
79
+ const parts = raw.split(",").map((o) => o.trim()).filter((o) => o.length > 0);
80
+ if (parts.length === 0) return void 0;
81
+ return parts.length === 1 ? parts[0] : parts;
82
+ }
83
+ function isDevelopment() {
84
+ return typeof process !== "undefined" && process.env.NODE_ENV === "development";
85
+ }
74
86
  function resolveEditorOrigin(editorOrigin) {
75
- if (editorOrigin === void 0) return DEFAULT_CMSSY_EDITOR_ORIGIN;
76
- if (Array.isArray(editorOrigin)) {
77
- const cleaned = editorOrigin.filter((o) => o && o.trim().length > 0);
78
- return cleaned.length > 0 ? cleaned : DEFAULT_CMSSY_EDITOR_ORIGIN;
87
+ const value = editorOrigin ?? (typeof process !== "undefined" ? parseEditorOriginEnv(process.env.CMSSY_EDITOR_ORIGIN) : void 0);
88
+ if (value === void 0) {
89
+ return isDevelopment() ? "*" : DEFAULT_CMSSY_EDITOR_ORIGINS;
90
+ }
91
+ if (Array.isArray(value)) {
92
+ const cleaned = value.filter((o) => o && o.trim().length > 0);
93
+ return cleaned.length > 0 ? cleaned : DEFAULT_CMSSY_EDITOR_ORIGINS;
79
94
  }
80
- return editorOrigin.trim().length > 0 ? editorOrigin : DEFAULT_CMSSY_EDITOR_ORIGIN;
95
+ return value.trim().length > 0 ? value : DEFAULT_CMSSY_EDITOR_ORIGINS;
81
96
  }
82
97
  function assertAuthConfig(config) {
83
98
  const auth = config.auth;
@@ -285,9 +300,9 @@ function resolveBridgeOrigin(editorOrigin) {
285
300
  );
286
301
  }
287
302
  const origin = toCspOrigin(origins[0].trim());
288
- if (origin === "*") {
303
+ if (origin === "*" && !isDevelopment()) {
289
304
  throw new Error(
290
- "cmssy: editorOrigin '*' is not allowed for the live-edit bridge; set the concrete editor origin (e.g. https://www.cmssy.io)"
305
+ "cmssy: editorOrigin '*' is only allowed in development; set a concrete editor origin (e.g. https://cmssy.io) for production"
291
306
  );
292
307
  }
293
308
  return origin;
@@ -1617,4 +1632,4 @@ function verifyCmssyWebhook(options) {
1617
1632
  return parsed;
1618
1633
  }
1619
1634
 
1620
- export { CMSSY_CART_COOKIE, CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, CMSSY_SESSION_COOKIE, CmssyWebhookError, DEFAULT_CMSSY_EDITOR_ORIGIN, SESSION_MAX_AGE_SECONDS, applyCmssyCsp, assertAuthConfig, buildCmssyMetadata, cmssyCspHeaders, createCmssyAuthMiddleware, createCmssyAuthRoute, createCmssyCartRoute, createCmssyLocaleMiddleware, createCmssyNotFound, createCmssyOrdersRoute, createCmssyPage, createCmssyRobots, createCmssySitemap, createDraftRoute, fetchProduct, fetchProducts, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, resolveEditorOrigin, resolveLocaleFromPathname, sealSession, sessionCookieOptions, splitCmssyLocale, verifyCmssyWebhook };
1635
+ export { CMSSY_CART_COOKIE, CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, CMSSY_SESSION_COOKIE, CmssyWebhookError, DEFAULT_CMSSY_EDITOR_ORIGINS, SESSION_MAX_AGE_SECONDS, applyCmssyCsp, assertAuthConfig, buildCmssyMetadata, cmssyCspHeaders, createCmssyAuthMiddleware, createCmssyAuthRoute, createCmssyCartRoute, createCmssyLocaleMiddleware, createCmssyNotFound, createCmssyOrdersRoute, createCmssyPage, createCmssyRobots, createCmssySitemap, createDraftRoute, fetchProduct, fetchProducts, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, resolveEditorOrigin, resolveLocaleFromPathname, sealSession, sessionCookieOptions, splitCmssyLocale, verifyCmssyWebhook };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/next",
3
- "version": "0.5.6",
3
+ "version": "0.6.0",
4
4
  "description": "Next.js App Router bindings for cmssy headless sites (createCmssyPage + draft preview)",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -54,7 +54,7 @@
54
54
  "tsup": "^8.3.0",
55
55
  "typescript": "^5.6.0",
56
56
  "vitest": "^2.1.0",
57
- "@cmssy/react": "0.5.6"
57
+ "@cmssy/react": "0.6.0"
58
58
  },
59
59
  "dependencies": {
60
60
  "jose": "^6.2.3"