Refactor Code to typescript
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
declare function _exports({ query, user, useLocal }: {
|
||||
query: {
|
||||
invite: number;
|
||||
database_access: string;
|
||||
priviledge: string;
|
||||
email: string;
|
||||
};
|
||||
useLocal?: boolean;
|
||||
user: import("../../types").DATASQUIREL_LoggedInUser;
|
||||
}): Promise<any>;
|
||||
export = _exports;
|
||||
+22
-33
@@ -1,9 +1,19 @@
|
||||
// @ts-check
|
||||
import serverError from "./serverError";
|
||||
import DB_HANDLER from "../../utils/backend/global-db/DB_HANDLER";
|
||||
import addDbEntry from "./db/addDbEntry";
|
||||
import LOCAL_DB_HANDLER from "../../utils/backend/global-db/LOCAL_DB_HANDLER";
|
||||
import { DATASQUIREL_LoggedInUser } from "../../types";
|
||||
|
||||
const serverError = require("./serverError");
|
||||
const DB_HANDLER = require("../../utils/backend/global-db/DB_HANDLER");
|
||||
const addDbEntry = require("./db/addDbEntry");
|
||||
const LOCAL_DB_HANDLER = require("../../utils/backend/global-db/LOCAL_DB_HANDLER");
|
||||
type Param = {
|
||||
query: {
|
||||
invite: number;
|
||||
database_access: string;
|
||||
priviledge: string;
|
||||
email: string;
|
||||
};
|
||||
useLocal?: boolean;
|
||||
user: DATASQUIREL_LoggedInUser;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add Admin User on Login
|
||||
@@ -12,21 +22,12 @@ const LOCAL_DB_HANDLER = require("../../utils/backend/global-db/LOCAL_DB_HANDLER
|
||||
* @description this function handles admin users that have been invited by another
|
||||
* admin user. This fires when the invited user has been logged in or a new account
|
||||
* has been created for the invited user
|
||||
*
|
||||
* @param {object} params - parameters object
|
||||
*
|
||||
* @param {object} params.query - query object
|
||||
* @param {number} params.query.invite - Invitation user id
|
||||
* @param {string} params.query.database_access - String containing authorized databases
|
||||
* @param {string} params.query.priviledge - String containing databases priviledges
|
||||
* @param {string} params.query.email - Inviting user email address
|
||||
*
|
||||
* @param {boolean} [params.useLocal]
|
||||
* @param {import("../../types").DATASQUIREL_LoggedInUser} params.user - invited user object
|
||||
*
|
||||
* @returns {Promise<any>} new user auth object payload
|
||||
*/
|
||||
module.exports = async function addAdminUserOnLogin({ query, user, useLocal }) {
|
||||
export default async function addAdminUserOnLogin({
|
||||
query,
|
||||
user,
|
||||
useLocal,
|
||||
}: Param): Promise<any> {
|
||||
try {
|
||||
const finalDbHandler = useLocal ? LOCAL_DB_HANDLER : DB_HANDLER;
|
||||
const { invite, database_access, priviledge, email } = query;
|
||||
@@ -132,23 +133,11 @@ module.exports = async function addAdminUserOnLogin({ query, user, useLocal }) {
|
||||
[invite, email]
|
||||
);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
|
||||
} catch (error: any) {
|
||||
serverError({
|
||||
component: "addAdminUserOnLogin",
|
||||
message: error.message,
|
||||
user: user,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
declare function _exports({ userId, useLocal }: {
|
||||
userId: number | string;
|
||||
useLocal?: boolean;
|
||||
}): Promise<any>;
|
||||
export = _exports;
|
||||
+16
-18
@@ -1,24 +1,22 @@
|
||||
// @ts-check
|
||||
import generator from "generate-password";
|
||||
import DB_HANDLER from "../../utils/backend/global-db/DB_HANDLER";
|
||||
import NO_DB_HANDLER from "../../utils/backend/global-db/NO_DB_HANDLER";
|
||||
import addDbEntry from "./db/addDbEntry";
|
||||
import encrypt from "../dsql/encrypt";
|
||||
import LOCAL_DB_HANDLER from "../../utils/backend/global-db/LOCAL_DB_HANDLER";
|
||||
|
||||
const generator = require("generate-password");
|
||||
const DB_HANDLER = require("../../utils/backend/global-db/DB_HANDLER");
|
||||
const NO_DB_HANDLER = require("../../utils/backend/global-db/NO_DB_HANDLER");
|
||||
const addDbEntry = require("./db/addDbEntry");
|
||||
const encrypt = require("../dsql/encrypt");
|
||||
const LOCAL_DB_HANDLER = require("../../utils/backend/global-db/LOCAL_DB_HANDLER");
|
||||
type Param = {
|
||||
userId: number | string;
|
||||
useLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* # Add Mariadb User
|
||||
*
|
||||
* @description this function adds a Mariadb user to the database server
|
||||
*
|
||||
* @param {object} params - parameters object *
|
||||
* @param {number | string} params.userId - invited user object
|
||||
* @param {boolean} [params.useLocal]
|
||||
*
|
||||
* @returns {Promise<any>} new user auth object payload
|
||||
*/
|
||||
module.exports = async function addMariadbUser({ userId, useLocal }) {
|
||||
export default async function addMariadbUser({
|
||||
userId,
|
||||
useLocal,
|
||||
}: Param): Promise<any> {
|
||||
try {
|
||||
const defaultMariadbUserHost = process.env.DSQL_DB_HOST || "127.0.0.1";
|
||||
|
||||
@@ -62,13 +60,13 @@ module.exports = async function addMariadbUser({ userId, useLocal }) {
|
||||
});
|
||||
|
||||
console.log(`User ${userId} SQL credentials successfully added.`);
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(
|
||||
`Error in adding SQL user in 'addMariadbUser' function =>`,
|
||||
error.message
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
@@ -1,9 +0,0 @@
|
||||
declare function _exports({ userId, database, useLocal, payload, }: {
|
||||
userId: number;
|
||||
database: string;
|
||||
useLocal?: boolean;
|
||||
payload?: {
|
||||
[x: string]: any;
|
||||
};
|
||||
}): Promise<any>;
|
||||
export = _exports;
|
||||
+21
-27
@@ -1,34 +1,28 @@
|
||||
// @ts-check
|
||||
import serverError from "./serverError";
|
||||
import DB_HANDLER from "../../utils/backend/global-db/DB_HANDLER";
|
||||
import { default as grabUserSchemaData } from "./grabUserSchemaData";
|
||||
import { default as setUserSchemaData } from "./setUserSchemaData";
|
||||
import addDbEntry from "./db/addDbEntry";
|
||||
import createDbFromSchema from "../../shell/createDbFromSchema";
|
||||
import LOCAL_DB_HANDLER from "../../utils/backend/global-db/LOCAL_DB_HANDLER";
|
||||
import grabNewUsersTableSchema from "./grabNewUsersTableSchema";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { execSync } = require("child_process");
|
||||
const serverError = require("./serverError");
|
||||
const DB_HANDLER = require("../../utils/backend/global-db/DB_HANDLER");
|
||||
const { default: grabUserSchemaData } = require("./grabUserSchemaData");
|
||||
const { default: setUserSchemaData } = require("./setUserSchemaData");
|
||||
const addDbEntry = require("./db/addDbEntry");
|
||||
const createDbFromSchema = require("../../shell/createDbFromSchema");
|
||||
const LOCAL_DB_HANDLER = require("../../utils/backend/global-db/LOCAL_DB_HANDLER");
|
||||
const grabNewUsersTableSchema = require("./grabNewUsersTableSchema");
|
||||
type Param = {
|
||||
userId: number;
|
||||
database: string;
|
||||
useLocal?: boolean;
|
||||
payload?: { [s: string]: any };
|
||||
};
|
||||
|
||||
/**
|
||||
* # Add User Table to Database
|
||||
*
|
||||
* @param {object} params
|
||||
* @param {number} params.userId - user id
|
||||
* @param {string} params.database
|
||||
* @param {boolean} [params.useLocal]
|
||||
* @param {Object<string, any>} [params.payload] - payload object
|
||||
*
|
||||
* @returns {Promise<any>} new user auth object payload
|
||||
*/
|
||||
module.exports = async function addUsersTableToDb({
|
||||
export default async function addUsersTableToDb({
|
||||
userId,
|
||||
database,
|
||||
useLocal,
|
||||
payload,
|
||||
}) {
|
||||
}: Param): Promise<any> {
|
||||
try {
|
||||
const dbFullName = database;
|
||||
|
||||
@@ -39,7 +33,7 @@ module.exports = async function addUsersTableToDb({
|
||||
if (!userSchemaData) throw new Error("User schema data not found!");
|
||||
|
||||
let targetDatabase = userSchemaData.find(
|
||||
(db) => db.dbFullName === database
|
||||
(db: any) => db.dbFullName === database
|
||||
);
|
||||
|
||||
if (!targetDatabase) {
|
||||
@@ -47,7 +41,7 @@ module.exports = async function addUsersTableToDb({
|
||||
}
|
||||
|
||||
let existingTableIndex = targetDatabase?.tables.findIndex(
|
||||
(table) => table.tableName === "users"
|
||||
(table: any) => table.tableName === "users"
|
||||
);
|
||||
|
||||
if (typeof existingTableIndex == "number" && existingTableIndex > 0) {
|
||||
@@ -59,7 +53,7 @@ module.exports = async function addUsersTableToDb({
|
||||
setUserSchemaData({ schemaData: userSchemaData, userId });
|
||||
|
||||
/** @type {any[] | null} */
|
||||
const targetDb = useLocal
|
||||
const targetDb: any[] | null = useLocal
|
||||
? await LOCAL_DB_HANDLER(
|
||||
`SELECT id FROM user_databases WHERE user_id=? AND db_slug=?`,
|
||||
[userId, database]
|
||||
@@ -90,7 +84,7 @@ module.exports = async function addUsersTableToDb({
|
||||
});
|
||||
|
||||
return `Done!`;
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(`addUsersTableToDb.js ERROR: ${error.message}`);
|
||||
|
||||
serverError({
|
||||
@@ -100,4 +94,4 @@ module.exports = async function addUsersTableToDb({
|
||||
});
|
||||
return error.message;
|
||||
}
|
||||
};
|
||||
}
|
||||
+18
-9
@@ -1,10 +1,17 @@
|
||||
// @ts-check
|
||||
import fs from "fs";
|
||||
import decrypt from "../dsql/decrypt";
|
||||
import { CheckApiCredentialsFn } from "../../types";
|
||||
|
||||
const fs = require("fs");
|
||||
const decrypt = require("../dsql/decrypt");
|
||||
|
||||
/** @type {import("../../types").CheckApiCredentialsFn} */
|
||||
const grabApiCred = ({ key, database, table, user_id, media }) => {
|
||||
/**
|
||||
* # Grap API Credentials
|
||||
*/
|
||||
const grabApiCred: CheckApiCredentialsFn = ({
|
||||
key,
|
||||
database,
|
||||
table,
|
||||
user_id,
|
||||
media,
|
||||
}) => {
|
||||
if (!key) return null;
|
||||
if (!user_id) return null;
|
||||
|
||||
@@ -18,7 +25,9 @@ const grabApiCred = ({ key, database, table, user_id, media }) => {
|
||||
|
||||
const ApiJSON = decrypt({ encryptedString: key });
|
||||
/** @type {import("../../types").ApiKeyObject} */
|
||||
const ApiObject = JSON.parse(ApiJSON || "");
|
||||
const ApiObject: import("../../types").ApiKeyObject = JSON.parse(
|
||||
ApiJSON || ""
|
||||
);
|
||||
const isApiKeyValid = fs.existsSync(
|
||||
`${allowedKeysPath}/${ApiObject.sign}`
|
||||
);
|
||||
@@ -41,10 +50,10 @@ const grabApiCred = ({ key, database, table, user_id, media }) => {
|
||||
.includes(String(table));
|
||||
if (isTableAllowed) return ApiObject;
|
||||
return null;
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(`api-cred ERROR: ${error.message}`);
|
||||
return { error: `api-cred ERROR: ${error.message}` };
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = grabApiCred;
|
||||
export default grabApiCred;
|
||||
@@ -1,26 +0,0 @@
|
||||
export function grabAuthDirs(): {
|
||||
root: string;
|
||||
auth: string;
|
||||
};
|
||||
export function initAuthFiles(): boolean;
|
||||
/**
|
||||
* # Write Auth Files
|
||||
* @param {string} name
|
||||
* @param {string} data
|
||||
*/
|
||||
export function writeAuthFile(name: string, data: string): boolean;
|
||||
/**
|
||||
* # Get Auth Files
|
||||
* @param {string} name
|
||||
*/
|
||||
export function getAuthFile(name: string): string;
|
||||
/**
|
||||
* # Delete Auth Files
|
||||
* @param {string} name
|
||||
*/
|
||||
export function deleteAuthFile(name: string): void;
|
||||
/**
|
||||
* # Delete Auth Files
|
||||
* @param {string} name
|
||||
*/
|
||||
export function checkAuthFile(name: string): boolean;
|
||||
+13
-25
@@ -1,9 +1,7 @@
|
||||
// @ts-check
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const grabAuthDirs = () => {
|
||||
export const grabAuthDirs = () => {
|
||||
const DSQL_AUTH_DIR = process.env.DSQL_AUTH_DIR;
|
||||
const ROOT_DIR = DSQL_AUTH_DIR?.match(/./)
|
||||
? DSQL_AUTH_DIR
|
||||
@@ -13,7 +11,7 @@ const grabAuthDirs = () => {
|
||||
return { root: ROOT_DIR, auth: AUTH_DIR };
|
||||
};
|
||||
|
||||
const initAuthFiles = () => {
|
||||
export const initAuthFiles = () => {
|
||||
try {
|
||||
const authDirs = grabAuthDirs();
|
||||
|
||||
@@ -22,7 +20,7 @@ const initAuthFiles = () => {
|
||||
if (!fs.existsSync(authDirs.auth))
|
||||
fs.mkdirSync(authDirs.auth, { recursive: true });
|
||||
return true;
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (error: any) {
|
||||
console.log(`Error initializing Auth Files: ${error.message}`);
|
||||
return false;
|
||||
}
|
||||
@@ -30,15 +28,13 @@ const initAuthFiles = () => {
|
||||
|
||||
/**
|
||||
* # Write Auth Files
|
||||
* @param {string} name
|
||||
* @param {string} data
|
||||
*/
|
||||
const writeAuthFile = (name, data) => {
|
||||
export const writeAuthFile = (name: string, data: string) => {
|
||||
initAuthFiles();
|
||||
try {
|
||||
fs.writeFileSync(path.join(grabAuthDirs().auth, name), data);
|
||||
return true;
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(`Error writing Auth File: ${error.message}`);
|
||||
return false;
|
||||
}
|
||||
@@ -46,13 +42,12 @@ const writeAuthFile = (name, data) => {
|
||||
|
||||
/**
|
||||
* # Get Auth Files
|
||||
* @param {string} name
|
||||
*/
|
||||
const getAuthFile = (name) => {
|
||||
export const getAuthFile = (name: string) => {
|
||||
try {
|
||||
const authFilePath = path.join(grabAuthDirs().auth, name);
|
||||
return fs.readFileSync(authFilePath, "utf-8");
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(`Error getting Auth File: ${error.message}`);
|
||||
return null;
|
||||
}
|
||||
@@ -62,10 +57,10 @@ const getAuthFile = (name) => {
|
||||
* # Delete Auth Files
|
||||
* @param {string} name
|
||||
*/
|
||||
const deleteAuthFile = (name) => {
|
||||
export const deleteAuthFile = (name: string) => {
|
||||
try {
|
||||
return fs.rmSync(path.join(grabAuthDirs().auth, name));
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(`Error deleting Auth File: ${error.message}`);
|
||||
return null;
|
||||
}
|
||||
@@ -75,19 +70,12 @@ const deleteAuthFile = (name) => {
|
||||
* # Delete Auth Files
|
||||
* @param {string} name
|
||||
*/
|
||||
const checkAuthFile = (name) => {
|
||||
export const checkAuthFile = (name: string) => {
|
||||
try {
|
||||
return fs.existsSync(path.join(grabAuthDirs().auth, name));
|
||||
return true;
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(`Error checking Auth File: ${error.message}`);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
exports.grabAuthDirs = grabAuthDirs;
|
||||
exports.initAuthFiles = initAuthFiles;
|
||||
exports.writeAuthFile = writeAuthFile;
|
||||
exports.getAuthFile = getAuthFile;
|
||||
exports.deleteAuthFile = deleteAuthFile;
|
||||
exports.checkAuthFile = checkAuthFile;
|
||||
@@ -1,9 +0,0 @@
|
||||
declare function _exports(params?: {
|
||||
database?: string;
|
||||
userId?: string | number;
|
||||
}): {
|
||||
keyCookieName: string;
|
||||
csrfCookieName: string;
|
||||
oneTimeCodeName: string;
|
||||
};
|
||||
export = _exports;
|
||||
+12
-9
@@ -1,15 +1,18 @@
|
||||
// @ts-check
|
||||
type Param = {
|
||||
database?: string;
|
||||
userId?: string | number;
|
||||
};
|
||||
|
||||
type Return = {
|
||||
keyCookieName: string;
|
||||
csrfCookieName: string;
|
||||
oneTimeCodeName: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* # Grab Auth Cookie Names
|
||||
*
|
||||
* @param {object} [params]
|
||||
* @param {string} [params.database]
|
||||
* @param {string | number} [params.userId]
|
||||
*
|
||||
* @returns {{ keyCookieName: string, csrfCookieName: string, oneTimeCodeName: string }}
|
||||
*/
|
||||
module.exports = function getAuthCookieNames(params) {
|
||||
export default function getAuthCookieNames(params?: Param): Return {
|
||||
const cookiesPrefix = process.env.DSQL_COOKIES_PREFIX || "dsql_";
|
||||
const cookiesKeyName = process.env.DSQL_COOKIES_KEY_NAME || "key";
|
||||
const cookiesCSRFName = process.env.DSQL_COOKIES_CSRF_NAME || "csrf";
|
||||
@@ -40,4 +43,4 @@ module.exports = function getAuthCookieNames(params) {
|
||||
csrfCookieName,
|
||||
oneTimeCodeName,
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
export = addDbEntry;
|
||||
/**
|
||||
* Add a db Entry Function
|
||||
* ==============================================================================
|
||||
* @description Description
|
||||
* @async
|
||||
*
|
||||
* @param {object} params - An object containing the function parameters.
|
||||
* @param {("Master" | "Dsql User")} [params.dbContext] - What is the database context? "Master"
|
||||
* or "Dsql User". Defaults to "Master"
|
||||
* @param {("Read Only" | "Full Access")} [params.paradigm] - What is the paradigm for "Dsql User"?
|
||||
* "Read only" or "Full Access"? Defaults to "Read Only"
|
||||
* @param {string} [params.dbFullName] - Database full name
|
||||
* @param {string} params.tableName - Table name
|
||||
* @param {any} params.data - Data to add
|
||||
* @param {import("../../../types").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
||||
* @param {string} [params.duplicateColumnName] - Duplicate column name
|
||||
* @param {string} [params.duplicateColumnValue] - Duplicate column value
|
||||
* @param {boolean} [params.update] - Update this row if it exists
|
||||
* @param {string} [params.encryptionKey] - Update this row if it exists
|
||||
* @param {string} [params.encryptionSalt] - Update this row if it exists
|
||||
* @param {boolean} [params.useLocal]
|
||||
*
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
declare function addDbEntry({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt, useLocal, }: {
|
||||
dbContext?: ("Master" | "Dsql User");
|
||||
paradigm?: ("Read Only" | "Full Access");
|
||||
dbFullName?: string;
|
||||
tableName: string;
|
||||
data: any;
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
duplicateColumnName?: string;
|
||||
duplicateColumnValue?: string;
|
||||
update?: boolean;
|
||||
encryptionKey?: string;
|
||||
encryptionSalt?: string;
|
||||
useLocal?: boolean;
|
||||
}): Promise<any>;
|
||||
+27
-22
@@ -1,13 +1,28 @@
|
||||
// @ts-check
|
||||
|
||||
const sanitizeHtml = require("sanitize-html");
|
||||
const sanitizeHtmlOptions = require("../html/sanitizeHtmlOptions");
|
||||
const updateDbEntry = require("./updateDbEntry");
|
||||
const _ = require("lodash");
|
||||
const DB_HANDLER = require("../../../utils/backend/global-db/DB_HANDLER");
|
||||
const DSQL_USER_DB_HANDLER = require("../../../utils/backend/global-db/DSQL_USER_DB_HANDLER");
|
||||
const encrypt = require("../../dsql/encrypt");
|
||||
const LOCAL_DB_HANDLER = require("../../../utils/backend/global-db/LOCAL_DB_HANDLER");
|
||||
import sanitizeHtml from "sanitize-html";
|
||||
import sanitizeHtmlOptions from "../html/sanitizeHtmlOptions";
|
||||
import updateDbEntry from "./updateDbEntry";
|
||||
import _ from "lodash";
|
||||
import DB_HANDLER from "../../../utils/backend/global-db/DB_HANDLER";
|
||||
import DSQL_USER_DB_HANDLER from "../../../utils/backend/global-db/DSQL_USER_DB_HANDLER";
|
||||
import encrypt from "../../dsql/encrypt";
|
||||
import LOCAL_DB_HANDLER from "../../../utils/backend/global-db/LOCAL_DB_HANDLER";
|
||||
|
||||
type Param = {
|
||||
dbContext?: "Master" | "Dsql User";
|
||||
paradigm?: "Read Only" | "Full Access";
|
||||
dbFullName?: string;
|
||||
tableName: string;
|
||||
data: any;
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
duplicateColumnName?: string;
|
||||
duplicateColumnValue?: string;
|
||||
update?: boolean;
|
||||
encryptionKey?: string;
|
||||
encryptionSalt?: string;
|
||||
useLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a db Entry Function
|
||||
@@ -33,7 +48,7 @@ const LOCAL_DB_HANDLER = require("../../../utils/backend/global-db/LOCAL_DB_HAND
|
||||
*
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
async function addDbEntry({
|
||||
export default async function addDbEntry({
|
||||
dbContext,
|
||||
paradigm,
|
||||
dbFullName,
|
||||
@@ -46,7 +61,7 @@ async function addDbEntry({
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
useLocal,
|
||||
}) {
|
||||
}: Param): Promise<any> {
|
||||
/**
|
||||
* Initialize variables
|
||||
*/
|
||||
@@ -59,7 +74,7 @@ async function addDbEntry({
|
||||
: true;
|
||||
|
||||
/** @type { any } */
|
||||
const dbHandler = useLocal
|
||||
const dbHandler: any = useLocal
|
||||
? LOCAL_DB_HANDLER
|
||||
: isMaster
|
||||
? DB_HANDLER
|
||||
@@ -187,7 +202,7 @@ async function addDbEntry({
|
||||
} else {
|
||||
insertValuesArray.push(value);
|
||||
}
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log("DSQL: Error in parsing data keys =>", error.message);
|
||||
continue;
|
||||
}
|
||||
@@ -233,18 +248,8 @@ async function addDbEntry({
|
||||
queryValues: queryValuesArray,
|
||||
});
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Return statement
|
||||
*/
|
||||
return newInsert;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
module.exports = addDbEntry;
|
||||
@@ -1,34 +0,0 @@
|
||||
export = deleteDbEntry;
|
||||
/**
|
||||
* Imports: Handle imports
|
||||
*/
|
||||
/**
|
||||
* Delete DB Entry Function
|
||||
* ==============================================================================
|
||||
* @description Description
|
||||
* @async
|
||||
*
|
||||
* @param {object} params - An object containing the function parameters.
|
||||
* @param {string} [params.dbContext] - What is the database context? "Master"
|
||||
* or "Dsql User". Defaults to "Master"
|
||||
* @param {("Read Only" | "Full Access")} [params.paradigm] - What is the paradigm for "Dsql User"?
|
||||
* "Read only" or "Full Access"? Defaults to "Read Only"
|
||||
* @param {string} params.dbFullName - Database full name
|
||||
* @param {string} params.tableName - Table name
|
||||
* @param {import("../../../types").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
||||
* @param {string} params.identifierColumnName - Update row identifier column name
|
||||
* @param {string|number} params.identifierValue - Update row identifier column value
|
||||
* @param {boolean} [params.useLocal]
|
||||
*
|
||||
* @returns {Promise<object|null>}
|
||||
*/
|
||||
declare function deleteDbEntry({ dbContext, paradigm, dbFullName, tableName, identifierColumnName, identifierValue, useLocal, }: {
|
||||
dbContext?: string;
|
||||
paradigm?: ("Read Only" | "Full Access");
|
||||
dbFullName: string;
|
||||
tableName: string;
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
identifierColumnName: string;
|
||||
identifierValue: string | number;
|
||||
useLocal?: boolean;
|
||||
}): Promise<object | null>;
|
||||
@@ -1,104 +0,0 @@
|
||||
// @ts-check
|
||||
|
||||
const DB_HANDLER = require("../../../utils/backend/global-db/DB_HANDLER");
|
||||
const DSQL_USER_DB_HANDLER = require("../../../utils/backend/global-db/DSQL_USER_DB_HANDLER");
|
||||
const LOCAL_DB_HANDLER = require("../../../utils/backend/global-db/LOCAL_DB_HANDLER");
|
||||
|
||||
/**
|
||||
* Imports: Handle imports
|
||||
*/
|
||||
|
||||
/**
|
||||
* Delete DB Entry Function
|
||||
* ==============================================================================
|
||||
* @description Description
|
||||
* @async
|
||||
*
|
||||
* @param {object} params - An object containing the function parameters.
|
||||
* @param {string} [params.dbContext] - What is the database context? "Master"
|
||||
* or "Dsql User". Defaults to "Master"
|
||||
* @param {("Read Only" | "Full Access")} [params.paradigm] - What is the paradigm for "Dsql User"?
|
||||
* "Read only" or "Full Access"? Defaults to "Read Only"
|
||||
* @param {string} params.dbFullName - Database full name
|
||||
* @param {string} params.tableName - Table name
|
||||
* @param {import("../../../types").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
||||
* @param {string} params.identifierColumnName - Update row identifier column name
|
||||
* @param {string|number} params.identifierValue - Update row identifier column value
|
||||
* @param {boolean} [params.useLocal]
|
||||
*
|
||||
* @returns {Promise<object|null>}
|
||||
*/
|
||||
async function deleteDbEntry({
|
||||
dbContext,
|
||||
paradigm,
|
||||
dbFullName,
|
||||
tableName,
|
||||
identifierColumnName,
|
||||
identifierValue,
|
||||
useLocal,
|
||||
}) {
|
||||
try {
|
||||
/**
|
||||
* Check if data is valid
|
||||
*/
|
||||
const isMaster = useLocal
|
||||
? true
|
||||
: dbContext?.match(/dsql.user/i)
|
||||
? false
|
||||
: dbFullName && !dbFullName.match(/^datasquirel$/)
|
||||
? false
|
||||
: true;
|
||||
|
||||
/** @type { (a1:any, a2?:any) => any } */
|
||||
const dbHandler = useLocal
|
||||
? LOCAL_DB_HANDLER
|
||||
: isMaster
|
||||
? DB_HANDLER
|
||||
: DSQL_USER_DB_HANDLER;
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Execution
|
||||
*
|
||||
* @description
|
||||
*/
|
||||
const query = `DELETE FROM ${tableName} WHERE \`${identifierColumnName}\`=?`;
|
||||
|
||||
const deletedEntry = isMaster
|
||||
? await dbHandler(query, [identifierValue])
|
||||
: await dbHandler({
|
||||
paradigm,
|
||||
queryString: query,
|
||||
database: dbFullName,
|
||||
queryValues: [identifierValue],
|
||||
});
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Return statement
|
||||
*/
|
||||
return deletedEntry;
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (error) {
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
module.exports = deleteDbEntry;
|
||||
@@ -0,0 +1,68 @@
|
||||
import DB_HANDLER from "../../../utils/backend/global-db/DB_HANDLER";
|
||||
import DSQL_USER_DB_HANDLER from "../../../utils/backend/global-db/DSQL_USER_DB_HANDLER";
|
||||
import LOCAL_DB_HANDLER from "../../../utils/backend/global-db/LOCAL_DB_HANDLER";
|
||||
|
||||
type Param = {
|
||||
dbContext?: string;
|
||||
paradigm?: "Read Only" | "Full Access";
|
||||
dbFullName: string;
|
||||
tableName: string;
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
identifierColumnName: string;
|
||||
identifierValue: string | number;
|
||||
useLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* # Delete DB Entry Function
|
||||
* @description
|
||||
*/
|
||||
export default async function deleteDbEntry({
|
||||
dbContext,
|
||||
paradigm,
|
||||
dbFullName,
|
||||
tableName,
|
||||
identifierColumnName,
|
||||
identifierValue,
|
||||
useLocal,
|
||||
}: Param): Promise<object | null> {
|
||||
try {
|
||||
const isMaster = useLocal
|
||||
? true
|
||||
: dbContext?.match(/dsql.user/i)
|
||||
? false
|
||||
: dbFullName && !dbFullName.match(/^datasquirel$/)
|
||||
? false
|
||||
: true;
|
||||
|
||||
/** @type { (a1:any, a2?:any) => any } */
|
||||
const dbHandler: (a1: any, a2?: any) => any = useLocal
|
||||
? LOCAL_DB_HANDLER
|
||||
: isMaster
|
||||
? DB_HANDLER
|
||||
: DSQL_USER_DB_HANDLER;
|
||||
|
||||
/**
|
||||
* Execution
|
||||
*
|
||||
* @description
|
||||
*/
|
||||
const query = `DELETE FROM ${tableName} WHERE \`${identifierColumnName}\`=?`;
|
||||
|
||||
const deletedEntry = isMaster
|
||||
? await dbHandler(query, [identifierValue])
|
||||
: await dbHandler({
|
||||
paradigm,
|
||||
queryString: query,
|
||||
database: dbFullName,
|
||||
queryValues: [identifierValue],
|
||||
});
|
||||
|
||||
/**
|
||||
* Return statement
|
||||
*/
|
||||
return deletedEntry;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* # Path Traversal Check
|
||||
*
|
||||
* @param {string|number} text - Text or number or object
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
function pathTraversalCheck(text) {
|
||||
return text.toString().replace(/\//g, "");
|
||||
}
|
||||
|
||||
module.exports = pathTraversalCheck;
|
||||
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* # Path Traversal Check
|
||||
* @returns {string}
|
||||
*/
|
||||
export default function pathTraversalCheck(text: string | number): string {
|
||||
return text.toString().replace(/\//g, "");
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
export = runQuery;
|
||||
/**
|
||||
* Run DSQL users queries
|
||||
* ==============================================================================
|
||||
* @param {object} params - An object containing the function parameters.
|
||||
* @param {string} params.dbFullName - Database full name. Eg. "datasquire_user_2_test"
|
||||
* @param {string | any} params.query - Query string or object
|
||||
* @param {boolean} [params.readOnly] - Is this operation read only?
|
||||
* @param {boolean} [params.local] - Is this operation read only?
|
||||
* @param {import("../../../types").DSQL_DatabaseSchemaType} [params.dbSchema] - Database schema
|
||||
* @param {(string | number)[]} [params.queryValuesArray] - An optional array of query values if "?" is used in the query string
|
||||
* @param {string} [params.tableName] - Table Name
|
||||
*
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
declare function runQuery({ dbFullName, query, readOnly, dbSchema, queryValuesArray, tableName, local, }: {
|
||||
dbFullName: string;
|
||||
query: string | any;
|
||||
readOnly?: boolean;
|
||||
local?: boolean;
|
||||
dbSchema?: import("../../../types").DSQL_DatabaseSchemaType;
|
||||
queryValuesArray?: (string | number)[];
|
||||
tableName?: string;
|
||||
}): Promise<any>;
|
||||
+24
-47
@@ -1,32 +1,26 @@
|
||||
// @ts-check
|
||||
import fullAccessDbHandler from "../fullAccessDbHandler";
|
||||
import varReadOnlyDatabaseDbHandler from "../varReadOnlyDatabaseDbHandler";
|
||||
import serverError from "../serverError";
|
||||
import addDbEntry from "./addDbEntry";
|
||||
import updateDbEntry from "./updateDbEntry";
|
||||
import deleteDbEntry from "./deleteDbEntry";
|
||||
import trimSql from "../../../utils/trim-sql";
|
||||
import { DSQL_TableSchemaType } from "../../../types";
|
||||
|
||||
const fs = require("fs");
|
||||
|
||||
const LOCAL_DB_HANDLER = require("../../../utils/backend/global-db/LOCAL_DB_HANDLER");
|
||||
const fullAccessDbHandler = require("../fullAccessDbHandler");
|
||||
const varReadOnlyDatabaseDbHandler = require("../varReadOnlyDatabaseDbHandler");
|
||||
const serverError = require("../serverError");
|
||||
const addDbEntry = require("./addDbEntry");
|
||||
const updateDbEntry = require("./updateDbEntry");
|
||||
const deleteDbEntry = require("./deleteDbEntry");
|
||||
const parseDbResults = require("../parseDbResults");
|
||||
const trimSql = require("../../../utils/trim-sql");
|
||||
type Param = {
|
||||
dbFullName: string;
|
||||
query: string | any;
|
||||
readOnly?: boolean;
|
||||
local?: boolean;
|
||||
dbSchema?: import("../../../types").DSQL_DatabaseSchemaType;
|
||||
queryValuesArray?: (string | number)[];
|
||||
tableName?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Run DSQL users queries
|
||||
* ==============================================================================
|
||||
* @param {object} params - An object containing the function parameters.
|
||||
* @param {string} params.dbFullName - Database full name. Eg. "datasquire_user_2_test"
|
||||
* @param {string | any} params.query - Query string or object
|
||||
* @param {boolean} [params.readOnly] - Is this operation read only?
|
||||
* @param {boolean} [params.local] - Is this operation read only?
|
||||
* @param {import("../../../types").DSQL_DatabaseSchemaType} [params.dbSchema] - Database schema
|
||||
* @param {(string | number)[]} [params.queryValuesArray] - An optional array of query values if "?" is used in the query string
|
||||
* @param {string} [params.tableName] - Table Name
|
||||
*
|
||||
* @return {Promise<any>}
|
||||
* # Run DSQL users queries
|
||||
*/
|
||||
async function runQuery({
|
||||
export default async function runQuery({
|
||||
dbFullName,
|
||||
query,
|
||||
readOnly,
|
||||
@@ -34,19 +28,16 @@ async function runQuery({
|
||||
queryValuesArray,
|
||||
tableName,
|
||||
local,
|
||||
}) {
|
||||
}: Param): Promise<any> {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
|
||||
/** @type {any} */
|
||||
let result;
|
||||
/** @type {any} */
|
||||
let error;
|
||||
/** @type {import("../../../types").DSQL_TableSchemaType | undefined} */
|
||||
let tableSchema;
|
||||
let result: any;
|
||||
let error: any;
|
||||
let tableSchema: DSQL_TableSchemaType | undefined;
|
||||
|
||||
if (dbSchema) {
|
||||
try {
|
||||
@@ -178,11 +169,7 @@ async function runQuery({
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
serverError({
|
||||
component: "functions/backend/runQuery",
|
||||
message: error.message,
|
||||
@@ -191,15 +178,5 @@ async function runQuery({
|
||||
error = error.message;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
return { result, error };
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
|
||||
module.exports = runQuery;
|
||||
+9
-14
@@ -1,20 +1,12 @@
|
||||
// @ts-check
|
||||
|
||||
const _ = require("lodash");
|
||||
import _ from "lodash";
|
||||
|
||||
/**
|
||||
* Sanitize SQL function
|
||||
* ==============================================================================
|
||||
* @description this function takes in a text(or number) and returns a sanitized
|
||||
* text, usually without spaces
|
||||
*
|
||||
* @param {any} text - Text or number or object
|
||||
* @param {boolean} [spaces] - Allow spaces
|
||||
* @param {RegExp?} [regex] - Regular expression, removes any match
|
||||
*
|
||||
* @returns {any}
|
||||
*/
|
||||
function sanitizeSql(text, spaces, regex) {
|
||||
function sanitizeSql(text: any, spaces: boolean, regex?: RegExp | null): any {
|
||||
if (!text) return "";
|
||||
if (typeof text == "number" || typeof text == "boolean") return text;
|
||||
if (typeof text == "string" && !text?.toString()?.match(/./)) return "";
|
||||
@@ -63,9 +55,9 @@ function sanitizeSql(text, spaces, regex) {
|
||||
*
|
||||
* @returns {object}
|
||||
*/
|
||||
function sanitizeObjects(object, spaces) {
|
||||
function sanitizeObjects(object: any, spaces: boolean): object {
|
||||
/** @type {any} */
|
||||
let objectUpdated = { ...object };
|
||||
let objectUpdated: any = { ...object };
|
||||
const keys = Object.keys(objectUpdated);
|
||||
|
||||
keys.forEach((key) => {
|
||||
@@ -98,7 +90,10 @@ function sanitizeObjects(object, spaces) {
|
||||
*
|
||||
* @returns {string[]|number[]|object[]}
|
||||
*/
|
||||
function sanitizeArrays(array, spaces) {
|
||||
function sanitizeArrays(
|
||||
array: any[],
|
||||
spaces: boolean
|
||||
): string[] | number[] | object[] {
|
||||
let arrayUpdated = _.cloneDeep(array);
|
||||
|
||||
arrayUpdated.forEach((item, index) => {
|
||||
@@ -121,4 +116,4 @@ function sanitizeArrays(array, spaces) {
|
||||
return arrayUpdated;
|
||||
}
|
||||
|
||||
module.exports = sanitizeSql;
|
||||
export default sanitizeSql;
|
||||
@@ -1,37 +0,0 @@
|
||||
export = updateDbEntry;
|
||||
/**
|
||||
* Update DB Function
|
||||
* ==============================================================================
|
||||
* @description Description
|
||||
* @async
|
||||
*
|
||||
* @param {object} params - An object containing the function parameters.
|
||||
* @param {("Master" | "Dsql User")} [params.dbContext] - What is the database context? "Master"
|
||||
* or "Dsql User". Defaults to "Master"
|
||||
* @param {("Read Only" | "Full Access")} [params.paradigm] - What is the paradigm for "Dsql User"?
|
||||
* "Read only" or "Full Access"? Defaults to "Read Only"
|
||||
* @param {string} [params.dbFullName] - Database full name
|
||||
* @param {string} params.tableName - Table name
|
||||
* @param {string} [params.encryptionKey]
|
||||
* @param {string} [params.encryptionSalt]
|
||||
* @param {any} params.data - Data to add
|
||||
* @param {import("../../../types").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
||||
* @param {string} params.identifierColumnName - Update row identifier column name
|
||||
* @param {string | number} params.identifierValue - Update row identifier column value
|
||||
* @param {boolean} [params.useLocal]
|
||||
*
|
||||
* @returns {Promise<object|null>}
|
||||
*/
|
||||
declare function updateDbEntry({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt, useLocal, }: {
|
||||
dbContext?: ("Master" | "Dsql User");
|
||||
paradigm?: ("Read Only" | "Full Access");
|
||||
dbFullName?: string;
|
||||
tableName: string;
|
||||
encryptionKey?: string;
|
||||
encryptionSalt?: string;
|
||||
data: any;
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
identifierColumnName: string;
|
||||
identifierValue: string | number;
|
||||
useLocal?: boolean;
|
||||
}): Promise<object | null>;
|
||||
+26
-46
@@ -1,39 +1,29 @@
|
||||
// @ts-check
|
||||
import sanitizeHtml from "sanitize-html";
|
||||
import sanitizeHtmlOptions from "../html/sanitizeHtmlOptions";
|
||||
import DB_HANDLER from "../../../utils/backend/global-db/DB_HANDLER";
|
||||
import DSQL_USER_DB_HANDLER from "../../../utils/backend/global-db/DSQL_USER_DB_HANDLER";
|
||||
import encrypt from "../../dsql/encrypt";
|
||||
import LOCAL_DB_HANDLER from "../../../utils/backend/global-db/LOCAL_DB_HANDLER";
|
||||
|
||||
type Param = {
|
||||
dbContext?: "Master" | "Dsql User";
|
||||
paradigm?: "Read Only" | "Full Access";
|
||||
dbFullName?: string;
|
||||
tableName: string;
|
||||
encryptionKey?: string;
|
||||
encryptionSalt?: string;
|
||||
data: any;
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
identifierColumnName: string;
|
||||
identifierValue: string | number;
|
||||
useLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Imports: Handle imports
|
||||
* # Update DB Function
|
||||
* @description
|
||||
*/
|
||||
const sanitizeHtml = require("sanitize-html");
|
||||
const sanitizeHtmlOptions = require("../html/sanitizeHtmlOptions");
|
||||
const DB_HANDLER = require("../../../utils/backend/global-db/DB_HANDLER");
|
||||
const DSQL_USER_DB_HANDLER = require("../../../utils/backend/global-db/DSQL_USER_DB_HANDLER");
|
||||
const encrypt = require("../../dsql/encrypt");
|
||||
const LOCAL_DB_HANDLER = require("../../../utils/backend/global-db/LOCAL_DB_HANDLER");
|
||||
|
||||
/**
|
||||
* Update DB Function
|
||||
* ==============================================================================
|
||||
* @description Description
|
||||
* @async
|
||||
*
|
||||
* @param {object} params - An object containing the function parameters.
|
||||
* @param {("Master" | "Dsql User")} [params.dbContext] - What is the database context? "Master"
|
||||
* or "Dsql User". Defaults to "Master"
|
||||
* @param {("Read Only" | "Full Access")} [params.paradigm] - What is the paradigm for "Dsql User"?
|
||||
* "Read only" or "Full Access"? Defaults to "Read Only"
|
||||
* @param {string} [params.dbFullName] - Database full name
|
||||
* @param {string} params.tableName - Table name
|
||||
* @param {string} [params.encryptionKey]
|
||||
* @param {string} [params.encryptionSalt]
|
||||
* @param {any} params.data - Data to add
|
||||
* @param {import("../../../types").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
||||
* @param {string} params.identifierColumnName - Update row identifier column name
|
||||
* @param {string | number} params.identifierValue - Update row identifier column value
|
||||
* @param {boolean} [params.useLocal]
|
||||
*
|
||||
* @returns {Promise<object|null>}
|
||||
*/
|
||||
async function updateDbEntry({
|
||||
export default async function updateDbEntry({
|
||||
dbContext,
|
||||
paradigm,
|
||||
dbFullName,
|
||||
@@ -45,7 +35,7 @@ async function updateDbEntry({
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
useLocal,
|
||||
}) {
|
||||
}: Param): Promise<object | null> {
|
||||
/**
|
||||
* Check if data is valid
|
||||
*/
|
||||
@@ -60,7 +50,7 @@ async function updateDbEntry({
|
||||
: true;
|
||||
|
||||
/** @type {(a1:any, a2?:any)=> any } */
|
||||
const dbHandler = useLocal
|
||||
const dbHandler: (a1: any, a2?: any) => any = useLocal
|
||||
? LOCAL_DB_HANDLER
|
||||
: isMaster
|
||||
? DB_HANDLER
|
||||
@@ -153,7 +143,7 @@ async function updateDbEntry({
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
@@ -189,18 +179,8 @@ async function updateDbEntry({
|
||||
queryValues: updateValues,
|
||||
});
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Return statement
|
||||
*/
|
||||
return updatedEntry;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
module.exports = updateDbEntry;
|
||||
+17
-22
@@ -1,10 +1,8 @@
|
||||
// @ts-check
|
||||
import fs from "fs";
|
||||
import serverError from "./serverError";
|
||||
|
||||
const fs = require("fs");
|
||||
const serverError = require("./serverError");
|
||||
|
||||
const mysql = require("serverless-mysql");
|
||||
const grabDbSSL = require("../../utils/backend/grabDbSSL");
|
||||
import mysql from "serverless-mysql";
|
||||
import grabDbSSL from "../../utils/backend/grabDbSSL";
|
||||
|
||||
const connection = mysql({
|
||||
config: {
|
||||
@@ -18,14 +16,9 @@ const connection = mysql({
|
||||
});
|
||||
|
||||
/**
|
||||
* Main DB Handler Function
|
||||
* ==============================================================================
|
||||
* @async
|
||||
*
|
||||
* @param {any} args
|
||||
* @returns {Promise<object|null>}
|
||||
* # Main DB Handler Function
|
||||
*/
|
||||
module.exports = async function dbHandler(...args) {
|
||||
export default async function dbHandler(...args: any[]) {
|
||||
process.env.NODE_ENV?.match(/dev/) &&
|
||||
fs.appendFileSync(
|
||||
"./.tmp/sqlQuery.sql",
|
||||
@@ -47,18 +40,20 @@ module.exports = async function dbHandler(...args) {
|
||||
*/
|
||||
try {
|
||||
results = await new Promise((resolve, reject) => {
|
||||
// @ts-ignore
|
||||
connection.query(...args, (error, result, fields) => {
|
||||
if (error) {
|
||||
resolve({ error: error.message });
|
||||
} else {
|
||||
resolve(result);
|
||||
connection.query(
|
||||
...args,
|
||||
(error: any, result: any, fields: any) => {
|
||||
if (error) {
|
||||
resolve({ error: error.message });
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
});
|
||||
|
||||
await connection.end();
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (error: any) {
|
||||
fs.appendFileSync(
|
||||
"./.tmp/dbErrorLogs.txt",
|
||||
JSON.stringify(error, null, 4) + "\n" + Date() + "\n\n\n",
|
||||
@@ -83,4 +78,4 @@ module.exports = async function dbHandler(...args) {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
export = defaultFieldsRegexp;
|
||||
/**
|
||||
* Regular expression to match default fields
|
||||
*
|
||||
* @description Regular expression to match default fields
|
||||
*/
|
||||
declare const defaultFieldsRegexp: RegExp;
|
||||
+1
-3
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* Regular expression to match default fields
|
||||
*
|
||||
@@ -8,4 +6,4 @@
|
||||
const defaultFieldsRegexp =
|
||||
/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/;
|
||||
|
||||
module.exports = defaultFieldsRegexp;
|
||||
export default defaultFieldsRegexp;
|
||||
@@ -1,8 +0,0 @@
|
||||
declare function _exports({ queryString, database, tableSchema, queryValuesArray, local, }: {
|
||||
queryString: string;
|
||||
database: string;
|
||||
local?: boolean;
|
||||
tableSchema?: import("../../types").DSQL_TableSchemaType | null;
|
||||
queryValuesArray?: string[];
|
||||
}): Promise<any>;
|
||||
export = _exports;
|
||||
+17
-16
@@ -1,27 +1,28 @@
|
||||
// @ts-check
|
||||
|
||||
const DSQL_USER_DB_HANDLER = require("../../utils/backend/global-db/DSQL_USER_DB_HANDLER");
|
||||
const LOCAL_DB_HANDLER = require("../../utils/backend/global-db/LOCAL_DB_HANDLER");
|
||||
const parseDbResults = require("./parseDbResults");
|
||||
const serverError = require("./serverError");
|
||||
import DSQL_USER_DB_HANDLER from "../../utils/backend/global-db/DSQL_USER_DB_HANDLER";
|
||||
import LOCAL_DB_HANDLER from "../../utils/backend/global-db/LOCAL_DB_HANDLER";
|
||||
import parseDbResults from "./parseDbResults";
|
||||
import serverError from "./serverError";
|
||||
|
||||
type Param = {
|
||||
queryString: string;
|
||||
database: string;
|
||||
local?: boolean;
|
||||
tableSchema?: import("../../types").DSQL_TableSchemaType | null;
|
||||
queryValuesArray?: string[];
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {object} param0
|
||||
* @param {string} param0.queryString
|
||||
* @param {string} param0.database
|
||||
* @param {boolean} [param0.local]
|
||||
* @param {import("../../types").DSQL_TableSchemaType | null} [param0.tableSchema]
|
||||
* @param {string[]} [param0.queryValuesArray]
|
||||
* @returns
|
||||
* # Full Access Db Handler
|
||||
*/
|
||||
module.exports = async function fullAccessDbHandler({
|
||||
export default async function fullAccessDbHandler({
|
||||
queryString,
|
||||
database,
|
||||
tableSchema,
|
||||
queryValuesArray,
|
||||
local,
|
||||
}) {
|
||||
}: Param) {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
@@ -47,7 +48,7 @@ module.exports = async function fullAccessDbHandler({
|
||||
});
|
||||
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
////////////////////////////////////////
|
||||
|
||||
serverError({
|
||||
@@ -78,4 +79,4 @@ module.exports = async function fullAccessDbHandler({
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
declare function _exports(params?: {
|
||||
payload?: {
|
||||
[x: string]: any;
|
||||
};
|
||||
}): import("../../types").DSQL_TableSchemaType | null;
|
||||
export = _exports;
|
||||
+10
-16
@@ -1,22 +1,16 @@
|
||||
// @ts-check
|
||||
|
||||
const grabSchemaFieldsFromData = require("./grabSchemaFieldsFromData");
|
||||
const serverError = require("./serverError");
|
||||
import { DSQL_FieldSchemaType, DSQL_TableSchemaType } from "../../types";
|
||||
import grabSchemaFieldsFromData from "./grabSchemaFieldsFromData";
|
||||
import serverError from "./serverError";
|
||||
|
||||
/**
|
||||
* # Add User Table to Database
|
||||
*
|
||||
* @param {object} [params]
|
||||
* @param {Object<string,any>} [params.payload] - fields to add to the table
|
||||
*
|
||||
* @returns {import("../../types").DSQL_TableSchemaType | null} new user auth object payload
|
||||
*/
|
||||
module.exports = function grabNewUsersTableSchema(params) {
|
||||
export default function grabNewUsersTableSchema(params: {
|
||||
payload?: { [s: string]: any };
|
||||
}): DSQL_TableSchemaType | null {
|
||||
try {
|
||||
/** @type {import("../../types").DSQL_TableSchemaType} */
|
||||
const userPreset = require("../../data/presets/users.json");
|
||||
/** @type {import("../../types").DSQL_FieldSchemaType[]} */
|
||||
const defaultFields = require("../../data/defaultFields.json");
|
||||
const userPreset: DSQL_TableSchemaType = require("../../data/presets/users.json");
|
||||
const defaultFields: DSQL_FieldSchemaType[] = require("../../data/defaultFields.json");
|
||||
|
||||
const supplementalFields = params?.payload
|
||||
? grabSchemaFieldsFromData({
|
||||
@@ -41,7 +35,7 @@ module.exports = function grabNewUsersTableSchema(params) {
|
||||
userPreset.fields = [...finalFields];
|
||||
|
||||
return userPreset;
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(`grabNewUsersTableSchema.js ERROR: ${error.message}`);
|
||||
|
||||
serverError({
|
||||
@@ -51,4 +45,4 @@ module.exports = function grabNewUsersTableSchema(params) {
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
declare function _exports({ data, fields, excludeData, excludeFields, }: {
|
||||
data?: {
|
||||
[x: string]: any;
|
||||
};
|
||||
fields?: string[];
|
||||
excludeData?: {
|
||||
[x: string]: any;
|
||||
};
|
||||
excludeFields?: import("../../types").DSQL_FieldSchemaType[];
|
||||
}): import("../../types").DSQL_FieldSchemaType[];
|
||||
export = _exports;
|
||||
+27
-34
@@ -1,33 +1,31 @@
|
||||
// @ts-check
|
||||
import { DSQL_FieldSchemaType } from "../../types";
|
||||
import serverError from "./serverError";
|
||||
|
||||
const serverError = require("./serverError");
|
||||
type Param = {
|
||||
data?: { [s: string]: any };
|
||||
fields?: string[];
|
||||
excludeData?: { [s: string]: any };
|
||||
excludeFields?: DSQL_FieldSchemaType[];
|
||||
};
|
||||
|
||||
/**
|
||||
* # Add User Table to Database
|
||||
*
|
||||
* @param {object} params
|
||||
* @param {Object<string,any>} [params.data]
|
||||
* @param {string[]} [params.fields]
|
||||
* @param {Object<string,any>} [params.excludeData]
|
||||
* @param {import("../../types").DSQL_FieldSchemaType[]} [params.excludeFields]
|
||||
*
|
||||
* @returns {import("../../types").DSQL_FieldSchemaType[]} new user auth object payload
|
||||
*/
|
||||
module.exports = function grabSchemaFieldsFromData({
|
||||
export default function grabSchemaFieldsFromData({
|
||||
data,
|
||||
fields,
|
||||
excludeData,
|
||||
excludeFields,
|
||||
}) {
|
||||
}: Param): DSQL_FieldSchemaType[] {
|
||||
try {
|
||||
const possibleFields = require("../../data/possibleFields.json");
|
||||
const dataTypes = require("../../data/dataTypes.json");
|
||||
|
||||
/** @type {import("../../types").DSQL_FieldSchemaType[]} */
|
||||
const finalFields = [];
|
||||
/** @type {DSQL_FieldSchemaType[]} */
|
||||
const finalFields: DSQL_FieldSchemaType[] = [];
|
||||
|
||||
/** @type {string[]} */
|
||||
let filteredFields = [];
|
||||
let filteredFields: string[] = [];
|
||||
|
||||
if (data && Object.keys(data)?.[0]) {
|
||||
filteredFields = Object.keys(data);
|
||||
@@ -52,11 +50,10 @@ module.exports = function grabSchemaFieldsFromData({
|
||||
const value = data ? data[fld] : null;
|
||||
|
||||
if (typeof value == "string") {
|
||||
const newField =
|
||||
/** @type {import("../../types").DSQL_FieldSchemaType} */ ({
|
||||
fieldName: fld,
|
||||
dataType: value.length > 255 ? "TEXT" : "VARCHAR(255)",
|
||||
});
|
||||
const newField: DSQL_FieldSchemaType = {
|
||||
fieldName: fld,
|
||||
dataType: value.length > 255 ? "TEXT" : "VARCHAR(255)",
|
||||
};
|
||||
|
||||
if (Boolean(value.match(/<[^>]+>/g))) {
|
||||
newField.richText = true;
|
||||
@@ -64,24 +61,20 @@ module.exports = function grabSchemaFieldsFromData({
|
||||
|
||||
finalFields.push(newField);
|
||||
} else if (typeof value == "number") {
|
||||
finalFields.push(
|
||||
/** @type {import("../../types").DSQL_FieldSchemaType} */ ({
|
||||
fieldName: fld,
|
||||
dataType: "INT",
|
||||
})
|
||||
);
|
||||
finalFields.push({
|
||||
fieldName: fld,
|
||||
dataType: "INT",
|
||||
});
|
||||
} else {
|
||||
finalFields.push(
|
||||
/** @type {import("../../types").DSQL_FieldSchemaType} */ ({
|
||||
fieldName: fld,
|
||||
dataType: "VARCHAR(255)",
|
||||
})
|
||||
);
|
||||
finalFields.push({
|
||||
fieldName: fld,
|
||||
dataType: "VARCHAR(255)",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return finalFields;
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(`grabSchemaFieldsFromData.js ERROR: ${error.message}`);
|
||||
|
||||
serverError({
|
||||
@@ -91,4 +84,4 @@ module.exports = function grabSchemaFieldsFromData({
|
||||
|
||||
return [];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
declare function _exports({ userId }: {
|
||||
userId: string | number;
|
||||
}): import("../../types").DSQL_DatabaseSchemaType[] | null;
|
||||
export = _exports;
|
||||
@@ -1,46 +0,0 @@
|
||||
// @ts-check
|
||||
|
||||
const serverError = require("./serverError");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* @param {Object} params
|
||||
* @param {string | number} params.userId
|
||||
* @returns {import("../../types").DSQL_DatabaseSchemaType[] | null}
|
||||
*/
|
||||
module.exports = function grabUserSchemaData({ userId }) {
|
||||
try {
|
||||
const userSchemaFilePath = path.resolve(
|
||||
process.cwd(),
|
||||
`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${userId}/main.json`
|
||||
);
|
||||
const userSchemaData = JSON.parse(
|
||||
fs.readFileSync(userSchemaFilePath, "utf-8")
|
||||
);
|
||||
|
||||
return userSchemaData;
|
||||
} catch (/** @type {any} */ error) {
|
||||
serverError({
|
||||
component: "grabUserSchemaData",
|
||||
message: error.message,
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import serverError from "./serverError";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
/**
|
||||
* # Grab User Schema Data
|
||||
*/
|
||||
export default function grabUserSchemaData({
|
||||
userId,
|
||||
}: {
|
||||
userId: string | number;
|
||||
}): import("../../types").DSQL_DatabaseSchemaType[] | null {
|
||||
try {
|
||||
const userSchemaFilePath = path.resolve(
|
||||
process.cwd(),
|
||||
`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${userId}/main.json`
|
||||
);
|
||||
const userSchemaData = JSON.parse(
|
||||
fs.readFileSync(userSchemaFilePath, "utf-8")
|
||||
);
|
||||
|
||||
return userSchemaData;
|
||||
} catch (error: any) {
|
||||
serverError({
|
||||
component: "grabUserSchemaData",
|
||||
message: error.message,
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
declare function _exports({ to, subject, text, html, alias, }: {
|
||||
to?: string;
|
||||
subject?: string;
|
||||
text?: string;
|
||||
html?: string;
|
||||
alias?: string | null;
|
||||
}): Promise<any>;
|
||||
export = _exports;
|
||||
+19
-45
@@ -1,21 +1,5 @@
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
|
||||
const fs = require("fs");
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
const nodemailer = require("nodemailer");
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
import fs from "fs";
|
||||
import nodemailer, { SendMailOptions } from "nodemailer";
|
||||
|
||||
let transporter = nodemailer.createTransport({
|
||||
host: process.env.DSQL_MAIL_HOST,
|
||||
@@ -27,31 +11,26 @@ let transporter = nodemailer.createTransport({
|
||||
},
|
||||
});
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
type Param = {
|
||||
to?: string;
|
||||
subject?: string;
|
||||
text?: string;
|
||||
html?: string;
|
||||
senderName?: string;
|
||||
alias?: string | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* # Handle mails
|
||||
* @param {object} mailObject - Mail Object with params
|
||||
* @param {string} [mailObject.to] - who is recieving this email? Comma separated for multiple recipients
|
||||
* @param {string} [mailObject.subject] - Mail Subject
|
||||
* @param {string} [mailObject.text] - Mail text
|
||||
* @param {string} [mailObject.html] - Mail HTML
|
||||
* @param {string | null} [mailObject.alias] - Sender alias: "support" or null
|
||||
*
|
||||
* @returns {Promise<any>} mail object
|
||||
* # Handle mails With Nodemailer
|
||||
*/
|
||||
module.exports = async function handleNodemailer({
|
||||
export default async function handleNodemailer({
|
||||
to,
|
||||
subject,
|
||||
text,
|
||||
html,
|
||||
alias,
|
||||
}) {
|
||||
senderName,
|
||||
}: Param): Promise<any> {
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
@@ -89,12 +68,11 @@ module.exports = async function handleNodemailer({
|
||||
////////////////////////////////////////
|
||||
|
||||
try {
|
||||
let mailObject = {};
|
||||
let mailObject: SendMailOptions = {};
|
||||
|
||||
mailObject["from"] = `"Datasquirel" <${sender}>`;
|
||||
mailObject["from"] = `"${senderName || "Datasquirel"}" <${sender}>`;
|
||||
mailObject["sender"] = sender;
|
||||
if (alias) mailObject["replyTo "] = sender;
|
||||
// mailObject["priority"] = "high";
|
||||
if (alias) mailObject["replyTo"] = sender;
|
||||
mailObject["to"] = to;
|
||||
mailObject["subject"] = subject;
|
||||
mailObject["text"] = text;
|
||||
@@ -108,7 +86,7 @@ module.exports = async function handleNodemailer({
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
@@ -122,8 +100,4 @@ module.exports = async function handleNodemailer({
|
||||
}
|
||||
|
||||
return sentMessage;
|
||||
};
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
export let allowedTags: string[];
|
||||
export let allowedAttributes: {
|
||||
a: string[];
|
||||
img: string[];
|
||||
"*": string[];
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
// @ts-check
|
||||
|
||||
const sanitizeHtmlOptions = {
|
||||
allowedTags: ["b", "i", "em", "strong", "a", "p", "span", "ul", "ol", "li", "h1", "h2", "h3", "h4", "h5", "h6", "img", "div", "button", "pre", "code", "br"],
|
||||
allowedAttributes: {
|
||||
a: ["href"],
|
||||
img: ["src", "alt", "width", "height", "class", "style"],
|
||||
"*": ["style", "class"],
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = sanitizeHtmlOptions;
|
||||
@@ -0,0 +1,35 @@
|
||||
// @ts-check
|
||||
|
||||
const sanitizeHtmlOptions = {
|
||||
allowedTags: [
|
||||
"b",
|
||||
"i",
|
||||
"em",
|
||||
"strong",
|
||||
"a",
|
||||
"p",
|
||||
"span",
|
||||
"ul",
|
||||
"ol",
|
||||
"li",
|
||||
"h1",
|
||||
"h2",
|
||||
"h3",
|
||||
"h4",
|
||||
"h5",
|
||||
"h6",
|
||||
"img",
|
||||
"div",
|
||||
"button",
|
||||
"pre",
|
||||
"code",
|
||||
"br",
|
||||
],
|
||||
allowedAttributes: {
|
||||
a: ["href"],
|
||||
img: ["src", "alt", "width", "height", "class", "style"],
|
||||
"*": ["style", "class"],
|
||||
},
|
||||
};
|
||||
|
||||
export default sanitizeHtmlOptions;
|
||||
@@ -1,6 +0,0 @@
|
||||
export = httpRequest;
|
||||
/**
|
||||
* # Generate a http Request
|
||||
* @type {import("../../types").HttpRequestFunction}
|
||||
*/
|
||||
declare const httpRequest: import("../../types").HttpRequestFunction;
|
||||
+15
-16
@@ -1,16 +1,17 @@
|
||||
// @ts-check
|
||||
|
||||
const http = require("node:http");
|
||||
const https = require("node:https");
|
||||
const querystring = require("querystring");
|
||||
const serializeQuery = require("../../utils/serialize-query");
|
||||
const _ = require("lodash");
|
||||
import http from "node:http";
|
||||
import https from "node:https";
|
||||
import querystring from "querystring";
|
||||
import serializeQuery from "../../utils/serialize-query";
|
||||
import _ from "lodash";
|
||||
import { HttpFunctionResponse, HttpRequestParams } from "../../types";
|
||||
|
||||
/**
|
||||
* # Generate a http Request
|
||||
* @type {import("../../types").HttpRequestFunction}
|
||||
*/
|
||||
const httpRequest = (params) => {
|
||||
export default function httpRequest<
|
||||
ReqObj extends { [k: string]: any } = { [k: string]: any },
|
||||
ResObj extends { [k: string]: any } = { [k: string]: any }
|
||||
>(params: HttpRequestParams<ReqObj>): Promise<HttpFunctionResponse<ResObj>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const isUrlEncodedFormBody = params.urlEncodedFormBody;
|
||||
|
||||
@@ -37,7 +38,7 @@ const httpRequest = (params) => {
|
||||
delete params.urlEncodedFormBody;
|
||||
|
||||
/** @type {import("node:https").RequestOptions} */
|
||||
const requestOptions = {
|
||||
const requestOptions: import("node:https").RequestOptions = {
|
||||
...params,
|
||||
headers: {
|
||||
"Content-Type": isUrlEncodedFormBody
|
||||
@@ -69,13 +70,13 @@ const httpRequest = (params) => {
|
||||
response.on("end", function () {
|
||||
const data = (() => {
|
||||
try {
|
||||
/** @type {Object<string,any>} */
|
||||
const jsonObj = JSON.parse(str);
|
||||
const jsonObj: { [k: string]: any } =
|
||||
JSON.parse(str);
|
||||
return jsonObj;
|
||||
} catch (error) {
|
||||
return undefined;
|
||||
}
|
||||
})();
|
||||
})() as any;
|
||||
|
||||
resolve({
|
||||
status: response.statusCode || 404,
|
||||
@@ -106,6 +107,4 @@ const httpRequest = (params) => {
|
||||
|
||||
httpsRequest.end();
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = httpRequest;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
declare function _exports({ url, method, hostname, path, headers, body, port, scheme, }: {
|
||||
scheme?: string;
|
||||
url?: string;
|
||||
method?: string;
|
||||
hostname?: string;
|
||||
path?: string;
|
||||
port?: number | string;
|
||||
headers?: object;
|
||||
body?: object;
|
||||
}): Promise<any>;
|
||||
export = _exports;
|
||||
+19
-43
@@ -1,35 +1,22 @@
|
||||
// @ts-check
|
||||
import https from "https";
|
||||
import http from "http";
|
||||
import { URL } from "url";
|
||||
|
||||
type Param = {
|
||||
scheme?: string;
|
||||
url?: string;
|
||||
method?: string;
|
||||
hostname?: string;
|
||||
path?: string;
|
||||
port?: number | string;
|
||||
headers?: object;
|
||||
body?: object;
|
||||
};
|
||||
|
||||
/**
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
* # Make Https Request
|
||||
*/
|
||||
const https = require("https");
|
||||
const http = require("http");
|
||||
const { URL } = require("url");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Main Function
|
||||
* ==============================================================================
|
||||
* @param {{
|
||||
* scheme?: string,
|
||||
* url?: string,
|
||||
* method?: string,
|
||||
* hostname?: string,
|
||||
* path?: string,
|
||||
* port?: number | string,
|
||||
* headers?: object,
|
||||
* body?: object,
|
||||
* }} params - params
|
||||
*/
|
||||
module.exports = function httpsRequest({
|
||||
export default function httpsRequest({
|
||||
url,
|
||||
method,
|
||||
hostname,
|
||||
@@ -38,7 +25,7 @@ module.exports = function httpsRequest({
|
||||
body,
|
||||
port,
|
||||
scheme,
|
||||
}) {
|
||||
}: Param) {
|
||||
const reqPayloadString = body ? JSON.stringify(body) : null;
|
||||
|
||||
const PARSED_URL = url ? new URL(url) : null;
|
||||
@@ -48,7 +35,7 @@ module.exports = function httpsRequest({
|
||||
////////////////////////////////////////////////
|
||||
|
||||
/** @type {any} */
|
||||
let requestOptions = {
|
||||
let requestOptions: any = {
|
||||
method: method || "GET",
|
||||
hostname: PARSED_URL ? PARSED_URL.hostname : hostname,
|
||||
port: scheme?.match(/https/i)
|
||||
@@ -126,16 +113,5 @@ module.exports = function httpsRequest({
|
||||
});
|
||||
|
||||
httpsRequest.end();
|
||||
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
});
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
+9
-12
@@ -1,16 +1,13 @@
|
||||
// @ts-check
|
||||
|
||||
const fs = require("fs");
|
||||
const serverError = require("./serverError");
|
||||
const NO_DB_HANDLER = require("../../../package-shared/utils/backend/global-db/NO_DB_HANDLER");
|
||||
import fs from "fs";
|
||||
import serverError from "./serverError";
|
||||
import NO_DB_HANDLER from "../../../package-shared/utils/backend/global-db/NO_DB_HANDLER";
|
||||
|
||||
/**
|
||||
* Create database from Schema Function
|
||||
* ==============================================================================
|
||||
* @param {string} queryString - Query String
|
||||
* @returns {Promise<any>}
|
||||
* # No Database DB Handler
|
||||
*/
|
||||
module.exports = async function noDatabaseDbHandler(queryString) {
|
||||
export default async function noDatabaseDbHandler(
|
||||
queryString: string
|
||||
): Promise<any> {
|
||||
process.env.NODE_ENV?.match(/dev/) &&
|
||||
fs.appendFileSync(
|
||||
"./.tmp/sqlQuery.sql",
|
||||
@@ -37,7 +34,7 @@ module.exports = async function noDatabaseDbHandler(queryString) {
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
serverError({
|
||||
component: "noDatabaseDbHandler",
|
||||
message: error.message,
|
||||
@@ -56,4 +53,4 @@ module.exports = async function noDatabaseDbHandler(queryString) {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
declare function _exports({ unparsedResults, tableSchema, }: {
|
||||
unparsedResults: any[];
|
||||
tableSchema?: import("../../types").DSQL_TableSchemaType;
|
||||
}): Promise<object[] | null>;
|
||||
export = _exports;
|
||||
+11
-12
@@ -1,7 +1,12 @@
|
||||
// @ts-check
|
||||
|
||||
const decrypt = require("../dsql/decrypt");
|
||||
const defaultFieldsRegexp = require("./defaultFieldsRegexp");
|
||||
import decrypt from "../dsql/decrypt";
|
||||
import defaultFieldsRegexp from "./defaultFieldsRegexp";
|
||||
|
||||
type Param = {
|
||||
unparsedResults: any[];
|
||||
tableSchema?: import("../../types").DSQL_TableSchemaType;
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse Database results
|
||||
@@ -9,17 +14,11 @@ const defaultFieldsRegexp = require("./defaultFieldsRegexp");
|
||||
* @description this function takes a database results array gotten from a DB handler
|
||||
* function, decrypts encrypted fields, and returns an updated array with no encrypted
|
||||
* fields
|
||||
*
|
||||
* @param {object} params - Single object params
|
||||
* @param {any[]} params.unparsedResults - Array of data objects containing Fields(keys)
|
||||
* and corresponding values of the fields(values)
|
||||
* @param {import("../../types").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
||||
* @returns {Promise<object[]|null>}
|
||||
*/
|
||||
module.exports = async function parseDbResults({
|
||||
export default async function parseDbResults({
|
||||
unparsedResults,
|
||||
tableSchema,
|
||||
}) {
|
||||
}: Param): Promise<any[] | null> {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
@@ -71,8 +70,8 @@ module.exports = async function parseDbResults({
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
return parsedResults;
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log("ERROR in parseDbResults Function =>", error.message);
|
||||
return unparsedResults;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
declare function _exports({ user, message, component, noMail, req, }: {
|
||||
user?: {
|
||||
id?: number | string;
|
||||
first_name?: string;
|
||||
last_name?: string;
|
||||
email?: string;
|
||||
} & any;
|
||||
message: string;
|
||||
component?: string;
|
||||
noMail?: boolean;
|
||||
req?: import("next").NextApiRequest & IncomingMessage;
|
||||
}): Promise<void>;
|
||||
export = _exports;
|
||||
import { IncomingMessage } from "http";
|
||||
+19
-16
@@ -1,28 +1,31 @@
|
||||
// @ts-check
|
||||
|
||||
const fs = require("fs");
|
||||
const { IncomingMessage } = require("http");
|
||||
import fs from "fs";
|
||||
import { IncomingMessage } from "http";
|
||||
|
||||
type Param = {
|
||||
user?: {
|
||||
id?: number | string;
|
||||
first_name?: string;
|
||||
last_name?: string;
|
||||
email?: string;
|
||||
} & any;
|
||||
message: string;
|
||||
component?: string;
|
||||
noMail?: boolean;
|
||||
req?: import("next").NextApiRequest & IncomingMessage;
|
||||
};
|
||||
|
||||
/**
|
||||
* # Server Error
|
||||
*
|
||||
* @param {{
|
||||
* user?: { id?: number | string, first_name?: string, last_name?: string, email?: string } & *,
|
||||
* message: string,
|
||||
* component?: string,
|
||||
* noMail?: boolean,
|
||||
* req?: import("next").NextApiRequest & IncomingMessage,
|
||||
* }} params - user id
|
||||
*
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
module.exports = async function serverError({
|
||||
export default async function serverError({
|
||||
user,
|
||||
message,
|
||||
component,
|
||||
noMail,
|
||||
req,
|
||||
}) {
|
||||
}: Param): Promise<void> {
|
||||
const date = new Date();
|
||||
|
||||
const reqIp = (() => {
|
||||
@@ -80,10 +83,10 @@ module.exports = async function serverError({
|
||||
|
||||
fs.writeFileSync(`./.tmp/error.log`, log);
|
||||
fs.appendFileSync(`./.tmp/error.log`, `\n\n\n\n\n${initialText}`);
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log("Server Error Reporting Error:", error.message);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
@@ -1,5 +0,0 @@
|
||||
declare function _exports({ userId, schemaData }: {
|
||||
userId: string | number;
|
||||
schemaData: import("../../types").DSQL_DatabaseSchemaType[];
|
||||
}): boolean;
|
||||
export = _exports;
|
||||
@@ -1,49 +0,0 @@
|
||||
// @ts-check
|
||||
|
||||
const serverError = require("./serverError");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* @param {Object} params
|
||||
* @param {string | number} params.userId
|
||||
* @param {import("../../types").DSQL_DatabaseSchemaType[]} params.schemaData
|
||||
* @returns {boolean}
|
||||
*/
|
||||
module.exports = function setUserSchemaData({ userId, schemaData }) {
|
||||
try {
|
||||
const userSchemaFilePath = path.resolve(
|
||||
process.cwd(),
|
||||
`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${userId}/main.json`
|
||||
);
|
||||
fs.writeFileSync(
|
||||
userSchemaFilePath,
|
||||
JSON.stringify(schemaData),
|
||||
"utf8"
|
||||
);
|
||||
|
||||
return true;
|
||||
} catch (/** @type {any} */ error) {
|
||||
serverError({
|
||||
component: "/functions/backend/setUserSchemaData",
|
||||
message: error.message,
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import serverError from "./serverError";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { DSQL_DatabaseSchemaType } from "../../types";
|
||||
|
||||
type Param = {
|
||||
userId: string | number;
|
||||
schemaData: DSQL_DatabaseSchemaType[];
|
||||
};
|
||||
|
||||
/**
|
||||
* # Set User Schema Data
|
||||
*/
|
||||
export default function setUserSchemaData({
|
||||
userId,
|
||||
schemaData,
|
||||
}: Param): boolean {
|
||||
try {
|
||||
const userSchemaFilePath = path.resolve(
|
||||
process.cwd(),
|
||||
`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${userId}/main.json`
|
||||
);
|
||||
fs.writeFileSync(
|
||||
userSchemaFilePath,
|
||||
JSON.stringify(schemaData),
|
||||
"utf8"
|
||||
);
|
||||
|
||||
return true;
|
||||
} catch (error: any) {
|
||||
serverError({
|
||||
component: "/functions/backend/setUserSchemaData",
|
||||
message: error.message,
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
+12
-12
@@ -1,17 +1,17 @@
|
||||
// @ts-check
|
||||
|
||||
const { IncomingMessage } = require("http");
|
||||
const parseCookies = require("../../utils/backend/parseCookies");
|
||||
const decrypt = require("../dsql/decrypt");
|
||||
const getAuthCookieNames = require("./cookies/get-auth-cookie-names");
|
||||
import { IncomingMessage } from "http";
|
||||
import parseCookies from "../../utils/backend/parseCookies";
|
||||
import decrypt from "../dsql/decrypt";
|
||||
import getAuthCookieNames from "./cookies/get-auth-cookie-names";
|
||||
|
||||
/**
|
||||
* @async
|
||||
* @param {IncomingMessage} req - https request object
|
||||
*
|
||||
* @returns {Promise<({ email: string, password: string, authKey: string, logged_in_status: boolean, date: number } | null)>}
|
||||
*/
|
||||
module.exports = async function (req) {
|
||||
export default async function (req: IncomingMessage): Promise<{
|
||||
email: string;
|
||||
password: string;
|
||||
authKey: string;
|
||||
logged_in_status: boolean;
|
||||
date: number;
|
||||
} | null> {
|
||||
const { keyCookieName, csrfCookieName } = getAuthCookieNames();
|
||||
const suKeyName = `${keyCookieName}_su`;
|
||||
|
||||
@@ -40,4 +40,4 @@ module.exports = async function (req) {
|
||||
|
||||
/** ********************* return user object */
|
||||
return userObject;
|
||||
};
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
declare function _exports({ userId, database, newFields, newPayload, }: {
|
||||
userId: number | string;
|
||||
database: string;
|
||||
newFields?: string[];
|
||||
newPayload?: {
|
||||
[x: string]: any;
|
||||
};
|
||||
}): Promise<any>;
|
||||
export = _exports;
|
||||
+15
-18
@@ -1,28 +1,25 @@
|
||||
// @ts-check
|
||||
import serverError from "./serverError";
|
||||
import grabUserSchemaData from "./grabUserSchemaData";
|
||||
import setUserSchemaData from "./setUserSchemaData";
|
||||
import createDbFromSchema from "../../shell/createDbFromSchema";
|
||||
import grabSchemaFieldsFromData from "./grabSchemaFieldsFromData";
|
||||
|
||||
const serverError = require("./serverError");
|
||||
const grabUserSchemaData = require("./grabUserSchemaData");
|
||||
const setUserSchemaData = require("./setUserSchemaData");
|
||||
const createDbFromSchema = require("../../shell/createDbFromSchema");
|
||||
const grabSchemaFieldsFromData = require("./grabSchemaFieldsFromData");
|
||||
type Param = {
|
||||
userId: number | string;
|
||||
database: string;
|
||||
newFields?: string[];
|
||||
newPayload?: { [s: string]: any };
|
||||
};
|
||||
|
||||
/**
|
||||
* # Add User Table to Database
|
||||
*
|
||||
* @param {object} params
|
||||
* @param {number | string} params.userId - user id
|
||||
* @param {string} params.database
|
||||
* @param {string[]} [params.newFields] - new fields to add to the users table
|
||||
* @param {Object<string, any>} [params.newPayload]
|
||||
*
|
||||
* @returns {Promise<any>} new user auth object payload
|
||||
*/
|
||||
module.exports = async function updateUsersTableSchema({
|
||||
export default async function updateUsersTableSchema({
|
||||
userId,
|
||||
database,
|
||||
newFields,
|
||||
newPayload,
|
||||
}) {
|
||||
}: Param): Promise<any> {
|
||||
try {
|
||||
const dbFullName = database;
|
||||
|
||||
@@ -67,7 +64,7 @@ module.exports = async function updateUsersTableSchema({
|
||||
});
|
||||
|
||||
return `Done!`;
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (error: any) {
|
||||
console.log(`addUsersTableToDb.js ERROR: ${error.message}`);
|
||||
|
||||
serverError({
|
||||
@@ -77,4 +74,4 @@ module.exports = async function updateUsersTableSchema({
|
||||
});
|
||||
return error.message;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
declare function _exports({ queryString, queryValuesArray, database, tableSchema, useLocal, }: {
|
||||
queryString: string;
|
||||
queryValuesArray?: any[];
|
||||
database?: string;
|
||||
tableSchema?: import("../../types").DSQL_TableSchemaType;
|
||||
useLocal?: boolean;
|
||||
}): Promise<any>;
|
||||
export = _exports;
|
||||
+19
-35
@@ -1,31 +1,27 @@
|
||||
// @ts-check
|
||||
import parseDbResults from "./parseDbResults";
|
||||
import serverError from "./serverError";
|
||||
import DB_HANDLER from "../../utils/backend/global-db/DB_HANDLER";
|
||||
import DSQL_USER_DB_HANDLER from "../../utils/backend/global-db/DSQL_USER_DB_HANDLER";
|
||||
import LOCAL_DB_HANDLER from "../../utils/backend/global-db/LOCAL_DB_HANDLER";
|
||||
|
||||
const fs = require("fs");
|
||||
const parseDbResults = require("./parseDbResults");
|
||||
const serverError = require("./serverError");
|
||||
const DB_HANDLER = require("../../utils/backend/global-db/DB_HANDLER");
|
||||
const DSQL_USER_DB_HANDLER = require("../../utils/backend/global-db/DSQL_USER_DB_HANDLER");
|
||||
const LOCAL_DB_HANDLER = require("../../utils/backend/global-db/LOCAL_DB_HANDLER");
|
||||
type Param = {
|
||||
queryString: string;
|
||||
queryValuesArray?: any[];
|
||||
database?: string;
|
||||
tableSchema?: import("../../types").DSQL_TableSchemaType;
|
||||
useLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* DB handler for specific database
|
||||
* ==============================================================================
|
||||
* @async
|
||||
* @param {object} params - Single object params
|
||||
* @param {string} params.queryString - SQL string
|
||||
* @param {*[]} [params.queryValuesArray] - Values Array
|
||||
* @param {string} [params.database] - Database name
|
||||
* @param {import("../../types").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
||||
* @param {boolean} [params.useLocal]
|
||||
* @returns {Promise<any>}
|
||||
* # DB handler for specific database
|
||||
*/
|
||||
module.exports = async function varDatabaseDbHandler({
|
||||
export default async function varDatabaseDbHandler({
|
||||
queryString,
|
||||
queryValuesArray,
|
||||
database,
|
||||
tableSchema,
|
||||
useLocal,
|
||||
}) {
|
||||
}: Param): Promise<any> {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
@@ -38,7 +34,7 @@ module.exports = async function varDatabaseDbHandler({
|
||||
: false;
|
||||
|
||||
/** @type {any} */
|
||||
const FINAL_DB_HANDLER = useLocal
|
||||
const FINAL_DB_HANDLER: any = useLocal
|
||||
? LOCAL_DB_HANDLER
|
||||
: isMaster
|
||||
? DB_HANDLER
|
||||
@@ -75,11 +71,7 @@ module.exports = async function varDatabaseDbHandler({
|
||||
queryString,
|
||||
});
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (error: any) {
|
||||
serverError({
|
||||
component: "varDatabaseDbHandler/lines-29-32",
|
||||
message: error.message,
|
||||
@@ -99,7 +91,7 @@ module.exports = async function varDatabaseDbHandler({
|
||||
tableSchema: tableSchema,
|
||||
});
|
||||
return parsedResults;
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (error: any) {
|
||||
console.log(
|
||||
"\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",
|
||||
database,
|
||||
@@ -111,17 +103,9 @@ module.exports = async function varDatabaseDbHandler({
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} else if (results) {
|
||||
return results;
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
declare function _exports({ queryString, database, queryValuesArray, tableSchema, useLocal, }: {
|
||||
queryString: string;
|
||||
database: string;
|
||||
queryValuesArray?: string[];
|
||||
tableSchema?: import("../../types").DSQL_TableSchemaType;
|
||||
useLocal?: boolean;
|
||||
}): Promise<any>;
|
||||
export = _exports;
|
||||
+18
-16
@@ -1,28 +1,30 @@
|
||||
// @ts-check
|
||||
|
||||
const fs = require("fs");
|
||||
const serverError = require("./serverError");
|
||||
const parseDbResults = require("./parseDbResults");
|
||||
const DSQL_USER_DB_HANDLER = require("../../utils/backend/global-db/DSQL_USER_DB_HANDLER");
|
||||
const LOCAL_DB_HANDLER = require("../../utils/backend/global-db/LOCAL_DB_HANDLER");
|
||||
import fs from "fs";
|
||||
import serverError from "./serverError";
|
||||
import parseDbResults from "./parseDbResults";
|
||||
import DSQL_USER_DB_HANDLER from "../../utils/backend/global-db/DSQL_USER_DB_HANDLER";
|
||||
import LOCAL_DB_HANDLER from "../../utils/backend/global-db/LOCAL_DB_HANDLER";
|
||||
|
||||
type Param = {
|
||||
queryString: string;
|
||||
database: string;
|
||||
queryValuesArray?: string[];
|
||||
tableSchema?: import("../../types").DSQL_TableSchemaType;
|
||||
useLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {object} param0
|
||||
* @param {string} param0.queryString
|
||||
* @param {string} param0.database
|
||||
* @param {string[]} [param0.queryValuesArray]
|
||||
* @param {import("../../types").DSQL_TableSchemaType} [param0.tableSchema]
|
||||
* @param {boolean} [param0.useLocal]
|
||||
* # Read Only Db Handler with Varaibles
|
||||
* @returns
|
||||
*/
|
||||
module.exports = async function varReadOnlyDatabaseDbHandler({
|
||||
export default async function varReadOnlyDatabaseDbHandler({
|
||||
queryString,
|
||||
database,
|
||||
queryValuesArray,
|
||||
tableSchema,
|
||||
useLocal,
|
||||
}) {
|
||||
}: Param) {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
@@ -46,7 +48,7 @@ module.exports = async function varReadOnlyDatabaseDbHandler({
|
||||
});
|
||||
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
////////////////////////////////////////
|
||||
|
||||
serverError({
|
||||
@@ -76,4 +78,4 @@ module.exports = async function varReadOnlyDatabaseDbHandler({
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user