@openmeter/sdk 1.0.0-beta.60 → 1.0.0-beta.63

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.
@@ -1,55 +0,0 @@
1
- import { BaseClient } from './client.js';
2
- export class SubjectClient extends BaseClient {
3
- constructor(config) {
4
- super(config);
5
- }
6
- /**
7
- * Upsert subject
8
- * Useful to map display name and metadata to subjects
9
- * @note OpenMeter Cloud only feature
10
- */
11
- async upsert(subject, options) {
12
- return await this.request({
13
- path: '/api/v1/subjects',
14
- method: 'POST',
15
- headers: {
16
- 'Content-Type': 'application/json',
17
- },
18
- body: JSON.stringify(subject),
19
- options,
20
- });
21
- }
22
- /**
23
- * Get subject by id or key
24
- * @note OpenMeter Cloud only feature
25
- */
26
- async get(idOrKey, options) {
27
- return await this.request({
28
- path: `/api/v1/subjects/${idOrKey}`,
29
- method: 'GET',
30
- options,
31
- });
32
- }
33
- /**
34
- * List subjects
35
- * @note OpenMeter Cloud only feature
36
- */
37
- async list(options) {
38
- return await this.request({
39
- path: '/api/v1/subjects',
40
- method: 'GET',
41
- options,
42
- });
43
- }
44
- /**
45
- * Delete subject by id or key
46
- * @note OpenMeter Cloud only feature
47
- */
48
- async delete(idOrKey, options) {
49
- return await this.request({
50
- path: `/api/v1/subjects/${idOrKey}`,
51
- method: 'DELETE',
52
- options,
53
- });
54
- }
55
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * This file was auto-generated by openapi-typescript.
3
- * Do not make direct changes to the file.
4
- */
5
- export {};
@@ -1,262 +0,0 @@
1
- import { MockAgent } from 'undici';
2
- import { mockEvent, mockMeter, mockMeterValue, mockSubject } from './mocks.js';
3
- export const mockAgent = new MockAgent();
4
- mockAgent.disableNetConnect();
5
- const client = mockAgent.get('http://127.0.0.1:8888');
6
- /** Event */
7
- client
8
- .intercept({
9
- path: '/api/v1/events',
10
- method: 'POST',
11
- headers: {
12
- Accept: 'application/json',
13
- 'Content-Type': 'application/cloudevents+json',
14
- },
15
- body: JSON.stringify({
16
- specversion: '1.0',
17
- id: 'id-1',
18
- source: 'my-app',
19
- type: 'my-type',
20
- subject: 'my-awesome-user-id',
21
- time: new Date('2023-01-01'),
22
- data: {
23
- api_calls: 1,
24
- },
25
- }),
26
- })
27
- .reply(204);
28
- // Batch ingest
29
- client
30
- .intercept({
31
- path: '/api/v1/events',
32
- method: 'POST',
33
- headers: {
34
- Accept: 'application/json',
35
- 'Content-Type': 'application/cloudevents-batch+json',
36
- },
37
- body: JSON.stringify([
38
- {
39
- specversion: '1.0',
40
- id: 'id-1',
41
- source: 'my-app',
42
- type: 'my-type',
43
- subject: 'my-awesome-user-id',
44
- time: new Date('2023-01-01'),
45
- data: {
46
- api_calls: 1,
47
- },
48
- }
49
- ]),
50
- })
51
- .reply(204);
52
- client
53
- .intercept({
54
- path: `/api/v1/events`,
55
- method: 'GET',
56
- headers: {
57
- Accept: 'application/json',
58
- },
59
- })
60
- .reply(200, [
61
- {
62
- event: mockEvent,
63
- },
64
- ], {
65
- headers: {
66
- 'Content-Type': 'application/json',
67
- },
68
- });
69
- client
70
- .intercept({
71
- path: '/api/v1/events',
72
- method: 'POST',
73
- headers: {
74
- Accept: 'application/json',
75
- 'Content-Type': 'application/cloudevents+json',
76
- },
77
- body: JSON.stringify({
78
- specversion: '1.0',
79
- id: 'aaf17be7-860c-4519-91d3-00d97da3cc65',
80
- source: '@openmeter/sdk',
81
- type: 'my-type',
82
- subject: 'my-awesome-user-id',
83
- data: {
84
- api_calls: 1,
85
- },
86
- }),
87
- })
88
- .reply(204);
89
- /** Portal */
90
- client
91
- .intercept({
92
- path: '/api/v1/meters',
93
- method: 'GET',
94
- headers: {
95
- Accept: 'application/json',
96
- },
97
- })
98
- .reply(200, [mockMeter], {
99
- headers: {
100
- 'Content-Type': 'application/json',
101
- },
102
- });
103
- client
104
- .intercept({
105
- path: `/api/v1/meters/${mockMeter.slug}`,
106
- method: 'GET',
107
- headers: {
108
- Accept: 'application/json',
109
- },
110
- })
111
- .reply(200, mockMeter, {
112
- headers: {
113
- 'Content-Type': 'application/json',
114
- },
115
- });
116
- /** Meter Query */
117
- client
118
- .intercept({
119
- path: `/api/v1/meters/${mockMeter.slug}/query`,
120
- query: {},
121
- method: 'GET',
122
- headers: {
123
- Accept: 'application/json',
124
- },
125
- })
126
- .reply(200, {
127
- from: mockMeterValue.windowStart,
128
- to: mockMeterValue.windowEnd,
129
- windowSize: 'HOUR',
130
- data: [mockMeterValue],
131
- }, {
132
- headers: {
133
- 'Content-Type': 'application/json',
134
- },
135
- });
136
- client
137
- .intercept({
138
- path: `/api/v1/meters/${mockMeter.slug}/query`,
139
- query: {
140
- subject: 'user-1',
141
- groupBy: ['a', 'b'],
142
- from: new Date('2021-01-01').toISOString(),
143
- to: new Date('2021-01-02').toISOString(),
144
- windowSize: 'HOUR',
145
- 'filterGroupBy[model]': 'gpt-4',
146
- },
147
- method: 'GET',
148
- headers: {
149
- Accept: 'application/json',
150
- },
151
- })
152
- .reply(200, {
153
- from: mockMeterValue.windowStart,
154
- to: mockMeterValue.windowEnd,
155
- windowSize: 'HOUR',
156
- data: [mockMeterValue],
157
- }, {
158
- headers: {
159
- 'Content-Type': 'application/json',
160
- },
161
- });
162
- /** Meter Subjects */
163
- client
164
- .intercept({
165
- path: `/api/v1/meters/${mockMeter.slug}/subjects`,
166
- method: 'GET',
167
- headers: {
168
- Accept: 'application/json',
169
- },
170
- })
171
- .reply(200, [mockMeterValue.subject], {
172
- headers: {
173
- 'Content-Type': 'application/json',
174
- },
175
- });
176
- /** Portal */
177
- client
178
- .intercept({
179
- path: '/api/v1/portal/tokens',
180
- method: 'POST',
181
- headers: {
182
- Accept: 'application/json',
183
- 'Content-Type': 'application/json',
184
- },
185
- body: JSON.stringify({
186
- subject: 'customer-1',
187
- }),
188
- })
189
- .reply(201, {
190
- subject: 'customer-1',
191
- expiresAt: new Date('2023-01-01'),
192
- }, {
193
- headers: {
194
- 'Content-Type': 'application/json',
195
- },
196
- });
197
- client
198
- .intercept({
199
- path: '/api/v1/portal/tokens/invalidate',
200
- method: 'POST',
201
- headers: {
202
- Accept: 'application/json',
203
- 'Content-Type': 'application/json',
204
- },
205
- body: JSON.stringify({}),
206
- })
207
- .reply(204);
208
- /** Subjects */
209
- client
210
- .intercept({
211
- path: '/api/v1/subjects',
212
- method: 'POST',
213
- headers: {
214
- Accept: 'application/json',
215
- 'Content-Type': 'application/json',
216
- },
217
- body: JSON.stringify([{
218
- key: mockSubject.key,
219
- displayName: mockSubject.displayName,
220
- metadata: mockSubject.metadata,
221
- }]),
222
- })
223
- .reply(200, [mockSubject], {
224
- headers: {
225
- 'Content-Type': 'application/json',
226
- },
227
- });
228
- client
229
- .intercept({
230
- path: '/api/v1/subjects',
231
- method: 'GET',
232
- headers: {
233
- Accept: 'application/json',
234
- },
235
- })
236
- .reply(200, [mockSubject], {
237
- headers: {
238
- 'Content-Type': 'application/json',
239
- },
240
- });
241
- client
242
- .intercept({
243
- path: '/api/v1/subjects/customer-1',
244
- method: 'GET',
245
- headers: {
246
- Accept: 'application/json',
247
- },
248
- })
249
- .reply(200, mockSubject, {
250
- headers: {
251
- 'Content-Type': 'application/json',
252
- },
253
- });
254
- client
255
- .intercept({
256
- path: '/api/v1/subjects/customer-1',
257
- method: 'DELETE',
258
- headers: {
259
- Accept: 'application/json',
260
- },
261
- })
262
- .reply(204);
@@ -1,40 +0,0 @@
1
- import { WindowSize } from '../index.js';
2
- export const mockEvent = {
3
- specversion: '1.0',
4
- id: 'id-1',
5
- source: 'my-app',
6
- type: 'my-type',
7
- subject: 'my-awesome-user-id',
8
- time: new Date('2023-01-01'),
9
- data: {
10
- api_calls: 1,
11
- },
12
- };
13
- export const mockMeter = {
14
- slug: 'm1',
15
- aggregation: 'SUM',
16
- eventType: 'api_requests',
17
- valueProperty: '$.duration_ms',
18
- windowSize: WindowSize.HOUR,
19
- groupBy: {
20
- method: '$.method',
21
- path: '$.path',
22
- },
23
- };
24
- export const mockMeterValue = {
25
- subject: 'customer-1',
26
- windowStart: '2023-01-01T01:00:00.001Z',
27
- windowEnd: '2023-01-01T01:00:00.001Z',
28
- value: 1,
29
- groupBy: {
30
- method: 'GET',
31
- },
32
- };
33
- export const mockSubject = {
34
- id: 'abcde',
35
- key: 'customer-1',
36
- displayName: 'Customer 1',
37
- metadata: {
38
- foo: 'bar',
39
- },
40
- };