@theholocron/holocron-plugin-cloudflare 5.0.0-alpha.25 → 5.0.0-alpha.250
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 +2 -2
- package/dist/index.d.mts +31 -37
- package/dist/index.mjs +47 -16
- package/package.json +18 -16
package/README.md
CHANGED
|
@@ -79,7 +79,7 @@ Zone ids are cached per plugin instance for the lifetime of the process.
|
|
|
79
79
|
|
|
80
80
|
## `deployment` capability
|
|
81
81
|
|
|
82
|
-
Manages [Cloudflare Pages](https://developers.cloudflare.com/pages/) projects. Used by `holocron setup` to provision per-PR preview deployments.
|
|
82
|
+
Manages [Cloudflare Pages](https://developers.cloudflare.com/pages/) projects. Used by `holocron repo setup` to provision per-PR preview deployments.
|
|
83
83
|
|
|
84
84
|
| Method | What it does |
|
|
85
85
|
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -106,7 +106,7 @@ cache, separate from `dns`'s.
|
|
|
106
106
|
|
|
107
107
|
### Preview deployment setup
|
|
108
108
|
|
|
109
|
-
When `preview: true` (or `preview: { project, domain }`) is set in a repo's deploy config, `holocron setup` calls:
|
|
109
|
+
When `preview: true` (or `preview: { project, domain }`) is set in a repo's deploy config, `holocron repo setup` calls:
|
|
110
110
|
|
|
111
111
|
1. `ensureProject` — creates `<org>-preview` if it doesn't exist
|
|
112
112
|
2. `ensureCustomDomain` — attaches `*.<domain>` to the project
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { AuthError, DeployScriptConfig, DeployScriptResult, Deployment, DeploymentProject, DeploymentProjectSettings, DeploymentRecord, DeploymentTarget, DeploymentTrigger, Dns, DnsRecord, ResolveTokenInput, WikiProxyConfig, Workers } from "@theholocron/cli";
|
|
1
|
+
import { AuthError, DeployScriptConfig, DeployScriptResult, Deployment, DeploymentProject, DeploymentProjectSettings, DeploymentRecord, DeploymentTarget, DeploymentTrigger, Dns, DnsRecord, DnsRecordRequest, ResolveTokenInput, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess, WikiProxyConfig, Workers } from "@theholocron/cli";
|
|
2
2
|
import { CloudflareClient, CloudflareClient as CloudflareClient$1, CloudflareClientOptions, createCloudflareClient } from "@theholocron/cloudflare-client";
|
|
3
|
-
|
|
4
|
-
declare
|
|
5
|
-
//#endregion
|
|
6
|
-
//#region src/capabilities/deployment.d.ts
|
|
7
|
-
declare class CloudflareDeployment implements Deployment {
|
|
3
|
+
export declare const resolveToken: (input?: ResolveTokenInput) => string;
|
|
4
|
+
export declare class CloudflareDeployment implements Deployment {
|
|
8
5
|
private readonly client;
|
|
9
6
|
private readonly accountId;
|
|
10
7
|
readonly key: "deployment";
|
|
@@ -28,12 +25,10 @@ declare class CloudflareDeployment implements Deployment {
|
|
|
28
25
|
getDeployment(deploymentId: string): Promise<DeploymentRecord>;
|
|
29
26
|
listPreviewDeployments(projectId: string, branch: string): Promise<DeploymentRecord[]>;
|
|
30
27
|
deletePreviewDeployments(projectId: string, deploymentIds: string[]): Promise<number>;
|
|
31
|
-
ensureCustomDomain(projectId: string, hostname: string): Promise<
|
|
28
|
+
ensureCustomDomain(projectId: string, hostname: string): Promise<DnsRecordRequest | null>;
|
|
32
29
|
private getProjectByName;
|
|
33
30
|
}
|
|
34
|
-
|
|
35
|
-
//#region src/capabilities/dns.d.ts
|
|
36
|
-
declare class CloudflareDns implements Dns {
|
|
31
|
+
export declare class CloudflareDns implements Dns {
|
|
37
32
|
private readonly client;
|
|
38
33
|
readonly key: "dns";
|
|
39
34
|
readonly providerName = "cloudflare";
|
|
@@ -42,6 +37,11 @@ declare class CloudflareDns implements Dns {
|
|
|
42
37
|
listRecords(domain: string): Promise<DnsRecord[]>;
|
|
43
38
|
upsertRecord(domain: string, record: DnsRecord): Promise<DnsRecord>;
|
|
44
39
|
deleteRecord(domain: string, id: string): Promise<void>;
|
|
40
|
+
/** `holocron doctor` has no specific domain to check — lists every zone the token can see instead. */
|
|
41
|
+
whoami(): Promise<{
|
|
42
|
+
ok: boolean;
|
|
43
|
+
zones: number;
|
|
44
|
+
}>;
|
|
45
45
|
/**
|
|
46
46
|
* Walk from full domain up to apex to find the Cloudflare zone.
|
|
47
47
|
* E.g. "api.staging.example.com" tries:
|
|
@@ -51,9 +51,7 @@ declare class CloudflareDns implements Dns {
|
|
|
51
51
|
*/
|
|
52
52
|
private resolveZone;
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
//#region src/capabilities/workers.d.ts
|
|
56
|
-
declare class CloudflareWorkers implements Workers {
|
|
54
|
+
export declare class CloudflareWorkers implements Workers {
|
|
57
55
|
private readonly client;
|
|
58
56
|
private readonly accountId;
|
|
59
57
|
readonly key: "workers";
|
|
@@ -61,30 +59,24 @@ declare class CloudflareWorkers implements Workers {
|
|
|
61
59
|
private readonly zoneCache;
|
|
62
60
|
constructor(client: () => Pick<CloudflareClient$1, "workers" | "zones">, accountId: string);
|
|
63
61
|
upsertProxy(hostname: string, config: WikiProxyConfig): Promise<void>;
|
|
62
|
+
/** `holocron doctor` has no specific script to check — lists every script the token can see instead. */
|
|
63
|
+
whoami(): Promise<{
|
|
64
|
+
ok: boolean;
|
|
65
|
+
scripts: number;
|
|
66
|
+
}>;
|
|
64
67
|
deployScript(name: string, config: DeployScriptConfig): Promise<DeployScriptResult>;
|
|
68
|
+
setSecret(script: string, name: string, value: string): Promise<void>;
|
|
69
|
+
secretNames(script: string): Promise<string[]>;
|
|
65
70
|
/** Idempotent create-or-update for one route pattern — shared by both public methods. */
|
|
66
71
|
private upsertRoute;
|
|
67
72
|
private resolveZone;
|
|
68
73
|
}
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/verify-token.d.ts
|
|
71
|
-
interface VerifyTokenSuccess {
|
|
72
|
-
ok: true;
|
|
73
|
-
subject: string;
|
|
74
|
-
}
|
|
75
|
-
interface VerifyTokenFailure {
|
|
76
|
-
ok: false;
|
|
77
|
-
message: string;
|
|
78
|
-
}
|
|
79
|
-
type VerifyTokenResult = VerifyTokenSuccess | VerifyTokenFailure;
|
|
80
74
|
interface VerifyTokenOptions {
|
|
81
75
|
baseUrl?: string;
|
|
82
76
|
fetch?: typeof fetch;
|
|
83
77
|
}
|
|
84
|
-
declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult>;
|
|
85
|
-
|
|
86
|
-
//#region src/index.d.ts
|
|
87
|
-
interface CloudflarePluginOptions extends ResolveTokenInput {
|
|
78
|
+
export declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult$1>;
|
|
79
|
+
export interface CloudflarePluginOptions extends ResolveTokenInput {
|
|
88
80
|
/**
|
|
89
81
|
* Cloudflare account ID. Required for Pages (deployment) operations;
|
|
90
82
|
* optional for DNS-only use.
|
|
@@ -94,25 +86,27 @@ interface CloudflarePluginOptions extends ResolveTokenInput {
|
|
|
94
86
|
baseUrl?: string;
|
|
95
87
|
fetch?: typeof fetch;
|
|
96
88
|
}
|
|
97
|
-
interface PluginContext {
|
|
89
|
+
export interface PluginContext {
|
|
98
90
|
options: CloudflarePluginOptions;
|
|
99
91
|
/** Memoized client — the token is resolved on first use, not at plugin load. */
|
|
100
92
|
client: () => CloudflareClient;
|
|
101
93
|
/** Memoized token resolver — shared by the client and the Workers capability. */
|
|
102
94
|
token: () => string;
|
|
103
95
|
}
|
|
104
|
-
declare function createContext(options?: CloudflarePluginOptions): PluginContext;
|
|
105
|
-
declare function dns(ctx: PluginContext): Dns;
|
|
106
|
-
declare function deployment(ctx: PluginContext): Deployment;
|
|
107
|
-
declare function workersCapability(ctx: PluginContext): Workers;
|
|
108
|
-
declare function createPlugin(options?: CloudflarePluginOptions): {
|
|
96
|
+
export declare function createContext(options?: CloudflarePluginOptions): PluginContext;
|
|
97
|
+
export declare function dns(ctx: PluginContext): Dns;
|
|
98
|
+
export declare function deployment(ctx: PluginContext): Deployment;
|
|
99
|
+
export declare function workersCapability(ctx: PluginContext): Workers;
|
|
100
|
+
export declare function createPlugin(options?: CloudflarePluginOptions): {
|
|
109
101
|
name: string;
|
|
102
|
+
probes: {
|
|
103
|
+
connection: import("@theholocron/cli").Probe;
|
|
104
|
+
};
|
|
110
105
|
capabilities: {
|
|
111
106
|
deployment?: (() => Deployment) | undefined;
|
|
112
107
|
workers?: (() => Workers) | undefined;
|
|
113
108
|
dns: () => Dns;
|
|
114
109
|
};
|
|
115
110
|
};
|
|
116
|
-
declare const AUTH_HINT: string;
|
|
117
|
-
|
|
118
|
-
export { AUTH_HINT, AuthError, type CloudflareClient, type CloudflareClientOptions, CloudflareDeployment, CloudflareDns, CloudflarePluginOptions, CloudflareWorkers, PluginContext, type ResolveTokenInput, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createCloudflareClient, createContext, createPlugin, deployment, dns, resolveToken, verifyToken, workersCapability };
|
|
111
|
+
export declare const AUTH_HINT: string;
|
|
112
|
+
export { AuthError, type CloudflareClient, type CloudflareClientOptions, type ResolveTokenInput, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createCloudflareClient };
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { AuthError, ProviderApiError, createResolveToken } from "@theholocron/cli";
|
|
1
|
+
import { AuthError, ProviderApiError, connectionProbe, createResolveToken } from "@theholocron/cli";
|
|
2
2
|
import { createCloudflareClient } from "@theholocron/cloudflare-client";
|
|
3
|
-
|
|
3
|
+
import { errorMessage } from "@theholocron/misc-utils";
|
|
4
|
+
// src/auth.ts
|
|
4
5
|
const resolveToken = createResolveToken({
|
|
5
6
|
envName: "HOLOCRON_CLOUDFLARE_TOKEN",
|
|
6
7
|
vendorEnvName: "CLOUDFLARE_API_TOKEN",
|
|
7
8
|
keyringService: "cloudflare",
|
|
8
9
|
errorMessage: "no Cloudflare API token found. Pass --token <TOKEN>, set HOLOCRON_CLOUDFLARE_TOKEN / CLOUDFLARE_API_TOKEN, or run: holocron auth set cloudflare <TOKEN>"
|
|
9
10
|
});
|
|
10
|
-
|
|
11
|
-
//#region src/capabilities/deployment.ts
|
|
11
|
+
// src/capabilities/deployment.ts
|
|
12
12
|
var CloudflareDeployment = class {
|
|
13
13
|
client;
|
|
14
14
|
accountId;
|
|
@@ -74,8 +74,9 @@ var CloudflareDeployment = class {
|
|
|
74
74
|
return deploymentIds.length;
|
|
75
75
|
}
|
|
76
76
|
async ensureCustomDomain(projectId, hostname) {
|
|
77
|
-
if ((await this.client().pages.listDomains(this.accountId, projectId)).some((d) => d.name === hostname)) return;
|
|
77
|
+
if ((await this.client().pages.listDomains(this.accountId, projectId)).some((d) => d.name === hostname)) return null;
|
|
78
78
|
await this.client().pages.addDomain(this.accountId, projectId, hostname);
|
|
79
|
+
return null;
|
|
79
80
|
}
|
|
80
81
|
async getProjectByName(name) {
|
|
81
82
|
try {
|
|
@@ -113,8 +114,7 @@ function normalizeStatus(status) {
|
|
|
113
114
|
default: return "error";
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
|
-
|
|
117
|
-
//#region src/capabilities/dns.ts
|
|
117
|
+
// src/capabilities/dns.ts
|
|
118
118
|
var CloudflareDns = class {
|
|
119
119
|
client;
|
|
120
120
|
key = "dns";
|
|
@@ -153,6 +153,13 @@ var CloudflareDns = class {
|
|
|
153
153
|
const zoneId = await this.resolveZone(domain);
|
|
154
154
|
await this.client().dns.delete(zoneId, id);
|
|
155
155
|
}
|
|
156
|
+
/** `holocron doctor` has no specific domain to check — lists every zone the token can see instead. */
|
|
157
|
+
async whoami() {
|
|
158
|
+
return {
|
|
159
|
+
ok: true,
|
|
160
|
+
zones: (await this.client().zones.list()).length
|
|
161
|
+
};
|
|
162
|
+
}
|
|
156
163
|
/**
|
|
157
164
|
* Walk from full domain up to apex to find the Cloudflare zone.
|
|
158
165
|
* E.g. "api.staging.example.com" tries:
|
|
@@ -184,8 +191,7 @@ function mapRecord(raw) {
|
|
|
184
191
|
ttl: raw.ttl
|
|
185
192
|
};
|
|
186
193
|
}
|
|
187
|
-
|
|
188
|
-
//#region src/capabilities/workers.ts
|
|
194
|
+
// src/capabilities/workers.ts
|
|
189
195
|
var CloudflareWorkers = class {
|
|
190
196
|
client;
|
|
191
197
|
accountId;
|
|
@@ -202,12 +208,25 @@ var CloudflareWorkers = class {
|
|
|
202
208
|
await this.client().workers.putScript(this.accountId, scriptName, script);
|
|
203
209
|
await this.upsertRoute(`${hostname}/*`, scriptName);
|
|
204
210
|
}
|
|
211
|
+
/** `holocron doctor` has no specific script to check — lists every script the token can see instead. */
|
|
212
|
+
async whoami() {
|
|
213
|
+
return {
|
|
214
|
+
ok: true,
|
|
215
|
+
scripts: (await this.client().workers.listScripts(this.accountId)).length
|
|
216
|
+
};
|
|
217
|
+
}
|
|
205
218
|
async deployScript(name, config) {
|
|
206
219
|
await this.client().workers.putScript(this.accountId, name, config.code);
|
|
207
220
|
for (const [secretName, value] of Object.entries(config.secrets ?? {})) await this.client().workers.putSecret(this.accountId, name, secretName, value);
|
|
208
221
|
for (const pattern of config.routes ?? []) await this.upsertRoute(pattern, name);
|
|
209
222
|
return { scriptName: name };
|
|
210
223
|
}
|
|
224
|
+
async setSecret(script, name, value) {
|
|
225
|
+
await this.client().workers.putSecret(this.accountId, script, name, value);
|
|
226
|
+
}
|
|
227
|
+
async secretNames(script) {
|
|
228
|
+
return (await this.client().workers.listSecrets(this.accountId, script)).map((secret) => secret.name);
|
|
229
|
+
}
|
|
211
230
|
/** Idempotent create-or-update for one route pattern — shared by both public methods. */
|
|
212
231
|
async upsertRoute(pattern, scriptName) {
|
|
213
232
|
const hostname = pattern.split("/")[0];
|
|
@@ -250,8 +269,7 @@ function generateProxyScript(config) {
|
|
|
250
269
|
`};`
|
|
251
270
|
].join("\n");
|
|
252
271
|
}
|
|
253
|
-
|
|
254
|
-
//#region src/verify-token.ts
|
|
272
|
+
// src/verify-token.ts
|
|
255
273
|
async function verifyToken(token, opts = {}) {
|
|
256
274
|
const client = createCloudflareClient({
|
|
257
275
|
token,
|
|
@@ -266,19 +284,23 @@ async function verifyToken(token, opts = {}) {
|
|
|
266
284
|
};
|
|
267
285
|
} catch {}
|
|
268
286
|
try {
|
|
287
|
+
const names = (await client.zones.list()).map((z) => z.name);
|
|
288
|
+
if (names.length === 0) return {
|
|
289
|
+
ok: true,
|
|
290
|
+
subject: "no zones visible"
|
|
291
|
+
};
|
|
269
292
|
return {
|
|
270
293
|
ok: true,
|
|
271
|
-
subject: `
|
|
294
|
+
subject: `zones: ${names.length <= 5 ? names.join(", ") : `${names.slice(0, 5).join(", ")} (+${names.length - 5} more)`}`
|
|
272
295
|
};
|
|
273
296
|
} catch (err) {
|
|
274
297
|
return {
|
|
275
298
|
ok: false,
|
|
276
|
-
message:
|
|
299
|
+
message: errorMessage(err)
|
|
277
300
|
};
|
|
278
301
|
}
|
|
279
302
|
}
|
|
280
|
-
|
|
281
|
-
//#region src/index.ts
|
|
303
|
+
// src/index.ts
|
|
282
304
|
function createContext(options = {}) {
|
|
283
305
|
const accountId = options.accountId ?? process.env.CLOUDFLARE_ACCOUNT_ID;
|
|
284
306
|
const opts = {
|
|
@@ -313,6 +335,16 @@ function createPlugin(options = {}) {
|
|
|
313
335
|
const ctx = createContext(options);
|
|
314
336
|
return {
|
|
315
337
|
name: "@theholocron/holocron-plugin-cloudflare",
|
|
338
|
+
probes: { connection: connectionProbe({
|
|
339
|
+
provider: "Cloudflare",
|
|
340
|
+
url: options.baseUrl ?? "https://api.cloudflare.com",
|
|
341
|
+
fetch: options.fetch,
|
|
342
|
+
token: () => resolveToken(options),
|
|
343
|
+
verify: (token) => verifyToken(token, {
|
|
344
|
+
baseUrl: options.baseUrl,
|
|
345
|
+
fetch: options.fetch
|
|
346
|
+
})
|
|
347
|
+
}) },
|
|
316
348
|
capabilities: {
|
|
317
349
|
dns: () => dns(ctx),
|
|
318
350
|
...ctx.options.accountId ? {
|
|
@@ -323,5 +355,4 @@ function createPlugin(options = {}) {
|
|
|
323
355
|
};
|
|
324
356
|
}
|
|
325
357
|
const AUTH_HINT = "create an API token at https://dash.cloudflare.com/profile/api-tokens with Zone:Read, DNS:Edit, Cloudflare Pages:Edit, Workers Scripts:Edit (account-level), and Workers Routes:Edit (zone-level) permissions, then run: holocron auth set cloudflare <TOKEN>";
|
|
326
|
-
//#endregion
|
|
327
358
|
export { AUTH_HINT, AuthError, CloudflareDeployment, CloudflareDns, CloudflareWorkers, createCloudflareClient, createContext, createPlugin, deployment, dns, resolveToken, verifyToken, workersCapability };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/holocron-plugin-cloudflare",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.250",
|
|
4
4
|
"description": "Holocron plugin for Cloudflare. Implements the dns capability against Cloudflare's REST API — zone resolution, DNS record management.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"holocron",
|
|
9
9
|
"plugin"
|
|
10
10
|
],
|
|
11
|
-
"homepage": "https://github.com/theholocron/holocron/tree/main/
|
|
11
|
+
"homepage": "https://github.com/theholocron/holocron/tree/main/plugins/holocron-plugin-cloudflare#readme",
|
|
12
12
|
"bugs": "https://github.com/theholocron/holocron/issues",
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "git+https://github.com/theholocron/holocron.git",
|
|
16
|
-
"directory": "
|
|
16
|
+
"directory": "plugins/holocron-plugin-cloudflare"
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"author": "Newton Koumantzelis",
|
|
@@ -30,28 +30,30 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@theholocron/cloudflare-client": "^1.
|
|
34
|
-
"@theholocron/eslint-config": "^8.
|
|
35
|
-
"@theholocron/http-client": "^1.
|
|
36
|
-
"@theholocron/
|
|
37
|
-
"@theholocron/
|
|
38
|
-
"@theholocron/
|
|
33
|
+
"@theholocron/cloudflare-client": "^1.53.1",
|
|
34
|
+
"@theholocron/eslint-config": "^8.8.2",
|
|
35
|
+
"@theholocron/http-client": "^1.57.0",
|
|
36
|
+
"@theholocron/misc-utils": "^1.16.0",
|
|
37
|
+
"@theholocron/tsconfig": "^8.8.2",
|
|
38
|
+
"@theholocron/tsdown-config": "^8.8.2",
|
|
39
|
+
"@theholocron/vitest-config": "^8.8.2",
|
|
39
40
|
"@types/node": "^26",
|
|
40
|
-
"@vitest/coverage-v8": "^
|
|
41
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
41
42
|
"@vitest/eslint-plugin": "^1.6.27",
|
|
42
43
|
"chalk": "^6.0.0",
|
|
43
44
|
"eslint": "^10.8.1",
|
|
44
45
|
"eslint-plugin-n": "^18.3.0",
|
|
45
46
|
"globals": "^17.11.0",
|
|
46
|
-
"tsdown": "^0.
|
|
47
|
-
"tsx": "4.23.
|
|
47
|
+
"tsdown": "^0.23.3",
|
|
48
|
+
"tsx": "4.23.15",
|
|
48
49
|
"typescript": "^5.9.3",
|
|
49
|
-
"vitest": "^
|
|
50
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
50
|
+
"vitest": "^5.0.5",
|
|
51
|
+
"@theholocron/cli": "5.0.0-alpha.250"
|
|
51
52
|
},
|
|
52
53
|
"peerDependencies": {
|
|
53
|
-
"@theholocron/cloudflare-client": "^1.
|
|
54
|
-
"@theholocron/
|
|
54
|
+
"@theholocron/cloudflare-client": "^1.53.1",
|
|
55
|
+
"@theholocron/misc-utils": "^1.16.0",
|
|
56
|
+
"@theholocron/cli": "5.0.0-alpha.250"
|
|
55
57
|
},
|
|
56
58
|
"peerDependenciesMeta": {
|
|
57
59
|
"@theholocron/cloudflare-client": {}
|