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: {
"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,

8
package-lock.json generated
View File

@ -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",

View File

@ -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": {

2
publish.sh Normal file → Executable file
View File

@ -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

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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;

View File

@ -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;

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,