Skip to content

Commit 1f3c37e

Browse files
committed
feat(api): add event subject list endpoint
1 parent c394e83 commit 1f3c37e

34 files changed

Lines changed: 2280 additions & 721 deletions

api/spec/packages/aip-client-javascript/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ The full call path, HTTP route, and a short description are listed below.
113113

114114
### Events
115115

116-
| Method | HTTP | Description |
117-
| ---------------------- | ------------------------ | ---------------------------------------------------------------------------- |
118-
| `client.events.list` | `GET /openmeter/events` | List ingested events. |
119-
| `client.events.ingest` | `POST /openmeter/events` | Ingests an event or batch of events following the CloudEvents specification. |
116+
| Method | HTTP | Description |
117+
| ---------------------------- | -------------------------------- | ------------------------------------------------------------------------------------- |
118+
| `client.events.list` | `GET /openmeter/events` | List ingested events. |
119+
| `client.events.ingest` | `POST /openmeter/events` | Ingests an event or batch of events following the CloudEvents specification. |
120+
| `client.events.listSubjects` | `GET /openmeter/events/subjects` | List the subjects of the ingested events. Subjects are ordered by key alphabetically. |
120121

121122
### Meters
122123

api/spec/packages/aip-client-javascript/src/funcs/events.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import type {
77
ListMeteringEventsResponse,
88
IngestMeteringEventsRequest,
99
IngestMeteringEventsResponse,
10+
ListEventSubjectsRequest,
11+
ListEventSubjectsResponse,
1012
} from '../models/operations/events.js'
1113

1214
export function listMeteringEvents(
@@ -35,3 +37,19 @@ export function ingestMeteringEvents(
3537
await http(client).post('openmeter/events', { ...options, json: req })
3638
})
3739
}
40+
41+
export function listEventSubjects(
42+
client: Client,
43+
req: ListEventSubjectsRequest = {},
44+
options?: RequestOptions,
45+
): Promise<Result<ListEventSubjectsResponse>> {
46+
const searchParams = toURLSearchParams({
47+
page: req.page,
48+
filter: req.filter,
49+
})
50+
return request(() =>
51+
http(client)
52+
.get('openmeter/events/subjects', { ...options, searchParams })
53+
.json<ListEventSubjectsResponse>(),
54+
)
55+
}

