@pithy-sh/cloudflare 0.1.7 → 0.2.1

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.
@@ -88,6 +88,25 @@ export declare class CloudflareWorkersManager extends CloudflareManager {
88
88
  * same endpoint — `previews_enabled` is always sent explicitly so CF does not default it to true.
89
89
  */
90
90
  setSubdomainSettings(scriptName: string, enabled: boolean, previewsEnabled?: boolean): Promise<void>;
91
+ /**
92
+ * A deployed Worker's **plain-text vars**, keyed by binding name — or `null` when the account holds
93
+ * no Worker of that name.
94
+ *
95
+ * Read through `scripts/script-and-version-settings`, which answers the *deployed* script's binding
96
+ * list in one call. {@link listVersions} + {@link getVersion} would answer the same question in two,
97
+ * off the newest *uploaded* version — which is not necessarily the deployed one under gradual
98
+ * rollouts, and which costs a round trip to learn a version id nobody wanted. So: settings.
99
+ *
100
+ * **Only `plain_text`.** A `secret_text` binding's value is never returned by the API, and a caller
101
+ * that wanted one would be asking the wrong question anyway; every other binding kind is a resource
102
+ * reference rather than a value. So this is the vars block a `wrangler.jsonc` declares, read back.
103
+ *
104
+ * `null` for a missing Worker rather than a throw, because "there is no such Worker" is an ordinary
105
+ * answer to this question — it is what a first deploy looks like. Every other failure throws, so a
106
+ * caller can tell *not deployed* from *the account would not answer*: {@link CloudflareWorkersManager}
107
+ * has no business collapsing those two into one silence, and #537's gate reports them differently.
108
+ */
109
+ getWorkerVars(scriptName: string): Promise<Record<string, string> | null>;
91
110
  /** Edit a Worker's settings (observability, logpush, tags, …). */
92
111
  updateSettings(scriptName: string, settings: WorkerSettings): Promise<void>;
93
112
  /** Delete a Worker script. */
@@ -1 +1 @@
1
- {"version":3,"file":"workersManager.d.ts","sourceRoot":"","sources":["../../src/workers/workersManager.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAClG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kDAAk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AC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAOjE;IAED;;;;OAIG;IACG,oBAAoB,CAAC,gBAAgB,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAoBvG;IAED;;;;OAIG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAO/C;IAED,cAAc,IAAI,MAAM,CAEvB;IAED,mEAAmE;IAC7D,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC,CAO9C;CACF"}
@@ -1,6 +1,6 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: MIT
3
- import { CloudflareInvalidResponseError, cloudflareRequest, messageOf } from "../client/errors.js";
3
+ import { CloudflareInvalidResponseError, cloudflareRequest, isNotFoundError, messageOf } from "../client/errors.js";
4
4
  import { CloudflareManager } from "../client/manager.js";
5
5
  import { NotFoundError, ValidationError } from "@pithy-sh/core/src/error/pithyError";
6
6
  //#region src/workers/workersManager.ts
@@ -147,6 +147,38 @@ var CloudflareWorkersManager = class extends CloudflareManager {
147
147
  previews_enabled: previewsEnabled
148
148
  }));
149
149
  }
150
+ /**
151
+ * A deployed Worker's **plain-text vars**, keyed by binding name — or `null` when the account holds
152
+ * no Worker of that name.
153
+ *
154
+ * Read through `scripts/script-and-version-settings`, which answers the *deployed* script's binding
155
+ * list in one call. {@link listVersions} + {@link getVersion} would answer the same question in two,
156
+ * off the newest *uploaded* version — which is not necessarily the deployed one under gradual
157
+ * rollouts, and which costs a round trip to learn a version id nobody wanted. So: settings.
158
+ *
159
+ * **Only `plain_text`.** A `secret_text` binding's value is never returned by the API, and a caller
160
+ * that wanted one would be asking the wrong question anyway; every other binding kind is a resource
161
+ * reference rather than a value. So this is the vars block a `wrangler.jsonc` declares, read back.
162
+ *
163
+ * `null` for a missing Worker rather than a throw, because "there is no such Worker" is an ordinary
164
+ * answer to this question — it is what a first deploy looks like. Every other failure throws, so a
165
+ * caller can tell *not deployed* from *the account would not answer*: {@link CloudflareWorkersManager}
166
+ * has no business collapsing those two into one silence, and #537's gate reports them differently.
167
+ */
168
+ async getWorkerVars(scriptName) {
169
+ return cloudflareRequest(`get vars for '${scriptName}'`, async () => {
170
+ let settings;
171
+ try {
172
+ settings = await this.getClient().workers.scripts.scriptAndVersionSettings.get(scriptName, { account_id: this.accountId }, requestOptions);
173
+ } catch (error) {
174
+ if (isNotFoundError(error)) return null;
175
+ throw error;
176
+ }
177
+ const vars = {};
178
+ for (const binding of settings.bindings ?? []) if (binding.type === "plain_text") vars[binding.name] = binding.text;
179
+ return vars;
180
+ });
181
+ }
150
182
  /** Edit a Worker's settings (observability, logpush, tags, …). */
