import {z} from 'zod' export type GetApiApiPlatformFgaAuditArgs = {object?: (string | null) | undefined, user?: (string | null) | undefined, actorId?: (string | null) | undefined, requestOperation?: (string | null) | undefined, relation?: (string | null) | undefined, allowed?: (boolean | null) | undefined, client?: (string | null) | undefined, trace?: (string | null) | undefined, httpMethod?: (string | null) | undefined, httpStatus?: (number | null) | undefined, httpService?: (string | null) | undefined, from?: (string | null) | undefined, to?: (string | null) | undefined, page?: number | undefined, per_page?: number | undefined}; export type GetApiApiPlatformFgaAuditOptions = {baseUrl: string, Auth0AuthorizationCode?: string | undefined, fetch?: typeof fetch | undefined}; export const fgaTupleAuditItem = z.object({id: z.string(), occurredAt: z.string(), operation: z.string(), requestOperation: z.string(), user: z.string().nullable().optional(), relation: z.string().nullable().optional(), object: z.string().nullable().optional(), condition: z.record(z.string(), z.unknown()).nullable().optional(), fgaRequestId: z.string(), fgaClientId: z.string(), fgaClientName: z.string().nullable().optional(), actorId: z.string().nullable().optional(), actorIp: z.string().nullable().optional(), userAgent: z.string().nullable().optional(), correlationId: z.string().nullable().optional(), region: z.string().nullable().optional(), requestDuration: z.string().nullable().optional(), authorizationModelId: z.string().nullable().optional(), accountId: z.string().nullable().optional(), writesOnDuplicate: z.string().nullable().optional(), deletesOnMissing: z.string().nullable().optional(), fgaQueryDurationMs: z.string().nullable().optional(), fgaResponseRequestId: z.string().nullable().optional(), responseHeaders: z.record(z.string(), z.unknown()).nullable().optional(), allowed: z.boolean().nullable().optional(), statusCode: z.number().int(), storeId: z.string(), httpMethod: z.string().nullable().optional(), httpStatus: z.number().int().nullable().optional(), httpUrl: z.string().nullable().optional(), httpService: z.string().nullable().optional(), httpProject: z.string().nullable().optional()}); export const fgaTupleAuditListResponse = z.object({items: z.array(fgaTupleAuditItem), total: z.number().int(), page: z.number().int(), perPage: z.number().int()}); 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 Fga Tuple Audit * * GET /api/platform/fga-audit */ export const getApiApiPlatformFgaAudit = async (args: GetApiApiPlatformFgaAuditArgs, options: GetApiApiPlatformFgaAuditOptions) => { const {baseUrl, fetch: fetchFn = fetch, Auth0AuthorizationCode} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.object != null) query.append("object", String(args.object)) if (args.user != null) query.append("user", String(args.user)) if (args.actorId != null) query.append("actorId", String(args.actorId)) if (args.requestOperation != null) query.append("requestOperation", String(args.requestOperation)) if (args.relation != null) query.append("relation", String(args.relation)) if (args.allowed != null) query.append("allowed", String(args.allowed)) if (args.client != null) query.append("client", String(args.client)) if (args.trace != null) query.append("trace", String(args.trace)) if (args.httpMethod != null) query.append("httpMethod", String(args.httpMethod)) if (args.httpStatus != null) query.append("httpStatus", String(args.httpStatus)) if (args.httpService != null) query.append("httpService", String(args.httpService)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (Auth0AuthorizationCode !== undefined) headers.set('authorization', `Bearer ${Auth0AuthorizationCode}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/platform/fga-audit${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(fgaTupleAuditListResponse, await res.json()) };