diff --git a/package.json b/package.json index 5a51c459..f77131d9 100644 --- a/package.json +++ b/package.json @@ -94,8 +94,7 @@ }, "dependencies": { "@swc/helpers": "^0.3.13", - "@whereby/jslib-media": "whereby/jslib-media.git#1.3.6", - "assert": "^2.0.0", + "@whereby/jslib-media": "whereby/jslib-media.git#1.4.1", "axios": "^1.2.3", "btoa": "^1.2.1", "events": "^3.3.0", diff --git a/src/lib/api/ApiClient.ts b/src/lib/api/ApiClient.ts index c152d06b..630319b0 100644 --- a/src/lib/api/ApiClient.ts +++ b/src/lib/api/ApiClient.ts @@ -1,5 +1,5 @@ -import assert from "assert"; import nodeBtoa from "btoa"; +import assert from "@whereby/jslib-media/src/utils/assert"; import HttpClient, { HttpClientRequestConfig } from "./HttpClient"; import MultipartHttpClient from "./MultipartHttpClient"; import { assertString } from "./parameterAssertUtils"; @@ -74,9 +74,6 @@ export default class ApiClient { baseUrl = "https://api.appearin.net", fetchDeviceCredentials = noCredentials, }: ApiClientOptions = {}) { - assertString(baseUrl, "baseUrl"); - assert.ok(typeof fetchDeviceCredentials === "function", "fetchDeviceCredentials is required"); - this.authenticatedHttpClient = new AuthenticatedHttpClient({ httpClient: new HttpClient({ baseUrl, @@ -92,7 +89,7 @@ export default class ApiClient { */ request(url: string, options: HttpClientRequestConfig): Promise { assertString(url, "url"); - assert.equal(url[0], "/", 'url only accepts relative URLs beginning with "/".'); + assert.ok(url[0] === "/", 'url only accepts relative URLs beginning with "/".'); assert.ok(options, "options are required"); return this.authenticatedHttpClient.request(url, options); @@ -103,7 +100,7 @@ export default class ApiClient { */ requestMultipart(url: string, options: HttpClientRequestConfig): Promise { assertString(url, "url"); - assert.equal(url[0], "/", 'url only accepts relative URLs beginning with "/".'); + assert.ok(url[0] === "/", 'url only accepts relative URLs beginning with "/".'); assert.ok(options, "options are required"); return this.authenticatedFormDataHttpClient.request(url, options); diff --git a/src/lib/api/HttpClient.ts b/src/lib/api/HttpClient.ts index c6cd77d7..61de1a60 100644 --- a/src/lib/api/HttpClient.ts +++ b/src/lib/api/HttpClient.ts @@ -1,4 +1,4 @@ -import assert from "assert"; +import assert from "@whereby/jslib-media/src/utils/assert"; import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios"; import Response, { ErrorResponseObject } from "./Response"; import { assertString } from "./parameterAssertUtils"; @@ -10,7 +10,6 @@ export interface IHttpClient { } function _getAbsoluteUrl({ baseUrl, url }: { baseUrl?: string; url: string }): string { - assert.ok(typeof url === "string", "url is required"); return baseUrl ? baseUrl + url : url; } @@ -50,7 +49,7 @@ export default class HttpClient implements IHttpClient { */ request(url: string, options: HttpClientRequestConfig): Promise { assertString(url, "url"); - assert.equal(url[0], "/", 'url only accepts relative URLs beginning with "/".'); + assert.ok(url[0] === "/", 'url only accepts relative URLs beginning with "/".'); assert.ok(options, "options are required"); return this._requestAxios(url, options) diff --git a/src/lib/api/MultipartHttpClient.ts b/src/lib/api/MultipartHttpClient.ts index f6adae75..d2e54203 100644 --- a/src/lib/api/MultipartHttpClient.ts +++ b/src/lib/api/MultipartHttpClient.ts @@ -1,4 +1,4 @@ -import assert from "assert"; +import assert from "@whereby/jslib-media/src/utils/assert"; import { HttpClientRequestConfig, IHttpClient } from "./HttpClient"; import Response from "./Response"; diff --git a/src/lib/api/OrganizationApiClient.ts b/src/lib/api/OrganizationApiClient.ts index b886147e..f4e28342 100644 --- a/src/lib/api/OrganizationApiClient.ts +++ b/src/lib/api/OrganizationApiClient.ts @@ -1,5 +1,5 @@ +import assert from "@whereby/jslib-media/src/utils/assert"; import ApiClient from "./ApiClient"; -import assert from "assert"; import { assertString } from "./parameterAssertUtils"; import { HttpClientRequestConfig } from "./HttpClient"; import Response from "./Response"; @@ -18,8 +18,9 @@ export default class OrganizationApiClient { /** * Create an OrganizationApiClient instance. * - * @param {ApiClient} [apiClient] - The apiClient to use. - * @param {Function} [fetchOrganization] - function that returns a promise with the organization. + * @param {Object} options - The options for the OrganizationApiClient. + * @param {ApiClient} [options.apiClient] - The apiClient to use. + * @param {Function} [options.fetchOrganization] - function that returns a promise with the organization. */ constructor({ apiClient, @@ -29,8 +30,6 @@ export default class OrganizationApiClient { fetchOrganization?: FetchOrganizationFunction; }) { this._apiClient = apiClient; - assert.ok(typeof fetchOrganization === "function", "fetchOrganization is required"); - this._fetchOrganization = fetchOrganization; this._apiClient = apiClient; } @@ -41,7 +40,7 @@ export default class OrganizationApiClient { options: HttpClientRequestConfig ): Promise { assertString(url, "url"); - assert.equal(url[0], "/", 'url only accepts relative URLs beginning with "/".'); + assert.ok(url[0] === "/", 'url only accepts relative URLs beginning with "/".'); assert.ok(options, "options are required"); return this._fetchOrganization().then((organization) => { if (!organization) { diff --git a/src/lib/api/models/Room.ts b/src/lib/api/models/Room.ts index cd2cd66d..23935651 100644 --- a/src/lib/api/models/Room.ts +++ b/src/lib/api/models/Room.ts @@ -1,5 +1,5 @@ // @ts-nocheck -import assert from "assert"; +import assert from "@whereby/jslib-media/src/utils/assert"; export default class Room { public readonly isLocked: boolean; diff --git a/src/lib/api/organizationService/index.ts b/src/lib/api/organizationService/index.ts index 4894cf27..fd688e5f 100644 --- a/src/lib/api/organizationService/index.ts +++ b/src/lib/api/organizationService/index.ts @@ -1,4 +1,4 @@ -import assert from "assert"; +import assert from "@whereby/jslib-media/src/utils/assert"; import Organization, { OrganizationPreferences } from "../models/Organization"; import { assertInstanceOf, diff --git a/src/lib/api/parameterAssertUtils.ts b/src/lib/api/parameterAssertUtils.ts index e9f9a7d6..a3dffbb1 100644 --- a/src/lib/api/parameterAssertUtils.ts +++ b/src/lib/api/parameterAssertUtils.ts @@ -1,4 +1,4 @@ -import assert from "assert"; +import assert from "@whereby/jslib-media/src/utils/assert"; /** * Asserts that value is truthy. @@ -65,7 +65,7 @@ export function assertInstanceOf(value: unknown, type: new (any: unknown) => */ export function assertRoomName(roomName: unknown, parameterName = "roomName"): string { assertString(roomName, parameterName); - assert.equal(typeof roomName === "string" && roomName[0], "/", `${parameterName} must begin with a '/'`); + assert.ok(typeof roomName === "string" && roomName[0] === "/", `${parameterName} must begin with a '/'`); return roomName as string; } diff --git a/src/lib/api/test/ApiClient.spec.ts b/src/lib/api/test/ApiClient.spec.ts index 69ccd4e2..a4b9c3c2 100644 --- a/src/lib/api/test/ApiClient.spec.ts +++ b/src/lib/api/test/ApiClient.spec.ts @@ -16,11 +16,6 @@ describe("ApiClient", () => { it("should not throw an error if no constructor params are passed through", () => { expect(() => new ApiClient()).not.toThrowError(); }); - - //@ts-expect-error - itShouldThrowIfInvalid("baseUrl", () => new ApiClient({ baseUrl: null })); - //@ts-expect-error - itShouldThrowIfInvalid("fetchDeviceCredentials", () => new ApiClient({ fetchDeviceCredentials: null })); }); describe("request", () => { @@ -48,9 +43,6 @@ describe("ApiClient", () => { expect(() => apiClient.request("some-url", {})).toThrowError(); }); - //@ts-expect-error - itShouldThrowIfInvalid("fetchDeviceCredentials", () => new ApiClient({ fetchDeviceCredentials: null })); - it("should run `this.fetchDeviceCredentials`", () => { const url = "/some/path"; const fetchOptions = {}; diff --git a/src/lib/api/test/extractUtils.spec.ts b/src/lib/api/test/extractUtils.spec.ts index 089c8656..576b1fb7 100644 --- a/src/lib/api/test/extractUtils.spec.ts +++ b/src/lib/api/test/extractUtils.spec.ts @@ -13,7 +13,7 @@ import { nullOrTransform, Transformer, } from "../extractUtils"; -import assert from "assert"; +import assert from "@whereby/jslib-media/src/utils/assert"; import { Json } from "../Response"; import { assertString } from "../parameterAssertUtils"; type User = { name: string; eyeColor: string | null; age: number; dob: Date }; diff --git a/src/lib/api/test/parameterAssertUtils.spec.ts b/src/lib/api/test/parameterAssertUtils.spec.ts index 406f5be9..9764f6ae 100644 --- a/src/lib/api/test/parameterAssertUtils.spec.ts +++ b/src/lib/api/test/parameterAssertUtils.spec.ts @@ -1,4 +1,3 @@ -import assert from "assert"; import { assertBoolean, assertRoomName, @@ -13,8 +12,6 @@ function forEachObject(object: Record, func: (value: unknown, k } describe("parameterAssertUtils", () => { function itShouldThrowForValues(testValues: Record, test: (desc: string, value: unknown) => void) { - assert.ok(typeof test === "function", "test must be a function"); - forEachObject(testValues, (value, descriptionOfValue) => { it(`should throw for ${descriptionOfValue}`, () => { test(descriptionOfValue, value); diff --git a/src/lib/utils/__tests__/debounce.spec.ts b/src/lib/utils/__tests__/debounce.spec.ts index d06fe93e..78fd14ae 100644 --- a/src/lib/utils/__tests__/debounce.spec.ts +++ b/src/lib/utils/__tests__/debounce.spec.ts @@ -16,13 +16,6 @@ describe("debounce", () => { jest.clearAllMocks(); }); - it("should throw if no function is provided", () => { - expect(() => { - // @ts-expect-error - debounce(); - }).toThrow("fn is required"); - }); - it("should set the timer with the specified delay", () => { const delay = Math.floor(Math.random() * 2000); diff --git a/src/lib/utils/debounce.ts b/src/lib/utils/debounce.ts index e0be769e..6f86037d 100644 --- a/src/lib/utils/debounce.ts +++ b/src/lib/utils/debounce.ts @@ -1,5 +1,3 @@ -import assert from "assert"; - interface Options { delay?: number; edges?: boolean; @@ -21,8 +19,6 @@ interface DebouncedFunction { * @returns {Function} Debounced function. */ export default function debounce(fn: DebouncedFunction, { delay = 500, edges }: Options = {}): DebouncedFunction { - assert.ok(typeof fn === "function", "fn is required"); - let timeout: NodeJS.Timeout | undefined; let nCalls = 0; diff --git a/src/types.d.ts b/src/types.d.ts index 66379be1..0c5d617b 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -82,6 +82,16 @@ declare module "@whereby/jslib-media/src/webrtc/RtcManager" { } } +declare const assert: { + (value: unknown, message?: string | Error): asserts value; + ok(value: unknown, message?: string | Error): asserts value; + notEqual(actual: T, expected: T, message: string): void; +}; + +declare module "@whereby/jslib-media/src/utils/assert" { + export = assert; +} + declare module "@whereby/jslib-media/src/utils/urls" { export function fromLocation({ host }: { host: string }): { subdomain: string }; } diff --git a/yarn.lock b/yarn.lock index 6ed3751e..d81f335c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3581,11 +3581,10 @@ "@webassemblyjs/ast" "1.11.6" "@xtuc/long" "4.2.2" -"@whereby/jslib-media@whereby/jslib-media.git#1.3.6": - version "1.3.6" - resolved "https://codeload.github.com/whereby/jslib-media/tar.gz/bc8f3efd48e9e5b23b886bc8ea181b33f1d62719" +"@whereby/jslib-media@whereby/jslib-media.git#1.4.1": + version "1.4.1" + resolved "https://codeload.github.com/whereby/jslib-media/tar.gz/abc55b7e2d3af9c71cb3f3a2953291bb79725064" dependencies: - assert "^2.0.0" events "^3.3.0" mediasoup-client "3.6.100" rtcstats "github:whereby/rtcstats#v5.3.0"