zaileys 4.7.0 → 4.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/auth/adapters/convex.d.ts +9 -0
- package/dist/auth/adapters/file.d.ts +16 -0
- package/dist/auth/adapters/index.d.ts +6 -0
- package/dist/auth/adapters/memory.d.ts +9 -0
- package/dist/auth/adapters/postgres.d.ts +20 -0
- package/dist/auth/adapters/redis.d.ts +27 -0
- package/dist/auth/adapters/sqlite.d.ts +19 -0
- package/dist/auth/cache.d.ts +11 -0
- package/dist/auth/index.d.ts +3 -0
- package/dist/auth/types.d.ts +21 -0
- package/dist/automation/auto-delete.d.ts +30 -0
- package/dist/automation/broadcast.d.ts +10 -0
- package/dist/automation/errors.d.ts +8 -0
- package/dist/automation/index.d.ts +11 -0
- package/dist/automation/operation-guard.d.ts +20 -0
- package/dist/automation/presence.d.ts +28 -0
- package/dist/automation/queue.d.ts +18 -0
- package/dist/automation/rate-limiter.d.ts +18 -0
- package/dist/automation/schedule.d.ts +45 -0
- package/dist/automation/types.d.ts +31 -0
- package/dist/builder/album.d.ts +4 -0
- package/dist/builder/builder.d.ts +59 -0
- package/dist/builder/content/airich.d.ts +80 -0
- package/dist/builder/content/audio.d.ts +9 -0
- package/dist/builder/content/buttons.d.ts +30 -0
- package/dist/builder/content/carousel.d.ts +19 -0
- package/dist/builder/content/contact.d.ts +13 -0
- package/dist/builder/content/document.d.ts +9 -0
- package/dist/builder/content/event.d.ts +3 -0
- package/dist/builder/content/group-invite.d.ts +3 -0
- package/dist/builder/content/image.d.ts +8 -0
- package/dist/builder/content/list.d.ts +14 -0
- package/dist/builder/content/location.d.ts +11 -0
- package/dist/builder/content/markdown.d.ts +2 -0
- package/dist/builder/content/poll.d.ts +10 -0
- package/dist/builder/content/product.d.ts +3 -0
- package/dist/builder/content/sticker.d.ts +7 -0
- package/dist/builder/content/template.d.ts +3 -0
- package/dist/builder/content/text.d.ts +4 -0
- package/dist/builder/content/video.d.ts +10 -0
- package/dist/builder/edit-builder.d.ts +15 -0
- package/dist/builder/errors.d.ts +8 -0
- package/dist/builder/index.d.ts +6 -0
- package/dist/builder/media-loader.d.ts +11 -0
- package/dist/builder/mutations.d.ts +14 -0
- package/dist/builder/state.d.ts +15 -0
- package/dist/builder/types.d.ts +164 -0
- package/dist/builder/username-resolve.d.ts +8 -0
- package/dist/client/client.d.ts +130 -0
- package/dist/client/event-emitter.d.ts +19 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/types.d.ts +104 -0
- package/dist/command/dispatcher.d.ts +23 -0
- package/dist/command/errors.d.ts +8 -0
- package/dist/command/index.d.ts +7 -0
- package/dist/command/middleware.d.ts +2 -0
- package/dist/command/parser.d.ts +2 -0
- package/dist/command/registry.d.ts +13 -0
- package/dist/command/types.d.ts +30 -0
- package/dist/connection/auth-adapter.d.ts +4 -0
- package/dist/connection/auth-guard.d.ts +37 -0
- package/dist/connection/disconnect-reason.d.ts +6 -0
- package/dist/connection/index.d.ts +7 -0
- package/dist/connection/pairing-flow.d.ts +16 -0
- package/dist/connection/qr-terminal.d.ts +2 -0
- package/dist/connection/reconnect.d.ts +15 -0
- package/dist/connection/state-machine.d.ts +9 -0
- package/dist/connection/status-log.d.ts +25 -0
- package/dist/domain/business.d.ts +19 -0
- package/dist/domain/chat.d.ts +27 -0
- package/dist/domain/community.d.ts +28 -0
- package/dist/domain/contact.d.ts +21 -0
- package/dist/domain/errors.d.ts +8 -0
- package/dist/domain/group.d.ts +35 -0
- package/dist/domain/index.d.ts +11 -0
- package/dist/domain/newsletter.d.ts +35 -0
- package/dist/domain/privacy.d.ts +15 -0
- package/dist/domain/profile.d.ts +14 -0
- package/dist/domain/socket-like.d.ts +117 -0
- package/dist/domain/types.d.ts +24 -0
- package/dist/events/context.d.ts +238 -0
- package/dist/events/decoders/_media-download.d.ts +8 -0
- package/dist/events/decoders/_shared.d.ts +26 -0
- package/dist/events/decoders/calls.d.ts +11 -0
- package/dist/events/decoders/groups.d.ts +36 -0
- package/dist/events/decoders/interactive.d.ts +9 -0
- package/dist/events/decoders/lifecycle.d.ts +69 -0
- package/dist/events/decoders/messages.d.ts +30 -0
- package/dist/events/decoders/mutations.d.ts +24 -0
- package/dist/events/guards.d.ts +9 -0
- package/dist/events/index.d.ts +4 -0
- package/dist/events/pipeline.d.ts +37 -0
- package/dist/events/types.d.ts +187 -0
- package/dist/index.cjs +8 -8
- package/dist/index.d.ts +14 -2264
- package/dist/index.mjs +8 -8
- package/dist/media/ffmpeg/audio.d.ts +12 -0
- package/dist/media/ffmpeg/core.d.ts +67 -0
- package/dist/media/ffmpeg/document.d.ts +10 -0
- package/dist/media/ffmpeg/image.d.ts +7 -0
- package/dist/media/ffmpeg/index.d.ts +7 -0
- package/dist/media/ffmpeg/sticker.d.ts +14 -0
- package/dist/media/ffmpeg/transform.d.ts +2 -0
- package/dist/media/ffmpeg/video.d.ts +6 -0
- package/dist/media/index.d.ts +2 -0
- package/dist/media/media.d.ts +39 -0
- package/dist/plugin/index.d.ts +5 -0
- package/dist/plugin/loader.d.ts +30 -0
- package/dist/plugin/registry.d.ts +24 -0
- package/dist/plugin/types.d.ts +25 -0
- package/dist/store/adapters/convex.d.ts +33 -0
- package/dist/store/adapters/index.d.ts +5 -0
- package/dist/store/adapters/memory.d.ts +31 -0
- package/dist/store/adapters/postgres.d.ts +40 -0
- package/dist/store/adapters/redis.d.ts +49 -0
- package/dist/store/adapters/sqlite.d.ts +36 -0
- package/dist/store/index.d.ts +2 -0
- package/dist/store/types.d.ts +48 -0
- package/dist/types/convex.d.ts +35 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/lid-mapping.d.ts +5 -0
- package/dist/types/optional-clients.d.ts +69 -0
- package/dist/types/store-error.d.ts +8 -0
- package/dist/utils/array.d.ts +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/jid.d.ts +6 -0
- package/dist/utils/logger.d.ts +10 -0
- package/package.json +5 -7
- package/dist/index.d.cts +0 -2264
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type MediaInput } from './core.js';
|
|
2
|
+
export type AudioType = 'opus' | 'mp3';
|
|
3
|
+
export declare class AudioProcessor {
|
|
4
|
+
static toOpus(input: MediaInput): Promise<Buffer>;
|
|
5
|
+
static toMp3(input: MediaInput): Promise<Buffer>;
|
|
6
|
+
static convert(input: MediaInput, type?: AudioType): Promise<Buffer>;
|
|
7
|
+
static waveform(input: MediaInput): Promise<{
|
|
8
|
+
waveform: Uint8Array;
|
|
9
|
+
seconds: number;
|
|
10
|
+
}>;
|
|
11
|
+
private static computeWaveform;
|
|
12
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export declare const FFMPEG_CONSTANTS: {
|
|
2
|
+
readonly OPUS: {
|
|
3
|
+
readonly CODEC: 'libopus';
|
|
4
|
+
readonly CHANNELS: 1;
|
|
5
|
+
readonly FREQUENCY: 48000;
|
|
6
|
+
readonly BITRATE: '48k';
|
|
7
|
+
readonly FORMAT: 'ogg';
|
|
8
|
+
};
|
|
9
|
+
readonly THUMBNAIL: {
|
|
10
|
+
readonly SIZE: 100;
|
|
11
|
+
readonly QUALITY: 50;
|
|
12
|
+
readonly TIMESTAMP: '10%';
|
|
13
|
+
};
|
|
14
|
+
readonly STICKER: {
|
|
15
|
+
readonly SIZE: 512;
|
|
16
|
+
readonly MAX_DURATION: 6;
|
|
17
|
+
readonly FPS: 10;
|
|
18
|
+
readonly DEFAULT_QUALITY: 60;
|
|
19
|
+
readonly COMPRESSION_LEVEL: 6;
|
|
20
|
+
};
|
|
21
|
+
readonly MIME: {
|
|
22
|
+
readonly AUDIO: 'audio/';
|
|
23
|
+
readonly VIDEO: 'video/';
|
|
24
|
+
readonly IMAGE: 'image/';
|
|
25
|
+
readonly GIF: 'image/gif';
|
|
26
|
+
readonly MP4: 'video/mp4';
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export type MediaInput = string | ArrayBuffer | Buffer;
|
|
30
|
+
export type FileExtension = 'wav' | 'ogg' | 'mp4' | 'gif' | 'jpg' | 'webp' | 'tmp' | 'mp3' | 'png';
|
|
31
|
+
export interface FFmpegConfig {
|
|
32
|
+
input: string;
|
|
33
|
+
output: string;
|
|
34
|
+
options: string[];
|
|
35
|
+
onEnd: () => Promise<void>;
|
|
36
|
+
onError: (err: Error) => Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
export declare const initializeFFmpeg: (disable?: boolean) => Promise<void>;
|
|
39
|
+
export declare const generateId: () => string;
|
|
40
|
+
export declare const detectFileType: (buffer: Buffer) => Promise<{
|
|
41
|
+
ext: string;
|
|
42
|
+
mime: string;
|
|
43
|
+
} | undefined>;
|
|
44
|
+
export declare class FileManager {
|
|
45
|
+
private static generateUniqueId;
|
|
46
|
+
static createTempPath(prefix: string, ext: FileExtension): string;
|
|
47
|
+
static cleanup(files: string[]): Promise<void>;
|
|
48
|
+
static safeReadFile(filePath: string): Promise<Buffer>;
|
|
49
|
+
static safeWriteFile(filePath: string, data: Buffer): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
export declare class BufferConverter {
|
|
52
|
+
static toBuffer(input: MediaInput): Promise<Buffer>;
|
|
53
|
+
private static fromString;
|
|
54
|
+
private static fromUrl;
|
|
55
|
+
static getExtension(buffer: Buffer): Promise<FileExtension>;
|
|
56
|
+
}
|
|
57
|
+
export declare class MimeValidator {
|
|
58
|
+
static validate(fileType: {
|
|
59
|
+
mime: string;
|
|
60
|
+
} | undefined, expectedPrefix: string): void;
|
|
61
|
+
static isMedia(mime: string): boolean;
|
|
62
|
+
static isAnimated(mime: string): boolean;
|
|
63
|
+
}
|
|
64
|
+
export declare class FFmpegProcessor {
|
|
65
|
+
static process(config: FFmpegConfig): Promise<void>;
|
|
66
|
+
static getDuration(filePath: string): Promise<number>;
|
|
67
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type MediaInput } from './core.js';
|
|
2
|
+
export declare class DocumentProcessor {
|
|
3
|
+
static create(input: MediaInput): Promise<{
|
|
4
|
+
document: Buffer<ArrayBufferLike>;
|
|
5
|
+
mimetype: string;
|
|
6
|
+
ext: string;
|
|
7
|
+
fileName: string;
|
|
8
|
+
jpegThumbnail: string;
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type MediaInput } from './core.js';
|
|
2
|
+
export declare class ImageProcessor {
|
|
3
|
+
static thumbnail(buffer: Buffer): Promise<string>;
|
|
4
|
+
static resize(buffer: Buffer, width: number, height: number): Promise<Buffer>;
|
|
5
|
+
static toJpeg(input: MediaInput): Promise<Buffer>;
|
|
6
|
+
static resizeForSticker(buffer: Buffer, quality: number, shape?: string): Promise<Buffer>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type MediaInput } from './core.js';
|
|
2
|
+
export type StickerShapeType = 'circle' | 'rounded' | 'oval' | 'default';
|
|
3
|
+
export interface StickerMetadataType {
|
|
4
|
+
packageName?: string;
|
|
5
|
+
authorName?: string;
|
|
6
|
+
quality?: number;
|
|
7
|
+
shape?: StickerShapeType;
|
|
8
|
+
}
|
|
9
|
+
export declare class StickerProcessor {
|
|
10
|
+
static create(input: MediaInput, metadata?: StickerMetadataType): Promise<Buffer>;
|
|
11
|
+
private static createExifMetadata;
|
|
12
|
+
private static processAnimated;
|
|
13
|
+
private static getExtension;
|
|
14
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type AudioType, type MediaInput, type StickerMetadataType } from './ffmpeg/index.js';
|
|
2
|
+
export declare class Media {
|
|
3
|
+
private input;
|
|
4
|
+
constructor(input: MediaInput);
|
|
5
|
+
get audio(): {
|
|
6
|
+
toOpus: () => Promise<Buffer<ArrayBufferLike>>;
|
|
7
|
+
toMp3: () => Promise<Buffer<ArrayBufferLike>>;
|
|
8
|
+
convert: (type?: AudioType) => Promise<Buffer<ArrayBufferLike>>;
|
|
9
|
+
waveform: () => Promise<{
|
|
10
|
+
waveform: Uint8Array;
|
|
11
|
+
seconds: number;
|
|
12
|
+
}>;
|
|
13
|
+
};
|
|
14
|
+
get video(): {
|
|
15
|
+
toMp4: () => Promise<Buffer<ArrayBufferLike>>;
|
|
16
|
+
thumbnail: () => Promise<string>;
|
|
17
|
+
};
|
|
18
|
+
get image(): {
|
|
19
|
+
toJpeg: () => Promise<Buffer<ArrayBufferLike>>;
|
|
20
|
+
thumbnail: () => Promise<string>;
|
|
21
|
+
resize: (width: number, height: number) => Promise<Buffer<ArrayBufferLike>>;
|
|
22
|
+
};
|
|
23
|
+
get sticker(): {
|
|
24
|
+
create: (metadata?: StickerMetadataType) => Promise<Buffer<ArrayBufferLike>>;
|
|
25
|
+
};
|
|
26
|
+
get document(): {
|
|
27
|
+
create: () => Promise<{
|
|
28
|
+
document: Buffer<ArrayBufferLike>;
|
|
29
|
+
mimetype: string;
|
|
30
|
+
ext: string;
|
|
31
|
+
fileName: string;
|
|
32
|
+
jpegThumbnail: string;
|
|
33
|
+
}>;
|
|
34
|
+
};
|
|
35
|
+
get thumbnail(): {
|
|
36
|
+
get: () => Promise<string>;
|
|
37
|
+
};
|
|
38
|
+
toBuffer(): Promise<Buffer>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { definePlugin } from './types.js';
|
|
2
|
+
export type { Plugin, PluginContext, PluginsOptions } from './types.js';
|
|
3
|
+
export { PluginRegistry } from './registry.js';
|
|
4
|
+
export type { PluginHost } from './registry.js';
|
|
5
|
+
export { PluginLoader, scanPluginFiles, importPlugin } from './loader.js';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Logger } from '../client/types.js';
|
|
2
|
+
import type { PluginRegistry } from './registry.js';
|
|
3
|
+
import type { Plugin, PluginsOptions } from './types.js';
|
|
4
|
+
export declare function scanPluginFiles(dir: string, pattern: RegExp, ignore: RegExp): Promise<string[]>;
|
|
5
|
+
export declare function importPlugin(file: string, bust?: number): Promise<Plugin | undefined>;
|
|
6
|
+
export declare class PluginLoader {
|
|
7
|
+
private readonly dir;
|
|
8
|
+
private readonly pattern;
|
|
9
|
+
private readonly ignore;
|
|
10
|
+
private readonly watchEnabled;
|
|
11
|
+
private readonly onError;
|
|
12
|
+
private readonly registry;
|
|
13
|
+
private readonly logger;
|
|
14
|
+
private watcher;
|
|
15
|
+
private readonly fileToName;
|
|
16
|
+
private bust;
|
|
17
|
+
private debounce;
|
|
18
|
+
private readonly pending;
|
|
19
|
+
private flushChain;
|
|
20
|
+
constructor(deps: {
|
|
21
|
+
registry: PluginRegistry;
|
|
22
|
+
options: PluginsOptions;
|
|
23
|
+
logger?: Logger;
|
|
24
|
+
});
|
|
25
|
+
start(): Promise<void>;
|
|
26
|
+
stop(): Promise<void>;
|
|
27
|
+
private loadFile;
|
|
28
|
+
private startWatch;
|
|
29
|
+
private flush;
|
|
30
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Logger } from '../client/types.js';
|
|
2
|
+
import type { Plugin, PluginContext } from './types.js';
|
|
3
|
+
export interface PluginHost {
|
|
4
|
+
command(spec: string, handler: Parameters<PluginContext['command']>[1]): unknown;
|
|
5
|
+
unregisterCommand(spec: string): void;
|
|
6
|
+
use(mw: Parameters<PluginContext['use']>[0]): unknown;
|
|
7
|
+
unuse(mw: Parameters<PluginContext['use']>[0]): unknown;
|
|
8
|
+
on: PluginContext['on'];
|
|
9
|
+
logger?: Logger | undefined;
|
|
10
|
+
}
|
|
11
|
+
export declare class PluginRegistry {
|
|
12
|
+
private readonly host;
|
|
13
|
+
private readonly logger;
|
|
14
|
+
private readonly plugins;
|
|
15
|
+
constructor(deps: {
|
|
16
|
+
client: PluginHost;
|
|
17
|
+
logger?: Logger;
|
|
18
|
+
});
|
|
19
|
+
has(name: string): boolean;
|
|
20
|
+
list(): string[];
|
|
21
|
+
loadPlugin(plugin: Plugin, file: string): Promise<void>;
|
|
22
|
+
unload(name: string): Promise<void>;
|
|
23
|
+
unloadAll(): Promise<void>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Client } from '../client/client.js';
|
|
2
|
+
import type { Logger, ClientEventMap } from '../client/types.js';
|
|
3
|
+
import type { CommandHandler, Middleware } from '../command/index.js';
|
|
4
|
+
export interface PluginContext {
|
|
5
|
+
client: Client;
|
|
6
|
+
logger: Logger | undefined;
|
|
7
|
+
pluginDir: string;
|
|
8
|
+
command(spec: string, handler: CommandHandler): void;
|
|
9
|
+
use(middleware: Middleware): void;
|
|
10
|
+
on<E extends keyof ClientEventMap>(event: E, handler: (payload: ClientEventMap[E]) => void): () => void;
|
|
11
|
+
once<E extends keyof ClientEventMap>(event: E, handler: (payload: ClientEventMap[E]) => void): () => void;
|
|
12
|
+
}
|
|
13
|
+
export interface Plugin {
|
|
14
|
+
name: string;
|
|
15
|
+
setup(ctx: PluginContext): void | (() => void) | Promise<void | (() => void)>;
|
|
16
|
+
onUnload?(): void | Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export type PluginsOptions = {
|
|
19
|
+
dir?: string;
|
|
20
|
+
watch?: boolean;
|
|
21
|
+
pattern?: RegExp;
|
|
22
|
+
ignore?: RegExp;
|
|
23
|
+
onError?: (err: unknown, file: string) => void;
|
|
24
|
+
};
|
|
25
|
+
export declare const definePlugin: (plugin: Plugin) => Plugin;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Chat, Contact, PresenceData, WAMessage, WAMessageKey } from 'baileys';
|
|
2
|
+
import { type ConvexKvOptions } from '../../types/convex.js';
|
|
3
|
+
import type { BaileysSocketLike, MessageStore, MessageStoreListOptions, PruneOptions, ScheduledJobRecord } from '../types.js';
|
|
4
|
+
export type ConvexMessageStoreOptions = ConvexKvOptions;
|
|
5
|
+
export declare class ConvexMessageStore implements MessageStore {
|
|
6
|
+
private readonly kv;
|
|
7
|
+
private closed;
|
|
8
|
+
private boundSocket;
|
|
9
|
+
private readonly listeners;
|
|
10
|
+
constructor(options: ConvexMessageStoreOptions);
|
|
11
|
+
saveMessage(message: WAMessage): Promise<void>;
|
|
12
|
+
getMessage(key: WAMessageKey): Promise<WAMessage | undefined>;
|
|
13
|
+
listMessages(jid: string, options?: MessageStoreListOptions): Promise<WAMessage[]>;
|
|
14
|
+
saveChat(chat: Chat): Promise<void>;
|
|
15
|
+
getChat(jid: string): Promise<Chat | undefined>;
|
|
16
|
+
listChats(options?: {
|
|
17
|
+
archived?: boolean;
|
|
18
|
+
}): Promise<Chat[]>;
|
|
19
|
+
saveContact(contact: Contact): Promise<void>;
|
|
20
|
+
getContact(jid: string): Promise<Contact | undefined>;
|
|
21
|
+
listContacts(): Promise<Contact[]>;
|
|
22
|
+
savePresence(jid: string, presence: PresenceData): Promise<void>;
|
|
23
|
+
getPresence(jid: string): Promise<PresenceData | undefined>;
|
|
24
|
+
saveScheduledJob(job: ScheduledJobRecord): Promise<void>;
|
|
25
|
+
listScheduledJobs(): Promise<ScheduledJobRecord[]>;
|
|
26
|
+
deleteScheduledJob(id: string): Promise<void>;
|
|
27
|
+
deleteMessage(key: WAMessageKey): Promise<void>;
|
|
28
|
+
pruneMessages(opts: PruneOptions): Promise<number>;
|
|
29
|
+
bind(socket: BaileysSocketLike): void;
|
|
30
|
+
clear(): Promise<void>;
|
|
31
|
+
close(): Promise<void>;
|
|
32
|
+
private assertOpen;
|
|
33
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Chat, Contact, PresenceData, WAMessage, WAMessageKey } from 'baileys';
|
|
2
|
+
import type { BaileysSocketLike, MessageStore, MessageStoreListOptions, PruneOptions } from '../types.js';
|
|
3
|
+
export declare class MemoryMessageStore implements MessageStore {
|
|
4
|
+
private readonly messages;
|
|
5
|
+
private readonly messagesByJid;
|
|
6
|
+
private readonly chats;
|
|
7
|
+
private readonly contacts;
|
|
8
|
+
private readonly presence;
|
|
9
|
+
private boundSocket;
|
|
10
|
+
private readonly listeners;
|
|
11
|
+
private closed;
|
|
12
|
+
saveMessage(message: WAMessage): Promise<void>;
|
|
13
|
+
getMessage(key: WAMessageKey): Promise<WAMessage | undefined>;
|
|
14
|
+
listMessages(jid: string, options?: MessageStoreListOptions): Promise<WAMessage[]>;
|
|
15
|
+
saveChat(chat: Chat): Promise<void>;
|
|
16
|
+
getChat(jid: string): Promise<Chat | undefined>;
|
|
17
|
+
listChats(options?: {
|
|
18
|
+
archived?: boolean;
|
|
19
|
+
}): Promise<Chat[]>;
|
|
20
|
+
saveContact(contact: Contact): Promise<void>;
|
|
21
|
+
getContact(jid: string): Promise<Contact | undefined>;
|
|
22
|
+
listContacts(): Promise<Contact[]>;
|
|
23
|
+
savePresence(jid: string, presence: PresenceData): Promise<void>;
|
|
24
|
+
getPresence(jid: string): Promise<PresenceData | undefined>;
|
|
25
|
+
bind(socket: BaileysSocketLike): void;
|
|
26
|
+
deleteMessage(key: WAMessageKey): Promise<void>;
|
|
27
|
+
pruneMessages(opts: PruneOptions): Promise<number>;
|
|
28
|
+
clear(): Promise<void>;
|
|
29
|
+
close(): Promise<void>;
|
|
30
|
+
private assertOpen;
|
|
31
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Chat, Contact, PresenceData, WAMessage, WAMessageKey } from 'baileys';
|
|
2
|
+
import type { PgPoolLike } from '../../types/optional-clients.js';
|
|
3
|
+
import type { BaileysSocketLike, MessageStore, MessageStoreListOptions, PruneOptions } from '../types.js';
|
|
4
|
+
export interface PostgresMessageStoreOptions {
|
|
5
|
+
pool?: PgPoolLike;
|
|
6
|
+
connectionString?: string;
|
|
7
|
+
max?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class PostgresMessageStore implements MessageStore {
|
|
10
|
+
private readonly externalPool;
|
|
11
|
+
private readonly connectionString;
|
|
12
|
+
private readonly poolMax;
|
|
13
|
+
private ownedPool;
|
|
14
|
+
private resolvedPool;
|
|
15
|
+
private readyPromise;
|
|
16
|
+
private boundSocket;
|
|
17
|
+
private readonly listeners;
|
|
18
|
+
private closed;
|
|
19
|
+
constructor(options: PostgresMessageStoreOptions);
|
|
20
|
+
private assertOpen;
|
|
21
|
+
private ensureReady;
|
|
22
|
+
saveMessage(message: WAMessage): Promise<void>;
|
|
23
|
+
getMessage(key: WAMessageKey): Promise<WAMessage | undefined>;
|
|
24
|
+
listMessages(jid: string, options?: MessageStoreListOptions): Promise<WAMessage[]>;
|
|
25
|
+
saveChat(chat: Chat): Promise<void>;
|
|
26
|
+
getChat(jid: string): Promise<Chat | undefined>;
|
|
27
|
+
listChats(options?: {
|
|
28
|
+
archived?: boolean;
|
|
29
|
+
}): Promise<Chat[]>;
|
|
30
|
+
saveContact(contact: Contact): Promise<void>;
|
|
31
|
+
getContact(jid: string): Promise<Contact | undefined>;
|
|
32
|
+
listContacts(): Promise<Contact[]>;
|
|
33
|
+
savePresence(jid: string, presence: PresenceData): Promise<void>;
|
|
34
|
+
getPresence(jid: string): Promise<PresenceData | undefined>;
|
|
35
|
+
deleteMessage(key: WAMessageKey): Promise<void>;
|
|
36
|
+
pruneMessages(opts: PruneOptions): Promise<number>;
|
|
37
|
+
bind(socket: BaileysSocketLike): void;
|
|
38
|
+
clear(): Promise<void>;
|
|
39
|
+
close(): Promise<void>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Chat, Contact, PresenceData, WAMessage, WAMessageKey } from 'baileys';
|
|
2
|
+
import type { RedisClientLike } from '../../types/optional-clients.js';
|
|
3
|
+
import type { BaileysSocketLike, MessageStore, MessageStoreListOptions, PruneOptions } from '../types.js';
|
|
4
|
+
export interface RedisMessageStoreOptions {
|
|
5
|
+
client?: RedisClientLike;
|
|
6
|
+
url?: string;
|
|
7
|
+
namespace?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class RedisMessageStore implements MessageStore {
|
|
10
|
+
private readonly namespace;
|
|
11
|
+
private readonly externalClient;
|
|
12
|
+
private readonly url;
|
|
13
|
+
private ownedClient;
|
|
14
|
+
private ready;
|
|
15
|
+
private closed;
|
|
16
|
+
private boundSocket;
|
|
17
|
+
private readonly listeners;
|
|
18
|
+
constructor(options: RedisMessageStoreOptions);
|
|
19
|
+
saveMessage(message: WAMessage): Promise<void>;
|
|
20
|
+
getMessage(key: WAMessageKey): Promise<WAMessage | undefined>;
|
|
21
|
+
listMessages(jid: string, options?: MessageStoreListOptions): Promise<WAMessage[]>;
|
|
22
|
+
saveChat(chat: Chat): Promise<void>;
|
|
23
|
+
getChat(jid: string): Promise<Chat | undefined>;
|
|
24
|
+
listChats(options?: {
|
|
25
|
+
archived?: boolean;
|
|
26
|
+
}): Promise<Chat[]>;
|
|
27
|
+
saveContact(contact: Contact): Promise<void>;
|
|
28
|
+
getContact(jid: string): Promise<Contact | undefined>;
|
|
29
|
+
listContacts(): Promise<Contact[]>;
|
|
30
|
+
savePresence(jid: string, presence: PresenceData): Promise<void>;
|
|
31
|
+
getPresence(jid: string): Promise<PresenceData | undefined>;
|
|
32
|
+
bind(socket: BaileysSocketLike): void;
|
|
33
|
+
clear(): Promise<void>;
|
|
34
|
+
close(): Promise<void>;
|
|
35
|
+
deleteMessage(key: WAMessageKey): Promise<void>;
|
|
36
|
+
pruneMessages(opts: PruneOptions): Promise<number>;
|
|
37
|
+
private jidFromIndexKey;
|
|
38
|
+
private msgIndexKey;
|
|
39
|
+
private msgDataKey;
|
|
40
|
+
private chatsKey;
|
|
41
|
+
private chatsArchiveKey;
|
|
42
|
+
private contactsKey;
|
|
43
|
+
private presenceKey;
|
|
44
|
+
private ensureReady;
|
|
45
|
+
private connect;
|
|
46
|
+
private runRead;
|
|
47
|
+
private runWrite;
|
|
48
|
+
private assertOpen;
|
|
49
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Chat, Contact, PresenceData, WAMessage, WAMessageKey } from 'baileys';
|
|
2
|
+
import type { BaileysSocketLike, MessageStore, MessageStoreListOptions, PruneOptions } from '../types.js';
|
|
3
|
+
export interface SqliteMessageStoreOptions {
|
|
4
|
+
database: string | Buffer;
|
|
5
|
+
readonly?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare class SqliteMessageStore implements MessageStore {
|
|
8
|
+
private readonly options;
|
|
9
|
+
private db;
|
|
10
|
+
private prepared;
|
|
11
|
+
private readyPromise;
|
|
12
|
+
private closed;
|
|
13
|
+
private boundSocket;
|
|
14
|
+
private readonly listeners;
|
|
15
|
+
constructor(options: SqliteMessageStoreOptions);
|
|
16
|
+
saveMessage(message: WAMessage): Promise<void>;
|
|
17
|
+
getMessage(key: WAMessageKey): Promise<WAMessage | undefined>;
|
|
18
|
+
listMessages(jid: string, options?: MessageStoreListOptions): Promise<WAMessage[]>;
|
|
19
|
+
saveChat(chat: Chat): Promise<void>;
|
|
20
|
+
getChat(jid: string): Promise<Chat | undefined>;
|
|
21
|
+
listChats(options?: {
|
|
22
|
+
archived?: boolean;
|
|
23
|
+
}): Promise<Chat[]>;
|
|
24
|
+
saveContact(contact: Contact): Promise<void>;
|
|
25
|
+
getContact(jid: string): Promise<Contact | undefined>;
|
|
26
|
+
listContacts(): Promise<Contact[]>;
|
|
27
|
+
savePresence(jid: string, presence: PresenceData): Promise<void>;
|
|
28
|
+
getPresence(jid: string): Promise<PresenceData | undefined>;
|
|
29
|
+
deleteMessage(key: WAMessageKey): Promise<void>;
|
|
30
|
+
pruneMessages(opts: PruneOptions): Promise<number>;
|
|
31
|
+
bind(socket: BaileysSocketLike): void;
|
|
32
|
+
clear(): Promise<void>;
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
private ensureReady;
|
|
35
|
+
private openAndMigrate;
|
|
36
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Chat, Contact, PresenceData, WAMessage, WAMessageKey } from 'baileys';
|
|
2
|
+
export type MessageStoreListOptions = {
|
|
3
|
+
limit?: number;
|
|
4
|
+
before?: number;
|
|
5
|
+
};
|
|
6
|
+
export type PruneOptions = {
|
|
7
|
+
/** Delete messages whose `messageTimestamp` is strictly older than this epoch value, in **seconds** (matching stored `messageTimestamp`). */
|
|
8
|
+
olderThan?: number;
|
|
9
|
+
/** Keep only the newest N messages per chat. */
|
|
10
|
+
maxPerChat?: number;
|
|
11
|
+
/** Restrict pruning to chats whose jid passes this predicate. */
|
|
12
|
+
chatFilter?: (jid: string) => boolean;
|
|
13
|
+
};
|
|
14
|
+
export type ScheduledJobRecord = {
|
|
15
|
+
id: string;
|
|
16
|
+
fireAt: number;
|
|
17
|
+
recipient: string;
|
|
18
|
+
payload: unknown;
|
|
19
|
+
};
|
|
20
|
+
export interface BaileysSocketLike {
|
|
21
|
+
ev: {
|
|
22
|
+
on: (event: string, handler: (...args: unknown[]) => void) => void;
|
|
23
|
+
off?: (event: string, handler: (...args: unknown[]) => void) => void;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export interface MessageStore {
|
|
27
|
+
saveMessage(message: WAMessage): Promise<void>;
|
|
28
|
+
getMessage(key: WAMessageKey): Promise<WAMessage | undefined>;
|
|
29
|
+
listMessages(jid: string, options?: MessageStoreListOptions): Promise<WAMessage[]>;
|
|
30
|
+
saveChat(chat: Chat): Promise<void>;
|
|
31
|
+
getChat(jid: string): Promise<Chat | undefined>;
|
|
32
|
+
listChats(options?: {
|
|
33
|
+
archived?: boolean;
|
|
34
|
+
}): Promise<Chat[]>;
|
|
35
|
+
saveContact(contact: Contact): Promise<void>;
|
|
36
|
+
getContact(jid: string): Promise<Contact | undefined>;
|
|
37
|
+
listContacts(): Promise<Contact[]>;
|
|
38
|
+
savePresence(jid: string, presence: PresenceData): Promise<void>;
|
|
39
|
+
getPresence(jid: string): Promise<PresenceData | undefined>;
|
|
40
|
+
bind(socket: BaileysSocketLike): void;
|
|
41
|
+
clear(): Promise<void>;
|
|
42
|
+
close(): Promise<void>;
|
|
43
|
+
saveScheduledJob?(job: ScheduledJobRecord): Promise<void>;
|
|
44
|
+
listScheduledJobs?(): Promise<ScheduledJobRecord[]>;
|
|
45
|
+
deleteScheduledJob?(id: string): Promise<void>;
|
|
46
|
+
deleteMessage?(key: WAMessageKey): Promise<void>;
|
|
47
|
+
pruneMessages?(opts: PruneOptions): Promise<number>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface ConvexClientLike {
|
|
2
|
+
query(name: string, args: Record<string, unknown>): Promise<unknown>;
|
|
3
|
+
mutation(name: string, args: Record<string, unknown>): Promise<unknown>;
|
|
4
|
+
}
|
|
5
|
+
export interface ConvexKvOptions {
|
|
6
|
+
client?: ConvexClientLike;
|
|
7
|
+
url?: string;
|
|
8
|
+
namespace?: string;
|
|
9
|
+
}
|
|
10
|
+
export type ConvexKvRow = {
|
|
11
|
+
key: string;
|
|
12
|
+
value: string;
|
|
13
|
+
sortKey?: number;
|
|
14
|
+
};
|
|
15
|
+
export declare class ConvexKv {
|
|
16
|
+
readonly namespace: string;
|
|
17
|
+
private readonly externalClient;
|
|
18
|
+
private readonly url;
|
|
19
|
+
private client;
|
|
20
|
+
private closed;
|
|
21
|
+
constructor(options: ConvexKvOptions);
|
|
22
|
+
get(keys: readonly string[]): Promise<Map<string, string>>;
|
|
23
|
+
set(items: readonly ConvexKvRow[]): Promise<void>;
|
|
24
|
+
del(keys: readonly string[]): Promise<void>;
|
|
25
|
+
clear(prefix?: string): Promise<void>;
|
|
26
|
+
list(prefix: string, options?: {
|
|
27
|
+
before?: number;
|
|
28
|
+
limit?: number;
|
|
29
|
+
}): Promise<ConvexKvRow[]>;
|
|
30
|
+
close(): void;
|
|
31
|
+
private ensureClient;
|
|
32
|
+
private runRead;
|
|
33
|
+
private runWrite;
|
|
34
|
+
private assertOpen;
|
|
35
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** Structural stand-ins for optional peers (pg, redis) so their types never leak into dist typings. */
|
|
2
|
+
export interface PgQueryResultLike<R = Record<string, unknown>> {
|
|
3
|
+
rows: R[];
|
|
4
|
+
rowCount?: number | null;
|
|
5
|
+
}
|
|
6
|
+
export interface PgPoolClientLike {
|
|
7
|
+
query<R extends Record<string, unknown> = Record<string, unknown>>(sql: string, params?: readonly unknown[]): Promise<PgQueryResultLike<R>>;
|
|
8
|
+
release(): void;
|
|
9
|
+
}
|
|
10
|
+
export interface PgPoolLike {
|
|
11
|
+
query<R extends Record<string, unknown> = Record<string, unknown>>(sql: string, params?: readonly unknown[]): Promise<PgQueryResultLike<R>>;
|
|
12
|
+
connect(): Promise<PgPoolClientLike>;
|
|
13
|
+
end(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export interface PgPoolCtorLike {
|
|
16
|
+
new (config: {
|
|
17
|
+
connectionString?: string | undefined;
|
|
18
|
+
max?: number | undefined;
|
|
19
|
+
}): PgPoolLike;
|
|
20
|
+
}
|
|
21
|
+
export interface RedisMultiLike {
|
|
22
|
+
set(key: string, value: string): RedisMultiLike;
|
|
23
|
+
del(key: string): RedisMultiLike;
|
|
24
|
+
sAdd(key: string, members: string): RedisMultiLike;
|
|
25
|
+
sRem(key: string, members: string): RedisMultiLike;
|
|
26
|
+
hSet(key: string, field: string, value: string): RedisMultiLike;
|
|
27
|
+
hDel(key: string, fields: string | string[]): RedisMultiLike;
|
|
28
|
+
zAdd(key: string, entry: {
|
|
29
|
+
score: number;
|
|
30
|
+
value: string;
|
|
31
|
+
}): RedisMultiLike;
|
|
32
|
+
zRem(key: string, members: string | string[]): RedisMultiLike;
|
|
33
|
+
exec(): Promise<unknown>;
|
|
34
|
+
}
|
|
35
|
+
export interface RedisClientLike {
|
|
36
|
+
readonly isOpen: boolean;
|
|
37
|
+
connect(): Promise<unknown>;
|
|
38
|
+
quit(): Promise<unknown>;
|
|
39
|
+
get(key: string): Promise<string | null>;
|
|
40
|
+
set(key: string, value: string, options?: {
|
|
41
|
+
EX?: number;
|
|
42
|
+
}): Promise<unknown>;
|
|
43
|
+
del(keys: string | string[]): Promise<number>;
|
|
44
|
+
mGet(keys: string[]): Promise<Array<string | null>>;
|
|
45
|
+
hGet(key: string, field: string): Promise<string | null | undefined>;
|
|
46
|
+
hSet(key: string, field: string, value: string): Promise<number>;
|
|
47
|
+
hDel(key: string, fields: string | string[]): Promise<number>;
|
|
48
|
+
hmGet(key: string, fields: string[]): Promise<Array<string | null>>;
|
|
49
|
+
hGetAll(key: string): Promise<Record<string, string>>;
|
|
50
|
+
sAdd(key: string, members: string): Promise<number>;
|
|
51
|
+
sRem(key: string, members: string): Promise<number>;
|
|
52
|
+
sMembers(key: string): Promise<string[]>;
|
|
53
|
+
sIsMember(key: string, member: string): Promise<boolean | number>;
|
|
54
|
+
zRange(key: string, min: number, max: number): Promise<string[]>;
|
|
55
|
+
zRangeByScore(key: string, min: string | number, max: string | number, options?: {
|
|
56
|
+
LIMIT?: {
|
|
57
|
+
offset: number;
|
|
58
|
+
count: number;
|
|
59
|
+
};
|
|
60
|
+
}): Promise<string[]>;
|
|
61
|
+
scan(cursor: number, options?: {
|
|
62
|
+
MATCH?: string;
|
|
63
|
+
COUNT?: number;
|
|
64
|
+
}): Promise<{
|
|
65
|
+
cursor: number | string;
|
|
66
|
+
keys: string[];
|
|
67
|
+
}>;
|
|
68
|
+
multi(): RedisMultiLike;
|
|
69
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type StoreErrorCode = 'STORE_NOT_AVAILABLE' | 'STORE_CONNECTION_FAILED' | 'STORE_WRITE_FAILED' | 'STORE_READ_FAILED' | 'STORE_CORRUPTED' | 'STORE_CLOSED';
|
|
2
|
+
export declare class ZaileysStoreError extends Error {
|
|
3
|
+
readonly code: StoreErrorCode;
|
|
4
|
+
readonly cause?: unknown;
|
|
5
|
+
constructor(code: StoreErrorCode, message: string, options?: {
|
|
6
|
+
cause?: unknown;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const chunk: <T>(input: readonly T[], size: number) => T[][];
|