Skip to content

Commit

Permalink
Release 0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Jan 18, 2024
1 parent 3833021 commit c99e710
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 13 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Fern.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fern-api/node-sdk",
"version": "0.2.1",
"version": "0.2.2",
"private": false,
"repository": "https://github.com/fern-api/node-sdk",
"main": "./index.js",
Expand All @@ -12,12 +12,15 @@
},
"dependencies": {
"url-join": "4.0.1",
"form-data": "4.0.0",
"node-fetch": "2.7.0",
"qs": "6.11.2",
"js-base64": "3.7.2"
},
"devDependencies": {
"@types/url-join": "4.0.1",
"@types/qs": "6.9.8",
"@types/node-fetch": "2.6.9",
"@types/node": "17.0.33",
"prettier": "2.7.1",
"typescript": "4.6.4"
Expand Down
4 changes: 2 additions & 2 deletions src/api/resources/snippets/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class Snippets {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@fern-api/node-sdk",
"X-Fern-SDK-Version": "0.2.1",
"X-Fern-SDK-Version": "0.2.2",
},
contentType: "application/json",
body: await serializers.snippets.GetSnippetRequest.jsonOrThrow(request, {
Expand Down Expand Up @@ -229,7 +229,7 @@ export class Snippets {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@fern-api/node-sdk",
"X-Fern-SDK-Version": "0.2.1",
"X-Fern-SDK-Version": "0.2.2",
},
contentType: "application/json",
queryParameters: _queryParams,
Expand Down
1 change: 0 additions & 1 deletion src/api/resources/snippets/types/SnippetsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export interface SnippetsPage {
/**
* The snippets are returned as a map of endpoint path (e.g. `/api/users`)
* to a map of endpoint method (e.g. `POST`) to snippets.
*
*/
snippets: Record<Fern.snippets.EndpointPath, Fern.snippets.SnippetsByEndpointMethod>;
}
1 change: 1 addition & 0 deletions src/core/fetcher/APIResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type APIResponse<Success, Failure> = SuccessfulResponse<Success> | Failed
export interface SuccessfulResponse<T> {
ok: true;
body: T;
headers?: Record<string, any>;
}

export interface FailedResponse<T> {
Expand Down
30 changes: 27 additions & 3 deletions src/core/fetcher/Fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { default as FormData } from "form-data";
import qs from "qs";
import { APIResponse } from "./APIResponse";

if (typeof window === "undefined") {
global.fetch = require("node-fetch");
}

export type FetchFunction = <R = unknown>(args: Fetcher.Args) => Promise<APIResponse<R, Fetcher.Error>>;

export declare namespace Fetcher {
Expand All @@ -14,7 +19,7 @@ export declare namespace Fetcher {
timeoutMs?: number;
maxRetries?: number;
withCredentials?: boolean;
responseType?: "json" | "blob";
responseType?: "json" | "blob" | "streaming";
}

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

let body: BodyInit | undefined = undefined;
if (args.body instanceof FormData) {
// @ts-expect-error
body = args.body;
} else {
body = JSON.stringify(args.body);
}

const makeRequest = async (): Promise<Response> => {
const controller = new AbortController();
let abortId = undefined;
Expand All @@ -73,7 +86,7 @@ async function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse
const response = await fetch(url, {
method: args.method,
headers,
body: args.body === undefined ? undefined : JSON.stringify(args.body),
body,
signal: controller.signal,
credentials: args.withCredentials ? "same-origin" : undefined,
});
Expand Down Expand Up @@ -104,10 +117,12 @@ async function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse
let body: unknown;
if (response.body != null && args.responseType === "blob") {
body = await response.blob();
} else if (response.body != null && args.responseType === "streaming") {
body = response.body;
} else if (response.body != null) {
try {
body = await response.json();
} catch {
} catch (err) {
return {
ok: false,
error: {
Expand All @@ -123,6 +138,7 @@ async function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse
return {
ok: true,
body: body as R,
headers: response.headers,
};
} else {
return {
Expand All @@ -142,6 +158,14 @@ async function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse
reason: "timeout",
},
};
} else if (error instanceof Error) {
return {
ok: false,
error: {
reason: "unknown",
errorMessage: error.message,
},
};
}

return {
Expand Down
8 changes: 8 additions & 0 deletions src/core/fetcher/getHeader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function getHeader(headers: Record<string, any>, header: string): string | undefined {
for (const [headerKey, headerValue] of Object.entries(headers)) {
if (headerKey.toLowerCase() === header.toLowerCase()) {
return headerValue;
}
}
return undefined;
}
1 change: 1 addition & 0 deletions src/core/fetcher/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type { APIResponse } from "./APIResponse";
export { fetcher } from "./Fetcher";
export type { Fetcher, FetchFunction } from "./Fetcher";
export { getHeader } from "./getHeader";
export { Supplier } from "./Supplier";
96 changes: 90 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
# yarn lockfile v1


"@types/[email protected]":
version "2.6.9"
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.9.tgz#15f529d247f1ede1824f7e7acdaa192d5f28071e"
integrity sha512-bQVlnMLFJ2d35DkPNjEPmd9ueO/rh5EiaZt2bhqiSarPjZIuIV6bPQVqcrEyvNo+AfTrRGVazle1tl597w3gfA==
dependencies:
"@types/node" "*"
form-data "^4.0.0"

"@types/node@*":
version "20.11.5"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.5.tgz#be10c622ca7fcaa3cf226cf80166abc31389d86e"
integrity sha512-g557vgQjUUfN76MZAN/dt1z3dzcUsimuysco0KeluHgrPdJXkP/XdAURgyO2W9fZWHRtRBiVKzKn8vyOAwlG+w==
dependencies:
undici-types "~5.26.4"

"@types/[email protected]":
version "17.0.33"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.33.tgz#3c1879b276dc63e73030bb91165e62a4509cd506"
Expand All @@ -17,6 +32,11 @@
resolved "https://registry.yarnpkg.com/@types/url-join/-/url-join-4.0.1.tgz#4989c97f969464647a8586c7252d97b449cdc045"
integrity sha512-wDXw9LEEUHyV+7UWy7U315nrJGJ7p1BzaCxDpEoLr789Dk1WDVMMlf3iBfbG2F8NdWnYyFbtTxUn2ZNbm1Q4LQ==

asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==

call-bind@^1.0.0:
version "1.0.5"
resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.5.tgz#6fa2b7845ce0ea49bf4d8b9ef64727a2c2e2e513"
Expand All @@ -26,6 +46,13 @@ call-bind@^1.0.0:
get-intrinsic "^1.2.1"
set-function-length "^1.1.1"

combined-stream@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
dependencies:
delayed-stream "~1.0.0"

define-data-property@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/define-data-property/-/define-data-property-1.1.1.tgz#c35f7cd0ab09883480d12ac5cb213715587800b3"
Expand All @@ -35,6 +62,20 @@ define-data-property@^1.1.1:
gopd "^1.0.1"
has-property-descriptors "^1.0.0"

delayed-stream@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==

[email protected], form-data@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"

function-bind@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.2.tgz#2c02d864d97f3ea6c8830c464cbd11ab6eab7a1c"
Expand All @@ -57,7 +98,7 @@ gopd@^1.0.1:
dependencies:
get-intrinsic "^1.1.3"

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

[email protected]:
version "1.52.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==

mime-types@^2.1.12:
version "2.1.35"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==
dependencies:
mime-db "1.52.0"

[email protected]:
version "2.7.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
dependencies:
whatwg-url "^5.0.0"

object-inspect@^1.9.0:
version "1.13.1"
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.13.1.tgz#b96c6109324ccfef6b12216a956ca4dc2ff94bc2"
Expand All @@ -104,14 +164,15 @@ [email protected]:
side-channel "^1.0.4"

set-function-length@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/set-function-length/-/set-function-length-1.1.1.tgz#4bc39fafb0307224a33e106a7d35ca1218d659ed"
integrity sha512-VoaqjbBJKiWtg4yRcKBQ7g7wnGnLV3M8oLvVWwOk2PdYY6PEFegR1vezXR0tw6fZGF9csVakIRjrJiy2veSBFQ==
version "1.2.0"
resolved "https://registry.yarnpkg.com/set-function-length/-/set-function-length-1.2.0.tgz#2f81dc6c16c7059bda5ab7c82c11f03a515ed8e1"
integrity sha512-4DBHDoyHlM1IRPGYcoxexgh67y4ueR53FKV1yyxwFMY7aCqcN/38M1+SwZ/qJQ8iLv7+ck385ot4CcisOAPT9w==
dependencies:
define-data-property "^1.1.1"
get-intrinsic "^1.2.1"
function-bind "^1.1.2"
get-intrinsic "^1.2.2"
gopd "^1.0.1"
has-property-descriptors "^1.0.0"
has-property-descriptors "^1.0.1"

side-channel@^1.0.4:
version "1.0.4"
Expand All @@ -122,12 +183,35 @@ side-channel@^1.0.4:
get-intrinsic "^1.0.2"
object-inspect "^1.9.0"

tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==

[email protected]:
version "4.6.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.4.tgz#caa78bbc3a59e6a5c510d35703f6a09877ce45e9"
integrity sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==

undici-types@~5.26.4:
version "5.26.5"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==

[email protected]:
version "4.0.1"
resolved "https://registry.yarnpkg.com/url-join/-/url-join-4.0.1.tgz#b642e21a2646808ffa178c4c5fda39844e12cde7"
integrity sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==

whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"

0 comments on commit c99e710

Please sign in to comment.