import {z} from 'zod' export type GetApiApiV1AuditLogIdArgs = {id: string, account_id?: string | undefined}; export type GetApiApiV1AuditLogIdOptions = {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 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 }; /** * Get audit log by ID * * GET /api/v1/audit-log/{id} */ export const getApiApiV1AuditLogId = async (args: GetApiApiV1AuditLogIdArgs, options?: GetApiApiV1AuditLogIdOptions) => { 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.account_id != null) query.append("account_id", String(args.account_id)) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/audit-log/${encodeURIComponent(String(args.id))}${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(auditLogResponse, await res.json()) };