import {z} from 'zod' export type GetApiWorkspacesWorkspaceProviderConfigurationLinksArgs = {workspace: string, 'page[number]'?: string | undefined, 'page[size]'?: string | undefined, sort?: Array<'name'> | undefined, include?: Array<'provider-configuration'> | undefined}; export type GetApiWorkspacesWorkspaceProviderConfigurationLinksOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const providerConfigurationLink = z.object({attributes: z.object({alias: z.string().max(128).nullable().optional(), default: z.boolean().optional()}).optional(), id: z.string().optional(), links: z.object({self: z.string().optional()}).optional(), relationships: z.object({environment: z.object({data: z.object({id: z.string(), type: z.enum(["environments", ""])}).nullable()}).optional(), "provider-configuration": z.object({data: z.object({id: z.string(), type: z.enum(["provider-configurations", ""])})}), workspace: z.object({data: z.object({id: z.string(), type: z.enum(["workspaces", ""])}).nullable()}).optional()}), type: z.literal("provider-configuration-links")}); export const providerConfigurationLinkListingDocument = z.object({data: z.array(providerConfigurationLink).optional(), included: z.array(z.object({})).optional(), links: z.record(z.string(), z.string()).optional(), meta: z.object({}).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 Provider configuration workspace links * * GET /workspaces/{workspace}/provider-configuration-links */ export const getApiWorkspacesWorkspaceProviderConfigurationLinks = async (args: GetApiWorkspacesWorkspaceProviderConfigurationLinksArgs, options?: GetApiWorkspacesWorkspaceProviderConfigurationLinksOptions) => { const {baseUrl = "https://example.scalr.io/api/iacp/v3", fetch: fetchFn = fetch, APIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.api+json") if (args['page[number]'] != null) query.append("page[number]", String(args['page[number]'])) if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args.sort != null) query.append("sort", args.sort.join(',')) if (args.include != null) query.append("include", args.include.join(',')) if (APIKey !== undefined) headers.set('authorization', `Bearer ${APIKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/workspaces/${encodeURIComponent(String(args.workspace))}/provider-configuration-links${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(providerConfigurationLinkListingDocument, await res.json()) };