client.ts
This file
Path
examples/burrow/packages/catalog/src/client.ts
39 lines · 1.0 KiB · TypeScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
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 1–39why, one step back1import { API, legacyFetch } from "@burrow/kit";2import type { Transport } from "@burrow/kit";34/** A product as the catalog lists it. */5export interface Product {6 readonly id: string;7 readonly name: string;8 readonly priceCents: number;9}1011/** Reads the catalog. */12export interface CatalogClient {13 readonly category: (slug: string) => Promise<readonly Product[]>;14 readonly product: (id: string) => Promise<Product>;15}1617const clientOver = (transport?: Transport): CatalogClient => ({18 category: async (slug) =>19 JSON.parse(20 await legacyFetch(21 `${API}/categories/${encodeURIComponent(slug)}`,22 transport23 )24 ),25 product: async (id) =>26 JSON.parse(27 await legacyFetch(`${API}/products/${encodeURIComponent(id)}`, transport)28 ),29});3031// Made on first use.32let client: CatalogClient | undefined;3334/** The catalog client, made on first use over the transport it was first given. */35export const catalog = (transport?: Transport): CatalogClient => {36 client ??= clientOver(transport);3738 return client;39};