This commit is contained in:
Benjamin Toby 2024-11-06 12:58:41 +01:00
parent 2c2ae5de0d
commit 880a74dbcb
6 changed files with 65 additions and 12 deletions

View File

@ -5,6 +5,8 @@ const decrypt = require("./decrypt");
/** @type {import("../../types").CheckApiCredentialsFn} */
const grabApiCred = ({ key, database, table }) => {
if (!key) return null;
try {
const allowedKeysPath = process.env.DSQL_API_KEYS_PATH;

View File

@ -2,7 +2,7 @@
const { IncomingMessage } = require("http");
const decrypt = require("./decrypt");
const parseCookies = require("../../../utils/functions/parseCookies");
const parseCookies = require("../../utils/backend/parseCookies");
/**
* @async

View File

@ -1092,7 +1092,7 @@ export type CheckApiCredentialsFn = (
param: CheckApiCredentialsFnParam
) => ApiKeyObject | null | undefined;
export type CheckApiCredentialsFnParam = {
key: string;
key?: string;
database?: string;
table?: string;
};

View File

@ -3,15 +3,6 @@
const fs = require("fs");
const path = require("path");
// const mysql = require("mysql");
// const NO_DB = mysql.createConnection({
// host: process.env.DSQL_DB_HOST,
// user: process.env.DSQL_DB_USERNAME,
// password: process.env.DSQL_DB_PASSWORD,
// charset: "utf8mb4",
// });
const mysql = require("serverless-mysql");
const SSL_DIR =

View File

@ -0,0 +1,60 @@
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const http = require("http");
/**
* Parse request cookies
* ==============================================================================
*
* @description This function takes in a request object and returns the cookies as a JS object
*
* @async
*
* @param {object} params - main params object
* @param {http.IncomingMessage} params.request - HTTPS request object
*
* @returns {any | null}
*/
module.exports = function ({ request }) {
/**
* Check inputs
*
* @description Check inputs
*/
/** @type {string | undefined} */
const cookieString = request.headers.cookie;
if (!cookieString || typeof cookieString !== "string") {
return null;
}
/** @type {string[]} */
const cookieSplitArray = cookieString.split(";");
/** @type {*} */
let cookieObject = {};
cookieSplitArray.forEach((keyValueString) => {
const [key, value] = keyValueString.split("=");
if (key && typeof key == "string") {
cookieObject[key.replace(/^ +| +$/, "")] =
value && typeof value == "string"
? value.replace(/^ +| +$/, "")
: null;
}
});
/**
* Make https request
*
* @description make a request to datasquirel.com
*/
return cookieObject;
};

View File

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