better-zap 0.0.1

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.
@@ -0,0 +1,123 @@
1
+ import { $ as WebhookContact, A as noopLogger, B as InteractiveMediaCarouselCardInput, C as WhatsAppLogStore, D as Logger, E as LogLevel, F as StatusUpdateEvent, G as SendMessageError, H as MessageError, I as SyncEvent, J as TemplateComponent, K as SendMessageResponse, L as WhatsAppConfig, M as ConversationSummary, N as ConversationUpdateEvent, O as LoggerConfig, P as NewMessageEvent, Q as WebhookChange, R as Conversation, S as WhatsAppLogRecord, T as WhatsAppStatus, U as MessageStatus, V as MediaMessage, W as SendInteractiveMediaCarouselData, X as UIMessage, Y as TemplateParameter, Z as UIMessageStatus, _ as WhatsAppService, a as TemplateComponentDefinition, at as WhatsAppInteractiveButtonsMessage, b as WHATSAPP_MESSAGE_TYPES, c as TemplateParameterDefinition, ct as WhatsAppLocationMessage, d as TemplateRegistry, et as WebhookEntry, f as defineTemplates, g as OutgoingLoggingMetadata, h as serializeTemplateFromRegistry, i as SupportedTemplateParameterType, it as WhatsAppCarouselCard, j as serializeError, k as createLogger, l as TemplateParameterInputMap, lt as WhatsAppTemplateMessage, m as hasConfiguredTemplates, n as createZapClient, nt as WebhookPayload, o as TemplateDefinition, ot as WhatsAppInteractiveListMessage, p as getTemplateNames, q as SendResult, r as EMPTY_TEMPLATE_REGISTRY, rt as WebhookValue, s as TemplateName, st as WhatsAppInteractiveMediaCarouselMessage, t as ZapClient, tt as WebhookError, u as TemplateParams, ut as WhatsAppTextMessage, v as MessageLoggerNotifier, w as WhatsAppMessageType, x as WhatsAppDirection, y as MessageLoggerService, z as IncomingMessage } from "./client-D5Lgtacj.cjs";
2
+
3
+ //#region src/events.d.ts
4
+ type MessageContext = {
5
+ message: IncomingMessage;
6
+ contact: WebhookContact | undefined;
7
+ content: string;
8
+ phone: string;
9
+ };
10
+ type StatusContext = {
11
+ status: MessageStatus;
12
+ timestamp: string;
13
+ errorMessage?: string;
14
+ errorCode?: number;
15
+ };
16
+ //#endregion
17
+ //#region src/utils/phone.d.ts
18
+ /**
19
+ * Formats a phone number to the international format required by Meta Cloud API.
20
+ * Currently defaults to Brazilian country code (55) if not provided.
21
+ * Normalizes Brazilian numbers to always include the 9th digit.
22
+ */
23
+ declare function formatPhone(phone: string): string;
24
+ //#endregion
25
+ //#region src/utils/delay.d.ts
26
+ /**
27
+ * Utility function to pause execution for a given number of milliseconds.
28
+ * Useful for exponential backoff or rate limiting.
29
+ */
30
+ declare function delay(ms: number): Promise<void>;
31
+ //#endregion
32
+ //#region src/better-zap.types.d.ts
33
+ interface BetterZapDatabase {
34
+ whatsappLog: WhatsAppLogStore;
35
+ }
36
+ type BetterZapCoreConfig = WhatsAppConfig & {
37
+ webhookToken: string;
38
+ appSecret: string;
39
+ };
40
+ type UnionToIntersection<TUnion> = (TUnion extends unknown ? (value: TUnion) => void : never) extends ((value: infer TIntersection) => void) ? TIntersection : never;
41
+ type Simplify<TValue> = { [TKey in keyof TValue]: TValue[TKey] } & {};
42
+ type Awaitable<TValue> = TValue | Promise<TValue>;
43
+ type BetterZapCoreContext<TDatabase extends BetterZapDatabase = BetterZapDatabase> = {
44
+ db: TDatabase;
45
+ api: WhatsAppService;
46
+ logger: MessageLoggerService;
47
+ };
48
+ type BetterZapContext<TDatabase extends BetterZapDatabase = BetterZapDatabase, TPluginContext extends Record<string, unknown> = {}> = Simplify<BetterZapCoreContext<TDatabase> & TPluginContext>;
49
+ type BetterZapCoreServices = {
50
+ whatsapp: WhatsAppService;
51
+ logger: MessageLoggerService;
52
+ };
53
+ type BetterZapServices<TPluginServices extends Record<string, unknown> = {}> = Simplify<BetterZapCoreServices & TPluginServices>;
54
+ interface BetterZapPluginInitResult<TContext extends Record<string, unknown> = {}, TServices extends Record<string, unknown> = {}> {
55
+ context?: TContext;
56
+ services?: TServices;
57
+ }
58
+ interface BetterZapPluginInitContext<TDatabase extends BetterZapDatabase = BetterZapDatabase> {
59
+ database: TDatabase;
60
+ config: BetterZapCoreConfig;
61
+ context: BetterZapContext<TDatabase, Record<string, unknown>>;
62
+ services: BetterZapServices<Record<string, unknown>>;
63
+ log: Logger;
64
+ }
65
+ interface BetterZapPlugin<TDatabase extends BetterZapDatabase = BetterZapDatabase, TContext extends Record<string, unknown> = {}, TServices extends Record<string, unknown> = {}> {
66
+ id: string;
67
+ init?: (ctx: BetterZapPluginInitContext<TDatabase>) => BetterZapPluginInitResult<TContext, TServices> | void;
68
+ hooks?: {
69
+ onMessage?: (ctx: MessageContext & BetterZapContext<TDatabase, Record<string, unknown> & TContext>) => Promise<void>;
70
+ onStatusUpdate?: (ctx: StatusContext & BetterZapContext<TDatabase, Record<string, unknown> & TContext>) => Promise<void>;
71
+ };
72
+ }
73
+ type InferBetterZapPluginContext<TPlugins> = Simplify<UnionToIntersection<TPlugins extends readonly BetterZapPlugin<any, infer TContext, any>[] ? TContext : {}>>;
74
+ type InferBetterZapPluginServices<TPlugins> = Simplify<UnionToIntersection<TPlugins extends readonly BetterZapPlugin<any, any, infer TServices>[] ? TServices : {}>>;
75
+ type RawTemplateSendOptions = {
76
+ language?: string;
77
+ components?: TemplateComponent[];
78
+ logging?: OutgoingLoggingMetadata;
79
+ };
80
+ type TypedTemplateSendOptions<TTemplates extends TemplateRegistry, TName extends TemplateName<TTemplates>> = {
81
+ language?: string;
82
+ params: TemplateParams<TTemplates[TName]>;
83
+ logging?: OutgoingLoggingMetadata;
84
+ };
85
+ type BetterZapTemplateSendMethod<TTemplates extends TemplateRegistry> = [TemplateName<TTemplates>] extends [never] ? (to: string, templateName: string, opts?: RawTemplateSendOptions) => Promise<SendResult> : <TName extends TemplateName<TTemplates>>(to: string, templateName: TName, opts: TypedTemplateSendOptions<TTemplates, TName>) => Promise<SendResult>;
86
+ interface BetterZapApi<TTemplates extends TemplateRegistry = {}> {
87
+ send: {
88
+ text(to: string, body: string, opts?: Omit<OutgoingLoggingMetadata, "content">): Promise<SendResult>;
89
+ template: BetterZapTemplateSendMethod<TTemplates>;
90
+ templateRaw(to: string, templateName: string, opts?: RawTemplateSendOptions): Promise<SendResult>;
91
+ interactiveButtons(to: string, body: string, buttons: Array<{
92
+ id: string;
93
+ title: string;
94
+ }>, opts?: Omit<OutgoingLoggingMetadata, "content">): Promise<SendResult>;
95
+ interactiveList(to: string, body: string, buttonLabel: string, sections: Array<{
96
+ title: string;
97
+ rows: Array<{
98
+ id: string;
99
+ title: string;
100
+ description?: string;
101
+ }>;
102
+ }>, opts?: Omit<OutgoingLoggingMetadata, "content">): Promise<SendResult>;
103
+ interactiveMediaCarousel(data: SendInteractiveMediaCarouselData, opts?: Omit<OutgoingLoggingMetadata, "content">): Promise<SendResult>;
104
+ location(to: string, location: {
105
+ latitude: number;
106
+ longitude: number;
107
+ name: string;
108
+ address: string;
109
+ }, opts?: Omit<OutgoingLoggingMetadata, "content">): Promise<SendResult>;
110
+ markAsRead(messageId: string): Promise<SendResult>;
111
+ reaction(to: string, messageId: string, emoji: string): Promise<SendResult>;
112
+ };
113
+ conversations: {
114
+ list(): Promise<Conversation[]>;
115
+ get(phone: string): Promise<Conversation | null>;
116
+ messages(phone: string, opts?: {
117
+ cursor?: string;
118
+ limit?: number;
119
+ }): Promise<UIMessage[]>;
120
+ };
121
+ }
122
+ //#endregion
123
+ export { type Awaitable, type BetterZapApi, type BetterZapContext, type BetterZapCoreConfig, type BetterZapCoreContext, type BetterZapCoreServices, type BetterZapDatabase, type BetterZapPlugin, type BetterZapPluginInitContext, type BetterZapPluginInitResult, type BetterZapServices, type Conversation, type ConversationSummary, type ConversationUpdateEvent, EMPTY_TEMPLATE_REGISTRY, type IncomingMessage, type InferBetterZapPluginContext, type InferBetterZapPluginServices, type InteractiveMediaCarouselCardInput, type LogLevel, type Logger, type LoggerConfig, type MediaMessage, type MessageContext, type MessageError, type MessageLoggerNotifier, MessageLoggerService, type MessageStatus, type NewMessageEvent, type OutgoingLoggingMetadata, type SendInteractiveMediaCarouselData, type SendMessageError, type SendMessageResponse, type SendResult, type StatusContext, type StatusUpdateEvent, type SupportedTemplateParameterType, type SyncEvent, type TemplateComponent, type TemplateComponentDefinition, type TemplateDefinition, type TemplateName, type TemplateParameter, type TemplateParameterDefinition, type TemplateParameterInputMap, type TemplateParams, type TemplateRegistry, type UIMessage, type UIMessageStatus, WHATSAPP_MESSAGE_TYPES, type WebhookChange, type WebhookContact, type WebhookEntry, type WebhookError, type WebhookPayload, type WebhookValue, type WhatsAppCarouselCard, type WhatsAppConfig, type WhatsAppDirection, type WhatsAppInteractiveButtonsMessage, type WhatsAppInteractiveListMessage, type WhatsAppInteractiveMediaCarouselMessage, type WhatsAppLocationMessage, type WhatsAppLogRecord, type WhatsAppLogStore, type WhatsAppMessageType, WhatsAppService, type WhatsAppStatus, type WhatsAppTemplateMessage, type WhatsAppTextMessage, type ZapClient, createLogger, createZapClient, defineTemplates, delay, formatPhone, getTemplateNames, hasConfiguredTemplates, noopLogger, serializeError, serializeTemplateFromRegistry };
@@ -0,0 +1,123 @@
1
+ import { $ as WebhookContact, A as noopLogger, B as InteractiveMediaCarouselCardInput, C as WhatsAppLogStore, D as Logger, E as LogLevel, F as StatusUpdateEvent, G as SendMessageError, H as MessageError, I as SyncEvent, J as TemplateComponent, K as SendMessageResponse, L as WhatsAppConfig, M as ConversationSummary, N as ConversationUpdateEvent, O as LoggerConfig, P as NewMessageEvent, Q as WebhookChange, R as Conversation, S as WhatsAppLogRecord, T as WhatsAppStatus, U as MessageStatus, V as MediaMessage, W as SendInteractiveMediaCarouselData, X as UIMessage, Y as TemplateParameter, Z as UIMessageStatus, _ as WhatsAppService, a as TemplateComponentDefinition, at as WhatsAppInteractiveButtonsMessage, b as WHATSAPP_MESSAGE_TYPES, c as TemplateParameterDefinition, ct as WhatsAppLocationMessage, d as TemplateRegistry, et as WebhookEntry, f as defineTemplates, g as OutgoingLoggingMetadata, h as serializeTemplateFromRegistry, i as SupportedTemplateParameterType, it as WhatsAppCarouselCard, j as serializeError, k as createLogger, l as TemplateParameterInputMap, lt as WhatsAppTemplateMessage, m as hasConfiguredTemplates, n as createZapClient, nt as WebhookPayload, o as TemplateDefinition, ot as WhatsAppInteractiveListMessage, p as getTemplateNames, q as SendResult, r as EMPTY_TEMPLATE_REGISTRY, rt as WebhookValue, s as TemplateName, st as WhatsAppInteractiveMediaCarouselMessage, t as ZapClient, tt as WebhookError, u as TemplateParams, ut as WhatsAppTextMessage, v as MessageLoggerNotifier, w as WhatsAppMessageType, x as WhatsAppDirection, y as MessageLoggerService, z as IncomingMessage } from "./client-ColqW3Zc.mjs";
2
+
3
+ //#region src/events.d.ts
4
+ type MessageContext = {
5
+ message: IncomingMessage;
6
+ contact: WebhookContact | undefined;
7
+ content: string;
8
+ phone: string;
9
+ };
10
+ type StatusContext = {
11
+ status: MessageStatus;
12
+ timestamp: string;
13
+ errorMessage?: string;
14
+ errorCode?: number;
15
+ };
16
+ //#endregion
17
+ //#region src/utils/phone.d.ts
18
+ /**
19
+ * Formats a phone number to the international format required by Meta Cloud API.
20
+ * Currently defaults to Brazilian country code (55) if not provided.
21
+ * Normalizes Brazilian numbers to always include the 9th digit.
22
+ */
23
+ declare function formatPhone(phone: string): string;
24
+ //#endregion
25
+ //#region src/utils/delay.d.ts
26
+ /**
27
+ * Utility function to pause execution for a given number of milliseconds.
28
+ * Useful for exponential backoff or rate limiting.
29
+ */
30
+ declare function delay(ms: number): Promise<void>;
31
+ //#endregion
32
+ //#region src/better-zap.types.d.ts
33
+ interface BetterZapDatabase {
34
+ whatsappLog: WhatsAppLogStore;
35
+ }
36
+ type BetterZapCoreConfig = WhatsAppConfig & {
37
+ webhookToken: string;
38
+ appSecret: string;
39
+ };
40
+ type UnionToIntersection<TUnion> = (TUnion extends unknown ? (value: TUnion) => void : never) extends ((value: infer TIntersection) => void) ? TIntersection : never;
41
+ type Simplify<TValue> = { [TKey in keyof TValue]: TValue[TKey] } & {};
42
+ type Awaitable<TValue> = TValue | Promise<TValue>;
43
+ type BetterZapCoreContext<TDatabase extends BetterZapDatabase = BetterZapDatabase> = {
44
+ db: TDatabase;
45
+ api: WhatsAppService;
46
+ logger: MessageLoggerService;
47
+ };
48
+ type BetterZapContext<TDatabase extends BetterZapDatabase = BetterZapDatabase, TPluginContext extends Record<string, unknown> = {}> = Simplify<BetterZapCoreContext<TDatabase> & TPluginContext>;
49
+ type BetterZapCoreServices = {
50
+ whatsapp: WhatsAppService;
51
+ logger: MessageLoggerService;
52
+ };
53
+ type BetterZapServices<TPluginServices extends Record<string, unknown> = {}> = Simplify<BetterZapCoreServices & TPluginServices>;
54
+ interface BetterZapPluginInitResult<TContext extends Record<string, unknown> = {}, TServices extends Record<string, unknown> = {}> {
55
+ context?: TContext;
56
+ services?: TServices;
57
+ }
58
+ interface BetterZapPluginInitContext<TDatabase extends BetterZapDatabase = BetterZapDatabase> {
59
+ database: TDatabase;
60
+ config: BetterZapCoreConfig;
61
+ context: BetterZapContext<TDatabase, Record<string, unknown>>;
62
+ services: BetterZapServices<Record<string, unknown>>;
63
+ log: Logger;
64
+ }
65
+ interface BetterZapPlugin<TDatabase extends BetterZapDatabase = BetterZapDatabase, TContext extends Record<string, unknown> = {}, TServices extends Record<string, unknown> = {}> {
66
+ id: string;
67
+ init?: (ctx: BetterZapPluginInitContext<TDatabase>) => BetterZapPluginInitResult<TContext, TServices> | void;
68
+ hooks?: {
69
+ onMessage?: (ctx: MessageContext & BetterZapContext<TDatabase, Record<string, unknown> & TContext>) => Promise<void>;
70
+ onStatusUpdate?: (ctx: StatusContext & BetterZapContext<TDatabase, Record<string, unknown> & TContext>) => Promise<void>;
71
+ };
72
+ }
73
+ type InferBetterZapPluginContext<TPlugins> = Simplify<UnionToIntersection<TPlugins extends readonly BetterZapPlugin<any, infer TContext, any>[] ? TContext : {}>>;
74
+ type InferBetterZapPluginServices<TPlugins> = Simplify<UnionToIntersection<TPlugins extends readonly BetterZapPlugin<any, any, infer TServices>[] ? TServices : {}>>;
75
+ type RawTemplateSendOptions = {
76
+ language?: string;
77
+ components?: TemplateComponent[];
78
+ logging?: OutgoingLoggingMetadata;
79
+ };
80
+ type TypedTemplateSendOptions<TTemplates extends TemplateRegistry, TName extends TemplateName<TTemplates>> = {
81
+ language?: string;
82
+ params: TemplateParams<TTemplates[TName]>;
83
+ logging?: OutgoingLoggingMetadata;
84
+ };
85
+ type BetterZapTemplateSendMethod<TTemplates extends TemplateRegistry> = [TemplateName<TTemplates>] extends [never] ? (to: string, templateName: string, opts?: RawTemplateSendOptions) => Promise<SendResult> : <TName extends TemplateName<TTemplates>>(to: string, templateName: TName, opts: TypedTemplateSendOptions<TTemplates, TName>) => Promise<SendResult>;
86
+ interface BetterZapApi<TTemplates extends TemplateRegistry = {}> {
87
+ send: {
88
+ text(to: string, body: string, opts?: Omit<OutgoingLoggingMetadata, "content">): Promise<SendResult>;
89
+ template: BetterZapTemplateSendMethod<TTemplates>;
90
+ templateRaw(to: string, templateName: string, opts?: RawTemplateSendOptions): Promise<SendResult>;
91
+ interactiveButtons(to: string, body: string, buttons: Array<{
92
+ id: string;
93
+ title: string;
94
+ }>, opts?: Omit<OutgoingLoggingMetadata, "content">): Promise<SendResult>;
95
+ interactiveList(to: string, body: string, buttonLabel: string, sections: Array<{
96
+ title: string;
97
+ rows: Array<{
98
+ id: string;
99
+ title: string;
100
+ description?: string;
101
+ }>;
102
+ }>, opts?: Omit<OutgoingLoggingMetadata, "content">): Promise<SendResult>;
103
+ interactiveMediaCarousel(data: SendInteractiveMediaCarouselData, opts?: Omit<OutgoingLoggingMetadata, "content">): Promise<SendResult>;
104
+ location(to: string, location: {
105
+ latitude: number;
106
+ longitude: number;
107
+ name: string;
108
+ address: string;
109
+ }, opts?: Omit<OutgoingLoggingMetadata, "content">): Promise<SendResult>;
110
+ markAsRead(messageId: string): Promise<SendResult>;
111
+ reaction(to: string, messageId: string, emoji: string): Promise<SendResult>;
112
+ };
113
+ conversations: {
114
+ list(): Promise<Conversation[]>;
115
+ get(phone: string): Promise<Conversation | null>;
116
+ messages(phone: string, opts?: {
117
+ cursor?: string;
118
+ limit?: number;
119
+ }): Promise<UIMessage[]>;
120
+ };
121
+ }
122
+ //#endregion
123
+ export { type Awaitable, type BetterZapApi, type BetterZapContext, type BetterZapCoreConfig, type BetterZapCoreContext, type BetterZapCoreServices, type BetterZapDatabase, type BetterZapPlugin, type BetterZapPluginInitContext, type BetterZapPluginInitResult, type BetterZapServices, type Conversation, type ConversationSummary, type ConversationUpdateEvent, EMPTY_TEMPLATE_REGISTRY, type IncomingMessage, type InferBetterZapPluginContext, type InferBetterZapPluginServices, type InteractiveMediaCarouselCardInput, type LogLevel, type Logger, type LoggerConfig, type MediaMessage, type MessageContext, type MessageError, type MessageLoggerNotifier, MessageLoggerService, type MessageStatus, type NewMessageEvent, type OutgoingLoggingMetadata, type SendInteractiveMediaCarouselData, type SendMessageError, type SendMessageResponse, type SendResult, type StatusContext, type StatusUpdateEvent, type SupportedTemplateParameterType, type SyncEvent, type TemplateComponent, type TemplateComponentDefinition, type TemplateDefinition, type TemplateName, type TemplateParameter, type TemplateParameterDefinition, type TemplateParameterInputMap, type TemplateParams, type TemplateRegistry, type UIMessage, type UIMessageStatus, WHATSAPP_MESSAGE_TYPES, type WebhookChange, type WebhookContact, type WebhookEntry, type WebhookError, type WebhookPayload, type WebhookValue, type WhatsAppCarouselCard, type WhatsAppConfig, type WhatsAppDirection, type WhatsAppInteractiveButtonsMessage, type WhatsAppInteractiveListMessage, type WhatsAppInteractiveMediaCarouselMessage, type WhatsAppLocationMessage, type WhatsAppLogRecord, type WhatsAppLogStore, type WhatsAppMessageType, WhatsAppService, type WhatsAppStatus, type WhatsAppTemplateMessage, type WhatsAppTextMessage, type ZapClient, createLogger, createZapClient, defineTemplates, delay, formatPhone, getTemplateNames, hasConfiguredTemplates, noopLogger, serializeError, serializeTemplateFromRegistry };