Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): manual updates #138

Merged
merged 1 commit into from
Feb 16, 2025
Merged
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
81 changes: 63 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ const client = new Terminal({
});

async function main() {
const product: Terminal.ProductListResponse = await client.product.list();
const params: Terminal.SubscriptionCreateParams = {
id: 'sub_XXXXXXXXXXXXXXXXXXXXXXXXX',
addressID: 'shp_XXXXXXXXXXXXXXXXXXXXXXXXX',
cardID: 'crd_XXXXXXXXXXXXXXXXXXXXXXXXX',
frequency: 'fixed',
productVariantID: 'var_XXXXXXXXXXXXXXXXXXXXXXXXX',
quantity: 1,
};
const subscription: Terminal.SubscriptionCreateResponse = await client.subscription.create(params);
}

main();
Expand All @@ -67,15 +75,24 @@ a subclass of `APIError` will be thrown:
<!-- prettier-ignore -->
```ts
async function main() {
const product = await client.product.list().catch(async (err) => {
if (err instanceof Terminal.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
} else {
throw err;
}
});
const subscription = await client.subscription
.create({
id: 'sub_XXXXXXXXXXXXXXXXXXXXXXXXX',
addressID: 'shp_XXXXXXXXXXXXXXXXXXXXXXXXX',
cardID: 'crd_XXXXXXXXXXXXXXXXXXXXXXXXX',
frequency: 'fixed',
productVariantID: 'var_XXXXXXXXXXXXXXXXXXXXXXXXX',
quantity: 1,
})
.catch(async (err) => {
if (err instanceof Terminal.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
} else {
throw err;
}
});
}

main();
Expand Down Expand Up @@ -110,7 +127,7 @@ const client = new Terminal({
});

// Or, configure per-request:
await client.product.list({
await client.subscription.create({ id: 'sub_XXXXXXXXXXXXXXXXXXXXXXXXX', addressID: 'shp_XXXXXXXXXXXXXXXXXXXXXXXXX', cardID: 'crd_XXXXXXXXXXXXXXXXXXXXXXXXX', frequency: 'fixed', productVariantID: 'var_XXXXXXXXXXXXXXXXXXXXXXXXX', quantity: 1 }, {
maxRetries: 5,
});
```
Expand All @@ -127,7 +144,7 @@ const client = new Terminal({
});

// Override per-request:
await client.product.list({
await client.subscription.create({ id: 'sub_XXXXXXXXXXXXXXXXXXXXXXXXX', addressID: 'shp_XXXXXXXXXXXXXXXXXXXXXXXXX', cardID: 'crd_XXXXXXXXXXXXXXXXXXXXXXXXX', frequency: 'fixed', productVariantID: 'var_XXXXXXXXXXXXXXXXXXXXXXXXX', quantity: 1 }, {
timeout: 5 * 1000,
});
```
Expand All @@ -148,13 +165,31 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi
```ts
const client = new Terminal();

const response = await client.product.list().asResponse();
const response = await client.subscription
.create({
id: 'sub_XXXXXXXXXXXXXXXXXXXXXXXXX',
addressID: 'shp_XXXXXXXXXXXXXXXXXXXXXXXXX',
cardID: 'crd_XXXXXXXXXXXXXXXXXXXXXXXXX',
frequency: 'fixed',
productVariantID: 'var_XXXXXXXXXXXXXXXXXXXXXXXXX',
quantity: 1,
})
.asResponse();
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object

const { data: product, response: raw } = await client.product.list().withResponse();
const { data: subscription, response: raw } = await client.subscription
.create({
id: 'sub_XXXXXXXXXXXXXXXXXXXXXXXXX',
addressID: 'shp_XXXXXXXXXXXXXXXXXXXXXXXXX',
cardID: 'crd_XXXXXXXXXXXXXXXXXXXXXXXXX',
frequency: 'fixed',
productVariantID: 'var_XXXXXXXXXXXXXXXXXXXXXXXXX',
quantity: 1,
})
.withResponse();
console.log(raw.headers.get('X-My-Header'));
console.log(product.data);
console.log(subscription.data);
```

### Making custom/undocumented requests
Expand Down Expand Up @@ -258,9 +293,19 @@ const client = new Terminal({
});

// Override per-request:
await client.product.list({
httpAgent: new http.Agent({ keepAlive: false }),
});
await client.subscription.create(
{
id: 'sub_XXXXXXXXXXXXXXXXXXXXXXXXX',
addressID: 'shp_XXXXXXXXXXXXXXXXXXXXXXXXX',
cardID: 'crd_XXXXXXXXXXXXXXXXXXXXXXXXX',
frequency: 'fixed',
productVariantID: 'var_XXXXXXXXXXXXXXXXXXXXXXXXX',
quantity: 1,
},
{
httpAgent: new http.Agent({ keepAlive: false }),
},
);
```

## Semantic versioning
Expand Down