@spacefast/common 0.0.12 → 0.0.17

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 (189) hide show
  1. package/dist/agents/client-registry.d.ts +22 -0
  2. package/dist/agents/client-registry.js +41 -0
  3. package/dist/agents/connect-targets.d.ts +51 -6
  4. package/dist/agents/connect-targets.js +93 -28
  5. package/dist/brand.d.ts +0 -11
  6. package/dist/brand.js +0 -20
  7. package/dist/config/domains.d.ts +15 -6
  8. package/dist/config/domains.js +24 -10
  9. package/dist/config/postgres-budget.d.ts +3 -0
  10. package/dist/config/postgres-budget.js +6 -1
  11. package/dist/config/postgres-budget.json +2 -1
  12. package/dist/contracts/abuse.js +1 -1
  13. package/dist/contracts/access.d.ts +486 -1196
  14. package/dist/contracts/access.js +323 -1054
  15. package/dist/contracts/activity.d.ts +1 -1
  16. package/dist/contracts/activity.js +11 -15
  17. package/dist/contracts/api-keys.d.ts +16 -0
  18. package/dist/contracts/api-keys.js +11 -9
  19. package/dist/contracts/archives.d.ts +1 -2
  20. package/dist/contracts/archives.js +15 -17
  21. package/dist/contracts/beta.js +1 -1
  22. package/dist/contracts/builds.js +14 -14
  23. package/dist/contracts/channels.js +2 -2
  24. package/dist/contracts/comments.d.ts +143 -99
  25. package/dist/contracts/comments.js +194 -79
  26. package/dist/contracts/common.d.ts +12 -12
  27. package/dist/contracts/common.js +33 -30
  28. package/dist/contracts/continuation.js +5 -5
  29. package/dist/contracts/countries.js +2 -7
  30. package/dist/contracts/data-source-routes.d.ts +20 -0
  31. package/dist/contracts/data-source-routes.js +15 -0
  32. package/dist/contracts/device-auth.d.ts +13 -9
  33. package/dist/contracts/device-auth.js +12 -12
  34. package/dist/contracts/docs.d.ts +10 -10
  35. package/dist/contracts/domains.js +39 -33
  36. package/dist/contracts/enums.d.ts +4 -14
  37. package/dist/contracts/enums.js +3 -10
  38. package/dist/contracts/error-code-meta.d.ts +122 -56
  39. package/dist/contracts/error-code-meta.js +43 -19
  40. package/dist/contracts/error-codes.d.ts +7 -4
  41. package/dist/contracts/error-codes.js +48 -24
  42. package/dist/contracts/events.d.ts +22 -15
  43. package/dist/contracts/events.js +33 -5
  44. package/dist/contracts/execution.d.ts +238 -0
  45. package/dist/contracts/execution.js +309 -0
  46. package/dist/contracts/feature-lifecycle.d.ts +39 -188
  47. package/dist/contracts/feature-lifecycle.js +52 -196
  48. package/dist/contracts/features.d.ts +13 -115
  49. package/dist/contracts/features.js +5 -35
  50. package/dist/contracts/functions.d.ts +597 -0
  51. package/dist/contracts/functions.js +475 -0
  52. package/dist/contracts/grants.d.ts +1175 -0
  53. package/dist/contracts/grants.js +783 -0
  54. package/dist/contracts/ids.d.ts +7 -5
  55. package/dist/contracts/ids.js +7 -7
  56. package/dist/contracts/internal.js +2 -2
  57. package/dist/contracts/mcp.d.ts +17 -556
  58. package/dist/contracts/mcp.js +9 -103
  59. package/dist/contracts/me.js +3 -4
  60. package/dist/contracts/notifications.d.ts +108 -0
  61. package/dist/contracts/notifications.js +54 -0
  62. package/dist/contracts/oauth-resources.d.ts +22 -5
  63. package/dist/contracts/oauth-resources.js +23 -2
  64. package/dist/contracts/operations.d.ts +0 -48
  65. package/dist/contracts/operations.js +0 -19
  66. package/dist/contracts/pages.d.ts +10 -14
  67. package/dist/contracts/pages.js +17 -21
  68. package/dist/contracts/plan-policy.d.ts +1 -8
  69. package/dist/contracts/plan-policy.js +1 -4
  70. package/dist/contracts/platform.d.ts +78 -30
  71. package/dist/contracts/platform.js +69 -20
  72. package/dist/contracts/problem-document.d.ts +14 -0
  73. package/dist/contracts/problem-document.js +35 -0
  74. package/dist/contracts/push-new.d.ts +41 -2
  75. package/dist/contracts/push-new.js +4 -0
  76. package/dist/contracts/quotas.d.ts +0 -1
  77. package/dist/contracts/quotas.js +0 -5
  78. package/dist/contracts/repository-connections.d.ts +1 -1
  79. package/dist/contracts/resources.d.ts +16 -71
  80. package/dist/contracts/resources.js +13 -16
  81. package/dist/contracts/runtime-api.d.ts +666 -303
  82. package/dist/contracts/runtime-api.js +272 -113
  83. package/dist/contracts/runtime-app.d.ts +168 -0
  84. package/dist/contracts/runtime-app.js +42 -0
  85. package/dist/contracts/runtime-db.d.ts +424 -0
  86. package/dist/contracts/runtime-db.js +108 -0
  87. package/dist/contracts/runtime-storage.d.ts +120 -0
  88. package/dist/contracts/runtime-storage.js +40 -0
  89. package/dist/contracts/sf-config-v1.d.ts +54 -1
  90. package/dist/contracts/sf-config-v1.js +2 -2
  91. package/dist/contracts/sites.d.ts +6 -0
  92. package/dist/contracts/sites.js +30 -11
  93. package/dist/contracts/space-config.d.ts +91 -121
  94. package/dist/contracts/space-config.js +464 -42
  95. package/dist/contracts/spaces.d.ts +300 -171
  96. package/dist/contracts/spaces.js +128 -98
  97. package/dist/contracts/superadmin-emails.d.ts +2 -2
  98. package/dist/contracts/superadmin-spaces.d.ts +26 -130
  99. package/dist/contracts/superadmin-spaces.js +22 -0
  100. package/dist/contracts/superadmin-tenants.js +4 -4
  101. package/dist/contracts/superadmin.d.ts +4 -0
  102. package/dist/contracts/superadmin.js +14 -1
  103. package/dist/contracts/tags.d.ts +6 -6
  104. package/dist/contracts/tags.js +1 -1
  105. package/dist/contracts/teams.d.ts +9 -9
  106. package/dist/contracts/teams.js +25 -16
  107. package/dist/contracts/theme-json.js +1 -1
  108. package/dist/contracts/transfers.d.ts +0 -1
  109. package/dist/contracts/transfers.js +4 -4
  110. package/dist/contracts/variables.js +3 -3
  111. package/dist/contracts/zero.d.ts +384 -596
  112. package/dist/contracts/zero.js +167 -299
  113. package/dist/dashboard-paths/index.d.ts +18 -3
  114. package/dist/dashboard-paths/index.js +19 -0
  115. package/dist/docs/agent-handoff-document.d.ts +2 -2
  116. package/dist/docs/agent-handoff-document.js +8 -7
  117. package/dist/docs/agent-prose.d.ts +22 -3
  118. package/dist/docs/agent-prose.js +227 -55
  119. package/dist/docs/agent-setup.d.ts +14 -11
  120. package/dist/docs/agent-setup.js +289 -61
  121. package/dist/docs/agent-solutions.d.ts +6 -6
  122. package/dist/docs/agent-solutions.js +24 -22
  123. package/dist/docs/catalog.d.ts +53 -98
  124. package/dist/docs/catalog.js +90 -117
  125. package/dist/docs/error-docs.js +304 -236
  126. package/dist/docs/skill-distribution.d.ts +2 -0
  127. package/dist/docs/skill-distribution.js +7 -4
  128. package/dist/docs/skills.d.ts +546 -0
  129. package/dist/docs/skills.js +340 -0
  130. package/dist/utils/auth-redirect.d.ts +1 -3
  131. package/dist/utils/auth-redirect.js +1 -21
  132. package/dist/utils/browser-credential.d.ts +19 -0
  133. package/dist/utils/browser-credential.js +62 -0
  134. package/dist/utils/build-settings.d.ts +2 -0
  135. package/dist/utils/build-settings.js +61 -9
  136. package/dist/utils/comment-avatars.d.ts +7 -0
  137. package/dist/utils/comment-avatars.js +42 -0
  138. package/dist/utils/content-type.d.ts +3 -3
  139. package/dist/utils/content-type.js +38 -61
  140. package/dist/utils/credential-policy.d.ts +1 -1
  141. package/dist/utils/credential-policy.js +4 -0
  142. package/dist/utils/domain-diagnostics.d.ts +5 -5
  143. package/dist/utils/domain-diagnostics.js +21 -10
  144. package/dist/utils/egress-policy.fixtures.json +1 -1
  145. package/dist/utils/grants.d.ts +53 -0
  146. package/dist/utils/grants.js +160 -0
  147. package/dist/utils/local-space-state.d.ts +78 -4
  148. package/dist/utils/local-space-state.js +384 -82
  149. package/dist/utils/one-shot-replay.d.ts +14 -0
  150. package/dist/utils/one-shot-replay.js +21 -0
  151. package/dist/utils/page-preview.d.ts +7 -0
  152. package/dist/utils/page-preview.js +9 -0
  153. package/dist/utils/pages.d.ts +2 -5
  154. package/dist/utils/pages.js +64 -33
  155. package/dist/utils/publish-form-data.d.ts +22 -0
  156. package/dist/utils/publish-form-data.js +26 -0
  157. package/dist/utils/publish-policy.d.ts +34 -4
  158. package/dist/utils/publish-policy.js +149 -62
  159. package/dist/utils/query-keys.d.ts +8 -10
  160. package/dist/utils/query-keys.js +14 -10
  161. package/dist/utils/runtime-paths.d.ts +3 -0
  162. package/dist/utils/runtime-paths.js +7 -0
  163. package/dist/utils/secure-local-file.d.ts +73 -0
  164. package/dist/utils/secure-local-file.js +1373 -0
  165. package/dist/utils/space-config.d.ts +17 -4
  166. package/dist/utils/space-config.js +151 -8
  167. package/dist/utils/static-runtime-policy.d.ts +5 -0
  168. package/dist/utils/static-runtime-policy.js +54 -10
  169. package/dist/utils/storage-policy.d.ts +20 -0
  170. package/dist/utils/storage-policy.fixtures.json +174 -0
  171. package/dist/utils/storage-policy.js +193 -0
  172. package/dist/utils/upload-session.d.ts +15 -1
  173. package/dist/utils/upload-session.js +68 -2
  174. package/dist/utils/version-file-browser.d.ts +13 -0
  175. package/dist/utils/version-file-browser.js +59 -0
  176. package/package.json +20 -1
  177. package/dist/contracts/mounts.d.ts +0 -142
  178. package/dist/contracts/mounts.js +0 -56
  179. package/dist/utils/access-grant.d.ts +0 -14
  180. package/dist/utils/access-grant.js +0 -88
  181. package/dist/utils/access-match.d.ts +0 -46
  182. package/dist/utils/access-match.fixtures.json +0 -513
  183. package/dist/utils/access-match.js +0 -312
  184. package/dist/utils/access-verdict.fixtures.json +0 -421
  185. package/dist/utils/asset-fingerprint.d.ts +0 -53
  186. package/dist/utils/asset-fingerprint.js +0 -574
  187. package/dist/utils/sf-config-v1.d.ts +0 -2
  188. package/dist/utils/sf-config-v1.fixtures.json +0 -9
  189. package/dist/utils/sf-config-v1.js +0 -551
