import {z} from 'zod' export type GetApiV1OrgsOrgIdIntegrationsIntegrationIdScanPolicyArgs = {orgId: string, integrationId: string, Authorization?: string | undefined}; export type GetApiV1OrgsOrgIdIntegrationsIntegrationIdScanPolicyOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1OrgsOrgIdIntegrationsIntegrationIdScanPolicyResponse = z.object({links: z.object({self: z.string()}), data: z.object({id: z.string(), type: z.literal("integration-scan-policy"), attributes: z.object({mode: z.union([z.literal("allow"), z.literal("deny")]).nullable(), fullNames: z.array(z.string().min(1)), accountsDiffer: z.boolean()})})}); 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 }; /** * Returns the repo allow/deny scan policy of the account the integration connects; every connection on one account shares it. `mode` is null when no policy is configured (scan everything); an `allow` policy with an empty `fullNames` means scan nothing. Returns 422 (not_scannable_integration) for integrations that are not source control, 422 (scan_policy_account_unknown) when the connected account is not recorded. When the connection names several accounts whose policies differ, answers with the combination that scans the least and `accountsDiffer: true`; combined deny lists can then name more repos than PUT accepts. * * GET /v1/orgs/{orgId}/integrations/{integrationId}/scan-policy */ export const getApiV1OrgsOrgIdIntegrationsIntegrationIdScanPolicy = async (args: GetApiV1OrgsOrgIdIntegrationsIntegrationIdScanPolicyArgs, options?: GetApiV1OrgsOrgIdIntegrationsIntegrationIdScanPolicyOptions) => { const {baseUrl = "https://api.tessl.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/orgs/${encodeURIComponent(String(args.orgId))}/integrations/${encodeURIComponent(String(args.integrationId))}/scan-policy${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(getApiV1OrgsOrgIdIntegrationsIntegrationIdScanPolicyResponse, await res.json()) };