@metronome/sdk 3.4.1 → 3.6.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.
Files changed (103) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/README.md +2 -2
  3. package/bin/cli +12 -5
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts.map +1 -1
  6. package/client.js +11 -0
  7. package/client.js.map +1 -1
  8. package/client.mjs +11 -0
  9. package/client.mjs.map +1 -1
  10. package/internal/types.d.mts +6 -6
  11. package/internal/types.d.mts.map +1 -1
  12. package/internal/types.d.ts +6 -6
  13. package/internal/types.d.ts.map +1 -1
  14. package/internal/utils/env.js +2 -2
  15. package/internal/utils/env.js.map +1 -1
  16. package/internal/utils/env.mjs +2 -2
  17. package/internal/utils/env.mjs.map +1 -1
  18. package/internal/utils/log.d.mts.map +1 -1
  19. package/internal/utils/log.d.ts.map +1 -1
  20. package/internal/utils/log.js +2 -0
  21. package/internal/utils/log.js.map +1 -1
  22. package/internal/utils/log.mjs +2 -0
  23. package/internal/utils/log.mjs.map +1 -1
  24. package/package.json +1 -1
  25. package/resources/shared.d.mts +176 -7
  26. package/resources/shared.d.mts.map +1 -1
  27. package/resources/shared.d.ts +176 -7
  28. package/resources/shared.d.ts.map +1 -1
  29. package/resources/v1/alerts.d.mts +1 -1
  30. package/resources/v1/alerts.d.mts.map +1 -1
  31. package/resources/v1/alerts.d.ts +1 -1
  32. package/resources/v1/alerts.d.ts.map +1 -1
  33. package/resources/v1/contracts/contracts.d.mts +240 -166
  34. package/resources/v1/contracts/contracts.d.mts.map +1 -1
  35. package/resources/v1/contracts/contracts.d.ts +240 -166
  36. package/resources/v1/contracts/contracts.d.ts.map +1 -1
  37. package/resources/v1/contracts/contracts.js +54 -2
  38. package/resources/v1/contracts/contracts.js.map +1 -1
  39. package/resources/v1/contracts/contracts.mjs +54 -2
  40. package/resources/v1/contracts/contracts.mjs.map +1 -1
  41. package/resources/v1/contracts/index.d.mts +1 -1
  42. package/resources/v1/contracts/index.d.mts.map +1 -1
  43. package/resources/v1/contracts/index.d.ts +1 -1
  44. package/resources/v1/contracts/index.d.ts.map +1 -1
  45. package/resources/v1/contracts/index.js.map +1 -1
  46. package/resources/v1/contracts/index.mjs.map +1 -1
  47. package/resources/v1/contracts/products.d.mts +18 -0
  48. package/resources/v1/contracts/products.d.mts.map +1 -1
  49. package/resources/v1/contracts/products.d.ts +18 -0
  50. package/resources/v1/contracts/products.d.ts.map +1 -1
  51. package/resources/v1/customers/alerts.d.mts +1 -1
  52. package/resources/v1/customers/alerts.d.mts.map +1 -1
  53. package/resources/v1/customers/alerts.d.ts +1 -1
  54. package/resources/v1/customers/alerts.d.ts.map +1 -1
  55. package/resources/v1/customers/invoices.d.mts +9 -0
  56. package/resources/v1/customers/invoices.d.mts.map +1 -1
  57. package/resources/v1/customers/invoices.d.ts +9 -0
  58. package/resources/v1/customers/invoices.d.ts.map +1 -1
  59. package/resources/v1/index.d.mts +1 -1
  60. package/resources/v1/index.d.mts.map +1 -1
  61. package/resources/v1/index.d.ts +1 -1
  62. package/resources/v1/index.d.ts.map +1 -1
  63. package/resources/v1/index.js.map +1 -1
  64. package/resources/v1/index.mjs.map +1 -1
  65. package/resources/v1/packages.d.mts +10 -10
  66. package/resources/v1/packages.d.mts.map +1 -1
  67. package/resources/v1/packages.d.ts +10 -10
  68. package/resources/v1/packages.d.ts.map +1 -1
  69. package/resources/v1/v1.d.mts +2 -2
  70. package/resources/v1/v1.d.mts.map +1 -1
  71. package/resources/v1/v1.d.ts +2 -2
  72. package/resources/v1/v1.d.ts.map +1 -1
  73. package/resources/v1/v1.js.map +1 -1
  74. package/resources/v1/v1.mjs.map +1 -1
  75. package/resources/v2/contracts.d.mts +163 -13
  76. package/resources/v2/contracts.d.mts.map +1 -1
  77. package/resources/v2/contracts.d.ts +163 -13
  78. package/resources/v2/contracts.d.ts.map +1 -1
  79. package/resources/webhooks.js +1 -1
  80. package/resources/webhooks.js.map +1 -1
  81. package/resources/webhooks.mjs +1 -1
  82. package/resources/webhooks.mjs.map +1 -1
  83. package/src/client.ts +12 -0
  84. package/src/internal/types.ts +6 -8
  85. package/src/internal/utils/env.ts +2 -2
  86. package/src/internal/utils/log.ts +2 -0
  87. package/src/resources/shared.ts +236 -7
  88. package/src/resources/v1/alerts.ts +1 -1
  89. package/src/resources/v1/contracts/contracts.ts +302 -183
  90. package/src/resources/v1/contracts/index.ts +2 -0
  91. package/src/resources/v1/contracts/products.ts +20 -0
  92. package/src/resources/v1/customers/alerts.ts +1 -1
  93. package/src/resources/v1/customers/invoices.ts +12 -0
  94. package/src/resources/v1/index.ts +2 -0
  95. package/src/resources/v1/packages.ts +14 -14
  96. package/src/resources/v1/v1.ts +4 -0
  97. package/src/resources/v2/contracts.ts +209 -15
  98. package/src/resources/webhooks.ts +1 -1
  99. package/src/version.ts +1 -1
  100. package/version.d.mts +1 -1
  101. package/version.d.ts +1 -1
  102. package/version.js +1 -1
  103. package/version.mjs +1 -1
