import {z} from 'zod' export type V1IndexData = {data?: Array | undefined, search_score?: number | undefined, tenant?: string | undefined, will_be_deleted_at?: string | undefined}; export type GoogleprotobufAny = {'@type'?: string | undefined} | {[key: string]: unknown}; export type V1Meta = {annotations?: {[key: string]: string} | undefined, create_time?: string | undefined, created_by?: string | undefined, description?: string | undefined, index_data?: V1IndexData | undefined, kind?: string | undefined, name: string, parent_kind?: string | undefined, parent_uuid?: string | undefined, references?: {[key: string]: GoogleprotobufAny} | undefined, tags?: Array | undefined, update_time?: string | undefined, updated_by?: string | undefined, upsert_time?: string | undefined, version?: string | undefined}; export type ContextContextType = 'CONTEXT_TYPE_UNSPECIFIED' | 'CONTEXT_TYPE_MAIN' | 'CONTEXT_TYPE_EXTERNAL' | 'CONTEXT_TYPE_CI_RUN' | 'CONTEXT_TYPE_SBOM' | 'CONTEXT_TYPE_REF'; export type V1Context = {id: string, tags?: Array | undefined, type: ContextContextType, will_be_deleted_at?: string | undefined}; export type NotificationActionAggregationType = 'AGGREGATION_TYPE_UNSPECIFIED' | 'AGGREGATION_TYPE_PROJECT' | 'AGGREGATION_TYPE_DEPENDENCY' | 'AGGREGATION_TYPE_DEPENDENCY_ACROSS_PKG_VERSIONS' | 'AGGREGATION_TYPE_NONE' | 'AGGREGATION_TYPE_MANUAL'; export type SpecAggregationDetails = {aggregation_target_name?: string | undefined, aggregation_type?: NotificationActionAggregationType | undefined, pkg_version_name?: string | undefined, pkg_version_uuid?: string | undefined, standalone_tickets?: boolean | undefined}; export type V1NotificationDiff = {new_finding_uuids?: Array | undefined, resolved_finding_uuids?: Array | undefined}; export type NotificationDismissNotificationDismissCategory = 'NOTIFICATION_DISMISS_CATEGORY_UNSPECIFIED' | 'NOTIFICATION_DISMISS_CATEGORY_FALSE_POSITIVE' | 'NOTIFICATION_DISMISS_CATEGORY_MITIGATED' | 'NOTIFICATION_DISMISS_CATEGORY_LOW_PRIORITY'; export type SpecNotificationDismiss = {category?: NotificationDismissNotificationDismissCategory | undefined, comment?: string | undefined, time?: string | undefined}; export type SpecFindingDetails = {dependency?: string | undefined, description?: string | undefined, explanation?: string | undefined, package_version?: string | undefined, remediation?: string | undefined, severity?: string | undefined, summary?: string | undefined}; export type V1NotificationActionDataMetadata = {data?: GoogleprotobufAny | undefined}; export type NotificationTargetActionActionType = 'ACTION_TYPE_UNSPECIFIED' | 'ACTION_TYPE_WEBHOOK' | 'ACTION_TYPE_JIRA' | 'ACTION_TYPE_EMAIL' | 'ACTION_TYPE_VANTA' | 'ACTION_TYPE_SLACK' | 'ACTION_TYPE_GITHUB_PR' | 'ACTION_TYPE_ADO_BOARDS' | 'ACTION_TYPE_REMEDIATION_PR'; export type V1NotificationActionData = {error_status?: string | undefined, is_ignored?: boolean | undefined, last_failed_at?: string | undefined, metadata?: V1NotificationActionDataMetadata | undefined, notification_target_type?: NotificationTargetActionActionType | undefined, open_action_complete?: boolean | undefined, resolve_action_complete?: boolean | undefined, retry_count?: number | undefined, update_action_complete?: boolean | undefined}; export type V1ResourceUuids = {uuids?: Array | undefined}; export type V1PolicyOutput = {allow?: boolean | undefined, raw?: Array> | undefined, violating_resources?: {[key: string]: V1ResourceUuids} | undefined}; export type V1NotificationPayload = {policy_output?: V1PolicyOutput | undefined}; export type PolicyPolicyType = 'POLICY_TYPE_UNSPECIFIED' | 'POLICY_TYPE_ADMISSION' | 'POLICY_TYPE_NOTIFICATION' | 'POLICY_TYPE_FINDING' | 'POLICY_TYPE_FINDING_CFG' | 'POLICY_TYPE_ML_FINDING' | 'POLICY_TYPE_SYSTEM_FINDING' | 'POLICY_TYPE_USER_FINDING' | 'POLICY_TYPE_EXCEPTION' | 'POLICY_TYPE_REMEDIATION'; export type AutomatedPRParametersLanguageParameters = {assignees?: Array | undefined, labels?: Array | undefined, reviewers?: Array | undefined}; export type RemediationParametersAutomatedPRParameters = {language_parameters?: {[key: string]: AutomatedPRParametersLanguageParameters} | undefined, max_open_prs?: number | undefined}; export type V1RemediationParameters = {automated_pr_parameters?: RemediationParametersAutomatedPRParameters | undefined}; export type SpecNotificationState = 'NOTIFICATION_STATE_UNSPECIFIED' | 'NOTIFICATION_STATE_OPEN_NOTIFICATION_PENDING' | 'NOTIFICATION_STATE_OPEN' | 'NOTIFICATION_STATE_DISMISSED' | 'NOTIFICATION_STATE_SNOOZED' | 'NOTIFICATION_STATE_RESOLVED_NOTIFICATION_PENDING' | 'NOTIFICATION_STATE_RESOLVED' | 'NOTIFICATION_STATE_DELETED'; export type V1NotificationSpec = {aggregation_details?: SpecAggregationDetails | undefined, diff?: V1NotificationDiff | undefined, dismiss?: SpecNotificationDismiss | undefined, finding_details?: {[key: string]: SpecFindingDetails} | undefined, hashsum?: string | undefined, last_seen_at?: string | undefined, notification_action_data?: {[key: string]: V1NotificationActionData} | undefined, notification_external_ids?: Array | undefined, payload?: V1NotificationPayload | undefined, policy_type?: PolicyPolicyType | undefined, policy_uuid?: string | undefined, project_uuid: string, remediation_parameters?: V1RemediationParameters | undefined, repository_version_uuid?: string | undefined, resolved_at?: string | undefined, state: SpecNotificationState}; export type V1TenantMeta = {namespace: string}; export type V1Notification = {context?: V1Context | undefined, meta: V1Meta, spec: V1NotificationSpec, tenant_meta?: V1TenantMeta | undefined, uuid?: string | undefined}; export type V1BatchNotificationSpec = {finding_uuids?: Array | undefined, notification_target_uuid?: string | undefined, notifications?: Array | undefined}; export type BatchNotificationServiceCreateBatchNotificationBody = {meta?: V1Meta | undefined, spec?: V1BatchNotificationSpec | undefined, tenant_meta?: Record | undefined, uuid?: string | undefined}; export type CreateApiV1NamespacesTenantMetaNamespaceBatchNotificationsArgs = {'tenant_meta.namespace': string, body: BatchNotificationServiceCreateBatchNotificationBody}; export type CreateApiV1NamespacesTenantMetaNamespaceBatchNotificationsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const v1IndexData = z.object({data: z.array(z.string()).optional(), search_score: z.number().optional(), tenant: z.string().optional(), will_be_deleted_at: z.string().optional()}); export const googleprotobufAny = z.object({"@type": z.string().optional()}).and(z.record(z.string(), z.unknown())); export const v1Meta = z.object({annotations: z.record(z.string(), z.string()).optional(), create_time: z.string().optional(), created_by: z.string().optional(), description: z.string().optional(), index_data: v1IndexData.optional(), kind: z.string().optional(), name: z.string(), parent_kind: z.string().optional(), parent_uuid: z.string().optional(), references: z.record(z.string(), googleprotobufAny).optional(), tags: z.array(z.string()).optional(), update_time: z.string().optional(), updated_by: z.string().optional(), upsert_time: z.string().optional(), version: z.string().optional()}); export const contextContextType = z.enum(["CONTEXT_TYPE_UNSPECIFIED", "CONTEXT_TYPE_MAIN", "CONTEXT_TYPE_EXTERNAL", "CONTEXT_TYPE_CI_RUN", "CONTEXT_TYPE_SBOM", "CONTEXT_TYPE_REF"]); export const v1Context = z.object({id: z.string(), tags: z.array(z.string()).optional(), type: contextContextType, will_be_deleted_at: z.string().optional()}); export const notificationActionAggregationType = z.enum(["AGGREGATION_TYPE_UNSPECIFIED", "AGGREGATION_TYPE_PROJECT", "AGGREGATION_TYPE_DEPENDENCY", "AGGREGATION_TYPE_DEPENDENCY_ACROSS_PKG_VERSIONS", "AGGREGATION_TYPE_NONE", "AGGREGATION_TYPE_MANUAL"]); export const specAggregationDetails = z.object({aggregation_target_name: z.string().optional(), aggregation_type: notificationActionAggregationType.optional(), pkg_version_name: z.string().optional(), pkg_version_uuid: z.string().optional(), standalone_tickets: z.boolean().optional()}); export const v1NotificationDiff = z.object({new_finding_uuids: z.array(z.string()).optional(), resolved_finding_uuids: z.array(z.string()).optional()}); export const notificationDismissNotificationDismissCategory = z.enum(["NOTIFICATION_DISMISS_CATEGORY_UNSPECIFIED", "NOTIFICATION_DISMISS_CATEGORY_FALSE_POSITIVE", "NOTIFICATION_DISMISS_CATEGORY_MITIGATED", "NOTIFICATION_DISMISS_CATEGORY_LOW_PRIORITY"]); export const specNotificationDismiss = z.object({category: notificationDismissNotificationDismissCategory.optional(), comment: z.string().optional(), time: z.string().optional()}); export const specFindingDetails = z.object({dependency: z.string().optional(), description: z.string().optional(), explanation: z.string().optional(), package_version: z.string().optional(), remediation: z.string().optional(), severity: z.string().optional(), summary: z.string().optional()}); export const v1NotificationActionDataMetadata = z.object({data: googleprotobufAny.optional()}); export const notificationTargetActionActionType = z.enum(["ACTION_TYPE_UNSPECIFIED", "ACTION_TYPE_WEBHOOK", "ACTION_TYPE_JIRA", "ACTION_TYPE_EMAIL", "ACTION_TYPE_VANTA", "ACTION_TYPE_SLACK", "ACTION_TYPE_GITHUB_PR", "ACTION_TYPE_ADO_BOARDS", "ACTION_TYPE_REMEDIATION_PR"]); export const v1NotificationActionData = z.object({error_status: z.string().optional(), is_ignored: z.boolean().optional(), last_failed_at: z.string().optional(), metadata: v1NotificationActionDataMetadata.optional(), notification_target_type: notificationTargetActionActionType.optional(), open_action_complete: z.boolean().optional(), resolve_action_complete: z.boolean().optional(), retry_count: z.number().int().optional(), update_action_complete: z.boolean().optional()}); export const v1ResourceUuids = z.object({uuids: z.array(z.string()).optional()}); export const v1PolicyOutput = z.object({allow: z.boolean().optional(), raw: z.array(z.object({})).optional(), violating_resources: z.record(z.string(), v1ResourceUuids).optional()}); export const v1NotificationPayload = z.object({policy_output: v1PolicyOutput.optional()}); export const policyPolicyType = z.enum(["POLICY_TYPE_UNSPECIFIED", "POLICY_TYPE_ADMISSION", "POLICY_TYPE_NOTIFICATION", "POLICY_TYPE_FINDING", "POLICY_TYPE_FINDING_CFG", "POLICY_TYPE_ML_FINDING", "POLICY_TYPE_SYSTEM_FINDING", "POLICY_TYPE_USER_FINDING", "POLICY_TYPE_EXCEPTION", "POLICY_TYPE_REMEDIATION"]); export const automatedPRParametersLanguageParameters = z.object({assignees: z.array(z.string()).optional(), labels: z.array(z.string()).optional(), reviewers: z.array(z.string()).optional()}); export const remediationParametersAutomatedPRParameters = z.object({language_parameters: z.record(z.string(), automatedPRParametersLanguageParameters).optional(), max_open_prs: z.number().int().optional()}); export const v1RemediationParameters = z.object({automated_pr_parameters: remediationParametersAutomatedPRParameters.optional()}); export const specNotificationState = z.enum(["NOTIFICATION_STATE_UNSPECIFIED", "NOTIFICATION_STATE_OPEN_NOTIFICATION_PENDING", "NOTIFICATION_STATE_OPEN", "NOTIFICATION_STATE_DISMISSED", "NOTIFICATION_STATE_SNOOZED", "NOTIFICATION_STATE_RESOLVED_NOTIFICATION_PENDING", "NOTIFICATION_STATE_RESOLVED", "NOTIFICATION_STATE_DELETED"]); export const v1NotificationSpec = z.object({aggregation_details: specAggregationDetails.optional(), diff: v1NotificationDiff.optional(), dismiss: specNotificationDismiss.optional(), finding_details: z.record(z.string(), specFindingDetails).optional(), hashsum: z.string().optional(), last_seen_at: z.string().optional(), notification_action_data: z.record(z.string(), v1NotificationActionData).optional(), notification_external_ids: z.array(z.string()).optional(), payload: v1NotificationPayload.optional(), policy_type: policyPolicyType.optional(), policy_uuid: z.string().optional(), project_uuid: z.string(), remediation_parameters: v1RemediationParameters.optional(), repository_version_uuid: z.string().optional(), resolved_at: z.string().optional(), state: specNotificationState}); export const v1TenantMeta = z.object({namespace: z.string()}); export const v1Notification = z.object({context: v1Context.optional(), meta: v1Meta, spec: v1NotificationSpec, tenant_meta: v1TenantMeta.optional(), uuid: z.string().optional()}); export const v1BatchNotificationSpec = z.object({finding_uuids: z.array(z.string()).optional(), notification_target_uuid: z.string().optional(), notifications: z.array(v1Notification).optional()}); export const v1BatchNotification = z.object({meta: v1Meta.optional(), spec: v1BatchNotificationSpec.optional(), tenant_meta: v1TenantMeta.optional(), uuid: z.string().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 }; /** * CreateBatchNotification * * POST /v1/namespaces/{tenant_meta.namespace}/batch/notifications */ export const createApiV1NamespacesTenantMetaNamespaceBatchNotifications = async (args: CreateApiV1NamespacesTenantMetaNamespaceBatchNotificationsArgs, options?: CreateApiV1NamespacesTenantMetaNamespaceBatchNotificationsOptions) => { const {baseUrl = "https://api.endorlabs.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/namespaces/${encodeURIComponent(String(args['tenant_meta.namespace']))}/batch/notifications${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(v1BatchNotification, await res.json()) };