/* * 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 { lazySchema as lazySchema$, safeParse } from "../../lib/schemas.js"; import * as openEnums from "../../types/enums.js"; import { OpenEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import * as types from "../../types/primitives.js"; import { smartUnion } from "../../types/smartUnion.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; /** * The outcome for this item. * * @remarks * * - `created` / `updated` — the record was written. * - `failed` — it was not written, and `error` says why. * - `uncertain` — the request to the connector did not complete (typically a timeout), so whether this record was written is genuinely unknown. Do not blindly retry: list the resource to find what exists first, or a retry may duplicate it. * * A `created` or `updated` result can also carry an `error`: the record was written, but work that runs after the write did not complete. * * Read this rather than `id` to decide what happened. `id` is present when the identifier could also be read back, which is not the same question — a written record whose id could not be parsed still reports `created`. */ export const BatchItemResultStatus = { Created: "created", Updated: "updated", Failed: "failed", Uncertain: "uncertain", } as const; /** * The outcome for this item. * * @remarks * * - `created` / `updated` — the record was written. * - `failed` — it was not written, and `error` says why. * - `uncertain` — the request to the connector did not complete (typically a timeout), so whether this record was written is genuinely unknown. Do not blindly retry: list the resource to find what exists first, or a retry may duplicate it. * * A `created` or `updated` result can also carry an `error`: the record was written, but work that runs after the write did not complete. * * Read this rather than `id` to decide what happened. `id` is present when the identifier could also be read back, which is not the same question — a written record whose id could not be parsed still reports `created`. */ export type BatchItemResultStatus = OpenEnum; export type Detail2 = {}; /** * Contains parameter or domain specific information related to the error and why it occurred. */ export type BatchItemResultDetail = string | Detail2; /** * Why this item did not complete. Present when `status` is `failed`, meaning the record was not written, and when `status` is `uncertain`, meaning it is unknown whether it was. Also present, more rarely, alongside `created`/`updated`: the record WAS written and post-write processing failed, so the item reports the error beside its success status. * * @remarks * * Per-item failures are independent — one item's rejection says nothing about the others. The exception is a failure of the request itself, such as a timeout: where a connector writes the whole batch in one call, every item shares that outcome and carries the same error. */ export type ErrorT = { /** * HTTP status code */ statusCode?: number | undefined; /** * Contains an explanation of the status_code as defined in HTTP/1.1 standard (RFC 7231) */ error?: string | undefined; /** * The type of error returned */ typeName?: string | undefined; /** * A human-readable message providing more details about the error. */ message?: string | undefined; /** * Contains parameter or domain specific information related to the error and why it occurred. */ detail?: string | Detail2 | undefined; /** * Link to documentation of error type */ ref?: string | undefined; }; export type BatchItemResultWarnings = { type?: string | undefined; operation?: string | undefined; message?: string | undefined; statusCode?: number | undefined; error?: string | undefined; }; export type BatchItemResult = { /** * A caller-supplied reference for this item, echoed back on the matching result so each outcome can be tied to the record it came from. Must be unique within the request. Never sent to the connector. */ ref?: string | undefined; /** * A unique identifier for an object. */ id?: string | undefined; /** * The third-party API ID of original entity */ downstreamId?: string | null | undefined; /** * The outcome for this item. * * @remarks * * - `created` / `updated` — the record was written. * - `failed` — it was not written, and `error` says why. * - `uncertain` — the request to the connector did not complete (typically a timeout), so whether this record was written is genuinely unknown. Do not blindly retry: list the resource to find what exists first, or a retry may duplicate it. * * A `created` or `updated` result can also carry an `error`: the record was written, but work that runs after the write did not complete. * * Read this rather than `id` to decide what happened. `id` is present when the identifier could also be read back, which is not the same question — a written record whose id could not be parsed still reports `created`. */ status: BatchItemResultStatus; /** * Why this item did not complete. Present when `status` is `failed`, meaning the record was not written, and when `status` is `uncertain`, meaning it is unknown whether it was. Also present, more rarely, alongside `created`/`updated`: the record WAS written and post-write processing failed, so the item reports the error beside its success status. * * @remarks * * Per-item failures are independent — one item's rejection says nothing about the others. The exception is a failure of the request itself, such as a timeout: where a connector writes the whole batch in one call, every item shares that outcome and carries the same error. */ error?: ErrorT | undefined; /** * Non-fatal problems with THIS item — a currency the connector could not match, for example, which is sent without it. Present per item rather than per request, because a caller with twenty records needs to know which one was affected. * * @remarks * * A warning does not imply the record was written: some are raised while preparing the item, before the write is attempted, so they can appear on a `failed` item too. Read `status` for what happened. */ warnings?: Array | undefined; }; /** @internal */ export const BatchItemResultStatus$inboundSchema: z.ZodType< BatchItemResultStatus, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => openEnums.inboundSchema(BatchItemResultStatus) ); /** @internal */ export const Detail2$inboundSchema: z.ZodType = /* @__PURE__ */ lazySchema$(() => z.object({})); export function detail2FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Detail2$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Detail2' from JSON`, ); } /** @internal */ export const BatchItemResultDetail$inboundSchema: z.ZodType< BatchItemResultDetail, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => smartUnion([types.string(), z.lazy(() => Detail2$inboundSchema)]) ); export function batchItemResultDetailFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => BatchItemResultDetail$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'BatchItemResultDetail' from JSON`, ); } /** @internal */ export const ErrorT$inboundSchema: z.ZodType = /* @__PURE__ */ lazySchema$(() => z.object({ status_code: types.optional(types.number()), error: types.optional(types.string()), type_name: types.optional(types.string()), message: types.optional(types.string()), detail: types.optional( smartUnion([types.string(), z.lazy(() => Detail2$inboundSchema)]), ), ref: types.optional(types.string()), }).transform((v) => { return remap$(v, { "status_code": "statusCode", "type_name": "typeName", }); }) ); export function errorFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ErrorT$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ErrorT' from JSON`, ); } /** @internal */ export const BatchItemResultWarnings$inboundSchema: z.ZodType< BatchItemResultWarnings, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => z.object({ type: types.optional(types.string()), operation: types.optional(types.string()), message: types.optional(types.string()), status_code: types.optional(types.number()), error: types.optional(types.string()), }).transform((v) => { return remap$(v, { "status_code": "statusCode", }); }) ); export function batchItemResultWarningsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => BatchItemResultWarnings$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'BatchItemResultWarnings' from JSON`, ); } /** @internal */ export const BatchItemResult$inboundSchema: z.ZodType< BatchItemResult, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => z.object({ _ref: types.optional(types.string()), id: types.optional(types.string()), downstream_id: z.nullable(types.string()).optional(), status: BatchItemResultStatus$inboundSchema, error: types.optional(z.lazy(() => ErrorT$inboundSchema)), warnings: types.optional( z.array(z.lazy(() => BatchItemResultWarnings$inboundSchema)), ), }).transform((v) => { return remap$(v, { "_ref": "ref", "downstream_id": "downstreamId", }); }) ); export function batchItemResultFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => BatchItemResult$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'BatchItemResult' from JSON`, ); }