@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.
- package/README.md +276 -26
- package/dist/cjs/clients/client.cjs +120 -0
- package/dist/cjs/clients/client.d.cts +40 -0
- package/dist/cjs/clients/client.js.map +1 -0
- 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/event.cjs +71 -0
- package/dist/cjs/clients/event.d.cts +79 -0
- package/dist/cjs/clients/event.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/meter.cjs +69 -0
- package/dist/cjs/clients/meter.d.cts +75 -0
- package/dist/cjs/clients/meter.js.map +1 -0
- package/dist/cjs/clients/portal.cjs +41 -0
- package/dist/cjs/clients/portal.d.cts +22 -0
- package/dist/cjs/clients/portal.js.map +1 -0
- package/dist/cjs/clients/subject.cjs +226 -0
- package/dist/cjs/clients/subject.d.cts +117 -0
- package/dist/cjs/clients/subject.js.map +1 -0
- package/dist/cjs/index.cjs +33 -0
- package/dist/cjs/index.d.cts +21 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/schemas/openapi.cjs +7 -0
- package/dist/cjs/schemas/openapi.d.cts +2078 -0
- package/dist/cjs/schemas/openapi.js.map +1 -0
- package/dist/cjs/test/agent.cjs +470 -0
- package/dist/cjs/test/agent.d.cts +2 -0
- package/dist/cjs/test/agent.js.map +1 -0
- package/dist/cjs/test/mocks.cjs +152 -0
- package/dist/cjs/test/mocks.d.cts +25 -0
- package/dist/cjs/test/mocks.js.map +1 -0
- package/dist/cjs/tsconfig.68d5eed0.tsbuildinfo +1 -0
- package/dist/cjs/tsconfig.ae38b1d6.tsbuildinfo +1 -0
- package/dist/clients/client.d.ts +3 -3
- package/dist/clients/client.js +24 -10
- package/dist/clients/client.js.map +1 -0
- 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/event.d.ts +16 -2
- package/dist/clients/event.js +44 -18
- package/dist/clients/event.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/meter.d.ts +30 -7
- package/dist/clients/meter.js +17 -4
- package/dist/clients/meter.js.map +1 -0
- package/dist/clients/portal.d.ts +22 -0
- package/dist/clients/portal.js +37 -0
- package/dist/clients/portal.js.map +1 -0
- package/dist/clients/subject.d.ts +117 -0
- package/dist/clients/subject.js +222 -0
- package/dist/clients/subject.js.map +1 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/schemas/openapi.d.ts +1876 -212
- package/dist/schemas/openapi.js +1 -0
- package/dist/schemas/openapi.js.map +1 -0
- package/dist/test/agent.js +394 -32
- package/dist/test/agent.js.map +1 -0
- package/dist/test/mocks.d.ts +15 -1
- package/dist/test/mocks.js +136 -8
- package/dist/test/mocks.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +65 -51
- package/clients/client.ts +0 -153
- package/clients/event.ts +0 -109
- package/clients/meter.ts +0 -84
- package/index.ts +0 -17
- package/schemas/openapi.ts +0 -421
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { components } from '../schemas/openapi.cjs';
|
|
2
|
+
import { RequestOptions, BaseClient, OpenMeterConfig } from './client.cjs';
|
|
3
|
+
export type CloudEvent = components['schemas']['Event'];
|
|
4
|
+
export type IngestedEvent = components['schemas']['IngestedEvent'];
|
|
5
|
+
export type EventsQueryParams = {
|
|
6
|
+
/**
|
|
7
|
+
* @description Limit number of results. Max: 100
|
|
8
|
+
* @example 25
|
|
9
|
+
*/
|
|
10
|
+
limit?: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Usage Event
|
|
14
|
+
*/
|
|
15
|
+
export type Event = {
|
|
16
|
+
/**
|
|
17
|
+
* @description The version of the CloudEvents specification which the event uses.
|
|
18
|
+
* @example 1.0
|
|
19
|
+
*/
|
|
20
|
+
specversion?: string;
|
|
21
|
+
/**
|
|
22
|
+
* @description Unique identifier for the event, defaults to uuid v4.
|
|
23
|
+
* @example "5c10fade-1c9e-4d6c-8275-c52c36731d3c"
|
|
24
|
+
*/
|
|
25
|
+
id?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Format: uri-reference
|
|
28
|
+
* @description Identifies the context in which an event happened, defaults to: @openmeter/sdk
|
|
29
|
+
* @example services/service-0
|
|
30
|
+
*/
|
|
31
|
+
source?: string;
|
|
32
|
+
/**
|
|
33
|
+
* @description Describes the type of event related to the originating occurrence.
|
|
34
|
+
* @example "api_request"
|
|
35
|
+
*/
|
|
36
|
+
type: string;
|
|
37
|
+
/**
|
|
38
|
+
* @description Describes the subject of the event in the context of the event producer (identified by source).
|
|
39
|
+
* @example "customer_id"
|
|
40
|
+
*/
|
|
41
|
+
subject: string;
|
|
42
|
+
/**
|
|
43
|
+
* Format: date-time
|
|
44
|
+
* @description Date of when the occurrence happened.
|
|
45
|
+
* @example new Date('2023-01-01T01:01:01.001Z')
|
|
46
|
+
*/
|
|
47
|
+
time?: Date;
|
|
48
|
+
/**
|
|
49
|
+
* Format: uri
|
|
50
|
+
* @description Identifies the schema that data adheres to.
|
|
51
|
+
*/
|
|
52
|
+
dataschema?: string;
|
|
53
|
+
/**
|
|
54
|
+
* @description Content type of the data value. Must adhere to RFC 2046 format.
|
|
55
|
+
* @example application/json
|
|
56
|
+
* @enum {string|null}
|
|
57
|
+
*/
|
|
58
|
+
datacontenttype?: 'application/json';
|
|
59
|
+
/**
|
|
60
|
+
* @description The event payload.
|
|
61
|
+
* @example {
|
|
62
|
+
* "duration_ms": "12",
|
|
63
|
+
* "path": "/hello"
|
|
64
|
+
* }
|
|
65
|
+
*/
|
|
66
|
+
data: Record<string, unknown>;
|
|
67
|
+
};
|
|
68
|
+
export declare class EventsClient extends BaseClient {
|
|
69
|
+
constructor(config: OpenMeterConfig);
|
|
70
|
+
/**
|
|
71
|
+
* Ingest usage event in a CloudEvents format
|
|
72
|
+
* @see https://cloudevents.io
|
|
73
|
+
*/
|
|
74
|
+
ingest(usageEvent: Event | Event[], options?: RequestOptions): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* List raw events
|
|
77
|
+
*/
|
|
78
|
+
list(params?: EventsQueryParams, options?: RequestOptions): Promise<IngestedEvent[]>;
|
|
79
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../../clients/event.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAE3B,2CAAyE;AAuEzE,MAAa,YAAa,SAAQ,sBAAU;IAC1C,YAAY,MAAuB;QACjC,KAAK,CAAC,MAAM,CAAC,CAAA;IACf,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,MAAM,CACjB,UAA2B,EAC3B,OAAwB;QAExB,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;QACzC,MAAM,WAAW,GAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CACzE,CAAC,EAAE,EAAE,EAAE;YACL,wBAAwB;YACxB,IAAI,EAAE,CAAC,eAAe,IAAI,EAAE,CAAC,eAAe,KAAK,kBAAkB,EAAE,CAAC;gBACpE,MAAM,IAAI,SAAS,CACjB,gCAAg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nC,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,gBAAgB;YACtB,YAAY;YACZ,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;CACF;AA5ED,oCA4EC"}
|
|
@@ -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"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MetersClient = exports.MeterAggregation = exports.WindowSize = void 0;
|
|
4
|
+
const client_js_1 = require("./client.cjs");
|
|
5
|
+
var WindowSize;
|
|
6
|
+
(function (WindowSize) {
|
|
7
|
+
WindowSize["MINUTE"] = "MINUTE";
|
|
8
|
+
WindowSize["HOUR"] = "HOUR";
|
|
9
|
+
WindowSize["DAY"] = "DAY";
|
|
10
|
+
})(WindowSize || (exports.WindowSize = WindowSize = {}));
|
|
11
|
+
var MeterAggregation;
|
|
12
|
+
(function (MeterAggregation) {
|
|
13
|
+
MeterAggregation["SUM"] = "SUM";
|
|
14
|
+
MeterAggregation["COUNT"] = "COUNT";
|
|
15
|
+
MeterAggregation["AVG"] = "AVG";
|
|
16
|
+
MeterAggregation["MIN"] = "MIN";
|
|
17
|
+
MeterAggregation["MAX"] = "MAX";
|
|
18
|
+
})(MeterAggregation || (exports.MeterAggregation = MeterAggregation = {}));
|
|
19
|
+
class MetersClient extends client_js_1.BaseClient {
|
|
20
|
+
constructor(config) {
|
|
21
|
+
super(config);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get one meter by slug
|
|
25
|
+
*/
|
|
26
|
+
async get(slug, options) {
|
|
27
|
+
return this.request({
|
|
28
|
+
method: 'GET',
|
|
29
|
+
path: `/api/v1/meters/${slug}`,
|
|
30
|
+
options,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* List meters
|
|
35
|
+
*/
|
|
36
|
+
async list(options) {
|
|
37
|
+
return this.request({
|
|
38
|
+
method: 'GET',
|
|
39
|
+
path: `/api/v1/meters`,
|
|
40
|
+
options,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Query a meter
|
|
45
|
+
*/
|
|
46
|
+
async query(slug, params, options) {
|
|
47
|
+
const searchParams = params
|
|
48
|
+
? client_js_1.BaseClient.toURLSearchParams(params)
|
|
49
|
+
: undefined;
|
|
50
|
+
return this.request({
|
|
51
|
+
method: 'GET',
|
|
52
|
+
path: `/api/v1/meters/${slug}/query`,
|
|
53
|
+
searchParams,
|
|
54
|
+
options,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* List subjects of a meter
|
|
59
|
+
*/
|
|
60
|
+
async subjects(slug, options) {
|
|
61
|
+
return this.request({
|
|
62
|
+
method: 'GET',
|
|
63
|
+
path: `/api/v1/meters/${slug}/subjects`,
|
|
64
|
+
options,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.MetersClient = MetersClient;
|
|
69
|
+
//# sourceMappingURL=meter.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { paths, components } from '../schemas/openapi.cjs';
|
|
2
|
+
import { BaseClient, OpenMeterConfig, RequestOptions } from './client.cjs';
|
|
3
|
+
export declare enum WindowSize {
|
|
4
|
+
MINUTE = "MINUTE",
|
|
5
|
+
HOUR = "HOUR",
|
|
6
|
+
DAY = "DAY"
|
|
7
|
+
}
|
|
8
|
+
export declare enum MeterAggregation {
|
|
9
|
+
SUM = "SUM",
|
|
10
|
+
COUNT = "COUNT",
|
|
11
|
+
AVG = "AVG",
|
|
12
|
+
MIN = "MIN",
|
|
13
|
+
MAX = "MAX"
|
|
14
|
+
}
|
|
15
|
+
export type MeterQueryParams = {
|
|
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 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
|
+
*/
|
|
48
|
+
groupBy?: string[];
|
|
49
|
+
/**
|
|
50
|
+
* @description Filter by group by
|
|
51
|
+
*/
|
|
52
|
+
filterGroupBy?: Record<string, string>;
|
|
53
|
+
};
|
|
54
|
+
export type MeterQueryResponse = paths['/api/v1/meters/{meterIdOrSlug}/query']['get']['responses']['200']['content']['application/json'];
|
|
55
|
+
export type Meter = components['schemas']['Meter'];
|
|
56
|
+
export type WindowSizeType = components['schemas']['WindowSize'];
|
|
57
|
+
export declare class MetersClient extends BaseClient {
|
|
58
|
+
constructor(config: OpenMeterConfig);
|
|
59
|
+
/**
|
|
60
|
+
* Get one meter by slug
|
|
61
|
+
*/
|
|
62
|
+
get(slug: string, options?: RequestOptions): Promise<Meter>;
|
|
63
|
+
/**
|
|
64
|
+
* List meters
|
|
65
|
+
*/
|
|
66
|
+
list(options?: RequestOptions): Promise<Meter[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Query a meter
|
|
69
|
+
*/
|
|
70
|
+
query(slug: string, params?: MeterQueryParams, options?: RequestOptions): Promise<MeterQueryResponse>;
|
|
71
|
+
/**
|
|
72
|
+
* List subjects of a meter
|
|
73
|
+
*/
|
|
74
|
+
subjects(slug: string, options?: RequestOptions): Promise<string[]>;
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meter.js","sourceRoot":"","sources":["../../../clients/meter.ts"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B,OAAO,IAAI,CAAC,OAAO,CAAW;YAC5B,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,kBAAkB,IAAI,WAAW;YACvC,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;CACF;AA3DD,oCA2DC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PortalClient = void 0;
|
|
4
|
+
const client_js_1 = require("./client.cjs");
|
|
5
|
+
class PortalClient extends client_js_1.BaseClient {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
super(config);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create portal token
|
|
11
|
+
* Useful for creating a token sharable with your customer to query their own usage
|
|
12
|
+
*/
|
|
13
|
+
async createToken(token, options) {
|
|
14
|
+
return await this.request({
|
|
15
|
+
path: '/api/v1/portal/tokens',
|
|
16
|
+
method: 'POST',
|
|
17
|
+
headers: {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
},
|
|
20
|
+
body: JSON.stringify(token),
|
|
21
|
+
options,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Invalidate portal token
|
|
26
|
+
* @note OpenMeter Cloud only feature
|
|
27
|
+
*/
|
|
28
|
+
async invalidateTokens(invalidate = {}, options) {
|
|
29
|
+
return await this.request({
|
|
30
|
+
path: '/api/v1/portal/tokens/invalidate',
|
|
31
|
+
method: 'POST',
|
|
32
|
+
headers: {
|
|
33
|
+
'Content-Type': 'application/json',
|
|
34
|
+
},
|
|
35
|
+
body: JSON.stringify(invalidate),
|
|
36
|
+
options,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.PortalClient = PortalClient;
|
|
41
|
+
//# sourceMappingURL=portal.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { components } from '../schemas/openapi.cjs';
|
|
2
|
+
import { RequestOptions, BaseClient, OpenMeterConfig } from './client.cjs';
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"portal.js","sourceRoot":"","sources":["../../../clients/portal.ts"],"names":[],"mappings":";;;AACA,2CAAyE;AAIzE,MAAa,YAAa,SAAQ,sBAAU;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;AA9CD,oCA8CC"}
|