ts / dist / cjs / gate.d.ts
414 words
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
 * Client-side domain gate: a safety net configured on `createGatedClient`
 * via `deniedDomains` / `allowedDomains` that stops domain-touching
 * MUTATIONS (POST/PUT/PATCH/DELETE) before any request reaches the API.
 * Reads are never gated.
 *
 * Entries are exact domain names ("example.ro") or wildcards
 * ("*.example.ro", matching any name under example.ro and the bare suffix
 * itself). Matching is case-insensitive and ignores trailing dots. Deny wins
 * over allow; when `allowedDomains` is set, anything not on it is denied.
 *
 * Because many registration endpoints address domains by registration id,
 * the gate fetches the account's registrations once at creation and keeps
 * an id → domain cache. Ids unknown to the cache (registered after the
 * client was created) are resolved with a single GET
 * /domains/registrations/{id} and cached; ids that still cannot be resolved
 * pass under a pure deny-list but FAIL CLOSED under an allow-list.
 * `refreshGate` re-fetches the whole cache.
 */
import type { Client } from './client.js';
export type GateRules = Readonly<{
    /** Names/patterns this client must never mutate, even though the account could. */
    deniedDomains?: readonly string[];
    /** When set, ONLY these names/patterns may be mutated; an empty list denies everything. */
    allowedDomains?: readonly string[];
}>;
export type Gate = Readonly<{
    rules: GateRules;
    /** registration id → normalized domain name */
    registrations: Map<string, string>;
}>;
/** What a gated operation is about to touch. */
export type GateTarget = Readonly<{
    domain: string | null | undefined;
} | {
    registrationId: string | null | undefined;
}>;
/** Lower-case, trimmed, no trailing dots; undefined for blank input. */
export declare const normalizeDomain: (domain: string | null | undefined) => string | undefined;
/**
 * Return a copy of CLIENT with a domain gate attached. Eagerly builds the
 * registration id → domain cache, which requires an authenticated client.
 */
export declare const attachGate: (client: Client, rules: GateRules) => Promise<Client>;
/**
 * Re-fetch the registration cache of CLIENT's gate (for long-lived clients
 * that registered domains after creation). Returns the refreshed map, or
 * undefined when the client has no gate.
 */
export declare const refreshGate: (client: Client) => Promise<ReadonlyMap<string, string> | undefined>;
/**
 * Assert that the mutation OP (e.g. "POST /domains/registrations") may touch
 * TARGET, throwing a domainDenied error otherwise. A no-op for clients
 * without a gate. Registration ids are resolved through the gate's cache,
 * with a miss falling back to a single-registration fetch.
 */
export declare const checkGate: (client: Client, op: string, target: GateTarget) => Promise<void>;

static mirror of HEAD · about · clone: git clone https://ird.cod-sursa.ro/ts.git