UNPKG

@m-ld/gateway

Version:

m-ld gateway for services

77 lines (76 loc) 3.13 kB
import { MeldClone, MeldConfig, MeldReadState, MeldUpdate } from '@m-ld/m-ld'; import { AccountOwnedId, BaseGateway, CloneFactory, Env, GatewayPrincipal, KeyStore } from '../lib/index.js'; import { Iri, UserKey } from '../data/index.js'; import { GatewayConfig } from './index.js'; import { Account, AccountContext, SubdomainNaming } from './Account.js'; import { SubdomainClone } from './SubdomainClone.js'; import { SubdomainSpec } from '../data/Subdomain.js'; import { SubdomainCache } from './SubdomainCache'; export interface Who { acc: Account; keyid: string; } export declare class Gateway extends BaseGateway implements AccountContext { private readonly env; private readonly cloneFactory; readonly keyStore: KeyStore; private readonly subdomainCache; readonly me: GatewayPrincipal; domain: MeldClone; readonly config: GatewayConfig; private readonly subs; constructor(env: Env, config: GatewayConfig, cloneFactory: CloneFactory, keyStore: KeyStore, subdomainCache: SubdomainCache); initialise(): Promise<this>; get rootAccountName(): string; onUpdateSubdomains(update: MeldUpdate): Promise<void[][]>; onUpdateSubdomain(_id: AccountOwnedId, _update: MeldUpdate, _state: MeldReadState): Promise<void>; /** * @param sd * @param iri gateway-relative or absolute IRI * @param type note vocabulary is common between gw and ts * @param key */ writePrincipalToSubdomain(sd: SubdomainClone, iri: Iri, type: 'Account' | 'Gateway', key: UserKey): Promise<void>; getDataPath(id: AccountOwnedId): Promise<string>; subdomainRemoved(id: AccountOwnedId): Promise<void>; tsTombstoneExists(id: AccountOwnedId): Promise<boolean>; /** * @param account name * @param [orCreate] allow creation of new account */ account(account: string, orCreate: true): Promise<Account>; account(account: string, orCreate?: boolean): Promise<Account | undefined>; /** * @param user name * @param email */ activation(user: string, email: string): Promise<{ code: string; jwe: string; }>; /** * Verify the JWT was an activation created by us * @param code an activation code created by this Gateway * @param jwe a corresponding encrypted JWT */ verifyActivation(code: string, jwe: string): { user: string; email: string; }; /** * Gets the m-ld configuration for a subdomain. Calling this method will * create the subdomain if it does not already exist. * * The caller must have already checked user access to the subdomain. * * @param spec the subdomain identity * @param naming if `'any'`, a named subdomain will be created * @param who the user who is asking */ subdomainConfig(spec: SubdomainSpec, naming: SubdomainNaming, who?: Who): Promise<Partial<MeldConfig>>; getSubdomain(id: AccountOwnedId): Promise<SubdomainClone | undefined>; private cloneSubdomain; /** @internal for tests */ hasClonedSubdomain(id: AccountOwnedId): boolean; close(): Promise<void>; }