Skip to content

Commit 9f29682

Browse files
committed
Release 6.0.62
1 parent 42981e5 commit 9f29682

File tree

60 files changed

+1248
-766
lines changed

Some content is hidden

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

60 files changed

+1248
-766
lines changed

README.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ A full reference for this library is available [here](./reference.md).
3939
Instantiate and use the client with the following:
4040

4141
```typescript
42-
import { AboundClient, Abound } from "@withabound/node-sdk";
42+
import { AboundClient } from "@withabound/node-sdk";
4343

4444
const client = new AboundClient({ apiKey: "YOUR_API_KEY" });
4545
await client.form1099Nec.create({
@@ -117,17 +117,29 @@ try {
117117

118118
## Advanced
119119

120+
### Additional Headers
121+
122+
If you would like to send additional headers as part of the request, use the `headers` request option.
123+
124+
```typescript
125+
const response = await client.form1099Nec.create(..., {
126+
headers: {
127+
'X-Custom-Header': 'custom value'
128+
}
129+
});
130+
```
131+
120132
### Retries
121133

122134
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
123-
as the request is deemed retriable and the number of retry attempts has not grown larger than the configured
135+
as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
124136
retry limit (default: 2).
125137

126-
A request is deemed retriable when any of the following HTTP status codes is returned:
138+
A request is deemed retryable when any of the following HTTP status codes is returned:
127139

128-
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
129-
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
130-
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
140+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
141+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
142+
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
131143

132144
Use the `maxRetries` request option to configure this behavior.
133145

@@ -164,12 +176,12 @@ controller.abort(); // aborts the request
164176
The SDK defaults to `node-fetch` but will use the global fetch client if present. The SDK works in the following
165177
runtimes:
166178

167-
- Node.js 18+
168-
- Vercel
169-
- Cloudflare Workers
170-
- Deno v1.25+
171-
- Bun 1.0+
172-
- React Native
179+
- Node.js 18+
180+
- Vercel
181+
- Cloudflare Workers
182+
- Deno v1.25+
183+
- Bun 1.0+
184+
- React Native
173185

174186
### Customizing Fetch Client
175187

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/** @type {import('jest').Config} */
2-
module.exports = {
2+
export default {
33
preset: "ts-jest",
44
testEnvironment: "node",
5+
moduleNameMapper: {
6+
"(.+)\.js$": "$1",
7+
},
58
};

package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@withabound/node-sdk",
3-
"version": "6.0.61",
3+
"version": "6.0.62",
44
"private": false,
55
"repository": "https://github.com/withabound/abound-node",
66
"license": "MIT",
@@ -17,25 +17,25 @@
1717
"url-join": "4.0.1",
1818
"form-data": "^4.0.0",
1919
"formdata-node": "^6.0.3",
20-
"node-fetch": "2.7.0",
21-
"qs": "6.11.2",
20+
"node-fetch": "^2.7.0",
21+
"qs": "^6.13.1",
2222
"readable-stream": "^4.5.2",
23-
"js-base64": "3.7.2"
23+
"js-base64": "3.7.7"
2424
},
2525
"devDependencies": {
2626
"@types/url-join": "4.0.1",
27-
"@types/qs": "6.9.8",
28-
"@types/node-fetch": "2.6.9",
29-
"@types/readable-stream": "^4.0.15",
30-
"webpack": "^5.94.0",
31-
"ts-loader": "^9.3.1",
32-
"jest": "29.7.0",
33-
"@types/jest": "29.5.5",
34-
"ts-jest": "29.1.1",
35-
"jest-environment-jsdom": "29.7.0",
36-
"@types/node": "17.0.33",
37-
"prettier": "2.7.1",
38-
"typescript": "4.6.4"
27+
"@types/qs": "^6.9.17",
28+
"@types/node-fetch": "^2.6.12",
29+
"@types/readable-stream": "^4.0.18",
30+
"webpack": "^5.97.1",
31+
"ts-loader": "^9.5.1",
32+
"jest": "^29.7.0",
33+
"@types/jest": "^29.5.14",
34+
"ts-jest": "^29.1.1",
35+
"jest-environment-jsdom": "^29.7.0",
36+
"@types/node": "^18.19.70",
37+
"prettier": "^3.4.2",
38+
"typescript": "~5.7.2"
3939
},
4040
"browser": {
4141
"fs": false,

scripts/rename-to-esm-files.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require("fs").promises;
4+
const path = require("path");
5+
6+
const extensionMap = {
7+
".js": ".mjs",
8+
".d.ts": ".d.mts",
9+
};
10+
const oldExtensions = Object.keys(extensionMap);
11+
12+
async function findFiles(rootPath) {
13+
const files = [];
14+
15+
async function scan(directory) {
16+
const entries = await fs.readdir(directory, { withFileTypes: true });
17+
18+
for (const entry of entries) {
19+
const fullPath = path.join(directory, entry.name);
20+
21+
if (entry.isDirectory()) {
22+
if (entry.name !== "node_modules" && !entry.name.startsWith(".")) {
23+
await scan(fullPath);
24+
}
25+
} else if (entry.isFile()) {
26+
if (oldExtensions.some((ext) => entry.name.endsWith(ext))) {
27+
files.push(fullPath);
28+
}
29+
}
30+
}
31+
}
32+
33+
await scan(rootPath);
34+
return files;
35+
}
36+
37+
async function updateFiles(files) {
38+
const updatedFiles = [];
39+
for (const file of files) {
40+
const updated = await updateFileContents(file);
41+
updatedFiles.push(updated);
42+
}
43+
44+
console.log(`Updated imports in ${updatedFiles.length} files.`);
45+
}
46+
47+
async function updateFileContents(file) {
48+
const content = await fs.readFile(file, "utf8");
49+
50+
let newContent = content;
51+
// Update each extension type defined in the map
52+
for (const [oldExt, newExt] of Object.entries(extensionMap)) {
53+
const regex = new RegExp(`(import|export)(.+from\\s+['"])(\\.\\.?\\/[^'"]+)(\\${oldExt})(['"])`, "g");
54+
newContent = newContent.replace(regex, `$1$2$3${newExt}$5`);
55+
}
56+
57+
if (content !== newContent) {
58+
await fs.writeFile(file, newContent, "utf8");
59+
return true;
60+
}
61+
return false;
62+
}
63+
64+
async function renameFiles(files) {
65+
let counter = 0;
66+
for (const file of files) {
67+
const ext = oldExtensions.find((ext) => file.endsWith(ext));
68+
const newExt = extensionMap[ext];
69+
70+
if (newExt) {
71+
const newPath = file.slice(0, -ext.length) + newExt;
72+
await fs.rename(file, newPath);
73+
counter++;
74+
}
75+
}
76+
77+
console.log(`Renamed ${counter} files.`);
78+
}
79+
80+
async function main() {
81+
try {
82+
const targetDir = process.argv[2];
83+
if (!targetDir) {
84+
console.error("Please provide a target directory");
85+
process.exit(1);
86+
}
87+
88+
const targetPath = path.resolve(targetDir);
89+
const targetStats = await fs.stat(targetPath);
90+
91+
if (!targetStats.isDirectory()) {
92+
console.error("The provided path is not a directory");
93+
process.exit(1);
94+
}
95+
96+
console.log(`Scanning directory: ${targetDir}`);
97+
98+
const files = await findFiles(targetDir);
99+
100+
if (files.length === 0) {
101+
console.log("No matching files found.");
102+
process.exit(0);
103+
}
104+
105+
console.log(`Found ${files.length} files.`);
106+
await updateFiles(files);
107+
await renameFiles(files);
108+
console.log("\nDone!");
109+
} catch (error) {
110+
console.error("An error occurred:", error.message);
111+
process.exit(1);
112+
}
113+
}
114+
115+
main();

src/Client.ts

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,99 +19,91 @@ import { TinVerifications } from "./api/resources/tinVerifications/client/Client
1919
import { Users } from "./api/resources/users/client/Client";
2020

2121
export declare namespace AboundClient {
22-
interface Options {
22+
export interface Options {
2323
environment?: core.Supplier<environments.AboundEnvironment | string>;
24+
/** Specify a custom URL to connect the client to. */
25+
baseUrl?: core.Supplier<string>;
2426
apiKey: core.Supplier<core.BearerToken>;
2527
fetcher?: core.FetchFunction;
2628
}
2729

28-
interface RequestOptions {
30+
export interface RequestOptions {
2931
/** The maximum time to wait for a response in seconds. */
3032
timeoutInSeconds?: number;
3133
/** The number of times to retry the request. Defaults to 2. */
3234
maxRetries?: number;
3335
/** A hook to abort the request. */
3436
abortSignal?: AbortSignal;
37+
/** Additional headers to include in the request. */
38+
headers?: Record<string, string>;
3539
}
3640
}
3741

3842
export class AboundClient {
39-
constructor(protected readonly _options: AboundClient.Options) {}
40-
4143
protected _accessTokens: AccessTokens | undefined;
44+
protected _electronicDeliveryConsents: ElectronicDeliveryConsents | undefined;
45+
protected _form1099Int: Form1099Int | undefined;
46+
protected _form1099K: Form1099K | undefined;
47+
protected _form1099Misc: Form1099Misc | undefined;
48+
protected _form1099Nec: Form1099Nec | undefined;
49+
protected _formW8BenE: FormW8BenE | undefined;
50+
protected _formW8Ben: FormW8Ben | undefined;
51+
protected _formW9: FormW9 | undefined;
52+
protected _mailings: Mailings | undefined;
53+
protected _taxTreaties: TaxTreaties | undefined;
54+
protected _tinVerifications: TinVerifications | undefined;
55+
protected _users: Users | undefined;
56+
57+
constructor(protected readonly _options: AboundClient.Options) {}
4258

4359
public get accessTokens(): AccessTokens {
4460
return (this._accessTokens ??= new AccessTokens(this._options));
4561
}
4662

47-
protected _electronicDeliveryConsents: ElectronicDeliveryConsents | undefined;
48-
4963
public get electronicDeliveryConsents(): ElectronicDeliveryConsents {
5064
return (this._electronicDeliveryConsents ??= new ElectronicDeliveryConsents(this._options));
5165
}
5266

53-
protected _form1099Int: Form1099Int | undefined;
54-
5567
public get form1099Int(): Form1099Int {
5668
return (this._form1099Int ??= new Form1099Int(this._options));
5769
}
5870

59-
protected _form1099K: Form1099K | undefined;
60-
6171
public get form1099K(): Form1099K {
6272
return (this._form1099K ??= new Form1099K(this._options));
6373
}
6474

65-
protected _form1099Misc: Form1099Misc | undefined;
66-
6775
public get form1099Misc(): Form1099Misc {
6876
return (this._form1099Misc ??= new Form1099Misc(this._options));
6977
}
7078

71-
protected _form1099Nec: Form1099Nec | undefined;
72-
7379
public get form1099Nec(): Form1099Nec {
7480
return (this._form1099Nec ??= new Form1099Nec(this._options));
7581
}
7682

77-
protected _formW8BenE: FormW8BenE | undefined;
78-
7983
public get formW8BenE(): FormW8BenE {
8084
return (this._formW8BenE ??= new FormW8BenE(this._options));
8185
}
8286

83-
protected _formW8Ben: FormW8Ben | undefined;
84-
8587
public get formW8Ben(): FormW8Ben {
8688
return (this._formW8Ben ??= new FormW8Ben(this._options));
8789
}
8890

89-
protected _formW9: FormW9 | undefined;
90-
9191
public get formW9(): FormW9 {
9292
return (this._formW9 ??= new FormW9(this._options));
9393
}
9494

95-
protected _mailings: Mailings | undefined;
96-
9795
public get mailings(): Mailings {
9896
return (this._mailings ??= new Mailings(this._options));
9997
}
10098

101-
protected _taxTreaties: TaxTreaties | undefined;
102-
10399
public get taxTreaties(): TaxTreaties {
104100
return (this._taxTreaties ??= new TaxTreaties(this._options));
105101
}
106102

107-
protected _tinVerifications: TinVerifications | undefined;
108-
109103
public get tinVerifications(): TinVerifications {
110104
return (this._tinVerifications ??= new TinVerifications(this._options));
111105
}
112106

113-
protected _users: Users | undefined;
114-
115107
public get users(): Users {
116108
return (this._users ??= new Users(this._options));
117109
}

0 commit comments

Comments
 (0)