// Code generated by @openmeter/typespec-typescript. DO NOT EDIT. import { type Client, http } from '../core.js' import { type Result, type RequestOptions } from '../lib/types.js' import { request } from '../lib/request.js' import { toURLSearchParams, encodeSort } from '../lib/encodings.js' import { toWire, fromWire, assertValid, toSnakeCase } from '../lib/wire.js' import * as schemas from '../models/schemas.js' import type { ListMeteringEventsRequest, ListMeteringEventsResponse, IngestMeteringEventsRequest, IngestMeteringEventsResponse, } from '../models/operations/events.js' /** * List metering events * * List ingested events. * * GET /openmeter/events */ export function listMeteringEvents( client: Client, req: ListMeteringEventsRequest = {}, options?: RequestOptions, ): Promise> { return request(() => { if (client._options.validate && req.sort !== undefined) { assertValid(schemas.listMeteringEventsQueryParams.shape.sort, req.sort) } const query = toWire( { page: req.page, filter: req.filter, sort: encodeSort(req.sort, toSnakeCase), }, schemas.listMeteringEventsQueryParams, ) if (client._options.validate) { assertValid(schemas.listMeteringEventsQueryParamsWire, query) } const searchParams = toURLSearchParams(query) return http(client) .get('openmeter/events', { ...options, searchParams }) .json() .then((data) => { if (client._options.validate) { assertValid(schemas.listMeteringEventsResponseWire, data) } return fromWire(data, schemas.listMeteringEventsResponse) }) }) } /** * Ingest metering events * * Ingests an event or batch of events following the CloudEvents specification. * * POST /openmeter/events */ export function ingestMeteringEvents( client: Client, req: IngestMeteringEventsRequest, options?: RequestOptions, ): Promise> { return request(async () => { const body = toWire(req, schemas.ingestMeteringEventsBody) if (client._options.validate) { assertValid(schemas.ingestMeteringEventsBodyWire, body) } await http(client).post('openmeter/events', { ...options, json: body }) }) }