@openmeter/sdk 1.0.0-beta.1 → 1.0.0-beta.101

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 (81) hide show
  1. package/README.md +276 -26
  2. package/dist/cjs/clients/client.cjs +120 -0
  3. package/dist/cjs/clients/client.d.cts +40 -0
  4. package/dist/cjs/clients/client.js.map +1 -0
  5. package/dist/cjs/clients/entitlement.cjs +27 -0
  6. package/dist/cjs/clients/entitlement.d.cts +25 -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 +75 -0
  12. package/dist/cjs/clients/feature.d.cts +40 -0
  13. package/dist/cjs/clients/feature.js.map +1 -0
  14. package/dist/cjs/clients/grant.cjs +27 -0
  15. package/dist/cjs/clients/grant.d.cts +15 -0
  16. package/dist/cjs/clients/grant.js.map +1 -0
  17. package/dist/cjs/clients/meter.cjs +69 -0
  18. package/dist/cjs/clients/meter.d.cts +75 -0
  19. package/dist/cjs/clients/meter.js.map +1 -0
  20. package/dist/cjs/clients/portal.cjs +41 -0
  21. package/dist/cjs/clients/portal.d.cts +22 -0
  22. package/dist/cjs/clients/portal.js.map +1 -0
  23. package/dist/cjs/clients/subject.cjs +226 -0
  24. package/dist/cjs/clients/subject.d.cts +117 -0
  25. package/dist/cjs/clients/subject.js.map +1 -0
  26. package/dist/cjs/index.cjs +33 -0
  27. package/dist/cjs/index.d.cts +21 -0
  28. package/dist/cjs/index.js.map +1 -0
  29. package/dist/cjs/schemas/openapi.cjs +7 -0
  30. package/dist/cjs/schemas/openapi.d.cts +2078 -0
  31. package/dist/cjs/schemas/openapi.js.map +1 -0
  32. package/dist/cjs/test/agent.cjs +470 -0
  33. package/dist/cjs/test/agent.d.cts +2 -0
  34. package/dist/cjs/test/agent.js.map +1 -0
  35. package/dist/cjs/test/mocks.cjs +152 -0
  36. package/dist/cjs/test/mocks.d.cts +25 -0
  37. package/dist/cjs/test/mocks.js.map +1 -0
  38. package/dist/cjs/tsconfig.68d5eed0.tsbuildinfo +1 -0
  39. package/dist/cjs/tsconfig.ae38b1d6.tsbuildinfo +1 -0
  40. package/dist/clients/client.d.ts +3 -3
  41. package/dist/clients/client.js +24 -10
  42. package/dist/clients/client.js.map +1 -0
  43. package/dist/clients/entitlement.d.ts +25 -0
  44. package/dist/clients/entitlement.js +23 -0
  45. package/dist/clients/entitlement.js.map +1 -0
  46. package/dist/clients/event.d.ts +16 -2
  47. package/dist/clients/event.js +44 -18
  48. package/dist/clients/event.js.map +1 -0
  49. package/dist/clients/feature.d.ts +40 -0
  50. package/dist/clients/feature.js +71 -0
  51. package/dist/clients/feature.js.map +1 -0
  52. package/dist/clients/grant.d.ts +15 -0
  53. package/dist/clients/grant.js +23 -0
  54. package/dist/clients/grant.js.map +1 -0
  55. package/dist/clients/meter.d.ts +30 -7
  56. package/dist/clients/meter.js +17 -4
  57. package/dist/clients/meter.js.map +1 -0
  58. package/dist/clients/portal.d.ts +22 -0
  59. package/dist/clients/portal.js +37 -0
  60. package/dist/clients/portal.js.map +1 -0
  61. package/dist/clients/subject.d.ts +117 -0
  62. package/dist/clients/subject.js +222 -0
  63. package/dist/clients/subject.js.map +1 -0
  64. package/dist/index.d.ts +12 -2
  65. package/dist/index.js +16 -0
  66. package/dist/index.js.map +1 -0
  67. package/dist/schemas/openapi.d.ts +1876 -212
  68. package/dist/schemas/openapi.js +1 -0
  69. package/dist/schemas/openapi.js.map +1 -0
  70. package/dist/test/agent.js +394 -32
  71. package/dist/test/agent.js.map +1 -0
  72. package/dist/test/mocks.d.ts +15 -1
  73. package/dist/test/mocks.js +136 -8
  74. package/dist/test/mocks.js.map +1 -0
  75. package/dist/tsconfig.tsbuildinfo +1 -1
  76. package/package.json +65 -51
  77. package/clients/client.ts +0 -153
  78. package/clients/event.ts +0 -109
  79. package/clients/meter.ts +0 -84
  80. package/index.ts +0 -17
  81. package/schemas/openapi.ts +0 -421
