Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@trpc/react-query": "^11.1.1",
"@trpc/server": "^11.1.1",
"@usesend/email-editor": "workspace:*",
"@usesend/lib": "workspace:*",
"@usesend/ui": "workspace:*",
"bullmq": "^5.51.1",
"chrono-node": "^2.8.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
-- CreateEnum
CREATE TYPE "WebhookStatus" AS ENUM ('ACTIVE', 'PAUSED', 'AUTO_DISABLED');

-- CreateEnum
CREATE TYPE "WebhookCallStatus" AS ENUM ('PENDING', 'IN_PROGRESS', 'DELIVERED', 'FAILED', 'DISCARDED');

-- CreateTable
CREATE TABLE "Webhook" (
"id" TEXT NOT NULL,
"teamId" INTEGER NOT NULL,
"url" TEXT NOT NULL,
"description" TEXT,
"secret" TEXT NOT NULL,
"status" "WebhookStatus" NOT NULL DEFAULT 'ACTIVE',
"eventTypes" TEXT[],
"apiVersion" TEXT,
"consecutiveFailures" INTEGER NOT NULL DEFAULT 0,
"lastFailureAt" TIMESTAMP(3),
"lastSuccessAt" TIMESTAMP(3),
"createdByUserId" INTEGER,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "Webhook_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "WebhookCall" (
"id" TEXT NOT NULL,
"webhookId" TEXT NOT NULL,
"teamId" INTEGER NOT NULL,
"type" TEXT NOT NULL,
"payload" TEXT NOT NULL,
"status" "WebhookCallStatus" NOT NULL DEFAULT 'PENDING',
"attempt" INTEGER NOT NULL DEFAULT 0,
"nextAttemptAt" TIMESTAMP(3),
"lastError" TEXT,
"responseStatus" INTEGER,
"responseTimeMs" INTEGER,
"responseText" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "WebhookCall_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE INDEX "Webhook_teamId_idx" ON "Webhook"("teamId");

-- CreateIndex
CREATE INDEX "WebhookCall_teamId_webhookId_status_idx" ON "WebhookCall"("teamId", "webhookId", "status");

-- CreateIndex
CREATE INDEX "WebhookCall_createdAt_idx" ON "WebhookCall"("createdAt" DESC);

-- AddForeignKey
ALTER TABLE "Webhook" ADD CONSTRAINT "Webhook_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Webhook" ADD CONSTRAINT "Webhook_createdByUserId_fkey" FOREIGN KEY ("createdByUserId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "WebhookCall" ADD CONSTRAINT "WebhookCall_webhookId_fkey" FOREIGN KEY ("webhookId") REFERENCES "Webhook"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "WebhookCall" ADD CONSTRAINT "WebhookCall_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
83 changes: 72 additions & 11 deletions apps/web/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,18 @@ model VerificationToken {
}

model User {
id Int @id @default(autoincrement())
name String?
email String? @unique
emailVerified DateTime?
image String?
isBetaUser Boolean @default(false)
isWaitlisted Boolean @default(false)
createdAt DateTime @default(now())
accounts Account[]
sessions Session[]
teamUsers TeamUser[]
id Int @id @default(autoincrement())
name String?
email String? @unique
emailVerified DateTime?
image String?
isBetaUser Boolean @default(false)
isWaitlisted Boolean @default(false)
createdAt DateTime @default(now())
accounts Account[]
sessions Session[]
teamUsers TeamUser[]
webhookEndpoints Webhook[]
}

enum Plan {
Expand Down Expand Up @@ -122,6 +123,8 @@ model Team {
subscription Subscription[]
invites TeamInvite[]
suppressionList SuppressionList[]
webhookEndpoints Webhook[]
webhookCalls WebhookCall[]
}

model TeamInvite {
Expand Down Expand Up @@ -443,3 +446,61 @@ model SuppressionList {

@@unique([teamId, email])
}

enum WebhookStatus {
ACTIVE
PAUSED
AUTO_DISABLED
}

enum WebhookCallStatus {
PENDING
IN_PROGRESS
DELIVERED
FAILED
DISCARDED
}

model Webhook {
id String @id @default(cuid())
teamId Int
url String
description String?
secret String
status WebhookStatus @default(ACTIVE)
eventTypes String[]
apiVersion String?
consecutiveFailures Int @default(0)
lastFailureAt DateTime?
lastSuccessAt DateTime?
createdByUserId Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
calls WebhookCall[]
createdBy User? @relation(fields: [createdByUserId], references: [id], onDelete: SetNull)

@@index([teamId])
}

model WebhookCall {
id String @id @default(cuid())
webhookId String
teamId Int
type String
payload String
status WebhookCallStatus @default(PENDING)
attempt Int @default(0)
nextAttemptAt DateTime?
lastError String?
responseStatus Int?
responseTimeMs Int?
responseText String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
webhook Webhook @relation(fields: [webhookId], references: [id], onDelete: Cascade)
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)

@@index([teamId, webhookId, status])
@@index([createdAt(sort: Desc)])
}
3 changes: 2 additions & 1 deletion apps/web/src/app/(dashboard)/dev-settings/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import { H1 } from "@usesend/ui";
import { SettingsNavButton } from "./settings-nav-button";

export const dynamic = "force-static";
Expand All @@ -11,7 +12,7 @@ export default function ApiKeysPage({
}) {
return (
<div>
<h1 className="font-bold text-lg">Developer settings</h1>
<H1>Developer Settings</H1>
<div className="flex gap-4 mt-4">
<SettingsNavButton href="/dev-settings">API Keys</SettingsNavButton>
<SettingsNavButton href="/dev-settings/smtp">SMTP</SettingsNavButton>
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/app/(dashboard)/emails/email-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
BOUNCE_ERROR_MESSAGES,
COMPLAINT_ERROR_MESSAGES,
DELIVERY_DELAY_ERRORS,
} from "~/lib/constants/ses-errors";
} from "@usesend/lib/src/constants/ses-errors";
import CancelEmail from "./cancel-email";
import { useEffect } from "react";
import { useState } from "react";
Expand Down Expand Up @@ -75,7 +75,7 @@ export default function EmailDetails({ emailId }: { emailId: string }) {
<span className="text-sm">
{formatDate(
emailQuery.data?.scheduledAt,
"MMM dd'th', hh:mm a"
"MMM dd'th', hh:mm a",
)}
</span>
<div className="ml-4">
Expand Down
Loading