sanoma 0.11.13 → 0.11.15

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.
@@ -1,66 +0,0 @@
1
- import { createHash, timingSafeEqual } from "node:crypto";
2
- import { errorMessage, readRootSnapshot } from "@sanoma-ai/workflows";
3
- import { describeConfig } from "@sanoma-ai/workflows/describe";
4
- import { SITES_BUNDLE_HEADER, SITES_BUNDLE_PATH } from "@sanoma-ai/workflows/shared";
5
- import { siteBuild } from "./sites.js";
6
- const digest = (text) => createHash("sha256").update(text).digest();
7
- /** An answer of the route, as JSON, never cached, and marked as the route's (`SITES_BUNDLE_HEADER`). */
8
- const answered = (status, body) => new Response(body, {
9
- status,
10
- headers: { "content-type": "application/json", "cache-control": "no-store", [SITES_BUNDLE_HEADER]: "1" },
11
- });
12
- /**
13
- * `GET /__sanoma/sites-bundle` with the instance token: the bundle of the public sites the
14
- * Cloudflare host's Worker serves (`buildWorker` in `@sanoma-ai/app/build`), which a deploy
15
- * downloads once the container answers. Built on the first ask, in the background: 202 while it
16
- * builds, then 200 with the bundle as JSON; 404 when no site is the Worker's to serve (each is
17
- * private, without a domain, or has a login). A failed build answers 500 with why, once, and the
18
- * next ask builds again.
19
- */
20
- export function sitesBundleRoute(config, { root, domains, token, log }) {
21
- const expected = digest(`Bearer ${token}`);
22
- let building;
23
- let answer;
24
- const build = async () => {
25
- const sites = await siteBuild(root);
26
- const described = describeConfig(config);
27
- const description = {
28
- ...described,
29
- sites: described.sites.map((site) => (domains[site.name] ? { ...site, domain: domains[site.name] } : site)),
30
- };
31
- const bundle = await sites?.buildWorker(root, {
32
- configFile: config.file,
33
- description,
34
- snapshot: readRootSnapshot(config),
35
- log,
36
- });
37
- if (bundle)
38
- log(`built the sites bundle for the Worker: ${bundle.sites.join(", ")}`);
39
- answer = bundle
40
- ? { status: 200, body: JSON.stringify(bundle) }
41
- : { status: 404, body: JSON.stringify({ error: "no public site without a login has a domain" }) };
42
- };
43
- return {
44
- method: "GET",
45
- path: SITES_BUNDLE_PATH,
46
- async handle(request) {
47
- if (!timingSafeEqual(digest(request.headers.get("authorization") ?? ""), expected)) {
48
- return answered(401, JSON.stringify({ error: "the token is not this instance's SANOMA_WAKEUP_TOKEN" }));
49
- }
50
- if (answer) {
51
- const { status, body } = answer;
52
- if (status === 500)
53
- answer = undefined;
54
- return answered(status, body);
55
- }
56
- building ??= build()
57
- .catch((err) => {
58
- log(`building the sites bundle for the Worker failed: ${errorMessage(err)}`);
59
- answer = { status: 500, body: JSON.stringify({ error: errorMessage(err) }) };
60
- })
61
- .finally(() => (building = undefined));
62
- return answered(202, JSON.stringify({ building: true }));
63
- },
64
- };
65
- }
66
- //# sourceMappingURL=sites-bundle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sites-bundle.js","sourceRoot":"","sources":["../src/sites-bundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAqB,MAAM,sBAAsB,CAAC;AACzF,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAYvC,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;AAE5E,wGAAwG;AACxG,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAE,IAAY,EAAE,EAAE,CAChD,IAAI,QAAQ,CAAC,IAAI,EAAE;IACjB,MAAM;IACN,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC,mBAAmB,CAAC,EAAE,GAAG,EAAE;CACzG,CAAC,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