Browse Source

Fix typescript errors and update depencies

master
Fabian Stamm 1 year ago
parent
commit
7c0d5949ab
  1. 2899
      package-lock.json
  2. 22
      package.json
  3. 2
      src/api/admin/client.ts
  4. 4
      src/api/admin/permission.ts
  5. 2
      src/api/admin/regcode.ts
  6. 4
      src/api/admin/user.ts
  7. 4
      src/api/client/permissions.ts
  8. 2
      src/api/internal/oauth.ts
  9. 5
      src/api/middlewares/client.ts
  10. 2
      src/api/middlewares/user.ts
  11. 8
      src/api/oauth/auth.ts
  12. 2
      src/api/oauth/jwt.ts
  13. 4
      src/api/user/login.ts
  14. 4
      src/database.ts

2899
package-lock.json generated

File diff suppressed because it is too large Load Diff

22
package.json

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
{
"name": "open_auth_service",
"version": "1.1.1",
"version": "1.1.2",
"main": "lib/index.js",
"author": "Fabian Stamm <dev@fabianstamm.de>",
"license": "MIT",
@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
"install-views_repo": "git submodule init && git submodule update && cd views_repo && npm install ",
"build-views_repo": "cd views_repo && npm run build",
"watch-views_repo": "cd views_repo && npm run dev",
"format": "prettier --write ."
"format": "prettier --write \"src/**\""
},
"pipelines": {
"install": [
@ -36,23 +36,23 @@ @@ -36,23 +36,23 @@
"@types/cookie-parser": "^1.4.2",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.3",
"@types/i18n": "^0.8.6",
"@types/i18n": "^0.12.0",
"@types/ini": "^1.3.30",
"@types/jsonwebtoken": "^8.3.8",
"@types/mongodb": "^3.5.2",
"@types/node": "^13.9.0",
"@types/node": "^14.14.14",
"@types/node-rsa": "^1.0.0",
"@types/qrcode": "^1.3.4",
"@types/speakeasy": "^2.0.5",
"@types/uuid": "^7.0.0",
"apidoc": "^0.20.0",
"@types/uuid": "^8.3.0",
"apidoc": "^0.25.0",
"concurrently": "^5.1.0",
"nodemon": "^2.0.2",
"prettier": "^2.0.5",
"typescript": "^3.8.3"
"typescript": "^4.1.3"
},
"dependencies": {
"@hibas123/config": "^1.1.0",
"@hibas123/config": "^1.1.1",
"@hibas123/nodelogging": "^2.1.4",
"@hibas123/nodeloggingserver_client": "^1.1.2",
"@hibas123/safe_mongo": "^1.6.1",
@ -63,8 +63,8 @@ @@ -63,8 +63,8 @@
"dotenv": "^8.2.0",
"express": "^4.17.1",
"handlebars": "^4.7.3",
"i18n": "^0.8.5",
"ini": "^1.3.5",
"i18n": "^0.13.2",
"ini": "^2.0.0",
"jsonwebtoken": "^8.5.1",
"moment": "^2.24.0",
"mongodb": "^3.5.4",
@ -74,6 +74,6 @@ @@ -74,6 +74,6 @@
"reflect-metadata": "^0.1.13",
"speakeasy": "^2.0.0",
"u2f": "^0.1.3",
"uuid": "^7.0.2"
"uuid": "^8.3.2"
}
}

2
src/api/admin/client.ts

