@webflow/cloud-app 0.1.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +93 -0
  3. package/dist/bindings.d.ts +185 -0
  4. package/dist/bindings.d.ts.map +1 -0
  5. package/dist/bindings.js +120 -0
  6. package/dist/bindings.js.map +1 -0
  7. package/dist/config/package-json.d.ts +57 -0
  8. package/dist/config/package-json.d.ts.map +1 -0
  9. package/dist/config/package-json.js +94 -0
  10. package/dist/config/package-json.js.map +1 -0
  11. package/dist/config/webflow-json.d.ts +53 -0
  12. package/dist/config/webflow-json.d.ts.map +1 -0
  13. package/dist/config/webflow-json.js +72 -0
  14. package/dist/config/webflow-json.js.map +1 -0
  15. package/dist/create-webflow-json.d.ts +24 -0
  16. package/dist/create-webflow-json.d.ts.map +1 -0
  17. package/dist/create-webflow-json.js +170 -0
  18. package/dist/create-webflow-json.js.map +1 -0
  19. package/dist/errors.d.ts +13 -0
  20. package/dist/errors.d.ts.map +1 -0
  21. package/dist/errors.js +23 -0
  22. package/dist/errors.js.map +1 -0
  23. package/dist/frameworks/astro/adapter-patches/ensure-fixed-cloudflare-adapter.d.ts +36 -0
  24. package/dist/frameworks/astro/adapter-patches/ensure-fixed-cloudflare-adapter.d.ts.map +1 -0
  25. package/dist/frameworks/astro/adapter-patches/ensure-fixed-cloudflare-adapter.js +94 -0
  26. package/dist/frameworks/astro/adapter-patches/ensure-fixed-cloudflare-adapter.js.map +1 -0
  27. package/dist/frameworks/astro/adapter-patches/strip-cloudflare-base-nesting.d.ts +2 -0
  28. package/dist/frameworks/astro/adapter-patches/strip-cloudflare-base-nesting.d.ts.map +1 -0
  29. package/dist/frameworks/astro/adapter-patches/strip-cloudflare-base-nesting.js +97 -0
  30. package/dist/frameworks/astro/adapter-patches/strip-cloudflare-base-nesting.js.map +1 -0
  31. package/dist/frameworks/astro/astro5.d.ts +28 -0
  32. package/dist/frameworks/astro/astro5.d.ts.map +1 -0
  33. package/dist/frameworks/astro/astro5.js +259 -0
  34. package/dist/frameworks/astro/astro5.js.map +1 -0
  35. package/dist/frameworks/astro/astro6.d.ts +28 -0
  36. package/dist/frameworks/astro/astro6.d.ts.map +1 -0
  37. package/dist/frameworks/astro/astro6.js +286 -0
  38. package/dist/frameworks/astro/astro6.js.map +1 -0
  39. package/dist/frameworks/astro/astro7.d.ts +28 -0
  40. package/dist/frameworks/astro/astro7.d.ts.map +1 -0
  41. package/dist/frameworks/astro/astro7.js +283 -0
  42. package/dist/frameworks/astro/astro7.js.map +1 -0
  43. package/dist/frameworks/astro/index.d.ts +10 -0
  44. package/dist/frameworks/astro/index.d.ts.map +1 -0
  45. package/dist/frameworks/astro/index.js +16 -0
  46. package/dist/frameworks/astro/index.js.map +1 -0
  47. package/dist/frameworks/astro/templates/astro.config.webflow.ts +61 -0
  48. package/dist/frameworks/astro/templates/v5/astro.config.mjs.template +25 -0
  49. package/dist/frameworks/astro/templates/v5/webflow-loader.ts +103 -0
  50. package/dist/frameworks/astro/templates/v5/wrangler.json +6 -0
  51. package/dist/frameworks/astro/templates/v6/astro.config.mjs.template +35 -0
  52. package/dist/frameworks/astro/templates/v6/webflow-loader.ts +112 -0
  53. package/dist/frameworks/astro/templates/v6/wrangler.json +9 -0
  54. package/dist/frameworks/astro/templates/v7/astro.config.mjs.template +34 -0
  55. package/dist/frameworks/astro/templates/v7/webflow-loader.ts +113 -0
  56. package/dist/frameworks/astro/templates/v7/wrangler.json +9 -0
  57. package/dist/frameworks/base.d.ts +134 -0
  58. package/dist/frameworks/base.d.ts.map +1 -0
  59. package/dist/frameworks/base.js +175 -0
  60. package/dist/frameworks/base.js.map +1 -0
  61. package/dist/frameworks/errors.d.ts +72 -0
  62. package/dist/frameworks/errors.d.ts.map +1 -0
  63. package/dist/frameworks/errors.js +120 -0
  64. package/dist/frameworks/errors.js.map +1 -0
  65. package/dist/frameworks/nextjs/adapter-resolver.d.ts +72 -0
  66. package/dist/frameworks/nextjs/adapter-resolver.d.ts.map +1 -0
  67. package/dist/frameworks/nextjs/adapter-resolver.js +246 -0
  68. package/dist/frameworks/nextjs/adapter-resolver.js.map +1 -0
  69. package/dist/frameworks/nextjs/index.d.ts +38 -0
  70. package/dist/frameworks/nextjs/index.d.ts.map +1 -0
  71. package/dist/frameworks/nextjs/index.js +268 -0
  72. package/dist/frameworks/nextjs/index.js.map +1 -0
  73. package/dist/frameworks/nextjs/templates/next.config.ts.template +13 -0
  74. package/dist/frameworks/nextjs/templates/next.config.webflow.ts +46 -0
  75. package/dist/frameworks/nextjs/templates/open-next.config.ts +3 -0
  76. package/dist/frameworks/nextjs/templates/webflow-loader.ts +44 -0
  77. package/dist/frameworks/nextjs/templates/wrangler.json +6 -0
  78. package/dist/frameworks/registry.d.ts +127 -0
  79. package/dist/frameworks/registry.d.ts.map +1 -0
  80. package/dist/frameworks/registry.js +257 -0
  81. package/dist/frameworks/registry.js.map +1 -0
  82. package/dist/frameworks/static/index.d.ts +93 -0
  83. package/dist/frameworks/static/index.d.ts.map +1 -0
  84. package/dist/frameworks/static/index.js +352 -0
  85. package/dist/frameworks/static/index.js.map +1 -0
  86. package/dist/frameworks/static/templates/wrangler.json +7 -0
  87. package/dist/frameworks/types.d.ts +138 -0
  88. package/dist/frameworks/types.d.ts.map +1 -0
  89. package/dist/frameworks/types.js +3 -0
  90. package/dist/frameworks/types.js.map +1 -0
  91. package/dist/frameworks/vite/index.d.ts +46 -0
  92. package/dist/frameworks/vite/index.d.ts.map +1 -0
  93. package/dist/frameworks/vite/index.js +303 -0
  94. package/dist/frameworks/vite/index.js.map +1 -0
  95. package/dist/frameworks/vite/templates/vite.config.ts.template +14 -0
  96. package/dist/frameworks/vite/templates/vite.config.webflow.ts +52 -0
  97. package/dist/frameworks/vite/templates/wrangler.json +10 -0
  98. package/dist/index.d.ts +44 -0
  99. package/dist/index.d.ts.map +1 -0
  100. package/dist/index.js +118 -0
  101. package/dist/index.js.map +1 -0
  102. package/dist/pipeline.d.ts +8 -0
  103. package/dist/pipeline.d.ts.map +1 -0
  104. package/dist/pipeline.js +263 -0
  105. package/dist/pipeline.js.map +1 -0
  106. package/dist/ports/command-runner.d.ts +60 -0
  107. package/dist/ports/command-runner.d.ts.map +1 -0
  108. package/dist/ports/command-runner.js +116 -0
  109. package/dist/ports/command-runner.js.map +1 -0
  110. package/dist/ports/filesystem.d.ts +19 -0
  111. package/dist/ports/filesystem.d.ts.map +1 -0
  112. package/dist/ports/filesystem.js +68 -0
  113. package/dist/ports/filesystem.js.map +1 -0
  114. package/dist/ports/index.d.ts +17 -0
  115. package/dist/ports/index.d.ts.map +1 -0
  116. package/dist/ports/index.js +14 -0
  117. package/dist/ports/index.js.map +1 -0
  118. package/dist/ports/logger.d.ts +22 -0
  119. package/dist/ports/logger.d.ts.map +1 -0
  120. package/dist/ports/logger.js +18 -0
  121. package/dist/ports/logger.js.map +1 -0
  122. package/dist/ports/telemetry.d.ts +23 -0
  123. package/dist/ports/telemetry.d.ts.map +1 -0
  124. package/dist/ports/telemetry.js +12 -0
  125. package/dist/ports/telemetry.js.map +1 -0
  126. package/dist/toolchain/errors.d.ts +32 -0
  127. package/dist/toolchain/errors.d.ts.map +1 -0
  128. package/dist/toolchain/errors.js +31 -0
  129. package/dist/toolchain/errors.js.map +1 -0
  130. package/dist/toolchain/resolver.d.ts +25 -0
  131. package/dist/toolchain/resolver.d.ts.map +1 -0
  132. package/dist/toolchain/resolver.js +200 -0
  133. package/dist/toolchain/resolver.js.map +1 -0
  134. package/dist/toolchain/types.d.ts +52 -0
  135. package/dist/toolchain/types.d.ts.map +1 -0
  136. package/dist/toolchain/types.js +10 -0
  137. package/dist/toolchain/types.js.map +1 -0
  138. package/dist/types.d.ts +66 -0
  139. package/dist/types.d.ts.map +1 -0
  140. package/dist/types.js +3 -0
  141. package/dist/types.js.map +1 -0
  142. package/dist/utils/fs.d.ts +29 -0
  143. package/dist/utils/fs.d.ts.map +1 -0
  144. package/dist/utils/fs.js +126 -0
  145. package/dist/utils/fs.js.map +1 -0
  146. package/dist/utils/index.d.ts +11 -0
  147. package/dist/utils/index.d.ts.map +1 -0
  148. package/dist/utils/index.js +27 -0
  149. package/dist/utils/index.js.map +1 -0
  150. package/dist/utils/node-version.d.ts +20 -0
  151. package/dist/utils/node-version.d.ts.map +1 -0
  152. package/dist/utils/node-version.js +113 -0
  153. package/dist/utils/node-version.js.map +1 -0
  154. package/dist/utils/process.d.ts +25 -0
  155. package/dist/utils/process.d.ts.map +1 -0
  156. package/dist/utils/process.js +40 -0
  157. package/dist/utils/process.js.map +1 -0
  158. package/dist/utils/reserved-env.d.ts +26 -0
  159. package/dist/utils/reserved-env.d.ts.map +1 -0
  160. package/dist/utils/reserved-env.js +51 -0
  161. package/dist/utils/reserved-env.js.map +1 -0
  162. package/dist/utils/template.d.ts +15 -0
  163. package/dist/utils/template.d.ts.map +1 -0
  164. package/dist/utils/template.js +75 -0
  165. package/dist/utils/template.js.map +1 -0
  166. package/dist/utils/version.d.ts +9 -0
  167. package/dist/utils/version.d.ts.map +1 -0
  168. package/dist/utils/version.js +52 -0
  169. package/dist/utils/version.js.map +1 -0
  170. package/dist/wrangler.d.ts +192 -0
  171. package/dist/wrangler.d.ts.map +1 -0
  172. package/dist/wrangler.js +246 -0
  173. package/dist/wrangler.js.map +1 -0
  174. package/package.json +47 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Webflow, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # @webflow/cloud-app
