import {z} from 'zod' export type GetApiV1PortfoliosSharedOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const listingNotice = z.object({status: z.string().nullable().optional(), ticker: z.string().nullable().optional(), delistedOn: z.string().nullable().optional(), successorTicker: z.string().nullable().optional()}); export const portfolioSummaryDto = z.object({id: z.string().optional(), name: z.string().nullable().optional(), currency: z.string().nullable().optional(), openLotCount: z.number().int().optional(), closedLotCount: z.number().int().optional(), createdAtUtc: z.string().optional(), access: z.string().nullable().optional(), sharedBy: z.string().nullable().optional()}); export const portfolioSummaryDtoListResponse = z.object({listingNotice: listingNotice.optional(), data: z.array(portfolioSummaryDto).nullable().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 }; /** * Portfolios colleagues shared with your organization, with what you may do with each and * who shared it. Unpriced, like your own list; fetch one by id to have it valued. * * GET /v1/portfolios/shared */ export const getApiV1PortfoliosShared = async (options?: GetApiV1PortfoliosSharedOptions) => { const {baseUrl = "https://api.equibles.com", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/portfolios/shared${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(portfolioSummaryDtoListResponse, await res.json()) };