import {z} from 'zod' export type ProviderConfigurationLink = {attributes?: ({alias?: (string | null) | undefined, default?: boolean | undefined}) | undefined, id?: string | undefined, links?: ({self?: string | undefined}) | undefined, relationships: {environment?: ({data: {id: string, type: 'environments' | ''} | null}) | undefined, 'provider-configuration': {data: {id: string, type: 'provider-configurations' | ''}}, workspace?: ({data: {id: string, type: 'workspaces' | ''} | null}) | undefined}, type: 'provider-configuration-links'}; export type ProviderConfigurationLinkDocument = {data?: ProviderConfigurationLink | undefined, included?: Array> | undefined, meta?: Record | undefined}; export type CreateApiWorkspacesWorkspaceProviderConfigurationLinksArgs = {workspace: string, body: ProviderConfigurationLinkDocument}; export type CreateApiWorkspacesWorkspaceProviderConfigurationLinksOptions = {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 providerConfigurationLinkDocument = z.object({data: providerConfigurationLink.optional(), included: z.array(z.object({})).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 }; /** * Attach a Provider configuration to the workspace * * POST /workspaces/{workspace}/provider-configuration-links */ export const createApiWorkspacesWorkspaceProviderConfigurationLinks = async (args: CreateApiWorkspacesWorkspaceProviderConfigurationLinksArgs, options?: CreateApiWorkspacesWorkspaceProviderConfigurationLinksOptions) => { const {baseUrl = "https://example.scalr.io/api/iacp/v3", fetch: fetchFn = fetch, APIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/vnd.api+json") headers.set('accept', "application/vnd.api+json") 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: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(providerConfigurationLinkDocument, await res.json()) };