Updates
This commit is contained in:
parent
e6b4b09277
commit
90c36f2345
9
dist/engine/dump.js
vendored
9
dist/engine/dump.js
vendored
@ -7,6 +7,7 @@ var _a, _b, _c;
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const path_1 = __importDefault(require("path"));
|
const path_1 = __importDefault(require("path"));
|
||||||
const child_process_1 = require("child_process");
|
const child_process_1 = require("child_process");
|
||||||
|
const grab_db_names_1 = __importDefault(require("../package-shared/utils/grab-db-names"));
|
||||||
require("dotenv").config({
|
require("dotenv").config({
|
||||||
path: path_1.default.resolve(process.cwd(), ".env"),
|
path: path_1.default.resolve(process.cwd(), ".env"),
|
||||||
});
|
});
|
||||||
@ -18,15 +19,15 @@ const mysqlDumpPath = ((_b = process.platform) === null || _b === void 0 ? void
|
|||||||
"C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe" +
|
"C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe" +
|
||||||
"'"
|
"'"
|
||||||
: "mysqldump";
|
: "mysqldump";
|
||||||
const { DSQL_USER, DSQL_PASS, DSQL_DB_NAME } = process.env;
|
const { DSQL_USER, DSQL_PASS } = process.env;
|
||||||
const dbName = DSQL_DB_NAME || "";
|
const { dbFullName } = (0, grab_db_names_1.default)();
|
||||||
const dumpFilePathArg = process.argv.indexOf("--file");
|
const dumpFilePathArg = process.argv.indexOf("--file");
|
||||||
if (dumpFilePathArg < 0) {
|
if (dumpFilePathArg < 0) {
|
||||||
console.log("Please provide a dump file path using `--file` argument");
|
console.log("Please provide a dump file path using `--file` argument");
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
const dumpFilePath = process.argv[dumpFilePathArg + 1];
|
const dumpFilePath = process.argv[dumpFilePathArg + 1];
|
||||||
if (!(dbName === null || dbName === void 0 ? void 0 : dbName.match(/./))) {
|
if (!(dbFullName === null || dbFullName === void 0 ? void 0 : dbFullName.match(/./))) {
|
||||||
console.log("DSQL_DB_NAME is required in your `.env` file");
|
console.log("DSQL_DB_NAME is required in your `.env` file");
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
@ -39,7 +40,7 @@ try {
|
|||||||
cwd: process.cwd(),
|
cwd: process.cwd(),
|
||||||
};
|
};
|
||||||
// if (process.platform.match(/win/i)) execSyncOptions.shell = "bash.exe";
|
// if (process.platform.match(/win/i)) execSyncOptions.shell = "bash.exe";
|
||||||
const dump = (0, child_process_1.execSync)(`${mysqlPath} -u ${DSQL_USER} -p${DSQL_PASS} ${dbName} < ${dumpFilePath}`, execSyncOptions);
|
const dump = (0, child_process_1.execSync)(`${mysqlPath} -u ${DSQL_USER} -p${DSQL_PASS} ${dbFullName} < ${dumpFilePath}`, execSyncOptions);
|
||||||
console.log("Dumped successfully", dump.toString());
|
console.log("Dumped successfully", dump.toString());
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
|||||||
1
dist/package-shared/actions/get.js
vendored
1
dist/package-shared/actions/get.js
vendored
@ -33,7 +33,6 @@ function get(_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_NAME } = process.env;
|
|
||||||
if (useLocal) {
|
if (useLocal) {
|
||||||
const result = yield (0, crud_1.default)({
|
const result = yield (0, crud_1.default)({
|
||||||
action: "get",
|
action: "get",
|
||||||
|
|||||||
1
dist/package-shared/actions/post.js
vendored
1
dist/package-shared/actions/post.js
vendored
@ -36,7 +36,6 @@ function post(_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 (useLocal) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
(0, debug_log_1.default)({
|
(0, debug_log_1.default)({
|
||||||
|
|||||||
@ -15,7 +15,7 @@ type Param = {
|
|||||||
key: string;
|
key: string;
|
||||||
code: string;
|
code: string;
|
||||||
email: string | null;
|
email: string | null;
|
||||||
database: string;
|
database?: string;
|
||||||
clientId: string;
|
clientId: string;
|
||||||
clientSecret: string;
|
clientSecret: string;
|
||||||
response: http.ServerResponse;
|
response: http.ServerResponse;
|
||||||
|
|||||||
@ -19,6 +19,7 @@ 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_github_login_1 = __importDefault(require("../../../functions/api/users/social/api-github-login"));
|
const api_github_login_1 = __importDefault(require("../../../functions/api/users/social/api-github-login"));
|
||||||
const grab_cookie_expirt_date_1 = __importDefault(require("../../../utils/grab-cookie-expirt-date"));
|
const grab_cookie_expirt_date_1 = __importDefault(require("../../../utils/grab-cookie-expirt-date"));
|
||||||
|
const grab_db_names_1 = __importDefault(require("../../../utils/grab-db-names"));
|
||||||
/**
|
/**
|
||||||
* # SERVER FUNCTION: Login with google Function
|
* # SERVER FUNCTION: Login with google Function
|
||||||
*/
|
*/
|
||||||
@ -62,7 +63,7 @@ function githubAuth(_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, DSQL_KEY, DSQL_REF_DB_NAME, DSQL_FULL_SYNC, } = process.env;
|
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(/./)) &&
|
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_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_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
|
||||||
@ -74,13 +75,14 @@ function githubAuth(_a) {
|
|||||||
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
|
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
|
||||||
}
|
}
|
||||||
catch (error) { }
|
catch (error) { }
|
||||||
|
const { dbFullName } = (0, grab_db_names_1.default)({ dbName: database });
|
||||||
httpResponse = yield (0, api_github_login_1.default)({
|
httpResponse = yield (0, api_github_login_1.default)({
|
||||||
code,
|
code,
|
||||||
email: email || undefined,
|
email: email || undefined,
|
||||||
clientId,
|
clientId,
|
||||||
clientSecret,
|
clientSecret,
|
||||||
additionalFields,
|
additionalFields,
|
||||||
database: DSQL_DB_NAME,
|
database: dbFullName,
|
||||||
additionalData,
|
additionalData,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,6 @@ type Param = {
|
|||||||
encryptionSalt?: string;
|
encryptionSalt?: string;
|
||||||
level?: "deep" | "normal";
|
level?: "deep" | "normal";
|
||||||
database?: string;
|
database?: string;
|
||||||
dsqlUserId?: string | number;
|
|
||||||
expiry?: number;
|
expiry?: number;
|
||||||
csrfHeaderName?: string;
|
csrfHeaderName?: string;
|
||||||
debug?: boolean;
|
debug?: boolean;
|
||||||
@ -25,5 +24,5 @@ type Param = {
|
|||||||
* @description This Function takes in a request object and returns a user object
|
* @description This Function takes in a request object and returns a user object
|
||||||
* with the user's data
|
* with the user's data
|
||||||
*/
|
*/
|
||||||
export default function userAuth({ request, req, encryptionKey, encryptionSalt, level, database, dsqlUserId, encryptedUserString, expiry, cookieString, csrfHeaderName, debug, skipFileCheck, }: Param): AuthenticatedUser;
|
export default function userAuth({ request, req, encryptionKey, encryptionSalt, level, database, encryptedUserString, expiry, cookieString, csrfHeaderName, debug, skipFileCheck, }: Param): AuthenticatedUser;
|
||||||
export {};
|
export {};
|
||||||
|
|||||||
@ -22,7 +22,7 @@ const yearInMilliseconds = dayInMilliseconds * 365;
|
|||||||
* @description This Function takes in a request object and returns a user object
|
* @description This Function takes in a request object and returns a user object
|
||||||
* with the user's data
|
* with the user's data
|
||||||
*/
|
*/
|
||||||
function userAuth({ request, req, encryptionKey, encryptionSalt, level, database, dsqlUserId, encryptedUserString, expiry = weekInMilliseconds, cookieString, csrfHeaderName, debug, skipFileCheck, }) {
|
function userAuth({ request, req, encryptionKey, encryptionSalt, level, database, encryptedUserString, expiry = weekInMilliseconds, cookieString, csrfHeaderName, debug, skipFileCheck, }) {
|
||||||
try {
|
try {
|
||||||
const finalRequest = req || request;
|
const finalRequest = req || request;
|
||||||
const cookies = (0, parseCookies_1.default)({
|
const cookies = (0, parseCookies_1.default)({
|
||||||
@ -37,7 +37,7 @@ function userAuth({ request, req, encryptionKey, encryptionSalt, level, database
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const keyNames = (0, get_auth_cookie_names_1.default)({
|
const keyNames = (0, get_auth_cookie_names_1.default)({
|
||||||
database: database || process.env.DSQL_DB_NAME,
|
database,
|
||||||
});
|
});
|
||||||
if (debug) {
|
if (debug) {
|
||||||
(0, debug_log_1.default)({
|
(0, debug_log_1.default)({
|
||||||
|
|||||||
@ -5,35 +5,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = getAuthCookieNames;
|
exports.default = getAuthCookieNames;
|
||||||
const get_csrf_header_name_1 = __importDefault(require("../../../actions/get-csrf-header-name"));
|
const get_csrf_header_name_1 = __importDefault(require("../../../actions/get-csrf-header-name"));
|
||||||
const app_names_1 = require("../../../dict/app-names");
|
const grab_db_names_1 = __importDefault(require("../../../utils/grab-db-names"));
|
||||||
/**
|
/**
|
||||||
* # Grab Auth Cookie Names
|
* # Grab Auth Cookie Names
|
||||||
*/
|
*/
|
||||||
function getAuthCookieNames(params) {
|
function getAuthCookieNames(params) {
|
||||||
var _a, _b;
|
|
||||||
const cookiesPrefix = process.env.DSQL_COOKIES_PREFIX || "dsql_";
|
const cookiesPrefix = process.env.DSQL_COOKIES_PREFIX || "dsql_";
|
||||||
const cookiesKeyName = process.env.DSQL_COOKIES_KEY_NAME || "key";
|
const cookiesKeyName = process.env.DSQL_COOKIES_KEY_NAME || "key";
|
||||||
const cookiesCSRFName = (0, get_csrf_header_name_1.default)();
|
const cookiesCSRFName = (0, get_csrf_header_name_1.default)();
|
||||||
const cookieOneTimeCodeName = process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME || "one-time-code";
|
const cookieOneTimeCodeName = process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME || "one-time-code";
|
||||||
const targetDatabase = ((_a = params === null || params === void 0 ? void 0 : params.database) === null || _a === void 0 ? void 0 : _a.replace(new RegExp(`^${app_names_1.AppNames["DsqlDbPrefix"]}\\d+_`), "")) ||
|
const { dbSlug } = (0, grab_db_names_1.default)({ dbName: params === null || params === void 0 ? void 0 : params.database });
|
||||||
((_b = process.env.DSQL_DB_NAME) === null || _b === void 0 ? void 0 : _b.replace(new RegExp(`^${app_names_1.AppNames["DsqlDbPrefix"]}\\d+_`), ""));
|
|
||||||
let keyCookieName = cookiesPrefix;
|
let keyCookieName = cookiesPrefix;
|
||||||
if (params === null || params === void 0 ? void 0 : params.userId)
|
if (params === null || params === void 0 ? void 0 : params.userId)
|
||||||
keyCookieName += `user_${params.userId}_`;
|
keyCookieName += `user_${params.userId}_`;
|
||||||
if (targetDatabase)
|
if (dbSlug)
|
||||||
keyCookieName += `${targetDatabase}_`;
|
keyCookieName += `${dbSlug}_`;
|
||||||
keyCookieName += cookiesKeyName;
|
keyCookieName += cookiesKeyName;
|
||||||
let csrfCookieName = cookiesPrefix;
|
let csrfCookieName = cookiesPrefix;
|
||||||
if (params === null || params === void 0 ? void 0 : params.userId)
|
if (params === null || params === void 0 ? void 0 : params.userId)
|
||||||
csrfCookieName += `user_${params.userId}_`;
|
csrfCookieName += `user_${params.userId}_`;
|
||||||
if (targetDatabase)
|
if (dbSlug)
|
||||||
csrfCookieName += `${targetDatabase}_`;
|
csrfCookieName += `${dbSlug}_`;
|
||||||
csrfCookieName += cookiesCSRFName;
|
csrfCookieName += cookiesCSRFName;
|
||||||
let oneTimeCodeName = cookiesPrefix;
|
let oneTimeCodeName = cookiesPrefix;
|
||||||
if (params === null || params === void 0 ? void 0 : params.userId)
|
if (params === null || params === void 0 ? void 0 : params.userId)
|
||||||
oneTimeCodeName += `user_${params.userId}_`;
|
oneTimeCodeName += `user_${params.userId}_`;
|
||||||
if (targetDatabase)
|
if (dbSlug)
|
||||||
oneTimeCodeName += `${targetDatabase}_`;
|
oneTimeCodeName += `${dbSlug}_`;
|
||||||
oneTimeCodeName += cookieOneTimeCodeName;
|
oneTimeCodeName += cookieOneTimeCodeName;
|
||||||
return {
|
return {
|
||||||
keyCookieName,
|
keyCookieName,
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = grabUserDSQLAPIPath;
|
exports.default = grabUserDSQLAPIPath;
|
||||||
|
// import grabDbNames from "../../grab-db-names";
|
||||||
function grabUserDSQLAPIPath({ apiVersion, paradigm, action, database, userID, }) {
|
function grabUserDSQLAPIPath({ apiVersion, paradigm, action, database, userID, }) {
|
||||||
const finalAPIVersion = process.env.DSQL_API_VERSION || apiVersion || "v1";
|
const finalAPIVersion = process.env.DSQL_API_VERSION || apiVersion || "v1";
|
||||||
const finalParadigm = paradigm || "auth";
|
const finalParadigm = paradigm || "auth";
|
||||||
const finalAction = action || "login";
|
const finalAction = action || "login";
|
||||||
|
// const { dbFullName } = grabDbNames({ dbName: database });
|
||||||
const finalDatabase = database || process.env.DSQL_DB_NAME || "datasquirel";
|
const finalDatabase = database || process.env.DSQL_DB_NAME || "datasquirel";
|
||||||
let finalPath = `/api/${finalAPIVersion}/users/${finalParadigm}/${finalDatabase}`;
|
let finalPath = `/api/${finalAPIVersion}/users/${finalParadigm}/${finalDatabase}`;
|
||||||
switch (paradigm) {
|
switch (paradigm) {
|
||||||
|
|||||||
1
dist/package-shared/utils/check-array-depth copy.d.ts
vendored
Normal file
1
dist/package-shared/utils/check-array-depth copy.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export default function checkArrayDepth(arr: any[] | any[][] | any[][][] | any, depth: number): boolean;
|
||||||
10
dist/package-shared/utils/check-array-depth copy.js
vendored
Normal file
10
dist/package-shared/utils/check-array-depth copy.js
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.default = checkArrayDepth;
|
||||||
|
function checkArrayDepth(arr, depth) {
|
||||||
|
if (!Array.isArray(arr))
|
||||||
|
return false;
|
||||||
|
if (depth === 1)
|
||||||
|
return true;
|
||||||
|
return arr.every((item) => checkArrayDepth(item, depth - 1));
|
||||||
|
}
|
||||||
6
dist/package-shared/utils/grab-db-names.d.ts
vendored
6
dist/package-shared/utils/grab-db-names.d.ts
vendored
@ -6,6 +6,7 @@ type Param = {
|
|||||||
dbName?: string;
|
dbName?: string;
|
||||||
userId?: string | number;
|
userId?: string | number;
|
||||||
user?: UserType | null;
|
user?: UserType | null;
|
||||||
|
nullable?: boolean;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* # Grab full database name
|
* # Grab full database name
|
||||||
@ -13,9 +14,10 @@ type Param = {
|
|||||||
* @param param0
|
* @param param0
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export default function grabDbNames({ dbName, userId, user }: Param): {
|
export default function grabDbNames(params?: Param): {
|
||||||
userDbPrefix: string;
|
userDbPrefix: string;
|
||||||
dbFullName: string | undefined;
|
dbFullName: string;
|
||||||
dbNamePrefix: string | undefined;
|
dbNamePrefix: string | undefined;
|
||||||
|
dbSlug: string;
|
||||||
};
|
};
|
||||||
export {};
|
export {};
|
||||||
|
|||||||
26
dist/package-shared/utils/grab-db-names.js
vendored
26
dist/package-shared/utils/grab-db-names.js
vendored
@ -11,10 +11,26 @@ const grab_db_full_name_1 = __importDefault(require("./grab-db-full-name"));
|
|||||||
* @param param0
|
* @param param0
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function grabDbNames({ dbName, userId, user }) {
|
function grabDbNames(params) {
|
||||||
|
var _a;
|
||||||
const dbNamePrefix = process.env.DSQL_USER_DB_PREFIX;
|
const dbNamePrefix = process.env.DSQL_USER_DB_PREFIX;
|
||||||
const finalUserId = (user === null || user === void 0 ? void 0 : user.id) || userId;
|
const finalUserId = ((_a = params === null || params === void 0 ? void 0 : params.user) === null || _a === void 0 ? void 0 : _a.id) || (params === null || params === void 0 ? void 0 : params.userId);
|
||||||
const userDbPrefix = `${dbNamePrefix}${finalUserId}_`;
|
const userDbPrefix = finalUserId ? `${dbNamePrefix}${finalUserId}_` : ``;
|
||||||
const dbFullName = (0, grab_db_full_name_1.default)({ dbName, user, userId });
|
const finalDbName = (params === null || params === void 0 ? void 0 : params.dbName) || process.env.DSQL_DB_NAME || process.env.DSQL_DB_SLUG;
|
||||||
return { userDbPrefix, dbFullName, dbNamePrefix };
|
const dbSlug = finalDbName === null || finalDbName === void 0 ? void 0 : finalDbName.replace(userDbPrefix, "");
|
||||||
|
if (!dbSlug)
|
||||||
|
throw new Error(`No Db Name Provided!`);
|
||||||
|
const dbFullName = (0, grab_db_full_name_1.default)({
|
||||||
|
dbName: dbSlug,
|
||||||
|
user: params === null || params === void 0 ? void 0 : params.user,
|
||||||
|
userId: params === null || params === void 0 ? void 0 : params.userId,
|
||||||
|
});
|
||||||
|
if (!dbFullName)
|
||||||
|
throw new Error(`Couldn't grab DB full name!`);
|
||||||
|
return {
|
||||||
|
userDbPrefix,
|
||||||
|
dbFullName,
|
||||||
|
dbNamePrefix,
|
||||||
|
dbSlug,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,13 +5,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = grabDSQLConnectionConfig;
|
exports.default = grabDSQLConnectionConfig;
|
||||||
const grabDbSSL_1 = __importDefault(require("./backend/grabDbSSL"));
|
const grabDbSSL_1 = __importDefault(require("./backend/grabDbSSL"));
|
||||||
|
const grab_db_names_1 = __importDefault(require("./grab-db-names"));
|
||||||
/**
|
/**
|
||||||
* # Grab General CONNECTION for DSQL
|
* # Grab General CONNECTION for DSQL
|
||||||
*/
|
*/
|
||||||
function grabDSQLConnectionConfig(param) {
|
function grabDSQLConnectionConfig(param) {
|
||||||
const CONN_TIMEOUT = 10000;
|
const CONN_TIMEOUT = 10000;
|
||||||
const config = Object.assign({ 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.database) ||
|
const dbNames = (param === null || param === void 0 ? void 0 : param.noDb)
|
||||||
((param === null || param === void 0 ? void 0 : param.noDb) ? undefined : process.env.DSQL_DB_NAME), port: process.env.DSQL_DB_PORT
|
? undefined
|
||||||
|
: (0, grab_db_names_1.default)({ dbName: param === null || param === void 0 ? void 0 : param.database });
|
||||||
|
const config = Object.assign({ host: process.env.DSQL_DB_HOST, user: process.env.DSQL_DB_USERNAME, password: process.env.DSQL_DB_PASSWORD, database: dbNames === null || dbNames === void 0 ? void 0 : dbNames.dbFullName, port: process.env.DSQL_DB_PORT
|
||||||
? Number(process.env.DSQL_DB_PORT)
|
? Number(process.env.DSQL_DB_PORT)
|
||||||
: undefined, charset: "utf8mb4", ssl: (0, grabDbSSL_1.default)(), bigIntAsNumber: true, supportBigNumbers: true, bigNumberStrings: false, dateStrings: true, metaAsArray: true, socketTimeout: CONN_TIMEOUT, connectTimeout: CONN_TIMEOUT, compress: true }, param === null || param === void 0 ? void 0 : param.config);
|
: undefined, charset: "utf8mb4", ssl: (0, grabDbSSL_1.default)(), bigIntAsNumber: true, supportBigNumbers: true, bigNumberStrings: false, dateStrings: true, metaAsArray: true, socketTimeout: CONN_TIMEOUT, connectTimeout: CONN_TIMEOUT, compress: true }, param === null || param === void 0 ? void 0 : param.config);
|
||||||
return config;
|
return config;
|
||||||
|
|||||||
4
dist/package-shared/utils/grab-sql-names.d.ts
vendored
Normal file
4
dist/package-shared/utils/grab-sql-names.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
/**
|
||||||
|
* # Grab Names For Query
|
||||||
|
*/
|
||||||
|
export default function grabSQLNames(): {};
|
||||||
9
dist/package-shared/utils/grab-sql-names.js
vendored
Normal file
9
dist/package-shared/utils/grab-sql-names.js
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.default = grabSQLNames;
|
||||||
|
/**
|
||||||
|
* # Grab Names For Query
|
||||||
|
*/
|
||||||
|
function grabSQLNames() {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
@ -3,6 +3,7 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { execSync } from "child_process";
|
import { execSync } from "child_process";
|
||||||
|
import grabDbNames from "../package-shared/utils/grab-db-names";
|
||||||
|
|
||||||
require("dotenv").config({
|
require("dotenv").config({
|
||||||
path: path.resolve(process.cwd(), ".env"),
|
path: path.resolve(process.cwd(), ".env"),
|
||||||
@ -17,9 +18,10 @@ const mysqlDumpPath = process.platform?.match(/win/i)
|
|||||||
"'"
|
"'"
|
||||||
: "mysqldump";
|
: "mysqldump";
|
||||||
|
|
||||||
const { DSQL_USER, DSQL_PASS, DSQL_DB_NAME } = process.env;
|
const { DSQL_USER, DSQL_PASS } = process.env;
|
||||||
|
|
||||||
|
const { dbFullName } = grabDbNames();
|
||||||
|
|
||||||
const dbName = DSQL_DB_NAME || "";
|
|
||||||
const dumpFilePathArg = process.argv.indexOf("--file");
|
const dumpFilePathArg = process.argv.indexOf("--file");
|
||||||
|
|
||||||
if (dumpFilePathArg < 0) {
|
if (dumpFilePathArg < 0) {
|
||||||
@ -29,7 +31,7 @@ if (dumpFilePathArg < 0) {
|
|||||||
|
|
||||||
const dumpFilePath = process.argv[dumpFilePathArg + 1];
|
const dumpFilePath = process.argv[dumpFilePathArg + 1];
|
||||||
|
|
||||||
if (!dbName?.match(/./)) {
|
if (!dbFullName?.match(/./)) {
|
||||||
console.log("DSQL_DB_NAME is required in your `.env` file");
|
console.log("DSQL_DB_NAME is required in your `.env` file");
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
@ -47,7 +49,7 @@ try {
|
|||||||
// if (process.platform.match(/win/i)) execSyncOptions.shell = "bash.exe";
|
// if (process.platform.match(/win/i)) execSyncOptions.shell = "bash.exe";
|
||||||
|
|
||||||
const dump = execSync(
|
const dump = execSync(
|
||||||
`${mysqlPath} -u ${DSQL_USER} -p${DSQL_PASS} ${dbName} < ${dumpFilePath}`,
|
`${mysqlPath} -u ${DSQL_USER} -p${DSQL_PASS} ${dbFullName} < ${dumpFilePath}`,
|
||||||
execSyncOptions
|
execSyncOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,6 @@ export default async function get<
|
|||||||
*
|
*
|
||||||
* @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_NAME } = process.env;
|
|
||||||
|
|
||||||
if (useLocal) {
|
if (useLocal) {
|
||||||
const result = await dsqlCrud({
|
const result = await dsqlCrud({
|
||||||
|
|||||||
@ -47,9 +47,6 @@ export default async function post({
|
|||||||
*
|
*
|
||||||
* @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 (useLocal) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
debugLog({
|
debugLog({
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import encrypt from "../../../functions/dsql/encrypt";
|
|||||||
import grabHostNames from "../../../utils/grab-host-names";
|
import grabHostNames from "../../../utils/grab-host-names";
|
||||||
import apiGithubLogin from "../../../functions/api/users/social/api-github-login";
|
import apiGithubLogin from "../../../functions/api/users/social/api-github-login";
|
||||||
import grabCookieExpiryDate from "../../../utils/grab-cookie-expirt-date";
|
import grabCookieExpiryDate from "../../../utils/grab-cookie-expirt-date";
|
||||||
|
import grabDbNames from "../../../utils/grab-db-names";
|
||||||
|
|
||||||
interface FunctionReturn {
|
interface FunctionReturn {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
@ -23,7 +24,7 @@ type Param = {
|
|||||||
key: string;
|
key: string;
|
||||||
code: string;
|
code: string;
|
||||||
email: string | null;
|
email: string | null;
|
||||||
database: string;
|
database?: string;
|
||||||
clientId: string;
|
clientId: string;
|
||||||
clientSecret: string;
|
clientSecret: string;
|
||||||
response: http.ServerResponse;
|
response: http.ServerResponse;
|
||||||
@ -96,15 +97,8 @@ export default async function githubAuth({
|
|||||||
*
|
*
|
||||||
* @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 {
|
const { DSQL_DB_HOST, DSQL_DB_USERNAME, DSQL_DB_PASSWORD, DSQL_DB_NAME } =
|
||||||
DSQL_DB_HOST,
|
process.env;
|
||||||
DSQL_DB_USERNAME,
|
|
||||||
DSQL_DB_PASSWORD,
|
|
||||||
DSQL_DB_NAME,
|
|
||||||
DSQL_KEY,
|
|
||||||
DSQL_REF_DB_NAME,
|
|
||||||
DSQL_FULL_SYNC,
|
|
||||||
} = process.env;
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
DSQL_DB_HOST?.match(/./) &&
|
DSQL_DB_HOST?.match(/./) &&
|
||||||
@ -126,13 +120,15 @@ export default async function githubAuth({
|
|||||||
dbSchema = JSON.parse(fs.readFileSync(localDbSchemaPath, "utf8"));
|
dbSchema = JSON.parse(fs.readFileSync(localDbSchemaPath, "utf8"));
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
|
|
||||||
|
const { dbFullName } = grabDbNames({ dbName: database });
|
||||||
|
|
||||||
httpResponse = await apiGithubLogin({
|
httpResponse = await apiGithubLogin({
|
||||||
code,
|
code,
|
||||||
email: email || undefined,
|
email: email || undefined,
|
||||||
clientId,
|
clientId,
|
||||||
clientSecret,
|
clientSecret,
|
||||||
additionalFields,
|
additionalFields,
|
||||||
database: DSQL_DB_NAME,
|
database: dbFullName,
|
||||||
additionalData,
|
additionalData,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import { AuthenticatedUser, DATASQUIREL_LoggedInUser } from "../../types";
|
|||||||
import getCsrfHeaderName from "../../actions/get-csrf-header-name";
|
import getCsrfHeaderName from "../../actions/get-csrf-header-name";
|
||||||
import grabHostNames from "../../utils/grab-host-names";
|
import grabHostNames from "../../utils/grab-host-names";
|
||||||
import debugLog from "../../utils/logging/debug-log";
|
import debugLog from "../../utils/logging/debug-log";
|
||||||
|
import grabDbNames from "../../utils/grab-db-names";
|
||||||
|
|
||||||
const minuteInMilliseconds = 60000;
|
const minuteInMilliseconds = 60000;
|
||||||
const hourInMilliseconds = minuteInMilliseconds * 60;
|
const hourInMilliseconds = minuteInMilliseconds * 60;
|
||||||
@ -24,7 +25,6 @@ type Param = {
|
|||||||
encryptionSalt?: string;
|
encryptionSalt?: string;
|
||||||
level?: "deep" | "normal";
|
level?: "deep" | "normal";
|
||||||
database?: string;
|
database?: string;
|
||||||
dsqlUserId?: string | number;
|
|
||||||
expiry?: number;
|
expiry?: number;
|
||||||
csrfHeaderName?: string;
|
csrfHeaderName?: string;
|
||||||
debug?: boolean;
|
debug?: boolean;
|
||||||
@ -44,7 +44,6 @@ export default function userAuth({
|
|||||||
encryptionSalt,
|
encryptionSalt,
|
||||||
level,
|
level,
|
||||||
database,
|
database,
|
||||||
dsqlUserId,
|
|
||||||
encryptedUserString,
|
encryptedUserString,
|
||||||
expiry = weekInMilliseconds,
|
expiry = weekInMilliseconds,
|
||||||
cookieString,
|
cookieString,
|
||||||
@ -69,7 +68,7 @@ export default function userAuth({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const keyNames = getAuthCookieNames({
|
const keyNames = getAuthCookieNames({
|
||||||
database: database || process.env.DSQL_DB_NAME,
|
database,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import getCsrfHeaderName from "../../../actions/get-csrf-header-name";
|
import getCsrfHeaderName from "../../../actions/get-csrf-header-name";
|
||||||
import { AppNames } from "../../../dict/app-names";
|
import { AppNames } from "../../../dict/app-names";
|
||||||
|
import grabDbNames from "../../../utils/grab-db-names";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
database?: string;
|
database?: string;
|
||||||
@ -22,29 +23,21 @@ export default function getAuthCookieNames(params?: Param): Return {
|
|||||||
const cookieOneTimeCodeName =
|
const cookieOneTimeCodeName =
|
||||||
process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME || "one-time-code";
|
process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME || "one-time-code";
|
||||||
|
|
||||||
const targetDatabase =
|
const { dbSlug } = grabDbNames({ dbName: params?.database });
|
||||||
params?.database?.replace(
|
|
||||||
new RegExp(`^${AppNames["DsqlDbPrefix"]}\\d+_`),
|
|
||||||
""
|
|
||||||
) ||
|
|
||||||
process.env.DSQL_DB_NAME?.replace(
|
|
||||||
new RegExp(`^${AppNames["DsqlDbPrefix"]}\\d+_`),
|
|
||||||
""
|
|
||||||
);
|
|
||||||
|
|
||||||
let keyCookieName = cookiesPrefix;
|
let keyCookieName = cookiesPrefix;
|
||||||
if (params?.userId) keyCookieName += `user_${params.userId}_`;
|
if (params?.userId) keyCookieName += `user_${params.userId}_`;
|
||||||
if (targetDatabase) keyCookieName += `${targetDatabase}_`;
|
if (dbSlug) keyCookieName += `${dbSlug}_`;
|
||||||
keyCookieName += cookiesKeyName;
|
keyCookieName += cookiesKeyName;
|
||||||
|
|
||||||
let csrfCookieName = cookiesPrefix;
|
let csrfCookieName = cookiesPrefix;
|
||||||
if (params?.userId) csrfCookieName += `user_${params.userId}_`;
|
if (params?.userId) csrfCookieName += `user_${params.userId}_`;
|
||||||
if (targetDatabase) csrfCookieName += `${targetDatabase}_`;
|
if (dbSlug) csrfCookieName += `${dbSlug}_`;
|
||||||
csrfCookieName += cookiesCSRFName;
|
csrfCookieName += cookiesCSRFName;
|
||||||
|
|
||||||
let oneTimeCodeName = cookiesPrefix;
|
let oneTimeCodeName = cookiesPrefix;
|
||||||
if (params?.userId) oneTimeCodeName += `user_${params.userId}_`;
|
if (params?.userId) oneTimeCodeName += `user_${params.userId}_`;
|
||||||
if (targetDatabase) oneTimeCodeName += `${targetDatabase}_`;
|
if (dbSlug) oneTimeCodeName += `${dbSlug}_`;
|
||||||
oneTimeCodeName += cookieOneTimeCodeName;
|
oneTimeCodeName += cookieOneTimeCodeName;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { GrabUserAPIPathParams } from "../../../types";
|
import { GrabUserAPIPathParams } from "../../../types";
|
||||||
|
// import grabDbNames from "../../grab-db-names";
|
||||||
|
|
||||||
export default function grabUserDSQLAPIPath({
|
export default function grabUserDSQLAPIPath({
|
||||||
apiVersion,
|
apiVersion,
|
||||||
@ -11,6 +12,8 @@ export default function grabUserDSQLAPIPath({
|
|||||||
const finalParadigm = paradigm || "auth";
|
const finalParadigm = paradigm || "auth";
|
||||||
const finalAction = action || "login";
|
const finalAction = action || "login";
|
||||||
|
|
||||||
|
// const { dbFullName } = grabDbNames({ dbName: database });
|
||||||
|
|
||||||
const finalDatabase = database || process.env.DSQL_DB_NAME || "datasquirel";
|
const finalDatabase = database || process.env.DSQL_DB_NAME || "datasquirel";
|
||||||
|
|
||||||
let finalPath = `/api/${finalAPIVersion}/users/${finalParadigm}/${finalDatabase}`;
|
let finalPath = `/api/${finalAPIVersion}/users/${finalParadigm}/${finalDatabase}`;
|
||||||
|
|||||||
8
package-shared/utils/check-array-depth copy.ts
Normal file
8
package-shared/utils/check-array-depth copy.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export default function checkArrayDepth(
|
||||||
|
arr: any[] | any[][] | any[][][] | any,
|
||||||
|
depth: number
|
||||||
|
): boolean {
|
||||||
|
if (!Array.isArray(arr)) return false;
|
||||||
|
if (depth === 1) return true;
|
||||||
|
return arr.every((item) => checkArrayDepth(item, depth - 1));
|
||||||
|
}
|
||||||
@ -8,6 +8,7 @@ type Param = {
|
|||||||
dbName?: string;
|
dbName?: string;
|
||||||
userId?: string | number;
|
userId?: string | number;
|
||||||
user?: UserType | null;
|
user?: UserType | null;
|
||||||
|
nullable?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,12 +17,30 @@ type Param = {
|
|||||||
* @param param0
|
* @param param0
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export default function grabDbNames({ dbName, userId, user }: Param) {
|
export default function grabDbNames(params?: Param) {
|
||||||
const dbNamePrefix = process.env.DSQL_USER_DB_PREFIX;
|
const dbNamePrefix = process.env.DSQL_USER_DB_PREFIX;
|
||||||
const finalUserId = user?.id || userId;
|
const finalUserId = params?.user?.id || params?.userId;
|
||||||
const userDbPrefix = `${dbNamePrefix}${finalUserId}_`;
|
const userDbPrefix = finalUserId ? `${dbNamePrefix}${finalUserId}_` : ``;
|
||||||
|
|
||||||
const dbFullName = grabDbFullName({ dbName, user, userId });
|
const finalDbName =
|
||||||
|
params?.dbName || process.env.DSQL_DB_NAME || process.env.DSQL_DB_SLUG;
|
||||||
|
|
||||||
return { userDbPrefix, dbFullName, dbNamePrefix };
|
const dbSlug = finalDbName?.replace(userDbPrefix, "");
|
||||||
|
|
||||||
|
if (!dbSlug) throw new Error(`No Db Name Provided!`);
|
||||||
|
|
||||||
|
const dbFullName = grabDbFullName({
|
||||||
|
dbName: dbSlug,
|
||||||
|
user: params?.user,
|
||||||
|
userId: params?.userId,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!dbFullName) throw new Error(`Couldn't grab DB full name!`);
|
||||||
|
|
||||||
|
return {
|
||||||
|
userDbPrefix,
|
||||||
|
dbFullName,
|
||||||
|
dbNamePrefix,
|
||||||
|
dbSlug,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { ConnectionConfig } from "mariadb";
|
import { ConnectionConfig } from "mariadb";
|
||||||
import grabDbSSL from "./backend/grabDbSSL";
|
import grabDbSSL from "./backend/grabDbSSL";
|
||||||
import { DsqlConnectionParam } from "../types";
|
import { DsqlConnectionParam } from "../types";
|
||||||
|
import grabDbNames from "./grab-db-names";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* # Grab General CONNECTION for DSQL
|
* # Grab General CONNECTION for DSQL
|
||||||
@ -10,13 +11,15 @@ export default function grabDSQLConnectionConfig(
|
|||||||
): ConnectionConfig {
|
): ConnectionConfig {
|
||||||
const CONN_TIMEOUT = 10000;
|
const CONN_TIMEOUT = 10000;
|
||||||
|
|
||||||
|
const dbNames = param?.noDb
|
||||||
|
? undefined
|
||||||
|
: grabDbNames({ dbName: param?.database });
|
||||||
|
|
||||||
const config: ConnectionConfig = {
|
const config: ConnectionConfig = {
|
||||||
host: process.env.DSQL_DB_HOST,
|
host: process.env.DSQL_DB_HOST,
|
||||||
user: process.env.DSQL_DB_USERNAME,
|
user: process.env.DSQL_DB_USERNAME,
|
||||||
password: process.env.DSQL_DB_PASSWORD,
|
password: process.env.DSQL_DB_PASSWORD,
|
||||||
database:
|
database: dbNames?.dbFullName,
|
||||||
param?.database ||
|
|
||||||
(param?.noDb ? undefined : process.env.DSQL_DB_NAME),
|
|
||||||
port: process.env.DSQL_DB_PORT
|
port: process.env.DSQL_DB_PORT
|
||||||
? Number(process.env.DSQL_DB_PORT)
|
? Number(process.env.DSQL_DB_PORT)
|
||||||
: undefined,
|
: undefined,
|
||||||
|
|||||||
6
package-shared/utils/grab-sql-names.ts
Normal file
6
package-shared/utils/grab-sql-names.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* # Grab Names For Query
|
||||||
|
*/
|
||||||
|
export default function grabSQLNames() {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "5.3.3",
|
"version": "5.3.4",
|
||||||
"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