/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { LinkTagSchemaOutput, LinkTagSchemaOutput$inboundSchema, } from "./linktagschemaoutput.js"; export type TestVariants = { url: string; percentage: number; }; export type LinkSchema = { /** * The unique ID of the short link. */ id: string; /** * The domain of the short link. If not provided, the primary domain for the workspace will be used (or `dub.sh` if the workspace has no domains). */ domain: string; /** * The short link slug. If not provided, a random 7-character slug will be generated. */ key: string; /** * The destination URL of the short link. */ url: string; /** * Whether to track conversions for the short link. */ trackConversion: boolean; /** * The ID of the link in your database. If set, it can be used to identify the link in future API requests (must be prefixed with 'ext_' when passed as a query parameter). This key is unique across your workspace. */ externalId: string | null; /** * The ID of the tenant that created the link inside your system. If set, it can be used to fetch all links for a tenant. */ tenantId: string | null; /** * The ID of the program the short link is associated with. */ programId: string | null; /** * The ID of the partner the short link is associated with. */ partnerId: string | null; /** * Whether the short link is archived. */ archived: boolean; /** * The date and time when the short link will expire in ISO-8601 format. */ expiresAt: string | null; /** * The URL to redirect to when the short link has expired. */ expiredUrl: string | null; /** * The date and time when the short link was disabled. When a short link is disabled, it will redirect to its domain's not found URL, and its stats will be excluded from your overall stats. */ disabledAt: string | null; /** * The password required to access the destination URL of the short link. */ password: string | null; /** * Whether the short link uses Custom Link Previews feature. */ proxy: boolean; /** * The title of the short link. Will be used for Custom Link Previews if `proxy` is true. */ title: string | null; /** * The description of the short link. Will be used for Custom Link Previews if `proxy` is true. */ description: string | null; /** * The image of the short link. Will be used for Custom Link Previews if `proxy` is true. */ image: string | null; /** * The custom link preview video (og:video). Will be used for Custom Link Previews if `proxy` is true. Learn more: https://d.to/og */ video: string | null; /** * Whether the short link uses link cloaking. */ rewrite: boolean; /** * Whether to allow search engines to index the short link. */ doIndex: boolean; /** * The iOS destination URL for the short link for iOS device targeting. */ ios: string | null; /** * The Android destination URL for the short link for Android device targeting. */ android: string | null; /** * Geo targeting information for the short link in JSON format `{[COUNTRY]: https://example.com }`. See https://d.to/geo for more information. */ geo: { [k: string]: string } | null; /** * Whether the short link's stats are publicly accessible. */ publicStats: boolean; /** * The tags assigned to the short link. */ tags: Array | null; /** * The unique ID of the folder assigned to the short link. */ folderId: string | null; /** * The IDs of the webhooks that the short link is associated with. */ webhookIds: Array; /** * The comments for the short link. */ comments: string | null; /** * The full URL of the short link, including the https protocol (e.g. `https://dub.sh/try`). */ shortLink: string; /** * The full URL of the QR code for the short link (e.g. `https://api.dub.co/qr?url=https://dub.sh/try`). */ qrCode: string; /** * The UTM source of the short link. */ utmSource: string | null; /** * The UTM medium of the short link. */ utmMedium: string | null; /** * The UTM campaign of the short link. */ utmCampaign: string | null; /** * The UTM term of the short link. */ utmTerm: string | null; /** * The UTM content of the short link. */ utmContent: string | null; /** * An array of A/B test URLs and the percentage of traffic to send to each URL. */ testVariants?: Array | null | undefined; /** * The date and time when the tests started. */ testStartedAt?: string | null | undefined; /** * The date and time when the tests were or will be completed. */ testCompletedAt?: string | null | undefined; /** * The user ID of the creator of the short link. */ userId: string | null; /** * The workspace ID of the short link. */ workspaceId: string; /** * The number of clicks on the short link. */ clicks: number; /** * The number of leads the short link has generated. */ leads: number; /** * The number of leads that converted to paying customers. */ conversions: number; /** * The total number of sales (includes recurring sales) generated by the short link. */ sales: number; /** * The total dollar value of sales (in cents) generated by the short link. */ saleAmount: number; /** * The date and time when the short link was last clicked. */ lastClicked: string | null; /** * The date and time when the short link was created. */ createdAt: string; /** * The date and time when the short link was last updated. */ updatedAt: string; /** * Deprecated: Use `tags` instead. The unique ID of the tag assigned to the short link. * * @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible. */ tagId: string | null; /** * Deprecated: Use `workspaceId` instead. The project ID of the short link. * * @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible. */ projectId: string; }; /** @internal */ export const TestVariants$inboundSchema: z.ZodType< TestVariants, z.ZodTypeDef, unknown > = z.object({ url: z.string(), percentage: z.number(), }); export function testVariantsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => TestVariants$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'TestVariants' from JSON`, ); } /** @internal */ export const LinkSchema$inboundSchema: z.ZodType< LinkSchema, z.ZodTypeDef, unknown > = z.object({ id: z.string(), domain: z.string(), key: z.string(), url: z.string(), trackConversion: z.boolean().default(false), externalId: z.nullable(z.string()), tenantId: z.nullable(z.string()), programId: z.nullable(z.string()), partnerId: z.nullable(z.string()), archived: z.boolean().default(false), expiresAt: z.nullable(z.string()), expiredUrl: z.nullable(z.string()), disabledAt: z.nullable(z.string()), password: z.nullable(z.string()), proxy: z.boolean().default(false), title: z.nullable(z.string()), description: z.nullable(z.string()), image: z.nullable(z.string()), video: z.nullable(z.string()), rewrite: z.boolean().default(false), doIndex: z.boolean().default(false), ios: z.nullable(z.string()), android: z.nullable(z.string()), geo: z.nullable(z.record(z.string())), publicStats: z.boolean().default(false), tags: z.nullable(z.array(LinkTagSchemaOutput$inboundSchema)), folderId: z.nullable(z.string()), webhookIds: z.array(z.string()), comments: z.nullable(z.string()), shortLink: z.string(), qrCode: z.string(), utm_source: z.nullable(z.string()), utm_medium: z.nullable(z.string()), utm_campaign: z.nullable(z.string()), utm_term: z.nullable(z.string()), utm_content: z.nullable(z.string()), testVariants: z.nullable(z.array(z.lazy(() => TestVariants$inboundSchema))) .optional(), testStartedAt: z.nullable(z.string()).optional(), testCompletedAt: z.nullable(z.string()).optional(), userId: z.nullable(z.string()), workspaceId: z.string(), clicks: z.number().default(0), leads: z.number().default(0), conversions: z.number().default(0), sales: z.number().default(0), saleAmount: z.number().default(0), lastClicked: z.nullable(z.string()), createdAt: z.string(), updatedAt: z.string(), tagId: z.nullable(z.string()), projectId: z.string(), }).transform((v) => { return remap$(v, { "utm_source": "utmSource", "utm_medium": "utmMedium", "utm_campaign": "utmCampaign", "utm_term": "utmTerm", "utm_content": "utmContent", }); }); export function linkSchemaFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => LinkSchema$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'LinkSchema' from JSON`, ); }