Skip to content

Commit c99e710

Browse files
committed
Release 0.2.2
1 parent 3833021 commit c99e710

File tree

9 files changed

+154
-13
lines changed

9 files changed

+154
-13
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Fern.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fern-api/node-sdk",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"private": false,
55
"repository": "https://github.com/fern-api/node-sdk",
66
"main": "./index.js",
@@ -12,12 +12,15 @@
1212
},
1313
"dependencies": {
1414
"url-join": "4.0.1",
15+
"form-data": "4.0.0",
16+
"node-fetch": "2.7.0",
1517
"qs": "6.11.2",
1618
"js-base64": "3.7.2"
1719
},
1820
"devDependencies": {
1921
"@types/url-join": "4.0.1",
2022
"@types/qs": "6.9.8",
23+
"@types/node-fetch": "2.6.9",
2124
"@types/node": "17.0.33",
2225
"prettier": "2.7.1",
2326
"typescript": "4.6.4"

src/api/resources/snippets/client/Client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class Snippets {
5959
Authorization: await this._getAuthorizationHeader(),
6060
"X-Fern-Language": "JavaScript",
6161
"X-Fern-SDK-Name": "@fern-api/node-sdk",
62-
"X-Fern-SDK-Version": "0.2.1",
62+
"X-Fern-SDK-Version": "0.2.2",
6363
},
6464
contentType: "application/json",
6565
body: await serializers.snippets.GetSnippetRequest.jsonOrThrow(request, {
@@ -229,7 +229,7 @@ export class Snippets {
229229
Authorization: await this._getAuthorizationHeader(),
230230
"X-Fern-Language": "JavaScript",
231231
"X-Fern-SDK-Name": "@fern-api/node-sdk",
232-
"X-Fern-SDK-Version": "0.2.1",
232+
"X-Fern-SDK-Version": "0.2.2",
233233
},
234234
contentType: "application/json",
235235
queryParameters: _queryParams,

src/api/resources/snippets/types/SnippetsPage.ts

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export interface SnippetsPage {
1010
/**
1111
* The snippets are returned as a map of endpoint path (e.g. `/api/users`)
1212
* to a map of endpoint method (e.g. `POST`) to snippets.
13-
*
1413
*/
1514
snippets: Record<Fern.snippets.EndpointPath, Fern.snippets.SnippetsByEndpointMethod>;
1615
}

src/core/fetcher/APIResponse.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export type APIResponse<Success, Failure> = SuccessfulResponse<Success> | Failed
33
export interface SuccessfulResponse<T> {
44
ok: true;
55
body: T;
6+
headers?: Record<string, any>;
67
}
78

89
export interface FailedResponse<T> {

src/core/fetcher/Fetcher.ts

+27-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import { default as FormData } from "form-data";
12
import qs from "qs";
23
import { APIResponse } from "./APIResponse";
34

5+
if (typeof window === "undefined") {
6+
global.fetch = require("node-fetch");
7+
}
8+
49
export type FetchFunction = <R = unknown>(args: Fetcher.Args) => Promise<APIResponse<R, Fetcher.Error>>;
510

611
export declare namespace Fetcher {
@@ -14,7 +19,7 @@ export declare namespace Fetcher {
1419
timeoutMs?: number;
1520
maxRetries?: number;
1621
withCredentials?: boolean;
17-
responseType?: "json" | "blob";
22+
responseType?: "json" | "blob" | "streaming";
1823
}
1924

2025
export type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError;
@@ -64,6 +69,14 @@ async function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse
6469
? `${args.url}?${qs.stringify(args.queryParameters, { arrayFormat: "repeat" })}`
6570
: args.url;
6671

72+
let body: BodyInit | undefined = undefined;
73+
if (args.body instanceof FormData) {
74+
// @ts-expect-error
75+
body = args.body;
76+
} else {
77+
body = JSON.stringify(args.body);
78+
}
79+
6780
const makeRequest = async (): Promise<Response> => {
6881
const controller = new AbortController();
6982
let abortId = undefined;
@@ -73,7 +86,7 @@ async function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse
7386
const response = await fetch(url, {
7487
method: args.method,
7588
headers,
76-
body: args.body === undefined ? undefined : JSON.stringify(args.body),
89+
body,
7790
signal: controller.signal,
7891
credentials: args.withCredentials ? "same-origin" : undefined,
7992
});
@@ -104,10 +117,12 @@ async function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse
104117
let body: unknown;
105118
if (response.body != null && args.responseType === "blob") {
106119
body = await response.blob();
120+
} else if (response.body != null && args.responseType === "streaming") {
121+
body = response.body;
107122
} else if (response.body != null) {
108123
try {
109124
body = await response.json();
110-
} catch {
125+
} catch (err) {
111126
return {
112127
ok: false,
113128
error: {
@@ -123,6 +138,7 @@ async function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse
123138
return {
124139
ok: true,
125140
body: body as R,
141+
headers: response.headers,
126142
};
127143
} else {
128144
return {
@@ -142,6 +158,14 @@ async function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse
142158
reason: "timeout",
143159
},
144160
};
161+
} else if (error instanceof Error) {
162+
return {
163+
ok: false,
164+
error: {
165+
reason: "unknown",
166+
errorMessage: error.message,
167+
},
168+
};
145169
}
146170

147171
return {

src/core/fetcher/getHeader.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function getHeader(headers: Record<string, any>, header: string): string | undefined {
2+
for (const [headerKey, headerValue] of Object.entries(headers)) {
3+
if (headerKey.toLowerCase() === header.toLowerCase()) {
4+
return headerValue;
5+
}
6+
}
7+
return undefined;
8+
}

src/core/fetcher/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export type { APIResponse } from "./APIResponse";
22
export { fetcher } from "./Fetcher";
33
export type { Fetcher, FetchFunction } from "./Fetcher";
4+
export { getHeader } from "./getHeader";
45
export { Supplier } from "./Supplier";

yarn.lock

+90-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
# yarn lockfile v1
33

44

5+
6+
version "2.6.9"
7+
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.9.tgz#15f529d247f1ede1824f7e7acdaa192d5f28071e"
8+
integrity sha512-bQVlnMLFJ2d35DkPNjEPmd9ueO/rh5EiaZt2bhqiSarPjZIuIV6bPQVqcrEyvNo+AfTrRGVazle1tl597w3gfA==
9+
dependencies:
10+
"@types/node" "*"
11+
form-data "^4.0.0"
12+
13+
"@types/node@*":
14+
version "20.11.5"
15+
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.5.tgz#be10c622ca7fcaa3cf226cf80166abc31389d86e"
16+
integrity sha512-g557vgQjUUfN76MZAN/dt1z3dzcUsimuysco0KeluHgrPdJXkP/XdAURgyO2W9fZWHRtRBiVKzKn8vyOAwlG+w==
17+
dependencies:
18+
undici-types "~5.26.4"
19+
520
621
version "17.0.33"
722
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.33.tgz#3c1879b276dc63e73030bb91165e62a4509cd506"
@@ -17,6 +32,11 @@
1732
resolved "https://registry.yarnpkg.com/@types/url-join/-/url-join-4.0.1.tgz#4989c97f969464647a8586c7252d97b449cdc045"
1833
integrity sha512-wDXw9LEEUHyV+7UWy7U315nrJGJ7p1BzaCxDpEoLr789Dk1WDVMMlf3iBfbG2F8NdWnYyFbtTxUn2ZNbm1Q4LQ==
1934

35+
asynckit@^0.4.0:
36+
version "0.4.0"
37+
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
38+
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
39+
2040
call-bind@^1.0.0:
2141
version "1.0.5"
2242
resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.5.tgz#6fa2b7845ce0ea49bf4d8b9ef64727a2c2e2e513"
@@ -26,6 +46,13 @@ call-bind@^1.0.0:
2646
get-intrinsic "^1.2.1"
2747
set-function-length "^1.1.1"
2848

49+
combined-stream@^1.0.8:
50+
version "1.0.8"
51+
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
52+
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
53+
dependencies:
54+
delayed-stream "~1.0.0"
55+
2956
define-data-property@^1.1.1:
3057
version "1.1.1"
3158
resolved "https://registry.yarnpkg.com/define-data-property/-/define-data-property-1.1.1.tgz#c35f7cd0ab09883480d12ac5cb213715587800b3"
@@ -35,6 +62,20 @@ define-data-property@^1.1.1:
3562
gopd "^1.0.1"
3663
has-property-descriptors "^1.0.0"
3764

65+
delayed-stream@~1.0.0:
66+
version "1.0.0"
67+
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
68+
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==
69+
70+
[email protected], form-data@^4.0.0:
71+
version "4.0.0"
72+
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
73+
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
74+
dependencies:
75+
asynckit "^0.4.0"
76+
combined-stream "^1.0.8"
77+
mime-types "^2.1.12"
78+
3879
function-bind@^1.1.2:
3980
version "1.1.2"
4081
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.2.tgz#2c02d864d97f3ea6c8830c464cbd11ab6eab7a1c"
@@ -57,7 +98,7 @@ gopd@^1.0.1:
5798
dependencies:
5899
get-intrinsic "^1.1.3"
59100

60-
has-property-descriptors@^1.0.0:
101+
has-property-descriptors@^1.0.0, has-property-descriptors@^1.0.1:
61102
version "1.0.1"
62103
resolved "https://registry.yarnpkg.com/has-property-descriptors/-/has-property-descriptors-1.0.1.tgz#52ba30b6c5ec87fd89fa574bc1c39125c6f65340"
63104
integrity sha512-VsX8eaIewvas0xnvinAe9bw4WfIeODpGYikiWYLH+dma0Jw6KHYqWiWfhQlgOVK8D6PvjubK5Uc4P0iIhIcNVg==
@@ -86,6 +127,25 @@ [email protected]:
86127
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.2.tgz#816d11d81a8aff241603d19ce5761e13e41d7745"
87128
integrity sha512-NnRs6dsyqUXejqk/yv2aiXlAvOs56sLkX6nUdeaNezI5LFFLlsZjOThmwnrcwh5ZZRwZlCMnVAY3CvhIhoVEKQ==
88129

130+
131+
version "1.52.0"
132+
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
133+
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==
134+
135+
mime-types@^2.1.12:
136+
version "2.1.35"
137+
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
138+
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==
139+
dependencies:
140+
mime-db "1.52.0"
141+
142+
143+
version "2.7.0"
144+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
145+
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
146+
dependencies:
147+
whatwg-url "^5.0.0"
148+
89149
object-inspect@^1.9.0:
90150
version "1.13.1"
91151
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.13.1.tgz#b96c6109324ccfef6b12216a956ca4dc2ff94bc2"
@@ -104,14 +164,15 @@ [email protected]:
104164
side-channel "^1.0.4"
105165

106166
set-function-length@^1.1.1:
107-
version "1.1.1"
108-
resolved "https://registry.yarnpkg.com/set-function-length/-/set-function-length-1.1.1.tgz#4bc39fafb0307224a33e106a7d35ca1218d659ed"
109-
integrity sha512-VoaqjbBJKiWtg4yRcKBQ7g7wnGnLV3M8oLvVWwOk2PdYY6PEFegR1vezXR0tw6fZGF9csVakIRjrJiy2veSBFQ==
167+
version "1.2.0"
168+
resolved "https://registry.yarnpkg.com/set-function-length/-/set-function-length-1.2.0.tgz#2f81dc6c16c7059bda5ab7c82c11f03a515ed8e1"
169+
integrity sha512-4DBHDoyHlM1IRPGYcoxexgh67y4ueR53FKV1yyxwFMY7aCqcN/38M1+SwZ/qJQ8iLv7+ck385ot4CcisOAPT9w==
110170
dependencies:
111171
define-data-property "^1.1.1"
112-
get-intrinsic "^1.2.1"
172+
function-bind "^1.1.2"
173+
get-intrinsic "^1.2.2"
113174
gopd "^1.0.1"
114-
has-property-descriptors "^1.0.0"
175+
has-property-descriptors "^1.0.1"
115176

116177
side-channel@^1.0.4:
117178
version "1.0.4"
@@ -122,12 +183,35 @@ side-channel@^1.0.4:
122183
get-intrinsic "^1.0.2"
123184
object-inspect "^1.9.0"
124185

186+
tr46@~0.0.3:
187+
version "0.0.3"
188+
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
189+
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==
190+
125191
126192
version "4.6.4"
127193
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.4.tgz#caa78bbc3a59e6a5c510d35703f6a09877ce45e9"
128194
integrity sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==
129195

196+
undici-types@~5.26.4:
197+
version "5.26.5"
198+
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
199+
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==
200+
130201
131202
version "4.0.1"
132203
resolved "https://registry.yarnpkg.com/url-join/-/url-join-4.0.1.tgz#b642e21a2646808ffa178c4c5fda39844e12cde7"
133204
integrity sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==
205+
206+
webidl-conversions@^3.0.0:
207+
version "3.0.1"
208+
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
209+
integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==
210+
211+
whatwg-url@^5.0.0:
212+
version "5.0.0"
213+
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
214+
integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==
215+
dependencies:
216+
tr46 "~0.0.3"
217+
webidl-conversions "^3.0.0"

0 commit comments

Comments
 (0)