@pithy-sh/cloudflare 0.1.2 → 0.1.4

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 (139) hide show
  1. package/dist/ai/aiManager.d.ts +101 -0
  2. package/dist/ai/aiManager.d.ts.map +1 -0
  3. package/dist/ai/aiManager.js +150 -0
  4. package/dist/ai/vectorizeManager.d.ts +69 -0
  5. package/dist/ai/vectorizeManager.d.ts.map +1 -0
  6. package/dist/ai/vectorizeManager.js +103 -0
  7. package/dist/ai/vectorizeProvisioner.d.ts +125 -0
  8. package/dist/ai/vectorizeProvisioner.d.ts.map +1 -0
  9. package/dist/ai/vectorizeProvisioner.js +197 -0
  10. package/dist/client/accounts.d.ts +50 -0
  11. package/dist/client/accounts.d.ts.map +1 -0
  12. package/dist/client/accounts.js +57 -0
  13. package/dist/client/clients.d.ts +124 -0
  14. package/dist/client/clients.d.ts.map +1 -0
  15. package/dist/client/clients.js +218 -0
  16. package/dist/client/errors.d.ts +75 -0
  17. package/dist/client/errors.d.ts.map +1 -0
  18. package/dist/client/errors.js +100 -0
  19. package/dist/client/manager.d.ts +47 -0
  20. package/dist/client/manager.d.ts.map +1 -0
  21. package/dist/client/manager.js +53 -0
  22. package/dist/d1/d1Manager.d.ts +76 -0
  23. package/dist/d1/d1Manager.d.ts.map +1 -0
  24. package/dist/d1/d1Manager.js +130 -0
  25. package/dist/d1/d1PreparedStatement.d.ts +26 -0
  26. package/dist/d1/d1PreparedStatement.d.ts.map +1 -0
  27. package/dist/d1/d1PreparedStatement.js +93 -0
  28. package/dist/d1/d1Provisioner.d.ts +30 -0
  29. package/dist/d1/d1Provisioner.d.ts.map +1 -0
  30. package/dist/d1/d1Provisioner.js +69 -0
  31. package/dist/email/emailRoutingManager.d.ts +38 -0
  32. package/dist/email/emailRoutingManager.d.ts.map +1 -0
  33. package/dist/email/emailRoutingManager.js +126 -0
  34. package/dist/email/emailSendManager.d.ts +47 -0
  35. package/dist/email/emailSendManager.d.ts.map +1 -0
  36. package/dist/email/emailSendManager.js +54 -0
  37. package/dist/env/devVars.d.ts +67 -0
  38. package/dist/env/devVars.d.ts.map +1 -0
  39. package/dist/env/devVars.js +86 -0
  40. package/dist/hostnames/customHostnamesManager.d.ts +53 -0
  41. package/dist/hostnames/customHostnamesManager.d.ts.map +1 -0
  42. package/dist/hostnames/customHostnamesManager.js +86 -0
  43. package/dist/kv/kvManager.d.ts +78 -0
  44. package/dist/kv/kvManager.d.ts.map +1 -0
  45. package/dist/kv/kvManager.js +137 -0
  46. package/dist/kv/kvProvisioner.d.ts +30 -0
  47. package/dist/kv/kvProvisioner.d.ts.map +1 -0
  48. package/dist/kv/kvProvisioner.js +73 -0
  49. package/dist/media/assetSeeder.d.ts +33 -0
  50. package/dist/media/assetSeeder.d.ts.map +1 -0
  51. package/dist/media/assetSeeder.js +72 -0
  52. package/dist/media/imageManager.d.ts +36 -0
  53. package/dist/media/imageManager.d.ts.map +1 -0
  54. package/dist/media/imageManager.js +105 -0
  55. package/dist/media/ownership.d.ts +42 -0
  56. package/dist/media/ownership.d.ts.map +1 -0
  57. package/dist/media/ownership.js +48 -0
  58. package/dist/media/streamManager.d.ts +85 -0
  59. package/dist/media/streamManager.d.ts.map +1 -0
  60. package/dist/media/streamManager.js +147 -0
  61. package/dist/queue/queueManager.d.ts +86 -0
  62. package/dist/queue/queueManager.d.ts.map +1 -0
  63. package/dist/queue/queueManager.js +116 -0
  64. package/dist/r2/r2Credentials.d.ts +14 -0
  65. package/dist/r2/r2Credentials.d.ts.map +1 -0
  66. package/dist/r2/r2Credentials.js +15 -0
  67. package/dist/r2/r2Manager.d.ts +228 -0
  68. package/dist/r2/r2Manager.d.ts.map +1 -0
  69. package/dist/r2/r2Manager.js +407 -0
  70. package/dist/r2/r2Provisioner.d.ts +41 -0
  71. package/dist/r2/r2Provisioner.d.ts.map +1 -0
  72. package/dist/r2/r2Provisioner.js +88 -0
  73. package/dist/secrets/secretsStoreManager.d.ts +84 -0
  74. package/dist/secrets/secretsStoreManager.d.ts.map +1 -0
  75. package/dist/secrets/secretsStoreManager.js +149 -0
  76. package/dist/secrets/secretsStores.d.ts +49 -0
  77. package/dist/secrets/secretsStores.d.ts.map +1 -0
  78. package/dist/secrets/secretsStores.js +67 -0
  79. package/dist/test-utils/emailRoutingRules.d.ts +41 -0
  80. package/dist/test-utils/emailRoutingRules.d.ts.map +1 -0
  81. package/dist/test-utils/emailRoutingRules.js +91 -0
  82. package/dist/test-utils/fixtureReportSetup.d.ts +27 -0
  83. package/dist/test-utils/fixtureReportSetup.d.ts.map +1 -0
  84. package/dist/test-utils/fixtureReportSetup.js +32 -0
  85. package/dist/test-utils/fixtures.d.ts +226 -0
  86. package/dist/test-utils/fixtures.d.ts.map +1 -0
  87. package/dist/test-utils/fixtures.js +279 -0
  88. package/dist/test-utils/harness.d.ts +194 -0
  89. package/dist/test-utils/harness.d.ts.map +1 -0
  90. package/dist/test-utils/harness.js +353 -0
  91. package/dist/test-utils/inboundRecorder.d.ts +93 -0
  92. package/dist/test-utils/inboundRecorder.d.ts.map +1 -0
  93. package/dist/test-utils/inboundRecorder.js +143 -0
  94. package/dist/test-utils/integrationSetup.d.ts +24 -0
  95. package/dist/test-utils/integrationSetup.d.ts.map +1 -0
  96. package/dist/test-utils/integrationSetup.js +39 -0
  97. package/dist/test-utils/reap.d.ts +114 -0
  98. package/dist/test-utils/reap.d.ts.map +1 -0
  99. package/dist/test-utils/reap.js +187 -0
  100. package/dist/tokens/accountTokensManager.d.ts +159 -0
  101. package/dist/tokens/accountTokensManager.d.ts.map +1 -0
  102. package/dist/tokens/accountTokensManager.js +282 -0
  103. package/dist/tokens/permissions.d.ts +38 -0
  104. package/dist/tokens/permissions.d.ts.map +1 -0
  105. package/dist/tokens/permissions.js +52 -0
  106. package/dist/tokens/profiles.d.ts +104 -0
  107. package/dist/tokens/profiles.d.ts.map +1 -0
  108. package/dist/tokens/profiles.js +139 -0
  109. package/dist/turnstile/turnstileManager.d.ts +77 -0
  110. package/dist/turnstile/turnstileManager.d.ts.map +1 -0
  111. package/dist/turnstile/turnstileManager.js +140 -0
  112. package/dist/user/userManager.d.ts +38 -0
  113. package/dist/user/userManager.d.ts.map +1 -0
  114. package/dist/user/userManager.js +60 -0
  115. package/dist/workers/buildsManager.d.ts +118 -0
  116. package/dist/workers/buildsManager.d.ts.map +1 -0
  117. package/dist/workers/buildsManager.js +239 -0
  118. package/dist/workers/buildsTypes.d.ts +104 -0
  119. package/dist/workers/buildsTypes.d.ts.map +1 -0
  120. package/dist/workers/buildsTypes.js +89 -0
  121. package/dist/workers/workersBuildEvent.d.ts +66 -0
  122. package/dist/workers/workersBuildEvent.d.ts.map +1 -0
  123. package/dist/workers/workersBuildEvent.js +49 -0
  124. package/dist/workers/workersManager.d.ts +138 -0
  125. package/dist/workers/workersManager.d.ts.map +1 -0
  126. package/dist/workers/workersManager.js +314 -0
  127. package/dist/workers/workersProvisioner.d.ts +82 -0
  128. package/dist/workers/workersProvisioner.d.ts.map +1 -0
  129. package/dist/workers/workersProvisioner.js +108 -0
  130. package/dist/workflows/stepFailure.d.ts +182 -0
  131. package/dist/workflows/stepFailure.d.ts.map +1 -0
  132. package/dist/workflows/stepFailure.js +229 -0
  133. package/dist/workflows/workflowsClient.d.ts +89 -0
  134. package/dist/workflows/workflowsClient.d.ts.map +1 -0
  135. package/dist/workflows/workflowsClient.js +158 -0
  136. package/dist/zones/zonesManager.d.ts +52 -0
  137. package/dist/zones/zonesManager.d.ts.map +1 -0
  138. package/dist/zones/zonesManager.js +76 -0
  139. package/package.json +18 -9
