Updates
This commit is contained in:
parent
357365a1ba
commit
d98deb06c5
@ -17,7 +17,7 @@ const http = require("http");
|
||||
*
|
||||
* @returns {Object<string, string>}
|
||||
*/
|
||||
module.exports = function ({ request, cookieString }) {
|
||||
module.exports = function parseCookies({ request, cookieString }) {
|
||||
try {
|
||||
/** @type {string | undefined} */
|
||||
const cookieStr = request
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/datasquirel",
|
||||
"version": "3.1.0",
|
||||
"version": "3.1.1",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
|
8
users/get-token.d.ts
vendored
8
users/get-token.d.ts
vendored
@ -12,7 +12,8 @@ export = getToken;
|
||||
* string and csrf token string
|
||||
*
|
||||
* @param {Object} params - Arg
|
||||
* @param {http.IncomingMessage} params.request - Http request object
|
||||
* @param {http.IncomingMessage} [params.request] - Http request object
|
||||
* @param {string} [params.cookieString]
|
||||
* @param {string} params.encryptionKey - Encryption Key
|
||||
* @param {string} params.encryptionSalt - Encryption Salt
|
||||
* @param {string} params.database - Database Name
|
||||
@ -20,8 +21,9 @@ export = getToken;
|
||||
*
|
||||
* @returns {{ key: string | undefined, csrf: string | undefined }}
|
||||
*/
|
||||
declare function getToken({ request, encryptionKey, encryptionSalt, database, useLocal, }: {
|
||||
request: http.IncomingMessage;
|
||||
declare function getToken({ request, encryptionKey, encryptionSalt, database, useLocal, cookieString, }: {
|
||||
request?: http.IncomingMessage;
|
||||
cookieString?: string;
|
||||
encryptionKey: string;
|
||||
encryptionSalt: string;
|
||||
database: string;
|
||||
|
@ -24,7 +24,8 @@ const parseCookies = require("../package-shared/utils/backend/parseCookies");
|
||||
* string and csrf token string
|
||||
*
|
||||
* @param {Object} params - Arg
|
||||
* @param {http.IncomingMessage} params.request - Http request object
|
||||
* @param {http.IncomingMessage} [params.request] - Http request object
|
||||
* @param {string} [params.cookieString]
|
||||
* @param {string} params.encryptionKey - Encryption Key
|
||||
* @param {string} params.encryptionSalt - Encryption Salt
|
||||
* @param {string} params.database - Database Name
|
||||
@ -38,6 +39,7 @@ function getToken({
|
||||
encryptionSalt,
|
||||
database,
|
||||
useLocal,
|
||||
cookieString,
|
||||
}) {
|
||||
try {
|
||||
/**
|
||||
@ -45,7 +47,7 @@ function getToken({
|
||||
*
|
||||
* @description Grab the payload
|
||||
*/
|
||||
const cookies = parseCookies({ request });
|
||||
const cookies = parseCookies({ request, cookieString });
|
||||
const keynames = getAuthCookieNames();
|
||||
const authKeyName = keynames.keyCookieName;
|
||||
const csrfName = keynames.csrfCookieName;
|
||||
|
4
users/logout-user.d.ts
vendored
4
users/logout-user.d.ts
vendored
@ -6,12 +6,13 @@ export = logoutUser;
|
||||
* @param {string} [params.encryptedUserString] - Encrypted User String
|
||||
* @param {http.IncomingMessage & Object<string, any>} [params.request] - Request Object
|
||||
* @param {http.ServerResponse & Object<string, any>} [params.response] - Http response object
|
||||
* @param {string} [params.cookieString]
|
||||
* @param {string} [params.database] - Target database name(slug): optional
|
||||
* @param {string | number} [params.dsqlUserId]
|
||||
*
|
||||
* @returns {{success: boolean, msg: string, cookieNames?: any}}
|
||||
*/
|
||||
declare function logoutUser({ response, database, dsqlUserId, encryptedUserString, request, }: {
|
||||
declare function logoutUser({ response, database, dsqlUserId, encryptedUserString, request, cookieString, }: {
|
||||
encryptedUserString?: string;
|
||||
request?: http.IncomingMessage & {
|
||||
[x: string]: any;
|
||||
@ -19,6 +20,7 @@ declare function logoutUser({ response, database, dsqlUserId, encryptedUserStrin
|
||||
response?: http.ServerResponse & {
|
||||
[x: string]: any;
|
||||
};
|
||||
cookieString?: string;
|
||||
database?: string;
|
||||
dsqlUserId?: string | number;
|
||||
}): {
|
||||
|
@ -16,6 +16,7 @@ const parseCookies = require("../package-shared/utils/backend/parseCookies");
|
||||
* @param {string} [params.encryptedUserString] - Encrypted User String
|
||||
* @param {http.IncomingMessage & Object<string, any>} [params.request] - Request Object
|
||||
* @param {http.ServerResponse & Object<string, any>} [params.response] - Http response object
|
||||
* @param {string} [params.cookieString]
|
||||
* @param {string} [params.database] - Target database name(slug): optional
|
||||
* @param {string | number} [params.dsqlUserId]
|
||||
*
|
||||
@ -27,6 +28,7 @@ function logoutUser({
|
||||
dsqlUserId,
|
||||
encryptedUserString,
|
||||
request,
|
||||
cookieString,
|
||||
}) {
|
||||
/**
|
||||
* Check Encryption Keys
|
||||
@ -46,7 +48,10 @@ function logoutUser({
|
||||
const decryptedUserJSON = (() => {
|
||||
try {
|
||||
if (request) {
|
||||
const cookiesObject = parseCookies({ request });
|
||||
const cookiesObject = parseCookies({
|
||||
request,
|
||||
cookieString,
|
||||
});
|
||||
return decrypt({
|
||||
encryptedString: cookiesObject[authKeyName],
|
||||
});
|
||||
|
4
users/user-auth.d.ts
vendored
4
users/user-auth.d.ts
vendored
@ -8,6 +8,7 @@ export = userAuth;
|
||||
* @param {Object} params - Arg
|
||||
* @param {http.IncomingMessage & Object<string, any>} [params.request] - Http request object
|
||||
* @param {http.IncomingMessage & Object<string, any>} [params.req] - Http request object
|
||||
* @param {string} [params.cookieString]
|
||||
* @param {string} [params.encryptedUserString] - Encrypted user string to use instead of getting from cookie header
|
||||
* @param {string} [params.encryptionKey] - Encryption Key: alt env: DSQL_ENCRYPTION_PASSWORD
|
||||
* @param {string} [params.encryptionSalt] - Encryption Salt: alt env: DSQL_ENCRYPTION_SALT
|
||||
@ -18,13 +19,14 @@ export = userAuth;
|
||||
*
|
||||
* @returns { import("../package-shared/types").AuthenticatedUser }
|
||||
*/
|
||||
declare function userAuth({ request, req, encryptionKey, encryptionSalt, level, database, dsqlUserId, encryptedUserString, expiry, }: {
|
||||
declare function userAuth({ request, req, encryptionKey, encryptionSalt, level, database, dsqlUserId, encryptedUserString, expiry, cookieString, }: {
|
||||
request?: http.IncomingMessage & {
|
||||
[x: string]: any;
|
||||
};
|
||||
req?: http.IncomingMessage & {
|
||||
[x: string]: any;
|
||||
};
|
||||
cookieString?: string;
|
||||
encryptedUserString?: string;
|
||||
encryptionKey?: string;
|
||||
encryptionSalt?: string;
|
||||
|
@ -24,6 +24,7 @@ const yearInMilliseconds = dayInMilliseconds * 365;
|
||||
* @param {Object} params - Arg
|
||||
* @param {http.IncomingMessage & Object<string, any>} [params.request] - Http request object
|
||||
* @param {http.IncomingMessage & Object<string, any>} [params.req] - Http request object
|
||||
* @param {string} [params.cookieString]
|
||||
* @param {string} [params.encryptedUserString] - Encrypted user string to use instead of getting from cookie header
|
||||
* @param {string} [params.encryptionKey] - Encryption Key: alt env: DSQL_ENCRYPTION_PASSWORD
|
||||
* @param {string} [params.encryptionSalt] - Encryption Salt: alt env: DSQL_ENCRYPTION_SALT
|
||||
@ -44,6 +45,7 @@ function userAuth({
|
||||
dsqlUserId,
|
||||
encryptedUserString,
|
||||
expiry = weekInMilliseconds,
|
||||
cookieString,
|
||||
}) {
|
||||
try {
|
||||
const finalEncryptionKey =
|
||||
@ -51,7 +53,10 @@ function userAuth({
|
||||
const finalEncryptionSalt =
|
||||
encryptionSalt || process.env.DSQL_ENCRYPTION_SALT;
|
||||
|
||||
const cookies = parseCookies({ request: request || req });
|
||||
const cookies = parseCookies({
|
||||
request: request || req,
|
||||
cookieString,
|
||||
});
|
||||
|
||||
const keyNames = getAuthCookieNames({
|
||||
userId: dsqlUserId || process.env.DSQL_API_USER_ID,
|
||||
|
8
users/validate-temp-email-code.d.ts
vendored
8
users/validate-temp-email-code.d.ts
vendored
@ -5,15 +5,17 @@ export = validateTempEmailCode;
|
||||
* @async
|
||||
*
|
||||
* @param {object} params - Single Param object containing params
|
||||
* @param {http.IncomingMessage & Object<string, any>} params.request
|
||||
* @param {http.IncomingMessage & Object<string, any>} [params.request]
|
||||
* @param {string} [params.cookieString]
|
||||
* @param {string} [params.email]
|
||||
*
|
||||
* @returns { Promise<import("../package-shared/types").SendOneTimeCodeEmailResponse | null>}
|
||||
*/
|
||||
declare function validateTempEmailCode({ request, email }: {
|
||||
request: http.IncomingMessage & {
|
||||
declare function validateTempEmailCode({ request, email, cookieString }: {
|
||||
request?: http.IncomingMessage & {
|
||||
[x: string]: any;
|
||||
};
|
||||
cookieString?: string;
|
||||
email?: string;
|
||||
}): Promise<import("../package-shared/types").SendOneTimeCodeEmailResponse | null>;
|
||||
import http = require("http");
|
||||
|
@ -12,17 +12,18 @@ const EJSON = require("../package-shared/utils/ejson");
|
||||
* @async
|
||||
*
|
||||
* @param {object} params - Single Param object containing params
|
||||
* @param {http.IncomingMessage & Object<string, any>} params.request
|
||||
* @param {http.IncomingMessage & Object<string, any>} [params.request]
|
||||
* @param {string} [params.cookieString]
|
||||
* @param {string} [params.email]
|
||||
*
|
||||
* @returns { Promise<import("../package-shared/types").SendOneTimeCodeEmailResponse | null>}
|
||||
*/
|
||||
async function validateTempEmailCode({ request, email }) {
|
||||
async function validateTempEmailCode({ request, email, cookieString }) {
|
||||
try {
|
||||
const keyNames = getAuthCookieNames();
|
||||
const oneTimeCodeCookieName = keyNames.oneTimeCodeName;
|
||||
|
||||
const cookies = parseCookies({ request });
|
||||
const cookies = parseCookies({ request, cookieString });
|
||||
const encryptedOneTimeCode = cookies[oneTimeCodeCookieName];
|
||||
|
||||
const encryptedPayload = decrypt({
|
||||
|
Loading…
Reference in New Issue
Block a user