diff --git a/.eslintrc.js b/.eslintrc.js index 1cd0131..123df40 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,56 +1,56 @@ -module.exports = { - root: true, - extends: ["airbnb-base", "prettier", "plugin:import/recommended", "plugin:import/typescript"], - ignorePatterns: ["dist/**/*", "build/**/*", "public/swagger.json", "public/custom.js"], - parser: "@typescript-eslint/parser", - plugins: ["@typescript-eslint", "prettier", "import"], - rules: { - // fixes prettier/eslint formatting conflict - indent: ["error", "tab", { SwitchCase: 1 }], - // snake_case used in emitted JSON - camelcase: "off", - // circular imports needed for collection sharing - "import/no-cycle": "off", - "no-plusplus": "off", - "@typescript-eslint/no-unused-vars": ["error"], - "no-console": "off", - "no-param-reassign": "off", - "consistent-return": "off", - "import/prefer-default-export": "off", - "prefer-destructuring": "off", - "class-methods-use-this": "off", - "import/extensions": [ - "error", - "ignorePackages", - { - js: "never", - jsx: "never", - ts: "never", - tsx: "never", - mjs: "never", - }, - ], - }, - settings: { - "import/resolver": { - typescript: { - alwaysTryTypes: true, - project: "tsconfig.json", - }, - node: { - extensions: [".js", ".ts", ".json"], - }, - }, - "import/extensions": [ - "error", - "ignorePackages", - { - "": "never", - js: "never", - jsx: "never", - ts: "never", - tsx: "never", - }, - ], - }, -}; +module.exports = { + root: true, + extends: ["airbnb-base", "prettier", "plugin:import/recommended", "plugin:import/typescript"], + ignorePatterns: ["dist/**/*", "build/**/*", "public/swagger.json", "public/*"], + parser: "@typescript-eslint/parser", + plugins: ["@typescript-eslint", "prettier", "import"], + rules: { + // fixes prettier/eslint formatting conflict + indent: ["error", "tab", { SwitchCase: 1 }], + // snake_case used in emitted JSON + camelcase: "off", + // circular imports needed for collection sharing + "import/no-cycle": "off", + "no-plusplus": "off", + "@typescript-eslint/no-unused-vars": ["error"], + "no-console": "off", + "no-param-reassign": "off", + "consistent-return": "off", + "import/prefer-default-export": "off", + "prefer-destructuring": "off", + "class-methods-use-this": "off", + "import/extensions": [ + "error", + "ignorePackages", + { + js: "never", + jsx: "never", + ts: "never", + tsx: "never", + mjs: "never", + }, + ], + }, + settings: { + "import/resolver": { + typescript: { + alwaysTryTypes: true, + project: "tsconfig.json", + }, + node: { + extensions: [".js", ".ts", ".json"], + }, + }, + "import/extensions": [ + "error", + "ignorePackages", + { + "": "never", + js: "never", + jsx: "never", + ts: "never", + tsx: "never", + }, + ], + }, +}; diff --git a/nodemon.json b/nodemon.json index 390f5ef..b3b7370 100644 --- a/nodemon.json +++ b/nodemon.json @@ -2,7 +2,7 @@ "exec": "npm run exec", "watch": [ "src", - "public/custom.js", + "public/custom*", ".env" ], "ext": "ts, css, json" diff --git a/package-lock.json b/package-lock.json index c92182c..d26f43b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "express": "^4.21.1", "firestorm-db": "^1.13.0", "form-data": "^4.0.1", - "isomorphic-dompurify": "^2.17.0", + "isomorphic-dompurify": "^2.18.0", "multer": "^1.4.5-lts.1", "response-time": "^2.3.3", "statuses": "^2.0.1", @@ -4093,12 +4093,12 @@ "license": "ISC" }, "node_modules/isomorphic-dompurify": { - "version": "2.17.0", - "resolved": "https://registry.npmjs.org/isomorphic-dompurify/-/isomorphic-dompurify-2.17.0.tgz", - "integrity": "sha512-W9RC9aPgEAFF55VMo/9AUQ+GYkQ68gTRMLqS8fP9rw1VoYCsI7RdrRMAePhhqyCLfZS3JNjA4ahFi1L4aczUUg==", + "version": "2.18.0", + "resolved": "https://registry.npmjs.org/isomorphic-dompurify/-/isomorphic-dompurify-2.18.0.tgz", + "integrity": "sha512-e0AaROtWPy6ofSTCnUuBvXFidt1eFmrwEbi+Acpz0du6v2H+fq+3svPBn0g/AfBXz24FTWA9ccle7HSFT3HG7A==", "license": "MIT", "dependencies": { - "dompurify": "^3.2.1", + "dompurify": "^3.2.2", "jsdom": "^25.0.1" }, "engines": { diff --git a/package.json b/package.json index 2225ec1..4ddab73 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "start": "node dist/src/index.js", "swag": "tsoa spec", "lint": "eslint . --ext .js,.jsx,.ts,.tsx --fix", - "prettier": "prettier \"{,!(node_modules)/**/}*.ts\" --config .prettierrc --write" + "prettier": "prettier \"{,!(node_modules)/**/}*.{js,ts}\" --config .prettierrc --write" }, "keywords": [], "author": "", @@ -50,7 +50,7 @@ "express": "^4.21.1", "firestorm-db": "^1.13.0", "form-data": "^4.0.1", - "isomorphic-dompurify": "^2.17.0", + "isomorphic-dompurify": "^2.18.0", "multer": "^1.4.5-lts.1", "response-time": "^2.3.3", "statuses": "^2.0.1", diff --git a/public/custom.js b/public/custom.js index 509895f..ee2dce2 100644 --- a/public/custom.js +++ b/public/custom.js @@ -2,7 +2,7 @@ * Swagger pre-auth and auth script for Swagger UI * @author TheRolf */ -(function () { +(() => { const API_KEY = "ApiKey"; function startUntil(func, cond) { @@ -17,8 +17,8 @@ }, 20); } - function getKeys() { - const value = window.localStorage.getItem(API_KEY); + function getTokens() { + const value = localStorage.getItem(API_KEY); // if new guy, return empty object if (!value) return {}; @@ -26,10 +26,10 @@ // try to parse and return value try { return JSON.parse(value); - } catch {} - - // if not parsed, set empty object - return {}; + } catch { + // if not parsed, set empty object + return {}; + } } startUntil( @@ -37,17 +37,17 @@ const originalAuthorize = ui.authActions.authorize; // on login - ui.authActions.authorize = function (payload) { + ui.authActions.authorize = (payload) => { const key = Object.keys(payload)[0]; // get stored keys - const apiKeys = getKeys(); + const apiKeys = getTokens(); // add this one apiKeys[key] = payload[key].value; // update keys - window.localStorage.setItem(API_KEY, JSON.stringify(apiKeys)); + localStorage.setItem(API_KEY, JSON.stringify(apiKeys)); // call original key return originalAuthorize(payload); @@ -57,15 +57,14 @@ const originalLogout = ui.authActions.logout; // on logout - ui.authActions.logout = function (payload) { - const apiKeys = getKeys(); + ui.authActions.logout = (payload) => { + const apiTokens = getTokens(); - console.log(apiKeys); // delete key if existing - if (payload[0] in apiKeys) delete apiKeys[payload[0]]; + if (payload[0] in apiTokens) delete apiTokens[payload[0]]; // update keys - window.localStorage.setItem(API_KEY, JSON.stringify(apiKeys)); + localStorage.setItem(API_KEY, JSON.stringify(apiTokens)); // call original key return originalLogout(payload); @@ -74,14 +73,14 @@ // on load // load each token, // For each existing token, pre auth - const apiKeys = getKeys(); + const apiTokens = getTokens(); - const keys = Object.keys(apiKeys); + const keys = Object.keys(apiTokens); keys.forEach((key) => { - window.ui.preauthorizeApiKey(key, apiKeys[key]); + ui.preauthorizeApiKey(key, apiTokens[key]); }); - if (keys.length) console.info(`Pre-authed to ${keys.join(", ")}`); + if (keys.length) console.log(`Pre-authed to ${keys.join(", ")}`); }, () => window.ui !== undefined, ); diff --git a/public/custom_dom.js b/public/customDOM.js similarity index 56% rename from public/custom_dom.js rename to public/customDOM.js index 0b52b8f..edbdbb4 100644 --- a/public/custom_dom.js +++ b/public/customDOM.js @@ -1,22 +1,18 @@ -/** - * Swagger custom dom for Swagger UI - * @author TheRolf - */ - -const GITHUB_URL = 'https://github.com/Faithful-Resource-Pack/API'; - -(() => { - // eslint-disable-next-line no-undef - const doc = document; - - doc.addEventListener('DOMContentLoaded', () => { - // Add custom footer - const { body } = doc; - body.innerHTML += `\ - Fork me on GitHub\ - `; - }); -})(); +/** + * Swagger custom dom for Swagger UI + * @author TheRolf + */ + +const GITHUB_URL = "https://github.com/Faithful-Resource-Pack/API"; + +(() => { + document.addEventListener("DOMContentLoaded", () => { + // Add custom footer + document.body.innerHTML += `\ + Fork me on GitHub\ + `; + }); +})(); diff --git a/src/index.ts b/src/index.ts index b438478..928e077 100644 --- a/src/index.ts +++ b/src/index.ts @@ -66,7 +66,7 @@ app.use( // @types/swagger-ui-express isn't updated and complains { customCssUrl: "/custom.css", - customJs: ["/custom.js", "/custom_dom.js"], + customJs: ["/custom.js", "/customDOM.js"], swaggerOptions: { tryItOutEnabled: true, },