Skip to content

Commit 15b26e3

Browse files
committed
more webhook stuf
stuff webhook call changes more stuff stuff stuff more webhook stuff add pnpm more ui stuff stuff sdk stuff stuff
1 parent b4640ac commit 15b26e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+4193
-100
lines changed

apps/marketing/next-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference path="./.next/types/routes.d.ts" />
34

45
// NOTE: This file should not be edited
56
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

apps/web/next-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference path="./.next/types/routes.d.ts" />
34

45
// NOTE: This file should not be edited
56
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

apps/web/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@trpc/react-query": "^11.1.1",
4040
"@trpc/server": "^11.1.1",
4141
"@usesend/email-editor": "workspace:*",
42+
"@usesend/lib": "workspace:*",
4243
"@usesend/ui": "workspace:*",
4344
"bullmq": "^5.51.1",
4445
"chrono-node": "^2.8.0",
@@ -65,12 +66,13 @@
6566
"react-hook-form": "^7.56.1",
6667
"recharts": "^2.15.3",
6768
"server-only": "^0.0.1",
69+
"shiki": "^3.3.0",
6870
"stripe": "^18.0.0",
6971
"superjson": "^2.2.2",
7072
"tldts": "^7.0.4",
7173
"ua-parser-js": "^2.0.3",
72-
"usesend-js": "workspace:*",
7374
"use-debounce": "^10.0.4",
75+
"usesend-js": "workspace:*",
7476
"zod": "^3.24.3",
7577
"zustand": "^5.0.8"
7678
},
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
-- CreateEnum
2+
CREATE TYPE "WebhookStatus" AS ENUM ('ACTIVE', 'PAUSED', 'AUTO_DISABLED', 'DELETED');
3+
4+
-- CreateEnum
5+
CREATE TYPE "WebhookCallStatus" AS ENUM ('PENDING', 'IN_PROGRESS', 'DELIVERED', 'FAILED', 'DISCARDED');
6+
7+
-- CreateTable
8+
CREATE TABLE "Webhook" (
9+
"id" TEXT NOT NULL,
10+
"teamId" INTEGER NOT NULL,
11+
"url" TEXT NOT NULL,
12+
"description" TEXT,
13+
"secret" TEXT NOT NULL,
14+
"status" "WebhookStatus" NOT NULL DEFAULT 'ACTIVE',
15+
"eventTypes" TEXT[],
16+
"apiVersion" TEXT,
17+
"consecutiveFailures" INTEGER NOT NULL DEFAULT 0,
18+
"lastFailureAt" TIMESTAMP(3),
19+
"lastSuccessAt" TIMESTAMP(3),
20+
"createdByUserId" INTEGER,
21+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
22+
"updatedAt" TIMESTAMP(3) NOT NULL,
23+
24+
CONSTRAINT "Webhook_pkey" PRIMARY KEY ("id")
25+
);
26+
27+
-- CreateTable
28+
CREATE TABLE "WebhookCall" (
29+
"id" TEXT NOT NULL,
30+
"webhookId" TEXT NOT NULL,
31+
"teamId" INTEGER NOT NULL,
32+
"type" TEXT NOT NULL,
33+
"payload" TEXT NOT NULL,
34+
"status" "WebhookCallStatus" NOT NULL DEFAULT 'PENDING',
35+
"attempt" INTEGER NOT NULL DEFAULT 0,
36+
"nextAttemptAt" TIMESTAMP(3),
37+
"lastError" TEXT,
38+
"responseStatus" INTEGER,
39+
"responseTimeMs" INTEGER,
40+
"responseText" TEXT,
41+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
42+
"updatedAt" TIMESTAMP(3) NOT NULL,
43+
44+
CONSTRAINT "WebhookCall_pkey" PRIMARY KEY ("id")
45+
);
46+
47+
-- CreateIndex
48+
CREATE INDEX "Webhook_teamId_idx" ON "Webhook"("teamId");
49+
50+
-- CreateIndex
51+
CREATE INDEX "WebhookCall_teamId_webhookId_status_idx" ON "WebhookCall"("teamId", "webhookId", "status");
52+
53+
-- CreateIndex
54+
CREATE INDEX "WebhookCall_createdAt_idx" ON "WebhookCall"("createdAt" DESC);
55+
56+
-- AddForeignKey
57+
ALTER TABLE "Webhook" ADD CONSTRAINT "Webhook_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
58+
59+
-- AddForeignKey
60+
ALTER TABLE "Webhook" ADD CONSTRAINT "Webhook_createdByUserId_fkey" FOREIGN KEY ("createdByUserId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
61+
62+
-- AddForeignKey
63+
ALTER TABLE "WebhookCall" ADD CONSTRAINT "WebhookCall_webhookId_fkey" FOREIGN KEY ("webhookId") REFERENCES "Webhook"("id") ON DELETE CASCADE ON UPDATE CASCADE;
64+
65+
-- AddForeignKey
66+
ALTER TABLE "WebhookCall" ADD CONSTRAINT "WebhookCall_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;

apps/web/prisma/schema.prisma

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,18 @@ model VerificationToken {
7979
}
8080

8181
model User {
82-
id Int @id @default(autoincrement())
83-
name String?
84-
email String? @unique
85-
emailVerified DateTime?
86-
image String?
87-
isBetaUser Boolean @default(false)
88-
isWaitlisted Boolean @default(false)
89-
createdAt DateTime @default(now())
90-
accounts Account[]
91-
sessions Session[]
92-
teamUsers TeamUser[]
82+
id Int @id @default(autoincrement())
83+
name String?
84+
email String? @unique
85+
emailVerified DateTime?
86+
image String?
87+
isBetaUser Boolean @default(false)
88+
isWaitlisted Boolean @default(false)
89+
createdAt DateTime @default(now())
90+
accounts Account[]
91+
sessions Session[]
92+
teamUsers TeamUser[]
93+
webhookEndpoints Webhook[]
9394
}
9495

9596
enum Plan {
@@ -122,6 +123,8 @@ model Team {
122123
subscription Subscription[]
123124
invites TeamInvite[]
124125
suppressionList SuppressionList[]
126+
webhookEndpoints Webhook[]
127+
webhookCalls WebhookCall[]
125128
}
126129

127130
model TeamInvite {
@@ -443,3 +446,61 @@ model SuppressionList {
443446
444447
@@unique([teamId, email])
445448
}
449+
450+
enum WebhookStatus {
451+
ACTIVE
452+
PAUSED
453+
AUTO_DISABLED
454+
}
455+
456+
enum WebhookCallStatus {
457+
PENDING
458+
IN_PROGRESS
459+
DELIVERED
460+
FAILED
461+
DISCARDED
462+
}
463+
464+
model Webhook {
465+
id String @id @default(cuid())
466+
teamId Int
467+
url String
468+
description String?
469+
secret String
470+
status WebhookStatus @default(ACTIVE)
471+
eventTypes String[]
472+
apiVersion String?
473+
consecutiveFailures Int @default(0)
474+
lastFailureAt DateTime?
475+
lastSuccessAt DateTime?
476+
createdByUserId Int?
477+
createdAt DateTime @default(now())
478+
updatedAt DateTime @updatedAt
479+
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
480+
calls WebhookCall[]
481+
createdBy User? @relation(fields: [createdByUserId], references: [id], onDelete: SetNull)
482+
483+
@@index([teamId])
484+
}
485+
486+
model WebhookCall {
487+
id String @id @default(cuid())
488+
webhookId String
489+
teamId Int
490+
type String
491+
payload String
492+
status WebhookCallStatus @default(PENDING)
493+
attempt Int @default(0)
494+
nextAttemptAt DateTime?
495+
lastError String?
496+
responseStatus Int?
497+
responseTimeMs Int?
498+
responseText String?
499+
createdAt DateTime @default(now())
500+
updatedAt DateTime @updatedAt
501+
webhook Webhook @relation(fields: [webhookId], references: [id], onDelete: Cascade)
502+
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
503+
504+
@@index([teamId, webhookId, status])
505+
@@index([createdAt(sort: Desc)])
506+
}

apps/web/src/app/(dashboard)/dev-settings/layout.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
22

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

56
export const dynamic = "force-static";
@@ -11,9 +12,12 @@ export default function ApiKeysPage({
1112
}) {
1213
return (
1314
<div>
14-
<h1 className="font-bold text-lg">Developer settings</h1>
15+
<H1>Developer Settings</H1>
1516
<div className="flex gap-4 mt-4">
1617
<SettingsNavButton href="/dev-settings">API Keys</SettingsNavButton>
18+
<SettingsNavButton href="/dev-settings/webhooks">
19+
Webhooks
20+
</SettingsNavButton>
1721
<SettingsNavButton href="/dev-settings/smtp">SMTP</SettingsNavButton>
1822
</div>
1923
<div className="mt-8">{children}</div>

apps/web/src/app/(dashboard)/emails/email-details.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
BOUNCE_ERROR_MESSAGES,
2020
COMPLAINT_ERROR_MESSAGES,
2121
DELIVERY_DELAY_ERRORS,
22-
} from "~/lib/constants/ses-errors";
22+
} from "@usesend/lib/src/constants/ses-errors";
2323
import CancelEmail from "./cancel-email";
2424
import { useEffect } from "react";
2525
import { useState } from "react";
@@ -75,7 +75,7 @@ export default function EmailDetails({ emailId }: { emailId: string }) {
7575
<span className="text-sm">
7676
{formatDate(
7777
emailQuery.data?.scheduledAt,
78-
"MMM dd'th', hh:mm a"
78+
"MMM dd'th', hh:mm a",
7979
)}
8080
</span>
8181
<div className="ml-4">

0 commit comments

Comments
 (0)