@spacefast/common 0.0.12 → 0.0.13

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