diff --git a/apps/web/src/app/(app)/settings/developers/logs/[logId]/loading.tsx b/apps/web/src/app/(app)/settings/developers/logs/[logId]/loading.tsx index f30b62c..1dba7db 100644 --- a/apps/web/src/app/(app)/settings/developers/logs/[logId]/loading.tsx +++ b/apps/web/src/app/(app)/settings/developers/logs/[logId]/loading.tsx @@ -30,6 +30,12 @@ export default async function WebhookLogsDetailsLoading() { + + Number of retries + + + + HTTP Status diff --git a/apps/web/src/app/(app)/settings/developers/logs/[logId]/page.tsx b/apps/web/src/app/(app)/settings/developers/logs/[logId]/page.tsx index f6c0581..a726f61 100644 --- a/apps/web/src/app/(app)/settings/developers/logs/[logId]/page.tsx +++ b/apps/web/src/app/(app)/settings/developers/logs/[logId]/page.tsx @@ -67,6 +67,23 @@ export default async function WebhookLogsDetails({ }) : null + const nextRetryDelay = Math.round( + Math.min(86400, Math.exp(2.5 * webhookLog.numberOfRetries)), + ) + + const nextRetryDate = dayjs(webhookLog.finishedAt).add( + nextRetryDelay, + 'second', + ) + + const isNextRetryDateInFuture = nextRetryDate.isAfter(dayjs()) + + const formattedNextRetryDate = isNextRetryDateInFuture + ? dayjs().to(nextRetryDate, true) + : '' + + const nextRetryDateFormatted = `(Next retry in ${formattedNextRetryDate.trim()})` + return (
@@ -112,6 +129,16 @@ export default async function WebhookLogsDetails({ Error reason {webhookLog.errorReason || '-'} + + Number of retries + + {webhookLog.status === 'ERROR' + ? `${webhookLog.numberOfRetries} ${ + isNextRetryDateInFuture ? nextRetryDateFormatted : '' + }` + : '-'} + + HTTP Status diff --git a/apps/web/src/app/api/webhooks/external/route.ts b/apps/web/src/app/api/webhooks/external/route.ts index 1f996da..d175c8d 100644 --- a/apps/web/src/app/api/webhooks/external/route.ts +++ b/apps/web/src/app/api/webhooks/external/route.ts @@ -9,8 +9,14 @@ export const runtime = 'edge' async function handler(request: NextRequest) { const requestBody = await request.json() + const numberOfRetries = Number(request.headers.get('Upstash-Retried')) || 0 - const webhookEvent = webhookEventSchema.parse(requestBody) + const webhookData = { + ...requestBody, + numberOfRetries, + } + + const webhookEvent = webhookEventSchema.parse(webhookData) const { success } = await handleWebhookEvent(webhookEvent) diff --git a/packages/drizzle/migrations/0012_unique_black_tom.sql b/packages/drizzle/migrations/0012_unique_black_tom.sql new file mode 100644 index 0000000..9d19779 --- /dev/null +++ b/packages/drizzle/migrations/0012_unique_black_tom.sql @@ -0,0 +1 @@ +ALTER TABLE "company_webhook_logs" ADD COLUMN "number_of_retries" integer DEFAULT 0; \ No newline at end of file diff --git a/packages/drizzle/migrations/0013_nervous_abomination.sql b/packages/drizzle/migrations/0013_nervous_abomination.sql new file mode 100644 index 0000000..3a4afd9 --- /dev/null +++ b/packages/drizzle/migrations/0013_nervous_abomination.sql @@ -0,0 +1 @@ +ALTER TABLE "company_webhook_logs" ALTER COLUMN "number_of_retries" SET NOT NULL; \ No newline at end of file diff --git a/packages/drizzle/migrations/meta/0012_snapshot.json b/packages/drizzle/migrations/meta/0012_snapshot.json new file mode 100644 index 0000000..6977731 --- /dev/null +++ b/packages/drizzle/migrations/meta/0012_snapshot.json @@ -0,0 +1,1061 @@ +{ + "id": "af8aac02-94a8-4af3-8ce8-9283857fa686", + "prevId": "7ad3bb32-9f4b-4c61-a6ab-9ac7ccac1814", + "version": "5", + "dialect": "pg", + "tables": { + "accounts": { + "name": "accounts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_account_id": { + "name": "provider_account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "session_state": { + "name": "session_state", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "token_type": { + "name": "token_type", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "accounts_provider_provider_account_id_index": { + "name": "accounts_provider_provider_account_id_index", + "columns": [ + "provider", + "provider_account_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "accounts_user_id_users_id_fk": { + "name": "accounts_user_id_users_id_fk", + "tableFrom": "accounts", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "companies": { + "name": "companies", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "external_api_key": { + "name": "external_api_key", + "type": "json", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "companies_domain_index": { + "name": "companies_domain_index", + "columns": [ + "domain" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "sessions": { + "name": "sessions", + "schema": "", + "columns": { + "session_token": { + "name": "session_token", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "expires": { + "name": "expires", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "tag_to_uploads": { + "name": "tag_to_uploads", + "schema": "", + "columns": { + "tag_id": { + "name": "tag_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "upload_id": { + "name": "upload_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "tag_to_uploads_tag_id_upload_id_index": { + "name": "tag_to_uploads_tag_id_upload_id_index", + "columns": [ + "tag_id", + "upload_id" + ], + "isUnique": true + }, + "tag_to_uploads_upload_id_index": { + "name": "tag_to_uploads_upload_id_index", + "columns": [ + "upload_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "tag_to_uploads_tag_id_tags_id_fk": { + "name": "tag_to_uploads_tag_id_tags_id_fk", + "tableFrom": "tag_to_uploads", + "tableTo": "tags", + "columnsFrom": [ + "tag_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "tag_to_uploads_upload_id_uploads_id_fk": { + "name": "tag_to_uploads_upload_id_uploads_id_fk", + "tableFrom": "tag_to_uploads", + "tableTo": "uploads", + "columnsFrom": [ + "upload_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "tags": { + "name": "tags", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "tags_slug_index": { + "name": "tags_slug_index", + "columns": [ + "slug" + ], + "isUnique": true + } + }, + "foreignKeys": { + "tags_company_id_companies_id_fk": { + "name": "tags_company_id_companies_id_fk", + "tableFrom": "tags", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "transcriptions": { + "name": "transcriptions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "upload_id": { + "name": "upload_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "transcriptions_upload_id_index": { + "name": "transcriptions_upload_id_index", + "columns": [ + "upload_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "transcriptions_upload_id_uploads_id_fk": { + "name": "transcriptions_upload_id_uploads_id_fk", + "tableFrom": "transcriptions", + "tableTo": "uploads", + "columnsFrom": [ + "upload_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "transcription_segments": { + "name": "transcription_segments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "transcription_id": { + "name": "transcription_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "start": { + "name": "start", + "type": "numeric(10, 2)", + "primaryKey": false, + "notNull": true + }, + "end": { + "name": "end", + "type": "numeric(10, 2)", + "primaryKey": false, + "notNull": true + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "transcription_segments_transcription_id_transcriptions_id_fk": { + "name": "transcription_segments_transcription_id_transcriptions_id_fk", + "tableFrom": "transcription_segments", + "tableTo": "transcriptions", + "columnsFrom": [ + "transcription_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "upload_batches": { + "name": "upload_batches", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "upload_batches_author_id_users_id_fk": { + "name": "upload_batches_author_id_users_id_fk", + "tableFrom": "upload_batches", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "cascade" + }, + "upload_batches_company_id_companies_id_fk": { + "name": "upload_batches_company_id_companies_id_fk", + "tableFrom": "upload_batches", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified": { + "name": "email_verified", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "users_email_index": { + "name": "users_email_index", + "columns": [ + "email" + ], + "isUnique": true + } + }, + "foreignKeys": { + "users_company_id_companies_id_fk": { + "name": "users_company_id_companies_id_fk", + "tableFrom": "users", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "verification_tokens": { + "name": "verification_tokens", + "schema": "", + "columns": { + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires": { + "name": "expires", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "verification_tokens_token_index": { + "name": "verification_tokens_token_index", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "verification_tokens_identifier_token_pk": { + "name": "verification_tokens_identifier_token_pk", + "columns": [ + "identifier", + "token" + ] + } + }, + "uniqueConstraints": {} + }, + "uploads": { + "name": "uploads", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "duration": { + "name": "duration", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "storage_key": { + "name": "storage_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "upload_batch_id": { + "name": "upload_batch_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "external_provider_id": { + "name": "external_provider_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "external_status": { + "name": "external_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "external_stream_url": { + "name": "external_stream_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "audio_storage_key": { + "name": "audio_storage_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "processed_at": { + "name": "processed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "size_in_bytes": { + "name": "size_in_bytes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "upload_order": { + "name": "upload_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "commit_url": { + "name": "commit_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "subtitles_storage_key": { + "name": "subtitles_storage_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "language": { + "name": "language", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pt'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "uploads_external_provider_id_index": { + "name": "uploads_external_provider_id_index", + "columns": [ + "external_provider_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "uploads_upload_batch_id_upload_batches_id_fk": { + "name": "uploads_upload_batch_id_upload_batches_id_fk", + "tableFrom": "uploads", + "tableTo": "upload_batches", + "columnsFrom": [ + "upload_batch_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "cascade" + }, + "uploads_company_id_companies_id_fk": { + "name": "uploads_company_id_companies_id_fk", + "tableFrom": "uploads", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "cascade" + }, + "uploads_author_id_users_id_fk": { + "name": "uploads_author_id_users_id_fk", + "tableFrom": "uploads", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "upload_webhooks": { + "name": "upload_webhooks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "upload_id": { + "name": "upload_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "UploadWebhookType", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "UploadWebhookStatus", + "primaryKey": false, + "notNull": true, + "default": "'RUNNING'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "upload_webhooks_upload_id_uploads_id_fk": { + "name": "upload_webhooks_upload_id_uploads_id_fk", + "tableFrom": "upload_webhooks", + "tableTo": "uploads", + "columnsFrom": [ + "upload_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "company_webhooks": { + "name": "company_webhooks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "signing_key": { + "name": "signing_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "events": { + "name": "events", + "type": "text[]", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "company_webhooks_company_id_url_index": { + "name": "company_webhooks_company_id_url_index", + "columns": [ + "company_id", + "url" + ], + "isUnique": true + } + }, + "foreignKeys": { + "company_webhooks_company_id_companies_id_fk": { + "name": "company_webhooks_company_id_companies_id_fk", + "tableFrom": "company_webhooks", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "company_webhook_logs": { + "name": "company_webhook_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "company_webhook_id": { + "name": "company_webhook_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "CompanyWebhookLogStatus", + "primaryKey": false, + "notNull": true, + "default": "'PENDING'" + }, + "error_reason": { + "name": "error_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "http_code": { + "name": "http_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "http_method": { + "name": "http_method", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "request_body": { + "name": "request_body", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "request_headers": { + "name": "request_headers", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "response_body": { + "name": "response_body", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "number_of_retries": { + "name": "number_of_retries", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "status_idx": { + "name": "status_idx", + "columns": [ + "status" + ], + "isUnique": false + } + }, + "foreignKeys": { + "company_webhook_logs_company_webhook_id_company_webhooks_id_fk": { + "name": "company_webhook_logs_company_webhook_id_company_webhooks_id_fk", + "tableFrom": "company_webhook_logs", + "tableTo": "company_webhooks", + "columnsFrom": [ + "company_webhook_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + } + }, + "enums": { + "UploadWebhookStatus": { + "name": "UploadWebhookStatus", + "values": { + "ERROR": "ERROR", + "SUCCESS": "SUCCESS", + "RUNNING": "RUNNING" + } + }, + "UploadWebhookType": { + "name": "UploadWebhookType", + "values": { + "CREATE_SUBTITLES_FROM_TRANSCRIPTION": "CREATE_SUBTITLES_FROM_TRANSCRIPTION", + "UPDATE_EXTERNAL_PROVIDER_STATUS": "UPDATE_EXTERNAL_PROVIDER_STATUS", + "UPLOAD_TO_EXTERNAL_PROVIDER": "UPLOAD_TO_EXTERNAL_PROVIDER", + "CREATE_TRANSCRIPTION": "CREATE_TRANSCRIPTION", + "PROCESS_VIDEO": "PROCESS_VIDEO" + } + }, + "CompanyWebhookLogStatus": { + "name": "CompanyWebhookLogStatus", + "values": { + "PENDING": "PENDING", + "SUCCESS": "SUCCESS", + "ERROR": "ERROR" + } + } + }, + "schemas": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/packages/drizzle/migrations/meta/0013_snapshot.json b/packages/drizzle/migrations/meta/0013_snapshot.json new file mode 100644 index 0000000..e1e720b --- /dev/null +++ b/packages/drizzle/migrations/meta/0013_snapshot.json @@ -0,0 +1,1061 @@ +{ + "id": "d1b7f5a1-7c93-4c9a-a626-8c968b83b98b", + "prevId": "af8aac02-94a8-4af3-8ce8-9283857fa686", + "version": "5", + "dialect": "pg", + "tables": { + "accounts": { + "name": "accounts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_account_id": { + "name": "provider_account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "session_state": { + "name": "session_state", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "token_type": { + "name": "token_type", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "accounts_provider_provider_account_id_index": { + "name": "accounts_provider_provider_account_id_index", + "columns": [ + "provider", + "provider_account_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "accounts_user_id_users_id_fk": { + "name": "accounts_user_id_users_id_fk", + "tableFrom": "accounts", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "companies": { + "name": "companies", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "external_api_key": { + "name": "external_api_key", + "type": "json", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "companies_domain_index": { + "name": "companies_domain_index", + "columns": [ + "domain" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "sessions": { + "name": "sessions", + "schema": "", + "columns": { + "session_token": { + "name": "session_token", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "expires": { + "name": "expires", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "tag_to_uploads": { + "name": "tag_to_uploads", + "schema": "", + "columns": { + "tag_id": { + "name": "tag_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "upload_id": { + "name": "upload_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "tag_to_uploads_tag_id_upload_id_index": { + "name": "tag_to_uploads_tag_id_upload_id_index", + "columns": [ + "tag_id", + "upload_id" + ], + "isUnique": true + }, + "tag_to_uploads_upload_id_index": { + "name": "tag_to_uploads_upload_id_index", + "columns": [ + "upload_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "tag_to_uploads_tag_id_tags_id_fk": { + "name": "tag_to_uploads_tag_id_tags_id_fk", + "tableFrom": "tag_to_uploads", + "tableTo": "tags", + "columnsFrom": [ + "tag_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "tag_to_uploads_upload_id_uploads_id_fk": { + "name": "tag_to_uploads_upload_id_uploads_id_fk", + "tableFrom": "tag_to_uploads", + "tableTo": "uploads", + "columnsFrom": [ + "upload_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "tags": { + "name": "tags", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "tags_slug_index": { + "name": "tags_slug_index", + "columns": [ + "slug" + ], + "isUnique": true + } + }, + "foreignKeys": { + "tags_company_id_companies_id_fk": { + "name": "tags_company_id_companies_id_fk", + "tableFrom": "tags", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "transcriptions": { + "name": "transcriptions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "upload_id": { + "name": "upload_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "transcriptions_upload_id_index": { + "name": "transcriptions_upload_id_index", + "columns": [ + "upload_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "transcriptions_upload_id_uploads_id_fk": { + "name": "transcriptions_upload_id_uploads_id_fk", + "tableFrom": "transcriptions", + "tableTo": "uploads", + "columnsFrom": [ + "upload_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "transcription_segments": { + "name": "transcription_segments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "transcription_id": { + "name": "transcription_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "start": { + "name": "start", + "type": "numeric(10, 2)", + "primaryKey": false, + "notNull": true + }, + "end": { + "name": "end", + "type": "numeric(10, 2)", + "primaryKey": false, + "notNull": true + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "transcription_segments_transcription_id_transcriptions_id_fk": { + "name": "transcription_segments_transcription_id_transcriptions_id_fk", + "tableFrom": "transcription_segments", + "tableTo": "transcriptions", + "columnsFrom": [ + "transcription_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "upload_batches": { + "name": "upload_batches", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "upload_batches_author_id_users_id_fk": { + "name": "upload_batches_author_id_users_id_fk", + "tableFrom": "upload_batches", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "cascade" + }, + "upload_batches_company_id_companies_id_fk": { + "name": "upload_batches_company_id_companies_id_fk", + "tableFrom": "upload_batches", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified": { + "name": "email_verified", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "users_email_index": { + "name": "users_email_index", + "columns": [ + "email" + ], + "isUnique": true + } + }, + "foreignKeys": { + "users_company_id_companies_id_fk": { + "name": "users_company_id_companies_id_fk", + "tableFrom": "users", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "verification_tokens": { + "name": "verification_tokens", + "schema": "", + "columns": { + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires": { + "name": "expires", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "verification_tokens_token_index": { + "name": "verification_tokens_token_index", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "verification_tokens_identifier_token_pk": { + "name": "verification_tokens_identifier_token_pk", + "columns": [ + "identifier", + "token" + ] + } + }, + "uniqueConstraints": {} + }, + "uploads": { + "name": "uploads", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "duration": { + "name": "duration", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "storage_key": { + "name": "storage_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "upload_batch_id": { + "name": "upload_batch_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "external_provider_id": { + "name": "external_provider_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "external_status": { + "name": "external_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "external_stream_url": { + "name": "external_stream_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "audio_storage_key": { + "name": "audio_storage_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "processed_at": { + "name": "processed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "size_in_bytes": { + "name": "size_in_bytes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "upload_order": { + "name": "upload_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "commit_url": { + "name": "commit_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "subtitles_storage_key": { + "name": "subtitles_storage_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "language": { + "name": "language", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pt'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "uploads_external_provider_id_index": { + "name": "uploads_external_provider_id_index", + "columns": [ + "external_provider_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "uploads_upload_batch_id_upload_batches_id_fk": { + "name": "uploads_upload_batch_id_upload_batches_id_fk", + "tableFrom": "uploads", + "tableTo": "upload_batches", + "columnsFrom": [ + "upload_batch_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "cascade" + }, + "uploads_company_id_companies_id_fk": { + "name": "uploads_company_id_companies_id_fk", + "tableFrom": "uploads", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "cascade" + }, + "uploads_author_id_users_id_fk": { + "name": "uploads_author_id_users_id_fk", + "tableFrom": "uploads", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "upload_webhooks": { + "name": "upload_webhooks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "upload_id": { + "name": "upload_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "UploadWebhookType", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "UploadWebhookStatus", + "primaryKey": false, + "notNull": true, + "default": "'RUNNING'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "upload_webhooks_upload_id_uploads_id_fk": { + "name": "upload_webhooks_upload_id_uploads_id_fk", + "tableFrom": "upload_webhooks", + "tableTo": "uploads", + "columnsFrom": [ + "upload_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "company_webhooks": { + "name": "company_webhooks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "signing_key": { + "name": "signing_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "events": { + "name": "events", + "type": "text[]", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "company_webhooks_company_id_url_index": { + "name": "company_webhooks_company_id_url_index", + "columns": [ + "company_id", + "url" + ], + "isUnique": true + } + }, + "foreignKeys": { + "company_webhooks_company_id_companies_id_fk": { + "name": "company_webhooks_company_id_companies_id_fk", + "tableFrom": "company_webhooks", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "company_webhook_logs": { + "name": "company_webhook_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "company_webhook_id": { + "name": "company_webhook_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "CompanyWebhookLogStatus", + "primaryKey": false, + "notNull": true, + "default": "'PENDING'" + }, + "error_reason": { + "name": "error_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "http_code": { + "name": "http_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "http_method": { + "name": "http_method", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "request_body": { + "name": "request_body", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "request_headers": { + "name": "request_headers", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "response_body": { + "name": "response_body", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "number_of_retries": { + "name": "number_of_retries", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "status_idx": { + "name": "status_idx", + "columns": [ + "status" + ], + "isUnique": false + } + }, + "foreignKeys": { + "company_webhook_logs_company_webhook_id_company_webhooks_id_fk": { + "name": "company_webhook_logs_company_webhook_id_company_webhooks_id_fk", + "tableFrom": "company_webhook_logs", + "tableTo": "company_webhooks", + "columnsFrom": [ + "company_webhook_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + } + }, + "enums": { + "UploadWebhookStatus": { + "name": "UploadWebhookStatus", + "values": { + "ERROR": "ERROR", + "SUCCESS": "SUCCESS", + "RUNNING": "RUNNING" + } + }, + "UploadWebhookType": { + "name": "UploadWebhookType", + "values": { + "CREATE_SUBTITLES_FROM_TRANSCRIPTION": "CREATE_SUBTITLES_FROM_TRANSCRIPTION", + "UPDATE_EXTERNAL_PROVIDER_STATUS": "UPDATE_EXTERNAL_PROVIDER_STATUS", + "UPLOAD_TO_EXTERNAL_PROVIDER": "UPLOAD_TO_EXTERNAL_PROVIDER", + "CREATE_TRANSCRIPTION": "CREATE_TRANSCRIPTION", + "PROCESS_VIDEO": "PROCESS_VIDEO" + } + }, + "CompanyWebhookLogStatus": { + "name": "CompanyWebhookLogStatus", + "values": { + "PENDING": "PENDING", + "SUCCESS": "SUCCESS", + "ERROR": "ERROR" + } + } + }, + "schemas": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/packages/drizzle/migrations/meta/_journal.json b/packages/drizzle/migrations/meta/_journal.json index a7acf06..45ba24d 100644 --- a/packages/drizzle/migrations/meta/_journal.json +++ b/packages/drizzle/migrations/meta/_journal.json @@ -85,6 +85,20 @@ "when": 1709384306801, "tag": "0011_typical_mariko_yashida", "breakpoints": true + }, + { + "idx": 12, + "version": "5", + "when": 1709425775291, + "tag": "0012_unique_black_tom", + "breakpoints": true + }, + { + "idx": 13, + "version": "5", + "when": 1709426695600, + "tag": "0013_nervous_abomination", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/drizzle/schema/company-webhook-log.ts b/packages/drizzle/schema/company-webhook-log.ts index 9400dda..08e5bc5 100644 --- a/packages/drizzle/schema/company-webhook-log.ts +++ b/packages/drizzle/schema/company-webhook-log.ts @@ -1,6 +1,7 @@ import { relations } from 'drizzle-orm' import { index, + integer, pgEnum, pgTable, text, @@ -33,6 +34,7 @@ export const companyWebhookLog = pgTable( requestBody: text('request_body'), requestHeaders: text('request_headers'), responseBody: text('response_body'), + numberOfRetries: integer('number_of_retries').default(0).notNull(), createdAt: timestamp('created_at').defaultNow().notNull(), finishedAt: timestamp('finished_at'), }, diff --git a/packages/webhooks/src/handle-webhook-event.ts b/packages/webhooks/src/handle-webhook-event.ts index db98a56..603d8c3 100644 --- a/packages/webhooks/src/handle-webhook-event.ts +++ b/packages/webhooks/src/handle-webhook-event.ts @@ -9,6 +9,7 @@ export async function handleWebhookEvent({ deliverTo, companyWebhookId, trigger, + numberOfRetries, payload, }: WebhookEvent) { const webhookLogId = crypto.randomUUID() @@ -56,6 +57,7 @@ export async function handleWebhookEvent({ httpMethod: 'POST', requestBody, requestHeaders: JSON.stringify(requestHeaders), + numberOfRetries, }) const response = await fetch(deliverTo, { diff --git a/packages/webhooks/src/webhook-event.ts b/packages/webhooks/src/webhook-event.ts index 0d9a920..27d003b 100644 --- a/packages/webhooks/src/webhook-event.ts +++ b/packages/webhooks/src/webhook-event.ts @@ -14,36 +14,42 @@ export const webhookEventSchema = z.discriminatedUnion('trigger', [ trigger: z.literal('upload.created'), deliverTo: z.string().url(), companyWebhookId: z.string().uuid(), + numberOfRetries: z.number(), payload: uploadCreatedSchema, }), z.object({ trigger: z.literal('upload.updated'), deliverTo: z.string().url(), companyWebhookId: z.string().uuid(), + numberOfRetries: z.number(), payload: uploadUpdatedSchema, }), z.object({ trigger: z.literal('upload.deleted'), deliverTo: z.string().url(), companyWebhookId: z.string().uuid(), + numberOfRetries: z.number(), payload: uploadDeletedSchema, }), z.object({ trigger: z.literal('upload.transcription.created'), deliverTo: z.string().url(), companyWebhookId: z.string().uuid(), + numberOfRetries: z.number(), payload: uploadTranscriptionCreatedSchema, }), z.object({ trigger: z.literal('tag.created'), deliverTo: z.string().url(), companyWebhookId: z.string().uuid(), + numberOfRetries: z.number(), payload: tagCreatedSchema, }), z.object({ trigger: z.literal('tag.deleted'), deliverTo: z.string().url(), companyWebhookId: z.string().uuid(), + numberOfRetries: z.number(), payload: tagDeletedSchema, }), ])