The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type { Input } from "alchemy/Input"; |
| 2 | import * as Output from "alchemy/Output"; |
| 3 | import * as Config from "effect/Config"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as Redacted from "effect/Redacted"; |
| 6 | import type { Environment } from "./Environment.ts"; |
| 7 | import { Secret } from "./Secret.ts"; |
| 8 | |
| 9 | export interface SecretsProps { |
| 10 | /** |
| 11 | * Repository owner (user or organization). |
| 12 | */ |
| 13 | owner: string; |
| 14 | |
| 15 | /** |
| 16 | * Repository name. |
| 17 | */ |
| 18 | repository: string; |
| 19 | |
| 20 | /** |
| 21 | * Optional environment. When set every secret is scoped to that GitHub |
| 22 | * Actions environment instead of the whole repository. Accepts an |
| 23 | * environment name or a `GitHub.Environment` resource. |
| 24 | */ |
| 25 | environment?: string | Environment; |
| 26 | |
| 27 | /** |
| 28 | * Map of secret name to value. Plain strings are wrapped with |
| 29 | * `Redacted.make`; already-redacted values are passed through. |
| 30 | */ |
| 31 | secrets: Record<string, Input<string | Redacted.Redacted<string>>>; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Bulk-creates a set of {@link Secret}s in the same repository (and |
| 36 | * optionally the same environment). |
| 37 | * |
| 38 | * Each entry in `secrets` becomes one `GitHub.Secret` resource, using the |
| 39 | * map key as both the alchemy logical id and the secret name. |
| 40 | * **Example:** Example |
| 41 | * ```ts |
| 42 | * yield* GitHub.Secrets({ |
| 43 | * owner: "my-org", |
| 44 | * repository: "my-repo", |
| 45 | * secrets: { |
| 46 | * AXIOM_INGEST_TOKEN: tokenValue, |
| 47 | * AXIOM_DATASET_TRACES: traces.name, |
| 48 | * }, |
| 49 | * }); |
| 50 | * ``` |
| 51 | * |
| 52 | * @resource |
| 53 | * @product Actions |
| 54 | */ |
| 55 | export const Secrets = ({ owner, repository, environment, secrets }: SecretsProps) => |
| 56 | Effect.forEach(Object.entries(secrets), ([name, value]) => |
| 57 | Secret(name, { |
| 58 | owner, |
| 59 | repository, |
| 60 | environment, |
| 61 | name, |
| 62 | value: liftValue(value), |
| 63 | }), |
| 64 | ); |
| 65 | |
| 66 | // Accepts a plain string, an existing `Redacted<string>`, or a lazy `Input` |
| 67 | // of either. We must lift through lazy inputs so the inner string gets wrapped |
| 68 | // after the engine resolves it — otherwise `Redacted.make(input)` produces an |
| 69 | // opaque `Redacted<Config | Effect | Output>` that the plan cannot resolve. |
| 70 | const liftValue = ( |
| 71 | value: Input<string | Redacted.Redacted<string>>, |
| 72 | ): Input<Redacted.Redacted<string>> => |
| 73 | Config.isConfig(value) |
| 74 | ? Config.map(value, toRedacted) |
| 75 | : Effect.isEffect(value) |
| 76 | ? Effect.map(value, toRedacted) |
| 77 | : Output.isOutput(value) |
| 78 | ? Output.map(value as Output.Output<string | Redacted.Redacted<string>>, toRedacted) |
| 79 | : toRedacted(value as string | Redacted.Redacted<string>); |
| 80 | |
| 81 | const toRedacted = (value: string | Redacted.Redacted<string>): Redacted.Redacted<string> => |
| 82 | Redacted.isRedacted(value) ? (value as Redacted.Redacted<string>) : Redacted.make(value); |