This commit is contained in:
Benjamin Toby
2025-06-01 07:05:45 +01:00
parent b3353b8b70
commit a68d1c1d3f
12 changed files with 350 additions and 230 deletions
@@ -144,7 +144,7 @@ export default async function apiCreateUser({
});
if (addUser?.insertId) {
const newlyAddedUserQuery = `SELECT id,first_name,last_name,email,username,phone,image,image_thumbnail,city,state,country,zip_code,address,verification_status,more_user_data FROM ${dbFullName}.users WHERE id='${addUser.insertId}'`;
const newlyAddedUserQuery = `SELECT id,uuid,first_name,last_name,email,username,image,image_thumbnail,verification_status FROM ${dbFullName}.users WHERE id='${addUser.insertId}'`;
const newlyAddedUser = await varDatabaseDbHandler({
queryString: newlyAddedUserQuery,
@@ -1,115 +0,0 @@
import http from "node:http";
import https from "node:https";
import querystring from "querystring";
import serializeQuery from "../../utils/serialize-query";
import _ from "lodash";
import { HttpFunctionResponse, HttpRequestParams } from "../../types";
/**
* # Generate a http Request
*/
export default function httpRequest<
ReqObj extends { [k: string]: any } = { [k: string]: any },
ResObj extends { [k: string]: any } = { [k: string]: any }
>(params: HttpRequestParams<ReqObj>): Promise<HttpFunctionResponse<ResObj>> {
return new Promise((resolve, reject) => {
const isUrlEncodedFormBody = params.urlEncodedFormBody;
const reqPayloadString = params.body
? isUrlEncodedFormBody
? querystring.stringify(params.body)
: JSON.stringify(params.body).replace(/\n|\r|\n\r/gm, "")
: undefined;
const reqQueryString = params.query
? serializeQuery(params.query)
: undefined;
const paramScheme = params.scheme;
const finalScheme = paramScheme == "http" ? http : https;
const finalPath = params.path
? params.path + (reqQueryString ? reqQueryString : "")
: undefined;
delete params.body;
delete params.scheme;
delete params.query;
delete params.urlEncodedFormBody;
let finalHeaders: http.OutgoingHttpHeaders = {
"Content-Type": isUrlEncodedFormBody
? "application/x-www-form-urlencoded"
: "application/json",
};
if (reqPayloadString) {
finalHeaders["Content-Length"] =
Buffer.from(reqPayloadString).length;
}
finalHeaders = { ...finalHeaders, ...params.headers };
/** @type {import("node:https").RequestOptions} */
const requestOptions: import("node:https").RequestOptions = {
...params,
headers: finalHeaders,
port: paramScheme == "https" ? 443 : params.port,
path: finalPath,
};
const httpsRequest = finalScheme.request(
requestOptions,
/**
* Callback Function
*
* @description https request callback
*/
(response) => {
var str = "";
response.on("data", function (chunk) {
str += chunk;
});
response.on("end", function () {
const data = (() => {
try {
const jsonObj: { [k: string]: any } =
JSON.parse(str);
return jsonObj;
} catch (error) {
return undefined;
}
})() as any;
resolve({
status: response.statusCode || 404,
data,
str,
requestedPath: finalPath,
});
});
response.on("error", (err) => {
resolve({
status: response.statusCode || 404,
str,
error: err.message,
requestedPath: finalPath,
});
});
}
);
if (reqPayloadString) {
httpsRequest.write(reqPayloadString);
}
httpsRequest.on("error", (error) => {
console.log("HTTPS request ERROR =>", error);
});
httpsRequest.end();
});
}
+179 -2
View File
@@ -1,5 +1,5 @@
import type { IncomingMessage, ServerResponse } from "http";
import type { RequestOptions } from "https";
import { DSQL_DATASQUIREL_PROCESS_QUEUE } from "@/package-shared/types/dsql";
import { Editor } from "tinymce";
export type DSQL_DatabaseFullName = string;
@@ -358,7 +358,7 @@ export interface PostInsertReturn {
changedRows: number;
}
export type UserType = DATASQUIREL_LoggedInUser;
export type UserType = DATASQUIREL_LoggedInUser & {};
export interface ApiKeyDef {
name: string;
@@ -1595,3 +1595,180 @@ export interface MariaDBUser {
default_role: string;
max_statement_time: number;
}
export type PagePropsType = {
user?: UserType | null;
pageUrl?: string | null;
query?: any;
};
export type APIResponseObject<T extends any = any> = {
success: boolean;
payload?: T;
error?: any;
msg?: string;
queryRes?: any;
status?: number;
};
export const UserTypes = ["su", "admin"] as const;
export const SignUpParadigms = [
{
name: "email",
},
{
name: "google",
},
] as const;
export const QueueJobTypes = ["dummy", "import-database"] as const;
export const WebSocketEvents = [
/**
* # Client Events
* @description Events sent from Client to Server
*/
"client:check-queue",
"client:dev:queue",
"client:delete-queue",
"client:pty-shell",
/**
* # Server Events
* @description Events sent from Server to Client
*/
"server:error",
"server:message",
"server:ready",
"server:success",
"server:update",
"server:queue",
"server:dev:queue",
"server:queue-deleted",
"server:pty-shell",
] as const;
export type WebSocketDataType = {
event: (typeof WebSocketEvents)[number];
data?: {
queue?: DSQL_DATASQUIREL_PROCESS_QUEUE;
};
error?: string;
message?: string;
};
export const DatasquirelWindowEvents = [
"queue-started",
"queue-complete",
"queue-running",
] as const;
export type DatasquirelWindowEventPayloadType = {
event: (typeof DatasquirelWindowEvents)[number];
data?: {
queue?: DSQL_DATASQUIREL_PROCESS_QUEUE;
};
error?: string;
message?: string;
};
/**
* # Docker Compose Types
*/
export type DockerCompose = {
services: DockerComposeServices;
networks: DockerComposeNetworks;
name: string;
};
export const DockerComposeServices = [
"setup",
"cron",
"reverse-proxy",
"webapp",
"websocket",
"static",
"db",
"db-load-balancer",
"post-db-setup",
] as const;
export type DockerComposeServices = {
[key in (typeof DockerComposeServices)[number]]: DockerComposeServiceWithBuildObject;
};
export type DockerComposeNetworks = {
datasquirel: {
driver: "bridge";
ipam: {
config: DockerComposeNetworkConfigObject[];
};
};
};
export type DockerComposeNetworkConfigObject = {
subnet: string;
gateway: string;
};
export type DockerComposeServiceWithBuildObject = {
build: DockerComposeServicesBuildObject;
env_file: string;
container_name: string;
hostname: string;
volumes: string[];
environment: string[];
networks?: DockerComposeServiceNetworkObject;
restart?: string;
depends_on?: {
[k: string]: {
condition: string;
};
};
user?: string;
};
export type DockerComposeServiceWithImage = Omit<
DockerComposeServiceWithBuildObject,
"build"
> & {
image: string;
};
export type DockerComposeServicesBuildObject = {
context: string;
dockerfile: string;
};
export type DockerComposeServiceNetworkObject = {
datasquirel: {
ipv4_address: string;
};
};
/**
* # Site Setup Types
*/
export type SiteSetup = {
docker: {
network: {
subnet: string;
};
};
};
export type AppRefObject = {};
export type DsqlAppData = {
DSQL_REMOTE_SQL_HOST?: string;
DSQL_SU_USER_ID?: string;
DSQL_HOST_ENV?: string;
DSQL_HOST?: string;
DSQL_STATIC_HOST?: string;
DSQL_GOOGLE_CLIENT_ID?: string;
DSQL_TINY_MCE_API_KEY?: string;
DSQL_WEBSOCKET_URL?: string;
DSQL_FACEBOOK_APP_ID?: string;
DSQL_GITHUB_ID?: string;
};
@@ -68,7 +68,7 @@ export default function grabDirNames(param?: Param) {
const dbNginxLoadBalancerConfigFile = path.join(
appDir,
"docker/mariadb/load-balancer/config/template/nginx.conf"
"docker/services/mariadb/load-balancer/config/template/nginx.conf"
);
const dockerComposeFile = path.join(appDir, "docker-compose.yml");