realm-object-server
Version:
124 lines (123 loc) • 4.38 kB
TypeScript
/// <reference types="node" />
import { Discovery } from "./discovery";
import { Realm } from "./shared/realmUtil";
import { Logger } from "./shared/Logger";
import { FindRealmResponse } from "./shared/FindRealmResponse";
import { RealmDefinition } from "./RealmFactory";
import { StatsStorage, StatsSink } from "./stats";
import { TokenValidator } from "./shared";
import { IService } from "./Service";
import { RequestHandler } from "express";
import * as https from "https";
import { AuthClient } from "./service-clients/AuthClient";
import { PermissionsClient } from "./service-clients/PermissionsClient";
import { RealmDirectoryClient } from "./service-clients/RealmDirectoryClient";
import { HealthClient } from "./service-clients/HealthClient";
export declare class ServerValidationError extends Error {
}
export declare class ServerStartError extends Error {
}
export interface CustomTokenValidatorConfig {
publicKey: string;
issuer: string;
algorithms?: string[];
audience?: string;
userIdFieldName?: string;
isAdminQuery?: {
path: string;
value: any;
};
requiredClaims?: {
[path: string]: any;
};
}
export interface ServerConfig {
dataPath: string;
privateKeyPath?: string;
publicKeyPath?: string;
featureToken?: string;
autoKeyGen?: boolean;
autoKeyGenBits?: number;
writeAdminTokenToJson?: boolean;
logger?: Logger;
logLevel?: "all" | "trace" | "debug" | "detail" | "info" | "warn" | "error" | "fatal" | "off";
address?: string;
port?: number | string;
disableTokenRevocation?: boolean;
discovery?: Discovery;
https?: boolean;
httpsKeyPath?: string;
httpsCertChainPath?: string;
httpsPort?: number;
httpsAddress?: string;
httpsForInternalComponents?: boolean;
httpsAgentForInternalComponents?: https.Agent;
middlewares?: RequestHandler | RequestHandler[];
statsSink?: StatsSink;
statsStorage?: StatsStorage;
jsonBodyLimit?: number | string;
authorizationHeaderName?: string;
internalIdentities?: string[];
serviceAgent?: https.Agent;
realmsEncryptionKey?: ArrayBuffer | ArrayBufferView;
vacuumIntervalInSeconds?: number;
minimumSupportedSyncProtocolVersion?: number;
refreshTokenValidators?: CustomTokenValidatorConfig[];
}
export declare class Server {
private serverConfig;
private realmFactory;
private realmHoover;
authClient: AuthClient;
permissionsClient: PermissionsClient;
realmDirectoryClient: RealmDirectoryClient;
healthClient: HealthClient;
privateKey: string;
publicKey: string;
adminToken: string;
services: IService[];
tokenValidator: TokenValidator;
readonly version: string;
private _started;
private numberOfOpenFiles;
readonly started: boolean;
readonly dataPath: string;
readonly discovery: Discovery;
readonly logger: Logger;
readonly publicKeyPath: string;
readonly privateKeyPath: string;
protected statsSink: StatsSink;
protected statsStorage: StatsStorage;
private expressApp;
private httpServer;
private httpAccessLogger;
private httpsServer;
private httpBytesSentCounter;
private httpBytesReceivedCounter;
start(config: ServerConfig): Promise<void>;
readonly address: string;
readonly secureAddress: string;
shutdown(): Promise<void>;
addServices(...services: IService[]): this;
addService(service: IService | string, config?: object): this;
removeService(service: IService | string): this;
getService(name: string): IService & any;
private upgradeHandler;
private connectionHandler;
private shouldIgnoreTrafficForSocket;
private injectLogger;
private addServiceEndpoints;
private startServices;
private startService;
private authenticationMiddleware;
private processException;
private errorHandler;
private validateStartConfig;
private periodicLoggingOfOpenFiles;
openRealm(pathOrDefinition: string | RealmDefinition, schema?: Realm.ObjectSchema[]): Promise<Realm>;
applyPermissions(condition: Realm.Sync.PermissionCondition, realmPath: string, accessLevel: Realm.Sync.AccessLevel): Promise<{
affectedUsers: number;
}>;
ensureRealmExists(realmPath: string, ownerId?: string): Promise<FindRealmResponse>;
private checkNodeVersion;
}