@metronome/sdk 0.1.0-beta.9 → 0.1.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 (286) hide show
  1. package/CHANGELOG.md +179 -0
  2. package/README.md +30 -46
  3. package/_shims/index.d.ts +2 -0
  4. package/_shims/index.js +5 -1
  5. package/_shims/index.mjs +5 -1
  6. package/core.d.ts +19 -5
  7. package/core.d.ts.map +1 -1
  8. package/core.js +23 -14
  9. package/core.js.map +1 -1
  10. package/core.mjs +24 -15
  11. package/core.mjs.map +1 -1
  12. package/index.d.mts +3 -2
  13. package/index.d.ts +3 -2
  14. package/index.d.ts.map +1 -1
  15. package/index.js +6 -3
  16. package/index.js.map +1 -1
  17. package/index.mjs +6 -3
  18. package/index.mjs.map +1 -1
  19. package/package.json +1 -1
  20. package/pagination.d.ts +1 -0
  21. package/pagination.d.ts.map +1 -1
  22. package/pagination.js +3 -0
  23. package/pagination.js.map +1 -1
  24. package/pagination.mjs +3 -0
  25. package/pagination.mjs.map +1 -1
  26. package/resource.d.ts +1 -1
  27. package/resource.d.ts.map +1 -1
  28. package/resource.js.map +1 -1
  29. package/resource.mjs.map +1 -1
  30. package/resources/shared.d.ts +473 -37
  31. package/resources/shared.d.ts.map +1 -1
  32. package/resources/v1/alerts.d.ts +26 -2
  33. package/resources/v1/alerts.d.ts.map +1 -1
  34. package/resources/v1/alerts.js +19 -0
  35. package/resources/v1/alerts.js.map +1 -1
  36. package/resources/v1/alerts.mjs +19 -0
  37. package/resources/v1/alerts.mjs.map +1 -1
  38. package/resources/v1/audit-logs.d.ts +8 -0
  39. package/resources/v1/audit-logs.d.ts.map +1 -1
  40. package/resources/v1/audit-logs.js.map +1 -1
  41. package/resources/v1/audit-logs.mjs.map +1 -1
  42. package/resources/v1/billable-metrics.d.ts +58 -3
  43. package/resources/v1/billable-metrics.d.ts.map +1 -1
  44. package/resources/v1/billable-metrics.js +41 -0
  45. package/resources/v1/billable-metrics.js.map +1 -1
  46. package/resources/v1/billable-metrics.mjs +41 -0
  47. package/resources/v1/billable-metrics.mjs.map +1 -1
  48. package/resources/v1/contracts/contracts.d.ts +1478 -102
  49. package/resources/v1/contracts/contracts.d.ts.map +1 -1
  50. package/resources/v1/contracts/contracts.js +180 -3
  51. package/resources/v1/contracts/contracts.js.map +1 -1
  52. package/resources/v1/contracts/contracts.mjs +180 -3
  53. package/resources/v1/contracts/contracts.mjs.map +1 -1
  54. package/resources/v1/contracts/index.d.ts +2 -2
  55. package/resources/v1/contracts/index.d.ts.map +1 -1
  56. package/resources/v1/contracts/index.js.map +1 -1
  57. package/resources/v1/contracts/index.mjs.map +1 -1
  58. package/resources/v1/contracts/named-schedules.d.ts +21 -0
  59. package/resources/v1/contracts/named-schedules.d.ts.map +1 -1
  60. package/resources/v1/contracts/named-schedules.js +21 -0
  61. package/resources/v1/contracts/named-schedules.js.map +1 -1
  62. package/resources/v1/contracts/named-schedules.mjs +21 -0
  63. package/resources/v1/contracts/named-schedules.mjs.map +1 -1
  64. package/resources/v1/contracts/products.d.ts +51 -3
  65. package/resources/v1/contracts/products.d.ts.map +1 -1
  66. package/resources/v1/contracts/products.js +33 -0
  67. package/resources/v1/contracts/products.js.map +1 -1
  68. package/resources/v1/contracts/products.mjs +33 -0
  69. package/resources/v1/contracts/products.mjs.map +1 -1
  70. package/resources/v1/contracts/rate-cards/index.d.ts +1 -1
  71. package/resources/v1/contracts/rate-cards/index.d.ts.map +1 -1
  72. package/resources/v1/contracts/rate-cards/index.js.map +1 -1
  73. package/resources/v1/contracts/rate-cards/index.mjs.map +1 -1
  74. package/resources/v1/contracts/rate-cards/named-schedules.d.ts +25 -0
  75. package/resources/v1/contracts/rate-cards/named-schedules.d.ts.map +1 -1
  76. package/resources/v1/contracts/rate-cards/named-schedules.js +25 -0
  77. package/resources/v1/contracts/rate-cards/named-schedules.js.map +1 -1
  78. package/resources/v1/contracts/rate-cards/named-schedules.mjs +25 -0
  79. package/resources/v1/contracts/rate-cards/named-schedules.mjs.map +1 -1
  80. package/resources/v1/contracts/rate-cards/product-orders.d.ts +30 -0
  81. package/resources/v1/contracts/rate-cards/product-orders.d.ts.map +1 -1
  82. package/resources/v1/contracts/rate-cards/product-orders.js +30 -0
  83. package/resources/v1/contracts/rate-cards/product-orders.js.map +1 -1
  84. package/resources/v1/contracts/rate-cards/product-orders.mjs +30 -0
  85. package/resources/v1/contracts/rate-cards/product-orders.mjs.map +1 -1
  86. package/resources/v1/contracts/rate-cards/rate-cards.d.ts +107 -10
  87. package/resources/v1/contracts/rate-cards/rate-cards.d.ts.map +1 -1
  88. package/resources/v1/contracts/rate-cards/rate-cards.js +71 -0
  89. package/resources/v1/contracts/rate-cards/rate-cards.js.map +1 -1
  90. package/resources/v1/contracts/rate-cards/rate-cards.mjs +71 -0
  91. package/resources/v1/contracts/rate-cards/rate-cards.mjs.map +1 -1
  92. package/resources/v1/contracts/rate-cards/rates.d.ts +102 -14
  93. package/resources/v1/contracts/rate-cards/rates.d.ts.map +1 -1
  94. package/resources/v1/contracts/rate-cards/rates.js +68 -0
  95. package/resources/v1/contracts/rate-cards/rates.js.map +1 -1
  96. package/resources/v1/contracts/rate-cards/rates.mjs +68 -0
  97. package/resources/v1/contracts/rate-cards/rates.mjs.map +1 -1
  98. package/resources/v1/credit-grants.d.ts +77 -2
  99. package/resources/v1/credit-grants.d.ts.map +1 -1
  100. package/resources/v1/credit-grants.js +39 -2
  101. package/resources/v1/credit-grants.js.map +1 -1
  102. package/resources/v1/credit-grants.mjs +39 -2
  103. package/resources/v1/credit-grants.mjs.map +1 -1
  104. package/resources/v1/custom-fields.d.ts +51 -7
  105. package/resources/v1/custom-fields.d.ts.map +1 -1
  106. package/resources/v1/custom-fields.js +35 -0
  107. package/resources/v1/custom-fields.js.map +1 -1
  108. package/resources/v1/custom-fields.mjs +35 -0
  109. package/resources/v1/custom-fields.mjs.map +1 -1
  110. package/resources/v1/customers/alerts.d.ts +28 -0
  111. package/resources/v1/customers/alerts.d.ts.map +1 -1
  112. package/resources/v1/customers/alerts.js +23 -0
  113. package/resources/v1/customers/alerts.js.map +1 -1
  114. package/resources/v1/customers/alerts.mjs +23 -0
  115. package/resources/v1/customers/alerts.mjs.map +1 -1
  116. package/resources/v1/customers/billing-config.d.ts +31 -0
  117. package/resources/v1/customers/billing-config.d.ts.map +1 -1
  118. package/resources/v1/customers/billing-config.js +27 -0
  119. package/resources/v1/customers/billing-config.js.map +1 -1
  120. package/resources/v1/customers/billing-config.mjs +27 -0
  121. package/resources/v1/customers/billing-config.mjs.map +1 -1
  122. package/resources/v1/customers/commits.d.ts +94 -7
  123. package/resources/v1/customers/commits.d.ts.map +1 -1
  124. package/resources/v1/customers/commits.js +56 -1
  125. package/resources/v1/customers/commits.js.map +1 -1
  126. package/resources/v1/customers/commits.mjs +56 -1
  127. package/resources/v1/customers/commits.mjs.map +1 -1
  128. package/resources/v1/customers/credits.d.ts +73 -3
  129. package/resources/v1/customers/credits.d.ts.map +1 -1
  130. package/resources/v1/customers/credits.js +41 -1
  131. package/resources/v1/customers/credits.js.map +1 -1
  132. package/resources/v1/customers/credits.mjs +41 -1
  133. package/resources/v1/customers/credits.mjs.map +1 -1
  134. package/resources/v1/customers/customers.d.ts +186 -9
  135. package/resources/v1/customers/customers.d.ts.map +1 -1
  136. package/resources/v1/customers/customers.js +106 -1
  137. package/resources/v1/customers/customers.js.map +1 -1
  138. package/resources/v1/customers/customers.mjs +106 -1
  139. package/resources/v1/customers/customers.mjs.map +1 -1
  140. package/resources/v1/customers/index.d.ts +1 -1
  141. package/resources/v1/customers/index.d.ts.map +1 -1
  142. package/resources/v1/customers/index.js.map +1 -1
  143. package/resources/v1/customers/index.mjs.map +1 -1
  144. package/resources/v1/customers/invoices.d.ts +144 -52
  145. package/resources/v1/customers/invoices.d.ts.map +1 -1
  146. package/resources/v1/customers/invoices.js +49 -0
  147. package/resources/v1/customers/invoices.js.map +1 -1
  148. package/resources/v1/customers/invoices.mjs +49 -0
  149. package/resources/v1/customers/invoices.mjs.map +1 -1
  150. package/resources/v1/customers/named-schedules.d.ts +21 -0
  151. package/resources/v1/customers/named-schedules.d.ts.map +1 -1
  152. package/resources/v1/customers/named-schedules.js +21 -0
  153. package/resources/v1/customers/named-schedules.js.map +1 -1
  154. package/resources/v1/customers/named-schedules.mjs +21 -0
  155. package/resources/v1/customers/named-schedules.mjs.map +1 -1
  156. package/resources/v1/customers/plans.d.ts +46 -1
  157. package/resources/v1/customers/plans.d.ts.map +1 -1
  158. package/resources/v1/customers/plans.js +43 -0
  159. package/resources/v1/customers/plans.js.map +1 -1
  160. package/resources/v1/customers/plans.mjs +43 -0
  161. package/resources/v1/customers/plans.mjs.map +1 -1
  162. package/resources/v1/dashboards.d.ts +30 -2
  163. package/resources/v1/dashboards.d.ts.map +1 -1
  164. package/resources/v1/dashboards.js +26 -0
  165. package/resources/v1/dashboards.js.map +1 -1
  166. package/resources/v1/dashboards.mjs +26 -0
  167. package/resources/v1/dashboards.mjs.map +1 -1
  168. package/resources/v1/index.d.ts +3 -3
  169. package/resources/v1/index.d.ts.map +1 -1
  170. package/resources/v1/index.js.map +1 -1
  171. package/resources/v1/index.mjs.map +1 -1
  172. package/resources/v1/invoices.d.ts +14 -0
  173. package/resources/v1/invoices.d.ts.map +1 -1
  174. package/resources/v1/invoices.js +14 -0
  175. package/resources/v1/invoices.js.map +1 -1
  176. package/resources/v1/invoices.mjs +14 -0
  177. package/resources/v1/invoices.mjs.map +1 -1
  178. package/resources/v1/plans.d.ts +47 -4
  179. package/resources/v1/plans.d.ts.map +1 -1
  180. package/resources/v1/plans.js +27 -0
  181. package/resources/v1/plans.js.map +1 -1
  182. package/resources/v1/plans.mjs +27 -0
  183. package/resources/v1/plans.mjs.map +1 -1
  184. package/resources/v1/pricing-units.d.ts +8 -0
  185. package/resources/v1/pricing-units.d.ts.map +1 -1
  186. package/resources/v1/pricing-units.js.map +1 -1
  187. package/resources/v1/pricing-units.mjs.map +1 -1
  188. package/resources/v1/services.d.ts +5 -0
  189. package/resources/v1/services.d.ts.map +1 -1
  190. package/resources/v1/services.js +5 -0
  191. package/resources/v1/services.js.map +1 -1
  192. package/resources/v1/services.mjs +5 -0
  193. package/resources/v1/services.mjs.map +1 -1
  194. package/resources/v1/usage.d.ts +161 -3
  195. package/resources/v1/usage.d.ts.map +1 -1
  196. package/resources/v1/usage.js +46 -0
  197. package/resources/v1/usage.js.map +1 -1
  198. package/resources/v1/usage.mjs +46 -0
  199. package/resources/v1/usage.mjs.map +1 -1
  200. package/resources/v1/v1.d.ts +6 -6
  201. package/resources/v1/v1.d.ts.map +1 -1
  202. package/resources/v1/v1.js.map +1 -1
  203. package/resources/v1/v1.mjs.map +1 -1
  204. package/resources/v2/contracts.d.ts +2923 -207
  205. package/resources/v2/contracts.d.ts.map +1 -1
  206. package/resources/v2/contracts.js +90 -2
  207. package/resources/v2/contracts.js.map +1 -1
  208. package/resources/v2/contracts.mjs +90 -2
  209. package/resources/v2/contracts.mjs.map +1 -1
  210. package/resources/webhooks.js +5 -5
  211. package/resources/webhooks.js.map +1 -1
  212. package/resources/webhooks.mjs +5 -5
  213. package/resources/webhooks.mjs.map +1 -1
  214. package/src/_shims/auto/runtime-bun.ts +1 -1
  215. package/src/_shims/auto/runtime-node.ts +1 -1
  216. package/src/_shims/auto/runtime.ts +1 -1
  217. package/src/_shims/auto/types-node.ts +1 -1
  218. package/src/_shims/bun-runtime.ts +2 -2
  219. package/src/_shims/index.d.ts +5 -3
  220. package/src/_shims/index.js +5 -1
  221. package/src/_shims/index.mjs +6 -2
  222. package/src/_shims/node-runtime.ts +3 -3
  223. package/src/_shims/registry.ts +1 -1
  224. package/src/_shims/web-runtime.ts +3 -3
  225. package/src/core.ts +46 -18
  226. package/src/error.ts +1 -1
  227. package/src/index.ts +22 -16
  228. package/src/internal/qs/formats.ts +1 -1
  229. package/src/internal/qs/index.ts +3 -3
  230. package/src/internal/qs/stringify.ts +3 -3
  231. package/src/internal/qs/utils.ts +2 -2
  232. package/src/pagination.ts +5 -1
  233. package/src/resource.ts +2 -2
  234. package/src/resources/index.ts +4 -4
  235. package/src/resources/shared.ts +539 -40
  236. package/src/resources/v1/alerts.ts +29 -5
  237. package/src/resources/v1/audit-logs.ts +12 -4
  238. package/src/resources/v1/billable-metrics.ts +57 -8
  239. package/src/resources/v1/contracts/contracts.ts +1643 -124
  240. package/src/resources/v1/contracts/index.ts +8 -4
  241. package/src/resources/v1/contracts/named-schedules.ts +23 -2
  242. package/src/resources/v1/contracts/products.ts +53 -9
  243. package/src/resources/v1/contracts/rate-cards/index.ts +6 -4
  244. package/src/resources/v1/contracts/rate-cards/named-schedules.ts +27 -2
  245. package/src/resources/v1/contracts/rate-cards/product-orders.ts +33 -3
  246. package/src/resources/v1/contracts/rate-cards/rate-cards.ts +113 -20
  247. package/src/resources/v1/contracts/rate-cards/rates.ts +86 -18
  248. package/src/resources/v1/contracts/rate-cards.ts +1 -1
  249. package/src/resources/v1/contracts.ts +1 -1
  250. package/src/resources/v1/credit-grants.ts +82 -10
  251. package/src/resources/v1/custom-fields.ts +57 -9
  252. package/src/resources/v1/customers/alerts.ts +32 -3
  253. package/src/resources/v1/customers/billing-config.ts +34 -2
  254. package/src/resources/v1/customers/commits.ts +97 -10
  255. package/src/resources/v1/customers/credits.ts +76 -6
  256. package/src/resources/v1/customers/customers.ts +208 -27
  257. package/src/resources/v1/customers/index.ts +10 -8
  258. package/src/resources/v1/customers/invoices.ts +123 -57
  259. package/src/resources/v1/customers/named-schedules.ts +23 -2
  260. package/src/resources/v1/customers/plans.ts +48 -5
  261. package/src/resources/v1/customers.ts +1 -1
  262. package/src/resources/v1/dashboards.ts +30 -4
  263. package/src/resources/v1/index.ts +20 -14
  264. package/src/resources/v1/invoices.ts +16 -2
  265. package/src/resources/v1/plans.ts +45 -10
  266. package/src/resources/v1/pricing-units.ts +12 -4
  267. package/src/resources/v1/services.ts +7 -2
  268. package/src/resources/v1/usage.ts +187 -6
  269. package/src/resources/v1/v1.ts +39 -27
  270. package/src/resources/v1.ts +1 -1
  271. package/src/resources/v2/contracts.ts +3397 -235
  272. package/src/resources/v2/index.ts +2 -2
  273. package/src/resources/v2/v2.ts +3 -3
  274. package/src/resources/v2.ts +1 -1
  275. package/src/resources/webhooks.ts +7 -7
  276. package/src/resources.ts +1 -1
  277. package/src/shims/node.ts +3 -3
  278. package/src/shims/web.ts +3 -3
  279. package/src/uploads.ts +4 -4
  280. package/src/version.ts +1 -1
  281. package/version.d.ts +1 -1
  282. package/version.d.ts.map +1 -1
  283. package/version.js +1 -1
  284. package/version.js.map +1 -1
  285. package/version.mjs +1 -1
  286. package/version.mjs.map +1 -1
