import {z} from 'zod' export type B037OrganizationInvestmentRequest = {offset?: number | undefined, limit?: number | undefined, organization_id?: string | undefined}; export type CreateApiSynapseOrganizationInvestmentArgs = {body: B037OrganizationInvestmentRequest}; export type CreateApiSynapseOrganizationInvestmentOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const b037OrganizationInvestmentCommonName = z.object({lang: z.string().optional(), name: z.string().optional()}); export const b037OrganizationInvestmentCommonOrganization = z.object({display_name: z.array(b037OrganizationInvestmentCommonName).optional(), organization_id: z.string().optional()}); export const b037OrganizationInvestmentFundingTypeDto = z.object({classification: z.string().optional(), classification_en: z.string().optional()}); export const b037OrganizationInvestmentMoneyRaised = z.object({value_cny: z.number().optional(), value_usd: z.number().optional(), original_value: z.number().optional(), original_currency: z.string().optional()}); export const b037OrganizationInvestmentFundingRoundDto = z.object({investors: z.array(b037OrganizationInvestmentCommonOrganization).optional(), funding_type: b037OrganizationInvestmentFundingTypeDto.optional(), announced_time: z.number().int().optional(), funded_organization: b037OrganizationInvestmentCommonOrganization.optional(), transaction_amount_lower: b037OrganizationInvestmentMoneyRaised.optional(), transaction_amount_upper: b037OrganizationInvestmentMoneyRaised.optional(), original_transaction_amount: z.string().optional()}); export const b037OrganizationInvestmentGetOrganizationInvestmentResponseDto = z.object({items: z.array(b037OrganizationInvestmentFundingRoundDto).optional(), limit: z.number().int().optional(), total: z.number().int().optional(), offset: z.number().int().optional()}); export const b037OrganizationInvestmentResponse = z.object({data: b037OrganizationInvestmentGetOrganizationInvestmentResponseDto.optional(), status: z.boolean(), error_msg: z.string().optional(), error_code: z.number().int()}); 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 }; /** * B037 Investment * * POST /synapse/organization/investment */ export const createApiSynapseOrganizationInvestment = async (args: CreateApiSynapseOrganizationInvestmentArgs, options?: CreateApiSynapseOrganizationInvestmentOptions) => { const {baseUrl = "https://connect.patsnap.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/synapse/organization/investment${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(b037OrganizationInvestmentResponse, await res.json()) };