import {z} from 'zod' export type ScopeType = 'organization' | 'application' | 'project'; export type TemplateConfig = {probes?: Array | undefined, strategies?: Array | undefined, numTests?: number | undefined, maxConcurrency?: number | undefined, language?: (string | Array) | undefined, probeTimeoutMs?: number | undefined, maxCampaignTimeMs?: number | undefined}; export type UpdateTemplateRequest = {name?: string | undefined, description?: string | undefined, scopeType?: ScopeType | undefined, config?: TemplateConfig | undefined}; export type UpdateApiApiV30RedteamingOrgsOrgUuidTemplatesTemplateIdArgs = {pretty?: boolean | undefined, 'X-Correlation-ID'?: string | undefined, orgUuid: string, templateId: string, body: UpdateTemplateRequest}; export type UpdateApiApiV30RedteamingOrgsOrgUuidTemplatesTemplateIdOptions = {baseUrl?: string | undefined, bearerKey?: string | undefined, fetch?: typeof fetch | undefined}; export const supportToken = z.string(); export const templateConfig = z.object({probes: z.array(z.string()).optional(), strategies: z.array(z.string()).optional(), numTests: z.number().int().optional(), maxConcurrency: z.number().int().optional(), language: z.union([z.string(), z.array(z.string())]).optional(), probeTimeoutMs: z.number().int().optional(), maxCampaignTimeMs: z.number().int().optional()}); export const scopeType = z.enum(["organization", "application", "project"]); export const link = z.object({href: z.string()}); export const links = z.record(z.string(), link); export const template = z.object({id: z.string(), name: z.string(), description: z.string(), config: templateConfig, scopeType: scopeType, organization: z.string(), application: z.string(), project: z.string(), createdBy: z.string(), updatedBy: z.string(), createdAt: z.string(), updatedAt: z.string(), canEdit: z.boolean(), canDelete: z.boolean(), _links: links}); export const templateResource = z.object({supportToken: supportToken, response: template}); 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 }; /** * Update an organization-scoped scan template * * PUT /api/v3.0/redteaming/orgs/{orgUuid}/templates/{templateId} */ export const updateApiApiV30RedteamingOrgsOrgUuidTemplatesTemplateId = async (args: UpdateApiApiV30RedteamingOrgsOrgUuidTemplatesTemplateIdArgs, options?: UpdateApiApiV30RedteamingOrgsOrgUuidTemplatesTemplateIdOptions) => { const {baseUrl = "https://baseUrl", fetch: fetchFn = fetch, bearerKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.pretty != null) query.append("pretty", String(args.pretty)) if (args['X-Correlation-ID'] != null) headers.set("X-Correlation-ID", String(args['X-Correlation-ID'])) if (bearerKey !== undefined) headers.set('authorization', `Bearer ${bearerKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v3.0/redteaming/orgs/${encodeURIComponent(String(args.orgUuid))}/templates/${encodeURIComponent(String(args.templateId))}${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(templateResource, await res.json()) };