Compare commits
No commits in common. "afd50caf42cbe69935a05a84434a956a2bdc1808" and "8fd6c28461dc23c37522a69e1fd790d60395ed95" have entirely different histories.
afd50caf42
...
8fd6c28461
@ -1,76 +0,0 @@
|
|||||||
/** @type {import("../../package-shared/types").FetchApiFn} */
|
|
||||||
async function clientFetch() {
|
|
||||||
let data;
|
|
||||||
|
|
||||||
if (typeof options === "string") {
|
|
||||||
try {
|
|
||||||
let fetchData;
|
|
||||||
const csrfValue = localStorage.getItem("csrf");
|
|
||||||
|
|
||||||
switch (options) {
|
|
||||||
case "post":
|
|
||||||
fetchData = await fetch(url, {
|
|
||||||
method: options,
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"x-csrf-auth": csrf ? csrfValue : "",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
data = fetchData.json();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
fetchData = await fetch(url);
|
|
||||||
data = fetchData.json();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (/** @type {any} */ error) {
|
|
||||||
console.log("FetchAPI error #1:", error.message);
|
|
||||||
data = null;
|
|
||||||
}
|
|
||||||
} else if (typeof options === "object") {
|
|
||||||
try {
|
|
||||||
let fetchData;
|
|
||||||
|
|
||||||
const csrfValue = localStorage.getItem("csrf");
|
|
||||||
|
|
||||||
if (options.body && typeof options.body === "object") {
|
|
||||||
let oldOptionsBody = _.cloneDeep(options.body);
|
|
||||||
options.body = JSON.stringify(oldOptionsBody);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.headers) {
|
|
||||||
options.headers["x-csrf-auth"] = csrf ? csrfValue : "";
|
|
||||||
|
|
||||||
const finalOptions = { ...options };
|
|
||||||
fetchData = await fetch(url, finalOptions);
|
|
||||||
} else {
|
|
||||||
fetchData = await fetch(url, {
|
|
||||||
...options,
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"x-csrf-auth": csrf ? csrfValue : "",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
data = fetchData.json();
|
|
||||||
} catch (/** @type {any} */ error) {
|
|
||||||
console.log("FetchAPI error #2:", error.message);
|
|
||||||
data = null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
let fetchData = await fetch(url);
|
|
||||||
data = fetchData.json();
|
|
||||||
} catch (/** @type {any} */ error) {
|
|
||||||
console.log("FetchAPI error #3:", error.message);
|
|
||||||
data = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = clientFetch;
|
|
||||||
exports.fetchApi = clientFetch;
|
|
@ -9,8 +9,6 @@ const inputFileToBase64 = require("./media/inputFileToBase64");
|
|||||||
const getAccessToken = require("./auth/google/getAccessToken");
|
const getAccessToken = require("./auth/google/getAccessToken");
|
||||||
const getGithubAccessToken = require("./auth/github/getAccessToken");
|
const getGithubAccessToken = require("./auth/github/getAccessToken");
|
||||||
const logout = require("./auth/logout");
|
const logout = require("./auth/logout");
|
||||||
const { fetchApi } = require("./fetch");
|
|
||||||
const clientFetch = require("./fetch");
|
|
||||||
|
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
@ -38,17 +36,12 @@ const auth = {
|
|||||||
logout: logout,
|
logout: logout,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch
|
|
||||||
*/
|
|
||||||
const fetch = {
|
|
||||||
fetchApi,
|
|
||||||
clientFetch,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main Export
|
* Main Export
|
||||||
*/
|
*/
|
||||||
const datasquirelClient = { media, auth, fetch };
|
const datasquirelClient = {
|
||||||
|
media: media,
|
||||||
|
auth: auth,
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = datasquirelClient;
|
module.exports = datasquirelClient;
|
||||||
|
42
index.d.ts
vendored
42
index.d.ts
vendored
@ -1,42 +0,0 @@
|
|||||||
import get = require("./utils/get");
|
|
||||||
import post = require("./utils/post");
|
|
||||||
export namespace media {
|
|
||||||
export { uploadImage };
|
|
||||||
export { uploadFile };
|
|
||||||
export { deleteFile };
|
|
||||||
}
|
|
||||||
export namespace user {
|
|
||||||
export { createUser };
|
|
||||||
export { loginUser };
|
|
||||||
export { sendEmailCode };
|
|
||||||
export { logoutUser };
|
|
||||||
export { userAuth };
|
|
||||||
export { reAuthUser };
|
|
||||||
export { updateUser };
|
|
||||||
export { getUser };
|
|
||||||
export { getToken };
|
|
||||||
export { validateToken };
|
|
||||||
export namespace social {
|
|
||||||
export { loginWithGoogle };
|
|
||||||
export { loginWithGithub };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
import getSchema = require("./utils/get-schema");
|
|
||||||
import sanitizeSql = require("./utils/functions/sanitizeSql");
|
|
||||||
import datasquirelClient = require("./client");
|
|
||||||
import uploadImage = require("./utils/upload-image");
|
|
||||||
import uploadFile = require("./utils/upload-file");
|
|
||||||
import deleteFile = require("./utils/delete-file");
|
|
||||||
import createUser = require("./users/add-user");
|
|
||||||
import loginUser = require("./users/login-user");
|
|
||||||
import sendEmailCode = require("./users/send-email-code");
|
|
||||||
import logoutUser = require("./users/logout-user");
|
|
||||||
import userAuth = require("./users/user-auth");
|
|
||||||
import reAuthUser = require("./users/reauth-user");
|
|
||||||
import updateUser = require("./users/update-user");
|
|
||||||
import getUser = require("./users/get-user");
|
|
||||||
import getToken = require("./users/get-token");
|
|
||||||
import validateToken = require("./users/validate-token");
|
|
||||||
import loginWithGoogle = require("./users/social/google-auth");
|
|
||||||
import loginWithGithub = require("./users/social/github-auth");
|
|
||||||
export { get, post, getSchema, sanitizeSql, datasquirelClient as client };
|
|
2
index.js
2
index.js
@ -27,7 +27,6 @@ const getToken = require("./users/get-token");
|
|||||||
const validateToken = require("./users/validate-token");
|
const validateToken = require("./users/validate-token");
|
||||||
|
|
||||||
const sanitizeSql = require("./utils/functions/sanitizeSql");
|
const sanitizeSql = require("./utils/functions/sanitizeSql");
|
||||||
const datasquirelClient = require("./client");
|
|
||||||
|
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
@ -72,7 +71,6 @@ const datasquirel = {
|
|||||||
user: user,
|
user: user,
|
||||||
getSchema: getSchema,
|
getSchema: getSchema,
|
||||||
sanitizeSql: sanitizeSql,
|
sanitizeSql: sanitizeSql,
|
||||||
client: datasquirelClient,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = datasquirel;
|
module.exports = datasquirel;
|
||||||
|
41
package-shared/types/index.d.ts
vendored
41
package-shared/types/index.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
import type { IncomingMessage, ServerResponse } from "http";
|
import http from "http";
|
||||||
|
|
||||||
import { Editor } from "tinymce";
|
import { Editor } from "tinymce";
|
||||||
export type DSQL_DatabaseFullName = string;
|
export type DSQL_DatabaseFullName = string;
|
||||||
@ -186,9 +186,9 @@ export interface PackageUserLoginLocalBody {
|
|||||||
dbSchema?: DSQL_DatabaseSchemaType;
|
dbSchema?: DSQL_DatabaseSchemaType;
|
||||||
}
|
}
|
||||||
|
|
||||||
type Request = IncomingMessage;
|
type Request = http.IncomingMessage;
|
||||||
|
|
||||||
type Response = ServerResponse;
|
type Response = http.ServerResponse;
|
||||||
|
|
||||||
type ImageInputFileToBase64FunctionReturn = {
|
type ImageInputFileToBase64FunctionReturn = {
|
||||||
imageBase64: string;
|
imageBase64: string;
|
||||||
@ -1096,38 +1096,3 @@ export type CheckApiCredentialsFnParam = {
|
|||||||
database?: string;
|
database?: string;
|
||||||
table?: string;
|
table?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FetchApiFn = (
|
|
||||||
url: string,
|
|
||||||
options?: FetchApiOptions,
|
|
||||||
csrf?: boolean
|
|
||||||
) => Promise<any>;
|
|
||||||
|
|
||||||
type FetchApiOptions = {
|
|
||||||
method:
|
|
||||||
| "POST"
|
|
||||||
| "GET"
|
|
||||||
| "DELETE"
|
|
||||||
| "PUT"
|
|
||||||
| "PATCH"
|
|
||||||
| "post"
|
|
||||||
| "get"
|
|
||||||
| "delete"
|
|
||||||
| "put"
|
|
||||||
| "patch";
|
|
||||||
body?: object | string;
|
|
||||||
headers?: FetchHeader;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type AuthCsrfHeaderName = "x-csrf-auth";
|
|
||||||
|
|
||||||
type FetchHeader = HeadersInit & {
|
|
||||||
[key in AuthCsrfHeaderName]?: string | null;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type FetchApiReturn = {
|
|
||||||
success: boolean;
|
|
||||||
payload: any;
|
|
||||||
msg?: string;
|
|
||||||
[key: string]: any;
|
|
||||||
};
|
|
||||||
|
@ -1,15 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "datasquirel",
|
"name": "datasquirel",
|
||||||
"version": "2.4.4",
|
"version": "2.4.2",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"dsql-watch": "./engine/dsql.js",
|
"dsql-watch": "./engine/dsql.js",
|
||||||
"dsql-dump": "./engine/dump.js"
|
"dsql-dump": "./engine/dump.js"
|
||||||
},
|
},
|
||||||
"scripts": {
|
|
||||||
"compile-tsc": "rm -rf dist && tsc --declaration --allowJs --outDir dist --emitDeclarationOnly --resolveJsonModule index.js && cat ./dist/index.d.ts > ./index.d.ts"
|
|
||||||
},
|
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/BenjaminToby/dsql.git"
|
"url": "git+https://github.com/BenjaminToby/dsql.git"
|
||||||
|
@ -29,8 +29,7 @@
|
|||||||
"types",
|
"types",
|
||||||
"users",
|
"users",
|
||||||
"utils",
|
"utils",
|
||||||
"package-shared",
|
"package-shared"
|
||||||
"client"
|
|
||||||
],
|
],
|
||||||
"exclude": ["node_modules", "dump"]
|
"exclude": ["node_modules", "dump"]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user