| |
|
|
| 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, |
| toPathWire, |
| fromWire, |
| assertValid, |
| toSnakeCase, |
| } from '../lib/wire.js' |
| import * as schemas from '../models/schemas.js' |
| import type { |
| CreateSubscriptionRequest, |
| CreateSubscriptionResponse, |
| ListSubscriptionsRequest, |
| ListSubscriptionsResponse, |
| GetSubscriptionRequest, |
| GetSubscriptionResponse, |
| CancelSubscriptionRequest, |
| CancelSubscriptionResponse, |
| UnscheduleCancelationRequest, |
| UnscheduleCancelationResponse, |
| ChangeSubscriptionRequest, |
| ChangeSubscriptionResponse, |
| CreateSubscriptionAddonRequest, |
| CreateSubscriptionAddonResponse, |
| ListSubscriptionAddonsRequest, |
| ListSubscriptionAddonsResponse, |
| GetSubscriptionAddonRequest, |
| GetSubscriptionAddonResponse, |
| } from '../models/operations/subscriptions.js' |
|
|
| |
| |
| |
| |
| |
| export function createSubscription( |
| client: Client, |
| req: CreateSubscriptionRequest, |
| options?: RequestOptions, |
| ): Promise<Result<CreateSubscriptionResponse>> { |
| return request(() => { |
| const body = toWire(req, schemas.createSubscriptionBody) |
| if (client._options.validate) { |
| assertValid(schemas.createSubscriptionBodyWire, body) |
| } |
| return http(client) |
| .post('openmeter/subscriptions', { ...options, json: body }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.createSubscriptionResponseWire, data) |
| } |
| return fromWire(data, schemas.createSubscriptionResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| export function listSubscriptions( |
| client: Client, |
| req: ListSubscriptionsRequest = {}, |
| options?: RequestOptions, |
| ): Promise<Result<ListSubscriptionsResponse>> { |
| return request(() => { |
| if (client._options.validate && req.sort !== undefined) { |
| assertValid(schemas.listSubscriptionsQueryParams.shape.sort, req.sort) |
| } |
| const query = toWire( |
| { |
| page: req.page, |
| sort: encodeSort(req.sort, toSnakeCase), |
| filter: req.filter, |
| }, |
| schemas.listSubscriptionsQueryParams, |
| ) |
| if (client._options.validate) { |
| assertValid(schemas.listSubscriptionsQueryParamsWire, query) |
| } |
| const searchParams = toURLSearchParams(query) |
| return http(client) |
| .get('openmeter/subscriptions', { ...options, searchParams }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.listSubscriptionsResponseWire, data) |
| } |
| return fromWire(data, schemas.listSubscriptionsResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| export function getSubscription( |
| client: Client, |
| req: GetSubscriptionRequest, |
| options?: RequestOptions, |
| ): Promise<Result<GetSubscriptionResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| subscriptionId: req.subscriptionId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.getSubscriptionPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.getSubscriptionPathParamsWire, pathParams) |
| } |
| const path = `openmeter/subscriptions/${(() => { |
| if (pathParams.subscriptionId === undefined) { |
| throw new Error('missing path parameter: subscriptionId') |
| } |
| return encodeURIComponent(String(pathParams.subscriptionId)) |
| })()}` |
| return http(client) |
| .get(path, options) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.getSubscriptionResponseWire, data) |
| } |
| return fromWire(data, schemas.getSubscriptionResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| export function cancelSubscription( |
| client: Client, |
| req: CancelSubscriptionRequest, |
| options?: RequestOptions, |
| ): Promise<Result<CancelSubscriptionResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| subscriptionId: req.subscriptionId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.cancelSubscriptionPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.cancelSubscriptionPathParamsWire, pathParams) |
| } |
| const path = `openmeter/subscriptions/${(() => { |
| if (pathParams.subscriptionId === undefined) { |
| throw new Error('missing path parameter: subscriptionId') |
| } |
| return encodeURIComponent(String(pathParams.subscriptionId)) |
| })()}/cancel` |
| const body = toWire(req.body, schemas.cancelSubscriptionBody) |
| if (client._options.validate) { |
| assertValid(schemas.cancelSubscriptionBodyWire, body) |
| } |
| return http(client) |
| .post(path, { ...options, json: body }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.cancelSubscriptionResponseWire, data) |
| } |
| return fromWire(data, schemas.cancelSubscriptionResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| export function unscheduleCancelation( |
| client: Client, |
| req: UnscheduleCancelationRequest, |
| options?: RequestOptions, |
| ): Promise<Result<UnscheduleCancelationResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| subscriptionId: req.subscriptionId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.unscheduleCancelationPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.unscheduleCancelationPathParamsWire, pathParams) |
| } |
| const path = `openmeter/subscriptions/${(() => { |
| if (pathParams.subscriptionId === undefined) { |
| throw new Error('missing path parameter: subscriptionId') |
| } |
| return encodeURIComponent(String(pathParams.subscriptionId)) |
| })()}/unschedule-cancelation` |
| return http(client) |
| .post(path, options) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.unscheduleCancelationResponseWire, data) |
| } |
| return fromWire(data, schemas.unscheduleCancelationResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| export function changeSubscription( |
| client: Client, |
| req: ChangeSubscriptionRequest, |
| options?: RequestOptions, |
| ): Promise<Result<ChangeSubscriptionResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| subscriptionId: req.subscriptionId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.changeSubscriptionPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.changeSubscriptionPathParamsWire, pathParams) |
| } |
| const path = `openmeter/subscriptions/${(() => { |
| if (pathParams.subscriptionId === undefined) { |
| throw new Error('missing path parameter: subscriptionId') |
| } |
| return encodeURIComponent(String(pathParams.subscriptionId)) |
| })()}/change` |
| const body = toWire(req.body, schemas.changeSubscriptionBody) |
| if (client._options.validate) { |
| assertValid(schemas.changeSubscriptionBodyWire, body) |
| } |
| return http(client) |
| .post(path, { ...options, json: body }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.changeSubscriptionResponseWire, data) |
| } |
| return fromWire(data, schemas.changeSubscriptionResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| export function createSubscriptionAddon( |
| client: Client, |
| req: CreateSubscriptionAddonRequest, |
| options?: RequestOptions, |
| ): Promise<Result<CreateSubscriptionAddonResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| subscriptionId: req.subscriptionId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.createSubscriptionAddonPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.createSubscriptionAddonPathParamsWire, pathParams) |
| } |
| const path = `openmeter/subscriptions/${(() => { |
| if (pathParams.subscriptionId === undefined) { |
| throw new Error('missing path parameter: subscriptionId') |
| } |
| return encodeURIComponent(String(pathParams.subscriptionId)) |
| })()}/addons` |
| const body = toWire(req.body, schemas.createSubscriptionAddonBody) |
| if (client._options.validate) { |
| assertValid(schemas.createSubscriptionAddonBodyWire, body) |
| } |
| return http(client) |
| .post(path, { ...options, json: body }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.createSubscriptionAddonResponseWire, data) |
| } |
| return fromWire(data, schemas.createSubscriptionAddonResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| export function listSubscriptionAddons( |
| client: Client, |
| req: ListSubscriptionAddonsRequest, |
| options?: RequestOptions, |
| ): Promise<Result<ListSubscriptionAddonsResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| subscriptionId: req.subscriptionId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.listSubscriptionAddonsPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.listSubscriptionAddonsPathParamsWire, pathParams) |
| } |
| const path = `openmeter/subscriptions/${(() => { |
| if (pathParams.subscriptionId === undefined) { |
| throw new Error('missing path parameter: subscriptionId') |
| } |
| return encodeURIComponent(String(pathParams.subscriptionId)) |
| })()}/addons` |
| if (client._options.validate && req.sort !== undefined) { |
| assertValid( |
| schemas.listSubscriptionAddonsQueryParams.shape.sort, |
| req.sort, |
| ) |
| } |
| const query = toWire( |
| { |
| page: req.page, |
| sort: encodeSort(req.sort, toSnakeCase), |
| }, |
| schemas.listSubscriptionAddonsQueryParams, |
| ) |
| if (client._options.validate) { |
| assertValid(schemas.listSubscriptionAddonsQueryParamsWire, query) |
| } |
| const searchParams = toURLSearchParams(query) |
| return http(client) |
| .get(path, { ...options, searchParams }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.listSubscriptionAddonsResponseWire, data) |
| } |
| return fromWire(data, schemas.listSubscriptionAddonsResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| export function getSubscriptionAddon( |
| client: Client, |
| req: GetSubscriptionAddonRequest, |
| options?: RequestOptions, |
| ): Promise<Result<GetSubscriptionAddonResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| subscriptionId: req.subscriptionId, |
| subscriptionAddonId: req.subscriptionAddonId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.getSubscriptionAddonPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.getSubscriptionAddonPathParamsWire, pathParams) |
| } |
| const path = `openmeter/subscriptions/${(() => { |
| if (pathParams.subscriptionId === undefined) { |
| throw new Error('missing path parameter: subscriptionId') |
| } |
| return encodeURIComponent(String(pathParams.subscriptionId)) |
| })()}/addons/${(() => { |
| if (pathParams.subscriptionAddonId === undefined) { |
| throw new Error('missing path parameter: subscriptionAddonId') |
| } |
| return encodeURIComponent(String(pathParams.subscriptionAddonId)) |
| })()}` |
| return http(client) |
| .get(path, options) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.getSubscriptionAddonResponseWire, data) |
| } |
| return fromWire(data, schemas.getSubscriptionAddonResponse) |
| }) |
| }) |
| } |
|
|