Major Bugfix and Refactoring
This commit is contained in:
+5
-6
@@ -10,6 +10,7 @@ const http = require("http");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const localAddUser = require("../engine/user/add-user");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -54,9 +55,7 @@ async function addUser({
|
||||
DSQL_FULL_SYNC,
|
||||
} = process.env;
|
||||
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
if (
|
||||
DSQL_HOST?.match(/./) &&
|
||||
@@ -97,7 +96,7 @@ async function addUser({
|
||||
encryptionKey,
|
||||
});
|
||||
|
||||
const httpsRequest = (scheme?.match(/^http$/i) ? http : https).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -105,8 +104,8 @@ async function addUser({
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/add-user`,
|
||||
},
|
||||
|
||||
|
||||
+11
-8
@@ -1,11 +1,16 @@
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const https = require("https");
|
||||
const http = require("http");
|
||||
const getLocalUser = require("../engine/user/get-user");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -26,7 +31,7 @@ const getLocalUser = require("../engine/user/get-user");
|
||||
* @param {number} params.userId - user id
|
||||
* @param {string[]} [params.fields] - fields to select
|
||||
*
|
||||
* @returns { Promise<import("../types/user.td").GetUserFunctionReturn>}
|
||||
* @returns { Promise<import("../package-shared/types").GetUserFunctionReturn>}
|
||||
*/
|
||||
async function getUser({ key, userId, database, fields }) {
|
||||
/**
|
||||
@@ -58,9 +63,7 @@ async function getUser({ key, userId, database, fields }) {
|
||||
fields: [...new Set(updatedFields)],
|
||||
});
|
||||
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
/**
|
||||
* Check for local DB settings
|
||||
@@ -83,7 +86,7 @@ async function getUser({ key, userId, database, fields }) {
|
||||
DSQL_PASS?.match(/./) &&
|
||||
DSQL_DB_NAME?.match(/./)
|
||||
) {
|
||||
/** @type {DSQL_DatabaseSchemaType | undefined} */
|
||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
||||
let dbSchema;
|
||||
|
||||
try {
|
||||
@@ -109,7 +112,7 @@ async function getUser({ key, userId, database, fields }) {
|
||||
* @description make a request to datasquirel.com
|
||||
*/
|
||||
const httpResponse = await new Promise((resolve, reject) => {
|
||||
const httpsRequest = (scheme?.match(/^http$/i) ? http : https).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -117,8 +120,8 @@ async function getUser({ key, userId, database, fields }) {
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/get-user`,
|
||||
},
|
||||
|
||||
|
||||
+5
-8
@@ -11,6 +11,7 @@ const fs = require("fs");
|
||||
const path = require("path");
|
||||
const encrypt = require("../functions/encrypt");
|
||||
const loginLocalUser = require("../engine/user/login-user");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -56,9 +57,7 @@ async function loginUser({
|
||||
temp_code_field,
|
||||
token,
|
||||
}) {
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
const defaultTempLoginFieldName = "temp_login_code";
|
||||
const emailLoginTempCodeFieldName = email_login
|
||||
@@ -171,9 +170,7 @@ async function loginUser({
|
||||
|
||||
const reqPayloadJSON = JSON.stringify(reqPayload);
|
||||
|
||||
const httpsRequest = (
|
||||
scheme?.match(/^http$/i) ? http : https
|
||||
).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -181,8 +178,8 @@ async function loginUser({
|
||||
"Content-Length": Buffer.from(reqPayloadJSON).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/login-user`,
|
||||
},
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ const encrypt = require("../functions/encrypt");
|
||||
|
||||
const userAuth = require("./user-auth");
|
||||
const localReauthUser = require("../engine/user/reauth-user");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -56,9 +57,7 @@ async function reauthUser({
|
||||
*
|
||||
* @description Check Encryption Keys
|
||||
*/
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
const existingUser = userAuth({
|
||||
database,
|
||||
@@ -134,9 +133,7 @@ async function reauthUser({
|
||||
additionalFields,
|
||||
});
|
||||
|
||||
const httpsRequest = (
|
||||
scheme?.match(/^http$/i) ? http : https
|
||||
).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -144,8 +141,8 @@ async function reauthUser({
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/reauth-user`,
|
||||
},
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ const path = require("path");
|
||||
const encrypt = require("../functions/encrypt");
|
||||
const loginLocalUser = require("../engine/user/login-user");
|
||||
const localSendEmailCode = require("../engine/user/send-email-code");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -54,9 +55,7 @@ async function sendEmailCode({
|
||||
mail_port,
|
||||
sender,
|
||||
}) {
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
const defaultTempLoginFieldName = "temp_login_code";
|
||||
const emailLoginTempCodeFieldName = temp_code_field
|
||||
@@ -164,9 +163,7 @@ async function sendEmailCode({
|
||||
),
|
||||
});
|
||||
|
||||
const httpsRequest = (
|
||||
scheme?.match(/^http$/i) ? http : https
|
||||
).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -174,8 +171,8 @@ async function sendEmailCode({
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/send-email-code`,
|
||||
},
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ const fs = require("fs");
|
||||
const path = require("path");
|
||||
const encrypt = require("../../functions/encrypt");
|
||||
const localGithubAuth = require("../../engine/user/social/github-auth");
|
||||
const grabHostNames = require("../../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -64,9 +65,7 @@ async function githubAuth({
|
||||
*
|
||||
* @description Check inputs
|
||||
*/
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
if (!key || key?.match(/ /)) {
|
||||
return {
|
||||
@@ -193,9 +192,7 @@ async function githubAuth({
|
||||
additionalFields,
|
||||
});
|
||||
|
||||
const httpsRequest = (
|
||||
scheme?.match(/^http$/i) ? http : https
|
||||
).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -203,8 +200,8 @@ async function githubAuth({
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/github-login`,
|
||||
},
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ const fs = require("fs");
|
||||
const path = require("path");
|
||||
const encrypt = require("../../functions/encrypt");
|
||||
const localGoogleAuth = require("../../engine/user/social/google-auth");
|
||||
const grabHostNames = require("../../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -55,9 +56,7 @@ async function googleAuth({
|
||||
encryptionSalt,
|
||||
additionalFields,
|
||||
}) {
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
/**
|
||||
* Check inputs
|
||||
@@ -189,9 +188,7 @@ async function googleAuth({
|
||||
additionalFields,
|
||||
});
|
||||
|
||||
const httpsRequest = (
|
||||
scheme?.match(/^http$/i) ? http : https
|
||||
).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -199,8 +196,8 @@ async function googleAuth({
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/google-login`,
|
||||
},
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ const https = require("https");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const localUpdateUser = require("../engine/user/update-user");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -47,9 +48,7 @@ async function updateUser({ key, payload, database }) {
|
||||
DSQL_FULL_SYNC,
|
||||
} = process.env;
|
||||
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
if (
|
||||
DSQL_HOST?.match(/./) &&
|
||||
@@ -87,7 +86,7 @@ async function updateUser({ key, payload, database }) {
|
||||
database,
|
||||
});
|
||||
|
||||
const httpsRequest = (scheme?.match(/^http$/i) ? http : https).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -95,8 +94,8 @@ async function updateUser({ key, payload, database }) {
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/update-user`,
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user