import {z} from 'zod' export type UpdateApiTenantsIdConfigArgs = {'X-Steward-Request-Timestamp'?: string | undefined, 'X-Steward-Request-Expires-At'?: string | undefined, 'X-Steward-Signature'?: string | undefined, 'X-Steward-Signing-Key-Id'?: string | undefined, 'Idempotency-Key'?: string | undefined, body: {tenantId: string, displayName?: string | undefined, policyExposure?: {[key: string]: unknown} | undefined, policyTemplates?: Array<{[key: string]: unknown}> | undefined, secretRoutePresets?: Array<{[key: string]: unknown}> | undefined, approvalConfig?: {[key: string]: unknown} | undefined, featureFlags?: {[key: string]: unknown} | undefined, theme?: {[key: string]: unknown} | undefined, allowedOrigins?: Array | undefined, allowedRedirectUrls?: Array | undefined, oidcProviders?: Array<{[key: string]: unknown}> | undefined, authAbuseConfig?: {[key: string]: unknown} | undefined, appClients?: Array<{[key: string]: unknown}> | undefined, testAccount?: {[key: string]: unknown} | undefined, gasSponsorshipConfig?: {[key: string]: unknown} | undefined, createdAt?: string | undefined, updatedAt?: string | undefined} | {[key: string]: unknown}}; export type UpdateApiTenantsIdConfigOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiTenantsIdConfigResponse = z.object({ok: z.literal(true), data: z.object({tenantId: z.string(), displayName: z.string().optional(), policyExposure: z.record(z.string(), z.unknown()).optional(), policyTemplates: z.array(z.record(z.string(), z.unknown())).optional(), secretRoutePresets: z.array(z.record(z.string(), z.unknown())).optional(), approvalConfig: z.record(z.string(), z.unknown()).optional(), featureFlags: z.record(z.string(), z.unknown()).optional(), theme: z.record(z.string(), z.unknown()).optional(), allowedOrigins: z.array(z.string()).optional(), allowedRedirectUrls: z.array(z.string()).optional(), oidcProviders: z.array(z.record(z.string(), z.unknown())).optional(), authAbuseConfig: z.record(z.string(), z.unknown()).optional(), appClients: z.array(z.record(z.string(), z.unknown())).optional(), testAccount: z.record(z.string(), z.unknown()).optional(), gasSponsorshipConfig: z.record(z.string(), z.unknown()).optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()}).and(z.record(z.string(), 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 }; /** * Update tenant control-plane config * * PUT /tenants/{id}/config */ export const updateApiTenantsIdConfig = async (args: UpdateApiTenantsIdConfigArgs, options?: UpdateApiTenantsIdConfigOptions) => { const {baseUrl = "http://localhost:3200", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Steward-Request-Timestamp'] != null) headers.set("X-Steward-Request-Timestamp", String(args['X-Steward-Request-Timestamp'])) if (args['X-Steward-Request-Expires-At'] != null) headers.set("X-Steward-Request-Expires-At", String(args['X-Steward-Request-Expires-At'])) if (args['X-Steward-Signature'] != null) headers.set("X-Steward-Signature", String(args['X-Steward-Signature'])) if (args['X-Steward-Signing-Key-Id'] != null) headers.set("X-Steward-Signing-Key-Id", String(args['X-Steward-Signing-Key-Id'])) if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/tenants/${encodeURIComponent(String(args.id))}/config${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(updateApiTenantsIdConfigResponse, await res.json()) };