This commit is contained in:
Benjamin Toby
2025-04-18 12:06:15 +01:00
parent 8d38f99bf1
commit 6593047efd
180 changed files with 3965 additions and 2 deletions
+13
View File
@@ -0,0 +1,13 @@
type Param = {
clientId: string;
redirectUrl: string;
setLoading?: (arg0: boolean) => void;
scopes?: string[];
};
/**
* Login with Github Function
* ===============================================================================
* @description This function uses github api to login a user with datasquirel
*/
export default function getAccessToken({ clientId, redirectUrl, setLoading, scopes, }: Param): void;
export {};
+18
View File
@@ -0,0 +1,18 @@
interface GoogleGetAccessTokenFunctionParams {
clientId: string;
triggerPrompt?: boolean;
setLoading?: React.Dispatch<React.SetStateAction<boolean>>;
}
/**
* Login with Google Function
* ===============================================================================
* @description This function uses google identity api to login a user with datasquirel
*/
export default function getAccessToken(params: GoogleGetAccessTokenFunctionParams): Promise<string>;
/**
* # Google Login Function
*/
export declare function googleLogin({ google, clientId, setLoading, triggerPrompt, }: GoogleGetAccessTokenFunctionParams & {
google: any;
}): Promise<unknown>;
export {};
+8
View File
@@ -0,0 +1,8 @@
/**
* Login with Google Function
* ===============================================================================
* @description This function uses google identity api to login a user with datasquirel
*/
export default function logout(params?: {
googleClientId?: any;
}): Promise<boolean>;
+9
View File
@@ -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;
+21
View File
@@ -0,0 +1,21 @@
type FetchApiOptions = {
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
*/
export default function fetchApi(url: string, options?: FetchApiOptions, csrf?: boolean,
/** Key to use to grab local Storage csrf value. */
localStorageCSRFKey?: string): Promise<any>;
export {};
+55
View File
@@ -0,0 +1,55 @@
import imageInputFileToBase64 from "./media/imageInputFileToBase64";
import imageInputToBase64 from "./media/imageInputToBase64";
import inputFileToBase64 from "./media/inputFileToBase64";
import getAccessToken from "./auth/google/getAccessToken";
import getGithubAccessToken from "./auth/github/getAccessToken";
import logout from "./auth/logout";
import fetchApi from "./fetch";
import serializeQuery from "../package-shared/utils/serialize-query";
import serializeCookies from "../package-shared/utils/serialize-cookies";
import numberfy from "../package-shared/utils/numberfy";
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";
/**
* Main Export
*/
declare const datasquirelClient: {
media: {
imageInputToBase64: typeof imageInputToBase64;
imageInputFileToBase64: typeof imageInputFileToBase64;
inputFileToBase64: typeof inputFileToBase64;
};
auth: {
google: {
getAccessToken: typeof getAccessToken;
};
github: {
getAccessToken: typeof getGithubAccessToken;
};
logout: typeof logout;
postLogin: typeof postLogin;
};
fetch: {
fetchApi: typeof fetchApi;
clientFetch: typeof fetchApi;
};
utils: {
deserializeQuery: typeof deserializeQuery;
serializeQuery: typeof serializeQuery;
serializeCookies: typeof serializeCookies;
EJSON: {
parse: (string: string | null | number, reviver?: (this: any, key: string, value: any) => any) => {
[s: string]: any;
} | {
[s: string]: any;
}[] | undefined;
stringify: (value: any, replacer?: ((this: any, key: string, value: any) => any) | null, space?: string | number) => string | undefined;
};
numberfy: typeof numberfy;
slugify: typeof slugify;
debugLog: typeof debugLog;
};
};
export default datasquirelClient;
+14
View File
@@ -0,0 +1,14 @@
import imageInputFileToBase64 from "./imageInputFileToBase64";
import imageInputToBase64 from "./imageInputToBase64";
/**
* ==========================
* Main Export
* ==========================
*/
declare const datasquirelClient: {
media: {
imageInputToBase64: typeof imageInputToBase64;
imageInputFileToBase64: typeof imageInputFileToBase64;
};
};
export default datasquirelClient;
+11
View File
@@ -0,0 +1,11 @@
import { ImageInputFileToBase64FunctionReturn } from "../../package-shared/types";
type Param = {
imageInputFile: File;
maxWidth?: number;
imagePreviewNode?: HTMLImageElement;
};
/**
* # Image input File top Base64
*/
export default function imageInputFileToBase64({ imageInputFile, maxWidth, imagePreviewNode, }: Param): Promise<ImageInputFileToBase64FunctionReturn>;
export {};
+15
View File
@@ -0,0 +1,15 @@
type FunctionReturn = {
imageBase64?: string;
imageBase64Full?: string;
imageName?: string;
};
type Param = {
imageInput: HTMLInputElement;
maxWidth?: number;
mimeType?: string;
};
/**
* # Image Input Element to Base 64
*/
export default function imageInputToBase64({ imageInput, maxWidth, mimeType, }: Param): Promise<FunctionReturn>;
export {};
+21
View File
@@ -0,0 +1,21 @@
type FunctionReturn = {
fileBase64?: string;
fileBase64Full?: string;
fileName?: string;
fileSize?: number;
fileType?: string;
};
type Param = {
inputFile: File;
allowedRegex?: RegExp;
};
/**
* Input File to base64
* ==============================================================================
*
* @description This function takes in a *SINGLE* input file from a HTML file input element.
* HTML file input elements usually return an array of input objects, so be sure to select the target
* file from the array.
*/
export default function inputFileToBase64({ inputFile, allowedRegex, }: Param): Promise<FunctionReturn>;
export {};
+8
View File
@@ -0,0 +1,8 @@
/**
* Parse request cookies
* ============================================================================== *
* @description This function takes in a request object and returns the cookies as a JS object
*/
export default function (): {
[s: string]: any;
} | null;