@@ -0,0 +1,40 @@
1
+ import { components, operations } from '../schemas/openapi.js';
2
+ import { RequestOptions, BaseClient, OpenMeterConfig } from './client.js';
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,71 @@
1
+ import { BaseClient } from './client.js';
2
+ export class FeatureClient extends BaseClient {
3
+ constructor(config) {
4
+ super(config);
5
+ }
6
+ /**
7
+ * Create Feature
8
+ * Features are the building blocks of your entitlements, part of your product offering.
9
+ *
10
+ * @example
11
+ * const feature = await openmeter.features.create({
12
+ * key: 'ai_tokens',
13
+ * name: 'AI Tokens',
14
+ * // optional
15
+ * meterSlug: 'tokens_total',
16
+ * })
17
+ */
18
+ async create(input, options) {
19
+ return await this.request({
20
+ path: '/api/v1/features',
21
+ method: 'POST',
22
+ headers: {
23
+ 'Content-Type': 'application/json',
24
+ },
25
+ body: JSON.stringify(input),
26
+ options,
27
+ });
28
+ }
29
+ /**
30
+ * Get Feature by ID or Key
31
+ *
32
+ * @example
33
+ * const feature = await openmeter.features.get('ai_tokens')
34
+ */
35
+ async get(idOrKey, options) {
36
+ return await this.request({
37
+ path: `/api/v1/features/${idOrKey}`,
38
+ method: 'GET',
39
+ options,
40
+ });
41
+ }
42
+ /**
43
+ * List features
44
+ * @example
45
+ * const feature = await openmeter.features.list()
46
+ */
47
+ async list(params, options) {
48
+ const searchParams = params
49
+ ? BaseClient.toURLSearchParams(params)
50
+ : undefined;
51
+ return await this.request({
52
+ path: '/api/v1/features',
53
+ method: 'GET',
54
+ searchParams,
55
+ options,
56
+ });
57
+ }
58
+ /**
59
+ * Delete feature by ID or Key
60
+ * @example
61
+ * await openmeter.delete('ai_tokens')
62
+ */
63
+ async delete(idOrKey, options) {
64
+ return await this.request({
65
+ path: `/api/v1/features/${idOrKey}`,
66
+ method: 'DELETE',
67
+ options,
68
+ });
69
+ }
70
+ }
71
+ //# 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;AAOzE,MAAM,OAAO,aAAc,SAAQ,UAAU;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,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;;;;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"}
@@ -0,0 +1,15 @@
1
+ import { components, operations } from '../schemas/openapi.js';
2
+ import { RequestOptions, BaseClient, OpenMeterConfig } from './client.js';
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,23 @@
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
+ //# 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;AAUzE,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;CACF"}
@@ -13,7 +13,11 @@ export declare enum MeterAggregation {
13
13
  MAX = "MAX"
14
14
  }
15
15
  export type MeterQueryParams = {
16
- subject?: string;
16
+ /**
17
+ * @description Subject(s) to filter by.
18
+ * @example ["customer-1", "customer-2"]
19
+ */
20
+ subject?: string[];
17
21
  /**
18
22
  * @description Start date.
19
23
  * Must be aligned with the window size.
@@ -26,13 +30,28 @@ export type MeterQueryParams = {
26
30
  * Inclusive.
27
31
  */
28
32
  to?: Date;
29
- /** @description If not specified, a single usage aggregate will be returned for the entirety of the specified period for each subject and group. */
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
+ */
30
38
  windowSize?: WindowSizeType;
31
- /** @description If not specified a single aggregate will be returned for each subject and time window. */
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;
44
+ /**
45
+ * @description Group By
46
+ * If not specified a single aggregate will be returned for each subject and time window.
47
+ */
32
48
  groupBy?: string[];
49
+ /**
50
+ * @description Filter by group by
51
+ */
52
+ filterGroupBy?: Record<string, string>;
33
53
  };
