Updates
This commit is contained in:
parent
6acf0f2cd6
commit
ccb5605b58
@ -2,4 +2,4 @@ import { APILoginFunctionReturn, LoginUserParam } from "../../types";
|
||||
/**
|
||||
* # Login A user
|
||||
*/
|
||||
export default function loginUser({ key, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, user_id, skipPassword, apiUserID, skipWriteAuthFile, dbUserId, debug, cleanupTokens, secureCookie, request, }: LoginUserParam): Promise<APILoginFunctionReturn>;
|
||||
export default function loginUser({ key, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, user_id, skipPassword, apiUserID, skipWriteAuthFile, dbUserId, debug, cleanupTokens, secureCookie, request, useLocal, }: LoginUserParam): Promise<APILoginFunctionReturn>;
|
||||
|
17
dist/package-shared/actions/users/login-user.js
vendored
17
dist/package-shared/actions/users/login-user.js
vendored
@ -13,8 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = loginUser;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const encrypt_1 = __importDefault(require("../../functions/dsql/encrypt"));
|
||||
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||
const api_login_1 = __importDefault(require("../../functions/api/users/api-login"));
|
||||
@ -26,7 +24,7 @@ const grab_cookie_expirt_date_1 = __importDefault(require("../../utils/grab-cook
|
||||
* # Login A user
|
||||
*/
|
||||
function loginUser(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ key, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, user_id, skipPassword, apiUserID, skipWriteAuthFile, dbUserId, debug, cleanupTokens, secureCookie, request, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ key, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, user_id, skipPassword, apiUserID, skipWriteAuthFile, dbUserId, debug, cleanupTokens, secureCookie, request, useLocal, }) {
|
||||
var _b, _c, _d;
|
||||
const grabedHostNames = (0, grab_host_names_1.default)({ userId: user_id || apiUserID });
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
@ -82,18 +80,7 @@ function loginUser(_a) {
|
||||
*
|
||||
* @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 === null || DSQL_DB_HOST === void 0 ? void 0 : DSQL_DB_HOST.match(/./)) &&
|
||||
(DSQL_DB_USERNAME === null || DSQL_DB_USERNAME === void 0 ? void 0 : DSQL_DB_USERNAME.match(/./)) &&
|
||||
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
|
||||
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
|
||||
global.DSQL_USE_LOCAL) {
|
||||
let dbSchema;
|
||||
try {
|
||||
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
||||
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
|
||||
}
|
||||
catch (error) { }
|
||||
if (useLocal) {
|
||||
httpResponse = yield (0, api_login_1.default)({
|
||||
database: database || process.env.DSQL_DB_NAME || "",
|
||||
email: payload.email,
|
||||
|
@ -2,7 +2,7 @@ import http from "http";
|
||||
import { SendOneTimeCodeEmailResponse } from "../../types";
|
||||
type Param = {
|
||||
key?: string;
|
||||
database?: string;
|
||||
database: string;
|
||||
email: string;
|
||||
temp_code_field_name?: string;
|
||||
response?: http.ServerResponse & {
|
||||
@ -15,6 +15,7 @@ type Param = {
|
||||
sender?: string;
|
||||
user_id?: boolean;
|
||||
extraCookies?: import("../../types").CookieObject[];
|
||||
useLocal?: boolean;
|
||||
};
|
||||
/**
|
||||
* # Send Email Code to a User
|
||||
|
@ -13,8 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = sendEmailCode;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||
const api_send_email_code_1 = __importDefault(require("../../functions/api/users/api-send-email-code"));
|
||||
/**
|
||||
@ -22,7 +20,7 @@ const api_send_email_code_1 = __importDefault(require("../../functions/api/users
|
||||
*/
|
||||
function sendEmailCode(params) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { key, email, database, temp_code_field_name, mail_domain, mail_password, mail_username, mail_port, sender, user_id, response, extraCookies, } = params;
|
||||
const { key, email, database, temp_code_field_name, mail_domain, mail_password, mail_username, mail_port, sender, user_id, response, extraCookies, useLocal, } = params;
|
||||
const grabedHostNames = (0, grab_host_names_1.default)();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
const defaultTempLoginFieldName = "temp_login_code";
|
||||
@ -30,26 +28,10 @@ function sendEmailCode(params) {
|
||||
? temp_code_field_name
|
||||
: defaultTempLoginFieldName;
|
||||
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 === null || DSQL_DB_HOST === void 0 ? void 0 : DSQL_DB_HOST.match(/./)) &&
|
||||
(DSQL_DB_USERNAME === null || DSQL_DB_USERNAME === void 0 ? void 0 : DSQL_DB_USERNAME.match(/./)) &&
|
||||
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
|
||||
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
|
||||
global.DSQL_USE_LOCAL) {
|
||||
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
|
||||
let dbSchema;
|
||||
try {
|
||||
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
||||
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
|
||||
}
|
||||
catch (error) { }
|
||||
console.log("useLocal", useLocal);
|
||||
if (useLocal) {
|
||||
return yield (0, api_send_email_code_1.default)({
|
||||
database: DSQL_DB_NAME,
|
||||
database,
|
||||
email,
|
||||
email_login_field: emailLoginTempCodeFieldName,
|
||||
html: emailHtml,
|
||||
|
@ -15,9 +15,13 @@ type Param = {
|
||||
debug?: boolean;
|
||||
secureCookie?: boolean;
|
||||
loginOnly?: boolean;
|
||||
/**
|
||||
* Login without calling external API
|
||||
*/
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
/**
|
||||
* # SERVER FUNCTION: Login with google Function
|
||||
*/
|
||||
export default function googleAuth({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, debug, secureCookie, loginOnly, }: Param): Promise<APILoginFunctionReturn>;
|
||||
export default function googleAuth({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, debug, secureCookie, loginOnly, forceLocal, }: Param): Promise<APILoginFunctionReturn>;
|
||||
export {};
|
||||
|
@ -23,7 +23,7 @@ const grab_cookie_expirt_date_1 = __importDefault(require("../../../utils/grab-c
|
||||
* # SERVER FUNCTION: Login with google Function
|
||||
*/
|
||||
function googleAuth(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, debug, secureCookie, loginOnly, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, debug, secureCookie, loginOnly, forceLocal, }) {
|
||||
var _b;
|
||||
const grabedHostNames = (0, grab_host_names_1.default)({
|
||||
userId: apiUserID || process.env.DSQL_API_USER_ID,
|
||||
@ -66,17 +66,7 @@ function googleAuth(_a) {
|
||||
let httpResponse = {
|
||||
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 === null || DSQL_DB_HOST === void 0 ? void 0 : DSQL_DB_HOST.match(/./)) &&
|
||||
(DSQL_DB_USERNAME === null || DSQL_DB_USERNAME === void 0 ? void 0 : DSQL_DB_USERNAME.match(/./)) &&
|
||||
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
|
||||
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
|
||||
global.DSQL_USE_LOCAL) {
|
||||
if (forceLocal) {
|
||||
if (debug) {
|
||||
console.log(`Google login with Local Paradigm ...`);
|
||||
}
|
||||
@ -85,6 +75,7 @@ function googleAuth(_a) {
|
||||
additionalFields,
|
||||
additionalData,
|
||||
debug,
|
||||
loginOnly,
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
12
dist/package-shared/types/index.d.ts
vendored
12
dist/package-shared/types/index.d.ts
vendored
@ -710,7 +710,7 @@ export interface ImageObjectType {
|
||||
export interface FileObjectType {
|
||||
fileName?: string;
|
||||
private?: boolean;
|
||||
fileType?: string;
|
||||
fileType?: (typeof FileMimeTypes)[number];
|
||||
fileSize?: number;
|
||||
fileBase64?: string;
|
||||
fileBase64Full?: string;
|
||||
@ -1420,12 +1420,12 @@ export type DatasquirelWindowEventPayloadType = {
|
||||
* # Docker Compose Types
|
||||
*/
|
||||
export type DockerCompose = {
|
||||
services: DockerComposeServices;
|
||||
services: DockerComposeServicesType;
|
||||
networks: DockerComposeNetworks;
|
||||
name: string;
|
||||
};
|
||||
export declare const DockerComposeServices: readonly ["setup", "cron", "reverse-proxy", "webapp", "websocket", "static", "db", "maxscale", "post-db-setup", "web-app-post-db-setup", "post-replica-db-setup", "db-replica-1", "db-replica-2", "db-cron", "web-app-post-db-setup"];
|
||||
export type DockerComposeServices = {
|
||||
export type DockerComposeServicesType = {
|
||||
[key in (typeof DockerComposeServices)[number]]: DockerComposeServiceWithBuildObject;
|
||||
};
|
||||
export type DockerComposeNetworks = {
|
||||
@ -1448,6 +1448,7 @@ export type DockerComposeServiceWithBuildObject = {
|
||||
hostname: string;
|
||||
volumes: string[];
|
||||
environment: string[];
|
||||
ports?: string[];
|
||||
networks?: DockerComposeServiceNetworkObject;
|
||||
restart?: string;
|
||||
depends_on?: {
|
||||
@ -1501,7 +1502,7 @@ export type MediaUploadDataType = ImageObjectType & FileObjectType & {
|
||||
overwrite?: boolean;
|
||||
};
|
||||
export declare const ImageMimeTypes: (keyof sharp.FormatEnum)[];
|
||||
export declare const FileMimeTypes: readonly ["pdf", "csv", "json", "sql", "xlsx", "txt", "zip", "xz", "yaml", "yml"];
|
||||
export declare const FileMimeTypes: readonly ["pdf", "csv", "json", "sql", "xlsx", "txt", "zip", "xz", "tar.xz", "yaml", "yml"];
|
||||
export declare const VideoMimeTypes: readonly ["mp4", "wav"];
|
||||
export declare const CurrentlyEditedFieldActions: readonly ["edit-field", "edit-index", "delete-field", "delete-index", "new-field", "new-index", "move-up", "move-down", "complete"];
|
||||
export type CurrentlyEditedTableSchemaType = {
|
||||
@ -1576,6 +1577,7 @@ export type LoginUserParam = {
|
||||
dbUserId?: string | number;
|
||||
cleanupTokens?: boolean;
|
||||
secureCookie?: boolean;
|
||||
useLocal?: boolean;
|
||||
};
|
||||
export declare const UserSelectFields: readonly [{
|
||||
readonly field: "first_name";
|
||||
@ -1611,7 +1613,7 @@ export declare const InvitedUserSelectFields: readonly [{
|
||||
readonly alias: "invited_user_last_name";
|
||||
}, {
|
||||
readonly field: "email";
|
||||
readonly alias: "invited_user_email";
|
||||
readonly alias: "invited_user_email_addr";
|
||||
}, {
|
||||
readonly field: "image_thumbnail";
|
||||
readonly alias: "invited_user_image_thumbnail";
|
||||
|
3
dist/package-shared/types/index.js
vendored
3
dist/package-shared/types/index.js
vendored
@ -144,6 +144,7 @@ exports.FileMimeTypes = [
|
||||
"txt",
|
||||
"zip",
|
||||
"xz",
|
||||
"tar.xz",
|
||||
"yaml",
|
||||
"yml",
|
||||
];
|
||||
@ -221,7 +222,7 @@ exports.InvitedUserSelectFields = [
|
||||
},
|
||||
{
|
||||
field: "email",
|
||||
alias: "invited_user_email",
|
||||
alias: "invited_user_email_addr",
|
||||
},
|
||||
{
|
||||
field: "image_thumbnail",
|
||||
|
@ -29,13 +29,14 @@ export default function grabDirNames(param?: Param): {
|
||||
dbNginxLoadBalancerConfigFile: string;
|
||||
dockerComposeFile: string;
|
||||
dockerComposeFileAlt: string;
|
||||
testDockerComposeFile: string;
|
||||
testDockerComposeFileAlt: string;
|
||||
dsqlDockerComposeFile: string;
|
||||
dsqlDockerComposeFileAlt: string;
|
||||
extraDockerComposeFile: string;
|
||||
extraDockerComposeFileAlt: string;
|
||||
siteSetupFile: string;
|
||||
envFile: string;
|
||||
testEnvFile: string;
|
||||
dsqlEnvFileName: string;
|
||||
dsqlEnvFile: string;
|
||||
userPublicMediaDir: string | undefined;
|
||||
userTempSQLFilePath: string | undefined;
|
||||
STATIC_ROOT: string;
|
||||
@ -69,5 +70,24 @@ export default function grabDirNames(param?: Param): {
|
||||
mainDBSSLDir: string;
|
||||
replica1DBSSLDir: string;
|
||||
replica2DBSSLDir: string;
|
||||
staticConfigDir: string;
|
||||
staticNGINXConfigFile: string;
|
||||
mainReverseProxyConfigDir: string;
|
||||
mainReverseProxyConfigFile: string;
|
||||
mainReverseProxyTemplatesDir: string;
|
||||
mainReverseProxyTemplatesDefaultFile: string;
|
||||
dsqlDockerComposeFileName: string;
|
||||
dsqlDockerComposeFileNameAlt: string;
|
||||
distroDirName: "distro";
|
||||
distroAppDirName: "dsql-app";
|
||||
distroDataDirName: "dsql-data";
|
||||
distroCommunityName: "dsql-community";
|
||||
distroCommunityExportTarName: "dsql-community.tar.xz";
|
||||
distroProName: "dsql-pro";
|
||||
distroProExportTarName: "dsql-pro.tar.xz";
|
||||
distroEnterpriseName: "dsql-enterprise";
|
||||
distroEnterpriseExportTarName: "dsql-enterprise.tar.xz";
|
||||
communityDistroTempDir: string;
|
||||
communityDistroDir: string;
|
||||
};
|
||||
export {};
|
||||
|
@ -15,6 +15,12 @@ function grabDirNames(param) {
|
||||
if (!DATA_DIR)
|
||||
throw new Error("Please provide the `DATA_DIR` env variable.");
|
||||
const STATIC_ROOT = path_1.default.join(DATA_DIR, "static");
|
||||
const staticConfigDir = path_1.default.join(DATA_DIR, "static-config");
|
||||
const staticNGINXConfigFile = path_1.default.join(staticConfigDir, "default.conf");
|
||||
const mainReverseProxyConfigDir = path_1.default.join(DATA_DIR, "reverse-proxy");
|
||||
const mainReverseProxyConfigFile = path_1.default.join(mainReverseProxyConfigDir, "default.conf");
|
||||
const mainReverseProxyTemplatesDir = path_1.default.join(mainReverseProxyConfigDir, "templates");
|
||||
const mainReverseProxyTemplatesDefaultFile = path_1.default.join(mainReverseProxyTemplatesDir, "default.conf.template");
|
||||
const publicImagesDir = path_1.default.join(STATIC_ROOT, `images`);
|
||||
const publicDir = path_1.default.join(appDir, "public");
|
||||
const publicSSLDir = path_1.default.join(publicDir, "documents", "ssl");
|
||||
@ -100,15 +106,18 @@ function grabDirNames(param) {
|
||||
const dbNginxLoadBalancerConfigFile = path_1.default.join(appDir, "docker/services/mariadb/load-balancer/config/template/nginx.conf");
|
||||
let dockerComposeFile = path_1.default.join(appDir, "docker-compose.yml");
|
||||
let dockerComposeFileAlt = path_1.default.join(appDir, "docker-compose.yaml");
|
||||
const testDockerComposeFile = path_1.default.join(appDir, "test.docker-compose.yml");
|
||||
const testDockerComposeFileAlt = path_1.default.join(appDir, "test.docker-compose.yaml");
|
||||
const dsqlDockerComposeFileName = "dsql.docker-compose.yml";
|
||||
const dsqlDockerComposeFileNameAlt = "dsql.docker-compose.yaml";
|
||||
const dsqlDockerComposeFile = path_1.default.join(appDir, dsqlDockerComposeFileName);
|
||||
const dsqlDockerComposeFileAlt = path_1.default.join(appDir, dsqlDockerComposeFileNameAlt);
|
||||
const dbDockerComposeFile = path_1.default.join(appDir, "db.docker-compose.yml");
|
||||
const dbDockerComposeFileAlt = path_1.default.join(appDir, "db.docker-compose.yaml");
|
||||
const extraDockerComposeFile = path_1.default.join(appDir, "extra.docker-compose.yml");
|
||||
const extraDockerComposeFileAlt = path_1.default.join(appDir, "extra.docker-compose.yaml");
|
||||
const siteSetupFile = path_1.default.join(appDir, "site-setup.json");
|
||||
const envFile = path_1.default.join(appDir, ".env");
|
||||
const testEnvFile = path_1.default.join(appDir, "test.env");
|
||||
const dsqlEnvFileName = "dsql.env";
|
||||
const dsqlEnvFile = path_1.default.join(appDir, dsqlEnvFileName);
|
||||
/**
|
||||
* # Backup Dir names
|
||||
* @description
|
||||
@ -119,6 +128,20 @@ function grabDirNames(param) {
|
||||
: undefined;
|
||||
const sqlBackupDirName = `sql`;
|
||||
const schemasBackupDirName = `schema`;
|
||||
/**
|
||||
* # Distribution Names
|
||||
*/
|
||||
const distroDirName = "distro";
|
||||
const distroAppDirName = "dsql-app";
|
||||
const distroDataDirName = "dsql-data";
|
||||
const distroCommunityName = "dsql-community";
|
||||
const distroCommunityExportTarName = `${distroCommunityName}.tar.xz`;
|
||||
const distroProName = "dsql-pro";
|
||||
const distroProExportTarName = `${distroProName}.tar.xz`;
|
||||
const distroEnterpriseName = "dsql-enterprise";
|
||||
const distroEnterpriseExportTarName = `${distroEnterpriseName}.tar.xz`;
|
||||
const communityDistroTempDir = path_1.default.resolve(appDir, "build", "community", ".tmp");
|
||||
const communityDistroDir = path_1.default.resolve(communityDistroTempDir, distroDirName);
|
||||
return {
|
||||
appDir,
|
||||
privateDataDir,
|
||||
@ -143,13 +166,14 @@ function grabDirNames(param) {
|
||||
dbNginxLoadBalancerConfigFile,
|
||||
dockerComposeFile,
|
||||
dockerComposeFileAlt,
|
||||
testDockerComposeFile,
|
||||
testDockerComposeFileAlt,
|
||||
dsqlDockerComposeFile,
|
||||
dsqlDockerComposeFileAlt,
|
||||
extraDockerComposeFile,
|
||||
extraDockerComposeFileAlt,
|
||||
siteSetupFile,
|
||||
envFile,
|
||||
testEnvFile,
|
||||
dsqlEnvFileName,
|
||||
dsqlEnvFile,
|
||||
userPublicMediaDir,
|
||||
userTempSQLFilePath,
|
||||
STATIC_ROOT,
|
||||
@ -183,5 +207,24 @@ function grabDirNames(param) {
|
||||
mainDBSSLDir,
|
||||
replica1DBSSLDir,
|
||||
replica2DBSSLDir,
|
||||
staticConfigDir,
|
||||
staticNGINXConfigFile,
|
||||
mainReverseProxyConfigDir,
|
||||
mainReverseProxyConfigFile,
|
||||
mainReverseProxyTemplatesDir,
|
||||
mainReverseProxyTemplatesDefaultFile,
|
||||
dsqlDockerComposeFileName,
|
||||
dsqlDockerComposeFileNameAlt,
|
||||
distroDirName,
|
||||
distroAppDirName,
|
||||
distroDataDirName,
|
||||
distroCommunityName,
|
||||
distroCommunityExportTarName,
|
||||
distroProName,
|
||||
distroProExportTarName,
|
||||
distroEnterpriseName,
|
||||
distroEnterpriseExportTarName,
|
||||
communityDistroTempDir,
|
||||
communityDistroDir,
|
||||
};
|
||||
}
|
||||
|
@ -4,9 +4,13 @@ export default function grabDockerStackServicesNames(): {
|
||||
dbServiceName: string;
|
||||
dbCronServiceName: string;
|
||||
postDbSetupServiceName: string;
|
||||
setupServiceName: string;
|
||||
webAppServiceName: string;
|
||||
webAppCronServiceName: string;
|
||||
webAppPostDbSetupServiceName: string;
|
||||
dbReplica1ServiceName: string;
|
||||
dbReplica2ServiceName: string;
|
||||
reverseProxyServiceName: string;
|
||||
staticServiceName: string;
|
||||
websocketServiceName: string;
|
||||
cronServiceName: string;
|
||||
};
|
||||
|
@ -6,22 +6,30 @@ 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,
|
||||
maxScaleServiceName,
|
||||
dbServiceName,
|
||||
dbCronServiceName,
|
||||
postDbSetupServiceName,
|
||||
setupServiceName,
|
||||
webAppServiceName,
|
||||
webAppCronServiceName,
|
||||
webAppPostDbSetupServiceName,
|
||||
dbReplica1ServiceName,
|
||||
dbReplica2ServiceName,
|
||||
reverseProxyServiceName,
|
||||
staticServiceName,
|
||||
websocketServiceName,
|
||||
cronServiceName,
|
||||
};
|
||||
}
|
||||
|
@ -5,4 +5,5 @@ export default function grabIPAddresses(): {
|
||||
mainDBIP: string;
|
||||
localHostIP: string;
|
||||
globalIPPrefix: string;
|
||||
webSocketIP: string;
|
||||
};
|
||||
|
@ -7,11 +7,12 @@ exports.default = grabIPAddresses;
|
||||
const grab_docker_resource_ip_numbers_1 = __importDefault(require("../../grab-docker-resource-ip-numbers"));
|
||||
function grabIPAddresses() {
|
||||
const globalIPPrefix = process.env.DSQL_NETWORK_IP_PREFIX || "172.72.0";
|
||||
const { cron, db, maxscale, postDbSetup, web } = (0, grab_docker_resource_ip_numbers_1.default)();
|
||||
const { cron, db, maxscale, postDbSetup, web, db_cron, reverse_proxy, web_app_post_db_setup, websocket, } = (0, grab_docker_resource_ip_numbers_1.default)();
|
||||
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 {
|
||||
webAppIP,
|
||||
@ -20,5 +21,6 @@ function grabIPAddresses() {
|
||||
mainDBIP,
|
||||
localHostIP,
|
||||
globalIPPrefix,
|
||||
webSocketIP,
|
||||
};
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ function default_1(_a) {
|
||||
genObject: query,
|
||||
dbFullName,
|
||||
});
|
||||
const DB_CONN = global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
let connQueries = [
|
||||
{
|
||||
query: queryObject === null || queryObject === void 0 ? void 0 : queryObject.string,
|
||||
@ -53,7 +52,7 @@ function default_1(_a) {
|
||||
},
|
||||
];
|
||||
}
|
||||
const res = yield (0, conn_db_handler_1.default)(DB_CONN, connQueries);
|
||||
const res = yield (0, conn_db_handler_1.default)(undefined, connQueries);
|
||||
const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
|
||||
return {
|
||||
success: isSuccess,
|
||||
|
10
dist/package-shared/utils/db/conn-db-handler.js
vendored
10
dist/package-shared/utils/db/conn-db-handler.js
vendored
@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = connDbHandler;
|
||||
const debug_log_1 = __importDefault(require("../logging/debug-log"));
|
||||
const grab_dsql_connection_1 = __importDefault(require("../grab-dsql-connection"));
|
||||
/**
|
||||
* # Run Query From MySQL Connection
|
||||
* @description Run a query from a pre-existing MySQL/Mariadb Connection
|
||||
@ -34,14 +35,15 @@ query,
|
||||
values, debug) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var _a, _b;
|
||||
const finalConnection = conn || (yield (0, grab_dsql_connection_1.default)());
|
||||
try {
|
||||
if (!conn)
|
||||
if (!finalConnection)
|
||||
throw new Error("No Connection Found!");
|
||||
if (!query)
|
||||
throw new Error("Query String Required!");
|
||||
let queryErrorArray = [];
|
||||
if (typeof query == "string") {
|
||||
const res = yield conn.query(trimQuery(query), values);
|
||||
const res = yield finalConnection.query(trimQuery(query), values);
|
||||
if (debug) {
|
||||
(0, debug_log_1.default)({
|
||||
log: res,
|
||||
@ -62,7 +64,7 @@ values, debug) {
|
||||
const queryObj = query[i];
|
||||
currentQueryError.sql = queryObj.query;
|
||||
currentQueryError.sqlValues = queryObj.values;
|
||||
const queryObjRes = yield conn.query(trimQuery(queryObj.query), queryObj.values);
|
||||
const queryObjRes = yield finalConnection.query(trimQuery(queryObj.query), queryObj.values);
|
||||
if (debug) {
|
||||
(0, debug_log_1.default)({
|
||||
log: queryObjRes,
|
||||
@ -118,7 +120,7 @@ values, debug) {
|
||||
};
|
||||
}
|
||||
finally {
|
||||
yield (conn === null || conn === void 0 ? void 0 : conn.end());
|
||||
yield (finalConnection === null || finalConnection === void 0 ? void 0 : finalConnection.end());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -20,6 +20,20 @@ const grabDbSSL_1 = __importDefault(require("./backend/grabDbSSL"));
|
||||
*/
|
||||
function grabDSQLConnection(param) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return yield mariadb_1.default.createConnection({
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
user: process.env.DSQL_DB_USERNAME,
|
||||
password: process.env.DSQL_DB_PASSWORD,
|
||||
database: (param === null || param === void 0 ? void 0 : param.noDb) ? undefined : process.env.DSQL_DB_NAME,
|
||||
port: process.env.DSQL_DB_PORT
|
||||
? Number(process.env.DSQL_DB_PORT)
|
||||
: undefined,
|
||||
charset: "utf8mb4",
|
||||
ssl: (0, grabDbSSL_1.default)(),
|
||||
supportBigNumbers: true,
|
||||
bigNumberStrings: false,
|
||||
dateStrings: true,
|
||||
});
|
||||
if (global.DSQL_USE_LOCAL || (param === null || param === void 0 ? void 0 : param.local)) {
|
||||
return (global.DSQL_DB_CONN ||
|
||||
(yield mariadb_1.default.createConnection({
|
||||
|
6
dist/package-shared/utils/numberfy.js
vendored
6
dist/package-shared/utils/numberfy.js
vendored
@ -26,8 +26,12 @@ function numberfy(num, decimals) {
|
||||
return 0;
|
||||
if (isNaN(numberfiedNum))
|
||||
return 0;
|
||||
if (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);
|
||||
|
@ -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);
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/datasquirel",
|
||||
"version": "4.8.8",
|
||||
"version": "4.8.9",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
|
Loading…
Reference in New Issue
Block a user