| 1 | /** |
| 2 | * Shared scaffolding for Fly SecretKey HTTP bindings. |
| 3 | * |
| 4 | * NOT exported from `index.ts`. |
| 5 | */ |
| 6 | import type * as Effect from "effect/Effect"; |
| 7 | import type { SecretAuth } from "./SecretHttp.ts"; |
| 8 | import { makeHttpSecretBinding } from "./SecretHttp.ts"; |
| 9 | import type { SecretKey } from "./SecretKey.ts"; |
| 10 | |
| 11 | export const bytesToBase64 = (bytes: Uint8Array | ArrayLike<number>): string => |
| 12 | Buffer.from( |
| 13 | bytes instanceof Uint8Array ? bytes : Uint8Array.from(bytes), |
| 14 | ).toString("base64"); |
| 15 | |
| 16 | export const base64ToBytes = (value: string | undefined): Uint8Array => |
| 17 | Uint8Array.from(Buffer.from(value ?? "", "base64")); |
| 18 | |
| 19 | export const makeHttpSecretKeyBinding = <Client>(options: { |
| 20 | makeClient: ( |
| 21 | auth: SecretAuth, |
| 22 | appName: Effect.Effect<string>, |
| 23 | secretName: Effect.Effect<string>, |
| 24 | ) => Client; |
| 25 | }) => makeHttpSecretBinding<SecretKey, Client>({ ...options, kms: true }); |