@better-zap/hono 0.2.0 → 0.2.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/dist/index.cjs +1458 -0
- package/dist/index.d.cts +177 -0
- package/dist/index.d.mts +177 -0
- package/dist/index.mjs +1454 -0
- package/package.json +17 -8
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
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
|
+
import { Hono } from "hono";
|
|
3
|
+
|
|
4
|
+
//#region src/webhook/create-webhook-handler.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for {@link createWebhookHandler}.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam Env - Hono bindings type (e.g. Cloudflare Worker env).
|
|
9
|
+
*/
|
|
10
|
+
type WebhookConfig = {
|
|
11
|
+
/** Token for the Meta verification challenge (`GET /webhook`). */verifyToken: string; /** App secret used for HMAC-SHA256 signature verification. */
|
|
12
|
+
appSecret: string; /** logger for automatic message storage. */
|
|
13
|
+
logger: MessageLoggerService; /** Structured logger for operational logging. */
|
|
14
|
+
log: Logger; /** Optional database contracts used for automatic coexistence persistence. */
|
|
15
|
+
database?: BetterZapDatabase$1; /** Called once per incoming message, after SDK pre-processing. */
|
|
16
|
+
onMessage: (ctx: MessageContext$1) => Promise<void>; /** Called once per delivery status update (sent → delivered → read → failed). */
|
|
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>;
|
|
27
|
+
/**
|
|
28
|
+
* Called for Meta platform-level errors.
|
|
29
|
+
* @default Uses the configured {@link WebhookConfig.log} logger's {@code error} method.
|
|
30
|
+
*/
|
|
31
|
+
onError?: (error: WebhookError) => void;
|
|
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
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Creates a Hono router that handles the full WhatsApp webhook lifecycle.
|
|
80
|
+
*
|
|
81
|
+
* **SDK guarantees (non-hookable):**
|
|
82
|
+
* - Signature is always verified before any processing
|
|
83
|
+
* - Meta always receives a fast 200 OK (processing runs via `waitUntil`)
|
|
84
|
+
* - Hook errors never crash the webhook (wrapped in try/catch)
|
|
85
|
+
* - Contact is resolved and content is extracted before `onMessage`
|
|
86
|
+
* - Status timestamp is parsed to ISO before `onStatusUpdate`
|
|
87
|
+
*
|
|
88
|
+
* @typeParam Env - Hono bindings type (e.g. Cloudflare Worker env).
|
|
89
|
+
*/
|
|
90
|
+
declare function createWebhookHandler(config: WebhookConfig): Hono<{
|
|
91
|
+
Bindings: Record<string, any>;
|
|
92
|
+
}>;
|
|
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
|
|
148
|
+
//#region src/webhook/signature-verification.d.ts
|
|
149
|
+
declare function verifyMetaWebhookSignature({
|
|
150
|
+
rawBody,
|
|
151
|
+
signatureHeader,
|
|
152
|
+
appSecret
|
|
153
|
+
}: {
|
|
154
|
+
rawBody: ArrayBuffer;
|
|
155
|
+
signatureHeader: string | undefined;
|
|
156
|
+
appSecret: string;
|
|
157
|
+
}): Promise<boolean>;
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/webhook/message-content.d.ts
|
|
160
|
+
/**
|
|
161
|
+
* Extract human-readable content from incoming messages for audit logs.
|
|
162
|
+
*/
|
|
163
|
+
declare function getMessageContent(message: IncomingMessage): string;
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/handler/types.d.ts
|
|
166
|
+
type BetterZapEnv = {
|
|
167
|
+
Variables: {
|
|
168
|
+
whatsapp: WhatsAppService;
|
|
169
|
+
store: WhatsAppLogStore;
|
|
170
|
+
logger: Logger;
|
|
171
|
+
coexistence?: CoexistenceService;
|
|
172
|
+
coexistenceStore?: CoexistenceStore;
|
|
173
|
+
subscribeWabaAfterCodeExchange?: boolean;
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
//#endregion
|
|
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
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
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, 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
|
+
|
|
4
|
+
//#region src/webhook/create-webhook-handler.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for {@link createWebhookHandler}.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam Env - Hono bindings type (e.g. Cloudflare Worker env).
|
|
9
|
+
*/
|
|
10
|
+
type WebhookConfig = {
|
|
11
|
+
/** Token for the Meta verification challenge (`GET /webhook`). */verifyToken: string; /** App secret used for HMAC-SHA256 signature verification. */
|
|
12
|
+
appSecret: string; /** logger for automatic message storage. */
|
|
13
|
+
logger: MessageLoggerService; /** Structured logger for operational logging. */
|
|
14
|
+
log: Logger; /** Optional database contracts used for automatic coexistence persistence. */
|
|
15
|
+
database?: BetterZapDatabase$1; /** Called once per incoming message, after SDK pre-processing. */
|
|
16
|
+
onMessage: (ctx: MessageContext$1) => Promise<void>; /** Called once per delivery status update (sent → delivered → read → failed). */
|
|
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>;
|
|
27
|
+
/**
|
|
28
|
+
* Called for Meta platform-level errors.
|
|
29
|
+
* @default Uses the configured {@link WebhookConfig.log} logger's {@code error} method.
|
|
30
|
+
*/
|
|
31
|
+
onError?: (error: WebhookError) => void;
|
|
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
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Creates a Hono router that handles the full WhatsApp webhook lifecycle.
|
|
80
|
+
*
|
|
81
|
+
* **SDK guarantees (non-hookable):**
|
|
82
|
+
* - Signature is always verified before any processing
|
|
83
|
+
* - Meta always receives a fast 200 OK (processing runs via `waitUntil`)
|
|
84
|
+
* - Hook errors never crash the webhook (wrapped in try/catch)
|
|
85
|
+
* - Contact is resolved and content is extracted before `onMessage`
|
|
86
|
+
* - Status timestamp is parsed to ISO before `onStatusUpdate`
|
|
87
|
+
*
|
|
88
|
+
* @typeParam Env - Hono bindings type (e.g. Cloudflare Worker env).
|
|
89
|
+
*/
|
|
90
|
+
declare function createWebhookHandler(config: WebhookConfig): Hono<{
|
|
91
|
+
Bindings: Record<string, any>;
|
|
92
|
+
}>;
|
|
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
|
|
148
|
+
//#region src/webhook/signature-verification.d.ts
|
|
149
|
+
declare function verifyMetaWebhookSignature({
|
|
150
|
+
rawBody,
|
|
151
|
+
signatureHeader,
|
|
152
|
+
appSecret
|
|
153
|
+
}: {
|
|
154
|
+
rawBody: ArrayBuffer;
|
|
155
|
+
signatureHeader: string | undefined;
|
|
156
|
+
appSecret: string;
|
|
157
|
+
}): Promise<boolean>;
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/webhook/message-content.d.ts
|
|
160
|
+
/**
|
|
161
|
+
* Extract human-readable content from incoming messages for audit logs.
|
|
162
|
+
*/
|
|
163
|
+
declare function getMessageContent(message: IncomingMessage): string;
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/handler/types.d.ts
|
|
166
|
+
type BetterZapEnv = {
|
|
167
|
+
Variables: {
|
|
168
|
+
whatsapp: WhatsAppService;
|
|
169
|
+
store: WhatsAppLogStore;
|
|
170
|
+
logger: Logger;
|
|
171
|
+
coexistence?: CoexistenceService;
|
|
172
|
+
coexistenceStore?: CoexistenceStore;
|
|
173
|
+
subscribeWabaAfterCodeExchange?: boolean;
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
//#endregion
|
|
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 };
|