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('update-novu-subscriber');
try {
export default createEdgeFunction(
{
name: 'update-novu-subscriber',
requireAuth: false,
corsHeaders: corsHeaders
},
async (req, context) => {
const novuApiKey = Deno.env.get('NOVU_API_KEY');
if (!novuApiKey) {
@@ -31,7 +30,8 @@ serve(async (req) => {
data?: Record<string, unknown>;
};
edgeLogger.info('Updating Novu subscriber', { action: 'update_novu_subscriber', subscriberId, email, firstName, requestId: tracking.requestId });
context.span.setAttribute('action', 'update_novu_subscriber');
edgeLogger.info('Updating Novu subscriber', { action: 'update_novu_subscriber', subscriberId, email, firstName, requestId: context.requestId });
const subscriber = await novu.subscribers.update(subscriberId, {
email,
@@ -42,45 +42,19 @@ serve(async (req) => {
data,
});
edgeLogger.info('Subscriber updated successfully', { action: 'update_novu_subscriber', subscriberId: subscriber.data._id });
endRequest(tracking, 200);
edgeLogger.info('Subscriber updated successfully', { action: 'update_novu_subscriber', subscriberId: subscriber.data._id, requestId: context.requestId });
return new Response(
JSON.stringify({
success: true,
subscriberId: subscriber.data._id,
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 updating Novu subscriber', { action: 'update_novu_subscriber', error: errorMessage, requestId: tracking.requestId });
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,
}
);
}
});
);