Skip to content

Commit 4091a52

Browse files
🌿 Fern Regeneration -- March 4, 2024 (#13)
Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
1 parent 6216aab commit 4091a52

File tree

12 files changed

+2420
-82
lines changed

12 files changed

+2420
-82
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,21 @@ jobs:
1616
- name: Compile
1717
run: yarn && yarn build
1818

19+
test:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout repo
24+
uses: actions/checkout@v3
25+
26+
- name: Set up node
27+
uses: actions/setup-node@v3
28+
29+
- name: Compile
30+
run: yarn && yarn test
31+
1932
publish:
20-
needs: [ compile ]
33+
needs: [ compile, test ]
2134
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
2235
runs-on: ubuntu-latest
2336

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: "ts-jest",
4+
testEnvironment: "node",
5+
};

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "hume",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"private": false,
55
"repository": "https://github.com/HumeAI/hume-typescript-sdk",
66
"main": "./index.js",
77
"types": "./index.d.ts",
88
"scripts": {
99
"format": "prettier --write 'src/**/*.ts'",
1010
"build": "tsc",
11-
"prepack": "cp -rv dist/. ."
11+
"prepack": "cp -rv dist/. .",
12+
"test": "jest"
1213
},
1314
"dependencies": {
1415
"url-join": "4.0.1",
@@ -24,6 +25,9 @@
2425
"@types/url-join": "4.0.1",
2526
"@types/qs": "6.9.8",
2627
"@types/node-fetch": "2.6.9",
28+
"jest": "^29.7.0",
29+
"@types/jest": "^29.5.5",
30+
"ts-jest": "^29.1.1",
2731
"@types/node": "17.0.33",
2832
"prettier": "2.7.1",
2933
"typescript": "4.6.4"

src/Client.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ export class HumeClient {
2929
* Sort and filter jobs.
3030
*
3131
* @example
32-
* await hume.listJobs({
33-
* status: Hume.Status.Queued,
34-
* when: Hume.When.CreatedBefore,
35-
* sortBy: Hume.SortBy.Created,
36-
* direction: Hume.Direction.Asc
37-
* })
32+
* await hume.listJobs({})
3833
*/
3934
public async listJobs(
4035
request: Hume.ListJobsRequest = {},
@@ -80,7 +75,9 @@ export class HumeClient {
8075
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
8176
"X-Fern-Language": "JavaScript",
8277
"X-Fern-SDK-Name": "hume",
83-
"X-Fern-SDK-Version": "0.4.1",
78+
"X-Fern-SDK-Version": "0.4.2",
79+
"X-Fern-Runtime": core.RUNTIME.type,
80+
"X-Fern-Runtime-Version": core.RUNTIME.version,
8481
},
8582
contentType: "application/json",
8683
queryParameters: _queryParams,
@@ -120,6 +117,9 @@ export class HumeClient {
120117

121118
/**
122119
* Start a new batch job.
120+
*
121+
* @example
122+
* await hume.submitJob({})
123123
*/
124124
public async submitJob(
125125
request: Hume.BaseRequest = {},
@@ -135,7 +135,9 @@ export class HumeClient {
135135
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
136136
"X-Fern-Language": "JavaScript",
137137
"X-Fern-SDK-Name": "hume",
138-
"X-Fern-SDK-Version": "0.4.1",
138+
"X-Fern-SDK-Version": "0.4.2",
139+
"X-Fern-Runtime": core.RUNTIME.type,
140+
"X-Fern-Runtime-Version": core.RUNTIME.version,
139141
},
140142
contentType: "application/json",
141143
body: await serializers.BaseRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
@@ -193,7 +195,9 @@ export class HumeClient {
193195
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
194196
"X-Fern-Language": "JavaScript",
195197
"X-Fern-SDK-Name": "hume",
196-
"X-Fern-SDK-Version": "0.4.1",
198+
"X-Fern-SDK-Version": "0.4.2",
199+
"X-Fern-Runtime": core.RUNTIME.type,
200+
"X-Fern-Runtime-Version": core.RUNTIME.version,
197201
},
198202
contentType: "application/json",
199203
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
@@ -244,7 +248,9 @@ export class HumeClient {
244248
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
245249
"X-Fern-Language": "JavaScript",
246250
"X-Fern-SDK-Name": "hume",
247-
"X-Fern-SDK-Version": "0.4.1",
251+
"X-Fern-SDK-Version": "0.4.2",
252+
"X-Fern-Runtime": core.RUNTIME.type,
253+
"X-Fern-Runtime-Version": core.RUNTIME.version,
248254
},
249255
contentType: "application/json",
250256
responseType: "streaming",
@@ -291,7 +297,9 @@ export class HumeClient {
291297
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
292298
"X-Fern-Language": "JavaScript",
293299
"X-Fern-SDK-Name": "hume",
294-
"X-Fern-SDK-Version": "0.4.1",
300+
"X-Fern-SDK-Version": "0.4.2",
301+
"X-Fern-Runtime": core.RUNTIME.type,
302+
"X-Fern-Runtime-Version": core.RUNTIME.version,
295303
},
296304
contentType: "application/json",
297305
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,

src/api/client/requests/BaseRequest.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
import * as Hume from "../..";
66

7+
/**
8+
* @example
9+
* {}
10+
*/
711
export interface BaseRequest {
812
models?: Hume.Models;
913
transcription?: Hume.Transcription;

src/api/client/requests/ListJobsRequest.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ import * as Hume from "../..";
66

77
/**
88
* @example
9-
* {
10-
* status: Hume.Status.Queued,
11-
* when: Hume.When.CreatedBefore,
12-
* sortBy: Hume.SortBy.Created,
13-
* direction: Hume.Direction.Asc
14-
* }
9+
* {}
1510
*/
1611
export interface ListJobsRequest {
1712
/**

src/core/fetcher/Fetcher.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { default as FormData } from "form-data";
22
import qs from "qs";
3+
import { RUNTIME } from "../runtime";
34
import { APIResponse } from "./APIResponse";
45

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

118
export declare namespace Fetcher {
@@ -73,22 +70,30 @@ async function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse
7370
if (args.body instanceof FormData) {
7471
// @ts-expect-error
7572
body = args.body;
73+
} else if (args.body instanceof Uint8Array) {
74+
body = args.body;
7675
} else {
7776
body = JSON.stringify(args.body);
7877
}
7978

79+
// In Node.js environments, the SDK always uses`node-fetch`.
80+
// If not in Node.js the SDK uses global fetch if available,
81+
// and falls back to node-fetch.
82+
const fetchFn =
83+
RUNTIME.type === "node" ? require("node-fetch") : typeof fetch == "function" ? fetch : require("node-fetch");
84+
8085
const makeRequest = async (): Promise<Response> => {
8186
const controller = new AbortController();
8287
let abortId = undefined;
8388
if (args.timeoutMs != null) {
8489
abortId = setTimeout(() => controller.abort(), args.timeoutMs);
8590
}
86-
const response = await fetch(url, {
91+
const response = await fetchFn(url, {
8792
method: args.method,
8893
headers,
8994
body,
9095
signal: controller.signal,
91-
credentials: args.withCredentials ? "same-origin" : undefined,
96+
credentials: args.withCredentials ? "include" : undefined,
9297
});
9398
if (abortId != null) {
9499
clearTimeout(abortId);
@@ -119,18 +124,21 @@ async function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse
119124
body = await response.blob();
120125
} else if (response.body != null && args.responseType === "streaming") {
121126
body = response.body;
122-
} else if (response.body != null) {
123-
try {
124-
body = await response.json();
125-
} catch (err) {
126-
return {
127-
ok: false,
128-
error: {
129-
reason: "non-json",
130-
statusCode: response.status,
131-
rawBody: await response.text(),
132-
},
133-
};
127+
} else {
128+
const text = await response.text();
129+
if (text.length > 0) {
130+
try {
131+
body = JSON.parse(text);
132+
} catch (err) {
133+
return {
134+
ok: false,
135+
error: {
136+
reason: "non-json",
137+
statusCode: response.status,
138+
rawBody: text,
139+
},
140+
};
141+
}
134142
}
135143
}
136144

src/core/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./fetcher";
2+
export * from "./runtime";
23
export * as serialization from "./schemas";

src/core/runtime/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { RUNTIME } from "./runtime";

src/core/runtime/runtime.ts

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
interface DenoGlobal {
2+
version: {
3+
deno: string;
4+
};
5+
}
6+
7+
interface BunGlobal {
8+
version: string;
9+
}
10+
11+
declare const Deno: DenoGlobal;
12+
declare const Bun: BunGlobal;
13+
14+
/**
15+
* A constant that indicates whether the environment the code is running is a Web Browser.
16+
*/
17+
const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
18+
19+
/**
20+
* A constant that indicates whether the environment the code is running is a Web Worker.
21+
*/
22+
const isWebWorker =
23+
typeof self === "object" &&
24+
// @ts-ignore
25+
typeof self?.importScripts === "function" &&
26+
(self.constructor?.name === "DedicatedWorkerGlobalScope" ||
27+
self.constructor?.name === "ServiceWorkerGlobalScope" ||
28+
self.constructor?.name === "SharedWorkerGlobalScope");
29+
30+
/**
31+
* A constant that indicates whether the environment the code is running is Deno.
32+
*/
33+
const isDeno =
34+
typeof Deno !== "undefined" && typeof Deno.version !== "undefined" && typeof Deno.version.deno !== "undefined";
35+
36+
/**
37+
* A constant that indicates whether the environment the code is running is Bun.sh.
38+
*/
39+
const isBun = typeof Bun !== "undefined" && typeof Bun.version !== "undefined";
40+
41+
/**
42+
* A constant that indicates whether the environment the code is running is Node.JS.
43+
*/
44+
const isNode =
45+
typeof process !== "undefined" &&
46+
Boolean(process.version) &&
47+
Boolean(process.versions?.node) &&
48+
// Deno spoofs process.versions.node, see https://deno.land/[email protected]/node/process.ts?s=versions
49+
!isDeno &&
50+
!isBun;
51+
52+
/**
53+
* A constant that indicates whether the environment the code is running is in React-Native.
54+
* https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js
55+
*/
56+
const isReactNative = typeof navigator !== "undefined" && navigator?.product === "ReactNative";
57+
58+
/**
59+
* A constant that indicates which environment and version the SDK is running in.
60+
*/
61+
export const RUNTIME: Runtime = evaluateRuntime();
62+
63+
export interface Runtime {
64+
type: "browser" | "web-worker" | "deno" | "bun" | "node" | "react-native" | "unknown";
65+
version?: string;
66+
}
67+
68+
function evaluateRuntime(): Runtime {
69+
if (isBrowser) {
70+
return {
71+
type: "browser",
72+
version: window.navigator.userAgent,
73+
};
74+
}
75+
76+
if (isWebWorker) {
77+
return {
78+
type: "web-worker",
79+
};
80+
}
81+
82+
if (isDeno) {
83+
return {
84+
type: "deno",
85+
version: Deno.version.deno,
86+
};
87+
}
88+
89+
if (isBun) {
90+
return {
91+
type: "bun",
92+
version: Bun.version,
93+
};
94+
}
95+
96+
if (isNode) {
97+
return {
98+
type: "node",
99+
version: process.versions.node,
100+
};
101+
}
102+
103+
if (isReactNative) {
104+
return {
105+
type: "react-native",
106+
};
107+
}
108+
109+
return {
110+
type: "unknown",
111+
};
112+
}

0 commit comments

Comments
 (0)