Updates
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
export = addDbEntry;
|
||||
/**
|
||||
* Add a db Entry Function
|
||||
* ==============================================================================
|
||||
* @description Description
|
||||
* @async
|
||||
*
|
||||
* @param {object} params - An object containing the function parameters.
|
||||
* @param {("Master" | "Dsql User")} [params.dbContext] - What is the database context? "Master"
|
||||
* or "Dsql User". Defaults to "Master"
|
||||
* @param {("Read Only" | "Full Access")} [params.paradigm] - What is the paradigm for "Dsql User"?
|
||||
* "Read only" or "Full Access"? Defaults to "Read Only"
|
||||
* @param {string} [params.dbFullName] - Database full name
|
||||
* @param {string} params.tableName - Table name
|
||||
* @param {any} params.data - Data to add
|
||||
* @param {import("../../../types").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
||||
* @param {string} [params.duplicateColumnName] - Duplicate column name
|
||||
* @param {string} [params.duplicateColumnValue] - Duplicate column value
|
||||
* @param {boolean} [params.update] - Update this row if it exists
|
||||
* @param {string} [params.encryptionKey] - Update this row if it exists
|
||||
* @param {string} [params.encryptionSalt] - Update this row if it exists
|
||||
*
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
declare function addDbEntry({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt, }: {
|
||||
dbContext?: ("Master" | "Dsql User");
|
||||
paradigm?: ("Read Only" | "Full Access");
|
||||
dbFullName?: string;
|
||||
tableName: string;
|
||||
data: any;
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
duplicateColumnName?: string;
|
||||
duplicateColumnValue?: string;
|
||||
update?: boolean;
|
||||
encryptionKey?: string;
|
||||
encryptionSalt?: string;
|
||||
}): Promise<any>;
|
||||
@@ -0,0 +1,32 @@
|
||||
export = deleteDbEntry;
|
||||
/**
|
||||
* Imports: Handle imports
|
||||
*/
|
||||
/**
|
||||
* Delete DB Entry Function
|
||||
* ==============================================================================
|
||||
* @description Description
|
||||
* @async
|
||||
*
|
||||
* @param {object} params - An object containing the function parameters.
|
||||
* @param {string} [params.dbContext] - What is the database context? "Master"
|
||||
* or "Dsql User". Defaults to "Master"
|
||||
* @param {("Read Only" | "Full Access")} [params.paradigm] - What is the paradigm for "Dsql User"?
|
||||
* "Read only" or "Full Access"? Defaults to "Read Only"
|
||||
* @param {string} params.dbFullName - Database full name
|
||||
* @param {string} params.tableName - Table name
|
||||
* @param {import("../../../types").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
||||
* @param {string} params.identifierColumnName - Update row identifier column name
|
||||
* @param {string|number} params.identifierValue - Update row identifier column value
|
||||
*
|
||||
* @returns {Promise<object|null>}
|
||||
*/
|
||||
declare function deleteDbEntry({ dbContext, paradigm, dbFullName, tableName, identifierColumnName, identifierValue, }: {
|
||||
dbContext?: string;
|
||||
paradigm?: ("Read Only" | "Full Access");
|
||||
dbFullName: string;
|
||||
tableName: string;
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
identifierColumnName: string;
|
||||
identifierValue: string | number;
|
||||
}): Promise<object | null>;
|
||||
@@ -0,0 +1,30 @@
|
||||
export = runQuery;
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/**
|
||||
* Run DSQL users queries
|
||||
* ==============================================================================
|
||||
* @param {object} params - An object containing the function parameters.
|
||||
* @param {string} params.dbFullName - Database full name. Eg. "datasquire_user_2_test"
|
||||
* @param {string | any} params.query - Query string or object
|
||||
* @param {boolean} [params.readOnly] - Is this operation read only?
|
||||
* @param {boolean} [params.local] - Is this operation read only?
|
||||
* @param {import("../../../types").DSQL_DatabaseSchemaType} [params.dbSchema] - Database schema
|
||||
* @param {string[]} [params.queryValuesArray] - An optional array of query values if "?" is used in the query string
|
||||
* @param {string} [params.tableName] - Table Name
|
||||
*
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
declare function runQuery({ dbFullName, query, readOnly, dbSchema, queryValuesArray, tableName, local, }: {
|
||||
dbFullName: string;
|
||||
query: string | any;
|
||||
readOnly?: boolean;
|
||||
local?: boolean;
|
||||
dbSchema?: import("../../../types").DSQL_DatabaseSchemaType;
|
||||
queryValuesArray?: string[];
|
||||
tableName?: string;
|
||||
}): Promise<any>;
|
||||
@@ -0,0 +1,35 @@
|
||||
export = updateDbEntry;
|
||||
/**
|
||||
* Update DB Function
|
||||
* ==============================================================================
|
||||
* @description Description
|
||||
* @async
|
||||
*
|
||||
* @param {object} params - An object containing the function parameters.
|
||||
* @param {("Master" | "Dsql User")} [params.dbContext] - What is the database context? "Master"
|
||||
* or "Dsql User". Defaults to "Master"
|
||||
* @param {("Read Only" | "Full Access")} [params.paradigm] - What is the paradigm for "Dsql User"?
|
||||
* "Read only" or "Full Access"? Defaults to "Read Only"
|
||||
* @param {string} [params.dbFullName] - Database full name
|
||||
* @param {string} params.tableName - Table name
|
||||
* @param {string} [params.encryptionKey]
|
||||
* @param {string} [params.encryptionSalt]
|
||||
* @param {any} params.data - Data to add
|
||||
* @param {import("../../../types").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
||||
* @param {string} params.identifierColumnName - Update row identifier column name
|
||||
* @param {string | number} params.identifierValue - Update row identifier column value
|
||||
*
|
||||
* @returns {Promise<object|null>}
|
||||
*/
|
||||
declare function updateDbEntry({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt, }: {
|
||||
dbContext?: ("Master" | "Dsql User");
|
||||
paradigm?: ("Read Only" | "Full Access");
|
||||
dbFullName?: string;
|
||||
tableName: string;
|
||||
encryptionKey?: string;
|
||||
encryptionSalt?: string;
|
||||
data: any;
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
identifierColumnName: string;
|
||||
identifierValue: string | number;
|
||||
}): Promise<object | null>;
|
||||
@@ -0,0 +1,6 @@
|
||||
export = decrypt;
|
||||
/**
|
||||
* @param {string} encryptedString
|
||||
* @returns {string | null}
|
||||
*/
|
||||
declare function decrypt(encryptedString: string): string | null;
|
||||
@@ -0,0 +1,7 @@
|
||||
export = defaultFieldsRegexp;
|
||||
/**
|
||||
* Regular expression to match default fields
|
||||
*
|
||||
* @description Regular expression to match default fields
|
||||
*/
|
||||
declare const defaultFieldsRegexp: RegExp;
|
||||
@@ -0,0 +1,9 @@
|
||||
export = encrypt;
|
||||
/**
|
||||
* @async
|
||||
* @param {string} data
|
||||
* @param {string} [encryptionKey]
|
||||
* @param {string} [encryptionSalt]
|
||||
* @returns {string | null}
|
||||
*/
|
||||
declare function encrypt(data: string, encryptionKey?: string, encryptionSalt?: string): string | null;
|
||||
@@ -0,0 +1,8 @@
|
||||
declare function _exports({ queryString, database, tableSchema, queryValuesArray, local, }: {
|
||||
queryString: string;
|
||||
database: string;
|
||||
local?: boolean;
|
||||
tableSchema?: import("../../types").DSQL_TableSchemaType | null;
|
||||
queryValuesArray?: string[];
|
||||
}): Promise<any>;
|
||||
export = _exports;
|
||||
@@ -0,0 +1,6 @@
|
||||
export let allowedTags: string[];
|
||||
export let allowedAttributes: {
|
||||
a: string[];
|
||||
img: string[];
|
||||
"*": string[];
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
declare function _exports({ unparsedResults, tableSchema, }: {
|
||||
unparsedResults: any[];
|
||||
tableSchema?: import("../../types").DSQL_TableSchemaType;
|
||||
}): Promise<object[] | null>;
|
||||
export = _exports;
|
||||
@@ -0,0 +1,12 @@
|
||||
declare function _exports({ user, message, component, noMail, }: {
|
||||
user?: {
|
||||
id?: number | string;
|
||||
first_name?: string;
|
||||
last_name?: string;
|
||||
email?: string;
|
||||
} & any;
|
||||
message: string;
|
||||
component?: string;
|
||||
noMail?: boolean;
|
||||
}): Promise<void>;
|
||||
export = _exports;
|
||||
@@ -0,0 +1,7 @@
|
||||
declare function _exports({ queryString, database, queryValuesArray, tableSchema, }: {
|
||||
queryString: string;
|
||||
database: string;
|
||||
queryValuesArray?: string[];
|
||||
tableSchema?: import("../../types").DSQL_TableSchemaType;
|
||||
}): Promise<any>;
|
||||
export = _exports;
|
||||
+123
-3
@@ -1,4 +1,4 @@
|
||||
import http from "http";
|
||||
import type { IncomingMessage, ServerResponse } from "http";
|
||||
|
||||
import { Editor } from "tinymce";
|
||||
export type DSQL_DatabaseFullName = string;
|
||||
@@ -186,9 +186,9 @@ export interface PackageUserLoginLocalBody {
|
||||
dbSchema?: DSQL_DatabaseSchemaType;
|
||||
}
|
||||
|
||||
type Request = http.IncomingMessage;
|
||||
type Request = IncomingMessage;
|
||||
|
||||
type Response = http.ServerResponse;
|
||||
type Response = ServerResponse;
|
||||
|
||||
type ImageInputFileToBase64FunctionReturn = {
|
||||
imageBase64: string;
|
||||
@@ -1096,3 +1096,123 @@ export type CheckApiCredentialsFnParam = {
|
||||
database?: string;
|
||||
table?: string;
|
||||
};
|
||||
|
||||
export type FetchApiFn = (
|
||||
url: string,
|
||||
options?: FetchApiOptions,
|
||||
contentType?: "json" | "text" | "html" | "blob" | "file"
|
||||
) => Promise<any>;
|
||||
|
||||
export type FetchApiOptions = RequestInit & {
|
||||
method:
|
||||
| "POST"
|
||||
| "GET"
|
||||
| "DELETE"
|
||||
| "PUT"
|
||||
| "PATCH"
|
||||
| "post"
|
||||
| "get"
|
||||
| "delete"
|
||||
| "put"
|
||||
| "patch";
|
||||
body?: object | string;
|
||||
headers?: FetchHeader;
|
||||
query?: { [key: string]: any };
|
||||
};
|
||||
|
||||
export type AuthCsrfHeaderName = "x-csrf-auth";
|
||||
|
||||
type FetchHeader = HeadersInit & {
|
||||
[key in AuthCsrfHeaderName]?: string | null;
|
||||
} & {
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
export type FetchApiReturn = {
|
||||
success: boolean;
|
||||
payload: any;
|
||||
msg?: string;
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
export type ServerQueryParam = {
|
||||
selectFields?: string[];
|
||||
query?: ServerQueryQueryObject;
|
||||
limit?: number;
|
||||
order?: {
|
||||
field: string;
|
||||
strategy: "ASC" | "DESC";
|
||||
};
|
||||
searchOperator?: "AND" | "OR";
|
||||
searchEquality?: "EQUAL" | "LIKE";
|
||||
addUserId?: {
|
||||
fieldName: string;
|
||||
};
|
||||
join?: ServerQueryParamsJoin[];
|
||||
} & {
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
export type ServerQueryQueryObject<T extends object = { [key: string]: any }> =
|
||||
{
|
||||
[key in keyof T]: {
|
||||
value: string | string[];
|
||||
operator?: "AND" | "OR";
|
||||
equality?: "EQUAL" | "LIKE";
|
||||
tableName?: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type FetchDataParams = {
|
||||
path: string;
|
||||
method?: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
|
||||
body?: object | string;
|
||||
query?: AuthFetchQuery;
|
||||
tableName?: string;
|
||||
};
|
||||
|
||||
export type AuthFetchQuery = ServerQueryParam & {
|
||||
[key: string]: string | number | { [key: string]: any };
|
||||
};
|
||||
|
||||
export type ServerQueryParamsJoin<
|
||||
Table extends string = string,
|
||||
Field extends object = { [key: string]: any }
|
||||
> = {
|
||||
joinType: "INNER JOIN" | "JOIN" | "LEFT JOIN" | "RIGHT JOIN";
|
||||
tableName: Table;
|
||||
match?:
|
||||
| ServerQueryParamsJoinMatchObject<Field>
|
||||
| ServerQueryParamsJoinMatchObject<Field>[];
|
||||
selectFields?: (
|
||||
| keyof Field
|
||||
| {
|
||||
field: keyof Field;
|
||||
alias?: string;
|
||||
}
|
||||
)[];
|
||||
};
|
||||
|
||||
export type ServerQueryParamsJoinMatchObject<
|
||||
Field extends object = { [key: string]: any }
|
||||
> = {
|
||||
/** Field name from the **Root Table** */
|
||||
source: string | ServerQueryParamsJoinMatchSourceTargetObject;
|
||||
/** Field name from the **Join Table** */
|
||||
target: keyof Field | ServerQueryParamsJoinMatchSourceTargetObject;
|
||||
};
|
||||
|
||||
export type ServerQueryParamsJoinMatchSourceTargetObject = {
|
||||
tableName: string;
|
||||
fieldName: string;
|
||||
};
|
||||
|
||||
export type SqlGeneratorFn = (Param0: {
|
||||
genObject?: ServerQueryParam;
|
||||
tableName: string;
|
||||
}) =>
|
||||
| {
|
||||
string: string;
|
||||
values: string[];
|
||||
}
|
||||
| undefined;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export = DB_HANDLER;
|
||||
/**
|
||||
* DSQL user read-only DB handler
|
||||
* @param {object} params
|
||||
* @param {string} params.paradigm
|
||||
* @param {string} params.database
|
||||
* @param {string} params.queryString
|
||||
* @param {string[]} [params.queryValues]
|
||||
*/ declare function DB_HANDLER(...args: any[]): Promise<any>;
|
||||
@@ -0,0 +1,18 @@
|
||||
export = DSQL_USER_DB_HANDLER;
|
||||
/**
|
||||
* DSQL user read-only DB handler
|
||||
* @param {object} params
|
||||
* @param {"Full Access" | "FA" | "Read Only"} params.paradigm
|
||||
* @param {string} params.database
|
||||
* @param {string} params.queryString
|
||||
* @param {string[]} [params.queryValues]
|
||||
*/
|
||||
declare function DSQL_USER_DB_HANDLER({ paradigm, database, queryString, queryValues, }: {
|
||||
paradigm: "Full Access" | "FA" | "Read Only";
|
||||
database: string;
|
||||
queryString: string;
|
||||
queryValues?: string[];
|
||||
}): Promise<any> | {
|
||||
success: boolean;
|
||||
error: any;
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
declare function _exports(): string | (import("tls").SecureContextOptions & {
|
||||
rejectUnauthorized?: boolean | undefined;
|
||||
}) | undefined;
|
||||
export = _exports;
|
||||
@@ -7,12 +7,17 @@ const fs = require("fs");
|
||||
*/
|
||||
module.exports = function grabDbSSL() {
|
||||
const SSL_DIR = process.env.DSQL_SSL_DIR;
|
||||
if (!SSL_DIR?.match(/./)) return undefined;
|
||||
if (!SSL_DIR?.match(/./)) {
|
||||
// console.log(
|
||||
// "No SSL certificate provided. Query will run in normal mode. To add SSL add an env path dir `DSQL_SSL_DIR` with a file named `ca-cert.pem`"
|
||||
// );
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const caFilePath = `${SSL_DIR}/ca-cert.pem`;
|
||||
|
||||
if (!fs.existsSync(caFilePath)) {
|
||||
console.log(`${caFilePath} does not exist`);
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user