@stigg/typescript 0.1.0-beta.40 → 0.1.0-beta.42

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 (99) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/package.json +1 -1
  3. package/resources/v1/credits/consumption.d.mts +4 -1
  4. package/resources/v1/credits/consumption.d.mts.map +1 -1
  5. package/resources/v1/credits/consumption.d.ts +4 -1
  6. package/resources/v1/credits/consumption.d.ts.map +1 -1
  7. package/resources/v1/customers/customers.d.mts +9 -2
  8. package/resources/v1/customers/customers.d.mts.map +1 -1
  9. package/resources/v1/customers/customers.d.ts +9 -2
  10. package/resources/v1/customers/customers.d.ts.map +1 -1
  11. package/resources/v1/customers/customers.js +9 -2
  12. package/resources/v1/customers/customers.js.map +1 -1
  13. package/resources/v1/customers/customers.mjs +9 -2
  14. package/resources/v1/customers/customers.mjs.map +1 -1
  15. package/resources/v1/customers/events.d.mts +4 -0
  16. package/resources/v1/customers/events.d.mts.map +1 -0
  17. package/resources/v1/customers/events.d.ts +4 -0
  18. package/resources/v1/customers/events.d.ts.map +1 -0
  19. package/resources/v1/customers/events.js +9 -0
  20. package/resources/v1/customers/events.js.map +1 -0
  21. package/resources/v1/customers/events.mjs +5 -0
  22. package/resources/v1/customers/events.mjs.map +1 -0
  23. package/resources/v1/customers/index.d.mts +2 -0
  24. package/resources/v1/customers/index.d.mts.map +1 -1
  25. package/resources/v1/customers/index.d.ts +2 -0
  26. package/resources/v1/customers/index.d.ts.map +1 -1
  27. package/resources/v1/customers/index.js +5 -1
  28. package/resources/v1/customers/index.js.map +1 -1
  29. package/resources/v1/customers/index.mjs +2 -0
  30. package/resources/v1/customers/index.mjs.map +1 -1
  31. package/resources/v1/customers/usage.d.mts +4 -0
  32. package/resources/v1/customers/usage.d.mts.map +1 -0
  33. package/resources/v1/customers/usage.d.ts +4 -0
  34. package/resources/v1/customers/usage.d.ts.map +1 -0
  35. package/resources/v1/customers/usage.js +9 -0
  36. package/resources/v1/customers/usage.js.map +1 -0
  37. package/resources/v1/customers/usage.mjs +5 -0
  38. package/resources/v1/customers/usage.mjs.map +1 -0
  39. package/resources/v1/events/data-export/destinations.d.mts +3 -1
  40. package/resources/v1/events/data-export/destinations.d.mts.map +1 -1
  41. package/resources/v1/events/data-export/destinations.d.ts +3 -1
  42. package/resources/v1/events/data-export/destinations.d.ts.map +1 -1
  43. package/resources/v1/events/data-export/destinations.js +3 -1
  44. package/resources/v1/events/data-export/destinations.js.map +1 -1
  45. package/resources/v1/events/data-export/destinations.mjs +3 -1
  46. package/resources/v1/events/data-export/destinations.mjs.map +1 -1
  47. package/resources/v1/events/events.d.mts +106 -1
  48. package/resources/v1/events/events.d.mts.map +1 -1
  49. package/resources/v1/events/events.d.ts +106 -1
  50. package/resources/v1/events/events.d.ts.map +1 -1
  51. package/resources/v1/events/events.js +19 -0
  52. package/resources/v1/events/events.js.map +1 -1
  53. package/resources/v1/events/events.mjs +19 -0
  54. package/resources/v1/events/events.mjs.map +1 -1
  55. package/resources/v1/events/index.d.mts +1 -1
  56. package/resources/v1/events/index.d.mts.map +1 -1
  57. package/resources/v1/events/index.d.ts +1 -1
  58. package/resources/v1/events/index.d.ts.map +1 -1
  59. package/resources/v1/events/index.js.map +1 -1
  60. package/resources/v1/events/index.mjs +1 -1
  61. package/resources/v1/events/index.mjs.map +1 -1
  62. package/resources/v1/index.d.mts +2 -2
  63. package/resources/v1/index.d.mts.map +1 -1
  64. package/resources/v1/index.d.ts +2 -2
  65. package/resources/v1/index.d.ts.map +1 -1
  66. package/resources/v1/index.js.map +1 -1
  67. package/resources/v1/index.mjs +1 -1
  68. package/resources/v1/index.mjs.map +1 -1
  69. package/resources/v1/usage.d.mts +125 -2
  70. package/resources/v1/usage.d.mts.map +1 -1
  71. package/resources/v1/usage.d.ts +125 -2
  72. package/resources/v1/usage.d.ts.map +1 -1
  73. package/resources/v1/usage.js +19 -0
  74. package/resources/v1/usage.js.map +1 -1
  75. package/resources/v1/usage.mjs +19 -0
  76. package/resources/v1/usage.mjs.map +1 -1
  77. package/resources/v1/v1.d.mts +4 -4
  78. package/resources/v1/v1.d.mts.map +1 -1
  79. package/resources/v1/v1.d.ts +4 -4
  80. package/resources/v1/v1.d.ts.map +1 -1
  81. package/resources/v1/v1.js.map +1 -1
  82. package/resources/v1/v1.mjs +1 -1
  83. package/resources/v1/v1.mjs.map +1 -1
  84. package/src/resources/v1/credits/consumption.ts +4 -1
  85. package/src/resources/v1/customers/customers.ts +13 -2
  86. package/src/resources/v1/customers/events.ts +5 -0
  87. package/src/resources/v1/customers/index.ts +2 -0
  88. package/src/resources/v1/customers/usage.ts +5 -0
  89. package/src/resources/v1/events/data-export/destinations.ts +3 -1
  90. package/src/resources/v1/events/events.ts +144 -1
  91. package/src/resources/v1/events/index.ts +7 -1
  92. package/src/resources/v1/index.ts +9 -1
  93. package/src/resources/v1/usage.ts +162 -1
  94. package/src/resources/v1/v1.ts +13 -1
  95. package/src/version.ts +1 -1
  96. package/version.d.mts +1 -1
  97. package/version.d.ts +1 -1
  98. package/version.js +1 -1
  99. package/version.mjs +1 -1
