Refactor webhook handler service and update dependencies
Refactor to make database webhook handler service a function. This change introduces the function `getDatabaseWebhookHandlerService()` to return an instance of the service, allowing easier management of instances. Dependencies are updated as well, including bringing `react-i18next` to version 14.1.1(i18next@23.11.3) and `@react-email/components` to version 0.0.17 and others.
This commit is contained in:
@@ -7,23 +7,31 @@ import { RecordChange, Tables } from '../record-change.type';
|
||||
import { DatabaseWebhookRouterService } from './database-webhook-router.service';
|
||||
import { getDatabaseWebhookVerifier } from './verifier';
|
||||
|
||||
export class DatabaseWebhookHandlerService {
|
||||
export function getDatabaseWebhookHandlerService() {
|
||||
return new DatabaseWebhookHandlerService();
|
||||
}
|
||||
|
||||
class DatabaseWebhookHandlerService {
|
||||
private readonly namespace = 'database-webhook-handler';
|
||||
|
||||
/**
|
||||
* @name handleWebhook
|
||||
* @description Handle the webhook event
|
||||
* @param request
|
||||
*/
|
||||
async handleWebhook(request: Request) {
|
||||
const logger = await getLogger();
|
||||
|
||||
const json = await request.clone().json();
|
||||
const { table, type } = json as RecordChange<keyof Tables>;
|
||||
|
||||
logger.info(
|
||||
{
|
||||
name: this.namespace,
|
||||
table,
|
||||
type,
|
||||
},
|
||||
'Received webhook from DB. Processing...',
|
||||
);
|
||||
const ctx = {
|
||||
name: this.namespace,
|
||||
table,
|
||||
type,
|
||||
};
|
||||
|
||||
logger.info(ctx, 'Received webhook from DB. Processing...');
|
||||
|
||||
// check if the signature is valid
|
||||
const verifier = await getDatabaseWebhookVerifier();
|
||||
@@ -45,20 +53,11 @@ export class DatabaseWebhookHandlerService {
|
||||
// handle the webhook event based on the table
|
||||
await service.handleWebhook(json);
|
||||
|
||||
logger.info(
|
||||
{
|
||||
name: this.namespace,
|
||||
table,
|
||||
type,
|
||||
},
|
||||
'Webhook processed successfully',
|
||||
);
|
||||
logger.info(ctx, 'Webhook processed successfully');
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
{
|
||||
name: this.namespace,
|
||||
table,
|
||||
type,
|
||||
...ctx,
|
||||
error,
|
||||
},
|
||||
'Failed to process webhook',
|
||||
|
||||
Reference in New Issue
Block a user