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 });
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const child_process_1 = require("child_process");
|
||||
const grab_db_names_1 = __importDefault(require("../package-shared/utils/grab-db-names"));
|
||||
require("dotenv").config({
|
||||
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" +
|
||||
"'"
|
||||
: "mysqldump";
|
||||
const { DSQL_USER, DSQL_PASS, DSQL_DB_NAME } = process.env;
|
||||
const dbName = DSQL_DB_NAME || "";
|
||||
const { DSQL_USER, DSQL_PASS } = process.env;
|
||||
const { dbFullName } = (0, grab_db_names_1.default)();
|
||||
const dumpFilePathArg = process.argv.indexOf("--file");
|
||||
if (dumpFilePathArg < 0) {
|
||||
console.log("Please provide a dump file path using `--file` argument");
|
||||
process.exit();
|
||||
}
|
||||
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");
|
||||
process.exit();
|
||||
}
|
||||
@ -39,7 +40,7 @@ try {
|
||||
cwd: process.cwd(),
|
||||
};
|
||||
// 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());
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
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
|
||||
*/
|
||||
const { DSQL_DB_NAME } = process.env;
|
||||
if (useLocal) {
|
||||
const result = yield (0, crud_1.default)({
|
||||
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
|
||||
*/
|
||||
const { DSQL_DB_HOST, DSQL_DB_USERNAME, DSQL_DB_PASSWORD, DSQL_DB_NAME } = process.env;
|
||||
if (useLocal) {
|
||||
if (debug) {
|
||||
(0, debug_log_1.default)({
|
||||
|
||||
@ -15,7 +15,7 @@ type Param = {
|
||||
key: string;
|
||||
code: string;
|
||||
email: string | null;
|
||||
database: string;
|
||||
database?: string;
|
||||
clientId: string;
|
||||
clientSecret: string;
|
||||
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 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_db_names_1 = __importDefault(require("../../../utils/grab-db-names"));
|
||||
/**
|
||||
* # 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
|
||||
*/
|
||||
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(/./)) &&
|
||||
(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(/./)) &&
|
||||
@ -74,13 +75,14 @@ function githubAuth(_a) {
|
||||
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
|
||||
}
|
||||
catch (error) { }
|
||||
const { dbFullName } = (0, grab_db_names_1.default)({ dbName: database });
|
||||
httpResponse = yield (0, api_github_login_1.default)({
|
||||
code,
|
||||
email: email || undefined,
|
||||
clientId,
|
||||
clientSecret,
|
||||
additionalFields,
|
||||
database: DSQL_DB_NAME,
|
||||
database: dbFullName,
|
||||
additionalData,
|
||||
});
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ type Param = {
|
||||
encryptionSalt?: string;
|
||||
level?: "deep" | "normal";
|
||||
database?: string;
|
||||
dsqlUserId?: string | number;
|
||||
expiry?: number;
|
||||
csrfHeaderName?: string;
|
||||
debug?: boolean;
|
||||
@ -25,5 +24,5 @@ type Param = {
|
||||
* @description This Function takes in a request object and returns a user object
|
||||
* 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 {};
|
||||
|
||||
@ -22,7 +22,7 @@ const yearInMilliseconds = dayInMilliseconds * 365;
|
||||
* @description This Function takes in a request object and returns a user object
|
||||
* 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 {
|
||||
const finalRequest = req || request;
|
||||
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)({
|
||||
database: database || process.env.DSQL_DB_NAME,
|
||||
database,
|
||||
});
|
||||
if (debug) {
|
||||
(0, debug_log_1.default)({
|
||||
|
||||
@ -5,35 +5,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = getAuthCookieNames;
|
||||
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
|
||||
*/
|
||||
function getAuthCookieNames(params) {
|
||||
var _a, _b;
|
||||
const cookiesPrefix = process.env.DSQL_COOKIES_PREFIX || "dsql_";
|
||||
const cookiesKeyName = process.env.DSQL_COOKIES_KEY_NAME || "key";
|
||||
const cookiesCSRFName = (0, get_csrf_header_name_1.default)();
|
||||
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+_`), "")) ||
|
||||
((_b = process.env.DSQL_DB_NAME) === null || _b === void 0 ? void 0 : _b.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 });
|
||||
let keyCookieName = cookiesPrefix;
|
||||
if (params === null || params === void 0 ? void 0 : params.userId)
|
||||
keyCookieName += `user_${params.userId}_`;
|
||||
if (targetDatabase)
|
||||
keyCookieName += `${targetDatabase}_`;
|
||||
if (dbSlug)
|
||||
keyCookieName += `${dbSlug}_`;
|
||||
keyCookieName += cookiesKeyName;
|
||||
let csrfCookieName = cookiesPrefix;
|
||||
if (params === null || params === void 0 ? void 0 : params.userId)
|
||||
csrfCookieName += `user_${params.userId}_`;
|
||||
if (targetDatabase)
|
||||
csrfCookieName += `${targetDatabase}_`;
|
||||
if (dbSlug)
|
||||
csrfCookieName += `${dbSlug}_`;
|
||||
csrfCookieName += cookiesCSRFName;
|
||||
let oneTimeCodeName = cookiesPrefix;
|
||||
if (params === null || params === void 0 ? void 0 : params.userId)
|
||||
oneTimeCodeName += `user_${params.userId}_`;
|
||||
if (targetDatabase)
|
||||
oneTimeCodeName += `${targetDatabase}_`;
|
||||
if (dbSlug)
|
||||
oneTimeCodeName += `${dbSlug}_`;
|
||||
oneTimeCodeName += cookieOneTimeCodeName;
|
||||
return {
|
||||
keyCookieName,
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabUserDSQLAPIPath;
|
||||
// import grabDbNames from "../../grab-db-names";
|
||||
function grabUserDSQLAPIPath({ apiVersion, paradigm, action, database, userID, }) {
|
||||
const finalAPIVersion = process.env.DSQL_API_VERSION || apiVersion || "v1";
|
||||
const finalParadigm = paradigm || "auth";
|
||||
const finalAction = action || "login";
|
||||
// const { dbFullName } = grabDbNames({ dbName: database });
|
||||
const finalDatabase = database || process.env.DSQL_DB_NAME || "datasquirel";
|
||||
let finalPath = `/api/${finalAPIVersion}/users/${finalParadigm}/${finalDatabase}`;
|
||||
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;
|
||||
userId?: string | number;
|
||||
user?: UserType | null;
|
||||
nullable?: boolean;
|
||||
};
|
||||
/**
|
||||
* # Grab full database name
|
||||
@ -13,9 +14,10 @@ type Param = {
|
||||
* @param param0
|
||||
* @returns
|
||||
*/
|
||||
export default function grabDbNames({ dbName, userId, user }: Param): {
|
||||
export default function grabDbNames(params?: Param): {
|
||||
userDbPrefix: string;
|
||||
dbFullName: string | undefined;
|
||||
dbFullName: string;
|
||||
dbNamePrefix: string | undefined;
|
||||
dbSlug: string;
|
||||
};
|
||||
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
|
||||
* @returns
|
||||
*/
|
||||
function grabDbNames({ dbName, userId, user }) {
|
||||
function grabDbNames(params) {
|
||||
var _a;
|
||||
const dbNamePrefix = process.env.DSQL_USER_DB_PREFIX;
|
||||
const finalUserId = (user === null || user === void 0 ? void 0 : user.id) || userId;
|
||||
const userDbPrefix = `${dbNamePrefix}${finalUserId}_`;
|
||||
const dbFullName = (0, grab_db_full_name_1.default)({ dbName, user, userId });
|
||||
return { userDbPrefix, dbFullName, dbNamePrefix };
|
||||
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 = finalUserId ? `${dbNamePrefix}${finalUserId}_` : ``;
|
||||
const finalDbName = (params === null || params === void 0 ? void 0 : params.dbName) || process.env.DSQL_DB_NAME || process.env.DSQL_DB_SLUG;
|
||||
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 });
|
||||
exports.default = grabDSQLConnectionConfig;
|
||||
const grabDbSSL_1 = __importDefault(require("./backend/grabDbSSL"));
|
||||
const grab_db_names_1 = __importDefault(require("./grab-db-names"));
|
||||
/**
|
||||
* # Grab General CONNECTION for DSQL
|
||||
*/
|
||||
function grabDSQLConnectionConfig(param) {
|
||||
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) ||
|
||||
((param === null || param === void 0 ? void 0 : param.noDb) ? undefined : process.env.DSQL_DB_NAME), port: process.env.DSQL_DB_PORT
|
||||
const dbNames = (param === null || param === void 0 ? void 0 : param.noDb)
|
||||
? 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)
|
||||
: 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;
|
||||
|
||||
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 path from "path";
|
||||
import { execSync } from "child_process";
|
||||
import grabDbNames from "../package-shared/utils/grab-db-names";
|
||||
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), ".env"),
|
||||
@ -17,9 +18,10 @@ const mysqlDumpPath = process.platform?.match(/win/i)
|
||||
"'"
|
||||
: "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");
|
||||
|
||||
if (dumpFilePathArg < 0) {
|
||||
@ -29,7 +31,7 @@ if (dumpFilePathArg < 0) {
|
||||
|
||||
const dumpFilePath = process.argv[dumpFilePathArg + 1];
|
||||
|
||||
if (!dbName?.match(/./)) {
|
||||
if (!dbFullName?.match(/./)) {
|
||||
console.log("DSQL_DB_NAME is required in your `.env` file");
|
||||
process.exit();
|
||||
}
|
||||
@ -47,7 +49,7 @@ try {
|
||||
// if (process.platform.match(/win/i)) execSyncOptions.shell = "bash.exe";
|
||||
|
||||
const dump = execSync(
|
||||
`${mysqlPath} -u ${DSQL_USER} -p${DSQL_PASS} ${dbName} < ${dumpFilePath}`,
|
||||
`${mysqlPath} -u ${DSQL_USER} -p${DSQL_PASS} ${dbFullName} < ${dumpFilePath}`,
|
||||
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
|
||||
*/
|
||||
const { DSQL_DB_NAME } = process.env;
|
||||
|
||||
if (useLocal) {
|
||||
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
|
||||
*/
|
||||
const { DSQL_DB_HOST, DSQL_DB_USERNAME, DSQL_DB_PASSWORD, DSQL_DB_NAME } =
|
||||
process.env;
|
||||
|
||||
if (useLocal) {
|
||||
if (debug) {
|
||||
debugLog({
|
||||
|
||||
@ -5,6 +5,7 @@ import encrypt from "../../../functions/dsql/encrypt";
|
||||
import grabHostNames from "../../../utils/grab-host-names";
|
||||
import apiGithubLogin from "../../../functions/api/users/social/api-github-login";
|
||||
import grabCookieExpiryDate from "../../../utils/grab-cookie-expirt-date";
|
||||
import grabDbNames from "../../../utils/grab-db-names";
|
||||
|
||||
interface FunctionReturn {
|
||||
success: boolean;
|
||||
@ -23,7 +24,7 @@ type Param = {
|
||||
key: string;
|
||||
code: string;
|
||||
email: string | null;
|
||||
database: string;
|
||||
database?: string;
|
||||
clientId: string;
|
||||
clientSecret: string;
|
||||
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
|
||||
*/
|
||||
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?.match(/./) &&
|
||||
@ -126,13 +120,15 @@ export default async function githubAuth({
|
||||
dbSchema = JSON.parse(fs.readFileSync(localDbSchemaPath, "utf8"));
|
||||
} catch (error) {}
|
||||
|
||||
const { dbFullName } = grabDbNames({ dbName: database });
|
||||
|
||||
httpResponse = await apiGithubLogin({
|
||||
code,
|
||||
email: email || undefined,
|
||||
clientId,
|
||||
clientSecret,
|
||||
additionalFields,
|
||||
database: DSQL_DB_NAME,
|
||||
database: dbFullName,
|
||||
additionalData,
|
||||
});
|
||||
} else {
|
||||
|
||||
@ -7,6 +7,7 @@ import { AuthenticatedUser, DATASQUIREL_LoggedInUser } from "../../types";
|
||||
import getCsrfHeaderName from "../../actions/get-csrf-header-name";
|
||||
import grabHostNames from "../../utils/grab-host-names";
|
||||
import debugLog from "../../utils/logging/debug-log";
|
||||
import grabDbNames from "../../utils/grab-db-names";
|
||||
|
||||
const minuteInMilliseconds = 60000;
|
||||
const hourInMilliseconds = minuteInMilliseconds * 60;
|
||||
@ -24,7 +25,6 @@ type Param = {
|
||||
encryptionSalt?: string;
|
||||
level?: "deep" | "normal";
|
||||
database?: string;
|
||||
dsqlUserId?: string | number;
|
||||
expiry?: number;
|
||||
csrfHeaderName?: string;
|
||||
debug?: boolean;
|
||||
@ -44,7 +44,6 @@ export default function userAuth({
|
||||
encryptionSalt,
|
||||
level,
|
||||
database,
|
||||
dsqlUserId,
|
||||
encryptedUserString,
|
||||
expiry = weekInMilliseconds,
|
||||
cookieString,
|
||||
@ -69,7 +68,7 @@ export default function userAuth({
|
||||
}
|
||||
|
||||
const keyNames = getAuthCookieNames({
|
||||
database: database || process.env.DSQL_DB_NAME,
|
||||
database,
|
||||
});
|
||||
|
||||
if (debug) {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import getCsrfHeaderName from "../../../actions/get-csrf-header-name";
|
||||
import { AppNames } from "../../../dict/app-names";
|
||||
import grabDbNames from "../../../utils/grab-db-names";
|
||||
|
||||
type Param = {
|
||||
database?: string;
|
||||
@ -22,29 +23,21 @@ export default function getAuthCookieNames(params?: Param): Return {
|
||||
const cookieOneTimeCodeName =
|
||||
process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME || "one-time-code";
|
||||
|
||||
const targetDatabase =
|
||||
params?.database?.replace(
|
||||
new RegExp(`^${AppNames["DsqlDbPrefix"]}\\d+_`),
|
||||
""
|
||||
) ||
|
||||
process.env.DSQL_DB_NAME?.replace(
|
||||
new RegExp(`^${AppNames["DsqlDbPrefix"]}\\d+_`),
|
||||
""
|
||||
);
|
||||
const { dbSlug } = grabDbNames({ dbName: params?.database });
|
||||
|
||||
let keyCookieName = cookiesPrefix;
|
||||
if (params?.userId) keyCookieName += `user_${params.userId}_`;
|
||||
if (targetDatabase) keyCookieName += `${targetDatabase}_`;
|
||||
if (dbSlug) keyCookieName += `${dbSlug}_`;
|
||||
keyCookieName += cookiesKeyName;
|
||||
|
||||
let csrfCookieName = cookiesPrefix;
|
||||
if (params?.userId) csrfCookieName += `user_${params.userId}_`;
|
||||
if (targetDatabase) csrfCookieName += `${targetDatabase}_`;
|
||||
if (dbSlug) csrfCookieName += `${dbSlug}_`;
|
||||
csrfCookieName += cookiesCSRFName;
|
||||
|
||||
let oneTimeCodeName = cookiesPrefix;
|
||||
if (params?.userId) oneTimeCodeName += `user_${params.userId}_`;
|
||||
if (targetDatabase) oneTimeCodeName += `${targetDatabase}_`;
|
||||
if (dbSlug) oneTimeCodeName += `${dbSlug}_`;
|
||||
oneTimeCodeName += cookieOneTimeCodeName;
|
||||
|
||||
return {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { GrabUserAPIPathParams } from "../../../types";
|
||||
// import grabDbNames from "../../grab-db-names";
|
||||
|
||||
export default function grabUserDSQLAPIPath({
|
||||
apiVersion,
|
||||
@ -11,6 +12,8 @@ export default function grabUserDSQLAPIPath({
|
||||
const finalParadigm = paradigm || "auth";
|
||||
const finalAction = action || "login";
|
||||
|
||||
// const { dbFullName } = grabDbNames({ dbName: database });
|
||||
|
||||
const finalDatabase = database || process.env.DSQL_DB_NAME || "datasquirel";
|
||||
|
||||
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;
|
||||
userId?: string | number;
|
||||
user?: UserType | null;
|
||||
nullable?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -16,12 +17,30 @@ type Param = {
|
||||
* @param param0
|
||||
* @returns
|
||||
*/
|
||||
export default function grabDbNames({ dbName, userId, user }: Param) {
|
||||
export default function grabDbNames(params?: Param) {
|
||||
const dbNamePrefix = process.env.DSQL_USER_DB_PREFIX;
|
||||
const finalUserId = user?.id || userId;
|
||||
const userDbPrefix = `${dbNamePrefix}${finalUserId}_`;
|
||||
const finalUserId = params?.user?.id || params?.userId;
|
||||
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 grabDbSSL from "./backend/grabDbSSL";
|
||||
import { DsqlConnectionParam } from "../types";
|
||||
import grabDbNames from "./grab-db-names";
|
||||
|
||||
/**
|
||||
* # Grab General CONNECTION for DSQL
|
||||
@ -10,13 +11,15 @@ export default function grabDSQLConnectionConfig(
|
||||
): ConnectionConfig {
|
||||
const CONN_TIMEOUT = 10000;
|
||||
|
||||
const dbNames = param?.noDb
|
||||
? undefined
|
||||
: grabDbNames({ dbName: param?.database });
|
||||
|
||||
const config: ConnectionConfig = {
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
user: process.env.DSQL_DB_USERNAME,
|
||||
password: process.env.DSQL_DB_PASSWORD,
|
||||
database:
|
||||
param?.database ||
|
||||
(param?.noDb ? undefined : process.env.DSQL_DB_NAME),
|
||||
database: dbNames?.dbFullName,
|
||||
port: process.env.DSQL_DB_PORT
|
||||
? Number(process.env.DSQL_DB_PORT)
|
||||
: 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",
|
||||
"version": "5.3.3",
|
||||
"version": "5.3.4",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user