@@ -64,18 +64,18 @@ class Webhooks extends resource_1.APIResource {
64
64
  const msgDate = (0, core_1.getRequiredHeader)(headers, 'Date');
65
65
  const msgSignature = (0, core_1.getRequiredHeader)(headers, 'Metronome-Webhook-Signature');
66
66
  const now = Date.now();
67
- const timestampSeconds = Math.floor(new Date(msgDate).valueOf());
68
- if (isNaN(timestampSeconds)) {
67
+ const timestampMs = Math.floor(new Date(msgDate).valueOf());
68
+ if (isNaN(timestampMs)) {
69
69
  throw new Error(`Invalid timestamp header: ${msgDate}`);
70
70
  }
71
71
  if (typeof body !== 'string') {
72
72
  throw new Error('Webhook body must be passed as the raw JSON string sent from the server (do not parse it first).');
73
73
  }
74
- const webhook_tolerance_in_seconds = 5 * 60; // 5 minutes
75
- if (now - timestampSeconds > webhook_tolerance_in_seconds) {
74
+ const webhook_tolerance_in_ms = 5 * 60 * 1000; // 5 minutes
75
+ if (now - timestampMs > webhook_tolerance_in_ms) {
76
76
  throw new Error('Webhook timestamp is too old');
77
77
  }
78
- if (timestampSeconds > now + webhook_tolerance_in_seconds) {
78
+ if (timestampMs > now + webhook_tolerance_in_ms) {
79
79
  throw new Error('Webhook timestamp is too new');
80
80
  }
81
81
  const expectedSignature = this.signPayload(body, { date: msgDate, secret });
@@ -1 +1 @@
1
- {"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../src/resources/webhooks.ts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GAAkG,CACnG,CAAC;SACH;QAED,MAAM,uBAAuB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;QAC3D,IAAI,GAAG,GAAG,WAAW,GAAG,uBAAuB,EAAE;YAC/C,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACjD;QAED,IAAI,WAAW,GAAG,GAAG,GAAG,uBAAuB,EAAE;YAC/C,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACjD;QAED,MAAM,iBAAiB,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QAC5E,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC;QAE7C,IAAI,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,EAAE;YACzF,SAAS;YACT,OAAO;SACR;QAED,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;IACvF,CAAC;CACF;AAjHD,4BAiHC"}
@@ -61,18 +61,18 @@ export class Webhooks extends APIResource {
61
61
  const msgDate = getRequiredHeader(headers, 'Date');
62
62
  const msgSignature = getRequiredHeader(headers, 'Metronome-Webhook-Signature');
63
63
  const now = Date.now();
64
- const timestampSeconds = Math.floor(new Date(msgDate).valueOf());
65
- if (isNaN(timestampSeconds)) {
64
+ const timestampMs = Math.floor(new Date(msgDate).valueOf());
65
+ if (isNaN(timestampMs)) {
66
66
  throw new Error(`Invalid timestamp header: ${msgDate}`);
67
67
  }
68
68
  if (typeof body !== 'string') {
69
69
  throw new Error('Webhook body must be passed as the raw JSON string sent from the server (do not parse it first).');
70
70
  }
71
- const webhook_tolerance_in_seconds = 5 * 60; // 5 minutes
72
- if (now - timestampSeconds > webhook_tolerance_in_seconds) {
71
+ const webhook_tolerance_in_ms = 5 * 60 * 1000; // 5 minutes
72
+ if (now - timestampMs > webhook_tolerance_in_ms) {
73
73
  throw new Error('Webhook timestamp is too old');
74
74
  }
75
- if (timestampSeconds > now + webhook_tolerance_in_seconds) {
75
+ if (timestampMs > now + webhook_tolerance_in_ms) {
76
76
  throw new Error('Webhook timestamp is too new');
77
77
  }
78
78
  const expectedSignature = this.signPayload(body, { date: msgDate, secret });
@@ -1 +1 @@
1
- {"version":3,"file":"webhooks.mjs","sourceRoot":"","sources":["../src/resources/webhooks.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,WAAW,EAAE;OACf,EAAE,UAAU,EAAE,MAAM,QAAQ;OAC5B,EAAE,iBAAiB,EAAe;AAEzC,MAAM,OAAO,QAAS,SAAQ,WAAW;IACvC;;OAEG;IACH,MAAM,CACJ,OAAe,EACf,OAAoB,EACpB,SAAoC,IAAI,CAAC,OAAO,CAAC,aAAa;QAE9D,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAEO,cAAc,CAAC,MAAiC;QACtD,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,MAAM,IAAI,KAAK,CACb,0KAA0K,CAC3K,CAAC;SACH;QAED,OAAO;IACT,CAAC;IAEO,WAAW,CAAC,OAAe,EAAE,EAAE,IAAI,EAAE,MAAM,EAAoC;QACrF,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QAErD,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAEpB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;I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CAAC,CAAC;QAE/E,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QAE5D,IAAI,KAAK,CAAC,WAAW,CAAC,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,6BAA6B,OAAO,EAAE,CAAC,CAAC;SACzD;QAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;YAC5B,MAAM,IAAI,KAAK,CACb,kGAAkG,CACnG,CAAC;SACH;QAED,MAAM,uBAAuB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;QAC3D,IAAI,GAAG,GAAG,WAAW,GAAG,uBAAuB,EAAE;YAC/C,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACjD;QAED,IAAI,WAAW,GAAG,GAAG,GAAG,uBAAuB,EAAE;YAC/C,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACjD;QAED,MAAM,iBAAiB,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QAC5E,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC;QAE7C,IAAI,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,EAAE;YACzF,SAAS;YACT,OAAO;SACR;QAED,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;IACvF,CAAC;CACF"}
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
3
  */
4
- export * from '../bun-runtime';
4
+ export * from "../bun-runtime.js";
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
3
  */
4
- export * from '../node-runtime';
4
+ export * from "../node-runtime.js";
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
3
  */
4
- export * from '../web-runtime';
4
+ export * from "../web-runtime.js";
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
3
  */
4
- export * from '../node-types';
4
+ export * from "../node-types.js";
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
3
  */
4
- import { type Shims } from './registry';
5
- import { getRuntime as getWebRuntime } from './web-runtime';
4
+ import { type Shims } from "./registry.js";
5
+ import { getRuntime as getWebRuntime } from "./web-runtime.js";
6
6
  import { ReadStream as FsReadStream } from 'node:fs';
7
7
 
8
8
  export function getRuntime(): Shims {
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
3
  */
4
- import { manual } from './manual-types';
5
- import * as auto from "./auto/types";
6
- import { type RequestOptions } from '../core';
4
+ import { manual } from "./manual-types.js";
5
+ import * as auto from "./auto/types.js";
6
+ import { type RequestOptions } from "../core.js";
7
7
 
8
8
  type SelectType<Manual, Auto> = unknown extends Manual ? Auto : Manual;
9
9
 
@@ -79,3 +79,5 @@ export function fileFromPath(path: string, options?: FileFromPathOptions): Promi
79
79
  export function fileFromPath(path: string, filename?: string, options?: FileFromPathOptions): Promise<File>;
80
80
 
81
81
  export function isFsReadStream(value: any): value is FsReadStream;
82
+
83
+ export const init: () => void;
@@ -3,7 +3,9 @@
3
3
  */
4
4
  const shims = require('./registry');
5
5
  const auto = require('@metronome/sdk/_shims/auto/runtime');
6
- if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
6
+ exports.init = () => {
7
+ if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
8
+ };
7
9
  for (const property of Object.keys(shims)) {
8
10
  Object.defineProperty(exports, property, {
9
11
  get() {
@@ -11,3 +13,5 @@ for (const property of Object.keys(shims)) {
11
13
  },
12
14
  });
13
15
  }
16
+
17
+ exports.init();
@@ -2,6 +2,10 @@
2
2
  * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
3
  */
4
4
  import * as shims from './registry.mjs';
5
- import * as auto from "./auto/runtime";
6
- if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
5
+ import * as auto from "./auto/runtime.mjs";
6
+ export const init = () => {
7
+ if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
8
+ };
7
9
  export * from './registry.mjs';
10
+
11
+ init();
@@ -10,9 +10,9 @@ import { ReadStream as FsReadStream } from 'node:fs';
10
10
  import { type Agent } from 'node:http';
11
11
  import { FormDataEncoder } from 'form-data-encoder';
12
12
  import { Readable } from 'node:stream';
13
- import { type RequestOptions } from '../core';
14
- import { MultipartBody } from './MultipartBody';
15
- import { type Shims } from './registry';
13
+ import { type RequestOptions } from "../core.js";
14
+ import { MultipartBody } from "./MultipartBody.js";
15
+ import { type Shims } from "./registry.js";
16
16
  import { ReadableStream } from 'node:stream/web';
17
17
 
18
18
  type FileFromPathOptions = Omit<FilePropertyBag, 'lastModified'>;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
3
  */
4
- import { type RequestOptions } from '../core';
4
+ import { type RequestOptions } from "../core.js";
5
5
 
6
6
  export interface Shims {
7
7
  kind: string;
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
3
  */
4
- import { MultipartBody } from './MultipartBody';
5
- import { type RequestOptions } from '../core';
6
- import { type Shims } from './registry';
4
+ import { MultipartBody } from "./MultipartBody.js";
5
+ import { type RequestOptions } from "../core.js";
6
+ import { type Shims } from "./registry.js";
7
7
 
8
8
  export function getRuntime({ manuallyImported }: { manuallyImported?: boolean } = {}): Shims {
9
9
  const recommendation =
package/src/core.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { VERSION } from './version';
1
+ import { VERSION } from "./version.js";
2
2
  import {
3
3
  MetronomeError,
4
4
  APIError,
5
5
  APIConnectionError,
6
6
  APIConnectionTimeoutError,
7
7
  APIUserAbortError,
8
- } from './error';
8
+ } from "./error.js";
9
9
  import {
10
10
  kind as shimsKind,
11
11
  type Readable,
@@ -16,18 +16,37 @@ import {
16
16
  type RequestInit,
17
17
  type Response,
18
18
  type HeadersInit,
19
- } from './_shims/index';
19
+ init,
20
+ } from "./_shims/index.js";
21
+
22
+ // try running side effects outside of _shims/index to workaround https://github.com/vercel/next.js/issues/76881
23
+ init();
24
+
20
25
  export { type Response };
21
- import { BlobLike, isBlobLike, isMultipartBody } from './uploads';
26
+ import { BlobLike, isBlobLike, isMultipartBody } from "./uploads.js";
22
27
  export {
23
28
  maybeMultipartFormRequestOptions,
24
29
  multipartFormRequestOptions,
25
30
  createForm,
26
31
  type Uploadable,
27
- } from './uploads';
32
+ } from "./uploads.js";
28
33
 
29
34
  export type Fetch = (url: RequestInfo, init?: RequestInit) => Promise<Response>;
30
35
 
36
+ /**
37
+ * An alias to the builtin `Array` type so we can
38
+ * easily alias it in import statements if there are name clashes.
39
+ */
40
+ type _Array<T> = Array<T>;
41
+
42
+ /**
43
+ * An alias to the builtin `Record` type so we can
44
+ * easily alias it in import statements if there are name clashes.
45
+ */
46
+ type _Record<K extends keyof any, T> = Record<K, T>;
47
+
48
+ export type { _Array as Array, _Record as Record };
49
+
31
50
  type PromiseOrValue<T> = T | Promise<T>;
32
51
 
33
52
  type APIResponseProps = {
@@ -151,6 +170,7 @@ export class APIPromise<T> extends Promise<T> {
151
170
 
152
171
  export abstract class APIClient {
153
172
  baseURL: string;
173
+ #baseURLOverridden: boolean;
154
174
  maxRetries: number;
155
175
  timeout: number;
156
176
  httpAgent: Agent | undefined;
@@ -160,18 +180,21 @@ export abstract class APIClient {
160
180
 
161
181
  constructor({
162
182
  baseURL,
183
+ baseURLOverridden,
163
184
  maxRetries = 2,
164
185
  timeout = 60000, // 1 minute
165
186
  httpAgent,
166
187
  fetch: overriddenFetch,
167
188
  }: {
168
189
  baseURL: string;
190
+ baseURLOverridden: boolean;
169
191
  maxRetries?: number | undefined;
170
192
  timeout: number | undefined;
171
193
  httpAgent: Agent | undefined;
172
194
  fetch: Fetch | undefined;
173
195
  }) {
174
196
  this.baseURL = baseURL;
197
+ this.#baseURLOverridden = baseURLOverridden;
175
198
  this.maxRetries = validatePositiveInteger('maxRetries', maxRetries);
176
199
  this.timeout = validatePositiveInteger('timeout', timeout);
177
200
  this.httpAgent = httpAgent;
@@ -194,7 +217,7 @@ export abstract class APIClient {
194
217
  protected defaultHeaders(opts: FinalRequestOptions): Headers {
195
218
  return {
196
219
  Accept: 'application/json',
197
- 'Content-Type': 'application/json',
220
+ ...(['head', 'get'].includes(opts.method) ? {} : { 'Content-Type': 'application/json' }),
198
221
  'User-Agent': this.getUserAgent(),
199
222
  ...getPlatformHeaders(),
200
223
  ...this.authHeaders(opts),
@@ -276,12 +299,12 @@ export abstract class APIClient {
276
299
  return null;
277
300
  }
278
301
 
279
- buildRequest<Req>(
280
- options: FinalRequestOptions<Req>,
302
+ async buildRequest<Req>(
303
+ inputOptions: FinalRequestOptions<Req>,
281
304
  { retryCount = 0 }: { retryCount?: number } = {},
282
- ): { req: RequestInit; url: string; timeout: number } {
283
- options = { ...options };
284
- const { method, path, query, headers: headers = {} } = options;
305
+ ): Promise<{ req: RequestInit; url: string; timeout: number }> {
306
+ const options = { ...inputOptions };
307
+ const { method, path, query, defaultBaseURL, headers: headers = {} } = options;
285
308
 
286
309
  const body =
287
310
  ArrayBuffer.isView(options.body) || (options.__binaryRequest && typeof options.body === 'string') ?
@@ -291,7 +314,7 @@ export abstract class APIClient {
291
314
  : null;
292
315
  const contentLength = this.calculateContentLength(body);
293
316
 
294
- const url = this.buildURL(path!, query);
317
+ const url = this.buildURL(path!, query, defaultBaseURL);
295
318
  if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
296
319
  options.timeout = options.timeout ?? this.timeout;
297
320
  const httpAgent = options.httpAgent ?? this.httpAgent ?? getDefaultAgent(url);
@@ -308,8 +331,8 @@ export abstract class APIClient {
308
331
  }
309
332
 
310
333
  if (this.idempotencyHeader && method !== 'get') {
311
- if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();
312
- headers[this.idempotencyHeader] = options.idempotencyKey;
334
+ if (!inputOptions.idempotencyKey) inputOptions.idempotencyKey = this.defaultIdempotencyKey();
335
+ headers[this.idempotencyHeader] = inputOptions.idempotencyKey;
313
336
  }
314
337
 
315
338
  const reqHeaders = this.buildHeaders({ options, headers, contentLength, retryCount });
@@ -366,7 +389,7 @@ export abstract class APIClient {
366
389
  getHeader(headers, 'x-stainless-timeout') === undefined &&
367
390
  options.timeout
368
391
  ) {
369
- reqHeaders['x-stainless-timeout'] = String(options.timeout);
392
+ reqHeaders['x-stainless-timeout'] = String(Math.trunc(options.timeout / 1000));
370
393
  }
371
394
 
372
395
  this.validateHeaders(reqHeaders, headers);
@@ -427,7 +450,9 @@ export abstract class APIClient {
427
450
 
428
451
  await this.prepareOptions(options);
429
452
 
430
- const { req, url, timeout } = this.buildRequest(options, { retryCount: maxRetries - retriesRemaining });
453
+ const { req, url, timeout } = await this.buildRequest(options, {
454
+ retryCount: maxRetries - retriesRemaining,
455
+ });
431
456
 
432
457
  await this.prepareRequest(req, { url, options });
433
458
 
@@ -484,11 +509,12 @@ export abstract class APIClient {
484
509
  return new PagePromise<PageClass, Item>(this, request, Page);
485
510
  }
486
511
 
487
- buildURL<Req>(path: string, query: Req | null | undefined): string {
512
+ buildURL<Req>(path: string, query: Req | null | undefined, defaultBaseURL?: string | undefined): string {
513
+ const baseURL = (!this.#baseURLOverridden && defaultBaseURL) || this.baseURL;
488
514
  const url =
489
515
  isAbsoluteURL(path) ?
490
516
  new URL(path)
491
- : new URL(this.baseURL + (this.baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
517
+ : new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
492
518
 
493
519
  const defaultQuery = this.defaultQuery();
494
520
  if (!isEmptyObj(defaultQuery)) {
@@ -773,6 +799,7 @@ export type RequestOptions<
773
799
  query?: Req | undefined;
774
800
  body?: Req | null | undefined;
775
801
  headers?: Headers | undefined;
802
+ defaultBaseURL?: string | undefined;
776
803
 
777
804
  maxRetries?: number;
778
805
  stream?: boolean | undefined;
@@ -794,6 +821,7 @@ const requestOptionsKeys: KeysEnum<RequestOptions> = {
794
821
  query: true,
795
822
  body: true,
796
823
  headers: true,
824
+ defaultBaseURL: true,
797
825
 
798
826
  maxRetries: true,
799
827
  stream: true,
package/src/error.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import { castToError, Headers } from './core';
3
+ import { castToError, Headers } from "./core.js";
4
4
 
5
5
  export class MetronomeError extends Error {}
6
6
 
package/src/index.ts CHANGED
@@ -1,17 +1,15 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import { type Agent } from './_shims/index';
4
- import * as qs from './internal/qs';
5
- import * as Core from './core';
6
- import * as Errors from './error';
7
- import * as Pagination from './pagination';
8
- import { type CursorPageParams, CursorPageResponse } from './pagination';
9
- import * as Uploads from './uploads';
10
- import * as API from './resources/index';
11
- import { V1 } from './resources/v1/v1';
12
- import { V2 } from './resources/v2/v2';
13
-
14
- import { Webhooks } from './resources/webhooks';
3
+ import { type Agent } from "./_shims/index.js";
4
+ import * as qs from "./internal/qs.js";
5
+ import * as Core from "./core.js";
6
+ import * as Errors from "./error.js";
7
+ import * as Pagination from "./pagination.js";
8
+ import { type CursorPageParams, CursorPageResponse } from "./pagination.js";
9
+ import * as Uploads from "./uploads.js";
10
+ import * as API from "./resources/index.js";
11
+ import { V1 } from "./resources/v1/v1.js";
12
+ import { V2 } from "./resources/v2/v2.js";
15
13
 
16
14
  export interface ClientOptions {
17
15
  /**
@@ -37,6 +35,8 @@ export interface ClientOptions {
37
35
  *
38
36
  * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
39
37
  * much longer than this timeout before the promise succeeds or fails.
38
+ *
39
+ * @unit milliseconds
40
40
  */
41
41
  timeout?: number | undefined;
42
42
 
@@ -124,6 +124,7 @@ export class Metronome extends Core.APIClient {
124
124
 
125
125
  super({
126
126
  baseURL: options.baseURL!,
127
+ baseURLOverridden: baseURL ? baseURL !== 'https://api.metronome.com' : false,
127
128
  timeout: options.timeout ?? 60000 /* 1 minute */,
128
129
  httpAgent: options.httpAgent,
129
130
  maxRetries: options.maxRetries,
@@ -140,6 +141,13 @@ export class Metronome extends Core.APIClient {
140
141
  v1: API.V1 = new API.V1(this);
141
142
  webhooks: API.Webhooks = new API.Webhooks(this);
142
143
 
144
+ /**
145
+ * Check whether the base URL is set to its default.
146
+ */
147
+ #baseURLOverridden(): boolean {
148
+ return this.baseURL !== 'https://api.metronome.com';
149
+ }
150
+
143
151
  protected override defaultQuery(): Core.DefaultQuery | undefined {
144
152
  return this._options.defaultQuery;
145
153
  }
@@ -192,8 +200,6 @@ export declare namespace Metronome {
192
200
 
193
201
  export { V1 as V1 };
194
202
 
195
- export { Webhooks as Webhooks };
196
-
197
203
  export type BaseUsageFilter = API.BaseUsageFilter;
198
204
  export type Commit = API.Commit;
199
205
  export type ContractWithoutAmendments = API.ContractWithoutAmendments;
@@ -212,7 +218,7 @@ export declare namespace Metronome {
212
218
  export type Tier = API.Tier;
213
219
  }
214
220
 
215
- export { toFile, fileFromPath } from './uploads';
221
+ export { toFile, fileFromPath } from "./uploads.js";
216
222
  export {
217
223
  MetronomeError,
218
224
  APIError,
@@ -227,6 +233,6 @@ export {
227
233
  InternalServerError,
228
234
  PermissionDeniedError,
229
235
  UnprocessableEntityError,
230
- } from './error';
236
+ } from "./error.js";
231
237
 
232
238
  export default Metronome;
@@ -1,4 +1,4 @@
1
- import type { Format } from './types';
1
+ import type { Format } from "./types.js";
2
2
 
3
3
  export const default_format: Format = 'RFC3986';
4
4
  export const formatters: Record<Format, (str: PropertyKey) => string> = {
@@ -1,4 +1,4 @@
1
- import { default_format, formatters, RFC1738, RFC3986 } from './formats';
1
+ import { default_format, formatters, RFC1738, RFC3986 } from "./formats.js";
2
2
 
3
3
  const formats = {
4
4
  formatters,
@@ -7,7 +7,7 @@ const formats = {
7
7
  default: default_format,
8
8
  };
9
9
 
10
- export { stringify } from './stringify';
10
+ export { stringify } from "./stringify.js";
11
11
  export { formats };
12
12
 
13
- export type { DefaultDecoder, DefaultEncoder, Format, ParseOptions, StringifyOptions } from './types';
13
+ export type { DefaultDecoder, DefaultEncoder, Format, ParseOptions, StringifyOptions } from "./types.js";
@@ -1,6 +1,6 @@
1
- import { encode, is_buffer, maybe_map } from './utils';
2
- import { default_format, formatters } from './formats';
3
- import type { NonNullableProperties, StringifyOptions } from './types';
1
+ import { encode, is_buffer, maybe_map } from "./utils.js";
2
+ import { default_format, formatters } from "./formats.js";
3
+ import type { NonNullableProperties, StringifyOptions } from "./types.js";
4
4
 
5
5
  const has = Object.prototype.hasOwnProperty;
6
6
 
@@ -1,5 +1,5 @@
1
- import { RFC1738 } from './formats';
2
- import type { DefaultEncoder, Format } from './types';
1
+ import { RFC1738 } from "./formats.js";
2
+ import type { DefaultEncoder, Format } from "./types.js";
3
3
 
4
4
  const has = Object.prototype.hasOwnProperty;
5
5
  const is_array = Array.isArray;
package/src/pagination.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from './core';
3
+ import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from "./core.js";
4
4
 
5
5
  export interface CursorPageResponse<Item> {
6
6
  /**
@@ -53,6 +53,10 @@ export class CursorPage<Item> extends AbstractPage<Item> implements CursorPageRe
53
53
  return this.data ?? [];
54
54
  }
55
55
 
56
+ override hasNextPage(): boolean {
57
+ return this.nextPageInfo() != null;
58
+ }
59
+
56
60
  // @deprecated Please use `nextPageInfo()` instead
57
61
  nextPageParams(): Partial<CursorPageParams> | null {
58
62
  const info = this.nextPageInfo();
package/src/resource.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import type { Metronome } from './index';
3
+ import type { Metronome } from "./index.js";
4
4
 
5
- export class APIResource {
5
+ export abstract class APIResource {
6
6
  protected _client: Metronome;
7
7
 
8
8
  constructor(client: Metronome) {
@@ -1,6 +1,6 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- export * from './shared';
4
- export { V1 } from './v1/v1';
5
- export { V2 } from './v2/v2';
6
- export { Webhooks } from './webhooks';
3
+ export * from "./shared.js";
4
+ export { V1 } from "./v1/v1.js";
5
+ export { V2 } from "./v2/v2.js";
6
+ export { Webhooks } from "./webhooks.js";