@pithy-sh/cloudflare 0.1.1 → 0.1.3

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 +99 -0
  2. package/dist/ai/aiManager.d.ts.map +1 -0
  3. package/dist/ai/aiManager.js +148 -0
  4. package/dist/ai/vectorizeManager.d.ts +67 -0
  5. package/dist/ai/vectorizeManager.d.ts.map +1 -0
  6. package/dist/ai/vectorizeManager.js +101 -0
  7. package/dist/ai/vectorizeProvisioner.d.ts +123 -0
  8. package/dist/ai/vectorizeProvisioner.d.ts.map +1 -0
  9. package/dist/ai/vectorizeProvisioner.js +195 -0
  10. package/dist/client/accounts.d.ts +48 -0
  11. package/dist/client/accounts.d.ts.map +1 -0
  12. package/dist/client/accounts.js +55 -0
  13. package/dist/client/clients.d.ts +122 -0
  14. package/dist/client/clients.d.ts.map +1 -0
  15. package/dist/client/clients.js +216 -0
  16. package/dist/client/errors.d.ts +73 -0
  17. package/dist/client/errors.d.ts.map +1 -0
  18. package/dist/client/errors.js +98 -0
  19. package/dist/client/manager.d.ts +45 -0
  20. package/dist/client/manager.d.ts.map +1 -0
  21. package/dist/client/manager.js +51 -0
  22. package/dist/d1/d1Manager.d.ts +74 -0
  23. package/dist/d1/d1Manager.d.ts.map +1 -0
  24. package/dist/d1/d1Manager.js +128 -0
  25. package/dist/d1/d1PreparedStatement.d.ts +24 -0
  26. package/dist/d1/d1PreparedStatement.d.ts.map +1 -0
  27. package/dist/d1/d1PreparedStatement.js +91 -0
  28. package/dist/d1/d1Provisioner.d.ts +28 -0
  29. package/dist/d1/d1Provisioner.d.ts.map +1 -0
  30. package/dist/d1/d1Provisioner.js +67 -0
  31. package/dist/email/emailRoutingManager.d.ts +36 -0
  32. package/dist/email/emailRoutingManager.d.ts.map +1 -0
  33. package/dist/email/emailRoutingManager.js +124 -0
  34. package/dist/email/emailSendManager.d.ts +45 -0
  35. package/dist/email/emailSendManager.d.ts.map +1 -0
  36. package/dist/email/emailSendManager.js +52 -0
  37. package/dist/env/devVars.d.ts +65 -0
  38. package/dist/env/devVars.d.ts.map +1 -0
  39. package/dist/env/devVars.js +84 -0
  40. package/dist/hostnames/customHostnamesManager.d.ts +51 -0
  41. package/dist/hostnames/customHostnamesManager.d.ts.map +1 -0
  42. package/dist/hostnames/customHostnamesManager.js +84 -0
  43. package/dist/kv/kvManager.d.ts +76 -0
  44. package/dist/kv/kvManager.d.ts.map +1 -0
  45. package/dist/kv/kvManager.js +135 -0
  46. package/dist/kv/kvProvisioner.d.ts +28 -0
  47. package/dist/kv/kvProvisioner.d.ts.map +1 -0
  48. package/dist/kv/kvProvisioner.js +71 -0
  49. package/dist/media/assetSeeder.d.ts +31 -0
  50. package/dist/media/assetSeeder.d.ts.map +1 -0
  51. package/dist/media/assetSeeder.js +70 -0
  52. package/dist/media/imageManager.d.ts +34 -0
  53. package/dist/media/imageManager.d.ts.map +1 -0
  54. package/dist/media/imageManager.js +103 -0
  55. package/dist/media/ownership.d.ts +40 -0
  56. package/dist/media/ownership.d.ts.map +1 -0
  57. package/dist/media/ownership.js +46 -0
  58. package/dist/media/streamManager.d.ts +83 -0
  59. package/dist/media/streamManager.d.ts.map +1 -0
  60. package/dist/media/streamManager.js +145 -0
  61. package/dist/queue/queueManager.d.ts +84 -0
  62. package/dist/queue/queueManager.d.ts.map +1 -0
  63. package/dist/queue/queueManager.js +114 -0
  64. package/dist/r2/r2Credentials.d.ts +12 -0
  65. package/dist/r2/r2Credentials.d.ts.map +1 -0
  66. package/dist/r2/r2Credentials.js +13 -0
  67. package/dist/r2/r2Manager.d.ts +226 -0
  68. package/dist/r2/r2Manager.d.ts.map +1 -0
  69. package/dist/r2/r2Manager.js +405 -0
  70. package/dist/r2/r2Provisioner.d.ts +39 -0
  71. package/dist/r2/r2Provisioner.d.ts.map +1 -0
  72. package/dist/r2/r2Provisioner.js +86 -0
  73. package/dist/secrets/secretsStoreManager.d.ts +82 -0
  74. package/dist/secrets/secretsStoreManager.d.ts.map +1 -0
  75. package/dist/secrets/secretsStoreManager.js +147 -0
  76. package/dist/secrets/secretsStores.d.ts +47 -0
  77. package/dist/secrets/secretsStores.d.ts.map +1 -0
  78. package/dist/secrets/secretsStores.js +65 -0
  79. package/dist/test-utils/emailRoutingRules.d.ts +39 -0
  80. package/dist/test-utils/emailRoutingRules.d.ts.map +1 -0
  81. package/dist/test-utils/emailRoutingRules.js +89 -0
  82. package/dist/test-utils/fixtureReportSetup.d.ts +25 -0
  83. package/dist/test-utils/fixtureReportSetup.d.ts.map +1 -0
  84. package/dist/test-utils/fixtureReportSetup.js +30 -0
  85. package/dist/test-utils/fixtures.d.ts +224 -0
  86. package/dist/test-utils/fixtures.d.ts.map +1 -0
  87. package/dist/test-utils/fixtures.js +277 -0
  88. package/dist/test-utils/harness.d.ts +192 -0
  89. package/dist/test-utils/harness.d.ts.map +1 -0
  90. package/dist/test-utils/harness.js +351 -0
  91. package/dist/test-utils/inboundRecorder.d.ts +91 -0
  92. package/dist/test-utils/inboundRecorder.d.ts.map +1 -0
  93. package/dist/test-utils/inboundRecorder.js +141 -0
  94. package/dist/test-utils/integrationSetup.d.ts +22 -0
  95. package/dist/test-utils/integrationSetup.d.ts.map +1 -0
  96. package/dist/test-utils/integrationSetup.js +37 -0
  97. package/dist/test-utils/reap.d.ts +112 -0
  98. package/dist/test-utils/reap.d.ts.map +1 -0
  99. package/dist/test-utils/reap.js +185 -0
  100. package/dist/tokens/accountTokensManager.d.ts +157 -0
  101. package/dist/tokens/accountTokensManager.d.ts.map +1 -0
  102. package/dist/tokens/accountTokensManager.js +280 -0
  103. package/dist/tokens/permissions.d.ts +36 -0
  104. package/dist/tokens/permissions.d.ts.map +1 -0
  105. package/dist/tokens/permissions.js +50 -0
  106. package/dist/tokens/profiles.d.ts +102 -0
  107. package/dist/tokens/profiles.d.ts.map +1 -0
  108. package/dist/tokens/profiles.js +137 -0
  109. package/dist/turnstile/turnstileManager.d.ts +75 -0
  110. package/dist/turnstile/turnstileManager.d.ts.map +1 -0
  111. package/dist/turnstile/turnstileManager.js +138 -0
  112. package/dist/user/userManager.d.ts +36 -0
  113. package/dist/user/userManager.d.ts.map +1 -0
  114. package/dist/user/userManager.js +58 -0
  115. package/dist/workers/buildsManager.d.ts +116 -0
  116. package/dist/workers/buildsManager.d.ts.map +1 -0
  117. package/dist/workers/buildsManager.js +237 -0
  118. package/dist/workers/buildsTypes.d.ts +102 -0
  119. package/dist/workers/buildsTypes.d.ts.map +1 -0
  120. package/dist/workers/buildsTypes.js +87 -0
  121. package/dist/workers/workersBuildEvent.d.ts +64 -0
  122. package/dist/workers/workersBuildEvent.d.ts.map +1 -0
  123. package/dist/workers/workersBuildEvent.js +47 -0
  124. package/dist/workers/workersManager.d.ts +136 -0
  125. package/dist/workers/workersManager.d.ts.map +1 -0
  126. package/dist/workers/workersManager.js +312 -0
  127. package/dist/workers/workersProvisioner.d.ts +80 -0
  128. package/dist/workers/workersProvisioner.d.ts.map +1 -0
  129. package/dist/workers/workersProvisioner.js +106 -0
  130. package/dist/workflows/stepFailure.d.ts +180 -0
  131. package/dist/workflows/stepFailure.d.ts.map +1 -0
  132. package/dist/workflows/stepFailure.js +227 -0
  133. package/dist/workflows/workflowsClient.d.ts +87 -0
  134. package/dist/workflows/workflowsClient.d.ts.map +1 -0
  135. package/dist/workflows/workflowsClient.js +156 -0
  136. package/dist/zones/zonesManager.d.ts +50 -0
  137. package/dist/zones/zonesManager.d.ts.map +1 -0
  138. package/dist/zones/zonesManager.js +74 -0
  139. package/package.json +18 -9
