@openmeter/sdk 1.0.0-beta.13 → 1.0.0-beta.131

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 (86) hide show
  1. package/README.md +224 -46
  2. package/dist/cjs/clients/client.cjs +120 -0
  3. package/dist/cjs/clients/client.d.cts +37 -0
  4. package/dist/cjs/clients/client.js.map +1 -0
  5. package/dist/cjs/clients/entitlement.cjs +39 -0
  6. package/dist/cjs/clients/entitlement.d.cts +32 -0
  7. package/dist/cjs/clients/entitlement.js.map +1 -0
  8. package/dist/cjs/clients/event.cjs +71 -0
  9. package/dist/cjs/clients/event.d.cts +79 -0
  10. package/dist/cjs/clients/event.js.map +1 -0
  11. package/dist/cjs/clients/feature.cjs +80 -0
  12. package/dist/cjs/clients/feature.d.cts +46 -0
  13. package/dist/cjs/clients/feature.js.map +1 -0
  14. package/dist/cjs/clients/grant.cjs +41 -0
  15. package/dist/cjs/clients/grant.d.cts +24 -0
  16. package/dist/cjs/clients/grant.js.map +1 -0
  17. package/dist/cjs/clients/meter.cjs +83 -0
  18. package/dist/cjs/clients/meter.d.cts +79 -0
  19. package/dist/cjs/clients/meter.js.map +1 -0
  20. package/dist/cjs/clients/pagination.cjs +3 -0
  21. package/dist/cjs/clients/pagination.d.cts +6 -0
  22. package/dist/cjs/clients/pagination.js.map +1 -0
  23. package/dist/cjs/clients/portal.cjs +41 -0
  24. package/dist/cjs/clients/portal.d.cts +22 -0
  25. package/dist/cjs/clients/portal.js.map +1 -0
  26. package/dist/cjs/clients/subject.cjs +242 -0
  27. package/dist/cjs/clients/subject.d.cts +125 -0
  28. package/dist/cjs/clients/subject.js.map +1 -0
  29. package/dist/cjs/index.cjs +33 -0
  30. package/dist/cjs/index.d.cts +21 -0
  31. package/dist/cjs/index.js.map +1 -0
  32. package/dist/cjs/schemas/openapi.cjs +7 -0
  33. package/dist/cjs/schemas/openapi.d.cts +3032 -0
  34. package/dist/cjs/schemas/openapi.js.map +1 -0
  35. package/dist/cjs/test/agent.cjs +485 -0
  36. package/dist/cjs/test/agent.d.cts +2 -0
  37. package/dist/cjs/test/agent.js.map +1 -0
  38. package/dist/cjs/test/mocks.cjs +153 -0
  39. package/dist/cjs/test/mocks.d.cts +25 -0
  40. package/dist/cjs/test/mocks.js.map +1 -0
  41. package/dist/cjs/tsconfig.229eb452.tsbuildinfo +1 -0
  42. package/dist/cjs/tsconfig.b2052a4e.tsbuildinfo +1 -0
  43. package/dist/clients/client.d.ts +1 -4
  44. package/dist/clients/client.js +12 -1
  45. package/dist/clients/client.js.map +1 -0
  46. package/dist/clients/entitlement.d.ts +32 -0
  47. package/dist/clients/entitlement.js +35 -0
  48. package/dist/clients/entitlement.js.map +1 -0
  49. package/dist/clients/event.d.ts +5 -5
  50. package/dist/clients/event.js +29 -18
  51. package/dist/clients/event.js.map +1 -0
  52. package/dist/clients/feature.d.ts +46 -0
  53. package/dist/clients/feature.js +76 -0
  54. package/dist/clients/feature.js.map +1 -0
  55. package/dist/clients/grant.d.ts +24 -0
  56. package/dist/clients/grant.js +37 -0
  57. package/dist/clients/grant.js.map +1 -0
  58. package/dist/clients/meter.d.ts +13 -30
  59. package/dist/clients/meter.js +15 -0
  60. package/dist/clients/meter.js.map +1 -0
  61. package/dist/clients/pagination.d.ts +6 -0
  62. package/dist/clients/pagination.js +2 -0
  63. package/dist/clients/pagination.js.map +1 -0
  64. package/dist/clients/portal.d.ts +22 -0
  65. package/dist/clients/portal.js +37 -0
  66. package/dist/clients/portal.js.map +1 -0
  67. package/dist/clients/subject.d.ts +125 -0
  68. package/dist/clients/subject.js +238 -0
  69. package/dist/clients/subject.js.map +1 -0
  70. package/dist/index.d.ts +11 -2
  71. package/dist/index.js +16 -1
  72. package/dist/index.js.map +1 -0
  73. package/dist/schemas/openapi.d.ts +2790 -164
  74. package/dist/schemas/openapi.js +1 -0
  75. package/dist/schemas/openapi.js.map +1 -0
  76. package/dist/test/agent.js +327 -29
  77. package/dist/test/agent.js.map +1 -0
  78. package/dist/test/mocks.d.ts +13 -0
  79. package/dist/test/mocks.js +118 -0
  80. package/dist/test/mocks.js.map +1 -0
  81. package/dist/tsconfig.tsbuildinfo +1 -1
  82. package/package.json +40 -30
  83. package/dist/next.d.ts +0 -15
  84. package/dist/next.js +0 -46
  85. package/index.ts +0 -19
  86. package/next.ts +0 -76
