import {z} from 'zod' export type GetApiV2StorageComponentsComponentIdConfigsConfigurationIdVersionsArgs = {componentId: string, configurationId: string, include?: (string | null) | undefined, limit?: (number | null) | undefined, offset?: (number | null) | undefined}; export type GetApiV2StorageComponentsComponentIdConfigsConfigurationIdVersionsOptions = {baseUrl?: string | undefined, StorageKey?: string | undefined, fetch?: typeof fetch | undefined}; export const configurationCreatorTokenResponse = z.object({id: z.number().int(), description: z.string().nullable()}); export const actorResponse = z.object({type: z.enum(["token", "session", "pat", "system"]), id: z.string(), name: z.string(), adminId: z.number().int().nullable()}); export const configurationVersionListItemResponse = z.object({version: z.number().int(), created: z.string(), versionIdentifier: z.string().nullable(), creatorToken: configurationCreatorTokenResponse, actor: actorResponse.nullable(), changeDescription: z.string().nullable(), isDisabled: z.boolean(), isDeleted: z.boolean(), name: z.string().optional(), description: z.string().nullable().optional(), configuration: z.record(z.string(), z.unknown()).optional()}); export const getApiV2StorageComponentsComponentIdConfigsConfigurationIdVersionsResponse = z.array(configurationVersionListItemResponse); 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 }; /** * Versions list * * GET /v2/storage/components/{componentId}/configs/{configurationId}/versions * * Also accepts auth: ManageKey, BearerAuth */ export const getApiV2StorageComponentsComponentIdConfigsConfigurationIdVersions = async (args: GetApiV2StorageComponentsComponentIdConfigsConfigurationIdVersionsArgs, options?: GetApiV2StorageComponentsComponentIdConfigsConfigurationIdVersionsOptions) => { const {baseUrl = "https://connection.keboola.com", fetch: fetchFn = fetch, StorageKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.include != null) query.append("include", String(args.include)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (StorageKey !== undefined) headers.set("X-StorageApi-Token", StorageKey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/storage/components/${encodeURIComponent(String(args.componentId))}/configs/${encodeURIComponent(String(args.configurationId))}/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(getApiV2StorageComponentsComponentIdConfigsConfigurationIdVersionsResponse, await res.json()) };