Skip to content

Commit

Permalink
chore(deps): Update all deps and tsconfig (#204)
Browse files Browse the repository at this point in the history
update deps and tsconfig
  • Loading branch information
jimmycallin authored Feb 13, 2024
1 parent 5590451 commit 99d6d72
Show file tree
Hide file tree
Showing 21 changed files with 605 additions and 1,354 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ build/
dist/
package.tgz
.eggs/
tsconfig.tsbuildinfo

# Yarn
.pnp.*
Expand All @@ -60,3 +61,4 @@ package.tgz
!.yarn/sdks
!.yarn/versions
.DS_Store

28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@
"dist"
],
"devDependencies": {
"@types/uuid": "^9.0.6",
"@types/uuid": "^9.0.8",
"cross-fetch": "^4.0.0",
"dayjs": "^1.11.10",
"eslint": "^8.51.0",
"eslint": "^8.56.0",
"eslint-config-react-app": "^7.0.1",
"husky": "^8.0.3",
"jsdom": "^23.0.0",
"lint-staged": "^15.0.2",
"msw": "^1.3.2",
"husky": "^9.0.10",
"jsdom": "^24.0.0",
"lint-staged": "^15.2.2",
"msw": "^2.2.0",
"pinst": "^3.0.0",
"prettier": "^3.0.3",
"typescript": "^5.2.2",
"vite": "^4.5.0",
"vite-plugin-dts": "^3.6.0",
"vitest": "^0.34.6",
"ws": "^8.14.2"
"prettier": "^3.2.5",
"typescript": "^5.3.3",
"vite": "^5.1.1",
"vite-plugin-dts": "^3.7.2",
"vitest": "^1.2.2",
"ws": "^8.16.0"
},
"repository": {
"type": "git",
Expand All @@ -59,8 +59,8 @@
"homepage": "http://ftrack.com",
"dependencies": {
"isomorphic-ws": "^5.0.0",
"loglevel": "^1.8.1",
"moment": "^2.29.4",
"loglevel": "^1.9.1",
"moment": "^2.30.1",
"uuid": "^9.0.1"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion source/event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// :copyright: Copyright (c) 2016 ftrack
import { v4 as uuidV4 } from "uuid";
import { EventSource } from "./event_hub.js";
import type { EventSource } from "./event_hub.js";
/**
* ftrack API Event class.
*/
Expand Down
2 changes: 1 addition & 1 deletion source/event_hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
EventServerPublishError,
NotUniqueError,
} from "./error.js";
import { Data } from "./types.js";
import type { Data } from "./types.js";

interface BaseActionData {
selection: Array<{
Expand Down
2 changes: 1 addition & 1 deletion source/project_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import * as operation from "./operation.js";
import { Session } from "./session.js";
import { Data, QueryResponse } from "./types.js";
import type { Data, QueryResponse } from "./types.js";
/**
* Project schema namespace
* @namespace project_schema
Expand Down
2 changes: 1 addition & 1 deletion source/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SERVER_LOCATION_ID } from "./constant.js";
import { CreateComponentError } from "./error.js";
import { Session } from "./session.js";
import { v4 as uuidV4 } from "uuid";
import {
import type {
CreateComponentOptions,
CreateResponse,
GetUploadMetadataResponse,
Expand Down
2 changes: 1 addition & 1 deletion source/util/convert_to_iso_string.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Moment } from "moment";
import type { Moment } from "moment";
import type dayjs from "dayjs";

/**
Expand Down
2 changes: 1 addition & 1 deletion source/util/get_schema_mapping.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// :copyright: Copyright (c) 2023 ftrack

import { Schema } from "../types.js";
import type { Schema } from "../types.js";

export default function getSchemaMappingFromSchemas(schemas: Schema[]) {
const schemaMapping = {} as Record<string, Schema>;
Expand Down
2 changes: 1 addition & 1 deletion test/back_off.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// :copyright: Copyright (c) 2023 ftrack
import { backOff } from "../source/util/back_off";
import { backOff } from "../source/util/back_off.js";
import { describe, it, expect } from "vitest";

describe("backOff", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/convert_to_iso_string.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// :copyright: Copyright (c) 2022 ftrack

import { convertToIsoString } from "../source/util/convert_to_iso_string";
import { convertToIsoString } from "../source/util/convert_to_iso_string.js";
import moment from "moment";
import dayjs from "dayjs";
import { describe, it, expect } from "vitest";
Expand Down
7 changes: 6 additions & 1 deletion test/event.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// :copyright: Copyright (c) 2023 ftrack

import { Event } from "../source/event";
import { Event } from "../source/event.js";
import { describe, expect, it } from "vitest";

describe("Event class", () => {
Expand All @@ -26,6 +26,7 @@ describe("Event class", () => {
);
const data = event.getData();
expect(data.target).toBe("sampleTarget");
// @ts-expect-error TODO: Type should be able to be defined with custom properties
expect(data.customOption).toBe("customValue");
});

Expand Down Expand Up @@ -56,6 +57,7 @@ describe("Event class", () => {
describe("prepareSource Method", () => {
it("should prepare and add source to event data", () => {
const event = new Event("testTopic", { key: "value" });
// @ts-expect-error TODO: Type should be able to be defined with custom properties
event.prepareSource({ newKey: "newValue" });
const data = event.getData();
expect(data.source).toEqual({ newKey: "newValue" });
Expand All @@ -67,6 +69,7 @@ describe("Event class", () => {
{ key: "value" },
{ source: { oldKey: "oldValue" } },
);
// @ts-expect-error TODO: Type should be able to be defined with custom properties
event.prepareSource({ oldKey: "newValue", newKey: "newValue" });
const data = event.getData();
expect(data.source).toEqual({
Expand All @@ -80,6 +83,7 @@ describe("Event class", () => {
{ key: "value" },
{ source: undefined },
);
// @ts-expect-error TODO: Type should be able to be defined with custom properties
event.prepareSource({ newKey: "newValue" });
const data = event.getData();
expect(data.source).toEqual({
Expand All @@ -88,6 +92,7 @@ describe("Event class", () => {
});
it("Prepare should handle source null", () => {
const event = new Event("testTopic", { key: "value" }, { source: null });
// @ts-expect-error TODO: Type should be able to be defined with custom properties
event.prepareSource({ newKey: "newValue" });
const data = event.getData();
expect(data.source).toEqual({
Expand Down
10 changes: 5 additions & 5 deletions test/event_hub.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { EventHub } from "../source/event_hub";
import { Event } from "../source/event";
import { EventHub } from "../source/event_hub.js";
import { Event } from "../source/event.js";
import { vi, describe, expect, beforeEach, afterEach, test } from "vitest";

describe("EventHub", () => {
let eventHub;
let eventHub: any;

beforeEach(() => {
eventHub = new EventHub("", "", "");
Expand Down Expand Up @@ -245,7 +245,7 @@ test("EventHub constructor", async () => {
// Scenario 1
const eventHub1 = new EventHub("https://ftrack.test", "testUser", "testKey", {
applicationId: "custom.app.id",
});
}) as any;

// Check instance properties for scenario 1
expect(eventHub1._applicationId).toBe("custom.app.id");
Expand All @@ -259,7 +259,7 @@ test("EventHub constructor", async () => {
"http://ftrack.test:8080",
"testUser",
"testKey",
);
) as any;

// Check instance properties for scenario 2
expect(eventHub2._applicationId).toBe("ftrack.api.javascript");
Expand Down
2 changes: 1 addition & 1 deletion test/get_chunk_size.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// :copyright: Copyright (c) 2023 ftrack
import { getChunkSize } from "../source/util/get_chunk_size";
import { getChunkSize } from "../source/util/get_chunk_size.js";
import { describe, expect, it } from "vitest";

describe("getChunkSize", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/normalize_string.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// :copyright: Copyright (c) 2019 ftrack
import normalizeString from "../source/util/normalize_string";
import normalizeString from "../source/util/normalize_string.js";
import { describe, it, expect } from "vitest";

describe("Normalize string", () => {
Expand Down
71 changes: 39 additions & 32 deletions test/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// :copyright: Copyright (c) 2022 ftrack
import { rest } from "msw";
import { HttpResponse, type PathParams, http, HttpHandler } from "msw";
import fs from "fs/promises";
import querySchemas from "./fixtures/query_schemas.json";
import queryServerInformation from "./fixtures/query_server_information.json";
Expand All @@ -13,21 +13,23 @@ const InvalidCredentialsError = {
exception: "InvalidCredentialsError",
error_code: null,
};
function authenticate(req) {

function authenticate(info: Parameters<Parameters<typeof http.post>[1]>[0]) {
// allow returning invalid authentication by setting ftrack-api-key to "INVALID_API_KEY"
// otherwise, return true
if (req.headers.get("ftrack-api-key") === "INVALID_API_KEY") {
if (info.request.headers.get("ftrack-api-key") === "INVALID_API_KEY") {
return false;
}
return true;
}
function pick(object, keys) {

function pick<T>(object: T, keys: (keyof T)[]) {
return keys.reduce((obj, key) => {
if (object && object.hasOwnProperty(key)) {
obj[key] = object[key];
}
return obj;
}, {});
}, {} as T);
}

export function getInitialSessionQuery() {
Expand All @@ -38,13 +40,21 @@ export function getExampleQuery() {
return [exampleQuery];
}

export const handlers = [
rest.post("http://ftrack.test/api", async (req, res, ctx) => {
if (!authenticate(req)) {
return res(ctx.json(InvalidCredentialsError));
// Get socket io session id
const handleSocketIORequest: Parameters<typeof http.get>[1] = (info) => {
if (!authenticate(info)) {
return HttpResponse.json(InvalidCredentialsError);
}
return HttpResponse.text("1234567890:"); // The returned session ID has a colon and then some other information at the end. This only has the colon, to check that the colon is removed.
};

export const handlers: HttpHandler[] = [
http.post<PathParams, any[]>("http://ftrack.test/api", async (info) => {
if (!authenticate(info)) {
return HttpResponse.json(InvalidCredentialsError);
}
const body = await Promise.all(
(await req.json()).map(
(await info.request.json()).map(
async ({
action,
expression,
Expand Down Expand Up @@ -108,35 +118,32 @@ export const handlers = [
},
),
);
return res(ctx.json(body));
return HttpResponse.json(body);
}),
rest.options("http://ftrack.test/file-url", async (req, res, ctx) => {
return res(
ctx.status(200),
ctx.set("Access-Control-Allow-Origin", "*"),
ctx.body("file"),
);
http.options("http://ftrack.test/file-url", async () => {
return new Response("file", {
status: 200,
headers: {
"Access-Control-Allow-Origin": "*",
},
});
}),
rest.put("http://ftrack.test/file-url", async (req, res, ctx) => {
return res(ctx.status(200), ctx.set("Access-Control-Allow-Origin", "*"));
http.put("http://ftrack.test/file-url", async (info) => {
return new Response(null, {
status: 200,
headers: { "Access-Control-Allow-Origin": "*" },
});
}),
// Get socket io session id
rest.get("https://ftrack.test/socket.io/1/", handleSocketIORequest),
rest.get("http://ftrack.test/socket.io/1/", handleSocketIORequest),
rest.get("https://ftrack.test/*", (req, res, ctx) => {
return res(ctx.status(200));
http.get("https://ftrack.test/socket.io/1/", handleSocketIORequest),
http.get("http://ftrack.test/socket.io/1/", handleSocketIORequest),
http.get("https://ftrack.test/*", (info) => {
return new Response(null, { status: 200 });
}),

rest.get("http://ftrack.test:8080/*", (req, res, ctx) => {
return res(ctx.status(200));
http.get("http://ftrack.test:8080/*", (info) => {
return new Response(null, { status: 200 });
}),
];
// Get socket io session id
function handleSocketIORequest(req, res, ctx) {
if (!authenticate(req)) {
return ctx.json(InvalidCredentialsError);
}
return res(ctx.text("1234567890:")); // The returned session ID has a colon and then some other information at the end. This only has the colon, to check that the colon is removed.
}

export const server = setupServer(...handlers);
Loading

0 comments on commit 99d6d72

Please sign in to comment.