import {z} from 'zod' export type CreateApiSimulationsCustomersCustomerIdAgentsAgentIdRevokeArgs = {customerId: string, agentId: string, 'Idempotency-Key': string, 'X-Instance-ID'?: (string | null) | undefined}; export type CreateApiSimulationsCustomersCustomerIdAgentsAgentIdRevokeOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiSimulationsCustomersCustomerIdAgentsAgentIdRevokeResponse = z.union([z.object({data: z.object({type: z.literal("customer"), id: z.string(), attributes: z.object({name: z.string(), email: z.string().nullable(), phone: z.string().nullable(), avatarUrl: z.string().nullable(), createdAt: z.string().nullable(), delegation: z.object({id: z.string(), status: z.enum(["ACTIVE", "SUSPENDED", "REVOKED", "EXPIRED"]), permissions: z.array(z.string()), createdAt: z.string(), revokedAt: z.string().nullable()}), agents: z.array(z.object({id: z.string(), name: z.string().nullable(), handle: z.string().nullable(), status: z.string(), permissions: z.array(z.string()), limits: z.object({perTransaction: z.number().int().gt(0).nullable().optional(), perDay: z.number().int().gt(0).nullable().optional(), perMonth: z.number().int().gt(0).nullable().optional()}).nullable()}))})})}), z.object({data: z.object({type: z.literal("customer"), id: z.string(), attributes: z.object({name: z.string(), email: z.string().nullable(), phone: z.string().nullable(), avatarUrl: z.string().nullable(), createdAt: z.string().nullable(), delegation: z.object({id: z.string(), status: z.enum(["ACTIVE", "SUSPENDED", "REVOKED", "EXPIRED"]), permissions: z.array(z.string()), createdAt: z.string(), revokedAt: z.string().nullable()}), agents: z.array(z.object({id: z.string(), name: z.string().nullable(), handle: z.string().nullable(), status: z.string(), permissions: z.array(z.string()), limits: z.object({perTransaction: z.number().int().gt(0).nullable().optional(), perDay: z.number().int().gt(0).nullable().optional(), perMonth: z.number().int().gt(0).nullable().optional()}).nullable()}))})}), meta: z.object({deleted: z.unknown()})})]); 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 }; /** * Revoke agent access as test customer * * POST /simulations/customers/{customerId}/agents/{agentId}/revoke */ export const createApiSimulationsCustomersCustomerIdAgentsAgentIdRevoke = async (args: CreateApiSimulationsCustomersCustomerIdAgentsAgentIdRevokeArgs, options?: CreateApiSimulationsCustomersCustomerIdAgentsAgentIdRevokeOptions) => { const {baseUrl = "https://api.sandbox.natural.com", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (args['X-Instance-ID'] != null) headers.set("X-Instance-ID", String(args['X-Instance-ID'])) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/simulations/customers/${encodeURIComponent(String(args.customerId))}/agents/${encodeURIComponent(String(args.agentId))}/revoke${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(createApiSimulationsCustomersCustomerIdAgentsAgentIdRevokeResponse, await res.json()) };