import {z} from 'zod' export type GetApiV1TenantIdBackendsArgs = {type?: ('aws-s3' | 'azure-blob' | 'gcp-s3' | 'fusionstorage-object' | 'ibm-cos' | 'yig' | 'aws-file' | 'azure-file') | undefined, name?: string | undefined, region?: string | undefined, offset?: number | undefined, limit?: number | undefined, sort?: string | undefined}; export type GetApiV1TenantIdBackendsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const backendList = z.object({id: z.string().optional(), tenantId: z.string().optional(), userId: z.string().optional(), name: z.string().optional(), type: z.enum(["aws-s3", "azure-blob", "gcp-s3", "fusionstorage-object", "ibm-cos", "yig", "aws-file", "azure-file"]).optional(), region: z.string().optional(), endpoint: z.string().optional()}); export const getApiV1TenantIdBackendsResponse = z.object({backends: z.array(backendList).optional(), next: z.number().int().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 all backends. * * GET /v1/{tenantId}/backends */ export const getApiV1TenantIdBackends = async (args: GetApiV1TenantIdBackendsArgs, options?: GetApiV1TenantIdBackendsOptions) => { const {baseUrl = "https://virtserver.swaggerhub.com/open83/crystal/1.0.0", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.type != null) query.append("type", String(args.type)) if (args.name != null) query.append("name", String(args.name)) if (args.region != null) query.append("region", String(args.region)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.sort != null) query.append("sort", String(args.sort)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/${encodeURIComponent(String(args.tenantId))}/backends${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(getApiV1TenantIdBackendsResponse, await res.json()) };