Updates
This commit is contained in:
@@ -38,6 +38,7 @@ export default async function loginUser({
|
||||
cleanupTokens,
|
||||
secureCookie,
|
||||
request,
|
||||
useLocal,
|
||||
}: LoginUserParam): Promise<APILoginFunctionReturn> {
|
||||
const grabedHostNames = grabHostNames({ userId: user_id || apiUserID });
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
@@ -105,26 +106,7 @@ export default async function loginUser({
|
||||
*
|
||||
* @description Look for local db settings in `.env` file and by pass the http request if available
|
||||
*/
|
||||
const { DSQL_DB_HOST, DSQL_DB_USERNAME, DSQL_DB_PASSWORD, DSQL_DB_NAME } =
|
||||
process.env;
|
||||
|
||||
if (
|
||||
DSQL_DB_HOST?.match(/./) &&
|
||||
DSQL_DB_USERNAME?.match(/./) &&
|
||||
DSQL_DB_PASSWORD?.match(/./) &&
|
||||
DSQL_DB_NAME?.match(/./) &&
|
||||
global.DSQL_USE_LOCAL
|
||||
) {
|
||||
let dbSchema: DSQL_DatabaseSchemaType | undefined;
|
||||
|
||||
try {
|
||||
const localDbSchemaPath = path.resolve(
|
||||
process.cwd(),
|
||||
"dsql.schema.json"
|
||||
);
|
||||
dbSchema = JSON.parse(fs.readFileSync(localDbSchemaPath, "utf8"));
|
||||
} catch (error) {}
|
||||
|
||||
if (useLocal) {
|
||||
httpResponse = await apiLoginUser({
|
||||
database: database || process.env.DSQL_DB_NAME || "",
|
||||
email: payload.email,
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import http from "http";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import grabHostNames from "../../utils/grab-host-names";
|
||||
import apiSendEmailCode from "../../functions/api/users/api-send-email-code";
|
||||
import { SendOneTimeCodeEmailResponse } from "../../types";
|
||||
|
||||
type Param = {
|
||||
key?: string;
|
||||
database?: string;
|
||||
database: string;
|
||||
email: string;
|
||||
temp_code_field_name?: string;
|
||||
response?: http.ServerResponse & { [s: string]: any };
|
||||
@@ -18,6 +16,7 @@ type Param = {
|
||||
sender?: string;
|
||||
user_id?: boolean;
|
||||
extraCookies?: import("../../types").CookieObject[];
|
||||
useLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -39,6 +38,7 @@ export default async function sendEmailCode(
|
||||
user_id,
|
||||
response,
|
||||
extraCookies,
|
||||
useLocal,
|
||||
} = params;
|
||||
|
||||
const grabedHostNames = grabHostNames();
|
||||
@@ -51,34 +51,11 @@ export default async function sendEmailCode(
|
||||
|
||||
const emailHtml = `<p>Please use this code to login</p>\n<h2>{{code}}</h2>\n<p>Please note that this code expires after 15 minutes</p>`;
|
||||
|
||||
/**
|
||||
* Check for local DB settings
|
||||
*
|
||||
* @description Look for local db settings in `.env` file and by pass the http request if available
|
||||
*/
|
||||
const { DSQL_DB_HOST, DSQL_DB_USERNAME, DSQL_DB_PASSWORD, DSQL_DB_NAME } =
|
||||
process.env;
|
||||
|
||||
if (
|
||||
DSQL_DB_HOST?.match(/./) &&
|
||||
DSQL_DB_USERNAME?.match(/./) &&
|
||||
DSQL_DB_PASSWORD?.match(/./) &&
|
||||
DSQL_DB_NAME?.match(/./) &&
|
||||
global.DSQL_USE_LOCAL
|
||||
) {
|
||||
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
|
||||
let dbSchema: import("../../types").DSQL_DatabaseSchemaType | undefined;
|
||||
|
||||
try {
|
||||
const localDbSchemaPath = path.resolve(
|
||||
process.cwd(),
|
||||
"dsql.schema.json"
|
||||
);
|
||||
dbSchema = JSON.parse(fs.readFileSync(localDbSchemaPath, "utf8"));
|
||||
} catch (error) {}
|
||||
console.log("useLocal", useLocal);
|
||||
|
||||
if (useLocal) {
|
||||
return await apiSendEmailCode({
|
||||
database: DSQL_DB_NAME,
|
||||
database,
|
||||
email,
|
||||
email_login_field: emailLoginTempCodeFieldName,
|
||||
html: emailHtml,
|
||||
|
||||
@@ -20,6 +20,10 @@ type Param = {
|
||||
debug?: boolean;
|
||||
secureCookie?: boolean;
|
||||
loginOnly?: boolean;
|
||||
/**
|
||||
* Login without calling external API
|
||||
*/
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -38,6 +42,7 @@ export default async function googleAuth({
|
||||
debug,
|
||||
secureCookie,
|
||||
loginOnly,
|
||||
forceLocal,
|
||||
}: Param): Promise<APILoginFunctionReturn> {
|
||||
const grabedHostNames = grabHostNames({
|
||||
userId: apiUserID || process.env.DSQL_API_USER_ID,
|
||||
@@ -89,21 +94,7 @@ export default async function googleAuth({
|
||||
success: false,
|
||||
};
|
||||
|
||||
/**
|
||||
* Check for local DB settings
|
||||
*
|
||||
* @description Look for local db settings in `.env` file and by pass the http request if available
|
||||
*/
|
||||
const { DSQL_DB_HOST, DSQL_DB_USERNAME, DSQL_DB_PASSWORD, DSQL_DB_NAME } =
|
||||
process.env;
|
||||
|
||||
if (
|
||||
DSQL_DB_HOST?.match(/./) &&
|
||||
DSQL_DB_USERNAME?.match(/./) &&
|
||||
DSQL_DB_PASSWORD?.match(/./) &&
|
||||
DSQL_DB_NAME?.match(/./) &&
|
||||
global.DSQL_USE_LOCAL
|
||||
) {
|
||||
if (forceLocal) {
|
||||
if (debug) {
|
||||
console.log(`Google login with Local Paradigm ...`);
|
||||
}
|
||||
@@ -113,6 +104,7 @@ export default async function googleAuth({
|
||||
additionalFields,
|
||||
additionalData,
|
||||
debug,
|
||||
loginOnly,
|
||||
});
|
||||
} else {
|
||||
httpResponse = await new Promise((resolve, reject) => {
|
||||
|
||||
@@ -850,7 +850,7 @@ export interface ImageObjectType {
|
||||
export interface FileObjectType {
|
||||
fileName?: string;
|
||||
private?: boolean;
|
||||
fileType?: string;
|
||||
fileType?: (typeof FileMimeTypes)[number];
|
||||
fileSize?: number;
|
||||
fileBase64?: string;
|
||||
fileBase64Full?: string;
|
||||
@@ -1677,7 +1677,7 @@ export type DatasquirelWindowEventPayloadType = {
|
||||
* # Docker Compose Types
|
||||
*/
|
||||
export type DockerCompose = {
|
||||
services: DockerComposeServices;
|
||||
services: DockerComposeServicesType;
|
||||
networks: DockerComposeNetworks;
|
||||
name: string;
|
||||
};
|
||||
@@ -1700,7 +1700,7 @@ export const DockerComposeServices = [
|
||||
"web-app-post-db-setup",
|
||||
] as const;
|
||||
|
||||
export type DockerComposeServices = {
|
||||
export type DockerComposeServicesType = {
|
||||
[key in (typeof DockerComposeServices)[number]]: DockerComposeServiceWithBuildObject;
|
||||
};
|
||||
|
||||
@@ -1726,6 +1726,7 @@ export type DockerComposeServiceWithBuildObject = {
|
||||
hostname: string;
|
||||
volumes: string[];
|
||||
environment: string[];
|
||||
ports?: string[];
|
||||
networks?: DockerComposeServiceNetworkObject;
|
||||
restart?: string;
|
||||
depends_on?: {
|
||||
@@ -1809,6 +1810,7 @@ export const FileMimeTypes = [
|
||||
"txt",
|
||||
"zip",
|
||||
"xz",
|
||||
"tar.xz",
|
||||
"yaml",
|
||||
"yml",
|
||||
] as const;
|
||||
@@ -1915,6 +1917,7 @@ export type LoginUserParam = {
|
||||
dbUserId?: string | number;
|
||||
cleanupTokens?: boolean;
|
||||
secureCookie?: boolean;
|
||||
useLocal?: boolean;
|
||||
};
|
||||
|
||||
export const UserSelectFields = [
|
||||
@@ -1966,7 +1969,7 @@ export const InvitedUserSelectFields = [
|
||||
},
|
||||
{
|
||||
field: "email",
|
||||
alias: "invited_user_email",
|
||||
alias: "invited_user_email_addr",
|
||||
},
|
||||
{
|
||||
field: "image_thumbnail",
|
||||
|
||||
@@ -20,6 +20,24 @@ export default function grabDirNames(param?: Param) {
|
||||
throw new Error("Please provide the `DATA_DIR` env variable.");
|
||||
|
||||
const STATIC_ROOT = path.join(DATA_DIR, "static");
|
||||
|
||||
const staticConfigDir = path.join(DATA_DIR, "static-config");
|
||||
const staticNGINXConfigFile = path.join(staticConfigDir, "default.conf");
|
||||
|
||||
const mainReverseProxyConfigDir = path.join(DATA_DIR, "reverse-proxy");
|
||||
const mainReverseProxyConfigFile = path.join(
|
||||
mainReverseProxyConfigDir,
|
||||
"default.conf"
|
||||
);
|
||||
const mainReverseProxyTemplatesDir = path.join(
|
||||
mainReverseProxyConfigDir,
|
||||
"templates"
|
||||
);
|
||||
const mainReverseProxyTemplatesDefaultFile = path.join(
|
||||
mainReverseProxyTemplatesDir,
|
||||
"default.conf.template"
|
||||
);
|
||||
|
||||
const publicImagesDir = path.join(STATIC_ROOT, `images`);
|
||||
|
||||
const publicDir = path.join(appDir, "public");
|
||||
@@ -140,10 +158,12 @@ export default function grabDirNames(param?: Param) {
|
||||
|
||||
let dockerComposeFile = path.join(appDir, "docker-compose.yml");
|
||||
let dockerComposeFileAlt = path.join(appDir, "docker-compose.yaml");
|
||||
const testDockerComposeFile = path.join(appDir, "test.docker-compose.yml");
|
||||
const testDockerComposeFileAlt = path.join(
|
||||
const dsqlDockerComposeFileName = "dsql.docker-compose.yml";
|
||||
const dsqlDockerComposeFileNameAlt = "dsql.docker-compose.yaml";
|
||||
const dsqlDockerComposeFile = path.join(appDir, dsqlDockerComposeFileName);
|
||||
const dsqlDockerComposeFileAlt = path.join(
|
||||
appDir,
|
||||
"test.docker-compose.yaml"
|
||||
dsqlDockerComposeFileNameAlt
|
||||
);
|
||||
const dbDockerComposeFile = path.join(appDir, "db.docker-compose.yml");
|
||||
const dbDockerComposeFileAlt = path.join(appDir, "db.docker-compose.yaml");
|
||||
@@ -159,7 +179,8 @@ export default function grabDirNames(param?: Param) {
|
||||
const siteSetupFile = path.join(appDir, "site-setup.json");
|
||||
|
||||
const envFile = path.join(appDir, ".env");
|
||||
const testEnvFile = path.join(appDir, "test.env");
|
||||
const dsqlEnvFileName = "dsql.env";
|
||||
const dsqlEnvFile = path.join(appDir, dsqlEnvFileName);
|
||||
|
||||
/**
|
||||
* # Backup Dir names
|
||||
@@ -173,6 +194,32 @@ export default function grabDirNames(param?: Param) {
|
||||
const sqlBackupDirName = `sql`;
|
||||
const schemasBackupDirName = `schema`;
|
||||
|
||||
/**
|
||||
* # Distribution Names
|
||||
*/
|
||||
const distroDirName = "distro" as const;
|
||||
const distroAppDirName = "dsql-app" as const;
|
||||
const distroDataDirName = "dsql-data" as const;
|
||||
const distroCommunityName = "dsql-community" as const;
|
||||
const distroCommunityExportTarName =
|
||||
`${distroCommunityName}.tar.xz` as const;
|
||||
const distroProName = "dsql-pro" as const;
|
||||
const distroProExportTarName = `${distroProName}.tar.xz` as const;
|
||||
const distroEnterpriseName = "dsql-enterprise" as const;
|
||||
const distroEnterpriseExportTarName =
|
||||
`${distroEnterpriseName}.tar.xz` as const;
|
||||
|
||||
const communityDistroTempDir = path.resolve(
|
||||
appDir,
|
||||
"build",
|
||||
"community",
|
||||
".tmp"
|
||||
);
|
||||
const communityDistroDir = path.resolve(
|
||||
communityDistroTempDir,
|
||||
distroDirName
|
||||
);
|
||||
|
||||
return {
|
||||
appDir,
|
||||
privateDataDir,
|
||||
@@ -197,13 +244,14 @@ export default function grabDirNames(param?: Param) {
|
||||
dbNginxLoadBalancerConfigFile,
|
||||
dockerComposeFile,
|
||||
dockerComposeFileAlt,
|
||||
testDockerComposeFile,
|
||||
testDockerComposeFileAlt,
|
||||
dsqlDockerComposeFile,
|
||||
dsqlDockerComposeFileAlt,
|
||||
extraDockerComposeFile,
|
||||
extraDockerComposeFileAlt,
|
||||
siteSetupFile,
|
||||
envFile,
|
||||
testEnvFile,
|
||||
dsqlEnvFileName,
|
||||
dsqlEnvFile,
|
||||
userPublicMediaDir,
|
||||
userTempSQLFilePath,
|
||||
STATIC_ROOT,
|
||||
@@ -237,5 +285,24 @@ export default function grabDirNames(param?: Param) {
|
||||
mainDBSSLDir,
|
||||
replica1DBSSLDir,
|
||||
replica2DBSSLDir,
|
||||
staticConfigDir,
|
||||
staticNGINXConfigFile,
|
||||
mainReverseProxyConfigDir,
|
||||
mainReverseProxyConfigFile,
|
||||
mainReverseProxyTemplatesDir,
|
||||
mainReverseProxyTemplatesDefaultFile,
|
||||
dsqlDockerComposeFileName,
|
||||
dsqlDockerComposeFileNameAlt,
|
||||
distroDirName,
|
||||
distroAppDirName,
|
||||
distroDataDirName,
|
||||
distroCommunityName,
|
||||
distroCommunityExportTarName,
|
||||
distroProName,
|
||||
distroProExportTarName,
|
||||
distroEnterpriseName,
|
||||
distroEnterpriseExportTarName,
|
||||
communityDistroTempDir,
|
||||
communityDistroDir,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,12 +4,16 @@ export default function grabDockerStackServicesNames() {
|
||||
const maxScaleServiceName = `${deploymentName}-dsql-maxscale`;
|
||||
const dbServiceName = `${deploymentName}-dsql-db`;
|
||||
const dbCronServiceName = `${deploymentName}-dsql-db-cron`;
|
||||
const cronServiceName = `${deploymentName}-dsql-cron`;
|
||||
const postDbSetupServiceName = `${deploymentName}-dsql-post-db-setup`;
|
||||
const setupServiceName = `${deploymentName}-dsql-setup`;
|
||||
const webAppServiceName = `${deploymentName}-dsql-web-app`;
|
||||
const webAppCronServiceName = `${deploymentName}-dsql-web-app-cron`;
|
||||
const webAppPostDbSetupServiceName = `${deploymentName}-dsql-web-app-post-db-setup`;
|
||||
const dbReplica1ServiceName = `${deploymentName}-dsql-db-replica-1`;
|
||||
const dbReplica2ServiceName = `${deploymentName}-dsql-db-replica-2`;
|
||||
const reverseProxyServiceName = `${deploymentName}-dsql-reverse-proxy`;
|
||||
const staticServiceName = `${deploymentName}-dsql-static`;
|
||||
const websocketServiceName = `${deploymentName}-dsql-websocket`;
|
||||
|
||||
return {
|
||||
deploymentName,
|
||||
@@ -17,10 +21,14 @@ export default function grabDockerStackServicesNames() {
|
||||
dbServiceName,
|
||||
dbCronServiceName,
|
||||
postDbSetupServiceName,
|
||||
setupServiceName,
|
||||
webAppServiceName,
|
||||
webAppCronServiceName,
|
||||
webAppPostDbSetupServiceName,
|
||||
dbReplica1ServiceName,
|
||||
dbReplica2ServiceName,
|
||||
reverseProxyServiceName,
|
||||
staticServiceName,
|
||||
websocketServiceName,
|
||||
cronServiceName,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,13 +2,23 @@ import grabDockerResourceIPNumbers from "../../grab-docker-resource-ip-numbers";
|
||||
|
||||
export default function grabIPAddresses() {
|
||||
const globalIPPrefix = process.env.DSQL_NETWORK_IP_PREFIX || "172.72.0";
|
||||
const { cron, db, maxscale, postDbSetup, web } =
|
||||
grabDockerResourceIPNumbers();
|
||||
const {
|
||||
cron,
|
||||
db,
|
||||
maxscale,
|
||||
postDbSetup,
|
||||
web,
|
||||
db_cron,
|
||||
reverse_proxy,
|
||||
web_app_post_db_setup,
|
||||
websocket,
|
||||
} = grabDockerResourceIPNumbers();
|
||||
|
||||
const webAppIP = `${globalIPPrefix}.${web}`;
|
||||
const appCronIP = `${globalIPPrefix}.${cron}`;
|
||||
const maxScaleIP = `${globalIPPrefix}.${maxscale}`;
|
||||
const mainDBIP = `${globalIPPrefix}.${db}`;
|
||||
const webSocketIP = `${globalIPPrefix}.${websocket}`;
|
||||
const localHostIP = `${globalIPPrefix}.1`;
|
||||
|
||||
return {
|
||||
@@ -18,5 +28,6 @@ export default function grabIPAddresses() {
|
||||
mainDBIP,
|
||||
localHostIP,
|
||||
globalIPPrefix,
|
||||
webSocketIP,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@ export default async function <
|
||||
dbFullName,
|
||||
});
|
||||
|
||||
const DB_CONN = global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
|
||||
let connQueries: ConnDBHandlerQueryObject[] = [
|
||||
{
|
||||
query: queryObject?.string,
|
||||
@@ -55,7 +53,7 @@ export default async function <
|
||||
];
|
||||
}
|
||||
|
||||
const res = await connDbHandler(DB_CONN, connQueries);
|
||||
const res = await connDbHandler(undefined, connQueries);
|
||||
|
||||
const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import debugLog from "../logging/debug-log";
|
||||
import { DSQLErrorObject } from "../../types";
|
||||
import mariadb, { Connection, ConnectionConfig, Pool } from "mariadb";
|
||||
import grabDSQLConnection from "../grab-dsql-connection";
|
||||
|
||||
export type ConnDBHandlerQueryObject = {
|
||||
query: string;
|
||||
@@ -33,14 +34,16 @@ export default async function connDbHandler<ReturnType = any>(
|
||||
values?: ConnDBHandlerQueryObject["values"],
|
||||
debug?: boolean
|
||||
): Promise<Return<ReturnType>> {
|
||||
const finalConnection = conn || (await grabDSQLConnection());
|
||||
|
||||
try {
|
||||
if (!conn) throw new Error("No Connection Found!");
|
||||
if (!finalConnection) throw new Error("No Connection Found!");
|
||||
if (!query) throw new Error("Query String Required!");
|
||||
|
||||
let queryErrorArray: DSQLErrorObject[] = [];
|
||||
|
||||
if (typeof query == "string") {
|
||||
const res = await conn.query(trimQuery(query), values);
|
||||
const res = await finalConnection.query(trimQuery(query), values);
|
||||
|
||||
if (debug) {
|
||||
debugLog({
|
||||
@@ -67,7 +70,7 @@ export default async function connDbHandler<ReturnType = any>(
|
||||
currentQueryError.sql = queryObj.query;
|
||||
currentQueryError.sqlValues = queryObj.values;
|
||||
|
||||
const queryObjRes = await conn.query(
|
||||
const queryObjRes = await finalConnection.query(
|
||||
trimQuery(queryObj.query),
|
||||
queryObj.values
|
||||
);
|
||||
@@ -133,7 +136,7 @@ export default async function connDbHandler<ReturnType = any>(
|
||||
// config: conn,
|
||||
};
|
||||
} finally {
|
||||
await conn?.end();
|
||||
await finalConnection?.end();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,21 @@ type Param = {
|
||||
export default async function grabDSQLConnection(
|
||||
param?: Param
|
||||
): Promise<Connection> {
|
||||
return await mariadb.createConnection({
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
user: process.env.DSQL_DB_USERNAME,
|
||||
password: process.env.DSQL_DB_PASSWORD,
|
||||
database: param?.noDb ? undefined : process.env.DSQL_DB_NAME,
|
||||
port: process.env.DSQL_DB_PORT
|
||||
? Number(process.env.DSQL_DB_PORT)
|
||||
: undefined,
|
||||
charset: "utf8mb4",
|
||||
ssl: grabDbSSL(),
|
||||
supportBigNumbers: true,
|
||||
bigNumberStrings: false,
|
||||
dateStrings: true,
|
||||
});
|
||||
|
||||
if (global.DSQL_USE_LOCAL || param?.local) {
|
||||
return (
|
||||
global.DSQL_DB_CONN ||
|
||||
|
||||
@@ -24,7 +24,12 @@ export default function numberfy(num: any, decimals?: number): number {
|
||||
if (typeof numberfiedNum !== "number") return 0;
|
||||
if (isNaN(numberfiedNum)) return 0;
|
||||
|
||||
if (decimals) return Number(numberfiedNum.toFixed(decimals));
|
||||
if (decimals == 0) {
|
||||
return Math.round(Number(numberfiedNum));
|
||||
} else if (decimals) {
|
||||
return Number(numberfiedNum.toFixed(decimals));
|
||||
}
|
||||
|
||||
if (existingDecimals)
|
||||
return Number(numberfiedNum.toFixed(existingDecimals));
|
||||
return Math.round(numberfiedNum);
|
||||
|
||||
Reference in New Issue
Block a user