api/spec/packages/aip-client-javascript/src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export type {
138138
Internal,
139139
NotImplemented,
140140
NotAvailable,
141+
ListSubjectsParamsFilter,
141142
CreateCreditGrantFilters,
142143
CreditGrantFilters,
143144
UpsertPlanAddonRequest,
@@ -146,7 +147,6 @@ export type {
146147
Meter,
147148
PaginatedMeta,
148149
QueryFilterStringMapItem,
149-
SubscriptionCreate,
150150
CustomerKeyReference,
151151
CustomerUsageAttribution,
152152
BillingAddress,
@@ -165,6 +165,7 @@ export type {
165165
GetCreditBalanceParamsFilter,
166166
ListChargesParamsFilter,
167167
ListPlansParamsFilter,
168+
SubscriptionCreate,
168169
RateCardProrationConfiguration,
169170
Subscription,
170171
AppCatalogItem,
@@ -193,6 +194,7 @@ export type {
193194
ListSubscriptionsParamsFilter,
194195
ListFeatureParamsFilter,
195196
ListAddonsParamsFilter,
197+
EventSubject,
196198
CreateCreditGrantTaxConfig,
197199
CreditGrantTaxConfig,
198200
TaxConfig,
@@ -239,6 +241,7 @@ export type {
239241
PriceGraduated,
240242
PriceVolume,
241243
PricePagePaginatedResponse,
244+
SubjectPaginatedResponse,
242245
CreateCreditGrantRequest,
243246
CreditGrant,
244247
WorkflowTaxSettings,
@@ -303,10 +306,15 @@ export type {
303306
AppStripeCreateCheckoutSessionTaxIdCollectionInput,
304307
CreateCreditGrantPurchaseInput,
305308
CreditGrantPurchaseInput,
309+
SubscriptionCreateInput,
310+
SubscriptionInput,
306311
GovernanceQueryRequestInput,
307312
UnitConfigInput,
308313
IngestedEventInput,
314+
SubscriptionPagePaginatedResponseInput,
315+
SubscriptionChangeResponseInput,
309316
SubscriptionCancelInput,
317+
SubscriptionChangeInput,
310318
InvoiceUsageQuantityDetailInput,
311319
CreateCreditGrantRequestInput,
312320
CreditGrantInput,

api/spec/packages/aip-client-javascript/src/models/operations/events.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import type {
55
EventInput,
66
IngestedEventPaginatedResponse,
77
ListEventsParamsFilter,
8+
ListSubjectsParamsFilter,
89
SortQueryInput,
10+
SubjectPaginatedResponse,
911
} from '../types.js'
1012

1113
export interface ListMeteringEventsQuery {
@@ -21,3 +23,12 @@ export type ListMeteringEventsResponse = IngestedEventPaginatedResponse
2123

2224
export type IngestMeteringEventsRequest = EventInput | EventInput[]
2325
export type IngestMeteringEventsResponse = void
26+
27+
export interface ListEventSubjectsQuery {
28+
page?: CursorPaginationQueryPage
29+
/** Filter subjects returned in the response. To filter subjects by key add the following query param: filter[key][contains]=customer */
30+
filter?: ListSubjectsParamsFilter
31+
}
32+
33+
export type ListEventSubjectsRequest = ListEventSubjectsQuery
34+
export type ListEventSubjectsResponse = SubjectPaginatedResponse

api/spec/packages/aip-client-javascript/src/models/operations/subscriptions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import type {
77
SubscriptionAddon,
88
SubscriptionAddonPagePaginatedResponse,
99
SubscriptionCancelInput,
10-
SubscriptionChange,
10+
SubscriptionChangeInput,
1111
SubscriptionChangeResponse,
12-
SubscriptionCreate,
12+
SubscriptionCreateInput,
1313
SubscriptionPagePaginatedResponse,
1414
} from '../types.js'
1515

16-
export type CreateSubscriptionRequest = SubscriptionCreate
16+
export type CreateSubscriptionRequest = SubscriptionCreateInput
1717
export type CreateSubscriptionResponse = Subscription
1818

1919
export interface ListSubscriptionsQuery {
@@ -46,7 +46,7 @@ export type UnscheduleCancelationResponse = Subscription
4646

4747
export type ChangeSubscriptionRequest = {
4848
subscriptionId: string
49-
body: SubscriptionChange
49+
body: SubscriptionChangeInput
5050
}
5151
export type ChangeSubscriptionResponse = SubscriptionChangeResponse
5252

api/spec/packages/aip-client-javascript/src/models/schemas.ts

Lines changed: 73 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,17 @@ export const baseError = z
253253
)
254254
.describe('Standard error response.')
255255

256+
export const booleanFieldFilter = z
257+
.union([
258+
z.boolean(),
259+
z.object({
260+
eq: z
261+
.boolean()
262+
.describe('Value strictly equals the given boolean value.'),
263+
}),
264+
])
265+
.describe('Filter by a boolean value (true/false).')
266+
256267
export const resourceKey = z
257268
.string()
258269
.min(1)
@@ -1025,17 +1036,6 @@ export const publicLabels = z
10251036
'Public labels store information about an entity that can be used for filtering a list of objects.',
10261037
)
10271038

1028-
export const booleanFieldFilter = z
1029-
.union([
1030-
z.boolean(),
1031-
z.object({
1032-
eq: z
1033-
.boolean()
1034-
.describe('Value strictly equals the given boolean value.'),
1035-
}),
1036-
])
1037-
.describe('Filter by a boolean value (true/false).')
1038-
10391039
export const numericFieldFilter = z
10401040
.union([
10411041
z.number(),
@@ -1907,6 +1907,13 @@ export const notImplemented = baseError.describe('Not Implemented.')
19071907

19081908
export const notAvailable = baseError.describe('Not Available.')
19091909

1910+
export const listSubjectsParamsFilter = z
1911+
.object({
1912+
key: stringFieldFilter.optional(),
1913+
attributed: booleanFieldFilter.optional(),
1914+
})
1915+
.describe('Filter options for listing subjects.')
1916+
19101917
export const createCreditGrantFilters = z
19111918
.object({
19121919
features: z
@@ -2132,33 +2139,6 @@ export const queryFilterStringMapItem = z
21322139
'A query filter for an item in a string map attribute. Operators are mutually exclusive, only one operator is allowed at a time.',
21332140
)
21342141

2135-
export const subscriptionCreate = z
2136-
.object({
2137-
labels: labels.optional(),
2138-
customer: z
2139-
.object({
2140-
id: ulid.optional(),
2141-
key: externalResourceKey.optional(),
2142-
})
2143-
.describe('The customer to create the subscription for.'),
2144-
plan: z
2145-
.object({
2146-
id: ulid.optional(),
2147-
key: resourceKey.optional(),
2148-
version: z
2149-
.number()
2150-
.int()
2151-
.optional()
2152-
2153-
.describe(
2154-
'The plan version of the subscription, if any. If not provided, the latest version of the plan will be used.',
2155-
),
2156-
})
2157-
.describe('The plan reference of the subscription.'),
2158-
billing_anchor: dateTime.optional(),
2159-
})
2160-
.describe('Subscription create request.')
2161-
21622142
export const ulidOrExternalResourceKey = z
21632143
.union([ulid, externalResourceKey])
21642144
.describe('ULID ID or External Resource Key.')
@@ -2415,6 +2395,34 @@ export const listPlansParamsFilter = z
24152395
})
24162396
.describe('Filter options for listing plans.')
24172397

2398+
export const subscriptionCreate = z
2399+
.object({
2400+
labels: labels.optional(),
2401+
settlement_mode: settlementMode.optional().default('credit_then_invoice'),
2402+
customer: z
2403+
.object({
2404+
id: ulid.optional(),
2405+
key: externalResourceKey.optional(),
2406+
})
2407+
.describe('The customer to create the subscription for.'),
2408+
plan: z
2409+
.object({
2410+
id: ulid.optional(),
2411+
key: resourceKey.optional(),
2412+
version: z
2413+
.number()
2414+
.int()
2415+
.optional()
2416+
2417+
.describe(
2418+
'The plan version of the subscription, if any. If not provided, the latest version of the plan will be used.',
2419+
),
2420+
})
2421+
.describe('The plan reference of the subscription.'),
2422+
billing_anchor: dateTime.optional(),
2423+
})
2424+
.describe('Subscription create request.')
2425+
24182426
export const rateCardProrationConfiguration = z
24192427
.object({
24202428
mode: rateCardProrationMode,
@@ -2432,6 +2440,7 @@ export const subscription = z
24322440
plan_id: ulid.optional(),
24332441
billing_anchor: dateTime,
24342442
status: subscriptionStatus,
2443+
settlement_mode: settlementMode.optional().default('credit_then_invoice'),
24352444
})
24362445
.describe('Subscription.')
24372446

@@ -2865,6 +2874,13 @@ export const listAddonsParamsFilter = z
28652874
})
28662875
.describe('Filter options for listing add-ons.')
28672876

2877+
export const eventSubject = z
2878+
.object({
2879+
key: z.string().min(1).describe('The key of the subject.'),
2880+
customer: customerReference.optional(),
2881+
})
2882+
.describe('Subject of an event.')
2883+
28682884
export const createCreditGrantTaxConfig = z
28692885
.object({
28702886
behavior: taxBehavior.optional(),
@@ -3296,6 +3312,7 @@ export const subscriptionCancel = z
32963312
export const subscriptionChange = z
32973313
.object({
32983314
labels: labels.optional(),
3315+
settlement_mode: settlementMode.optional().default('credit_then_invoice'),
32993316
customer: z
33003317
.object({
33013318
id: ulid.optional(),
@@ -3615,6 +3632,13 @@ export const pricePagePaginatedResponse = z
36153632
})
36163633
.describe('Page paginated response.')
36173634

3635+
export const subjectPaginatedResponse = z
3636+
.object({
3637+
data: z.array(eventSubject),
3638+
meta: cursorMeta,
3639+
})
3640+
.describe('Cursor paginated response.')
3641+
36183642
export const createCreditGrantRequest = z
36193643
.object({
36203644
name: z
@@ -4454,6 +4478,7 @@ export const plan = z
44544478
.describe(
44554479
'The plan phases define the pricing ramp for a subscription. A phase switch occurs only at the end of a billing period. At least one phase is required.',
44564480
),
4481+
settlement_mode: settlementMode.optional().default('credit_then_invoice'),
44574482
validation_errors: z
44584483
.array(productCatalogValidationError)
44594484
.optional()
@@ -4563,6 +4588,16 @@ export const listMeteringEventsResponse = z.object({
45634588

45644589
export const ingestMeteringEventsBody = event
45654590

4591+
export const listEventSubjectsQueryParams = z.object({
4592+
page: cursorPaginationQueryPage.optional(),
4593+
filter: listSubjectsParamsFilter.optional(),
4594+
})
4595+
4596+
export const listEventSubjectsResponse = z.object({
4597+
data: z.array(eventSubject),
4598+
meta: cursorMeta,
4599+
})
4600+
45664601
export const createMeterBody = createMeterRequest
45674602

45684603
export const createMeterResponse = meter

0 commit comments

Comments
 (0)