@metronome/sdk 0.1.0-alpha.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 (284) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/LICENSE +201 -0
  3. package/README.md +313 -0
  4. package/_shims/MultipartBody.d.ts +9 -0
  5. package/_shims/MultipartBody.d.ts.map +1 -0
  6. package/_shims/MultipartBody.js +16 -0
  7. package/_shims/MultipartBody.js.map +1 -0
  8. package/_shims/MultipartBody.mjs +12 -0
  9. package/_shims/MultipartBody.mjs.map +1 -0
  10. package/_shims/README.md +46 -0
  11. package/_shims/auto/runtime-bun.d.ts +5 -0
  12. package/_shims/auto/runtime-bun.d.ts.map +1 -0
  13. package/_shims/auto/runtime-bun.js +21 -0
  14. package/_shims/auto/runtime-bun.js.map +1 -0
  15. package/_shims/auto/runtime-bun.mjs +2 -0
  16. package/_shims/auto/runtime-bun.mjs.map +1 -0
  17. package/_shims/auto/runtime-node.d.ts +5 -0
  18. package/_shims/auto/runtime-node.d.ts.map +1 -0
  19. package/_shims/auto/runtime-node.js +21 -0
  20. package/_shims/auto/runtime-node.js.map +1 -0
  21. package/_shims/auto/runtime-node.mjs +2 -0
  22. package/_shims/auto/runtime-node.mjs.map +1 -0
  23. package/_shims/auto/runtime.d.ts +5 -0
  24. package/_shims/auto/runtime.d.ts.map +1 -0
  25. package/_shims/auto/runtime.js +21 -0
  26. package/_shims/auto/runtime.js.map +1 -0
  27. package/_shims/auto/runtime.mjs +2 -0
  28. package/_shims/auto/runtime.mjs.map +1 -0
  29. package/_shims/auto/types-node.d.ts +5 -0
  30. package/_shims/auto/types-node.d.ts.map +1 -0
  31. package/_shims/auto/types-node.js +21 -0
  32. package/_shims/auto/types-node.js.map +1 -0
  33. package/_shims/auto/types-node.mjs +2 -0
  34. package/_shims/auto/types-node.mjs.map +1 -0
  35. package/_shims/auto/types.d.ts +101 -0
  36. package/_shims/auto/types.js +3 -0
  37. package/_shims/auto/types.mjs +3 -0
  38. package/_shims/bun-runtime.d.ts +6 -0
  39. package/_shims/bun-runtime.d.ts.map +1 -0
  40. package/_shims/bun-runtime.js +14 -0
  41. package/_shims/bun-runtime.js.map +1 -0
  42. package/_shims/bun-runtime.mjs +10 -0
  43. package/_shims/bun-runtime.mjs.map +1 -0
  44. package/_shims/index.d.ts +81 -0
  45. package/_shims/index.js +13 -0
  46. package/_shims/index.mjs +7 -0
  47. package/_shims/manual-types.d.ts +12 -0
  48. package/_shims/manual-types.js +3 -0
  49. package/_shims/manual-types.mjs +3 -0
  50. package/_shims/node-runtime.d.ts +3 -0
  51. package/_shims/node-runtime.d.ts.map +1 -0
  52. package/_shims/node-runtime.js +90 -0
  53. package/_shims/node-runtime.js.map +1 -0
  54. package/_shims/node-runtime.mjs +56 -0
  55. package/_shims/node-runtime.mjs.map +1 -0
  56. package/_shims/node-types.d.ts +42 -0
  57. package/_shims/node-types.js +3 -0
  58. package/_shims/node-types.mjs +3 -0
  59. package/_shims/registry.d.ts +37 -0
  60. package/_shims/registry.d.ts.map +1 -0
  61. package/_shims/registry.js +41 -0
  62. package/_shims/registry.js.map +1 -0
  63. package/_shims/registry.mjs +37 -0
  64. package/_shims/registry.mjs.map +1 -0
  65. package/_shims/web-runtime.d.ts +5 -0
  66. package/_shims/web-runtime.d.ts.map +1 -0
  67. package/_shims/web-runtime.js +78 -0
  68. package/_shims/web-runtime.js.map +1 -0
  69. package/_shims/web-runtime.mjs +71 -0
  70. package/_shims/web-runtime.mjs.map +1 -0
  71. package/_shims/web-types.d.ts +83 -0
  72. package/_shims/web-types.js +3 -0
  73. package/_shims/web-types.mjs +3 -0
  74. package/core.d.ts +237 -0
  75. package/core.d.ts.map +1 -0
  76. package/core.js +868 -0
  77. package/core.js.map +1 -0
  78. package/core.mjs +837 -0
  79. package/core.mjs.map +1 -0
  80. package/error.d.ts +53 -0
  81. package/error.d.ts.map +1 -0
  82. package/error.js +143 -0
  83. package/error.js.map +1 -0
  84. package/error.mjs +127 -0
  85. package/error.mjs.map +1 -0
  86. package/index.d.mts +210 -0
  87. package/index.d.ts +210 -0
  88. package/index.d.ts.map +1 -0
  89. package/index.js +133 -0
  90. package/index.js.map +1 -0
  91. package/index.mjs +105 -0
  92. package/index.mjs.map +1 -0
  93. package/package.json +106 -0
  94. package/resource.d.ts +6 -0
  95. package/resource.d.ts.map +1 -0
  96. package/resource.js +11 -0
  97. package/resource.js.map +1 -0
  98. package/resource.mjs +7 -0
  99. package/resource.mjs.map +1 -0
  100. package/resources/alerts.d.ts +103 -0
  101. package/resources/alerts.d.ts.map +1 -0
  102. package/resources/alerts.js +23 -0
  103. package/resources/alerts.js.map +1 -0
  104. package/resources/alerts.mjs +19 -0
  105. package/resources/alerts.mjs.map +1 -0
  106. package/resources/audit-logs.d.ts +83 -0
  107. package/resources/audit-logs.d.ts.map +1 -0
  108. package/resources/audit-logs.js +18 -0
  109. package/resources/audit-logs.js.map +1 -0
  110. package/resources/audit-logs.mjs +14 -0
  111. package/resources/audit-logs.mjs.map +1 -0
  112. package/resources/billable-metrics.d.ts +236 -0
  113. package/resources/billable-metrics.d.ts.map +1 -0
  114. package/resources/billable-metrics.js +36 -0
  115. package/resources/billable-metrics.js.map +1 -0
  116. package/resources/billable-metrics.mjs +32 -0
  117. package/resources/billable-metrics.mjs.map +1 -0
  118. package/resources/credit-grants.d.ts +469 -0
  119. package/resources/credit-grants.d.ts.map +1 -0
  120. package/resources/credit-grants.js +50 -0
  121. package/resources/credit-grants.js.map +1 -0
  122. package/resources/credit-grants.mjs +46 -0
  123. package/resources/credit-grants.mjs.map +1 -0
  124. package/resources/custom-fields.d.ts +82 -0
  125. package/resources/custom-fields.d.ts.map +1 -0
  126. package/resources/custom-fields.js +66 -0
  127. package/resources/custom-fields.js.map +1 -0
  128. package/resources/custom-fields.mjs +62 -0
  129. package/resources/custom-fields.mjs.map +1 -0
  130. package/resources/customers/alerts.d.ts +146 -0
  131. package/resources/customers/alerts.d.ts.map +1 -0
  132. package/resources/customers/alerts.js +35 -0
  133. package/resources/customers/alerts.js.map +1 -0
  134. package/resources/customers/alerts.mjs +31 -0
  135. package/resources/customers/alerts.mjs.map +1 -0
  136. package/resources/customers/billing-config.d.ts +64 -0
  137. package/resources/customers/billing-config.d.ts.map +1 -0
  138. package/resources/customers/billing-config.js +37 -0
  139. package/resources/customers/billing-config.js.map +1 -0
  140. package/resources/customers/billing-config.mjs +33 -0
  141. package/resources/customers/billing-config.mjs.map +1 -0
  142. package/resources/customers/customers.d.ts +313 -0
  143. package/resources/customers/customers.d.ts.map +1 -0
  144. package/resources/customers/customers.js +116 -0
  145. package/resources/customers/customers.js.map +1 -0
  146. package/resources/customers/customers.mjs +89 -0
  147. package/resources/customers/customers.mjs.map +1 -0
  148. package/resources/customers/index.d.ts +6 -0
  149. package/resources/customers/index.d.ts.map +1 -0
  150. package/resources/customers/index.js +15 -0
  151. package/resources/customers/index.js.map +1 -0
  152. package/resources/customers/index.mjs +7 -0
  153. package/resources/customers/index.mjs.map +1 -0
  154. package/resources/customers/invoices.d.ts +331 -0
  155. package/resources/customers/invoices.d.ts.map +1 -0
  156. package/resources/customers/invoices.js +30 -0
  157. package/resources/customers/invoices.js.map +1 -0
  158. package/resources/customers/invoices.mjs +26 -0
  159. package/resources/customers/invoices.mjs.map +1 -0
  160. package/resources/customers/plans.d.ts +239 -0
  161. package/resources/customers/plans.d.ts.map +1 -0
  162. package/resources/customers/plans.js +41 -0
  163. package/resources/customers/plans.js.map +1 -0
  164. package/resources/customers/plans.mjs +37 -0
  165. package/resources/customers/plans.mjs.map +1 -0
  166. package/resources/dashboards.d.ts +61 -0
  167. package/resources/dashboards.d.ts.map +1 -0
  168. package/resources/dashboards.js +19 -0
  169. package/resources/dashboards.js.map +1 -0
  170. package/resources/dashboards.mjs +15 -0
  171. package/resources/dashboards.mjs.map +1 -0
  172. package/resources/index.d.ts +13 -0
  173. package/resources/index.d.ts.map +1 -0
  174. package/resources/index.js +42 -0
  175. package/resources/index.js.map +1 -0
  176. package/resources/index.mjs +14 -0
  177. package/resources/index.mjs.map +1 -0
  178. package/resources/plans.d.ts +217 -0
  179. package/resources/plans.d.ts.map +1 -0
  180. package/resources/plans.js +36 -0
  181. package/resources/plans.js.map +1 -0
  182. package/resources/plans.mjs +32 -0
  183. package/resources/plans.mjs.map +1 -0
  184. package/resources/services.d.ts +26 -0
  185. package/resources/services.d.ts.map +1 -0
  186. package/resources/services.js +20 -0
  187. package/resources/services.js.map +1 -0
  188. package/resources/services.mjs +16 -0
  189. package/resources/services.mjs.map +1 -0
  190. package/resources/shared.d.ts +540 -0
  191. package/resources/shared.d.ts.map +1 -0
  192. package/resources/shared.js +4 -0
  193. package/resources/shared.js.map +1 -0
  194. package/resources/shared.mjs +3 -0
  195. package/resources/shared.mjs.map +1 -0
  196. package/resources/usage.d.ts +182 -0
  197. package/resources/usage.d.ts.map +1 -0
  198. package/resources/usage.js +41 -0
  199. package/resources/usage.js.map +1 -0
  200. package/resources/usage.mjs +37 -0
  201. package/resources/usage.mjs.map +1 -0
  202. package/resources/webhooks.d.ts +22 -0
  203. package/resources/webhooks.d.ts.map +1 -0
  204. package/resources/webhooks.js +91 -0
  205. package/resources/webhooks.js.map +1 -0
  206. package/resources/webhooks.mjs +87 -0
  207. package/resources/webhooks.mjs.map +1 -0
  208. package/shims/node.d.ts +29 -0
  209. package/shims/node.d.ts.map +1 -0
  210. package/shims/node.js +31 -0
  211. package/shims/node.js.map +1 -0
  212. package/shims/node.mjs +5 -0
  213. package/shims/node.mjs.map +1 -0
  214. package/shims/web.d.ts +26 -0
  215. package/shims/web.d.ts.map +1 -0
  216. package/shims/web.js +31 -0
  217. package/shims/web.js.map +1 -0
  218. package/shims/web.mjs +5 -0
  219. package/shims/web.mjs.map +1 -0
  220. package/src/_shims/MultipartBody.ts +9 -0
  221. package/src/_shims/README.md +46 -0
  222. package/src/_shims/auto/runtime-bun.ts +4 -0
  223. package/src/_shims/auto/runtime-node.ts +4 -0
  224. package/src/_shims/auto/runtime.ts +4 -0
  225. package/src/_shims/auto/types-node.ts +4 -0
  226. package/src/_shims/auto/types.d.ts +101 -0
  227. package/src/_shims/auto/types.js +3 -0
  228. package/src/_shims/auto/types.mjs +3 -0
  229. package/src/_shims/bun-runtime.ts +14 -0
  230. package/src/_shims/index.d.ts +81 -0
  231. package/src/_shims/index.js +13 -0
  232. package/src/_shims/index.mjs +7 -0
  233. package/src/_shims/manual-types.d.ts +12 -0
  234. package/src/_shims/manual-types.js +3 -0
  235. package/src/_shims/manual-types.mjs +3 -0
  236. package/src/_shims/node-runtime.ts +83 -0
  237. package/src/_shims/node-types.d.ts +42 -0
  238. package/src/_shims/node-types.js +3 -0
  239. package/src/_shims/node-types.mjs +3 -0
  240. package/src/_shims/registry.ts +67 -0
  241. package/src/_shims/web-runtime.ts +103 -0
  242. package/src/_shims/web-types.d.ts +83 -0
  243. package/src/_shims/web-types.js +3 -0
  244. package/src/_shims/web-types.mjs +3 -0
  245. package/src/core.ts +1146 -0
  246. package/src/error.ts +146 -0
  247. package/src/index.ts +303 -0
  248. package/src/lib/.keep +4 -0
  249. package/src/resource.ts +11 -0
  250. package/src/resources/alerts.ts +144 -0
  251. package/src/resources/audit-logs.ts +116 -0
  252. package/src/resources/billable-metrics.ts +341 -0
  253. package/src/resources/credit-grants.ts +627 -0
  254. package/src/resources/custom-fields.ts +242 -0
  255. package/src/resources/customers/alerts.ts +214 -0
  256. package/src/resources/customers/billing-config.ts +183 -0
  257. package/src/resources/customers/customers.ts +500 -0
  258. package/src/resources/customers/index.ts +53 -0
  259. package/src/resources/customers/invoices.ts +533 -0
  260. package/src/resources/customers/plans.ts +363 -0
  261. package/src/resources/dashboards.ts +98 -0
  262. package/src/resources/index.ts +90 -0
  263. package/src/resources/plans.ts +333 -0
  264. package/src/resources/services.ts +35 -0
  265. package/src/resources/shared.ts +849 -0
  266. package/src/resources/usage.ts +245 -0
  267. package/src/resources/webhooks.ts +120 -0
  268. package/src/shims/node.ts +50 -0
  269. package/src/shims/web.ts +50 -0
  270. package/src/tsconfig.json +11 -0
  271. package/src/uploads.ts +248 -0
  272. package/src/version.ts +1 -0
  273. package/uploads.d.ts +75 -0
  274. package/uploads.d.ts.map +1 -0
  275. package/uploads.js +165 -0
  276. package/uploads.js.map +1 -0
  277. package/uploads.mjs +152 -0
  278. package/uploads.mjs.map +1 -0
  279. package/version.d.ts +2 -0
  280. package/version.d.ts.map +1 -0
  281. package/version.js +5 -0
  282. package/version.js.map +1 -0
  283. package/version.mjs +2 -0
  284. package/version.mjs.map +1 -0
