@openmeter/sdk 1.0.0-beta.100 → 1.0.0-beta.102
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.
- package/README.md +169 -3
- package/dist/cjs/clients/client.cjs +3 -0
- package/dist/cjs/clients/client.d.cts +1 -1
- package/dist/cjs/clients/client.js.map +1 -1
- package/dist/cjs/clients/entitlement.cjs +27 -0
- package/dist/cjs/clients/entitlement.d.cts +25 -0
- package/dist/cjs/clients/entitlement.js.map +1 -0
- package/dist/cjs/clients/feature.cjs +75 -0
- package/dist/cjs/clients/feature.d.cts +40 -0
- package/dist/cjs/clients/feature.js.map +1 -0
- package/dist/cjs/clients/grant.cjs +27 -0
- package/dist/cjs/clients/grant.d.cts +15 -0
- package/dist/cjs/clients/grant.js.map +1 -0
- package/dist/cjs/clients/subject.cjs +166 -0
- package/dist/cjs/clients/subject.d.cts +92 -2
- package/dist/cjs/clients/subject.js.map +1 -1
- package/dist/cjs/index.cjs +9 -0
- package/dist/cjs/index.d.cts +6 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/schemas/openapi.d.cts +4 -4
- package/dist/cjs/test/agent.cjs +209 -5
- package/dist/cjs/test/agent.js.map +1 -1
- package/dist/cjs/test/mocks.cjs +109 -1
- package/dist/cjs/test/mocks.d.cts +11 -0
- package/dist/cjs/test/mocks.js.map +1 -1
- package/dist/cjs/tsconfig.32b136de.tsbuildinfo +1 -0
- package/dist/cjs/tsconfig.688f9ab6.tsbuildinfo +1 -0
- package/dist/clients/client.d.ts +1 -1
- package/dist/clients/client.js +3 -0
- package/dist/clients/client.js.map +1 -1
- package/dist/clients/entitlement.d.ts +25 -0
- package/dist/clients/entitlement.js +23 -0
- package/dist/clients/entitlement.js.map +1 -0
- package/dist/clients/feature.d.ts +40 -0
- package/dist/clients/feature.js +71 -0
- package/dist/clients/feature.js.map +1 -0
- package/dist/clients/grant.d.ts +15 -0
- package/dist/clients/grant.js +23 -0
- package/dist/clients/grant.js.map +1 -0
- package/dist/clients/subject.d.ts +92 -2
- package/dist/clients/subject.js +166 -0
- package/dist/clients/subject.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/schemas/openapi.d.ts +4 -4
- package/dist/test/agent.js +210 -6
- package/dist/test/agent.js.map +1 -1
- package/dist/test/mocks.d.ts +11 -0
- package/dist/test/mocks.js +108 -0
- package/dist/test/mocks.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/cjs/tsconfig.43c3843a.tsbuildinfo +0 -1
- package/dist/cjs/tsconfig.d98fa456.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -114,7 +114,7 @@ const subjects = await openmeter.meters.subjects('my-meter-slug')
|
|
|
114
114
|
|
|
115
115
|
#### createToken
|
|
116
116
|
|
|
117
|
-
Create subject
|
|
117
|
+
Create subject-specific tokens.
|
|
118
118
|
Useful to build consumer dashboards.
|
|
119
119
|
|
|
120
120
|
```ts
|
|
@@ -141,8 +141,8 @@ Upsert subjects.
|
|
|
141
141
|
const subjects = await openmeter.subjects.upsert([
|
|
142
142
|
{
|
|
143
143
|
key: 'customer-1',
|
|
144
|
-
displayName: 'ACME'
|
|
145
|
-
}
|
|
144
|
+
displayName: 'ACME',
|
|
145
|
+
},
|
|
146
146
|
])
|
|
147
147
|
```
|
|
148
148
|
|
|
@@ -170,3 +170,169 @@ It doesn't delete corresponding usage.
|
|
|
170
170
|
```ts
|
|
171
171
|
await openmeter.subjects.delete('customer-1')
|
|
172
172
|
```
|
|
173
|
+
|
|
174
|
+
#### createEntitlement
|
|
175
|
+
|
|
176
|
+
Create entitlement for a subject.
|
|
177
|
+
Entitlements allow you to manage subject feature access, balances, and usage limits.
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
// Issue 10,000,000 tokens every month
|
|
181
|
+
const entitlement = await openmeter.subjects.createEntitlement('customer-1', {
|
|
182
|
+
type: 'metered',
|
|
183
|
+
featureKey: 'ai_tokens',
|
|
184
|
+
usagePeriod: {
|
|
185
|
+
interval: 'MONTH',
|
|
186
|
+
},
|
|
187
|
+
issueAfterReset: 10000000,
|
|
188
|
+
})
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
#### listEntitlements
|
|
192
|
+
|
|
193
|
+
List subject entitlements.
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
const entitlement = await openmeter.subjects.listEntitlements('customer-1')
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
#### getEntitlement
|
|
200
|
+
|
|
201
|
+
Get a subject entitlement by ID by Feature ID or by Feature Key.
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
const entitlement = await openmeter.subjects.getEntitlement(
|
|
205
|
+
'customer-1',
|
|
206
|
+
'ai_tokens'
|
|
207
|
+
)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
#### deleteEntitlement
|
|
211
|
+
|
|
212
|
+
Delete a subject entitlement by ID by Feature ID or by Feature Key.
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
await openmeter.subjects.deleteEntitlement('customer-1', 'ai_tokens')
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
#### getEntitlementValue
|
|
219
|
+
|
|
220
|
+
Get entitlement value by ID by Feature ID or by Feature Key.
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
const value = await openmeter.subjects.getEntitlementValue(
|
|
224
|
+
'customer-1',
|
|
225
|
+
'ai_tokens'
|
|
226
|
+
)
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
#### getEntitlementHistory
|
|
230
|
+
|
|
231
|
+
Get entitlement history by ID by Feature ID or by Feature Key
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
const entitlement = await openmeter.subjects.getEntitlementHistory(
|
|
235
|
+
'customer-1',
|
|
236
|
+
'ai_tokens'
|
|
237
|
+
)
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
#### resetEntitlementUsage
|
|
241
|
+
|
|
242
|
+
Reset the entitlement usage and start a new period. Eligible grants will be rolled over.
|
|
243
|
+
|
|
244
|
+
```ts
|
|
245
|
+
const entitlement = await openmeter.subjects.resetEntitlementUsage(
|
|
246
|
+
'customer-1',
|
|
247
|
+
{
|
|
248
|
+
retainAnchor: true,
|
|
249
|
+
}
|
|
250
|
+
)
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
#### createEntitlementGrant
|
|
254
|
+
|
|
255
|
+
Create a grant for an entitlement.
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
const grant = await openmeter.subjects.createEntitlementGrant(
|
|
259
|
+
'customer-1',
|
|
260
|
+
'ai_tokens',
|
|
261
|
+
{
|
|
262
|
+
amount: 100,
|
|
263
|
+
priority: 1,
|
|
264
|
+
effectiveAt: '2023-01-01T00:00:00Z',
|
|
265
|
+
expiration: {
|
|
266
|
+
duration: 'HOUR',
|
|
267
|
+
count: 12,
|
|
268
|
+
},
|
|
269
|
+
minRolloverAmount: 100,
|
|
270
|
+
maxRolloverAmount: 100,
|
|
271
|
+
recurrence: {
|
|
272
|
+
interval: 'MONTH',
|
|
273
|
+
anchor: '2024-06-28T18:29:44.867Z',
|
|
274
|
+
},
|
|
275
|
+
}
|
|
276
|
+
)
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
#### listEntitlementGrants
|
|
280
|
+
|
|
281
|
+
List entitlement grants
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
const entitlement = await openmeter.subjects.listEntitlementGrants('customer-1', 'ai_tokens)
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## Features
|
|
288
|
+
|
|
289
|
+
Features are the building blocks of your entitlements, part of your product offering.
|
|
290
|
+
|
|
291
|
+
#### create
|
|
292
|
+
|
|
293
|
+
Upsert subjects.
|
|
294
|
+
|
|
295
|
+
```ts
|
|
296
|
+
const feature = await openmeter.features.create({
|
|
297
|
+
key: 'ai_tokens',
|
|
298
|
+
name: 'AI Tokens',
|
|
299
|
+
// optional
|
|
300
|
+
meterSlug: 'tokens_total',
|
|
301
|
+
})
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
#### list
|
|
305
|
+
|
|
306
|
+
List features.
|
|
307
|
+
|
|
308
|
+
```ts
|
|
309
|
+
const features = await openmeter.features.list()
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
#### get
|
|
313
|
+
|
|
314
|
+
Get feature by key.
|
|
315
|
+
|
|
316
|
+
```ts
|
|
317
|
+
const feature = await openmeter.features.get('ai_tokens')
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
#### delete
|
|
321
|
+
|
|
322
|
+
Delete feature by key.
|
|
323
|
+
|
|
324
|
+
```ts
|
|
325
|
+
await openmeter.features.delete('ai_tokens')
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
## Grants
|
|
329
|
+
|
|
330
|
+
Entitlement grants allow to issue of additional one-time or recurring allowances on a subject's entitlement.
|
|
331
|
+
|
|
332
|
+
#### list
|
|
333
|
+
|
|
334
|
+
List grants.
|
|
335
|
+
|
|
336
|
+
```ts
|
|
337
|
+
const grants = await openmeter.grants.list()
|
|
338
|
+
```
|
|
@@ -28,7 +28,7 @@ export declare class BaseClient {
|
|
|
28
28
|
}): Promise<T>;
|
|
29
29
|
protected getUrl(path: string, searchParams?: URLSearchParams): import("url").URL;
|
|
30
30
|
protected getAuthHeaders(): IncomingHttpHeaders;
|
|
31
|
-
protected static toURLSearchParams(params: Record<string, string | number | Date | string[] | Record<string, string> | undefined>): URLSearchParams;
|
|
31
|
+
protected static toURLSearchParams(params: Record<string, string | boolean | number | Date | string[] | Record<string, string> | undefined>): URLSearchParams;
|
|
32
32
|
}
|
|
33
33
|
export declare class HttpError extends Error {
|
|
34
34
|
statusCode: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../clients/client.ts"],"names":[],"mappings":";;;AACA,mCAA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
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntitlementClient = void 0;
|
|
4
|
+
const client_js_1 = require("./client.cjs");
|
|
5
|
+
class EntitlementClient extends client_js_1.BaseClient {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
super(config);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* List entitlements
|
|
11
|
+
* @example
|
|
12
|
+
* const entitlement = await openmeter.entitlements.list()
|
|
13
|
+
*/
|
|
14
|
+
async list(params, options) {
|
|
15
|
+
const searchParams = params
|
|
16
|
+
? client_js_1.BaseClient.toURLSearchParams(params)
|
|
17
|
+
: undefined;
|
|
18
|
+
return await this.request({
|
|
19
|
+
path: '/api/v1/entitlements',
|
|
20
|
+
method: 'GET',
|
|
21
|
+
searchParams,
|
|
22
|
+
options,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.EntitlementClient = EntitlementClient;
|
|
27
|
+
//# sourceMappingURL=entitlement.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { components, operations } from '../schemas/openapi.cjs';
|
|
2
|
+
import { RequestOptions, BaseClient, OpenMeterConfig } from './client.cjs';
|
|
3
|
+
export type Entitlement = EntitlementMetered | EntitlementStatic | EntitlementBoolean;
|
|
4
|
+
export type EntitlementMetered = components['schemas']['EntitlementMetered'];
|
|
5
|
+
export type EntitlementStatic = components['schemas']['EntitlementStatic'];
|
|
6
|
+
export type EntitlementBoolean = components['schemas']['EntitlementBoolean'];
|
|
7
|
+
export type RecurringPeriodEnum = components['schemas']['RecurringPeriodEnum'];
|
|
8
|
+
export type EntitlementValue = components['schemas']['EntitlementValue'];
|
|
9
|
+
export type WindowedBalanceHistory = components['schemas']['WindowedBalanceHistory'];
|
|
10
|
+
export type EntitlementCreateInputs = EntitlementMeteredCreateInputs | EntitlementStaticCreateInputs | EntitlementBooleanCreateInputs;
|
|
11
|
+
export type EntitlementMeteredCreateInputs = components['schemas']['EntitlementMeteredCreateInputs'];
|
|
12
|
+
export type EntitlementStaticCreateInputs = components['schemas']['EntitlementStaticCreateInputs'];
|
|
13
|
+
export type EntitlementBooleanCreateInputs = components['schemas']['EntitlementBooleanCreateInputs'];
|
|
14
|
+
export type EntitlementResetInputs = operations['resetEntitlementUsage']['requestBody']['content']['application/json'];
|
|
15
|
+
export type ListEntitlementQueryParams = operations['listEntitlements']['parameters']['query'];
|
|
16
|
+
export type GetEntitlementHistoryQueryParams = operations['getEntitlementHistory']['parameters']['query'];
|
|
17
|
+
export declare class EntitlementClient extends BaseClient {
|
|
18
|
+
constructor(config: OpenMeterConfig);
|
|
19
|
+
/**
|
|
20
|
+
* List entitlements
|
|
21
|
+
* @example
|
|
22
|
+
* const entitlement = await openmeter.entitlements.list()
|
|
23
|
+
*/
|
|
24
|
+
list(params?: ListEntitlementQueryParams, options?: RequestOptions): Promise<Entitlement[]>;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlement.js","sourceRoot":"","sources":["../../../clients/entitlement.ts"],"names":[],"mappings":";;;AACA,2CAAyE;AA8BzE,MAAa,iBAAkB,SAAQ,sBAAU;IAC/C,YAAY,MAAuB;QACjC,KAAK,CAAC,MAAM,CAAC,CAAA;IACf,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,IAAI,CACf,MAAmC,EACnC,OAAwB;QAExB,MAAM,YAAY,GAAG,MAAM;YACzB,CAAC,CAAC,sBAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC;YACtC,CAAC,CAAC,SAAS,CAAA;QACb,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC;YACxB,IAAI,EAAE,sBAAsB;YAC5B,MAAM,EAAE,KAAK;YACb,YAAY;YACZ,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;CACF;AAxBD,8CAwBC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FeatureClient = void 0;
|
|
4
|
+
const client_js_1 = require("./client.cjs");
|
|
5
|
+
class FeatureClient extends client_js_1.BaseClient {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
super(config);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create Feature
|
|
11
|
+
* Features are the building blocks of your entitlements, part of your product offering.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const feature = await openmeter.features.create({
|
|
15
|
+
* key: 'ai_tokens',
|
|
16
|
+
* name: 'AI Tokens',
|
|
17
|
+
* // optional
|
|
18
|
+
* meterSlug: 'tokens_total',
|
|
19
|
+
* })
|
|
20
|
+
*/
|
|
21
|
+
async create(input, options) {
|
|
22
|
+
return await this.request({
|
|
23
|
+
path: '/api/v1/features',
|
|
24
|
+
method: 'POST',
|
|
25
|
+
headers: {
|
|
26
|
+
'Content-Type': 'application/json',
|
|
27
|
+
},
|
|
28
|
+
body: JSON.stringify(input),
|
|
29
|
+
options,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get Feature by ID or Key
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* const feature = await openmeter.features.get('ai_tokens')
|
|
37
|
+
*/
|
|
38
|
+
async get(idOrKey, options) {
|
|
39
|
+
return await this.request({
|
|
40
|
+
path: `/api/v1/features/${idOrKey}`,
|
|
41
|
+
method: 'GET',
|
|
42
|
+
options,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* List features
|
|
47
|
+
* @example
|
|
48
|
+
* const feature = await openmeter.features.list()
|
|
49
|
+
*/
|
|
50
|
+
async list(params, options) {
|
|
51
|
+
const searchParams = params
|
|
52
|
+
? client_js_1.BaseClient.toURLSearchParams(params)
|
|
53
|
+
: undefined;
|
|
54
|
+
return await this.request({
|
|
55
|
+
path: '/api/v1/features',
|
|
56
|
+
method: 'GET',
|
|
57
|
+
searchParams,
|
|
58
|
+
options,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Delete feature by ID or Key
|
|
63
|
+
* @example
|
|
64
|
+
* await openmeter.delete('ai_tokens')
|
|
65
|
+
*/
|
|
66
|
+
async delete(idOrKey, options) {
|
|
67
|
+
return await this.request({
|
|
68
|
+
path: `/api/v1/features/${idOrKey}`,
|
|
69
|
+
method: 'DELETE',
|
|
70
|
+
options,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.FeatureClient = FeatureClient;
|
|
75
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { components, operations } from '../schemas/openapi.cjs';
|
|
2
|
+
import { RequestOptions, BaseClient, OpenMeterConfig } from './client.cjs';
|
|
3
|
+
export type Feature = components['schemas']['Feature'];
|
|
4
|
+
export type FeatureCreateInputs = components['schemas']['FeatureCreateInputs'];
|
|
5
|
+
export type ListFeatureQueryParams = operations['listFeatures']['parameters']['query'];
|
|
6
|
+
export declare class FeatureClient extends BaseClient {
|
|
7
|
+
constructor(config: OpenMeterConfig);
|
|
8
|
+
/**
|
|
9
|
+
* Create Feature
|
|
10
|
+
* Features are the building blocks of your entitlements, part of your product offering.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const feature = await openmeter.features.create({
|
|
14
|
+
* key: 'ai_tokens',
|
|
15
|
+
* name: 'AI Tokens',
|
|
16
|
+
* // optional
|
|
17
|
+
* meterSlug: 'tokens_total',
|
|
18
|
+
* })
|
|
19
|
+
*/
|
|
20
|
+
create(input: FeatureCreateInputs, options?: RequestOptions): Promise<Feature>;
|
|
21
|
+
/**
|
|
22
|
+
* Get Feature by ID or Key
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const feature = await openmeter.features.get('ai_tokens')
|
|
26
|
+
*/
|
|
27
|
+
get(idOrKey: string, options?: RequestOptions): Promise<Feature>;
|
|
28
|
+
/**
|
|
29
|
+
* List features
|
|
30
|
+
* @example
|
|
31
|
+
* const feature = await openmeter.features.list()
|
|
32
|
+
*/
|
|
33
|
+
list(params?: ListFeatureQueryParams, options?: RequestOptions): Promise<Feature[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Delete feature by ID or Key
|
|
36
|
+
* @example
|
|
37
|
+
* await openmeter.delete('ai_tokens')
|
|
38
|
+
*/
|
|
39
|
+
delete(idOrKey: string, options?: RequestOptions): Promise<void>;
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature.js","sourceRoot":"","sources":["../../../clients/feature.ts"],"names":[],"mappings":";;;AACA,2CAAyE;AAOzE,MAAa,aAAc,SAAQ,sBAAU;IAC3C,YAAY,MAAuB;QACjC,KAAK,CAAC,MAAM,CAAC,CAAA;IACf,CAAC;IAED;;;;;;;;;;;OAWG;IACI,KAAK,CAAC,MAAM,CACjB,KAA0B,EAC1B,OAAwB;QAExB,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC;YACxB,IAAI,EAAE,kBAAkB;YACxB,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;YAC3B,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,GAAG,CACd,OAAe,EACf,OAAwB;QAExB,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC;YACxB,IAAI,EAAE,oBAAoB,OAAO,EAAE;YACnC,MAAM,EAAE,KAAK;YACb,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,IAAI,CACf,MAA+B,EAC/B,OAAwB;QAExB,MAAM,YAAY,GAAG,MAAM;YACzB,CAAC,CAAC,sBAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC;YACtC,CAAC,CAAC,SAAS,CAAA;QACb,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC;YACxB,IAAI,EAAE,kBAAkB;YACxB,MAAM,EAAE,KAAK;YACb,YAAY;YACZ,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,MAAM,CACjB,OAAe,EACf,OAAwB;QAExB,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC;YACxB,IAAI,EAAE,oBAAoB,OAAO,EAAE;YACnC,MAAM,EAAE,QAAQ;YAChB,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;CACF;AApFD,sCAoFC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GrantClient = void 0;
|
|
4
|
+
const client_js_1 = require("./client.cjs");
|
|
5
|
+
class GrantClient extends client_js_1.BaseClient {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
super(config);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* List grants
|
|
11
|
+
* @example
|
|
12
|
+
* const grant = await openmeter.grants.list()
|
|
13
|
+
*/
|
|
14
|
+
async list(params, options) {
|
|
15
|
+
const searchParams = params
|
|
16
|
+
? client_js_1.BaseClient.toURLSearchParams(params)
|
|
17
|
+
: undefined;
|
|
18
|
+
return await this.request({
|
|
19
|
+
path: '/api/v1/grants',
|
|
20
|
+
method: 'GET',
|
|
21
|
+
searchParams,
|
|
22
|
+
options,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.GrantClient = GrantClient;
|
|
27
|
+
//# sourceMappingURL=grant.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { components, operations } from '../schemas/openapi.cjs';
|
|
2
|
+
import { RequestOptions, BaseClient, OpenMeterConfig } from './client.cjs';
|
|
3
|
+
export type EntitlementGrant = components['schemas']['EntitlementGrant'];
|
|
4
|
+
export type EntitlementGrantCreateInput = components['schemas']['EntitlementGrantCreateInput'];
|
|
5
|
+
export type ListGrantQueryParams = operations['listGrants']['parameters']['query'];
|
|
6
|
+
export type ListEntitlementGrantQueryParams = operations['listEntitlementGrants']['parameters']['query'];
|
|
7
|
+
export declare class GrantClient extends BaseClient {
|
|
8
|
+
constructor(config: OpenMeterConfig);
|
|
9
|
+
/**
|
|
10
|
+
* List grants
|
|
11
|
+
* @example
|
|
12
|
+
* const grant = await openmeter.grants.list()
|
|
13
|
+
*/
|
|
14
|
+
list(params?: ListGrantQueryParams, options?: RequestOptions): Promise<EntitlementGrant[]>;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grant.js","sourceRoot":"","sources":["../../../clients/grant.ts"],"names":[],"mappings":";;;AACA,2CAAyE;AAUzE,MAAa,WAAY,SAAQ,sBAAU;IACzC,YAAY,MAAuB;QACjC,KAAK,CAAC,MAAM,CAAC,CAAA;IACf,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,IAAI,CACf,MAA6B,EAC7B,OAAwB;QAExB,MAAM,YAAY,GAAG,MAAM;YACzB,CAAC,CAAC,sBAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC;YACtC,CAAC,CAAC,SAAS,CAAA;QACb,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC;YACxB,IAAI,EAAE,gBAAgB;YACtB,MAAM,EAAE,KAAK;YACb,YAAY;YACZ,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;CACF;AAxBD,kCAwBC"}
|
|
@@ -55,6 +55,172 @@ class SubjectClient extends client_js_1.BaseClient {
|
|
|
55
55
|
options,
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
+
/** Entitlements **/
|
|
59
|
+
/**
|
|
60
|
+
* Create Entitlement
|
|
61
|
+
* Entitlements allows you to manage subject feature access, balances, and usage limits.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // Issue 10,000,000 tokens every month
|
|
65
|
+
* const entitlement = await openmeter.subjects.createEntitlement('customer-1', {
|
|
66
|
+
* type: 'metered',
|
|
67
|
+
* featureKey: 'ai_tokens',
|
|
68
|
+
* usagePeriod: {
|
|
69
|
+
* interval: 'MONTH',
|
|
70
|
+
* },
|
|
71
|
+
* issueAfterReset: 10000000,
|
|
72
|
+
* })
|
|
73
|
+
*/
|
|
74
|
+
async createEntitlement(subjectIdOrKey, input, options) {
|
|
75
|
+
return await this.request({
|
|
76
|
+
path: `/api/v1/subjects/${subjectIdOrKey}/entitlements`,
|
|
77
|
+
method: 'POST',
|
|
78
|
+
headers: {
|
|
79
|
+
'Content-Type': 'application/json',
|
|
80
|
+
},
|
|
81
|
+
body: JSON.stringify(input),
|
|
82
|
+
options,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* List entitlements
|
|
87
|
+
* @example
|
|
88
|
+
* const entitlement = await openmeter.subjects.listEntitlements('customer-1')
|
|
89
|
+
*/
|
|
90
|
+
async listEntitlements(subjectIdOrKey, params, options) {
|
|
91
|
+
const searchParams = params
|
|
92
|
+
? client_js_1.BaseClient.toURLSearchParams(params)
|
|
93
|
+
: undefined;
|
|
94
|
+
return await this.request({
|
|
95
|
+
path: `/api/v1/subjects/${subjectIdOrKey}/entitlements`,
|
|
96
|
+
method: 'GET',
|
|
97
|
+
searchParams,
|
|
98
|
+
options,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get entitlement by ID by Feature ID or by Feature Key
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* const entitlement = await openmeter.subjects.getEntitlement('customer-1', 'ai_tokens')
|
|
106
|
+
*/
|
|
107
|
+
async getEntitlement(subjectIdOrKey, entitlementIdOrFeatureIdOrFeatureKey, options) {
|
|
108
|
+
return await this.request({
|
|
109
|
+
path: `/api/v1/subjects/${subjectIdOrKey}/entitlements/${entitlementIdOrFeatureIdOrFeatureKey}`,
|
|
110
|
+
method: 'GET',
|
|
111
|
+
options,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Delete entitlement by ID by Feature ID or by Feature Key
|
|
116
|
+
* @example
|
|
117
|
+
* await openmeter.deleteEntitlement('customer-1', 'ai_tokens')
|
|
118
|
+
*/
|
|
119
|
+
async deleteEntitlement(subjectIdOrKey, entitlementIdOrFeatureIdOrFeatureKey, options) {
|
|
120
|
+
return await this.request({
|
|
121
|
+
path: `/api/v1/subjects/${subjectIdOrKey}/entitlements/${entitlementIdOrFeatureIdOrFeatureKey}`,
|
|
122
|
+
method: 'DELETE',
|
|
123
|
+
options,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get entitlement value by ID by Feature ID or by Feature Key
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* const value = await openmeter.subjects.getEntitlementValue('customer-1', 'ai_tokens')
|
|
131
|
+
*/
|
|
132
|
+
async getEntitlementValue(subjectIdOrKey, entitlementIdOrFeatureIdOrFeatureKey, options) {
|
|
133
|
+
return await this.request({
|
|
134
|
+
path: `/api/v1/subjects/${subjectIdOrKey}/entitlements/${entitlementIdOrFeatureIdOrFeatureKey}/value`,
|
|
135
|
+
method: 'GET',
|
|
136
|
+
options,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get entitlement history by ID by Feature ID or by Feature Key
|
|
141
|
+
* @example
|
|
142
|
+
* const entitlement = await openmeter.subjects.getEntitlementHistory('customer-1', 'ai_tokens')
|
|
143
|
+
*/
|
|
144
|
+
async getEntitlementHistory(subjectIdOrKey, entitlementIdOrFeatureIdOrFeatureKey, params, options) {
|
|
145
|
+
const searchParams = params
|
|
146
|
+
? client_js_1.BaseClient.toURLSearchParams(params)
|
|
147
|
+
: undefined;
|
|
148
|
+
return await this.request({
|
|
149
|
+
path: `/api/v1/subjects/${subjectIdOrKey}/entitlements/${entitlementIdOrFeatureIdOrFeatureKey}/history`,
|
|
150
|
+
method: 'GET',
|
|
151
|
+
searchParams,
|
|
152
|
+
options,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Reset Entitlement Usage
|
|
157
|
+
* Reset the entitlement usage and start a new period. Eligible grants will be rolled over
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* const entitlement = await openmeter.subjects.resetEntitlementUsage('customer-1', 'ai_tokens', {
|
|
161
|
+
* retainAnchor: true
|
|
162
|
+
* })
|
|
163
|
+
*/
|
|
164
|
+
async resetEntitlementUsage(subjectIdOrKey, entitlementIdOrFeatureIdOrFeatureKey, input, options) {
|
|
165
|
+
return await this.request({
|
|
166
|
+
path: `/api/v1/subjects/${subjectIdOrKey}/entitlements/${entitlementIdOrFeatureIdOrFeatureKey}/reset`,
|
|
167
|
+
method: 'POST',
|
|
168
|
+
headers: {
|
|
169
|
+
'Content-Type': 'application/json',
|
|
170
|
+
},
|
|
171
|
+
body: JSON.stringify(input),
|
|
172
|
+
options,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/** Entitlement Grant **/
|
|
176
|
+
/**
|
|
177
|
+
* Create Entitlement Grant
|
|
178
|
+
* Create a grant for an entitlement.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* const grant = await openmeter.subjects.createEntitlementGrant('customer-1', 'ai_tokens', {
|
|
182
|
+
* amount: 100,
|
|
183
|
+
* priority: 1,
|
|
184
|
+
* effectiveAt: '2023-01-01T00:00:00Z',
|
|
185
|
+
* expiration: {
|
|
186
|
+
* duration: 'HOUR',
|
|
187
|
+
* count: 12,
|
|
188
|
+
* },
|
|
189
|
+
* minRolloverAmount: 100,
|
|
190
|
+
* maxRolloverAmount: 100,
|
|
191
|
+
* recurrence: {
|
|
192
|
+
* interval: 'MONTH',
|
|
193
|
+
* anchor: '2024-06-28T18:29:44.867Z',
|
|
194
|
+
* },
|
|
195
|
+
* })
|
|
196
|
+
*/
|
|
197
|
+
async createEntitlementGrant(subjectIdOrKey, entitlementIdOrFeatureIdOrFeatureKey, input, options) {
|
|
198
|
+
return await this.request({
|
|
199
|
+
path: `/api/v1/subjects/${subjectIdOrKey}/entitlements/${entitlementIdOrFeatureIdOrFeatureKey}/grants`,
|
|
200
|
+
method: 'POST',
|
|
201
|
+
headers: {
|
|
202
|
+
'Content-Type': 'application/json',
|
|
203
|
+
},
|
|
204
|
+
body: JSON.stringify(input),
|
|
205
|
+
options,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* List entitlement grants
|
|
210
|
+
* @example
|
|
211
|
+
* const entitlement = await openmeter.subjects.listEntitlementGrants('customer-1', 'ai_tokens)
|
|
212
|
+
*/
|
|
213
|
+
async listEntitlementGrants(subjectIdOrKey, entitlementIdOrFeatureIdOrFeatureKey, params, options) {
|
|
214
|
+
const searchParams = params
|
|
215
|
+
? client_js_1.BaseClient.toURLSearchParams(params)
|
|
216
|
+
: undefined;
|
|
217
|
+
return await this.request({
|
|
218
|
+
path: `/api/v1/subjects/${subjectIdOrKey}/entitlements/${entitlementIdOrFeatureIdOrFeatureKey}/grants`,
|
|
219
|
+
method: 'GET',
|
|
220
|
+
searchParams,
|
|
221
|
+
options,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
58
224
|
}
|
|
59
225
|
exports.SubjectClient = SubjectClient;
|
|
60
226
|
//# sourceMappingURL=subject.js.map
|