IF Commons GitHub

governance/token

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0002-anyfs-githost-store FR-003

Where the token of a host comes from, a closed union: none (what is public), a token given in code (what the tests use, a throwaway of a server of their own), the environment through a function that reads it so that nothing reads the process behind a caller's back, or a provider, a function that gives it or says why not, which is how a short-lived token is fetched and how a secret is asked of a person through the credential port of Headless. A token is never part of a place, never in a URL and never in a sentence: it travels in one header of one request, and what is written of one is [redacted].

import { anonymous, staticToken, redactor } from "./token.ts";
const t = staticToken("ghp_exampleexampleexample");
t.kind === "ok" && t.value.kind; // "static"
redactor(["ghp_exampleexampleexample"])("the host said ghp_exampleexampleexample"); // "the host said [redacted]"

Source: commons/anyfs-githost/src/governance/token.ts

8 of 9 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

anonymousconst
const anonymous: TokenSource

No token: only what is public can be read.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

cachedTokenfunction
function cachedToken(source: TokenSource, now?: () => number): () => Promise<Result<string | undefined, string>>

A source that asks its provider again only after ttlMs (never, for a token in code and the environment), so a person is asked once and a short-lived token is fetched when it is about to lapse.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

environmentTokenconst
const environmentToken: (env: (name: string) => string | undefined, name: string) => TokenSource

The token of a variable of the environment: a function that reads it, which is the only place the process is touched.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

providedTokenconst
const providedToken: (fetch: () => Promise<Result<string, string>>, ttlMs?: number | undefined) => TokenSource

The token by a function: for a short-lived token, which it gives again, and for a secret asked of a person.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

redactorfunction
function redactor(tokens: readonly string[]): (text: string) => string

A function that takes every token it is given out of a sentence, so that no failure, no detail and no log line holds one.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

resolveTokenfunction
function resolveToken(source: TokenSource): Promise<Result<string | undefined, string>>

The token a source gives now: none for the source that has none, or why it gives none. A sentence never holds a token.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

staticTokenfunction
function staticToken(token: string): Result<TokenSource, string>

A token given in code, or why it is not one a host would take.

Imported by 6 tests of the run (5 passed, 0 failed): the library's results

TokenSourcetypeno test imports it
type TokenSource =
  | { readonly kind: "none" }
  | { readonly kind: "static"; readonly token: string }
  | { readonly kind: "environment"; readonly env: (name: string) => string | undefined; readonly name: string }
  | { readonly kind: "provider"; readonly fetch: () => Promise<Result<string, string>>; readonly ttlMs?: number };

Where the token comes from.

usableconst
const usable: (token: string) => boolean

Whether a text can be a token in a header.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.