Compare commits
284
Commits
a3561da53d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d0ee2e688 | ||
|
|
0e44676226 | ||
|
|
a68e42beab | ||
|
|
3d4ee58d01 | ||
|
|
ac489ce443 | ||
|
|
0da68e30b8 | ||
|
|
0a1993494d | ||
|
|
194e4dcad0 | ||
|
|
70908a2019 | ||
|
|
cf2cbe452b | ||
|
|
16cc7bede5 | ||
|
|
5847bd34ab | ||
|
|
af2749a922 | ||
|
|
fd83f6ab1b | ||
|
|
2741214db8 | ||
|
|
35ad577ead | ||
|
|
e1ca42137a | ||
|
|
a90706de5d | ||
|
|
80df059135 | ||
|
|
09fff9881e | ||
|
|
b25316485b | ||
|
|
7345010391 | ||
|
|
42caaecb18 | ||
|
|
b6fa30a3f2 | ||
|
|
7169e467cc | ||
|
|
cda056311b | ||
|
|
acccc26c38 | ||
|
|
664cb3a3d8 | ||
|
|
b50e100732 | ||
|
|
0a03405598 | ||
|
|
18a9409aec | ||
|
|
1c20286c8c | ||
|
|
a915be704b | ||
|
|
a10524da95 | ||
|
|
ea40a1a8c2 | ||
|
|
9402c859f7 | ||
|
|
58984214fc | ||
|
|
8bcb35a8f0 | ||
|
|
18e29fa413 | ||
|
|
def2f2f057 | ||
|
|
290dfe303c | ||
|
|
f0d44092e5 | ||
|
|
a8128c23ab | ||
|
|
b07153673e | ||
|
|
bd507eb9ea | ||
|
|
d109388af5 | ||
|
|
d985503688 | ||
|
|
8277ff3e41 | ||
|
|
b8e5d45762 | ||
|
|
515db80a79 | ||
|
|
05733b4ade | ||
|
|
f7a2d6e03a | ||
|
|
276a0db83b | ||
|
|
637ca6ea54 | ||
|
|
19eb7bf222 | ||
|
|
863906f3e6 | ||
|
|
b10bcb4d46 | ||
|
|
83eb4b976f | ||
|
|
d9f0f74481 | ||
|
|
49276d4cb3 | ||
|
|
0dc8f3c787 | ||
|
|
27887ded41 | ||
|
|
f1e0aa9fc4 | ||
|
|
5caa604b8f | ||
|
|
f95cf21ffd | ||
|
|
0e5b5fea6e | ||
|
|
d7cef41552 | ||
|
|
b02399c64d | ||
|
|
98aaa94b80 | ||
|
|
cfcd08680f | ||
|
|
0d9f313dc0 | ||
|
|
14ea760373 | ||
|
|
c88fb13375 | ||
|
|
f91aff421c | ||
|
|
57f06a631f | ||
|
|
9ab5543c5c | ||
|
|
4a6da06580 | ||
|
|
c6d1ac7793 | ||
|
|
77fca5e47c | ||
|
|
3346486b6b | ||
|
|
672e011cd8 | ||
|
|
7959014721 | ||
|
|
0858b18344 | ||
|
|
8eebe3215a | ||
|
|
5fcfc4dc2c | ||
|
|
22434ee656 | ||
|
|
d2fe98b4b8 | ||
|
|
57e67f5c51 | ||
|
|
957709f79d | ||
|
|
66f207416d | ||
|
|
90c36f2345 | ||
|
|
e6b4b09277 | ||
|
|
b81948d2c1 | ||
|
|
557bbb30bd | ||
|
|
0fcd92ab3e | ||
|
|
d646b4e93a | ||
|
|
c5954f6ba2 | ||
|
|
5c3324105e | ||
|
|
c34d256891 | ||
|
|
97f480c208 | ||
|
|
1086b35b9d | ||
|
|
2336b71703 | ||
|
|
82bea3efd0 | ||
|
|
e8269a8b5e | ||
|
|
56198e8ac5 | ||
|
|
700a704abd | ||
|
|
a1e56bb1b0 | ||
|
|
689f885d9d | ||
|
|
eb98148533 | ||
|
|
43a741f9ac | ||
|
|
ab13c68c8e | ||
|
|
71a8431de5 | ||
|
|
9ca64cf25e | ||
|
|
1f375fe94f | ||
|
|
8ac8b8eb51 | ||
|
|
a429436939 | ||
|
|
3437be2c08 | ||
|
|
3cf76f5155 | ||
|
|
5a4d4448a5 | ||
|
|
05d6d13ef0 | ||
|
|
20a390e4a8 | ||
|
|
a53b6e6974 | ||
|
|
9ce8bf2c90 | ||
|
|
c7e02a3061 | ||
|
|
caa26217a0 | ||
|
|
5cb8a067c0 | ||
|
|
166bde51c7 | ||
|
|
f9725a1d6f | ||
|
|
5ab079f687 | ||
|
|
a131764e1e | ||
|
|
c593404263 | ||
|
|
da87fe6491 | ||
|
|
e8787a2ef8 | ||
|
|
03abe33d22 | ||
|
|
382da38bb0 | ||
|
|
c37d105dee | ||
|
|
ccb5605b58 | ||
|
|
6acf0f2cd6 | ||
|
|
b38ddc9f21 | ||
|
|
3597b11342 | ||
|
|
fcc668d3a1 | ||
|
|
ad904622eb | ||
|
|
d80d876ac1 | ||
|
|
23d1b28354 | ||
|
|
56a58c225e | ||
|
|
a2d8fba8d7 | ||
|
|
728183b827 | ||
|
|
4f4eb44a98 | ||
|
|
321683e7c8 | ||
|
|
3730e4722e | ||
|
|
7e8bb37c09 | ||
|
|
6e334c2525 | ||
|
|
881128fcea | ||
|
|
761348de08 | ||
|
|
1364074c2c | ||
|
|
4a083fe73b | ||
|
|
8639c9f34d | ||
|
|
cd96c11817 | ||
|
|
9b7c98cff6 | ||
|
|
b28b05956b | ||
|
|
a68d1c1d3f | ||
|
|
b3353b8b70 | ||
|
|
2618d472dc | ||
|
|
0fc2c7fb3e | ||
|
|
4adb5af430 | ||
|
|
04a56b5bc3 | ||
|
|
a90989cea7 | ||
|
|
674af34355 | ||
|
|
07c2186b98 | ||
|
|
fe2b34d0ee | ||
|
|
181501296a | ||
|
|
cd4a2f7902 | ||
|
|
cc29a3c107 | ||
|
|
8d855ce94d | ||
|
|
9ea903a401 | ||
|
|
e4c6c995ef | ||
|
|
c71c1c29ca | ||
|
|
e7b7cf0314 | ||
|
|
daad62141e | ||
|
|
22f4372cbf | ||
|
|
18cbf9b2f4 | ||
|
|
2ad17ae682 | ||
|
|
d78e44c98d | ||
|
|
cd6bfdfc67 | ||
|
|
6593047efd | ||
|
|
8d38f99bf1 | ||
|
|
fb0bc4b753 | ||
|
|
7c04884a00 | ||
|
|
656eb27b8c | ||
|
|
ee23d71b66 | ||
|
|
ba1a4aeeb8 | ||
|
|
d41d28104f | ||
|
|
a9c0dd4b63 | ||
|
|
870de51f5d | ||
|
|
c24afca519 | ||
|
|
6e32bbb4e0 | ||
|
|
bcaaaae347 | ||
|
|
cd224b24df | ||
|
|
fe97939faf | ||
|
|
2091c823c8 | ||
|
|
e3c98388c6 | ||
|
|
fecb9a1df6 | ||
|
|
fbe4f7e5e6 | ||
|
|
e829ebd2ed | ||
|
|
870bc7fd17 | ||
|
|
34f843bc84 | ||
|
|
ec4d0428bb | ||
|
|
c192d9cd13 | ||
|
|
d4cb764a18 | ||
|
|
e9bb9fb07f | ||
|
|
c08db13f3d | ||
|
|
2e0b6d0a70 | ||
|
|
8b3553fcd5 | ||
|
|
b578843c6d | ||
|
|
12296a3e75 | ||
|
|
dbc68e54c6 | ||
|
|
5819017a97 | ||
|
|
e089f84ef4 | ||
|
|
ca65327527 | ||
|
|
e6702c7f82 | ||
|
|
95318307fe | ||
|
|
a2961d6b89 | ||
|
|
5e3476ad15 | ||
|
|
3358412028 | ||
|
|
6d4ccb63a3 | ||
|
|
b8fbbd3afb | ||
|
|
64ee344ba1 | ||
|
|
06de31dcb2 | ||
|
|
1acdad97a2 | ||
|
|
e41224bab7 | ||
|
|
97fc8f42c2 | ||
|
|
38abc55870 | ||
|
|
94d15ecb30 | ||
|
|
7188fe6e2c | ||
|
|
ff5550ec85 | ||
|
|
b6a3e002fb | ||
|
|
8ecef72efc | ||
|
|
4fe8921bc6 | ||
|
|
483ea16d4d | ||
|
|
ebf3618667 | ||
|
|
e82bcd0824 | ||
|
|
1db9c3a2e7 | ||
|
|
9f773de1a1 | ||
|
|
4aa69791c1 | ||
|
|
d89ded9d43 | ||
|
|
8d809412bb | ||
|
|
7d0f3e12f3 | ||
|
|
16191975f9 | ||
|
|
c210e6ca46 | ||
|
|
3695a75919 | ||
|
|
fdd3913f4f | ||
|
|
3dd1d08a5b | ||
|
|
dfe6fb3177 | ||
|
|
c947567311 | ||
|
|
a44526aeed | ||
|
|
982149f759 | ||
|
|
b18ec506b3 | ||
|
|
a2feec6f5b | ||
|
|
342056060b | ||
|
|
967cbae93f | ||
|
|
e13a14ab5c | ||
|
|
785b15aad5 | ||
|
|
8394963f0b | ||
|
|
60cccc9d9f | ||
|
|
82152082f3 | ||
|
|
9cd2707157 | ||
|
|
fc9839fd0c | ||
|
|
49716e8c5c | ||
|
|
62bb1fd6d4 | ||
|
|
f181b79ef7 | ||
|
|
09bfbd4214 | ||
|
|
20754d5cae | ||
|
|
0731e8cb6c | ||
|
|
03d4fdc270 | ||
|
|
d55fe64d47 | ||
|
|
edd555c088 | ||
|
|
0cd3eb418c | ||
|
|
2118a55ab6 | ||
|
|
7551749784 | ||
|
|
285d3b8369 | ||
|
|
87c7b4a83b | ||
|
|
d586de0639 | ||
|
|
8f00f333aa | ||
|
|
186cc76ffb |
@@ -1,12 +1,13 @@
|
|||||||
|
import getCsrfHeaderName from "../../package-shared/actions/get-csrf-header-name";
|
||||||
import parseClientCookies from "../utils/parseClientCookies";
|
import parseClientCookies from "../utils/parseClientCookies";
|
||||||
/**
|
/**
|
||||||
* Login with Google Function
|
* Login with Google Function
|
||||||
* ===============================================================================
|
* ===============================================================================
|
||||||
* @description This function uses google identity api to login a user with datasquirel
|
* @description This function uses google identity api to login a user with datasquirel
|
||||||
*/
|
*/
|
||||||
export default async function logout(
|
export default async function logout(params?: {
|
||||||
params: { [s: string]: any } | null
|
googleClientId?: any;
|
||||||
): Promise<boolean> {
|
}): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
const localUser = localStorage.getItem("user");
|
const localUser = localStorage.getItem("user");
|
||||||
let targetUser;
|
let targetUser;
|
||||||
@@ -38,7 +39,7 @@ export default async function logout(
|
|||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
|
||||||
localStorage.setItem("user", "{}");
|
localStorage.setItem("user", "{}");
|
||||||
localStorage.removeItem("csrf");
|
localStorage.removeItem(getCsrfHeaderName());
|
||||||
|
|
||||||
document.cookie = `datasquirel_social_id=null;samesite=strict;path=/`;
|
document.cookie = `datasquirel_social_id=null;samesite=strict;path=/`;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import getCsrfHeaderName from "../../package-shared/actions/get-csrf-header-name";
|
||||||
|
import { APILoginFunctionReturn } from "../../package-shared/types";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client Setup After Login
|
||||||
|
* ===============================================================================
|
||||||
|
* @description This function sets local storage variables like `csrf` after a user
|
||||||
|
* is logged in. Use this in conjunction with the `datasquirel.user.loginUser`
|
||||||
|
* function
|
||||||
|
*/
|
||||||
|
export default function postLogin(res: APILoginFunctionReturn): boolean {
|
||||||
|
try {
|
||||||
|
if (!res.payload) return false;
|
||||||
|
if (!res.payload.csrf_k) return false;
|
||||||
|
localStorage.setItem(getCsrfHeaderName(), res.payload.csrf_k);
|
||||||
|
localStorage.setItem("user", JSON.stringify(res.payload));
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import {
|
||||||
|
APIResponseObject,
|
||||||
|
ClientCrudFetchParams,
|
||||||
|
PostInsertReturn,
|
||||||
|
} from "../../package-shared/types";
|
||||||
|
import serializeQuery from "../../package-shared/utils/serialize-query";
|
||||||
|
import fetchApi from "../fetch";
|
||||||
|
|
||||||
|
export default async function clientCrudFetch<
|
||||||
|
T extends { [k: string]: any } = { [k: string]: any },
|
||||||
|
P = string,
|
||||||
|
R extends { [k: string]: any } = { [k: string]: any }
|
||||||
|
>({
|
||||||
|
table,
|
||||||
|
basePath,
|
||||||
|
body,
|
||||||
|
query,
|
||||||
|
targetId,
|
||||||
|
method = "GET",
|
||||||
|
apiOrigin,
|
||||||
|
headers,
|
||||||
|
...options
|
||||||
|
}: ClientCrudFetchParams<T, P>) {
|
||||||
|
try {
|
||||||
|
let pathname = basePath || ``;
|
||||||
|
|
||||||
|
pathname += `/${String(table)}`;
|
||||||
|
|
||||||
|
if (targetId) {
|
||||||
|
pathname += `/${String(targetId)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query) {
|
||||||
|
pathname = `${pathname}${serializeQuery(query)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
pathname = pathname.replace(/\/{2,}/g, "/");
|
||||||
|
|
||||||
|
pathname = apiOrigin
|
||||||
|
? `${apiOrigin}/${pathname}`.replace(/([^:]\/)\/+/g, "$1")
|
||||||
|
: pathname;
|
||||||
|
|
||||||
|
const res = await fetchApi<
|
||||||
|
any,
|
||||||
|
APIResponseObject<PostInsertReturn | R[]>
|
||||||
|
>(pathname, {
|
||||||
|
method,
|
||||||
|
body,
|
||||||
|
headers,
|
||||||
|
...options,
|
||||||
|
});
|
||||||
|
|
||||||
|
return res;
|
||||||
|
} catch (error: any) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
msg: `API ERROR => ${error.message}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
+32
-58
@@ -1,52 +1,31 @@
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
import {
|
||||||
type FetchApiOptions = {
|
DSQLClientFetchHeader,
|
||||||
method:
|
DSQLFetchApiOptions,
|
||||||
| "POST"
|
} from "../../package-shared/types";
|
||||||
| "GET"
|
import serializeQuery from "../../package-shared/utils/serialize-query";
|
||||||
| "DELETE"
|
|
||||||
| "PUT"
|
|
||||||
| "PATCH"
|
|
||||||
| "post"
|
|
||||||
| "get"
|
|
||||||
| "delete"
|
|
||||||
| "put"
|
|
||||||
| "patch";
|
|
||||||
body?: object | string;
|
|
||||||
headers?: FetchHeader;
|
|
||||||
};
|
|
||||||
|
|
||||||
type FetchHeader = HeadersInit & {
|
|
||||||
[key: string]: string | null;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type FetchApiReturn = {
|
|
||||||
success: boolean;
|
|
||||||
payload: any;
|
|
||||||
msg?: string;
|
|
||||||
[key: string]: any;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* # Fetch API
|
* # Fetch API
|
||||||
*/
|
*/
|
||||||
export default async function fetchApi(
|
export default async function fetchApi<
|
||||||
url: string,
|
T extends { [k: string]: any } = { [k: string]: any },
|
||||||
options?: FetchApiOptions,
|
R extends any = any,
|
||||||
csrf?: boolean,
|
>(url: string, options?: DSQLFetchApiOptions<T>): Promise<R> {
|
||||||
/** Key to use to grab local Storage csrf value. */
|
|
||||||
localStorageCSRFKey?: string
|
|
||||||
): Promise<any> {
|
|
||||||
let data;
|
let data;
|
||||||
|
|
||||||
const csrfValue = localStorage.getItem(localStorageCSRFKey || "csrf");
|
|
||||||
|
|
||||||
let finalHeaders = {
|
let finalHeaders = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
} as FetchHeader;
|
} as DSQLClientFetchHeader;
|
||||||
|
|
||||||
if (csrf && csrfValue) {
|
if (options?.csrfKey && options.csrfValue) {
|
||||||
finalHeaders[`'${csrfValue.replace(/\"/g, "")}'`] = "true";
|
finalHeaders[options.csrfKey] = options.csrfValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let finalURL = url;
|
||||||
|
|
||||||
|
if (options?.query) {
|
||||||
|
finalURL += serializeQuery(options.query);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof options === "string") {
|
if (typeof options === "string") {
|
||||||
@@ -55,7 +34,7 @@ export default async function fetchApi(
|
|||||||
|
|
||||||
switch (options) {
|
switch (options) {
|
||||||
case "post":
|
case "post":
|
||||||
fetchData = await fetch(url, {
|
fetchData = await fetch(finalURL, {
|
||||||
method: options,
|
method: options,
|
||||||
headers: finalHeaders,
|
headers: finalHeaders,
|
||||||
} as RequestInit);
|
} as RequestInit);
|
||||||
@@ -63,7 +42,7 @@ export default async function fetchApi(
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fetchData = await fetch(url);
|
fetchData = await fetch(finalURL);
|
||||||
data = fetchData.json();
|
data = fetchData.json();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -72,28 +51,23 @@ export default async function fetchApi(
|
|||||||
data = null;
|
data = null;
|
||||||
}
|
}
|
||||||
} else if (typeof options === "object") {
|
} else if (typeof options === "object") {
|
||||||
try {
|
|
||||||
let fetchData;
|
let fetchData;
|
||||||
|
let fetchOptions: RequestInit = {};
|
||||||
|
|
||||||
if (options.body && typeof options.body === "object") {
|
try {
|
||||||
let oldOptionsBody = _.cloneDeep(options.body);
|
fetchOptions.method = options.method;
|
||||||
options.body = JSON.stringify(oldOptionsBody);
|
|
||||||
|
if (options.method.match(/post|put|delete|patch/i)) {
|
||||||
|
if (options.body && typeof options.body == "object") {
|
||||||
|
fetchOptions.body = JSON.stringify(options.body);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.headers) {
|
fetchOptions.headers = _.merge(finalHeaders, options.headers || {});
|
||||||
options.headers = _.merge(options.headers, finalHeaders);
|
|
||||||
|
|
||||||
const finalOptions: any = { ...options };
|
fetchOptions = _.merge(fetchOptions, options.fetchOptions);
|
||||||
fetchData = await fetch(url, finalOptions);
|
|
||||||
} else {
|
|
||||||
const finalOptions = {
|
|
||||||
...options,
|
|
||||||
headers: finalHeaders,
|
|
||||||
} as RequestInit;
|
|
||||||
|
|
||||||
fetchData = await fetch(url, finalOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
fetchData = await fetch(finalURL, fetchOptions);
|
||||||
data = fetchData.json();
|
data = fetchData.json();
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log("FetchAPI error #2:", error.message);
|
console.log("FetchAPI error #2:", error.message);
|
||||||
@@ -101,7 +75,7 @@ export default async function fetchApi(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
let fetchData = await fetch(url);
|
let fetchData = await fetch(finalURL);
|
||||||
data = await fetchData.json();
|
data = await fetchData.json();
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log("FetchAPI error #3:", error.message);
|
console.log("FetchAPI error #3:", error.message);
|
||||||
|
|||||||
+18
-12
@@ -11,18 +11,15 @@ import serializeCookies from "../package-shared/utils/serialize-cookies";
|
|||||||
import EJSON from "../package-shared/utils/ejson";
|
import EJSON from "../package-shared/utils/ejson";
|
||||||
import numberfy from "../package-shared/utils/numberfy";
|
import numberfy from "../package-shared/utils/numberfy";
|
||||||
import slugify from "../package-shared/utils/slugify";
|
import slugify from "../package-shared/utils/slugify";
|
||||||
|
import postLogin from "./auth/post-login";
|
||||||
|
import deserializeQuery from "../package-shared/utils/deserialize-query";
|
||||||
|
import debugLog from "../package-shared/utils/logging/debug-log";
|
||||||
|
import clientCrudFetch from "./crud-fetch";
|
||||||
|
|
||||||
////////////////////////////////////////
|
|
||||||
////////////////////////////////////////
|
|
||||||
////////////////////////////////////////
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Media Functions Object
|
|
||||||
*/
|
|
||||||
const media = {
|
const media = {
|
||||||
imageInputToBase64: imageInputToBase64,
|
imageInputToBase64,
|
||||||
imageInputFileToBase64: imageInputFileToBase64,
|
imageInputFileToBase64,
|
||||||
inputFileToBase64: inputFileToBase64,
|
inputFileToBase64,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,15 +32,18 @@ const auth = {
|
|||||||
github: {
|
github: {
|
||||||
getAccessToken: getGithubAccessToken,
|
getAccessToken: getGithubAccessToken,
|
||||||
},
|
},
|
||||||
logout: logout,
|
logout,
|
||||||
|
postLogin,
|
||||||
};
|
};
|
||||||
|
|
||||||
const utils = {
|
const utils = {
|
||||||
|
deserializeQuery,
|
||||||
serializeQuery,
|
serializeQuery,
|
||||||
serializeCookies,
|
serializeCookies,
|
||||||
EJSON,
|
EJSON,
|
||||||
numberfy,
|
numberfy,
|
||||||
slugify,
|
slugify,
|
||||||
|
debugLog,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,6 +57,12 @@ const fetch = {
|
|||||||
/**
|
/**
|
||||||
* Main Export
|
* Main Export
|
||||||
*/
|
*/
|
||||||
const datasquirelClient = { media, auth, fetch, utils };
|
const datasquirelClient = {
|
||||||
|
media,
|
||||||
|
auth,
|
||||||
|
fetch,
|
||||||
|
utils,
|
||||||
|
clientCrudFetch,
|
||||||
|
};
|
||||||
|
|
||||||
export default datasquirelClient;
|
export default datasquirelClient;
|
||||||
|
|||||||
Vendored
+3
-3
@@ -3,6 +3,6 @@
|
|||||||
* ===============================================================================
|
* ===============================================================================
|
||||||
* @description This function uses google identity api to login a user with datasquirel
|
* @description This function uses google identity api to login a user with datasquirel
|
||||||
*/
|
*/
|
||||||
export default function logout(params: {
|
export default function logout(params?: {
|
||||||
[s: string]: any;
|
googleClientId?: any;
|
||||||
} | null): Promise<boolean>;
|
}): Promise<boolean>;
|
||||||
|
|||||||
Vendored
+2
-1
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = logout;
|
exports.default = logout;
|
||||||
|
const get_csrf_header_name_1 = __importDefault(require("../../package-shared/actions/get-csrf-header-name"));
|
||||||
const parseClientCookies_1 = __importDefault(require("../utils/parseClientCookies"));
|
const parseClientCookies_1 = __importDefault(require("../utils/parseClientCookies"));
|
||||||
/**
|
/**
|
||||||
* Login with Google Function
|
* Login with Google Function
|
||||||
@@ -46,7 +47,7 @@ function logout(params) {
|
|||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
localStorage.setItem("user", "{}");
|
localStorage.setItem("user", "{}");
|
||||||
localStorage.removeItem("csrf");
|
localStorage.removeItem((0, get_csrf_header_name_1.default)());
|
||||||
document.cookie = `datasquirel_social_id=null;samesite=strict;path=/`;
|
document.cookie = `datasquirel_social_id=null;samesite=strict;path=/`;
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
|||||||
Vendored
+9
@@ -0,0 +1,9 @@
|
|||||||
|
import { APILoginFunctionReturn } from "../../package-shared/types";
|
||||||
|
/**
|
||||||
|
* Client Setup After Login
|
||||||
|
* ===============================================================================
|
||||||
|
* @description This function sets local storage variables like `csrf` after a user
|
||||||
|
* is logged in. Use this in conjunction with the `datasquirel.user.loginUser`
|
||||||
|
* function
|
||||||
|
*/
|
||||||
|
export default function postLogin(res: APILoginFunctionReturn): boolean;
|
||||||
Vendored
+28
@@ -0,0 +1,28 @@
|
|||||||
|
"use strict";
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.default = postLogin;
|
||||||
|
const get_csrf_header_name_1 = __importDefault(require("../../package-shared/actions/get-csrf-header-name"));
|
||||||
|
/**
|
||||||
|
* Client Setup After Login
|
||||||
|
* ===============================================================================
|
||||||
|
* @description This function sets local storage variables like `csrf` after a user
|
||||||
|
* is logged in. Use this in conjunction with the `datasquirel.user.loginUser`
|
||||||
|
* function
|
||||||
|
*/
|
||||||
|
function postLogin(res) {
|
||||||
|
try {
|
||||||
|
if (!res.payload)
|
||||||
|
return false;
|
||||||
|
if (!res.payload.csrf_k)
|
||||||
|
return false;
|
||||||
|
localStorage.setItem((0, get_csrf_header_name_1.default)(), res.payload.csrf_k);
|
||||||
|
localStorage.setItem("user", JSON.stringify(res.payload));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
import { APIResponseObject, ClientCrudFetchParams, PostInsertReturn } from "../../package-shared/types";
|
||||||
|
export default function clientCrudFetch<T extends {
|
||||||
|
[k: string]: any;
|
||||||
|
} = {
|
||||||
|
[k: string]: any;
|
||||||
|
}, P = string, R extends {
|
||||||
|
[k: string]: any;
|
||||||
|
} = {
|
||||||
|
[k: string]: any;
|
||||||
|
}>({ table, basePath, body, query, targetId, method, apiOrigin, headers, ...options }: ClientCrudFetchParams<T, P>): Promise<APIResponseObject<PostInsertReturn | R[]>>;
|
||||||
Vendored
+57
@@ -0,0 +1,57 @@
|
|||||||
|
"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 __rest = (this && this.__rest) || function (s, e) {
|
||||||
|
var t = {};
|
||||||
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||||
|
t[p] = s[p];
|
||||||
|
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||||
|
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||||
|
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
||||||
|
t[p[i]] = s[p[i]];
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.default = clientCrudFetch;
|
||||||
|
const serialize_query_1 = __importDefault(require("../../package-shared/utils/serialize-query"));
|
||||||
|
const fetch_1 = __importDefault(require("../fetch"));
|
||||||
|
function clientCrudFetch(_a) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
var { table, basePath, body, query, targetId, method = "GET", apiOrigin, headers } = _a, options = __rest(_a, ["table", "basePath", "body", "query", "targetId", "method", "apiOrigin", "headers"]);
|
||||||
|
try {
|
||||||
|
let pathname = basePath || ``;
|
||||||
|
pathname += `/${String(table)}`;
|
||||||
|
if (targetId) {
|
||||||
|
pathname += `/${String(targetId)}`;
|
||||||
|
}
|
||||||
|
if (query) {
|
||||||
|
pathname = `${pathname}${(0, serialize_query_1.default)(query)}`;
|
||||||
|
}
|
||||||
|
pathname = pathname.replace(/\/{2,}/g, "/");
|
||||||
|
pathname = apiOrigin
|
||||||
|
? `${apiOrigin}/${pathname}`.replace(/([^:]\/)\/+/g, "$1")
|
||||||
|
: pathname;
|
||||||
|
const res = yield (0, fetch_1.default)(pathname, Object.assign({ method,
|
||||||
|
body,
|
||||||
|
headers }, options));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
msg: `API ERROR => ${error.message}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
Vendored
+6
-18
@@ -1,21 +1,9 @@
|
|||||||
type FetchApiOptions = {
|
import { DSQLFetchApiOptions } from "../../package-shared/types";
|
||||||
method: "POST" | "GET" | "DELETE" | "PUT" | "PATCH" | "post" | "get" | "delete" | "put" | "patch";
|
|
||||||
body?: object | string;
|
|
||||||
headers?: FetchHeader;
|
|
||||||
};
|
|
||||||
type FetchHeader = HeadersInit & {
|
|
||||||
[key: string]: string | null;
|
|
||||||
};
|
|
||||||
export type FetchApiReturn = {
|
|
||||||
success: boolean;
|
|
||||||
payload: any;
|
|
||||||
msg?: string;
|
|
||||||
[key: string]: any;
|
|
||||||
};
|
|
||||||
/**
|
/**
|
||||||
* # Fetch API
|
* # Fetch API
|
||||||
*/
|
*/
|
||||||
export default function fetchApi(url: string, options?: FetchApiOptions, csrf?: boolean,
|
export default function fetchApi<T extends {
|
||||||
/** Key to use to grab local Storage csrf value. */
|
[k: string]: any;
|
||||||
localStorageCSRFKey?: string): Promise<any>;
|
} = {
|
||||||
export {};
|
[k: string]: any;
|
||||||
|
}, R extends any = any>(url: string, options?: DSQLFetchApiOptions<T>): Promise<R>;
|
||||||
|
|||||||
Vendored
+20
-21
@@ -14,34 +14,36 @@ 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 serialize_query_1 = __importDefault(require("../../package-shared/utils/serialize-query"));
|
||||||
/**
|
/**
|
||||||
* # Fetch API
|
* # Fetch API
|
||||||
*/
|
*/
|
||||||
function fetchApi(url, options, csrf,
|
function fetchApi(url, options) {
|
||||||
/** Key to use to grab local Storage csrf value. */
|
|
||||||
localStorageCSRFKey) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let data;
|
let data;
|
||||||
const csrfValue = localStorage.getItem(localStorageCSRFKey || "csrf");
|
|
||||||
let finalHeaders = {
|
let finalHeaders = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
};
|
};
|
||||||
if (csrf && csrfValue) {
|
if ((options === null || options === void 0 ? void 0 : options.csrfKey) && options.csrfValue) {
|
||||||
finalHeaders[`'${csrfValue.replace(/\"/g, "")}'`] = "true";
|
finalHeaders[options.csrfKey] = options.csrfValue;
|
||||||
|
}
|
||||||
|
let finalURL = url;
|
||||||
|
if (options === null || options === void 0 ? void 0 : options.query) {
|
||||||
|
finalURL += (0, serialize_query_1.default)(options.query);
|
||||||
}
|
}
|
||||||
if (typeof options === "string") {
|
if (typeof options === "string") {
|
||||||
try {
|
try {
|
||||||
let fetchData;
|
let fetchData;
|
||||||
switch (options) {
|
switch (options) {
|
||||||
case "post":
|
case "post":
|
||||||
fetchData = yield fetch(url, {
|
fetchData = yield fetch(finalURL, {
|
||||||
method: options,
|
method: options,
|
||||||
headers: finalHeaders,
|
headers: finalHeaders,
|
||||||
});
|
});
|
||||||
data = fetchData.json();
|
data = fetchData.json();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fetchData = yield fetch(url);
|
fetchData = yield fetch(finalURL);
|
||||||
data = fetchData.json();
|
data = fetchData.json();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -52,21 +54,18 @@ localStorageCSRFKey) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (typeof options === "object") {
|
else if (typeof options === "object") {
|
||||||
try {
|
|
||||||
let fetchData;
|
let fetchData;
|
||||||
if (options.body && typeof options.body === "object") {
|
let fetchOptions = {};
|
||||||
let oldOptionsBody = lodash_1.default.cloneDeep(options.body);
|
try {
|
||||||
options.body = JSON.stringify(oldOptionsBody);
|
fetchOptions.method = options.method;
|
||||||
|
if (options.method.match(/post|put|delete|patch/i)) {
|
||||||
|
if (options.body && typeof options.body == "object") {
|
||||||
|
fetchOptions.body = JSON.stringify(options.body);
|
||||||
}
|
}
|
||||||
if (options.headers) {
|
|
||||||
options.headers = lodash_1.default.merge(options.headers, finalHeaders);
|
|
||||||
const finalOptions = Object.assign({}, options);
|
|
||||||
fetchData = yield fetch(url, finalOptions);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const finalOptions = Object.assign(Object.assign({}, options), { headers: finalHeaders });
|
|
||||||
fetchData = yield fetch(url, finalOptions);
|
|
||||||
}
|
}
|
||||||
|
fetchOptions.headers = lodash_1.default.merge(finalHeaders, options.headers || {});
|
||||||
|
fetchOptions = lodash_1.default.merge(fetchOptions, options.fetchOptions);
|
||||||
|
fetchData = yield fetch(finalURL, fetchOptions);
|
||||||
data = fetchData.json();
|
data = fetchData.json();
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
@@ -76,7 +75,7 @@ localStorageCSRFKey) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
let fetchData = yield fetch(url);
|
let fetchData = yield fetch(finalURL);
|
||||||
data = yield fetchData.json();
|
data = yield fetchData.json();
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|||||||
Vendored
+9
-1
@@ -9,6 +9,10 @@ import serializeQuery from "../package-shared/utils/serialize-query";
|
|||||||
import serializeCookies from "../package-shared/utils/serialize-cookies";
|
import serializeCookies from "../package-shared/utils/serialize-cookies";
|
||||||
import numberfy from "../package-shared/utils/numberfy";
|
import numberfy from "../package-shared/utils/numberfy";
|
||||||
import slugify from "../package-shared/utils/slugify";
|
import slugify from "../package-shared/utils/slugify";
|
||||||
|
import postLogin from "./auth/post-login";
|
||||||
|
import deserializeQuery from "../package-shared/utils/deserialize-query";
|
||||||
|
import debugLog from "../package-shared/utils/logging/debug-log";
|
||||||
|
import clientCrudFetch from "./crud-fetch";
|
||||||
/**
|
/**
|
||||||
* Main Export
|
* Main Export
|
||||||
*/
|
*/
|
||||||
@@ -26,12 +30,14 @@ declare const datasquirelClient: {
|
|||||||
getAccessToken: typeof getGithubAccessToken;
|
getAccessToken: typeof getGithubAccessToken;
|
||||||
};
|
};
|
||||||
logout: typeof logout;
|
logout: typeof logout;
|
||||||
|
postLogin: typeof postLogin;
|
||||||
};
|
};
|
||||||
fetch: {
|
fetch: {
|
||||||
fetchApi: typeof fetchApi;
|
fetchApi: typeof fetchApi;
|
||||||
clientFetch: typeof fetchApi;
|
clientFetch: typeof fetchApi;
|
||||||
};
|
};
|
||||||
utils: {
|
utils: {
|
||||||
|
deserializeQuery: typeof deserializeQuery;
|
||||||
serializeQuery: typeof serializeQuery;
|
serializeQuery: typeof serializeQuery;
|
||||||
serializeCookies: typeof serializeCookies;
|
serializeCookies: typeof serializeCookies;
|
||||||
EJSON: {
|
EJSON: {
|
||||||
@@ -40,10 +46,12 @@ declare const datasquirelClient: {
|
|||||||
} | {
|
} | {
|
||||||
[s: string]: any;
|
[s: string]: any;
|
||||||
}[] | undefined;
|
}[] | undefined;
|
||||||
stringify: (value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number) => string | undefined;
|
stringify: (value: any, replacer?: ((this: any, key: string, value: any) => any) | null, space?: string | number) => string | undefined;
|
||||||
};
|
};
|
||||||
numberfy: typeof numberfy;
|
numberfy: typeof numberfy;
|
||||||
slugify: typeof slugify;
|
slugify: typeof slugify;
|
||||||
|
debugLog: typeof debugLog;
|
||||||
};
|
};
|
||||||
|
clientCrudFetch: typeof clientCrudFetch;
|
||||||
};
|
};
|
||||||
export default datasquirelClient;
|
export default datasquirelClient;
|
||||||
|
|||||||
Vendored
+14
-7
@@ -16,12 +16,10 @@ const serialize_cookies_1 = __importDefault(require("../package-shared/utils/ser
|
|||||||
const ejson_1 = __importDefault(require("../package-shared/utils/ejson"));
|
const ejson_1 = __importDefault(require("../package-shared/utils/ejson"));
|
||||||
const numberfy_1 = __importDefault(require("../package-shared/utils/numberfy"));
|
const numberfy_1 = __importDefault(require("../package-shared/utils/numberfy"));
|
||||||
const slugify_1 = __importDefault(require("../package-shared/utils/slugify"));
|
const slugify_1 = __importDefault(require("../package-shared/utils/slugify"));
|
||||||
////////////////////////////////////////
|
const post_login_1 = __importDefault(require("./auth/post-login"));
|
||||||
////////////////////////////////////////
|
const deserialize_query_1 = __importDefault(require("../package-shared/utils/deserialize-query"));
|
||||||
////////////////////////////////////////
|
const debug_log_1 = __importDefault(require("../package-shared/utils/logging/debug-log"));
|
||||||
/**
|
const crud_fetch_1 = __importDefault(require("./crud-fetch"));
|
||||||
* Media Functions Object
|
|
||||||
*/
|
|
||||||
const media = {
|
const media = {
|
||||||
imageInputToBase64: imageInputToBase64_1.default,
|
imageInputToBase64: imageInputToBase64_1.default,
|
||||||
imageInputFileToBase64: imageInputFileToBase64_1.default,
|
imageInputFileToBase64: imageInputFileToBase64_1.default,
|
||||||
@@ -38,13 +36,16 @@ const auth = {
|
|||||||
getAccessToken: getAccessToken_2.default,
|
getAccessToken: getAccessToken_2.default,
|
||||||
},
|
},
|
||||||
logout: logout_1.default,
|
logout: logout_1.default,
|
||||||
|
postLogin: post_login_1.default,
|
||||||
};
|
};
|
||||||
const utils = {
|
const utils = {
|
||||||
|
deserializeQuery: deserialize_query_1.default,
|
||||||
serializeQuery: serialize_query_1.default,
|
serializeQuery: serialize_query_1.default,
|
||||||
serializeCookies: serialize_cookies_1.default,
|
serializeCookies: serialize_cookies_1.default,
|
||||||
EJSON: ejson_1.default,
|
EJSON: ejson_1.default,
|
||||||
numberfy: numberfy_1.default,
|
numberfy: numberfy_1.default,
|
||||||
slugify: slugify_1.default,
|
slugify: slugify_1.default,
|
||||||
|
debugLog: debug_log_1.default,
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Fetch
|
* Fetch
|
||||||
@@ -56,5 +57,11 @@ const fetch = {
|
|||||||
/**
|
/**
|
||||||
* Main Export
|
* Main Export
|
||||||
*/
|
*/
|
||||||
const datasquirelClient = { media, auth, fetch, utils };
|
const datasquirelClient = {
|
||||||
|
media,
|
||||||
|
auth,
|
||||||
|
fetch,
|
||||||
|
utils,
|
||||||
|
clientCrudFetch: crud_fetch_1.default,
|
||||||
|
};
|
||||||
exports.default = datasquirelClient;
|
exports.default = datasquirelClient;
|
||||||
|
|||||||
Vendored
+7
-5
@@ -3,10 +3,11 @@
|
|||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
var _a, _b;
|
var _a, _b, _c;
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const path_1 = __importDefault(require("path"));
|
const path_1 = __importDefault(require("path"));
|
||||||
const child_process_1 = require("child_process");
|
const child_process_1 = require("child_process");
|
||||||
|
const grab_db_names_1 = __importDefault(require("../package-shared/utils/grab-db-names"));
|
||||||
require("dotenv").config({
|
require("dotenv").config({
|
||||||
path: path_1.default.resolve(process.cwd(), ".env"),
|
path: path_1.default.resolve(process.cwd(), ".env"),
|
||||||
});
|
});
|
||||||
@@ -18,15 +19,15 @@ const mysqlDumpPath = ((_b = process.platform) === null || _b === void 0 ? void
|
|||||||
"C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe" +
|
"C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe" +
|
||||||
"'"
|
"'"
|
||||||
: "mysqldump";
|
: "mysqldump";
|
||||||
const { DSQL_USER, DSQL_PASS, DSQL_DB_NAME } = process.env;
|
const { DSQL_USER, DSQL_PASS } = process.env;
|
||||||
const dbName = DSQL_DB_NAME || "";
|
const { dbFullName } = (0, grab_db_names_1.default)();
|
||||||
const dumpFilePathArg = process.argv.indexOf("--file");
|
const dumpFilePathArg = process.argv.indexOf("--file");
|
||||||
if (dumpFilePathArg < 0) {
|
if (dumpFilePathArg < 0) {
|
||||||
console.log("Please provide a dump file path using `--file` argument");
|
console.log("Please provide a dump file path using `--file` argument");
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
const dumpFilePath = process.argv[dumpFilePathArg + 1];
|
const dumpFilePath = process.argv[dumpFilePathArg + 1];
|
||||||
if (!(dbName === null || dbName === void 0 ? void 0 : dbName.match(/./))) {
|
if (!(dbFullName === null || dbFullName === void 0 ? void 0 : dbFullName.match(/./))) {
|
||||||
console.log("DSQL_DB_NAME is required in your `.env` file");
|
console.log("DSQL_DB_NAME is required in your `.env` file");
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
@@ -39,12 +40,13 @@ try {
|
|||||||
cwd: process.cwd(),
|
cwd: process.cwd(),
|
||||||
};
|
};
|
||||||
// if (process.platform.match(/win/i)) execSyncOptions.shell = "bash.exe";
|
// if (process.platform.match(/win/i)) execSyncOptions.shell = "bash.exe";
|
||||||
const dump = (0, child_process_1.execSync)(`${mysqlPath} -u ${DSQL_USER} -p${DSQL_PASS} ${dbName} < ${dumpFilePath}`, execSyncOptions);
|
const dump = (0, child_process_1.execSync)(`${mysqlPath} -u ${DSQL_USER} -p${DSQL_PASS} ${dbFullName} < ${dumpFilePath}`, execSyncOptions);
|
||||||
console.log("Dumped successfully", dump.toString());
|
console.log("Dumped successfully", dump.toString());
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
(_c = global.ERROR_CALLBACK) === null || _c === void 0 ? void 0 : _c.call(global, `MariaDB Dump Error`, error);
|
||||||
console.log("Dump Error: ", error.message);
|
console.log("Dump Error: ", error.message);
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+2
@@ -0,0 +1,2 @@
|
|||||||
|
#! /usr/bin/env node
|
||||||
|
export {};
|
||||||
Vendored
+139
@@ -0,0 +1,139 @@
|
|||||||
|
#! /usr/bin/env node
|
||||||
|
"use strict";
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
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 });
|
||||||
|
const fs_1 = __importStar(require("fs"));
|
||||||
|
const __1 = __importDefault(require(".."));
|
||||||
|
const db_schema_to_type_1 = __importDefault(require("../package-shared/functions/dsql/db-schema-to-type"));
|
||||||
|
const path_1 = __importDefault(require("path"));
|
||||||
|
const debug_log_1 = __importDefault(require("../package-shared/utils/logging/debug-log"));
|
||||||
|
const app_names_1 = require("../package-shared/dict/app-names");
|
||||||
|
const configFileName = app_names_1.AppNames["SchemaToTypeDefConfigFileName"];
|
||||||
|
const configFilePath = path_1.default.join(process.cwd(), configFileName);
|
||||||
|
if (!fs_1.default.existsSync(configFilePath)) {
|
||||||
|
(0, debug_log_1.default)({
|
||||||
|
log: `Config File doesn't exist. Please add a '${app_names_1.AppNames["SchemaToTypeDefConfigFileName"]}' in the working directory with relevant configurations.`,
|
||||||
|
addTime: true,
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
const config = JSON.parse((0, fs_1.readFileSync)(path_1.default.join(process.cwd(), configFileName), "utf-8"));
|
||||||
|
if (!config.database) {
|
||||||
|
(0, debug_log_1.default)({
|
||||||
|
log: `Config File needs a 'database' value.`,
|
||||||
|
addTime: true,
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
if (!config.outDir && !config.outFile) {
|
||||||
|
(0, debug_log_1.default)({
|
||||||
|
log: `Config File needs a 'outDir' or 'outFile' value.`,
|
||||||
|
addTime: true,
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
if (!config.apiConnectionConfig) {
|
||||||
|
(0, debug_log_1.default)({
|
||||||
|
log: `Config File needs a 'apiConnectionConfig' value. This value needs an 'apiKey' value.`,
|
||||||
|
addTime: true,
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
if (!config.apiConnectionConfig.apiKey) {
|
||||||
|
(0, debug_log_1.default)({
|
||||||
|
log: `Config value 'apiConnectionConfig' needs an 'apiKey' value.`,
|
||||||
|
addTime: true,
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
try {
|
||||||
|
if (config.debug) {
|
||||||
|
(0, debug_log_1.default)({
|
||||||
|
log: config,
|
||||||
|
label: "Config",
|
||||||
|
addTime: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const schemaRes = yield __1.default.api.schema.get({
|
||||||
|
dbName: config.database || "",
|
||||||
|
apiConnectionConfig: config.apiConnectionConfig,
|
||||||
|
});
|
||||||
|
const dbSchema = schemaRes.singleRes;
|
||||||
|
if (config.debug) {
|
||||||
|
(0, debug_log_1.default)({
|
||||||
|
log: schemaRes,
|
||||||
|
label: "schema",
|
||||||
|
addTime: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!dbSchema)
|
||||||
|
throw new Error("No schema found");
|
||||||
|
const definitions = (0, db_schema_to_type_1.default)({ dbSchema });
|
||||||
|
const finalOutfile = path_1.default.resolve(process.cwd(), config.outDir ? config.outDir + "/dsql.ts" : config.outFile || "");
|
||||||
|
const ourfileDir = path_1.default.dirname(finalOutfile);
|
||||||
|
if (!fs_1.default.existsSync(ourfileDir)) {
|
||||||
|
fs_1.default.mkdirSync(ourfileDir, { recursive: true });
|
||||||
|
}
|
||||||
|
fs_1.default.writeFileSync(finalOutfile, (definitions === null || definitions === void 0 ? void 0 : definitions.join("\n\n")) || "", "utf-8");
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
(0, debug_log_1.default)({
|
||||||
|
log: error.message,
|
||||||
|
label: "Error",
|
||||||
|
title: "Schema to Typedef",
|
||||||
|
addTime: true,
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}))();
|
||||||
Vendored
+111
-47
@@ -1,57 +1,89 @@
|
|||||||
/**
|
declare global {
|
||||||
* Imports
|
var ERROR_CALLBACK: ErrorCallback | undefined;
|
||||||
*/
|
}
|
||||||
import get from "./utils/get";
|
import get from "./package-shared/actions/get";
|
||||||
import post from "./utils/post";
|
import post from "./package-shared/actions/post";
|
||||||
import getSchema from "./utils/get-schema";
|
import getSchema from "./package-shared/actions/get-schema";
|
||||||
import uploadImage from "./utils/upload-image";
|
|
||||||
import uploadFile from "./utils/upload-file";
|
|
||||||
import deleteFile from "./utils/delete-file";
|
|
||||||
import createUser from "./users/add-user";
|
|
||||||
import updateUser from "./users/update-user";
|
|
||||||
import loginUser from "./users/login-user";
|
|
||||||
import sendEmailCode from "./users/send-email-code";
|
|
||||||
import logoutUser from "./users/logout-user";
|
|
||||||
import userAuth from "./users/user-auth";
|
|
||||||
import reAuthUser from "./users/reauth-user";
|
|
||||||
import getUser from "./users/get-user";
|
|
||||||
import loginWithGoogle from "./users/social/google-auth";
|
|
||||||
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";
|
||||||
import trimSql from "./package-shared/utils/trim-sql";
|
import trimSql from "./package-shared/utils/trim-sql";
|
||||||
import parseCookies from "./package-shared/utils/backend/parseCookies";
|
import parseCookies from "./package-shared/utils/backend/parseCookies";
|
||||||
import httpRequest from "./package-shared/functions/backend/httpRequest";
|
import connDbHandler from "./package-shared/utils/db/conn-db-handler";
|
||||||
|
import encrypt from "./package-shared/functions/dsql/encrypt";
|
||||||
|
import decrypt from "./package-shared/functions/dsql/decrypt";
|
||||||
|
import hashPassword from "./package-shared/functions/dsql/hashPassword";
|
||||||
|
import dsqlCrud from "./package-shared/utils/data-fetching/crud";
|
||||||
|
import dsqlMethodCrud from "./package-shared/utils/data-fetching/method-crud";
|
||||||
|
import debugLog from "./package-shared/utils/logging/debug-log";
|
||||||
|
import { ErrorCallback } from "./package-shared/types";
|
||||||
|
import parseEnv from "./package-shared/utils/parse-env";
|
||||||
|
import dbHandler from "./package-shared/functions/backend/dbHandler";
|
||||||
|
import httpsRequest from "./package-shared/functions/backend/httpsRequest";
|
||||||
|
import handleNodemailer from "./package-shared/functions/backend/handleNodemailer";
|
||||||
|
import grabDSQLConnection from "./package-shared/utils/grab-dsql-connection";
|
||||||
|
import grabDSQLConnectionConfig from "./package-shared/utils/grab-dsql-connection-config";
|
||||||
|
import purgeDefaultFields from "./package-shared/utils/purge-default-fields";
|
||||||
|
import apiCrudHandler from "./package-shared/api-paths";
|
||||||
/**
|
/**
|
||||||
* Main Export
|
* Main Export
|
||||||
*/
|
*/
|
||||||
declare const datasquirel: {
|
declare const datasquirel: {
|
||||||
get: typeof get;
|
/**
|
||||||
post: typeof post;
|
* API Actions
|
||||||
|
*/
|
||||||
|
api: {
|
||||||
|
crud: {
|
||||||
|
get: typeof import("./package-shared/api/crud/get").default;
|
||||||
|
insert: typeof import("./package-shared/api/crud/post").default;
|
||||||
|
update: typeof import("./package-shared/api/crud/put").default;
|
||||||
|
delete: typeof import("./package-shared/api/crud/delete").default;
|
||||||
|
options: () => Promise<void>;
|
||||||
|
};
|
||||||
media: {
|
media: {
|
||||||
uploadImage: typeof uploadImage;
|
get: typeof import("./package-shared/api/media/get").default;
|
||||||
uploadFile: typeof uploadFile;
|
add: typeof import("./package-shared/api/media/post").default;
|
||||||
deleteFile: typeof deleteFile;
|
delete: typeof import("./package-shared/api/media/delete").default;
|
||||||
};
|
};
|
||||||
user: {
|
user: {
|
||||||
createUser: typeof createUser;
|
auth: {
|
||||||
deleteUser: any;
|
login: typeof import("./package-shared/actions/users/login-user").default;
|
||||||
loginUser: typeof loginUser;
|
get: typeof import("./package-shared/actions/users/get-user").default;
|
||||||
sendEmailCode: typeof sendEmailCode;
|
signup: typeof import("./package-shared/actions/users/add-user").default;
|
||||||
logoutUser: typeof logoutUser;
|
sendEmailCode: typeof import("./package-shared/actions/users/send-email-code").default;
|
||||||
userAuth: typeof userAuth;
|
update: typeof import("./package-shared/actions/users/update-user").default;
|
||||||
reAuthUser: typeof reAuthUser;
|
resetPassword: typeof import("./package-shared/actions/users/reset-password").default;
|
||||||
updateUser: typeof updateUser;
|
googleLogin: typeof import("./package-shared/actions/users/social/google-auth").default;
|
||||||
getUser: typeof getUser;
|
logout: typeof import("./package-shared/actions/users/logout-user").default;
|
||||||
getToken: typeof getToken;
|
auth: typeof import("./package-shared/actions/users/user-auth").default;
|
||||||
validateToken: typeof validateToken;
|
validateTempEmailCode: typeof import("./package-shared/actions/users/validate-temp-email-code").default;
|
||||||
validateTempEmailCode: any;
|
};
|
||||||
social: {
|
};
|
||||||
loginWithGoogle: typeof loginWithGoogle;
|
schema: {
|
||||||
loginWithGithub: typeof loginWithGithub;
|
get: typeof import("./package-shared/api/schema/get").default;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Get Action
|
||||||
|
*/
|
||||||
|
get: typeof get;
|
||||||
|
/**
|
||||||
|
* Post Action
|
||||||
|
*/
|
||||||
|
post: typeof post;
|
||||||
|
user: {
|
||||||
|
auth: {
|
||||||
|
login: (_: import("./package-shared/types").LoginUserParam) => Promise<import("./package-shared/types").APIResponseObject>;
|
||||||
|
get: (_: import("./package-shared/types").GetUserParams) => Promise<import("./package-shared/types").APIResponseObject>;
|
||||||
|
signup: (_: import("./package-shared/types").AddUserParams) => Promise<import("./package-shared/types").APIResponseObject>;
|
||||||
|
sendEmailCode: (_: import("./package-shared/types").SendEmailCodeParams) => Promise<import("./package-shared/types").APIResponseObject>;
|
||||||
|
update: (_: import("./package-shared/types").UpdateUserParams) => Promise<import("./package-shared/types").APIResponseObject>;
|
||||||
|
resetPassword: (_: import("./package-shared/types").ResetPasswordParams) => Promise<import("./package-shared/types").APIResponseObject>;
|
||||||
|
googleLogin: (_: import("./package-shared/types").GoogleAuthParams) => Promise<import("./package-shared/types").APIResponseObject>;
|
||||||
|
logout: typeof import("./package-shared/actions/users/logout-user").default;
|
||||||
|
auth: typeof import("./package-shared/actions/users/user-auth").default;
|
||||||
|
validateTempEmailCode: typeof import("./package-shared/actions/users/validate-temp-email-code").default;
|
||||||
|
githubLoginFn: typeof import("./package-shared/functions/api/social-login/githubLogin").default;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
getSchema: typeof getSchema;
|
getSchema: typeof getSchema;
|
||||||
@@ -69,12 +101,14 @@ declare const datasquirel: {
|
|||||||
getAccessToken: typeof import("./client/auth/github/getAccessToken").default;
|
getAccessToken: typeof import("./client/auth/github/getAccessToken").default;
|
||||||
};
|
};
|
||||||
logout: typeof import("./client/auth/logout").default;
|
logout: typeof import("./client/auth/logout").default;
|
||||||
|
postLogin: typeof import("./client/auth/post-login").default;
|
||||||
};
|
};
|
||||||
fetch: {
|
fetch: {
|
||||||
fetchApi: typeof import("./client/fetch").default;
|
fetchApi: typeof import("./client/fetch").default;
|
||||||
clientFetch: typeof import("./client/fetch").default;
|
clientFetch: typeof import("./client/fetch").default;
|
||||||
};
|
};
|
||||||
utils: {
|
utils: {
|
||||||
|
deserializeQuery: typeof import("./package-shared/utils/deserialize-query").default;
|
||||||
serializeQuery: typeof import("./package-shared/utils/serialize-query").default;
|
serializeQuery: typeof import("./package-shared/utils/serialize-query").default;
|
||||||
serializeCookies: typeof import("./package-shared/utils/serialize-cookies").default;
|
serializeCookies: typeof import("./package-shared/utils/serialize-cookies").default;
|
||||||
EJSON: {
|
EJSON: {
|
||||||
@@ -83,11 +117,13 @@ declare const datasquirel: {
|
|||||||
} | {
|
} | {
|
||||||
[s: string]: any;
|
[s: string]: any;
|
||||||
}[] | undefined;
|
}[] | undefined;
|
||||||
stringify: (value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number) => string | undefined;
|
stringify: (value: any, replacer?: ((this: any, key: string, value: any) => any) | null, space?: string | number) => string | undefined;
|
||||||
};
|
};
|
||||||
numberfy: typeof import("./package-shared/utils/numberfy").default;
|
numberfy: typeof import("./package-shared/utils/numberfy").default;
|
||||||
slugify: typeof import("./package-shared/utils/slugify").default;
|
slugify: typeof import("./package-shared/utils/slugify").default;
|
||||||
|
debugLog: typeof debugLog;
|
||||||
};
|
};
|
||||||
|
clientCrudFetch: typeof import("./client/crud-fetch").default;
|
||||||
};
|
};
|
||||||
sql: {
|
sql: {
|
||||||
sqlGenerator: typeof sqlGenerator;
|
sqlGenerator: typeof sqlGenerator;
|
||||||
@@ -97,12 +133,40 @@ declare const datasquirel: {
|
|||||||
};
|
};
|
||||||
utils: {
|
utils: {
|
||||||
crypto: {
|
crypto: {
|
||||||
encrypt: any;
|
encrypt: typeof encrypt;
|
||||||
decrypt: any;
|
decrypt: typeof decrypt;
|
||||||
hash: any;
|
hashPassword: typeof hashPassword;
|
||||||
};
|
};
|
||||||
parseCookies: typeof parseCookies;
|
parseCookies: typeof parseCookies;
|
||||||
httpRequest: typeof httpRequest;
|
connDbHandler: typeof connDbHandler;
|
||||||
|
debugLog: typeof debugLog;
|
||||||
|
parseEnv: typeof parseEnv;
|
||||||
|
httpsRequest: typeof httpsRequest;
|
||||||
|
httpRequest: typeof httpsRequest;
|
||||||
|
grabDSQLConnection: typeof grabDSQLConnection;
|
||||||
|
grabDSQLConnectionConfig: typeof grabDSQLConnectionConfig;
|
||||||
|
purgeDefaultFields: typeof purgeDefaultFields;
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* Run Crud actions `get`, `insert`, `update`, `delete`
|
||||||
|
* @description *Requires global variables `DSQL_USE_LOCAL` and `DSQL_DB_CONN`
|
||||||
|
*/
|
||||||
|
crud: typeof dsqlCrud;
|
||||||
|
/**
|
||||||
|
* Run Crud based on request Methods `GET`, `POST`, `PUT`, `PATCH`
|
||||||
|
* @description *Requires global variables `DSQL_USE_LOCAL` and `DSQL_DB_CONN`
|
||||||
|
*/
|
||||||
|
methodCrud: typeof dsqlMethodCrud;
|
||||||
|
/**
|
||||||
|
* General Database Handler
|
||||||
|
*/
|
||||||
|
dbHandler: typeof dbHandler;
|
||||||
|
/**
|
||||||
|
* Handle Mail
|
||||||
|
*/
|
||||||
|
mail: {
|
||||||
|
mailer: typeof handleNodemailer;
|
||||||
|
};
|
||||||
|
apiCrudHandler: typeof apiCrudHandler;
|
||||||
};
|
};
|
||||||
export default datasquirel;
|
export default datasquirel;
|
||||||
|
|||||||
Vendored
+72
-58
@@ -1,68 +1,45 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
// @ts-check
|
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
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 post_1 = __importDefault(require("./utils/post"));
|
|
||||||
const get_schema_1 = __importDefault(require("./utils/get-schema"));
|
|
||||||
const upload_image_1 = __importDefault(require("./utils/upload-image"));
|
|
||||||
const upload_file_1 = __importDefault(require("./utils/upload-file"));
|
|
||||||
const delete_file_1 = __importDefault(require("./utils/delete-file"));
|
|
||||||
const add_user_1 = __importDefault(require("./users/add-user"));
|
|
||||||
const update_user_1 = __importDefault(require("./users/update-user"));
|
|
||||||
const login_user_1 = __importDefault(require("./users/login-user"));
|
|
||||||
const send_email_code_1 = __importDefault(require("./users/send-email-code"));
|
|
||||||
const logout_user_1 = __importDefault(require("./users/logout-user"));
|
|
||||||
const user_auth_1 = __importDefault(require("./users/user-auth"));
|
|
||||||
const reauth_user_1 = __importDefault(require("./users/reauth-user"));
|
|
||||||
const get_user_1 = __importDefault(require("./users/get-user"));
|
|
||||||
const google_auth_1 = __importDefault(require("./users/social/google-auth"));
|
|
||||||
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"));
|
||||||
const sql_delete_generator_1 = __importDefault(require("./package-shared/functions/dsql/sql/sql-delete-generator"));
|
const sql_delete_generator_1 = __importDefault(require("./package-shared/functions/dsql/sql/sql-delete-generator"));
|
||||||
const trim_sql_1 = __importDefault(require("./package-shared/utils/trim-sql"));
|
const trim_sql_1 = __importDefault(require("./package-shared/utils/trim-sql"));
|
||||||
const parseCookies_1 = __importDefault(require("./package-shared/utils/backend/parseCookies"));
|
const parseCookies_1 = __importDefault(require("./package-shared/utils/backend/parseCookies"));
|
||||||
const httpRequest_1 = __importDefault(require("./package-shared/functions/backend/httpRequest"));
|
const conn_db_handler_1 = __importDefault(require("./package-shared/utils/db/conn-db-handler"));
|
||||||
////////////////////////////////////////
|
const encrypt_1 = __importDefault(require("./package-shared/functions/dsql/encrypt"));
|
||||||
////////////////////////////////////////
|
const decrypt_1 = __importDefault(require("./package-shared/functions/dsql/decrypt"));
|
||||||
////////////////////////////////////////
|
const hashPassword_1 = __importDefault(require("./package-shared/functions/dsql/hashPassword"));
|
||||||
|
const crud_1 = __importDefault(require("./package-shared/utils/data-fetching/crud"));
|
||||||
|
const method_crud_1 = __importDefault(require("./package-shared/utils/data-fetching/method-crud"));
|
||||||
|
const debug_log_1 = __importDefault(require("./package-shared/utils/logging/debug-log"));
|
||||||
|
const parse_env_1 = __importDefault(require("./package-shared/utils/parse-env"));
|
||||||
|
const crud_2 = __importDefault(require("./package-shared/api/crud"));
|
||||||
|
const user_1 = __importDefault(require("./package-shared/api/user"));
|
||||||
|
const local_user_1 = __importDefault(require("./package-shared/api/user/local-user"));
|
||||||
|
const media_1 = __importDefault(require("./package-shared/api/media"));
|
||||||
|
const dbHandler_1 = __importDefault(require("./package-shared/functions/backend/dbHandler"));
|
||||||
|
const httpsRequest_1 = __importDefault(require("./package-shared/functions/backend/httpsRequest"));
|
||||||
|
const handleNodemailer_1 = __importDefault(require("./package-shared/functions/backend/handleNodemailer"));
|
||||||
|
const grab_dsql_connection_1 = __importDefault(require("./package-shared/utils/grab-dsql-connection"));
|
||||||
|
const grab_dsql_connection_config_1 = __importDefault(require("./package-shared/utils/grab-dsql-connection-config"));
|
||||||
|
const schema_1 = __importDefault(require("./package-shared/api/schema"));
|
||||||
|
const purge_default_fields_1 = __importDefault(require("./package-shared/utils/purge-default-fields"));
|
||||||
|
const api_paths_1 = __importDefault(require("./package-shared/api-paths"));
|
||||||
/**
|
/**
|
||||||
* User Functions Object
|
* API Functions Object
|
||||||
*/
|
*/
|
||||||
const user = {
|
const api = {
|
||||||
createUser: add_user_1.default,
|
crud: crud_2.default,
|
||||||
deleteUser: require("./users/delete-user"),
|
media: media_1.default,
|
||||||
loginUser: login_user_1.default,
|
user: user_1.default,
|
||||||
sendEmailCode: send_email_code_1.default,
|
schema: schema_1.default,
|
||||||
logoutUser: logout_user_1.default,
|
|
||||||
userAuth: user_auth_1.default,
|
|
||||||
reAuthUser: reauth_user_1.default,
|
|
||||||
updateUser: update_user_1.default,
|
|
||||||
getUser: get_user_1.default,
|
|
||||||
getToken: get_token_1.default,
|
|
||||||
validateToken: validate_token_1.default,
|
|
||||||
validateTempEmailCode: require("./users/validate-temp-email-code"),
|
|
||||||
social: {
|
|
||||||
loginWithGoogle: google_auth_1.default,
|
|
||||||
loginWithGithub: github_auth_1.default,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* Media Functions Object
|
|
||||||
*/
|
|
||||||
const media = {
|
|
||||||
uploadImage: upload_image_1.default,
|
|
||||||
uploadFile: upload_file_1.default,
|
|
||||||
deleteFile: delete_file_1.default,
|
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* SQL Utils
|
* SQL Utils
|
||||||
@@ -77,21 +54,58 @@ const sql = {
|
|||||||
* Main Export
|
* Main Export
|
||||||
*/
|
*/
|
||||||
const datasquirel = {
|
const datasquirel = {
|
||||||
|
/**
|
||||||
|
* API Actions
|
||||||
|
*/
|
||||||
|
api,
|
||||||
|
/**
|
||||||
|
* Get Action
|
||||||
|
*/
|
||||||
get: get_1.default,
|
get: get_1.default,
|
||||||
|
/**
|
||||||
|
* Post Action
|
||||||
|
*/
|
||||||
post: post_1.default,
|
post: post_1.default,
|
||||||
media,
|
user: local_user_1.default,
|
||||||
user,
|
|
||||||
getSchema: get_schema_1.default,
|
getSchema: get_schema_1.default,
|
||||||
client: client_1.default,
|
client: client_1.default,
|
||||||
sql,
|
sql,
|
||||||
utils: {
|
utils: {
|
||||||
crypto: {
|
crypto: {
|
||||||
encrypt: require("./package-shared/functions/dsql/encrypt"),
|
encrypt: encrypt_1.default,
|
||||||
decrypt: require("./package-shared/functions/dsql/decrypt"),
|
decrypt: decrypt_1.default,
|
||||||
hash: require("./package-shared/functions/dsql/hashPassword"),
|
hashPassword: hashPassword_1.default,
|
||||||
},
|
},
|
||||||
parseCookies: parseCookies_1.default,
|
parseCookies: parseCookies_1.default,
|
||||||
httpRequest: httpRequest_1.default,
|
connDbHandler: conn_db_handler_1.default,
|
||||||
|
debugLog: debug_log_1.default,
|
||||||
|
parseEnv: parse_env_1.default,
|
||||||
|
httpsRequest: httpsRequest_1.default,
|
||||||
|
httpRequest: httpsRequest_1.default,
|
||||||
|
grabDSQLConnection: grab_dsql_connection_1.default,
|
||||||
|
grabDSQLConnectionConfig: grab_dsql_connection_config_1.default,
|
||||||
|
purgeDefaultFields: purge_default_fields_1.default,
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Run Crud actions `get`, `insert`, `update`, `delete`
|
||||||
|
* @description *Requires global variables `DSQL_USE_LOCAL` and `DSQL_DB_CONN`
|
||||||
|
*/
|
||||||
|
crud: crud_1.default,
|
||||||
|
/**
|
||||||
|
* Run Crud based on request Methods `GET`, `POST`, `PUT`, `PATCH`
|
||||||
|
* @description *Requires global variables `DSQL_USE_LOCAL` and `DSQL_DB_CONN`
|
||||||
|
*/
|
||||||
|
methodCrud: method_crud_1.default,
|
||||||
|
/**
|
||||||
|
* General Database Handler
|
||||||
|
*/
|
||||||
|
dbHandler: dbHandler_1.default,
|
||||||
|
/**
|
||||||
|
* Handle Mail
|
||||||
|
*/
|
||||||
|
mail: {
|
||||||
|
mailer: handleNodemailer_1.default,
|
||||||
|
},
|
||||||
|
apiCrudHandler: api_paths_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
|
||||||
*/
|
*/
|
||||||
@@ -74,4 +74,3 @@ function deleteFile(_a) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
module.exports = deleteFile;
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export default function getCsrfHeaderName(): string;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.default = getCsrfHeaderName;
|
||||||
|
function getCsrfHeaderName() {
|
||||||
|
return "x-dsql-csrf-key";
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
@@ -6,5 +6,5 @@ type GetSchemaReturn = {
|
|||||||
/**
|
/**
|
||||||
* # Get Schema for Database, table, or field *
|
* # Get Schema for Database, table, or field *
|
||||||
*/
|
*/
|
||||||
export default function getSchema({ key, database, field, table, user_id, }: GetSchemaAPIParam): Promise<GetSchemaReturn>;
|
export default function getSchema({ key, database, field, table, user_id, env, }: GetSchemaAPIParam): Promise<GetSchemaReturn>;
|
||||||
export {};
|
export {};
|
||||||
@@ -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,13 +13,13 @@ 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 *
|
||||||
*/
|
*/
|
||||||
function getSchema(_a) {
|
function getSchema(_a) {
|
||||||
return __awaiter(this, arguments, void 0, function* ({ key, database, field, table, user_id, }) {
|
return __awaiter(this, arguments, void 0, function* ({ key, database, field, table, user_id, env, }) {
|
||||||
const grabedHostNames = (0, grab_host_names_1.default)();
|
const grabedHostNames = (0, grab_host_names_1.default)({ env });
|
||||||
const { host, port, scheme } = grabedHostNames;
|
const { host, port, scheme } = grabedHostNames;
|
||||||
/**
|
/**
|
||||||
* Make https request
|
* Make https request
|
||||||
@@ -65,9 +64,6 @@ function getSchema(_a) {
|
|||||||
})
|
})
|
||||||
.end();
|
.end();
|
||||||
});
|
});
|
||||||
return {
|
return httpResponse;
|
||||||
success: true,
|
|
||||||
payload: httpResponse,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Vendored
+24
@@ -0,0 +1,24 @@
|
|||||||
|
import { APIResponseObject, DsqlCrudQueryObject } from "../types";
|
||||||
|
type Param<T extends {
|
||||||
|
[k: string]: any;
|
||||||
|
} = {
|
||||||
|
[k: string]: any;
|
||||||
|
}> = {
|
||||||
|
key?: string;
|
||||||
|
database: string;
|
||||||
|
query: DsqlCrudQueryObject<T>;
|
||||||
|
table?: string;
|
||||||
|
debug?: boolean;
|
||||||
|
useLocal?: boolean;
|
||||||
|
apiVersion?: string;
|
||||||
|
};
|
||||||
|
export type ApiGetParams = Param;
|
||||||
|
/**
|
||||||
|
* # Make a get request to Datasquirel API
|
||||||
|
*/
|
||||||
|
export default function get<T extends {
|
||||||
|
[k: string]: any;
|
||||||
|
} = {
|
||||||
|
[k: string]: any;
|
||||||
|
}>({ key, database, query, table, debug, useLocal, apiVersion, }: Param<T>): Promise<APIResponseObject>;
|
||||||
|
export {};
|
||||||
+25
-43
@@ -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,44 +13,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = get;
|
exports.default = get;
|
||||||
const path_1 = __importDefault(require("path"));
|
const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const serialize_query_1 = __importDefault(require("../utils/serialize-query"));
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const debug_log_1 = __importDefault(require("../utils/logging/debug-log"));
|
||||||
const get_1 = __importDefault(require("../package-shared/functions/api/query/get"));
|
const crud_1 = __importDefault(require("../utils/data-fetching/crud"));
|
||||||
const serialize_query_1 = __importDefault(require("../package-shared/utils/serialize-query"));
|
const grab_api_key_1 = __importDefault(require("../utils/grab-api-key"));
|
||||||
/**
|
/**
|
||||||
* # Make a get request to Datasquirel API
|
* # Make a get request to Datasquirel API
|
||||||
*/
|
*/
|
||||||
function get(_a) {
|
function get(_a) {
|
||||||
return __awaiter(this, arguments, void 0, function* ({ key, db, query, queryValues, tableName, useLocal, user_id, }) {
|
return __awaiter(this, arguments, void 0, function* ({ key, database, query, table, debug, useLocal, apiVersion = "v1", }) {
|
||||||
const grabedHostNames = (0, grab_host_names_1.default)();
|
const grabedHostNames = (0, grab_host_names_1.default)();
|
||||||
const { host, port, scheme } = grabedHostNames;
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
function debugFn(log, label) {
|
||||||
|
(0, debug_log_1.default)({ log, addTime: true, title: "apiGet", label });
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Check for local DB settings
|
* Check for local DB settings
|
||||||
*
|
*
|
||||||
* @description Look for local db settings in `.env` file and by pass the http request if available
|
* @description Look for local db settings in `.env` file and by pass the http request if available
|
||||||
*/
|
*/
|
||||||
const { DSQL_DB_HOST, DSQL_DB_USERNAME, DSQL_DB_PASSWORD, DSQL_DB_NAME } = process.env;
|
if (useLocal) {
|
||||||
if ((DSQL_DB_HOST === null || DSQL_DB_HOST === void 0 ? void 0 : DSQL_DB_HOST.match(/./)) &&
|
const result = yield (0, crud_1.default)({
|
||||||
(DSQL_DB_USERNAME === null || DSQL_DB_USERNAME === void 0 ? void 0 : DSQL_DB_USERNAME.match(/./)) &&
|
action: "get",
|
||||||
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
|
table: table || "",
|
||||||
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
|
dbFullName: database,
|
||||||
useLocal) {
|
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
|
||||||
let dbSchema;
|
|
||||||
try {
|
|
||||||
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
|
||||||
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
|
|
||||||
}
|
|
||||||
catch (error) { }
|
|
||||||
return yield (0, get_1.default)({
|
|
||||||
dbFullName: DSQL_DB_NAME,
|
|
||||||
query,
|
query,
|
||||||
queryValues,
|
|
||||||
tableName,
|
|
||||||
dbSchema,
|
|
||||||
useLocal,
|
|
||||||
});
|
});
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Make https request
|
* Make https request
|
||||||
@@ -59,26 +48,19 @@ function get(_a) {
|
|||||||
* @description make a request to datasquirel.com
|
* @description make a request to datasquirel.com
|
||||||
*/
|
*/
|
||||||
const httpResponse = yield new Promise((resolve, reject) => {
|
const httpResponse = yield new Promise((resolve, reject) => {
|
||||||
/** @type {import("../package-shared/types").GetReqQueryObject} */
|
const queryString = (0, serialize_query_1.default)(query);
|
||||||
const queryObject = {
|
if (debug) {
|
||||||
db: process.env.DSQL_API_DB_NAME || String(db),
|
debugFn(queryString, "queryString");
|
||||||
query: String(query.replace(/\n|\r|\n\r/g, "").replace(/ {2,}/g, " ")),
|
}
|
||||||
queryValues: queryValues
|
let path = `/api/${apiVersion}/crud/${database}/${table}`;
|
||||||
? JSON.stringify(queryValues)
|
if (debug) {
|
||||||
: undefined,
|
debugFn(path, "path");
|
||||||
tableName,
|
}
|
||||||
};
|
|
||||||
const queryString = (0, serialize_query_1.default)(Object.assign({}, queryObject));
|
|
||||||
let path = `/api/query/${user_id || grabedHostNames.user_id}/get${queryString}`;
|
|
||||||
/** @type {https.RequestOptions} */
|
|
||||||
const requestObject = {
|
const requestObject = {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: key ||
|
Authorization: (0, grab_api_key_1.default)(key),
|
||||||
process.env.DSQL_READ_ONLY_API_KEY ||
|
|
||||||
process.env.DSQL_FULL_ACCESS_API_KEY ||
|
|
||||||
process.env.DSQL_API_KEY,
|
|
||||||
},
|
},
|
||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
@@ -100,7 +82,7 @@ function get(_a) {
|
|||||||
try {
|
try {
|
||||||
resolve(JSON.parse(str));
|
resolve(JSON.parse(str));
|
||||||
}
|
}
|
||||||
catch ( /** @type {any} */error) {
|
catch (error) {
|
||||||
reject({
|
reject({
|
||||||
error: error.message,
|
error: error.message,
|
||||||
result: str,
|
result: str,
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
import { PostDataPayload, PostReturn } from "../package-shared/types";
|
import { PostDataPayload, PostReturn } from "../types";
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
database?: string;
|
database?: string;
|
||||||
query: PostDataPayload;
|
query: string | PostDataPayload;
|
||||||
queryValues?: any[];
|
queryValues?: any[];
|
||||||
tableName?: string;
|
tableName?: string;
|
||||||
useLocal?: boolean;
|
|
||||||
user_id?: boolean;
|
user_id?: boolean;
|
||||||
|
useLocal?: boolean;
|
||||||
|
debug?: boolean;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* # Make a post request to Datasquirel API
|
* # Make a post request to Datasquirel API
|
||||||
*/
|
*/
|
||||||
export default function post({ key, query, queryValues, database, tableName, useLocal, user_id, }: Param): Promise<PostReturn>;
|
export default function post({ key, query, queryValues, database, tableName, user_id, useLocal, debug, }: Param): Promise<PostReturn>;
|
||||||
export {};
|
export {};
|
||||||
+21
-23
@@ -14,42 +14,41 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = post;
|
exports.default = post;
|
||||||
const path_1 = __importDefault(require("path"));
|
const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const post_1 = __importDefault(require("../functions/api/query/post"));
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const debug_log_1 = __importDefault(require("../utils/logging/debug-log"));
|
||||||
const post_1 = __importDefault(require("../package-shared/functions/api/query/post"));
|
|
||||||
/**
|
/**
|
||||||
* # Make a post request to Datasquirel API
|
* # Make a post request to Datasquirel API
|
||||||
*/
|
*/
|
||||||
function post(_a) {
|
function post(_a) {
|
||||||
return __awaiter(this, arguments, void 0, function* ({ key, query, queryValues, database, tableName, useLocal, user_id, }) {
|
return __awaiter(this, arguments, void 0, function* ({ key, query, queryValues, database, tableName, user_id, useLocal, debug, }) {
|
||||||
const grabedHostNames = (0, grab_host_names_1.default)();
|
const grabedHostNames = (0, grab_host_names_1.default)();
|
||||||
const { host, port, scheme } = grabedHostNames;
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
if (debug) {
|
||||||
|
(0, debug_log_1.default)({
|
||||||
|
log: grabedHostNames,
|
||||||
|
addTime: true,
|
||||||
|
label: "grabedHostNames",
|
||||||
|
});
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Check for local DB settings
|
* Check for local DB settings
|
||||||
*
|
*
|
||||||
* @description Look for local db settings in `.env` file and by pass the http request if available
|
* @description Look for local db settings in `.env` file and by pass the http request if available
|
||||||
*/
|
*/
|
||||||
const { DSQL_DB_HOST, DSQL_DB_USERNAME, DSQL_DB_PASSWORD, DSQL_DB_NAME } = process.env;
|
if (useLocal) {
|
||||||
if ((DSQL_DB_HOST === null || DSQL_DB_HOST === void 0 ? void 0 : DSQL_DB_HOST.match(/./)) &&
|
if (debug) {
|
||||||
(DSQL_DB_USERNAME === null || DSQL_DB_USERNAME === void 0 ? void 0 : DSQL_DB_USERNAME.match(/./)) &&
|
(0, debug_log_1.default)({
|
||||||
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
|
log: "Using Local DB ...",
|
||||||
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
|
addTime: true,
|
||||||
useLocal) {
|
});
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
|
||||||
let dbSchema;
|
|
||||||
try {
|
|
||||||
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
|
||||||
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
|
|
||||||
}
|
}
|
||||||
catch (error) { }
|
|
||||||
return yield (0, post_1.default)({
|
return yield (0, post_1.default)({
|
||||||
dbFullName: DSQL_DB_NAME,
|
dbFullName: database || "",
|
||||||
query,
|
query,
|
||||||
dbSchema,
|
|
||||||
queryValues,
|
queryValues,
|
||||||
tableName,
|
tableName,
|
||||||
useLocal,
|
debug,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -68,8 +67,7 @@ function post(_a) {
|
|||||||
JSON.parse(reqPayloadString);
|
JSON.parse(reqPayloadString);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.log(error);
|
console.log("Error Parsing HTTP response for post action: ", error.message);
|
||||||
console.log(reqPayloadString);
|
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
payload: null,
|
payload: null,
|
||||||
@@ -105,7 +103,7 @@ function post(_a) {
|
|||||||
try {
|
try {
|
||||||
resolve(JSON.parse(str));
|
resolve(JSON.parse(str));
|
||||||
}
|
}
|
||||||
catch ( /** @type {any} */error) {
|
catch (error) {
|
||||||
console.log("Route ERROR:", error.message);
|
console.log("Route ERROR:", error.message);
|
||||||
resolve({
|
resolve({
|
||||||
success: false,
|
success: false,
|
||||||
@@ -14,10 +14,11 @@ type Param = {
|
|||||||
folder?: string;
|
folder?: string;
|
||||||
isPrivate?: boolean;
|
isPrivate?: boolean;
|
||||||
};
|
};
|
||||||
user_id?: boolean;
|
user_id?: string | number;
|
||||||
|
useDefault?: boolean;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* # Upload File via API
|
* # Upload File via API
|
||||||
*/
|
*/
|
||||||
export default function uploadImage({ key, payload, user_id, }: Param): Promise<Return>;
|
export default function uploadImage({ key, payload, user_id, useDefault, }: Param): Promise<Return>;
|
||||||
export {};
|
export {};
|
||||||
@@ -13,13 +13,13 @@ 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
|
||||||
*/
|
*/
|
||||||
function uploadImage(_a) {
|
function uploadImage(_a) {
|
||||||
return __awaiter(this, arguments, void 0, function* ({ key, payload, user_id, }) {
|
return __awaiter(this, arguments, void 0, function* ({ key, payload, user_id, useDefault, }) {
|
||||||
const grabedHostNames = (0, grab_host_names_1.default)();
|
const grabedHostNames = (0, grab_host_names_1.default)({ useDefault });
|
||||||
const { host, port, scheme } = grabedHostNames;
|
const { host, port, scheme } = grabedHostNames;
|
||||||
try {
|
try {
|
||||||
/**
|
/**
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
export interface DSQLUploadImageFunctionReturn {
|
||||||
|
success: boolean;
|
||||||
|
payload: DSQLUploadImagePayload | null;
|
||||||
|
msg?: string;
|
||||||
|
}
|
||||||
|
export interface DSQLUploadImagePayload {
|
||||||
|
urlPath: string;
|
||||||
|
urlThumbnailPath: string;
|
||||||
|
}
|
||||||
|
type Param = {
|
||||||
|
key?: string;
|
||||||
|
payload: {
|
||||||
|
imageData: string;
|
||||||
|
imageName: string;
|
||||||
|
mimeType?: string;
|
||||||
|
thumbnailSize?: number;
|
||||||
|
folder?: string;
|
||||||
|
isPrivate?: boolean;
|
||||||
|
};
|
||||||
|
user_id?: string | number;
|
||||||
|
useDefault?: boolean;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* # Upload Image via API
|
||||||
|
*/
|
||||||
|
export default function uploadImage({ key, payload, user_id, useDefault, }: Param): Promise<DSQLUploadImageFunctionReturn>;
|
||||||
|
export {};
|
||||||
@@ -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,13 +13,13 @@ 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
|
||||||
*/
|
*/
|
||||||
function uploadImage(_a) {
|
function uploadImage(_a) {
|
||||||
return __awaiter(this, arguments, void 0, function* ({ key, payload, user_id, }) {
|
return __awaiter(this, arguments, void 0, function* ({ key, payload, user_id, useDefault, }) {
|
||||||
const grabedHostNames = (0, grab_host_names_1.default)();
|
const grabedHostNames = (0, grab_host_names_1.default)({ useDefault });
|
||||||
const { host, port, scheme } = grabedHostNames;
|
const { host, port, scheme } = grabedHostNames;
|
||||||
try {
|
try {
|
||||||
/**
|
/**
|
||||||
@@ -75,4 +74,3 @@ function uploadImage(_a) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
module.exports = uploadImage;
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { AddUserParams, APIResponseObject } from "../../types";
|
||||||
|
/**
|
||||||
|
* # Add User to Database
|
||||||
|
*/
|
||||||
|
export default function addUser({ apiKey, payload, database, encryptionKey, useLocal, verify, apiVersion, dsqlUserID, }: AddUserParams): Promise<APIResponseObject>;
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
"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.default = addUser;
|
||||||
|
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||||
|
const api_create_user_1 = __importDefault(require("../../functions/api/users/api-create-user"));
|
||||||
|
const grab_api_path_1 = __importDefault(require("../../utils/backend/users/grab-api-path"));
|
||||||
|
const query_dsql_api_1 = __importDefault(require("../../functions/api/query-dsql-api"));
|
||||||
|
/**
|
||||||
|
* # Add User to Database
|
||||||
|
*/
|
||||||
|
function addUser(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ apiKey, payload, database, encryptionKey, useLocal, verify, apiVersion = "v1", dsqlUserID, }) {
|
||||||
|
const grabedHostNames = (0, grab_host_names_1.default)();
|
||||||
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
const apiAddUserParams = {
|
||||||
|
database,
|
||||||
|
encryptionKey,
|
||||||
|
payload,
|
||||||
|
verify,
|
||||||
|
dsqlUserID,
|
||||||
|
};
|
||||||
|
if (useLocal) {
|
||||||
|
return yield (0, api_create_user_1.default)(apiAddUserParams);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Make https request
|
||||||
|
*
|
||||||
|
* @description make a request to datasquirel.com
|
||||||
|
*/
|
||||||
|
const httpResponse = yield (0, query_dsql_api_1.default)({
|
||||||
|
path: (0, grab_api_path_1.default)({
|
||||||
|
paradigm: "auth",
|
||||||
|
action: "signup",
|
||||||
|
database,
|
||||||
|
apiVersion,
|
||||||
|
}),
|
||||||
|
apiKey,
|
||||||
|
body: apiAddUserParams,
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
|
return httpResponse;
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { UpdateUserFunctionReturn } from "../../types";
|
||||||
|
type Param = {
|
||||||
|
apiKey?: string;
|
||||||
|
database: string;
|
||||||
|
deletedUserId: string | number;
|
||||||
|
useLocal?: boolean;
|
||||||
|
apiVersion?: string;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* # Update User
|
||||||
|
*/
|
||||||
|
export default function deleteUser({ apiKey, database, deletedUserId, useLocal, apiVersion, }: Param): Promise<UpdateUserFunctionReturn>;
|
||||||
|
export {};
|
||||||
+17
-29
@@ -13,38 +13,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = deleteUser;
|
exports.default = deleteUser;
|
||||||
const path_1 = __importDefault(require("path"));
|
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const api_delete_user_1 = __importDefault(require("../../functions/api/users/api-delete-user"));
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const grab_api_path_1 = __importDefault(require("../../utils/backend/users/grab-api-path"));
|
||||||
const api_delete_user_1 = __importDefault(require("../package-shared/functions/api/users/api-delete-user"));
|
|
||||||
/**
|
/**
|
||||||
* # Update User
|
* # Update User
|
||||||
*/
|
*/
|
||||||
function deleteUser(_a) {
|
function deleteUser(_a) {
|
||||||
return __awaiter(this, arguments, void 0, function* ({ key, database, user_id, useLocal, deletedUserId, }) {
|
return __awaiter(this, arguments, void 0, function* ({ apiKey, database, deletedUserId, useLocal, apiVersion = "v1", }) {
|
||||||
/**
|
|
||||||
* Check for local DB settings
|
|
||||||
*
|
|
||||||
* @description Look for local db settings in `.env` file and by pass the http request if available
|
|
||||||
*/
|
|
||||||
const { DSQL_DB_HOST, DSQL_DB_USERNAME, DSQL_DB_PASSWORD, DSQL_DB_NAME } = process.env;
|
|
||||||
const grabedHostNames = (0, grab_host_names_1.default)();
|
const grabedHostNames = (0, grab_host_names_1.default)();
|
||||||
const { host, port, scheme } = grabedHostNames;
|
const { host, port, scheme } = grabedHostNames;
|
||||||
if ((DSQL_DB_HOST === null || DSQL_DB_HOST === void 0 ? void 0 : DSQL_DB_HOST.match(/./)) &&
|
if (useLocal) {
|
||||||
(DSQL_DB_USERNAME === null || DSQL_DB_USERNAME === void 0 ? void 0 : DSQL_DB_USERNAME.match(/./)) &&
|
|
||||||
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
|
|
||||||
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
|
|
||||||
useLocal) {
|
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
|
||||||
let dbSchema;
|
|
||||||
try {
|
|
||||||
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
|
||||||
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
|
|
||||||
}
|
|
||||||
catch (error) { }
|
|
||||||
return yield (0, api_delete_user_1.default)({
|
return yield (0, api_delete_user_1.default)({
|
||||||
dbFullName: DSQL_DB_NAME,
|
dbFullName: database,
|
||||||
useLocal,
|
|
||||||
deletedUserId,
|
deletedUserId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -58,18 +39,25 @@ function deleteUser(_a) {
|
|||||||
database,
|
database,
|
||||||
deletedUserId,
|
deletedUserId,
|
||||||
});
|
});
|
||||||
|
const finalAPIKey = apiKey ||
|
||||||
|
process.env.DSQL_API_KEY ||
|
||||||
|
process.env.DSQL_FULL_ACCESS_API_KEY;
|
||||||
const httpsRequest = scheme.request({
|
const httpsRequest = scheme.request({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Content-Length": Buffer.from(reqPayload).length,
|
"Content-Length": Buffer.from(reqPayload).length,
|
||||||
Authorization: process.env.DSQL_FULL_ACCESS_API_KEY ||
|
Authorization: finalAPIKey,
|
||||||
process.env.DSQL_API_KEY ||
|
|
||||||
key,
|
|
||||||
},
|
},
|
||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
path: `/api/user/${user_id || grabedHostNames.user_id}/delete-user`,
|
path: (0, grab_api_path_1.default)({
|
||||||
|
paradigm: "auth",
|
||||||
|
action: "delete",
|
||||||
|
database,
|
||||||
|
apiVersion,
|
||||||
|
userID: deletedUserId,
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Callback Function
|
* Callback Function
|
||||||
+1
-2
@@ -5,7 +5,6 @@ type Param = {
|
|||||||
encryptionKey: string;
|
encryptionKey: string;
|
||||||
encryptionSalt: string;
|
encryptionSalt: string;
|
||||||
database: string;
|
database: string;
|
||||||
useLocal?: boolean;
|
|
||||||
};
|
};
|
||||||
type Return = {
|
type Return = {
|
||||||
key: string | undefined;
|
key: string | undefined;
|
||||||
@@ -17,5 +16,5 @@ type Return = {
|
|||||||
* @description This Function takes in a request object and returns a user token
|
* @description This Function takes in a request object and returns a user token
|
||||||
* string and csrf token string
|
* string and csrf token string
|
||||||
*/
|
*/
|
||||||
export default function getToken({ request, encryptionKey, encryptionSalt, database, useLocal, cookieString, }: Param): Return;
|
export default function getToken({ request, encryptionKey, encryptionSalt, cookieString, }: Param): Return;
|
||||||
export {};
|
export {};
|
||||||
@@ -4,16 +4,16 @@ 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
|
||||||
* ==============================================================================
|
* ==============================================================================
|
||||||
* @description This Function takes in a request object and returns a user token
|
* @description This Function takes in a request object and returns a user token
|
||||||
* string and csrf token string
|
* string and csrf token string
|
||||||
*/
|
*/
|
||||||
function getToken({ request, encryptionKey, encryptionSalt, database, useLocal, cookieString, }) {
|
function getToken({ request, encryptionKey, encryptionSalt, cookieString, }) {
|
||||||
try {
|
try {
|
||||||
/**
|
/**
|
||||||
* Grab the payload
|
* Grab the payload
|
||||||
@@ -61,6 +61,7 @@ function getToken({ request, encryptionKey, encryptionSalt, database, useLocal,
|
|||||||
return { key, csrf };
|
return { key, csrf };
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
console.log("Error Getting Token:", error.message);
|
||||||
/**
|
/**
|
||||||
* Return User Object
|
* Return User Object
|
||||||
*
|
*
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { APIResponseObject, GetUserParams } from "../../types";
|
||||||
|
/**
|
||||||
|
* # Get User
|
||||||
|
*/
|
||||||
|
export default function getUser({ apiKey, userId, database, fields, useLocal, apiVersion, dbUserId, selectAll, }: GetUserParams): Promise<APIResponseObject>;
|
||||||
@@ -13,15 +13,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = getUser;
|
exports.default = getUser;
|
||||||
const path_1 = __importDefault(require("path"));
|
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const api_get_user_1 = __importDefault(require("../../functions/api/users/api-get-user"));
|
||||||
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
|
const grab_api_path_1 = __importDefault(require("../../utils/backend/users/grab-api-path"));
|
||||||
const api_get_user_1 = __importDefault(require("../package-shared/functions/api/users/api-get-user"));
|
|
||||||
/**
|
/**
|
||||||
* # Get User
|
* # Get User
|
||||||
*/
|
*/
|
||||||
function getUser(_a) {
|
function getUser(_a) {
|
||||||
return __awaiter(this, arguments, void 0, function* ({ key, userId, database, fields, apiUserId, useLocal, }) {
|
return __awaiter(this, arguments, void 0, function* ({ apiKey, userId, database, fields, useLocal, apiVersion = "v1", dbUserId, selectAll, }) {
|
||||||
/**
|
/**
|
||||||
* Initialize
|
* Initialize
|
||||||
*/
|
*/
|
||||||
@@ -42,37 +41,17 @@ function getUser(_a) {
|
|||||||
"date_updated_timestamp",
|
"date_updated_timestamp",
|
||||||
];
|
];
|
||||||
const updatedFields = fields && fields[0] ? [...defaultFields, ...fields] : defaultFields;
|
const updatedFields = fields && fields[0] ? [...defaultFields, ...fields] : defaultFields;
|
||||||
const reqPayload = JSON.stringify({
|
|
||||||
userId,
|
|
||||||
database,
|
|
||||||
fields: [...new Set(updatedFields)],
|
|
||||||
});
|
|
||||||
const grabedHostNames = (0, grab_host_names_1.default)();
|
const grabedHostNames = (0, grab_host_names_1.default)();
|
||||||
const { host, port, scheme } = grabedHostNames;
|
const { host, port, scheme } = grabedHostNames;
|
||||||
/**
|
const getUserParams = {
|
||||||
* Check for local DB settings
|
|
||||||
*
|
|
||||||
* @description Look for local db settings in `.env` file and by pass the http request if available
|
|
||||||
*/
|
|
||||||
const { DSQL_DB_HOST, DSQL_DB_USERNAME, DSQL_DB_PASSWORD, DSQL_DB_NAME } = process.env;
|
|
||||||
if ((DSQL_DB_HOST === null || DSQL_DB_HOST === void 0 ? void 0 : DSQL_DB_HOST.match(/./)) &&
|
|
||||||
(DSQL_DB_USERNAME === null || DSQL_DB_USERNAME === void 0 ? void 0 : DSQL_DB_USERNAME.match(/./)) &&
|
|
||||||
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
|
|
||||||
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
|
|
||||||
useLocal) {
|
|
||||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
|
||||||
let dbSchema;
|
|
||||||
try {
|
|
||||||
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
|
||||||
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
|
|
||||||
}
|
|
||||||
catch (error) { }
|
|
||||||
return yield (0, api_get_user_1.default)({
|
|
||||||
userId,
|
userId,
|
||||||
fields: [...new Set(updatedFields)],
|
fields: [...new Set(updatedFields)],
|
||||||
dbFullName: DSQL_DB_NAME,
|
database,
|
||||||
useLocal,
|
dbUserId,
|
||||||
});
|
selectAll,
|
||||||
|
};
|
||||||
|
if (useLocal) {
|
||||||
|
return yield (0, api_get_user_1.default)(getUserParams);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Make https request
|
* Make https request
|
||||||
@@ -80,18 +59,27 @@ function getUser(_a) {
|
|||||||
* @description make a request to datasquirel.com
|
* @description make a request to datasquirel.com
|
||||||
*/
|
*/
|
||||||
const httpResponse = yield new Promise((resolve, reject) => {
|
const httpResponse = yield new Promise((resolve, reject) => {
|
||||||
|
const reqPayload = JSON.stringify(getUserParams);
|
||||||
|
const finalAPIKey = apiKey ||
|
||||||
|
process.env.DSQL_API_KEY ||
|
||||||
|
process.env.DSQL_FULL_ACCESS_API_KEY ||
|
||||||
|
process.env.DSQL_READ_ONLY_API_KEY;
|
||||||
const httpsRequest = scheme.request({
|
const httpsRequest = scheme.request({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Content-Length": Buffer.from(reqPayload).length,
|
"Content-Length": Buffer.from(reqPayload).length,
|
||||||
Authorization: key ||
|
Authorization: finalAPIKey,
|
||||||
process.env.DSQL_FULL_ACCESS_API_KEY ||
|
|
||||||
process.env.DSQL_API_KEY,
|
|
||||||
},
|
},
|
||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
path: `/api/user/${apiUserId || grabedHostNames.user_id}/get-user`,
|
path: (0, grab_api_path_1.default)({
|
||||||
|
paradigm: "auth",
|
||||||
|
action: "get",
|
||||||
|
database,
|
||||||
|
apiVersion,
|
||||||
|
userID: userId,
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Callback Function
|
* Callback Function
|
||||||
@@ -113,9 +101,6 @@ function getUser(_a) {
|
|||||||
httpsRequest.write(reqPayload);
|
httpsRequest.write(reqPayload);
|
||||||
httpsRequest.end();
|
httpsRequest.end();
|
||||||
});
|
});
|
||||||
/** ********************************************** */
|
|
||||||
/** ********************************************** */
|
|
||||||
/** ********************************************** */
|
|
||||||
return httpResponse;
|
return httpResponse;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { APIResponseObject, LoginUserParam } from "../../types";
|
||||||
|
/**
|
||||||
|
* # Login A user
|
||||||
|
*/
|
||||||
|
export default function loginUser({ apiKey, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, skipPassword, apiUserID, skipWriteAuthFile, dbUserId, debug, cleanupTokens, secureCookie, useLocal, apiVersion, }: LoginUserParam): Promise<APIResponseObject>;
|
||||||
+119
@@ -0,0 +1,119 @@
|
|||||||
|
"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.default = loginUser;
|
||||||
|
const api_login_1 = __importDefault(require("../../functions/api/users/api-login"));
|
||||||
|
const debug_log_1 = __importDefault(require("../../utils/logging/debug-log"));
|
||||||
|
const grab_cookie_expirt_date_1 = __importDefault(require("../../utils/grab-cookie-expirt-date"));
|
||||||
|
const grab_api_path_1 = __importDefault(require("../../utils/backend/users/grab-api-path"));
|
||||||
|
const query_dsql_api_1 = __importDefault(require("../../functions/api/query-dsql-api"));
|
||||||
|
const post_login_response_handler_1 = __importDefault(require("../../functions/backend/auth/post-login-response-handler"));
|
||||||
|
function debugFn(log, label) {
|
||||||
|
(0, debug_log_1.default)({ log, addTime: true, title: "loginUser", label });
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* # Login A user
|
||||||
|
*/
|
||||||
|
function loginUser(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ apiKey, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, skipPassword, apiUserID, skipWriteAuthFile, dbUserId, debug, cleanupTokens, secureCookie, useLocal, apiVersion = "v1", }) {
|
||||||
|
const COOKIE_EXPIRY_DATE = (0, grab_cookie_expirt_date_1.default)();
|
||||||
|
const defaultTempLoginFieldName = "temp_login_code";
|
||||||
|
const emailLoginTempCodeFieldName = email_login
|
||||||
|
? temp_code_field
|
||||||
|
? temp_code_field
|
||||||
|
: defaultTempLoginFieldName
|
||||||
|
: undefined;
|
||||||
|
const finalEncryptionKey = encryptionKey || process.env.DSQL_ENCRYPTION_PASSWORD;
|
||||||
|
const finalEncryptionSalt = encryptionSalt || process.env.DSQL_ENCRYPTION_SALT;
|
||||||
|
if (!(finalEncryptionKey === null || finalEncryptionKey === void 0 ? void 0 : finalEncryptionKey.match(/.{8,}/))) {
|
||||||
|
console.log("Encryption key is invalid");
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
payload: null,
|
||||||
|
msg: "Encryption key is invalid",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (!(finalEncryptionSalt === null || finalEncryptionSalt === void 0 ? void 0 : finalEncryptionSalt.match(/.{8,}/))) {
|
||||||
|
console.log("Encryption salt is invalid");
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
payload: null,
|
||||||
|
msg: "Encryption salt is invalid",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Initialize HTTP response variable
|
||||||
|
*/
|
||||||
|
let httpResponse = {
|
||||||
|
success: false,
|
||||||
|
};
|
||||||
|
const apiLoginParams = {
|
||||||
|
database,
|
||||||
|
email: payload.email,
|
||||||
|
username: payload.username,
|
||||||
|
password: payload.password,
|
||||||
|
skipPassword,
|
||||||
|
encryptionKey: finalEncryptionKey,
|
||||||
|
additionalFields,
|
||||||
|
email_login,
|
||||||
|
email_login_code,
|
||||||
|
email_login_field: emailLoginTempCodeFieldName,
|
||||||
|
token,
|
||||||
|
dbUserId,
|
||||||
|
debug,
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Check for local DB settings
|
||||||
|
*
|
||||||
|
* @description Look for local db settings in `.env` file and by pass the http request if available
|
||||||
|
*/
|
||||||
|
if (useLocal) {
|
||||||
|
httpResponse = yield (0, api_login_1.default)(apiLoginParams);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
httpResponse = yield (0, query_dsql_api_1.default)({
|
||||||
|
path: (0, grab_api_path_1.default)({
|
||||||
|
paradigm: "auth",
|
||||||
|
action: "login",
|
||||||
|
database,
|
||||||
|
apiVersion,
|
||||||
|
}),
|
||||||
|
apiKey,
|
||||||
|
body: apiLoginParams,
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (debug) {
|
||||||
|
debugFn(httpResponse, "httpResponse");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* # Send Response
|
||||||
|
*/
|
||||||
|
if (httpResponse === null || httpResponse === void 0 ? void 0 : httpResponse.success) {
|
||||||
|
(0, post_login_response_handler_1.default)({
|
||||||
|
database,
|
||||||
|
httpResponse,
|
||||||
|
cleanupTokens,
|
||||||
|
debug,
|
||||||
|
encryptionKey,
|
||||||
|
encryptionSalt,
|
||||||
|
response,
|
||||||
|
secureCookie,
|
||||||
|
skipWriteAuthFile,
|
||||||
|
token,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return httpResponse;
|
||||||
|
});
|
||||||
|
}
|
||||||
+2
-1
@@ -10,6 +10,7 @@ type Param = {
|
|||||||
cookieString?: string;
|
cookieString?: string;
|
||||||
database?: string;
|
database?: string;
|
||||||
dsqlUserId?: string | number;
|
dsqlUserId?: string | number;
|
||||||
|
debug?: boolean;
|
||||||
};
|
};
|
||||||
type Return = {
|
type Return = {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
@@ -19,5 +20,5 @@ type Return = {
|
|||||||
/**
|
/**
|
||||||
* # Logout user
|
* # Logout user
|
||||||
*/
|
*/
|
||||||
export default function logoutUser({ response, database, dsqlUserId, encryptedUserString, request, cookieString, }: Param): Return;
|
export default function logoutUser({ response, database, dsqlUserId, encryptedUserString, request, cookieString, debug, }: Param): Return;
|
||||||
export {};
|
export {};
|
||||||
+19
-11
@@ -4,15 +4,16 @@ 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 debug_log_1 = __importDefault(require("../../utils/logging/debug-log"));
|
||||||
/**
|
/**
|
||||||
* # Logout user
|
* # Logout user
|
||||||
*/
|
*/
|
||||||
function logoutUser({ response, database, dsqlUserId, encryptedUserString, request, cookieString, }) {
|
function logoutUser({ response, database, dsqlUserId, encryptedUserString, request, cookieString, debug, }) {
|
||||||
/**
|
/**
|
||||||
* Check Encryption Keys
|
* Check Encryption Keys
|
||||||
*
|
*
|
||||||
@@ -21,11 +22,16 @@ function logoutUser({ response, database, dsqlUserId, encryptedUserString, reque
|
|||||||
try {
|
try {
|
||||||
const cookieNames = (0, get_auth_cookie_names_1.default)({
|
const cookieNames = (0, get_auth_cookie_names_1.default)({
|
||||||
database,
|
database,
|
||||||
userId: dsqlUserId || process.env.DSQL_API_USER_ID,
|
|
||||||
});
|
});
|
||||||
|
function debugFn(log, label) {
|
||||||
|
(0, debug_log_1.default)({ log, addTime: true, title: "logoutUser", label });
|
||||||
|
}
|
||||||
|
if (debug) {
|
||||||
|
debugFn(cookieNames, "cookieNames");
|
||||||
|
}
|
||||||
const authKeyName = cookieNames.keyCookieName;
|
const authKeyName = cookieNames.keyCookieName;
|
||||||
const csrfName = cookieNames.csrfCookieName;
|
const csrfName = cookieNames.csrfCookieName;
|
||||||
const oneTimeCodeName = (0, get_auth_cookie_names_1.default)().oneTimeCodeName;
|
const oneTimeCodeName = cookieNames.oneTimeCodeName;
|
||||||
const decryptedUserJSON = (() => {
|
const decryptedUserJSON = (() => {
|
||||||
try {
|
try {
|
||||||
if (request) {
|
if (request) {
|
||||||
@@ -46,11 +52,14 @@ function logoutUser({ response, database, dsqlUserId, encryptedUserString, reque
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( /** @type {any} */error) {
|
catch (error) {
|
||||||
console.log("Error getting decrypted User JSON to logout:", error.message);
|
console.log("Error getting decrypted User JSON to logout:", error.message);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
if (debug) {
|
||||||
|
debugFn(decryptedUserJSON, "decryptedUserJSON");
|
||||||
|
}
|
||||||
if (!decryptedUserJSON)
|
if (!decryptedUserJSON)
|
||||||
throw new Error("Invalid User");
|
throw new Error("Invalid User");
|
||||||
const userObject = ejson_1.default.parse(decryptedUserJSON);
|
const userObject = ejson_1.default.parse(decryptedUserJSON);
|
||||||
@@ -69,7 +78,7 @@ function logoutUser({ response, database, dsqlUserId, encryptedUserString, reque
|
|||||||
cookieNames,
|
cookieNames,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch ( /** @type {any} */error) {
|
catch (error) {
|
||||||
console.log("Logout Error:", error.message);
|
console.log("Logout Error:", error.message);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -77,4 +86,3 @@ function logoutUser({ response, database, dsqlUserId, encryptedUserString, reque
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = logoutUser;
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { APIResponseObject, ResetPasswordParams } from "../../types";
|
||||||
|
/**
|
||||||
|
* # Reset User Password
|
||||||
|
*/
|
||||||
|
export default function resetPassword(params: ResetPasswordParams): Promise<APIResponseObject>;
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
"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.default = resetPassword;
|
||||||
|
const query_dsql_api_1 = __importDefault(require("../../functions/api/query-dsql-api"));
|
||||||
|
const grab_api_path_1 = __importDefault(require("../../utils/backend/users/grab-api-path"));
|
||||||
|
const api_reset_user_password_1 = __importDefault(require("../../functions/api/users/api-reset-user-password"));
|
||||||
|
/**
|
||||||
|
* # Reset User Password
|
||||||
|
*/
|
||||||
|
function resetPassword(params) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (params.useLocal) {
|
||||||
|
return yield (0, api_reset_user_password_1.default)(params);
|
||||||
|
}
|
||||||
|
const httpResponse = yield (0, query_dsql_api_1.default)({
|
||||||
|
path: (0, grab_api_path_1.default)({
|
||||||
|
paradigm: "auth",
|
||||||
|
action: "reset-password",
|
||||||
|
database: params.database,
|
||||||
|
apiVersion: params.apiVersion,
|
||||||
|
}),
|
||||||
|
apiKey: params.apiKey,
|
||||||
|
body: params,
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
|
return httpResponse;
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { APIResponseObject, SendEmailCodeParams } from "../../types";
|
||||||
|
/**
|
||||||
|
* # Send Email Code to a User
|
||||||
|
*/
|
||||||
|
export default function sendEmailCode(params: SendEmailCodeParams): Promise<APIResponseObject>;
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
"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.default = sendEmailCode;
|
||||||
|
const api_send_email_code_1 = __importDefault(require("../../functions/api/users/api-send-email-code"));
|
||||||
|
const grab_api_path_1 = __importDefault(require("../../utils/backend/users/grab-api-path"));
|
||||||
|
const query_dsql_api_1 = __importDefault(require("../../functions/api/query-dsql-api"));
|
||||||
|
/**
|
||||||
|
* # Send Email Code to a User
|
||||||
|
*/
|
||||||
|
function sendEmailCode(params) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const { apiKey, email, database, temp_code_field_name, mail_domain, mail_password, mail_username, mail_port, sender, response, extraCookies, useLocal, apiVersion, html, } = params;
|
||||||
|
const defaultTempLoginFieldName = "temp_login_code";
|
||||||
|
const emailLoginTempCodeFieldName = temp_code_field_name
|
||||||
|
? temp_code_field_name
|
||||||
|
: defaultTempLoginFieldName;
|
||||||
|
const emailHtml = html ||
|
||||||
|
`<p>Please use this code to login</p>\n<h2>{{code}}</h2>\n<p>Please note that this code expires after 15 minutes</p>`;
|
||||||
|
const apiSendEmailCodeParams = {
|
||||||
|
database,
|
||||||
|
email,
|
||||||
|
email_login_field: emailLoginTempCodeFieldName,
|
||||||
|
html: emailHtml,
|
||||||
|
mail_domain,
|
||||||
|
mail_password,
|
||||||
|
mail_port,
|
||||||
|
mail_username,
|
||||||
|
sender,
|
||||||
|
response,
|
||||||
|
extraCookies,
|
||||||
|
};
|
||||||
|
if (useLocal) {
|
||||||
|
return yield (0, api_send_email_code_1.default)(apiSendEmailCodeParams);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const httpResponse = yield (0, query_dsql_api_1.default)({
|
||||||
|
path: (0, grab_api_path_1.default)({
|
||||||
|
paradigm: "auth",
|
||||||
|
action: "send-email-code",
|
||||||
|
database,
|
||||||
|
apiVersion,
|
||||||
|
}),
|
||||||
|
apiKey,
|
||||||
|
body: apiSendEmailCodeParams,
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
|
return httpResponse;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
Vendored
+3
-2
@@ -15,7 +15,7 @@ type Param = {
|
|||||||
key: string;
|
key: string;
|
||||||
code: string;
|
code: string;
|
||||||
email: string | null;
|
email: string | null;
|
||||||
database: string;
|
database?: string;
|
||||||
clientId: string;
|
clientId: string;
|
||||||
clientSecret: string;
|
clientSecret: string;
|
||||||
response: http.ServerResponse;
|
response: http.ServerResponse;
|
||||||
@@ -26,9 +26,10 @@ type Param = {
|
|||||||
[s: string]: string | number;
|
[s: string]: string | number;
|
||||||
};
|
};
|
||||||
user_id?: boolean;
|
user_id?: boolean;
|
||||||
|
secureCookie?: boolean;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* # SERVER FUNCTION: Login with google Function
|
* # SERVER FUNCTION: Login with google Function
|
||||||
*/
|
*/
|
||||||
export default function githubAuth({ key, code, email, database, clientId, clientSecret, response, encryptionKey, encryptionSalt, additionalFields, user_id, additionalData, }: Param): Promise<FunctionReturn | undefined>;
|
export default function githubAuth({ key, code, email, database, clientId, clientSecret, response, encryptionKey, encryptionSalt, additionalFields, user_id, additionalData, secureCookie, }: Param): Promise<FunctionReturn | undefined>;
|
||||||
export {};
|
export {};
|
||||||
+14
-12
@@ -15,14 +15,16 @@ 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"));
|
||||||
|
const grab_cookie_expirt_date_1 = __importDefault(require("../../../utils/grab-cookie-expirt-date"));
|
||||||
|
const grab_db_names_1 = __importDefault(require("../../../utils/grab-db-names"));
|
||||||
/**
|
/**
|
||||||
* # SERVER FUNCTION: Login with google Function
|
* # SERVER FUNCTION: Login with google Function
|
||||||
*/
|
*/
|
||||||
function githubAuth(_a) {
|
function githubAuth(_a) {
|
||||||
return __awaiter(this, arguments, void 0, function* ({ key, code, email, database, clientId, clientSecret, response, encryptionKey, encryptionSalt, additionalFields, user_id, additionalData, }) {
|
return __awaiter(this, arguments, void 0, function* ({ key, code, email, database, clientId, clientSecret, response, encryptionKey, encryptionSalt, additionalFields, user_id, additionalData, secureCookie, }) {
|
||||||
/**
|
/**
|
||||||
* Check inputs
|
* Check inputs
|
||||||
*
|
*
|
||||||
@@ -30,6 +32,7 @@ function githubAuth(_a) {
|
|||||||
*/
|
*/
|
||||||
const grabedHostNames = (0, grab_host_names_1.default)();
|
const grabedHostNames = (0, grab_host_names_1.default)();
|
||||||
const { host, port, scheme } = grabedHostNames;
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
const COOKIE_EXPIRY_DATE = (0, grab_cookie_expirt_date_1.default)();
|
||||||
if (!code || (code === null || code === void 0 ? void 0 : code.match(/ /))) {
|
if (!code || (code === null || code === void 0 ? void 0 : code.match(/ /))) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -60,25 +63,26 @@ function githubAuth(_a) {
|
|||||||
*
|
*
|
||||||
* @description Look for local db settings in `.env` file and by pass the http request if available
|
* @description Look for local db settings in `.env` file and by pass the http request if available
|
||||||
*/
|
*/
|
||||||
const { DSQL_DB_HOST, DSQL_DB_USERNAME, DSQL_DB_PASSWORD, DSQL_DB_NAME, DSQL_KEY, DSQL_REF_DB_NAME, DSQL_FULL_SYNC, } = process.env;
|
const { DSQL_DB_HOST, DSQL_DB_USERNAME, DSQL_DB_PASSWORD, DSQL_DB_NAME } = process.env;
|
||||||
if ((DSQL_DB_HOST === null || DSQL_DB_HOST === void 0 ? void 0 : DSQL_DB_HOST.match(/./)) &&
|
if ((DSQL_DB_HOST === null || DSQL_DB_HOST === void 0 ? void 0 : DSQL_DB_HOST.match(/./)) &&
|
||||||
(DSQL_DB_USERNAME === null || DSQL_DB_USERNAME === void 0 ? void 0 : DSQL_DB_USERNAME.match(/./)) &&
|
(DSQL_DB_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");
|
||||||
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
|
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
|
||||||
}
|
}
|
||||||
catch (error) { }
|
catch (error) { }
|
||||||
|
const { dbFullName } = (0, grab_db_names_1.default)({ dbName: database });
|
||||||
httpResponse = yield (0, api_github_login_1.default)({
|
httpResponse = yield (0, api_github_login_1.default)({
|
||||||
code,
|
code,
|
||||||
email: email || undefined,
|
email: email || undefined,
|
||||||
clientId,
|
clientId,
|
||||||
clientSecret,
|
clientSecret,
|
||||||
additionalFields,
|
additionalFields,
|
||||||
database: DSQL_DB_NAME,
|
database: dbFullName,
|
||||||
additionalData,
|
additionalData,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -127,7 +131,7 @@ function githubAuth(_a) {
|
|||||||
resolve(JSON.parse(str));
|
resolve(JSON.parse(str));
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.log(error);
|
console.log("Github Auth Error:", error.message);
|
||||||
resolve({
|
resolve({
|
||||||
success: false,
|
success: false,
|
||||||
user: null,
|
user: null,
|
||||||
@@ -161,10 +165,8 @@ function githubAuth(_a) {
|
|||||||
const authKeyName = `datasquirel_${dsqlUserId}_${database}_auth_key`;
|
const authKeyName = `datasquirel_${dsqlUserId}_${database}_auth_key`;
|
||||||
const csrfName = `datasquirel_${dsqlUserId}_${database}_csrf`;
|
const csrfName = `datasquirel_${dsqlUserId}_${database}_csrf`;
|
||||||
response.setHeader("Set-Cookie", [
|
response.setHeader("Set-Cookie", [
|
||||||
`${authKeyName}=${encryptedPayload};samesite=strict;path=/;HttpOnly=true;Secure=true`,
|
`${authKeyName}=${encryptedPayload};samesite=strict;path=/;HttpOnly=true;Expires=${COOKIE_EXPIRY_DATE}${secureCookie ? ";Secure=true" : ""}`,
|
||||||
`${csrfName}=${user.csrf_k};samesite=strict;path=/;HttpOnly=true`,
|
`${csrfName}=${user.csrf_k};samesite=strict;path=/;HttpOnly=true;Expires=${COOKIE_EXPIRY_DATE}`,
|
||||||
`dsqluid=${dsqlUserId};samesite=strict;path=/;HttpOnly=true`,
|
|
||||||
`datasquirel_social_id=${user.social_id};samesite=strict;path=/`,
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
return httpResponse;
|
return httpResponse;
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { APIResponseObject, GoogleAuthParams } from "../../../types";
|
||||||
|
/**
|
||||||
|
* # SERVER FUNCTION: Login with google Function
|
||||||
|
*/
|
||||||
|
export default function googleAuth({ apiKey, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, debug, secureCookie, loginOnly, useLocal, apiVersion, skipWriteAuthFile, cleanupTokens, }: GoogleAuthParams): Promise<APIResponseObject>;
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
"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.default = googleAuth;
|
||||||
|
const api_google_login_1 = __importDefault(require("../../../functions/api/users/social/api-google-login"));
|
||||||
|
const query_dsql_api_1 = __importDefault(require("../../../functions/api/query-dsql-api"));
|
||||||
|
const grab_api_path_1 = __importDefault(require("../../../utils/backend/users/grab-api-path"));
|
||||||
|
const post_login_response_handler_1 = __importDefault(require("../../../functions/backend/auth/post-login-response-handler"));
|
||||||
|
/**
|
||||||
|
* # SERVER FUNCTION: Login with google Function
|
||||||
|
*/
|
||||||
|
function googleAuth(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ apiKey, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, debug, secureCookie, loginOnly, useLocal, apiVersion, skipWriteAuthFile, cleanupTokens, }) {
|
||||||
|
const finalEncryptionKey = encryptionKey || process.env.DSQL_ENCRYPTION_PASSWORD;
|
||||||
|
const finalEncryptionSalt = encryptionSalt || process.env.DSQL_ENCRYPTION_SALT;
|
||||||
|
if (!(finalEncryptionKey === null || finalEncryptionKey === void 0 ? void 0 : finalEncryptionKey.match(/.{8,}/))) {
|
||||||
|
console.log("Encryption key is invalid");
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
payload: null,
|
||||||
|
msg: "Encryption key is invalid",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (!(finalEncryptionSalt === null || finalEncryptionSalt === void 0 ? void 0 : finalEncryptionSalt.match(/.{8,}/))) {
|
||||||
|
console.log("Encryption salt is invalid");
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
payload: null,
|
||||||
|
msg: "Encryption salt is invalid",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Check inputs
|
||||||
|
*
|
||||||
|
* @description Check inputs
|
||||||
|
*/
|
||||||
|
if (!token || (token === null || token === void 0 ? void 0 : token.match(/ /))) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
payload: null,
|
||||||
|
msg: "Please enter Google Access Token",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Initialize HTTP response variable
|
||||||
|
*/
|
||||||
|
let httpResponse = {
|
||||||
|
success: false,
|
||||||
|
};
|
||||||
|
const googleAuthParams = {
|
||||||
|
token,
|
||||||
|
additionalFields,
|
||||||
|
additionalData,
|
||||||
|
debug,
|
||||||
|
loginOnly,
|
||||||
|
database,
|
||||||
|
};
|
||||||
|
if (useLocal) {
|
||||||
|
if (debug) {
|
||||||
|
console.log(`Google login with Local Paradigm ...`);
|
||||||
|
}
|
||||||
|
httpResponse = yield (0, api_google_login_1.default)(googleAuthParams);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
httpResponse = yield (0, query_dsql_api_1.default)({
|
||||||
|
path: (0, grab_api_path_1.default)({
|
||||||
|
paradigm: "auth",
|
||||||
|
action: "google-login",
|
||||||
|
database,
|
||||||
|
apiVersion,
|
||||||
|
}),
|
||||||
|
apiKey,
|
||||||
|
body: googleAuthParams,
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Make https request
|
||||||
|
*
|
||||||
|
* @description make a request to datasquirel.com
|
||||||
|
*/
|
||||||
|
if ((httpResponse === null || httpResponse === void 0 ? void 0 : httpResponse.success) && (httpResponse === null || httpResponse === void 0 ? void 0 : httpResponse.singleRes) && database) {
|
||||||
|
(0, post_login_response_handler_1.default)({
|
||||||
|
database,
|
||||||
|
httpResponse,
|
||||||
|
cleanupTokens,
|
||||||
|
debug,
|
||||||
|
encryptionKey,
|
||||||
|
encryptionSalt,
|
||||||
|
response,
|
||||||
|
secureCookie,
|
||||||
|
skipWriteAuthFile,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return httpResponse;
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { APIResponseObject, UpdateUserParams } from "../../types";
|
||||||
|
import { DSQL_DATASQUIREL_USERS } from "../../types/dsql";
|
||||||
|
/**
|
||||||
|
* # Update User
|
||||||
|
*/
|
||||||
|
export default function updateUser<T extends DSQL_DATASQUIREL_USERS = DSQL_DATASQUIREL_USERS & {
|
||||||
|
[k: string]: any;
|
||||||
|
}>({ payload, database, updatedUserId, useLocal, apiKey, apiVersion, dbUserId, }: UpdateUserParams<T>): Promise<APIResponseObject>;
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
"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.default = updateUser;
|
||||||
|
const api_update_user_1 = __importDefault(require("../../functions/api/users/api-update-user"));
|
||||||
|
const query_dsql_api_1 = __importDefault(require("../../functions/api/query-dsql-api"));
|
||||||
|
const grab_api_path_1 = __importDefault(require("../../utils/backend/users/grab-api-path"));
|
||||||
|
/**
|
||||||
|
* # Update User
|
||||||
|
*/
|
||||||
|
function updateUser(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ payload, database, updatedUserId, useLocal, apiKey, apiVersion, dbUserId, }) {
|
||||||
|
const updateUserParams = {
|
||||||
|
payload: payload,
|
||||||
|
database,
|
||||||
|
updatedUserId,
|
||||||
|
dbUserId,
|
||||||
|
};
|
||||||
|
if (useLocal) {
|
||||||
|
return yield (0, api_update_user_1.default)(updateUserParams);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Make https request
|
||||||
|
*
|
||||||
|
* @description make a request to datasquirel.com
|
||||||
|
*/
|
||||||
|
const httpResponse = yield (0, query_dsql_api_1.default)({
|
||||||
|
path: (0, grab_api_path_1.default)({
|
||||||
|
paradigm: "auth",
|
||||||
|
action: "update",
|
||||||
|
database,
|
||||||
|
apiVersion,
|
||||||
|
}),
|
||||||
|
apiKey,
|
||||||
|
body: updateUserParams,
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
|
return httpResponse;
|
||||||
|
});
|
||||||
|
}
|
||||||
+4
-4
@@ -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;
|
||||||
@@ -13,10 +13,10 @@ type Param = {
|
|||||||
encryptionSalt?: string;
|
encryptionSalt?: string;
|
||||||
level?: "deep" | "normal";
|
level?: "deep" | "normal";
|
||||||
database?: string;
|
database?: string;
|
||||||
dsqlUserId?: string | number;
|
|
||||||
expiry?: number;
|
expiry?: number;
|
||||||
csrfHeaderName?: string;
|
csrfHeaderName?: string;
|
||||||
csrfHeaderIsValue?: boolean;
|
debug?: boolean;
|
||||||
|
skipFileCheck?: boolean;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Authenticate User from request
|
* Authenticate User from request
|
||||||
@@ -24,5 +24,5 @@ type Param = {
|
|||||||
* @description This Function takes in a request object and returns a user object
|
* @description This Function takes in a request object and returns a user object
|
||||||
* with the user's data
|
* with the user's data
|
||||||
*/
|
*/
|
||||||
export default function userAuth({ request, req, encryptionKey, encryptionSalt, level, database, dsqlUserId, encryptedUserString, expiry, cookieString, csrfHeaderIsValue, csrfHeaderName, }: Param): AuthenticatedUser;
|
export default function userAuth({ request, req, encryptionKey, encryptionSalt, level, database, encryptedUserString, expiry, cookieString, csrfHeaderName, debug, skipFileCheck, }: Param): AuthenticatedUser;
|
||||||
export {};
|
export {};
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
// @ts-check
|
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
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 });
|
||||||
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("../../actions/get-csrf-header-name"));
|
||||||
|
const debug_log_1 = __importDefault(require("../../utils/logging/debug-log"));
|
||||||
const minuteInMilliseconds = 60000;
|
const minuteInMilliseconds = 60000;
|
||||||
const hourInMilliseconds = minuteInMilliseconds * 60;
|
const hourInMilliseconds = minuteInMilliseconds * 60;
|
||||||
const dayInMilliseconds = hourInMilliseconds * 24;
|
const dayInMilliseconds = hourInMilliseconds * 24;
|
||||||
@@ -21,25 +22,40 @@ const yearInMilliseconds = dayInMilliseconds * 365;
|
|||||||
* @description This Function takes in a request object and returns a user object
|
* @description This Function takes in a request object and returns a user object
|
||||||
* with the user's data
|
* with the user's data
|
||||||
*/
|
*/
|
||||||
function userAuth({ request, req, encryptionKey, encryptionSalt, level, database, dsqlUserId, encryptedUserString, expiry = weekInMilliseconds, cookieString, csrfHeaderIsValue, csrfHeaderName, }) {
|
function userAuth({ request, req, encryptionKey, encryptionSalt, level, database, encryptedUserString, expiry = weekInMilliseconds, cookieString, csrfHeaderName, debug, skipFileCheck, }) {
|
||||||
try {
|
try {
|
||||||
const finalRequest = req || request;
|
const finalRequest = req || request;
|
||||||
const finalEncryptionKey = encryptionKey || process.env.DSQL_ENCRYPTION_PASSWORD;
|
|
||||||
const finalEncryptionSalt = encryptionSalt || process.env.DSQL_ENCRYPTION_SALT;
|
|
||||||
const cookies = (0, parseCookies_1.default)({
|
const cookies = (0, parseCookies_1.default)({
|
||||||
request: finalRequest,
|
request: finalRequest,
|
||||||
cookieString,
|
cookieString,
|
||||||
});
|
});
|
||||||
const keyNames = (0, get_auth_cookie_names_1.default)({
|
if (debug) {
|
||||||
userId: dsqlUserId || process.env.DSQL_API_USER_ID,
|
(0, debug_log_1.default)({
|
||||||
database: database || process.env.DSQL_DB_NAME,
|
log: cookies,
|
||||||
|
addTime: true,
|
||||||
|
label: "userAuth:cookies",
|
||||||
});
|
});
|
||||||
const authKeyName = keyNames.keyCookieName;
|
}
|
||||||
const csrfName = keyNames.csrfCookieName;
|
const keyNames = (0, get_auth_cookie_names_1.default)({
|
||||||
|
database,
|
||||||
|
});
|
||||||
|
if (debug) {
|
||||||
|
(0, debug_log_1.default)({
|
||||||
|
log: keyNames,
|
||||||
|
addTime: true,
|
||||||
|
label: "userAuth:keyNames",
|
||||||
|
});
|
||||||
|
}
|
||||||
const key = encryptedUserString
|
const key = encryptedUserString
|
||||||
? encryptedUserString
|
? encryptedUserString
|
||||||
: cookies[authKeyName];
|
: cookies[keyNames.keyCookieName];
|
||||||
const csrf = cookies[csrfName];
|
if (debug) {
|
||||||
|
(0, debug_log_1.default)({
|
||||||
|
log: key,
|
||||||
|
addTime: true,
|
||||||
|
label: "userAuth:key",
|
||||||
|
});
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Grab the payload
|
* Grab the payload
|
||||||
*
|
*
|
||||||
@@ -47,9 +63,16 @@ function userAuth({ request, req, encryptionKey, encryptionSalt, level, database
|
|||||||
*/
|
*/
|
||||||
let userPayloadJSON = (0, decrypt_1.default)({
|
let userPayloadJSON = (0, decrypt_1.default)({
|
||||||
encryptedString: key,
|
encryptedString: key,
|
||||||
encryptionKey: finalEncryptionKey,
|
encryptionKey,
|
||||||
encryptionSalt: finalEncryptionSalt,
|
encryptionSalt,
|
||||||
});
|
});
|
||||||
|
if (debug) {
|
||||||
|
(0, debug_log_1.default)({
|
||||||
|
log: userPayloadJSON,
|
||||||
|
addTime: true,
|
||||||
|
label: "userAuth:userPayloadJSON",
|
||||||
|
});
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Grab the payload
|
* Grab the payload
|
||||||
*
|
*
|
||||||
@@ -60,27 +83,31 @@ function userAuth({ request, req, encryptionKey, encryptionSalt, level, database
|
|||||||
success: false,
|
success: false,
|
||||||
payload: null,
|
payload: null,
|
||||||
msg: "Couldn't Decrypt cookie",
|
msg: "Couldn't Decrypt cookie",
|
||||||
|
cookieNames: keyNames,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Grab the payload
|
|
||||||
*
|
|
||||||
* @description Grab the payload
|
|
||||||
*/
|
|
||||||
/** @type {import("../package-shared/types").DATASQUIREL_LoggedInUser} */
|
|
||||||
let userObject = JSON.parse(userPayloadJSON);
|
let userObject = JSON.parse(userPayloadJSON);
|
||||||
|
if (debug) {
|
||||||
|
(0, debug_log_1.default)({
|
||||||
|
log: userObject,
|
||||||
|
addTime: true,
|
||||||
|
label: "userAuth:userObject",
|
||||||
|
});
|
||||||
|
}
|
||||||
if (!userObject.csrf_k) {
|
if (!userObject.csrf_k) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
payload: null,
|
payload: null,
|
||||||
msg: "No CSRF_K in decrypted payload",
|
msg: "No CSRF_K in decrypted payload",
|
||||||
|
cookieNames: keyNames,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (!(0, write_auth_files_1.checkAuthFile)(userObject.csrf_k)) {
|
if (!skipFileCheck && !(0, write_auth_files_1.checkAuthFile)(userObject.csrf_k)) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
payload: null,
|
payload: null,
|
||||||
msg: "Auth file doesn't exist",
|
msg: "Auth file doesn't exist",
|
||||||
|
cookieNames: keyNames,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -89,22 +116,13 @@ function userAuth({ request, req, encryptionKey, encryptionSalt, level, database
|
|||||||
* @description Grab the payload
|
* @description Grab the payload
|
||||||
*/
|
*/
|
||||||
if ((level === null || level === void 0 ? void 0 : level.match(/deep/i)) && finalRequest) {
|
if ((level === null || level === void 0 ? void 0 : level.match(/deep/i)) && finalRequest) {
|
||||||
if (csrfHeaderName &&
|
const finalCsrfHeaderName = csrfHeaderName || (0, get_csrf_header_name_1.default)();
|
||||||
finalRequest.headers[csrfHeaderName] !== userObject.csrf_k) {
|
if (finalRequest.headers[finalCsrfHeaderName] !== userObject.csrf_k) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
payload: null,
|
payload: null,
|
||||||
msg: "CSRF_K mismatch",
|
msg: "CSRF_K mismatch",
|
||||||
};
|
cookieNames: keyNames,
|
||||||
}
|
|
||||||
const targetCsrfHeaderKey = Object.keys(finalRequest.headers)
|
|
||||||
.map((k) => k.replace(/[^a-zA-Z0-9\-]/g, ""))
|
|
||||||
.find((k) => k == userObject.csrf_k);
|
|
||||||
if (csrfHeaderIsValue && !targetCsrfHeaderKey) {
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
payload: null,
|
|
||||||
msg: "CSRF_K Header Key mismatch",
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,6 +133,7 @@ function userAuth({ request, req, encryptionKey, encryptionSalt, level, database
|
|||||||
success: false,
|
success: false,
|
||||||
payload: null,
|
payload: null,
|
||||||
msg: "Payload Creation Date is not a number",
|
msg: "Payload Creation Date is not a number",
|
||||||
|
cookieNames: keyNames,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const timeElapsed = Date.now() - payloadCreationDate;
|
const timeElapsed = Date.now() - payloadCreationDate;
|
||||||
@@ -126,6 +145,7 @@ function userAuth({ request, req, encryptionKey, encryptionSalt, level, database
|
|||||||
success: false,
|
success: false,
|
||||||
payload: null,
|
payload: null,
|
||||||
msg: "Session has expired",
|
msg: "Session has expired",
|
||||||
|
cookieNames: keyNames,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -138,7 +158,7 @@ function userAuth({ request, req, encryptionKey, encryptionSalt, level, database
|
|||||||
payload: userObject,
|
payload: userObject,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch ( /** @type {any} */error) {
|
catch (error) {
|
||||||
/**
|
/**
|
||||||
* Return User Object
|
* Return User Object
|
||||||
*
|
*
|
||||||
+3
-2
@@ -1,14 +1,15 @@
|
|||||||
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;
|
||||||
};
|
};
|
||||||
cookieString?: string;
|
cookieString?: string;
|
||||||
email?: string;
|
email?: string;
|
||||||
|
code?: string;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* # Verify the temp email code sent to the user's email address
|
* # Verify the temp email code sent to the user's email address
|
||||||
*/
|
*/
|
||||||
export default function validateTempEmailCode({ request, email, cookieString, }: Param): Promise<SendOneTimeCodeEmailResponse | null>;
|
export default function validateTempEmailCode({ request, email, cookieString, code, }: Param): Promise<SendOneTimeCodeEmailResponse | null>;
|
||||||
export {};
|
export {};
|
||||||
+5
-5
@@ -13,15 +13,15 @@ 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
|
||||||
*/
|
*/
|
||||||
function validateTempEmailCode(_a) {
|
function validateTempEmailCode(_a) {
|
||||||
return __awaiter(this, arguments, void 0, function* ({ request, email, cookieString, }) {
|
return __awaiter(this, arguments, void 0, function* ({ request, email, cookieString, code, }) {
|
||||||
try {
|
try {
|
||||||
const keyNames = (0, get_auth_cookie_names_1.default)();
|
const keyNames = (0, get_auth_cookie_names_1.default)();
|
||||||
const oneTimeCodeCookieName = keyNames.oneTimeCodeName;
|
const oneTimeCodeCookieName = keyNames.oneTimeCodeName;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { APIPathsCrudParams, APIResponseObject } from "../../types";
|
||||||
|
export default function <T extends {
|
||||||
|
[k: string]: any;
|
||||||
|
} = {
|
||||||
|
[k: string]: any;
|
||||||
|
}>({ table, body, targetId, query, }: APIPathsCrudParams<T>): Promise<APIResponseObject>;
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
"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.default = default_1;
|
||||||
|
const crud_1 = __importDefault(require("../../utils/data-fetching/crud"));
|
||||||
|
function default_1(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ table, body, targetId, query, }) {
|
||||||
|
if (!targetId && !(body === null || body === void 0 ? void 0 : body.searchQuery)) {
|
||||||
|
throw new Error(`Target ID or \`searchQuery\` field is required to delete Data.`);
|
||||||
|
}
|
||||||
|
const DELETE_RESLT = yield (0, crud_1.default)(Object.assign(Object.assign({}, body === null || body === void 0 ? void 0 : body.crudParams), { action: "delete", table, query: query === null || query === void 0 ? void 0 : query.searchQuery, targetId }));
|
||||||
|
return DELETE_RESLT;
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { APIPathsCrudParams, APIResponseObject } from "../../types";
|
||||||
|
export default function <T extends {
|
||||||
|
[k: string]: any;
|
||||||
|
} = {
|
||||||
|
[k: string]: any;
|
||||||
|
}>({ table, query, allowedTable, url, }: APIPathsCrudParams<T>): Promise<APIResponseObject>;
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
"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.default = default_1;
|
||||||
|
const crud_1 = __importDefault(require("../../utils/data-fetching/crud"));
|
||||||
|
function default_1(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ table, query, allowedTable, url, }) {
|
||||||
|
var _b, _c;
|
||||||
|
if (((allowedTable === null || allowedTable === void 0 ? void 0 : allowedTable.allowedFields) || (allowedTable === null || allowedTable === void 0 ? void 0 : allowedTable.disallowedFields)) &&
|
||||||
|
!((_c = (_b = query === null || query === void 0 ? void 0 : query.searchQuery) === null || _b === void 0 ? void 0 : _b.selectFields) === null || _c === void 0 ? void 0 : _c[0])) {
|
||||||
|
throw new Error(`Please specify fields to select! Use the \`selectFields\` option in the query object`);
|
||||||
|
}
|
||||||
|
const GET_RESULT = yield (0, crud_1.default)(Object.assign(Object.assign({}, query === null || query === void 0 ? void 0 : query.crudParams), { action: "get", table, query: query === null || query === void 0 ? void 0 : query.searchQuery }));
|
||||||
|
return GET_RESULT;
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { APIPathsCrudParams, APIResponseObject } from "../../types";
|
||||||
|
export default function <T extends {
|
||||||
|
[k: string]: any;
|
||||||
|
} = {
|
||||||
|
[k: string]: any;
|
||||||
|
}>({ table, body }: APIPathsCrudParams<T>): Promise<APIResponseObject>;
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
"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.default = default_1;
|
||||||
|
const crud_1 = __importDefault(require("../../utils/data-fetching/crud"));
|
||||||
|
function default_1(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ table, body }) {
|
||||||
|
const POST_RESULT = yield (0, crud_1.default)(Object.assign(Object.assign({}, body === null || body === void 0 ? void 0 : body.crudParams), { action: "insert", table, data: body === null || body === void 0 ? void 0 : body.data, batchData: body === null || body === void 0 ? void 0 : body.batchData }));
|
||||||
|
return POST_RESULT;
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { APIPathsCrudParams, APIResponseObject } from "../../types";
|
||||||
|
export default function <T extends {
|
||||||
|
[k: string]: any;
|
||||||
|
} = {
|
||||||
|
[k: string]: any;
|
||||||
|
}>({ table, body, targetId, query, }: APIPathsCrudParams<T>): Promise<APIResponseObject>;
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
"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.default = default_1;
|
||||||
|
const crud_1 = __importDefault(require("../../utils/data-fetching/crud"));
|
||||||
|
function default_1(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ table, body, targetId, query, }) {
|
||||||
|
if (!targetId && !(body === null || body === void 0 ? void 0 : body.searchQuery)) {
|
||||||
|
throw new Error(`Target ID or \`searchQuery\` field is required to update Data.`);
|
||||||
|
}
|
||||||
|
const PUT_RESULT = yield (0, crud_1.default)(Object.assign(Object.assign({}, body === null || body === void 0 ? void 0 : body.crudParams), { action: "update", table, data: body === null || body === void 0 ? void 0 : body.data, query: query === null || query === void 0 ? void 0 : query.searchQuery, targetId }));
|
||||||
|
return PUT_RESULT;
|
||||||
|
});
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
import { APIPathsParams, APIResponseObject } from "../types";
|
||||||
|
export default function apiCrudHandler<T extends {
|
||||||
|
[k: string]: any;
|
||||||
|
} = {
|
||||||
|
[k: string]: any;
|
||||||
|
}>(params: APIPathsParams<T>): Promise<APIResponseObject>;
|
||||||
+116
@@ -0,0 +1,116 @@
|
|||||||
|
"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.default = apiCrudHandler;
|
||||||
|
const lodash_1 = __importDefault(require("lodash"));
|
||||||
|
const get_result_1 = __importDefault(require("./functions/get-result"));
|
||||||
|
const grab_path_data_1 = require("./utils/grab-path-data");
|
||||||
|
const checks_1 = __importDefault(require("./utils/checks"));
|
||||||
|
const post_result_1 = __importDefault(require("./functions/post-result"));
|
||||||
|
const put_result_1 = __importDefault(require("./functions/put-result"));
|
||||||
|
const delete_result_1 = __importDefault(require("./functions/delete-result"));
|
||||||
|
function apiCrudHandler(params) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
var _a, _b, _c;
|
||||||
|
try {
|
||||||
|
const { auth, method } = params;
|
||||||
|
const isAuthorized = yield (auth === null || auth === void 0 ? void 0 : auth());
|
||||||
|
const { table, targetId, url, query } = (0, grab_path_data_1.grabPathData)(params);
|
||||||
|
const crudParams = Object.assign(Object.assign({}, params), { isAuthorized,
|
||||||
|
table,
|
||||||
|
targetId });
|
||||||
|
const checkedObj = yield (0, checks_1.default)(Object.assign(Object.assign({}, crudParams), { query: lodash_1.default.merge(params.query || {}, query) }));
|
||||||
|
crudParams.query = checkedObj.query;
|
||||||
|
crudParams.body = checkedObj.body;
|
||||||
|
crudParams.allowedTable = checkedObj.allowedTable;
|
||||||
|
crudParams.url = url;
|
||||||
|
const finalSearchQuery = lodash_1.default.merge((_a = crudParams.query) === null || _a === void 0 ? void 0 : _a.searchQuery, (_b = crudParams.body) === null || _b === void 0 ? void 0 : _b.searchQuery);
|
||||||
|
if (finalSearchQuery) {
|
||||||
|
crudParams.query = Object.assign(Object.assign({}, crudParams.query), { searchQuery: finalSearchQuery });
|
||||||
|
}
|
||||||
|
if (targetId) {
|
||||||
|
if (crudParams.query) {
|
||||||
|
if (crudParams.query.searchQuery) {
|
||||||
|
crudParams.query.searchQuery = lodash_1.default.merge(crudParams.query.searchQuery, {
|
||||||
|
query: {
|
||||||
|
id: {
|
||||||
|
value: String(targetId),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
crudParams.query.searchQuery = {
|
||||||
|
query: {
|
||||||
|
id: {
|
||||||
|
value: String(targetId),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
crudParams.query = {
|
||||||
|
searchQuery: {
|
||||||
|
query: {
|
||||||
|
id: {
|
||||||
|
value: String(targetId),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let result;
|
||||||
|
switch (method) {
|
||||||
|
case "GET":
|
||||||
|
result = yield (0, get_result_1.default)(crudParams);
|
||||||
|
break;
|
||||||
|
case "POST":
|
||||||
|
result = yield (0, post_result_1.default)(crudParams);
|
||||||
|
break;
|
||||||
|
case "PUT":
|
||||||
|
result = yield (0, put_result_1.default)(crudParams);
|
||||||
|
break;
|
||||||
|
case "DELETE":
|
||||||
|
result = yield (0, delete_result_1.default)(crudParams);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
yield ((_c = params.postResultsFn) === null || _c === void 0 ? void 0 : _c.call(params, Object.assign(Object.assign(Object.assign({}, lodash_1.default.omit(crudParams, [
|
||||||
|
"postResultsFnExtraParameters",
|
||||||
|
"postResultsFn",
|
||||||
|
"deleteMiddleware",
|
||||||
|
"putMiddleware",
|
||||||
|
"postMiddleware",
|
||||||
|
"getMiddleware",
|
||||||
|
"auth",
|
||||||
|
])), { res: result }), (params.postResultsFnExtraParameters || {}))));
|
||||||
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
msg: `Unhandled`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
msg: error.message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { APIPathsCrudParams, APIPathsParamsAllowedTable } from "../../types";
|
||||||
|
export default function checks<T extends {
|
||||||
|
[k: string]: any;
|
||||||
|
} = {
|
||||||
|
[k: string]: any;
|
||||||
|
}>({ table, allowedTables, query, body, method, getMiddleware, postMiddleware, putMiddleware, deleteMiddleware, crudMiddleware, targetId, }: APIPathsCrudParams<T>): Promise<Pick<APIPathsCrudParams<T>, "query" | "body"> & {
|
||||||
|
allowedTable: APIPathsParamsAllowedTable;
|
||||||
|
}>;
|
||||||
+135
@@ -0,0 +1,135 @@
|
|||||||
|
"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.default = checks;
|
||||||
|
const lodash_1 = __importDefault(require("lodash"));
|
||||||
|
function checks(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ table, allowedTables, query, body, method, getMiddleware, postMiddleware, putMiddleware, deleteMiddleware, crudMiddleware, targetId, }) {
|
||||||
|
var _b, _c, _d, _e, _f;
|
||||||
|
const allowedTable = allowedTables.find((tbl) => tbl.table == table);
|
||||||
|
if (!allowedTable) {
|
||||||
|
throw new Error(`Can't Access this table: \`${table}\``);
|
||||||
|
}
|
||||||
|
let newQuery = lodash_1.default.cloneDeep(query);
|
||||||
|
let newBody = lodash_1.default.cloneDeep(body);
|
||||||
|
const searchFields = Object.keys(((_b = newQuery === null || newQuery === void 0 ? void 0 : newQuery.searchQuery) === null || _b === void 0 ? void 0 : _b.query) || {});
|
||||||
|
const selectFields = (_d = (((_c = newQuery === null || newQuery === void 0 ? void 0 : newQuery.searchQuery) === null || _c === void 0 ? void 0 : _c.selectFields)
|
||||||
|
? newQuery.searchQuery.selectFields.map((f) => typeof f == "string"
|
||||||
|
? f
|
||||||
|
: typeof f == "object"
|
||||||
|
? f.fieldName
|
||||||
|
: undefined)
|
||||||
|
: undefined)) === null || _d === void 0 ? void 0 : _d.filter((f) => typeof f == "string");
|
||||||
|
const targetFields = [...(searchFields || []), ...(selectFields || [])];
|
||||||
|
if (method == "GET" && allowedTable.allowedFields) {
|
||||||
|
for (let i = 0; i < targetFields.length; i++) {
|
||||||
|
const fld = targetFields[i];
|
||||||
|
const allowedFld = allowedTable.allowedFields.find((f) => typeof f == "string" ? f == fld : fld.match(f));
|
||||||
|
if (!allowedFld) {
|
||||||
|
throw new Error(`\`${allowedFld}\` field not allowed`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (method == "GET" && allowedTable.disallowedFields) {
|
||||||
|
for (let i = 0; i < targetFields.length; i++) {
|
||||||
|
const fld = targetFields[i];
|
||||||
|
const disallowedFld = allowedTable.disallowedFields.find((f) => typeof f == "string" ? f == fld : fld.match(f));
|
||||||
|
if (disallowedFld) {
|
||||||
|
throw new Error(`\`${disallowedFld}\` field not allowed`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((_e = newQuery === null || newQuery === void 0 ? void 0 : newQuery.searchQuery) === null || _e === void 0 ? void 0 : _e.join) {
|
||||||
|
const alljoins = (_f = newQuery === null || newQuery === void 0 ? void 0 : newQuery.searchQuery) === null || _f === void 0 ? void 0 : _f.join.flat();
|
||||||
|
for (let i = 0; i < alljoins.length; i++) {
|
||||||
|
const join = alljoins[i];
|
||||||
|
if (!join)
|
||||||
|
continue;
|
||||||
|
const joinTableName = join.tableName;
|
||||||
|
const selectFields = join.selectFields;
|
||||||
|
if (allowedTables === null || allowedTables === void 0 ? void 0 : allowedTables[0]) {
|
||||||
|
const allowedJoinTable = allowedTables.find((t) => t.table == joinTableName);
|
||||||
|
if (!(allowedJoinTable === null || allowedJoinTable === void 0 ? void 0 : allowedJoinTable.table)) {
|
||||||
|
throw new Error(`Can't joint \`${joinTableName}\` table`);
|
||||||
|
}
|
||||||
|
const allowedFields = allowedJoinTable.allowedFields;
|
||||||
|
const disallowedFields = allowedJoinTable.disallowedFields;
|
||||||
|
if (selectFields === null || selectFields === void 0 ? void 0 : selectFields[0]) {
|
||||||
|
for (let j = 0; j < selectFields.length; j++) {
|
||||||
|
const selectField = selectFields[j];
|
||||||
|
const selectFieldName = typeof selectField == "object"
|
||||||
|
? selectField.field
|
||||||
|
: String(selectField);
|
||||||
|
if ((allowedFields === null || allowedFields === void 0 ? void 0 : allowedFields[0]) &&
|
||||||
|
!allowedFields.find((f) => String(f) == selectFieldName)) {
|
||||||
|
throw new Error(`Can't Select this Field!`);
|
||||||
|
}
|
||||||
|
if ((disallowedFields === null || disallowedFields === void 0 ? void 0 : disallowedFields[0]) &&
|
||||||
|
disallowedFields.find((f) => String(f) == selectFieldName)) {
|
||||||
|
throw new Error(`Disallowed Field Selected!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (method == "GET" && getMiddleware) {
|
||||||
|
newQuery = yield getMiddleware({
|
||||||
|
query: newQuery || {},
|
||||||
|
table,
|
||||||
|
targetId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (method !== "GET" && crudMiddleware) {
|
||||||
|
const middRes = yield crudMiddleware({
|
||||||
|
body: newBody || {},
|
||||||
|
query: newQuery || {},
|
||||||
|
table,
|
||||||
|
targetId,
|
||||||
|
});
|
||||||
|
newBody = lodash_1.default.merge(newBody, middRes);
|
||||||
|
}
|
||||||
|
if (method == "POST" && postMiddleware) {
|
||||||
|
const middRes = yield postMiddleware({
|
||||||
|
body: newBody || {},
|
||||||
|
query: newQuery || {},
|
||||||
|
table,
|
||||||
|
targetId,
|
||||||
|
});
|
||||||
|
newBody = lodash_1.default.merge(newBody, middRes);
|
||||||
|
}
|
||||||
|
if (method == "PUT" && putMiddleware) {
|
||||||
|
const middRes = yield putMiddleware({
|
||||||
|
body: newBody || {},
|
||||||
|
query: newQuery || {},
|
||||||
|
table,
|
||||||
|
targetId,
|
||||||
|
});
|
||||||
|
newBody = lodash_1.default.merge(newBody, middRes);
|
||||||
|
}
|
||||||
|
if (method == "DELETE" && deleteMiddleware) {
|
||||||
|
const middRes = yield deleteMiddleware({
|
||||||
|
body: newBody || {},
|
||||||
|
query: newQuery || {},
|
||||||
|
table,
|
||||||
|
});
|
||||||
|
newBody = lodash_1.default.merge(newBody, middRes);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
query: newQuery,
|
||||||
|
body: newBody,
|
||||||
|
allowedTable,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { APIPathsData, APIPathsParams } from "../../types";
|
||||||
|
export declare function grabPathData<T extends {
|
||||||
|
[k: string]: any;
|
||||||
|
} = {
|
||||||
|
[k: string]: any;
|
||||||
|
}>({ href, basePath }: APIPathsParams<T>): APIPathsData<T>;
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
"use strict";
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.grabPathData = grabPathData;
|
||||||
|
const deserialize_query_1 = __importDefault(require("../../utils/deserialize-query"));
|
||||||
|
function grabPathData({ href, basePath }) {
|
||||||
|
const urlObj = new URL(href);
|
||||||
|
const pathname = basePath
|
||||||
|
? urlObj.pathname.replace(basePath, "")
|
||||||
|
: urlObj.pathname;
|
||||||
|
const urlArray = pathname.split("/").filter((u) => Boolean(u.match(/./)));
|
||||||
|
const table = urlArray[0];
|
||||||
|
const targetId = urlArray[1];
|
||||||
|
let query = ((urlObj === null || urlObj === void 0 ? void 0 : urlObj.searchParams)
|
||||||
|
? (0, deserialize_query_1.default)(Object.fromEntries(urlObj.searchParams))
|
||||||
|
: undefined);
|
||||||
|
if (!table) {
|
||||||
|
throw new Error(`No Table Found`);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
table,
|
||||||
|
targetId,
|
||||||
|
query,
|
||||||
|
url: urlObj,
|
||||||
|
};
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
import { SQLDeleteData } from "../../types";
|
||||||
|
type Params<T extends {
|
||||||
|
[key: string]: any;
|
||||||
|
} = {
|
||||||
|
[key: string]: any;
|
||||||
|
}> = {
|
||||||
|
dbName: string;
|
||||||
|
tableName: string;
|
||||||
|
deleteSpec?: T & {
|
||||||
|
deleteKeyValues?: SQLDeleteData<T>[];
|
||||||
|
};
|
||||||
|
targetID?: string | number;
|
||||||
|
apiKey?: string;
|
||||||
|
/**
|
||||||
|
* # Query datasquirel.com
|
||||||
|
*/
|
||||||
|
useDefault?: boolean;
|
||||||
|
};
|
||||||
|
export default function apiCrudDELETE<T extends {
|
||||||
|
[key: string]: any;
|
||||||
|
} = {
|
||||||
|
[key: string]: any;
|
||||||
|
}>({ dbName, tableName, deleteSpec, targetID, apiKey, useDefault }: Params<T>): Promise<import("../../types").APIResponseObject>;
|
||||||
|
export {};
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
"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.default = apiCrudDELETE;
|
||||||
|
const path_1 = __importDefault(require("path"));
|
||||||
|
const query_dsql_api_1 = __importDefault(require("../../functions/api/query-dsql-api"));
|
||||||
|
const grab_api_base_path_1 = __importDefault(require("../../utils/grab-api-base-path"));
|
||||||
|
function apiCrudDELETE(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ dbName, tableName, deleteSpec, targetID, apiKey, useDefault }) {
|
||||||
|
const basePath = (0, grab_api_base_path_1.default)({ paradigm: "crud" });
|
||||||
|
const finalID = typeof targetID === "number" ? String(targetID) : targetID;
|
||||||
|
const finalPath = path_1.default.join(basePath, dbName, tableName, finalID || "");
|
||||||
|
const GET_RES = yield (0, query_dsql_api_1.default)({
|
||||||
|
method: "DELETE",
|
||||||
|
path: finalPath,
|
||||||
|
body: deleteSpec,
|
||||||
|
apiKey,
|
||||||
|
useDefault,
|
||||||
|
});
|
||||||
|
return GET_RES;
|
||||||
|
});
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
import { APIResponseObject, DsqlCrudQueryObject } from "../../types";
|
||||||
|
type Params<T extends {
|
||||||
|
[key: string]: any;
|
||||||
|
} = {
|
||||||
|
[key: string]: any;
|
||||||
|
}> = {
|
||||||
|
dbName: string;
|
||||||
|
tableName: string;
|
||||||
|
query?: DsqlCrudQueryObject<T>;
|
||||||
|
targetId?: string | number;
|
||||||
|
apiKey?: string;
|
||||||
|
/**
|
||||||
|
* # Query datasquirel.com
|
||||||
|
*/
|
||||||
|
useDefault?: boolean;
|
||||||
|
};
|
||||||
|
export default function apiCrudGET<T extends {
|
||||||
|
[key: string]: any;
|
||||||
|
} = {
|
||||||
|
[key: string]: any;
|
||||||
|
}>({ dbName, tableName, query, targetId, apiKey, useDefault, }: Params<T>): Promise<APIResponseObject>;
|
||||||
|
export {};
|
||||||
Vendored
+33
@@ -0,0 +1,33 @@
|
|||||||
|
"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.default = apiCrudGET;
|
||||||
|
const path_1 = __importDefault(require("path"));
|
||||||
|
const query_dsql_api_1 = __importDefault(require("../../functions/api/query-dsql-api"));
|
||||||
|
const grab_api_base_path_1 = __importDefault(require("../../utils/grab-api-base-path"));
|
||||||
|
function apiCrudGET(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ dbName, tableName, query, targetId, apiKey, useDefault, }) {
|
||||||
|
const basePath = (0, grab_api_base_path_1.default)({ paradigm: "crud" });
|
||||||
|
const finalID = typeof targetId === "number" ? String(targetId) : targetId;
|
||||||
|
const finalPath = path_1.default.join(basePath, dbName, tableName, finalID || "");
|
||||||
|
const GET_RES = yield (0, query_dsql_api_1.default)({
|
||||||
|
method: "GET",
|
||||||
|
path: finalPath,
|
||||||
|
query,
|
||||||
|
apiKey,
|
||||||
|
useDefault,
|
||||||
|
});
|
||||||
|
return GET_RES;
|
||||||
|
});
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
import apiCrudGET from "./get";
|
||||||
|
import apiCrudPOST from "./post";
|
||||||
|
import apiCrudPUT from "./put";
|
||||||
|
import apiCrudDELETE from "./delete";
|
||||||
|
declare const crud: {
|
||||||
|
get: typeof apiCrudGET;
|
||||||
|
insert: typeof apiCrudPOST;
|
||||||
|
update: typeof apiCrudPUT;
|
||||||
|
delete: typeof apiCrudDELETE;
|
||||||
|
options: () => Promise<void>;
|
||||||
|
};
|
||||||
|
export default crud;
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
"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 });
|
||||||
|
const get_1 = __importDefault(require("./get"));
|
||||||
|
const post_1 = __importDefault(require("./post"));
|
||||||
|
const put_1 = __importDefault(require("./put"));
|
||||||
|
const delete_1 = __importDefault(require("./delete"));
|
||||||
|
const crud = {
|
||||||
|
get: get_1.default,
|
||||||
|
insert: post_1.default,
|
||||||
|
update: put_1.default,
|
||||||
|
delete: delete_1.default,
|
||||||
|
options: () => __awaiter(void 0, void 0, void 0, function* () { }),
|
||||||
|
};
|
||||||
|
exports.default = crud;
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
import { APIResponseObject } from "../../types";
|
||||||
|
export type APICrudPostParams<T extends {
|
||||||
|
[key: string]: any;
|
||||||
|
} = {
|
||||||
|
[key: string]: any;
|
||||||
|
}> = {
|
||||||
|
dbName: string;
|
||||||
|
tableName: string;
|
||||||
|
body: T;
|
||||||
|
update?: boolean;
|
||||||
|
apiKey?: string;
|
||||||
|
/**
|
||||||
|
* # Query datasquirel.com
|
||||||
|
*/
|
||||||
|
useDefault?: boolean;
|
||||||
|
};
|
||||||
|
export default function apiCrudPOST<T extends {
|
||||||
|
[key: string]: any;
|
||||||
|
} = {
|
||||||
|
[key: string]: any;
|
||||||
|
}>({ dbName, tableName, body, update, apiKey, useDefault, }: APICrudPostParams<T>): Promise<APIResponseObject>;
|
||||||
Vendored
+38
@@ -0,0 +1,38 @@
|
|||||||
|
"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.default = apiCrudPOST;
|
||||||
|
const path_1 = __importDefault(require("path"));
|
||||||
|
const query_dsql_api_1 = __importDefault(require("../../functions/api/query-dsql-api"));
|
||||||
|
const grab_api_base_path_1 = __importDefault(require("../../utils/grab-api-base-path"));
|
||||||
|
function apiCrudPOST(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ dbName, tableName, body, update, apiKey, useDefault, }) {
|
||||||
|
const basePath = (0, grab_api_base_path_1.default)({ paradigm: "crud" });
|
||||||
|
const passedID = body.id;
|
||||||
|
const finalID = update
|
||||||
|
? typeof passedID === "number"
|
||||||
|
? String(passedID)
|
||||||
|
: passedID
|
||||||
|
: undefined;
|
||||||
|
const finalPath = path_1.default.join(basePath, dbName, tableName, finalID || "");
|
||||||
|
const GET_RES = yield (0, query_dsql_api_1.default)({
|
||||||
|
method: update ? "PUT" : "POST",
|
||||||
|
path: finalPath,
|
||||||
|
body,
|
||||||
|
apiKey,
|
||||||
|
useDefault,
|
||||||
|
});
|
||||||
|
return GET_RES;
|
||||||
|
});
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
import { APICrudPostParams } from "./post";
|
||||||
|
type Params<T extends {
|
||||||
|
[key: string]: any;
|
||||||
|
} = {
|
||||||
|
[key: string]: any;
|
||||||
|
}> = Omit<APICrudPostParams<T>, "update"> & {
|
||||||
|
targetID: string | number;
|
||||||
|
apiKey?: string;
|
||||||
|
};
|
||||||
|
export default function apiCrudPUT<T extends {
|
||||||
|
[key: string]: any;
|
||||||
|
} = {
|
||||||
|
[key: string]: any;
|
||||||
|
}>({ dbName, tableName, body, targetID, apiKey }: Params<T>): Promise<import("../../types").APIResponseObject>;
|
||||||
|
export {};
|
||||||
Vendored
+31
@@ -0,0 +1,31 @@
|
|||||||
|
"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.default = apiCrudPUT;
|
||||||
|
const post_1 = __importDefault(require("./post"));
|
||||||
|
function apiCrudPUT(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ dbName, tableName, body, targetID, apiKey }) {
|
||||||
|
const updatedBody = Object.assign({}, body);
|
||||||
|
if (targetID) {
|
||||||
|
updatedBody["id"] = targetID;
|
||||||
|
}
|
||||||
|
return yield (0, post_1.default)({
|
||||||
|
dbName,
|
||||||
|
tableName,
|
||||||
|
body: updatedBody,
|
||||||
|
update: true,
|
||||||
|
apiKey,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
import { APIResponseObject } from "../../types";
|
||||||
|
import { DSQL_DATASQUIREL_USER_MEDIA } from "../../types/dsql";
|
||||||
|
type Params = {
|
||||||
|
mediaID?: string | number;
|
||||||
|
apiKey?: string;
|
||||||
|
/**
|
||||||
|
* # Query datasquirel.com
|
||||||
|
*/
|
||||||
|
useDefault?: boolean;
|
||||||
|
query?: any;
|
||||||
|
};
|
||||||
|
export default function apiMediaDELETE(params: Params): Promise<APIResponseObject<DSQL_DATASQUIREL_USER_MEDIA | DSQL_DATASQUIREL_USER_MEDIA[]>>;
|
||||||
|
export {};
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
"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.default = apiMediaDELETE;
|
||||||
|
const query_dsql_api_1 = __importDefault(require("../../functions/api/query-dsql-api"));
|
||||||
|
const path_1 = __importDefault(require("path"));
|
||||||
|
const grab_api_base_path_1 = __importDefault(require("../../utils/grab-api-base-path"));
|
||||||
|
const grab_api_key_1 = __importDefault(require("../../utils/grab-api-key"));
|
||||||
|
function apiMediaDELETE(params) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const basePath = (0, grab_api_base_path_1.default)({ paradigm: "media" });
|
||||||
|
const mediaID = params.mediaID
|
||||||
|
? typeof params.mediaID === "number"
|
||||||
|
? String(params.mediaID)
|
||||||
|
: params.mediaID
|
||||||
|
: undefined;
|
||||||
|
const finalPath = path_1.default.join(basePath, mediaID || "");
|
||||||
|
const apiKey = (0, grab_api_key_1.default)(params.apiKey);
|
||||||
|
const DELETE_MEDIA_RES = yield (0, query_dsql_api_1.default)({
|
||||||
|
method: "DELETE",
|
||||||
|
path: finalPath,
|
||||||
|
apiKey,
|
||||||
|
useDefault: params.useDefault,
|
||||||
|
query: params.query,
|
||||||
|
});
|
||||||
|
return DELETE_MEDIA_RES;
|
||||||
|
});
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
import { APIGetMediaParams, APIResponseObject } from "../../types";
|
||||||
|
import { DSQL_DATASQUIREL_USER_MEDIA } from "../../types/dsql";
|
||||||
|
export default function apiMediaGET(params: APIGetMediaParams): Promise<APIResponseObject<DSQL_DATASQUIREL_USER_MEDIA | DSQL_DATASQUIREL_USER_MEDIA[]>>;
|
||||||
Vendored
+39
@@ -0,0 +1,39 @@
|
|||||||
|
"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.default = apiMediaGET;
|
||||||
|
const query_dsql_api_1 = __importDefault(require("../../functions/api/query-dsql-api"));
|
||||||
|
const path_1 = __importDefault(require("path"));
|
||||||
|
const grab_api_base_path_1 = __importDefault(require("../../utils/grab-api-base-path"));
|
||||||
|
const grab_api_key_1 = __importDefault(require("../../utils/grab-api-key"));
|
||||||
|
function apiMediaGET(params) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const basePath = (0, grab_api_base_path_1.default)({ paradigm: "media" });
|
||||||
|
const mediaID = params.mediaID
|
||||||
|
? typeof params.mediaID === "number"
|
||||||
|
? String(params.mediaID)
|
||||||
|
: params.mediaID
|
||||||
|
: undefined;
|
||||||
|
const finalPath = path_1.default.join(basePath, mediaID || "");
|
||||||
|
const apiKey = (0, grab_api_key_1.default)(params.apiKey);
|
||||||
|
const GET_MEDIA_RES = yield (0, query_dsql_api_1.default)({
|
||||||
|
method: "GET",
|
||||||
|
path: finalPath,
|
||||||
|
query: params,
|
||||||
|
apiKey,
|
||||||
|
useDefault: params.useDefault,
|
||||||
|
});
|
||||||
|
return GET_MEDIA_RES;
|
||||||
|
});
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
import apiMediaGET from "./get";
|
||||||
|
import apiMediaPOST from "./post";
|
||||||
|
import apiMediaDELETE from "./delete";
|
||||||
|
declare const media: {
|
||||||
|
get: typeof apiMediaGET;
|
||||||
|
add: typeof apiMediaPOST;
|
||||||
|
delete: typeof apiMediaDELETE;
|
||||||
|
};
|
||||||
|
export default media;
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
"use strict";
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const get_1 = __importDefault(require("./get"));
|
||||||
|
const post_1 = __importDefault(require("./post"));
|
||||||
|
const delete_1 = __importDefault(require("./delete"));
|
||||||
|
const media = {
|
||||||
|
get: get_1.default,
|
||||||
|
add: post_1.default,
|
||||||
|
delete: delete_1.default,
|
||||||
|
};
|
||||||
|
exports.default = media;
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
import { AddMediaAPIBody, APIResponseObject } from "../../types";
|
||||||
|
import { DSQL_DATASQUIREL_USER_MEDIA } from "../../types/dsql";
|
||||||
|
export default function apiMediaPOST(params: AddMediaAPIBody): Promise<APIResponseObject<DSQL_DATASQUIREL_USER_MEDIA | DSQL_DATASQUIREL_USER_MEDIA[]>>;
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
"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.default = apiMediaPOST;
|
||||||
|
const query_dsql_api_1 = __importDefault(require("../../functions/api/query-dsql-api"));
|
||||||
|
const grab_api_base_path_1 = __importDefault(require("../../utils/grab-api-base-path"));
|
||||||
|
const grab_api_key_1 = __importDefault(require("../../utils/grab-api-key"));
|
||||||
|
function apiMediaPOST(params) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const basePath = (0, grab_api_base_path_1.default)({ paradigm: "media" });
|
||||||
|
const apiKey = (0, grab_api_key_1.default)(params.apiKey);
|
||||||
|
const POST_MEDIA_RES = yield (0, query_dsql_api_1.default)({
|
||||||
|
method: "POST",
|
||||||
|
path: basePath,
|
||||||
|
body: params,
|
||||||
|
apiKey,
|
||||||
|
useDefault: params.useDefault,
|
||||||
|
});
|
||||||
|
return POST_MEDIA_RES;
|
||||||
|
});
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
import { APIConnectionOptions, APIResponseObject, DSQL_DatabaseSchemaType, DSQL_FieldSchemaType, DSQL_TableSchemaType } from "../../types";
|
||||||
|
import { GrabHostNamesReturn } from "../../utils/grab-host-names";
|
||||||
|
type Params = {
|
||||||
|
dbName: string;
|
||||||
|
tableName?: string;
|
||||||
|
fieldName?: string;
|
||||||
|
apiKey?: string;
|
||||||
|
apiConnectionConfig?: APIConnectionOptions;
|
||||||
|
grabbedHostnames?: GrabHostNamesReturn;
|
||||||
|
useDefault?: boolean;
|
||||||
|
};
|
||||||
|
export default function <T extends DSQL_DatabaseSchemaType | DSQL_TableSchemaType | DSQL_FieldSchemaType = DSQL_DatabaseSchemaType>({ dbName, tableName, apiKey, useDefault, fieldName, apiConnectionConfig, grabbedHostnames, }: Params): Promise<APIResponseObject>;
|
||||||
|
export {};
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
"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.default = default_1;
|
||||||
|
const path_1 = __importDefault(require("path"));
|
||||||
|
const query_dsql_api_1 = __importDefault(require("../../functions/api/query-dsql-api"));
|
||||||
|
const grab_api_base_path_1 = __importDefault(require("../../utils/grab-api-base-path"));
|
||||||
|
function default_1(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ dbName, tableName, apiKey, useDefault, fieldName, apiConnectionConfig, grabbedHostnames, }) {
|
||||||
|
const basePath = (0, grab_api_base_path_1.default)({ paradigm: "schema" });
|
||||||
|
const finalPath = path_1.default.join(basePath, dbName, tableName || "", fieldName || "");
|
||||||
|
const GET_RES = yield (0, query_dsql_api_1.default)({
|
||||||
|
method: "GET",
|
||||||
|
path: finalPath,
|
||||||
|
apiKey,
|
||||||
|
useDefault,
|
||||||
|
apiConnectionConfig,
|
||||||
|
grabbedHostnames,
|
||||||
|
});
|
||||||
|
return GET_RES;
|
||||||
|
});
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
import get from "./get";
|
||||||
|
declare const schema: {
|
||||||
|
get: typeof get;
|
||||||
|
};
|
||||||
|
export default schema;
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
"use strict";
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const get_1 = __importDefault(require("./get"));
|
||||||
|
const schema = {
|
||||||
|
get: get_1.default,
|
||||||
|
};
|
||||||
|
exports.default = schema;
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
import addUser from "../../actions/users/add-user";
|
||||||
|
import getUser from "../../actions/users/get-user";
|
||||||
|
import loginUser from "../../actions/users/login-user";
|
||||||
|
import logoutUser from "../../actions/users/logout-user";
|
||||||
|
import resetPassword from "../../actions/users/reset-password";
|
||||||
|
import sendEmailCode from "../../actions/users/send-email-code";
|
||||||
|
import googleAuth from "../../actions/users/social/google-auth";
|
||||||
|
import updateUser from "../../actions/users/update-user";
|
||||||
|
import userAuth from "../../actions/users/user-auth";
|
||||||
|
import validateTempEmailCode from "../../actions/users/validate-temp-email-code";
|
||||||
|
declare const user: {
|
||||||
|
auth: {
|
||||||
|
login: typeof loginUser;
|
||||||
|
get: typeof getUser;
|
||||||
|
signup: typeof addUser;
|
||||||
|
sendEmailCode: typeof sendEmailCode;
|
||||||
|
update: typeof updateUser;
|
||||||
|
resetPassword: typeof resetPassword;
|
||||||
|
googleLogin: typeof googleAuth;
|
||||||
|
logout: typeof logoutUser;
|
||||||
|
auth: typeof userAuth;
|
||||||
|
validateTempEmailCode: typeof validateTempEmailCode;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
export default user;
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
"use strict";
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const add_user_1 = __importDefault(require("../../actions/users/add-user"));
|
||||||
|
const get_user_1 = __importDefault(require("../../actions/users/get-user"));
|
||||||
|
const login_user_1 = __importDefault(require("../../actions/users/login-user"));
|
||||||
|
const logout_user_1 = __importDefault(require("../../actions/users/logout-user"));
|
||||||
|
const reset_password_1 = __importDefault(require("../../actions/users/reset-password"));
|
||||||
|
const send_email_code_1 = __importDefault(require("../../actions/users/send-email-code"));
|
||||||
|
const google_auth_1 = __importDefault(require("../../actions/users/social/google-auth"));
|
||||||
|
const update_user_1 = __importDefault(require("../../actions/users/update-user"));
|
||||||
|
const user_auth_1 = __importDefault(require("../../actions/users/user-auth"));
|
||||||
|
const validate_temp_email_code_1 = __importDefault(require("../../actions/users/validate-temp-email-code"));
|
||||||
|
const user = {
|
||||||
|
auth: {
|
||||||
|
login: login_user_1.default,
|
||||||
|
get: get_user_1.default,
|
||||||
|
signup: add_user_1.default,
|
||||||
|
sendEmailCode: send_email_code_1.default,
|
||||||
|
update: update_user_1.default,
|
||||||
|
resetPassword: reset_password_1.default,
|
||||||
|
googleLogin: google_auth_1.default,
|
||||||
|
logout: logout_user_1.default,
|
||||||
|
auth: user_auth_1.default,
|
||||||
|
validateTempEmailCode: validate_temp_email_code_1.default,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
exports.default = user;
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
import logoutUser from "../../actions/users/logout-user";
|
||||||
|
import userAuth from "../../actions/users/user-auth";
|
||||||
|
import validateTempEmailCode from "../../actions/users/validate-temp-email-code";
|
||||||
|
import githubLogin from "../../functions/api/social-login/githubLogin";
|
||||||
|
import { AddUserParams, GetUserParams, GoogleAuthParams, LoginUserParam, ResetPasswordParams, SendEmailCodeParams, UpdateUserParams } from "../../types";
|
||||||
|
declare const localUser: {
|
||||||
|
auth: {
|
||||||
|
login: (_: LoginUserParam) => Promise<import("../../types").APIResponseObject>;
|
||||||
|
get: (_: GetUserParams) => Promise<import("../../types").APIResponseObject>;
|
||||||
|
signup: (_: AddUserParams) => Promise<import("../../types").APIResponseObject>;
|
||||||
|
sendEmailCode: (_: SendEmailCodeParams) => Promise<import("../../types").APIResponseObject>;
|
||||||
|
update: (_: UpdateUserParams) => Promise<import("../../types").APIResponseObject>;
|
||||||
|
resetPassword: (_: ResetPasswordParams) => Promise<import("../../types").APIResponseObject>;
|
||||||
|
googleLogin: (_: GoogleAuthParams) => Promise<import("../../types").APIResponseObject>;
|
||||||
|
logout: typeof logoutUser;
|
||||||
|
auth: typeof userAuth;
|
||||||
|
validateTempEmailCode: typeof validateTempEmailCode;
|
||||||
|
githubLoginFn: typeof githubLogin;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
export default localUser;
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user