@cmssy/next 0.7.3 → 0.7.5

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/index.cjs CHANGED
@@ -95,6 +95,33 @@ function resolveEditorOrigin(editorOrigin) {
95
95
  }
96
96
  return value.trim().length > 0 ? value : DEFAULT_CMSSY_EDITOR_ORIGINS;
97
97
  }
98
+ var REQUIRED_CONFIG_ENV = [
99
+ ["workspaceSlug", "CMSSY_WORKSPACE_SLUG"],
100
+ ["draftSecret", "CMSSY_DRAFT_SECRET"]
101
+ ];
102
+ function defineCmssyConfig(config) {
103
+ const resolved = { ...config };
104
+ const missing = [];
105
+ for (const [key, env] of REQUIRED_CONFIG_ENV) {
106
+ const value = config[key];
107
+ const trimmed = typeof value === "string" ? value.trim() : "";
108
+ if (trimmed) {
109
+ resolved[key] = trimmed;
110
+ } else {
111
+ missing.push(`${env} (config.${key})`);
112
+ }
113
+ }
114
+ if (missing.length > 0) {
115
+ throw new Error(
116
+ `cmssy: missing required configuration:
117
+ - ${missing.join(
118
+ "\n - "
119
+ )}
120
+ Set the listed environment variables (e.g. in .env.local) and restart the dev server.`
121
+ );
122
+ }
123
+ return resolved;
124
+ }
98
125
  function assertAuthConfig(config) {
99
126
  const auth = config.auth;
100
127
  if (!auth || typeof auth.modelSlug !== "string" || !auth.modelSlug) {
@@ -203,7 +230,7 @@ function createCmssyPage(config, blocks, options) {
203
230
  const editMode = isEnabled || hasEditFlag(query[EDIT_QUERY_PARAM]);
204
231
  const devAllowed = isDevelopment() && Boolean(config.devToken?.trim());
205
232
  const devFlagged = hasEditFlag(query[DEV_QUERY_PARAM]);
206
- const devPreview = devAllowed && (devFlagged || config.preview === "dev");
233
+ const devPreview = devAllowed && devFlagged;
207
234
  const editorActive = editMode || devAllowed && devFlagged;
208
235
  let locale;
209
236
  let pagePath = path;
@@ -1671,6 +1698,7 @@ exports.createCmssyPage = createCmssyPage;
1671
1698
  exports.createCmssyRobots = createCmssyRobots;
1672
1699
  exports.createCmssySitemap = createCmssySitemap;
1673
1700
  exports.createDraftRoute = createDraftRoute;
1701
+ exports.defineCmssyConfig = defineCmssyConfig;
1674
1702
  exports.fetchProduct = fetchProduct;
1675
1703
  exports.fetchProducts = fetchProducts;
1676
1704
  exports.getCmssyAccessToken = getCmssyAccessToken;
package/dist/index.d.cts CHANGED
@@ -12,7 +12,6 @@ interface CmssyAuthConfig {
12
12
  modelSlug: string;
13
13
  sessionSecret: string;
14
14
  }
15
- type CmssyPreviewMode = "dev" | "live";
16
15
  interface CmssyNextConfig {
17
16
  /**
18
17
  * Full GraphQL delivery endpoint. Defaults to the cmssy cloud endpoint
@@ -22,13 +21,6 @@ interface CmssyNextConfig {
22
21
  workspaceSlug: string;
23
22
  draftSecret: string;
24
23
  devToken?: string;
25
- /**
26
- * Local content-source mode. `"dev"` (with NODE_ENV=development + a devToken)
27
- * serves the caller's dev-draft overlay on every request without the
28
- * `?cmssyDev` flag; `"live"` (or unset) serves published content. Ignored in
29
- * production. Pass the raw env value through - the SDK owns the semantics.
30
- */
31
- preview?: CmssyPreviewMode | (string & {});
32
24
  /**
33
25
  * Origin allowed to frame your app in the editor. Defaults to
34
26
  * {@link DEFAULT_CMSSY_EDITOR_ORIGINS}; set it only for self-hosted admins.
@@ -46,6 +38,24 @@ interface CmssyNextConfig {
46
38
  enabledLocales?: string[];
47
39
  resolveLocale?: () => string | Promise<string>;
48
40
  }
41
+ /**
42
+ * Env-shaped input for {@link defineCmssyConfig}: the required string fields are
43
+ * widened to `string | undefined` so a config can pass `process.env.*` straight
44
+ * through without a `?? ""` fallback (which would mask a missing value as an
45
+ * empty string) or a cast.
46
+ */
47
+ type CmssyEnvConfig = Omit<CmssyNextConfig, "workspaceSlug" | "draftSecret"> & {
48
+ workspaceSlug?: string;
49
+ draftSecret?: string;
50
+ };
51
+ /**
52
+ * Validates an env-sourced config and returns a strictly-typed
53
+ * {@link CmssyNextConfig}. Pass raw `process.env.*` values; this throws a clear,
54
+ * actionable error listing any missing required variables (rendered by the
55
+ * Next.js error overlay / boundary), so the app fails fast instead of running
56
+ * with silently-empty config.
57
+ */
58
+ declare function defineCmssyConfig(config: CmssyEnvConfig): CmssyNextConfig;
49
59
  declare function assertAuthConfig(config: CmssyNextConfig): CmssyAuthConfig;
50
60
 
51
61
  interface CmssyEditorProps {
@@ -349,4 +359,4 @@ declare class CmssyWebhookError extends Error {
349
359
  */
350
360
  declare function verifyCmssyWebhook(options: VerifyCmssyWebhookOptions): CmssyWebhookEvent;
351
361
 
352
- 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 };
362
+ 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 CmssyEnvConfig, 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, defineCmssyConfig, fetchProduct, fetchProducts, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, resolveEditorOrigin, resolveLocaleFromPathname, sealSession, sessionCookieOptions, splitCmssyLocale, verifyCmssyWebhook };
package/dist/index.d.ts CHANGED
@@ -12,7 +12,6 @@ interface CmssyAuthConfig {
12
12
  modelSlug: string;
13
13
  sessionSecret: string;
14
14
  }
15
- type CmssyPreviewMode = "dev" | "live";
16
15
  interface CmssyNextConfig {
17
16
  /**
18
17
  * Full GraphQL delivery endpoint. Defaults to the cmssy cloud endpoint
@@ -22,13 +21,6 @@ interface CmssyNextConfig {
22
21
  workspaceSlug: string;
23
22
  draftSecret: string;
24
23
  devToken?: string;
25
- /**
26
- * Local content-source mode. `"dev"` (with NODE_ENV=development + a devToken)
27
- * serves the caller's dev-draft overlay on every request without the
28
- * `?cmssyDev` flag; `"live"` (or unset) serves published content. Ignored in
29
- * production. Pass the raw env value through - the SDK owns the semantics.
30
- */
31
- preview?: CmssyPreviewMode | (string & {});
32
24
  /**
33
25
  * Origin allowed to frame your app in the editor. Defaults to
34
26
  * {@link DEFAULT_CMSSY_EDITOR_ORIGINS}; set it only for self-hosted admins.
@@ -46,6 +38,24 @@ interface CmssyNextConfig {
46
38
  enabledLocales?: string[];
47
39
  resolveLocale?: () => string | Promise<string>;
48
40
  }
41
+ /**
42
+ * Env-shaped input for {@link defineCmssyConfig}: the required string fields are
43
+ * widened to `string | undefined` so a config can pass `process.env.*` straight
44
+ * through without a `?? ""` fallback (which would mask a missing value as an
45
+ * empty string) or a cast.
46
+ */
47
+ type CmssyEnvConfig = Omit<CmssyNextConfig, "workspaceSlug" | "draftSecret"> & {
48
+ workspaceSlug?: string;
49
+ draftSecret?: string;
50
+ };
51
+ /**
52
+ * Validates an env-sourced config and returns a strictly-typed
53
+ * {@link CmssyNextConfig}. Pass raw `process.env.*` values; this throws a clear,
54
+ * actionable error listing any missing required variables (rendered by the
55
+ * Next.js error overlay / boundary), so the app fails fast instead of running
56
+ * with silently-empty config.
57
+ */
58
+ declare function defineCmssyConfig(config: CmssyEnvConfig): CmssyNextConfig;
49
59
  declare function assertAuthConfig(config: CmssyNextConfig): CmssyAuthConfig;
50
60
 
51
61
  interface CmssyEditorProps {
@@ -349,4 +359,4 @@ declare class CmssyWebhookError extends Error {
349
359
  */
350
360
  declare function verifyCmssyWebhook(options: VerifyCmssyWebhookOptions): CmssyWebhookEvent;
351
361
 
352
- 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 };
362
+ 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 CmssyEnvConfig, 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, defineCmssyConfig, fetchProduct, fetchProducts, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, resolveEditorOrigin, resolveLocaleFromPathname, sealSession, sessionCookieOptions, splitCmssyLocale, verifyCmssyWebhook };
package/dist/index.js CHANGED
@@ -94,6 +94,33 @@ function resolveEditorOrigin(editorOrigin) {
94
94
  }
95
95
  return value.trim().length > 0 ? value : DEFAULT_CMSSY_EDITOR_ORIGINS;
96
96
  }
97
+ var REQUIRED_CONFIG_ENV = [
98
+ ["workspaceSlug", "CMSSY_WORKSPACE_SLUG"],
99
+ ["draftSecret", "CMSSY_DRAFT_SECRET"]
100
+ ];
101
+ function defineCmssyConfig(config) {
102
+ const resolved = { ...config };
103
+ const missing = [];
104
+ for (const [key, env] of REQUIRED_CONFIG_ENV) {
105
+ const value = config[key];
106
+ const trimmed = typeof value === "string" ? value.trim() : "";
107
+ if (trimmed) {
108
+ resolved[key] = trimmed;
109
+ } else {
110
+ missing.push(`${env} (config.${key})`);
111
+ }
112
+ }
113
+ if (missing.length > 0) {
114
+ throw new Error(
115
+ `cmssy: missing required configuration:
116
+ - ${missing.join(
117
+ "\n - "
118
+ )}
119
+ Set the listed environment variables (e.g. in .env.local) and restart the dev server.`
120
+ );
121
+ }
122
+ return resolved;
123
+ }
97
124
  function assertAuthConfig(config) {
98
125
  const auth = config.auth;
99
126
  if (!auth || typeof auth.modelSlug !== "string" || !auth.modelSlug) {
@@ -202,7 +229,7 @@ function createCmssyPage(config, blocks, options) {
202
229
  const editMode = isEnabled || hasEditFlag(query[EDIT_QUERY_PARAM]);
203
230
  const devAllowed = isDevelopment() && Boolean(config.devToken?.trim());
204
231
  const devFlagged = hasEditFlag(query[DEV_QUERY_PARAM]);
205
- const devPreview = devAllowed && (devFlagged || config.preview === "dev");
232
+ const devPreview = devAllowed && devFlagged;
206
233
  const editorActive = editMode || devAllowed && devFlagged;
207
234
  let locale;
208
235
  let pagePath = path;
@@ -1641,4 +1668,4 @@ function verifyCmssyWebhook(options) {
1641
1668
  return parsed;
1642
1669
  }
1643
1670
 
1644
- 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 };
1671
+ 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, defineCmssyConfig, 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.7.3",
3
+ "version": "0.7.5",
4
4
  "description": "Next.js App Router bindings for cmssy headless sites (createCmssyPage + draft preview)",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -41,7 +41,7 @@
41
41
  "dist"
42
42
  ],
43
43
  "peerDependencies": {
44
- "@cmssy/react": "^0.7.3",
44
+ "@cmssy/react": "^0.7.5",
45
45
  "next": ">=15",
46
46
  "react": "^18.2.0 || ^19.0.0",
47
47
  "react-dom": "^18.2.0 || ^19.0.0"
@@ -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.7.3"
57
+ "@cmssy/react": "0.7.5"
58
58
  },
59
59
  "dependencies": {
60
60
  "jose": "^6.2.3"