orb-billing 1.25.0 → 1.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/core.ts CHANGED
@@ -43,6 +43,10 @@ async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
43
43
  return null as T;
44
44
  }
45
45
 
46
+ if (props.options.__binaryResponse) {
47
+ return response as unknown as T;
48
+ }
49
+
46
50
  const contentType = response.headers.get('content-type');
47
51
  if (contentType?.includes('application/json')) {
48
52
  const json = await response.json();
@@ -52,10 +56,11 @@ async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
52
56
  return json as T;
53
57
  }
54
58
 
55
- // TODO handle blob, arraybuffer, other content types, etc.
56
59
  const text = await response.text();
57
60
  debug('response', response.status, response.url, response.headers, text);
58
- return text as any as T;
61
+
62
+ // TODO handle blob, arraybuffer, other content types, etc.
63
+ return text as unknown as T;
59
64
  }
60
65
 
61
66
  /**
@@ -720,6 +725,8 @@ export type RequestOptions<Req extends {} = Record<string, unknown> | Readable>
720
725
  httpAgent?: Agent;
721
726
  signal?: AbortSignal | undefined | null;
722
727
  idempotencyKey?: string;
728
+
729
+ __binaryResponse?: boolean | undefined;
723
730
  };
724
731
 
725
732
  // This is required so that we can determine if a given object matches the RequestOptions
@@ -738,6 +745,8 @@ const requestOptionsKeys: KeysEnum<RequestOptions> = {
738
745
  httpAgent: true,
739
746
  signal: true,
740
747
  idempotencyKey: true,
748
+
749
+ __binaryResponse: true,
741
750
  };
742
751
 
743
752
  export const isRequestOptions = (obj: unknown): obj is RequestOptions<Record<string, unknown> | Readable> => {
@@ -46,7 +46,7 @@ export class Ledger extends APIResource {
46
46
  * deductions take place from a non-expiring credit block.
47
47
  *
48
48
  * 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
50
50
  * basis before paid credits with a $5.00 cost basis).
51
51
  *
52
52
  * It's also possible for a single usage event's deduction to _span_ credit blocks.
@@ -393,7 +393,7 @@ export class Ledger extends APIResource {
393
393
  * deductions take place from a non-expiring credit block.
394
394
  *
395
395
  * 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
397
397
  * basis before paid credits with a $5.00 cost basis).
398
398
  *
399
399
  * It's also possible for a single usage event's deduction to _span_ credit blocks.
@@ -39,7 +39,7 @@ export class Customers extends APIResource {
39
39
  * This endpoint can be used to update the `payment_provider`,
40
40
  * `payment_provider_id`, `name`, `email`, `email_delivery`, `tax_id`,
41
41
  * `auto_collection`, `metadata`, `shipping_address`, `billing_address`, and
42
- * `additional_emails` of an existing customer. "Other fields on a customer are
42
+ * `additional_emails` of an existing customer. Other fields on a customer are
43
43
  * currently immutable.
44
44
  */
45
45
  update(
@@ -1030,13 +1030,6 @@ export interface CustomerUpdateParams {
1030
1030
 
1031
1031
  email_delivery?: boolean | null;
1032
1032
 
1033
- /**
1034
- * An optional user-defined ID for this customer resource, used throughout the
1035
- * system as an alias for this Customer. Use this field to identify a customer by
1036
- * an existing identifier in your system.
1037
- */
1038
- external_customer_id?: string | null;
1039
-
1040
1033
  /**
1041
1034
  * User-specified key value pairs, often useful for referencing internal resources
1042
1035
  * or IDs. Returned as-is in the customer resource.
@@ -1452,13 +1445,6 @@ export interface CustomerUpdateByExternalIDParams {
1452
1445
 
1453
1446
  email_delivery?: boolean | null;
1454
1447
 
1455
- /**
1456
- * An optional user-defined ID for this customer resource, used throughout the
1457
- * system as an alias for this Customer. Use this field to identify a customer by
1458
- * an existing identifier in your system.
1459
- */
1460
- external_customer_id?: string | null;
1461
-
1462
1448
  /**
1463
1449
  * User-specified key value pairs, often useful for referencing internal resources
1464
1450
  * or IDs. Returned as-is in the customer resource.
@@ -2,7 +2,6 @@
2
2
 
3
3
  import * as Core from "../../core";
4
4
  import { APIResource } from "../../resource";
5
- import { isRequestOptions } from "../../core";
6
5
  import * as EventsAPI from "./events";
7
6
  import * as BackfillsAPI from "./backfills";
8
7
 
@@ -26,7 +25,7 @@ export class Events extends APIResource {
26
25
  * event in cases where you need to:
27
26
  *
28
27
  * - 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
30
29
  * payment gateway succeeded or failed)
31
30
  *
32
31
  * This amendment API is always audit-safe. The process will still retain the
@@ -74,7 +73,7 @@ export class Events extends APIResource {
74
73
  * event in cases where you need to:
75
74
  *
76
75
  * - 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.
78
77
  * call to a payment gateway failed and the user should not be billed)
79
78
  *
80
79
  * If you want to only change specific properties of an event, but keep the event
@@ -323,46 +322,14 @@ export class Events extends APIResource {
323
322
  *
324
323
  * - `event_ids`: This is an explicit array of IDs to filter by. Note that an
325
324
  * 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.
330
325
  *
331
326
  * By default, Orb does not return _deprecated_ events in this endpoint.
332
327
  *
333
328
  * By default, Orb will not throw a `404` if no events matched, Orb will return an
334
329
  * empty array for `data` instead.
335
330
  */
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 });
366
333
  }
367
334
  }
368
335
 
@@ -421,8 +388,6 @@ export namespace EventIngestResponse {
421
388
 
422
389
  export interface EventSearchResponse {
423
390
  data: Array<EventSearchResponse.Data>;
424
-
425
- pagination_metadata: EventSearchResponse.PaginationMetadata;
426
391
  }
427
392
 
428
393
  export namespace EventSearchResponse {
@@ -469,12 +434,6 @@ export namespace EventSearchResponse {
469
434
  */
470
435
  timestamp: string;
471
436
  }
472
-
473
- export interface PaginationMetadata {
474
- has_more: boolean;
475
-
476
- next_cursor: string | null;
477
- }
478
437
  }
479
438
 
480
439
  export interface EventUpdateParams {
@@ -569,50 +528,11 @@ export namespace EventIngestParams {
569
528
 
570
529
  export interface EventSearchParams {
571
530
  /**
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.
614
534
  */
615
- invoice_id?: string | null;
535
+ event_ids: Array<string>;
616
536
  }
617
537
 
618
538
  export namespace Events {