import {z} from 'zod' export type GetApiV1OrgsOrgBillingIssuesArgs = {org: string, superuserForceAccess?: boolean | undefined}; export type GetApiV1OrgsOrgBillingIssuesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const v1BillingIssueLevel = z.enum(["BILLING_ISSUE_LEVEL_UNSPECIFIED", "BILLING_ISSUE_LEVEL_WARNING", "BILLING_ISSUE_LEVEL_ERROR"]); export const v1BillingIssueMetadataMessage = z.object({message: z.string().optional()}); export const v1BillingIssueMetadataNeverSubscribed = z.object({}); export const v1BillingIssueMetadataNoBillableAddress = z.object({}); export const v1BillingIssueMetadataNoPaymentMethod = z.object({}); export const v1BillingIssueMetadataOnCreditTrial = z.object({creditAllocation: z.number().optional(), lowCredit: z.boolean().optional(), planId: z.string().optional(), subscriptionId: z.string().optional()}); export const v1BillingIssueMetadataOnTrial = z.object({endDate: z.string().optional(), gracePeriodEndDate: z.string().optional()}); export const v1BillingIssueMetadataPaymentFailedMeta = z.object({amountDue: z.string().optional(), currency: z.string().optional(), dueDate: z.string().optional(), failedOn: z.string().optional(), gracePeriodEndDate: z.string().optional(), invoiceId: z.string().optional(), invoiceNumber: z.string().optional(), invoiceUrl: z.string().optional()}); export const v1BillingIssueMetadataPaymentFailed = z.object({invoices: z.array(v1BillingIssueMetadataPaymentFailedMeta).optional()}); export const v1BillingIssueMetadataSubscriptionCancelled = z.object({endDate: z.string().optional()}); export const v1BillingIssueMetadataTrialCreditsDepleted = z.object({depletedOn: z.string().optional(), planId: z.string().optional(), subscriptionId: z.string().optional()}); export const v1BillingIssueMetadataTrialEnded = z.object({endDate: z.string().optional(), gracePeriodEndDate: z.string().optional()}); export const v1BillingIssueMetadata = z.object({message: v1BillingIssueMetadataMessage.optional(), neverSubscribed: v1BillingIssueMetadataNeverSubscribed.optional(), noBillableAddress: v1BillingIssueMetadataNoBillableAddress.optional(), noPaymentMethod: v1BillingIssueMetadataNoPaymentMethod.optional(), onCreditTrial: v1BillingIssueMetadataOnCreditTrial.optional(), onTrial: v1BillingIssueMetadataOnTrial.optional(), paymentFailed: v1BillingIssueMetadataPaymentFailed.optional(), subscriptionCancelled: v1BillingIssueMetadataSubscriptionCancelled.optional(), trialCreditsDepleted: v1BillingIssueMetadataTrialCreditsDepleted.optional(), trialEnded: v1BillingIssueMetadataTrialEnded.optional()}); export const v1BillingIssueType = z.enum(["BILLING_ISSUE_TYPE_UNSPECIFIED", "BILLING_ISSUE_TYPE_ON_TRIAL", "BILLING_ISSUE_TYPE_TRIAL_ENDED", "BILLING_ISSUE_TYPE_NO_PAYMENT_METHOD", "BILLING_ISSUE_TYPE_NO_BILLABLE_ADDRESS", "BILLING_ISSUE_TYPE_PAYMENT_FAILED", "BILLING_ISSUE_TYPE_SUBSCRIPTION_CANCELLED", "BILLING_ISSUE_TYPE_NEVER_SUBSCRIBED", "BILLING_ISSUE_TYPE_ON_CREDIT_TRIAL", "BILLING_ISSUE_TYPE_TRIAL_CREDITS_DEPLETED", "BILLING_ISSUE_TYPE_MESSAGE"]); export const v1BillingIssue = z.object({createdOn: z.string().optional(), eventTime: z.string().optional(), level: v1BillingIssueLevel.optional(), metadata: v1BillingIssueMetadata.optional(), org: z.string().optional(), type: v1BillingIssueType.optional()}); export const v1ListOrganizationBillingIssuesResponse = z.object({issues: z.array(v1BillingIssue).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 }; /** * ListOrganizationBillingIssues lists all the billing issues for the organization * * GET /v1/orgs/{org}/billing/issues */ export const getApiV1OrgsOrgBillingIssues = async (args: GetApiV1OrgsOrgBillingIssuesArgs, options: GetApiV1OrgsOrgBillingIssuesOptions) => { 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/issues${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(v1ListOrganizationBillingIssuesResponse, await res.json()) };