@@ -9,10 +9,10 @@
9
9
  */
10
10
  export const readEnv = (env: string): string | undefined => {
11
11
  if (typeof (globalThis as any).process !== 'undefined') {
12
- return (globalThis as any).process.env?.[env]?.trim() ?? undefined;
12
+ return (globalThis as any).process.env?.[env]?.trim() || undefined;
13
13
  }
14
14
  if (typeof (globalThis as any).Deno !== 'undefined') {
15
- return (globalThis as any).Deno.env?.get?.(env)?.trim();
15
+ return (globalThis as any).Deno.env?.get?.(env)?.trim() || undefined;
16
16
  }
17
17
  return undefined;
18
18
  };
@@ -107,6 +107,8 @@ export const formatRequestDetails = (details: {
107
107
  name,
108
108
  (
109
109
  name.toLowerCase() === 'authorization' ||
110
+ name.toLowerCase() === 'api-key' ||
111
+ name.toLowerCase() === 'x-api-key' ||
110
112
  name.toLowerCase() === 'cookie' ||
111
113
  name.toLowerCase() === 'set-cookie'
112
114
  ) ?
@@ -34,6 +34,12 @@ export interface BaseThresholdCommit {
34
34
  * will default to the commit product name.
35
35
  */
36
36
  name?: string;
37
+
38
+ /**
39
+ * The priority of the commit, used to determine drawdown order. Lower priority
40
+ * commits are consumed first. Defaults to 100 if not specified.
41
+ */
42
+ priority?: number;
37
43
  }
38
44
 
39
45
  export interface BaseUsageFilter {
@@ -755,7 +761,7 @@ export interface ContractV2 {
755
761
  /**
756
762
  * List of subscriptions on the contract.
757
763
  */
758
- subscriptions?: Array<Subscription>;
764
+ subscriptions?: Array<ContractV2.Subscription>;
759
765
 
760
766
  total_contract_value?: number;
761
767
 
@@ -1081,6 +1087,8 @@ export namespace ContractV2 {
1081
1087
  export interface Override {
1082
1088
  id: string;
1083
1089
 
1090
+ created_at: string;
1091
+
1084
1092
  starting_at: string;
1085
1093
 
1086
1094
  applicable_product_tags?: Array<string>;
@@ -1123,8 +1131,6 @@ export namespace ContractV2 {
1123
1131
  product_tags?: Array<string>;
1124
1132
 
1125
1133
  recurring_commit_ids?: Array<string>;
1126
-
1127
- recurring_credit_ids?: Array<string>;
1128
1134
  }
1129
1135
 
1130
1136
  export interface OverwriteRate {
@@ -1221,6 +1227,8 @@ export namespace ContractV2 {
1221
1227
 
1222
1228
  applicable_product_tags?: Array<string>;
1223
1229
 
1230
+ archived_at?: string;
1231
+
1224
1232
  /**
1225
1233
  * The current balance of the credit or commit. This balance reflects the amount of
1226
1234
  * credit or commit that the customer has access to use at this moment - thus,
@@ -1267,6 +1275,7 @@ export namespace ContractV2 {
1267
1275
  | Credit.CreditCreditedLedgerEntry
1268
1276
  | Credit.CreditManualLedgerEntry
1269
1277
  | Credit.CreditSeatBasedAdjustmentLedgerEntry
1278
+ | Credit.CreditRolloverLedgerEntry
1270
1279
  >;
1271
1280
 
1272
1281
  name?: string;
@@ -1287,6 +1296,8 @@ export namespace ContractV2 {
1287
1296
  */
1288
1297
  recurring_credit_id?: string;
1289
1298
 
1299
+ rolled_over_from?: Credit.RolledOverFrom;
1300
+
1290
1301
  /**
1291
1302
  * This field's availability is dependent on your client's configuration.
1292
1303
  */
@@ -1397,6 +1408,24 @@ export namespace ContractV2 {
1397
1408
 
1398
1409
  type: 'CREDIT_SEAT_BASED_ADJUSTMENT';
1399
1410
  }
1411
+
1412
+ export interface CreditRolloverLedgerEntry {
1413
+ amount: number;
1414
+
1415
+ new_contract_id: string;
1416
+
1417
+ segment_id: string;
1418
+
1419
+ timestamp: string;
1420
+
1421
+ type: 'CREDIT_ROLLOVER';
1422
+ }
1423
+
1424
+ export interface RolledOverFrom {
1425
+ contract_id: string;
1426
+
1427
+ credit_id: string;
1428
+ }
1400
1429
  }
1401
1430
 
1402
1431
  /**
@@ -1828,6 +1857,130 @@ export namespace ContractV2 {
1828
1857
  reseller_contract_value?: number;
1829
1858
  }
1830
1859
  }
1860
+
1861
+ export interface Subscription {
1862
+ /**
1863
+ * Previous, current, and next billing periods for the subscription.
1864
+ */
1865
+ billing_periods: Subscription.BillingPeriods;
1866
+
1867
+ collection_schedule: 'ADVANCE' | 'ARREARS';
1868
+
1869
+ proration: Subscription.Proration;
1870
+
1871
+ /**
1872
+ * Determines how the subscription's quantity is controlled. Defaults to
1873
+ * QUANTITY_ONLY. **QUANTITY_ONLY**: The subscription quantity is specified
1874
+ * directly on the subscription. `initial_quantity` must be provided with this
1875
+ * option. Compatible with recurring commits/credits that use POOLED allocation.
1876
+ * **SEAT_BASED**: Use when you want to pass specific seat identifiers (e.g. add
1877
+ * user_123) to increment and decrement a subscription quantity, rather than
1878
+ * directly providing the quantity. You must use a **SEAT_BASED** subscription to
1879
+ * use a linked recurring credit with an allocation per seat. `seat_config` must be
1880
+ * provided with this option.
1881
+ */
1882
+ quantity_management_mode: 'SEAT_BASED' | 'QUANTITY_ONLY';
1883
+
1884
+ /**
1885
+ * List of quantity schedule items for the subscription. Only includes the current
1886
+ * quantity and future quantity changes.
1887
+ */
1888
+ quantity_schedule: Array<Subscription.QuantitySchedule>;
1889
+
1890
+ starting_at: string;
1891
+
1892
+ subscription_rate: Subscription.SubscriptionRate;
1893
+
1894
+ id?: string;
1895
+
1896
+ /**
1897
+ * Custom fields to be added eg. { "key1": "value1", "key2": "value2" }
1898
+ */
1899
+ custom_fields?: { [key: string]: string };
1900
+
1901
+ description?: string;
1902
+
1903
+ ending_before?: string;
1904
+
1905
+ fiat_credit_type_id?: string;
1906
+
1907
+ name?: string;
1908
+
1909
+ seat_config?: Subscription.SeatConfig;
1910
+ }
1911
+
1912
+ export namespace Subscription {
1913
+ /**
1914
+ * Previous, current, and next billing periods for the subscription.
1915
+ */
1916
+ export interface BillingPeriods {
1917
+ current?: BillingPeriods.Current;
1918
+
1919
+ next?: BillingPeriods.Next;
1920
+
1921
+ previous?: BillingPeriods.Previous;
1922
+ }
1923
+
1924
+ export namespace BillingPeriods {
1925
+ export interface Current {
1926
+ ending_before: string;
1927
+
1928
+ starting_at: string;
1929
+ }
1930
+
1931
+ export interface Next {
1932
+ ending_before: string;
1933
+
1934
+ starting_at: string;
1935
+ }
1936
+
1937
+ export interface Previous {
1938
+ ending_before: string;
1939
+
1940
+ starting_at: string;
1941
+ }
1942
+ }
1943
+
1944
+ export interface Proration {
1945
+ invoice_behavior: 'BILL_IMMEDIATELY' | 'BILL_ON_NEXT_COLLECTION_DATE';
1946
+
1947
+ is_prorated: boolean;
1948
+ }
1949
+
1950
+ export interface QuantitySchedule {
1951
+ quantity: number;
1952
+
1953
+ starting_at: string;
1954
+
1955
+ ending_before?: string;
1956
+ }
1957
+
1958
+ export interface SubscriptionRate {
1959
+ billing_frequency: 'MONTHLY' | 'QUARTERLY' | 'ANNUAL' | 'WEEKLY';
1960
+
1961
+ product: SubscriptionRate.Product;
1962
+ }
1963
+
1964
+ export namespace SubscriptionRate {
1965
+ export interface Product {
1966
+ id: string;
1967
+
1968
+ name: string;
1969
+ }
1970
+ }
1971
+
1972
+ export interface SeatConfig {
1973
+ /**
1974
+ * The property name, sent on usage events, that identifies the seat ID associated
1975
+ * with the usage event. For example, the property name might be seat_id or
1976
+ * user_id. The property must be set as a group key on billable metrics and a
1977
+ * presentation/pricing group key on contract products. This allows linked
1978
+ * recurring credits with an allocation per seat to be consumed by only one seat's
1979
+ * usage.
1980
+ */
1981
+ seat_group_key: string;
1982
+ }
1983
+ }
1831
1984
  }
1832
1985
 
1833
1986
  export interface ContractWithoutAmendments {
@@ -2318,6 +2471,7 @@ export interface Credit {
2318
2471
  | Credit.CreditCreditedLedgerEntry
2319
2472
  | Credit.CreditManualLedgerEntry
2320
2473
  | Credit.CreditSeatBasedAdjustmentLedgerEntry
2474
+ | Credit.CreditRolloverLedgerEntry
2321
2475
  >;
2322
2476
 
2323
2477
  name?: string;
@@ -2341,6 +2495,8 @@ export interface Credit {
2341
2495
  */
2342
2496
  recurring_credit_id?: string;
2343
2497
 
2498
+ rolled_over_from?: Credit.RolledOverFrom;
2499
+
2344
2500
  /**
2345
2501
  * This field's availability is dependent on your client's configuration.
2346
2502
  */
@@ -2461,6 +2617,24 @@ export namespace Credit {
2461
2617
  type: 'CREDIT_SEAT_BASED_ADJUSTMENT';
2462
2618
  }
2463
2619
 
2620
+ export interface CreditRolloverLedgerEntry {
2621
+ amount: number;
2622
+
2623
+ new_contract_id: string;
2624
+
2625
+ segment_id: string;
2626
+
2627
+ timestamp: string;
2628
+
2629
+ type: 'CREDIT_ROLLOVER';
2630
+ }
2631
+
2632
+ export interface RolledOverFrom {
2633
+ contract_id: string;
2634
+
2635
+ credit_id: string;
2636
+ }
2637
+
2464
2638
  /**
2465
2639
  * The subscription configuration for this credit, if it was generated from a
2466
2640
  * recurring credit with a subscription attached.
@@ -2622,6 +2796,8 @@ export interface ID {
2622
2796
  export interface Override {
2623
2797
  id: string;
2624
2798
 
2799
+ created_at: string;
2800
+
2625
2801
  starting_at: string;
2626
2802
 
2627
2803
  applicable_product_tags?: Array<string>;
@@ -2696,8 +2872,6 @@ export namespace Override {
2696
2872
  product_tags?: Array<string>;
2697
2873
 
2698
2874
  recurring_commit_ids?: Array<string>;
2699
-
2700
- recurring_credit_ids?: Array<string>;
2701
2875
  }
2702
2876
 
2703
2877
  export interface Product {
@@ -2899,6 +3073,8 @@ export interface PrepaidBalanceThresholdConfiguration {
2899
3073
  * commit amount will be in terms of this credit type instead of the fiat currency.
2900
3074
  */
2901
3075
  custom_credit_type_id?: string;
3076
+
3077
+ discount_configuration?: PrepaidBalanceThresholdConfiguration.DiscountConfiguration;
2902
3078
  }
2903
3079
 
2904
3080
  export namespace PrepaidBalanceThresholdConfiguration {
@@ -2925,6 +3101,15 @@ export namespace PrepaidBalanceThresholdConfiguration {
2925
3101
  */
2926
3102
  specifiers?: Array<Shared.CommitSpecifierInput>;
2927
3103
  }
3104
+
3105
+ export interface DiscountConfiguration {
3106
+ /**
3107
+ * The fraction of the original amount that the customer pays after applying the
3108
+ * discount. For example, 0.85 means the customer pays 85% of the original amount
3109
+ * (a 15% discount).
3110
+ */
3111
+ payment_fraction: number;
3112
+ }
2928
3113
  }
2929
3114
 
2930
3115
  export interface PrepaidBalanceThresholdConfigurationV2 {
@@ -2955,10 +3140,12 @@ export interface PrepaidBalanceThresholdConfigurationV2 {
2955
3140
  * commit amount will be in terms of this credit type instead of the fiat currency.
2956
3141
  */
2957
3142
  custom_credit_type_id?: string;
3143
+
3144
+ discount_configuration?: PrepaidBalanceThresholdConfigurationV2.DiscountConfiguration;
2958
3145
  }
2959
3146
 
2960
3147
  export namespace PrepaidBalanceThresholdConfigurationV2 {
2961
- export interface Commit extends Shared.UpdateBaseThresholdCommit {
3148
+ export interface Commit extends Shared.BaseThresholdCommit {
2962
3149
  /**
2963
3150
  * Which products the threshold commit applies to. If applicable_product_ids,
2964
3151
  * applicable_product_tags or specifiers are not provided, the commit applies to
@@ -2983,6 +3170,15 @@ export namespace PrepaidBalanceThresholdConfigurationV2 {
2983
3170
  */
2984
3171
  specifiers?: Array<Shared.CommitSpecifierInput>;
2985
3172
  }
3173
+
3174
+ export interface DiscountConfiguration {
3175
+ /**
3176
+ * The fraction of the original amount that the customer pays after applying the
3177
+ * discount. For example, 0.85 means the customer pays 85% of the original amount
3178
+ * (a 15% discount).
3179
+ */
3180
+ payment_fraction: number;
3181
+ }
2986
3182
  }
2987
3183
 
2988
3184
  export interface PropertyFilter {
@@ -3204,10 +3400,23 @@ export interface SpendThresholdConfiguration {
3204
3400
  * hits this amount, a threshold charge will be initiated.
3205
3401
  */
3206
3402
  threshold_amount: number;
3403
+
3404
+ discount_configuration?: SpendThresholdConfiguration.DiscountConfiguration;
3405
+ }
3406
+
3407
+ export namespace SpendThresholdConfiguration {
3408
+ export interface DiscountConfiguration {
3409
+ /**
3410
+ * The fraction of the original amount that the customer pays after applying the
3411
+ * discount. For example, 0.85 means the customer pays 85% of the original amount
3412
+ * (a 15% discount).
3413
+ */
3414
+ payment_fraction: number;
3415
+ }
3207
3416
  }
3208
3417
 
3209
3418
  export interface SpendThresholdConfigurationV2 {
3210
- commit: UpdateBaseThresholdCommit;
3419
+ commit: BaseThresholdCommit;
3211
3420
 
3212
3421
  /**
3213
3422
  * When set to false, the contract will not be evaluated against the
@@ -3223,6 +3432,19 @@ export interface SpendThresholdConfigurationV2 {
3223
3432
  * hits this amount, a threshold charge will be initiated.
3224
3433
  */
3225
3434
  threshold_amount: number;
3435
+
3436
+ discount_configuration?: SpendThresholdConfigurationV2.DiscountConfiguration;
3437
+ }
3438
+
3439
+ export namespace SpendThresholdConfigurationV2 {
3440
+ export interface DiscountConfiguration {
3441
+ /**
3442
+ * The fraction of the original amount that the customer pays after applying the
3443
+ * discount. For example, 0.85 means the customer pays 85% of the original amount
3444
+ * (a 15% discount).
3445
+ */
3446
+ payment_fraction: number;
3447
+ }
3226
3448
  }
3227
3449
 
3228
3450
  export interface Subscription {
@@ -3364,6 +3586,13 @@ export interface UpdateBaseThresholdCommit {
3364
3586
  */
3365
3587
  name?: string;
3366
3588
 
3589
+ /**
3590
+ * The priority of the commit, used to determine drawdown order. Lower priority
3591
+ * commits are consumed first. Defaults to 100 if not specified. On updates, set to
3592
+ * null to clear a previously configured priority.
3593
+ */
3594
+ priority?: number | null;
3595
+
3367
3596
  /**
3368
3597
  * The commit product that will be used to generate the line item for commit
3369
3598
  * payment.
@@ -229,7 +229,7 @@ export interface AlertCreateParams {
229
229
 
230
230
  export namespace AlertCreateParams {
231
231
  export interface CustomFieldFilter {
232
- entity: 'Contract' | 'Commit' | 'ContractCredit';
232
+ entity: 'Contract' | 'Commit' | 'ContractCredit' | 'ContractCreditOrCommit';
233
233
 
234
234
  key: string;
235
235