@@ -24,6 +24,29 @@ export class Events extends APIResource {
24
24
  dataExport: DataExportAPI.DataExport = new DataExportAPI.DataExport(this._client);
25
25
  beta: BetaAPI.Beta = new BetaAPI.Beta(this._client);
26
26
 
27
+ /**
28
+ * Estimates the credit cost of a usage event without ingesting it. Returns the
29
+ * estimated cost per credit currency, the current balance, and the balance after
30
+ * the estimated consumption.
31
+ */
32
+ estimateCost(
33
+ params: EventEstimateCostParams,
34
+ options?: RequestOptions,
35
+ ): APIPromise<EventEstimateCostResponse> {
36
+ const { 'X-ACCOUNT-ID': xAccountID, 'X-ENVIRONMENT-ID': xEnvironmentID, ...body } = params;
37
+ return this._client.post('/api/v1/events/estimate', {
38
+ body,
39
+ ...options,
40
+ headers: buildHeaders([
41
+ {
42
+ ...(xAccountID != null ? { 'X-ACCOUNT-ID': xAccountID } : undefined),
43
+ ...(xEnvironmentID != null ? { 'X-ENVIRONMENT-ID': xEnvironmentID } : undefined),
44
+ },
45
+ options?.headers,
46
+ ]),
47
+ });
48
+ }
49
+
27
50
  /**
28
51
  * Reports raw usage events for event-based metering. Events are ingested
29
52
  * asynchronously and aggregated into usage totals.
@@ -44,6 +67,86 @@ export class Events extends APIResource {
44
67
  }
45
68
  }
46
69
 
70
+ /**
71
+ * Response object
72
+ */
73
+ export interface EventEstimateCostResponse {
74
+ /**
75
+ * Estimated credit cost, current balance and balance after
76
+ */
77
+ data: EventEstimateCostResponse.Data;
78
+ }
79
+
80
+ export namespace EventEstimateCostResponse {
81
+ /**
82
+ * Estimated credit cost, current balance and balance after
83
+ */
84
+ export interface Data {
85
+ /**
86
+ * Per-currency cost estimates
87
+ */
88
+ estimates: Array<Data.Estimate>;
89
+
90
+ /**
91
+ * Request-level warnings about the estimation context
92
+ */
93
+ warnings: Array<'RESOURCE_SCOPED_SUBSCRIPTION_EXISTS' | 'FEATURE_NOT_FOUND' | 'FEATURE_NOT_CREDIT_BASED'>;
94
+ }
95
+
96
+ export namespace Data {
97
+ export interface Estimate {
98
+ /**
99
+ * The credit balance after subtracting the estimated cost
100
+ */
101
+ balanceAfterEstimate: number;
102
+
103
+ /**
104
+ * Estimated cost contribution per feature
105
+ */
106
+ breakdown: Array<Estimate.Breakdown>;
107
+
108
+ /**
109
+ * The credit currency identifier
110
+ */
111
+ currencyId: string;
112
+
113
+ /**
114
+ * The current credit balance, including not-yet-reconciled consumption
115
+ */
116
+ currentBalance: number;
117
+
118
+ /**
119
+ * The estimated credit cost of the reported event or usage
120
+ */
121
+ estimatedCost: number;
122
+
123
+ /**
124
+ * Whether the estimated consumption would bring the balance below zero
125
+ */
126
+ wouldOverdraft: boolean;
127
+ }
128
+
129
+ export namespace Estimate {
130
+ export interface Breakdown {
131
+ /**
132
+ * The estimated credit cost contributed by this feature
133
+ */
134
+ cost: number;
135
+
136
+ /**
137
+ * The feature whose meter contributed this cost
138
+ */
139
+ featureId: string;
140
+
141
+ /**
142
+ * Warning explaining why this cost may be inaccurate, if any
143
+ */
144
+ warningCode: 'UNSUPPORTED_AGGREGATION' | null;
145
+ }
146
+ }
147
+ }
148
+ }
149
+
47
150
  /**
48
151
  * Response object
49
152
  */
@@ -55,6 +158,41 @@ export interface EventReportResponse {
55
158
  data: unknown;
56
159
  }
57
160
 
161
+ export interface EventEstimateCostParams {
162
+ /**
163
+ * Body param: Customer id
164
+ */
165
+ customerId: string;
166
+
167
+ /**
168
+ * Body param: The name of the usage event
169
+ */
170
+ eventName: string;
171
+
172
+ /**
173
+ * Body param: Dimensions associated with the usage event
174
+ */
175
+ dimensions?: { [key: string]: string | number | boolean };
176
+
177
+ /**
178
+ * Body param: Resource id
179
+ */
180
+ resourceId?: string | null;
181
+
182
+ /**
183
+ * Header param: Account ID — optional when authenticating with a user JWT (Bearer
184
+ * token); falls back to the user's first membership. Ignored for API-key auth.
185
+ */
186
+ 'X-ACCOUNT-ID'?: string;
187
+
188
+ /**
189
+ * Header param: Environment ID — required when authenticating with a user JWT
190
+ * (Bearer token) on environment-scoped endpoints. Ignored for API-key auth (env is
191
+ * intrinsic to the key).
192
+ */
193
+ 'X-ENVIRONMENT-ID'?: string;
194
+ }
195
+
58
196
  export interface EventReportParams {
59
197
  /**
60
198
  * Body param: A list of usage events to report
@@ -116,7 +254,12 @@ Events.DataExport = DataExport;
116
254
  Events.Beta = Beta;
117
255
 
118
256
  export declare namespace Events {
119
- export { type EventReportResponse as EventReportResponse, type EventReportParams as EventReportParams };
257
+ export {
258
+ type EventEstimateCostResponse as EventEstimateCostResponse,
259
+ type EventReportResponse as EventReportResponse,
260
+ type EventEstimateCostParams as EventEstimateCostParams,
261
+ type EventReportParams as EventReportParams,
262
+ };
120
263
 
121
264
  export {
122
265
  DataExport as DataExport,
@@ -10,4 +10,10 @@ export {
10
10
  type DataExportMintScopedTokenParams,
11
11
  type DataExportTriggerSyncParams,
12
12
  } from './data-export/index';
13
- export { Events, type EventReportResponse, type EventReportParams } from './events';
13
+ export {
14
+ Events,
15
+ type EventEstimateCostResponse,
16
+ type EventReportResponse,
17
+ type EventEstimateCostParams,
18
+ type EventReportParams,
19
+ } from './events';
@@ -62,7 +62,13 @@ export {
62
62
  type CustomerListResponsesMyCursorIDPage,
63
63
  type CustomerListResourcesResponsesMyCursorIDPage,
64
64
  } from './customers/index';
65
- export { Events, type EventReportResponse, type EventReportParams } from './events/index';
65
+ export {
66
+ Events,
67
+ type EventEstimateCostResponse,
68
+ type EventReportResponse,
69
+ type EventEstimateCostParams,
70
+ type EventReportParams,
71
+ } from './events/index';
66
72
  export {
67
73
  Features,
68
74
  type Feature,
@@ -130,8 +136,10 @@ export {
130
136
  } from './subscriptions/index';
131
137
  export {
132
138
  Usage,
139
+ type UsageEstimateCostResponse,
133
140
  type UsageHistoryResponse,
134
141
  type UsageReportResponse,
142
+ type UsageEstimateCostParams,
135
143
  type UsageHistoryParams,
136
144
  type UsageReportParams,
137
145
  } from './usage';
@@ -10,6 +10,29 @@ import { path } from '../../internal/utils/path';
10
10
  * Operations related to usage & metering
11
11
  */
12
12
  export class Usage extends APIResource {
13
+ /**
14
+ * Estimates the credit cost of a usage report without recording it. Returns the
15
+ * estimated cost per credit currency, the current balance, and the balance after
16
+ * the estimated consumption.
17
+ */
18
+ estimateCost(
19
+ params: UsageEstimateCostParams,
20
+ options?: RequestOptions,
21
+ ): APIPromise<UsageEstimateCostResponse> {
22
+ const { 'X-ACCOUNT-ID': xAccountID, 'X-ENVIRONMENT-ID': xEnvironmentID, ...body } = params;
23
+ return this._client.post('/api/v1/usage/estimate', {
24
+ body,
25
+ ...options,
26
+ headers: buildHeaders([
27
+ {
28
+ ...(xAccountID != null ? { 'X-ACCOUNT-ID': xAccountID } : undefined),
29
+ ...(xEnvironmentID != null ? { 'X-ENVIRONMENT-ID': xEnvironmentID } : undefined),
30
+ },
31
+ options?.headers,
32
+ ]),
33
+ });
34
+ }
35
+
13
36
  /**
14
37
  * Retrieves historical usage data for a customer's metered feature over time.
15
38
  */
@@ -52,6 +75,86 @@ export class Usage extends APIResource {
52
75
  }
53
76
  }
54
77
 
78
+ /**
79
+ * Response object
80
+ */
81
+ export interface UsageEstimateCostResponse {
82
+ /**
83
+ * Estimated credit cost, current balance and balance after
84
+ */
85
+ data: UsageEstimateCostResponse.Data;
86
+ }
87
+
88
+ export namespace UsageEstimateCostResponse {
89
+ /**
90
+ * Estimated credit cost, current balance and balance after
91
+ */
92
+ export interface Data {
93
+ /**
94
+ * Per-currency cost estimates
95
+ */
96
+ estimates: Array<Data.Estimate>;
97
+
98
+ /**
99
+ * Request-level warnings about the estimation context
100
+ */
101
+ warnings: Array<'RESOURCE_SCOPED_SUBSCRIPTION_EXISTS' | 'FEATURE_NOT_FOUND' | 'FEATURE_NOT_CREDIT_BASED'>;
102
+ }
103
+
104
+ export namespace Data {
105
+ export interface Estimate {
106
+ /**
107
+ * The credit balance after subtracting the estimated cost
108
+ */
109
+ balanceAfterEstimate: number;
110
+
111
+ /**
112
+ * Estimated cost contribution per feature
113
+ */
114
+ breakdown: Array<Estimate.Breakdown>;
115
+
116
+ /**
117
+ * The credit currency identifier
118
+ */
119
+ currencyId: string;
120
+
121
+ /**
122
+ * The current credit balance, including not-yet-reconciled consumption
123
+ */
124
+ currentBalance: number;
125
+
126
+ /**
127
+ * The estimated credit cost of the reported event or usage
128
+ */
129
+ estimatedCost: number;
130
+
131
+ /**
132
+ * Whether the estimated consumption would bring the balance below zero
133
+ */
134
+ wouldOverdraft: boolean;
135
+ }
136
+
137
+ export namespace Estimate {
138
+ export interface Breakdown {
139
+ /**
140
+ * The estimated credit cost contributed by this feature
141
+ */
142
+ cost: number;
143
+
144
+ /**
145
+ * The feature whose meter contributed this cost
146
+ */
147
+ featureId: string;
148
+
149
+ /**
150
+ * Warning explaining why this cost may be inaccurate, if any
151
+ */
152
+ warningCode: 'UNSUPPORTED_AGGREGATION' | null;
153
+ }
154
+ }
155
+ }
156
+ }
157
+
55
158
  /**
56
159
  * Response object
57
160
  */
@@ -232,13 +335,24 @@ export namespace UsageReportResponse {
232
335
  * Optimistic credit balance for a credit-backed feature
233
336
  */
234
337
  export interface Credit {
338
+ /**
339
+ * The credits this single reportUsage call deducted, in credit units — scoped to
340
+ * this one measurement (0 for idempotency duplicates). Contrast `currentUsage`,
341
+ * which is the wallet-wide running total shared across all features on this
342
+ * currency. Use it to reconcile expected per-call deductions.
343
+ */
344
+ consumed: number;
345
+
235
346
  /**
236
347
  * The credit currency identifier
237
348
  */
238
349
  currencyId: string;
239
350
 
240
351
  /**
241
- * The credits consumed (optimistic — includes not-yet-reconciled usage)
352
+ * The wallet's total consumed credits for this currency (optimistic — includes
353
+ * not-yet-reconciled usage), shared across every feature that draws on the
354
+ * currency. This is the running balance, not this call's deduction — see
355
+ * `consumed` for that.
242
356
  */
243
357
  currentUsage: number;
244
358
 
@@ -262,6 +376,51 @@ export namespace UsageReportResponse {
262
376
  }
263
377
  }
264
378
 
379
+ export interface UsageEstimateCostParams {
380
+ /**
381
+ * Body param: Customer id
382
+ */
383
+ customerId: string;
384
+
385
+ /**
386
+ * Body param: Feature id
387
+ */
388
+ featureId: string;
389
+
390
+ /**
391
+ * Body param: The value to report for usage
392
+ */
393
+ value: number;
394
+
395
+ /**
396
+ * Body param: Additional dimensions for the usage report
397
+ */
398
+ dimensions?: { [key: string]: string | number | boolean };
399
+
400
+ /**
401
+ * Body param: Resource id
402
+ */
403
+ resourceId?: string | null;
404
+
405
+ /**
406
+ * Body param: The method by which the usage value should be updated
407
+ */
408
+ updateBehavior?: 'DELTA' | 'SET';
409
+
410
+ /**
411
+ * Header param: Account ID — optional when authenticating with a user JWT (Bearer
412
+ * token); falls back to the user's first membership. Ignored for API-key auth.
413
+ */
414
+ 'X-ACCOUNT-ID'?: string;
415
+
416
+ /**
417
+ * Header param: Environment ID — required when authenticating with a user JWT
418
+ * (Bearer token) on environment-scoped endpoints. Ignored for API-key auth (env is
419
+ * intrinsic to the key).
420
+ */
421
+ 'X-ENVIRONMENT-ID'?: string;
422
+ }
423
+
265
424
  export interface UsageHistoryParams {
266
425
  /**
267
426
  * Path param: Customer id
@@ -371,8 +530,10 @@ export namespace UsageReportParams {
371
530
 
372
531
  export declare namespace Usage {
373
532
  export {
533
+ type UsageEstimateCostResponse as UsageEstimateCostResponse,
374
534
  type UsageHistoryResponse as UsageHistoryResponse,
375
535
  type UsageReportResponse as UsageReportResponse,
536
+ type UsageEstimateCostParams as UsageEstimateCostParams,
376
537
  type UsageHistoryParams as UsageHistoryParams,
377
538
  type UsageReportParams as UsageReportParams,
378
539
  };
@@ -42,6 +42,8 @@ import {
42
42
  import * as UsageAPI from './usage';
43
43
  import {
44
44
  Usage,
45
+ UsageEstimateCostParams,
46
+ UsageEstimateCostResponse,
45
47
  UsageHistoryParams,
46
48
  UsageHistoryResponse,
47
49
  UsageReportParams,
@@ -102,7 +104,13 @@ import {
102
104
  Customers,
103
105
  } from './customers/customers';
104
106
  import * as EventsAPI from './events/events';
105
- import { EventReportParams, EventReportResponse, Events } from './events/events';
107
+ import {
108
+ EventEstimateCostParams,
109
+ EventEstimateCostResponse,
110
+ EventReportParams,
111
+ EventReportResponse,
112
+ Events,
113
+ } from './events/events';
106
114
  import * as PlansAPI from './plans/plans';
107
115
  import {
108
116
  Plan,
@@ -229,7 +237,9 @@ export declare namespace V1 {
229
237
 
230
238
  export {
231
239
  Events as Events,
240
+ type EventEstimateCostResponse as EventEstimateCostResponse,
232
241
  type EventReportResponse as EventReportResponse,
242
+ type EventEstimateCostParams as EventEstimateCostParams,
233
243
  type EventReportParams as EventReportParams,
234
244
  };
235
245
 
@@ -302,8 +312,10 @@ export declare namespace V1 {
302
312
 
303
313
  export {
304
314
  Usage as Usage,
315
+ type UsageEstimateCostResponse as UsageEstimateCostResponse,
305
316
  type UsageHistoryResponse as UsageHistoryResponse,
306
317
  type UsageReportResponse as UsageReportResponse,
318
+ type UsageEstimateCostParams as UsageEstimateCostParams,
307
319
  type UsageHistoryParams as UsageHistoryParams,
308
320
  type UsageReportParams as UsageReportParams,
309
321
  };
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.1.0-beta.40'; // x-release-please-version
1
+ export const VERSION = '0.1.0-beta.42'; // x-release-please-version
package/version.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.1.0-beta.40";
1
+ export declare const VERSION = "0.1.0-beta.42";
2
2
  //# sourceMappingURL=version.d.mts.map
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.1.0-beta.40";
1
+ export declare const VERSION = "0.1.0-beta.42";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '0.1.0-beta.40'; // x-release-please-version
4
+ exports.VERSION = '0.1.0-beta.42'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.1.0-beta.40'; // x-release-please-version
1
+ export const VERSION = '0.1.0-beta.42'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map