@@ -0,0 +1,50 @@
1
+ import { z } from "zod";
2
+ import { CloudflareManager } from "../client/manager";
3
+ /**
4
+ * The account's zones — the registrable domains a custom domain can attach to.
5
+ *
6
+ * **Nothing here listed zones before.** Every zone-scoped operation in this package takes a `zoneId` the
7
+ * caller already knows: `CloudflareCustomHostnamesManager` takes it as constructor config,
8
+ * `CloudflareEmailRoutingManager` takes it per method, `CloudflareWorkersManager.addRoute` takes it
9
+ * positionally — and `pithy email provision` makes a human paste one, telling them to "find it on the
10
+ * zone's Overview page". So the CLI never *discovered* a zone; it demanded one.
11
+ *
12
+ * That is what this exists to change. When `pithy init` and `pithy worker add` ask where a Worker will
13
+ * answer, offering the account's real zones means a typo fails at `init` with a list of what exists,
14
+ * rather than at `deploy` with a Cloudflare error to decode.
15
+ *
16
+ * Read-only, deliberately. Pithy attaches routes to zones and never creates, transfers, or deletes one —
17
+ * a zone is the adopter's relationship with their registrar, not a resource this toolset provisions. The
18
+ * scoped token needs only `Zone:Read`.
19
+ */
20
+ /** One zone on the account. */
21
+ export declare const ZoneInfo: z.ZodObject<{
22
+ id: z.ZodString;
23
+ name: z.ZodString;
24
+ status: z.ZodString;
25
+ }, z.core.$strip>;
26
+ export type ZoneInfo = z.output<typeof ZoneInfo>;
27
+ /** Read the account's zones. Never creates or deletes — a zone is the adopter's, not ours to provision. */
28
+ export declare class CloudflareZonesManager extends CloudflareManager {
29
+ getServiceType(): string;
30
+ /** Prove access by listing. A read, and never throws — the caller decides what an inaccessible account means. */
31
+ validateServiceAccess(): Promise<boolean>;
32
+ /**
33
+ * Every zone on this account, name-sorted so a picker is stable between runs.
34
+ *
35
+ * Filtered to the account, because a user-bound token can see zones on accounts this project has
36
+ * nothing to do with — offering those would invite someone to attach a Worker to a zone that another
37
+ * account owns, which fails at deploy with an error that names neither problem.
38
+ */
39
+ listZones(): Promise<ZoneInfo[]>;
40
+ /**
41
+ * The zone a hostname belongs to, or `null`.
42
+ *
43
+ * Matches the **longest** zone name that the hostname sits under, which is the only correct rule when
44
+ * an account holds both `example.com` and `eu.example.com`: `api.eu.example.com` belongs to the latter,
45
+ * and picking the first match would attach it to the wrong zone. A public-suffix guess is not used at
46
+ * all — a zone can itself be a subdomain, and the account's own list is the authority.
47
+ */
48
+ findZoneForHostname(hostname: string): Promise<ZoneInfo | null>;
49
+ }
50
+ //# sourceMappingURL=zonesManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zonesManager.d.ts","sourceRoot":"","sources":["../../src/zones/zonesManager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;;;;;;;;;;GAgBG;AAEH,+BAA+B;AAC/B,eAAO,MAAM,QAAQ;;;;iBAc4F,CAAC;AAClH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEjD,2GAA2G;AAC3G,qBAAa,sBAAuB,SAAQ,iBAAiB;IAC3D,cAAc,IAAI,MAAM,CAEvB;IAED,iHAAiH;IAC3G,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC,CAO9C;IAED;;;;;;OAMG;IACG,SAAS,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CASrC;IAED;;;;;;;OAOG;IACG,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAKpE;CACF"}
@@ -0,0 +1,74 @@
1
+ import { cloudflareRequest } from "../client/errors.js";
2
+ import { CloudflareManager } from "../client/manager.js";
3
+ import { z } from "zod";
4
+ //#region src/zones/zonesManager.ts
5
+ /**
6
+ * The account's zones — the registrable domains a custom domain can attach to.
7
+ *
8
+ * **Nothing here listed zones before.** Every zone-scoped operation in this package takes a `zoneId` the
9
+ * caller already knows: `CloudflareCustomHostnamesManager` takes it as constructor config,
10
+ * `CloudflareEmailRoutingManager` takes it per method, `CloudflareWorkersManager.addRoute` takes it
11
+ * positionally — and `pithy email provision` makes a human paste one, telling them to "find it on the
12
+ * zone's Overview page". So the CLI never *discovered* a zone; it demanded one.
13
+ *
14
+ * That is what this exists to change. When `pithy init` and `pithy worker add` ask where a Worker will
15
+ * answer, offering the account's real zones means a typo fails at `init` with a list of what exists,
16
+ * rather than at `deploy` with a Cloudflare error to decode.
17
+ *
18
+ * Read-only, deliberately. Pithy attaches routes to zones and never creates, transfers, or deletes one —
19
+ * a zone is the adopter's relationship with their registrar, not a resource this toolset provisions. The
20
+ * scoped token needs only `Zone:Read`.
21
+ */
22
+ /** One zone on the account. */
23
+ const ZoneInfo = z.object({
24
+ id: z.string().describe("The CF-assigned zone id, which every zone-scoped API call is addressed by."),
25
+ name: z.string().describe("The registrable domain, e.g. `example.com`. This is the value a Worker's `domains` declaration names as its `zone`, and what wrangler writes as `zone_name`."),
26
+ status: z.string().describe("The zone's lifecycle status — `active` once Cloudflare is serving it, otherwise `pending`, `initializing`, or `moved`. A non-active zone cannot carry a custom domain yet, so a picker shows it and says so rather than hiding it.")
27
+ }).describe("One Cloudflare zone: the registrable domain a custom domain can attach to, and whether it is live.");
28
+ /** Read the account's zones. Never creates or deletes — a zone is the adopter's, not ours to provision. */
29
+ var CloudflareZonesManager = class extends CloudflareManager {
30
+ getServiceType() {
31
+ return "Cloudflare Zones";
32
+ }
33
+ /** Prove access by listing. A read, and never throws — the caller decides what an inaccessible account means. */
34
+ async validateServiceAccess() {
35
+ try {
36
+ await this.listZones();
37
+ return true;
38
+ } catch {
39
+ return false;
40
+ }
41
+ }
42
+ /**
43
+ * Every zone on this account, name-sorted so a picker is stable between runs.
44
+ *
45
+ * Filtered to the account, because a user-bound token can see zones on accounts this project has
46
+ * nothing to do with — offering those would invite someone to attach a Worker to a zone that another
47
+ * account owns, which fails at deploy with an error that names neither problem.
48
+ */
49
+ async listZones() {
50
+ return cloudflareRequest("list zones", async () => {
51
+ const zones = [];
52
+ for await (const zone of this.getClient().zones.list({ account: { id: this.accountId } })) {
53
+ const parsed = ZoneInfo.safeParse(zone);
54
+ if (parsed.success) zones.push(parsed.data);
55
+ }
56
+ return zones.sort((a, b) => a.name.localeCompare(b.name));
57
+ });
58
+ }
59
+ /**
60
+ * The zone a hostname belongs to, or `null`.
61
+ *
62
+ * Matches the **longest** zone name that the hostname sits under, which is the only correct rule when
63
+ * an account holds both `example.com` and `eu.example.com`: `api.eu.example.com` belongs to the latter,
64
+ * and picking the first match would attach it to the wrong zone. A public-suffix guess is not used at
65
+ * all — a zone can itself be a subdomain, and the account's own list is the authority.
66
+ */
67
+ async findZoneForHostname(hostname) {
68
+ const candidates = (await this.listZones()).filter((zone) => hostname === zone.name || hostname.endsWith(`.${zone.name}`));
69
+ if (candidates.length === 0) return null;
70
+ return candidates.reduce((longest, zone) => zone.name.length > longest.name.length ? zone : longest);
71
+ }
72
+ };
73
+ //#endregion
74
+ export { CloudflareZonesManager, ZoneInfo };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pithy-sh/cloudflare",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,18 +8,23 @@
8
8
  "directory": "packages/cloudflare"
