Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/lib/api/schema/purchases/get-purchases.ts
Views: 688
import { z } from "../../framework";12import { FailedAPIOperationSchema } from "../common";3import { ProjectIdSchema } from "../projects/common";45import {6DayStatementIdSchema,7InvoiceIdSchema,8MonthStatementIdSchema,9PurchaseIdSchema,10} from "./common";1112const PurchaseServiceSchema = z13.string()14.describe("The service being charged for, e.g., `openai-gpt-4`, etc.");1516// OpenAPI spec17//18export const GetPurchasesInputSchema = z19.object({20limit: z21.number()22.default(100)23.describe("Upper bound on the number of purchases to return.")24.nullish(),25offset: z26.number()27.describe("Number of purchases by which to offset results.")28.nullish(),29service: PurchaseServiceSchema.nullish(),30project_id: ProjectIdSchema.describe(31"The project id associated with this purchase, if one exists.",32).nullish(),33group: z34.boolean()35.describe(36`If \`true\`, results are groups by service and project id, and then decreasingly37ordered by cost. Otherwise, results are ordered by time, with the newest38purchases returned first.`,39)40.nullish(),41cutoff: z42.union([z.string(), z.number()])43.describe(44`When provided, only purchases which occur _after_ the timestamp specified in this45field will be returned.`,46)47.nullish(),48thisMonth: z49.boolean()50.describe(51"If `true`, only purchases since the most recent closing date will be returned.",52)53.nullish(),54day_statement_id: DayStatementIdSchema.describe(55"Daily statement id of the statement that includes this purchase",56).nullish(),57month_statement_id: MonthStatementIdSchema.describe(58"Monthly statement id of the statement that includes this purchase",59).nullish(),60no_statement: z61.boolean()62.describe(63`If \`true\`, only purchases which are64_not_ associated with a monthly or daily statement are returned.`,65)66.nullish(),67})68.describe("Gets user purchases.");6970export const GetPurchasesOutputSchema = z.union([71FailedAPIOperationSchema,72z73.array(74z.object({75id: PurchaseIdSchema,76time: z.string().describe("Time at which this purchase was logged."),77cost: z.number().describe(78`The cost in US dollars. Not set if the purchase isn't finished, e.g., when79upgrading a project this is only set when project stops or purchase is finalized.80This takes precedence over the \`cost_per_hour\` times the length of the period81when active.`,82),83period_start: z.string().describe(84`When the purchase starts being active (e.g., a 1 week license starts and ends on85specific days; for metered purchases it is when the purchased started charging) `,86),87period_end: z.string().describe(88`When the purchase stops being active. For metered purchases, it's when the89purchase finished being charged, in which case the cost field should be equal to90the length of the period times the \`cost_per_hour\`.`,91),92cost_per_hour: z.number().describe(93`The cost in US dollars per hour. This is used to compute the cost so far for94metered purchases when the cost field isn't set yet. The cost so far is the95number of hours since \`period_start\` times the \`cost_per_hour\`. The96description field may also contain redundant cost per hour information, but this97\`cost_per_hour\` field is the definitive source of truth. Once the \`cost\`98field is set, this \`cost_per_hour\` is just useful for display purposes.`,99),100cost_so_far: z.number().describe(101`The cost so far in US dollars for a metered purchase that accumulates. This is102used, e.g., for data transfer charges.`,103),104service: PurchaseServiceSchema,105description: z.map(z.string(), z.any()).describe(106`An object that provides additional details about what was purchased and can have107an arbitrary format. This is mainly used to provide extra insight when rendering108this purchase for users, and its content should not be relied on for queries.`,109),110invoice_id: InvoiceIdSchema.nullable().describe(111`The id of the Stripe invoice that was sent that included this item. May be112null. **Legacy Behavior:** if paid via a payment intent, this will be the id of113a payment intent instead, and it will start with \`pi_\`.`,114),115project_id: ProjectIdSchema.nullable().describe(116`The id of the project where this purchase happened. Not all purchases117necessarily involve a project, and so this field may be null.`,118),119pending: z120.boolean()121.nullable()122.describe(123`If \`true\`, then this transaction is considered pending, which means that124for a few days it doesn't count against the user's quotas for the purposes of125deciding whether or not a purchase is allowed. This is needed so we can charge126a user for their subscriptions, then collect the money from them, without all127of the running pay-as-you-go project upgrades suddenly breaking (etc.).`,128),129note: z130.string()131.nullable()132.describe(133`Non-private notes about this purchase. The user has read-only access to this134field.`,135),136}),137)138.describe(139`An array of purchases filtered and/or grouped according to the provided request140body.`,141),142]);143144export type GetPurchasesInput = z.infer<typeof GetPurchasesInputSchema>;145export type GetPurchasesOutput = z.infer<typeof GetPurchasesOutputSchema>;146147148