waba-toolkit 0.1.1 → 0.1.3

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.ts CHANGED
@@ -533,14 +533,24 @@ interface ContactInfo {
533
533
  }
534
534
  /**
535
535
  * Extracts sender info from webhook payload.
536
- * Returns undefined if the webhook doesn't contain message contact info.
536
+ * Returns null if the webhook doesn't contain message contact info.
537
537
  */
538
- declare function getContactInfo(webhook: WebhookPayload): ContactInfo | undefined;
538
+ declare function getContactInfo(webhook: WebhookPayload): ContactInfo | null;
539
539
  /**
540
540
  * Parses message timestamp to Date object.
541
541
  * WhatsApp timestamps are Unix epoch seconds as strings.
542
542
  */
543
543
  declare function getMessageTimestamp(message: IncomingMessage): Date;
544
+ /**
545
+ * Extracts message ID from message or status webhook.
546
+ * Returns null if not a message/status webhook or ID not present.
547
+ */
548
+ declare function getMessageId(webhook: WebhookPayload): string | null;
549
+ /**
550
+ * Extracts call ID from call webhook.
551
+ * Returns null if not a call webhook or ID not present.
552
+ */
553
+ declare function getCallId(webhook: WebhookPayload): string | null;
544
554
 
545
555
  /** Base error class for all WABA errors */
