@better-zap/hono 0.1.0 → 0.2.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.
package/dist/index.d.cts CHANGED
@@ -1,29 +1,6 @@
1
- import { BetterZapApi, BetterZapApi as BetterZapApi$1, BetterZapContext, BetterZapContext as BetterZapContext$1, BetterZapCoreConfig, BetterZapCoreConfig as BetterZapCoreConfig$1, BetterZapDatabase, BetterZapDatabase as BetterZapDatabase$1, BetterZapPlugin, BetterZapPlugin as BetterZapPlugin$1, BetterZapPluginInitContext, BetterZapPluginInitResult, BetterZapServices, BetterZapServices as BetterZapServices$1, IncomingMessage, InferBetterZapPluginContext, InferBetterZapPluginContext as InferBetterZapPluginContext$1, InferBetterZapPluginServices, InferBetterZapPluginServices as InferBetterZapPluginServices$1, Logger, LoggerConfig, MessageContext, MessageContext as MessageContext$1, MessageLoggerService, StatusContext, StatusContext as StatusContext$1, TemplateRegistry, WebhookError, WhatsAppLogStore, WhatsAppService } from "better-zap";
1
+ import { BetterZapApi, BetterZapApi as BetterZapApi$1, BetterZapContext, BetterZapContext as BetterZapContext$1, BetterZapCoreConfig, BetterZapCoreConfig as BetterZapCoreConfig$1, BetterZapDatabase, BetterZapDatabase as BetterZapDatabase$1, BetterZapPlugin, BetterZapPlugin as BetterZapPlugin$1, BetterZapPluginInitContext, BetterZapPluginInitResult, BetterZapServices, BetterZapServices as BetterZapServices$1, CoexistenceAccountOffboardedValue, CoexistenceAccountReconnectedValue, CoexistenceAccountUpdateValue, CoexistenceCredentialProvider, CoexistenceHistoryValue, CoexistenceMessageEditValue, CoexistenceMessageRevokeValue, CoexistenceService, CoexistenceSmbAppStateSyncValue, CoexistenceSmbMessageEchoesValue, CoexistenceStore, CoexistenceUnsupportedValue, IncomingMessage, InferBetterZapPluginContext, InferBetterZapPluginContext as InferBetterZapPluginContext$1, InferBetterZapPluginServices, InferBetterZapPluginServices as InferBetterZapPluginServices$1, Logger, LoggerConfig, MessageContext, MessageContext as MessageContext$1, MessageLoggerService, StatusContext, StatusContext as StatusContext$1, TemplateRegistry, WebhookChange, WebhookError, WhatsAppLogStore, WhatsAppService } from "better-zap";
2
2
  import { Hono } from "hono";
3
3
 
