zaileys 4.9.0 → 4.11.0

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.
@@ -1,5 +1,5 @@
1
1
  import type { Logger } from '../client/types.js';
2
- import type { Plugin, PluginContext } from './types.js';
2
+ import { type Plugin, type PluginContext } from './types.js';
3
3
  export interface PluginHost {
4
4
  command(spec: Parameters<PluginContext['command']>[0], handler: Parameters<PluginContext['command']>[1]): unknown;
5
5
  unregisterCommand(spec: Parameters<PluginContext["command"]>[0]): void;
@@ -1,6 +1,7 @@
1
1
  import type { Client } from '../client/client.js';
2
2
  import type { Logger, ClientEventMap } from '../client/types.js';
3
- import type { CommandHandler, CommandSpec, Middleware } from '../command/index.js';
3
+ import type { CommandGuards, CommandHandler, CommandMeta, CommandSpec, Middleware } from '../command/index.js';
4
+ import type { InboundEventMap } from '../events/types.js';
4
5
  export interface PluginContext {
5
6
  client: Client;
6
7
  logger: Logger | undefined;
@@ -12,11 +13,24 @@ export interface PluginContext {
12
13
  on<E extends keyof ClientEventMap>(event: E, handler: (payload: ClientEventMap[E]) => void): () => void;
13
14
  once<E extends keyof ClientEventMap>(event: E, handler: (payload: ClientEventMap[E]) => void): () => void;
14
15
  }
15
- export interface Plugin {
16
+ /** `'poll-vote'` reads as `pollVote()` on a plugin, so the method names stay idiomatic. */
17
+ type Camel<S extends string> = S extends `${infer Head}-${infer Tail}` ? `${Head}${Capitalize<Camel<Tail>>}` : S;
18
+ /** One optional method per inbound event, derived so a new event is available here automatically. */
19
+ export type PluginEventHandlers = {
20
+ [E in keyof InboundEventMap as Camel<E>]?: (payload: InboundEventMap[E], ctx: PluginContext) => void | Promise<void>;
21
+ };
22
+ /** Every inbound event name, in the order their methods are wired up. */
23
+ export declare const INBOUND_EVENTS: readonly ["message", "text", "image", "video", "audio", "document", "sticker", "reaction", "edit", "delete", "poll-vote", "button-click", "list-select", "mention", "mention-all", "group-update", "group-join", "group-leave", "member-tag", "call-incoming", "call-ended", "history-sync", "limited", "presence", "newsletter"];
24
+ export type Plugin = CommandMeta & CommandGuards & PluginEventHandlers & {
25
+ /** Identifies the plugin, and names the command that `command()` handles. */
16
26
  name: string;
17
- setup(ctx: PluginContext): void | (() => void) | Promise<void | (() => void)>;
27
+ aliases?: string[];
28
+ /** Handles the command named after this plugin. The metadata above describes it. */
29
+ command?: (ctx: Parameters<CommandHandler>[0], plugin: PluginContext) => void | Promise<void>;
30
+ /** Escape hatch for what the methods above cannot express: extra commands, middleware, cleanup. */
31
+ setup?(ctx: PluginContext): void | (() => void) | Promise<void | (() => void)>;
18
32
  onUnload?(): void | Promise<void>;
19
- }
33
+ };
20
34
  export type PluginsOptions = {
21
35
  dir?: string;
22
36
  watch?: boolean;
@@ -24,4 +38,6 @@ export type PluginsOptions = {
24
38
  ignore?: RegExp;
25
39
  onError?: (err: unknown, file: string) => void;
26
40
  };
41
+ /** Identity helper — gives you autocomplete on the plugin shape at zero runtime cost. */
27
42
  export declare const definePlugin: (plugin: Plugin) => Plugin;
43
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zaileys",
3
3
  "description": "Zaileys - Simplified WhatsApp Node.js TypeScript/JavaScript API",
4
- "version": "4.9.0",
4
+ "version": "4.11.0",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",