diff --git a/package-shared/functions/backend/api-cred.js b/package-shared/functions/backend/api-cred.js index 892968a..ceecb4f 100644 --- a/package-shared/functions/backend/api-cred.js +++ b/package-shared/functions/backend/api-cred.js @@ -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}` }; } }; diff --git a/package-shared/functions/dsql/sql/sql-generator.js b/package-shared/functions/dsql/sql/sql-generator.js index a7d9379..5eea1e7 100644 --- a/package-shared/functions/dsql/sql/sql-generator.js +++ b/package-shared/functions/dsql/sql/sql-generator.js @@ -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} `)} `; } diff --git a/package-shared/types/index.d.ts b/package-shared/types/index.d.ts index 7448c00..26a9571 100644 --- a/package-shared/types/index.d.ts +++ b/package-shared/types/index.d.ts @@ -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; export type FetchApiOptions = RequestInit & { diff --git a/package-shared/types/index.ts b/package-shared/types/index.ts index e04e8b5..facd5f6 100644 --- a/package-shared/types/index.ts +++ b/package-shared/types/index.ts @@ -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 = ( diff --git a/package.json b/package.json index 292425e..9b97942 100644 --- a/package.json +++ b/package.json @@ -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": {