import { Subject, Observable } from 'rxjs'; import { VasatAPIResponse, VasatConfig, VasatStorage } from './types'; import { Device, DeviceMeta } from './device'; import { ChunkedFileUploaderConfig, UploaderHandle } from './chunked_upload'; export interface GUIDModel { GUID(): string; GUID_FIELD_NAME(): string; } export type VasatModelClass> = { new (vasat: VasatConnection, s?: any, args?: any): T; }; export interface HttpOptions { requestParams?: { [key: string]: string; }; requestheaders?: { [key: string]: string; }; } export interface SaveOptions extends HttpOptions { delta?: any; forcePost?: boolean; returnObject?: boolean; } export interface PatchOptions extends HttpOptions { returnObject?: boolean; } export interface FetchOptions extends HttpOptions { } export interface VasatSession { user?: any; device: Device; access_token: string; expires_by: number; refresh_token?: string; media_token?: string; } export interface VasatConnection { config: VasatConfig; storage?: VasatStorage; pathPrefix?: string; token?: string; mediaToken?: string; get authPrefix(): string; /** * identifier the the combination of the client & host used by this Vasat config. * Use primarily for the localStorage key when localSotrage is being used for session information. */ clientKey(): string; /** * @deprecated Subjective definition of what 'ready' use your own logic to decide */ onReady(): Observable; sessionObservable(fire: Boolean): Observable; localSession(): VasatSession | undefined; invalidateSession(): void; /** * invalidiate caches used by search queries with .useCache(true) or manual registerCache() calls. */ invalidateCache(): void; /** * value of the session token */ authToken(): string; /** * update the stored session information */ saveLocalSession(obj: VasatSession): void; /** * Returns true if there is a valid sesison */ hasSession(): boolean; /** * * @param username username to be used * @param password password to be used * @param email email to be used * @param userMeta user represetation (dependant on the server side representation of a user) * @param byoClientId override the default clientId */ signup(username: string, password: string, email?: string, userMeta?: any, byoClientId?: string): Observable; /** * Login to server with username/password * @param user * @param pass */ loginWithUsername(user: string, pass: string): Observable; /** * login with the client credentials specified in the VasatConfig */ loginWithClientCredentials(): Observable; /** * @param remoteClientId * @param remoteClientToken * @deprecated - generic OAuth should be used with server side logic deteriming the redirect */ loginWithClientFacebook(remoteClientId: string, remoteClientToken: string): Observable; registerPushRegId(regId: string): Observable; resetPasswordRequest(email: string): Observable; resetPasswordTokenCheck(token: string): Observable>; resetPassword(token: string, newPassword: string): Observable>; requestForgetPassword(email: string): Observable; /** * @deprecated use logout */ logoutObservable(): Observable; /** * Logout and invalidate session */ logout(): Observable; /** * fetch and return the active user from the server */ refreshMeUser(): Observable>; /** * Call specified api endpoint. Function provides authentication with the active session. And reads result in the .payload encapsulation of a response. * @param url path to call (if not absolute, assuing the host vasat server) eg '/api/MyEndpoint?arg=1' * @param meth post put get patch * @param args objected to be sent in the request */ api(url: string, meth?: string, args?: any): Observable; _http(meth: string, url: string, obj: any, args?: any): Observable; /** * Observable of the redirect URL to be sent to when using a remote OAuth to login. * This is used in the OAuth authorization_code method of authentication. * @param client the REMOTE Client id * @param redirectUrl url to be redreicted to once Login is complete * @param state state as per OAuth standard, value 'vasat' is used if none specified, highly recommended random value supplied. */ loginViaOAuthUrl(client: string, redirectUrl: string, state?: string): Observable; /** * The second step of the OAuth authorization_code method, where the code is exchanged for a token and working session. * If there is no checks needed about a users state being signup or login, pass this method directly into #completeRemoteOAuthSignup. * Otherwise prompt user for any subsequent details before calling #completeRemoteOAuthSignup * * @param client id of the LOCAL client * @param code code as returned by the remote auth agent * @param redirectUrl same redirect as step 1 */ loginRemoteOAuthCode(client: string, code: string, redirectUrl: string): Observable>; /** * Final step to exchange codes and obtain a session. This step is to be called after #loginRemoteOAuthCode. * The need for this to be a didcated step is to allow detection of a remote login's state on this server being a first time signup or a repeat login. * This also allows a first time signup to be prompted for more information before the Vasat server-sdie user is initialised. * eg: needing to have a UI to agree to terms of site on the first time they sign in. * * @param sr signupRequest as returned by #loginRemoteOAuthCode * @param user metadata of the user and any other information needed by any custom server side signup process. */ completeRemoteOAuthSignup(sr: RemoteOAuthResponse, user: any): Observable; registerCacheClass>(obj: VasatModelClass | string, items: T[], overrideExisting?: boolean): void; findCached>(obj: VasatModelClass | string, id: number | ((v: T) => boolean)): T | undefined; findCachedClass>(obj: string): VasatModelClass; getCached>(obj: VasatModelClass | string): T[]; filterCached>(obj: VasatModelClass | string, id: number | ((v: T) => boolean)): T[]; registeredClassForString(key: string): VasatModelClass; registerClass>(obj: VasatModelClass): void; /** * The base method to search for all items of a specific VasatModel type. * @param v class defintion of VasatModel */ searchByObject>(v: VasatModelClass): VasatSearchQuery; /** * The base method to search for all items of a specific ServerSide type. Without declaring a client side VasatModel class. * Results will be a wrapper implmentation of VasatModel * @param obj the server side Model name of the type being searched. */ searchByObjectString>(obj: string): VasatSearchQuery; searchByObjectStringAndDomain>(domain: string, obj: string): VasatSearchQuery; modelPathPrefix(m: VasatModel): string; registerPathPrefix(m: VasatModelClass, prefix: string): void; /** * Register a url prefix for an entrie domain * @param domain domain name * @param prefix prefix or full url */ registerDomainPrefix(domain: string, prefix: string): void; deviceMeta(): DeviceMeta; /** * Attempt to refresh the vasat token with the vasat object's obtained refresh token */ refreshToken(): Observable; } export declare class VasatAPICall { _error?: any; _loading: boolean; _deleted: boolean; _modelPath?: string; apiObservable(vasat: VasatConnection, meth: string, url: string, obj?: any, args?: any): Observable; protected processResp(vasat: VasatConnection, meth: string, url: string, resp: VasatAPIResponse, obj?: any, args?: any): Observable; postProcess(meth: string, url: string, resp: VasatAPIResponse, obj?: any, args?: any): Observable; } export declare const VASAT_MODEL_SYSTEM_FIELDS: string[]; export declare const VASAT_MODEL_SYSTEM_OBJECTS: string[]; export declare class VasatModel> extends VasatAPICall { vasat: VasatConnection; protected _objType: string; id?: string; name?: string; displayName?: string; active?: boolean; dateMade?: Date; dateUpdated?: Date; acl?: string[]; paths?: string[]; loading?: Observable; props: any; _domainName?: string; _hash?: string; _saveReturnResponse: boolean; [key: string]: any; get files(): VasatSearchQuery; constructor(vasat: VasatConnection, _objType: string, vars?: any); setVals(vars: any): void; /** * @deprecated Subjective definition of what 'ready' use your own logic to decide */ onReady(): Observable; /** * Sets the returned ID to this object. * Special case for MeUser is to set the response object as the api will returned the entire User object * @param args * @returns */ set(args: any): T; /** * Root path for model * @returns root of the model eg /api/v2/Article */ urlRoot(): string; /** * Root path for object * @returns root of the model eg /api/v2/Article/1234 */ urlPath(): string; fetch(opts?: FetchOptions): Observable; patch(delta: any, opts?: PatchOptions): Observable; save(saveOpts?: SaveOptions): Observable; delete(params?: string): Observable; processResp(vasat: VasatConnection, meth: string, url: string, resp: VasatAPIResponse, obj?: any, args?: any): Observable>; postSet(objs: any, scope?: any): Observable; toJSON(shallow?: boolean): any; _toJSON(the_obj: any, depth: number, refMap: any[]): any; /** * @deprecated renamed to fileUrl */ file(fileName: string, cache?: boolean, withMediaToken?: boolean): string; fileUrl(fn: string, cache?: boolean, withMediaToken?: boolean): string; rootPath(): string; domainName(): string | undefined; className(): string; sendFile(f: File, name?: string, config?: ChunkedFileUploaderConfig): UploaderHandle; deleteFile(name: string): Observable; } export declare class VasatAccessModel> extends VasatModel { } export interface SearchQueryOp { eq?: any; in?: any[]; like?: any; gt?: number; lt?: number; ge?: number; le?: number; } export interface SearchQueryNode { and?: SearchQueryNode[]; or?: SearchQueryNode[]; not?: SearchQueryNode; [columnName: string]: SearchQueryOp | SearchQueryNode[] | SearchQueryNode | undefined; } /** * Vasat Search query builder. Users to search for a list of objects of a particular type */ export declare class VasatSearchQuery> extends VasatAPICall { protected clazz: VasatModelClass; protected vasat: VasatConnection; protected searchUrl?: string | undefined; queryParams: any; private _useCache?; constructor(clazz: VasatModelClass, vasat: VasatConnection, searchUrl?: string | undefined); _castToString(v: any): string; /** * search for column being null * @param column column name * @returns */ isNull(column: string): this; /** * search for column being non null * @param column column name * @returns */ isNotNull(column: string): this; /** * search using a complex query, all simple queires are ignored if this is used * @param value complex quesy * @returns */ complexQuery(value: SearchQueryNode): this; /** * Column being equal to value * @param column column name * @param value value * @returns */ equals(column: string, value: any): this; /** * Column being equal to any value in list * @param column column name * @param value value array * @returns */ equalsAny(column: string, value: any[]): this; /** * Column containing string (case insensitive) * @param column column name * @param value value * @returns */ contains(column: string, value: any): this; greaterThan(column: string, value: any): this; lessThan(column: string, value: any): this; notEquals(column: string, value: any): this; notContains(column: string, value: any): this; notGreaterThan(column: string, value: any): this; notLessThan(column: string, value: any): this; /** * Column to sort by * @param column * @param descend set to true if you want decending order * @returns */ sortBy(column: string, descend?: boolean): this; /** * Limit number of rows. returned. If not set there it typically a server side limit. * @param limit * @returns */ limit(limit: number): this; /** * number of records to skip when returning results * @param offset * @returns */ offset(offset: number): this; /** * For backend implmentations that have returned a contiuation token to fetch more. * @param continuationToken * @returns */ continuation(continuationToken: string): this; /** * Query params to add to the URL * @param params */ addQueryParams(params: any): void; query(): Observable>; /** * @deprecated renamed. use query instead */ queryObservable(): Observable>; queryObservableBYO(searchRes: SearchResults): Observable>; /** * * @deprecated should call obj.delete().subscribe() * @param obj */ remove(obj: T): void; /** * * @deprecated should call obj.delete().subscribe() * @param obj */ removeObservable(obj: T): Observable; /** * Will use caching and keep results in memory, this is useful for when using @AsClass() referecnes. * @param cache * @returns */ useCache(cache: boolean): this; protected _resSubject: Subject; items: Observable; protected resultCache: T[]; protected _query(returnObservable: boolean, searchRes?: SearchResults): any; postProcess(meth: string, url: string, resp: any, postObj?: any, args?: any): Observable; } export declare class SearchResults> { private clazz; private resp; private query; queryObj: VasatSearchQuery; items: T[]; private vasat; pages: number; total: number; offset: number; _currentPage: number; pageUpdate: Subject; continuation?: string; currentContinuation?: string; constructor(clazz: VasatModelClass, resp: VasatAPIResponse, query: any, queryObj: VasatSearchQuery, limit: number, items: T[], vasat: VasatConnection); setFromResponse(resp: VasatAPIResponse, limit: number): void; get limit(): number; get sortBy(): any; get sortDown(): boolean; get currentPageP1(): number; set currentPageP1(p: number); get currentPage(): number; set sortBy(s: any); set limit(s: number); set sortDown(s: boolean); set currentPage(p: number); refresh(): void; } export declare class ToManyList> extends VasatSearchQuery { private parent; private name; constructor(clazz: VasatModelClass, parent: VasatModel, name: string); _updateURL(): void; _query(returnObservable: boolean, searchRes?: SearchResults): any; /** * @deprecated Renamed to add() */ addObserveable(obj: T): Observable; add(adds: T | T[]): Observable; /** * * @deprecated Use remove() instead */ removeObservable(obj: T | T[]): Observable; remove(removes: T | T[]): Observable; } export declare class FileRef extends VasatModel { length: number; fileMade: number; contentType?: string; remoteId?: string; meta?: any; progress?: { total: number; chunkSize: number; seq: number; offset: number; }; urlPath(): string; } export declare class HistoricRecord extends VasatModel { hash: string; client?: string; event?: string; ipaddress?: string; objectType: string; record?: any; recordID?: string; user?: string; constructor(vasat: VasatConnection); } export interface RemoteOAuthResponse> { mode: 'login' | 'signup'; status: 'complete' | 'incomplete'; token?: string; user?: T; }