Skip to content

Commit

Permalink
Node20 support (#43)
Browse files Browse the repository at this point in the history
Update server imports to nodeNext. Downgrade compile target to node 16
  • Loading branch information
sdumetz authored Oct 23, 2023
1 parent eb080c9 commit 1d01e09
Show file tree
Hide file tree
Showing 86 changed files with 894 additions and 263 deletions.
2 changes: 1 addition & 1 deletion source/server/auth/User.test.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import User from "./User";
import User from "./User.js";
import {expect} from "chai";
10 changes: 5 additions & 5 deletions source/server/auth/UserManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import UserManager, { AccessTypes } from "./UserManager";
import UserManager, { AccessTypes } from "./UserManager.js";
import {tmpdir} from "os";
import fs from "fs/promises";
import path from "path";

import {expect} from "chai";
import { BadRequestError, NotFoundError, UnauthorizedError } from "../utils/errors";
import User from "./User";
import openDatabase from "../vfs/helpers/db";
import { Uid } from "../utils/uid";
import { BadRequestError, NotFoundError, UnauthorizedError } from "../utils/errors.js";
import User from "./User.js";
import openDatabase from "../vfs/helpers/db.js";
import { Uid } from "../utils/uid.js";

describe("UserManager static methods", function(){
describe("parsePassword()", function(){
Expand Down
8 changes: 4 additions & 4 deletions source/server/auth/UserManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import crypto from "crypto";
import path from "path";
import {promisify, callbackify} from "util";

import uid, { Uid } from "../utils/uid";
import { BadRequestError, InternalError, NotFoundError, UnauthorizedError } from "../utils/errors";
import User, {SafeUser, StoredUser} from "./User";
import uid, { Uid } from "../utils/uid.js";
import { BadRequestError, InternalError, NotFoundError, UnauthorizedError } from "../utils/errors.js";
import User, {SafeUser, StoredUser} from "./User.js";

import openDatabase, {Database, DbOptions} from "../vfs/helpers/db";
import openDatabase, {Database, DbOptions} from "../vfs/helpers/db.js";


const scrypt :(
Expand Down
4 changes: 2 additions & 2 deletions source/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/

import path from "path";
import createServer from "./server";
import config from "./utils/config";
import createServer from "./server.js";
import config from "./utils/config.js";

//@ts-ignore
import("source-map-support").then((s)=>{
Expand Down
16 changes: 9 additions & 7 deletions source/server/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import fs from "fs/promises";
import path from "path";
import { fileURLToPath } from 'url';
import {tmpdir} from "os";

import request from "supertest";
import createServer from "./server";
import Vfs, { DocProps, WriteFileParams } from "./vfs";
import User from "./auth/User";
import createServer from "./server.js";
import Vfs, { DocProps, WriteFileParams } from "./vfs/index.js";
import User from "./auth/User.js";
import { Element, xml2js } from "xml-js";
import UserManager from "./auth/UserManager";

import UserManager from "./auth/UserManager.js";

const thisDir = path.dirname(fileURLToPath(import.meta.url));

describe("Web Server Integration", function(){
let vfs :Vfs, userManager :UserManager, user :User, admin :User;
Expand Down Expand Up @@ -71,10 +72,11 @@ describe("Web Server Integration", function(){
});

it("can create a new scene", async function(){
let content = await fs.readFile(path.join(__dirname, "__test_fixtures/cube.glb"));
let content = await fs.readFile(path.join(thisDir, "__test_fixtures/cube.glb"));
let r = await this.agent.post("/api/v1/scenes/bar")
.set("Content-Type", "application/octet-stream")
.send(content)
.expect(201);
let res = await this.agent.get("/scenes/bar/models/bar.glb").expect(200);
expect(res.text.slice(0,4).toString()).to.equal("glTF");
expect(res.text.length).to.equal(content.length);
Expand All @@ -84,7 +86,7 @@ describe("Web Server Integration", function(){
});

it("can upload a glb model in an existing scene", async function(){
let content = await fs.readFile(path.join(__dirname, "__test_fixtures/cube.glb"));
let content = await fs.readFile(path.join(thisDir, "__test_fixtures/cube.glb"));
await this.agent.put("/scenes/foo/models/baz.glb")
.send(content)
.expect(201);
Expand Down
5 changes: 3 additions & 2 deletions source/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"version": "0.0.1",
"description": "eThesaurus application, based on Smithsonian DPO Voyager - 3D Explorer and Tool Suite",
"public": false,
"type": "module",
"scripts": {
"start": "ROOT_DIR=\"$(pwd)/../..\" node ./dist/server/index.js",
"test": "mocha",
"test": "NODE_NO_WARNINGS=1 mocha",
"build": "tsc -b ."
},
"nodemonConfig": {
Expand Down Expand Up @@ -65,7 +66,7 @@
"supertest": "^6.3.3",
"webpack-dev-middleware": "^6.1.1"
},
"overrides":{
"overrides": {
"webpack-dev-middleware": {
"webpack": "^5.88.1"
}
Expand Down
42 changes: 21 additions & 21 deletions source/server/routes/api/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@

import path from "path";
import { Router } from "express";
import User from "../../../auth/User";
import UserManager from "../../../auth/UserManager";
import { BadRequestError } from "../../../utils/errors";
import { canAdmin, canRead, getUserManager, isAdministrator, isAdministratorOrOpen, isUser } from "../../../utils/locals";
import wrap from "../../../utils/wrapAsync";
import User from "../../../auth/User.js";
import UserManager from "../../../auth/UserManager.js";
import { BadRequestError } from "../../../utils/errors.js";
import { canAdmin, canRead, getUserManager, isAdministrator, isAdministratorOrOpen, isUser } from "../../../utils/locals.js";
import wrap from "../../../utils/wrapAsync.js";
import bodyParser from "body-parser";
import { getLogin, getLoginLink, sendLoginLink, postLogin } from "./login";
import { postLogout } from "./logout";
import postScene from "./scenes/scene/post";
import getScenes from "./scenes/get";
import getSceneHistory from "./scenes/scene/history/get";
import getFiles from "./scenes/scene/files/get";
import { getLogin, getLoginLink, sendLoginLink, postLogin } from "./login.js";
import { postLogout } from "./logout.js";
import postScene from "./scenes/scene/post.js";
import getScenes from "./scenes/get.js";
import getSceneHistory from "./scenes/scene/history/get.js";
import getFiles from "./scenes/scene/files/get.js";

import getScene from "./scenes/scene/get";
import getPermissions from "./scenes/scene/permissions/get";
import patchPermissions from "./scenes/scene/permissions/patch";
import postUser from "./users/post";
import handleDeleteUser from "./users/uid/delete";
import { handlePatchUser } from "./users/uid/patch";
import { postSceneHistory } from "./scenes/scene/history/post";
import handleGetStats from "./stats";
import postScenes from "./scenes/post";
import patchScene from "./scenes/scene/patch";
import getScene from "./scenes/scene/get.js";
import getPermissions from "./scenes/scene/permissions/get.js";
import patchPermissions from "./scenes/scene/permissions/patch.js";
import postUser from "./users/post.js";
import handleDeleteUser from "./users/uid/delete.js";
import { handlePatchUser } from "./users/uid/patch.js";
import { postSceneHistory } from "./scenes/scene/history/post.js";
import handleGetStats from "./stats/index.js";
import postScenes from "./scenes/post.js";
import patchScene from "./scenes/scene/patch.js";



Expand Down
6 changes: 3 additions & 3 deletions source/server/routes/api/v1/login.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import request from "supertest";
import Vfs from "../../../vfs";
import User from "../../../auth/User";
import UserManager from "../../../auth/UserManager";
import Vfs from "../../../vfs/index.js";
import User from "../../../auth/User.js";
import UserManager from "../../../auth/UserManager.js";



Expand Down
10 changes: 5 additions & 5 deletions source/server/routes/api/v1/login.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createHmac } from "crypto";
import { Request, RequestHandler, Response } from "express";
import User, { SafeUser } from "../../../auth/User";
import { BadRequestError, ForbiddenError, HTTPError } from "../../../utils/errors";
import { getHost, getUser, getUserManager } from "../../../utils/locals";
import sendmail from "../../../utils/mails/send";
import { recoverAccount } from "../../../utils/mails/templates";
import User, { SafeUser } from "../../../auth/User.js";
import { BadRequestError, ForbiddenError, HTTPError } from "../../../utils/errors.js";
import { getHost, getUser, getUserManager } from "../../../utils/locals.js";
import sendmail from "../../../utils/mails/send.js";
import { recoverAccount } from "../../../utils/mails/templates.js";
/**
*
* @type {RequestHandler}
Expand Down
10 changes: 5 additions & 5 deletions source/server/routes/api/v1/scenes/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {tmpdir} from "os";
import request from "supertest";
import { expect } from "chai";

import Vfs from "../../../../vfs";
import UserManager from "../../../../auth/UserManager";
import User from "../../../../auth/User";
import { HandleMock } from "../../../../utils/zip/zip.test";
import { read_cdh } from "../../../../utils/zip";
import Vfs from "../../../../vfs/index.js";
import UserManager from "../../../../auth/UserManager.js";
import User from "../../../../auth/User.js";
import { HandleMock } from "../../../../utils/zip/zip.test.js";
import { read_cdh } from "../../../../utils/zip/index.js";



Expand Down
10 changes: 5 additions & 5 deletions source/server/routes/api/v1/scenes/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import { createHash } from "crypto";
import { Request, Response } from "express";
import path from "path";
import { AccessType } from "../../../../auth/UserManager";
import { HTTPError } from "../../../../utils/errors";
import { getHost, getUser, getVfs } from "../../../../utils/locals";
import { wrapFormat } from "../../../../utils/wrapAsync";
import { ZipEntry, zip } from "../../../../utils/zip";
import { AccessType } from "../../../../auth/UserManager.js";
import { HTTPError } from "../../../../utils/errors.js";
import { getHost, getUser, getVfs } from "../../../../utils/locals.js";
import { wrapFormat } from "../../../../utils/wrapAsync.js";
import { ZipEntry, zip } from "../../../../utils/zip/index.js";

export default async function getScenes(req :Request, res :Response){
let vfs = getVfs(req);
Expand Down
6 changes: 3 additions & 3 deletions source/server/routes/api/v1/scenes/post.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import fs from "fs/promises";

import request from "supertest";

import Vfs from "../../../../vfs";
import UserManager from "../../../../auth/UserManager";
import { NotFoundError } from "../../../../utils/errors";
import Vfs from "../../../../vfs/index.js";
import UserManager from "../../../../auth/UserManager.js";
import { NotFoundError } from "../../../../utils/errors.js";

function binaryParser(res:request.Response, callback:(err:Error|null, data:Buffer)=>any) {
res.setEncoding('binary');
Expand Down
12 changes: 5 additions & 7 deletions source/server/routes/api/v1/scenes/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import path from "path";
import {once} from "events";

import { Request, Response } from "express";
import { getHost, getUser, getVfs } from "../../../../utils/locals";
import { wrapFormat } from "../../../../utils/wrapAsync";
import { zip } from "../../../../utils/zip";
import { Uid } from "../../../../utils/uid";
import { unzip } from "../../../../utils/zip";
import { HTTPError } from "../../../../utils/errors";
import { getHost, getUser, getVfs } from "../../../../utils/locals.js";
import { Uid } from "../../../../utils/uid.js";
import { unzip } from "../../../../utils/zip/index.js";
import { HTTPError } from "../../../../utils/errors.js";
import { createReadStream } from "fs";
import { getMimeType } from "../../../../utils/filetypes";
import { getMimeType } from "../../../../utils/filetypes.js";


interface ImportResults {
Expand Down
4 changes: 2 additions & 2 deletions source/server/routes/api/v1/scenes/scene/files/get.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import { Request, Response } from "express";
import toCsv from "../../../../../../utils/csv";
import { getVfs } from "../../../../../../utils/locals";
import toCsv from "../../../../../../utils/csv.js";
import { getVfs } from "../../../../../../utils/locals.js";



Expand Down
10 changes: 5 additions & 5 deletions source/server/routes/api/v1/scenes/scene/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {Readable} from "stream";
import request from "supertest";
import { expect } from "chai";

import Vfs from "../../../../../vfs";
import UserManager from "../../../../../auth/UserManager";
import User from "../../../../../auth/User";
import { read_cdh } from "../../../../../utils/zip";
import Vfs from "../../../../../vfs/index.js";
import UserManager from "../../../../../auth/UserManager.js";
import User from "../../../../../auth/User.js";
import { read_cdh } from "../../../../../utils/zip/index.js";

import { HandleMock } from "../../../../../utils/zip/zip.test";
import { HandleMock } from "../../../../../utils/zip/zip.test.js";

describe("GET /api/v1/scenes/:scene", function(){
let vfs:Vfs, userManager:UserManager, ids :number[];
Expand Down
8 changes: 4 additions & 4 deletions source/server/routes/api/v1/scenes/scene/get.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

import { Request, Response } from "express";
import path from "path";
import { getUserId, getVfs } from "../../../../../utils/locals";
import { wrapFormat } from "../../../../../utils/wrapAsync";
import { ZipEntry, zip } from "../../../../../utils/zip";
import { HTTPError } from "../../../../../utils/errors";
import { getUserId, getVfs } from "../../../../../utils/locals.js";
import { wrapFormat } from "../../../../../utils/wrapAsync.js";
import { ZipEntry, zip } from "../../../../../utils/zip/index.js";
import { HTTPError } from "../../../../../utils/errors.js";



Expand Down
6 changes: 3 additions & 3 deletions source/server/routes/api/v1/scenes/scene/history/get.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import request from "supertest";
import Vfs from "../../../../../../vfs";
import User from "../../../../../../auth/User";
import UserManager from "../../../../../../auth/UserManager";
import Vfs from "../../../../../../vfs/index.js";
import User from "../../../../../../auth/User.js";
import UserManager from "../../../../../../auth/UserManager.js";



Expand Down
2 changes: 1 addition & 1 deletion source/server/routes/api/v1/scenes/scene/history/get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { Request, Response } from "express";
import { getVfs } from "../../../../../../utils/locals";
import { getVfs } from "../../../../../../utils/locals.js";


export default async function getSceneHistory(req :Request, res :Response){
Expand Down
6 changes: 3 additions & 3 deletions source/server/routes/api/v1/scenes/scene/history/post.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import request from "supertest";
import Vfs from "../../../../../../vfs";
import User from "../../../../../../auth/User";
import UserManager from "../../../../../../auth/UserManager";
import Vfs from "../../../../../../vfs/index.js";
import User from "../../../../../../auth/User.js";
import UserManager from "../../../../../../auth/UserManager.js";
import { randomBytes } from "crypto";


Expand Down
6 changes: 3 additions & 3 deletions source/server/routes/api/v1/scenes/scene/history/post.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Request, Response } from "express";
import path from "path";
import { BadRequestError } from "../../../../../../utils/errors";
import { getUser, getVfs } from "../../../../../../utils/locals";
import { ItemEntry } from "../../../../../../vfs";
import { BadRequestError } from "../../../../../../utils/errors.js";
import { getUser, getVfs } from "../../../../../../utils/locals.js";
import { ItemEntry } from "../../../../../../vfs/index.js";


/**
Expand Down
4 changes: 2 additions & 2 deletions source/server/routes/api/v1/scenes/scene/patch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import request from "supertest";

import Vfs from "../../../../../vfs";
import UserManager from "../../../../../auth/UserManager";
import Vfs from "../../../../../vfs/index.js";
import UserManager from "../../../../../auth/UserManager.js";

describe("PATCH /api/v1/scenes/:scene", function(){
let vfs:Vfs, userManager:UserManager, ids :number[];
Expand Down
4 changes: 2 additions & 2 deletions source/server/routes/api/v1/scenes/scene/patch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { ConflictError } from "../../../../../utils/errors";
import { getUserId, getVfs } from "../../../../../utils/locals";
import { ConflictError } from "../../../../../utils/errors.js";
import { getUserId, getVfs } from "../../../../../utils/locals.js";
import { Request, Response } from "express";


Expand Down
4 changes: 2 additions & 2 deletions source/server/routes/api/v1/scenes/scene/permissions/get.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import { Request, Response } from "express";
import { BadRequestError } from "../../../../../../utils/errors";
import { getUserId, getUserManager } from "../../../../../../utils/locals";
import { BadRequestError } from "../../../../../../utils/errors.js";
import { getUserId, getUserManager } from "../../../../../../utils/locals.js";



Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { Request, Response } from "express";
import { getUserManager } from "../../../../../../utils/locals";
import { getUserManager } from "../../../../../../utils/locals.js";



Expand Down
Loading

0 comments on commit 1d01e09

Please sign in to comment.