Updates
This commit is contained in:
parent
2c2ae5de0d
commit
880a74dbcb
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
2
package-shared/types/index.d.ts
vendored
2
package-shared/types/index.d.ts
vendored
@ -1092,7 +1092,7 @@ export type CheckApiCredentialsFn = (
|
||||
param: CheckApiCredentialsFnParam
|
||||
) => ApiKeyObject | null | undefined;
|
||||
export type CheckApiCredentialsFnParam = {
|
||||
key: string;
|
||||
key?: string;
|
||||
database?: string;
|
||||
table?: string;
|
||||
};
|
||||
|
@ -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 =
|
||||
|
60
package-shared/utils/backend/parseCookies.js
Normal file
60
package-shared/utils/backend/parseCookies.js
Normal 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;
|
||||
};
|
@ -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": {
|
||||
|
Loading…
Reference in New Issue
Block a user