From 29ddcbe88f4a90c97305309af65af7d4e7b1f09c Mon Sep 17 00:00:00 2001 From: balzack Date: Sun, 30 Jun 2024 23:14:35 -0700 Subject: [PATCH] adding bot interface --- app/sdk/src/api.ts | 25 ++++- app/sdk/src/bot.ts | 22 +++++ app/sdk/src/contact.ts | 17 +++- app/sdk/src/content.ts | 17 +++- app/sdk/src/entities.ts | 172 ++++++++++++++++++++++++++++++++ app/sdk/src/index.ts | 7 +- app/sdk/src/session.ts | 2 +- app/sdk/src/types.ts | 210 ++++++++++++++++++++++++---------------- 8 files changed, 375 insertions(+), 97 deletions(-) create mode 100644 app/sdk/src/bot.ts create mode 100644 app/sdk/src/entities.ts diff --git a/app/sdk/src/api.ts b/app/sdk/src/api.ts index b9375cd8..1e14eca8 100644 --- a/app/sdk/src/api.ts +++ b/app/sdk/src/api.ts @@ -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; @@ -76,13 +78,16 @@ export interface Contact { removeChannel(cardId: string, channelId: string): Promise; addTopic(cardId: string, channelId: string, type: string, message: string, assets: Asset[]): Promise; removeTopic(cardId: string, channelId: string, topicId: string): Promise; + addTag(cardId: string, channelId: string, topicId: string, type: string, value: string): Promise; + removeTag(cardId: string, tagId: string): Promise; setTopicSubject(cardId: string, channelId: string, topicId: string, type: string, subject: string): Promise; - getTopics(cardId: string, channelId: string, revision: number, count: number, begin: number, end: number): Promise; - getTopic(cardId: string, channelId: string, topicId: string): Promise; resyncCard(cardId: string): Promise; getTopicAssetUrl(cardId: string, channelId: string, topicId: string, assetId: string): string; getCardImageUrl(cardId: string): string; + addRepeaterAccess(cardId: string, channelId: string, name: string): Promise; + removeRepeaterAccess(cardId: string, channelId: string, repeaterId: string): Promise; + 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; removeTopic(channelId: string, topicId: string): Promise; setTopicSubject(channelId: string, topicId: string, type: string, subject: string): Promise; - getTopics(channelId: string, revision: number, count: number, begin: number, end: number): Promise; - getTopic(channelId: string, topicId: string): Promise; + addTag(channelId: string, topicId: string, type: string, value: string): Promise; + removeTag(channelId: string, topicId: string, tagId: string): Promise; getTopicAssetUrl(channelId: string, topicId: string, assetId: string): string; + addRepeaterAccess(channelId: string, name: string): Promise; + removeRepeaterAccess(channelId: string, repeaterId: string): Promise; + 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; + removeTopic(server: string, token: string, topicId: string): Promise; + addTag(server: string, token: string, topicId: string, type: string, value: string): Promise; + removeTag(server: string, token: string, topicId: string, tagId: string): Promise; +} + diff --git a/app/sdk/src/bot.ts b/app/sdk/src/bot.ts new file mode 100644 index 00000000..ac25eaf0 --- /dev/null +++ b/app/sdk/src/bot.ts @@ -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 { + return ''; + } + + public async removeTopic(server: string, token: string, topicId: string): Promise { + } + + public async addTag(server: string, token: string, topicId: string, type: string, value: string): Promise { + return ''; + } + + public async removeTag(server: string, token: string, topicId: string, tagId: string): Promise { + } +} diff --git a/app/sdk/src/contact.ts b/app/sdk/src/contact.ts index 3489ddaa..21024732 100644 --- a/app/sdk/src/contact.ts +++ b/app/sdk/src/contact.ts @@ -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 { } - public async getTopics(cardId: string, channelId: string, revision: number, count: number, begin: number, end: number): Promise { + public async addTag(cardId: string, channelId: string, topicId: string, type: string, value: string): Promise { + return ''; } - public async getTopic(cardId: string, channelId: string, topicId: string): Promise { - return {} + public async removeTag(cardId: string, tagId: string): Promise { + return; } public async resyncCard(cardId: string): Promise { @@ -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 { + return { id: '', guid: '', name: '', server: '', token: '' }; + } + + public async removeRepeaterAccess(cardId: string, channelId: string, repeaterId: string): Promise { + } + } diff --git a/app/sdk/src/content.ts b/app/sdk/src/content.ts index e914487a..a4ae4b1d 100644 --- a/app/sdk/src/content.ts +++ b/app/sdk/src/content.ts @@ -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 { } - public async getTopics(channelId: string, revision: number, count: number, begin: number, end: number): Promise { - return []; + + public async addTag(channelId: string, topicId: string, type: string, value: string): Promise { + return ''; } - public async getTopic(channelId: string, topicId: string): Promise { - return {}; + public async removeTag(channelId: string, topicId: string, tagId: string): Promise { } public getTopicAssetUrl(channelId: string, topicId: string, assetId: string): string { return ''; } + + public async addRepeaterAccess(channelId: string, name: string): Promise { + return { id: '', guid: '', name: '', server: '', token: '' }; + } + + public async removeRepeaterAccess(channelId: string, repeaterId: string): Promise { + } } diff --git a/app/sdk/src/entities.ts b/app/sdk/src/entities.ts new file mode 100644 index 00000000..21cf4355 --- /dev/null +++ b/app/sdk/src/entities.ts @@ -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, +} + diff --git a/app/sdk/src/index.ts b/app/sdk/src/index.ts index 35a7a070..e6e16e91 100644 --- a/app/sdk/src/index.ts +++ b/app/sdk/src/index.ts @@ -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 { return new NodeModule('', ''); } + + public async automate() { + return new BotModule(); + } } diff --git a/app/sdk/src/session.ts b/app/sdk/src/session.ts index 185de157..b119b3c8 100644 --- a/app/sdk/src/session.ts +++ b/app/sdk/src/session.ts @@ -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; diff --git a/app/sdk/src/types.ts b/app/sdk/src/types.ts index 1eb62980..50b6a4cc 100644 --- a/app/sdk/src/types.ts +++ b/app/sdk/src/types.ts @@ -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, +} +