@signalapp/mock-server
Version:
Mock Signal Server for writing tests
50 lines (49 loc) • 2.13 kB
TypeScript
import { ProtocolAddress } from '@signalapp/libsignal-client';
import type { JsonValue } from 'type-fest';
import { type RegistrationId, ServiceIdKind } from './types';
import { ParsedUrlQuery } from 'node:querystring';
import { Device } from './data/device';
export type PromiseQueueConfig = Readonly<{
timeout?: number;
name: string;
}>;
export declare function generateRandomE164(): string;
export type ParseAuthHeaderResult = {
username: string;
password: string;
error?: undefined;
} | {
username?: undefined;
password?: undefined;
error: string;
};
export declare function parseAuthHeader(header?: string, options?: {
allowEmptyPassword?: boolean;
}): ParseAuthHeaderResult;
export declare class PromiseQueue<T> {
private readonly defaultTimeout;
private readonly entries;
private readonly resolvers;
private readonly name;
constructor(config: PromiseQueueConfig);
get size(): number;
stop(): void;
pushAndWait(value: T, timeout?: number | undefined): {
promise: Promise<void>;
cancel: () => void;
};
push(value: T): void;
shift(timeout?: number | undefined): Promise<T>;
}
export declare function addressToString(address: ProtocolAddress): string;
export declare function getTodayInSeconds(): number;
export declare function daysToSeconds(days: number): number;
export declare function generateRegistrationId(): RegistrationId;
export declare function generateDevicePassword(): string;
export declare function toBase64(buf: Uint8Array<ArrayBuffer>): string;
export declare function toURLSafeBase64(buf: Uint8Array<ArrayBuffer>): string;
export declare function fromBase64(base64: string): Buffer<ArrayBuffer>;
export declare function fromURLSafeBase64(base64: string): Buffer<ArrayBuffer>;
export declare function assertJsonValue(root: unknown): asserts root is JsonValue;
export declare function serviceIdKindFromQuery(query: Record<string, string> | ParsedUrlQuery | undefined): ServiceIdKind;
export declare function getDevicesKeysResult(serviceIdKind: ServiceIdKind, devices: ReadonlyArray<Device>): Promise<JsonValue>;