import {z} from 'zod' export type TypeMoney = {currencyCode?: string | undefined, units?: unknown | undefined, nanos?: number | undefined}; export type UserUsageLimitIncreaseRequestRequestState = 'REQUEST_STATE_UNSPECIFIED' | 'PENDING' | 'APPROVED' | 'REJECTED'; export type GatewayUserUsageLimitIncreaseRequest = {name?: string | undefined, userId: string, requestedLimit: TypeMoney, requestState?: UserUsageLimitIncreaseRequestRequestState | undefined, createTime?: string | undefined, previousLimit?: TypeMoney | undefined, decisionTime?: string | undefined, decidedBy?: string | undefined}; export type CreateApiV1AccountsAccountIdUsageLimitIncreaseRequestsArgs = {account_id: string, body: GatewayUserUsageLimitIncreaseRequest}; export type CreateApiV1AccountsAccountIdUsageLimitIncreaseRequestsOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const typeMoney = z.object({currencyCode: z.string().optional(), units: z.string().optional(), nanos: z.number().int().optional()}); export const userUsageLimitIncreaseRequestRequestState = z.enum(["REQUEST_STATE_UNSPECIFIED", "PENDING", "APPROVED", "REJECTED"]); export const gatewayUserUsageLimitIncreaseRequest = z.object({name: z.string().optional(), userId: z.string(), requestedLimit: typeMoney, requestState: userUsageLimitIncreaseRequestRequestState.optional(), createTime: z.string().optional(), previousLimit: typeMoney.optional(), decisionTime: z.string().optional(), decidedBy: z.string().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 }; /** * Files a member's request to raise their own per-user serverless cap. * * POST /v1/accounts/{account_id}/usageLimitIncreaseRequests */ export const createApiV1AccountsAccountIdUsageLimitIncreaseRequests = async (args: CreateApiV1AccountsAccountIdUsageLimitIncreaseRequestsArgs, options: CreateApiV1AccountsAccountIdUsageLimitIncreaseRequestsOptions) => { const {baseUrl, 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 (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.account_id))}/usageLimitIncreaseRequests${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(gatewayUserUsageLimitIncreaseRequest, await res.json()) };