Add .d.ts files

This commit is contained in:
Benjamin Toby
2024-11-08 16:44:31 +01:00
parent afd50caf42
commit 4e42a1f895
69 changed files with 1870 additions and 1 deletions
+28
View File
@@ -0,0 +1,28 @@
export = addUser;
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* Add User to Database
* ==============================================================================
* @async
*
* @param {object} props - Single object passed
* @param {string} props.key - FULL ACCESS API Key
* @param {string} props.database - Database Name
* @param {import("../package-shared/types").UserDataPayload} props.payload - User Data Payload
* @param {string} props.encryptionKey
* @param {string} [props.encryptionSalt]
*
* @returns { Promise<import("../package-shared/types").AddUserFunctionReturn> }
*/
declare function addUser({ key, payload, database, encryptionKey, encryptionSalt, }: {
key: string;
database: string;
payload: import("../package-shared/types").UserDataPayload;
encryptionKey: string;
encryptionSalt?: string;
}): Promise<import("../package-shared/types").AddUserFunctionReturn>;
+31
View File
@@ -0,0 +1,31 @@
export = getToken;
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* Get just the access token for user
* ==============================================================================
* @description This Function takes in a request object and returns a user token
* string and csrf token string
*
* @param {Object} params - Arg
* @param {http.IncomingMessage} params.request - Http request object
* @param {string} params.encryptionKey - Encryption Key
* @param {string} params.encryptionSalt - Encryption Salt
* @param {string} params.database - Database Name
*
* @returns {{ key: string | undefined, csrf: string | undefined }}
*/
declare function getToken({ request, encryptionKey, encryptionSalt, database }: {
request: http.IncomingMessage;
encryptionKey: string;
encryptionSalt: string;
database: string;
}): {
key: string | undefined;
csrf: string | undefined;
};
import http = require("http");
+27
View File
@@ -0,0 +1,27 @@
export = getUser;
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* ==============================================================================
* Main Function
* ==============================================================================
* @async
*
* @param {object} params - Single Param object containing params
* @param {String} params.key - API Key
* @param {String} params.database - Target Database
* @param {number} params.userId - user id
* @param {string[]} [params.fields] - fields to select
*
* @returns { Promise<import("../types/user.td").GetUserFunctionReturn>}
*/
declare function getUser({ key, userId, database, fields }: {
key: string;
database: string;
userId: number;
fields?: string[];
}): Promise<any>;
+49
View File
@@ -0,0 +1,49 @@
export = loginUser;
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* Login A user
* ==============================================================================
* @async
*
* @param {object} params - Single Param object containing params
* @param {String} params.key - FULL ACCESS API Key
* @param {String} params.database - Target Database
* @param {{
* email?: string,
* username?: string,
* password: string,
* }} params.payload Login Email/Username and Password
* @param {string[]} [params.additionalFields] - Additional Fields to be added to the user object
* @param {http.ServerResponse} params.response - Http response object
* @param {String} params.encryptionKey - Encryption Key
* @param {String} params.encryptionSalt - Encryption Salt
* @param {boolean} [params.email_login] - Email only Login
* @param {string} [params.email_login_code] - Email login code
* @param {string} [params.temp_code_field] - Database table field name for temporary code
* @param {boolean} [params.token] - Send access key as part of response body?
*
* @returns { Promise<import("../package-shared/types").AuthenticatedUser>}
*/
declare function loginUser({ key, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, }: {
key: string;
database: string;
payload: {
email?: string;
username?: string;
password: string;
};
additionalFields?: string[];
response: http.ServerResponse;
encryptionKey: string;
encryptionSalt: string;
email_login?: boolean;
email_login_code?: string;
temp_code_field?: string;
token?: boolean;
}): Promise<import("../package-shared/types").AuthenticatedUser>;
import http = require("http");
+22
View File
@@ -0,0 +1,22 @@
export = logoutUser;
/**
* Logout user
* ==============================================================================
* @param {object} params - Single Param object containing params
* @param {http.IncomingMessage} params.request - Http request object
* @param {http.ServerResponse} params.response - Http response object
* @param {string} [params.database] - Target database name(slug): optional => If you don't
* include this you will be logged out of all datasquirel websites instead of just the target
* database
*
* @returns {{success: boolean, payload: string}}
*/
declare function logoutUser({ request, response, database }: {
request: http.IncomingMessage;
response: http.ServerResponse;
database?: string;
}): {
success: boolean;
payload: string;
};
import http = require("http");
+38
View File
@@ -0,0 +1,38 @@
export = reauthUser;
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* ==============================================================================
* Main Function
* ==============================================================================
* @async
*
* @param {object} params - Single Param object containing params
* @param {String} params.key - API Key
* @param {String} params.database - Target Database
* @param {http.ServerResponse} params.response - Http response object
* @param {http.IncomingMessage} params.request - Http request object
* @param {("deep" | "normal")} [params.level] - Authentication level
* @param {String} params.encryptionKey - Encryption Key
* @param {String} params.encryptionSalt - Encryption Salt
* @param {string[]} [params.additionalFields] - Additional Fields to be added to the user object
* @param {string} [params.token] - access token to use instead of getting from cookie header
*
* @returns { Promise<import("../package-shared/types").ReauthUserFunctionReturn> }
*/
declare function reauthUser({ key, database, response, request, level, encryptionKey, encryptionSalt, additionalFields, token, }: {
key: string;
database: string;
response: http.ServerResponse;
request: http.IncomingMessage;
level?: ("deep" | "normal");
encryptionKey: string;
encryptionSalt: string;
additionalFields?: string[];
token?: string;
}): Promise<import("../package-shared/types").ReauthUserFunctionReturn>;
import http = require("http");
+43
View File
@@ -0,0 +1,43 @@
export = sendEmailCode;
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* Send Email Code to a User
* ==============================================================================
* @async
*
* @param {object} params - Single Param object containing params
* @param {String} params.key - FULL ACCESS API Key
* @param {String} params.database - Target Database
* @param {string} params.email Login Email/Username and Password
* @param {http.ServerResponse} params.response - Http response object
* @param {String} params.encryptionKey - Encryption Key
* @param {String} params.encryptionSalt - Encryption Salt
* @param {string} [params.temp_code_field] - Database table field name for temporary code
* @param {string} [params.mail_domain]
* @param {string} [params.mail_username]
* @param {string} [params.mail_password]
* @param {number} [params.mail_port]
* @param {string} [params.sender]
*
* @returns { Promise<boolean>}
*/
declare function sendEmailCode({ key, email, database, encryptionKey, encryptionSalt, temp_code_field, mail_domain, mail_password, mail_username, mail_port, sender, }: {
key: string;
database: string;
email: string;
response: http.ServerResponse;
encryptionKey: string;
encryptionSalt: string;
temp_code_field?: string;
mail_domain?: string;
mail_username?: string;
mail_password?: string;
mail_port?: number;
sender?: string;
}): Promise<boolean>;
import http = require("http");
+74
View File
@@ -0,0 +1,74 @@
export = githubAuth;
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* @typedef {object} FunctionReturn
* @property {boolean} success - Did the function run successfully?
* @property {{id: number, first_name: string, last_name: string, csrf_k: string, social_id: string} | null} user - Returned User
* @property {number} [dsqlUserId] - Dsql User Id
* @property {string} [msg] - Response message
*/
/**
* SERVER FUNCTION: Login with google Function
* ==============================================================================
*
* @async
*
* @param {object} params - main params object
* @param {string} params.key - API full access key
* @param {string} params.code - Github access code gotten from the client side
* @param {string?} params.email - Email gotten from the client side if available
* @param {string} params.database - Target database name(slug)
* @param {string} params.clientId - Github client id
* @param {string} params.clientSecret - Github client Secret
* @param {http.ServerResponse} params.response - HTTPS response object
* @param {string} params.encryptionKey - Encryption key
* @param {string} params.encryptionSalt - Encryption salt
* @param {object} [params.additionalFields] - Additional Fields to be added to the user object
*
* @returns { Promise<FunctionReturn | undefined> }
*/
declare function githubAuth({ key, code, email, database, clientId, clientSecret, response, encryptionKey, encryptionSalt, additionalFields, }: {
key: string;
code: string;
email: string | null;
database: string;
clientId: string;
clientSecret: string;
response: http.ServerResponse;
encryptionKey: string;
encryptionSalt: string;
additionalFields?: object;
}): Promise<FunctionReturn | undefined>;
declare namespace githubAuth {
export { FunctionReturn };
}
import http = require("http");
type FunctionReturn = {
/**
* - Did the function run successfully?
*/
success: boolean;
/**
* - Returned User
*/
user: {
id: number;
first_name: string;
last_name: string;
csrf_k: string;
social_id: string;
} | null;
/**
* - Dsql User Id
*/
dsqlUserId?: number;
/**
* - Response message
*/
msg?: string;
};
+47
View File
@@ -0,0 +1,47 @@
export = googleAuth;
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* @typedef {object | null} FunctionReturn
* @property {boolean} success - Did the function run successfully?
* @property {import("../../types/user.td").DATASQUIREL_LoggedInUser | null} user - Returned User
* @property {number} [dsqlUserId] - Dsql User Id
* @property {string} [msg] - Response message
*/
/**
* SERVER FUNCTION: Login with google Function
* ==============================================================================
*
* @async
*
* @param {object} params - main params object
* @param {string} params.key - API full access key
* @param {string} params.token - Google access token gotten from the client side
* @param {string} params.database - Target database name(slug)
* @param {string} params.clientId - Google client id
* @param {http.ServerResponse} params.response - HTTPS response object
* @param {string} params.encryptionKey - Encryption key
* @param {string} params.encryptionSalt - Encryption salt
* @param {object} [params.additionalFields] - Additional Fields to be added to the user object
*
* @returns { Promise<FunctionReturn> }
*/
declare function googleAuth({ key, token, database, clientId, response, encryptionKey, encryptionSalt, additionalFields, }: {
key: string;
token: string;
database: string;
clientId: string;
response: http.ServerResponse;
encryptionKey: string;
encryptionSalt: string;
additionalFields?: object;
}): Promise<FunctionReturn>;
declare namespace googleAuth {
export { FunctionReturn };
}
import http = require("http");
type FunctionReturn = object | null;
+29
View File
@@ -0,0 +1,29 @@
export = updateUser;
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* ==============================================================================
* Main Function
* ==============================================================================
* @async
*
* @param {object} params - API Key
* @param {String} params.key - API Key
* @param {String} params.database - Target Database
* @param {{ id: number } & Object.<string, any>} params.payload - User Object: ID is required
*
* @returns { Promise<import("../package-shared/types").UpdateUserFunctionReturn>}
*/
declare function updateUser({ key, payload, database }: {
key: string;
database: string;
payload: {
id: number;
} & {
[x: string]: any;
};
}): Promise<import("../package-shared/types").UpdateUserFunctionReturn>;
+32
View File
@@ -0,0 +1,32 @@
export = userAuth;
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* Authenticate User from request
* ==============================================================================
* @description This Function takes in a request object and returns a user object
* with the user's data
*
* @param {Object} params - Arg
* @param {http.IncomingMessage} params.request - Http request object
* @param {string} params.encryptionKey - Encryption Key
* @param {string} params.encryptionSalt - Encryption Salt
* @param {("deep" | "normal")} [params.level] - Optional. "Deep" value indicates an extra layer of security
* @param {string} params.database - Database Name
* @param {string} [params.token] - access token to use instead of getting from cookie header
*
* @returns { import("../package-shared/types").AuthenticatedUser }
*/
declare function userAuth({ request, encryptionKey, encryptionSalt, level, database, token, }: {
request: http.IncomingMessage;
encryptionKey: string;
encryptionSalt: string;
level?: ("deep" | "normal");
database: string;
token?: string;
}): import("../package-shared/types").AuthenticatedUser;
import http = require("http");
+28
View File
@@ -0,0 +1,28 @@
export = validateToken;
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* Validate Token
* ==============================================================================
* @description This Function takes in a encrypted token and returns a user object
*
* @param {Object} params - Arg
* @param {string} params.token - Encrypted Token
* @param {string} params.encryptionKey - Encryption Key
* @param {string} params.encryptionSalt - Encryption Salt
* @param {("deep" | "normal")?} [params.level] - Optional. "Deep" value indicates an extra layer of security
* @param {string} params.database - Database Name
*
* @returns { import("../package-shared/types").DATASQUIREL_LoggedInUser | null}
*/
declare function validateToken({ token, encryptionKey, encryptionSalt }: {
token: string;
encryptionKey: string;
encryptionSalt: string;
level?: ("deep" | "normal") | null;
database: string;
}): import("../package-shared/types").DATASQUIREL_LoggedInUser | null;