4
- //#region src/better-zap.types.d.ts
5
- interface BetterZapConfig<TDatabase extends BetterZapDatabase$1 = BetterZapDatabase$1, TPlugins extends readonly BetterZapPlugin$1<TDatabase, any, any>[] = readonly [], TTemplates extends TemplateRegistry = {}> {
6
- database: TDatabase;
7
- config: BetterZapCoreConfig$1;
8
- plugins?: TPlugins;
9
- templates?: TTemplates;
10
- conversationSync?: DurableObjectNamespace<any>;
11
- webhook: {
12
- onMessage: (ctx: MessageContext$1 & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
13
- onStatusUpdate: (ctx: StatusContext$1 & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
14
- };
15
- basePath?: string;
16
- logger?: LoggerConfig;
17
- }
18
- interface BetterZap<TPluginServices extends Record<string, unknown> = {}, TTemplates extends TemplateRegistry = {}> {
19
- handler: (request: Request, env?: any, executionCtx?: any) => Promise<Response>;
20
- api: BetterZapApi$1<TTemplates>;
21
- services: BetterZapServices$1<TPluginServices>;
22
- }
23
- //#endregion
24
- //#region src/better-zap.d.ts
25
- declare function betterZap<TDatabase extends BetterZapDatabase$1 = BetterZapDatabase$1, TPlugins extends readonly BetterZapPlugin$1<TDatabase, any, any>[] = readonly BetterZapPlugin$1<TDatabase, any, any>[], TTemplates extends TemplateRegistry = {}>(options: BetterZapConfig<TDatabase, TPlugins, TTemplates>): BetterZap<InferBetterZapPluginServices$1<TPlugins>, TTemplates>;
26
- //#endregion
27
4
  //#region src/webhook/create-webhook-handler.d.ts
28
5
  /**
29
6
  * Configuration for {@link createWebhookHandler}.
@@ -34,15 +11,70 @@ type WebhookConfig = {
34
11
  /** Token for the Meta verification challenge (`GET /webhook`). */verifyToken: string; /** App secret used for HMAC-SHA256 signature verification. */
35
12
  appSecret: string; /** logger for automatic message storage. */
36
13
  logger: MessageLoggerService; /** Structured logger for operational logging. */
37
- log: Logger; /** Called once per incoming message, after SDK pre-processing. */
14
+ log: Logger; /** Optional database contracts used for automatic coexistence persistence. */
15
+ database?: BetterZapDatabase$1; /** Called once per incoming message, after SDK pre-processing. */
38
16
  onMessage: (ctx: MessageContext$1) => Promise<void>; /** Called once per delivery status update (sent → delivered → read → failed). */
39
- onStatusUpdate: (ctx: StatusContext$1) => Promise<void>;
17
+ onStatusUpdate: (ctx: StatusContext$1) => Promise<void>; /** Called once per history webhook after SDK pre-processing. */
18
+ onCoexistenceHistory?: (ctx: CoexistenceHistoryContext) => Promise<void>; /** Called once per SMB app state sync webhook after SDK pre-processing. */
19
+ onSmbAppStateSync?: (ctx: SmbAppStateSyncContext) => Promise<void>; /** Called once per app message echo webhook after SDK pre-processing. */
20
+ onSmbMessageEcho?: (ctx: SmbMessageEchoContext) => Promise<void>; /** Called once per coexistence account lifecycle webhook. */
21
+ onCoexistenceAccountUpdate?: (ctx: CoexistenceAccountUpdateContext) => Promise<void>; /** Called once per coexistence offboarding lifecycle webhook. */
22
+ onCoexistenceAccountOffboarded?: (ctx: CoexistenceAccountOffboardedContext) => Promise<void>; /** Called once per coexistence background reconnection lifecycle webhook. */
23
+ onCoexistenceAccountReconnected?: (ctx: CoexistenceAccountReconnectedContext) => Promise<void>; /** Called for coexistence message edit webhooks. */
24
+ onCoexistenceMessageEdit?: (ctx: CoexistenceMessageEditContext) => Promise<void>; /** Called for coexistence message revoke webhooks. */
25
+ onCoexistenceMessageRevoke?: (ctx: CoexistenceMessageRevokeContext) => Promise<void>; /** Called when a coexistence webhook contains unsupported/error content. */
26
+ onCoexistenceUnsupportedMessage?: (ctx: CoexistenceUnsupportedMessageContext) => Promise<void>;
40
27
  /**
41
28
  * Called for Meta platform-level errors.
42
29
  * @default Uses the configured {@link WebhookConfig.log} logger's {@code error} method.
43
30
  */
44
31
  onError?: (error: WebhookError) => void;
45
32
  };
33
+ interface CoexistenceHistoryContext {
34
+ value: CoexistenceHistoryValue;
35
+ change: WebhookChange;
36
+ importedMessages: number;
37
+ duplicateMessages: number;
38
+ }
39
+ interface SmbAppStateSyncContext {
40
+ value: CoexistenceSmbAppStateSyncValue;
41
+ change: WebhookChange;
42
+ upsertedContacts: number;
43
+ removedContacts: number;
44
+ }
45
+ interface SmbMessageEchoContext {
46
+ value: CoexistenceSmbMessageEchoesValue;
47
+ change: WebhookChange;
48
+ importedMessages: number;
49
+ duplicateMessages: number;
50
+ }
51
+ interface CoexistenceAccountUpdateContext {
52
+ value: CoexistenceAccountUpdateValue;
53
+ change: WebhookChange;
54
+ }
55
+ interface CoexistenceAccountOffboardedContext {
56
+ value: CoexistenceAccountOffboardedValue;
57
+ change: WebhookChange;
58
+ }
59
+ interface CoexistenceAccountReconnectedContext {
60
+ value: CoexistenceAccountReconnectedValue;
61
+ change: WebhookChange;
62
+ }
63
+ interface CoexistenceMessageEditContext {
64
+ value: CoexistenceMessageEditValue;
65
+ change: WebhookChange;
66
+ editedMessages: number;
67
+ }
68
+ interface CoexistenceMessageRevokeContext {
69
+ value: CoexistenceMessageRevokeValue;
70
+ change: WebhookChange;
71
+ revokedMessages: number;
72
+ }
73
+ interface CoexistenceUnsupportedMessageContext {
74
+ value: CoexistenceHistoryValue | CoexistenceSmbAppStateSyncValue | CoexistenceUnsupportedValue;
75
+ change: WebhookChange;
76
+ errors: WebhookError[];
77
+ }
46
78
  /**
47
79
  * Creates a Hono router that handles the full WhatsApp webhook lifecycle.
48
80
  *
@@ -59,6 +91,60 @@ declare function createWebhookHandler(config: WebhookConfig): Hono<{
59
91
  Bindings: Record<string, any>;
60
92
  }>;
61
93
  //#endregion
94
+ //#region src/better-zap.types.d.ts
95
+ type BetterZapAuthorizeAppRequest = (input: {
96
+ request: Request;
97
+ env?: unknown;
98
+ }) => boolean | Promise<boolean>;
99
+ interface BetterZapConfig<TDatabase extends BetterZapDatabase$1 = BetterZapDatabase$1, TPlugins extends readonly BetterZapPlugin$1<TDatabase, any, any>[] = readonly [], TTemplates extends TemplateRegistry = {}> {
100
+ database: TDatabase;
101
+ config: BetterZapCoreConfig$1;
102
+ plugins?: TPlugins;
103
+ templates?: TTemplates;
104
+ conversationSync?: DurableObjectNamespace<any>;
105
+ webhook: {
106
+ onMessage: (ctx: MessageContext$1 & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
107
+ onStatusUpdate: (ctx: StatusContext$1 & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
108
+ onCoexistenceHistory?: (ctx: CoexistenceHistoryContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
109
+ onSmbAppStateSync?: (ctx: SmbAppStateSyncContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
110
+ onSmbMessageEcho?: (ctx: SmbMessageEchoContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
111
+ onCoexistenceAccountUpdate?: (ctx: CoexistenceAccountUpdateContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
112
+ onCoexistenceAccountOffboarded?: (ctx: CoexistenceAccountOffboardedContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
113
+ onCoexistenceAccountReconnected?: (ctx: CoexistenceAccountReconnectedContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
114
+ onCoexistenceMessageEdit?: (ctx: CoexistenceMessageEditContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
115
+ onCoexistenceMessageRevoke?: (ctx: CoexistenceMessageRevokeContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
116
+ onCoexistenceUnsupportedMessage?: (ctx: CoexistenceUnsupportedMessageContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
117
+ };
118
+ coexistence?: {
119
+ enabled?: boolean;
120
+ service?: CoexistenceService;
121
+ credentials?: CoexistenceCredentialProvider;
122
+ accessToken?: string;
123
+ appId?: string;
124
+ appSecret?: string;
125
+ graphApiVersion?: string;
126
+ graphBaseUrl?: string;
127
+ fetch?: typeof fetch;
128
+ /**
129
+ * Subscribe the connected WABA to this app after a successful Embedded
130
+ * Signup code exchange. Defaults to true. Failures are returned and recorded
131
+ * instead of being silently ignored.
132
+ */
133
+ subscribeWabaAfterCodeExchange?: boolean;
134
+ };
135
+ basePath?: string;
136
+ authorizeAppRequest?: BetterZapAuthorizeAppRequest;
137
+ logger?: LoggerConfig;
138
+ }
139
+ interface BetterZap<TPluginServices extends Record<string, unknown> = {}, TTemplates extends TemplateRegistry = {}> {
140
+ handler: (request: Request, env?: any, executionCtx?: any) => Promise<Response>;
141
+ api: BetterZapApi$1<TTemplates>;
142
+ services: BetterZapServices$1<TPluginServices>;
143
+ }
144
+ //#endregion
145
+ //#region src/better-zap.d.ts
146
+ declare function betterZap<TDatabase extends BetterZapDatabase$1 = BetterZapDatabase$1, TPlugins extends readonly BetterZapPlugin$1<TDatabase, any, any>[] = readonly BetterZapPlugin$1<TDatabase, any, any>[], TTemplates extends TemplateRegistry = {}>(options: BetterZapConfig<TDatabase, TPlugins, TTemplates>): BetterZap<InferBetterZapPluginServices$1<TPlugins>, TTemplates>;
147
+ //#endregion
62
148
  //#region src/webhook/signature-verification.d.ts