546
556
  declare class WABAError extends Error {
@@ -563,4 +573,4 @@ declare class WABASignatureError extends WABAError {
563
573
  constructor(message?: string);
564
574
  }
565
575
 
566
- export { type AudioMessage, type ButtonMessage, type ButtonReply, type CallEntry, type CallWebhookValue, type ContactCard, type ContactInfo, type ContactsMessage, type ConversationObject, type DocumentMessage, type GetMediaOptions, type ImageMessage, type IncomingMessage, type IncomingMessageBase, type InteractiveMessage, type ListReply, type LocationMessage, type MediaBufferResult, type MediaMessage, type MediaMetadata, type MediaObject, type MediaStreamResult, type MessageClassification, type MessageContext, type MessageStatus, type MessageWebhookValue, type OrderMessage, type PricingObject, type ReactionMessage, type ReferralMessage, type StatusEntry, type StatusWebhookValue, type StickerMessage, type SystemMessage, type TextMessage, type UnsupportedMessage, type VerifyWebhookSignatureOptions, type VideoMessage, WABAClient, type WABAClientOptions, WABAError, WABAMediaError, WABANetworkError, WABASignatureError, type WebhookChange, type WebhookClassification, type WebhookContact, type WebhookEntry, type WebhookError, type WebhookMetadata, type WebhookPayload, type WebhookValue, classifyMessage, classifyWebhook, extractMediaId, getContactInfo, getMessageTimestamp, isMediaMessage, verifyWebhookSignature };
576
+ export { type AudioMessage, type ButtonMessage, type ButtonReply, type CallEntry, type CallWebhookValue, type ContactCard, type ContactInfo, type ContactsMessage, type ConversationObject, type DocumentMessage, type GetMediaOptions, type ImageMessage, type IncomingMessage, type IncomingMessageBase, type InteractiveMessage, type ListReply, type LocationMessage, type MediaBufferResult, type MediaMessage, type MediaMetadata, type MediaObject, type MediaStreamResult, type MessageClassification, type MessageContext, type MessageStatus, type MessageWebhookValue, type OrderMessage, type PricingObject, type ReactionMessage, type ReferralMessage, type StatusEntry, type StatusWebhookValue, type StickerMessage, type SystemMessage, type TextMessage, type UnsupportedMessage, type VerifyWebhookSignatureOptions, type VideoMessage, WABAClient, type WABAClientOptions, WABAError, WABAMediaError, WABANetworkError, WABASignatureError, type WebhookChange, type WebhookClassification, type WebhookContact, type WebhookEntry, type WebhookError, type WebhookMetadata, type WebhookPayload, type WebhookValue, classifyMessage, classifyWebhook, extractMediaId, getCallId, getContactInfo, getMessageId, getMessageTimestamp, isMediaMessage, verifyWebhookSignature };
package/dist/index.js CHANGED
@@ -249,7 +249,7 @@ function getContactInfo(webhook) {
249
249
  const change = entry?.changes?.[0];
250
250
  const value = change?.value;
251
251
  if (!value || !("contacts" in value) || !value.contacts?.length) {
252
- return void 0;
252
+ return null;
253
253
  }
254
254
  const contact = value.contacts[0];
255
255
  const metadata = value.metadata;
@@ -263,6 +263,36 @@ function getMessageTimestamp(message) {
263
263
  const epochSeconds = parseInt(message.timestamp, 10);
264
264
  return new Date(epochSeconds * 1e3);
265
265
  }
266
+ function getMessageId(webhook) {
267
+ const entry = webhook.entry?.[0];
268
+ const change = entry?.changes?.[0];
269
+ const value = change?.value;
270
+ if (!value) {
271
+ return null;
272
+ }
273
+ if ("messages" in value) {
274
+ const messageValue = value;
275
+ return messageValue.messages?.[0]?.id ?? null;
276
+ }
277
+ if ("statuses" in value) {
278
+ const statusValue = value;
279
+ return statusValue.statuses?.[0]?.id ?? null;
280
+ }
281
+ return null;
282
+ }
283
+ function getCallId(webhook) {
284
+ const entry = webhook.entry?.[0];
285
+ const change = entry?.changes?.[0];
286
+ const value = change?.value;
287
+ if (!value) {
288
+ return null;
289
+ }
290
+ if ("calls" in value) {
291
+ const callValue = value;
292
+ return callValue.calls?.[0]?.id ?? null;
293
+ }
294
+ return null;
295
+ }
266
296
  export {
267
297
  WABAClient,
268
298
  WABAError,
@@ -272,7 +302,9 @@ export {
272
302
  classifyMessage,
273
303
  classifyWebhook,
274
304
  extractMediaId,
305
+ getCallId,
275
306
  getContactInfo,
307
+ getMessageId,
276
308
  getMessageTimestamp,
277
309
  isMediaMessage,
278
310
  verifyWebhookSignature
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors.ts","../src/verify.ts","../src/client.ts","../src/webhooks/classify.ts","../src/webhooks/messages.ts","../src/helpers.ts"],"sourcesContent":["/** Base error class for all WABA errors */\nexport class WABAError extends Error {\n constructor(\n message: string,\n public readonly code?: number,\n public readonly details?: unknown\n ) {\n super(message);\n this.name = 'WABAError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Error for media-related failures (404, access denied) */\nexport class WABAMediaError extends WABAError {\n constructor(\n message: string,\n public readonly mediaId: string,\n code?: number\n ) {\n super(message, code);\n this.name = 'WABAMediaError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Error for network/connection failures */\nexport class WABANetworkError extends WABAError {\n override readonly cause?: Error;\n\n constructor(message: string, cause?: Error) {\n super(message);\n this.name = 'WABANetworkError';\n this.cause = cause;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Error for invalid webhook signatures */\nexport class WABASignatureError extends WABAError {\n constructor(message: string = 'Invalid webhook signature') {\n super(message);\n this.name = 'WABASignatureError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { createHmac, timingSafeEqual } from 'node:crypto';\nimport { WABASignatureError } from './errors.js';\n\nexport interface VerifyWebhookSignatureOptions {\n /** X-Hub-Signature-256 header value */\n signature: string | undefined;\n /** Raw request body (NOT parsed JSON) */\n rawBody: Buffer | string;\n /** Meta App Secret */\n appSecret: string | undefined;\n}\n\n/**\n * Verifies webhook signature using HMAC-SHA256.\n * Uses timing-safe comparison to prevent timing attacks.\n *\n * @throws {WABASignatureError} If appSecret is not provided\n * @returns true if signature is valid, false otherwise\n */\nexport function verifyWebhookSignature(\n options: VerifyWebhookSignatureOptions\n): boolean {\n const { signature, rawBody, appSecret } = options;\n\n if (!appSecret) {\n throw new WABASignatureError('appSecret is required for webhook verification');\n }\n\n if (!signature) {\n return false;\n }\n\n // Remove 'sha256=' prefix if present\n const signatureHash = signature.startsWith('sha256=')\n ? signature.slice(7)\n : signature;\n\n // Compute expected signature\n const hmac = createHmac('sha256', appSecret);\n const bodyBuffer =\n typeof rawBody === 'string' ? Buffer.from(rawBody, 'utf-8') : rawBody;\n const expectedHash = hmac.update(bodyBuffer).digest('hex');\n\n // Convert to buffers for timing-safe comparison\n const signatureBuffer = Buffer.from(signatureHash, 'utf-8');\n const expectedBuffer = Buffer.from(expectedHash, 'utf-8');\n\n // Ensure same length before comparison\n if (signatureBuffer.length !== expectedBuffer.length) {\n return false;\n }\n\n return timingSafeEqual(signatureBuffer, expectedBuffer);\n}\n","import type { WABAClientOptions, GetMediaOptions } from './types/client.js';\nimport type {\n MediaMetadata,\n MediaStreamResult,\n MediaBufferResult,\n RawMediaResponse,\n} from './types/media.js';\nimport { WABAMediaError, WABANetworkError, WABASignatureError } from './errors.js';\nimport { verifyWebhookSignature } from './verify.js';\n\nconst DEFAULT_API_VERSION = 'v22.0';\nconst DEFAULT_BASE_URL = 'https://graph.facebook.com';\n\n/**\n * Client for WhatsApp Business API media operations.\n */\nexport class WABAClient {\n private readonly accessToken: string;\n private readonly appSecret?: string;\n private readonly apiVersion: string;\n private readonly baseUrl: string;\n\n constructor(options: WABAClientOptions) {\n this.accessToken = options.accessToken;\n this.appSecret = options.appSecret;\n this.apiVersion = options.apiVersion ?? DEFAULT_API_VERSION;\n this.baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;\n }\n\n /**\n * Verifies webhook signature using HMAC-SHA256.\n * Requires appSecret to be set in constructor options.\n *\n * @throws {WABASignatureError} If appSecret was not provided in constructor\n * @returns true if signature is valid, false otherwise\n */\n verifyWebhook(signature: string | undefined, rawBody: Buffer | string): boolean {\n if (!this.appSecret) {\n throw new WABASignatureError(\n 'appSecret is required for webhook verification. Pass it in WABAClientOptions.'\n );\n }\n return verifyWebhookSignature({ signature, rawBody, appSecret: this.appSecret });\n }\n\n /**\n * Fetches media by ID from WhatsApp Business API.\n *\n * Step 1: GET /{apiVersion}/{mediaId} → retrieves temporary URL + metadata\n * Step 2: GET {temporaryUrl} → downloads binary content\n *\n * @throws {WABAMediaError} - Media not found (404) or access denied\n * @throws {WABANetworkError} - Network/connection failures\n */\n async getMedia(mediaId: string): Promise<MediaStreamResult>;\n async getMedia(\n mediaId: string,\n options: { asBuffer: true }\n ): Promise<MediaBufferResult>;\n async getMedia(\n mediaId: string,\n options?: GetMediaOptions\n ): Promise<MediaStreamResult | MediaBufferResult>;\n async getMedia(\n mediaId: string,\n options?: GetMediaOptions\n ): Promise<MediaStreamResult | MediaBufferResult> {\n // Step 1: Get media metadata and temporary URL\n const metadata = await this.fetchMediaMetadata(mediaId);\n\n // Step 2: Download the actual media\n const response = await this.downloadMedia(metadata.url, mediaId);\n\n if (options?.asBuffer) {\n const buffer = await response.arrayBuffer();\n return {\n ...metadata,\n buffer,\n };\n }\n\n if (!response.body) {\n throw new WABAMediaError('Response body is null', mediaId);\n }\n\n return {\n ...metadata,\n stream: response.body,\n };\n }\n\n private async fetchMediaMetadata(mediaId: string): Promise<MediaMetadata> {\n const url = `${this.baseUrl}/${this.apiVersion}/${mediaId}`;\n\n let response: Response;\n try {\n response = await fetch(url, {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${this.accessToken}`,\n },\n });\n } catch (error) {\n throw new WABANetworkError(\n `Failed to fetch media metadata: ${error instanceof Error ? error.message : 'Unknown error'}`,\n error instanceof Error ? error : undefined\n );\n }\n\n if (!response.ok) {\n const errorBody = await response.text().catch(() => 'Unknown error');\n throw new WABAMediaError(\n `Failed to fetch media metadata: ${response.status} ${errorBody}`,\n mediaId,\n response.status\n );\n }\n\n const data = (await response.json()) as RawMediaResponse;\n\n // Normalize snake_case to camelCase\n return {\n id: data.id,\n mimeType: data.mime_type,\n sha256: data.sha256,\n fileSize: parseInt(data.file_size, 10),\n url: data.url,\n };\n }\n\n private async downloadMedia(url: string, mediaId: string): Promise<Response> {\n let response: Response;\n try {\n response = await fetch(url, {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${this.accessToken}`,\n },\n });\n } catch (error) {\n throw new WABANetworkError(\n `Failed to download media: ${error instanceof Error ? error.message : 'Unknown error'}`,\n error instanceof Error ? error : undefined\n );\n }\n\n if (!response.ok) {\n throw new WABAMediaError(\n `Failed to download media: ${response.status}`,\n mediaId,\n response.status\n );\n }\n\n return response;\n }\n}\n","import type {\n WebhookPayload,\n WebhookClassification,\n MessageWebhookValue,\n StatusWebhookValue,\n CallWebhookValue,\n} from '../types/webhooks.js';\n\n/**\n * Classifies a webhook payload into its type.\n * Returns a discriminated union for type-safe handling.\n */\nexport function classifyWebhook(payload: WebhookPayload): WebhookClassification {\n const entry = payload.entry?.[0];\n const change = entry?.changes?.[0];\n const value = change?.value;\n\n if (!value) {\n return { type: 'unknown', payload };\n }\n\n // Check for calls array (call webhooks)\n if ('calls' in value && Array.isArray(value.calls)) {\n return { type: 'call', payload: value as CallWebhookValue };\n }\n\n // Check for statuses array (status webhooks)\n if ('statuses' in value && Array.isArray(value.statuses)) {\n return { type: 'status', payload: value as StatusWebhookValue };\n }\n\n // Check for messages array (message webhooks)\n if ('messages' in value && Array.isArray(value.messages)) {\n return { type: 'message', payload: value as MessageWebhookValue };\n }\n\n // Check for errors without messages (error webhook)\n if ('errors' in value && Array.isArray(value.errors)) {\n return { type: 'message', payload: value as MessageWebhookValue };\n }\n\n return { type: 'unknown', payload };\n}\n","import type {\n IncomingMessage,\n MessageClassification,\n TextMessage,\n ImageMessage,\n AudioMessage,\n VideoMessage,\n DocumentMessage,\n StickerMessage,\n LocationMessage,\n ContactsMessage,\n InteractiveMessage,\n ReactionMessage,\n ButtonMessage,\n OrderMessage,\n SystemMessage,\n ReferralMessage,\n UnsupportedMessage,\n} from '../types/messages.js';\n\n/**\n * Classifies an incoming message by its type.\n * Returns a discriminated union for type-safe handling.\n */\nexport function classifyMessage(message: IncomingMessage): MessageClassification {\n switch (message.type) {\n case 'text':\n return { type: 'text', message: message as TextMessage };\n case 'image':\n return { type: 'image', message: message as ImageMessage };\n case 'audio':\n return { type: 'audio', message: message as AudioMessage };\n case 'video':\n return { type: 'video', message: message as VideoMessage };\n case 'document':\n return { type: 'document', message: message as DocumentMessage };\n case 'sticker':\n return { type: 'sticker', message: message as StickerMessage };\n case 'location':\n return { type: 'location', message: message as LocationMessage };\n case 'contacts':\n return { type: 'contacts', message: message as ContactsMessage };\n case 'interactive':\n return { type: 'interactive', message: message as InteractiveMessage };\n case 'reaction':\n return { type: 'reaction', message: message as ReactionMessage };\n case 'button':\n return { type: 'button', message: message as ButtonMessage };\n case 'order':\n return { type: 'order', message: message as OrderMessage };\n case 'system':\n return { type: 'system', message: message as SystemMessage };\n case 'referral':\n return { type: 'referral', message: message as ReferralMessage };\n default:\n return { type: 'unsupported', message: message as UnsupportedMessage };\n }\n}\n","import type {\n IncomingMessage,\n MediaMessage,\n ImageMessage,\n AudioMessage,\n VideoMessage,\n DocumentMessage,\n StickerMessage,\n} from './types/messages.js';\nimport type { WebhookPayload } from './types/webhooks.js';\n\nconst MEDIA_TYPES = new Set(['image', 'audio', 'video', 'document', 'sticker']);\n\n/**\n * Type guard: returns true if message contains downloadable media.\n * Narrows type to messages with image/audio/video/document/sticker.\n */\nexport function isMediaMessage(message: IncomingMessage): message is MediaMessage {\n return MEDIA_TYPES.has(message.type);\n}\n\n/**\n * Extracts media ID from any media message type.\n * Returns undefined if message has no media.\n */\nexport function extractMediaId(message: IncomingMessage): string | undefined {\n if (!isMediaMessage(message)) {\n return undefined;\n }\n\n switch (message.type) {\n case 'image':\n return (message as ImageMessage).image.id;\n case 'audio':\n return (message as AudioMessage).audio.id;\n case 'video':\n return (message as VideoMessage).video.id;\n case 'document':\n return (message as DocumentMessage).document.id;\n case 'sticker':\n return (message as StickerMessage).sticker.id;\n default:\n return undefined;\n }\n}\n\nexport interface ContactInfo {\n waId: string;\n profileName: string | undefined;\n phoneNumberId: string;\n}\n\n/**\n * Extracts sender info from webhook payload.\n * Returns undefined if the webhook doesn't contain message contact info.\n */\nexport function getContactInfo(webhook: WebhookPayload): ContactInfo | undefined {\n const entry = webhook.entry?.[0];\n const change = entry?.changes?.[0];\n const value = change?.value;\n\n if (!value || !('contacts' in value) || !value.contacts?.length) {\n return undefined;\n }\n\n const contact = value.contacts[0];\n const metadata = value.metadata;\n\n return {\n waId: contact.wa_id,\n profileName: contact.profile?.name,\n phoneNumberId: metadata.phone_number_id,\n };\n}\n\n/**\n * Parses message timestamp to Date object.\n * WhatsApp timestamps are Unix epoch seconds as strings.\n */\nexport function getMessageTimestamp(message: IncomingMessage): Date {\n const epochSeconds = parseInt(message.timestamp, 10);\n return new Date(epochSeconds * 1000);\n}\n"],"mappings":";AACO,IAAM,YAAN,cAAwB,MAAM;AAAA,EACnC,YACE,SACgB,MACA,SAChB;AACA,UAAM,OAAO;AAHG;AACA;AAGhB,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,WAAW,SAAS;AAAA,EAClD;AACF;AAGO,IAAM,iBAAN,cAA6B,UAAU;AAAA,EAC5C,YACE,SACgB,SAChB,MACA;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oBAAI,IAAI,CAAC,SAAS,SAAS,SAAS,YAAY,SAAS,CAAC;AAMvE,SAAS,eAAe,SAAmD;AAChF,SAAO,YAAY,IAAI,QAAQ,IAAI;AACrC;AAMO,SAAS,eAAe,SAA8C;AAC3E,MAAI,CAAC,eAAe,OAAO,GAAG;AAC5B,WAAO;AAAA,EACT;AAEA,UAAQ,QAAQ,MAAM;AAAA,IACpB,KAAK;AACH,aAAQ,QAAyB,MAAM;AAAA,IACzC,KAAK;AACH,aAAQ,QAAyB,MAAM;AAAA,IACzC,KAAK;AACH,aAAQ,QAAyB,MAAM;AAAA,IACzC,KAAK;AACH,aAAQ,QAA4B,SAAS;AAAA,IAC/C,KAAK;AACH,aAAQ,QAA2B,QAAQ;AAAA,IAC7C;AACE,aAAO;AAAA,EACX;AACF;AAYO,SAAS,eAAe,SAAkD;AAC/E,QAAM,QAAQ,QAAQ,QAAQ,CAAC;AAC/B,QAAM,SAAS,OAAO,UAAU,CAAC;AACjC,QAAM,QAAQ,QAAQ;AAEtB,MAAI,CAAC,SAAS,EAAE,cAAc,UAAU,CAAC,MAAM,UAAU,QAAQ;AAC/D,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,MAAM,SAAS,CAAC;AAChC,QAAM,WAAW,MAAM;AAEvB,SAAO;AAAA,IACL,MAAM,QAAQ;AAAA,IACd,aAAa,QAAQ,SAAS;AAAA,IAC9B,eAAe,SAAS;AAAA,EAC1B;AACF;AAMO,SAAS,oBAAoB,SAAgC;AAClE,QAAM,eAAe,SAAS,QAAQ,WAAW,EAAE;AACnD,SAAO,IAAI,KAAK,eAAe,GAAI;AACrC;","names":[]}
1
+ {"version":3,"sources":["../src/errors.ts","../src/verify.ts","../src/client.ts","../src/webhooks/classify.ts","../src/webhooks/messages.ts","../src/helpers.ts"],"sourcesContent":["/** Base error class for all WABA errors */\nexport class WABAError extends Error {\n constructor(\n message: string,\n public readonly code?: number,\n public readonly details?: unknown\n ) {\n super(message);\n this.name = 'WABAError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Error for media-related failures (404, access denied) */\nexport class WABAMediaError extends WABAError {\n constructor(\n message: string,\n public readonly mediaId: string,\n code?: number\n ) {\n super(message, code);\n this.name = 'WABAMediaError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Error for network/connection failures */\nexport class WABANetworkError extends WABAError {\n override readonly cause?: Error;\n\n constructor(message: string, cause?: Error) {\n super(message);\n this.name = 'WABANetworkError';\n this.cause = cause;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Error for invalid webhook signatures */\nexport class WABASignatureError extends WABAError {\n constructor(message: string = 'Invalid webhook signature') {\n super(message);\n this.name = 'WABASignatureError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { createHmac, timingSafeEqual } from 'node:crypto';\nimport { WABASignatureError } from './errors.js';\n\nexport interface VerifyWebhookSignatureOptions {\n /** X-Hub-Signature-256 header value */\n signature: string | undefined;\n /** Raw request body (NOT parsed JSON) */\n rawBody: Buffer | string;\n /** Meta App Secret */\n appSecret: string | undefined;\n}\n\n/**\n * Verifies webhook signature using HMAC-SHA256.\n * Uses timing-safe comparison to prevent timing attacks.\n *\n * @throws {WABASignatureError} If appSecret is not provided\n * @returns true if signature is valid, false otherwise\n */\nexport function verifyWebhookSignature(\n options: VerifyWebhookSignatureOptions\n): boolean {\n const { signature, rawBody, appSecret } = options;\n\n if (!appSecret) {\n throw new WABASignatureError('appSecret is required for webhook verification');\n }\n\n if (!signature) {\n return false;\n }\n\n // Remove 'sha256=' prefix if present\n const signatureHash = signature.startsWith('sha256=')\n ? signature.slice(7)\n : signature;\n\n // Compute expected signature\n const hmac = createHmac('sha256', appSecret);\n const bodyBuffer =\n typeof rawBody === 'string' ? Buffer.from(rawBody, 'utf-8') : rawBody;\n const expectedHash = hmac.update(bodyBuffer).digest('hex');\n\n // Convert to buffers for timing-safe comparison\n const signatureBuffer = Buffer.from(signatureHash, 'utf-8');\n const expectedBuffer = Buffer.from(expectedHash, 'utf-8');\n\n // Ensure same length before comparison\n if (signatureBuffer.length !== expectedBuffer.length) {\n return false;\n }\n\n return timingSafeEqual(signatureBuffer, expectedBuffer);\n}\n","import type { WABAClientOptions, GetMediaOptions } from './types/client.js';\nimport type {\n MediaMetadata,\n MediaStreamResult,\n MediaBufferResult,\n RawMediaResponse,\n} from './types/media.js';\nimport { WABAMediaError, WABANetworkError, WABASignatureError } from './errors.js';\nimport { verifyWebhookSignature } from './verify.js';\n\nconst DEFAULT_API_VERSION = 'v22.0';\nconst DEFAULT_BASE_URL = 'https://graph.facebook.com';\n\n/**\n * Client for WhatsApp Business API media operations.\n */\nexport class WABAClient {\n private readonly accessToken: string;\n private readonly appSecret?: string;\n private readonly apiVersion: string;\n private readonly baseUrl: string;\n\n constructor(options: WABAClientOptions) {\n this.accessToken = options.accessToken;\n this.appSecret = options.appSecret;\n this.apiVersion = options.apiVersion ?? DEFAULT_API_VERSION;\n this.baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;\n }\n\n /**\n * Verifies webhook signature using HMAC-SHA256.\n * Requires appSecret to be set in constructor options.\n *\n * @throws {WABASignatureError} If appSecret was not provided in constructor\n * @returns true if signature is valid, false otherwise\n */\n verifyWebhook(signature: string | undefined, rawBody: Buffer | string): boolean {\n if (!this.appSecret) {\n throw new WABASignatureError(\n 'appSecret is required for webhook verification. Pass it in WABAClientOptions.'\n );\n }\n return verifyWebhookSignature({ signature, rawBody, appSecret: this.appSecret });\n }\n\n /**\n * Fetches media by ID from WhatsApp Business API.\n *\n * Step 1: GET /{apiVersion}/{mediaId} → retrieves temporary URL + metadata\n * Step 2: GET {temporaryUrl} → downloads binary content\n *\n * @throws {WABAMediaError} - Media not found (404) or access denied\n * @throws {WABANetworkError} - Network/connection failures\n */\n async getMedia(mediaId: string): Promise<MediaStreamResult>;\n async getMedia(\n mediaId: string,\n options: { asBuffer: true }\n ): Promise<MediaBufferResult>;\n async getMedia(\n mediaId: string,\n options?: GetMediaOptions\n ): Promise<MediaStreamResult | MediaBufferResult>;\n async getMedia(\n mediaId: string,\n options?: GetMediaOptions\n ): Promise<MediaStreamResult | MediaBufferResult> {\n // Step 1: Get media metadata and temporary URL\n const metadata = await this.fetchMediaMetadata(mediaId);\n\n // Step 2: Download the actual media\n const response = await this.downloadMedia(metadata.url, mediaId);\n\n if (options?.asBuffer) {\n const buffer = await response.arrayBuffer();\n return {\n ...metadata,\n buffer,\n };\n }\n\n if (!response.body) {\n throw new WABAMediaError('Response body is null', mediaId);\n }\n\n return {\n ...metadata,\n stream: response.body,\n };\n }\n\n private async fetchMediaMetadata(mediaId: string): Promise<MediaMetadata> {\n const url = `${this.baseUrl}/${this.apiVersion}/${mediaId}`;\n\n let response: Response;\n try {\n response = await fetch(url, {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${this.accessToken}`,\n },\n });\n } catch (error) {\n throw new WABANetworkError(\n `Failed to fetch media metadata: ${error instanceof Error ? error.message : 'Unknown error'}`,\n error instanceof Error ? error : undefined\n );\n }\n\n if (!response.ok) {\n const errorBody = await response.text().catch(() => 'Unknown error');\n throw new WABAMediaError(\n `Failed to fetch media metadata: ${response.status} ${errorBody}`,\n mediaId,\n response.status\n );\n }\n\n const data = (await response.json()) as RawMediaResponse;\n\n // Normalize snake_case to camelCase\n return {\n id: data.id,\n mimeType: data.mime_type,\n sha256: data.sha256,\n fileSize: parseInt(data.file_size, 10),\n url: data.url,\n };\n }\n\n private async downloadMedia(url: string, mediaId: string): Promise<Response> {\n let response: Response;\n try {\n response = await fetch(url, {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${this.accessToken}`,\n },\n });\n } catch (error) {\n throw new WABANetworkError(\n `Failed to download media: ${error instanceof Error ? error.message : 'Unknown error'}`,\n error instanceof Error ? error : undefined\n );\n }\n\n if (!response.ok) {\n throw new WABAMediaError(\n `Failed to download media: ${response.status}`,\n mediaId,\n response.status\n );\n }\n\n return response;\n }\n}\n","import type {\n WebhookPayload,\n WebhookClassification,\n MessageWebhookValue,\n StatusWebhookValue,\n CallWebhookValue,\n} from '../types/webhooks.js';\n\n/**\n * Classifies a webhook payload into its type.\n * Returns a discriminated union for type-safe handling.\n */\nexport function classifyWebhook(payload: WebhookPayload): WebhookClassification {\n const entry = payload.entry?.[0];\n const change = entry?.changes?.[0];\n const value = change?.value;\n\n if (!value) {\n return { type: 'unknown', payload };\n }\n\n // Check for calls array (call webhooks)\n if ('calls' in value && Array.isArray(value.calls)) {\n return { type: 'call', payload: value as CallWebhookValue };\n }\n\n // Check for statuses array (status webhooks)\n if ('statuses' in value && Array.isArray(value.statuses)) {\n return { type: 'status', payload: value as StatusWebhookValue };\n }\n\n // Check for messages array (message webhooks)\n if ('messages' in value && Array.isArray(value.messages)) {\n return { type: 'message', payload: value as MessageWebhookValue };\n }\n\n // Check for errors without messages (error webhook)\n if ('errors' in value && Array.isArray(value.errors)) {\n return { type: 'message', payload: value as MessageWebhookValue };\n }\n\n return { type: 'unknown', payload };\n}\n","import type {\n IncomingMessage,\n MessageClassification,\n TextMessage,\n ImageMessage,\n AudioMessage,\n VideoMessage,\n DocumentMessage,\n StickerMessage,\n LocationMessage,\n ContactsMessage,\n InteractiveMessage,\n ReactionMessage,\n ButtonMessage,\n OrderMessage,\n SystemMessage,\n ReferralMessage,\n UnsupportedMessage,\n} from '../types/messages.js';\n\n/**\n * Classifies an incoming message by its type.\n * Returns a discriminated union for type-safe handling.\n */\nexport function classifyMessage(message: IncomingMessage): MessageClassification {\n switch (message.type) {\n case 'text':\n return { type: 'text', message: message as TextMessage };\n case 'image':\n return { type: 'image', message: message as ImageMessage };\n case 'audio':\n return { type: 'audio', message: message as AudioMessage };\n case 'video':\n return { type: 'video', message: message as VideoMessage };\n case 'document':\n return { type: 'document', message: message as DocumentMessage };\n case 'sticker':\n return { type: 'sticker', message: message as StickerMessage };\n case 'location':\n return { type: 'location', message: message as LocationMessage };\n case 'contacts':\n return { type: 'contacts', message: message as ContactsMessage };\n case 'interactive':\n return { type: 'interactive', message: message as InteractiveMessage };\n case 'reaction':\n return { type: 'reaction', message: message as ReactionMessage };\n case 'button':\n return { type: 'button', message: message as ButtonMessage };\n case 'order':\n return { type: 'order', message: message as OrderMessage };\n case 'system':\n return { type: 'system', message: message as SystemMessage };\n case 'referral':\n return { type: 'referral', message: message as ReferralMessage };\n default:\n return { type: 'unsupported', message: message as UnsupportedMessage };\n }\n}\n","import type {\n IncomingMessage,\n MediaMessage,\n ImageMessage,\n AudioMessage,\n VideoMessage,\n DocumentMessage,\n StickerMessage,\n} from './types/messages.js';\nimport type {\n WebhookPayload,\n MessageWebhookValue,\n StatusWebhookValue,\n CallWebhookValue,\n} from './types/webhooks.js';\n\nconst MEDIA_TYPES = new Set(['image', 'audio', 'video', 'document', 'sticker']);\n\n/**\n * Type guard: returns true if message contains downloadable media.\n * Narrows type to messages with image/audio/video/document/sticker.\n */\nexport function isMediaMessage(message: IncomingMessage): message is MediaMessage {\n return MEDIA_TYPES.has(message.type);\n}\n\n/**\n * Extracts media ID from any media message type.\n * Returns undefined if message has no media.\n */\nexport function extractMediaId(message: IncomingMessage): string | undefined {\n if (!isMediaMessage(message)) {\n return undefined;\n }\n\n switch (message.type) {\n case 'image':\n return (message as ImageMessage).image.id;\n case 'audio':\n return (message as AudioMessage).audio.id;\n case 'video':\n return (message as VideoMessage).video.id;\n case 'document':\n return (message as DocumentMessage).document.id;\n case 'sticker':\n return (message as StickerMessage).sticker.id;\n default:\n return undefined;\n }\n}\n\nexport interface ContactInfo {\n waId: string;\n profileName: string | undefined;\n phoneNumberId: string;\n}\n\n/**\n * Extracts sender info from webhook payload.\n * Returns null if the webhook doesn't contain message contact info.\n */\nexport function getContactInfo(webhook: WebhookPayload): ContactInfo | null {\n const entry = webhook.entry?.[0];\n const change = entry?.changes?.[0];\n const value = change?.value;\n\n if (!value || !('contacts' in value) || !value.contacts?.length) {\n return null;\n }\n\n const contact = value.contacts[0];\n const metadata = value.metadata;\n\n return {\n waId: contact.wa_id,\n profileName: contact.profile?.name,\n phoneNumberId: metadata.phone_number_id,\n };\n}\n\n/**\n * Parses message timestamp to Date object.\n * WhatsApp timestamps are Unix epoch seconds as strings.\n */\nexport function getMessageTimestamp(message: IncomingMessage): Date {\n const epochSeconds = parseInt(message.timestamp, 10);\n return new Date(epochSeconds * 1000);\n}\n\n/**\n * Extracts message ID from message or status webhook.\n * Returns null if not a message/status webhook or ID not present.\n */\nexport function getMessageId(webhook: WebhookPayload): string | null {\n const entry = webhook.entry?.[0];\n const change = entry?.changes?.[0];\n const value = change?.value;\n\n if (!value) {\n return null;\n }\n\n // Try message webhook\n if ('messages' in value) {\n const messageValue = value as MessageWebhookValue;\n return messageValue.messages?.[0]?.id ?? null;\n }\n\n // Try status webhook\n if ('statuses' in value) {\n const statusValue = value as StatusWebhookValue;\n return statusValue.statuses?.[0]?.id ?? null;\n }\n\n return null;\n}\n\n/**\n * Extracts call ID from call webhook.\n * Returns null if not a call webhook or ID not present.\n */\nexport function getCallId(webhook: WebhookPayload): string | null {\n const entry = webhook.entry?.[0];\n const change = entry?.changes?.[0];\n const value = change?.value;\n\n if (!value) {\n return null;\n }\n\n // Check if it's a call webhook\n if ('calls' in value) {\n const callValue = value as CallWebhookValue;\n return callValue.calls?.[0]?.id ?? null;\n }\n\n return null;\n}\n"],"mappings":";AACO,IAAM,YAAN,cAAwB,MAAM;AAAA,EACnC,YACE,SACgB,MACA,SAChB;AACA,UAAM,OAAO;AAHG;AACA;AAGhB,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,WAAW,SAAS;AAAA,EAClD;AACF;AAGO,IAAM,iBAAN,cAA6B,UAAU;AAAA,EAC5C,YACE,SACgB,SAChB,MACA;AACA,UAAM,SAAS,IAAI;AAHH;AAIhB,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,WAAW,SAAS;AAAA,EAClD;AACF;AAGO,IAAM,mBAAN,cAA+B,UAAU;AAAA,EAC5B;AAAA,EAElB,YAAY,SAAiB,OAAe;AAC1C,UAAM,OAAO;AACb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,QAAQ,QAAQ,CAAC;AAC/B,QAAM,SAAS,OAAO,UAAU,CAAC;AACjC,QAAM,QAAQ,QAAQ;AAEtB,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAGA,MAAI,WAAW,OAAO;AACpB,UAAM,YAAY;AAClB,WAAO,UAAU,QAAQ,CAAC,GAAG,MAAM;AAAA,EACrC;AAEA,SAAO;AACT;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "waba-toolkit",
3
- "version": "0.1.1",
4
- "description": "Minimal, type-safe toolkit for WhatsApp Business API webhook processing and media handling",
3
+ "version": "0.1.3",
4
+ "description": "Type-safe, zero-dependency WhatsApp Business API toolkit for webhooks, media downloads, and signature verification",
5
5
  "type": "module",
6
6
  "engines": {
7
7
  "node": ">=20.0.0"
@@ -26,14 +26,26 @@
26
26
  "whatsapp",
27
27
  "waba",
28
28
  "whatsapp-business-api",
29
+ "whatsapp-cloud-api",
29
30
  "webhook",
30
- "meta"
31
+ "meta",
32
+ "cloud-api",
33
+ "messaging",
34
+ "typescript"
31
35
  ],
36
+ "homepage": "https://github.com/teknicus/waba-toolkit",
37
+ "bugs": {
38
+ "url": "https://github.com/teknicus/waba-toolkit/issues"
39
+ },
32
40
  "license": "MIT",
33
41
  "devDependencies": {
34
42
  "@types/node": "^25.0.3",
35
43
  "tsup": "^8.0.0",
36
44
  "typescript": "^5.0.0",
37
45
  "vitest": "^4.0.16"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/teknicus/waba-toolkit.git"
38
50
  }
39
51
  }