import {z} from 'zod' export type BitbucketIntegrationCreateInput = {type: string, fetch_branches?: boolean | undefined, prune_branches?: boolean | undefined, environment_init_resources?: ('default' | 'manual' | 'minimum' | 'parent') | undefined, app_credentials?: ({key: string, secret: string} | null) | undefined, addon_credentials?: ({addon_key: string, client_key: string, shared_secret: string} | null) | undefined, repository: string, build_pull_requests?: boolean | undefined, pull_requests_clone_parent_data?: boolean | undefined, resync_pull_requests?: boolean | undefined}; export type BitbucketServerIntegrationCreateInput = {type: string, fetch_branches?: boolean | undefined, prune_branches?: boolean | undefined, environment_init_resources?: ('default' | 'manual' | 'minimum' | 'parent') | undefined, url: string, username: string, token: string, project: string, repository: string, build_pull_requests?: boolean | undefined, pull_requests_clone_parent_data?: boolean | undefined}; export type BlackfireIntegrationCreateInput = {type: string}; export type FastlyIntegrationCreateInput = {type: string, events?: Array | undefined, environments?: Array | undefined, excluded_environments?: Array | undefined, states?: Array | undefined, result?: ('*' | 'failure' | 'success') | undefined, token: string, service_id: string}; export type GithubIntegrationCreateInput = {type: string, fetch_branches?: boolean | undefined, prune_branches?: boolean | undefined, environment_init_resources?: ('default' | 'manual' | 'minimum' | 'parent') | undefined, token: string, base_url?: (string | null) | undefined, repository: string, build_pull_requests?: boolean | undefined, build_draft_pull_requests?: boolean | undefined, build_pull_requests_post_merge?: boolean | undefined, pull_requests_clone_parent_data?: boolean | undefined}; export type GitLabIntegrationCreateInput = {type: string, fetch_branches?: boolean | undefined, prune_branches?: boolean | undefined, environment_init_resources?: ('default' | 'manual' | 'minimum' | 'parent') | undefined, token: string, rotate_token?: boolean | undefined, rotate_token_validity_in_weeks?: number | undefined, base_url?: string | undefined, project: string, build_merge_requests?: boolean | undefined, build_wip_merge_requests?: boolean | undefined, merge_requests_clone_parent_data?: boolean | undefined}; export type EmailIntegrationCreateInput = {type: string, from_address?: (string | null) | undefined, recipients: Array}; export type PagerDutyIntegrationCreateInput = {type: string, routing_key: string}; export type SlackIntegrationCreateInput = {type: string, token: string, channel: string}; export type HealthWebHookIntegrationCreateInput = {type: string, shared_key?: (string | null) | undefined, url: string}; export type HttpLogIntegrationCreateInput = {type: string, extra?: {[key: string]: string} | undefined, url: string, headers?: {[key: string]: string} | undefined, tls_verify?: boolean | undefined, excluded_services?: Array | undefined}; export type NewRelicIntegrationCreateInput = {type: string, extra?: {[key: string]: string} | undefined, url: string, license_key: string, tls_verify?: boolean | undefined, excluded_services?: Array | undefined}; export type ScriptIntegrationCreateInput = {type: string, events?: Array | undefined, environments?: Array | undefined, excluded_environments?: Array | undefined, states?: Array | undefined, result?: ('*' | 'failure' | 'success') | undefined, script: string}; export type SplunkIntegrationCreateInput = {type: string, extra?: {[key: string]: string} | undefined, url: string, index: string, token: string, sourcetype?: string | undefined, tls_verify?: boolean | undefined, excluded_services?: Array | undefined}; export type SumologicIntegrationCreateInput = {type: string, extra?: {[key: string]: string} | undefined, url: string, category?: string | undefined, tls_verify?: boolean | undefined, excluded_services?: Array | undefined}; export type SyslogIntegrationCreateInput = {type: string, extra?: {[key: string]: string} | undefined, host?: string | undefined, port?: number | undefined, protocol?: ('tcp' | 'tls' | 'udp') | undefined, facility?: number | undefined, message_format?: ('rfc3164' | 'rfc5424') | undefined, auth_token?: string | undefined, auth_mode?: ('prefix' | 'structured_data') | undefined, tls_verify?: boolean | undefined, excluded_services?: Array | undefined}; export type WebHookIntegrationCreateInput = {type: string, events?: Array | undefined, environments?: Array | undefined, excluded_environments?: Array | undefined, states?: Array | undefined, result?: ('*' | 'failure' | 'success') | undefined, shared_key?: (string | null) | undefined, url: string}; export type IntegrationCreateInput = BitbucketIntegrationCreateInput | BitbucketServerIntegrationCreateInput | BlackfireIntegrationCreateInput | FastlyIntegrationCreateInput | GithubIntegrationCreateInput | GitLabIntegrationCreateInput | EmailIntegrationCreateInput | PagerDutyIntegrationCreateInput | SlackIntegrationCreateInput | HealthWebHookIntegrationCreateInput | HttpLogIntegrationCreateInput | NewRelicIntegrationCreateInput | HttpLogIntegrationCreateInput | ScriptIntegrationCreateInput | SplunkIntegrationCreateInput | SumologicIntegrationCreateInput | SyslogIntegrationCreateInput | WebHookIntegrationCreateInput; export type CreateApiProjectsProjectIdIntegrationsArgs = {projectId: string, body: IntegrationCreateInput}; export type CreateApiProjectsProjectIdIntegrationsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const acceptedResponse = z.object({status: z.string(), code: z.number().int()}); 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 }; /** * Integrate project with a third-party service * * POST /projects/{projectId}/integrations */ export const createApiProjectsProjectIdIntegrations = async (args: CreateApiProjectsProjectIdIntegrationsArgs, options?: CreateApiProjectsProjectIdIntegrationsOptions) => { const {baseUrl = "https://api.upsun.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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: "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(acceptedResponse, await res.json()) };