Updates
This commit is contained in:
Vendored
-1
@@ -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",
|
||||
|
||||
Vendored
-1
@@ -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;
|
||||
|
||||
+4
-2
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
+1
-2
@@ -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 {};
|
||||
|
||||
+2
-2
@@ -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) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export default function checkArrayDepth(arr: any[] | any[][] | any[][][] | any, depth: number): boolean;
|
||||
@@ -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));
|
||||
}
|
||||
+4
-2
@@ -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 {};
|
||||
|
||||
+21
-5
@@ -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;
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* # Grab Names For Query
|
||||
*/
|
||||
export default function grabSQLNames(): {};
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabSQLNames;
|
||||
/**
|
||||
* # Grab Names For Query
|
||||
*/
|
||||
function grabSQLNames() {
|
||||
return {};
|
||||
}
|
||||
Reference in New Issue
Block a user