Updates
This commit is contained in:
@@ -32,7 +32,7 @@ module.exports = async function addMariadbUser({ userId, useLocal }) {
|
||||
});
|
||||
const encryptedPassword = encrypt({ data: password });
|
||||
|
||||
const createMariadbUsersQuery = `CREATE USER IF NOT EXISTS '${username}'@'127.0.0.1' IDENTIFIED BY '${password}' REQUIRE SSL`;
|
||||
const createMariadbUsersQuery = `CREATE USER IF NOT EXISTS '${username}'@'127.0.0.1' IDENTIFIED BY '${password}'`;
|
||||
|
||||
if (useLocal) {
|
||||
await LOCAL_DB_HANDLER(createMariadbUsersQuery);
|
||||
|
||||
@@ -1,37 +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
|
||||
*
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
declare function addDbEntry({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt, }: {
|
||||
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;
|
||||
}): Promise<any>;
|
||||
@@ -1,32 +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
|
||||
*
|
||||
* @returns {Promise<object|null>}
|
||||
*/
|
||||
declare function deleteDbEntry({ dbContext, paradigm, dbFullName, tableName, identifierColumnName, identifierValue, }: {
|
||||
dbContext?: string;
|
||||
paradigm?: ("Read Only" | "Full Access");
|
||||
dbFullName: string;
|
||||
tableName: string;
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
identifierColumnName: string;
|
||||
identifierValue: string | number;
|
||||
}): Promise<object | null>;
|
||||
@@ -1,30 +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[]} [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[];
|
||||
tableName?: string;
|
||||
}): Promise<any>;
|
||||
@@ -1,35 +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
|
||||
*
|
||||
* @returns {Promise<object|null>}
|
||||
*/
|
||||
declare function updateDbEntry({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt, }: {
|
||||
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;
|
||||
}): Promise<object | null>;
|
||||
@@ -1,6 +0,0 @@
|
||||
export = decrypt;
|
||||
/**
|
||||
* @param {string} encryptedString
|
||||
* @returns {string | null}
|
||||
*/
|
||||
declare function decrypt(encryptedString: string): string | null;
|
||||
@@ -1,29 +0,0 @@
|
||||
// @ts-check
|
||||
|
||||
const { scryptSync, createDecipheriv } = require("crypto");
|
||||
const { Buffer } = require("buffer");
|
||||
|
||||
/**
|
||||
* @param {string} encryptedString
|
||||
* @returns {string | null}
|
||||
*/
|
||||
const decrypt = (encryptedString) => {
|
||||
const algorithm = "aes-192-cbc";
|
||||
const password = process.env.DSQL_ENCRYPTION_PASSWORD || "";
|
||||
const salt = process.env.DSQL_ENCRYPTION_SALT || "";
|
||||
|
||||
let key = scryptSync(password, salt, 24);
|
||||
let iv = Buffer.alloc(16, 0);
|
||||
// @ts-ignore
|
||||
const decipher = createDecipheriv(algorithm, key, iv);
|
||||
|
||||
try {
|
||||
let decrypted = decipher.update(encryptedString, "hex", "utf8");
|
||||
decrypted += decipher.final("utf8");
|
||||
return decrypted;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = decrypt;
|
||||
@@ -1,7 +0,0 @@
|
||||
export = defaultFieldsRegexp;
|
||||
/**
|
||||
* Regular expression to match default fields
|
||||
*
|
||||
* @description Regular expression to match default fields
|
||||
*/
|
||||
declare const defaultFieldsRegexp: RegExp;
|
||||
@@ -1,9 +0,0 @@
|
||||
export = encrypt;
|
||||
/**
|
||||
* @async
|
||||
* @param {string} data
|
||||
* @param {string} [encryptionKey]
|
||||
* @param {string} [encryptionSalt]
|
||||
* @returns {string | null}
|
||||
*/
|
||||
declare function encrypt(data: string, encryptionKey?: string, encryptionSalt?: string): string | null;
|
||||
@@ -1,43 +0,0 @@
|
||||
// @ts-check
|
||||
|
||||
const { scryptSync, createCipheriv } = require("crypto");
|
||||
const { Buffer } = require("buffer");
|
||||
const serverError = require("./serverError");
|
||||
|
||||
/**
|
||||
* @async
|
||||
* @param {string} data
|
||||
* @param {string} [encryptionKey]
|
||||
* @param {string} [encryptionSalt]
|
||||
* @returns {string | null}
|
||||
*/
|
||||
const encrypt = (data, encryptionKey, encryptionSalt) => {
|
||||
const algorithm = "aes-192-cbc";
|
||||
const password = encryptionKey
|
||||
? encryptionKey
|
||||
: process.env.DSQL_ENCRYPTION_PASSWORD || "";
|
||||
|
||||
/** ********************* Generate key */
|
||||
const salt = encryptionSalt
|
||||
? encryptionSalt
|
||||
: process.env.DSQL_ENCRYPTION_SALT || "";
|
||||
let key = scryptSync(password, salt, 24);
|
||||
let iv = Buffer.alloc(16, 0);
|
||||
// @ts-ignore
|
||||
const cipher = createCipheriv(algorithm, key, iv);
|
||||
|
||||
/** ********************* Encrypt data */
|
||||
try {
|
||||
let encrypted = cipher.update(data, "utf8", "hex");
|
||||
encrypted += cipher.final("hex");
|
||||
return encrypted;
|
||||
} catch (/** @type {any} */ error) {
|
||||
serverError({
|
||||
component: "encrypt",
|
||||
message: error.message,
|
||||
});
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = encrypt;
|
||||
@@ -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;
|
||||
@@ -1,6 +0,0 @@
|
||||
export let allowedTags: string[];
|
||||
export let allowedAttributes: {
|
||||
a: string[];
|
||||
img: string[];
|
||||
"*": string[];
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
declare function _exports({ unparsedResults, tableSchema, }: {
|
||||
unparsedResults: any[];
|
||||
tableSchema?: import("../../types").DSQL_TableSchemaType;
|
||||
}): Promise<object[] | null>;
|
||||
export = _exports;
|
||||
@@ -1,31 +0,0 @@
|
||||
// @ts-check
|
||||
|
||||
const { createHmac } = require("crypto");
|
||||
//
|
||||
|
||||
/**
|
||||
* # Password Hash function
|
||||
* @param {string} password
|
||||
* @returns
|
||||
*/
|
||||
function hashPassword(password) {
|
||||
const hmac = createHmac(
|
||||
"sha512",
|
||||
process.env.DSQL_ENCRYPTION_PASSWORD || ""
|
||||
);
|
||||
hmac.update(password);
|
||||
let hashed = hmac.digest("base64");
|
||||
return hashed;
|
||||
}
|
||||
|
||||
exports.hashPassword = hashPassword;
|
||||
|
||||
// export const comparePasswords = async (password) => {
|
||||
// const hmac = createHmac("sha512", process.env.DSQL_ENCRYPTION_PASSWORD);
|
||||
// hmac.update(password);
|
||||
// let hashed = hmac.digest("base64");
|
||||
|
||||
// let dbPass = await global.DB_HANDLER(`SELECT * FROM users WHERE password = '${hashed}'`);
|
||||
// console.log(dbPass);
|
||||
// return dbPass;
|
||||
// };
|
||||
@@ -1,12 +0,0 @@
|
||||
declare function _exports({ user, message, component, noMail, }: {
|
||||
user?: {
|
||||
id?: number | string;
|
||||
first_name?: string;
|
||||
last_name?: string;
|
||||
email?: string;
|
||||
} & any;
|
||||
message: string;
|
||||
component?: string;
|
||||
noMail?: boolean;
|
||||
}): Promise<void>;
|
||||
export = _exports;
|
||||
@@ -1,7 +0,0 @@
|
||||
declare function _exports({ queryString, database, queryValuesArray, tableSchema, }: {
|
||||
queryString: string;
|
||||
database: string;
|
||||
queryValuesArray?: string[];
|
||||
tableSchema?: import("../../types").DSQL_TableSchemaType;
|
||||
}): Promise<any>;
|
||||
export = _exports;
|
||||
Reference in New Issue
Block a user