/* * 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 const Type = { Click: "click", Lead: "lead", Sale: "sale", Custom: "custom", } as const; export type Type = ClosedEnum; /** * Filter the list of commissions by their corresponding status. */ export const QueryParamStatus = { Pending: "pending", Processed: "processed", Paid: "paid", Refunded: "refunded", Duplicate: "duplicate", Fraud: "fraud", Canceled: "canceled", } as const; /** * Filter the list of commissions by their corresponding status. */ export type QueryParamStatus = ClosedEnum; /** * The field to sort the list of commissions by. */ export const ListCommissionsQueryParamSortBy = { CreatedAt: "createdAt", Amount: "amount", } as const; /** * The field to sort the list of commissions by. */ export type ListCommissionsQueryParamSortBy = ClosedEnum< typeof ListCommissionsQueryParamSortBy >; /** * The sort order for the list of commissions. */ export const ListCommissionsQueryParamSortOrder = { Asc: "asc", Desc: "desc", } as const; /** * The sort order for the list of commissions. */ export type ListCommissionsQueryParamSortOrder = ClosedEnum< typeof ListCommissionsQueryParamSortOrder >; /** * The interval to retrieve commissions for. */ export const ListCommissionsQueryParamInterval = { TwentyFourh: "24h", Sevend: "7d", Thirtyd: "30d", Ninetyd: "90d", Oney: "1y", Mtd: "mtd", Qtd: "qtd", Ytd: "ytd", All: "all", } as const; /** * The interval to retrieve commissions for. */ export type ListCommissionsQueryParamInterval = ClosedEnum< typeof ListCommissionsQueryParamInterval >; export type ListCommissionsRequest = { type?: Type | undefined; /** * Filter the list of commissions by the associated customer. */ customerId?: string | undefined; /** * Filter the list of commissions by the associated payout. */ payoutId?: string | undefined; /** * Filter the list of commissions by the associated partner. When specified, takes precedence over `tenantId`. */ partnerId?: string | undefined; /** * Filter the list of commissions by the associated partner's `tenantId` (their unique ID within your database). */ tenantId?: string | undefined; /** * Filter the list of commissions by the associated partner group. */ groupId?: string | undefined; /** * Filter the list of commissions by the associated invoice. Since invoiceId is unique on a per-program basis, this will only return one commission per invoice. */ invoiceId?: string | undefined; /** * Filter the list of commissions by their corresponding status. */ status?: QueryParamStatus | undefined; /** * The field to sort the list of commissions by. */ sortBy?: ListCommissionsQueryParamSortBy | undefined; /** * The sort order for the list of commissions. */ sortOrder?: ListCommissionsQueryParamSortOrder | undefined; /** * The interval to retrieve commissions for. */ interval?: ListCommissionsQueryParamInterval | undefined; /** * The start date of the date range to filter the commissions by. */ start?: string | undefined; /** * The end date of the date range to filter the commissions by. */ end?: string | undefined; timezone?: string | 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 const ListCommissionsType = { Click: "click", Lead: "lead", Sale: "sale", Custom: "custom", } as const; export type ListCommissionsType = ClosedEnum; export const ListCommissionsStatus = { Pending: "pending", Processed: "processed", Paid: "paid", Refunded: "refunded", Duplicate: "duplicate", Fraud: "fraud", Canceled: "canceled", } as const; export type ListCommissionsStatus = ClosedEnum; export type ListCommissionsPartner = { /** * 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; /** * The partner's group ID on Dub. */ groupId?: string | null | undefined; }; export type ListCommissionsCustomer = { /** * 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 ListCommissionsResponseBody = { /** * The commission's unique ID on Dub. */ id: string; type?: ListCommissionsType | undefined; amount: number; earnings: number; currency: string; status: ListCommissionsStatus; invoiceId: string | null; description: string | null; quantity: number; /** * The user who created the manual commission. */ userId?: string | null | undefined; createdAt: string; updatedAt: string; partner: ListCommissionsPartner; customer?: ListCommissionsCustomer | null | undefined; }; export type ListCommissionsResponse = { result: Array; }; /** @internal */ export const Type$outboundSchema: z.ZodNativeEnum = z.nativeEnum( Type, ); /** @internal */ export const QueryParamStatus$outboundSchema: z.ZodNativeEnum< typeof QueryParamStatus > = z.nativeEnum(QueryParamStatus); /** @internal */ export const ListCommissionsQueryParamSortBy$outboundSchema: z.ZodNativeEnum< typeof ListCommissionsQueryParamSortBy > = z.nativeEnum(ListCommissionsQueryParamSortBy); /** @internal */ export const ListCommissionsQueryParamSortOrder$outboundSchema: z.ZodNativeEnum< typeof ListCommissionsQueryParamSortOrder > = z.nativeEnum(ListCommissionsQueryParamSortOrder); /** @internal */ export const ListCommissionsQueryParamInterval$outboundSchema: z.ZodNativeEnum< typeof ListCommissionsQueryParamInterval > = z.nativeEnum(ListCommissionsQueryParamInterval); /** @internal */ export type ListCommissionsRequest$Outbound = { type?: string | undefined; customerId?: string | undefined; payoutId?: string | undefined; partnerId?: string | undefined; tenantId?: string | undefined; groupId?: string | undefined; invoiceId?: string | undefined; status?: string | undefined; sortBy: string; sortOrder: string; interval: string; start?: string | undefined; end?: string | undefined; timezone?: string | undefined; endingBefore?: string | undefined; startingAfter?: string | undefined; page?: number | undefined; pageSize: number; }; /** @internal */ export const ListCommissionsRequest$outboundSchema: z.ZodType< ListCommissionsRequest$Outbound, z.ZodTypeDef, ListCommissionsRequest > = z.object({ type: Type$outboundSchema.optional(), customerId: z.string().optional(), payoutId: z.string().optional(), partnerId: z.string().optional(), tenantId: z.string().optional(), groupId: z.string().optional(), invoiceId: z.string().optional(), status: QueryParamStatus$outboundSchema.optional(), sortBy: ListCommissionsQueryParamSortBy$outboundSchema.default("createdAt"), sortOrder: ListCommissionsQueryParamSortOrder$outboundSchema.default("desc"), interval: ListCommissionsQueryParamInterval$outboundSchema.default("all"), start: z.string().optional(), end: z.string().optional(), timezone: z.string().optional(), endingBefore: z.string().optional(), startingAfter: z.string().optional(), page: z.number().optional(), pageSize: z.number().default(100), }); export function listCommissionsRequestToJSON( listCommissionsRequest: ListCommissionsRequest, ): string { return JSON.stringify( ListCommissionsRequest$outboundSchema.parse(listCommissionsRequest), ); } /** @internal */ export const ListCommissionsType$inboundSchema: z.ZodNativeEnum< typeof ListCommissionsType > = z.nativeEnum(ListCommissionsType); /** @internal */ export const ListCommissionsStatus$inboundSchema: z.ZodNativeEnum< typeof ListCommissionsStatus > = z.nativeEnum(ListCommissionsStatus); /** @internal */ export const ListCommissionsPartner$inboundSchema: z.ZodType< ListCommissionsPartner, 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(), }); export function listCommissionsPartnerFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ListCommissionsPartner$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ListCommissionsPartner' from JSON`, ); } /** @internal */ export const ListCommissionsCustomer$inboundSchema: z.ZodType< ListCommissionsCustomer, 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(), }); export function listCommissionsCustomerFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ListCommissionsCustomer$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ListCommissionsCustomer' from JSON`, ); } /** @internal */ export const ListCommissionsResponseBody$inboundSchema: z.ZodType< ListCommissionsResponseBody, z.ZodTypeDef, unknown > = z.object({ id: z.string(), type: ListCommissionsType$inboundSchema.optional(), amount: z.number(), earnings: z.number(), currency: z.string(), status: ListCommissionsStatus$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(() => ListCommissionsPartner$inboundSchema), customer: z.nullable(z.lazy(() => ListCommissionsCustomer$inboundSchema)) .optional(), }); export function listCommissionsResponseBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ListCommissionsResponseBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ListCommissionsResponseBody' from JSON`, ); } /** @internal */ export const ListCommissionsResponse$inboundSchema: z.ZodType< ListCommissionsResponse, z.ZodTypeDef, unknown > = z.object({ Result: z.array(z.lazy(() => ListCommissionsResponseBody$inboundSchema)), }).transform((v) => { return remap$(v, { "Result": "result", }); }); export function listCommissionsResponseFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ListCommissionsResponse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ListCommissionsResponse' from JSON`, ); }