63
149
  declare function verifyMetaWebhookSignature({
64
150
  rawBody,
@@ -82,7 +168,10 @@ type BetterZapEnv = {
82
168
  whatsapp: WhatsAppService;
83
169
  store: WhatsAppLogStore;
84
170
  logger: Logger;
171
+ coexistence?: CoexistenceService;
172
+ coexistenceStore?: CoexistenceStore;
173
+ subscribeWabaAfterCodeExchange?: boolean;
85
174
  };
86
175
  };
87
176
  //#endregion
88
- export { type BetterZap, type BetterZapApi, type BetterZapConfig, type BetterZapContext, type BetterZapCoreConfig, type BetterZapDatabase, type BetterZapEnv, type BetterZapPlugin, type BetterZapPluginInitContext, type BetterZapPluginInitResult, type BetterZapServices, type InferBetterZapPluginContext, type InferBetterZapPluginServices, type MessageContext, type StatusContext, type WebhookConfig, betterZap, createWebhookHandler, getMessageContent, verifyMetaWebhookSignature };
177
+ export { type BetterZap, type BetterZapApi, type BetterZapConfig, type BetterZapContext, type BetterZapCoreConfig, type BetterZapDatabase, type BetterZapEnv, type BetterZapPlugin, type BetterZapPluginInitContext, type BetterZapPluginInitResult, type BetterZapServices, type CoexistenceAccountOffboardedContext, type CoexistenceAccountReconnectedContext, type CoexistenceAccountUpdateContext, type CoexistenceHistoryContext, type CoexistenceMessageEditContext, type CoexistenceMessageRevokeContext, type CoexistenceUnsupportedMessageContext, type InferBetterZapPluginContext, type InferBetterZapPluginServices, type MessageContext, type SmbAppStateSyncContext, type SmbMessageEchoContext, type StatusContext, type WebhookConfig, betterZap, createWebhookHandler, getMessageContent, verifyMetaWebhookSignature };
package/dist/index.d.mts CHANGED
@@ -1,29 +1,6 @@
1
1
  import { Hono } from "hono";
2
- import { BetterZapApi, BetterZapApi as BetterZapApi$1, BetterZapContext, BetterZapContext as BetterZapContext$1, BetterZapCoreConfig, BetterZapCoreConfig as BetterZapCoreConfig$1, BetterZapDatabase, BetterZapDatabase as BetterZapDatabase$1, BetterZapPlugin, BetterZapPlugin as BetterZapPlugin$1, BetterZapPluginInitContext, BetterZapPluginInitResult, BetterZapServices, BetterZapServices as BetterZapServices$1, IncomingMessage, InferBetterZapPluginContext, InferBetterZapPluginContext as InferBetterZapPluginContext$1, InferBetterZapPluginServices, InferBetterZapPluginServices as InferBetterZapPluginServices$1, Logger, LoggerConfig, MessageContext, MessageContext as MessageContext$1, MessageLoggerService, StatusContext, StatusContext as StatusContext$1, TemplateRegistry, WebhookError, WhatsAppLogStore, WhatsAppService } from "better-zap";
2
+ import { BetterZapApi, BetterZapApi as BetterZapApi$1, BetterZapContext, BetterZapContext as BetterZapContext$1, BetterZapCoreConfig, BetterZapCoreConfig as BetterZapCoreConfig$1, BetterZapDatabase, BetterZapDatabase as BetterZapDatabase$1, BetterZapPlugin, BetterZapPlugin as BetterZapPlugin$1, BetterZapPluginInitContext, BetterZapPluginInitResult, BetterZapServices, BetterZapServices as BetterZapServices$1, CoexistenceAccountOffboardedValue, CoexistenceAccountReconnectedValue, CoexistenceAccountUpdateValue, CoexistenceCredentialProvider, CoexistenceHistoryValue, CoexistenceMessageEditValue, CoexistenceMessageRevokeValue, CoexistenceService, CoexistenceSmbAppStateSyncValue, CoexistenceSmbMessageEchoesValue, CoexistenceStore, CoexistenceUnsupportedValue, IncomingMessage, InferBetterZapPluginContext, InferBetterZapPluginContext as InferBetterZapPluginContext$1, InferBetterZapPluginServices, InferBetterZapPluginServices as InferBetterZapPluginServices$1, Logger, LoggerConfig, MessageContext, MessageContext as MessageContext$1, MessageLoggerService, StatusContext, StatusContext as StatusContext$1, TemplateRegistry, WebhookChange, WebhookError, WhatsAppLogStore, WhatsAppService } from "better-zap";
3
3
 
4
- //#region src/better-zap.types.d.ts
5
- interface BetterZapConfig<TDatabase extends BetterZapDatabase$1 = BetterZapDatabase$1, TPlugins extends readonly BetterZapPlugin$1<TDatabase, any, any>[] = readonly [], TTemplates extends TemplateRegistry = {}> {
6
- database: TDatabase;
7
- config: BetterZapCoreConfig$1;
8
- plugins?: TPlugins;
9
- templates?: TTemplates;
10
- conversationSync?: DurableObjectNamespace<any>;
11
- webhook: {
12
- onMessage: (ctx: MessageContext$1 & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
13
- onStatusUpdate: (ctx: StatusContext$1 & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
14
- };
15
- basePath?: string;
16
- logger?: LoggerConfig;
17
- }
18
- interface BetterZap<TPluginServices extends Record<string, unknown> = {}, TTemplates extends TemplateRegistry = {}> {
19
- handler: (request: Request, env?: any, executionCtx?: any) => Promise<Response>;
20
- api: BetterZapApi$1<TTemplates>;
21
- services: BetterZapServices$1<TPluginServices>;
22
- }
23
- //#endregion
24
- //#region src/better-zap.d.ts
25
- declare function betterZap<TDatabase extends BetterZapDatabase$1 = BetterZapDatabase$1, TPlugins extends readonly BetterZapPlugin$1<TDatabase, any, any>[] = readonly BetterZapPlugin$1<TDatabase, any, any>[], TTemplates extends TemplateRegistry = {}>(options: BetterZapConfig<TDatabase, TPlugins, TTemplates>): BetterZap<InferBetterZapPluginServices$1<TPlugins>, TTemplates>;
26
- //#endregion
27
4
  //#region src/webhook/create-webhook-handler.d.ts
28
5
  /**
29
6
  * Configuration for {@link createWebhookHandler}.
@@ -34,15 +11,70 @@ type WebhookConfig = {
34
11
  /** Token for the Meta verification challenge (`GET /webhook`). */verifyToken: string; /** App secret used for HMAC-SHA256 signature verification. */
35
12
  appSecret: string; /** logger for automatic message storage. */
36
13
  logger: MessageLoggerService; /** Structured logger for operational logging. */
37
- log: Logger; /** Called once per incoming message, after SDK pre-processing. */
14
+ log: Logger; /** Optional database contracts used for automatic coexistence persistence. */
15
+ database?: BetterZapDatabase$1; /** Called once per incoming message, after SDK pre-processing. */
38
16
  onMessage: (ctx: MessageContext$1) => Promise<void>; /** Called once per delivery status update (sent → delivered → read → failed). */
39
- onStatusUpdate: (ctx: StatusContext$1) => Promise<void>;
17
+ onStatusUpdate: (ctx: StatusContext$1) => Promise<void>; /** Called once per history webhook after SDK pre-processing. */
18
+ onCoexistenceHistory?: (ctx: CoexistenceHistoryContext) => Promise<void>; /** Called once per SMB app state sync webhook after SDK pre-processing. */
19
+ onSmbAppStateSync?: (ctx: SmbAppStateSyncContext) => Promise<void>; /** Called once per app message echo webhook after SDK pre-processing. */
20
+ onSmbMessageEcho?: (ctx: SmbMessageEchoContext) => Promise<void>; /** Called once per coexistence account lifecycle webhook. */
21
+ onCoexistenceAccountUpdate?: (ctx: CoexistenceAccountUpdateContext) => Promise<void>; /** Called once per coexistence offboarding lifecycle webhook. */
22
+ onCoexistenceAccountOffboarded?: (ctx: CoexistenceAccountOffboardedContext) => Promise<void>; /** Called once per coexistence background reconnection lifecycle webhook. */
23
+ onCoexistenceAccountReconnected?: (ctx: CoexistenceAccountReconnectedContext) => Promise<void>; /** Called for coexistence message edit webhooks. */
24
+ onCoexistenceMessageEdit?: (ctx: CoexistenceMessageEditContext) => Promise<void>; /** Called for coexistence message revoke webhooks. */
25
+ onCoexistenceMessageRevoke?: (ctx: CoexistenceMessageRevokeContext) => Promise<void>; /** Called when a coexistence webhook contains unsupported/error content. */
26
+ onCoexistenceUnsupportedMessage?: (ctx: CoexistenceUnsupportedMessageContext) => Promise<void>;
40
27
  /**
41
28
  * Called for Meta platform-level errors.
42
29
  * @default Uses the configured {@link WebhookConfig.log} logger's {@code error} method.
43
30
  */
44
31
  onError?: (error: WebhookError) => void;
45
32
  };
33
+ interface CoexistenceHistoryContext {
34
+ value: CoexistenceHistoryValue;
35
+ change: WebhookChange;
36
+ importedMessages: number;
37
+ duplicateMessages: number;
38
+ }
39
+ interface SmbAppStateSyncContext {
40
+ value: CoexistenceSmbAppStateSyncValue;
41
+ change: WebhookChange;
42
+ upsertedContacts: number;
43
+ removedContacts: number;
44
+ }
45
+ interface SmbMessageEchoContext {
46
+ value: CoexistenceSmbMessageEchoesValue;
47
+ change: WebhookChange;
48
+ importedMessages: number;
49
+ duplicateMessages: number;
50
+ }
51
+ interface CoexistenceAccountUpdateContext {
52
+ value: CoexistenceAccountUpdateValue;
53
+ change: WebhookChange;
54
+ }
55
+ interface CoexistenceAccountOffboardedContext {
56
+ value: CoexistenceAccountOffboardedValue;
57
+ change: WebhookChange;
58
+ }
59
+ interface CoexistenceAccountReconnectedContext {
60
+ value: CoexistenceAccountReconnectedValue;
61
+ change: WebhookChange;
62
+ }
63
+ interface CoexistenceMessageEditContext {
64
+ value: CoexistenceMessageEditValue;
65
+ change: WebhookChange;
66
+ editedMessages: number;
67
+ }
68
+ interface CoexistenceMessageRevokeContext {
69
+ value: CoexistenceMessageRevokeValue;
70
+ change: WebhookChange;
71
+ revokedMessages: number;
72
+ }
73
+ interface CoexistenceUnsupportedMessageContext {
74
+ value: CoexistenceHistoryValue | CoexistenceSmbAppStateSyncValue | CoexistenceUnsupportedValue;
75
+ change: WebhookChange;
76
+ errors: WebhookError[];
77
+ }
46
78
  /**
47
79
  * Creates a Hono router that handles the full WhatsApp webhook lifecycle.
48
80
  *
@@ -59,6 +91,60 @@ declare function createWebhookHandler(config: WebhookConfig): Hono<{
59
91
  Bindings: Record<string, any>;
60
92
  }>;
61
93
  //#endregion
94
+ //#region src/better-zap.types.d.ts
95
+ type BetterZapAuthorizeAppRequest = (input: {
96
+ request: Request;
97
+ env?: unknown;
98
+ }) => boolean | Promise<boolean>;
99
+ interface BetterZapConfig<TDatabase extends BetterZapDatabase$1 = BetterZapDatabase$1, TPlugins extends readonly BetterZapPlugin$1<TDatabase, any, any>[] = readonly [], TTemplates extends TemplateRegistry = {}> {
100
+ database: TDatabase;
101
+ config: BetterZapCoreConfig$1;
102
+ plugins?: TPlugins;
103
+ templates?: TTemplates;
104
+ conversationSync?: DurableObjectNamespace<any>;
105
+ webhook: {
106
+ onMessage: (ctx: MessageContext$1 & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
107
+ onStatusUpdate: (ctx: StatusContext$1 & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
108
+ onCoexistenceHistory?: (ctx: CoexistenceHistoryContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
109
+ onSmbAppStateSync?: (ctx: SmbAppStateSyncContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
110
+ onSmbMessageEcho?: (ctx: SmbMessageEchoContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
111
+ onCoexistenceAccountUpdate?: (ctx: CoexistenceAccountUpdateContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
112
+ onCoexistenceAccountOffboarded?: (ctx: CoexistenceAccountOffboardedContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
113
+ onCoexistenceAccountReconnected?: (ctx: CoexistenceAccountReconnectedContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
114
+ onCoexistenceMessageEdit?: (ctx: CoexistenceMessageEditContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
115
+ onCoexistenceMessageRevoke?: (ctx: CoexistenceMessageRevokeContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
116
+ onCoexistenceUnsupportedMessage?: (ctx: CoexistenceUnsupportedMessageContext & BetterZapContext$1<TDatabase, InferBetterZapPluginContext$1<TPlugins>>) => Promise<void>;
117
+ };
118
+ coexistence?: {
119
+ enabled?: boolean;
120
+ service?: CoexistenceService;
121
+ credentials?: CoexistenceCredentialProvider;
122
+ accessToken?: string;
123
+ appId?: string;
124
+ appSecret?: string;
125
+ graphApiVersion?: string;
126
+ graphBaseUrl?: string;
127
+ fetch?: typeof fetch;
128
+ /**
129
+ * Subscribe the connected WABA to this app after a successful Embedded
130
+ * Signup code exchange. Defaults to true. Failures are returned and recorded
131
+ * instead of being silently ignored.
132
+ */
133
+ subscribeWabaAfterCodeExchange?: boolean;
134
+ };
135
+ basePath?: string;
136
+ authorizeAppRequest?: BetterZapAuthorizeAppRequest;
137
+ logger?: LoggerConfig;
138
+ }
139
+ interface BetterZap<TPluginServices extends Record<string, unknown> = {}, TTemplates extends TemplateRegistry = {}> {
140
+ handler: (request: Request, env?: any, executionCtx?: any) => Promise<Response>;
141
+ api: BetterZapApi$1<TTemplates>;
142
+ services: BetterZapServices$1<TPluginServices>;
143
+ }
144
+ //#endregion
145
+ //#region src/better-zap.d.ts
146
+ declare function betterZap<TDatabase extends BetterZapDatabase$1 = BetterZapDatabase$1, TPlugins extends readonly BetterZapPlugin$1<TDatabase, any, any>[] = readonly BetterZapPlugin$1<TDatabase, any, any>[], TTemplates extends TemplateRegistry = {}>(options: BetterZapConfig<TDatabase, TPlugins, TTemplates>): BetterZap<InferBetterZapPluginServices$1<TPlugins>, TTemplates>;
147
+ //#endregion
62
148
  //#region src/webhook/signature-verification.d.ts
