Skip to content

Open-source status page, incident response and uptime monitoring

🧹 some cleaning and improvments (#633)

Thibault Le Ouay6aa605e6de04
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index df7fd9957..b02e41638 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -3,7 +3,9 @@ name: Code Check
on:
push:
branches:
- - "*"
+ - "main"
+ pull_request:
+ branches: [main]
jobs:
lint:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index a253db2b8..683671077 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -3,7 +3,9 @@ name: Tests
on:
push:
branches:
- - "*"
+ - "main"
+ pull_request:
+ branches: [main]
jobs:
tests:
diff --git a/apps/server/src/checker/alerting.ts b/apps/server/src/checker/alerting.ts
index 05abc42c3..f8cb2e208 100644
--- a/apps/server/src/checker/alerting.ts
+++ b/apps/server/src/checker/alerting.ts
@@ -38,6 +38,9 @@ export const triggerAlerting = async ({
.where(eq(schema.monitor.id, Number(monitorId)))
.all();
for (const notif of notifications) {
+ console.log(
+ `💌 sending notification for ${monitorId} and chanel ${notif.notification.provider}`,
+ );
const monitor = selectMonitorSchema.parse(notif.monitor);
await providerToFunction[notif.notification.provider]({
monitor,
diff --git a/apps/web/.env.example b/apps/web/.env.example
index 89677cb13..3215d81ee 100644
--- a/apps/web/.env.example
+++ b/apps/web/.env.example
@@ -51,15 +51,6 @@ NEXT_PUBLIC_URL=
NEXT_PUBLIC_SENTRY_DSN=''
-# Vercel Log Drains
-INTEGRATION_SECRET=
-LOG_DRAIN_SECRET=
-
-# Marketplace Integration
-VERCEL_CLIENT_ID=
-VERCEL_CLIENT_SECRET=
-VERCEL_REDIRECT_URI=
-AES_KEY=
# Unkey
UNKEY_API_ID=
UNKEY_TOKEN=
@@ -73,4 +64,4 @@ CRON_SECRET=
EXTERNAL_API_URL=
-PLAYGROUND_UNKEY_API_KEY=
\ No newline at end of file
+PLAYGROUND_UNKEY_API_KEY=
diff --git a/apps/web/package.json b/apps/web/package.json
index 38c47959a..3c979db3b 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -27,7 +27,6 @@
"@openstatus/ui": "workspace:*",
"@openstatus/upstash": "workspace:*",
"@openstatus/utils": "workspace:*",
- "@openstatus/vercel": "workspace:*",
"@sentry/integrations": "7.73.0",
"@sentry/nextjs": "7.73.0",
"@stripe/stripe-js": "2.1.6",
diff --git a/apps/web/src/env.ts b/apps/web/src/env.ts
index 390931f7c..2833183a8 100644
--- a/apps/web/src/env.ts
+++ b/apps/web/src/env.ts
@@ -3,7 +3,6 @@ import { z } from "zod";
import "@openstatus/db/env.mjs";
import "@openstatus/analytics/env";
-import "@openstatus/vercel/env";
export const env = createEnv({
server: {
diff --git a/packages/integrations/vercel/.env.example b/packages/integrations/vercel/.env.example
deleted file mode 100644
index ef6628e12..000000000
--- a/packages/integrations/vercel/.env.example
+++ /dev/null
@@ -1,12 +0,0 @@
-# Log Drains
-# add from the first form - 'x-vercel-verify'
-INTEGRATION_SECRET=
-# after verify, in the modal box - 'x-vercel-signature'
-LOG_DRAIN_SECRET=
-
-
-# Marketplace Integration
-VERCEL_CLIENT_ID=
-VERCEL_CLIENT_SECRET=
-VERCEL_REDIRECT_URI=
-AES_KEY=
\ No newline at end of file
diff --git a/packages/integrations/vercel/README.md b/packages/integrations/vercel/README.md
deleted file mode 100644
index 0fe7a2bcd..000000000
--- a/packages/integrations/vercel/README.md
+++ /dev/null
@@ -1,60 +0,0 @@
-# Log drain integration for Vercel
-
-Seamless installement into Vercel's log drains for your project.
-
-> Inspired by
-> [@valeriangalliat/vercel-custom-log-drain](https://github.com/valeriangalliat/vercel-custom-log-drain).
-
-## Description
-
-When integrating the Vercel App into your project. Every request to
-[openstatus.dev](https://openstatus.dev) will include the key inside of the
-`Headers`.
-
-Once we have the `access_token` token we will be able to `createLogDrain` as
-authentificated user. The token is only expires after 30 minutes and is required
-for the user to access the integration within vercel.
-
-When creating the log drain, we should include a custom header to it, with an
-`OpenStatus-Vercel-TOKEN: "os_xxx-yyy"` token from Unkey. That way, it is easy
-to revoke tokens. We can test without but should include it. Check with Andreas
-how a good use case an look like.
-
-The new created log drain will point towards our `/api/integrations/vercel`. We
-will then be able to filter them and ingest Tinybird the the logs we want to
-keep. Maybe, we can start first by ingesting only errors.
-
-1. We can start simple an only create the log drain for the user. nothing else
-2. Once clear we will have to create a little `/configure` page where the user,
- authentificated within vercel, can update the log drain integration easily.
-
-The UI for the Integration should be the bare minimum. The UX should be in the
-focus. Default shadcn/ui components will do it.
-
-- white background
-- `DataTable` filled with `getLogDrains` data:
- - createdAt
- - name
- - projectId
- - dropdown menu: data can be deleted
-- 'Connect'-button to add log drains to different projet
-
-<!-- Redirect URL aka callback explaination -->
-
-### Files
-
-- `webhook.ts`: ingests Tinybird with the log drains
-- `callback.ts`: callback for getting an access token
-- `configure.ts`: simple page to configure your vercel integration authorized as
- vercel user through access token
-- `client.ts`: includes all important REST API calls to vercel, updating the
- users project
-
-### API Scopes
-
-The following scopes are necessary:
-
-- Log Drains (Read/Write): be able to send a request with the payload
-- Projects (Read): connect log drains with projects
-
-> We might require more scopes.
diff --git a/packages/integrations/vercel/env.ts b/packages/integrations/vercel/env.ts
deleted file mode 100644
index da33d360a..000000000
--- a/packages/integrations/vercel/env.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { createEnv } from "@t3-oss/env-core";
-import { z } from "zod";
-
-export const env = createEnv({
- server: {
- INTEGRATION_SECRET: z.string().min(1),
- TINY_BIRD_API_KEY: z.string().min(1),
- },
- runtimeEnv: {
- INTEGRATION_SECRET: process.env.INTEGRATION_SECRET,
- TINY_BIRD_API_KEY: process.env.TINY_BIRD_API_KEY,
- },
-});
diff --git a/packages/integrations/vercel/package.json b/packages/integrations/vercel/package.json
deleted file mode 100644
index f471d9e7f..000000000
--- a/packages/integrations/vercel/package.json
+++ /dev/null
@@ -1,21 +0,0 @@
-{
- "name": "@openstatus/vercel",
- "version": "0.0.0",
- "main": "src/index.ts",
- "description": "Log drains Vercel integration.",
- "dependencies": {
- "@openstatus/tinybird": "workspace:*",
- "@t3-oss/env-core": "0.7.0",
- "react": "18.2.0",
- "react-dom": "18.2.0",
- "zod": "^3.22.2"
- },
- "devDependencies": {
- "@openstatus/tsconfig": "workspace:*",
- "@types/node": "20.8.0",
- "@types/react": "18.2.24",
- "@types/react-dom": "18.2.8",
- "next": "13.5.3",
- "typescript": "5.2.2"
- }
-}
diff --git a/packages/integrations/vercel/src/components/integration-card.tsx b/packages/integrations/vercel/src/components/integration-card.tsx
deleted file mode 100644
index e39bbf67a..000000000
--- a/packages/integrations/vercel/src/components/integration-card.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-export const VercelIntegrationCard = () => {
- return <></>;
-};
diff --git a/packages/integrations/vercel/src/components/submit-button.tsx b/packages/integrations/vercel/src/components/submit-button.tsx
deleted file mode 100644
index 9fa2a9328..000000000
--- a/packages/integrations/vercel/src/components/submit-button.tsx
+++ /dev/null
@@ -1,22 +0,0 @@
-"use client";
-
-import { experimental_useFormStatus as useFormStatus } from "react-dom";
-
-export function SubmitButton({
- disabled,
- children,
-}: {
- disabled?: boolean;
- children: React.ReactNode;
-}) {
- const { pending } = useFormStatus();
- return (
- <button
- type="submit"
- disabled={pending || disabled}
- className="bg-foreground text-background rounded-md px-2 py-1 disabled:cursor-not-allowed disabled:opacity-60"
- >
- {pending ? "Loading" : children}
- </button>
- );
-}
diff --git a/packages/integrations/vercel/src/index.ts b/packages/integrations/vercel/src/index.ts
deleted file mode 100644
index 8526d383c..000000000
--- a/packages/integrations/vercel/src/index.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-export * from "./libs/schema";
-export * from "./routes/webhook";
-export * from "./routes/callback";
-export * from "./pages/configure";
diff --git a/packages/integrations/vercel/src/libs/client.ts b/packages/integrations/vercel/src/libs/client.ts
deleted file mode 100644
index f5c3160c1..000000000
--- a/packages/integrations/vercel/src/libs/client.ts
+++ /dev/null
@@ -1,157 +0,0 @@
-// CREDITS: https://github.com/valeriangalliat/vercel-custom-log-drain/blob/43043c095475c9fac279e5fec8976497ee1ea9b6/clients/vercel.ts
-
-import { projectsSchema } from "./schema";
-
-async function fetchOk(
- url: string,
- init?: RequestInit | undefined,
-): Promise<Response> {
- const res = await fetch(url, init);
-
- if (!res.ok) {
- const contentType = res.headers.get("content-type");
- let body: string | object | null;
-
- try {
- const isJson = contentType && contentType.includes("json");
- body = await (isJson ? res.json() : res.text());
- } catch (err) {
- body = null;
- }
-
- console.log({ body });
-
- throw Object.assign(new Error(`Failed to fetch: ${url}`), {
- res,
- body,
- });
- }
-
- return res;
-}
-
-const base = "https://api.vercel.com";
-
-export async function getToken(code: string): Promise<string> {
- const url = `${base}/v2/oauth/access_token`;
-
- const res = await fetchOk(url, {
- method: "POST",
- headers: {
- "Content-Type": "application/x-www-form-urlencoded",
- },
- body: new URLSearchParams({
- client_id: process.env.VERCEL_CLIENT_ID || "",
- client_secret: process.env.VERCEL_CLIENT_SECRET || "",
- code,
- redirect_uri: process.env.VERCEL_REDIRECT_URI || "",
- }),
- });
-
- const json = await res.json();
-
- return json.access_token;
-}
-
-// Type from <https://vercel.com/docs/log-drains>
-export type LogDrain = {
- /** The oauth2 client application id that created this log drain */
- clientId: string;
- /** The client configuration this log drain was created with */
- configurationId: string;
- /** A timestamp that tells you when the log drain was created */
- createdAt: number;
- /** The unique identifier of the log drain. Always prefixed with `ld_` */
- id: string;
- /** The type of log format */
- deliveryFormat: "json" | "ndjson" | "syslog";
- /** The name of the log drain */
- name: string;
- /** The identifier of the team or user whose events will trigger the log drain */
- ownerId: string;
- /** The identifier of the project this log drain is associated with */
- projectId?: string | null;
- /** The URL to call when logs are generated */
- url: string;
- /** TODO: add correct description and check if correct */
- headers?: Record<string, string>;
- /** The sources from which logs are currently being delivered to this log drain */
- sources?: (
- | "static"
- | "lambda"
- | "build"
- | "edge"
- | "external"
- | "deployment"
- )[]; // REMINDER: creating a log drain with "deployment" source won't work
-};
-
-function getQuery(teamId?: string) {
- return teamId ? `?teamId=${encodeURIComponent(teamId)}` : "";
-}
-
-export async function getLogDrains(
- token: string,
- teamId?: string,
-): Promise<LogDrain[]> {
- const url = `${base}/v2/integrations/log-drains${getQuery(teamId)}`;
-
- const res = await fetchOk(url, {
- headers: {
- Authorization: `Bearer ${token}`,
- },
- });
-
- return await res.json();
-}
-
-export async function getProjects(token: string, teamId?: string) {
- const url = `${base}/v9/projects${getQuery(teamId)}`;
-
- const res = await fetchOk(url, {
- headers: {
- Authorization: `Bearer ${token}`,
- },
- });
-
- const json = await res.json();
- console.log(json);
- return projectsSchema.parse(json);
-}
-
-export async function createLogDrain(
- token: string,
- logDrain: LogDrain,
- teamId?: string,
-): Promise<LogDrain> {
- const url = `${base}/v2/integrations/log-drains${getQuery(teamId)}`;
-
- console.log({ token, logDrain, teamId });
-
- const res = await fetchOk(url, {
- method: "post",
- headers: {
- Authorization: `Bearer ${token}`,
- },
- body: JSON.stringify(logDrain),
- });
-
- return await res.json();
-}
-
-export async function deleteLogDrain(
- token: string,
- id: string,
- teamId?: string,
-): Promise<void> {
- const url = `${base}/v1/integrations/log-drains/${encodeURIComponent(
- id,
- )}${getQuery(teamId)}`;
-
- await fetchOk(url, {
- method: "delete",
- headers: {
- Authorization: `Bearer ${token}`,
- },
- });
-}
diff --git a/packages/integrations/vercel/src/libs/crypto.ts b/packages/integrations/vercel/src/libs/crypto.ts
deleted file mode 100644
index eb0989cc7..000000000
--- a/packages/integrations/vercel/src/libs/crypto.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-// CREDITS: https://github.com/valeriangalliat/vercel-custom-log-drain/blob/master/utils/crypto.ts
-
-import crypto from "crypto";
-
-/** generate key via `node -p "crypto.randomBytes(32).toString('base64url')"` */
-const key = Buffer.from(process.env.AES_KEY || "", "base64url");
-
-export function encrypt(iv: Buffer, data: Buffer): Buffer {
- const cipher = crypto.createCipheriv("aes-256-cbc", key, iv);
- return Buffer.concat([cipher.update(data), cipher.final()]);
-}
-
-export function decrypt(iv: Buffer, encrypted: Buffer): Buffer {
- const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
- return Buffer.concat([decipher.update(encrypted), decipher.final()]);
-}
diff --git a/packages/integrations/vercel/src/libs/schema.ts b/packages/integrations/vercel/src/libs/schema.ts
deleted file mode 100644
index 1c2d85cb7..000000000
--- a/packages/integrations/vercel/src/libs/schema.ts
+++ /dev/null
@@ -1,613 +0,0 @@
-import * as z from "zod";
-
-/**
- * If the response of the request returns an HTTP statusCode with a value of -1,
- * that means there was no response returned and the lambda crashed.
- * In the same response, if the value of proxy.statusCode is returned with -1,
- * that means the revalidation occurred in the background.
- */
-
-// https://vercel.com/docs/observability/log-drains-overview/log-drains-reference#json-log-drains
-export const logDrainSchema = z.object({
- id: z.string().optional(),
- timestamp: z.number().optional(),
- type: z
- .enum([
- "middleware-invocation",
- "stdout",
- "stderr",
- "edge-function-invocation",
- "fatal",
- ])
- .optional(),
- edgeType: z.enum(["edge-function", "middleware"]).optional(),
- requestId: z.string().optional(),
- statusCode: z.number().optional(),
- message: z.string().optional(),
- projectId: z.string().optional(),
- deploymentId: z.string().optional(),
- buildId: z.string().optional(),
- source: z.enum(["external", "lambda", "edge", "static", "build"]),
- host: z.string().optional(),
- environment: z.string().optional(),
- branch: z.string().optional(),
- destination: z.string().optional(),
- path: z.string().optional(),
- entrypoint: z.string().optional(),
- proxy: z
- .object({
- timestamp: z.number().optional(),
- region: z.string().optional(), // TODO: use regions enum?
- method: z.string().optional(), // TODO: use methods enum?
- vercelCache: z.string().optional(), // TODO: use "HIT" / "MISS" enum?
- statusCode: z.number().optional(),
- path: z.string().optional(),
- host: z.string().optional(),
- scheme: z.string().optional(),
- clientIp: z.string().optional(),
- userAgent: z.array(z.string()).optional(),
- })
- .optional(),
-});
-
-export const logDrainSchemaArray = z.array(logDrainSchema);
-
-export const projectSchema = z.object({
- accountId: z.string(),
- analytics: z
- .object({
- id: z.string(),
- canceledAt: z.number().nullable(),
- disabledAt: z.number(),
- enabledAt: z.number(),
- paidAt: z.number().optional(),
- sampleRatePercent: z.number().optional().nullable(),
- spendLimitInDollars: z.number().optional().nullable(),
- })
- .optional(),
- autoExposeSystemEnvs: z.boolean().optional(),
- autoAssignCustomDomains: z.boolean().optional(),
- autoAssignCustomDomainsUpdatedBy: z.string().optional(),
- buildCommand: z.string().optional().nullable(),
- commandForIgnoringBuildStep: z.string().optional().nullable(),
- connectConfigurationId: z.string().optional().nullable(),
- connectBuildsEnabled: z.boolean().optional(),
- createdAt: z.number().optional(),
- customerSupportCodeVisibility: z.boolean().optional(),
- crons: z
- .object({
- enabledAt: z.number(),
- disabledAt: z.number().nullable(),
- updatedAt: z.number(),
- deploymentId: z.string().nullable(),
- definitions: z.array(
- z.object({
- host: z.string(),
- path: z.string(),
- schedule: z.string(),
- }),
- ),
- })
- .optional(),
- dataCache: z
- .object({
- userDisabled: z.boolean(),
- storageSizeBytes: z.number().optional().nullable(),
- unlimited: z.boolean().optional(),
- })
- .optional(),
- devCommand: z.string().optional().nullable(),
- directoryListing: z.boolean(),
- installCommand: z.string().optional().nullable(),
- env: z
- .array(
- z.object({
- target: z
- .union([
- z.array(
- z.union([
- z.literal("production"),
- z.literal("preview"),
- z.literal("development"),
- z.literal("preview"),
- z.literal("development"),
- ]),
- ),
- z.union([
- z.literal("production"),
- z.literal("preview"),
- z.literal("development"),
- z.literal("preview"),
- z.literal("development"),
- ]),
- ])
- .optional(),
- type: z.union([
- z.literal("secret"),
- z.literal("system"),
- z.literal("encrypted"),
- z.literal("plain"),
- z.literal("sensitive"),
- ]),
- id: z.string().optional(),
- key: z.string(),
- value: z.string(),
- configurationId: z.string().optional().nullable(),
- createdAt: z.number().optional(),
- updatedAt: z.number().optional(),
- createdBy: z.string().optional().nullable(),
- updatedBy: z.string().optional().nullable(),
- gitBranch: z.string().optional(),
- edgeConfigId: z.string().optional().nullable(),
- edgeConfigTokenId: z.string().optional().nullable(),
- contentHint: z
- .union([
- z.object({
- type: z.literal("redis-url"),
- storeId: z.string(),
- }),
- z.object({
- type: z.literal("redis-rest-api-url"),
- storeId: z.string(),
- }),
- z.object({
- type: z.literal("redis-rest-api-token"),
- storeId: z.string(),
- }),
- z.object({
- type: z.literal("redis-rest-api-read-only-token"),
- storeId: z.string(),
- }),
- z.object({
- type: z.literal("blob-read-write-token"),
- storeId: z.string(),
- }),
- z.object({
- type: z.literal("postgres-url"),
- storeId: z.string(),
- }),
- z.object({
- type: z.literal("postgres-url-non-pooling"),
- storeId: z.string(),
- }),
- z.object({
- type: z.literal("postgres-prisma-url"),
- storeId: z.string(),
- }),
- z.object({
- type: z.literal("postgres-user"),
- storeId: z.string(),
- }),
- z.object({
- type: z.literal("postgres-host"),
- storeId: z.string(),
- }),
- z.object({
- type: z.literal("postgres-password"),
- storeId: z.string(),
- }),
- z.object({
- type: z.literal("postgres-database"),
- storeId: z.string(),
- }),
- ])
- .optional(),
- decrypted: z.boolean().optional(),
- }),
- )
- .optional(),
- framework: z
- .union([
- z.literal("blitzjs"),
- z.literal("nextjs"),
- z.literal("gatsby"),
- z.literal("remix"),
- z.literal("astro"),
- z.literal("hexo"),
- z.literal("eleventy"),
- z.literal("docusaurus-2"),
- z.literal("docusaurus"),
- z.literal("preact"),
- z.literal("solidstart"),
- z.literal("dojo"),
- z.literal("ember"),
- z.literal("vue"),
- z.literal("scully"),
- z.literal("ionic-angular"),
- z.literal("angular"),
- z.literal("polymer"),
- z.literal("svelte"),
- z.literal("sveltekit"),
- z.literal("sveltekit-1"),
- z.literal("ionic-react"),
- z.literal("create-react-app"),
- z.literal("gridsome"),
- z.literal("umijs"),
- z.literal("sapper"),
- z.literal("saber"),
- z.literal("stencil"),
- z.literal("nuxtjs"),
- z.literal("redwoodjs"),
- z.literal("hugo"),
- z.literal("jekyll"),
- z.literal("brunch"),
- z.literal("middleman"),
- z.literal("zola"),
- z.literal("hydrogen"),
- z.literal("vite"),
- z.literal("vitepress"),
- z.literal("vuepress"),
- z.literal("parcel"),
- z.literal("sanity"),
- z.literal("storybook"),
- ])
- .optional(),
- gitForkProtection: z.boolean().optional(),
- gitLFS: z.boolean().optional(),
- id: z.string(),
- latestDeployments: z
- .array(
- z.object({
- alias: z.array(z.string()).optional(),
- aliasAssigned: z.union([z.number(), z.boolean(), z.null()]).nullish(),
- aliasError: z
- .object({
- code: z.string(),
- message: z.string(),
- })
- .optional()
- .nullable(),
- aliasFinal: z.string().optional().nullable(),
- automaticAliases: z.array(z.string()).optional(),
- builds: z
- .array(
- z.object({
- use: z.string(),
- src: z.string().optional(),
- dest: z.string().optional(),
- }),
- )
- .optional(),
- connectBuildsEnabled: z.boolean().optional(),
- connectConfigurationId: z.string().optional(),
- createdAt: z.number(),
- createdIn: z.string(),
- creator: z
- .object({
- email: z.string(),
- githubLogin: z.string().optional(),
- gitlabLogin: z.string().optional(),
- uid: z.string(),
- username: z.string(),
- })
- .nullable(),
- deploymentHostname: z.string(),
- name: z.string(),
- forced: z.boolean().optional(),
- id: z.string(),
- meta: z.record(z.string()).optional(),
- monorepoManager: z.string().optional().nullable(),
- plan: z.union([
- z.literal("pro"),
- z.literal("enterprise"),
- z.literal("hobby"),
- z.literal("oss"),
- ]),
- private: z.boolean(),
- readyState: z.union([
- z.literal("BUILDING"),
- z.literal("ERROR"),
- z.literal("INITIALIZING"),
- z.literal("QUEUED"),
- z.literal("READY"),
- z.literal("CANCELED"),
- ]),
- readySubstate: z
- .union([z.literal("STAGED"), z.literal("PROMOTED")])
- .optional(),
- requestedAt: z.number().optional(),
- target: z.string().optional().nullable(),
- teamId: z.string().optional().nullable(),
- type: z.literal("LAMBDAS"),
- url: z.string(),
- userId: z.string(),
- withCache: z.boolean().optional(),
- checksConclusion: z
- .union([
- z.literal("succeeded"),
- z.literal("failed"),
- z.literal("skipped"),
- z.literal("canceled"),
- ])
- .optional(),
- checksState: z
- .union([
- z.literal("registered"),
- z.literal("running"),
- z.literal("completed"),
- ])
- .optional(),
- readyAt: z.number().optional(),
- buildingAt: z.number().optional(),
- previewCommentsEnabled: z.boolean().optional(),
- }),
- )
- .optional(),
- link: z
- .union([
- z.object({
- org: z.string().optional(),
- repo: z.string().optional(),
- repoId: z.number().optional(),
- type: z.literal("github").optional(),
- createdAt: z.number().optional(),
- deployHooks: z.array(
- z.object({
- createdAt: z.number().optional(),
- id: z.string(),
- name: z.string(),
- ref: z.string(),
- url: z.string(),
- }),
- ),
- gitCredentialId: z.string().optional(),
- updatedAt: z.number().optional(),
- sourceless: z.boolean().optional(),
- productionBranch: z.string().optional(),
- }),
- z.object({
- projectId: z.string().optional(),
- projectName: z.string().optional(),
- projectNameWithNamespace: z.string().optional(),
- projectNamespace: z.string().optional(),
- projectUrl: z.string().optional(),
- type: z.literal("gitlab").optional(),
- createdAt: z.number().optional(),
- deployHooks: z.array(
- z.object({
- createdAt: z.number().optional(),
- id: z.string(),
- name: z.string(),
- ref: z.string(),
- url: z.string(),
- }),
- ),
- gitCredentialId: z.string().optional(),
- updatedAt: z.number().optional(),
- sourceless: z.boolean().optional(),
- productionBranch: z.string().optional(),
- }),
- z.object({
- name: z.string().optional(),
- slug: z.string().optional(),
- owner: z.string().optional(),
- type: z.literal("bitbucket").optional(),
- uuid: z.string().optional(),
- workspaceUuid: z.string().optional(),
- createdAt: z.number().optional(),
- deployHooks: z.array(
- z.object({
- createdAt: z.number().optional(),
- id: z.string(),
- name: z.string(),
- ref: z.string(),
- url: z.string(),
- }),
- ),
- gitCredentialId: z.string().optional(),
- updatedAt: z.number().optional(),
- sourceless: z.boolean().optional(),
- productionBranch: z.string().optional(),
- }),
- ])
- .optional(),
- name: z.string(),
- nodeVersion: z.union([
- z.literal("18.x"),
- z.literal("16.x"),
- z.literal("14.x"),
- z.literal("12.x"),
- z.literal("10.x"),
- ]),
- outputDirectory: z.string().optional().nullable(),
- passwordProtection: z.record(z.unknown()).optional().nullable(),
- productionDeploymentsFastLane: z.boolean().optional(),
- publicSource: z.boolean().optional().nullable(),
- rootDirectory: z.string().optional().nullable(),
- serverlessFunctionRegion: z.string().optional().nullable(),
- skipGitConnectDuringLink: z.boolean().optional(),
- sourceFilesOutsideRootDirectory: z.boolean().optional(),
- ssoProtection: z
- .object({
- deploymentType: z.union([
- z.literal("all"),
- z.literal("preview"),
- z.literal("prod_deployment_urls_and_all_previews"),
- ]),
- })
- .optional()
- .nullable(),
- targets: z
- .record(
- z
- .object({
- alias: z.array(z.string()).optional(),
- aliasAssigned: z.union([z.number(), z.boolean(), z.null()]).nullish(),
- aliasError: z
- .object({
- code: z.string(),
- message: z.string(),
- })
- .optional()
- .nullable(),
- aliasFinal: z.string().optional().nullable(),
- automaticAliases: z.array(z.string()).optional(),
- builds: z
- .array(
- z.object({
- use: z.string(),
- src: z.string().optional(),
- dest: z.string().optional(),
- }),
- )
- .optional(),
- connectBuildsEnabled: z.boolean().optional(),
- connectConfigurationId: z.string().optional(),
- createdAt: z.number(),
- createdIn: z.string(),
- creator: z
- .object({
- email: z.string(),
- githubLogin: z.string().optional(),
- gitlabLogin: z.string().optional(),
- uid: z.string(),
- username: z.string(),
- })
- .nullable(),
- deploymentHostname: z.string(),
- name: z.string(),
- forced: z.boolean().optional(),
- id: z.string(),
- meta: z.record(z.string()).optional(),
- monorepoManager: z.string().optional().nullable(),
- plan: z.union([
- z.literal("pro"),
- z.literal("enterprise"),
- z.literal("hobby"),
- z.literal("oss"),
- ]),
- private: z.boolean(),
- readyState: z.union([
- z.literal("BUILDING"),
- z.literal("ERROR"),
- z.literal("INITIALIZING"),
- z.literal("QUEUED"),
- z.literal("READY"),
- z.literal("CANCELED"),
- ]),
- readySubstate: z
- .union([z.literal("STAGED"), z.literal("PROMOTED")])
- .optional(),
- requestedAt: z.number().optional(),
- target: z.string().optional().nullable(),
- teamId: z.string().optional().nullable(),
- type: z.literal("LAMBDAS"),
- url: z.string(),
- userId: z.string(),
- withCache: z.boolean().optional(),
- checksConclusion: z
- .union([
- z.literal("succeeded"),
- z.literal("failed"),
- z.literal("skipped"),
- z.literal("canceled"),
- ])
- .optional(),
- checksState: z
- .union([
- z.literal("registered"),
- z.literal("running"),
- z.literal("completed"),
- ])
- .optional(),
- readyAt: z.number().optional(),
- buildingAt: z.number().optional(),
- previewCommentsEnabled: z.boolean().optional(),
- })
- .nullable(),
- )
- .optional(),
- transferCompletedAt: z.number().optional(),
- transferStartedAt: z.number().optional(),
- transferToAccountId: z.string().optional(),
- transferredFromAccountId: z.string().optional(),
- updatedAt: z.number().optional(),
- live: z.boolean().optional(),
- enablePreviewFeedback: z.boolean().optional().nullable(),
- permissions: z.object({}).optional(),
- lastRollbackTarget: z.record(z.unknown()).optional().nullable(),
- lastAliasRequest: z
- .object({
- fromDeploymentId: z.string(),
- toDeploymentId: z.string(),
- jobStatus: z.union([
- z.literal("succeeded"),
- z.literal("failed"),
- z.literal("skipped"),
- z.literal("pending"),
- z.literal("in-progress"),
- ]),
- requestedAt: z.number(),
- type: z.union([z.literal("promote"), z.literal("rollback")]),
- })
- .optional()
- .nullable(),
- hasFloatingAliases: z.boolean().optional(),
- protectionBypass: z
- .record(
- z.union([
- z.object({
- createdAt: z.number(),
- createdBy: z.string(),
- scope: z.union([
- z.literal("shareable-link"),
- z.literal("automation-bypass"),
- ]),
- }),
- z.object({
- createdAt: z.number(),
- lastUpdatedAt: z.number(),
- lastUpdatedBy: z.string(),
- access: z.union([z.literal("requested"), z.literal("granted")]),
- scope: z.literal("user"),
- }),
- ]),
- )
- .optional(),
- hasActiveBranches: z.boolean().optional(),
- trustedIps: z
- .union([
- z.object({
- deploymentType: z.union([
- z.literal("all"),
- z.literal("preview"),
- z.literal("prod_deployment_urls_and_all_previews"),
- z.literal("production"),
- ]),
- addresses: z.array(
- z.object({
- value: z.string(),
- note: z.string().optional(),
- }),
- ),
- protectionMode: z.union([
- z.literal("additional"),
- z.literal("exclusive"),
- ]),
- }),
- z.object({
- deploymentType: z.union([
- z.literal("all"),
- z.literal("preview"),
- z.literal("prod_deployment_urls_and_all_previews"),
- z.literal("production"),
- ]),
- }),
- ])
- .optional(),
- gitComments: z
- .object({
- onPullRequest: z.boolean(),
- onCommit: z.boolean(),
- })
- .optional(),
-});
-
-export const projectsSchema = z.object({
- projects: z.array(projectSchema),
- pagination: z.object({
- count: z.number(),
- next: z.number().nullable(),
- prev: z.number().nullable(),
- }),
-});
diff --git a/packages/integrations/vercel/src/libs/tinybird.ts b/packages/integrations/vercel/src/libs/tinybird.ts
deleted file mode 100644
index cea819c25..000000000
--- a/packages/integrations/vercel/src/libs/tinybird.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import { Tinybird } from "@openstatus/tinybird";
-
-import { logDrainSchema } from "./schema";
-
-const tb = new Tinybird({ token: process.env.TINY_BIRD_API_KEY || "" }); // should we use t3-env?
-
-export function publishVercelLogDrain() {
- return tb.buildIngestEndpoint({
- datasource: "vercel_log_drain__v0",
- event: logDrainSchema,
- });
-}
diff --git a/packages/integrations/vercel/src/pages/configure.tsx b/packages/integrations/vercel/src/pages/configure.tsx
deleted file mode 100644
index ca52e8200..000000000
--- a/packages/integrations/vercel/src/pages/configure.tsx
+++ /dev/null
@@ -1,107 +0,0 @@
-import { revalidatePath } from "next/cache";
-import { cookies } from "next/headers";
-import { redirect } from "next/navigation";
-
-import { SubmitButton } from "../components/submit-button";
-import {
- createLogDrain,
- deleteLogDrain,
- getLogDrains,
- getProjects,
-} from "../libs/client";
-import { decrypt } from "../libs/crypto";
-
-export async function Configure() {
- const iv = cookies().get("iv")?.value;
- const encryptedToken = cookies().get("token")?.value;
- const teamId = cookies().get("teamId")?.value;
-
- if (!iv || !encryptedToken) {
- /** Redirect to access new token */
- return redirect("/app");
- }
-
- const token = decrypt(
- Buffer.from(iv || "", "base64url"),
- Buffer.from(encryptedToken || "", "base64url"),
- ).toString();
-
- let logDrains = await getLogDrains(token, teamId);
-
- const projects = await getProjects(token, teamId);
-
- for (const project of projects.projects) {
- console.log({ project });
- console.log("create integration");
- }
- // Create integration project if it doesn't exist
-
- if (logDrains.length === 0) {
- logDrains = [
- await createLogDrain(
- token,
- // @ts-expect-error We need more data - but this is a demo
- {
- deliveryFormat: "json",
- name: "OpenStatus Log Drain",
- // TODO: update with correct url
- url: "https://wwww.openstatus.dev/api/integrations/vercel",
- sources: ["static", "lambda", "edge", "external"],
- // headers: { "key": "value"}
- },
- teamId,
- ),
- ];
- }
-
- // TODO: automatically create log drain on installation
- async function create(formData: FormData) {
- "use server";
- await createLogDrain(
- token,
- // @ts-expect-error We need more data - but this is a demo
- {
- deliveryFormat: "json",
- name: "OpenStatus Log Drain",
- // TODO: update with correct url
- url: "https://wwww.openstatus.dev/api/integrations/vercel",
- sources: ["static", "lambda", "edge", "external"],
- // headers: { "key": "value"}
- },
- teamId,
- );
- revalidatePath("/");
- }
-
- async function _delete(formData: FormData) {
- "use server";
- const id = formData.get("id")?.toString();
- console.log({ id });
- if (id) {
- await deleteLogDrain(token, id, String(teamId));
- revalidatePath("/");
- }
- }
-
- return (
- <div className="flex w-full flex-col items-center justify-center">
- <div className="border-border m-3 grid w-full max-w-xl gap-3 rounded-lg border p-6 backdrop-blur-[2px]">
- <h1 className="font-cal text-2xl">Configure Vercel Integration</h1>
- <ul>
- {logDrains.map((item) => (
- <li
- key={item.id}
- className="flex items-center justify-between gap-2"
- >
- <p>{item.name}</p>
- <form action={_delete}>
- <input name="id" value={item.id} className="hidden" />
- <SubmitButton>Remove integration</SubmitButton>
- </form>
- </li>
- ))}
- </ul>
- </div>
- </div>
- );
-}
diff --git a/packages/integrations/vercel/src/routes/callback.ts b/packages/integrations/vercel/src/routes/callback.ts
deleted file mode 100644
index e25dd9005..000000000
--- a/packages/integrations/vercel/src/routes/callback.ts
+++ /dev/null
@@ -1,54 +0,0 @@
-import crypto from "crypto";
-import { NextResponse } from "next/server";
-import type { NextRequest } from "next/server";
-
-import { getToken } from "../libs/client";
-import { encrypt } from "../libs/crypto";
-
-export async function GET(req: NextRequest) {
- const { searchParams } = new URL(req.url);
- const code = searchParams.get("code");
- const next = searchParams.get("next");
- const teamId = searchParams.get("teamId");
- console.log({ code, next, teamId });
- if (!code || !next) {
- throw new Error("Missing `code` or `next` param");
- }
-
- /** Get access token from Vercel */
- const token = await getToken(code);
-
- // TODO: automatically install log drains to the allowed projects
-
- const iv = crypto.randomBytes(16);
- const encryptedToken = encrypt(iv, Buffer.from(token));
-
- // redirect to vercel's integration page after installation
- const res = NextResponse.redirect(
- `https://wwww.openstatus.dev/app/integrations/vercel/configure`,
- );
-
- console.log("Setting cookies");
- /** Encrypt access token and add to Cookies */
- res.cookies.set("token", encryptedToken.toString("base64url"));
- res.cookies.set("iv", iv.toString("base64url"));
-
- if (teamId) {
- res.cookies.set("teamId", teamId);
- }
-
- return res;
-}
-
-/**
- * The code below is only needed if we allow the user
- * to send the secret link to a team mate e.g.
- */
-function getSecretUrl(iv: Buffer, encryptedToken: Buffer) {
- const baseUrl = new URL(process.env.VRCL_REDIRECT_URI!);
- baseUrl.pathname = "/configure";
- baseUrl.searchParams.set("token", encryptedToken.toString("base64url"));
- baseUrl.searchParams.set("iv", iv.toString("base64url"));
- const secretUrl = baseUrl.toString();
- return secretUrl;
-}
diff --git a/packages/integrations/vercel/src/routes/webhook.ts b/packages/integrations/vercel/src/routes/webhook.ts
deleted file mode 100644
index 55bd5379d..000000000
--- a/packages/integrations/vercel/src/routes/webhook.ts
+++ /dev/null
@@ -1,76 +0,0 @@
-import { log } from "console";
-import crypto from "crypto";
-import { NextResponse } from "next/server";
-import * as z from "zod";
-
-import { env } from "../../env";
-import { logDrainSchemaArray } from "../libs/schema";
-import { publishVercelLogDrain } from "../libs/tinybird";
-
-export const config = {
- api: {
- bodyParser: false,
- },
-};
-
-/**
- * Ingest log drains from Vercel.
- */
-export async function POST(request: Request) {
- const rawBody = await request.text();
- // const rawBodyBuffer = Buffer.from(rawBody, "utf-8");
- // // const bodySignature = sha1(rawBodyBuffer, "LOG_DRAIN_SECRET");
-
- // // /**
- // // * Validates the signature of the request
- // // * Uncomment for 'Test Log Drain' in Vercel
- // // */
- // // if (bodySignature !== request.headers.get("x-vercel-signature")) {
- // // return NextResponse.json(
- // // {
- // // code: "invalid_signature",
- // // error: "signature didn't match",
- // // },
- // // { status: 401 },
- // // );
- // // }
-
- /**
- * Returns a header verification to Vercel, so the route can be added as a log drain
- */
- if (z.object({}).safeParse(JSON.parse(rawBody)).success) {
- return NextResponse.json(
- { code: "ok" },
- { status: 200, headers: { "x-vercel-verify": env.INTEGRATION_SECRET } },
- );
- }
-
- /**
- * Validates the body of the request
- */
- const logDrains = logDrainSchemaArray.safeParse(JSON.parse(rawBody));
-
- if (logDrains.success) {
- // We are only pushing the logs that are not stdout or stderr
- const data = logDrains.data.filter(
- (log) => log.type !== "stdout" && log.type !== "stderr",
- );
-
- for (const event of data) {
- // FIXME: Zod-bird is broken
- await publishVercelLogDrain()(event);
- }
-
- return NextResponse.json({ code: "ok" }, { status: 200 });
- } else {
- console.error("Error parsing logDrains", logDrains.error);
- }
- return NextResponse.json({ error: logDrains.error }, { status: 500 });
-}
-
-/**
- * Creates a sha1 hash from a buffer and a secret
- */
-function sha1(data: Buffer, secret: string) {
- return crypto.createHmac("sha1", secret).update(data).digest("hex");
-}
diff --git a/packages/integrations/vercel/tsconfig.json b/packages/integrations/vercel/tsconfig.json
deleted file mode 100644
index a8a8c9309..000000000
--- a/packages/integrations/vercel/tsconfig.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "extends": "@openstatus/tsconfig/nextjs.json",
- "include": ["src", "*.ts"]
-}
diff --git a/packages/notifications/discord/src/index.ts b/packages/notifications/discord/src/index.ts
index f7a7d871c..36f42cb8c 100644
--- a/packages/notifications/discord/src/index.ts
+++ b/packages/notifications/discord/src/index.ts
@@ -18,7 +18,6 @@ const postToWebhook = async (content: string, webhookUrl: string) => {
export const sendDiscordMessage = async ({
monitor,
notification,
- region,
statusCode,
message,
}: {
@@ -36,12 +35,13 @@ export const sendDiscordMessage = async ({
await postToWebhook(
`Your monitor ${name} is down 🚨
- Your monitor with url ${monitor.url} is down in ${region} with ${
+ Your monitor with url ${monitor.url} is down with ${
statusCode ? `status code ${statusCode}` : `error message ${message}`
}.`,
webhookUrl,
);
} catch (err) {
+ console.error(err);
// Do something
}
};
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 02c4a0fde..c0d9045a5 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -155,9 +155,6 @@ importers:
'@openstatus/utils':
specifier: workspace:*
version: link:../../packages/utils
- '@openstatus/vercel':
- specifier: workspace:*
- version: link:../../packages/integrations/vercel
'@sentry/integrations':
specifier: 7.73.0
version: 7.73.0
@@ -543,43 +540,6 @@ importers:
specifier: 5.2.2
version: 5.2.2
- packages/integrations/vercel:
- dependencies:
- '@openstatus/tinybird':
- specifier: workspace:*
- version: link:../../tinybird
- '@t3-oss/env-core':
- specifier: 0.7.0
- react:
- specifier: 18.2.0
- version: 18.2.0
- react-dom:
- specifier: 18.2.0
- version: 18.2.0([email protected])
- zod:
- specifier: ^3.22.2
- version: 3.22.2
- devDependencies:
- '@openstatus/tsconfig':
- specifier: workspace:*
- version: link:../../tsconfig
- '@types/node':
- specifier: 20.8.0
- version: 20.8.0
- '@types/react':
- specifier: 18.2.24
- version: 18.2.24
- '@types/react-dom':
- specifier: 18.2.8
- version: 18.2.8
- next:
- specifier: 13.5.3
- typescript:
- specifier: 5.2.2
- version: 5.2.2
-
packages/notifications/discord:
dependencies:
'@openstatus/db':