1/**
2 * Shared scaffolding for Fly SecretKey HTTP bindings.
3 *
4 * NOT exported from `index.ts`.
5 */
6import type * as Effect from "effect/Effect";
7import type { SecretAuth } from "./SecretHttp.ts";
8import { makeHttpSecretBinding } from "./SecretHttp.ts";
9import type { SecretKey } from "./SecretKey.ts";
10
11export const bytesToBase64 = (bytes: Uint8Array | ArrayLike<number>): string =>
12 Buffer.from(
13 bytes instanceof Uint8Array ? bytes : Uint8Array.from(bytes),
14 ).toString("base64");
15
16export const base64ToBytes = (value: string | undefined): Uint8Array =>
17 Uint8Array.from(Buffer.from(value ?? "", "base64"));
18
19export 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 });