Skip to content

Commit fe3cd55

Browse files
committedNov 6, 2023
feat(api): remove unsupported params (#24)
1 parent ce13e46 commit fe3cd55

File tree

4 files changed

+15
-115
lines changed

4 files changed

+15
-115
lines changed
 

‎src/resources/customers/credits/ledger.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class Ledger extends APIResource {
4646
* deductions take place from a non-expiring credit block.
4747
*
4848
* If there are multiple blocks with the same expiration date, Orb will deduct from
49-
* the block with the _lower cost basis_ first (ex. trial credits with a $0 cost
49+
* the block with the _lower cost basis_ first (e.g. trial credits with a $0 cost
5050
* basis before paid credits with a $5.00 cost basis).
5151
*
5252
* It's also possible for a single usage event's deduction to _span_ credit blocks.
@@ -393,7 +393,7 @@ export class Ledger extends APIResource {
393393
* deductions take place from a non-expiring credit block.
394394
*
395395
* If there are multiple blocks with the same expiration date, Orb will deduct from
396-
* the block with the _lower cost basis_ first (ex. trial credits with a $0 cost
396+
* the block with the _lower cost basis_ first (e.g. trial credits with a $0 cost
397397
* basis before paid credits with a $5.00 cost basis).
398398
*
399399
* It's also possible for a single usage event's deduction to _span_ credit blocks.

‎src/resources/events/events.ts

+8-88
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import * as Core from 'orb-billing/core';
44
import { APIResource } from 'orb-billing/resource';
5-
import { isRequestOptions } from 'orb-billing/core';
65
import * as EventsAPI from 'orb-billing/resources/events/events';
76
import * as BackfillsAPI from 'orb-billing/resources/events/backfills';
87

@@ -26,7 +25,7 @@ export class Events extends APIResource {
2625
* event in cases where you need to:
2726
*
2827
* - update an event with new metadata as you iterate on your pricing model
29-
* - update an event based on the result of an external API call (ex. call to a
28+
* - update an event based on the result of an external API call (e.g. call to a
3029
* payment gateway succeeded or failed)
3130
*
3231
* This amendment API is always audit-safe. The process will still retain the
@@ -74,7 +73,7 @@ export class Events extends APIResource {
7473
* event in cases where you need to:
7574
*
7675
* - no longer bill for an event that was improperly reported
77-
* - no longer bill for an event based on the result of an external API call (ex.
76+
* - no longer bill for an event based on the result of an external API call (e.g.
7877
* call to a payment gateway failed and the user should not be billed)
7978
*
8079
* If you want to only change specific properties of an event, but keep the event
@@ -323,46 +322,14 @@ export class Events extends APIResource {
323322
*
324323
* - `event_ids`: This is an explicit array of IDs to filter by. Note that an
325324
* event's ID is the `idempotency_key` that was originally used for ingestion.
326-
* - `invoice_id`: This is an issued Orb invoice ID (see also
327-
* [List Invoices](list-invoices)). Orb will fetch all events that were used to
328-
* calculate the invoice. In the common case, this will be a list of events whose
329-
* `timestamp` property falls within the billing period specified by the invoice.
330325
*
331326
* By default, Orb does not return _deprecated_ events in this endpoint.
332327
*
333328
* By default, Orb will not throw a `404` if no events matched, Orb will return an
334329
* empty array for `data` instead.
335330
*/
336-
search(params?: EventSearchParams, options?: Core.RequestOptions): Core.APIPromise<EventSearchResponse>;
337-
search(options?: Core.RequestOptions): Core.APIPromise<EventSearchResponse>;
338-
search(
339-
params: EventSearchParams | Core.RequestOptions = {},
340-
options?: Core.RequestOptions,
341-
): Core.APIPromise<EventSearchResponse> {
342-
if (isRequestOptions(params)) {
343-
return this.search({}, params);
344-
}
345-
const {
346-
cursor,
347-
limit,
348-
'timestamp[gt]': timestampGt,
349-
'timestamp[gte]': timestampGte,
350-
'timestamp[lt]': timestampLt,
351-
'timestamp[lte]': timestampLte,
352-
...body
353-
} = params;
354-
return this.post('/events/search', {
355-
query: {
356-
cursor,
357-
limit,
358-
'timestamp[gt]': timestampGt,
359-
'timestamp[gte]': timestampGte,
360-
'timestamp[lt]': timestampLt,
361-
'timestamp[lte]': timestampLte,
362-
},
363-
body,
364-
...options,
365-
});
331+
search(body: EventSearchParams, options?: Core.RequestOptions): Core.APIPromise<EventSearchResponse> {
332+
return this.post('/events/search', { body, ...options });
366333
}
367334
}
368335

@@ -421,8 +388,6 @@ export namespace EventIngestResponse {
421388

422389
export interface EventSearchResponse {
423390
data: Array<EventSearchResponse.Data>;
424-
425-
pagination_metadata: EventSearchResponse.PaginationMetadata;
426391
}
427392

428393
export namespace EventSearchResponse {
@@ -469,12 +434,6 @@ export namespace EventSearchResponse {
469434
*/
470435
timestamp: string;
471436
}
472-
473-
export interface PaginationMetadata {
474-
has_more: boolean;
475-
476-
next_cursor: string | null;
477-
}
478437
}
479438

480439
export interface EventUpdateParams {
@@ -569,50 +528,11 @@ export namespace EventIngestParams {
569528

570529
export interface EventSearchParams {
571530
/**
572-
* Query param: Cursor for pagination. This can be populated by the `next_cursor`
573-
* value returned from the initial request.
574-
*/
575-
cursor?: string | null;
576-
577-
/**
578-
* Query param: The number of items to fetch. Defaults to 20.
579-
*/
580-
limit?: number;
581-
582-
/**
583-
* Query param:
584-
*/
585-
'timestamp[gt]'?: string | null;
586-
587-
/**
588-
* Query param:
589-
*/
590-
'timestamp[gte]'?: string | null;
591-
592-
/**
593-
* Query param:
594-
*/
595-
'timestamp[lt]'?: string | null;
596-
597-
/**
598-
* Query param:
599-
*/
600-
'timestamp[lte]'?: string | null;
601-
602-
/**
603-
* Body param: This is an explicit array of IDs to filter by. Note that an event's
604-
* ID is the idempotency_key that was originally used for ingestion. Values in this
605-
* array will be treated case sensitively.
606-
*/
607-
event_ids?: Array<string> | null;
608-
609-
/**
610-
* Body param: This is an issued Orb invoice ID (see also List Invoices). Orb will
611-
* fetch all events that were used to calculate the invoice. In the common case,
612-
* this will be a list of events whose timestamp property falls within the billing
613-
* period specified by the invoice.
531+
* This is an explicit array of IDs to filter by. Note that an event's ID is the
532+
* idempotency_key that was originally used for ingestion. Values in this array
533+
* will be treated case sensitively.
614534
*/
615-
invoice_id?: string | null;
535+
event_ids: Array<string>;
616536
}
617537

618538
export namespace Events {

‎src/resources/subscriptions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ export class Subscriptions extends APIResource {
399399
* Orb supports invoicing for a subscription when a preconfigured usage threshold
400400
* is hit. To enable threshold billing, pass in an `invoicing_threshold`, which is
401401
* specified in the subscription's invoicing currency, when creating a
402-
* subscription. Ex. pass in `10.00` to issue an invoice when usage amounts hit
402+
* subscription. E.g. pass in `10.00` to issue an invoice when usage amounts hit
403403
* $10.00 for a subscription that invoices in USD.
404404
*/
405405
create(body?: SubscriptionCreateParams, options?: Core.RequestOptions): Core.APIPromise<Subscription>;

‎tests/api-resources/events/events.test.ts

+4-24
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ describe('resource events', () => {
117117
});
118118
});
119119

120-
test('search', async () => {
121-
const responsePromise = orb.events.search();
120+
test('search: only required params', async () => {
121+
const responsePromise = orb.events.search({ event_ids: ['string', 'string', 'string'] });
122122
const rawResponse = await responsePromise.asResponse();
123123
expect(rawResponse).toBeInstanceOf(Response);
124124
const response = await responsePromise;
@@ -128,27 +128,7 @@ describe('resource events', () => {
128128
expect(dataAndResponse.response).toBe(rawResponse);
129129
});
130130

131-
test('search: request options instead of params are passed correctly', async () => {
132-
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
133-
await expect(orb.events.search({ path: '/_stainless_unknown_path' })).rejects.toThrow(Orb.NotFoundError);
134-
});
135-
136-
test('search: request options and params are passed correctly', async () => {
137-
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
138-
await expect(
139-
orb.events.search(
140-
{
141-
cursor: 'string',
142-
limit: 0,
143-
'timestamp[gt]': '2019-12-27T18:11:19.117Z',
144-
'timestamp[gte]': '2019-12-27T18:11:19.117Z',
145-
'timestamp[lt]': '2019-12-27T18:11:19.117Z',
146-
'timestamp[lte]': '2019-12-27T18:11:19.117Z',
147-
event_ids: ['string', 'string', 'string'],
148-
invoice_id: 'string',
149-
},
150-
{ path: '/_stainless_unknown_path' },
151-
),
152-
).rejects.toThrow(Orb.NotFoundError);
131+
test('search: required and optional params', async () => {
132+
const response = await orb.events.search({ event_ids: ['string', 'string', 'string'] });
153133
});
154134
});

0 commit comments

Comments
 (0)
Please sign in to comment.