Updates
This commit is contained in:
parent
6be3ede31a
commit
357365a1ba
4
index.d.ts
vendored
4
index.d.ts
vendored
@ -31,6 +31,7 @@ export namespace sql {
|
|||||||
export { sqlDeleteGenerator };
|
export { sqlDeleteGenerator };
|
||||||
export { trimSql as trim };
|
export { trimSql as trim };
|
||||||
}
|
}
|
||||||
|
import parseCookies = require("./package-shared/utils/backend/parseCookies");
|
||||||
import uploadImage = require("./utils/upload-image");
|
import uploadImage = require("./utils/upload-image");
|
||||||
import uploadFile = require("./utils/upload-file");
|
import uploadFile = require("./utils/upload-file");
|
||||||
import deleteFile = require("./utils/delete-file");
|
import deleteFile = require("./utils/delete-file");
|
||||||
@ -51,7 +52,7 @@ import sqlInsertGenerator = require("./package-shared/functions/dsql/sql/sql-ins
|
|||||||
import sqlDeleteGenerator = require("./package-shared/functions/dsql/sql/sql-delete-generator");
|
import sqlDeleteGenerator = require("./package-shared/functions/dsql/sql/sql-delete-generator");
|
||||||
import trimSql = require("./package-shared/utils/trim-sql");
|
import trimSql = require("./package-shared/utils/trim-sql");
|
||||||
export declare namespace utils {
|
export declare namespace utils {
|
||||||
namespace crypto {
|
export namespace crypto {
|
||||||
let encrypt: ({ data, encryptionKey, encryptionSalt }: {
|
let encrypt: ({ data, encryptionKey, encryptionSalt }: {
|
||||||
data: string;
|
data: string;
|
||||||
encryptionKey?: string;
|
encryptionKey?: string;
|
||||||
@ -67,5 +68,6 @@ export declare namespace utils {
|
|||||||
encryptionKey?: string;
|
encryptionKey?: string;
|
||||||
}) => string;
|
}) => string;
|
||||||
}
|
}
|
||||||
|
export { parseCookies };
|
||||||
}
|
}
|
||||||
export { get, post, getSchema, datasquirelClient as client };
|
export { get, post, getSchema, datasquirelClient as client };
|
||||||
|
7
index.js
7
index.js
@ -31,11 +31,7 @@ const sqlGenerator = require("./package-shared/functions/dsql/sql/sql-generator"
|
|||||||
const sqlInsertGenerator = require("./package-shared/functions/dsql/sql/sql-insert-generator");
|
const sqlInsertGenerator = require("./package-shared/functions/dsql/sql/sql-insert-generator");
|
||||||
const sqlDeleteGenerator = require("./package-shared/functions/dsql/sql/sql-delete-generator");
|
const sqlDeleteGenerator = require("./package-shared/functions/dsql/sql/sql-delete-generator");
|
||||||
const trimSql = require("./package-shared/utils/trim-sql");
|
const trimSql = require("./package-shared/utils/trim-sql");
|
||||||
const serializeQuery = require("./package-shared/utils/serialize-query");
|
const parseCookies = require("./package-shared/utils/backend/parseCookies");
|
||||||
const serializeCookies = require("./package-shared/utils/serialize-cookies");
|
|
||||||
const EJSON = require("./package-shared/utils/ejson");
|
|
||||||
const numberfy = require("./package-shared/utils/numberfy");
|
|
||||||
const slugify = require("./package-shared/utils/slugify");
|
|
||||||
|
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
@ -99,6 +95,7 @@ const datasquirel = {
|
|||||||
decrypt: require("./package-shared/functions/dsql/decrypt"),
|
decrypt: require("./package-shared/functions/dsql/decrypt"),
|
||||||
hash: require("./package-shared/functions/dsql/hashPassword"),
|
hash: require("./package-shared/functions/dsql/hashPassword"),
|
||||||
},
|
},
|
||||||
|
parseCookies,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
declare function _exports({ request }: {
|
declare function _exports({ request, cookieString }: {
|
||||||
request?: http.IncomingMessage & {
|
request?: http.IncomingMessage & {
|
||||||
[x: string]: any;
|
[x: string]: any;
|
||||||
};
|
};
|
||||||
|
cookieString?: string;
|
||||||
}): {
|
}): {
|
||||||
[x: string]: any;
|
[x: string]: string;
|
||||||
};
|
};
|
||||||
export = _exports;
|
export = _exports;
|
||||||
import http = require("http");
|
import http = require("http");
|
||||||
|
@ -1,56 +1,58 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
/**
|
|
||||||
* ==============================================================================
|
|
||||||
* Imports
|
|
||||||
* ==============================================================================
|
|
||||||
*/
|
|
||||||
const http = require("http");
|
const http = require("http");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse request cookies
|
* Parse request cookies
|
||||||
* ==============================================================================
|
* ===================================================
|
||||||
*
|
*
|
||||||
* @description This function takes in a request object and returns the cookies as a JS object
|
* @description This function takes in a request object and
|
||||||
|
* returns the cookies as a JS object
|
||||||
*
|
*
|
||||||
* @async
|
* @async
|
||||||
*
|
*
|
||||||
* @param {object} params - main params object
|
* @param {object} params - main params object
|
||||||
* @param {http.IncomingMessage & Object<string, any>} [params.request] - HTTPS request object
|
* @param {http.IncomingMessage & Object<string, any>} [params.request] - HTTPS request object
|
||||||
|
* @param {string} [params.cookieString]
|
||||||
*
|
*
|
||||||
* @returns {Object<string, any>}
|
* @returns {Object<string, string>}
|
||||||
*/
|
*/
|
||||||
module.exports = function ({ request }) {
|
module.exports = function ({ request, cookieString }) {
|
||||||
if (!request) return {};
|
try {
|
||||||
|
|
||||||
/** @type {string | undefined} */
|
/** @type {string | undefined} */
|
||||||
const cookieString = request.headers.cookie;
|
const cookieStr = request
|
||||||
|
? request.headers.cookie
|
||||||
|
: cookieString
|
||||||
|
? cookieString
|
||||||
|
: undefined;
|
||||||
|
|
||||||
if (!cookieString || typeof cookieString !== "string") {
|
if (!cookieStr) return {};
|
||||||
|
|
||||||
|
if (!cookieStr || typeof cookieStr !== "string") {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
const cookieSplitArray = cookieString.split(";");
|
const cookieSplitArray = cookieStr.split(";");
|
||||||
|
|
||||||
/** @type {*} */
|
/** @type {Object<string, string>} */
|
||||||
let cookieObject = {};
|
let cookieObject = {};
|
||||||
|
|
||||||
cookieSplitArray.forEach((keyValueString) => {
|
cookieSplitArray.forEach((keyValueString) => {
|
||||||
const [key, value] = keyValueString.split("=");
|
const [key, value] = keyValueString.split("=");
|
||||||
if (key && typeof key == "string") {
|
if (key && typeof key == "string") {
|
||||||
cookieObject[key.replace(/^ +| +$/, "")] =
|
const parsedKey = key.replace(/^ +| +$/, "");
|
||||||
|
cookieObject[parsedKey] =
|
||||||
value && typeof value == "string"
|
value && typeof value == "string"
|
||||||
? value.replace(/^ +| +$/, "")
|
? value.replace(/^ +| +$/, "")
|
||||||
: null;
|
: "";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* Make https request
|
|
||||||
*
|
|
||||||
* @description make a request to datasquirel.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
return cookieObject;
|
return cookieObject;
|
||||||
|
} catch (/** @type {any} */ error) {
|
||||||
|
console.log(`ERROR parsing cookies: ${error.message}`);
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "3.0.9",
|
"version": "3.1.0",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
Loading…
Reference in New Issue
Block a user