meta-cloud-api 1.0.3 → 1.1.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/{BusinessProfileApi-WXscSgo-.d.ts → BusinessProfileApi-CW0emncx.d.ts} +1 -1
- package/dist/{EncryptionApi-D7pt-OXT.d.ts → EncryptionApi-Dyea0SR3.d.ts} +1 -1
- package/dist/{FlowApi-B2ffO-HD.d.ts → FlowApi-DvoT7ivY.d.ts} +1 -1
- package/dist/{MessageApi-BgsSpDno.d.ts → MessageApi-D-9SuL4w.d.ts} +1 -1
- package/dist/{TemplateApi-xGgIZt89.d.ts → TemplateApi-D4_6LvhN.d.ts} +1 -1
- package/dist/{WabaApi-DqQi_68m.d.ts → WabaApi-BvY1JVRH.d.ts} +1 -1
- package/dist/{WebhookProcessor-BXYunz4N.d.ts → WebhookProcessor-CE4xBPe0.d.ts} +2 -2
- package/dist/{WhatsApp-pTZPQm81.d.ts → WhatsApp-iAly_4pr.d.ts} +6 -6
- package/dist/api/encryption/index.d.ts +2 -2
- package/dist/api/flow/index.d.ts +3 -2
- package/dist/api/flow/index.js +1 -1
- package/dist/api/index.d.ts +9 -8
- package/dist/api/index.js +1 -1
- package/dist/api/messages/builders/index.d.ts +1 -1
- package/dist/api/messages/index.d.ts +2 -2
- package/dist/api/profile/index.d.ts +2 -2
- package/dist/api/template/index.d.ts +6 -200
- package/dist/api/waba/index.d.ts +2 -2
- package/dist/chunk-5577QQ7V.js +2 -0
- package/dist/chunk-5577QQ7V.js.map +1 -0
- package/dist/{chunk-WGGN32O2.js → chunk-6DFC5L3X.js} +2 -2
- package/dist/chunk-6DFC5L3X.js.map +1 -0
- package/dist/chunk-GM63NGNV.js +2 -0
- package/dist/chunk-GM63NGNV.js.map +1 -0
- package/dist/chunk-J2JPTKU6.js +2 -0
- package/dist/chunk-J2JPTKU6.js.map +1 -0
- package/dist/{chunk-JPGXONBQ.js → chunk-U5FBZ6UB.js} +3 -3
- package/dist/{chunk-JPGXONBQ.js.map → chunk-U5FBZ6UB.js.map} +1 -1
- package/dist/chunk-ZMNXRMWK.js +2 -0
- package/dist/chunk-ZMNXRMWK.js.map +1 -0
- package/dist/{common-BiRA_uz3.d.ts → common-CzzMWFoO.d.ts} +1 -1
- package/dist/{common-lV0NsO7t.d.ts → common-nVoO5ROn.d.ts} +28 -1
- package/dist/core/webhook/frameworks/express.d.ts +20 -16
- package/dist/core/webhook/frameworks/express.js +1 -1
- package/dist/core/webhook/frameworks/nextjs-app.d.ts +48 -0
- package/dist/core/webhook/frameworks/nextjs-app.js +2 -0
- package/dist/core/webhook/frameworks/nextjs-app.js.map +1 -0
- package/dist/core/webhook/frameworks/nextjs.d.ts +18 -14
- package/dist/core/webhook/frameworks/nextjs.js +1 -1
- package/dist/core/webhook/index.d.ts +12 -10
- package/dist/core/webhook/index.js +1 -1
- package/dist/core/whatsapp/index.d.ts +10 -9
- package/dist/core/whatsapp/index.js +1 -1
- package/dist/factory-D2eO5etK.d.ts +200 -0
- package/dist/handler-DbySwF0E.d.ts +20 -0
- package/dist/index.d.ts +20 -17
- package/dist/index.js +1 -1
- package/dist/{isMetaError-CXWJwW58.d.ts → isMetaError-CLqzdSws.d.ts} +1 -1
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/index.js +1 -1
- package/package.json +59 -76
- package/dist/chunk-NLF2JGYY.js +0 -2
- package/dist/chunk-NLF2JGYY.js.map +0 -1
- package/dist/chunk-NOJFGTRT.js +0 -2
- package/dist/chunk-NOJFGTRT.js.map +0 -1
- package/dist/chunk-WGGN32O2.js.map +0 -1
- package/dist/chunk-YXZ4L2OK.js +0 -2
- package/dist/chunk-YXZ4L2OK.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/webhook/utils/webhookUtils.ts","../src/core/webhook/WebhookProcessor.ts"],"names":["LIB_NAME","LOGGER","Logger","processWebhookMessages","request","whatsapp","handlers","body","errorMsg","errors","entry","changes","change","processMessages","error","processFlowRequest","config","flowHandlers","signature","verifySignature","data","decryptedBody","decryptFlowRequest","handler","isFlowPingRequest","isFlowErrorRequest","isFlowDataExchangeRequest","result","encryptedResponse","encryptFlowResponse","verificationToken","expectedSignature","crypto","constructFullUrl","headers","url","protocol","host","waba_id","value","metadata","contacts","wabaId","displayPhoneNumber","phoneNumberId","profileName","statuses","status","processedStatus","executeHandler","messages","message","messageType","processedMessage","handlerType","encrypted_aes_key","encrypted_flow_data","initial_vector","privatePem","passphrase","privateKey","decryptedAesKey","flowDataBuffer","initialVectorBuffer","encrypted_flow_data_body","encrypted_flow_data_tag","decipher","decryptedJSONString","response","aesKeyBuffer","flipped_iv","pair","cipher","WebhookProcessor","importConfig","WhatsApp","mode","token","challenge","webResponse","contentType","type"],"mappings":"6JAUA,IAAMA,CAAAA,CAAW,eAAA,CACXC,CAAAA,CAAS,IAAIC,CAAAA,CAAOF,CAAAA,CAAU,OAAA,CAAQ,GAAA,CAAI,KAAA,GAAU,MAAM,EAQhE,eAAsBG,CAAAA,CAClBC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CAKiB,CACjB,GAAI,CACAL,CAAAA,CAAO,IAAA,CAAK,qCAAqC,CAAA,CACjD,IAAMM,CAAAA,CAAO,MAAMH,CAAAA,CAAQ,IAAA,EAAK,CAIhC,GAHAH,CAAAA,CAAO,IAAA,CAAK,uBAAA,CAAyBM,CAAI,CAAA,CAGrCA,CAAAA,CAAK,MAAA,GAAW,2BAAA,CAA6B,CAC7C,IAAMC,CAAAA,CAAW,yCAAA,CACjB,OAAAP,CAAAA,CAAO,IAAA,CAAKO,CAAAA,CAAU,CAAE,IAAA,CAAAD,CAAK,CAAC,CAAA,CACvB,IAAI,QAAA,CAAS,IAAA,CAAK,SAAA,CAAU,CAAE,MAAOC,CAAS,CAAC,CAAA,CAAG,CAAE,MAAA,CAAQ,GAAI,CAAC,CAC5E,CAEA,IAAMC,CAAAA,CAAmB,EAAC,CAG1B,IAAA,IAAWC,KAASH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CtB,CAAAA,CAAO,GAAA,CAAI,CAAA,+BAAA,EAAkCgF,CAAI,CAAA,CAAE,EACvD,CAEA,mBAAA,CAAoB1D,CAAAA,CAA+B,CAC/C,IAAA,CAAK,iBAAA,CAAoBA,CAAAA,CACzBtB,CAAAA,CAAO,GAAA,CAAI,gCAAgC,EAC/C,CAEA,oBAAA,CAAqBsB,CAAAA,CAA+B,CAChD,IAAA,CAAK,mBAAqBA,CAAAA,CAC1BtB,CAAAA,CAAO,GAAA,CAAI,iCAAiC,EAChD,CAEA,MAAA,CAAOgF,CAAAA,CAAoB1D,CAAAA,CAA4B,CACnD,IAAA,CAAK,YAAA,CAAa,GAAA,CAAI0D,CAAAA,CAAM1D,CAAO,CAAA,CACnCtB,EAAO,GAAA,CAAI,CAAA,4BAAA,EAA+BgF,CAAI,CAAA,CAAE,EACpD,CAEA,SAAA,EAAsB,CAClB,OAAO,IAAA,CAAK,MAChB,CAEA,SAAA,EAA4B,CACxB,OAAO,IAAA,CAAK,MAChB,CACJ","file":"chunk-JPGXONBQ.js","sourcesContent":["import crypto from 'crypto';\nimport { FlowEndpointRequest } from '../../../api/flow';\nimport { FlowTypeEnum } from '../../../api/flow/types';\nimport { WabaConfigType } from '../../../types/config';\nimport { MessageTypesEnum } from '../../../types/enums';\nimport { isFlowDataExchangeRequest, isFlowErrorRequest, isFlowPingRequest } from '../../../utils/flowTypeGuards';\nimport Logger from '../../../utils/logger';\nimport { WhatsApp } from '../../whatsapp';\nimport { WebhookMessage, WebhookMessageValue } from '../types';\n\nconst LIB_NAME = 'WEBHOOK_UTILS';\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true');\n\nexport type MessageHandler = (whatsapp: WhatsApp, message: WebhookMessage) => void | Promise<void>;\nexport type FlowHandler = (whatsapp: WhatsApp, request: FlowEndpointRequest) => any | Promise<any>;\n\n/**\n * Process webhook messages\n */\nexport async function processWebhookMessages(\n request: Request,\n whatsapp: WhatsApp,\n handlers: {\n messageHandlers: Map<MessageTypesEnum, MessageHandler>;\n preProcessHandler?: MessageHandler;\n postProcessHandler?: MessageHandler;\n },\n): Promise<Response> {\n try {\n LOGGER.info('Processing webhook messages request');\n const body = await request.json();\n LOGGER.info('Webhook request body:', body);\n\n // Check this is a WhatsApp Business Account webhook\n if (body.object !== 'whatsapp_business_account') {\n const errorMsg = 'Received webhook for non-WhatsApp event';\n LOGGER.warn(errorMsg, { body });\n return new Response(JSON.stringify({ error: errorMsg }), { status: 404 });\n }\n\n const errors: string[] = [];\n\n // Process each entry\n for (const entry of body.entry) {\n try {\n LOGGER.info('Processing webhook entry:', { entryId: entry.id });\n const changes = entry.changes;\n for (const change of changes) {\n if (change.field === 'messages') {\n LOGGER.info('Processing messages change:', { change });\n await processMessages(entry.id, change.value, whatsapp, handlers);\n }\n }\n } catch (error) {\n const errorMsg = `Error processing webhook: ${error}`;\n LOGGER.error(errorMsg, { entry, error });\n errors.push(errorMsg);\n }\n }\n\n LOGGER.info('Webhook processing complete', { errorCount: errors.length });\n return new Response(errors.length > 0 ? JSON.stringify({ errors }) : null, { status: 200 });\n } catch (error) {\n LOGGER.error('Error processing webhook:', error);\n return new Response(JSON.stringify({ error: 'Internal Server Error' }), { status: 500 });\n }\n}\n\n/**\n * Handle flow requests\n */\nexport async function processFlowRequest(\n request: Request,\n config: WabaConfigType,\n whatsapp: WhatsApp,\n flowHandlers: Map<FlowTypeEnum, FlowHandler>,\n): Promise<Response> {\n try {\n LOGGER.info('Processing flow request');\n const body = await request.text();\n const signature = request.headers.get('x-hub-signature-256');\n LOGGER.info('Flow request signature:', { signature });\n\n // Validate request signature\n if (!verifySignature(body, signature, config.WEBHOOK_VERIFICATION_TOKEN || '')) {\n LOGGER.warn('Invalid request signature', { signature });\n return new Response(JSON.stringify({ error: 'Unauthorized' }), { status: 401 });\n }\n\n const data = JSON.parse(body);\n LOGGER.info('Flow request data:', data);\n\n // Decrypt the request\n const { decryptedBody } = decryptFlowRequest(data, config);\n LOGGER.info('Decrypted flow request:', decryptedBody);\n\n // Get the flow handler\n const handler = flowHandlers.get(FlowTypeEnum.All);\n if (!handler) {\n LOGGER.warn('No handler registered for flow action:', { action: decryptedBody.action });\n return new Response(JSON.stringify({ error: 'Handler not found' }), { status: 404 });\n }\n\n // Handle different flow types\n if (isFlowPingRequest(decryptedBody)) {\n LOGGER.info('Handling flow ping request');\n return new Response(\n JSON.stringify({\n version: '3.0',\n data: { status: 'active' },\n }),\n { status: 200 },\n );\n }\n\n if (isFlowErrorRequest(decryptedBody)) {\n LOGGER.warn('Flow error request received:', decryptedBody);\n return new Response(null, { status: 200 });\n }\n\n if (isFlowDataExchangeRequest(decryptedBody)) {\n LOGGER.info('Processing flow data exchange request');\n const result = await handler(whatsapp, decryptedBody);\n LOGGER.info('Flow handler result:', result);\n\n const encryptedResponse = encryptFlowResponse(\n result,\n Buffer.from(data.aes_key, 'base64'),\n Buffer.from(data.initial_vector, 'base64'),\n );\n LOGGER.info('Encrypted flow response generated');\n\n return new Response(JSON.stringify(encryptedResponse), { status: 200 });\n }\n\n LOGGER.warn('Unknown flow request type:', decryptedBody);\n return new Response(JSON.stringify({ error: 'Unknown request type' }), { status: 400 });\n } catch (error) {\n LOGGER.error('Error handling flow request:', error);\n return new Response(JSON.stringify({ error: 'Internal server error' }), { status: 500 });\n }\n}\n\n/**\n * Verify webhook signature\n */\nfunction verifySignature(body: string, signature: string | null, verificationToken: string): boolean {\n if (!signature) {\n LOGGER.warn('Missing signature in request');\n return false;\n }\n\n LOGGER.info('Signature verification details:', {\n bodyLength: body.length,\n verificationTokenLength: verificationToken.length,\n rawSignature: signature,\n cleanedSignature: signature.replace('sha256=', ''),\n });\n\n const expectedSignature = crypto.createHmac('sha256', verificationToken).update(body).digest('hex');\n LOGGER.info('Signature verification:', {\n received: signature.replace('sha256=', ''),\n expected: expectedSignature,\n });\n\n return crypto.timingSafeEqual(Buffer.from(signature.replace('sha256=', '')), Buffer.from(expectedSignature));\n}\n\n/**\n * Constructs a full URL from framework-specific request headers and URL\n * @param headers - Request headers containing host and protocol information\n * @param url - Relative URL path\n * @returns Full URL string\n */\nexport function constructFullUrl(headers: Record<string, string | string[] | undefined>, url?: string): string {\n const protocol = headers['x-forwarded-proto'] || 'http';\n const host = headers.host || 'localhost';\n const path = url || '/';\n return `${protocol}://${host}${path}`;\n}\n\n/**\n * Private helper functions\n */\nasync function processMessages(\n waba_id: string,\n value: WebhookMessageValue,\n whatsapp: WhatsApp,\n handlers: {\n messageHandlers: Map<MessageTypesEnum, MessageHandler>;\n preProcessHandler?: MessageHandler;\n postProcessHandler?: MessageHandler;\n },\n): Promise<void> {\n LOGGER.info('Processing messages:', { waba_id, value });\n\n const metadata = value.metadata;\n const contacts = value.contacts;\n const wabaId = waba_id;\n const displayPhoneNumber = metadata?.display_phone_number || '';\n const phoneNumberId = metadata?.phone_number_id || '';\n const profileName = contacts?.[0]?.profile?.name || '';\n\n if (value.statuses && value.statuses.length > 0) {\n LOGGER.info('Processing statuses:', { statusCount: value.statuses.length });\n const statuses = value.statuses;\n for (const status of statuses) {\n const processedStatus: WebhookMessage = {\n wabaId,\n id: status.id,\n from: status.recipient_id,\n timestamp: status.timestamp,\n type: MessageTypesEnum.Statuses,\n phoneNumberId,\n displayPhoneNumber,\n profileName,\n statuses: value.statuses[0],\n originalData: status,\n };\n\n LOGGER.info('Processing status:', processedStatus);\n await executeHandler(\n handlers.messageHandlers.get(MessageTypesEnum.Statuses),\n whatsapp,\n processedStatus,\n MessageTypesEnum.Statuses,\n );\n }\n return;\n }\n\n if (value.messages && value.messages.length > 0) {\n LOGGER.info('Processing messages:', { messageCount: value.messages.length });\n const messages = value.messages;\n\n for (const message of messages) {\n const messageType = message.type;\n LOGGER.info('Processing message:', { messageType, messageId: message.id });\n\n const processedMessage: WebhookMessage = {\n wabaId,\n id: message.id,\n from: message.from,\n timestamp: message.timestamp,\n type: message.type,\n phoneNumberId,\n displayPhoneNumber,\n profileName,\n originalData: message,\n };\n\n switch (messageType) {\n case MessageTypesEnum.Text:\n processedMessage.text = message.text;\n break;\n case MessageTypesEnum.Image:\n processedMessage.image = message.image;\n break;\n case MessageTypesEnum.Video:\n processedMessage.video = message.video;\n break;\n case MessageTypesEnum.Audio:\n processedMessage.audio = message.audio;\n break;\n case MessageTypesEnum.Document:\n processedMessage.document = message.document;\n break;\n case MessageTypesEnum.Sticker:\n processedMessage.sticker = message.sticker;\n break;\n case MessageTypesEnum.Location:\n processedMessage.location = message.location;\n break;\n case MessageTypesEnum.Contacts:\n processedMessage.contacts = message.contacts;\n break;\n case MessageTypesEnum.Interactive:\n processedMessage.interactive = message.interactive;\n break;\n case MessageTypesEnum.Button:\n processedMessage.button = message.button;\n break;\n case MessageTypesEnum.Order:\n processedMessage.order = message.order;\n break;\n case MessageTypesEnum.System:\n processedMessage.system = message.system;\n break;\n case MessageTypesEnum.Reaction:\n processedMessage.reaction = message.reaction;\n break;\n default:\n LOGGER.warn('Unknown message type:', { messageType });\n break;\n }\n\n // Execute handlers in sequence\n LOGGER.info('Executing message handlers');\n await executeHandler(handlers.preProcessHandler, whatsapp, processedMessage, 'pre-process');\n await executeHandler(handlers.messageHandlers.get(messageType), whatsapp, processedMessage, messageType);\n await executeHandler(handlers.postProcessHandler, whatsapp, processedMessage, 'post-process');\n }\n }\n}\n\nasync function executeHandler(\n handler: MessageHandler | undefined,\n whatsapp: WhatsApp,\n message: WebhookMessage,\n handlerType: string,\n): Promise<void> {\n if (handler) {\n try {\n LOGGER.info('Executing handler:', { handlerType, messageId: message.id });\n await handler(whatsapp, message);\n LOGGER.info('Handler execution complete:', { handlerType, messageId: message.id });\n } catch (error) {\n LOGGER.error(`Error in ${handlerType} handler:`, { error, messageId: message.id });\n }\n } else {\n LOGGER.info('No handler registered:', { handlerType });\n }\n}\n\nfunction decryptFlowRequest(\n body: any,\n config: WabaConfigType,\n): {\n decryptedBody: FlowEndpointRequest;\n aesKeyBuffer: Buffer;\n initialVectorBuffer: Buffer;\n} {\n LOGGER.info('Decrypting flow request');\n const { encrypted_aes_key, encrypted_flow_data, initial_vector } = body;\n\n if (!encrypted_aes_key || !encrypted_flow_data || !initial_vector) {\n LOGGER.error('Missing required encryption properties');\n throw new Error('Missing required encryption properties');\n }\n\n const privatePem = config.FLOW_API_PRIVATE_PEM.replace(/\\\\n/g, '\\n');\n const passphrase = config.FLOW_API_PASSPHRASE;\n\n const privateKey = crypto.createPrivateKey({ key: privatePem, passphrase });\n let decryptedAesKey: Buffer;\n\n try {\n LOGGER.info('Decrypting AES key');\n decryptedAesKey = crypto.privateDecrypt(\n {\n key: privateKey,\n padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,\n oaepHash: 'sha256',\n },\n Buffer.from(encrypted_aes_key, 'base64'),\n );\n } catch (error) {\n LOGGER.error('Failed to decrypt AES key:', error);\n throw new Error('Failed to decrypt the request. Please verify your private key.');\n }\n\n const flowDataBuffer = Buffer.from(encrypted_flow_data, 'base64');\n const initialVectorBuffer = Buffer.from(initial_vector, 'base64');\n\n const TAG_LENGTH = 16;\n const encrypted_flow_data_body = flowDataBuffer.subarray(0, -TAG_LENGTH);\n const encrypted_flow_data_tag = flowDataBuffer.subarray(-TAG_LENGTH);\n\n LOGGER.info('Decrypting flow data');\n const decipher = crypto.createDecipheriv('aes-128-gcm', decryptedAesKey, initialVectorBuffer);\n decipher.setAuthTag(encrypted_flow_data_tag);\n\n const decryptedJSONString = Buffer.concat([decipher.update(encrypted_flow_data_body), decipher.final()]).toString(\n 'utf-8',\n );\n\n LOGGER.info('Flow request decryption complete');\n return {\n decryptedBody: JSON.parse(decryptedJSONString),\n aesKeyBuffer: decryptedAesKey,\n initialVectorBuffer,\n };\n}\n\nfunction encryptFlowResponse(response: any, aesKeyBuffer: Buffer, initialVectorBuffer: Buffer): string {\n LOGGER.info('Encrypting flow response');\n const flipped_iv: number[] = [];\n for (const pair of Array.from(initialVectorBuffer.entries())) {\n flipped_iv.push(~pair[1]);\n }\n\n try {\n const cipher = crypto.createCipheriv('aes-128-gcm', aesKeyBuffer, Buffer.from(flipped_iv));\n const encryptedResponse = Buffer.concat([\n cipher.update(JSON.stringify(response || {}), 'utf-8'),\n cipher.final(),\n cipher.getAuthTag(),\n ]).toString('base64');\n\n LOGGER.info('Flow response encryption complete');\n return encryptedResponse;\n } catch (error) {\n LOGGER.error('Response encryption error:', error);\n throw new Error('Failed to encrypt response. Internal server error.');\n }\n}\n","import { FlowTypeEnum } from '../../api/flow/types';\nimport { importConfig } from '../../config/importConfig';\nimport { WabaConfigType, WhatsAppConfig } from '../../types/config';\nimport { MessageTypesEnum } from '../../types/enums';\nimport Logger from '../../utils/logger';\nimport { WhatsApp } from '../whatsapp';\nimport { FlowHandler, MessageHandler, processFlowRequest, processWebhookMessages } from './utils/webhookUtils';\n\nconst LOGGER = new Logger('WEBHOOK_PROCESSOR', process.env.DEBUG === 'true');\n\nexport interface WebhookResponse {\n status: number;\n body: string;\n headers: Record<string, string>;\n}\n\nexport class WebhookProcessor {\n private config: WabaConfigType;\n private client: WhatsApp;\n private messageHandlers: Map<MessageTypesEnum, MessageHandler> = new Map();\n private preProcessHandler: MessageHandler | undefined = undefined;\n private postProcessHandler: MessageHandler | undefined = undefined;\n private flowHandlers: Map<FlowTypeEnum, FlowHandler> = new Map();\n\n constructor(config: WhatsAppConfig) {\n this.config = importConfig(config);\n this.client = new WhatsApp(config);\n LOGGER.log('WebhookProcessor instantiated');\n }\n\n async processVerification(\n mode: string | null,\n token: string | null,\n challenge: string | null,\n ): Promise<WebhookResponse> {\n if (mode === 'subscribe' && token === this.config.WEBHOOK_VERIFICATION_TOKEN) {\n return {\n status: 200,\n body: challenge || '',\n headers: { 'Content-Type': 'text/plain' },\n };\n }\n\n return {\n status: 403,\n body: JSON.stringify({ error: 'Forbidden' }),\n headers: { 'Content-Type': 'application/json' },\n };\n }\n\n async processWebhook(request: Request): Promise<WebhookResponse> {\n try {\n const webResponse = await processWebhookMessages(request, this.client, {\n messageHandlers: this.messageHandlers,\n preProcessHandler: this.preProcessHandler,\n postProcessHandler: this.postProcessHandler,\n });\n\n const body = await webResponse.text();\n const contentType = webResponse.headers.get('content-type') || 'application/json';\n\n return {\n status: webResponse.status,\n body,\n headers: { 'Content-Type': contentType },\n };\n } catch (error) {\n LOGGER.log(`Error processing webhook: ${error}`);\n return {\n status: 500,\n body: JSON.stringify({ error: 'Internal Server Error' }),\n headers: { 'Content-Type': 'application/json' },\n };\n }\n }\n\n async processFlow(request: Request): Promise<WebhookResponse> {\n try {\n const webResponse = await processFlowRequest(request, this.config, this.client, this.flowHandlers);\n const body = await webResponse.text();\n const contentType = webResponse.headers.get('content-type') || 'application/json';\n\n return {\n status: webResponse.status,\n body,\n headers: { 'Content-Type': contentType },\n };\n } catch (error) {\n LOGGER.log(`Error processing flow: ${error}`);\n return {\n status: 500,\n body: JSON.stringify({ error: 'Internal Server Error' }),\n headers: { 'Content-Type': 'application/json' },\n };\n }\n }\n\n onMessage(type: MessageTypesEnum, handler: MessageHandler): void {\n this.messageHandlers.set(type, handler);\n LOGGER.log(`Registered message handler for ${type}`);\n }\n\n onMessagePreProcess(handler: MessageHandler): void {\n this.preProcessHandler = handler;\n LOGGER.log('Registered pre-process handler');\n }\n\n onMessagePostProcess(handler: MessageHandler): void {\n this.postProcessHandler = handler;\n LOGGER.log('Registered post-process handler');\n }\n\n onFlow(type: FlowTypeEnum, handler: FlowHandler): void {\n this.flowHandlers.set(type, handler);\n LOGGER.log(`Registered flow handler for ${type}`);\n }\n\n getClient(): WhatsApp {\n return this.client;\n }\n\n getConfig(): WabaConfigType {\n return this.config;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/core/webhook/utils/webhookUtils.ts","../src/core/webhook/WebhookProcessor.ts"],"names":["LIB_NAME","LOGGER","Logger","processWebhookMessages","request","whatsapp","handlers","body","errorMsg","errors","entry","changes","change","processMessages","error","processFlowRequest","config","flowHandlers","signature","verifySignature","data","decryptedBody","decryptFlowRequest","handler","isFlowPingRequest","isFlowErrorRequest","isFlowDataExchangeRequest","result","encryptedResponse","encryptFlowResponse","verificationToken","expectedSignature","crypto","constructFullUrl","headers","url","protocol","host","waba_id","value","metadata","contacts","wabaId","displayPhoneNumber","phoneNumberId","profileName","statuses","status","processedStatus","executeHandler","messages","message","messageType","processedMessage","handlerType","encrypted_aes_key","encrypted_flow_data","initial_vector","privatePem","passphrase","privateKey","decryptedAesKey","flowDataBuffer","initialVectorBuffer","encrypted_flow_data_body","encrypted_flow_data_tag","decipher","decryptedJSONString","response","aesKeyBuffer","flipped_iv","pair","cipher","WebhookProcessor","importConfig","WhatsApp","mode","token","challenge","webResponse","contentType","type"],"mappings":"6JAUA,IAAMA,CAAAA,CAAW,eAAA,CACXC,CAAAA,CAAS,IAAIC,CAAAA,CAAOF,CAAAA,CAAU,OAAA,CAAQ,GAAA,CAAI,KAAA,GAAU,MAAM,EAQhE,eAAsBG,CAAAA,CAClBC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CAKiB,CACjB,GAAI,CACAL,CAAAA,CAAO,IAAA,CAAK,qCAAqC,CAAA,CACjD,IAAMM,CAAAA,CAAO,MAAMH,CAAAA,CAAQ,IAAA,EAAK,CAIhC,GAHAH,CAAAA,CAAO,IAAA,CAAK,uBAAA,CAAyBM,CAAI,CAAA,CAGrCA,CAAAA,CAAK,MAAA,GAAW,2BAAA,CAA6B,CAC7C,IAAMC,CAAAA,CAAW,yCAAA,CACjB,OAAAP,CAAAA,CAAO,IAAA,CAAKO,CAAAA,CAAU,CAAE,IAAA,CAAAD,CAAK,CAAC,CAAA,CACvB,IAAI,QAAA,CAAS,IAAA,CAAK,SAAA,CAAU,CAAE,MAAOC,CAAS,CAAC,CAAA,CAAG,CAAE,MAAA,CAAQ,GAAI,CAAC,CAC5E,CAEA,IAAMC,CAAAA,CAAmB,EAAC,CAG1B,IAAA,IAAWC,KAASH,CAAAA,CAAK,KAAA,CACrB,GAAI,CACAN,CAAAA,CAAO,IAAA,CAAK,2BAAA,CAA6B,CAAE,OAAA,CAASS,CAAAA,CAAM,EAAG,CAA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C,IAAA,CAAK,iBAAA,CAAoBA,CAAAA,CACzBtB,CAAAA,CAAO,GAAA,CAAI,gCAAgC,EAC/C,CAEA,oBAAA,CAAqBsB,CAAAA,CAA+B,CAChD,IAAA,CAAK,mBAAqBA,CAAAA,CAC1BtB,CAAAA,CAAO,GAAA,CAAI,iCAAiC,EAChD,CAEA,MAAA,CAAOgF,CAAAA,CAAoB1D,CAAAA,CAA4B,CACnD,IAAA,CAAK,YAAA,CAAa,GAAA,CAAI0D,CAAAA,CAAM1D,CAAO,CAAA,CACnCtB,EAAO,GAAA,CAAI,CAAA,4BAAA,EAA+BgF,CAAI,CAAA,CAAE,EACpD,CAEA,SAAA,EAAsB,CAClB,OAAO,IAAA,CAAK,MAChB,CAEA,SAAA,EAA4B,CACxB,OAAO,IAAA,CAAK,MAChB,CACJ","file":"chunk-U5FBZ6UB.js","sourcesContent":["import crypto from 'crypto';\nimport { FlowEndpointRequest } from '../../../api/flow';\nimport { FlowTypeEnum } from '../../../api/flow/types';\nimport { WabaConfigType } from '../../../types/config';\nimport { MessageTypesEnum } from '../../../types/enums';\nimport { isFlowDataExchangeRequest, isFlowErrorRequest, isFlowPingRequest } from '../../../utils/flowTypeGuards';\nimport Logger from '../../../utils/logger';\nimport { WhatsApp } from '../../whatsapp';\nimport { WebhookMessage, WebhookMessageValue } from '../types';\n\nconst LIB_NAME = 'WEBHOOK_UTILS';\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true');\n\nexport type MessageHandler = (whatsapp: WhatsApp, message: WebhookMessage) => void | Promise<void>;\nexport type FlowHandler = (whatsapp: WhatsApp, request: FlowEndpointRequest) => any | Promise<any>;\n\n/**\n * Process webhook messages\n */\nexport async function processWebhookMessages(\n request: Request,\n whatsapp: WhatsApp,\n handlers: {\n messageHandlers: Map<MessageTypesEnum, MessageHandler>;\n preProcessHandler?: MessageHandler;\n postProcessHandler?: MessageHandler;\n },\n): Promise<Response> {\n try {\n LOGGER.info('Processing webhook messages request');\n const body = await request.json();\n LOGGER.info('Webhook request body:', body);\n\n // Check this is a WhatsApp Business Account webhook\n if (body.object !== 'whatsapp_business_account') {\n const errorMsg = 'Received webhook for non-WhatsApp event';\n LOGGER.warn(errorMsg, { body });\n return new Response(JSON.stringify({ error: errorMsg }), { status: 404 });\n }\n\n const errors: string[] = [];\n\n // Process each entry\n for (const entry of body.entry) {\n try {\n LOGGER.info('Processing webhook entry:', { entryId: entry.id });\n const changes = entry.changes;\n for (const change of changes) {\n if (change.field === 'messages') {\n LOGGER.info('Processing messages change:', { change });\n await processMessages(entry.id, change.value, whatsapp, handlers);\n }\n }\n } catch (error) {\n const errorMsg = `Error processing webhook: ${error}`;\n LOGGER.error(errorMsg, { entry, error });\n errors.push(errorMsg);\n }\n }\n\n LOGGER.info('Webhook processing complete', { errorCount: errors.length });\n return new Response(errors.length > 0 ? JSON.stringify({ errors }) : null, { status: 200 });\n } catch (error) {\n LOGGER.error('Error processing webhook:', error);\n return new Response(JSON.stringify({ error: 'Internal Server Error' }), { status: 500 });\n }\n}\n\n/**\n * Handle flow requests\n */\nexport async function processFlowRequest(\n request: Request,\n config: WabaConfigType,\n whatsapp: WhatsApp,\n flowHandlers: Map<FlowTypeEnum, FlowHandler>,\n): Promise<Response> {\n try {\n LOGGER.info('Processing flow request');\n const body = await request.text();\n const signature = request.headers.get('x-hub-signature-256');\n LOGGER.info('Flow request signature:', { signature });\n\n // Validate request signature\n if (!verifySignature(body, signature, config.WEBHOOK_VERIFICATION_TOKEN || '')) {\n LOGGER.warn('Invalid request signature', { signature });\n return new Response(JSON.stringify({ error: 'Unauthorized' }), { status: 401 });\n }\n\n const data = JSON.parse(body);\n LOGGER.info('Flow request data:', data);\n\n // Decrypt the request\n const { decryptedBody } = decryptFlowRequest(data, config);\n LOGGER.info('Decrypted flow request:', decryptedBody);\n\n // Get the flow handler\n const handler = flowHandlers.get(FlowTypeEnum.All);\n if (!handler) {\n LOGGER.warn('No handler registered for flow action:', { action: decryptedBody.action });\n return new Response(JSON.stringify({ error: 'Handler not found' }), { status: 404 });\n }\n\n // Handle different flow types\n if (isFlowPingRequest(decryptedBody)) {\n LOGGER.info('Handling flow ping request');\n return new Response(\n JSON.stringify({\n version: '3.0',\n data: { status: 'active' },\n }),\n { status: 200 },\n );\n }\n\n if (isFlowErrorRequest(decryptedBody)) {\n LOGGER.warn('Flow error request received:', decryptedBody);\n return new Response(null, { status: 200 });\n }\n\n if (isFlowDataExchangeRequest(decryptedBody)) {\n LOGGER.info('Processing flow data exchange request');\n const result = await handler(whatsapp, decryptedBody);\n LOGGER.info('Flow handler result:', result);\n\n const encryptedResponse = encryptFlowResponse(\n result,\n Buffer.from(data.aes_key, 'base64'),\n Buffer.from(data.initial_vector, 'base64'),\n );\n LOGGER.info('Encrypted flow response generated');\n\n return new Response(JSON.stringify(encryptedResponse), { status: 200 });\n }\n\n LOGGER.warn('Unknown flow request type:', decryptedBody);\n return new Response(JSON.stringify({ error: 'Unknown request type' }), { status: 400 });\n } catch (error) {\n LOGGER.error('Error handling flow request:', error);\n return new Response(JSON.stringify({ error: 'Internal server error' }), { status: 500 });\n }\n}\n\n/**\n * Verify webhook signature\n */\nfunction verifySignature(body: string, signature: string | null, verificationToken: string): boolean {\n if (!signature) {\n LOGGER.warn('Missing signature in request');\n return false;\n }\n\n LOGGER.info('Signature verification details:', {\n bodyLength: body.length,\n verificationTokenLength: verificationToken.length,\n rawSignature: signature,\n cleanedSignature: signature.replace('sha256=', ''),\n });\n\n const expectedSignature = crypto.createHmac('sha256', verificationToken).update(body).digest('hex');\n LOGGER.info('Signature verification:', {\n received: signature.replace('sha256=', ''),\n expected: expectedSignature,\n });\n\n return crypto.timingSafeEqual(Buffer.from(signature.replace('sha256=', '')), Buffer.from(expectedSignature));\n}\n\n/**\n * Constructs a full URL from framework-specific request headers and URL\n * @param headers - Request headers containing host and protocol information\n * @param url - Relative URL path\n * @returns Full URL string\n */\nexport function constructFullUrl(headers: Record<string, string | string[] | undefined>, url?: string): string {\n const protocol = headers['x-forwarded-proto'] || 'http';\n const host = headers.host || 'localhost';\n const path = url || '/';\n return `${protocol}://${host}${path}`;\n}\n\n/**\n * Private helper functions\n */\nasync function processMessages(\n waba_id: string,\n value: WebhookMessageValue,\n whatsapp: WhatsApp,\n handlers: {\n messageHandlers: Map<MessageTypesEnum, MessageHandler>;\n preProcessHandler?: MessageHandler;\n postProcessHandler?: MessageHandler;\n },\n): Promise<void> {\n LOGGER.info('Processing messages:', { waba_id, value });\n\n const metadata = value.metadata;\n const contacts = value.contacts;\n const wabaId = waba_id;\n const displayPhoneNumber = metadata?.display_phone_number || '';\n const phoneNumberId = metadata?.phone_number_id || '';\n const profileName = contacts?.[0]?.profile?.name || '';\n\n if (value.statuses && value.statuses.length > 0) {\n LOGGER.info('Processing statuses:', { statusCount: value.statuses.length });\n const statuses = value.statuses;\n for (const status of statuses) {\n const processedStatus: WebhookMessage = {\n wabaId,\n id: status.id,\n from: status.recipient_id,\n timestamp: status.timestamp,\n type: MessageTypesEnum.Statuses,\n phoneNumberId,\n displayPhoneNumber,\n profileName,\n statuses: value.statuses[0],\n originalData: status,\n };\n\n LOGGER.info('Processing status:', processedStatus);\n await executeHandler(\n handlers.messageHandlers.get(MessageTypesEnum.Statuses),\n whatsapp,\n processedStatus,\n MessageTypesEnum.Statuses,\n );\n }\n return;\n }\n\n if (value.messages && value.messages.length > 0) {\n LOGGER.info('Processing messages:', { messageCount: value.messages.length });\n const messages = value.messages;\n\n for (const message of messages) {\n const messageType = message.type;\n LOGGER.info('Processing message:', { messageType, messageId: message.id });\n\n const processedMessage: WebhookMessage = {\n wabaId,\n id: message.id,\n from: message.from,\n timestamp: message.timestamp,\n type: message.type,\n phoneNumberId,\n displayPhoneNumber,\n profileName,\n originalData: message,\n };\n\n switch (messageType) {\n case MessageTypesEnum.Text:\n processedMessage.text = message.text;\n break;\n case MessageTypesEnum.Image:\n processedMessage.image = message.image;\n break;\n case MessageTypesEnum.Video:\n processedMessage.video = message.video;\n break;\n case MessageTypesEnum.Audio:\n processedMessage.audio = message.audio;\n break;\n case MessageTypesEnum.Document:\n processedMessage.document = message.document;\n break;\n case MessageTypesEnum.Sticker:\n processedMessage.sticker = message.sticker;\n break;\n case MessageTypesEnum.Location:\n processedMessage.location = message.location;\n break;\n case MessageTypesEnum.Contacts:\n processedMessage.contacts = message.contacts;\n break;\n case MessageTypesEnum.Interactive:\n processedMessage.interactive = message.interactive;\n break;\n case MessageTypesEnum.Button:\n processedMessage.button = message.button;\n break;\n case MessageTypesEnum.Order:\n processedMessage.order = message.order;\n break;\n case MessageTypesEnum.System:\n processedMessage.system = message.system;\n break;\n case MessageTypesEnum.Reaction:\n processedMessage.reaction = message.reaction;\n break;\n default:\n LOGGER.warn('Unknown message type:', { messageType });\n break;\n }\n\n // Execute handlers in sequence\n LOGGER.info('Executing message handlers');\n await executeHandler(handlers.preProcessHandler, whatsapp, processedMessage, 'pre-process');\n await executeHandler(handlers.messageHandlers.get(messageType), whatsapp, processedMessage, messageType);\n await executeHandler(handlers.postProcessHandler, whatsapp, processedMessage, 'post-process');\n }\n }\n}\n\nasync function executeHandler(\n handler: MessageHandler | undefined,\n whatsapp: WhatsApp,\n message: WebhookMessage,\n handlerType: string,\n): Promise<void> {\n if (handler) {\n try {\n LOGGER.info('Executing handler:', { handlerType, messageId: message.id });\n await handler(whatsapp, message);\n LOGGER.info('Handler execution complete:', { handlerType, messageId: message.id });\n } catch (error) {\n LOGGER.error(`Error in ${handlerType} handler:`, { error, messageId: message.id });\n }\n } else {\n LOGGER.info('No handler registered:', { handlerType });\n }\n}\n\nfunction decryptFlowRequest(\n body: any,\n config: WabaConfigType,\n): {\n decryptedBody: FlowEndpointRequest;\n aesKeyBuffer: Buffer;\n initialVectorBuffer: Buffer;\n} {\n LOGGER.info('Decrypting flow request');\n const { encrypted_aes_key, encrypted_flow_data, initial_vector } = body;\n\n if (!encrypted_aes_key || !encrypted_flow_data || !initial_vector) {\n LOGGER.error('Missing required encryption properties');\n throw new Error('Missing required encryption properties');\n }\n\n const privatePem = config.FLOW_API_PRIVATE_PEM.replace(/\\\\n/g, '\\n');\n const passphrase = config.FLOW_API_PASSPHRASE;\n\n const privateKey = crypto.createPrivateKey({ key: privatePem, passphrase });\n let decryptedAesKey: Buffer;\n\n try {\n LOGGER.info('Decrypting AES key');\n decryptedAesKey = crypto.privateDecrypt(\n {\n key: privateKey,\n padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,\n oaepHash: 'sha256',\n },\n Buffer.from(encrypted_aes_key, 'base64'),\n );\n } catch (error) {\n LOGGER.error('Failed to decrypt AES key:', error);\n throw new Error('Failed to decrypt the request. Please verify your private key.');\n }\n\n const flowDataBuffer = Buffer.from(encrypted_flow_data, 'base64');\n const initialVectorBuffer = Buffer.from(initial_vector, 'base64');\n\n const TAG_LENGTH = 16;\n const encrypted_flow_data_body = flowDataBuffer.subarray(0, -TAG_LENGTH);\n const encrypted_flow_data_tag = flowDataBuffer.subarray(-TAG_LENGTH);\n\n LOGGER.info('Decrypting flow data');\n const decipher = crypto.createDecipheriv('aes-128-gcm', decryptedAesKey, initialVectorBuffer);\n decipher.setAuthTag(encrypted_flow_data_tag);\n\n const decryptedJSONString = Buffer.concat([decipher.update(encrypted_flow_data_body), decipher.final()]).toString(\n 'utf-8',\n );\n\n LOGGER.info('Flow request decryption complete');\n return {\n decryptedBody: JSON.parse(decryptedJSONString),\n aesKeyBuffer: decryptedAesKey,\n initialVectorBuffer,\n };\n}\n\nfunction encryptFlowResponse(response: any, aesKeyBuffer: Buffer, initialVectorBuffer: Buffer): string {\n LOGGER.info('Encrypting flow response');\n const flipped_iv: number[] = [];\n for (const pair of Array.from(initialVectorBuffer.entries())) {\n flipped_iv.push(~pair[1]);\n }\n\n try {\n const cipher = crypto.createCipheriv('aes-128-gcm', aesKeyBuffer, Buffer.from(flipped_iv));\n const encryptedResponse = Buffer.concat([\n cipher.update(JSON.stringify(response || {}), 'utf-8'),\n cipher.final(),\n cipher.getAuthTag(),\n ]).toString('base64');\n\n LOGGER.info('Flow response encryption complete');\n return encryptedResponse;\n } catch (error) {\n LOGGER.error('Response encryption error:', error);\n throw new Error('Failed to encrypt response. Internal server error.');\n }\n}\n","import { FlowTypeEnum } from '../../api/flow/types';\nimport { importConfig } from '../../config/importConfig';\nimport { WabaConfigType, WhatsAppConfig } from '../../types/config';\nimport { MessageTypesEnum } from '../../types/enums';\nimport Logger from '../../utils/logger';\nimport { WhatsApp } from '../whatsapp';\nimport { FlowHandler, MessageHandler, processFlowRequest, processWebhookMessages } from './utils/webhookUtils';\n\nconst LOGGER = new Logger('WEBHOOK_PROCESSOR', process.env.DEBUG === 'true');\n\nexport interface WebhookResponse {\n status: number;\n body: string;\n headers: Record<string, string>;\n}\n\nexport class WebhookProcessor {\n private config: WabaConfigType;\n private client: WhatsApp;\n private messageHandlers: Map<MessageTypesEnum, MessageHandler> = new Map();\n private preProcessHandler: MessageHandler | undefined = undefined;\n private postProcessHandler: MessageHandler | undefined = undefined;\n private flowHandlers: Map<FlowTypeEnum, FlowHandler> = new Map();\n\n constructor(config: WhatsAppConfig) {\n this.config = importConfig(config);\n this.client = new WhatsApp(config);\n LOGGER.log('WebhookProcessor instantiated');\n }\n\n async processVerification(\n mode: string | null,\n token: string | null,\n challenge: string | null,\n ): Promise<WebhookResponse> {\n if (mode === 'subscribe' && token === this.config.WEBHOOK_VERIFICATION_TOKEN) {\n return {\n status: 200,\n body: challenge || '',\n headers: { 'Content-Type': 'text/plain' },\n };\n }\n\n return {\n status: 403,\n body: JSON.stringify({ error: 'Forbidden' }),\n headers: { 'Content-Type': 'application/json' },\n };\n }\n\n async processWebhook(request: Request): Promise<WebhookResponse> {\n try {\n const webResponse = await processWebhookMessages(request, this.client, {\n messageHandlers: this.messageHandlers,\n preProcessHandler: this.preProcessHandler,\n postProcessHandler: this.postProcessHandler,\n });\n\n const body = await webResponse.text();\n const contentType = webResponse.headers.get('content-type') || 'application/json';\n\n return {\n status: webResponse.status,\n body,\n headers: { 'Content-Type': contentType },\n };\n } catch (error) {\n LOGGER.log(`Error processing webhook: ${error}`);\n return {\n status: 500,\n body: JSON.stringify({ error: 'Internal Server Error' }),\n headers: { 'Content-Type': 'application/json' },\n };\n }\n }\n\n async processFlow(request: Request): Promise<WebhookResponse> {\n try {\n const webResponse = await processFlowRequest(request, this.config, this.client, this.flowHandlers);\n const body = await webResponse.text();\n const contentType = webResponse.headers.get('content-type') || 'application/json';\n\n return {\n status: webResponse.status,\n body,\n headers: { 'Content-Type': contentType },\n };\n } catch (error) {\n LOGGER.log(`Error processing flow: ${error}`);\n return {\n status: 500,\n body: JSON.stringify({ error: 'Internal Server Error' }),\n headers: { 'Content-Type': 'application/json' },\n };\n }\n }\n\n onMessage(type: MessageTypesEnum, handler: MessageHandler): void {\n this.messageHandlers.set(type, handler);\n LOGGER.log(`Registered message handler for ${type}`);\n }\n\n onMessagePreProcess(handler: MessageHandler): void {\n this.preProcessHandler = handler;\n LOGGER.log('Registered pre-process handler');\n }\n\n onMessagePostProcess(handler: MessageHandler): void {\n this.postProcessHandler = handler;\n LOGGER.log('Registered post-process handler');\n }\n\n onFlow(type: FlowTypeEnum, handler: FlowHandler): void {\n this.flowHandlers.set(type, handler);\n LOGGER.log(`Registered flow handler for ${type}`);\n }\n\n getClient(): WhatsApp {\n return this.client;\n }\n\n getConfig(): WabaConfigType {\n return this.config;\n }\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {a}from'./chunk-5577QQ7V.js';var u=class extends a{constructor(e){super(e);}async handleGet(e,s,t){try{let{"hub.mode":n,"hub.verify_token":r,"hub.challenge":o}=e.query,a=await this.processVerification(n||null,r||null,o||null);return this.applyHeaders(a,s),s.status(a.status).send(a.body)}catch(n){return t(n),s}}async handlePost(e,s,t){try{let n=this.constructFullUrl(e.headers,e.url),r=new globalThis.Request(n,{method:e.method,headers:e.headers,body:JSON.stringify(e.body)}),o=await this.processWebhook(r);return this.applyHeaders(o,s),s.status(o.status).send(o.body)}catch(n){return t(n),s}}async handleFlow(e,s,t){try{let n=this.constructFullUrl(e.headers,e.url),r=new globalThis.Request(n,{method:e.method,headers:e.headers,body:e.method==="POST"?JSON.stringify(e.body):void 0}),o=await this.processFlow(r);return this.applyHeaders(o,s),s.status(o.status).send(o.body)}catch(n){return t(n),s}}getHandlers(){return {GET:(e,s,t)=>this.handleGet(e,s,t),POST:(e,s,t)=>this.handlePost(e,s,t),webhook:(e,s,t)=>this.autoRoute(e,s,t),flow:(e,s,t)=>this.handleFlow(e,s,t),processor:this.webhookProcessor}}};function x(i){return new u(i).getHandlers()}export{x as a};//# sourceMappingURL=chunk-ZMNXRMWK.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-ZMNXRMWK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/webhook/frameworks/express.ts"],"names":["ExpressWebhookHandler","BaseWebhookHandler","config","req","res","next","mode","token","challenge","result","error","fullUrl","webRequest","webhookHandler"],"mappings":"oCA8BA,IAAMA,CAAAA,CAAN,cAAoCC,CAAoD,CACpF,WAAA,CAAYC,CAAAA,CAA8B,CACtC,KAAA,CAAMA,CAAM,EAChB,CAEA,MAAgB,SAAA,CAAUC,CAAAA,CAAqBC,CAAAA,CAAsBC,CAAAA,CAA8C,CAC/G,GAAI,CACA,GAAM,CAAE,UAAA,CAAYC,CAAAA,CAAM,kBAAA,CAAoBC,CAAAA,CAAO,eAAA,CAAiBC,CAAU,CAAA,CAAIL,EAAI,KAAA,CAElFM,CAAAA,CAAS,MAAM,IAAA,CAAK,mBAAA,CACrBH,CAAAA,EAAmB,IAAA,CACnBC,CAAAA,EAAoB,IAAA,CACpBC,CAAAA,EAAwB,IAC7B,CAAA,CAEA,OAAA,IAAA,CAAK,YAAA,CAAaC,CAAAA,CAAQL,CAAG,EACtBA,CAAAA,CAAI,MAAA,CAAOK,CAAAA,CAAO,MAAM,CAAA,CAAE,IAAA,CAAKA,CAAAA,CAAO,IAAI,CACrD,CAAA,MAASC,CAAAA,CAAO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IAAA,CAAK,WAAA,CAAYG,CAAU,CAAA,CAChD,OAAA,IAAA,CAAK,YAAA,CAAaH,EAAQL,CAAG,CAAA,CACtBA,CAAAA,CAAI,MAAA,CAAOK,CAAAA,CAAO,MAAM,CAAA,CAAE,IAAA,CAAKA,CAAAA,CAAO,IAAI,CACrD,CAAA,MAASC,CAAAA,CAAO,CACZ,OAAAL,CAAAA,CAAKK,CAAK,CAAA,CACHN,CACX,CACJ,CAEA,WAAA,EAAc,CACV,OAAO,CAEH,GAAA,CAAK,CAACD,CAAAA,CAAqBC,CAAAA,CAAsBC,CAAAA,GAAuB,IAAA,CAAK,SAAA,CAAUF,CAAAA,CAAKC,EAAKC,CAAI,CAAA,CACrG,IAAA,CAAM,CAACF,CAAAA,CAAqBC,CAAAA,CAAsBC,CAAAA,GAAuB,IAAA,CAAK,UAAA,CAAWF,CAAAA,CAAKC,CAAAA,CAAKC,CAAI,CAAA,CAGvG,OAAA,CAAS,CAACF,CAAAA,CAAqBC,EAAsBC,CAAAA,GAAuB,IAAA,CAAK,SAAA,CAAUF,CAAAA,CAAKC,CAAAA,CAAKC,CAAI,CAAA,CAGzG,IAAA,CAAM,CAACF,CAAAA,CAAqBC,CAAAA,CAAsBC,CAAAA,GAAuB,IAAA,CAAK,UAAA,CAAWF,CAAAA,CAAKC,CAAAA,CAAKC,CAAI,CAAA,CAGvG,SAAA,CAAW,IAAA,CAAK,gBACpB,CACJ,CACJ,CAAA,CAEO,SAASQ,CAAAA,CAAeX,CAAAA,CAA8B,CAEzD,OADgB,IAAIF,CAAAA,CAAsBE,CAAM,CAAA,CACjC,aACnB","file":"chunk-ZMNXRMWK.js","sourcesContent":["import { BaseRequest, BaseResponse, BaseWebhookConfig, BaseWebhookHandler } from './handler';\n\n// Express-like interfaces to avoid direct Express dependency\nexport interface ExpressRequest extends BaseRequest {\n method: string;\n url: string;\n headers: Record<string, string | string[] | undefined>;\n body?: any;\n query: Record<string, any>;\n rawBody?: any;\n}\n\nexport interface ExpressResponse extends BaseResponse<ExpressResponse> {\n status(code: number): ExpressResponse;\n json(data: any): ExpressResponse;\n send(data?: any): ExpressResponse;\n setHeader(name: string, value: string): void;\n}\n\nexport interface NextFunction {\n (error?: any): void;\n}\n\nexport interface ExpressWebhookConfig extends BaseWebhookConfig {\n path?: string;\n}\n\n/**\n * Express-specific webhook handler extending the base handler\n */\nclass ExpressWebhookHandler extends BaseWebhookHandler<ExpressRequest, ExpressResponse> {\n constructor(config: ExpressWebhookConfig) {\n super(config);\n }\n\n protected async handleGet(req: ExpressRequest, res: ExpressResponse, next: NextFunction): Promise<ExpressResponse> {\n try {\n const { 'hub.mode': mode, 'hub.verify_token': token, 'hub.challenge': challenge } = req.query;\n\n const result = await this.processVerification(\n (mode as string) || null,\n (token as string) || null,\n (challenge as string) || null,\n );\n\n this.applyHeaders(result, res);\n return res.status(result.status).send(result.body);\n } catch (error) {\n next(error);\n return res;\n }\n }\n\n protected async handlePost(\n req: ExpressRequest,\n res: ExpressResponse,\n next: NextFunction,\n ): Promise<ExpressResponse> {\n try {\n const fullUrl = this.constructFullUrl(req.headers, req.url);\n const webRequest = new globalThis.Request(fullUrl, {\n method: req.method,\n headers: req.headers as HeadersInit,\n body: JSON.stringify(req.body),\n });\n\n const result = await this.processWebhook(webRequest);\n this.applyHeaders(result, res);\n return res.status(result.status).send(result.body);\n } catch (error) {\n next(error);\n return res;\n }\n }\n\n protected async handleFlow(\n req: ExpressRequest,\n res: ExpressResponse,\n next: NextFunction,\n ): Promise<ExpressResponse> {\n try {\n const fullUrl = this.constructFullUrl(req.headers, req.url);\n const webRequest = new globalThis.Request(fullUrl, {\n method: req.method,\n headers: req.headers as HeadersInit,\n body: req.method === 'POST' ? JSON.stringify(req.body) : undefined,\n });\n\n const result = await this.processFlow(webRequest);\n this.applyHeaders(result, res);\n return res.status(result.status).send(result.body);\n } catch (error) {\n next(error);\n return res;\n }\n }\n\n getHandlers() {\n return {\n // Method handlers for clean destructuring\n GET: (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => this.handleGet(req, res, next),\n POST: (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => this.handlePost(req, res, next),\n\n // Auto-routing webhook handler\n webhook: (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => this.autoRoute(req, res, next),\n\n // Flow handler\n flow: (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => this.handleFlow(req, res, next),\n\n // Expose processor for handler registration\n processor: this.webhookProcessor,\n };\n }\n}\n\nexport function webhookHandler(config: ExpressWebhookConfig) {\n const handler = new ExpressWebhookHandler(config);\n return handler.getHandlers();\n}\n"]}
|
|
@@ -422,4 +422,4 @@ declare class MessagesClass extends BaseClass {
|
|
|
422
422
|
status(params: StatusParams): Promise<MessagesResponse>;
|
|
423
423
|
}
|
|
424
424
|
|
|
425
|
-
export { type AudioMediaObject as A, type ContactObject as C, type DocumentMediaObject$1 as D, type ImageMediaObject$1 as I, type LocationObject as L, type
|
|
425
|
+
export { type AudioMediaObject as A, type ContactObject as C, type DocumentMediaObject$1 as D, type GeneralMessageBody as G, type ImageMediaObject$1 as I, type LocationObject as L, type MessageRequestBody as M, type NameObject as N, type ReactionParams as R, type StatusParams as S, type TextMessageParams as T, type VideoMediaObject$1 as V, type MessageRequestParams as a, MessagesClass as b, type MessagesResponse as c, type TextObject as d, type StickerMediaObject as e, type InteractiveObject as f, type MessageTemplateObject as g, type AddressesObject as h };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { e as ResponseSuccess } from './request-vYMaEfk5.js';
|
|
2
|
+
import { IncomingMessage, IncomingHttpHeaders } from 'http';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Enum for Flow Status
|
|
@@ -171,6 +172,32 @@ interface ValidateFlowJsonResponse {
|
|
|
171
172
|
success: boolean;
|
|
172
173
|
validation_errors?: FlowValidationError[];
|
|
173
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* WhatsApp Flow Endpoint - Encrypted Request Payload
|
|
177
|
+
* Represents the raw encrypted data received from WhatsApp
|
|
178
|
+
*/
|
|
179
|
+
interface FlowEncryptedRequestPayload {
|
|
180
|
+
encrypted_aes_key: string;
|
|
181
|
+
encrypted_flow_data: string;
|
|
182
|
+
initial_vector: string;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* WhatsApp Flow Endpoint - Decrypted Request Response
|
|
186
|
+
* Represents the successfully decrypted data and encryption keys
|
|
187
|
+
*/
|
|
188
|
+
interface FlowDecryptedRequestResponse {
|
|
189
|
+
decryptedBody: any;
|
|
190
|
+
aesKeyBuffer: Buffer;
|
|
191
|
+
initialVectorBuffer: Buffer;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* WhatsApp Flow Endpoint - HTTP Request with Body
|
|
195
|
+
* Represents an HTTP request with the encrypted payload
|
|
196
|
+
*/
|
|
197
|
+
interface FlowHttpRequest extends IncomingMessage {
|
|
198
|
+
body: FlowEncryptedRequestPayload;
|
|
199
|
+
headers: IncomingHttpHeaders;
|
|
200
|
+
}
|
|
174
201
|
/**
|
|
175
202
|
* WhatsApp Flow Endpoint - Health Check Request
|
|
176
203
|
* Represents the structure of a health check request
|
|
@@ -373,4 +400,4 @@ interface FlowClass {
|
|
|
373
400
|
}): Promise<FlowMigrationResponse>;
|
|
374
401
|
}
|
|
375
402
|
|
|
376
|
-
export { type
|
|
403
|
+
export { type FlowValidationError as A, type FlowValidationErrorPointer as B, type PaginationCursors as C, type CreateFlowResponse as D, FlowTypeEnum as F, type Pagination as P, type UpdateFlowResponse as U, type ValidateFlowJsonResponse as V, FlowActionEnum as a, FlowCategoryEnum as b, FlowStatusEnum as c, type Flow as d, type FlowAsset as e, type FlowAssetsResponse as f, type FlowClass as g, type FlowDataExchangeRequest as h, type FlowDataExchangeResponse as i, type FlowDecryptedRequestResponse as j, type FlowEncryptedRequestPayload as k, type FlowEndpointRequest as l, type FlowEndpointResponse as m, type FlowErrorNotificationRequest as n, type FlowErrorNotificationResponse as o, type FlowHealthCheckRequest as p, type FlowHealthCheckResponse as q, type FlowHttpRequest as r, type FlowMigrationFailure as s, type FlowMigrationResult as t, type FlowMigrationResponse as u, type FlowPreview as v, type FlowPreviewResponse as w, type FlowsListResponse as x, type FlowSuccessScreenResponse as y, type FlowType as z };
|
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as WebhookProcessor } from '../../../WebhookProcessor-
|
|
1
|
+
import { B as BaseWebhookConfig, a as BaseRequest, b as BaseResponse } from '../../../handler-DbySwF0E.js';
|
|
2
|
+
import { c as WebhookProcessor } from '../../../WebhookProcessor-CE4xBPe0.js';
|
|
3
|
+
import '../../../types/config.js';
|
|
3
4
|
import '../../../enums-BZd9T2ul.js';
|
|
4
|
-
import '../../../common-
|
|
5
|
+
import '../../../common-nVoO5ROn.js';
|
|
5
6
|
import '../../../request-vYMaEfk5.js';
|
|
6
|
-
import '
|
|
7
|
+
import 'http';
|
|
8
|
+
import '../../../WhatsApp-iAly_4pr.js';
|
|
7
9
|
import '../../../httpsClient-v4gmltzS.js';
|
|
8
10
|
import 'https';
|
|
9
|
-
import '../../../EncryptionApi-
|
|
11
|
+
import '../../../EncryptionApi-Dyea0SR3.js';
|
|
10
12
|
import '../../../base-CdGDdVEl.js';
|
|
11
|
-
import '../../../FlowApi-
|
|
13
|
+
import '../../../FlowApi-DvoT7ivY.js';
|
|
12
14
|
import '../../../MediaApi-BrEKpqi_.js';
|
|
13
|
-
import '../../../MessageApi-
|
|
14
|
-
import '../../../common-
|
|
15
|
+
import '../../../MessageApi-D-9SuL4w.js';
|
|
16
|
+
import '../../../common-CzzMWFoO.js';
|
|
15
17
|
import '../../../PhoneNumberApi-DKlu9PHl.js';
|
|
16
|
-
import '../../../BusinessProfileApi-
|
|
18
|
+
import '../../../BusinessProfileApi-CW0emncx.js';
|
|
17
19
|
import '../../../QrCodeApi-7vDwIBHR.js';
|
|
18
20
|
import '../../../RegistrationApi-qO_qoti9.js';
|
|
19
|
-
import '../../../TemplateApi-
|
|
21
|
+
import '../../../TemplateApi-D4_6LvhN.js';
|
|
20
22
|
import '../../../TwoStepVerificationApi-DfNPIz-C.js';
|
|
21
|
-
import '../../../WabaApi-
|
|
23
|
+
import '../../../WabaApi-BvY1JVRH.js';
|
|
22
24
|
|
|
23
|
-
interface ExpressRequest {
|
|
25
|
+
interface ExpressRequest extends BaseRequest {
|
|
24
26
|
method: string;
|
|
25
27
|
url: string;
|
|
26
28
|
headers: Record<string, string | string[] | undefined>;
|
|
@@ -28,7 +30,7 @@ interface ExpressRequest {
|
|
|
28
30
|
query: Record<string, any>;
|
|
29
31
|
rawBody?: any;
|
|
30
32
|
}
|
|
31
|
-
interface ExpressResponse {
|
|
33
|
+
interface ExpressResponse extends BaseResponse<ExpressResponse> {
|
|
32
34
|
status(code: number): ExpressResponse;
|
|
33
35
|
json(data: any): ExpressResponse;
|
|
34
36
|
send(data?: any): ExpressResponse;
|
|
@@ -37,12 +39,14 @@ interface ExpressResponse {
|
|
|
37
39
|
interface NextFunction {
|
|
38
40
|
(error?: any): void;
|
|
39
41
|
}
|
|
40
|
-
interface ExpressWebhookConfig extends
|
|
42
|
+
interface ExpressWebhookConfig extends BaseWebhookConfig {
|
|
41
43
|
path?: string;
|
|
42
44
|
}
|
|
43
45
|
declare function webhookHandler(config: ExpressWebhookConfig): {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
GET: (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => Promise<ExpressResponse>;
|
|
47
|
+
POST: (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => Promise<ExpressResponse>;
|
|
48
|
+
webhook: (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => Promise<any>;
|
|
49
|
+
flow: (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => Promise<ExpressResponse>;
|
|
46
50
|
processor: WebhookProcessor;
|
|
47
51
|
};
|
|
48
52
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{a as webhookHandler}from'../../../chunk-
|
|
1
|
+
export{a as webhookHandler}from'../../../chunk-ZMNXRMWK.js';import'../../../chunk-5577QQ7V.js';import'../../../chunk-U5FBZ6UB.js';import'../../../chunk-6DFC5L3X.js';import'../../../chunk-BAOZ4U74.js';import'../../../chunk-FKXSL2JK.js';import'../../../chunk-AMHQGG6Z.js';import'../../../chunk-VHAODWCN.js';import'../../../chunk-JPAV644F.js';import'../../../chunk-PHPQ5HP3.js';import'../../../chunk-IYSR44P6.js';import'../../../chunk-SNNRWNGZ.js';import'../../../chunk-L4ESAO2S.js';import'../../../chunk-7QBIZCJ4.js';import'../../../chunk-JXCLRKQ7.js';import'../../../chunk-LV3TULSI.js';import'../../../chunk-CRZ7EUYR.js';import'../../../chunk-JC6YMVID.js';import'../../../chunk-J2JPTKU6.js';import'../../../chunk-FSKBLPGE.js';import'../../../chunk-MJEG3K4V.js';import'../../../chunk-RIL6QABY.js';import'../../../chunk-KMAH6636.js';//# sourceMappingURL=express.js.map
|
|
2
2
|
//# sourceMappingURL=express.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { WhatsAppConfig } from '../../../types/config.js';
|
|
2
|
+
import { c as WebhookProcessor } from '../../../WebhookProcessor-CE4xBPe0.js';
|
|
3
|
+
import '../../../enums-BZd9T2ul.js';
|
|
4
|
+
import '../../../common-nVoO5ROn.js';
|
|
5
|
+
import '../../../request-vYMaEfk5.js';
|
|
6
|
+
import 'http';
|
|
7
|
+
import '../../../WhatsApp-iAly_4pr.js';
|
|
8
|
+
import '../../../httpsClient-v4gmltzS.js';
|
|
9
|
+
import 'https';
|
|
10
|
+
import '../../../EncryptionApi-Dyea0SR3.js';
|
|
11
|
+
import '../../../base-CdGDdVEl.js';
|
|
12
|
+
import '../../../FlowApi-DvoT7ivY.js';
|
|
13
|
+
import '../../../MediaApi-BrEKpqi_.js';
|
|
14
|
+
import '../../../MessageApi-D-9SuL4w.js';
|
|
15
|
+
import '../../../common-CzzMWFoO.js';
|
|
16
|
+
import '../../../PhoneNumberApi-DKlu9PHl.js';
|
|
17
|
+
import '../../../BusinessProfileApi-CW0emncx.js';
|
|
18
|
+
import '../../../QrCodeApi-7vDwIBHR.js';
|
|
19
|
+
import '../../../RegistrationApi-qO_qoti9.js';
|
|
20
|
+
import '../../../TemplateApi-D4_6LvhN.js';
|
|
21
|
+
import '../../../TwoStepVerificationApi-DfNPIz-C.js';
|
|
22
|
+
import '../../../WabaApi-BvY1JVRH.js';
|
|
23
|
+
|
|
24
|
+
interface NextRequest extends Request {
|
|
25
|
+
nextUrl: {
|
|
26
|
+
searchParams: URLSearchParams;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
interface NextResponse {
|
|
30
|
+
json(data: any): NextResponse;
|
|
31
|
+
}
|
|
32
|
+
interface NextJsAppWebhookConfig extends WhatsAppConfig {
|
|
33
|
+
}
|
|
34
|
+
declare function webhookHandler(config: NextJsAppWebhookConfig): {
|
|
35
|
+
GET: (request: NextRequest) => Promise<Response>;
|
|
36
|
+
POST: (request: NextRequest) => Promise<Response>;
|
|
37
|
+
webhook: {
|
|
38
|
+
GET: (request: NextRequest) => Promise<Response>;
|
|
39
|
+
POST: (request: NextRequest) => Promise<Response>;
|
|
40
|
+
};
|
|
41
|
+
flow: {
|
|
42
|
+
GET: (request: NextRequest) => Promise<Response>;
|
|
43
|
+
POST: (request: NextRequest) => Promise<Response>;
|
|
44
|
+
};
|
|
45
|
+
processor: WebhookProcessor;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { type NextJsAppWebhookConfig, type NextRequest, type NextResponse, webhookHandler };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {d}from'../../../chunk-U5FBZ6UB.js';import'../../../chunk-6DFC5L3X.js';import'../../../chunk-BAOZ4U74.js';import'../../../chunk-FKXSL2JK.js';import'../../../chunk-AMHQGG6Z.js';import'../../../chunk-VHAODWCN.js';import'../../../chunk-JPAV644F.js';import'../../../chunk-PHPQ5HP3.js';import'../../../chunk-IYSR44P6.js';import'../../../chunk-SNNRWNGZ.js';import'../../../chunk-L4ESAO2S.js';import'../../../chunk-7QBIZCJ4.js';import'../../../chunk-JXCLRKQ7.js';import'../../../chunk-LV3TULSI.js';import'../../../chunk-CRZ7EUYR.js';import'../../../chunk-JC6YMVID.js';import'../../../chunk-J2JPTKU6.js';import'../../../chunk-FSKBLPGE.js';import'../../../chunk-MJEG3K4V.js';import'../../../chunk-RIL6QABY.js';import'../../../chunk-KMAH6636.js';function p(u){let s=new d(u);return {GET:async r=>{try{let{searchParams:e}=new URL(r.url),o=e.get("hub.mode"),n=e.get("hub.verify_token"),a=e.get("hub.challenge"),t=await s.processVerification(o,n,a);return new Response(t.body,{status:t.status,headers:t.headers})}catch(e){return console.error("Webhook verification error:",e),new Response("Internal Server Error",{status:500})}},POST:async r=>{try{let e=await s.processWebhook(r);return new Response(e.body,{status:e.status,headers:e.headers})}catch(e){return console.error("Webhook processing error:",e),new Response("Internal Server Error",{status:500})}},webhook:{GET:async r=>{try{let{searchParams:e}=new URL(r.url),o=e.get("hub.mode"),n=e.get("hub.verify_token"),a=e.get("hub.challenge"),t=await s.processVerification(o,n,a);return new Response(t.body,{status:t.status,headers:t.headers})}catch(e){return console.error("Webhook verification error:",e),new Response("Internal Server Error",{status:500})}},POST:async r=>{try{let e=await s.processWebhook(r);return new Response(e.body,{status:e.status,headers:e.headers})}catch(e){return console.error("Webhook processing error:",e),new Response("Internal Server Error",{status:500})}}},flow:{GET:async r=>{try{let e=await s.processFlow(r);return Response.json(e.body,{status:e.status,headers:e.headers})}catch(e){return console.error("Flow GET error:",e),new Response("Internal Server Error",{status:500})}},POST:async r=>{try{let e=await s.processFlow(r);return Response.json(e.body,{status:e.status,headers:e.headers})}catch(e){return console.error("Flow POST error:",e),new Response("Internal Server Error",{status:500})}}},processor:s}}export{p as webhookHandler};//# sourceMappingURL=nextjs-app.js.map
|
|
2
|
+
//# sourceMappingURL=nextjs-app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/webhook/frameworks/nextjs-app.ts"],"names":["webhookHandler","config","processor","WebhookProcessor","request","searchParams","mode","token","challenge","result","error"],"mappings":"uuBAkBO,SAASA,EAAeC,CAAAA,CAAgC,CAC3D,IAAMC,CAAAA,CAAY,IAAIC,CAAAA,CAAiBF,CAAM,CAAA,CAE7C,OAAO,CAEH,GAAA,CAAK,MAAOG,GAAyB,CACjC,GAAI,CACA,GAAM,CAAE,YAAA,CAAAC,CAAa,EAAI,IAAI,GAAA,CAAID,EAAQ,GAAG,CAAA,CACtCE,EAAOD,CAAAA,CAAa,GAAA,CAAI,UAAU,CAAA,CAClCE,EAAQF,CAAAA,CAAa,GAAA,CAAI,kBAAkB,CAAA,CAC3CG,CAAAA,CAAYH,EAAa,GAAA,CAAI,eAAe,CAAA,CAE5CI,CAAAA,CAAS,MAAMP,CAAAA,CAAU,mBAAA,CAAoBI,CAAAA,CAAMC,CAAAA,CAAOC,CAAS,CAAA,CAGzE,OAAO,IAAI,QAAA,CAASC,EAAO,IAAA,CAAM,CAC7B,OAAQA,CAAAA,CAAO,MAAA,CACf,QAASA,CAAAA,CAAO,OACpB,CAAC,CACL,OAASC,CAAAA,CAAO,CACZ,eAAQ,KAAA,CAAM,6BAAA,CAA+BA,CAAK,CAAA,CAC3C,IAAI,QAAA,CAAS,uBAAA,CAAyB,CAAE,MAAA,CAAQ,GAAI,CAAC,CAChE,CACJ,EAEA,IAAA,CAAM,MAAON,CAAAA,EAAyB,CAClC,GAAI,CACA,IAAMK,CAAAA,CAAS,MAAMP,EAAU,cAAA,CAAeE,CAAO,CAAA,CAGrD,OAAO,IAAI,QAAA,CAASK,CAAAA,CAAO,KAAM,CAC7B,MAAA,CAAQA,EAAO,MAAA,CACf,OAAA,CAASA,CAAAA,CAAO,OACpB,CAAC,CACL,CAAA,MAASC,EAAO,CACZ,OAAA,OAAA,CAAQ,MAAM,2BAAA,CAA6BA,CAAK,CAAA,CACzC,IAAI,SAAS,uBAAA,CAAyB,C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,CAElD,OAAO,QAAA,CAAS,KAAKK,CAAAA,CAAO,IAAA,CAAM,CAC9B,MAAA,CAAQA,EAAO,MAAA,CACf,OAAA,CAASA,EAAO,OACpB,CAAC,CACL,CAAA,MAASC,CAAAA,CAAO,CACZ,OAAA,OAAA,CAAQ,MAAM,iBAAA,CAAmBA,CAAK,EAC/B,IAAI,QAAA,CAAS,wBAAyB,CAAE,MAAA,CAAQ,GAAI,CAAC,CAChE,CACJ,CAAA,CAEA,KAAM,MAAON,CAAAA,EAAyB,CAClC,GAAI,CACA,IAAMK,CAAAA,CAAS,MAAMP,CAAAA,CAAU,WAAA,CAAYE,CAAO,CAAA,CAElD,OAAO,SAAS,IAAA,CAAKK,CAAAA,CAAO,IAAA,CAAM,CAC9B,OAAQA,CAAAA,CAAO,MAAA,CACf,QAASA,CAAAA,CAAO,OACpB,CAAC,CACL,CAAA,MAASC,CAAAA,CAAO,CACZ,eAAQ,KAAA,CAAM,kBAAA,CAAoBA,CAAK,CAAA,CAChC,IAAI,SAAS,uBAAA,CAAyB,CAAE,MAAA,CAAQ,GAAI,CAAC,CAChE,CACJ,CACJ,CAAA,CAGA,SAAA,CAAAR,CACJ,CACJ","file":"nextjs-app.js","sourcesContent":["import { WhatsAppConfig } from '../../../types/config';\nimport { WebhookProcessor } from '../WebhookProcessor';\n\n// Define Next.js types locally to avoid requiring Next.js as a dependency\nexport interface NextRequest extends Request {\n nextUrl: {\n searchParams: URLSearchParams;\n };\n}\n\nexport interface NextResponse {\n json(data: any): NextResponse;\n}\n\nexport interface NextJsAppWebhookConfig extends WhatsAppConfig {\n // App Router specific config (currently none, but interface reserved for future use)\n}\n\nexport function webhookHandler(config: NextJsAppWebhookConfig) {\n const processor = new WebhookProcessor(config);\n\n return {\n // Clean GET/POST handlers following whatsapp-api-js methodology\n GET: async (request: NextRequest) => {\n try {\n const { searchParams } = new URL(request.url);\n const mode = searchParams.get('hub.mode');\n const token = searchParams.get('hub.verify_token');\n const challenge = searchParams.get('hub.challenge');\n\n const result = await processor.processVerification(mode, token, challenge);\n\n // Return plain text response for webhook verification\n return new Response(result.body, {\n status: result.status,\n headers: result.headers,\n });\n } catch (error) {\n console.error('Webhook verification error:', error);\n return new Response('Internal Server Error', { status: 500 });\n }\n },\n\n POST: async (request: NextRequest) => {\n try {\n const result = await processor.processWebhook(request);\n\n // Return JSON response for webhook processing\n return new Response(result.body, {\n status: result.status,\n headers: result.headers,\n });\n } catch (error) {\n console.error('Webhook processing error:', error);\n return new Response('Internal Server Error', { status: 500 });\n }\n },\n\n // Legacy webhook object for backward compatibility\n webhook: {\n GET: async (request: NextRequest) => {\n try {\n const { searchParams } = new URL(request.url);\n const mode = searchParams.get('hub.mode');\n const token = searchParams.get('hub.verify_token');\n const challenge = searchParams.get('hub.challenge');\n\n const result = await processor.processVerification(mode, token, challenge);\n return new Response(result.body, {\n status: result.status,\n headers: result.headers,\n });\n } catch (error) {\n console.error('Webhook verification error:', error);\n return new Response('Internal Server Error', { status: 500 });\n }\n },\n\n POST: async (request: NextRequest) => {\n try {\n const result = await processor.processWebhook(request);\n return new Response(result.body, {\n status: result.status,\n headers: result.headers,\n });\n } catch (error) {\n console.error('Webhook processing error:', error);\n return new Response('Internal Server Error', { status: 500 });\n }\n },\n },\n\n // Flow handler for App Router\n flow: {\n GET: async (request: NextRequest) => {\n try {\n const result = await processor.processFlow(request);\n\n return Response.json(result.body, {\n status: result.status,\n headers: result.headers,\n });\n } catch (error) {\n console.error('Flow GET error:', error);\n return new Response('Internal Server Error', { status: 500 });\n }\n },\n\n POST: async (request: NextRequest) => {\n try {\n const result = await processor.processFlow(request);\n\n return Response.json(result.body, {\n status: result.status,\n headers: result.headers,\n });\n } catch (error) {\n console.error('Flow POST error:', error);\n return new Response('Internal Server Error', { status: 500 });\n }\n },\n },\n\n // Expose processor for handler registration\n processor,\n };\n}\n"]}
|
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as WebhookProcessor } from '../../../WebhookProcessor-
|
|
1
|
+
import { a as BaseRequest, b as BaseResponse, B as BaseWebhookConfig } from '../../../handler-DbySwF0E.js';
|
|
2
|
+
import { c as WebhookProcessor } from '../../../WebhookProcessor-CE4xBPe0.js';
|
|
3
|
+
import '../../../types/config.js';
|
|
3
4
|
import '../../../enums-BZd9T2ul.js';
|
|
4
|
-
import '../../../common-
|
|
5
|
+
import '../../../common-nVoO5ROn.js';
|
|
5
6
|
import '../../../request-vYMaEfk5.js';
|
|
6
|
-
import '
|
|
7
|
+
import 'http';
|
|
8
|
+
import '../../../WhatsApp-iAly_4pr.js';
|
|
7
9
|
import '../../../httpsClient-v4gmltzS.js';
|
|
8
10
|
import 'https';
|
|
9
|
-
import '../../../EncryptionApi-
|
|
11
|
+
import '../../../EncryptionApi-Dyea0SR3.js';
|
|
10
12
|
import '../../../base-CdGDdVEl.js';
|
|
11
|
-
import '../../../FlowApi-
|
|
13
|
+
import '../../../FlowApi-DvoT7ivY.js';
|
|
12
14
|
import '../../../MediaApi-BrEKpqi_.js';
|
|
13
|
-
import '../../../MessageApi-
|
|
14
|
-
import '../../../common-
|
|
15
|
+
import '../../../MessageApi-D-9SuL4w.js';
|
|
16
|
+
import '../../../common-CzzMWFoO.js';
|
|
15
17
|
import '../../../PhoneNumberApi-DKlu9PHl.js';
|
|
16
|
-
import '../../../BusinessProfileApi-
|
|
18
|
+
import '../../../BusinessProfileApi-CW0emncx.js';
|
|
17
19
|
import '../../../QrCodeApi-7vDwIBHR.js';
|
|
18
20
|
import '../../../RegistrationApi-qO_qoti9.js';
|
|
19
|
-
import '../../../TemplateApi-
|
|
21
|
+
import '../../../TemplateApi-D4_6LvhN.js';
|
|
20
22
|
import '../../../TwoStepVerificationApi-DfNPIz-C.js';
|
|
21
|
-
import '../../../WabaApi-
|
|
23
|
+
import '../../../WabaApi-BvY1JVRH.js';
|
|
22
24
|
|
|
23
|
-
interface BaseApiRequest {
|
|
25
|
+
interface BaseApiRequest extends BaseRequest {
|
|
24
26
|
method?: string;
|
|
25
27
|
url?: string;
|
|
26
28
|
headers: Record<string, string | string[] | undefined>;
|
|
@@ -28,15 +30,17 @@ interface BaseApiRequest {
|
|
|
28
30
|
query: Partial<Record<string, string | string[]>>;
|
|
29
31
|
rawBody?: any;
|
|
30
32
|
}
|
|
31
|
-
interface BaseApiResponse {
|
|
33
|
+
interface BaseApiResponse extends BaseResponse {
|
|
32
34
|
status(code: number): any;
|
|
33
35
|
json(data: any): void | any;
|
|
34
36
|
send(data?: any): void | any;
|
|
35
37
|
setHeader(name: string, value: string): void;
|
|
36
38
|
}
|
|
37
|
-
interface NextJsWebhookConfig extends
|
|
39
|
+
interface NextJsWebhookConfig extends BaseWebhookConfig {
|
|
38
40
|
}
|
|
39
41
|
declare function webhookHandler<TRequest extends BaseApiRequest, TResponse extends BaseApiResponse>(config: NextJsWebhookConfig): {
|
|
42
|
+
GET: (req: TRequest, res: TResponse) => Promise<any>;
|
|
43
|
+
POST: (req: TRequest, res: TResponse) => Promise<any>;
|
|
40
44
|
webhook: (req: TRequest, res: TResponse) => Promise<any>;
|
|
41
45
|
flow: (req: TRequest, res: TResponse) => Promise<any>;
|
|
42
46
|
processor: WebhookProcessor;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{a as webhookHandler}from'../../../chunk-
|
|
1
|
+
export{a as webhookHandler}from'../../../chunk-GM63NGNV.js';import'../../../chunk-5577QQ7V.js';import'../../../chunk-U5FBZ6UB.js';import'../../../chunk-6DFC5L3X.js';import'../../../chunk-BAOZ4U74.js';import'../../../chunk-FKXSL2JK.js';import'../../../chunk-AMHQGG6Z.js';import'../../../chunk-VHAODWCN.js';import'../../../chunk-JPAV644F.js';import'../../../chunk-PHPQ5HP3.js';import'../../../chunk-IYSR44P6.js';import'../../../chunk-SNNRWNGZ.js';import'../../../chunk-L4ESAO2S.js';import'../../../chunk-7QBIZCJ4.js';import'../../../chunk-JXCLRKQ7.js';import'../../../chunk-LV3TULSI.js';import'../../../chunk-CRZ7EUYR.js';import'../../../chunk-JC6YMVID.js';import'../../../chunk-J2JPTKU6.js';import'../../../chunk-FSKBLPGE.js';import'../../../chunk-MJEG3K4V.js';import'../../../chunk-RIL6QABY.js';import'../../../chunk-KMAH6636.js';//# sourceMappingURL=nextjs.js.map
|
|
2
2
|
//# sourceMappingURL=nextjs.js.map
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
export { ExpressRequest, ExpressResponse, webhookHandler as ExpressWebhook, ExpressWebhookConfig, NextFunction } from './frameworks/express.js';
|
|
2
2
|
export { webhookHandler as NextJsWebhook, NextJsWebhookConfig } from './frameworks/nextjs.js';
|
|
3
|
-
export { F as FlowHandler, e as MessageHandler, M as MessageStatus, W as WebhookContact, a as WebhookEvent, b as WebhookMessage, c as WebhookProcessor, d as WebhookResponse, g as constructFullUrl, f as processFlowRequest, p as processWebhookMessages } from '../../WebhookProcessor-
|
|
3
|
+
export { F as FlowHandler, e as MessageHandler, M as MessageStatus, W as WebhookContact, a as WebhookEvent, b as WebhookMessage, c as WebhookProcessor, d as WebhookResponse, g as constructFullUrl, f as processFlowRequest, p as processWebhookMessages } from '../../WebhookProcessor-CE4xBPe0.js';
|
|
4
|
+
import '../../handler-DbySwF0E.js';
|
|
4
5
|
import '../../types/config.js';
|
|
5
6
|
import '../../enums-BZd9T2ul.js';
|
|
6
|
-
import '../../common-
|
|
7
|
+
import '../../common-nVoO5ROn.js';
|
|
7
8
|
import '../../request-vYMaEfk5.js';
|
|
8
|
-
import '
|
|
9
|
+
import 'http';
|
|
10
|
+
import '../../WhatsApp-iAly_4pr.js';
|
|
9
11
|
import '../../httpsClient-v4gmltzS.js';
|
|
10
12
|
import 'https';
|
|
11
|
-
import '../../EncryptionApi-
|
|
13
|
+
import '../../EncryptionApi-Dyea0SR3.js';
|
|
12
14
|
import '../../base-CdGDdVEl.js';
|
|
13
|
-
import '../../FlowApi-
|
|
15
|
+
import '../../FlowApi-DvoT7ivY.js';
|
|
14
16
|
import '../../MediaApi-BrEKpqi_.js';
|
|
15
|
-
import '../../MessageApi-
|
|
16
|
-
import '../../common-
|
|
17
|
+
import '../../MessageApi-D-9SuL4w.js';
|
|
18
|
+
import '../../common-CzzMWFoO.js';
|
|
17
19
|
import '../../PhoneNumberApi-DKlu9PHl.js';
|
|
18
|
-
import '../../BusinessProfileApi-
|
|
20
|
+
import '../../BusinessProfileApi-CW0emncx.js';
|
|
19
21
|
import '../../QrCodeApi-7vDwIBHR.js';
|
|
20
22
|
import '../../RegistrationApi-qO_qoti9.js';
|
|
21
|
-
import '../../TemplateApi-
|
|
23
|
+
import '../../TemplateApi-D4_6LvhN.js';
|
|
22
24
|
import '../../TwoStepVerificationApi-DfNPIz-C.js';
|
|
23
|
-
import '../../WabaApi-
|
|
25
|
+
import '../../WabaApi-BvY1JVRH.js';
|
|
24
26
|
|
|
25
27
|
declare const generateXHub256Sig: (body: string, appSecret: string) => string;
|
|
26
28
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{a as generateXHub256Sig}from'../../chunk-RWCVPWRC.js';export{a as ExpressWebhook}from'../../chunk-
|
|
1
|
+
export{a as generateXHub256Sig}from'../../chunk-RWCVPWRC.js';export{a as ExpressWebhook}from'../../chunk-ZMNXRMWK.js';export{a as NextJsWebhook}from'../../chunk-GM63NGNV.js';import'../../chunk-5577QQ7V.js';export{d as WebhookProcessor,c as constructFullUrl,b as processFlowRequest,a as processWebhookMessages}from'../../chunk-U5FBZ6UB.js';import'../../chunk-6DFC5L3X.js';import'../../chunk-BAOZ4U74.js';import'../../chunk-FKXSL2JK.js';import'../../chunk-AMHQGG6Z.js';import'../../chunk-VHAODWCN.js';import'../../chunk-JPAV644F.js';import'../../chunk-PHPQ5HP3.js';import'../../chunk-IYSR44P6.js';import'../../chunk-SNNRWNGZ.js';import'../../chunk-L4ESAO2S.js';import'../../chunk-7QBIZCJ4.js';import'../../chunk-JXCLRKQ7.js';import'../../chunk-LV3TULSI.js';import'../../chunk-CRZ7EUYR.js';import'../../chunk-JC6YMVID.js';import'../../chunk-J2JPTKU6.js';import'../../chunk-FSKBLPGE.js';import'../../chunk-MJEG3K4V.js';import'../../chunk-RIL6QABY.js';import'../../chunk-KMAH6636.js';//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { E as EncryptionApi } from '../../EncryptionApi-
|
|
2
|
-
import { F as FlowApi } from '../../FlowApi-
|
|
1
|
+
import { E as EncryptionApi } from '../../EncryptionApi-Dyea0SR3.js';
|
|
2
|
+
import { F as FlowApi } from '../../FlowApi-DvoT7ivY.js';
|
|
3
3
|
import { WhatsAppConfig } from '../../types/config.js';
|
|
4
4
|
import { M as MediaApi } from '../../MediaApi-BrEKpqi_.js';
|
|
5
|
-
import { M as MessagesApi } from '../../MessageApi-
|
|
5
|
+
import { M as MessagesApi } from '../../MessageApi-D-9SuL4w.js';
|
|
6
6
|
import { P as PhoneNumberApi } from '../../PhoneNumberApi-DKlu9PHl.js';
|
|
7
|
-
import { B as BusinessProfileApi } from '../../BusinessProfileApi-
|
|
7
|
+
import { B as BusinessProfileApi } from '../../BusinessProfileApi-CW0emncx.js';
|
|
8
8
|
import { Q as QrCodeApi } from '../../QrCodeApi-7vDwIBHR.js';
|
|
9
9
|
import { R as RegistrationApi } from '../../RegistrationApi-qO_qoti9.js';
|
|
10
|
-
import { T as TemplateApi } from '../../TemplateApi-
|
|
10
|
+
import { T as TemplateApi } from '../../TemplateApi-D4_6LvhN.js';
|
|
11
11
|
import { T as TwoStepVerificationApi } from '../../TwoStepVerificationApi-DfNPIz-C.js';
|
|
12
|
-
import { W as WabaApi } from '../../WabaApi-
|
|
13
|
-
export { W as WhatsApp } from '../../WhatsApp-
|
|
12
|
+
import { W as WabaApi } from '../../WabaApi-BvY1JVRH.js';
|
|
13
|
+
export { W as WhatsApp } from '../../WhatsApp-iAly_4pr.js';
|
|
14
14
|
import '../../base-CdGDdVEl.js';
|
|
15
15
|
import '../../enums-BZd9T2ul.js';
|
|
16
16
|
import '../../request-vYMaEfk5.js';
|
|
17
|
-
import '../../common-
|
|
18
|
-
import '
|
|
17
|
+
import '../../common-nVoO5ROn.js';
|
|
18
|
+
import 'http';
|
|
19
|
+
import '../../common-CzzMWFoO.js';
|
|
19
20
|
import '../../httpsClient-v4gmltzS.js';
|
|
20
21
|
import 'https';
|
|
21
22
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{b as WhatsApp}from'../../chunk-BAOZ4U74.js';import'../../chunk-FKXSL2JK.js';import'../../chunk-AMHQGG6Z.js';import'../../chunk-VHAODWCN.js';import'../../chunk-JPAV644F.js';import'../../chunk-PHPQ5HP3.js';import'../../chunk-IYSR44P6.js';import'../../chunk-SNNRWNGZ.js';import'../../chunk-L4ESAO2S.js';import'../../chunk-7QBIZCJ4.js';import'../../chunk-JXCLRKQ7.js';import'../../chunk-LV3TULSI.js';import'../../chunk-CRZ7EUYR.js';import'../../chunk-JC6YMVID.js';import'../../chunk-
|
|
1
|
+
export{b as WhatsApp}from'../../chunk-BAOZ4U74.js';import'../../chunk-FKXSL2JK.js';import'../../chunk-AMHQGG6Z.js';import'../../chunk-VHAODWCN.js';import'../../chunk-JPAV644F.js';import'../../chunk-PHPQ5HP3.js';import'../../chunk-IYSR44P6.js';import'../../chunk-SNNRWNGZ.js';import'../../chunk-L4ESAO2S.js';import'../../chunk-7QBIZCJ4.js';import'../../chunk-JXCLRKQ7.js';import'../../chunk-LV3TULSI.js';import'../../chunk-CRZ7EUYR.js';import'../../chunk-JC6YMVID.js';import'../../chunk-J2JPTKU6.js';import'../../chunk-FSKBLPGE.js';import'../../chunk-MJEG3K4V.js';import'../../chunk-RIL6QABY.js';import'../../chunk-KMAH6636.js';//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|