import {z} from 'zod' export type GetApiProjectsProjectIdIntegrationsArgs = {projectId: string}; export type GetApiProjectsProjectIdIntegrationsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const bitbucketIntegration = z.object({id: z.string().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable(), type: z.string(), fetch_branches: z.boolean(), prune_branches: z.boolean(), environment_init_resources: z.enum(["default", "manual", "minimum", "parent"]), app_credentials: z.object({key: z.string()}).nullable().optional(), addon_credentials: z.object({addon_key: z.string(), client_key: z.string()}).nullable().optional(), repository: z.string(), build_pull_requests: z.boolean(), pull_requests_clone_parent_data: z.boolean(), resync_pull_requests: z.boolean()}); export const bitbucketServerIntegration = z.object({id: z.string().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable(), type: z.string(), fetch_branches: z.boolean(), prune_branches: z.boolean(), environment_init_resources: z.enum(["default", "manual", "minimum", "parent"]), url: z.string(), username: z.string(), project: z.string(), repository: z.string(), build_pull_requests: z.boolean(), pull_requests_clone_parent_data: z.boolean()}); export const blackfireIntegration = z.object({id: z.string().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable(), type: z.string(), environments_credentials: z.record(z.string(), z.object({server_uuid: z.string(), server_token: z.string()})), continuous_profiling: z.boolean()}); export const fastlyIntegration = z.object({id: z.string().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable(), type: z.string(), events: z.array(z.string()), environments: z.array(z.string()), excluded_environments: z.array(z.string()), states: z.array(z.string()), result: z.enum(["*", "failure", "success"]), service_id: z.string()}); export const githubIntegration = z.object({id: z.string().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable(), type: z.string(), fetch_branches: z.boolean(), prune_branches: z.boolean(), environment_init_resources: z.enum(["default", "manual", "minimum", "parent"]), base_url: z.string().nullable(), repository: z.string(), build_pull_requests: z.boolean(), build_draft_pull_requests: z.boolean(), build_pull_requests_post_merge: z.boolean(), pull_requests_clone_parent_data: z.boolean(), token_type: z.enum(["classic_personal_token", "github_app"])}); export const gitLabIntegration = z.object({id: z.string().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable(), type: z.string(), fetch_branches: z.boolean(), prune_branches: z.boolean(), environment_init_resources: z.enum(["default", "manual", "minimum", "parent"]), token_expires_at: z.string().nullable(), rotate_token: z.boolean(), rotate_token_validity_in_weeks: z.number().int(), base_url: z.string(), project: z.string(), build_merge_requests: z.boolean(), build_wip_merge_requests: z.boolean(), merge_requests_clone_parent_data: z.boolean()}); export const emailIntegration = z.object({id: z.string().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable(), type: z.string(), from_address: z.string().nullable(), recipients: z.array(z.string())}); export const pagerDutyIntegration = z.object({id: z.string().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable(), type: z.string(), routing_key: z.string()}); export const slackIntegration = z.object({id: z.string().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable(), type: z.string(), channel: z.string()}); export const healthWebHookIntegration = z.object({id: z.string().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable(), type: z.string(), url: z.string()}); export const httpLogIntegration = z.object({id: z.string().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable(), type: z.string(), extra: z.record(z.string(), z.string()), url: z.string(), headers: z.record(z.string(), z.string()), tls_verify: z.boolean(), excluded_services: z.array(z.string())}); export const newRelicIntegration = z.object({id: z.string().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable(), type: z.string(), extra: z.record(z.string(), z.string()), url: z.string(), tls_verify: z.boolean(), excluded_services: z.array(z.string())}); export const scriptIntegration = z.object({id: z.string().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable(), type: z.string(), events: z.array(z.string()), environments: z.array(z.string()), excluded_environments: z.array(z.string()), states: z.array(z.string()), result: z.enum(["*", "failure", "success"]), script: z.string()}); export const splunkIntegration = z.object({id: z.string().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable(), type: z.string(), extra: z.record(z.string(), z.string()), url: z.string(), index: z.string(), sourcetype: z.string(), tls_verify: z.boolean(), excluded_services: z.array(z.string())}); export const sumologicIntegration = z.object({id: z.string().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable(), type: z.string(), extra: z.record(z.string(), z.string()), url: z.string(), category: z.string(), tls_verify: z.boolean(), excluded_services: z.array(z.string())}); export const syslogIntegration = z.object({id: z.string().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable(), type: z.string(), extra: z.record(z.string(), z.string()), host: z.string(), port: z.number().int(), protocol: z.enum(["tcp", "tls", "udp"]), facility: z.number().int(), message_format: z.enum(["rfc3164", "rfc5424"]), tls_verify: z.boolean(), excluded_services: z.array(z.string())}); export const webHookIntegration = z.object({id: z.string().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable(), type: z.string(), events: z.array(z.string()), environments: z.array(z.string()), excluded_environments: z.array(z.string()), states: z.array(z.string()), result: z.enum(["*", "failure", "success"]), shared_key: z.string().nullable(), url: z.string()}); export const integration = z.union([bitbucketIntegration, bitbucketServerIntegration, blackfireIntegration, fastlyIntegration, githubIntegration, gitLabIntegration, emailIntegration, pagerDutyIntegration, slackIntegration, healthWebHookIntegration, httpLogIntegration, newRelicIntegration, httpLogIntegration, scriptIntegration, splunkIntegration, sumologicIntegration, syslogIntegration, webHookIntegration]); export const integrationCollection = z.array(integration); 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 list of existing integrations for a project * * GET /projects/{projectId}/integrations */ export const getApiProjectsProjectIdIntegrations = async (args: GetApiProjectsProjectIdIntegrationsArgs, options?: GetApiProjectsProjectIdIntegrationsOptions) => { const {baseUrl = "https://api.upsun.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.projectId))}/integrations${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(integrationCollection, await res.json()) };