@decocms/blocks 8.1.0-next.6 → 8.1.0-next.7
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/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/run.js +1 -1
- package/dist/v8/cli/run.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/remoteLoader.d.ts +2 -4
- package/dist/v8/remoteLoader.d.ts.map +1 -1
- package/dist/v8/remoteLoader.js +106 -87
- package/dist/v8/remoteLoader.js.map +1 -1
- 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 +47 -16
- package/dist/v8/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/v8/cli/content.ts +85 -5
- package/src/v8/cli/run.ts +1 -1
- 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/remoteLoader.ts +111 -106
- package/src/v8/telemetry.ts +27 -108
- package/src/v8/types.ts +48 -14
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[];
|
|
@@ -212,12 +225,23 @@ export type Match<T> =
|
|
|
212
225
|
// The CMS and its clients
|
|
213
226
|
// ---------------------------------------------------------------------------
|
|
214
227
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
228
|
+
/**
|
|
229
|
+
* Where telemetry goes. With `endpoint`, to that OTLP/HTTP collector, with
|
|
230
|
+
* `headers`; without one, to the hosted Deco CMS collector when `createCMS`
|
|
231
|
+
* has a `token`, and nowhere otherwise.
|
|
232
|
+
*/
|
|
233
|
+
export interface TelemetryConfig {
|
|
234
|
+
/** An OTLP/HTTP base URL; each signal is sent to `<endpoint>/v1/<signal>`. */
|
|
235
|
+
endpoint?: string;
|
|
236
|
+
/** Headers sent with every batch to `endpoint`. */
|
|
237
|
+
headers?: Record<string, string>;
|
|
238
|
+
/**
|
|
239
|
+
* Resource attributes, merged over the defaults (`service.name`,
|
|
240
|
+
* `service.version`, `deployment.environment.name`, …).
|
|
241
|
+
*/
|
|
242
|
+
resource?: Record<string, string>;
|
|
219
243
|
limits?: { errorSampleRate?: number; traceSampleRate?: number };
|
|
220
|
-
}
|
|
244
|
+
}
|
|
221
245
|
|
|
222
246
|
export interface CMSConfig {
|
|
223
247
|
/** Your block functions; the CMS uses `{ ...builtIns, ...blocks }`. */
|
|
@@ -234,12 +258,24 @@ export interface CMSConfig {
|
|
|
234
258
|
* (/next/api-reference#host-patterns). Without it, content may allow any host.
|
|
235
259
|
*/
|
|
236
260
|
hosts?: string[];
|
|
261
|
+
/**
|
|
262
|
+
* The hosts a draft pointer may point at; replaces the defaults (v7's
|
|
263
|
+
* list: `.decocms.com` and the loopback hosts). An entry starting with a
|
|
264
|
+
* dot matches any subdomain; any other entry, that exact host.
|
|
265
|
+
*/
|
|
266
|
+
draftHosts?: string[];
|
|
237
267
|
};
|
|
238
268
|
/** The private key that decrypts `secret` blocks. */
|
|
239
269
|
secrets?: { key?: string };
|
|
240
|
-
/**
|
|
270
|
+
/**
|
|
271
|
+
* Your site ID (Studio's site slug): turns on hosted releases from
|
|
272
|
+
* `delivery.decocms.com`. Drafts don't need it.
|
|
273
|
+
*/
|
|
241
274
|
site?: string;
|
|
242
|
-
/**
|
|
275
|
+
/**
|
|
276
|
+
* Your site token (server-only secret): sends telemetry to the hosted Deco
|
|
277
|
+
* CMS collector. Releases and drafts don't use it. Needs `site`.
|
|
278
|
+
*/
|
|
243
279
|
token?: string;
|
|
244
280
|
}
|
|
245
281
|
|
|
@@ -280,13 +316,11 @@ export interface CMS {
|
|
|
280
316
|
forRelease(): Client;
|
|
281
317
|
/**
|
|
282
318
|
* A client reading the draft a pointer names: its changes, fetched from a
|
|
283
|
-
*
|
|
284
|
-
* `
|
|
285
|
-
* production content.
|
|
319
|
+
* draft host (`*.decocms.com` and loopback by default;
|
|
320
|
+
* `createCMS({ preview: { draftHosts } })` replaces the list), over this
|
|
321
|
+
* server's production content.
|
|
286
322
|
*/
|
|
287
323
|
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
324
|
/** Ask the content source for newer content now; never throws. */
|
|
291
325
|
update(): Promise<{ updated: boolean }>;
|
|
292
326
|
/**
|