import {z} from 'zod' export type TeamV1GrantTeamQuotaRequest = {amountMicros?: string | undefined, remark?: string | undefined, teamId?: string | undefined}; export type CreateApiV1TeamsTeamIdQuotaGrantsArgs = {teamId: string, body: TeamV1GrantTeamQuotaRequest}; export type CreateApiV1TeamsTeamIdQuotaGrantsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const teamV1QuotaGrantInfo = z.object({action: z.string().optional(), amountMicros: z.string().optional(), balanceAfterMicros: z.string().optional(), createdAt: z.string().optional(), grantId: z.string().optional(), memberId: z.string().optional(), operatorId: z.string().optional(), operatorName: z.string().optional(), remark: z.string().optional(), teamId: z.string().optional()}); export const teamV1GrantTeamQuotaReply = z.object({grant: teamV1QuotaGrantInfo.optional(), totalQuotaMicros: 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 }; /** * GrantTeamQuota 给团队增量增加可用额度(仅 owner):total_quota_micros += amount, * * POST /v1/teams/{teamId}/quota/grants */ export const createApiV1TeamsTeamIdQuotaGrants = async (args: CreateApiV1TeamsTeamIdQuotaGrantsArgs, options: CreateApiV1TeamsTeamIdQuotaGrantsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/teams/${encodeURIComponent(String(args.teamId))}/quota/grants${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(teamV1GrantTeamQuotaReply, await res.json()) };