import {z} from 'zod' export type GetApiChangelogSharedRulesGraphSharedRulesKeyArgs = {sharedRulesKey: string, start?: number | undefined, end?: number | undefined, max_results?: number | undefined, ref_id?: string | undefined, direction?: ('before' | 'after') | undefined}; export type GetApiChangelogSharedRulesGraphSharedRulesKeyOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const changeEntry = z.object({object_type: z.enum(["org", "user", "zone", "proxy", "domain", "route", "shared_rules", "cluster"]).optional(), change_type: z.enum(["addition", "removal"]).optional(), object_key: z.string().optional(), zone_key: z.string().optional(), path: z.string().optional(), value: z.string().optional()}); export const changeDescription = z.object({at: z.number().optional(), txn: z.string().optional(), actor_key: z.string().optional(), comment: z.string().optional(), diffs: z.array(changeEntry).optional()}); export const pageDetails = z.object({total_entries: z.number().int().optional(), has_more: z.boolean().optional(), direction: z.enum(["before", "after"]).optional(), ref_id: z.string().optional()}); export const paginationDetails = z.object({pagination: pageDetails.optional()}); export const paginatedChangeDescriptions = z.object({result: z.array(changeDescription).optional(), details: paginationDetails.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 changes related to the indicated SharedRules * * GET /changelog/shared-rules-graph/{sharedRulesKey} */ export const getApiChangelogSharedRulesGraphSharedRulesKey = async (args: GetApiChangelogSharedRulesGraphSharedRulesKeyArgs, options?: GetApiChangelogSharedRulesGraphSharedRulesKeyOptions) => { const {baseUrl = "https://api.turbinelabs.io/v1.0", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.start != null) query.append("start", String(args.start)) if (args.end != null) query.append("end", String(args.end)) if (args.max_results != null) query.append("max_results", String(args.max_results)) if (args.ref_id != null) query.append("ref_id", String(args.ref_id)) if (args.direction != null) query.append("direction", String(args.direction)) if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/changelog/shared-rules-graph/${encodeURIComponent(String(args.sharedRulesKey))}${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(paginatedChangeDescriptions, await res.json()) };