import {z} from 'zod' export type ApiServerLimitsExample = {maxRequestPerMinute?: number | undefined}; export type CepLimitsExample = {maxPublishedWorkers?: number | undefined, maxWorkersMemoryMB?: number | undefined, maxMemoryMBPerWorker?: number | undefined, maxWorkersCpuSecondsPerMinute?: number | undefined, maxWorkersThroughputInMBPerMinute?: number | undefined, maxWorkersThroughputOutMBPerMinute?: number | undefined, maxLogsLengthKBPerMinutePerWorker?: number | undefined, maxCpuSecondsPerMinutePerWorker?: number | undefined}; export type DatabaseLimitsExample = {maxDocumentSize?: number | undefined, maxDocumentsReturnedByQuery?: number | undefined, maxQueryExecutionTimeInMs?: number | undefined, maxQueryMemoryBytes?: number | undefined, maxGeoFabricsPerTenant?: number | undefined, maxCollectionsPerFabric?: number | undefined, maxGraphsPerFabric?: number | undefined, maxIndexes?: number | undefined, maxViewsPerFabric?: number | undefined, maxRequestsPerDay?: number | undefined, maxStoragePerRegion?: number | undefined, maxRestQLUsagePerFabric?: number | undefined, maxRestQLUsagePerDay?: number | undefined, maxDocumentsImportedPerAPICall?: number | undefined}; export type EventhubLimitsExample = {maxEventhubProducersCount?: number | undefined, maxEventhubConsumersCount?: number | undefined}; export type StreamsLimitsExample = {maxStreamsCount?: number | undefined, maxProducersCount?: number | undefined, maxConsumersCount?: number | undefined, maxSubscriptionsCount?: number | undefined, maxBacklogMessageTTLMin?: number | undefined, maxBacklogStorageSizeMB?: number | undefined, maxDispatchThrottlingRateInByte?: number | undefined}; export type DmiLimitsExample = {maxConnections?: number | undefined, maxWorkflows?: number | undefined}; export type TenantLimitsValue = {apiServer?: ApiServerLimitsExample | undefined, cep?: CepLimitsExample | undefined, database?: DatabaseLimitsExample | undefined, eventhub?: EventhubLimitsExample | undefined, streamsGlobal?: StreamsLimitsExample | undefined, streamsLocal?: StreamsLimitsExample | undefined, dataMeshIntegration?: DmiLimitsExample | undefined}; export type PatchApiApiLimitsPlanAttributionNameArgs = {attribution: unknown, name: unknown, body: TenantLimitsValue}; export type PatchApiApiLimitsPlanAttributionNameOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiApiLimitsPlanAttributionNameResponse = z.object({code: z.number().int().optional(), error: z.boolean().optional(), result: z.boolean().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 }; /** * Update billing plan limits * * PATCH /_api/limits/plan/{attribution}/{name} * * Also accepts auth: BearerAuth */ export const patchApiApiLimitsPlanAttributionName = async (args: PatchApiApiLimitsPlanAttributionNameArgs, options: PatchApiApiLimitsPlanAttributionNameOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/_api/limits/plan/${encodeURIComponent(String(args.attribution))}/${encodeURIComponent(String(args.name))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiApiLimitsPlanAttributionNameResponse, await res.json()) };