/* * 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"; export type UpdateCustomerRequestBody = { /** * The customer's email address. */ email?: string | null | undefined; /** * The customer's name. If not provided, the email address will be used, and if email is not provided, a random name will be generated. */ name?: string | null | undefined; /** * The customer's avatar URL. If not provided, a random avatar will be generated. */ avatar?: string | null | undefined; /** * The customer's unique identifier your database. This is useful for associating subsequent conversion events from Dub's API to your internal systems. */ externalId?: string | undefined; /** * 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; /** * The customer's country in ISO 3166-1 alpha-2 format. Updating this field will only affect the customer's country in Dub's system (and has no effect on existing conversion events). */ country?: string | undefined; }; export type UpdateCustomerRequest = { /** * 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; requestBody?: UpdateCustomerRequestBody | undefined; }; export type UpdateCustomerLink = { /** * 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 UpdateCustomerPartner = { /** * 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 UpdateCustomerType = { Percentage: "percentage", Flat: "flat", } as const; export type UpdateCustomerType = ClosedEnum; export type UpdateCustomerDiscount = { id: string; amount: number; type: UpdateCustomerType; maxDuration: number | null; couponId: string | null; couponTestId: string | null; description?: string | null | undefined; partnersCount?: number | null | undefined; }; /** * The customer was updated. */ export type UpdateCustomerResponseBody = { /** * 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?: UpdateCustomerLink | null | undefined; programId?: string | null | undefined; partner?: UpdateCustomerPartner | null | undefined; discount?: UpdateCustomerDiscount | null | undefined; }; /** @internal */ export type UpdateCustomerRequestBody$Outbound = { email?: string | null | undefined; name?: string | null | undefined; avatar?: string | null | undefined; externalId?: string | undefined; stripeCustomerId?: string | null | undefined; country?: string | undefined; }; /** @internal */ export const UpdateCustomerRequestBody$outboundSchema: z.ZodType< UpdateCustomerRequestBody$Outbound, z.ZodTypeDef, UpdateCustomerRequestBody > = z.object({ email: z.nullable(z.string()).optional(), name: z.nullable(z.string()).optional(), avatar: z.nullable(z.string()).optional(), externalId: z.string().optional(), stripeCustomerId: z.nullable(z.string()).optional(), country: z.string().optional(), }); export function updateCustomerRequestBodyToJSON( updateCustomerRequestBody: UpdateCustomerRequestBody, ): string { return JSON.stringify( UpdateCustomerRequestBody$outboundSchema.parse(updateCustomerRequestBody), ); } /** @internal */ export type UpdateCustomerRequest$Outbound = { id: string; includeExpandedFields?: boolean | undefined; RequestBody?: UpdateCustomerRequestBody$Outbound | undefined; }; /** @internal */ export const UpdateCustomerRequest$outboundSchema: z.ZodType< UpdateCustomerRequest$Outbound, z.ZodTypeDef, UpdateCustomerRequest > = z.object({ id: z.string(), includeExpandedFields: z.boolean().optional(), requestBody: z.lazy(() => UpdateCustomerRequestBody$outboundSchema) .optional(), }).transform((v) => { return remap$(v, { requestBody: "RequestBody", }); }); export function updateCustomerRequestToJSON( updateCustomerRequest: UpdateCustomerRequest, ): string { return JSON.stringify( UpdateCustomerRequest$outboundSchema.parse(updateCustomerRequest), ); } /** @internal */ export const UpdateCustomerLink$inboundSchema: z.ZodType< UpdateCustomerLink, 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 updateCustomerLinkFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => UpdateCustomerLink$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'UpdateCustomerLink' from JSON`, ); } /** @internal */ export const UpdateCustomerPartner$inboundSchema: z.ZodType< UpdateCustomerPartner, z.ZodTypeDef, unknown > = z.object({ id: z.string(), name: z.string(), email: z.nullable(z.string()), image: z.nullable(z.string()), }); export function updateCustomerPartnerFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => UpdateCustomerPartner$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'UpdateCustomerPartner' from JSON`, ); } /** @internal */ export const UpdateCustomerType$inboundSchema: z.ZodNativeEnum< typeof UpdateCustomerType > = z.nativeEnum(UpdateCustomerType); /** @internal */ export const UpdateCustomerDiscount$inboundSchema: z.ZodType< UpdateCustomerDiscount, z.ZodTypeDef, unknown > = z.object({ id: z.string(), amount: z.number(), type: UpdateCustomerType$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 updateCustomerDiscountFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => UpdateCustomerDiscount$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'UpdateCustomerDiscount' from JSON`, ); } /** @internal */ export const UpdateCustomerResponseBody$inboundSchema: z.ZodType< UpdateCustomerResponseBody, 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(() => UpdateCustomerLink$inboundSchema)).optional(), programId: z.nullable(z.string()).optional(), partner: z.nullable(z.lazy(() => UpdateCustomerPartner$inboundSchema)) .optional(), discount: z.nullable(z.lazy(() => UpdateCustomerDiscount$inboundSchema)) .optional(), }); export function updateCustomerResponseBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => UpdateCustomerResponseBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'UpdateCustomerResponseBody' from JSON`, ); }