151
183
  async updateSettings(scriptName, settings) {
152
184
  await cloudflareRequest(`update settings for '${scriptName}'`, () => this.getClient().workers.scripts.settings.edit(scriptName, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pithy-sh/cloudflare",
3
- "version": "0.1.7",
3
+ "version": "0.2.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,11 +36,15 @@
36
36
  "@aws-sdk/client-s3": "^3.1111.0",
37
37
  "@aws-sdk/s3-request-presigner": "^3.1111.0",
38
38
  "@cloudflare/workers-types": "^5.20260729.1",
39
- "@pithy-sh/core": "^0.3.1",
40
39
  "cloudflare": "^7.0.0",
41
40
  "js-base64": "^3.9.2"
42
41
  },
42
+ "peerDependencies": {
43
+ "@pithy-sh/core": "^0.5.0",
44
+ "zod": "^4.4.0"
45
+ },
43
46
  "devDependencies": {
47
+ "@pithy-sh/core": "workspace:*",
44
48
  "@pithy-sh/tsconfig": "workspace:*",
45
49
  "@types/node": "^22.15.0",
46
50
  "@vitest/coverage-v8": "^4.1.0",
@@ -50,8 +54,5 @@
50
54
  "typescript": "^7.0.2",
51
55
  "vitest": "^4.1.0",
52
56
  "zod": "^4.4.0"
53
- },
54
- "peerDependencies": {
55
- "zod": "^4.4.0"
56
57
  }
57
58
  }
@@ -5,11 +5,12 @@ import { NotFoundError, ValidationError } from "@pithy-sh/core/src/error/pithyEr
5
5
  import type { Cloudflare } from "cloudflare";
6
6
  import type { RouteCreateResponse, RouteListResponse } from "cloudflare/resources/workers/routes";
7
7
  import type { Deployment } from "cloudflare/resources/workers/scripts/deployments";
8
+ import type { ScriptAndVersionSettingGetResponse } from "cloudflare/resources/workers/scripts/script-and-version-settings";
8
9
  import type { Script } from "cloudflare/resources/workers/scripts/scripts";
9
10
  import type { SecretListResponse } from "cloudflare/resources/workers/scripts/secrets";
10
11
  import type { SettingEditParams } from "cloudflare/resources/workers/scripts/settings";
11
12
  import type { VersionGetResponse, VersionListResponse } from "cloudflare/resources/workers/scripts/versions";
12
- import { CloudflareInvalidResponseError, cloudflareRequest, messageOf } from "../client/errors";
13
+ import { CloudflareInvalidResponseError, cloudflareRequest, isNotFoundError, messageOf } from "../client/errors";
13
14
  import { CloudflareManager } from "../client/manager";
14
15
 
15
16
  /** Per-call SDK timeout + retry budget for Worker management operations. */
@@ -212,6 +213,45 @@ export class CloudflareWorkersManager extends CloudflareManager {
212
213
  );
213
214
  }
214
215
 
216
+ /**
217
+ * A deployed Worker's **plain-text vars**, keyed by binding name — or `null` when the account holds
218
+ * no Worker of that name.
219
+ *
220
+ * Read through `scripts/script-and-version-settings`, which answers the *deployed* script's binding
221
+ * list in one call. {@link listVersions} + {@link getVersion} would answer the same question in two,
222
+ * off the newest *uploaded* version — which is not necessarily the deployed one under gradual
223
+ * rollouts, and which costs a round trip to learn a version id nobody wanted. So: settings.
224
+ *
225
+ * **Only `plain_text`.** A `secret_text` binding's value is never returned by the API, and a caller
226
+ * that wanted one would be asking the wrong question anyway; every other binding kind is a resource
227
+ * reference rather than a value. So this is the vars block a `wrangler.jsonc` declares, read back.
228
+ *
229
+ * `null` for a missing Worker rather than a throw, because "there is no such Worker" is an ordinary
230
+ * answer to this question — it is what a first deploy looks like. Every other failure throws, so a
231
+ * caller can tell *not deployed* from *the account would not answer*: {@link CloudflareWorkersManager}
232
+ * has no business collapsing those two into one silence, and #537's gate reports them differently.
233
+ */
234
+ async getWorkerVars(scriptName: string): Promise<Record<string, string> | null> {
235
+ return cloudflareRequest(`get vars for '${scriptName}'`, async () => {
236
+ let settings: ScriptAndVersionSettingGetResponse;
237
+ try {
238
+ settings = await this.getClient().workers.scripts.scriptAndVersionSettings.get(
239
+ scriptName,
240
+ { account_id: this.accountId },
241
+ requestOptions,
242
+ );
243
+ } catch (error) {
244
+ if (isNotFoundError(error)) return null;
245
+ throw error;
246
+ }
247
+ const vars: Record<string, string> = {};
248
+ for (const binding of settings.bindings ?? []) {
249
+ if (binding.type === "plain_text") vars[binding.name] = binding.text;
250
+ }
251
+ return vars;
252
+ });
253
+ }
254
+
215
255
  /** Edit a Worker's settings (observability, logpush, tags, …). */
216
256
  async updateSettings(scriptName: string, settings: WorkerSettings): Promise<void> {
217
257
  await cloudflareRequest(`update settings for '${scriptName}'`, () =>