Updates
This commit is contained in:
@@ -93,7 +93,7 @@ export default async function githubLogin({
|
||||
}
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(
|
||||
"ERROR in githubLogin.js backend function =>",
|
||||
"ERROR in githubLogin.ts backend function =>",
|
||||
error.message
|
||||
);
|
||||
}
|
||||
|
||||
@@ -221,19 +221,19 @@ export default async function handleSocialDb({
|
||||
});
|
||||
} else {
|
||||
console.log(
|
||||
"Social User Failed to insert in 'handleSocialDb.js' backend function =>",
|
||||
"Social User Failed to insert in 'handleSocialDb.ts' backend function =>",
|
||||
newUser
|
||||
);
|
||||
|
||||
return {
|
||||
success: false,
|
||||
payload: null,
|
||||
msg: "Social User Failed to insert in 'handleSocialDb.js' backend function",
|
||||
msg: "Social User Failed to insert in 'handleSocialDb.ts' backend function",
|
||||
};
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.log(
|
||||
"ERROR in 'handleSocialDb.js' backend function =>",
|
||||
"ERROR in 'handleSocialDb.ts' backend function =>",
|
||||
error.message
|
||||
);
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ export default async function apiGoogleLogin({
|
||||
|
||||
return { ...loggedInGoogleUser };
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(`apo-google-login.js ERROR: ${error.message}`);
|
||||
console.log(`api-google-login.ts ERROR: ${error.message}`);
|
||||
|
||||
return {
|
||||
success: false,
|
||||
|
||||
@@ -85,7 +85,7 @@ export default async function addUsersTableToDb({
|
||||
|
||||
return `Done!`;
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(`addUsersTableToDb.js ERROR: ${error.message}`);
|
||||
console.log(`addUsersTableToDb.ts ERROR: ${error.message}`);
|
||||
|
||||
serverError({
|
||||
component: "addUsersTableToDb",
|
||||
|
||||
@@ -6,7 +6,7 @@ import _ from "lodash";
|
||||
* @description this function takes in a text(or number) and returns a sanitized
|
||||
* text, usually without spaces
|
||||
*/
|
||||
function sanitizeSql(text: any, spaces: boolean, regex?: RegExp | null): any {
|
||||
function sanitizeSql(text: any, spaces?: boolean, regex?: RegExp | null): any {
|
||||
if (!text) return "";
|
||||
if (typeof text == "number" || typeof text == "boolean") return text;
|
||||
if (typeof text == "string" && !text?.toString()?.match(/./)) return "";
|
||||
@@ -55,7 +55,7 @@ function sanitizeSql(text: any, spaces: boolean, regex?: RegExp | null): any {
|
||||
*
|
||||
* @returns {object}
|
||||
*/
|
||||
function sanitizeObjects(object: any, spaces: boolean): object {
|
||||
function sanitizeObjects(object: any, spaces?: boolean): object {
|
||||
/** @type {any} */
|
||||
let objectUpdated: any = { ...object };
|
||||
const keys = Object.keys(objectUpdated);
|
||||
@@ -92,7 +92,7 @@ function sanitizeObjects(object: any, spaces: boolean): object {
|
||||
*/
|
||||
function sanitizeArrays(
|
||||
array: any[],
|
||||
spaces: boolean
|
||||
spaces?: boolean
|
||||
): string[] | number[] | object[] {
|
||||
let arrayUpdated = _.cloneDeep(array);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ export default function grabNewUsersTableSchema(params: {
|
||||
|
||||
return userPreset;
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(`grabNewUsersTableSchema.js ERROR: ${error.message}`);
|
||||
console.log(`grabNewUsersTableSchema.ts ERROR: ${error.message}`);
|
||||
|
||||
serverError({
|
||||
component: "grabNewUsersTableSchema",
|
||||
|
||||
@@ -75,10 +75,10 @@ export default function grabSchemaFieldsFromData({
|
||||
|
||||
return finalFields;
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
console.log(`grabSchemaFieldsFromData.js ERROR: ${error.message}`);
|
||||
console.log(`grabSchemaFieldsFromData.ts ERROR: ${error.message}`);
|
||||
|
||||
serverError({
|
||||
component: "grabSchemaFieldsFromData.js",
|
||||
component: "grabSchemaFieldsFromData.ts",
|
||||
message: error.message,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import fs from "fs";
|
||||
import nodemailer, { SendMailOptions } from "nodemailer";
|
||||
import nodemailer from "nodemailer";
|
||||
|
||||
let transporter = nodemailer.createTransport({
|
||||
host: process.env.DSQL_MAIL_HOST,
|
||||
@@ -68,7 +68,7 @@ export default async function handleNodemailer({
|
||||
////////////////////////////////////////
|
||||
|
||||
try {
|
||||
let mailObject: SendMailOptions = {};
|
||||
let mailObject: any = {};
|
||||
|
||||
mailObject["from"] = `"${senderName || "Datasquirel"}" <${sender}>`;
|
||||
mailObject["sender"] = sender;
|
||||
|
||||
@@ -65,7 +65,7 @@ export default async function updateUsersTableSchema({
|
||||
|
||||
return `Done!`;
|
||||
} catch (error: any) {
|
||||
console.log(`addUsersTableToDb.js ERROR: ${error.message}`);
|
||||
console.log(`addUsersTableToDb.ts ERROR: ${error.message}`);
|
||||
|
||||
serverError({
|
||||
component: "addUsersTableToDb",
|
||||
|
||||
@@ -56,5 +56,3 @@ export default function encrypt({
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = encrypt;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
require("dotenv").config({ path: "./../.env" });
|
||||
|
||||
import noDatabaseDbHandler from "./utils/noDatabaseDbHandler";
|
||||
import varDatabaseDbHandler from "./utils/varDatabaseDbHandler";
|
||||
import createTable from "./utils/createTable";
|
||||
@@ -10,8 +8,7 @@ import updateTable from "./utils/updateTable";
|
||||
import dbHandler from "./utils/dbHandler";
|
||||
import EJSON from "../utils/ejson";
|
||||
import { DSQL_DatabaseSchemaType } from "../types";
|
||||
|
||||
const execFlag = process.argv.find((arg) => arg === "--exec");
|
||||
import { parseArgs } from "util";
|
||||
|
||||
type Param = {
|
||||
userId?: number | string | null;
|
||||
@@ -27,6 +24,14 @@ export default async function createDbFromSchema({
|
||||
targetDatabase,
|
||||
dbSchemaData,
|
||||
}: Param) {
|
||||
console.log("///////////////////////////////");
|
||||
console.log("///////////////////////////////");
|
||||
console.log("Rebuilding Database ...");
|
||||
console.log("process.env.DSQL_DB_HOST", process.env.DSQL_DB_HOST);
|
||||
console.log("process.env.DSQL_DB_USERNAME", process.env.DSQL_DB_USERNAME);
|
||||
console.log("process.env.DSQL_DB_PASSWORD", process.env.DSQL_DB_PASSWORD);
|
||||
console.log("process.env.DSQL_DB_NAME", process.env.DSQL_DB_NAME);
|
||||
|
||||
const schemaPath = userId
|
||||
? path.join(
|
||||
String(process.env.DSQL_USER_DB_SCHEMA_PATH),
|
||||
@@ -58,11 +63,15 @@ export default async function createDbFromSchema({
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log("Checking Database ...");
|
||||
|
||||
/** @type {any} */
|
||||
const dbCheck: any = await noDatabaseDbHandler(
|
||||
`SELECT SCHEMA_NAME AS dbFullName FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '${dbFullName}'`
|
||||
);
|
||||
|
||||
console.log("DB Checked Success!");
|
||||
|
||||
if (dbCheck && dbCheck[0]?.dbFullName) {
|
||||
// Database Exists
|
||||
} else {
|
||||
@@ -297,8 +306,21 @@ export default async function createDbFromSchema({
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Database Successfully Rebuilt!");
|
||||
console.log("///////////////////////////////");
|
||||
console.log("///////////////////////////////");
|
||||
}
|
||||
|
||||
if (execFlag) {
|
||||
const { values } = parseArgs({
|
||||
args: process.argv,
|
||||
options: {
|
||||
exec: { type: "boolean" },
|
||||
},
|
||||
strict: true,
|
||||
allowPositionals: true,
|
||||
});
|
||||
|
||||
if (values.exec) {
|
||||
createDbFromSchema({});
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ for (let i = 0; i < sourceFiles.length; i++) {
|
||||
const dstFile = dstFiles[i];
|
||||
|
||||
fs.watch(srcFolder, { recursive: true }, (evtType, prev) => {
|
||||
if (prev?.match(/\(/) || prev?.match(/\.js$/i)) {
|
||||
if (prev?.match(/\(/) || prev?.match(/\.(j|t)s$/i)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,39 +1,16 @@
|
||||
import dbHandler from "./dbHandler";
|
||||
|
||||
/**
|
||||
* # Create database from Schema Function
|
||||
*/
|
||||
export default async function noDatabaseDbHandler(
|
||||
queryString: string
|
||||
): Promise<any> {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
let results;
|
||||
|
||||
/**
|
||||
* Fetch from db
|
||||
*
|
||||
* @description Fetch data from db if no cache
|
||||
*/
|
||||
try {
|
||||
/** ********************* Run Query */
|
||||
results = await dbHandler({ query: queryString });
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (error: any) {
|
||||
console.log("ERROR in noDatabaseDbHandler =>", error.message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return results
|
||||
*
|
||||
* @description Return results add to cache if "req" param is passed
|
||||
*/
|
||||
if (results) {
|
||||
return results;
|
||||
} else {
|
||||
|
||||
@@ -131,6 +131,7 @@ export interface DSQL_MYSQL_user_databases_Type {
|
||||
db_image: string;
|
||||
db_description: string;
|
||||
active_clone: number;
|
||||
active_data: 0 | 1;
|
||||
active_clone_parent_db: string;
|
||||
remote_connected?: number;
|
||||
remote_db_full_name?: string;
|
||||
@@ -365,7 +366,7 @@ export interface DashboardContextType {
|
||||
user?: UserType;
|
||||
databases?: DSQL_MYSQL_user_databases_Type[];
|
||||
setTargetDatabase?: React.Dispatch<
|
||||
React.SetStateAction<DSQL_MYSQL_user_databases_Type>
|
||||
React.SetStateAction<DSQL_MYSQL_user_databases_Type | undefined>
|
||||
>;
|
||||
targetDatabase?: DSQL_MYSQL_user_databases_Type;
|
||||
metrics?: MetricsType;
|
||||
@@ -428,7 +429,7 @@ export interface AddEntryContextType {
|
||||
richTextEditors: React.MutableRefObject<RichTextEditorsRefArray[]>;
|
||||
jsonTextEditors: React.MutableRefObject<JSONTextEditorsRefArray[]>;
|
||||
query: any;
|
||||
duplicateEntry?: any;
|
||||
duplicateEntry: any;
|
||||
confirmedDelegetedUser: any;
|
||||
}
|
||||
|
||||
@@ -505,13 +506,13 @@ export interface SingleDatabaseContextType {
|
||||
}
|
||||
|
||||
export interface ApiKeysContextType {
|
||||
user: UserType;
|
||||
apiKeys: any[];
|
||||
setApiKeys: React.Dispatch<React.SetStateAction<any[]>>;
|
||||
targetApiKey: any | null;
|
||||
setTargetApiKey: React.Dispatch<React.SetStateAction<any | null>>;
|
||||
newApiKey: any | null;
|
||||
setNewApiKey: React.Dispatch<React.SetStateAction<any | null>>;
|
||||
user?: UserType;
|
||||
apiKeys?: any[];
|
||||
setApiKeys?: React.Dispatch<React.SetStateAction<any[]>>;
|
||||
targetApiKey?: any | null;
|
||||
setTargetApiKey?: React.Dispatch<React.SetStateAction<any | null>>;
|
||||
newApiKey?: any | null;
|
||||
setNewApiKey?: React.Dispatch<React.SetStateAction<any | null>>;
|
||||
}
|
||||
|
||||
export interface LoginFormContextType {
|
||||
@@ -544,32 +545,32 @@ export interface DocsAsidePageObject {
|
||||
}
|
||||
|
||||
export interface AllUserUsersContextType {
|
||||
user: UserType;
|
||||
users: MYSQL_delegated_users_table_def[];
|
||||
targetUser: MYSQL_user_users_table_def | null;
|
||||
setTargetUser: React.Dispatch<
|
||||
React.SetStateAction<MYSQL_user_users_table_def | null>
|
||||
user?: UserType;
|
||||
users?: MYSQL_delegated_users_table_def[];
|
||||
targetUser?: MYSQL_user_users_table_def | undefined;
|
||||
setTargetUser?: React.Dispatch<
|
||||
React.SetStateAction<MYSQL_user_users_table_def | undefined>
|
||||
>;
|
||||
databases: DSQL_MYSQL_user_databases_Type[];
|
||||
pendingInvitations: MYSQL_invitations_table_def[];
|
||||
pendingInvitationsReceived: any[];
|
||||
adminUsers: any[];
|
||||
invitedAccounts: any[];
|
||||
databases?: DSQL_MYSQL_user_databases_Type[];
|
||||
pendingInvitations?: MYSQL_invitations_table_def[];
|
||||
pendingInvitationsReceived?: any[];
|
||||
adminUsers?: any[];
|
||||
invitedAccounts?: any[];
|
||||
}
|
||||
|
||||
export interface AddSocialLoginContextType {
|
||||
user: UserType;
|
||||
database: DSQL_MYSQL_user_databases_Type;
|
||||
query: any;
|
||||
socialLogins: SocialLoginObjectType[];
|
||||
user?: UserType;
|
||||
database?: DSQL_MYSQL_user_databases_Type;
|
||||
query?: any;
|
||||
socialLogins?: SocialLoginObjectType[];
|
||||
}
|
||||
|
||||
export interface DelegatedDbContextType {
|
||||
user: UserType;
|
||||
users: MYSQL_user_users_table_def[];
|
||||
targetUser: MYSQL_user_users_table_def | null;
|
||||
targetUser: MYSQL_user_users_table_def | undefined;
|
||||
setTargetUser: React.Dispatch<
|
||||
React.SetStateAction<MYSQL_user_users_table_def | null>
|
||||
React.SetStateAction<MYSQL_user_users_table_def | undefined>
|
||||
>;
|
||||
database: DSQL_MYSQL_user_databases_Type;
|
||||
}
|
||||
@@ -585,9 +586,9 @@ export interface AddUserUserContextType {
|
||||
export interface UserUsersContextType {
|
||||
user: UserType;
|
||||
users: MYSQL_user_users_table_def[];
|
||||
targetUser: MYSQL_user_users_table_def;
|
||||
targetUser?: MYSQL_user_users_table_def;
|
||||
setTargetUser: React.Dispatch<
|
||||
React.SetStateAction<MYSQL_user_users_table_def | null>
|
||||
React.SetStateAction<MYSQL_user_users_table_def | undefined>
|
||||
>;
|
||||
database: DSQL_MYSQL_user_databases_Type;
|
||||
table: DSQL_TableSchemaType;
|
||||
@@ -717,16 +718,16 @@ export interface UserSchemaContextType {
|
||||
}
|
||||
|
||||
export interface ConnectContextType {
|
||||
user: UserType;
|
||||
query: any;
|
||||
mariadbUserCred: MariaDBUserCredType;
|
||||
mariadbUsers: MYSQL_mariadb_users_table_def[];
|
||||
targetMariadbUser: MYSQL_mariadb_users_table_def | null;
|
||||
setTargetMariadbUser: React.Dispatch<
|
||||
user?: UserType;
|
||||
query?: any;
|
||||
mariadbUserCred?: MariaDBUserCredType;
|
||||
mariadbUsers?: MYSQL_mariadb_users_table_def[];
|
||||
targetMariadbUser?: MYSQL_mariadb_users_table_def | null;
|
||||
setTargetMariadbUser?: React.Dispatch<
|
||||
React.SetStateAction<MYSQL_mariadb_users_table_def | null>
|
||||
>;
|
||||
refresh: number;
|
||||
setRefresh: React.Dispatch<React.SetStateAction<number>>;
|
||||
refresh?: number;
|
||||
setRefresh?: React.Dispatch<React.SetStateAction<number>>;
|
||||
}
|
||||
|
||||
export interface MYSQL_mariadb_users_table_def {
|
||||
@@ -750,7 +751,7 @@ export interface DbContextType {
|
||||
databases?: DSQL_MYSQL_user_databases_Type[];
|
||||
targetDatabase?: DSQL_MYSQL_user_databases_Type;
|
||||
setTargetDatabase?: React.Dispatch<
|
||||
React.SetStateAction<DSQL_MYSQL_user_databases_Type>
|
||||
React.SetStateAction<DSQL_MYSQL_user_databases_Type | undefined>
|
||||
>;
|
||||
}
|
||||
|
||||
@@ -761,33 +762,33 @@ export interface MariaDBUserCredType {
|
||||
}
|
||||
|
||||
export interface AddTableContextType {
|
||||
user: UserType;
|
||||
dbSchemaData: DSQL_DatabaseSchemaType[];
|
||||
database: DSQL_MYSQL_user_databases_Type;
|
||||
tables: DSQL_TableSchemaType[];
|
||||
tableFields: DSQL_FieldSchemaType[];
|
||||
setTableFields: React.Dispatch<
|
||||
user?: UserType;
|
||||
dbSchemaData?: DSQL_DatabaseSchemaType[];
|
||||
database?: DSQL_MYSQL_user_databases_Type;
|
||||
tables?: DSQL_TableSchemaType[];
|
||||
tableFields?: DSQL_FieldSchemaType[];
|
||||
setTableFields?: React.Dispatch<
|
||||
React.SetStateAction<DSQL_FieldSchemaType[]>
|
||||
>;
|
||||
targetField: DSQL_FieldSchemaType | null;
|
||||
setTargetField: React.Dispatch<
|
||||
targetField?: DSQL_FieldSchemaType | null;
|
||||
setTargetField?: React.Dispatch<
|
||||
React.SetStateAction<DSQL_FieldSchemaType | null>
|
||||
>;
|
||||
pageRefresh: number | null;
|
||||
setPageRefresh: React.Dispatch<React.SetStateAction<number>>;
|
||||
refreshFieldsListRef: React.MutableRefObject<
|
||||
React.Dispatch<React.SetStateAction<number>>
|
||||
pageRefresh?: number | null;
|
||||
setPageRefresh?: React.Dispatch<React.SetStateAction<number>>;
|
||||
refreshFieldsListRef?: React.MutableRefObject<
|
||||
React.Dispatch<React.SetStateAction<number>> | undefined
|
||||
>;
|
||||
query: any;
|
||||
query?: any;
|
||||
}
|
||||
|
||||
export interface DbSchemaContextType {
|
||||
user: UserType;
|
||||
database: DSQL_MYSQL_user_databases_Type;
|
||||
dbImage: string;
|
||||
setDbImage: React.Dispatch<React.SetStateAction<string>>;
|
||||
dbSchemaData: DSQL_DatabaseSchemaType[];
|
||||
tables: any[];
|
||||
user?: UserType;
|
||||
database?: DSQL_MYSQL_user_databases_Type;
|
||||
dbImage?: string;
|
||||
setDbImage?: React.Dispatch<React.SetStateAction<string>>;
|
||||
dbSchemaData?: DSQL_DatabaseSchemaType[];
|
||||
tables?: any[];
|
||||
}
|
||||
|
||||
export interface DbShellContextType {
|
||||
|
||||
@@ -11,7 +11,7 @@ const MASTER = mysql({
|
||||
? Number(process.env.DSQL_DB_PORT)
|
||||
: undefined,
|
||||
charset: "utf8mb4",
|
||||
ssl: grabDbSSL(),
|
||||
// ssl: grabDbSSL(),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -120,5 +120,3 @@ export default function DSQL_USER_DB_HANDLER({
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DSQL_USER_DB_HANDLER;
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { ServerlessMysql } from "serverless-mysql";
|
||||
|
||||
type QueryObject = {
|
||||
query: string;
|
||||
values?: (string | number | undefined)[];
|
||||
};
|
||||
|
||||
type Return<ReturnType = any> = ReturnType | null;
|
||||
|
||||
/**
|
||||
* # Run Query From MySQL Connection
|
||||
* @description Run a query from a pre-existing MySQL/Mariadb Connection
|
||||
* setup with `serverless-mysql` npm module
|
||||
*/
|
||||
export default async function connDbHandler<ReturnType = any>(
|
||||
/**
|
||||
* ServerlessMySQL Connection Object
|
||||
*/
|
||||
conn: ServerlessMysql,
|
||||
/**
|
||||
* String Or `QueryObject` Array
|
||||
*/
|
||||
query: QueryObject["query"] | QueryObject[],
|
||||
/**
|
||||
* Array of Values to Sanitize and Inject
|
||||
*/
|
||||
values?: QueryObject["values"]
|
||||
): Promise<Return<ReturnType>> {
|
||||
try {
|
||||
if (typeof query == "string") {
|
||||
const res = await conn.query(query, values);
|
||||
return JSON.parse(JSON.stringify(res));
|
||||
} else if (typeof query == "object") {
|
||||
const resArray = [];
|
||||
for (let i = 0; i < query.length; i++) {
|
||||
const queryObj = query[i];
|
||||
const queryObjRes = await conn.query(
|
||||
queryObj.query,
|
||||
queryObj.values
|
||||
);
|
||||
resArray.push(JSON.parse(JSON.stringify(queryObjRes)));
|
||||
}
|
||||
return resArray as any;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (error) {
|
||||
return null;
|
||||
} finally {
|
||||
conn.end();
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,11 @@ function parse(
|
||||
*/
|
||||
function stringify(
|
||||
value: any,
|
||||
replacer?: (this: any, key: string, value: any) => any,
|
||||
replacer?: ((this: any, key: string, value: any) => any) | null,
|
||||
space?: string | number
|
||||
): string | undefined {
|
||||
try {
|
||||
return JSON.stringify(value, replacer, space);
|
||||
return JSON.stringify(value, replacer || undefined, space);
|
||||
} catch (error) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -11,4 +11,4 @@ function endConnection(connection: mysql.Connection) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = endConnection;
|
||||
export default endConnection;
|
||||
|
||||
Reference in New Issue
Block a user