Path: blob/master/src/packages/next/lib/api/schema/purchases/get-purchases.ts
1451 views
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(),30compute_server_id: z31.number()32.describe(33"Only get purchases involving this compute server. The id must be the *global* compute server id, not the one local to this project. NOTE: This gets purchases for whoever is the *owner* of the compute server, which might not be the user requesting the purchases.",34)35.nullish(),36project_id: ProjectIdSchema.describe(37"Only get purchases involving this project made by the client making this request. This does not get purchases by other collaborators in this project.",38).nullish(),39group: z40.boolean()41.describe(42`If \`true\`, results are groups by service and project id, and then decreasingly43ordered by cost. Otherwise, results are ordered by time, with the newest44purchases returned first.`,45)46.nullish(),47cutoff: z48.union([z.string(), z.number()])49.describe(50`When provided, only purchases which occur _after_ the timestamp specified in this51field will be returned.`,52)53.nullish(),54thisMonth: z55.boolean()56.describe(57"If `true`, only purchases since the most recent closing date will be returned.",58)59.nullish(),60day_statement_id: DayStatementIdSchema.describe(61"Daily statement id of the statement that includes this purchase",62).nullish(),63month_statement_id: MonthStatementIdSchema.describe(64"Monthly statement id of the statement that includes this purchase",65).nullish(),66no_statement: z67.boolean()68.describe(69`If \`true\`, only purchases which are70_not_ associated with a monthly or daily statement are returned.`,71)72.nullish(),73})74.describe("Gets user purchases.");7576export const GetPurchasesOutputSchema = z.union([77FailedAPIOperationSchema,78z79.object({80balance: z81.number()82.describe(83`The account balance after this purchase was made. For in progress PAYG purchases, e.g., compute servers, this can be complicated -- it's the balance when the purchases table was requested, incorporating the contribution of this purchase so far.`,84),85purchases: z.array(86z.object({87id: PurchaseIdSchema,88time: z.string().describe("Time at which this purchase was logged."),89cost: z.number().describe(90`The cost in US dollars. Not set if the purchase isn't finished, e.g., when91upgrading a project this is only set when project stops or purchase is finalized.92This takes precedence over the \`cost_per_hour\` times the length of the period93when active.`,94),95period_start: z.string().describe(96`When the purchase starts being active (e.g., a 1 week license starts and ends on97specific days; for metered purchases it is when the purchased started charging) `,98),99period_end: z.string().describe(100`When the purchase stops being active. For metered purchases, it's when the101purchase finished being charged, in which case the cost field should be equal to102the length of the period times the \`cost_per_hour\`.`,103),104cost_per_hour: z.number().describe(105`The cost in US dollars per hour. This is used to compute the cost so far for106metered purchases when the cost field isn't set yet. The cost so far is the107number of hours since \`period_start\` times the \`cost_per_hour\`. The108description field may also contain redundant cost per hour information, but this109\`cost_per_hour\` field is the definitive source of truth. Once the \`cost\`110field is set, this \`cost_per_hour\` is just useful for display purposes.`,111),112cost_so_far: z.number().describe(113`The cost so far in US dollars for a metered purchase that accumulates. This is114used, e.g., for data transfer charges.`,115),116service: PurchaseServiceSchema,117description: z.map(z.string(), z.any()).describe(118`An object that provides additional details about what was purchased and can have119an arbitrary format. This is mainly used to provide extra insight when rendering120this purchase for users, and its content should not be relied on for queries.`,121),122invoice_id: InvoiceIdSchema.nullable().describe(123`The id of the Stripe invoice that was sent that included this item. May be124null. **Legacy Behavior:** if paid via a payment intent, this will be the id of125a payment intent instead, and it will start with \`pi_\`.`,126),127project_id: ProjectIdSchema.nullable().describe(128`The id of the project where this purchase happened. Not all purchases129necessarily involve a project, and so this field may be null.`,130),131pending: z132.boolean()133.nullable()134.describe(135`If \`true\`, then this transaction is considered pending, which means that136for a few days it doesn't count against the user's quotas for the purposes of137deciding whether or not a purchase is allowed. This is needed so we can charge138a user for their subscriptions, then collect the money from them, without all139of the running pay-as-you-go project upgrades suddenly breaking (etc.).`,140),141note: z142.string()143.nullable()144.describe(145`Non-private notes about this purchase. The user has read-only access to this146field.`,147),148}),149),150})151.describe(152`An array of purchases filtered and/or grouped according to the provided request153body.`,154),155]);156157export type GetPurchasesInput = z.infer<typeof GetPurchasesInputSchema>;158export type GetPurchasesOutput = z.infer<typeof GetPurchasesOutputSchema>;159160161