some api cleanup

This commit is contained in:
balzack 2025-03-02 22:31:02 -08:00
parent c5c2ec8ee8
commit 84ebd847df
4 changed files with 118 additions and 16 deletions

View File

@ -374,6 +374,111 @@ Automate allocates the Bot interface for ia specific communication channel
<br>
</details>
<details>
<summary>Focus interface module manages the topics on an activated channel</summary><br>
<ul>
The current topics can be accessed with a [Topic](https://github.com/balzack/databag/blob/sdk/app/sdk/src/types.ts) listener
```Focus::addTopicListener(ev: (arg: { topics: Topic[] | null }) => void): void```
```Focus::removeTopicListener(ev: (arg: { topics: Topic[] }) => void): void```
</ul>
<br>
</details>
<details>
<summary>Ring interface module provides access to incoming call requests</summary><br>
<ul>
The current calls can accessed with a call listener
```Ring::addRingingListener(ev: (calls: { cardId: string, callId: string }[]) => void): void```
```Ring::removeRingingListener(ev: (calls: { cardId: string, callId: string }[]) => void): void```
</ul>
<br>
</details>
<details>
<summary>Link interface module provides a proxied peer to peer link</summary><br>
<ul>
The connection status can be accessed with a status listener
```Link::addStatusListener(ev: (status: string) => Promise<void>): void```
```Link::clearStatusListener(): void```
</ul>
<br>
</details>
## Admin Communication
## Bot Communication
<details>
<summary>Service interface provides account management and server configuration</summary><br>
<ul>
Retrieve the list of account on the server
```Service::getMembers(): Promise<Member[]>```
Create a token allowing for the creation of an account when the server is private
```Service::createMemberAccess(): Promise<string>```
Create a token allowing for access to an account without password
```Service::resetMemberAccess(): Promise<string>```
Enable or disable specified account on the server
```Service::blockMember(memberId: number, blocked: boolean): Promise<void>```
Delete specified account from the server
```Service::removeMember(memberId: number): Promise<void>```
Retrieve current server configuration
```Service::getSetup(): Promise<Setup>```
Update the server configuration
```Service::getSetup(): Promise<Setup>```
Check if multi-factor authentication is enabled for admin access
```Service::checkMFAuth(): Promise<boolean>```
Retrieve mutli-factor authentication values to be confirmed
```Service::enableMFAuth(): Promise<{ image: string, text: string }>```
Confirm multi-factor authentication values to complete the enable process
```Service::confirmMFAuth(code: string): Promise<void>```
Disable multi-factor auth for admin access
```Service::disableMFAuth(): Promise<void>```
</ul>
<br>
</details>

View File

@ -41,18 +41,18 @@ export class DatabagSDK {
}
public async initOfflineStore(sql: SqlStore): Promise<Session | null> {
const { articleTypes, channelTypes } = this.params;
const { channelTypes } = this.params;
this.store = new OfflineStore(this.log, sql);
await this.staging?.clear();
const login = await this.store.init();
return login ? new SessionModule(this.store, this.crypto, this.log, this.staging, login.guid, login.token, login.node, login.secure, login.timestamp, articleTypes, channelTypes) : null;
return login ? new SessionModule(this.store, this.crypto, this.log, this.staging, login.guid, login.token, login.node, login.secure, login.timestamp, channelTypes) : null;
}
public async initOnlineStore(web: WebStore): Promise<Session | null> {
const { articleTypes, channelTypes } = this.params;
const { channelTypes } = this.params;
this.store = new OnlineStore(this.log, web);
const login = await this.store.init();
return login ? new SessionModule(this.store, this.crypto, this.log, this.staging, login.guid, login.token, login.node, login.secure, login.timestamp, articleTypes, channelTypes) : null;
return login ? new SessionModule(this.store, this.crypto, this.log, this.staging, login.guid, login.token, login.node, login.secure, login.timestamp, channelTypes) : null;
}
public async available(node: string, secure: boolean): Promise<number> {
@ -64,7 +64,7 @@ export class DatabagSDK {
}
public async login(handle: string, password: string, node: string, secure: boolean, mfaCode: string | null, params: SessionParams): Promise<Session> {
const { articleTypes, channelTypes } = this.params;
const { channelTypes } = this.params;
const { appName, version, deviceId, deviceToken, pushType, notifications } = params;
const { guid, appToken, created, pushSupported } = await setLogin(node, secure, handle, password, mfaCode, appName, version, deviceId, deviceToken, pushType, notifications);
const login: Login = {
@ -76,11 +76,11 @@ export class DatabagSDK {
pushSupported,
};
await this.store.setLogin(login);
return new SessionModule(this.store, this.crypto, this.log, this.staging, guid, appToken, node, secure, created, articleTypes, channelTypes);
return new SessionModule(this.store, this.crypto, this.log, this.staging, guid, appToken, node, secure, created, channelTypes);
}
public async access(node: string, secure: boolean, token: string, params: SessionParams): Promise<Session> {
const { articleTypes, channelTypes } = this.params;
const { channelTypes } = this.params;
const { appName, version, deviceId, deviceToken, pushType, notifications } = params;
const { guid, appToken, created, pushSupported } = await setAccess(node, secure, token, appName, version, deviceId, deviceToken, pushType, notifications);
const login: Login = {
@ -92,11 +92,11 @@ export class DatabagSDK {
pushSupported,
};
await this.store.setLogin(login);
return new SessionModule(this.store, this.crypto, this.log, this.staging, guid, appToken, node, secure, created, articleTypes, channelTypes);
return new SessionModule(this.store, this.crypto, this.log, this.staging, guid, appToken, node, secure, created, channelTypes);
}
public async create(handle: string, password: string, node: string, secure: boolean, token: string | null, params: SessionParams): Promise<Session> {
const { articleTypes, channelTypes } = this.params;
const { channelTypes } = this.params;
await addAccount(node, secure, handle, password, token);
const { appName, version, deviceId, deviceToken, pushType, notifications } = params;
const { guid, appToken, created, pushSupported } = await setLogin(node, secure, handle, password, null, appName, version, deviceId, deviceToken, pushType, notifications);
@ -109,7 +109,7 @@ export class DatabagSDK {
pushSupported,
};
await this.store.setLogin(login);
return new SessionModule(this.store, this.crypto, this.log, this.staging, guid, appToken, node, secure, created, articleTypes, channelTypes);
return new SessionModule(this.store, this.crypto, this.log, this.staging, guid, appToken, node, secure, created, channelTypes);
}
public async remove(session: Session): Promise<void> {

View File

@ -44,7 +44,7 @@ export class SessionModule implements Session {
private channelTypes: string[];
private articleTypes: string[];
constructor(store: Store, crypto: Crypto | null, log: Logging, staging: Staging | null, guid: string, token: string, node: string, secure: boolean, loginTimestamp: number, articleTypes: string[], channelTypes: string[]) {
constructor(store: Store, crypto: Crypto | null, log: Logging, staging: Staging | null, guid: string, token: string, node: string, secure: boolean, loginTimestamp: number, channelTypes: string[]) {
log.info('new databag session');
this.store = store;
@ -56,7 +56,7 @@ export class SessionModule implements Session {
this.node = node;
this.secure = secure;
this.channelTypes = channelTypes;
this.articleTypes = articleTypes;
this.articleTypes = [];
this.loginTimestamp = loginTimestamp;
this.status = 'connecting';
this.emitter = new EventEmitter();

View File

@ -251,9 +251,6 @@ export type Setup = {
};
export type Params = {
topicBatch: number;
tagBatch: number;
articleTypes: string[];
channelTypes: string[];
};