Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Sep 5, 2024
1 parent 40011a9 commit b9b40f8
Show file tree
Hide file tree
Showing 12 changed files with 526 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 88
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/metronome%2Fmetronome-2213de19fd79bd2188fb178888a30c39dbcacebd7b0693b47e293d118fba5228.yml
configured_endpoints: 90
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/metronome%2Fmetronome-689348d45e1dedd9c2658451fce83ea94d995005f95e67b73f3b9ec8e30b0a93.yml
4 changes: 3 additions & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ Methods:

- <code title="post /billable-metrics/create">client.billableMetrics.<a href="./src/resources/billable-metrics.ts">create</a>({ ...params }) -> BillableMetricCreateResponse</code>
- <code title="get /billable-metrics/{billable_metric_id}">client.billableMetrics.<a href="./src/resources/billable-metrics.ts">retrieve</a>(billableMetricId) -> BillableMetricRetrieveResponse</code>
- <code title="get /customers/{customer_id}/billable-metrics">client.billableMetrics.<a href="./src/resources/billable-metrics.ts">list</a>(customerId, { ...params }) -> BillableMetricListResponsesCursorPage</code>
- <code title="get /billable-metrics">client.billableMetrics.<a href="./src/resources/billable-metrics.ts">list</a>({ ...params }) -> BillableMetricListResponsesCursorPage</code>
- <code title="post /billable-metrics/archive">client.billableMetrics.<a href="./src/resources/billable-metrics.ts">archive</a>({ ...params }) -> BillableMetricArchiveResponse</code>

