@theholocron/holocron-plugin-cloudflare 5.0.0-alpha.565 → 5.0.0-alpha.567
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/dist/index.d.mts +2 -1
- package/dist/index.mjs +33 -0
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthError, DeployScriptConfig, DeployScriptResult, Deployment, DeploymentProject, DeploymentProjectSettings, DeploymentRecord, DeploymentTarget, DeploymentTrigger, Dns, DnsRecord, DnsRecordRequest, EnsureRelaySourceInput, EnsureRelaySourceResult, EnsuredTunnel, InspectRelaySourceInput, MintTokenInput, PluginToken, RelaySourceState, ResolveTokenInput, TunnelRoute, Tunnels, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess, WikiProxyConfig, WorkerDeploymentState, WorkerScriptState, Workers } from "@theholocron/cli";
|
|
1
|
+
import { AuthError, DeployScriptConfig, DeployScriptResult, Deployment, DeploymentProject, DeploymentProjectSettings, DeploymentRecord, DeploymentTarget, DeploymentTrigger, Dns, DnsRecord, DnsRecordRequest, EnsureRelaySourceInput, EnsureRelaySourceResult, EnsuredTunnel, InspectRelaySourceInput, MintTokenInput, PluginToken, RelaySourceState, ResolveTokenInput, RevokeTokenInput, TunnelRoute, Tunnels, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess, WikiProxyConfig, WorkerDeploymentState, WorkerScriptState, Workers } from "@theholocron/cli";
|
|
2
2
|
import { CloudflareClient, CloudflareClient as CloudflareClient$1, CloudflareClientOptions, createCloudflareClient } from "@theholocron/cloudflare-client";
|
|
3
3
|
/** Resolves the Cloudflare API token from `--token`, `HOLOCRON_CLOUDFLARE_TOKEN`, `CLOUDFLARE_API_TOKEN` or the keyring, and throws an `AuthError` when none is set. */
|
|
4
4
|
export declare const resolveToken: import("@theholocron/cli").TokenResolver;
|
|
@@ -179,6 +179,7 @@ export declare function createPlugin(options?: CloudflarePluginOptions): {
|
|
|
179
179
|
};
|
|
180
180
|
whoami: import("@theholocron/cli").ProviderAction;
|
|
181
181
|
mintToken: (input: MintTokenInput) => Promise<import("@theholocron/cli").MintTokenResult>;
|
|
182
|
+
revokeToken: (input: RevokeTokenInput) => Promise<import("@theholocron/cli").RevokeTokenResult>;
|
|
182
183
|
capabilities: {
|
|
183
184
|
deployment?: (() => Deployment) | undefined;
|
|
184
185
|
workers?: (() => Workers) | undefined;
|
package/dist/index.mjs
CHANGED
|
@@ -893,6 +893,38 @@ function tokenProbe(ctx) {
|
|
|
893
893
|
}
|
|
894
894
|
};
|
|
895
895
|
}
|
|
896
|
+
// src/revoke-token/revoke-token.ts
|
|
897
|
+
const AFTER = "anything still using the token stops working; make sure its replacement is in place (`holocron sync secrets --env <layer>`)";
|
|
898
|
+
/**
|
|
899
|
+
* Deletes a Cloudflare API token by its id through `DELETE /user/tokens/{token_id}` (needs `API Tokens: Write`). It
|
|
900
|
+
* first asks `GET /user/tokens/verify` which token the call is made with and refuses that id, because deleting it would
|
|
901
|
+
* lock the run out; an account or zone token is refused by that endpoint, so there the plugin cannot tell and relies on
|
|
902
|
+
* Cloudflare. A 404 means the token is already gone (`revoked: false`); any other failure is thrown. No value is read or
|
|
903
|
+
* returned.
|
|
904
|
+
*/
|
|
905
|
+
async function revokeCloudflareToken(ctx, input) {
|
|
906
|
+
const client = ctx.client();
|
|
907
|
+
let ownId;
|
|
908
|
+
try {
|
|
909
|
+
ownId = (await client.tokens.verify()).id;
|
|
910
|
+
} catch {
|
|
911
|
+
ownId = void 0;
|
|
912
|
+
}
|
|
913
|
+
if (ownId === input.id) throw new Error(`\`${input.id}\` is the token this call is made with; deleting it would lock the run out. Run it with another token (--token cloudflare=<value>)`);
|
|
914
|
+
try {
|
|
915
|
+
await client.tokens.delete(input.id);
|
|
916
|
+
} catch (err) {
|
|
917
|
+
if (err.status === 404) return {
|
|
918
|
+
revoked: false,
|
|
919
|
+
notes: ["Cloudflare has no token with that id, so there is nothing to delete"]
|
|
920
|
+
};
|
|
921
|
+
throw err;
|
|
922
|
+
}
|
|
923
|
+
return {
|
|
924
|
+
revoked: true,
|
|
925
|
+
notes: [`deleted token ${input.id}; ${AFTER}`, ...ownId === void 0 ? ["could not tell whether this was the token in use (an account or zone token cannot ask Cloudflare)"] : []]
|
|
926
|
+
};
|
|
927
|
+
}
|
|
896
928
|
// src/verify-token.ts
|
|
897
929
|
/** Checks a Cloudflare API token, first by the token-verify endpoint and otherwise by listing zones; resolves to a description of what it found, or the failure message. */
|
|
898
930
|
async function verifyToken(token, opts = {}) {
|
|
@@ -1009,6 +1041,7 @@ function createPlugin(options = {}) {
|
|
|
1009
1041
|
}
|
|
1010
1042
|
}),
|
|
1011
1043
|
mintToken: (input) => mintCloudflareToken(ctx, input),
|
|
1044
|
+
revokeToken: (input) => revokeCloudflareToken(ctx, input),
|
|
1012
1045
|
capabilities: {
|
|
1013
1046
|
dns: () => dns(ctx),
|
|
1014
1047
|
...ctx.options.accountId ? {
|
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.567",
|
|
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",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"tsx": "4.23.15",
|
|
45
45
|
"typescript": "^6.0.3",
|
|
46
46
|
"vitest": "^5.1.1",
|
|
47
|
-
"@theholocron/
|
|
48
|
-
"@theholocron/
|
|
47
|
+
"@theholocron/cli": "5.0.0-alpha.567",
|
|
48
|
+
"@theholocron/cloudflare-client": "^1.58.0-alpha.65",
|
|
49
49
|
"@theholocron/eslint-config": "^8.9.0-alpha.24",
|
|
50
|
-
"@theholocron/http-client": "^1.58.0-alpha.
|
|
51
|
-
"@theholocron/kyber": "5.0.0-alpha.
|
|
50
|
+
"@theholocron/http-client": "^1.58.0-alpha.65",
|
|
51
|
+
"@theholocron/kyber": "5.0.0-alpha.567",
|
|
52
52
|
"@theholocron/misc-utils": "^1.17.0-alpha.8",
|
|
53
53
|
"@theholocron/tsconfig": "^8.9.0-alpha.24",
|
|
54
54
|
"@theholocron/tsdown-config": "^8.9.0-alpha.24",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@theholocron/cloudflare-client": "^1.53.1",
|
|
59
59
|
"@theholocron/misc-utils": "^1.16.0",
|
|
60
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
60
|
+
"@theholocron/cli": "5.0.0-alpha.567"
|
|
61
61
|
},
|
|
62
62
|
"peerDependenciesMeta": {
|
|
63
63
|
"@theholocron/cloudflare-client": {}
|