import {z} from 'zod' export type GetApiApiV1SecInsiderTransactionsOwnersArgs = {page?: number | undefined, pagesize?: number | undefined, date_from?: string | undefined, date_to?: string | undefined, updated_since?: number | undefined, date?: string | undefined, chamber?: ('House' | 'Senate') | undefined, fields?: string | undefined, search_keys_type?: ('symbol' | 'cik' | 'name_fuzzy' | 'name_starts_with') | undefined, search_keys?: string | undefined, display?: ('flat' | 'nested') | undefined}; export type GetApiApiV1SecInsiderTransactionsOwnersOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiSECFootnotes = z.object({id: z.string().optional(), text: z.string().optional()}); export const gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiOwner = z.object({insider_cik: z.string().optional(), insider_name: z.string().optional(), insider_title: z.string().optional(), is_director: z.boolean().optional(), is_officer: z.boolean().optional(), is_ten_percent_owner: z.boolean().optional(), raw_signature: z.string().optional()}); export const gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiTransaction = z.object({acquired_or_disposed: z.string().optional(), conversion_exercise_price_derivative: z.string().optional(), date_deemed_execution: z.string().optional(), date_exercisable: z.string().optional(), date_expiration: z.string().optional(), date_transaction: z.string().optional(), is_derivative: z.boolean().optional(), ownership: z.string().optional(), post_transaction_quantity: z.string().optional(), price_per_share: z.string().optional(), remaining_underlying_shares: z.string().optional(), security_title: z.string().optional(), shares: z.string().optional(), transaction_code: z.string().optional(), transaction_id: z.string().optional(), underlying_security_title: z.string().optional(), underlying_shares: z.string().optional(), voluntarily_reported: z.boolean().optional()}); export const gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiInsiderTransaction = z.object({accession_number: z.string().optional(), company_cik: z.string().optional(), company_name: z.string().optional(), company_symbol: z.string().optional(), filing_date: z.string().optional(), footnotes: z.array(gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiSECFootnotes).optional(), form_type: z.string().optional(), html_url: z.string().optional(), id: z.string().optional(), is_10b5: z.boolean().optional(), owner: gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiOwner.optional(), remaining_shares: z.string().optional(), remaining_underlying_shares: z.string().optional(), traded_percentage: z.string().optional(), transactions: z.array(gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiTransaction).optional(), updated: z.number().int().optional()}); export const gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiInsiderTransactionFilingDoc = z.object({data: z.array(gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiInsiderTransaction).optional()}); 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 }; /** * Insider Transaction Owner * * GET /api/v1/sec/insider_transactions/owners */ export const getApiApiV1SecInsiderTransactionsOwners = async (args: GetApiApiV1SecInsiderTransactionsOwnersArgs, options?: GetApiApiV1SecInsiderTransactionsOwnersOptions) => { const {baseUrl = "https://api.benzinga.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.pagesize != null) query.append("pagesize", String(args.pagesize)) if (args.date_from != null) query.append("date_from", String(args.date_from)) if (args.date_to != null) query.append("date_to", String(args.date_to)) if (args.updated_since != null) query.append("updated_since", String(args.updated_since)) if (args.date != null) query.append("date", String(args.date)) if (args.chamber != null) query.append("chamber", String(args.chamber)) if (args.fields != null) query.append("fields", String(args.fields)) if (args.search_keys_type != null) query.append("search_keys_type", String(args.search_keys_type)) if (args.search_keys != null) query.append("search_keys", String(args.search_keys)) if (args.display != null) query.append("display", String(args.display)) if (ApiKeyAuth !== undefined) headers.set("Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/sec/insider_transactions/owners${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiInsiderTransactionFilingDoc, await res.json()) };