import { EventEmitter } from "events"; import { HeadersInit } from "node-fetch"; //#region lib/access.d.ts type AuthHeader = { Authorization: string; Timestamp: string; }; declare class Access { static DELIMITER: string; static createAccessHeader(appId: string, url: string, secret: string): AuthHeader; private static createAccessHeaderByTimestamp; private static signature; private static url2PathWithQuery; } //#endregion //#region lib/constants.d.ts declare const NAMESPACE_APPLICATION = "application"; declare const CLUSTER_NAME_DEFAULT = "default"; declare const CLUSTER_NAMESPACE_SEPARATOR = "+"; declare const APOLLO_CLUSTER_KEY = "apollo.cluster"; declare const APOLLO_META_KEY = "apollo.meta"; declare const CONFIG_FILE_CONTENT_KEY = "content"; declare const NO_APPID_PLACEHOLDER = "ApolloNoAppIdPlaceHolder"; declare const NOTIFICATION_ID_PLACEHOLDER = -1; declare const CHANGE_EVENT_NAME = "change"; declare enum ConfigTypes { PROPERTIES = "properties", XML = "xml", JSON = "json", YML = "yml", YAML = "yaml", TXT = "txt" } declare enum PropertyChangeType { ADDED = "ADDED", MODIFIED = "MODIFIED", DELETED = "DELETED" } //#endregion //#region lib/config_change.d.ts declare class ConfigChange { private readonly namespaceName; private readonly propertyName; private readonly oldValue; private readonly newValue; private readonly changeType; constructor(namespaceName: string, propertyName: string, oldValue: undefined | T, newValue: undefined | T, changeType: PropertyChangeType); getNamespace(): string; getPropertyName(): string; getOldValue(): undefined | T; getNewValue(): undefined | T; getChangeType(): PropertyChangeType; } //#endregion //#region lib/config_change_event.d.ts declare class ConfigChangeEvent { private readonly namespaceName; private readonly configChanges; constructor(namespaceName: string, configChanges: Map>); getNamespace(): string; changedKeys(): string[]; getChange(key: string): undefined | ConfigChange; } //#endregion //#region lib/types.d.ts type ConfigOptions = { configServerUrl: string; appId: string; clusterName: string; namespaceName: string; secret?: string; }; type ConfigRequestOptions = { ip?: string; label?: string; }; type ConfigContentType = { content?: string; }; //#endregion //#region lib/config.d.ts declare abstract class Config extends EventEmitter { private readonly options; private releaseKey; private notificationId; private readonly requestOptions; constructor(options: ConfigOptions, requestOptions?: string | ConfigRequestOptions); getNamespaceName(): string; getNotificationId(): number; setNotificationId(newNotificationId: number): void; protected getConfigOptions(): ConfigOptions; protected getAppId(): string; protected getSecret(): undefined | string; protected getReleaseKey(): string; protected setReleaseKey(releaseKey: string): void; protected getIp(): undefined | string; protected getLabel(): undefined | string; loadAndUpdateConfig(notificationId?: number): Promise; private createNotificationMessages; private normalizeRequestOptions; abstract _loadAndUpdateConfig(url: string, headers: AuthHeader | undefined): Promise; } //#endregion //#region lib/configInterface.d.ts interface ConfigInterface { getAllConfig(): TAllConfig; getProperty(key: string, defaultValue?: TValue): undefined | TValue; getNamespaceName(): string; getNotificationId(): number; loadAndUpdateConfig(notificationId?: number): Promise; addChangeListener(fn: (changeEvent: ConfigChangeEvent) => void): this; } //#endregion //#region lib/properties_config.d.ts type KVConfigContentType = { [key: string]: string; }; declare class PropertiesConfig extends Config implements ConfigInterface> { private configs; constructor(options: ConfigOptions, requestOptions?: string | ConfigRequestOptions); getProperty(key: string, defaultValue?: string): undefined | string; getAllConfig(): Map; private setProperty; private deleteProperty; addChangeListener(fn: (changeEvent: ConfigChangeEvent) => void): this; _loadAndUpdateConfig(url: string, headers: AuthHeader | undefined): Promise; private resolveConfigurations; private getCurrentConfigurations; private diffMap; private updateConfigAndCreateChangeEvent; } //#endregion //#region lib/json_config.d.ts type JSONBaseType = string | number | boolean | null; type JSONArrayType = JSONValueType[]; type JSONType = { [key: string]: JSONValueType; }; type JSONValueType = JSONBaseType | JSONArrayType | JSONType; declare class JSONConfig extends Config implements ConfigInterface { private configs; private content; constructor(options: ConfigOptions, requestOptions?: string | ConfigRequestOptions); getProperty(key: string, defaultValue?: JSONValueType): undefined | JSONValueType; private getPropertyByJSONAndKey; private getPropertyByJSONAndKeySlice; getAllConfig(): JSONValueType; addChangeListener(fn: (changeEvent: ConfigChangeEvent) => void): this; _loadAndUpdateConfig(url: string, headers: AuthHeader | undefined): Promise; private resolveContent; private diffJSON; private updateConfigAndCreateChangeEvent; private cloneJSONValue; } //#endregion //#region lib/plain_config.d.ts declare class PlainConfig extends Config implements ConfigInterface { private configs; constructor(options: ConfigOptions, requestOptions?: string | ConfigRequestOptions); getAllConfig(): undefined | string; getProperty(_?: string, defaultValue?: string): undefined | string; _loadAndUpdateConfig(url: string, headers: AuthHeader | undefined): Promise; private resolveContent; addChangeListener(fn: (changeEvent: ConfigChangeEvent) => void): this; private updateConfigAndCreateChangeEvent; } //#endregion //#region lib/config_manager.d.ts type ConfigManagerOptions = { configServerUrl: string; appId: string; clusterName: string; secret?: string; }; declare class ConfigManager { private readonly options; private static readonly NO_IP_CONFIGS_MAP_KEY; private static readonly NO_LABEL_CONFIGS_MAP_KEY; private LONG_POLL_RETRY_TIME; private MAX_LONG_POLL_RETRY_TIME; private MIN_LONG_POLL_RETRY_TIME; private configsMap; private configsMapVersion; private closed; constructor(options: ConfigManagerOptions); private getTypeByNamespaceName; getConfig(namespaceName: string, ip?: string): Promise; getConfig(namespaceName: string, options?: ConfigRequestOptions): Promise; getConfig(namespaceName: string, options?: string | ConfigRequestOptions): Promise; removeConfig(namespaceName: string, ip?: string): void; removeConfig(namespaceName: string, options?: ConfigRequestOptions): void; removeConfig(namespaceName: string, options?: string | ConfigRequestOptions): void; close(): void; private updateConfigs; private startLongPoll; private normalizeRequestOptions; private formatConfigsMapKey; private sleep; } //#endregion //#region lib/config_service.d.ts declare class ConfigService { private readonly options; private readonly configManager; constructor(options: { configServerUrl: string; appId: string; clusterName?: string; secret?: string; }); /** * getAppConfig, default namespace name: `application` */ getAppConfig(ip?: string): Promise; getAppConfig(options?: ConfigRequestOptions): Promise; getAppConfig(options?: string | ConfigRequestOptions): Promise; /** * get Config by namespaceName */ getConfig(namespaceName: string, ip?: string): Promise; getConfig(namespaceName: string, options?: ConfigRequestOptions): Promise; getConfig(namespaceName: string, options?: string | ConfigRequestOptions): Promise; /** * stop long polling and release cached config instances */ close(): void; } //#endregion //#region lib/request.d.ts type ConfigUrlOptions = { configServerUrl: string; appId: string; clusterName: string; namespaceName: string; releaseKey?: string; ip?: string; label?: string; messages?: NotificationMessages; }; type NotificationsUrlOptions = { configServerUrl: string; appId: string; clusterName: string; }; type ConfigQueryParam = { releaseKey?: string; ip?: string; label?: string; messages?: string; }; type Notification = { namespaceName: string; notificationId: number; }; type NotificationMessages = { details: { [key: string]: number; }; }; type ConfigurationChange = { key?: string; propertyName?: string; changeType?: string; configurationChangeType?: string; oldValue?: string; newValue?: string; }; type LoadConfigResp = { appId: string; cluster: string; namespaceName: string; configurations?: T; configurationChanges?: ConfigurationChange[]; configSyncType?: string; releaseKey: string; }; declare class Request { static formatConfigUrl(urlOptions: ConfigUrlOptions): string; static fetchConfig(url: string, headers?: HeadersInit): Promise | null>; static formatNotificationsUrl(options: NotificationsUrlOptions, configsMap: Map): string; static fetchNotifications(url: string, headers?: HeadersInit): Promise; static isIncrementalConfig(loadConfigResp: LoadConfigResp): boolean; static mergeConfigurationChanges(configurations: { [key: string]: string; }, configurationChanges?: ConfigurationChange[]): { [key: string]: string; }; private static trimTrailingSlash; private static appendQuery; private static stringify; private static parseJSON; } //#endregion export { APOLLO_CLUSTER_KEY, APOLLO_META_KEY, Access, AuthHeader, CHANGE_EVENT_NAME, CLUSTER_NAMESPACE_SEPARATOR, CLUSTER_NAME_DEFAULT, CONFIG_FILE_CONTENT_KEY, Config, ConfigChange, ConfigChangeEvent, ConfigContentType, ConfigInterface, ConfigManager, ConfigManagerOptions, ConfigOptions, ConfigQueryParam, ConfigRequestOptions, ConfigService, ConfigTypes, ConfigUrlOptions, ConfigurationChange, JSONArrayType, JSONBaseType, JSONConfig, JSONType, JSONValueType, KVConfigContentType, LoadConfigResp, NAMESPACE_APPLICATION, NOTIFICATION_ID_PLACEHOLDER, NO_APPID_PLACEHOLDER, Notification, NotificationMessages, NotificationsUrlOptions, PlainConfig, PropertiesConfig, PropertyChangeType, Request };