/* * 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 lifecycle status of the batch request itself. Terminal values are `completed` (processing finished — inspect `results` and `exclusions` for per-payroll outcomes) and `failed` (the batch crashed at the system level; can be retried). This is distinct from the per-payroll `status` returned inside `results[]`. A `completed` batch does not imply every payroll was cancelled. */ export const PayrollBatchResultsStatus = { Pending: "pending", Processing: "processing", Completed: "completed", Failed: "failed", } as const; /** * The lifecycle status of the batch request itself. Terminal values are `completed` (processing finished — inspect `results` and `exclusions` for per-payroll outcomes) and `failed` (the batch crashed at the system level; can be retried). This is distinct from the per-payroll `status` returned inside `results[]`. A `completed` batch does not imply every payroll was cancelled. */ export type PayrollBatchResultsStatus = ClosedEnum< typeof PayrollBatchResultsStatus >; /** * The outcome of cancelling this payroll. A cancel is atomic — there is no per-payroll `partial_success`. * * @remarks * - `success`: the payroll was cancelled, or required no action (already cancelled / never run) * - `failed`: the payroll could not be cancelled; see `errors` */ export const PayrollBatchResultsResultsStatus = { Success: "success", Failed: "failed", } as const; /** * The outcome of cancelling this payroll. A cancel is atomic — there is no per-payroll `partial_success`. * * @remarks * - `success`: the payroll was cancelled, or required no action (already cancelled / never run) * - `failed`: the payroll could not be cancelled; see `errors` */ export type PayrollBatchResultsResultsStatus = ClosedEnum< typeof PayrollBatchResultsResultsStatus >; /** * Machine-readable reason the cancellation failed. * * @remarks * - `not_cancellable`: the payroll is past the point where it can be cancelled * - `internal_error`: an unexpected error occurred; the request can be retried */ export const PayrollBatchResultsResultsCategory = { NotCancellable: "not_cancellable", InternalError: "internal_error", } as const; /** * Machine-readable reason the cancellation failed. * * @remarks * - `not_cancellable`: the payroll is past the point where it can be cancelled * - `internal_error`: an unexpected error occurred; the request can be retried */ export type PayrollBatchResultsResultsCategory = ClosedEnum< typeof PayrollBatchResultsResultsCategory >; export type PayrollBatchResultsErrors = { /** * The key identifying the error source. */ errorKey?: string | undefined; /** * Machine-readable reason the cancellation failed. * * @remarks * - `not_cancellable`: the payroll is past the point where it can be cancelled * - `internal_error`: an unexpected error occurred; the request can be retried */ category?: PayrollBatchResultsResultsCategory | undefined; /** * Human-readable explanation of the failure. */ message?: string | undefined; }; export type Results = { /** * The index of this payroll in the original POST batch array. */ idx?: number | undefined; /** * The UUID of the payroll. */ uuid?: string | undefined; /** * The outcome of cancelling this payroll. A cancel is atomic — there is no per-payroll `partial_success`. * * @remarks * - `success`: the payroll was cancelled, or required no action (already cancelled / never run) * - `failed`: the payroll could not be cancelled; see `errors` */ status?: PayrollBatchResultsResultsStatus | undefined; /** * Present only when `status` is `failed`. A cancel is a single atomic operation, so this is a flat array with exactly one error. */ errors?: Array | undefined; }; /** * The type of entity this exclusion represents. */ export const PayrollBatchResultsEntityType = { Payroll: "payroll", } as const; /** * The type of entity this exclusion represents. */ export type PayrollBatchResultsEntityType = ClosedEnum< typeof PayrollBatchResultsEntityType >; /** * Always `failed` for an excluded payroll. */ export const PayrollBatchResultsExclusionsStatus = { Failed: "failed", } as const; /** * Always `failed` for an excluded payroll. */ export type PayrollBatchResultsExclusionsStatus = ClosedEnum< typeof PayrollBatchResultsExclusionsStatus >; /** * Machine-readable category for why the payroll was excluded. * * @remarks * - `not_found`: the payroll does not exist, or is not associated with a company the partner is mapped to * - `duplicate_operation`: the same payroll UUID appeared more than once in the request; only the first occurrence is processed */ export const PayrollBatchResultsCategory = { NotFound: "not_found", DuplicateOperation: "duplicate_operation", } as const; /** * Machine-readable category for why the payroll was excluded. * * @remarks * - `not_found`: the payroll does not exist, or is not associated with a company the partner is mapped to * - `duplicate_operation`: the same payroll UUID appeared more than once in the request; only the first occurrence is processed */ export type PayrollBatchResultsCategory = ClosedEnum< typeof PayrollBatchResultsCategory >; export type Exclusions = { /** * The index of this payroll in the original POST batch array. */ idx?: number | undefined; /** * The type of entity this exclusion represents. */ entityType?: PayrollBatchResultsEntityType | undefined; /** * The UUID of the excluded payroll. */ uuid?: string | undefined; /** * The UUID of the company asserted to own the payroll. */ companyUuid?: string | undefined; /** * Always `failed` for an excluded payroll. */ status?: PayrollBatchResultsExclusionsStatus | undefined; /** * Machine-readable category for why the payroll was excluded. * * @remarks * - `not_found`: the payroll does not exist, or is not associated with a company the partner is mapped to * - `duplicate_operation`: the same payroll UUID appeared more than once in the request; only the first occurrence is processed */ category?: PayrollBatchResultsCategory | undefined; /** * Human-readable explanation for the exclusion. */ message?: string | undefined; }; /** * A payroll cancellation batch with per-payroll results. */ export type PayrollBatchResults = { /** * The unique identifier of the payroll cancellation batch. */ uuid: string; /** * The idempotency key provided when creating the batch. */ idempotencyKey: string; /** * The lifecycle status of the batch request itself. Terminal values are `completed` (processing finished — inspect `results` and `exclusions` for per-payroll outcomes) and `failed` (the batch crashed at the system level; can be retried). This is distinct from the per-payroll `status` returned inside `results[]`. A `completed` batch does not imply every payroll was cancelled. */ status: PayrollBatchResultsStatus; /** * The timestamp when the batch was submitted. */ submittedAt: Date; /** * The timestamp when the batch processing completed. */ completedAt?: Date | null | undefined; /** * The number of payrolls submitted in the batch. */ submittedItems?: number | null | undefined; /** * The number of payrolls processed (cancelled or attempted). Only present once the batch reaches a terminal status. */ processedItems?: number | undefined; /** * The number of payrolls excluded from processing. Only present once the batch reaches a terminal status. */ excludedItems?: number | undefined; /** * Per-payroll cancellation results. Only present once the batch reaches a terminal status. One entry per authorized payroll. */ results?: Array | undefined; /** * Payrolls that could not be processed, determined at submission time. Only present once the batch reaches a terminal status. Every UUID submitted in the POST batch appears in exactly one of `results` or `exclusions`. */ exclusions?: Array | undefined; }; /** @internal */ export const PayrollBatchResultsStatus$inboundSchema: z.ZodNativeEnum< typeof PayrollBatchResultsStatus > = z.nativeEnum(PayrollBatchResultsStatus); /** @internal */ export const PayrollBatchResultsResultsStatus$inboundSchema: z.ZodNativeEnum< typeof PayrollBatchResultsResultsStatus > = z.nativeEnum(PayrollBatchResultsResultsStatus); /** @internal */ export const PayrollBatchResultsResultsCategory$inboundSchema: z.ZodNativeEnum< typeof PayrollBatchResultsResultsCategory > = z.nativeEnum(PayrollBatchResultsResultsCategory); /** @internal */ export const PayrollBatchResultsErrors$inboundSchema: z.ZodType< PayrollBatchResultsErrors, z.ZodTypeDef, unknown > = z.object({ error_key: z.string().optional(), category: PayrollBatchResultsResultsCategory$inboundSchema.optional(), message: z.string().optional(), }).transform((v) => { return remap$(v, { "error_key": "errorKey", }); }); export function payrollBatchResultsErrorsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => PayrollBatchResultsErrors$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'PayrollBatchResultsErrors' from JSON`, ); } /** @internal */ export const Results$inboundSchema: z.ZodType = z.object({ idx: z.number().int().optional(), uuid: z.string().optional(), status: PayrollBatchResultsResultsStatus$inboundSchema.optional(), errors: z.array(z.lazy(() => PayrollBatchResultsErrors$inboundSchema)) .optional(), }); export function resultsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Results$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Results' from JSON`, ); } /** @internal */ export const PayrollBatchResultsEntityType$inboundSchema: z.ZodNativeEnum< typeof PayrollBatchResultsEntityType > = z.nativeEnum(PayrollBatchResultsEntityType); /** @internal */ export const PayrollBatchResultsExclusionsStatus$inboundSchema: z.ZodNativeEnum< typeof PayrollBatchResultsExclusionsStatus > = z.nativeEnum(PayrollBatchResultsExclusionsStatus); /** @internal */ export const PayrollBatchResultsCategory$inboundSchema: z.ZodNativeEnum< typeof PayrollBatchResultsCategory > = z.nativeEnum(PayrollBatchResultsCategory); /** @internal */ export const Exclusions$inboundSchema: z.ZodType< Exclusions, z.ZodTypeDef, unknown > = z.object({ idx: z.number().int().optional(), entity_type: PayrollBatchResultsEntityType$inboundSchema.optional(), uuid: z.string().optional(), company_uuid: z.string().optional(), status: PayrollBatchResultsExclusionsStatus$inboundSchema.optional(), category: PayrollBatchResultsCategory$inboundSchema.optional(), message: z.string().optional(), }).transform((v) => { return remap$(v, { "entity_type": "entityType", "company_uuid": "companyUuid", }); }); export function exclusionsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Exclusions$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Exclusions' from JSON`, ); } /** @internal */ export const PayrollBatchResults$inboundSchema: z.ZodType< PayrollBatchResults, z.ZodTypeDef, unknown > = z.object({ uuid: z.string(), idempotency_key: z.string(), status: PayrollBatchResultsStatus$inboundSchema, submitted_at: z.string().datetime({ offset: true }).transform(v => new Date(v) ), completed_at: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), submitted_items: z.nullable(z.number().int()).optional(), processed_items: z.number().int().optional(), excluded_items: z.number().int().optional(), results: z.array(z.lazy(() => Results$inboundSchema)).optional(), exclusions: z.array(z.lazy(() => Exclusions$inboundSchema)).optional(), }).transform((v) => { return remap$(v, { "idempotency_key": "idempotencyKey", "submitted_at": "submittedAt", "completed_at": "completedAt", "submitted_items": "submittedItems", "processed_items": "processedItems", "excluded_items": "excludedItems", }); }); export function payrollBatchResultsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => PayrollBatchResults$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'PayrollBatchResults' from JSON`, ); }