@block-auth.io/blockauth-sdk
Version:
Block-Auth Auth SDK is a SaaS service blockchain based authentication service. It provides a simple and secure way to authenticate users in your application.
277 lines (276 loc) • 6.9 kB
TypeScript
/**
* This class allow you to use WebSocket API
* for Block-Auth service
*
* @class WsClient
* @param reconnect - Allow to automatically reconnect
* to the WebSocket API
* @returns WsClient
* @example
*
* import { WsClient } from '@blockauth/sdk'
* const client = new WsClient()
* await client.connect()
*
*/
declare class WsClient {
private _wsUrl;
private _wsConfig;
private _uiConfig;
private _ws;
private _accessToken;
private _refreshToken;
private _user;
private _users;
private _roles;
private _logs;
private _kycIssuerByAddress;
constructor(url?: string, reconnect?: boolean);
/**
* Check if the WebSocket API is connected
* to Block-Auth service
* @returns boolean
*/
isConnected(): any;
/**
* Allow you to connect to the WebSocket API
* for Block-Auth service
* @param waitMs - time to wait for connection ready
* @returns Promise<void>
*/
connect(url?: string, waitMs?: number): Promise<void>;
/**
* Allow you to subscribe to an event, and
* verify if the event is already subscribed
* for Block-Auth service
* @param event - Event name
* @param callback - Callback function
* @returns void
*/
on(event: string, callback: Function): void;
/**
* Allow you to unsubscribe to an event, and
* verify if the event is already unsubscribed
* for Block-Auth service
* @param event - Event name
* @param callback - Callback function
* @returns void
*/
off(event: string, callback: Function): void;
/**
* Allow you to emit an event, and
* verify if the event is already emitted
* for Block-Auth service
* @param event - Event name
* @param data - Data to send
* @returns void
*/
emit(event: string, data: any): void;
/**
* Allow you to close the connection
* to the WebSocket API for Block-Auth service
* @returns void
*/
close(): void;
/**
* Event fired when the WebSocket API
* is connected to Block-Auth service
* @returns void
*/
onConnect(): void;
/**
* Event fired when the WebSocket API
* got an error on reconnection to Block-Auth service
*/
onReconnectError(err: any): void;
/**
* Event fired when the WebSocket API
* try to reconnect to Block-Auth service
* @param attempt - Number of attempt
*/
onReconnectAttempt(attempt: number): void;
/**
* Event fired when the WebSocket API
* need to signin to Block-Auth service
* @param data - Data received from Block-Auth service
* @returns void
* @example
* ```typescript
* {
* success: true,
* message: {
* accessToken
* refreshToken
* }
* }
* ```
* */
onSdkSignin(data: any): any;
/**
* Event fired when the WebSocket API
* need to refresh the signin to Block-Auth service
* @param data - Data received from Block-Auth service
* @returns void
* @example
* ```typescript
* {
* "success": true,
* "message": {
* accessToken
* refreshToken
* }
* }
* ```
* */
onSdkRefresh(data: any): void;
/**
* Event fired when the WebSocket API
* need to check if an address is signed for
* current APP at this current time
* @param data - Data received from Block-Auth service
* @returns void
* @example
* ```typescript
* {
"success": false,
"message": "User not signed in APP yet"
}
* ```
* */
onSdkSign(data: any): void;
/**
* Event fired when the WebSocket API
* need to get APP config from Block-Auth service
* @param data - Data received from Block-Auth service
* @returns void
* @example
* ```typescript
* {
"success": true,
"message": {
"domain": "example.com",
"config": { ... }
}
}
* ```
* */
onSdkApp(data: any): void;
/**
* Event fired when the WebSocket API
* need to get APP user from Block-Auth service
* @param data - Data received from Block-Auth service
* @returns void
* @example
* ```typescript
* {
"success": true,
"message": {
"items": [ {
...profileProperties
"did": "did:564",
"address": "0x564",
} ],
}
}
* ```
* */
onSdkUser(data: any): void;
/**
* Event fired when the WebSocket API
* need to get APP users from Block-Auth service
* @param data - Data received from Block-Auth service
* @returns void
* @example
* ```typescript
* {
"success": true,
"message": {
"pages": 1,
"items": [ ... ],
"total": 1,
}
}
* ```
* */
onSdkUsers(data: any): void;
/**
* Event fired when the WebSocket API
* need to get APP roles from Block-Auth service
* @param data - Data received from Block-Auth service
* @returns void
* @example
* ```typescript
* {
"success": true,
"message": {
"pages": 1,
"items": [ ... ],
"total": 1,
}
}
* ```
* */
onSdkRoles(data: any): void;
/**
* Event fired when the WebSocket API
* need to get APP logs from Block-Auth service
* @param data - Data received from Block-Auth service
* @returns void
* @example
* ```typescript
* {
"success": true,
"message": {
"pages": 1,
"items": [ ... ],
"total": 1,
}
}
* ```
* */
onSdkLogs(data: any): void;
onSdkKycIssuer(data: any): void;
/**
* Event fired when the WebSocket API
* is disconnected from Block-Auth service
*/
onDisconnect(reason: string): void;
/**
* Get SocketIO instance
*/
get ws(): any;
/**
* Get WebSocket access token
*/
get accessToken(): string;
/**
* Get WebSocket refresh token
*/
get refreshToken(): string;
/**
* Get WebSocket APP config
*/
get uiConfig(): any;
/**
* Get WebSocket APP user
*/
get user(): any;
/**
* Get WebSocket APP users
*/
get users(): any[];
/**
* Get WebSocket APP roles
*/
get roles(): any[];
/**
* Get WebSocket APP logs
*/
get logs(): any[];
/**
* Get WebSocket APP issuer for an address
* if module KYC is enabled
*/
get kycIssuerByAddress(): any;
}
export { WsClient };