/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v4-mini"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { Customer, Customer$inboundSchema } from "./customer.js"; import { CustomerCreatedMetadata, CustomerCreatedMetadata$inboundSchema, } from "./customercreatedmetadata.js"; /** * An event created by Polar when a customer is created. */ export type CustomerCreatedEvent = { /** * The ID of the object. */ id: string; /** * The timestamp of the event. */ timestamp: Date; /** * The ID of the organization owning the event. */ organizationId: string; /** * ID of the customer in your Polar organization associated with the event. */ customerId: string | null; /** * The customer associated with the event. */ customer: Customer | null; /** * ID of the customer in your system associated with the event. */ externalCustomerId: string | null; /** * ID of the member within the customer's organization who performed the action inside B2B. */ memberId?: string | null | undefined; /** * ID of the member in your system within the customer's organization who performed the action inside B2B. */ externalMemberId?: string | null | undefined; /** * Number of direct child events linked to this event. */ childCount: number; /** * The ID of the parent event. */ parentId?: string | null | undefined; /** * Human readable label of the event type. */ label: string; /** * The source of the event. `system` events are created by Polar. `user` events are the one you create through our ingestion API. */ source: "system"; /** * The name of the event. */ name: "customer.created"; metadata: CustomerCreatedMetadata; }; /** @internal */ export const CustomerCreatedEvent$inboundSchema: z.ZodMiniType< CustomerCreatedEvent, unknown > = z.pipe( z.object({ id: z.string(), timestamp: z.pipe( z.iso.datetime({ offset: true }), z.transform(v => new Date(v)), ), organization_id: z.string(), customer_id: z.nullable(z.string()), customer: z.nullable(Customer$inboundSchema), external_customer_id: z.nullable(z.string()), member_id: z.optional(z.nullable(z.string())), external_member_id: z.optional(z.nullable(z.string())), child_count: z._default(z.int(), 0), parent_id: z.optional(z.nullable(z.string())), label: z.string(), source: z.literal("system"), name: z.literal("customer.created"), metadata: CustomerCreatedMetadata$inboundSchema, }), z.transform((v) => { return remap$(v, { "organization_id": "organizationId", "customer_id": "customerId", "external_customer_id": "externalCustomerId", "member_id": "memberId", "external_member_id": "externalMemberId", "child_count": "childCount", "parent_id": "parentId", }); }), ); export function customerCreatedEventFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CustomerCreatedEvent$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CustomerCreatedEvent' from JSON`, ); }