# Services
Expand Down Expand Up @@ -292,6 +292,7 @@ Types:
- <code><a href="./src/resources/contracts/contracts.ts">ContractListResponse</a></code>
- <code><a href="./src/resources/contracts/contracts.ts">ContractAmendResponse</a></code>
- <code><a href="./src/resources/contracts/contracts.ts">ContractArchiveResponse</a></code>
- <code><a href="./src/resources/contracts/contracts.ts">ContractCreateHistoricalInvoicesResponse</a></code>
- <code><a href="./src/resources/contracts/contracts.ts">ContractListBalancesResponse</a></code>
- <code><a href="./src/resources/contracts/contracts.ts">ContractRetrieveRateScheduleResponse</a></code>
- <code><a href="./src/resources/contracts/contracts.ts">ContractScheduleProServicesInvoiceResponse</a></code>
Expand All @@ -305,6 +306,7 @@ Methods:
- <code title="post /contracts/addManualBalanceLedgerEntry">client.contracts.<a href="./src/resources/contracts/contracts.ts">addManualBalanceEntry</a>({ ...params }) -> void</code>
- <code title="post /contracts/amend">client.contracts.<a href="./src/resources/contracts/contracts.ts">amend</a>({ ...params }) -> ContractAmendResponse</code>
- <code title="post /contracts/archive">client.contracts.<a href="./src/resources/contracts/contracts.ts">archive</a>({ ...params }) -> ContractArchiveResponse</code>
- <code title="post /contracts/createHistoricalInvoices">client.contracts.<a href="./src/resources/contracts/contracts.ts">createHistoricalInvoices</a>({ ...params }) -> ContractCreateHistoricalInvoicesResponse</code>
- <code title="post /contracts/customerBalances/list">client.contracts.<a href="./src/resources/contracts/contracts.ts">listBalances</a>({ ...params }) -> ContractListBalancesResponse</code>
- <code title="post /contracts/getContractRateSchedule">client.contracts.<a href="./src/resources/contracts/contracts.ts">retrieveRateSchedule</a>({ ...params }) -> ContractRetrieveRateScheduleResponse</code>
- <code title="post /contracts/scheduleProServicesInvoice">client.contracts.<a href="./src/resources/contracts/contracts.ts">scheduleProServicesInvoice</a>({ ...params }) -> ContractScheduleProServicesInvoiceResponse</code>
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export namespace Metronome {
export import ContractListResponse = API.ContractListResponse;
export import ContractAmendResponse = API.ContractAmendResponse;
export import ContractArchiveResponse = API.ContractArchiveResponse;
export import ContractCreateHistoricalInvoicesResponse = API.ContractCreateHistoricalInvoicesResponse;
export import ContractListBalancesResponse = API.ContractListBalancesResponse;
export import ContractRetrieveRateScheduleResponse = API.ContractRetrieveRateScheduleResponse;
export import ContractScheduleProServicesInvoiceResponse = API.ContractScheduleProServicesInvoiceResponse;
Expand All @@ -332,6 +333,7 @@ export namespace Metronome {
export import ContractAddManualBalanceEntryParams = API.ContractAddManualBalanceEntryParams;
export import ContractAmendParams = API.ContractAmendParams;
export import ContractArchiveParams = API.ContractArchiveParams;
export import ContractCreateHistoricalInvoicesParams = API.ContractCreateHistoricalInvoicesParams;
export import ContractListBalancesParams = API.ContractListBalancesParams;
export import ContractRetrieveRateScheduleParams = API.ContractRetrieveRateScheduleParams;
export import ContractScheduleProServicesInvoiceParams = API.ContractScheduleProServicesInvoiceParams;
Expand Down
46 changes: 11 additions & 35 deletions src/resources/billable-metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,26 @@ export class BillableMetrics extends APIResource {
}

/**
* Get all billable metrics for a given customer.
* List all billable metrics.
*/
list(
customerId: string,
query?: BillableMetricListParams,
options?: Core.RequestOptions,
): Core.PagePromise<BillableMetricListResponsesCursorPage, BillableMetricListResponse>;
list(
customerId: string,
options?: Core.RequestOptions,
): Core.PagePromise<BillableMetricListResponsesCursorPage, BillableMetricListResponse>;
list(
customerId: string,
query: BillableMetricListParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.PagePromise<BillableMetricListResponsesCursorPage, BillableMetricListResponse> {
if (isRequestOptions(query)) {
return this.list(customerId, {}, query);
return this.list({}, query);
}
return this._client.getAPIList(
`/customers/${customerId}/billable-metrics`,
BillableMetricListResponsesCursorPage,
{ query, ...options },
);
return this._client.getAPIList('/billable-metrics', BillableMetricListResponsesCursorPage, {
query,
...options,
});
}

/**
Expand Down Expand Up @@ -128,19 +124,15 @@ export namespace BillableMetricRetrieveResponse {
}

export interface BillableMetricListResponse {
id: string;

name: string;

/**
* (DEPRECATED) use aggregation_type instead
* ID of the billable metric
*/
aggregate?: string;
id: string;

/**
* (DEPRECATED) use aggregation_key instead
* The display name of the billable metric.
*/
aggregate_keys?: Array<string>;
name: string;

/**
* A key that specifies which property of the event is used to aggregate data. This
Expand All @@ -161,16 +153,6 @@ export interface BillableMetricListResponse {
*/
event_type_filter?: Shared.EventTypeFilter;

/**
* (DEPRECATED) use property_filters & event_type_filter instead
*/
filter?: Record<string, unknown>;

/**
* (DEPRECATED) use group_keys instead
*/
group_by?: Array<string>;

/**
* Property names that are used to group usage costs on an invoice. Each entry
* represents a set of properties used to slice events into distinct buckets.
Expand Down Expand Up @@ -236,13 +218,7 @@ export interface BillableMetricCreateParams {
property_filters?: Array<Shared.PropertyFilter>;
}

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
*/
on_current_plan?: boolean;
}
export interface BillableMetricListParams extends CursorPageParams {}

export interface BillableMetricArchiveParams {
id: string;
Expand Down
77 changes: 77 additions & 0 deletions src/resources/contracts/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ export class Contracts extends APIResource {
return this._client.post('/contracts/archive', { body, ...options });
}

/**
* Creates historical usage invoices for a contract
*/
createHistoricalInvoices(
body: ContractCreateHistoricalInvoicesParams,
options?: Core.RequestOptions,
): Core.APIPromise<ContractCreateHistoricalInvoicesResponse> {
return this._client.post('/contracts/createHistoricalInvoices', { body, ...options });
}

/**
* List balances (commits and credits).
*/
Expand Down Expand Up @@ -379,6 +389,10 @@ export interface ContractArchiveResponse {
data: Shared.ID;
}

export interface ContractCreateHistoricalInvoicesResponse {
data: Array<InvoicesAPI.Invoice>;
}

export interface ContractListBalancesResponse {
data: Array<Shared.Commit | Shared.Credit>;

Expand Down Expand Up @@ -2120,6 +2134,67 @@ export interface ContractArchiveParams {
void_invoices: boolean;
}

export interface ContractCreateHistoricalInvoicesParams {
invoices: Array<ContractCreateHistoricalInvoicesParams.Invoice>;

preview: boolean;
}

export namespace ContractCreateHistoricalInvoicesParams {
export interface Invoice {
contract_id: string;

credit_type_id: string;

customer_id: string;

exclusive_end_date: string;

inclusive_start_date: string;

issue_date: string;

usage_line_items: Array<Invoice.UsageLineItem>;

/**
* This field's availability is dependent on your client's configuration.
*/
billable_status?: 'billable' | 'unbillable';

breakdown_granularity?: 'hour' | 'day' | 'HOUR' | 'DAY' | 'Hour' | 'Day';

custom_fields?: Record<string, string>;
}

export namespace Invoice {
export interface UsageLineItem {
exclusive_end_date: string;

inclusive_start_date: string;

product_id: string;

presentation_group_values?: Record<string, string>;

pricing_group_values?: Record<string, string>;

quantity?: number;

subtotals_with_quantity?: Array<UsageLineItem.SubtotalsWithQuantity>;
}

export namespace UsageLineItem {
export interface SubtotalsWithQuantity {
exclusive_end_date: string;

inclusive_start_date: string;

quantity: number;
}
}
}
}

export interface ContractListBalancesParams {
customer_id: string;

Expand Down Expand Up @@ -2332,6 +2407,7 @@ export namespace Contracts {
export import ContractListResponse = ContractsAPI.ContractListResponse;
export import ContractAmendResponse = ContractsAPI.ContractAmendResponse;
export import ContractArchiveResponse = ContractsAPI.ContractArchiveResponse;
export import ContractCreateHistoricalInvoicesResponse = ContractsAPI.ContractCreateHistoricalInvoicesResponse;
export import ContractListBalancesResponse = ContractsAPI.ContractListBalancesResponse;
export import ContractRetrieveRateScheduleResponse = ContractsAPI.ContractRetrieveRateScheduleResponse;
export import ContractScheduleProServicesInvoiceResponse = ContractsAPI.ContractScheduleProServicesInvoiceResponse;
Expand All @@ -2342,6 +2418,7 @@ export namespace Contracts {
export import ContractAddManualBalanceEntryParams = ContractsAPI.ContractAddManualBalanceEntryParams;
export import ContractAmendParams = ContractsAPI.ContractAmendParams;
export import ContractArchiveParams = ContractsAPI.ContractArchiveParams;
export import ContractCreateHistoricalInvoicesParams = ContractsAPI.ContractCreateHistoricalInvoicesParams;
export import ContractListBalancesParams = ContractsAPI.ContractListBalancesParams;
export import ContractRetrieveRateScheduleParams = ContractsAPI.ContractRetrieveRateScheduleParams;
export import ContractScheduleProServicesInvoiceParams = ContractsAPI.ContractScheduleProServicesInvoiceParams;
Expand Down
2 changes: 2 additions & 0 deletions src/resources/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export {
ContractListResponse,
ContractAmendResponse,
ContractArchiveResponse,
ContractCreateHistoricalInvoicesResponse,
ContractListBalancesResponse,
ContractRetrieveRateScheduleResponse,
ContractScheduleProServicesInvoiceResponse,
Expand All @@ -16,6 +17,7 @@ export {
ContractAddManualBalanceEntryParams,
ContractAmendParams,
ContractArchiveParams,
ContractCreateHistoricalInvoicesParams,
ContractListBalancesParams,
ContractRetrieveRateScheduleParams,
ContractScheduleProServicesInvoiceParams,
Expand Down
7 changes: 7 additions & 0 deletions src/resources/customers/invoices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ export namespace Invoice {
*/
is_prorated?: boolean;

/**
* only present for contract invoices and when the include_list_prices query
* parameter is set to true. This will include the list rate for the charge if
* applicable. Only present for usage and subscription line items.
*/
list_price?: Shared.Rate;

metadata?: string;

/**
Expand Down
48 changes: 48 additions & 0 deletions src/resources/dashboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export interface DashboardGetEmbeddableURLParams {
*/
dashboard: 'invoices' | 'usage' | 'credits';

bm_group_key_display_name_overrides?: DashboardGetEmbeddableURLParams.BmGroupKeyDisplayNameOverrides;

bm_group_key_values_display_name_overrides?: DashboardGetEmbeddableURLParams.BmGroupKeyValuesDisplayNameOverrides;

/**
* Optional list of colors to override
*/
Expand All @@ -48,6 +52,50 @@ export interface DashboardGetEmbeddableURLParams {
}

export namespace DashboardGetEmbeddableURLParams {
export interface BmGroupKeyDisplayNameOverrides {
/**
* The new display name for the group key. e.g. "Tenant ID"
*/
display_name?: string;

/**
* The current name of the group key. e.g. "tenant_id"
*/
group_key_name?: string;
}

export interface BmGroupKeyValuesDisplayNameOverrides {
/**
* The actual value of the group key. e.g. "123-xyz-abc". If group key is not used,
* it is the BM's name.
*/
group_key_name?: string;

/**
* An object containing the group key value and the new display name for the group
* key value.
*/
value_display_name?: BmGroupKeyValuesDisplayNameOverrides.ValueDisplayName;
}

export namespace BmGroupKeyValuesDisplayNameOverrides {
/**
* An object containing the group key value and the new display name for the group
* key value.
*/
export interface ValueDisplayName {
/**
* The new display name for the group key value. e.g. "EU-Cluster-A"
*/
display_name?: string;

/**
* The actual value of the group key. e.g. "123-xyz-abc"
*/
group_key_value?: string;
}
}

export interface ColorOverride {
/**
* The color to override
Expand Down
2 changes: 2 additions & 0 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export {
ContractListResponse,
ContractAmendResponse,
ContractArchiveResponse,
ContractCreateHistoricalInvoicesResponse,
ContractListBalancesResponse,
ContractRetrieveRateScheduleResponse,
ContractScheduleProServicesInvoiceResponse,
Expand All @@ -41,6 +42,7 @@ export {
ContractAddManualBalanceEntryParams,
ContractAmendParams,
ContractArchiveParams,
ContractCreateHistoricalInvoicesParams,
ContractListBalancesParams,
ContractRetrieveRateScheduleParams,
ContractScheduleProServicesInvoiceParams,
Expand Down
16 changes: 5 additions & 11 deletions tests/api-resources/billable-metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('resource billableMetrics', () => {
});

test('list', async () => {
const responsePromise = client.billableMetrics.list('d7abd0cd-4ae9-4db7-8676-e986a4ebd8dc');
const responsePromise = client.billableMetrics.list();
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
Expand All @@ -84,21 +84,15 @@ describe('resource billableMetrics', () => {

test('list: request options instead of params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(
client.billableMetrics.list('d7abd0cd-4ae9-4db7-8676-e986a4ebd8dc', {
path: '/_stainless_unknown_path',
}),
).rejects.toThrow(Metronome.NotFoundError);
await expect(client.billableMetrics.list({ path: '/_stainless_unknown_path' })).rejects.toThrow(
Metronome.NotFoundError,
);
});

test('list: request options and params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(
client.billableMetrics.list(
'd7abd0cd-4ae9-4db7-8676-e986a4ebd8dc',
{ limit: 1, next_page: 'next_page', on_current_plan: true },
{ path: '/_stainless_unknown_path' },
),
client.billableMetrics.list({ limit: 1, next_page: 'next_page' }, { path: '/_stainless_unknown_path' }),
).rejects.toThrow(Metronome.NotFoundError);
});

Expand Down
Loading

0 comments on commit b9b40f8

Please sign in to comment.