2
+
3
+ Build a JS framework app into a [Webflow Cloud](https://webflow.com) bundle that
4
+ runs on Cloudflare Workers — **without your app having to know anything about
5
+ Cloudflare.**
6
+
7
+ You declare what you need in `webflow.json`. `@webflow/cloud-app` figures out your
8
+ framework (Vite, Next.js, Astro), injects the right Cloudflare adapter and
9
+ config, runs the build, and produces a worker-ready output directory. No
10
+ `wrangler.json`, no adapter packages in your `package.json`, no generated config
11
+ files in your tree — all of that happens in an ephemeral build workspace.
12
+
13
+ This is the same engine the Webflow CLI and Webflow Cloud's server-side builder
14
+ use, so a build is identical wherever it runs.
15
+
16
+ > **Status:** early. The public API and the host port seam below are stable; the
17
+ > framework build pipeline is being extracted from the canonical
18
+ > (cosmic-builder) implementation. `buildApp` throws `NotImplementedError` until
19
+ > that lands.
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ npm install @webflow/cloud-app
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```ts
30
+ import { buildApp, consoleLogger, nodeCommandRunner } from '@webflow/cloud-app';
31
+
32
+ const result = await buildApp({
33
+ projectDir: process.cwd(),
34
+ outputDir: './.webflow-output',
35
+ ports: {
36
+ logger: consoleLogger,
37
+ runCommand: nodeCommandRunner,
38
+ // telemetry + fs fall back to no-op / node defaults
39
+ },
40
+ });
41
+
42
+ console.log(result.framework, result.deploymentType, result.entrypointPath);
43
+ ```
44
+
45
+ ## Ports — running the same engine anywhere
46
+
47
+ Everything environment-specific is injected, so the engine itself is pure build
48
+ logic and stays public-safe (no auth, upload, secrets, or vendor SDKs baked in).
49
+
50
+ | Port | Required | Default | Why a host overrides it |
51
+ | ------------ | -------- | ----------------------------------------- | ---------------------------------------------------------------------- |
52
+ | `logger` | yes | `consoleLogger` / `silentLogger` provided | route output into oclif spinners, ECS structured logs, etc. |
53
+ | `runCommand` | yes | `nodeCommandRunner` provided | control/sandbox how `npm`, the framework build, and `wrangler` execute |
54
+ | `telemetry` | no | `noopTelemetry` | wrap `dd-trace` so existing dashboards keep working |
55
+ | `fs` | no | `nodeFileSystem` | plug in a virtual filesystem (e.g. browser-based agents) |
56
+
57
+ ## `webflow.json`
58
+
59
+ The only Webflow-owned file in your project. Framework is auto-detected (you can
60
+ pin it) and **bindings are declared here** rather than in `wrangler.json`:
61
+
62
+ ```jsonc
63
+ {
64
+ "cloud": {
65
+ "framework": "nextjs",
66
+ "bindings": {
67
+ "kv": [{ "binding": "MY_KV" }],
68
+ "r2": [{ "binding": "MY_BUCKET", "bucket_name": "my-bucket" }],
69
+ "d1": [{ "binding": "DB", "database_name": "app-db", "migrations_dir": "./migrations" }],
70
+ },
71
+ },
72
+ }
73
+ ```
74
+
75
+ You declare the binding name (and, for R2/D1, the resource name) — Webflow Cloud
76
+ provisions the resource and namespaces it per environment. KV ids / D1
77
+ `database_id`s are assigned for you; omit them. Limits: up to 5 of each type; R2
78
+ bucket names are lowercase alphanumeric + hyphens, ≤27 chars. (`vars` is not
79
+ supported yet — it needs deployer support to propagate.)
80
+
81
+ The deploy-contract fields (`contract_version`, `framework`, `deployment_type`,
82
+ `entrypoint_path`, `skip_no_bundle`) are filled in by the build and validated
83
+ against [`@webflow/cosmic-deploy-contract`](https://www.npmjs.com/package/@webflow/cosmic-deploy-contract)
84
+ before output is produced.
85
+
86
+ ## Development
87
+
88
+ ```bash
89
+ npm install # from the monorepo root
90
+ npm test # jest
91
+ npm run build # tsc → dist/
92
+ npm run type-check
93
+ ```
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Cloud resource bindings declared in `webflow.json`.
3
+ *
4
+ * NEW in @webflow/cloud-app: users declare KV / R2 / D1 bindings under
5
+ * `cloud.bindings` in webflow.json instead of hand-writing wrangler.json (which
6
+ * is now internal). The engine validates them and synthesizes a wrangler-shaped
7
+ * bridge (clouduser.wrangler.json) that the existing deployer consumes
8
+ * unchanged — the deployer namespaces resources as `<APP_NAME>-<name>` and
9
+ * fills in the real ids, so the placeholder ids below only need to satisfy the
10
+ * build-phase wrangler schema + dry-run.
11
+ *
12
+ * `vars` are intentionally NOT supported yet: the deployer's
13
+ * `processWranglerBindings` ships only d1/kv/r2 and drops everything else, so
14
+ * vars wouldn't survive to deploy without a deployer change.
15
+ */
16
+ import { z } from 'zod';
17
+ import type { WranglerJson } from './wrangler';
18
+ /** Max number of each binding type, matching the deployer's limits. */
19
+ export declare const MAX_BINDINGS_PER_TYPE = 5;
20
+ export declare const KvBindingSchema: z.ZodObject<{
21
+ binding: z.ZodString;
22
+ id: z.ZodOptional<z.ZodString>;
23
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
24
+ binding: z.ZodString;
25
+ id: z.ZodOptional<z.ZodString>;
26
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
27
+ binding: z.ZodString;
28
+ id: z.ZodOptional<z.ZodString>;
29
+ }, z.ZodTypeAny, "passthrough">>;
30
+ export declare const R2BindingSchema: z.ZodObject<{
31
+ binding: z.ZodString;
32
+ bucket_name: z.ZodString;
33
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
34
+ binding: z.ZodString;
35
+ bucket_name: z.ZodString;
36
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
37
+ binding: z.ZodString;
38
+ bucket_name: z.ZodString;
39
+ }, z.ZodTypeAny, "passthrough">>;
40
+ export declare const D1BindingSchema: z.ZodObject<{
41
+ binding: z.ZodString;
42
+ database_name: z.ZodString;
43
+ database_id: z.ZodOptional<z.ZodString>;
44
+ migrations_dir: z.ZodOptional<z.ZodString>;
45
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
46
+ binding: z.ZodString;
47
+ database_name: z.ZodString;
48
+ database_id: z.ZodOptional<z.ZodString>;
49
+ migrations_dir: z.ZodOptional<z.ZodString>;
50
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
51
+ binding: z.ZodString;
52
+ database_name: z.ZodString;
53
+ database_id: z.ZodOptional<z.ZodString>;
54
+ migrations_dir: z.ZodOptional<z.ZodString>;
55
+ }, z.ZodTypeAny, "passthrough">>;
56
+ export declare const BindingsSchema: z.ZodObject<{
57
+ kv: z.ZodOptional<z.ZodArray<z.ZodObject<{
58
+ binding: z.ZodString;
59
+ id: z.ZodOptional<z.ZodString>;
60
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
61
+ binding: z.ZodString;
62
+ id: z.ZodOptional<z.ZodString>;
63
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
64
+ binding: z.ZodString;
65
+ id: z.ZodOptional<z.ZodString>;
66
+ }, z.ZodTypeAny, "passthrough">>, "many">>;
67
+ r2: z.ZodOptional<z.ZodArray<z.ZodObject<{
68
+ binding: z.ZodString;
69
+ bucket_name: z.ZodString;
70
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
71
+ binding: z.ZodString;
72
+ bucket_name: z.ZodString;
73
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
74
+ binding: z.ZodString;
75
+ bucket_name: z.ZodString;
76
+ }, z.ZodTypeAny, "passthrough">>, "many">>;
77
+ d1: z.ZodOptional<z.ZodArray<z.ZodObject<{
78
+ binding: z.ZodString;
79
+ database_name: z.ZodString;
80
+ database_id: z.ZodOptional<z.ZodString>;
81
+ migrations_dir: z.ZodOptional<z.ZodString>;
82
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
83
+ binding: z.ZodString;
84
+ database_name: z.ZodString;
85
+ database_id: z.ZodOptional<z.ZodString>;
86
+ migrations_dir: z.ZodOptional<z.ZodString>;
87
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
88
+ binding: z.ZodString;
89
+ database_name: z.ZodString;
90
+ database_id: z.ZodOptional<z.ZodString>;
91
+ migrations_dir: z.ZodOptional<z.ZodString>;
92
+ }, z.ZodTypeAny, "passthrough">>, "many">>;
93
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
94
+ kv: z.ZodOptional<z.ZodArray<z.ZodObject<{
95
+ binding: z.ZodString;
96
+ id: z.ZodOptional<z.ZodString>;
97
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
98
+ binding: z.ZodString;
99
+ id: z.ZodOptional<z.ZodString>;
100
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
101
+ binding: z.ZodString;
102
+ id: z.ZodOptional<z.ZodString>;
103
+ }, z.ZodTypeAny, "passthrough">>, "many">>;
104
+ r2: z.ZodOptional<z.ZodArray<z.ZodObject<{
105
+ binding: z.ZodString;
106
+ bucket_name: z.ZodString;
107
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
108
+ binding: z.ZodString;
109
+ bucket_name: z.ZodString;
110
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
111
+ binding: z.ZodString;
112
+ bucket_name: z.ZodString;
113
+ }, z.ZodTypeAny, "passthrough">>, "many">>;
114
+ d1: z.ZodOptional<z.ZodArray<z.ZodObject<{
115
+ binding: z.ZodString;
116
+ database_name: z.ZodString;
117
+ database_id: z.ZodOptional<z.ZodString>;
118
+ migrations_dir: z.ZodOptional<z.ZodString>;
119
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
120
+ binding: z.ZodString;
121
+ database_name: z.ZodString;
122
+ database_id: z.ZodOptional<z.ZodString>;
123
+ migrations_dir: z.ZodOptional<z.ZodString>;
124
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
125
+ binding: z.ZodString;
126
+ database_name: z.ZodString;
127
+ database_id: z.ZodOptional<z.ZodString>;
128
+ migrations_dir: z.ZodOptional<z.ZodString>;
129
+ }, z.ZodTypeAny, "passthrough">>, "many">>;
130
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
131
+ kv: z.ZodOptional<z.ZodArray<z.ZodObject<{
132
+ binding: z.ZodString;
133
+ id: z.ZodOptional<z.ZodString>;
134
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
135
+ binding: z.ZodString;
136
+ id: z.ZodOptional<z.ZodString>;
137
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
138
+ binding: z.ZodString;
139
+ id: z.ZodOptional<z.ZodString>;
140
+ }, z.ZodTypeAny, "passthrough">>, "many">>;
141
+ r2: z.ZodOptional<z.ZodArray<z.ZodObject<{
142
+ binding: z.ZodString;
143
+ bucket_name: z.ZodString;
144
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
145
+ binding: z.ZodString;
146
+ bucket_name: z.ZodString;
147
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
148
+ binding: z.ZodString;
149
+ bucket_name: z.ZodString;
150
+ }, z.ZodTypeAny, "passthrough">>, "many">>;
151
+ d1: z.ZodOptional<z.ZodArray<z.ZodObject<{
152
+ binding: z.ZodString;
153
+ database_name: z.ZodString;
154
+ database_id: z.ZodOptional<z.ZodString>;
155
+ migrations_dir: z.ZodOptional<z.ZodString>;
156
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
157
+ binding: z.ZodString;
158
+ database_name: z.ZodString;
159
+ database_id: z.ZodOptional<z.ZodString>;
160
+ migrations_dir: z.ZodOptional<z.ZodString>;
161
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
162
+ binding: z.ZodString;
163
+ database_name: z.ZodString;
164
+ database_id: z.ZodOptional<z.ZodString>;
165
+ migrations_dir: z.ZodOptional<z.ZodString>;
166
+ }, z.ZodTypeAny, "passthrough">>, "many">>;
167
+ }, z.ZodTypeAny, "passthrough">>;
168
+ export type WebflowBindings = z.infer<typeof BindingsSchema>;
169
+ /** Parse the raw `cloud.bindings` block. Returns undefined if it's absent/invalid-shaped. */
170
+ export declare function parseBindings(raw: unknown): WebflowBindings | undefined;
171
+ /** Whether the binding block declares at least one binding. */
172
+ export declare function hasAnyBindings(bindings: WebflowBindings | undefined): boolean;
173
+ /** Validate an R2 bucket name (rules from Cloudflare; 27-char cap leaves room for the app-name prefix). */
174
+ export declare function validateR2BucketName(name: string): void;
175
+ /** Enforce per-type count limits and R2 naming rules. Mirrors the deployer's checks. */
176
+ export declare function validateBindings(bindings: WebflowBindings): void;
177
+ /**
178
+ * Synthesize the wrangler-shaped binding bridge from webflow.json bindings.
179
+ *
180
+ * Produces the same shape the build pipeline would otherwise read from a user's
181
+ * wrangler.json: `name` + `compatibility_date` (placeholders the deployer
182
+ * ignores) plus the kv/r2/d1 arrays with placeholder ids.
183
+ */
184
+ export declare function bindingsToWranglerJson(bindings: WebflowBindings, name?: string): WranglerJson;
185
+ //# sourceMappingURL=bindings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bindings.d.ts","sourceRoot":"","sources":["../src/bindings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,uEAAuE;AACvE,eAAO,MAAM,qBAAqB,IAAI,CAAC;AASvC,eAAO,MAAM,eAAe;;;;;;;;;gCAEZ,CAAC;AACjB,eAAO,MAAM,eAAe;;;;;;;;;gCAEZ,CAAC;AACjB,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;gCAOZ,CAAC;AAEjB,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCAMX,CAAC;AAEjB,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAE7D,6FAA6F;AAC7F,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,GAAG,SAAS,CAGvE;AAED,+DAA+D;AAC/D,wBAAgB,cAAc,CAAC,QAAQ,EAAE,eAAe,GAAG,SAAS,GAAG,OAAO,CAG7E;AAED,2GAA2G;AAC3G,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAgBvD;AAED,wFAAwF;AACxF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAmBhE;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,eAAe,EACzB,IAAI,SAAgB,GACnB,YAAY,CAmBd"}
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BindingsSchema = exports.D1BindingSchema = exports.R2BindingSchema = exports.KvBindingSchema = exports.MAX_BINDINGS_PER_TYPE = void 0;
4
+ exports.parseBindings = parseBindings;
5
+ exports.hasAnyBindings = hasAnyBindings;
6
+ exports.validateR2BucketName = validateR2BucketName;
7
+ exports.validateBindings = validateBindings;
8
+ exports.bindingsToWranglerJson = bindingsToWranglerJson;
9
+ /**
10
+ * Cloud resource bindings declared in `webflow.json`.
11
+ *
12
+ * NEW in @webflow/cloud-app: users declare KV / R2 / D1 bindings under
13
+ * `cloud.bindings` in webflow.json instead of hand-writing wrangler.json (which
14
+ * is now internal). The engine validates them and synthesizes a wrangler-shaped
15
+ * bridge (clouduser.wrangler.json) that the existing deployer consumes
16
+ * unchanged — the deployer namespaces resources as `<APP_NAME>-<name>` and
17
+ * fills in the real ids, so the placeholder ids below only need to satisfy the
18
+ * build-phase wrangler schema + dry-run.
19
+ *
20
+ * `vars` are intentionally NOT supported yet: the deployer's
21
+ * `processWranglerBindings` ships only d1/kv/r2 and drops everything else, so
22
+ * vars wouldn't survive to deploy without a deployer change.
23
+ */
24
+ const zod_1 = require("zod");
25
+ const errors_1 = require("./frameworks/errors");
26
+ /** Max number of each binding type, matching the deployer's limits. */
27
+ exports.MAX_BINDINGS_PER_TYPE = 5;
28
+ // Cloudflare assigns the real ids at deploy time; these only satisfy the
29
+ // build-phase wrangler schema + `wrangler deploy --dry-run`.
30
+ const KV_ID_PLACEHOLDER = '0'.repeat(32);
31
+ const D1_ID_PLACEHOLDER = '00000000-0000-0000-0000-000000000000';
32
+ // `binding` is the JS binding name (e.g. `env.MY_KV`). `id` / `database_id` are
33
+ // optional — users normally omit them (the deployer assigns real ones).
34
+ exports.KvBindingSchema = zod_1.z
35
+ .object({ binding: zod_1.z.string(), id: zod_1.z.string().optional() })
36
+ .passthrough();
37
+ exports.R2BindingSchema = zod_1.z
38
+ .object({ binding: zod_1.z.string(), bucket_name: zod_1.z.string() })
39
+ .passthrough();
40
+ exports.D1BindingSchema = zod_1.z
41
+ .object({
42
+ binding: zod_1.z.string(),
43
+ database_name: zod_1.z.string(),
44
+ database_id: zod_1.z.string().optional(),
45
+ migrations_dir: zod_1.z.string().optional(),
46
+ })
47
+ .passthrough();
48
+ exports.BindingsSchema = zod_1.z
49
+ .object({
50
+ kv: zod_1.z.array(exports.KvBindingSchema).optional(),
51
+ r2: zod_1.z.array(exports.R2BindingSchema).optional(),
52
+ d1: zod_1.z.array(exports.D1BindingSchema).optional(),
53
+ })
54
+ .passthrough();
55
+ /** Parse the raw `cloud.bindings` block. Returns undefined if it's absent/invalid-shaped. */
56
+ function parseBindings(raw) {
57
+ const result = exports.BindingsSchema.safeParse(raw);
58
+ return result.success ? result.data : undefined;
59
+ }
60
+ /** Whether the binding block declares at least one binding. */
61
+ function hasAnyBindings(bindings) {
62
+ if (!bindings)
63
+ return false;
64
+ return Boolean(bindings.kv?.length || bindings.r2?.length || bindings.d1?.length);
65
+ }
66
+ /** Validate an R2 bucket name (rules from Cloudflare; 27-char cap leaves room for the app-name prefix). */
67
+ function validateR2BucketName(name) {
68
+ if (!/^[a-z0-9-]+$/.test(name)) {
69
+ throw new errors_1.FrameworkConfigError(`Invalid object storage bucket name ${JSON.stringify(name)}: Only lowercase letters, numbers, and hyphens are allowed.`);
70
+ }
71
+ if (name.startsWith('-') || name.endsWith('-')) {
72
+ throw new errors_1.FrameworkConfigError(`Invalid object storage bucket name "${name}": Cannot begin or end with a hyphen.`);
73
+ }
74
+ if (name.length > 27) {
75
+ throw new errors_1.FrameworkConfigError(`Invalid object storage bucket name "${name}": Must be 27 characters or fewer (currently ${name.length} characters).`);
76
+ }
77
+ }
78
+ /** Enforce per-type count limits and R2 naming rules. Mirrors the deployer's checks. */
79
+ function validateBindings(bindings) {
80
+ if ((bindings.kv?.length ?? 0) > exports.MAX_BINDINGS_PER_TYPE) {
81
+ throw new errors_1.FrameworkConfigError(`Too many KV namespaces configured: ${bindings.kv.length}. Maximum allowed is ${exports.MAX_BINDINGS_PER_TYPE}.`);
82
+ }
83
+ if ((bindings.d1?.length ?? 0) > exports.MAX_BINDINGS_PER_TYPE) {
84
+ throw new errors_1.FrameworkConfigError(`Too many D1 databases configured: ${bindings.d1.length}. Maximum allowed is ${exports.MAX_BINDINGS_PER_TYPE}.`);
85
+ }
86
+ if ((bindings.r2?.length ?? 0) > exports.MAX_BINDINGS_PER_TYPE) {
87
+ throw new errors_1.FrameworkConfigError(`Too many R2 buckets configured: ${bindings.r2.length}. Maximum allowed is ${exports.MAX_BINDINGS_PER_TYPE}.`);
88
+ }
89
+ for (const bucket of bindings.r2 ?? []) {
90
+ validateR2BucketName(bucket.bucket_name);
91
+ }
92
+ }
93
+ /**
94
+ * Synthesize the wrangler-shaped binding bridge from webflow.json bindings.
95
+ *
96
+ * Produces the same shape the build pipeline would otherwise read from a user's
97
+ * wrangler.json: `name` + `compatibility_date` (placeholders the deployer
98
+ * ignores) plus the kv/r2/d1 arrays with placeholder ids.
99
+ */
100
+ function bindingsToWranglerJson(bindings, name = 'webflow-app') {
101
+ return {
102
+ name,
103
+ compatibility_date: '2025-01-01',
104
+ kv_namespaces: (bindings.kv ?? []).map((k) => ({
105
+ binding: k.binding,
106
+ id: k.id ?? KV_ID_PLACEHOLDER,
107
+ })),
108
+ r2_buckets: (bindings.r2 ?? []).map((r) => ({
109
+ binding: r.binding,
110
+ bucket_name: r.bucket_name,
111
+ })),
112
+ d1_databases: (bindings.d1 ?? []).map((d) => ({
113
+ binding: d.binding,
114
+ database_name: d.database_name,
115
+ database_id: d.database_id ?? D1_ID_PLACEHOLDER,
116
+ ...(d.migrations_dir ? { migrations_dir: d.migrations_dir } : {}),
117
+ })),
118
+ };
119
+ }
120
+ //# sourceMappingURL=bindings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bindings.js","sourceRoot":"","sources":["../src/bindings.ts"],"names":[],"mappings":";;;AAwDA,sCAGC;AAGD,wCAGC;AAGD,oDAgBC;AAGD,4CAmBC;AASD,wDAsBC;AAzID;;;;;;;;;;;;;;GAcG;AACH,6BAAwB;AAExB,gDAA2D;AAG3D,uEAAuE;AAC1D,QAAA,qBAAqB,GAAG,CAAC,CAAC;AAEvC,yEAAyE;AACzE,6DAA6D;AAC7D,MAAM,iBAAiB,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACzC,MAAM,iBAAiB,GAAG,sCAAsC,CAAC;AAEjE,gFAAgF;AAChF,wEAAwE;AAC3D,QAAA,eAAe,GAAG,OAAC;KAC7B,MAAM,CAAC,EAAE,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC;KAC1D,WAAW,EAAE,CAAC;AACJ,QAAA,eAAe,GAAG,OAAC;KAC7B,MAAM,CAAC,EAAE,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,CAAC;KACxD,WAAW,EAAE,CAAC;AACJ,QAAA,eAAe,GAAG,OAAC;KAC7B,MAAM,CAAC;IACN,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;IACnB,aAAa,EAAE,OAAC,CAAC,MAAM,EAAE;IACzB,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,cAAc,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACtC,CAAC;KACD,WAAW,EAAE,CAAC;AAEJ,QAAA,cAAc,GAAG,OAAC;KAC5B,MAAM,CAAC;IACN,EAAE,EAAE,OAAC,CAAC,KAAK,CAAC,uBAAe,CAAC,CAAC,QAAQ,EAAE;IACvC,EAAE,EAAE,OAAC,CAAC,KAAK,CAAC,uBAAe,CAAC,CAAC,QAAQ,EAAE;IACvC,EAAE,EAAE,OAAC,CAAC,KAAK,CAAC,uBAAe,CAAC,CAAC,QAAQ,EAAE;CACxC,CAAC;KACD,WAAW,EAAE,CAAC;AAIjB,6FAA6F;AAC7F,SAAgB,aAAa,CAAC,GAAY;IACxC,MAAM,MAAM,GAAG,sBAAc,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC7C,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AAClD,CAAC;AAED,+DAA+D;AAC/D,SAAgB,cAAc,CAAC,QAAqC;IAClE,IAAI,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5B,OAAO,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,IAAI,QAAQ,CAAC,EAAE,EAAE,MAAM,IAAI,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;AACpF,CAAC;AAED,2GAA2G;AAC3G,SAAgB,oBAAoB,CAAC,IAAY;IAC/C,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,6BAAoB,CAC5B,sCAAsC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,6DAA6D,CACxH,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,6BAAoB,CAC5B,uCAAuC,IAAI,uCAAuC,CACnF,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACrB,MAAM,IAAI,6BAAoB,CAC5B,uCAAuC,IAAI,gDAAgD,IAAI,CAAC,MAAM,eAAe,CACtH,CAAC;IACJ,CAAC;AACH,CAAC;AAED,wFAAwF;AACxF,SAAgB,gBAAgB,CAAC,QAAyB;IACxD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,6BAAqB,EAAE,CAAC;QACvD,MAAM,IAAI,6BAAoB,CAC5B,sCAAsC,QAAQ,CAAC,EAAG,CAAC,MAAM,wBAAwB,6BAAqB,GAAG,CAC1G,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,6BAAqB,EAAE,CAAC;QACvD,MAAM,IAAI,6BAAoB,CAC5B,qCAAqC,QAAQ,CAAC,EAAG,CAAC,MAAM,wBAAwB,6BAAqB,GAAG,CACzG,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,6BAAqB,EAAE,CAAC;QACvD,MAAM,IAAI,6BAAoB,CAC5B,mCAAmC,QAAQ,CAAC,EAAG,CAAC,MAAM,wBAAwB,6BAAqB,GAAG,CACvG,CAAC;IACJ,CAAC;IACD,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC;QACvC,oBAAoB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,sBAAsB,CACpC,QAAyB,EACzB,IAAI,GAAG,aAAa;IAEpB,OAAO;QACL,IAAI;QACJ,kBAAkB,EAAE,YAAY;QAChC,aAAa,EAAE,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC7C,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,iBAAiB;SAC9B,CAAC,CAAC;QACH,UAAU,EAAE,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC1C,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,WAAW,EAAE,CAAC,CAAC,WAAW;SAC3B,CAAC,CAAC;QACH,YAAY,EAAE,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC5C,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,aAAa,EAAE,CAAC,CAAC,aAAa;YAC9B,WAAW,EAAE,CAAC,CAAC,WAAW,IAAI,iBAAiB;YAC/C,GAAG,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAClE,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Package.json schema (minimal fields we need).
4
+ *
5
+ * Only the fields used by the framework builder are validated here.
6
+ */
7
+ export declare const PackageJsonSchema: z.ZodObject<{
8
+ /** Package name */
9
+ name: z.ZodOptional<z.ZodString>;
10
+ /** Package version */
11
+ version: z.ZodOptional<z.ZodString>;
12
+ /** Production dependencies (package name -> version specifier) */
13
+ dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
14
+ /** Development dependencies (package name -> version specifier) */
15
+ devDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
16
+ /** Runtime declarations. `node` is deliberately retained as unknown so the
17
+ * toolchain resolver can warn and fall back for a malformed customer
18
+ * declaration rather than rejecting the entire package.json. */
19
+ engines: z.ZodOptional<z.ZodObject<{
20
+ node: z.ZodOptional<z.ZodUnknown>;
21
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
22
+ node: z.ZodOptional<z.ZodUnknown>;
23
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
24
+ node: z.ZodOptional<z.ZodUnknown>;
25
+ }, z.ZodTypeAny, "passthrough">>>;
26
+ }, "strip", z.ZodTypeAny, {
27
+ name?: string | undefined;
28
+ version?: string | undefined;
29
+ dependencies?: Record<string, string> | undefined;
30
+ devDependencies?: Record<string, string> | undefined;
31
+ engines?: z.objectOutputType<{
32
+ node: z.ZodOptional<z.ZodUnknown>;
33
+ }, z.ZodTypeAny, "passthrough"> | undefined;
34
+ }, {
35
+ name?: string | undefined;
36
+ version?: string | undefined;
37
+ dependencies?: Record<string, string> | undefined;
38
+ devDependencies?: Record<string, string> | undefined;
39
+ engines?: z.objectInputType<{
40
+ node: z.ZodOptional<z.ZodUnknown>;
41
+ }, z.ZodTypeAny, "passthrough"> | undefined;
42
+ }>;
43
+ /**
44
+ * Package.json structure (minimal fields we need).
45
+ */
46
+ export type PackageJson = z.infer<typeof PackageJsonSchema>;
47
+ /**
48
+ * Load and validate package.json from `cwd`. Returns `undefined` when the file
49
+ * is absent.
50
+ *
51
+ * NOTE: unlike the original cosmic-builder implementation this does NOT cache
52
+ * across calls — a single long-lived host process (the server-side builder, an
53
+ * MCP server) builds many different projects, so a module-level cache would
54
+ * leak one project's package.json into the next build.
55
+ */
56
+ export declare function loadPackageJson(cwd: string): PackageJson | undefined;
57
+ //# sourceMappingURL=package-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-json.d.ts","sourceRoot":"","sources":["../../src/config/package-json.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,eAAO,MAAM,iBAAiB;IAC5B,mBAAmB;;IAEnB,sBAAsB;;IAEtB,kEAAkE;;IAElE,mEAAmE;;IAEnE;;oEAEgE;;;;;;;;;;;;;;;;;;;;;;;;EAOhE,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAoBpE"}
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.PackageJsonSchema = void 0;
37
+ exports.loadPackageJson = loadPackageJson;
38
+ const fs = __importStar(require("node:fs"));
39
+ const path = __importStar(require("node:path"));
40
+ const zod_1 = require("zod");
41
+ /**
42
+ * Package.json schema (minimal fields we need).
43
+ *
44
+ * Only the fields used by the framework builder are validated here.
45
+ */
46
+ exports.PackageJsonSchema = zod_1.z.object({
47
+ /** Package name */
48
+ name: zod_1.z.string().optional(),
49
+ /** Package version */
50
+ version: zod_1.z.string().optional(),
51
+ /** Production dependencies (package name -> version specifier) */
52
+ dependencies: zod_1.z.record(zod_1.z.string()).optional(),
53
+ /** Development dependencies (package name -> version specifier) */
54
+ devDependencies: zod_1.z.record(zod_1.z.string()).optional(),
55
+ /** Runtime declarations. `node` is deliberately retained as unknown so the
56
+ * toolchain resolver can warn and fall back for a malformed customer
57
+ * declaration rather than rejecting the entire package.json. */
58
+ engines: zod_1.z
59
+ .object({
60
+ node: zod_1.z.unknown().optional(),
61
+ })
62
+ .passthrough()
63
+ .optional(),
64
+ });
65
+ /**
66
+ * Load and validate package.json from `cwd`. Returns `undefined` when the file
67
+ * is absent.
68
+ *
69
+ * NOTE: unlike the original cosmic-builder implementation this does NOT cache
70
+ * across calls — a single long-lived host process (the server-side builder, an
71
+ * MCP server) builds many different projects, so a module-level cache would
72
+ * leak one project's package.json into the next build.
73
+ */
74
+ function loadPackageJson(cwd) {
75
+ const filePath = path.join(cwd, 'package.json');
76
+ if (!fs.statSync(filePath, { throwIfNoEntry: false })) {
77
+ return undefined;
78
+ }
79
+ const raw = fs.readFileSync(filePath).toString('utf8');
80
+ let unparsed;
81
+ try {
82
+ unparsed = JSON.parse(raw);
83
+ }
84
+ catch (e) {
85
+ throw new Error(`package.json was not valid JSON`, { cause: e });
86
+ }
87
+ try {
88
+ return exports.PackageJsonSchema.parse(unparsed);
89
+ }
90
+ catch (e) {
91
+ throw new Error('package.json schema validation failed', { cause: e });
92
+ }
93
+ }
94
+ //# sourceMappingURL=package-json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-json.js","sourceRoot":"","sources":["../../src/config/package-json.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,0CAoBC;AAhED,4CAA8B;AAC9B,gDAAkC;AAElC,6BAAwB;AAExB;;;;GAIG;AACU,QAAA,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC;IACxC,mBAAmB;IACnB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,sBAAsB;IACtB,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,kEAAkE;IAClE,YAAY,EAAE,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IAC7C,mEAAmE;IACnE,eAAe,EAAE,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IAChD;;oEAEgE;IAChE,OAAO,EAAE,OAAC;SACP,MAAM,CAAC;QACN,IAAI,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;KAC7B,CAAC;SACD,WAAW,EAAE;SACb,QAAQ,EAAE;CACd,CAAC,CAAC;AAOH;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAAC,GAAW;IACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IAChD,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QACtD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAEvD,IAAI,QAAiB,CAAC;IACtB,IAAI,CAAC;QACH,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,iCAAiC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;IACnE,CAAC;IAED,IAAI,CAAC;QACH,OAAO,yBAAiB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,uCAAuC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;IACzE,CAAC;AACH,CAAC"}
@@ -0,0 +1,53 @@
1
+ import type { Logger } from '../ports';
2
+ import type { WebflowBindings } from '../bindings';
3
+ /**
4
+ * Build-time, permissive view of webflow.json.
5
+ *
6
+ * The user's source webflow.json may not yet contain a complete deploy
7
+ * contract — that's emitted by `createWebflowJson` later in the build. Reads
8
+ * here treat every field as optional and `framework` as an arbitrary `string`
9
+ * (it's user input until the contract validates it at deploy time).
10
+ *
11
+ * Deploy-time reads MUST use `validateForDeploy` from
12
+ * `@webflow/cosmic-deploy-contract`, which is strict and fails fast on contract
13
+ * violations. Do not introduce a second permissive deploy reader here.
14
+ */
15
+ export type WebflowJson = {
16
+ cloud?: {
17
+ /** User-specified or producer-written framework hint. Validated strictly only at deploy time. */
18
+ framework?: string;
19
+ contract_version?: string;
20
+ framework_version?: string;
21
+ entrypoint_path?: string;
22
+ deployment_type?: string;
23
+ skip_no_bundle?: boolean;
24
+ /**
25
+ * User-declared KV / R2 / D1 bindings. The single user-facing place to
26
+ * declare bindings (replacing hand-written wrangler.json). Parsed/validated
27
+ * by `bindings.ts` and synthesized into the wrangler bridge at build time.
28
+ */
29
+ bindings?: WebflowBindings;
30
+ /**
31
+ * Build-only: URL prefix for static assets. NOT part of the deploy contract.
32
+ */
33
+ assets_path_prefix?: string;
34
+ /**
35
+ * Build-only: skip appending the mount path to the assets source dir
36
+ * (Astro 6 writes to `dist/client/` regardless of mount config). NOT part
37
+ * of the deploy contract.
38
+ */
39
+ assets_source_skip_mount_path?: boolean;
40
+ [key: string]: unknown;
41
+ };
42
+ [key: string]: unknown;
43
+ };
44
+ /**
45
+ * Load and JSONC-parse webflow.json (or webflow.jsonc) at `cwd`.
46
+ *
47
+ * Returns `undefined` when the file is absent or fails to parse as JSONC.
48
+ * Intentionally permissive — used by build-phase code that reads optional hints
49
+ * (user-specified framework, build-only flags). The deploy phase uses
50
+ * `validateForDeploy` from the contract package instead.
51
+ */
52
+ export declare function loadWebflowJson(log: Logger, cwd: string, file?: string): WebflowJson | undefined;
53
+ //# sourceMappingURL=webflow-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webflow-json.d.ts","sourceRoot":"","sources":["../../src/config/webflow-json.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,CAAC,EAAE;QACN,iGAAiG;QACjG,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB;;;;WAIG;QACH,QAAQ,CAAC,EAAE,eAAe,CAAC;QAC3B;;WAEG;QACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B;;;;WAIG;QACH,6BAA6B,CAAC,EAAE,OAAO,CAAC;QACxC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;IACF,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,IAAI,SAAiB,GACpB,WAAW,GAAG,SAAS,CAyBzB"}