Skip to content

Commit 78aa3f8

Browse files
committed
Release 0.1.7
1 parent c2972a9 commit 78aa3f8

File tree

768 files changed

+11470
-15258
lines changed

Some content is hidden

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

768 files changed

+11470
-15258
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
steps:
1010
- name: Checkout repo
11-
uses: actions/checkout@v3
11+
uses: actions/checkout@v4
1212

1313
- name: Set up node
1414
uses: actions/setup-node@v3
@@ -21,7 +21,7 @@ jobs:
2121

2222
steps:
2323
- name: Checkout repo
24-
uses: actions/checkout@v3
24+
uses: actions/checkout@v4
2525

2626
- name: Set up node
2727
uses: actions/setup-node@v3
@@ -35,7 +35,7 @@ jobs:
3535
runs-on: ubuntu-latest
3636
steps:
3737
- name: Checkout repo
38-
uses: actions/checkout@v3
38+
uses: actions/checkout@v4
3939
- name: Set up node
4040
uses: actions/setup-node@v3
4141
- name: Install dependencies

README.md

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ npm i -s @beehiiv/sdk
1717

1818
## Reference
1919

20-
A full reference for this library is available [here](./reference.md).
20+
A full reference for this library is available [here](https://github.com/beehiiv/typescript-sdk/blob/HEAD/./reference.md).
2121

2222
## Usage
2323

@@ -32,8 +32,8 @@ await client.automationJourneys.create(
3232
"aut_00000000-0000-0000-0000-000000000000",
3333
{
3434
35-
doubleOptOverride: "on",
36-
}
35+
double_opt_override: "on",
36+
},
3737
);
3838
```
3939

@@ -65,23 +65,36 @@ try {
6565
console.log(err.statusCode);
6666
console.log(err.message);
6767
console.log(err.body);
68+
console.log(err.rawResponse);
6869
}
6970
}
7071
```
7172

7273
## Advanced
7374

75+
### Additional Headers
76+
77+
If you would like to send additional headers as part of the request, use the `headers` request option.
78+
79+
```typescript
80+
const response = await client.automationJourneys.create(..., {
81+
headers: {
82+
'X-Custom-Header': 'custom value'
83+
}
84+
});
85+
```
86+
7487
### Retries
7588

7689
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
90+
as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
7891
retry limit (default: 2).
7992

80-
A request is deemed retriable when any of the following HTTP status codes is returned:
93+
A request is deemed retryable when any of the following HTTP status codes is returned:
8194

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)
95+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
96+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
97+
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
8598

8699
Use the `maxRetries` request option to configure this behavior.
87100

