import {z} from 'zod' export type GetApiVisV2OrgsOrgIdExportsArgs = {filter?: string | undefined, skipToken?: string | undefined, orgId: number}; export type GetApiVisV2OrgsOrgIdExportsOptions = {baseUrl?: string | undefined, JWTAuthHeaderAuthorization?: string | undefined, fetch?: typeof fetch | undefined}; export const flexeraVisFiledata = z.object({createdAt: z.string().optional(), id: z.string().max(36).optional(), name: z.string().optional(), size: z.number().int().optional(), type: z.enum(["snapshot", "delta"]).optional()}); export const exportDataCollection = z.array(flexeraVisFiledata); export const exportFileList = z.object({count: z.number().int().optional(), nextPage: z.string().optional(), prevPage: z.string().optional(), values: exportDataCollection.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 }; /** * List all inventory exports * * GET /vis/v2/orgs/{orgId}/exports */ export const getApiVisV2OrgsOrgIdExports = async (args: GetApiVisV2OrgsOrgIdExportsArgs, options?: GetApiVisV2OrgsOrgIdExportsOptions) => { const {baseUrl = "https://api.flexera.com", fetch: fetchFn = fetch, JWTAuthHeaderAuthorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.filter != null) query.append("filter", String(args.filter)) if (args.skipToken != null) query.append("skipToken", String(args.skipToken)) if (JWTAuthHeaderAuthorization !== undefined) headers.set('authorization', `Bearer ${JWTAuthHeaderAuthorization}`) const url = `${baseUrl.replace(/\/+$/, '')}/vis/v2/orgs/${encodeURIComponent(String(args.orgId))}/exports${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(exportFileList, await res.json()) };