Skip to content

Commit

Permalink
🌿 Fern Regeneration -- March 4, 2024 (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
  • Loading branch information
fern-api[bot] authored Mar 4, 2024
1 parent 6216aab commit 4091a52
Show file tree
Hide file tree
Showing 12 changed files with 2,420 additions and 82 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,21 @@ jobs:
- name: Compile
run: yarn && yarn build

test:
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set up node
uses: actions/setup-node@v3

- name: Compile
run: yarn && yarn test

publish:
needs: [ compile ]
needs: [ compile, test ]
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
runs-on: ubuntu-latest

Expand Down
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
};
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "hume",
"version": "0.4.1",
"version": "0.4.2",
"private": false,
"repository": "https://github.com/HumeAI/hume-typescript-sdk",
"main": "./index.js",
"types": "./index.d.ts",
"scripts": {
"format": "prettier --write 'src/**/*.ts'",
"build": "tsc",
"prepack": "cp -rv dist/. ."
"prepack": "cp -rv dist/. .",
"test": "jest"
},
"dependencies": {
"url-join": "4.0.1",
Expand All @@ -24,6 +25,9 @@
"@types/url-join": "4.0.1",
"@types/qs": "6.9.8",
"@types/node-fetch": "2.6.9",
"jest": "^29.7.0",
"@types/jest": "^29.5.5",
"ts-jest": "^29.1.1",
"@types/node": "17.0.33",
"prettier": "2.7.1",
"typescript": "4.6.4"
Expand Down
30 changes: 19 additions & 11 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ export class HumeClient {
* Sort and filter jobs.
*
* @example
* await hume.listJobs({
* status: Hume.Status.Queued,
* when: Hume.When.CreatedBefore,
* sortBy: Hume.SortBy.Created,
* direction: Hume.Direction.Asc
* })
* await hume.listJobs({})
*/
public async listJobs(
request: Hume.ListJobsRequest = {},
Expand Down Expand Up @@ -80,7 +75,9 @@ export class HumeClient {
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "hume",
"X-Fern-SDK-Version": "0.4.1",
"X-Fern-SDK-Version": "0.4.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
contentType: "application/json",
queryParameters: _queryParams,
Expand Down Expand Up @@ -120,6 +117,9 @@ export class HumeClient {

/**
* Start a new batch job.
*
* @example
* await hume.submitJob({})
*/
public async submitJob(
request: Hume.BaseRequest = {},
Expand All @@ -135,7 +135,9 @@ export class HumeClient {
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "hume",
"X-Fern-SDK-Version": "0.4.1",
"X-Fern-SDK-Version": "0.4.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
contentType: "application/json",
body: await serializers.BaseRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
Expand Down Expand Up @@ -193,7 +195,9 @@ export class HumeClient {
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "hume",
"X-Fern-SDK-Version": "0.4.1",
"X-Fern-SDK-Version": "0.4.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
contentType: "application/json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
Expand Down Expand Up @@ -244,7 +248,9 @@ export class HumeClient {
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "hume",
"X-Fern-SDK-Version": "0.4.1",
"X-Fern-SDK-Version": "0.4.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
contentType: "application/json",
responseType: "streaming",
Expand Down Expand Up @@ -291,7 +297,9 @@ export class HumeClient {
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "hume",
"X-Fern-SDK-Version": "0.4.1",
"X-Fern-SDK-Version": "0.4.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
contentType: "application/json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
Expand Down
4 changes: 4 additions & 0 deletions src/api/client/requests/BaseRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

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

/**
* @example
* {}
*/
export interface BaseRequest {
models?: Hume.Models;
transcription?: Hume.Transcription;
Expand Down
7 changes: 1 addition & 6 deletions src/api/client/requests/ListJobsRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import * as Hume from "../..";

/**
* @example
* {
* status: Hume.Status.Queued,
* when: Hume.When.CreatedBefore,
* sortBy: Hume.SortBy.Created,
* direction: Hume.Direction.Asc
* }
* {}
*/
export interface ListJobsRequest {
/**
Expand Down
44 changes: 26 additions & 18 deletions src/core/fetcher/Fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { default as FormData } from "form-data";
import qs from "qs";
import { RUNTIME } from "../runtime";
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 Down Expand Up @@ -73,22 +70,30 @@ async function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse
if (args.body instanceof FormData) {
// @ts-expect-error
body = args.body;
} else if (args.body instanceof Uint8Array) {
body = args.body;
} else {
body = JSON.stringify(args.body);
}

// In Node.js environments, the SDK always uses`node-fetch`.
// If not in Node.js the SDK uses global fetch if available,
// and falls back to node-fetch.
const fetchFn =
RUNTIME.type === "node" ? require("node-fetch") : typeof fetch == "function" ? fetch : require("node-fetch");

const makeRequest = async (): Promise<Response> => {
const controller = new AbortController();
let abortId = undefined;
if (args.timeoutMs != null) {
abortId = setTimeout(() => controller.abort(), args.timeoutMs);
}
const response = await fetch(url, {
const response = await fetchFn(url, {
method: args.method,
headers,
body,
signal: controller.signal,
credentials: args.withCredentials ? "same-origin" : undefined,
credentials: args.withCredentials ? "include" : undefined,
});
if (abortId != null) {
clearTimeout(abortId);
Expand Down Expand Up @@ -119,18 +124,21 @@ async function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse
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 (err) {
return {
ok: false,
error: {
reason: "non-json",
statusCode: response.status,
rawBody: await response.text(),
},
};
} else {
const text = await response.text();
if (text.length > 0) {
try {
body = JSON.parse(text);
} catch (err) {
return {
ok: false,
error: {
reason: "non-json",
statusCode: response.status,
rawBody: text,
},
};
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./fetcher";
export * from "./runtime";
export * as serialization from "./schemas";
1 change: 1 addition & 0 deletions src/core/runtime/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { RUNTIME } from "./runtime";
112 changes: 112 additions & 0 deletions src/core/runtime/runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
interface DenoGlobal {
version: {
deno: string;
};
}

interface BunGlobal {
version: string;
}

declare const Deno: DenoGlobal;
declare const Bun: BunGlobal;

/**
* A constant that indicates whether the environment the code is running is a Web Browser.
*/
const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";

/**
* A constant that indicates whether the environment the code is running is a Web Worker.
*/
const isWebWorker =
typeof self === "object" &&
// @ts-ignore
typeof self?.importScripts === "function" &&
(self.constructor?.name === "DedicatedWorkerGlobalScope" ||
self.constructor?.name === "ServiceWorkerGlobalScope" ||
self.constructor?.name === "SharedWorkerGlobalScope");

/**
* A constant that indicates whether the environment the code is running is Deno.
*/
const isDeno =
typeof Deno !== "undefined" && typeof Deno.version !== "undefined" && typeof Deno.version.deno !== "undefined";

/**
* A constant that indicates whether the environment the code is running is Bun.sh.
*/
const isBun = typeof Bun !== "undefined" && typeof Bun.version !== "undefined";

/**
* A constant that indicates whether the environment the code is running is Node.JS.
*/
const isNode =
typeof process !== "undefined" &&
Boolean(process.version) &&
Boolean(process.versions?.node) &&
// Deno spoofs process.versions.node, see https://deno.land/std@0.177.0/node/process.ts?s=versions
!isDeno &&
!isBun;

/**
* A constant that indicates whether the environment the code is running is in React-Native.
* https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js
*/
const isReactNative = typeof navigator !== "undefined" && navigator?.product === "ReactNative";

/**
* A constant that indicates which environment and version the SDK is running in.
*/
export const RUNTIME: Runtime = evaluateRuntime();

export interface Runtime {
type: "browser" | "web-worker" | "deno" | "bun" | "node" | "react-native" | "unknown";
version?: string;
}

function evaluateRuntime(): Runtime {
if (isBrowser) {
return {
type: "browser",
version: window.navigator.userAgent,
};
}

if (isWebWorker) {
return {
type: "web-worker",
};
}

if (isDeno) {
return {
type: "deno",
version: Deno.version.deno,
};
}

if (isBun) {
return {
type: "bun",
version: Bun.version,
};
}

if (isNode) {
return {
type: "node",
version: process.versions.node,
};
}

if (isReactNative) {
return {
type: "react-native",
};
}

return {
type: "unknown",
};
}
11 changes: 11 additions & 0 deletions tests/client.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* This is a test file for the SDK.
*
* Add any tests here and make sure to mark this file
* in `.fernignore`.
*/
describe("test", () => {
it("default", () => {
expect(true).toBe(true);
});
});
Loading

0 comments on commit 4091a52

Please sign in to comment.