@ -157,7 +157,7 @@ ClientRouter.route("/:id") @@ -157,7 +157,7 @@ ClientRouter.route("/:id")
true
),
promiseMiddleware(async (req, res) => {
let { id } = req.query;
let { id } = req.query as { [key: string]: string };
let client = await Client.findById(id);
if (!client)
throw new RequestError(

4
src/api/admin/permission.ts

@ -28,7 +28,7 @@ PermissionRoute.route("/") @@ -28,7 +28,7 @@ PermissionRoute.route("/")
promiseMiddleware(async (req, res) => {
let query = {};
if (req.query.client) {
query = { client: new ObjectID(req.query.client) };
query = { client: new ObjectID(req.query.client as string) };
}
let permissions = await Permission.find(query);
res.json(permissions);
@ -102,7 +102,7 @@ PermissionRoute.route("/") @@ -102,7 +102,7 @@ PermissionRoute.route("/")
*/
.delete(
promiseMiddleware(async (req, res) => {
let { id } = req.query;
let { id } = req.query as { [key: string]: string };
await Permission.delete(id);
res.json({ success: true });
})

2
src/api/admin/regcode.ts

@ -40,7 +40,7 @@ RegCodeRoute.route("/") @@ -40,7 +40,7 @@ RegCodeRoute.route("/")
*/
.delete(
promiseMiddleware(async (req, res) => {
let { id } = req.query;
let { id } = req.query as { [key: string]: string };
await RegCode.delete(id);
res.json({ success: true });
})

4
src/api/admin/user.ts

@ -51,7 +51,7 @@ UserRoute.route("/") @@ -51,7 +51,7 @@ UserRoute.route("/")
*/
.delete(
promiseMiddleware(async (req, res) => {
let { id } = req.query;
let { id } = req.query as { [key: string]: string };
let user = await User.findById(id);
await Promise.all([
@ -83,7 +83,7 @@ UserRoute.route("/") @@ -83,7 +83,7 @@ UserRoute.route("/")
*/
.put(
promiseMiddleware(async (req, res) => {
let { id } = req.query;
let { id } = req.query as { [key: string]: string };
let user = await User.findById(id);
user.admin = !user.admin;
await User.save(user);

4
src/api/client/permissions.ts

@ -14,7 +14,7 @@ import { ObjectID } from "mongodb"; @@ -14,7 +14,7 @@ import { ObjectID } from "mongodb";
export const GetPermissions = Stacker(
GetClientAuthMiddleware(true),
async (req: Request, res: Response) => {
const { user, permission } = req.query;
const { user, permission } = req.query as { [key: string]: string };
let permissions: { id: string; name: string; description: string }[];
let users: string[];
@ -22,7 +22,7 @@ export const GetPermissions = Stacker( @@ -22,7 +22,7 @@ export const GetPermissions = Stacker(
if (user) {
const grant = await Grant.findOne({
client: req.client._id,
user: user,
user: new ObjectID(user),
});
permissions = await Promise.all(

2
src/api/internal/oauth.ts

@ -10,7 +10,7 @@ export const OAuthInternalApp = Stacker( @@ -10,7 +10,7 @@ export const OAuthInternalApp = Stacker(
GetClientAuthMiddleware(false, true),
UserMiddleware,
async (req: Request, res: Response) => {
let { redirect_uri, state } = req.query;
let { redirect_uri, state } = req.query as { [key: string]: string };
if (!redirect_uri) {
throw new RequestError(
"No redirect url set!",

5
src/api/middlewares/client.ts

@ -70,8 +70,9 @@ export function GetClientApiAuthMiddleware(permissions?: string[]) { @@ -70,8 +70,9 @@ export function GetClientApiAuthMiddleware(permissions?: string[]) {
req.__("You are not logged in or your login is expired"),
HttpStatusCode.UNAUTHORIZED
);
let token: string =
req.query.access_token || req.headers.authorization;
let token =
(req.query.access_token as string) ||
(req.headers.authorization as string);
if (!token) throw invalid_err;
if (token.toLowerCase().startsWith("bearer "))

2
src/api/middlewares/user.ts

@ -31,7 +31,7 @@ export function GetUserMiddleware( @@ -31,7 +31,7 @@ export function GetUserMiddleware(
throw new Invalid(req.__(message));
};
try {
let { login, special } = req.query;
let { login, special } = req.query as { [key: string]: string };
if (!login) {
login = req.cookies.login;
special = req.cookies.special;

8
src/api/oauth/auth.ts

@ -94,7 +94,7 @@ const GetAuthRoute = (view = false) => @@ -94,7 +94,7 @@ const GetAuthRoute = (view = false) =>
scope = "",
state,
nored,
} = req.query;
} = req.query as { [key: string]: string };
const sendError = (type) => {
if (redirect_uri === "$local") redirect_uri = "/code";
res.redirect(
@ -178,8 +178,10 @@ const GetAuthRoute = (view = false) => @@ -178,8 +178,10 @@ const GetAuthRoute = (view = false) =>
if (!grant && missing_permissions.length > 0) {
await new Promise<void>((yes, no) =>
GetUserMiddleware(false, true)(req, res, (err?: Error) =>
err ? no(err) : yes()
GetUserMiddleware(false, true)(
req,
res,
(err?: Error | string) => (err ? no(err) : yes())
)
); // Maybe unresolved when redirect is happening

2
src/api/oauth/jwt.ts

@ -7,7 +7,7 @@ import Client from "../../models/client"; @@ -7,7 +7,7 @@ import Client from "../../models/client";
import { getAccessTokenJWT } from "../../helper/jwt";
const JWTRoute = promiseMiddleware(async (req: Request, res: Response) => {
let { refreshtoken } = req.query;
let { refreshtoken } = req.query as { [key: string]: string };
if (!refreshtoken)
throw new RequestError(
req.__("Refresh token not set"),

4
src/api/user/login.ts

@ -9,9 +9,9 @@ import * as crypto from "crypto"; @@ -9,9 +9,9 @@ import * as crypto from "crypto";
import Logging from "@hibas123/nodelogging";
const Login = promiseMiddleware(async (req: Request, res: Response) => {
let type = req.query.type;
let type = req.query.type as string;
if (type === "username") {
let { username, uid } = req.query;
let { username, uid } = req.query as { [key: string]: string };
let user = await User.findOne(
username ? { username: username.toLowerCase() } : { uid: uid }
);

4
src/database.ts

@ -7,5 +7,7 @@ if (Config.database) { @@ -7,5 +7,7 @@ if (Config.database) {
if (Config.database.host) host = Config.database.host;
}
if (Config.core.dev) dbname += "_dev";
const DB = new SafeMongo("mongodb://" + host, dbname);
const DB = new SafeMongo("mongodb://" + host, dbname, {
useUnifiedTopology: true,
});
export default DB;

Loading…
Cancel
Save