63
149
  declare function verifyMetaWebhookSignature({
64
150
  rawBody,
@@ -82,7 +168,10 @@ type BetterZapEnv = {
82
168
  whatsapp: WhatsAppService;
83
169
  store: WhatsAppLogStore;
84
170
  logger: Logger;
171
+ coexistence?: CoexistenceService;
172
+ coexistenceStore?: CoexistenceStore;
173
+ subscribeWabaAfterCodeExchange?: boolean;
85
174
  };
86
175
  };
87
176
  //#endregion
88
- export { type BetterZap, type BetterZapApi, type BetterZapConfig, type BetterZapContext, type BetterZapCoreConfig, type BetterZapDatabase, type BetterZapEnv, type BetterZapPlugin, type BetterZapPluginInitContext, type BetterZapPluginInitResult, type BetterZapServices, type InferBetterZapPluginContext, type InferBetterZapPluginServices, type MessageContext, type StatusContext, type WebhookConfig, betterZap, createWebhookHandler, getMessageContent, verifyMetaWebhookSignature };
177
+ export { type BetterZap, type BetterZapApi, type BetterZapConfig, type BetterZapContext, type BetterZapCoreConfig, type BetterZapDatabase, type BetterZapEnv, type BetterZapPlugin, type BetterZapPluginInitContext, type BetterZapPluginInitResult, type BetterZapServices, type CoexistenceAccountOffboardedContext, type CoexistenceAccountReconnectedContext, type CoexistenceAccountUpdateContext, type CoexistenceHistoryContext, type CoexistenceMessageEditContext, type CoexistenceMessageRevokeContext, type CoexistenceUnsupportedMessageContext, type InferBetterZapPluginContext, type InferBetterZapPluginServices, type MessageContext, type SmbAppStateSyncContext, type SmbMessageEchoContext, type StatusContext, type WebhookConfig, betterZap, createWebhookHandler, getMessageContent, verifyMetaWebhookSignature };