import {z} from 'zod' export type ApinizerBasicHeader = {name?: string | undefined, value?: string | undefined, resolvedName?: string | undefined, resolvedValue?: string | undefined}; export type ClientRoute = {relativePathList?: Array | undefined, methodList?: (Array<'GET' | 'POST' | 'PUT' | 'HEAD' | 'OPTIONS' | 'DELETE' | 'PATCH' | 'TRACE' | 'ALL' | 'QUERY'>) | undefined, hostList?: Array | undefined, headerList?: Array | undefined, bufferRequest?: boolean | undefined, bufferResponse?: boolean | undefined}; export type ApiProxyRoutingAddress = {address: string, description?: string | undefined, weight?: number | undefined, soapType?: ('SOAP11' | 'SOAP12' | 'HTTP') | undefined, addressType?: ('PRIMARY' | 'CANARY' | 'MIRROR' | 'FAILOVER_ONLY') | undefined, healthCheckPath?: string | undefined, healthMonitoringEnabled?: boolean | undefined}; export type CanaryReleaseSettingsDTO = {enabled?: boolean | undefined, trafficPercentage?: number | undefined, cooldownPeriodSeconds?: number | undefined}; export type ApiProxyRoutingInfoDTO = {loadBalanceAlgorithm?: ('ROUND_ROBIN' | 'LRU' | 'WEIGHTED' | 'RANDOM' | 'PICK_FIRST') | undefined, routingAddressList?: Array | undefined, connectionSettingsEnabled?: boolean | undefined, connectTimeout?: number | undefined, readTimeout?: number | undefined, connectionRequestTimeout?: number | undefined, validateAfterInactivity?: number | undefined, idleConnectionTimeout?: number | undefined, redirectsEnabled?: boolean | undefined, maxRedirects?: number | undefined, relativeRedirectsAllowed?: boolean | undefined, preserveHttpMethodOnRedirect?: boolean | undefined, enableStreaming?: boolean | undefined, connectionPoolManagementType?: ('GENERAL' | 'CUSTOM' | 'NONE') | undefined, customConnectionPoolSize?: number | undefined, retryCount?: number | undefined, failoverRetryCount?: number | undefined, ignoreRoutingError?: boolean | undefined, retryDelayType?: ('NO_DELAY' | 'FIXED' | 'EXPONENTIAL') | undefined, retryFixedDelayMs?: number | undefined, retryInitialDelayMs?: number | undefined, retryMaxDelayMs?: number | undefined, retryBackoffMultiplier?: number | undefined, stickySessionEnabled?: boolean | undefined, stickyType?: ('COOKIE_ONLY' | 'IP_HASH' | 'HYBRID') | undefined, stickyCookieName?: string | undefined, stickyCookieTtl?: number | undefined, stickyCookieSecure?: boolean | undefined, stickyCookieHttpOnly?: boolean | undefined, stickyHashSecret?: string | undefined, healthMonitoringCustomizationEnabled?: boolean | undefined, healthCheckIntervalSeconds?: number | undefined, healthCheckTimeoutSeconds?: number | undefined, healthCheckFailThreshold?: number | undefined, healthCheckPassThreshold?: number | undefined, trafficMirrorEnabled?: boolean | undefined, mirrorPercentage?: number | undefined, mirrorIgnoreCircuitBreaker?: boolean | undefined, mirrorRespectCircuitBreaker?: boolean | undefined, canarySettings?: CanaryReleaseSettingsDTO | undefined, failoverOnlyEnabled?: boolean | undefined, queryEncodingMode?: ('STANDARD' | 'RFC3986' | 'PASSTHROUGH') | undefined}; export type MaintenanceModeSettingDTO = {deploy?: boolean | undefined, deployTargetEnvironmentNameList?: Array | undefined, enabled?: boolean | undefined, httpStatusCode?: number | undefined, contentType?: string | undefined, message?: string | undefined}; export type SpecAuthorizationValue = {value?: string | undefined, type?: string | undefined, keyName?: string | undefined}; export type ApiProxyParseFromURLDTO = {deploy?: boolean | undefined, deployTargetEnvironmentNameList?: Array | undefined, apiProxyCreationType?: ('WSDL' | 'SWAGGER' | 'OPEN_API' | 'REVERSE_PROXY' | 'EMPTY_API') | undefined, soapToRest?: boolean | undefined, reParse?: boolean | undefined, apiProxyGroupName?: string | undefined, apiProxyName?: string | undefined, apiProxyDescription?: string | undefined, clientRoute?: ClientRoute | undefined, backendApiVersion?: string | undefined, enableWSA?: boolean | undefined, enableWSRM?: boolean | undefined, routingInfo?: ApiProxyRoutingInfoDTO | undefined, maintenanceModeSetting?: MaintenanceModeSettingDTO | undefined, specUrl?: string | undefined, specAuthorizationValueList?: Array | undefined, specAuthUsername?: string | undefined, specAuthPassword?: string | undefined, useSpecAuthorization?: boolean | undefined, skipSslVerification?: boolean | undefined, trustStoreName?: string | undefined, uploadedTrustStoreContent?: string | undefined, uploadedTrustStorePassword?: string | undefined, uploadedTrustStoreType?: string | undefined, certificateName?: string | undefined, connectionTimeout?: number | undefined}; export type CreateApiApiopsProjectsProjectNameApiProxiesUrlArgs = {projectName: string, body: ApiProxyParseFromURLDTO}; export type CreateApiApiopsProjectsProjectNameApiProxiesUrlOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const deploymentResult = z.object({envName: z.string().optional(), podName: z.string().optional(), podIp: z.string().optional(), success: z.boolean().optional(), detail: z.string().optional(), responseTime: z.number().int().optional(), detailList: z.array(z.unknown()).optional(), firstFromApiResultList: z.unknown()}); export const apiOpsAdvisoryDTO = z.object({level: z.string().optional(), key: z.string().optional(), params: z.record(z.string(), z.unknown()).optional()}); export const apiOpsResponseSuccess = z.object({status: z.enum(["SUCCESS", "FAILURE"]).optional(), resultMessage: z.string().optional(), resultList: z.array(z.string()).optional(), resultCount: z.number().int().optional(), deploymentResult: deploymentResult.optional(), unresolvedReferences: z.array(z.string()).optional(), advisories: z.array(apiOpsAdvisoryDTO).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 }; /** * Create an API Proxy from URL * * POST /apiops/projects/{projectName}/apiProxies/url/ */ export const createApiApiopsProjectsProjectNameApiProxiesUrl = async (args: CreateApiApiopsProjectsProjectNameApiProxiesUrlArgs, options?: CreateApiApiopsProjectsProjectNameApiProxiesUrlOptions) => { const {baseUrl = "http://167.86.118.166:32080", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/apiops/projects/${encodeURIComponent(String(args.projectName))}/apiProxies/url/${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(apiOpsResponseSuccess, await res.json()) };