import {z} from 'zod' export type GetApiV1OrgsOrgBillingSubscriptionsArgs = {org: string, superuserForceAccess?: boolean | undefined}; export type GetApiV1OrgsOrgBillingSubscriptionsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const v1OrganizationQuotas = z.object({deployments: z.number().int().optional(), outstandingInvites: z.number().int().optional(), projects: z.number().int().optional(), seats: z.number().int().optional(), slotsPerDeployment: z.number().int().optional(), slotsTotal: z.number().int().optional(), storageLimitBytesPerDeployment: z.string().optional()}); export const v1Organization = z.object({billingCustomerId: z.string().optional(), billingEmail: z.string().optional(), billingPlanDisplayName: z.string().optional(), billingPlanName: z.string().optional(), createdOn: z.string().optional(), customDomain: z.string().optional(), defaultProjectRoleId: z.string().optional(), defaultProvisioner: z.string().optional(), description: z.string().optional(), displayName: z.string().optional(), faviconUrl: z.string().optional(), id: z.string().optional(), logoDarkUrl: z.string().optional(), logoUrl: z.string().optional(), name: z.string().optional(), paymentCustomerId: z.string().optional(), quotas: v1OrganizationQuotas.optional(), thumbnailUrl: z.string().optional(), updatedOn: z.string().optional()}); export const v1BillingPlanType = z.enum(["BILLING_PLAN_TYPE_UNSPECIFIED", "BILLING_PLAN_TYPE_TRIAL", "BILLING_PLAN_TYPE_TEAM", "BILLING_PLAN_TYPE_MANAGED", "BILLING_PLAN_TYPE_ENTERPRISE", "BILLING_PLAN_TYPE_FREE", "BILLING_PLAN_TYPE_PRO", "BILLING_PLAN_TYPE_STARTER", "BILLING_PLAN_TYPE_GROWTH"]); export const v1Quotas = z.object({apiCallsPerSeat: z.string().optional(), deployments: z.string().optional(), outstandingInvites: z.string().optional(), projects: z.string().optional(), seats: z.string().optional(), slotsPerDeployment: z.string().optional(), slotsTotal: z.string().optional(), storageLimitBytesPerDeployment: z.string().optional(), tokensPerSeat: z.string().optional()}); export const v1BillingPlan = z.object({default: z.boolean().optional(), description: z.string().optional(), displayName: z.string().optional(), id: z.string().optional(), name: z.string().optional(), planType: v1BillingPlanType.optional(), public: z.boolean().optional(), quotas: v1Quotas.optional(), trialPeriodDays: z.number().int().optional()}); export const v1Subscription = z.object({currentBillingCycleEndDate: z.string().optional(), currentBillingCycleStartDate: z.string().optional(), endDate: z.string().optional(), id: z.string().optional(), plan: v1BillingPlan.optional(), startDate: z.string().optional(), trialEndDate: z.string().optional()}); export const v1GetBillingSubscriptionResponse = z.object({billingPortalUrl: z.string().optional(), organization: v1Organization.optional(), subscription: v1Subscription.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 }; /** * GetBillingSubscription lists the subscription for the organization * * GET /v1/orgs/{org}/billing/subscriptions */ export const getApiV1OrgsOrgBillingSubscriptions = async (args: GetApiV1OrgsOrgBillingSubscriptionsArgs, options: GetApiV1OrgsOrgBillingSubscriptionsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.superuserForceAccess != null) query.append("superuserForceAccess", String(args.superuserForceAccess)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/orgs/${encodeURIComponent(String(args.org))}/billing/subscriptions${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(v1GetBillingSubscriptionResponse, await res.json()) };