This commit is contained in:
Benjamin Toby
2025-07-09 20:30:45 +01:00
parent ccb5605b58
commit c37d105dee
264 changed files with 2389 additions and 3743 deletions
+7 -8
View File
@@ -1,17 +1,16 @@
import { ApiGetQueryObject, GetReturn } from "../types";
import { APIResponseObject, DsqlCrudQueryObject } from "../types";
type Param<T extends {
[k: string]: any;
} = {
[k: string]: any;
}> = {
key?: string;
db?: string;
query: string | ApiGetQueryObject<T>;
queryValues?: string[];
tableName?: string;
user_id?: string | number;
database: string;
query: DsqlCrudQueryObject<T>;
table?: string;
debug?: boolean;
forceLocal?: boolean;
useLocal?: boolean;
apiVersion?: string;
};
export type ApiGetParams = Param;
/**
@@ -21,5 +20,5 @@ export default function get<T extends {
[k: string]: any;
} = {
[k: string]: any;
}, R extends any = any>({ key, db, query, queryValues, tableName, user_id, debug, forceLocal, }: Param<T>): Promise<GetReturn<R>>;
}, R extends any = any>({ key, database, query, table, debug, useLocal, apiVersion, }: Param<T>): Promise<APIResponseObject<R>>;
export {};
+13 -43
View File
@@ -13,18 +13,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = get;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
const get_1 = __importDefault(require("../functions/api/query/get"));
const serialize_query_1 = __importDefault(require("../utils/serialize-query"));
const grab_query_and_values_1 = __importDefault(require("../utils/grab-query-and-values"));
const debug_log_1 = __importDefault(require("../utils/logging/debug-log"));
const crud_1 = __importDefault(require("../utils/data-fetching/crud"));
const grab_api_key_1 = __importDefault(require("../utils/grab-api-key"));
/**
* # Make a get request to Datasquirel API
*/
function get(_a) {
return __awaiter(this, arguments, void 0, function* ({ key, db, query, queryValues, tableName, user_id, debug, forceLocal, }) {
return __awaiter(this, arguments, void 0, function* ({ key, database, query, table, debug, useLocal, apiVersion = "v1", }) {
const grabedHostNames = (0, grab_host_names_1.default)();
const { host, port, scheme } = grabedHostNames;
function debugFn(log, label) {
@@ -36,25 +34,14 @@ 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 ((DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) && global.DSQL_USE_LOCAL) {
let dbSchema;
try {
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
}
catch (error) { }
if (debug) {
debugFn("Running Locally ...");
}
return yield (0, get_1.default)({
dbFullName: DSQL_DB_NAME,
if (useLocal) {
const result = yield (0, crud_1.default)({
action: "get",
table: table || "",
dbFullName: database,
query,
queryValues,
tableName,
dbSchema,
debug,
forceLocal,
});
return result;
}
/**
* Make https request
@@ -62,25 +49,11 @@ function get(_a) {
* @description make a request to datasquirel.com
*/
const httpResponse = yield new Promise((resolve, reject) => {
const queryAndValues = (0, grab_query_and_values_1.default)({
query,
values: queryValues,
});
const queryObject = {
db: process.env.DSQL_API_DB_NAME || String(db),
query: queryAndValues.query,
queryValues: queryAndValues.valuesString,
tableName,
debug,
};
if (debug) {
debugFn(queryObject, "queryObject");
}
const queryString = (0, serialize_query_1.default)(Object.assign({}, queryObject));
const queryString = (0, serialize_query_1.default)(query);
if (debug) {
debugFn(queryString, "queryString");
}
let path = `/api/query/${user_id || grabedHostNames.user_id}/get${queryString}`;
let path = `/api/${apiVersion}/crud/${database}/${table}`;
if (debug) {
debugFn(path, "path");
}
@@ -88,10 +61,7 @@ function get(_a) {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: key ||
process.env.DSQL_READ_ONLY_API_KEY ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
Authorization: (0, grab_api_key_1.default)(key),
},
port,
hostname: host,
@@ -113,7 +83,7 @@ function get(_a) {
try {
resolve(JSON.parse(str));
}
catch ( /** @type {any} */error) {
catch (error) {
reject({
error: error.message,
result: str,
+2 -2
View File
@@ -6,11 +6,11 @@ type Param = {
queryValues?: any[];
tableName?: string;
user_id?: boolean;
forceLocal?: boolean;
useLocal?: boolean;
debug?: boolean;
};
/**
* # Make a post request to Datasquirel API
*/
export default function post({ key, query, queryValues, database, tableName, user_id, forceLocal, debug, }: Param): Promise<PostReturn>;
export default function post({ key, query, queryValues, database, tableName, user_id, useLocal, debug, }: Param): Promise<PostReturn>;
export {};
+4 -20
View File
@@ -14,8 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = post;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
const post_1 = __importDefault(require("../functions/api/query/post"));
const debug_log_1 = __importDefault(require("../utils/logging/debug-log"));
@@ -23,7 +21,7 @@ const debug_log_1 = __importDefault(require("../utils/logging/debug-log"));
* # Make a post request to Datasquirel API
*/
function post(_a) {
return __awaiter(this, arguments, void 0, function* ({ key, query, queryValues, database, tableName, user_id, forceLocal, debug, }) {
return __awaiter(this, arguments, void 0, function* ({ key, query, queryValues, database, tableName, user_id, useLocal, debug, }) {
const grabedHostNames = (0, grab_host_names_1.default)();
const { host, port, scheme } = grabedHostNames;
if (debug) {
@@ -39,18 +37,7 @@ 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 ((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(/./)) &&
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
global.DSQL_USE_LOCAL) {
/** @type {import("../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema;
try {
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
}
catch (error) { }
if (useLocal) {
if (debug) {
(0, debug_log_1.default)({
log: "Using Local DB ...",
@@ -58,12 +45,10 @@ function post(_a) {
});
}
return yield (0, post_1.default)({
dbFullName: database || DSQL_DB_NAME,
dbFullName: database || "",
query,
dbSchema,
queryValues,
tableName,
forceLocal,
debug,
});
}
@@ -73,7 +58,6 @@ function post(_a) {
* @description make a request to datasquirel.com
*/
const httpResponse = yield new Promise((resolve, reject) => {
var _a;
const reqPayloadString = JSON.stringify({
query,
queryValues,
@@ -84,7 +68,7 @@ function post(_a) {
JSON.parse(reqPayloadString);
}
catch (error) {
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `Error Parsing HTTP response for post action`, error);
console.log("Error Parsing HTTP response for post action: ", error.message);
return {
success: false,
payload: null,
-2
View File
@@ -19,7 +19,6 @@ const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
*/
function uploadImage(_a) {
return __awaiter(this, arguments, void 0, function* ({ key, payload, user_id, useDefault, }) {
var _b;
const grabedHostNames = (0, grab_host_names_1.default)({ useDefault });
const { host, port, scheme } = grabedHostNames;
try {
@@ -67,7 +66,6 @@ function uploadImage(_a) {
}
catch (error) {
console.log("Error in uploading file: ", error.message);
(_b = global.ERROR_CALLBACK) === null || _b === void 0 ? void 0 : _b.call(global, `Error Uploading File`, error);
return {
success: false,
payload: null,
-2
View File
@@ -19,7 +19,6 @@ const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
*/
function uploadImage(_a) {
return __awaiter(this, arguments, void 0, function* ({ key, payload, user_id, useDefault, }) {
var _b;
const grabedHostNames = (0, grab_host_names_1.default)({ useDefault });
const { host, port, scheme } = grabedHostNames;
try {
@@ -67,7 +66,6 @@ function uploadImage(_a) {
}
catch (error) {
console.log("Error in uploading image: ", error.message);
(_b = global.ERROR_CALLBACK) === null || _b === void 0 ? void 0 : _b.call(global, `Error Uploading Image`, error);
return {
success: false,
payload: null,
+4 -5
View File
@@ -1,15 +1,14 @@
import { AddUserFunctionReturn, UserDataPayload } from "../../types";
type Param = {
key?: string;
database?: string;
database: string;
payload: UserDataPayload;
encryptionKey?: string;
encryptionSalt?: string;
user_id?: string | number;
apiUserId?: string | number;
useLocal?: boolean;
verify?: boolean;
};
/**
* # Add User to Database
*/
export default function addUser({ key, payload, database, encryptionKey, user_id, apiUserId, }: Param): Promise<AddUserFunctionReturn>;
export default function addUser({ key, payload, database, encryptionKey, useLocal, verify, }: Param): Promise<AddUserFunctionReturn>;
export {};
+5 -24
View File
@@ -13,40 +13,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = addUser;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
const api_create_user_1 = __importDefault(require("../../functions/api/users/api-create-user"));
/**
* # Add User to Database
*/
function addUser(_a) {
return __awaiter(this, arguments, void 0, function* ({ key, payload, database, encryptionKey, user_id, apiUserId, }) {
/**
* Check for local DB settings
*
* @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_API_USER_ID, } = process.env;
return __awaiter(this, arguments, void 0, function* ({ key, payload, database, encryptionKey, useLocal, verify, }) {
const grabedHostNames = (0, grab_host_names_1.default)();
const { host, port, scheme } = grabedHostNames;
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(/./)) &&
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
global.DSQL_USE_LOCAL) {
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema;
try {
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
}
catch (error) { }
if (useLocal) {
return yield (0, api_create_user_1.default)({
database: DSQL_DB_NAME,
database,
encryptionKey,
payload,
userId: apiUserId,
verify,
});
}
/**
@@ -71,7 +52,7 @@ function addUser(_a) {
},
port,
hostname: host,
path: `/api/user/${user_id || grabedHostNames.user_id}/add-user`,
path: ``,
},
/**
* Callback Function
+4 -3
View File
@@ -1,12 +1,13 @@
import { UpdateUserFunctionReturn } from "../../types";
type Param = {
key?: string;
database?: string;
database: string;
deletedUserId: string | number;
user_id?: boolean;
useLocal?: boolean;
apiVersion?: string;
};
/**
* # Update User
*/
export default function deleteUser({ key, database, user_id, deletedUserId, }: Param): Promise<UpdateUserFunctionReturn>;
export default function deleteUser({ key, database, deletedUserId, useLocal, apiVersion, }: Param): Promise<UpdateUserFunctionReturn>;
export {};
+4 -23
View File
@@ -13,37 +13,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = deleteUser;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
const api_delete_user_1 = __importDefault(require("../../functions/api/users/api-delete-user"));
/**
* # Update User
*/
function deleteUser(_a) {
return __awaiter(this, arguments, void 0, function* ({ key, database, user_id, deletedUserId, }) {
/**
* Check for local DB settings
*
* @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;
return __awaiter(this, arguments, void 0, function* ({ key, database, deletedUserId, useLocal, apiVersion = "v1", }) {
const grabedHostNames = (0, grab_host_names_1.default)();
const { host, port, scheme } = grabedHostNames;
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(/./)) &&
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
global.DSQL_USE_LOCAL) {
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema;
try {
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
}
catch (error) { }
if (useLocal) {
return yield (0, api_delete_user_1.default)({
dbFullName: DSQL_DB_NAME,
dbFullName: database,
deletedUserId,
});
}
@@ -68,7 +49,7 @@ function deleteUser(_a) {
},
port,
hostname: host,
path: `/api/user/${user_id || grabedHostNames.user_id}/delete-user`,
path: `/api/${apiVersion}/users/${database}/${deletedUserId}`,
},
/**
* Callback Function
+1 -2
View File
@@ -14,7 +14,6 @@ const parseCookies_1 = __importDefault(require("../../utils/backend/parseCookies
* string and csrf token string
*/
function getToken({ request, encryptionKey, encryptionSalt, cookieString, }) {
var _a;
try {
/**
* Grab the payload
@@ -62,7 +61,7 @@ function getToken({ request, encryptionKey, encryptionSalt, cookieString, }) {
return { key, csrf };
}
catch (error) {
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `Error Getting Token`, error);
console.log("Error Getting Token:", error.message);
/**
* Return User Object
*
+3 -2
View File
@@ -4,10 +4,11 @@ type Param = {
database: string;
userId: number;
fields?: string[];
apiUserId?: boolean;
useLocal?: boolean;
apiVersion?: string;
};
/**
* # Get User
*/
export default function getUser({ key, userId, database, fields, apiUserId, }: Param): Promise<GetUserFunctionReturn>;
export default function getUser({ key, userId, database, fields, useLocal, apiVersion, }: Param): Promise<GetUserFunctionReturn>;
export {};
+4 -26
View File
@@ -13,15 +13,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = getUser;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
const api_get_user_1 = __importDefault(require("../../functions/api/users/api-get-user"));
/**
* # Get User
*/
function getUser(_a) {
return __awaiter(this, arguments, void 0, function* ({ key, userId, database, fields, apiUserId, }) {
return __awaiter(this, arguments, void 0, function* ({ key, userId, database, fields, useLocal, apiVersion = "v1", }) {
/**
* Initialize
*/
@@ -49,28 +47,11 @@ function getUser(_a) {
});
const grabedHostNames = (0, grab_host_names_1.default)();
const { host, port, scheme } = grabedHostNames;
/**
* Check for local DB settings
*
* @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 ((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(/./)) &&
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
global.DSQL_USE_LOCAL) {
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema;
try {
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
}
catch (error) { }
if (useLocal) {
return yield (0, api_get_user_1.default)({
userId,
fields: [...new Set(updatedFields)],
dbFullName: DSQL_DB_NAME,
dbFullName: database,
});
}
/**
@@ -90,7 +71,7 @@ function getUser(_a) {
},
port,
hostname: host,
path: `/api/user/${apiUserId || grabedHostNames.user_id}/get-user`,
path: `/api/${apiVersion}/users/${database}/${userId}`,
},
/**
* Callback Function
@@ -112,9 +93,6 @@ function getUser(_a) {
httpsRequest.write(reqPayload);
httpsRequest.end();
});
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
return httpResponse;
});
}
+5 -5
View File
@@ -25,7 +25,7 @@ const grab_cookie_expirt_date_1 = __importDefault(require("../../utils/grab-cook
*/
function loginUser(_a) {
return __awaiter(this, arguments, void 0, function* ({ key, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, user_id, skipPassword, apiUserID, skipWriteAuthFile, dbUserId, debug, cleanupTokens, secureCookie, request, useLocal, }) {
var _b, _c, _d;
var _b, _c;
const grabedHostNames = (0, grab_host_names_1.default)({ userId: user_id || apiUserID });
const { host, port, scheme } = grabedHostNames;
const COOKIE_EXPIRY_DATE = (0, grab_cookie_expirt_date_1.default)();
@@ -82,7 +82,7 @@ function loginUser(_a) {
*/
if (useLocal) {
httpResponse = yield (0, api_login_1.default)({
database: database || process.env.DSQL_DB_NAME || "",
database,
email: payload.email,
username: payload.username,
password: payload.password,
@@ -154,14 +154,14 @@ function loginUser(_a) {
httpResponse["token"] = encryptedPayload;
}
catch (error) {
(_b = global.ERROR_CALLBACK) === null || _b === void 0 ? void 0 : _b.call(global, `Login User HTTP Response Error`, error);
console.log("Login User HTTP Response Error:", error.message);
}
const cookieNames = (0, get_auth_cookie_names_1.default)({
database,
userId: grabedHostNames.user_id,
});
if (httpResponse.csrf && !skipWriteAuthFile) {
(0, write_auth_files_1.writeAuthFile)(httpResponse.csrf, JSON.stringify(httpResponse.payload), cleanupTokens && ((_c = httpResponse.payload) === null || _c === void 0 ? void 0 : _c.id)
(0, write_auth_files_1.writeAuthFile)(httpResponse.csrf, JSON.stringify(httpResponse.payload), cleanupTokens && ((_b = httpResponse.payload) === null || _b === void 0 ? void 0 : _b.id)
? { userId: httpResponse.payload.id }
: undefined);
}
@@ -176,7 +176,7 @@ function loginUser(_a) {
}
response === null || response === void 0 ? void 0 : response.setHeader("Set-Cookie", [
`${authKeyName}=${encryptedPayload};samesite=strict;path=/;HttpOnly=true;Expires=${COOKIE_EXPIRY_DATE}${secureCookie ? ";Secure=true" : ""}`,
`${csrfName}=${(_d = httpResponse.payload) === null || _d === void 0 ? void 0 : _d.csrf_k};samesite=strict;path=/;HttpOnly=true;Expires=${COOKIE_EXPIRY_DATE}`,
`${csrfName}=${(_c = httpResponse.payload) === null || _c === void 0 ? void 0 : _c.csrf_k};samesite=strict;path=/;HttpOnly=true;Expires=${COOKIE_EXPIRY_DATE}`,
]);
if (debug) {
debugFn("Response Sent!");
-2
View File
@@ -15,7 +15,6 @@ const debug_log_1 = __importDefault(require("../../utils/logging/debug-log"));
* # Logout user
*/
function logoutUser({ response, database, dsqlUserId, encryptedUserString, request, cookieString, debug, }) {
var _a;
/**
* Check Encryption Keys
*
@@ -84,7 +83,6 @@ function logoutUser({ response, database, dsqlUserId, encryptedUserString, reque
}
catch (error) {
console.log("Logout Error:", error.message);
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `Logout User Error`, error);
return {
success: false,
msg: "Logout Failed",
+1 -2
View File
@@ -125,12 +125,11 @@ function githubAuth(_a) {
str += chunk;
});
response.on("end", function () {
var _a;
try {
resolve(JSON.parse(str));
}
catch (error) {
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `Github Auth Error`, error);
console.log("Github Auth Error:", error.message);
resolve({
success: false,
user: null,
+3 -2
View File
@@ -1,15 +1,16 @@
import { UpdateUserFunctionReturn } from "../../types";
type Param = {
key?: string;
database?: string;
database: string;
updatedUserId: string | number;
payload: {
[s: string]: any;
};
user_id?: boolean;
useLocal?: boolean;
};
/**
* # Update User
*/
export default function updateUser({ key, payload, database, user_id, updatedUserId, }: Param): Promise<UpdateUserFunctionReturn>;
export default function updateUser({ key, payload, database, user_id, updatedUserId, useLocal, }: Param): Promise<UpdateUserFunctionReturn>;
export {};
+3 -23
View File
@@ -13,40 +13,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = updateUser;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
const api_update_user_1 = __importDefault(require("../../functions/api/users/api-update-user"));
/**
* # Update User
*/
function updateUser(_a) {
return __awaiter(this, arguments, void 0, function* ({ key, payload, database, user_id, updatedUserId, }) {
/**
* Check for local DB settings
*
* @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;
return __awaiter(this, arguments, void 0, function* ({ key, payload, database, user_id, updatedUserId, useLocal, }) {
const grabedHostNames = (0, grab_host_names_1.default)();
const { host, port, scheme } = grabedHostNames;
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(/./)) &&
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
global.DSQL_USE_LOCAL) {
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema;
try {
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
}
catch (error) { }
if (useLocal) {
return yield (0, api_update_user_1.default)({
payload: payload,
dbFullName: DSQL_DB_NAME,
dbFullName: database,
updatedUserId,
dbSchema,
});
}
/**
-2
View File
@@ -24,7 +24,6 @@ const yearInMilliseconds = dayInMilliseconds * 365;
* with the user's data
*/
function userAuth({ request, req, encryptionKey, encryptionSalt, level, database, dsqlUserId, encryptedUserString, expiry = weekInMilliseconds, cookieString, csrfHeaderName, debug, skipFileCheck, }) {
var _a;
try {
const finalRequest = req || request;
const { user_id } = (0, grab_host_names_1.default)({ userId: dsqlUserId });
@@ -163,7 +162,6 @@ function userAuth({ request, req, encryptionKey, encryptionSalt, level, database
};
}
catch (error) {
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `User Auth Error`, error);
/**
* Return User Object
*
@@ -22,7 +22,6 @@ const ejson_1 = __importDefault(require("../../utils/ejson"));
*/
function validateTempEmailCode(_a) {
return __awaiter(this, arguments, void 0, function* ({ request, email, cookieString, }) {
var _b;
try {
const keyNames = (0, get_auth_cookie_names_1.default)();
const oneTimeCodeCookieName = keyNames.oneTimeCodeName;
@@ -41,7 +40,6 @@ function validateTempEmailCode(_a) {
return null;
}
catch (error) {
(_b = global.ERROR_CALLBACK) === null || _b === void 0 ? void 0 : _b.call(global, `Validate Temp Email Code Error`, error);
console.log("validateTempEmailCode error:", error.message);
return null;
}
-2
View File
@@ -11,7 +11,6 @@ const decrypt_1 = __importDefault(require("../../functions/dsql/decrypt"));
* @description This Function takes in a encrypted token and returns a user object
*/
function validateToken({ token, encryptionKey, encryptionSalt, }) {
var _a;
try {
/**
* Grab the payload
@@ -54,7 +53,6 @@ function validateToken({ token, encryptionKey, encryptionSalt, }) {
return userObject;
}
catch (error) {
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `Validate Token Error`, error);
/**
* Return User Object
*