| 1 | import { Random } from "alchemy"; |
| 2 | import * as Cloudflare from "alchemy/Cloudflare"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import { Store } from "./Store.ts"; |
| 5 | |
| 6 | /** |
| 7 | * An API key secret in the Secrets Store. |
| 8 | * |
| 9 | * Uses `Random` to generate a stable random value that persists |
| 10 | * across deploys (only regenerated if the resource is replaced). |
| 11 | */ |
| 12 | export const ApiKey = Effect.gen(function* () { |
| 13 | const store = yield* Store; |
| 14 | const secret = yield* Random("ApiKeyValue"); |
| 15 | |
| 16 | return yield* Cloudflare.SecretsStore.Secret("ApiKey", { |
| 17 | store, |
| 18 | value: secret.text, |
| 19 | }); |
| 20 | }); |