@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,276 @@
|
|
|
1
|
+
import { transformResponse } from './utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Entitlements
|
|
4
|
+
* @description With Entitlements, you can define and enforce usage limits, implement quota-based pricing, and manage access to features in your application.
|
|
5
|
+
*/
|
|
6
|
+
export class Entitlements {
|
|
7
|
+
client;
|
|
8
|
+
grants;
|
|
9
|
+
constructor(client) {
|
|
10
|
+
this.client = client;
|
|
11
|
+
this.grants = new Grants(client);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create an entitlement
|
|
15
|
+
*
|
|
16
|
+
* - Boolean entitlements define static feature access, e.g. "Can use SSO authentication".
|
|
17
|
+
* - Static entitlements let you pass along a configuration while granting access, e.g. "Using this feature with X Y settings" (passed in the config).
|
|
18
|
+
* - 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.
|
|
19
|
+
*
|
|
20
|
+
* 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.
|
|
21
|
+
*
|
|
22
|
+
* Once an entitlement is created you cannot modify it, only delete it.
|
|
23
|
+
*
|
|
24
|
+
* @param subjectIdOrKey - The ID or key of the subject
|
|
25
|
+
* @param entitlement - The entitlement to create
|
|
26
|
+
* @param signal - An optional abort signal
|
|
27
|
+
* @returns The created entitlement
|
|
28
|
+
*/
|
|
29
|
+
async create(subjectIdOrKey, entitlement, options) {
|
|
30
|
+
const resp = await this.client.POST('/api/v1/subjects/{subjectIdOrKey}/entitlements', {
|
|
31
|
+
body: entitlement,
|
|
32
|
+
params: {
|
|
33
|
+
path: {
|
|
34
|
+
subjectIdOrKey: subjectIdOrKey,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
...options,
|
|
38
|
+
});
|
|
39
|
+
return transformResponse(resp);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get an entitlement by ID
|
|
43
|
+
*
|
|
44
|
+
* @param id - The ID of the entitlement
|
|
45
|
+
* @param signal - An optional abort signal
|
|
46
|
+
* @returns The entitlement
|
|
47
|
+
*/
|
|
48
|
+
async get(id, options) {
|
|
49
|
+
const resp = await this.client.GET('/api/v1/entitlements/{entitlementId}', {
|
|
50
|
+
params: {
|
|
51
|
+
path: {
|
|
52
|
+
entitlementId: id,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
...options,
|
|
56
|
+
});
|
|
57
|
+
return transformResponse(resp);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* List entitlements
|
|
61
|
+
*
|
|
62
|
+
* @param query - The query parameters
|
|
63
|
+
* @param signal - An optional abort signal
|
|
64
|
+
* @returns The entitlements
|
|
65
|
+
*/
|
|
66
|
+
async list(query, options) {
|
|
67
|
+
const resp = await this.client.GET('/api/v1/entitlements', {
|
|
68
|
+
params: {
|
|
69
|
+
query,
|
|
70
|
+
},
|
|
71
|
+
...options,
|
|
72
|
+
});
|
|
73
|
+
return transformResponse(resp);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Delete an entitlement
|
|
77
|
+
*
|
|
78
|
+
* @param subjectIdOrKey - The ID or key of the subject
|
|
79
|
+
* @param entitlementId - The ID of the entitlement
|
|
80
|
+
* @param signal - An optional abort signal
|
|
81
|
+
* @returns The deleted entitlement
|
|
82
|
+
*/
|
|
83
|
+
async delete(subjectIdOrKey, entitlementId, options) {
|
|
84
|
+
const resp = await this.client.DELETE('/api/v1/subjects/{subjectIdOrKey}/entitlements/{entitlementId}', {
|
|
85
|
+
params: {
|
|
86
|
+
path: {
|
|
87
|
+
entitlementId,
|
|
88
|
+
subjectIdOrKey,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
...options,
|
|
92
|
+
});
|
|
93
|
+
return transformResponse(resp);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get the value of an entitlement to check access
|
|
97
|
+
* All entitlement types share the hasAccess property in their value response, but multiple other properties are returned based on the entitlement type.
|
|
98
|
+
*
|
|
99
|
+
* @param subjectIdOrKey - The ID or key of the subject
|
|
100
|
+
* @param entitlementIdOrFeatureKey - The ID or feature key of the entitlement
|
|
101
|
+
* @param query - The query parameters
|
|
102
|
+
* @param signal - An optional abort signal
|
|
103
|
+
* @returns The entitlement value
|
|
104
|
+
*/
|
|
105
|
+
async value(subjectIdOrKey, entitlementIdOrFeatureKey, query, options) {
|
|
106
|
+
const resp = await this.client.GET('/api/v1/subjects/{subjectIdOrKey}/entitlements/{entitlementIdOrFeatureKey}/value', {
|
|
107
|
+
params: {
|
|
108
|
+
path: {
|
|
109
|
+
entitlementIdOrFeatureKey,
|
|
110
|
+
subjectIdOrKey,
|
|
111
|
+
},
|
|
112
|
+
query,
|
|
113
|
+
},
|
|
114
|
+
...options,
|
|
115
|
+
});
|
|
116
|
+
return transformResponse(resp);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Get the history of an entitlement
|
|
120
|
+
* Returns historical balance and usage data for the entitlement. The queried history can span accross multiple reset events.
|
|
121
|
+
*
|
|
122
|
+
* @param subjectIdOrKey - The ID or key of the subject
|
|
123
|
+
* @param entitlementId - The ID of the entitlement
|
|
124
|
+
* @param query - The query parameters
|
|
125
|
+
* @param signal - An optional abort signal
|
|
126
|
+
* @returns The history of the entitlement
|
|
127
|
+
*/
|
|
128
|
+
async history(subjectIdOrKey, entitlementId, query, options) {
|
|
129
|
+
const resp = await this.client.GET('/api/v1/subjects/{subjectIdOrKey}/entitlements/{entitlementId}/history', {
|
|
130
|
+
params: {
|
|
131
|
+
path: {
|
|
132
|
+
entitlementId,
|
|
133
|
+
subjectIdOrKey,
|
|
134
|
+
},
|
|
135
|
+
query,
|
|
136
|
+
},
|
|
137
|
+
...options,
|
|
138
|
+
});
|
|
139
|
+
return transformResponse(resp);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Override an entitlement
|
|
143
|
+
* This is useful for upgrades, downgrades, or other changes to entitlements that require a new entitlement to be created with zero downtime.
|
|
144
|
+
*
|
|
145
|
+
* @param subjectIdOrKey - The ID or key of the subject
|
|
146
|
+
* @param entitlementIdOrFeatureKey - The ID or feature key of the entitlement
|
|
147
|
+
* @param override - The override to create
|
|
148
|
+
* @param signal - An optional abort signal
|
|
149
|
+
* @returns The overridden entitlement
|
|
150
|
+
*/
|
|
151
|
+
async override(subjectIdOrKey, entitlementIdOrFeatureKey, override, options) {
|
|
152
|
+
const resp = await this.client.PUT('/api/v1/subjects/{subjectIdOrKey}/entitlements/{entitlementIdOrFeatureKey}/override', {
|
|
153
|
+
body: override,
|
|
154
|
+
params: {
|
|
155
|
+
path: {
|
|
156
|
+
entitlementIdOrFeatureKey,
|
|
157
|
+
subjectIdOrKey,
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
...options,
|
|
161
|
+
});
|
|
162
|
+
return transformResponse(resp);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Reset entitlement usage
|
|
166
|
+
* - 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.
|
|
167
|
+
* - 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.
|
|
168
|
+
*
|
|
169
|
+
* @param subjectIdOrKey - The ID or key of the subject
|
|
170
|
+
* @param entitlementId - The ID of the entitlement
|
|
171
|
+
* @param body - The body of the request
|
|
172
|
+
* @param signal - An optional abort signal
|
|
173
|
+
* @returns The reset entitlement
|
|
174
|
+
*/
|
|
175
|
+
async reset(subjectIdOrKey, entitlementId, body, options) {
|
|
176
|
+
const resp = await this.client.POST('/api/v1/subjects/{subjectIdOrKey}/entitlements/{entitlementId}/reset', {
|
|
177
|
+
body,
|
|
178
|
+
params: {
|
|
179
|
+
path: {
|
|
180
|
+
entitlementId,
|
|
181
|
+
subjectIdOrKey,
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
...options,
|
|
185
|
+
});
|
|
186
|
+
return transformResponse(resp);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
export class Grants {
|
|
190
|
+
client;
|
|
191
|
+
constructor(client) {
|
|
192
|
+
this.client = client;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Grant usage to a subject for an entitlement
|
|
196
|
+
*
|
|
197
|
+
* @param subjectIdOrKey - The ID or key of the subject
|
|
198
|
+
* @param entitlementIdOrFeatureKey - The ID or feature key of the entitlement
|
|
199
|
+
* @param grant - The grant to create
|
|
200
|
+
* @param signal - An optional abort signal
|
|
201
|
+
* @returns The created grant
|
|
202
|
+
*/
|
|
203
|
+
async create(subjectIdOrKey, entitlementIdOrFeatureKey, grant, options) {
|
|
204
|
+
const resp = await this.client.POST('/api/v1/subjects/{subjectIdOrKey}/entitlements/{entitlementIdOrFeatureKey}/grants', {
|
|
205
|
+
body: grant,
|
|
206
|
+
params: {
|
|
207
|
+
path: {
|
|
208
|
+
entitlementIdOrFeatureKey,
|
|
209
|
+
subjectIdOrKey,
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
...options,
|
|
213
|
+
});
|
|
214
|
+
return transformResponse(resp);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* List grants for an entitlement
|
|
218
|
+
*
|
|
219
|
+
* @param subjectIdOrKey - The ID or key of the subject
|
|
220
|
+
* @param entitlementIdOrFeatureKey - The ID or feature key of the entitlement
|
|
221
|
+
* @param signal - An optional abort signal
|
|
222
|
+
* @returns The grants
|
|
223
|
+
*/
|
|
224
|
+
async list(subjectIdOrKey, entitlementIdOrFeatureKey, query, options) {
|
|
225
|
+
const resp = await this.client.GET('/api/v1/subjects/{subjectIdOrKey}/entitlements/{entitlementIdOrFeatureKey}/grants', {
|
|
226
|
+
params: {
|
|
227
|
+
path: {
|
|
228
|
+
entitlementIdOrFeatureKey,
|
|
229
|
+
subjectIdOrKey,
|
|
230
|
+
},
|
|
231
|
+
query,
|
|
232
|
+
},
|
|
233
|
+
...options,
|
|
234
|
+
});
|
|
235
|
+
return transformResponse(resp);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* List all grants
|
|
239
|
+
* List all grants for all the subjects and entitlements.
|
|
240
|
+
*
|
|
241
|
+
* @param query - The query parameters
|
|
242
|
+
* @param options - The request options
|
|
243
|
+
* @returns The grants
|
|
244
|
+
*/
|
|
245
|
+
async listAll(query, options) {
|
|
246
|
+
const resp = await this.client.GET('/api/v1/grants', {
|
|
247
|
+
params: {
|
|
248
|
+
query,
|
|
249
|
+
},
|
|
250
|
+
...options,
|
|
251
|
+
});
|
|
252
|
+
return transformResponse(resp);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Void a grant
|
|
256
|
+
* Voiding a grant means it is no longer valid, it doesn't take part in further balance calculations.
|
|
257
|
+
* Voiding a grant does not retroactively take effect, meaning any usage that has already been attributed
|
|
258
|
+
* to the grant will remain, but future usage cannot be burnt down from the grant.
|
|
259
|
+
*
|
|
260
|
+
* @param grantId - The ID of the grant
|
|
261
|
+
* @param options - The request options
|
|
262
|
+
* @returns The voided grant
|
|
263
|
+
*/
|
|
264
|
+
async void(grantId, options) {
|
|
265
|
+
const resp = await this.client.DELETE('/api/v1/grants/{grantId}', {
|
|
266
|
+
params: {
|
|
267
|
+
path: {
|
|
268
|
+
grantId,
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
...options,
|
|
272
|
+
});
|
|
273
|
+
return transformResponse(resp);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=entitlements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlements.js","sourceRoot":"","sources":["../../../src/client/entitlements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAY9C;;;GAGG;AACH,MAAM,OAAO,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AuD,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,iBAAiB,CAAC,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,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { RequestOptions } from './common.js';
|
|
2
|
+
import type { operations, paths, Event } from './schemas.js';
|
|
3
|
+
import type { Client } from 'openapi-fetch';
|
|
4
|
+
/**
|
|
5
|
+
* Events are used to track usage of your product or service.
|
|
6
|
+
* Events are processed asynchronously by the meters, so they may not be immediately available for querying.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Events {
|
|
9
|
+
private client;
|
|
10
|
+
constructor(client: Client<paths, `${string}/${string}`>);
|
|
11
|
+
/**
|
|
12
|
+
* Ingests an event or batch of events
|
|
13
|
+
* @param events - The events to ingest
|
|
14
|
+
* @param signal - An optional abort signal
|
|
15
|
+
* @returns The ingested events
|
|
16
|
+
*/
|
|
17
|
+
ingest(events: Event | Event[], options?: RequestOptions): Promise<undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* List events
|
|
20
|
+
* @param params - The query parameters
|
|
21
|
+
* @param options - Optional request options
|
|
22
|
+
* @returns The events
|
|
23
|
+
*/
|
|
24
|
+
list(params?: operations['listEvents']['parameters']['query'], options?: RequestOptions): Promise<{
|
|
25
|
+
event: import("./schemas.js").components["schemas"]["Event"];
|
|
26
|
+
customerId?: string;
|
|
27
|
+
validationError?: string;
|
|
28
|
+
ingestedAt: Date;
|
|
29
|
+
storedAt: Date;
|
|
30
|
+
}[]>;
|
|
31
|
+
/**
|
|
32
|
+
* List events (V2)
|
|
33
|
+
* @description List ingested events with advanced filtering and cursor pagination.
|
|
34
|
+
* @param params - The query parameters
|
|
35
|
+
* @param options - Optional request options
|
|
36
|
+
* @returns The events
|
|
37
|
+
*/
|
|
38
|
+
listV2(params?: operations['listEventsV2']['parameters']['query'], options?: RequestOptions): Promise<{
|
|
39
|
+
items: import("./schemas.js").components["schemas"]["IngestedEvent"][];
|
|
40
|
+
nextCursor?: string;
|
|
41
|
+
}>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Sets the defaults for an event
|
|
45
|
+
* @param ev - The event to set the defaults for
|
|
46
|
+
* @returns The event with the defaults set
|
|
47
|
+
*/
|
|
48
|
+
export declare function setDefaultsForEvent(ev: Event): Promise<Event>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { transformResponse } from './utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Events are used to track usage of your product or service.
|
|
4
|
+
* Events are processed asynchronously by the meters, so they may not be immediately available for querying.
|
|
5
|
+
*/
|
|
6
|
+
export class Events {
|
|
7
|
+
client;
|
|
8
|
+
constructor(client) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Ingests an event or batch of events
|
|
13
|
+
* @param events - The events to ingest
|
|
14
|
+
* @param signal - An optional abort signal
|
|
15
|
+
* @returns The ingested events
|
|
16
|
+
*/
|
|
17
|
+
async ingest(events, options) {
|
|
18
|
+
const body = await Promise.all((Array.isArray(events) ? events : [events]).map(setDefaultsForEvent));
|
|
19
|
+
const resp = await this.client.POST('/api/v1/events', {
|
|
20
|
+
body,
|
|
21
|
+
headers: {
|
|
22
|
+
'Content-Type': 'application/cloudevents-batch+json',
|
|
23
|
+
},
|
|
24
|
+
...options,
|
|
25
|
+
});
|
|
26
|
+
return transformResponse(resp);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* List events
|
|
30
|
+
* @param params - The query parameters
|
|
31
|
+
* @param options - Optional request options
|
|
32
|
+
* @returns The events
|
|
33
|
+
*/
|
|
34
|
+
async list(params, options) {
|
|
35
|
+
const resp = await this.client.GET('/api/v1/events', {
|
|
36
|
+
params: { query: params },
|
|
37
|
+
...options,
|
|
38
|
+
});
|
|
39
|
+
return transformResponse(resp);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* List events (V2)
|
|
43
|
+
* @description List ingested events with advanced filtering and cursor pagination.
|
|
44
|
+
* @param params - The query parameters
|
|
45
|
+
* @param options - Optional request options
|
|
46
|
+
* @returns The events
|
|
47
|
+
*/
|
|
48
|
+
async listV2(params, options) {
|
|
49
|
+
const resp = await this.client.GET('/api/v2/events', {
|
|
50
|
+
params: { query: params },
|
|
51
|
+
...options,
|
|
52
|
+
});
|
|
53
|
+
return transformResponse(resp);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Sets the defaults for an event
|
|
58
|
+
* @param ev - The event to set the defaults for
|
|
59
|
+
* @returns The event with the defaults set
|
|
60
|
+
*/
|
|
61
|
+
export async function setDefaultsForEvent(ev) {
|
|
62
|
+
return {
|
|
63
|
+
...ev,
|
|
64
|
+
id: ev.id ?? (await generateId()),
|
|
65
|
+
source: ev.source ?? '@openmeter/sdk',
|
|
66
|
+
specversion: ev.specversion ?? '1.0',
|
|
67
|
+
time: ev.time ?? new Date(),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
let _randomUUID;
|
|
71
|
+
// One-off attempt to load node:crypto and capture randomUUID (if present)
|
|
72
|
+
async function loadUUIDProvider() {
|
|
73
|
+
if (_randomUUID !== undefined) {
|
|
74
|
+
// already tried
|
|
75
|
+
return _randomUUID;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const c = await import('node:crypto');
|
|
79
|
+
if (typeof c.randomUUID === 'function') {
|
|
80
|
+
// available
|
|
81
|
+
_randomUUID = c.randomUUID.bind(c);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
// not-available
|
|
86
|
+
}
|
|
87
|
+
return _randomUUID;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Generates a random ID
|
|
91
|
+
* @returns A random ID
|
|
92
|
+
*/
|
|
93
|
+
async function generateId() {
|
|
94
|
+
const randomUUID = await loadUUIDProvider();
|
|
95
|
+
if (randomUUID) {
|
|
96
|
+
return randomUUID();
|
|
97
|
+
}
|
|
98
|
+
// Fallback to semi-random ID
|
|
99
|
+
const bytes = new Uint8Array(16);
|
|
100
|
+
for (let i = 0; i < 16; i++) {
|
|
101
|
+
bytes[i] = (Math.random() * 256) | 0;
|
|
102
|
+
}
|
|
103
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
104
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
105
|
+
const hex = [...bytes].map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
106
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/client/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAK9C;;;GAGG;AACH,MAAM,OAAO,MAAM;IACG;IAApB,YAAoB,MAA4C;QAA5C,WAAM,GAAN,MAAM,CAAsC;IAAG,CAAC;IAEpE;;;;;OAKG;IACI,KAAK,CAAC,MAAM,CAAC,MAAuB,EAAE,OAAwB;QACnE,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC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AG,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAC3E,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAA;AAC5G,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { RequestOptions } from './common.js';
|
|
2
|
+
import type { FeatureCreateInputs, operations, paths } from './schemas.js';
|
|
3
|
+
import type { Client } from 'openapi-fetch';
|
|
4
|
+
/**
|
|
5
|
+
* Features
|
|
6
|
+
* @description Features are the building blocks of your application. They represent the capabilities or services that your application offers.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Features {
|
|
9
|
+
private client;
|
|
10
|
+
constructor(client: Client<paths, `${string}/${string}`>);
|
|
11
|
+
/**
|
|
12
|
+
* Create a feature
|
|
13
|
+
* @param feature - The feature to create
|
|
14
|
+
* @param signal - An optional abort signal
|
|
15
|
+
* @returns The created feature
|
|
16
|
+
*/
|
|
17
|
+
create(feature: FeatureCreateInputs, options?: RequestOptions): Promise<{
|
|
18
|
+
readonly createdAt: Date;
|
|
19
|
+
readonly updatedAt: Date;
|
|
20
|
+
readonly deletedAt?: Date;
|
|
21
|
+
readonly archivedAt?: Date;
|
|
22
|
+
key: string;
|
|
23
|
+
name: string;
|
|
24
|
+
metadata?: import("./schemas.js").components["schemas"]["Metadata"];
|
|
25
|
+
meterSlug?: string;
|
|
26
|
+
meterGroupByFilters?: {
|
|
27
|
+
[key: string]: string;
|
|
28
|
+
};
|
|
29
|
+
readonly id: string;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Get a feature by ID
|
|
33
|
+
* @param id - The ID of the feature
|
|
34
|
+
* @param signal - An optional abort signal
|
|
35
|
+
* @returns The feature
|
|
36
|
+
*/
|
|
37
|
+
get(id: operations['getFeature']['parameters']['path']['featureId'], options?: RequestOptions): Promise<{
|
|
38
|
+
readonly createdAt: Date;
|
|
39
|
+
readonly updatedAt: Date;
|
|
40
|
+
readonly deletedAt?: Date;
|
|
41
|
+
readonly archivedAt?: Date;
|
|
42
|
+
key: string;
|
|
43
|
+
name: string;
|
|
44
|
+
metadata?: import("./schemas.js").components["schemas"]["Metadata"];
|
|
45
|
+
meterSlug?: string;
|
|
46
|
+
meterGroupByFilters?: {
|
|
47
|
+
[key: string]: string;
|
|
48
|
+
};
|
|
49
|
+
readonly id: string;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* List features
|
|
53
|
+
* @param query - The query parameters
|
|
54
|
+
* @param signal - An optional abort signal
|
|
55
|
+
* @returns The features
|
|
56
|
+
*/
|
|
57
|
+
list(query?: Omit<operations['listFeatures']['parameters']['query'], 'page' | 'pageSize'>, options?: RequestOptions): Promise<{
|
|
58
|
+
readonly createdAt: Date;
|
|
59
|
+
readonly updatedAt: Date;
|
|
60
|
+
readonly deletedAt?: Date;
|
|
61
|
+
readonly archivedAt?: Date;
|
|
62
|
+
key: string;
|
|
63
|
+
name: string;
|
|
64
|
+
metadata?: import("./schemas.js").components["schemas"]["Metadata"];
|
|
65
|
+
meterSlug?: string;
|
|
66
|
+
meterGroupByFilters?: {
|
|
67
|
+
[key: string]: string;
|
|
68
|
+
};
|
|
69
|
+
readonly id: string;
|
|
70
|
+
}[]>;
|
|
71
|
+
/**
|
|
72
|
+
* Delete a feature by ID
|
|
73
|
+
* @param id - The ID of the feature
|
|
74
|
+
* @param signal - An optional abort signal
|
|
75
|
+
* @returns The deleted feature
|
|
76
|
+
*/
|
|
77
|
+
delete(id: operations['deleteFeature']['parameters']['path']['featureId'], options?: RequestOptions): Promise<undefined>;
|
|
78
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { transformResponse } from './utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Features
|
|
4
|
+
* @description Features are the building blocks of your application. They represent the capabilities or services that your application offers.
|
|
5
|
+
*/
|
|
6
|
+
export class Features {
|
|
7
|
+
client;
|
|
8
|
+
constructor(client) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create a feature
|
|
13
|
+
* @param feature - The feature to create
|
|
14
|
+
* @param signal - An optional abort signal
|
|
15
|
+
* @returns The created feature
|
|
16
|
+
*/
|
|
17
|
+
async create(feature, options) {
|
|
18
|
+
const resp = await this.client.POST('/api/v1/features', {
|
|
19
|
+
body: feature,
|
|
20
|
+
...options,
|
|
21
|
+
});
|
|
22
|
+
return transformResponse(resp);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get a feature by ID
|
|
26
|
+
* @param id - The ID of the feature
|
|
27
|
+
* @param signal - An optional abort signal
|
|
28
|
+
* @returns The feature
|
|
29
|
+
*/
|
|
30
|
+
async get(id, options) {
|
|
31
|
+
const resp = await this.client.GET('/api/v1/features/{featureId}', {
|
|
32
|
+
params: {
|
|
33
|
+
path: {
|
|
34
|
+
featureId: id,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
...options,
|
|
38
|
+
});
|
|
39
|
+
return transformResponse(resp);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* List features
|
|
43
|
+
* @param query - The query parameters
|
|
44
|
+
* @param signal - An optional abort signal
|
|
45
|
+
* @returns The features
|
|
46
|
+
*/
|
|
47
|
+
async list(query, options) {
|
|
48
|
+
const resp = await this.client.GET('/api/v1/features', {
|
|
49
|
+
params: {
|
|
50
|
+
query,
|
|
51
|
+
},
|
|
52
|
+
...options,
|
|
53
|
+
});
|
|
54
|
+
return transformResponse(resp);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Delete a feature by ID
|
|
58
|
+
* @param id - The ID of the feature
|
|
59
|
+
* @param signal - An optional abort signal
|
|
60
|
+
* @returns The deleted feature
|
|
61
|
+
*/
|
|
62
|
+
async delete(id, options) {
|
|
63
|
+
const resp = await this.client.DELETE('/api/v1/features/{featureId}', {
|
|
64
|
+
params: {
|
|
65
|
+
path: {
|
|
66
|
+
featureId: id,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
...options,
|
|
70
|
+
});
|
|
71
|
+
return transformResponse(resp);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=features.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features.js","sourceRoot":"","sources":["../../../src/client/features.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAU9C;;;GAGG;AACH,MAAM,OAAO,QAAQ;IACC;IAApB,YAAoB,MAA4C;QAA5C,WAAM,GAAN,MAAM,CAAsC;IAAG,CAAC;IAEpE;;;;;OAKG;IACI,KAAK,CAAC,MAAM,CAAC,OAA4B,EAAE,OAAwB;QACxE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE;YACtD,IAAI,EAAE,OAAO;YACb,GAAG,OAAO;SACX,CAAC,CAAA;QAEF,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,GAAG,CACd,EAA+D,EAC/D,OAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,8BAA8B,EAAE;YACjE,MAAM,EAAE;gBACN,IAAI,EAAE;oBACJ,SAAS,EAAE,EAAE;iBACd;aACF;YACD,GAAG,OAAO;SACX,CAAC,CAAA;QAEF,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,IAAI,CACf,KAGC,EACD,OAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,kBAAkB,EAAE;YACrD,MAAM,EAAE;gBACN,KAAK;aACN;YACD,GAAG,OAAO;SACX,CAAC,CAAA;QAEF,OAAO,iBAAiB,CAAC,IAAI,CAAc,CAAA;IAC7C,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,MAAM,CACjB,EAAkE,EAClE,OAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,8BAA8B,EAAE;YACpE,MAAM,EAAE;gBACN,IAAI,EAAE;oBACJ,SAAS,EAAE,EAAE;iBACd;aACF;YACD,GAAG,OAAO;SACX,CAAC,CAAA;QAEF,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type Client, type ClientOptions } from 'openapi-fetch';
|
|
2
|
+
import { Addons } from './addons.js';
|
|
3
|
+
import { Apps } from './apps.js';
|
|
4
|
+
import { Billing } from './billing.js';
|
|
5
|
+
import { Customers } from './customers.js';
|
|
6
|
+
import { Debug } from './debug.js';
|
|
7
|
+
import { Entitlements } from './entitlements.js';
|
|
8
|
+
import { Events } from './events.js';
|
|
9
|
+
import { Features } from './features.js';
|
|
10
|
+
import { Info } from './info.js';
|
|
11
|
+
import { Meters } from './meters.js';
|
|
12
|
+
import { Notifications } from './notifications.js';
|
|
13
|
+
import { Plans } from './plans.js';
|
|
14
|
+
import { Portal } from './portal.js';
|
|
15
|
+
import { Subjects } from './subjects.js';
|
|
16
|
+
import { SubscriptionAddons } from './subscription-addons.js';
|
|
17
|
+
import { Subscriptions } from './subscriptions.js';
|
|
18
|
+
import type { paths } from './schemas.js';
|
|
19
|
+
export * from './schemas.js';
|
|
20
|
+
export * from './common.js';
|
|
21
|
+
/**
|
|
22
|
+
* OpenMeter Config
|
|
23
|
+
*/
|
|
24
|
+
export type Config = Pick<ClientOptions, 'baseUrl' | 'headers' | 'fetch' | 'Request' | 'requestInitExt'> & ({
|
|
25
|
+
apiKey?: string;
|
|
26
|
+
} | {
|
|
27
|
+
baseUrl: 'https://openmeter.cloud';
|
|
28
|
+
apiKey: string;
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* OpenMeter Client
|
|
32
|
+
*/
|
|
33
|
+
export declare class OpenMeter {
|
|
34
|
+
config: Config;
|
|
35
|
+
client: Client<paths, `${string}/${string}`>;
|
|
36
|
+
addons: Addons;
|
|
37
|
+
apps: Apps;
|
|
38
|
+
billing: Billing;
|
|
39
|
+
customers: Customers;
|
|
40
|
+
debug: Debug;
|
|
41
|
+
entitlements: Entitlements;
|
|
42
|
+
events: Events;
|
|
43
|
+
features: Features;
|
|
44
|
+
info: Info;
|
|
45
|
+
meters: Meters;
|
|
46
|
+
notifications: Notifications;
|
|
47
|
+
plans: Plans;
|
|
48
|
+
portal: Portal;
|
|
49
|
+
subjects: Subjects;
|
|
50
|
+
subscriptionAddons: SubscriptionAddons;
|
|
51
|
+
subscriptions: Subscriptions;
|
|
52
|
+
constructor(config: Config);
|
|
53
|
+
}
|