Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Jun 8, 2024
1 parent 861f35c commit 55303bb
Show file tree
Hide file tree
Showing 57 changed files with 1,330 additions and 810 deletions.
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 42
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/metronome%2Fmetronome-a0403cd987757a0e69e2bffb8a87a8cf4a848a8c35d35ed5eb34cf4649a9b5d0.yml
configured_endpoints: 48
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/metronome%2Fmetronome-05e51d588b47a6124e7af1cd591b6d1ec254edeba03c4fd499ac905d4687cb6d.yml
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ cd metronome-node
# With yarn
yarn link
cd ../my-package
yarn link metronome
yarn link @metronome/sdk

# With pnpm
pnpm link --global
cd ../my-package
pnpm link -—global metronome
pnpm link -—global @metronome/sdk
```

## Running tests
Expand Down
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Metronome Node API Library

[![NPM version](https://img.shields.io/npm/v/metronome.svg)](https://npmjs.org/package/metronome) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/metronome)
[![NPM version](https://img.shields.io/npm/v/@metronome/sdk.svg)](https://npmjs.org/package/@metronome/sdk) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@metronome/sdk)

This library provides convenient access to the Metronome REST API from server-side TypeScript or JavaScript.

Expand All @@ -11,7 +11,7 @@ It is generated with [Stainless](https://www.stainlessapi.com/).
## Installation

```sh
npm install metronome
npm install @metronome/sdk
```

## Usage
Expand All @@ -20,20 +20,23 @@ The full API of this library can be found in [api.md](api.md).

<!-- prettier-ignore -->
```js
import Metronome from 'metronome';
import Metronome from '@metronome/sdk';

const metronome = new Metronome({
bearerToken: process.env['METRONOME_BEARER_TOKEN'], // This is the default and can be omitted
});

