haystack-nclient
Version:
Project Haystack Network Client
201 lines (200 loc) • 6.71 kB
TypeScript
import { HNamespace, HVal, HaysonVal } from 'haystack-core';
import { getOpUrlCallback, getHaystackServiceUrlCallback, getHostServiceUrlCallback, getServiceUrlCallback } from '../util/http';
import { RecordService } from './RecordService';
import { ClientServiceConfig } from './ClientServiceConfig';
import { OpsService } from './OpsService';
import { ExtOpsService } from './ExtOpsService';
import { ScheduleService } from './schedules/ScheduleService';
import { FetchMethod } from './fetchVal';
import { WatchService } from './watches/WatchService';
import { UserService } from './UserService';
import { ProjectService } from './ProjectService';
import { GroupsService } from './groups/GroupService';
import { RolesService } from './roles/RolesService';
import { NotificationService } from './notifications/NotificationService';
import { NotificationSettingsService } from './notifications/NotificationSettingService';
import { FunctionService } from './functions/FunctionService';
/**
* A high level Haystack Client
*/
export declare class Client implements ClientServiceConfig {
#private;
/**
* The origin of the client.
*/
readonly origin: string;
/**
* The project associated with this client.
*/
readonly project: string;
/**
* Is the optional path that is appended to the client origin url
*/
readonly pathPrefix: string;
/**
* The defs associated with the client.
*/
defs: HNamespace;
/**
* The ops service.
*/
readonly ops: OpsService;
/**
* The extended ops service.
*/
readonly ext: ExtOpsService;
/**
* The record service.
*/
readonly record: RecordService;
/**
* The schedule service.
*/
readonly schedule: ScheduleService;
/**
* The watch service.
*/
readonly watch: WatchService;
/**
* The user service.
*/
readonly user: UserService;
/**
* The user groups service
*/
readonly groups: GroupsService;
/**
* The user roles service
*/
readonly roles: RolesService;
/**
* The project service.
*/
readonly proj: ProjectService;
/**
* The notifications service.
*/
readonly notifications: NotificationService;
/**
* The notifications settings service.
*/
readonly notificationsSettings: NotificationSettingsService;
/**
* The functions service
*/
readonly functions: FunctionService;
/**
* The `fetch` function to use for network communication.
*/
readonly fetch: FetchMethod;
/**
* Constructs a new client.
*
* @param options.base The base URL.
* @param options.project An optional project name. Defaults to 'sys'.
* @param options.defs An optional instance of defs. If specified, the client will
* be set to an intialized state.
* @param options.options An optional set of fetch `options` to use with every request
* sent from this client.
* @param options.authBearer An optional bearer token that will be added to every request sent using
* this client. This will add/overwrite any existing `Authorization` header already
* added to the `options`.
* @param options.fetch An optional fetch function to use for all network requests. If not specified
* the FIN CSRF fetch will be used.
* @param options.pathPrefix The optional path to be appended to the base URL when making certain requests.
* @param options.getOpsUrl Optional function that returns the ops URL to use.
* @param options.getHaystackServiceUrl Optional function that returns the haystack service URL to use.
* @param options.getHostServiceUrl Optional function that returns the host service URL to use.
*/
constructor({ base, project, defs, options, authBearer, fetch, getServiceUrl, getOpUrl, getHaystackServiceUrl, getHostServiceUrl, pathPrefix, }: {
base: URL;
project?: string;
defs?: HNamespace;
options?: RequestInit;
authBearer?: string;
fetch?: FetchMethod;
getServiceUrl?: getServiceUrlCallback;
getOpUrl?: getOpUrlCallback;
getHaystackServiceUrl?: getHaystackServiceUrlCallback;
getHostServiceUrl?: getHostServiceUrlCallback;
pathPrefix?: string;
});
private static parseProjectFromFinMobile;
private static parseProjectFromApi;
private static parseProjectFromProjects;
/**
* Returns the origin API Url
*
* @param path Name of the API
* @returns A URL.
*/
getServiceUrl(path: string): string;
/**
* Returns the URL for an op.
*
* @param op The op to create the URL for.
* @returns A URL.
*/
getOpUrl(op: string): string;
/**
* Returns the URL for a haystack service.
*
* @param path The path of the service.
* @returns A URL.
*/
getHaystackServiceUrl(service: string): string;
/**
* Returns the URL for a host service.
*
* @param path The path of the service.
* @returns A URL.
*/
getHostServiceUrl(path: string): string;
/**
* @returns The default options to used with a fetch operation.
*/
getDefaultOptions(): RequestInit;
/**
* Asynchronously load the defs library using this service.
*
* Please note, this will overwrite any existing defs loaded.
*
* @returns A promise that's resolved once the defs have been loaded.
*/
loadDefs(): Promise<void>;
/**
* @returns True if the defs have been loaded using this service.
*/
isDefsLoaded(): boolean;
/**
* @returns A promise that resolves to the service's defs.
*/
private requestDefs;
/**
* @returns A JSON object of the Client that uniquely identifies it.
*/
toJSON(): {
opUrl: string;
haystackServiceUrl: string;
hostServiceUrl: string;
project: string;
pathPrefix: string;
};
/**
* Fetch a haystack value from the server.
*
* @param resource The resource to request.
* @param body Optional haystack value used for the request's body.
* @param options Optional object containing any custom settings.
* @returns A promise that resolves to a value.
* @throws A fetch or grid error.
*/
fetchVal<T extends HVal>(resource: RequestInfo, body?: HVal | HaysonVal, options?: RequestInit): Promise<T>;
/**
* Closes the client.
*
* Warning: this will close any watches associated with this client. Any
* watches may throw an error if they are used after being closed.
*/
close(): Promise<void>;
}