@decocms/blocks 8.1.0-next.6 → 8.1.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/v8/cli/check/index.d.ts +6 -2
- package/dist/v8/cli/check/index.d.ts.map +1 -1
- package/dist/v8/cli/check/index.js +34 -7
- package/dist/v8/cli/check/index.js.map +1 -1
- package/dist/v8/cli/color.d.ts +14 -0
- package/dist/v8/cli/color.d.ts.map +1 -0
- package/dist/v8/cli/color.js +14 -0
- package/dist/v8/cli/color.js.map +1 -0
- package/dist/v8/cli/content.d.ts +24 -3
- package/dist/v8/cli/content.d.ts.map +1 -1
- package/dist/v8/cli/content.js +70 -5
- package/dist/v8/cli/content.js.map +1 -1
- package/dist/v8/cli/log.d.ts +4 -0
- package/dist/v8/cli/log.d.ts.map +1 -1
- package/dist/v8/cli/log.js +9 -0
- package/dist/v8/cli/log.js.map +1 -1
- package/dist/v8/cli/run.d.ts +1 -0
- package/dist/v8/cli/run.d.ts.map +1 -1
- package/dist/v8/cli/run.js +18 -4
- package/dist/v8/cli/run.js.map +1 -1
- package/dist/v8/cli/schema/index.d.ts.map +1 -1
- package/dist/v8/cli/schema/index.js +5 -3
- package/dist/v8/cli/schema/index.js.map +1 -1
- package/dist/v8/cli/schema/tsProgram.d.ts +1 -0
- package/dist/v8/cli/schema/tsProgram.d.ts.map +1 -1
- package/dist/v8/cli/schema/tsProgram.js +1 -0
- package/dist/v8/cli/schema/tsProgram.js.map +1 -1
- package/dist/v8/cli/schema/typeToSchema.d.ts.map +1 -1
- package/dist/v8/cli/schema/typeToSchema.js +50 -7
- package/dist/v8/cli/schema/typeToSchema.js.map +1 -1
- package/dist/v8/cms.d.ts.map +1 -1
- package/dist/v8/cms.js +16 -19
- package/dist/v8/cms.js.map +1 -1
- package/dist/v8/content.d.ts +4 -5
- package/dist/v8/content.d.ts.map +1 -1
- package/dist/v8/content.js +46 -44
- package/dist/v8/content.js.map +1 -1
- package/dist/v8/draftChanges.d.ts +37 -14
- package/dist/v8/draftChanges.d.ts.map +1 -1
- package/dist/v8/draftChanges.js +66 -44
- package/dist/v8/draftChanges.js.map +1 -1
- package/dist/v8/identity.d.ts +0 -2
- package/dist/v8/identity.d.ts.map +1 -1
- package/dist/v8/identity.js +0 -10
- package/dist/v8/identity.js.map +1 -1
- package/dist/v8/matchRoute.d.ts +12 -10
- package/dist/v8/matchRoute.d.ts.map +1 -1
- package/dist/v8/matchRoute.js +60 -86
- package/dist/v8/matchRoute.js.map +1 -1
- package/dist/v8/remoteLoader.d.ts +4 -4
- package/dist/v8/remoteLoader.d.ts.map +1 -1
- package/dist/v8/remoteLoader.js +106 -96
- package/dist/v8/remoteLoader.js.map +1 -1
- package/dist/v8/routeTrie.d.ts +43 -0
- package/dist/v8/routeTrie.d.ts.map +1 -0
- package/dist/v8/routeTrie.js +88 -0
- package/dist/v8/routeTrie.js.map +1 -0
- package/dist/v8/telemetry.d.ts +7 -7
- package/dist/v8/telemetry.d.ts.map +1 -1
- package/dist/v8/telemetry.js +24 -100
- package/dist/v8/telemetry.js.map +1 -1
- package/dist/v8/types.d.ts +59 -17
- package/dist/v8/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/v8/cli/check/index.ts +32 -7
- package/src/v8/cli/color.ts +29 -0
- package/src/v8/cli/content.ts +85 -5
- package/src/v8/cli/log.ts +12 -0
- package/src/v8/cli/run.ts +19 -4
- package/src/v8/cli/schema/index.ts +5 -3
- package/src/v8/cli/schema/tsProgram.ts +2 -1
- package/src/v8/cli/schema/typeToSchema.ts +47 -7
- package/src/v8/cms.ts +17 -20
- package/src/v8/content.ts +54 -46
- package/src/v8/draftChanges.ts +79 -43
- package/src/v8/identity.ts +0 -10
- package/src/v8/matchRoute.ts +70 -106
- package/src/v8/remoteLoader.ts +112 -111
- package/src/v8/routeTrie.ts +103 -0
- package/src/v8/telemetry.ts +27 -108
- package/src/v8/types.ts +60 -15
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The segment trie behind `matchRoute` (see /next/router-internals): paths
|
|
3
|
+
* compile into nodes keyed by segment, and a lookup walks the URL's segments,
|
|
4
|
+
* trying the literal child, then the parameter child, then a trailing `*` (a
|
|
5
|
+
* splat: one or more remaining segments). A lookup costs the URL's depth, not
|
|
6
|
+
* the number of entries. No regex, no sorting.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** A leaf holds the entry and its parameter names, in path order; `splat` is a trailing `*`'s leaf. */
|
|
10
|
+
type Leaf<T> = { value: T; names: string[] };
|
|
11
|
+
export type TrieNode<T> = {
|
|
12
|
+
literals: Map<string, TrieNode<T>>;
|
|
13
|
+
param?: TrieNode<T>;
|
|
14
|
+
leaf?: Leaf<T>;
|
|
15
|
+
splat?: Leaf<T>;
|
|
16
|
+
};
|
|
17
|
+
export type Hit<T> = { value: T; params: Record<string, string>; rest: string[] };
|
|
18
|
+
|
|
19
|
+
/** A trie holding `entries` (`[path, value]`); on a conflict the earlier keeps the leaf. */
|
|
20
|
+
export function buildTrie<T>(entries: Iterable<[string, T]>): TrieNode<T> {
|
|
21
|
+
const root: TrieNode<T> = { literals: new Map() };
|
|
22
|
+
for (const [path, value] of entries) insert(root, path, value);
|
|
23
|
+
return root;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Adds `path`; returns the value already holding its leaf (a conflict: the earlier keeps it). */
|
|
27
|
+
export function insert<T>(root: TrieNode<T>, path: string, value: T): T | undefined {
|
|
28
|
+
const names: string[] = [];
|
|
29
|
+
const segments = splitPath(path);
|
|
30
|
+
let node = root;
|
|
31
|
+
for (const [i, segment] of segments.entries()) {
|
|
32
|
+
if (segment === "*" && i === segments.length - 1) {
|
|
33
|
+
if (node.splat) return node.splat.value;
|
|
34
|
+
node.splat = { value, names };
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
if (segment.startsWith(":") && segment.length > 1) {
|
|
38
|
+
names.push(segment.slice(1));
|
|
39
|
+
node = node.param ??= { literals: new Map() };
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const literal = safeDecode(segment);
|
|
43
|
+
const child = node.literals.get(literal) ?? { literals: new Map() };
|
|
44
|
+
node.literals.set(literal, child);
|
|
45
|
+
node = child;
|
|
46
|
+
}
|
|
47
|
+
if (node.leaf) return node.leaf.value;
|
|
48
|
+
node.leaf = { value, names };
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Walks the URL's segments: the literal child first, then the parameter child, then the splat. */
|
|
53
|
+
export function lookup<T>(
|
|
54
|
+
node: TrieNode<T>,
|
|
55
|
+
segs: string[],
|
|
56
|
+
i = 0,
|
|
57
|
+
vals: string[] = [],
|
|
58
|
+
): Hit<T> | null {
|
|
59
|
+
if (i === segs.length) return node.leaf ? hit(node.leaf, vals, []) : null;
|
|
60
|
+
const literal = node.literals.get(segs[i]!);
|
|
61
|
+
let found = literal ? lookup(literal, segs, i + 1, vals) : null;
|
|
62
|
+
// A parameter is one segment and never contains a slash, even an encoded one.
|
|
63
|
+
if (!found && node.param && !segs[i]!.includes("/")) {
|
|
64
|
+
found = lookup(node.param, segs, i + 1, [...vals, segs[i]!]);
|
|
65
|
+
}
|
|
66
|
+
// A splat takes the rest (at least one segment, as there is one here).
|
|
67
|
+
return found ?? (node.splat ? hit(node.splat, vals, segs.slice(i)) : null);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function hit<T>({ value, names }: Leaf<T>, values: string[], rest: string[]): Hit<T> {
|
|
71
|
+
const params: Record<string, string> = Object.fromEntries(names.map((n, i) => [n, values[i]!]));
|
|
72
|
+
if (rest.length > 0) params["*"] = rest.join("/");
|
|
73
|
+
return { value, params, rest };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** `/a/b/`, `/a//b` and `/a/b?x` all name `["a", "b"]`; `/` names `[]`. */
|
|
77
|
+
export function splitPath(path: string): string[] {
|
|
78
|
+
return splitRef(path)
|
|
79
|
+
.path.split("/")
|
|
80
|
+
.filter((segment) => segment.length > 0);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A path or URL split at its first `?` and `#`: everything before, the query
|
|
85
|
+
* (without its `?`, `""` when there's none) and the fragment (with its `#`).
|
|
86
|
+
*/
|
|
87
|
+
export function splitRef(ref: string): { path: string; query: string; hash: string } {
|
|
88
|
+
const hashAt = ref.indexOf("#") === -1 ? ref.length : ref.indexOf("#");
|
|
89
|
+
const queryAt = ref.indexOf("?") === -1 || ref.indexOf("?") > hashAt ? hashAt : ref.indexOf("?");
|
|
90
|
+
return {
|
|
91
|
+
path: ref.slice(0, queryAt),
|
|
92
|
+
query: ref.slice(queryAt + 1, hashAt),
|
|
93
|
+
hash: ref.slice(hashAt),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function safeDecode(segment: string): string {
|
|
98
|
+
try {
|
|
99
|
+
return decodeURIComponent(segment);
|
|
100
|
+
} catch {
|
|
101
|
+
return segment;
|
|
102
|
+
}
|
|
103
|
+
}
|
package/src/v8/telemetry.ts
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
* Telemetry: OpenTelemetry over OTLP/HTTP (JSON, gzipped), with no SDK. See
|
|
3
3
|
* /next/telemetry and /next/telemetry-internals.
|
|
4
4
|
*
|
|
5
|
-
* - **Where** comes from code: `createCMS({ telemetry
|
|
6
|
-
* `
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* wins when both are set. `false` sends nothing.
|
|
5
|
+
* - **Where** comes from code only: `createCMS({ telemetry: { endpoint,
|
|
6
|
+
* headers } })`, else the hosted Deco CMS collector when `createCMS` has a
|
|
7
|
+
* `token` (sent as a Bearer token), else nowhere. `false` sends nothing.
|
|
8
|
+
* Nothing is read from the environment.
|
|
10
9
|
* - **How much** comes from content: the `telemetry` section of the CMS
|
|
11
10
|
* settings (`cms.settings()`, the release's `CMS` block), capped by
|
|
12
11
|
* `telemetry.limits`. The CMS reads it outside any request, when the
|
|
@@ -21,10 +20,9 @@
|
|
|
21
20
|
import { hasBackgroundHook, later, runInBackground } from "./background.ts";
|
|
22
21
|
import { rate, TELEMETRY_DEFAULTS } from "./builtins/data.ts";
|
|
23
22
|
import { isResolutionError } from "./errors.ts";
|
|
24
|
-
import { readEnv } from "./identity.ts";
|
|
25
23
|
import type { CMSError, Snapshot, Telemetry, TelemetryConfig } from "./types.ts";
|
|
26
24
|
|
|
27
|
-
/** The hosted Deco CMS collector, for `
|
|
25
|
+
/** The hosted Deco CMS collector, for `createCMS({ token })`. */
|
|
28
26
|
const HOSTED_TELEMETRY_ENDPOINT = "https://otel.decocms.com";
|
|
29
27
|
|
|
30
28
|
const SINK = Symbol.for("decocms.blocks.telemetry");
|
|
@@ -54,12 +52,12 @@ type Attributes = Record<string, string | number | boolean | undefined>;
|
|
|
54
52
|
type Signal = "metrics" | "logs" | "traces";
|
|
55
53
|
|
|
56
54
|
interface Destination {
|
|
57
|
-
/** The base URL each signal's `/v1/<signal>` is appended to
|
|
55
|
+
/** The base URL each signal's `/v1/<signal>` is appended to. */
|
|
58
56
|
endpoint: string;
|
|
59
|
-
/** Full per-signal URLs, used as they are (the `OTEL_EXPORTER_OTLP_<SIGNAL>_ENDPOINT` form). */
|
|
60
|
-
signals?: Partial<Record<Signal, string>>;
|
|
61
57
|
headers: Record<string, string>;
|
|
62
58
|
site?: string;
|
|
59
|
+
/** `telemetry.resource`: merged over the default resource attributes. */
|
|
60
|
+
resource: Record<string, string>;
|
|
63
61
|
limits: { errorSampleRate: number; traceSampleRate: number };
|
|
64
62
|
}
|
|
65
63
|
|
|
@@ -98,69 +96,32 @@ interface LogRecord {
|
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
/**
|
|
101
|
-
* Where telemetry goes, or `null` for nowhere
|
|
102
|
-
* `
|
|
99
|
+
* Where telemetry goes, or `null` for nowhere: `false` is off; a non-empty
|
|
100
|
+
* `endpoint` is that collector, with `headers`; otherwise a `token` is the
|
|
101
|
+
* hosted Deco CMS collector, with the token as a Bearer credential.
|
|
103
102
|
*/
|
|
104
103
|
export function resolveDestination(
|
|
105
104
|
config: false | TelemetryConfig | undefined,
|
|
106
105
|
site?: string,
|
|
106
|
+
token?: string,
|
|
107
107
|
): Destination | null {
|
|
108
108
|
if (config === false) return null;
|
|
109
|
-
|
|
109
|
+
// OPEN: no per-signal URLs (v7's OTEL_EXPORTER_OTLP_<SIGNAL>_ENDPOINT): every signal goes to `<endpoint>/v1/<signal>`.
|
|
110
110
|
const limits = telemetryLimits(config);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return { endpoint: config.endpoint, headers: { ...config.headers }, site, limits };
|
|
111
|
+
const resource = { ...config?.resource };
|
|
112
|
+
if (typeof config?.endpoint === "string" && config.endpoint) {
|
|
113
|
+
return { endpoint: config.endpoint, headers: { ...config.headers }, site, resource, limits };
|
|
114
114
|
}
|
|
115
|
-
if (!
|
|
115
|
+
if (!token) return null;
|
|
116
116
|
return {
|
|
117
117
|
endpoint: HOSTED_TELEMETRY_ENDPOINT,
|
|
118
|
-
headers: { authorization: `Bearer ${
|
|
119
|
-
site
|
|
118
|
+
headers: { authorization: `Bearer ${token}` },
|
|
119
|
+
site,
|
|
120
|
+
resource,
|
|
120
121
|
limits,
|
|
121
122
|
};
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
/** v7's names for the standard OTLP variables, read when the standard one is unset. */
|
|
125
|
-
const V7_ALIASES = {
|
|
126
|
-
OTEL_EXPORTER_OTLP_HEADERS: "DECO_OTEL_HEADERS",
|
|
127
|
-
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT: "DECO_OTEL_METRICS_ENDPOINT",
|
|
128
|
-
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT: "DECO_OTEL_LOGS_ENDPOINT",
|
|
129
|
-
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: "DECO_OTEL_TRACES_ENDPOINT",
|
|
130
|
-
} as const;
|
|
131
|
-
|
|
132
|
-
/** The standard variable, else its v7 alias. */
|
|
133
|
-
function readOtlpEnv(name: keyof typeof V7_ALIASES | "OTEL_EXPORTER_OTLP_ENDPOINT") {
|
|
134
|
-
return (
|
|
135
|
-
readEnv(name) ||
|
|
136
|
-
(name in V7_ALIASES ? readEnv(V7_ALIASES[name as keyof typeof V7_ALIASES]) : undefined)
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* The destination the environment names: the standard OTLP variables, with
|
|
142
|
-
* v7's `DECO_OTEL_*` names as aliases. `DECO_OTEL_AUTH_TOKEN` (v7's secret
|
|
143
|
-
* for the collector) becomes the `authorization` header unless the headers
|
|
144
|
-
* set one. `null` when no endpoint is set.
|
|
145
|
-
*/
|
|
146
|
-
function destinationFromEnv(site: string | undefined): Destination | null {
|
|
147
|
-
const endpoint = readOtlpEnv("OTEL_EXPORTER_OTLP_ENDPOINT") ?? "";
|
|
148
|
-
const signals: Partial<Record<Signal, string>> = {};
|
|
149
|
-
for (const signal of ["metrics", "logs", "traces"] as const) {
|
|
150
|
-
const url = readOtlpEnv(
|
|
151
|
-
`OTEL_EXPORTER_OTLP_${signal.toUpperCase() as Uppercase<Signal>}_ENDPOINT`,
|
|
152
|
-
);
|
|
153
|
-
if (url) signals[signal] = url;
|
|
154
|
-
}
|
|
155
|
-
if (!endpoint && Object.keys(signals).length === 0) return null;
|
|
156
|
-
const token = readEnv("DECO_OTEL_AUTH_TOKEN");
|
|
157
|
-
const headers = {
|
|
158
|
-
...(token ? { authorization: token } : {}),
|
|
159
|
-
...parseKeyValues(readOtlpEnv("OTEL_EXPORTER_OTLP_HEADERS")),
|
|
160
|
-
};
|
|
161
|
-
return { endpoint, signals, headers, site, limits: DEFAULT_LIMITS };
|
|
162
|
-
}
|
|
163
|
-
|
|
164
125
|
export class TelemetryPipeline {
|
|
165
126
|
readonly #destination: Destination;
|
|
166
127
|
#settings: Required<Telemetry> = { ...TELEMETRY_DEFAULTS };
|
|
@@ -430,24 +391,19 @@ export class TelemetryPipeline {
|
|
|
430
391
|
#resource(): Attributes {
|
|
431
392
|
const site = this.#destination.site;
|
|
432
393
|
return {
|
|
433
|
-
"service.name":
|
|
434
|
-
"service.version":
|
|
435
|
-
"
|
|
436
|
-
|
|
437
|
-
(readEnv("NODE_ENV") === "development" ? "development" : "production"),
|
|
394
|
+
"service.name": site || "decocms-site",
|
|
395
|
+
"service.version": "unknown",
|
|
396
|
+
// OPEN: the environment name defaults to "production"; `telemetry.resource` overrides it.
|
|
397
|
+
"deployment.environment.name": "production",
|
|
438
398
|
...(site ? { "deco.site": site } : {}),
|
|
439
399
|
...(this.#release ? { "deco.release": this.#release } : {}),
|
|
440
|
-
//
|
|
441
|
-
|
|
442
|
-
...parseKeyValues(readEnv("OTEL_RESOURCE_ATTRIBUTES")),
|
|
400
|
+
// `telemetry.resource` wins: service.version=<commit>, deployment.environment.name=preview, …
|
|
401
|
+
...this.#destination.resource,
|
|
443
402
|
};
|
|
444
403
|
}
|
|
445
404
|
|
|
446
405
|
async #send(signal: Signal, payload: unknown): Promise<void> {
|
|
447
|
-
const
|
|
448
|
-
const url =
|
|
449
|
-
signals?.[signal] ?? (endpoint ? `${endpoint.replace(/\/+$/, "")}/v1/${signal}` : "");
|
|
450
|
-
if (!url) return; // this signal has no destination
|
|
406
|
+
const url = `${this.#destination.endpoint.replace(/\/+$/, "")}/v1/${signal}`;
|
|
451
407
|
const { body, gzipped } = await gzip(JSON.stringify(payload));
|
|
452
408
|
const headers: Record<string, string> = {
|
|
453
409
|
...this.#destination.headers,
|
|
@@ -485,26 +441,6 @@ export function setCurrentTelemetry(pipeline: TelemetryPipeline | undefined): vo
|
|
|
485
441
|
// Helpers
|
|
486
442
|
// ---------------------------------------------------------------------------
|
|
487
443
|
|
|
488
|
-
/** Where hosts put the deployed commit, tried in order (`service.version`). */
|
|
489
|
-
const COMMIT_VARIABLES = [
|
|
490
|
-
"DECO_COMMIT_SHA",
|
|
491
|
-
"WORKERS_CI_COMMIT_SHA",
|
|
492
|
-
"CF_PAGES_COMMIT_SHA",
|
|
493
|
-
"VERCEL_GIT_COMMIT_SHA",
|
|
494
|
-
"GITHUB_SHA",
|
|
495
|
-
"RENDER_GIT_COMMIT",
|
|
496
|
-
"SOURCE_VERSION",
|
|
497
|
-
"COMMIT_SHA",
|
|
498
|
-
];
|
|
499
|
-
|
|
500
|
-
function firstEnv(names: readonly string[]): string | undefined {
|
|
501
|
-
for (const name of names) {
|
|
502
|
-
const value = readEnv(name);
|
|
503
|
-
if (value) return value;
|
|
504
|
-
}
|
|
505
|
-
return undefined;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
444
|
const QUERY = /(https?:\/\/[^\s?#"'<>]+)\?[^\s#"'<>]*/gi;
|
|
509
445
|
const CREDENTIAL = /\b(Bearer|Basic)\s+[\w~+/.=-]+/gi;
|
|
510
446
|
const SENSITIVE =
|
|
@@ -537,23 +473,6 @@ function randomHex(bytes: number): string {
|
|
|
537
473
|
return Array.from(values, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
538
474
|
}
|
|
539
475
|
|
|
540
|
-
/** `k1=v1,k2=v2` with URL-encoded values, the format of the OTEL_* environment variables. */
|
|
541
|
-
function parseKeyValues(raw: string | undefined): Record<string, string> {
|
|
542
|
-
const out: Record<string, string> = {};
|
|
543
|
-
for (const pair of raw?.split(",") ?? []) {
|
|
544
|
-
const at = pair.indexOf("=");
|
|
545
|
-
if (at <= 0) continue;
|
|
546
|
-
try {
|
|
547
|
-
out[decodeURIComponent(pair.slice(0, at).trim())] = decodeURIComponent(
|
|
548
|
-
pair.slice(at + 1).trim(),
|
|
549
|
-
);
|
|
550
|
-
} catch {
|
|
551
|
-
// A malformed pair is skipped.
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
return out;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
476
|
function encodeAttributes(attributes: Attributes, scrub: (text: string) => string) {
|
|
558
477
|
return Object.entries(attributes)
|
|
559
478
|
.filter(([, value]) => value !== undefined)
|
package/src/v8/types.ts
CHANGED
|
@@ -28,6 +28,19 @@ export type Snapshot = {
|
|
|
28
28
|
blocks: Record<string, unknown>;
|
|
29
29
|
/** The alias table `deco content` writes: old type name → your type. */
|
|
30
30
|
aliases?: Record<string, string>;
|
|
31
|
+
/**
|
|
32
|
+
* The hash of the `.deco/schema.gen.json` this content was built with, which
|
|
33
|
+
* `deco content` writes. A hosted release is swapped in only when its
|
|
34
|
+
* `schemaHash` equals the bundled content's; without one, never.
|
|
35
|
+
*/
|
|
36
|
+
schemaHash?: string;
|
|
37
|
+
/**
|
|
38
|
+
* The commit time of the git HEAD `deco content` built this content from
|
|
39
|
+
* (committer date, ISO 8601). A hosted release is swapped in only when its
|
|
40
|
+
* `publishedAt` is later; without one (a custom loader, an older content
|
|
41
|
+
* module, a build outside git), the bundled content counts as the oldest.
|
|
42
|
+
*/
|
|
43
|
+
committedAt?: string;
|
|
31
44
|
};
|
|
32
45
|
|
|
33
46
|
/**
|
|
@@ -48,11 +61,11 @@ export interface Loader {
|
|
|
48
61
|
|
|
49
62
|
/** The parts of a draft pointer, `<host[:port]><path[?query]>@<version>`. */
|
|
50
63
|
export interface DraftPointer {
|
|
51
|
-
/** `host[:port]`
|
|
64
|
+
/** `host[:port]` that serves the draft's changes. */
|
|
52
65
|
host: string;
|
|
53
66
|
/** Starts with `/`; opaque to the app. Never carries the `__variant` parameters. */
|
|
54
67
|
path: string;
|
|
55
|
-
/** Opaque:
|
|
68
|
+
/** Opaque: identifies the editor's last save. `"local"` names no draft (`deco serve`). */
|
|
56
69
|
version: string;
|
|
57
70
|
/** The variants this preview forces (the query's `__variant` parameters); absent when none. */
|
|
58
71
|
variants?: ForcedVariant[];
|
|
@@ -94,7 +107,12 @@ export interface Page extends Route {
|
|
|
94
107
|
|
|
95
108
|
/** The built-in `redirect` block. */
|
|
96
109
|
export interface Redirect {
|
|
97
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* Literal path or template (`:name` segments, an optional trailing `/*`),
|
|
112
|
+
* optionally scoped to a query (`/calcados?map=c,ft`): then it matches only
|
|
113
|
+
* a request whose query string is exactly that one, and wins over a
|
|
114
|
+
* path-only `from` for the same URL.
|
|
115
|
+
*/
|
|
98
116
|
from: string;
|
|
99
117
|
to: string;
|
|
100
118
|
/** `true` for a 301, `false` for a 302. */
|
|
@@ -212,12 +230,23 @@ export type Match<T> =
|
|
|
212
230
|
// The CMS and its clients
|
|
213
231
|
// ---------------------------------------------------------------------------
|
|
214
232
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
233
|
+
/**
|
|
234
|
+
* Where telemetry goes. With `endpoint`, to that OTLP/HTTP collector, with
|
|
235
|
+
* `headers`; without one, to the hosted Deco CMS collector when `createCMS`
|
|
236
|
+
* has a `token`, and nowhere otherwise.
|
|
237
|
+
*/
|
|
238
|
+
export interface TelemetryConfig {
|
|
239
|
+
/** An OTLP/HTTP base URL; each signal is sent to `<endpoint>/v1/<signal>`. */
|
|
240
|
+
endpoint?: string;
|
|
241
|
+
/** Headers sent with every batch to `endpoint`. */
|
|
242
|
+
headers?: Record<string, string>;
|
|
243
|
+
/**
|
|
244
|
+
* Resource attributes, merged over the defaults (`service.name`,
|
|
245
|
+
* `service.version`, `deployment.environment.name`, …).
|
|
246
|
+
*/
|
|
247
|
+
resource?: Record<string, string>;
|
|
219
248
|
limits?: { errorSampleRate?: number; traceSampleRate?: number };
|
|
220
|
-
}
|
|
249
|
+
}
|
|
221
250
|
|
|
222
251
|
export interface CMSConfig {
|
|
223
252
|
/** Your block functions; the CMS uses `{ ...builtIns, ...blocks }`. */
|
|
@@ -226,6 +255,12 @@ export interface CMSConfig {
|
|
|
226
255
|
content: ContentModule | Loader;
|
|
227
256
|
/** ms between `update()` checks of a content source that has one; minimum 60 000. */
|
|
228
257
|
interval?: number;
|
|
258
|
+
/**
|
|
259
|
+
* Local development (`import.meta.env.DEV`, `process.env.NODE_ENV === "development"`):
|
|
260
|
+
* hosted releases are never swapped in, so local files win. Drafts still load.
|
|
261
|
+
* The SDK reads no environment variable for it; default `false`.
|
|
262
|
+
*/
|
|
263
|
+
dev?: boolean;
|
|
229
264
|
/** Where telemetry goes; see /next/telemetry. */
|
|
230
265
|
telemetry?: false | TelemetryConfig;
|
|
231
266
|
preview?: {
|
|
@@ -234,12 +269,24 @@ export interface CMSConfig {
|
|
|
234
269
|
* (/next/api-reference#host-patterns). Without it, content may allow any host.
|
|
235
270
|
*/
|
|
236
271
|
hosts?: string[];
|
|
272
|
+
/**
|
|
273
|
+
* The hosts a draft pointer may point at; replaces the defaults (v7's
|
|
274
|
+
* list: `.decocms.com` and the loopback hosts). An entry starting with a
|
|
275
|
+
* dot matches any subdomain; any other entry, that exact host.
|
|
276
|
+
*/
|
|
277
|
+
draftHosts?: string[];
|
|
237
278
|
};
|
|
238
279
|
/** The private key that decrypts `secret` blocks. */
|
|
239
280
|
secrets?: { key?: string };
|
|
240
|
-
/**
|
|
281
|
+
/**
|
|
282
|
+
* Your site ID (Studio's site slug): turns on hosted releases from
|
|
283
|
+
* `delivery.decocms.com`. Drafts don't need it.
|
|
284
|
+
*/
|
|
241
285
|
site?: string;
|
|
242
|
-
/**
|
|
286
|
+
/**
|
|
287
|
+
* Your site token (server-only secret): sends telemetry to the hosted Deco
|
|
288
|
+
* CMS collector. Releases and drafts don't use it. Needs `site`.
|
|
289
|
+
*/
|
|
243
290
|
token?: string;
|
|
244
291
|
}
|
|
245
292
|
|
|
@@ -280,13 +327,11 @@ export interface CMS {
|
|
|
280
327
|
forRelease(): Client;
|
|
281
328
|
/**
|
|
282
329
|
* A client reading the draft a pointer names: its changes, fetched from a
|
|
283
|
-
*
|
|
284
|
-
* `
|
|
285
|
-
* production content.
|
|
330
|
+
* draft host (`*.decocms.com` and loopback by default;
|
|
331
|
+
* `createCMS({ preview: { draftHosts } })` replaces the list), over this
|
|
332
|
+
* server's production content.
|
|
286
333
|
*/
|
|
287
334
|
forDraft(pointer: string): Client;
|
|
288
|
-
/** A client pinned to a revision this CMS has served; an unknown revision behaves like the release. */
|
|
289
|
-
forRevision(revision: string): Client;
|
|
290
335
|
/** Ask the content source for newer content now; never throws. */
|
|
291
336
|
update(): Promise<{ updated: boolean }>;
|
|
292
337
|
/**
|