Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ List methods return a `PagePromise`. Awaited, it gives the first `Page`: the res
properties read on the page, with `items`, `hasNextPage()`, `getNextPage()` and `iterPages()`.
Iterated with `for await`, it yields every item of every page.

[Add ons](#add-ons) · [Add ons entitlements](#add-ons-entitlements) · [Batch jobs](#batch-jobs) · [Checkout sessions](#checkout-sessions) · [Connect](#connect) · [Coupons](#coupons) · [Credit notes](#credit-notes) · [Custom properties](#custom-properties) · [Customers](#customers) · [Entitlements](#entitlements) · [Events](#events) · [Features](#features) · [Invoices](#invoices) · [Metrics](#metrics) · [Oauth](#oauth) · [Oauth apps](#oauth-apps) · [Plans](#plans) · [Plans versions](#plans-versions) · [Product families](#product-families) · [Products](#products) · [Products entitlements](#products-entitlements) · [Subscriptions](#subscriptions) · [Usage](#usage)
[Add ons](#add-ons) · [Add ons entitlements](#add-ons-entitlements) · [Batch jobs](#batch-jobs) · [Checkout sessions](#checkout-sessions) · [Connect](#connect) · [Coupons](#coupons) · [Credit notes](#credit-notes) · [Custom properties](#custom-properties) · [Customers](#customers) · [Entitlements](#entitlements) · [Events](#events) · [Features](#features) · [Invoices](#invoices) · [Metrics](#metrics) · [Oauth](#oauth) · [Oauth apps](#oauth-apps) · [Plans](#plans) · [Plans versions](#plans-versions) · [Product families](#product-families) · [Products](#products) · [Products entitlements](#products-entitlements) · [Subscriptions](#subscriptions) · [Usage](#usage) · [Webhook endpoints](#webhook-endpoints) · [Webhook endpoints endpoints](#webhook-endpoints-endpoints)

## Add ons

Expand Down Expand Up @@ -284,3 +284,26 @@ Iterated with `for await`, it yields every item of every page.
| `client.usage.retrieveCustomer(customerId: string, options: UsageRetrieveCustomerOptions): APIPromise<UsageResponse>` | `GET /api/v1/usage/customer/{customer_id}` | [`UsageResponse`](src/models/usageResponse.ts) |
| `client.usage.retrieveSubscription(subscriptionId: string, options?: UsageRetrieveSubscriptionOptions): APIPromise<UsageResponse>` | `GET /api/v1/usage/subscription/{subscription_id}` | [`UsageResponse`](src/models/usageResponse.ts) |
| `client.usage.retrieveSummary(options: UsageRetrieveSummaryOptions): APIPromise<UsageResponse>` | `GET /api/v1/usage/summary` | [`UsageResponse`](src/models/usageResponse.ts) |

## Webhook endpoints

[`client.webhookEndpoints`](src/api/webhookEndpoints.ts)

| Method | Request | Returns |
| --- | --- | --- |
| `client.webhookEndpoints.resendWebhookDelivery(deliveryId: string): APIPromise<WebhookDelivery>` | `POST /api/v1/webhooks/deliveries/{delivery_id}/resend` | [`WebhookDelivery`](src/models/webhookDelivery.ts) |

### Webhook endpoints endpoints

[`client.webhookEndpoints.endpoints`](src/api/webhookEndpointsEndpoints.ts)

| Method | Request | Returns |
| --- | --- | --- |
| `client.webhookEndpoints.endpoints.list(): APIPromise<WebhookEndpointListResponse>` | `GET /api/v1/webhooks/endpoints` | [`WebhookEndpointListResponse`](src/models/webhookEndpointListResponse.ts) |
| `client.webhookEndpoints.endpoints.create(createWebhookEndpointRequest: CreateWebhookEndpointRequest): APIPromise<CreatedWebhookEndpoint>` | `POST /api/v1/webhooks/endpoints` | [`CreatedWebhookEndpoint`](src/models/createdWebhookEndpoint.ts) |
| `client.webhookEndpoints.endpoints.retrieve(endpointId: string): APIPromise<WebhookEndpoint>` | `GET /api/v1/webhooks/endpoints/{endpoint_id}` | [`WebhookEndpoint`](src/models/webhookEndpoint.ts) |
| `client.webhookEndpoints.endpoints.delete(endpointId: string): APIPromise<void>` | `DELETE /api/v1/webhooks/endpoints/{endpoint_id}` | nothing |
| `client.webhookEndpoints.endpoints.update(endpointId: string, updateWebhookEndpointRequest: UpdateWebhookEndpointRequest): APIPromise<WebhookEndpoint>` | `PATCH /api/v1/webhooks/endpoints/{endpoint_id}` | [`WebhookEndpoint`](src/models/webhookEndpoint.ts) |
| `client.webhookEndpoints.endpoints.listDeliveries(endpointId: string, options?: WebhookEndpointsEndpointsListDeliveriesOptions): PagePromise<WebhookDeliveryListResponse, WebhookDelivery>` | `GET /api/v1/webhooks/endpoints/{endpoint_id}/deliveries` | [`WebhookDeliveryListResponse`](src/models/webhookDeliveryListResponse.ts) pages of [`WebhookDelivery`](src/models/webhookDelivery.ts) |
| `client.webhookEndpoints.endpoints.rotateSecret(endpointId: string): APIPromise<WebhookEndpointSecret>` | `POST /api/v1/webhooks/endpoints/{endpoint_id}/rotate-secret` | [`WebhookEndpointSecret`](src/models/webhookEndpointSecret.ts) |
| `client.webhookEndpoints.endpoints.retrieveSecret(endpointId: string): APIPromise<WebhookEndpointSecret>` | `GET /api/v1/webhooks/endpoints/{endpoint_id}/secret` | [`WebhookEndpointSecret`](src/models/webhookEndpointSecret.ts) |
44 changes: 44 additions & 0 deletions src/api/webhookEndpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// this file is @generated

import {
type WebhookDelivery,
WebhookDeliverySerializer,
} from "../models/webhookDelivery.js";
import { WebhookEndpointsEndpoints } from "./webhookEndpointsEndpoints.js";
import type { APIPromise } from "../apiPromise.js";
import {
MeteroidRequest,
type MeteroidRequestContext,
type RequestOptions,
} from "../request.js";

/** The webhook endpoints operations, reached through the client's `webhookEndpoints`. */
export class WebhookEndpoints {
private _endpoints?: WebhookEndpointsEndpoints;
/** @internal */
public constructor(private readonly requestCtx: MeteroidRequestContext) {}

/** The endpoints operations. */
public get endpoints(): WebhookEndpointsEndpoints {
this._endpoints ??= new WebhookEndpointsEndpoints(this.requestCtx);
return this._endpoints;
}

/**
* Resend a webhook delivery
*
* Re-queues the same event for the same endpoint. Fails if the endpoint is disabled.
*/
public resendWebhookDelivery(
deliveryId: string,
requestOptions?: RequestOptions
): APIPromise<WebhookDelivery> {
const request = new MeteroidRequest(
"POST",
"/api/v1/webhooks/deliveries/{delivery_id}/resend"
);

request.setPathParam("delivery_id", deliveryId);
return request.send(this.requestCtx, WebhookDeliverySerializer.parse, requestOptions);
}
}
226 changes: 226 additions & 0 deletions src/api/webhookEndpointsEndpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
// this file is @generated

import {
type CreateWebhookEndpointRequest,
CreateWebhookEndpointRequestSerializer,
} from "../models/createWebhookEndpointRequest.js";
import {
type CreatedWebhookEndpoint,
CreatedWebhookEndpointSerializer,
} from "../models/createdWebhookEndpoint.js";
import {
type UpdateWebhookEndpointRequest,
UpdateWebhookEndpointRequestSerializer,
} from "../models/updateWebhookEndpointRequest.js";
import type { WebhookDelivery } from "../models/webhookDelivery.js";
import {
type WebhookDeliveryListResponse,
WebhookDeliveryListResponseSerializer,
} from "../models/webhookDeliveryListResponse.js";
import type { WebhookDeliveryStatus } from "../models/webhookDeliveryStatus.js";
import {
type WebhookEndpoint,
WebhookEndpointSerializer,
} from "../models/webhookEndpoint.js";
import {
type WebhookEndpointListResponse,
WebhookEndpointListResponseSerializer,
} from "../models/webhookEndpointListResponse.js";
import {
type WebhookEndpointSecret,
WebhookEndpointSecretSerializer,
} from "../models/webhookEndpointSecret.js";
import type { APIPromise } from "../apiPromise.js";
import { PagePromise } from "../pagination.js";
import {
MeteroidRequest,
type MeteroidRequestContext,
type RequestOptions,
} from "../request.js";

/** The query and header parameters of `listDeliveries`. */
export interface WebhookEndpointsEndpointsListDeliveriesOptions {
/** Only return deliveries in this state. */
status?: WebhookDeliveryStatus | undefined;
/** Page number (0-indexed) */
page?: number | undefined;
/** Number of items per page */
perPage?: number | undefined;
}

/** The webhook endpoints endpoints operations, reached through the client's `webhookEndpoints.endpoints`. */
export class WebhookEndpointsEndpoints {
/** @internal */
public constructor(private readonly requestCtx: MeteroidRequestContext) {}

/** List webhook endpoints */
public list(requestOptions?: RequestOptions): APIPromise<WebhookEndpointListResponse> {
const request = new MeteroidRequest("GET", "/api/v1/webhooks/endpoints");

return request.send(
this.requestCtx,
WebhookEndpointListResponseSerializer.parse,
requestOptions
);
}

/**
* Create a webhook endpoint
*
* The signing secret is returned once, in this response only.
*/
public create(
createWebhookEndpointRequest: CreateWebhookEndpointRequest,
requestOptions?: RequestOptions
): APIPromise<CreatedWebhookEndpoint> {
const request = new MeteroidRequest("POST", "/api/v1/webhooks/endpoints");

request.setBody(
CreateWebhookEndpointRequestSerializer.serialize(createWebhookEndpointRequest)
);
return request.send(
this.requestCtx,
CreatedWebhookEndpointSerializer.parse,
requestOptions
);
}

/** Get a webhook endpoint */
public retrieve(
endpointId: string,
requestOptions?: RequestOptions
): APIPromise<WebhookEndpoint> {
const request = new MeteroidRequest(
"GET",
"/api/v1/webhooks/endpoints/{endpoint_id}"
);

request.setPathParam("endpoint_id", endpointId);
return request.send(this.requestCtx, WebhookEndpointSerializer.parse, requestOptions);
}

/**
* Delete a webhook endpoint
*
* The endpoint is archived and its pending deliveries are cancelled.
*/
public delete(endpointId: string, requestOptions?: RequestOptions): APIPromise<void> {
const request = new MeteroidRequest(
"DELETE",
"/api/v1/webhooks/endpoints/{endpoint_id}"
);

request.setPathParam("endpoint_id", endpointId);
return request.sendNoResponseBody(this.requestCtx, requestOptions);
}

/**
* Update a webhook endpoint
*
* Omitted fields are left untouched. Re-enabling a disabled endpoint resets its
* consecutive failure count.
*/
public update(
endpointId: string,
updateWebhookEndpointRequest: UpdateWebhookEndpointRequest,
requestOptions?: RequestOptions
): APIPromise<WebhookEndpoint> {
const request = new MeteroidRequest(
"PATCH",
"/api/v1/webhooks/endpoints/{endpoint_id}"
);

request.setPathParam("endpoint_id", endpointId);
request.setBody(
UpdateWebhookEndpointRequestSerializer.serialize(updateWebhookEndpointRequest)
);
return request.send(this.requestCtx, WebhookEndpointSerializer.parse, requestOptions);
}

/**
* List deliveries for a webhook endpoint
*
* Await it for the first page: the response body, its properties read on the page, with
* `items`, `hasNextPage()`, `getNextPage()` and `iterPages()`. Or iterate it with `for await`
* over every item of every page, fetched on demand.
*/
public listDeliveries(
endpointId: string,
options?: WebhookEndpointsEndpointsListDeliveriesOptions,
requestOptions?: RequestOptions
): PagePromise<WebhookDeliveryListResponse, WebhookDelivery> {
return new PagePromise<WebhookDeliveryListResponse, WebhookDelivery>(
{
style: "page",
items: (page) => page.data,
totalPages: (page) => page.paginationMeta?.totalPages,
firstPage: 0,
fetch: (page) =>
this.#listDeliveries(endpointId, { ...options, page: page }, requestOptions),
},
options?.page
);
}

#listDeliveries(
endpointId: string,
options?: WebhookEndpointsEndpointsListDeliveriesOptions,
requestOptions?: RequestOptions
): APIPromise<WebhookDeliveryListResponse> {
const request = new MeteroidRequest(
"GET",
"/api/v1/webhooks/endpoints/{endpoint_id}/deliveries"
);

request.setPathParam("endpoint_id", endpointId);
request.setQueryParam("status", options?.status);
request.setQueryParam("page", options?.page);
request.setQueryParam("per_page", options?.perPage);
return request.send(
this.requestCtx,
WebhookDeliveryListResponseSerializer.parse,
requestOptions
);
}

/**
* Rotate a webhook endpoint secret
*
* The previous secret keeps signing alongside the new one for 24 hours, so consumers
* can roll over without dropping events.
*/
public rotateSecret(
endpointId: string,
requestOptions?: RequestOptions
): APIPromise<WebhookEndpointSecret> {
const request = new MeteroidRequest(
"POST",
"/api/v1/webhooks/endpoints/{endpoint_id}/rotate-secret"
);

request.setPathParam("endpoint_id", endpointId);
return request.send(
this.requestCtx,
WebhookEndpointSecretSerializer.parse,
requestOptions
);
}

/** Reveal a webhook endpoint secret */
public retrieveSecret(
endpointId: string,
requestOptions?: RequestOptions
): APIPromise<WebhookEndpointSecret> {
const request = new MeteroidRequest(
"GET",
"/api/v1/webhooks/endpoints/{endpoint_id}/secret"
);

request.setPathParam("endpoint_id", endpointId);
return request.send(
this.requestCtx,
WebhookEndpointSecretSerializer.parse,
requestOptions
);
}
}
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ProductFamilies } from "./api/productFamilies.js";
import { Products } from "./api/products.js";
import { Subscriptions } from "./api/subscriptions.js";
import { Usage } from "./api/usage.js";
import { WebhookEndpoints } from "./api/webhookEndpoints.js";
import type { Security, SecurityScheme } from "./auth.js";
import type { Middleware } from "./middleware.js";
import { readEnv, type MeteroidRequestContext } from "./request.js";
Expand Down Expand Up @@ -115,6 +116,9 @@ export { Usage } from "./api/usage.js";
export type { UsageRetrieveCustomerOptions } from "./api/usage.js";
export type { UsageRetrieveSubscriptionOptions } from "./api/usage.js";
export type { UsageRetrieveSummaryOptions } from "./api/usage.js";
export { WebhookEndpoints } from "./api/webhookEndpoints.js";
export { WebhookEndpointsEndpoints } from "./api/webhookEndpointsEndpoints.js";
export type { WebhookEndpointsEndpointsListDeliveriesOptions } from "./api/webhookEndpointsEndpoints.js";

export type MeteroidOptions = {
/**
Expand Down Expand Up @@ -212,6 +216,7 @@ export class Meteroid {
private _products?: Products;
private _subscriptions?: Subscriptions;
private _usage?: Usage;
private _webhookEndpoints?: WebhookEndpoints;

/**
* Reads the API key from `METEROID_API_KEY` and the base URL from `METEROID_BASE_URL`
Expand Down Expand Up @@ -357,4 +362,10 @@ export class Meteroid {
this._usage ??= new Usage(this.requestCtx);
return this._usage;
}

/** The webhook endpoints API. */
public get webhookEndpoints(): WebhookEndpoints {
this._webhookEndpoints ??= new WebhookEndpoints(this.requestCtx);
return this._webhookEndpoints;
}
}
Loading