import {z} from 'zod' export type CredentialProfileCertType = 'ESEAL' | 'INDIVIDUAL' | 'INDIVIDUAL_WITH_ORGANIZATION' | 'PROFESSIONAL' | 'CLIENT_AUTHENTICATION'; export type CertificateProfileType = 'ADVANCED_PLUS' | 'QUALIFIED' | 'BASIC'; export type GetApiApiV1AuditLogCursorArgs = {cursor_timestamp?: string | undefined, cursor_id?: string | undefined, limit?: number | undefined, direction?: ('NEXT' | 'PREVIOUS') | undefined, sort_by?: 'timestamp' | undefined, sort_order?: ('ASC' | 'DESC') | undefined, id?: string | undefined, action?: ('SIGN' | 'UPDATE' | 'ENABLE' | 'DISABLE' | 'CREATE' | 'DELETE' | 'EMAIL_SENT' | 'FETCH' | 'AUTHORIZE' | 'SEND_OTP' | 'REVOKE' | 'VERIFY' | 'LIST') | undefined, resource_type?: ('VALIDATION' | 'SIGNATURE' | 'LICENSE' | 'CREDENTIAL' | 'TIMESTAMP' | 'MANAGER_CONFIG' | 'DSE_ACCOUNT' | 'DSE_PROFILE' | 'CERTIFICATE_PROFILE' | 'SIGNING_PROVIDER' | 'DOCUMENT' | 'CERTIFICATE' | 'SELF_ENROLLMENT_LINK' | 'VALIDATION_PROFILE' | 'DSM_CERTIFICATE_TEMPLATE' | 'DSM_CERTIFICATE_PROFILE' | 'MIGRATION' | 'PRODUCT' | 'ONBOARDING' | 'SIGNER' | 'USER') | undefined, resource_id?: string | undefined, account_id?: string | undefined, user_id?: string | undefined, start_date?: string | undefined, end_date?: string | undefined, status?: ('SUCCESS' | 'FAILURE') | undefined, created_by?: string | undefined, certificate_type?: Array | undefined, certificate_level?: Array | undefined}; export type GetApiApiV1AuditLogCursorOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const certificateProfileType = z.enum(["ADVANCED_PLUS", "QUALIFIED", "BASIC"]); export const credentialProfileCertType = z.enum(["ESEAL", "INDIVIDUAL", "INDIVIDUAL_WITH_ORGANIZATION", "PROFESSIONAL", "CLIENT_AUTHENTICATION"]); export const auditLogResponse = z.object({id: z.string().optional(), account_id: z.string().optional(), resource_type: z.enum(["VALIDATION", "SIGNATURE", "LICENSE", "CREDENTIAL", "TIMESTAMP", "MANAGER_CONFIG", "DSE_ACCOUNT", "DSE_PROFILE", "CERTIFICATE_PROFILE", "SIGNING_PROVIDER", "DOCUMENT", "CERTIFICATE", "SELF_ENROLLMENT_LINK", "VALIDATION_PROFILE", "DSM_CERTIFICATE_TEMPLATE", "DSM_CERTIFICATE_PROFILE", "MIGRATION", "PRODUCT", "ONBOARDING", "SIGNER", "USER"]).optional(), resource_id: z.string().optional(), action: z.enum(["SIGN", "UPDATE", "CREATE", "DELETE", "EMAIL_SENT", "FETCH", "AUTHORIZE", "SEND_OTP", "ENABLE", "DISABLE", "CANCEL", "REVOKE", "SIGNING_HUB_USER_CREATION", "HASH_ENHANCEMENT", "SIGNATURE_ENHANCEMENT"]).optional(), auth_type: z.enum(["BASIC", "API_TOKEN", "INTERNAL"]).optional(), timestamp: z.string().optional(), description: z.string().optional(), status: z.enum(["SUCCESS", "FAILURE"]).optional(), error_message: z.string().optional(), data: z.string().optional(), userId: z.string().optional(), created_by: z.string().optional(), hash: z.string().optional(), number_hashes: z.number().int().optional(), license_hash_enabled: z.boolean().optional(), certificateLevel: certificateProfileType.optional(), certificateType: credentialProfileCertType.optional()}); export const paginationInfo = z.object({count: z.number().int().optional(), limit: z.number().int().optional(), has_next: z.boolean().optional(), has_previous: z.boolean().optional(), next_cursor_timestamp: z.string().optional(), next_cursor_id: z.string().optional(), previous_cursor_timestamp: z.string().optional(), previous_cursor_id: z.string().optional()}); export const auditLogSearchCursorResponse = z.object({data: z.array(auditLogResponse).optional(), pagination: paginationInfo.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 }; /** * List audit logs using cursor pagination * * GET /api/v1/audit-log/cursor */ export const getApiApiV1AuditLogCursor = async (args: GetApiApiV1AuditLogCursorArgs, options?: GetApiApiV1AuditLogCursorOptions) => { const {baseUrl = "https://one.digicert.com/documentmanager", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.cursor_timestamp != null) query.append("cursor_timestamp", String(args.cursor_timestamp)) if (args.cursor_id != null) query.append("cursor_id", String(args.cursor_id)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.direction != null) query.append("direction", String(args.direction)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (args.id != null) query.append("id", String(args.id)) if (args.action != null) query.append("action", String(args.action)) if (args.resource_type != null) query.append("resource_type", String(args.resource_type)) if (args.resource_id != null) query.append("resource_id", String(args.resource_id)) if (args.account_id != null) query.append("account_id", String(args.account_id)) if (args.user_id != null) query.append("user_id", String(args.user_id)) if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) if (args.status != null) query.append("status", String(args.status)) if (args.created_by != null) query.append("created_by", String(args.created_by)) for (const item of args.certificate_type ?? []) query.append("certificate_type", String(item)) for (const item of args.certificate_level ?? []) query.append("certificate_level", String(item)) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/audit-log/cursor${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(auditLogSearchCursorResponse, await res.json()) };