// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../core/resource'; import * as PricesAPI from './prices'; import * as Shared from './shared'; import { APIPromise } from '../core/api-promise'; import { RequestOptions } from '../internal/request-options'; import { path } from '../internal/utils/path'; export class Products extends APIResource { /** * Create Product */ create(body: ProductCreateParams, options?: RequestOptions): APIPromise { return this._client.post('/api/v1/products', { body, ...options }); } /** * Get Product */ retrieve(id: string, options?: RequestOptions): APIPromise { return this._client.get(path`/api/v1/products/${id}`, options); } /** * Update Product */ update(id: string, body: ProductUpdateParams, options?: RequestOptions): APIPromise { return this._client.put(path`/api/v1/products/${id}`, { body, ...options }); } /** * List Products */ list( query: ProductListParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { return this._client.get('/api/v1/products', { query, ...options }); } } export interface ProductClientSelectSchema { id: string; active: boolean; /** * Epoch milliseconds. */ createdAt: number; default: boolean; description: string | null; imageURL: string | null; livemode: boolean; name: string; organizationId: string; pluralQuantityLabel: string | null; pricingModelId: string; singularQuantityLabel: string | null; slug: string | null; /** * Epoch milliseconds. */ updatedAt: number; } export interface ProductCreateResponse { product: ProductClientSelectSchema; } export interface ProductRetrieveResponse { id: string; active: boolean; /** * Epoch milliseconds. */ createdAt: number; default: boolean; /** * The default price for the product. If no price is explicitly set as default, * will return the first price created for the product.. */ defaultPrice: | PricesAPI.SubscriptionPriceClientSelectSchema | PricesAPI.SinglePaymentPriceClientSelectSchema | PricesAPI.UsagePriceClientSelectSchema; description: string | null; features: Array< | Shared.ToggleFeatureClientSelectSchema | Shared.UsageCreditGrantFeatureClientSelectSchema | ProductRetrieveResponse.ResourceFeatureClientSelectSchema >; imageURL: string | null; livemode: boolean; name: string; organizationId: string; pluralQuantityLabel: string | null; prices: Array< | PricesAPI.SubscriptionPriceClientSelectSchema | PricesAPI.SinglePaymentPriceClientSelectSchema | PricesAPI.UsagePriceClientSelectSchema >; pricingModelId: string; singularQuantityLabel: string | null; slug: string | null; /** * Epoch milliseconds. */ updatedAt: number; } export namespace ProductRetrieveResponse { export interface ResourceFeatureClientSelectSchema { id: string; active: boolean; /** * A positive integer */ amount: number; /** * Epoch milliseconds. */ createdAt: number; description: string; livemode: boolean; name: string; organizationId: string; pricingModelId: string; resourceId: string; slug: string; type: 'resource'; /** * Epoch milliseconds. */ updatedAt: number; renewalFrequency?: null; usageMeterId?: null; } } export interface ProductUpdateResponse { product: ProductClientSelectSchema; } export interface ProductListResponse { data: Array; hasMore: boolean; total: number; currentCursor?: string; nextCursor?: string; } export interface ProductCreateParams { price: | ProductCreateParams.ProductSubscriptionPriceInsert | ProductCreateParams.ProductSinglePaymentPriceInsert | ProductCreateParams.ProductUsagePriceInsert; product: ProductCreateParams.Product; featureIds?: Array; } export namespace ProductCreateParams { export interface ProductSubscriptionPriceInsert { /** * A positive integer */ intervalCount: number; intervalUnit: 'day' | 'week' | 'month' | 'year'; /** * Whether or not this price is the default price. For product prices, this * indicates the default price for that product. For usage prices, this indicates * the default price for that usage meter. */ isDefault: boolean; type: 'subscription'; /** * The price per unit. This should be in the smallest unit of the currency. For * example, if the currency is USD, GBP, CAD, EUR or SGD, the price should be in * cents. */ unitPrice: number; active?: boolean; name?: string | null; slug?: string | null; /** * The trial period in days. If the trial period is 0 or null, there will be no * trial period. */ trialPeriodDays?: number | null; /** * Omitted. */ usageEventsPerUnit?: null; /** * Omitted. */ usageMeterId?: null; } export interface ProductSinglePaymentPriceInsert { /** * Whether or not this price is the default price. For product prices, this * indicates the default price for that product. For usage prices, this indicates * the default price for that usage meter. */ isDefault: boolean; type: 'single_payment'; /** * The price per unit. This should be in the smallest unit of the currency. For * example, if the currency is USD, GBP, CAD, EUR or SGD, the price should be in * cents. */ unitPrice: number; active?: boolean; /** * Omitted. */ intervalCount?: null; /** * Omitted. */ intervalUnit?: null; name?: string | null; slug?: string | null; /** * Omitted. */ trialPeriodDays?: null; /** * Omitted. */ usageEventsPerUnit?: null; /** * Omitted. */ usageMeterId?: null; } export interface ProductUsagePriceInsert { /** * A positive integer */ intervalCount: number; intervalUnit: 'day' | 'week' | 'month' | 'year'; /** * Whether or not this price is the default price. For product prices, this * indicates the default price for that product. For usage prices, this indicates * the default price for that usage meter. */ isDefault: boolean; type: 'usage'; /** * The price per unit. This should be in the smallest unit of the currency. For * example, if the currency is USD, GBP, CAD, EUR or SGD, the price should be in * cents. */ unitPrice: number; /** * The number of usage events per unit. Used to determine how to map usage events * to quantities when raising invoices for usage. */ usageEventsPerUnit: number; /** * The usage meter that uses this price. All usage events on that meter must be * associated with a price that is also associated with that usage meter. */ usageMeterId: string; active?: boolean; name?: string | null; slug?: string | null; /** * Omitted. */ trialPeriodDays?: null; } export interface Product { active: boolean; name: string; pricingModelId: string; default?: boolean; description?: string | null; imageURL?: string | null; pluralQuantityLabel?: string | null; singularQuantityLabel?: string | null; slug?: string | null; } } export interface ProductUpdateParams { product: ProductUpdateParams.Product; featureIds?: Array; /** * The latest price fields. Ignored if the product is a default product for its * pricing model. */ price?: | ProductUpdateParams.SubscriptionPriceClientInsertSchema | ProductUpdateParams.SinglePaymentPriceClientInsertSchema | ProductUpdateParams.UsagePriceClientInsertSchema; } export namespace ProductUpdateParams { export interface Product { id: string; active: boolean; name: string; default?: boolean; description?: string | null; imageURL?: string | null; pluralQuantityLabel?: string | null; singularQuantityLabel?: string | null; slug?: string | null; } export interface SubscriptionPriceClientInsertSchema { /** * A positive integer */ intervalCount: number; intervalUnit: 'day' | 'week' | 'month' | 'year'; /** * Whether or not this price is the default price. For product prices, this * indicates the default price for that product. For usage prices, this indicates * the default price for that usage meter. */ isDefault: boolean; /** * The product this price belongs to. Required for subscription prices. */ productId: string; type: 'subscription'; /** * The price per unit. This should be in the smallest unit of the currency. For * example, if the currency is USD, GBP, CAD, EUR or SGD, the price should be in * cents. */ unitPrice: number; active?: boolean; name?: string | null; slug?: string | null; /** * The trial period in days. If the trial period is 0 or null, there will be no * trial period. */ trialPeriodDays?: number | null; /** * Omitted. */ usageEventsPerUnit?: null; /** * Omitted. */ usageMeterId?: null; } export interface SinglePaymentPriceClientInsertSchema { /** * Whether or not this price is the default price. For product prices, this * indicates the default price for that product. For usage prices, this indicates * the default price for that usage meter. */ isDefault: boolean; /** * The product this price belongs to. Required for single payment prices. */ productId: string; type: 'single_payment'; /** * The price per unit. This should be in the smallest unit of the currency. For * example, if the currency is USD, GBP, CAD, EUR or SGD, the price should be in * cents. */ unitPrice: number; active?: boolean; /** * Omitted. */ intervalCount?: null; /** * Omitted. */ intervalUnit?: null; name?: string | null; slug?: string | null; /** * Omitted. */ trialPeriodDays?: null; /** * Omitted. */ usageEventsPerUnit?: null; /** * Omitted. */ usageMeterId?: null; } export interface UsagePriceClientInsertSchema { /** * A positive integer */ intervalCount: number; intervalUnit: 'day' | 'week' | 'month' | 'year'; /** * Whether or not this price is the default price. For product prices, this * indicates the default price for that product. For usage prices, this indicates * the default price for that usage meter. */ isDefault: boolean; type: 'usage'; /** * The price per unit. This should be in the smallest unit of the currency. For * example, if the currency is USD, GBP, CAD, EUR or SGD, the price should be in * cents. */ unitPrice: number; /** * The number of usage events per unit. Used to determine how to map usage events * to quantities when raising invoices for usage. */ usageEventsPerUnit: number; /** * The usage meter that uses this price. All usage events on that meter must be * associated with a price that is also associated with that usage meter. */ usageMeterId: string; active?: boolean; name?: string | null; /** * Omitted. */ productId?: null; slug?: string | null; /** * Omitted. */ trialPeriodDays?: null; } } export interface ProductListParams { cursor?: string; limit?: string; } export declare namespace Products { export { type ProductClientSelectSchema as ProductClientSelectSchema, type ProductCreateResponse as ProductCreateResponse, type ProductRetrieveResponse as ProductRetrieveResponse, type ProductUpdateResponse as ProductUpdateResponse, type ProductListResponse as ProductListResponse, type ProductCreateParams as ProductCreateParams, type ProductUpdateParams as ProductUpdateParams, type ProductListParams as ProductListParams, }; }