import {z} from 'zod' export type ProtosScmV1CompleteAdoScmAppInstallRequest = {deploymentId?: string | undefined, scmAppId?: string | undefined}; export type UpdateApiApiScmAdoAppInstallArgs = {body: ProtosScmV1CompleteAdoScmAppInstallRequest}; export type UpdateApiApiScmAdoAppInstallOptions = {baseUrl: string, SemgrepWebToken?: string | undefined, fetch?: typeof fetch | undefined}; export const protosScmV1ScmApp = z.object({id: z.string().optional(), slug: z.string().optional(), appId: z.string().optional(), scmType: z.enum(["SCM_TYPE_GITHUB", "SCM_TYPE_GITHUB_ENTERPRISE", "SCM_TYPE_GITLAB", "SCM_TYPE_GITLAB_SELFMANAGED", "SCM_TYPE_BITBUCKET", "SCM_TYPE_BITBUCKET_DATACENTER", "SCM_TYPE_AZURE_DEVOPS", "SCM_TYPE_UNKNOWN", "SCM_TYPE_HARNESS"]).optional(), baseUrl: z.string().optional(), requestId: z.string().optional(), scmName: z.string().optional(), codeAccess: z.boolean().optional(), tenantId: z.string().optional()}); export const protosScmV1CompleteAdoScmAppInstallResponse = z.object({app: protosScmV1ScmApp.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 }; /** * Complete Azure DevOps SCM App install * * PUT /api/scm/ado_app_install * * Also accepts auth: SemgrepJWT */ export const updateApiApiScmAdoAppInstall = async (args: UpdateApiApiScmAdoAppInstallArgs, options: UpdateApiApiScmAdoAppInstallOptions) => { const {baseUrl, fetch: fetchFn = fetch, SemgrepWebToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (SemgrepWebToken !== undefined) headers.set('authorization', `Bearer ${SemgrepWebToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/scm/ado_app_install${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(protosScmV1CompleteAdoScmAppInstallResponse, await res.json()) };