/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { RFCDate } from "../../types/rfcdate.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { Currency, Currency$inboundSchema, Currency$outboundSchema, } from "./currency.js"; import { CustomField, CustomField$inboundSchema, CustomField$Outbound, CustomField$outboundSchema, } from "./customfield.js"; import { CustomMappings, CustomMappings$inboundSchema, CustomMappings$Outbound, CustomMappings$outboundSchema, } from "./custommappings.js"; import { PassThroughBody, PassThroughBody$inboundSchema, PassThroughBody$Outbound, PassThroughBody$outboundSchema, } from "./passthroughbody.js"; export type Opportunity = { /** * A unique identifier for the opportunity. */ id?: string | undefined; /** * The title or name of the opportunity. */ title: string; /** * The unique identifier of the primary contact associated with the opportunity. */ primaryContactId: string | null; /** * A description of the opportunity. */ description?: string | null | undefined; /** * The type of the opportunity */ type?: string | null | undefined; /** * The monetary value associated with the opportunity */ monetaryAmount?: number | null | undefined; /** * Indicates the associated currency for an amount of money. Values correspond to [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217). */ currency?: Currency | null | undefined; /** * The probability of winning the opportunity, expressed as a percentage. */ winProbability?: number | null | undefined; /** * The expected revenue from the opportunity */ expectedRevenue?: number | null | undefined; /** * The actual closing date for the opportunity. If close_date is null, the opportunity is not closed yet. */ closeDate?: RFCDate | null | undefined; /** * The unique identifier of the reason why the opportunity was lost. */ lossReasonId?: string | null | undefined; /** * The reason why the opportunity was lost. */ lossReason?: string | null | undefined; /** * The unique identifier of the reason why the opportunity was won. */ wonReasonId?: string | null | undefined; /** * The reason why the opportunity was won. */ wonReason?: string | null | undefined; /** * The unique identifier of the pipeline associated with the opportunity */ pipelineId?: string | null | undefined; /** * The unique identifier of the stage in the pipeline associated with the opportunity. */ pipelineStageId?: string | null | undefined; /** * The unique identifier of the source of the opportunity. */ sourceId?: string | null | undefined; /** * The unique identifier of the lead associated with the opportunity. */ leadId?: string | null | undefined; /** * The source of the lead associated with the opportunity. */ leadSource?: string | null | undefined; /** * The unique identifier of the contact associated with the opportunity. */ contactId?: string | null | undefined; /** * An array of unique identifiers of all contacts associated with the opportunity. */ contactIds?: Array | undefined; /** * The unique identifier of the company associated with the opportunity. */ companyId?: string | null | undefined; /** * The name of the company associated with the opportunity. */ companyName?: string | null | undefined; /** * The unique identifier of the user who owns the opportunity. */ ownerId?: string | null | undefined; /** * The priority level of the opportunity. */ priority?: string | null | undefined; /** * The current status of the opportunity. */ status?: string | null | undefined; /** * The unique identifier of the current status of the opportunity. */ statusId?: string | null | undefined; tags?: Array | null | undefined; /** * The number of interactions with the opportunity. */ interactionCount?: number | null | undefined; customFields?: Array | undefined; /** * The date and time when the stage of the opportunity was last changed. */ stageLastChangedAt?: Date | null | undefined; /** * The date and time of the last activity associated with the opportunity. */ lastActivityAt?: string | null | undefined; /** * Indicates whether the opportunity has been deleted. */ deleted?: boolean | undefined; /** * The date and time when the stage of the opportunity was last changed. */ dateStageChanged?: Date | null | undefined; /** * The date and time when the opportunity was last contacted. */ dateLastContacted?: Date | null | undefined; /** * The date and time when the lead associated with the opportunity was created. */ dateLeadCreated?: Date | null | undefined; /** * When custom mappings are configured on the resource, the result is included here. */ customMappings?: CustomMappings | null | undefined; /** * The unique identifier of the user who last updated the opportunity. */ updatedBy?: string | null | undefined; /** * The unique identifier of the user who created the opportunity. */ createdBy?: string | null | undefined; /** * The date and time when the opportunity was last updated. */ updatedAt?: Date | null | undefined; /** * The date and time when the opportunity was created. */ createdAt?: Date | null | undefined; /** * The pass_through property allows passing service-specific, custom data or structured modifications in request body when creating or updating resources. */ passThrough?: Array | undefined; }; /** @internal */ export const Opportunity$inboundSchema: z.ZodType< Opportunity, z.ZodTypeDef, unknown > = z.object({ id: z.string().optional(), title: z.string(), primary_contact_id: z.nullable(z.string()), description: z.nullable(z.string()).optional(), type: z.nullable(z.string()).optional(), monetary_amount: z.nullable(z.number()).optional(), currency: z.nullable(Currency$inboundSchema).optional(), win_probability: z.nullable(z.number()).optional(), expected_revenue: z.nullable(z.number()).optional(), close_date: z.nullable(z.string().transform(v => new RFCDate(v))).optional(), loss_reason_id: z.nullable(z.string()).optional(), loss_reason: z.nullable(z.string()).optional(), won_reason_id: z.nullable(z.string()).optional(), won_reason: z.nullable(z.string()).optional(), pipeline_id: z.nullable(z.string()).optional(), pipeline_stage_id: z.nullable(z.string()).optional(), source_id: z.nullable(z.string()).optional(), lead_id: z.nullable(z.string()).optional(), lead_source: z.nullable(z.string()).optional(), contact_id: z.nullable(z.string()).optional(), contact_ids: z.array(z.string()).optional(), company_id: z.nullable(z.string()).optional(), company_name: z.nullable(z.string()).optional(), owner_id: z.nullable(z.string()).optional(), priority: z.nullable(z.string()).optional(), status: z.nullable(z.string()).optional(), status_id: z.nullable(z.string()).optional(), tags: z.nullable(z.array(z.string())).optional(), interaction_count: z.nullable(z.number()).optional(), custom_fields: z.array(CustomField$inboundSchema).optional(), stage_last_changed_at: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), last_activity_at: z.nullable(z.string()).optional(), deleted: z.boolean().optional(), date_stage_changed: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), date_last_contacted: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), date_lead_created: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), custom_mappings: z.nullable(CustomMappings$inboundSchema).optional(), updated_by: z.nullable(z.string()).optional(), created_by: z.nullable(z.string()).optional(), updated_at: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), created_at: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), pass_through: z.array(PassThroughBody$inboundSchema).optional(), }).transform((v) => { return remap$(v, { "primary_contact_id": "primaryContactId", "monetary_amount": "monetaryAmount", "win_probability": "winProbability", "expected_revenue": "expectedRevenue", "close_date": "closeDate", "loss_reason_id": "lossReasonId", "loss_reason": "lossReason", "won_reason_id": "wonReasonId", "won_reason": "wonReason", "pipeline_id": "pipelineId", "pipeline_stage_id": "pipelineStageId", "source_id": "sourceId", "lead_id": "leadId", "lead_source": "leadSource", "contact_id": "contactId", "contact_ids": "contactIds", "company_id": "companyId", "company_name": "companyName", "owner_id": "ownerId", "status_id": "statusId", "interaction_count": "interactionCount", "custom_fields": "customFields", "stage_last_changed_at": "stageLastChangedAt", "last_activity_at": "lastActivityAt", "date_stage_changed": "dateStageChanged", "date_last_contacted": "dateLastContacted", "date_lead_created": "dateLeadCreated", "custom_mappings": "customMappings", "updated_by": "updatedBy", "created_by": "createdBy", "updated_at": "updatedAt", "created_at": "createdAt", "pass_through": "passThrough", }); }); /** @internal */ export type Opportunity$Outbound = { id?: string | undefined; title: string; primary_contact_id: string | null; description?: string | null | undefined; type?: string | null | undefined; monetary_amount?: number | null | undefined; currency?: string | null | undefined; win_probability?: number | null | undefined; expected_revenue?: number | null | undefined; close_date?: string | null | undefined; loss_reason_id?: string | null | undefined; loss_reason?: string | null | undefined; won_reason_id?: string | null | undefined; won_reason?: string | null | undefined; pipeline_id?: string | null | undefined; pipeline_stage_id?: string | null | undefined; source_id?: string | null | undefined; lead_id?: string | null | undefined; lead_source?: string | null | undefined; contact_id?: string | null | undefined; contact_ids?: Array | undefined; company_id?: string | null | undefined; company_name?: string | null | undefined; owner_id?: string | null | undefined; priority?: string | null | undefined; status?: string | null | undefined; status_id?: string | null | undefined; tags?: Array | null | undefined; interaction_count?: number | null | undefined; custom_fields?: Array | undefined; stage_last_changed_at?: string | null | undefined; last_activity_at?: string | null | undefined; deleted?: boolean | undefined; date_stage_changed?: string | null | undefined; date_last_contacted?: string | null | undefined; date_lead_created?: string | null | undefined; custom_mappings?: CustomMappings$Outbound | null | undefined; updated_by?: string | null | undefined; created_by?: string | null | undefined; updated_at?: string | null | undefined; created_at?: string | null | undefined; pass_through?: Array | undefined; }; /** @internal */ export const Opportunity$outboundSchema: z.ZodType< Opportunity$Outbound, z.ZodTypeDef, Opportunity > = z.object({ id: z.string().optional(), title: z.string(), primaryContactId: z.nullable(z.string()), description: z.nullable(z.string()).optional(), type: z.nullable(z.string()).optional(), monetaryAmount: z.nullable(z.number()).optional(), currency: z.nullable(Currency$outboundSchema).optional(), winProbability: z.nullable(z.number()).optional(), expectedRevenue: z.nullable(z.number()).optional(), closeDate: z.nullable(z.instanceof(RFCDate).transform(v => v.toString())) .optional(), lossReasonId: z.nullable(z.string()).optional(), lossReason: z.nullable(z.string()).optional(), wonReasonId: z.nullable(z.string()).optional(), wonReason: z.nullable(z.string()).optional(), pipelineId: z.nullable(z.string()).optional(), pipelineStageId: z.nullable(z.string()).optional(), sourceId: z.nullable(z.string()).optional(), leadId: z.nullable(z.string()).optional(), leadSource: z.nullable(z.string()).optional(), contactId: z.nullable(z.string()).optional(), contactIds: z.array(z.string()).optional(), companyId: z.nullable(z.string()).optional(), companyName: z.nullable(z.string()).optional(), ownerId: z.nullable(z.string()).optional(), priority: z.nullable(z.string()).optional(), status: z.nullable(z.string()).optional(), statusId: z.nullable(z.string()).optional(), tags: z.nullable(z.array(z.string())).optional(), interactionCount: z.nullable(z.number()).optional(), customFields: z.array(CustomField$outboundSchema).optional(), stageLastChangedAt: z.nullable(z.date().transform(v => v.toISOString())) .optional(), lastActivityAt: z.nullable(z.string()).optional(), deleted: z.boolean().optional(), dateStageChanged: z.nullable(z.date().transform(v => v.toISOString())) .optional(), dateLastContacted: z.nullable(z.date().transform(v => v.toISOString())) .optional(), dateLeadCreated: z.nullable(z.date().transform(v => v.toISOString())) .optional(), customMappings: z.nullable(CustomMappings$outboundSchema).optional(), updatedBy: z.nullable(z.string()).optional(), createdBy: z.nullable(z.string()).optional(), updatedAt: z.nullable(z.date().transform(v => v.toISOString())).optional(), createdAt: z.nullable(z.date().transform(v => v.toISOString())).optional(), passThrough: z.array(PassThroughBody$outboundSchema).optional(), }).transform((v) => { return remap$(v, { primaryContactId: "primary_contact_id", monetaryAmount: "monetary_amount", winProbability: "win_probability", expectedRevenue: "expected_revenue", closeDate: "close_date", lossReasonId: "loss_reason_id", lossReason: "loss_reason", wonReasonId: "won_reason_id", wonReason: "won_reason", pipelineId: "pipeline_id", pipelineStageId: "pipeline_stage_id", sourceId: "source_id", leadId: "lead_id", leadSource: "lead_source", contactId: "contact_id", contactIds: "contact_ids", companyId: "company_id", companyName: "company_name", ownerId: "owner_id", statusId: "status_id", interactionCount: "interaction_count", customFields: "custom_fields", stageLastChangedAt: "stage_last_changed_at", lastActivityAt: "last_activity_at", dateStageChanged: "date_stage_changed", dateLastContacted: "date_last_contacted", dateLeadCreated: "date_lead_created", customMappings: "custom_mappings", updatedBy: "updated_by", createdBy: "created_by", updatedAt: "updated_at", createdAt: "created_at", passThrough: "pass_through", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace Opportunity$ { /** @deprecated use `Opportunity$inboundSchema` instead. */ export const inboundSchema = Opportunity$inboundSchema; /** @deprecated use `Opportunity$outboundSchema` instead. */ export const outboundSchema = Opportunity$outboundSchema; /** @deprecated use `Opportunity$Outbound` instead. */ export type Outbound = Opportunity$Outbound; } export function opportunityToJSON(opportunity: Opportunity): string { return JSON.stringify(Opportunity$outboundSchema.parse(opportunity)); } export function opportunityFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Opportunity$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Opportunity' from JSON`, ); }