From d1215afee2dc765cfc906dbcec19991fde52df39 Mon Sep 17 00:00:00 2001 From: balzack Date: Wed, 30 Oct 2024 16:51:49 -0700 Subject: [PATCH] cleanup on content api --- app/sdk/README.md | 99 ++++++++++++++++++++++-------------------- app/sdk/src/api.ts | 4 +- app/sdk/src/content.ts | 4 +- app/sdk/src/stream.ts | 20 +++++++-- 4 files changed, 71 insertions(+), 56 deletions(-) diff --git a/app/sdk/README.md b/app/sdk/README.md index 93475a69..9012ad65 100644 --- a/app/sdk/README.md +++ b/app/sdk/README.md @@ -293,46 +293,10 @@ Automate allocates the Bot interface for ia specific communication channel ```Contact::cancelCard(cardId: string): Promise``` - The current articles can be access with an [Article](https://github.com/balzack/databag/blob/sdk/app/sdk/src/types.ts) listener - - ```Contact::addArticleListener(id: string | null, ev: (arg: { cardId: string; articles: Article[] }) => void): void``` - - ```Contact::removeArticleListener(id: string | null, ev: (arg: { cardId: string; articles: Article[] }) => void): void``` - - Relinquish access to shared article - - ```Contact::removeArticle(cardId: string): Promise``` - - The current channels can be access with a [Channel](https://github.com/balzack/databag/blob/sdk/app/sdk/src/types.ts) listener - - ```Contact::addChannelListener(id: string | null, ev: (arg: { cardId: string; channels: Channel[] }) => void): void``` - - ```Contact::removeChannelListener(id: string | null, ev: (arg: { cardId: string; channels: Channel[] }) => void): void``` - - Relinquish access to shared channel - - ```Contact::removeChannel(cardId: string): Promise``` - - Enable or disable push notification associated with specified contact channel - - ```Contact::setChannelNotifications(cardId: string, channelId: string, enabled: boolean): Promise``` - - Get whether notifications are enabled on specified contact channel - - ```Contact::getChannelNotifications(cardId: string, channelId: string): Promise``` - - Mark contact channel as read or unread with setUnreadChannel - - ```Contact::setUnreadChannel(cardId: string, channelId: string, unread: boolean): Promise``` - Get list of searchable accounts of specified server with getRegistry ```Contact::getRegistry(server: string, secure: boolean): Promise``` - Get URL of profile image for searchable contact on specified server - - ```Contact::getRegistryImageUrl(server: string, secure: boolean, guid: string): string``` - Block or unblock contact to hide locally with setBlockedCard ```Contact::setBlockedCard(cardId: string, boolean: blocked): Promise``` @@ -345,35 +309,74 @@ Automate allocates the Bot interface for ia specific communication channel ```Contact::flagCard(cardId: string): Promise``` - Block or unblock contact article to hide locallay with setBlockedArticle + - ```Contact::setBlockedArticle(cardId: string, articleId: string, boolean: blocked): Promise``` +
+ - Get list of all blocked contact articles with getBlockedArticles +
+ Contact interface module manages contacts and the shared articles and channels
- ```Contact::getBlockedArticles(): Promise``` +
    - Flag article for review by admin with flagArticle + The current channels can be access with a [Channel](https://github.com/balzack/databag/blob/sdk/app/sdk/src/types.ts) listener - ```Contact::flagArticle(cardId: string, articleId: string): Promise``` + ```Content::addChannelListener(ev: (arg: { channels: Channel[], cardId: string | null }) => void): void``` - Block or unblock contact channel with setBlockedChanenl + ```Content::removeChannelListener(ev: (arg: { channels: Channel[], cardId: string | null }) => void): void``` - ```Contact::setBlockedChannel(cardId: string, channelId: string, boolean: blocked): Promise``` + Add a new channel shared with specified contacts with addChannel - Get list of all blocked contact channels with getBlockedChannels + ```Content::addChannel(sealed: boolean, type: string, subject: any, cardIds: string[]): Promise``` - ```Contact::getBlockedChannels(): Promise``` + Remove a hosted channel with removeChannel + + ```Content::removeChannel(channelId: string): Promise``` + + Leave a channel hosted by a contact with leaveChannel + + ```Content::leaveChannel(cardId: string, channelId: string): Promise``` + + Update the subject on specified channel + + ```Content::setChannelSubject(channelId: string, subject: string): Promise``` + + Add member to specified channel + + ```Content::setChannelCard(channelId: string, cardId: string): Promise``` + + Remove member from specified channel + + ```Content::clearChannelCard(channelId: string, cardId: string): Promise``` + + Enable or disable push notification associated with specified channel + + ```Content::setChannelNotifications(cardId: string | null, channelId: string, enabled: boolean): Promise``` + + Get whether notifications are enabled on specified channel + + ```Content::getChannelNotifications(cardId: string | null, channelId: string): Promise``` + + Mark channel as read or unread with setUnreadChannel + + ```Content::setUnreadChannel(cardId: string | null, channelId: string, unread: boolean): Promise``` + + Block or unblock channel with setBlockedChannel + + ```Content::setBlockedChannel(cardId: string | null, channelId: string, boolean: blocked): Promise``` + + Get list of all blocked channels with getBlockedChannels + + ```Content::getBlockedChannels(): Promise``` Flag channel for review by admin with flagChannel - ```Contact::flagChannel(cardId: string, channelId: string): Promise``` + ```Content::flagChannel(cardId: string | null, channelId: string): Promise```

- ## Admin Communication diff --git a/app/sdk/src/api.ts b/app/sdk/src/api.ts index 32b4af7a..01551474 100644 --- a/app/sdk/src/api.ts +++ b/app/sdk/src/api.ts @@ -88,7 +88,7 @@ export interface Contact { } export interface Content { - addChannel(sealed: boolean, type: string, subject: string, cardIds: string[]): Promise; + addChannel(sealed: boolean, type: string, subject: any, cardIds: string[]): Promise; removeChannel(channelId: string): Promise; setChannelSubject(channelId: string, subject: string): Promise; setChannelCard(channelId: string, cardId: string): Promise; @@ -100,7 +100,7 @@ export interface Content { setChannelNotifications(cardId: string | null, channelId: string, enabled: boolean): Promise; setUnreadChannel(cardId: string | null, channelId: string, unread: boolean): Promise; - flagChannel(cardId: string, channelId: string): Promise; + flagChannel(cardId: string | null, channelId: string): Promise; setBlockedChannel(cardId: string | null, channelId: string, blocked: boolean): Promise; getBlockedChannels(): Promise; diff --git a/app/sdk/src/content.ts b/app/sdk/src/content.ts index 6da79537..737b8b23 100644 --- a/app/sdk/src/content.ts +++ b/app/sdk/src/content.ts @@ -18,7 +18,7 @@ export class ContentModule implements Content { this.crypto = crypto; } - public async addChannel(sealed: boolean, type: string, subject: string, cardIds: string[]): Promise { + public async addChannel(sealed: boolean, type: string, subject: any, cardIds: string[]): Promise { if (sealed) { if (!this.crypto) { throw new Error('crypto not set'); @@ -77,7 +77,7 @@ export class ContentModule implements Content { return await this.stream.setUnreadChannel(channelId, unread); } - public async flagChannel(cardId: string, channelId: string): Promise { + public async flagChannel(cardId: string | null, channelId: string): Promise { if (cardId) { return await this.contact.flagChannel(cardId, channelId); } diff --git a/app/sdk/src/stream.ts b/app/sdk/src/stream.ts index 8d39cb04..4c94ae8e 100644 --- a/app/sdk/src/stream.ts +++ b/app/sdk/src/stream.ts @@ -225,7 +225,7 @@ export class StreamModule { await this.sync(); } - public async addSealedChannel(type: string, subject: string, cardIds: string[], aesKeyHex: string, seals: { publicKey: string, sealedKey: string}[]): Promise { + public async addSealedChannel(type: string, subject: any, cardIds: string[], aesKeyHex: string, seals: { publicKey: string, sealedKey: string}[]): Promise { const { node, secure, token, crypto, seal } = this; if (!crypto) { throw new Error('crypto not set'); @@ -235,14 +235,15 @@ export class StreamModule { } const sealKey = await this.crypto.rsaEncrypt(aesKeyHex, seal.publicKey); const { ivHex } = await crypto.aesIv(); - const { encryptedDataB64 } = await crypto.aesEncrypt(subject, ivHex, aesKeyHex); + const subjectData = JSON.stringify(subject); + const { encryptedDataB64 } = await crypto.aesEncrypt(subjectData, ivHex, aesKeyHex); const sealedSubject = { subjectEncrypted: encryptedDataB64, subjectIv: ivHex, seals: [ ...seals, sealKey ] }; return await addChannel(node, secure, token, type, sealedSubject, cardIds); } - public async addUnsealedChannel(type: string, subject: string, cardIds: string[]): Promise { + public async addUnsealedChannel(type: string, subject: any, cardIds: string[]): Promise { const { node, secure, token } = this; - return await addChannel(node, secure, token, type, { subject }, cardIds); + return await addChannel(node, secure, token, type, subject, cardIds); } public async removeChannel(channelId: string): Promise { @@ -279,11 +280,22 @@ export class StreamModule { public async setChannelCard(channelId: string, cardId: string): Promise { const { node, secure, token } = this; + const channel = this.channelEntries.get(channelId); + if (!channel) { + throw new Error('channel not found'); + } + if (channel.item.sealed) { + throw new Error('sealed channels cannot add members'); + } await setChannelCard(node, secure, token, channelId, cardId); } public async clearChannelCard(channelId: string, cardId: string): Promise { const { node, secure, token } = this; + const channel = this.channelEntries.get(channelId); + if (!channel) { + throw new Error('channel not found'); + } await clearChannelCard(node, secure, token, channelid, cardId); }