This commit is contained in:
Benjamin Toby 2024-12-17 18:39:50 +01:00
parent 4b8e8de71f
commit a2ba913340
5 changed files with 16 additions and 10 deletions

View File

@ -4,7 +4,7 @@ const fs = require("fs");
const decrypt = require("../dsql/decrypt");
/** @type {import("../../types").CheckApiCredentialsFn} */
const grabApiCred = ({ key, database, table, user_id }) => {
const grabApiCred = ({ key, database, table, user_id, media }) => {
if (!key) return null;
if (!user_id) return null;
@ -27,6 +27,8 @@ const grabApiCred = ({ key, database, table, user_id }) => {
if (!isApiKeyValid) return null;
if (!ApiObject.target_database) return ApiObject;
if (media) return ApiObject;
if (!database && ApiObject.target_database) return null;
const isDatabaseAllowed = ApiObject.target_database
?.split(",")
@ -41,7 +43,7 @@ const grabApiCred = ({ key, database, table, user_id }) => {
return null;
} catch (/** @type {any} */ error) {
console.log(`api-cred ERROR: ${error.message}`);
return null;
return { error: `api-cred ERROR: ${error.message}` };
}
};

View File

@ -172,7 +172,7 @@ function sqlGenerator({ tableName, genObject }) {
return str;
})();
if (sqlSearhString) {
if (sqlSearhString?.[0] && sqlSearhString.find((str) => str)) {
const stringOperator = genObject?.searchOperator || "AND";
queryString += ` WHERE ${sqlSearhString.join(` ${stringOperator} `)} `;
}

View File

@ -864,12 +864,13 @@ export interface MYSQL_delegated_user_tables_table_def {
date_updated_timestamp?: string;
}
export type ApiKeyObject = {
user_id: string | number;
user_id?: string | number;
full_access?: boolean;
sign: string;
date_code: number;
sign?: string;
date_code?: number;
target_database?: string;
target_table?: string;
error?: string;
};
export type AddApiKeyRequestBody = {
api_key_name: string;
@ -884,6 +885,7 @@ export type CheckApiCredentialsFnParam = {
database?: string;
table?: string;
user_id?: string | number;
media?: boolean;
};
export type FetchApiFn = (url: string, options?: FetchApiOptions, csrf?: boolean) => Promise<any>;
export type FetchApiOptions = RequestInit & {

View File

@ -1020,12 +1020,13 @@ export interface MYSQL_delegated_user_tables_table_def {
}
export type ApiKeyObject = {
user_id: string | number;
user_id?: string | number;
full_access?: boolean;
sign: string;
date_code: number;
sign?: string;
date_code?: number;
target_database?: string;
target_table?: string;
error?: string;
};
export type AddApiKeyRequestBody = {
@ -1044,6 +1045,7 @@ export type CheckApiCredentialsFnParam = {
database?: string;
table?: string;
user_id?: string | number;
media?: boolean;
};
export type FetchApiFn = (

View File

@ -1,6 +1,6 @@
{
"name": "@moduletrace/datasquirel",
"version": "3.1.6",
"version": "3.1.7",
"description": "Cloud-based SQL data management tool",
"main": "index.js",
"bin": {