34
- export type MeterQueryResponse = paths['/api/v1/meters/{meterIdOrSlug}/values']['get']['responses']['200']['content']['application/json'];
35
- export type MeterValue = components['schemas']['MeterValue'];
54
+ export type MeterQueryResponse = paths['/api/v1/meters/{meterIdOrSlug}/query']['get']['responses']['200']['content']['application/json'];
36
55
  export type Meter = components['schemas']['Meter'];
37
56
  export type WindowSizeType = components['schemas']['WindowSize'];
38
57
  export declare class MetersClient extends BaseClient {
@@ -46,7 +65,11 @@ export declare class MetersClient extends BaseClient {
46
65
  */
47
66
  list(options?: RequestOptions): Promise<Meter[]>;
48
67
  /**
49
- * Get aggregated values of a meter
68
+ * Query a meter
69
+ */
70
+ query(slug: string, params?: MeterQueryParams, options?: RequestOptions): Promise<MeterQueryResponse>;
71
+ /**
72
+ * List subjects of a meter
50
73
  */
51
- values(slug: string, params?: MeterQueryParams, options?: RequestOptions): Promise<MeterQueryResponse>;
74
+ subjects(slug: string, options?: RequestOptions): Promise<string[]>;
52
75
  }
@@ -38,15 +38,28 @@ export class MetersClient extends BaseClient {
38
38
  });
39
39
  }
40
40
  /**
41
- * Get aggregated values of a meter
41
+ * Query a meter
42
42
  */
43
- async values(slug, params, options) {
44
- const searchParams = params ? BaseClient.toURLSearchParams(params) : undefined;
43
+ async query(slug, params, options) {
44
+ const searchParams = params
45
+ ? BaseClient.toURLSearchParams(params)
46
+ : undefined;
45
47
  return this.request({
46
48
  method: 'GET',
47
- path: `/api/v1/meters/${slug}/values`,
49
+ path: `/api/v1/meters/${slug}/query`,
48
50
  searchParams,
49
51
  options,
50
52
  });
51
53
  }
54
+ /**
55
+ * List subjects of a meter
56
+ */
57
+ async subjects(slug, options) {
58
+ return this.request({
59
+ method: 'GET',
60
+ path: `/api/v1/meters/${slug}/subjects`,
61
+ options,
62
+ });
63
+ }
52
64
  }
