Migrate Novu functions to wrapEdgeFunction

Refactor Phase 3 Batch 2–4 Novu-related functions to use the createEdgeFunction wrapper, replacing explicit HTTP servers with edge wrapper, adding standardized logging, tracing, and error handling across subscriber management, topic/notification, and migration/sync functions.
This commit is contained in:
gpt-engineer-app[bot]
2025-11-11 03:55:02 +00:00
parent 19804ea9bd
commit a1280ddd05
9 changed files with 166 additions and 569 deletions

View File

@@ -1,16 +1,15 @@
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
import { Novu } from "npm:@novu/api@1.6.0";
import { corsHeaders } from '../_shared/cors.ts';
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
import { edgeLogger } from "../_shared/logger.ts";
import { createEdgeFunction } from '../_shared/edgeFunctionWrapper.ts';
serve(async (req) => {
if (req.method === 'OPTIONS') {
return new Response(null, { headers: corsHeaders });
}
const tracking = startRequest('trigger-notification');
try {
export default createEdgeFunction(
{
name: 'trigger-notification',
requireAuth: false,
corsHeaders: corsHeaders
},
async (req, context) => {
const novuApiKey = Deno.env.get('NOVU_API_KEY');
if (!novuApiKey) {
@@ -38,10 +37,11 @@ serve(async (req) => {
? { subscriberId }
: { topicKey: topicKey! };
context.span.setAttribute('action', 'trigger_notification');
edgeLogger.info('Triggering notification', {
workflowId,
recipient,
requestId: tracking.requestId,
requestId: context.requestId,
action: 'trigger_notification'
});
@@ -53,50 +53,21 @@ serve(async (req) => {
});
edgeLogger.info('Notification triggered successfully', {
requestId: tracking.requestId,
requestId: context.requestId,
transactionId: result.data.transactionId
});
endRequest(tracking, 200);
return new Response(
JSON.stringify({
success: true,
transactionId: result.data.transactionId,
requestId: tracking.requestId
}),
{
headers: {
...corsHeaders,
'Content-Type': 'application/json',
'X-Request-ID': tracking.requestId
},
status: 200,
}
);
} catch (error: unknown) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
edgeLogger.error('Error triggering notification', {
requestId: tracking.requestId,
error: errorMessage
});
endRequest(tracking, 500, errorMessage);
return new Response(
JSON.stringify({
success: false,
error: errorMessage,
requestId: tracking.requestId
}),
{
headers: {
...corsHeaders,
'Content-Type': 'application/json',
'X-Request-ID': tracking.requestId
},
status: 500,
}
);
}
});
);