Updates
This commit is contained in:
parent
7ffa5c0da5
commit
aaa604c66b
@ -51,7 +51,7 @@ async function localGet({ options, dbSchema }) {
|
|||||||
(query.match(
|
(query.match(
|
||||||
/^alter|^delete|information_schema|databases|^create/i
|
/^alter|^delete|information_schema|databases|^create/i
|
||||||
) ||
|
) ||
|
||||||
!query.match(/^select/i))
|
!query.match(/^select|^\( ?select/i))
|
||||||
) {
|
) {
|
||||||
return { success: false, msg: "Wrong Input" };
|
return { success: false, msg: "Wrong Input" };
|
||||||
}
|
}
|
||||||
|
62
package-lock.json
generated
62
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "2.6.5",
|
"version": "2.6.7",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "2.6.5",
|
"version": "2.6.7",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/ace": "^0.0.52",
|
"@types/ace": "^0.0.52",
|
||||||
@ -15,7 +15,6 @@
|
|||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
"generate-password": "^1.7.1",
|
"generate-password": "^1.7.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"mariadb": "^3.4.0",
|
|
||||||
"mysql": "^2.18.1",
|
"mysql": "^2.18.1",
|
||||||
"nodemailer": "^6.9.14",
|
"nodemailer": "^6.9.14",
|
||||||
"sanitize-html": "^2.13.1",
|
"sanitize-html": "^2.13.1",
|
||||||
@ -37,12 +36,6 @@
|
|||||||
"integrity": "sha512-YPF9S7fzpuyrxru+sG/rrTpZkC6gpHBPF14W3x70kqVOD+ks6jkYLapk4yceh36xej7K4HYxcyz9ZDQ2lTvwgQ==",
|
"integrity": "sha512-YPF9S7fzpuyrxru+sG/rrTpZkC6gpHBPF14W3x70kqVOD+ks6jkYLapk4yceh36xej7K4HYxcyz9ZDQ2lTvwgQ==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@types/geojson": {
|
|
||||||
"version": "7946.0.14",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-7946.0.14.tgz",
|
|
||||||
"integrity": "sha512-WCfD5Ht3ZesJUsONdhvm84dmzWOiOzOAqOncN0++w0lBw1o8OuDNJF2McvvCef/yBqb/HYRahp1BYtODFQ8bRg==",
|
|
||||||
"license": "MIT"
|
|
||||||
},
|
|
||||||
"node_modules/@types/jquery": {
|
"node_modules/@types/jquery": {
|
||||||
"version": "3.5.32",
|
"version": "3.5.32",
|
||||||
"resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.5.32.tgz",
|
"resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.5.32.tgz",
|
||||||
@ -72,6 +65,7 @@
|
|||||||
"version": "22.7.5",
|
"version": "22.7.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.5.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.5.tgz",
|
||||||
"integrity": "sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ==",
|
"integrity": "sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ==",
|
||||||
|
"devOptional": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"undici-types": "~6.19.2"
|
"undici-types": "~6.19.2"
|
||||||
@ -136,15 +130,6 @@
|
|||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/denque": {
|
|
||||||
"version": "2.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz",
|
|
||||||
"integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==",
|
|
||||||
"license": "Apache-2.0",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.10"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/dom-serializer": {
|
"node_modules/dom-serializer": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz",
|
||||||
@ -260,18 +245,6 @@
|
|||||||
"entities": "^4.4.0"
|
"entities": "^4.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/iconv-lite": {
|
|
||||||
"version": "0.6.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
|
|
||||||
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"safer-buffer": ">= 2.1.2 < 3.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.10.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/inherits": {
|
"node_modules/inherits": {
|
||||||
"version": "2.0.4",
|
"version": "2.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||||
@ -297,28 +270,6 @@
|
|||||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/lru-cache": {
|
|
||||||
"version": "10.4.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz",
|
|
||||||
"integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==",
|
|
||||||
"license": "ISC"
|
|
||||||
},
|
|
||||||
"node_modules/mariadb": {
|
|
||||||
"version": "3.4.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/mariadb/-/mariadb-3.4.0.tgz",
|
|
||||||
"integrity": "sha512-hdRPcAzs+MTxK5VG1thBW18gGTlw6yWBe9YnLB65GLo7q0fO5DWsgomIevV/pXSaWRmD3qi6ka4oSFRTExRiEQ==",
|
|
||||||
"license": "LGPL-2.1-or-later",
|
|
||||||
"dependencies": {
|
|
||||||
"@types/geojson": "^7946.0.14",
|
|
||||||
"@types/node": "^22.5.4",
|
|
||||||
"denque": "^2.1.0",
|
|
||||||
"iconv-lite": "^0.6.3",
|
|
||||||
"lru-cache": "^10.3.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 14"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/mysql": {
|
"node_modules/mysql": {
|
||||||
"version": "2.18.1",
|
"version": "2.18.1",
|
||||||
"resolved": "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz",
|
"resolved": "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz",
|
||||||
@ -424,12 +375,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
||||||
},
|
},
|
||||||
"node_modules/safer-buffer": {
|
|
||||||
"version": "2.1.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
|
||||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
|
|
||||||
"license": "MIT"
|
|
||||||
},
|
|
||||||
"node_modules/sanitize-html": {
|
"node_modules/sanitize-html": {
|
||||||
"version": "2.13.1",
|
"version": "2.13.1",
|
||||||
"resolved": "https://registry.npmjs.org/sanitize-html/-/sanitize-html-2.13.1.tgz",
|
"resolved": "https://registry.npmjs.org/sanitize-html/-/sanitize-html-2.13.1.tgz",
|
||||||
@ -485,6 +430,7 @@
|
|||||||
"version": "6.19.8",
|
"version": "6.19.8",
|
||||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz",
|
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz",
|
||||||
"integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==",
|
"integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==",
|
||||||
|
"devOptional": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/util-deprecate": {
|
"node_modules/util-deprecate": {
|
||||||
|
@ -3,20 +3,16 @@
|
|||||||
const mysql = require("serverless-mysql");
|
const mysql = require("serverless-mysql");
|
||||||
const grabDbSSL = require("../grabDbSSL");
|
const grabDbSSL = require("../grabDbSSL");
|
||||||
|
|
||||||
// const mariadb = require("mariadb");
|
/**
|
||||||
// const pool = mariadb.createPool({
|
* DSQL user read-only DB handler
|
||||||
// host: process.env.DSQL_DB_HOST,
|
* @param {object} params
|
||||||
// user: process.env.DSQL_DB_USERNAME,
|
* @param {string} params.paradigm
|
||||||
// password: process.env.DSQL_DB_PASSWORD,
|
* @param {string} params.database
|
||||||
// database: process.env.DSQL_DB_NAME,
|
* @param {string} params.queryString
|
||||||
// port: process.env.DSQL_DB_PORT
|
* @param {string[]} [params.queryValues]
|
||||||
// ? Number(process.env.DSQL_DB_PORT)
|
*/
|
||||||
// : undefined,
|
async function LOCAL_DB_HANDLER(/** @type {any[]} */ ...args) {
|
||||||
// charset: "utf8mb4",
|
const MASTER = mysql({
|
||||||
// ssl: true,
|
|
||||||
// });
|
|
||||||
|
|
||||||
const MASTER = mysql({
|
|
||||||
config: {
|
config: {
|
||||||
host: process.env.DSQL_DB_HOST,
|
host: process.env.DSQL_DB_HOST,
|
||||||
user: process.env.DSQL_DB_USERNAME,
|
user: process.env.DSQL_DB_USERNAME,
|
||||||
@ -30,38 +26,26 @@ const MASTER = mysql({
|
|||||||
timeout: 1000,
|
timeout: 1000,
|
||||||
connectTimeout: 1000,
|
connectTimeout: 1000,
|
||||||
},
|
},
|
||||||
});
|
onConnect: () => {
|
||||||
|
console.log("Connection Successful!");
|
||||||
/**
|
},
|
||||||
* DSQL user read-only DB handler
|
onConnectError: (/** @type {any} */ err) => {
|
||||||
* @param {object} params
|
console.log("Connection Error", err.message);
|
||||||
* @param {string} params.paradigm
|
},
|
||||||
* @param {string} params.database
|
onError: (/** @type {any} */ err) => {
|
||||||
* @param {string} params.queryString
|
console.log("Client Error", err.message);
|
||||||
* @param {string[]} [params.queryValues]
|
},
|
||||||
*/
|
|
||||||
async function LOCAL_DB_HANDLER(/** @type {any[]} */ ...args) {
|
|
||||||
MASTER.config({
|
|
||||||
host: process.env.DSQL_DB_HOST,
|
|
||||||
user: process.env.DSQL_DB_USERNAME,
|
|
||||||
password: process.env.DSQL_DB_PASSWORD,
|
|
||||||
database: process.env.DSQL_DB_NAME,
|
|
||||||
port: process.env.DSQL_DB_PORT
|
|
||||||
? Number(process.env.DSQL_DB_PORT)
|
|
||||||
: undefined,
|
|
||||||
charset: "utf8mb4",
|
|
||||||
ssl: grabDbSSL(),
|
|
||||||
timeout: 1000,
|
|
||||||
connectTimeout: 1000,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("Querying ...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const results = await MASTER.query(...args);
|
const results = await MASTER.query(...args);
|
||||||
await MASTER.end();
|
await MASTER.end();
|
||||||
|
|
||||||
return JSON.parse(JSON.stringify(results));
|
return JSON.parse(JSON.stringify(results));
|
||||||
} catch (/** @type {any} */ error) {
|
} catch (/** @type {any} */ error) {
|
||||||
console.log("DB Error =>", error);
|
console.log("DB Error =>", error.message);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: error.message,
|
error: error.message,
|
||||||
|
@ -8,9 +8,6 @@ const fs = require("fs");
|
|||||||
module.exports = function grabDbSSL() {
|
module.exports = function grabDbSSL() {
|
||||||
const SSL_DIR = process.env.DSQL_SSL_DIR;
|
const SSL_DIR = process.env.DSQL_SSL_DIR;
|
||||||
if (!SSL_DIR?.match(/./)) {
|
if (!SSL_DIR?.match(/./)) {
|
||||||
// console.log(
|
|
||||||
// "No SSL certificate provided. Query will run in normal mode. To add SSL add an env path dir `DSQL_SSL_DIR` with a file named `ca-cert.pem`"
|
|
||||||
// );
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "2.6.6",
|
"version": "2.6.7",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
@ -36,7 +36,6 @@
|
|||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
"generate-password": "^1.7.1",
|
"generate-password": "^1.7.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"mariadb": "^3.4.0",
|
|
||||||
"mysql": "^2.18.1",
|
"mysql": "^2.18.1",
|
||||||
"nodemailer": "^6.9.14",
|
"nodemailer": "^6.9.14",
|
||||||
"sanitize-html": "^2.13.1",
|
"sanitize-html": "^2.13.1",
|
||||||
|
@ -19,10 +19,11 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
|||||||
* @param {string} params.query - SQL Query
|
* @param {string} params.query - SQL Query
|
||||||
* @param {string[]} [params.queryValues] - An array of query values if using "?" placeholders
|
* @param {string[]} [params.queryValues] - An array of query values if using "?" placeholders
|
||||||
* @param {string} [params.tableName] - Name of the table to query
|
* @param {string} [params.tableName] - Name of the table to query
|
||||||
|
* @param {boolean} [params.useLocal] - Whether to use a remote database instead of API
|
||||||
*
|
*
|
||||||
* @returns { Promise<import("../package-shared/types").GetReturn> } - Return Object
|
* @returns { Promise<import("../package-shared/types").GetReturn> } - Return Object
|
||||||
*/
|
*/
|
||||||
async function get({ key, db, query, queryValues, tableName }) {
|
async function get({ key, db, query, queryValues, tableName, useLocal }) {
|
||||||
const { host, port, scheme } = grabHostNames();
|
const { host, port, scheme } = grabHostNames();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,7 +38,8 @@ async function get({ key, db, query, queryValues, tableName }) {
|
|||||||
DSQL_DB_HOST?.match(/./) &&
|
DSQL_DB_HOST?.match(/./) &&
|
||||||
DSQL_DB_USERNAME?.match(/./) &&
|
DSQL_DB_USERNAME?.match(/./) &&
|
||||||
DSQL_DB_PASSWORD?.match(/./) &&
|
DSQL_DB_PASSWORD?.match(/./) &&
|
||||||
DSQL_DB_NAME?.match(/./)
|
DSQL_DB_NAME?.match(/./) &&
|
||||||
|
useLocal
|
||||||
) {
|
) {
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
||||||
let dbSchema;
|
let dbSchema;
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
const http = require("http");
|
|
||||||
const https = require("https");
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const localPost = require("../engine/query/post");
|
const localPost = require("../engine/query/post");
|
||||||
@ -17,10 +15,18 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
|||||||
* @param {import("../package-shared/types").PostDataPayload | string} params.query - SQL query String or Request Object
|
* @param {import("../package-shared/types").PostDataPayload | string} params.query - SQL query String or Request Object
|
||||||
* @param {any[]} [params.queryValues] - Query Values if using "?" placeholders
|
* @param {any[]} [params.queryValues] - Query Values if using "?" placeholders
|
||||||
* @param {string} [params.tableName] - Name of the table to query
|
* @param {string} [params.tableName] - Name of the table to query
|
||||||
|
* @param {boolean} [params.useLocal] - Whether to use a remote database instead of API
|
||||||
*
|
*
|
||||||
* @returns { Promise<import("../package-shared/types").PostReturn> } - Return Object
|
* @returns { Promise<import("../package-shared/types").PostReturn> } - Return Object
|
||||||
*/
|
*/
|
||||||
async function post({ key, query, queryValues, database, tableName }) {
|
async function post({
|
||||||
|
key,
|
||||||
|
query,
|
||||||
|
queryValues,
|
||||||
|
database,
|
||||||
|
tableName,
|
||||||
|
useLocal,
|
||||||
|
}) {
|
||||||
const { host, port, scheme } = grabHostNames();
|
const { host, port, scheme } = grabHostNames();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,7 +41,8 @@ async function post({ key, query, queryValues, database, tableName }) {
|
|||||||
DSQL_DB_HOST?.match(/./) &&
|
DSQL_DB_HOST?.match(/./) &&
|
||||||
DSQL_DB_USERNAME?.match(/./) &&
|
DSQL_DB_USERNAME?.match(/./) &&
|
||||||
DSQL_DB_PASSWORD?.match(/./) &&
|
DSQL_DB_PASSWORD?.match(/./) &&
|
||||||
DSQL_DB_NAME?.match(/./)
|
DSQL_DB_NAME?.match(/./) &&
|
||||||
|
useLocal
|
||||||
) {
|
) {
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
||||||
let dbSchema;
|
let dbSchema;
|
||||||
|
Loading…
Reference in New Issue
Block a user