Updates
This commit is contained in:
parent
1db9c3a2e7
commit
e82bcd0824
@ -1,5 +1,5 @@
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import getCsrfHeaderName from "../../utils/get-csrf-header-name";
|
import getCsrfHeaderName from "../../package-shared/actions/get-csrf-header-name";
|
||||||
|
|
||||||
type FetchApiOptions = {
|
type FetchApiOptions = {
|
||||||
method:
|
method:
|
||||||
|
2
dist/client/fetch/index.js
vendored
2
dist/client/fetch/index.js
vendored
@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = fetchApi;
|
exports.default = fetchApi;
|
||||||
const lodash_1 = __importDefault(require("lodash"));
|
const lodash_1 = __importDefault(require("lodash"));
|
||||||
const get_csrf_header_name_1 = __importDefault(require("../../utils/get-csrf-header-name"));
|
const get_csrf_header_name_1 = __importDefault(require("../../package-shared/actions/get-csrf-header-name"));
|
||||||
/**
|
/**
|
||||||
* # Fetch API
|
* # Fetch API
|
||||||
*/
|
*/
|
||||||
|
61
dist/index.d.ts
vendored
61
dist/index.d.ts
vendored
@ -5,27 +5,24 @@ declare global {
|
|||||||
var DSQL_FULL_ACCESS_DB_CONN: ServerlessMysql | undefined;
|
var DSQL_FULL_ACCESS_DB_CONN: ServerlessMysql | undefined;
|
||||||
var DSQL_USE_LOCAL: boolean | undefined;
|
var DSQL_USE_LOCAL: boolean | undefined;
|
||||||
}
|
}
|
||||||
/**
|
import get from "./package-shared/actions/get";
|
||||||
* Imports
|
import post from "./package-shared/actions/post";
|
||||||
*/
|
import getSchema from "./package-shared/actions/get-schema";
|
||||||
import get from "./utils/get";
|
import uploadImage from "./package-shared/actions/upload-image";
|
||||||
import post from "./utils/post";
|
import uploadFile from "./package-shared/actions/upload-file";
|
||||||
import getSchema from "./utils/get-schema";
|
import deleteFile from "./package-shared/actions/delete-file";
|
||||||
import uploadImage from "./utils/upload-image";
|
import createUser from "./package-shared/actions/users/add-user";
|
||||||
import uploadFile from "./utils/upload-file";
|
import updateUser from "./package-shared/actions/users/update-user";
|
||||||
import deleteFile from "./utils/delete-file";
|
import loginUser from "./package-shared/actions/users/login-user";
|
||||||
import createUser from "./users/add-user";
|
import sendEmailCode from "./package-shared/actions/users/send-email-code";
|
||||||
import updateUser from "./users/update-user";
|
import logoutUser from "./package-shared/actions/users/logout-user";
|
||||||
import loginUser from "./users/login-user";
|
import userAuth from "./package-shared/actions/users/user-auth";
|
||||||
import sendEmailCode from "./users/send-email-code";
|
import reAuthUser from "./package-shared/actions/users/reauth-user";
|
||||||
import logoutUser from "./users/logout-user";
|
import getUser from "./package-shared/actions/users/get-user";
|
||||||
import userAuth from "./users/user-auth";
|
import loginWithGoogle from "./package-shared/actions/users/social/google-auth";
|
||||||
import reAuthUser from "./users/reauth-user";
|
import loginWithGithub from "./package-shared/actions/users/social/github-auth";
|
||||||
import getUser from "./users/get-user";
|
import getToken from "./package-shared/actions/users/get-token";
|
||||||
import loginWithGoogle from "./users/social/google-auth";
|
import validateToken from "./package-shared/actions/users/validate-token";
|
||||||
import loginWithGithub from "./users/social/github-auth";
|
|
||||||
import getToken from "./users/get-token";
|
|
||||||
import validateToken from "./users/validate-token";
|
|
||||||
import sqlGenerator from "./package-shared/functions/dsql/sql/sql-generator";
|
import sqlGenerator from "./package-shared/functions/dsql/sql/sql-generator";
|
||||||
import sqlInsertGenerator from "./package-shared/functions/dsql/sql/sql-insert-generator";
|
import sqlInsertGenerator from "./package-shared/functions/dsql/sql/sql-insert-generator";
|
||||||
import sqlDeleteGenerator from "./package-shared/functions/dsql/sql/sql-delete-generator";
|
import sqlDeleteGenerator from "./package-shared/functions/dsql/sql/sql-delete-generator";
|
||||||
@ -36,13 +33,21 @@ import connDbHandler from "./package-shared/utils/db/conn-db-handler";
|
|||||||
import encrypt from "./package-shared/functions/dsql/encrypt";
|
import encrypt from "./package-shared/functions/dsql/encrypt";
|
||||||
import decrypt from "./package-shared/functions/dsql/decrypt";
|
import decrypt from "./package-shared/functions/dsql/decrypt";
|
||||||
import hashPassword from "./package-shared/functions/dsql/hashPassword";
|
import hashPassword from "./package-shared/functions/dsql/hashPassword";
|
||||||
import validateTempEmailCode from "./users/validate-temp-email-code";
|
import validateTempEmailCode from "./package-shared/actions/users/validate-temp-email-code";
|
||||||
import deleteUser from "./users/delete-user";
|
import deleteUser from "./package-shared/actions/users/delete-user";
|
||||||
|
import dsqlCrud from "./package-shared/utils/data-fetching/crud";
|
||||||
|
import dsqlMethodCrud from "./package-shared/utils/data-fetching/method-crud";
|
||||||
/**
|
/**
|
||||||
* Main Export
|
* Main Export
|
||||||
*/
|
*/
|
||||||
declare const datasquirel: {
|
declare const datasquirel: {
|
||||||
|
/**
|
||||||
|
* Get Action
|
||||||
|
*/
|
||||||
get: typeof get;
|
get: typeof get;
|
||||||
|
/**
|
||||||
|
* Post Action
|
||||||
|
*/
|
||||||
post: typeof post;
|
post: typeof post;
|
||||||
media: {
|
media: {
|
||||||
uploadImage: typeof uploadImage;
|
uploadImage: typeof uploadImage;
|
||||||
@ -119,5 +124,15 @@ declare const datasquirel: {
|
|||||||
httpRequest: typeof httpRequest;
|
httpRequest: typeof httpRequest;
|
||||||
connDbHandler: typeof connDbHandler;
|
connDbHandler: typeof connDbHandler;
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* Run Crud actions `get`, `insert`, `update`, `delete`
|
||||||
|
* @note *Requires global variables `DSQL_USE_LOCAL` and `DSQL_DB_CONN`
|
||||||
|
*/
|
||||||
|
crud: typeof dsqlCrud;
|
||||||
|
/**
|
||||||
|
* Run Crud based on request Methods `GET`, `POST`, `PUT`, `PATCH`
|
||||||
|
* @note *Requires global variables `DSQL_USE_LOCAL` and `DSQL_DB_CONN`
|
||||||
|
*/
|
||||||
|
methodCrud: typeof dsqlMethodCrud;
|
||||||
};
|
};
|
||||||
export default datasquirel;
|
export default datasquirel;
|
||||||
|
64
dist/index.js
vendored
64
dist/index.js
vendored
@ -3,27 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
/**
|
const get_1 = __importDefault(require("./package-shared/actions/get"));
|
||||||
* Imports
|
const post_1 = __importDefault(require("./package-shared/actions/post"));
|
||||||
*/
|
const get_schema_1 = __importDefault(require("./package-shared/actions/get-schema"));
|
||||||
const get_1 = __importDefault(require("./utils/get"));
|
const upload_image_1 = __importDefault(require("./package-shared/actions/upload-image"));
|
||||||
const post_1 = __importDefault(require("./utils/post"));
|
const upload_file_1 = __importDefault(require("./package-shared/actions/upload-file"));
|
||||||
const get_schema_1 = __importDefault(require("./utils/get-schema"));
|
const delete_file_1 = __importDefault(require("./package-shared/actions/delete-file"));
|
||||||
const upload_image_1 = __importDefault(require("./utils/upload-image"));
|
const add_user_1 = __importDefault(require("./package-shared/actions/users/add-user"));
|
||||||
const upload_file_1 = __importDefault(require("./utils/upload-file"));
|
const update_user_1 = __importDefault(require("./package-shared/actions/users/update-user"));
|
||||||
const delete_file_1 = __importDefault(require("./utils/delete-file"));
|
const login_user_1 = __importDefault(require("./package-shared/actions/users/login-user"));
|
||||||
const add_user_1 = __importDefault(require("./users/add-user"));
|
const send_email_code_1 = __importDefault(require("./package-shared/actions/users/send-email-code"));
|
||||||
const update_user_1 = __importDefault(require("./users/update-user"));
|
const logout_user_1 = __importDefault(require("./package-shared/actions/users/logout-user"));
|
||||||
const login_user_1 = __importDefault(require("./users/login-user"));
|
const user_auth_1 = __importDefault(require("./package-shared/actions/users/user-auth"));
|
||||||
const send_email_code_1 = __importDefault(require("./users/send-email-code"));
|
const reauth_user_1 = __importDefault(require("./package-shared/actions/users/reauth-user"));
|
||||||
const logout_user_1 = __importDefault(require("./users/logout-user"));
|
const get_user_1 = __importDefault(require("./package-shared/actions/users/get-user"));
|
||||||
const user_auth_1 = __importDefault(require("./users/user-auth"));
|
const google_auth_1 = __importDefault(require("./package-shared/actions/users/social/google-auth"));
|
||||||
const reauth_user_1 = __importDefault(require("./users/reauth-user"));
|
const github_auth_1 = __importDefault(require("./package-shared/actions/users/social/github-auth"));
|
||||||
const get_user_1 = __importDefault(require("./users/get-user"));
|
const get_token_1 = __importDefault(require("./package-shared/actions/users/get-token"));
|
||||||
const google_auth_1 = __importDefault(require("./users/social/google-auth"));
|
const validate_token_1 = __importDefault(require("./package-shared/actions/users/validate-token"));
|
||||||
const github_auth_1 = __importDefault(require("./users/social/github-auth"));
|
|
||||||
const get_token_1 = __importDefault(require("./users/get-token"));
|
|
||||||
const validate_token_1 = __importDefault(require("./users/validate-token"));
|
|
||||||
const client_1 = __importDefault(require("./client"));
|
const client_1 = __importDefault(require("./client"));
|
||||||
const sql_generator_1 = __importDefault(require("./package-shared/functions/dsql/sql/sql-generator"));
|
const sql_generator_1 = __importDefault(require("./package-shared/functions/dsql/sql/sql-generator"));
|
||||||
const sql_insert_generator_1 = __importDefault(require("./package-shared/functions/dsql/sql/sql-insert-generator"));
|
const sql_insert_generator_1 = __importDefault(require("./package-shared/functions/dsql/sql/sql-insert-generator"));
|
||||||
@ -35,11 +32,10 @@ const conn_db_handler_1 = __importDefault(require("./package-shared/utils/db/con
|
|||||||
const encrypt_1 = __importDefault(require("./package-shared/functions/dsql/encrypt"));
|
const encrypt_1 = __importDefault(require("./package-shared/functions/dsql/encrypt"));
|
||||||
const decrypt_1 = __importDefault(require("./package-shared/functions/dsql/decrypt"));
|
const decrypt_1 = __importDefault(require("./package-shared/functions/dsql/decrypt"));
|
||||||
const hashPassword_1 = __importDefault(require("./package-shared/functions/dsql/hashPassword"));
|
const hashPassword_1 = __importDefault(require("./package-shared/functions/dsql/hashPassword"));
|
||||||
const validate_temp_email_code_1 = __importDefault(require("./users/validate-temp-email-code"));
|
const validate_temp_email_code_1 = __importDefault(require("./package-shared/actions/users/validate-temp-email-code"));
|
||||||
const delete_user_1 = __importDefault(require("./users/delete-user"));
|
const delete_user_1 = __importDefault(require("./package-shared/actions/users/delete-user"));
|
||||||
////////////////////////////////////////
|
const crud_1 = __importDefault(require("./package-shared/utils/data-fetching/crud"));
|
||||||
////////////////////////////////////////
|
const method_crud_1 = __importDefault(require("./package-shared/utils/data-fetching/method-crud"));
|
||||||
////////////////////////////////////////
|
|
||||||
/**
|
/**
|
||||||
* User Functions Object
|
* User Functions Object
|
||||||
*/
|
*/
|
||||||
@ -82,7 +78,13 @@ const sql = {
|
|||||||
* Main Export
|
* Main Export
|
||||||
*/
|
*/
|
||||||
const datasquirel = {
|
const datasquirel = {
|
||||||
|
/**
|
||||||
|
* Get Action
|
||||||
|
*/
|
||||||
get: get_1.default,
|
get: get_1.default,
|
||||||
|
/**
|
||||||
|
* Post Action
|
||||||
|
*/
|
||||||
post: post_1.default,
|
post: post_1.default,
|
||||||
media,
|
media,
|
||||||
user,
|
user,
|
||||||
@ -99,5 +101,15 @@ const datasquirel = {
|
|||||||
httpRequest: httpRequest_1.default,
|
httpRequest: httpRequest_1.default,
|
||||||
connDbHandler: conn_db_handler_1.default,
|
connDbHandler: conn_db_handler_1.default,
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Run Crud actions `get`, `insert`, `update`, `delete`
|
||||||
|
* @note *Requires global variables `DSQL_USE_LOCAL` and `DSQL_DB_CONN`
|
||||||
|
*/
|
||||||
|
crud: crud_1.default,
|
||||||
|
/**
|
||||||
|
* Run Crud based on request Methods `GET`, `POST`, `PUT`, `PATCH`
|
||||||
|
* @note *Requires global variables `DSQL_USE_LOCAL` and `DSQL_DB_CONN`
|
||||||
|
*/
|
||||||
|
methodCrud: method_crud_1.default,
|
||||||
};
|
};
|
||||||
exports.default = datasquirel;
|
exports.default = datasquirel;
|
||||||
|
@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = deleteFile;
|
exports.default = deleteFile;
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
|
||||||
/**
|
/**
|
||||||
* # Delete File via API
|
* # Delete File via API
|
||||||
*/
|
*/
|
@ -1,4 +1,4 @@
|
|||||||
import { DSQL_DatabaseSchemaType, DSQL_FieldSchemaType, DSQL_TableSchemaType, GetSchemaAPIParam } from "../package-shared/types";
|
import { DSQL_DatabaseSchemaType, DSQL_FieldSchemaType, DSQL_TableSchemaType, GetSchemaAPIParam } from "../types";
|
||||||
type GetSchemaReturn = {
|
type GetSchemaReturn = {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
payload?: DSQL_DatabaseSchemaType | DSQL_TableSchemaType | DSQL_FieldSchemaType | null;
|
payload?: DSQL_DatabaseSchemaType | DSQL_TableSchemaType | DSQL_FieldSchemaType | null;
|
@ -1,5 +1,4 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
// @ts-check
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
@ -14,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = getSchema;
|
exports.default = getSchema;
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
|
||||||
/**
|
/**
|
||||||
* # Get Schema for Database, table, or field *
|
* # Get Schema for Database, table, or field *
|
||||||
*/
|
*/
|
@ -1,4 +1,4 @@
|
|||||||
import { ApiGetQueryObject, GetReturn } from "../package-shared/types";
|
import { ApiGetQueryObject, GetReturn } from "../types";
|
||||||
type Param<T extends {
|
type Param<T extends {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
} = {
|
} = {
|
@ -15,10 +15,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
exports.default = get;
|
exports.default = get;
|
||||||
const path_1 = __importDefault(require("path"));
|
const path_1 = __importDefault(require("path"));
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const fs_1 = __importDefault(require("fs"));
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
|
||||||
const get_1 = __importDefault(require("../package-shared/functions/api/query/get"));
|
const get_1 = __importDefault(require("../functions/api/query/get"));
|
||||||
const serialize_query_1 = __importDefault(require("../package-shared/utils/serialize-query"));
|
const serialize_query_1 = __importDefault(require("../utils/serialize-query"));
|
||||||
const grab_query_and_values_1 = __importDefault(require("../package-shared/utils/grab-query-and-values"));
|
const grab_query_and_values_1 = __importDefault(require("../utils/grab-query-and-values"));
|
||||||
/**
|
/**
|
||||||
* # Make a get request to Datasquirel API
|
* # Make a get request to Datasquirel API
|
||||||
*/
|
*/
|
@ -1,4 +1,4 @@
|
|||||||
import { PostDataPayload, PostReturn } from "../package-shared/types";
|
import { PostDataPayload, PostReturn } from "../types";
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
database?: string;
|
database?: string;
|
@ -16,8 +16,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
exports.default = post;
|
exports.default = post;
|
||||||
const path_1 = __importDefault(require("path"));
|
const path_1 = __importDefault(require("path"));
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const fs_1 = __importDefault(require("fs"));
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
|
||||||
const post_1 = __importDefault(require("../package-shared/functions/api/query/post"));
|
const post_1 = __importDefault(require("../functions/api/query/post"));
|
||||||
/**
|
/**
|
||||||
* # Make a post request to Datasquirel API
|
* # Make a post request to Datasquirel API
|
||||||
*/
|
*/
|
||||||
@ -36,7 +36,7 @@ function post(_a) {
|
|||||||
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.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(/./)) &&
|
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
|
||||||
global.DSQL_USE_LOCAL) {
|
global.DSQL_USE_LOCAL) {
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
/** @type {import("../types").DSQL_DatabaseSchemaType | undefined} */
|
||||||
let dbSchema;
|
let dbSchema;
|
||||||
try {
|
try {
|
||||||
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = uploadImage;
|
exports.default = uploadImage;
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
|
||||||
/**
|
/**
|
||||||
* # Upload File via API
|
* # Upload File via API
|
||||||
*/
|
*/
|
@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = uploadImage;
|
exports.default = uploadImage;
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
|
||||||
/**
|
/**
|
||||||
* # Upload Image via API
|
* # Upload Image via API
|
||||||
*/
|
*/
|
@ -1,4 +1,4 @@
|
|||||||
import { AddUserFunctionReturn, UserDataPayload } from "../package-shared/types";
|
import { AddUserFunctionReturn, UserDataPayload } from "../../types";
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
database?: string;
|
database?: string;
|
@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
exports.default = addUser;
|
exports.default = addUser;
|
||||||
const path_1 = __importDefault(require("path"));
|
const path_1 = __importDefault(require("path"));
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const fs_1 = __importDefault(require("fs"));
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||||
const api_create_user_1 = __importDefault(require("../package-shared/functions/api/users/api-create-user"));
|
const api_create_user_1 = __importDefault(require("../../functions/api/users/api-create-user"));
|
||||||
/**
|
/**
|
||||||
* # Add User to Database
|
* # Add User to Database
|
||||||
*/
|
*/
|
||||||
@ -35,7 +35,7 @@ function addUser(_a) {
|
|||||||
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.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(/./)) &&
|
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
|
||||||
global.DSQL_USE_LOCAL) {
|
global.DSQL_USE_LOCAL) {
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
|
||||||
let dbSchema;
|
let dbSchema;
|
||||||
try {
|
try {
|
||||||
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
@ -1,4 +1,4 @@
|
|||||||
import { UpdateUserFunctionReturn } from "../package-shared/types";
|
import { UpdateUserFunctionReturn } from "../../types";
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
database?: string;
|
database?: string;
|
@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
exports.default = deleteUser;
|
exports.default = deleteUser;
|
||||||
const path_1 = __importDefault(require("path"));
|
const path_1 = __importDefault(require("path"));
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const fs_1 = __importDefault(require("fs"));
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||||
const api_delete_user_1 = __importDefault(require("../package-shared/functions/api/users/api-delete-user"));
|
const api_delete_user_1 = __importDefault(require("../../functions/api/users/api-delete-user"));
|
||||||
/**
|
/**
|
||||||
* # Update User
|
* # Update User
|
||||||
*/
|
*/
|
||||||
@ -35,7 +35,7 @@ function deleteUser(_a) {
|
|||||||
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.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(/./)) &&
|
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
|
||||||
global.DSQL_USE_LOCAL) {
|
global.DSQL_USE_LOCAL) {
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
|
||||||
let dbSchema;
|
let dbSchema;
|
||||||
try {
|
try {
|
||||||
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = getToken;
|
exports.default = getToken;
|
||||||
const decrypt_1 = __importDefault(require("../package-shared/functions/dsql/decrypt"));
|
const decrypt_1 = __importDefault(require("../../functions/dsql/decrypt"));
|
||||||
const get_auth_cookie_names_1 = __importDefault(require("../package-shared/functions/backend/cookies/get-auth-cookie-names"));
|
const get_auth_cookie_names_1 = __importDefault(require("../../functions/backend/cookies/get-auth-cookie-names"));
|
||||||
const parseCookies_1 = __importDefault(require("../package-shared/utils/backend/parseCookies"));
|
const parseCookies_1 = __importDefault(require("../../utils/backend/parseCookies"));
|
||||||
/**
|
/**
|
||||||
* Get just the access token for user
|
* Get just the access token for user
|
||||||
* ==============================================================================
|
* ==============================================================================
|
@ -1,4 +1,4 @@
|
|||||||
import { GetUserFunctionReturn } from "../package-shared/types";
|
import { GetUserFunctionReturn } from "../../types";
|
||||||
type Param = {
|
type Param = {
|
||||||
key: string;
|
key: string;
|
||||||
database: string;
|
database: string;
|
@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
exports.default = getUser;
|
exports.default = getUser;
|
||||||
const path_1 = __importDefault(require("path"));
|
const path_1 = __importDefault(require("path"));
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const fs_1 = __importDefault(require("fs"));
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||||
const api_get_user_1 = __importDefault(require("../package-shared/functions/api/users/api-get-user"));
|
const api_get_user_1 = __importDefault(require("../../functions/api/users/api-get-user"));
|
||||||
/**
|
/**
|
||||||
* # Get User
|
* # Get User
|
||||||
*/
|
*/
|
||||||
@ -60,7 +60,7 @@ function getUser(_a) {
|
|||||||
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.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(/./)) &&
|
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
|
||||||
global.DSQL_USE_LOCAL) {
|
global.DSQL_USE_LOCAL) {
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
|
||||||
let dbSchema;
|
let dbSchema;
|
||||||
try {
|
try {
|
||||||
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
@ -1,5 +1,5 @@
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import { APILoginFunctionReturn } from "../package-shared/types";
|
import { APILoginFunctionReturn } from "../../types";
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
database: string;
|
database: string;
|
@ -15,11 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
exports.default = loginUser;
|
exports.default = loginUser;
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const fs_1 = __importDefault(require("fs"));
|
||||||
const path_1 = __importDefault(require("path"));
|
const path_1 = __importDefault(require("path"));
|
||||||
const encrypt_1 = __importDefault(require("../package-shared/functions/dsql/encrypt"));
|
const encrypt_1 = __importDefault(require("../../functions/dsql/encrypt"));
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||||
const api_login_1 = __importDefault(require("../package-shared/functions/api/users/api-login"));
|
const api_login_1 = __importDefault(require("../../functions/api/users/api-login"));
|
||||||
const get_auth_cookie_names_1 = __importDefault(require("../package-shared/functions/backend/cookies/get-auth-cookie-names"));
|
const get_auth_cookie_names_1 = __importDefault(require("../../functions/backend/cookies/get-auth-cookie-names"));
|
||||||
const write_auth_files_1 = require("../package-shared/functions/backend/auth/write-auth-files");
|
const write_auth_files_1 = require("../../functions/backend/auth/write-auth-files");
|
||||||
/**
|
/**
|
||||||
* # Login A user
|
* # Login A user
|
||||||
*/
|
*/
|
||||||
@ -67,7 +67,7 @@ function loginUser(_a) {
|
|||||||
/**
|
/**
|
||||||
* Initialize HTTP response variable
|
* Initialize HTTP response variable
|
||||||
*/
|
*/
|
||||||
/** @type {import("../package-shared/types").APILoginFunctionReturn} */
|
/** @type {import("../../types").APILoginFunctionReturn} */
|
||||||
let httpResponse = {
|
let httpResponse = {
|
||||||
success: false,
|
success: false,
|
||||||
};
|
};
|
@ -4,12 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = logoutUser;
|
exports.default = logoutUser;
|
||||||
const get_auth_cookie_names_1 = __importDefault(require("../package-shared/functions/backend/cookies/get-auth-cookie-names"));
|
const get_auth_cookie_names_1 = __importDefault(require("../../functions/backend/cookies/get-auth-cookie-names"));
|
||||||
const decrypt_1 = __importDefault(require("../package-shared/functions/dsql/decrypt"));
|
const decrypt_1 = __importDefault(require("../../functions/dsql/decrypt"));
|
||||||
const ejson_1 = __importDefault(require("../package-shared/utils/ejson"));
|
const ejson_1 = __importDefault(require("../../utils/ejson"));
|
||||||
const write_auth_files_1 = require("../package-shared/functions/backend/auth/write-auth-files");
|
const write_auth_files_1 = require("../../functions/backend/auth/write-auth-files");
|
||||||
const parseCookies_1 = __importDefault(require("../package-shared/utils/backend/parseCookies"));
|
const parseCookies_1 = __importDefault(require("../../utils/backend/parseCookies"));
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||||
/**
|
/**
|
||||||
* # Logout user
|
* # Logout user
|
||||||
*/
|
*/
|
@ -1,5 +1,5 @@
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import { APILoginFunctionReturn } from "../package-shared/types";
|
import { APILoginFunctionReturn } from "../../types";
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
database?: string;
|
database?: string;
|
@ -15,12 +15,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
exports.default = reauthUser;
|
exports.default = reauthUser;
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const fs_1 = __importDefault(require("fs"));
|
||||||
const path_1 = __importDefault(require("path"));
|
const path_1 = __importDefault(require("path"));
|
||||||
const encrypt_1 = __importDefault(require("../package-shared/functions/dsql/encrypt"));
|
const encrypt_1 = __importDefault(require("../../functions/dsql/encrypt"));
|
||||||
const user_auth_1 = __importDefault(require("./user-auth"));
|
const user_auth_1 = __importDefault(require("./user-auth"));
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||||
const api_reauth_user_1 = __importDefault(require("../package-shared/functions/api/users/api-reauth-user"));
|
const api_reauth_user_1 = __importDefault(require("../../functions/api/users/api-reauth-user"));
|
||||||
const write_auth_files_1 = require("../package-shared/functions/backend/auth/write-auth-files");
|
const write_auth_files_1 = require("../../functions/backend/auth/write-auth-files");
|
||||||
const get_auth_cookie_names_1 = __importDefault(require("../package-shared/functions/backend/cookies/get-auth-cookie-names"));
|
const get_auth_cookie_names_1 = __importDefault(require("../../functions/backend/cookies/get-auth-cookie-names"));
|
||||||
/**
|
/**
|
||||||
* # Reauthorize User
|
* # Reauthorize User
|
||||||
*/
|
*/
|
||||||
@ -66,7 +66,7 @@ function reauthUser(_a) {
|
|||||||
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.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(/./)) &&
|
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
|
||||||
global.DSQL_USE_LOCAL) {
|
global.DSQL_USE_LOCAL) {
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
|
||||||
let dbSchema;
|
let dbSchema;
|
||||||
try {
|
try {
|
||||||
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
@ -1,5 +1,5 @@
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import { SendOneTimeCodeEmailResponse } from "../package-shared/types";
|
import { SendOneTimeCodeEmailResponse } from "../../types";
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
database?: string;
|
database?: string;
|
||||||
@ -14,7 +14,7 @@ type Param = {
|
|||||||
mail_port?: number;
|
mail_port?: number;
|
||||||
sender?: string;
|
sender?: string;
|
||||||
user_id?: boolean;
|
user_id?: boolean;
|
||||||
extraCookies?: import("../package-shared/types").CookieObject[];
|
extraCookies?: import("../../types").CookieObject[];
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* # Send Email Code to a User
|
* # Send Email Code to a User
|
@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
exports.default = sendEmailCode;
|
exports.default = sendEmailCode;
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const fs_1 = __importDefault(require("fs"));
|
||||||
const path_1 = __importDefault(require("path"));
|
const path_1 = __importDefault(require("path"));
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||||
const api_send_email_code_1 = __importDefault(require("../package-shared/functions/api/users/api-send-email-code"));
|
const api_send_email_code_1 = __importDefault(require("../../functions/api/users/api-send-email-code"));
|
||||||
/**
|
/**
|
||||||
* # Send Email Code to a User
|
* # Send Email Code to a User
|
||||||
*/
|
*/
|
||||||
@ -40,7 +40,7 @@ function sendEmailCode(_a) {
|
|||||||
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.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(/./)) &&
|
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
|
||||||
global.DSQL_USE_LOCAL) {
|
global.DSQL_USE_LOCAL) {
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
|
||||||
let dbSchema;
|
let dbSchema;
|
||||||
try {
|
try {
|
||||||
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
||||||
@ -67,7 +67,7 @@ function sendEmailCode(_a) {
|
|||||||
*
|
*
|
||||||
* @description make a request to datasquirel.com
|
* @description make a request to datasquirel.com
|
||||||
*
|
*
|
||||||
* @type {import("../package-shared/types").SendOneTimeCodeEmailResponse}
|
* @type {import("../../types").SendOneTimeCodeEmailResponse}
|
||||||
*/
|
*/
|
||||||
const httpResponse = yield new Promise((resolve, reject) => {
|
const httpResponse = yield new Promise((resolve, reject) => {
|
||||||
const reqPayload = JSON.stringify({
|
const reqPayload = JSON.stringify({
|
@ -15,9 +15,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
exports.default = githubAuth;
|
exports.default = githubAuth;
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const fs_1 = __importDefault(require("fs"));
|
||||||
const path_1 = __importDefault(require("path"));
|
const path_1 = __importDefault(require("path"));
|
||||||
const encrypt_1 = __importDefault(require("../../package-shared/functions/dsql/encrypt"));
|
const encrypt_1 = __importDefault(require("../../../functions/dsql/encrypt"));
|
||||||
const grab_host_names_1 = __importDefault(require("../../package-shared/utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../../../utils/grab-host-names"));
|
||||||
const api_github_login_1 = __importDefault(require("../../package-shared/functions/api/users/social/api-github-login"));
|
const api_github_login_1 = __importDefault(require("../../../functions/api/users/social/api-github-login"));
|
||||||
/**
|
/**
|
||||||
* # SERVER FUNCTION: Login with google Function
|
* # SERVER FUNCTION: Login with google Function
|
||||||
*/
|
*/
|
||||||
@ -65,7 +65,7 @@ function githubAuth(_a) {
|
|||||||
(DSQL_DB_USERNAME === null || DSQL_DB_USERNAME === void 0 ? void 0 : DSQL_DB_USERNAME.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_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(/./))) {
|
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./))) {
|
||||||
/** @type {import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined | undefined} */
|
/** @type {import("../../../types").DSQL_DatabaseSchemaType | undefined | undefined} */
|
||||||
let dbSchema;
|
let dbSchema;
|
||||||
try {
|
try {
|
||||||
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
@ -1,5 +1,5 @@
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import { APILoginFunctionReturn } from "../../package-shared/types";
|
import { APILoginFunctionReturn } from "../../../types";
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
token: string;
|
token: string;
|
@ -13,11 +13,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = googleAuth;
|
exports.default = googleAuth;
|
||||||
const encrypt_1 = __importDefault(require("../../package-shared/functions/dsql/encrypt"));
|
const encrypt_1 = __importDefault(require("../../../functions/dsql/encrypt"));
|
||||||
const grab_host_names_1 = __importDefault(require("../../package-shared/utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../../../utils/grab-host-names"));
|
||||||
const api_google_login_1 = __importDefault(require("../../package-shared/functions/api/users/social/api-google-login"));
|
const api_google_login_1 = __importDefault(require("../../../functions/api/users/social/api-google-login"));
|
||||||
const get_auth_cookie_names_1 = __importDefault(require("../../package-shared/functions/backend/cookies/get-auth-cookie-names"));
|
const get_auth_cookie_names_1 = __importDefault(require("../../../functions/backend/cookies/get-auth-cookie-names"));
|
||||||
const write_auth_files_1 = require("../../package-shared/functions/backend/auth/write-auth-files");
|
const write_auth_files_1 = require("../../../functions/backend/auth/write-auth-files");
|
||||||
/**
|
/**
|
||||||
* # SERVER FUNCTION: Login with google Function
|
* # SERVER FUNCTION: Login with google Function
|
||||||
*/
|
*/
|
||||||
@ -88,7 +88,7 @@ function googleAuth(_a) {
|
|||||||
* Make https request
|
* Make https request
|
||||||
*
|
*
|
||||||
* @description make a request to datasquirel.com
|
* @description make a request to datasquirel.com
|
||||||
* @type {{ success: boolean, user: import("../../package-shared/types").DATASQUIREL_LoggedInUser | null, msg?: string, dsqlUserId?: number } | null } - Https response object
|
* @type {{ success: boolean, user: import("../../../types").DATASQUIREL_LoggedInUser | null, msg?: string, dsqlUserId?: number } | null } - Https response object
|
||||||
*/
|
*/
|
||||||
httpResponse = yield new Promise((resolve, reject) => {
|
httpResponse = yield new Promise((resolve, reject) => {
|
||||||
const reqPayload = JSON.stringify({
|
const reqPayload = JSON.stringify({
|
@ -1,4 +1,4 @@
|
|||||||
import { UpdateUserFunctionReturn } from "../package-shared/types";
|
import { UpdateUserFunctionReturn } from "../../types";
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
database?: string;
|
database?: string;
|
@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
exports.default = updateUser;
|
exports.default = updateUser;
|
||||||
const path_1 = __importDefault(require("path"));
|
const path_1 = __importDefault(require("path"));
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const fs_1 = __importDefault(require("fs"));
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||||
const api_update_user_1 = __importDefault(require("../package-shared/functions/api/users/api-update-user"));
|
const api_update_user_1 = __importDefault(require("../../functions/api/users/api-update-user"));
|
||||||
/**
|
/**
|
||||||
* # Update User
|
* # Update User
|
||||||
*/
|
*/
|
||||||
@ -35,7 +35,7 @@ function updateUser(_a) {
|
|||||||
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.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(/./)) &&
|
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
|
||||||
global.DSQL_USE_LOCAL) {
|
global.DSQL_USE_LOCAL) {
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
|
||||||
let dbSchema;
|
let dbSchema;
|
||||||
try {
|
try {
|
||||||
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
@ -1,5 +1,5 @@
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import { AuthenticatedUser } from "../package-shared/types";
|
import { AuthenticatedUser } from "../../types";
|
||||||
type Param = {
|
type Param = {
|
||||||
request?: http.IncomingMessage & {
|
request?: http.IncomingMessage & {
|
||||||
[s: string]: any;
|
[s: string]: any;
|
@ -4,12 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = userAuth;
|
exports.default = userAuth;
|
||||||
const decrypt_1 = __importDefault(require("../package-shared/functions/dsql/decrypt"));
|
const decrypt_1 = __importDefault(require("../../functions/dsql/decrypt"));
|
||||||
const get_auth_cookie_names_1 = __importDefault(require("../package-shared/functions/backend/cookies/get-auth-cookie-names"));
|
const get_auth_cookie_names_1 = __importDefault(require("../../functions/backend/cookies/get-auth-cookie-names"));
|
||||||
const write_auth_files_1 = require("../package-shared/functions/backend/auth/write-auth-files");
|
const write_auth_files_1 = require("../../functions/backend/auth/write-auth-files");
|
||||||
const parseCookies_1 = __importDefault(require("../package-shared/utils/backend/parseCookies"));
|
const parseCookies_1 = __importDefault(require("../../utils/backend/parseCookies"));
|
||||||
const get_csrf_header_name_1 = __importDefault(require("../utils/get-csrf-header-name"));
|
const get_csrf_header_name_1 = __importDefault(require("../../actions/get-csrf-header-name"));
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||||
const minuteInMilliseconds = 60000;
|
const minuteInMilliseconds = 60000;
|
||||||
const hourInMilliseconds = minuteInMilliseconds * 60;
|
const hourInMilliseconds = minuteInMilliseconds * 60;
|
||||||
const dayInMilliseconds = hourInMilliseconds * 24;
|
const dayInMilliseconds = hourInMilliseconds * 24;
|
||||||
@ -76,7 +76,7 @@ function userAuth({ request, req, encryptionKey, encryptionSalt, level, database
|
|||||||
*
|
*
|
||||||
* @description Grab the payload
|
* @description Grab the payload
|
||||||
*/
|
*/
|
||||||
/** @type {import("../package-shared/types").DATASQUIREL_LoggedInUser} */
|
/** @type {import("../../types").DATASQUIREL_LoggedInUser} */
|
||||||
let userObject = JSON.parse(userPayloadJSON);
|
let userObject = JSON.parse(userPayloadJSON);
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log("userAuth:userObject:", userObject);
|
console.log("userAuth:userObject:", userObject);
|
@ -1,5 +1,5 @@
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import { SendOneTimeCodeEmailResponse } from "../package-shared/types";
|
import { SendOneTimeCodeEmailResponse } from "../../types";
|
||||||
type Param = {
|
type Param = {
|
||||||
request?: http.IncomingMessage & {
|
request?: http.IncomingMessage & {
|
||||||
[s: string]: any;
|
[s: string]: any;
|
@ -13,10 +13,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = validateTempEmailCode;
|
exports.default = validateTempEmailCode;
|
||||||
const get_auth_cookie_names_1 = __importDefault(require("../package-shared/functions/backend/cookies/get-auth-cookie-names"));
|
const get_auth_cookie_names_1 = __importDefault(require("../../functions/backend/cookies/get-auth-cookie-names"));
|
||||||
const parseCookies_1 = __importDefault(require("../package-shared/utils/backend/parseCookies"));
|
const parseCookies_1 = __importDefault(require("../../utils/backend/parseCookies"));
|
||||||
const decrypt_1 = __importDefault(require("../package-shared/functions/dsql/decrypt"));
|
const decrypt_1 = __importDefault(require("../../functions/dsql/decrypt"));
|
||||||
const ejson_1 = __importDefault(require("../package-shared/utils/ejson"));
|
const ejson_1 = __importDefault(require("../../utils/ejson"));
|
||||||
/**
|
/**
|
||||||
* # Verify the temp email code sent to the user's email address
|
* # Verify the temp email code sent to the user's email address
|
||||||
*/
|
*/
|
@ -1,4 +1,4 @@
|
|||||||
import { DATASQUIREL_LoggedInUser } from "../package-shared/types";
|
import { DATASQUIREL_LoggedInUser } from "../../types";
|
||||||
type Param = {
|
type Param = {
|
||||||
token: string;
|
token: string;
|
||||||
encryptionKey: string;
|
encryptionKey: string;
|
@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = validateToken;
|
exports.default = validateToken;
|
||||||
const decrypt_1 = __importDefault(require("../package-shared/functions/dsql/decrypt"));
|
const decrypt_1 = __importDefault(require("../../functions/dsql/decrypt"));
|
||||||
/**
|
/**
|
||||||
* Validate Token
|
* Validate Token
|
||||||
* ======================================
|
* ======================================
|
@ -29,7 +29,6 @@ function apiPost(_a) {
|
|||||||
((_b = query === null || query === void 0 ? void 0 : query.action) === null || _b === void 0 ? void 0 : _b.match(/^create |^alter |^drop /i))) {
|
((_b = query === null || query === void 0 ? void 0 : query.action) === null || _b === void 0 ? void 0 : _b.match(/^create |^alter |^drop /i))) {
|
||||||
return { success: false, msg: "Wrong Input" };
|
return { success: false, msg: "Wrong Input" };
|
||||||
}
|
}
|
||||||
/** @type {any} */
|
|
||||||
let results;
|
let results;
|
||||||
/**
|
/**
|
||||||
* Create new user folder and file
|
* Create new user folder and file
|
||||||
|
@ -35,7 +35,6 @@ function apiDeleteUser(_a) {
|
|||||||
}
|
}
|
||||||
const deleteUser = yield (0, deleteDbEntry_1.default)({
|
const deleteUser = yield (0, deleteDbEntry_1.default)({
|
||||||
dbContext: "Dsql User",
|
dbContext: "Dsql User",
|
||||||
paradigm: "Full Access",
|
|
||||||
dbFullName,
|
dbFullName,
|
||||||
tableName: "users",
|
tableName: "users",
|
||||||
identifierColumnName: "id",
|
identifierColumnName: "id",
|
||||||
|
@ -68,7 +68,6 @@ function apiUpdateUser(_a) {
|
|||||||
})();
|
})();
|
||||||
const updateUser = yield (0, updateDbEntry_1.default)({
|
const updateUser = yield (0, updateDbEntry_1.default)({
|
||||||
dbContext: "Dsql User",
|
dbContext: "Dsql User",
|
||||||
paradigm: "Full Access",
|
|
||||||
dbFullName,
|
dbFullName,
|
||||||
tableName: "users",
|
tableName: "users",
|
||||||
identifierColumnName: "id",
|
identifierColumnName: "id",
|
||||||
|
@ -16,6 +16,7 @@ exports.default = dbHandler;
|
|||||||
const fs_1 = __importDefault(require("fs"));
|
const fs_1 = __importDefault(require("fs"));
|
||||||
const serverError_1 = __importDefault(require("./serverError"));
|
const serverError_1 = __importDefault(require("./serverError"));
|
||||||
const grab_dsql_connection_1 = __importDefault(require("../../utils/grab-dsql-connection"));
|
const grab_dsql_connection_1 = __importDefault(require("../../utils/grab-dsql-connection"));
|
||||||
|
const path_1 = __importDefault(require("path"));
|
||||||
/**
|
/**
|
||||||
* # Main DB Handler Function
|
* # Main DB Handler Function
|
||||||
*/
|
*/
|
||||||
@ -44,7 +45,10 @@ function dbHandler(...args) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
fs_1.default.appendFileSync("./.tmp/dbErrorLogs.txt", JSON.stringify(error, null, 4) + "\n" + Date() + "\n\n\n", "utf8");
|
const tmpFolder = path_1.default.resolve(process.cwd(), "./.tmp");
|
||||||
|
if (!fs_1.default.existsSync(tmpFolder))
|
||||||
|
fs_1.default.mkdirSync(tmpFolder, { recursive: true });
|
||||||
|
fs_1.default.appendFileSync(path_1.default.resolve(tmpFolder, "./dbErrorLogs.txt"), JSON.stringify(error, null, 4) + "\n" + Date() + "\n\n\n", "utf8");
|
||||||
results = null;
|
results = null;
|
||||||
(0, serverError_1.default)({
|
(0, serverError_1.default)({
|
||||||
component: "dbHandler",
|
component: "dbHandler",
|
||||||
|
5
dist/package-shared/shell/utils/dbHandler.js
vendored
5
dist/package-shared/shell/utils/dbHandler.js
vendored
@ -39,7 +39,10 @@ function dbHandler(_a) {
|
|||||||
console.log("ERROR in dbHandler =>", error.message);
|
console.log("ERROR in dbHandler =>", error.message);
|
||||||
console.log(error);
|
console.log(error);
|
||||||
console.log(CONNECTION.config());
|
console.log(CONNECTION.config());
|
||||||
fs_1.default.appendFileSync(path_1.default.resolve(__dirname, "../.tmp/dbErrorLogs.txt"), JSON.stringify(error, null, 4) + "\n" + Date() + "\n\n\n", "utf8");
|
const tmpFolder = path_1.default.resolve(process.cwd(), "./.tmp");
|
||||||
|
if (!fs_1.default.existsSync(tmpFolder))
|
||||||
|
fs_1.default.mkdirSync(tmpFolder, { recursive: true });
|
||||||
|
fs_1.default.appendFileSync(path_1.default.resolve(tmpFolder, "./dbErrorLogs.txt"), JSON.stringify(error, null, 4) + "\n" + Date() + "\n\n\n", "utf8");
|
||||||
results = null;
|
results = null;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
38
dist/package-shared/types/index.d.ts
vendored
38
dist/package-shared/types/index.d.ts
vendored
@ -34,7 +34,29 @@ export interface DSQL_ChildrenTablesType {
|
|||||||
tableName: string;
|
tableName: string;
|
||||||
tableNameFull?: string;
|
tableNameFull?: string;
|
||||||
}
|
}
|
||||||
export interface DSQL_FieldSchemaType {
|
export declare const TextFieldTypesArray: readonly [{
|
||||||
|
readonly title: "Plain Text";
|
||||||
|
readonly value: "plain";
|
||||||
|
}, {
|
||||||
|
readonly title: "Rich Text";
|
||||||
|
readonly value: "richText";
|
||||||
|
}, {
|
||||||
|
readonly title: "JSON";
|
||||||
|
readonly value: "json";
|
||||||
|
}, {
|
||||||
|
readonly title: "YAML";
|
||||||
|
readonly value: "yaml";
|
||||||
|
}, {
|
||||||
|
readonly title: "HTML";
|
||||||
|
readonly value: "html";
|
||||||
|
}, {
|
||||||
|
readonly title: "CSS";
|
||||||
|
readonly value: "css";
|
||||||
|
}, {
|
||||||
|
readonly title: "Javascript";
|
||||||
|
readonly value: "javascript";
|
||||||
|
}];
|
||||||
|
export type DSQL_FieldSchemaType = {
|
||||||
fieldName?: string;
|
fieldName?: string;
|
||||||
originName?: string;
|
originName?: string;
|
||||||
updatedField?: boolean;
|
updatedField?: boolean;
|
||||||
@ -47,13 +69,6 @@ export interface DSQL_FieldSchemaType {
|
|||||||
defaultValue?: string | number;
|
defaultValue?: string | number;
|
||||||
defaultValueLiteral?: string;
|
defaultValueLiteral?: string;
|
||||||
foreignKey?: DSQL_ForeignKeyType;
|
foreignKey?: DSQL_ForeignKeyType;
|
||||||
richText?: boolean;
|
|
||||||
json?: boolean;
|
|
||||||
yaml?: boolean;
|
|
||||||
html?: boolean;
|
|
||||||
css?: boolean;
|
|
||||||
javascript?: boolean;
|
|
||||||
shell?: boolean;
|
|
||||||
newTempField?: boolean;
|
newTempField?: boolean;
|
||||||
defaultField?: boolean;
|
defaultField?: boolean;
|
||||||
plainText?: boolean;
|
plainText?: boolean;
|
||||||
@ -65,7 +80,11 @@ export interface DSQL_FieldSchemaType {
|
|||||||
onDelete?: string;
|
onDelete?: string;
|
||||||
onDeleteLiteral?: string;
|
onDeleteLiteral?: string;
|
||||||
cssFiles?: string[];
|
cssFiles?: string[];
|
||||||
}
|
integerLength?: string | number;
|
||||||
|
decimals?: string | number;
|
||||||
|
} & {
|
||||||
|
[key in (typeof TextFieldTypesArray)[number]["value"]]?: boolean;
|
||||||
|
};
|
||||||
export interface DSQL_ForeignKeyType {
|
export interface DSQL_ForeignKeyType {
|
||||||
foreignKeyName?: string;
|
foreignKeyName?: string;
|
||||||
destinationTableName?: string;
|
destinationTableName?: string;
|
||||||
@ -784,6 +803,7 @@ export interface MYSQL_user_database_tables_table_def {
|
|||||||
table_slug?: string;
|
table_slug?: string;
|
||||||
table_description?: string;
|
table_description?: string;
|
||||||
child_table?: number;
|
child_table?: number;
|
||||||
|
active_data?: 0 | 1;
|
||||||
child_table_parent_database?: string;
|
child_table_parent_database?: string;
|
||||||
child_table_parent_table?: string;
|
child_table_parent_table?: string;
|
||||||
date_created?: string;
|
date_created?: string;
|
||||||
|
11
dist/package-shared/types/index.js
vendored
11
dist/package-shared/types/index.js
vendored
@ -1,5 +1,14 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.ServerQueryEqualities = exports.ServerQueryOperators = void 0;
|
exports.ServerQueryEqualities = exports.ServerQueryOperators = exports.TextFieldTypesArray = void 0;
|
||||||
|
exports.TextFieldTypesArray = [
|
||||||
|
{ title: "Plain Text", value: "plain" },
|
||||||
|
{ title: "Rich Text", value: "richText" },
|
||||||
|
{ title: "JSON", value: "json" },
|
||||||
|
{ title: "YAML", value: "yaml" },
|
||||||
|
{ title: "HTML", value: "html" },
|
||||||
|
{ title: "CSS", value: "css" },
|
||||||
|
{ title: "Javascript", value: "javascript" },
|
||||||
|
];
|
||||||
exports.ServerQueryOperators = ["AND", "OR"];
|
exports.ServerQueryOperators = ["AND", "OR"];
|
||||||
exports.ServerQueryEqualities = ["EQUAL", "LIKE", "NOT EQUAL"];
|
exports.ServerQueryEqualities = ["EQUAL", "LIKE", "NOT EQUAL"];
|
||||||
|
25
dist/package-shared/utils/data-fetching/crud.d.ts
vendored
Normal file
25
dist/package-shared/utils/data-fetching/crud.d.ts
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import sqlGenerator from "../../functions/dsql/sql/sql-generator";
|
||||||
|
import { PostReturn, ServerQueryParam, ServerQueryQueryObject } from "../../types";
|
||||||
|
export declare const DsqlCrudActions: readonly ["insert", "update", "delete", "get"];
|
||||||
|
export type CrudQueryObject<T extends object = {
|
||||||
|
[key: string]: any;
|
||||||
|
}> = ServerQueryParam & {
|
||||||
|
query: ServerQueryQueryObject<T>;
|
||||||
|
};
|
||||||
|
export type CrudParam<T extends object = {
|
||||||
|
[key: string]: any;
|
||||||
|
}> = {
|
||||||
|
action: (typeof DsqlCrudActions)[number];
|
||||||
|
table: string;
|
||||||
|
data?: T;
|
||||||
|
targetId?: string | number;
|
||||||
|
query?: CrudQueryObject<T>;
|
||||||
|
sanitize?: (data?: T) => T;
|
||||||
|
};
|
||||||
|
export default function dsqlCrud<T extends {
|
||||||
|
[key: string]: any;
|
||||||
|
} = {
|
||||||
|
[key: string]: any;
|
||||||
|
}>({ action, data, table, targetId, query, sanitize, }: CrudParam<T>): Promise<(PostReturn & {
|
||||||
|
queryObject?: ReturnType<Awaited<typeof sqlGenerator>>;
|
||||||
|
}) | null>;
|
69
dist/package-shared/utils/data-fetching/crud.js
vendored
Normal file
69
dist/package-shared/utils/data-fetching/crud.js
vendored
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
"use strict";
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.DsqlCrudActions = void 0;
|
||||||
|
exports.default = dsqlCrud;
|
||||||
|
const get_1 = __importDefault(require("../../actions/get"));
|
||||||
|
const post_1 = __importDefault(require("../../actions/post"));
|
||||||
|
const sql_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-generator"));
|
||||||
|
exports.DsqlCrudActions = ["insert", "update", "delete", "get"];
|
||||||
|
function dsqlCrud(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ action, data, table, targetId, query, sanitize, }) {
|
||||||
|
const finalData = sanitize ? sanitize(data) : data;
|
||||||
|
const finalId = targetId;
|
||||||
|
let queryObject;
|
||||||
|
switch (action) {
|
||||||
|
case "get":
|
||||||
|
queryObject = (0, sql_generator_1.default)({
|
||||||
|
tableName: table,
|
||||||
|
genObject: query,
|
||||||
|
});
|
||||||
|
const GET_RES = yield (0, get_1.default)({
|
||||||
|
query: (queryObject === null || queryObject === void 0 ? void 0 : queryObject.string) || "",
|
||||||
|
queryValues: (queryObject === null || queryObject === void 0 ? void 0 : queryObject.values) || [],
|
||||||
|
});
|
||||||
|
return Object.assign(Object.assign({}, GET_RES), { queryObject });
|
||||||
|
case "insert":
|
||||||
|
return yield (0, post_1.default)({
|
||||||
|
query: {
|
||||||
|
action: "insert",
|
||||||
|
table,
|
||||||
|
data: finalData,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
case "update":
|
||||||
|
data === null || data === void 0 ? true : delete data.id;
|
||||||
|
return yield (0, post_1.default)({
|
||||||
|
query: {
|
||||||
|
action: "update",
|
||||||
|
table,
|
||||||
|
identifierColumnName: "id",
|
||||||
|
identifierValue: String(finalId),
|
||||||
|
data: finalData,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
case "delete":
|
||||||
|
return yield (0, post_1.default)({
|
||||||
|
query: {
|
||||||
|
action: "delete",
|
||||||
|
table,
|
||||||
|
identifierColumnName: "id",
|
||||||
|
identifierValue: String(finalId),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
42
dist/package-shared/utils/data-fetching/method-crud.d.ts
vendored
Normal file
42
dist/package-shared/utils/data-fetching/method-crud.d.ts
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import { DATASQUIREL_LoggedInUser, ServerQueryParam } from "../../types";
|
||||||
|
export declare const DataCrudRequestMethods: readonly ["GET", "POST", "PUT", "DELETE"];
|
||||||
|
export type APIDataCrudQuery = ServerQueryParam & {
|
||||||
|
page?: number;
|
||||||
|
};
|
||||||
|
export type CRUDResponseObject<P extends any = any> = {
|
||||||
|
success: boolean;
|
||||||
|
payload?: P;
|
||||||
|
msg?: string;
|
||||||
|
error?: string;
|
||||||
|
};
|
||||||
|
export type ApiDataCrudParam<T extends {
|
||||||
|
[key: string]: any;
|
||||||
|
} = {
|
||||||
|
[key: string]: any;
|
||||||
|
}> = {
|
||||||
|
method: (typeof DataCrudRequestMethods)[number];
|
||||||
|
body?: T;
|
||||||
|
query?: string | T;
|
||||||
|
tableName: string;
|
||||||
|
addUser?: {
|
||||||
|
field: string;
|
||||||
|
};
|
||||||
|
user?: DATASQUIREL_LoggedInUser;
|
||||||
|
extraData?: T;
|
||||||
|
transform?: ({ data, existingData, user, }: {
|
||||||
|
user?: DATASQUIREL_LoggedInUser;
|
||||||
|
data: T;
|
||||||
|
existingData?: T;
|
||||||
|
reqMethod: (typeof DataCrudRequestMethods)[number];
|
||||||
|
}) => Promise<T>;
|
||||||
|
existingData?: T;
|
||||||
|
};
|
||||||
|
export default function dsqlMethodCrud<T extends {
|
||||||
|
[key: string]: any;
|
||||||
|
} = {
|
||||||
|
[key: string]: any;
|
||||||
|
}, P extends {
|
||||||
|
[key: string]: any;
|
||||||
|
} = {
|
||||||
|
[key: string]: any;
|
||||||
|
}>({ method, tableName, addUser, user, extraData, transform, existingData, body, query, }: ApiDataCrudParam<T>): Promise<CRUDResponseObject<P>>;
|
122
dist/package-shared/utils/data-fetching/method-crud.js
vendored
Normal file
122
dist/package-shared/utils/data-fetching/method-crud.js
vendored
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
"use strict";
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.DataCrudRequestMethods = void 0;
|
||||||
|
exports.default = dsqlMethodCrud;
|
||||||
|
const ejson_1 = __importDefault(require("../ejson"));
|
||||||
|
const crud_1 = __importDefault(require("./crud"));
|
||||||
|
exports.DataCrudRequestMethods = ["GET", "POST", "PUT", "DELETE"];
|
||||||
|
function dsqlMethodCrud(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ method, tableName, addUser, user, extraData, transform, existingData, body, query, }) {
|
||||||
|
let result = {
|
||||||
|
success: false,
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
let finalBody = body;
|
||||||
|
let finalQuery = query;
|
||||||
|
Object.keys(finalQuery).forEach((key) => {
|
||||||
|
const value = finalQuery[key];
|
||||||
|
if (typeof value == "string" && value.match(/^\{|^\[/)) {
|
||||||
|
finalQuery[key] = ejson_1.default.stringify(value);
|
||||||
|
}
|
||||||
|
if (value == "true") {
|
||||||
|
finalQuery[key] = true;
|
||||||
|
}
|
||||||
|
if (value == "false") {
|
||||||
|
finalQuery[key] = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const LIMIT = finalQuery.limit || 10;
|
||||||
|
const PAGE = finalQuery.page || 1;
|
||||||
|
const OFFSET = (PAGE - 1) * LIMIT;
|
||||||
|
let finalData = Object.assign(Object.assign({}, finalBody.data), extraData);
|
||||||
|
if (user && addUser) {
|
||||||
|
finalData = Object.assign(Object.assign({}, finalData), { [addUser.field]: String(user.id) });
|
||||||
|
}
|
||||||
|
if (transform) {
|
||||||
|
finalData = yield transform({
|
||||||
|
data: finalData,
|
||||||
|
existingData: existingData,
|
||||||
|
user,
|
||||||
|
reqMethod: method,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
switch (method) {
|
||||||
|
case "GET":
|
||||||
|
const GET_RESULT = yield (0, crud_1.default)({
|
||||||
|
action: "get",
|
||||||
|
table: tableName,
|
||||||
|
query: Object.assign(Object.assign({}, finalQuery), { query: Object.assign(Object.assign({}, finalQuery.query), { user_id: user
|
||||||
|
? {
|
||||||
|
value: String(user.id),
|
||||||
|
}
|
||||||
|
: undefined }), limit: LIMIT, offset: OFFSET || undefined }),
|
||||||
|
});
|
||||||
|
result = {
|
||||||
|
success: Boolean(GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.success),
|
||||||
|
payload: GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.payload,
|
||||||
|
msg: GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.msg,
|
||||||
|
error: GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.error,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case "POST":
|
||||||
|
const POST_RESULT = yield (0, crud_1.default)({
|
||||||
|
action: "insert",
|
||||||
|
table: tableName,
|
||||||
|
data: finalData,
|
||||||
|
});
|
||||||
|
result = {
|
||||||
|
success: Boolean(POST_RESULT === null || POST_RESULT === void 0 ? void 0 : POST_RESULT.success),
|
||||||
|
payload: POST_RESULT === null || POST_RESULT === void 0 ? void 0 : POST_RESULT.payload,
|
||||||
|
msg: POST_RESULT === null || POST_RESULT === void 0 ? void 0 : POST_RESULT.msg,
|
||||||
|
error: POST_RESULT === null || POST_RESULT === void 0 ? void 0 : POST_RESULT.error,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case "PUT":
|
||||||
|
const PUT_RESULT = yield (0, crud_1.default)({
|
||||||
|
action: "update",
|
||||||
|
table: tableName,
|
||||||
|
data: finalData,
|
||||||
|
targetId: finalBody.data.id,
|
||||||
|
});
|
||||||
|
result = {
|
||||||
|
success: Boolean(PUT_RESULT === null || PUT_RESULT === void 0 ? void 0 : PUT_RESULT.success),
|
||||||
|
payload: PUT_RESULT === null || PUT_RESULT === void 0 ? void 0 : PUT_RESULT.payload,
|
||||||
|
msg: PUT_RESULT === null || PUT_RESULT === void 0 ? void 0 : PUT_RESULT.msg,
|
||||||
|
error: PUT_RESULT === null || PUT_RESULT === void 0 ? void 0 : PUT_RESULT.error,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case "DELETE":
|
||||||
|
const DELETE_RESULT = yield (0, crud_1.default)({
|
||||||
|
action: "delete",
|
||||||
|
table: tableName,
|
||||||
|
targetId: finalBody.data.id,
|
||||||
|
});
|
||||||
|
result = {
|
||||||
|
success: Boolean(DELETE_RESULT === null || DELETE_RESULT === void 0 ? void 0 : DELETE_RESULT.success),
|
||||||
|
payload: DELETE_RESULT === null || DELETE_RESULT === void 0 ? void 0 : DELETE_RESULT.payload,
|
||||||
|
msg: DELETE_RESULT === null || DELETE_RESULT === void 0 ? void 0 : DELETE_RESULT.msg,
|
||||||
|
error: DELETE_RESULT === null || DELETE_RESULT === void 0 ? void 0 : DELETE_RESULT.error,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
65
index.ts
65
index.ts
@ -7,31 +7,28 @@ declare global {
|
|||||||
var DSQL_USE_LOCAL: boolean | undefined;
|
var DSQL_USE_LOCAL: boolean | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
import get from "./package-shared/actions/get";
|
||||||
* Imports
|
import post from "./package-shared/actions/post";
|
||||||
*/
|
import getSchema from "./package-shared/actions/get-schema";
|
||||||
import get from "./utils/get";
|
|
||||||
import post from "./utils/post";
|
|
||||||
import getSchema from "./utils/get-schema";
|
|
||||||
|
|
||||||
import uploadImage from "./utils/upload-image";
|
import uploadImage from "./package-shared/actions/upload-image";
|
||||||
import uploadFile from "./utils/upload-file";
|
import uploadFile from "./package-shared/actions/upload-file";
|
||||||
import deleteFile from "./utils/delete-file";
|
import deleteFile from "./package-shared/actions/delete-file";
|
||||||
|
|
||||||
import createUser from "./users/add-user";
|
import createUser from "./package-shared/actions/users/add-user";
|
||||||
import updateUser from "./users/update-user";
|
import updateUser from "./package-shared/actions/users/update-user";
|
||||||
import loginUser from "./users/login-user";
|
import loginUser from "./package-shared/actions/users/login-user";
|
||||||
import sendEmailCode from "./users/send-email-code";
|
import sendEmailCode from "./package-shared/actions/users/send-email-code";
|
||||||
import logoutUser from "./users/logout-user";
|
import logoutUser from "./package-shared/actions/users/logout-user";
|
||||||
|
|
||||||
import userAuth from "./users/user-auth";
|
import userAuth from "./package-shared/actions/users/user-auth";
|
||||||
import reAuthUser from "./users/reauth-user";
|
import reAuthUser from "./package-shared/actions/users/reauth-user";
|
||||||
import getUser from "./users/get-user";
|
import getUser from "./package-shared/actions/users/get-user";
|
||||||
|
|
||||||
import loginWithGoogle from "./users/social/google-auth";
|
import loginWithGoogle from "./package-shared/actions/users/social/google-auth";
|
||||||
import loginWithGithub from "./users/social/github-auth";
|
import loginWithGithub from "./package-shared/actions/users/social/github-auth";
|
||||||
import getToken from "./users/get-token";
|
import getToken from "./package-shared/actions/users/get-token";
|
||||||
import validateToken from "./users/validate-token";
|
import validateToken from "./package-shared/actions/users/validate-token";
|
||||||
|
|
||||||
import datasquirelClient from "./client";
|
import datasquirelClient from "./client";
|
||||||
import sqlGenerator from "./package-shared/functions/dsql/sql/sql-generator";
|
import sqlGenerator from "./package-shared/functions/dsql/sql/sql-generator";
|
||||||
@ -44,12 +41,10 @@ import connDbHandler from "./package-shared/utils/db/conn-db-handler";
|
|||||||
import encrypt from "./package-shared/functions/dsql/encrypt";
|
import encrypt from "./package-shared/functions/dsql/encrypt";
|
||||||
import decrypt from "./package-shared/functions/dsql/decrypt";
|
import decrypt from "./package-shared/functions/dsql/decrypt";
|
||||||
import hashPassword from "./package-shared/functions/dsql/hashPassword";
|
import hashPassword from "./package-shared/functions/dsql/hashPassword";
|
||||||
import validateTempEmailCode from "./users/validate-temp-email-code";
|
import validateTempEmailCode from "./package-shared/actions/users/validate-temp-email-code";
|
||||||
import deleteUser from "./users/delete-user";
|
import deleteUser from "./package-shared/actions/users/delete-user";
|
||||||
|
import dsqlCrud from "./package-shared/utils/data-fetching/crud";
|
||||||
////////////////////////////////////////
|
import dsqlMethodCrud from "./package-shared/utils/data-fetching/method-crud";
|
||||||
////////////////////////////////////////
|
|
||||||
////////////////////////////////////////
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User Functions Object
|
* User Functions Object
|
||||||
@ -96,7 +91,13 @@ const sql = {
|
|||||||
* Main Export
|
* Main Export
|
||||||
*/
|
*/
|
||||||
const datasquirel = {
|
const datasquirel = {
|
||||||
|
/**
|
||||||
|
* Get Action
|
||||||
|
*/
|
||||||
get,
|
get,
|
||||||
|
/**
|
||||||
|
* Post Action
|
||||||
|
*/
|
||||||
post,
|
post,
|
||||||
media,
|
media,
|
||||||
user,
|
user,
|
||||||
@ -113,6 +114,16 @@ const datasquirel = {
|
|||||||
httpRequest,
|
httpRequest,
|
||||||
connDbHandler,
|
connDbHandler,
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Run Crud actions `get`, `insert`, `update`, `delete`
|
||||||
|
* @note *Requires global variables `DSQL_USE_LOCAL` and `DSQL_DB_CONN`
|
||||||
|
*/
|
||||||
|
crud: dsqlCrud,
|
||||||
|
/**
|
||||||
|
* Run Crud based on request Methods `GET`, `POST`, `PUT`, `PATCH`
|
||||||
|
* @note *Requires global variables `DSQL_USE_LOCAL` and `DSQL_DB_CONN`
|
||||||
|
*/
|
||||||
|
methodCrud: dsqlMethodCrud,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default datasquirel;
|
export default datasquirel;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import grabHostNames from "../package-shared/utils/grab-host-names";
|
import grabHostNames from "../utils/grab-host-names";
|
||||||
|
|
||||||
interface Return {
|
interface Return {
|
||||||
success: boolean;
|
success: boolean;
|
@ -1,13 +1,11 @@
|
|||||||
// @ts-check
|
import grabHostNames from "../utils/grab-host-names";
|
||||||
|
|
||||||
import grabHostNames from "../package-shared/utils/grab-host-names";
|
|
||||||
import {
|
import {
|
||||||
DSQL_DatabaseSchemaType,
|
DSQL_DatabaseSchemaType,
|
||||||
DSQL_FieldSchemaType,
|
DSQL_FieldSchemaType,
|
||||||
DSQL_TableSchemaType,
|
DSQL_TableSchemaType,
|
||||||
GetSchemaAPIParam,
|
GetSchemaAPIParam,
|
||||||
GetSchemaRequestQuery,
|
GetSchemaRequestQuery,
|
||||||
} from "../package-shared/types";
|
} from "../types";
|
||||||
|
|
||||||
type GetSchemaReturn = {
|
type GetSchemaReturn = {
|
||||||
success: boolean;
|
success: boolean;
|
@ -1,17 +1,17 @@
|
|||||||
import https from "node:https";
|
import https from "node:https";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import grabHostNames from "../package-shared/utils/grab-host-names";
|
import grabHostNames from "../utils/grab-host-names";
|
||||||
import apiGet from "../package-shared/functions/api/query/get";
|
import apiGet from "../functions/api/query/get";
|
||||||
import serializeQuery from "../package-shared/utils/serialize-query";
|
import serializeQuery from "../utils/serialize-query";
|
||||||
import {
|
import {
|
||||||
ApiGetQueryObject,
|
ApiGetQueryObject,
|
||||||
DSQL_DatabaseSchemaType,
|
DSQL_DatabaseSchemaType,
|
||||||
GetReqQueryObject,
|
GetReqQueryObject,
|
||||||
GetReturn,
|
GetReturn,
|
||||||
ServerQueryParam,
|
ServerQueryParam,
|
||||||
} from "../package-shared/types";
|
} from "../types";
|
||||||
import apiGetGrabQueryAndValues from "../package-shared/utils/grab-query-and-values";
|
import apiGetGrabQueryAndValues from "../utils/grab-query-and-values";
|
||||||
|
|
||||||
type Param<T extends { [k: string]: any } = { [k: string]: any }> = {
|
type Param<T extends { [k: string]: any } = { [k: string]: any }> = {
|
||||||
key?: string;
|
key?: string;
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import grabHostNames from "../package-shared/utils/grab-host-names";
|
import grabHostNames from "../utils/grab-host-names";
|
||||||
import apiPost from "../package-shared/functions/api/query/post";
|
import apiPost from "../functions/api/query/post";
|
||||||
import { PostDataPayload, PostReturn } from "../package-shared/types";
|
import { PostDataPayload, PostReturn } from "../types";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
@ -44,10 +44,8 @@ export default async function post({
|
|||||||
DSQL_DB_NAME?.match(/./) &&
|
DSQL_DB_NAME?.match(/./) &&
|
||||||
global.DSQL_USE_LOCAL
|
global.DSQL_USE_LOCAL
|
||||||
) {
|
) {
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
/** @type {import("../types").DSQL_DatabaseSchemaType | undefined} */
|
||||||
let dbSchema:
|
let dbSchema: import("../types").DSQL_DatabaseSchemaType | undefined;
|
||||||
| import("../package-shared/types").DSQL_DatabaseSchemaType
|
|
||||||
| undefined;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localDbSchemaPath = path.resolve(
|
const localDbSchemaPath = path.resolve(
|
@ -1,4 +1,4 @@
|
|||||||
import grabHostNames from "../package-shared/utils/grab-host-names";
|
import grabHostNames from "../utils/grab-host-names";
|
||||||
|
|
||||||
interface Return {
|
interface Return {
|
||||||
success: boolean;
|
success: boolean;
|
@ -1,6 +1,6 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
import grabHostNames from "../package-shared/utils/grab-host-names";
|
import grabHostNames from "../utils/grab-host-names";
|
||||||
|
|
||||||
interface FunctionReturn {
|
interface FunctionReturn {
|
||||||
success: boolean;
|
success: boolean;
|
@ -1,11 +1,8 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import grabHostNames from "../package-shared/utils/grab-host-names";
|
import grabHostNames from "../../utils/grab-host-names";
|
||||||
import apiCreateUser from "../package-shared/functions/api/users/api-create-user";
|
import apiCreateUser from "../../functions/api/users/api-create-user";
|
||||||
import {
|
import { AddUserFunctionReturn, UserDataPayload } from "../../types";
|
||||||
AddUserFunctionReturn,
|
|
||||||
UserDataPayload,
|
|
||||||
} from "../package-shared/types";
|
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
@ -51,10 +48,8 @@ export default async function addUser({
|
|||||||
DSQL_DB_NAME?.match(/./) &&
|
DSQL_DB_NAME?.match(/./) &&
|
||||||
global.DSQL_USE_LOCAL
|
global.DSQL_USE_LOCAL
|
||||||
) {
|
) {
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
|
||||||
let dbSchema:
|
let dbSchema: import("../../types").DSQL_DatabaseSchemaType | undefined;
|
||||||
| import("../package-shared/types").DSQL_DatabaseSchemaType
|
|
||||||
| undefined;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localDbSchemaPath = path.resolve(
|
const localDbSchemaPath = path.resolve(
|
@ -1,8 +1,8 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import grabHostNames from "../package-shared/utils/grab-host-names";
|
import grabHostNames from "../../utils/grab-host-names";
|
||||||
import apiDeleteUser from "../package-shared/functions/api/users/api-delete-user";
|
import apiDeleteUser from "../../functions/api/users/api-delete-user";
|
||||||
import { UpdateUserFunctionReturn } from "../package-shared/types";
|
import { UpdateUserFunctionReturn } from "../../types";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
@ -38,10 +38,8 @@ export default async function deleteUser({
|
|||||||
DSQL_DB_NAME?.match(/./) &&
|
DSQL_DB_NAME?.match(/./) &&
|
||||||
global.DSQL_USE_LOCAL
|
global.DSQL_USE_LOCAL
|
||||||
) {
|
) {
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
|
||||||
let dbSchema:
|
let dbSchema: import("../../types").DSQL_DatabaseSchemaType | undefined;
|
||||||
| import("../package-shared/types").DSQL_DatabaseSchemaType
|
|
||||||
| undefined;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localDbSchemaPath = path.resolve(
|
const localDbSchemaPath = path.resolve(
|
@ -1,7 +1,7 @@
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import decrypt from "../package-shared/functions/dsql/decrypt";
|
import decrypt from "../../functions/dsql/decrypt";
|
||||||
import getAuthCookieNames from "../package-shared/functions/backend/cookies/get-auth-cookie-names";
|
import getAuthCookieNames from "../../functions/backend/cookies/get-auth-cookie-names";
|
||||||
import parseCookies from "../package-shared/utils/backend/parseCookies";
|
import parseCookies from "../../utils/backend/parseCookies";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
request?: http.IncomingMessage;
|
request?: http.IncomingMessage;
|
@ -1,8 +1,8 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import grabHostNames from "../package-shared/utils/grab-host-names";
|
import grabHostNames from "../../utils/grab-host-names";
|
||||||
import apiGetUser from "../package-shared/functions/api/users/api-get-user";
|
import apiGetUser from "../../functions/api/users/api-get-user";
|
||||||
import { GetUserFunctionReturn } from "../package-shared/types";
|
import { GetUserFunctionReturn } from "../../types";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
key: string;
|
key: string;
|
||||||
@ -69,10 +69,8 @@ export default async function getUser({
|
|||||||
DSQL_DB_NAME?.match(/./) &&
|
DSQL_DB_NAME?.match(/./) &&
|
||||||
global.DSQL_USE_LOCAL
|
global.DSQL_USE_LOCAL
|
||||||
) {
|
) {
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
|
||||||
let dbSchema:
|
let dbSchema: import("../../types").DSQL_DatabaseSchemaType | undefined;
|
||||||
| import("../package-shared/types").DSQL_DatabaseSchemaType
|
|
||||||
| undefined;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localDbSchemaPath = path.resolve(
|
const localDbSchemaPath = path.resolve(
|
@ -1,16 +1,16 @@
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import encrypt from "../package-shared/functions/dsql/encrypt";
|
import encrypt from "../../functions/dsql/encrypt";
|
||||||
import grabHostNames from "../package-shared/utils/grab-host-names";
|
import grabHostNames from "../../utils/grab-host-names";
|
||||||
import apiLoginUser from "../package-shared/functions/api/users/api-login";
|
import apiLoginUser from "../../functions/api/users/api-login";
|
||||||
import getAuthCookieNames from "../package-shared/functions/backend/cookies/get-auth-cookie-names";
|
import getAuthCookieNames from "../../functions/backend/cookies/get-auth-cookie-names";
|
||||||
import { writeAuthFile } from "../package-shared/functions/backend/auth/write-auth-files";
|
import { writeAuthFile } from "../../functions/backend/auth/write-auth-files";
|
||||||
import {
|
import {
|
||||||
APILoginFunctionReturn,
|
APILoginFunctionReturn,
|
||||||
DSQL_DatabaseSchemaType,
|
DSQL_DatabaseSchemaType,
|
||||||
PackageUserLoginRequestBody,
|
PackageUserLoginRequestBody,
|
||||||
} from "../package-shared/types";
|
} from "../../types";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
@ -107,11 +107,10 @@ export default async function loginUser({
|
|||||||
* Initialize HTTP response variable
|
* Initialize HTTP response variable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @type {import("../package-shared/types").APILoginFunctionReturn} */
|
/** @type {import("../../types").APILoginFunctionReturn} */
|
||||||
let httpResponse: import("../package-shared/types").APILoginFunctionReturn =
|
let httpResponse: import("../../types").APILoginFunctionReturn = {
|
||||||
{
|
success: false,
|
||||||
success: false,
|
};
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for local DB settings
|
* Check for local DB settings
|
@ -1,11 +1,11 @@
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import getAuthCookieNames from "../package-shared/functions/backend/cookies/get-auth-cookie-names";
|
import getAuthCookieNames from "../../functions/backend/cookies/get-auth-cookie-names";
|
||||||
import decrypt from "../package-shared/functions/dsql/decrypt";
|
import decrypt from "../../functions/dsql/decrypt";
|
||||||
import EJSON from "../package-shared/utils/ejson";
|
import EJSON from "../../utils/ejson";
|
||||||
import { deleteAuthFile } from "../package-shared/functions/backend/auth/write-auth-files";
|
import { deleteAuthFile } from "../../functions/backend/auth/write-auth-files";
|
||||||
import parseCookies from "../package-shared/utils/backend/parseCookies";
|
import parseCookies from "../../utils/backend/parseCookies";
|
||||||
import { DATASQUIREL_LoggedInUser } from "../package-shared/types";
|
import { DATASQUIREL_LoggedInUser } from "../../types";
|
||||||
import grabHostNames from "../package-shared/utils/grab-host-names";
|
import grabHostNames from "../../utils/grab-host-names";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
encryptedUserString?: string;
|
encryptedUserString?: string;
|
@ -2,17 +2,17 @@ import http from "http";
|
|||||||
import https from "https";
|
import https from "https";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import encrypt from "../package-shared/functions/dsql/encrypt";
|
import encrypt from "../../functions/dsql/encrypt";
|
||||||
|
|
||||||
import userAuth from "./user-auth";
|
import userAuth from "./user-auth";
|
||||||
import grabHostNames from "../package-shared/utils/grab-host-names";
|
import grabHostNames from "../../utils/grab-host-names";
|
||||||
import apiReauthUser from "../package-shared/functions/api/users/api-reauth-user";
|
import apiReauthUser from "../../functions/api/users/api-reauth-user";
|
||||||
import {
|
import {
|
||||||
writeAuthFile,
|
writeAuthFile,
|
||||||
deleteAuthFile,
|
deleteAuthFile,
|
||||||
} from "../package-shared/functions/backend/auth/write-auth-files";
|
} from "../../functions/backend/auth/write-auth-files";
|
||||||
import getAuthCookieNames from "../package-shared/functions/backend/cookies/get-auth-cookie-names";
|
import getAuthCookieNames from "../../functions/backend/cookies/get-auth-cookie-names";
|
||||||
import { APILoginFunctionReturn } from "../package-shared/types";
|
import { APILoginFunctionReturn } from "../../types";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
@ -92,10 +92,8 @@ export default async function reauthUser({
|
|||||||
DSQL_DB_NAME?.match(/./) &&
|
DSQL_DB_NAME?.match(/./) &&
|
||||||
global.DSQL_USE_LOCAL
|
global.DSQL_USE_LOCAL
|
||||||
) {
|
) {
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
|
||||||
let dbSchema:
|
let dbSchema: import("../../types").DSQL_DatabaseSchemaType | undefined;
|
||||||
| import("../package-shared/types").DSQL_DatabaseSchemaType
|
|
||||||
| undefined;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localDbSchemaPath = path.resolve(
|
const localDbSchemaPath = path.resolve(
|
@ -1,9 +1,9 @@
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import grabHostNames from "../package-shared/utils/grab-host-names";
|
import grabHostNames from "../../utils/grab-host-names";
|
||||||
import apiSendEmailCode from "../package-shared/functions/api/users/api-send-email-code";
|
import apiSendEmailCode from "../../functions/api/users/api-send-email-code";
|
||||||
import { SendOneTimeCodeEmailResponse } from "../package-shared/types";
|
import { SendOneTimeCodeEmailResponse } from "../../types";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
@ -17,7 +17,7 @@ type Param = {
|
|||||||
mail_port?: number;
|
mail_port?: number;
|
||||||
sender?: string;
|
sender?: string;
|
||||||
user_id?: boolean;
|
user_id?: boolean;
|
||||||
extraCookies?: import("../package-shared/types").CookieObject[];
|
extraCookies?: import("../../types").CookieObject[];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,10 +62,8 @@ export default async function sendEmailCode({
|
|||||||
DSQL_DB_NAME?.match(/./) &&
|
DSQL_DB_NAME?.match(/./) &&
|
||||||
global.DSQL_USE_LOCAL
|
global.DSQL_USE_LOCAL
|
||||||
) {
|
) {
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
|
||||||
let dbSchema:
|
let dbSchema: import("../../types").DSQL_DatabaseSchemaType | undefined;
|
||||||
| import("../package-shared/types").DSQL_DatabaseSchemaType
|
|
||||||
| undefined;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localDbSchemaPath = path.resolve(
|
const localDbSchemaPath = path.resolve(
|
||||||
@ -94,9 +92,9 @@ export default async function sendEmailCode({
|
|||||||
*
|
*
|
||||||
* @description make a request to datasquirel.com
|
* @description make a request to datasquirel.com
|
||||||
*
|
*
|
||||||
* @type {import("../package-shared/types").SendOneTimeCodeEmailResponse}
|
* @type {import("../../types").SendOneTimeCodeEmailResponse}
|
||||||
*/
|
*/
|
||||||
const httpResponse: import("../package-shared/types").SendOneTimeCodeEmailResponse =
|
const httpResponse: import("../../types").SendOneTimeCodeEmailResponse =
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
const reqPayload = JSON.stringify({
|
const reqPayload = JSON.stringify({
|
||||||
email,
|
email,
|
@ -1,9 +1,9 @@
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import encrypt from "../../package-shared/functions/dsql/encrypt";
|
import encrypt from "../../../functions/dsql/encrypt";
|
||||||
import grabHostNames from "../../package-shared/utils/grab-host-names";
|
import grabHostNames from "../../../utils/grab-host-names";
|
||||||
import apiGithubLogin from "../../package-shared/functions/api/users/social/api-github-login";
|
import apiGithubLogin from "../../../functions/api/users/social/api-github-login";
|
||||||
|
|
||||||
interface FunctionReturn {
|
interface FunctionReturn {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
@ -108,9 +108,9 @@ export default async function githubAuth({
|
|||||||
DSQL_DB_PASSWORD?.match(/./) &&
|
DSQL_DB_PASSWORD?.match(/./) &&
|
||||||
DSQL_DB_NAME?.match(/./)
|
DSQL_DB_NAME?.match(/./)
|
||||||
) {
|
) {
|
||||||
/** @type {import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined | undefined} */
|
/** @type {import("../../../types").DSQL_DatabaseSchemaType | undefined | undefined} */
|
||||||
let dbSchema:
|
let dbSchema:
|
||||||
| import("../../package-shared/types").DSQL_DatabaseSchemaType
|
| import("../../../types").DSQL_DatabaseSchemaType
|
||||||
| undefined
|
| undefined
|
||||||
| undefined;
|
| undefined;
|
||||||
|
|
@ -1,10 +1,10 @@
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import encrypt from "../../package-shared/functions/dsql/encrypt";
|
import encrypt from "../../../functions/dsql/encrypt";
|
||||||
import grabHostNames from "../../package-shared/utils/grab-host-names";
|
import grabHostNames from "../../../utils/grab-host-names";
|
||||||
import apiGoogleLogin from "../../package-shared/functions/api/users/social/api-google-login";
|
import apiGoogleLogin from "../../../functions/api/users/social/api-google-login";
|
||||||
import getAuthCookieNames from "../../package-shared/functions/backend/cookies/get-auth-cookie-names";
|
import getAuthCookieNames from "../../../functions/backend/cookies/get-auth-cookie-names";
|
||||||
import { writeAuthFile } from "../../package-shared/functions/backend/auth/write-auth-files";
|
import { writeAuthFile } from "../../../functions/backend/auth/write-auth-files";
|
||||||
import { APILoginFunctionReturn } from "../../package-shared/types";
|
import { APILoginFunctionReturn } from "../../../types";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
@ -111,7 +111,7 @@ export default async function googleAuth({
|
|||||||
* Make https request
|
* Make https request
|
||||||
*
|
*
|
||||||
* @description make a request to datasquirel.com
|
* @description make a request to datasquirel.com
|
||||||
* @type {{ success: boolean, user: import("../../package-shared/types").DATASQUIREL_LoggedInUser | null, msg?: string, dsqlUserId?: number } | null } - Https response object
|
* @type {{ success: boolean, user: import("../../../types").DATASQUIREL_LoggedInUser | null, msg?: string, dsqlUserId?: number } | null } - Https response object
|
||||||
*/
|
*/
|
||||||
httpResponse = await new Promise((resolve, reject) => {
|
httpResponse = await new Promise((resolve, reject) => {
|
||||||
const reqPayload = JSON.stringify({
|
const reqPayload = JSON.stringify({
|
@ -1,8 +1,8 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import grabHostNames from "../package-shared/utils/grab-host-names";
|
import grabHostNames from "../../utils/grab-host-names";
|
||||||
import apiUpdateUser from "../package-shared/functions/api/users/api-update-user";
|
import apiUpdateUser from "../../functions/api/users/api-update-user";
|
||||||
import { UpdateUserFunctionReturn } from "../package-shared/types";
|
import { UpdateUserFunctionReturn } from "../../types";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
@ -40,10 +40,8 @@ export default async function updateUser({
|
|||||||
DSQL_DB_NAME?.match(/./) &&
|
DSQL_DB_NAME?.match(/./) &&
|
||||||
global.DSQL_USE_LOCAL
|
global.DSQL_USE_LOCAL
|
||||||
) {
|
) {
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
|
||||||
let dbSchema:
|
let dbSchema: import("../../types").DSQL_DatabaseSchemaType | undefined;
|
||||||
| import("../package-shared/types").DSQL_DatabaseSchemaType
|
|
||||||
| undefined;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localDbSchemaPath = path.resolve(
|
const localDbSchemaPath = path.resolve(
|
@ -1,11 +1,11 @@
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import decrypt from "../package-shared/functions/dsql/decrypt";
|
import decrypt from "../../functions/dsql/decrypt";
|
||||||
import getAuthCookieNames from "../package-shared/functions/backend/cookies/get-auth-cookie-names";
|
import getAuthCookieNames from "../../functions/backend/cookies/get-auth-cookie-names";
|
||||||
import { checkAuthFile } from "../package-shared/functions/backend/auth/write-auth-files";
|
import { checkAuthFile } from "../../functions/backend/auth/write-auth-files";
|
||||||
import parseCookies from "../package-shared/utils/backend/parseCookies";
|
import parseCookies from "../../utils/backend/parseCookies";
|
||||||
import { AuthenticatedUser } from "../package-shared/types";
|
import { AuthenticatedUser } from "../../types";
|
||||||
import getCsrfHeaderName from "../utils/get-csrf-header-name";
|
import getCsrfHeaderName from "../../actions/get-csrf-header-name";
|
||||||
import grabHostNames from "../package-shared/utils/grab-host-names";
|
import grabHostNames from "../../utils/grab-host-names";
|
||||||
|
|
||||||
const minuteInMilliseconds = 60000;
|
const minuteInMilliseconds = 60000;
|
||||||
const hourInMilliseconds = minuteInMilliseconds * 60;
|
const hourInMilliseconds = minuteInMilliseconds * 60;
|
||||||
@ -114,8 +114,8 @@ export default function userAuth({
|
|||||||
* @description Grab the payload
|
* @description Grab the payload
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @type {import("../package-shared/types").DATASQUIREL_LoggedInUser} */
|
/** @type {import("../../types").DATASQUIREL_LoggedInUser} */
|
||||||
let userObject: import("../package-shared/types").DATASQUIREL_LoggedInUser =
|
let userObject: import("../../types").DATASQUIREL_LoggedInUser =
|
||||||
JSON.parse(userPayloadJSON);
|
JSON.parse(userPayloadJSON);
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
@ -1,9 +1,9 @@
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import getAuthCookieNames from "../package-shared/functions/backend/cookies/get-auth-cookie-names";
|
import getAuthCookieNames from "../../functions/backend/cookies/get-auth-cookie-names";
|
||||||
import parseCookies from "../package-shared/utils/backend/parseCookies";
|
import parseCookies from "../../utils/backend/parseCookies";
|
||||||
import decrypt from "../package-shared/functions/dsql/decrypt";
|
import decrypt from "../../functions/dsql/decrypt";
|
||||||
import EJSON from "../package-shared/utils/ejson";
|
import EJSON from "../../utils/ejson";
|
||||||
import { SendOneTimeCodeEmailResponse } from "../package-shared/types";
|
import { SendOneTimeCodeEmailResponse } from "../../types";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
request?: http.IncomingMessage & { [s: string]: any };
|
request?: http.IncomingMessage & { [s: string]: any };
|
@ -1,6 +1,6 @@
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import decrypt from "../package-shared/functions/dsql/decrypt";
|
import decrypt from "../../functions/dsql/decrypt";
|
||||||
import { DATASQUIREL_LoggedInUser } from "../package-shared/types";
|
import { DATASQUIREL_LoggedInUser } from "../../types";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
token: string;
|
token: string;
|
@ -53,22 +53,40 @@
|
|||||||
"title": "TEXT",
|
"title": "TEXT",
|
||||||
"name": "TEXT",
|
"name": "TEXT",
|
||||||
"value": "0-100",
|
"value": "0-100",
|
||||||
"description": "MEDIUMTEXT is just text with max length 16,777,215",
|
"description": "MEDIUMTEXT is just text with max length 16,777,215"
|
||||||
"maxValue": 127
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "MEDIUMTEXT",
|
"title": "MEDIUMTEXT",
|
||||||
"name": "MEDIUMTEXT",
|
"name": "MEDIUMTEXT",
|
||||||
"value": "0-255",
|
"value": "0-255",
|
||||||
"description": "MEDIUMTEXT is just text with max length 16,777,215",
|
"description": "MEDIUMTEXT is just text with max length 16,777,215"
|
||||||
"maxValue": 127
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "LONGTEXT",
|
"title": "LONGTEXT",
|
||||||
"name": "LONGTEXT",
|
"name": "LONGTEXT",
|
||||||
"value": "0-255",
|
"value": "0-255",
|
||||||
"description": "LONGTEXT is just text with max length 4,294,967,295",
|
"description": "LONGTEXT is just text with max length 4,294,967,295"
|
||||||
"maxValue": 127
|
},
|
||||||
|
{
|
||||||
|
"title": "DECIMAL",
|
||||||
|
"name": "DECIMAL",
|
||||||
|
"description": "Numbers with decimals",
|
||||||
|
"integer": "1-100",
|
||||||
|
"decimals": "1-4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "FLOAT",
|
||||||
|
"name": "FLOAT",
|
||||||
|
"description": "Numbers with decimals",
|
||||||
|
"integer": "1-100",
|
||||||
|
"decimals": "1-4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "DOUBLE",
|
||||||
|
"name": "DOUBLE",
|
||||||
|
"description": "Numbers with decimals",
|
||||||
|
"integer": "1-100",
|
||||||
|
"decimals": "1-4"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "UUID",
|
"title": "UUID",
|
||||||
|
@ -34,7 +34,6 @@ export default async function apiPost({
|
|||||||
return { success: false, msg: "Wrong Input" };
|
return { success: false, msg: "Wrong Input" };
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {any} */
|
|
||||||
let results: any;
|
let results: any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,7 +32,6 @@ export default async function apiDeleteUser({
|
|||||||
|
|
||||||
const deleteUser = await deleteDbEntry({
|
const deleteUser = await deleteDbEntry({
|
||||||
dbContext: "Dsql User",
|
dbContext: "Dsql User",
|
||||||
paradigm: "Full Access",
|
|
||||||
dbFullName,
|
dbFullName,
|
||||||
tableName: "users",
|
tableName: "users",
|
||||||
identifierColumnName: "id",
|
identifierColumnName: "id",
|
||||||
|
@ -81,7 +81,6 @@ export default async function apiUpdateUser({
|
|||||||
|
|
||||||
const updateUser = await updateDbEntry({
|
const updateUser = await updateDbEntry({
|
||||||
dbContext: "Dsql User",
|
dbContext: "Dsql User",
|
||||||
paradigm: "Full Access",
|
|
||||||
dbFullName,
|
dbFullName,
|
||||||
tableName: "users",
|
tableName: "users",
|
||||||
identifierColumnName: "id",
|
identifierColumnName: "id",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import serverError from "./serverError";
|
import serverError from "./serverError";
|
||||||
import mysql from "serverless-mysql";
|
|
||||||
import grabDSQLConnection from "../../utils/grab-dsql-connection";
|
import grabDSQLConnection from "../../utils/grab-dsql-connection";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* # Main DB Handler Function
|
* # Main DB Handler Function
|
||||||
@ -37,8 +37,12 @@ export default async function dbHandler(...args: any[]) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
const tmpFolder = path.resolve(process.cwd(), "./.tmp");
|
||||||
|
if (!fs.existsSync(tmpFolder))
|
||||||
|
fs.mkdirSync(tmpFolder, { recursive: true });
|
||||||
|
|
||||||
fs.appendFileSync(
|
fs.appendFileSync(
|
||||||
"./.tmp/dbErrorLogs.txt",
|
path.resolve(tmpFolder, "./dbErrorLogs.txt"),
|
||||||
JSON.stringify(error, null, 4) + "\n" + Date() + "\n\n\n",
|
JSON.stringify(error, null, 4) + "\n" + Date() + "\n\n\n",
|
||||||
"utf8"
|
"utf8"
|
||||||
);
|
);
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
import mysql from "serverless-mysql";
|
|
||||||
import grabDbSSL from "../../utils/backend/grabDbSSL";
|
|
||||||
import grabDSQLConnection from "../../utils/grab-dsql-connection";
|
import grabDSQLConnection from "../../utils/grab-dsql-connection";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
@ -37,8 +34,12 @@ export default async function dbHandler({
|
|||||||
console.log(error);
|
console.log(error);
|
||||||
console.log(CONNECTION.config());
|
console.log(CONNECTION.config());
|
||||||
|
|
||||||
|
const tmpFolder = path.resolve(process.cwd(), "./.tmp");
|
||||||
|
if (!fs.existsSync(tmpFolder))
|
||||||
|
fs.mkdirSync(tmpFolder, { recursive: true });
|
||||||
|
|
||||||
fs.appendFileSync(
|
fs.appendFileSync(
|
||||||
path.resolve(__dirname, "../.tmp/dbErrorLogs.txt"),
|
path.resolve(tmpFolder, "./dbErrorLogs.txt"),
|
||||||
JSON.stringify(error, null, 4) + "\n" + Date() + "\n\n\n",
|
JSON.stringify(error, null, 4) + "\n" + Date() + "\n\n\n",
|
||||||
"utf8"
|
"utf8"
|
||||||
);
|
);
|
||||||
|
@ -41,7 +41,17 @@ export interface DSQL_ChildrenTablesType {
|
|||||||
tableNameFull?: string;
|
tableNameFull?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DSQL_FieldSchemaType {
|
export const TextFieldTypesArray = [
|
||||||
|
{ title: "Plain Text", value: "plain" },
|
||||||
|
{ title: "Rich Text", value: "richText" },
|
||||||
|
{ title: "JSON", value: "json" },
|
||||||
|
{ title: "YAML", value: "yaml" },
|
||||||
|
{ title: "HTML", value: "html" },
|
||||||
|
{ title: "CSS", value: "css" },
|
||||||
|
{ title: "Javascript", value: "javascript" },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export type DSQL_FieldSchemaType = {
|
||||||
fieldName?: string;
|
fieldName?: string;
|
||||||
originName?: string;
|
originName?: string;
|
||||||
updatedField?: boolean;
|
updatedField?: boolean;
|
||||||
@ -54,13 +64,6 @@ export interface DSQL_FieldSchemaType {
|
|||||||
defaultValue?: string | number;
|
defaultValue?: string | number;
|
||||||
defaultValueLiteral?: string;
|
defaultValueLiteral?: string;
|
||||||
foreignKey?: DSQL_ForeignKeyType;
|
foreignKey?: DSQL_ForeignKeyType;
|
||||||
richText?: boolean;
|
|
||||||
json?: boolean;
|
|
||||||
yaml?: boolean;
|
|
||||||
html?: boolean;
|
|
||||||
css?: boolean;
|
|
||||||
javascript?: boolean;
|
|
||||||
shell?: boolean;
|
|
||||||
newTempField?: boolean;
|
newTempField?: boolean;
|
||||||
defaultField?: boolean;
|
defaultField?: boolean;
|
||||||
plainText?: boolean;
|
plainText?: boolean;
|
||||||
@ -72,7 +75,11 @@ export interface DSQL_FieldSchemaType {
|
|||||||
onDelete?: string;
|
onDelete?: string;
|
||||||
onDeleteLiteral?: string;
|
onDeleteLiteral?: string;
|
||||||
cssFiles?: string[];
|
cssFiles?: string[];
|
||||||
}
|
integerLength?: string | number;
|
||||||
|
decimals?: string | number;
|
||||||
|
} & {
|
||||||
|
[key in (typeof TextFieldTypesArray)[number]["value"]]?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
export interface DSQL_ForeignKeyType {
|
export interface DSQL_ForeignKeyType {
|
||||||
foreignKeyName?: string;
|
foreignKeyName?: string;
|
||||||
@ -923,6 +930,7 @@ export interface MYSQL_user_database_tables_table_def {
|
|||||||
table_slug?: string;
|
table_slug?: string;
|
||||||
table_description?: string;
|
table_description?: string;
|
||||||
child_table?: number;
|
child_table?: number;
|
||||||
|
active_data?: 0 | 1;
|
||||||
child_table_parent_database?: string;
|
child_table_parent_database?: string;
|
||||||
child_table_parent_table?: string;
|
child_table_parent_table?: string;
|
||||||
date_created?: string;
|
date_created?: string;
|
||||||
|
95
package-shared/utils/data-fetching/crud.ts
Normal file
95
package-shared/utils/data-fetching/crud.ts
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
import get from "../../actions/get";
|
||||||
|
import post from "../../actions/post";
|
||||||
|
import sqlGenerator from "../../functions/dsql/sql/sql-generator";
|
||||||
|
import {
|
||||||
|
PostReturn,
|
||||||
|
ServerQueryParam,
|
||||||
|
ServerQueryQueryObject,
|
||||||
|
} from "../../types";
|
||||||
|
import numberfy from "../numberfy";
|
||||||
|
|
||||||
|
export const DsqlCrudActions = ["insert", "update", "delete", "get"] as const;
|
||||||
|
|
||||||
|
export type CrudQueryObject<T extends object = { [key: string]: any }> =
|
||||||
|
ServerQueryParam & {
|
||||||
|
query: ServerQueryQueryObject<T>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CrudParam<T extends object = { [key: string]: any }> = {
|
||||||
|
action: (typeof DsqlCrudActions)[number];
|
||||||
|
table: string;
|
||||||
|
data?: T;
|
||||||
|
targetId?: string | number;
|
||||||
|
query?: CrudQueryObject<T>;
|
||||||
|
sanitize?: (data?: T) => T;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function dsqlCrud<
|
||||||
|
T extends { [key: string]: any } = { [key: string]: any }
|
||||||
|
>({
|
||||||
|
action,
|
||||||
|
data,
|
||||||
|
table,
|
||||||
|
targetId,
|
||||||
|
query,
|
||||||
|
sanitize,
|
||||||
|
}: CrudParam<T>): Promise<
|
||||||
|
| (PostReturn & {
|
||||||
|
queryObject?: ReturnType<Awaited<typeof sqlGenerator>>;
|
||||||
|
})
|
||||||
|
| null
|
||||||
|
> {
|
||||||
|
const finalData = sanitize ? sanitize(data) : data;
|
||||||
|
const finalId = targetId;
|
||||||
|
let queryObject: ReturnType<Awaited<typeof sqlGenerator>> | undefined;
|
||||||
|
|
||||||
|
switch (action) {
|
||||||
|
case "get":
|
||||||
|
queryObject = sqlGenerator({
|
||||||
|
tableName: table,
|
||||||
|
genObject: query,
|
||||||
|
});
|
||||||
|
|
||||||
|
const GET_RES = await get({
|
||||||
|
query: queryObject?.string || "",
|
||||||
|
queryValues: queryObject?.values || [],
|
||||||
|
});
|
||||||
|
|
||||||
|
return { ...GET_RES, queryObject };
|
||||||
|
|
||||||
|
case "insert":
|
||||||
|
return await post({
|
||||||
|
query: {
|
||||||
|
action: "insert",
|
||||||
|
table,
|
||||||
|
data: finalData,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
case "update":
|
||||||
|
delete data?.id;
|
||||||
|
|
||||||
|
return await post({
|
||||||
|
query: {
|
||||||
|
action: "update",
|
||||||
|
table,
|
||||||
|
identifierColumnName: "id",
|
||||||
|
identifierValue: String(finalId),
|
||||||
|
data: finalData,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
case "delete":
|
||||||
|
return await post({
|
||||||
|
query: {
|
||||||
|
action: "delete",
|
||||||
|
table,
|
||||||
|
identifierColumnName: "id",
|
||||||
|
identifierValue: String(finalId),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
180
package-shared/utils/data-fetching/method-crud.ts
Normal file
180
package-shared/utils/data-fetching/method-crud.ts
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
import { DATASQUIREL_LoggedInUser, ServerQueryParam } from "../../types";
|
||||||
|
import EJSON from "../ejson";
|
||||||
|
import dsqlCrud from "./crud";
|
||||||
|
|
||||||
|
export const DataCrudRequestMethods = ["GET", "POST", "PUT", "DELETE"] as const;
|
||||||
|
|
||||||
|
export type APIDataCrudQuery = ServerQueryParam & {
|
||||||
|
page?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CRUDResponseObject<P extends any = any> = {
|
||||||
|
success: boolean;
|
||||||
|
payload?: P;
|
||||||
|
msg?: string;
|
||||||
|
error?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ApiDataCrudParam<
|
||||||
|
T extends { [key: string]: any } = { [key: string]: any }
|
||||||
|
> = {
|
||||||
|
method: (typeof DataCrudRequestMethods)[number];
|
||||||
|
body?: T;
|
||||||
|
query?: string | T;
|
||||||
|
tableName: string;
|
||||||
|
addUser?: {
|
||||||
|
field: string;
|
||||||
|
};
|
||||||
|
user?: DATASQUIREL_LoggedInUser;
|
||||||
|
extraData?: T;
|
||||||
|
transform?: ({
|
||||||
|
data,
|
||||||
|
existingData,
|
||||||
|
user,
|
||||||
|
}: {
|
||||||
|
user?: DATASQUIREL_LoggedInUser;
|
||||||
|
data: T;
|
||||||
|
existingData?: T;
|
||||||
|
reqMethod: (typeof DataCrudRequestMethods)[number];
|
||||||
|
}) => Promise<T>;
|
||||||
|
existingData?: T;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function dsqlMethodCrud<
|
||||||
|
T extends { [key: string]: any } = { [key: string]: any },
|
||||||
|
P extends { [key: string]: any } = { [key: string]: any }
|
||||||
|
>({
|
||||||
|
method,
|
||||||
|
tableName,
|
||||||
|
addUser,
|
||||||
|
user,
|
||||||
|
extraData,
|
||||||
|
transform,
|
||||||
|
existingData,
|
||||||
|
body,
|
||||||
|
query,
|
||||||
|
}: ApiDataCrudParam<T>): Promise<CRUDResponseObject<P>> {
|
||||||
|
let result: CRUDResponseObject = {
|
||||||
|
success: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
let finalBody = body as any;
|
||||||
|
let finalQuery = query as any;
|
||||||
|
|
||||||
|
Object.keys(finalQuery).forEach((key) => {
|
||||||
|
const value = finalQuery[key];
|
||||||
|
if (typeof value == "string" && value.match(/^\{|^\[/)) {
|
||||||
|
finalQuery[key] = EJSON.stringify(value);
|
||||||
|
}
|
||||||
|
if (value == "true") {
|
||||||
|
finalQuery[key] = true;
|
||||||
|
}
|
||||||
|
if (value == "false") {
|
||||||
|
finalQuery[key] = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const LIMIT = finalQuery.limit || 10;
|
||||||
|
const PAGE = finalQuery.page || 1;
|
||||||
|
const OFFSET = (PAGE - 1) * LIMIT;
|
||||||
|
|
||||||
|
let finalData = {
|
||||||
|
...finalBody.data,
|
||||||
|
...extraData,
|
||||||
|
} as T;
|
||||||
|
|
||||||
|
if (user && addUser) {
|
||||||
|
finalData = {
|
||||||
|
...finalData,
|
||||||
|
[addUser.field]: String(user.id),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transform) {
|
||||||
|
finalData = await transform({
|
||||||
|
data: finalData,
|
||||||
|
existingData: existingData,
|
||||||
|
user,
|
||||||
|
reqMethod: method as (typeof DataCrudRequestMethods)[number],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (method) {
|
||||||
|
case "GET":
|
||||||
|
const GET_RESULT = await dsqlCrud({
|
||||||
|
action: "get",
|
||||||
|
table: tableName,
|
||||||
|
query: {
|
||||||
|
...finalQuery,
|
||||||
|
query: {
|
||||||
|
...finalQuery.query,
|
||||||
|
user_id: user
|
||||||
|
? {
|
||||||
|
value: String(user.id),
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
limit: LIMIT,
|
||||||
|
offset: OFFSET || undefined,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
result = {
|
||||||
|
success: Boolean(GET_RESULT?.success),
|
||||||
|
payload: GET_RESULT?.payload,
|
||||||
|
msg: GET_RESULT?.msg,
|
||||||
|
error: GET_RESULT?.error,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "POST":
|
||||||
|
const POST_RESULT = await dsqlCrud({
|
||||||
|
action: "insert",
|
||||||
|
table: tableName,
|
||||||
|
data: finalData,
|
||||||
|
});
|
||||||
|
result = {
|
||||||
|
success: Boolean(POST_RESULT?.success),
|
||||||
|
payload: POST_RESULT?.payload,
|
||||||
|
msg: POST_RESULT?.msg,
|
||||||
|
error: POST_RESULT?.error,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "PUT":
|
||||||
|
const PUT_RESULT = await dsqlCrud({
|
||||||
|
action: "update",
|
||||||
|
table: tableName,
|
||||||
|
data: finalData,
|
||||||
|
targetId: finalBody.data.id,
|
||||||
|
});
|
||||||
|
result = {
|
||||||
|
success: Boolean(PUT_RESULT?.success),
|
||||||
|
payload: PUT_RESULT?.payload,
|
||||||
|
msg: PUT_RESULT?.msg,
|
||||||
|
error: PUT_RESULT?.error,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case "DELETE":
|
||||||
|
const DELETE_RESULT = await dsqlCrud({
|
||||||
|
action: "delete",
|
||||||
|
table: tableName,
|
||||||
|
targetId: finalBody.data.id,
|
||||||
|
});
|
||||||
|
result = {
|
||||||
|
success: Boolean(DELETE_RESULT?.success),
|
||||||
|
payload: DELETE_RESULT?.payload,
|
||||||
|
msg: DELETE_RESULT?.msg,
|
||||||
|
error: DELETE_RESULT?.error,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "3.8.4",
|
"version": "3.8.5",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
@ -6,6 +6,7 @@ else
|
|||||||
msg="$1"
|
msg="$1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
rm -rf dist
|
||||||
tsc
|
tsc
|
||||||
git add .
|
git add .
|
||||||
git commit -m "$msg"
|
git commit -m "$msg"
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
"package-shared/functions/dsql",
|
"package-shared/functions/dsql",
|
||||||
"types",
|
"types",
|
||||||
"users",
|
"users",
|
||||||
"utils",
|
"actions",
|
||||||
"package-shared",
|
"package-shared",
|
||||||
"client"
|
"client"
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user