This commit is contained in:
Benjamin Toby
2025-02-12 17:56:44 +01:00
parent a5c3d59d24
commit 1b48c07ee8
431 changed files with 1665 additions and 827 deletions
+5 -10
View File
@@ -9,7 +9,6 @@ import {
DSQL_DatabaseSchemaType,
GetReqQueryObject,
GetReturn,
ServerQueryParam,
} from "../types";
import apiGetGrabQueryAndValues from "../utils/grab-query-and-values";
@@ -21,6 +20,7 @@ type Param<T extends { [k: string]: any } = { [k: string]: any }> = {
tableName?: string;
user_id?: string | number;
debug?: boolean;
forceLocal?: boolean;
};
export type ApiGetParams = Param;
@@ -38,6 +38,7 @@ export default async function get<
tableName,
user_id,
debug,
forceLocal,
}: Param<T>): Promise<GetReturn> {
const grabedHostNames = grabHostNames();
const { host, port, scheme } = grabedHostNames;
@@ -47,16 +48,9 @@ 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_HOST, DSQL_DB_USERNAME, DSQL_DB_PASSWORD, DSQL_DB_NAME } =
process.env;
const { DSQL_DB_NAME } = process.env;
if (
DSQL_DB_HOST?.match(/./) &&
DSQL_DB_USERNAME?.match(/./) &&
DSQL_DB_PASSWORD?.match(/./) &&
DSQL_DB_NAME?.match(/./) &&
global.DSQL_USE_LOCAL
) {
if (DSQL_DB_NAME?.match(/./) && global.DSQL_USE_LOCAL) {
let dbSchema: DSQL_DatabaseSchemaType | undefined;
try {
@@ -78,6 +72,7 @@ export default async function get<
tableName,
dbSchema,
debug,
forceLocal,
});
}
+3
View File
@@ -13,6 +13,7 @@ type Param = {
queryValues?: any[];
tableName?: string;
user_id?: boolean;
forceLocal?: boolean;
};
/**
@@ -25,6 +26,7 @@ export default async function post({
database,
tableName,
user_id,
forceLocal,
}: Param): Promise<PostReturn> {
const grabedHostNames = grabHostNames();
const { host, port, scheme } = grabedHostNames;
@@ -61,6 +63,7 @@ export default async function post({
dbSchema,
queryValues,
tableName,
forceLocal,
});
}
@@ -34,8 +34,10 @@ export default async function googleAuth({
apiUserID,
debug,
}: Param): Promise<APILoginFunctionReturn> {
const grabedHostNames = grabHostNames();
const { host, port, scheme } = grabedHostNames;
const grabedHostNames = grabHostNames({
userId: apiUserID || process.env.DSQL_API_USER_ID,
});
const { host, port, scheme, user_id } = grabedHostNames;
const finalEncryptionKey =
encryptionKey || process.env.DSQL_ENCRYPTION_PASSWORD;
@@ -107,12 +109,6 @@ export default async function googleAuth({
debug,
});
} else {
/**
* Make https request
*
* @description make a request to datasquirel.com
* @type {{ success: boolean, user: import("../../../types").DATASQUIREL_LoggedInUser | null, msg?: string, dsqlUserId?: number } | null } - Https response object
*/
httpResponse = await new Promise((resolve, reject) => {
const reqPayload = JSON.stringify({
token,
@@ -179,7 +175,7 @@ export default async function googleAuth({
const cookieNames = getAuthCookieNames({
database,
userId: apiUserID || process.env.DSQL_API_USER_ID,
userId: user_id,
});
if (httpResponse.csrf) {
@@ -105,6 +105,7 @@ export default function userAuth({
success: false,
payload: null,
msg: "Couldn't Decrypt cookie",
cookieNames: keyNames,
};
}
@@ -127,6 +128,7 @@ export default function userAuth({
success: false,
payload: null,
msg: "No CSRF_K in decrypted payload",
cookieNames: keyNames,
};
}
@@ -135,6 +137,7 @@ export default function userAuth({
success: false,
payload: null,
msg: "Auth file doesn't exist",
cookieNames: keyNames,
};
}
@@ -152,6 +155,7 @@ export default function userAuth({
success: false,
payload: null,
msg: "CSRF_K mismatch",
cookieNames: keyNames,
};
}
}
@@ -166,6 +170,7 @@ export default function userAuth({
success: false,
payload: null,
msg: "Payload Creation Date is not a number",
cookieNames: keyNames,
};
}
@@ -180,6 +185,7 @@ export default function userAuth({
success: false,
payload: null,
msg: "Session has expired",
cookieNames: keyNames,
};
}