iterate.com / kernel

git clone https://git.iterate.com/repos/kernel

kernel / core / secrets-worker / src / env.tsmain at 949894f

// env.ts — THE SECRETS WORKER'S BINDINGS, as the stack declares them (core/alchemy), and its
// config. The boundary calls it. It calls the pinned hosts, and one other Worker: auth, which says
// who signed an approval (./approvals-page.ts) and signs a request to iterate Cloud
// (./cloud-client.ts).
import type { EgressGatewayEnv } from "iterate/lib";
import type { AuthService } from "iterate/workers";
import type { ActsGate } from "./acts-gate.ts";
import type { ApprovalsIndex } from "./approvals-index.ts";
import { secretsConfigOf } from "./config.ts";
import type { SecretDurableObject } from "./secret/durable-object.ts";

// THE BINDINGS are declared on `Cloudflare.Env`, which `import { env } from "cloudflare:workers"` is
// typed by, as `wrangler types` declares them
// (https://developers.cloudflare.com/workers/runtime-apis/bindings/#importing-env-as-a-global).
// `Env` is the same type by name.
declare global {
  namespace Cloudflare {
    // `EgressGatewayEnv`: the stack's egress gateway, when its deploy names one. Every request
    // that a secret's object sends to a pinned host goes through it; the calls to an iterate
    // Cloud do not (./cloud-client.ts).
    interface Env extends EgressGatewayEnv {
      /** JSON: the config that every Worker of the mind gets (iterate/mind-config). */
      ITERATE: string;
      /** Generated by the stack and bound as a secret: the config's `atRestKey` (./config.ts).
       *  Never returned or logged. */
      ITERATE__AT_REST_KEY: string;
      /** Made by the stack and bound as a secret: the config's `cloudflareRealtime`, as JSON
       *  (./config.ts). Never returned or logged. */
      ITERATE__CLOUDFLARE_REALTIME: string;
      /** One object per secret, named by its path (./secret/durable-object.ts). */
      SECRET: DurableObjectNamespace<SecretDurableObject>;
      /** The Worker Loader, for a secret's exchange code alone (./secret/exchange-jail.ts). */
      LOADER: WorkerLoader;
      /** The list of secrets with an approval rule or a request waiting (./approvals-index.ts). */
      APPROVALS: DurableObjectNamespace<ApprovalsIndex>;
      /** The gate for acts that are not a secret's request: one object (./acts-gate.ts). */
      ACTS: DurableObjectNamespace<ActsGate>;
      /** The `Auth` entrypoint of the auth Worker: who signed a statement (`verify`), and a
       *  statement signed by the stack's own key (`sign`), which is how a request to iterate
       *  Cloud's broker says which deployment sent it (./cloud-client.ts). */
      AUTH: Pick<AuthService, "verify" | "sign">;
    }
  }
}

export type Env = Cloudflare.Env;

/** The Worker's config, which `mindConfigOf` parses once for each `env` object: an isolate's
 *  requests share one, and so do a Durable Object's. */
export const configOf = (env: Env) => secretsConfigOf(env);