import {z} from 'zod' export type GetApiSubscriptionsSubscriptionIdCanUpdateArgs = {subscriptionId: string, plan?: ('development' | 'standard' | 'medium' | 'large' | 'xlarge' | '2xlarge') | undefined, environments?: number | undefined, storage?: number | undefined, user_licenses?: number | undefined}; export type GetApiSubscriptionsSubscriptionIdCanUpdateOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiSubscriptionsSubscriptionIdCanUpdateResponse = z.object({can_update: z.boolean().optional(), message: z.string().optional(), required_action: z.object({}).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 }; /** * Checks if the user is able to update a project. * * GET /subscriptions/{subscriptionId}/can-update */ export const getApiSubscriptionsSubscriptionIdCanUpdate = async (args: GetApiSubscriptionsSubscriptionIdCanUpdateArgs, options?: GetApiSubscriptionsSubscriptionIdCanUpdateOptions) => { const {baseUrl = "https://api.upsun.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.plan != null) query.append("plan", String(args.plan)) if (args.environments != null) query.append("environments", String(args.environments)) if (args.storage != null) query.append("storage", String(args.storage)) if (args.user_licenses != null) query.append("user_licenses", String(args.user_licenses)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/subscriptions/${encodeURIComponent(String(args.subscriptionId))}/can-update${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiSubscriptionsSubscriptionIdCanUpdateResponse, await res.json()) };