@homepages/concrete 12.0.0 → 13.0.1
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/CHANGELOG.md +192 -0
- package/README.md +8 -10
- package/codemods/fixtures-are-data.mjs +7 -0
- package/codemods/fixtures-list-properties.mjs +6 -0
- package/codemods/manifest.json +15 -0
- package/codemods/steps/fixtures-list-properties.mjs +16 -0
- package/codemods/steps/fixtures-to-data.mjs +41 -0
- package/dist/artifact/playground/client/assets/archivo-latin-ext-wght-normal-C4zznr8T.woff2 +0 -0
- package/dist/artifact/playground/client/assets/archivo-latin-wght-normal-E0tuGl4L.woff2 +0 -0
- package/dist/artifact/playground/client/assets/archivo-vietnamese-wght-normal-XAtsl5Q_.woff2 +0 -0
- package/dist/artifact/playground/client/assets/index-Bmvcss4B.js +1338 -0
- package/dist/artifact/playground/client/assets/index-C01UCAWD.css +1 -0
- package/dist/artifact/playground/client/index.html +2 -2
- package/dist/artifact/playground/client/island-canvas-host.mjs +1 -1
- package/dist/artifact/playground/host.mjs +110 -59
- package/dist/base.css +2 -2
- package/dist/cli/build/icons.js +1 -1
- package/dist/cli/build/index.js +11 -10
- package/dist/cli/build/manifest.js +44 -0
- package/dist/cli/build/record.js +123 -0
- package/dist/cli/build/sections.js +28 -18
- package/dist/cli/build/source.js +1 -1
- package/dist/cli/build/static.js +8 -5
- package/dist/cli/build/template-build.js +614 -0
- package/dist/cli/check/analyze.js +18 -1
- package/dist/cli/check/load-workspace.js +2 -2
- package/dist/cli/check/portable-names.js +1 -1
- package/dist/cli/check/render/corpus.js +119 -0
- package/dist/cli/check/render/invariants.js +1 -0
- package/dist/cli/check/stages/bundles.js +15 -18
- package/dist/cli/check/stages/composition.js +8 -25
- package/dist/cli/check/stages/fixtures.js +14 -10
- package/dist/cli/check/stages/logic.js +7 -23
- package/dist/cli/check/stages/render.js +12 -14
- package/dist/cli/check/stages/sections.js +22 -66
- package/dist/cli/check/stages/stylesheet.js +4 -26
- package/dist/cli/check/stages/workspace.js +27 -22
- package/dist/cli/commands.js +51 -23
- package/dist/cli/currency/preamble.js +1 -1
- package/dist/cli/currency/resolve-latest.js +3 -2
- package/dist/cli/dev/capture-browser.js +26 -0
- package/dist/cli/dev/fixture-schema.js +441 -0
- package/dist/cli/dev/folder-files.js +244 -0
- package/dist/cli/dev/index.js +7 -3
- package/dist/cli/dev/playground-server.js +34 -0
- package/dist/cli/dev/section-ladders.js +76 -0
- package/dist/cli/dev/server.js +120 -304
- package/dist/cli/install/background.js +16 -0
- package/dist/cli/install/index.js +45 -0
- package/dist/cli/install/tools.js +27 -0
- package/dist/cli/media/derive.js +19 -13
- package/dist/cli/media/deriver-plugin.js +14 -3
- package/dist/cli/property/fixture-list.js +46 -0
- package/dist/cli/property/index.js +12 -9
- package/dist/cli/property/library.js +12 -10
- package/dist/cli/publish/artifact.js +90 -0
- package/dist/cli/publish/captures.js +61 -0
- package/dist/cli/publish/fixtures.js +17 -0
- package/dist/cli/publish/index.js +10 -18
- package/dist/cli/{build → publish}/playground.js +3 -3
- package/dist/cli/publish/report.js +15 -33
- package/dist/cli/upgrade/codemod.d.ts +14 -0
- package/dist/cli/upgrade/fixture-conversion.d.ts +11 -0
- package/dist/cli/upgrade/fixture-conversion.js +54 -0
- package/dist/cli/upgrade/fixture-modules.js +125 -0
- package/dist/cli/upgrade/fixtures-to-data.d.ts +40 -0
- package/dist/cli/upgrade/fixtures-to-data.js +498 -0
- package/dist/cli/upgrade/index.js +18 -2
- package/dist/cli/upgrade/legacy-fixtures.d.ts +34 -0
- package/dist/cli/upgrade/legacy-fixtures.js +22 -0
- package/dist/cli/upgrade/stage.js +1 -1
- package/dist/cli/workspace-fixtures.js +80 -0
- package/dist/cli.js +1 -0
- package/dist/css/compile.js +9 -3
- package/dist/fixtures/bundle-rule.js +16 -16
- package/dist/fixtures/media-plugin.js +12 -33
- package/dist/fixtures/synthesize-empties.js +3 -2
- package/dist/index.d.ts +7 -7
- package/dist/{playground-island-runtime.d.ts → island-runtime.d.ts} +1 -2
- package/dist/{playground-island-runtime.js → island-runtime.js} +1 -2
- package/dist/islands/client-module.js +1 -1
- package/dist/{cli/dev → islands}/tsconfig-paths.js +2 -14
- package/dist/islands/wrap.js +40 -0
- package/dist/node_modules/.pnpm/acorn@8.18.0/node_modules/acorn/dist/acorn.js +5119 -0
- package/dist/packages/external/concrete/package.js +1 -1
- package/dist/packages/internal/bundle-evaluation/dist/cache.js +36 -0
- package/dist/packages/internal/bundle-evaluation/dist/evaluate.js +174 -0
- package/dist/packages/internal/bundle-evaluation/dist/index.js +5 -0
- package/dist/packages/internal/bundle-evaluation/dist/section-code.js +10 -0
- package/dist/packages/internal/capture-settle/dist/index.js +2 -2
- package/dist/packages/internal/capture-settle/dist/settle.js +88 -13
- package/dist/packages/internal/code-fingerprint/dist/index.js +57 -0
- package/dist/packages/internal/content-doc-ops/dist/index.js +176 -0
- package/dist/packages/internal/content-doc-ops/dist/made-rows.js +15 -0
- package/dist/packages/internal/deliverable-reads/dist/bootstrap.js +81 -0
- package/dist/packages/internal/deliverable-reads/dist/display.js +21 -0
- package/dist/packages/internal/deliverable-reads/dist/format.js +15 -0
- package/dist/packages/internal/deliverable-reads/dist/index.js +7 -0
- package/dist/packages/internal/deliverable-reads/dist/pages.js +29 -0
- package/dist/packages/internal/deliverable-reads/dist/requirements.js +72 -0
- package/dist/{cli/capture → packages/internal/download-files/dist}/bundle.js +8 -4
- package/dist/packages/internal/download-files/dist/capture-origin.js +126 -0
- package/dist/packages/internal/download-files/dist/capture-routes.js +139 -0
- package/dist/packages/internal/download-files/dist/capture-shell.js +38 -0
- package/dist/packages/internal/download-files/dist/capture.js +74 -0
- package/dist/packages/internal/download-files/dist/egress-watch.js +38 -0
- package/dist/packages/internal/download-files/dist/files.js +7 -0
- package/dist/packages/internal/download-files/dist/finish.js +35 -0
- package/dist/packages/internal/download-files/dist/fleet.js +94 -0
- package/dist/packages/internal/download-files/dist/format.js +40 -0
- package/dist/packages/internal/download-files/dist/make.js +105 -0
- package/dist/packages/internal/download-files/dist/master-tally.js +32 -0
- package/dist/packages/internal/download-files/dist/names.js +24 -0
- package/dist/packages/internal/download-files/dist/pdf-boxes.js +33 -0
- package/dist/packages/internal/download-files/dist/pdf-image-placements.js +194 -0
- package/dist/packages/internal/download-files/dist/pdf-images.js +289 -0
- package/dist/packages/internal/file-store/dist/files.js +8 -0
- package/dist/packages/internal/file-store/dist/lru.js +40 -0
- package/dist/packages/internal/file-store/dist/refusal.js +12 -0
- package/dist/packages/internal/file-store/dist/trees.js +151 -0
- package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +1 -1
- package/dist/packages/internal/fill-bake/dist/compute-reads.js +47 -21
- package/dist/packages/internal/fill-bake/dist/index.js +5 -1
- package/dist/packages/internal/fill-bake/dist/item-merge.js +4 -3
- package/dist/packages/internal/fill-bake/dist/resolve-instance.js +9 -0
- package/dist/packages/internal/fill-bake/dist/resolve.js +3 -0
- package/dist/packages/internal/fill-bake/dist/round-trip.js +2 -0
- package/dist/packages/internal/fill-bake/dist/strip.js +6 -0
- package/dist/packages/internal/fill-vocabulary/dist/holder.js +1 -1
- package/dist/packages/internal/fill-vocabulary/dist/resolved-decision.js +1 -1
- package/dist/packages/internal/fill-vocabulary/dist/verbs.js +1 -1
- package/dist/packages/internal/island-runtime/dist/index.js +1 -10
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.d.ts +5 -0
- package/dist/packages/internal/lead-fields/dist/ingest.js +72 -0
- package/dist/packages/internal/media-resolution/dist/video.js +6 -2
- package/dist/packages/internal/page-render/dist/addresses.js +57 -0
- package/dist/packages/internal/page-render/dist/index.js +6 -0
- package/dist/packages/internal/page-render/dist/kept.js +30 -0
- package/dist/packages/internal/page-render/dist/nav.js +42 -0
- package/dist/packages/internal/page-render/dist/render.js +152 -0
- package/dist/packages/internal/page-shell/dist/assemble.js +161 -0
- package/dist/packages/internal/page-shell/dist/escape.js +10 -0
- package/dist/packages/internal/page-shell/dist/frame.js +23 -0
- package/dist/packages/internal/page-shell/dist/index.js +26 -0
- package/dist/packages/internal/playground/dist/build-fingerprint.js +18 -0
- package/dist/packages/internal/playground/dist/fixture-conversions/list-names-properties.js +76 -0
- package/dist/packages/internal/playground/dist/fixture-formats.d.ts +37 -0
- package/dist/packages/internal/playground/dist/fixture-formats.js +20 -0
- package/dist/packages/internal/playground/dist/host/bootstrap.js +108 -0
- package/dist/packages/internal/playground/dist/host/built.js +202 -0
- package/dist/packages/internal/playground/dist/host/catalog-fixture.js +53 -0
- package/dist/packages/internal/playground/dist/host/download.js +34 -0
- package/dist/packages/internal/playground/dist/host/env.js +11 -0
- package/dist/packages/internal/playground/dist/host/everywhere-saves.js +353 -0
- package/dist/packages/internal/playground/dist/host/fixture-addresses.js +52 -0
- package/dist/packages/internal/playground/dist/host/fixture-documents.js +494 -0
- package/dist/packages/internal/playground/dist/host/fixture-operations.js +364 -0
- package/dist/packages/internal/playground/dist/host/fixture-units.js +93 -0
- package/dist/{fixtures → packages/internal/playground/dist/host}/image-dimensions.js +1 -1
- package/dist/packages/internal/playground/dist/host/leads.js +41 -0
- package/dist/packages/internal/playground/dist/host/media-saves.js +309 -0
- package/dist/{fixtures → packages/internal/playground/dist/host}/media-store.js +79 -26
- package/dist/packages/internal/playground/dist/host/overridable.js +9 -0
- package/dist/packages/internal/playground/dist/host/owned-saves.js +203 -0
- package/dist/{playground → packages/internal/playground/dist}/host/page-state.js +1 -1
- package/dist/packages/internal/playground/dist/host/program.js +54 -0
- package/dist/packages/internal/playground/dist/host/property-derive.js +216 -0
- package/dist/packages/internal/playground/dist/host/property-saves.js +74 -0
- package/dist/{fixtures → packages/internal/playground/dist/host}/property.js +88 -229
- package/dist/packages/internal/playground/dist/host/provenance.js +49 -0
- package/dist/packages/internal/playground/dist/host/resolve.js +553 -0
- package/dist/packages/internal/playground/dist/host/row-images.js +41 -0
- package/dist/{fixtures → packages/internal/playground/dist/host}/rows.js +1 -1
- package/dist/packages/internal/playground/dist/host/save.js +429 -0
- package/dist/packages/internal/playground/dist/host/serve.js +952 -0
- package/dist/packages/internal/playground/dist/host/site.js +79 -0
- package/dist/packages/internal/playground/dist/host/slots.js +202 -0
- package/dist/packages/internal/playground/dist/host/stated-content.js +93 -0
- package/dist/packages/internal/playground/dist/host/stored-fixtures.js +135 -0
- package/dist/packages/internal/playground/dist/host/violations.js +7 -0
- package/dist/packages/internal/playground/dist/jobs/lanes.js +24 -0
- package/dist/packages/internal/playground/dist/jobs/memory-queue.js +112 -0
- package/dist/packages/internal/playground/dist/jobs/probe.js +37 -0
- package/dist/packages/internal/playground/dist/jobs/queue.js +28 -0
- package/dist/packages/internal/playground/dist/jobs/runner.js +207 -0
- package/dist/packages/internal/playground/dist/layout.js +14 -0
- package/dist/packages/internal/playground/dist/platform.js +33 -0
- package/dist/packages/internal/playground/dist/server/changes.js +57 -0
- package/dist/packages/internal/playground/dist/server/crop.js +47 -0
- package/dist/packages/internal/playground/dist/server/derived-files.js +88 -0
- package/dist/packages/internal/playground/dist/server/download.js +158 -0
- package/dist/{cli/dev → packages/internal/playground/dist/server}/http.js +4 -12
- package/dist/packages/internal/playground/dist/server/jobs.js +29 -0
- package/dist/{cli/dev → packages/internal/playground/dist/server}/listen.js +4 -11
- package/dist/packages/internal/playground/dist/server/playground-server.js +424 -0
- package/dist/{cli/dev → packages/internal/playground/dist/server}/request-error.js +1 -1
- package/dist/packages/internal/playground/dist/server/size-ladders.js +170 -0
- package/dist/packages/internal/playground/dist/server/verification.js +75 -0
- package/dist/packages/internal/playground/dist/server/verify-build.js +139 -0
- package/dist/packages/internal/playground/dist/wire.js +78 -0
- package/dist/packages/internal/property-facts/dist/registry-facts.js +1 -1
- package/dist/packages/internal/section-contracts/dist/fill-verb-contract.js +1 -1
- package/dist/packages/internal/section-contracts/dist/reads-acyclic-contract.js +1 -1
- package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +1 -1
- package/dist/packages/internal/site-files/dist/head.js +59 -0
- package/dist/packages/internal/site-files/dist/index.js +4 -0
- package/dist/packages/internal/site-files/dist/site.js +211 -0
- package/dist/packages/internal/static-assets-binding/dist/index.js +32 -0
- package/dist/packages/internal/static-assets-binding/dist/section-asset-url.js +38 -5
- package/dist/packages/internal/template-artifact/dist/asset-mime.js +8 -1
- package/dist/packages/internal/template-artifact/dist/build.js +148 -0
- package/dist/packages/internal/template-artifact/dist/composition.js +62 -0
- package/dist/packages/internal/template-artifact/dist/index.js +2 -2
- package/dist/packages/internal/template-artifact/dist/layout.js +48 -12
- package/dist/packages/internal/template-artifact/dist/manifest.js +3 -10
- package/dist/packages/internal/template-artifact/dist/verify.js +51 -31
- package/dist/packages/internal/template-contracts/dist/address-value.js +6 -1
- package/dist/packages/internal/template-contracts/dist/content-categories.js +10 -1
- package/dist/packages/internal/template-contracts/dist/fact-compute.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/fact-keys.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/fact-registry.d.ts +3 -3
- package/dist/packages/internal/template-contracts/dist/fact-registry.js +59 -32
- package/dist/packages/internal/template-contracts/dist/fill-spec.js +14 -1
- package/dist/packages/internal/template-contracts/dist/list.d.ts +3 -3
- package/dist/packages/internal/template-contracts/dist/media-candidates.js +67 -2
- package/dist/packages/internal/template-contracts/dist/media-offer.js +180 -0
- package/dist/packages/internal/template-contracts/dist/object.d.ts +2 -2
- package/dist/packages/internal/template-contracts/dist/primitive-descriptors.js +9 -2
- package/dist/packages/internal/template-contracts/dist/read-graph.js +36 -2
- package/dist/packages/internal/template-contracts/dist/ref-locate.js +16 -1
- package/dist/packages/internal/template-contracts/dist/registry-facts.d.ts +9 -10
- package/dist/packages/internal/template-contracts/dist/registry-facts.js +12 -1
- package/dist/packages/internal/template-contracts/dist/registry-graph.js +112 -0
- package/dist/packages/internal/template-contracts/dist/registry-shape.js +15 -2
- package/dist/packages/internal/template-contracts/dist/require-graph.js +300 -0
- package/dist/packages/internal/template-contracts/dist/row-ref.d.ts +3 -3
- package/dist/packages/internal/template-contracts/dist/row.d.ts +3 -3
- package/dist/packages/internal/template-contracts/dist/runtime-values.d.ts +1 -1
- package/dist/{schema → packages/internal/template-contracts/dist}/section-nav.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/slot-builders.d.ts +4 -4
- package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +3 -1
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +24 -1
- package/dist/packages/internal/template-contracts/dist/slot-overrides.js +26 -1
- package/dist/packages/internal/template-contracts/dist/slot-ref.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/slot-types.js +1 -1
- package/dist/packages/internal/template-contracts/dist/slot-value.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/table-members.js +7 -2
- package/dist/packages/internal/template-contracts/dist/video-value.d.ts +1 -1
- package/dist/packages/internal/upload-formats/dist/heic.js +35 -0
- package/dist/packages/internal/upload-formats/dist/index.js +80 -0
- package/dist/packages/internal/upload-formats/dist/magic-bytes.js +293 -0
- package/dist/platform/paths.js +1 -0
- package/dist/platform/process.js +49 -1
- package/dist/rules/registry.js +27 -3
- package/dist/schema/fact.d.ts +2 -2
- package/dist/schema/facts-view.d.ts +1 -1
- package/dist/schema/section-props.d.ts +1 -1
- package/dist/schema/section-schema.d.ts +1 -1
- package/dist/schema/section-schema.js +1 -0
- package/dist/section/declare.d.ts +1 -1
- package/dist/section/discovery.js +6 -2
- package/dist/section/publish-shape.js +38 -0
- package/dist/section/section.d.ts +1 -1
- package/dist/template/define-template.d.ts +14 -4
- package/dist/template/define-template.js +2 -0
- package/dist/template/logic-shim.d.ts +1 -1
- package/dist/template/materialize.js +1 -1
- package/dist/template/running-copy.js +0 -1
- package/dist/template/section-reads.js +1 -1
- package/guide/reference/cli/INDEX.md +6 -5
- package/guide/reference/cli/build.md +10 -8
- package/guide/reference/cli/check.md +4 -2
- package/guide/reference/cli/dev.md +6 -2
- package/guide/reference/cli/install.md +41 -0
- package/guide/reference/cli/property-add.md +5 -4
- package/guide/reference/cli/property-list.md +2 -2
- package/guide/reference/cli/publish.md +5 -5
- package/guide/reference/cli/upgrade.md +1 -1
- package/guide/reference/rules/INDEX.md +8 -4
- package/package.json +14 -30
- package/dist/artifact/playground/client/assets/index-BcLGpWLR.js +0 -1266
- package/dist/artifact/playground/client/assets/index-CxWPYOH2.css +0 -1
- package/dist/cli/build/artifact.js +0 -220
- package/dist/cli/build/captures.js +0 -48
- package/dist/cli/build/fixtures.js +0 -92
- package/dist/cli/capture/capture-browser.js +0 -37
- package/dist/cli/capture/capture.js +0 -115
- package/dist/cli/check/render/inputs.js +0 -60
- package/dist/cli/check/render/nav.js +0 -31
- package/dist/cli/dev/crop.js +0 -20
- package/dist/cli/dev/fixture-ladders.js +0 -96
- package/dist/cli/dev/hmr.js +0 -26
- package/dist/cli/dev/islands.js +0 -234
- package/dist/cli/dev/load-template.js +0 -52
- package/dist/cli/dev/vite.js +0 -114
- package/dist/cli/dev/workspace-reader.js +0 -249
- package/dist/cli/publish/freshness.js +0 -64
- package/dist/fixtures/brand.d.ts +0 -4
- package/dist/fixtures/brand.js +0 -8
- package/dist/fixtures/load.js +0 -159
- package/dist/fixtures/resolve.js +0 -392
- package/dist/fixtures.d.ts +0 -429
- package/dist/fixtures.js +0 -23
- package/dist/packages/internal/canvas-core/dist/island-host.js +0 -62
- package/dist/packages/internal/canvas-core/dist/island-shields.js +0 -30
- package/dist/playground/canvas-island-host.d.ts +0 -11
- package/dist/playground/canvas-island-host.js +0 -29
- package/dist/playground/canvas-markers.js +0 -14
- package/dist/playground/host/paths.js +0 -8
- package/dist/playground/layout.js +0 -17
- package/dist/playground/wire.js +0 -28
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { dataFixtureId, propertyName, resolveReference } from "./fixture-documents.js";
|
|
2
|
+
import { contentFixtureUnit, propertyUnit, readFixtureListing, unitOfPath, unitsOf } from "./fixture-units.js";
|
|
3
|
+
import { HostRefusal } from "./env.js";
|
|
4
|
+
import { documentText } from "./save.js";
|
|
5
|
+
|
|
6
|
+
//#region ../../internal/playground/dist/host/fixture-operations.js
|
|
7
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
const NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
9
|
+
const FILE_MEMBERS = [
|
|
10
|
+
"file",
|
|
11
|
+
"poster",
|
|
12
|
+
"preview"
|
|
13
|
+
];
|
|
14
|
+
const NEW_PROPERTY_DOCUMENT = "property.json";
|
|
15
|
+
const EMPTY_PROPERTY = {
|
|
16
|
+
listing_intent: null,
|
|
17
|
+
description: null
|
|
18
|
+
};
|
|
19
|
+
function folderReads(view) {
|
|
20
|
+
return {
|
|
21
|
+
list: async (folder) => (await view.list(folder)).map((entry) => entry.path),
|
|
22
|
+
readBytes: async (path) => (await view.readBytes(path))?.bytes ?? null
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function parseFixtureOperation(text) {
|
|
26
|
+
let body;
|
|
27
|
+
try {
|
|
28
|
+
body = JSON.parse(text);
|
|
29
|
+
} catch (err) {
|
|
30
|
+
throw new HostRefusal(400, `request body is not JSON: ${err instanceof Error ? err.message : String(err)}`);
|
|
31
|
+
}
|
|
32
|
+
if (!isRecord(body)) throw new HostRefusal(400, "A fixture operation is a JSON object.");
|
|
33
|
+
const { op, kind, name } = body;
|
|
34
|
+
if (op !== "new" && op !== "rename" && op !== "duplicate" && op !== "delete") throw new HostRefusal(400, "A fixture operation's op is \"new\", \"rename\", \"duplicate\" or \"delete\".");
|
|
35
|
+
if (kind !== "property" && kind !== "content") throw new HostRefusal(400, "A fixture operation's kind is \"property\" or \"content\".");
|
|
36
|
+
if (typeof name !== "string") throw new HostRefusal(400, "A fixture operation names the fixture.");
|
|
37
|
+
if (op === "new") {
|
|
38
|
+
if (kind === "property") return {
|
|
39
|
+
op,
|
|
40
|
+
kind,
|
|
41
|
+
name
|
|
42
|
+
};
|
|
43
|
+
if (typeof body.property !== "string") throw new HostRefusal(400, "A new content fixture names the property it is on.");
|
|
44
|
+
return {
|
|
45
|
+
op,
|
|
46
|
+
kind,
|
|
47
|
+
name,
|
|
48
|
+
property: body.property
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (op === "delete") return {
|
|
52
|
+
op,
|
|
53
|
+
kind,
|
|
54
|
+
name
|
|
55
|
+
};
|
|
56
|
+
if (typeof body.to !== "string") throw new HostRefusal(400, `A ${op} names the new name, as "to".`);
|
|
57
|
+
return {
|
|
58
|
+
op,
|
|
59
|
+
kind,
|
|
60
|
+
name,
|
|
61
|
+
to: body.to
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const folderOf = (path) => path.slice(0, path.lastIndexOf("/") + 1);
|
|
65
|
+
const listed = (folder) => folder.replace(/\/$/, "");
|
|
66
|
+
async function fixtureOperation(list, reads, operation) {
|
|
67
|
+
if (list === null) throw new HostRefusal(409, "This template names no fixture list, so it has no fixtures to change; name one in template.ts.");
|
|
68
|
+
const fixtures = await read(list, reads);
|
|
69
|
+
const { op, kind, name } = operation;
|
|
70
|
+
if (operation.op === "new") {
|
|
71
|
+
admitName(fixtures, kind, name);
|
|
72
|
+
return operation.kind === "property" ? newProperty(fixtures, name) : newContent(fixtures, name, operation.property);
|
|
73
|
+
}
|
|
74
|
+
if (op === "delete") return kind === "property" ? deleteProperty(fixtures, name) : deleteContent(fixtures, name);
|
|
75
|
+
const to = operation.to;
|
|
76
|
+
admitName(fixtures, kind, to);
|
|
77
|
+
if (op === "rename") return kind === "property" ? renameProperty(fixtures, name, to) : renameContent(fixtures, name, to);
|
|
78
|
+
return kind === "property" ? duplicateProperty(fixtures, name, to) : duplicateContent(fixtures, name, to);
|
|
79
|
+
}
|
|
80
|
+
async function read(list, reads) {
|
|
81
|
+
const text = await reads.readText(list);
|
|
82
|
+
if (text === null) throw new HostRefusal(409, `The fixture list "${list}" is gone; reload the playground.`);
|
|
83
|
+
let doc;
|
|
84
|
+
try {
|
|
85
|
+
doc = JSON.parse(text);
|
|
86
|
+
} catch (err) {
|
|
87
|
+
throw new HostRefusal(409, `The fixture list "${list}" does not parse as JSON (${err instanceof Error ? err.message : String(err)}); fix it, then try again.`);
|
|
88
|
+
}
|
|
89
|
+
if (!isRecord(doc) || !Array.isArray(doc["properties"]) || !Array.isArray(doc["fixtures"])) throw new HostRefusal(409, `The fixture list "${list}" does not list properties and fixtures; fix it, then try again.`);
|
|
90
|
+
const listing = await readFixtureListing((path) => reads.readText(path), list);
|
|
91
|
+
return {
|
|
92
|
+
reads,
|
|
93
|
+
list: {
|
|
94
|
+
path: list,
|
|
95
|
+
doc,
|
|
96
|
+
properties: doc["properties"],
|
|
97
|
+
fixtures: doc["fixtures"]
|
|
98
|
+
},
|
|
99
|
+
listing,
|
|
100
|
+
units: unitsOf(listing)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const KIND_WORDS = {
|
|
104
|
+
property: "property",
|
|
105
|
+
content: "content fixture"
|
|
106
|
+
};
|
|
107
|
+
function admitName({ listing }, kind, name) {
|
|
108
|
+
if (!NAME.test(name)) throw new HostRefusal(400, `"${name}" is not a name: a ${KIND_WORDS[kind]}'s name is lowercase letters, digits and dashes, as "lake-house" is.`);
|
|
109
|
+
if (kind === "property") {
|
|
110
|
+
if (listing.properties.some((p) => propertyName(p) === name)) throw new HostRefusal(409, `There is already a property "${name}".`);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const holder = listing.fixtures.find((f) => dataFixtureId(f) === name);
|
|
114
|
+
if (holder === void 0) return;
|
|
115
|
+
const on = listing.named.get(holder);
|
|
116
|
+
throw new HostRefusal(409, `There is already a content fixture "${name}"${on === void 0 ? "" : `, on the property "${propertyName(on)}"`}.`);
|
|
117
|
+
}
|
|
118
|
+
async function admitPlace({ reads }, paths, folders) {
|
|
119
|
+
for (const path of paths) if (await reads.readText(path) !== null) throw new HostRefusal(409, `"${path}" is already there; move it, or choose another name.`);
|
|
120
|
+
for (const folder of folders) {
|
|
121
|
+
const held = await reads.list(listed(folder));
|
|
122
|
+
if (held.length > 0) throw new HostRefusal(409, `"${folder}" already holds "${held[0]}"; move it, or choose another name.`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function propertyNamed({ listing }, name) {
|
|
126
|
+
const property = listing.properties.find((p) => propertyName(p) === name);
|
|
127
|
+
if (property === void 0) throw new HostRefusal(404, `There is no property "${name}" (have: ${listing.properties.map(propertyName).join(", ") || "none"}).`);
|
|
128
|
+
return property;
|
|
129
|
+
}
|
|
130
|
+
function contentNamed({ listing }, name) {
|
|
131
|
+
const fixture = listing.fixtures.find((f) => dataFixtureId(f) === name);
|
|
132
|
+
if (fixture === void 0) throw new HostRefusal(404, `There is no content fixture "${name}" (have: ${listing.fixtures.map(dataFixtureId).join(", ") || "none"}).`);
|
|
133
|
+
return fixture;
|
|
134
|
+
}
|
|
135
|
+
const contentOn = ({ listing }, property) => listing.fixtures.filter((f) => listing.named.get(f) === property);
|
|
136
|
+
function propertyOfContent(fixtures, fixture) {
|
|
137
|
+
const property = fixtures.listing.named.get(fixture);
|
|
138
|
+
if (property === void 0) throw new HostRefusal(409, `The content fixture "${dataFixtureId(fixture)}" names no property that resolves; fix "${fixture}", then try again.`);
|
|
139
|
+
return propertyName(property);
|
|
140
|
+
}
|
|
141
|
+
async function filesOf({ reads, units }, unit) {
|
|
142
|
+
const under = (await reads.list(listed(unit.folder))).filter((path) => {
|
|
143
|
+
const owner = unitOfPath(path, units);
|
|
144
|
+
return owner !== null && owner.kind === unit.kind && owner.key === unit.key;
|
|
145
|
+
});
|
|
146
|
+
return unit.kind === "fixture" ? [unit.key, ...under] : under;
|
|
147
|
+
}
|
|
148
|
+
function entryFor(list, path) {
|
|
149
|
+
const folder = folderOf(list.path);
|
|
150
|
+
if (!path.startsWith(folder)) throw new HostRefusal(409, `"${path}" is outside the fixture list's folder, so the list cannot name it.`);
|
|
151
|
+
return path.slice(folder.length);
|
|
152
|
+
}
|
|
153
|
+
function replaced(list, entries, path, entry) {
|
|
154
|
+
return entries.flatMap((stated) => {
|
|
155
|
+
const ref = resolveReference(list.path, stated);
|
|
156
|
+
if (!("path" in ref) || ref.path !== path) return [stated];
|
|
157
|
+
return entry === null ? [] : [entry];
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
function listWrite(list, members) {
|
|
161
|
+
return {
|
|
162
|
+
path: list.path,
|
|
163
|
+
text: documentText({
|
|
164
|
+
...list.doc,
|
|
165
|
+
properties: members.properties ?? list.properties,
|
|
166
|
+
fixtures: members.fixtures ?? list.fixtures
|
|
167
|
+
})
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
async function documentAt({ reads }, path) {
|
|
171
|
+
const text = await reads.readText(path);
|
|
172
|
+
if (text === null) throw new HostRefusal(409, `"${path}" is gone; reload the playground.`);
|
|
173
|
+
let doc;
|
|
174
|
+
try {
|
|
175
|
+
doc = JSON.parse(text);
|
|
176
|
+
} catch (err) {
|
|
177
|
+
throw new HostRefusal(409, `"${path}" does not parse as JSON (${err instanceof Error ? err.message : String(err)}); fix the file, then try again.`);
|
|
178
|
+
}
|
|
179
|
+
if (!isRecord(doc)) throw new HostRefusal(409, `"${path}" is not a JSON object; fix the file, then try again.`);
|
|
180
|
+
return doc;
|
|
181
|
+
}
|
|
182
|
+
function withOwnFolder(doc, file, from, to) {
|
|
183
|
+
if (!Array.isArray(doc["files"])) return doc;
|
|
184
|
+
const base = folderOf(file);
|
|
185
|
+
const files = doc["files"].map((entry) => {
|
|
186
|
+
if (!isRecord(entry)) return entry;
|
|
187
|
+
const next = { ...entry };
|
|
188
|
+
for (const member of FILE_MEMBERS) {
|
|
189
|
+
const ref = resolveReference(file, entry[member]);
|
|
190
|
+
if ("path" in ref && ref.path.startsWith(from)) next[member] = `${to}${ref.path.slice(from.length)}`.slice(base.length);
|
|
191
|
+
}
|
|
192
|
+
return next;
|
|
193
|
+
});
|
|
194
|
+
return {
|
|
195
|
+
...doc,
|
|
196
|
+
files
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function propertyReference(fixture, property) {
|
|
200
|
+
const folder = folderOf(fixture);
|
|
201
|
+
if (!property.startsWith(folder)) throw new HostRefusal(409, `"${property}" is not inside the folder of "${fixture}", so the content fixture cannot name it.`);
|
|
202
|
+
return property.slice(folder.length);
|
|
203
|
+
}
|
|
204
|
+
const moves = (files, from, to) => files.map((path) => ({
|
|
205
|
+
path: `${to}${path.slice(from.length)}`,
|
|
206
|
+
from: path
|
|
207
|
+
}));
|
|
208
|
+
async function copies({ reads }, files, from, to) {
|
|
209
|
+
const writes = [];
|
|
210
|
+
for (const path of files) {
|
|
211
|
+
const bytes = await reads.readBytes(path);
|
|
212
|
+
if (bytes === null) throw new HostRefusal(409, `"${path}" is gone; reload the playground.`);
|
|
213
|
+
writes.push({
|
|
214
|
+
path: `${to}${path.slice(from.length)}`,
|
|
215
|
+
bytes
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
return writes;
|
|
219
|
+
}
|
|
220
|
+
const removals = (files) => files.map((path) => ({
|
|
221
|
+
path,
|
|
222
|
+
remove: true
|
|
223
|
+
}));
|
|
224
|
+
async function newProperty(fixtures, name) {
|
|
225
|
+
const folder = `${folderOf(fixtures.list.path)}properties/${name}/`;
|
|
226
|
+
const file = `${folder}${NEW_PROPERTY_DOCUMENT}`;
|
|
227
|
+
await admitPlace(fixtures, [], [folder]);
|
|
228
|
+
return {
|
|
229
|
+
writes: [{
|
|
230
|
+
path: file,
|
|
231
|
+
text: documentText(EMPTY_PROPERTY)
|
|
232
|
+
}, listWrite(fixtures.list, { properties: [...fixtures.list.properties, entryFor(fixtures.list, file)] })],
|
|
233
|
+
at: { property: name }
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
async function newContent(fixtures, name, on) {
|
|
237
|
+
const property = propertyNamed(fixtures, on);
|
|
238
|
+
const file = `${folderOf(fixtures.list.path)}${name}.json`;
|
|
239
|
+
const own = contentFixtureUnit(file).folder;
|
|
240
|
+
await admitPlace(fixtures, [file], [own]);
|
|
241
|
+
return {
|
|
242
|
+
writes: [{
|
|
243
|
+
path: file,
|
|
244
|
+
text: documentText({ property: propertyReference(file, property) })
|
|
245
|
+
}, listWrite(fixtures.list, { fixtures: [...fixtures.list.fixtures, entryFor(fixtures.list, file)] })],
|
|
246
|
+
at: {
|
|
247
|
+
property: on,
|
|
248
|
+
content: name
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
async function renameContent(fixtures, name, to) {
|
|
253
|
+
const file = contentNamed(fixtures, name);
|
|
254
|
+
const unit = contentFixtureUnit(file);
|
|
255
|
+
const next = `${folderOf(file)}${to}.json`;
|
|
256
|
+
const nextFolder = contentFixtureUnit(next).folder;
|
|
257
|
+
await admitPlace(fixtures, [next], [nextFolder]);
|
|
258
|
+
const doc = withOwnFolder(await documentAt(fixtures, file), file, unit.folder, nextFolder);
|
|
259
|
+
const own = (await filesOf(fixtures, unit)).filter((path) => path !== file);
|
|
260
|
+
return {
|
|
261
|
+
writes: [
|
|
262
|
+
{
|
|
263
|
+
path: next,
|
|
264
|
+
text: documentText(doc)
|
|
265
|
+
},
|
|
266
|
+
...moves(own, unit.folder, nextFolder),
|
|
267
|
+
{
|
|
268
|
+
path: file,
|
|
269
|
+
remove: true
|
|
270
|
+
},
|
|
271
|
+
listWrite(fixtures.list, { fixtures: replaced(fixtures.list, fixtures.list.fixtures, file, entryFor(fixtures.list, next)) })
|
|
272
|
+
],
|
|
273
|
+
at: {
|
|
274
|
+
property: propertyOfContent(fixtures, file),
|
|
275
|
+
content: to
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
async function renameProperty(fixtures, name, to) {
|
|
280
|
+
const file = propertyNamed(fixtures, name);
|
|
281
|
+
const unit = propertyUnit(file);
|
|
282
|
+
const nextFolder = `${folderOf(listed(unit.folder))}${to}/`;
|
|
283
|
+
const next = `${nextFolder}${file.slice(unit.folder.length)}`;
|
|
284
|
+
await admitPlace(fixtures, [], [nextFolder]);
|
|
285
|
+
const renamed = [];
|
|
286
|
+
for (const fixture of contentOn(fixtures, file)) {
|
|
287
|
+
const doc = await documentAt(fixtures, fixture);
|
|
288
|
+
renamed.push({
|
|
289
|
+
path: fixture,
|
|
290
|
+
text: documentText({
|
|
291
|
+
...doc,
|
|
292
|
+
property: propertyReference(fixture, next)
|
|
293
|
+
})
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
writes: [
|
|
298
|
+
...moves(await filesOf(fixtures, unit), unit.folder, nextFolder),
|
|
299
|
+
...renamed,
|
|
300
|
+
listWrite(fixtures.list, { properties: replaced(fixtures.list, fixtures.list.properties, file, entryFor(fixtures.list, next)) })
|
|
301
|
+
],
|
|
302
|
+
at: { property: to }
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
async function duplicateContent(fixtures, name, to) {
|
|
306
|
+
const file = contentNamed(fixtures, name);
|
|
307
|
+
const unit = contentFixtureUnit(file);
|
|
308
|
+
const next = `${folderOf(file)}${to}.json`;
|
|
309
|
+
const nextFolder = contentFixtureUnit(next).folder;
|
|
310
|
+
await admitPlace(fixtures, [next], [nextFolder]);
|
|
311
|
+
const doc = withOwnFolder(await documentAt(fixtures, file), file, unit.folder, nextFolder);
|
|
312
|
+
const own = (await filesOf(fixtures, unit)).filter((path) => path !== file);
|
|
313
|
+
return {
|
|
314
|
+
writes: [
|
|
315
|
+
{
|
|
316
|
+
path: next,
|
|
317
|
+
text: documentText(doc)
|
|
318
|
+
},
|
|
319
|
+
...await copies(fixtures, own, unit.folder, nextFolder),
|
|
320
|
+
listWrite(fixtures.list, { fixtures: [...fixtures.list.fixtures, entryFor(fixtures.list, next)] })
|
|
321
|
+
],
|
|
322
|
+
at: {
|
|
323
|
+
property: propertyOfContent(fixtures, file),
|
|
324
|
+
content: to
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
async function duplicateProperty(fixtures, name, to) {
|
|
329
|
+
const file = propertyNamed(fixtures, name);
|
|
330
|
+
const unit = propertyUnit(file);
|
|
331
|
+
const nextFolder = `${folderOf(listed(unit.folder))}${to}/`;
|
|
332
|
+
const next = `${nextFolder}${file.slice(unit.folder.length)}`;
|
|
333
|
+
await admitPlace(fixtures, [], [nextFolder]);
|
|
334
|
+
return {
|
|
335
|
+
writes: [...await copies(fixtures, await filesOf(fixtures, unit), unit.folder, nextFolder), listWrite(fixtures.list, { properties: [...fixtures.list.properties, entryFor(fixtures.list, next)] })],
|
|
336
|
+
at: { property: to }
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
async function deleteContent(fixtures, name) {
|
|
340
|
+
const file = contentNamed(fixtures, name);
|
|
341
|
+
const property = fixtures.listing.named.get(file);
|
|
342
|
+
return {
|
|
343
|
+
writes: [...removals(await filesOf(fixtures, contentFixtureUnit(file))), listWrite(fixtures.list, { fixtures: replaced(fixtures.list, fixtures.list.fixtures, file, null) })],
|
|
344
|
+
at: property === void 0 ? null : { property: propertyName(property) }
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
async function deleteProperty(fixtures, name) {
|
|
348
|
+
const file = propertyNamed(fixtures, name);
|
|
349
|
+
const on = contentOn(fixtures, file);
|
|
350
|
+
const removed = await filesOf(fixtures, propertyUnit(file));
|
|
351
|
+
for (const fixture of on) removed.push(...await filesOf(fixtures, contentFixtureUnit(fixture)));
|
|
352
|
+
let entries = fixtures.list.fixtures;
|
|
353
|
+
for (const fixture of on) entries = replaced(fixtures.list, entries, fixture, null);
|
|
354
|
+
return {
|
|
355
|
+
writes: [...removals(removed), listWrite(fixtures.list, {
|
|
356
|
+
properties: replaced(fixtures.list, fixtures.list.properties, file, null),
|
|
357
|
+
fixtures: entries
|
|
358
|
+
})],
|
|
359
|
+
at: null
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
//#endregion
|
|
364
|
+
export { fixtureOperation, folderReads, parseFixtureOperation };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { dataFixtureId, resolveReference } from "./fixture-documents.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../internal/playground/dist/host/fixture-units.js
|
|
4
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5
|
+
function folderOf(path) {
|
|
6
|
+
return path.slice(0, path.lastIndexOf("/") + 1);
|
|
7
|
+
}
|
|
8
|
+
async function readJson(read, path) {
|
|
9
|
+
const text = await read(path);
|
|
10
|
+
if (text === null) return null;
|
|
11
|
+
try {
|
|
12
|
+
const parsed = JSON.parse(text);
|
|
13
|
+
return isRecord(parsed) ? parsed : null;
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function resolvedEntries(list, member) {
|
|
19
|
+
const paths = [];
|
|
20
|
+
for (const entry of Array.isArray(member) ? member : []) {
|
|
21
|
+
const ref = resolveReference(list, entry);
|
|
22
|
+
if ("path" in ref && !paths.includes(ref.path)) paths.push(ref.path);
|
|
23
|
+
}
|
|
24
|
+
return paths;
|
|
25
|
+
}
|
|
26
|
+
async function readFixtureListing(read, list) {
|
|
27
|
+
const doc = await readJson(read, list);
|
|
28
|
+
const properties = resolvedEntries(list, doc?.["properties"]);
|
|
29
|
+
const fixtures = resolvedEntries(list, doc?.["fixtures"]);
|
|
30
|
+
const named = /* @__PURE__ */ new Map();
|
|
31
|
+
for (const fixture of fixtures) {
|
|
32
|
+
const property = await propertyOf(read, fixture);
|
|
33
|
+
if (property !== null) named.set(fixture, property);
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
list,
|
|
37
|
+
properties,
|
|
38
|
+
fixtures,
|
|
39
|
+
named
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async function propertyOf(read, fixture) {
|
|
43
|
+
const doc = await readJson(read, fixture);
|
|
44
|
+
if (doc === null) return null;
|
|
45
|
+
const ref = resolveReference(fixture, doc["property"]);
|
|
46
|
+
return "path" in ref ? ref.path : null;
|
|
47
|
+
}
|
|
48
|
+
function contentFixtureUnit(fixture) {
|
|
49
|
+
return {
|
|
50
|
+
kind: "fixture",
|
|
51
|
+
key: fixture,
|
|
52
|
+
folder: `${folderOf(fixture)}${dataFixtureId(fixture)}/`
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function propertyUnit(property) {
|
|
56
|
+
const folder = folderOf(property);
|
|
57
|
+
return {
|
|
58
|
+
kind: "property",
|
|
59
|
+
key: folder,
|
|
60
|
+
folder
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function unitsOf(listing) {
|
|
64
|
+
const units = /* @__PURE__ */ new Map();
|
|
65
|
+
for (const fixture of listing.fixtures) units.set(fixture, contentFixtureUnit(fixture));
|
|
66
|
+
for (const property of [...listing.properties, ...listing.named.values()]) {
|
|
67
|
+
const unit = propertyUnit(property);
|
|
68
|
+
if (!units.has(unit.key)) units.set(unit.key, unit);
|
|
69
|
+
}
|
|
70
|
+
return [...units.values()];
|
|
71
|
+
}
|
|
72
|
+
function unitOfPath(path, units) {
|
|
73
|
+
let best = null;
|
|
74
|
+
let bestDepth = -1;
|
|
75
|
+
for (const unit of units) {
|
|
76
|
+
if (unit.kind === "fixture" && unit.key === path) return unit;
|
|
77
|
+
const folder = unit.folder;
|
|
78
|
+
if (!path.startsWith(folder)) continue;
|
|
79
|
+
const depth = folder.length;
|
|
80
|
+
if (depth > bestDepth || depth === bestDepth && unit.kind === "property") {
|
|
81
|
+
best = unit;
|
|
82
|
+
bestDepth = depth;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return best;
|
|
86
|
+
}
|
|
87
|
+
function listEntryFor(list, path) {
|
|
88
|
+
const folder = folderOf(list);
|
|
89
|
+
return path.startsWith(folder) ? path.slice(folder.length) : null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
//#endregion
|
|
93
|
+
export { contentFixtureUnit, listEntryFor, propertyOf, propertyUnit, readFixtureListing, unitOfPath, unitsOf };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { isLeadIngestRefusal, leadIngestBody, leadIngestHeaders, leadIngestSize, leadTimestampFresh } from "../../../lead-fields/dist/ingest.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../internal/playground/dist/host/leads.js
|
|
4
|
+
const PLAYGROUND_SITE = {
|
|
5
|
+
siteId: "00000000-0000-4000-8000-00000000c0de",
|
|
6
|
+
siteSecret: "706c617967726f756e642d6c6561642d666f726d2d6e6f7468696e672d6b657074"
|
|
7
|
+
};
|
|
8
|
+
function json(status, body) {
|
|
9
|
+
return new Response(JSON.stringify(body), {
|
|
10
|
+
status,
|
|
11
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function hexBytes(hex) {
|
|
15
|
+
const out = new Uint8Array(/* @__PURE__ */ new ArrayBuffer(hex.length / 2));
|
|
16
|
+
for (let i = 0; i < out.length; i++) out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
async function signatureOf(message) {
|
|
20
|
+
const key = await crypto.subtle.importKey("raw", hexBytes(PLAYGROUND_SITE.siteSecret), {
|
|
21
|
+
name: "HMAC",
|
|
22
|
+
hash: "SHA-256"
|
|
23
|
+
}, false, ["sign"]);
|
|
24
|
+
return [...new Uint8Array(await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(message)))].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
25
|
+
}
|
|
26
|
+
async function answerLead(request, nowSeconds = Math.floor(Date.now() / 1e3)) {
|
|
27
|
+
if (request.method !== "POST") return json(405, { error: "method_not_allowed" });
|
|
28
|
+
const headers = leadIngestHeaders((name) => request.headers.get(name));
|
|
29
|
+
if (isLeadIngestRefusal(headers)) return json(headers.status, { error: headers.error });
|
|
30
|
+
const rawBody = await request.text();
|
|
31
|
+
const tooLarge = leadIngestSize(rawBody);
|
|
32
|
+
if (tooLarge !== null) return json(tooLarge.status, { error: tooLarge.error });
|
|
33
|
+
if (headers.siteId !== PLAYGROUND_SITE.siteId || !leadTimestampFresh(headers.timestamp, nowSeconds)) return json(401, { error: "unauthorized" });
|
|
34
|
+
if (headers.signature.toLowerCase() !== await signatureOf(`${headers.timestamp}.${rawBody}`)) return json(401, { error: "unauthorized" });
|
|
35
|
+
const body = leadIngestBody(rawBody);
|
|
36
|
+
if (isLeadIngestRefusal(body)) return json(body.status, { error: body.error });
|
|
37
|
+
return json(200, { ok: true });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { PLAYGROUND_SITE, answerLead };
|