import {z} from 'zod' export type GetApiV1HoneytokensHoneytokenIdActivityLogsArgs = {honeytoken_id: string, cursor?: string | undefined, per_page?: number | undefined, ordering?: ('created_at' | '-created_at' | 'updated_at' | '-updated_at') | undefined, member_id?: number | undefined, api_token_id?: string | undefined, content_key?: string | undefined, search?: string | undefined}; export type GetApiV1HoneytokensHoneytokenIdActivityLogsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1HoneytokensHoneytokenIdActivityLogsResponse = z.array(z.object({id: z.string().optional(), honeytoken_id: z.string().optional(), honey_token_deployment_id: z.string().nullable().optional(), member: z.object({id: z.number().int().optional(), name: z.string().optional(), email: z.string().optional(), access_level: z.string().optional()}).nullable().optional(), api_token_id: z.string().nullable().optional(), created_at: z.string().optional(), updated_at: z.string().nullable().optional(), content: z.discriminatedUnion("type", [z.object({type: z.literal("note").optional(), comment: z.string().max(10000).optional()}), z.object({type: z.literal("action").optional(), content_key: z.string().optional(), data: z.record(z.string(), z.unknown()).nullable().optional()})]).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 activity logs of a honeytoken * * GET /v1/honeytokens/{honeytoken_id}/activity-logs */ export const getApiV1HoneytokensHoneytokenIdActivityLogs = async (args: GetApiV1HoneytokensHoneytokenIdActivityLogsArgs, options?: GetApiV1HoneytokensHoneytokenIdActivityLogsOptions) => { const {baseUrl = "https://api.gitguardian.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.ordering != null) query.append("ordering", String(args.ordering)) if (args.member_id != null) query.append("member_id", String(args.member_id)) if (args.api_token_id != null) query.append("api_token_id", String(args.api_token_id)) if (args.content_key != null) query.append("content_key", String(args.content_key)) if (args.search != null) query.append("search", String(args.search)) if (apiKey !== undefined) headers.set('authorization', `Bearer ${apiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/honeytokens/${encodeURIComponent(String(args.honeytoken_id))}/activity-logs${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(getApiV1HoneytokensHoneytokenIdActivityLogsResponse, await res.json()) };