@@ -113,21 +126,33 @@ const response = await client.automationJourneys.create(..., {
113126
controller.abort(); // aborts the request
114127
```
115128

129+
### Access Raw Response Data
130+
131+
The SDK provides access to raw response data, including headers, through the `.withRawResponse()` method.
132+
The `.withRawResponse()` method returns a promise that results to an object with a `data` and a `rawResponse` property.
133+
134+
```typescript
135+
const { data, rawResponse } = await client.automationJourneys.create(...).withRawResponse();
136+
137+
console.log(data);
138+
console.log(rawResponse.headers['X-My-Header']);
139+
```
140+
116141
### Runtime Compatibility
117142

118143
The SDK defaults to `node-fetch` but will use the global fetch client if present. The SDK works in the following
119144
runtimes:
120145

121-
- Node.js 18+
122-
- Vercel
123-
- Cloudflare Workers
124-
- Deno v1.25+
125-
- Bun 1.0+
126-
- React Native
146+
- Node.js 18+
147+
- Vercel
148+
- Cloudflare Workers
149+
- Deno v1.25+
150+
- Bun 1.0+
151+
- React Native
127152

128153
### Customizing Fetch Client
129154

130-
The SDK provides a way for your to customize the underlying HTTP client / Fetch function. If you're running in an
155+
The SDK provides a way for you to customize the underlying HTTP client / Fetch function. If you're running in an
131156
unsupported environment, this provides a way for you to break glass and ensure the SDK works.
132157

133158
```typescript
@@ -147,10 +172,10 @@ than the configured retry limit (default: 2).
147172

148173
A request is deemed retriable when any of the following HTTP status codes is returned:
149174

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)
175+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
176+
- [409](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409) (Conflict)
177+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
178+
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
154179

155180
Use the `maxRetries` request option to configure this behavior.
156181

@@ -178,12 +203,12 @@ works in the following runtimes:
178203

179204
The following runtimes are supported:
180205

181-
- Node.js 15+
182-
- Vercel
183-
- Cloudflare Workers
184-
- Deno v1.25+
185-
- Bun 1.0+
186-
- React Native
206+
- Node.js 15+
207+
- Vercel
208+
- Cloudflare Workers
209+
- Deno v1.25+
210+
- Bun 1.0+
211+
- React Native
187212

188213
### Customizing Fetch client
189214

jest.config.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

jest.config.mjs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/** @type {import('jest').Config} */
2+
export default {
3+
preset: "ts-jest",
4+
testEnvironment: "node",
5+
projects: [
6+
{
7+
displayName: "unit",
8+
preset: "ts-jest",
9+
testEnvironment: "node",
10+
moduleNameMapper: {
11+
"^(\.{1,2}/.*)\.js$": "$1",
12+
},
13+
roots: ["<rootDir>/tests"],
14+
testPathIgnorePatterns: ["\.browser\.(spec|test)\.[jt]sx?$", "/tests/wire/"],
15+
setupFilesAfterEnv: [],
16+
},
17+
{
18+
displayName: "browser",
19+
preset: "ts-jest",
20+
testEnvironment: "<rootDir>/tests/BrowserTestEnvironment.ts",
21+
moduleNameMapper: {
22+
"^(\.{1,2}/.*)\.js$": "$1",
23+
},
24+
roots: ["<rootDir>/tests"],
25+
testMatch: ["<rootDir>/tests/unit/**/?(*.)+(browser).(spec|test).[jt]s?(x)"],
26+
setupFilesAfterEnv: [],
27+
},
28+
,
29+
{
30+
displayName: "wire",
31+
preset: "ts-jest",
32+
testEnvironment: "node",
33+
moduleNameMapper: {
34+
"^(\.{1,2}/.*)\.js$": "$1",
35+
},
36+
roots: ["<rootDir>/tests/wire"],
37+
setupFilesAfterEnv: ["<rootDir>/tests/mock-server/setup.ts"],
38+
},
39+
],
40+
workerThreads: false,
41+
passWithNoTests: true,
42+
};

package.json

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,65 @@
11
{
22
"name": "@beehiiv/sdk",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"private": false,
5-
"repository": "https://github.com/beehiiv/typescript-sdk",
6-
"main": "./index.js",
7-
"types": "./index.d.ts",
5+
"repository": "github:beehiiv/typescript-sdk",
6+
"type": "commonjs",
7+
"main": "./dist/cjs/index.js",
8+
"module": "./dist/esm/index.mjs",
9+
"types": "./dist/cjs/index.d.ts",
10+
"exports": {
11+
".": {
12+
"types": "./dist/cjs/index.d.ts",
13+
"import": {
14+
"types": "./dist/esm/index.d.mts",
15+
"default": "./dist/esm/index.mjs"
16+
},
17+
"require": {
18+
"types": "./dist/cjs/index.d.ts",
19+
"default": "./dist/cjs/index.js"
20+
},
21+
"default": "./dist/cjs/index.js"
22+
},
23+
"./package.json": "./package.json"
24+
},
25+
"files": [
26+
"dist",
27+
"reference.md",
28+
"README.md",
29+
"LICENSE"
30+
],
831
"scripts": {
932
"format": "prettier . --write --ignore-unknown",
10-
"build": "tsc",
11-
"prepack": "cp -rv dist/. .",
12-
"test": "jest"
13-
},
14-
"dependencies": {
15-
"url-join": "4.0.1",
16-
"form-data": "^4.0.0",
17-
"formdata-node": "^6.0.3",
18-
"node-fetch": "2.7.0",
19-
"qs": "6.11.2",
20-
"readable-stream": "^4.5.2",
21-
"js-base64": "3.7.2"
33+
"build": "yarn build:cjs && yarn build:esm",
34+
"build:cjs": "tsc --project ./tsconfig.cjs.json",
35+
"build:esm": "tsc --project ./tsconfig.esm.json && node scripts/rename-to-esm-files.js dist/esm",
36+
"test": "jest --config jest.config.mjs",
37+
"test:unit": "jest --selectProjects unit",
38+
"test:browser": "jest --selectProjects browser",
39+
"test:wire": "jest --selectProjects wire"
2240
},
2341
"devDependencies": {
24-
"@types/url-join": "4.0.1",
25-
"@types/qs": "6.9.8",
26-
"@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",
31-
"jest": "29.7.0",
32-
"@types/jest": "29.5.5",
33-
"ts-jest": "29.1.1",
34-
"jest-environment-jsdom": "29.7.0",
35-
"@types/node": "17.0.33",
36-
"prettier": "2.7.1",
37-
"typescript": "4.6.4"
42+
"webpack": "^5.97.1",
43+
"ts-loader": "^9.5.1",
44+
"jest": "^29.7.0",
45+
"@jest/globals": "^29.7.0",
46+
"@types/jest": "^29.5.14",
47+
"ts-jest": "^29.3.4",
48+
"jest-environment-jsdom": "^29.7.0",
49+
"msw": "^2.8.4",
50+
"@types/node": "^18.19.70",
51+
"prettier": "^3.4.2",
52+
"typescript": "~5.7.2"
3853
},
3954
"browser": {
4055
"fs": false,
4156
"os": false,
42-
"path": false
43-
}
57+
"path": false,
58+
"stream": false
59+
},
60+
"packageManager": "[email protected]",
61+
"engines": {
62+
"node": ">=18.0.0"
63+
},
64+
"sideEffects": false
4465
}

0 commit comments

Comments
 (0)