import { AcceptedZipSources, ConstructibleArchives } from './reading/StreamArchive'; import DMArchive from './direct_messages/DMArchive'; import { EventEmitter } from 'events'; import TweetArchive from './tweets/TweetArchive'; import { FavoriteArchive } from './tweets/FavoriteArchive'; import UserData from './user/UserData'; import AdArchive from './user/AdArchive'; import MediaArchive from './MediaArchive'; import { ExtendedInfoContainer, TwitterArchiveLoadOptions, BasicArchiveInfo, ArchiveSyntheticInfo } from './types/Internal'; import { PartialTweetGDPR } from './types/GDPRTweets'; import { PartialFavorite } from './types/GDPRExtended'; import { GDPRMoment } from './types/GDPRMoments'; import { ClassicPayloadDetails } from './types/ClassicPayloadIndex'; import { PartialTweet, TwitterUserDetails } from './types/ClassicTweets'; import { AccountGDPR, ProfileGDPR } from './types/GDPRAccount'; import { DMFile } from './types/GDPRDMs'; import ArchiveManifest from './types/GDPRManifest'; export type ArchiveReadState = "idle" | "reading" | "indexing" | "tweet_read" | "user_read" | "dm_read" | "extended_read" | "ready"; /** Read steps fired in `'read'` event. */ export type ArchiveReadStep = "zipready" | "userinfosready" | "tweetsread" | "indexready" | "willreaddm" | "willreadextended"; export type ArchiveReadPart = "tweet" | "dm" | "follower" | "following" | "mute" | "block" | "favorite" | "list" | "moment" | "ad"; /** * Represents a full Twitter Archive. Support GDPR and classic archive. * * You can check if the archive is a GDPR archive with property `.is_gdpr`. * * Available on both GDPR and old classic archives * ----- * Tweets, that are available in `.tweets`. * Remember that, in searchs in particular, tweets are **NOT** sorted. * * Quick user information, like screen name, bio, location, ID and account * creation date is available through `.user[.summary]`. * * * Available on GDPR archives only * ----- * Favorites, mutes, blocks, followings, followers, that are stored in * `.favorites`, `.mutes`, `.blocks`, `.followings` and `.followers`. * * Direct messages, parsed if archive is a GDPR archive, stored in `.messages`, * are returned and sorted from the most older to the more recent. * * Medias stored in archives are in `.medias`. * * User detailled data (screen name history, email address) is in `.user` property. * * Quick start * ----- * * Initialize a `TwitterArchive` object with a filepath, `Blob`, `ArrayBuffer` or `Uint8Array` objects. * * Then, you could add events in order to know archive read steps. * Finally, wait for ready-ness of the object, and use it ! * * ```ts * import TwitterArchive, { ArchiveReadStep } from 'twitter-archive-reader'; * * // From a local file * const archive = new TwitterArchive('filepath.zip'); * // or file input (browser) * const archive = new TwitterArchive(document.querySelector('input[type="file"]').files[0]); * * // Listen for archive steps to give feedback to user * archive.events.on('read', ({ step }: { step: ArchiveReadStep }) => { * console.log("Archive reading step:", step); * }); * * // Wait for ready-ness * await archive.ready(); * console.log("Archive is ready !"); * ``` */ export declare class TwitterArchive { static readonly settings: { ENABLE_CACHE: boolean; LAZY_JSON_PARSE: boolean; LAZY_JSON_THRESHOLD: number; TRIM_GDPR_RETWEET_ENTITIES: boolean; }; protected _ready: Promise; protected _has_viewer: boolean; protected _manifest: ArchiveManifest | undefined; protected archive: ConstructibleArchives; /** Current archive load state. */ state: ArchiveReadState; /** Where events about archive read are emitted. */ readonly events: EventEmitter<[never]>; protected _tweets: TweetArchive; protected _messages: DMArchive; protected _favorites: FavoriteArchive; protected extended_info_container: ExtendedInfoContainer; protected _user: UserData; protected _ads: AdArchive; protected _medias: MediaArchive; protected _is_gdpr: boolean; protected _created_at: string; /** * Twitter Archive constructor. * * Don't forget to await the archive ready-ness with `.ready()` method ! * * ```ts * // From a local file * const archive = new TwitterArchive('filepath.zip'); * // or file input (browser) * const archive = new TwitterArchive(document.querySelector('input[type="file"]').files[0]); * * await archive.ready(); * ``` * * @param file Archive to load. * * If you want to build an archive instance **without** a file, you can pass `null` here. * You must then load parts of the archive with `.loadArchivePart()` or `.loadClassicArchivePart()` ! * * Valid files are local paths (path to a ZIP file or path to an dezipped folder supported) as `string`, * browser `File` entities (typically extracted from ``), Node.js `Buffer`, `UInt8Array` and `JSZip` objects. * * You can also re-use the loaded ZIP/object used in another `TwitterArchive` instance by passing `otherInstance.raw`. * * @param options.ignore * Specify if you want to ignore a specific part of archive, for performance or memory reasons. * * Available parts are in `ArchiveReadPart` type. * * By default, all parts are imported from archive. * If you want to ignore every part, you can specify `"*"` in the part array. * * **Profile and account data is always parsed.** * * ```ts * type ArchiveReadPart = "tweet" | "dm" | "follower" | "following" | "mute" | "block" | "favorite" | "list" | "moment" | "ad"; * ``` * * To manually load a part after archive has been loaded, use `.initArchivePart()` method. * Please don't initialize a part twice, it could lead to vicious bugs! */ constructor(file: AcceptedZipSources | Promise | null, options?: TwitterArchiveLoadOptions); protected addTweetsToGdprArchive(tweets: PartialTweetGDPR[]): void; protected init(parts_to_read: Set): Promise; protected initGDPR(parts_to_read: Set): Promise; protected initClassic(parts_to_read: Set): Promise; /** * Read one or more archive parts from loaded archive. * * You don't need to call this method if you use the default constructor. */ initArchivePart(...parts: (ArchiveReadPart | "")[]): Promise; /** ----------------- */ /** ARCHIVE ACCESSORS */ /** ----------------- */ /** * `true` if ZIP file is still loaded inside this instance. * Can be freed (to save memory, f.e.) with `.releaseZip()`. */ get is_zip_loaded(): boolean; /** * Archive creation date. * * **Warning**: This is accurate only for classic archives (< 2018, tweet only), * or GDPR archives produced after mid-March 2020 (which also have a `manifest.js` file). * * In other archives, this will be the current date. * * You can check if the generation date is valid with this tiny snippet. * ```ts * const date_is_valid = !archive.is_gdpr || archive.has_manifest; * * if (date_is_valid) { * console.log("Generation date is", archive.generation_date); * } * ``` * */ get generation_date(): Date; /** * Archive quick information. * * - `.info.archive` : `{ created_at: string, tweets: number }` * - `.info.user`: See `TwitterUserDetails` */ get info(): BasicArchiveInfo; /** `true` if archive is a GDPR archive. */ get is_gdpr(): boolean; /** * `true` if the current archive have an Twitter HTML viewer integrated. */ get has_viewer(): boolean; /** * `true` if archive have a manifest file inside. * * This only applies to GDPR archives produced by Twitter after mid-March 2020. */ get has_manifest(): boolean; /** * Manifest file, indicating generation date, all available JS files, and more. * * This property is only available for GDPR archives produced by Twitter after mid-March 2020. */ get manifest(): ArchiveManifest; /** * Raw archive object. Can be used to get specific files. * * Returns twitter_archive. */ get raw(): ConstructibleArchives; /** Resolved when archive read is over. */ ready(): Promise; /** Access to the `DMArchive` object. Will be undefined if `.is_gdpr === false`. */ get messages(): DMArchive; /** Access to the `TweetArchive` object. Contains all the tweets of this archive. */ get tweets(): TweetArchive; /** * Access to the `FavoriteArchive` object. Contains all the favorited tweets of the archive. * * If `.is_gdpr === false`, this container will be empty. */ get favorites(): FavoriteArchive; /** * Access to a set of followers IDs. * * If `.is_gdpr === false`, this container will be empty. */ get followers(): Set; /** * Access to a set of followings user IDs. * * If `.is_gdpr === false`, this container will be empty. */ get followings(): Set; /** * Access to a set of blocked user IDs. * * If `.is_gdpr === false`, this container will be empty. */ get blocks(): Set; /** * Access to a set of muted user IDs. * * If `.is_gdpr === false`, this container will be empty. */ get mutes(): Set; /** * Access to archive Twitter moments. * * If `.is_gdpr === false`, this array will be empty. */ get moments(): GDPRMoment[]; /** * Access to your subscribed and created lists, and the lists you were added into. * * If `.is_gdpr === false`, this container will be contain empty arrays. */ get lists(): { created: string[]; member_of: string[]; subscribed: string[]; }; /** * All the archive owner's user data on Twitter. * * Contains data sended to Twitter about archive owner, like: * - **Screen name (@)** * - **Tweet name (TN)** * - **Account creation date** * - **Biography** * - **Phone number** * - **Personnalization** (inferred informations about user interests) * - **Email addresses** * - *...* * * If `.is_gdpr === false`, this is will contain only basic data (related to `.user.summary`). */ get user(): UserData; /** * Informations about which ads archive owner seen or interacted with. */ get ads(): AdArchive; /** * Access to medias stored in this archive, like dm images, tweet medias and profile pictures. */ get medias(): MediaArchive; /** -------------------- */ /** SIDELOADING MANUALLY */ /** -------------------- */ /** * Load a part of a GDPR archive. * * Set current archive as GDPR archive. */ loadArchivePart(parts?: { tweets?: PartialTweetGDPR[]; account?: AccountGDPR; profile?: ProfileGDPR; dms?: DMFile[]; favorites?: PartialFavorite[]; blocks?: string[]; mutes?: string[]; followers?: string[]; followings?: string[]; moments?: GDPRMoment[]; }): Promise; /** * Load a part of a classic archive. * * Set current archive as non-gdpr archive. */ loadClassicArchivePart(parts?: { tweets?: PartialTweet[]; payload?: ClassicPayloadDetails; user?: TwitterUserDetails; }): void; protected initUserCache(): void; /** --------------------------------------- */ /** ARCHIVE FINGERPRINTING AND INFORMATIONS */ /** --------------------------------------- */ /** * Unload ZIP file inside this instance. * Returns `true` if ZIP has been unloaded. * * ZIP can still be loaded in `archive.medias`, you can use its own `.releaseZip()` method. */ releaseZip(): boolean; /** * Résumé of this archive. * * Contains the 'archive index' (without the tweets), * if the archive is GDPR, last tweet date, * tweet count and dm count. */ get synthetic_info(): ArchiveSyntheticInfo; /** * `.synthetic_info`, but without hash. Used to... calculate hash. */ protected get synthetic_info_without_hash(): ArchiveSyntheticInfo; /** * Create a pseudo-unique hash from a archive information (number of tweets, owner, last tweet date...), * in order to have a fingerprint of one archive. */ static hash(from: ArchiveSyntheticInfo | TwitterArchive): string; /** * Pseudo-unique hash from the archive information (number of tweets, owner, last tweet date...), * in order to have a fingerprint of this archive. */ get hash(): string; protected emitAndChangeState(step: string, new_state?: ArchiveReadState): void; }