Skip to content

Commit 6cc3e7f

Browse files
committed
Release 0.0.244
1 parent e8be629 commit 6cc3e7f

File tree

452 files changed

+9087
-3664
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

452 files changed

+9087
-3664
lines changed

README.md

Lines changed: 133 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,144 @@
11
# Beehiiv TypeScript Library
22

3-
[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-SDK%20generated%20by%20Fern-brightgreen)](https://buildwithfern.com/)
4-
[![npm shield](https://img.shields.io/npm/v/beehiiv)](https://www.npmjs.com/package/beehiiv)
3+
[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fbeehiiv%2Ftypescript-sdk)
4+
[![npm shield](https://img.shields.io/npm/v/@beehiiv/sdk)](https://www.npmjs.com/package/@beehiiv/sdk)
55

6-
The Beehiiv TypeScript library provides convenient access to the Beehiiv Public API from JavaScript/TypeScript.
6+
The Beehiiv TypeScript library provides convenient access to the Beehiiv API from TypeScript.
77

88
## Documentation
99

1010
API reference documentation is available [here](https://developers.beehiiv.com/docs/v2/o3elujhmkik1d-beehiiv-api).
1111

12-
## Reference
13-
14-
A full reference of the SDK is available [here](./reference.md).
15-
1612
## Installation
1713

18-
```bash
19-
npm install --save beehiiv
20-
# or
21-
yarn add beehiiv
14+
```sh
15+
npm i -s @beehiiv/sdk
2216
```
2317

24-
In Deno (1.25+) you can import by doing:
18+
## Reference
2519

26-
```ts
27-
import { Beehiv } from "npm:beehiv";
28-
```
20+
A full reference for this library is available [here](./reference.md).
2921

3022
## Usage
3123

32-
```typescript
33-
import { BeehiivClient, Beehiiv } from 'beehiiv';
24+
Instantiate and use the client with the following:
3425

35-
const beehiiv = new BeehiivClient({
36-
token: "token...", // Defaults to process.env.BEEHIIV_API_KEY
37-
});
26+
```typescript
27+
import { BeehiivClient } from "@beehiiv/sdk";
3828

39-
const response = await beehiiv.subscriptions.create(
40-
"pub_11c6387f-1d31-40c7-85ee-4a2da0c63001",
29+
const client = new BeehiivClient({ token: "YOUR_TOKEN" });
30+
await client.automationJourneys.create(
31+
"pub_00000000-0000-0000-0000-000000000000",
32+
"aut_00000000-0000-0000-0000-000000000000",
4133
{
42-
email: "...@email.com",
43-
},
34+
email: "test@example.com",
35+
doubleOptOverride: "on",
36+
}
4437
);
4538
```
4639

47-
## Request and Response Types
40+
## Request And Response Types
4841

49-
The SDK exports all request and response types as TypeScript interfaces. Simply
50-
import them under the `Beehiiv` namespace:
42+
The SDK exports all request and response types as TypeScript interfaces. Simply import them with the
43+
following namespace:
5144

52-
```ts
53-
import { Beehiiv } from "beehiiv";
45+
```typescript
46+
import { Beehiiv } from "@beehiiv/sdk";
5447

55-
const publication: Beehiiv.Publication = {
56-
id: "pub_...",
57-
name: "Some publication",
58-
referralProgramEnabled: true,
59-
created: 1713226240
48+
const request: Beehiiv.AutomationJourneysCreateRequest = {
49+
...
6050
};
6151
```
6252

6353
## Exception Handling
6454

65-
When the API returns a non-success status code (4xx or 5xx response),
66-
a subclass of [BeehiivError](./src/errors/BeehiivError.ts) will be thrown:
55+
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
56+
will be thrown.
6757

68-
```ts
69-
import { BeehiivError } from 'beehiiv';
58+
```typescript
59+
import { BeehiivError } from "@beehiiv/sdk";
7060

7161
try {
72-
await beehiiv.subscriptions.create(
73-
"pub_11c6387f-1d31-40c7-85ee-4a2da0c63001",
74-
{
75-
email: "...@email.com",
76-
},
77-
);
62+
await client.automationJourneys.create(...);
7863
} catch (err) {
79-
if (err instanceof BeehiivError) {
80-
console.log(err.statusCode);
81-
console.log(err.message);
82-
console.log(err.body);
83-
}
64+
if (err instanceof BeehiivError) {
65+
console.log(err.statusCode);
66+
console.log(err.message);
67+
console.log(err.body);
68+
}
8469
}
8570
```
8671

72+
## Advanced
73+
74+
### Retries
75+
76+
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
77+
as the request is deemed retriable and the number of retry attempts has not grown larger than the configured
78+
retry limit (default: 2).
79+
80+
A request is deemed retriable when any of the following HTTP status codes is returned:
81+
82+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
83+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
84+
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
85+
86+
Use the `maxRetries` request option to configure this behavior.
87+
88+
```typescript
89+
const response = await client.automationJourneys.create(..., {
90+
maxRetries: 0 // override maxRetries at the request level
91+
});
92+
```
93+
94+
### Timeouts
95+
96+
The SDK defaults to a 60 second timeout. Use the `timeoutInSeconds` option to configure this behavior.
97+
98+
```typescript
99+
const response = await client.automationJourneys.create(..., {
100+
timeoutInSeconds: 30 // override timeout to 30s
101+
});
102+
```
103+
104+
### Aborting Requests
105+
106+
The SDK allows users to abort requests at any point by passing in an abort signal.
107+
108+
```typescript
109+
const controller = new AbortController();
110+
const response = await client.automationJourneys.create(..., {
111+
abortSignal: controller.signal
112+
});
113+
controller.abort(); // aborts the request
114+
```
115+
116+
### Runtime Compatibility
117+
118+
The SDK defaults to `node-fetch` but will use the global fetch client if present. The SDK works in the following
119+
runtimes:
120+
121+
- Node.js 18+
122+
- Vercel
123+
- Cloudflare Workers
124+
- Deno v1.25+
125+
- Bun 1.0+
126+
- React Native
127+
128+
### Customizing Fetch Client
129+
130+
The SDK provides a way for your to customize the underlying HTTP client / Fetch function. If you're running in an
131+
unsupported environment, this provides a way for you to break glass and ensure the SDK works.
132+
133+
```typescript
134+
import { BeehiivClient } from "@beehiiv/sdk";
135+
136+
const client = new BeehiivClient({
137+
...
138+
fetcher: // provide your implementation here
139+
});
140+
```
141+
87142
## Retries
88143

89144
The TypeScript SDK is instrumented with automatic retries with exponential backoff. A request will be
@@ -92,12 +147,12 @@ than the configured retry limit (default: 2).
92147

93148
A request is deemed retriable when any of the following HTTP status codes is returned:
94149

95-
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
96-
- [409](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409) (Conflict)
97-
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
98-
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
99-
100-
Use the `maxRetries` request option to configure this behavior.
150+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
151+
- [409](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409) (Conflict)
152+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
153+
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
154+
155+
Use the `maxRetries` request option to configure this behavior.
101156

102157
```ts
103158
const response = await beehiiv.subscriptions.create(..., {
@@ -107,8 +162,8 @@ const response = await beehiiv.subscriptions.create(..., {
107162

108163
## Timeouts
109164

110-
The SDK defaults to a 60 second timout. Use the `timeoutInSeconds` option to
111-
configure this behavior.
165+
The SDK defaults to a 60 second timout. Use the `timeoutInSeconds` option to
166+
configure this behavior.
112167

113168
```ts
114169
const response = await beehiiv.subscriptions.create(..., {
@@ -118,23 +173,23 @@ const response = await beehiiv.subscriptions.create(..., {
118173

119174
## Runtime compatiblity
120175

121-
The SDK defaults to `node-fetch` but will use the global fetch client if present. The SDK
122-
works in the following runtimes:
176+
The SDK defaults to `node-fetch` but will use the global fetch client if present. The SDK
177+
works in the following runtimes:
123178

124179
The following runtimes are supported:
125180

126-
- Node.js 15+
127-
- Vercel
128-
- Cloudflare Workers
129-
- Deno v1.25+
130-
- Bun 1.0+
131-
- React Native
181+
- Node.js 15+
182+
- Vercel
183+
- Cloudflare Workers
184+
- Deno v1.25+
185+
- Bun 1.0+
186+
- React Native
132187

133188
### Customizing Fetch client
134189

135-
The SDK provides a way for you to customize the underlying HTTP client / Fetch function. If you're
136-
running in an unsupported environment, this provides a way for you to break the glass and
137-
ensure the SDK works.
190+
The SDK provides a way for you to customize the underlying HTTP client / Fetch function. If you're
191+
running in an unsupported environment, this provides a way for you to break the glass and
192+
ensure the SDK works.
138193

139194
```ts
140195
import { BeehiivClient } from 'beehiiv';
@@ -147,14 +202,17 @@ const beehiiv = new BeehiivClient({
147202

148203
## Beta status
149204

150-
This SDK is in beta, and there may be breaking changes between versions without a major version update.
151-
Therefore, we recommend pinning the package version to a specific version in your package.json file.
152-
This way, you can install the same version each time without breaking changes unless you are
205+
This SDK is in beta, and there may be breaking changes between versions without a major version update.
206+
Therefore, we recommend pinning the package version to a specific version in your package.json file.
207+
This way, you can install the same version each time without breaking changes unless you are
153208
intentionally looking for the latest version.
154209

155210
## Contributing
156211

157-
While we value open-source contributions to this SDK, this library is generated programmatically.
158-
Additions made directly to this library would have to be moved over to our generation code,
159-
otherwise they would be overwritten upon the next generated release. Feel free to open a
160-
PR as a proof of concept, but know that we will not be able to merge it as-is.
212+
While we value open-source contributions to this SDK, this library is generated programmatically.
213+
Additions made directly to this library would have to be moved over to our generation code,
214+
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
215+
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
216+
an issue first to discuss with us!
217+
218+
On the other hand, contributions to the README are always very welcome!

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "beehiiv",
3-
"version": "0.1.3",
2+
"name": "@beehiiv/sdk",
3+
"version": "0.0.244",
44
"private": false,
55
"repository": "https://github.com/beehiiv/typescript-sdk",
66
"main": "./index.js",
@@ -17,12 +17,17 @@
1717
"formdata-node": "^6.0.3",
1818
"node-fetch": "2.7.0",
1919
"qs": "6.11.2",
20+
"readable-stream": "^4.5.2",
2021
"js-base64": "3.7.2"
2122
},
2223
"devDependencies": {
2324
"@types/url-join": "4.0.1",
2425
"@types/qs": "6.9.8",
2526
"@types/node-fetch": "2.6.9",
27+
"@types/readable-stream": "^4.0.15",
28+
"fetch-mock-jest": "^1.5.1",
29+
"webpack": "^5.94.0",
30+
"ts-loader": "^9.3.1",
2631
"jest": "29.7.0",
2732
"@types/jest": "29.5.5",
2833
"ts-jest": "29.1.1",

0 commit comments

Comments
 (0)