Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
feat: response header analysis (#809)
Maximilian Kaske2d9420c5613e
diff --git a/apps/web/package.json b/apps/web/package.jsonindex de3b7b625..882bf95d2 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -21,6 +21,7 @@"@openstatus/assertions": "workspace:*","@openstatus/db": "workspace:*","@openstatus/emails": "workspace:*",+ "@openstatus/header-analysis": "workspace:*","@openstatus/next-monitoring": "0.0.2","@openstatus/notification-discord": "workspace:*","@openstatus/notification-emails": "workspace:*",diff --git a/apps/web/src/app/app/(auth)/layout.tsx b/apps/web/src/app/app/(auth)/login/layout.tsxsimilarity index 50%rename from apps/web/src/app/app/(auth)/layout.tsxrename to apps/web/src/app/app/(auth)/login/layout.tsxindex 21814f3b1..40424c0ab 100644--- a/apps/web/src/app/app/(auth)/layout.tsx+++ b/apps/web/src/app/app/(auth)/login/layout.tsx@@ -16,36 +16,38 @@ export default async function AuthLayout({return (<div className="grid min-h-screen grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-5"><aside className="border-border col-span-1 flex w-full flex-col gap-4 border p-4 backdrop-blur-[2px] md:p-8 xl:col-span-2">- <Link href="/" className="relative">+ <Link href="/" className="relative h-8 w-8"><Imagesrc="/icon.png"alt="OpenStatus"- height={30}- width={30}+ height={32}+ width={32}className="border-border rounded-full border"/></Link>- <div className="flex w-full max-w-lg flex-1 flex-col justify-center text-left">- <h1 className="font-cal text-foreground mb-3 text-2xl">- Open Source Monitoring Service- </h1>- <p className="text-muted-foreground">- Monitor your website or API and create your own status page within a- couple of minutes. Want to know how it works? <br />- <br />- Check out{" "}- <a- href="https://github.com/openstatushq/openstatus"- target="_blank"- rel="noreferrer"- className="text-foreground underline underline-offset-4 hover:no-underline"- >- GitHub- </a>{" "}- and let us know your use case!- </p>+ <div className="flex w-full max-w-lg flex-1 flex-col justify-center gap-8 text-left">+ <div className="mx-auto grid gap-3">+ <h1 className="font-cal text-foreground text-2xl">+ Open Source Monitoring Service+ </h1>+ <p className="text-muted-foreground">+ Monitor your website or API and create your own status page within+ a couple of minutes. Want to know how it works? <br />+ <br />+ Check out{" "}+ <a+ href="https://github.com/openstatushq/openstatus"+ target="_blank"+ rel="noreferrer"+ className="text-foreground underline underline-offset-4 hover:no-underline"+ >+ GitHub+ </a>{" "}+ and let us know your use case!+ </p>+ </div></div>- <div className="md:h-[30px]" />+ <div className="md:h-8" /></aside><main className="container col-span-1 mx-auto flex items-center justify-center md:col-span-1 xl:col-span-3">{children}diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/_components/data-table-wrapper.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/_components/data-table-wrapper.tsxindex bf2e096da..a52c22f08 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/_components/data-table-wrapper.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/_components/data-table-wrapper.tsx@@ -101,6 +101,7 @@ function Details({ row }: { row: Row<Monitor> }) {<ResponseDetailTabstiming={first.timing}headers={first.headers}+ status={first.statusCode}message={first.message}assertions={assertions.deserialize(first.assertions || "[]")}/>diff --git a/apps/web/src/app/play/checker/[id]/page.tsx b/apps/web/src/app/play/checker/[id]/page.tsxindex 5a507a400..f0d1dbc59 100644--- a/apps/web/src/app/play/checker/[id]/page.tsx+++ b/apps/web/src/app/play/checker/[id]/page.tsx@@ -47,7 +47,7 @@ export default async function CheckPage({ params, searchParams }: Props) {const check =data.checks.find((i) => i.region === selectedRegion) || data.checks?.[0];- const { region, headers, timing } = check;+ const { region, headers, timing, status } = check;return (<>@@ -77,7 +77,7 @@ export default async function CheckPage({ params, searchParams }: Props) {<RegionInfo check={check} /></div></div>- <ResponseDetailTabs timing={timing} headers={headers} />+ <ResponseDetailTabs {...{ timing, headers, status }} /></div><Separator /><p className="text-muted-foreground text-sm">@@ -85,7 +85,7 @@ export default async function CheckPage({ params, searchParams }: Props) {<span className="text-foreground">1 day</span>. If you want to persistthe data,{" "}<Link- href="/app/sign-in"+ href="/app/login"className="text-foreground underline underline-offset-4 hover:no-underline">logindiff --git a/apps/web/src/app/sitemap.ts b/apps/web/src/app/sitemap.tsindex f756a3805..d82a012fa 100644--- a/apps/web/src/app/sitemap.ts+++ b/apps/web/src/app/sitemap.ts@@ -23,9 +23,7 @@ export default function sitemap(): MetadataRoute.Sitemap {"/about","/blog","/changelog",- "/app/sign-in",- "/app/sign-up",- "/monitor/openstatus",+ "/app/login",].map((route) => ({url: addPathToBaseURL(route),lastModified: new Date(),diff --git a/apps/web/src/app/status-page/[domain]/_components/header.tsx b/apps/web/src/app/status-page/[domain]/_components/header.tsxindex e897c745e..7d9c048a3 100644--- a/apps/web/src/app/status-page/[domain]/_components/header.tsx+++ b/apps/web/src/app/status-page/[domain]/_components/header.tsx@@ -43,7 +43,7 @@ export function Header({ navigation, plan, page }: Props) {</div>) : null}</div>- <TabsContainer className="-mb-[12px] hidden sm:block">+ <TabsContainer className="-mb-[14px] hidden sm:block">{navigation.map(({ label, href, disabled, segment }) => {const active = segment === selectedSegment;return (diff --git a/apps/web/src/components/forms/monitor/request-test-button.tsx b/apps/web/src/components/forms/monitor/request-test-button.tsxindex c5d131c72..2ecdf061c 100644--- a/apps/web/src/components/forms/monitor/request-test-button.tsx+++ b/apps/web/src/components/forms/monitor/request-test-button.tsx@@ -133,6 +133,7 @@ export function RequestTestButton({ form, pingEndpoint }: Props) {<ResponseDetailTabstiming={check.data.timing}headers={check.data.headers}+ status={check.data.status}assertions={deserialize(JSON.stringify([...(statusAssertions || []),diff --git a/apps/web/src/components/marketing/hero.tsx b/apps/web/src/components/marketing/hero.tsxindex 9e4cce565..c8ba1624d 100644--- a/apps/web/src/components/marketing/hero.tsx+++ b/apps/web/src/components/marketing/hero.tsx@@ -41,7 +41,7 @@ export function Hero() {<div className="my-4 grid gap-2 sm:grid-cols-2"><div className="text-center sm:block sm:text-right"><Button className="w-48 rounded-full sm:w-auto" asChild>- <Link href="/app/sign-up">Get Started</Link>+ <Link href="/app/login">Get Started</Link></Button></div><div className="text-center sm:block sm:text-left">diff --git a/apps/web/src/components/marketing/in-between-cta.tsx b/apps/web/src/components/marketing/in-between-cta.tsxindex 136f267c1..4eb2246f0 100644--- a/apps/web/src/components/marketing/in-between-cta.tsx+++ b/apps/web/src/components/marketing/in-between-cta.tsx@@ -50,7 +50,7 @@ export function BottomCTA() {<InBetweenCTAdescription="Learn over time how your services are performing, and inform your users when there are issues."actions={{- primary: { label: "Start for Free", href: "/app/sign-up" },+ primary: { label: "Start for Free", href: "/app/login" },secondary: { label: "Schedule a Demo", href: "/cal", target: "_blank" },}}/>diff --git a/apps/web/src/components/marketing/pricing/pricing-table.tsx b/apps/web/src/components/marketing/pricing/pricing-table.tsxindex 4384030d5..a08b2aef5 100644--- a/apps/web/src/components/marketing/pricing/pricing-table.tsx+++ b/apps/web/src/components/marketing/pricing/pricing-table.tsx@@ -80,7 +80,9 @@ export function PricingTable({if (events?.[key]) {return events[key]?.();}- return router.push(`/app/sign-up?plan=${key}`);+ // FIXME: how to properly handle `?redirectTo` with unknown workspaceSlug+ // to redirect user to `/app/[workspaceSlug]/settings/billing?plan=${key}`?+ return router.push(`/app/login?plan=${key}`);}}disabled={isCurrentPlan || isLoading}>diff --git a/apps/web/src/components/monitor-dashboard/response-details.tsx b/apps/web/src/components/monitor-dashboard/response-details.tsxindex cff4796f3..802ad269e 100644--- a/apps/web/src/components/monitor-dashboard/response-details.tsx+++ b/apps/web/src/components/monitor-dashboard/response-details.tsx@@ -23,7 +23,7 @@ export async function ResponseDetails(props: ResponseDetailsParams) {const response = details[0];- const { timing, headers, message } = response;+ const { timing, headers, message, statusCode } = response;const defaultValue = headers ? "headers" : timing ? "timing" : "message";@@ -50,7 +50,9 @@ export async function ResponseDetails(props: ResponseDetailsParams) {</TabsTrigger></TabsList><TabsContent value="headers">- {headers ? <ResponseHeaderTable headers={headers} /> : null}+ {headers ? (+ <ResponseHeaderTable headers={headers} status={statusCode || 0} />+ ) : null}</TabsContent><TabsContent value="timing">{timing ? <ResponseTimingTable timing={timing} hideInfo /> : null}diff --git a/apps/web/src/components/ping-response-analysis/response-detail-tabs.tsx b/apps/web/src/components/ping-response-analysis/response-detail-tabs.tsxindex 62a758110..1b50890ca 100644--- a/apps/web/src/components/ping-response-analysis/response-detail-tabs.tsx+++ b/apps/web/src/components/ping-response-analysis/response-detail-tabs.tsx@@ -14,11 +14,13 @@ import type { Timing } from "./utils";export async function ResponseDetailTabs({timing,headers,+ status,message,assertions,}: {timing: Timing | null;headers: Record<string, string> | null;+ status: number | null;message?: string | null;assertions?: Assertion[] | null;}) {@@ -43,9 +45,12 @@ export async function ResponseDetailTabs({</TabsTrigger></TabsList><TabsContent value="headers">- {headers ? <ResponseHeaderTable headers={headers} /> : null}+ {headers ? (+ <ResponseHeaderTable headers={headers} status={status || 0} />+ ) : null}</TabsContent><TabsContent value="timing">+ {/* TODO: show hideInfo={false} when in /play/checker page */}{timing ? <ResponseTimingTable timing={timing} hideInfo /> : null}</TabsContent><TabsContent value="message">diff --git a/apps/web/src/components/ping-response-analysis/response-header-analysis.tsx b/apps/web/src/components/ping-response-analysis/response-header-analysis.tsxnew file mode 100644index 000000000..7c550a6a9--- /dev/null+++ b/apps/web/src/components/ping-response-analysis/response-header-analysis.tsx@@ -0,0 +1,240 @@+import "@openstatus/header-analysis";++import React from "react";+import { Info } from "lucide-react";++import {+ parseCacheControlHeader,+ parseCfCacheStatus,+ parseCfRay,+ parseFlyRequestId,+ parseXVercelCache,+ parseXVercelId,+} from "@openstatus/header-analysis";+import {+ Dialog,+ DialogContent,+ DialogDescription,+ DialogHeader,+ DialogTitle,+ DialogTrigger,+} from "@openstatus/ui";++const allowedHeaders = [+ "Cache-Control",+ "Cf-Cache-Status",+ "Cf-Ray",+ "X-Vercel-Cache",+ "X-Vercel-Id",+ "Location",+ "Fly-Request-Id",+];++export function ResponseHeaderAnalysis({+ headerKey,+ headers,+ status,+}: {+ headers: Record<string, string | undefined>;+ headerKey: string;+ status: number;+}) {+ const header = headers[headerKey];++ if (!header) return null;+ if (!allowedHeaders.includes(headerKey)) return null;++ return (+ <Dialog>+ <DialogTrigger className="text-muted-foreground hover:text-foreground data-[state=open]:text-foreground">+ <Info className="h-4 w-4" />+ </DialogTrigger>+ <DialogContent className="sm:max-w-2xl">+ <DialogHeader>+ <DialogTitle>Header Analysis</DialogTitle>+ <DialogDescription>+ Breaking down the{" "}+ <code className="font-semibold">"{headerKey}"</code>{" "}+ header.+ </DialogDescription>+ </DialogHeader>+ {(() => {+ switch (headerKey) {+ case "Cache-Control":+ return <CacheControl header={header} />;+ case "Cf-Cache-Status":+ return <CfCacheStatus header={header} />;+ case "Cf-Ray":+ return <CfRay header={header} />;+ case "X-Vercel-Cache":+ return <XVercelCache header={header} />;+ case "X-Vercel-Id":+ return <XVercelId header={header} />;+ case "Fly-Request-Id":+ return <FlyRequestId header={header} />;+ case "Location":+ return <Location header={header} status={status} />;+ default:+ return null;+ }+ })()}+ </DialogContent>+ </Dialog>+ );+}++function CacheControl({ header }: { header: string }) {+ const values = parseCacheControlHeader(header);++ return (+ <div className="grid gap-4 sm:grid-cols-4">+ {values.map(({ name, value, description }) => {+ return (+ <React.Fragment key={name}>+ <p className="sm:col-span-1">+ <code className="bg-muted rounded p-1 font-semibold">{name}</code>{" "}+ {value !== undefined ? <code>({value})</code> : null}+ </p>+ <p className="sm:col-span-3">{description}</p>+ </React.Fragment>+ );+ })}+ </div>+ );+}++function CfCacheStatus({ header }: { header: string }) {+ const { value, description } = parseCfCacheStatus(header);++ return (+ <div className="grid gap-4 sm:grid-cols-4">+ <p className="sm:col-span-1">+ <code className="bg-muted rounded p-1 font-semibold">{value}</code>+ </p>+ <p className="sm:col-span-3">{description}</p>+ </div>+ );+}++function XVercelCache({ header }: { header: string }) {+ const { value, description } = parseXVercelCache(header);++ return (+ <div className="grid gap-4 sm:grid-cols-4">+ <p className="sm:col-span-1">+ <code className="bg-muted rounded p-1 font-semibold">{value}</code>+ </p>+ <p className="sm:col-span-3">{description}</p>+ </div>+ );+}++export function XVercelId({ header }: { header: string }) {+ const value = parseXVercelId(header);++ return (+ <div className="grid gap-4">+ <p className="text-muted-foreground col-span-full text-sm">+ This header contains a list of Edge regions your request hit, as well as+ the region the function was executed in (for both Edge and Serverless):+ </p>+ <div className="grid grid-cols-4 gap-3">+ {value.status === "failed" ? (+ <p className="text-destructive">{value.error.message}</p>+ ) : (+ value.data.map(({ code, location, flag }) => (+ <React.Fragment key={code}>+ <p className="sm:col-span-1">+ <code className="bg-muted rounded p-1 font-semibold">+ {code}+ </code>+ </p>+ <p className="sm:col-span-3">+ {location} {flag}+ </p>+ </React.Fragment>+ ))+ )}+ </div>+ </div>+ );+}++export function CfRay({ header }: { header: string }) {+ const value = parseCfRay(header);++ return (+ <div className="grid gap-4">+ <p className="text-muted-foreground col-span-full text-sm">+ This header is a hashed value that encodes information about the data+ center and the visitor’s request. The data center the request hit is:+ </p>+ {value.status === "failed" ? (+ <p className="text-destructive">{value.error.message}</p>+ ) : (+ <div className="grid grid-cols-4 gap-3">+ <p className="sm:col-span-1">+ <code className="bg-muted rounded p-1 font-semibold">+ {value.data.code}+ </code>+ </p>+ <p className="sm:col-span-3">+ {value.data.location} {value.data.flag}+ </p>+ </div>+ )}+ </div>+ );+}++export function Location({+ header,+ status,+}: {+ header: string;+ status: number;+}) {+ return (+ <div className="grid gap-4">+ <p className="text-muted-foreground col-span-full text-sm">+ This header in HTTP responses is used to redirect the client to a new+ URL. It is often seen with status codes like <code>301</code> (Moved+ Permanently) and <code>302</code> (Found), guiding the client's+ browser to navigate to a different location.+ </p>+ <div className="grid gap-4 sm:grid-cols-4">+ <p className="sm:col-span-1">+ <code className="bg-muted rounded p-1 font-semibold">{status}</code>+ </p>+ <p className="sm:col-span-3">{header}</p>+ </div>+ </div>+ );+}++export function FlyRequestId({ header }: { header: string }) {+ const value = parseFlyRequestId(header);++ return (+ <div className="grid gap-4">+ <p className="text-muted-foreground col-span-full text-sm">+ This header is a hashed value that encodes information about the data+ center and the visitor’s request. The data center the request hit is:+ </p>+ {value.status === "failed" ? (+ <p className="text-destructive">{value.error.message}</p>+ ) : (+ <div className="grid grid-cols-4 gap-3">+ <p className="sm:col-span-1">+ <code className="bg-muted rounded p-1 font-semibold">+ {value.data.code}+ </code>+ </p>+ <p className="sm:col-span-3">+ {value.data.location} {value.data.flag}+ </p>+ </div>+ )}+ </div>+ );+}diff --git a/apps/web/src/components/ping-response-analysis/response-header-table.tsx b/apps/web/src/components/ping-response-analysis/response-header-table.tsxindex 9bd7f479b..819b29cce 100644--- a/apps/web/src/components/ping-response-analysis/response-header-table.tsx+++ b/apps/web/src/components/ping-response-analysis/response-header-table.tsx@@ -9,11 +9,14 @@ import {} from "@openstatus/ui";import { CopyToClipboardButton } from "./copy-to-clipboard-button";+import { ResponseHeaderAnalysis } from "./response-header-analysis";export function ResponseHeaderTable({headers,+ status,}: {headers: Record<string, string>;+ status: number;}) {return (<Table>@@ -28,8 +31,15 @@ export function ResponseHeaderTable({{Object.entries(headers).map(([key, value]) => (<TableRow key={key}><TableCell className="group">- <div className="min-[130px] flex items-center justify-between gap-1">- <code className="break-all font-medium">{key}</code>+ <div className="flex min-w-[130px] items-center justify-between gap-2">+ <div className="flex items-center justify-between gap-2">+ <code className="break-all font-medium">{key}</code>+ <ResponseHeaderAnalysis+ headerKey={key}+ headers={headers}+ status={status}+ />+ </div><CopyToClipboardButtoncopyValue={key}className="invisible group-hover:visible"diff --git a/apps/web/src/components/ping-response-analysis/response-timing-table.tsx b/apps/web/src/components/ping-response-analysis/response-timing-table.tsxindex 13ebee315..d40721cea 100644--- a/apps/web/src/components/ping-response-analysis/response-timing-table.tsx+++ b/apps/web/src/components/ping-response-analysis/response-timing-table.tsx@@ -15,7 +15,7 @@ import {import { timingDict } from "./config";import type { Timing } from "./utils";-import { getTimingPhases, getTotalLatency } from "./utils";+import { getTimingPhases, getTimingPhasesWidth } from "./utils";export function ResponseTimingTable({timing,@@ -24,26 +24,29 @@ export function ResponseTimingTable({timing: Timing;hideInfo?: boolean;}) {- const total = getTotalLatency(timing);const timingPhases = getTimingPhases(timing);+ const timingPhasesWidth = getTimingPhasesWidth(timing);+return (<Table><TableCaption className="mt-2">Response Timing</TableCaption><TableHeader><TableRow>- <TableHead className="w-[120px] md:w-[150px]">Timing</TableHead>- <TableHead className="w-[120px] md:w-[150px]">Duration</TableHead>+ <TableHead className="w-[72px] md:w-[150px]">Timing</TableHead>+ <TableHead className="w-[100px] md:w-[150px]">Duration</TableHead><TableHead /></TableRow></TableHeader><TableBody>{Object.entries(timingPhases).map(([key, value]) => {- const { short, long, description } =- timingDict[key as keyof typeof timingPhases];+ const phase = key as keyof typeof timingPhases;+ const { short, long, description } = timingDict[phase];+ const { preWidth, width } = timingPhasesWidth[phase];+return (<TableRow key={key}><TableCell>- <div className="flex w-[80px] items-center justify-between gap-2">+ <div className="flex w-[72px] items-center justify-between gap-2"><p className="text-muted-foreground">{short}</p>{!hideInfo ? (<Popover>@@ -63,11 +66,17 @@ export function ResponseTimingTable({<TableCell><code>{value}ms</code></TableCell>- <TableCell>+ <TableCell className="flex w-full">+ <div+ style={{+ width: `${preWidth}%`,+ minWidth: "1px",+ }}+ /><divclassName="bg-foreground h-3 rounded-md"style={{- width: `${(value / total) * 100}%`,+ width: `${width}%`,minWidth: "1px",}}/>diff --git a/apps/web/src/components/ping-response-analysis/utils.ts b/apps/web/src/components/ping-response-analysis/utils.tsindex f65b8f8b4..9e49d269d 100644--- a/apps/web/src/components/ping-response-analysis/utils.ts+++ b/apps/web/src/components/ping-response-analysis/utils.ts@@ -10,7 +10,7 @@ export function latencyFormatter(value: number) {}export function timestampFormatter(timestamp: number) {- return new Date(timestamp).toLocaleString(); // TODO: properly format the date+ return new Date(timestamp).toUTCString(); // GMT format}export function regionFormatter(@@ -43,6 +43,41 @@ export function getTimingPhases(timing: Timing) {};}+export function getTimingPhasesWidth(timing: Timing) {+ const total = getTotalLatency(timing);+ const phases = getTimingPhases(timing);++ const dns = { preWidth: 0, width: (phases.dns / total) * 100 };++ const connection = {+ preWidth: dns.preWidth + dns.width,+ width: (phases.connection / total) * 100,+ };++ const tls = {+ preWidth: connection.preWidth + connection.width,+ width: (phases.tls / total) * 100,+ };++ const ttfb = {+ preWidth: tls.preWidth + tls.width,+ width: (phases.ttfb / total) * 100,+ };++ const transfer = {+ preWidth: ttfb.preWidth + ttfb.width,+ width: (phases.transfer / total) * 100,+ };++ return {+ dns,+ connection,+ tls,+ ttfb,+ transfer,+ };+}+export const timingSchema = z.object({dnsStart: z.number(),dnsDone: z.number(),diff --git a/packages/header-analysis/package.json b/packages/header-analysis/package.jsonnew file mode 100644index 000000000..b787e52c9--- /dev/null+++ b/packages/header-analysis/package.json@@ -0,0 +1,15 @@+{+ "name": "@openstatus/header-analysis",+ "version": "1.0.0",+ "description": "",+ "main": "src/index.ts",+ "scripts": {},+ "dependencies": {},+ "devDependencies": {+ "@openstatus/tsconfig": "workspace:*",+ "typescript": "5.4.5"+ },+ "keywords": [],+ "author": "",+ "license": "ISC"+}diff --git a/packages/header-analysis/src/index.ts b/packages/header-analysis/src/index.tsnew file mode 100644index 000000000..90d590561--- /dev/null+++ b/packages/header-analysis/src/index.ts@@ -0,0 +1,6 @@+export * from "./parser/cache-control";+export * from "./parser/cf-cache-status";+export * from "./parser/cf-ray";+export * from "./parser/fly-request-id";+export * from "./parser/x-vercel-cache";+export * from "./parser/x-vercel-id";\ No newline at end of filediff --git a/packages/header-analysis/src/parser/cache-control.ts b/packages/header-analysis/src/parser/cache-control.tsnew file mode 100644index 000000000..1de4bcc32--- /dev/null+++ b/packages/header-analysis/src/parser/cache-control.ts@@ -0,0 +1,63 @@+interface CacheControlInfo {+ directive: string; // unparsed directive+ description: string;+ name: string;+ value?: number;+}++export function parseCacheControlHeader(header: string): CacheControlInfo[] {+ const cacheControlDirectives = header+ .split(",")+ .map((directive) => directive.trim());++ const cacheControlInfo: CacheControlInfo[] = [];++ cacheControlDirectives.forEach((directive) => {+ const parts = directive.split("=");++ const name = parts[0].trim();+ const value = !isNaN(Number(parts[1])) ? Number(parts[1]) : undefined;+ const description = getDirectiveDescription(name);++ cacheControlInfo.push({ description, name, value, directive });+ });++ return cacheControlInfo;+}++function getDirectiveDescription(key: string): string {+ switch (key.toLowerCase()) {+ case "max-age":+ return "Specifies the maximum amount of time in seconds that a resource is considered fresh in a cache. After this time, the cache is required to revalidate the resource with the origin server.";+ case "max-stale":+ return "Indicates that a cache can serve a stale response even after its freshness lifetime has expired. Optionally, a value can be specified to indicate the maximum staleness allowed.";+ case "min-fresh":+ return "Specifies the minimum amount of time in seconds that a resource must be considered fresh. Caches should not serve a response that is older than this value without revalidating with the origin server.";+ case "s-maxage":+ return "Similar to max-age, but applies specifically to shared caches, such as proxy servers. Overrides max-age when present in shared caches.";+ case "no-cache":+ return "Forces caches to submit the request to the origin server for validation before releasing a cached copy. The response must be validated with the origin server before it can be used.";+ case "no-store":+ return "Instructs caches not to store any part of either the request or response. The content must be obtained from the origin server for each request.";+ case "no-transform":+ return "Specifies that intermediaries should not modify the content of the resource, such as by transcoding or compressing it.";+ case "only-if-cached":+ return "Indicates that a cache should respond only if the resource is available in the cache. It should not contact the origin server to retrieve the resource.";+ case "must-revalidate":+ return "Specifies that caches must revalidate stale responses with the origin server before using them.";+ case "proxy-revalidate":+ return "Similar to must-revalidate, but applies specifically to shared caches. It indicates that shared caches must revalidate stale responses with the origin server before using them.";+ case "private":+ return "Indicates that the response is intended for a single user and should not be cached by shared caches.";+ case "public":+ return "Specifies that the response may be cached by any cache, including both private and shared caches.";+ case "immutable":+ return "Indicates that the response body will not change over time. Caches can store immutable responses indefinitely.";+ case "stale-while-revalidate":+ return "Allows a cache to serve stale responses while asynchronously revalidating them with the origin server in the background.";+ case "stale-if-error":+ return "Allows a cache to serve stale responses if the origin server is unavailable or returns an error.";+ default:+ return "";+ }+}diff --git a/packages/header-analysis/src/parser/cf-cache-status.ts b/packages/header-analysis/src/parser/cf-cache-status.tsnew file mode 100644index 000000000..08bfa5e54--- /dev/null+++ b/packages/header-analysis/src/parser/cf-cache-status.ts@@ -0,0 +1,26 @@+interface CfCacheStatusInfo {+ description: string;+ value: string;+}++export function parseCfCacheStatus(header: string): CfCacheStatusInfo {+ const description = getCacheDescription(header);+ return { description, value: header };+}++function getCacheDescription(key: string): string {+ switch (key.toUpperCase()) {+ case "HIT":+ return "Your resource was found in Cloudflare’s cache. This means that it has been previously accessed from your original server and loaded into Cache. It has not expired.";+ case "MISS":+ return "Cloudflare looked for your resource in cache but did not find it. Cloudflare went back to your origin server to retrieve the resource. The next time this resource is accessed its status should be HIT.";+ case "BYPASS":+ return "Cloudflare has been instructed to not cache this asset. It has been served directly from the origin. This is usually because something like an existing NO-CACHE header is being respected.";+ case "EXPIRED":+ return "Cloudflare has previously retrieved this resource, but its cache has expired. Cloudflare will go back to the origin to retrieve this resource again. The next time this resource is accessed its status should be HIT.";+ case "DYNAMIC":+ return "This resource is not cached by default and there are no explicit settings configured to cache it. You will see this frequently when Cloudflare is handling a POST request. This request will always go to the origin.";+ default:+ return "";+ }+}diff --git a/packages/header-analysis/src/parser/cf-ray.ts b/packages/header-analysis/src/parser/cf-ray.tsnew file mode 100644index 000000000..beebf4542--- /dev/null+++ b/packages/header-analysis/src/parser/cf-ray.ts@@ -0,0 +1,22 @@+// List of all Cloudflare data center taken by https://www.feitsui.com/en/article/26+import { regions } from "../regions/cloudflare";+import type { ParserReturn, Region } from "../types";++export function parseCfRay(header: string): ParserReturn<Region> {+ const regex = /\b([A-Z]{3})\b/g;+ const arr = header.match(regex);++ if (!arr || !Array.isArray(arr) || arr.length === 0) {+ return { status: "failed", error: new Error("Couldn't parse the header.") };+ }++ const region = regions[arr[0]];+ if (region) return { status: "success", data: region };++ return {+ status: "failed",+ error: new Error(+ `It seems like the data center '${arr[0]}' (iata) is not listed.`,+ ),+ };+}diff --git a/packages/header-analysis/src/parser/fly-request-id.ts b/packages/header-analysis/src/parser/fly-request-id.tsnew file mode 100644index 000000000..26589835c--- /dev/null+++ b/packages/header-analysis/src/parser/fly-request-id.ts@@ -0,0 +1,21 @@+import { regions } from "../regions/fly";+import type { ParserReturn, Region } from "../types";++export function parseFlyRequestId(header: string): ParserReturn<Region> {+ const regex = /\b([a-z]{3})\b/g;+ const arr = header.match(regex);++ if (!arr || arr.length === 0) {+ return { status: "failed", error: new Error("Couldn't parse the header.") };+ }++ const region = regions[arr[0]];+ if (region) return { status: "success", data: region };++ return {+ status: "failed",+ error: new Error(+ `It seems like the data center '${arr[0]}' (iata) is not listed.`,+ ),+ };+}diff --git a/packages/header-analysis/src/parser/x-vercel-cache.ts b/packages/header-analysis/src/parser/x-vercel-cache.tsnew file mode 100644index 000000000..70e3ee6b8--- /dev/null+++ b/packages/header-analysis/src/parser/x-vercel-cache.ts@@ -0,0 +1,26 @@+interface VercelCacheInfo {+ description: string;+ value: string;+}++export function parseXVercelCache(header: string): VercelCacheInfo {+ const description = getCacheDescription(header);+ return { description, value: header };+}++function getCacheDescription(key: string): string {+ switch (key.toUpperCase()) {+ case "MISS":+ return "The response was not found in the edge cache and was fetched from the origin server.";+ case "HIT":+ return "The response was served from the edge cache.";+ case "STALE":+ return "The response was served from the edge cache. A background request to the origin server was made to update the content.";+ case "PRERENDER":+ return "The response was served from static storage.";+ case "REVLIDATED":+ return "The response was served from the origin server and the cache was refreshed due to an authorization from the user in the incoming request.";+ default:+ return "";+ }+}diff --git a/packages/header-analysis/src/parser/x-vercel-id.ts b/packages/header-analysis/src/parser/x-vercel-id.tsnew file mode 100644index 000000000..b282ad412--- /dev/null+++ b/packages/header-analysis/src/parser/x-vercel-id.ts@@ -0,0 +1,18 @@+import { regions } from "../regions/vercel";+import type { ParserReturn, Region } from "../types";++export function parseXVercelId(header: string): ParserReturn<Region[]> {+ const regex = /([a-z]{3}[0-9])+:+/g;++ const arr = header.match(regex);+ if (!arr || !arr.length) {+ return { status: "failed", error: new Error("Couldn't parse the header.") };+ }++ const data = arr.map((r) => {+ const regionId = r.replace(/:+/, "");+ return regions[regionId];+ });++ return { status: "success", data };+}diff --git a/packages/header-analysis/src/regions/cloudflare.ts b/packages/header-analysis/src/regions/cloudflare.tsnew file mode 100644index 000000000..5bf5ed7c7--- /dev/null+++ b/packages/header-analysis/src/regions/cloudflare.ts@@ -0,0 +1,289 @@+import type { Region } from "../types";++// REMINDER: nono-official data center list+// https://www.feitsui.com/en/article/26+export const regions: Record<string, Region> = {+ CGB: { code: "CGB", location: "Cuiabá, Brazil", flag: "🇧🇷" },+ COR: { code: "COR", location: "Córdoba, Argentina", flag: "🇦🇷" },+ BTS: { code: "BTS", location: "Bratislava, Slovakia", flag: "🇸🇰" },+ KHH: { code: "KHH", location: "Kaohsiung, Taiwan", flag: "🇹🇼" },+ GND: { code: "GND", location: "Grenada", flag: "🇬🇩" },+ NVT: { code: "NVT", location: "Navegantes, Brazil", flag: "🇧🇷" },+ ISU: { code: "ISU", location: "Sulaimaniyah, Iraq", flag: "🇮🇶" },+ PAP: { code: "PAP", location: "Port-au-Prince, Haiti", flag: "🇭🇹" },+ KLD: { code: "KLD", location: "Tver, Russia", flag: "🇷🇺" },+ REC: { code: "REC", location: "Recife, Brazil", flag: "🇧🇷" },+ FSD: { code: "FSD", location: "Sioux Falls, USA", flag: "🇺🇸" },+ ADB: { code: "ADB", location: "Izmir, Turkey", flag: "🇹🇷" },+ CHC: { code: "CHC", location: "Christchurch, New Zealand", flag: "🇳🇿" },+ UDI: { code: "UDI", location: "Uberlândia, Brazil", flag: "🇧🇷" },+ PPT: { code: "PPT", location: "Papeete, French Polynesia", flag: "🇵🇫" },+ KIN: { code: "KIN", location: "Kingston, Jamaica", flag: "🇯🇲" },+ STR: { code: "STR", location: "Stuttgart, Germany", flag: "🇩🇪" },+ COK: { code: "COK", location: "Kochi, India", flag: "🇮🇳" },+ KJA: { code: "KJA", location: "Krasnoyarsk, Russia", flag: "🇷🇺" },+ AUS: { code: "AUS", location: "Austin, USA", flag: "🇺🇸" },+ ORN: { code: "ORN", location: "Oran, Algeria", flag: "🇩🇿" },+ ACC: { code: "ACC", location: "Accra, Ghana", flag: "🇬🇭" },+ GDL: { code: "GDL", location: "Guadalajara, Mexico", flag: "🇲🇽" },+ SJK: { code: "SJK", location: "São José dos Campos, Brazil", flag: "🇧🇷" },+ AAE: { code: "AAE", location: "Annaba, Algeria", flag: "🇩🇿" },+ MDL: { code: "MDL", location: "Mandalay, Myanmar", flag: "🇲🇲" },+ DPS: { code: "DPS", location: "Denpasar, Indonesia", flag: "🇮🇩" },+ VIX: { code: "VIX", location: "Vitória, Brazil", flag: "🇧🇷" },+ FUK: { code: "FUK", location: "Fukuoka, Japan", flag: "🇯🇵" },+ CNN: { code: "CNN", location: "Chengdu, China", flag: "🇨🇳" },+ LYS: { code: "LYS", location: "Lyon, France", flag: "🇫🇷" },+ XAP: { code: "XAP", location: "Chapecó, Brazil", flag: "🇧🇷" },+ CAI: { code: "CAI", location: "Cairo, Egypt", flag: "🇪🇬" },+ RDU: { code: "RDU", location: "Raleigh-Durham, USA", flag: "🇺🇸" },+ CAW: { code: "CAW", location: "Campos dos Goytacazes, Brazil", flag: "🇧🇷" },+ OKC: { code: "OKC", location: "Oklahoma City, USA", flag: "🇺🇸" },+ SDQ: {+ code: "SDQ",+ location: "Santo Domingo, Dominican Republic",+ flag: "🇩🇴",+ },+ OUA: { code: "OUA", location: "Ouagadougou, Burkina Faso", flag: "🇧🇫" },+ YHZ: { code: "YHZ", location: "Halifax, Canada", flag: "🇨🇦" },+ ANC: { code: "ANC", location: "Anchorage, USA", flag: "🇺🇸" },+ LPB: { code: "LPB", location: "La Paz, Bolivia", flag: "🇧🇴" },+ SUV: { code: "SUV", location: "Suva, Fiji", flag: "🇫🇯" },+ BGR: { code: "BGR", location: "Bangor, USA", flag: "🇺🇸" },+ SJU: { code: "SJU", location: "San Juan, Puerto Rico", flag: "🇵🇷" },+ BBI: { code: "BBI", location: "Bhubaneswar, India", flag: "🇮🇳" },+ ALG: { code: "ALG", location: "Algiers, Algeria", flag: "🇩🇿" },+ LAD: { code: "LAD", location: "Luanda, Angola", flag: "🇦🇴" },+ EZE: { code: "EZE", location: "Buenos Aires, Argentina", flag: "🇦🇷" },+ NQN: { code: "NQN", location: "Neuquén, Argentina", flag: "🇦🇷" },+ EVN: { code: "EVN", location: "Yerevan, Armenia", flag: "🇦🇲" },+ ADL: { code: "ADL", location: "Adelaide, Australia", flag: "🇦🇺" },+ BNE: { code: "BNE", location: "Brisbane, Australia", flag: "🇦🇺" },+ CBR: { code: "CBR", location: "Canberra, Australia", flag: "🇦🇺" },+ HBA: { code: "HBA", location: "Hobart, Australia", flag: "🇦🇺" },+ MEL: { code: "MEL", location: "Melbourne, Australia", flag: "🇦🇺" },+ PER: { code: "PER", location: "Perth, Australia", flag: "🇦🇺" },+ SYD: { code: "SYD", location: "Sydney, Australia", flag: "🇦🇺" },+ VIE: { code: "VIE", location: "Vienna, Austria", flag: "🇦🇹" },+ LLK: { code: "LLK", location: "Luleå, Sweden", flag: "🇸🇪" },+ GYD: { code: "GYD", location: "Baku, Azerbaijan", flag: "🇦🇿" },+ BAH: { code: "BAH", location: "Manama, Bahrain", flag: "🇧🇭" },+ CGP: { code: "CGP", location: "Chittagong, Bangladesh", flag: "🇧🇩" },+ DAC: { code: "DAC", location: "Dhaka, Bangladesh", flag: "🇧🇩" },+ JSR: { code: "JSR", location: "Jessore, Bangladesh", flag: "🇧🇩" },+ MSQ: { code: "MSQ", location: "Minsk, Belarus", flag: "🇧🇾" },+ BRU: { code: "BRU", location: "Brussels, Belgium", flag: "🇧🇪" },+ PBH: { code: "PBH", location: "Paro, Bhutan", flag: "🇧🇹" },+ GBE: { code: "GBE", location: "Gaborone, Botswana", flag: "🇧🇼" },+ QWJ: { code: "QWJ", location: "Bouake, Ivory Coast", flag: "🇨🇮" },+ CNF: { code: "CNF", location: "Belo Horizonte, Brazil", flag: "🇧🇷" },+ BEL: { code: "BEL", location: "Belém, Brazil", flag: "🇧🇷" },+ BNU: { code: "BNU", location: "Blumenau, Brazil", flag: "🇧🇷" },+ BSB: { code: "BSB", location: "Brasília, Brazil", flag: "🇧🇷" },+ VCP: { code: "VCP", location: "Campinas, Brazil", flag: "🇧🇷" },+ CFC: { code: "CFC", location: "Cafelândia, Brazil", flag: "🇧🇷" },+ CWB: { code: "CWB", location: "Curitiba, Brazil", flag: "🇧🇷" },+ FLN: { code: "FLN", location: "Florianópolis, Brazil", flag: "🇧🇷" },+ FOR: { code: "FOR", location: "Fortaleza, Brazil", flag: "🇧🇷" },+ GYN: { code: "GYN", location: "Goiânia, Brazil", flag: "🇧🇷" },+ ITJ: { code: "ITJ", location: "Itajaí, Brazil", flag: "🇧🇷" },+ JOI: { code: "JOI", location: "Joinville, Brazil", flag: "🇧🇷" },+ JDO: { code: "JDO", location: "Juazeiro do Norte, Brazil", flag: "🇧🇷" },+ MAO: { code: "MAO", location: "Manaus, Brazil", flag: "🇧🇷" },+ POA: { code: "POA", location: "Porto Alegre, Brazil", flag: "🇧🇷" },+ RAO: { code: "RAO", location: "Ribeirão Preto, Brazil", flag: "🇧🇷" },+ GIG: { code: "GIG", location: "Rio de Janeiro, Brazil", flag: "🇧🇷" },+ SSA: { code: "SSA", location: "Salvador, Brazil", flag: "🇧🇷" },+ SOD: { code: "SOD", location: "Sorocaba, Brazil", flag: "🇧🇷" },+ SJP: { code: "SJP", location: "São José do Rio Preto, Brazil", flag: "🇧🇷" },+ GRU: { code: "GRU", location: "São Paulo, Brazil", flag: "🇧🇷" },+ BWN: { code: "BWN", location: "Bandar Seri Begawan, Brunei", flag: "🇧🇳" },+ SOF: { code: "SOF", location: "Sofia, Bulgaria", flag: "🇧🇬" },+ PNH: { code: "PNH", location: "Phnom Penh, Cambodia", flag: "🇰🇭" },+ YYC: { code: "YYC", location: "Calgary, Canada", flag: "🇨🇦" },+ YUL: { code: "YUL", location: "Montreal, Canada", flag: "🇨🇦" },+ YOW: { code: "YOW", location: "Ottawa, Canada", flag: "🇨🇦" },+ YXE: { code: "YXE", location: "Saskatoon, Canada", flag: "🇨🇦" },+ YYZ: { code: "YYZ", location: "Toronto, Canada", flag: "🇨🇦" },+ YVR: { code: "YVR", location: "Vancouver, Canada", flag: "🇨🇦" },+ YWG: { code: "YWG", location: "Winnipeg, Canada", flag: "🇨🇦" },+ ARI: { code: "ARI", location: "Arica, Chile", flag: "🇨🇱" },+ SCL: { code: "SCL", location: "Santiago, Chile", flag: "🇨🇱" },+ HKG: { code: "HKG", location: "Hong Kong, Hong Kong", flag: "🇭🇰" },+ MFM: { code: "MFM", location: "Macau, Macau", flag: "🇲🇴" },+ TPE: { code: "TPE", location: "Taipei, Taiwan", flag: "🇹🇼" },+ BOG: { code: "BOG", location: "Bogotá, Colombia", flag: "🇨🇴" },+ MDE: { code: "MDE", location: "Medellín, Colombia", flag: "🇨🇴" },+ SJO: { code: "SJO", location: "San José, Costa Rica", flag: "🇨🇷" },+ ZAG: { code: "ZAG", location: "Zagreb, Croatia", flag: "🇭🇷" },+ LCA: { code: "LCA", location: "Larnaca, Cyprus", flag: "🇨🇾" },+ PRG: { code: "PRG", location: "Prague, Czech Republic", flag: "🇨🇿" },+ CPH: { code: "CPH", location: "Copenhagen, Denmark", flag: "🇩🇰" },+ JIB: { code: "JIB", location: "Djibouti", flag: "🇩🇯" },+ GYE: { code: "GYE", location: "Guayaquil, Ecuador", flag: "🇪🇨" },+ UIO: { code: "UIO", location: "Quito, Ecuador", flag: "🇪🇨" },+ TLL: { code: "TLL", location: "Tallinn, Estonia", flag: "🇪🇪" },+ HEL: { code: "HEL", location: "Helsinki, Finland", flag: "🇫🇮" },+ MRS: { code: "MRS", location: "Marseille, France", flag: "🇫🇷" },+ CDG: { code: "CDG", location: "Paris, France", flag: "🇫🇷" },+ RUN: { code: "RUN", location: "Saint-Denis, Réunion", flag: "🇷🇪" },+ TBS: { code: "TBS", location: "Tbilisi, Georgia", flag: "🇬🇪" },+ TXL: { code: "TXL", location: "Berlin, Germany", flag: "🇩🇪" },+ DUS: { code: "DUS", location: "Düsseldorf, Germany", flag: "🇩🇪" },+ FRA: { code: "FRA", location: "Frankfurt, Germany", flag: "🇩🇪" },+ HAM: { code: "HAM", location: "Hamburg, Germany", flag: "🇩🇪" },+ MUC: { code: "MUC", location: "Munich, Germany", flag: "🇩🇪" },+ ATH: { code: "ATH", location: "Athens, Greece", flag: "🇬🇷" },+ SKG: { code: "SKG", location: "Thessaloniki, Greece", flag: "🇬🇷" },+ GUM: { code: "GUM", location: "Hagåtña, Guam", flag: "🇬🇺" },+ GUA: { code: "GUA", location: "Guatemala City, Guatemala", flag: "🇬🇹" },+ GEO: { code: "GEO", location: "Georgetown, Guyana", flag: "🇬🇾" },+ TGU: { code: "TGU", location: "Tegucigalpa, Honduras", flag: "🇭🇳" },+ BUD: { code: "BUD", location: "Budapest, Hungary", flag: "🇭🇺" },+ KEF: { code: "KEF", location: "Reykjavík, Iceland", flag: "🇮🇸" },+ AMD: { code: "AMD", location: "Ahmedabad, India", flag: "🇮🇳" },+ BLR: { code: "BLR", location: "Bengaluru, India", flag: "🇮🇳" },+ IXC: { code: "IXC", location: "Chandigarh, India", flag: "🇮🇳" },+ MAA: { code: "MAA", location: "Chennai, India", flag: "🇮🇳" },+ HYD: { code: "HYD", location: "Hyderabad, India", flag: "🇮🇳" },+ KNU: { code: "KNU", location: "Kanpur, India", flag: "🇮🇳" },+ CCU: { code: "CCU", location: "Kolkata, India", flag: "🇮🇳" },+ BOM: { code: "BOM", location: "Mumbai, India", flag: "🇮🇳" },+ NAG: { code: "NAG", location: "Nagpur, India", flag: "🇮🇳" },+ DEL: { code: "DEL", location: "New Delhi, India", flag: "🇮🇳" },+ PAT: { code: "PAT", location: "Patna, India", flag: "🇮🇳" },+ CGK: { code: "CGK", location: "Jakarta, Indonesia", flag: "🇮🇩" },+ JOG: { code: "JOG", location: "Yogyakarta, Indonesia", flag: "🇮🇩" },+ BGW: { code: "BGW", location: "Baghdad, Iraq", flag: "🇮🇶" },+ BSR: { code: "BSR", location: "Basra, Iraq", flag: "🇮🇶" },+ EBL: { code: "EBL", location: "Erbil, Iraq", flag: "🇮🇶" },+ NJF: { code: "NJF", location: "Najaf, Iraq", flag: "🇮🇶" },+ XNH: { code: "XNH", location: "Nouadhibou, Mauritania", flag: "🇲🇷" },+ ORK: { code: "ORK", location: "Cork, Ireland", flag: "🇮🇪" },+ DUB: { code: "DUB", location: "Dublin, Ireland", flag: "🇮🇪" },+ HFA: { code: "HFA", location: "Haifa, Israel", flag: "🇮🇱" },+ TLV: { code: "TLV", location: "Tel-Aviv, Israel", flag: "🇮🇱" },+ MXP: { code: "MXP", location: "Milan, Italy", flag: "🇮🇹" },+ PMO: { code: "PMO", location: "Palermo, Italy", flag: "🇮🇹" },+ FCO: { code: "FCO", location: "Rome, Italy", flag: "🇮🇹" },+ OKA: { code: "OKA", location: "Okinawa, Japan", flag: "🇯🇵" },+ KIX: { code: "KIX", location: "Osaka, Japan", flag: "🇯🇵" },+ NRT: { code: "NRT", location: "Tokyo, Japan", flag: "🇯🇵" },+ AMM: { code: "AMM", location: "Amman, Jordan", flag: "🇯🇴" },+ ALA: { code: "ALA", location: "Almaty, Kazakhstan", flag: "🇰🇿" },+ MBA: { code: "MBA", location: "Mombasa, Kenya", flag: "🇰🇪" },+ NBO: { code: "NBO", location: "Nairobi, Kenya", flag: "🇰🇪" },+ KWI: { code: "KWI", location: "Kuwait City, Kuwait", flag: "🇰🇼" },+ VTE: { code: "VTE", location: "Vientiane, Laos", flag: "🇱🇦" },+ RIX: { code: "RIX", location: "Riga, Latvia", flag: "🇱🇻" },+ VNO: { code: "VNO", location: "Vilnius, Lithuania", flag: "🇱🇹" },+ LUX: { code: "LUX", location: "Luxembourg", flag: "🇱🇺" },+ TNR: { code: "TNR", location: "Antananarivo, Madagascar", flag: "🇲🇬" },+ JHB: { code: "JHB", location: "Johor Bahru, Malaysia", flag: "🇲🇾" },+ KUL: { code: "KUL", location: "Kuala Lumpur, Malaysia", flag: "🇲🇾" },+ MLE: { code: "MLE", location: "Malé, Maldives", flag: "🇲🇻" },+ MRU: { code: "MRU", location: "Port Louis, Mauritius", flag: "🇲🇺" },+ MEX: { code: "MEX", location: "Mexico City, Mexico", flag: "🇲🇽" },+ QRO: { code: "QRO", location: "Querétaro, Mexico", flag: "🇲🇽" },+ KIV: { code: "KIV", location: "Chișinău, Moldova", flag: "🇲🇩" },+ ULN: { code: "ULN", location: "Ulaanbaatar, Mongolia", flag: "🇲🇳" },+ CMN: { code: "CMN", location: "Casablanca, Morocco", flag: "🇲🇦" },+ MPM: { code: "MPM", location: "Maputo, Mozambique", flag: "🇲🇿" },+ RGN: { code: "RGN", location: "Yangon, Myanmar", flag: "🇲🇲" },+ KTM: { code: "KTM", location: "Kathmandu, Nepal", flag: "🇳🇵" },+ AMS: { code: "AMS", location: "Amsterdam, Netherlands", flag: "🇳🇱" },+ NOU: { code: "NOU", location: "Nouméa, New Caledonia", flag: "🇳🇨" },+ AKL: { code: "AKL", location: "Auckland, New Zealand", flag: "🇳🇿" },+ LOS: { code: "LOS", location: "Lagos, Nigeria", flag: "🇳🇬" },+ OSL: { code: "OSL", location: "Oslo, Norway", flag: "🇳🇴" },+ MCT: { code: "MCT", location: "Muscat, Oman", flag: "🇴🇲" },+ ISB: { code: "ISB", location: "Islamabad, Pakistan", flag: "🇵🇰" },+ KHI: { code: "KHI", location: "Karachi, Pakistan", flag: "🇵🇰" },+ LHE: { code: "LHE", location: "Lahore, Pakistan", flag: "🇵🇰" },+ ZDM: { code: "ZDM", location: "Zahedan, Iran", flag: "🇮🇷" },+ PTY: { code: "PTY", location: "Panama City, Panama", flag: "🇵🇦" },+ ASU: { code: "ASU", location: "Asunción, Paraguay", flag: "🇵🇾" },+ LIM: { code: "LIM", location: "Lima, Peru", flag: "🇵🇪" },+ CGY: { code: "CGY", location: "Cagayan de Oro, Philippines", flag: "🇵🇭" },+ CEB: { code: "CEB", location: "Cebu, Philippines", flag: "🇵🇭" },+ MNL: { code: "MNL", location: "Manila, Philippines", flag: "🇵🇭" },+ WAW: { code: "WAW", location: "Warsaw, Poland", flag: "🇵🇱" },+ LIS: { code: "LIS", location: "Lisbon, Portugal", flag: "🇵🇹" },+ DOH: { code: "DOH", location: "Doha, Qatar", flag: "🇶🇦" },+ OTP: { code: "OTP", location: "Bucharest, Romania", flag: "🇷🇴" },+ LED: { code: "LED", location: "Saint Petersburg, Russia", flag: "🇷🇺" },+ DME: { code: "DME", location: "Moscow, Russia", flag: "🇷🇺" },+ KZN: { code: "KZN", location: "Kazan, Russia", flag: "🇷🇺" },+ KRR: { code: "KRR", location: "Krasnodar, Russia", flag: "🇷🇺" },+ SVX: { code: "SVX", location: "Yekaterinburg, Russia", flag: "🇷🇺" },+ KGL: { code: "KGL", location: "Kigali, Rwanda", flag: "🇷🇼" },+ JED: { code: "JED", location: "Jeddah, Saudi Arabia", flag: "🇸🇦" },+ RUH: { code: "RUH", location: "Riyadh, Saudi Arabia", flag: "🇸🇦" },+ DKR: { code: "DKR", location: "Dakar, Senegal", flag: "🇸🇳" },+ BEG: { code: "BEG", location: "Belgrade, Serbia", flag: "🇷🇸" },+ SGP: { code: "SGP", location: "Singapore", flag: "🇸🇬" },+ LJU: { code: "LJU", location: "Ljubljana, Slovenia", flag: "🇸🇮" },+ CPT: { code: "CPT", location: "Cape Town, South Africa", flag: "🇿🇦" },+ DUR: { code: "DUR", location: "Durban, South Africa", flag: "🇿🇦" },+ JNB: { code: "JNB", location: "Johannesburg, South Africa", flag: "🇿🇦" },+ ICN: { code: "ICN", location: "Seoul, South Korea", flag: "🇰🇷" },+ MAD: { code: "MAD", location: "Madrid, Spain", flag: "🇪🇸" },+ BCN: { code: "BCN", location: "Barcelona, Spain", flag: "🇪🇸" },+ GOT: { code: "GOT", location: "Gothenburg, Sweden", flag: "🇸🇪" },+ ARN: { code: "ARN", location: "Stockholm, Sweden", flag: "🇸🇪" },+ BSL: { code: "BSL", location: "Basel, Switzerland", flag: "🇨🇭" },+ GVA: { code: "GVA", location: "Geneva, Switzerland", flag: "🇨🇭" },+ ZRH: { code: "ZRH", location: "Zürich, Switzerland", flag: "🇨🇭" },+ DAR: { code: "DAR", location: "Dar es Salaam, Tanzania", flag: "🇹🇿" },+ BKK: { code: "BKK", location: "Bangkok, Thailand", flag: "🇹🇭" },+ IST: { code: "IST", location: "Istanbul, Turkey", flag: "🇹🇷" },+ TUN: { code: "TUN", location: "Tunis, Tunisia", flag: "🇹🇳" },+ KBP: { code: "KBP", location: "Kyiv, Ukraine", flag: "🇺🇦" },+ DXB: { code: "DXB", location: "Dubai, United Arab Emirates", flag: "🇦🇪" },+ EDI: { code: "EDI", location: "Edinburgh, United Kingdom", flag: "🇬🇧" },+ LHR: { code: "LHR", location: "London, United Kingdom", flag: "🇬🇧" },+ MAN: { code: "MAN", location: "Manchester, United Kingdom", flag: "🇬🇧" },+ IAD: { code: "IAD", location: "Washington, USA", flag: "🇺🇸" },+ ATL: { code: "ATL", location: "Atlanta, USA", flag: "🇺🇸" },+ BOS: { code: "BOS", location: "Boston, USA", flag: "🇺🇸" },+ BUF: { code: "BUF", location: "Buffalo, USA", flag: "🇺🇸" },+ CLT: { code: "CLT", location: "Charlotte, USA", flag: "🇺🇸" },+ ORD: { code: "ORD", location: "Chicago, USA", flag: "🇺🇸" },+ CMH: { code: "CMH", location: "Columbus, USA", flag: "🇺🇸" },+ DFW: { code: "DFW", location: "Dallas, USA", flag: "🇺🇸" },+ DEN: { code: "DEN", location: "Denver, USA", flag: "🇺🇸" },+ DTW: { code: "DTW", location: "Detroit, USA", flag: "🇺🇸" },+ HNL: { code: "HNL", location: "Honolulu, USA", flag: "🇺🇸" },+ IAH: { code: "IAH", location: "Houston, USA", flag: "🇺🇸" },+ JAX: { code: "JAX", location: "Jacksonville, USA", flag: "🇺🇸" },+ MCI: { code: "MCI", location: "Kansas City, USA", flag: "🇺🇸" },+ LAS: { code: "LAS", location: "Las Vegas, USA", flag: "🇺🇸" },+ LAX: { code: "LAX", location: "Los Angeles, USA", flag: "🇺🇸" },+ MFE: { code: "MFE", location: "McAllen, USA", flag: "🇺🇸" },+ MEM: { code: "MEM", location: "Memphis, USA", flag: "🇺🇸" },+ MIA: { code: "MIA", location: "Miami, USA", flag: "🇺🇸" },+ MSP: { code: "MSP", location: "Minneapolis, USA", flag: "🇺🇸" },+ MGM: { code: "MGM", location: "Montgomery, USA", flag: "🇺🇸" },+ BNA: { code: "BNA", location: "Nashville, USA", flag: "🇺🇸" },+ EWR: { code: "EWR", location: "Newark, USA", flag: "🇺🇸" },+ OMA: { code: "OMA", location: "Omaha, USA", flag: "🇺🇸" },+ PHL: { code: "PHL", location: "Philadelphia, USA", flag: "🇺🇸" },+ PHX: { code: "PHX", location: "Phoenix, USA", flag: "🇺🇸" },+ PIT: { code: "PIT", location: "Pittsburgh, USA", flag: "🇺🇸" },+ PDX: { code: "PDX", location: "Portland, USA", flag: "🇺🇸" },+ RIC: { code: "RIC", location: "Richmond, USA", flag: "🇺🇸" },+ SMF: { code: "SMF", location: "Sacramento, USA", flag: "🇺🇸" },+ SLC: { code: "SLC", location: "Salt Lake City, USA", flag: "🇺🇸" },+ SAN: { code: "SAN", location: "San Diego, USA", flag: "🇺🇸" },+ SFO: { code: "SFO", location: "San Francisco, USA", flag: "🇺🇸" },+ SJC: { code: "SJC", location: "San Jose, USA", flag: "🇺🇸" },+ SEA: { code: "SEA", location: "Seattle, USA", flag: "🇺🇸" },+ IND: { code: "IND", location: "Indianapolis, USA", flag: "🇺🇸" },+ STL: { code: "STL", location: "St. Louis, USA", flag: "🇺🇸" },+ TLH: { code: "TLH", location: "Tallahassee, USA", flag: "🇺🇸" },+ TPA: { code: "TPA", location: "Tampa, USA", flag: "🇺🇸" },+ TAS: { code: "TAS", location: "Tashkent, Uzbekistan", flag: "🇺🇿" },+ HAN: { code: "HAN", location: "Hanoi, Vietnam", flag: "🇻🇳" },+ SGN: { code: "SGN", location: "Ho Chi Minh City, Vietnam", flag: "🇻🇳" },+ HRE: { code: "HRE", location: "Harare, Zimbabwe", flag: "🇿🇼" },+};diff --git a/packages/header-analysis/src/regions/fly.ts b/packages/header-analysis/src/regions/fly.tsnew file mode 100644index 000000000..5adc4fc69--- /dev/null+++ b/packages/header-analysis/src/regions/fly.ts@@ -0,0 +1,40 @@+import type { Region } from "../types";++// https://fly.io/docs/reference/regions/+export const regions: Record<string, Region> = {+ ams: { code: "ams", location: "Amsterdam, Netherlands", flag: "🇳🇱" },+ arn: { code: "arn", location: "Stockholm, Sweden", flag: "🇸🇪" },+ atl: { code: "atl", location: "Atlanta, Georgia (US)", flag: "🇺🇸" },+ bog: { code: "bog", location: "Bogotá, Colombia", flag: "🇨🇴" },+ bom: { code: "bom", location: "Mumbai, India", flag: "🇮🇳" },+ bos: { code: "bos", location: "Boston, Massachusetts (US)", flag: "🇺🇸" },+ cdg: { code: "cdg", location: "Paris, France", flag: "🇫🇷" },+ den: { code: "den", location: "Denver, Colorado (US)", flag: "🇺🇸" },+ dfw: { code: "dfw", location: "Dallas, Texas (US)", flag: "🇺🇸" },+ ewr: { code: "ewr", location: "Secaucus, NJ (US)", flag: "🇺🇸" },+ eze: { code: "eze", location: "Ezeiza, Argentina", flag: "🇦🇷" },+ fra: { code: "fra", location: "Frankfurt, Germany", flag: "🇩🇪" },+ gdl: { code: "gdl", location: "Guadalajara, Mexico", flag: "🇲🇽" },+ gig: { code: "gig", location: "Rio de Janeiro, Brazil", flag: "🇧🇷" },+ gru: { code: "gru", location: "Sao Paulo, Brazil", flag: "🇧🇷" },+ hkg: { code: "hkg", location: "Hong Kong, Hong Kong", flag: "🇭🇰" },+ iad: { code: "iad", location: "Ashburn, Virginia (US)", flag: "🇺🇸" },+ jnb: { code: "jnb", location: "Johannesburg, South Africa", flag: "🇿🇦" },+ lax: { code: "lax", location: "Los Angeles, California (US)", flag: "🇺🇸" },+ lhr: { code: "lhr", location: "London, United Kingdom", flag: "🇬🇧" },+ mad: { code: "mad", location: "Madrid, Spain", flag: "🇪🇸" },+ mia: { code: "mia", location: "Miami, Florida (US)", flag: "🇺🇸" },+ nrt: { code: "nrt", location: "Tokyo, Japan", flag: "🇯🇵" },+ ord: { code: "ord", location: "Chicago, Illinois (US)", flag: "🇺🇸" },+ otp: { code: "otp", location: "Bucharest, Romania", flag: "🇷🇴" },+ phx: { code: "phx", location: "Phoenix, Arizona (US)", flag: "🇺🇸" },+ qro: { code: "qro", location: "Querétaro, Mexico", flag: "🇲🇽" },+ scl: { code: "scl", location: "Santiago, Chile", flag: "🇨🇱" },+ sea: { code: "sea", location: "Seattle, Washington (US)", flag: "🇺🇸" },+ sin: { code: "sin", location: "Singapore, Singapore", flag: "🇸🇬" },+ sjc: { code: "sjc", location: "San Jose, California (US)", flag: "🇺🇸" },+ syd: { code: "syd", location: "Sydney, Australia", flag: "🇦🇺" },+ waw: { code: "waw", location: "Warsaw, Poland", flag: "🇵🇱" },+ yul: { code: "yul", location: "Montreal, Canada", flag: "🇨🇦" },+ yyz: { code: "yyz", location: "Toronto, Canada", flag: "🇨🇦" },+};diff --git a/packages/header-analysis/src/regions/vercel.ts b/packages/header-analysis/src/regions/vercel.tsnew file mode 100644index 000000000..fd4fe859f--- /dev/null+++ b/packages/header-analysis/src/regions/vercel.ts@@ -0,0 +1,23 @@+import type { Region } from "../types";++// https://vercel.com/docs/edge-network/regions+export const regions: Record<string, Region> = {+ arn1: { code: "arn1", location: "Stockholm, Sweden", flag: "🇸🇪" },+ bom1: { code: "bom1", location: "Mumbai, India", flag: "🇮🇳" },+ cdg1: { code: "cdg1", location: "Paris, France", flag: "🇫🇷" },+ cle1: { code: "cle1", location: "Cleveland, USA", flag: "🇺🇸" },+ cpt1: { code: "cpt1", location: "Cape Town, South Africa", flag: "🇿🇦" },+ dub1: { code: "dub1", location: "Dublin, Ireland", flag: "🇮🇪" },+ fra1: { code: "fra1", location: "Frankfurt, Germany", flag: "🇩🇪" },+ gru1: { code: "gru1", location: "São Paulo, Brazil", flag: "🇧🇷" },+ hkg1: { code: "hkg1", location: "Hong Kong", flag: "🇭🇰" },+ hnd1: { code: "hnd1", location: "Tokyo, Japan", flag: "🇯🇵" },+ iad1: { code: "iad1", location: "Washington, D.C., USA", flag: "🇺🇸" },+ icn1: { code: "icn1", location: "Seoul, South Korea", flag: "🇰🇷" },+ kix1: { code: "kix1", location: "Osaka, Japan", flag: "🇯🇵" },+ lhr1: { code: "lhr1", location: "London, United Kingdom", flag: "🇬🇧" },+ pdx1: { code: "pdx1", location: "Portland, USA", flag: "🇺🇸" },+ sfo1: { code: "sfo1", location: "San Francisco, USA", flag: "🇺🇸" },+ sin1: { code: "sin1", location: "Singapore", flag: "🇸🇬" },+ syd1: { code: "syd1", location: "Sydney, Australia", flag: "🇦🇺" },+};diff --git a/packages/header-analysis/src/types/index.ts b/packages/header-analysis/src/types/index.tsnew file mode 100644index 000000000..e1e379769--- /dev/null+++ b/packages/header-analysis/src/types/index.ts@@ -0,0 +1,9 @@+export type Region = {+ code: string;+ location: string;+ flag: string;+};++export type ParserReturn<T> =+ | { status: "success"; data: T }+ | { status: "failed"; error: Error };diff --git a/packages/header-analysis/tsconfig.json b/packages/header-analysis/tsconfig.jsonnew file mode 100644index 000000000..48baa5cfe--- /dev/null+++ b/packages/header-analysis/tsconfig.json@@ -0,0 +1,7 @@+{+ "extends": "@openstatus/tsconfig/base.json",+ "include": ["src", "*.ts"],+ "compilerOptions": {+ "resolveJsonModule": true+ }+}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 3680dc3c2..9d07abebb 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -260,6 +260,9 @@ importers:'@openstatus/emails':specifier: workspace:*version: link:../../packages/emails+ '@openstatus/header-analysis':+ specifier: workspace:*+ version: link:../../packages/header-analysis'@openstatus/next-monitoring':specifier: 0.0.2version: 0.0.2([email protected](@babel/[email protected])(@opentelemetry/[email protected])([email protected]([email protected]))([email protected]))([email protected])@@ -735,6 +738,15 @@ importers:specifier: 5.4.5version: 5.4.5+ packages/header-analysis:+ devDependencies:+ '@openstatus/tsconfig':+ specifier: workspace:*+ version: link:../tsconfig+ typescript:+ specifier: 5.4.5+ version: 5.4.5+packages/notifications/discord:dependencies:'@openstatus/db':