@stigg/typescript 0.1.0-beta.57 → 0.1.0-beta.58

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 (82) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/client.d.mts +3 -0
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +3 -0
  5. package/client.d.ts.map +1 -1
  6. package/client.js +3 -0
  7. package/client.js.map +1 -1
  8. package/client.mjs +3 -0
  9. package/client.mjs.map +1 -1
  10. package/package.json +1 -1
  11. package/resources/index.d.mts +1 -0
  12. package/resources/index.d.mts.map +1 -1
  13. package/resources/index.d.ts +1 -0
  14. package/resources/index.d.ts.map +1 -1
  15. package/resources/index.js +3 -1
  16. package/resources/index.js.map +1 -1
  17. package/resources/index.mjs +1 -0
  18. package/resources/index.mjs.map +1 -1
  19. package/resources/v1/credits/consumption.d.mts +50 -0
  20. package/resources/v1/credits/consumption.d.mts.map +1 -1
  21. package/resources/v1/credits/consumption.d.ts +50 -0
  22. package/resources/v1/credits/consumption.d.ts.map +1 -1
  23. package/resources/v1/customers/customers.d.mts +20 -0
  24. package/resources/v1/customers/customers.d.mts.map +1 -1
  25. package/resources/v1/customers/customers.d.ts +20 -0
  26. package/resources/v1/customers/customers.d.ts.map +1 -1
  27. package/resources/v1/customers/customers.js.map +1 -1
  28. package/resources/v1/customers/customers.mjs.map +1 -1
  29. package/resources/v1/usage.d.mts +4 -1
  30. package/resources/v1/usage.d.mts.map +1 -1
  31. package/resources/v1/usage.d.ts +4 -1
  32. package/resources/v1/usage.d.ts.map +1 -1
  33. package/resources/v1/usage.js +4 -1
  34. package/resources/v1/usage.js.map +1 -1
  35. package/resources/v1/usage.mjs +4 -1
  36. package/resources/v1/usage.mjs.map +1 -1
  37. package/resources/v2/index.d.mts +3 -0
  38. package/resources/v2/index.d.mts.map +1 -0
  39. package/resources/v2/index.d.ts +3 -0
  40. package/resources/v2/index.d.ts.map +1 -0
  41. package/resources/v2/index.js +9 -0
  42. package/resources/v2/index.js.map +1 -0
  43. package/resources/v2/index.mjs +4 -0
  44. package/resources/v2/index.mjs.map +1 -0
  45. package/resources/v2/usage.d.mts +284 -0
  46. package/resources/v2/usage.d.mts.map +1 -0
  47. package/resources/v2/usage.d.ts +284 -0
  48. package/resources/v2/usage.d.ts.map +1 -0
  49. package/resources/v2/usage.js +32 -0
  50. package/resources/v2/usage.js.map +1 -0
  51. package/resources/v2/usage.mjs +28 -0
  52. package/resources/v2/usage.mjs.map +1 -0
  53. package/resources/v2/v2.d.mts +10 -0
  54. package/resources/v2/v2.d.mts.map +1 -0
  55. package/resources/v2/v2.d.ts +10 -0
  56. package/resources/v2/v2.d.ts.map +1 -0
  57. package/resources/v2/v2.js +17 -0
  58. package/resources/v2/v2.js.map +1 -0
  59. package/resources/v2/v2.mjs +12 -0
  60. package/resources/v2/v2.mjs.map +1 -0
  61. package/resources/v2.d.mts +2 -0
  62. package/resources/v2.d.mts.map +1 -0
  63. package/resources/v2.d.ts +2 -0
  64. package/resources/v2.d.ts.map +1 -0
  65. package/resources/v2.js +6 -0
  66. package/resources/v2.js.map +1 -0
  67. package/resources/v2.mjs +3 -0
  68. package/resources/v2.mjs.map +1 -0
  69. package/src/client.ts +5 -0
  70. package/src/resources/index.ts +1 -0
  71. package/src/resources/v1/credits/consumption.ts +60 -0
  72. package/src/resources/v1/customers/customers.ts +24 -0
  73. package/src/resources/v1/usage.ts +4 -1
  74. package/src/resources/v2/index.ts +4 -0
  75. package/src/resources/v2/usage.ts +344 -0
  76. package/src/resources/v2/v2.ts +19 -0
  77. package/src/resources/v2.ts +3 -0
  78. package/src/version.ts +1 -1
  79. package/version.d.mts +1 -1
  80. package/version.d.ts +1 -1
  81. package/version.js +1 -1
  82. package/version.mjs +1 -1
