import {z} from 'zod' export type GetApiV2StorageBranchBranchIdComponentsComponentIdConfigsArgs = {componentId: string, isDeleted?: boolean | undefined, branchId: string}; export type GetApiV2StorageBranchBranchIdComponentsComponentIdConfigsOptions = {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 getApiV2StorageBranchBranchIdComponentsComponentIdConfigsResponse = z.array(configurationResponse); 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 configurations * * GET /v2/storage/branch/{branchId}/components/{componentId}/configs * * Also accepts auth: ManageKey, BearerAuth */ export const getApiV2StorageBranchBranchIdComponentsComponentIdConfigs = async (args: GetApiV2StorageBranchBranchIdComponentsComponentIdConfigsArgs, options?: GetApiV2StorageBranchBranchIdComponentsComponentIdConfigsOptions) => { 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.isDeleted != null) query.append("isDeleted", String(args.isDeleted)) if (StorageKey !== undefined) headers.set("X-StorageApi-Token", StorageKey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/storage/branch/${encodeURIComponent(String(args.branchId))}/components/${encodeURIComponent(String(args.componentId))}/configs${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(getApiV2StorageBranchBranchIdComponentsComponentIdConfigsResponse, await res.json()) };