@thecms/next 0.0.0-stage → 0.20.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/chunk-NLO5OID2.js +175 -0
- package/dist/client.d.ts +133 -0
- package/dist/client.js +178 -0
- package/dist/kit.d.ts +87 -0
- package/dist/kit.js +150 -0
- package/dist/server.d.ts +313 -0
- package/dist/server.js +1177 -0
- package/package.json +52 -4
- package/README.md +0 -3
package/dist/kit.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cmsContext
|
|
3
|
+
} from "./chunk-NLO5OID2.js";
|
|
4
|
+
|
|
5
|
+
// src/kit/block.ts
|
|
6
|
+
function* everyBlock(blocks) {
|
|
7
|
+
for (const block2 of blocks) {
|
|
8
|
+
yield block2;
|
|
9
|
+
for (const slot of Object.values(block2.slots ?? {})) yield* everyBlock(slot);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function blk(block2, own) {
|
|
13
|
+
return ["blk", cmsContext().isFirst(block2) ? "first" : "", own ?? ""].filter(Boolean).join(" ");
|
|
14
|
+
}
|
|
15
|
+
function orderOf(block2) {
|
|
16
|
+
const same = [...everyBlock(cmsContext().page.body)].filter((b) => b.in === "view" && b.set === block2.set && b.shape === block2.shape);
|
|
17
|
+
return same.findIndex((b) => b.uid === block2.uid);
|
|
18
|
+
}
|
|
19
|
+
function loadingOf(block2, index = 0) {
|
|
20
|
+
return cmsContext().isFirst(block2) && index === 0 ? void 0 : "lazy";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/kit/media.ts
|
|
24
|
+
import { platformUrl } from "@thecms/sdk";
|
|
25
|
+
function absoluteSrcSet(srcset) {
|
|
26
|
+
return srcset.split(/,\s+/).map((candidate) => {
|
|
27
|
+
const [url, width] = candidate.trim().split(/\s+/);
|
|
28
|
+
return width ? `${platformUrl(url)} ${width}` : platformUrl(url);
|
|
29
|
+
}).join(", ");
|
|
30
|
+
}
|
|
31
|
+
function altOf(alt, locale, defaultLocale) {
|
|
32
|
+
if (typeof alt === "string") return alt;
|
|
33
|
+
if (!alt || typeof alt !== "object") return "";
|
|
34
|
+
const texts = alt;
|
|
35
|
+
const text = texts[locale] ?? texts[defaultLocale];
|
|
36
|
+
return typeof text === "string" ? text : "";
|
|
37
|
+
}
|
|
38
|
+
function image(asset) {
|
|
39
|
+
if (!asset || typeof asset !== "object" || typeof asset.url !== "string") return void 0;
|
|
40
|
+
const a = asset;
|
|
41
|
+
const { locale, site } = cmsContext();
|
|
42
|
+
return {
|
|
43
|
+
src: platformUrl(a.url),
|
|
44
|
+
...a.srcset ? { srcSet: absoluteSrcSet(a.srcset) } : {},
|
|
45
|
+
alt: altOf(a.alt, locale, site.defaultLocale),
|
|
46
|
+
...a.width ? { width: a.width } : {},
|
|
47
|
+
...a.height ? { height: a.height } : {}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/kit/links.ts
|
|
52
|
+
function hrefOf(link) {
|
|
53
|
+
if (!link || typeof link !== "object") return void 0;
|
|
54
|
+
const l = link;
|
|
55
|
+
const to = l.kind === "page" ? l.path : l.kind === "url" ? l.href : void 0;
|
|
56
|
+
return typeof to === "string" ? to : void 0;
|
|
57
|
+
}
|
|
58
|
+
function urlOf(record, view) {
|
|
59
|
+
const urls = record._urls;
|
|
60
|
+
if (!urls || typeof urls !== "object") return void 0;
|
|
61
|
+
const paths = urls;
|
|
62
|
+
const path = view !== void 0 ? paths[view] : Object.values(paths)[0];
|
|
63
|
+
return typeof path === "string" ? path : void 0;
|
|
64
|
+
}
|
|
65
|
+
function homeOf(locale) {
|
|
66
|
+
return locale === cmsContext().site.defaultLocale ? "/" : `/${locale}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/kit/markdown.ts
|
|
70
|
+
var ESCAPES = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
71
|
+
var escape = (text) => text.replace(/[&<>"']/g, (c) => ESCAPES[c]);
|
|
72
|
+
var LINK = /\[([^\]\n]+)\]\((https?:\/\/[^)\s]+|mailto:[^)\s]+|\/(?!\/)[^)\s]*)\)/g;
|
|
73
|
+
function emphasis(escaped) {
|
|
74
|
+
return escaped.replace(/\*\*(\S(?:.*?\S)?)\*\*/g, "<strong>$1</strong>").replace(/\*(\S(?:[^*]*?\S)?)\*/g, "<em>$1</em>").replace(/\n/g, "<br>");
|
|
75
|
+
}
|
|
76
|
+
function inline(text) {
|
|
77
|
+
let out = "";
|
|
78
|
+
let at = 0;
|
|
79
|
+
for (const m of text.matchAll(LINK)) {
|
|
80
|
+
out += emphasis(escape(text.slice(at, m.index)));
|
|
81
|
+
out += `<a href="${escape(m[2])}">${emphasis(escape(m[1]))}</a>`;
|
|
82
|
+
at = m.index + m[0].length;
|
|
83
|
+
}
|
|
84
|
+
return out + emphasis(escape(text.slice(at)));
|
|
85
|
+
}
|
|
86
|
+
var blocksOf = (text) => text.trim().split(/\n\s*\n/).map((b) => b.trim()).filter(Boolean);
|
|
87
|
+
function block(text) {
|
|
88
|
+
const [first, ...rest] = text.split("\n");
|
|
89
|
+
const heading = /^(#{2,3})\s+(.+)$/.exec(first);
|
|
90
|
+
if (heading) {
|
|
91
|
+
const level = heading[1].length;
|
|
92
|
+
return `<h${level}>${inline(heading[2].trim())}</h${level}>` + (rest.length ? block(rest.join("\n")) : "");
|
|
93
|
+
}
|
|
94
|
+
const lines = text.split("\n");
|
|
95
|
+
if (lines.every((l) => /^\s*-\s+/.test(l))) {
|
|
96
|
+
return `<ul>${lines.map((l) => `<li>${inline(l.replace(/^\s*-\s+/, ""))}</li>`).join("")}</ul>`;
|
|
97
|
+
}
|
|
98
|
+
return `<p>${inline(text)}</p>`;
|
|
99
|
+
}
|
|
100
|
+
function markdown(text) {
|
|
101
|
+
return text ? blocksOf(text).map(block).join("") : "";
|
|
102
|
+
}
|
|
103
|
+
function paragraphs(text) {
|
|
104
|
+
return text ? blocksOf(text).map(block) : [];
|
|
105
|
+
}
|
|
106
|
+
function firstParagraph(text) {
|
|
107
|
+
return text ? blocksOf(text)[0] ?? "" : "";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/kit/dates.ts
|
|
111
|
+
function dateParts(iso, format, timeZone) {
|
|
112
|
+
const date = new Date(iso);
|
|
113
|
+
const as = (options) => new Intl.DateTimeFormat(format, { timeZone, ...options }).format(date);
|
|
114
|
+
return {
|
|
115
|
+
day: as({ day: "2-digit" }),
|
|
116
|
+
mon: as({ month: "short" }),
|
|
117
|
+
month: as({ month: "long" }),
|
|
118
|
+
monthYear: as({ month: "long", year: "numeric" }),
|
|
119
|
+
year: as({ year: "numeric" }),
|
|
120
|
+
full: as({ day: "numeric", month: "long", year: "numeric" }),
|
|
121
|
+
iso: date.toISOString()
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/kit/filters.ts
|
|
126
|
+
var messageOr = (t, key, fallback) => {
|
|
127
|
+
const text = t(key);
|
|
128
|
+
return text !== key ? text : fallback;
|
|
129
|
+
};
|
|
130
|
+
function filterLabel(t, filter) {
|
|
131
|
+
return messageOr(t, `filters.${filter.field}.label`, filter.label);
|
|
132
|
+
}
|
|
133
|
+
function optionLabel(t, field, option) {
|
|
134
|
+
return messageOr(t, `filters.${field}.${option.value}`, option.label ?? option.value);
|
|
135
|
+
}
|
|
136
|
+
export {
|
|
137
|
+
blk,
|
|
138
|
+
dateParts,
|
|
139
|
+
filterLabel,
|
|
140
|
+
firstParagraph,
|
|
141
|
+
homeOf,
|
|
142
|
+
hrefOf,
|
|
143
|
+
image,
|
|
144
|
+
loadingOf,
|
|
145
|
+
markdown,
|
|
146
|
+
optionLabel,
|
|
147
|
+
orderOf,
|
|
148
|
+
paragraphs,
|
|
149
|
+
urlOf
|
|
150
|
+
};
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import * as _thecms_sdk from '@thecms/sdk';
|
|
2
|
+
import { ResolvedBodyItem, ResolvedPage, SiteAnswer, Sdk, platformUrl, CheckoutStarted, ReaderPurchase, ReaderOrder } from '@thecms/sdk';
|
|
3
|
+
export { PREVIEW_COOKIE } from '@thecms/sdk';
|
|
4
|
+
import { Metadata, MetadataRoute } from 'next';
|
|
5
|
+
import { ComponentType, ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
/** What the browser needs to talk to the CMS (D186, SITE-KEY D255): carried by every page, never a secret. */
|
|
8
|
+
interface CmsClientConfig {
|
|
9
|
+
/** the application's public key: the browser's SDK finds the site from it */
|
|
10
|
+
publicKey: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* KIT (D383): the messages of the pages the CMS does not give (not found, an
|
|
14
|
+
* error, a page blocked in the visitor's country), by fixed key —
|
|
15
|
+
* `notFound.title`, `notFound.body`, `notFound.home`, `error.title`,
|
|
16
|
+
* `error.body`, `error.retry`, `geoBlocked.title`, `geoBlocked.body`.
|
|
17
|
+
*/
|
|
18
|
+
declare const SITE_TEXT_KEYS: {
|
|
19
|
+
readonly notFound: readonly ["title", "body", "home"];
|
|
20
|
+
readonly error: readonly ["title", "body", "retry"];
|
|
21
|
+
readonly geoBlocked: readonly ["title", "body"];
|
|
22
|
+
};
|
|
23
|
+
type Group<G extends keyof typeof SITE_TEXT_KEYS> = Record<(typeof SITE_TEXT_KEYS)[G][number], string>;
|
|
24
|
+
/** What `CmsSiteTexts` hands to the client components (`useSiteTexts()`): plain data. */
|
|
25
|
+
interface SiteTexts {
|
|
26
|
+
/** the language of the address */
|
|
27
|
+
locale: string;
|
|
28
|
+
/** the Site name, null when not set */
|
|
29
|
+
name: string | null;
|
|
30
|
+
/** the home of the address's language first, then the other languages' */
|
|
31
|
+
homes: {
|
|
32
|
+
locale: string;
|
|
33
|
+
path: string;
|
|
34
|
+
}[];
|
|
35
|
+
notFound: Group<"notFound">;
|
|
36
|
+
error: Group<"error">;
|
|
37
|
+
geoBlocked: Group<"geoBlocked">;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** What a component of the site receives: the block, nothing else. */
|
|
41
|
+
interface CmsBlockProps {
|
|
42
|
+
block: ResolvedBodyItem;
|
|
43
|
+
}
|
|
44
|
+
/** A component of the site that draws a block. */
|
|
45
|
+
type CmsBlockComponent = ComponentType<CmsBlockProps>;
|
|
46
|
+
/** set → shape → component, or set → component (every shape of that set). */
|
|
47
|
+
type CmsComponents = Record<string, CmsBlockComponent | Record<string, CmsBlockComponent>>;
|
|
48
|
+
/** What `cmsContext()` gives: the page being drawn, its language, the site's texts and globals. */
|
|
49
|
+
interface CmsContext {
|
|
50
|
+
/** the page `cms.page()` gave */
|
|
51
|
+
page: ResolvedPage;
|
|
52
|
+
/** the page's language */
|
|
53
|
+
locale: string;
|
|
54
|
+
/** the page's address on the site, in its language (`/it/attivita`) */
|
|
55
|
+
path: string;
|
|
56
|
+
/** the page in the other languages it is translated in (hreflang), without `x-default` */
|
|
57
|
+
alternates: {
|
|
58
|
+
locale: string;
|
|
59
|
+
path: string;
|
|
60
|
+
}[];
|
|
61
|
+
/** the site's answer (`cms.site()`): url, languages, globals, messages */
|
|
62
|
+
site: SiteAnswer;
|
|
63
|
+
/** a message in the page's language, else the default language's, else the key; nested keys with dots (`contact.call`) */
|
|
64
|
+
t(key: string): string;
|
|
65
|
+
/** a global; a translated one (`{ it, en }`) in the page's language, else the default language's */
|
|
66
|
+
g(key: string): unknown;
|
|
67
|
+
/** the page's first own block (`in: "view"`, not the layout's; inside a layout's slot too): it carries the page's H1 */
|
|
68
|
+
isFirst(block: ResolvedBodyItem): boolean;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* SITE-EDITOR E6 (D310) — the context of the page being drawn: anywhere after
|
|
72
|
+
* `cms.page()` in the same request (the root `CmsBlocks`, the components and
|
|
73
|
+
* their slots, their helpers). Server components only: a client component
|
|
74
|
+
* receives data, not the context.
|
|
75
|
+
*/
|
|
76
|
+
declare function cmsContext(): CmsContext;
|
|
77
|
+
/** What `CmsBlocks` takes: a page (the root) or a cascade of blocks (a slot). */
|
|
78
|
+
type CmsBlocksProps = {
|
|
79
|
+
page: ResolvedPage;
|
|
80
|
+
main?: boolean;
|
|
81
|
+
/** the anonymous visitor's id for the view (VISITS D160), only with their consent */
|
|
82
|
+
visitor?: string | null;
|
|
83
|
+
blocks?: never;
|
|
84
|
+
} | {
|
|
85
|
+
blocks: ResolvedBodyItem[] | null | undefined;
|
|
86
|
+
page?: never;
|
|
87
|
+
main?: never;
|
|
88
|
+
visitor?: never;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* SITE-EDITOR (D281, D283; E6 D309) — draws blocks with the components given
|
|
92
|
+
* to `createNextCms({ components })`. The ROOT is the page: `<CmsBlocks
|
|
93
|
+
* page={page} main />` draws `page.body`; with `main` the page's own blocks
|
|
94
|
+
* (`in: "view"`) go in `<main id="main">`, the layout's before and after stay
|
|
95
|
+
* outside (no `<main>` without blocks of the page). A container draws its
|
|
96
|
+
* slot with `<CmsBlocks blocks={block.slots?.main ?? []} />`: never a root,
|
|
97
|
+
* the context stays the page's. Every component receives `{ block }`;
|
|
98
|
+
* `block.uid` is its key; `cmsContext()` gives the rest. A block without a
|
|
99
|
+
* component, or one that could not be resolved, draws nothing on the site.
|
|
100
|
+
* The root also follows the page (D311): on the site redrawn when the CMS
|
|
101
|
+
* changes it and its view recorded (`visitor` only with consent); in the
|
|
102
|
+
* editor the conversation with the editor. The site mounts neither. SEO-AI
|
|
103
|
+
* (D500): it never writes a JSON-LD — that is the site's (`lib/jsonld.ts`,
|
|
104
|
+
* printed with `jsonLdText`).
|
|
105
|
+
*/
|
|
106
|
+
declare function CmsBlocks(props: CmsBlocksProps): ReactNode;
|
|
107
|
+
|
|
108
|
+
/** What `cms.siteText(path)` gives: the address's language and the site's texts in it. */
|
|
109
|
+
interface SiteText {
|
|
110
|
+
/** the address's first segment when it is a language of the site, else the default language */
|
|
111
|
+
locale: string;
|
|
112
|
+
/** a message in that language, else the default language's, else the key */
|
|
113
|
+
t: CmsContext["t"];
|
|
114
|
+
/** a global; a translated one in that language, else the default language's */
|
|
115
|
+
g: CmsContext["g"];
|
|
116
|
+
/** the Site name, null when not set */
|
|
117
|
+
name: string | null;
|
|
118
|
+
/** the home of the address's language first (`/` for the default one, `/<language>` for the others), then the other languages' */
|
|
119
|
+
homes: {
|
|
120
|
+
locale: string;
|
|
121
|
+
path: string;
|
|
122
|
+
}[];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* KIT (D383) — in the layout: `<CmsSiteTexts path={path}>{children}</CmsSiteTexts>`
|
|
126
|
+
* hands the texts of the pages the CMS does not give (not found, error, a page
|
|
127
|
+
* blocked in the visitor's country), in the address's language, to the client
|
|
128
|
+
* components below — `useSiteTexts()` in `error.tsx` and `not-found.tsx`.
|
|
129
|
+
* Messages `notFound.*`, `error.*`, `geoBlocked.*` (the key when one is missing).
|
|
130
|
+
*/
|
|
131
|
+
declare function CmsSiteTexts({ path, children }: {
|
|
132
|
+
path: string;
|
|
133
|
+
children?: ReactNode;
|
|
134
|
+
}): Promise<ReactNode>;
|
|
135
|
+
|
|
136
|
+
interface NextCmsOptions {
|
|
137
|
+
/** the public key of the application this site shows (dashboard → the application's settings); not a secret. One site: no host is looked at. */
|
|
138
|
+
publicKey?: string;
|
|
139
|
+
/**
|
|
140
|
+
* MULTISITE (D637, D638): several applications of the same workspace in one project — `{ "<host>": "<publicKey>" }`,
|
|
141
|
+
* the host as the `Host` header brings it (hostname[:port], exact, lowercase; in development the local ones too:
|
|
142
|
+
* `business.localhost:3000`). Each request's host chooses among them and nothing else: a host that is not
|
|
143
|
+
* declared answers 404; every address (canonical, sitemap, robots, hreflang) still comes from the application's
|
|
144
|
+
* Site URL, never from the host. Instead of `publicKey`, never with it.
|
|
145
|
+
*/
|
|
146
|
+
sites?: Record<string, string>;
|
|
147
|
+
/** the workspace's API key, server-side only: the visitor's country through the site, records / media / products */
|
|
148
|
+
secretKey?: string;
|
|
149
|
+
/**
|
|
150
|
+
* SITE-EDITOR (D281): the site's components for the CMS's blocks, nested
|
|
151
|
+
* like the CMS — `{ section: { hero: Hero, text: Text }, footer: Footer }`
|
|
152
|
+
* (set → shape → component; a component alone draws every shape of its
|
|
153
|
+
* set). `<CmsBlocks blocks={…} />` draws with them, anywhere in the site.
|
|
154
|
+
*/
|
|
155
|
+
components?: CmsComponents;
|
|
156
|
+
/** a custom fetch (tests) */
|
|
157
|
+
fetch?: (input: string, init?: RequestInit) => Promise<Response>;
|
|
158
|
+
}
|
|
159
|
+
/** A page of the site, ready to draw: the CMS's page + what the client hooks need. */
|
|
160
|
+
type CmsPage = ResolvedPage & {
|
|
161
|
+
kind: "page";
|
|
162
|
+
_cms: CmsClientConfig;
|
|
163
|
+
};
|
|
164
|
+
/** The page's record is not available in the visitor's country: the site answers with its own message. */
|
|
165
|
+
interface CmsGeoBlocked {
|
|
166
|
+
kind: "geoBlocked";
|
|
167
|
+
country?: string;
|
|
168
|
+
continent?: string;
|
|
169
|
+
}
|
|
170
|
+
/** The props Next gives a page or `generateMetadata` of a catch-all route (`[[...path]]`, any name). */
|
|
171
|
+
interface CmsPageProps {
|
|
172
|
+
params: Promise<Record<string, string | string[] | undefined>>;
|
|
173
|
+
searchParams?: Promise<Record<string, string | string[] | undefined>>;
|
|
174
|
+
}
|
|
175
|
+
/** SITE-CONNECTION (D266): this package's version, as the site's server announces it (kept equal to package.json by a test). */
|
|
176
|
+
declare const NEXT_VERSION = "0.20.0";
|
|
177
|
+
/** The reader's session (D192) and the preview token (D190, P7: valid for the preview route only): httpOnly cookies of the site. */
|
|
178
|
+
declare const READER_COOKIE = "cms_reader";
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* LLMS-PROXY (24/11/2026): where the site's own page is asked — first at the application's Site URL (the address its
|
|
182
|
+
* visitors use: behind a reverse proxy that ends TLS, the public https one), then as this request reached the server,
|
|
183
|
+
* with the proxy's forwarded scheme (`X-Forwarded-Proto`: the same host, never another one), then `req.url` as it is.
|
|
184
|
+
* Never a host taken from a request header to BUILD an address: a forged `X-Forwarded-Host` would make the site read,
|
|
185
|
+
* and keep as its own text, another site's page. (MULTISITE D638: the `Host` header only CHOOSES among the declared
|
|
186
|
+
* sites — an undeclared host never gets here — and the pages' addresses are the Site URL's.)
|
|
187
|
+
*/
|
|
188
|
+
declare function sitePageOrigins(req: Request, siteUrl?: string | null): string[];
|
|
189
|
+
/** The page's language as Open Graph writes it; none without a match (the tag stays out). */
|
|
190
|
+
declare function ogLocale(locale: string): string | undefined;
|
|
191
|
+
declare function createNextCms(options: NextCmsOptions): {
|
|
192
|
+
/**
|
|
193
|
+
* The SDK of the request's site, for everything else (lists, records with the secret key…) — MULTISITE (D638):
|
|
194
|
+
* the one the request's host chose (an undeclared host is "not found").
|
|
195
|
+
*/
|
|
196
|
+
sdkOf: () => Promise<Sdk>;
|
|
197
|
+
/**
|
|
198
|
+
* SITE-KEY (D253): what holds for the whole site — its address, its preview
|
|
199
|
+
* route, its sitemap, the languages, the globals and the messages. Once per
|
|
200
|
+
* request: the layout, the page and the metadata share it. MULTISITE (D638):
|
|
201
|
+
* the request's site — `app` is the application's slug, the layout puts it
|
|
202
|
+
* on `<html data-site={…}>` (D641).
|
|
203
|
+
*/
|
|
204
|
+
site: () => Promise<SiteAnswer>;
|
|
205
|
+
/**
|
|
206
|
+
* KIT (D382): the site's texts for an address where there is no page of
|
|
207
|
+
* the CMS (the layout, not found, an error, a page blocked in the
|
|
208
|
+
* visitor's country): the address's language (its first segment when it is
|
|
209
|
+
* a language of the site, else the default one), `t` / `g` in it as in
|
|
210
|
+
* `cmsContext()`, the Site name, the homes of the languages (the address's
|
|
211
|
+
* first). From `site()`: no request more.
|
|
212
|
+
*/
|
|
213
|
+
siteText(path: string): Promise<SiteText>;
|
|
214
|
+
/**
|
|
215
|
+
* The page at the route's path. Redirects and "not found" are answered
|
|
216
|
+
* with Next's own functions (they never return); a page blocked in the
|
|
217
|
+
* visitor's country comes back as `{ kind: "geoBlocked" }`. The editor's
|
|
218
|
+
* link into a page (`?preview=`) passes through the site's CMS route, which
|
|
219
|
+
* keeps the token in the preview's cookie (D254, D289); in a tab the token
|
|
220
|
+
* is ignored (D290). E6 (D306): `?f=<token>` (a list link's `token`, the
|
|
221
|
+
* site puts it in its own address) — the page comes with that list's
|
|
222
|
+
* block at that state, in the same answer.
|
|
223
|
+
*/
|
|
224
|
+
page(props: CmsPageProps): Promise<CmsPage | CmsGeoBlocked>;
|
|
225
|
+
/**
|
|
226
|
+
* `export const generateMetadata = cms.metadata` (NEXT-META D327–D329): title, description, the
|
|
227
|
+
* canonical and hreflang made absolute on the Site URL (`metadataBase`), Open Graph (url, type,
|
|
228
|
+
* locale, siteName, an article's dates, image), the Twitter card.
|
|
229
|
+
*/
|
|
230
|
+
metadata: (props: CmsPageProps) => Promise<Metadata>;
|
|
231
|
+
/** An address the CMS gave (an image, a file, an og image), absolute. */
|
|
232
|
+
url: typeof platformUrl;
|
|
233
|
+
/** The signed-in reader of the site, or null (D192). */
|
|
234
|
+
reader(): Promise<{
|
|
235
|
+
id: string;
|
|
236
|
+
email: string;
|
|
237
|
+
purchases: string[];
|
|
238
|
+
} | null>;
|
|
239
|
+
/**
|
|
240
|
+
* SIGN-IN (D347): where a "Sign in with …" button of the site goes — one
|
|
241
|
+
* of `site().signIn` (`key`), back to `returnTo` (a path of the site).
|
|
242
|
+
* The platform signs the reader in and returns to the site's CMS route
|
|
243
|
+
* (`/api/cms/signed-in`), which sets the reader's cookie; a refusal comes
|
|
244
|
+
* back to `returnTo` with `?signin=closed|domain|unverified|revoked|failed`.
|
|
245
|
+
*/
|
|
246
|
+
signInUrl(key: string, returnTo?: string): Promise<string>;
|
|
247
|
+
/** Another page or filter of a list: a link the CMS built (and signed), read with the visitor's address. */
|
|
248
|
+
follow(link: string): Promise<_thecms_sdk.ResolvedBodyItem>;
|
|
249
|
+
/** The values of protected fields the reader bought (paywall keys of the page); null without a signed-in reader. */
|
|
250
|
+
unlock(keys: string[]): Promise<_thecms_sdk.UnlockAnswer | null>;
|
|
251
|
+
/**
|
|
252
|
+
* PAYMENTS (D361): buy a product for the signed-in reader (from a server
|
|
253
|
+
* action: `redirect((await cms.checkout(id, "/thanks"))!.redirectUrl)`) —
|
|
254
|
+
* priced for the reader's country (their address forwarded: the secret key
|
|
255
|
+
* makes the CMS trust it), back to `returnTo` with `?order=<id>`; null
|
|
256
|
+
* without a signed-in reader. A refusal is a `CmsError` with
|
|
257
|
+
* `details.reason`. Without code: a form posting `productId` and `return`
|
|
258
|
+
* to `/api/cms/checkout` (the optional route) does the same.
|
|
259
|
+
*/
|
|
260
|
+
checkout(productId: string, returnTo?: string): Promise<CheckoutStarted | null>;
|
|
261
|
+
/** D360: the signed-in reader's purchases, newest first (in force, until when, still on sale); null without a reader. */
|
|
262
|
+
purchases(): Promise<ReaderPurchase[] | null>;
|
|
263
|
+
/** D355: one of the signed-in reader's orders (the return page's `?order=<id>`); null without a reader or for an order not theirs. */
|
|
264
|
+
order(id: string): Promise<ReaderOrder | null>;
|
|
265
|
+
/**
|
|
266
|
+
* D257: `export const GET = cms.sitemap` in `app/sitemap.xml/route.ts` — the
|
|
267
|
+
* CMS's sitemap from the site's own address; 404 when the application
|
|
268
|
+
* publishes none.
|
|
269
|
+
*/
|
|
270
|
+
sitemap: () => Promise<Response>;
|
|
271
|
+
/**
|
|
272
|
+
* D257: `export default cms.robots` in `app/robots.ts` — the whole site, the
|
|
273
|
+
* sitemap in when there is one; SEO-AI (D490): with AI readers off, the AI
|
|
274
|
+
* crawlers shut out (the platform's list), the rest unchanged.
|
|
275
|
+
*/
|
|
276
|
+
robots: () => Promise<MetadataRoute.Robots>;
|
|
277
|
+
/**
|
|
278
|
+
* SEO-AI (D491): `export const GET = cms.llms` in `app/llms.txt/route.ts` —
|
|
279
|
+
* the site's pages for AI readers (`?part=n` of an index); 404 while AI readers are off.
|
|
280
|
+
*/
|
|
281
|
+
llms: (req: Request) => Promise<Response>;
|
|
282
|
+
/**
|
|
283
|
+
* SEO-AI (D492, SA7 D506): `export const GET = cms.pageText` in
|
|
284
|
+
* `app/llms/[[...path]]/route.ts` — the clean text of the page at the rest
|
|
285
|
+
* of the address (`/llms/it/chi-siamo` → `/it/chi-siamo`, `/llms` → the
|
|
286
|
+
* home): EXACTLY what the page shows, the site's own code included. The
|
|
287
|
+
* site's public page is asked as a visitor from nowhere known (no cookie,
|
|
288
|
+
* no preview: paid fields stay closed, only what every country reads) and
|
|
289
|
+
* its HTML becomes markdown. A page answering 404, a redirect or blocked
|
|
290
|
+
* by country → 404; AI readers off → 404. Kept a minute per instance and
|
|
291
|
+
* cached like a public page: an AI reader never redraws it each time.
|
|
292
|
+
*/
|
|
293
|
+
pageText: (req: Request, ctx: {
|
|
294
|
+
params: Promise<{
|
|
295
|
+
path?: string[];
|
|
296
|
+
}>;
|
|
297
|
+
}) => Promise<Response>;
|
|
298
|
+
/** `export const { GET, POST } = cms.handler` in `app/api/cms/[...cms]/route.ts` (D189–D192; SIGN-IN D347: `signed-in`; PAYMENTS D361: `checkout`). */
|
|
299
|
+
handler: {
|
|
300
|
+
GET: (req: Request, ctx: RouteContext) => Promise<Response>;
|
|
301
|
+
POST: (req: Request, ctx: RouteContext) => Promise<Response>;
|
|
302
|
+
};
|
|
303
|
+
} & {
|
|
304
|
+
sdk: Sdk;
|
|
305
|
+
};
|
|
306
|
+
type NextCms = ReturnType<typeof createNextCms>;
|
|
307
|
+
type RouteContext = {
|
|
308
|
+
params: Promise<{
|
|
309
|
+
cms?: string[];
|
|
310
|
+
}>;
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
export { type CmsBlockComponent, type CmsBlockProps, CmsBlocks, type CmsBlocksProps, type CmsClientConfig, type CmsComponents, type CmsContext, type CmsGeoBlocked, type CmsPage, type CmsPageProps, CmsSiteTexts, NEXT_VERSION, type NextCms, type NextCmsOptions, READER_COOKIE, SITE_TEXT_KEYS, type SiteText, type SiteTexts, cmsContext, createNextCms, ogLocale, sitePageOrigins };
|