import { type AuthVersion, type ClassMethods } from "./types"; import Crypto from "./crypto"; import FS from "./fs"; import appendStream from "./streams/append"; import { streamDecodeBase64, streamEncodeBase64 } from "./streams/base64"; import cryptoUtils from "./crypto/utils"; import Cloud from "./cloud"; import Chats from "./chats"; import Notes from "./notes"; import Contacts from "./contacts"; import User from "./user"; import Socket from "./socket"; import type Encrypt from "./crypto/encrypt"; import type Decrypt from "./crypto/decrypt"; import type APIV3FileUploadChunkBuffer from "./api/v3/file/upload/chunk/buffer"; import type APIV3FileDownloadChunkBuffer from "./api/v3/file/download/chunk/buffer"; import TypedEventEmitter, { type Events } from "./events"; import { type AxiosInstance } from "axios"; import Lock from "./lock"; export type SDKWorker = { crypto: { encrypt: ClassMethods; decrypt: ClassMethods; utils: typeof cryptoUtils; }; api: { v3: { file: { upload: { chunk: { buffer: ClassMethods; }; }; download: { chunk: { buffer: ClassMethods; }; }; }; }; }; }; export type FilenSDKConfig = { email?: string; password?: string; twoFactorCode?: string; masterKeys?: string[]; apiKey?: string; publicKey?: string; privateKey?: string; authVersion?: AuthVersion; baseFolderUUID?: string; userId?: number; metadataCache?: boolean; tmpPath?: string; connectToSocket?: boolean; }; /** * FilenSDK * @date 2/1/2024 - 2:45:02 AM * * @export * @class FilenSDK * @typedef {FilenSDK} */ export declare class FilenSDK { config: FilenSDKConfig; private _api; private _crypto; private _fs; private _cloud; private _notes; private _chats; private _contacts; private _user; socket: Socket; workers: SDKWorker[] | null; private currentWorkerWorkIndex; readonly events: TypedEventEmitter; readonly axiosInstance: AxiosInstance; hmacKey: Buffer | null; readonly _locks: { driveWrite: Lock; notesWrite: Lock; chatsWrite: Lock; intensive: Lock; auth: Lock; }; /** * Creates an instance of FilenSDK. * * @constructor * @public * @param {?FilenSDKConfig} [params] * @param {?SDKWorker[]} [workers] * @param {?AxiosInstance} [axiosInstance] */ constructor(params?: FilenSDKConfig, workers?: SDKWorker[], axiosInstance?: AxiosInstance); /** * Initialize the SDK again (after logging in for example). * @date 2/1/2024 - 3:23:58 PM * * @public * @param {FilenSDKConfig} params */ init(params?: FilenSDKConfig): void; /** * Update the SDK Worker pool. * * @public * @param {SDKWorker[]} sdkWorkers */ setSDKWorkers(sdkWorkers: SDKWorker[]): void; getBaseWorker(): SDKWorker; /** * Get a worker from the SDK Worker pool if set. Greatly improves performance. * * @public * @returns {SDKWorker} */ getWorker(): SDKWorker; /** * Check if the SDK user is authenticated. * @date 1/31/2024 - 4:08:17 PM * * @private * @returns {boolean} */ private isLoggedIn; generateHMACKey(): Promise; /** * Update keypair. * @date 2/20/2024 - 7:47:41 AM * * @private * @async * @param {{apiKey: string, publicKey: string, privateKey: string, masterKeys: string[]}} param0 * @param {string} param0.apiKey * @param {string} param0.publicKey * @param {string} param0.privateKey * @param {{}} param0.masterKeys * @returns {Promise} */ private _updateKeyPair; /** * Set keypair. * @date 2/20/2024 - 7:48:10 AM * * @private * @async * @param {{apiKey: string, publicKey: string, privateKey: string, masterKeys: string[]}} param0 * @param {string} param0.apiKey * @param {string} param0.publicKey * @param {string} param0.privateKey * @param {{}} param0.masterKeys * @returns {Promise} */ private _setKeyPair; private __updateKeyPair; private _updateKeys; /** * Authenticate. * @date 2/20/2024 - 7:24:10 AM * * @public * @async * @param {{email?: string, password?: string, twoFactorCode?: string}} param0 * @param {string} param0.email * @param {string} param0.password * @param {string} param0.twoFactorCode * @returns {Promise} */ login({ email, password, twoFactorCode }: { email?: string; password?: string; twoFactorCode?: string; }): Promise; register({ email, password, refId, affId }: { email: string; password: string; refId?: string; affId?: string; }): Promise; /** * Logout. * @date 2/9/2024 - 5:48:28 AM * * @public */ logout(): void; api(version: number): { health: () => Promise<"OK">; dir: () => { content: (params_0: { uuid: string | "recents"; dirsOnly?: boolean; }) => Promise; download: (params_0: { uuid: string; type?: import("./api/v3/dir/download").DirDownloadType; linkUUID?: string; linkHasPassword?: boolean; linkPassword?: string; linkSalt?: string; skipCache?: boolean; }) => Promise; shared: (params_0: { uuid: string; }) => Promise; linked: (params_0: { uuid: string; }) => Promise; link: () => { add: (params_0: { uuid: string; parent: string; linkUUID: string; type: string; metadata: string; key: string; expiration: string; }) => Promise; status: (params_0: { uuid: string; }) => Promise; remove: (params_0: { uuid: string; }) => Promise; edit: (params_0: { uuid: string; expiration: import("./types").PublicLinkExpiration; password: string; downloadBtn: boolean; passwordHashed: string; salt: string; }) => Promise; info: (params_0: { uuid: string; }) => Promise; content: (params_0: { uuid: string; password: string; parent: string; }) => Promise; }; exists: (params_0: { nameHashed: string; parent: string; }) => Promise; create: (params_0: { uuid?: string; metadataEncrypted: string; parent: string; nameHashed: string; }) => Promise; present: (params_0: { uuid: string; }) => Promise; trash: (params_0: { uuid: string; }) => Promise; move: (params_0: { uuid: string; to: string; }) => Promise; rename: (params_0: { uuid: string; metadataEncrypted: string; nameHashed: string; }) => Promise; metadata: (params_0: { uuid: string; metadataEncrypted: string; nameHashed: string; }) => Promise; size: (params_0: { uuid: string; sharerId?: number; receiverId?: number; trash?: boolean; }) => Promise; sizeLink: (params_0: { uuid: string; linkUUID: string; }) => Promise; delete: () => { permanent: (params_0: { uuid: string; }) => Promise; }; restore: (params_0: { uuid: string; }) => Promise; color: (params_0: { uuid: string; color: import("./api/v3/dir/color").DirColors; }) => Promise; tree: (params_0: { uuid: string; deviceId: string; skipCache?: boolean; includeRaw?: boolean; }) => Promise; get: (params_0: { uuid: string; }) => Promise; }; auth: () => { info: (params_0: { email: string; }) => Promise; }; login: (params_0: { email: string; password: string; twoFactorCode?: string; authVersion: AuthVersion; }) => Promise; register: (params_0: { email: string; password: string; salt: string; authVersion: AuthVersion; refId?: string; affId?: string; }) => Promise; confirmationSend: (params_0: { email: string; }) => Promise; user: () => { info: (params_0: { apiKey?: string; }) => Promise; baseFolder: (params_0: { apiKey?: string; }) => Promise; publicKey: (params_0: { email: string; }) => Promise; settings: () => Promise; account: () => Promise; gdpr: () => Promise; avatar: (params_0: { base64: string; hash: string; }) => Promise; settingsEmail: () => { change: (params_0: { email: string; password: string; authVersion: AuthVersion; }) => Promise; }; personal: () => { change: (params_0: { city: string; companyName: string; country: string; firstName: string; lastName: string; postalCode: string; street: string; streetNumber: string; vatId: string; }) => Promise; }; delete: (params_0: { twoFactorCode?: string; }) => Promise; deleteVersions: () => Promise; deleteAll: () => Promise; settingsPassword: () => { change: (params_0: { password: string; currentPassword: string; authVersion: AuthVersion; salt: string; masterKeys: string; }) => Promise; }; twoFactorAuthentication: () => { enable: (params_0: { code: string; }) => Promise; disable: (params_0: { code: string; }) => Promise; }; events: (params_0: { lastTimestamp: number; filter: string; }) => Promise; event: (params_0: { uuid: string; }) => Promise; sub: () => { cancel: (params_0: { uuid: string; }) => Promise; create: (params_0: { planId: number; method: import("./api/v3/user/sub/create").PaymentMethods; }) => Promise; }; invoice: (params_0: { uuid: string; }) => Promise; affiliate: () => { payout: (params_0: { address: string; method: string; }) => Promise; }; versioning: (params_0: { enable: boolean; }) => Promise; loginAlerts: (params_0: { enable: boolean; }) => Promise; nickname: (params_0: { nickname: string; }) => Promise; appearOffline: (params_0: { appearOffline: boolean; }) => Promise; profile: (params_0: { id: number; }) => Promise; lastActive: () => { desktop: (params_0: { timestamp: number; }) => Promise; }; keyPair: () => { update: (params_0: { publicKey: string; encryptedPrivateKey: string; apiKey?: string; }) => Promise; set: (params_0: { publicKey: string; encryptedPrivateKey: string; apiKey?: string; }) => Promise; info: (params_0: { apiKey?: string; }) => Promise; }; masterKeys: (params_0: { encryptedMasterKeys: string; apiKey?: string; }) => Promise; setDEK: (params_0: { encryptedDEK: string; apiKey?: string; }) => Promise; getDEK: (params?: { apiKey?: string; } | undefined) => Promise; password: () => { forgot: (params_0: { email: string; }) => Promise; forgotReset: (params_0: { token: string; password: string; authVersion: number; salt: string; hasRecoveryKeys: boolean; newMasterKeys: string; }) => Promise; }; didExportMasterKeys: () => Promise; lock: (params_0: { uuid: string; resource: string; type: "acquire" | "refresh" | "status" | "release"; }) => Promise; }; shared: () => { in: (params?: { uuid?: string; } | undefined) => Promise; out: (params?: { uuid?: string; receiverId?: number; } | undefined) => Promise; }; upload: () => { done: (params_0: { uuid: string; name: string; nameHashed: string; size: string; chunks: number; mime: string; rm: string; metadata: string; version: import("./types").FileEncryptionVersion; uploadKey: string; }) => Promise; empty: (params_0: { uuid: string; name: string; nameHashed: string; size: string; parent: string; mime: string; metadata: string; version: import("./types").FileEncryptionVersion; }) => Promise; }; item: () => { share: (params_0: { uuid: string; parent: string; email: string; type: "file" | "folder"; metadata: string; }) => Promise; shared: (params_0: { uuid: string; }) => Promise; linked: (params_0: { uuid: string; }) => Promise; linkedRename: (params_0: { uuid: string; linkUUID: string; metadata: string; }) => Promise; sharedRename: (params_0: { uuid: string; receiverId: number; metadata: string; }) => Promise; favorite: (params_0: { uuid: string; type: "file" | "folder"; favorite: boolean; }) => Promise; sharedOut: () => { remove: (params_0: { uuid: string; receiverId: number; }) => Promise; }; sharedIn: () => { remove: (params_0: { uuid: string; }) => Promise; }; }; file: () => { exists: (params_0: { nameHashed: string; parent: string; }) => Promise; trash: (params_0: { uuid: string; }) => Promise; move: (params_0: { uuid: string; to: string; }) => Promise; rename: (params_0: { uuid: string; metadataEncrypted: string; nameEncrypted: string; nameHashed: string; }) => Promise; metadata: (params_0: { uuid: string; metadataEncrypted: string; nameEncrypted: string; nameHashed: string; }) => Promise; delete: () => { permanent: (params_0: { uuid: string; }) => Promise; }; restore: (params_0: { uuid: string; }) => Promise; version: () => { restore: (params_0: { uuid: string; currentUUID: string; }) => Promise; }; link: () => { status: (params_0: { uuid: string; }) => Promise; edit: (params_0: { uuid: string; fileUUID: string; expiration: import("./types").PublicLinkExpiration; password: string; passwordHashed: string; downloadBtn: boolean; type: "enable" | "disable"; salt: string; }) => Promise; info: (params_0: { uuid: string; password: string; }) => Promise; password: (params_0: { uuid: string; }) => Promise; }; versions: (params_0: { uuid: string; }) => Promise; download: () => { chunk: () => { buffer: (params_0: { uuid: string; bucket: string; region: string; chunk: number; timeout?: number; abortSignal?: AbortSignal; onProgress?: import("./types").ProgressCallback; onProgressId?: string; }) => Promise; stream: (params_0: { uuid: string; bucket: string; region: string; chunk: number; timeout?: number; abortSignal?: AbortSignal; onProgress?: import("./types").ProgressCallback; onProgressId?: string; }) => Promise | import("fs").ReadStream>; local: (params_0: { uuid: string; bucket: string; region: string; chunk: number; timeout?: number; abortSignal?: AbortSignal; to: string; onProgress?: import("./types").ProgressCallback; onProgressId?: string; }) => Promise; }; }; upload: () => { chunk: () => { buffer: (params_0: { uuid: string; index: number; parent: string; uploadKey: string; abortSignal?: AbortSignal; maxRetries?: number; retryTimeout?: number; timeout?: number; buffer: Buffer; onProgress?: import("./types").ProgressCallback; onProgressId?: string; }) => Promise; }; }; get: (params_0: { uuid: string; }) => Promise; present: (params_0: { uuid: string; }) => Promise; }; trash: () => { empty: () => Promise; }; chat: () => { conversations: () => Promise; messages: (params_0: { conversation: string; timestamp: number; }) => Promise; conversationsName: () => { edit: (params_0: { uuid: string; name: string; }) => Promise; }; send: (params_0: { conversation: string; uuid: string; message: string; replyTo: string; }) => Promise; edit: (params_0: { conversation: string; uuid: string; message: string; }) => Promise; conversationsCreate: (params_0: { uuid: string; metadata: string; ownerMetadata: string; }) => Promise; conversationsParticipants: () => { add: (params_0: { uuid: string; contactUUID: string; metadata: string; }) => Promise; remove: (params_0: { uuid: string; userId: number; }) => Promise; }; typing: (params_0: { conversation: string; type: import("./api/v3/chat/typing").ChatTypingType; }) => Promise; conversationsRead: (params_0: { uuid: string; }) => Promise; conversationsUnread: (params_0: { uuid: string; }) => Promise; unread: () => Promise; conversationsOnline: (params_0: { conversation: string; }) => Promise; delete: (params_0: { uuid: string; }) => Promise; message: () => { embed: () => { disable: (params_0: { uuid: string; }) => Promise; }; }; conversationsLeave: (params_0: { uuid: string; }) => Promise; conversationsDelete: (params_0: { uuid: string; }) => Promise; lastFocusUpdate: (params_0: { conversations: import("./api/v3/chat/lastFocusUpdate").ChatLastFocusValues[]; }) => Promise; lastFocus: () => Promise; mute: (params_0: { uuid: string; mute: boolean; }) => Promise; }; notes: () => { all: () => Promise; content: (params_0: { uuid: string; }) => Promise; create: (params_0: { uuid: string; title: string; metadata: string; }) => Promise; contentEdit: (params_0: { uuid: string; preview: string; content: string; type: import("./api/v3/notes").NoteType; }) => Promise; titleEdit: (params_0: { uuid: string; title: string; }) => Promise; delete: (params_0: { uuid: string; }) => Promise; trash: (params_0: { uuid: string; }) => Promise; archive: (params_0: { uuid: string; }) => Promise; restore: (params_0: { uuid: string; }) => Promise; typeChange: (params_0: { uuid: string; type: import("./api/v3/notes").NoteType; preview: string; content: string; }) => Promise; pinned: (params_0: { uuid: string; pinned: boolean; }) => Promise; favorite: (params_0: { uuid: string; favorite: boolean; }) => Promise; history: (params_0: { uuid: string; }) => Promise; historyRestore: (params_0: { uuid: string; id: number; }) => Promise; participantsRemove: (params_0: { uuid: string; userId: number; }) => Promise; participantsAdd: (params_0: { uuid: string; contactUUID: string; metadata: string; permissionsWrite: boolean; }) => Promise; participantsPermissions: (params_0: { uuid: string; userId: number; permissionsWrite: boolean; }) => Promise; tags: () => Promise; tagsCreate: (params_0: { name: string; }) => Promise; tagsRename: (params_0: { uuid: string; name: string; }) => Promise; tagsDelete: (params_0: { uuid: string; }) => Promise; tagsFavorite: (params_0: { uuid: string; favorite: boolean; }) => Promise; tag: (params_0: { uuid: string; tag: string; }) => Promise; untag: (params_0: { uuid: string; tag: string; }) => Promise; }; contacts: () => { all: () => Promise; requestsIn: () => Promise; requestsInCount: () => Promise; requestsOut: () => Promise; requestsOutDelete: (params_0: { uuid: string; }) => Promise; requestsSend: (params_0: { email: string; }) => Promise; requestsAccept: (params_0: { uuid: string; }) => Promise; requestsDeny: (params_0: { uuid: string; }) => Promise; delete: (params_0: { uuid: string; }) => Promise; blocked: () => Promise; blockedAdd: (params_0: { email: string; }) => Promise; blockedDelete: (params_0: { uuid: string; }) => Promise; }; search: () => { add: (params_0: { items: import("./api/v3/search/add").SearchAddItem[]; }) => Promise; find: (params_0: { hashes: string[]; }) => Promise; }; }; /** * Returns an instance of Crypto. * @date 1/31/2024 - 4:29:49 PM * * @public * @returns {Crypto} */ crypto(): Crypto; /** * Returns an instance of FS. * @date 2/17/2024 - 1:52:12 AM * * @public * @returns {FS} */ fs(): FS; /** * Returns an instance of Cloud. * @date 2/17/2024 - 1:52:05 AM * * @public * @returns {Cloud} */ cloud(): Cloud; /** * Returns an instance of Notes. * @date 2/19/2024 - 6:32:35 AM * * @public * @returns {Notes} */ notes(): Notes; /** * Returns an instance of Chats. * @date 2/19/2024 - 6:32:35 AM * * @public * @returns {Chats} */ chats(): Chats; /** * Returns an instance of Contacts. * @date 2/20/2024 - 6:27:05 AM * * @public * @returns {Contacts} */ contacts(): Contacts; /** * Return an instance of User. * @date 2/20/2024 - 6:27:17 AM * * @public * @returns {User} */ user(): User; /** * Clear the temporary directory. Only available in a Node.JS environment. * @date 2/17/2024 - 1:51:39 AM * * @public * @async * @returns {Promise} */ clearTemporaryDirectory(): Promise; readonly utils: { crypto: { generateRandomString: typeof import("./crypto/utils").generateRandomString; deriveKeyFromPassword: typeof import("./crypto/utils").deriveKeyFromPassword; hashFn: typeof import("./crypto/utils").hashFn; generatePasswordAndMasterKeyBasedOnAuthVersion: typeof import("./crypto/utils").generatePasswordAndMasterKeyBasedOnAuthVersion; hashPassword: typeof import("./crypto/utils").hashPassword; derKeyToPem: typeof import("./crypto/utils").derKeyToPem; importPublicKey: typeof import("./crypto/utils").importPublicKey; importPrivateKey: typeof import("./crypto/utils").importPrivateKey; bufferToHash: typeof import("./crypto/utils").bufferToHash; generateKeyPair: typeof import("./crypto/utils").generateKeyPair; importRawKey: typeof import("./crypto/utils").importRawKey; importPBKDF2Key: typeof import("./crypto/utils").importPBKDF2Key; generateRandomBytes: typeof import("./crypto/utils").generateRandomBytes; generateRandomHexString: typeof import("./crypto/utils").generateRandomHexString; hashFileName: typeof import("./crypto/utils").hashFileName; hashSearchIndex: typeof import("./crypto/utils").hashSearchIndex; generateSearchIndexHashes: typeof import("./crypto/utils").generateSearchIndexHashes; generatePrivateKeyHMAC: typeof import("./crypto/utils").generatePrivateKeyHMAC; generateEncryptionKey: typeof import("./crypto/utils").generateEncryptionKey; argon2id: typeof import("./crypto/utils").argon2id; hashPublicLinkPassword: typeof import("./crypto/utils").hashPublicLinkPassword; }; streams: { append: typeof appendStream; decodeBase64: typeof streamDecodeBase64; encodeBase64: typeof streamEncodeBase64; }; sleep: typeof import("./utils").sleep; convertTimestampToMs: typeof import("./utils").convertTimestampToMs; normalizePath: typeof import("./utils").normalizePath; uuidv4: typeof import("./utils").uuidv4; Uint8ArrayConcat: typeof import("./utils").Uint8ArrayConcat; promiseAllChunked: typeof import("./utils").promiseAllChunked; getRandomArbitrary: typeof import("./utils").getRandomArbitrary; clearTempDirectory: typeof import("./utils").clearTempDirectory; parseURLParams: typeof import("./utils").parseURLParams; getEveryPossibleDirectoryPath: typeof import("./utils").getEveryPossibleDirectoryPath; simpleDate: typeof import("./utils").simpleDate; replacePathStartWithFromAndTo: typeof import("./utils").replacePathStartWithFromAndTo; fastStringHash: typeof import("./utils").fastStringHash; nodeStreamToBuffer: typeof import("./utils").nodeStreamToBuffer; nameSplitter: typeof import("./utils").nameSplitter; isValidHexString: typeof import("./utils").isValidHexString; isValidDirectoryName: typeof import("./utils").isValidDirectoryName; isValidFileName: typeof import("./utils").isValidFileName; progressiveSplit: typeof import("./utils").progressiveSplit; chunkArray: typeof import("./utils").chunkArray; }; } export default FilenSDK; export { CloudItem, CloudItemShared, CloudItemFile, CloudItemDirectory, CloudItemTree } from "./cloud"; export { FSItem, FSItemType, FSStats, StatFS, FSConfig } from "./fs"; export * from "./types"; export * from "./constants"; export * from "./api/errors"; export * from "./cloud/signals"; export { SocketEvent } from "./socket"; export { ChunkedUploadWriter } from "./cloud/streams";