mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 11:11:16 -05:00
Centralize CORS configuration
Consolidate CORS handling by introducing a shared supabase/functions/_shared/cors.ts and migrate edge functions to import from it. Remove inline cors.ts usage across functions, standardize headers (including traceparent and x-request-id), and prepare for environment-aware origins.
This commit is contained in:
119
supabase/functions/_shared/cors.ts
Normal file
119
supabase/functions/_shared/cors.ts
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
/**
|
||||||
|
* Centralized CORS configuration for all edge functions
|
||||||
|
* Provides consistent header handling across the application
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Standard headers that should be allowed across all functions
|
||||||
|
const STANDARD_HEADERS = [
|
||||||
|
'authorization',
|
||||||
|
'x-client-info',
|
||||||
|
'apikey',
|
||||||
|
'content-type',
|
||||||
|
];
|
||||||
|
|
||||||
|
// Tracing headers for distributed tracing and request tracking
|
||||||
|
const TRACING_HEADERS = [
|
||||||
|
'traceparent',
|
||||||
|
'x-request-id',
|
||||||
|
];
|
||||||
|
|
||||||
|
// All headers combined
|
||||||
|
const ALL_HEADERS = [...STANDARD_HEADERS, ...TRACING_HEADERS];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic CORS headers - allows all origins
|
||||||
|
* Use for most edge functions that need public access
|
||||||
|
*/
|
||||||
|
export const corsHeaders = {
|
||||||
|
'Access-Control-Allow-Origin': '*',
|
||||||
|
'Access-Control-Allow-Headers': STANDARD_HEADERS.join(', '),
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extended CORS headers - includes tracing headers
|
||||||
|
* Use for functions that participate in distributed tracing
|
||||||
|
*/
|
||||||
|
export const corsHeadersWithTracing = {
|
||||||
|
'Access-Control-Allow-Origin': '*',
|
||||||
|
'Access-Control-Allow-Headers': ALL_HEADERS.join(', '),
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CORS headers with methods - for functions with multiple HTTP verbs
|
||||||
|
*/
|
||||||
|
export const corsHeadersWithMethods = {
|
||||||
|
'Access-Control-Allow-Origin': '*',
|
||||||
|
'Access-Control-Allow-Headers': ALL_HEADERS.join(', '),
|
||||||
|
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CORS headers with credentials - for authenticated requests requiring cookies
|
||||||
|
*/
|
||||||
|
export const corsHeadersWithCredentials = {
|
||||||
|
'Access-Control-Allow-Origin': '*',
|
||||||
|
'Access-Control-Allow-Headers': ALL_HEADERS.join(', '),
|
||||||
|
'Access-Control-Allow-Credentials': 'true',
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Environment-aware CORS configuration
|
||||||
|
* Validates origin against allowlist (production) or localhost (development)
|
||||||
|
*/
|
||||||
|
export const getAllowedOrigin = (requestOrigin: string | null): string | null => {
|
||||||
|
// If no origin header, it's not a CORS request (same-origin or server-to-server)
|
||||||
|
if (!requestOrigin) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const environment = Deno.env.get('ENVIRONMENT') || 'development';
|
||||||
|
|
||||||
|
// Production allowlist - configure via ALLOWED_ORIGINS environment variable
|
||||||
|
const allowedOriginsEnv = Deno.env.get('ALLOWED_ORIGINS') || '';
|
||||||
|
const allowedOrigins = allowedOriginsEnv.split(',').filter(origin => origin.trim());
|
||||||
|
|
||||||
|
// In development, only allow localhost and Replit domains
|
||||||
|
if (environment === 'development') {
|
||||||
|
if (
|
||||||
|
requestOrigin.includes('localhost') ||
|
||||||
|
requestOrigin.includes('127.0.0.1') ||
|
||||||
|
requestOrigin.includes('.repl.co') ||
|
||||||
|
requestOrigin.includes('.replit.dev')
|
||||||
|
) {
|
||||||
|
return requestOrigin;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// In production, only allow specific domains from environment variable
|
||||||
|
if (allowedOrigins.includes(requestOrigin)) {
|
||||||
|
return requestOrigin;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get CORS headers with validated origin
|
||||||
|
* Use for functions requiring strict origin validation (e.g., upload-image)
|
||||||
|
*/
|
||||||
|
export const getCorsHeaders = (allowedOrigin: string | null): Record<string, string> => {
|
||||||
|
if (!allowedOrigin) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
'Access-Control-Allow-Origin': allowedOrigin,
|
||||||
|
'Access-Control-Allow-Headers': ALL_HEADERS.join(', '),
|
||||||
|
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
|
||||||
|
'Access-Control-Allow-Credentials': 'true',
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle OPTIONS preflight request
|
||||||
|
* Returns a Response with appropriate CORS headers
|
||||||
|
*/
|
||||||
|
export const handleCorsPreFlight = (corsHeaders: Record<string, string>): Response => {
|
||||||
|
return new Response(null, { headers: corsHeaders });
|
||||||
|
};
|
||||||
@@ -1,12 +1,8 @@
|
|||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||||
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface DeleteUserRequest {
|
interface DeleteUserRequest {
|
||||||
targetUserId: string;
|
targetUserId: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||||
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
serve(async (req) => {
|
serve(async (req) => {
|
||||||
const tracking = startRequest();
|
const tracking = startRequest();
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||||
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
Deno.serve(async (req) => {
|
Deno.serve(async (req) => {
|
||||||
const tracking = startRequest();
|
const tracking = startRequest();
|
||||||
|
|
||||||
|
|||||||
@@ -8,13 +8,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface StatusRequest {
|
interface StatusRequest {
|
||||||
idempotencyKey: string;
|
idempotencyKey: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger } from '../_shared/logger.ts';
|
import { edgeLogger } from '../_shared/logger.ts';
|
||||||
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface CleanupStats {
|
interface CleanupStats {
|
||||||
item_edit_history_deleted: number;
|
item_edit_history_deleted: number;
|
||||||
orphaned_records_deleted: number;
|
orphaned_records_deleted: number;
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
serve(async (req) => {
|
serve(async (req) => {
|
||||||
const tracking = startRequest();
|
const tracking = startRequest();
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
||||||
import { Novu } from "npm:@novu/api@1.6.0";
|
import { Novu } from "npm:@novu/api@1.6.0";
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger } from '../_shared/logger.ts';
|
import { edgeLogger } from '../_shared/logger.ts';
|
||||||
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Simple request tracking
|
// Simple request tracking
|
||||||
const startRequest = () => ({ requestId: crypto.randomUUID(), start: Date.now() });
|
const startRequest = () => ({ requestId: crypto.randomUUID(), start: Date.now() });
|
||||||
const endRequest = (tracking: { start: number }) => Date.now() - tracking.start;
|
const endRequest = (tracking: { start: number }) => Date.now() - tracking.start;
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
||||||
|
import { corsHeadersWithTracing as corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
||||||
import { formatEdgeError } from "../_shared/errorFormatter.ts";
|
import { formatEdgeError } from "../_shared/errorFormatter.ts";
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type, x-request-id',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface IPLocationResponse {
|
interface IPLocationResponse {
|
||||||
country: string;
|
country: string;
|
||||||
countryCode: string;
|
countryCode: string;
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { sanitizeError } from '../_shared/errorSanitizer.ts';
|
import { sanitizeError } from '../_shared/errorSanitizer.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||||
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface ExportOptions {
|
interface ExportOptions {
|
||||||
include_reviews: boolean;
|
include_reviews: boolean;
|
||||||
include_lists: boolean;
|
include_lists: boolean;
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
||||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
||||||
import { Novu } from "npm:@novu/api@1.6.0";
|
import { Novu } from "npm:@novu/api@1.6.0";
|
||||||
|
import { corsHeadersWithTracing as corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
||||||
import { withEdgeRetry } from '../_shared/retryHelper.ts';
|
import { withEdgeRetry } from '../_shared/retryHelper.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type, x-request-id',
|
|
||||||
};
|
|
||||||
|
|
||||||
const TOPICS = {
|
const TOPICS = {
|
||||||
MODERATION_SUBMISSIONS: 'moderation-submissions',
|
MODERATION_SUBMISSIONS: 'moderation-submissions',
|
||||||
MODERATION_REPORTS: 'moderation-reports',
|
MODERATION_REPORTS: 'moderation-reports',
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||||
import { createErrorResponse, sanitizeError } from '../_shared/errorSanitizer.ts';
|
import { createErrorResponse, sanitizeError } from '../_shared/errorSanitizer.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface MergeTicketsRequest {
|
interface MergeTicketsRequest {
|
||||||
primaryTicketId: string;
|
primaryTicketId: string;
|
||||||
mergeTicketIds: string[];
|
mergeTicketIds: string[];
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||||
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
Deno.serve(async (req) => {
|
Deno.serve(async (req) => {
|
||||||
const tracking = startRequest();
|
const tracking = startRequest();
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
||||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
||||||
import { Novu } from "npm:@novu/api@1.6.0";
|
import { Novu } from "npm:@novu/api@1.6.0";
|
||||||
|
import { corsHeadersWithTracing as corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type, x-request-id',
|
|
||||||
};
|
|
||||||
|
|
||||||
serve(async (req) => {
|
serve(async (req) => {
|
||||||
if (req.method === 'OPTIONS') {
|
if (req.method === 'OPTIONS') {
|
||||||
return new Response(null, { headers: corsHeaders });
|
return new Response(null, { headers: corsHeaders });
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
||||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
||||||
|
import { corsHeadersWithTracing as corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
||||||
import { withEdgeRetry } from '../_shared/retryHelper.ts';
|
import { withEdgeRetry } from '../_shared/retryHelper.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type, x-request-id',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface NotificationPayload {
|
interface NotificationPayload {
|
||||||
reportId: string;
|
reportId: string;
|
||||||
reportType: string;
|
reportType: string;
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
||||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||||
import { withEdgeRetry } from '../_shared/retryHelper.ts';
|
import { withEdgeRetry } from '../_shared/retryHelper.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface NotificationPayload {
|
interface NotificationPayload {
|
||||||
submission_id: string;
|
submission_id: string;
|
||||||
submission_type: string;
|
submission_type: string;
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
||||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
||||||
|
import { corsHeadersWithTracing as corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type, x-request-id',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface AnnouncementPayload {
|
interface AnnouncementPayload {
|
||||||
title: string;
|
title: string;
|
||||||
message: string;
|
message: string;
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
||||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
||||||
|
import { corsHeadersWithTracing as corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type, x-request-id',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface RequestBody {
|
interface RequestBody {
|
||||||
submission_id: string;
|
submission_id: string;
|
||||||
user_id: string;
|
user_id: string;
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
||||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger } from '../_shared/logger.ts';
|
import { edgeLogger } from '../_shared/logger.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Simple request tracking
|
// Simple request tracking
|
||||||
const startRequest = () => ({ requestId: crypto.randomUUID(), start: Date.now() });
|
const startRequest = () => ({ requestId: crypto.randomUUID(), start: Date.now() });
|
||||||
const endRequest = (tracking: { start: number }) => Date.now() - tracking.start;
|
const endRequest = (tracking: { start: number }) => Date.now() - tracking.start;
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger } from '../_shared/logger.ts';
|
import { edgeLogger } from '../_shared/logger.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
Deno.serve(async (req) => {
|
Deno.serve(async (req) => {
|
||||||
// Handle CORS preflight
|
// Handle CORS preflight
|
||||||
if (req.method === 'OPTIONS') {
|
if (req.method === 'OPTIONS') {
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import "jsr:@supabase/functions-js/edge-runtime.d.ts";
|
import "jsr:@supabase/functions-js/edge-runtime.d.ts";
|
||||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
const CLOUDFLARE_ACCOUNT_ID = Deno.env.get('CLOUDFLARE_ACCOUNT_ID');
|
const CLOUDFLARE_ACCOUNT_ID = Deno.env.get('CLOUDFLARE_ACCOUNT_ID');
|
||||||
const CLOUDFLARE_API_TOKEN = Deno.env.get('CLOUDFLARE_IMAGES_API_TOKEN');
|
const CLOUDFLARE_API_TOKEN = Deno.env.get('CLOUDFLARE_IMAGES_API_TOKEN');
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
||||||
|
import { corsHeadersWithTracing as corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type, x-request-id',
|
|
||||||
};
|
|
||||||
|
|
||||||
serve(async (req) => {
|
serve(async (req) => {
|
||||||
if (req.method === 'OPTIONS') {
|
if (req.method === 'OPTIONS') {
|
||||||
return new Response(null, { headers: corsHeaders });
|
return new Response(null, { headers: corsHeaders });
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
export const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type, traceparent, x-request-id',
|
|
||||||
};
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
||||||
import { corsHeaders } from './cors.ts';
|
import { corsHeadersWithTracing as corsHeaders } from '../_shared/cors.ts';
|
||||||
import { rateLimiters, withRateLimit } from '../_shared/rateLimiter.ts';
|
import { rateLimiters, withRateLimit } from '../_shared/rateLimiter.ts';
|
||||||
import {
|
import {
|
||||||
edgeLogger,
|
edgeLogger,
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
export const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type, traceparent, x-request-id',
|
|
||||||
};
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
||||||
import { corsHeaders } from './cors.ts';
|
import { corsHeadersWithTracing as corsHeaders } from '../_shared/cors.ts';
|
||||||
import { rateLimiters, withRateLimit } from '../_shared/rateLimiter.ts';
|
import { rateLimiters, withRateLimit } from '../_shared/rateLimiter.ts';
|
||||||
import {
|
import {
|
||||||
edgeLogger,
|
edgeLogger,
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
||||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
||||||
import { createErrorResponse } from "../_shared/errorSanitizer.ts";
|
import { createErrorResponse } from "../_shared/errorSanitizer.ts";
|
||||||
import { formatEdgeError } from "../_shared/errorFormatter.ts";
|
import { formatEdgeError } from "../_shared/errorFormatter.ts";
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface InboundEmailPayload {
|
interface InboundEmailPayload {
|
||||||
from: string;
|
from: string;
|
||||||
to: string;
|
to: string;
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
||||||
import { Novu } from "npm:@novu/api@1.6.0";
|
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, startRequest, endRequest } from "../_shared/logger.ts";
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type, x-request-id',
|
|
||||||
};
|
|
||||||
|
|
||||||
serve(async (req) => {
|
serve(async (req) => {
|
||||||
if (req.method === 'OPTIONS') {
|
if (req.method === 'OPTIONS') {
|
||||||
return new Response(null, { headers: corsHeaders });
|
return new Response(null, { headers: corsHeaders });
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
serve(async (req) => {
|
serve(async (req) => {
|
||||||
const tracking = startRequest();
|
const tracking = startRequest();
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
serve(async (req) => {
|
serve(async (req) => {
|
||||||
const tracking = startRequest();
|
const tracking = startRequest();
|
||||||
|
|
||||||
|
|||||||
@@ -11,13 +11,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger } from '../_shared/logger.ts';
|
import { edgeLogger } from '../_shared/logger.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface CleanupResult {
|
interface CleanupResult {
|
||||||
idempotency_keys?: {
|
idempotency_keys?: {
|
||||||
deleted: number;
|
deleted: number;
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger } from '../_shared/logger.ts';
|
import { edgeLogger } from '../_shared/logger.ts';
|
||||||
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
serve(async (req: Request) => {
|
serve(async (req: Request) => {
|
||||||
if (req.method === 'OPTIONS') {
|
if (req.method === 'OPTIONS') {
|
||||||
return new Response(null, { headers: corsHeaders });
|
return new Response(null, { headers: corsHeaders });
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface SeedOptions {
|
interface SeedOptions {
|
||||||
preset: 'small' | 'medium' | 'large' | 'stress';
|
preset: 'small' | 'medium' | 'large' | 'stress';
|
||||||
entityTypes: string[];
|
entityTypes: string[];
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
||||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
||||||
import { createErrorResponse } from "../_shared/errorSanitizer.ts";
|
import { createErrorResponse } from "../_shared/errorSanitizer.ts";
|
||||||
import { formatEdgeError } from "../_shared/errorFormatter.ts";
|
import { formatEdgeError } from "../_shared/errorFormatter.ts";
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface AdminReplyRequest {
|
interface AdminReplyRequest {
|
||||||
submissionId: string;
|
submissionId: string;
|
||||||
replyBody: string;
|
replyBody: string;
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
||||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger } from "../_shared/logger.ts";
|
import { edgeLogger } from "../_shared/logger.ts";
|
||||||
import { createErrorResponse } from "../_shared/errorSanitizer.ts";
|
import { createErrorResponse } from "../_shared/errorSanitizer.ts";
|
||||||
import { formatEdgeError } from "../_shared/errorFormatter.ts";
|
import { formatEdgeError } from "../_shared/errorFormatter.ts";
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface ContactSubmission {
|
interface ContactSubmission {
|
||||||
name: string;
|
name: string;
|
||||||
email: string;
|
email: string;
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
||||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||||
import { withEdgeRetry } from '../_shared/retryHelper.ts';
|
import { withEdgeRetry } from '../_shared/retryHelper.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface EscalationRequest {
|
interface EscalationRequest {
|
||||||
submissionId: string;
|
submissionId: string;
|
||||||
escalationReason: string;
|
escalationReason: string;
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface EmailRequest {
|
interface EmailRequest {
|
||||||
email: string;
|
email: string;
|
||||||
displayName?: string;
|
displayName?: string;
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
||||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
||||||
import { Novu } from "npm:@novu/api@1.6.0";
|
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, startRequest, endRequest } from '../_shared/logger.ts';
|
||||||
import { withEdgeRetry } from '../_shared/retryHelper.ts';
|
import { withEdgeRetry } from '../_shared/retryHelper.ts';
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
const TOPICS = {
|
const TOPICS = {
|
||||||
MODERATION_SUBMISSIONS: 'moderation-submissions',
|
MODERATION_SUBMISSIONS: 'moderation-submissions',
|
||||||
MODERATION_REPORTS: 'moderation-reports',
|
MODERATION_REPORTS: 'moderation-reports',
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
||||||
import { Novu } from "npm:@novu/api@1.6.0";
|
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, startRequest, endRequest } from "../_shared/logger.ts";
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type, x-request-id',
|
|
||||||
};
|
|
||||||
|
|
||||||
serve(async (req) => {
|
serve(async (req) => {
|
||||||
if (req.method === 'OPTIONS') {
|
if (req.method === 'OPTIONS') {
|
||||||
return new Response(null, { headers: corsHeaders });
|
return new Response(null, { headers: corsHeaders });
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
||||||
import { Novu } from "npm:@novu/api@1.6.0";
|
import { Novu } from "npm:@novu/api@1.6.0";
|
||||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
serve(async (req) => {
|
serve(async (req) => {
|
||||||
const tracking = startRequest('update-novu-preferences');
|
const tracking = startRequest('update-novu-preferences');
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
||||||
import { Novu } from "npm:@novu/api@1.6.0";
|
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, startRequest, endRequest } from "../_shared/logger.ts";
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type, x-request-id',
|
|
||||||
};
|
|
||||||
|
|
||||||
serve(async (req) => {
|
serve(async (req) => {
|
||||||
if (req.method === 'OPTIONS') {
|
if (req.method === 'OPTIONS') {
|
||||||
return new Response(null, { headers: corsHeaders });
|
return new Response(null, { headers: corsHeaders });
|
||||||
|
|||||||
@@ -1,62 +1,10 @@
|
|||||||
import { serve } from "https://deno.land/std@0.168.0/http/server.ts"
|
import { serve } from "https://deno.land/std@0.168.0/http/server.ts"
|
||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
|
||||||
|
import { getAllowedOrigin, getCorsHeaders } from '../_shared/cors.ts'
|
||||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts'
|
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts'
|
||||||
import { rateLimiters, withRateLimit } from '../_shared/rateLimiter.ts'
|
import { rateLimiters, withRateLimit } from '../_shared/rateLimiter.ts'
|
||||||
import { formatEdgeError } from '../_shared/errorFormatter.ts'
|
import { formatEdgeError } from '../_shared/errorFormatter.ts'
|
||||||
|
|
||||||
// Environment-aware CORS configuration
|
|
||||||
const getAllowedOrigin = (requestOrigin: string | null): string | null => {
|
|
||||||
// If no origin header, it's not a CORS request (same-origin or server-to-server)
|
|
||||||
if (!requestOrigin) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const environment = Deno.env.get('ENVIRONMENT') || 'development';
|
|
||||||
|
|
||||||
// Production allowlist - configure via ALLOWED_ORIGINS environment variable
|
|
||||||
// Format: comma-separated list of origins, e.g., "https://example.com,https://www.example.com"
|
|
||||||
const allowedOriginsEnv = Deno.env.get('ALLOWED_ORIGINS') || '';
|
|
||||||
const allowedOrigins = allowedOriginsEnv.split(',').filter(origin => origin.trim());
|
|
||||||
|
|
||||||
// In development, only allow localhost and Replit domains - nothing else
|
|
||||||
if (environment === 'development') {
|
|
||||||
if (
|
|
||||||
requestOrigin.includes('localhost') ||
|
|
||||||
requestOrigin.includes('127.0.0.1') ||
|
|
||||||
requestOrigin.includes('.repl.co') ||
|
|
||||||
requestOrigin.includes('.replit.dev')
|
|
||||||
) {
|
|
||||||
return requestOrigin;
|
|
||||||
}
|
|
||||||
// Origin not allowed in development - log and deny
|
|
||||||
edgeLogger.warn('CORS origin not allowed in development mode', { origin: requestOrigin });
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// In production, only allow specific domains from environment variable
|
|
||||||
if (allowedOrigins.includes(requestOrigin)) {
|
|
||||||
return requestOrigin;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Origin not allowed in production - log and deny
|
|
||||||
edgeLogger.warn('CORS origin not allowed in production mode', { origin: requestOrigin });
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getCorsHeaders = (allowedOrigin: string | null): Record<string, string> => {
|
|
||||||
// If no allowed origin, return empty headers (no CORS access)
|
|
||||||
if (!allowedOrigin) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
'Access-Control-Allow-Origin': allowedOrigin,
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
'Access-Control-Allow-Methods': 'GET, POST, DELETE, OPTIONS',
|
|
||||||
'Access-Control-Allow-Credentials': 'true',
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// Helper to create authenticated Supabase client
|
// Helper to create authenticated Supabase client
|
||||||
const createAuthenticatedSupabaseClient = (authHeader: string) => {
|
const createAuthenticatedSupabaseClient = (authHeader: string) => {
|
||||||
const supabaseUrl = Deno.env.get('SUPABASE_URL')
|
const supabaseUrl = Deno.env.get('SUPABASE_URL')
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.39.3';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.39.3';
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { edgeLogger } from "../_shared/logger.ts";
|
import { edgeLogger } from "../_shared/logger.ts";
|
||||||
import { formatEdgeError } from "../_shared/errorFormatter.ts";
|
import { formatEdgeError } from "../_shared/errorFormatter.ts";
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Simple request tracking
|
// Simple request tracking
|
||||||
const startRequest = () => ({ requestId: crypto.randomUUID(), start: Date.now() });
|
const startRequest = () => ({ requestId: crypto.randomUUID(), start: Date.now() });
|
||||||
const endRequest = (tracking: { start: number }) => Date.now() - tracking.start;
|
const endRequest = (tracking: { start: number }) => Date.now() - tracking.start;
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
||||||
|
import { corsHeaders } from '../_shared/cors.ts';
|
||||||
import { startRequest, endRequest, edgeLogger } from "../_shared/logger.ts";
|
import { startRequest, endRequest, edgeLogger } from "../_shared/logger.ts";
|
||||||
import { formatEdgeError } from "../_shared/errorFormatter.ts";
|
import { formatEdgeError } from "../_shared/errorFormatter.ts";
|
||||||
|
|
||||||
const corsHeaders = {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type, x-request-id',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Comprehensive list of disposable email domains
|
// Comprehensive list of disposable email domains
|
||||||
const DISPOSABLE_DOMAINS = new Set([
|
const DISPOSABLE_DOMAINS = new Set([
|
||||||
// Popular disposable email services
|
// Popular disposable email services
|
||||||
|
|||||||
Reference in New Issue
Block a user