@@ -0,0 +1,597 @@
1
+ import { z } from "zod";
2
+ import { runtimeKindSchema, type ExecutionCapabilities } from "./execution.js";
3
+ /**
4
+ * Spacefast Functions: tenant workers run as Cloudflare Dynamic Workers.
5
+ *
6
+ * The shape of this product follows from two constraints that are not
7
+ * negotiable and that together rule out the obvious architecture:
8
+ *
9
+ * 1. **Cloudflare is reached from wp.cloud, never from the control plane.**
10
+ * The control plane records intent; the space's own origin performs every
11
+ * Cloudflare call.
12
+ * 2. **Every asset is served by wp.cloud.** We deliberately decline
13
+ * Cloudflare's static-asset support for user workers. A worker receives
14
+ * only the requests that could not be answered from bytes on disk, and
15
+ * `/_next/static/*` and friends never leave our origin.
16
+ *
17
+ * Dynamic Workers is what makes both hold at once. There is no upload: a
18
+ * version's bundle stays in its own content store on wp.cloud, and the host
19
+ * worker pulls it on demand through the Worker Loader binding. So there is no
20
+ * script lifecycle here — no namespace, no script name, no tag budget, no
21
+ * eviction, no garbage collection — because there is no artefact of ours living
22
+ * on Cloudflare to manage. What Cloudflare holds is a warm isolate, which is a
23
+ * cache, not a record.
24
+ *
25
+ * That also keeps the exit cheap. The contract below is "here is a module
26
+ * graph, here is its configuration, run it", which is workerd's own shape; the
27
+ * managed runtime is an implementation of it rather than the thing we built
28
+ * against.
29
+ *
30
+ * What the worker gets in exchange is the thing we could not build: a real V8
31
+ * isolate that runs npm packages and framework output — OpenNext Next.js among
32
+ * them — without us having to sandbox any of it.
33
+ *
34
+ * The cost is that the worker is a continent away from the space's MySQL.
35
+ * `ctx.db` therefore travels back over an HTTPS relay to the same PHP broker
36
+ * the local tier speaks to over a pipe, which is slower and batched rather
37
+ * than transactional. That is why capsules are a different product rather
38
+ * than a placement option — see `endpointIsPortable` in `./execution.js`.
39
+ */
40
+ export declare const FUNCTIONS_RUNTIME_KIND = "functions";
41
+ export declare const FUNCTIONS_SOURCE_METADATA_KEY = "spacefastFunctions";
42
+ export declare const FUNCTIONS_PLATFORM_ROUTE_PREFIX = "/__spacefast/functions";
43
+ export declare const FUNCTIONS_RUNTIME_ROUTE_PATHS: {
44
+ readonly logs: "/__spacefast/functions/logs";
45
+ /** Where a dispatched worker calls back for brokered capabilities. */
46
+ readonly relay: "/__spacefast/functions/relay";
47
+ };
48
+ /** Public, signed read path. Distinct from storage so the token is never a filename. */
49
+ export declare const FUNCTIONS_BUNDLE_ROUTE_PREFIX = "/__spacefast/functions/b";
50
+ export declare const FUNCTIONS_RUNTIME_STORAGE_ROOT = "__spacefast/functions";
51
+ /**
52
+ * Where a version's compiled bundle lives.
53
+ *
54
+ * Under the same `__spacefast/` prefix as every other platform-owned path, so
55
+ * there is one convention rather than one per product. Two consequences fall
56
+ * out of that placement, and both are wanted:
57
+ *
58
+ * - It is not servable as static content. The runtime treats the whole prefix
59
+ * as control paths, so a tenant's compiled source is not readable at a
60
+ * guessable URL — and the digest that would make it guessable appears in
61
+ * build output.
62
+ * - It is written by the ordinary publish path anyway. The upload policy
63
+ * carves out exactly this subtree (`publish-policy.ts`), so the bundle rides
64
+ * the normal manifest and upload passes instead of needing a parallel one.
65
+ *
66
+ * The dispatch configuration — host, capabilities, relay credential — is not
67
+ * here and is not content at all. The engine writes it beside the version's
68
+ * file tree rather than inside it, exactly as it does for Zero, so a publish
69
+ * cannot reach it: no carve-out, no upload path, nothing to guard. A publish
70
+ * able to write that file would be a publish able to grant itself authority it
71
+ * was never given.
72
+ */
73
+ export declare const FUNCTIONS_RUNTIME_BUNDLE_ROOT = "__spacefast/functions/bundles";
74
+ export declare const FUNCTIONS_BUNDLE_FORMAT = "spacefast.functions.bundle.v1";
75
+ /**
76
+ * Ceiling on a bundle's decoded size.
77
+ *
78
+ * The whole module graph arrives in one response so a cold isolate costs a
79
+ * single round trip, which means this number is also how much the host holds in
80
+ * memory before instantiating anything. Set below the runtime's own script
81
+ * limit so an oversized build fails in our tooling, where we can say which
82
+ * modules are large, rather than at dispatch, where the tenant sees a 502.
83
+ */
84
+ export declare const FUNCTIONS_BUNDLE_MAX_BYTES: number;
85
+ /**
86
+ * A worker's dynamic route table. Anything not matched here is answered from
87
+ * the version's static content by wp.cloud and never reaches Cloudflare, which
88
+ * is both the cheaper path and the one that keeps assets ours.
89
+ */
90
+ export declare const functionsRouteSchema: z.ZodObject<{
91
+ method: z.ZodDefault<z.ZodNullable<z.ZodEnum<{
92
+ POST: "POST";
93
+ PUT: "PUT";
94
+ GET: "GET";
95
+ HEAD: "HEAD";
96
+ PATCH: "PATCH";
97
+ DELETE: "DELETE";
98
+ OPTIONS: "OPTIONS";
99
+ }>>>;
100
+ path: z.ZodString;
101
+ subtree: z.ZodDefault<z.ZodBoolean>;
102
+ }, z.core.$strict>;
103
+ export type FunctionsRoute = z.infer<typeof functionsRouteSchema>;
104
+ /**
105
+ * One module in a bundle, in the shape the Worker Loader consumes.
106
+ *
107
+ * `commonjs` exists because bundlers still emit it and rejecting it would fail
108
+ * builds for a format the runtime accepts. Binary module types are deliberately
109
+ * absent: nothing we build today emits them, and adding one later is additive.
110
+ */
111
+ export declare const functionsBundleModuleSchema: z.ZodUnion<readonly [z.ZodObject<{
112
+ js: z.ZodString;
113
+ }, z.core.$strict>, z.ZodObject<{
114
+ cjs: z.ZodString;
115
+ }, z.core.$strict>, z.ZodObject<{
116
+ text: z.ZodString;
117
+ }, z.core.$strict>, z.ZodObject<{
118
+ json: z.ZodUnknown;
119
+ }, z.core.$strict>]>;
120
+ export type FunctionsBundleModule = z.infer<typeof functionsBundleModuleSchema>;
121
+ /**
122
+ * The document served at a bundle URL and parsed by the host.
123
+ *
124
+ * Both sides of that exchange validate against this schema, which is the point
125
+ * of it living here: the CLI's bundler and the host's loader are separate
126
+ * deployments that must agree, and the only thing keeping them honest is a
127
+ * shared definition of the bytes in between.
128
+ */
129
+ export declare const functionsBundleManifestSchema: z.ZodObject<{
130
+ format: z.ZodLiteral<"spacefast.functions.bundle.v1">;
131
+ mainModule: z.ZodString;
132
+ modules: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
133
+ js: z.ZodString;
134
+ }, z.core.$strict>, z.ZodObject<{
135
+ cjs: z.ZodString;
136
+ }, z.core.$strict>, z.ZodObject<{
137
+ text: z.ZodString;
138
+ }, z.core.$strict>, z.ZodObject<{
139
+ json: z.ZodUnknown;
140
+ }, z.core.$strict>]>>;
141
+ }, z.core.$strict>;
142
+ export type FunctionsBundleManifest = z.infer<typeof functionsBundleManifestSchema>;
143
+ /**
144
+ * Where the worker's compiled bytes live in the version's own content store.
145
+ * Unlike Zero's bundles these are not carried inline in the finalize payload:
146
+ * framework output routinely runs to megabytes, and inlining it would put the
147
+ * whole thing through the control plane, which the direct-from-wp.cloud rule
148
+ * forbids.
149
+ */
150
+ export declare const functionsBundleRefSchema: z.ZodObject<{
151
+ path: z.ZodString;
152
+ sha256: z.ZodString;
153
+ size: z.ZodNumber;
154
+ }, z.core.$strict>;
155
+ export type FunctionsBundleRef = z.infer<typeof functionsBundleRefSchema>;
156
+ /**
157
+ * The path a bundle is served from.
158
+ *
159
+ * Content-addressed, so the response is immutable and can be cached at our edge
160
+ * forever — a cold isolate anywhere in the world costs one CDN hit rather than
161
+ * a round trip to the space's origin.
162
+ *
163
+ * The token rides in the path rather than the query string for exactly that
164
+ * reason: a query parameter is subject to cache-key normalisation, and a token
165
+ * that gets stripped from the key would let one space's cached bundle answer
166
+ * another space's URL.
167
+ *
168
+ * Both halves are load-bearing. The digest alone is unguessable to anyone who
169
+ * lacks the bytes, but it is derivable by anyone who *has* them, and it shows up
170
+ * in build output and `sf runtime status`. The token adds the dimension the
171
+ * digest cannot: holding the code does not entitle you to fetch it from us, and
172
+ * rotating the site secret invalidates every URL at once.
173
+ */
174
+ export declare function functionsBundlePath(input: {
175
+ sha256: string;
176
+ token: string;
177
+ }): string;
178
+ /**
179
+ * Where the bundle actually sits in the published version — the same path minus
180
+ * the token segment. The token authorises the read; it does not name the file,
181
+ * so rotating the signing key changes every URL without moving a single byte.
182
+ */
183
+ export declare function functionsBundleStoragePath(input: {
184
+ sha256: string;
185
+ }): string;
186
+ export declare const functionsWorkerArtifactSchema: z.ZodObject<{
187
+ format: z.ZodLiteral<"spacefast.functions.worker.v1">;
188
+ appName: z.ZodString;
189
+ entry: z.ZodString;
190
+ mainModule: z.ZodString;
191
+ bundle: z.ZodObject<{
192
+ path: z.ZodString;
193
+ sha256: z.ZodString;
194
+ size: z.ZodNumber;
195
+ }, z.core.$strict>;
196
+ compatibilityDate: z.ZodString;
197
+ compatibilityFlags: z.ZodDefault<z.ZodArray<z.ZodString>>;
198
+ routes: z.ZodDefault<z.ZodArray<z.ZodObject<{
199
+ method: z.ZodDefault<z.ZodNullable<z.ZodEnum<{
200
+ POST: "POST";
201
+ PUT: "PUT";
202
+ GET: "GET";
203
+ HEAD: "HEAD";
204
+ PATCH: "PATCH";
205
+ DELETE: "DELETE";
206
+ OPTIONS: "OPTIONS";
207
+ }>>>;
208
+ path: z.ZodString;
209
+ subtree: z.ZodDefault<z.ZodBoolean>;
210
+ }, z.core.$strict>>>;
211
+ capabilities: z.ZodDefault<z.ZodObject<{
212
+ db: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
213
+ fetch: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
214
+ auth: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
215
+ env: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
216
+ realtime: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
217
+ logging: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
218
+ }, z.core.$strip>>;
219
+ }, z.core.$strict>;
220
+ export type FunctionsWorkerArtifact = z.infer<typeof functionsWorkerArtifactSchema>;
221
+ /**
222
+ * The authority a dispatched worker may exercise, in the vocabulary the host
223
+ * speaks on the wire.
224
+ *
225
+ * Deliberately a different, narrower list than `executionCapabilitiesSchema`.
226
+ * That one records what a build *declared* it uses; this one is what the origin
227
+ * *grants*, resolved by the control plane at finalize so the origin forwards a
228
+ * decision rather than making one. Anything absent fails closed at the relay.
229
+ */
230
+ export declare const FUNCTIONS_DISPATCH_CAPABILITIES: readonly ["db.read", "db.write", "fetch", "log"];
231
+ export declare const functionsDispatchCapabilitySchema: z.ZodEnum<{
232
+ fetch: "fetch";
233
+ "db.read": "db.read";
234
+ "db.write": "db.write";
235
+ log: "log";
236
+ }>;
237
+ export type FunctionsDispatchCapability = z.infer<typeof functionsDispatchCapabilitySchema>;
238
+ /**
239
+ * Resolves a build's declared capabilities into the grant a dispatch carries.
240
+ *
241
+ * Three of the six declared capabilities have no dispatch counterpart, and each
242
+ * for its own reason:
243
+ *
244
+ * - `env` is not a runtime call at all. Values are resolved at finalize and
245
+ * travel in the config, so a worker reading `env` reaches nothing.
246
+ * - `auth` and `realtime` bind a handler to the local tier — see
247
+ * `endpointIsPortable` — so code declaring them deploys as a capsule and
248
+ * never arrives here.
249
+ *
250
+ * `db` widens to both read and write because a declaration says a handler
251
+ * touches the database, not how. Narrowing it would take per-statement analysis
252
+ * we do not do, and guessing "read-only" from a declaration would be a grant
253
+ * the author never asked for and cannot see.
254
+ */
255
+ export declare function functionsDispatchCapabilities(capabilities: ExecutionCapabilities): FunctionsDispatchCapability[];
256
+ /** Everything except `log` needs the relay to mean anything. */
257
+ export declare function functionsGrantNeedsRelay(granted: readonly FunctionsDispatchCapability[]): boolean;
258
+ /**
259
+ * What the space origin needs in order to dispatch to the host on its own. The
260
+ * shared secret is a wp.cloud site secret; it is never part of a version's
261
+ * content and never reaches tenant code, so it is not modelled here.
262
+ *
263
+ * There is no account id and no namespace: the origin talks to one host worker
264
+ * over HTTPS and holds no Cloudflare API credential at all.
265
+ */
266
+ export declare const functionsHostConfigSchema: z.ZodObject<{
267
+ hostname: z.ZodString;
268
+ bundleUrl: z.ZodString;
269
+ }, z.core.$strict>;
270
+ export type FunctionsHostConfig = z.infer<typeof functionsHostConfigSchema>;
271
+ /**
272
+ * The callback a dispatched worker uses for `ctx.db`, `ctx.fetch` and logging.
273
+ *
274
+ * Each relay call re-enters the space's PHP-FPM pool, which is the deadlock
275
+ * hazard this product's admission control exists to bound: a proxied request
276
+ * occupies a worker for its whole life while its relay calls demand more. The
277
+ * batching allowance below is the other half of the answer — a handler that
278
+ * issues twenty statements must cost one relay round trip, not twenty. Measured
279
+ * against the PHP broker, batching twenty writes into one call is 8.3x faster
280
+ * than twenty separate ones.
281
+ */
282
+ export declare const functionsRelayConfigSchema: z.ZodObject<{
283
+ url: z.ZodString;
284
+ token: z.ZodString;
285
+ maxBatchStatements: z.ZodNumber;
286
+ maxConcurrentCalls: z.ZodNumber;
287
+ }, z.core.$strict>;
288
+ export type FunctionsRelayConfig = z.infer<typeof functionsRelayConfigSchema>;
289
+ /**
290
+ * What a build declares about its worker — everything the CLI can know from the
291
+ * author's project alone.
292
+ *
293
+ * Unlike Zero, this is *not* the same document the runtime receives. A build
294
+ * cannot name the host it will be dispatched to, cannot mint the credential its
295
+ * relay calls will carry, and cannot decide what authority it is granted; all
296
+ * three are the platform's to say. Keeping them out of this schema is what makes
297
+ * that structural rather than a convention — a version's own metadata has no
298
+ * field in which to assert authority it was not given.
299
+ */
300
+ export declare const functionsSourceFinalizeSchema: z.ZodObject<{
301
+ runtimeKind: z.ZodLiteral<"functions">;
302
+ artifact: z.ZodObject<{
303
+ format: z.ZodLiteral<"spacefast.functions.worker.v1">;
304
+ appName: z.ZodString;
305
+ entry: z.ZodString;
306
+ mainModule: z.ZodString;
307
+ bundle: z.ZodObject<{
308
+ path: z.ZodString;
309
+ sha256: z.ZodString;
310
+ size: z.ZodNumber;
311
+ }, z.core.$strict>;
312
+ compatibilityDate: z.ZodString;
313
+ compatibilityFlags: z.ZodDefault<z.ZodArray<z.ZodString>>;
314
+ routes: z.ZodDefault<z.ZodArray<z.ZodObject<{
315
+ method: z.ZodDefault<z.ZodNullable<z.ZodEnum<{
316
+ POST: "POST";
317
+ PUT: "PUT";
318
+ GET: "GET";
319
+ HEAD: "HEAD";
320
+ PATCH: "PATCH";
321
+ DELETE: "DELETE";
322
+ OPTIONS: "OPTIONS";
323
+ }>>>;
324
+ path: z.ZodString;
325
+ subtree: z.ZodDefault<z.ZodBoolean>;
326
+ }, z.core.$strict>>>;
327
+ capabilities: z.ZodDefault<z.ZodObject<{
328
+ db: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
329
+ fetch: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
330
+ auth: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
331
+ env: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
332
+ realtime: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
333
+ logging: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
334
+ }, z.core.$strip>>;
335
+ }, z.core.$strict>;
336
+ variables: z.ZodDefault<z.ZodObject<{
337
+ source: z.ZodLiteral<"spacefast-variables">;
338
+ names: z.ZodDefault<z.ZodArray<z.ZodString>>;
339
+ }, z.core.$strict>>;
340
+ }, z.core.$strict>;
341
+ export type FunctionsSourceFinalize = z.infer<typeof functionsSourceFinalizeSchema>;
342
+ /**
343
+ * The document the control plane sends to the runtime, which the engine stores
344
+ * beside the version's files and the origin reads on every dispatch.
345
+ *
346
+ * It is the build's declaration plus the four things only the platform can
347
+ * supply: where to dispatch, what the worker is allowed to do, the credential
348
+ * that lets it do those things, and the resolved values of its variables.
349
+ */
350
+ export declare const functionsRuntimeConfigSchema: z.ZodObject<{
351
+ runtimeKind: z.ZodLiteral<"functions">;
352
+ artifact: z.ZodObject<{
353
+ format: z.ZodLiteral<"spacefast.functions.worker.v1">;
354
+ appName: z.ZodString;
355
+ entry: z.ZodString;
356
+ mainModule: z.ZodString;
357
+ bundle: z.ZodObject<{
358
+ path: z.ZodString;
359
+ sha256: z.ZodString;
360
+ size: z.ZodNumber;
361
+ }, z.core.$strict>;
362
+ compatibilityDate: z.ZodString;
363
+ compatibilityFlags: z.ZodDefault<z.ZodArray<z.ZodString>>;
364
+ routes: z.ZodDefault<z.ZodArray<z.ZodObject<{
365
+ method: z.ZodDefault<z.ZodNullable<z.ZodEnum<{
366
+ POST: "POST";
367
+ PUT: "PUT";
368
+ GET: "GET";
369
+ HEAD: "HEAD";
370
+ PATCH: "PATCH";
371
+ DELETE: "DELETE";
372
+ OPTIONS: "OPTIONS";
373
+ }>>>;
374
+ path: z.ZodString;
375
+ subtree: z.ZodDefault<z.ZodBoolean>;
376
+ }, z.core.$strict>>>;
377
+ capabilities: z.ZodDefault<z.ZodObject<{
378
+ db: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
379
+ fetch: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
380
+ auth: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
381
+ env: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
382
+ realtime: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
383
+ logging: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
384
+ }, z.core.$strip>>;
385
+ }, z.core.$strict>;
386
+ variables: z.ZodDefault<z.ZodObject<{
387
+ source: z.ZodLiteral<"spacefast-variables">;
388
+ names: z.ZodDefault<z.ZodArray<z.ZodString>>;
389
+ }, z.core.$strict>>;
390
+ host: z.ZodObject<{
391
+ hostname: z.ZodString;
392
+ bundleUrl: z.ZodString;
393
+ }, z.core.$strict>;
394
+ grantedCapabilities: z.ZodDefault<z.ZodArray<z.ZodEnum<{
395
+ fetch: "fetch";
396
+ "db.read": "db.read";
397
+ "db.write": "db.write";
398
+ log: "log";
399
+ }>>>;
400
+ relay: z.ZodDefault<z.ZodNullable<z.ZodObject<{
401
+ url: z.ZodString;
402
+ token: z.ZodString;
403
+ maxBatchStatements: z.ZodNumber;
404
+ maxConcurrentCalls: z.ZodNumber;
405
+ }, z.core.$strict>>>;
406
+ variableValues: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
407
+ }, z.core.$strict>;
408
+ export type FunctionsRuntimeConfig = z.infer<typeof functionsRuntimeConfigSchema>;
409
+ export declare const functionsDeployMetadataSchema: z.ZodObject<{
410
+ artifactId: z.ZodOptional<z.ZodString>;
411
+ finalize: z.ZodObject<{
412
+ runtimeKind: z.ZodLiteral<"functions">;
413
+ artifact: z.ZodObject<{
414
+ format: z.ZodLiteral<"spacefast.functions.worker.v1">;
415
+ appName: z.ZodString;
416
+ entry: z.ZodString;
417
+ mainModule: z.ZodString;
418
+ bundle: z.ZodObject<{
419
+ path: z.ZodString;
420
+ sha256: z.ZodString;
421
+ size: z.ZodNumber;
422
+ }, z.core.$strict>;
423
+ compatibilityDate: z.ZodString;
424
+ compatibilityFlags: z.ZodDefault<z.ZodArray<z.ZodString>>;
425
+ routes: z.ZodDefault<z.ZodArray<z.ZodObject<{
426
+ method: z.ZodDefault<z.ZodNullable<z.ZodEnum<{
427
+ POST: "POST";
428
+ PUT: "PUT";
429
+ GET: "GET";
430
+ HEAD: "HEAD";
431
+ PATCH: "PATCH";
432
+ DELETE: "DELETE";
433
+ OPTIONS: "OPTIONS";
434
+ }>>>;
435
+ path: z.ZodString;
436
+ subtree: z.ZodDefault<z.ZodBoolean>;
437
+ }, z.core.$strict>>>;
438
+ capabilities: z.ZodDefault<z.ZodObject<{
439
+ db: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
440
+ fetch: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
441
+ auth: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
442
+ env: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
443
+ realtime: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
444
+ logging: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
445
+ }, z.core.$strip>>;
446
+ }, z.core.$strict>;
447
+ variables: z.ZodDefault<z.ZodObject<{
448
+ source: z.ZodLiteral<"spacefast-variables">;
449
+ names: z.ZodDefault<z.ZodArray<z.ZodString>>;
450
+ }, z.core.$strict>>;
451
+ }, z.core.$strict>;
452
+ }, z.core.$strict>;
453
+ export type FunctionsDeployMetadata = z.infer<typeof functionsDeployMetadataSchema>;
454
+ /**
455
+ * Builds the declaration a publish attaches to its version.
456
+ *
457
+ * Exists so the CLI's publish step and every test that needs a Functions
458
+ * version agree on the shape by construction rather than by copying an object
459
+ * literal around — the same reason `createZeroRuntimeFinalizePayload` exists.
460
+ */
461
+ export declare function createFunctionsSourceFinalize(input: {
462
+ appName: string;
463
+ entry: string;
464
+ mainModule: string;
465
+ bundle: z.input<typeof functionsBundleRefSchema>;
466
+ compatibilityDate: string;
467
+ compatibilityFlags?: string[];
468
+ routes?: z.input<typeof functionsRouteSchema>[];
469
+ capabilities?: ExecutionCapabilities;
470
+ variableNames?: string[];
471
+ }): FunctionsSourceFinalize;
472
+ /**
473
+ * What a version's worker is currently doing, as an observer of the space can
474
+ * actually determine.
475
+ *
476
+ * There is no upload state to report. A bundle is either in the version's
477
+ * content store or it is not, and dispatch is decided by which version is
478
+ * serving — so these three cover the whole space of answers, and each one is
479
+ * checkable rather than inferred from a job we ran earlier.
480
+ */
481
+ export declare const functionsExecutionStateSchema: z.ZodEnum<{
482
+ ready: "ready";
483
+ absent: "absent";
484
+ serving: "serving";
485
+ }>;
486
+ export type FunctionsExecutionState = z.infer<typeof functionsExecutionStateSchema>;
487
+ /**
488
+ * What a live worker is, as the `app` member of a space's runtime status.
489
+ *
490
+ * Shaped like `zeroAppSchema` and discriminated by the same `runtimeKind`, so a
491
+ * reader switches on one field rather than probing for which product answered.
492
+ * No `versionId`: the status response it rides in already names the live
493
+ * version.
494
+ *
495
+ * Everything but `executionState` is a field of the version's own finalize
496
+ * metadata, so this answers whether or not the origin is reachable. There is no
497
+ * `database` field: `capabilities.db` is the fact the whole `/db` family
498
+ * branches on, and stating it twice invites the two to disagree.
499
+ */
500
+ export declare const functionsAppSchema: z.ZodObject<{
501
+ runtimeKind: z.ZodLiteral<"functions">;
502
+ artifactId: z.ZodString;
503
+ appName: z.ZodString;
504
+ entry: z.ZodString;
505
+ compatibilityDate: z.ZodString;
506
+ compatibilityFlags: z.ZodDefault<z.ZodArray<z.ZodString>>;
507
+ routes: z.ZodDefault<z.ZodArray<z.ZodObject<{
508
+ method: z.ZodDefault<z.ZodNullable<z.ZodEnum<{
509
+ POST: "POST";
510
+ PUT: "PUT";
511
+ GET: "GET";
512
+ HEAD: "HEAD";
513
+ PATCH: "PATCH";
514
+ DELETE: "DELETE";
515
+ OPTIONS: "OPTIONS";
516
+ }>>>;
517
+ path: z.ZodString;
518
+ subtree: z.ZodDefault<z.ZodBoolean>;
519
+ }, z.core.$strict>>>;
520
+ capabilities: z.ZodDefault<z.ZodObject<{
521
+ db: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
522
+ fetch: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
523
+ auth: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
524
+ env: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
525
+ realtime: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
526
+ logging: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
527
+ }, z.core.$strip>>;
528
+ executionState: z.ZodEnum<{
529
+ ready: "ready";
530
+ absent: "absent";
531
+ serving: "serving";
532
+ }>;
533
+ bundleSize: z.ZodNumber;
534
+ bundleSha256: z.ZodString;
535
+ variables: z.ZodObject<{
536
+ source: z.ZodLiteral<"spacefast-variables">;
537
+ names: z.ZodDefault<z.ZodArray<z.ZodString>>;
538
+ }, z.core.$strict>;
539
+ }, z.core.$strict>;
540
+ export type FunctionsApp = z.infer<typeof functionsAppSchema>;
541
+ /**
542
+ * The wire shape of the origin's log-read route, not a public API contract.
543
+ *
544
+ * Handler logs reach callers through `GET /v1/spaces/:spaceId/logs/runtime`,
545
+ * which serves the platform's own `runtimeLogListResponseSchema` for both
546
+ * execution tiers. These aliases describe the hop underneath it: a worker tails
547
+ * its output to the origin that dispatched it, and the control plane reads it
548
+ * back from there. Keeping them named after this product is the point — the
549
+ * origin is the only place a wp.cloud-hosted space keeps anything, and Zero's
550
+ * records never travel this path at all.
551
+ */
552
+ export declare const functionsLogEntrySchema: z.ZodObject<{
553
+ id: z.ZodString;
554
+ timestamp: z.ZodString;
555
+ level: z.ZodEnum<{
556
+ info: "info";
557
+ error: "error";
558
+ debug: "debug";
559
+ warn: "warn";
560
+ }>;
561
+ requestId: z.ZodNullable<z.ZodString>;
562
+ versionId: z.ZodNullable<z.ZodString>;
563
+ handlerName: z.ZodNullable<z.ZodString>;
564
+ message: z.ZodString;
565
+ metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
566
+ }, z.core.$strict>;
567
+ export type FunctionsLogEntry = z.infer<typeof functionsLogEntrySchema>;
568
+ export declare const functionsLogListQuerySchema: z.ZodObject<{
569
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
570
+ cursor: z.ZodOptional<z.ZodString>;
571
+ requestId: z.ZodOptional<z.ZodString>;
572
+ handlerName: z.ZodOptional<z.ZodString>;
573
+ }, z.core.$strict>;
574
+ export type FunctionsLogListQuery = z.infer<typeof functionsLogListQuerySchema>;
575
+ export declare const functionsLogListResponseSchema: z.ZodObject<{
576
+ data: z.ZodArray<z.ZodObject<{
577
+ id: z.ZodString;
578
+ timestamp: z.ZodString;
579
+ level: z.ZodEnum<{
580
+ info: "info";
581
+ error: "error";
582
+ debug: "debug";
583
+ warn: "warn";
584
+ }>;
585
+ requestId: z.ZodNullable<z.ZodString>;
586
+ versionId: z.ZodNullable<z.ZodString>;
587
+ handlerName: z.ZodNullable<z.ZodString>;
588
+ message: z.ZodString;
589
+ metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
590
+ }, z.core.$strict>>;
591
+ pagination: z.ZodObject<{
592
+ nextCursor: z.ZodNullable<z.ZodString>;
593
+ }, z.core.$strict>;
594
+ }, z.core.$strict>;
595
+ export type FunctionsLogListResponse = z.infer<typeof functionsLogListResponseSchema>;
596
+ /** Narrows a space's live runtime kind to this product. */
597
+ export declare function isFunctionsRuntime(kind: z.infer<typeof runtimeKindSchema> | null): boolean;