diff --git a/package-shared/utils/backend/parseCookies.js b/package-shared/utils/backend/parseCookies.js index 86d28dc..5436e30 100644 --- a/package-shared/utils/backend/parseCookies.js +++ b/package-shared/utils/backend/parseCookies.js @@ -17,7 +17,7 @@ const http = require("http"); * * @returns {Object} */ -module.exports = function ({ request, cookieString }) { +module.exports = function parseCookies({ request, cookieString }) { try { /** @type {string | undefined} */ const cookieStr = request diff --git a/package.json b/package.json index 2935f2d..24f4860 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/users/get-token.d.ts b/users/get-token.d.ts index 081537e..815ecc0 100644 --- a/users/get-token.d.ts +++ b/users/get-token.d.ts @@ -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; diff --git a/users/get-token.js b/users/get-token.js index 65eb6aa..c706568 100644 --- a/users/get-token.js +++ b/users/get-token.js @@ -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; diff --git a/users/logout-user.d.ts b/users/logout-user.d.ts index cafd9e1..278e60c 100644 --- a/users/logout-user.d.ts +++ b/users/logout-user.d.ts @@ -6,12 +6,13 @@ export = logoutUser; * @param {string} [params.encryptedUserString] - Encrypted User String * @param {http.IncomingMessage & Object} [params.request] - Request Object * @param {http.ServerResponse & Object} [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; }): { diff --git a/users/logout-user.js b/users/logout-user.js index 3851289..9da39fb 100644 --- a/users/logout-user.js +++ b/users/logout-user.js @@ -16,6 +16,7 @@ const parseCookies = require("../package-shared/utils/backend/parseCookies"); * @param {string} [params.encryptedUserString] - Encrypted User String * @param {http.IncomingMessage & Object} [params.request] - Request Object * @param {http.ServerResponse & Object} [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], }); diff --git a/users/user-auth.d.ts b/users/user-auth.d.ts index 85c8c53..1857827 100644 --- a/users/user-auth.d.ts +++ b/users/user-auth.d.ts @@ -8,6 +8,7 @@ export = userAuth; * @param {Object} params - Arg * @param {http.IncomingMessage & Object} [params.request] - Http request object * @param {http.IncomingMessage & Object} [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; diff --git a/users/user-auth.js b/users/user-auth.js index fa01cc1..0fc416a 100644 --- a/users/user-auth.js +++ b/users/user-auth.js @@ -24,6 +24,7 @@ const yearInMilliseconds = dayInMilliseconds * 365; * @param {Object} params - Arg * @param {http.IncomingMessage & Object} [params.request] - Http request object * @param {http.IncomingMessage & Object} [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, diff --git a/users/validate-temp-email-code.d.ts b/users/validate-temp-email-code.d.ts index 0d1e334..83794d7 100644 --- a/users/validate-temp-email-code.d.ts +++ b/users/validate-temp-email-code.d.ts @@ -5,15 +5,17 @@ export = validateTempEmailCode; * @async * * @param {object} params - Single Param object containing params - * @param {http.IncomingMessage & Object} params.request + * @param {http.IncomingMessage & Object} [params.request] + * @param {string} [params.cookieString] * @param {string} [params.email] * * @returns { Promise} */ -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 http = require("http"); diff --git a/users/validate-temp-email-code.js b/users/validate-temp-email-code.js index 0176648..7b0c3e5 100644 --- a/users/validate-temp-email-code.js +++ b/users/validate-temp-email-code.js @@ -12,17 +12,18 @@ const EJSON = require("../package-shared/utils/ejson"); * @async * * @param {object} params - Single Param object containing params - * @param {http.IncomingMessage & Object} params.request + * @param {http.IncomingMessage & Object} [params.request] + * @param {string} [params.cookieString] * @param {string} [params.email] * * @returns { Promise} */ -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({