@morabr/mora-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ export { MoraSDK } from './sdk';
2
+ export * from './api/api';
3
+ export * from './interfaces';
@@ -0,0 +1,22 @@
1
+ import { SigninDto } from './api/api';
2
+ export interface SDKOptions {
3
+ baseURL: string;
4
+ autoRefresh?: boolean;
5
+ tokenExpireOffset?: number;
6
+ }
7
+ export type ApiSecurityDataType = {
8
+ bearer: string;
9
+ };
10
+ export type SDKEvents = {
11
+ connecting: void;
12
+ connected: void;
13
+ authChanged: {
14
+ authToken: string;
15
+ refreshToken: string;
16
+ };
17
+ };
18
+ export interface AuthenticatedCredential {
19
+ authToken: string;
20
+ refreshToken: string;
21
+ }
22
+ export type AuthCredential = SigninDto | AuthenticatedCredential;
@@ -0,0 +1,45 @@
1
+ /// <reference types="node" />
2
+ import { SDKOptions, ApiSecurityDataType, SDKEvents, AuthCredential } from './interfaces';
3
+ import { JwtPayload } from 'jwt-decode';
4
+ import { Api, SigninDto } from './api/api';
5
+ import { Emitter } from 'mitt';
6
+ export declare class MoraSDK {
7
+ api: Api<ApiSecurityDataType>;
8
+ protected authToken: string;
9
+ protected authTokenDecoded: JwtPayload | undefined;
10
+ protected refreshTokenDecoded: JwtPayload | undefined;
11
+ protected refreshToken: string;
12
+ protected options: SDKOptions;
13
+ protected autoRefreshTimer: NodeJS.Timeout | undefined;
14
+ protected signInCredential: SigninDto | undefined;
15
+ emitter: Emitter<SDKEvents>;
16
+ protected defaultOptions: Partial<SDKOptions>;
17
+ constructor(options: SDKOptions);
18
+ enableAutoRefresh(force?: boolean): void;
19
+ disableAutoRefresh(): void;
20
+ private hookTimer;
21
+ private hookInterceptors;
22
+ clearTokens(): void;
23
+ authenticate(credential: AuthCredential, opts?: {
24
+ avoidEvents?: boolean;
25
+ }): Promise<void>;
26
+ reAuthenticate(opts?: {
27
+ throwError?: boolean;
28
+ }): Promise<void>;
29
+ isAuthenticated(): boolean;
30
+ protected setAuthToken(token: string): void;
31
+ triggerRefreshToken(): Promise<void>;
32
+ isTokenExpired(): boolean;
33
+ getAuthToken(): string;
34
+ protected setRefreshToken(refreshToken: string): void;
35
+ getRefreshToken(): string;
36
+ refreshTokens(opts?: {
37
+ throwError?: boolean;
38
+ }): Promise<void>;
39
+ private authenticateAsUser;
40
+ private authenticateAsToken;
41
+ private setTokens;
42
+ getAuthTokenDecoded(): JwtPayload | undefined;
43
+ getRefreshTokenDecoded(): JwtPayload | undefined;
44
+ static decodeToken(token: string): JwtPayload | undefined;
45
+ }