@@ -0,0 +1,76 @@
1
+ import { BaseClient } from './client.js';
2
+ export class FeatureClient extends BaseClient {
3
+ constructor(config) {
4
+ super(config);
5
+ }
6
+ /**
7
+ * Features are the building blocks of your entitlements, part of your product offering.
8
+ * @description
9
+ * Features are either metered or static. A feature is metered if meterSlug is provided at creation. For metered features you can pass additional filters that will be applied when calculating feature usage, based on the meter's groupBy fields. Only meters with SUM and COUNT aggregation are supported for features.
10
+ *
11
+ * Features cannot be updated later, only archived.
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
34
+ *
35
+ * @example
36
+ * const feature = await openmeter.features.get('ai_tokens')
37
+ */
38
+ async get(id, options) {
39
+ return await this.request({
40
+ path: `/api/v1/features/${id}`,
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
+ ? 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
+ * Archive a feature
63
+ * @description
64
+ * Once a feature is archived it cannot be unarchived. If a feature is archived, new entitlements cannot be created for it, but archiving the feature does not affect existing entitlements.
65
+ * @example
66
+ * await openmeter.delete('ai_tokens')
67
+ */
68
+ async delete(id, options) {
69
+ return await this.request({
70
+ path: `/api/v1/features/${id}`,
71
+ method: 'DELETE',
72
+ options,
73
+ });
74
+ }
75
+ }
76
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature.js","sourceRoot":"","sources":["../../clients/feature.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,UAAU,EAAmB,MAAM,aAAa,CAAA;AAQzE,MAAM,OAAO,aAAc,SAAQ,UAAU;IAC3C,YAAY,MAAuB;QACjC,KAAK,CAAC,MAAM,CAAC,CAAA;IACf,CAAC;IAED;;;;;;;;;;;;;;OAcG;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,CAAC,EAAU,EAAE,OAAwB;QACnD,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC;YACxB,IAAI,EAAE,oBAAoB,EAAE,EAAE;YAC9B,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,UAAU,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;;;;;;OAMG;IACI,KAAK,CAAC,MAAM,CAAC,EAAU,EAAE,OAAwB;QACtD,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC;YACxB,IAAI,EAAE,oBAAoB,EAAE,EAAE;YAC9B,MAAM,EAAE,QAAQ;YAChB,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,24 @@
1
+ import { components, operations } from '../schemas/openapi.js';
2
+ import { RequestOptions, BaseClient, OpenMeterConfig } from './client.js';
3
+ import { Paginated } from './pagination.js';
4
+ export type EntitlementGrant = components['schemas']['EntitlementGrant'];
5
+ export type EntitlementGrantCreateInput = components['schemas']['EntitlementGrantCreateInput'];
6
+ export type ListGrantQueryParams = operations['listGrants']['parameters']['query'];
7
+ export type ListEntitlementGrantQueryParams = operations['listEntitlementGrants']['parameters']['query'];
8
+ export declare class GrantClient extends BaseClient {
9
+ constructor(config: OpenMeterConfig);
10
+ /**
11
+ * List grants
12
+ * @example
13
+ * const grant = await openmeter.grants.list()
14
+ */
15
+ list(params?: ListGrantQueryParams, options?: RequestOptions): Promise<EntitlementGrant[] | Paginated<EntitlementGrant>>;
16
+ /**
17
+ * Void a grant
18
+ * @description
19
+ * Voiding a grant means it is no longer valid, it doesn't take part in further balance calculations. Voiding a grant does not retroactively take effect, meaning any usage that has already been attributed to the grant will remain, but future usage cannot be burnt down from the grant.
20
+ * @example
21
+ * const grant = await openmeter.grants.list()
22
+ */
23
+ delete(id: string, options?: RequestOptions): Promise<EntitlementGrant[]>;
24
+ }
@@ -0,0 +1,37 @@
1
+ import { BaseClient } from './client.js';
2
+ export class GrantClient extends BaseClient {
3
+ constructor(config) {
4
+ super(config);
5
+ }
6
+ /**
7
+ * List grants
8
+ * @example
9
+ * const grant = await openmeter.grants.list()
10
+ */
11
+ async list(params, options) {
12
+ const searchParams = params
13
+ ? BaseClient.toURLSearchParams(params)
14
+ : undefined;
15
+ return await this.request({
16
+ path: '/api/v1/grants',
17
+ method: 'GET',
18
+ searchParams,
19
+ options,
20
+ });
21
+ }
22
+ /**
23
+ * Void a grant
24
+ * @description
25
+ * Voiding a grant means it is no longer valid, it doesn't take part in further balance calculations. Voiding a grant does not retroactively take effect, meaning any usage that has already been attributed to the grant will remain, but future usage cannot be burnt down from the grant.
26
+ * @example
27
+ * const grant = await openmeter.grants.list()
28
+ */
29
+ async delete(id, options) {
30
+ return await this.request({
31
+ method: 'DELETE',
32
+ path: `/api/v1/grants/${id}`,
33
+ options,
34
+ });
35
+ }
36
+ }
37
+ //# sourceMappingURL=grant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grant.js","sourceRoot":"","sources":["../../clients/grant.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,UAAU,EAAmB,MAAM,aAAa,CAAA;AAWzE,MAAM,OAAO,WAAY,SAAQ,UAAU;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,UAAU,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;IAED;;;;;;OAMG;IACI,KAAK,CAAC,MAAM,CACjB,EAAU,EACV,OAAwB;QAExB,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC;YACxB,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,kBAAkB,EAAE,EAAE;YAC5B,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -12,36 +12,6 @@ export declare enum MeterAggregation {
12
12
  MIN = "MIN",
13
13
  MAX = "MAX"
14
14
  }
15
- export type MeterValuesParams = {
16
- /**
17
- * @description Subject(s) to filter by.
18
- * @example ["customer-1", "customer-2"]
19
- */
20
- subject?: string;
21
- /**
22
- * @description Start date.
23
- * Must be aligned with the window size.
24
- * Inclusive.
25
- */
26
- from?: Date;
27
- /**
28
- * @description End date.
29
- * Must be aligned with the window size.
30
- * Inclusive.
31
- */
32
- to?: Date;
33
- /**
34
- * @description Window Size
35
- * If not specified, a single usage aggregate will be returned for the entirety of
36
- * the specified period for each subject and group.
37
- */
38
- windowSize?: WindowSizeType;
39
- /**
40
- * @description Group By
41
- * If not specified a single aggregate will be returned for each subject and time window.
42
- */
43
- groupBy?: string[];
44
- };
45
15
  export type MeterQueryParams = {
46
16
  /**
47
17
  * @description Subject(s) to filter by.
@@ -66,17 +36,30 @@ export type MeterQueryParams = {
66
36
  * the specified period for each subject and group.
67
37
  */
68
38
  windowSize?: WindowSizeType;
39
+ /**
40
+ * @description The value is the name of the time zone as defined in the IANA Time Zone Database (http://www.iana.org/time-zones).
41
+ * If not specified, the UTC timezone will be used.
42
+ */
43
+ windowTimeZone?: string;
69
44
  /**
70
45
  * @description Group By
71
46
  * If not specified a single aggregate will be returned for each subject and time window.
72
47
  */
73
48
  groupBy?: string[];
49
+ /**
50
+ * @description Filter by group by
51
+ */
52
+ filterGroupBy?: Record<string, string>;
74
53
  };
75
54
  export type MeterQueryResponse = paths['/api/v1/meters/{meterIdOrSlug}/query']['get']['responses']['200']['content']['application/json'];
76
55
  export type Meter = components['schemas']['Meter'];
77
56
  export type WindowSizeType = components['schemas']['WindowSize'];
78
57
  export declare class MetersClient extends BaseClient {
79
58
  constructor(config: OpenMeterConfig);
59
+ /**
60
+ * Create a meter
61
+ */
62
+ create(meter: Meter, options?: RequestOptions): Promise<Meter>;
80
63
  /**
81
64
  * Get one meter by slug
82
65
  */
@@ -17,6 +17,20 @@ export class MetersClient extends BaseClient {
17
17
  constructor(config) {
18
18
  super(config);
19
19
  }
20
+ /**
21
+ * Create a meter
22
+ */
23
+ async create(meter, options) {
24
+ return this.request({
25
+ method: 'POST',
26
+ path: `/api/v1/meters`,
27
+ headers: {
28
+ 'Content-Type': 'application/json',
29
+ },
30
+ body: JSON.stringify(meter),
31
+ options,
32
+ });
33
+ }
20
34
  /**
21
35
  * Get one meter by slug
22
36
  */
@@ -62,3 +76,4 @@ export class MetersClient extends BaseClient {
62
76
  });
63
77
  }
64
78
  }
79
+ //# sourceMappingURL=meter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meter.js","sourceRoot":"","sources":["../../clients/meter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAmC,MAAM,aAAa,CAAA;AAEzE,MAAM,CAAN,IAAY,UAIX;AAJD,WAAY,UAAU;IACpB,+BAAiB,CAAA;IACjB,2BAAa,CAAA;IACb,yBAAW,CAAA;AACb,CAAC,EAJW,UAAU,KAAV,UAAU,QAIrB;AAED,MAAM,CAAN,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC1B,+BAAW,CAAA;IACX,mCAAe,CAAA;IACf,+BAAW,CAAA;IACX,+BAAW,CAAA;IACX,+BAAW,CAAA;AACb,CAAC,EANW,gBAAgB,KAAhB,gBAAgB,QAM3B;AAgDD,MAAM,OAAO,YAAa,SAAQ,UAAU;IAC1C,YAAY,MAAuB;QACjC,KAAK,CAAC,MAAM,CAAC,CAAA;IACf,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,MAAM,CAAC,KAAY,EAAE,OAAwB;QACxD,OAAO,IAAI,CAAC,OAAO,CAAQ;YACzB,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;YAC3B,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,GAAG,CAAC,IAAY,EAAE,OAAwB;QACrD,OAAO,IAAI,CAAC,OAAO,CAAQ;YACzB,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,kBAAkB,IAAI,EAAE;YAC9B,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAI,CAAC,OAAwB;QACxC,OAAO,IAAI,CAAC,OAAO,CAAU;YAC3B,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,gBAAgB;YACtB,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,KAAK,CAChB,IAAY,EACZ,MAAyB,EACzB,OAAwB;QAExB,MAAM,YAAY,GAAG,MAAM;YACzB,CAAC,CAAC,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC;YACtC,CAAC,CAAC,SAAS,CAAA;QACb,OAAO,IAAI,CAAC,OAAO,CAAqB;YACtC,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,kBAAkB,IAAI,QAAQ;YACpC,YAAY;YACZ,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ,CACnB,IAAY,EACZ,OAAwB;QAExB,OAAO,IAAI,CAAC,OAAO,CAAW;YAC5B,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,kBAAkB,IAAI,WAAW;YACvC,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ export interface Paginated<T> {
2
+ items: T[];
3
+ totalCount: number;
4
+ page: number;
5
+ pageSize: number;
6
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=pagination.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.js","sourceRoot":"","sources":["../../clients/pagination.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ import { components } from '../schemas/openapi.js';
2
+ import { RequestOptions, BaseClient, OpenMeterConfig } from './client.js';
3
+ export type PortalToken = components['schemas']['PortalToken'];
4
+ export declare class PortalClient extends BaseClient {
5
+ constructor(config: OpenMeterConfig);
6
+ /**
7
+ * Create portal token
8
+ * Useful for creating a token sharable with your customer to query their own usage
9
+ */
10
+ createToken(token: {
11
+ subject: string;
12
+ expiresAt?: Date;
13
+ allowedMeterSlugs?: string[];
14
+ }, options?: RequestOptions): Promise<PortalToken>;
15
+ /**
16
+ * Invalidate portal token
17
+ * @note OpenMeter Cloud only feature
18
+ */
19
+ invalidateTokens(invalidate?: {
20
+ subject?: string;
21
+ }, options?: RequestOptions): Promise<void>;
22
+ }
@@ -0,0 +1,37 @@
1
+ import { BaseClient } from './client.js';
2
+ export class PortalClient extends BaseClient {
3
+ constructor(config) {
4
+ super(config);
5
+ }
6
+ /**
7
+ * Create portal token
8
+ * Useful for creating a token sharable with your customer to query their own usage
9
+ */
10
+ async createToken(token, options) {
11
+ return await this.request({
12
+ path: '/api/v1/portal/tokens',
13
+ method: 'POST',
14
+ headers: {
15
+ 'Content-Type': 'application/json',
16
+ },
17
+ body: JSON.stringify(token),
18
+ options,
19
+ });
20
+ }
21
+ /**
22
+ * Invalidate portal token
23
+ * @note OpenMeter Cloud only feature
24
+ */
25
+ async invalidateTokens(invalidate = {}, options) {
26
+ return await this.request({
27
+ path: '/api/v1/portal/tokens/invalidate',
28
+ method: 'POST',
29
+ headers: {
30
+ 'Content-Type': 'application/json',
31
+ },
32
+ body: JSON.stringify(invalidate),
33
+ options,
34
+ });
35
+ }
36
+ }
37
+ //# sourceMappingURL=portal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal.js","sourceRoot":"","sources":["../../clients/portal.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,UAAU,EAAmB,MAAM,aAAa,CAAA;AAIzE,MAAM,OAAO,YAAa,SAAQ,UAAU;IAC1C,YAAY,MAAuB;QACjC,KAAK,CAAC,MAAM,CAAC,CAAA;IACf,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,WAAW,CACtB,KAIC,EACD,OAAwB;QAExB,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC;YACxB,IAAI,EAAE,uBAAuB;YAC7B,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;;;OAGG;IACI,KAAK,CAAC,gBAAgB,CAC3B,aAAmC,EAAE,EACrC,OAAwB;QAExB,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC;YACxB,IAAI,EAAE,kCAAkC;YACxC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;YAChC,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,125 @@
1
+ import { components } from '../schemas/openapi.js';
2
+ import { RequestOptions, BaseClient, OpenMeterConfig } from './client.js';
3
+ import { Entitlement, EntitlementCreateInputs, EntitlementResetInputs, EntitlementValue, GetEntitlementHistoryQueryParams, ListEntitlementQueryParams, WindowedBalanceHistory } from './entitlement.js';
4
+ import { EntitlementGrant, EntitlementGrantCreateInput, ListEntitlementGrantQueryParams } from './grant.js';
5
+ export type Subject = components['schemas']['Subject'];
6
+ export declare class SubjectClient extends BaseClient {
7
+ constructor(config: OpenMeterConfig);
8
+ /**
9
+ * Upsert subject
10
+ * Useful to map display name and metadata to subjects
11
+ * @note OpenMeter Cloud only feature
12
+ */
13
+ upsert(subject: Omit<Subject, 'id'>[], options?: RequestOptions): Promise<Subject[]>;
14
+ /**
15
+ * Get subject by id or key
16
+ * @note OpenMeter Cloud only feature
17
+ */
18
+ get(idOrKey: string, options?: RequestOptions): Promise<Subject>;
19
+ /**
20
+ * List subjects
21
+ * @note OpenMeter Cloud only feature
22
+ */
23
+ list(options?: RequestOptions): Promise<Subject[]>;
24
+ /**
25
+ * Delete subject by id or key
26
+ * @note OpenMeter Cloud only feature
27
+ */
28
+ delete(idOrKey: string, options?: RequestOptions): Promise<void>;
29
+ /** Entitlements **/
30
+ /**
31
+ * Create Entitlement
32
+ * Entitlements allows you to manage subject feature access, balances, and usage limits.
33
+ * @remarks
34
+ * Input should be either `EntitlementMeteredCreateInputs`, `EntitlementStaticCreateInputs`, or `EntitlementBooleanCreateInputs`
35
+ * @example
36
+ * // Issue 10,000,000 tokens every month
37
+ * const entitlement = await openmeter.subjects.createEntitlement('customer-1', {
38
+ * type: 'metered',
39
+ * featureKey: 'ai_tokens',
40
+ * usagePeriod: {
41
+ * interval: 'MONTH',
42
+ * },
43
+ * issueAfterReset: 10000000,
44
+ * })
45
+ */
46
+ createEntitlement(subjectIdOrKey: string, input: EntitlementCreateInputs, options?: RequestOptions): Promise<Entitlement>;
47
+ /**
48
+ * List entitlements of a subject
49
+ * @example
50
+ * const entitlement = await openmeter.subjects.listEntitlements('customer-1')
51
+ */
52
+ listEntitlements(subjectIdOrKey: string, params?: ListEntitlementQueryParams, options?: RequestOptions): Promise<Entitlement[]>;
53
+ /**
54
+ * Get entitlement
55
+ *
56
+ * @example
57
+ * const entitlement = await openmeter.subjects.getEntitlement('customer-1', '01J1SD3QDV86GP77TQ4PZZ4EXE')
58
+ */
59
+ getEntitlement(subjectIdOrKey: string, entitlementId: string, options?: RequestOptions): Promise<Entitlement>;
60
+ /**
61
+ * Delete entitlement
62
+ * @example
63
+ * await openmeter.deleteEntitlement('customer-1', '01J1SD3QDV86GP77TQ4PZZ4EXE')
64
+ */
65
+ deleteEntitlement(subjectIdOrKey: string, entitlementId: string, options?: RequestOptions): Promise<void>;
66
+ /**
67
+ * Get entitlement value by ID or Feature Key
68
+ *
69
+ * @example
70
+ * const value = await openmeter.subjects.getEntitlementValue('customer-1', 'ai_tokens')
71
+ */
72
+ getEntitlementValue(subjectIdOrKey: string, entitlementIdOrFeatureKey: string, options?: RequestOptions): Promise<EntitlementValue>;
73
+ /**
74
+ * Get entitlement value at a specific time.
75
+ *
76
+ * @example
77
+ * const value = await openmeter.subjects.getEntitlementValueAt('customer-1', 'ai_tokens', new Date('2024-01-01'))
78
+ */
79
+ getEntitlementValueAt(subjectIdOrKey: string, entitlementIdOrFeatureKey: string, at: Date, options?: RequestOptions): Promise<EntitlementValue>;
80
+ /**
81
+ * Get entitlement history
82
+ * @example
83
+ * const entitlement = await openmeter.subjects.getEntitlementHistory('customer-1', '01J1SD3QDV86GP77TQ4PZZ4EXE')
84
+ */
85
+ getEntitlementHistory(subjectIdOrKey: string, entitlementId: string, params?: GetEntitlementHistoryQueryParams, options?: RequestOptions): Promise<WindowedBalanceHistory[]>;
86
+ /**
87
+ * Reset Entitlement Usage
88
+ * Reset the entitlement usage and start a new period. Eligible grants will be rolled over
89
+ *
90
+ * @example
91
+ * const entitlement = await openmeter.subjects.resetEntitlementUsage('customer-1', '01J1SD3QDV86GP77TQ4PZZ4EXE', {
92
+ * retainAnchor: true
93
+ * })
94
+ */
95
+ resetEntitlementUsage(subjectIdOrKey: string, entitlementId: string, input: EntitlementResetInputs, options?: RequestOptions): Promise<Entitlement>;
96
+ /** Entitlement Grant **/
97
+ /**
98
+ * Create Entitlement Grant
99
+ * Create a grant for an entitlement.
100
+ *
101
+ * @example
102
+ * const grant = await openmeter.subjects.createEntitlementGrant('customer-1', '01J1SD3QDV86GP77TQ4PZZ4EXE', {
103
+ * amount: 100,
104
+ * priority: 1,
105
+ * effectiveAt: '2023-01-01T00:00:00Z',
106
+ * expiration: {
107
+ * duration: 'HOUR',
108
+ * count: 12,
109
+ * },
110
+ * minRolloverAmount: 100,
111
+ * maxRolloverAmount: 100,
112
+ * recurrence: {
113
+ * interval: 'MONTH',
114
+ * anchor: '2024-06-28T18:29:44.867Z',
115
+ * },
116
+ * })
117
+ */
118
+ createEntitlementGrant(subjectIdOrKey: string, entitlementIdOrFeatureKey: string, input: EntitlementGrantCreateInput, options?: RequestOptions): Promise<EntitlementGrant>;
119
+ /**
120
+ * List entitlement grants
121
+ * @example
122
+ * const entitlement = await openmeter.subjects.listEntitlementGrants('customer-1', '01J1SD3QDV86GP77TQ4PZZ4EXE')
123
+ */
124
+ listEntitlementGrants(subjectIdOrKey: string, entitlementIdOrFeatureKey: string, params?: ListEntitlementGrantQueryParams, options?: RequestOptions): Promise<EntitlementGrant[]>;
125
+ }