diff --git a/engine/query/update-api-schema-from-local-db.js b/engine/query/update-api-schema-from-local-db.js index 745cf00..4f09243 100644 --- a/engine/query/update-api-schema-from-local-db.js +++ b/engine/query/update-api-schema-from-local-db.js @@ -72,7 +72,10 @@ async function updateApiSchemaFromLocalDb() { headers: { "Content-Type": "application/json", "Content-Length": Buffer.from(reqPayload).length, - Authorization: key, + Authorization: + key || + process.env.DSQL_FULL_ACCESS_API_KEY || + process.env.DSQL_API_KEY, }, port, hostname: host, diff --git a/package-lock.json b/package-lock.json index 77d2e44..3bf314b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { - "name": "datasquirel", - "version": "2.4.6", + "name": "@moduletrace/datasquirel", + "version": "2.6.4", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "datasquirel", - "version": "2.4.6", + "name": "@moduletrace/datasquirel", + "version": "2.6.4", "license": "ISC", "dependencies": { "@types/ace": "^0.0.52", diff --git a/package.json b/package.json index e3c7126..dc6b700 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/datasquirel", - "version": "2.6.4", + "version": "2.6.5", "description": "Cloud-based SQL data management tool", "main": "index.js", "bin": { diff --git a/publish.sh b/publish.sh old mode 100644 new mode 100755 index e08e938..145a31d --- a/publish.sh +++ b/publish.sh @@ -6,4 +6,4 @@ else msg="$1" 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 diff --git a/users/add-user.js b/users/add-user.js index de266d8..5a80301 100644 --- a/users/add-user.js +++ b/users/add-user.js @@ -1,10 +1,5 @@ // @ts-check -/** - * ============================================================================== - * Imports - * ============================================================================== - */ const https = require("https"); const http = require("http"); const path = require("path"); @@ -12,13 +7,6 @@ const fs = require("fs"); const localAddUser = require("../engine/user/add-user"); const grabHostNames = require("../package-shared/utils/grab-host-names"); -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ - /** * Add User to Database * ============================================================================== @@ -102,7 +90,10 @@ async function addUser({ headers: { "Content-Type": "application/json", "Content-Length": Buffer.from(reqPayload).length, - Authorization: key, + Authorization: + key || + process.env.DSQL_FULL_ACCESS_API_KEY || + process.env.DSQL_API_KEY, }, port, hostname: host, diff --git a/users/get-user.js b/users/get-user.js index 26f1f64..aa2c2bf 100644 --- a/users/get-user.js +++ b/users/get-user.js @@ -118,7 +118,10 @@ async function getUser({ key, userId, database, fields }) { headers: { "Content-Type": "application/json", "Content-Length": Buffer.from(reqPayload).length, - Authorization: key, + Authorization: + key || + process.env.DSQL_FULL_ACCESS_API_KEY || + process.env.DSQL_API_KEY, }, port, hostname: host, diff --git a/users/login-user.js b/users/login-user.js index 1857212..4135ce2 100644 --- a/users/login-user.js +++ b/users/login-user.js @@ -176,7 +176,10 @@ async function loginUser({ headers: { "Content-Type": "application/json", "Content-Length": Buffer.from(reqPayloadJSON).length, - Authorization: key, + Authorization: + key || + process.env.DSQL_FULL_ACCESS_API_KEY || + process.env.DSQL_API_KEY, }, port, hostname: host, diff --git a/users/reauth-user.js b/users/reauth-user.js index 73f5377..9e08448 100644 --- a/users/reauth-user.js +++ b/users/reauth-user.js @@ -139,7 +139,10 @@ async function reauthUser({ headers: { "Content-Type": "application/json", "Content-Length": Buffer.from(reqPayload).length, - Authorization: key, + Authorization: + key || + process.env.DSQL_FULL_ACCESS_API_KEY || + process.env.DSQL_API_KEY, }, port, hostname: host, diff --git a/users/send-email-code.js b/users/send-email-code.js index f86e51f..81baf33 100644 --- a/users/send-email-code.js +++ b/users/send-email-code.js @@ -169,7 +169,10 @@ async function sendEmailCode({ headers: { "Content-Type": "application/json", "Content-Length": Buffer.from(reqPayload).length, - Authorization: key, + Authorization: + key || + process.env.DSQL_FULL_ACCESS_API_KEY || + process.env.DSQL_API_KEY, }, port, hostname: host, diff --git a/users/social/github-auth.js b/users/social/github-auth.js index 1b42aee..26f33d8 100644 --- a/users/social/github-auth.js +++ b/users/social/github-auth.js @@ -198,7 +198,10 @@ async function githubAuth({ headers: { "Content-Type": "application/json", "Content-Length": Buffer.from(reqPayload).length, - Authorization: key, + Authorization: + key || + process.env.DSQL_FULL_ACCESS_API_KEY || + process.env.DSQL_API_KEY, }, port, hostname: host, diff --git a/users/social/google-auth.js b/users/social/google-auth.js index 6645312..8aad757 100644 --- a/users/social/google-auth.js +++ b/users/social/google-auth.js @@ -194,7 +194,10 @@ async function googleAuth({ headers: { "Content-Type": "application/json", "Content-Length": Buffer.from(reqPayload).length, - Authorization: key, + Authorization: + key || + process.env.DSQL_FULL_ACCESS_API_KEY || + process.env.DSQL_API_KEY, }, port, hostname: host, diff --git a/users/update-user.js b/users/update-user.js index 2cfe48f..4cfa1d1 100644 --- a/users/update-user.js +++ b/users/update-user.js @@ -1,10 +1,5 @@ // @ts-check -/** - * ============================================================================== - * Imports - * ============================================================================== - */ const http = require("http"); const https = require("https"); const path = require("path"); @@ -12,17 +7,8 @@ const fs = require("fs"); const localUpdateUser = require("../engine/user/update-user"); const grabHostNames = require("../package-shared/utils/grab-host-names"); -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ - /** - * ============================================================================== - * Main Function - * ============================================================================== + * # Update User * @async * * @param {object} params - API Key @@ -92,7 +78,10 @@ async function updateUser({ key, payload, database }) { headers: { "Content-Type": "application/json", "Content-Length": Buffer.from(reqPayload).length, - Authorization: key, + Authorization: + process.env.DSQL_FULL_ACCESS_API_KEY || + process.env.DSQL_API_KEY || + key, }, port, hostname: host, diff --git a/utils/delete-file.js b/utils/delete-file.js index 201d7c1..46fdac2 100644 --- a/utils/delete-file.js +++ b/utils/delete-file.js @@ -1,21 +1,9 @@ // @ts-check -/** - * ============================================================================== - * Imports - * ============================================================================== - */ const http = require("http"); const https = require("https"); const grabHostNames = require("../package-shared/utils/grab-host-names"); -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ - /** * @typedef {Object} FunctionReturn * @property {boolean} success - Did the function run successfully? @@ -27,9 +15,7 @@ const grabHostNames = require("../package-shared/utils/grab-host-names"); */ /** - * ============================================================================== - * Main Function - * ============================================================================== + * # Delete File via API * @async * * @param {Object} params - Single Param object containing params @@ -56,7 +42,10 @@ async function uploadImage({ key, url }) { headers: { "Content-Type": "application/json", "Content-Length": Buffer.from(reqPayload).length, - Authorization: key, + Authorization: + key || + process.env.DSQL_FULL_ACCESS_API_KEY || + process.env.DSQL_API_KEY, }, port, hostname: host, @@ -89,16 +78,8 @@ async function uploadImage({ key, url }) { httpsRequest.end(); }); - /** ********************************************** */ - /** ********************************************** */ - /** ********************************************** */ - return httpResponse; } catch (/** @type {*} */ error) { - /** ********************************************** */ - /** ********************************************** */ - /** ********************************************** */ - console.log("Error deleting file: ", error.message); return { @@ -109,8 +90,4 @@ async function uploadImage({ key, url }) { } } -/** ********************************************** */ -/** ********************************************** */ -/** ********************************************** */ - module.exports = uploadImage; diff --git a/utils/get-schema.js b/utils/get-schema.js index 576b0d5..a54585f 100644 --- a/utils/get-schema.js +++ b/utils/get-schema.js @@ -1,21 +1,9 @@ // @ts-check -/** - * ============================================================================== - * Imports - * ============================================================================== - */ const http = require("http"); const https = require("https"); const grabHostNames = require("../package-shared/utils/grab-host-names"); -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ - /** * @typedef {Object} GetSchemaReturn * @property {boolean} success - Did the function run successfully? @@ -52,7 +40,10 @@ async function getSchema({ key, database, field, table }) { method: "GET", headers: { "Content-Type": "application/json", - Authorization: key, + Authorization: + key || + process.env.DSQL_FULL_ACCESS_API_KEY || + process.env.DSQL_API_KEY, }, port, hostname: host, @@ -85,15 +76,7 @@ async function getSchema({ key, database, field, table }) { .end(); }); - /** ********************************************** */ - /** ********************************************** */ - /** ********************************************** */ - return httpResponse; } -/** ********************************************** */ -/** ********************************************** */ -/** ********************************************** */ - module.exports = getSchema; diff --git a/utils/get.js b/utils/get.js index 8c55832..6fd2512 100644 --- a/utils/get.js +++ b/utils/get.js @@ -1,10 +1,5 @@ // @ts-check -/** - * ============================================================================== - * Imports - * ============================================================================== - */ const http = require("node:http"); const https = require("node:https"); const path = require("path"); @@ -13,13 +8,6 @@ const localGet = require("../engine/query/get"); const serializeQuery = require("./functions/serialize-query"); const grabHostNames = require("../package-shared/utils/grab-host-names"); -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ - /** * 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) => { /** @type {import("../package-shared/types").GetReqQueryObject} */ const queryObject = { - db: String(db), + db: process.env.DSQL_API_DB_NAME || String(db), query: String( query .replace(/\n|\r|\n\r/g, "") @@ -100,7 +88,11 @@ async function get({ key, db, query, queryValues, tableName }) { method: "GET", headers: { "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, hostname: host, diff --git a/utils/post.js b/utils/post.js index 6771620..2918060 100644 --- a/utils/post.js +++ b/utils/post.js @@ -1,8 +1,5 @@ // @ts-check -/** - * Imports - */ const http = require("http"); const https = require("https"); const path = require("path"); @@ -10,16 +7,8 @@ const fs = require("fs"); const localPost = require("../engine/query/post"); const grabHostNames = require("../package-shared/utils/grab-host-names"); -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ - /** - * Make a post request to Datasquirel API - * ============================================================================== + * # Make a post request to Datasquirel API * @async * * @param {Object} params - Single object passed @@ -78,7 +67,7 @@ async function post({ key, query, queryValues, database, tableName }) { const reqPayloadString = JSON.stringify({ query, queryValues, - database, + database: process.env.DSQL_API_DB_NAME || database, tableName: tableName ? tableName : null, }).replace(/\n|\r|\n\r/gm, ""); @@ -103,7 +92,10 @@ async function post({ key, query, queryValues, database, tableName }) { headers: { "Content-Type": "application/json", "Content-Length": Buffer.from(reqPayload).length, - Authorization: key, + Authorization: + key || + process.env.DSQL_FULL_ACCESS_API_KEY || + process.env.DSQL_API_KEY, }, port, hostname: host, diff --git a/utils/upload-file.js b/utils/upload-file.js index 20bd1f0..d7f475f 100644 --- a/utils/upload-file.js +++ b/utils/upload-file.js @@ -1,21 +1,9 @@ // @ts-check -/** - * ============================================================================== - * Imports - * ============================================================================== - */ const http = require("http"); const https = require("https"); const grabHostNames = require("../package-shared/utils/grab-host-names"); -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ - /** * @typedef {Object} FunctionReturn * @property {boolean} success - Did the function run successfully? @@ -26,9 +14,7 @@ const grabHostNames = require("../package-shared/utils/grab-host-names"); */ /** - * ============================================================================== - * Main Function - * ============================================================================== + * # Upload File via API * @async * * @param {Object} params - Single Param object containing params @@ -61,7 +47,10 @@ async function uploadImage({ key, payload }) { headers: { "Content-Type": "application/json", "Content-Length": Buffer.from(reqPayload).length, - Authorization: key, + Authorization: + key || + process.env.DSQL_FULL_ACCESS_API_KEY || + process.env.DSQL_API_KEY, }, port, hostname: host, diff --git a/utils/upload-image.js b/utils/upload-image.js index 48d2f7d..847f17f 100644 --- a/utils/upload-image.js +++ b/utils/upload-image.js @@ -1,21 +1,9 @@ // @ts-check -/** - * ============================================================================== - * Imports - * ============================================================================== - */ const http = require("http"); const https = require("https"); const grabHostNames = require("../package-shared/utils/grab-host-names"); -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ - /** * @typedef {Object} FunctionReturn * @property {boolean} success - Did the function run successfully? @@ -27,9 +15,7 @@ const grabHostNames = require("../package-shared/utils/grab-host-names"); */ /** - * ============================================================================== - * Main Function - * ============================================================================== + * # Upload Image via API * @async * * @param {Object} params - Single Param object containing params @@ -63,7 +49,10 @@ async function uploadImage({ key, payload }) { headers: { "Content-Type": "application/json", "Content-Length": Buffer.from(reqPayload).length, - Authorization: key, + Authorization: + key || + process.env.DSQL_FULL_ACCESS_API_KEY || + process.env.DSQL_API_KEY, }, port, hostname: host,