import {z} from 'zod' export type PatchApiOrganizationsIdArgs = {id: string, 'if-match': string, body: {name?: string | undefined, website?: (string | null) | undefined, linkedin?: (string | null) | undefined, address?: ({region?: string | undefined, country: string, formatted?: string | undefined, street_address?: string | undefined, locality?: string | undefined, postal_code?: string | undefined} | null) | undefined, legal_structure?: ('sole_proprietor' | 'single_member_llc' | 'limited_liability_company' | 'general_partnership' | 'unlisted_corporation' | 'publicly_traded_corporation' | 'association' | 'non_profit' | 'government_organization' | 'revocable_trust' | 'irrevocable_trust' | 'estate' | 'null' | null) | undefined, industry?: (string | null) | undefined, formation_date?: (string | null) | undefined, size?: ('1-24' | '25-99' | '100-499' | '500+' | 'null' | null) | undefined, yc_id?: ('no' | 'claimed' | 'null' | null) | undefined, yc_url?: (string | null) | undefined}}; export type PatchApiOrganizationsIdOptions = {baseUrl?: string | undefined, APIKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiOrganizationsIdResponse = z.object({name: z.string().min(1), website: z.string().optional(), linkedin: z.string().optional(), address: z.object({region: z.string().min(1).optional(), country: z.string(), formatted: z.string().min(1).optional(), street_address: z.string().min(1).optional(), locality: z.string().min(1).optional(), postal_code: z.string().min(1).optional()}).optional(), legal_structure: z.enum(["sole_proprietor", "single_member_llc", "limited_liability_company", "general_partnership", "unlisted_corporation", "publicly_traded_corporation", "association", "non_profit", "government_organization", "revocable_trust", "irrevocable_trust", "estate"]).optional(), industry: z.string().optional(), formation_date: z.string().optional(), size: z.enum(["1-24", "25-99", "100-499", "500+"]).optional(), yc_id: z.union([z.string(), z.enum(["no", "claimed"])]).optional(), aiprise_business_id: z.string().optional(), monato_business_id: z.string().optional(), picture: z.string(), id: z.string(), created_at: z.string(), created_by: z.string(), updated_at: z.string(), updated_by: z.string()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update an organization * * PATCH /organizations/{id} * * Also accepts auth: OAuth2 */ export const patchApiOrganizationsId = async (args: PatchApiOrganizationsIdArgs, options?: PatchApiOrganizationsIdOptions) => { const {baseUrl = "https://core.sivo.com", fetch: fetchFn = fetch, APIKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['if-match'] != null) headers.set("if-match", String(args['if-match'])) if (APIKeyAuth !== undefined) headers.set("Authorization", APIKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/organizations/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(patchApiOrganizationsIdResponse, await res.json()) };