The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add parseUrlSchema, document /metatags endpoint
Steven Tey33c50dabf9ff
diff --git a/apps/docs/api-reference/endpoint/retrieve-metatags.mdx b/apps/docs/api-reference/endpoint/retrieve-metatags.mdxnew file mode 100644index 0000000000..0bc0651241--- /dev/null+++ b/apps/docs/api-reference/endpoint/retrieve-metatags.mdx@@ -0,0 +1,3 @@+---+openapi: get /metatags+---diff --git a/apps/web/lib/openapi/index.ts b/apps/web/lib/openapi/index.tsindex f814e18f84..372dd88017 100644--- a/apps/web/lib/openapi/index.ts+++ b/apps/web/lib/openapi/index.ts@@ -6,6 +6,7 @@ import { API_DOMAIN } from "@dub/utils";import { ZodOpenApiObject } from "zod-openapi";import { analyticsPaths } from "./analytics";import { linksPaths } from "./links";+import { metatagsPath } from "./metatags";import { qrCodePaths } from "./qr";import { tagsPaths } from "./tags";import { workspacesPaths } from "./workspaces";@@ -39,6 +40,7 @@ export const openApiObject: ZodOpenApiObject = {...analyticsPaths,...workspacesPaths,...tagsPaths,+ ...metatagsPath,},components: {schemas: {diff --git a/apps/web/lib/openapi/metatags/index.ts b/apps/web/lib/openapi/metatags/index.tsnew file mode 100644index 0000000000..c36f9df693--- /dev/null+++ b/apps/web/lib/openapi/metatags/index.ts@@ -0,0 +1,39 @@+import { ZodOpenApiPathsObject } from "zod-openapi";+import { openApiErrorResponses } from "@/lib/openapi/responses";+import { getUrlQuerySchema } from "@/lib/zod/schemas";+import { ZodOpenApiOperationObject } from "zod-openapi";++const getMetatags: ZodOpenApiOperationObject = {+ operationId: "getMetatags",+ "x-speakeasy-name-override": "get",+ summary: "Retrieve the metatags for a URL",+ description: "Retrieve the metatags for a URL",+ requestParams: {+ query: getUrlQuerySchema,+ },+ responses: {+ "200": {+ description: "The retrieved metatags",+ content: {+ "application/json": {+ schema: {+ type: "object",+ properties: {+ title: { type: "string" },+ description: { type: "string" },+ image: { type: "string" },+ },+ },+ },+ },+ },+ },+ tags: ["Metatags"],+ security: [{ token: [] }],+};++export const metatagsPath: ZodOpenApiPathsObject = {+ "/metatags": {+ get: getMetatags,+ },+};diff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.tsindex a38639822c..2b85e11edc 100644--- a/apps/web/lib/zod/schemas/links.ts+++ b/apps/web/lib/zod/schemas/links.ts@@ -8,12 +8,14 @@ import {import { booleanQuerySchema } from "./misc";import { TagSchema } from "./tags";+export const parseUrlSchema = z+ .string()+ .describe("The destination URL of the short link.")+ .transform((v) => getUrlFromString(v))+ .refine((v) => isValidUrl(v), { message: "Invalid URL" });+export const getUrlQuerySchema = z.object({- url: z- .string()- .describe("The destination URL of the short link.")- .transform((v) => getUrlFromString(v))- .refine((v) => isValidUrl(v), { message: "Invalid URL" }),+ url: parseUrlSchema,});export const getDomainQuerySchema = z.object({@@ -127,7 +129,7 @@ export const createLinkBodySchema = z.object({.describe("The prefix of the short link slug for randomly-generated keys (e.g. if prefix is `/c/`, generated keys will be in the `/c/:key` format). Will be ignored if `key` is provided.",),- url: z.string().describe("The destination URL of the short link."),+ url: parseUrlSchema.describe("The destination URL of the short link."),archived: z.boolean().optional()@@ -137,8 +139,7 @@ export const createLinkBodySchema = z.object({.string().nullish().describe("The date and time when the short link will expire at."),- expiredUrl: z- .string()+ expiredUrl: parseUrlSchema.nullish().describe("The URL to redirect to when the short link has expired."),password: z@@ -175,20 +176,18 @@ export const createLinkBodySchema = z.object({.optional().default(false).describe("Whether the short link uses link cloaking."),- ios: z- .string()+ ios: parseUrlSchema.nullish().describe("The iOS destination URL for the short link for iOS device targeting.",),- android: z- .string()+ android: parseUrlSchema.nullish().describe("The Android destination URL for the short link for Android device targeting.",),geo: z- .record(z.enum(COUNTRY_CODES), z.string().url())+ .record(z.enum(COUNTRY_CODES), parseUrlSchema).nullish().describe("Geo targeting information for the short link in JSON format `{[COUNTRY]: https://example.com }`.",