import {z} from 'zod' export type CacheConfig = {key?: string | undefined, ttlInSecond?: number | undefined}; export type SchemaReference = {name?: string | undefined, version: number}; export type MappedWorkflow = {name?: string | undefined, requestMetadataAsInput?: boolean | undefined, version?: number | undefined}; export type QueryParameter = {name?: string | undefined, required?: boolean | undefined}; export type RateLimitConfig = {concurrentExecLimit?: number | undefined, policy?: ('QUEUE' | 'REJECT') | undefined, rateLimitKey?: string | undefined}; export type Tag = {key?: string | undefined, type?: string | undefined, value?: string | undefined}; export type ServiceRoute = {cacheConfig?: CacheConfig | undefined, createTime?: number | undefined, createdBy?: string | undefined, description?: string | undefined, httpMethod?: string | undefined, inputSchema?: string | undefined, inputSchemaRef?: SchemaReference | undefined, inputScript?: string | undefined, mappedWorkflow?: MappedWorkflow | undefined, orgId?: string | undefined, outputSchema?: string | undefined, outputSchemaRef?: SchemaReference | undefined, outputScript?: string | undefined, path?: string | undefined, queryParameters?: Array | undefined, rateLimitConfig?: RateLimitConfig | undefined, serviceId?: string | undefined, tags?: Array | undefined, timeoutInSeconds?: number | undefined, updateTime?: number | undefined, updatedBy?: string | undefined, waitUntilTasks?: string | undefined, workflowExecutionMode?: ('SYNCHRONOUS' | 'ASYNCHRONOUS') | undefined, workflowMetadataInOutput?: boolean | undefined}; export type UpdateApiApiGatewayConfigServicesServiceIdRoutesArgs = {serviceId: string, body: ServiceRoute}; export type UpdateApiApiGatewayConfigServicesServiceIdRoutesOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiApiGatewayConfigServicesServiceIdRoutesResponse = z.object({}); 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 }; /** * PUT /api/gateway/config/services/{serviceId}/routes */ export const updateApiApiGatewayConfigServicesServiceIdRoutes = async (args: UpdateApiApiGatewayConfigServicesServiceIdRoutesArgs, options?: UpdateApiApiGatewayConfigServicesServiceIdRoutesOptions) => { const {baseUrl = "https://developer.orkescloud.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("X-Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/gateway/config/services/${encodeURIComponent(String(args.serviceId))}/routes${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiApiGatewayConfigServicesServiceIdRoutesResponse, await res.json()) };