diff --git a/js/modules/data.d.ts b/js/modules/data.d.ts index 29e42df98..e9543b99b 100644 --- a/js/modules/data.d.ts +++ b/js/modules/data.d.ts @@ -1,3 +1,389 @@ +import { ConversationType } from '../../ts/state/ducks/conversations'; +import { Mesasge } from '../../ts/types/Message'; + +type IdentityKey = { + id: string; + publicKey: ArrayBuffer; + firstUse: boolean; + verified: number; + nonblockingApproval: boolean; +} | null; + +type PreKey = { + id: string; + publicKey: string; + privateKey: string; + recipient: string; +} | null; + +type PairingAuthorisation = { + primaryDevicePubKey: string; + secondaryDevicePubKey: string; + requestSignature: string; + grantSignature: string | null; +} | null; + +type PairingAuthorisationInit = { + requestSignature: string; + grantSignature: string; +}; + +type GuardNode = { + ed25519PubKey: string; +}; + +type SwarmNode = { + address: string; + ip: string; + port: string; + pubkey_ed25519: string; + pubkey_x25519: string; +}; + +type StorageItem = { + id: string; + value: any; +}; + +type SessionDataInfo = { + id: string; + number: string; + deviceId: number; + record: string; +}; + +type ServerToken = { + serverUrl: string; + token: string; +}; + +// Basic export function searchMessages(query: string): Promise>; export function searchConversations(query: string): Promise>; -export function getPrimaryDeviceFor(pubKey: string): Promise; +export function shutdown(): Promise; +export function close(): Promise; +export function removeDB(): Promise; +export function removeIndexedDBFiles(): Promise; +export function getPasswordHash(): Promise; + +// Identity Keys +export function createOrUpdateIdentityKey(data: any): Promise; +export function getIdentityKeyById(id: string): Promise; +export function bulkAddIdentityKeys(array: Array): Promise; +export function removeIdentityKeyById(id: string): Promise; +export function removeAllIdentityKeys(): Promise; + +// Pre Keys +export function createOrUpdatePreKey(data: PreKey): Promise; +export function getPreKeyById(id: string): Promise; +export function getPreKeyByRecipient(recipient: string): Promise; +export function bulkAddPreKeys(data: Array): Promise; +export function removePreKeyById(id: string): Promise; +export function getAllPreKeys(): Promise>; + +// Signed Pre Keys +export function createOrUpdateSignedPreKey(data: PreKey): Promise; +export function getSignedPreKeyById(id: string): Promise; +export function getAllSignedPreKeys(recipient: string): Promise; +export function bulkAddSignedPreKeys(array: Array): Promise; +export function removeSignedPreKeyById(id: string): Promise; +export function removeAllSignedPreKeys(): Promise; + +// Contact Pre Key +export function createOrUpdateContactPreKey(data: PreKey): Promise; +export function getContactPreKeyById(id: string): Promise; +export function getContactPreKeyByIdentityKey(key: string): Promise; +export function getContactPreKeys( + keyId: string, + identityKeyString: string +): Promise>; +export function getAllContactPreKeys(): Promise>; +export function bulkAddContactPreKeys(array: Array): Promise; +export function removeContactPreKeyByIdentityKey(id: string): Promise; +export function removeAllContactPreKeys(): Promise; + +// Contact Signed Pre Key +export function createOrUpdateContactSignedPreKey(data: PreKey): Promise; +export function getContactSignedPreKeyByIdid(string): Promise; +export function getContactSignedPreKeyByIdentityKey( + key: string +): Promise; +export function getContactSignedPreKeys( + keyId: string, + identityKeyString: string +): Promise>; +export function bulkAddContactSignedPreKeys( + array: Array +): Promise; +export function removeContactSignedPreKeyByIdentityKey( + id: string +): Promise; +export function removeAllContactSignedPreKeys(): Promise; + +// Authorisations & Linking +export function createOrUpdatePairingAuthorisation( + data: PairingAuthorisationInit +): Promise; +export function removePairingAuthorisationForSecondaryPubKey( + pubKey: string +): Promise; +export function getGrantAuthorisationsForPrimaryPubKey( + pubKey: string +): Promise>; +export function getGrantAuthorisationForSecondaryPubKey( + pubKey: string +): Promise; +export function getAuthorisationForSecondaryPubKey( + pubKey: string +): PairingAuthorisation; +export function getSecondaryDevicesFor( + primaryDevicePubKey: string +): Array; +export function getPrimaryDeviceFor( + secondaryDevicePubKey: string +): string | null; +export function getPairedDevicesFor(pubKey: string): Array; + +// Guard Nodes +export function getGuardNodes(): Promise; +export function updateGuardNodes(nodes: Array): Promise; + +// Storage Items +export function createOrUpdateItem(data: StorageItem): Promise; +export function getItemById(id: string): Promise; +export function getAlItems(): Promise>; +export function bulkAddItems(array: Array): Promise; +export function removeItemById(id: string): Promise; +export function removeAllItems(): Promise; + +// Sessions +export function createOrUpdateSession(data: SessionDataInfo): Promise; +export function getAllSessions(): Promise>; +export function getSessionById(id: string): Promise; +export function getSessionsByNumber(number: string): Promise; +export function bulkAddSessions(array: Array): Promise; +export function removeSessionById(id: string): Promise; +export function removeSessionsByNumber(number: string): Promise; +export function removeAllSessions(): Promise; + +// Conversations +export function getConversationCount(): Promise; +export function saveConversation(data: ConversationType): Promise; +export function saveConversations(data: Array): Promise; +export function updateConversation(data: ConversationType): Promise; +export function removeConversation(id: string): Promise; + +export function getAllConversations({ + ConversationCollection, +}: { + ConversationCollection: any; +}): Promise>; + +export function getAllConversationIds(): Promise>; +export function getAllPrivateConversations(): Promise>; +export function getAllPublicConversations(): Promise>; +export function getPublicConversationsByServer( + server: string, + { ConversationCollection }: { ConversationCollection: any } +): Promise; +export function getPubkeysInPublicConversation( + id: string +): Promise>; +export function savePublicServerToken(data: ServerToken): Promise; +export function getPublicServerTokenByServerUrl( + serverUrl: string +): Promise; +export function getAllGroupsInvolvingId( + id: string, + { ConversationCollection }: { ConversationCollection: any } +): Promise>; + +// Returns conversation row +// TODO: Make strict return types for search +export function searchConversations(query: string): Promise; +export function searchMessages(query: string): Promise; +export function searchMessagesInConversation( + query: string, + conversationId: string, + { limit }?: { limit: any } +): Promise; +export function getMessageCount(): Promise; +export function saveMessage( + data: Mesasge, + { forceSave, Message }?: { forceSave: any; Message: any } +): Promise; +export function cleanSeenMessages(): Promise; +export function cleanLastHashes(): Promise; +export function saveSeenMessageHash(data: { + expiresAt: number; + hash: string; +}): Promise; + +// TODO: Strictly type the following +export function updateLastHash(data: any): Promise; +export function saveSeenMessageHashes(data: any): Promise; +export function saveLegacyMessage(data: any): Promise; +export function saveMessages( + arrayOfMessages: any, + { forceSave }?: any +): Promise; +export function removeMessage(id: string, { Message }?: any): Promise; +export function getUnreadByConversation( + conversationId: string, + { MessageCollection }?: any +): Promise; +export function removeAllMessagesInConversation( + conversationId: string, + { MessageCollection }?: any +): Promise; + +export function getMessageBySender( + { + source, + sourceDevice, + sent_at, + }: { source: any; sourceDevice: any; sent_at: any }, + { Message }: { Message: any } +): Promise; +export function getMessageIdsFromServerIds( + serverIds: any, + conversationId: any +): Promise; +export function getMessageById( + id: string, + { Message }: { Message: any } +): Promise; +export function getAllMessages({ + MessageCollection, +}: { + MessageCollection: any; +}): Promise; +export function getAllUnsentMessages({ + MessageCollection, +}: { + MessageCollection: any; +}): Promise; +export function getAllMessageIds(): Promise; +export function getMessagesBySentAt( + sentAt: any, + { MessageCollection }: { MessageCollection: any } +): Promise; +export function getExpiredMessages({ + MessageCollection, +}: { + MessageCollection: any; +}): Promise; +export function getOutgoingWithoutExpiresAt({ + MessageCollection, +}: any): Promise; +export function getNextExpiringMessage({ + MessageCollection, +}: { + MessageCollection: any; +}): Promise; +export function getNextExpiringMessage({ + MessageCollection, +}: { + MessageCollection: any; +}): Promise; +export function getMessagesByConversation( + conversationId: any, + { + limit, + receivedAt, + MessageCollection, + type, + }: { + limit?: number; + receivedAt?: number; + MessageCollection: any; + type?: string; + } +): Promise; +export function getSeenMessagesByHashList(hashes: any): Promise; +export function getLastHashBySnode(convoId: any, snode: any): Promise; + +// Unprocessed +export function getUnprocessedCount(): Promise; +export function getAllUnprocessed(): Promise; +export function getUnprocessedById(id: any): Promise; +export function saveUnprocessed( + data: any, + { + forceSave, + }?: { + forceSave: any; + } +): Promise; +export function saveUnprocesseds( + arrayOfUnprocessed: any, + { + forceSave, + }?: { + forceSave: any; + } +): Promise; +export function updateUnprocessedAttempts( + id: any, + attempts: any +): Promise; +export function updateUnprocessedWithData(id: any, data: any): Promise; +export function removeUnprocessed(id: any): Promise; +export function removeAllUnprocessed(): Promise; + +// Attachment Downloads +export function getNextAttachmentDownloadJobs(limit: any): Promise; +export function saveAttachmentDownloadJob(job: any): Promise; +export function setAttachmentDownloadJobPending( + id: any, + pending: any +): Promise; +export function resetAttachmentDownloadPending(): Promise; +export function removeAttachmentDownloadJob(id: any): Promise; +export function removeAllAttachmentDownloadJobs(): Promise; + +// Other +export function removeAll(): Promise; +export function removeAllConfiguration(): Promise; +export function removeAllConversations(): Promise; +export function removeAllPrivateConversations(): Promise; +export function removeOtherData(): Promise; +export function cleanupOrphanedAttachments(): Promise; + +// Getters +export function getMessagesNeedingUpgrade( + limit: any, + { + maxVersion, + }: { + maxVersion?: number; + } +): Promise; +export function getLegacyMessagesNeedingUpgrade( + limit: any, + { + maxVersion, + }: { + maxVersion?: number; + } +): Promise; +export function getMessagesWithVisualMediaAttachments( + conversationId: any, + { + limit, + }: { + limit: any; + } +): Promise; +export function getMessagesWithFileAttachments( + conversationId: any, + { + limit, + }: { + limit: any; + } +): Promise; + +// Sender Keys +export function getSenderKeys(groupId: any, senderIdentity: any): Promise; +export function createOrUpdateSenderKeys(data: any): Promise; diff --git a/ts/window.ts b/ts/window.ts new file mode 100644 index 000000000..2490690a4 --- /dev/null +++ b/ts/window.ts @@ -0,0 +1,77 @@ +declare global { + interface Window { + seedNodeList: any; + + WebAPI: any; + LokiSnodeAPI: any; + SenderKeyAPI: any; + LokiMessageAPI: any; + StubMessageAPI: any; + StubAppDotNetApi: any; + LokiPublicChatAPI: any; + LokiAppDotNetServerAPI: any; + LokiFileServerAPI: any; + LokiRssAPI: any; + } +} + +// window.WebAPI = initializeWebAPI(); +// const LokiSnodeAPI = require('./js/modules/loki_snode_api'); +// window.SenderKeyAPI = require('./js/modules/loki_sender_key_api'); +// window.lokiSnodeAPI +// window.LokiMessageAPI = require('./js/modules/loki_message_api'); +// window.StubMessageAPI = require('./integration_test/stubs/stub_message_api'); +// window.StubAppDotNetApi = require('./integration_test/stubs/stub_app_dot_net_api'); +// window.LokiPublicChatAPI = require('./js/modules/loki_public_chat_api'); +// window.LokiAppDotNetServerAPI = require('./js/modules/loki_app_dot_net_api'); +// window.LokiFileServerAPI = require('./js/modules/loki_file_server_api'); +// window.LokiRssAPI = require('./js/modules/loki_rss_api'); + +export const exporttts = { + // APIs + WebAPI: window.WebAPI, + + // Utilities + Events: () => window.Events, + Signal: () => window.Signal, + Whisper: () => window.Whisper, + ConversationController: () => window.ConversationController, + passwordUtil: () => window.passwordUtil, + + // Values + CONSTANTS: () => window.CONSTANTS, + versionInfo: () => window.versionInfo, + mnemonic: () => window.mnemonic, + lokiFeatureFlags: () => window.lokiFeatureFlags, + + // Getters + getAccountManager: () => window.getAccountManager, + getConversations: () => window.getConversations, + getFriendsFromContacts: () => window.getFriendsFromContacts, + getSettingValue: () => window.getSettingValue, + + // Setters + setPassword: () => window.setPassword, + setSettingValue: () => window.setSettingValue, + + // UI Events + pushToast: () => window.pushToast, + confirmationDialog: () => window.confirmationDialog, + + showQRDialog: () => window.showQRDialog, + showSeedDialog: () => window.showSeedDialog, + showPasswordDialog: () => window.showPasswordDialog, + showEditProfileDialog: () => window.showEditProfileDialog, + + toggleTheme: () => window.toggleTheme, + toggleMenuBar: () => window.toggleMenuBar, + toggleSpellCheck: () => window.toggleSpellCheck, + toggleLinkPreview: () => window.toggleLinkPreview, + toggleMediaPermissions: () => window.toggleMediaPermissions, + + // Actions + clearLocalData: () => window.clearLocalData, + deleteAccount: () => window.deleteAccount, + resetDatabase: () => window.resetDatabase, + attemptConnection: () => window.attemptConnection, +};