@theholocron/cloudflare-client 1.11.1 → 1.11.2

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.
package/README.md CHANGED
@@ -56,6 +56,43 @@ await cf.tunnels.putConfig("my-account-id", tunnel.id, {
56
56
  await cf.tunnels.delete("my-account-id", tunnel.id);
57
57
  ```
58
58
 
59
+ ## Usage — Pages
60
+
61
+ ```ts
62
+ const cf = createCloudflareClient({ token: process.env.CLOUDFLARE_API_TOKEN! });
63
+ const ACCOUNT = process.env.CLOUDFLARE_ACCOUNT_ID!;
64
+
65
+ // Ensure a Pages project exists
66
+ const existing = await cf.pages.getProject(ACCOUNT, "my-docs-preview");
67
+
68
+ // Create a project
69
+ const project = await cf.pages.createProject(ACCOUNT, {
70
+ name: "my-docs-preview",
71
+ production_branch: "main",
72
+ });
73
+
74
+ // Trigger a preview deployment for a branch
75
+ const deployment = await cf.pages.createDeployment(ACCOUNT, "my-docs-preview", "feat/my-feature");
76
+ console.log(deployment.url); // https://<hash>.my-docs-preview.pages.dev
77
+
78
+ // Get deployment status
79
+ const status = await cf.pages.getDeployment(ACCOUNT, "my-docs-preview", deployment.id);
80
+
81
+ // Add a custom domain to the project
82
+ await cf.pages.addDomain(ACCOUNT, "my-docs-preview", "*.preview.example.dev");
83
+
84
+ // List custom domains
85
+ const domains = await cf.pages.listDomains(ACCOUNT, "my-docs-preview");
86
+
87
+ // Set an env var on a project
88
+ await cf.pages.updateProject(ACCOUNT, "my-docs-preview", {
89
+ deployment_configs: {
90
+ preview: { env_vars: { MY_VAR: { value: "hello", type: "plain_text" } } },
91
+ production: { env_vars: {} },
92
+ },
93
+ });
94
+ ```
95
+
59
96
  ## Auth
60
97
 
61
98
  Create an [API Token](https://dash.cloudflare.com/profile/api-tokens) with the permissions your use case requires:
@@ -64,6 +101,7 @@ Create an [API Token](https://dash.cloudflare.com/profile/api-tokens) with the p
64
101
  | ------------------ | -------------------------------- |
65
102
  | DNS management | `Zone:Read`, `DNS:Edit` |
66
103
  | Tunnel management | `Account:Cloudflare Tunnel:Edit` |
104
+ | Pages deployments | `Account:Cloudflare Pages:Edit` |
67
105
  | Token verification | `User:API Tokens:Read` |
68
106
 
69
107
  Pass the token directly or via the `CLOUDFLARE_API_TOKEN` environment variable.
package/dist/index.d.mts CHANGED
@@ -31,6 +31,54 @@ interface CfDnsRecordInput {
31
31
  proxied?: boolean;
32
32
  }
33
33
  //#endregion
34
+ //#region src/pages/pages.d.ts
35
+ type CfPagesEnvVarType = "plain_text" | "secret_text";
36
+ interface CfPagesEnvVar {
37
+ value: string;
38
+ type: CfPagesEnvVarType;
39
+ }
40
+ interface CfPagesEnvConfig {
41
+ env_vars: Record<string, CfPagesEnvVar>;
42
+ }
43
+ interface CfPagesProject {
44
+ id: string;
45
+ name: string;
46
+ subdomain: string;
47
+ domains: string[];
48
+ production_branch: string;
49
+ deployment_configs: {
50
+ preview: CfPagesEnvConfig;
51
+ production: CfPagesEnvConfig;
52
+ };
53
+ }
54
+ interface CfPagesProjectInput {
55
+ name: string;
56
+ production_branch: string;
57
+ }
58
+ interface CfPagesDeploymentStage {
59
+ name: string;
60
+ status: "idle" | "active" | "canceled" | "success" | "failure";
61
+ }
62
+ interface CfPagesDomain {
63
+ id: string;
64
+ name: string;
65
+ status: "active" | "pending" | "blocked" | "error" | "moved" | "pending_tls";
66
+ }
67
+ interface CfPagesDeployment {
68
+ id: string;
69
+ url: string;
70
+ environment: "preview" | "production";
71
+ deployment_trigger: {
72
+ type: string;
73
+ metadata: {
74
+ branch: string;
75
+ commit_hash: string;
76
+ };
77
+ };
78
+ latest_stage: CfPagesDeploymentStage;
79
+ created_on: string;
80
+ }
81
+ //#endregion
34
82
  //#region src/zones/zones.d.ts
35
83
  interface CfZone {
36
84
  id: string;
@@ -71,6 +119,16 @@ declare function createCloudflareClient(opts: CloudflareClientOptions): {
71
119
  id: string;
72
120
  }>;
73
121
  };
122
+ pages: {
123
+ listProjects: (accountId: string) => Promise<CfPagesProject[]>;
124
+ getProject: (accountId: string, name: string) => Promise<CfPagesProject>;
125
+ createProject: (accountId: string, input: CfPagesProjectInput) => Promise<CfPagesProject>;
126
+ updateProject: (accountId: string, name: string, patch: Partial<Pick<CfPagesProject, "deployment_configs" | "production_branch">>) => Promise<CfPagesProject>;
127
+ createDeployment: (accountId: string, projectName: string, branch: string) => Promise<CfPagesDeployment>;
128
+ getDeployment: (accountId: string, projectName: string, deploymentId: string) => Promise<CfPagesDeployment>;
129
+ listDomains: (accountId: string, projectName: string) => Promise<CfPagesDomain[]>;
130
+ addDomain: (accountId: string, projectName: string, hostname: string) => Promise<CfPagesDomain>;
131
+ };
74
132
  zones: {
75
133
  list: (query?: {
76
134
  name?: string;
@@ -95,4 +153,4 @@ declare function createCloudflareClient(opts: CloudflareClientOptions): {
95
153
  };
96
154
  type CloudflareClient = ReturnType<typeof createCloudflareClient>;
97
155
  //#endregion
98
- export { type CfDnsRecord, type CfDnsRecordInput, type CfDnsRecordType, type CfEnvelope, type CfIngressRule, type CfTokenVerification, type CfTunnel, type CfTunnelConfig, type CfZone, CloudflareClient, type CloudflareClientOptions, createCloudflareClient };
156
+ export { type CfDnsRecord, type CfDnsRecordInput, type CfDnsRecordType, type CfEnvelope, type CfIngressRule, type CfPagesDeployment, type CfPagesDeploymentStage, type CfPagesDomain, type CfPagesEnvConfig, type CfPagesEnvVar, type CfPagesEnvVarType, type CfPagesProject, type CfPagesProjectInput, type CfTokenVerification, type CfTunnel, type CfTunnelConfig, type CfZone, CloudflareClient, type CloudflareClientOptions, createCloudflareClient };
package/dist/index.mjs CHANGED
@@ -44,6 +44,20 @@ function dns(rest) {
44
44
  };
45
45
  }
46
46
  //#endregion
47
+ //#region src/pages/pages.ts
48
+ function pages(rest) {
49
+ return {
50
+ listProjects: (accountId) => cfRequest(rest, "GET", `/accounts/${accountId}/pages/projects`, void 0, { per_page: "100" }),
51
+ getProject: (accountId, name) => cfRequest(rest, "GET", `/accounts/${accountId}/pages/projects/${name}`),
52
+ createProject: (accountId, input) => cfRequest(rest, "POST", `/accounts/${accountId}/pages/projects`, input),
53
+ updateProject: (accountId, name, patch) => cfRequest(rest, "PATCH", `/accounts/${accountId}/pages/projects/${name}`, patch),
54
+ createDeployment: (accountId, projectName, branch) => cfRequest(rest, "POST", `/accounts/${accountId}/pages/projects/${projectName}/deployments`, { branch }),
55
+ getDeployment: (accountId, projectName, deploymentId) => cfRequest(rest, "GET", `/accounts/${accountId}/pages/projects/${projectName}/deployments/${deploymentId}`),
56
+ listDomains: (accountId, projectName) => cfRequest(rest, "GET", `/accounts/${accountId}/pages/projects/${projectName}/domains`),
57
+ addDomain: (accountId, projectName, hostname) => cfRequest(rest, "POST", `/accounts/${accountId}/pages/projects/${projectName}/domains`, { name: hostname })
58
+ };
59
+ }
60
+ //#endregion
47
61
  //#region src/tokens/tokens.ts
48
62
  function tokens(rest) {
49
63
  return { verify: () => cfRequest(rest, "GET", "/user/tokens/verify") };
@@ -77,6 +91,7 @@ function createCloudflareClient(opts) {
77
91
  const rest = createCloudflareRestClient(opts);
78
92
  return {
79
93
  dns: dns(rest),
94
+ pages: pages(rest),
80
95
  zones: zones(rest),
81
96
  tunnels: tunnels(rest),
82
97
  tokens: tokens(rest)
package/package.json CHANGED
@@ -1,7 +1,15 @@
1
1
  {
2
2
  "name": "@theholocron/cloudflare-client",
3
- "version": "1.11.1",
3
+ "version": "1.11.2",
4
4
  "description": "A TypeScript client for the Cloudflare API",
5
+ "keywords": [
6
+ "cloudflare",
7
+ "dns",
8
+ "tunnel",
9
+ "typescript",
10
+ "http-client",
11
+ "api"
12
+ ],
5
13
  "homepage": "https://github.com/theholocron/clients/tree/main/packages/cloudflare-client#readme",
6
14
  "bugs": "https://github.com/theholocron/clients/issues",
7
15
  "repository": {
@@ -11,17 +19,8 @@
11
19
  },
12
20
  "license": "GPL-3.0",
13
21
  "author": "Newton Koumantzelis",
14
- "keywords": [
15
- "cloudflare",
16
- "dns",
17
- "tunnel",
18
- "typescript",
19
- "http-client",
20
- "api"
21
- ],
22
- "type": "module",
23
22
  "sideEffects": false,
24
- "main": "./dist/index.mjs",
23
+ "type": "module",
25
24
  "exports": {
26
25
  ".": {
27
26
  "types": "./dist/index.d.mts",
@@ -29,15 +28,20 @@
29
28
  "default": "./dist/index.mjs"
30
29
  }
31
30
  },
31
+ "main": "./dist/index.mjs",
32
+ "files": [
33
+ "dist",
34
+ "README.md"
35
+ ],
32
36
  "dependencies": {
33
- "@theholocron/http-client": "^1.11.1"
37
+ "@theholocron/http-client": "^1.11.2"
34
38
  },
35
39
  "devDependencies": {
40
+ "@theholocron/eslint-config": "^7.23.1",
41
+ "@theholocron/tsconfig": "^7.20.0",
42
+ "@theholocron/tsdown-config": "^7.20.0",
43
+ "@theholocron/vitest-config": "^7.20.0",
36
44
  "@types/node": "^26.2.0",
37
- "@theholocron/eslint-config": "^7.24.1",
38
- "@theholocron/tsconfig": "^7.24.1",
39
- "@theholocron/tsdown-config": "^7.24.1",
40
- "@theholocron/vitest-config": "^7.24.1",
41
45
  "@vitest/coverage-v8": "^4.1.10",
42
46
  "@vitest/eslint-plugin": "^1.6.25",
43
47
  "eslint": "^10.8.1",
@@ -48,24 +52,20 @@
48
52
  "typescript": "^5.9.3",
49
53
  "vitest": "^4.1.10"
50
54
  },
51
- "publishConfig": {
52
- "access": "public"
53
- },
54
- "files": [
55
- "dist",
56
- "README.md"
57
- ],
58
55
  "engines": {
59
56
  "node": ">=22.0.0"
60
57
  },
58
+ "publishConfig": {
59
+ "access": "public"
60
+ },
61
61
  "releases": "https://github.com/theholocron/clients/releases",
62
62
  "wiki": "https://github.com/theholocron/clients/wiki",
63
63
  "scripts": {
64
64
  "build": "tsdown",
65
65
  "lint": "eslint .",
66
66
  "test": "vitest run",
67
- "test:watch": "vitest",
68
67
  "test:coverage": "vitest run --coverage",
68
+ "test:watch": "vitest",
69
69
  "typecheck": "tsc --noEmit"
70
70
  },
71
71
  "types": "./dist/index.d.mts"