diff --git a/app/sdk/src/account.ts b/app/sdk/src/account.ts index 38be5e28..80a0f8c8 100644 --- a/app/sdk/src/account.ts +++ b/app/sdk/src/account.ts @@ -1,5 +1,5 @@ import { EventEmitter } from 'events'; -import { type Account, type Seal, type SealKey, type AccountStatus } from './types'; +import { type Account, type Seal, type SealKey, type AccountStatus } from './api'; export class AccountModule implements Account { diff --git a/app/sdk/src/api.ts b/app/sdk/src/api.ts new file mode 100644 index 00000000..33d1ccbf --- /dev/null +++ b/app/sdk/src/api.ts @@ -0,0 +1,129 @@ + +export interface SqlStore { + set(stmt: string, params: (string | number)[]): Promise; + get(stmt: string, params: (string | number)[]): Promise; +} + +export interface WebStore { + getValue(key: string): Promise; + setValue(key: string, value: string): Promise; + clearValue(key: string): Promise; + clearAll(): Promise; +} + +export interface Session { + getAccount(): Account; + getIdentity(): Identity; + getContact(): Contact; + getGroup(): Group; + getAttribute(): Attribute; + getContent(): Content; + + resync(): void; + addStatusListener(ev: (status: string) => void): void; + removeStatusListener(ev: (status: string) => void): void; +} + +export interface Node { +} + +export interface Account { + setNotifications(flag: boolean): Promise; + setSearchable(flag: boolean): Promise; + enableMFA(): Promise; + disableMFA(): Promise; + confirmMFA(): Promise; + setAccountSeal(seal: Seal, key: SealKey): Promise + unlockAccountSeal(key: SealKey): Promise + setLogin(username: string, password: string): Promise + + addStatusListener(ev: (status: AccountStatus) => void): void; + removeStatusListener(ev: (status: AccountStatus) => void): void; +} + +export interface Identity { + setProfileData(name: string, location: string, description: string): Promise; + setProfileImage(image: string): Promise; + getHandleStatus(handle: string): Promise; + + addProfileListener(ev: (profile: Profile) => void): void; + removeProfileListener(ev: (profile: Profile) => void): void; +} + +export interface Contact { +} + +export interface Group { +} + +export interface Attribute { +} + +export interface Content { + addChannel(type: string, subject: string, cardIds: string[]): Promise; + removeChannel(channelId: string): Promise; + setChannelSubject(channelId: string, type: string, subject: string): Promise; + setChannelCard(channelId: string, cardId: string): Promise; + clearChannelCard(channelId: string, cardId: string): Promise; + addTopic(channelId: string, type: string, message: string, assets: Asset[]): Promise; + removeTopic(channelId: string, topicId: string): Promise; + setTopicSubject(channelId: string, topicId: string, type: string, subject: string): Promise; + getTopicAssetUrl(channelId: string, topicId: string, assetId: string): string; + getTopics(channelId: string, revision: number, count: number, begin: number, end: number): Promise; + getTopic(channelId: string, topicId: string): Promise; + + addChannelListener(ev: (channels: Channel[]) => void): void; + removeChannelListener(ev: (channels: Channel[]) => void): void; +} + +export interface SealKey { + publicKey: string; + privateKey: string; +} + +export interface Seal { + passwordSalt: string; + privateKeyIv: string; + privateKeyEncrypted: string; + publicKey: string; +} + +export interface AccountStatus { + disabled: boolean; + storageUsed: number; + storageAvailable: number; + forwardingAddress: string; + searchable: boolean; + allowUnsealed: boolean; + pushEnabled: boolean; + sealable: boolean; + seal: Seal; + enableIce: boolean; + multiFactorAuth: boolean; + webPushKey: string; +} + +export interface Profile { + guid: string; + handle: string; + name: string; + description: string; + location: string; + image: string; + revision: number; + seal: string; + version: string; + node: string; +} + +export interface Card { +} + +export interface Channel { +} + +export interface Topic { +} + +export interface Asset { +} diff --git a/app/sdk/src/attribute.ts b/app/sdk/src/attribute.ts index 0e8efaa3..9ff2c5d3 100644 --- a/app/sdk/src/attribute.ts +++ b/app/sdk/src/attribute.ts @@ -1,5 +1,5 @@ import { EventEmitter } from 'events'; -import { type Attribute } from './types'; +import { type Attribute } from './api'; export class AttributeModule implements Attribute { diff --git a/app/sdk/src/contact.ts b/app/sdk/src/contact.ts index 18bc3590..749363d6 100644 --- a/app/sdk/src/contact.ts +++ b/app/sdk/src/contact.ts @@ -1,5 +1,4 @@ -export interface Contact { -} +import { type Contact } from './api'; export class ContactModule implements Contact { constructor(token: string, url: string, sync: (flag: boolean) => void) {} diff --git a/app/sdk/src/content.ts b/app/sdk/src/content.ts index 2b1c1f90..3c0b7bce 100644 --- a/app/sdk/src/content.ts +++ b/app/sdk/src/content.ts @@ -1,5 +1,5 @@ import { EventEmitter } from 'events'; -import { type Content, type Channel, type Topic, type Asset } from './types'; +import { type Content, type Channel, type Topic, type Asset } from './api'; export class ContentModule implements Content { diff --git a/app/sdk/src/group.ts b/app/sdk/src/group.ts index b7abe148..3a439421 100644 --- a/app/sdk/src/group.ts +++ b/app/sdk/src/group.ts @@ -1,4 +1,4 @@ -import { type Group } from './types'; +import { type Group } from './api'; export class GroupModule implements Group { constructor(token: string, url: string, sync: (flag: boolean) => void) {} diff --git a/app/sdk/src/identity.ts b/app/sdk/src/identity.ts index 5b051552..b80f85a6 100644 --- a/app/sdk/src/identity.ts +++ b/app/sdk/src/identity.ts @@ -1,5 +1,5 @@ import { EventEmitter } from 'events'; -import { type Identity, type Profile } from './types'; +import { type Identity, type Profile } from './api'; export class IdentityModule implements Identity { diff --git a/app/sdk/src/index.ts b/app/sdk/src/index.ts index 7aebd017..35a7a070 100644 --- a/app/sdk/src/index.ts +++ b/app/sdk/src/index.ts @@ -1,7 +1,7 @@ import { SessionModule } from './session'; import { NodeModule } from './node'; -import { type Session, type Node, type SqlStore, type WebStore } from './types'; +import { type Session, type Node, type SqlStore, type WebStore } from './api'; export class DatabagSDK { diff --git a/app/sdk/src/session.ts b/app/sdk/src/session.ts index 17644acf..e123e813 100644 --- a/app/sdk/src/session.ts +++ b/app/sdk/src/session.ts @@ -7,7 +7,7 @@ import { GroupModule } from './group'; import { AttributeModule } from './attribute'; import { ContentModule } from './content'; -import { type Session, type SqlStore, type WebStore, type Account, type Identity, type Contact, type Group, type Attribute, type Content } from './types'; +import { type Session, type SqlStore, type WebStore, type Account, type Identity, type Contact, type Group, type Attribute, type Content } from './api'; export class SessionModule implements Session { diff --git a/app/sdk/src/types.ts b/app/sdk/src/types.ts index 8bb9fd91..8b137891 100644 --- a/app/sdk/src/types.ts +++ b/app/sdk/src/types.ts @@ -1,130 +1 @@ -import { EventEmitter } from 'events'; -export interface SqlStore { - set(stmt: string, params: (string | number)[]): Promise; - get(stmt: string, params: (string | number)[]): Promise; -} - -export interface WebStore { - getValue(key: string): Promise; - setValue(key: string, value: string): Promise; - clearValue(key: string): Promise; - clearAll(): Promise; -} - -export interface Session { - getAccount(): Account; - getIdentity(): Identity; - getContact(): Contact; - getGroup(): Group; - getAttribute(): Attribute; - getContent(): Content; - - resync(): void; - addStatusListener(ev: (status: string) => void): void; - removeStatusListener(ev: (status: string) => void): void; -} - -export interface Node { -} - -export interface Account { - setNotifications(flag: boolean): Promise; - setSearchable(flag: boolean): Promise; - enableMFA(): Promise; - disableMFA(): Promise; - confirmMFA(): Promise; - setAccountSeal(seal: Seal, key: SealKey): Promise - unlockAccountSeal(key: SealKey): Promise - setLogin(username: string, password: string): Promise - - addStatusListener(ev: (status: AccountStatus) => void): void; - removeStatusListener(ev: (status: AccountStatus) => void): void; -} - -export interface Identity { - setProfileData(name: string, location: string, description: string): Promise; - setProfileImage(image: string): Promise; - getHandleStatus(handle: string): Promise; - - addProfileListener(ev: (profile: Profile) => void): void; - removeProfileListener(ev: (profile: Profile) => void): void; -} - -export interface Contact { -} - -export interface Group { -} - -export interface Attribute { -} - -export interface Content { - addChannel(type: string, subject: string, cardIds: string[]): Promise; - removeChannel(channelId: string): Promise; - setChannelSubject(channelId: string, type: string, subject: string): Promise; - setChannelCard(channelId: string, cardId: string): Promise; - clearChannelCard(channelId: string, cardId: string): Promise; - addTopic(channelId: string, type: string, message: string, assets: Asset[]): Promise; - removeTopic(channelId: string, topicId: string): Promise; - setTopicSubject(channelId: string, topicId: string, type: string, subject: string): Promise; - getTopicAssetUrl(channelId: string, topicId: string, assetId: string): string; - getTopics(channelId: string, revision: number, count: number, begin: number, end: number): Promise; - getTopic(channelId: string, topicId: string): Promise; - - addChannelListener(ev: (channels: Channel[]) => void): void; - removeChannelListener(ev: (channels: Channel[]) => void): void; -} - -export interface SealKey { - publicKey: string; - privateKey: string; -} - -export interface Seal { - passwordSalt: string; - privateKeyIv: string; - privateKeyEncrypted: string; - publicKey: string; -} - -export interface AccountStatus { - disabled: boolean; - storageUsed: number; - storageAvailable: number; - forwardingAddress: string; - searchable: boolean; - allowUnsealed: boolean; - pushEnabled: boolean; - sealable: boolean; - seal: Seal; - enableIce: boolean; - multiFactorAuth: boolean; - webPushKey: string; -} - -export interface Profile { - guid: string; - handle: string; - name: string; - description: string; - location: string; - image: string; - revision: number; - seal: string; - version: string; - node: string; -} - -export interface Card { -} - -export interface Channel { -} - -export interface Topic { -} - -export interface Asset { -} diff --git a/app/sdk/tsup.config.ts b/app/sdk/tsup.config.ts index 56635355..4168b43c 100644 --- a/app/sdk/tsup.config.ts +++ b/app/sdk/tsup.config.ts @@ -1,7 +1,7 @@ import { defineConfig } from "tsup"; export default defineConfig({ - entry: ["src/index.ts", "src/types.ts"], + entry: ["src/index.ts", "src/api.ts"], format: ["cjs", "esm"], // Build for commonJS and ESmodules dts: true, // Generate declaration file (.d.ts) splitting: false,