mirror of
https://github.com/balzack/databag.git
synced 2025-04-23 01:55:17 +00:00
formatting code
This commit is contained in:
parent
41f0963908
commit
753231d622
@ -10,7 +10,7 @@
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"format": "prettier --print-width 200 --write src",
|
||||
"format": "prettier --single-quote true --print-width 200 --write src",
|
||||
"test": "jest"
|
||||
},
|
||||
"repository": {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { EventEmitter } from "eventemitter3";
|
||||
import type { Alias, Settings, Logging } from "./api";
|
||||
import type { Group } from "./types";
|
||||
import { Store } from "./store";
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
import type { Alias, Settings, Logging } from './api';
|
||||
import type { Group } from './types';
|
||||
import { Store } from './store';
|
||||
|
||||
export class AliasModule implements Alias {
|
||||
private log: Logging;
|
||||
@ -23,21 +23,21 @@ export class AliasModule implements Alias {
|
||||
}
|
||||
|
||||
public addGroupListener(ev: (groups: Group[]) => void): void {
|
||||
this.emitter.on("group", ev);
|
||||
this.emitter.on('group', ev);
|
||||
}
|
||||
|
||||
public removeGroupListener(ev: (groups: Group[]) => void): void {
|
||||
this.emitter.off("group", ev);
|
||||
this.emitter.off('group', ev);
|
||||
}
|
||||
|
||||
public async close(): void {}
|
||||
|
||||
public async setRevision(rev: number): Promise<void> {
|
||||
console.log("set alias revision:", rev);
|
||||
console.log('set alias revision:', rev);
|
||||
}
|
||||
|
||||
public async addGroup(sealed: boolean, dataType: string, subject: string, cardIds: string[]): Promise<string> {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
|
||||
public async removeGroup(groupId: string): Promise<void> {}
|
||||
|
@ -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;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { EventEmitter } from "eventemitter3";
|
||||
import type { Attribute, Settings, Logging } from "./api";
|
||||
import type { Article } from "./types";
|
||||
import { Store } from "./store";
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
import type { Attribute, Settings, Logging } from './api';
|
||||
import type { Article } from './types';
|
||||
import { Store } from './store';
|
||||
|
||||
export class AttributeModule implements Attribute {
|
||||
private log: Logging;
|
||||
@ -23,21 +23,21 @@ export class AttributeModule implements Attribute {
|
||||
}
|
||||
|
||||
public addCardListener(ev: (articles: Article[]) => void): void {
|
||||
this.emitter.on("artcile", ev);
|
||||
this.emitter.on('artcile', ev);
|
||||
}
|
||||
|
||||
public removeCardListener(ev: (articles: Article[]) => void): void {
|
||||
this.emitter.off("article", ev);
|
||||
this.emitter.off('article', ev);
|
||||
}
|
||||
|
||||
public async close(): void {}
|
||||
|
||||
public async setRevision(rev: number): Promise<void> {
|
||||
console.log("set attribute revision:", rev);
|
||||
console.log('set attribute revision:', rev);
|
||||
}
|
||||
|
||||
public async addArticle(sealed: boolean, type: string, subject: string, cardIds: string[], groupIds: string[]): Promise<string> {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
|
||||
public async removeArticle(articleId: string): Promise<void> {}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { EventEmitter } from "eventemitter3";
|
||||
import { Logging } from "./api";
|
||||
import { Revision } from "./entities";
|
||||
import { Call } from "./types";
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
import { Logging } from './api';
|
||||
import { Revision } from './entities';
|
||||
import { Call } from './types';
|
||||
|
||||
export class Connection {
|
||||
private log: Logging;
|
||||
@ -24,47 +24,47 @@ export class Connection {
|
||||
}
|
||||
|
||||
public addRevisionListener(ev: (revision: Revision) => void): void {
|
||||
this.emitter.on("revision", ev);
|
||||
this.emitter.on('revision', ev);
|
||||
}
|
||||
|
||||
public removeRevisionListener(ev: (revision: Revision) => void): void {
|
||||
this.emitter.off("revision", ev);
|
||||
this.emitter.off('revision', ev);
|
||||
}
|
||||
|
||||
public addRingListener(ev: (call: Call) => void): void {
|
||||
this.emitter.on("call", ev);
|
||||
this.emitter.on('call', ev);
|
||||
}
|
||||
|
||||
public removeRingListener(ev: (call: Call) => void): void {
|
||||
this.emitter.off("call", ev);
|
||||
this.emitter.off('call', ev);
|
||||
}
|
||||
|
||||
public addStatusListener(ev: (status: string) => void): void {
|
||||
this.emitter.on("status", ev);
|
||||
this.emitter.on('status', ev);
|
||||
}
|
||||
|
||||
public removeStatusListener(ev: (status: string) => void): void {
|
||||
this.emitter.off("status", ev);
|
||||
this.emitter.off('status', ev);
|
||||
}
|
||||
|
||||
private setWebSocket(token: string, node: string, secure: boolean): WebSocket {
|
||||
if (this.closed) {
|
||||
this.emitter.emit("status", "closed");
|
||||
this.emitter.emit('status', 'closed');
|
||||
return this.websocket;
|
||||
}
|
||||
|
||||
this.emitter.emit("status", "connecting");
|
||||
const wsUrl = `ws${secure ? "s" : ""}://${node}/status?mode=ring`;
|
||||
this.emitter.emit('status', 'connecting');
|
||||
const wsUrl = `ws${secure ? 's' : ''}://${node}/status?mode=ring`;
|
||||
const ws = new WebSocket(wsUrl);
|
||||
ws.onmessage = (e) => {
|
||||
try {
|
||||
if (e.data === "") {
|
||||
if (e.data === '') {
|
||||
this.close();
|
||||
}
|
||||
const activity = JSON.parse(e.data);
|
||||
this.emitter.emit("status", "connected");
|
||||
this.emitter.emit('status', 'connected');
|
||||
if (activity.revision) {
|
||||
this.emitter.emit("revision", activity.revision as Revision);
|
||||
this.emitter.emit('revision', activity.revision as Revision);
|
||||
} else if (activity.ring) {
|
||||
const { cardId, callId, calleeToken, ice, iceUrl, iceUsername, icePassword } = activity.ring;
|
||||
const call: Call = {
|
||||
@ -81,9 +81,9 @@ export class Connection {
|
||||
},
|
||||
],
|
||||
};
|
||||
this.emitter.emit("call", call);
|
||||
this.emitter.emit('call', call);
|
||||
} else {
|
||||
this.emitter.emit("revision", activity as Revision);
|
||||
this.emitter.emit('revision', activity as Revision);
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
@ -92,7 +92,7 @@ export class Connection {
|
||||
};
|
||||
ws.onclose = (e) => {
|
||||
console.log(e);
|
||||
this.emitter.emit("status", "disconnected");
|
||||
this.emitter.emit('status', 'disconnected');
|
||||
setTimeout(() => {
|
||||
if (ws != null) {
|
||||
ws.onmessage = () => {};
|
||||
|
@ -4,16 +4,7 @@ import { Logging } from './logging';
|
||||
import { FocusModule } from './focus';
|
||||
import type { Card, Channel, Article, Topic, Asset, Tag, Profile, Participant } from './types';
|
||||
import { type CardEntity, avatar } from './entities';
|
||||
import type {
|
||||
ArticleDetail,
|
||||
ChannelSummary,
|
||||
ChannelDetail,
|
||||
CardProfile,
|
||||
CardDetail,
|
||||
CardItem,
|
||||
ChannelItem,
|
||||
ArticleItem,
|
||||
} from './items';
|
||||
import type { ArticleDetail, ChannelSummary, ChannelDetail, CardProfile, CardDetail, CardItem, ChannelItem, ArticleItem } from './items';
|
||||
import { defaultCardItem, defaultChannelItem } from './items';
|
||||
import { Store } from './store';
|
||||
import { Crypto } from './crypto';
|
||||
@ -112,9 +103,9 @@ export class ContactModule implements Contact {
|
||||
private async init() {
|
||||
const { guid } = this;
|
||||
this.revision = await this.store.getContactRevision(guid);
|
||||
|
||||
|
||||
const values = await this.store.getMarkers(guid);
|
||||
values.forEach(value => {
|
||||
values.forEach((value) => {
|
||||
this.markers.add(value);
|
||||
});
|
||||
|
||||
@ -124,11 +115,10 @@ export class ContactModule implements Contact {
|
||||
const articles = this.articleEntries.get(cardId);
|
||||
const article = this.setArticle(cardId, articleId, item);
|
||||
if (!articles) {
|
||||
const entries = new Map<string, { item: ArticleItem, article: Article }>();
|
||||
const entries = new Map<string, { item: ArticleItem; article: Article }>();
|
||||
this.articleEntries.set(cardId, entries);
|
||||
entries.set(articleId, { item, article });
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
articles.set(articleId, { item, article });
|
||||
}
|
||||
});
|
||||
@ -137,13 +127,12 @@ export class ContactModule implements Contact {
|
||||
const channels = await this.store.getContactCardChannels(guid);
|
||||
channels.forEach(({ cardId, channelId, item }) => {
|
||||
const channels = this.channelEntries.get(cardId);
|
||||
const channel = this.setChannel(cardId, channelId, item)
|
||||
const channel = this.setChannel(cardId, channelId, item);
|
||||
if (!channels) {
|
||||
const entries = new Map<string, { item: ChannelItem, channel: Channel }>();
|
||||
const entries = new Map<string, { item: ChannelItem; channel: Channel }>();
|
||||
this.channelEntries.set(cardId, entries);
|
||||
entries.set(channelId, { item, channel });
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
channels.set(channelId, { item, channel });
|
||||
}
|
||||
});
|
||||
@ -176,20 +165,20 @@ export class ContactModule implements Contact {
|
||||
}
|
||||
|
||||
private isMarked(marker: string, cardId: string | null, channelId: string | null, topicId: string | null, tagId: string | null): boolean {
|
||||
const value = `${marker}::${cardId}::${channelId}::${topicId}::${tagId}`
|
||||
const value = `${marker}::${cardId}::${channelId}::${topicId}::${tagId}`;
|
||||
return this.markers.has(value);
|
||||
}
|
||||
|
||||
private async setMarker(marker: string, cardId: string | null, channelId: string | null, topicId: string | null, tagId: string | null) {
|
||||
const value = `${marker}::${cardId}::${channelId}::${topicId}::${tagId}`
|
||||
const value = `${marker}::${cardId}::${channelId}::${topicId}::${tagId}`;
|
||||
this.markers.add(value);
|
||||
await this.store.setMarker(this.guid, value);
|
||||
}
|
||||
|
||||
private async clearMarker(marker: string, cardId: string | null, channelId: string | null, topicId: string | null, tagId: string | null) {
|
||||
const value = `${marker}::${cardId}::${channelId}::${topicId}::${tagId}`
|
||||
const value = `${marker}::${cardId}::${channelId}::${topicId}::${tagId}`;
|
||||
this.markers.delete(value);
|
||||
await this.store.clearMarker(this.guid, value);
|
||||
await this.store.clearMarker(this.guid, value);
|
||||
}
|
||||
|
||||
private isCardBlocked(cardId: string): boolean {
|
||||
@ -214,7 +203,7 @@ export class ContactModule implements Contact {
|
||||
|
||||
private async clearChannelBlocked(cardId: string, channelId: string) {
|
||||
await this.clearMarker('blocked', cardId, channelId, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
private isArticleBlocked(cardId: string, articleId: string): boolean {
|
||||
return this.isMarked('blocked', cardId, articleId, null, null);
|
||||
@ -468,7 +457,7 @@ export class ContactModule implements Contact {
|
||||
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
|
||||
}
|
||||
|
||||
private async syncChannels(cardId: string, card: { guid: string, node: string, token: string }, revision: number): Promise<void> {
|
||||
private async syncChannels(cardId: string, card: { guid: string; node: string; token: string }, revision: number): Promise<void> {
|
||||
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);
|
||||
@ -537,8 +526,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);
|
||||
@ -618,8 +605,6 @@ export class ContactModule implements Contact {
|
||||
this.emitter.emit(`channel::${cardId}`, { cardId, channels });
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async setFocus(cardId: string, channelId: string): Promise<Focus> {
|
||||
if (this.focus) {
|
||||
await this.focus.close();
|
||||
@ -644,8 +629,6 @@ export class ContactModule implements Contact {
|
||||
this.focus = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async addCard(server: string | null, guid: string): Promise<string> {
|
||||
const { node, secure, token } = this;
|
||||
const insecure = server ? /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server) : false;
|
||||
@ -731,7 +714,6 @@ export class ContactModule implements Contact {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async removeArticle(cardId: string, articleId: string): Promise<void> {}
|
||||
|
||||
public async removeChannel(cardId: string, channelId: string): Promise<void> {
|
||||
@ -743,8 +725,6 @@ export class ContactModule implements Contact {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async getBlockedCards(): Promise<Card[]> {
|
||||
return Array.from(this.cardEntries.entries())
|
||||
.filter(([key, value]) => this.isCardBlocked(key))
|
||||
@ -757,7 +737,7 @@ export class ContactModule implements Contact {
|
||||
const cardChannels = Array.from(card.entries())
|
||||
.filter(([key, value]) => this.isChannelBlocked(cardId, key))
|
||||
.map(([key, value]) => value.channel);
|
||||
cardChannels.forEach(channel => {
|
||||
cardChannels.forEach((channel) => {
|
||||
channels.push(channel);
|
||||
});
|
||||
});
|
||||
@ -802,8 +782,6 @@ export class ContactModule implements Contact {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async flagCard(cardId: string): Promise<void> {
|
||||
const entry = this.cardEntries.get(cardId);
|
||||
if (entry) {
|
||||
@ -831,8 +809,6 @@ export class ContactModule implements Contact {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async setUnreadChannel(cardId: string, channelId: string, unread: boolean): Promise<void> {
|
||||
const entries = this.channelEntries.get(cardId);
|
||||
if (entries) {
|
||||
@ -840,8 +816,7 @@ export class ContactModule implements Contact {
|
||||
if (entry) {
|
||||
if (unread) {
|
||||
await this.setChannelUnread(cardId, channelId);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
await this.clearChannelUnread(cardId, channelId);
|
||||
}
|
||||
entry.channel = this.setChannel(cardId, channelId, entry.item);
|
||||
@ -850,8 +825,6 @@ export class ContactModule implements Contact {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async getChannelNotifications(cardId: string, channelId: string): Promise<boolean> {
|
||||
const entry = this.cardEntries.get(cardId);
|
||||
if (entry) {
|
||||
@ -871,13 +844,10 @@ export class ContactModule implements Contact {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public async getRegistry(handle: string | null, server: string | null): Promise<Profile[]> {
|
||||
const { node, secure } = this;
|
||||
const insecure = server ? /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server) : false;
|
||||
const listing = server ? await getRegistryListing(handle, server, !insecure) : await getRegistryListing(handle, node, secure)
|
||||
const listing = server ? await getRegistryListing(handle, server, !insecure) : await getRegistryListing(handle, node, secure);
|
||||
return listing.map((entity) => {
|
||||
return {
|
||||
guid: entity.guid,
|
||||
@ -888,13 +858,12 @@ export class ContactModule implements Contact {
|
||||
node: entity.node,
|
||||
version: entity.version,
|
||||
sealSet: Boolean(entity.seal),
|
||||
imageUrl: entity.imageSet ? server ? getRegistryImageUrl(server, true, entity.guid) : getRegistryImageUrl(node, secure, entity.guid) : avatar,
|
||||
imageUrl: entity.imageSet ? (server ? getRegistryImageUrl(server, true, entity.guid) : getRegistryImageUrl(node, secure, entity.guid)) : avatar,
|
||||
imageSet: entity.imageSet,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private setCard(cardId: string, item: CardItem): Card {
|
||||
const { node, secure, token } = this;
|
||||
const { profile, detail } = item;
|
||||
@ -960,12 +929,10 @@ export class ContactModule implements Contact {
|
||||
enableAudio: detail.enableAudio,
|
||||
enableVideo: detail.enableVideo,
|
||||
enableBinary: detail.enableBinary,
|
||||
members: detail.members.map(guid => ({ guid })),
|
||||
members: detail.members.map((guid) => ({ guid })),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async setSeal(seal: { privateKey: string; publicKey: string } | null) {
|
||||
this.seal = seal;
|
||||
this.unsealAll = true;
|
||||
@ -973,7 +940,7 @@ export class ContactModule implements Contact {
|
||||
}
|
||||
|
||||
private async getChannelKey(seals: [{ publicKey: string; sealedKey: string }]): Promise<string | null> {
|
||||
const seal = seals.find(({ publicKey }) => (this.seal && publicKey === this.seal.publicKey));
|
||||
const seal = seals.find(({ publicKey }) => this.seal && publicKey === this.seal.publicKey);
|
||||
if (seal && this.crypto && this.seal) {
|
||||
const key = await this.crypto.rsaDecrypt(seal.sealedKey, this.seal.privateKey);
|
||||
return key.data;
|
||||
@ -1022,8 +989,6 @@ export class ContactModule implements Contact {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private async getCardEntry(cardId: string) {
|
||||
const { guid } = this;
|
||||
const entry = this.cardEntries.get(cardId);
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { EventEmitter } from "eventemitter3";
|
||||
import type { Content, Settings, Logging, Focus } from "./api";
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
import type { Content, Settings, Logging, Focus } from './api';
|
||||
import { FocusModule } from './focus';
|
||||
import type { Channel, Topic, Asset, Tag, Participant } from "./types";
|
||||
import { Store } from "./store";
|
||||
import { Crypto } from "./crypto";
|
||||
import type { Channel, Topic, Asset, Tag, Participant } from './types';
|
||||
import { Store } from './store';
|
||||
import { Crypto } from './crypto';
|
||||
|
||||
export class ContentModule implements Content {
|
||||
private log: Logging;
|
||||
@ -31,21 +31,21 @@ export class ContentModule implements Content {
|
||||
}
|
||||
|
||||
public addChannelListener(ev: (channels: Channel[]) => void): void {
|
||||
this.emitter.on("channel", ev);
|
||||
this.emitter.on('channel', ev);
|
||||
}
|
||||
|
||||
public removeChannelListener(ev: (channels: Channel[]) => void): void {
|
||||
this.emitter.off("channel", ev);
|
||||
this.emitter.off('channel', ev);
|
||||
}
|
||||
|
||||
public async close(): void {}
|
||||
|
||||
public async setRevision(rev: number): Promise<void> {
|
||||
console.log("set content revision:", rev);
|
||||
console.log('set content revision:', rev);
|
||||
}
|
||||
|
||||
public async addChannel(sealed: boolean, type: string, subject: string, cardIds: string[], groupIds: string[]): Promise<string> {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
|
||||
public async removeChannel(channelId: string): Promise<void> {}
|
||||
@ -61,7 +61,7 @@ export class ContentModule implements Content {
|
||||
public async clearChannelGroup(channelId: string, groupId: string): Promise<void> {}
|
||||
|
||||
public async addTopic(channelId: string, type: string, subject: string, assets: Asset[]): Promise<string> {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
|
||||
public async removeTopic(channelId: string, topicId: string): Promise<void> {}
|
||||
@ -73,7 +73,7 @@ export class ContentModule implements Content {
|
||||
public async setTopicSort(channelId: string, topicId: string, sort: number): Promise<void> {}
|
||||
|
||||
public async addTag(channelId: string, topicId: string, type: string, value: string): Promise<string> {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
|
||||
public async removeTag(channelId: string, topicId: string, tagId: string): Promise<void> {}
|
||||
@ -129,7 +129,7 @@ export class ContentModule implements Content {
|
||||
public async disableAddParticipant(channelId: string, memberId: string): Promise<void> {}
|
||||
|
||||
public getTopicAssetUrl(channelId: string, topicId: string, assetId: string): string {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
|
||||
public async getTopics(channelId: string): Promise<Topic[]> {
|
||||
@ -166,8 +166,9 @@ export class ContentModule implements Content {
|
||||
}
|
||||
|
||||
public async addParticipantAccess(channelId: string, name: string): Promise<Participant> {
|
||||
return { id: "", guid: "", name: "", server: "", token: "" };
|
||||
return { id: '', guid: '', name: '', server: '', token: '' };
|
||||
}
|
||||
|
||||
public async removeParticipantAccess(channelId: string, repeaterId: string): Promise<void> {}
|
||||
i}
|
||||
i;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { Contributor } from "./api";
|
||||
import type { Asset } from "./types";
|
||||
import type { Crypto } from "./crypto";
|
||||
import type { Logging } from "./logging";
|
||||
import type { Contributor } from './api';
|
||||
import type { Asset } from './types';
|
||||
import type { Crypto } from './crypto';
|
||||
import type { Logging } from './logging';
|
||||
|
||||
export class ContributorModule implements Contributor {
|
||||
private log: Logging;
|
||||
@ -19,13 +19,13 @@ export class ContributorModule implements Contributor {
|
||||
}
|
||||
|
||||
public async addTopic(type: string, message: string, assets: Asset[]): Promise<string> {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
|
||||
public async removeTopic(topicId: string): Promise<void> {}
|
||||
|
||||
public async addTag(topicId: string, type: string, value: string): Promise<string> {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
|
||||
public async removeTag(topicId: string, tagId: string): Promise<void> {}
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,8 +1,8 @@
|
||||
import { EventEmitter } from "eventemitter3";
|
||||
import type { Focus } from "./api";
|
||||
import type { Topic, Asset, Participant } from "./types";
|
||||
import type { Logging } from "./logging";
|
||||
import { Store } from "./store";
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
import type { Focus } from './api';
|
||||
import type { Topic, Asset, Participant } from './types';
|
||||
import type { Logging } from './logging';
|
||||
import { Store } from './store';
|
||||
import { Crypto } from './crypto';
|
||||
|
||||
export class FocusModule implements Focus {
|
||||
@ -13,9 +13,9 @@ export class FocusModule implements Focus {
|
||||
private crypto: Crypto | null;
|
||||
private store: Store;
|
||||
private guid: string;
|
||||
private connection: { node: string, secure: boolean, token: string} | null;
|
||||
private connection: { node: string; secure: boolean; token: string } | null;
|
||||
|
||||
constructor(log: Logging, store: Store, crypto: Crypto | null, cardId: string | null, channelId: string, guid: string, connection: { node: string, secure: boolean, token: string } | null) {
|
||||
constructor(log: Logging, store: Store, crypto: Crypto | null, cardId: string | null, channelId: string, guid: string, connection: { node: string; secure: boolean; token: string } | null) {
|
||||
this.cardId = cardId;
|
||||
this.channelId = channelId;
|
||||
this.log = log;
|
||||
@ -38,11 +38,10 @@ export class FocusModule implements Focus {
|
||||
}
|
||||
}
|
||||
|
||||
public async close() {
|
||||
}
|
||||
public async close() {}
|
||||
|
||||
public async addTopic(type: string, message: string, assets: Asset[]): Promise<string> {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
|
||||
public async removeTopic(topicId: string): Promise<void> {}
|
||||
@ -52,7 +51,7 @@ export class FocusModule implements Focus {
|
||||
public async setTopicSort(topicId: string, sort: number): Promise<void> {}
|
||||
|
||||
public async addTag(topicId: string, type: string, subject: string): Promise<string> {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
|
||||
public async removeTag(cardId: string, tagId: string): Promise<void> {}
|
||||
@ -70,11 +69,11 @@ export class FocusModule implements Focus {
|
||||
public async clearUnreadChannel(cardId: string, channelId: string): Promise<void> {}
|
||||
|
||||
public getTopicAssetUrl(topicId: string, assetId: string): string {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
|
||||
public async addParticipantAccess(name: string): Promise<Participant> {
|
||||
return { id: "", name: "", node: "", secure: false, token: "" };
|
||||
return { id: '', name: '', node: '', secure: false, token: '' };
|
||||
}
|
||||
|
||||
public async removeParticipantAccess(repeaterId: string): Promise<void> {}
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { EventEmitter } from "eventemitter3";
|
||||
import type { Identity } from "./api";
|
||||
import type { Logging } from "./logging";
|
||||
import type { Profile } from "./types";
|
||||
import { Store } from "./store";
|
||||
import { getProfile } from "./net/getProfile";
|
||||
import { getProfileImageUrl } from "./net/getProfileImageUrl";
|
||||
import { setProfileData } from "./net/setProfileData";
|
||||
import { setProfileImage } from "./net/setProfileImage";
|
||||
import { ProfileEntity, defaultProfileEntity, avatar } from "./entities";
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
import type { Identity } from './api';
|
||||
import type { Logging } from './logging';
|
||||
import type { Profile } from './types';
|
||||
import { Store } from './store';
|
||||
import { getProfile } from './net/getProfile';
|
||||
import { getProfileImageUrl } from './net/getProfileImageUrl';
|
||||
import { setProfileData } from './net/setProfileData';
|
||||
import { setProfileImage } from './net/setProfileImage';
|
||||
import { ProfileEntity, defaultProfileEntity, avatar } from './entities';
|
||||
|
||||
const CLOSE_POLL_MS = 100;
|
||||
const RETRY_POLL_MS = 2000;
|
||||
@ -51,7 +51,7 @@ export class IdentityModule implements Identity {
|
||||
} else {
|
||||
this.imageUrl = avatar;
|
||||
}
|
||||
this.emitter.emit("profile", this.setProfile());
|
||||
this.emitter.emit('profile', this.setProfile());
|
||||
this.syncing = false;
|
||||
await this.sync();
|
||||
}
|
||||
@ -75,7 +75,7 @@ export class IdentityModule implements Identity {
|
||||
} else {
|
||||
this.imageUrl = avatar;
|
||||
}
|
||||
this.emitter.emit("profile", this.setProfile());
|
||||
this.emitter.emit('profile', this.setProfile());
|
||||
this.revision = nextRev;
|
||||
if (this.nextRevision === nextRev) {
|
||||
this.nextRevision = null;
|
||||
@ -107,12 +107,12 @@ export class IdentityModule implements Identity {
|
||||
}
|
||||
|
||||
public addProfileListener(ev: (profile: Profile) => void): void {
|
||||
this.emitter.on("profile", ev);
|
||||
this.emitter.emit("profile", this.setProfile());
|
||||
this.emitter.on('profile', ev);
|
||||
this.emitter.emit('profile', this.setProfile());
|
||||
}
|
||||
|
||||
public removeProfileListener(ev: (profile: Profile) => void): void {
|
||||
this.emitter.off("profile", ev);
|
||||
this.emitter.off('profile', ev);
|
||||
}
|
||||
|
||||
public async close(): Promise<void> {
|
||||
|
@ -1,26 +1,26 @@
|
||||
import { SessionModule } from "./session";
|
||||
import { NodeModule } from "./node";
|
||||
import { ContributorModule } from "./contributor";
|
||||
import { type Logging, ConsoleLogging } from "./logging";
|
||||
import { type Store, OfflineStore, OnlineStore, NoStore } from "./store";
|
||||
import { setLogin } from "./net/setLogin";
|
||||
import { clearLogin } from "./net/clearLogin";
|
||||
import { removeAccount } from "./net/removeAccount";
|
||||
import { setAccess } from "./net/setAccess";
|
||||
import { addAccount } from "./net/addAccount";
|
||||
import { setAdmin } from "./net/setAdmin";
|
||||
import { getAvailable } from "./net/getAvailable";
|
||||
import { getUsername } from "./net/getUsername";
|
||||
import type { Session, Node, Contributor } from "./api";
|
||||
import type { Params, SessionParams } from "./types";
|
||||
import type { Login } from "./entities";
|
||||
import type { Crypto } from "./crypto";
|
||||
import type { WebStore, SqlStore } from "./store";
|
||||
import { SessionModule } from './session';
|
||||
import { NodeModule } from './node';
|
||||
import { ContributorModule } from './contributor';
|
||||
import { type Logging, ConsoleLogging } from './logging';
|
||||
import { type Store, OfflineStore, OnlineStore, NoStore } from './store';
|
||||
import { setLogin } from './net/setLogin';
|
||||
import { clearLogin } from './net/clearLogin';
|
||||
import { removeAccount } from './net/removeAccount';
|
||||
import { setAccess } from './net/setAccess';
|
||||
import { addAccount } from './net/addAccount';
|
||||
import { setAdmin } from './net/setAdmin';
|
||||
import { getAvailable } from './net/getAvailable';
|
||||
import { getUsername } from './net/getUsername';
|
||||
import type { Session, Node, Contributor } from './api';
|
||||
import type { Params, SessionParams } from './types';
|
||||
import type { Login } from './entities';
|
||||
import type { Crypto } from './crypto';
|
||||
import type { WebStore, SqlStore } from './store';
|
||||
|
||||
export * from "./api";
|
||||
export * from "./types";
|
||||
export { WebStore, SqlStore } from "./store";
|
||||
export { Crypto } from "./crypto";
|
||||
export * from './api';
|
||||
export * from './types';
|
||||
export { WebStore, SqlStore } from './store';
|
||||
export { Crypto } from './crypto';
|
||||
|
||||
export class DatabagSDK {
|
||||
private log: Logging;
|
||||
@ -33,7 +33,7 @@ export class DatabagSDK {
|
||||
this.params = params;
|
||||
this.crypto = crypto ? crypto : null;
|
||||
this.log = log ? log : new ConsoleLogging();
|
||||
this.log.info("databag sdk");
|
||||
this.log.info('databag sdk');
|
||||
}
|
||||
|
||||
public async initOfflineStore(sql: SqlStore): Promise<Session | null> {
|
||||
|
@ -81,19 +81,19 @@ export const defaultCardItem = {
|
||||
revision: 0,
|
||||
profile: {
|
||||
revision: 0,
|
||||
handle: "",
|
||||
guid: "",
|
||||
name: "",
|
||||
description: "",
|
||||
location: "",
|
||||
handle: '',
|
||||
guid: '',
|
||||
name: '',
|
||||
description: '',
|
||||
location: '',
|
||||
imageSet: false,
|
||||
node: "",
|
||||
version: "",
|
||||
seal: "",
|
||||
node: '',
|
||||
version: '',
|
||||
seal: '',
|
||||
},
|
||||
detail: {
|
||||
revision: 0,
|
||||
status: "",
|
||||
status: '',
|
||||
statusUpdated: 0,
|
||||
token: 0,
|
||||
},
|
||||
@ -119,19 +119,19 @@ export const defaultChannelItem = {
|
||||
summary: {
|
||||
revision: 0,
|
||||
sealed: false,
|
||||
guid: "",
|
||||
dataType: "",
|
||||
data: "",
|
||||
guid: '',
|
||||
dataType: '',
|
||||
data: '',
|
||||
created: 0,
|
||||
updated: 0,
|
||||
status: "",
|
||||
transform: "",
|
||||
status: '',
|
||||
transform: '',
|
||||
},
|
||||
detail: {
|
||||
revision: 0,
|
||||
sealed: false,
|
||||
dataType: "",
|
||||
data: "",
|
||||
dataType: '',
|
||||
data: '',
|
||||
created: 0,
|
||||
updated: 0,
|
||||
enableImage: false,
|
||||
|
@ -6,12 +6,12 @@ export interface Logging {
|
||||
|
||||
export class ConsoleLogging implements Logging {
|
||||
public error(m: any): void {
|
||||
console.log("error:", m);
|
||||
console.log('error:', m);
|
||||
}
|
||||
public warn(m: any): void {
|
||||
console.log("warn:", m);
|
||||
console.log('warn:', m);
|
||||
}
|
||||
public info(m: any): void {
|
||||
console.log("info:", m);
|
||||
console.log('info:', m);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { encode } from "./base64";
|
||||
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<void> {
|
||||
const access = token ? `?token=${token}` : "";
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/account/profile${access}`;
|
||||
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);
|
||||
headers.append('Credentials', `Basic ${auth}`);
|
||||
const { status } = await fetchWithTimeout(endpoint, { method: 'POST', headers }, 60000);
|
||||
checkResponse(status);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
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" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/account/mfauth?agent=${token}`;
|
||||
const auth = await fetchWithTimeout(endpoint, { method: 'POST' });
|
||||
checkResponse(auth.status);
|
||||
return await auth.json();
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { DataMessage } from '../entities';
|
||||
|
||||
export async function addCard(node: string, secure: boolean, token: string, message: DataMessage) {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards?agent=${token}`;
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/contact/cards?agent=${token}`;
|
||||
const card = await fetchWithTimeout(endpoint, {
|
||||
method: "POST",
|
||||
method: 'POST',
|
||||
body: JSON.stringify(message),
|
||||
});
|
||||
checkResponse(card.status);
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function addFlag(node: string, secure: boolean, guid: string, data: { channelId?: string, articleId?: string }) {
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/account/flag/${guid}`
|
||||
const response = await fetchWithTimeout(endpoint, { method: 'POST', body: JSON.stringify(data) } );
|
||||
export async function addFlag(node: string, secure: boolean, guid: string, data: { channelId?: string; articleId?: string }) {
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/account/flag/${guid}`;
|
||||
const response = await fetchWithTimeout(endpoint, { method: 'POST', body: JSON.stringify(data) });
|
||||
checkResponse(response.status);
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
export function encode(input: string) {
|
||||
let output = "";
|
||||
let output = '';
|
||||
let chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
||||
let i = 0;
|
||||
|
||||
const _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
const _keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
||||
|
||||
input = _utf8_encode(input);
|
||||
|
||||
@ -30,8 +30,8 @@ export function encode(input: string) {
|
||||
}
|
||||
|
||||
function _utf8_encode(value: string) {
|
||||
value = value.replace(/\r\n/g, "\n");
|
||||
let utftext = "";
|
||||
value = value.replace(/\r\n/g, '\n');
|
||||
let utftext = '';
|
||||
|
||||
for (let n = 0; n < value.length; n++) {
|
||||
let c = value.charCodeAt(n);
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
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" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/account/seal?agent=${token}`;
|
||||
const seal = await fetchWithTimeout(endpoint, { method: 'DELETE' });
|
||||
checkResponse(seal.status);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function clearLogin(node: string, secure: boolean, token: string, all: boolean): Promise<void> {
|
||||
const param = all ? "&all=true" : "";
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/account/apps?agent=${token}${param}`;
|
||||
const { status } = await fetchWithTimeout(endpoint, { method: "DELETE" });
|
||||
const param = all ? '&all=true' : '';
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/account/apps?agent=${token}${param}`;
|
||||
const { status } = await fetchWithTimeout(endpoint, { method: 'DELETE' });
|
||||
checkResponse(status);
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ export function checkResponse(code: number) {
|
||||
export async function fetchWithTimeout(url: string, options: RequestInit, timeout: number = TIMEOUT): Promise<Response> {
|
||||
return Promise.race<Response>([
|
||||
fetch(url, options).catch((err) => {
|
||||
throw new Error(url + " failed");
|
||||
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)),
|
||||
]);
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { ConfigEntity } from "../entities";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { ConfigEntity } from '../entities';
|
||||
|
||||
export async function getAccountStatus(node: string, secure: boolean, token: string): Promise<ConfigEntity> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/account/status?agent=${token}`;
|
||||
const status = await fetchWithTimeout(endpoint, { method: "GET" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/account/status?agent=${token}`;
|
||||
const status = await fetchWithTimeout(endpoint, { method: 'GET' });
|
||||
checkResponse(status.status);
|
||||
return await status.json();
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function getAvailable(node: string, secure: boolean): Promise<number> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/account/available`;
|
||||
const available = await fetchWithTimeout(endpoint, { method: "GET" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/account/available`;
|
||||
const available = await fetchWithTimeout(endpoint, { method: 'GET' });
|
||||
checkResponse(available.status);
|
||||
return await available.json();
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { DataMessage } from '../entities';
|
||||
|
||||
export async function getCardCloseMessage(node: string, secure: boolean, token: string, cardId: string): Promise<DataMessage> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards/${cardId}/closeMessage?agent=${token}`;
|
||||
const close = await fetchWithTimeout(endpoint, { method: "GET" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/contact/cards/${cardId}/closeMessage?agent=${token}`;
|
||||
const close = await fetchWithTimeout(endpoint, { method: 'GET' });
|
||||
checkResponse(close.status);
|
||||
return await close.json();
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { CardDetailEntity } from "../entities";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { CardDetailEntity } from '../entities';
|
||||
|
||||
export async function getCardDetail(node: string, secure: boolean, token: string, cardId: string): Promise<CardDetailEntity> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards/${cardId}/detail?agent=${token}`;
|
||||
const detail = await fetchWithTimeout(endpoint, { method: "GET" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/contact/cards/${cardId}/detail?agent=${token}`;
|
||||
const detail = await fetchWithTimeout(endpoint, { method: 'GET' });
|
||||
checkResponse(detail.status);
|
||||
return await detail.json();
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
export function getCardImageUrl(node: string, secure: boolean, token: string, cardId: string, revision: number): string {
|
||||
return `http${secure ? 's' : ''}://${node}/contact/cards/${cardId}/profile/image?agent=${token}&revision=${revision}`
|
||||
return `http${secure ? 's' : ''}://${node}/contact/cards/${cardId}/profile/image?agent=${token}&revision=${revision}`;
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { DataMessage } from "../entities";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { DataMessage } from '../entities';
|
||||
|
||||
export async function getCardOpenMessage(node: string, secure: boolean, token: string, cardId: string): Promise<DataMessage> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards/${cardId}/openMessage?agent=${token}`;
|
||||
const open = await fetchWithTimeout(endpoint, { method: "GET" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/contact/cards/${cardId}/openMessage?agent=${token}`;
|
||||
const open = await fetchWithTimeout(endpoint, { method: 'GET' });
|
||||
checkResponse(open.status);
|
||||
return await open.json();
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { CardProfileEntity } from "../entities";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { CardProfileEntity } from '../entities';
|
||||
|
||||
export async function getCardProfile(node: string, secure: boolean, token: string, cardId: string): Promise<CardProfileEntity> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards/${cardId}/profile?agent=${token}`;
|
||||
const profile = await fetchWithTimeout(endpoint, { method: "GET" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/contact/cards/${cardId}/profile?agent=${token}`;
|
||||
const profile = await fetchWithTimeout(endpoint, { method: 'GET' });
|
||||
checkResponse(profile.status);
|
||||
return await profile.json();
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { CardEntity } from "../entities";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { CardEntity } from '../entities';
|
||||
|
||||
export async function getCards(node: string, secure: boolean, token: string, revision: number): Promise<CardEntity[]> {
|
||||
const param = revision ? `&revision=${revision}` : "";
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards?agent=${token}${param}`;
|
||||
const cards = await fetchWithTimeout(endpoint, { method: "GET" });
|
||||
const param = revision ? `&revision=${revision}` : '';
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/contact/cards?agent=${token}${param}`;
|
||||
const cards = await fetchWithTimeout(endpoint, { method: 'GET' });
|
||||
checkResponse(cards.status);
|
||||
return await cards.json();
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { ChannelDetailEntity } from "../entities";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { ChannelDetailEntity } from '../entities';
|
||||
|
||||
export async function getContactChannelDetail(server: string, secure: boolean, guid: string, token: string, channelId: string): Promise<ChannelDetailEntity> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${secure}/content/channels/${channelId}/detail?contact=${guid}.${token}`;
|
||||
const detail = await fetchWithTimeout(endpoint, { method: "GET" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${secure}/content/channels/${channelId}/detail?contact=${guid}.${token}`;
|
||||
const detail = await fetchWithTimeout(endpoint, { method: 'GET' });
|
||||
checkResponse(detail.status);
|
||||
return await detail.json();
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function getContactChannelNotifications(node: string, secure: boolean, guid: string, token: string, channelId: string): Promise<boolean> {
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/content/channels/${channelId}/notification?contact=${guid}.${token}`
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/content/channels/${channelId}/notification?contact=${guid}.${token}`;
|
||||
const notify = await fetchWithTimeout(endpoint, { method: 'GET' });
|
||||
checkResponse(notify.status)
|
||||
return await notify.json()
|
||||
checkResponse(notify.status);
|
||||
return await notify.json();
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { ChannelSummaryEntity } from "../entities";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { ChannelSummaryEntity } from '../entities';
|
||||
|
||||
export async function getContactChannelSummary(server: string, secure: boolean, guid: string, token: string, channelId: string): Promise<ChannelSummaryEntity> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${server}/content/channels/${channelId}/summary?contact=${guid}.${token}`;
|
||||
const summary = await fetchWithTimeout(endpoint, { method: "GET" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${server}/content/channels/${channelId}/summary?contact=${guid}.${token}`;
|
||||
const summary = await fetchWithTimeout(endpoint, { method: 'GET' });
|
||||
checkResponse(summary.status);
|
||||
return await summary.json();
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { ChannelEntity } from "../entities";
|
||||
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<ChannelEntity[]> {
|
||||
const type = `types=${encodeURIComponent(JSON.stringify(types))}`;
|
||||
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" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/content/channels?contact=${guid}.${token}&${param}&${type}`;
|
||||
const channels = await fetchWithTimeout(endpoint, { method: 'GET' });
|
||||
checkResponse(channels.status);
|
||||
return await channels.json();
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { DataMessage } from "../entities";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { DataMessage } from '../entities';
|
||||
|
||||
export async function getContactListing(node: string, secure: boolean, guid: string): Promise<DataMessage> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/account/listing/${guid}/message`;
|
||||
const listing = await fetchWithTimeout(endpoint, { method: "GET" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/account/listing/${guid}/message`;
|
||||
const listing = await fetchWithTimeout(endpoint, { method: 'GET' });
|
||||
checkResponse(listing.status);
|
||||
return await listing.json();
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { DataMessage } from "../entities";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { DataMessage } from '../entities';
|
||||
|
||||
export async function getContactProfile(node: string, secure: boolean, guid: string, token: string): Promise<DataMessage> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/profile/message?contact=${guid}.${token}`;
|
||||
const profile = await fetchWithTimeout(endpoint, { method: "GET" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/profile/message?contact=${guid}.${token}`;
|
||||
const profile = await fetchWithTimeout(endpoint, { method: 'GET' });
|
||||
checkResponse(profile.status);
|
||||
return await profile.json();
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { ProfileEntity } from "../entities";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { ProfileEntity } from '../entities';
|
||||
|
||||
export async function getProfile(node: string, secure: boolean, token: string): Promise<ProfileEntity> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/profile?agent=${token}`;
|
||||
const profile = await fetchWithTimeout(endpoint, { method: "GET" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/profile?agent=${token}`;
|
||||
const profile = await fetchWithTimeout(endpoint, { method: 'GET' });
|
||||
checkResponse(profile.status);
|
||||
return await profile.json();
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
export function getProfileImageUrl(node: string, secure: boolean, token: string, revision: number) {
|
||||
return `http${secure ? "s" : ""}://${node}/profile/image?agent=${token}&revision=${revision}`;
|
||||
return `http${secure ? 's' : ''}://${node}/profile/image?agent=${token}&revision=${revision}`;
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
export function getRegistryImageUrl(node: string, secure: boolean, guid: string): string {
|
||||
return `http${secure ? 's' : ''}://${node}/account/listing/${guid}/image`
|
||||
return `http${secure ? 's' : ''}://${node}/account/listing/${guid}/image`;
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,10 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { AccountEntity } from "../entities";
|
||||
import { AccountEntity } from '../entities';
|
||||
|
||||
export async function getRegistryListing(handle: string | null, server: string, secure: boolean): Promise<AccountEntity[]> {
|
||||
const param = handle ? `?filter=${handle}` : '';
|
||||
const endpoint = `http${secure ? 's' : ''}://${server}/account/listing${param}`
|
||||
const endpoint = `http${secure ? 's' : ''}://${server}/account/listing${param}`;
|
||||
const listing = await fetchWithTimeout(endpoint, { method: 'GET' });
|
||||
checkResponse(listing.status);
|
||||
return await listing.json();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function getUsername(name: string, token: string | null, agent: string | null, node: string, secure: boolean): Promise<boolean> {
|
||||
const param = token ? `&token=${token}` : agent ? `&agent=${agent}` : "";
|
||||
const param = token ? `&token=${token}` : agent ? `&agent=${agent}` : '';
|
||||
const username = encodeURIComponent(name);
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/account/username?name=${username}${param}`;
|
||||
const taken = await fetchWithTimeout(endpoint, { method: "GET" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/account/username?name=${username}${param}`;
|
||||
const taken = await fetchWithTimeout(endpoint, { method: 'GET' });
|
||||
checkResponse(taken.status);
|
||||
return await taken.json();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function removeAccount(node: string, secure: boolean, token: string): Promise<void> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/profile?agent=${token}`;
|
||||
const { status } = await fetchWithTimeout(endpoint, { method: "DELETE" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/profile?agent=${token}`;
|
||||
const { status } = await fetchWithTimeout(endpoint, { method: 'DELETE' });
|
||||
checkResponse(status);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
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" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/account/mfauth?agent=${token}`;
|
||||
const { status } = await fetchWithTimeout(endpoint, { method: 'DELETE' });
|
||||
checkResponse(status);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function removeCard(node: string, secure: boolean, token: string, cardId: string): Promise<void> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards/${cardId}?agent=${token}`;
|
||||
const { status } = await fetchWithTimeout(endpoint, { method: "DELETE" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/contact/cards/${cardId}?agent=${token}`;
|
||||
const { status } = await fetchWithTimeout(endpoint, { method: 'DELETE' });
|
||||
checkResponse(status);
|
||||
}
|
||||
|
@ -5,4 +5,3 @@ export async function removeContactChannel(node: string, secure: boolean, guid:
|
||||
const response = await fetchWithTimeout(endpoint, { method: 'DELETE' });
|
||||
checkResponse(response.status);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function setAccess(
|
||||
node: string,
|
||||
@ -16,9 +16,9 @@ export async function setAccess(
|
||||
created: number;
|
||||
pushSupported: boolean;
|
||||
}> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/account/access?token=${token}&appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}&pushType=${pushType}`;
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/account/access?token=${token}&appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}&pushType=${pushType}`;
|
||||
const access = await fetchWithTimeout(endpoint, {
|
||||
method: "PUT",
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(notifications),
|
||||
});
|
||||
checkResponse(access.status);
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { encode } from "./base64";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { encode } from './base64';
|
||||
|
||||
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 endpoint = `http${secure ? 's' : ''}://${node}/account/login?agent=${token}`;
|
||||
const auth = encode(`${username}:${password}`);
|
||||
const headers = new Headers();
|
||||
headers.append("Credentials", `Basic ${auth}`);
|
||||
headers.append('Credentials', `Basic ${auth}`);
|
||||
const { status } = await fetchWithTimeout(endpoint, {
|
||||
method: "PUT",
|
||||
method: 'PUT',
|
||||
headers,
|
||||
});
|
||||
checkResponse(status);
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
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" });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/account/mfauth?agent=${token}&code=${code}`;
|
||||
const { status } = await fetchWithTimeout(endpoint, { method: 'PUT' });
|
||||
checkResponse(status);
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function setAccountNotifications(node: string, secure: boolean, token: string, flag: boolean) {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/account/notification?agent=${token}`;
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/account/notification?agent=${token}`;
|
||||
const { status } = await fetchWithTimeout(endpoint, {
|
||||
method: "PUT",
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(flag),
|
||||
});
|
||||
checkResponse(status);
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { SealEntity } from "../entities";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { SealEntity } from '../entities';
|
||||
|
||||
export async function setAccountSeal(node: string, secure: boolean, token: string, seal: SealEntity) {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/account/seal?agent=${token}`;
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/account/seal?agent=${token}`;
|
||||
const { status } = await fetchWithTimeout(endpoint, {
|
||||
method: "PUT",
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(seal),
|
||||
});
|
||||
checkResponse(status);
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function setAccountSearchable(node: string, secure: boolean, token: string, flag: boolean) {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/account/searchable?agent=${token}`;
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/account/searchable?agent=${token}`;
|
||||
const { status } = await fetchWithTimeout(endpoint, {
|
||||
method: "PUT",
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(flag),
|
||||
});
|
||||
checkResponse(status);
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function setAdmin(node: string, secure: boolean, token: string, mfaCode: string | null): Promise<string> {
|
||||
const mfa = mfaCode ? `&code=${mfaCode}` : "";
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/admin/access?token=${encodeURIComponent(token)}${mfa}`;
|
||||
const admin = await fetchWithTimeout(endpoint, { method: "PUT" });
|
||||
const mfa = mfaCode ? `&code=${mfaCode}` : '';
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/admin/access?token=${encodeURIComponent(token)}${mfa}`;
|
||||
const admin = await fetchWithTimeout(endpoint, { method: 'PUT' });
|
||||
checkResponse(admin.status);
|
||||
return await admin.json();
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { DataMessage } from '../entities';
|
||||
|
||||
export async function setCardCloseMessage(node: string, secure: boolean, message: DataMessage): Promise<void> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/contact/closeMessage`;
|
||||
const close = await fetchWithTimeout(endpoint, { method: "PUT", body: JSON.stringify(message) });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/contact/closeMessage`;
|
||||
const close = await fetchWithTimeout(endpoint, { method: 'PUT', body: JSON.stringify(message) });
|
||||
checkResponse(close.status);
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function setCardConfirmed(node: string, secure: boolean, token: string, cardId: string): Promise<void> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards/${cardId}/status?agent=${token}`;
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/contact/cards/${cardId}/status?agent=${token}`;
|
||||
const { status } = await fetchWithTimeout(endpoint, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify("confirmed"),
|
||||
method: 'PUT',
|
||||
body: JSON.stringify('confirmed'),
|
||||
});
|
||||
checkResponse(status);
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
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<void> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards/${cardId}/status?agent=${token}&token=${access}&viewRevision=1&articleRevision=${article}&channelRevision=${channel}&profileRevision=${profile}`;
|
||||
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("connected"),
|
||||
method: 'PUT',
|
||||
body: JSON.stringify('connected'),
|
||||
});
|
||||
checkResponse(status);
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function setCardConnecting(node: string, secure: boolean, token: string, cardId: string): Promise<void> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards/${cardId}/status?agent=${token}`;
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/contact/cards/${cardId}/status?agent=${token}`;
|
||||
const { status } = await fetchWithTimeout(endpoint, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify("connecting"),
|
||||
method: 'PUT',
|
||||
body: JSON.stringify('connecting'),
|
||||
});
|
||||
checkResponse(status);
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { DataMessage, ContactStatus } from "../entities";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { DataMessage, ContactStatus } from '../entities';
|
||||
|
||||
export async function setCardOpenMessage(node: string, secure: boolean, message: DataMessage): Promise<ContactStatus> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/contact/openMessage`;
|
||||
const open = await fetchWithTimeout(endpoint, { method: "PUT", body: JSON.stringify(message) });
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/contact/openMessage`;
|
||||
const open = await fetchWithTimeout(endpoint, { method: 'PUT', body: JSON.stringify(message) });
|
||||
checkResponse(open.status);
|
||||
return await open.json();
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { DataMessage } from "../entities";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { DataMessage } from '../entities';
|
||||
|
||||
export async function setCardProfile(node: string, secure: boolean, token: string, cardId: string, data: DataMessage): Promise<void> {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/contact/cards/${cardId}/profile?agent=${token}`;
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/contact/cards/${cardId}/profile?agent=${token}`;
|
||||
const { status } = await fetchWithTimeout(endpoint, {
|
||||
method: "PUT",
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
checkResponse(status);
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function setContactChannelNotifications(node: string, secure: boolean, guid: string, token: string, channelId: string, enabled: boolean) {
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/content/channels/${channelId}/notification?contact=${guid}.${token}`
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/content/channels/${channelId}/notification?contact=${guid}.${token}`;
|
||||
const notify = await fetchWithTimeout(endpoint, { method: 'PUT', body: JSON.stringify(enabled) });
|
||||
checkResponse(notify.status)
|
||||
checkResponse(notify.status);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { encode } from "./base64";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import { encode } from './base64';
|
||||
|
||||
export async function setLogin(
|
||||
node: string,
|
||||
@ -19,13 +19,13 @@ export async function setLogin(
|
||||
created: number;
|
||||
pushSupported: boolean;
|
||||
}> {
|
||||
const mfa = code ? `&code=${code}` : "";
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/account/apps?appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}&pushType=${pushType}${mfa}`;
|
||||
const mfa = code ? `&code=${code}` : '';
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/account/apps?appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}&pushType=${pushType}${mfa}`;
|
||||
const auth = encode(`${username}:${password}`);
|
||||
const headers = new Headers();
|
||||
headers.append("Authorization", "Basic " + auth);
|
||||
headers.append('Authorization', 'Basic ' + auth);
|
||||
const login = await fetchWithTimeout(endpoint, {
|
||||
method: "POST",
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify(notifications),
|
||||
});
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function setProfileData(node: string, secure: boolean, token: string, name: string, location: string, description: string): Promise<void> {
|
||||
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 endpoint = `http${secure ? 's' : ''}://${node}/profile/data?agent=${token}`;
|
||||
const { status } = await fetchWithTimeout(endpoint, { method: 'PUT', body: JSON.stringify(data) });
|
||||
checkResponse(status);
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from "./fetchUtil";
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function setProfileImage(node: string, secure: boolean, token: string, image: string) {
|
||||
const endpoint = `http${secure ? "s" : ""}://${node}/profile/image?agent=${token}`;
|
||||
const endpoint = `http${secure ? 's' : ''}://${node}/profile/image?agent=${token}`;
|
||||
const { status } = await fetchWithTimeout(endpoint, {
|
||||
method: "PUT",
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(image),
|
||||
});
|
||||
checkResponse(status);
|
||||
|
@ -1,6 +1,6 @@
|
||||
import type { Node } from "./api";
|
||||
import type { NodeAccount, NodeConfig } from "./types";
|
||||
import type { Logging } from "./logging";
|
||||
import type { Node } from './api';
|
||||
import type { NodeAccount, NodeConfig } from './types';
|
||||
import type { Logging } from './logging';
|
||||
|
||||
export class NodeModule implements Node {
|
||||
private log: Logging;
|
||||
@ -16,11 +16,11 @@ export class NodeModule implements Node {
|
||||
}
|
||||
|
||||
public async createAccountAccess(): Promise<string> {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
|
||||
public async resetAccountAccess(): Promise<string> {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
|
||||
public async blockAccount(flag: boolean): Promise<void> {}
|
||||
@ -33,21 +33,21 @@ export class NodeModule implements Node {
|
||||
|
||||
public async getConfig(): Promise<NodeConfig> {
|
||||
return {
|
||||
domain: "",
|
||||
accountStorage: "",
|
||||
domain: '',
|
||||
accountStorage: '',
|
||||
enableImage: true,
|
||||
enableAudio: true,
|
||||
enableVideo: true,
|
||||
enableBinary: true,
|
||||
keyType: "",
|
||||
keyType: '',
|
||||
pushSupported: true,
|
||||
allowUnsealed: true,
|
||||
transformSupported: true,
|
||||
enableIce: true,
|
||||
iceService: "",
|
||||
iceUrl: "",
|
||||
iceUsername: "",
|
||||
icePassword: "",
|
||||
iceService: '',
|
||||
iceUrl: '',
|
||||
iceUsername: '',
|
||||
icePassword: '',
|
||||
enableOpenAccess: true,
|
||||
openAccessLimit: 0,
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { EventEmitter } from "eventemitter3";
|
||||
import type { Ring, Logging } from "./api";
|
||||
import type { Call } from "./types";
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
import type { Ring, Logging } from './api';
|
||||
import type { Call } from './types';
|
||||
|
||||
export class RingModule implements Ring {
|
||||
private log: Logging;
|
||||
@ -12,19 +12,19 @@ export class RingModule implements Ring {
|
||||
}
|
||||
|
||||
public addCallingListener(ev: (calls: Call[]) => void): void {
|
||||
this.emitter.on("calling", ev);
|
||||
this.emitter.on('calling', ev);
|
||||
}
|
||||
|
||||
public removeCallingListener(ev: (calls: Call[]) => void): void {
|
||||
this.emitter.off("calling", ev);
|
||||
this.emitter.off('calling', ev);
|
||||
}
|
||||
|
||||
public addCallListener(ev: (call: Call | null) => void): void {
|
||||
this.emitter.on("call", ev);
|
||||
this.emitter.on('call', ev);
|
||||
}
|
||||
|
||||
public removeCallListener(ev: (call: Call | null) => void): void {
|
||||
this.emitter.off("call", ev);
|
||||
this.emitter.off('call', ev);
|
||||
}
|
||||
|
||||
public ring(call: Call): void {}
|
||||
|
@ -1,23 +1,23 @@
|
||||
import { EventEmitter } from "eventemitter3";
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
|
||||
import { SettingsModule } from "./settings";
|
||||
import { IdentityModule } from "./identity";
|
||||
import { ContactModule } from "./contact";
|
||||
import { AliasModule } from "./alias";
|
||||
import { AttributeModule } from "./attribute";
|
||||
import { ContentModule } from "./content";
|
||||
import { StreamModule } from "./stream";
|
||||
import { FocusModule } from "./focus";
|
||||
import { RingModule } from "./ring";
|
||||
import { SettingsModule } from './settings';
|
||||
import { IdentityModule } from './identity';
|
||||
import { ContactModule } from './contact';
|
||||
import { AliasModule } from './alias';
|
||||
import { AttributeModule } from './attribute';
|
||||
import { ContentModule } from './content';
|
||||
import { StreamModule } from './stream';
|
||||
import { FocusModule } from './focus';
|
||||
import { RingModule } from './ring';
|
||||
|
||||
import { Connection } from "./connection";
|
||||
import { Connection } from './connection';
|
||||
|
||||
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";
|
||||
import type { Logging } from "./logging";
|
||||
import type { Crypto } from "./crypto";
|
||||
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';
|
||||
import type { Logging } from './logging';
|
||||
import type { Crypto } from './crypto';
|
||||
|
||||
export class SessionModule implements Session {
|
||||
private emitter: EventEmitter;
|
||||
@ -43,7 +43,7 @@ export class SessionModule implements Session {
|
||||
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[]) {
|
||||
log.info("new databag session");
|
||||
log.info('new databag session');
|
||||
|
||||
this.store = store;
|
||||
this.crypto = crypto;
|
||||
@ -55,7 +55,7 @@ export class SessionModule implements Session {
|
||||
this.channelTypes = channelTypes;
|
||||
this.articleTypes = articleTypes;
|
||||
this.loginTimestamp = loginTimestamp;
|
||||
this.status = "connecting";
|
||||
this.status = 'connecting';
|
||||
this.emitter = new EventEmitter();
|
||||
|
||||
this.identity = new IdentityModule(log, this.store, guid, token, node, secure);
|
||||
@ -70,7 +70,7 @@ export class SessionModule implements Session {
|
||||
|
||||
const onStatus = (ev: string) => {
|
||||
this.status = ev;
|
||||
this.emitter.emit("status", this.getStatus());
|
||||
this.emitter.emit('status', this.getStatus());
|
||||
};
|
||||
|
||||
const onSeal = (seal: { privateKey: string; publicKey: string } | null) => {
|
||||
@ -97,11 +97,11 @@ export class SessionModule implements Session {
|
||||
}
|
||||
|
||||
public addStatusListener(ev: (status: string) => void): void {
|
||||
this.emitter.on("status", ev);
|
||||
this.emitter.on('status', ev);
|
||||
}
|
||||
|
||||
public removeStatusListener(ev: (status: string) => void): void {
|
||||
this.emitter.off("status", ev);
|
||||
this.emitter.off('status', ev);
|
||||
}
|
||||
|
||||
private getStatus(): string {
|
||||
|
@ -1,20 +1,20 @@
|
||||
import { EventEmitter } from "eventemitter3";
|
||||
import type { Settings } from "./api";
|
||||
import type { Config } from "./types";
|
||||
import { Store } from "./store";
|
||||
import { Crypto } from "./crypto";
|
||||
import { Logging } from "./logging";
|
||||
import { defaultConfigEntity, ConfigEntity } from "./entities";
|
||||
import { getAccountStatus } from "./net/getAccountStatus";
|
||||
import { addAccountMFAuth } from "./net/addAccountMFAuth";
|
||||
import { setAccountMFAuth } from "./net/setAccountMFAuth";
|
||||
import { removeAccountMFAuth } from "./net/removeAccountMFAuth";
|
||||
import { setAccountLogin } from "./net/setAccountLogin";
|
||||
import { setAccountNotifications } from "./net/setAccountNotifications";
|
||||
import { setAccountSearchable } from "./net/setAccountSearchable";
|
||||
import { setAccountSeal } from "./net/setAccountSeal";
|
||||
import { clearAccountSeal } from "./net/clearAccountSeal";
|
||||
import { getUsername } from "./net/getUsername";
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
import type { Settings } from './api';
|
||||
import type { Config } from './types';
|
||||
import { Store } from './store';
|
||||
import { Crypto } from './crypto';
|
||||
import { Logging } from './logging';
|
||||
import { defaultConfigEntity, ConfigEntity } from './entities';
|
||||
import { getAccountStatus } from './net/getAccountStatus';
|
||||
import { addAccountMFAuth } from './net/addAccountMFAuth';
|
||||
import { setAccountMFAuth } from './net/setAccountMFAuth';
|
||||
import { removeAccountMFAuth } from './net/removeAccountMFAuth';
|
||||
import { setAccountLogin } from './net/setAccountLogin';
|
||||
import { setAccountNotifications } from './net/setAccountNotifications';
|
||||
import { setAccountSearchable } from './net/setAccountSearchable';
|
||||
import { setAccountSeal } from './net/setAccountSeal';
|
||||
import { clearAccountSeal } from './net/clearAccountSeal';
|
||||
import { getUsername } from './net/getUsername';
|
||||
|
||||
const CLOSE_POLL_MS = 100;
|
||||
const RETRY_POLL_MS = 2000;
|
||||
@ -64,8 +64,8 @@ export class SettingsModule implements Settings {
|
||||
this.revision = await this.store.getSettingsRevision(this.guid);
|
||||
this.config = await this.store.getSettingsData(this.guid);
|
||||
this.seal = await this.store.getSeal(this.guid);
|
||||
this.emitter.emit("seal", this.getSeal());
|
||||
this.emitter.emit("config", this.getConfig());
|
||||
this.emitter.emit('seal', this.getSeal());
|
||||
this.emitter.emit('config', this.getConfig());
|
||||
this.syncing = false;
|
||||
await this.sync();
|
||||
}
|
||||
@ -84,8 +84,8 @@ export class SettingsModule implements Settings {
|
||||
await this.store.setSettingsData(guid, config);
|
||||
await this.store.setSettingsRevision(guid, nextRev);
|
||||
this.config = config;
|
||||
this.emitter.emit("config", this.getConfig());
|
||||
this.emitter.emit("seal", this.getSeal());
|
||||
this.emitter.emit('config', this.getConfig());
|
||||
this.emitter.emit('seal', this.getSeal());
|
||||
this.revision = nextRev;
|
||||
if (this.nextRevision === nextRev) {
|
||||
this.nextRevision = null;
|
||||
@ -123,21 +123,21 @@ export class SettingsModule implements Settings {
|
||||
}
|
||||
|
||||
public addConfigListener(ev: (config: Config) => void): void {
|
||||
this.emitter.on("config", ev);
|
||||
this.emitter.emit("config", this.getConfig());
|
||||
this.emitter.on('config', ev);
|
||||
this.emitter.emit('config', this.getConfig());
|
||||
}
|
||||
|
||||
public removeConfigListener(ev: (config: Config) => void): void {
|
||||
this.emitter.off("config", ev);
|
||||
this.emitter.off('config', ev);
|
||||
}
|
||||
|
||||
public addSealListener(ev: (seal: { privateKey: string; publicKey: string } | null) => void): void {
|
||||
this.emitter.on("seal", ev);
|
||||
this.emitter.on('seal', ev);
|
||||
ev(this.seal);
|
||||
}
|
||||
|
||||
public removeSealListener(ev: (seal: { privateKey: string; publicKey: string } | null) => void): void {
|
||||
this.emitter.off("seal", ev);
|
||||
this.emitter.off('seal', ev);
|
||||
}
|
||||
|
||||
public async close(): Promise<void> {
|
||||
@ -194,7 +194,7 @@ export class SettingsModule implements Settings {
|
||||
public async setSeal(password: string): Promise<void> {
|
||||
const { crypto, guid, node, secure, token } = this;
|
||||
if (!crypto) {
|
||||
throw new Error("crypto not enabled");
|
||||
throw new Error('crypto not enabled');
|
||||
}
|
||||
const { saltHex } = await crypto.pbkdfSalt();
|
||||
const { aesKeyHex } = await crypto.pbkdfKey(saltHex, password);
|
||||
@ -210,17 +210,17 @@ export class SettingsModule implements Settings {
|
||||
await setAccountSeal(node, secure, token, seal);
|
||||
this.seal = { publicKey: publicKeyB64, privateKey: privateKeyB64 };
|
||||
this.store.setSeal(guid, this.seal);
|
||||
this.emitter.emit("config", this.getConfig());
|
||||
this.emitter.emit("seal", this.getSeal());
|
||||
this.emitter.emit('config', this.getConfig());
|
||||
this.emitter.emit('seal', this.getSeal());
|
||||
}
|
||||
|
||||
public async updateSeal(password: string): Promise<void> {
|
||||
const { crypto, config, node, secure, token } = this;
|
||||
if (!crypto) {
|
||||
throw new Error("crypto not enabled");
|
||||
throw new Error('crypto not enabled');
|
||||
}
|
||||
if (!this.seal || this.seal.publicKey !== config.seal.publicKey) {
|
||||
throw new Error("seal not unlocked");
|
||||
throw new Error('seal not unlocked');
|
||||
}
|
||||
const { saltHex } = await crypto.pbkdfSalt();
|
||||
const { aesKeyHex } = await crypto.pbkdfKey(saltHex, password);
|
||||
@ -240,34 +240,34 @@ export class SettingsModule implements Settings {
|
||||
await clearAccountSeal(node, secure, token);
|
||||
await this.store.clearSeal(guid);
|
||||
this.seal = null;
|
||||
this.emitter.emit("config", this.getConfig());
|
||||
this.emitter.emit("seal", this.getSeal());
|
||||
this.emitter.emit('config', this.getConfig());
|
||||
this.emitter.emit('seal', this.getSeal());
|
||||
}
|
||||
|
||||
public async unlockSeal(password: string): Promise<void> {
|
||||
const { guid, config, crypto } = this;
|
||||
const { passwordSalt, privateKeyIv, privateKeyEncrypted, publicKey } = config.seal;
|
||||
if (!passwordSalt || !privateKeyIv || !privateKeyEncrypted || !publicKey) {
|
||||
throw new Error("account seal not set");
|
||||
throw new Error('account seal not set');
|
||||
}
|
||||
if (!crypto) {
|
||||
throw new Error("crypto not set");
|
||||
throw new Error('crypto not set');
|
||||
}
|
||||
const { aesKeyHex } = await crypto.pbkdfKey(passwordSalt, password);
|
||||
const { data } = await crypto.aesDecrypt(privateKeyEncrypted, privateKeyIv, aesKeyHex);
|
||||
const seal = { publicKey: publicKey, privateKey: data };
|
||||
this.store.setSeal(guid, seal);
|
||||
this.seal = seal;
|
||||
this.emitter.emit("config", this.getConfig());
|
||||
this.emitter.emit("seal", this.getSeal());
|
||||
this.emitter.emit('config', this.getConfig());
|
||||
this.emitter.emit('seal', this.getSeal());
|
||||
}
|
||||
|
||||
public async forgetSeal(): Promise<void> {
|
||||
const { guid } = this;
|
||||
await this.store.clearSeal(guid);
|
||||
this.seal = null;
|
||||
this.emitter.emit("config", this.getConfig());
|
||||
this.emitter.emit("seal", this.getSeal());
|
||||
this.emitter.emit('config', this.getConfig());
|
||||
this.emitter.emit('seal', this.getSeal());
|
||||
}
|
||||
|
||||
public async getUsernameStatus(username: string): Promise<boolean> {
|
||||
|
@ -1,6 +1,6 @@
|
||||
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";
|
||||
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 {
|
||||
init(): Promise<Login | null>;
|
||||
@ -87,17 +87,16 @@ export class OfflineStore implements Store {
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
|
||||
private async getValues(guid: string, table: string, fields: string[]): Promise<any[]> {
|
||||
return await this.sql.get(`SELECT ${fields.join(', ')} FROM ${table}_${guid}`)
|
||||
return await this.sql.get(`SELECT ${fields.join(', ')} FROM ${table}_${guid}`);
|
||||
}
|
||||
|
||||
private async addValue(guid: string, table: string, fields: string[], value: (string | number | null)[]): Promise<void> {
|
||||
return await this.sql.set(`INSERT INTO ${table}_${guid} (${fields.join(', ')}) VALUES (${fields.map(field => '?').join(', ')})`, value);
|
||||
return await this.sql.set(`INSERT INTO ${table}_${guid} (${fields.join(', ')}) VALUES (${fields.map((field) => '?').join(', ')})`, value);
|
||||
}
|
||||
|
||||
private async setValue(guid: string, table: string, idField: string, fields: string[], idValue: string | number, value: (string | number | null)[]): Promise<void> {
|
||||
return await this.sql.set(`UPDATE ${table}_${guid} SET ${fields.map(field => `${field}=?`).join(',')} WHERE ${idField}=?`, [ ...value, idValue ]);
|
||||
return await this.sql.set(`UPDATE ${table}_${guid} SET ${fields.map((field) => `${field}=?`).join(',')} WHERE ${idField}=?`, [...value, idValue]);
|
||||
}
|
||||
|
||||
private async removeValue(guid: string, table: string, idField: string, idValue: string | number): Promise<void> {
|
||||
@ -107,8 +106,7 @@ export class OfflineStore implements Store {
|
||||
private parse(value: string): any {
|
||||
try {
|
||||
return JSON.parse(value);
|
||||
}
|
||||
catch (err) {
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
return {};
|
||||
@ -127,11 +125,11 @@ export class OfflineStore implements Store {
|
||||
}
|
||||
|
||||
private async setAppValue(guid: string, id: string, value: any): Promise<void> {
|
||||
await this.sql.set("INSERT OR REPLACE INTO app (key, value) values (?, ?)", [`${guid}::${id}`, JSON.stringify(value)]);
|
||||
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<void> {
|
||||
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<void> {
|
||||
@ -150,14 +148,12 @@ export class OfflineStore implements Store {
|
||||
await this.sql.set(
|
||||
`CREATE TABLE IF NOT EXISTS card_channel_topic_${guid} (card_id text, channel_id text, topic_id text, revision integer, created integer, detail_revision integer, detail text, unsealed_detail text, unique(card_id, channel_id, topic_id))`,
|
||||
);
|
||||
await this.sql.set(
|
||||
`CREATE TABLE IF NOT EXISTS marker_${guid} (value text)`,
|
||||
);
|
||||
await this.sql.set(`CREATE TABLE IF NOT EXISTS marker_${guid} (value text)`);
|
||||
}
|
||||
|
||||
public async init(): Promise<Login | null> {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
public async setMarker(guid: string, value: string) {
|
||||
@ -169,76 +165,87 @@ export class OfflineStore implements Store {
|
||||
}
|
||||
|
||||
public async getMarkers(guid: string): Promise<string[]> {
|
||||
return (await this.getValues(guid, 'marker', ['value'])).map(marker => marker.value);
|
||||
return (await this.getValues(guid, 'marker', ['value'])).map((marker) => marker.value);
|
||||
}
|
||||
|
||||
public async setLogin(login: Login): Promise<void> {
|
||||
await this.initLogin(login.guid);
|
||||
await this.setAppValue("", "login", login);
|
||||
await this.setAppValue('', 'login', login);
|
||||
}
|
||||
|
||||
public async clearLogin(): Promise<void> {
|
||||
await this.clearAppValue("", "login");
|
||||
await this.clearAppValue('', 'login');
|
||||
}
|
||||
|
||||
public async getSeal(guid: string): Promise<{ publicKey: string; privateKey: string } | null> {
|
||||
return (await this.getAppValue(guid, "seal", null)) as {
|
||||
return (await this.getAppValue(guid, 'seal', null)) as {
|
||||
publicKey: string;
|
||||
privateKey: string;
|
||||
} | null;
|
||||
}
|
||||
|
||||
public async setSeal(guid: string, seal: { publicKey: string; privateKey: string }): Promise<void> {
|
||||
await this.setAppValue(guid, "seal", seal);
|
||||
await this.setAppValue(guid, 'seal', seal);
|
||||
}
|
||||
|
||||
public async clearSeal(guid: string): Promise<void> {
|
||||
await this.clearAppValue(guid, "seal");
|
||||
await this.clearAppValue(guid, 'seal');
|
||||
}
|
||||
|
||||
public async getProfileRevision(guid: string): Promise<number> {
|
||||
return (await this.getAppValue(guid, "profile_revision", 0)) as number;
|
||||
return (await this.getAppValue(guid, 'profile_revision', 0)) as number;
|
||||
}
|
||||
|
||||
public async setProfileRevision(guid: string, revision: number): Promise<void> {
|
||||
await this.setAppValue(guid, "profile_revision", revision);
|
||||
await this.setAppValue(guid, 'profile_revision', revision);
|
||||
}
|
||||
|
||||
public async getProfileData(guid: string): Promise<ProfileEntity> {
|
||||
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<void> {
|
||||
await this.setAppValue(guid, "profile_data", data);
|
||||
await this.setAppValue(guid, 'profile_data', data);
|
||||
}
|
||||
|
||||
public async getSettingsRevision(guid: string): Promise<number> {
|
||||
return (await this.getAppValue(guid, "account_revision", 0)) as number;
|
||||
return (await this.getAppValue(guid, 'account_revision', 0)) as number;
|
||||
}
|
||||
|
||||
public async setSettingsRevision(guid: string, revision: number): Promise<void> {
|
||||
await this.setAppValue(guid, "account_revision", revision);
|
||||
await this.setAppValue(guid, 'account_revision', revision);
|
||||
}
|
||||
|
||||
public async getSettingsData(guid: string): Promise<ConfigEntity> {
|
||||
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<void> {
|
||||
await this.setAppValue(guid, "account_data", data);
|
||||
await this.setAppValue(guid, 'account_data', data);
|
||||
}
|
||||
|
||||
public async getContactRevision(guid: string): Promise<number> {
|
||||
return (await this.getAppValue(guid, "contact_revision", 0)) as number;
|
||||
return (await this.getAppValue(guid, 'contact_revision', 0)) as number;
|
||||
}
|
||||
|
||||
public async setContactRevision(guid: string, revision: number): Promise<void> {
|
||||
await this.setAppValue(guid, "contact_revision", revision);
|
||||
await this.setAppValue(guid, 'contact_revision', revision);
|
||||
}
|
||||
|
||||
public async getContacts(guid: string): Promise<{ cardId: string; item: CardItem }[]> {
|
||||
const cards = await this.getValues(guid, 'card', ['offsync_profile', 'offsync_article', 'offsync_channel', 'revision', 'card_id', 'profile', 'detail', 'profile_revision', 'article_revision', 'channel_revision']);
|
||||
return cards.map(card => ({
|
||||
const cards = await this.getValues(guid, 'card', [
|
||||
'offsync_profile',
|
||||
'offsync_article',
|
||||
'offsync_channel',
|
||||
'revision',
|
||||
'card_id',
|
||||
'profile',
|
||||
'detail',
|
||||
'profile_revision',
|
||||
'article_revision',
|
||||
'channel_revision',
|
||||
]);
|
||||
return cards.map((card) => ({
|
||||
cardId: card.card_id,
|
||||
item: {
|
||||
offsyncProfile: card.offsync_profile,
|
||||
@ -250,7 +257,7 @@ export class OfflineStore implements Store {
|
||||
profileRevision: card.profile_revision,
|
||||
articleRevision: card.article_revision,
|
||||
channelRevision: card.channel_revision,
|
||||
}
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
@ -313,7 +320,6 @@ export class OfflineStore implements Store {
|
||||
await this.setValue(guid, 'card', 'card_id', ['channel_revision'], cardId, [revision]);
|
||||
}
|
||||
|
||||
|
||||
public async getContactCardArticles(guid: string): Promise<{ cardId: string; articleId: string; item: ArticleItem }[]> {
|
||||
return [];
|
||||
}
|
||||
@ -373,7 +379,7 @@ export class OnlineStore implements Store {
|
||||
}
|
||||
|
||||
public async init(): Promise<Login | null> {
|
||||
return (await this.getAppValue("", "login", null)) as Login | null;
|
||||
return (await this.getAppValue('', 'login', null)) as Login | null;
|
||||
}
|
||||
|
||||
public async setMarker(guid: string, value: string) {
|
||||
@ -384,7 +390,11 @@ export class OnlineStore implements Store {
|
||||
|
||||
public async clearMarker(guid: string, value: string) {
|
||||
const markers = (await this.getAppValue(guid, 'marker', [])) as string[];
|
||||
this.setAppValue(guid, 'marker', markers.filter(marker => (value != marker)));
|
||||
this.setAppValue(
|
||||
guid,
|
||||
'marker',
|
||||
markers.filter((marker) => value != marker),
|
||||
);
|
||||
}
|
||||
|
||||
public async getMarkers(guid: string): Promise<string[]> {
|
||||
@ -392,26 +402,26 @@ export class OnlineStore implements Store {
|
||||
}
|
||||
|
||||
public async setLogin(login: Login): Promise<void> {
|
||||
await this.setAppValue("", "login", login);
|
||||
await this.setAppValue('', 'login', login);
|
||||
}
|
||||
|
||||
public async clearLogin(): Promise<void> {
|
||||
await this.clearAppValue("", "login");
|
||||
await this.clearAppValue('', 'login');
|
||||
}
|
||||
|
||||
public async getSeal(guid: string): Promise<{ publicKey: string; privateKey: string } | null> {
|
||||
return (await this.getAppValue(guid, "seal", null)) as {
|
||||
return (await this.getAppValue(guid, 'seal', null)) as {
|
||||
publicKey: string;
|
||||
privateKey: string;
|
||||
} | null;
|
||||
}
|
||||
|
||||
public async setSeal(guid: string, seal: { publicKey: string; privateKey: string }): Promise<void> {
|
||||
await this.setAppValue(guid, "seal", seal);
|
||||
await this.setAppValue(guid, 'seal', seal);
|
||||
}
|
||||
|
||||
public async clearSeal(guid: string): Promise<void> {
|
||||
await this.clearAppValue(guid, "seal");
|
||||
await this.clearAppValue(guid, 'seal');
|
||||
}
|
||||
|
||||
public async getProfileRevision(guid: string): Promise<number> {
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { EventEmitter } from "eventemitter3";
|
||||
import type { Contact, Content, Stream } from "./api";
|
||||
import type { Channel } from "./types";
|
||||
import { Store } from "./store";
|
||||
import { Logging } from "./logging";
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
import type { Contact, Content, Stream } from './api';
|
||||
import type { Channel } from './types';
|
||||
import { Store } from './store';
|
||||
import { Logging } from './logging';
|
||||
|
||||
export class StreamModule implements Stream {
|
||||
private log: Logging;
|
||||
@ -20,11 +20,11 @@ export class StreamModule implements Stream {
|
||||
}
|
||||
|
||||
public addChannelListener(ev: (channels: Channel[]) => void): void {
|
||||
this.emitter.on("channel", ev);
|
||||
this.emitter.on('channel', ev);
|
||||
}
|
||||
|
||||
public removeChannelListener(ev: (channels: Channel[]) => void): void {
|
||||
this.emitter.off("channel", ev);
|
||||
this.emitter.off('channel', ev);
|
||||
}
|
||||
|
||||
public async close(): Promise<void> {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user