@homepages/concrete 1.0.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/CHANGELOG.md +59 -0
- package/README.md +174 -0
- package/codemods/manifest.json +9 -0
- package/dist/artifact/playground/client/assets/index-BSA1yutg.css +1 -0
- package/dist/artifact/playground/client/assets/index-JloQyj8h.js +1101 -0
- package/dist/artifact/playground/client/index.html +13 -0
- package/dist/artifact/playground/client/island-canvas-host.mjs +1 -0
- package/dist/artifact/playground/host.mjs +127 -0
- package/dist/asset-modules.d.ts +99 -0
- package/dist/base.css +220 -0
- package/dist/browser/site-config.d.ts +18 -0
- package/dist/browser/site-config.js +56 -0
- package/dist/browser/submit-lead.d.ts +98 -0
- package/dist/browser/submit-lead.js +188 -0
- package/dist/browser.d.ts +3 -0
- package/dist/browser.js +4 -0
- package/dist/cli/build/artifact.js +225 -0
- package/dist/cli/build/captures.js +67 -0
- package/dist/cli/build/esbuild.js +127 -0
- package/dist/cli/build/fixtures.js +96 -0
- package/dist/cli/build/icons.js +76 -0
- package/dist/cli/build/index.js +38 -0
- package/dist/cli/build/playground.js +31 -0
- package/dist/cli/build/sections.js +236 -0
- package/dist/cli/build/source.js +62 -0
- package/dist/cli/build/static.js +156 -0
- package/dist/cli/capture/bundle.js +37 -0
- package/dist/cli/capture/capture-browser.js +51 -0
- package/dist/cli/capture/capture.js +121 -0
- package/dist/cli/check/analyze.js +95 -0
- package/dist/cli/check/index.js +19 -0
- package/dist/cli/check/load-workspace.js +119 -0
- package/dist/cli/check/messages.js +16 -0
- package/dist/cli/check/render/class-conflicts.js +39 -0
- package/dist/cli/check/render/html.js +86 -0
- package/dist/cli/check/render/inputs.js +53 -0
- package/dist/cli/check/render/invariants.js +58 -0
- package/dist/cli/check/render/island-frames.js +72 -0
- package/dist/cli/check/render/marker-coverage.js +102 -0
- package/dist/cli/check/render/nav.js +64 -0
- package/dist/cli/check/report.js +73 -0
- package/dist/cli/check/stages/bundles.js +129 -0
- package/dist/cli/check/stages/composition.js +67 -0
- package/dist/cli/check/stages/contracts.js +22 -0
- package/dist/cli/check/stages/dependencies.js +261 -0
- package/dist/cli/check/stages/fixtures.js +74 -0
- package/dist/cli/check/stages/lint.js +41 -0
- package/dist/cli/check/stages/logic.js +63 -0
- package/dist/cli/check/stages/render.js +144 -0
- package/dist/cli/check/stages/sections.js +83 -0
- package/dist/cli/check/stages/stylesheet.js +31 -0
- package/dist/cli/check/stages/typecheck.js +68 -0
- package/dist/cli/check/stages/workspace.js +26 -0
- package/dist/cli/commands.js +342 -0
- package/dist/cli/currency/cache.js +89 -0
- package/dist/cli/currency/decide.js +65 -0
- package/dist/cli/currency/opt-out.js +16 -0
- package/dist/cli/currency/preamble.js +183 -0
- package/dist/cli/currency/prompt.js +28 -0
- package/dist/cli/currency/refresh.js +44 -0
- package/dist/cli/currency/resolve-latest.js +185 -0
- package/dist/cli/currency/version-order.js +38 -0
- package/dist/cli/dev/crop.js +22 -0
- package/dist/cli/dev/hmr.js +26 -0
- package/dist/cli/dev/http.js +129 -0
- package/dist/cli/dev/index.js +70 -0
- package/dist/cli/dev/islands.js +390 -0
- package/dist/cli/dev/load-template.js +46 -0
- package/dist/cli/dev/request-error.js +22 -0
- package/dist/cli/dev/server.js +307 -0
- package/dist/cli/dev/tsconfig-paths.js +95 -0
- package/dist/cli/dev/vite.js +85 -0
- package/dist/cli/dev/workspace-reader.js +274 -0
- package/dist/cli/io.d.ts +14 -0
- package/dist/cli/media/cache.js +125 -0
- package/dist/cli/media/derive.js +252 -0
- package/dist/cli/media/deriver-plugin.js +71 -0
- package/dist/cli/property/index.js +180 -0
- package/dist/cli/property/library.js +137 -0
- package/dist/cli/publish/client.js +119 -0
- package/dist/cli/publish/freshness.js +66 -0
- package/dist/cli/publish/git.js +43 -0
- package/dist/cli/publish/index.js +207 -0
- package/dist/cli/publish/pack.js +78 -0
- package/dist/cli/publish/report.js +98 -0
- package/dist/cli/publish/target.js +87 -0
- package/dist/cli/publish/wire.js +29 -0
- package/dist/cli/tar.js +87 -0
- package/dist/cli/upgrade/codemod.js +56 -0
- package/dist/cli/upgrade/index.js +263 -0
- package/dist/cli/upgrade/manifest.js +72 -0
- package/dist/cli/upgrade/plan.js +68 -0
- package/dist/cli/upgrade/stage.js +71 -0
- package/dist/cli/version.d.ts +12 -0
- package/dist/cli/version.js +15 -0
- package/dist/cli/workspace.js +108 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +94 -0
- package/dist/css/compile.js +77 -0
- package/dist/css/graph.js +109 -0
- package/dist/css/inline.js +132 -0
- package/dist/css/rules.js +65 -0
- package/dist/design-system/format-variants.js +127 -0
- package/dist/eslint/authoring.js +46 -0
- package/dist/eslint/correctness.js +42 -0
- package/dist/eslint/rules/editor-declaration.js +103 -0
- package/dist/eslint/rules/editor-reason.js +135 -0
- package/dist/eslint/rules/island-imports.js +20 -0
- package/dist/eslint/rules/jsx-visitor.js +20 -0
- package/dist/eslint/rules/no-client-runtime.js +88 -0
- package/dist/eslint/rules/no-editor-globals.js +60 -0
- package/dist/eslint/rules/no-hard-coded-color.js +183 -0
- package/dist/eslint/rules/no-inline-style.js +24 -0
- package/dist/eslint/rules/no-marker-literal.js +37 -0
- package/dist/eslint/rules/no-nondeterminism.js +44 -0
- package/dist/eslint/rules/no-px-breakpoint.js +44 -0
- package/dist/eslint/rules/no-raw-values.js +45 -0
- package/dist/eslint/rules/serializable-props.js +95 -0
- package/dist/eslint.d.ts +6 -0
- package/dist/eslint.js +26 -0
- package/dist/fixtures/brand.d.ts +4 -0
- package/dist/fixtures/brand.js +9 -0
- package/dist/fixtures/bundle-rule.js +67 -0
- package/dist/fixtures/canonical.d.ts +149 -0
- package/dist/fixtures/image-dimensions.js +59 -0
- package/dist/fixtures/load.js +154 -0
- package/dist/fixtures/media-plugin.js +141 -0
- package/dist/fixtures/media.js +165 -0
- package/dist/fixtures/property.js +210 -0
- package/dist/fixtures/resolve.js +202 -0
- package/dist/fixtures/rows.js +108 -0
- package/dist/fixtures/synthesize-empties.js +42 -0
- package/dist/fixtures.d.ts +213 -0
- package/dist/fixtures.js +37 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +37 -0
- package/dist/islands/client-module.js +97 -0
- package/dist/islands/marker.d.ts +43 -0
- package/dist/islands/marker.js +44 -0
- package/dist/node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js +687 -0
- package/dist/packages/external/concrete/package.js +5 -0
- package/dist/packages/internal/fact-interpolation/dist/index.js +22 -0
- package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +111 -0
- package/dist/packages/internal/fill-bake/dist/display.js +9 -0
- package/dist/packages/internal/fill-bake/dist/index.js +6 -0
- package/dist/packages/internal/fill-bake/dist/reconcile-cross-section.js +170 -0
- package/dist/packages/internal/fill-vocabulary/dist/facts.d.ts +32 -0
- package/dist/packages/internal/fill-vocabulary/dist/facts.js +131 -0
- package/dist/packages/internal/fill-vocabulary/dist/row-planners.js +73 -0
- package/dist/packages/internal/format-geometry/dist/capture.js +404 -0
- package/dist/packages/internal/format-geometry/dist/format.d.ts +41 -0
- package/dist/packages/internal/format-geometry/dist/geometry.js +58 -0
- package/dist/packages/internal/format-geometry/dist/index.js +4 -0
- package/dist/packages/internal/image-descriptor/dist/index.d.ts +35 -0
- package/dist/packages/internal/image-ladder/dist/crop.js +82 -0
- package/dist/packages/internal/image-ladder/dist/encode.js +23 -0
- package/dist/packages/internal/image-ladder/dist/index.js +4 -0
- package/dist/packages/internal/image-ladder/dist/policy.js +102 -0
- package/dist/packages/internal/island-runtime/dist/capture-holds.d.ts +13 -0
- package/dist/packages/internal/island-runtime/dist/capture-holds.js +45 -0
- package/dist/packages/internal/island-runtime/dist/contract.d.ts +176 -0
- package/dist/packages/internal/island-runtime/dist/contract.js +94 -0
- package/dist/packages/internal/island-runtime/dist/editor-instance-context.js +15 -0
- package/dist/packages/internal/island-runtime/dist/index.d.ts +103 -0
- package/dist/packages/internal/island-runtime/dist/index.js +163 -0
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.d.ts +19 -0
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.js +39 -0
- package/dist/packages/internal/island-runtime/dist/use-editor.d.ts +22 -0
- package/dist/packages/internal/island-runtime/dist/use-editor.js +54 -0
- package/dist/packages/internal/island-runtime/dist/viewport-schedule.js +105 -0
- package/dist/packages/internal/property-facts/dist/derive-facts-view.js +25 -0
- package/dist/packages/internal/property-facts/dist/index.js +3 -0
- package/dist/packages/internal/property-facts/dist/property-facts-CSdkSuD7.js +181 -0
- package/dist/packages/internal/section-contracts/dist/cap-contract.js +59 -0
- package/dist/packages/internal/section-contracts/dist/catalog.js +102 -0
- package/dist/packages/internal/section-contracts/dist/choose-select-contract.js +24 -0
- package/dist/packages/internal/section-contracts/dist/count-bounds-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/display-contract.js +30 -0
- package/dist/packages/internal/section-contracts/dist/display-evidence-contract.js +17 -0
- package/dist/packages/internal/section-contracts/dist/group-contract.js +21 -0
- package/dist/packages/internal/section-contracts/dist/index.js +26 -0
- package/dist/packages/internal/section-contracts/dist/interpolation-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/list-fill-contract.js +53 -0
- package/dist/packages/internal/section-contracts/dist/list-scalar-contract.js +70 -0
- package/dist/packages/internal/section-contracts/dist/name-title-contract.js +27 -0
- package/dist/packages/internal/section-contracts/dist/nested-slot-contract.js +12 -0
- package/dist/packages/internal/section-contracts/dist/option-source-contract.js +22 -0
- package/dist/packages/internal/section-contracts/dist/poi-curation-contract.js +18 -0
- package/dist/packages/internal/section-contracts/dist/pooling-field-contract.js +30 -0
- package/dist/packages/internal/section-contracts/dist/record-collection-contract.js +24 -0
- package/dist/packages/internal/section-contracts/dist/row-contract.js +37 -0
- package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +38 -0
- package/dist/packages/internal/section-contracts/dist/runners.js +181 -0
- package/dist/packages/internal/section-contracts/dist/select-contract.js +28 -0
- package/dist/packages/internal/section-contracts/dist/source-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/source-filter-contract.js +15 -0
- package/dist/packages/internal/section-contracts/dist/sources-contract.js +28 -0
- package/dist/packages/internal/section-contracts/dist/url-contract.js +20 -0
- package/dist/packages/internal/source-resolution/dist/index.js +222 -0
- package/dist/packages/internal/template-artifact/dist/hash.js +50 -0
- package/dist/packages/internal/template-artifact/dist/index.js +7 -0
- package/dist/packages/internal/template-artifact/dist/layout.js +165 -0
- package/dist/packages/internal/template-artifact/dist/manifest.js +73 -0
- package/dist/packages/internal/template-artifact/dist/sha256.js +138 -0
- package/dist/packages/internal/template-artifact/dist/verify.js +275 -0
- package/dist/packages/internal/template-contracts/dist/collection-editing.js +38 -0
- package/dist/packages/internal/template-contracts/dist/content-categories.d.ts +10 -0
- package/dist/packages/internal/template-contracts/dist/content-categories.js +17 -0
- package/dist/packages/internal/template-contracts/dist/document-value.d.ts +33 -0
- package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +81 -0
- package/dist/packages/internal/template-contracts/dist/facts-view.js +136 -0
- package/dist/packages/internal/template-contracts/dist/layout.js +17 -0
- package/dist/packages/internal/template-contracts/dist/markers.d.ts +40 -0
- package/dist/packages/internal/template-contracts/dist/markers.js +41 -0
- package/dist/packages/internal/template-contracts/dist/poi-row.d.ts +63 -0
- package/dist/packages/internal/template-contracts/dist/select-key.js +13 -0
- package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +1112 -0
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +1109 -0
- package/dist/packages/internal/template-contracts/dist/slot-overrides.js +11 -0
- package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +45 -0
- package/dist/packages/internal/template-contracts/dist/video-value.d.ts +63 -0
- package/dist/playground/host/page-state.js +12 -0
- package/dist/playground/host/paths.js +9 -0
- package/dist/playground/layout.js +24 -0
- package/dist/playground/wire.js +36 -0
- package/dist/playground-island-runtime.d.ts +3 -0
- package/dist/playground-island-runtime.js +4 -0
- package/dist/primitives/FrameShell.d.ts +29 -0
- package/dist/primitives/FrameShell.js +34 -0
- package/dist/primitives/Image.d.ts +119 -0
- package/dist/primitives/Image.js +173 -0
- package/dist/primitives/Section.d.ts +22 -0
- package/dist/primitives/Section.js +26 -0
- package/dist/primitives/Tour.d.ts +43 -0
- package/dist/primitives/Tour.js +72 -0
- package/dist/primitives/Video.d.ts +57 -0
- package/dist/primitives/Video.js +116 -0
- package/dist/primitives/embed-playback.js +50 -0
- package/dist/primitives/index.d.ts +11 -0
- package/dist/primitives/marker-attrs.js +44 -0
- package/dist/primitives/object-fit.js +11 -0
- package/dist/primitives/picture-sources.d.ts +24 -0
- package/dist/primitives/picture-sources.js +52 -0
- package/dist/primitives/probe-context.js +24 -0
- package/dist/primitives/slot-bindings.d.ts +96 -0
- package/dist/primitives/slot-bindings.js +226 -0
- package/dist/primitives/slot-document.d.ts +35 -0
- package/dist/primitives/slot-document.js +37 -0
- package/dist/primitives/slot-group.d.ts +40 -0
- package/dist/primitives/slot-group.js +45 -0
- package/dist/primitives/slot-list.d.ts +21 -0
- package/dist/primitives/slot-list.js +23 -0
- package/dist/primitives/slot-media.d.ts +71 -0
- package/dist/primitives/slot-media.js +98 -0
- package/dist/primitives/slot-scalar.d.ts +53 -0
- package/dist/primitives/slot-scalar.js +98 -0
- package/dist/primitives/slot.d.ts +26 -0
- package/dist/primitives/slot.js +28 -0
- package/dist/rules/registry.js +479 -0
- package/dist/schema/compute.d.ts +22 -0
- package/dist/schema/compute.js +30 -0
- package/dist/schema/define-schema.d.ts +27 -0
- package/dist/schema/define-schema.js +73 -0
- package/dist/schema/extract-fill-spec.js +246 -0
- package/dist/schema/extract-used-facts.js +176 -0
- package/dist/schema/fact.d.ts +65 -0
- package/dist/schema/fact.js +33 -0
- package/dist/schema/fill-builders.d.ts +387 -0
- package/dist/schema/fill-builders.js +263 -0
- package/dist/schema/fill-declaration.d.ts +76 -0
- package/dist/schema/fill-declaration.js +43 -0
- package/dist/schema/fill-spec.d.ts +18 -0
- package/dist/schema/fill-spec.js +170 -0
- package/dist/schema/format-presets.d.ts +27 -0
- package/dist/schema/format-presets.js +76 -0
- package/dist/schema/format.d.ts +22 -0
- package/dist/schema/format.js +40 -0
- package/dist/schema/formats.d.ts +6 -0
- package/dist/schema/formats.js +7 -0
- package/dist/schema/layout.d.ts +32 -0
- package/dist/schema/layout.js +30 -0
- package/dist/schema/manifest.js +300 -0
- package/dist/schema/property-facts.d.ts +83 -0
- package/dist/schema/runtime-values.d.ts +88 -0
- package/dist/schema/section-nav.d.ts +38 -0
- package/dist/schema/section-nav.js +29 -0
- package/dist/schema/section-props.d.ts +98 -0
- package/dist/schema/section-schema.d.ts +53 -0
- package/dist/schema/section-schema.js +54 -0
- package/dist/schema/slot-builders.d.ts +497 -0
- package/dist/schema/slot-builders.js +331 -0
- package/dist/schema/slot-types.d.ts +110 -0
- package/dist/schema/slot-types.js +187 -0
- package/dist/section/declare.d.ts +44 -0
- package/dist/section/declare.js +27 -0
- package/dist/section/discovery.js +76 -0
- package/dist/section/groups.js +74 -0
- package/dist/section/materialize.js +28 -0
- package/dist/section/placements.js +28 -0
- package/dist/section/section.d.ts +69 -0
- package/dist/section/section.js +101 -0
- package/dist/site-analytics.d.ts +1 -0
- package/dist/site-analytics.js +15 -0
- package/dist/site-runtime/analytics.js +97 -0
- package/dist/site-runtime/site-integrations.js +97 -0
- package/dist/styles.css +60 -0
- package/dist/template/define-template.d.ts +139 -0
- package/dist/template/define-template.js +98 -0
- package/dist/template/logic-build.js +191 -0
- package/dist/template/logic-shim.d.ts +43 -0
- package/dist/template/logic-shim.js +52 -0
- package/dist/template/logic-transform.js +92 -0
- package/dist/template/materialize.js +107 -0
- package/dist/template/reconcile.d.ts +67 -0
- package/dist/template/reconcile.js +25 -0
- package/dist/template/running-copy.js +58 -0
- package/guide/reference/cli/INDEX.md +79 -0
- package/guide/reference/cli/build.md +48 -0
- package/guide/reference/cli/check.md +49 -0
- package/guide/reference/cli/dev.md +46 -0
- package/guide/reference/cli/property-add.md +53 -0
- package/guide/reference/cli/property-list.md +46 -0
- package/guide/reference/cli/publish.md +54 -0
- package/guide/reference/cli/upgrade.md +48 -0
- package/guide/reference/rules/INDEX.md +190 -0
- package/package.json +137 -0
- package/tsconfig.base.json +16 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { SiteConfig } from "./site-config.js";
|
|
2
|
+
//#region src/browser/submit-lead.d.ts
|
|
3
|
+
/** Source attribution for the owner-facing leads inbox. */
|
|
4
|
+
interface LeadSource {
|
|
5
|
+
/** Bare hostname of the referring site; `""` means a direct visit. */
|
|
6
|
+
referrer: string;
|
|
7
|
+
utm_source: string;
|
|
8
|
+
utm_medium: string;
|
|
9
|
+
utm_campaign: string;
|
|
10
|
+
/** The page the lead was submitted from. */
|
|
11
|
+
source_url: string;
|
|
12
|
+
}
|
|
13
|
+
/** The contact details a lead carries. Only `email` is required. */
|
|
14
|
+
interface LeadInput {
|
|
15
|
+
email: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
phone?: string;
|
|
18
|
+
message?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Any additional fields this form collects, sent verbatim. Cannot shadow the
|
|
21
|
+
* named contact fields or the source attribution — see the precedence note on
|
|
22
|
+
* `submitLead`.
|
|
23
|
+
*/
|
|
24
|
+
extra?: Record<string, string | number | boolean | null>;
|
|
25
|
+
}
|
|
26
|
+
/** Options for {@link submitLead}. */
|
|
27
|
+
interface SubmitLeadOptions {
|
|
28
|
+
/** Override individual attribution fields, or pass `false` to send none. */
|
|
29
|
+
source?: Partial<LeadSource> | false;
|
|
30
|
+
/** Defaults to `readSiteConfig()`. Pass `null` to force preview behavior. */
|
|
31
|
+
config?: SiteConfig | null;
|
|
32
|
+
/** Defaults to `globalThis.fetch`. */
|
|
33
|
+
fetch?: typeof globalThis.fetch;
|
|
34
|
+
/** Retries after the first attempt, on network error or 5xx only. Default 2. */
|
|
35
|
+
retries?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Why {@link submitLead} did not succeed: no email was given, an identical
|
|
39
|
+
* submission is already in flight, the serialized body exceeds the ingest size
|
|
40
|
+
* limit, the site's credentials were rejected (401), the request was otherwise
|
|
41
|
+
* rejected, or every attempt failed on the network / a 5xx.
|
|
42
|
+
*/
|
|
43
|
+
type SubmitLeadFailure = "missing-email" | "in-flight" | "too-large" | "unauthorized" | "rejected" | "network";
|
|
44
|
+
/**
|
|
45
|
+
* The outcome of a {@link submitLead} call. `simulated: true` means nothing was
|
|
46
|
+
* actually sent — the page carried no site config (editor canvas or local
|
|
47
|
+
* preview) — and is otherwise absent. A failure never throws; it resolves here
|
|
48
|
+
* instead, with a `reason` and a user-facing `message`.
|
|
49
|
+
*/
|
|
50
|
+
type SubmitLeadResult = {
|
|
51
|
+
ok: true;
|
|
52
|
+
simulated?: true;
|
|
53
|
+
} | {
|
|
54
|
+
ok: false;
|
|
55
|
+
reason: SubmitLeadFailure;
|
|
56
|
+
message: string;
|
|
57
|
+
status?: number;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* The event {@link submitLead} dispatches on `window` once a lead is accepted — not
|
|
61
|
+
* on a failure, and not on a simulated submission. The event's detail is a
|
|
62
|
+
* {@link LeadEventDetail}. It is how a published page's connected integrations
|
|
63
|
+
* learn that a lead was captured; a template never dispatches it itself.
|
|
64
|
+
*/
|
|
65
|
+
declare const LEAD_EVENT = "homepages:lead";
|
|
66
|
+
/** What a {@link LEAD_EVENT} event carries as its detail. */
|
|
67
|
+
interface LeadEventDetail {
|
|
68
|
+
/** The email the lead was submitted with, trimmed. */
|
|
69
|
+
email: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Read attribution from a referrer, a query string, and the current URL.
|
|
73
|
+
* Exported for testing and for callers assembling a `source` override by hand.
|
|
74
|
+
*/
|
|
75
|
+
declare function captureSource(referrer: string, search: string, href: string): Partial<LeadSource>;
|
|
76
|
+
/**
|
|
77
|
+
* Serialize the ingest request body. The returned string is signed AND sent
|
|
78
|
+
* verbatim — the signature covers these exact bytes, so it must never be
|
|
79
|
+
* re-serialized between signing and sending.
|
|
80
|
+
*/
|
|
81
|
+
declare function buildLeadBody(input: LeadInput, source: Partial<LeadSource>): string;
|
|
82
|
+
/**
|
|
83
|
+
* Submit a lead to HomePages.
|
|
84
|
+
*
|
|
85
|
+
* Handles signing, the idempotency key, source attribution, and retry. Never
|
|
86
|
+
* throws — inspect the returned result. Field precedence into the submitted
|
|
87
|
+
* payload is `extra` < the named contact fields < source attribution, so `extra`
|
|
88
|
+
* can add fields but never shadow them.
|
|
89
|
+
*
|
|
90
|
+
* Off a published page — the editor canvas, or local preview — there is no site
|
|
91
|
+
* config, so nothing is sent and the result is `{ ok: true, simulated: true }`.
|
|
92
|
+
*
|
|
93
|
+
* A lead the server accepts is also announced page-wide: {@link LEAD_EVENT} is
|
|
94
|
+
* dispatched on `window` before the result resolves.
|
|
95
|
+
*/
|
|
96
|
+
declare function submitLead(input: LeadInput, options?: SubmitLeadOptions): Promise<SubmitLeadResult>;
|
|
97
|
+
//#endregion
|
|
98
|
+
export { LEAD_EVENT, LeadEventDetail, LeadInput, LeadSource, SubmitLeadFailure, SubmitLeadOptions, SubmitLeadResult, buildLeadBody, captureSource, submitLead };
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { readSiteConfig, signedIngestHeaders } from "./site-config.js";
|
|
2
|
+
|
|
3
|
+
//#region src/browser/submit-lead.ts
|
|
4
|
+
const UTM_KEYS = [
|
|
5
|
+
"utm_source",
|
|
6
|
+
"utm_medium",
|
|
7
|
+
"utm_campaign"
|
|
8
|
+
];
|
|
9
|
+
const UTM_MAX_LENGTH = 128;
|
|
10
|
+
const INGEST_PATH = "/leads/ingest";
|
|
11
|
+
/** Ingest replies 413 above this; failing locally gives the caller a usable reason. */
|
|
12
|
+
const MAX_BODY_BYTES = 16 * 1024;
|
|
13
|
+
const RETRY_BACKOFF_MS = [300, 1200];
|
|
14
|
+
/**
|
|
15
|
+
* The event {@link submitLead} dispatches on `window` once a lead is accepted — not
|
|
16
|
+
* on a failure, and not on a simulated submission. The event's detail is a
|
|
17
|
+
* {@link LeadEventDetail}. It is how a published page's connected integrations
|
|
18
|
+
* learn that a lead was captured; a template never dispatches it itself.
|
|
19
|
+
*/
|
|
20
|
+
const LEAD_EVENT = "homepages:lead";
|
|
21
|
+
/**
|
|
22
|
+
* Read attribution from a referrer, a query string, and the current URL.
|
|
23
|
+
* Exported for testing and for callers assembling a `source` override by hand.
|
|
24
|
+
*/
|
|
25
|
+
function captureSource(referrer, search, href) {
|
|
26
|
+
const source = {
|
|
27
|
+
referrer: "",
|
|
28
|
+
source_url: href
|
|
29
|
+
};
|
|
30
|
+
try {
|
|
31
|
+
if (referrer) source.referrer = new URL(referrer).hostname.replace(/^www\./, "");
|
|
32
|
+
} catch {}
|
|
33
|
+
try {
|
|
34
|
+
const params = new URLSearchParams(search);
|
|
35
|
+
for (const key of UTM_KEYS) {
|
|
36
|
+
const value = params.get(key);
|
|
37
|
+
if (value) source[key] = value.slice(0, UTM_MAX_LENGTH);
|
|
38
|
+
}
|
|
39
|
+
} catch {}
|
|
40
|
+
return source;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Serialize the ingest request body. The returned string is signed AND sent
|
|
44
|
+
* verbatim — the signature covers these exact bytes, so it must never be
|
|
45
|
+
* re-serialized between signing and sending.
|
|
46
|
+
*/
|
|
47
|
+
function buildLeadBody(input, source) {
|
|
48
|
+
const { source_url: sourceUrl, ...attribution } = source;
|
|
49
|
+
const fields = { ...input.extra };
|
|
50
|
+
fields.email = input.email.trim();
|
|
51
|
+
if (input.name !== void 0) fields.name = input.name;
|
|
52
|
+
if (input.phone !== void 0) fields.phone = input.phone;
|
|
53
|
+
if (input.message !== void 0) fields.message = input.message;
|
|
54
|
+
Object.assign(fields, attribution);
|
|
55
|
+
const body = { fields };
|
|
56
|
+
if (sourceUrl !== void 0) body.source_url = sourceUrl;
|
|
57
|
+
return JSON.stringify(body);
|
|
58
|
+
}
|
|
59
|
+
let warnedNoConfig = false;
|
|
60
|
+
const inFlight = /* @__PURE__ */ new Set();
|
|
61
|
+
/** Attribution needs a DOM; an island rendered server-side simply contributes none. */
|
|
62
|
+
function readAmbientSource() {
|
|
63
|
+
if (typeof document === "undefined" || typeof location === "undefined") return {};
|
|
64
|
+
return captureSource(document.referrer, location.search, location.href);
|
|
65
|
+
}
|
|
66
|
+
function resolveSource(override) {
|
|
67
|
+
if (override === false) return {};
|
|
68
|
+
return {
|
|
69
|
+
...readAmbientSource(),
|
|
70
|
+
...override ?? {}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Submit a lead to HomePages.
|
|
75
|
+
*
|
|
76
|
+
* Handles signing, the idempotency key, source attribution, and retry. Never
|
|
77
|
+
* throws — inspect the returned result. Field precedence into the submitted
|
|
78
|
+
* payload is `extra` < the named contact fields < source attribution, so `extra`
|
|
79
|
+
* can add fields but never shadow them.
|
|
80
|
+
*
|
|
81
|
+
* Off a published page — the editor canvas, or local preview — there is no site
|
|
82
|
+
* config, so nothing is sent and the result is `{ ok: true, simulated: true }`.
|
|
83
|
+
*
|
|
84
|
+
* A lead the server accepts is also announced page-wide: {@link LEAD_EVENT} is
|
|
85
|
+
* dispatched on `window` before the result resolves.
|
|
86
|
+
*/
|
|
87
|
+
async function submitLead(input, options = {}) {
|
|
88
|
+
if (!input.email || !input.email.trim()) return {
|
|
89
|
+
ok: false,
|
|
90
|
+
reason: "missing-email",
|
|
91
|
+
message: "Please enter your email address."
|
|
92
|
+
};
|
|
93
|
+
const config = options.config !== void 0 ? options.config : readSiteConfig();
|
|
94
|
+
if (!config) {
|
|
95
|
+
if (!warnedNoConfig) {
|
|
96
|
+
warnedNoConfig = true;
|
|
97
|
+
console.info("[concrete] submitLead: no site config on this page, so the lead was NOT sent. This is expected in the editor and in local preview; a published page carries the config.");
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
ok: true,
|
|
101
|
+
simulated: true
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const body = buildLeadBody(input, resolveSource(options.source));
|
|
105
|
+
if (new TextEncoder().encode(body).length > MAX_BODY_BYTES) return {
|
|
106
|
+
ok: false,
|
|
107
|
+
reason: "too-large",
|
|
108
|
+
message: "That submission is too long. Please shorten it and try again."
|
|
109
|
+
};
|
|
110
|
+
if (inFlight.has(body)) return {
|
|
111
|
+
ok: false,
|
|
112
|
+
reason: "in-flight",
|
|
113
|
+
message: "Your submission is already being sent."
|
|
114
|
+
};
|
|
115
|
+
inFlight.add(body);
|
|
116
|
+
try {
|
|
117
|
+
const result = await send(config, body, options);
|
|
118
|
+
if (result.ok) announceLead(input.email.trim());
|
|
119
|
+
return result;
|
|
120
|
+
} finally {
|
|
121
|
+
inFlight.delete(body);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function announceLead(email) {
|
|
125
|
+
if (typeof window === "undefined" || typeof CustomEvent === "undefined") return;
|
|
126
|
+
const detail = { email };
|
|
127
|
+
window.dispatchEvent(new CustomEvent(LEAD_EVENT, { detail }));
|
|
128
|
+
}
|
|
129
|
+
const NETWORK_MESSAGE = "We could not reach the server. Please check your connection and try again.";
|
|
130
|
+
function delay(ms) {
|
|
131
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
132
|
+
}
|
|
133
|
+
function clientFailure(status) {
|
|
134
|
+
if (status === 401) return {
|
|
135
|
+
ok: false,
|
|
136
|
+
reason: "unauthorized",
|
|
137
|
+
message: "This form cannot submit right now. Please contact the site owner.",
|
|
138
|
+
status
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
ok: false,
|
|
142
|
+
reason: "rejected",
|
|
143
|
+
message: "We could not accept that submission. Please check your details and try again.",
|
|
144
|
+
status
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
async function send(config, body, options) {
|
|
148
|
+
const doFetch = options.fetch ?? globalThis.fetch;
|
|
149
|
+
const idempotencyKey = crypto.randomUUID();
|
|
150
|
+
const attempts = Math.max(0, options.retries ?? RETRY_BACKOFF_MS.length) + 1;
|
|
151
|
+
let lastFailure = {
|
|
152
|
+
ok: false,
|
|
153
|
+
reason: "network",
|
|
154
|
+
message: NETWORK_MESSAGE
|
|
155
|
+
};
|
|
156
|
+
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
157
|
+
if (attempt > 0) await delay(RETRY_BACKOFF_MS[Math.min(attempt - 1, RETRY_BACKOFF_MS.length - 1)] ?? 0);
|
|
158
|
+
try {
|
|
159
|
+
const headers = await signedIngestHeaders(config, body);
|
|
160
|
+
const response = await doFetch(`${config.ingestBase}${INGEST_PATH}`, {
|
|
161
|
+
method: "POST",
|
|
162
|
+
headers: {
|
|
163
|
+
...headers,
|
|
164
|
+
"Idempotency-Key": idempotencyKey
|
|
165
|
+
},
|
|
166
|
+
body
|
|
167
|
+
});
|
|
168
|
+
if (response.ok) return { ok: true };
|
|
169
|
+
if (response.status < 500) return clientFailure(response.status);
|
|
170
|
+
lastFailure = {
|
|
171
|
+
ok: false,
|
|
172
|
+
reason: "network",
|
|
173
|
+
message: NETWORK_MESSAGE,
|
|
174
|
+
status: response.status
|
|
175
|
+
};
|
|
176
|
+
} catch {
|
|
177
|
+
lastFailure = {
|
|
178
|
+
ok: false,
|
|
179
|
+
reason: "network",
|
|
180
|
+
message: NETWORK_MESSAGE
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return lastFailure;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
//#endregion
|
|
188
|
+
export { LEAD_EVENT, buildLeadBody, captureSource, submitLead };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { SiteConfig, hmacHex, readSiteConfig, signedIngestHeaders } from "./browser/site-config.js";
|
|
2
|
+
import { LEAD_EVENT, LeadEventDetail, LeadInput, LeadSource, SubmitLeadFailure, SubmitLeadOptions, SubmitLeadResult, buildLeadBody, captureSource, submitLead } from "./browser/submit-lead.js";
|
|
3
|
+
export { LEAD_EVENT, type LeadEventDetail, type LeadInput, type LeadSource, type SiteConfig, type SubmitLeadFailure, type SubmitLeadOptions, type SubmitLeadResult, buildLeadBody, captureSource, hmacHex, readSiteConfig, signedIngestHeaders, submitLead };
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { hmacHex, readSiteConfig, signedIngestHeaders } from "./browser/site-config.js";
|
|
2
|
+
import { LEAD_EVENT, buildLeadBody, captureSource, submitLead } from "./browser/submit-lead.js";
|
|
3
|
+
|
|
4
|
+
export { LEAD_EVENT, buildLeadBody, captureSource, hmacHex, readSiteConfig, signedIngestHeaders, submitLead };
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { stampCollectionBounds } from "../../packages/internal/template-contracts/dist/slot-catalog.js";
|
|
2
|
+
import { orgsForScope } from "../../template/define-template.js";
|
|
3
|
+
import { CONCRETE_CLI_VERSION } from "../version.js";
|
|
4
|
+
import { MANIFEST_FILE, SECTION_FILES, TEMPLATE_FILES, assetPath, isSectionKey, isTemplateKey, islandPath, publishedSectionKey, sectionPath, staticPath, templatePath } from "../../packages/internal/template-artifact/dist/layout.js";
|
|
5
|
+
import { sectionContentHash, sourceDigest, templateContentHash } from "../../packages/internal/template-artifact/dist/hash.js";
|
|
6
|
+
import { ArtifactManifest } from "../../packages/internal/template-artifact/dist/manifest.js";
|
|
7
|
+
import { verifyArtifact } from "../../packages/internal/template-artifact/dist/verify.js";
|
|
8
|
+
import "../../packages/internal/template-artifact/dist/index.js";
|
|
9
|
+
import { compileTemplateCss } from "../../css/compile.js";
|
|
10
|
+
import { mediaCacheDir } from "../media/cache.js";
|
|
11
|
+
import { usedFactsFromSchema } from "../../schema/extract-used-facts.js";
|
|
12
|
+
import { buildSection } from "./sections.js";
|
|
13
|
+
import { TEMPLATE_FILE } from "../check/load-workspace.js";
|
|
14
|
+
import { analyzeWorkspace } from "../check/analyze.js";
|
|
15
|
+
import { captureFiles } from "./captures.js";
|
|
16
|
+
import { fixtureFiles } from "./fixtures.js";
|
|
17
|
+
import { deriveSiteIcons } from "./icons.js";
|
|
18
|
+
import { playgroundFiles } from "./playground.js";
|
|
19
|
+
import { collectSourceFiles } from "./source.js";
|
|
20
|
+
import { analyticsBundle, baseCssBundle, islandRuntimeBundle, reactVendorBundles } from "./static.js";
|
|
21
|
+
import { existsSync } from "node:fs";
|
|
22
|
+
import { dirname, isAbsolute, join, relative, sep } from "node:path";
|
|
23
|
+
import { mkdir, readdir, rm, writeFile } from "node:fs/promises";
|
|
24
|
+
|
|
25
|
+
//#region src/cli/build/artifact.ts
|
|
26
|
+
const encoder = new TextEncoder();
|
|
27
|
+
const json = (value) => encoder.encode(`${JSON.stringify(value, null, 2)}\n`);
|
|
28
|
+
function byKey(entries) {
|
|
29
|
+
return [...entries].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
30
|
+
}
|
|
31
|
+
/** Add a content-addressed file, refusing two different byte strings under one name. */
|
|
32
|
+
function putAsset(files, asset) {
|
|
33
|
+
const path = assetPath(asset.filename);
|
|
34
|
+
const prior = files.get(path);
|
|
35
|
+
if (prior !== void 0 && Buffer.compare(prior, asset.bytes) !== 0) throw new Error(`Two different files would be written as ${path}. Content-addressed names cannot collide; rename one of the sources.`);
|
|
36
|
+
files.set(path, asset.bytes);
|
|
37
|
+
}
|
|
38
|
+
function scopeOf(scope) {
|
|
39
|
+
return scope === "global" ? "global" : { orgs: [...orgsForScope(scope)] };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Refuse an output directory whose removal would take anything but a previous artifact
|
|
43
|
+
* with it: the workspace itself, a directory above it, or one holding other files.
|
|
44
|
+
*/
|
|
45
|
+
async function assertReplaceable(root, out) {
|
|
46
|
+
const rel = relative(out, root);
|
|
47
|
+
if (rel === "" || rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)) throw new Error(`The output directory ${out} contains the workspace; build writes into a directory of its own.`);
|
|
48
|
+
if (!existsSync(out)) return;
|
|
49
|
+
const entries = await readdir(out);
|
|
50
|
+
if (entries.length > 0 && !entries.includes("manifest.json")) throw new Error(`The output directory ${out} is not empty and holds no artifact; build replaces only a previous artifact. Name an empty or new directory.`);
|
|
51
|
+
}
|
|
52
|
+
/** Run check and, when it is green, build and write the artifact. */
|
|
53
|
+
async function buildArtifact(options) {
|
|
54
|
+
const { root, out } = options;
|
|
55
|
+
await assertReplaceable(root, out);
|
|
56
|
+
const { report, context } = await analyzeWorkspace({
|
|
57
|
+
root,
|
|
58
|
+
...options.runCommand === void 0 ? {} : { runCommand: options.runCommand }
|
|
59
|
+
});
|
|
60
|
+
if (!report.ok) return {
|
|
61
|
+
ok: false,
|
|
62
|
+
report
|
|
63
|
+
};
|
|
64
|
+
const { workspace, discovered, composition, sections, logic, corpus, assets: fixtureAssets } = context;
|
|
65
|
+
const template = workspace?.template ?? null;
|
|
66
|
+
if (workspace === void 0 || template === null || discovered === void 0 || composition === void 0 || sections === void 0 || logic === void 0 || corpus === void 0 || fixtureAssets === void 0) throw new Error("build: check passed without producing the workspace, composition, sections, logic bundles and fixtures a build reads.");
|
|
67
|
+
if (!isTemplateKey(template.key)) throw new Error(`Template key "${template.key}" cannot name an artifact: a key is one path segment of letters, digits, ".", "_" and "-".`);
|
|
68
|
+
const files = /* @__PURE__ */ new Map();
|
|
69
|
+
const publishedKey = (local) => publishedSectionKey(template.key, local);
|
|
70
|
+
const entryByKey = new Map(sections.map((entry) => [entry.key, entry]));
|
|
71
|
+
const builtByKey = /* @__PURE__ */ new Map();
|
|
72
|
+
const usedByKey = /* @__PURE__ */ new Map();
|
|
73
|
+
for (const [local, section] of byKey(composition.sections)) {
|
|
74
|
+
const key = publishedKey(local);
|
|
75
|
+
if (!isSectionKey(key)) throw new Error(`Section key "${local}" cannot name an artifact directory: a key is one path segment of letters, digits, ".", "_" and "-".`);
|
|
76
|
+
const entry = entryByKey.get(local);
|
|
77
|
+
const site = discovered.find((candidate) => candidate.section === section);
|
|
78
|
+
const sectionLogic = logic.sections.get(local);
|
|
79
|
+
if (entry === void 0 || site === void 0 || sectionLogic === void 0) throw new Error(`build: check passed without materializing, discovering or bundling the logic of section "${local}".`);
|
|
80
|
+
const module = join(root, site.module);
|
|
81
|
+
const schema = JSON.parse(JSON.stringify(entry.schema));
|
|
82
|
+
stampCollectionBounds(schema.slots);
|
|
83
|
+
const usedFacts = usedFactsFromSchema(section.schema);
|
|
84
|
+
usedByKey.set(key, usedFacts);
|
|
85
|
+
const built = context.built?.get(local) ?? await buildSection({
|
|
86
|
+
root,
|
|
87
|
+
key,
|
|
88
|
+
module,
|
|
89
|
+
exportName: site.exportName
|
|
90
|
+
});
|
|
91
|
+
if (built.passthrough.size > 0) throw new Error(`Section "${local}" imports images that could not be derived because \`sharp\` is not installed: ${[...built.passthrough].map((p) => relative(root, p)).join(", ")}. An artifact carries every image's responsive ladder; reinstall so sharp's native binary lands, then build again.`);
|
|
92
|
+
builtByKey.set(key, built);
|
|
93
|
+
files.set(sectionPath(key, SECTION_FILES.schema), json(schema));
|
|
94
|
+
files.set(sectionPath(key, SECTION_FILES.fillSpec), json(entry.fillSpec));
|
|
95
|
+
files.set(sectionPath(key, SECTION_FILES.usedFacts), json(usedFacts));
|
|
96
|
+
files.set(sectionPath(key, SECTION_FILES.logic), encoder.encode(sectionLogic));
|
|
97
|
+
files.set(sectionPath(key, SECTION_FILES.renderer), built.renderer);
|
|
98
|
+
for (const island of built.islands) files.set(islandPath(key, island.filename), island.bytes);
|
|
99
|
+
for (const asset of built.assets) putAsset(files, asset);
|
|
100
|
+
}
|
|
101
|
+
const { manifest } = composition;
|
|
102
|
+
const compositionColumn = {
|
|
103
|
+
output: manifest.output,
|
|
104
|
+
formats: manifest.formats,
|
|
105
|
+
pages: manifest.pages.map((page) => ({
|
|
106
|
+
...page,
|
|
107
|
+
sections: page.sections.map((instance) => ({
|
|
108
|
+
...instance,
|
|
109
|
+
section: publishedKey(instance.section)
|
|
110
|
+
}))
|
|
111
|
+
})),
|
|
112
|
+
canvases: manifest.canvases,
|
|
113
|
+
reconcile_reads: composition.reads.map((read) => ({
|
|
114
|
+
instance_id: read.instanceId,
|
|
115
|
+
slot: read.slot
|
|
116
|
+
}))
|
|
117
|
+
};
|
|
118
|
+
files.set(templatePath(TEMPLATE_FILES.composition), json(compositionColumn));
|
|
119
|
+
files.set(templatePath(TEMPLATE_FILES.logic), encoder.encode(logic.template));
|
|
120
|
+
files.set(templatePath(TEMPLATE_FILES.usedFacts), json([...new Set([...usedByKey.values()].flat())].sort()));
|
|
121
|
+
files.set(templatePath(TEMPLATE_FILES.preview), json(manifest.preview ?? null));
|
|
122
|
+
const css = await compileTemplateCss({
|
|
123
|
+
root,
|
|
124
|
+
templateFile: join(root, TEMPLATE_FILE),
|
|
125
|
+
template: {
|
|
126
|
+
key: template.key,
|
|
127
|
+
output: template.output,
|
|
128
|
+
formats: template.formats
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
if (css.bundle === null) throw new Error("build: check passed but the template stylesheet did not compile.");
|
|
132
|
+
files.set(templatePath(TEMPLATE_FILES.stylesheet), css.bundle.bytes);
|
|
133
|
+
for (const asset of css.bundle.assets) putAsset(files, asset);
|
|
134
|
+
const iconFile = workspace.assets.get(template.icon)?.path;
|
|
135
|
+
if (iconFile === void 0) throw new Error(`The template's icon (${template.icon}) is not a file in the workspace. Import it: \`import icon from "./icon.svg"\`.`);
|
|
136
|
+
const icons = await deriveSiteIcons(iconFile);
|
|
137
|
+
for (const asset of icons.assets) putAsset(files, asset);
|
|
138
|
+
const putStatic = (bundle) => {
|
|
139
|
+
files.set(staticPath(bundle.filename), bundle.bytes);
|
|
140
|
+
return {
|
|
141
|
+
filename: bundle.filename,
|
|
142
|
+
content_hash: bundle.contentHash
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
const islands = {};
|
|
146
|
+
const masters = [];
|
|
147
|
+
for (const [, built] of byKey(builtByKey)) {
|
|
148
|
+
for (const island of built.islands) islands[island.islandKey] = {
|
|
149
|
+
filename: island.filename,
|
|
150
|
+
content_hash: island.contentHash
|
|
151
|
+
};
|
|
152
|
+
masters.push(...built.masters);
|
|
153
|
+
}
|
|
154
|
+
const hasIslands = Object.keys(islands).length > 0;
|
|
155
|
+
const vendor = hasIslands ? await reactVendorBundles(root) : null;
|
|
156
|
+
const binding = {
|
|
157
|
+
base_css: putStatic(await baseCssBundle()),
|
|
158
|
+
template_css: {
|
|
159
|
+
filename: css.bundle.filename,
|
|
160
|
+
content_hash: css.bundle.contentHash
|
|
161
|
+
},
|
|
162
|
+
islands,
|
|
163
|
+
island_runtime: hasIslands ? putStatic(await islandRuntimeBundle()) : null,
|
|
164
|
+
react_vendor: vendor === null ? null : Object.fromEntries(byKey(vendor.facades).map(([specifier, facade]) => [specifier, putStatic(facade)])),
|
|
165
|
+
react_vendor_core: vendor === null ? null : putStatic(vendor.core),
|
|
166
|
+
analytics: template.output === "website" ? putStatic(await analyticsBundle()) : null,
|
|
167
|
+
masters: Object.fromEntries(byKey(masters)),
|
|
168
|
+
icons: icons.icons
|
|
169
|
+
};
|
|
170
|
+
files.set(templatePath(TEMPLATE_FILES.staticAssets), json(binding));
|
|
171
|
+
const fixtures = await fixtureFiles({
|
|
172
|
+
fixtures: corpus.filter((entry) => entry.emptied === void 0).map((entry) => entry.fixture),
|
|
173
|
+
assets: fixtureAssets,
|
|
174
|
+
cacheDir: mediaCacheDir(root)
|
|
175
|
+
});
|
|
176
|
+
for (const [path, bytes] of fixtures.files) files.set(path, bytes);
|
|
177
|
+
for (const asset of fixtures.assets) putAsset(files, asset);
|
|
178
|
+
const sectionHashes = /* @__PURE__ */ new Map();
|
|
179
|
+
for (const key of builtByKey.keys()) sectionHashes.set(key, sectionContentHash(files, key));
|
|
180
|
+
const sourceFiles = await collectSourceFiles(root, [out]);
|
|
181
|
+
const artifactManifest = ArtifactManifest.parse({
|
|
182
|
+
artifact_schema: 1,
|
|
183
|
+
framework_version: CONCRETE_CLI_VERSION,
|
|
184
|
+
key: template.key,
|
|
185
|
+
display_name: template.name,
|
|
186
|
+
deliverable_type: template.output,
|
|
187
|
+
scope: scopeOf(template.scope),
|
|
188
|
+
source_digest: sourceDigest(sourceFiles),
|
|
189
|
+
template: { content_hash: templateContentHash(files, sectionHashes) },
|
|
190
|
+
sections: byKey(sectionHashes).map(([key, hash]) => ({
|
|
191
|
+
key,
|
|
192
|
+
display_name: entryByKey.get(key.slice(template.key.length + 1))?.section.label ?? key,
|
|
193
|
+
content_hash: hash
|
|
194
|
+
})),
|
|
195
|
+
fixtures: fixtures.ids
|
|
196
|
+
});
|
|
197
|
+
files.set(MANIFEST_FILE, json(artifactManifest));
|
|
198
|
+
for (const [path, bytes] of await playgroundFiles()) files.set(path, bytes);
|
|
199
|
+
const captures = await captureFiles({
|
|
200
|
+
root,
|
|
201
|
+
output: template.output,
|
|
202
|
+
...options.capturer === void 0 ? {} : { capturer: options.capturer }
|
|
203
|
+
});
|
|
204
|
+
for (const [path, bytes] of captures) files.set(path, bytes);
|
|
205
|
+
const verdict = verifyArtifact(files);
|
|
206
|
+
if (verdict.problems.length > 0) throw new Error(`build: the artifact failed its own verification:\n${verdict.problems.map((p) => ` ${p.path}: ${p.message}`).join("\n")}`);
|
|
207
|
+
await rm(out, {
|
|
208
|
+
recursive: true,
|
|
209
|
+
force: true
|
|
210
|
+
});
|
|
211
|
+
for (const [path, bytes] of byKey(files)) {
|
|
212
|
+
const target = join(out, ...path.split("/"));
|
|
213
|
+
await mkdir(dirname(target), { recursive: true });
|
|
214
|
+
await writeFile(target, bytes);
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
ok: true,
|
|
218
|
+
report,
|
|
219
|
+
manifest: artifactManifest,
|
|
220
|
+
files
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
//#endregion
|
|
225
|
+
export { buildArtifact };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { CAPTURE_FILES, capturePath } from "../../packages/internal/template-artifact/dist/layout.js";
|
|
2
|
+
import "../../packages/internal/template-artifact/dist/index.js";
|
|
3
|
+
import { enabledPages } from "../../playground/host/page-state.js";
|
|
4
|
+
import { ROUTES } from "../../playground/wire.js";
|
|
5
|
+
import { startDevServer } from "../dev/server.js";
|
|
6
|
+
import { createServer } from "node:net";
|
|
7
|
+
import { Writable } from "node:stream";
|
|
8
|
+
|
|
9
|
+
//#region src/cli/build/captures.ts
|
|
10
|
+
function freePort() {
|
|
11
|
+
return new Promise((resolvePort, reject) => {
|
|
12
|
+
const probe = createServer();
|
|
13
|
+
probe.once("error", reject);
|
|
14
|
+
probe.listen(0, () => {
|
|
15
|
+
const address = probe.address();
|
|
16
|
+
probe.close(() => typeof address === "object" && address !== null ? resolvePort(address.port) : reject(/* @__PURE__ */ new Error("no free port for the capture host")));
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/** The server's notices are the dev command's; a build prints only its one line. */
|
|
21
|
+
const silent = new Writable({ write: (_chunk, _encoding, done) => done() });
|
|
22
|
+
/**
|
|
23
|
+
* Every capture file by artifact-relative path; empty for a website. Throws with the
|
|
24
|
+
* host's sentence when a capture fails — with the install line when Playwright is absent,
|
|
25
|
+
* since a rendered artifact without its captures would leave the platform's Download empty.
|
|
26
|
+
*/
|
|
27
|
+
async function captureFiles(options) {
|
|
28
|
+
const files = /* @__PURE__ */ new Map();
|
|
29
|
+
if (options.output === "website") return files;
|
|
30
|
+
const server = await startDevServer({
|
|
31
|
+
root: options.root,
|
|
32
|
+
port: await freePort(),
|
|
33
|
+
log: silent,
|
|
34
|
+
...options.capturer === void 0 ? {} : { capturer: options.capturer }
|
|
35
|
+
});
|
|
36
|
+
try {
|
|
37
|
+
const template = await server.workspace.template();
|
|
38
|
+
const { fixtures, problems } = await server.workspace.fixtures();
|
|
39
|
+
if (problems !== void 0) throw new Error(`build: the fixtures did not resolve for capture:\n${problems}`);
|
|
40
|
+
for (const fixture of fixtures) {
|
|
41
|
+
if (fixture.synthesized === true) continue;
|
|
42
|
+
for (const format of template.formats) {
|
|
43
|
+
const take = async (kind, target, file) => {
|
|
44
|
+
const response = await fetch(new URL(ROUTES.capture(kind, {
|
|
45
|
+
fixture: fixture.id,
|
|
46
|
+
format: format.id,
|
|
47
|
+
...target
|
|
48
|
+
}), server.url));
|
|
49
|
+
if (!response.ok) throw new Error(`build: capturing ${file} of fixture "${fixture.id}" at ${format.id} failed (${String(response.status)}): ${await response.text()}`);
|
|
50
|
+
files.set(capturePath(fixture.id, format.id, file), new Uint8Array(await response.arrayBuffer()));
|
|
51
|
+
};
|
|
52
|
+
if (template.output === "document") {
|
|
53
|
+
await take("print", {}, CAPTURE_FILES.document);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
for (const page of enabledPages(fixture, template.pages)) await take("screenshot", { page: page.id }, `${page.id}.png`);
|
|
57
|
+
await take("bundle", {}, CAPTURE_FILES.bundle);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
} finally {
|
|
61
|
+
await server.close();
|
|
62
|
+
}
|
|
63
|
+
return files;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { captureFiles };
|