diff --git a/package-shared/utils/backend/parseCookies.d.ts b/package-shared/utils/backend/parseCookies.d.ts index 2b064f5..221c6b3 100644 --- a/package-shared/utils/backend/parseCookies.d.ts +++ b/package-shared/utils/backend/parseCookies.d.ts @@ -1,5 +1,9 @@ declare function _exports({ request }: { - request: http.IncomingMessage; -}): any | null; + request?: http.IncomingMessage & { + [x: string]: any; + }; +}): { + [x: string]: any; +}; export = _exports; import http = require("http"); diff --git a/package-shared/utils/backend/parseCookies.js b/package-shared/utils/backend/parseCookies.js index 7556ae0..6a66e1e 100644 --- a/package-shared/utils/backend/parseCookies.js +++ b/package-shared/utils/backend/parseCookies.js @@ -16,22 +16,18 @@ const http = require("http"); * @async * * @param {object} params - main params object - * @param {http.IncomingMessage} params.request - HTTPS request object + * @param {http.IncomingMessage & Object} [params.request] - HTTPS request object * - * @returns {any | null} + * @returns {Object} */ module.exports = function ({ request }) { - /** - * Check inputs - * - * @description Check inputs - */ + if (!request) return {}; /** @type {string | undefined} */ const cookieString = request.headers.cookie; if (!cookieString || typeof cookieString !== "string") { - return null; + return {}; } /** @type {string[]} */ diff --git a/package-shared/utils/serialize-query.d.ts b/package-shared/utils/serialize-query.d.ts new file mode 100644 index 0000000..a9d19db --- /dev/null +++ b/package-shared/utils/serialize-query.d.ts @@ -0,0 +1,2 @@ +export = serializeQuery; +declare function serializeQuery(param0: import("../types").SerializeQueryParams): string; diff --git a/package-shared/utils/serialize-query.js b/package-shared/utils/serialize-query.js new file mode 100644 index 0000000..7c3670f --- /dev/null +++ b/package-shared/utils/serialize-query.js @@ -0,0 +1,18 @@ +// @ts-check + +/** @type {import("../types").SerializeQueryFnType} */ +function serializeQuery({ query }) { + let str = "?"; + const keys = Object.keys(query); + + /** @type {string[]} */ + const queryArr = []; + keys.forEach((key) => { + if (!key || !query[key]) return; + queryArr.push(`${key}=${query[key]}`); + }); + str += queryArr.join("&"); + return str; +} + +module.exports = serializeQuery; diff --git a/package.json b/package.json index 5787c3d..3e4d48b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/datasquirel", - "version": "2.8.3", + "version": "2.8.4", "description": "Cloud-based SQL data management tool", "main": "index.js", "bin": { diff --git a/users/get-token.js b/users/get-token.js index 9f9a42d..65eb6aa 100644 --- a/users/get-token.js +++ b/users/get-token.js @@ -7,8 +7,8 @@ */ const http = require("http"); const decrypt = require("../package-shared/functions/dsql/decrypt"); -const parseCookies = require("../utils/functions/parseCookies"); const getAuthCookieNames = require("../package-shared/functions/backend/cookies/get-auth-cookie-names"); +const parseCookies = require("../package-shared/utils/backend/parseCookies"); /** ****************************************************************************** */ /** ****************************************************************************** */ diff --git a/users/user-auth.js b/users/user-auth.js index 2e51aac..fa01cc1 100644 --- a/users/user-auth.js +++ b/users/user-auth.js @@ -2,11 +2,11 @@ const http = require("http"); const decrypt = require("../package-shared/functions/dsql/decrypt"); -const parseCookies = require("../utils/functions/parseCookies"); const getAuthCookieNames = require("../package-shared/functions/backend/cookies/get-auth-cookie-names"); const { checkAuthFile, } = require("../package-shared/functions/backend/auth/write-auth-files"); +const parseCookies = require("../package-shared/utils/backend/parseCookies"); const minuteInMilliseconds = 60000; const hourInMilliseconds = minuteInMilliseconds * 60; diff --git a/utils/get.js b/utils/get.js index 9412628..074d13a 100644 --- a/utils/get.js +++ b/utils/get.js @@ -3,9 +3,9 @@ const https = require("node:https"); const path = require("path"); const fs = require("fs"); -const serializeQuery = require("./functions/serialize-query"); const grabHostNames = require("../package-shared/utils/grab-host-names"); const apiGet = require("../package-shared/functions/api/query/get"); +const serializeQuery = require("../package-shared/utils/serialize-query"); /** * Make a get request to Datasquirel API