@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
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
import type { RequestOptions } from './common.cjs';
|
|
2
|
+
import type { EntitlementCreateInputs, EntitlementGrantCreateInput, operations, paths, ResetEntitlementUsageInput } from './schemas.cjs';
|
|
3
|
+
import type { Client } from 'openapi-fetch';
|
|
4
|
+
/**
|
|
5
|
+
* Entitlements
|
|
6
|
+
* @description With Entitlements, you can define and enforce usage limits, implement quota-based pricing, and manage access to features in your application.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Entitlements {
|
|
9
|
+
private client;
|
|
10
|
+
grants: Grants;
|
|
11
|
+
constructor(client: Client<paths, `${string}/${string}`>);
|
|
12
|
+
/**
|
|
13
|
+
* Create an entitlement
|
|
14
|
+
*
|
|
15
|
+
* - Boolean entitlements define static feature access, e.g. "Can use SSO authentication".
|
|
16
|
+
* - Static entitlements let you pass along a configuration while granting access, e.g. "Using this feature with X Y settings" (passed in the config).
|
|
17
|
+
* - Metered entitlements have many use cases, from setting up usage-based access to implementing complex credit systems. Example: The customer can use 10000 AI tokens during the usage period of the entitlement.
|
|
18
|
+
*
|
|
19
|
+
* A given subject can only have one active (non-deleted) entitlement per featureKey. If you try to create a new entitlement for a featureKey that already has an active entitlement, the request will fail with a 409 error.
|
|
20
|
+
*
|
|
21
|
+
* Once an entitlement is created you cannot modify it, only delete it.
|
|
22
|
+
*
|
|
23
|
+
* @param subjectIdOrKey - The ID or key of the subject
|
|
24
|
+
* @param entitlement - The entitlement to create
|
|
25
|
+
* @param signal - An optional abort signal
|
|
26
|
+
* @returns The created entitlement
|
|
27
|
+
*/
|
|
28
|
+
create(subjectIdOrKey: operations['createEntitlement']['parameters']['path']['subjectIdOrKey'], entitlement: EntitlementCreateInputs, options?: RequestOptions): Promise<import("openapi-typescript-helpers").SuccessResponse<{
|
|
29
|
+
201: {
|
|
30
|
+
headers: {
|
|
31
|
+
[name: string]: unknown;
|
|
32
|
+
};
|
|
33
|
+
content: {
|
|
34
|
+
"application/json": import("./schemas.cjs").components["schemas"]["Entitlement"];
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
400: {
|
|
38
|
+
headers: {
|
|
39
|
+
[name: string]: unknown;
|
|
40
|
+
};
|
|
41
|
+
content: {
|
|
42
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["BadRequestProblemResponse"];
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
401: {
|
|
46
|
+
headers: {
|
|
47
|
+
[name: string]: unknown;
|
|
48
|
+
};
|
|
49
|
+
content: {
|
|
50
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["UnauthorizedProblemResponse"];
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
403: {
|
|
54
|
+
headers: {
|
|
55
|
+
[name: string]: unknown;
|
|
56
|
+
};
|
|
57
|
+
content: {
|
|
58
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["ForbiddenProblemResponse"];
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
409: {
|
|
62
|
+
headers: {
|
|
63
|
+
[name: string]: unknown;
|
|
64
|
+
};
|
|
65
|
+
content: {
|
|
66
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["ConflictProblemResponse"];
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
412: {
|
|
70
|
+
headers: {
|
|
71
|
+
[name: string]: unknown;
|
|
72
|
+
};
|
|
73
|
+
content: {
|
|
74
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["PreconditionFailedProblemResponse"];
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
500: {
|
|
78
|
+
headers: {
|
|
79
|
+
[name: string]: unknown;
|
|
80
|
+
};
|
|
81
|
+
content: {
|
|
82
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["InternalServerErrorProblemResponse"];
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
503: {
|
|
86
|
+
headers: {
|
|
87
|
+
[name: string]: unknown;
|
|
88
|
+
};
|
|
89
|
+
content: {
|
|
90
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["ServiceUnavailableProblemResponse"];
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
default: {
|
|
94
|
+
headers: {
|
|
95
|
+
[name: string]: unknown;
|
|
96
|
+
};
|
|
97
|
+
content: {
|
|
98
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["UnexpectedProblemResponse"];
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
}, `${string}/${string}`>>;
|
|
102
|
+
/**
|
|
103
|
+
* Get an entitlement by ID
|
|
104
|
+
*
|
|
105
|
+
* @param id - The ID of the entitlement
|
|
106
|
+
* @param signal - An optional abort signal
|
|
107
|
+
* @returns The entitlement
|
|
108
|
+
*/
|
|
109
|
+
get(id: operations['getEntitlement']['parameters']['path']['entitlementId'], options?: RequestOptions): Promise<import("openapi-typescript-helpers").SuccessResponse<{
|
|
110
|
+
200: {
|
|
111
|
+
headers: {
|
|
112
|
+
[name: string]: unknown;
|
|
113
|
+
};
|
|
114
|
+
content: {
|
|
115
|
+
"application/json": import("./schemas.cjs").components["schemas"]["Entitlement"];
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
400: {
|
|
119
|
+
headers: {
|
|
120
|
+
[name: string]: unknown;
|
|
121
|
+
};
|
|
122
|
+
content: {
|
|
123
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["BadRequestProblemResponse"];
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
401: {
|
|
127
|
+
headers: {
|
|
128
|
+
[name: string]: unknown;
|
|
129
|
+
};
|
|
130
|
+
content: {
|
|
131
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["UnauthorizedProblemResponse"];
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
403: {
|
|
135
|
+
headers: {
|
|
136
|
+
[name: string]: unknown;
|
|
137
|
+
};
|
|
138
|
+
content: {
|
|
139
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["ForbiddenProblemResponse"];
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
404: {
|
|
143
|
+
headers: {
|
|
144
|
+
[name: string]: unknown;
|
|
145
|
+
};
|
|
146
|
+
content: {
|
|
147
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["NotFoundProblemResponse"];
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
412: {
|
|
151
|
+
headers: {
|
|
152
|
+
[name: string]: unknown;
|
|
153
|
+
};
|
|
154
|
+
content: {
|
|
155
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["PreconditionFailedProblemResponse"];
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
500: {
|
|
159
|
+
headers: {
|
|
160
|
+
[name: string]: unknown;
|
|
161
|
+
};
|
|
162
|
+
content: {
|
|
163
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["InternalServerErrorProblemResponse"];
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
503: {
|
|
167
|
+
headers: {
|
|
168
|
+
[name: string]: unknown;
|
|
169
|
+
};
|
|
170
|
+
content: {
|
|
171
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["ServiceUnavailableProblemResponse"];
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
default: {
|
|
175
|
+
headers: {
|
|
176
|
+
[name: string]: unknown;
|
|
177
|
+
};
|
|
178
|
+
content: {
|
|
179
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["UnexpectedProblemResponse"];
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
}, `${string}/${string}`>>;
|
|
183
|
+
/**
|
|
184
|
+
* List entitlements
|
|
185
|
+
*
|
|
186
|
+
* @param query - The query parameters
|
|
187
|
+
* @param signal - An optional abort signal
|
|
188
|
+
* @returns The entitlements
|
|
189
|
+
*/
|
|
190
|
+
list(query?: Omit<operations['listEntitlements']['parameters']['query'], 'page' | 'pageSize'>, options?: RequestOptions): Promise<({
|
|
191
|
+
type: "metered";
|
|
192
|
+
isSoftLimit?: boolean;
|
|
193
|
+
isUnlimited?: boolean;
|
|
194
|
+
issueAfterReset?: number;
|
|
195
|
+
issueAfterResetPriority?: number;
|
|
196
|
+
preserveOverageAtReset?: boolean;
|
|
197
|
+
readonly createdAt: Date;
|
|
198
|
+
readonly updatedAt: Date;
|
|
199
|
+
readonly deletedAt?: Date;
|
|
200
|
+
metadata?: import("./schemas.cjs").components["schemas"]["Metadata"];
|
|
201
|
+
activeFrom: Date;
|
|
202
|
+
activeTo?: Date;
|
|
203
|
+
readonly annotations?: import("./schemas.cjs").components["schemas"]["Annotations"];
|
|
204
|
+
readonly id: string;
|
|
205
|
+
subjectKey: string;
|
|
206
|
+
featureKey: string;
|
|
207
|
+
featureId: string;
|
|
208
|
+
readonly lastReset: Date;
|
|
209
|
+
readonly currentUsagePeriod: import("./schemas.cjs").components["schemas"]["Period"];
|
|
210
|
+
readonly measureUsageFrom: Date;
|
|
211
|
+
readonly usagePeriod: import("./schemas.cjs").components["schemas"]["RecurringPeriod"];
|
|
212
|
+
} | {
|
|
213
|
+
type: "static";
|
|
214
|
+
config: string;
|
|
215
|
+
readonly createdAt: Date;
|
|
216
|
+
readonly updatedAt: Date;
|
|
217
|
+
readonly deletedAt?: Date;
|
|
218
|
+
metadata?: import("./schemas.cjs").components["schemas"]["Metadata"];
|
|
219
|
+
activeFrom: Date;
|
|
220
|
+
activeTo?: Date;
|
|
221
|
+
readonly annotations?: import("./schemas.cjs").components["schemas"]["Annotations"];
|
|
222
|
+
readonly id: string;
|
|
223
|
+
subjectKey: string;
|
|
224
|
+
featureKey: string;
|
|
225
|
+
featureId: string;
|
|
226
|
+
currentUsagePeriod?: import("./schemas.cjs").components["schemas"]["Period"];
|
|
227
|
+
usagePeriod?: import("./schemas.cjs").components["schemas"]["RecurringPeriod"];
|
|
228
|
+
} | ({
|
|
229
|
+
type: "boolean";
|
|
230
|
+
readonly createdAt: Date;
|
|
231
|
+
readonly updatedAt: Date;
|
|
232
|
+
readonly deletedAt?: Date;
|
|
233
|
+
metadata?: import("./schemas.cjs").components["schemas"]["Metadata"];
|
|
234
|
+
activeFrom: Date;
|
|
235
|
+
activeTo?: Date;
|
|
236
|
+
readonly annotations?: import("./schemas.cjs").components["schemas"]["Annotations"];
|
|
237
|
+
readonly id: string;
|
|
238
|
+
subjectKey: string;
|
|
239
|
+
featureKey: string;
|
|
240
|
+
featureId: string;
|
|
241
|
+
currentUsagePeriod?: import("./schemas.cjs").components["schemas"]["Period"];
|
|
242
|
+
usagePeriod?: import("./schemas.cjs").components["schemas"]["RecurringPeriod"];
|
|
243
|
+
} & {
|
|
244
|
+
readonly createdAt: Date;
|
|
245
|
+
readonly updatedAt: Date;
|
|
246
|
+
readonly deletedAt?: Date;
|
|
247
|
+
metadata?: import("./schemas.cjs").components["schemas"]["Metadata"];
|
|
248
|
+
activeFrom: Date;
|
|
249
|
+
activeTo?: Date;
|
|
250
|
+
readonly annotations?: import("./schemas.cjs").components["schemas"]["Annotations"];
|
|
251
|
+
readonly id: string;
|
|
252
|
+
type: import("./schemas.cjs").components["schemas"]["EntitlementType"];
|
|
253
|
+
subjectKey: string;
|
|
254
|
+
featureKey: string;
|
|
255
|
+
featureId: string;
|
|
256
|
+
currentUsagePeriod?: import("./schemas.cjs").components["schemas"]["Period"];
|
|
257
|
+
usagePeriod?: import("./schemas.cjs").components["schemas"]["RecurringPeriod"];
|
|
258
|
+
} & {
|
|
259
|
+
readonly id: string;
|
|
260
|
+
readonly createdAt: Date;
|
|
261
|
+
readonly updatedAt: Date;
|
|
262
|
+
type: import("./schemas.cjs").components["schemas"]["EntitlementType"];
|
|
263
|
+
activeFrom: Date;
|
|
264
|
+
subjectKey: string;
|
|
265
|
+
featureKey: string;
|
|
266
|
+
featureId: string;
|
|
267
|
+
} & {
|
|
268
|
+
type: "boolean";
|
|
269
|
+
}))[]>;
|
|
270
|
+
/**
|
|
271
|
+
* Delete an entitlement
|
|
272
|
+
*
|
|
273
|
+
* @param subjectIdOrKey - The ID or key of the subject
|
|
274
|
+
* @param entitlementId - The ID of the entitlement
|
|
275
|
+
* @param signal - An optional abort signal
|
|
276
|
+
* @returns The deleted entitlement
|
|
277
|
+
*/
|
|
278
|
+
delete(subjectIdOrKey: operations['deleteEntitlement']['parameters']['path']['subjectIdOrKey'], entitlementId: operations['deleteEntitlement']['parameters']['path']['entitlementId'], options?: RequestOptions): Promise<undefined>;
|
|
279
|
+
/**
|
|
280
|
+
* Get the value of an entitlement to check access
|
|
281
|
+
* All entitlement types share the hasAccess property in their value response, but multiple other properties are returned based on the entitlement type.
|
|
282
|
+
*
|
|
283
|
+
* @param subjectIdOrKey - The ID or key of the subject
|
|
284
|
+
* @param entitlementIdOrFeatureKey - The ID or feature key of the entitlement
|
|
285
|
+
* @param query - The query parameters
|
|
286
|
+
* @param signal - An optional abort signal
|
|
287
|
+
* @returns The entitlement value
|
|
288
|
+
*/
|
|
289
|
+
value(subjectIdOrKey: operations['getEntitlementValue']['parameters']['path']['subjectIdOrKey'], entitlementIdOrFeatureKey: operations['getEntitlementValue']['parameters']['path']['entitlementIdOrFeatureKey'], query?: operations['getEntitlementValue']['parameters']['query'], options?: RequestOptions): Promise<{
|
|
290
|
+
readonly hasAccess: boolean;
|
|
291
|
+
readonly balance?: number;
|
|
292
|
+
readonly usage?: number;
|
|
293
|
+
readonly overage?: number;
|
|
294
|
+
readonly config?: string;
|
|
295
|
+
}>;
|
|
296
|
+
/**
|
|
297
|
+
* Get the history of an entitlement
|
|
298
|
+
* Returns historical balance and usage data for the entitlement. The queried history can span accross multiple reset events.
|
|
299
|
+
*
|
|
300
|
+
* @param subjectIdOrKey - The ID or key of the subject
|
|
301
|
+
* @param entitlementId - The ID of the entitlement
|
|
302
|
+
* @param query - The query parameters
|
|
303
|
+
* @param signal - An optional abort signal
|
|
304
|
+
* @returns The history of the entitlement
|
|
305
|
+
*/
|
|
306
|
+
history(subjectIdOrKey: operations['getEntitlementHistory']['parameters']['path']['subjectIdOrKey'], entitlementId: operations['getEntitlementHistory']['parameters']['path']['entitlementId'], query: operations['getEntitlementHistory']['parameters']['query'], options?: RequestOptions): Promise<{
|
|
307
|
+
windowedHistory: import("./schemas.cjs").components["schemas"]["BalanceHistoryWindow"][];
|
|
308
|
+
burndownHistory: import("./schemas.cjs").components["schemas"]["GrantBurnDownHistorySegment"][];
|
|
309
|
+
}>;
|
|
310
|
+
/**
|
|
311
|
+
* Override an entitlement
|
|
312
|
+
* This is useful for upgrades, downgrades, or other changes to entitlements that require a new entitlement to be created with zero downtime.
|
|
313
|
+
*
|
|
314
|
+
* @param subjectIdOrKey - The ID or key of the subject
|
|
315
|
+
* @param entitlementIdOrFeatureKey - The ID or feature key of the entitlement
|
|
316
|
+
* @param override - The override to create
|
|
317
|
+
* @param signal - An optional abort signal
|
|
318
|
+
* @returns The overridden entitlement
|
|
319
|
+
*/
|
|
320
|
+
override(subjectIdOrKey: operations['overrideEntitlement']['parameters']['path']['subjectIdOrKey'], entitlementIdOrFeatureKey: operations['overrideEntitlement']['parameters']['path']['entitlementIdOrFeatureKey'], override: EntitlementCreateInputs, options?: RequestOptions): Promise<import("openapi-typescript-helpers").SuccessResponse<{
|
|
321
|
+
201: {
|
|
322
|
+
headers: {
|
|
323
|
+
[name: string]: unknown;
|
|
324
|
+
};
|
|
325
|
+
content: {
|
|
326
|
+
"application/json": import("./schemas.cjs").components["schemas"]["Entitlement"];
|
|
327
|
+
};
|
|
328
|
+
};
|
|
329
|
+
400: {
|
|
330
|
+
headers: {
|
|
331
|
+
[name: string]: unknown;
|
|
332
|
+
};
|
|
333
|
+
content: {
|
|
334
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["BadRequestProblemResponse"];
|
|
335
|
+
};
|
|
336
|
+
};
|
|
337
|
+
401: {
|
|
338
|
+
headers: {
|
|
339
|
+
[name: string]: unknown;
|
|
340
|
+
};
|
|
341
|
+
content: {
|
|
342
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["UnauthorizedProblemResponse"];
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
403: {
|
|
346
|
+
headers: {
|
|
347
|
+
[name: string]: unknown;
|
|
348
|
+
};
|
|
349
|
+
content: {
|
|
350
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["ForbiddenProblemResponse"];
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
404: {
|
|
354
|
+
headers: {
|
|
355
|
+
[name: string]: unknown;
|
|
356
|
+
};
|
|
357
|
+
content: {
|
|
358
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["NotFoundProblemResponse"];
|
|
359
|
+
};
|
|
360
|
+
};
|
|
361
|
+
409: {
|
|
362
|
+
headers: {
|
|
363
|
+
[name: string]: unknown;
|
|
364
|
+
};
|
|
365
|
+
content: {
|
|
366
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["ConflictProblemResponse"];
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
412: {
|
|
370
|
+
headers: {
|
|
371
|
+
[name: string]: unknown;
|
|
372
|
+
};
|
|
373
|
+
content: {
|
|
374
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["PreconditionFailedProblemResponse"];
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
500: {
|
|
378
|
+
headers: {
|
|
379
|
+
[name: string]: unknown;
|
|
380
|
+
};
|
|
381
|
+
content: {
|
|
382
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["InternalServerErrorProblemResponse"];
|
|
383
|
+
};
|
|
384
|
+
};
|
|
385
|
+
503: {
|
|
386
|
+
headers: {
|
|
387
|
+
[name: string]: unknown;
|
|
388
|
+
};
|
|
389
|
+
content: {
|
|
390
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["ServiceUnavailableProblemResponse"];
|
|
391
|
+
};
|
|
392
|
+
};
|
|
393
|
+
default: {
|
|
394
|
+
headers: {
|
|
395
|
+
[name: string]: unknown;
|
|
396
|
+
};
|
|
397
|
+
content: {
|
|
398
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["UnexpectedProblemResponse"];
|
|
399
|
+
};
|
|
400
|
+
};
|
|
401
|
+
}, `${string}/${string}`>>;
|
|
402
|
+
/**
|
|
403
|
+
* Reset entitlement usage
|
|
404
|
+
* - Reset marks the start of a new usage period for the entitlement and initiates grant rollover. At the start of a period usage is zerod out and grants are rolled over based on their rollover settings. It would typically be synced with the subjects billing period to enforce usage based on their subscription.
|
|
405
|
+
* - Usage is automatically reset for metered entitlements based on their usage period, but this endpoint allows to manually reset it at any time. When doing so the period anchor of the entitlement can be changed if needed.
|
|
406
|
+
*
|
|
407
|
+
* @param subjectIdOrKey - The ID or key of the subject
|
|
408
|
+
* @param entitlementId - The ID of the entitlement
|
|
409
|
+
* @param body - The body of the request
|
|
410
|
+
* @param signal - An optional abort signal
|
|
411
|
+
* @returns The reset entitlement
|
|
412
|
+
*/
|
|
413
|
+
reset(subjectIdOrKey: operations['resetEntitlementUsage']['parameters']['path']['subjectIdOrKey'], entitlementId: operations['resetEntitlementUsage']['parameters']['path']['entitlementId'], body: ResetEntitlementUsageInput, options?: RequestOptions): Promise<undefined>;
|
|
414
|
+
}
|
|
415
|
+
export declare class Grants {
|
|
416
|
+
private client;
|
|
417
|
+
constructor(client: Client<paths, `${string}/${string}`>);
|
|
418
|
+
/**
|
|
419
|
+
* Grant usage to a subject for an entitlement
|
|
420
|
+
*
|
|
421
|
+
* @param subjectIdOrKey - The ID or key of the subject
|
|
422
|
+
* @param entitlementIdOrFeatureKey - The ID or feature key of the entitlement
|
|
423
|
+
* @param grant - The grant to create
|
|
424
|
+
* @param signal - An optional abort signal
|
|
425
|
+
* @returns The created grant
|
|
426
|
+
*/
|
|
427
|
+
create(subjectIdOrKey: operations['createGrant']['parameters']['path']['subjectIdOrKey'], entitlementIdOrFeatureKey: operations['createGrant']['parameters']['path']['entitlementIdOrFeatureKey'], grant: EntitlementGrantCreateInput, options?: RequestOptions): Promise<{
|
|
428
|
+
readonly createdAt: Date;
|
|
429
|
+
readonly updatedAt: Date;
|
|
430
|
+
readonly deletedAt?: Date;
|
|
431
|
+
amount: number;
|
|
432
|
+
priority?: number;
|
|
433
|
+
effectiveAt: Date;
|
|
434
|
+
expiration: import("./schemas.cjs").components["schemas"]["ExpirationPeriod"];
|
|
435
|
+
maxRolloverAmount?: number;
|
|
436
|
+
minRolloverAmount?: number;
|
|
437
|
+
metadata?: import("./schemas.cjs").components["schemas"]["Metadata"];
|
|
438
|
+
readonly id: string;
|
|
439
|
+
readonly entitlementId: string;
|
|
440
|
+
nextRecurrence?: Date;
|
|
441
|
+
readonly expiresAt?: Date;
|
|
442
|
+
voidedAt?: Date;
|
|
443
|
+
recurrence?: import("./schemas.cjs").components["schemas"]["RecurringPeriod"];
|
|
444
|
+
}>;
|
|
445
|
+
/**
|
|
446
|
+
* List grants for an entitlement
|
|
447
|
+
*
|
|
448
|
+
* @param subjectIdOrKey - The ID or key of the subject
|
|
449
|
+
* @param entitlementIdOrFeatureKey - The ID or feature key of the entitlement
|
|
450
|
+
* @param signal - An optional abort signal
|
|
451
|
+
* @returns The grants
|
|
452
|
+
*/
|
|
453
|
+
list(subjectIdOrKey: operations['listEntitlementGrants']['parameters']['path']['subjectIdOrKey'], entitlementIdOrFeatureKey: operations['listEntitlementGrants']['parameters']['path']['entitlementIdOrFeatureKey'], query?: operations['listEntitlementGrants']['parameters']['query'], options?: RequestOptions): Promise<{
|
|
454
|
+
readonly createdAt: Date;
|
|
455
|
+
readonly updatedAt: Date;
|
|
456
|
+
readonly deletedAt?: Date;
|
|
457
|
+
amount: number;
|
|
458
|
+
priority?: number;
|
|
459
|
+
effectiveAt: Date;
|
|
460
|
+
expiration: import("./schemas.cjs").components["schemas"]["ExpirationPeriod"];
|
|
461
|
+
maxRolloverAmount?: number;
|
|
462
|
+
minRolloverAmount?: number;
|
|
463
|
+
metadata?: import("./schemas.cjs").components["schemas"]["Metadata"];
|
|
464
|
+
readonly id: string;
|
|
465
|
+
readonly entitlementId: string;
|
|
466
|
+
nextRecurrence?: Date;
|
|
467
|
+
readonly expiresAt?: Date;
|
|
468
|
+
voidedAt?: Date;
|
|
469
|
+
recurrence?: import("./schemas.cjs").components["schemas"]["RecurringPeriod"];
|
|
470
|
+
}[]>;
|
|
471
|
+
/**
|
|
472
|
+
* List all grants
|
|
473
|
+
* List all grants for all the subjects and entitlements.
|
|
474
|
+
*
|
|
475
|
+
* @param query - The query parameters
|
|
476
|
+
* @param options - The request options
|
|
477
|
+
* @returns The grants
|
|
478
|
+
*/
|
|
479
|
+
listAll(query?: operations['listGrants']['parameters']['query'], options?: RequestOptions): Promise<import("openapi-typescript-helpers").SuccessResponse<{
|
|
480
|
+
200: {
|
|
481
|
+
headers: {
|
|
482
|
+
[name: string]: unknown;
|
|
483
|
+
};
|
|
484
|
+
content: {
|
|
485
|
+
"application/json": import("./schemas.cjs").components["schemas"]["EntitlementGrant"][] | import("./schemas.cjs").components["schemas"]["GrantPaginatedResponse"];
|
|
486
|
+
};
|
|
487
|
+
};
|
|
488
|
+
400: {
|
|
489
|
+
headers: {
|
|
490
|
+
[name: string]: unknown;
|
|
491
|
+
};
|
|
492
|
+
content: {
|
|
493
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["BadRequestProblemResponse"];
|
|
494
|
+
};
|
|
495
|
+
};
|
|
496
|
+
401: {
|
|
497
|
+
headers: {
|
|
498
|
+
[name: string]: unknown;
|
|
499
|
+
};
|
|
500
|
+
content: {
|
|
501
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["UnauthorizedProblemResponse"];
|
|
502
|
+
};
|
|
503
|
+
};
|
|
504
|
+
403: {
|
|
505
|
+
headers: {
|
|
506
|
+
[name: string]: unknown;
|
|
507
|
+
};
|
|
508
|
+
content: {
|
|
509
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["ForbiddenProblemResponse"];
|
|
510
|
+
};
|
|
511
|
+
};
|
|
512
|
+
412: {
|
|
513
|
+
headers: {
|
|
514
|
+
[name: string]: unknown;
|
|
515
|
+
};
|
|
516
|
+
content: {
|
|
517
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["PreconditionFailedProblemResponse"];
|
|
518
|
+
};
|
|
519
|
+
};
|
|
520
|
+
500: {
|
|
521
|
+
headers: {
|
|
522
|
+
[name: string]: unknown;
|
|
523
|
+
};
|
|
524
|
+
content: {
|
|
525
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["InternalServerErrorProblemResponse"];
|
|
526
|
+
};
|
|
527
|
+
};
|
|
528
|
+
503: {
|
|
529
|
+
headers: {
|
|
530
|
+
[name: string]: unknown;
|
|
531
|
+
};
|
|
532
|
+
content: {
|
|
533
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["ServiceUnavailableProblemResponse"];
|
|
534
|
+
};
|
|
535
|
+
};
|
|
536
|
+
default: {
|
|
537
|
+
headers: {
|
|
538
|
+
[name: string]: unknown;
|
|
539
|
+
};
|
|
540
|
+
content: {
|
|
541
|
+
"application/problem+json": import("./schemas.cjs").components["schemas"]["UnexpectedProblemResponse"];
|
|
542
|
+
};
|
|
543
|
+
};
|
|
544
|
+
}, `${string}/${string}`>>;
|
|
545
|
+
/**
|
|
546
|
+
* Void a grant
|
|
547
|
+
* Voiding a grant means it is no longer valid, it doesn't take part in further balance calculations.
|
|
548
|
+
* Voiding a grant does not retroactively take effect, meaning any usage that has already been attributed
|
|
549
|
+
* to the grant will remain, but future usage cannot be burnt down from the grant.
|
|
550
|
+
*
|
|
551
|
+
* @param grantId - The ID of the grant
|
|
552
|
+
* @param options - The request options
|
|
553
|
+
* @returns The voided grant
|
|
554
|
+
*/
|
|
555
|
+
void(grantId: operations['voidGrant']['parameters']['path']['grantId'], options?: RequestOptions): Promise<undefined>;
|
|
556
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlements.js","sourceRoot":"","sources":["../../../../src/client/entitlements.ts"],"names":[],"mappings":";;;AAAA,yCAA8C;AAY9C;;;GAGG;AACH,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I,CAAC,CAAA;IAChC,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,OAAO,CAClB,KAAuD,EACvD,OAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,gBAAgB,EAAE;YACnD,MAAM,EAAE;gBACN,KAAK;aACN;YACD,GAAG,OAAO;SACX,CAAC,CAAA;QAEF,OAAO,IAAA,4BAAiB,EAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED;;;;;;;;;OASG;IACI,KAAK,CAAC,IAAI,CACf,OAAiE,EACjE,OAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,0BAA0B,EAAE;YAChE,MAAM,EAAE;gBACN,IAAI,EAAE;oBACJ,OAAO;iBACR;aACF;YACD,GAAG,OAAO;SACX,CAAC,CAAA;QAEF,OAAO,IAAA,4BAAiB,EAAC,IAAI,CAAC,CAAA;IAChC,CAAC;CACF;AAjHD,wBAiHC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Events = void 0;
|
|
4
|
+
exports.setDefaultsForEvent = setDefaultsForEvent;
|
|
5
|
+
const utils_js_1 = require("./utils.cjs");
|
|
6
|
+
/**
|
|
7
|
+
* Events are used to track usage of your product or service.
|
|
8
|
+
* Events are processed asynchronously by the meters, so they may not be immediately available for querying.
|
|
9
|
+
*/
|
|
10
|
+
class Events {
|
|
11
|
+
client;
|
|
12
|
+
constructor(client) {
|
|
13
|
+
this.client = client;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Ingests an event or batch of events
|
|
17
|
+
* @param events - The events to ingest
|
|
18
|
+
* @param signal - An optional abort signal
|
|
19
|
+
* @returns The ingested events
|
|
20
|
+
*/
|
|
21
|
+
async ingest(events, options) {
|
|
22
|
+
const body = await Promise.all((Array.isArray(events) ? events : [events]).map(setDefaultsForEvent));
|
|
23
|
+
const resp = await this.client.POST('/api/v1/events', {
|
|
24
|
+
body,
|
|
25
|
+
headers: {
|
|
26
|
+
'Content-Type': 'application/cloudevents-batch+json',
|
|
27
|
+
},
|
|
28
|
+
...options,
|
|
29
|
+
});
|
|
30
|
+
return (0, utils_js_1.transformResponse)(resp);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* List events
|
|
34
|
+
* @param params - The query parameters
|
|
35
|
+
* @param options - Optional request options
|
|
36
|
+
* @returns The events
|
|
37
|
+
*/
|
|
38
|
+
async list(params, options) {
|
|
39
|
+
const resp = await this.client.GET('/api/v1/events', {
|
|
40
|
+
params: { query: params },
|
|
41
|
+
...options,
|
|
42
|
+
});
|
|
43
|
+
return (0, utils_js_1.transformResponse)(resp);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* List events (V2)
|
|
47
|
+
* @description List ingested events with advanced filtering and cursor pagination.
|
|
48
|
+
* @param params - The query parameters
|
|
49
|
+
* @param options - Optional request options
|
|
50
|
+
* @returns The events
|
|
51
|
+
*/
|
|
52
|
+
async listV2(params, options) {
|
|
53
|
+
const resp = await this.client.GET('/api/v2/events', {
|
|
54
|
+
params: { query: params },
|
|
55
|
+
...options,
|
|
56
|
+
});
|
|
57
|
+
return (0, utils_js_1.transformResponse)(resp);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.Events = Events;
|
|
61
|
+
/**
|
|
62
|
+
* Sets the defaults for an event
|
|
63
|
+
* @param ev - The event to set the defaults for
|
|
64
|
+
* @returns The event with the defaults set
|
|
65
|
+
*/
|
|
66
|
+
async function setDefaultsForEvent(ev) {
|
|
67
|
+
return {
|
|
68
|
+
...ev,
|
|
69
|
+
id: ev.id ?? (await generateId()),
|
|
70
|
+
source: ev.source ?? '@openmeter/sdk',
|
|
71
|
+
specversion: ev.specversion ?? '1.0',
|
|
72
|
+
time: ev.time ?? new Date(),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
let _randomUUID;
|
|
76
|
+
// One-off attempt to load node:crypto and capture randomUUID (if present)
|
|
77
|
+
async function loadUUIDProvider() {
|
|
78
|
+
if (_randomUUID !== undefined) {
|
|
79
|
+
// already tried
|
|
80
|
+
return _randomUUID;
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
const c = await import('node:crypto');
|
|
84
|
+
if (typeof c.randomUUID === 'function') {
|
|
85
|
+
// available
|
|
86
|
+
_randomUUID = c.randomUUID.bind(c);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// not-available
|
|
91
|
+
}
|
|
92
|
+
return _randomUUID;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Generates a random ID
|
|
96
|
+
* @returns A random ID
|
|
97
|
+
*/
|
|
98
|
+
async function generateId() {
|
|
99
|
+
const randomUUID = await loadUUIDProvider();
|
|
100
|
+
if (randomUUID) {
|
|
101
|
+
return randomUUID();
|
|
102
|
+
}
|
|
103
|
+
// Fallback to semi-random ID
|
|
104
|
+
const bytes = new Uint8Array(16);
|
|
105
|
+
for (let i = 0; i < 16; i++) {
|
|
106
|
+
bytes[i] = (Math.random() * 256) | 0;
|
|
107
|
+
}
|
|
108
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
109
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
110
|
+
const hex = [...bytes].map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
111
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=events.js.map
|