/* * 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 const CommissionCreatedEventEvent = { CommissionCreated: "commission.created", } as const; export type CommissionCreatedEventEvent = ClosedEnum< typeof CommissionCreatedEventEvent >; export const CommissionCreatedEventType = { Click: "click", Lead: "lead", Sale: "sale", Custom: "custom", } as const; export type CommissionCreatedEventType = ClosedEnum< typeof CommissionCreatedEventType >; export const CommissionCreatedEventStatus = { Pending: "pending", Processed: "processed", Paid: "paid", Refunded: "refunded", Duplicate: "duplicate", Fraud: "fraud", Canceled: "canceled", } as const; export type CommissionCreatedEventStatus = ClosedEnum< typeof CommissionCreatedEventStatus >; export type CommissionCreatedEventPartner = { /** * 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; /** * The date when the partner enabled payouts. */ payoutsEnabledAt: string | null; /** * The partner's country (required for tax purposes). */ country: string | null; groupId?: string | null | undefined; totalClicks: number; totalLeads: number; totalConversions: number; totalSales: number; totalSaleAmount: number; totalCommissions: number; }; export type CommissionCreatedEventCustomer = { /** * 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; }; export type CommissionCreatedEventLink = { /** * The unique ID of the short link. */ id: string; /** * The full URL of the short link, including the https protocol (e.g. `https://dub.sh/try`). */ shortLink: 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; }; export type CommissionCreatedEventData = { /** * The commission's unique ID on Dub. */ id: string; type?: CommissionCreatedEventType | undefined; amount: number; earnings: number; currency: string; status: CommissionCreatedEventStatus; invoiceId: string | null; description: string | null; quantity: number; /** * The user who created the manual commission. */ userId?: string | null | undefined; createdAt: string; updatedAt: string; partner: CommissionCreatedEventPartner; customer?: CommissionCreatedEventCustomer | null | undefined; link: CommissionCreatedEventLink | null; }; /** * Triggered when a commission is created for a partner. */ export type CommissionCreatedEvent = { id: string; event: CommissionCreatedEventEvent; createdAt: string; data: CommissionCreatedEventData; }; /** @internal */ export const CommissionCreatedEventEvent$inboundSchema: z.ZodNativeEnum< typeof CommissionCreatedEventEvent > = z.nativeEnum(CommissionCreatedEventEvent); /** @internal */ export const CommissionCreatedEventEvent$outboundSchema: z.ZodNativeEnum< typeof CommissionCreatedEventEvent > = CommissionCreatedEventEvent$inboundSchema; /** @internal */ export const CommissionCreatedEventType$inboundSchema: z.ZodNativeEnum< typeof CommissionCreatedEventType > = z.nativeEnum(CommissionCreatedEventType); /** @internal */ export const CommissionCreatedEventType$outboundSchema: z.ZodNativeEnum< typeof CommissionCreatedEventType > = CommissionCreatedEventType$inboundSchema; /** @internal */ export const CommissionCreatedEventStatus$inboundSchema: z.ZodNativeEnum< typeof CommissionCreatedEventStatus > = z.nativeEnum(CommissionCreatedEventStatus); /** @internal */ export const CommissionCreatedEventStatus$outboundSchema: z.ZodNativeEnum< typeof CommissionCreatedEventStatus > = CommissionCreatedEventStatus$inboundSchema; /** @internal */ export const CommissionCreatedEventPartner$inboundSchema: z.ZodType< CommissionCreatedEventPartner, z.ZodTypeDef, unknown > = z.object({ id: z.string(), name: z.string(), email: z.nullable(z.string()), image: z.nullable(z.string()), payoutsEnabledAt: z.nullable(z.string()), country: z.nullable(z.string()), groupId: z.nullable(z.string()).optional(), totalClicks: z.number(), totalLeads: z.number(), totalConversions: z.number(), totalSales: z.number(), totalSaleAmount: z.number(), totalCommissions: z.number(), }); /** @internal */ export type CommissionCreatedEventPartner$Outbound = { id: string; name: string; email: string | null; image: string | null; payoutsEnabledAt: string | null; country: string | null; groupId?: string | null | undefined; totalClicks: number; totalLeads: number; totalConversions: number; totalSales: number; totalSaleAmount: number; totalCommissions: number; }; /** @internal */ export const CommissionCreatedEventPartner$outboundSchema: z.ZodType< CommissionCreatedEventPartner$Outbound, z.ZodTypeDef, CommissionCreatedEventPartner > = z.object({ id: z.string(), name: z.string(), email: z.nullable(z.string()), image: z.nullable(z.string()), payoutsEnabledAt: z.nullable(z.string()), country: z.nullable(z.string()), groupId: z.nullable(z.string()).optional(), totalClicks: z.number(), totalLeads: z.number(), totalConversions: z.number(), totalSales: z.number(), totalSaleAmount: z.number(), totalCommissions: z.number(), }); export function commissionCreatedEventPartnerToJSON( commissionCreatedEventPartner: CommissionCreatedEventPartner, ): string { return JSON.stringify( CommissionCreatedEventPartner$outboundSchema.parse( commissionCreatedEventPartner, ), ); } export function commissionCreatedEventPartnerFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CommissionCreatedEventPartner$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CommissionCreatedEventPartner' from JSON`, ); } /** @internal */ export const CommissionCreatedEventCustomer$inboundSchema: z.ZodType< CommissionCreatedEventCustomer, 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(), }); /** @internal */ export type CommissionCreatedEventCustomer$Outbound = { id: string; name: string; email?: string | null | undefined; avatar?: string | null | undefined; externalId: string; stripeCustomerId?: string | null | undefined; country?: string | null | undefined; sales?: number | null | undefined; saleAmount?: number | null | undefined; createdAt: string; firstSaleAt?: string | null | undefined; subscriptionCanceledAt?: string | null | undefined; }; /** @internal */ export const CommissionCreatedEventCustomer$outboundSchema: z.ZodType< CommissionCreatedEventCustomer$Outbound, z.ZodTypeDef, CommissionCreatedEventCustomer > = 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(), }); export function commissionCreatedEventCustomerToJSON( commissionCreatedEventCustomer: CommissionCreatedEventCustomer, ): string { return JSON.stringify( CommissionCreatedEventCustomer$outboundSchema.parse( commissionCreatedEventCustomer, ), ); } export function commissionCreatedEventCustomerFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CommissionCreatedEventCustomer$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CommissionCreatedEventCustomer' from JSON`, ); } /** @internal */ export const CommissionCreatedEventLink$inboundSchema: z.ZodType< CommissionCreatedEventLink, z.ZodTypeDef, unknown > = z.object({ id: z.string(), shortLink: z.string(), domain: z.string(), key: z.string(), }); /** @internal */ export type CommissionCreatedEventLink$Outbound = { id: string; shortLink: string; domain: string; key: string; }; /** @internal */ export const CommissionCreatedEventLink$outboundSchema: z.ZodType< CommissionCreatedEventLink$Outbound, z.ZodTypeDef, CommissionCreatedEventLink > = z.object({ id: z.string(), shortLink: z.string(), domain: z.string(), key: z.string(), }); export function commissionCreatedEventLinkToJSON( commissionCreatedEventLink: CommissionCreatedEventLink, ): string { return JSON.stringify( CommissionCreatedEventLink$outboundSchema.parse(commissionCreatedEventLink), ); } export function commissionCreatedEventLinkFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CommissionCreatedEventLink$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CommissionCreatedEventLink' from JSON`, ); } /** @internal */ export const CommissionCreatedEventData$inboundSchema: z.ZodType< CommissionCreatedEventData, z.ZodTypeDef, unknown > = z.object({ id: z.string(), type: CommissionCreatedEventType$inboundSchema.optional(), amount: z.number(), earnings: z.number(), currency: z.string(), status: CommissionCreatedEventStatus$inboundSchema, invoiceId: z.nullable(z.string()), description: z.nullable(z.string()), quantity: z.number(), userId: z.nullable(z.string()).optional(), createdAt: z.string(), updatedAt: z.string(), partner: z.lazy(() => CommissionCreatedEventPartner$inboundSchema), customer: z.nullable( z.lazy(() => CommissionCreatedEventCustomer$inboundSchema), ).optional(), link: z.nullable(z.lazy(() => CommissionCreatedEventLink$inboundSchema)), }); /** @internal */ export type CommissionCreatedEventData$Outbound = { id: string; type?: string | undefined; amount: number; earnings: number; currency: string; status: string; invoiceId: string | null; description: string | null; quantity: number; userId?: string | null | undefined; createdAt: string; updatedAt: string; partner: CommissionCreatedEventPartner$Outbound; customer?: CommissionCreatedEventCustomer$Outbound | null | undefined; link: CommissionCreatedEventLink$Outbound | null; }; /** @internal */ export const CommissionCreatedEventData$outboundSchema: z.ZodType< CommissionCreatedEventData$Outbound, z.ZodTypeDef, CommissionCreatedEventData > = z.object({ id: z.string(), type: CommissionCreatedEventType$outboundSchema.optional(), amount: z.number(), earnings: z.number(), currency: z.string(), status: CommissionCreatedEventStatus$outboundSchema, invoiceId: z.nullable(z.string()), description: z.nullable(z.string()), quantity: z.number(), userId: z.nullable(z.string()).optional(), createdAt: z.string(), updatedAt: z.string(), partner: z.lazy(() => CommissionCreatedEventPartner$outboundSchema), customer: z.nullable( z.lazy(() => CommissionCreatedEventCustomer$outboundSchema), ).optional(), link: z.nullable(z.lazy(() => CommissionCreatedEventLink$outboundSchema)), }); export function commissionCreatedEventDataToJSON( commissionCreatedEventData: CommissionCreatedEventData, ): string { return JSON.stringify( CommissionCreatedEventData$outboundSchema.parse(commissionCreatedEventData), ); } export function commissionCreatedEventDataFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CommissionCreatedEventData$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CommissionCreatedEventData' from JSON`, ); } /** @internal */ export const CommissionCreatedEvent$inboundSchema: z.ZodType< CommissionCreatedEvent, z.ZodTypeDef, unknown > = z.object({ id: z.string(), event: CommissionCreatedEventEvent$inboundSchema, createdAt: z.string(), data: z.lazy(() => CommissionCreatedEventData$inboundSchema), }); /** @internal */ export type CommissionCreatedEvent$Outbound = { id: string; event: string; createdAt: string; data: CommissionCreatedEventData$Outbound; }; /** @internal */ export const CommissionCreatedEvent$outboundSchema: z.ZodType< CommissionCreatedEvent$Outbound, z.ZodTypeDef, CommissionCreatedEvent > = z.object({ id: z.string(), event: CommissionCreatedEventEvent$outboundSchema, createdAt: z.string(), data: z.lazy(() => CommissionCreatedEventData$outboundSchema), }); export function commissionCreatedEventToJSON( commissionCreatedEvent: CommissionCreatedEvent, ): string { return JSON.stringify( CommissionCreatedEvent$outboundSchema.parse(commissionCreatedEvent), ); } export function commissionCreatedEventFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CommissionCreatedEvent$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CommissionCreatedEvent' from JSON`, ); }