package/src/error.ts ADDED
@@ -0,0 +1,146 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { castToError, Headers } from './core';
4
+
5
+ export class MetronomeError extends Error {}
6
+
7
+ export class APIError extends MetronomeError {
8
+ readonly status: number | undefined;
9
+ readonly headers: Headers | undefined;
10
+ readonly error: Object | undefined;
11
+
12
+ constructor(
13
+ status: number | undefined,
14
+ error: Object | undefined,
15
+ message: string | undefined,
16
+ headers: Headers | undefined,
17
+ ) {
18
+ super(`${APIError.makeMessage(status, error, message)}`);
19
+ this.status = status;
20
+ this.headers = headers;
21
+ this.error = error;
22
+ }
23
+
24
+ private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
25
+ const msg =
26
+ error?.message ?
27
+ typeof error.message === 'string' ?
28
+ error.message
29
+ : JSON.stringify(error.message)
30
+ : error ? JSON.stringify(error)
31
+ : message;
32
+
33
+ if (status && msg) {
34
+ return `${status} ${msg}`;
35
+ }
36
+ if (status) {
37
+ return `${status} status code (no body)`;
38
+ }
39
+ if (msg) {
40
+ return msg;
41
+ }
42
+ return '(no status code or body)';
43
+ }
44
+
45
+ static generate(
46
+ status: number | undefined,
47
+ errorResponse: Object | undefined,
48
+ message: string | undefined,
49
+ headers: Headers | undefined,
50
+ ) {
51
+ if (!status) {
52
+ return new APIConnectionError({ cause: castToError(errorResponse) });
53
+ }
54
+
55
+ const error = errorResponse as Record<string, any>;
56
+
57
+ if (status === 400) {
58
+ return new BadRequestError(status, error, message, headers);
59
+ }
60
+
61
+ if (status === 401) {
62
+ return new AuthenticationError(status, error, message, headers);
63
+ }
64
+
65
+ if (status === 403) {
66
+ return new PermissionDeniedError(status, error, message, headers);
67
+ }
68
+
69
+ if (status === 404) {
70
+ return new NotFoundError(status, error, message, headers);
71
+ }
72
+
73
+ if (status === 409) {
74
+ return new ConflictError(status, error, message, headers);
75
+ }
76
+
77
+ if (status === 422) {
78
+ return new UnprocessableEntityError(status, error, message, headers);
79
+ }
80
+
81
+ if (status === 429) {
82
+ return new RateLimitError(status, error, message, headers);
83
+ }
84
+
85
+ if (status >= 500) {
86
+ return new InternalServerError(status, error, message, headers);
87
+ }
88
+
89
+ return new APIError(status, error, message, headers);
90
+ }
91
+ }
92
+
93
+ export class APIUserAbortError extends APIError {
94
+ override readonly status: undefined = undefined;
95
+
96
+ constructor({ message }: { message?: string } = {}) {
97
+ super(undefined, undefined, message || 'Request was aborted.', undefined);
98
+ }
99
+ }
100
+
101
+ export class APIConnectionError extends APIError {
102
+ override readonly status: undefined = undefined;
103
+
104
+ constructor({ message, cause }: { message?: string; cause?: Error | undefined }) {
105
+ super(undefined, undefined, message || 'Connection error.', undefined);
106
+ // in some environments the 'cause' property is already declared
107
+ // @ts-ignore
108
+ if (cause) this.cause = cause;
109
+ }
110
+ }
111
+
112
+ export class APIConnectionTimeoutError extends APIConnectionError {
113
+ constructor({ message }: { message?: string } = {}) {
114
+ super({ message: message ?? 'Request timed out.' });
115
+ }
116
+ }
117
+
118
+ export class BadRequestError extends APIError {
119
+ override readonly status: 400 = 400;
120
+ }
121
+
122
+ export class AuthenticationError extends APIError {
123
+ override readonly status: 401 = 401;
124
+ }
125
+
126
+ export class PermissionDeniedError extends APIError {
127
+ override readonly status: 403 = 403;
128
+ }
129
+
130
+ export class NotFoundError extends APIError {
131
+ override readonly status: 404 = 404;
132
+ }
133
+
134
+ export class ConflictError extends APIError {
135
+ override readonly status: 409 = 409;
136
+ }
137
+
138
+ export class UnprocessableEntityError extends APIError {
139
+ override readonly status: 422 = 422;
140
+ }
141
+
142
+ export class RateLimitError extends APIError {
143
+ override readonly status: 429 = 429;
144
+ }
145
+
146
+ export class InternalServerError extends APIError {}
package/src/index.ts ADDED
@@ -0,0 +1,303 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import * as Core from './core';
4
+ import * as Errors from './error';
5
+ import { type Agent } from './_shims/index';
6
+ import * as Uploads from './uploads';
7
+ import * as qs from 'qs';
8
+ import * as API from "./resources/index";
9
+
10
+ export interface ClientOptions {
11
+ /**
12
+ * Defaults to process.env['METRONOME_BEARER_TOKEN'].
13
+ */
14
+ bearerToken?: string | undefined;
15
+
16
+ /**
17
+ * Defaults to process.env['METRONOME_WEBHOOK_SECRET'].
18
+ */
19
+ webhookSecret?: string | null | undefined;
20
+
21
+ /**
22
+ * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
23
+ *
24
+ * Defaults to process.env['METRONOME_BASE_URL'].
25
+ */
26
+ baseURL?: string | null | undefined;
27
+
28
+ /**
29
+ * The maximum amount of time (in milliseconds) that the client should wait for a response
30
+ * from the server before timing out a single request.
31
+ *
32
+ * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
33
+ * much longer than this timeout before the promise succeeds or fails.
34
+ */
35
+ timeout?: number;
36
+
37
+ /**
38
+ * An HTTP agent used to manage HTTP(S) connections.
39
+ *
40
+ * If not provided, an agent will be constructed by default in the Node.js environment,
41
+ * otherwise no agent is used.
42
+ */
43
+ httpAgent?: Agent;
44
+
45
+ /**
46
+ * Specify a custom `fetch` function implementation.
47
+ *
48
+ * If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
49
+ * defined globally.
50
+ */
51
+ fetch?: Core.Fetch | undefined;
52
+
53
+ /**
54
+ * The maximum number of times that the client will retry a request in case of a
55
+ * temporary failure, like a network error or a 5XX error from the server.
56
+ *
57
+ * @default 2
58
+ */
59
+ maxRetries?: number;
60
+
61
+ /**
62
+ * Default headers to include with every request to the API.
63
+ *
64
+ * These can be removed in individual requests by explicitly setting the
65
+ * header to `undefined` or `null` in request options.
66
+ */
67
+ defaultHeaders?: Core.Headers;
68
+
69
+ /**
70
+ * Default query parameters to include with every request to the API.
71
+ *
72
+ * These can be removed in individual requests by explicitly setting the
73
+ * param to `undefined` in request options.
74
+ */
75
+ defaultQuery?: Core.DefaultQuery;
76
+ }
77
+
78
+ /** API Client for interfacing with the Metronome API. */
79
+ export class Metronome extends Core.APIClient {
80
+ bearerToken: string;
81
+ webhookSecret: string | null;
82
+
83
+ private _options: ClientOptions;
84
+
85
+ /**
86
+ * API Client for interfacing with the Metronome API.
87
+ *
88
+ * @param {string | undefined} [opts.bearerToken=process.env['METRONOME_BEARER_TOKEN'] ?? undefined]
89
+ * @param {string | null | undefined} [opts.webhookSecret=process.env['METRONOME_WEBHOOK_SECRET'] ?? null]
90
+ * @param {string} [opts.baseURL=process.env['METRONOME_BASE_URL'] ?? https://api.metronome.com/v1] - Override the default base URL for the API.
91
+ * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
92
+ * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
93
+ * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
94
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
95
+ * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
96
+ * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
97
+ */
98
+ constructor({
99
+ baseURL = Core.readEnv('METRONOME_BASE_URL'),
100
+ bearerToken = Core.readEnv('METRONOME_BEARER_TOKEN'),
101
+ webhookSecret = Core.readEnv('METRONOME_WEBHOOK_SECRET') ?? null,
102
+ ...opts
103
+ }: ClientOptions = {}) {
104
+ if (bearerToken === undefined) {
105
+ throw new Errors.MetronomeError(
106
+ "The METRONOME_BEARER_TOKEN environment variable is missing or empty; either provide it, or instantiate the Metronome client with an bearerToken option, like new Metronome({ bearerToken: 'My Bearer Token' }).",
107
+ );
108
+ }
109
+
110
+ const options: ClientOptions = {
111
+ bearerToken,
112
+ webhookSecret,
113
+ ...opts,
114
+ baseURL: baseURL || `https://api.metronome.com/v1`,
115
+ };
116
+
117
+ super({
118
+ baseURL: options.baseURL!,
119
+ timeout: options.timeout ?? 60000 /* 1 minute */,
120
+ httpAgent: options.httpAgent,
121
+ maxRetries: options.maxRetries,
122
+ fetch: options.fetch,
123
+ });
124
+ this._options = options;
125
+
126
+ this.bearerToken = bearerToken;
127
+ this.webhookSecret = webhookSecret;
128
+ }
129
+
130
+ alerts: API.Alerts = new API.Alerts(this);
131
+ plans: API.Plans = new API.Plans(this);
132
+ creditGrants: API.CreditGrants = new API.CreditGrants(this);
133
+ customers: API.Customers = new API.Customers(this);
134
+ dashboards: API.Dashboards = new API.Dashboards(this);
135
+ webhooks: API.Webhooks = new API.Webhooks(this);
136
+ usage: API.Usage = new API.Usage(this);
137
+ auditLogs: API.AuditLogs = new API.AuditLogs(this);
138
+ customFields: API.CustomFields = new API.CustomFields(this);
139
+ billableMetrics: API.BillableMetrics = new API.BillableMetrics(this);
140
+ services: API.Services = new API.Services(this);
141
+
142
+ protected override defaultQuery(): Core.DefaultQuery | undefined {
143
+ return this._options.defaultQuery;
144
+ }
145
+
146
+ protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers {
147
+ return {
148
+ ...super.defaultHeaders(opts),
149
+ ...this._options.defaultHeaders,
150
+ };
151
+ }
152
+
153
+ protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers {
154
+ return { Authorization: `Bearer ${this.bearerToken}` };
155
+ }
156
+
157
+ protected override stringifyQuery(query: Record<string, unknown>): string {
158
+ return qs.stringify(query, { arrayFormat: 'comma' });
159
+ }
160
+
161
+ static Metronome = this;
162
+
163
+ static MetronomeError = Errors.MetronomeError;
164
+ static APIError = Errors.APIError;
165
+ static APIConnectionError = Errors.APIConnectionError;
166
+ static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
167
+ static APIUserAbortError = Errors.APIUserAbortError;
168
+ static NotFoundError = Errors.NotFoundError;
169
+ static ConflictError = Errors.ConflictError;
170
+ static RateLimitError = Errors.RateLimitError;
171
+ static BadRequestError = Errors.BadRequestError;
172
+ static AuthenticationError = Errors.AuthenticationError;
173
+ static InternalServerError = Errors.InternalServerError;
174
+ static PermissionDeniedError = Errors.PermissionDeniedError;
175
+ static UnprocessableEntityError = Errors.UnprocessableEntityError;
176
+
177
+ static toFile = Uploads.toFile;
178
+ static fileFromPath = Uploads.fileFromPath;
179
+ }
180
+
181
+ export const {
182
+ MetronomeError,
183
+ APIError,
184
+ APIConnectionError,
185
+ APIConnectionTimeoutError,
186
+ APIUserAbortError,
187
+ NotFoundError,
188
+ ConflictError,
189
+ RateLimitError,
190
+ BadRequestError,
191
+ AuthenticationError,
192
+ InternalServerError,
193
+ PermissionDeniedError,
194
+ UnprocessableEntityError,
195
+ } = Errors;
196
+
197
+ export import toFile = Uploads.toFile;
198
+ export import fileFromPath = Uploads.fileFromPath;
199
+
200
+ export namespace Metronome {
201
+ export import RequestOptions = Core.RequestOptions;
202
+
203
+ export import Alerts = API.Alerts;
204
+ export import AlertCreateResponse = API.AlertCreateResponse;
205
+ export import AlertArchiveResponse = API.AlertArchiveResponse;
206
+ export import AlertCreateParams = API.AlertCreateParams;
207
+ export import AlertArchiveParams = API.AlertArchiveParams;
208
+
209
+ export import Plans = API.Plans;
210
+ export import PlanDetail = API.PlanDetail;
211
+ export import PlanListResponse = API.PlanListResponse;
212
+ export import PlanGetDetailsResponse = API.PlanGetDetailsResponse;
213
+ export import PlanListChargesResponse = API.PlanListChargesResponse;
214
+ export import PlanListCustomersResponse = API.PlanListCustomersResponse;
215
+ export import PlanListParams = API.PlanListParams;
216
+ export import PlanListChargesParams = API.PlanListChargesParams;
217
+ export import PlanListCustomersParams = API.PlanListCustomersParams;
218
+
219
+ export import CreditGrants = API.CreditGrants;
220
+ export import CreditLedgerEntry = API.CreditLedgerEntry;
221
+ export import RolloverAmountMaxAmount = API.RolloverAmountMaxAmount;
222
+ export import RolloverAmountMaxPercentage = API.RolloverAmountMaxPercentage;
223
+ export import CreditGrantCreateResponse = API.CreditGrantCreateResponse;
224
+ export import CreditGrantListResponse = API.CreditGrantListResponse;
225
+ export import CreditGrantEditResponse = API.CreditGrantEditResponse;
226
+ export import CreditGrantListCreditTypesResponse = API.CreditGrantListCreditTypesResponse;
227
+ export import CreditGrantListEntriesResponse = API.CreditGrantListEntriesResponse;
228
+ export import CreditGrantVoidResponse = API.CreditGrantVoidResponse;
229
+ export import CreditGrantCreateParams = API.CreditGrantCreateParams;
230
+ export import CreditGrantListParams = API.CreditGrantListParams;
231
+ export import CreditGrantEditParams = API.CreditGrantEditParams;
232
+ export import CreditGrantListCreditTypesParams = API.CreditGrantListCreditTypesParams;
233
+ export import CreditGrantListEntriesParams = API.CreditGrantListEntriesParams;
234
+ export import CreditGrantVoidParams = API.CreditGrantVoidParams;
235
+
236
+ export import Customers = API.Customers;
237
+ export import Customer = API.Customer;
238
+ export import CustomerDetail = API.CustomerDetail;
239
+ export import CustomerCreateResponse = API.CustomerCreateResponse;
240
+ export import CustomerRetrieveResponse = API.CustomerRetrieveResponse;
241
+ export import CustomerListResponse = API.CustomerListResponse;
242
+ export import CustomerArchiveResponse = API.CustomerArchiveResponse;
243
+ export import CustomerListBillableMetricsResponse = API.CustomerListBillableMetricsResponse;
244
+ export import CustomerListCostsResponse = API.CustomerListCostsResponse;
245
+ export import CustomerSetNameResponse = API.CustomerSetNameResponse;
246
+ export import CustomerCreateParams = API.CustomerCreateParams;
247
+ export import CustomerListParams = API.CustomerListParams;
248
+ export import CustomerArchiveParams = API.CustomerArchiveParams;
249
+ export import CustomerListBillableMetricsParams = API.CustomerListBillableMetricsParams;
250
+ export import CustomerListCostsParams = API.CustomerListCostsParams;
251
+ export import CustomerSetIngestAliasesParams = API.CustomerSetIngestAliasesParams;
252
+ export import CustomerSetNameParams = API.CustomerSetNameParams;
253
+ export import CustomerUpdateConfigParams = API.CustomerUpdateConfigParams;
254
+
255
+ export import Dashboards = API.Dashboards;
256
+ export import DashboardGetEmbeddableURLResponse = API.DashboardGetEmbeddableURLResponse;
257
+ export import DashboardGetEmbeddableURLParams = API.DashboardGetEmbeddableURLParams;
258
+
259
+ export import Webhooks = API.Webhooks;
260
+
261
+ export import Usage = API.Usage;
262
+ export import UsageListResponse = API.UsageListResponse;
263
+ export import UsageListWithGroupsResponse = API.UsageListWithGroupsResponse;
264
+ export import UsageListParams = API.UsageListParams;
265
+ export import UsageIngestParams = API.UsageIngestParams;
266
+ export import UsageListWithGroupsParams = API.UsageListWithGroupsParams;
267
+
268
+ export import AuditLogs = API.AuditLogs;
269
+ export import AuditLogListResponse = API.AuditLogListResponse;
270
+ export import AuditLogListParams = API.AuditLogListParams;
271
+
272
+ export import CustomFields = API.CustomFields;
273
+ export import CustomFieldListKeysResponse = API.CustomFieldListKeysResponse;
274
+ export import CustomFieldAddKeyParams = API.CustomFieldAddKeyParams;
275
+ export import CustomFieldDeleteValuesParams = API.CustomFieldDeleteValuesParams;
276
+ export import CustomFieldListKeysParams = API.CustomFieldListKeysParams;
277
+ export import CustomFieldRemoveKeyParams = API.CustomFieldRemoveKeyParams;
278
+ export import CustomFieldSetValuesParams = API.CustomFieldSetValuesParams;
279
+
280
+ export import BillableMetrics = API.BillableMetrics;
281
+ export import BillableMetricCreateResponse = API.BillableMetricCreateResponse;
282
+ export import BillableMetricRetrieveResponse = API.BillableMetricRetrieveResponse;
283
+ export import BillableMetricListResponse = API.BillableMetricListResponse;
284
+ export import BillableMetricArchiveResponse = API.BillableMetricArchiveResponse;
285
+ export import BillableMetricCreateParams = API.BillableMetricCreateParams;
286
+ export import BillableMetricListParams = API.BillableMetricListParams;
287
+ export import BillableMetricArchiveParams = API.BillableMetricArchiveParams;
288
+
289
+ export import Services = API.Services;
290
+ export import ServiceListResponse = API.ServiceListResponse;
291
+
292
+ export import Commit = API.Commit;
293
+ export import ContractWithoutAmendments = API.ContractWithoutAmendments;
294
+ export import CreditType = API.CreditType;
295
+ export import Discount = API.Discount;
296
+ export import ID = API.ID;
297
+ export import Override = API.Override;
298
+ export import Rate = API.Rate;
299
+ export import SchedulePointInTime = API.SchedulePointInTime;
300
+ export import ScheduledCharge = API.ScheduledCharge;
301
+ }
302
+
303
+ export default Metronome;
package/src/lib/.keep ADDED
@@ -0,0 +1,4 @@
1
+ File generated from our OpenAPI spec by Stainless.
2
+
3
+ This directory can be used to store custom files to expand the SDK.
4
+ It is ignored by Stainless code generation and its content (other than this keep file) won't be touched.
@@ -0,0 +1,11 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import type { Metronome } from './index';
4
+
5
+ export class APIResource {
6
+ protected _client: Metronome;
7
+
8
+ constructor(client: Metronome) {
9
+ this._client = client;
10
+ }
11
+ }
@@ -0,0 +1,144 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import * as Core from "../core";
4
+ import { APIResource } from "../resource";
5
+ import * as AlertsAPI from "./alerts";
6
+ import * as Shared from "./shared";
7
+
8
+ export class Alerts extends APIResource {
9
+ /**
10
+ * Create a new alert
11
+ */
12
+ create(body: AlertCreateParams, options?: Core.RequestOptions): Core.APIPromise<AlertCreateResponse> {
13
+ return this._client.post('/alerts/create', { body, ...options });
14
+ }
15
+
16
+ /**
17
+ * Archive an existing alert
18
+ */
19
+ archive(body: AlertArchiveParams, options?: Core.RequestOptions): Core.APIPromise<AlertArchiveResponse> {
20
+ return this._client.post('/alerts/archive', { body, ...options });
21
+ }
22
+ }
23
+
24
+ export interface AlertCreateResponse {
25
+ data: Shared.ID;
26
+ }
27
+
28
+ export interface AlertArchiveResponse {
29
+ data: Shared.ID;
30
+ }
31
+
32
+ export interface AlertCreateParams {
33
+ /**
34
+ * Type of the alert
35
+ */
36
+ alert_type:
37
+ | 'low_credit_balance_reached'
38
+ | 'spend_threshold_reached'
39
+ | 'monthly_invoice_total_spend_threshold_reached'
40
+ | 'low_remaining_days_in_plan_reached'
41
+ | 'low_remaining_credit_percentage_reached'
42
+ | 'usage_threshold_reached'
43
+ | 'low_remaining_days_for_commit_segment_reached'
44
+ | 'low_remaining_commit_balance_reached'
45
+ | 'low_remaining_commit_percentage_reached'
46
+ | 'low_remaining_days_for_contract_credit_segment_reached'
47
+ | 'low_remaining_contract_credit_balance_reached'
48
+ | 'low_remaining_contract_credit_percentage_reached'
49
+ | 'invoice_total_reached';
50
+
51
+ /**
52
+ * Name of the alert
53
+ */
54
+ name: string;
55
+
56
+ /**
57
+ * Threshold value of the alert policy
58
+ */
59
+ threshold: number;
60
+
61
+ /**
62
+ * For alerts of type `usage_threshold_reached`, specifies which billable metric to
63
+ * track the usage for.
64
+ */
65
+ billable_metric_id?: string;
66
+
67
+ credit_type_id?: string;
68
+
69
+ /**
70
+ * Only present for beta contract invoices. This field's availability is dependent
71
+ * on your client's configuration. A list of custom field filters for alert types
72
+ * that support advanced filtering
73
+ */
74
+ custom_field_filters?: Array<AlertCreateParams.CustomFieldFilter>;
75
+
76
+ /**
77
+ * If provided, will create this alert for this specific customer. To create an
78
+ * alert for all customers, do not specify `customer_id` or `plan_id`.
79
+ */
80
+ customer_id?: string;
81
+
82
+ /**
83
+ * If true, the alert will evaluate immediately on customers that already meet the
84
+ * alert threshold. If false, it will only evaluate on future customers that
85
+ * trigger the alert threshold. Defaults to true.
86
+ */
87
+ evaluate_on_create?: boolean;
88
+
89
+ /**
90
+ * Scopes alert evaluation to a specific presentation group key on individual line
91
+ * items. Only present for spend alerts.
92
+ */
93
+ group_key_filter?: AlertCreateParams.GroupKeyFilter;
94
+
95
+ /**
96
+ * Only supported for invoice_total_reached alerts. A list of invoice types to
97
+ * evaluate.
98
+ */
99
+ invoice_types_filter?: Array<string>;
100
+
101
+ /**
102
+ * If provided, will create this alert for this specific plan. To create an alert
103
+ * for all customers, do not specify `customer_id` or `plan_id`.
104
+ */
105
+ plan_id?: string;
106
+
107
+ /**
108
+ * Prevents the creation of duplicates. If a request to create a record is made
109
+ * with a previously used uniqueness key, a new record will not be created and the
110
+ * request will fail with a 409 error.
111
+ */
112
+ uniqueness_key?: string;
113
+ }
114
+
115
+ export namespace AlertCreateParams {
116
+ export interface CustomFieldFilter {
117
+ entity: 'Contract' | 'Commit' | 'ContractCredit';
118
+
119
+ key: string;
120
+
121
+ value: string;
122
+ }
123
+
124
+ /**
125
+ * Scopes alert evaluation to a specific presentation group key on individual line
126
+ * items. Only present for spend alerts.
127
+ */
128
+ export interface GroupKeyFilter {
129
+ key: string;
130
+
131
+ value: string;
132
+ }
133
+ }
134
+
135
+ export interface AlertArchiveParams {
136
+ id: string;
137
+ }
138
+
139
+ export namespace Alerts {
140
+ export import AlertCreateResponse = AlertsAPI.AlertCreateResponse;
141
+ export import AlertArchiveResponse = AlertsAPI.AlertArchiveResponse;
142
+ export import AlertCreateParams = AlertsAPI.AlertCreateParams;
143
+ export import AlertArchiveParams = AlertsAPI.AlertArchiveParams;
144
+ }