From d28b462b265de7ddae7a4e21aeafc8984645db87 Mon Sep 17 00:00:00 2001 From: stainless-bot Date: Mon, 10 Jun 2024 22:48:43 +0000 Subject: [PATCH] feat(api): update via SDK Studio --- api.md | 30 ++-- src/index.ts | 17 +- src/pagination.ts | 78 +++++++++ src/resources/audit-logs.ts | 74 +++----- src/resources/billable-metrics.ts | 45 ++--- src/resources/credit-grants.ts | 251 +++++++++++++-------------- src/resources/customers/customers.ts | 137 ++++++--------- src/resources/customers/index.ts | 8 +- src/resources/customers/invoices.ts | 34 ++-- src/resources/customers/plans.ts | 160 ++++++++--------- src/resources/index.ts | 18 +- src/resources/plans.ts | 225 +++++++++++------------- src/resources/usage.ts | 43 ++--- 13 files changed, 543 insertions(+), 577 deletions(-) create mode 100644 src/pagination.ts diff --git a/api.md b/api.md index a7d6725..1356287 100644 --- a/api.md +++ b/api.md @@ -36,10 +36,10 @@ Types: Methods: -- client.plans.list({ ...params }) -> PlanListResponse +- client.plans.list({ ...params }) -> PlanListResponsesCursorPage - client.plans.getDetails(planId) -> PlanGetDetailsResponse -- client.plans.listCharges(planId, { ...params }) -> PlanListChargesResponse -- client.plans.listCustomers(planId, { ...params }) -> PlanListCustomersResponse +- client.plans.listCharges(planId, { ...params }) -> PlanListChargesResponsesCursorPage +- client.plans.listCustomers(planId, { ...params }) -> PlanListCustomersResponsesCursorPage # CreditGrants @@ -58,9 +58,9 @@ Types: Methods: - client.creditGrants.create({ ...params }) -> CreditGrantCreateResponse -- client.creditGrants.list({ ...params }) -> CreditGrantListResponse +- client.creditGrants.list({ ...params }) -> CreditGrantListResponsesCursorPage - client.creditGrants.edit({ ...params }) -> CreditGrantEditResponse -- client.creditGrants.listCreditTypes({ ...params }) -> CreditGrantListCreditTypesResponse +- client.creditGrants.listCreditTypes({ ...params }) -> CreditGrantListCreditTypesResponsesCursorPage - client.creditGrants.listEntries({ ...params }) -> CreditGrantListEntriesResponse - client.creditGrants.void({ ...params }) -> CreditGrantVoidResponse @@ -72,7 +72,6 @@ Types: - CustomerDetail - CustomerCreateResponse - CustomerRetrieveResponse -- CustomerListResponse - CustomerArchiveResponse - CustomerListBillableMetricsResponse - CustomerListCostsResponse @@ -82,10 +81,10 @@ Methods: - client.customers.create({ ...params }) -> CustomerCreateResponse - client.customers.retrieve(customerId) -> CustomerRetrieveResponse -- client.customers.list({ ...params }) -> CustomerListResponse +- client.customers.list({ ...params }) -> CustomerDetailsCursorPage - client.customers.archive({ ...params }) -> CustomerArchiveResponse -- client.customers.listBillableMetrics(customerId, { ...params }) -> CustomerListBillableMetricsResponse -- client.customers.listCosts(customerId, { ...params }) -> CustomerListCostsResponse +- client.customers.listBillableMetrics(customerId, { ...params }) -> CustomerListBillableMetricsResponsesCursorPage +- client.customers.listCosts(customerId, { ...params }) -> CustomerListCostsResponsesCursorPage - client.customers.setIngestAliases(customerId, { ...params }) -> void - client.customers.setName(customerId, { ...params }) -> CustomerSetNameResponse - client.customers.updateConfig(customerId, { ...params }) -> void @@ -115,10 +114,10 @@ Types: Methods: -- client.customers.plans.list(customerId, { ...params }) -> PlanListResponse +- client.customers.plans.list(customerId, { ...params }) -> PlanListResponsesCursorPage - client.customers.plans.add(customerId, { ...params }) -> PlanAddResponse - client.customers.plans.end(customerId, customerPlanId, { ...params }) -> PlanEndResponse -- client.customers.plans.listPriceAdjustments(customerId, customerPlanId, { ...params }) -> PlanListPriceAdjustmentsResponse +- client.customers.plans.listPriceAdjustments(customerId, customerPlanId, { ...params }) -> PlanListPriceAdjustmentsResponsesCursorPage ## Invoices @@ -126,13 +125,12 @@ Types: - Invoice - InvoiceRetrieveResponse -- InvoiceListResponse - InvoiceAddChargeResponse Methods: - client.customers.invoices.retrieve(customerId, invoiceId, { ...params }) -> InvoiceRetrieveResponse -- client.customers.invoices.list(customerId, { ...params }) -> InvoiceListResponse +- client.customers.invoices.list(customerId, { ...params }) -> InvoicesCursorPage - client.customers.invoices.addCharge(customerId, { ...params }) -> InvoiceAddChargeResponse ## BillingConfig @@ -168,7 +166,7 @@ Methods: - client.usage.list({ ...params }) -> UsageListResponse - client.usage.ingest([ ...usage ]) -> void -- client.usage.listWithGroups({ ...params }) -> UsageListWithGroupsResponse +- client.usage.listWithGroups({ ...params }) -> UsageListWithGroupsResponsesCursorPage # AuditLogs @@ -178,7 +176,7 @@ Types: Methods: -- client.auditLogs.list({ ...params }) -> AuditLogListResponse +- client.auditLogs.list({ ...params }) -> AuditLogListResponsesCursorPage # CustomFields @@ -207,7 +205,7 @@ Methods: - client.billableMetrics.create({ ...params }) -> BillableMetricCreateResponse - client.billableMetrics.retrieve(billableMetricId) -> BillableMetricRetrieveResponse -- client.billableMetrics.list(customerId, { ...params }) -> BillableMetricListResponse +- client.billableMetrics.list(customerId, { ...params }) -> BillableMetricListResponsesCursorPage - client.billableMetrics.archive({ ...params }) -> BillableMetricArchiveResponse # Services diff --git a/src/index.ts b/src/index.ts index 17b56b1..e237138 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ import * as Errors from './error'; import { type Agent } from './_shims/index'; import * as Uploads from './uploads'; import * as qs from 'qs'; +import * as Pagination from '@metronome/sdk/pagination'; import * as API from '@metronome/sdk/resources/index'; export interface ClientOptions { @@ -199,6 +200,10 @@ export import fileFromPath = Uploads.fileFromPath; export namespace Metronome { export import RequestOptions = Core.RequestOptions; + export import CursorPage = Pagination.CursorPage; + export import CursorPageParams = Pagination.CursorPageParams; + export import CursorPageResponse = Pagination.CursorPageResponse; + export import Alerts = API.Alerts; export import AlertCreateResponse = API.AlertCreateResponse; export import AlertArchiveResponse = API.AlertArchiveResponse; @@ -211,6 +216,9 @@ export namespace Metronome { export import PlanGetDetailsResponse = API.PlanGetDetailsResponse; export import PlanListChargesResponse = API.PlanListChargesResponse; export import PlanListCustomersResponse = API.PlanListCustomersResponse; + export import PlanListResponsesCursorPage = API.PlanListResponsesCursorPage; + export import PlanListChargesResponsesCursorPage = API.PlanListChargesResponsesCursorPage; + export import PlanListCustomersResponsesCursorPage = API.PlanListCustomersResponsesCursorPage; export import PlanListParams = API.PlanListParams; export import PlanListChargesParams = API.PlanListChargesParams; export import PlanListCustomersParams = API.PlanListCustomersParams; @@ -225,6 +233,8 @@ export namespace Metronome { export import CreditGrantListCreditTypesResponse = API.CreditGrantListCreditTypesResponse; export import CreditGrantListEntriesResponse = API.CreditGrantListEntriesResponse; export import CreditGrantVoidResponse = API.CreditGrantVoidResponse; + export import CreditGrantListResponsesCursorPage = API.CreditGrantListResponsesCursorPage; + export import CreditGrantListCreditTypesResponsesCursorPage = API.CreditGrantListCreditTypesResponsesCursorPage; export import CreditGrantCreateParams = API.CreditGrantCreateParams; export import CreditGrantListParams = API.CreditGrantListParams; export import CreditGrantEditParams = API.CreditGrantEditParams; @@ -237,11 +247,13 @@ export namespace Metronome { export import CustomerDetail = API.CustomerDetail; export import CustomerCreateResponse = API.CustomerCreateResponse; export import CustomerRetrieveResponse = API.CustomerRetrieveResponse; - export import CustomerListResponse = API.CustomerListResponse; export import CustomerArchiveResponse = API.CustomerArchiveResponse; export import CustomerListBillableMetricsResponse = API.CustomerListBillableMetricsResponse; export import CustomerListCostsResponse = API.CustomerListCostsResponse; export import CustomerSetNameResponse = API.CustomerSetNameResponse; + export import CustomerDetailsCursorPage = API.CustomerDetailsCursorPage; + export import CustomerListBillableMetricsResponsesCursorPage = API.CustomerListBillableMetricsResponsesCursorPage; + export import CustomerListCostsResponsesCursorPage = API.CustomerListCostsResponsesCursorPage; export import CustomerCreateParams = API.CustomerCreateParams; export import CustomerListParams = API.CustomerListParams; export import CustomerArchiveParams = API.CustomerArchiveParams; @@ -258,12 +270,14 @@ export namespace Metronome { export import Usage = API.Usage; export import UsageListResponse = API.UsageListResponse; export import UsageListWithGroupsResponse = API.UsageListWithGroupsResponse; + export import UsageListWithGroupsResponsesCursorPage = API.UsageListWithGroupsResponsesCursorPage; export import UsageListParams = API.UsageListParams; export import UsageIngestParams = API.UsageIngestParams; export import UsageListWithGroupsParams = API.UsageListWithGroupsParams; export import AuditLogs = API.AuditLogs; export import AuditLogListResponse = API.AuditLogListResponse; + export import AuditLogListResponsesCursorPage = API.AuditLogListResponsesCursorPage; export import AuditLogListParams = API.AuditLogListParams; export import CustomFields = API.CustomFields; @@ -279,6 +293,7 @@ export namespace Metronome { export import BillableMetricRetrieveResponse = API.BillableMetricRetrieveResponse; export import BillableMetricListResponse = API.BillableMetricListResponse; export import BillableMetricArchiveResponse = API.BillableMetricArchiveResponse; + export import BillableMetricListResponsesCursorPage = API.BillableMetricListResponsesCursorPage; export import BillableMetricCreateParams = API.BillableMetricCreateParams; export import BillableMetricListParams = API.BillableMetricListParams; export import BillableMetricArchiveParams = API.BillableMetricArchiveParams; diff --git a/src/pagination.ts b/src/pagination.ts new file mode 100644 index 0000000..7a92f4b --- /dev/null +++ b/src/pagination.ts @@ -0,0 +1,78 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from './core'; + +export interface CursorPageResponse { + /** + * Cursor to fetch the next page + */ + next_page: string; + + /** + * Items of the page + */ + data: Array; +} + +export interface CursorPageParams { + /** + * Cursor to begin fetching from + */ + next_page?: string; + + /** + * Number of elements to fetch + */ + limit?: number; +} + +export class CursorPage extends AbstractPage implements CursorPageResponse { + /** + * Cursor to fetch the next page + */ + next_page: string; + + /** + * Items of the page + */ + data: Array; + + constructor( + client: APIClient, + response: Response, + body: CursorPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.next_page = body.next_page || ''; + this.data = body.data || []; + } + + getPaginatedItems(): Item[] { + return this.data ?? []; + } + + // @deprecated Please use `nextPageInfo()` instead + nextPageParams(): Partial | null { + const info = this.nextPageInfo(); + if (!info) return null; + if ('params' in info) return info.params; + const params = Object.fromEntries(info.url.searchParams); + if (!Object.keys(params).length) return null; + return params; + } + + nextPageInfo(): PageInfo | null { + const cursor = this.next_page; + if (!cursor) { + return null; + } + + return { + params: { + next_page: cursor, + }, + }; + } +} diff --git a/src/resources/audit-logs.ts b/src/resources/audit-logs.ts index b5aa4d5..0e631fc 100644 --- a/src/resources/audit-logs.ts +++ b/src/resources/audit-logs.ts @@ -4,6 +4,7 @@ import * as Core from '@metronome/sdk/core'; import { APIResource } from '@metronome/sdk/resource'; import { isRequestOptions } from '@metronome/sdk/core'; import * as AuditLogsAPI from '@metronome/sdk/resources/audit-logs'; +import { CursorPage, type CursorPageParams } from '@metronome/sdk/pagination'; export class AuditLogs extends APIResource { /** @@ -12,80 +13,60 @@ export class AuditLogs extends APIResource { * subsequent requests using the same next_page value will be in the returned data * array, ensuring a continuous and uninterrupted reading of audit logs. */ - list(query?: AuditLogListParams, options?: Core.RequestOptions): Core.APIPromise; - list(options?: Core.RequestOptions): Core.APIPromise; + list( + query?: AuditLogListParams, + options?: Core.RequestOptions, + ): Core.PagePromise; + list( + options?: Core.RequestOptions, + ): Core.PagePromise; list( query: AuditLogListParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(query)) { return this.list({}, query); } - return this._client.get('/auditLogs', { query, ...options }); + return this._client.getAPIList('/auditLogs', AuditLogListResponsesCursorPage, { query, ...options }); } } -export interface AuditLogListResponse { - data: Array; +export class AuditLogListResponsesCursorPage extends CursorPage {} - /** - * The next_page parameter is always returned to support ongoing log retrieval. It - * enables continuous querying, even when some requests return no new data. Save - * the next_page token from each response and use it for future requests to ensure - * no logs are missed. This setup is ideal for regular updates via automated - * processes, like cron jobs, to fetch logs continuously as they become available. - * When you receive an empty data array, it indicates a temporary absence of new - * logs, but subsequent requests might return new data. - */ - next_page: string | null; -} - -export namespace AuditLogListResponse { - export interface Data { - id: string; +export interface AuditLogListResponse { + id: string; - timestamp: string; + timestamp: string; - action?: string; + action?: string; - actor?: Data.Actor; + actor?: AuditLogListResponse.Actor; - description?: string; + description?: string; - resource_id?: string; + resource_id?: string; - resource_type?: string; + resource_type?: string; - status?: 'success' | 'failure' | 'pending'; - } + status?: 'success' | 'failure' | 'pending'; +} - export namespace Data { - export interface Actor { - id: string; +export namespace AuditLogListResponse { + export interface Actor { + id: string; - name: string; + name: string; - email?: string; - } + email?: string; } } -export interface AuditLogListParams { +export interface AuditLogListParams extends CursorPageParams { /** * RFC 3339 timestamp (exclusive). Cannot be used with 'next_page'. */ ending_before?: string; - /** - * Max number of results that should be returned - */ - limit?: number; - - /** - * Cursor that indicates where the next page of results should start. - */ - next_page?: string; - /** * Optional parameter that can be used to filter which audit logs are returned. If * you specify resource_id, you must also specify resource_type. @@ -112,5 +93,6 @@ export interface AuditLogListParams { export namespace AuditLogs { export import AuditLogListResponse = AuditLogsAPI.AuditLogListResponse; + export import AuditLogListResponsesCursorPage = AuditLogsAPI.AuditLogListResponsesCursorPage; export import AuditLogListParams = AuditLogsAPI.AuditLogListParams; } diff --git a/src/resources/billable-metrics.ts b/src/resources/billable-metrics.ts index a37cda9..c6cfe62 100644 --- a/src/resources/billable-metrics.ts +++ b/src/resources/billable-metrics.ts @@ -5,6 +5,7 @@ import { APIResource } from '@metronome/sdk/resource'; import { isRequestOptions } from '@metronome/sdk/core'; import * as BillableMetricsAPI from '@metronome/sdk/resources/billable-metrics'; import * as Shared from '@metronome/sdk/resources/shared'; +import { CursorPage, type CursorPageParams } from '@metronome/sdk/pagination'; export class BillableMetrics extends APIResource { /** @@ -34,17 +35,24 @@ export class BillableMetrics extends APIResource { customerId: string, query?: BillableMetricListParams, options?: Core.RequestOptions, - ): Core.APIPromise; - list(customerId: string, options?: Core.RequestOptions): Core.APIPromise; + ): Core.PagePromise; + list( + customerId: string, + options?: Core.RequestOptions, + ): Core.PagePromise; list( customerId: string, query: BillableMetricListParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(query)) { return this.list(customerId, {}, query); } - return this._client.get(`/customers/${customerId}/billable-metrics`, { query, ...options }); + return this._client.getAPIList( + `/customers/${customerId}/billable-metrics`, + BillableMetricListResponsesCursorPage, + { query, ...options }, + ); } /** @@ -58,6 +66,8 @@ export class BillableMetrics extends APIResource { } } +export class BillableMetricListResponsesCursorPage extends CursorPage {} + export interface BillableMetricCreateResponse { data: Shared.ID; } @@ -180,19 +190,11 @@ export namespace BillableMetricRetrieveResponse { } export interface BillableMetricListResponse { - data: Array; - - next_page: string | null; -} - -export namespace BillableMetricListResponse { - export interface Data { - id: string; + id: string; - name: string; + name: string; - group_by?: Array; - } + group_by?: Array; } export interface BillableMetricArchiveResponse { @@ -308,17 +310,7 @@ export namespace BillableMetricCreateParams { } } -export interface BillableMetricListParams { - /** - * Max number of results that should be returned - */ - limit?: number; - - /** - * Cursor that indicates where the next page of results should start. - */ - next_page?: string; - +export interface BillableMetricListParams extends CursorPageParams { /** * If true, the list of metrics will be filtered to just ones that are on the * customer's current plan @@ -335,6 +327,7 @@ export namespace BillableMetrics { export import BillableMetricRetrieveResponse = BillableMetricsAPI.BillableMetricRetrieveResponse; export import BillableMetricListResponse = BillableMetricsAPI.BillableMetricListResponse; export import BillableMetricArchiveResponse = BillableMetricsAPI.BillableMetricArchiveResponse; + export import BillableMetricListResponsesCursorPage = BillableMetricsAPI.BillableMetricListResponsesCursorPage; export import BillableMetricCreateParams = BillableMetricsAPI.BillableMetricCreateParams; export import BillableMetricListParams = BillableMetricsAPI.BillableMetricListParams; export import BillableMetricArchiveParams = BillableMetricsAPI.BillableMetricArchiveParams; diff --git a/src/resources/credit-grants.ts b/src/resources/credit-grants.ts index c8f41f6..f49ce14 100644 --- a/src/resources/credit-grants.ts +++ b/src/resources/credit-grants.ts @@ -5,6 +5,7 @@ import { APIResource } from '@metronome/sdk/resource'; import { isRequestOptions } from '@metronome/sdk/core'; import * as CreditGrantsAPI from '@metronome/sdk/resources/credit-grants'; import * as Shared from '@metronome/sdk/resources/shared'; +import { CursorPage, type CursorPageParams } from '@metronome/sdk/pagination'; export class CreditGrants extends APIResource { /** @@ -23,17 +24,24 @@ export class CreditGrants extends APIResource { list( params?: CreditGrantListParams, options?: Core.RequestOptions, - ): Core.APIPromise; - list(options?: Core.RequestOptions): Core.APIPromise; + ): Core.PagePromise; + list( + options?: Core.RequestOptions, + ): Core.PagePromise; list( params: CreditGrantListParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(params)) { return this.list({}, params); } const { limit, next_page, ...body } = params; - return this._client.post('/credits/listGrants', { query: { limit, next_page }, body, ...options }); + return this._client.getAPIList('/credits/listGrants', CreditGrantListResponsesCursorPage, { + query: { limit, next_page }, + body, + method: 'post', + ...options, + }); } /** @@ -49,16 +57,21 @@ export class CreditGrants extends APIResource { listCreditTypes( query?: CreditGrantListCreditTypesParams, options?: Core.RequestOptions, - ): Core.APIPromise; - listCreditTypes(options?: Core.RequestOptions): Core.APIPromise; + ): Core.PagePromise; + listCreditTypes( + options?: Core.RequestOptions, + ): Core.PagePromise; listCreditTypes( query: CreditGrantListCreditTypesParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(query)) { return this.listCreditTypes({}, query); } - return this._client.get('/credit-types/list', { query, ...options }); + return this._client.getAPIList('/credit-types/list', CreditGrantListCreditTypesResponsesCursorPage, { + query, + ...options, + }); } /** @@ -90,6 +103,10 @@ export class CreditGrants extends APIResource { } } +export class CreditGrantListResponsesCursorPage extends CursorPage {} + +export class CreditGrantListCreditTypesResponsesCursorPage extends CursorPage {} + export interface CreditLedgerEntry { /** * an amount representing the change to the customer's credit balance @@ -150,133 +167,125 @@ export interface CreditGrantCreateResponse { } export interface CreditGrantListResponse { - data: Array; + /** + * the Metronome ID of the credit grant + */ + id: string; - next_page: string | null; -} + /** + * The effective balance of the grant as of the end of the customer's current + * billing period. Expiration deductions will be included only if the grant expires + * before the end of the current billing period. + */ + balance: CreditGrantListResponse.Balance; -export namespace CreditGrantListResponse { - export interface Data { - /** - * the Metronome ID of the credit grant - */ - id: string; + custom_fields: Record; - /** - * The effective balance of the grant as of the end of the customer's current - * billing period. Expiration deductions will be included only if the grant expires - * before the end of the current billing period. - */ - balance: Data.Balance; + /** + * the Metronome ID of the customer + */ + customer_id: string; - custom_fields: Record; + deductions: Array; - /** - * the Metronome ID of the customer - */ - customer_id: string; + effective_at: string; - deductions: Array; + expires_at: string; - effective_at: string; + /** + * the amount of credits initially granted + */ + grant_amount: CreditGrantListResponse.GrantAmount; - expires_at: string; + name: string; - /** - * the amount of credits initially granted - */ - grant_amount: Data.GrantAmount; + /** + * the amount paid for this credit grant + */ + paid_amount: CreditGrantListResponse.PaidAmount; - name: string; + pending_deductions: Array; - /** - * the amount paid for this credit grant - */ - paid_amount: Data.PaidAmount; + priority: number; - pending_deductions: Array; + credit_grant_type?: string | null; - priority: number; + /** + * the Metronome ID of the invoice with the purchase charge for this credit grant, + * if applicable + */ + invoice_id?: string | null; - credit_grant_type?: string | null; + /** + * The products which these credits will be applied to. (If unspecified, the + * credits will be applied to charges for all products.) + */ + products?: Array; - /** - * the Metronome ID of the invoice with the purchase charge for this credit grant, - * if applicable - */ - invoice_id?: string | null; + reason?: string | null; + /** + * Prevents the creation of duplicates. If a request to create a record is made + * with a previously used uniqueness key, a new record will not be created and the + * request will fail with a 409 error. + */ + uniqueness_key?: string | null; +} + +export namespace CreditGrantListResponse { + /** + * The effective balance of the grant as of the end of the customer's current + * billing period. Expiration deductions will be included only if the grant expires + * before the end of the current billing period. + */ + export interface Balance { /** - * The products which these credits will be applied to. (If unspecified, the - * credits will be applied to charges for all products.) + * The end_date of the customer's current billing period. */ - products?: Array; - - reason?: string | null; + effective_at: string; /** - * Prevents the creation of duplicates. If a request to create a record is made - * with a previously used uniqueness key, a new record will not be created and the - * request will fail with a 409 error. + * The grant's current balance including all posted deductions. If the grant has + * expired, this amount will be 0. */ - uniqueness_key?: string | null; - } + excluding_pending: number; - export namespace Data { /** - * The effective balance of the grant as of the end of the customer's current - * billing period. Expiration deductions will be included only if the grant expires - * before the end of the current billing period. + * The grant's current balance including all posted and pending deductions. If the + * grant expires before the end of the customer's current billing period, this + * amount will be 0. */ - export interface Balance { - /** - * The end_date of the customer's current billing period. - */ - effective_at: string; - - /** - * The grant's current balance including all posted deductions. If the grant has - * expired, this amount will be 0. - */ - excluding_pending: number; + including_pending: number; + } - /** - * The grant's current balance including all posted and pending deductions. If the - * grant expires before the end of the customer's current billing period, this - * amount will be 0. - */ - including_pending: number; - } + /** + * the amount of credits initially granted + */ + export interface GrantAmount { + amount: number; /** - * the amount of credits initially granted + * the credit type for the amount granted */ - export interface GrantAmount { - amount: number; + credit_type: Shared.CreditType; + } - /** - * the credit type for the amount granted - */ - credit_type: Shared.CreditType; - } + /** + * the amount paid for this credit grant + */ + export interface PaidAmount { + amount: number; /** - * the amount paid for this credit grant + * the credit type for the amount paid */ - export interface PaidAmount { - amount: number; - - /** - * the credit type for the amount paid - */ - credit_type: Shared.CreditType; - } + credit_type: Shared.CreditType; + } - export interface Product { - id: string; + export interface Product { + id: string; - name: string; - } + name: string; } } @@ -285,19 +294,11 @@ export interface CreditGrantEditResponse { } export interface CreditGrantListCreditTypesResponse { - data: Array; + id?: string; - next_page: string | null; -} - -export namespace CreditGrantListCreditTypesResponse { - export interface Data { - id?: string; - - is_currency?: boolean; + is_currency?: boolean; - name?: string; - } + name?: string; } export interface CreditGrantListEntriesResponse { @@ -496,17 +497,7 @@ export namespace CreditGrantCreateParams { } } -export interface CreditGrantListParams { - /** - * Query param: Max number of results that should be returned - */ - limit?: number; - - /** - * Query param: Cursor that indicates where the next page of results should start. - */ - next_page?: string; - +export interface CreditGrantListParams extends CursorPageParams { /** * Body param: An array of credit grant IDs. If this is specified, neither * credit_type_ids nor customer_ids may be specified. @@ -554,17 +545,7 @@ export interface CreditGrantEditParams { name?: string; } -export interface CreditGrantListCreditTypesParams { - /** - * Max number of results that should be returned - */ - limit?: number; - - /** - * Cursor that indicates where the next page of results should start. - */ - next_page?: string; -} +export interface CreditGrantListCreditTypesParams extends CursorPageParams {} export interface CreditGrantListEntriesParams { /** @@ -618,6 +599,8 @@ export namespace CreditGrants { export import CreditGrantListCreditTypesResponse = CreditGrantsAPI.CreditGrantListCreditTypesResponse; export import CreditGrantListEntriesResponse = CreditGrantsAPI.CreditGrantListEntriesResponse; export import CreditGrantVoidResponse = CreditGrantsAPI.CreditGrantVoidResponse; + export import CreditGrantListResponsesCursorPage = CreditGrantsAPI.CreditGrantListResponsesCursorPage; + export import CreditGrantListCreditTypesResponsesCursorPage = CreditGrantsAPI.CreditGrantListCreditTypesResponsesCursorPage; export import CreditGrantCreateParams = CreditGrantsAPI.CreditGrantCreateParams; export import CreditGrantListParams = CreditGrantsAPI.CreditGrantListParams; export import CreditGrantEditParams = CreditGrantsAPI.CreditGrantEditParams; diff --git a/src/resources/customers/customers.ts b/src/resources/customers/customers.ts index 84cd2ed..1fee102 100644 --- a/src/resources/customers/customers.ts +++ b/src/resources/customers/customers.ts @@ -9,6 +9,7 @@ import * as AlertsAPI from '@metronome/sdk/resources/customers/alerts'; import * as BillingConfigAPI from '@metronome/sdk/resources/customers/billing-config'; import * as InvoicesAPI from '@metronome/sdk/resources/customers/invoices'; import * as PlansAPI from '@metronome/sdk/resources/customers/plans'; +import { CursorPage, type CursorPageParams } from '@metronome/sdk/pagination'; export class Customers extends APIResource { alerts: AlertsAPI.Alerts = new AlertsAPI.Alerts(this._client); @@ -33,16 +34,19 @@ export class Customers extends APIResource { /** * List all customers. */ - list(query?: CustomerListParams, options?: Core.RequestOptions): Core.APIPromise; - list(options?: Core.RequestOptions): Core.APIPromise; + list( + query?: CustomerListParams, + options?: Core.RequestOptions, + ): Core.PagePromise; + list(options?: Core.RequestOptions): Core.PagePromise; list( query: CustomerListParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(query)) { return this.list({}, query); } - return this._client.get('/customers', { query, ...options }); + return this._client.getAPIList('/customers', CustomerDetailsCursorPage, { query, ...options }); } /** @@ -62,20 +66,24 @@ export class Customers extends APIResource { customerId: string, query?: CustomerListBillableMetricsParams, options?: Core.RequestOptions, - ): Core.APIPromise; + ): Core.PagePromise; listBillableMetrics( customerId: string, options?: Core.RequestOptions, - ): Core.APIPromise; + ): Core.PagePromise; listBillableMetrics( customerId: string, query: CustomerListBillableMetricsParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(query)) { return this.listBillableMetrics(customerId, {}, query); } - return this._client.get(`/customers/${customerId}/billable-metrics`, { query, ...options }); + return this._client.getAPIList( + `/customers/${customerId}/billable-metrics`, + CustomerListBillableMetricsResponsesCursorPage, + { query, ...options }, + ); } /** @@ -87,8 +95,11 @@ export class Customers extends APIResource { customerId: string, query: CustomerListCostsParams, options?: Core.RequestOptions, - ): Core.APIPromise { - return this._client.get(`/customers/${customerId}/costs`, { query, ...options }); + ): Core.PagePromise { + return this._client.getAPIList(`/customers/${customerId}/costs`, CustomerListCostsResponsesCursorPage, { + query, + ...options, + }); } /** @@ -144,6 +155,12 @@ export class Customers extends APIResource { } } +export class CustomerDetailsCursorPage extends CursorPage {} + +export class CustomerListBillableMetricsResponsesCursorPage extends CursorPage {} + +export class CustomerListCostsResponsesCursorPage extends CursorPage {} + export interface Customer { /** * the Metronome ID of the customer @@ -217,66 +234,44 @@ export interface CustomerRetrieveResponse { data: CustomerDetail; } -export interface CustomerListResponse { - data: Array; - - next_page: string | null; -} - export interface CustomerArchiveResponse { data: Shared.ID; } export interface CustomerListBillableMetricsResponse { - data: Array; - - next_page: string | null; -} - -export namespace CustomerListBillableMetricsResponse { - export interface Data { - id: string; + id: string; - name: string; + name: string; - group_by?: Array; - } + group_by?: Array; } export interface CustomerListCostsResponse { - data: Array; + credit_types: Record; + + end_timestamp: string; - next_page: string | null; + start_timestamp: string; } export namespace CustomerListCostsResponse { - export interface Data { - credit_types: Record; + export interface CreditTypes { + cost?: number; - end_timestamp: string; + line_item_breakdown?: Array; - start_timestamp: string; + name?: string; } - export namespace Data { - export interface CreditTypes { - cost?: number; - - line_item_breakdown?: Array; - - name?: string; - } + export namespace CreditTypes { + export interface LineItemBreakdown { + cost: number; - export namespace CreditTypes { - export interface LineItemBreakdown { - cost: number; + name: string; - name: string; + group_key?: string; - group_key?: string; - - group_value?: string | null; - } + group_value?: string | null; } } } @@ -351,7 +346,7 @@ export namespace CustomerCreateParams { } } -export interface CustomerListParams { +export interface CustomerListParams extends CursorPageParams { /** * Filter the customer list by customer_id. Up to 100 ids can be provided. */ @@ -362,16 +357,6 @@ export interface CustomerListParams { */ ingest_alias?: string; - /** - * Max number of results that should be returned - */ - limit?: number; - - /** - * Cursor that indicates where the next page of results should start. - */ - next_page?: string; - /** * Filter the customer list by only archived customers. */ @@ -388,17 +373,7 @@ export interface CustomerArchiveParams { id: string; } -export interface CustomerListBillableMetricsParams { - /** - * Max number of results that should be returned - */ - limit?: number; - - /** - * Cursor that indicates where the next page of results should start. - */ - next_page?: string; - +export interface CustomerListBillableMetricsParams extends CursorPageParams { /** * If true, the list of metrics will be filtered to just ones that are on the * customer's current plan @@ -406,7 +381,7 @@ export interface CustomerListBillableMetricsParams { on_current_plan?: boolean; } -export interface CustomerListCostsParams { +export interface CustomerListCostsParams extends CursorPageParams { /** * RFC 3339 timestamp (exclusive) */ @@ -416,16 +391,6 @@ export interface CustomerListCostsParams { * RFC 3339 timestamp (inclusive) */ starting_on: string; - - /** - * Max number of results that should be returned - */ - limit?: number; - - /** - * Cursor that indicates where the next page of results should start. - */ - next_page?: string; } export interface CustomerSetIngestAliasesParams { @@ -457,11 +422,13 @@ export namespace Customers { export import CustomerDetail = CustomersAPI.CustomerDetail; export import CustomerCreateResponse = CustomersAPI.CustomerCreateResponse; export import CustomerRetrieveResponse = CustomersAPI.CustomerRetrieveResponse; - export import CustomerListResponse = CustomersAPI.CustomerListResponse; export import CustomerArchiveResponse = CustomersAPI.CustomerArchiveResponse; export import CustomerListBillableMetricsResponse = CustomersAPI.CustomerListBillableMetricsResponse; export import CustomerListCostsResponse = CustomersAPI.CustomerListCostsResponse; export import CustomerSetNameResponse = CustomersAPI.CustomerSetNameResponse; + export import CustomerDetailsCursorPage = CustomersAPI.CustomerDetailsCursorPage; + export import CustomerListBillableMetricsResponsesCursorPage = CustomersAPI.CustomerListBillableMetricsResponsesCursorPage; + export import CustomerListCostsResponsesCursorPage = CustomersAPI.CustomerListCostsResponsesCursorPage; export import CustomerCreateParams = CustomersAPI.CustomerCreateParams; export import CustomerListParams = CustomersAPI.CustomerListParams; export import CustomerArchiveParams = CustomersAPI.CustomerArchiveParams; @@ -482,6 +449,8 @@ export namespace Customers { export import PlanAddResponse = PlansAPI.PlanAddResponse; export import PlanEndResponse = PlansAPI.PlanEndResponse; export import PlanListPriceAdjustmentsResponse = PlansAPI.PlanListPriceAdjustmentsResponse; + export import PlanListResponsesCursorPage = PlansAPI.PlanListResponsesCursorPage; + export import PlanListPriceAdjustmentsResponsesCursorPage = PlansAPI.PlanListPriceAdjustmentsResponsesCursorPage; export import PlanListParams = PlansAPI.PlanListParams; export import PlanAddParams = PlansAPI.PlanAddParams; export import PlanEndParams = PlansAPI.PlanEndParams; @@ -489,8 +458,8 @@ export namespace Customers { export import Invoices = InvoicesAPI.Invoices; export import Invoice = InvoicesAPI.Invoice; export import InvoiceRetrieveResponse = InvoicesAPI.InvoiceRetrieveResponse; - export import InvoiceListResponse = InvoicesAPI.InvoiceListResponse; export import InvoiceAddChargeResponse = InvoicesAPI.InvoiceAddChargeResponse; + export import InvoicesCursorPage = InvoicesAPI.InvoicesCursorPage; export import InvoiceRetrieveParams = InvoicesAPI.InvoiceRetrieveParams; export import InvoiceListParams = InvoicesAPI.InvoiceListParams; export import InvoiceAddChargeParams = InvoicesAPI.InvoiceAddChargeParams; diff --git a/src/resources/customers/index.ts b/src/resources/customers/index.ts index d1ca0dd..cc3fa72 100644 --- a/src/resources/customers/index.ts +++ b/src/resources/customers/index.ts @@ -6,7 +6,6 @@ export { CustomerDetail, CustomerCreateResponse, CustomerRetrieveResponse, - CustomerListResponse, CustomerArchiveResponse, CustomerListBillableMetricsResponse, CustomerListCostsResponse, @@ -19,6 +18,9 @@ export { CustomerSetIngestAliasesParams, CustomerSetNameParams, CustomerUpdateConfigParams, + CustomerDetailsCursorPage, + CustomerListBillableMetricsResponsesCursorPage, + CustomerListCostsResponsesCursorPage, Customers, } from './customers'; export { @@ -33,11 +35,11 @@ export { export { Invoice, InvoiceRetrieveResponse, - InvoiceListResponse, InvoiceAddChargeResponse, InvoiceRetrieveParams, InvoiceListParams, InvoiceAddChargeParams, + InvoicesCursorPage, Invoices, } from './invoices'; export { @@ -49,5 +51,7 @@ export { PlanAddParams, PlanEndParams, PlanListPriceAdjustmentsParams, + PlanListResponsesCursorPage, + PlanListPriceAdjustmentsResponsesCursorPage, Plans, } from './plans'; diff --git a/src/resources/customers/invoices.ts b/src/resources/customers/invoices.ts index 4d717e6..c9f2c46 100644 --- a/src/resources/customers/invoices.ts +++ b/src/resources/customers/invoices.ts @@ -5,6 +5,7 @@ import { APIResource } from '@metronome/sdk/resource'; import { isRequestOptions } from '@metronome/sdk/core'; import * as InvoicesAPI from '@metronome/sdk/resources/customers/invoices'; import * as Shared from '@metronome/sdk/resources/shared'; +import { CursorPage, type CursorPageParams } from '@metronome/sdk/pagination'; export class Invoices extends APIResource { /** @@ -41,17 +42,20 @@ export class Invoices extends APIResource { customerId: string, query?: InvoiceListParams, options?: Core.RequestOptions, - ): Core.APIPromise; - list(customerId: string, options?: Core.RequestOptions): Core.APIPromise; + ): Core.PagePromise; + list(customerId: string, options?: Core.RequestOptions): Core.PagePromise; list( customerId: string, query: InvoiceListParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(query)) { return this.list(customerId, {}, query); } - return this._client.get(`/customers/${customerId}/invoices`, { query, ...options }); + return this._client.getAPIList(`/customers/${customerId}/invoices`, InvoicesCursorPage, { + query, + ...options, + }); } /** @@ -66,6 +70,8 @@ export class Invoices extends APIResource { } } +export class InvoicesCursorPage extends CursorPage {} + export interface Invoice { id: string; @@ -433,12 +439,6 @@ export interface InvoiceRetrieveResponse { data: Invoice; } -export interface InvoiceListResponse { - data: Array; - - next_page: string | null; -} - export interface InvoiceAddChargeResponse {} export interface InvoiceRetrieveParams { @@ -448,7 +448,7 @@ export interface InvoiceRetrieveParams { skip_zero_qty_line_items?: boolean; } -export interface InvoiceListParams { +export interface InvoiceListParams extends CursorPageParams { /** * Only return invoices for the specified credit type */ @@ -460,16 +460,6 @@ export interface InvoiceListParams { */ ending_before?: string; - /** - * Max number of results that should be returned - */ - limit?: number; - - /** - * Cursor that indicates where the next page of results should start. - */ - next_page?: string; - /** * If set, all zero quantity line items will be filtered out of the response */ @@ -525,8 +515,8 @@ export interface InvoiceAddChargeParams { export namespace Invoices { export import Invoice = InvoicesAPI.Invoice; export import InvoiceRetrieveResponse = InvoicesAPI.InvoiceRetrieveResponse; - export import InvoiceListResponse = InvoicesAPI.InvoiceListResponse; export import InvoiceAddChargeResponse = InvoicesAPI.InvoiceAddChargeResponse; + export import InvoicesCursorPage = InvoicesAPI.InvoicesCursorPage; export import InvoiceRetrieveParams = InvoicesAPI.InvoiceRetrieveParams; export import InvoiceListParams = InvoicesAPI.InvoiceListParams; export import InvoiceAddChargeParams = InvoicesAPI.InvoiceAddChargeParams; diff --git a/src/resources/customers/plans.ts b/src/resources/customers/plans.ts index c313b31..5752fc0 100644 --- a/src/resources/customers/plans.ts +++ b/src/resources/customers/plans.ts @@ -5,6 +5,7 @@ import { APIResource } from '@metronome/sdk/resource'; import { isRequestOptions } from '@metronome/sdk/core'; import * as PlansAPI from '@metronome/sdk/resources/customers/plans'; import * as Shared from '@metronome/sdk/resources/shared'; +import { CursorPage, type CursorPageParams } from '@metronome/sdk/pagination'; export class Plans extends APIResource { /** @@ -14,17 +15,23 @@ export class Plans extends APIResource { customerId: string, query?: PlanListParams, options?: Core.RequestOptions, - ): Core.APIPromise; - list(customerId: string, options?: Core.RequestOptions): Core.APIPromise; + ): Core.PagePromise; + list( + customerId: string, + options?: Core.RequestOptions, + ): Core.PagePromise; list( customerId: string, query: PlanListParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(query)) { return this.list(customerId, {}, query); } - return this._client.get(`/customers/${customerId}/plans`, { query, ...options }); + return this._client.getAPIList(`/customers/${customerId}/plans`, PlanListResponsesCursorPage, { + query, + ...options, + }); } /** @@ -76,76 +83,73 @@ export class Plans extends APIResource { customerPlanId: string, query?: PlanListPriceAdjustmentsParams, options?: Core.RequestOptions, - ): Core.APIPromise; + ): Core.PagePromise; listPriceAdjustments( customerId: string, customerPlanId: string, options?: Core.RequestOptions, - ): Core.APIPromise; + ): Core.PagePromise; listPriceAdjustments( customerId: string, customerPlanId: string, query: PlanListPriceAdjustmentsParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(query)) { return this.listPriceAdjustments(customerId, customerPlanId, {}, query); } - return this._client.get(`/customers/${customerId}/plans/${customerPlanId}/priceAdjustments`, { - query, - ...options, - }); + return this._client.getAPIList( + `/customers/${customerId}/plans/${customerPlanId}/priceAdjustments`, + PlanListPriceAdjustmentsResponsesCursorPage, + { query, ...options }, + ); } } -export interface PlanListResponse { - data: Array; +export class PlanListResponsesCursorPage extends CursorPage {} - next_page: string | null; -} +export class PlanListPriceAdjustmentsResponsesCursorPage extends CursorPage {} -export namespace PlanListResponse { - export interface Data { - /** - * the ID of the customer plan - */ - id: string; +export interface PlanListResponse { + /** + * the ID of the customer plan + */ + id: string; - custom_fields: Record; + custom_fields: Record; - plan_description: string; + plan_description: string; - /** - * the ID of the plan - */ - plan_id: string; + /** + * the ID of the plan + */ + plan_id: string; - plan_name: string; + plan_name: string; - starting_on: string; + starting_on: string; - ending_before?: string; + ending_before?: string; - net_payment_terms_days?: number; + net_payment_terms_days?: number; - trial_info?: Data.TrialInfo; - } + trial_info?: PlanListResponse.TrialInfo; +} - export namespace Data { - export interface TrialInfo { - ending_before: string; +export namespace PlanListResponse { + export interface TrialInfo { + ending_before: string; - spending_caps: Array; - } + spending_caps: Array; + } - export namespace TrialInfo { - export interface SpendingCap { - amount: number; + export namespace TrialInfo { + export interface SpendingCap { + amount: number; - amount_remaining: number; + amount_remaining: number; - credit_type: Shared.CreditType; - } + credit_type: Shared.CreditType; } } } @@ -157,52 +161,34 @@ export interface PlanAddResponse { export interface PlanEndResponse {} export interface PlanListPriceAdjustmentsResponse { - data: Array; - - next_page: string | null; -} + charge_id: string; -export namespace PlanListPriceAdjustmentsResponse { - export interface Data { - charge_id: string; + charge_type: 'usage' | 'fixed' | 'composite' | 'minimum' | 'seat'; - charge_type: 'usage' | 'fixed' | 'composite' | 'minimum' | 'seat'; + prices: Array; - prices: Array; - - start_period: number; + start_period: number; - quantity?: number; - } + quantity?: number; +} - export namespace Data { - export interface Price { - /** - * Determines how the value will be applied. - */ - adjustment_type: 'fixed' | 'quantity' | 'percentage' | 'override'; +export namespace PlanListPriceAdjustmentsResponse { + export interface Price { + /** + * Determines how the value will be applied. + */ + adjustment_type: 'fixed' | 'quantity' | 'percentage' | 'override'; - /** - * Used in pricing tiers. Indicates at what metric value the price applies. - */ - tier?: number; + /** + * Used in pricing tiers. Indicates at what metric value the price applies. + */ + tier?: number; - value?: number; - } + value?: number; } } -export interface PlanListParams { - /** - * Max number of results that should be returned - */ - limit?: number; - - /** - * Cursor that indicates where the next page of results should start. - */ - next_page?: string; -} +export interface PlanListParams extends CursorPageParams {} export interface PlanAddParams { plan_id: string; @@ -339,23 +325,15 @@ export interface PlanEndParams { void_stripe_invoices?: boolean; } -export interface PlanListPriceAdjustmentsParams { - /** - * Max number of results that should be returned - */ - limit?: number; - - /** - * Cursor that indicates where the next page of results should start. - */ - next_page?: string; -} +export interface PlanListPriceAdjustmentsParams extends CursorPageParams {} export namespace Plans { export import PlanListResponse = PlansAPI.PlanListResponse; export import PlanAddResponse = PlansAPI.PlanAddResponse; export import PlanEndResponse = PlansAPI.PlanEndResponse; export import PlanListPriceAdjustmentsResponse = PlansAPI.PlanListPriceAdjustmentsResponse; + export import PlanListResponsesCursorPage = PlansAPI.PlanListResponsesCursorPage; + export import PlanListPriceAdjustmentsResponsesCursorPage = PlansAPI.PlanListPriceAdjustmentsResponsesCursorPage; export import PlanListParams = PlansAPI.PlanListParams; export import PlanAddParams = PlansAPI.PlanAddParams; export import PlanEndParams = PlansAPI.PlanEndParams; diff --git a/src/resources/index.ts b/src/resources/index.ts index fdbd204..2ecd543 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -8,7 +8,12 @@ export { AlertArchiveParams, Alerts, } from './alerts'; -export { AuditLogListResponse, AuditLogListParams, AuditLogs } from './audit-logs'; +export { + AuditLogListResponse, + AuditLogListParams, + AuditLogListResponsesCursorPage, + AuditLogs, +} from './audit-logs'; export { BillableMetricCreateResponse, BillableMetricRetrieveResponse, @@ -17,6 +22,7 @@ export { BillableMetricCreateParams, BillableMetricListParams, BillableMetricArchiveParams, + BillableMetricListResponsesCursorPage, BillableMetrics, } from './billable-metrics'; export { @@ -35,6 +41,8 @@ export { CreditGrantListCreditTypesParams, CreditGrantListEntriesParams, CreditGrantVoidParams, + CreditGrantListResponsesCursorPage, + CreditGrantListCreditTypesResponsesCursorPage, CreditGrants, } from './credit-grants'; export { @@ -51,7 +59,6 @@ export { CustomerDetail, CustomerCreateResponse, CustomerRetrieveResponse, - CustomerListResponse, CustomerArchiveResponse, CustomerListBillableMetricsResponse, CustomerListCostsResponse, @@ -64,6 +71,9 @@ export { CustomerSetIngestAliasesParams, CustomerSetNameParams, CustomerUpdateConfigParams, + CustomerDetailsCursorPage, + CustomerListBillableMetricsResponsesCursorPage, + CustomerListCostsResponsesCursorPage, Customers, } from './customers/customers'; export { DashboardGetEmbeddableURLResponse, DashboardGetEmbeddableURLParams, Dashboards } from './dashboards'; @@ -76,6 +86,9 @@ export { PlanListParams, PlanListChargesParams, PlanListCustomersParams, + PlanListResponsesCursorPage, + PlanListChargesResponsesCursorPage, + PlanListCustomersResponsesCursorPage, Plans, } from './plans'; export { ServiceListResponse, Services } from './services'; @@ -85,5 +98,6 @@ export { UsageListParams, UsageIngestParams, UsageListWithGroupsParams, + UsageListWithGroupsResponsesCursorPage, Usage, } from './usage'; diff --git a/src/resources/plans.ts b/src/resources/plans.ts index c918970..efa80e4 100644 --- a/src/resources/plans.ts +++ b/src/resources/plans.ts @@ -6,21 +6,25 @@ import { isRequestOptions } from '@metronome/sdk/core'; import * as PlansAPI from '@metronome/sdk/resources/plans'; import * as Shared from '@metronome/sdk/resources/shared'; import * as CustomersAPI from '@metronome/sdk/resources/customers/customers'; +import { CursorPage, type CursorPageParams } from '@metronome/sdk/pagination'; export class Plans extends APIResource { /** * List all available plans. */ - list(query?: PlanListParams, options?: Core.RequestOptions): Core.APIPromise; - list(options?: Core.RequestOptions): Core.APIPromise; + list( + query?: PlanListParams, + options?: Core.RequestOptions, + ): Core.PagePromise; + list(options?: Core.RequestOptions): Core.PagePromise; list( query: PlanListParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(query)) { return this.list({}, query); } - return this._client.get('/plans', { query, ...options }); + return this._client.getAPIList('/plans', PlanListResponsesCursorPage, { query, ...options }); } /** @@ -37,17 +41,23 @@ export class Plans extends APIResource { planId: string, query?: PlanListChargesParams, options?: Core.RequestOptions, - ): Core.APIPromise; - listCharges(planId: string, options?: Core.RequestOptions): Core.APIPromise; + ): Core.PagePromise; + listCharges( + planId: string, + options?: Core.RequestOptions, + ): Core.PagePromise; listCharges( planId: string, query: PlanListChargesParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(query)) { return this.listCharges(planId, {}, query); } - return this._client.get(`/planDetails/${planId}/charges`, { query, ...options }); + return this._client.getAPIList(`/planDetails/${planId}/charges`, PlanListChargesResponsesCursorPage, { + query, + ...options, + }); } /** @@ -58,20 +68,32 @@ export class Plans extends APIResource { planId: string, query?: PlanListCustomersParams, options?: Core.RequestOptions, - ): Core.APIPromise; - listCustomers(planId: string, options?: Core.RequestOptions): Core.APIPromise; + ): Core.PagePromise; + listCustomers( + planId: string, + options?: Core.RequestOptions, + ): Core.PagePromise; listCustomers( planId: string, query: PlanListCustomersParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(query)) { return this.listCustomers(planId, {}, query); } - return this._client.get(`/planDetails/${planId}/customers`, { query, ...options }); + return this._client.getAPIList(`/planDetails/${planId}/customers`, PlanListCustomersResponsesCursorPage, { + query, + ...options, + }); } } +export class PlanListResponsesCursorPage extends CursorPage {} + +export class PlanListChargesResponsesCursorPage extends CursorPage {} + +export class PlanListCustomersResponsesCursorPage extends CursorPage {} + export interface PlanDetail { id: string; @@ -143,21 +165,13 @@ export namespace PlanDetail { } export interface PlanListResponse { - data: Array; - - next_page: string | null; -} - -export namespace PlanListResponse { - export interface Data { - id: string; + id: string; - description: string; + description: string; - name: string; + name: string; - custom_fields?: Record; - } + custom_fields?: Record; } export interface PlanGetDetailsResponse { @@ -165,148 +179,102 @@ export interface PlanGetDetailsResponse { } export interface PlanListChargesResponse { - data: Array; + id: string; - next_page: string | null; -} + charge_type: 'usage' | 'fixed' | 'composite' | 'minimum' | 'seat'; -export namespace PlanListChargesResponse { - export interface Data { - id: string; + credit_type: Shared.CreditType; - charge_type: 'usage' | 'fixed' | 'composite' | 'minimum' | 'seat'; + custom_fields: Record; - credit_type: Shared.CreditType; + name: string; - custom_fields: Record; + prices: Array; - name: string; + product_id: string; - prices: Array; + product_name: string; - product_id: string; + quantity?: number; - product_name: string; + /** + * Used in price ramps. Indicates how many billing periods pass before the charge + * applies. + */ + start_period?: number; - quantity?: number; + /** + * Specifies how quantities for usage based charges will be converted. + */ + unit_conversion?: PlanListChargesResponse.UnitConversion; +} +export namespace PlanListChargesResponse { + export interface Price { /** - * Used in price ramps. Indicates how many billing periods pass before the charge - * applies. + * Used in pricing tiers. Indicates at what metric value the price applies. */ - start_period?: number; + tier: number; - /** - * Specifies how quantities for usage based charges will be converted. - */ - unit_conversion?: Data.UnitConversion; - } - - export namespace Data { - export interface Price { - /** - * Used in pricing tiers. Indicates at what metric value the price applies. - */ - tier: number; + value: number; - value: number; + collection_interval?: number; - collection_interval?: number; + collection_schedule?: string; - collection_schedule?: string; + quantity?: number; + } - quantity?: number; - } + /** + * Specifies how quantities for usage based charges will be converted. + */ + export interface UnitConversion { + /** + * The conversion factor + */ + division_factor: number; /** - * Specifies how quantities for usage based charges will be converted. + * Whether usage should be rounded down or up to the nearest whole number. If null, + * quantity will be rounded to 20 decimal places. */ - export interface UnitConversion { - /** - * The conversion factor - */ - division_factor: number; - - /** - * Whether usage should be rounded down or up to the nearest whole number. If null, - * quantity will be rounded to 20 decimal places. - */ - rounding_behavior?: 'floor' | 'ceiling'; - } + rounding_behavior?: 'floor' | 'ceiling'; } } export interface PlanListCustomersResponse { - data: Array; + customer_details: CustomersAPI.CustomerDetail; - next_page: string | null; + plan_details: PlanListCustomersResponse.PlanDetails; } export namespace PlanListCustomersResponse { - export interface Data { - customer_details: CustomersAPI.CustomerDetail; - - plan_details: Data.PlanDetails; - } - - export namespace Data { - export interface PlanDetails { - id: string; + export interface PlanDetails { + id: string; - custom_fields: Record; + custom_fields: Record; - customer_plan_id: string; + customer_plan_id: string; - name: string; + name: string; - /** - * The start date of the plan - */ - starting_on: string; + /** + * The start date of the plan + */ + starting_on: string; - /** - * The end date of the plan - */ - ending_before?: string | null; - } + /** + * The end date of the plan + */ + ending_before?: string | null; } } -export interface PlanListParams { - /** - * Max number of results that should be returned - */ - limit?: number; - - /** - * Cursor that indicates where the next page of results should start. - */ - next_page?: string; -} - -export interface PlanListChargesParams { - /** - * Max number of results that should be returned - */ - limit?: number; +export interface PlanListParams extends CursorPageParams {} - /** - * Cursor that indicates where the next page of results should start. - */ - next_page?: string; -} - -export interface PlanListCustomersParams { - /** - * Max number of results that should be returned - */ - limit?: number; - - /** - * Cursor that indicates where the next page of results should start. - */ - next_page?: string; +export interface PlanListChargesParams extends CursorPageParams {} +export interface PlanListCustomersParams extends CursorPageParams { /** * Status of customers on a given plan. Defaults to `active`. * @@ -327,6 +295,9 @@ export namespace Plans { export import PlanGetDetailsResponse = PlansAPI.PlanGetDetailsResponse; export import PlanListChargesResponse = PlansAPI.PlanListChargesResponse; export import PlanListCustomersResponse = PlansAPI.PlanListCustomersResponse; + export import PlanListResponsesCursorPage = PlansAPI.PlanListResponsesCursorPage; + export import PlanListChargesResponsesCursorPage = PlansAPI.PlanListChargesResponsesCursorPage; + export import PlanListCustomersResponsesCursorPage = PlansAPI.PlanListCustomersResponsesCursorPage; export import PlanListParams = PlansAPI.PlanListParams; export import PlanListChargesParams = PlansAPI.PlanListChargesParams; export import PlanListCustomersParams = PlansAPI.PlanListCustomersParams; diff --git a/src/resources/usage.ts b/src/resources/usage.ts index 49a69a9..e961ef6 100644 --- a/src/resources/usage.ts +++ b/src/resources/usage.ts @@ -3,6 +3,7 @@ import * as Core from '@metronome/sdk/core'; import { APIResource } from '@metronome/sdk/resource'; import * as UsageAPI from '@metronome/sdk/resources/usage'; +import { CursorPage, type CursorPageParams } from '@metronome/sdk/pagination'; export class Usage extends APIResource { /** @@ -36,12 +37,19 @@ export class Usage extends APIResource { listWithGroups( params: UsageListWithGroupsParams, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { const { limit, next_page, ...body } = params; - return this._client.post('/usage/groups', { query: { limit, next_page }, body, ...options }); + return this._client.getAPIList('/usage/groups', UsageListWithGroupsResponsesCursorPage, { + query: { limit, next_page }, + body, + method: 'post', + ...options, + }); } } +export class UsageListWithGroupsResponsesCursorPage extends CursorPage {} + export interface UsageListResponse { data: Array; @@ -71,23 +79,15 @@ export namespace UsageListResponse { } export interface UsageListWithGroupsResponse { - data: Array; - - next_page: string | null; -} - -export namespace UsageListWithGroupsResponse { - export interface Data { - ending_before: string; + ending_before: string; - group_key: string | null; + group_key: string | null; - group_value: string | null; + group_value: string | null; - starting_on: string; + starting_on: string; - value: number | null; - } + value: number | null; } export interface UsageListParams { @@ -169,7 +169,7 @@ export namespace UsageIngestParams { } } -export interface UsageListWithGroupsParams { +export interface UsageListWithGroupsParams extends CursorPageParams { /** * Body param: */ @@ -188,16 +188,6 @@ export interface UsageListWithGroupsParams { */ window_size: 'hour' | 'day' | 'none' | 'HOUR' | 'DAY' | 'NONE' | 'Hour' | 'Day' | 'None'; - /** - * Query param: Max number of results that should be returned - */ - limit?: number; - - /** - * Query param: Cursor that indicates where the next page of results should start. - */ - next_page?: string; - /** * Body param: If true, will return the usage for the current billing period. Will * return an error if the customer is currently uncontracted or starting_on and @@ -239,6 +229,7 @@ export namespace UsageListWithGroupsParams { export namespace Usage { export import UsageListResponse = UsageAPI.UsageListResponse; export import UsageListWithGroupsResponse = UsageAPI.UsageListWithGroupsResponse; + export import UsageListWithGroupsResponsesCursorPage = UsageAPI.UsageListWithGroupsResponsesCursorPage; export import UsageListParams = UsageAPI.UsageListParams; export import UsageIngestParams = UsageAPI.UsageIngestParams; export import UsageListWithGroupsParams = UsageAPI.UsageListWithGroupsParams;