@@ -0,0 +1,344 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../../core/resource';
4
+ import { APIPromise } from '../../core/api-promise';
5
+ import { buildHeaders } from '../../internal/headers';
6
+ import { RequestOptions } from '../../internal/request-options';
7
+
8
+ /**
9
+ * Operations related to usage & metering
10
+ */
11
+ export class Usage extends APIResource {
12
+ /**
13
+ * Reports usage measurements for metered features. The reported usage is used to
14
+ * track, limit, and bill customer consumption. Credit balances are returned once
15
+ * per wallet in `credits`, not on each measurement.
16
+ */
17
+ report(params: UsageReportParams, options?: RequestOptions): APIPromise<UsageReportResponse> {
18
+ const { 'X-ACCOUNT-ID': xAccountID, 'X-ENVIRONMENT-ID': xEnvironmentID, ...body } = params;
19
+ return this._client.post('/api/v2/usage', {
20
+ body,
21
+ ...options,
22
+ headers: buildHeaders([
23
+ {
24
+ ...(xAccountID != null ? { 'X-ACCOUNT-ID': xAccountID } : undefined),
25
+ ...(xEnvironmentID != null ? { 'X-ENVIRONMENT-ID': xEnvironmentID } : undefined),
26
+ },
27
+ options?.headers,
28
+ ]),
29
+ });
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Response containing reported usage measurements with current usage values,
35
+ * period information and reset dates, plus the balance of each credit wallet they
36
+ * drew from.
37
+ */
38
+ export interface UsageReportResponse {
39
+ /**
40
+ * Reported usage measurements and the credit balances they drew from
41
+ */
42
+ data: UsageReportResponse.Data;
43
+ }
44
+
45
+ export namespace UsageReportResponse {
46
+ /**
47
+ * Reported usage measurements and the credit balances they drew from
48
+ */
49
+ export interface Data {
50
+ /**
51
+ * Usage measurements, in request order, with current values and period info
52
+ */
53
+ usages: Array<Data.Usage>;
54
+
55
+ /**
56
+ * The balance of each credit wallet the request drew from. Omitted when no
57
+ * reported feature consumes credits, or when credit balances aren't computed
58
+ * synchronously for the environment; each usage's `credit` is then `null`.
59
+ */
60
+ credits?: Array<Data.Credit>;
61
+
62
+ /**
63
+ * The current usage of each governance entitlement this request counted towards.
64
+ * Absent when governance is not enabled or the usage is unknown. Entitlements
65
+ * whose usage could not be read, and those of repeated idempotent requests, are
66
+ * left out
67
+ */
68
+ entities?: Array<Data.Entity>;
69
+ }
70
+
71
+ export namespace Data {
72
+ /**
73
+ * Recorded usage with period info and the credits it deducted
74
+ */
75
+ export interface Usage {
76
+ /**
77
+ * Unique identifier for the entity
78
+ */
79
+ id: string;
80
+
81
+ /**
82
+ * Timestamp of when the record was created
83
+ */
84
+ createdAt: string;
85
+
86
+ /**
87
+ * Customer id
88
+ */
89
+ customerId: string;
90
+
91
+ /**
92
+ * Feature id
93
+ */
94
+ featureId: string;
95
+
96
+ /**
97
+ * Timestamp
98
+ */
99
+ timestamp: string;
100
+
101
+ /**
102
+ * The usage measurement record
103
+ */
104
+ value: number;
105
+
106
+ /**
107
+ * The credits this measurement deducted. `null` when the measurement drew from no
108
+ * wallet listed in `credits`. The balance of the wallet it drew from is in the
109
+ * response `credits` list, matched by customer, resource and currency.
110
+ */
111
+ credit?: Usage.Credit | null;
112
+
113
+ /**
114
+ * The current measured usage value
115
+ */
116
+ currentUsage?: number | null;
117
+
118
+ /**
119
+ * The date when the next usage reset will occur
120
+ */
121
+ nextResetDate?: string | null;
122
+
123
+ /**
124
+ * The customer resource this usage applies to. Optional — only required if the
125
+ * customer has multiple resources (for example, one subscription per workspace or
126
+ * site) and usage needs to be tracked separately per resource; omit it to report
127
+ * usage at the customer level.
128
+ */
129
+ resourceId?: string | null;
130
+
131
+ /**
132
+ * The end date of the usage period in which this measurement resides (for
133
+ * entitlements with a reset period)
134
+ */
135
+ usagePeriodEnd?: string | null;
136
+
137
+ /**
138
+ * The start date of the usage period in which this measurement resides (for
139
+ * entitlements with a reset period)
140
+ */
141
+ usagePeriodStart?: string | null;
142
+ }
143
+
144
+ export namespace Usage {
145
+ /**
146
+ * The credits this measurement deducted. `null` when the measurement drew from no
147
+ * wallet listed in `credits`. The balance of the wallet it drew from is in the
148
+ * response `credits` list, matched by customer, resource and currency.
149
+ */
150
+ export interface Credit {
151
+ /**
152
+ * The credits this single reportUsage call deducted, in credit units — scoped to
153
+ * this one measurement (0 for idempotency duplicates). Contrast `currentUsage`,
154
+ * which is the wallet-wide running total shared across all features on this
155
+ * currency. Use it to reconcile expected per-call deductions.
156
+ */
157
+ consumed: number;
158
+
159
+ /**
160
+ * The credit currency identifier
161
+ */
162
+ currencyId: string;
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Optimistic credit balance of one wallet (customer, resource and currency) after
168
+ * the request, listed once however many measurements drew from it
169
+ */
170
+ export interface Credit {
171
+ /**
172
+ * The credit currency identifier
173
+ */
174
+ currencyId: string;
175
+
176
+ /**
177
+ * The wallet's total consumed credits for this currency (optimistic — includes
178
+ * not-yet-reconciled usage), shared across every feature that draws on the
179
+ * currency. This is the running balance, not this call's deduction — see
180
+ * `consumed` for that.
181
+ */
182
+ currentUsage: number;
183
+
184
+ /**
185
+ * Customer id
186
+ */
187
+ customerId: string;
188
+
189
+ /**
190
+ * The wallet's resource; `null` for the customer-level wallet
191
+ */
192
+ resourceId: string | null;
193
+
194
+ /**
195
+ * The grant-version timestamp of this balance, used by the SDK for last-write-wins
196
+ * reconciliation
197
+ */
198
+ timestamp: string;
199
+
200
+ /**
201
+ * The total credits granted
202
+ */
203
+ usageLimit: number;
204
+
205
+ /**
206
+ * End of the current credit grant period (when recurring credits reset), if
207
+ * applicable
208
+ */
209
+ usagePeriodEnd?: string | null;
210
+ }
211
+
212
+ /**
213
+ * The usage counted against one governance entitlement
214
+ */
215
+ export interface Entity {
216
+ /**
217
+ * The absolute usage counted against the entitlement
218
+ */
219
+ currentUsage: number;
220
+
221
+ /**
222
+ * The customer whose usage counted towards the entitlement
223
+ */
224
+ customerId: string;
225
+
226
+ /**
227
+ * The governance entitlement the usage counts towards
228
+ */
229
+ entitlementId: string;
230
+
231
+ /**
232
+ * The governance entity the entitlement belongs to
233
+ */
234
+ entityId: string;
235
+
236
+ /**
237
+ * The customer resource the usage counted from; `null` for customer-level usage
238
+ */
239
+ resourceId: string | null;
240
+
241
+ /**
242
+ * The entities the entitlement is scoped to (empty when it is not scoped)
243
+ */
244
+ scopeEntityIds: Array<string>;
245
+
246
+ /**
247
+ * When the entitlement usage was last updated
248
+ */
249
+ usageUpdatedAt: string;
250
+
251
+ /**
252
+ * The credit currency the entitlement governs (exactly one of featureId and
253
+ * currencyId is set)
254
+ */
255
+ currencyId?: string;
256
+
257
+ /**
258
+ * The feature the entitlement governs (exactly one of featureId and currencyId is
259
+ * set)
260
+ */
261
+ featureId?: string;
262
+ }
263
+ }
264
+ }
265
+
266
+ export interface UsageReportParams {
267
+ /**
268
+ * Body param: A list of usage reports to be submitted in bulk
269
+ */
270
+ usages: Array<UsageReportParams.Usage>;
271
+
272
+ /**
273
+ * Header param: Account ID — optional when authenticating with a user JWT (Bearer
274
+ * token); falls back to the user's first membership. Ignored for API-key auth.
275
+ */
276
+ 'X-ACCOUNT-ID'?: string;
277
+
278
+ /**
279
+ * Header param: Environment ID — required when authenticating with a user JWT
280
+ * (Bearer token) on environment-scoped endpoints. Ignored for API-key auth (env is
281
+ * intrinsic to the key).
282
+ */
283
+ 'X-ENVIRONMENT-ID'?: string;
284
+ }
285
+
286
+ export namespace UsageReportParams {
287
+ /**
288
+ * Single usage measurement
289
+ */
290
+ export interface Usage {
291
+ /**
292
+ * Customer id
293
+ */
294
+ customerId: string;
295
+
296
+ /**
297
+ * Feature id
298
+ */
299
+ featureId: string;
300
+
301
+ /**
302
+ * The value to report for usage. Must be a whole number — the REST API does not
303
+ * accept fractional (float) usage values; scale up (e.g. report cents instead of
304
+ * dollars, or milliseconds instead of seconds) if you need sub-unit precision.
305
+ */
306
+ value: number;
307
+
308
+ /**
309
+ * Timestamp of when the record was created
310
+ */
311
+ createdAt?: string;
312
+
313
+ /**
314
+ * Additional dimensions for the usage report
315
+ */
316
+ dimensions?: { [key: string]: string | number | boolean };
317
+
318
+ /**
319
+ * A key you provide to safely retry the same usage report without double-counting
320
+ * it. Reports with a previously-seen idempotency key are deduplicated for 7 days;
321
+ * after that window a retry is treated as new usage.
322
+ */
323
+ idempotencyKey?: string;
324
+
325
+ /**
326
+ * The customer resource this usage applies to. Optional — only required if the
327
+ * customer has multiple resources (for example, one subscription per workspace or
328
+ * site) and usage needs to be tracked separately per resource; omit it to report
329
+ * usage at the customer level.
330
+ */
331
+ resourceId?: string | null;
332
+
333
+ /**
334
+ * How the reported value is applied: DELTA (default) adds it to the feature's
335
+ * current usage; SET treats it as the new absolute usage total, and Stigg computes
336
+ * the delta internally.
337
+ */
338
+ updateBehavior?: 'DELTA' | 'SET';
339
+ }
340
+ }
341
+
342
+ export declare namespace Usage {
343
+ export { type UsageReportResponse as UsageReportResponse, type UsageReportParams as UsageReportParams };
344
+ }
@@ -0,0 +1,19 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../../core/resource';
4
+ import * as UsageAPI from './usage';
5
+ import { Usage, UsageReportParams, UsageReportResponse } from './usage';
6
+
7
+ export class V2 extends APIResource {
8
+ usage: UsageAPI.Usage = new UsageAPI.Usage(this._client);
9
+ }
10
+
11
+ V2.Usage = Usage;
12
+
13
+ export declare namespace V2 {
14
+ export {
15
+ Usage as Usage,
16
+ type UsageReportResponse as UsageReportResponse,
17
+ type UsageReportParams as UsageReportParams,
18
+ };
19
+ }
@@ -0,0 +1,3 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export * from './v2/index';
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.1.0-beta.57'; // x-release-please-version
1
+ export const VERSION = '0.1.0-beta.58'; // x-release-please-version
package/version.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.1.0-beta.57";
1
+ export declare const VERSION = "0.1.0-beta.58";
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.57";
1
+ export declare const VERSION = "0.1.0-beta.58";
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.57'; // x-release-please-version
4
+ exports.VERSION = '0.1.0-beta.58'; // 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.57'; // x-release-please-version
1
+ export const VERSION = '0.1.0-beta.58'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map