65
+ //# 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,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,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,117 @@
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
+ *
34
+ * @example
35
+ * // Issue 10,000,000 tokens every month
36
+ * const entitlement = await openmeter.subjects.createEntitlement('customer-1', {
37
+ * type: 'metered',
38
+ * featureKey: 'ai_tokens',
39
+ * usagePeriod: {
40
+ * interval: 'MONTH',
41
+ * },
42
+ * issueAfterReset: 10000000,
43
+ * })
44
+ */
45
+ createEntitlement(subjectIdOrKey: string, input: EntitlementCreateInputs, options?: RequestOptions): Promise<Entitlement>;
46
+ /**
47
+ * List entitlements
48
+ * @example
49
+ * const entitlement = await openmeter.subjects.listEntitlements('customer-1')
50
+ */
51
+ listEntitlements(subjectIdOrKey: string, params?: ListEntitlementQueryParams, options?: RequestOptions): Promise<Entitlement[]>;
52
+ /**
53
+ * Get entitlement by ID by Feature ID or by Feature Key
54
+ *
55
+ * @example
56
+ * const entitlement = await openmeter.subjects.getEntitlement('customer-1', 'ai_tokens')
57
+ */
58
+ getEntitlement(subjectIdOrKey: string, entitlementIdOrFeatureIdOrFeatureKey: string, options?: RequestOptions): Promise<Entitlement>;
59
+ /**
60
+ * Delete entitlement by ID by Feature ID or by Feature Key
61
+ * @example
62
+ * await openmeter.deleteEntitlement('customer-1', 'ai_tokens')
63
+ */
64
+ deleteEntitlement(subjectIdOrKey: string, entitlementIdOrFeatureIdOrFeatureKey: string, options?: RequestOptions): Promise<void>;
65
+ /**
66
+ * Get entitlement value by ID by Feature ID or by Feature Key
67
+ *
68
+ * @example
69
+ * const value = await openmeter.subjects.getEntitlementValue('customer-1', 'ai_tokens')
70
+ */
71
+ getEntitlementValue(subjectIdOrKey: string, entitlementIdOrFeatureIdOrFeatureKey: string, options?: RequestOptions): Promise<EntitlementValue>;
72
+ /**
73
+ * Get entitlement history by ID by Feature ID or by Feature Key
74
+ * @example
75
+ * const entitlement = await openmeter.subjects.getEntitlementHistory('customer-1', 'ai_tokens')
76
+ */
77
+ getEntitlementHistory(subjectIdOrKey: string, entitlementIdOrFeatureIdOrFeatureKey: string, params?: GetEntitlementHistoryQueryParams, options?: RequestOptions): Promise<WindowedBalanceHistory[]>;
78
+ /**
79
+ * Reset Entitlement Usage
80
+ * Reset the entitlement usage and start a new period. Eligible grants will be rolled over
81
+ *
82
+ * @example
83
+ * const entitlement = await openmeter.subjects.resetEntitlementUsage('customer-1', 'ai_tokens', {
84
+ * retainAnchor: true
85
+ * })
86
+ */
87
+ resetEntitlementUsage(subjectIdOrKey: string, entitlementIdOrFeatureIdOrFeatureKey: string, input: EntitlementResetInputs, options?: RequestOptions): Promise<Entitlement>;
88
+ /** Entitlement Grant **/
89
+ /**
90
+ * Create Entitlement Grant
91
+ * Create a grant for an entitlement.
92
+ *
93
+ * @example
94
+ * const grant = await openmeter.subjects.createEntitlementGrant('customer-1', 'ai_tokens', {
95
+ * amount: 100,
96
+ * priority: 1,
97
+ * effectiveAt: '2023-01-01T00:00:00Z',
98
+ * expiration: {
99
+ * duration: 'HOUR',
100
+ * count: 12,
101
+ * },
102
+ * minRolloverAmount: 100,
103
+ * maxRolloverAmount: 100,
104
+ * recurrence: {
105
+ * interval: 'MONTH',
106
+ * anchor: '2024-06-28T18:29:44.867Z',
107
+ * },
108
+ * })
109
+ */
110
+ createEntitlementGrant(subjectIdOrKey: string, entitlementIdOrFeatureIdOrFeatureKey: string, input: EntitlementGrantCreateInput, options?: RequestOptions): Promise<EntitlementGrant>;
111
+ /**
112
+ * List entitlement grants
113
+ * @example
114
+ * const entitlement = await openmeter.subjects.listEntitlementGrants('customer-1', 'ai_tokens)
115
+ */
116
+ listEntitlementGrants(subjectIdOrKey: string, entitlementIdOrFeatureIdOrFeatureKey: string, params?: ListEntitlementGrantQueryParams, options?: RequestOptions): Promise<EntitlementGrant[]>;
117
+ }
@@ -0,0 +1,222 @@
1
+ import { BaseClient } from './client.js';
2
+ export class SubjectClient extends BaseClient {
3
+ constructor(config) {
4
+ super(config);
5
+ }
6
+ /**
7
+ * Upsert subject
8
+ * Useful to map display name and metadata to subjects
9
+ * @note OpenMeter Cloud only feature
10
+ */
11
+ async upsert(subject, options) {
12
+ return await this.request({
13
+ path: '/api/v1/subjects',
14
+ method: 'POST',
15
+ headers: {
16
+ 'Content-Type': 'application/json',
17
+ },
18
+ body: JSON.stringify(subject),
19
+ options,
20
+ });
21
+ }
22
+ /**
23
+ * Get subject by id or key
24
+ * @note OpenMeter Cloud only feature
25
+ */
26
+ async get(idOrKey, options) {
27
+ return await this.request({
28
+ path: `/api/v1/subjects/${idOrKey}`,
29
+ method: 'GET',
30
+ options,
31
+ });
32
+ }
33
+ /**
34
+ * List subjects
35
+ * @note OpenMeter Cloud only feature
36
+ */
37
+ async list(options) {
38
+ return await this.request({
39
+ path: '/api/v1/subjects',
40
+ method: 'GET',
41
+ options,
42
+ });
43
+ }
44
+ /**
45
+ * Delete subject by id or key
46
+ * @note OpenMeter Cloud only feature
47
+ */
48
+ async delete(idOrKey, options) {
49
+ return await this.request({
50
+ path: `/api/v1/subjects/${idOrKey}`,
51
+ method: 'DELETE',
52
+ options,
53
+ });
54
+ }
55
+ /** Entitlements **/
56
+ /**
57
+ * Create Entitlement
58
+ * Entitlements allows you to manage subject feature access, balances, and usage limits.
59
+ *
60
+ * @example
61
+ * // Issue 10,000,000 tokens every month
62
+ * const entitlement = await openmeter.subjects.createEntitlement('customer-1', {
63
+ * type: 'metered',
64
+ * featureKey: 'ai_tokens',
65
+ * usagePeriod: {
66
+ * interval: 'MONTH',
67
+ * },
68
+ * issueAfterReset: 10000000,
69
+ * })
70
+ */
71
+ async createEntitlement(subjectIdOrKey, input, options) {
72
+ return await this.request({
73
+ path: `/api/v1/subjects/${subjectIdOrKey}/entitlements`,
74
+ method: 'POST',
75
+ headers: {
76
+ 'Content-Type': 'application/json',
77
+ },
78
+ body: JSON.stringify(input),
79
+ options,
80
+ });
81
+ }
82
+ /**
83
+ * List entitlements
84
+ * @example
85
+ * const entitlement = await openmeter.subjects.listEntitlements('customer-1')
86
+ */
87
+ async listEntitlements(subjectIdOrKey, params, options) {
88
+ const searchParams = params
89
+ ? BaseClient.toURLSearchParams(params)
90
+ : undefined;
91
+ return await this.request({
92
+ path: `/api/v1/subjects/${subjectIdOrKey}/entitlements`,
93
+ method: 'GET',
94
+ searchParams,
95
+ options,
96
+ });
97
+ }
98
+ /**
99
+ * Get entitlement by ID by Feature ID or by Feature Key
100
+ *
101
+ * @example
102
+ * const entitlement = await openmeter.subjects.getEntitlement('customer-1', 'ai_tokens')
103
+ */
104
+ async getEntitlement(subjectIdOrKey, entitlementIdOrFeatureIdOrFeatureKey, options) {
105
+ return await this.request({
106
+ path: `/api/v1/subjects/${subjectIdOrKey}/entitlements/${entitlementIdOrFeatureIdOrFeatureKey}`,
107
+ method: 'GET',
108
+ options,
109
+ });
110
+ }
111
+ /**
112
+ * Delete entitlement by ID by Feature ID or by Feature Key
113
+ * @example
114
+ * await openmeter.deleteEntitlement('customer-1', 'ai_tokens')
115
+ */
116
+ async deleteEntitlement(subjectIdOrKey, entitlementIdOrFeatureIdOrFeatureKey, options) {
117
+ return await this.request({
118
+ path: `/api/v1/subjects/${subjectIdOrKey}/entitlements/${entitlementIdOrFeatureIdOrFeatureKey}`,
119
+ method: 'DELETE',
120
+ options,
121
+ });
122
+ }
123
+ /**
124
+ * Get entitlement value by ID by Feature ID or by Feature Key
125
+ *
126
+ * @example
127
+ * const value = await openmeter.subjects.getEntitlementValue('customer-1', 'ai_tokens')
128
+ */
129
+ async getEntitlementValue(subjectIdOrKey, entitlementIdOrFeatureIdOrFeatureKey, options) {
130
+ return await this.request({
131
+ path: `/api/v1/subjects/${subjectIdOrKey}/entitlements/${entitlementIdOrFeatureIdOrFeatureKey}/value`,
132
+ method: 'GET',
133
+ options,
134
+ });
135
+ }
136
+ /**
137
+ * Get entitlement history by ID by Feature ID or by Feature Key
138
+ * @example
139
+ * const entitlement = await openmeter.subjects.getEntitlementHistory('customer-1', 'ai_tokens')
140
+ */
141
+ async getEntitlementHistory(subjectIdOrKey, entitlementIdOrFeatureIdOrFeatureKey, params, options) {
142
+ const searchParams = params
143
+ ? BaseClient.toURLSearchParams(params)
144
+ : undefined;
145
+ return await this.request({
146
+ path: `/api/v1/subjects/${subjectIdOrKey}/entitlements/${entitlementIdOrFeatureIdOrFeatureKey}/history`,
147
+ method: 'GET',
148
+ searchParams,
149
+ options,
150
+ });
151
+ }
152
+ /**
153
+ * Reset Entitlement Usage
154
+ * Reset the entitlement usage and start a new period. Eligible grants will be rolled over
155
+ *
156
+ * @example
157
+ * const entitlement = await openmeter.subjects.resetEntitlementUsage('customer-1', 'ai_tokens', {
158
+ * retainAnchor: true
159
+ * })
160
+ */
161
+ async resetEntitlementUsage(subjectIdOrKey, entitlementIdOrFeatureIdOrFeatureKey, input, options) {
162
+ return await this.request({
163
+ path: `/api/v1/subjects/${subjectIdOrKey}/entitlements/${entitlementIdOrFeatureIdOrFeatureKey}/reset`,
164
+ method: 'POST',
165
+ headers: {
166
+ 'Content-Type': 'application/json',
167
+ },
168
+ body: JSON.stringify(input),
169
+ options,
170
+ });
171
+ }
172
+ /** Entitlement Grant **/
173
+ /**
174
+ * Create Entitlement Grant
175
+ * Create a grant for an entitlement.
176
+ *
177
+ * @example
178
+ * const grant = await openmeter.subjects.createEntitlementGrant('customer-1', 'ai_tokens', {
179
+ * amount: 100,
180
+ * priority: 1,
181
+ * effectiveAt: '2023-01-01T00:00:00Z',
182
+ * expiration: {
183
+ * duration: 'HOUR',
184
+ * count: 12,
185
+ * },
186
+ * minRolloverAmount: 100,
187
+ * maxRolloverAmount: 100,
188
+ * recurrence: {
189
+ * interval: 'MONTH',
190
+ * anchor: '2024-06-28T18:29:44.867Z',
191
+ * },
192
+ * })
193
+ */
194
+ async createEntitlementGrant(subjectIdOrKey, entitlementIdOrFeatureIdOrFeatureKey, input, options) {
195
+ return await this.request({
196
+ path: `/api/v1/subjects/${subjectIdOrKey}/entitlements/${entitlementIdOrFeatureIdOrFeatureKey}/grants`,
197
+ method: 'POST',
198
+ headers: {
199
+ 'Content-Type': 'application/json',
200
+ },
201
+ body: JSON.stringify(input),
202
+ options,
203
+ });
204
+ }
205
+ /**
206
+ * List entitlement grants
207
+ * @example
208
+ * const entitlement = await openmeter.subjects.listEntitlementGrants('customer-1', 'ai_tokens)
209
+ */
210
+ async listEntitlementGrants(subjectIdOrKey, entitlementIdOrFeatureIdOrFeatureKey, params, options) {
211
+ const searchParams = params
212
+ ? BaseClient.toURLSearchParams(params)
213
+ : undefined;
214
+ return await this.request({
215
+ path: `/api/v1/subjects/${subjectIdOrKey}/entitlements/${entitlementIdOrFeatureIdOrFeatureKey}/grants`,
216
+ method: 'GET',
217
+ searchParams,
218
+ options,
219
+ });
220
+ }
221
+ }
222
+ //# sourceMappingURL=subject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subject.js","sourceRoot":"","sources":["../../clients/subject.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,UAAU,EAAmB,MAAM,aAAa,CAAA;AAkBzE,MAAM,OAAO,aAAc,SAAQ,UAAU;IAC3C,YAAY,MAAuB;QACjC,KAAK,CAAC,MAAM,CAAC,CAAA;IACf,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,MAAM,CACjB,OAA8B,EAC9B,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,OAAO,CAAC;YAC7B,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IAED;;;OAGG;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;;;OAGG;IACI,KAAK,CAAC,IAAI,CAAC,OAAwB;QACxC,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC;YACxB,IAAI,EAAE,kBAAkB;YACxB,MAAM,EAAE,KAAK;YACb,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IAED;;;OAGG;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;I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