import {z} from 'zod' export type GetApiV1OrganizationsOrganizationIdWorkspacesWorkspaceIdArgs = {organizationId: string, workspaceId: string}; export type GetApiV1OrganizationsOrganizationIdWorkspacesWorkspaceIdOptions = {baseUrl?: string | undefined, clientOauth?: string | undefined, fetch?: typeof fetch | undefined}; export const aWSRegions = z.enum(["us-west-2", "us-east-1", "us-east-2", "eu-central-1", "eu-central-2", "eu-west-2", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "ap-northeast-1", "sa-east-1", "eu-west-1", "eu-west-3"]); export const workspaceState = z.enum(["Provisioning", "Active", "Inactive", "Failed", "Deprovisioning"]); export const workspaceSchema = z.object({workspaceId: z.string().min(4).max(41), region: aWSRegions, leaderFQDN: z.string(), state: workspaceState, alias: z.string().max(30).optional(), description: z.string().max(255).optional(), tags: z.array(z.string().max(30)).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 }; /** * Get a Workspace * * GET /v1/organizations/{organizationId}/workspaces/{workspaceId} * * Also accepts auth: bearerAuth */ export const getApiV1OrganizationsOrganizationIdWorkspacesWorkspaceId = async (args: GetApiV1OrganizationsOrganizationIdWorkspacesWorkspaceIdArgs, options?: GetApiV1OrganizationsOrganizationIdWorkspacesWorkspaceIdOptions) => { const {baseUrl = "https://gateway.cribl.cloud", fetch: fetchFn = fetch, clientOauth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (clientOauth !== undefined) headers.set('authorization', `Bearer ${clientOauth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/organizations/${encodeURIComponent(String(args.organizationId))}/workspaces/${encodeURIComponent(String(args.workspaceId))}${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(workspaceSchema, await res.json()) };