@cmssy/next 0.7.2 → 0.7.4
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 +29 -1
- package/dist/index.d.cts +25 -5
- package/dist/index.d.ts +25 -5
- package/dist/index.js +29 -2
- package/package.json +3 -3
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 ||
|
|
233
|
+
const devPreview = devAllowed && (devFlagged || config.preview === "dev");
|
|
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,6 +12,7 @@ interface CmssyAuthConfig {
|
|
|
12
12
|
modelSlug: string;
|
|
13
13
|
sessionSecret: string;
|
|
14
14
|
}
|
|
15
|
+
type CmssyPreviewMode = "dev" | "live";
|
|
15
16
|
interface CmssyNextConfig {
|
|
16
17
|
/**
|
|
17
18
|
* Full GraphQL delivery endpoint. Defaults to the cmssy cloud endpoint
|
|
@@ -22,11 +23,12 @@ interface CmssyNextConfig {
|
|
|
22
23
|
draftSecret: string;
|
|
23
24
|
devToken?: string;
|
|
24
25
|
/**
|
|
25
|
-
*
|
|
26
|
-
* caller's dev-draft overlay on every request without the
|
|
27
|
-
*
|
|
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.
|
|
28
30
|
*/
|
|
29
|
-
|
|
31
|
+
preview?: CmssyPreviewMode | (string & {});
|
|
30
32
|
/**
|
|
31
33
|
* Origin allowed to frame your app in the editor. Defaults to
|
|
32
34
|
* {@link DEFAULT_CMSSY_EDITOR_ORIGINS}; set it only for self-hosted admins.
|
|
@@ -44,6 +46,24 @@ interface CmssyNextConfig {
|
|
|
44
46
|
enabledLocales?: string[];
|
|
45
47
|
resolveLocale?: () => string | Promise<string>;
|
|
46
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Env-shaped input for {@link defineCmssyConfig}: the required string fields are
|
|
51
|
+
* widened to `string | undefined` so a config can pass `process.env.*` straight
|
|
52
|
+
* through without a `?? ""` fallback (which would mask a missing value as an
|
|
53
|
+
* empty string) or a cast.
|
|
54
|
+
*/
|
|
55
|
+
type CmssyEnvConfig = Omit<CmssyNextConfig, "workspaceSlug" | "draftSecret"> & {
|
|
56
|
+
workspaceSlug?: string;
|
|
57
|
+
draftSecret?: string;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Validates an env-sourced config and returns a strictly-typed
|
|
61
|
+
* {@link CmssyNextConfig}. Pass raw `process.env.*` values; this throws a clear,
|
|
62
|
+
* actionable error listing any missing required variables (rendered by the
|
|
63
|
+
* Next.js error overlay / boundary), so the app fails fast instead of running
|
|
64
|
+
* with silently-empty config.
|
|
65
|
+
*/
|
|
66
|
+
declare function defineCmssyConfig(config: CmssyEnvConfig): CmssyNextConfig;
|
|
47
67
|
declare function assertAuthConfig(config: CmssyNextConfig): CmssyAuthConfig;
|
|
48
68
|
|
|
49
69
|
interface CmssyEditorProps {
|
|
@@ -347,4 +367,4 @@ declare class CmssyWebhookError extends Error {
|
|
|
347
367
|
*/
|
|
348
368
|
declare function verifyCmssyWebhook(options: VerifyCmssyWebhookOptions): CmssyWebhookEvent;
|
|
349
369
|
|
|
350
|
-
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 };
|
|
370
|
+
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,6 +12,7 @@ interface CmssyAuthConfig {
|
|
|
12
12
|
modelSlug: string;
|
|
13
13
|
sessionSecret: string;
|
|
14
14
|
}
|
|
15
|
+
type CmssyPreviewMode = "dev" | "live";
|
|
15
16
|
interface CmssyNextConfig {
|
|
16
17
|
/**
|
|
17
18
|
* Full GraphQL delivery endpoint. Defaults to the cmssy cloud endpoint
|
|
@@ -22,11 +23,12 @@ interface CmssyNextConfig {
|
|
|
22
23
|
draftSecret: string;
|
|
23
24
|
devToken?: string;
|
|
24
25
|
/**
|
|
25
|
-
*
|
|
26
|
-
* caller's dev-draft overlay on every request without the
|
|
27
|
-
*
|
|
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.
|
|
28
30
|
*/
|
|
29
|
-
|
|
31
|
+
preview?: CmssyPreviewMode | (string & {});
|
|
30
32
|
/**
|
|
31
33
|
* Origin allowed to frame your app in the editor. Defaults to
|
|
32
34
|
* {@link DEFAULT_CMSSY_EDITOR_ORIGINS}; set it only for self-hosted admins.
|
|
@@ -44,6 +46,24 @@ interface CmssyNextConfig {
|
|
|
44
46
|
enabledLocales?: string[];
|
|
45
47
|
resolveLocale?: () => string | Promise<string>;
|
|
46
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Env-shaped input for {@link defineCmssyConfig}: the required string fields are
|
|
51
|
+
* widened to `string | undefined` so a config can pass `process.env.*` straight
|
|
52
|
+
* through without a `?? ""` fallback (which would mask a missing value as an
|
|
53
|
+
* empty string) or a cast.
|
|
54
|
+
*/
|
|
55
|
+
type CmssyEnvConfig = Omit<CmssyNextConfig, "workspaceSlug" | "draftSecret"> & {
|
|
56
|
+
workspaceSlug?: string;
|
|
57
|
+
draftSecret?: string;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Validates an env-sourced config and returns a strictly-typed
|
|
61
|
+
* {@link CmssyNextConfig}. Pass raw `process.env.*` values; this throws a clear,
|
|
62
|
+
* actionable error listing any missing required variables (rendered by the
|
|
63
|
+
* Next.js error overlay / boundary), so the app fails fast instead of running
|
|
64
|
+
* with silently-empty config.
|
|
65
|
+
*/
|
|
66
|
+
declare function defineCmssyConfig(config: CmssyEnvConfig): CmssyNextConfig;
|
|
47
67
|
declare function assertAuthConfig(config: CmssyNextConfig): CmssyAuthConfig;
|
|
48
68
|
|
|
49
69
|
interface CmssyEditorProps {
|
|
@@ -347,4 +367,4 @@ declare class CmssyWebhookError extends Error {
|
|
|
347
367
|
*/
|
|
348
368
|
declare function verifyCmssyWebhook(options: VerifyCmssyWebhookOptions): CmssyWebhookEvent;
|
|
349
369
|
|
|
350
|
-
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 };
|
|
370
|
+
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 ||
|
|
232
|
+
const devPreview = devAllowed && (devFlagged || config.preview === "dev");
|
|
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
|
+
"version": "0.7.4",
|
|
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.
|
|
44
|
+
"@cmssy/react": "^0.7.4",
|
|
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.
|
|
57
|
+
"@cmssy/react": "0.7.4"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"jose": "^6.2.3"
|