/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { safeParse } from "../../lib/schemas.js"; import { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; export type GetCustomerRequest = { /** * The unique ID of the customer. You may use either the customer's `id` on Dub (obtained via `/customers` endpoint) or their `externalId` (unique ID within your system, prefixed with `ext_`, e.g. `ext_123`). */ id: string; /** * Whether to include expanded fields on the customer (`link`, `partner`, `discount`). */ includeExpandedFields?: boolean | undefined; }; export type GetCustomerLink = { /** * 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 full URL of the short link, including the https protocol (e.g. `https://dub.sh/try`). */ shortLink: string; /** * The destination URL of the short link. */ url: string; /** * The ID of the program the short link is associated with. */ programId: string | null; }; export type GetCustomerPartner = { /** * The partner's unique ID on Dub. */ id: string; /** * The partner's full legal name. */ name: string; /** * The partner's email address. Should be a unique value across Dub. */ email: string | null; /** * The partner's avatar image. */ image: string | null; }; export const GetCustomerType = { Percentage: "percentage", Flat: "flat", } as const; export type GetCustomerType = ClosedEnum; export type GetCustomerDiscount = { id: string; amount: number; type: GetCustomerType; maxDuration: number | null; couponId: string | null; couponTestId: string | null; description?: string | null | undefined; partnersCount?: number | null | undefined; }; /** * The customer object. */ export type GetCustomerResponseBody = { /** * The unique ID of the customer. You may use either the customer's `id` on Dub (obtained via `/customers` endpoint) or their `externalId` (unique ID within your system, prefixed with `ext_`, e.g. `ext_123`). */ id: string; /** * Name of the customer. */ name: string; /** * Email of the customer. */ email?: string | null | undefined; /** * Avatar URL of the customer. */ avatar?: string | null | undefined; /** * Unique identifier for the customer in the client's app. */ externalId: string; /** * The customer's Stripe customer ID. This is useful for attributing recurring sale events to the partner who referred the customer. */ stripeCustomerId?: string | null | undefined; /** * Country of the customer. */ country?: string | null | undefined; /** * Total number of sales for the customer. */ sales?: number | null | undefined; /** * Total amount of sales for the customer. */ saleAmount?: number | null | undefined; /** * The date the customer was created (usually the signup date or trial start date). */ createdAt: string; /** * The date the customer made their first sale. Useful for calculating the time to first sale and LTV. */ firstSaleAt?: string | null | undefined; /** * The date the customer canceled their subscription. Useful for calculating LTV and churn rate. */ subscriptionCanceledAt?: string | null | undefined; link?: GetCustomerLink | null | undefined; programId?: string | null | undefined; partner?: GetCustomerPartner | null | undefined; discount?: GetCustomerDiscount | null | undefined; }; /** @internal */ export type GetCustomerRequest$Outbound = { id: string; includeExpandedFields?: boolean | undefined; }; /** @internal */ export const GetCustomerRequest$outboundSchema: z.ZodType< GetCustomerRequest$Outbound, z.ZodTypeDef, GetCustomerRequest > = z.object({ id: z.string(), includeExpandedFields: z.boolean().optional(), }); export function getCustomerRequestToJSON( getCustomerRequest: GetCustomerRequest, ): string { return JSON.stringify( GetCustomerRequest$outboundSchema.parse(getCustomerRequest), ); } /** @internal */ export const GetCustomerLink$inboundSchema: z.ZodType< GetCustomerLink, z.ZodTypeDef, unknown > = z.object({ id: z.string(), domain: z.string(), key: z.string(), shortLink: z.string(), url: z.string(), programId: z.nullable(z.string()), }); export function getCustomerLinkFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetCustomerLink$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetCustomerLink' from JSON`, ); } /** @internal */ export const GetCustomerPartner$inboundSchema: z.ZodType< GetCustomerPartner, z.ZodTypeDef, unknown > = z.object({ id: z.string(), name: z.string(), email: z.nullable(z.string()), image: z.nullable(z.string()), }); export function getCustomerPartnerFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetCustomerPartner$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetCustomerPartner' from JSON`, ); } /** @internal */ export const GetCustomerType$inboundSchema: z.ZodNativeEnum< typeof GetCustomerType > = z.nativeEnum(GetCustomerType); /** @internal */ export const GetCustomerDiscount$inboundSchema: z.ZodType< GetCustomerDiscount, z.ZodTypeDef, unknown > = z.object({ id: z.string(), amount: z.number(), type: GetCustomerType$inboundSchema, maxDuration: z.nullable(z.number()), couponId: z.nullable(z.string()), couponTestId: z.nullable(z.string()), description: z.nullable(z.string()).optional(), partnersCount: z.nullable(z.number()).optional(), }); export function getCustomerDiscountFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetCustomerDiscount$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetCustomerDiscount' from JSON`, ); } /** @internal */ export const GetCustomerResponseBody$inboundSchema: z.ZodType< GetCustomerResponseBody, z.ZodTypeDef, unknown > = z.object({ id: z.string(), name: z.string(), email: z.nullable(z.string()).optional(), avatar: z.nullable(z.string()).optional(), externalId: z.string(), stripeCustomerId: z.nullable(z.string()).optional(), country: z.nullable(z.string()).optional(), sales: z.nullable(z.number()).optional(), saleAmount: z.nullable(z.number()).optional(), createdAt: z.string(), firstSaleAt: z.nullable(z.string()).optional(), subscriptionCanceledAt: z.nullable(z.string()).optional(), link: z.nullable(z.lazy(() => GetCustomerLink$inboundSchema)).optional(), programId: z.nullable(z.string()).optional(), partner: z.nullable(z.lazy(() => GetCustomerPartner$inboundSchema)) .optional(), discount: z.nullable(z.lazy(() => GetCustomerDiscount$inboundSchema)) .optional(), }); export function getCustomerResponseBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetCustomerResponseBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetCustomerResponseBody' from JSON`, ); }