import {z} from 'zod' export type GetApiEnvironmentsEnvironmentIDSnapshotsSnapshotIDVersionsArgs = {environmentID: string, snapshotID: string, 'X-Ping-External-Session-ID'?: string | undefined, 'X-Ping-External-Transaction-ID'?: string | undefined}; export type GetApiEnvironmentsEnvironmentIDSnapshotsSnapshotIDVersionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const comPingidentityApiResponseLink = z.object({href: z.string().min(1), name: z.string().optional(), profile: z.string().optional(), title: z.string().optional(), type: z.string().optional()}); export const comPingidentityApiRelationshipPingOneRO = z.object({id: z.string().min(1)}); export const comPingidentityPingoneConfigmanagementSnapshotsDataResourceInformation = z.object({category: z.string().optional(), id: z.string().optional(), name: z.string().optional()}); export const comPingidentityPingoneConfigmanagementSnapshotsDataSnapshotView = z.object({_embedded: z.record(z.string(), z.object({})).optional(), _links: z.object({self: comPingidentityApiResponseLink.optional()}).and(z.record(z.string(), comPingidentityApiResponseLink)).optional(), completedAt: z.string().optional(), configuration: z.string().optional(), createdAt: z.string().optional(), environment: comPingidentityApiRelationshipPingOneRO.optional(), error: z.string().optional(), errorCode: z.number().int().optional(), id: z.string().optional(), importMetadata: z.record(z.string(), z.object({})).optional(), referencedResources: z.array(z.string()).optional(), resource: comPingidentityPingoneConfigmanagementSnapshotsDataResourceInformation.optional(), resourceUrl: z.string().optional(), snapshotId: z.string().optional(), startedAt: z.string().optional(), status: z.enum(["COMPLETE", "ERROR", "IN_PROGRESS", "WAITING"]).optional(), versionedAt: z.string().optional()}); export const comPingidentityPingoneConfigmanagementSnapshotsDataSnapshotsVersionsResponse = z.object({_embedded: z.object({versions: z.array(comPingidentityPingoneConfigmanagementSnapshotsDataSnapshotView).optional()}).optional(), _links: z.object({self: comPingidentityApiResponseLink.optional()}).and(z.record(z.string(), comPingidentityApiResponseLink)).optional(), count: z.number().int().optional(), size: z.number().int().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 }; /** * GET /environments/{environmentID}/snapshots/{snapshotID}/versions */ export const getApiEnvironmentsEnvironmentIDSnapshotsSnapshotIDVersions = async (args: GetApiEnvironmentsEnvironmentIDSnapshotsSnapshotIDVersionsArgs, options?: GetApiEnvironmentsEnvironmentIDSnapshotsSnapshotIDVersionsOptions) => { const {baseUrl = "https://api.pingone.com/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Ping-External-Session-ID'] != null) headers.set("X-Ping-External-Session-ID", String(args['X-Ping-External-Session-ID'])) if (args['X-Ping-External-Transaction-ID'] != null) headers.set("X-Ping-External-Transaction-ID", String(args['X-Ping-External-Transaction-ID'])) const url = `${baseUrl.replace(/\/+$/, '')}/environments/${encodeURIComponent(String(args.environmentID))}/snapshots/${encodeURIComponent(String(args.snapshotID))}/versions${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(comPingidentityPingoneConfigmanagementSnapshotsDataSnapshotsVersionsResponse, await res.json()) };