import {z} from 'zod' export type GetApiV2StorageComponentsComponentIdConfigsConfigurationIdArgs = {componentId: string, configurationId: string}; export type GetApiV2StorageComponentsComponentIdConfigsConfigurationIdOptions = {baseUrl?: string | undefined, StorageKey?: string | undefined, fetch?: typeof fetch | undefined}; 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 configurationCreatorTokenResponse = z.object({id: z.number().int(), description: z.string().nullable()}); export const configurationCurrentVersionResponse = z.object({created: z.string(), creatorToken: configurationCreatorTokenResponse, actor: actorResponse.nullable(), changeDescription: z.string().nullable(), versionIdentifier: z.string().nullable()}); export const configurationResponse = z.object({id: z.string(), name: z.string(), description: z.string(), created: z.string(), creatorToken: z.object({id: z.number().int(), description: z.string()}), actor: actorResponse.nullable(), version: z.number().int(), changeDescription: z.string().nullable(), isDisabled: z.boolean(), isDeleted: z.boolean(), folder: z.string().max(400).nullable(), folderUpdated: z.string().nullable(), configuration: z.record(z.string(), z.unknown()), rowsSortOrder: z.array(z.string()), rows: z.array(z.object({id: z.string(), name: z.string(), description: z.string(), isDisabled: z.boolean(), version: z.number().int(), created: z.string(), creatorToken: configurationCreatorTokenResponse, actor: actorResponse.nullable(), changeDescription: z.string().nullable(), versionIdentifier: z.string().nullable(), state: z.union([z.record(z.string(), z.unknown()), z.array(z.unknown()), z.string()]), configuration: z.union([z.record(z.string(), z.unknown()), z.array(z.unknown()), z.string()])})), state: z.record(z.string(), z.unknown()), currentVersion: configurationCurrentVersionResponse}); 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 }; /** * Configuration Detail * * GET /v2/storage/components/{componentId}/configs/{configurationId} * * Also accepts auth: ManageKey, BearerAuth */ export const getApiV2StorageComponentsComponentIdConfigsConfigurationId = async (args: GetApiV2StorageComponentsComponentIdConfigsConfigurationIdArgs, options?: GetApiV2StorageComponentsComponentIdConfigsConfigurationIdOptions) => { 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 (StorageKey !== undefined) headers.set("X-StorageApi-Token", StorageKey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/storage/components/${encodeURIComponent(String(args.componentId))}/configs/${encodeURIComponent(String(args.configurationId))}${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(configurationResponse, await res.json()) };