This commit is contained in:
Benjamin Toby 2024-11-15 15:37:53 +01:00
parent ee35543885
commit 5e13f064aa
18 changed files with 74 additions and 151 deletions

View File

@ -72,7 +72,10 @@ async function updateApiSchemaFromLocalDb() {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
}, },
port, port,
hostname: host, hostname: host,

8
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "datasquirel", "name": "@moduletrace/datasquirel",
"version": "2.4.6", "version": "2.6.4",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "datasquirel", "name": "@moduletrace/datasquirel",
"version": "2.4.6", "version": "2.6.4",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@types/ace": "^0.0.52", "@types/ace": "^0.0.52",

View File

@ -1,6 +1,6 @@
{ {
"name": "@moduletrace/datasquirel", "name": "@moduletrace/datasquirel",
"version": "2.6.4", "version": "2.6.5",
"description": "Cloud-based SQL data management tool", "description": "Cloud-based SQL data management tool",
"main": "index.js", "main": "index.js",
"bin": { "bin": {

2
publish.sh Normal file → Executable file
View File

@ -6,4 +6,4 @@ else
msg="$1" msg="$1"
fi fi
npm run compile && git add . && git commit -m "$msg" && git push && git push origin2 main && npm publish npm run compile && git add . && git commit -m "$msg" && git push && npm publish

View File

@ -1,10 +1,5 @@
// @ts-check // @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const https = require("https"); const https = require("https");
const http = require("http"); const http = require("http");
const path = require("path"); const path = require("path");
@ -12,13 +7,6 @@ const fs = require("fs");
const localAddUser = require("../engine/user/add-user"); const localAddUser = require("../engine/user/add-user");
const grabHostNames = require("../package-shared/utils/grab-host-names"); const grabHostNames = require("../package-shared/utils/grab-host-names");
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** /**
* Add User to Database * Add User to Database
* ============================================================================== * ==============================================================================
@ -102,7 +90,10 @@ async function addUser({
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
}, },
port, port,
hostname: host, hostname: host,

View File

@ -118,7 +118,10 @@ async function getUser({ key, userId, database, fields }) {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
}, },
port, port,
hostname: host, hostname: host,

View File

@ -176,7 +176,10 @@ async function loginUser({
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayloadJSON).length, "Content-Length": Buffer.from(reqPayloadJSON).length,
Authorization: key, Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
}, },
port, port,
hostname: host, hostname: host,

View File

@ -139,7 +139,10 @@ async function reauthUser({
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
}, },
port, port,
hostname: host, hostname: host,

View File

@ -169,7 +169,10 @@ async function sendEmailCode({
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
}, },
port, port,
hostname: host, hostname: host,

View File

@ -198,7 +198,10 @@ async function githubAuth({
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
}, },
port, port,
hostname: host, hostname: host,

View File

@ -194,7 +194,10 @@ async function googleAuth({
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
}, },
port, port,
hostname: host, hostname: host,

View File

@ -1,10 +1,5 @@
// @ts-check // @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const http = require("http"); const http = require("http");
const https = require("https"); const https = require("https");
const path = require("path"); const path = require("path");
@ -12,17 +7,8 @@ const fs = require("fs");
const localUpdateUser = require("../engine/user/update-user"); const localUpdateUser = require("../engine/user/update-user");
const grabHostNames = require("../package-shared/utils/grab-host-names"); const grabHostNames = require("../package-shared/utils/grab-host-names");
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** /**
* ============================================================================== * # Update User
* Main Function
* ==============================================================================
* @async * @async
* *
* @param {object} params - API Key * @param {object} params - API Key
@ -92,7 +78,10 @@ async function updateUser({ key, payload, database }) {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization:
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY ||
key,
}, },
port, port,
hostname: host, hostname: host,

View File

@ -1,21 +1,9 @@
// @ts-check // @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const http = require("http"); const http = require("http");
const https = require("https"); const https = require("https");
const grabHostNames = require("../package-shared/utils/grab-host-names"); const grabHostNames = require("../package-shared/utils/grab-host-names");
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** /**
* @typedef {Object} FunctionReturn * @typedef {Object} FunctionReturn
* @property {boolean} success - Did the function run successfully? * @property {boolean} success - Did the function run successfully?
@ -27,9 +15,7 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
*/ */
/** /**
* ============================================================================== * # Delete File via API
* Main Function
* ==============================================================================
* @async * @async
* *
* @param {Object} params - Single Param object containing params * @param {Object} params - Single Param object containing params
@ -56,7 +42,10 @@ async function uploadImage({ key, url }) {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
}, },
port, port,
hostname: host, hostname: host,
@ -89,16 +78,8 @@ async function uploadImage({ key, url }) {
httpsRequest.end(); httpsRequest.end();
}); });
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
return httpResponse; return httpResponse;
} catch (/** @type {*} */ error) { } catch (/** @type {*} */ error) {
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
console.log("Error deleting file: ", error.message); console.log("Error deleting file: ", error.message);
return { return {
@ -109,8 +90,4 @@ async function uploadImage({ key, url }) {
} }
} }
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
module.exports = uploadImage; module.exports = uploadImage;

View File

@ -1,21 +1,9 @@
// @ts-check // @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const http = require("http"); const http = require("http");
const https = require("https"); const https = require("https");
const grabHostNames = require("../package-shared/utils/grab-host-names"); const grabHostNames = require("../package-shared/utils/grab-host-names");
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** /**
* @typedef {Object} GetSchemaReturn * @typedef {Object} GetSchemaReturn
* @property {boolean} success - Did the function run successfully? * @property {boolean} success - Did the function run successfully?
@ -52,7 +40,10 @@ async function getSchema({ key, database, field, table }) {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: key, Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
}, },
port, port,
hostname: host, hostname: host,
@ -85,15 +76,7 @@ async function getSchema({ key, database, field, table }) {
.end(); .end();
}); });
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
return httpResponse; return httpResponse;
} }
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
module.exports = getSchema; module.exports = getSchema;

View File

@ -1,10 +1,5 @@
// @ts-check // @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const http = require("node:http"); const http = require("node:http");
const https = require("node:https"); const https = require("node:https");
const path = require("path"); const path = require("path");
@ -13,13 +8,6 @@ const localGet = require("../engine/query/get");
const serializeQuery = require("./functions/serialize-query"); const serializeQuery = require("./functions/serialize-query");
const grabHostNames = require("../package-shared/utils/grab-host-names"); const grabHostNames = require("../package-shared/utils/grab-host-names");
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** /**
* Make a get request to Datasquirel API * Make a get request to Datasquirel API
* ============================================================================== * ==============================================================================
@ -80,7 +68,7 @@ async function get({ key, db, query, queryValues, tableName }) {
const httpResponse = await new Promise((resolve, reject) => { const httpResponse = await new Promise((resolve, reject) => {
/** @type {import("../package-shared/types").GetReqQueryObject} */ /** @type {import("../package-shared/types").GetReqQueryObject} */
const queryObject = { const queryObject = {
db: String(db), db: process.env.DSQL_API_DB_NAME || String(db),
query: String( query: String(
query query
.replace(/\n|\r|\n\r/g, "") .replace(/\n|\r|\n\r/g, "")
@ -100,7 +88,11 @@ async function get({ key, db, query, queryValues, tableName }) {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: key, Authorization:
key ||
process.env.DSQL_READ_ONLY_API_KEY ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
}, },
port, port,
hostname: host, hostname: host,

View File

@ -1,8 +1,5 @@
// @ts-check // @ts-check
/**
* Imports
*/
const http = require("http"); const http = require("http");
const https = require("https"); const https = require("https");
const path = require("path"); const path = require("path");
@ -10,16 +7,8 @@ const fs = require("fs");
const localPost = require("../engine/query/post"); const localPost = require("../engine/query/post");
const grabHostNames = require("../package-shared/utils/grab-host-names"); const grabHostNames = require("../package-shared/utils/grab-host-names");
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** /**
* Make a post request to Datasquirel API * # Make a post request to Datasquirel API
* ==============================================================================
* @async * @async
* *
* @param {Object} params - Single object passed * @param {Object} params - Single object passed
@ -78,7 +67,7 @@ async function post({ key, query, queryValues, database, tableName }) {
const reqPayloadString = JSON.stringify({ const reqPayloadString = JSON.stringify({
query, query,
queryValues, queryValues,
database, database: process.env.DSQL_API_DB_NAME || database,
tableName: tableName ? tableName : null, tableName: tableName ? tableName : null,
}).replace(/\n|\r|\n\r/gm, ""); }).replace(/\n|\r|\n\r/gm, "");
@ -103,7 +92,10 @@ async function post({ key, query, queryValues, database, tableName }) {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
}, },
port, port,
hostname: host, hostname: host,

View File

@ -1,21 +1,9 @@
// @ts-check // @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const http = require("http"); const http = require("http");
const https = require("https"); const https = require("https");
const grabHostNames = require("../package-shared/utils/grab-host-names"); const grabHostNames = require("../package-shared/utils/grab-host-names");
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** /**
* @typedef {Object} FunctionReturn * @typedef {Object} FunctionReturn
* @property {boolean} success - Did the function run successfully? * @property {boolean} success - Did the function run successfully?
@ -26,9 +14,7 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
*/ */
/** /**
* ============================================================================== * # Upload File via API
* Main Function
* ==============================================================================
* @async * @async
* *
* @param {Object} params - Single Param object containing params * @param {Object} params - Single Param object containing params
@ -61,7 +47,10 @@ async function uploadImage({ key, payload }) {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
}, },
port, port,
hostname: host, hostname: host,

View File

@ -1,21 +1,9 @@
// @ts-check // @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const http = require("http"); const http = require("http");
const https = require("https"); const https = require("https");
const grabHostNames = require("../package-shared/utils/grab-host-names"); const grabHostNames = require("../package-shared/utils/grab-host-names");
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** /**
* @typedef {Object} FunctionReturn * @typedef {Object} FunctionReturn
* @property {boolean} success - Did the function run successfully? * @property {boolean} success - Did the function run successfully?
@ -27,9 +15,7 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
*/ */
/** /**
* ============================================================================== * # Upload Image via API
* Main Function
* ==============================================================================
* @async * @async
* *
* @param {Object} params - Single Param object containing params * @param {Object} params - Single Param object containing params
@ -63,7 +49,10 @@ async function uploadImage({ key, payload }) {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
}, },
port, port,
hostname: host, hostname: host,