@obelisk/client
Version:
Typescript client to interact with Obelisk on a higher level than the regular ReST API calls.
187 lines (186 loc) • 5.33 kB
TypeScript
import { Observable, Observer } from 'rxjs';
import { Endpoint, GraphQLEndpoint, StreamEndpoint, TPageEndpoint } from './api';
import { Token, Tokens } from './auth';
import { ApiVersion, Client, ClientEvent, ClientOptions } from './interfaces';
/**
* The ObeliskClient is the main entrypoint for using the library.
*/
export declare class ObeliskClient implements Client {
private readonly UMA2CONFIG_PATH;
private _events$;
private _options;
private _optionsUrl;
private _optionsObject;
private _initMode;
private _uma2Config;
private _storage;
private _tokens;
private _oauth;
private authOver$;
private _config$;
private CRED_KEY;
private useOfflineToken;
private readonly defaultOptions;
/**
* Create a new client. **You need to call init() before using it!**
* @param options The ClientOptions object containing all setup configuration
* @param eventObserver Optionally you can add an observer that listens to the ClientEvents from the very start.
*/
constructor(optionsObjectOrUrl: ClientOptions | string, eventObserver?: Observer<ClientEvent>);
private getConfig;
/**
* @inheritdoc
*/
init(): Observable<boolean>;
/**
* @inheritdoc
*/
createLogoutUrl(redirectUri?: string): string;
/**
* @inheritdoc
*/
createLoginUrl(loginOptions?: {
redirectUri?: string;
prompt?: 'none' | 'login';
offline_access?: boolean;
}): string;
private storeClientCredentials;
private loadClientCredentials;
/**
* Client credentials will be cleared from Session storage, if they were present
*/
clearClientCredentials(): void;
/**
* @inheritdoc
*/
loginAsClient(clientId: string, clientSecret: string): Observable<Token>;
/**
* @inheritdoc
*/
login(loginOptions?: {
redirectUri?: string;
prompt?: 'none' | 'login';
offline_access?: boolean;
}): void;
/**
* @inheritdoc
*/
logout(redirectUri?: string): void;
/**
* @inheritdoc
*/
temporalPageEndpoint(uri: string, apiVersion?: ApiVersion): TPageEndpoint;
/**
* @inheritdoc
* */
endpoint(uri: string, apiVersion?: ApiVersion): Endpoint;
/**
* @inheritdoc
*/
streamEndpoint(uri: string, apiVersion?: ApiVersion): StreamEndpoint;
/**
* @inheritdoc
*/
graphQLEndpoint(): GraphQLEndpoint;
/**
* @inheritdoc
* */
rawEndpoint(uri: string, apiVersion?: ApiVersion): Endpoint;
/**
* @inheritdoc
*/
isLoggedIn(): boolean;
/**
* @inheritdoc
*/
rptHasRole(role: string, targetClientId?: string): boolean;
/**
* Check authenticated status in cookies. If loggedIn and no PAT token present, try to login silently.
*/
private isAuthenticated;
/**
* Clears all tokens. Including session storage client credentials.
*/
private clearTokens;
/**
* Checks whether the init function has been called yet.
*/
private checkInit;
/**
* Requests the Uma2 config from the wellknown url.
*/
private getUma2Config;
private updateLogInfo;
private storeTokens;
/**
* Checks a full url for a hash that can be parsed to a TokenResponse.
* @param url Full url with hash
*/
private checkHashForLogin;
/**
* Removes last slash if present
* @param uri
*/
private normalizeRedirectUri;
/**
* @hidden
* TODO: Schedules a token refresh WITHIN the expiry date timeframe. Useful for implicit token refreshes.
* @param pat
* @param patRefresh
*/
/**
* @inheritdoc
*/
keepSessionAlive(leeway?: number): Observable<boolean>;
/**
* Internal call that defers execution of refresh logic until RPT expires (- minus some leeway in ms)
* @param leeway The leeway in ms (default to 3000ms)
*/
private scheduleRefreshRpt;
/**
* Only for refreshing the PAT token. **Only meant for some specific cases**
*/
refreshPatToken(): Observable<boolean>;
/**
* Only for refreshing the RPT token. **Only meant for some specific cases**
*/
refreshRptToken(): Observable<boolean>;
/**
* @inheritdoc
**/
getNewRpt(ticket?: string): Observable<Token>;
/**
* Generates a new nonce and stores it in storage.
*/
private generateNonce;
/**
* Checks whether the given nonce matches the last generated one.
* @param nonce Nonce to check
*/
private isNonceValid;
/**
* Generates a new state and stores it in storage
*/
private generateState;
/**
* Checks whether the given state matches the last generated one.
* @param state State to check
*/
private isStateValid;
/**
* @inheritdoc
*/
get options(): ClientOptions;
/**
* @inheritdoc
*/
get tokens(): Tokens;
/**
* @inheritdoc
*/
get events(): Observable<ClientEvent>;
/**
* @inheritdoc
*/
get isAuthReady$(): Observable<void>;
}