Skip to content

Commit

Permalink
feat: remove response transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
domwebber committed Dec 4, 2023
1 parent 12fa51a commit 3f047dc
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/CloudAPI/CloudAPIWebhook/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import CloudAPIWebhookError from "./CloudWebhookAPIError";
import { IncomingMessage, ServerResponse } from "http";
import { createHmac } from "node:crypto";

export type ServerResponseTransform = (
response: ServerResponse,
) => ServerResponse;

export interface WebhookAPIRegisterReturn {
/**
* The verify token sent by WhatsApp.
Expand Down Expand Up @@ -47,7 +43,7 @@ export interface WebhookAPIRegisterReturn {
* // Within your request handler:
* return reg.accept();
*/
accept: (transform?: ServerResponseTransform) => ServerResponse;
accept: () => ServerResponse;

/**
* Reject the Webhook Registration.
Expand All @@ -60,7 +56,7 @@ export interface WebhookAPIRegisterReturn {
* // Within your request handler:
* return reg.reject();
*/
reject: (transform?: ServerResponseTransform) => ServerResponse;
reject: () => ServerResponse;
}

export interface WebhookAPIEventNotificationReturn {
Expand All @@ -76,7 +72,7 @@ export interface WebhookAPIEventNotificationReturn {
* // Within your request handler:
* return event.accept();
*/
accept: (transform?: ServerResponseTransform) => ServerResponse;
accept: () => ServerResponse;

/**
* Reject the Incoming Webhook.
Expand All @@ -89,7 +85,7 @@ export interface WebhookAPIEventNotificationReturn {
* // Within your request handler:
* return event.reject();
*/
reject: (transform?: ServerResponseTransform) => ServerResponse;
reject: () => ServerResponse;

/**
* Check the integrity of the request body.
Expand Down Expand Up @@ -169,11 +165,11 @@ export default class CloudAPIWebhook extends AbstractAPI {
return {
verifyToken: hubVerifyToken,
challenge: hubChallenge,
accept: (transform) => {
return (transform?.(res) ?? res).end(hubChallenge);
accept: () => {
return res.end(hubChallenge);
},
reject: (transform) => {
return (transform?.(res) ?? res).end();
reject: () => {
return res.end();
},
};
}
Expand Down Expand Up @@ -248,11 +244,11 @@ export default class CloudAPIWebhook extends AbstractAPI {
throw CloudAPIWebhookError.mismatchedXHubSignature();
}
},
accept: (transform) => {
return (transform?.(res) ?? res).end();
accept: () => {
return res.end();
},
reject: (transform) => {
return (transform?.(res) ?? res).end();
reject: () => {
return res.end();
},
};
}
Expand Down

0 comments on commit 3f047dc

Please sign in to comment.