async function main() {
const alertCreateResponse = await metronome.alerts.create({
alert_type: 'spend_threshold_reached',
name: '$100 spend threshold reached',
threshold: 10000,
const response = await metronome.usage.ingest({
usage: [
{
transaction_id: '2021-01-01T00:00:00Z_cluster42',
customer_id: '[email protected]',
event_type: 'heartbeat',
timestamp: '2021-01-01T00:00:00Z',
},
],
});

console.log(alertCreateResponse.data);
}

main();
Expand All @@ -45,7 +48,7 @@ This library includes TypeScript definitions for all request params and response

<!-- prettier-ignore -->
```ts
import Metronome from 'metronome';
import Metronome from '@metronome/sdk';

const metronome = new Metronome({
bearerToken: process.env['METRONOME_BEARER_TOKEN'], // This is the default and can be omitted
Expand Down Expand Up @@ -225,11 +228,11 @@ add the following import before your first import `from "Metronome"`:
```ts
// Tell TypeScript and the package to use the global web fetch instead of node-fetch.
// Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
import 'metronome/shims/web';
import Metronome from 'metronome';
import '@metronome/sdk/shims/web';
import Metronome from '@metronome/sdk';
```

To do the inverse, add `import "metronome/shims/node"` (which does import polyfills).
To do the inverse, add `import "@metronome/sdk/shims/node"` (which does import polyfills).
This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/Metronome-Industries/metronome-node/tree/main/src/_shims#readme)).

### Logging and middleware
Expand All @@ -239,7 +242,7 @@ which can be used to inspect or alter the `Request` or `Response` before/after e

```ts
import { fetch } from 'undici'; // as one example
import Metronome from 'metronome';
import Metronome from '@metronome/sdk';

const client = new Metronome({
fetch: async (url: RequestInfo, init?: RequestInit): Promise<Response> => {
Expand Down Expand Up @@ -298,7 +301,7 @@ TypeScript >= 4.5 is supported.
The following runtimes are supported:

- Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
- Deno v1.28.0 or higher, using `import Metronome from "npm:metronome"`.
- Deno v1.28.0 or higher, using `import Metronome from "npm:@metronome/sdk"`.
- Bun 1.0 or later.
- Cloudflare Workers.
- Vercel Edge Runtime.
Expand Down
95 changes: 60 additions & 35 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Types:

- <code><a href="./src/resources/shared.ts">Commit</a></code>
- <code><a href="./src/resources/shared.ts">ContractWithoutAmendments</a></code>
- <code><a href="./src/resources/shared.ts">CreditType</a></code>
- <code><a href="./src/resources/shared.ts">Discount</a></code>
- <code><a href="./src/resources/shared.ts">ID</a></code>
- <code><a href="./src/resources/shared.ts">Override</a></code>
Expand All @@ -23,20 +24,6 @@ Methods:
- <code title="post /alerts/create">client.alerts.<a href="./src/resources/alerts.ts">create</a>({ ...params }) -> AlertCreateResponse</code>
- <code title="post /alerts/archive">client.alerts.<a href="./src/resources/alerts.ts">archive</a>({ ...params }) -> AlertArchiveResponse</code>

# CustomerAlerts

Types:

- <code><a href="./src/resources/customer-alerts.ts">CustomerAlert</a></code>
- <code><a href="./src/resources/customer-alerts.ts">CustomerAlertRetrieveResponse</a></code>
- <code><a href="./src/resources/customer-alerts.ts">CustomerAlertListResponse</a></code>

Methods:

- <code title="post /customer-alerts/get">client.customerAlerts.<a href="./src/resources/customer-alerts.ts">retrieve</a>({ ...params }) -> CustomerAlertRetrieveResponse</code>
- <code title="post /customer-alerts/list">client.customerAlerts.<a href="./src/resources/customer-alerts.ts">list</a>({ ...params }) -> CustomerAlertListResponse</code>
- <code title="post /customer-alerts/reset">client.customerAlerts.<a href="./src/resources/customer-alerts.ts">reset</a>({ ...params }) -> void</code>

# Plans

Types:
Expand All @@ -54,33 +41,28 @@ Methods:
- <code title="get /planDetails/{plan_id}/charges">client.plans.<a href="./src/resources/plans.ts">listCharges</a>(planId, { ...params }) -> PlanListChargesResponse</code>
- <code title="get /planDetails/{plan_id}/customers">client.plans.<a href="./src/resources/plans.ts">listCustomers</a>(planId, { ...params }) -> PlanListCustomersResponse</code>

# Credits

Types:

- <code><a href="./src/resources/credits.ts">CreditCreateGrantResponse</a></code>
- <code><a href="./src/resources/credits.ts">CreditEditGrantResponse</a></code>
- <code><a href="./src/resources/credits.ts">CreditListEntriesResponse</a></code>
- <code><a href="./src/resources/credits.ts">CreditListGrantsResponse</a></code>
- <code><a href="./src/resources/credits.ts">CreditVoidGrantResponse</a></code>

Methods:

- <code title="post /credits/createGrant">client.credits.<a href="./src/resources/credits.ts">createGrant</a>({ ...params }) -> CreditCreateGrantResponse</code>
- <code title="post /credits/editGrant">client.credits.<a href="./src/resources/credits.ts">editGrant</a>({ ...params }) -> CreditEditGrantResponse</code>
- <code title="post /credits/listEntries">client.credits.<a href="./src/resources/credits.ts">listEntries</a>({ ...params }) -> CreditListEntriesResponse</code>
- <code title="post /credits/listGrants">client.credits.<a href="./src/resources/credits.ts">listGrants</a>({ ...params }) -> CreditListGrantsResponse</code>
- <code title="post /credits/voidGrant">client.credits.<a href="./src/resources/credits.ts">voidGrant</a>({ ...params }) -> CreditVoidGrantResponse</code>

# CreditTypes
# CreditGrants

Types:

- <code><a href="./src/resources/credit-types.ts">CreditTypeListResponse</a></code>
- <code><a href="./src/resources/credit-grants.ts">CreditLedgerEntry</a></code>
- <code><a href="./src/resources/credit-grants.ts">RolloverAmountMaxAmount</a></code>
- <code><a href="./src/resources/credit-grants.ts">RolloverAmountMaxPercentage</a></code>
- <code><a href="./src/resources/credit-grants.ts">CreditGrantCreateResponse</a></code>
- <code><a href="./src/resources/credit-grants.ts">CreditGrantListResponse</a></code>
- <code><a href="./src/resources/credit-grants.ts">CreditGrantEditResponse</a></code>
- <code><a href="./src/resources/credit-grants.ts">CreditGrantListCreditTypesResponse</a></code>
- <code><a href="./src/resources/credit-grants.ts">CreditGrantListEntriesResponse</a></code>
- <code><a href="./src/resources/credit-grants.ts">CreditGrantVoidResponse</a></code>

Methods:

- <code title="get /credit-types/list">client.creditTypes.<a href="./src/resources/credit-types.ts">list</a>({ ...params }) -> CreditTypeListResponse</code>
- <code title="post /credits/createGrant">client.creditGrants.<a href="./src/resources/credit-grants.ts">create</a>({ ...params }) -> CreditGrantCreateResponse</code>
- <code title="post /credits/listGrants">client.creditGrants.<a href="./src/resources/credit-grants.ts">list</a>({ ...params }) -> CreditGrantListResponse</code>
- <code title="post /credits/editGrant">client.creditGrants.<a href="./src/resources/credit-grants.ts">edit</a>({ ...params }) -> CreditGrantEditResponse</code>
- <code title="get /credit-types/list">client.creditGrants.<a href="./src/resources/credit-grants.ts">listCreditTypes</a>({ ...params }) -> CreditGrantListCreditTypesResponse</code>
- <code title="post /credits/listEntries">client.creditGrants.<a href="./src/resources/credit-grants.ts">listEntries</a>({ ...params }) -> CreditGrantListEntriesResponse</code>
- <code title="post /credits/voidGrant">client.creditGrants.<a href="./src/resources/credit-grants.ts">void</a>({ ...params }) -> CreditGrantVoidResponse</code>

# Customers

Expand Down Expand Up @@ -108,6 +90,20 @@ Methods:
- <code title="post /customers/{customer_id}/setName">client.customers.<a href="./src/resources/customers/customers.ts">setName</a>(customerId, { ...params }) -> CustomerSetNameResponse</code>
- <code title="post /customers/{customer_id}/updateConfig">client.customers.<a href="./src/resources/customers/customers.ts">updateConfig</a>(customerId, { ...params }) -> void</code>

## Alerts

Types:

- <code><a href="./src/resources/customers/alerts.ts">CustomerAlert</a></code>
- <code><a href="./src/resources/customers/alerts.ts">AlertRetrieveResponse</a></code>
- <code><a href="./src/resources/customers/alerts.ts">AlertListResponse</a></code>

Methods:

- <code title="post /customer-alerts/get">client.customers.alerts.<a href="./src/resources/customers/alerts.ts">retrieve</a>({ ...params }) -> AlertRetrieveResponse</code>
- <code title="post /customer-alerts/list">client.customers.alerts.<a href="./src/resources/customers/alerts.ts">list</a>({ ...params }) -> AlertListResponse</code>
- <code title="post /customer-alerts/reset">client.customers.alerts.<a href="./src/resources/customers/alerts.ts">reset</a>({ ...params }) -> void</code>

## Plans

Types:
Expand All @@ -131,11 +127,13 @@ Types:
- <code><a href="./src/resources/customers/invoices.ts">Invoice</a></code>
- <code><a href="./src/resources/customers/invoices.ts">InvoiceRetrieveResponse</a></code>
- <code><a href="./src/resources/customers/invoices.ts">InvoiceListResponse</a></code>
- <code><a href="./src/resources/customers/invoices.ts">InvoiceAddChargeResponse</a></code>

Methods:

- <code title="get /customers/{customer_id}/invoices/{invoice_id}">client.customers.invoices.<a href="./src/resources/customers/invoices.ts">retrieve</a>(customerId, invoiceId, { ...params }) -> InvoiceRetrieveResponse</code>
- <code title="get /customers/{customer_id}/invoices">client.customers.invoices.<a href="./src/resources/customers/invoices.ts">list</a>(customerId, { ...params }) -> InvoiceListResponse</code>
- <code title="post /customers/{customer_id}/addCharge">client.customers.invoices.<a href="./src/resources/customers/invoices.ts">addCharge</a>(customerId, { ...params }) -> InvoiceAddChargeResponse</code>

## BillingConfig

Expand Down Expand Up @@ -176,6 +174,7 @@ Types:
Methods:

- <code title="post /usage">client.usage.<a href="./src/resources/usage.ts">list</a>({ ...params }) -> UsageListResponse</code>
- <code title="post /ingest">client.usage.<a href="./src/resources/usage.ts">ingest</a>([ ...usage ]) -> void</code>
- <code title="post /usage/groups">client.usage.<a href="./src/resources/usage.ts">listWithGroups</a>({ ...params }) -> UsageListWithGroupsResponse</code>

# AuditLogs
Expand All @@ -201,3 +200,29 @@ Methods:
- <code title="post /customFields/listKeys">client.customFields.<a href="./src/resources/custom-fields.ts">listKeys</a>({ ...params }) -> CustomFieldListKeysResponse</code>
- <code title="post /customFields/removeKey">client.customFields.<a href="./src/resources/custom-fields.ts">removeKey</a>({ ...params }) -> void</code>
- <code title="post /customFields/setValues">client.customFields.<a href="./src/resources/custom-fields.ts">setValues</a>({ ...params }) -> void</code>

# BillableMetrics

Types:

- <code><a href="./src/resources/billable-metrics.ts">BillableMetricCreateResponse</a></code>
- <code><a href="./src/resources/billable-metrics.ts">BillableMetricRetrieveResponse</a></code>
- <code><a href="./src/resources/billable-metrics.ts">BillableMetricListResponse</a></code>
- <code><a href="./src/resources/billable-metrics.ts">BillableMetricArchiveResponse</a></code>

Methods:

- <code title="post /billable-metrics/create">client.billableMetrics.<a href="./src/resources/billable-metrics.ts">create</a>({ ...params }) -> BillableMetricCreateResponse</code>
- <code title="get /billable-metrics/{billable_metric_id}">client.billableMetrics.<a href="./src/resources/billable-metrics.ts">retrieve</a>(billableMetricId) -> BillableMetricRetrieveResponse</code>
- <code title="get /customers/{customer_id}/billable-metrics">client.billableMetrics.<a href="./src/resources/billable-metrics.ts">list</a>(customerId, { ...params }) -> BillableMetricListResponse</code>
- <code title="post /billable-metrics/archive">client.billableMetrics.<a href="./src/resources/billable-metrics.ts">archive</a>({ ...params }) -> BillableMetricArchiveResponse</code>

# Services

Types:

- <code><a href="./src/resources/services.ts">ServiceListResponse</a></code>

Methods:

- <code title="get /services">client.services.<a href="./src/resources/services.ts">list</a>() -> ServiceListResponse</code>
6 changes: 3 additions & 3 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const config: JestConfigWithTsJest = {
'^.+\\.(t|j)sx?$': ['@swc/jest', { sourceMaps: 'inline' }],
},
moduleNameMapper: {
'^metronome$': '<rootDir>/src/index.ts',
'^metronome/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
'^metronome/(.*)$': '<rootDir>/src/$1',
'^@metronome/sdk$': '<rootDir>/src/index.ts',
'^@metronome/sdk/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
'^@metronome/sdk/(.*)$': '<rootDir>/src/$1',
},
modulePathIgnorePatterns: [
'<rootDir>/ecosystem-tests/',
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "metronome",
"name": "@metronome/sdk",
"version": "0.0.1",
"description": "The official TypeScript library for the Metronome API",
"author": "Metronome <[email protected]>",
Expand Down Expand Up @@ -62,8 +62,8 @@
"./shims/web.mjs"
],
"imports": {
"metronome": ".",
"metronome/*": "./src/*"
"@metronome/sdk": ".",
"@metronome/sdk/*": "./src/*"
},
"exports": {
"./_shims/auto/*": {
Expand Down
6 changes: 3 additions & 3 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ node scripts/utils/check-version.cjs

# Build into dist and will publish the package from there,
# so that src/resources/foo.ts becomes <package root>/resources/foo.js
# This way importing from `"metronome/resources/foo"` works
# This way importing from `"@metronome/sdk/resources/foo"` works
# even with `"moduleResolution": "node"`

rm -rf dist; mkdir dist
Expand Down Expand Up @@ -47,8 +47,8 @@ node scripts/utils/postprocess-files.cjs

# make sure that nothing crashes when we require the output CJS or
# import the output ESM
(cd dist && node -e 'require("metronome")')
(cd dist && node -e 'import("metronome")' --input-type=module)
(cd dist && node -e 'require("@metronome/sdk")')
(cd dist && node -e 'import("@metronome/sdk")' --input-type=module)

if command -v deno &> /dev/null && [ -e ./scripts/build-deno ]
then
Expand Down
4 changes: 2 additions & 2 deletions scripts/utils/postprocess-files.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const fs = require('fs');
const path = require('path');
const { parse } = require('@typescript-eslint/parser');

const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'metronome/';
const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? '@metronome/sdk/';

const distDir =
process.env['DIST_PATH'] ?
Expand Down Expand Up @@ -142,7 +142,7 @@ async function postprocess() {

if (file.endsWith('.d.ts')) {
// work around bad tsc behavior
// if we have `import { type Readable } from 'metronome/_shims/index'`,
// if we have `import { type Readable } from '@metronome/sdk/_shims/index'`,
// tsc sometimes replaces `Readable` with `import("stream").Readable` inline
// in the output .d.ts
transformed = transformed.replace(/import\("stream"\).Readable/g, 'Readable');
Expand Down
Loading

0 comments on commit 55303bb

Please sign in to comment.