/* * 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 { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; /** * The field to sort the customers by. The default is `createdAt`. */ export const GetCustomersQueryParamSortBy = { CreatedAt: "createdAt", SaleAmount: "saleAmount", FirstSaleAt: "firstSaleAt", SubscriptionCanceledAt: "subscriptionCanceledAt", } as const; /** * The field to sort the customers by. The default is `createdAt`. */ export type GetCustomersQueryParamSortBy = ClosedEnum< typeof GetCustomersQueryParamSortBy >; /** * The sort order. The default is `desc`. */ export const GetCustomersQueryParamSortOrder = { Asc: "asc", Desc: "desc", } as const; /** * The sort order. The default is `desc`. */ export type GetCustomersQueryParamSortOrder = ClosedEnum< typeof GetCustomersQueryParamSortOrder >; export type GetCustomersRequest = { /** * A case-sensitive filter on the list based on the customer's `email` field. The value must be a string. Takes precedence over `externalId`. */ email?: string | undefined; /** * A case-sensitive filter on the list based on the customer's `externalId` field. The value must be a string. Takes precedence over `search`. */ externalId?: string | undefined; /** * A search query to filter customers by email, externalId, or name. If `email` or `externalId` is provided, this will be ignored. */ search?: string | undefined; /** * A filter on the list based on the customer's `country` field. */ country?: string | undefined; /** * A filter on the list based on the customer's `linkId` field (the referral link ID). */ linkId?: string | undefined; /** * Program ID to filter by. */ programId?: string | undefined; /** * Partner ID to filter by. */ partnerId?: string | undefined; /** * Whether to include expanded fields on the customer (`link`, `partner`, `discount`). */ includeExpandedFields?: boolean | undefined; /** * The field to sort the customers by. The default is `createdAt`. */ sortBy?: GetCustomersQueryParamSortBy | undefined; /** * The sort order. The default is `desc`. */ sortOrder?: GetCustomersQueryParamSortOrder | undefined; /** * If specified, the query only searches for results before this cursor. Mutually exclusive with `startingAfter`. */ endingBefore?: string | undefined; /** * If specified, the query only searches for results after this cursor. Mutually exclusive with `endingBefore`. */ startingAfter?: string | undefined; /** * DEPRECATED. Use `startingAfter` instead. */ page?: number | undefined; /** * The number of items per page. */ pageSize?: number | undefined; }; export type GetCustomersLink = { /** * 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 GetCustomersPartner = { /** * 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 GetCustomersType = { Percentage: "percentage", Flat: "flat", } as const; export type GetCustomersType = ClosedEnum; export type Discount = { id: string; amount: number; type: GetCustomersType; maxDuration: number | null; couponId: string | null; couponTestId: string | null; description?: string | null | undefined; partnersCount?: number | null | undefined; }; export type GetCustomersResponseBody = { /** * 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?: GetCustomersLink | null | undefined; programId?: string | null | undefined; partner?: GetCustomersPartner | null | undefined; discount?: Discount | null | undefined; }; export type GetCustomersResponse = { result: Array; }; /** @internal */ export const GetCustomersQueryParamSortBy$outboundSchema: z.ZodNativeEnum< typeof GetCustomersQueryParamSortBy > = z.nativeEnum(GetCustomersQueryParamSortBy); /** @internal */ export const GetCustomersQueryParamSortOrder$outboundSchema: z.ZodNativeEnum< typeof GetCustomersQueryParamSortOrder > = z.nativeEnum(GetCustomersQueryParamSortOrder); /** @internal */ export type GetCustomersRequest$Outbound = { email?: string | undefined; externalId?: string | undefined; search?: string | undefined; country?: string | undefined; linkId?: string | undefined; programId?: string | undefined; partnerId?: string | undefined; includeExpandedFields?: boolean | undefined; sortBy: string; sortOrder: string; endingBefore?: string | undefined; startingAfter?: string | undefined; page?: number | undefined; pageSize: number; }; /** @internal */ export const GetCustomersRequest$outboundSchema: z.ZodType< GetCustomersRequest$Outbound, z.ZodTypeDef, GetCustomersRequest > = z.object({ email: z.string().optional(), externalId: z.string().optional(), search: z.string().optional(), country: z.string().optional(), linkId: z.string().optional(), programId: z.string().optional(), partnerId: z.string().optional(), includeExpandedFields: z.boolean().optional(), sortBy: GetCustomersQueryParamSortBy$outboundSchema.default("createdAt"), sortOrder: GetCustomersQueryParamSortOrder$outboundSchema.default("desc"), endingBefore: z.string().optional(), startingAfter: z.string().optional(), page: z.number().optional(), pageSize: z.number().default(100), }); export function getCustomersRequestToJSON( getCustomersRequest: GetCustomersRequest, ): string { return JSON.stringify( GetCustomersRequest$outboundSchema.parse(getCustomersRequest), ); } /** @internal */ export const GetCustomersLink$inboundSchema: z.ZodType< GetCustomersLink, 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 getCustomersLinkFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetCustomersLink$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetCustomersLink' from JSON`, ); } /** @internal */ export const GetCustomersPartner$inboundSchema: z.ZodType< GetCustomersPartner, z.ZodTypeDef, unknown > = z.object({ id: z.string(), name: z.string(), email: z.nullable(z.string()), image: z.nullable(z.string()), }); export function getCustomersPartnerFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetCustomersPartner$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetCustomersPartner' from JSON`, ); } /** @internal */ export const GetCustomersType$inboundSchema: z.ZodNativeEnum< typeof GetCustomersType > = z.nativeEnum(GetCustomersType); /** @internal */ export const Discount$inboundSchema: z.ZodType< Discount, z.ZodTypeDef, unknown > = z.object({ id: z.string(), amount: z.number(), type: GetCustomersType$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 discountFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Discount$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Discount' from JSON`, ); } /** @internal */ export const GetCustomersResponseBody$inboundSchema: z.ZodType< GetCustomersResponseBody, 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(() => GetCustomersLink$inboundSchema)).optional(), programId: z.nullable(z.string()).optional(), partner: z.nullable(z.lazy(() => GetCustomersPartner$inboundSchema)) .optional(), discount: z.nullable(z.lazy(() => Discount$inboundSchema)).optional(), }); export function getCustomersResponseBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetCustomersResponseBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetCustomersResponseBody' from JSON`, ); } /** @internal */ export const GetCustomersResponse$inboundSchema: z.ZodType< GetCustomersResponse, z.ZodTypeDef, unknown > = z.object({ Result: z.array(z.lazy(() => GetCustomersResponseBody$inboundSchema)), }).transform((v) => { return remap$(v, { "Result": "result", }); }); export function getCustomersResponseFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetCustomersResponse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetCustomersResponse' from JSON`, ); }