import {z} from 'zod' export type GetApiV1OrgOrgIdStockgrantStockGrantIdArgs = {orgId: string, stockGrantId: string}; export type GetApiV1OrgOrgIdStockgrantStockGrantIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const stockGrantEntity = z.object({id: z.string(), orgId: z.string(), personId: z.string(), externalId: z.string().optional(), stock: z.string(), date: z.string(), vestStartDate: z.string().optional(), expireDate: z.string().optional(), shares: z.number(), price: z.number(), type: z.enum(["ISO", "NSO", "RSU", "SAR", "PERFORMANCE_SHARES", "PHANTOM_STOCK", "RSA"]), vestSchedule: z.string(), originalPrice: z.number().optional(), currentPrice: z.number().optional(), vestedShares: z.number().optional(), vestedSharesNextYear: z.number().optional(), vestedSharesByDate: z.record(z.string(), z.number()).optional(), vestEndDate: z.string().optional(), cancelDate: z.string().optional(), terminationDate: z.string().optional(), lastExercisableDate: z.string().optional(), details: z.string().optional(), createId: z.string().optional(), createAt: z.string().optional(), updateAt: z.string().optional(), updateId: z.string().optional(), deleteId: z.string().optional(), deleteAt: z.string().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 }; /** * Return a particular stock grant by id * * GET /v1/org/{orgId}/stockgrant/{stockGrantId} */ export const getApiV1OrgOrgIdStockgrantStockGrantId = async (args: GetApiV1OrgOrgIdStockgrantStockGrantIdArgs, options?: GetApiV1OrgOrgIdStockgrantStockGrantIdOptions) => { const {baseUrl = "https://localhost", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/org/${encodeURIComponent(String(args.orgId))}/stockgrant/${encodeURIComponent(String(args.stockGrantId))}${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(stockGrantEntity, await res.json()) };