From aa2ba3b072a22913911c05eade90c0226725b569 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Fri, 4 Oct 2024 14:49:00 -0700 Subject: [PATCH] change formatting style --- app/sdk/package.json | 2 +- app/sdk/src/alias.ts | 27 +- app/sdk/src/api.ts | 16 +- app/sdk/src/attribute.ts | 43 +- app/sdk/src/connection.ts | 16 +- app/sdk/src/contact.ts | 496 +++--------- app/sdk/src/content.ts | 211 +---- app/sdk/src/contributor.ts | 20 +- app/sdk/src/crypto.ts | 22 +- app/sdk/src/entities.ts | 12 +- app/sdk/src/focus.ts | 49 +- app/sdk/src/identity.ts | 28 +- app/sdk/src/index.ts | 163 +--- app/sdk/src/net/addAccount.ts | 14 +- app/sdk/src/net/addAccountMFAuth.ts | 6 +- app/sdk/src/net/addCard.ts | 7 +- app/sdk/src/net/base64.ts | 10 +- app/sdk/src/net/clearAccountSeal.ts | 6 +- app/sdk/src/net/clearLogin.ts | 7 +- app/sdk/src/net/fetchUtil.ts | 10 +- app/sdk/src/net/getAccountStatus.ts | 6 +- app/sdk/src/net/getAvailable.ts | 5 +- app/sdk/src/net/getCardCloseMessage.ts | 3 +- app/sdk/src/net/getCardDetail.ts | 7 +- app/sdk/src/net/getCardOpenMessage.ts | 5 +- app/sdk/src/net/getCardProfile.ts | 7 +- app/sdk/src/net/getCards.ts | 7 +- app/sdk/src/net/getContactChannelDetail.ts | 7 +- app/sdk/src/net/getContactChannelSummary.ts | 7 +- app/sdk/src/net/getContactChannels.ts | 13 +- app/sdk/src/net/getContactListing.ts | 6 +- app/sdk/src/net/getContactProfile.ts | 7 +- app/sdk/src/net/getProfile.ts | 6 +- app/sdk/src/net/getProfileImageUrl.ts | 7 +- app/sdk/src/net/getUsername.ts | 8 +- app/sdk/src/net/removeAccount.ts | 6 +- app/sdk/src/net/removeAccountMFAuth.ts | 6 +- app/sdk/src/net/removeCard.ts | 7 +- app/sdk/src/net/setAccountLogin.ts | 8 +- app/sdk/src/net/setAccountMFAuth.ts | 7 +- app/sdk/src/net/setAccountNotifications.ts | 7 +- app/sdk/src/net/setAccountSeal.ts | 7 +- app/sdk/src/net/setAccountSearchable.ts | 7 +- app/sdk/src/net/setAdmin.ts | 7 +- app/sdk/src/net/setCardCloseMessage.ts | 5 +- app/sdk/src/net/setCardConfirmed.ts | 9 +- app/sdk/src/net/setCardConnected.ts | 15 +- app/sdk/src/net/setCardConnecting.ts | 9 +- app/sdk/src/net/setCardOpenMessage.ts | 5 +- app/sdk/src/net/setCardProfile.ts | 8 +- app/sdk/src/net/setProfileData.ts | 14 +- app/sdk/src/net/setProfileImage.ts | 7 +- app/sdk/src/session.ts | 105 +-- app/sdk/src/settings.ts | 70 +- app/sdk/src/store.ts | 806 ++++---------------- app/sdk/src/stream.ts | 8 +- 56 files changed, 398 insertions(+), 1991 deletions(-) diff --git a/app/sdk/package.json b/app/sdk/package.json index 2c6b47e2..b8db5624 100644 --- a/app/sdk/package.json +++ b/app/sdk/package.json @@ -10,7 +10,7 @@ ], "scripts": { "build": "tsup", - "format": "prettier --write src", + "format": "prettier --print-width 200 --write src", "test": "jest" }, "repository": { diff --git a/app/sdk/src/alias.ts b/app/sdk/src/alias.ts index 49236614..683213ad 100644 --- a/app/sdk/src/alias.ts +++ b/app/sdk/src/alias.ts @@ -12,15 +12,7 @@ export class AliasModule implements Alias { private settings: Settings; private emitter: EventEmitter; - constructor( - log: Logging, - settings: Settings, - store: Store, - guid: string, - token: string, - node: string, - secure: boolean, - ) { + constructor(log: Logging, settings: Settings, store: Store, guid: string, token: string, node: string, secure: boolean) { this.guid = guid; this.token = token; this.node = node; @@ -44,30 +36,19 @@ export class AliasModule implements Alias { console.log("set alias revision:", rev); } - public async addGroup( - sealed: boolean, - dataType: string, - subject: string, - cardIds: string[], - ): Promise { + public async addGroup(sealed: boolean, dataType: string, subject: string, cardIds: string[]): Promise { return ""; } public async removeGroup(groupId: string): Promise {} - public async setGroupSubject( - groupId: string, - subject: string, - ): Promise {} + public async setGroupSubject(groupId: string, subject: string): Promise {} public async setGroupCard(groupId: string, cardId: string): Promise {} public async clearGroupCard(groupId: string, cardId: string): Promise {} - public async compare( - groupIds: string[], - cardIds: string[], - ): Promise> { + public async compare(groupIds: string[], cardIds: string[]): Promise> { return new Map(); } } diff --git a/app/sdk/src/api.ts b/app/sdk/src/api.ts index 1b68444e..1ce44e0b 100644 --- a/app/sdk/src/api.ts +++ b/app/sdk/src/api.ts @@ -1,4 +1,4 @@ -import type { Channel, Topic, Asset, Tag, Article, Group, Card, Profile, Call, Config, NodeConfig, NodeAccount, Participant } from './types'; +import type { Channel, Topic, Asset, Tag, Article, Group, Card, Profile, Call, Config, NodeConfig, NodeAccount, Participant } from "./types"; export interface Session { getSettings(): Settings; @@ -36,7 +36,7 @@ export interface Settings { disableNotifications(): Promise; enableRegistry(): Promise; disableRegistry(): Promise; - enableMFA(): Promise<{ secretImage: string, secretText: string }>; + enableMFA(): Promise<{ secretImage: string; secretText: string }>; disableMFA(): Promise; confirmMFA(code: string): Promise; setSeal(password: string): Promise; @@ -84,8 +84,8 @@ export interface Contact { clearBlockArticle(cardId: string, articleId: string): Promise; clearBlockChannel(cardId: string, channelId: string): Promise; getBlockedCards(): Promise<{ cardId: string }[]>; - getBlockedChannels(): Promise<{ cardId: string, channelId: string }[]>; - getBlockedArticles(): Promise<{ cardId: string, articleId: string }[]>; + getBlockedChannels(): Promise<{ cardId: string; channelId: string }[]>; + getBlockedArticles(): Promise<{ cardId: string; articleId: string }[]>; enableChannelNotifications(cardId: string, channelId: string): Promise; disableChannelNotifications(chardId: string, channelId: string): Promise; @@ -109,7 +109,7 @@ export interface Alias { setGroupCard(groupId: string, cardId: string): Promise; clearGroupCard(groupId: string, cardId: string): Promise; compare(groupIds: string[], cardIds: string[]): Promise>; - + addGroupListener(ev: (groups: Group[]) => void): void; removeGroupListener(ev: (groups: Group[]) => void): void; } @@ -151,8 +151,8 @@ export interface Content { setBlockTag(channelId: string, topicId: string, tagId: string): Promise; clearBlockTopic(channelId: string, topicId: string): Promise; clearBlockTag(channelId: string, topicId: string, tagId: string): Promise; - getBlockedTopics(): Promise<{ channelId: string, topicId: string }[]>; - getBlockedTags(): Promise<{ channelId: string, topicId: string, tagId: string }[]>; + getBlockedTopics(): Promise<{ channelId: string; topicId: string }[]>; + getBlockedTags(): Promise<{ channelId: string; topicId: string; tagId: string }[]>; enableNotifications(channelId: string, memberId: string): Promise; disableNotifications(channelId: string, memberId: string): Promise; @@ -237,5 +237,3 @@ export interface Contributor { addTag(topicId: string, type: string, value: string): Promise; removeTag(topicId: string, tagId: string): Promise; } - - diff --git a/app/sdk/src/attribute.ts b/app/sdk/src/attribute.ts index 145edc96..3eb038d5 100644 --- a/app/sdk/src/attribute.ts +++ b/app/sdk/src/attribute.ts @@ -12,15 +12,7 @@ export class AttributeModule implements Attribute { private settings: Settings; private emitter: EventEmitter; - constructor( - log: Logging, - settings: Settings, - store: Store, - guid: string, - token: string, - node: string, - secure: boolean, - ) { + constructor(log: Logging, settings: Settings, store: Store, guid: string, token: string, node: string, secure: boolean) { this.guid = guid; this.token = token; this.node = node; @@ -44,42 +36,21 @@ export class AttributeModule implements Attribute { console.log("set attribute revision:", rev); } - public async addArticle( - sealed: boolean, - type: string, - subject: string, - cardIds: string[], - groupIds: string[], - ): Promise { + public async addArticle(sealed: boolean, type: string, subject: string, cardIds: string[], groupIds: string[]): Promise { return ""; } public async removeArticle(articleId: string): Promise {} - public async setArticleSubject( - articleId: string, - subject: string, - ): Promise {} + public async setArticleSubject(articleId: string, subject: string): Promise {} - public async setArticleCard( - articleId: string, - cardId: string, - ): Promise {} + public async setArticleCard(articleId: string, cardId: string): Promise {} - public async clearArticleCard( - articleId: string, - cardId: string, - ): Promise {} + public async clearArticleCard(articleId: string, cardId: string): Promise {} - public async setArticleGroup( - articleId: string, - groupId: string, - ): Promise {} + public async setArticleGroup(articleId: string, groupId: string): Promise {} - public async clearArticleGroup( - articleId: string, - groupId: string, - ): Promise {} + public async clearArticleGroup(articleId: string, groupId: string): Promise {} public addArticleListener(ev: (articles: Article[]) => void): void {} diff --git a/app/sdk/src/connection.ts b/app/sdk/src/connection.ts index ba16d210..188b82c0 100644 --- a/app/sdk/src/connection.ts +++ b/app/sdk/src/connection.ts @@ -47,11 +47,7 @@ export class Connection { this.emitter.off("status", ev); } - private setWebSocket( - token: string, - node: string, - secure: boolean, - ): WebSocket { + private setWebSocket(token: string, node: string, secure: boolean): WebSocket { if (this.closed) { this.emitter.emit("status", "closed"); return this.websocket; @@ -70,15 +66,7 @@ export class Connection { if (activity.revision) { this.emitter.emit("revision", activity.revision as Revision); } else if (activity.ring) { - const { - cardId, - callId, - calleeToken, - ice, - iceUrl, - iceUsername, - icePassword, - } = activity.ring; + const { cardId, callId, calleeToken, ice, iceUrl, iceUsername, icePassword } = activity.ring; const call: Call = { cardId, callId, diff --git a/app/sdk/src/contact.ts b/app/sdk/src/contact.ts index 03adbf5e..388922ad 100644 --- a/app/sdk/src/contact.ts +++ b/app/sdk/src/contact.ts @@ -2,17 +2,7 @@ import { EventEmitter } from "eventemitter3"; import type { Contact, Logging } from "./api"; import type { Card, Topic, Asset, Tag, Profile, Participant } from "./types"; import type { CardEntity } from "./entities"; -import type { - ArticleRevision, - ArticleDetail, - ChannelRevision, - ChannelSummary, - ChannelDetail, - CardRevision, - CardNotification, - CardProfile, - CardDetail, -} from "./items"; +import type { ArticleRevision, ArticleDetail, ChannelRevision, ChannelSummary, ChannelDetail, CardRevision, CardNotification, CardProfile, CardDetail } from "./items"; import { defaultCardItem, defaultChannelItem } from "./items"; import { Store } from "./store"; import { getCards } from "./net/getCards"; @@ -23,11 +13,11 @@ import { getContactProfile } from "./net/getContactProfile"; import { getContactChannels } from "./net/getContactChannels"; import { getContactChannelDetail } from "./net/getContactChannelDetail"; import { getContactChannelSummary } from "./net/getContactChannelSummary"; -import { addCard } from './net/addCard'; -import { getContactListing } from './net/getContactListing'; -import { setCardConfirmed } from './net/setCardConfirmed'; -import { setCardConnecting } from './net/setCardConnecting'; -import { setCardConnected } from './net/setCardConnected'; +import { addCard } from "./net/addCard"; +import { getContactListing } from "./net/getContactListing"; +import { setCardConfirmed } from "./net/setCardConfirmed"; +import { setCardConnecting } from "./net/setCardConnecting"; +import { setCardConnected } from "./net/setCardConnected"; const CLOSE_POLL_MS = 100; const RETRY_POLL_MS = 2000; @@ -55,28 +45,12 @@ export class ContactModule implements Contact { private cardEntries: Map; // view of articles - private articleEntries: Map< - string, - Map - >; + private articleEntries: Map>; // view of channels - private channelEntries: Map< - string, - Map - >; + private channelEntries: Map>; - constructor( - log: Logging, - store: Store, - crypto: Crypto | null, - guid: string, - token: string, - node: string, - secure: boolean, - articleTypes, - channelTypes, - ) { + constructor(log: Logging, store: Store, crypto: Crypto | null, guid: string, token: string, node: string, secure: boolean, articleTypes, channelTypes) { this.guid = guid; this.token = token; this.node = node; @@ -90,14 +64,8 @@ export class ContactModule implements Contact { this.unsealAll = false; this.cardEntries = new Map(); - this.articleEntries = new Map< - string, - Map - >(); - this.channelEntries = new Map< - string, - Map - >(); + this.articleEntries = new Map>(); + this.channelEntries = new Map>(); this.revision = 0; this.sycning = true; @@ -121,13 +89,7 @@ export class ContactModule implements Contact { const articles = await this.store.getContactCardArticles(guid); articles.forEach(({ cardId, articleId, item }) => { if (!this.articleEntries.has(cardId)) { - this.articleEntries.set( - cardId, - new Map< - string, - Map - >(), - ); + this.articleEntries.set(cardId, new Map>()); } const article = setArticle(cardId, articleId, item); this.articleEntries.set(cardId).set(articleId, { item, article }); @@ -137,13 +99,7 @@ export class ContactModule implements Contact { const channels = await this.store.getContactCardChannels(guid); channels.forEach(({ cardId, channelId, item }) => { if (!this.channelEntries.has(cardId)) { - this.channelEntries.set( - cardId, - new Map< - string, - Map - >(), - ); + this.channelEntries.set(cardId, new Map>()); } const channel = setChannel(cardId, channelId, item); this.channelEntries.set(cardId).set(channelId, { item, channel }); @@ -169,9 +125,7 @@ export class ContactModule implements Contact { const entry = await this.getCardEntry(id); if (data.detailRevision !== entry.item.detail.revison) { - const detail = data.cardDetail - ? data.cardDetail - : await getCardDetail(node, secure, token, id); + const detail = data.cardDetail ? data.cardDetail : await getCardDetail(node, secure, token, id); const { status, statusUpdated, token: cardToken } = detail; entry.item.detail = { revision: data.detailRevision, @@ -180,17 +134,11 @@ export class ContactModule implements Contact { token: cardToken, }; entry.card = this.setCard(id, entry.item); - await this.store.setContactCardDetail( - guid, - id, - entry.item.detail, - ); + await this.store.setContactCardDetail(guid, id, entry.item.detail); } if (data.profileRevision !== entry.item.profile.revision) { - const profile = data.cardProfile - ? data.cardProfile - : await getCardProfile(node, secure, token, id); + const profile = data.cardProfile ? data.cardProfile : await getCardProfile(node, secure, token, id); entry.item.profile = { revision: data.profileRevision, handle: profile.handle, @@ -203,31 +151,14 @@ export class ContactModule implements Contact { seal: profile.seal, }; entry.card = this.setCard(id, entry.item); - await this.store.setContactCardProfile( - guid, - id, - entry.item.profile, - ); + await this.store.setContactCardProfile(guid, id, entry.item.profile); } - if ( - data.notifiedProfile > entry.item.profile.revision && - data.notifiedProfile !== entry.item.profileRevision - ) { + if (data.notifiedProfile > entry.item.profile.revision && data.notifiedProfile !== entry.item.profileRevision) { try { - await this.syncProfile( - id, - entry.item.profile.node, - entry.item.profile.guid, - entry.item.detail.token, - entry.item.profileRevision, - ); + await this.syncProfile(id, entry.item.profile.node, entry.item.profile.guid, entry.item.detail.token, entry.item.profileRevision); entry.item.profileRevision = data.notifiedProfile; - await this.store.setContactCardProfileRevision( - guid, - id, - data.notifiedProfile, - ); + await this.store.setContactCardProfileRevision(guid, id, data.notifiedProfile); } catch (err) { this.log.warn(err); entry.item.offsync = true; @@ -237,19 +168,9 @@ export class ContactModule implements Contact { if (data.notifiedArticle !== entry.item.articleRevision) { try { - await this.syncArticles( - id, - entry.item.profile.node, - entry.item.profile.guid, - entry.item.detail.token, - entry.item.articleRevision, - ); + await this.syncArticles(id, entry.item.profile.node, entry.item.profile.guid, entry.item.detail.token, entry.item.articleRevision); entry.item.articleRevision = data.notifiedArticle; - await this.store.setContactCardArticlesRevision( - guid, - id, - data.notifiedArticle, - ); + await this.store.setContactCardArticlesRevision(guid, id, data.notifiedArticle); } catch (err) { this.log.warn(err); entry.item.offsync = true; @@ -261,17 +182,9 @@ export class ContactModule implements Contact { if (data.notifiedChannel !== entry.item.channelRevision) { try { const { profile, detail } = entry.item; - await this.syncChannels( - id, - { guid: profile.guid, node: profile.node, token: detail.token }, - entry.item.channelRevision, - ); + await this.syncChannels(id, { guid: profile.guid, node: profile.node, token: detail.token }, entry.item.channelRevision); entry.item.channelRevision = data.notifiedChannel; - await this.store.setContactCardChannelsRevision( - guid, - id, - data.notifiedChannel, - ); + await this.store.setContactCardChannelsRevision(guid, id, data.notifiedChannel); } catch (err) { this.log.warn(err); entry.item.offsync = true; @@ -315,20 +228,10 @@ export class ContactModule implements Contact { const cardId = card.key; const channelId = channel.key; if (await this.unsealChannelDetail(cardId, channelId, item)) { - await this.store.setContactCardChannelUnsealedDetail( - guid, - cardId, - channelId, - item.unsealedDetail, - ); + await this.store.setContactCardChannelUnsealedDetail(guid, cardId, channelId, item.unsealedDetail); } if (await this.unsealChannelSummary(cardId, channelId, item)) { - await this.store.setContactCardChannelUnsealedSummary( - guid, - cardId, - channelId, - item.unsealedSummary, - ); + await this.store.setContactCardChannelUnsealedSummary(guid, cardId, channelId, item.unsealedSummary); } const channel = setChannel(cardId, channelId, item); this.channelEntries.set(cardId).set(channelId, { item, channel }); @@ -344,87 +247,36 @@ export class ContactModule implements Contact { } } - private async syncProfile( - cardId: string, - cardNode: string, - cardGuid: string, - cardToken: string, - revision: number, - ): Promise { + private async syncProfile(cardId: string, cardNode: string, cardGuid: string, cardToken: string, revision: number): Promise { const { node, secure, token } = this; const server = cardNode ? cardNode : node; - const insecure = - /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test( - server, - ); - const message = await getContactProfile( - server, - !insecure, - cardGuid, - cardToken, - ); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const message = await getContactProfile(server, !insecure, cardGuid, cardToken); await setCardProfile(node, secure, token, cardId, message); } - private async syncArticles( - cardId: string, - cardNode: string, - cardGuid: string, - cardToken: string, - revision: number, - ): Promise { + private async syncArticles(cardId: string, cardNode: string, cardGuid: string, cardToken: string, revision: number): Promise { const { node, secure, token } = this; const server = cardNode ? cardNode : node; - const insecure = - /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test( - server, - ); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); } - private async syncChannels( - cardId: string, - card: { guid, node, token }, - revision: number, - ): Promise { + private async syncChannels(cardId: string, card: { guid; node; token }, revision: number): Promise { const { guid, node, secure, token, channelTypes } = this; const server = card.node ? card.node : node; - const insecure = - /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test( - server, - ); - const delta = await getContactChannels( - server, - !insecure, - card.guid, - card.token, - revision, - channelTypes, - ); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const delta = await getContactChannels(server, !insecure, card.guid, card.token, revision, channelTypes); for (const entity of delta) { const { id, revision, data } = entity; if (data) { - const { detailRevision, topicRevision, channelSummary, channelDetail } = - data; + const { detailRevision, topicRevision, channelSummary, channelDetail } = data; const entries = this.getChannelEntries(cardId); const entry = await this.getChannelEntry(entries, cardId, id); if (detailRevision !== entry.item.detail.revision) { - const detail = channelDetail - ? channelDetail - : await getContactChannelDetail(server, !insecure, id); - const { - dataType, - data, - created, - updated, - enableImage, - enableAudio, - enableVideo, - enableBinary, - contacts, - members, - } = detail; + const detail = channelDetail ? channelDetail : await getContactChannelDetail(server, !insecure, id); + const { dataType, data, created, updated, enableImage, enableAudio, enableVideo, enableBinary, contacts, members } = detail; entry.item.detail = { revision: detailRevision, sealed: dataType === "sealed", @@ -442,21 +294,12 @@ export class ContactModule implements Contact { entry.item.unsealedDetail = null; await this.unsealChannelDetail(cardId, id, entry.item); entry.channel = this.setChannel(cardId, id, entry.item); - await this.store.setContactCardChannelDetail( - guid, - cardId, - id, - entry.item.detail, - entry.item.unsealedDetail, - ); + await this.store.setContactCardChannelDetail(guid, cardId, id, entry.item.detail, entry.item.unsealedDetail); } if (topicRevision !== entry.item.summary.revision) { - const summary = channelSummary - ? channelSummary - : await getContactChannelSummary(server, !insecure, id); - const { guid, dataType, data, created, updated, status, transform } = - summary.lastTopic; + const summary = channelSummary ? channelSummary : await getContactChannelSummary(server, !insecure, id); + const { guid, dataType, data, created, updated, status, transform } = summary.lastTopic; entry.item.summary = { revision: topicRevision, guid, @@ -470,14 +313,8 @@ export class ContactModule implements Contact { entry.item.unsealedSummary = null; await this.unsealChannelSummary(cardId, id, entry.item); entry.channel = this.setChannel(cardId, id, entry.item); - await this.store.setContactCardChannelSummary( - guid, - cardId, - id, - entry.item.summary, - entry.item.unsealedSummary, - ); - this.emitTopicRevision(cardId, id, card, topicRevision) + await this.store.setContactCardChannelSummary(guid, cardId, id, entry.item.summary, entry.item.unsealedSummary); + this.emitTopicRevision(cardId, id, card, topicRevision); } } else { const channels = this.getChannelEntries(cardId); @@ -487,7 +324,6 @@ export class ContactModule implements Contact { } } - public addCardListener(ev: (cards: Card[]) => void): void { this.emitter.on("card", ev); const cards = Array.from(this.cardEntries, ([cardId, entry]) => entry.card); @@ -503,35 +339,23 @@ export class ContactModule implements Contact { this.emitter.emit("card", cards); } - - public addArticleListener( - id: string | null, - ev: (arg: { cardId: string; articles: Article[] }) => void, - ): void { + public addArticleListener(id: string | null, ev: (arg: { cardId: string; articles: Article[] }) => void): void { if (id) { const cardId = id as string; this.emitter.on(`article::${cardId}`, ev); const entries = this.articleEntries.get(cardId); - const articles = entries - ? Array.from(entries, ([articleId, entry]) => entry.article) - : []; + const articles = entries ? Array.from(entries, ([articleId, entry]) => entry.article) : []; ev({ cardId, articles }); } else { this.emitter.on("article", ev); this.articleEntries.forEach((entries, cardId) => { - const articles = Array.from( - entries, - ([articleId, entry]) => entry.article, - ); + const articles = Array.from(entries, ([articleId, entry]) => entry.article); ev({ cardId, articles }); }); } } - public removeArticleListener( - id: string | null, - ev: (arg: { cardId: string; articles: Article[] }) => void, - ): void { + public removeArticleListener(id: string | null, ev: (arg: { cardId: string; articles: Article[] }) => void): void { if (id) { const cardId = id as string; this.emitter.off(`article::${cardId}`, ev); @@ -542,42 +366,28 @@ export class ContactModule implements Contact { private emitArticles(cardId: string) { const entries = this.articleEntries.get(cardId); - const articles = entries - ? Array.from(entries, ([articleId, entry]) => entry.article) - : []; + const articles = entries ? Array.from(entries, ([articleId, entry]) => entry.article) : []; this.emitter.emit("article", { cardId, articles }); this.emitter.emit(`article::${cardId}`, { cardId, articles }); } - - public addChannelListener( - id: string | null, - ev: (arg: { cardId: string; channels: Channel[] }) => void, - ): void { + public addChannelListener(id: string | null, ev: (arg: { cardId: string; channels: Channel[] }) => void): void { if (id) { const cardId = id as string; this.emitter.on(`channel::${cardId}`, ev); const entries = this.channelEntries.get(cardId); - const channels = entries - ? Array.from(entries, ([channelId, entry]) => entry.channel) - : []; + const channels = entries ? Array.from(entries, ([channelId, entry]) => entry.channel) : []; ev({ cardId, channels }); } else { this.emitter.on("channel", ev); this.channelEntries.forEach((entries, cardId) => { - const channels = Array.from( - entries, - ([channelId, entry]) => entry.channel, - ); + const channels = Array.from(entries, ([channelId, entry]) => entry.channel); ev({ cardId, channels }); }); } } - public removeChannelListener( - id: string | null, - ev: (arg: { cardId: string; channels: Channel[] }) => void, - ): void { + public removeChannelListener(id: string | null, ev: (arg: { cardId: string; channels: Channel[] }) => void): void { if (id) { const cardId = id as string; this.emitter.off(`channel::${cardId}`, ev); @@ -588,18 +398,12 @@ export class ContactModule implements Contact { private emitChannels(cardId: string) { const entries = this.channelEntries.get(cardId); - const channels = entries - ? Array.from(entries, ([channelId, entry]) => entry.channel) - : []; + const channels = entries ? Array.from(entries, ([channelId, entry]) => entry.channel) : []; this.emitter.emit("channel", { cardId, channels }); this.emitter.emit(`channel::${cardId}`, { cardId, channels }); } - public addTopicRevisionListener( - cardId: string, - channelId: string, - ev: (arg: { cardId: string; channelId: string, guid: string, node: string, token: string, revision: number }) => void, - ): void { + public addTopicRevisionListener(cardId: string, channelId: string, ev: (arg: { cardId: string; channelId: string; guid: string; node: string; token: string; revision: number }) => void): void { this.emitter.on(`revision::${cardId}::${channelId}`, ev); const entries = this.channelEntries.get(cardId); if (entries) { @@ -607,28 +411,22 @@ export class ContactModule implements Contact { if (entry) { const { profile, detail } = entry.item; const { guid, node } = profile; - const { token } = detail; + const { token } = detail; ev({ cardId, channelId, guid, node, token, revision }); } } } - public removeTopicRevisionListener( - cardId: string, - channelId: string, - ev: (arg: { cardId: string, channelId: string, guid: string, node: string, token: string, revision: number }) => void, - ): void { + public removeTopicRevisionListener(cardId: string, channelId: string, ev: (arg: { cardId: string; channelId: string; guid: string; node: string; token: string; revision: number }) => void): void { this.emitter.off(`revision::${cardId}::${channelId}`, ev); } - private emitTopicRevision(cardId: string, channelId: string, card: { guid: string, node: string, token: string }, revision: number) { + private emitTopicRevision(cardId: string, channelId: string, card: { guid: string; node: string; token: string }, revision: number) { const { guid, node, token } = card; const channel = { cardId, channelId, guid, node, token, revision }; this.emitter.emit(`revision::${cardId}::${channelId}`, channel); } - - public async setSeal(seal: { privateKey: string; publicKey: string } | null) { this.seal = seal; this.unsealAll = true; @@ -643,10 +441,7 @@ export class ContactModule implements Contact { } public async addCard(server: string, guid: string): Promise { - const insecure = - /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test( - server, - ); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); const message = await getContactListing(server, !insecure, guid); const { node, secure, token } = this; return await addCard(node, secure, token, message); @@ -657,13 +452,6 @@ export class ContactModule implements Contact { await removeCard(node, secure, token, cardId); } - - - - - - - public async confirmCard(cardId: string): Promise { const { node, secure, token } = this; await setCardConfirmed(node, secure, token, cardId); @@ -678,19 +466,15 @@ export class ContactModule implements Contact { const entry = this.cardEntries.get(cardId); if (entry) { const server = entry.item.profile.node ? entry.item.profile.node : node; - const insecure = - /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test( - server, - ); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); const contact = await setCardOpenMessage(server, !insecure, message); - if (contact.status === 'connected') { + if (contact.status === "connected") { const { token, articleRevision, channelRevision, profileRevision } = contact; await setCardConnected(node, secure, token, cardId, token, articleRevision, channelRevision, profileRevision); } } - } - catch (err) { - this.log.error('failed to deliver open message'); + } catch (err) { + this.log.error("failed to deliver open message"); } } @@ -702,15 +486,11 @@ export class ContactModule implements Contact { const entry = this.cardEntries.get(cardId); if (entry) { const server = entry.item.profile.node ? entry.item.profile.node : node; - const insecure = - /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test( - server, - ); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); await setCardCloseMessage(server, !insecure, message); } - } - catch (err) { - this.log.warn('failed to deliver close message'); + } catch (err) { + this.log.warn("failed to deliver close message"); } } @@ -728,15 +508,9 @@ export class ContactModule implements Contact { public async setBlockCard(cardId: string): Promise {} - public async setBlockArticle( - cardId: string, - articleId: string, - ): Promise {} + public async setBlockArticle(cardId: string, articleId: string): Promise {} - public async setBlockChannel( - cardId: string, - channelId: string, - ): Promise { + public async setBlockChannel(cardId: string, channelId: string): Promise { const entries = this.channelEntries.get(cardId); if (entries) { const entry = entries.get(channelId); @@ -751,61 +525,33 @@ export class ContactModule implements Contact { public async clearBlockCard(cardId: string): Promise {} - public async clearBlockArticle( - cardId: string, - articleId: string, - ): Promise {} + public async clearBlockArticle(cardId: string, articleId: string): Promise {} - public async clearBlockChannel( - cardId: string, - channelId: string, - ): Promise {} + public async clearBlockChannel(cardId: string, channelId: string): Promise {} public async getBlockedCards(): Promise<{ cardId: string }[]> { return []; } - public async getBlockedChannels(): Promise< - { cardId: string; channelId: string }[] - > { + public async getBlockedChannels(): Promise<{ cardId: string; channelId: string }[]> { return []; } - public async getBlockedArticles(): Promise< - { cardId: string; articleId: string }[] - > { + public async getBlockedArticles(): Promise<{ cardId: string; articleId: string }[]> { return []; } - public async removeArticle( - cardId: string, - articleId: string, - ): Promise {} + public async removeArticle(cardId: string, articleId: string): Promise {} - public async removeChannel( - cardId: string, - channelId: string, - ): Promise {} + public async removeChannel(cardId: string, channelId: string): Promise {} - public async enableChannelNotifications( - cardId: string, - channelId: string, - ): Promise {} + public async enableChannelNotifications(cardId: string, channelId: string): Promise {} - public async disableChannelNotifications( - cardId: string, - channelid: string, - ): Promise {} + public async disableChannelNotifications(cardId: string, channelid: string): Promise {} - public async setUnreadChannel( - cardId: string, - channelId: string, - ): Promise {} + public async setUnreadChannel(cardId: string, channelId: string): Promise {} - public async clearUnreadChannel( - cardId: string, - channelId: string, - ): Promise {} + public async clearUnreadChannel(cardId: string, channelId: string): Promise {} public async getRegistry(server: string): Promise { return []; @@ -819,17 +565,9 @@ export class ContactModule implements Contact { return ""; } - - - - - - - private setCard(cardId: string, item: CardItem): Card { const { offsync, blocked, profile, detail } = item; - const { guid, handle, name, description, location, imageSet, node } = - profile; + const { guid, handle, name, description, location, imageSet, node } = profile; const { status, statusUpdated } = detail; return { cardId, @@ -847,11 +585,7 @@ export class ContactModule implements Contact { }; } - private setArticle( - cardId: string, - articleId: string, - item: ArticleItem, - ): Article { + private setArticle(cardId: string, articleId: string, item: ArticleItem): Article { const { unread, blocked, detail, unsealedData } = item; const { dataType, sealed, data, created, updated } = detail; const articleData = sealed ? unsealedData : data; @@ -866,46 +600,24 @@ export class ContactModule implements Contact { }; } - private async getChannelKey( - seals: [{ publicKey: string; sealedKey: string }], - ): Promise { - const seal = seals.find( - ({ publicKey }) => publicKey === this.seal.publicKey, - ); + private async getChannelKey(seals: [{ publicKey: string; sealedKey: string }]): Promise { + const seal = seals.find(({ publicKey }) => publicKey === this.seal.publicKey); if (seal) { - const key = await this.crypto.rsaDecrypt( - seal.sealedKey, - this.seal.privateKey, - ); + const key = await this.crypto.rsaDecrypt(seal.sealedKey, this.seal.privateKey); return key.data; } return null; } - private async unsealChannelDetail( - cardId: string, - channelId: string, - item: ChannelItem, - ): Promise { - if ( - item.unsealedDetail == null && - item.detail.dataType === "sealed" && - this.seal && - this.crypto - ) { + private async unsealChannelDetail(cardId: string, channelId: string, item: ChannelItem): Promise { + if (item.unsealedDetail == null && item.detail.dataType === "sealed" && this.seal && this.crypto) { try { - const { subjectEncrypted, subjectIv, seals } = JSON.parse( - item.detail.data, - ); + const { subjectEncrypted, subjectIv, seals } = JSON.parse(item.detail.data); if (!item.channelKey) { item.channelKey = await this.getChannelKey(seals); } if (item.channelKey) { - const { data } = await this.crypto.aesDecrypt( - subjectEncrypted, - subjectIv, - item.channelKey, - ); + const { data } = await this.crypto.aesDecrypt(subjectEncrypted, subjectIv, item.channelKey); const { subject } = JSON.parse(data); item.unsealedDetail = subject; return true; @@ -917,17 +629,8 @@ export class ContactModule implements Contact { return false; } - private async unsealChannelSummary( - cardId: string, - channelId: string, - item: ChannelItem, - ): Promise { - if ( - item.unsealedSummary == null && - item.summary.dataType === "sealedtopic" && - this.seal && - this.crypto - ) { + private async unsealChannelSummary(cardId: string, channelId: string, item: ChannelItem): Promise { + if (item.unsealedSummary == null && item.summary.dataType === "sealedtopic" && this.seal && this.crypto) { try { if (!item.channelKey) { const { seals } = JSON.parse(item.detail.data); @@ -935,11 +638,7 @@ export class ContactModule implements Contact { } if (item.channelKey) { const { messageEncrypted, messageIv } = JSON.parse(item.summary.data); - const { data } = await this.crypto.aesDecrypt( - messageEncrypted, - messageIv, - item.channelKey, - ); + const { data } = await this.crypto.aesDecrypt(messageEncrypted, messageIv, item.channelKey); const { message } = JSON.parse(data); item.unsealedSummary = message; return true; @@ -951,17 +650,12 @@ export class ContactModule implements Contact { return false; } - private setChannel( - cardId: string, - channelId: string, - item: ChannelItem, - ): Channel { + private setChannel(cardId: string, channelId: string, item: ChannelItem): Channel { const { summary, detail } = item; const detailData = detail.sealed ? item.unsealedDetail : detail.data; const summaryData = summary.sealed ? item.unsealedSummary : summary.data; - const { pushEnabled } = - detail.members.find(({ member }) => member === this.guid) | {}; + const { pushEnabled } = detail.members.find(({ member }) => member === this.guid) | {}; const contacts = detail.members .filter(({ member }) => member != this.guid) .map(({ member, pushEnabled }) => { @@ -997,8 +691,6 @@ export class ContactModule implements Contact { }; } - - private async getCardEntry(cardId: string) { const { guid } = this; const entry = this.cardEntries.get(cardId); @@ -1023,11 +715,7 @@ export class ContactModule implements Contact { return channels; } - private async getChannelEntry( - channels: Map, - cardId: string, - channelId: string, - ) { + private async getChannelEntry(channels: Map, cardId: string, channelId: string) { const { guid } = this; const entry = channels.get(channelId); if (entry) { @@ -1040,6 +728,4 @@ export class ContactModule implements Contact { await this.store.addContactCardChannel(guid, cardId, channelId, item); return channelEntry; } - - } diff --git a/app/sdk/src/content.ts b/app/sdk/src/content.ts index 8ed9f6c8..59e772fb 100644 --- a/app/sdk/src/content.ts +++ b/app/sdk/src/content.ts @@ -12,15 +12,7 @@ export class ContentModule implements Content { private settings: Settings; private emitter: EventEmitter; - constructor( - log: Logging, - settings: Settings, - store: Store, - guid: string, - token: string, - node: string, - secure: boolean, - ) { + constructor(log: Logging, settings: Settings, store: Store, guid: string, token: string, node: string, secure: boolean) { this.guid = guid; this.token = token; this.node = node; @@ -44,49 +36,23 @@ export class ContentModule implements Content { console.log("set content revision:", rev); } - public async addChannel( - sealed: boolean, - type: string, - subject: string, - cardIds: string[], - groupIds: string[], - ): Promise { + public async addChannel(sealed: boolean, type: string, subject: string, cardIds: string[], groupIds: string[]): Promise { return ""; } public async removeChannel(channelId: string): Promise {} - public async setChannelSubject( - channelId: string, - subject: string, - ): Promise {} + public async setChannelSubject(channelId: string, subject: string): Promise {} - public async setChannelCard( - channelId: string, - cardId: string, - ): Promise {} + public async setChannelCard(channelId: string, cardId: string): Promise {} - public async clearChannelCard( - channelId: string, - cardId: string, - ): Promise {} + public async clearChannelCard(channelId: string, cardId: string): Promise {} - public async setChannelGroup( - channelId: string, - groupId: string, - ): Promise {} + public async setChannelGroup(channelId: string, groupId: string): Promise {} - public async clearChannelGroup( - channelId: string, - groupId: string, - ): Promise {} + public async clearChannelGroup(channelId: string, groupId: string): Promise {} - public async addTopic( - channelId: string, - type: string, - subject: string, - assets: Asset[], - ): Promise { + public async addTopic(channelId: string, type: string, subject: string, assets: Asset[]): Promise { return ""; } @@ -94,162 +60,67 @@ export class ContentModule implements Content { public async flagTopic(channelId: string, topicId: string): Promise {} - public async setTopicSubject( - channelId: string, - topicId: string, - subject: string, - ): Promise {} + public async setTopicSubject(channelId: string, topicId: string, subject: string): Promise {} - public async setTopicSort( - channelId: string, - topicId: string, - sort: number, - ): Promise {} + public async setTopicSort(channelId: string, topicId: string, sort: number): Promise {} - public async addTag( - channelId: string, - topicId: string, - type: string, - value: string, - ): Promise { + public async addTag(channelId: string, topicId: string, type: string, value: string): Promise { return ""; } - public async removeTag( - channelId: string, - topicId: string, - tagId: string, - ): Promise {} + public async removeTag(channelId: string, topicId: string, tagId: string): Promise {} - public async setTagSubject( - channelId: string, - topicId: string, - tagId: string, - subject: string, - ): Promise {} + public async setTagSubject(channelId: string, topicId: string, tagId: string, subject: string): Promise {} - public async setTagSort( - channelId: string, - topicId: string, - tagId: string, - sort: number, - ): Promise {} + public async setTagSort(channelId: string, topicId: string, tagId: string, sort: number): Promise {} - public async flagTag( - channelId: string, - topicId: string, - tagId: string, - ): Promise {} + public async flagTag(channelId: string, topicId: string, tagId: string): Promise {} - public async setBlockTopic( - channelId: string, - topicId: string, - ): Promise {} + public async setBlockTopic(channelId: string, topicId: string): Promise {} - public async setBlockTag( - channelId: string, - topicId: string, - tagId: string, - ): Promise {} + public async setBlockTag(channelId: string, topicId: string, tagId: string): Promise {} - public async clearBlockTopic( - channelId: string, - topicId: string, - ): Promise {} + public async clearBlockTopic(channelId: string, topicId: string): Promise {} - public async clearBlockTag( - channelId: string, - topicId: string, - tagId: string, - ): Promise {} + public async clearBlockTag(channelId: string, topicId: string, tagId: string): Promise {} - public async getBlockedTopics(): Promise< - { channelId: string; topicId: string }[] - > { + public async getBlockedTopics(): Promise<{ channelId: string; topicId: string }[]> { return []; } - public async getBlockedTags(): Promise< - { channelId: string; topicId: string; tagId: string }[] - > { + public async getBlockedTags(): Promise<{ channelId: string; topicId: string; tagId: string }[]> { return []; } - public async enableNotifications( - channelId: string, - memberId: string, - ): Promise {} + public async enableNotifications(channelId: string, memberId: string): Promise {} - public async disableNotifications( - channelId: string, - memberId: string, - ): Promise {} + public async disableNotifications(channelId: string, memberId: string): Promise {} - public async enableSortTopic( - channelId: string, - memberId: string, - ): Promise {} + public async enableSortTopic(channelId: string, memberId: string): Promise {} - public async disableSortTopic( - channelId: string, - memberId: string, - ): Promise {} + public async disableSortTopic(channelId: string, memberId: string): Promise {} - public async enableSortTag( - channelId: string, - memberId: string, - ): Promise {} + public async enableSortTag(channelId: string, memberId: string): Promise {} - public async disableSortTag( - channelId: string, - memberId: string, - ): Promise {} + public async disableSortTag(channelId: string, memberId: string): Promise {} - public async enableAddTopic( - channelId: string, - memberId: string, - ): Promise {} + public async enableAddTopic(channelId: string, memberId: string): Promise {} - public async disableAddTopic( - channelId: string, - memberId: string, - ): Promise {} + public async disableAddTopic(channelId: string, memberId: string): Promise {} - public async enableAddTag( - channelId: string, - memberId: string, - ): Promise {} + public async enableAddTag(channelId: string, memberId: string): Promise {} - public async disableAddTag( - channelId: string, - memberId: string, - ): Promise {} + public async disableAddTag(channelId: string, memberId: string): Promise {} - public async enableAddAsset( - channelId: string, - memberId: string, - ): Promise {} + public async enableAddAsset(channelId: string, memberId: string): Promise {} - public async disableAddAsset( - channelId: string, - memberId: string, - ): Promise {} + public async disableAddAsset(channelId: string, memberId: string): Promise {} - public async enableAddParticipant( - channelId: string, - memberId: string, - ): Promise {} + public async enableAddParticipant(channelId: string, memberId: string): Promise {} - public async disableAddParticipant( - channelId: string, - memberId: string, - ): Promise {} + public async disableAddParticipant(channelId: string, memberId: string): Promise {} - public getTopicAssetUrl( - channelId: string, - topicId: string, - assetId: string, - ): string { + public getTopicAssetUrl(channelId: string, topicId: string, assetId: string): string { return ""; } @@ -273,15 +144,9 @@ export class ContentModule implements Content { public async clearUnreadChannel(channelId: string): Promise {} - public async addParticipantAccess( - channelId: string, - name: string, - ): Promise { + public async addParticipantAccess(channelId: string, name: string): Promise { return { id: "", guid: "", name: "", server: "", token: "" }; } - public async removeParticipantAccess( - channelId: string, - repeaterId: string, - ): Promise {} + public async removeParticipantAccess(channelId: string, repeaterId: string): Promise {} } diff --git a/app/sdk/src/contributor.ts b/app/sdk/src/contributor.ts index adcf2e2c..e0d3b25b 100644 --- a/app/sdk/src/contributor.ts +++ b/app/sdk/src/contributor.ts @@ -10,13 +10,7 @@ export class ContributorModule implements Contributor { private secure: boolean; private token: string; - constructor( - log: Logging, - crypto: Crypto | null, - node: string, - secure: boolean, - token: string, - ) { + constructor(log: Logging, crypto: Crypto | null, node: string, secure: boolean, token: string) { this.log = log; this.crypto = crypto; this.node = node; @@ -24,21 +18,13 @@ export class ContributorModule implements Contributor { this.token = token; } - public async addTopic( - type: string, - message: string, - assets: Asset[], - ): Promise { + public async addTopic(type: string, message: string, assets: Asset[]): Promise { return ""; } public async removeTopic(topicId: string): Promise {} - public async addTag( - topicId: string, - type: string, - value: string, - ): Promise { + public async addTag(topicId: string, type: string, value: string): Promise { return ""; } diff --git a/app/sdk/src/crypto.ts b/app/sdk/src/crypto.ts index 6ecbf754..9ba34e7b 100644 --- a/app/sdk/src/crypto.ts +++ b/app/sdk/src/crypto.ts @@ -12,31 +12,17 @@ export interface Crypto { aesIv(): Promise<{ ivHex: string }>; // encrypt data with aes key and iv - aesEncrypt( - data: string, - ivHex: string, - aesKeyHex: string, - ): Promise<{ encryptedDataB64: string }>; + aesEncrypt(data: string, ivHex: string, aesKeyHex: string): Promise<{ encryptedDataB64: string }>; // decrypt data with aes key and iv - aesDecrypt( - encryptedDataB64: string, - ivHex: string, - aesKeyHex: string, - ): Promise<{ data: string }>; + aesDecrypt(encryptedDataB64: string, ivHex: string, aesKeyHex: string): Promise<{ data: string }>; // generate rsa key rsaKey(): Promise<{ publicKeyB64: string; privateKeyB64: string }>; // encrypt data with public rsa key - rsaEncrypt( - data: string, - publicKeyB64: string, - ): Promise<{ encryptedDataB64: string }>; + rsaEncrypt(data: string, publicKeyB64: string): Promise<{ encryptedDataB64: string }>; // decrypt data with private rsa key - rsaDecrypt( - encryptedDataB64: string, - privateKeyB64: string, - ): Promise<{ data: string }>; + rsaDecrypt(encryptedDataB64: string, privateKeyB64: string): Promise<{ data: string }>; } diff --git a/app/sdk/src/entities.ts b/app/sdk/src/entities.ts index 920411e8..7e7bacda 100644 --- a/app/sdk/src/entities.ts +++ b/app/sdk/src/entities.ts @@ -1,12 +1,12 @@ import type { Profile } from "./types"; export type ContactStatus = { - token: string, - status: string, - viewRevision: number, - channelRevision: number, - profileRevision: number, - articleRevision: number, + token: string; + status: string; + viewRevision: number; + channelRevision: number; + profileRevision: number; + articleRevision: number; }; export type DataMessage = { diff --git a/app/sdk/src/focus.ts b/app/sdk/src/focus.ts index 17e2eebf..7153b5bb 100644 --- a/app/sdk/src/focus.ts +++ b/app/sdk/src/focus.ts @@ -13,15 +13,7 @@ export class FocusModule implements Focus { private log: Logging; private emitter: EventEmitter; - constructor( - log: Logging, - identity: Identity, - contact: Contact, - content: Content, - store: Store, - cardId: string | null, - channelId: string, - ) { + constructor(log: Logging, identity: Identity, contact: Contact, content: Content, store: Store, cardId: string | null, channelId: string) { this.identity = identity; this.contact = contact; this.content = content; @@ -33,58 +25,33 @@ export class FocusModule implements Focus { public blur(): void {} - public async addTopic( - type: string, - message: string, - assets: Asset[], - ): Promise { + public async addTopic(type: string, message: string, assets: Asset[]): Promise { return ""; } public async removeTopic(topicId: string): Promise {} - public async setTopicSubject( - topicId: string, - subject: string, - ): Promise {} + public async setTopicSubject(topicId: string, subject: string): Promise {} public async setTopicSort(topicId: string, sort: number): Promise {} - public async addTag( - topicId: string, - type: string, - subject: string, - ): Promise { + public async addTag(topicId: string, type: string, subject: string): Promise { return ""; } public async removeTag(cardId: string, tagId: string): Promise {} - public async setTagSubject( - topicId: string, - tagId: string, - subject: string, - ): Promise {} + public async setTagSubject(topicId: string, tagId: string, subject: string): Promise {} - public async setTagSort( - topicId: string, - tagId: string, - sort: number, - ): Promise {} + public async setTagSort(topicId: string, tagId: string, sort: number): Promise {} public async viewMoreTopics(): Promise {} public async viewMoreTags(topicId: string): Promise {} - public async setUnreadChannel( - cardId: string, - channelId: string, - ): Promise {} + public async setUnreadChannel(cardId: string, channelId: string): Promise {} - public async clearUnreadChannel( - cardId: string, - channelId: string, - ): Promise {} + public async clearUnreadChannel(cardId: string, channelId: string): Promise {} public getTopicAssetUrl(topicId: string, assetId: string): string { return ""; diff --git a/app/sdk/src/identity.ts b/app/sdk/src/identity.ts index 259e0167..93fb520d 100644 --- a/app/sdk/src/identity.ts +++ b/app/sdk/src/identity.ts @@ -27,14 +27,7 @@ export class IdentityModule implements Identity { private closing: boolean; private emitter: EventEmitter; - constructor( - log: Logging, - store: Store, - guid: string, - token: string, - node: string, - secure: boolean, - ) { + constructor(log: Logging, store: Store, guid: string, token: string, node: string, secure: boolean) { this.guid = guid; this.token = token; this.node = node; @@ -99,18 +92,7 @@ export class IdentityModule implements Identity { } public setProfile() { - const { - guid, - handle, - name, - description, - location, - image, - revision, - seal, - version, - node, - } = this.profile; + const { guid, handle, name, description, location, image, revision, seal, version, node } = this.profile; return { guid, handle, @@ -145,11 +127,7 @@ export class IdentityModule implements Identity { await this.sync(); } - public async setProfileData( - name: string, - location: string, - description: string, - ): Promise { + public async setProfileData(name: string, location: string, description: string): Promise { const { node, secure, token } = this; await setProfileData(node, secure, token, name, location, description); } diff --git a/app/sdk/src/index.ts b/app/sdk/src/index.ts index 8c97315a..f185d2c9 100644 --- a/app/sdk/src/index.ts +++ b/app/sdk/src/index.ts @@ -40,79 +40,28 @@ export class DatabagSDK { const { articleTypes, channelTypes } = this.params; this.store = new OfflineStore(this.log, sql); const login = await this.store.init(); - return login - ? new SessionModule( - this.store, - this.crypto, - this.log, - login.guid, - login.token, - login.node, - login.secure, - login.timestamp, - articleTypes, - channelTypes, - ) - : null; + return login ? new SessionModule(this.store, this.crypto, this.log, login.guid, login.token, login.node, login.secure, login.timestamp, articleTypes, channelTypes) : null; } public async initOnlineStore(web: WebStore): Promise { const { articleTypes, 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, - login.guid, - login.token, - login.node, - login.secure, - login.timestamp, - articleTypes, - channelTypes, - ) - : null; + return login ? new SessionModule(this.store, this.crypto, this.log, login.guid, login.token, login.node, login.secure, login.timestamp, articleTypes, channelTypes) : null; } public async available(node: string, secure: boolean): Promise { return await getAvailable(node, secure); } - public async username( - name: string, - token: string, - node: string, - secure: boolean, - ): Promise { + public async username(name: string, token: string, node: string, secure: boolean): Promise { return await getUsername(name, token, null, node, secure); } - public async login( - handle: string, - password: string, - node: string, - secure: boolean, - mfaCode: string | null, - params: SessionParams, - ): Promise { + public async login(handle: string, password: string, node: string, secure: boolean, mfaCode: string | null, params: SessionParams): Promise { const { articleTypes, 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 { 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 = { guid, node, @@ -122,40 +71,13 @@ export class DatabagSDK { pushSupported, }; await this.store.setLogin(login); - return new SessionModule( - this.store, - this.crypto, - this.log, - guid, - appToken, - node, - secure, - created, - articleTypes, - channelTypes, - ); + return new SessionModule(this.store, this.crypto, this.log, guid, appToken, node, secure, created, articleTypes, channelTypes); } - public async access( - node: string, - secure: boolean, - token: string, - params: SessionParams, - ): Promise { + public async access(node: string, secure: boolean, token: string, params: SessionParams): Promise { const { articleTypes, 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 { 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 = { guid, node, @@ -165,45 +87,14 @@ export class DatabagSDK { pushSupported, }; await this.store.setLogin(login); - return new SessionModule( - this.store, - this.crypto, - this.log, - guid, - appToken, - node, - secure, - created, - articleTypes, - channelTypes, - ); + return new SessionModule(this.store, this.crypto, this.log, guid, appToken, node, secure, created, articleTypes, channelTypes); } - public async create( - handle: string, - password: string, - node: string, - secure: boolean, - token: string | null, - params: SessionParams, - ): Promise { + public async create(handle: string, password: string, node: string, secure: boolean, token: string | null, params: SessionParams): Promise { const { articleTypes, 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, - ); + 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); const login: Login = { guid, node, @@ -213,18 +104,7 @@ export class DatabagSDK { pushSupported, }; await this.store.setLogin(login); - return new SessionModule( - this.store, - this.crypto, - this.log, - guid, - appToken, - node, - secure, - created, - articleTypes, - channelTypes, - ); + return new SessionModule(this.store, this.crypto, this.log, guid, appToken, node, secure, created, articleTypes, channelTypes); } public async remove(session: Session): Promise { @@ -255,21 +135,12 @@ export class DatabagSDK { }); } - public async configure( - node: string, - secure: boolean, - token: string, - mfaCode: string | null, - ): Promise { + public async configure(node: string, secure: boolean, token: string, mfaCode: string | null): Promise { const access = await setAdmin(node, secure, token, mfaCode); return new NodeModule(this.log, node, secure, token); } - public async automate( - node: string, - secure: boolean, - token: string, - ): Promise { + public async automate(node: string, secure: boolean, token: string): Promise { return new ContributorModule(this.log, this.crypto, node, secure, token); } } diff --git a/app/sdk/src/net/addAccount.ts b/app/sdk/src/net/addAccount.ts index 7097c59e..48b3e460 100644 --- a/app/sdk/src/net/addAccount.ts +++ b/app/sdk/src/net/addAccount.ts @@ -1,22 +1,12 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; import { encode } from "./base64"; -export async function addAccount( - node: string, - secure: boolean, - username: string, - password: string, - token: string | null, -): Promise { +export async function addAccount(node: string, secure: boolean, username: string, password: string, token: string | null): Promise { const access = token ? `?token=${token}` : ""; const endpoint = `http${secure ? "s" : ""}://${node}/account/profile${access}`; const auth = encode(`${username}:${password}`); const headers = new Headers(); headers.append("Credentials", `Basic ${auth}`); - const { status } = await fetchWithTimeout( - endpoint, - { method: "POST", headers }, - 60000, - ); + const { status } = await fetchWithTimeout(endpoint, { method: "POST", headers }, 60000); checkResponse(status); } diff --git a/app/sdk/src/net/addAccountMFAuth.ts b/app/sdk/src/net/addAccountMFAuth.ts index c18e6247..6dc34150 100644 --- a/app/sdk/src/net/addAccountMFAuth.ts +++ b/app/sdk/src/net/addAccountMFAuth.ts @@ -1,10 +1,6 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function addAccountMFAuth( - node: string, - secure: boolean, - token: string, -): Promise<{ secretText: string; secretImage: string }> { +export async function addAccountMFAuth(node: string, secure: boolean, token: string): Promise<{ secretText: string; secretImage: string }> { const endpoint = `http${secure ? "s" : ""}://${node}/account/mfauth?agent=${token}`; const auth = await fetchWithTimeout(endpoint, { method: "POST" }); checkResponse(auth.status); diff --git a/app/sdk/src/net/addCard.ts b/app/sdk/src/net/addCard.ts index 41c431d6..c9f6b934 100644 --- a/app/sdk/src/net/addCard.ts +++ b/app/sdk/src/net/addCard.ts @@ -1,11 +1,6 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function addCard( - node: string, - secure: boolean, - token: string, - message: string, -) { +export async function addCard(node: string, secure: boolean, token: string, message: string) { const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards?agent=${token}`; const { status } = await fetchWithTimeout(endpoint, { method: "POST", diff --git a/app/sdk/src/net/base64.ts b/app/sdk/src/net/base64.ts index d4f1e358..f5c920f6 100644 --- a/app/sdk/src/net/base64.ts +++ b/app/sdk/src/net/base64.ts @@ -3,8 +3,7 @@ export function encode(input: string) { let chr1, chr2, chr3, enc1, enc2, enc3, enc4; let i = 0; - const _keyStr = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + const _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; input = _utf8_encode(input); @@ -24,12 +23,7 @@ export function encode(input: string) { enc4 = 64; } - output = - output + - _keyStr.charAt(enc1) + - _keyStr.charAt(enc2) + - _keyStr.charAt(enc3) + - _keyStr.charAt(enc4); + output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4); } return output; diff --git a/app/sdk/src/net/clearAccountSeal.ts b/app/sdk/src/net/clearAccountSeal.ts index 3befb49d..ceb0664c 100644 --- a/app/sdk/src/net/clearAccountSeal.ts +++ b/app/sdk/src/net/clearAccountSeal.ts @@ -1,10 +1,6 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function clearAccountSeal( - node: string, - secure: boolean, - token: string, -) { +export async function clearAccountSeal(node: string, secure: boolean, token: string) { const endpoint = `http${secure ? "s" : ""}://${node}/account/seal?agent=${token}`; const seal = await fetchWithTimeout(endpoint, { method: "DELETE" }); checkResponse(seal.status); diff --git a/app/sdk/src/net/clearLogin.ts b/app/sdk/src/net/clearLogin.ts index 74060d76..4f0c156d 100644 --- a/app/sdk/src/net/clearLogin.ts +++ b/app/sdk/src/net/clearLogin.ts @@ -1,11 +1,6 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function clearLogin( - node: string, - secure: boolean, - token: string, - all: boolean, -): Promise { +export async function clearLogin(node: string, secure: boolean, token: string, all: boolean): Promise { const param = all ? "&all=true" : ""; const endpoint = `http${secure ? "s" : ""}://${node}/account/apps?agent=${token}${param}`; const { status } = await fetchWithTimeout(endpoint, { method: "DELETE" }); diff --git a/app/sdk/src/net/fetchUtil.ts b/app/sdk/src/net/fetchUtil.ts index cf94323f..9b9557b1 100644 --- a/app/sdk/src/net/fetchUtil.ts +++ b/app/sdk/src/net/fetchUtil.ts @@ -8,17 +8,11 @@ export function checkResponse(code: number) { } } -export async function fetchWithTimeout( - url: string, - options: RequestInit, - timeout: number = TIMEOUT, -): Promise { +export async function fetchWithTimeout(url: string, options: RequestInit, timeout: number = TIMEOUT): Promise { return Promise.race([ fetch(url, options).catch((err) => { throw new Error(url + " failed"); }), - new Promise((_, reject) => - setTimeout(() => reject(new Error(url + " timeout")), TIMEOUT), - ), + new Promise((_, reject) => setTimeout(() => reject(new Error(url + " timeout")), TIMEOUT)), ]); } diff --git a/app/sdk/src/net/getAccountStatus.ts b/app/sdk/src/net/getAccountStatus.ts index eede0927..3f6ee221 100644 --- a/app/sdk/src/net/getAccountStatus.ts +++ b/app/sdk/src/net/getAccountStatus.ts @@ -1,11 +1,7 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; import { ConfigEntity } from "../entities"; -export async function getAccountStatus( - node: string, - secure: boolean, - token: string, -): Promise { +export async function getAccountStatus(node: string, secure: boolean, token: string): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/account/status?agent=${token}`; const status = await fetchWithTimeout(endpoint, { method: "GET" }); checkResponse(status.status); diff --git a/app/sdk/src/net/getAvailable.ts b/app/sdk/src/net/getAvailable.ts index 0b34ad31..122cb3ef 100644 --- a/app/sdk/src/net/getAvailable.ts +++ b/app/sdk/src/net/getAvailable.ts @@ -1,9 +1,6 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function getAvailable( - node: string, - secure: boolean, -): Promise { +export async function getAvailable(node: string, secure: boolean): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/account/available`; const available = await fetchWithTimeout(endpoint, { method: "GET" }); checkResponse(available.status); diff --git a/app/sdk/src/net/getCardCloseMessage.ts b/app/sdk/src/net/getCardCloseMessage.ts index 7444c84f..1087f14a 100644 --- a/app/sdk/src/net/getCardCloseMessage.ts +++ b/app/sdk/src/net/getCardCloseMessage.ts @@ -1,8 +1,7 @@ -import { checkResponse, fetchWithTimeout } from './fetchUtil'; +import { checkResponse, fetchWithTimeout } from "./fetchUtil"; export async function getCardCloseMessage(node: string, secure: boolean): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/contact/closeMessage`; const close = await fetchWithTimeout(endpoint, { method: "GET" }); checkResponse(close.status); } - diff --git a/app/sdk/src/net/getCardDetail.ts b/app/sdk/src/net/getCardDetail.ts index 0db78dce..e9adb032 100644 --- a/app/sdk/src/net/getCardDetail.ts +++ b/app/sdk/src/net/getCardDetail.ts @@ -1,12 +1,7 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; import { CardDetailEntity } from "../entities"; -export async function getCardDetail( - node: string, - secure: boolean, - token: string, - cardId: string, -): Promise { +export async function getCardDetail(node: string, secure: boolean, token: string, cardId: string): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards/${cardId}/detail?agent=${token}`; const detail = await fetchWithTimeout(endpoint, { method: "GET" }); checkResponse(detail.status); diff --git a/app/sdk/src/net/getCardOpenMessage.ts b/app/sdk/src/net/getCardOpenMessage.ts index 01116910..8e53f1b1 100644 --- a/app/sdk/src/net/getCardOpenMessage.ts +++ b/app/sdk/src/net/getCardOpenMessage.ts @@ -1,9 +1,8 @@ -import { checkResponse, fetchWithTimeout } from './fetchUtil'; -import { CardStatus } from '../entities'; +import { checkResponse, fetchWithTimeout } from "./fetchUtil"; +import { CardStatus } from "../entities"; export async function getCardOpenMessage(node: string, secure: boolean): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/contact/openMessage`; const open = await fetchWithTimeout(endpoint, { method: "GET" }); checkResponse(open.status); } - diff --git a/app/sdk/src/net/getCardProfile.ts b/app/sdk/src/net/getCardProfile.ts index 9e93fbda..2144b22c 100644 --- a/app/sdk/src/net/getCardProfile.ts +++ b/app/sdk/src/net/getCardProfile.ts @@ -1,12 +1,7 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; import { CardProfileEntity } from "../entities"; -export async function getCardProfile( - node: string, - secure: boolean, - token: string, - cardId: string, -): Promise { +export async function getCardProfile(node: string, secure: boolean, token: string, cardId: string): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards/${cardId}/profile?agent=${token}`; const profile = await fetchWithTimeout(endpoint, { method: "GET" }); checkResponse(profile.status); diff --git a/app/sdk/src/net/getCards.ts b/app/sdk/src/net/getCards.ts index b010eb3f..984db2c8 100644 --- a/app/sdk/src/net/getCards.ts +++ b/app/sdk/src/net/getCards.ts @@ -1,12 +1,7 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; import { CardEntity } from "../entities"; -export async function getCards( - node: string, - secure: boolean, - token: string, - revision: number, -): Promise { +export async function getCards(node: string, secure: boolean, token: string, revision: number): Promise { const param = revision ? `&revision=${revision}` : ""; const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards?agent=${token}${param}`; const cards = await fetchWithTimeout(endpoint, { method: "GET" }); diff --git a/app/sdk/src/net/getContactChannelDetail.ts b/app/sdk/src/net/getContactChannelDetail.ts index d85cc4c1..acdcef6e 100644 --- a/app/sdk/src/net/getContactChannelDetail.ts +++ b/app/sdk/src/net/getContactChannelDetail.ts @@ -1,12 +1,7 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; import { ChannelDetailEntity } from "../entities"; -export async function getContactChannelDetail( - server: string, - secure: boolean, - token: string, - channelId: string, -): Promise { +export async function getContactChannelDetail(server: string, secure: boolean, token: string, channelId: string): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/content/channels/${channelId}/detail?contact=${guid}.${token}`; const detail = await fetchWithTimeout(endpoint, { method: "GET" }); checkResponse(detail.status); diff --git a/app/sdk/src/net/getContactChannelSummary.ts b/app/sdk/src/net/getContactChannelSummary.ts index d27603e2..66bd06df 100644 --- a/app/sdk/src/net/getContactChannelSummary.ts +++ b/app/sdk/src/net/getContactChannelSummary.ts @@ -1,12 +1,7 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; import { ChannelSummaryEntity } from "../entities"; -export async function getContactChannelSummary( - server: string, - secure: boolean, - token: string, - channelId: string, -): Promise { +export async function getContactChannelSummary(server: string, secure: boolean, token: string, channelId: string): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/content/channels/${channelId}/summary?contact=${guid}.${token}`; const summary = await fetchWithTimeout(endpoint, { method: "GET" }); checkResponse(summary.status); diff --git a/app/sdk/src/net/getContactChannels.ts b/app/sdk/src/net/getContactChannels.ts index 2d840289..0ee3ee8f 100644 --- a/app/sdk/src/net/getContactChannels.ts +++ b/app/sdk/src/net/getContactChannels.ts @@ -1,18 +1,9 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; import { ChannelEntity } from "../entities"; -export async function getContactChannels( - node: string, - secure: boolean, - guid: string, - token: string, - revision: number, - types: string[], -): Promise { +export async function getContactChannels(node: string, secure: boolean, guid: string, token: string, revision: number, types: string[]): Promise { const type = `types=${encodeURIComponent(JSON.stringify(types))}`; - const param = revision - ? `viewRevision=1&channelRevision=${revision}` - : `viewRevision=1`; + const param = revision ? `viewRevision=1&channelRevision=${revision}` : `viewRevision=1`; const endpoint = `http${secure ? "s" : ""}://${node}/content/channels?contact=${guid}.${token}&${param}&${type}`; const channels = await fetchWithTimeout(endpoint, { method: "GET" }); checkResponse(channels.status); diff --git a/app/sdk/src/net/getContactListing.ts b/app/sdk/src/net/getContactListing.ts index 558a91b9..69ba7e47 100644 --- a/app/sdk/src/net/getContactListing.ts +++ b/app/sdk/src/net/getContactListing.ts @@ -1,11 +1,7 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; import { DataMessage } from "../entities"; -export async function getContactListing( - node: string, - secure: boolean, - guid: string -): Promise { +export async function getContactListing(node: string, secure: boolean, guid: string): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/account/listing/${guid}/message`; const listing = await fetchWithTimeout(endpoint, { method: "GET" }); checkResponse(listing.status); diff --git a/app/sdk/src/net/getContactProfile.ts b/app/sdk/src/net/getContactProfile.ts index d4643dd4..e6245d44 100644 --- a/app/sdk/src/net/getContactProfile.ts +++ b/app/sdk/src/net/getContactProfile.ts @@ -1,12 +1,7 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; import { DataMessage } from "../entities"; -export async function getContactProfile( - node: string, - secure: boolean, - guid: string, - token: string, -): Promise { +export async function getContactProfile(node: string, secure: boolean, guid: string, token: string): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/profile/message?contact=${guid}.${token}`; const profile = await fetchWithTimeout(endpoint, { method: "GET" }); checkResponse(profile.status); diff --git a/app/sdk/src/net/getProfile.ts b/app/sdk/src/net/getProfile.ts index e9229da9..8d660458 100644 --- a/app/sdk/src/net/getProfile.ts +++ b/app/sdk/src/net/getProfile.ts @@ -1,11 +1,7 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; import { ProfileEntity } from "../entities"; -export async function getProfile( - node: string, - secure: boolean, - token: string, -): Promise { +export async function getProfile(node: string, secure: boolean, token: string): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/profile?agent=${token}`; const profile = await fetchWithTimeout(endpoint, { method: "GET" }); checkResponse(profile.status); diff --git a/app/sdk/src/net/getProfileImageUrl.ts b/app/sdk/src/net/getProfileImageUrl.ts index 238ae1ac..fb37f507 100644 --- a/app/sdk/src/net/getProfileImageUrl.ts +++ b/app/sdk/src/net/getProfileImageUrl.ts @@ -1,8 +1,3 @@ -export function getProfileImageUrl( - node: string, - secure: boolean, - token: string, - revision: number, -) { +export function getProfileImageUrl(node: string, secure: boolean, token: string, revision: number) { return `http${secure ? "s" : ""}://${node}/profile/image?agent=${token}&revision=${revision}`; } diff --git a/app/sdk/src/net/getUsername.ts b/app/sdk/src/net/getUsername.ts index 40313b37..ba1eca9e 100644 --- a/app/sdk/src/net/getUsername.ts +++ b/app/sdk/src/net/getUsername.ts @@ -1,12 +1,6 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function getUsername( - name: string, - token: string | null, - agent: string | null, - node: string, - secure: boolean, -): Promise { +export async function getUsername(name: string, token: string | null, agent: string | null, node: string, secure: boolean): Promise { const param = token ? `&token=${token}` : agent ? `&agent=${agent}` : ""; const username = encodeURIComponent(name); const endpoint = `http${secure ? "s" : ""}://${node}/account/username?name=${username}${param}`; diff --git a/app/sdk/src/net/removeAccount.ts b/app/sdk/src/net/removeAccount.ts index 9a5401cb..209da9d3 100644 --- a/app/sdk/src/net/removeAccount.ts +++ b/app/sdk/src/net/removeAccount.ts @@ -1,10 +1,6 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function removeAccount( - node: string, - secure: boolean, - token: string, -): Promise { +export async function removeAccount(node: string, secure: boolean, token: string): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/profile?agent=${token}`; const { status } = await fetchWithTimeout(endpoint, { method: "DELETE" }); checkResponse(status); diff --git a/app/sdk/src/net/removeAccountMFAuth.ts b/app/sdk/src/net/removeAccountMFAuth.ts index a5cee4c1..19c1ae8d 100644 --- a/app/sdk/src/net/removeAccountMFAuth.ts +++ b/app/sdk/src/net/removeAccountMFAuth.ts @@ -1,10 +1,6 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function removeAccountMFAuth( - node: string, - secure: boolean, - token: string, -) { +export async function removeAccountMFAuth(node: string, secure: boolean, token: string) { const endpoint = `http${secure ? "s" : ""}://${node}/account/mfauth?agent=${token}`; const { status } = await fetchWithTimeout(endpoint, { method: "DELETE" }); checkResponse(status); diff --git a/app/sdk/src/net/removeCard.ts b/app/sdk/src/net/removeCard.ts index e537e290..244656cb 100644 --- a/app/sdk/src/net/removeCard.ts +++ b/app/sdk/src/net/removeCard.ts @@ -1,11 +1,6 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function removeAccount( - node: string, - secure: boolean, - token: string, - cardId: string, -): Promise { +export async function removeAccount(node: string, secure: boolean, token: string, cardId: string): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards/${cardId}?agent=${token}`; const { status } = await fetchWithTimeout(endpoint, { method: "DELETE" }); checkResponse(status); diff --git a/app/sdk/src/net/setAccountLogin.ts b/app/sdk/src/net/setAccountLogin.ts index c55d69f0..a25b44e8 100644 --- a/app/sdk/src/net/setAccountLogin.ts +++ b/app/sdk/src/net/setAccountLogin.ts @@ -1,13 +1,7 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; import { encode } from "./base64"; -export async function setAccountLogin( - node: string, - secure: boolean, - token: string, - username: string, - password: string, -) { +export async function setAccountLogin(node: string, secure: boolean, token: string, username: string, password: string) { const endpoint = `http${secure ? "s" : ""}://${node}/account/login?agent=${token}`; const auth = encode(`${username}:${password}`); const headers = new Headers(); diff --git a/app/sdk/src/net/setAccountMFAuth.ts b/app/sdk/src/net/setAccountMFAuth.ts index b5d6940d..61eb393e 100644 --- a/app/sdk/src/net/setAccountMFAuth.ts +++ b/app/sdk/src/net/setAccountMFAuth.ts @@ -1,11 +1,6 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function setAccountMFAuth( - node: string, - secure: boolean, - token: string, - code: string, -) { +export async function setAccountMFAuth(node: string, secure: boolean, token: string, code: string) { const endpoint = `http${secure ? "s" : ""}://${node}/account/mfauth?agent=${token}&code=${code}`; const { status } = await fetchWithTimeout(endpoint, { method: "PUT" }); checkResponse(status); diff --git a/app/sdk/src/net/setAccountNotifications.ts b/app/sdk/src/net/setAccountNotifications.ts index 4815db20..785e9f55 100644 --- a/app/sdk/src/net/setAccountNotifications.ts +++ b/app/sdk/src/net/setAccountNotifications.ts @@ -1,11 +1,6 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function setAccountNotifications( - node: string, - secure: boolean, - token: string, - flag: boolean, -) { +export async function setAccountNotifications(node: string, secure: boolean, token: string, flag: boolean) { const endpoint = `http${secure ? "s" : ""}://${node}/account/notification?agent=${token}`; const { status } = await fetchWithTimeout(endpoint, { method: "PUT", diff --git a/app/sdk/src/net/setAccountSeal.ts b/app/sdk/src/net/setAccountSeal.ts index d52a51ef..4ff60b4a 100644 --- a/app/sdk/src/net/setAccountSeal.ts +++ b/app/sdk/src/net/setAccountSeal.ts @@ -1,12 +1,7 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; import { SealEntity } from "../entities"; -export async function setAccountSeal( - node: string, - secure: boolean, - token: string, - seal: SealEntity, -) { +export async function setAccountSeal(node: string, secure: boolean, token: string, seal: SealEntity) { const endpoint = `http${secure ? "s" : ""}://${node}/account/seal?agent=${token}`; const { status } = await fetchWithTimeout(endpoint, { method: "PUT", diff --git a/app/sdk/src/net/setAccountSearchable.ts b/app/sdk/src/net/setAccountSearchable.ts index 92527393..2d21e91b 100644 --- a/app/sdk/src/net/setAccountSearchable.ts +++ b/app/sdk/src/net/setAccountSearchable.ts @@ -1,11 +1,6 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function setAccountSearchable( - node: string, - secure: boolean, - token: string, - flag: boolean, -) { +export async function setAccountSearchable(node: string, secure: boolean, token: string, flag: boolean) { const endpoint = `http${secure ? "s" : ""}://${node}/account/searchable?agent=${token}`; const { status } = await fetchWithTimeout(endpoint, { method: "PUT", diff --git a/app/sdk/src/net/setAdmin.ts b/app/sdk/src/net/setAdmin.ts index 89436707..4b879591 100644 --- a/app/sdk/src/net/setAdmin.ts +++ b/app/sdk/src/net/setAdmin.ts @@ -1,11 +1,6 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function setAdmin( - node: string, - secure: boolean, - token: string, - mfaCode: string | null, -): Promise { +export async function setAdmin(node: string, secure: boolean, token: string, mfaCode: string | null): Promise { const mfa = mfaCode ? `&code=${mfaCode}` : ""; const endpoint = `http${secure ? "s" : ""}://${node}/admin/access?token=${encodeURIComponent(token)}${mfa}`; const admin = await fetchWithTimeout(endpoint, { method: "PUT" }); diff --git a/app/sdk/src/net/setCardCloseMessage.ts b/app/sdk/src/net/setCardCloseMessage.ts index b3ffed5f..845a0f22 100644 --- a/app/sdk/src/net/setCardCloseMessage.ts +++ b/app/sdk/src/net/setCardCloseMessage.ts @@ -1,8 +1,7 @@ -import { checkResponse, fetchWithTimeout } from './fetchUtil'; +import { checkResponse, fetchWithTimeout } from "./fetchUtil"; export async function setCardCloseMessage(node: string, secure: boolean, message: string): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/contact/closeMessage`; - const close = await fetchWithTimeout(endpoint, { method: "PUT", JSON.stringify(message) }); + const close = await fetchWithTimeout(endpoint, { method: "PUT", body: JSON.stringify(message) }); checkResponse(close.status); } - diff --git a/app/sdk/src/net/setCardConfirmed.ts b/app/sdk/src/net/setCardConfirmed.ts index 462ccf9b..4b2b7029 100644 --- a/app/sdk/src/net/setCardConfirmed.ts +++ b/app/sdk/src/net/setCardConfirmed.ts @@ -1,15 +1,10 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function setCardConfirmed( - node: string, - secure: boolean, - token: string, - cardId: string, -): Promise { +export async function setCardConfirmed(node: string, secure: boolean, token: string, cardId: string): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards/${cardId}/status?agent=${token}`; const { status } = await fetchWithTimeout(endpoint, { method: "PUT", - body: JSON.stringify('confirmed'), + body: JSON.stringify("confirmed"), }); checkResponse(status); } diff --git a/app/sdk/src/net/setCardConnected.ts b/app/sdk/src/net/setCardConnected.ts index f07aea33..4d0b8d4c 100644 --- a/app/sdk/src/net/setCardConnected.ts +++ b/app/sdk/src/net/setCardConnected.ts @@ -1,19 +1,10 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function setCardConnected( - node: string, - secure: boolean, - token: string, - cardId: string, - access: string, - article: number, - channel: number, - profile: number, -): Promise { - const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards/${cardId}/status?agent=${token}&token=${access}&viewRevision=1&articleRevision=${article}&channelRevision=${channel}&profileRevision=${profile}` +export async function setCardConnected(node: string, secure: boolean, token: string, cardId: string, access: string, article: number, channel: number, profile: number): Promise { + const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards/${cardId}/status?agent=${token}&token=${access}&viewRevision=1&articleRevision=${article}&channelRevision=${channel}&profileRevision=${profile}`; const { status } = await fetchWithTimeout(endpoint, { method: "PUT", - body: JSON.stringify('connecting'), + body: JSON.stringify("connecting"), }); checkResponse(status); } diff --git a/app/sdk/src/net/setCardConnecting.ts b/app/sdk/src/net/setCardConnecting.ts index e23c4600..85b5133a 100644 --- a/app/sdk/src/net/setCardConnecting.ts +++ b/app/sdk/src/net/setCardConnecting.ts @@ -1,15 +1,10 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function setCardConnecting( - node: string, - secure: boolean, - token: string, - cardId: string, -): Promise { +export async function setCardConnecting(node: string, secure: boolean, token: string, cardId: string): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards/${cardId}/status?agent=${token}`; const { status } = await fetchWithTimeout(endpoint, { method: "PUT", - body: JSON.stringify('connecting'), + body: JSON.stringify("connecting"), }); checkResponse(status); } diff --git a/app/sdk/src/net/setCardOpenMessage.ts b/app/sdk/src/net/setCardOpenMessage.ts index ec4de1fe..4b3e365f 100644 --- a/app/sdk/src/net/setCardOpenMessage.ts +++ b/app/sdk/src/net/setCardOpenMessage.ts @@ -1,8 +1,7 @@ -import { checkResponse, fetchWithTimeout } from './fetchUtil'; +import { checkResponse, fetchWithTimeout } from "./fetchUtil"; export async function setCardOpenMessage(node: string, secure: boolean, message: string): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/contact/openMessage`; - const open = await fetchWithTimeout(endpoint, { method: "PUT", JSON.stringify(message) }); + const open = await fetchWithTimeout(endpoint, { method: "PUT", body: JSON.stringify(message) }); checkResponse(open.status); } - diff --git a/app/sdk/src/net/setCardProfile.ts b/app/sdk/src/net/setCardProfile.ts index 865d0319..3fb9808b 100644 --- a/app/sdk/src/net/setCardProfile.ts +++ b/app/sdk/src/net/setCardProfile.ts @@ -1,13 +1,7 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; import { DataMessage } from "./entities"; -export async function setCardProfile( - node: string, - secure: boolean, - token: string, - cardId: string, - data: DataMessage, -): Promise { +export async function setCardProfile(node: string, secure: boolean, token: string, cardId: string, data: DataMessage): Promise { const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards/${cardId}/profile?agent=${token}`; const { status } = await fetchWithTimeout(endpoint, { method: "PUT", diff --git a/app/sdk/src/net/setProfileData.ts b/app/sdk/src/net/setProfileData.ts index 8261a0e7..628438e7 100644 --- a/app/sdk/src/net/setProfileData.ts +++ b/app/sdk/src/net/setProfileData.ts @@ -1,18 +1,8 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function setProfileData( - node: string, - secure: boolean, - token: string, - name: string, - location: string, - description: string, -): Promise { +export async function setProfileData(node: string, secure: boolean, token: string, name: string, location: string, description: string): Promise { const data = { name: name, location: location, description: description }; const endpoint = `http${secure ? "s" : ""}://${node}/profile/data?agent=${token}`; - const { status } = await fetchWithTimeout(endpoint, { - method: "PUT", - body: JSON.stringify(data), - }); + const { status } = await fetchWithTimeout(endpoint, { method: "PUT", body: JSON.stringify(data) }); checkResponse(status); } diff --git a/app/sdk/src/net/setProfileImage.ts b/app/sdk/src/net/setProfileImage.ts index 2a831eff..b90c5756 100644 --- a/app/sdk/src/net/setProfileImage.ts +++ b/app/sdk/src/net/setProfileImage.ts @@ -1,11 +1,6 @@ import { checkResponse, fetchWithTimeout } from "./fetchUtil"; -export async function setProfileImage( - node: string, - secure: boolean, - token: string, - image: string, -) { +export async function setProfileImage(node: string, secure: boolean, token: string, image: string) { const endpoint = `http${secure ? "s" : ""}://${node}/profile/image?agent=${token}`; const { status } = await fetchWithTimeout(endpoint, { method: "PUT", diff --git a/app/sdk/src/session.ts b/app/sdk/src/session.ts index 73cffa1c..595957d3 100644 --- a/app/sdk/src/session.ts +++ b/app/sdk/src/session.ts @@ -12,18 +12,7 @@ import { RingModule } from "./ring"; import { Connection } from "./connection"; -import type { - Session, - Settings, - Identity, - Contact, - Ring, - Alias, - Attribute, - Content, - Stream, - Focus, -} from "./api"; +import type { Session, Settings, Identity, Contact, Ring, Alias, Attribute, Content, Stream, Focus } from "./api"; import { Revision } from "./entities"; import { Call } from "./types"; import { Store } from "./store"; @@ -53,18 +42,7 @@ export class SessionModule implements Session { private channelTypes: string[]; private articleTypes: string[]; - constructor( - store: Store, - crypto: Crypto | null, - log: Logging, - guid: string, - token: string, - node: string, - secure: boolean, - loginTimestamp: number, - channelTypes: string[], - articleTypes: string[], - ) { + constructor(store: Store, crypto: Crypto | null, log: Logging, guid: string, token: string, node: string, secure: boolean, loginTimestamp: number, channelTypes: string[], articleTypes: string[]) { log.info("new databag session"); this.store = store; @@ -80,68 +58,13 @@ export class SessionModule implements Session { this.status = "connecting"; this.emitter = new EventEmitter(); - this.identity = new IdentityModule( - log, - this.store, - guid, - token, - node, - secure, - ); - this.settings = new SettingsModule( - log, - this.store, - this.crypto, - guid, - token, - node, - secure, - ); - this.contact = new ContactModule( - log, - this.store, - this.crypto, - guid, - token, - node, - secure, - channelTypes, - articleTypes, - ); - this.alias = new AliasModule( - log, - this.settings, - this.store, - guid, - token, - node, - secure, - ); - this.attribute = new AttributeModule( - log, - this.settings, - this.store, - guid, - token, - node, - secure, - ); - this.content = new ContentModule( - log, - this.settings, - this.store, - guid, - token, - node, - secure, - ); - this.stream = new StreamModule( - log, - this.contact, - this.content, - this.store, - guid, - ); + this.identity = new IdentityModule(log, this.store, guid, token, node, secure); + this.settings = new SettingsModule(log, this.store, this.crypto, guid, token, node, secure); + this.contact = new ContactModule(log, this.store, this.crypto, guid, token, node, secure, channelTypes, articleTypes); + this.alias = new AliasModule(log, this.settings, this.store, guid, token, node, secure); + this.attribute = new AttributeModule(log, this.settings, this.store, guid, token, node, secure); + this.content = new ContentModule(log, this.settings, this.store, guid, token, node, secure); + this.stream = new StreamModule(log, this.contact, this.content, this.store, guid); this.ring = new RingModule(log); this.connection = new Connection(log, token, node, secure); @@ -234,15 +157,7 @@ export class SessionModule implements Session { } public addFocus(cardId: string | null, channelId: string): Focus { - return new FocusModule( - this.log, - this.identity, - this.contact, - this.content, - this.store, - cardId, - channelId, - ); + return new FocusModule(this.log, this.identity, this.contact, this.content, this.store, cardId, channelId); } public removeFocus(focus: Focus): void { diff --git a/app/sdk/src/settings.ts b/app/sdk/src/settings.ts index d219568f..21e5a576 100644 --- a/app/sdk/src/settings.ts +++ b/app/sdk/src/settings.ts @@ -35,15 +35,7 @@ export class SettingsModule implements Settings { private config: ConfigEntity; private seal: { privateKey: string; publicKey: string } | null; - constructor( - log: Logging, - store: Store, - crypto: Crypto | null, - guid: string, - token: string, - node: string, - secure: boolean, - ) { + constructor(log: Logging, store: Store, crypto: Crypto | null, guid: string, token: string, node: string, secure: boolean) { this.log = log; this.store = store; this.crypto = crypto; @@ -110,27 +102,10 @@ export class SettingsModule implements Settings { } public getConfig() { - const { - storageUsed, - storageAvailable, - forwardingAddress, - searchable, - allowUnsealed, - pushEnabled, - sealable, - seal, - enableIce, - mfaEnabled, - webPushKey, - } = this.config; - const { passwordSalt, privateKeyIv, privateKeyEncrypted, publicKey } = - seal || {}; - const sealSet = Boolean( - passwordSalt && privateKeyIv && privateKeyEncrypted && publicKey, - ); - const sealUnlocked = Boolean( - sealSet && this.seal?.privateKey && this.seal?.publicKey == publicKey, - ); + const { storageUsed, storageAvailable, forwardingAddress, searchable, allowUnsealed, pushEnabled, sealable, seal, enableIce, mfaEnabled, webPushKey } = this.config; + const { passwordSalt, privateKeyIv, privateKeyEncrypted, publicKey } = seal || {}; + const sealSet = Boolean(passwordSalt && privateKeyIv && privateKeyEncrypted && publicKey); + const sealUnlocked = Boolean(sealSet && this.seal?.privateKey && this.seal?.publicKey == publicKey); return { storageUsed, storageAvailable, @@ -156,16 +131,12 @@ export class SettingsModule implements Settings { this.emitter.off("config", ev); } - public addSealListener( - ev: (seal: { privateKey: string; publicKey: string } | null) => void, - ): void { + public addSealListener(ev: (seal: { privateKey: string; publicKey: string } | null) => void): void { this.emitter.on("seal", ev); ev(this.seal); } - public removeSealListener( - ev: (seal: { privateKey: string; publicKey: string } | null) => void, - ): void { + public removeSealListener(ev: (seal: { privateKey: string; publicKey: string } | null) => void): void { this.emitter.off("seal", ev); } @@ -206,11 +177,7 @@ export class SettingsModule implements Settings { secretText: string; }> { const { node, secure, token } = this; - const { secretImage, secretText } = await addAccountMFAuth( - node, - secure, - token, - ); + const { secretImage, secretText } = await addAccountMFAuth(node, secure, token); return { secretImage, secretText }; } @@ -233,11 +200,7 @@ export class SettingsModule implements Settings { const { aesKeyHex } = await crypto.pbkdfKey(saltHex, password); const { publicKeyB64, privateKeyB64 } = await crypto.rsaKey(); const { ivHex } = await crypto.aesIv(); - const { encryptedDataB64 } = await crypto.aesEncrypt( - privateKeyB64, - ivHex, - aesKeyHex, - ); + const { encryptedDataB64 } = await crypto.aesEncrypt(privateKeyB64, ivHex, aesKeyHex); const seal = { passwordSalt: saltHex, privateKeyIv: ivHex, @@ -262,11 +225,7 @@ export class SettingsModule implements Settings { const { saltHex } = await crypto.pbkdfSalt(); const { aesKeyHex } = await crypto.pbkdfKey(saltHex, password); const { ivHex } = await crypto.aesIv(); - const { encryptedDataB64 } = await crypto.aesEncrypt( - this.seal.privateKey, - ivHex, - aesKeyHex, - ); + const { encryptedDataB64 } = await crypto.aesEncrypt(this.seal.privateKey, ivHex, aesKeyHex); const seal = { passwordSalt: saltHex, privateKeyIv: ivHex, @@ -287,8 +246,7 @@ export class SettingsModule implements Settings { public async unlockSeal(password: string): Promise { const { guid, config, crypto } = this; - const { passwordSalt, privateKeyIv, privateKeyEncrypted, publicKey } = - config.seal; + const { passwordSalt, privateKeyIv, privateKeyEncrypted, publicKey } = config.seal; if (!passwordSalt || !privateKeyIv || !privateKeyEncrypted || !publicKey) { throw new Error("account seal not set"); } @@ -296,11 +254,7 @@ export class SettingsModule implements Settings { throw new Error("crypto not set"); } const { aesKeyHex } = await crypto.pbkdfKey(passwordSalt, password); - const { data } = await crypto.aesDecrypt( - privateKeyEncrypted, - privateKeyIv, - aesKeyHex, - ); + const { data } = await crypto.aesDecrypt(privateKeyEncrypted, privateKeyIv, aesKeyHex); const seal = { publicKey: publicKey, privateKey: data }; this.store.setSeal(guid, seal); this.seal = seal; diff --git a/app/sdk/src/store.ts b/app/sdk/src/store.ts index 2444fb59..81e2634d 100644 --- a/app/sdk/src/store.ts +++ b/app/sdk/src/store.ts @@ -1,20 +1,5 @@ -import { - Login, - ProfileEntity, - defaultProfileEntity, - ConfigEntity, - defaultConfigEntity, -} from "./entities"; -import type { - ArticleDetail, - ArticleItem, - ChannelItem, - CardItem, - CardProfile, - CardDetail, - ChannelSummary, - ChannelDetail, -} from "./items"; +import { Login, ProfileEntity, defaultProfileEntity, ConfigEntity, defaultConfigEntity } from "./entities"; +import type { ArticleDetail, ArticleItem, ChannelItem, CardItem, CardProfile, CardDetail, ChannelSummary, ChannelDetail } from "./items"; import type { Logging } from "./logging"; export interface Store { @@ -22,13 +7,8 @@ export interface Store { setLogin(login: Login): Promise; clearLogin(): Promise; - getSeal( - guid: string, - ): Promise<{ publicKey: string; privateKey: string } | null>; - setSeal( - guid: string, - seal: { publicKey: string; privateKey: string }, - ): Promise; + getSeal(guid: string): Promise<{ publicKey: string; privateKey: string } | null>; + setSeal(guid: string, seal: { publicKey: string; privateKey: string }): Promise; clearSeal(guid: string): Promise; getProfileRevision(guid: string): Promise; @@ -48,138 +28,36 @@ export interface Store { addContactCard(guid: string, cardId: string, item: CardItem): Promise; removeContactCard(guid: string, cardId: string): Promise; - setContactCardRevision( - guid: string, - cardId: string, - revision: number, - ): Promise; - setContactCardProfile( - guid: string, - cardId: string, - profile: CardProfile, - ): Promise; - setContactCardDetail( - guid: string, - cardId: string, - detail: CardDetail, - ): Promise; - setContactCardBlocked( - guid: string, - cardId: string, - blocked: boolean, - ): Promise; + setContactCardRevision(guid: string, cardId: string, revision: number): Promise; + setContactCardProfile(guid: string, cardId: string, profile: CardProfile): Promise; + setContactCardDetail(guid: string, cardId: string, detail: CardDetail): Promise; + setContactCardBlocked(guid: string, cardId: string, blocked: boolean): Promise; - setContactCardOffsync( - guid: string, - cardId: string, - offsync: boolean, - ): Promise; + setContactCardOffsync(guid: string, cardId: string, offsync: boolean): Promise; - setContactCardProfileRevision( - guid: string, - cardId: string, - revision: number, - ): Promise; - setContactCardArticlesRevision( - guid: string, - cardId: string, - revision: number, - ): Promise; - setContactCardChannelsRevision( - guid: string, - cardId: string, - revision: number, - ): Promise; + setContactCardProfileRevision(guid: string, cardId: string, revision: number): Promise; + setContactCardArticlesRevision(guid: string, cardId: string, revision: number): Promise; + setContactCardChannelsRevision(guid: string, cardId: string, revision: number): Promise; - getContactCardArticles( - guid: string, - ): Promise<{ cardId: string; articleId: string; item: ArticleItem }[]>; - addContactCardArticle( - guid: string, - cardId: string, - articleId: string, - item: ArticleItem, - ): Promise; - removeContactCardArticle( - guid: string, - cardId: string, - articleId: string, - ): Promise; + getContactCardArticles(guid: string): Promise<{ cardId: string; articleId: string; item: ArticleItem }[]>; + addContactCardArticle(guid: string, cardId: string, articleId: string, item: ArticleItem): Promise; + removeContactCardArticle(guid: string, cardId: string, articleId: string): Promise; - setContactCardArticleDetail( - guid: string, - cardId: string, - articleId: string, - detail: ChannelDetail, - unsealedData: string | null, - ): Promise; - setContactCardArticleUnsealed( - guid: string, - cardId: string, - articleId: string, - unsealedData: string | null, - ): Promise; + setContactCardArticleDetail(guid: string, cardId: string, articleId: string, detail: ChannelDetail, unsealedData: string | null): Promise; + setContactCardArticleUnsealed(guid: string, cardId: string, articleId: string, unsealedData: string | null): Promise; - getContactCardChannels( - guid: string, - ): Promise<{ cardId: string; channelId: string; item: ChannelItem }[]>; - addContactCardChannel( - guid: string, - cardId: string, - channelId: string, - item: ChannelItem, - ): Promise; - removeContactCardChannel( - guid: string, - cardId: string, - channelId: string, - ): Promise; + getContactCardChannels(guid: string): Promise<{ cardId: string; channelId: string; item: ChannelItem }[]>; + addContactCardChannel(guid: string, cardId: string, channelId: string, item: ChannelItem): Promise; + removeContactCardChannel(guid: string, cardId: string, channelId: string): Promise; - setContactCardChannelBlocked( - guid: string, - cardId: string, - channelId: string, - blocked: boolean, - ): Promise; - setContactCardChannelDetail( - guid: string, - cardId: string, - channelId: string, - detail: ChannelDetail, - unsealedData: string, - ): Promise; - setContactCardChannelSummary( - guid: string, - cardId: string, - channelId: string, - summary: ChannelSummary, - unsealedData: string, - ): Promise; - setContactCardChannelUnsealedDetail( - guid: string, - cardId: string, - channelId: string, - data: string | null, - ): Promise; - setContactCardChannelUnsealedSummary( - guid: string, - cardId: string, - channelId: string, - data: string | null, - ): Promise; + setContactCardChannelBlocked(guid: string, cardId: string, channelId: string, blocked: boolean): Promise; + setContactCardChannelDetail(guid: string, cardId: string, channelId: string, detail: ChannelDetail, unsealedData: string): Promise; + setContactCardChannelSummary(guid: string, cardId: string, channelId: string, summary: ChannelSummary, unsealedData: string): Promise; + setContactCardChannelUnsealedDetail(guid: string, cardId: string, channelId: string, data: string | null): Promise; + setContactCardChannelUnsealedSummary(guid: string, cardId: string, channelId: string, data: string | null): Promise; - setContactCardChannelTopicSyncRevision( - guid: string, - cardId: string, - channelId: string, - revision: number, - ): Promise; - setContactCardChannelTopicRemoteRevision( - guid: string, - cardId: string, - channelId: string, - revision: number, - ): Promise; + setContactCardChannelTopicSyncRevision(guid: string, cardId: string, channelId: string, revision: number): Promise; + setContactCardChannelTopicRemoteRevision(guid: string, cardId: string, channelId: string, revision: number): Promise; } export interface SqlStore { @@ -203,15 +81,9 @@ export class OfflineStore implements Store { this.log = log; } - private async getAppValue( - guid: string, - id: string, - unset: any, - ): Promise { + private async getAppValue(guid: string, id: string, unset: any): Promise { try { - const rows = await this.sql.get( - `SELECT * FROM app WHERE key='${guid}::${id}';`, - ); + const rows = await this.sql.get(`SELECT * FROM app WHERE key='${guid}::${id}';`); if (rows.length == 1 && rows[0].value != null) { return JSON.parse(rows[0].value); } @@ -221,22 +93,12 @@ export class OfflineStore implements Store { return unset; } - private async setAppValue( - guid: string, - id: string, - value: any, - ): Promise { - await this.sql.set( - "INSERT OR REPLACE INTO app (key, value) values (?, ?)", - [`${guid}::${id}`, JSON.stringify(value)], - ); + private async setAppValue(guid: string, id: string, value: any): Promise { + await this.sql.set("INSERT OR REPLACE INTO app (key, value) values (?, ?)", [`${guid}::${id}`, JSON.stringify(value)]); } private async clearAppValue(guid: string, id: string): Promise { - await this.sql.set( - "INSERT OR REPLACE INTO app (key, value) values (?, null)", - [`${guid}::${id}`], - ); + await this.sql.set("INSERT OR REPLACE INTO app (key, value) values (?, null)", [`${guid}::${id}`]); } private async initLogin(guid: string): Promise { @@ -258,9 +120,7 @@ export class OfflineStore implements Store { } public async init(): Promise { - await this.sql.set( - "CREATE TABLE IF NOT EXISTS app (key text, value text, unique(key));", - ); + await this.sql.set("CREATE TABLE IF NOT EXISTS app (key text, value text, unique(key));"); return (await this.getAppValue("", "login", null)) as Login | null; } @@ -273,19 +133,14 @@ export class OfflineStore implements Store { await this.clearAppValue("", "login"); } - public async getSeal( - guid: string, - ): Promise<{ publicKey: string; privateKey: string } | null> { + public async getSeal(guid: string): Promise<{ publicKey: string; privateKey: string } | null> { return (await this.getAppValue(guid, "seal", null)) as { publicKey: string; privateKey: string; } | null; } - public async setSeal( - guid: string, - seal: { publicKey: string; privateKey: string }, - ): Promise { + public async setSeal(guid: string, seal: { publicKey: string; privateKey: string }): Promise { await this.setAppValue(guid, "seal", seal); } @@ -297,25 +152,15 @@ export class OfflineStore implements Store { return (await this.getAppValue(guid, "profile_revision", 0)) as number; } - public async setProfileRevision( - guid: string, - revision: number, - ): Promise { + public async setProfileRevision(guid: string, revision: number): Promise { await this.setAppValue(guid, "profile_revision", revision); } public async getProfileData(guid: string): Promise { - return (await this.getAppValue( - guid, - "profile_data", - defaultProfileEntity, - )) as ProfileEntity; + return (await this.getAppValue(guid, "profile_data", defaultProfileEntity)) as ProfileEntity; } - public async setProfileData( - guid: string, - data: ProfileEntity, - ): Promise { + public async setProfileData(guid: string, data: ProfileEntity): Promise { await this.setAppValue(guid, "profile_data", data); } @@ -323,25 +168,15 @@ export class OfflineStore implements Store { return (await this.getAppValue(guid, "account_revision", 0)) as number; } - public async setSettingsRevision( - guid: string, - revision: number, - ): Promise { + public async setSettingsRevision(guid: string, revision: number): Promise { await this.setAppValue(guid, "account_revision", revision); } public async getSettingsData(guid: string): Promise { - return (await this.getAppValue( - guid, - "account_data", - defaultConfigEntity, - )) as ConfigEntity; + return (await this.getAppValue(guid, "account_data", defaultConfigEntity)) as ConfigEntity; } - public async setSettingsData( - guid: string, - data: ConfigEntity, - ): Promise { + public async setSettingsData(guid: string, data: ConfigEntity): Promise { await this.setAppValue(guid, "account_data", data); } @@ -349,176 +184,65 @@ export class OfflineStore implements Store { return 0; } - public async setContactRevision( - guid: string, - revision: number, - ): Promise {} + public async setContactRevision(guid: string, revision: number): Promise {} - public async getContacts( - guid: string, - ): Promise<{ cardId: string; item: CardItem }[]> { + public async getContacts(guid: string): Promise<{ cardId: string; item: CardItem }[]> { return []; } - public async addContactCard( - guid: string, - cardId: string, - item: CardItem, - ): Promise {} + public async addContactCard(guid: string, cardId: string, item: CardItem): Promise {} public async removeContactCard(guid: string, cardId: string): Promise {} - public async setContactCardRevision( - guid: string, - cardId: string, - revision: number, - ): Promise {} + public async setContactCardRevision(guid: string, cardId: string, revision: number): Promise {} - public async setContactCardProfile( - guid: string, - cardId: string, - profile: CardProfile, - ): Promise {} + public async setContactCardProfile(guid: string, cardId: string, profile: CardProfile): Promise {} - public async setContactCardDetail( - guid: string, - cardId: string, - detail: CardDetail, - ): Promise {} + public async setContactCardDetail(guid: string, cardId: string, detail: CardDetail): Promise {} - public async setContactCardBlocked( - guid: string, - cardId: string, - blocked: boolean, - ): Promise {} + public async setContactCardBlocked(guid: string, cardId: string, blocked: boolean): Promise {} - public async setContactCardOffsync( - guid: string, - cardId: string, - offsync: boolean, - ): Promise {} + public async setContactCardOffsync(guid: string, cardId: string, offsync: boolean): Promise {} - public async setContactCardProfileRevision( - guid: string, - cardId: string, - revision: number, - ): Promise {} + public async setContactCardProfileRevision(guid: string, cardId: string, revision: number): Promise {} - public async setContactCardArticlesRevision( - guid: string, - cardId: string, - revision: number, - ): Promise {} + public async setContactCardArticlesRevision(guid: string, cardId: string, revision: number): Promise {} - public async setContactCardChannelsRevision( - guid: string, - cardId: string, - revision: number, - ): Promise {} + public async setContactCardChannelsRevision(guid: string, cardId: string, revision: number): Promise {} - public async getContactCardArticles( - guid: string, - ): Promise<{ cardId: string; articleId: string; item: ArticleItem }[]> { + public async getContactCardArticles(guid: string): Promise<{ cardId: string; articleId: string; item: ArticleItem }[]> { return []; } - public async addContactCardArticle( - guid: string, - cardId: string, - articleId: string, - item: ArticleItem, - ): Promise {} + public async addContactCardArticle(guid: string, cardId: string, articleId: string, item: ArticleItem): Promise {} - public async removeContactCardArticle( - guid: string, - cardId: string, - articleId: string, - ): Promise {} + public async removeContactCardArticle(guid: string, cardId: string, articleId: string): Promise {} - public async setContactCardArticleDetail( - guid: string, - cardId: string, - articleId: string, - detail: ChannelDetail, - unsealedData: string | null, - ): Promise {} + public async setContactCardArticleDetail(guid: string, cardId: string, articleId: string, detail: ChannelDetail, unsealedData: string | null): Promise {} - public async setContactCardArticleUnsealed( - guid: string, - cardId: string, - articleId: string, - unsealedData: string | null, - ): Promise {} + public async setContactCardArticleUnsealed(guid: string, cardId: string, articleId: string, unsealedData: string | null): Promise {} - public async getContactCardChannels( - guid: string, - ): Promise<{ cardId: string; channelId: string; item: ChannelItem }[]> { + public async getContactCardChannels(guid: string): Promise<{ cardId: string; channelId: string; item: ChannelItem }[]> { return []; } - public async addContactCardChannel( - guid: string, - cardId: string, - channelId: string, - item: ChannelItem, - ): Promise {} + public async addContactCardChannel(guid: string, cardId: string, channelId: string, item: ChannelItem): Promise {} - public async removeContactCardChannel( - guid: string, - cardId: string, - channelId: string, - ): Promise {} + public async removeContactCardChannel(guid: string, cardId: string, channelId: string): Promise {} - public async setContactCardChannelBlocked( - guid: string, - cardId: string, - channelId: string, - blocked: boolean, - ): Promise {} + public async setContactCardChannelBlocked(guid: string, cardId: string, channelId: string, blocked: boolean): Promise {} - public async setContactCardChannelDetail( - guid: string, - cardId: string, - channelId: string, - detail: ChannelDetail, - unsealedData: string, - ): Promise {} + public async setContactCardChannelDetail(guid: string, cardId: string, channelId: string, detail: ChannelDetail, unsealedData: string): Promise {} - public async setContactCardChannelSummary( - guid: string, - cardId: string, - channelId: string, - summary: ChannelSummary, - unsealedData: string, - ): Promise {} + public async setContactCardChannelSummary(guid: string, cardId: string, channelId: string, summary: ChannelSummary, unsealedData: string): Promise {} - public async setContactCardChannelUnsealedDetail( - guid: string, - cardId: string, - channelId: string, - data: string | null, - ): Promise {} + public async setContactCardChannelUnsealedDetail(guid: string, cardId: string, channelId: string, data: string | null): Promise {} - public async setContactCardChannelUnsealedSummary( - guid: string, - cardId: string, - channelId: string, - data: string | null, - ): Promise {} + public async setContactCardChannelUnsealedSummary(guid: string, cardId: string, channelId: string, data: string | null): Promise {} - public async setContactCardChannelTopicSyncRevision( - guid: string, - cardId: string, - channelId: string, - revision: number, - ): Promise {} + public async setContactCardChannelTopicSyncRevision(guid: string, cardId: string, channelId: string, revision: number): Promise {} - public async setContactCardChannelTopicRemoteRevision( - guid: string, - cardId: string, - channelId: string, - revision: number, - ): Promise {} + public async setContactCardChannelTopicRemoteRevision(guid: string, cardId: string, channelId: string, revision: number): Promise {} } export class OnlineStore implements Store { @@ -530,11 +254,7 @@ export class OnlineStore implements Store { this.log = log; } - private async getAppValue( - guid: string, - id: string, - unset: any, - ): Promise { + private async getAppValue(guid: string, id: string, unset: any): Promise { const value = await this.web.getValue(`${guid}::${id}`); if (value != null) { return JSON.parse(value); @@ -542,11 +262,7 @@ export class OnlineStore implements Store { return unset; } - private async setAppValue( - guid: string, - id: string, - value: any, - ): Promise { + private async setAppValue(guid: string, id: string, value: any): Promise { await this.web.setValue(`${guid}::${id}`, JSON.stringify(value)); } @@ -566,19 +282,14 @@ export class OnlineStore implements Store { await this.clearAppValue("", "login"); } - public async getSeal( - guid: string, - ): Promise<{ publicKey: string; privateKey: string } | null> { + public async getSeal(guid: string): Promise<{ publicKey: string; privateKey: string } | null> { return (await this.getAppValue(guid, "seal", null)) as { publicKey: string; privateKey: string; } | null; } - public async setSeal( - guid: string, - seal: { publicKey: string; privateKey: string }, - ): Promise { + public async setSeal(guid: string, seal: { publicKey: string; privateKey: string }): Promise { await this.setAppValue(guid, "seal", seal); } @@ -590,212 +301,89 @@ export class OnlineStore implements Store { return 0; } - public async setProfileRevision( - guid: string, - revision: number, - ): Promise {} + public async setProfileRevision(guid: string, revision: number): Promise {} public async getProfileData(guid: string): Promise { return defaultProfileEntity; } - public async setProfileData( - guid: string, - data: ProfileEntity, - ): Promise {} + public async setProfileData(guid: string, data: ProfileEntity): Promise {} public async getSettingsRevision(guid: string): Promise { return 0; } - public async setSettingsRevision( - guid: string, - revision: number, - ): Promise {} + public async setSettingsRevision(guid: string, revision: number): Promise {} public async getSettingsData(guid: string): Promise { return defaultConfigEntity; } - public async setSettingsData( - guid: string, - data: ConfigEntity, - ): Promise {} + public async setSettingsData(guid: string, data: ConfigEntity): Promise {} public async getContactRevision(guid: string): Promise { return 0; } - public async setContactRevision( - guid: string, - revision: number, - ): Promise {} + public async setContactRevision(guid: string, revision: number): Promise {} - public async getContacts( - guid: string, - ): Promise<{ cardId: string; item: CardItem }[]> { + public async getContacts(guid: string): Promise<{ cardId: string; item: CardItem }[]> { return []; } - public async addContactCard( - guid: string, - cardId: string, - item: CardItem, - ): Promise {} + public async addContactCard(guid: string, cardId: string, item: CardItem): Promise {} public async removeContactCard(guid: string, cardId: string): Promise {} - public async setContactCardRevision( - guid: string, - cardId: string, - revision: number, - ): Promise {} + public async setContactCardRevision(guid: string, cardId: string, revision: number): Promise {} - public async setContactCardProfile( - guid: string, - cardId: string, - profile: CardProfile, - ): Promise {} + public async setContactCardProfile(guid: string, cardId: string, profile: CardProfile): Promise {} - public async setContactCardDetail( - guid: string, - cardId: string, - detail: CardDetail, - ): Promise {} + public async setContactCardDetail(guid: string, cardId: string, detail: CardDetail): Promise {} - public async setContactCardBlocked( - guid: string, - cardId: string, - blocked: boolean, - ): Promise {} + public async setContactCardBlocked(guid: string, cardId: string, blocked: boolean): Promise {} - public async setContactCardOffsync( - guid: string, - cardId: string, - offsync: boolean, - ): Promise {} + public async setContactCardOffsync(guid: string, cardId: string, offsync: boolean): Promise {} - public async setContactCardProfileRevision( - guid: string, - cardId: string, - revision: number, - ): Promise {} + public async setContactCardProfileRevision(guid: string, cardId: string, revision: number): Promise {} - public async setContactCardArticlesRevision( - guid: string, - cardId: string, - revision: number, - ): Promise {} + public async setContactCardArticlesRevision(guid: string, cardId: string, revision: number): Promise {} - public async setContactCardChannelsRevision( - guid: string, - cardId: string, - revision: number, - ): Promise {} + public async setContactCardChannelsRevision(guid: string, cardId: string, revision: number): Promise {} - public async getContactCardArticles( - guid: string, - ): Promise<{ cardId: string; articleId: string; item: ArticleItem }[]> { + public async getContactCardArticles(guid: string): Promise<{ cardId: string; articleId: string; item: ArticleItem }[]> { return []; } - public async addContactCardArticle( - guid: string, - cardId: string, - articleId: string, - item: ArticleItem, - ): Promise {} + public async addContactCardArticle(guid: string, cardId: string, articleId: string, item: ArticleItem): Promise {} - public async removeContactCardArticle( - guid: string, - cardId: string, - articleId: string, - ): Promise {} + public async removeContactCardArticle(guid: string, cardId: string, articleId: string): Promise {} - public async setContactCardArticleDetail( - guid: string, - cardId: string, - articleId: string, - detail: ChannelDetail, - unsealedData: string | null, - ): Promise {} + public async setContactCardArticleDetail(guid: string, cardId: string, articleId: string, detail: ChannelDetail, unsealedData: string | null): Promise {} - public async setContactCardArticleUnsealed( - guid: string, - cardId: string, - articleId: string, - unsealedData: string | null, - ): Promise {} + public async setContactCardArticleUnsealed(guid: string, cardId: string, articleId: string, unsealedData: string | null): Promise {} - public async getContactCardChannels( - guid: string, - ): Promise<{ cardId: string; channelId: string; item: ChannelItem }[]> { + public async getContactCardChannels(guid: string): Promise<{ cardId: string; channelId: string; item: ChannelItem }[]> { return []; } - public async addContactCardChannel( - guid: string, - cardId: string, - channelId: string, - item: ChannelItem, - ): Promise {} + public async addContactCardChannel(guid: string, cardId: string, channelId: string, item: ChannelItem): Promise {} - public async removeContactCardChannel( - guid: string, - cardId: string, - channelId: string, - ): Promise {} + public async removeContactCardChannel(guid: string, cardId: string, channelId: string): Promise {} - public async setContactCardChannelBlocked( - guid: string, - cardId: string, - channelId: string, - blocked: boolean, - ): Promise {} + public async setContactCardChannelBlocked(guid: string, cardId: string, channelId: string, blocked: boolean): Promise {} - public async setContactCardChannelDetail( - guid: string, - cardId: string, - channelId: string, - detail: ChannelDetail, - unsealedData: string, - ): Promise {} + public async setContactCardChannelDetail(guid: string, cardId: string, channelId: string, detail: ChannelDetail, unsealedData: string): Promise {} - public async setContactCardChannelSummary( - guid: string, - cardId: string, - channelId: string, - summary: ChannelSummary, - unsealedData: string, - ): Promise {} + public async setContactCardChannelSummary(guid: string, cardId: string, channelId: string, summary: ChannelSummary, unsealedData: string): Promise {} - public async setContactCardChannelUnsealedDetail( - guid: string, - cardId: string, - channelId: string, - data: string | null, - ): Promise {} + public async setContactCardChannelUnsealedDetail(guid: string, cardId: string, channelId: string, data: string | null): Promise {} - public async setContactCardChannelUnsealedSummary( - guid: string, - cardId: string, - channelId: string, - data: string | null, - ): Promise {} + public async setContactCardChannelUnsealedSummary(guid: string, cardId: string, channelId: string, data: string | null): Promise {} - public async setContactCardChannelTopicSyncRevision( - guid: string, - cardId: string, - channelId: string, - revision: number, - ): Promise {} + public async setContactCardChannelTopicSyncRevision(guid: string, cardId: string, channelId: string, revision: number): Promise {} - public async setContactCardChannelTopicRemoteRevision( - guid: string, - cardId: string, - channelId: string, - revision: number, - ): Promise {} + public async setContactCardChannelTopicRemoteRevision(guid: string, cardId: string, channelId: string, revision: number): Promise {} } export class NoStore implements Store { @@ -809,16 +397,11 @@ export class NoStore implements Store { public async clearLogin(): Promise {} - public async getSeal( - guid: string, - ): Promise<{ publicKey: string; privateKey: string } | null> { + public async getSeal(guid: string): Promise<{ publicKey: string; privateKey: string } | null> { return null; } - public async setSeal( - guid: string, - seal: { publicKey: string; privateKey: string }, - ): Promise {} + public async setSeal(guid: string, seal: { publicKey: string; privateKey: string }): Promise {} public async clearSeal(guid: string): Promise {} @@ -826,210 +409,87 @@ export class NoStore implements Store { return 0; } - public async setProfileRevision( - guid: string, - revision: number, - ): Promise {} + public async setProfileRevision(guid: string, revision: number): Promise {} public async getProfileData(guid: string): Promise { return defaultProfileEntity; } - public async setProfileData( - guid: string, - data: ProfileEntity, - ): Promise {} + public async setProfileData(guid: string, data: ProfileEntity): Promise {} public async getSettingsRevision(guid: string): Promise { return 0; } - public async setSettingsRevision( - guid: string, - revision: number, - ): Promise {} + public async setSettingsRevision(guid: string, revision: number): Promise {} public async getSettingsData(guid: string): Promise { return defaultConfigEntity; } - public async setSettingsData( - guid: string, - data: ConfigEntity, - ): Promise {} + public async setSettingsData(guid: string, data: ConfigEntity): Promise {} public async getContactRevision(guid: string): Promise { return 0; } - public async setContactRevision( - guid: string, - revision: number, - ): Promise {} + public async setContactRevision(guid: string, revision: number): Promise {} - public async getContacts( - guid: string, - ): Promise<{ cardId: string; item: CardItem }[]> { + public async getContacts(guid: string): Promise<{ cardId: string; item: CardItem }[]> { return []; } - public async addContactCard( - guid: string, - cardId: string, - item: CardItem, - ): Promise {} + public async addContactCard(guid: string, cardId: string, item: CardItem): Promise {} public async removeContactCard(guid: string, cardId: string): Promise {} - public async setContactCardRevision( - guid: string, - cardId: string, - revision: number, - ): Promise {} + public async setContactCardRevision(guid: string, cardId: string, revision: number): Promise {} - public async setContactCardProfile( - guid: string, - cardId: string, - profile: CardProfile, - ): Promise {} + public async setContactCardProfile(guid: string, cardId: string, profile: CardProfile): Promise {} - public async setContactCardDetail( - guid: string, - cardId: string, - detail: CardDetail, - ): Promise {} + public async setContactCardDetail(guid: string, cardId: string, detail: CardDetail): Promise {} - public async setContactCardBlocked( - guid: string, - cardId: string, - blocked: boolean, - ): Promise {} + public async setContactCardBlocked(guid: string, cardId: string, blocked: boolean): Promise {} - public async setContactCardOffsync( - guid: string, - cardId: string, - offsync: boolean, - ): Promise {} + public async setContactCardOffsync(guid: string, cardId: string, offsync: boolean): Promise {} - public async setContactCardProfileRevision( - guid: string, - cardId: string, - revision: number, - ): Promise {} + public async setContactCardProfileRevision(guid: string, cardId: string, revision: number): Promise {} - public async setContactCardArticlesRevision( - guid: string, - cardId: string, - revision: number, - ): Promise {} + public async setContactCardArticlesRevision(guid: string, cardId: string, revision: number): Promise {} - public async setContactCardChannelsRevision( - guid: string, - cardId: string, - revision: number, - ): Promise {} + public async setContactCardChannelsRevision(guid: string, cardId: string, revision: number): Promise {} - public async getContactCardArticles( - guid: string, - ): Promise<{ cardId: string; articleId: string; item: ArticleItem }[]> { + public async getContactCardArticles(guid: string): Promise<{ cardId: string; articleId: string; item: ArticleItem }[]> { return []; } - public async addContactCardArticle( - guid: string, - cardId: string, - articleId: string, - item: ArticleItem, - ): Promise {} + public async addContactCardArticle(guid: string, cardId: string, articleId: string, item: ArticleItem): Promise {} - public async removeContactCardArticle( - guid: string, - cardId: string, - articleId: string, - ): Promise {} + public async removeContactCardArticle(guid: string, cardId: string, articleId: string): Promise {} - public async setContactCardArticleDetail( - guid: string, - cardId: string, - articleId: string, - detail: ChannelDetail, - unsealedData: string | null, - ): Promise {} + public async setContactCardArticleDetail(guid: string, cardId: string, articleId: string, detail: ChannelDetail, unsealedData: string | null): Promise {} - public async setContactCardArticleUnsealed( - guid: string, - cardId: string, - articleId: string, - unsealedData: string | null, - ): Promise {} + public async setContactCardArticleUnsealed(guid: string, cardId: string, articleId: string, unsealedData: string | null): Promise {} - public async getContactCardChannels( - guid: string, - ): Promise<{ cardId: string; channelId: string; item: ChannelItem }[]> { + public async getContactCardChannels(guid: string): Promise<{ cardId: string; channelId: string; item: ChannelItem }[]> { return []; } - public async addContactCardChannel( - guid: string, - cardId: string, - channelId: string, - item: ChannelItem, - ): Promise {} + public async addContactCardChannel(guid: string, cardId: string, channelId: string, item: ChannelItem): Promise {} - public async removeContactCardChannel( - guid: string, - cardId: string, - channelId: string, - ): Promise {} + public async removeContactCardChannel(guid: string, cardId: string, channelId: string): Promise {} - public async setContactCardChannelBlocked( - guid: string, - cardId: string, - channelId: string, - blocked: boolean, - ): Promise {} + public async setContactCardChannelBlocked(guid: string, cardId: string, channelId: string, blocked: boolean): Promise {} - public async setContactCardChannelDetail( - guid: string, - cardId: string, - channelId: string, - detail: ChannelDetail, - unsealedData: string, - ): Promise {} + public async setContactCardChannelDetail(guid: string, cardId: string, channelId: string, detail: ChannelDetail, unsealedData: string): Promise {} - public async setContactCardChannelSummary( - guid: string, - cardId: string, - channelId: string, - summary: ChannelSummary, - unsealedData: string, - ): Promise {} + public async setContactCardChannelSummary(guid: string, cardId: string, channelId: string, summary: ChannelSummary, unsealedData: string): Promise {} - public async setContactCardChannelUnsealedDetail( - guid: string, - cardId: string, - channelId: string, - data: string | null, - ): Promise {} + public async setContactCardChannelUnsealedDetail(guid: string, cardId: string, channelId: string, data: string | null): Promise {} - public async setContactCardChannelUnsealedSummary( - guid: string, - cardId: string, - channelId: string, - data: string | null, - ): Promise {} + public async setContactCardChannelUnsealedSummary(guid: string, cardId: string, channelId: string, data: string | null): Promise {} - public async setContactCardChannelTopicSyncRevision( - guid: string, - cardId: string, - channelId: string, - revision: number, - ): Promise {} + public async setContactCardChannelTopicSyncRevision(guid: string, cardId: string, channelId: string, revision: number): Promise {} - public async setContactCardChannelTopicRemoteRevision( - guid: string, - cardId: string, - channelId: string, - revision: number, - ): Promise {} + public async setContactCardChannelTopicRemoteRevision(guid: string, cardId: string, channelId: string, revision: number): Promise {} } diff --git a/app/sdk/src/stream.ts b/app/sdk/src/stream.ts index b29bf1cc..2fd0b478 100644 --- a/app/sdk/src/stream.ts +++ b/app/sdk/src/stream.ts @@ -11,13 +11,7 @@ export class StreamModule implements Stream { private content: Content; private emitter: EventEmitter; - constructor( - log: Logging, - contact: Contact, - content: Content, - store: Store, - guid: string, - ) { + constructor(log: Logging, contact: Contact, content: Content, store: Store, guid: string) { this.contact = contact; this.content = content; this.log = log;