diff --git a/client/auth/github/getAccessToken.d.ts b/client/auth/github/getAccessToken.d.ts new file mode 100644 index 0000000..672a9ec --- /dev/null +++ b/client/auth/github/getAccessToken.d.ts @@ -0,0 +1,7 @@ +declare function _exports({ clientId, redirectUrl, setLoading, scopes }: { + clientId: string; + redirectUrl: string; + setLoading?: (arg0: boolean) => void; + scopes?: string[]; +}): void; +export = _exports; diff --git a/client/auth/google/getAccessToken.d.ts b/client/auth/google/getAccessToken.d.ts new file mode 100644 index 0000000..ce778d5 --- /dev/null +++ b/client/auth/google/getAccessToken.d.ts @@ -0,0 +1,7 @@ +declare function _exports({ clientId, element, triggerPrompt, readyStateDispatch, }: { + clientId: string; + element: HTMLElement; + triggerPrompt: boolean; + readyStateDispatch?: () => void; +}): Promise; +export = _exports; diff --git a/client/auth/logout.d.ts b/client/auth/logout.d.ts new file mode 100644 index 0000000..8535fd9 --- /dev/null +++ b/client/auth/logout.d.ts @@ -0,0 +1,2 @@ +declare function _exports(params: object | null): Promise; +export = _exports; diff --git a/client/fetch/index.d.ts b/client/fetch/index.d.ts new file mode 100644 index 0000000..fddf1ee --- /dev/null +++ b/client/fetch/index.d.ts @@ -0,0 +1,5 @@ +export = clientFetch; +declare function clientFetch(url: string, options?: import("../../package-shared/types").FetchApiOptions, csrf?: boolean): Promise; +declare namespace clientFetch { + export { clientFetch as fetchApi }; +} diff --git a/client/index.d.ts b/client/index.d.ts new file mode 100644 index 0000000..338a30b --- /dev/null +++ b/client/index.d.ts @@ -0,0 +1,26 @@ +export namespace media { + export { imageInputToBase64 }; + export { imageInputFileToBase64 }; + export { inputFileToBase64 }; +} +export namespace auth { + export namespace google { + export { getAccessToken }; + } + export namespace github { + export { getGithubAccessToken as getAccessToken }; + } + export { logout }; +} +export namespace fetch { + export { fetchApi }; + export { clientFetch }; +} +import imageInputToBase64 = require("./media/imageInputToBase64"); +import imageInputFileToBase64 = require("./media/imageInputFileToBase64"); +import inputFileToBase64 = require("./media/inputFileToBase64"); +import getAccessToken = require("./auth/google/getAccessToken"); +import getGithubAccessToken = require("./auth/github/getAccessToken"); +import logout = require("./auth/logout"); +import { fetchApi } from "./fetch"; +import clientFetch = require("./fetch"); diff --git a/client/media/imageInputFileToBase64.d.ts b/client/media/imageInputFileToBase64.d.ts new file mode 100644 index 0000000..3769031 --- /dev/null +++ b/client/media/imageInputFileToBase64.d.ts @@ -0,0 +1,8 @@ +declare function _exports({ imageInputFile, maxWidth, imagePreviewNode, }: { + imageInputFile: { + name: string; + }; + maxWidth?: number; + imagePreviewNode?: HTMLImageElement; +}): Promise; +export = _exports; diff --git a/client/media/imageInputToBase64.d.ts b/client/media/imageInputToBase64.d.ts new file mode 100644 index 0000000..d24dd25 --- /dev/null +++ b/client/media/imageInputToBase64.d.ts @@ -0,0 +1,14 @@ +declare namespace _exports { + export { FunctionReturn }; +} +declare function _exports({ imageInput, maxWidth, mimeType, }: { + imageInput: HTMLInputElement; + maxWidth?: number; + mimeType?: [string]; +}): Promise; +export = _exports; +type FunctionReturn = { + imageBase64: string; + imageBase64Full: string; + imageName: string; +}; diff --git a/client/media/inputFileToBase64.d.ts b/client/media/inputFileToBase64.d.ts new file mode 100644 index 0000000..7497274 --- /dev/null +++ b/client/media/inputFileToBase64.d.ts @@ -0,0 +1,19 @@ +declare namespace _exports { + export { FunctionReturn }; +} +declare function _exports({ inputFile, allowedRegex }: { + inputFile: { + name: string; + size: number; + type: string; + }; + allowedRegex?: RegExp; +}): Promise; +export = _exports; +type FunctionReturn = { + fileBase64: string; + fileBase64Full: string; + fileName: string; + fileSize: number; + fileType: string; +}; diff --git a/client/utils/parseClientCookies.d.ts b/client/utils/parseClientCookies.d.ts new file mode 100644 index 0000000..1f6b937 --- /dev/null +++ b/client/utils/parseClientCookies.d.ts @@ -0,0 +1,2 @@ +declare function _exports(): {} | null; +export = _exports; diff --git a/engine/engine/addUsersTableToDb.d.ts b/engine/engine/addUsersTableToDb.d.ts new file mode 100644 index 0000000..bb1d6b3 --- /dev/null +++ b/engine/engine/addUsersTableToDb.d.ts @@ -0,0 +1,4 @@ +declare function _exports({ dbSchema }: { + dbSchema: import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined; +}): Promise; +export = _exports; diff --git a/engine/engine/utils/camelJoinedtoCamelSpace.d.ts b/engine/engine/utils/camelJoinedtoCamelSpace.d.ts new file mode 100644 index 0000000..809740c --- /dev/null +++ b/engine/engine/utils/camelJoinedtoCamelSpace.d.ts @@ -0,0 +1,12 @@ +export = camelJoinedtoCamelSpace; +/** + * Convert Camel Joined Text to Camel Spaced Text + * ============================================================================== + * @description this function takes a camel cased text without spaces, and returns + * a camel-case-spaced text + * + * @param {string} text - text string without spaces + * + * @returns {string | null} + */ +declare function camelJoinedtoCamelSpace(text: string): string | null; diff --git a/engine/engine/utils/dbHandler.d.ts b/engine/engine/utils/dbHandler.d.ts new file mode 100644 index 0000000..7f29e75 --- /dev/null +++ b/engine/engine/utils/dbHandler.d.ts @@ -0,0 +1,8 @@ +declare function _exports({ query, values, database, dbSchema, tableName, }: { + query: string; + values?: (string | number)[]; + dbSchema?: import("../../../package-shared/types").DSQL_DatabaseSchemaType; + database?: string; + tableName?: string; +}): Promise; +export = _exports; diff --git a/engine/engine/utils/defaultFieldsRegexp.d.ts b/engine/engine/utils/defaultFieldsRegexp.d.ts new file mode 100644 index 0000000..078cc05 --- /dev/null +++ b/engine/engine/utils/defaultFieldsRegexp.d.ts @@ -0,0 +1,8 @@ +export = defaultFieldsRegexp; +/** + * Regular expression to match default fields + * + * @description Regular expression to match default fields + * @type {RegExp} + */ +declare const defaultFieldsRegexp: RegExp; diff --git a/engine/engine/utils/parseDbResults.d.ts b/engine/engine/utils/parseDbResults.d.ts new file mode 100644 index 0000000..b2b39a3 --- /dev/null +++ b/engine/engine/utils/parseDbResults.d.ts @@ -0,0 +1,5 @@ +declare function _exports({ unparsedResults, tableSchema, }: { + unparsedResults: any[]; + tableSchema?: import("../../../package-shared/types").DSQL_TableSchemaType; +}): Promise; +export = _exports; diff --git a/engine/engine/utils/varDatabaseDbHandler.d.ts b/engine/engine/utils/varDatabaseDbHandler.d.ts new file mode 100644 index 0000000..501f597 --- /dev/null +++ b/engine/engine/utils/varDatabaseDbHandler.d.ts @@ -0,0 +1,23 @@ +declare namespace _exports { + export { VarDbHandlerParam }; +} +declare function _exports({ queryString, queryValuesArray, database, tableSchema, }: VarDbHandlerParam): Promise; +export = _exports; +type VarDbHandlerParam = { + /** + * - SQL string + */ + queryString: string; + /** + * - Values Array + */ + queryValuesArray?: string[]; + /** + * - Database name + */ + database: string; + /** + * - Table schema + */ + tableSchema?: import("../../../package-shared/types").DSQL_TableSchemaType; +}; diff --git a/engine/query/get.d.ts b/engine/query/get.d.ts new file mode 100644 index 0000000..d36026a --- /dev/null +++ b/engine/query/get.d.ts @@ -0,0 +1,64 @@ +export = localGet; +/** + * @typedef {Object} LocalGetReturn + * @property {boolean} success - Did the function run successfully? + * @property {*} [payload] - GET request results + * @property {string} [msg] - Message + * @property {string} [error] - Error Message + */ +/** + * @typedef {Object} LocalQueryObject + * @property {string} query - Table Name + * @property {string} [tableName] - Table Name + * @property {string[]} [queryValues] - GET request results + */ +/** + * Make a get request to Datasquirel API + * ============================================================================== + * @async + * + * @param {Object} params - Single object passed + * @param {LocalQueryObject} params.options - SQL Query + * @param {import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined} [params.dbSchema] - Name of the table to query + * + * @returns { Promise } - Return Object + */ +declare function localGet({ options, dbSchema }: { + options: LocalQueryObject; + dbSchema?: import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined; +}): Promise; +declare namespace localGet { + export { LocalGetReturn, LocalQueryObject }; +} +type LocalGetReturn = { + /** + * - Did the function run successfully? + */ + success: boolean; + /** + * - GET request results + */ + payload?: any; + /** + * - Message + */ + msg?: string; + /** + * - Error Message + */ + error?: string; +}; +type LocalQueryObject = { + /** + * - Table Name + */ + query: string; + /** + * - Table Name + */ + tableName?: string; + /** + * - GET request results + */ + queryValues?: string[]; +}; diff --git a/engine/query/post.d.ts b/engine/query/post.d.ts new file mode 100644 index 0000000..51df2f4 --- /dev/null +++ b/engine/query/post.d.ts @@ -0,0 +1,16 @@ +export = localPost; +/** + * Make a get request to Datasquirel API + * ============================================================================== + * @async + * + * @param {Object} params - Single object passed + * @param {import("../../package-shared/types").LocalPostQueryObject} params.options + * @param {import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined} [params.dbSchema] + * + * @returns { Promise } + */ +declare function localPost({ options, dbSchema }: { + options: import("../../package-shared/types").LocalPostQueryObject; + dbSchema?: import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined; +}): Promise; diff --git a/engine/query/update-api-schema-from-local-db.d.ts b/engine/query/update-api-schema-from-local-db.d.ts new file mode 100644 index 0000000..d6a504b --- /dev/null +++ b/engine/query/update-api-schema-from-local-db.d.ts @@ -0,0 +1,38 @@ +export = updateApiSchemaFromLocalDb; +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** + * @typedef {Object} PostReturn + * @property {boolean} success - Did the function run successfully? + * @property {*} [payload] - The Y Coordinate + * @property {string} [error] - The Y Coordinate + */ +/** + * # Update API Schema From Local DB + * + * @async + * + * @returns { Promise } - Return Object + */ +declare function updateApiSchemaFromLocalDb(): Promise; +declare namespace updateApiSchemaFromLocalDb { + export { PostReturn }; +} +type PostReturn = { + /** + * - Did the function run successfully? + */ + success: boolean; + /** + * - The Y Coordinate + */ + payload?: any; + /** + * - The Y Coordinate + */ + error?: string; +}; diff --git a/engine/user/add-user.d.ts b/engine/user/add-user.d.ts new file mode 100644 index 0000000..51307ad --- /dev/null +++ b/engine/user/add-user.d.ts @@ -0,0 +1,20 @@ +export = localAddUser; +/** + * Make a get request to Datasquirel API + * ============================================================================== + * @async + * + * @param {Object} params - Single object passed + * @param {import("../../package-shared/types").UserDataPayload} params.payload - SQL Query + * @param {import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined} params.dbSchema - Name of the table to query + * @param {string} [params.encryptionKey] + * @param {string} [params.encryptionSalt] + * + * @returns { Promise } - Return Object + */ +declare function localAddUser({ payload, dbSchema, encryptionKey, encryptionSalt, }: { + payload: import("../../package-shared/types").UserDataPayload; + dbSchema: import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined; + encryptionKey?: string; + encryptionSalt?: string; +}): Promise; diff --git a/engine/user/get-user.d.ts b/engine/user/get-user.d.ts new file mode 100644 index 0000000..09b99c3 --- /dev/null +++ b/engine/user/get-user.d.ts @@ -0,0 +1,22 @@ +export = getLocalUser; +/** + * + * @param {object} param0 + * @param {number} param0.userId + * @param {string[]} param0.fields + * @param {import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined} [param0.dbSchema] + * @returns + */ +declare function getLocalUser({ userId, fields, dbSchema }: { + userId: number; + fields: string[]; + dbSchema?: import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined; +}): Promise<{ + success: boolean; + payload: any; + msg: string; +} | { + success: boolean; + payload: any; + msg?: undefined; +}>; diff --git a/engine/user/login-user.d.ts b/engine/user/login-user.d.ts new file mode 100644 index 0000000..c76adb2 --- /dev/null +++ b/engine/user/login-user.d.ts @@ -0,0 +1,39 @@ +export = loginLocalUser; +/** + * + * @param {import("../../package-shared/types").PackageUserLoginLocalBody} param0 + * @returns + */ +declare function loginLocalUser({ payload, additionalFields, dbSchema, email_login, email_login_code, email_login_field, }: import("../../package-shared/types").PackageUserLoginLocalBody): Promise<{ + success: boolean; + msg: string; + payload?: undefined; + userId?: undefined; +} | { + success: boolean; + payload: any; + msg: string; + userId?: undefined; +} | { + success: boolean; + msg: string; + payload: { + id: any; + first_name: any; + last_name: any; + username: any; + email: any; + phone: any; + social_id: any; + image: any; + image_thumbnail: any; + verification_status: any; + social_login: any; + social_platform: any; + csrf_k: string; + more_data: any; + logged_in_status: boolean; + date: number; + }; + userId: string; +}>; diff --git a/engine/user/reauth-user.d.ts b/engine/user/reauth-user.d.ts new file mode 100644 index 0000000..d138bb3 --- /dev/null +++ b/engine/user/reauth-user.d.ts @@ -0,0 +1,46 @@ +export = localReauthUser; +/** + * + * @param {object} param0 + * @param {*} param0.existingUser + * @param {string[]} [param0.additionalFields] + * @param {import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined} [param0.dbSchema] + * @returns + */ +declare function localReauthUser({ existingUser, additionalFields, dbSchema }: { + existingUser: any; + additionalFields?: string[]; + dbSchema?: import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined; +}): Promise<{ + success: boolean; + payload: any; + msg: string; + userId?: undefined; +} | { + success: boolean; + msg: string; + payload: { + id: any; + first_name: any; + last_name: any; + username: any; + email: any; + phone: any; + social_id: any; + image: any; + image_thumbnail: any; + verification_status: any; + social_login: any; + social_platform: any; + csrf_k: string; + more_data: any; + logged_in_status: boolean; + date: number; + }; + userId: string; +} | { + success: boolean; + msg: string; + payload?: undefined; + userId?: undefined; +}>; diff --git a/engine/user/send-email-code.d.ts b/engine/user/send-email-code.d.ts new file mode 100644 index 0000000..5e5da3a --- /dev/null +++ b/engine/user/send-email-code.d.ts @@ -0,0 +1,32 @@ +export = localSendEmailCode; +/** + * + * @param {object} param0 + * @param {string} param0.email + * @param {import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined} [param0.dbSchema] + * @param {string} param0.email_login_field + * @param {string} [param0.mail_domain] + * @param {string} [param0.mail_username] + * @param {string} [param0.mail_password] + * @param {number} [param0.mail_port] + * @param {string} [param0.sender] + * @returns + */ +declare function localSendEmailCode({ email, dbSchema, email_login_field, mail_domain, mail_username, mail_password, mail_port, sender, }: { + email: string; + dbSchema?: import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined; + email_login_field: string; + mail_domain?: string; + mail_username?: string; + mail_password?: string; + mail_port?: number; + sender?: string; +}): Promise<{ + success: boolean; + msg: string; + payload?: undefined; +} | { + success: boolean; + payload: any; + msg: string; +}>; diff --git a/engine/user/social/github-auth.d.ts b/engine/user/social/github-auth.d.ts new file mode 100644 index 0000000..77e6c44 --- /dev/null +++ b/engine/user/social/github-auth.d.ts @@ -0,0 +1,71 @@ +export = localGithubAuth; +/** + * SERVER FUNCTION: Login with google Function + * ============================================================================== + * + * @async + * + * @param {object} params - main params object + * @param {http.ServerResponse} params.res - HTTPS response object + * @param {string} params.code + * @param {string} [params.email] + * @param {string} params.clientId + * @param {string} params.clientSecret + * @param {object} [params.additionalFields] + * @param {import("../../../package-shared/types").DSQL_DatabaseSchemaType} params.dbSchema + */ +declare function localGithubAuth({ res, code, email, clientId, clientSecret, additionalFields, dbSchema, }: { + res: http.ServerResponse; + code: string; + email?: string; + clientId: string; + clientSecret: string; + additionalFields?: object; + dbSchema: import("../../../package-shared/types").DSQL_DatabaseSchemaType; +}): Promise<{ + success: boolean; + msg: string; +} | { + dsqlUserId: string; + /** + * - Did the operation complete successfully or not? + */ + success: boolean; + /** + * - User payload object: or "null" + */ + user: { + id: number; + first_name: string; + last_name: string; + } | null; + /** + * - Message + */ + msg?: string; + /** + * - Error Message + */ + error?: string; + /** + * - Social Id + */ + social_id?: string | number; + /** + * - Social Platform + */ + social_platform?: string; + /** + * - Payload + */ + payload?: object; + /** + * - Alert + */ + alert?: boolean; + /** + * - New User + */ + newUser?: any; +}>; +import http = require("http"); diff --git a/engine/user/social/google-auth.d.ts b/engine/user/social/google-auth.d.ts new file mode 100644 index 0000000..0f9db15 --- /dev/null +++ b/engine/user/social/google-auth.d.ts @@ -0,0 +1,28 @@ +export = localGoogleAuth; +/** + * SERVER FUNCTION: Login with google Function + * ============================================================================== + * + * @async + * + * @param {object} params - main params object + * @param {string} params.token - Google access token gotten from the client side + * @param {string} params.clientId - Google client id + * @param {http.ServerResponse} params.response - HTTPS response object + * @param {object} [params.additionalFields] - Additional Fields to be added to the user object + * @param {import("../../../package-shared/types").DSQL_DatabaseSchemaType} [params.dbSchema] - Database Schema + * + * @returns { Promise } + */ +declare function localGoogleAuth({ dbSchema, token, clientId, response, additionalFields, }: { + token: string; + clientId: string; + response: http.ServerResponse; + additionalFields?: object; + dbSchema?: import("../../../package-shared/types").DSQL_DatabaseSchemaType; +}): Promise; +declare namespace localGoogleAuth { + export { FunctionReturn }; +} +import http = require("http"); +type FunctionReturn = object | null; diff --git a/engine/user/social/utils/githubLogin.d.ts b/engine/user/social/utils/githubLogin.d.ts new file mode 100644 index 0000000..de8d308 --- /dev/null +++ b/engine/user/social/utils/githubLogin.d.ts @@ -0,0 +1,182 @@ +export = githubLogin; +/** + * + * @typedef {object} GithubUserPayload + * @property {string} login - Full name merged eg. "JohnDoe" + * @property {number} id - github user id + * @property {string} node_id - Some other id + * @property {string} avatar_url - profile picture + * @property {string} gravatar_id - some other id + * @property {string} url - Github user URL + * @property {string} html_url - User html URL - whatever that means + * @property {string} followers_url - Followers URL + * @property {string} following_url - Following URL + * @property {string} gists_url - Gists URL + * @property {string} starred_url - Starred URL + * @property {string} subscriptions_url - Subscriptions URL + * @property {string} organizations_url - Organizations URL + * @property {string} repos_url - Repositories URL + * @property {string} received_events_url - Received Events URL + * @property {string} type - Common value => "User" + * @property {boolean} site_admin - Is site admin or not? Boolean + * @property {string} name - More like "username" + * @property {string} company - User company + * @property {string} blog - User blog URL + * @property {string} location - User Location + * @property {string} email - User Email + * @property {string} hireable - Is user hireable + * @property {string} bio - User bio + * @property {string} twitter_username - User twitter username + * @property {number} public_repos - Number of public repositories + * @property {number} public_gists - Number of public gists + * @property {number} followers - Number of followers + * @property {number} following - Number of following + * @property {string} created_at - Date created + * @property {string} updated_at - Date updated + */ +/** + * Login/signup a github user + * ============================================================================== + * @async + * + * @param {Object} params - foundUser if any + * @param {string} params.code - github auth token + * @param {string} params.clientId - github client Id + * @param {string} params.clientSecret - github client Secret + * + * @returns {Promise} + */ +declare function githubLogin({ code, clientId, clientSecret }: { + code: string; + clientId: string; + clientSecret: string; +}): Promise; +declare namespace githubLogin { + export { GithubUserPayload }; +} +type GithubUserPayload = { + /** + * - Full name merged eg. "JohnDoe" + */ + login: string; + /** + * - github user id + */ + id: number; + /** + * - Some other id + */ + node_id: string; + /** + * - profile picture + */ + avatar_url: string; + /** + * - some other id + */ + gravatar_id: string; + /** + * - Github user URL + */ + url: string; + /** + * - User html URL - whatever that means + */ + html_url: string; + /** + * - Followers URL + */ + followers_url: string; + /** + * - Following URL + */ + following_url: string; + /** + * - Gists URL + */ + gists_url: string; + /** + * - Starred URL + */ + starred_url: string; + /** + * - Subscriptions URL + */ + subscriptions_url: string; + /** + * - Organizations URL + */ + organizations_url: string; + /** + * - Repositories URL + */ + repos_url: string; + /** + * - Received Events URL + */ + received_events_url: string; + /** + * - Common value => "User" + */ + type: string; + /** + * - Is site admin or not? Boolean + */ + site_admin: boolean; + /** + * - More like "username" + */ + name: string; + /** + * - User company + */ + company: string; + /** + * - User blog URL + */ + blog: string; + /** + * - User Location + */ + location: string; + /** + * - User Email + */ + email: string; + /** + * - Is user hireable + */ + hireable: string; + /** + * - User bio + */ + bio: string; + /** + * - User twitter username + */ + twitter_username: string; + /** + * - Number of public repositories + */ + public_repos: number; + /** + * - Number of public gists + */ + public_gists: number; + /** + * - Number of followers + */ + followers: number; + /** + * - Number of following + */ + following: number; + /** + * - Date created + */ + created_at: string; + /** + * - Date updated + */ + updated_at: string; +}; diff --git a/engine/user/social/utils/handleSocialDb.d.ts b/engine/user/social/utils/handleSocialDb.d.ts new file mode 100644 index 0000000..11603b3 --- /dev/null +++ b/engine/user/social/utils/handleSocialDb.d.ts @@ -0,0 +1,99 @@ +export = handleSocialDb; +/** + * Handle Social User Auth on Datasquirel Database + * ============================================================================== + * + * @description This function handles all social login logic after the social user + * has been authenticated and userpayload is present. The payload MUST contain the + * specified fields because this funciton will create a new user if the authenticated + * user does not exist. + * + * @param {{ + * database: string|null|undefined, + * social_id: string|number, + * email: string, + * social_platform: string, + * payload: { + * social_id: string | number, + * email: string, + * social_platform: string, + * first_name: string, + * last_name: string, + * image: string, + * image_thumbnail: string, + * username: string, + * }, + * res: http.ServerResponse, + * supEmail?: string | null, + * additionalFields?: object, + * dbSchema: import("../../../../package-shared/types").DSQL_DatabaseSchemaType | undefined + * }} params - function parameters inside an object + * + * @returns {Promise} - Response object + */ +declare function handleSocialDb({ social_id, email, social_platform, payload, res, supEmail, additionalFields, dbSchema, }: { + database: string | null | undefined; + social_id: string | number; + email: string; + social_platform: string; + payload: { + social_id: string | number; + email: string; + social_platform: string; + first_name: string; + last_name: string; + image: string; + image_thumbnail: string; + username: string; + }; + res: http.ServerResponse; + supEmail?: string | null; + additionalFields?: object; + dbSchema: import("../../../../package-shared/types").DSQL_DatabaseSchemaType | undefined; +}): Promise; +declare namespace handleSocialDb { + export { FunctionReturn }; +} +import http = require("http"); +type FunctionReturn = { + /** + * - Did the operation complete successfully or not? + */ + success: boolean; + /** + * - User payload object: or "null" + */ + user: { + id: number; + first_name: string; + last_name: string; + } | null; + /** + * - Message + */ + msg?: string; + /** + * - Error Message + */ + error?: string; + /** + * - Social Id + */ + social_id?: string | number; + /** + * - Social Platform + */ + social_platform?: string; + /** + * - Payload + */ + payload?: object; + /** + * - Alert + */ + alert?: boolean; + /** + * - New User + */ + newUser?: any; +}; diff --git a/engine/user/social/utils/httpsRequest.d.ts b/engine/user/social/utils/httpsRequest.d.ts new file mode 100644 index 0000000..32b77a8 --- /dev/null +++ b/engine/user/social/utils/httpsRequest.d.ts @@ -0,0 +1,23 @@ +export = httpsRequest; +/** + * Main Function + * ============================================================================== + * @param {{ + * url?: string, + * method: string, + * hostname: string, + * path?: string, + * href?: string, + * headers?: object, + * body?: object, + * }} params - params + */ +declare function httpsRequest({ url, method, hostname, path, href, headers, body }: { + url?: string; + method: string; + hostname: string; + path?: string; + href?: string; + headers?: object; + body?: object; +}): Promise; diff --git a/engine/user/update-user.d.ts b/engine/user/update-user.d.ts new file mode 100644 index 0000000..4ced0c4 --- /dev/null +++ b/engine/user/update-user.d.ts @@ -0,0 +1,44 @@ +export = localUpdateUser; +/** + * @typedef {Object} LocalPostReturn + * @property {boolean} success - Did the function run successfully? + * @property {*} [payload] - GET request results + * @property {string} [msg] - Message + * @property {string} [error] - Error Message + */ +/** + * Make a get request to Datasquirel API + * ============================================================================== + * @async + * + * @param {Object} params - Single object passed + * @param {*} params.payload - SQL Query + * @param {import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined} params.dbSchema - Name of the table to query + * + * @returns { Promise } - Return Object + */ +declare function localUpdateUser({ payload, dbSchema }: { + payload: any; + dbSchema: import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined; +}): Promise; +declare namespace localUpdateUser { + export { LocalPostReturn }; +} +type LocalPostReturn = { + /** + * - Did the function run successfully? + */ + success: boolean; + /** + * - GET request results + */ + payload?: any; + /** + * - Message + */ + msg?: string; + /** + * - Error Message + */ + error?: string; +}; diff --git a/functions/decrypt.d.ts b/functions/decrypt.d.ts new file mode 100644 index 0000000..51f1be4 --- /dev/null +++ b/functions/decrypt.d.ts @@ -0,0 +1,14 @@ +export = decrypt; +/** + * + * @param {object} param0 + * @param {string} param0.encryptedString + * @param {string} param0.encryptionKey + * @param {string} param0.encryptionSalt + * @returns + */ +declare function decrypt({ encryptedString, encryptionKey, encryptionSalt }: { + encryptedString: string; + encryptionKey: string; + encryptionSalt: string; +}): string; diff --git a/functions/encrypt.d.ts b/functions/encrypt.d.ts new file mode 100644 index 0000000..e05e80c --- /dev/null +++ b/functions/encrypt.d.ts @@ -0,0 +1,14 @@ +export = encrypt; +/** + * + * @param {object} param0 + * @param {string} param0.data + * @param {string} param0.encryptionKey + * @param {string} param0.encryptionSalt + * @returns {string | null} + */ +declare function encrypt({ data, encryptionKey, encryptionSalt }: { + data: string; + encryptionKey: string; + encryptionSalt: string; +}): string | null; diff --git a/functions/hashPassword.d.ts b/functions/hashPassword.d.ts new file mode 100644 index 0000000..f4be2fd --- /dev/null +++ b/functions/hashPassword.d.ts @@ -0,0 +1,5 @@ +declare function _exports({ password, encryptionKey }: { + password: string; + encryptionKey: string; +}): string; +export = _exports; diff --git a/package-shared/functions/backend/db/addDbEntry.d.ts b/package-shared/functions/backend/db/addDbEntry.d.ts new file mode 100644 index 0000000..5b7f08c --- /dev/null +++ b/package-shared/functions/backend/db/addDbEntry.d.ts @@ -0,0 +1,37 @@ +export = addDbEntry; +/** + * Add a db Entry Function + * ============================================================================== + * @description Description + * @async + * + * @param {object} params - An object containing the function parameters. + * @param {("Master" | "Dsql User")} [params.dbContext] - What is the database context? "Master" + * or "Dsql User". Defaults to "Master" + * @param {("Read Only" | "Full Access")} [params.paradigm] - What is the paradigm for "Dsql User"? + * "Read only" or "Full Access"? Defaults to "Read Only" + * @param {string} [params.dbFullName] - Database full name + * @param {string} params.tableName - Table name + * @param {any} params.data - Data to add + * @param {import("../../../types").DSQL_TableSchemaType} [params.tableSchema] - Table schema + * @param {string} [params.duplicateColumnName] - Duplicate column name + * @param {string} [params.duplicateColumnValue] - Duplicate column value + * @param {boolean} [params.update] - Update this row if it exists + * @param {string} [params.encryptionKey] - Update this row if it exists + * @param {string} [params.encryptionSalt] - Update this row if it exists + * + * @returns {Promise} + */ +declare function addDbEntry({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt, }: { + dbContext?: ("Master" | "Dsql User"); + paradigm?: ("Read Only" | "Full Access"); + dbFullName?: string; + tableName: string; + data: any; + tableSchema?: import("../../../types").DSQL_TableSchemaType; + duplicateColumnName?: string; + duplicateColumnValue?: string; + update?: boolean; + encryptionKey?: string; + encryptionSalt?: string; +}): Promise; diff --git a/package-shared/functions/backend/db/deleteDbEntry.d.ts b/package-shared/functions/backend/db/deleteDbEntry.d.ts new file mode 100644 index 0000000..630b4bd --- /dev/null +++ b/package-shared/functions/backend/db/deleteDbEntry.d.ts @@ -0,0 +1,32 @@ +export = deleteDbEntry; +/** + * Imports: Handle imports + */ +/** + * Delete DB Entry Function + * ============================================================================== + * @description Description + * @async + * + * @param {object} params - An object containing the function parameters. + * @param {string} [params.dbContext] - What is the database context? "Master" + * or "Dsql User". Defaults to "Master" + * @param {("Read Only" | "Full Access")} [params.paradigm] - What is the paradigm for "Dsql User"? + * "Read only" or "Full Access"? Defaults to "Read Only" + * @param {string} params.dbFullName - Database full name + * @param {string} params.tableName - Table name + * @param {import("../../../types").DSQL_TableSchemaType} [params.tableSchema] - Table schema + * @param {string} params.identifierColumnName - Update row identifier column name + * @param {string|number} params.identifierValue - Update row identifier column value + * + * @returns {Promise} + */ +declare function deleteDbEntry({ dbContext, paradigm, dbFullName, tableName, identifierColumnName, identifierValue, }: { + dbContext?: string; + paradigm?: ("Read Only" | "Full Access"); + dbFullName: string; + tableName: string; + tableSchema?: import("../../../types").DSQL_TableSchemaType; + identifierColumnName: string; + identifierValue: string | number; +}): Promise; diff --git a/package-shared/functions/backend/db/runQuery.d.ts b/package-shared/functions/backend/db/runQuery.d.ts new file mode 100644 index 0000000..b797a3d --- /dev/null +++ b/package-shared/functions/backend/db/runQuery.d.ts @@ -0,0 +1,30 @@ +export = runQuery; +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** + * Run DSQL users queries + * ============================================================================== + * @param {object} params - An object containing the function parameters. + * @param {string} params.dbFullName - Database full name. Eg. "datasquire_user_2_test" + * @param {string | any} params.query - Query string or object + * @param {boolean} [params.readOnly] - Is this operation read only? + * @param {boolean} [params.local] - Is this operation read only? + * @param {import("../../../types").DSQL_DatabaseSchemaType} [params.dbSchema] - Database schema + * @param {string[]} [params.queryValuesArray] - An optional array of query values if "?" is used in the query string + * @param {string} [params.tableName] - Table Name + * + * @return {Promise} + */ +declare function runQuery({ dbFullName, query, readOnly, dbSchema, queryValuesArray, tableName, local, }: { + dbFullName: string; + query: string | any; + readOnly?: boolean; + local?: boolean; + dbSchema?: import("../../../types").DSQL_DatabaseSchemaType; + queryValuesArray?: string[]; + tableName?: string; +}): Promise; diff --git a/package-shared/functions/backend/db/updateDbEntry.d.ts b/package-shared/functions/backend/db/updateDbEntry.d.ts new file mode 100644 index 0000000..5446d6e --- /dev/null +++ b/package-shared/functions/backend/db/updateDbEntry.d.ts @@ -0,0 +1,35 @@ +export = updateDbEntry; +/** + * Update DB Function + * ============================================================================== + * @description Description + * @async + * + * @param {object} params - An object containing the function parameters. + * @param {("Master" | "Dsql User")} [params.dbContext] - What is the database context? "Master" + * or "Dsql User". Defaults to "Master" + * @param {("Read Only" | "Full Access")} [params.paradigm] - What is the paradigm for "Dsql User"? + * "Read only" or "Full Access"? Defaults to "Read Only" + * @param {string} [params.dbFullName] - Database full name + * @param {string} params.tableName - Table name + * @param {string} [params.encryptionKey] + * @param {string} [params.encryptionSalt] + * @param {any} params.data - Data to add + * @param {import("../../../types").DSQL_TableSchemaType} [params.tableSchema] - Table schema + * @param {string} params.identifierColumnName - Update row identifier column name + * @param {string | number} params.identifierValue - Update row identifier column value + * + * @returns {Promise} + */ +declare function updateDbEntry({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt, }: { + dbContext?: ("Master" | "Dsql User"); + paradigm?: ("Read Only" | "Full Access"); + dbFullName?: string; + tableName: string; + encryptionKey?: string; + encryptionSalt?: string; + data: any; + tableSchema?: import("../../../types").DSQL_TableSchemaType; + identifierColumnName: string; + identifierValue: string | number; +}): Promise; diff --git a/package-shared/functions/backend/decrypt.d.ts b/package-shared/functions/backend/decrypt.d.ts new file mode 100644 index 0000000..35a1bb6 --- /dev/null +++ b/package-shared/functions/backend/decrypt.d.ts @@ -0,0 +1,6 @@ +export = decrypt; +/** + * @param {string} encryptedString + * @returns {string | null} + */ +declare function decrypt(encryptedString: string): string | null; diff --git a/package-shared/functions/backend/defaultFieldsRegexp.d.ts b/package-shared/functions/backend/defaultFieldsRegexp.d.ts new file mode 100644 index 0000000..fc8ca8c --- /dev/null +++ b/package-shared/functions/backend/defaultFieldsRegexp.d.ts @@ -0,0 +1,7 @@ +export = defaultFieldsRegexp; +/** + * Regular expression to match default fields + * + * @description Regular expression to match default fields + */ +declare const defaultFieldsRegexp: RegExp; diff --git a/package-shared/functions/backend/encrypt.d.ts b/package-shared/functions/backend/encrypt.d.ts new file mode 100644 index 0000000..24f82f5 --- /dev/null +++ b/package-shared/functions/backend/encrypt.d.ts @@ -0,0 +1,9 @@ +export = encrypt; +/** + * @async + * @param {string} data + * @param {string} [encryptionKey] + * @param {string} [encryptionSalt] + * @returns {string | null} + */ +declare function encrypt(data: string, encryptionKey?: string, encryptionSalt?: string): string | null; diff --git a/package-shared/functions/backend/fullAccessDbHandler.d.ts b/package-shared/functions/backend/fullAccessDbHandler.d.ts new file mode 100644 index 0000000..7511d7c --- /dev/null +++ b/package-shared/functions/backend/fullAccessDbHandler.d.ts @@ -0,0 +1,8 @@ +declare function _exports({ queryString, database, tableSchema, queryValuesArray, local, }: { + queryString: string; + database: string; + local?: boolean; + tableSchema?: import("../../types").DSQL_TableSchemaType | null; + queryValuesArray?: string[]; +}): Promise; +export = _exports; diff --git a/package-shared/functions/backend/html/sanitizeHtmlOptions.d.ts b/package-shared/functions/backend/html/sanitizeHtmlOptions.d.ts new file mode 100644 index 0000000..7e587c9 --- /dev/null +++ b/package-shared/functions/backend/html/sanitizeHtmlOptions.d.ts @@ -0,0 +1,6 @@ +export let allowedTags: string[]; +export let allowedAttributes: { + a: string[]; + img: string[]; + "*": string[]; +}; diff --git a/package-shared/functions/backend/parseDbResults.d.ts b/package-shared/functions/backend/parseDbResults.d.ts new file mode 100644 index 0000000..b04bca9 --- /dev/null +++ b/package-shared/functions/backend/parseDbResults.d.ts @@ -0,0 +1,5 @@ +declare function _exports({ unparsedResults, tableSchema, }: { + unparsedResults: any[]; + tableSchema?: import("../../types").DSQL_TableSchemaType; +}): Promise; +export = _exports; diff --git a/package-shared/functions/backend/serverError.d.ts b/package-shared/functions/backend/serverError.d.ts new file mode 100644 index 0000000..4715f61 --- /dev/null +++ b/package-shared/functions/backend/serverError.d.ts @@ -0,0 +1,12 @@ +declare function _exports({ user, message, component, noMail, }: { + user?: { + id?: number | string; + first_name?: string; + last_name?: string; + email?: string; + } & any; + message: string; + component?: string; + noMail?: boolean; +}): Promise; +export = _exports; diff --git a/package-shared/functions/backend/varReadOnlyDatabaseDbHandler.d.ts b/package-shared/functions/backend/varReadOnlyDatabaseDbHandler.d.ts new file mode 100644 index 0000000..4bd2b65 --- /dev/null +++ b/package-shared/functions/backend/varReadOnlyDatabaseDbHandler.d.ts @@ -0,0 +1,7 @@ +declare function _exports({ queryString, database, queryValuesArray, tableSchema, }: { + queryString: string; + database: string; + queryValuesArray?: string[]; + tableSchema?: import("../../types").DSQL_TableSchemaType; +}): Promise; +export = _exports; diff --git a/package-shared/utils/backend/global-db/DB_HANDLER.d.ts b/package-shared/utils/backend/global-db/DB_HANDLER.d.ts new file mode 100644 index 0000000..433d7ec --- /dev/null +++ b/package-shared/utils/backend/global-db/DB_HANDLER.d.ts @@ -0,0 +1,9 @@ +export = DB_HANDLER; +/** + * DSQL user read-only DB handler + * @param {object} params + * @param {string} params.paradigm + * @param {string} params.database + * @param {string} params.queryString + * @param {string[]} [params.queryValues] + */ declare function DB_HANDLER(...args: any[]): Promise; diff --git a/package-shared/utils/backend/global-db/DSQL_USER_DB_HANDLER.d.ts b/package-shared/utils/backend/global-db/DSQL_USER_DB_HANDLER.d.ts new file mode 100644 index 0000000..a616bb1 --- /dev/null +++ b/package-shared/utils/backend/global-db/DSQL_USER_DB_HANDLER.d.ts @@ -0,0 +1,18 @@ +export = DSQL_USER_DB_HANDLER; +/** + * DSQL user read-only DB handler + * @param {object} params + * @param {"Full Access" | "FA" | "Read Only"} params.paradigm + * @param {string} params.database + * @param {string} params.queryString + * @param {string[]} [params.queryValues] + */ +declare function DSQL_USER_DB_HANDLER({ paradigm, database, queryString, queryValues, }: { + paradigm: "Full Access" | "FA" | "Read Only"; + database: string; + queryString: string; + queryValues?: string[]; +}): Promise | { + success: boolean; + error: any; +}; diff --git a/package-shared/utils/backend/grabDbSSL.d.ts b/package-shared/utils/backend/grabDbSSL.d.ts new file mode 100644 index 0000000..abedcdb --- /dev/null +++ b/package-shared/utils/backend/grabDbSSL.d.ts @@ -0,0 +1,4 @@ +declare function _exports(): string | (import("tls").SecureContextOptions & { + rejectUnauthorized?: boolean | undefined; +}) | undefined; +export = _exports; diff --git a/package.json b/package.json index 1a6d4cb..f26bbd4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datasquirel", - "version": "2.4.4", + "version": "2.4.5", "description": "Cloud-based SQL data management tool", "main": "index.js", "bin": { @@ -8,6 +8,7 @@ "dsql-dump": "./engine/dump.js" }, "scripts": { + "compile": "tsc --declaration --allowJs --emitDeclarationOnly --resolveJsonModule index.js", "compile-tsc": "rm -rf dist && tsc --declaration --allowJs --outDir dist --emitDeclarationOnly --resolveJsonModule index.js && cat ./dist/index.d.ts > ./index.d.ts" }, "repository": { diff --git a/users/add-user.d.ts b/users/add-user.d.ts new file mode 100644 index 0000000..ddaad75 --- /dev/null +++ b/users/add-user.d.ts @@ -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 } + */ +declare function addUser({ key, payload, database, encryptionKey, encryptionSalt, }: { + key: string; + database: string; + payload: import("../package-shared/types").UserDataPayload; + encryptionKey: string; + encryptionSalt?: string; +}): Promise; diff --git a/users/get-token.d.ts b/users/get-token.d.ts new file mode 100644 index 0000000..4a6ed0f --- /dev/null +++ b/users/get-token.d.ts @@ -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"); diff --git a/users/get-user.d.ts b/users/get-user.d.ts new file mode 100644 index 0000000..393da65 --- /dev/null +++ b/users/get-user.d.ts @@ -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} + */ +declare function getUser({ key, userId, database, fields }: { + key: string; + database: string; + userId: number; + fields?: string[]; +}): Promise; diff --git a/users/login-user.d.ts b/users/login-user.d.ts new file mode 100644 index 0000000..d9d0031 --- /dev/null +++ b/users/login-user.d.ts @@ -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} + */ +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 http = require("http"); diff --git a/users/logout-user.d.ts b/users/logout-user.d.ts new file mode 100644 index 0000000..47274a4 --- /dev/null +++ b/users/logout-user.d.ts @@ -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"); diff --git a/users/reauth-user.d.ts b/users/reauth-user.d.ts new file mode 100644 index 0000000..2766e3c --- /dev/null +++ b/users/reauth-user.d.ts @@ -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 } + */ +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 http = require("http"); diff --git a/users/send-email-code.d.ts b/users/send-email-code.d.ts new file mode 100644 index 0000000..a691831 --- /dev/null +++ b/users/send-email-code.d.ts @@ -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} + */ +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; +import http = require("http"); diff --git a/users/social/github-auth.d.ts b/users/social/github-auth.d.ts new file mode 100644 index 0000000..23a6a8d --- /dev/null +++ b/users/social/github-auth.d.ts @@ -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 } + */ +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; +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; +}; diff --git a/users/social/google-auth.d.ts b/users/social/google-auth.d.ts new file mode 100644 index 0000000..41a7bc2 --- /dev/null +++ b/users/social/google-auth.d.ts @@ -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 } + */ +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; +declare namespace googleAuth { + export { FunctionReturn }; +} +import http = require("http"); +type FunctionReturn = object | null; diff --git a/users/update-user.d.ts b/users/update-user.d.ts new file mode 100644 index 0000000..6efa0b6 --- /dev/null +++ b/users/update-user.d.ts @@ -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.} params.payload - User Object: ID is required + * + * @returns { Promise} + */ +declare function updateUser({ key, payload, database }: { + key: string; + database: string; + payload: { + id: number; + } & { + [x: string]: any; + }; +}): Promise; diff --git a/users/user-auth.d.ts b/users/user-auth.d.ts new file mode 100644 index 0000000..0f8e88e --- /dev/null +++ b/users/user-auth.d.ts @@ -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"); diff --git a/users/validate-token.d.ts b/users/validate-token.d.ts new file mode 100644 index 0000000..dd37a03 --- /dev/null +++ b/users/validate-token.d.ts @@ -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; diff --git a/utils/delete-file.d.ts b/utils/delete-file.d.ts new file mode 100644 index 0000000..4334e7a --- /dev/null +++ b/utils/delete-file.d.ts @@ -0,0 +1,52 @@ +export = uploadImage; +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** + * @typedef {Object} FunctionReturn + * @property {boolean} success - Did the function run successfully? + * @property {{ + * urlPath: string, + * urlThumbnailPath: string + * }} payload - Payload containing the url for the image and its thumbnail + * @property {string} [msg] - An optional message + */ +/** + * ============================================================================== + * Main Function + * ============================================================================== + * @async + * + * @param {Object} params - Single Param object containing params + * @param {String} params.key - *FULL ACCESS API Key + * @param { string } params.url - File URL + * + * @returns { Promise } - Image Url + */ +declare function uploadImage({ key, url }: { + key: string; + url: string; +}): Promise; +declare namespace uploadImage { + export { FunctionReturn }; +} +type FunctionReturn = { + /** + * - Did the function run successfully? + */ + success: boolean; + /** + * - Payload containing the url for the image and its thumbnail + */ + payload: { + urlPath: string; + urlThumbnailPath: string; + }; + /** + * - An optional message + */ + msg?: string; +}; diff --git a/utils/functions/parseCookies.d.ts b/utils/functions/parseCookies.d.ts new file mode 100644 index 0000000..2b064f5 --- /dev/null +++ b/utils/functions/parseCookies.d.ts @@ -0,0 +1,5 @@ +declare function _exports({ request }: { + request: http.IncomingMessage; +}): any | null; +export = _exports; +import http = require("http"); diff --git a/utils/functions/sanitizeSql.d.ts b/utils/functions/sanitizeSql.d.ts new file mode 100644 index 0000000..2621202 --- /dev/null +++ b/utils/functions/sanitizeSql.d.ts @@ -0,0 +1,13 @@ +export = sanitizeSql; +/** + * Sanitize SQL function + * ============================================================================== + * @description this function takes in a text(or number) or object or array or + * boolean and returns a sanitized version of the same input. + * + * @param {string|number|object|boolean} input - Text or number or object or boolean + * @param {boolean?} spaces - Allow spaces? + * + * @returns {string|number|object|boolean} + */ +declare function sanitizeSql(input: string | number | object | boolean, spaces: boolean | null): string | number | object | boolean; diff --git a/utils/functions/serialize-query.d.ts b/utils/functions/serialize-query.d.ts new file mode 100644 index 0000000..3a27633 --- /dev/null +++ b/utils/functions/serialize-query.d.ts @@ -0,0 +1,2 @@ +export = serializeQuery; +declare function serializeQuery(param0: import("../../package-shared/types").SerializeQueryParams): string; diff --git a/utils/get-schema.d.ts b/utils/get-schema.d.ts new file mode 100644 index 0000000..4966f89 --- /dev/null +++ b/utils/get-schema.d.ts @@ -0,0 +1,32 @@ +export = getSchema; +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** + * @typedef {Object} GetSchemaReturn + * @property {boolean} success - Did the function run successfully? + * @property {import("../package-shared/types").DSQL_DatabaseSchemaType | import("../package-shared/types").DSQL_TableSchemaType | import("../package-shared/types").DSQL_FieldSchemaType | null} payload - Response payload + */ +/** + * # Get Schema for Database, table, or field * + * @param {import("../package-shared/types").GetSchemaAPIParam} params + * + * @returns { Promise } - Return Object + */ +declare function getSchema({ key, database, field, table }: import("../package-shared/types").GetSchemaAPIParam): Promise; +declare namespace getSchema { + export { GetSchemaReturn }; +} +type GetSchemaReturn = { + /** + * - Did the function run successfully? + */ + success: boolean; + /** + * - Response payload + */ + payload: import("../package-shared/types").DSQL_DatabaseSchemaType | import("../package-shared/types").DSQL_TableSchemaType | import("../package-shared/types").DSQL_FieldSchemaType | null; +}; diff --git a/utils/get.d.ts b/utils/get.d.ts new file mode 100644 index 0000000..d1d57d8 --- /dev/null +++ b/utils/get.d.ts @@ -0,0 +1,28 @@ +export = get; +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** + * Make a get request to Datasquirel API + * ============================================================================== + * @async + * + * @param {Object} params - Single object passed + * @param {string} [params.key] - API Key + * @param {string} [params.db] - Database Name + * @param {string} params.query - SQL Query + * @param {string[]} [params.queryValues] - An array of query values if using "?" placeholders + * @param {string} [params.tableName] - Name of the table to query + * + * @returns { Promise } - Return Object + */ +declare function get({ key, db, query, queryValues, tableName }: { + key?: string; + db?: string; + query: string; + queryValues?: string[]; + tableName?: string; +}): Promise; diff --git a/utils/post.d.ts b/utils/post.d.ts new file mode 100644 index 0000000..f85e925 --- /dev/null +++ b/utils/post.d.ts @@ -0,0 +1,28 @@ +export = post; +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** + * Make a post request to Datasquirel API + * ============================================================================== + * @async + * + * @param {Object} params - Single object passed + * @param {string} [params.key] - FULL ACCESS API Key + * @param {string} [params.database] - Database Name + * @param {import("../package-shared/types").PostDataPayload | string} params.query - SQL query String or Request Object + * @param {any[]} [params.queryValues] - Query Values if using "?" placeholders + * @param {string} [params.tableName] - Name of the table to query + * + * @returns { Promise } - Return Object + */ +declare function post({ key, query, queryValues, database, tableName }: { + key?: string; + database?: string; + query: import("../package-shared/types").PostDataPayload | string; + queryValues?: any[]; + tableName?: string; +}): Promise; diff --git a/utils/upload-file.d.ts b/utils/upload-file.d.ts new file mode 100644 index 0000000..bc470ca --- /dev/null +++ b/utils/upload-file.d.ts @@ -0,0 +1,62 @@ +export = uploadImage; +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** + * @typedef {Object} FunctionReturn + * @property {boolean} success - Did the function run successfully? + * @property {{ + * urlPath: string, + * } | null} payload - Payload containing the url for the image and its thumbnail + * @property {string} [msg] - An optional message + */ +/** + * ============================================================================== + * Main Function + * ============================================================================== + * @async + * + * @param {Object} params - Single Param object containing params + * @param {String} params.key - *FULL ACCESS API Key + * @param {{ + * fileData: string, + * fileName: string, + * mimeType?: string, + * folder?: string, + * isPrivate?: boolean, + * }} params.payload - Image Data Eg. + * + * @returns { Promise } - Return Object + */ +declare function uploadImage({ key, payload }: { + key: string; + payload: { + fileData: string; + fileName: string; + mimeType?: string; + folder?: string; + isPrivate?: boolean; + }; +}): Promise; +declare namespace uploadImage { + export { FunctionReturn }; +} +type FunctionReturn = { + /** + * - Did the function run successfully? + */ + success: boolean; + /** + * - Payload containing the url for the image and its thumbnail + */ + payload: { + urlPath: string; + } | null; + /** + * - An optional message + */ + msg?: string; +}; diff --git a/utils/upload-image.d.ts b/utils/upload-image.d.ts new file mode 100644 index 0000000..980cf23 --- /dev/null +++ b/utils/upload-image.d.ts @@ -0,0 +1,66 @@ +export = uploadImage; +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** + * @typedef {Object} FunctionReturn + * @property {boolean} success - Did the function run successfully? + * @property {{ + * urlPath: string, + * urlThumbnailPath: string + * } | null} payload - Payload containing the url for the image and its thumbnail + * @property {string} [msg] - An optional message + */ +/** + * ============================================================================== + * Main Function + * ============================================================================== + * @async + * + * @param {Object} params - Single Param object containing params + * @param {String} params.key - *FULL ACCESS API Key + * @param {{ + * imageData: string, + * imageName: string, + * mimeType?: string, + * thumbnailSize?: number, + * folder?: string, + * isPrivate?: boolean, + * }} params.payload - Image Data Eg. + * + * @returns { Promise } - Return Object + */ +declare function uploadImage({ key, payload }: { + key: string; + payload: { + imageData: string; + imageName: string; + mimeType?: string; + thumbnailSize?: number; + folder?: string; + isPrivate?: boolean; + }; +}): Promise; +declare namespace uploadImage { + export { FunctionReturn }; +} +type FunctionReturn = { + /** + * - Did the function run successfully? + */ + success: boolean; + /** + * - Payload containing the url for the image and its thumbnail + */ + payload: { + urlPath: string; + urlThumbnailPath: string; + } | null; + /** + * - An optional message + */ + msg?: string; +};