@openmeter/sdk 1.0.0-beta.21 → 1.0.0-beta.211
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 +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/apps.cjs +174 -0
- package/dist/cjs/src/client/apps.d.cts +286 -0
- package/dist/cjs/src/client/apps.js.map +1 -0
- package/dist/cjs/src/client/billing.cjs +309 -0
- package/dist/cjs/src/client/billing.d.cts +502 -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 +199 -0
- package/dist/cjs/src/client/customers.d.cts +179 -0
- package/dist/cjs/src/client/customers.js.map +1 -0
- package/dist/cjs/src/client/entitlements.cjs +244 -0
- package/dist/cjs/src/client/entitlements.d.cts +472 -0
- package/dist/cjs/src/client/entitlements.js.map +1 -0
- package/dist/cjs/src/client/events.cjs +66 -0
- package/dist/cjs/src/client/events.d.cts +31 -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 +108 -0
- package/dist/cjs/src/client/index.d.cts +45 -0
- package/dist/cjs/src/client/index.js.map +1 -0
- package/dist/cjs/src/client/meters.cjs +96 -0
- package/dist/cjs/src/client/meters.d.cts +99 -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 +219 -0
- package/dist/cjs/src/client/notifications.js.map +1 -0
- package/dist/cjs/src/client/plans.cjs +127 -0
- package/dist/cjs/src/client/plans.d.cts +142 -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 +22438 -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/subscriptions.cjs +116 -0
- package/dist/cjs/src/client/subscriptions.d.cts +147 -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 +60 -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/tsconfig.341d9ef4.tsbuildinfo +1 -0
- package/dist/cjs/tsconfig.523d9ac8.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/apps.d.ts +286 -0
- package/dist/src/client/apps.js +168 -0
- package/dist/src/client/apps.js.map +1 -0
- package/dist/src/client/billing.d.ts +502 -0
- package/dist/src/client/billing.js +302 -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 +179 -0
- package/dist/src/client/customers.js +193 -0
- package/dist/src/client/customers.js.map +1 -0
- package/dist/src/client/entitlements.d.ts +472 -0
- package/dist/src/client/entitlements.js +239 -0
- package/dist/src/client/entitlements.js.map +1 -0
- package/dist/src/client/events.d.ts +31 -0
- package/dist/src/client/events.js +58 -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 +45 -0
- package/dist/src/client/index.js +68 -0
- package/dist/src/client/index.js.map +1 -0
- package/dist/src/client/meters.d.ts +99 -0
- package/dist/src/client/meters.js +92 -0
- package/dist/src/client/meters.js.map +1 -0
- package/dist/src/client/notifications.d.ts +219 -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 +142 -0
- package/dist/src/client/plans.js +123 -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 +22438 -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/subscriptions.d.ts +147 -0
- package/dist/src/client/subscriptions.js +112 -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 +53 -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/tsconfig.tsbuildinfo +1 -1
- package/package.json +75 -35
- package/patches/openapi-typescript.patch +73 -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 -96
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../src/client/schemas.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { RequestOptions } from './common.js';
|
|
2
|
+
import type { operations, paths, SubjectUpsert } from './schemas.js';
|
|
3
|
+
import type { Client } from 'openapi-fetch';
|
|
4
|
+
/**
|
|
5
|
+
* Subjects
|
|
6
|
+
* @description Subjects are entities that consume resources you wish to meter. These can range from users, servers, and services to devices. The design of subjects is intentionally generic, enabling flexible application across various metering scenarios. Meters are aggregating events for each subject..
|
|
7
|
+
*/
|
|
8
|
+
export declare class Subjects {
|
|
9
|
+
private client;
|
|
10
|
+
constructor(client: Client<paths, `${string}/${string}`>);
|
|
11
|
+
/**
|
|
12
|
+
* Upsert one or multiple subjects
|
|
13
|
+
* If the subject does not exist, it will be created, otherwise it will be updated.
|
|
14
|
+
*
|
|
15
|
+
* @param subjects - The subjects to upsert
|
|
16
|
+
* @param signal - An optional abort signal
|
|
17
|
+
* @returns The upserted subjects
|
|
18
|
+
*/
|
|
19
|
+
upsert(subjects: SubjectUpsert | SubjectUpsert[], options?: RequestOptions): Promise<{
|
|
20
|
+
readonly id: string;
|
|
21
|
+
key: string;
|
|
22
|
+
displayName?: string | null;
|
|
23
|
+
metadata?: {
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
} | null;
|
|
26
|
+
currentPeriodStart?: Date;
|
|
27
|
+
currentPeriodEnd?: Date;
|
|
28
|
+
stripeCustomerId?: string | null;
|
|
29
|
+
}[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Get a subject by ID or key
|
|
32
|
+
* @param idOrKey - The ID or key of the subject
|
|
33
|
+
* @param signal - An optional abort signal
|
|
34
|
+
* @returns The subject
|
|
35
|
+
*/
|
|
36
|
+
get(idOrKey: operations['getSubject']['parameters']['path']['subjectIdOrKey'], options?: RequestOptions): Promise<{
|
|
37
|
+
readonly id: string;
|
|
38
|
+
key: string;
|
|
39
|
+
displayName?: string | null;
|
|
40
|
+
metadata?: {
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
} | null;
|
|
43
|
+
currentPeriodStart?: Date;
|
|
44
|
+
currentPeriodEnd?: Date;
|
|
45
|
+
stripeCustomerId?: string | null;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* List subjects
|
|
49
|
+
* @param signal - An optional abort signal
|
|
50
|
+
* @returns The subjects
|
|
51
|
+
*/
|
|
52
|
+
list(options?: RequestOptions): Promise<{
|
|
53
|
+
readonly id: string;
|
|
54
|
+
key: string;
|
|
55
|
+
displayName?: string | null;
|
|
56
|
+
metadata?: {
|
|
57
|
+
[key: string]: unknown;
|
|
58
|
+
} | null;
|
|
59
|
+
currentPeriodStart?: Date;
|
|
60
|
+
currentPeriodEnd?: Date;
|
|
61
|
+
stripeCustomerId?: string | null;
|
|
62
|
+
}[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Delete a subject by ID or key
|
|
65
|
+
* @param idOrKey - The ID or key of the subject
|
|
66
|
+
* @param signal - An optional abort signal
|
|
67
|
+
* @returns The deleted subject
|
|
68
|
+
*/
|
|
69
|
+
delete(idOrKey: operations['deleteSubject']['parameters']['path']['subjectIdOrKey'], options?: RequestOptions): Promise<undefined>;
|
|
70
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { transformResponse } from './utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Subjects
|
|
4
|
+
* @description Subjects are entities that consume resources you wish to meter. These can range from users, servers, and services to devices. The design of subjects is intentionally generic, enabling flexible application across various metering scenarios. Meters are aggregating events for each subject..
|
|
5
|
+
*/
|
|
6
|
+
export class Subjects {
|
|
7
|
+
client;
|
|
8
|
+
constructor(client) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Upsert one or multiple subjects
|
|
13
|
+
* If the subject does not exist, it will be created, otherwise it will be updated.
|
|
14
|
+
*
|
|
15
|
+
* @param subjects - The subjects to upsert
|
|
16
|
+
* @param signal - An optional abort signal
|
|
17
|
+
* @returns The upserted subjects
|
|
18
|
+
*/
|
|
19
|
+
async upsert(subjects, options) {
|
|
20
|
+
const resp = await this.client.POST('/api/v1/subjects', {
|
|
21
|
+
body: Array.isArray(subjects) ? subjects : [subjects],
|
|
22
|
+
...options,
|
|
23
|
+
});
|
|
24
|
+
return transformResponse(resp);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get a subject by ID or key
|
|
28
|
+
* @param idOrKey - The ID or key of the subject
|
|
29
|
+
* @param signal - An optional abort signal
|
|
30
|
+
* @returns The subject
|
|
31
|
+
*/
|
|
32
|
+
async get(idOrKey, options) {
|
|
33
|
+
const resp = await this.client.GET('/api/v1/subjects/{subjectIdOrKey}', {
|
|
34
|
+
params: {
|
|
35
|
+
path: {
|
|
36
|
+
subjectIdOrKey: idOrKey,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
...options,
|
|
40
|
+
});
|
|
41
|
+
return transformResponse(resp);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* List subjects
|
|
45
|
+
* @param signal - An optional abort signal
|
|
46
|
+
* @returns The subjects
|
|
47
|
+
*/
|
|
48
|
+
async list(options) {
|
|
49
|
+
const resp = await this.client.GET('/api/v1/subjects', {
|
|
50
|
+
...options,
|
|
51
|
+
});
|
|
52
|
+
return transformResponse(resp);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Delete a subject by ID or key
|
|
56
|
+
* @param idOrKey - The ID or key of the subject
|
|
57
|
+
* @param signal - An optional abort signal
|
|
58
|
+
* @returns The deleted subject
|
|
59
|
+
*/
|
|
60
|
+
async delete(idOrKey, options) {
|
|
61
|
+
const resp = await this.client.DELETE('/api/v1/subjects/{subjectIdOrKey}', {
|
|
62
|
+
params: {
|
|
63
|
+
path: {
|
|
64
|
+
subjectIdOrKey: idOrKey,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
...options,
|
|
68
|
+
});
|
|
69
|
+
return transformResponse(resp);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=subjects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subjects.js","sourceRoot":"","sources":["../../../src/client/subjects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAK9C;;;GAGG;AACH,MAAM,OAAO,QAAQ;IACC;IAApB,YAAoB,MAA4C;QAA5C,WAAM,GAAN,MAAM,CAAsC;IAAG,CAAC;IAEpE;;;;;;;OAOG;IACI,KAAK,CAAC,MAAM,CACjB,QAAyC,EACzC,OAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE;YACtD,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;YACrD,GAAG,OAAO;SACX,CAAC,CAAA;QAEF,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,GAAG,CACd,OAAyE,EACzE,OAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,mCAAmC,EAAE;YACtE,MAAM,EAAE;gBACN,IAAI,EAAE;oBACJ,cAAc,EAAE,OAAO;iBACxB;aACF;YACD,GAAG,OAAO;SACX,CAAC,CAAA;QAEF,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,IAAI,CAAC,OAAwB;QACxC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,kBAAkB,EAAE;YACrD,GAAG,OAAO;SACX,CAAC,CAAA;QAEF,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,MAAM,CACjB,OAA4E,EAC5E,OAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,mCAAmC,EAAE;YACzE,MAAM,EAAE;gBACN,IAAI,EAAE;oBACJ,cAAc,EAAE,OAAO;iBACxB;aACF;YACD,GAAG,OAAO;SACX,CAAC,CAAA;QAEF,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { RequestOptions } from './common.js';
|
|
2
|
+
import type { operations, paths, SubscriptionChange, SubscriptionCreate, SubscriptionEdit } from './schemas.js';
|
|
3
|
+
import type { Client } from 'openapi-fetch';
|
|
4
|
+
/**
|
|
5
|
+
* Subscriptions
|
|
6
|
+
*/
|
|
7
|
+
export declare class Subscriptions {
|
|
8
|
+
private readonly client;
|
|
9
|
+
constructor(client: Client<paths, `${string}/${string}`>);
|
|
10
|
+
/**
|
|
11
|
+
* Create a subscription
|
|
12
|
+
* @param body - The subscription to create
|
|
13
|
+
* @param signal - An optional abort signal
|
|
14
|
+
* @returns The created subscription
|
|
15
|
+
*/
|
|
16
|
+
create(body: SubscriptionCreate, options?: RequestOptions): Promise<{
|
|
17
|
+
readonly id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
metadata?: import("./schemas.js").components["schemas"]["Metadata"] | null;
|
|
21
|
+
readonly createdAt: Date;
|
|
22
|
+
readonly updatedAt: Date;
|
|
23
|
+
readonly deletedAt?: Date;
|
|
24
|
+
activeFrom: Date;
|
|
25
|
+
activeTo?: Date;
|
|
26
|
+
alignment?: import("./schemas.js").components["schemas"]["Alignment"];
|
|
27
|
+
readonly status: import("./schemas.js").components["schemas"]["SubscriptionStatus"];
|
|
28
|
+
customerId: string;
|
|
29
|
+
plan?: import("./schemas.js").components["schemas"]["PlanReference"];
|
|
30
|
+
currency: import("./schemas.js").components["schemas"]["CurrencyCode"];
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Get a subscription
|
|
34
|
+
* @param id - The subscription ID
|
|
35
|
+
* @param signal - An optional abort signal
|
|
36
|
+
* @returns The subscription
|
|
37
|
+
*/
|
|
38
|
+
get(id: operations['getSubscription']['parameters']['path']['subscriptionId'], options?: RequestOptions): Promise<{
|
|
39
|
+
readonly id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
metadata?: import("./schemas.js").components["schemas"]["Metadata"] | null;
|
|
43
|
+
readonly createdAt: Date;
|
|
44
|
+
readonly updatedAt: Date;
|
|
45
|
+
readonly deletedAt?: Date;
|
|
46
|
+
activeFrom: Date;
|
|
47
|
+
activeTo?: Date;
|
|
48
|
+
readonly status: import("./schemas.js").components["schemas"]["SubscriptionStatus"];
|
|
49
|
+
customerId: string;
|
|
50
|
+
plan?: import("./schemas.js").components["schemas"]["PlanReference"];
|
|
51
|
+
currency: import("./schemas.js").components["schemas"]["CurrencyCode"];
|
|
52
|
+
alignment?: import("./schemas.js").components["schemas"]["SubscriptionAlignment"];
|
|
53
|
+
phases: import("./schemas.js").components["schemas"]["SubscriptionPhaseExpanded"][];
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Edit a subscription
|
|
57
|
+
* @param id - The subscription ID
|
|
58
|
+
* @param body - The subscription to edit
|
|
59
|
+
* @param signal - An optional abort signal
|
|
60
|
+
* @returns The edited subscription
|
|
61
|
+
*/
|
|
62
|
+
edit(id: operations['editSubscription']['parameters']['path']['subscriptionId'], body: SubscriptionEdit, options?: RequestOptions): Promise<{
|
|
63
|
+
readonly id: string;
|
|
64
|
+
name: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
metadata?: import("./schemas.js").components["schemas"]["Metadata"] | null;
|
|
67
|
+
readonly createdAt: Date;
|
|
68
|
+
readonly updatedAt: Date;
|
|
69
|
+
readonly deletedAt?: Date;
|
|
70
|
+
activeFrom: Date;
|
|
71
|
+
activeTo?: Date;
|
|
72
|
+
alignment?: import("./schemas.js").components["schemas"]["Alignment"];
|
|
73
|
+
readonly status: import("./schemas.js").components["schemas"]["SubscriptionStatus"];
|
|
74
|
+
customerId: string;
|
|
75
|
+
plan?: import("./schemas.js").components["schemas"]["PlanReference"];
|
|
76
|
+
currency: import("./schemas.js").components["schemas"]["CurrencyCode"];
|
|
77
|
+
}>;
|
|
78
|
+
/**
|
|
79
|
+
* Cancel a subscription
|
|
80
|
+
* @param id - The subscription ID
|
|
81
|
+
* @param body - The subscription to cancel
|
|
82
|
+
* @param signal - An optional abort signal
|
|
83
|
+
* @returns The canceled subscription
|
|
84
|
+
*/
|
|
85
|
+
cancel(id: operations['cancelSubscription']['parameters']['path']['subscriptionId'], body: operations['cancelSubscription']['requestBody']['content']['application/json'], options?: RequestOptions): Promise<{
|
|
86
|
+
readonly id: string;
|
|
87
|
+
name: string;
|
|
88
|
+
description?: string;
|
|
89
|
+
metadata?: import("./schemas.js").components["schemas"]["Metadata"] | null;
|
|
90
|
+
readonly createdAt: Date;
|
|
91
|
+
readonly updatedAt: Date;
|
|
92
|
+
readonly deletedAt?: Date;
|
|
93
|
+
activeFrom: Date;
|
|
94
|
+
activeTo?: Date;
|
|
95
|
+
alignment?: import("./schemas.js").components["schemas"]["Alignment"];
|
|
96
|
+
readonly status: import("./schemas.js").components["schemas"]["SubscriptionStatus"];
|
|
97
|
+
customerId: string;
|
|
98
|
+
plan?: import("./schemas.js").components["schemas"]["PlanReference"];
|
|
99
|
+
currency: import("./schemas.js").components["schemas"]["CurrencyCode"];
|
|
100
|
+
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Change a subscription
|
|
103
|
+
* @description Closes a running subscription and starts a new one according to the specification. Can be used for upgrades, downgrades, and plan changes.
|
|
104
|
+
* @param id - The subscription ID
|
|
105
|
+
* @param body - The subscription to change
|
|
106
|
+
* @param signal - An optional abort signal
|
|
107
|
+
* @returns The changed subscription
|
|
108
|
+
*/
|
|
109
|
+
change(id: operations['changeSubscription']['parameters']['path']['subscriptionId'], body: SubscriptionChange, options?: RequestOptions): Promise<{
|
|
110
|
+
current: import("./schemas.js").components["schemas"]["Subscription"];
|
|
111
|
+
next: import("./schemas.js").components["schemas"]["SubscriptionExpanded"];
|
|
112
|
+
}>;
|
|
113
|
+
/**
|
|
114
|
+
* Migrate a subscription
|
|
115
|
+
* @description Migrates the subscripiton to the provided version of the current plan.
|
|
116
|
+
* @param id - The subscription ID
|
|
117
|
+
* @param body - The subscription to migrate
|
|
118
|
+
* @param signal - An optional abort signal
|
|
119
|
+
* @returns The migrated subscription
|
|
120
|
+
*/
|
|
121
|
+
migrate(id: operations['migrateSubscription']['parameters']['path']['subscriptionId'], body: operations['migrateSubscription']['requestBody']['content']['application/json'], options?: RequestOptions): Promise<{
|
|
122
|
+
current: import("./schemas.js").components["schemas"]["Subscription"];
|
|
123
|
+
next: import("./schemas.js").components["schemas"]["SubscriptionExpanded"];
|
|
124
|
+
}>;
|
|
125
|
+
/**
|
|
126
|
+
* Unschedule a cancelation
|
|
127
|
+
* @param id - The subscription ID
|
|
128
|
+
* @param signal - An optional abort signal
|
|
129
|
+
* @returns The unscheduled subscription
|
|
130
|
+
*/
|
|
131
|
+
unscheduleCancelation(id: operations['unscheduleCancelation']['parameters']['path']['subscriptionId'], options?: RequestOptions): Promise<{
|
|
132
|
+
readonly id: string;
|
|
133
|
+
name: string;
|
|
134
|
+
description?: string;
|
|
135
|
+
metadata?: import("./schemas.js").components["schemas"]["Metadata"] | null;
|
|
136
|
+
readonly createdAt: Date;
|
|
137
|
+
readonly updatedAt: Date;
|
|
138
|
+
readonly deletedAt?: Date;
|
|
139
|
+
activeFrom: Date;
|
|
140
|
+
activeTo?: Date;
|
|
141
|
+
alignment?: import("./schemas.js").components["schemas"]["Alignment"];
|
|
142
|
+
readonly status: import("./schemas.js").components["schemas"]["SubscriptionStatus"];
|
|
143
|
+
customerId: string;
|
|
144
|
+
plan?: import("./schemas.js").components["schemas"]["PlanReference"];
|
|
145
|
+
currency: import("./schemas.js").components["schemas"]["CurrencyCode"];
|
|
146
|
+
}>;
|
|
147
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { transformResponse } from './utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Subscriptions
|
|
4
|
+
*/
|
|
5
|
+
export class Subscriptions {
|
|
6
|
+
client;
|
|
7
|
+
constructor(client) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create a subscription
|
|
12
|
+
* @param body - The subscription to create
|
|
13
|
+
* @param signal - An optional abort signal
|
|
14
|
+
* @returns The created subscription
|
|
15
|
+
*/
|
|
16
|
+
async create(body, options) {
|
|
17
|
+
const resp = await this.client.POST('/api/v1/subscriptions', {
|
|
18
|
+
body,
|
|
19
|
+
...options,
|
|
20
|
+
});
|
|
21
|
+
return transformResponse(resp);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get a subscription
|
|
25
|
+
* @param id - The subscription ID
|
|
26
|
+
* @param signal - An optional abort signal
|
|
27
|
+
* @returns The subscription
|
|
28
|
+
*/
|
|
29
|
+
async get(id, options) {
|
|
30
|
+
const resp = await this.client.GET('/api/v1/subscriptions/{subscriptionId}', {
|
|
31
|
+
params: { path: { subscriptionId: id } },
|
|
32
|
+
...options,
|
|
33
|
+
});
|
|
34
|
+
return transformResponse(resp);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Edit a subscription
|
|
38
|
+
* @param id - The subscription ID
|
|
39
|
+
* @param body - The subscription to edit
|
|
40
|
+
* @param signal - An optional abort signal
|
|
41
|
+
* @returns The edited subscription
|
|
42
|
+
*/
|
|
43
|
+
async edit(id, body, options) {
|
|
44
|
+
const resp = await this.client.PATCH('/api/v1/subscriptions/{subscriptionId}', {
|
|
45
|
+
body,
|
|
46
|
+
params: { path: { subscriptionId: id } },
|
|
47
|
+
...options,
|
|
48
|
+
});
|
|
49
|
+
return transformResponse(resp);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Cancel a subscription
|
|
53
|
+
* @param id - The subscription ID
|
|
54
|
+
* @param body - The subscription to cancel
|
|
55
|
+
* @param signal - An optional abort signal
|
|
56
|
+
* @returns The canceled subscription
|
|
57
|
+
*/
|
|
58
|
+
async cancel(id, body, options) {
|
|
59
|
+
const resp = await this.client.POST('/api/v1/subscriptions/{subscriptionId}/cancel', {
|
|
60
|
+
body,
|
|
61
|
+
params: { path: { subscriptionId: id } },
|
|
62
|
+
...options,
|
|
63
|
+
});
|
|
64
|
+
return transformResponse(resp);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Change a subscription
|
|
68
|
+
* @description Closes a running subscription and starts a new one according to the specification. Can be used for upgrades, downgrades, and plan changes.
|
|
69
|
+
* @param id - The subscription ID
|
|
70
|
+
* @param body - The subscription to change
|
|
71
|
+
* @param signal - An optional abort signal
|
|
72
|
+
* @returns The changed subscription
|
|
73
|
+
*/
|
|
74
|
+
async change(id, body, options) {
|
|
75
|
+
const resp = await this.client.POST('/api/v1/subscriptions/{subscriptionId}/change', {
|
|
76
|
+
body,
|
|
77
|
+
params: { path: { subscriptionId: id } },
|
|
78
|
+
...options,
|
|
79
|
+
});
|
|
80
|
+
return transformResponse(resp);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Migrate a subscription
|
|
84
|
+
* @description Migrates the subscripiton to the provided version of the current plan.
|
|
85
|
+
* @param id - The subscription ID
|
|
86
|
+
* @param body - The subscription to migrate
|
|
87
|
+
* @param signal - An optional abort signal
|
|
88
|
+
* @returns The migrated subscription
|
|
89
|
+
*/
|
|
90
|
+
async migrate(id, body, options) {
|
|
91
|
+
const resp = await this.client.POST('/api/v1/subscriptions/{subscriptionId}/migrate', {
|
|
92
|
+
body,
|
|
93
|
+
params: { path: { subscriptionId: id } },
|
|
94
|
+
...options,
|
|
95
|
+
});
|
|
96
|
+
return transformResponse(resp);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Unschedule a cancelation
|
|
100
|
+
* @param id - The subscription ID
|
|
101
|
+
* @param signal - An optional abort signal
|
|
102
|
+
* @returns The unscheduled subscription
|
|
103
|
+
*/
|
|
104
|
+
async unscheduleCancelation(id, options) {
|
|
105
|
+
const resp = await this.client.POST('/api/v1/subscriptions/{subscriptionId}/unschedule-cancelation', {
|
|
106
|
+
params: { path: { subscriptionId: id } },
|
|
107
|
+
...options,
|
|
108
|
+
});
|
|
109
|
+
return transformResponse(resp);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=subscriptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptions.js","sourceRoot":"","sources":["../../../src/client/subscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAW9C;;GAEG;AACH,MAAM,OAAO,aAAa;IACK;IAA7B,YAA6B,MAA4C;QAA5C,WAAM,GAAN,MAAM,CAAsC;IAAG,CAAC;IAE7E;;;;;OAKG;IACI,KAAK,CAAC,MAAM,CAAC,IAAwB,EAAE,OAAwB;QACpE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,uBAAuB,EAAE;YAC3D,IAAI;YACJ,GAAG,OAAO;SACX,CAAC,CAAA;QAEF,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,GAAG,CACd,EAAyE,EACzE,OAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAChC,wCAAwC,EACxC;YACE,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,EAAE;YACxC,GAAG,OAAO;SACX,CACF,CAAA;QAED,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,IAAI,CACf,EAA0E,EAC1E,IAAsB,EACtB,OAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAClC,wCAAwC,EACxC;YACE,IAAI;YACJ,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,EAAE;YACxC,GAAG,OAAO;SACX,CACF,CAAA;QAED,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,MAAM,CACjB,EAA4E,EAC5E,IAAoF,EACpF,OAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACjC,+CAA+C,EAC/C;YACE,IAAI;YACJ,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,EAAE;YACxC,GAAG,OAAO;SACX,CACF,CAAA;QAED,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,MAAM,CACjB,EAA4E,EAC5E,IAAwB,EACxB,OAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACjC,+CAA+C,EAC/C;YACE,IAAI;YACJ,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,EAAE;YACxC,GAAG,OAAO;SACX,CACF,CAAA;QAED,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,OAAO,CAClB,EAA6E,EAC7E,IAAqF,EACrF,OAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACjC,gDAAgD,EAChD;YACE,IAAI;YACJ,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,EAAE;YACxC,GAAG,OAAO;SACX,CACF,CAAA;QAED,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,qBAAqB,CAChC,EAA+E,EAC/E,OAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACjC,+DAA+D,EAC/D;YACE,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,EAAE;YACxC,GAAG,OAAO;SACX,CACF,CAAA;QAED,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FetchResponse, ParseAsResponse } from 'openapi-fetch';
|
|
2
|
+
import type { MediaType, ResponseObjectMap, SuccessResponse } from 'openapi-typescript-helpers';
|
|
3
|
+
/**
|
|
4
|
+
* Transform a response from the API
|
|
5
|
+
* @param resp - The response to transform
|
|
6
|
+
* @throws HTTPError if the response is an error
|
|
7
|
+
* @returns The transformed response
|
|
8
|
+
*/
|
|
9
|
+
export declare function transformResponse<T extends Record<string | number, any>, Options, Media extends MediaType>(resp: FetchResponse<T, Options, Media>): ParseAsResponse<SuccessResponse<ResponseObjectMap<T>, Media>, Options> | never;
|
|
10
|
+
export declare function isIsoDateString(value: unknown): value is string;
|
|
11
|
+
export declare function decodeDates<T>(data: T): T;
|
|
12
|
+
export declare function encodeDates<T>(data: T): T;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { HTTPError } from './common.js';
|
|
2
|
+
/**
|
|
3
|
+
* Transform a response from the API
|
|
4
|
+
* @param resp - The response to transform
|
|
5
|
+
* @throws HTTPError if the response is an error
|
|
6
|
+
* @returns The transformed response
|
|
7
|
+
*/
|
|
8
|
+
export function transformResponse(resp) {
|
|
9
|
+
// Handle errors
|
|
10
|
+
if (resp.error || resp.response.status >= 400) {
|
|
11
|
+
throw HTTPError.fromResponse(resp);
|
|
12
|
+
}
|
|
13
|
+
// Decode dates
|
|
14
|
+
if (resp.data) {
|
|
15
|
+
resp.data = decodeDates(resp.data);
|
|
16
|
+
}
|
|
17
|
+
return resp.data;
|
|
18
|
+
}
|
|
19
|
+
const ISODateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d*)?(?:[-+]\d{2}:?\d{2}|Z)?$/;
|
|
20
|
+
export function isIsoDateString(value) {
|
|
21
|
+
return typeof value === 'string' && ISODateFormat.test(value);
|
|
22
|
+
}
|
|
23
|
+
export function decodeDates(data) {
|
|
24
|
+
// if it's a date string, return a date
|
|
25
|
+
if (isIsoDateString(data)) {
|
|
26
|
+
return new Date(data);
|
|
27
|
+
}
|
|
28
|
+
// if it's not an object or array, return it
|
|
29
|
+
if (data === null || data === undefined || typeof data !== 'object') {
|
|
30
|
+
return data;
|
|
31
|
+
}
|
|
32
|
+
// if it's an array, decode each element
|
|
33
|
+
if (Array.isArray(data)) {
|
|
34
|
+
return data.map((val) => decodeDates(val));
|
|
35
|
+
}
|
|
36
|
+
// if it's an object, decode each key
|
|
37
|
+
for (const [key, val] of Object.entries(data)) {
|
|
38
|
+
// @ts-expect-error we know this will give back the same type
|
|
39
|
+
data[key] = decodeDates(val);
|
|
40
|
+
}
|
|
41
|
+
return data;
|
|
42
|
+
}
|
|
43
|
+
export function encodeDates(data) {
|
|
44
|
+
// if it's a date, return a date string
|
|
45
|
+
if (data instanceof Date) {
|
|
46
|
+
return data.toISOString();
|
|
47
|
+
}
|
|
48
|
+
// if it's not an object or array, return it
|
|
49
|
+
if (data === null || data === undefined || typeof data !== 'object') {
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
// if it's an array, encode each element
|
|
53
|
+
if (Array.isArray(data)) {
|
|
54
|
+
return data.map((val) => encodeDates(val));
|
|
55
|
+
}
|
|
56
|
+
// if it's an object, encode each key
|
|
57
|
+
for (const [key, val] of Object.entries(data)) {
|
|
58
|
+
// @ts-expect-error we know this will give back the same type
|
|
59
|
+
data[key] = encodeDates(val);
|
|
60
|
+
}
|
|
61
|
+
return data;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/client/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAQvC;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAK/B,IAAsC;IAItC,gBAAgB;IAChB,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;QAC9C,MAAM,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;IACpC,CAAC;IAED,eAAe;IACf,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACpC,CAAC;IAED,OAAO,IAAI,CAAC,IAAK,CAAA;AACnB,CAAC;AAED,MAAM,aAAa,GACjB,wEAAwE,CAAA;AAE1E,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAC/D,CAAC;AAED,MAAM,UAAU,WAAW,CAAI,IAAO;IACpC,uCAAuC;IACvC,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,OAAO,IAAI,IAAI,CAAC,IAAI,CAAM,CAAA;IAC5B,CAAC;IAED,4CAA4C;IAC5C,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACpE,OAAO,IAAI,CAAA;IACb,CAAC;IAED,wCAAwC;IACxC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAM,CAAA;IACjD,CAAC;IAED,qCAAqC;IACrC,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9C,6DAA6D;QAC7D,IAAI,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;IAC9B,CAAC;IAED,OAAO,IAAS,CAAA;AAClB,CAAC;AAED,MAAM,UAAU,WAAW,CAAI,IAAO;IACpC,uCAAuC;IACvC,IAAI,IAAI,YAAY,IAAI,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC,WAAW,EAAO,CAAA;IAChC,CAAC;IAED,4CAA4C;IAC5C,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACpE,OAAO,IAAI,CAAA;IACb,CAAC;IAED,wCAAwC;IACxC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAM,CAAA;IACjD,CAAC;IAED,qCAAqC;IACrC,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9C,6DAA6D;QAC7D,IAAI,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;IAC9B,CAAC;IAED,OAAO,IAAS,CAAA;AAClB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { RequestOptions } from '../client/common.js';
|
|
2
|
+
import type { ClientOptions } from 'openapi-fetch';
|
|
3
|
+
/**
|
|
4
|
+
* Portal Config
|
|
5
|
+
*/
|
|
6
|
+
export type Config = Pick<ClientOptions, 'baseUrl' | 'headers' | 'fetch' | 'Request' | 'requestInitExt'> & {
|
|
7
|
+
portalToken: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* OpenMeter Portal Client
|
|
11
|
+
* Access to the customer portal.
|
|
12
|
+
*/
|
|
13
|
+
export declare class OpenMeter {
|
|
14
|
+
private client;
|
|
15
|
+
constructor(config: Config);
|
|
16
|
+
/**
|
|
17
|
+
* Query usage data for a meter by slug for customer portal.
|
|
18
|
+
* This endpoint is publicly exposable to consumers.
|
|
19
|
+
* @param meterSlug - The slug of the meter
|
|
20
|
+
* @param query - The query parameters
|
|
21
|
+
* @param signal - An optional abort signal
|
|
22
|
+
* @returns The meter data
|
|
23
|
+
*/
|
|
24
|
+
query(meterSlug: string, query?: {
|
|
25
|
+
/** @description Start date-time in RFC 3339 format. Inclusive. */
|
|
26
|
+
from?: string | Date;
|
|
27
|
+
/** @description End date-time in RFC 3339 format. Inclusive. */
|
|
28
|
+
to?: string | 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. */
|
|
30
|
+
windowSize?: 'MINUTE' | 'HOUR' | 'DAY';
|
|
31
|
+
/** @description The value is the name of the time zone as defined in the IANA Time Zone Database (http://www.iana.org/time-zones). If not specified, the UTC timezone will be used. */
|
|
32
|
+
windowTimeZone?: string;
|
|
33
|
+
/** @description Simple filter for group bys with exact match. */
|
|
34
|
+
filterGroupBy?: Record<string, string>;
|
|
35
|
+
/** @description If not specified a single aggregate will be returned for each subject and time window. `subject` is a reserved group by value. */
|
|
36
|
+
groupBy?: string[];
|
|
37
|
+
}, options?: RequestOptions): Promise<{
|
|
38
|
+
from?: Date;
|
|
39
|
+
to?: Date;
|
|
40
|
+
windowSize?: import("../client/schemas.js").components["schemas"]["WindowSize"];
|
|
41
|
+
data: import("../client/schemas.js").components["schemas"]["MeterQueryRow"][];
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import createClient from 'openapi-fetch';
|
|
2
|
+
import { createQuerySerializer } from 'openapi-fetch/dist/cjs/index.cjs';
|
|
3
|
+
import { encodeDates, transformResponse } from '../client/utils.js';
|
|
4
|
+
/**
|
|
5
|
+
* OpenMeter Portal Client
|
|
6
|
+
* Access to the customer portal.
|
|
7
|
+
*/
|
|
8
|
+
export class OpenMeter {
|
|
9
|
+
client;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.client = createClient({
|
|
12
|
+
...config,
|
|
13
|
+
headers: {
|
|
14
|
+
...config.headers,
|
|
15
|
+
Authorization: `Bearer ${config.portalToken}`,
|
|
16
|
+
},
|
|
17
|
+
querySerializer: (q) => createQuerySerializer({
|
|
18
|
+
array: {
|
|
19
|
+
explode: true,
|
|
20
|
+
style: 'form',
|
|
21
|
+
},
|
|
22
|
+
object: {
|
|
23
|
+
explode: true,
|
|
24
|
+
style: 'deepObject',
|
|
25
|
+
},
|
|
26
|
+
})(encodeDates(q)),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Query usage data for a meter by slug for customer portal.
|
|
31
|
+
* This endpoint is publicly exposable to consumers.
|
|
32
|
+
* @param meterSlug - The slug of the meter
|
|
33
|
+
* @param query - The query parameters
|
|
34
|
+
* @param signal - An optional abort signal
|
|
35
|
+
* @returns The meter data
|
|
36
|
+
*/
|
|
37
|
+
async query(meterSlug, query, options) {
|
|
38
|
+
const resp = await this.client.GET('/api/v1/portal/meters/{meterSlug}/query', {
|
|
39
|
+
headers: {
|
|
40
|
+
Accept: 'application/json',
|
|
41
|
+
},
|
|
42
|
+
params: {
|
|
43
|
+
path: {
|
|
44
|
+
meterSlug,
|
|
45
|
+
},
|
|
46
|
+
query,
|
|
47
|
+
},
|
|
48
|
+
...options,
|
|
49
|
+
});
|
|
50
|
+
return transformResponse(resp);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/portal/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AACxE,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAenE;;;GAGG;AACH,MAAM,OAAO,SAAS;IACZ,MAAM,CAAsC;IAEpD,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,YAAY,CAAQ;YAChC,GAAG,MAAM;YACT,OAAO,EAAE;gBACP,GAAG,MAAM,CAAC,OAAO;gBACjB,aAAa,EAAE,UAAU,MAAM,CAAC,WAAW,EAAE;aAC9C;YACD,eAAe,EAAE,CAAC,CAAC,EAAE,EAAE,CACrB,qBAAqB,CAAC;gBACpB,KAAK,EAAE;oBACL,OAAO,EAAE,IAAI;oBACb,KAAK,EAAE,MAAM;iBACd;gBACD,MAAM,EAAE;oBACN,OAAO,EAAE,IAAI;oBACb,KAAK,EAAE,YAAY;iBACpB;aACF,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;SACrB,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,KAAK,CAChB,SAAiB,EACjB,KAaC,EACD,OAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAChC,yCAAyC,EACzC;YACE,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;aAC3B;YACD,MAAM,EAAE;gBACN,IAAI,EAAE;oBACJ,SAAS;iBACV;gBACD,KAAK;aACN;YACD,GAAG,OAAO;SACX,CACF,CAAA;QAED,OAAO,iBAAiB,CACtB,IAAI,CACgF,CAAA;IACxF,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OpenMeter } from '../portal/index.js';
|
|
2
|
+
export * from '../portal/index.js';
|
|
3
|
+
export declare const OpenMeterContext: import("react").Context<OpenMeter | null>;
|
|
4
|
+
export type OpenMeterProviderProps = {
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
value: OpenMeter | null;
|
|
7
|
+
};
|
|
8
|
+
export declare function OpenMeterProvider({ children, value }: OpenMeterProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export declare function useOpenMeter(): OpenMeter | null;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext } from 'react';
|
|
4
|
+
export * from '../portal/index.js';
|
|
5
|
+
export const OpenMeterContext = createContext(null);
|
|
6
|
+
export function OpenMeterProvider({ children, value }) {
|
|
7
|
+
return (_jsx(OpenMeterContext.Provider, { value: value, children: children }));
|
|
8
|
+
}
|
|
9
|
+
export function useOpenMeter() {
|
|
10
|
+
const context = useContext(OpenMeterContext);
|
|
11
|
+
if (typeof context === 'undefined') {
|
|
12
|
+
throw new Error('useOpenMeter must be used within a OpenMeterProvider');
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/react/context.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAGjD,cAAc,oBAAoB,CAAA;AAElC,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAmB,IAAI,CAAC,CAAA;AAOrE,MAAM,UAAU,iBAAiB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAA0B;IAC3E,OAAO,CACL,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACpC,QAAQ,GACiB,CAC7B,CAAA;AACH,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,MAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAC5C,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;IACzE,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
|