alchemy 2.0.0-beta.34 → 2.0.0-beta.35
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/bin/cli.js +8 -7
- package/bin/exec.js +226 -52
- package/bin/exec.js.map +1 -1
- package/lib/AWS/AuthProvider.d.ts +7 -6
- package/lib/AWS/AuthProvider.d.ts.map +1 -1
- package/lib/AWS/AuthProvider.js +143 -134
- package/lib/AWS/AuthProvider.js.map +1 -1
- package/lib/AWS/Bootstrap.d.ts +2 -2
- package/lib/AWS/Bootstrap.d.ts.map +1 -1
- package/lib/AWS/EC2/hosted.d.ts +1 -1
- package/lib/AWS/Environment.d.ts +25 -3
- package/lib/AWS/Environment.d.ts.map +1 -1
- package/lib/AWS/Environment.js +47 -3
- package/lib/AWS/Environment.js.map +1 -1
- package/lib/AWS/IAM/OpenIDConnectProvider.d.ts +14 -6
- package/lib/AWS/IAM/OpenIDConnectProvider.d.ts.map +1 -1
- package/lib/AWS/IAM/OpenIDConnectProvider.js +6 -3
- package/lib/AWS/IAM/OpenIDConnectProvider.js.map +1 -1
- package/lib/AWS/IAM/Policy.d.ts +1 -1
- package/lib/AWS/IAM/Policy.d.ts.map +1 -1
- package/lib/AWS/IAM/Policy.js.map +1 -1
- package/lib/AWS/Lambda/BucketEventSource.d.ts +1 -1
- package/lib/AWS/Lambda/BucketEventSource.d.ts.map +1 -1
- package/lib/AWS/Lambda/EventBridgeEventSource.d.ts +1 -1
- package/lib/AWS/Lambda/EventBridgeEventSource.d.ts.map +1 -1
- package/lib/AWS/Lambda/QueueEventSource.d.ts +1 -1
- package/lib/AWS/Lambda/QueueEventSource.d.ts.map +1 -1
- package/lib/AWS/Lambda/StreamEventSource.d.ts +1 -1
- package/lib/AWS/Lambda/StreamEventSource.d.ts.map +1 -1
- package/lib/AWS/Lambda/TableEventSource.d.ts +1 -1
- package/lib/AWS/Lambda/TableEventSource.d.ts.map +1 -1
- package/lib/AWS/Lambda/TopicEventSource.d.ts +1 -1
- package/lib/AWS/Lambda/TopicEventSource.d.ts.map +1 -1
- package/lib/AWS/Providers.d.ts +1 -1
- package/lib/AWS/Providers.d.ts.map +1 -1
- package/lib/AWS/Providers.js +2 -1
- package/lib/AWS/Providers.js.map +1 -1
- package/lib/Auth/Credentials.d.ts +21 -6
- package/lib/Auth/Credentials.d.ts.map +1 -1
- package/lib/Auth/Credentials.js +30 -31
- package/lib/Auth/Credentials.js.map +1 -1
- package/lib/Auth/Profile.d.ts +31 -34
- package/lib/Auth/Profile.d.ts.map +1 -1
- package/lib/Auth/Profile.js +46 -31
- package/lib/Auth/Profile.js.map +1 -1
- package/lib/Axiom/AuthProvider.d.ts +2 -1
- package/lib/Axiom/AuthProvider.d.ts.map +1 -1
- package/lib/Axiom/AuthProvider.js +149 -143
- package/lib/Axiom/AuthProvider.js.map +1 -1
- package/lib/Axiom/Credentials.d.ts +2 -1
- package/lib/Axiom/Credentials.d.ts.map +1 -1
- package/lib/Axiom/Credentials.js +4 -4
- package/lib/Axiom/Credentials.js.map +1 -1
- package/lib/Axiom/Providers.d.ts +1 -1
- package/lib/Axiom/Providers.d.ts.map +1 -1
- package/lib/Axiom/Providers.js +3 -1
- package/lib/Axiom/Providers.js.map +1 -1
- package/lib/Cli/LoggingCli.d.ts.map +1 -1
- package/lib/Cli/LoggingCli.js +105 -7
- package/lib/Cli/LoggingCli.js.map +1 -1
- package/lib/Cli/checkVersion.d.ts +13 -0
- package/lib/Cli/checkVersion.d.ts.map +1 -0
- package/lib/Cli/checkVersion.js +47 -0
- package/lib/Cli/checkVersion.js.map +1 -0
- package/lib/Cli/commands/_shared.d.ts +2 -2
- package/lib/Cli/commands/_shared.d.ts.map +1 -1
- package/lib/Cli/commands/_shared.js +3 -3
- package/lib/Cli/commands/_shared.js.map +1 -1
- package/lib/Cli/commands/aws.d.ts +6 -0
- package/lib/Cli/commands/aws.d.ts.map +1 -0
- package/lib/Cli/commands/aws.js +63 -0
- package/lib/Cli/commands/aws.js.map +1 -0
- package/lib/Cli/commands/cloudflare.d.ts +17 -0
- package/lib/Cli/commands/cloudflare.d.ts.map +1 -0
- package/lib/Cli/commands/cloudflare.js +111 -0
- package/lib/Cli/commands/cloudflare.js.map +1 -0
- package/lib/Cli/commands/deploy.d.ts +6 -5
- package/lib/Cli/commands/deploy.d.ts.map +1 -1
- package/lib/Cli/commands/deploy.js +10 -10
- package/lib/Cli/commands/deploy.js.map +1 -1
- package/lib/Cli/commands/dev.d.ts.map +1 -1
- package/lib/Cli/commands/dev.js +16 -16
- package/lib/Cli/commands/dev.js.map +1 -1
- package/lib/Cli/commands/login.d.ts +2 -1
- package/lib/Cli/commands/login.d.ts.map +1 -1
- package/lib/Cli/commands/login.js +9 -8
- package/lib/Cli/commands/login.js.map +1 -1
- package/lib/Cli/commands/logs.d.ts +1 -1
- package/lib/Cli/commands/logs.d.ts.map +1 -1
- package/lib/Cli/commands/logs.js +7 -7
- package/lib/Cli/commands/logs.js.map +1 -1
- package/lib/Cli/commands/profile.d.ts +3 -1
- package/lib/Cli/commands/profile.d.ts.map +1 -1
- package/lib/Cli/commands/profile.js +14 -11
- package/lib/Cli/commands/profile.js.map +1 -1
- package/lib/Cli/commands/state.d.ts +1 -1
- package/lib/Cli/commands/state.d.ts.map +1 -1
- package/lib/Cli/commands/state.js +8 -8
- package/lib/Cli/commands/state.js.map +1 -1
- package/lib/Cli/commands/tail.d.ts +1 -1
- package/lib/Cli/commands/tail.d.ts.map +1 -1
- package/lib/Cli/commands/tail.js +7 -7
- package/lib/Cli/commands/tail.js.map +1 -1
- package/lib/Cli/exec.d.ts.map +1 -1
- package/lib/Cli/exec.js +5 -3
- package/lib/Cli/exec.js.map +1 -1
- package/lib/Cli/main.d.ts.map +1 -1
- package/lib/Cli/main.js +17 -5
- package/lib/Cli/main.js.map +1 -1
- package/lib/Cli/selectCli.d.ts +12 -0
- package/lib/Cli/selectCli.d.ts.map +1 -0
- package/lib/Cli/selectCli.js +32 -0
- package/lib/Cli/selectCli.js.map +1 -0
- package/lib/Cloudflare/Auth/AuthProvider.d.ts +2 -1
- package/lib/Cloudflare/Auth/AuthProvider.d.ts.map +1 -1
- package/lib/Cloudflare/Auth/AuthProvider.js +235 -214
- package/lib/Cloudflare/Auth/AuthProvider.js.map +1 -1
- package/lib/Cloudflare/CloudflareEnvironment.d.ts +2 -1
- package/lib/Cloudflare/CloudflareEnvironment.d.ts.map +1 -1
- package/lib/Cloudflare/CloudflareEnvironment.js +3 -2
- package/lib/Cloudflare/CloudflareEnvironment.js.map +1 -1
- package/lib/Cloudflare/Credentials.d.ts +2 -1
- package/lib/Cloudflare/Credentials.d.ts.map +1 -1
- package/lib/Cloudflare/Credentials.js +4 -4
- package/lib/Cloudflare/Credentials.js.map +1 -1
- package/lib/Cloudflare/D1/D1Clone.d.ts +2 -1
- package/lib/Cloudflare/D1/D1Clone.d.ts.map +1 -1
- package/lib/Cloudflare/D1/D1Database.d.ts +2 -1
- package/lib/Cloudflare/D1/D1Database.d.ts.map +1 -1
- package/lib/Cloudflare/D1/D1Import.d.ts +3 -1
- package/lib/Cloudflare/D1/D1Import.d.ts.map +1 -1
- package/lib/Cloudflare/Local/Sidecar.d.ts +11 -4
- package/lib/Cloudflare/Local/Sidecar.d.ts.map +1 -1
- package/lib/Cloudflare/Local/Sidecar.js +8 -6
- package/lib/Cloudflare/Local/Sidecar.js.map +1 -1
- package/lib/Cloudflare/Local/SidecarHandlers.d.ts.map +1 -1
- package/lib/Cloudflare/Local/SidecarHandlers.js +1 -5
- package/lib/Cloudflare/Local/SidecarHandlers.js.map +1 -1
- package/lib/Cloudflare/Local/SidecarServer.js +5 -2
- package/lib/Cloudflare/Local/SidecarServer.js.map +1 -1
- package/lib/Cloudflare/Logs.d.ts +5 -0
- package/lib/Cloudflare/Logs.d.ts.map +1 -1
- package/lib/Cloudflare/Logs.js +70 -1
- package/lib/Cloudflare/Logs.js.map +1 -1
- package/lib/Cloudflare/Providers.d.ts +1 -1
- package/lib/Cloudflare/Providers.d.ts.map +1 -1
- package/lib/Cloudflare/Providers.js +4 -1
- package/lib/Cloudflare/Providers.js.map +1 -1
- package/lib/Cloudflare/Queue/Queue.d.ts +1 -1
- package/lib/Cloudflare/Queue/Queue.js +1 -1
- package/lib/Cloudflare/Queue/QueueConsumer.d.ts +6 -2
- package/lib/Cloudflare/Queue/QueueConsumer.d.ts.map +1 -1
- package/lib/Cloudflare/Queue/QueueConsumer.js +194 -53
- package/lib/Cloudflare/Queue/QueueConsumer.js.map +1 -1
- package/lib/Cloudflare/Queue/QueueEventSource.d.ts +106 -0
- package/lib/Cloudflare/Queue/QueueEventSource.d.ts.map +1 -0
- package/lib/Cloudflare/Queue/QueueEventSource.js +145 -0
- package/lib/Cloudflare/Queue/QueueEventSource.js.map +1 -0
- package/lib/Cloudflare/Queue/index.d.ts +1 -0
- package/lib/Cloudflare/Queue/index.d.ts.map +1 -1
- package/lib/Cloudflare/Queue/index.js +1 -0
- package/lib/Cloudflare/Queue/index.js.map +1 -1
- package/lib/Cloudflare/R2/R2Bucket.d.ts +94 -0
- package/lib/Cloudflare/R2/R2Bucket.d.ts.map +1 -1
- package/lib/Cloudflare/R2/R2Bucket.js +186 -2
- package/lib/Cloudflare/R2/R2Bucket.js.map +1 -1
- package/lib/Cloudflare/StateStore/State.d.ts +4 -3
- package/lib/Cloudflare/StateStore/State.d.ts.map +1 -1
- package/lib/Cloudflare/StateStore/State.js +16 -8
- package/lib/Cloudflare/StateStore/State.js.map +1 -1
- package/lib/Cloudflare/VpcService/VpcServiceRef.d.ts +1 -1
- package/lib/Cloudflare/VpcService/VpcServiceRef.d.ts.map +1 -1
- package/lib/Cloudflare/Website/StaticSite.d.ts.map +1 -1
- package/lib/Cloudflare/Website/StaticSite.js +10 -1
- package/lib/Cloudflare/Website/StaticSite.js.map +1 -1
- package/lib/Cloudflare/Workers/Assets.d.ts +1 -1
- package/lib/Cloudflare/Workers/Assets.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/LocalWorkerProvider.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/LocalWorkerProvider.js +11 -1
- package/lib/Cloudflare/Workers/LocalWorkerProvider.js.map +1 -1
- package/lib/Cloudflare/Workers/Worker.d.ts +9 -7
- package/lib/Cloudflare/Workers/Worker.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/Worker.js +62 -142
- package/lib/Cloudflare/Workers/Worker.js.map +1 -1
- package/lib/Cloudflare/Workers/WorkerBundle.d.ts +2 -0
- package/lib/Cloudflare/Workers/WorkerBundle.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/WorkerBundle.js +21 -7
- package/lib/Cloudflare/Workers/WorkerBundle.js.map +1 -1
- package/lib/Cloudflare/Zone.d.ts +14 -0
- package/lib/Cloudflare/Zone.d.ts.map +1 -0
- package/lib/Cloudflare/Zone.js +44 -0
- package/lib/Cloudflare/Zone.js.map +1 -0
- package/lib/Drizzle/Schema.d.ts.map +1 -1
- package/lib/Drizzle/Schema.js +20 -5
- package/lib/Drizzle/Schema.js.map +1 -1
- package/lib/GitHub/AuthProvider.d.ts +3 -1
- package/lib/GitHub/AuthProvider.d.ts.map +1 -1
- package/lib/GitHub/AuthProvider.js +114 -108
- package/lib/GitHub/AuthProvider.js.map +1 -1
- package/lib/GitHub/Credentials.d.ts +2 -1
- package/lib/GitHub/Credentials.d.ts.map +1 -1
- package/lib/GitHub/Credentials.js +4 -4
- package/lib/GitHub/Credentials.js.map +1 -1
- package/lib/GitHub/Providers.d.ts +1 -1
- package/lib/GitHub/Providers.d.ts.map +1 -1
- package/lib/GitHub/Providers.js +3 -1
- package/lib/GitHub/Providers.js.map +1 -1
- package/lib/GitHub/Secrets.d.ts.map +1 -1
- package/lib/GitHub/Secrets.js +14 -1
- package/lib/GitHub/Secrets.js.map +1 -1
- package/lib/GitHub/Variables.d.ts +40 -0
- package/lib/GitHub/Variables.d.ts.map +1 -0
- package/lib/GitHub/Variables.js +28 -0
- package/lib/GitHub/Variables.js.map +1 -0
- package/lib/GitHub/index.d.ts +1 -0
- package/lib/GitHub/index.d.ts.map +1 -1
- package/lib/GitHub/index.js +1 -0
- package/lib/GitHub/index.js.map +1 -1
- package/lib/Neon/AuthProvider.d.ts +3 -1
- package/lib/Neon/AuthProvider.d.ts.map +1 -1
- package/lib/Neon/AuthProvider.js +87 -80
- package/lib/Neon/AuthProvider.js.map +1 -1
- package/lib/Neon/Credentials.d.ts +2 -1
- package/lib/Neon/Credentials.d.ts.map +1 -1
- package/lib/Neon/Credentials.js +4 -4
- package/lib/Neon/Credentials.js.map +1 -1
- package/lib/Neon/NeonEnvironment.d.ts +2 -1
- package/lib/Neon/NeonEnvironment.d.ts.map +1 -1
- package/lib/Neon/NeonEnvironment.js +3 -2
- package/lib/Neon/NeonEnvironment.js.map +1 -1
- package/lib/Neon/Project.d.ts +16 -0
- package/lib/Neon/Project.d.ts.map +1 -1
- package/lib/Neon/Project.js +25 -0
- package/lib/Neon/Project.js.map +1 -1
- package/lib/Neon/Providers.d.ts +1 -1
- package/lib/Neon/Providers.d.ts.map +1 -1
- package/lib/Neon/Providers.js +3 -1
- package/lib/Neon/Providers.js.map +1 -1
- package/lib/Neon/api.d.ts +1 -0
- package/lib/Neon/api.d.ts.map +1 -1
- package/lib/Neon/api.js +1 -0
- package/lib/Neon/api.js.map +1 -1
- package/lib/Sidecar/RpcClient.d.ts.map +1 -1
- package/lib/Sidecar/RpcClient.js +8 -5
- package/lib/Sidecar/RpcClient.js.map +1 -1
- package/lib/Sidecar/RpcPaths.d.ts +5 -0
- package/lib/Sidecar/RpcPaths.d.ts.map +1 -1
- package/lib/Sidecar/RpcPaths.js +10 -1
- package/lib/Sidecar/RpcPaths.js.map +1 -1
- package/lib/Sidecar/RpcServer.d.ts +24 -4
- package/lib/Sidecar/RpcServer.d.ts.map +1 -1
- package/lib/Sidecar/RpcServer.js +70 -15
- package/lib/Sidecar/RpcServer.js.map +1 -1
- package/lib/Sidecar/RpcServerBun.d.ts +4 -0
- package/lib/Sidecar/RpcServerBun.d.ts.map +1 -0
- package/lib/Sidecar/RpcServerBun.js +28 -0
- package/lib/Sidecar/RpcServerBun.js.map +1 -0
- package/lib/Sidecar/RpcServerNode.d.ts +4 -0
- package/lib/Sidecar/RpcServerNode.d.ts.map +1 -0
- package/lib/Sidecar/RpcServerNode.js +39 -0
- package/lib/Sidecar/RpcServerNode.js.map +1 -0
- package/lib/Sidecar/RpcServices.d.ts +6 -0
- package/lib/Sidecar/RpcServices.d.ts.map +1 -0
- package/lib/Sidecar/RpcServices.js +29 -0
- package/lib/Sidecar/RpcServices.js.map +1 -0
- package/lib/Stack.d.ts +5 -3
- package/lib/Stack.d.ts.map +1 -1
- package/lib/Stack.js +3 -1
- package/lib/Stack.js.map +1 -1
- package/lib/Test/Core.d.ts.map +1 -1
- package/lib/Test/Core.js +5 -4
- package/lib/Test/Core.js.map +1 -1
- package/lib/Util/PlatformServices.js +1 -1
- package/lib/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +15 -12
- package/src/AWS/AuthProvider.ts +269 -259
- package/src/AWS/Environment.ts +57 -3
- package/src/AWS/IAM/OpenIDConnectProvider.ts +19 -8
- package/src/AWS/IAM/Policy.ts +1 -1
- package/src/AWS/Providers.ts +2 -0
- package/src/Auth/Credentials.ts +82 -46
- package/src/Auth/Profile.ts +123 -69
- package/src/Axiom/AuthProvider.ts +263 -255
- package/src/Axiom/Credentials.ts +3 -4
- package/src/Axiom/Providers.ts +4 -0
- package/src/Cli/LoggingCli.ts +127 -11
- package/src/Cli/checkVersion.ts +57 -0
- package/src/Cli/commands/_shared.ts +4 -4
- package/src/Cli/commands/aws.ts +127 -0
- package/src/Cli/commands/cloudflare.ts +222 -0
- package/src/Cli/commands/deploy.ts +11 -10
- package/src/Cli/commands/dev.ts +28 -33
- package/src/Cli/commands/login.ts +9 -12
- package/src/Cli/commands/logs.ts +8 -8
- package/src/Cli/commands/profile.ts +14 -16
- package/src/Cli/commands/state.ts +8 -8
- package/src/Cli/commands/tail.ts +8 -8
- package/src/Cli/exec.ts +7 -3
- package/src/Cli/main.ts +20 -5
- package/src/Cli/selectCli.ts +33 -0
- package/src/Cloudflare/Auth/AuthProvider.ts +445 -430
- package/src/Cloudflare/CloudflareEnvironment.ts +3 -2
- package/src/Cloudflare/Credentials.ts +3 -4
- package/src/Cloudflare/Local/Sidecar.ts +13 -10
- package/src/Cloudflare/Local/SidecarHandlers.ts +8 -13
- package/src/Cloudflare/Local/SidecarServer.ts +6 -1
- package/src/Cloudflare/Logs.ts +115 -1
- package/src/Cloudflare/Providers.ts +6 -0
- package/src/Cloudflare/Queue/Queue.ts +1 -1
- package/src/Cloudflare/Queue/QueueConsumer.ts +262 -60
- package/src/Cloudflare/Queue/QueueEventSource.ts +234 -0
- package/src/Cloudflare/Queue/index.ts +1 -0
- package/src/Cloudflare/R2/R2Bucket.ts +337 -2
- package/src/Cloudflare/StateStore/State.ts +25 -16
- package/src/Cloudflare/Website/StaticSite.ts +11 -1
- package/src/Cloudflare/Workers/LocalWorkerProvider.ts +9 -1
- package/src/Cloudflare/Workers/Worker.ts +83 -203
- package/src/Cloudflare/Workers/WorkerBundle.ts +38 -12
- package/src/Cloudflare/Zone.ts +88 -0
- package/src/Drizzle/Schema.ts +21 -5
- package/src/GitHub/AuthProvider.ts +221 -217
- package/src/GitHub/Credentials.ts +3 -4
- package/src/GitHub/Providers.ts +4 -0
- package/src/GitHub/Secrets.ts +25 -1
- package/src/GitHub/Variables.ts +54 -0
- package/src/GitHub/index.ts +1 -0
- package/src/Neon/AuthProvider.ts +160 -154
- package/src/Neon/Credentials.ts +3 -4
- package/src/Neon/NeonEnvironment.ts +3 -2
- package/src/Neon/Project.ts +42 -0
- package/src/Neon/Providers.ts +4 -0
- package/src/Neon/api.ts +2 -0
- package/src/Sidecar/RpcClient.ts +8 -7
- package/src/Sidecar/RpcPaths.ts +11 -1
- package/src/Sidecar/RpcServer.ts +97 -24
- package/src/Sidecar/RpcServerBun.ts +41 -0
- package/src/Sidecar/RpcServerNode.ts +51 -0
- package/src/Sidecar/RpcServices.ts +48 -0
- package/src/Stack.ts +8 -0
- package/src/Test/Core.ts +10 -4
- package/src/Util/PlatformServices.ts +1 -1
- package/lib/Cli/commands/bootstrap.d.ts +0 -20
- package/lib/Cli/commands/bootstrap.d.ts.map +0 -1
- package/lib/Cli/commands/bootstrap.js +0 -107
- package/lib/Cli/commands/bootstrap.js.map +0 -1
- package/lib/Sidecar/RpcTransport.d.ts +0 -22
- package/lib/Sidecar/RpcTransport.d.ts.map +0 -1
- package/lib/Sidecar/RpcTransport.js +0 -81
- package/lib/Sidecar/RpcTransport.js.map +0 -1
- package/lib/Test/TestCli.d.ts +0 -19
- package/lib/Test/TestCli.d.ts.map +0 -1
- package/lib/Test/TestCli.js +0 -175
- package/lib/Test/TestCli.js.map +0 -1
- package/src/Cli/commands/bootstrap.ts +0 -216
- package/src/Sidecar/RpcTransport.ts +0 -85
- package/src/Test/TestCli.ts +0 -221
|
@@ -3,7 +3,6 @@ import * as CfCredentialsModule from "@distilled.cloud/cloudflare/Credentials";
|
|
|
3
3
|
import * as Console from "effect/Console";
|
|
4
4
|
import * as Duration from "effect/Duration";
|
|
5
5
|
import * as Effect from "effect/Effect";
|
|
6
|
-
import * as FileSystem from "effect/FileSystem";
|
|
7
6
|
import * as Layer from "effect/Layer";
|
|
8
7
|
import * as Match from "effect/Match";
|
|
9
8
|
import * as Redacted from "effect/Redacted";
|
|
@@ -14,12 +13,7 @@ import {
|
|
|
14
13
|
AuthProviderLayer,
|
|
15
14
|
type ConfigureContext,
|
|
16
15
|
} from "../../Auth/AuthProvider.ts";
|
|
17
|
-
import {
|
|
18
|
-
deleteCredentials,
|
|
19
|
-
displayRedacted,
|
|
20
|
-
readCredentials,
|
|
21
|
-
writeCredentials,
|
|
22
|
-
} from "../../Auth/Credentials.ts";
|
|
16
|
+
import { CredentialsStore, displayRedacted } from "../../Auth/Credentials.ts";
|
|
23
17
|
import {
|
|
24
18
|
getEnv,
|
|
25
19
|
getEnvRedacted,
|
|
@@ -85,390 +79,6 @@ export type CloudflareResolvedCredentials =
|
|
|
85
79
|
|
|
86
80
|
export const CLOUDFLARE_AUTH_PROVIDER_NAME = "Cloudflare";
|
|
87
81
|
|
|
88
|
-
/**
|
|
89
|
-
* Layer that registers the Cloudflare {@link AuthProvider} into the
|
|
90
|
-
* {@link AuthProviders} registry when built. Include this in the Cloudflare
|
|
91
|
-
* `providers()` layer so `alchemy login` can discover it.
|
|
92
|
-
*/
|
|
93
|
-
export const CloudflareAuth = AuthProviderLayer<
|
|
94
|
-
CloudflareAuthConfig,
|
|
95
|
-
CloudflareResolvedCredentials
|
|
96
|
-
>()(CLOUDFLARE_AUTH_PROVIDER_NAME, {
|
|
97
|
-
configure: (profileName, ctx) => configureCredentials(profileName, ctx),
|
|
98
|
-
logout: (profileName, config) => logout(profileName, config),
|
|
99
|
-
login: (profileName, config) => login(profileName, config),
|
|
100
|
-
prettyPrint: (profileName, config) => prettyPrint(profileName, config),
|
|
101
|
-
read: (profileName, config) => resolveCredentials(profileName, config),
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
const resolveCredentials = (
|
|
105
|
-
profileName: string,
|
|
106
|
-
config: CloudflareAuthConfig,
|
|
107
|
-
): Effect.Effect<
|
|
108
|
-
CloudflareResolvedCredentials,
|
|
109
|
-
AuthError,
|
|
110
|
-
FileSystem.FileSystem
|
|
111
|
-
> =>
|
|
112
|
-
Match.value(config).pipe(
|
|
113
|
-
Match.when(
|
|
114
|
-
{ method: "env" },
|
|
115
|
-
Effect.fnUntraced(function* () {
|
|
116
|
-
const accountId = yield* getEnvRequired("CLOUDFLARE_ACCOUNT_ID");
|
|
117
|
-
const apiToken = yield* getEnvRedacted("CLOUDFLARE_API_TOKEN");
|
|
118
|
-
if (apiToken) {
|
|
119
|
-
return {
|
|
120
|
-
type: "apiToken" as const,
|
|
121
|
-
apiToken,
|
|
122
|
-
accountId,
|
|
123
|
-
source: { type: "env" as const },
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
const apiKey = yield* getEnvRedacted("CLOUDFLARE_API_KEY");
|
|
127
|
-
const email = yield* getEnvRedacted("CLOUDFLARE_EMAIL");
|
|
128
|
-
if (apiKey && email) {
|
|
129
|
-
return {
|
|
130
|
-
type: "apiKey" as const,
|
|
131
|
-
apiKey,
|
|
132
|
-
email,
|
|
133
|
-
accountId,
|
|
134
|
-
source: { type: "env" as const },
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
return yield* new AuthError({
|
|
138
|
-
message:
|
|
139
|
-
"Cloudflare env credentials not found. Set CLOUDFLARE_API_TOKEN or CLOUDFLARE_API_KEY + CLOUDFLARE_EMAIL.",
|
|
140
|
-
});
|
|
141
|
-
}),
|
|
142
|
-
),
|
|
143
|
-
Match.when({ method: "stored" }, () =>
|
|
144
|
-
readCredentials<CloudflareStoredCredentials>(
|
|
145
|
-
profileName,
|
|
146
|
-
"cf-stored",
|
|
147
|
-
).pipe(
|
|
148
|
-
Effect.flatMap((creds) =>
|
|
149
|
-
creds == null
|
|
150
|
-
? Effect.fail(
|
|
151
|
-
new AuthError({
|
|
152
|
-
message:
|
|
153
|
-
"Cloudflare stored credentials not found. Run: alchemy-effect login --configure",
|
|
154
|
-
}),
|
|
155
|
-
)
|
|
156
|
-
: Effect.succeed(
|
|
157
|
-
Match.value(creds).pipe(
|
|
158
|
-
Match.when({ type: "apiToken" }, (c) => ({
|
|
159
|
-
type: "apiToken" as const,
|
|
160
|
-
apiToken: Redacted.make(c.apiToken),
|
|
161
|
-
accountId: c.accountId,
|
|
162
|
-
source: { type: "stored" as const },
|
|
163
|
-
})),
|
|
164
|
-
Match.when({ type: "apiKey" }, (c) => ({
|
|
165
|
-
type: "apiKey" as const,
|
|
166
|
-
apiKey: Redacted.make(c.apiKey),
|
|
167
|
-
email: Redacted.make(c.email),
|
|
168
|
-
accountId: c.accountId,
|
|
169
|
-
source: { type: "stored" as const },
|
|
170
|
-
})),
|
|
171
|
-
Match.exhaustive,
|
|
172
|
-
),
|
|
173
|
-
),
|
|
174
|
-
),
|
|
175
|
-
),
|
|
176
|
-
),
|
|
177
|
-
Match.when({ method: "oauth" }, (cfg) =>
|
|
178
|
-
Effect.gen(function* () {
|
|
179
|
-
const creds = yield* readCredentials<OAuthClient.OAuthCredentials>(
|
|
180
|
-
profileName,
|
|
181
|
-
"cf-oauth",
|
|
182
|
-
);
|
|
183
|
-
if (creds == null || creds.type !== "oauth") {
|
|
184
|
-
return yield* Effect.fail(
|
|
185
|
-
new AuthError({
|
|
186
|
-
message:
|
|
187
|
-
"Cloudflare OAuth credentials not found. Run: alchemy login",
|
|
188
|
-
}),
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
// Refresh proactively if the token has expired (or is within
|
|
192
|
-
// 10s of expiring). Persist the refreshed creds so subsequent
|
|
193
|
-
// resolves don't repeat the round-trip.
|
|
194
|
-
const fresh =
|
|
195
|
-
creds.expires > Date.now() + 10_000
|
|
196
|
-
? creds
|
|
197
|
-
: yield* OAuthClient.refresh(creds).pipe(
|
|
198
|
-
Effect.tap((refreshed) =>
|
|
199
|
-
writeCredentials(profileName, "cf-oauth", refreshed),
|
|
200
|
-
),
|
|
201
|
-
Effect.mapError(
|
|
202
|
-
(e) =>
|
|
203
|
-
new AuthError({
|
|
204
|
-
message:
|
|
205
|
-
"Cloudflare OAuth refresh failed. Run: alchemy login",
|
|
206
|
-
cause: e,
|
|
207
|
-
}),
|
|
208
|
-
),
|
|
209
|
-
);
|
|
210
|
-
return {
|
|
211
|
-
type: "oauth" as const,
|
|
212
|
-
accessToken: Redacted.make(fresh.access),
|
|
213
|
-
expires: fresh.expires,
|
|
214
|
-
accountId: cfg.accountId,
|
|
215
|
-
source: { type: "oauth" as const },
|
|
216
|
-
};
|
|
217
|
-
}),
|
|
218
|
-
),
|
|
219
|
-
Match.exhaustive,
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
const logout = (profileName: string, config: CloudflareAuthConfig) =>
|
|
223
|
-
Match.value(config).pipe(
|
|
224
|
-
Match.when({ method: "env" }, () => Effect.void),
|
|
225
|
-
Match.when({ method: "stored" }, () =>
|
|
226
|
-
deleteCredentials(profileName, "cf-stored").pipe(
|
|
227
|
-
Effect.andThen(Clank.success("Cloudflare: stored credentials removed")),
|
|
228
|
-
),
|
|
229
|
-
),
|
|
230
|
-
Match.when({ method: "oauth" }, () =>
|
|
231
|
-
readCredentials<OAuthClient.OAuthCredentials>(
|
|
232
|
-
profileName,
|
|
233
|
-
"cf-oauth",
|
|
234
|
-
).pipe(
|
|
235
|
-
Effect.tap((creds) =>
|
|
236
|
-
creds?.type === "oauth"
|
|
237
|
-
? OAuthClient.revoke(creds).pipe(
|
|
238
|
-
Effect.catchTag("OAuthError", (err) =>
|
|
239
|
-
Clank.warn(
|
|
240
|
-
`Cloudflare: could not revoke OAuth token: ${err.errorDescription}`,
|
|
241
|
-
),
|
|
242
|
-
),
|
|
243
|
-
)
|
|
244
|
-
: Effect.void,
|
|
245
|
-
),
|
|
246
|
-
Effect.andThen(deleteCredentials(profileName, "cf-oauth")),
|
|
247
|
-
Effect.andThen(Clank.success("Cloudflare: OAuth credentials removed.")),
|
|
248
|
-
),
|
|
249
|
-
),
|
|
250
|
-
Match.exhaustive,
|
|
251
|
-
);
|
|
252
|
-
|
|
253
|
-
const login = (profileName: string, config: CloudflareAuthConfig) =>
|
|
254
|
-
Match.value(config)
|
|
255
|
-
.pipe(
|
|
256
|
-
Match.when({ method: "env" }, () => Effect.void),
|
|
257
|
-
Match.when({ method: "stored" }, () =>
|
|
258
|
-
readCredentials<CloudflareStoredCredentials>(
|
|
259
|
-
profileName,
|
|
260
|
-
"cf-stored",
|
|
261
|
-
).pipe(
|
|
262
|
-
Effect.flatMap((creds) =>
|
|
263
|
-
creds == null ? loginStored(profileName) : Effect.void,
|
|
264
|
-
),
|
|
265
|
-
),
|
|
266
|
-
),
|
|
267
|
-
Match.when({ method: "oauth" }, (c) =>
|
|
268
|
-
Effect.gen(function* () {
|
|
269
|
-
const creds = yield* readCredentials<OAuthClient.OAuthCredentials>(
|
|
270
|
-
profileName,
|
|
271
|
-
"cf-oauth",
|
|
272
|
-
);
|
|
273
|
-
|
|
274
|
-
if (creds?.type === "oauth") {
|
|
275
|
-
yield* Clank.info("Cloudflare: refreshing OAuth credentials...");
|
|
276
|
-
yield* OAuthClient.refresh(creds).pipe(
|
|
277
|
-
Effect.flatMap((refreshed) =>
|
|
278
|
-
writeCredentials(profileName, "cf-oauth", refreshed).pipe(
|
|
279
|
-
Effect.andThen(
|
|
280
|
-
Clank.success("Cloudflare: OAuth credentials refreshed."),
|
|
281
|
-
),
|
|
282
|
-
),
|
|
283
|
-
),
|
|
284
|
-
Effect.catchTag("OAuthError", () =>
|
|
285
|
-
oauthLogin(profileName, c.scopes).pipe(Effect.asVoid),
|
|
286
|
-
),
|
|
287
|
-
);
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
yield* oauthLogin(profileName, c.scopes);
|
|
292
|
-
}),
|
|
293
|
-
),
|
|
294
|
-
Match.exhaustive,
|
|
295
|
-
)
|
|
296
|
-
.pipe(
|
|
297
|
-
Effect.mapError(
|
|
298
|
-
(e) => new AuthError({ message: "login failed", cause: e }),
|
|
299
|
-
),
|
|
300
|
-
);
|
|
301
|
-
|
|
302
|
-
const configureCredentials = (profileName: string, ctx: ConfigureContext) =>
|
|
303
|
-
Effect.gen(function* () {
|
|
304
|
-
if (ctx.ci) {
|
|
305
|
-
return { method: "env" as const };
|
|
306
|
-
}
|
|
307
|
-
return yield* configureInteractive(profileName);
|
|
308
|
-
}).pipe(
|
|
309
|
-
Effect.mapError(
|
|
310
|
-
(e) =>
|
|
311
|
-
new AuthError({
|
|
312
|
-
message: "failed to configure credentials",
|
|
313
|
-
cause: e,
|
|
314
|
-
}),
|
|
315
|
-
),
|
|
316
|
-
);
|
|
317
|
-
|
|
318
|
-
const configureInteractive = (profileName: string) =>
|
|
319
|
-
Clank.select({
|
|
320
|
-
message: "Cloudflare authentication method",
|
|
321
|
-
options,
|
|
322
|
-
}).pipe(
|
|
323
|
-
Effect.flatMap((method) =>
|
|
324
|
-
Match.value(method).pipe(
|
|
325
|
-
Match.when("env", () => Effect.succeed({ method: "env" as const })),
|
|
326
|
-
Match.when("oauth", () => configureOAuth(profileName)),
|
|
327
|
-
Match.when("stored", () => loginStored(profileName)),
|
|
328
|
-
Match.exhaustive,
|
|
329
|
-
),
|
|
330
|
-
),
|
|
331
|
-
);
|
|
332
|
-
|
|
333
|
-
const configureOAuth = Effect.fnUntraced(function* (profileName: string) {
|
|
334
|
-
const scopes = yield* promptOAuthScopes();
|
|
335
|
-
|
|
336
|
-
const oauthCreds = yield* oauthLogin(profileName, scopes);
|
|
337
|
-
|
|
338
|
-
const accountId = yield* selectAccount(oauthCreds.access).pipe(
|
|
339
|
-
Effect.mapError(
|
|
340
|
-
(e) =>
|
|
341
|
-
new AuthError({
|
|
342
|
-
message: "Cloudflare: could not list accounts",
|
|
343
|
-
cause: e,
|
|
344
|
-
}),
|
|
345
|
-
),
|
|
346
|
-
);
|
|
347
|
-
|
|
348
|
-
return {
|
|
349
|
-
method: "oauth" as const,
|
|
350
|
-
scopes,
|
|
351
|
-
accountId,
|
|
352
|
-
};
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
const loginStored = Effect.fnUntraced(function* (profileName: string) {
|
|
356
|
-
const credentialType = yield* Clank.select({
|
|
357
|
-
message: "Cloudflare credential type",
|
|
358
|
-
options: [
|
|
359
|
-
{ value: "apiToken" as const, label: "API Token", hint: "recommended" },
|
|
360
|
-
{ value: "apiKey" as const, label: "API Key + Email" },
|
|
361
|
-
],
|
|
362
|
-
}).pipe(retryOnce);
|
|
363
|
-
|
|
364
|
-
return yield* Match.value(credentialType).pipe(
|
|
365
|
-
Match.when("apiToken", () =>
|
|
366
|
-
Effect.gen(function* () {
|
|
367
|
-
const apiToken = yield* Clank.password({
|
|
368
|
-
message: "Cloudflare API Token",
|
|
369
|
-
validate: (v) => (v.length === 0 ? "Required" : undefined),
|
|
370
|
-
}).pipe(retryOnce);
|
|
371
|
-
const accountId = yield* promptAccountId();
|
|
372
|
-
|
|
373
|
-
yield* writeCredentials<CloudflareStoredCredentials>(
|
|
374
|
-
profileName,
|
|
375
|
-
"cf-stored",
|
|
376
|
-
{ type: "apiToken", apiToken, accountId },
|
|
377
|
-
);
|
|
378
|
-
yield* Clank.success("Cloudflare: credentials saved.");
|
|
379
|
-
return {
|
|
380
|
-
method: "stored" as const,
|
|
381
|
-
credentialType: "apiToken" as const,
|
|
382
|
-
};
|
|
383
|
-
}),
|
|
384
|
-
),
|
|
385
|
-
Match.when("apiKey", () =>
|
|
386
|
-
Effect.gen(function* () {
|
|
387
|
-
const apiKey = yield* Clank.text({
|
|
388
|
-
message: "Cloudflare API Key",
|
|
389
|
-
validate: (v) => (v.length === 0 ? "Required" : undefined),
|
|
390
|
-
}).pipe(retryOnce);
|
|
391
|
-
|
|
392
|
-
const email = yield* Clank.text({
|
|
393
|
-
message: "Cloudflare Email",
|
|
394
|
-
validate: (v) => (v.length === 0 ? "Required" : undefined),
|
|
395
|
-
}).pipe(retryOnce);
|
|
396
|
-
const accountId = yield* promptAccountId();
|
|
397
|
-
|
|
398
|
-
yield* writeCredentials<CloudflareStoredCredentials>(
|
|
399
|
-
profileName,
|
|
400
|
-
"cf-stored",
|
|
401
|
-
{ type: "apiKey", apiKey, email, accountId },
|
|
402
|
-
);
|
|
403
|
-
yield* Clank.success("Cloudflare: credentials saved.");
|
|
404
|
-
return {
|
|
405
|
-
method: "stored" as const,
|
|
406
|
-
credentialType: "apiKey" as const,
|
|
407
|
-
};
|
|
408
|
-
}),
|
|
409
|
-
),
|
|
410
|
-
Match.exhaustive,
|
|
411
|
-
);
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
const oauthLogin = (profileName: string, scopes: string[]) =>
|
|
415
|
-
Effect.gen(function* () {
|
|
416
|
-
const authorization = OAuthClient.authorize([...scopes, "offline_access"]);
|
|
417
|
-
|
|
418
|
-
yield* Clank.info("Cloudflare: opening browser for OAuth login...");
|
|
419
|
-
yield* Clank.info(authorization.url);
|
|
420
|
-
yield* Clank.openUrl(authorization.url).pipe(
|
|
421
|
-
Effect.catch(() =>
|
|
422
|
-
Clank.warn(
|
|
423
|
-
"Cloudflare: could not open browser automatically. Please open the URL above manually.",
|
|
424
|
-
),
|
|
425
|
-
),
|
|
426
|
-
);
|
|
427
|
-
yield* Clank.info(
|
|
428
|
-
"Cloudflare: waiting for authorization (up to 5 minutes)...",
|
|
429
|
-
);
|
|
430
|
-
|
|
431
|
-
const credentials = yield* OAuthClient.callback(authorization);
|
|
432
|
-
yield* writeCredentials(profileName, "cf-oauth", credentials);
|
|
433
|
-
yield* Clank.success("Cloudflare: OAuth credentials saved.");
|
|
434
|
-
return credentials;
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
const promptAccountId = () =>
|
|
438
|
-
getEnv("CLOUDFLARE_ACCOUNT_ID").pipe(
|
|
439
|
-
Effect.flatMap((envAccountId) =>
|
|
440
|
-
Clank.text({
|
|
441
|
-
message: "Cloudflare Account ID (Enter to skip)",
|
|
442
|
-
placeholder: envAccountId ?? "",
|
|
443
|
-
defaultValue: envAccountId ?? "",
|
|
444
|
-
}).pipe(retryOnce),
|
|
445
|
-
),
|
|
446
|
-
);
|
|
447
|
-
|
|
448
|
-
const promptOAuthScopes = () =>
|
|
449
|
-
Clank.confirm({
|
|
450
|
-
message: "Customize OAuth scopes? (default covers typical use cases)",
|
|
451
|
-
initialValue: false,
|
|
452
|
-
}).pipe(
|
|
453
|
-
retryOnce,
|
|
454
|
-
Effect.flatMap((customize) => {
|
|
455
|
-
if (!customize) return Effect.succeed([...DEFAULT_SCOPES]);
|
|
456
|
-
return Clank.multiselect({
|
|
457
|
-
message: "Select OAuth scopes",
|
|
458
|
-
initialValues: DEFAULT_SCOPES as string[],
|
|
459
|
-
options: Object.entries(ALL_SCOPES).map(([value, hint]) => ({
|
|
460
|
-
value: value as string,
|
|
461
|
-
label: value,
|
|
462
|
-
hint,
|
|
463
|
-
})),
|
|
464
|
-
required: true,
|
|
465
|
-
}).pipe(
|
|
466
|
-
Effect.map((s) => s as string[]),
|
|
467
|
-
retryOnce,
|
|
468
|
-
);
|
|
469
|
-
}),
|
|
470
|
-
);
|
|
471
|
-
|
|
472
82
|
const withOAuthCredentials = <A, E>(
|
|
473
83
|
accessToken: string,
|
|
474
84
|
effect: Effect.Effect<
|
|
@@ -516,49 +126,452 @@ const selectAccount = (accessToken: string) =>
|
|
|
516
126
|
}).pipe(retryOnce);
|
|
517
127
|
}).pipe((e) => withOAuthCredentials(accessToken, e));
|
|
518
128
|
|
|
519
|
-
const
|
|
520
|
-
|
|
521
|
-
Effect.
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
:
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
129
|
+
const promptAccountId = () =>
|
|
130
|
+
getEnv("CLOUDFLARE_ACCOUNT_ID").pipe(
|
|
131
|
+
Effect.flatMap((envAccountId) =>
|
|
132
|
+
Clank.text({
|
|
133
|
+
message: "Cloudflare Account ID (Enter to skip)",
|
|
134
|
+
placeholder: envAccountId ?? "",
|
|
135
|
+
defaultValue: envAccountId ?? "",
|
|
136
|
+
}).pipe(retryOnce),
|
|
137
|
+
),
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
const promptOAuthScopes = () =>
|
|
141
|
+
Clank.confirm({
|
|
142
|
+
message: "Customize OAuth scopes? (default covers typical use cases)",
|
|
143
|
+
initialValue: false,
|
|
144
|
+
}).pipe(
|
|
145
|
+
retryOnce,
|
|
146
|
+
Effect.flatMap((customize) => {
|
|
147
|
+
if (!customize) return Effect.succeed([...DEFAULT_SCOPES]);
|
|
148
|
+
return Clank.multiselect({
|
|
149
|
+
message: "Select OAuth scopes",
|
|
150
|
+
initialValues: DEFAULT_SCOPES as string[],
|
|
151
|
+
options: Object.entries(ALL_SCOPES).map(([value, hint]) => ({
|
|
152
|
+
value: value as string,
|
|
153
|
+
label: value,
|
|
154
|
+
hint,
|
|
155
|
+
})),
|
|
156
|
+
required: true,
|
|
157
|
+
}).pipe(
|
|
158
|
+
Effect.map((s) => s as string[]),
|
|
159
|
+
retryOnce,
|
|
160
|
+
);
|
|
161
|
+
}),
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Layer that registers the Cloudflare {@link AuthProvider} into the
|
|
166
|
+
* {@link AuthProviders} registry when built. Include this in the Cloudflare
|
|
167
|
+
* `providers()` layer so `alchemy login` can discover it.
|
|
168
|
+
*/
|
|
169
|
+
export const CloudflareAuth = AuthProviderLayer<
|
|
170
|
+
CloudflareAuthConfig,
|
|
171
|
+
CloudflareResolvedCredentials
|
|
172
|
+
>()(
|
|
173
|
+
CLOUDFLARE_AUTH_PROVIDER_NAME,
|
|
174
|
+
Effect.gen(function* () {
|
|
175
|
+
const store = yield* CredentialsStore;
|
|
176
|
+
|
|
177
|
+
const oauthLogin = (profileName: string, scopes: string[]) =>
|
|
178
|
+
Effect.gen(function* () {
|
|
179
|
+
const authorization = OAuthClient.authorize([
|
|
180
|
+
...scopes,
|
|
181
|
+
"offline_access",
|
|
182
|
+
]);
|
|
183
|
+
|
|
184
|
+
yield* Clank.info("Cloudflare: opening browser for OAuth login...");
|
|
185
|
+
yield* Clank.info(authorization.url);
|
|
186
|
+
yield* Clank.openUrl(authorization.url).pipe(
|
|
187
|
+
Effect.catch(() =>
|
|
188
|
+
Clank.warn(
|
|
189
|
+
"Cloudflare: could not open browser automatically. Please open the URL above manually.",
|
|
190
|
+
),
|
|
191
|
+
),
|
|
192
|
+
);
|
|
193
|
+
yield* Clank.info(
|
|
194
|
+
"Cloudflare: waiting for authorization (up to 5 minutes)...",
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
const credentials = yield* OAuthClient.callback(authorization);
|
|
198
|
+
yield* store.write(profileName, "cf-oauth", credentials);
|
|
199
|
+
yield* Clank.success("Cloudflare: OAuth credentials saved.");
|
|
200
|
+
return credentials;
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const loginStored = Effect.fnUntraced(function* (profileName: string) {
|
|
204
|
+
const credentialType = yield* Clank.select({
|
|
205
|
+
message: "Cloudflare credential type",
|
|
206
|
+
options: [
|
|
207
|
+
{
|
|
208
|
+
value: "apiToken" as const,
|
|
209
|
+
label: "API Token",
|
|
210
|
+
hint: "recommended",
|
|
211
|
+
},
|
|
212
|
+
{ value: "apiKey" as const, label: "API Key + Email" },
|
|
213
|
+
],
|
|
214
|
+
}).pipe(retryOnce);
|
|
215
|
+
|
|
216
|
+
return yield* Match.value(credentialType).pipe(
|
|
217
|
+
Match.when("apiToken", () =>
|
|
218
|
+
Effect.gen(function* () {
|
|
219
|
+
const apiToken = yield* Clank.password({
|
|
220
|
+
message: "Cloudflare API Token",
|
|
221
|
+
validate: (v) => (v.length === 0 ? "Required" : undefined),
|
|
222
|
+
}).pipe(retryOnce);
|
|
223
|
+
const accountId = yield* promptAccountId();
|
|
224
|
+
|
|
225
|
+
yield* store.write<CloudflareStoredCredentials>(
|
|
226
|
+
profileName,
|
|
227
|
+
"cf-stored",
|
|
228
|
+
{ type: "apiToken", apiToken, accountId },
|
|
229
|
+
);
|
|
230
|
+
yield* Clank.success("Cloudflare: credentials saved.");
|
|
231
|
+
return {
|
|
232
|
+
method: "stored" as const,
|
|
233
|
+
credentialType: "apiToken" as const,
|
|
234
|
+
};
|
|
235
|
+
}),
|
|
532
236
|
),
|
|
533
|
-
Match.when(
|
|
534
|
-
Effect.
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
237
|
+
Match.when("apiKey", () =>
|
|
238
|
+
Effect.gen(function* () {
|
|
239
|
+
const apiKey = yield* Clank.text({
|
|
240
|
+
message: "Cloudflare API Key",
|
|
241
|
+
validate: (v) => (v.length === 0 ? "Required" : undefined),
|
|
242
|
+
}).pipe(retryOnce);
|
|
243
|
+
|
|
244
|
+
const email = yield* Clank.text({
|
|
245
|
+
message: "Cloudflare Email",
|
|
246
|
+
validate: (v) => (v.length === 0 ? "Required" : undefined),
|
|
247
|
+
}).pipe(retryOnce);
|
|
248
|
+
const accountId = yield* promptAccountId();
|
|
249
|
+
|
|
250
|
+
yield* store.write<CloudflareStoredCredentials>(
|
|
251
|
+
profileName,
|
|
252
|
+
"cf-stored",
|
|
253
|
+
{ type: "apiKey", apiKey, email, accountId },
|
|
254
|
+
);
|
|
255
|
+
yield* Clank.success("Cloudflare: credentials saved.");
|
|
256
|
+
return {
|
|
257
|
+
method: "stored" as const,
|
|
258
|
+
credentialType: "apiKey" as const,
|
|
259
|
+
};
|
|
260
|
+
}),
|
|
540
261
|
),
|
|
541
|
-
Match.when({ type: "oauth" }, (c) => {
|
|
542
|
-
const remainingMs = c.expires - Date.now();
|
|
543
|
-
const expiresAt = new Date(c.expires).toISOString();
|
|
544
|
-
const expiresStr =
|
|
545
|
-
remainingMs <= 0
|
|
546
|
-
? `expired (${expiresAt})`
|
|
547
|
-
: `in ${Duration.format(Duration.millis(remainingMs))} (${expiresAt})`;
|
|
548
|
-
return Effect.all([
|
|
549
|
-
Console.log(` accessToken: ${displayRedacted(c.accessToken)}`),
|
|
550
|
-
Console.log(` expires: ${expiresStr}`),
|
|
551
|
-
Console.log(` accountId: ${c.accountId}`),
|
|
552
|
-
Console.log(` source: ${sourceStr}`),
|
|
553
|
-
]);
|
|
554
|
-
}),
|
|
555
262
|
Match.exhaustive,
|
|
556
263
|
);
|
|
557
|
-
})
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
const configureOAuth = Effect.fnUntraced(function* (profileName: string) {
|
|
267
|
+
const scopes = yield* promptOAuthScopes();
|
|
268
|
+
|
|
269
|
+
const oauthCreds = yield* oauthLogin(profileName, scopes);
|
|
270
|
+
|
|
271
|
+
const accountId = yield* selectAccount(oauthCreds.access).pipe(
|
|
272
|
+
Effect.mapError(
|
|
273
|
+
(e) =>
|
|
274
|
+
new AuthError({
|
|
275
|
+
message: "Cloudflare: could not list accounts",
|
|
276
|
+
cause: e,
|
|
277
|
+
}),
|
|
278
|
+
),
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
return {
|
|
282
|
+
method: "oauth" as const,
|
|
283
|
+
scopes,
|
|
284
|
+
accountId,
|
|
285
|
+
};
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
const configureInteractive = (profileName: string) =>
|
|
289
|
+
Clank.select({
|
|
290
|
+
message: "Cloudflare authentication method",
|
|
291
|
+
options,
|
|
292
|
+
}).pipe(
|
|
293
|
+
Effect.flatMap((method) =>
|
|
294
|
+
Match.value(method).pipe(
|
|
295
|
+
Match.when("env", () => Effect.succeed({ method: "env" as const })),
|
|
296
|
+
Match.when("oauth", () => configureOAuth(profileName)),
|
|
297
|
+
Match.when("stored", () => loginStored(profileName)),
|
|
298
|
+
Match.exhaustive,
|
|
299
|
+
),
|
|
300
|
+
),
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
const configureCredentials = (profileName: string, ctx: ConfigureContext) =>
|
|
304
|
+
Effect.gen(function* () {
|
|
305
|
+
if (ctx.ci) {
|
|
306
|
+
return { method: "env" as const };
|
|
307
|
+
}
|
|
308
|
+
return yield* configureInteractive(profileName);
|
|
309
|
+
}).pipe(
|
|
310
|
+
Effect.mapError(
|
|
311
|
+
(e) =>
|
|
312
|
+
new AuthError({
|
|
313
|
+
message: "failed to configure credentials",
|
|
314
|
+
cause: e,
|
|
315
|
+
}),
|
|
316
|
+
),
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
const resolveCredentials = (
|
|
320
|
+
profileName: string,
|
|
321
|
+
config: CloudflareAuthConfig,
|
|
322
|
+
): Effect.Effect<CloudflareResolvedCredentials, AuthError> =>
|
|
323
|
+
Match.value(config).pipe(
|
|
324
|
+
Match.when(
|
|
325
|
+
{ method: "env" },
|
|
326
|
+
Effect.fnUntraced(function* () {
|
|
327
|
+
const accountId = yield* getEnvRequired("CLOUDFLARE_ACCOUNT_ID");
|
|
328
|
+
const apiToken = yield* getEnvRedacted("CLOUDFLARE_API_TOKEN");
|
|
329
|
+
if (apiToken) {
|
|
330
|
+
return {
|
|
331
|
+
type: "apiToken" as const,
|
|
332
|
+
apiToken,
|
|
333
|
+
accountId,
|
|
334
|
+
source: { type: "env" as const },
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
const apiKey = yield* getEnvRedacted("CLOUDFLARE_API_KEY");
|
|
338
|
+
const email = yield* getEnvRedacted("CLOUDFLARE_EMAIL");
|
|
339
|
+
if (apiKey && email) {
|
|
340
|
+
return {
|
|
341
|
+
type: "apiKey" as const,
|
|
342
|
+
apiKey,
|
|
343
|
+
email,
|
|
344
|
+
accountId,
|
|
345
|
+
source: { type: "env" as const },
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
return yield* new AuthError({
|
|
349
|
+
message:
|
|
350
|
+
"Cloudflare env credentials not found. Set CLOUDFLARE_API_TOKEN or CLOUDFLARE_API_KEY + CLOUDFLARE_EMAIL.",
|
|
351
|
+
});
|
|
352
|
+
}),
|
|
353
|
+
),
|
|
354
|
+
Match.when({ method: "stored" }, () =>
|
|
355
|
+
store
|
|
356
|
+
.read<CloudflareStoredCredentials>(profileName, "cf-stored")
|
|
357
|
+
.pipe(
|
|
358
|
+
Effect.flatMap((creds) =>
|
|
359
|
+
creds == null
|
|
360
|
+
? Effect.fail(
|
|
361
|
+
new AuthError({
|
|
362
|
+
message:
|
|
363
|
+
"Cloudflare stored credentials not found. Run: alchemy-effect login --configure",
|
|
364
|
+
}),
|
|
365
|
+
)
|
|
366
|
+
: Effect.succeed(
|
|
367
|
+
Match.value(creds).pipe(
|
|
368
|
+
Match.when({ type: "apiToken" }, (c) => ({
|
|
369
|
+
type: "apiToken" as const,
|
|
370
|
+
apiToken: Redacted.make(c.apiToken),
|
|
371
|
+
accountId: c.accountId,
|
|
372
|
+
source: { type: "stored" as const },
|
|
373
|
+
})),
|
|
374
|
+
Match.when({ type: "apiKey" }, (c) => ({
|
|
375
|
+
type: "apiKey" as const,
|
|
376
|
+
apiKey: Redacted.make(c.apiKey),
|
|
377
|
+
email: Redacted.make(c.email),
|
|
378
|
+
accountId: c.accountId,
|
|
379
|
+
source: { type: "stored" as const },
|
|
380
|
+
})),
|
|
381
|
+
Match.exhaustive,
|
|
382
|
+
),
|
|
383
|
+
),
|
|
384
|
+
),
|
|
385
|
+
),
|
|
386
|
+
),
|
|
387
|
+
Match.when({ method: "oauth" }, (cfg) =>
|
|
388
|
+
Effect.gen(function* () {
|
|
389
|
+
const creds = yield* store.read<OAuthClient.OAuthCredentials>(
|
|
390
|
+
profileName,
|
|
391
|
+
"cf-oauth",
|
|
392
|
+
);
|
|
393
|
+
if (creds == null || creds.type !== "oauth") {
|
|
394
|
+
return yield* Effect.fail(
|
|
395
|
+
new AuthError({
|
|
396
|
+
message:
|
|
397
|
+
"Cloudflare OAuth credentials not found. Run: alchemy login",
|
|
398
|
+
}),
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
// Refresh proactively if the token has expired (or is within
|
|
402
|
+
// 10s of expiring). Persist the refreshed creds so subsequent
|
|
403
|
+
// resolves don't repeat the round-trip.
|
|
404
|
+
const fresh =
|
|
405
|
+
creds.expires > Date.now() + 10_000
|
|
406
|
+
? creds
|
|
407
|
+
: yield* OAuthClient.refresh(creds).pipe(
|
|
408
|
+
Effect.tap((refreshed) =>
|
|
409
|
+
store.write(profileName, "cf-oauth", refreshed),
|
|
410
|
+
),
|
|
411
|
+
Effect.mapError(
|
|
412
|
+
(e) =>
|
|
413
|
+
new AuthError({
|
|
414
|
+
message:
|
|
415
|
+
"Cloudflare OAuth refresh failed. Run: alchemy login",
|
|
416
|
+
cause: e,
|
|
417
|
+
}),
|
|
418
|
+
),
|
|
419
|
+
);
|
|
420
|
+
return {
|
|
421
|
+
type: "oauth" as const,
|
|
422
|
+
accessToken: Redacted.make(fresh.access),
|
|
423
|
+
expires: fresh.expires,
|
|
424
|
+
accountId: cfg.accountId,
|
|
425
|
+
source: { type: "oauth" as const },
|
|
426
|
+
};
|
|
427
|
+
}),
|
|
428
|
+
),
|
|
429
|
+
Match.exhaustive,
|
|
430
|
+
);
|
|
431
|
+
|
|
432
|
+
const logout = (profileName: string, config: CloudflareAuthConfig) =>
|
|
433
|
+
Match.value(config).pipe(
|
|
434
|
+
Match.when({ method: "env" }, () => Effect.void),
|
|
435
|
+
Match.when({ method: "stored" }, () =>
|
|
436
|
+
store
|
|
437
|
+
.delete(profileName, "cf-stored")
|
|
438
|
+
.pipe(
|
|
439
|
+
Effect.andThen(
|
|
440
|
+
Clank.success("Cloudflare: stored credentials removed"),
|
|
441
|
+
),
|
|
442
|
+
),
|
|
443
|
+
),
|
|
444
|
+
Match.when({ method: "oauth" }, () =>
|
|
445
|
+
store
|
|
446
|
+
.read<OAuthClient.OAuthCredentials>(profileName, "cf-oauth")
|
|
447
|
+
.pipe(
|
|
448
|
+
Effect.tap((creds) =>
|
|
449
|
+
creds?.type === "oauth"
|
|
450
|
+
? OAuthClient.revoke(creds).pipe(
|
|
451
|
+
Effect.catchTag("OAuthError", (err) =>
|
|
452
|
+
Clank.warn(
|
|
453
|
+
`Cloudflare: could not revoke OAuth token: ${err.errorDescription}`,
|
|
454
|
+
),
|
|
455
|
+
),
|
|
456
|
+
)
|
|
457
|
+
: Effect.void,
|
|
458
|
+
),
|
|
459
|
+
Effect.andThen(store.delete(profileName, "cf-oauth")),
|
|
460
|
+
Effect.andThen(
|
|
461
|
+
Clank.success("Cloudflare: OAuth credentials removed."),
|
|
462
|
+
),
|
|
463
|
+
),
|
|
464
|
+
),
|
|
465
|
+
Match.exhaustive,
|
|
466
|
+
);
|
|
467
|
+
|
|
468
|
+
const login = (profileName: string, config: CloudflareAuthConfig) =>
|
|
469
|
+
Match.value(config)
|
|
470
|
+
.pipe(
|
|
471
|
+
Match.when({ method: "env" }, () => Effect.void),
|
|
472
|
+
Match.when({ method: "stored" }, () =>
|
|
473
|
+
store
|
|
474
|
+
.read<CloudflareStoredCredentials>(profileName, "cf-stored")
|
|
475
|
+
.pipe(
|
|
476
|
+
Effect.flatMap((creds) =>
|
|
477
|
+
creds == null ? loginStored(profileName) : Effect.void,
|
|
478
|
+
),
|
|
479
|
+
),
|
|
480
|
+
),
|
|
481
|
+
Match.when({ method: "oauth" }, (c) =>
|
|
482
|
+
Effect.gen(function* () {
|
|
483
|
+
const creds = yield* store.read<OAuthClient.OAuthCredentials>(
|
|
484
|
+
profileName,
|
|
485
|
+
"cf-oauth",
|
|
486
|
+
);
|
|
487
|
+
|
|
488
|
+
if (creds?.type === "oauth") {
|
|
489
|
+
yield* Clank.info(
|
|
490
|
+
"Cloudflare: refreshing OAuth credentials...",
|
|
491
|
+
);
|
|
492
|
+
yield* OAuthClient.refresh(creds).pipe(
|
|
493
|
+
Effect.flatMap((refreshed) =>
|
|
494
|
+
store
|
|
495
|
+
.write(profileName, "cf-oauth", refreshed)
|
|
496
|
+
.pipe(
|
|
497
|
+
Effect.andThen(
|
|
498
|
+
Clank.success(
|
|
499
|
+
"Cloudflare: OAuth credentials refreshed.",
|
|
500
|
+
),
|
|
501
|
+
),
|
|
502
|
+
),
|
|
503
|
+
),
|
|
504
|
+
Effect.catchTag("OAuthError", () =>
|
|
505
|
+
oauthLogin(profileName, c.scopes).pipe(Effect.asVoid),
|
|
506
|
+
),
|
|
507
|
+
);
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
yield* oauthLogin(profileName, c.scopes);
|
|
512
|
+
}),
|
|
513
|
+
),
|
|
514
|
+
Match.exhaustive,
|
|
515
|
+
)
|
|
516
|
+
.pipe(
|
|
517
|
+
Effect.mapError(
|
|
518
|
+
(e) => new AuthError({ message: "login failed", cause: e }),
|
|
519
|
+
),
|
|
520
|
+
);
|
|
521
|
+
|
|
522
|
+
const prettyPrint = (profileName: string, config: CloudflareAuthConfig) =>
|
|
523
|
+
resolveCredentials(profileName, config).pipe(
|
|
524
|
+
Effect.tap((creds) => {
|
|
525
|
+
const sourceStr = creds.source.details
|
|
526
|
+
? `${creds.source.type} - ${creds.source.details}`
|
|
527
|
+
: creds.source.type;
|
|
528
|
+
return Match.value(creds).pipe(
|
|
529
|
+
Match.when({ type: "apiToken" }, (c) =>
|
|
530
|
+
Effect.all([
|
|
531
|
+
Console.log(` apiToken: ${displayRedacted(c.apiToken, 9)}`),
|
|
532
|
+
Console.log(` accountId: ${c.accountId}`),
|
|
533
|
+
Console.log(` source: ${sourceStr}`),
|
|
534
|
+
]),
|
|
535
|
+
),
|
|
536
|
+
Match.when({ type: "apiKey" }, (c) =>
|
|
537
|
+
Effect.all([
|
|
538
|
+
Console.log(` apiKey: ${displayRedacted(c.apiKey)}`),
|
|
539
|
+
Console.log(` email: ${displayRedacted(c.email)}`),
|
|
540
|
+
Console.log(` accountId: ${c.accountId}`),
|
|
541
|
+
Console.log(` source: ${sourceStr}`),
|
|
542
|
+
]),
|
|
543
|
+
),
|
|
544
|
+
Match.when({ type: "oauth" }, (c) => {
|
|
545
|
+
const remainingMs = c.expires - Date.now();
|
|
546
|
+
const expiresAt = new Date(c.expires).toISOString();
|
|
547
|
+
const expiresStr =
|
|
548
|
+
remainingMs <= 0
|
|
549
|
+
? `expired (${expiresAt})`
|
|
550
|
+
: `in ${Duration.format(Duration.millis(remainingMs))} (${expiresAt})`;
|
|
551
|
+
return Effect.all([
|
|
552
|
+
Console.log(` accessToken: ${displayRedacted(c.accessToken)}`),
|
|
553
|
+
Console.log(` expires: ${expiresStr}`),
|
|
554
|
+
Console.log(` accountId: ${c.accountId}`),
|
|
555
|
+
Console.log(` source: ${sourceStr}`),
|
|
556
|
+
]);
|
|
557
|
+
}),
|
|
558
|
+
Match.exhaustive,
|
|
559
|
+
);
|
|
560
|
+
}),
|
|
561
|
+
Effect.catch((e) =>
|
|
562
|
+
Console.error(` Failed to retrieve credentials: ${e}`),
|
|
563
|
+
),
|
|
564
|
+
);
|
|
565
|
+
|
|
566
|
+
return {
|
|
567
|
+
configure: configureCredentials,
|
|
568
|
+
logout,
|
|
569
|
+
login,
|
|
570
|
+
prettyPrint,
|
|
571
|
+
read: resolveCredentials,
|
|
572
|
+
};
|
|
573
|
+
}),
|
|
574
|
+
);
|
|
562
575
|
|
|
563
576
|
export const ALL_SCOPES = {
|
|
564
577
|
"access:read":
|
|
@@ -680,6 +693,8 @@ export const DEFAULT_SCOPES = [
|
|
|
680
693
|
"user:read",
|
|
681
694
|
"vectorize:write",
|
|
682
695
|
"workers_kv:write",
|
|
696
|
+
"workers_observability:read",
|
|
697
|
+
"workers_observability_telemetry:write",
|
|
683
698
|
"workers_routes:write",
|
|
684
699
|
"workers_scripts:write",
|
|
685
700
|
"workers_tail:read",
|