proxy.ts
This file
Path
packages/visibility/src/proxy.ts
45 lines · 1.3 KiB · TypeScript
Last changed by
Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
line 1why, one step back1// Only `@sensitive` items hold values, so `@proxy` on any other item maps to nothing.Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 2–15why, one step back2import type { EnvItem, EnvSchemaView } from "@repo/protocol/domain/env";3import type { EnvKey } from "@repo/protocol/ids";4import { Option, String } from "effect";56export interface ProxyRule {7 readonly block: boolean;8 readonly host: string;9 readonly key: EnvKey;10 readonly method: Option.Option<string>;11 readonly path: Option.Option<string>;12 readonly placeholder: string;13}1415/**Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
lines 16–17why, one step back16 * An empty `@placeholder` counts as none, as in varlock's proxy: the gateway17 * swaps the placeholder for the value, and an empty one marks no place to swap.Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 18–45why, one step back18 */19export const placeholderFor = (item: EnvItem): string =>20 Option.fromUndefinedOr(item.placeholder).pipe(21 Option.filter(String.isNonEmpty),22 Option.getOrElse(() => `__${item.key}_PLACEHOLDER__`)23 );2425export const proxyMap = (26 schema: Pick<EnvSchemaView, "items">27): readonly ProxyRule[] =>28 schema.items.flatMap((item) => {29 const { key, proxy, sensitive } = item;3031 if (!sensitive || proxy === undefined) {32 return [];33 }3435 const placeholder = placeholderFor(item);3637 return proxy.domains.map((host) => ({38 block: proxy.block ?? false,39 host,40 key,41 method: Option.fromUndefinedOr(proxy.method),42 path: Option.fromUndefinedOr(proxy.path),43 placeholder,44 }));45 });