import {z} from 'zod' export type GetApiApiIntegrationsDefOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const schemaDef = z.object({createTime: z.number().int().optional(), createdBy: z.string().optional(), data: z.record(z.string(), z.object({})).optional(), externalRef: z.string().optional(), name: z.string(), ownerApp: z.string().optional(), type: z.enum(["JSON", "AVRO", "PROTOBUF"]), updateTime: z.number().int().optional(), updatedBy: z.string().optional(), version: z.number().int()}); export const integrationDefApi = z.object({api: z.string().optional(), description: z.string().optional(), inputSchema: schemaDef.optional(), integrationType: z.string().optional(), jsonUISchema: z.string().optional(), outputSchema: schemaDef.optional()}); export const option = z.object({label: z.string().optional(), value: z.string().optional()}); export const integrationDefFormField = z.object({defaultValue: z.string().optional(), description: z.string().optional(), fieldName: z.enum(["oAuth2AccessToken", "oAuth2RefreshToken", "api_key", "user", "header", "endpoint", "organizationId", "authUrl", "environment", "projectName", "indexName", "publisher", "password", "namespace", "batchSize", "batchWaitTime", "visibilityTimeout", "connectionType", "connectionPoolSize", "consumer", "stream", "batchPollConsumersCount", "consumer_type", "region", "awsAccountId", "externalId", "roleArn", "protocol", "mechanism", "port", "schemaRegistryUrl", "schemaRegistryApiKey", "schemaRegistryApiSecret", "authenticationType", "truststoreAuthenticationType", "tls", "cipherSuite", "pubSubMethod", "keyStorePassword", "keyStoreLocation", "schemaRegistryAuthType", "valueSubjectNameStrategy", "useLatestSchemaVersion", "datasourceURL", "jdbcDriver", "subscription", "serviceAccountCredentials", "file", "tlsFile", "queueManager", "groupId", "channel", "dimensions", "distance_metric", "indexing_method", "inverted_list_count", "pullPeriod", "pullBatchWaitMillis", "completionsPath", "deploymentName", "betaVersion", "version", "oAuth2Scope", "oAuth2AuthCode", "oAuth2TokenExpiresAt", "oAuth2Provider", "oAuth2RedirectUri", "collection", "tablePrefix", "oAuth2ClientId", "oAuth2ClientSecret"]).optional(), fieldType: z.enum(["DROPDOWN", "TEXT", "PASSWORD", "FILE"]).optional(), label: z.string().optional(), optional: z.boolean().optional(), value: z.string().optional(), valueOptions: z.array(option).optional()}); export const integrationDef = z.object({apis: z.array(integrationDefApi).optional(), category: z.enum(["API", "AI_MODEL", "VECTOR_DB", "RELATIONAL_DB", "MESSAGE_BROKER", "GIT", "EMAIL", "MCP", "CLOUD"]).optional(), categoryLabel: z.string().optional(), configuration: z.array(integrationDefFormField).optional(), description: z.string().optional(), enabled: z.boolean().optional(), iconName: z.string().optional(), name: z.string().optional(), tags: z.array(z.string()).optional(), type: z.string().optional()}); export const getApiApiIntegrationsDefResponse = z.array(integrationDef); 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 Integration provider definitions * * GET /api/integrations/def */ export const getApiApiIntegrationsDef = async (options?: GetApiApiIntegrationsDefOptions) => { const {baseUrl = "https://developer.orkescloud.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("X-Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/integrations/def${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(getApiApiIntegrationsDefResponse, await res.json()) };