import {z} from 'zod' export type CreateApiV1HoneytokensHoneytokenIdResetArgs = {honeytoken_id: string, 'X-Privacy-Mode'?: ('true' | 'false') | undefined}; export type CreateApiV1HoneytokensHoneytokenIdResetOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1HoneytokensHoneytokenIdResetResponse = z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), created_at: z.string().optional(), gitguardian_url: z.string().optional(), status: z.enum(["active", "triggered", "revoked"]).optional(), triggered_at: z.string().optional(), revoked_at: z.string().optional(), open_events_count: z.number().int().optional(), type: z.literal("AWS").optional(), creator_id: z.number().int().nullable().optional(), revoker_id: z.number().int().nullable().optional(), creator_api_token_id: z.string().nullable().optional(), revoker_api_token_id: z.string().nullable().optional(), token: z.object({}).optional(), tags: z.array(z.literal("publicly_exposed")).optional(), custom_tags: z.array(z.object({id: z.string().optional(), key: z.string().optional(), value: z.string().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 }; /** * Reset the honeytoken * * POST /v1/honeytokens/{honeytoken_id}/reset */ export const createApiV1HoneytokensHoneytokenIdReset = async (args: CreateApiV1HoneytokensHoneytokenIdResetArgs, options?: CreateApiV1HoneytokensHoneytokenIdResetOptions) => { 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['X-Privacy-Mode'] != null) headers.set("X-Privacy-Mode", String(args['X-Privacy-Mode'])) if (apiKey !== undefined) headers.set('authorization', `Bearer ${apiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/honeytokens/${encodeURIComponent(String(args.honeytoken_id))}/reset${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiV1HoneytokensHoneytokenIdResetResponse, await res.json()) };