9
9
  },
10
10
  "files": [
11
+ "dist",
11
12
  "src",
12
- "!src/**/*.test.*"
13
+ "!src/**/*.test.*",
14
+ "!dist/**/*.test.*"
13
15
  ],
14
16
  "type": "module",
15
17
  "engines": {
16
18
  "node": ">=22"
17
19
  },
18
20
  "exports": {
19
- "./src/*": "./src/*.ts"
21
+ "./src/*": {
22
+ "types": "./dist/*.d.ts",
23
+ "default": "./dist/*.js"
24
+ }
20
25
  },
21
26
  "scripts": {
22
- "build": "tsc -p tsconfig.json --noEmit false --outDir dist",
27
+ "build": "tsdown && tsc -p tsconfig.build.json",
23
28
  "typecheck": "tsc -p tsconfig.json",
24
29
  "test": "vitest run",
25
30
  "test:node": "vitest run --project=node",
@@ -31,18 +36,22 @@
31
36
  "@aws-sdk/client-s3": "^3.1111.0",
32
37
  "@aws-sdk/s3-request-presigner": "^3.1111.0",
33
38
  "@cloudflare/workers-types": "^5.20260729.1",
34
- "@pithy-sh/core": "workspace:*",
39
+ "@pithy-sh/core": "^0.1.3",
35
40
  "cloudflare": "^7.0.0",
36
- "js-base64": "^3.9.2",
37
- "kysely": "^0.29.0",
38
- "zod": "^4.0.0"
41
+ "js-base64": "^3.9.2"
39
42
  },
40
43
  "devDependencies": {
41
44
  "@pithy-sh/tsconfig": "workspace:*",
42
45
  "@types/node": "^22.15.0",
43
46
  "@vitest/coverage-v8": "^4.1.0",
47
+ "kysely": "^0.29.0",
44
48
  "kysely-d1": "^0.4.0",
49
+ "tsdown": "^0.23.0",
45
50
  "typescript": "^7.0.2",
46
- "vitest": "^4.1.0"
51
+ "vitest": "^4.1.0",
52
+ "zod": "^4.4.0"
53
+ },
54
+ "peerDependencies": {
55
+ "zod": "^4.4.0"
47
56
  }
48
57
  }