Updates
This commit is contained in:
parent
6acf0f2cd6
commit
ccb5605b58
@ -2,4 +2,4 @@ import { APILoginFunctionReturn, LoginUserParam } from "../../types";
|
|||||||
/**
|
/**
|
||||||
* # Login A user
|
* # 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 });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = loginUser;
|
exports.default = loginUser;
|
||||||
const fs_1 = __importDefault(require("fs"));
|
|
||||||
const path_1 = __importDefault(require("path"));
|
|
||||||
const encrypt_1 = __importDefault(require("../../functions/dsql/encrypt"));
|
const encrypt_1 = __importDefault(require("../../functions/dsql/encrypt"));
|
||||||
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||||
const api_login_1 = __importDefault(require("../../functions/api/users/api-login"));
|
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
|
* # Login A user
|
||||||
*/
|
*/
|
||||||
function loginUser(_a) {
|
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;
|
var _b, _c, _d;
|
||||||
const grabedHostNames = (0, grab_host_names_1.default)({ userId: user_id || apiUserID });
|
const grabedHostNames = (0, grab_host_names_1.default)({ userId: user_id || apiUserID });
|
||||||
const { host, port, scheme } = grabedHostNames;
|
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
|
* @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 (useLocal) {
|
||||||
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) { }
|
|
||||||
httpResponse = yield (0, api_login_1.default)({
|
httpResponse = yield (0, api_login_1.default)({
|
||||||
database: database || process.env.DSQL_DB_NAME || "",
|
database: database || process.env.DSQL_DB_NAME || "",
|
||||||
email: payload.email,
|
email: payload.email,
|
||||||
|
@ -2,7 +2,7 @@ import http from "http";
|
|||||||
import { SendOneTimeCodeEmailResponse } from "../../types";
|
import { SendOneTimeCodeEmailResponse } from "../../types";
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
database?: string;
|
database: string;
|
||||||
email: string;
|
email: string;
|
||||||
temp_code_field_name?: string;
|
temp_code_field_name?: string;
|
||||||
response?: http.ServerResponse & {
|
response?: http.ServerResponse & {
|
||||||
@ -15,6 +15,7 @@ type Param = {
|
|||||||
sender?: string;
|
sender?: string;
|
||||||
user_id?: boolean;
|
user_id?: boolean;
|
||||||
extraCookies?: import("../../types").CookieObject[];
|
extraCookies?: import("../../types").CookieObject[];
|
||||||
|
useLocal?: boolean;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* # Send Email Code to a User
|
* # Send Email Code to a User
|
||||||
|
@ -13,8 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = sendEmailCode;
|
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 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"));
|
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) {
|
function sendEmailCode(params) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
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 grabedHostNames = (0, grab_host_names_1.default)();
|
||||||
const { host, port, scheme } = grabedHostNames;
|
const { host, port, scheme } = grabedHostNames;
|
||||||
const defaultTempLoginFieldName = "temp_login_code";
|
const defaultTempLoginFieldName = "temp_login_code";
|
||||||
@ -30,26 +28,10 @@ function sendEmailCode(params) {
|
|||||||
? temp_code_field_name
|
? temp_code_field_name
|
||||||
: defaultTempLoginFieldName;
|
: 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>`;
|
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>`;
|
||||||
/**
|
console.log("useLocal", useLocal);
|
||||||
* Check for local DB settings
|
if (useLocal) {
|
||||||
*
|
|
||||||
* @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) { }
|
|
||||||
return yield (0, api_send_email_code_1.default)({
|
return yield (0, api_send_email_code_1.default)({
|
||||||
database: DSQL_DB_NAME,
|
database,
|
||||||
email,
|
email,
|
||||||
email_login_field: emailLoginTempCodeFieldName,
|
email_login_field: emailLoginTempCodeFieldName,
|
||||||
html: emailHtml,
|
html: emailHtml,
|
||||||
|
@ -15,9 +15,13 @@ type Param = {
|
|||||||
debug?: boolean;
|
debug?: boolean;
|
||||||
secureCookie?: boolean;
|
secureCookie?: boolean;
|
||||||
loginOnly?: boolean;
|
loginOnly?: boolean;
|
||||||
|
/**
|
||||||
|
* Login without calling external API
|
||||||
|
*/
|
||||||
|
forceLocal?: boolean;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* # SERVER FUNCTION: Login with google Function
|
* # 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 {};
|
export {};
|
||||||
|
@ -23,7 +23,7 @@ const grab_cookie_expirt_date_1 = __importDefault(require("../../../utils/grab-c
|
|||||||
* # SERVER FUNCTION: Login with google Function
|
* # SERVER FUNCTION: Login with google Function
|
||||||
*/
|
*/
|
||||||
function googleAuth(_a) {
|
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;
|
var _b;
|
||||||
const grabedHostNames = (0, grab_host_names_1.default)({
|
const grabedHostNames = (0, grab_host_names_1.default)({
|
||||||
userId: apiUserID || process.env.DSQL_API_USER_ID,
|
userId: apiUserID || process.env.DSQL_API_USER_ID,
|
||||||
@ -66,17 +66,7 @@ function googleAuth(_a) {
|
|||||||
let httpResponse = {
|
let httpResponse = {
|
||||||
success: false,
|
success: false,
|
||||||
};
|
};
|
||||||
/**
|
if (forceLocal) {
|
||||||
* 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 (debug) {
|
if (debug) {
|
||||||
console.log(`Google login with Local Paradigm ...`);
|
console.log(`Google login with Local Paradigm ...`);
|
||||||
}
|
}
|
||||||
@ -85,6 +75,7 @@ function googleAuth(_a) {
|
|||||||
additionalFields,
|
additionalFields,
|
||||||
additionalData,
|
additionalData,
|
||||||
debug,
|
debug,
|
||||||
|
loginOnly,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
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 {
|
export interface FileObjectType {
|
||||||
fileName?: string;
|
fileName?: string;
|
||||||
private?: boolean;
|
private?: boolean;
|
||||||
fileType?: string;
|
fileType?: (typeof FileMimeTypes)[number];
|
||||||
fileSize?: number;
|
fileSize?: number;
|
||||||
fileBase64?: string;
|
fileBase64?: string;
|
||||||
fileBase64Full?: string;
|
fileBase64Full?: string;
|
||||||
@ -1420,12 +1420,12 @@ export type DatasquirelWindowEventPayloadType = {
|
|||||||
* # Docker Compose Types
|
* # Docker Compose Types
|
||||||
*/
|
*/
|
||||||
export type DockerCompose = {
|
export type DockerCompose = {
|
||||||
services: DockerComposeServices;
|
services: DockerComposeServicesType;
|
||||||
networks: DockerComposeNetworks;
|
networks: DockerComposeNetworks;
|
||||||
name: string;
|
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 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;
|
[key in (typeof DockerComposeServices)[number]]: DockerComposeServiceWithBuildObject;
|
||||||
};
|
};
|
||||||
export type DockerComposeNetworks = {
|
export type DockerComposeNetworks = {
|
||||||
@ -1448,6 +1448,7 @@ export type DockerComposeServiceWithBuildObject = {
|
|||||||
hostname: string;
|
hostname: string;
|
||||||
volumes: string[];
|
volumes: string[];
|
||||||
environment: string[];
|
environment: string[];
|
||||||
|
ports?: string[];
|
||||||
networks?: DockerComposeServiceNetworkObject;
|
networks?: DockerComposeServiceNetworkObject;
|
||||||
restart?: string;
|
restart?: string;
|
||||||
depends_on?: {
|
depends_on?: {
|
||||||
@ -1501,7 +1502,7 @@ export type MediaUploadDataType = ImageObjectType & FileObjectType & {
|
|||||||
overwrite?: boolean;
|
overwrite?: boolean;
|
||||||
};
|
};
|
||||||
export declare const ImageMimeTypes: (keyof sharp.FormatEnum)[];
|
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 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 declare const CurrentlyEditedFieldActions: readonly ["edit-field", "edit-index", "delete-field", "delete-index", "new-field", "new-index", "move-up", "move-down", "complete"];
|
||||||
export type CurrentlyEditedTableSchemaType = {
|
export type CurrentlyEditedTableSchemaType = {
|
||||||
@ -1576,6 +1577,7 @@ export type LoginUserParam = {
|
|||||||
dbUserId?: string | number;
|
dbUserId?: string | number;
|
||||||
cleanupTokens?: boolean;
|
cleanupTokens?: boolean;
|
||||||
secureCookie?: boolean;
|
secureCookie?: boolean;
|
||||||
|
useLocal?: boolean;
|
||||||
};
|
};
|
||||||
export declare const UserSelectFields: readonly [{
|
export declare const UserSelectFields: readonly [{
|
||||||
readonly field: "first_name";
|
readonly field: "first_name";
|
||||||
@ -1611,7 +1613,7 @@ export declare const InvitedUserSelectFields: readonly [{
|
|||||||
readonly alias: "invited_user_last_name";
|
readonly alias: "invited_user_last_name";
|
||||||
}, {
|
}, {
|
||||||
readonly field: "email";
|
readonly field: "email";
|
||||||
readonly alias: "invited_user_email";
|
readonly alias: "invited_user_email_addr";
|
||||||
}, {
|
}, {
|
||||||
readonly field: "image_thumbnail";
|
readonly field: "image_thumbnail";
|
||||||
readonly alias: "invited_user_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",
|
"txt",
|
||||||
"zip",
|
"zip",
|
||||||
"xz",
|
"xz",
|
||||||
|
"tar.xz",
|
||||||
"yaml",
|
"yaml",
|
||||||
"yml",
|
"yml",
|
||||||
];
|
];
|
||||||
@ -221,7 +222,7 @@ exports.InvitedUserSelectFields = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: "email",
|
field: "email",
|
||||||
alias: "invited_user_email",
|
alias: "invited_user_email_addr",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: "image_thumbnail",
|
field: "image_thumbnail",
|
||||||
|
@ -29,13 +29,14 @@ export default function grabDirNames(param?: Param): {
|
|||||||
dbNginxLoadBalancerConfigFile: string;
|
dbNginxLoadBalancerConfigFile: string;
|
||||||
dockerComposeFile: string;
|
dockerComposeFile: string;
|
||||||
dockerComposeFileAlt: string;
|
dockerComposeFileAlt: string;
|
||||||
testDockerComposeFile: string;
|
dsqlDockerComposeFile: string;
|
||||||
testDockerComposeFileAlt: string;
|
dsqlDockerComposeFileAlt: string;
|
||||||
extraDockerComposeFile: string;
|
extraDockerComposeFile: string;
|
||||||
extraDockerComposeFileAlt: string;
|
extraDockerComposeFileAlt: string;
|
||||||
siteSetupFile: string;
|
siteSetupFile: string;
|
||||||
envFile: string;
|
envFile: string;
|
||||||
testEnvFile: string;
|
dsqlEnvFileName: string;
|
||||||
|
dsqlEnvFile: string;
|
||||||
userPublicMediaDir: string | undefined;
|
userPublicMediaDir: string | undefined;
|
||||||
userTempSQLFilePath: string | undefined;
|
userTempSQLFilePath: string | undefined;
|
||||||
STATIC_ROOT: string;
|
STATIC_ROOT: string;
|
||||||
@ -69,5 +70,24 @@ export default function grabDirNames(param?: Param): {
|
|||||||
mainDBSSLDir: string;
|
mainDBSSLDir: string;
|
||||||
replica1DBSSLDir: string;
|
replica1DBSSLDir: string;
|
||||||
replica2DBSSLDir: 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 {};
|
export {};
|
||||||
|
@ -15,6 +15,12 @@ function grabDirNames(param) {
|
|||||||
if (!DATA_DIR)
|
if (!DATA_DIR)
|
||||||
throw new Error("Please provide the `DATA_DIR` env variable.");
|
throw new Error("Please provide the `DATA_DIR` env variable.");
|
||||||
const STATIC_ROOT = path_1.default.join(DATA_DIR, "static");
|
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 publicImagesDir = path_1.default.join(STATIC_ROOT, `images`);
|
||||||
const publicDir = path_1.default.join(appDir, "public");
|
const publicDir = path_1.default.join(appDir, "public");
|
||||||
const publicSSLDir = path_1.default.join(publicDir, "documents", "ssl");
|
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");
|
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 dockerComposeFile = path_1.default.join(appDir, "docker-compose.yml");
|
||||||
let dockerComposeFileAlt = path_1.default.join(appDir, "docker-compose.yaml");
|
let dockerComposeFileAlt = path_1.default.join(appDir, "docker-compose.yaml");
|
||||||
const testDockerComposeFile = path_1.default.join(appDir, "test.docker-compose.yml");
|
const dsqlDockerComposeFileName = "dsql.docker-compose.yml";
|
||||||
const testDockerComposeFileAlt = path_1.default.join(appDir, "test.docker-compose.yaml");
|
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 dbDockerComposeFile = path_1.default.join(appDir, "db.docker-compose.yml");
|
||||||
const dbDockerComposeFileAlt = path_1.default.join(appDir, "db.docker-compose.yaml");
|
const dbDockerComposeFileAlt = path_1.default.join(appDir, "db.docker-compose.yaml");
|
||||||
const extraDockerComposeFile = path_1.default.join(appDir, "extra.docker-compose.yml");
|
const extraDockerComposeFile = path_1.default.join(appDir, "extra.docker-compose.yml");
|
||||||
const extraDockerComposeFileAlt = path_1.default.join(appDir, "extra.docker-compose.yaml");
|
const extraDockerComposeFileAlt = path_1.default.join(appDir, "extra.docker-compose.yaml");
|
||||||
const siteSetupFile = path_1.default.join(appDir, "site-setup.json");
|
const siteSetupFile = path_1.default.join(appDir, "site-setup.json");
|
||||||
const envFile = path_1.default.join(appDir, ".env");
|
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
|
* # Backup Dir names
|
||||||
* @description
|
* @description
|
||||||
@ -119,6 +128,20 @@ function grabDirNames(param) {
|
|||||||
: undefined;
|
: undefined;
|
||||||
const sqlBackupDirName = `sql`;
|
const sqlBackupDirName = `sql`;
|
||||||
const schemasBackupDirName = `schema`;
|
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 {
|
return {
|
||||||
appDir,
|
appDir,
|
||||||
privateDataDir,
|
privateDataDir,
|
||||||
@ -143,13 +166,14 @@ function grabDirNames(param) {
|
|||||||
dbNginxLoadBalancerConfigFile,
|
dbNginxLoadBalancerConfigFile,
|
||||||
dockerComposeFile,
|
dockerComposeFile,
|
||||||
dockerComposeFileAlt,
|
dockerComposeFileAlt,
|
||||||
testDockerComposeFile,
|
dsqlDockerComposeFile,
|
||||||
testDockerComposeFileAlt,
|
dsqlDockerComposeFileAlt,
|
||||||
extraDockerComposeFile,
|
extraDockerComposeFile,
|
||||||
extraDockerComposeFileAlt,
|
extraDockerComposeFileAlt,
|
||||||
siteSetupFile,
|
siteSetupFile,
|
||||||
envFile,
|
envFile,
|
||||||
testEnvFile,
|
dsqlEnvFileName,
|
||||||
|
dsqlEnvFile,
|
||||||
userPublicMediaDir,
|
userPublicMediaDir,
|
||||||
userTempSQLFilePath,
|
userTempSQLFilePath,
|
||||||
STATIC_ROOT,
|
STATIC_ROOT,
|
||||||
@ -183,5 +207,24 @@ function grabDirNames(param) {
|
|||||||
mainDBSSLDir,
|
mainDBSSLDir,
|
||||||
replica1DBSSLDir,
|
replica1DBSSLDir,
|
||||||
replica2DBSSLDir,
|
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;
|
dbServiceName: string;
|
||||||
dbCronServiceName: string;
|
dbCronServiceName: string;
|
||||||
postDbSetupServiceName: string;
|
postDbSetupServiceName: string;
|
||||||
|
setupServiceName: string;
|
||||||
webAppServiceName: string;
|
webAppServiceName: string;
|
||||||
webAppCronServiceName: string;
|
|
||||||
webAppPostDbSetupServiceName: string;
|
webAppPostDbSetupServiceName: string;
|
||||||
dbReplica1ServiceName: string;
|
dbReplica1ServiceName: string;
|
||||||
dbReplica2ServiceName: string;
|
dbReplica2ServiceName: string;
|
||||||
|
reverseProxyServiceName: string;
|
||||||
|
staticServiceName: string;
|
||||||
|
websocketServiceName: string;
|
||||||
|
cronServiceName: string;
|
||||||
};
|
};
|
||||||
|
@ -6,22 +6,30 @@ function grabDockerStackServicesNames() {
|
|||||||
const maxScaleServiceName = `${deploymentName}-dsql-maxscale`;
|
const maxScaleServiceName = `${deploymentName}-dsql-maxscale`;
|
||||||
const dbServiceName = `${deploymentName}-dsql-db`;
|
const dbServiceName = `${deploymentName}-dsql-db`;
|
||||||
const dbCronServiceName = `${deploymentName}-dsql-db-cron`;
|
const dbCronServiceName = `${deploymentName}-dsql-db-cron`;
|
||||||
|
const cronServiceName = `${deploymentName}-dsql-cron`;
|
||||||
const postDbSetupServiceName = `${deploymentName}-dsql-post-db-setup`;
|
const postDbSetupServiceName = `${deploymentName}-dsql-post-db-setup`;
|
||||||
|
const setupServiceName = `${deploymentName}-dsql-setup`;
|
||||||
const webAppServiceName = `${deploymentName}-dsql-web-app`;
|
const webAppServiceName = `${deploymentName}-dsql-web-app`;
|
||||||
const webAppCronServiceName = `${deploymentName}-dsql-web-app-cron`;
|
|
||||||
const webAppPostDbSetupServiceName = `${deploymentName}-dsql-web-app-post-db-setup`;
|
const webAppPostDbSetupServiceName = `${deploymentName}-dsql-web-app-post-db-setup`;
|
||||||
const dbReplica1ServiceName = `${deploymentName}-dsql-db-replica-1`;
|
const dbReplica1ServiceName = `${deploymentName}-dsql-db-replica-1`;
|
||||||
const dbReplica2ServiceName = `${deploymentName}-dsql-db-replica-2`;
|
const dbReplica2ServiceName = `${deploymentName}-dsql-db-replica-2`;
|
||||||
|
const reverseProxyServiceName = `${deploymentName}-dsql-reverse-proxy`;
|
||||||
|
const staticServiceName = `${deploymentName}-dsql-static`;
|
||||||
|
const websocketServiceName = `${deploymentName}-dsql-websocket`;
|
||||||
return {
|
return {
|
||||||
deploymentName,
|
deploymentName,
|
||||||
maxScaleServiceName,
|
maxScaleServiceName,
|
||||||
dbServiceName,
|
dbServiceName,
|
||||||
dbCronServiceName,
|
dbCronServiceName,
|
||||||
postDbSetupServiceName,
|
postDbSetupServiceName,
|
||||||
|
setupServiceName,
|
||||||
webAppServiceName,
|
webAppServiceName,
|
||||||
webAppCronServiceName,
|
|
||||||
webAppPostDbSetupServiceName,
|
webAppPostDbSetupServiceName,
|
||||||
dbReplica1ServiceName,
|
dbReplica1ServiceName,
|
||||||
dbReplica2ServiceName,
|
dbReplica2ServiceName,
|
||||||
|
reverseProxyServiceName,
|
||||||
|
staticServiceName,
|
||||||
|
websocketServiceName,
|
||||||
|
cronServiceName,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -5,4 +5,5 @@ export default function grabIPAddresses(): {
|
|||||||
mainDBIP: string;
|
mainDBIP: string;
|
||||||
localHostIP: string;
|
localHostIP: string;
|
||||||
globalIPPrefix: 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"));
|
const grab_docker_resource_ip_numbers_1 = __importDefault(require("../../grab-docker-resource-ip-numbers"));
|
||||||
function grabIPAddresses() {
|
function grabIPAddresses() {
|
||||||
const globalIPPrefix = process.env.DSQL_NETWORK_IP_PREFIX || "172.72.0";
|
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 webAppIP = `${globalIPPrefix}.${web}`;
|
||||||
const appCronIP = `${globalIPPrefix}.${cron}`;
|
const appCronIP = `${globalIPPrefix}.${cron}`;
|
||||||
const maxScaleIP = `${globalIPPrefix}.${maxscale}`;
|
const maxScaleIP = `${globalIPPrefix}.${maxscale}`;
|
||||||
const mainDBIP = `${globalIPPrefix}.${db}`;
|
const mainDBIP = `${globalIPPrefix}.${db}`;
|
||||||
|
const webSocketIP = `${globalIPPrefix}.${websocket}`;
|
||||||
const localHostIP = `${globalIPPrefix}.1`;
|
const localHostIP = `${globalIPPrefix}.1`;
|
||||||
return {
|
return {
|
||||||
webAppIP,
|
webAppIP,
|
||||||
@ -20,5 +21,6 @@ function grabIPAddresses() {
|
|||||||
mainDBIP,
|
mainDBIP,
|
||||||
localHostIP,
|
localHostIP,
|
||||||
globalIPPrefix,
|
globalIPPrefix,
|
||||||
|
webSocketIP,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ function default_1(_a) {
|
|||||||
genObject: query,
|
genObject: query,
|
||||||
dbFullName,
|
dbFullName,
|
||||||
});
|
});
|
||||||
const DB_CONN = global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
|
||||||
let connQueries = [
|
let connQueries = [
|
||||||
{
|
{
|
||||||
query: queryObject === null || queryObject === void 0 ? void 0 : queryObject.string,
|
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]);
|
const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
|
||||||
return {
|
return {
|
||||||
success: isSuccess,
|
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 });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = connDbHandler;
|
exports.default = connDbHandler;
|
||||||
const debug_log_1 = __importDefault(require("../logging/debug-log"));
|
const debug_log_1 = __importDefault(require("../logging/debug-log"));
|
||||||
|
const grab_dsql_connection_1 = __importDefault(require("../grab-dsql-connection"));
|
||||||
/**
|
/**
|
||||||
* # Run Query From MySQL Connection
|
* # Run Query From MySQL Connection
|
||||||
* @description Run a query from a pre-existing MySQL/Mariadb Connection
|
* @description Run a query from a pre-existing MySQL/Mariadb Connection
|
||||||
@ -34,14 +35,15 @@ query,
|
|||||||
values, debug) {
|
values, debug) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
|
const finalConnection = conn || (yield (0, grab_dsql_connection_1.default)());
|
||||||
try {
|
try {
|
||||||
if (!conn)
|
if (!finalConnection)
|
||||||
throw new Error("No Connection Found!");
|
throw new Error("No Connection Found!");
|
||||||
if (!query)
|
if (!query)
|
||||||
throw new Error("Query String Required!");
|
throw new Error("Query String Required!");
|
||||||
let queryErrorArray = [];
|
let queryErrorArray = [];
|
||||||
if (typeof query == "string") {
|
if (typeof query == "string") {
|
||||||
const res = yield conn.query(trimQuery(query), values);
|
const res = yield finalConnection.query(trimQuery(query), values);
|
||||||
if (debug) {
|
if (debug) {
|
||||||
(0, debug_log_1.default)({
|
(0, debug_log_1.default)({
|
||||||
log: res,
|
log: res,
|
||||||
@ -62,7 +64,7 @@ values, debug) {
|
|||||||
const queryObj = query[i];
|
const queryObj = query[i];
|
||||||
currentQueryError.sql = queryObj.query;
|
currentQueryError.sql = queryObj.query;
|
||||||
currentQueryError.sqlValues = queryObj.values;
|
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) {
|
if (debug) {
|
||||||
(0, debug_log_1.default)({
|
(0, debug_log_1.default)({
|
||||||
log: queryObjRes,
|
log: queryObjRes,
|
||||||
@ -118,7 +120,7 @@ values, debug) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
finally {
|
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) {
|
function grabDSQLConnection(param) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
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)) {
|
if (global.DSQL_USE_LOCAL || (param === null || param === void 0 ? void 0 : param.local)) {
|
||||||
return (global.DSQL_DB_CONN ||
|
return (global.DSQL_DB_CONN ||
|
||||||
(yield mariadb_1.default.createConnection({
|
(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;
|
return 0;
|
||||||
if (isNaN(numberfiedNum))
|
if (isNaN(numberfiedNum))
|
||||||
return 0;
|
return 0;
|
||||||
if (decimals)
|
if (decimals == 0) {
|
||||||
|
return Math.round(Number(numberfiedNum));
|
||||||
|
}
|
||||||
|
else if (decimals) {
|
||||||
return Number(numberfiedNum.toFixed(decimals));
|
return Number(numberfiedNum.toFixed(decimals));
|
||||||
|
}
|
||||||
if (existingDecimals)
|
if (existingDecimals)
|
||||||
return Number(numberfiedNum.toFixed(existingDecimals));
|
return Number(numberfiedNum.toFixed(existingDecimals));
|
||||||
return Math.round(numberfiedNum);
|
return Math.round(numberfiedNum);
|
||||||
|
@ -38,6 +38,7 @@ export default async function loginUser({
|
|||||||
cleanupTokens,
|
cleanupTokens,
|
||||||
secureCookie,
|
secureCookie,
|
||||||
request,
|
request,
|
||||||
|
useLocal,
|
||||||
}: LoginUserParam): Promise<APILoginFunctionReturn> {
|
}: LoginUserParam): Promise<APILoginFunctionReturn> {
|
||||||
const grabedHostNames = grabHostNames({ userId: user_id || apiUserID });
|
const grabedHostNames = grabHostNames({ userId: user_id || apiUserID });
|
||||||
const { host, port, scheme } = grabedHostNames;
|
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
|
* @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 } =
|
if (useLocal) {
|
||||||
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) {}
|
|
||||||
|
|
||||||
httpResponse = await apiLoginUser({
|
httpResponse = await apiLoginUser({
|
||||||
database: database || process.env.DSQL_DB_NAME || "",
|
database: database || process.env.DSQL_DB_NAME || "",
|
||||||
email: payload.email,
|
email: payload.email,
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import fs from "fs";
|
|
||||||
import path from "path";
|
|
||||||
import grabHostNames from "../../utils/grab-host-names";
|
import grabHostNames from "../../utils/grab-host-names";
|
||||||
import apiSendEmailCode from "../../functions/api/users/api-send-email-code";
|
import apiSendEmailCode from "../../functions/api/users/api-send-email-code";
|
||||||
import { SendOneTimeCodeEmailResponse } from "../../types";
|
import { SendOneTimeCodeEmailResponse } from "../../types";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
database?: string;
|
database: string;
|
||||||
email: string;
|
email: string;
|
||||||
temp_code_field_name?: string;
|
temp_code_field_name?: string;
|
||||||
response?: http.ServerResponse & { [s: string]: any };
|
response?: http.ServerResponse & { [s: string]: any };
|
||||||
@ -18,6 +16,7 @@ type Param = {
|
|||||||
sender?: string;
|
sender?: string;
|
||||||
user_id?: boolean;
|
user_id?: boolean;
|
||||||
extraCookies?: import("../../types").CookieObject[];
|
extraCookies?: import("../../types").CookieObject[];
|
||||||
|
useLocal?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,6 +38,7 @@ export default async function sendEmailCode(
|
|||||||
user_id,
|
user_id,
|
||||||
response,
|
response,
|
||||||
extraCookies,
|
extraCookies,
|
||||||
|
useLocal,
|
||||||
} = params;
|
} = params;
|
||||||
|
|
||||||
const grabedHostNames = grabHostNames();
|
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>`;
|
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>`;
|
||||||
|
|
||||||
/**
|
console.log("useLocal", useLocal);
|
||||||
* 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) {}
|
|
||||||
|
|
||||||
|
if (useLocal) {
|
||||||
return await apiSendEmailCode({
|
return await apiSendEmailCode({
|
||||||
database: DSQL_DB_NAME,
|
database,
|
||||||
email,
|
email,
|
||||||
email_login_field: emailLoginTempCodeFieldName,
|
email_login_field: emailLoginTempCodeFieldName,
|
||||||
html: emailHtml,
|
html: emailHtml,
|
||||||
|
@ -20,6 +20,10 @@ type Param = {
|
|||||||
debug?: boolean;
|
debug?: boolean;
|
||||||
secureCookie?: boolean;
|
secureCookie?: boolean;
|
||||||
loginOnly?: boolean;
|
loginOnly?: boolean;
|
||||||
|
/**
|
||||||
|
* Login without calling external API
|
||||||
|
*/
|
||||||
|
forceLocal?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,6 +42,7 @@ export default async function googleAuth({
|
|||||||
debug,
|
debug,
|
||||||
secureCookie,
|
secureCookie,
|
||||||
loginOnly,
|
loginOnly,
|
||||||
|
forceLocal,
|
||||||
}: Param): Promise<APILoginFunctionReturn> {
|
}: Param): Promise<APILoginFunctionReturn> {
|
||||||
const grabedHostNames = grabHostNames({
|
const grabedHostNames = grabHostNames({
|
||||||
userId: apiUserID || process.env.DSQL_API_USER_ID,
|
userId: apiUserID || process.env.DSQL_API_USER_ID,
|
||||||
@ -89,21 +94,7 @@ export default async function googleAuth({
|
|||||||
success: false,
|
success: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
if (forceLocal) {
|
||||||
* 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 (debug) {
|
if (debug) {
|
||||||
console.log(`Google login with Local Paradigm ...`);
|
console.log(`Google login with Local Paradigm ...`);
|
||||||
}
|
}
|
||||||
@ -113,6 +104,7 @@ export default async function googleAuth({
|
|||||||
additionalFields,
|
additionalFields,
|
||||||
additionalData,
|
additionalData,
|
||||||
debug,
|
debug,
|
||||||
|
loginOnly,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
httpResponse = await new Promise((resolve, reject) => {
|
httpResponse = await new Promise((resolve, reject) => {
|
||||||
|
@ -850,7 +850,7 @@ export interface ImageObjectType {
|
|||||||
export interface FileObjectType {
|
export interface FileObjectType {
|
||||||
fileName?: string;
|
fileName?: string;
|
||||||
private?: boolean;
|
private?: boolean;
|
||||||
fileType?: string;
|
fileType?: (typeof FileMimeTypes)[number];
|
||||||
fileSize?: number;
|
fileSize?: number;
|
||||||
fileBase64?: string;
|
fileBase64?: string;
|
||||||
fileBase64Full?: string;
|
fileBase64Full?: string;
|
||||||
@ -1677,7 +1677,7 @@ export type DatasquirelWindowEventPayloadType = {
|
|||||||
* # Docker Compose Types
|
* # Docker Compose Types
|
||||||
*/
|
*/
|
||||||
export type DockerCompose = {
|
export type DockerCompose = {
|
||||||
services: DockerComposeServices;
|
services: DockerComposeServicesType;
|
||||||
networks: DockerComposeNetworks;
|
networks: DockerComposeNetworks;
|
||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
@ -1700,7 +1700,7 @@ export const DockerComposeServices = [
|
|||||||
"web-app-post-db-setup",
|
"web-app-post-db-setup",
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export type DockerComposeServices = {
|
export type DockerComposeServicesType = {
|
||||||
[key in (typeof DockerComposeServices)[number]]: DockerComposeServiceWithBuildObject;
|
[key in (typeof DockerComposeServices)[number]]: DockerComposeServiceWithBuildObject;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1726,6 +1726,7 @@ export type DockerComposeServiceWithBuildObject = {
|
|||||||
hostname: string;
|
hostname: string;
|
||||||
volumes: string[];
|
volumes: string[];
|
||||||
environment: string[];
|
environment: string[];
|
||||||
|
ports?: string[];
|
||||||
networks?: DockerComposeServiceNetworkObject;
|
networks?: DockerComposeServiceNetworkObject;
|
||||||
restart?: string;
|
restart?: string;
|
||||||
depends_on?: {
|
depends_on?: {
|
||||||
@ -1809,6 +1810,7 @@ export const FileMimeTypes = [
|
|||||||
"txt",
|
"txt",
|
||||||
"zip",
|
"zip",
|
||||||
"xz",
|
"xz",
|
||||||
|
"tar.xz",
|
||||||
"yaml",
|
"yaml",
|
||||||
"yml",
|
"yml",
|
||||||
] as const;
|
] as const;
|
||||||
@ -1915,6 +1917,7 @@ export type LoginUserParam = {
|
|||||||
dbUserId?: string | number;
|
dbUserId?: string | number;
|
||||||
cleanupTokens?: boolean;
|
cleanupTokens?: boolean;
|
||||||
secureCookie?: boolean;
|
secureCookie?: boolean;
|
||||||
|
useLocal?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const UserSelectFields = [
|
export const UserSelectFields = [
|
||||||
@ -1966,7 +1969,7 @@ export const InvitedUserSelectFields = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: "email",
|
field: "email",
|
||||||
alias: "invited_user_email",
|
alias: "invited_user_email_addr",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: "image_thumbnail",
|
field: "image_thumbnail",
|
||||||
|
@ -20,6 +20,24 @@ export default function grabDirNames(param?: Param) {
|
|||||||
throw new Error("Please provide the `DATA_DIR` env variable.");
|
throw new Error("Please provide the `DATA_DIR` env variable.");
|
||||||
|
|
||||||
const STATIC_ROOT = path.join(DATA_DIR, "static");
|
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 publicImagesDir = path.join(STATIC_ROOT, `images`);
|
||||||
|
|
||||||
const publicDir = path.join(appDir, "public");
|
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 dockerComposeFile = path.join(appDir, "docker-compose.yml");
|
||||||
let dockerComposeFileAlt = path.join(appDir, "docker-compose.yaml");
|
let dockerComposeFileAlt = path.join(appDir, "docker-compose.yaml");
|
||||||
const testDockerComposeFile = path.join(appDir, "test.docker-compose.yml");
|
const dsqlDockerComposeFileName = "dsql.docker-compose.yml";
|
||||||
const testDockerComposeFileAlt = path.join(
|
const dsqlDockerComposeFileNameAlt = "dsql.docker-compose.yaml";
|
||||||
|
const dsqlDockerComposeFile = path.join(appDir, dsqlDockerComposeFileName);
|
||||||
|
const dsqlDockerComposeFileAlt = path.join(
|
||||||
appDir,
|
appDir,
|
||||||
"test.docker-compose.yaml"
|
dsqlDockerComposeFileNameAlt
|
||||||
);
|
);
|
||||||
const dbDockerComposeFile = path.join(appDir, "db.docker-compose.yml");
|
const dbDockerComposeFile = path.join(appDir, "db.docker-compose.yml");
|
||||||
const dbDockerComposeFileAlt = path.join(appDir, "db.docker-compose.yaml");
|
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 siteSetupFile = path.join(appDir, "site-setup.json");
|
||||||
|
|
||||||
const envFile = path.join(appDir, ".env");
|
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
|
* # Backup Dir names
|
||||||
@ -173,6 +194,32 @@ export default function grabDirNames(param?: Param) {
|
|||||||
const sqlBackupDirName = `sql`;
|
const sqlBackupDirName = `sql`;
|
||||||
const schemasBackupDirName = `schema`;
|
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 {
|
return {
|
||||||
appDir,
|
appDir,
|
||||||
privateDataDir,
|
privateDataDir,
|
||||||
@ -197,13 +244,14 @@ export default function grabDirNames(param?: Param) {
|
|||||||
dbNginxLoadBalancerConfigFile,
|
dbNginxLoadBalancerConfigFile,
|
||||||
dockerComposeFile,
|
dockerComposeFile,
|
||||||
dockerComposeFileAlt,
|
dockerComposeFileAlt,
|
||||||
testDockerComposeFile,
|
dsqlDockerComposeFile,
|
||||||
testDockerComposeFileAlt,
|
dsqlDockerComposeFileAlt,
|
||||||
extraDockerComposeFile,
|
extraDockerComposeFile,
|
||||||
extraDockerComposeFileAlt,
|
extraDockerComposeFileAlt,
|
||||||
siteSetupFile,
|
siteSetupFile,
|
||||||
envFile,
|
envFile,
|
||||||
testEnvFile,
|
dsqlEnvFileName,
|
||||||
|
dsqlEnvFile,
|
||||||
userPublicMediaDir,
|
userPublicMediaDir,
|
||||||
userTempSQLFilePath,
|
userTempSQLFilePath,
|
||||||
STATIC_ROOT,
|
STATIC_ROOT,
|
||||||
@ -237,5 +285,24 @@ export default function grabDirNames(param?: Param) {
|
|||||||
mainDBSSLDir,
|
mainDBSSLDir,
|
||||||
replica1DBSSLDir,
|
replica1DBSSLDir,
|
||||||
replica2DBSSLDir,
|
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 maxScaleServiceName = `${deploymentName}-dsql-maxscale`;
|
||||||
const dbServiceName = `${deploymentName}-dsql-db`;
|
const dbServiceName = `${deploymentName}-dsql-db`;
|
||||||
const dbCronServiceName = `${deploymentName}-dsql-db-cron`;
|
const dbCronServiceName = `${deploymentName}-dsql-db-cron`;
|
||||||
|
const cronServiceName = `${deploymentName}-dsql-cron`;
|
||||||
const postDbSetupServiceName = `${deploymentName}-dsql-post-db-setup`;
|
const postDbSetupServiceName = `${deploymentName}-dsql-post-db-setup`;
|
||||||
|
const setupServiceName = `${deploymentName}-dsql-setup`;
|
||||||
const webAppServiceName = `${deploymentName}-dsql-web-app`;
|
const webAppServiceName = `${deploymentName}-dsql-web-app`;
|
||||||
const webAppCronServiceName = `${deploymentName}-dsql-web-app-cron`;
|
|
||||||
const webAppPostDbSetupServiceName = `${deploymentName}-dsql-web-app-post-db-setup`;
|
const webAppPostDbSetupServiceName = `${deploymentName}-dsql-web-app-post-db-setup`;
|
||||||
const dbReplica1ServiceName = `${deploymentName}-dsql-db-replica-1`;
|
const dbReplica1ServiceName = `${deploymentName}-dsql-db-replica-1`;
|
||||||
const dbReplica2ServiceName = `${deploymentName}-dsql-db-replica-2`;
|
const dbReplica2ServiceName = `${deploymentName}-dsql-db-replica-2`;
|
||||||
|
const reverseProxyServiceName = `${deploymentName}-dsql-reverse-proxy`;
|
||||||
|
const staticServiceName = `${deploymentName}-dsql-static`;
|
||||||
|
const websocketServiceName = `${deploymentName}-dsql-websocket`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
deploymentName,
|
deploymentName,
|
||||||
@ -17,10 +21,14 @@ export default function grabDockerStackServicesNames() {
|
|||||||
dbServiceName,
|
dbServiceName,
|
||||||
dbCronServiceName,
|
dbCronServiceName,
|
||||||
postDbSetupServiceName,
|
postDbSetupServiceName,
|
||||||
|
setupServiceName,
|
||||||
webAppServiceName,
|
webAppServiceName,
|
||||||
webAppCronServiceName,
|
|
||||||
webAppPostDbSetupServiceName,
|
webAppPostDbSetupServiceName,
|
||||||
dbReplica1ServiceName,
|
dbReplica1ServiceName,
|
||||||
dbReplica2ServiceName,
|
dbReplica2ServiceName,
|
||||||
|
reverseProxyServiceName,
|
||||||
|
staticServiceName,
|
||||||
|
websocketServiceName,
|
||||||
|
cronServiceName,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,23 @@ import grabDockerResourceIPNumbers from "../../grab-docker-resource-ip-numbers";
|
|||||||
|
|
||||||
export default function grabIPAddresses() {
|
export default function grabIPAddresses() {
|
||||||
const globalIPPrefix = process.env.DSQL_NETWORK_IP_PREFIX || "172.72.0";
|
const globalIPPrefix = process.env.DSQL_NETWORK_IP_PREFIX || "172.72.0";
|
||||||
const { cron, db, maxscale, postDbSetup, web } =
|
const {
|
||||||
grabDockerResourceIPNumbers();
|
cron,
|
||||||
|
db,
|
||||||
|
maxscale,
|
||||||
|
postDbSetup,
|
||||||
|
web,
|
||||||
|
db_cron,
|
||||||
|
reverse_proxy,
|
||||||
|
web_app_post_db_setup,
|
||||||
|
websocket,
|
||||||
|
} = grabDockerResourceIPNumbers();
|
||||||
|
|
||||||
const webAppIP = `${globalIPPrefix}.${web}`;
|
const webAppIP = `${globalIPPrefix}.${web}`;
|
||||||
const appCronIP = `${globalIPPrefix}.${cron}`;
|
const appCronIP = `${globalIPPrefix}.${cron}`;
|
||||||
const maxScaleIP = `${globalIPPrefix}.${maxscale}`;
|
const maxScaleIP = `${globalIPPrefix}.${maxscale}`;
|
||||||
const mainDBIP = `${globalIPPrefix}.${db}`;
|
const mainDBIP = `${globalIPPrefix}.${db}`;
|
||||||
|
const webSocketIP = `${globalIPPrefix}.${websocket}`;
|
||||||
const localHostIP = `${globalIPPrefix}.1`;
|
const localHostIP = `${globalIPPrefix}.1`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -18,5 +28,6 @@ export default function grabIPAddresses() {
|
|||||||
mainDBIP,
|
mainDBIP,
|
||||||
localHostIP,
|
localHostIP,
|
||||||
globalIPPrefix,
|
globalIPPrefix,
|
||||||
|
webSocketIP,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,6 @@ export default async function <
|
|||||||
dbFullName,
|
dbFullName,
|
||||||
});
|
});
|
||||||
|
|
||||||
const DB_CONN = global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
|
||||||
|
|
||||||
let connQueries: ConnDBHandlerQueryObject[] = [
|
let connQueries: ConnDBHandlerQueryObject[] = [
|
||||||
{
|
{
|
||||||
query: queryObject?.string,
|
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]);
|
const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import debugLog from "../logging/debug-log";
|
import debugLog from "../logging/debug-log";
|
||||||
import { DSQLErrorObject } from "../../types";
|
import { DSQLErrorObject } from "../../types";
|
||||||
import mariadb, { Connection, ConnectionConfig, Pool } from "mariadb";
|
import mariadb, { Connection, ConnectionConfig, Pool } from "mariadb";
|
||||||
|
import grabDSQLConnection from "../grab-dsql-connection";
|
||||||
|
|
||||||
export type ConnDBHandlerQueryObject = {
|
export type ConnDBHandlerQueryObject = {
|
||||||
query: string;
|
query: string;
|
||||||
@ -33,14 +34,16 @@ export default async function connDbHandler<ReturnType = any>(
|
|||||||
values?: ConnDBHandlerQueryObject["values"],
|
values?: ConnDBHandlerQueryObject["values"],
|
||||||
debug?: boolean
|
debug?: boolean
|
||||||
): Promise<Return<ReturnType>> {
|
): Promise<Return<ReturnType>> {
|
||||||
|
const finalConnection = conn || (await grabDSQLConnection());
|
||||||
|
|
||||||
try {
|
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!");
|
if (!query) throw new Error("Query String Required!");
|
||||||
|
|
||||||
let queryErrorArray: DSQLErrorObject[] = [];
|
let queryErrorArray: DSQLErrorObject[] = [];
|
||||||
|
|
||||||
if (typeof query == "string") {
|
if (typeof query == "string") {
|
||||||
const res = await conn.query(trimQuery(query), values);
|
const res = await finalConnection.query(trimQuery(query), values);
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
debugLog({
|
debugLog({
|
||||||
@ -67,7 +70,7 @@ export default async function connDbHandler<ReturnType = any>(
|
|||||||
currentQueryError.sql = queryObj.query;
|
currentQueryError.sql = queryObj.query;
|
||||||
currentQueryError.sqlValues = queryObj.values;
|
currentQueryError.sqlValues = queryObj.values;
|
||||||
|
|
||||||
const queryObjRes = await conn.query(
|
const queryObjRes = await finalConnection.query(
|
||||||
trimQuery(queryObj.query),
|
trimQuery(queryObj.query),
|
||||||
queryObj.values
|
queryObj.values
|
||||||
);
|
);
|
||||||
@ -133,7 +136,7 @@ export default async function connDbHandler<ReturnType = any>(
|
|||||||
// config: conn,
|
// config: conn,
|
||||||
};
|
};
|
||||||
} finally {
|
} finally {
|
||||||
await conn?.end();
|
await finalConnection?.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,21 @@ type Param = {
|
|||||||
export default async function grabDSQLConnection(
|
export default async function grabDSQLConnection(
|
||||||
param?: Param
|
param?: Param
|
||||||
): Promise<Connection> {
|
): 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) {
|
if (global.DSQL_USE_LOCAL || param?.local) {
|
||||||
return (
|
return (
|
||||||
global.DSQL_DB_CONN ||
|
global.DSQL_DB_CONN ||
|
||||||
|
@ -24,7 +24,12 @@ export default function numberfy(num: any, decimals?: number): number {
|
|||||||
if (typeof numberfiedNum !== "number") return 0;
|
if (typeof numberfiedNum !== "number") return 0;
|
||||||
if (isNaN(numberfiedNum)) 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)
|
if (existingDecimals)
|
||||||
return Number(numberfiedNum.toFixed(existingDecimals));
|
return Number(numberfiedNum.toFixed(existingDecimals));
|
||||||
return Math.round(numberfiedNum);
|
return Math.round(numberfiedNum);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "4.8.8",
|
"version": "4.8.9",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
Loading…
Reference in New Issue
Block a user