import {z} from 'zod' export type GitHubOIDCClaimPatterns = {actor?: string | undefined, actor_id?: string | undefined, enterprise?: string | undefined, enterprise_id?: string | undefined, environment?: string | undefined, event_name?: string | undefined, job_workflow_ref?: string | undefined, ref?: string | undefined, ref_type?: string | undefined, repository?: string | undefined, repository_id?: string | undefined, repository_owner?: string | undefined, repository_owner_id?: string | undefined, repository_visibility?: string | undefined, runner_environment?: string | undefined, sub: string, workflow?: string | undefined, workflow_ref?: string | undefined}; export type GitHubCloudAuthIntakeMappingCreateAttributes = {claim_matchers: GitHubOIDCClaimPatterns}; export type GitHubCloudAuthIntakeMappingType = 'github_oidc_auth_intake_mapping'; export type GitHubCloudAuthIntakeMappingCreateData = {attributes: GitHubCloudAuthIntakeMappingCreateAttributes, type: GitHubCloudAuthIntakeMappingType}; export type GitHubCloudAuthIntakeMappingCreateRequest = {data: GitHubCloudAuthIntakeMappingCreateData}; export type CreateApiApiV2WifGithubIntakeMappingArgs = {body: GitHubCloudAuthIntakeMappingCreateRequest}; export type CreateApiApiV2WifGithubIntakeMappingOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, appKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const gitHubOIDCClaimPatterns = z.object({actor: z.string().optional(), actor_id: z.string().optional(), enterprise: z.string().optional(), enterprise_id: z.string().optional(), environment: z.string().optional(), event_name: z.string().optional(), job_workflow_ref: z.string().optional(), ref: z.string().optional(), ref_type: z.string().optional(), repository: z.string().optional(), repository_id: z.string().optional(), repository_owner: z.string().optional(), repository_owner_id: z.string().optional(), repository_visibility: z.string().optional(), runner_environment: z.string().optional(), sub: z.string(), workflow: z.string().optional(), workflow_ref: z.string().optional()}); export const gitHubCloudAuthIntakeMappingAttributesResponse = z.object({claim_matchers: gitHubOIDCClaimPatterns}); export const gitHubCloudAuthIntakeMappingType = z.literal("github_oidc_auth_intake_mapping"); export const gitHubCloudAuthIntakeMappingDataResponse = z.object({attributes: gitHubCloudAuthIntakeMappingAttributesResponse, id: z.string(), type: gitHubCloudAuthIntakeMappingType}); export const gitHubCloudAuthIntakeMappingResponse = z.object({data: gitHubCloudAuthIntakeMappingDataResponse}); 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 }; /** * Create a GitHub cloud auth intake mapping * * POST /api/v2/wif/github/intake_mapping * * Also accepts auth: AuthZ */ export const createApiApiV2WifGithubIntakeMapping = async (args: CreateApiApiV2WifGithubIntakeMappingArgs, options?: CreateApiApiV2WifGithubIntakeMappingOptions) => { const {baseUrl = "https://api.datadoghq.com", fetch: fetchFn = fetch, apiKeyAuth, appKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("DD-API-KEY", apiKeyAuth) if (appKeyAuth !== undefined) headers.set("DD-APPLICATION-KEY", appKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/wif/github/intake_mapping${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(gitHubCloudAuthIntakeMappingResponse, await res.json()) };