@@ -0,0 +1,239 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { CloudflareInvalidResponseError, CloudflareRequestError, cloudflareRequest, decodeResponse, messageOf } from "../client/errors.js";
4
+ import { CloudflareManager } from "../client/manager.js";
5
+ import { CfBuild, CfBuildLog, CfBuildToken, CfBuildTrigger, CfRepoConnection } from "./buildsTypes.js";
6
+ import { z } from "zod";
7
+ //#region src/workers/buildsManager.ts
8
+ /** The Cloudflare REST API v4 base URL. The Builds endpoints live under `/accounts/{id}/builds`. */
9
+ const CF_API_BASE = "https://api.cloudflare.com/client/v4";
10
+ /** CF 409 code 12042: "A trigger already exists for this configuration". */
11
+ const CONFLICT_TRIGGER_EXISTS = 12042;
12
+ /** CF 404 code 12000: "Not found" — returned when a script has no triggers. */
13
+ const NOT_FOUND = 12e3;
14
+ /** The standard `{ result, success, errors, messages }` envelope every CF REST response carries. */
15
+ const CfEnvelope = z.object({
16
+ result: z.unknown(),
17
+ success: z.boolean().optional(),
18
+ errors: z.array(z.object({
19
+ code: z.number().optional(),
20
+ message: z.string().optional()
21
+ }).loose()).optional()
22
+ });
23
+ /**
24
+ * Out-of-Worker access to the Cloudflare Builds API: repo connections, build triggers, builds, and
25
+ * trigger env vars. CF Builds is the CI/CD layer for Workers — it clones a git repo, runs a build
26
+ * command, and reports outcomes.
27
+ *
28
+ * As of the SDK version this package targets, the Builds endpoints are NOT exposed as typed SDK
29
+ * resources, so this manager uses the documented escape hatch (`getApiToken()` + raw `fetch`) against
30
+ * explicit `/accounts/{id}/builds/...` paths. Every request goes through `cloudflareRequest` so
31
+ * failures wrap as `cloudflare/request_failed`, and every response is validated with Zod
32
+ * (`cloudflare/invalid_response` on mismatch).
33
+ */
34
+ var CloudflareBuildsManager = class extends CloudflareManager {
35
+ /**
36
+ * Issue a raw CF REST call and unwrap the `{ result, success, errors }` envelope. A failure —
37
+ * either a non-2xx status **or** a 200 carrying `success: false` — throws `cloudflare/request_failed`
38
+ * with the structured CF error codes pinned to the front of `detail` (so idempotency checks read a
39
+ * stable marker, never a substring a verbose body could push past truncation). An unparseable body
40
+ * throws `cloudflare/invalid_response`.
41
+ */
42
+ async call(method, path, body) {
43
+ const response = await fetch(`${CF_API_BASE}${path}`, {
44
+ method,
45
+ headers: {
46
+ authorization: `Bearer ${this.getApiToken()}`,
47
+ ...body !== void 0 ? { "content-type": "application/json" } : {}
48
+ },
49
+ ...body !== void 0 ? { body: JSON.stringify(body) } : {}
50
+ });
51
+ const text = await response.text();
52
+ let parsed = {};
53
+ if (text.length > 0) try {
54
+ parsed = JSON.parse(text);
55
+ } catch (error) {
56
+ throw new CloudflareInvalidResponseError({
57
+ message: "A Cloudflare Builds response was not valid JSON.",
58
+ detail: `${method} ${path}: ${messageOf(error)}`
59
+ });
60
+ }
61
+ const envelope = CfEnvelope.safeParse(parsed);
62
+ const apiReportedFailure = envelope.success && envelope.data.success === false;
63
+ if (!response.ok || apiReportedFailure) {
64
+ const codes = envelope.success ? (envelope.data.errors ?? []).map((e) => e.code).filter((c) => c !== void 0) : [];
65
+ const marker = codes.length > 0 ? `[cf-codes:${codes.join(",")}] ` : "";
66
+ throw new CloudflareRequestError({
67
+ message: `Cloudflare Builds returned ${response.status}.`,
68
+ detail: `${marker}${method} ${path} → ${response.status}: ${text}`.slice(0, 2e3)
69
+ });
70
+ }
71
+ return envelope.success ? envelope.data.result : parsed;
72
+ }
73
+ /**
74
+ * Register a git repository with CF Builds. `PUT /builds/repos/connections` is CF's documented
75
+ * upsert — calling with the same repo id returns the existing connection.
76
+ */
77
+ async createRepoConnection(args) {
78
+ return cloudflareRequest("create repo connection", async () => {
79
+ const result = await this.call("PUT", `/accounts/${this.getAccountId()}/builds/repos/connections`, {
80
+ provider_type: args.providerType,
81
+ repo_id: args.repoId,
82
+ repo_name: args.repoName,
83
+ provider_account_id: args.providerAccountId,
84
+ provider_account_name: args.providerAccountName
85
+ });
86
+ return this.validate(CfRepoConnection, result, "repo connection");
87
+ });
88
+ }
89
+ /**
90
+ * Upsert a build trigger linking a Worker script to a repo. Tries `POST /builds/triggers`; on the
91
+ * 409 "trigger already exists" conflict, falls back to listing the script's triggers and returning
92
+ * the matching one. Idempotent.
93
+ */
94
+ async upsertTrigger(args) {
95
+ return cloudflareRequest("upsert trigger", async () => {
96
+ try {
97
+ const result = await this.call("POST", `/accounts/${this.getAccountId()}/builds/triggers`, {
98
+ external_script_id: args.scriptName,
99
+ repo_connection_uuid: args.repoConnectionId,
100
+ build_token_uuid: args.buildTokenUuid,
101
+ trigger_name: args.triggerName,
102
+ branch_includes: args.branchIncludes,
103
+ branch_excludes: args.branchExcludes ?? [],
104
+ path_includes: args.pathIncludes ?? ["*"],
105
+ build_command: args.buildCommand,
106
+ deploy_command: args.deployCommand,
107
+ root_directory: args.rootDirectory ?? "/",
108
+ build_caching_enabled: args.buildCachingEnabled ?? true
109
+ });
110
+ return this.validate(CfBuildTrigger, result, "build trigger");
111
+ } catch (error) {
112
+ if (hasErrorCode(error, CONFLICT_TRIGGER_EXISTS)) {
113
+ const existing = await this.listTriggersByScript(args.scriptName);
114
+ const match = existing.find((t) => t.trigger_name === args.triggerName) ?? existing.find((t) => JSON.stringify(t.branch_includes) === JSON.stringify(args.branchIncludes));
115
+ if (match) return match;
116
+ }
117
+ throw error;
118
+ }
119
+ });
120
+ }
121
+ /** List the build tokens available on the account. */
122
+ async listBuildTokens() {
123
+ return cloudflareRequest("list build tokens", async () => {
124
+ const result = await this.call("GET", `/accounts/${this.getAccountId()}/builds/tokens`);
125
+ return this.validate(z.array(CfBuildToken), Array.isArray(result) ? result : [], "build tokens");
126
+ });
127
+ }
128
+ /** Patch an existing build trigger's configuration. */
129
+ async updateTrigger(triggerId, args) {
130
+ return cloudflareRequest("update trigger", async () => {
131
+ const body = {};
132
+ if (args.branchFilter !== void 0) body.branch_filter = args.branchFilter;
133
+ if (args.buildCommand !== void 0) body.build_command = args.buildCommand;
134
+ if (args.deployCommand !== void 0) body.deploy_command = args.deployCommand;
135
+ if (args.rootDirectory !== void 0) body.root_directory = args.rootDirectory;
136
+ const result = await this.call("PUT", `/accounts/${this.getAccountId()}/builds/triggers/${triggerId}`, body);
137
+ return this.validate(CfBuildTrigger, result, "build trigger");
138
+ });
139
+ }
140
+ /** Delete a build trigger. */
141
+ async deleteTrigger(triggerId) {
142
+ await cloudflareRequest("delete trigger", () => this.call("DELETE", `/accounts/${this.getAccountId()}/builds/triggers/${triggerId}`));
143
+ }
144
+ /** Manually start a build for a trigger at a specific branch + commit. */
145
+ async triggerManualBuild(triggerId, branch, commitHash) {
146
+ return cloudflareRequest("trigger manual build", async () => {
147
+ const result = await this.call("POST", `/accounts/${this.getAccountId()}/builds/triggers/${triggerId}/builds`, {
148
+ branch,
149
+ commit_hash: commitHash
150
+ });
151
+ return this.validate(CfBuild, result, "build");
152
+ });
153
+ }
154
+ /** Get a build's current status and metadata by id. */
155
+ async getBuild(buildId) {
156
+ return cloudflareRequest("get build", async () => {
157
+ const result = await this.call("GET", `/accounts/${this.getAccountId()}/builds/${buildId}`);
158
+ return this.validate(CfBuild, result, "build");
159
+ });
160
+ }
161
+ /** Cancel a running build. */
162
+ async cancelBuild(buildId) {
163
+ await cloudflareRequest("cancel build", () => this.call("POST", `/accounts/${this.getAccountId()}/builds/${buildId}/cancel`));
164
+ }
165
+ /** Get the log output for a build. */
166
+ async getBuildLogs(buildId) {
167
+ return cloudflareRequest("get build logs", async () => {
168
+ const result = await this.call("GET", `/accounts/${this.getAccountId()}/builds/${buildId}/logs`);
169
+ return this.validate(z.array(CfBuildLog), result, "build logs");
170
+ });
171
+ }
172
+ /** List all builds for a Worker script. */
173
+ async listBuildsByScript(scriptName) {
174
+ return cloudflareRequest("list builds by script", async () => {
175
+ const result = await this.call("GET", `/accounts/${this.getAccountId()}/builds?script_name=${encodeURIComponent(scriptName)}`);
176
+ return this.validate(z.array(CfBuild), result, "builds");
177
+ });
178
+ }
179
+ /**
180
+ * List the build triggers for a Worker script. `externalScriptId` must be the immutable Worker id
181
+ * (hex UUID), resolved via `CloudflareWorkersManager.getWorkerInternalId`. Returns an empty array
182
+ * when the script has no triggers (CF 404 code 12000).
183
+ */
184
+ async listTriggersByScript(externalScriptId) {
185
+ return cloudflareRequest("list triggers by script", async () => {
186
+ try {
187
+ const result = await this.call("GET", `/accounts/${this.getAccountId()}/builds/workers/${encodeURIComponent(externalScriptId)}/triggers`);
188
+ return this.validate(z.array(CfBuildTrigger), result, "build triggers");
189
+ } catch (error) {
190
+ if (hasErrorCode(error, NOT_FOUND)) return [];
191
+ throw error;
192
+ }
193
+ });
194
+ }
195
+ /**
196
+ * Bulk-upsert environment variables on a build trigger. The wire body is a map keyed by variable
197
+ * name (`{ NAME: { is_secret, value }, ... }`), not an array.
198
+ */
199
+ async upsertTriggerEnvVars(triggerId, envVars) {
200
+ await cloudflareRequest("upsert trigger env vars", () => {
201
+ const body = {};
202
+ for (const variable of envVars) body[variable.name] = {
203
+ is_secret: variable.type === "secret_text",
204
+ value: variable.value
205
+ };
206
+ return this.call("PATCH", `/accounts/${this.getAccountId()}/builds/triggers/${triggerId}/environment_variables`, body);
207
+ });
208
+ }
209
+ getServiceType() {
210
+ return "Cloudflare Builds";
211
+ }
212
+ /** Prove access by listing build triggers. Never throws. */
213
+ async validateServiceAccess() {
214
+ try {
215
+ await this.call("GET", `/accounts/${this.getAccountId()}/builds/triggers`);
216
+ return true;
217
+ } catch {
218
+ return false;
219
+ }
220
+ }
221
+ /** Validate a raw CF result against a Zod schema, throwing `cloudflare/invalid_response` on mismatch. */
222
+ validate(schema, raw, label) {
223
+ return decodeResponse(schema, raw, `Builds ${label}`);
224
+ }
225
+ };
226
+ /**
227
+ * Whether a thrown `CloudflareRequestError` carries the given CF error code. Reads the `[cf-codes:…]`
228
+ * marker `call()` pins to the front of `detail` (stable across the 2000-char truncation); falls back
229
+ * to a substring scan for errors raised without the structured marker.
230
+ */
231
+ function hasErrorCode(error, code) {
232
+ if (!(error instanceof CloudflareRequestError)) return false;
233
+ const detail = error.payload.detail ?? "";
234
+ const marker = detail.match(/^\[cf-codes:([\d,]+)\]/);
235
+ if (marker?.[1]) return marker[1].split(",").includes(String(code));
236
+ return detail.includes(`"code":${code}`) || detail.includes(`"code": ${code}`);
237
+ }
238
+ //#endregion
239
+ export { CloudflareBuildsManager };
@@ -0,0 +1,104 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { z } from "zod";
4
+ /**
5
+ * Zod schemas for the Cloudflare Builds REST API.
6
+ *
7
+ * CF Builds provides CI/CD for Workers — it clones a git repo, runs a build command, and optionally
8
+ * runs a deploy command. As of the SDK version this package targets, the Builds endpoints are not
9
+ * exposed as typed SDK resources, so `buildsManager` reaches them over raw `fetch` (the documented
10
+ * escape hatch) and validates every response through the schemas here. ISO-string dates on the wire
11
+ * are decoded to `Date` via the `JsonDate` codec, so each dated schema round-trips through
12
+ * `.parse()`/`.encode()`.
13
+ */
14
+ /** A git-provider repository linked to the Cloudflare account for builds. */
15
+ export declare const CfRepoConnection: z.ZodObject<{
16
+ repo_connection_uuid: z.ZodString;
17
+ repo_id: z.ZodString;
18
+ repo_name: z.ZodString;
19
+ provider_type: z.ZodString;
20
+ provider_account_id: z.ZodString;
21
+ provider_account_name: z.ZodString;
22
+ created_on: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
23
+ modified_on: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
24
+ deleted_on: z.ZodOptional<z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>>>;
25
+ }, z.core.$strip>;
26
+ export type CfRepoConnection = z.output<typeof CfRepoConnection>;
27
+ /** A build trigger linking a Worker script to a repo connection and its build/deploy commands. */
28
+ export declare const CfBuildTrigger: z.ZodObject<{
29
+ trigger_uuid: z.ZodString;
30
+ external_script_id: z.ZodString;
31
+ build_token_uuid: z.ZodString;
32
+ build_token_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
33
+ trigger_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
34
+ build_command: z.ZodString;
35
+ deploy_command: z.ZodString;
36
+ root_directory: z.ZodString;
37
+ branch_includes: z.ZodArray<z.ZodString>;
38
+ branch_excludes: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
39
+ path_includes: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
40
+ path_excludes: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
41
+ build_caching_enabled: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
42
+ created_on: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
43
+ modified_on: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
44
+ deleted_on: z.ZodOptional<z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>>>;
45
+ }, z.core.$strip>;
46
+ export type CfBuildTrigger = z.output<typeof CfBuildTrigger>;
47
+ /** Metadata about the commit a build ran against. */
48
+ export declare const CfBuildTriggerMetadata: z.ZodObject<{
49
+ branch: z.ZodString;
50
+ commit_hash: z.ZodString;
51
+ build_trigger_source: z.ZodOptional<z.ZodNullable<z.ZodString>>;
52
+ }, z.core.$loose>;
53
+ export type CfBuildTriggerMetadata = z.output<typeof CfBuildTriggerMetadata>;
54
+ /** A back-reference from a build to the trigger that produced it. */
55
+ export declare const CfBuildTriggerRef: z.ZodObject<{
56
+ trigger_uuid: z.ZodString;
57
+ external_script_id: z.ZodString;
58
+ }, z.core.$loose>;
59
+ export type CfBuildTriggerRef = z.output<typeof CfBuildTriggerRef>;
60
+ /** A single execution of a build trigger and its lifecycle state. */
61
+ export declare const CfBuild: z.ZodObject<{
62
+ build_uuid: z.ZodString;
63
+ status: z.ZodString;
64
+ build_outcome: z.ZodOptional<z.ZodNullable<z.ZodString>>;
65
+ initializing_on: z.ZodOptional<z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>>>;
66
+ running_on: z.ZodOptional<z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>>>;
67
+ stopped_on: z.ZodOptional<z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>>>;
68
+ created_on: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
69
+ modified_on: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
70
+ build_trigger_metadata: z.ZodOptional<z.ZodNullable<z.ZodObject<{
71
+ branch: z.ZodString;
72
+ commit_hash: z.ZodString;
73
+ build_trigger_source: z.ZodOptional<z.ZodNullable<z.ZodString>>;
74
+ }, z.core.$loose>>>;
75
+ trigger: z.ZodOptional<z.ZodNullable<z.ZodObject<{
76
+ trigger_uuid: z.ZodString;
77
+ external_script_id: z.ZodString;
78
+ }, z.core.$loose>>>;
79
+ }, z.core.$strip>;
80
+ export type CfBuild = z.output<typeof CfBuild>;
81
+ /** One line of a build's log output. */
82
+ export declare const CfBuildLog: z.ZodObject<{
83
+ line: z.ZodNumber;
84
+ timestamp: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
85
+ message: z.ZodString;
86
+ }, z.core.$strip>;
87
+ export type CfBuildLog = z.output<typeof CfBuildLog>;
88
+ /** An environment variable set on a build trigger. */
89
+ export declare const CfTriggerEnvVar: z.ZodObject<{
90
+ name: z.ZodString;
91
+ value: z.ZodString;
92
+ type: z.ZodEnum<{
93
+ plain_text: "plain_text";
94
+ secret_text: "secret_text";
95
+ }>;
96
+ }, z.core.$strip>;
97
+ export type CfTriggerEnvVar = z.output<typeof CfTriggerEnvVar>;
98
+ /** A build token usable by triggers on the account. */
99
+ export declare const CfBuildToken: z.ZodObject<{
100
+ build_token_uuid: z.ZodString;
101
+ build_token_name: z.ZodString;
102
+ }, z.core.$strip>;
103
+ export type CfBuildToken = z.output<typeof CfBuildToken>;
104
+ //# sourceMappingURL=buildsTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildsTypes.d.ts","sourceRoot":"","sources":["../../src/workers/buildsTypes.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;GASG;AAEH,6EAA6E;AAC7E,eAAO,MAAM,gBAAgB;;;;;;;;;;iBAY2C,CAAC;AACzE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEjE,kGAAkG;AAClG,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;iBAmBqE,CAAC;AACjG,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC;AAE7D,qDAAqD;AACrD,eAAO,MAAM,sBAAsB;;;;iBAOuB,CAAC;AAC3D,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE7E,qEAAqE;AACrE,eAAO,MAAM,iBAAiB;;;iBAMkC,CAAC;AACjE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEnE,qEAAqE;AACrE,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;iBAawD,CAAC;AAC7E,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,OAAO,CAAC,CAAC;AAE/C,wCAAwC;AACxC,eAAO,MAAM,UAAU;;;;iBAMsC,CAAC;AAC9D,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAErD,sDAAsD;AACtD,eAAO,MAAM,eAAe;;;;;;;iBAM8C,CAAC;AAC3E,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,eAAe,CAAC,CAAC;AAE/D,uDAAuD;AACvD,eAAO,MAAM,YAAY;;;iBAKyC,CAAC;AACnE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC"}
@@ -0,0 +1,89 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { z } from "zod";
4
+ import { JsonDate } from "@pithy-sh/core/src/data/codecs";
5
+ //#region src/workers/buildsTypes.ts
6
+ /**
7
+ * Zod schemas for the Cloudflare Builds REST API.
8
+ *
9
+ * CF Builds provides CI/CD for Workers — it clones a git repo, runs a build command, and optionally
10
+ * runs a deploy command. As of the SDK version this package targets, the Builds endpoints are not
11
+ * exposed as typed SDK resources, so `buildsManager` reaches them over raw `fetch` (the documented
12
+ * escape hatch) and validates every response through the schemas here. ISO-string dates on the wire
13
+ * are decoded to `Date` via the `JsonDate` codec, so each dated schema round-trips through
14
+ * `.parse()`/`.encode()`.
15
+ */
16
+ /** A git-provider repository linked to the Cloudflare account for builds. */
17
+ const CfRepoConnection = z.object({
18
+ repo_connection_uuid: z.string().describe("The connection's UUID, used to attach build triggers."),
19
+ repo_id: z.string().describe("The repository's id in the git provider."),
20
+ repo_name: z.string().describe("The repo path relative to the provider account."),
21
+ provider_type: z.string().describe("The git provider (e.g. 'gitlab', 'github')."),
22
+ provider_account_id: z.string().describe("The provider account identifier (e.g. 'group:15366484')."),
23
+ provider_account_name: z.string().describe("The provider account display name."),
24
+ created_on: JsonDate.describe("When the connection was created (ISO-8601 on the wire, Date in JS)."),
25
+ modified_on: JsonDate.describe("When the connection was last modified (ISO-8601 on the wire, Date in JS)."),
26
+ deleted_on: JsonDate.nullish().describe("When the connection was deleted, if it has been.")
27
+ }).describe("A git-provider repository connected to Cloudflare Builds.");
28
+ /** A build trigger linking a Worker script to a repo connection and its build/deploy commands. */
29
+ const CfBuildTrigger = z.object({
30
+ trigger_uuid: z.string().describe("The trigger's UUID."),
31
+ external_script_id: z.string().describe("The immutable Worker id (hex UUID) this trigger builds."),
32
+ build_token_uuid: z.string().describe("The build token this trigger authenticates with."),
33
+ build_token_name: z.string().nullish().describe("The build token's display name, if returned."),
34
+ trigger_name: z.string().nullish().describe("The trigger's human-readable name."),
35
+ build_command: z.string().describe("The shell command that builds the Worker."),
36
+ deploy_command: z.string().describe("The shell command CF Builds runs to deploy after a build."),
37
+ root_directory: z.string().describe("The repo subdirectory builds run from."),
38
+ branch_includes: z.array(z.string()).describe("Branch patterns whose pushes auto-fire the trigger."),
39
+ branch_excludes: z.array(z.string()).nullish().describe("Branch patterns excluded from auto-firing."),
40
+ path_includes: z.array(z.string()).nullish().describe("Path patterns whose changes auto-fire the trigger."),
41
+ path_excludes: z.array(z.string()).nullish().describe("Path patterns excluded from auto-firing."),
42
+ build_caching_enabled: z.boolean().nullish().describe("Whether build caching is enabled for the trigger."),
43
+ created_on: JsonDate.describe("When the trigger was created (ISO-8601 on the wire, Date in JS)."),
44
+ modified_on: JsonDate.describe("When the trigger was last modified (ISO-8601 on the wire, Date in JS)."),
45
+ deleted_on: JsonDate.nullish().describe("When the trigger was deleted, if it has been.")
46
+ }).describe("A Cloudflare Builds trigger binding a Worker script to a repo and build commands.");
47
+ /** Metadata about the commit a build ran against. */
48
+ const CfBuildTriggerMetadata = z.object({
49
+ branch: z.string().describe("The git branch the build ran against."),
50
+ commit_hash: z.string().describe("The git commit SHA the build ran against."),
51
+ build_trigger_source: z.string().nullish().describe("How the build was initiated (push, manual, api, …).")
52
+ }).loose().describe("Commit/branch metadata attached to a build.");
53
+ /** A back-reference from a build to the trigger that produced it. */
54
+ const CfBuildTriggerRef = z.object({
55
+ trigger_uuid: z.string().describe("The producing trigger's UUID."),
56
+ external_script_id: z.string().describe("The immutable Worker id the trigger targets.")
57
+ }).loose().describe("A reference to the trigger that produced a build.");
58
+ /** A single execution of a build trigger and its lifecycle state. */
59
+ const CfBuild = z.object({
60
+ build_uuid: z.string().describe("The build's identifier."),
61
+ status: z.string().describe("The build's lifecycle state (queued, initializing, running, stopped)."),
62
+ build_outcome: z.string().nullish().describe("The final result, present once the build completes."),
63
+ initializing_on: JsonDate.nullish().describe("When the build began initializing (ISO-8601 on the wire)."),
64
+ running_on: JsonDate.nullish().describe("When execution began (ISO-8601 on the wire, Date in JS)."),
65
+ stopped_on: JsonDate.nullish().describe("When the build finished (ISO-8601 on the wire, Date in JS)."),
66
+ created_on: JsonDate.describe("When the build was queued (ISO-8601 on the wire, Date in JS)."),
67
+ modified_on: JsonDate.describe("When the build's status last changed (ISO-8601 on the wire, Date in JS)."),
68
+ build_trigger_metadata: CfBuildTriggerMetadata.nullish().describe("Commit/branch metadata for the build."),
69
+ trigger: CfBuildTriggerRef.nullish().describe("The trigger that produced this build.")
70
+ }).describe("A single Cloudflare Builds execution and its lifecycle state.");
71
+ /** One line of a build's log output. */
72
+ const CfBuildLog = z.object({
73
+ line: z.number().describe("The log line number."),
74
+ timestamp: JsonDate.describe("When the line was emitted (ISO-8601 on the wire, Date in JS)."),
75
+ message: z.string().describe("The log message content.")
76
+ }).describe("A single line of Cloudflare Builds log output.");
77
+ /** An environment variable set on a build trigger. */
78
+ const CfTriggerEnvVar = z.object({
79
+ name: z.string().describe("The environment variable's name."),
80
+ value: z.string().describe("The environment variable's value."),
81
+ type: z.enum(["plain_text", "secret_text"]).describe("Whether the value is stored encrypted at rest.")
82
+ }).describe("An environment variable set on a Cloudflare Builds trigger.");
83
+ /** A build token usable by triggers on the account. */
84
+ const CfBuildToken = z.object({
85
+ build_token_uuid: z.string().describe("The build token's UUID."),
86
+ build_token_name: z.string().describe("The build token's display name.")
87
+ }).describe("A Cloudflare Builds token available on the account.");
88
+ //#endregion
89
+ export { CfBuild, CfBuildLog, CfBuildToken, CfBuildTrigger, CfBuildTriggerMetadata, CfBuildTriggerRef, CfRepoConnection, CfTriggerEnvVar };
@@ -0,0 +1,66 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { z } from "zod";
4
+ /**
5
+ * The shape of a Cloudflare Workers Builds lifecycle event, as delivered to a subscribed queue.
6
+ * A subscription (created via `workersProvisioner.setupBuildEventSubscription`) pushes one of these
7
+ * each time a build changes state. Consumers validate the raw message through `WorkersBuildEvent`
8
+ * before trusting it; ISO-string dates decode to `Date` via `JsonDate`, so the schema round-trips.
9
+ */
10
+ /** Where a build's lifecycle currently sits. */
11
+ export declare const WorkersBuildStatus: z.ZodEnum<{
12
+ initializing: "initializing";
13
+ queued: "queued";
14
+ running: "running";
15
+ stopped: "stopped";
16
+ }>;
17
+ export type WorkersBuildStatus = z.infer<typeof WorkersBuildStatus>;
18
+ /** The terminal result of a build, set once it reaches `stopped`. */
19
+ export declare const WorkersBuildOutcome: z.ZodEnum<{
20
+ cancelled: "cancelled";
21
+ fail: "fail";
22
+ skipped: "skipped";
23
+ success: "success";
24
+ terminated: "terminated";
25
+ }>;
26
+ export type WorkersBuildOutcome = z.infer<typeof WorkersBuildOutcome>;
27
+ /** What kicked off a build. */
28
+ export declare const WorkersTriggerSource: z.ZodEnum<{
29
+ api: "api";
30
+ manual: "manual";
31
+ pull_request: "pull_request";
32
+ push: "push";
33
+ }>;
34
+ export type WorkersTriggerSource = z.infer<typeof WorkersTriggerSource>;
35
+ /** A build lifecycle event delivered to a subscribed queue. */
36
+ export declare const WorkersBuildEvent: z.ZodObject<{
37
+ build_id: z.ZodString;
38
+ script_name: z.ZodString;
39
+ trigger_id: z.ZodString;
40
+ trigger_source: z.ZodEnum<{
41
+ api: "api";
42
+ manual: "manual";
43
+ pull_request: "pull_request";
44
+ push: "push";
45
+ }>;
46
+ status: z.ZodEnum<{
47
+ initializing: "initializing";
48
+ queued: "queued";
49
+ running: "running";
50
+ stopped: "stopped";
51
+ }>;
52
+ outcome: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
53
+ cancelled: "cancelled";
54
+ fail: "fail";
55
+ skipped: "skipped";
56
+ success: "success";
57
+ terminated: "terminated";
58
+ }>>>;
59
+ branch: z.ZodString;
60
+ commit_hash: z.ZodString;
61
+ started_at: z.ZodOptional<z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>>>;
62
+ completed_at: z.ZodOptional<z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>>>;
63
+ created_at: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
64
+ }, z.core.$strip>;
65
+ export type WorkersBuildEvent = z.output<typeof WorkersBuildEvent>;
66
+ //# sourceMappingURL=workersBuildEvent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workersBuildEvent.d.ts","sourceRoot":"","sources":["../../src/workers/workersBuildEvent.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;GAKG;AAEH,gDAAgD;AAChD,eAAO,MAAM,kBAAkB;;;;;EAEoB,CAAC;AACpD,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEpE,qEAAqE;AACrE,eAAO,MAAM,mBAAmB;;;;;;EAE0B,CAAC;AAC3D,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEtE,+BAA+B;AAC/B,eAAO,MAAM,oBAAoB;;;;;EAEgB,CAAC;AAClD,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE,+DAA+D;AAC/D,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAc6D,CAAC;AAC5F,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
@@ -0,0 +1,49 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { z } from "zod";
4
+ import { JsonDate } from "@pithy-sh/core/src/data/codecs";
5
+ //#region src/workers/workersBuildEvent.ts
6
+ /**
7
+ * The shape of a Cloudflare Workers Builds lifecycle event, as delivered to a subscribed queue.
8
+ * A subscription (created via `workersProvisioner.setupBuildEventSubscription`) pushes one of these
9
+ * each time a build changes state. Consumers validate the raw message through `WorkersBuildEvent`
10
+ * before trusting it; ISO-string dates decode to `Date` via `JsonDate`, so the schema round-trips.
11
+ */
12
+ /** Where a build's lifecycle currently sits. */
13
+ const WorkersBuildStatus = z.enum([
14
+ "queued",
15
+ "initializing",
16
+ "running",
17
+ "stopped"
18
+ ]).describe("A Cloudflare Builds lifecycle state.");
19
+ /** The terminal result of a build, set once it reaches `stopped`. */
20
+ const WorkersBuildOutcome = z.enum([
21
+ "success",
22
+ "fail",
23
+ "skipped",
24
+ "cancelled",
25
+ "terminated"
26
+ ]).describe("The terminal outcome of a Cloudflare build.");
27
+ /** What kicked off a build. */
28
+ const WorkersTriggerSource = z.enum([
29
+ "push",
30
+ "pull_request",
31
+ "manual",
32
+ "api"
33
+ ]).describe("What initiated a Cloudflare build.");
34
+ /** A build lifecycle event delivered to a subscribed queue. */
35
+ const WorkersBuildEvent = z.object({
36
+ build_id: z.string().describe("The build's unique identifier from CF Builds."),
37
+ script_name: z.string().describe("The Worker script this build targets."),
38
+ trigger_id: z.string().describe("The build trigger that initiated this build."),
39
+ trigger_source: WorkersTriggerSource.describe("How the build was initiated."),
40
+ status: WorkersBuildStatus.describe("The build's current lifecycle state."),
41
+ outcome: WorkersBuildOutcome.nullish().describe("The final result, set once status reaches 'stopped'."),
42
+ branch: z.string().describe("The git branch that was built."),
43
+ commit_hash: z.string().describe("The git commit SHA that was built."),
44
+ started_at: JsonDate.nullish().describe("When execution began (ISO-8601 on the wire, Date in JS)."),
45
+ completed_at: JsonDate.nullish().describe("When the build finished (ISO-8601 on the wire, Date in JS)."),
46
+ created_at: JsonDate.describe("When the build was queued (ISO-8601 on the wire, Date in JS).")
47
+ }).describe("A Cloudflare Workers Builds lifecycle event delivered to a subscribed queue.");
48
+ //#endregion
49
+ export { WorkersBuildEvent, WorkersBuildOutcome, WorkersBuildStatus, WorkersTriggerSource };