mirror of
https://github.com/balzack/databag.git
synced 2025-04-23 10:05:19 +00:00
adding bot interface
This commit is contained in:
parent
10b17afe97
commit
29ddcbe88f
@ -2,8 +2,10 @@
|
||||
// remove viewRevision
|
||||
// add bot api
|
||||
// formaize delete vs block remote channel
|
||||
// articles share by cards now
|
||||
|
||||
import type { Channel, Article, Group, Card, Profile, AccountStatus, NodeConfig, NodeAccount, Seal, SealKey, SignedMessage, ContactStatus, Asset, Topic } from './types';
|
||||
import type { Channel, Topic, Asset, Tag, Article, Group, Card, Profile, AccountStatus, NodeConfig, NodeAccount, Repeater } from './types';
|
||||
import type { Seal, SealKey, SignedMessage, ContactStatus } from './types';
|
||||
|
||||
export interface SqlStore {
|
||||
set(stmt: string, params: (string | number)[]): Promise<void>;
|
||||
@ -76,13 +78,16 @@ export interface Contact {
|
||||
removeChannel(cardId: string, channelId: string): Promise<void>;
|
||||
addTopic(cardId: string, channelId: string, type: string, message: string, assets: Asset[]): Promise<string>;
|
||||
removeTopic(cardId: string, channelId: string, topicId: string): Promise<void>;
|
||||
addTag(cardId: string, channelId: string, topicId: string, type: string, value: string): Promise<string>;
|
||||
removeTag(cardId: string, tagId: string): Promise<void>;
|
||||
setTopicSubject(cardId: string, channelId: string, topicId: string, type: string, subject: string): Promise<void>;
|
||||
getTopics(cardId: string, channelId: string, revision: number, count: number, begin: number, end: number): Promise<void>;
|
||||
getTopic(cardId: string, channelId: string, topicId: string): Promise<Topic>;
|
||||
resyncCard(cardId: string): Promise<void>;
|
||||
getTopicAssetUrl(cardId: string, channelId: string, topicId: string, assetId: string): string;
|
||||
getCardImageUrl(cardId: string): string;
|
||||
|
||||
addRepeaterAccess(cardId: string, channelId: string, name: string): Promise<Repeater>;
|
||||
removeRepeaterAccess(cardId: string, channelId: string, repeaterId: string): Promise<void>;
|
||||
|
||||
addCardListener(ev: (cards: Card[]) => void): void;
|
||||
removeCardListener(ev: (cards: Card[]) => void): void;
|
||||
}
|
||||
@ -123,11 +128,21 @@ export interface Content {
|
||||
addTopic(channelId: string, type: string, message: string, assets: Asset[]): Promise<string>;
|
||||
removeTopic(channelId: string, topicId: string): Promise<void>;
|
||||
setTopicSubject(channelId: string, topicId: string, type: string, subject: string): Promise<void>;
|
||||
getTopics(channelId: string, revision: number, count: number, begin: number, end: number): Promise<Topic[]>;
|
||||
getTopic(channelId: string, topicId: string): Promise<Topic>;
|
||||
addTag(channelId: string, topicId: string, type: string, value: string): Promise<string>;
|
||||
removeTag(channelId: string, topicId: string, tagId: string): Promise<void>;
|
||||
getTopicAssetUrl(channelId: string, topicId: string, assetId: string): string;
|
||||
|
||||
addRepeaterAccess(channelId: string, name: string): Promise<Repeater>;
|
||||
removeRepeaterAccess(channelId: string, repeaterId: string): Promise<void>;
|
||||
|
||||
addChannelListener(ev: (channels: Channel[]) => void): void;
|
||||
removeChannelListener(ev: (channels: Channel[]) => void): void;
|
||||
}
|
||||
|
||||
export interface Bot {
|
||||
addTopic(server: string, token: string, type: string, message: string, assets: Asset[]): Promise<string>;
|
||||
removeTopic(server: string, token: string, topicId: string): Promise<void>;
|
||||
addTag(server: string, token: string, topicId: string, type: string, value: string): Promise<string>;
|
||||
removeTag(server: string, token: string, topicId: string, tagId: string): Promise<void>;
|
||||
}
|
||||
|
||||
|
22
app/sdk/src/bot.ts
Normal file
22
app/sdk/src/bot.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { type Bot } from './api';
|
||||
import type { Asset } from './types';
|
||||
|
||||
export class BotModule implements Bot {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
public async addTopic(server: string, token: string, type: string, message: string, assets: Asset[]): Promise<string> {
|
||||
return '';
|
||||
}
|
||||
|
||||
public async removeTopic(server: string, token: string, topicId: string): Promise<void> {
|
||||
}
|
||||
|
||||
public async addTag(server: string, token: string, topicId: string, type: string, value: string): Promise<string> {
|
||||
return '';
|
||||
}
|
||||
|
||||
public async removeTag(server: string, token: string, topicId: string, tagId: string): Promise<void> {
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import { type Contact } from './api';
|
||||
import { type Card, type Topic, type SignedMessage, type ContactStatus, type Asset} from './types';
|
||||
import { type Card, type Topic, type SignedMessage, type ContactStatus, type Asset, type Repeater} from './types';
|
||||
|
||||
export class ContactModule implements Contact {
|
||||
|
||||
@ -74,11 +74,12 @@ export class ContactModule implements Contact {
|
||||
public async setTopicSubject(cardId: string, channelId: string, topicId: string, type: string, subject: string): Promise<void> {
|
||||
}
|
||||
|
||||
public async getTopics(cardId: string, channelId: string, revision: number, count: number, begin: number, end: number): Promise<void> {
|
||||
public async addTag(cardId: string, channelId: string, topicId: string, type: string, value: string): Promise<string> {
|
||||
return '';
|
||||
}
|
||||
|
||||
public async getTopic(cardId: string, channelId: string, topicId: string): Promise<Topic> {
|
||||
return {}
|
||||
public async removeTag(cardId: string, tagId: string): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
public async resyncCard(cardId: string): Promise<void> {
|
||||
@ -91,5 +92,13 @@ export class ContactModule implements Contact {
|
||||
public getCardImageUrl(cardId: string): string {
|
||||
return '';
|
||||
}
|
||||
|
||||
public async addRepeaterAccess(cardId: string, channelId: string, name: string): Promise<Repeater> {
|
||||
return { id: '', guid: '', name: '', server: '', token: '' };
|
||||
}
|
||||
|
||||
public async removeRepeaterAccess(cardId: string, channelId: string, repeaterId: string): Promise<void> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import { type Content } from './api';
|
||||
import type { Channel, Topic, Asset } from './types';
|
||||
import type { Channel, Topic, Asset, Repeater } from './types';
|
||||
|
||||
export class ContentModule implements Content {
|
||||
|
||||
@ -62,16 +62,23 @@ export class ContentModule implements Content {
|
||||
public async setTopicSubject(channelId: string, topicId: string, type: string, subject: string): Promise<void> {
|
||||
}
|
||||
|
||||
public async getTopics(channelId: string, revision: number, count: number, begin: number, end: number): Promise<Topic[]> {
|
||||
return [];
|
||||
|
||||
public async addTag(channelId: string, topicId: string, type: string, value: string): Promise<string> {
|
||||
return '';
|
||||
}
|
||||
|
||||
public async getTopic(channelId: string, topicId: string): Promise<Topic> {
|
||||
return {};
|
||||
public async removeTag(channelId: string, topicId: string, tagId: string): Promise<void> {
|
||||
}
|
||||
|
||||
public getTopicAssetUrl(channelId: string, topicId: string, assetId: string): string {
|
||||
return '';
|
||||
}
|
||||
|
||||
public async addRepeaterAccess(channelId: string, name: string): Promise<Repeater> {
|
||||
return { id: '', guid: '', name: '', server: '', token: '' };
|
||||
}
|
||||
|
||||
public async removeRepeaterAccess(channelId: string, repeaterId: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
|
172
app/sdk/src/entities.ts
Normal file
172
app/sdk/src/entities.ts
Normal file
@ -0,0 +1,172 @@
|
||||
import type { Seal } from './types';
|
||||
|
||||
export type CardEntity = {
|
||||
id: string,
|
||||
revision: number,
|
||||
data?: {
|
||||
detailRevision: number,
|
||||
profileRevision: number,
|
||||
notifiedProfile: number,
|
||||
notifiedArticle: number,
|
||||
notifiedChannel: number,
|
||||
cardDetail: {
|
||||
status: string,
|
||||
statusUpdated: number,
|
||||
token: string,
|
||||
notes: string,
|
||||
groups: [ string ]
|
||||
},
|
||||
cardProfile: {
|
||||
guid: string,
|
||||
handle: string,
|
||||
name: string,
|
||||
description: string,
|
||||
location: string,
|
||||
imageSet: boolean,
|
||||
version: string,
|
||||
node: string,
|
||||
seal: string,
|
||||
revision: number,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type ChannelEntity = {
|
||||
id: string,
|
||||
revision: number,
|
||||
data: {
|
||||
detailRevision: number,
|
||||
topicRevision: number,
|
||||
channelSummary?: {
|
||||
lastTopic: {
|
||||
guid: string,
|
||||
dataType: string,
|
||||
data: string,
|
||||
created: number,
|
||||
updated: number,
|
||||
status: string,
|
||||
transform: string
|
||||
}
|
||||
},
|
||||
channelDetail?: {
|
||||
dataType: string,
|
||||
data: string,
|
||||
created: number,
|
||||
updated: number,
|
||||
enableImage: boolean,
|
||||
enableAudio: boolean,
|
||||
enableVideo: boolean,
|
||||
enableBinary: boolean,
|
||||
contacts: {
|
||||
groups: [ string ],
|
||||
cards: [ string ],
|
||||
},
|
||||
members: {
|
||||
member: string,
|
||||
pushEnabled: boolean,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export type TopicEntity = {
|
||||
id: string,
|
||||
revision: number,
|
||||
data?: {
|
||||
detailRevision: number,
|
||||
tagRevision: number,
|
||||
topicDetail: {
|
||||
guid: string,
|
||||
dataType: string,
|
||||
data: string,
|
||||
created: number,
|
||||
updated: number,
|
||||
status: string,
|
||||
transform: string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type TagEntity = {
|
||||
id: string,
|
||||
revision: number,
|
||||
data?: {
|
||||
guid: string,
|
||||
dataType: string,
|
||||
data: string,
|
||||
created: number,
|
||||
updated: number,
|
||||
}
|
||||
}
|
||||
|
||||
export type AssetEntity = {
|
||||
assetId: string,
|
||||
transform: string,
|
||||
status: string,
|
||||
}
|
||||
|
||||
export type RepeaterEntity = {
|
||||
id: string,
|
||||
revision: number,
|
||||
data?: {
|
||||
name: string,
|
||||
token: string,
|
||||
}
|
||||
}
|
||||
|
||||
export type GroupEntity = {
|
||||
id: string,
|
||||
revision: number,
|
||||
data?: {
|
||||
dataType: string,
|
||||
data: string,
|
||||
created: number,
|
||||
updated: number,
|
||||
cards: [ string ]
|
||||
}
|
||||
}
|
||||
|
||||
export type ArticleEntity = {
|
||||
id: string,
|
||||
revision: number,
|
||||
data?: {
|
||||
dataType: string,
|
||||
data: string,
|
||||
created: number,
|
||||
updated: number,
|
||||
status: string,
|
||||
contacts?: {
|
||||
cards: [ string ],
|
||||
groups: [ string ],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type AccountEntity = {
|
||||
disabled: boolean,
|
||||
storageUsed: number,
|
||||
storageAvailable: number,
|
||||
forwardingAddress: string,
|
||||
searchable: boolean,
|
||||
allowUnsealed: boolean,
|
||||
pushEnabled: boolean,
|
||||
sealable: boolean,
|
||||
seal: Seal,
|
||||
enableIce: boolean,
|
||||
multiFactorAuth: boolean,
|
||||
webPushKey: string,
|
||||
}
|
||||
|
||||
export type ProfileEntity = {
|
||||
guid: string,
|
||||
handle: string,
|
||||
name: string,
|
||||
description: string,
|
||||
location: string,
|
||||
image: string,
|
||||
revision: number,
|
||||
seal: string,
|
||||
version: string,
|
||||
node: string,
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
import { SessionModule } from './session';
|
||||
import { NodeModule } from './node';
|
||||
import { BotModule } from './bot';
|
||||
|
||||
import { type Session, type Node, type SqlStore, type WebStore } from './api';
|
||||
import { type Session, type Node, type Bot, type SqlStore, type WebStore } from './api';
|
||||
|
||||
export class DatabagSDK {
|
||||
|
||||
@ -41,4 +42,8 @@ export class DatabagSDK {
|
||||
public async configure(token: string, url: string): Promise<Node> {
|
||||
return new NodeModule('', '');
|
||||
}
|
||||
|
||||
public async automate() {
|
||||
return new BotModule();
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ export class SessionModule implements Session {
|
||||
public contact: ContactModule;
|
||||
public alias: AliasModule;
|
||||
public attribute: AttributeModule;
|
||||
public content: ContentModule;
|
||||
public content: ContentModule;
|
||||
|
||||
constructor(store: SqlStore | WebStore | null, token: string, url: string) {
|
||||
this.store = store;
|
||||
|
@ -1,13 +1,103 @@
|
||||
export type SealKey = {
|
||||
publicKey: string,
|
||||
privateKey: string,
|
||||
export type Card = {
|
||||
id: string,
|
||||
status: string,
|
||||
statusUpdated: number,
|
||||
notes: string,
|
||||
groups: string[],
|
||||
guid: string,
|
||||
handle: string,
|
||||
name: string,
|
||||
description: string,
|
||||
location: string,
|
||||
imageSet: boolean,
|
||||
version: string,
|
||||
node: string,
|
||||
}
|
||||
|
||||
export type Seal = {
|
||||
passwordSalt: string,
|
||||
privateKeyIv: string,
|
||||
privateKeyEncrypted: string,
|
||||
publicKey: string,
|
||||
export type Channel = {
|
||||
id: string,
|
||||
guid: string,
|
||||
lastTopic: {
|
||||
guid: string,
|
||||
dataType: string,
|
||||
data: string,
|
||||
created: number,
|
||||
updated: number,
|
||||
status: string,
|
||||
transform: string
|
||||
}
|
||||
dataType: string,
|
||||
data: string,
|
||||
created: number,
|
||||
updated: number,
|
||||
enableImage: boolean,
|
||||
enableAudio: boolean,
|
||||
enableVideo: boolean,
|
||||
enableBinary: boolean,
|
||||
contacts?: {
|
||||
groups: string[],
|
||||
cards: string[],
|
||||
},
|
||||
members: {
|
||||
member: string,
|
||||
pushEnabled: boolean,
|
||||
},
|
||||
repeaters: Repeater[];
|
||||
}
|
||||
|
||||
export type Topic = {
|
||||
id: string,
|
||||
guid: string,
|
||||
dataType: string,
|
||||
data: string,
|
||||
created: number,
|
||||
updated: number,
|
||||
status: string,
|
||||
transform: string,
|
||||
tags: [ Tag ]
|
||||
}
|
||||
|
||||
export type Tag = {
|
||||
id: string,
|
||||
guid: string,
|
||||
dataType: string,
|
||||
data: string,
|
||||
created: number,
|
||||
updated: number,
|
||||
}
|
||||
|
||||
export type Asset = {
|
||||
path: string,
|
||||
fileType: string,
|
||||
}
|
||||
|
||||
export type Group = {
|
||||
id: string,
|
||||
dataType: string,
|
||||
data: string,
|
||||
created: number,
|
||||
updated: number,
|
||||
cards: [ string ]
|
||||
}
|
||||
|
||||
export type Article = {
|
||||
id: string,
|
||||
dataType: string,
|
||||
data: string,
|
||||
created: number,
|
||||
updated: number,
|
||||
contacts?: {
|
||||
cards: [ string ],
|
||||
groups: [ string ],
|
||||
}
|
||||
}
|
||||
|
||||
export type Repeater = {
|
||||
id: string,
|
||||
guid: string,
|
||||
name: string,
|
||||
token: string,
|
||||
server: string,
|
||||
}
|
||||
|
||||
export type AccountStatus = {
|
||||
@ -19,7 +109,7 @@ export type AccountStatus = {
|
||||
allowUnsealed: boolean,
|
||||
pushEnabled: boolean,
|
||||
sealable: boolean,
|
||||
seal: Seal,
|
||||
sealSet: boolean,
|
||||
enableIce: boolean,
|
||||
multiFactorAuth: boolean,
|
||||
webPushKey: string,
|
||||
@ -32,65 +122,11 @@ export type Profile = {
|
||||
description: string,
|
||||
location: string,
|
||||
image: string,
|
||||
revision: number,
|
||||
seal: string,
|
||||
sealSet: string,
|
||||
version: string,
|
||||
node: string,
|
||||
}
|
||||
|
||||
export type Card = {
|
||||
}
|
||||
|
||||
export type Channel = {
|
||||
id: string,
|
||||
revision: number,
|
||||
data: {
|
||||
detailRevision: number,
|
||||
topicRevision: number,
|
||||
channelSummary?: {
|
||||
lastTopic: {
|
||||
guid: string,
|
||||
dataType: string,
|
||||
data: string,
|
||||
created: number,
|
||||
updated: number,
|
||||
status: string,
|
||||
transform: string
|
||||
}
|
||||
},
|
||||
channelDetail?: {
|
||||
dataType: string,
|
||||
data: string,
|
||||
created: number,
|
||||
updated: number,
|
||||
enableImage: boolean,
|
||||
enableAudio: boolean,
|
||||
enableVideo: boolean,
|
||||
enableBinary: boolean,
|
||||
contacts: {
|
||||
groups: [ string ],
|
||||
cards: [ string ],
|
||||
},
|
||||
members: {
|
||||
member: string,
|
||||
pushEnabled: boolean,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export type Topic = {
|
||||
}
|
||||
|
||||
export type Asset = {
|
||||
}
|
||||
|
||||
export type Group = {
|
||||
}
|
||||
|
||||
export type Article = {
|
||||
}
|
||||
|
||||
export type NodeAccount = {
|
||||
accountId: number,
|
||||
guid: string,
|
||||
@ -102,23 +138,6 @@ export type NodeAccount = {
|
||||
disabled: boolean,
|
||||
}
|
||||
|
||||
export type SignedMessage = {
|
||||
message: string,
|
||||
keyType: string,
|
||||
publicKey: string,
|
||||
signature: string,
|
||||
signatureType: string,
|
||||
}
|
||||
|
||||
export type ContactStatus = {
|
||||
token: string,
|
||||
profileRevision: number,
|
||||
articleRevision: number,
|
||||
channelRevision: number,
|
||||
viewRevision: number,
|
||||
status: string,
|
||||
}
|
||||
|
||||
export type NodeConfig = {
|
||||
domain: string,
|
||||
accountStorage: string,
|
||||
@ -139,3 +158,32 @@ export type NodeConfig = {
|
||||
openAccessLimit: number,
|
||||
}
|
||||
|
||||
export type SealKey = {
|
||||
publicKey: string,
|
||||
privateKey: string,
|
||||
}
|
||||
|
||||
export type Seal = {
|
||||
passwordSalt: string,
|
||||
privateKeyIv: string,
|
||||
privateKeyEncrypted: string,
|
||||
publicKey: string,
|
||||
}
|
||||
|
||||
export type SignedMessage = {
|
||||
message: string,
|
||||
keyType: string,
|
||||
publicKey: string,
|
||||
signature: string,
|
||||
signatureType: string,
|
||||
}
|
||||
|
||||
export type ContactStatus = {
|
||||
token: string,
|
||||
profileRevision: number,
|
||||
articleRevision: number,
|
||||
channelRevision: number,
|
||||
viewRevision: number,
|
||||
status: string,
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user