@openmeter/sdk 1.0.0-beta.22 → 1.0.0-beta.221
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/Makefile +43 -0
- package/README.md +38 -150
- package/dist/cjs/index.cjs +18 -0
- package/dist/cjs/index.d.cts +1 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/src/client/addons.cjs +105 -0
- package/dist/cjs/src/client/addons.d.cts +152 -0
- package/dist/cjs/src/client/addons.js.map +1 -0
- package/dist/cjs/src/client/apps.cjs +247 -0
- package/dist/cjs/src/client/apps.d.cts +327 -0
- package/dist/cjs/src/client/apps.js.map +1 -0
- package/dist/cjs/src/client/billing.cjs +361 -0
- package/dist/cjs/src/client/billing.d.cts +526 -0
- package/dist/cjs/src/client/billing.js.map +1 -0
- package/dist/cjs/src/client/common.cjs +47 -0
- package/dist/cjs/src/client/common.d.cts +30 -0
- package/dist/cjs/src/client/common.js.map +1 -0
- package/dist/cjs/src/client/customers.cjs +283 -0
- package/dist/cjs/src/client/customers.d.cts +251 -0
- package/dist/cjs/src/client/customers.js.map +1 -0
- package/dist/cjs/src/client/debug.cjs +27 -0
- package/dist/cjs/src/client/debug.d.cts +17 -0
- package/dist/cjs/src/client/debug.js.map +1 -0
- package/dist/cjs/src/client/entitlements.cjs +281 -0
- package/dist/cjs/src/client/entitlements.d.cts +556 -0
- package/dist/cjs/src/client/entitlements.js.map +1 -0
- package/dist/cjs/src/client/events.cjs +113 -0
- package/dist/cjs/src/client/events.d.cts +48 -0
- package/dist/cjs/src/client/events.js.map +1 -0
- package/dist/cjs/src/client/features.cjs +78 -0
- package/dist/cjs/src/client/features.d.cts +78 -0
- package/dist/cjs/src/client/features.js.map +1 -0
- package/dist/cjs/src/client/index.cjs +120 -0
- package/dist/cjs/src/client/index.d.cts +53 -0
- package/dist/cjs/src/client/index.js.map +1 -0
- package/dist/cjs/src/client/info.cjs +42 -0
- package/dist/cjs/src/client/info.d.cts +34 -0
- package/dist/cjs/src/client/info.js.map +1 -0
- package/dist/cjs/src/client/meters.cjs +115 -0
- package/dist/cjs/src/client/meters.d.cts +123 -0
- package/dist/cjs/src/client/meters.js.map +1 -0
- package/dist/cjs/src/client/notifications.cjs +249 -0
- package/dist/cjs/src/client/notifications.d.cts +397 -0
- package/dist/cjs/src/client/notifications.js.map +1 -0
- package/dist/cjs/src/client/plans.cjs +204 -0
- package/dist/cjs/src/client/plans.d.cts +247 -0
- package/dist/cjs/src/client/plans.js.map +1 -0
- package/dist/cjs/src/client/portal.cjs +55 -0
- package/dist/cjs/src/client/portal.d.cts +48 -0
- package/dist/cjs/src/client/portal.js.map +1 -0
- package/dist/cjs/src/client/schemas.cjs +3 -0
- package/dist/cjs/src/client/schemas.d.cts +25246 -0
- package/dist/cjs/src/client/schemas.js.map +1 -0
- package/dist/cjs/src/client/subjects.cjs +76 -0
- package/dist/cjs/src/client/subjects.d.cts +70 -0
- package/dist/cjs/src/client/subjects.js.map +1 -0
- package/dist/cjs/src/client/subscription-addons.cjs +70 -0
- package/dist/cjs/src/client/subscription-addons.d.cts +123 -0
- package/dist/cjs/src/client/subscription-addons.js.map +1 -0
- package/dist/cjs/src/client/subscriptions.cjs +132 -0
- package/dist/cjs/src/client/subscriptions.d.cts +170 -0
- package/dist/cjs/src/client/subscriptions.js.map +1 -0
- package/dist/cjs/src/client/utils.cjs +69 -0
- package/dist/cjs/src/client/utils.d.cts +12 -0
- package/dist/cjs/src/client/utils.js.map +1 -0
- package/dist/cjs/src/portal/index.cjs +89 -0
- package/dist/cjs/src/portal/index.d.cts +43 -0
- package/dist/cjs/src/portal/index.js.map +1 -0
- package/dist/cjs/src/react/context.cjs +35 -0
- package/dist/cjs/src/react/context.d.cts +9 -0
- package/dist/cjs/src/react/context.js.map +1 -0
- package/dist/cjs/src/zod/index.cjs +12205 -0
- package/dist/cjs/src/zod/index.d.cts +19139 -0
- package/dist/cjs/src/zod/index.js.map +1 -0
- package/dist/cjs/tsconfig.0bedc47d.tsbuildinfo +1 -0
- package/dist/cjs/tsconfig.c449a50f.tsbuildinfo +1 -0
- package/dist/index.d.ts +1 -14
- package/dist/index.js +2 -15
- package/dist/index.js.map +1 -0
- package/dist/src/client/addons.d.ts +152 -0
- package/dist/src/client/addons.js +101 -0
- package/dist/src/client/addons.js.map +1 -0
- package/dist/src/client/apps.d.ts +327 -0
- package/dist/src/client/apps.js +240 -0
- package/dist/src/client/apps.js.map +1 -0
- package/dist/src/client/billing.d.ts +526 -0
- package/dist/src/client/billing.js +354 -0
- package/dist/src/client/billing.js.map +1 -0
- package/dist/src/client/common.d.ts +30 -0
- package/dist/src/client/common.js +42 -0
- package/dist/src/client/common.js.map +1 -0
- package/dist/src/client/customers.d.ts +251 -0
- package/dist/src/client/customers.js +276 -0
- package/dist/src/client/customers.js.map +1 -0
- package/dist/src/client/debug.d.ts +17 -0
- package/dist/src/client/debug.js +23 -0
- package/dist/src/client/debug.js.map +1 -0
- package/dist/src/client/entitlements.d.ts +556 -0
- package/dist/src/client/entitlements.js +276 -0
- package/dist/src/client/entitlements.js.map +1 -0
- package/dist/src/client/events.d.ts +48 -0
- package/dist/src/client/events.js +108 -0
- package/dist/src/client/events.js.map +1 -0
- package/dist/src/client/features.d.ts +78 -0
- package/dist/src/client/features.js +74 -0
- package/dist/src/client/features.js.map +1 -0
- package/dist/src/client/index.d.ts +53 -0
- package/dist/src/client/index.js +80 -0
- package/dist/src/client/index.js.map +1 -0
- package/dist/src/client/info.d.ts +34 -0
- package/dist/src/client/info.js +38 -0
- package/dist/src/client/info.js.map +1 -0
- package/dist/src/client/meters.d.ts +123 -0
- package/dist/src/client/meters.js +111 -0
- package/dist/src/client/meters.js.map +1 -0
- package/dist/src/client/notifications.d.ts +397 -0
- package/dist/src/client/notifications.js +242 -0
- package/dist/src/client/notifications.js.map +1 -0
- package/dist/src/client/plans.d.ts +247 -0
- package/dist/src/client/plans.js +199 -0
- package/dist/src/client/plans.js.map +1 -0
- package/dist/src/client/portal.d.ts +48 -0
- package/dist/src/client/portal.js +51 -0
- package/dist/src/client/portal.js.map +1 -0
- package/dist/src/client/schemas.d.ts +25246 -0
- package/dist/src/client/schemas.js +2 -0
- package/dist/src/client/schemas.js.map +1 -0
- package/dist/src/client/subjects.d.ts +70 -0
- package/dist/src/client/subjects.js +72 -0
- package/dist/src/client/subjects.js.map +1 -0
- package/dist/src/client/subscription-addons.d.ts +123 -0
- package/dist/src/client/subscription-addons.js +66 -0
- package/dist/src/client/subscription-addons.js.map +1 -0
- package/dist/src/client/subscriptions.d.ts +170 -0
- package/dist/src/client/subscriptions.js +128 -0
- package/dist/src/client/subscriptions.js.map +1 -0
- package/dist/src/client/utils.d.ts +12 -0
- package/dist/src/client/utils.js +63 -0
- package/dist/src/client/utils.js.map +1 -0
- package/dist/src/portal/index.d.ts +43 -0
- package/dist/src/portal/index.js +52 -0
- package/dist/src/portal/index.js.map +1 -0
- package/dist/src/react/context.d.ts +9 -0
- package/dist/src/react/context.js +16 -0
- package/dist/src/react/context.js.map +1 -0
- package/dist/src/zod/index.d.ts +19139 -0
- package/dist/src/zod/index.js +12178 -0
- package/dist/src/zod/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/orval.config.ts +42 -0
- package/package.json +89 -35
- package/patches/openapi-typescript.patch +6194 -0
- package/dist/clients/client.d.ts +0 -40
- package/dist/clients/client.js +0 -104
- package/dist/clients/event.d.ts +0 -79
- package/dist/clients/event.js +0 -53
- package/dist/clients/meter.d.ts +0 -71
- package/dist/clients/meter.js +0 -64
- package/dist/clients/portal.d.ts +0 -23
- package/dist/clients/portal.js +0 -37
- package/dist/next.d.ts +0 -15
- package/dist/next.js +0 -46
- package/dist/schemas/openapi.d.ts +0 -460
- package/dist/schemas/openapi.js +0 -5
- package/dist/test/agent.d.ts +0 -2
- package/dist/test/agent.js +0 -178
- package/dist/test/mocks.d.ts +0 -12
- package/dist/test/mocks.js +0 -32
- package/index.ts +0 -22
- package/next.ts +0 -76
package/dist/clients/client.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
|
-
import { IncomingHttpHeaders } from 'http';
|
|
5
|
-
import { Dispatcher } from 'undici';
|
|
6
|
-
import { components } from '../schemas/openapi.js';
|
|
7
|
-
export type OpenMeterConfig = {
|
|
8
|
-
baseUrl: string;
|
|
9
|
-
token?: string;
|
|
10
|
-
username?: string;
|
|
11
|
-
password?: string;
|
|
12
|
-
headers?: IncomingHttpHeaders;
|
|
13
|
-
};
|
|
14
|
-
export type RequestOptions = {
|
|
15
|
-
headers?: IncomingHttpHeaders;
|
|
16
|
-
};
|
|
17
|
-
export type Problem = components['schemas']['Problem'];
|
|
18
|
-
export declare class BaseClient {
|
|
19
|
-
protected config: OpenMeterConfig;
|
|
20
|
-
constructor(config: OpenMeterConfig);
|
|
21
|
-
protected request<T>({ path, method, searchParams, headers, body, options, }: {
|
|
22
|
-
path: string;
|
|
23
|
-
method: Dispatcher.HttpMethod;
|
|
24
|
-
searchParams?: URLSearchParams;
|
|
25
|
-
headers?: IncomingHttpHeaders;
|
|
26
|
-
body?: string | Buffer | Uint8Array;
|
|
27
|
-
options?: RequestOptions;
|
|
28
|
-
}): Promise<T>;
|
|
29
|
-
protected getUrl(path: string, searchParams?: URLSearchParams): import("url").URL;
|
|
30
|
-
protected getAuthHeaders(): IncomingHttpHeaders;
|
|
31
|
-
protected static toURLSearchParams(params: Record<string, string | number | Date | string[] | undefined>): URLSearchParams;
|
|
32
|
-
}
|
|
33
|
-
export declare class HttpError extends Error {
|
|
34
|
-
statusCode: number;
|
|
35
|
-
problem?: Problem;
|
|
36
|
-
constructor({ statusCode, problem, }: {
|
|
37
|
-
statusCode: number;
|
|
38
|
-
problem?: Problem;
|
|
39
|
-
});
|
|
40
|
-
}
|
package/dist/clients/client.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { request } from 'undici';
|
|
2
|
-
export class BaseClient {
|
|
3
|
-
config;
|
|
4
|
-
constructor(config) {
|
|
5
|
-
this.config = config;
|
|
6
|
-
}
|
|
7
|
-
async request({ path, method, searchParams, headers, body, options, }) {
|
|
8
|
-
// Building URL
|
|
9
|
-
const url = this.getUrl(path, searchParams);
|
|
10
|
-
// Request options
|
|
11
|
-
const reqHeaders = {
|
|
12
|
-
Accept: 'application/json',
|
|
13
|
-
...headers,
|
|
14
|
-
...this.getAuthHeaders(),
|
|
15
|
-
...this.config.headers,
|
|
16
|
-
...options?.headers,
|
|
17
|
-
};
|
|
18
|
-
const reqOpts = {
|
|
19
|
-
method,
|
|
20
|
-
headers: reqHeaders,
|
|
21
|
-
};
|
|
22
|
-
// Optional body
|
|
23
|
-
if (body) {
|
|
24
|
-
if (!reqHeaders['Content-Type'] && !reqHeaders['content-type']) {
|
|
25
|
-
throw new Error('Content Type is required with body');
|
|
26
|
-
}
|
|
27
|
-
reqOpts.body = body;
|
|
28
|
-
}
|
|
29
|
-
const resp = await request(url, reqOpts);
|
|
30
|
-
// Error handling
|
|
31
|
-
if (resp.statusCode > 399) {
|
|
32
|
-
if (resp.headers['content-type'] === 'application/problem+json') {
|
|
33
|
-
const problem = (await resp.body.json());
|
|
34
|
-
throw new HttpError({
|
|
35
|
-
statusCode: resp.statusCode,
|
|
36
|
-
problem,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
// Requests can fail before API, in this case we only have a status code
|
|
40
|
-
throw new HttpError({
|
|
41
|
-
statusCode: resp.statusCode,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
// Response parsing
|
|
45
|
-
if (resp.statusCode === 204 || resp.headers['content-length'] === '0') {
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
if (resp.headers['content-type'] === 'application/json') {
|
|
49
|
-
return (await resp.body.json());
|
|
50
|
-
}
|
|
51
|
-
if (!resp.headers['content-type']) {
|
|
52
|
-
throw new Error('Missing content type');
|
|
53
|
-
}
|
|
54
|
-
throw new Error(`Unknown content type: ${resp.headers['content-type']}`);
|
|
55
|
-
}
|
|
56
|
-
getUrl(path, searchParams) {
|
|
57
|
-
let qs = searchParams ? searchParams.toString() : '';
|
|
58
|
-
qs = qs.length > 0 ? `?${qs}` : '';
|
|
59
|
-
const url = new URL(`${path}${qs}`, this.config.baseUrl);
|
|
60
|
-
return url;
|
|
61
|
-
}
|
|
62
|
-
getAuthHeaders() {
|
|
63
|
-
if (this.config.token) {
|
|
64
|
-
return {
|
|
65
|
-
authorization: `Bearer ${this.config.token}`,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
if (this.config.username && this.config.password) {
|
|
69
|
-
const encoded = Buffer.from(`${this.config.username}:${this.config.password}`).toString('base64');
|
|
70
|
-
return {
|
|
71
|
-
authorization: `Basic ${encoded}`,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
return {};
|
|
75
|
-
}
|
|
76
|
-
static toURLSearchParams(params) {
|
|
77
|
-
const searchParams = new URLSearchParams();
|
|
78
|
-
for (const [key, value] of Object.entries(params)) {
|
|
79
|
-
if (value === undefined) {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
if (Array.isArray(value)) {
|
|
83
|
-
searchParams.append(key, value.join(','));
|
|
84
|
-
}
|
|
85
|
-
else if (value instanceof Date) {
|
|
86
|
-
searchParams.append(key, value.toISOString());
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
searchParams.append(key, value.toString());
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return searchParams;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
export class HttpError extends Error {
|
|
96
|
-
statusCode;
|
|
97
|
-
problem;
|
|
98
|
-
constructor({ statusCode, problem, }) {
|
|
99
|
-
super(problem?.type || 'unexpected status code');
|
|
100
|
-
this.name = 'HttpError';
|
|
101
|
-
this.statusCode = statusCode;
|
|
102
|
-
this.problem = problem;
|
|
103
|
-
}
|
|
104
|
-
}
|
package/dist/clients/event.d.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { components } from '../schemas/openapi.js';
|
|
2
|
-
import { RequestOptions, BaseClient, OpenMeterConfig } from './client.js';
|
|
3
|
-
type CloudEvents = components['schemas']['Event'];
|
|
4
|
-
export type EventsQueryParams = {
|
|
5
|
-
/**
|
|
6
|
-
* @description Limit number of results. Max: 100
|
|
7
|
-
* @example 25
|
|
8
|
-
*/
|
|
9
|
-
limit?: number;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Usage Event
|
|
13
|
-
*/
|
|
14
|
-
export type Event = {
|
|
15
|
-
/**
|
|
16
|
-
* @description The version of the CloudEvents specification which the event uses.
|
|
17
|
-
* @example 1.0
|
|
18
|
-
*/
|
|
19
|
-
specversion?: string;
|
|
20
|
-
/**
|
|
21
|
-
* @description Unique identifier for the event, defaults to uuid v4.
|
|
22
|
-
* @example "5c10fade-1c9e-4d6c-8275-c52c36731d3c"
|
|
23
|
-
*/
|
|
24
|
-
id?: string;
|
|
25
|
-
/**
|
|
26
|
-
* Format: uri-reference
|
|
27
|
-
* @description Identifies the context in which an event happened, defaults to: @openmeter/sdk
|
|
28
|
-
* @example services/service-0
|
|
29
|
-
*/
|
|
30
|
-
source?: string;
|
|
31
|
-
/**
|
|
32
|
-
* @description Describes the type of event related to the originating occurrence.
|
|
33
|
-
* @example "api_request"
|
|
34
|
-
*/
|
|
35
|
-
type: string;
|
|
36
|
-
/**
|
|
37
|
-
* @description Describes the subject of the event in the context of the event producer (identified by source).
|
|
38
|
-
* @example "customer_id"
|
|
39
|
-
*/
|
|
40
|
-
subject: string;
|
|
41
|
-
/**
|
|
42
|
-
* Format: date-time
|
|
43
|
-
* @description Date of when the occurrence happened.
|
|
44
|
-
* @example new Date('2023-01-01T01:01:01.001Z')
|
|
45
|
-
*/
|
|
46
|
-
time?: Date;
|
|
47
|
-
/**
|
|
48
|
-
* Format: uri
|
|
49
|
-
* @description Identifies the schema that data adheres to.
|
|
50
|
-
*/
|
|
51
|
-
dataschema?: string;
|
|
52
|
-
/**
|
|
53
|
-
* @description Content type of the data value. Must adhere to RFC 2046 format.
|
|
54
|
-
* @example application/json
|
|
55
|
-
* @enum {string|null}
|
|
56
|
-
*/
|
|
57
|
-
datacontenttype?: 'application/json';
|
|
58
|
-
/**
|
|
59
|
-
* @description The event payload.
|
|
60
|
-
* @example {
|
|
61
|
-
* "duration_ms": "12",
|
|
62
|
-
* "path": "/hello"
|
|
63
|
-
* }
|
|
64
|
-
*/
|
|
65
|
-
data: Record<string, string | number | Record<string, string | number>>;
|
|
66
|
-
};
|
|
67
|
-
export declare class EventsClient extends BaseClient {
|
|
68
|
-
constructor(config: OpenMeterConfig);
|
|
69
|
-
/**
|
|
70
|
-
* Ingest usage event in a CloudEvents format
|
|
71
|
-
* @see https://cloudevents.io
|
|
72
|
-
*/
|
|
73
|
-
ingest(usageEvent: Event, options?: RequestOptions): Promise<void>;
|
|
74
|
-
/**
|
|
75
|
-
* List raw events
|
|
76
|
-
*/
|
|
77
|
-
list(params?: EventsQueryParams, options?: RequestOptions): Promise<CloudEvents[]>;
|
|
78
|
-
}
|
|
79
|
-
export {};
|
package/dist/clients/event.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
import { BaseClient } from './client.js';
|
|
3
|
-
export class EventsClient extends BaseClient {
|
|
4
|
-
constructor(config) {
|
|
5
|
-
super(config);
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Ingest usage event in a CloudEvents format
|
|
9
|
-
* @see https://cloudevents.io
|
|
10
|
-
*/
|
|
11
|
-
async ingest(usageEvent, options) {
|
|
12
|
-
if (usageEvent.datacontenttype &&
|
|
13
|
-
usageEvent.datacontenttype !== 'application/json') {
|
|
14
|
-
throw new TypeError(`Unsupported datacontenttype: ${usageEvent.datacontenttype}`);
|
|
15
|
-
}
|
|
16
|
-
// We default where we can to lower the barrier to use CloudEvents
|
|
17
|
-
const body = {
|
|
18
|
-
specversion: usageEvent.specversion ?? '1.0',
|
|
19
|
-
id: usageEvent.id ?? crypto.randomUUID(),
|
|
20
|
-
source: usageEvent.source ?? '@openmeter/sdk',
|
|
21
|
-
type: usageEvent.type,
|
|
22
|
-
subject: usageEvent.subject,
|
|
23
|
-
time: usageEvent.time?.toISOString(),
|
|
24
|
-
datacontenttype: usageEvent.datacontenttype,
|
|
25
|
-
dataschema: usageEvent.dataschema,
|
|
26
|
-
data: usageEvent.data,
|
|
27
|
-
};
|
|
28
|
-
// Making Request
|
|
29
|
-
return await this.request({
|
|
30
|
-
path: '/api/v1/events',
|
|
31
|
-
method: 'POST',
|
|
32
|
-
body: JSON.stringify(body),
|
|
33
|
-
headers: {
|
|
34
|
-
'Content-Type': 'application/cloudevents+json',
|
|
35
|
-
},
|
|
36
|
-
options,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* List raw events
|
|
41
|
-
*/
|
|
42
|
-
async list(params, options) {
|
|
43
|
-
const searchParams = params
|
|
44
|
-
? BaseClient.toURLSearchParams(params)
|
|
45
|
-
: undefined;
|
|
46
|
-
return this.request({
|
|
47
|
-
method: 'GET',
|
|
48
|
-
path: `/api/v1/events`,
|
|
49
|
-
searchParams,
|
|
50
|
-
options,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
package/dist/clients/meter.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { paths, components } from '../schemas/openapi.js';
|
|
2
|
-
import { BaseClient, OpenMeterConfig, RequestOptions } from './client.js';
|
|
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
|
-
export type MeterQueryResponse = paths['/api/v1/meters/{meterIdOrSlug}/query']['get']['responses']['200']['content']['application/json'];
|
|
51
|
-
export type Meter = components['schemas']['Meter'];
|
|
52
|
-
export type WindowSizeType = components['schemas']['WindowSize'];
|
|
53
|
-
export declare class MetersClient extends BaseClient {
|
|
54
|
-
constructor(config: OpenMeterConfig);
|
|
55
|
-
/**
|
|
56
|
-
* Get one meter by slug
|
|
57
|
-
*/
|
|
58
|
-
get(slug: string, options?: RequestOptions): Promise<Meter>;
|
|
59
|
-
/**
|
|
60
|
-
* List meters
|
|
61
|
-
*/
|
|
62
|
-
list(options?: RequestOptions): Promise<Meter[]>;
|
|
63
|
-
/**
|
|
64
|
-
* Query a meter
|
|
65
|
-
*/
|
|
66
|
-
query(slug: string, params?: MeterQueryParams, options?: RequestOptions): Promise<MeterQueryResponse>;
|
|
67
|
-
/**
|
|
68
|
-
* List subjects of a meter
|
|
69
|
-
*/
|
|
70
|
-
subjects(slug: string, options?: RequestOptions): Promise<string[]>;
|
|
71
|
-
}
|
package/dist/clients/meter.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { BaseClient } from './client.js';
|
|
2
|
-
export var WindowSize;
|
|
3
|
-
(function (WindowSize) {
|
|
4
|
-
WindowSize["MINUTE"] = "MINUTE";
|
|
5
|
-
WindowSize["HOUR"] = "HOUR";
|
|
6
|
-
WindowSize["DAY"] = "DAY";
|
|
7
|
-
})(WindowSize || (WindowSize = {}));
|
|
8
|
-
export var MeterAggregation;
|
|
9
|
-
(function (MeterAggregation) {
|
|
10
|
-
MeterAggregation["SUM"] = "SUM";
|
|
11
|
-
MeterAggregation["COUNT"] = "COUNT";
|
|
12
|
-
MeterAggregation["AVG"] = "AVG";
|
|
13
|
-
MeterAggregation["MIN"] = "MIN";
|
|
14
|
-
MeterAggregation["MAX"] = "MAX";
|
|
15
|
-
})(MeterAggregation || (MeterAggregation = {}));
|
|
16
|
-
export class MetersClient extends BaseClient {
|
|
17
|
-
constructor(config) {
|
|
18
|
-
super(config);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Get one meter by slug
|
|
22
|
-
*/
|
|
23
|
-
async get(slug, options) {
|
|
24
|
-
return this.request({
|
|
25
|
-
method: 'GET',
|
|
26
|
-
path: `/api/v1/meters/${slug}`,
|
|
27
|
-
options,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* List meters
|
|
32
|
-
*/
|
|
33
|
-
async list(options) {
|
|
34
|
-
return this.request({
|
|
35
|
-
method: 'GET',
|
|
36
|
-
path: `/api/v1/meters`,
|
|
37
|
-
options,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Query a meter
|
|
42
|
-
*/
|
|
43
|
-
async query(slug, params, options) {
|
|
44
|
-
const searchParams = params
|
|
45
|
-
? BaseClient.toURLSearchParams(params)
|
|
46
|
-
: undefined;
|
|
47
|
-
return this.request({
|
|
48
|
-
method: 'GET',
|
|
49
|
-
path: `/api/v1/meters/${slug}/query`,
|
|
50
|
-
searchParams,
|
|
51
|
-
options,
|
|
52
|
-
});
|
|
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
|
-
}
|
|
64
|
-
}
|
package/dist/clients/portal.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
* @note OpenMeter Cloud only feature
|
|
10
|
-
*/
|
|
11
|
-
createToken(token: {
|
|
12
|
-
subject: string;
|
|
13
|
-
expiresAt?: Date;
|
|
14
|
-
allowedMeterSlugs?: string[];
|
|
15
|
-
}, options?: RequestOptions): Promise<PortalToken>;
|
|
16
|
-
/**
|
|
17
|
-
* Invalidate portal token
|
|
18
|
-
* @note OpenMeter Cloud only feature
|
|
19
|
-
*/
|
|
20
|
-
invalidateTokens(invalidate?: {
|
|
21
|
-
subject?: string;
|
|
22
|
-
}, options?: RequestOptions): Promise<void>;
|
|
23
|
-
}
|
package/dist/clients/portal.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
* @note OpenMeter Cloud only feature
|
|
10
|
-
*/
|
|
11
|
-
async createToken(token, options) {
|
|
12
|
-
return await this.request({
|
|
13
|
-
path: '/api/v1/portal/tokens',
|
|
14
|
-
method: 'POST',
|
|
15
|
-
headers: {
|
|
16
|
-
'Content-Type': 'application/json',
|
|
17
|
-
},
|
|
18
|
-
body: JSON.stringify(token),
|
|
19
|
-
options,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Invalidate portal token
|
|
24
|
-
* @note OpenMeter Cloud only feature
|
|
25
|
-
*/
|
|
26
|
-
async invalidateTokens(invalidate = {}, options) {
|
|
27
|
-
return await this.request({
|
|
28
|
-
path: '/api/v1/portal/tokens/invalidate',
|
|
29
|
-
method: 'POST',
|
|
30
|
-
headers: {
|
|
31
|
-
'Content-Type': 'application/json',
|
|
32
|
-
},
|
|
33
|
-
body: JSON.stringify(invalidate),
|
|
34
|
-
options,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
package/dist/next.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { OpenAIStreamCallbacks } from 'ai';
|
|
2
|
-
import type { TiktokenModel } from 'js-tiktoken';
|
|
3
|
-
type OpenAIUsage = {
|
|
4
|
-
total_tokens: number;
|
|
5
|
-
prompt_tokens: number;
|
|
6
|
-
completion_tokens: number;
|
|
7
|
-
};
|
|
8
|
-
type OpenAIStreamCallbacksWithUsage = OpenAIStreamCallbacks & {
|
|
9
|
-
onUsage?: (usage: OpenAIUsage) => Promise<void> | void;
|
|
10
|
-
};
|
|
11
|
-
export declare function createOpenAIStreamCallback({ model, prompts, }: {
|
|
12
|
-
model: TiktokenModel;
|
|
13
|
-
prompts: string[];
|
|
14
|
-
}, openAIStreamCallbacks: OpenAIStreamCallbacksWithUsage): Promise<OpenAIStreamCallbacks>;
|
|
15
|
-
export {};
|
package/dist/next.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
let encodingForModel;
|
|
2
|
-
export async function createOpenAIStreamCallback({ model, prompts, }, openAIStreamCallbacks) {
|
|
3
|
-
// Tiktoken is an optional dependency, so we import it conditionally
|
|
4
|
-
if (!encodingForModel) {
|
|
5
|
-
const { encodingForModel: encodingForModel_ } = await import('js-tiktoken');
|
|
6
|
-
encodingForModel = encodingForModel_;
|
|
7
|
-
}
|
|
8
|
-
const enc = encodingForModel(model);
|
|
9
|
-
let promptTokens = 0;
|
|
10
|
-
let completionTokens = 0;
|
|
11
|
-
const streamCallbacks = {
|
|
12
|
-
...openAIStreamCallbacks,
|
|
13
|
-
async onStart() {
|
|
14
|
-
for (const content of prompts) {
|
|
15
|
-
const tokens = enc.encode(content);
|
|
16
|
-
promptTokens += tokens.length;
|
|
17
|
-
}
|
|
18
|
-
if (typeof openAIStreamCallbacks?.onStart === 'function') {
|
|
19
|
-
return openAIStreamCallbacks.onStart();
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
async onToken(content) {
|
|
23
|
-
// To test tokenizaton see: https://platform.openai.com/tokenizer
|
|
24
|
-
const tokens = enc.encode(content);
|
|
25
|
-
completionTokens += tokens.length;
|
|
26
|
-
if (typeof openAIStreamCallbacks?.onToken === 'function') {
|
|
27
|
-
return openAIStreamCallbacks.onToken(content);
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
async onFinal(completion) {
|
|
31
|
-
// Mimicking OpenAI usage metadata API
|
|
32
|
-
const usage = {
|
|
33
|
-
total_tokens: promptTokens + completionTokens,
|
|
34
|
-
prompt_tokens: promptTokens,
|
|
35
|
-
completion_tokens: completionTokens,
|
|
36
|
-
};
|
|
37
|
-
if (typeof openAIStreamCallbacks?.onUsage === 'function') {
|
|
38
|
-
await openAIStreamCallbacks.onUsage(usage);
|
|
39
|
-
}
|
|
40
|
-
if (typeof openAIStreamCallbacks?.onFinal === 'function') {
|
|
41
|
-
return openAIStreamCallbacks.onFinal(completion);
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
return streamCallbacks;
|
|
46
|
-
}
|