Type Checking

This commit is contained in:
Tben 2023-08-07 04:42:49 +01:00
parent 7c30558173
commit 65d6424dcf
8 changed files with 34 additions and 69 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "datasquirel", "name": "datasquirel",
"version": "1.2.4", "version": "1.2.5",
"description": "Cloud-based SQL data management tool", "description": "Cloud-based SQL data management tool",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@ -1,8 +1,11 @@
// @ts-check
/** /**
* ============================================================================== * ==============================================================================
* Imports * Imports
* ============================================================================== * ==============================================================================
*/ */
const http = require("http");
const https = require("https"); const https = require("https");
const encrypt = require("../functions/encrypt"); const encrypt = require("../functions/encrypt");
@ -16,25 +19,9 @@ const encrypt = require("../functions/encrypt");
/** /**
* @typedef {object} AuthenticatedUser * @typedef {object} AuthenticatedUser
* @property {boolean} success - Did the function run successfully? * @property {boolean} success - Did the function run successfully?
* @property {{ * @property {import("../types/user.td").DATASQUIREL_LoggedInUser | null} payload - Payload of the response
* id: number,
* first_name: string,
* last_name: string,
* username: string,
* email: string,
* phone: string,
* social_id?: string,
* image: string,
* image_thumbnail: string,
* verification_status?: number,
* social_login?: number,
* social_platform?: string,
* csrf_k: string,
* more_data?: string,
* logged_in_status: boolean,
* date: string,
* }} payload - Payload of the response
* @property {string} [msg] - An optional message * @property {string} [msg] - An optional message
* @property {number} [userId] - An optional message
*/ */
/** /**
@ -51,7 +38,7 @@ const encrypt = require("../functions/encrypt");
* password: string, * password: string,
* }} params.payload Login Email/Username and Password * }} params.payload Login Email/Username and Password
* @param {string[]} [params.additionalFields] - Additional Fields to be added to the user object * @param {string[]} [params.additionalFields] - Additional Fields to be added to the user object
* @param {Object} params.response - Http response object * @param {http.ServerResponse} params.response - Http response object
* @param {String} params.encryptionKey - Encryption Key * @param {String} params.encryptionKey - Encryption Key
* @param {String} params.encryptionSalt - Encryption Salt * @param {String} params.encryptionSalt - Encryption Salt
* *
@ -96,7 +83,7 @@ async function loginUser({ key, payload, database, additionalFields, response, e
* *
* @description make a request to datasquirel.com * @description make a request to datasquirel.com
* *
* @type {{ success: boolean, payload: DATASQUIREL_LoggedInUser | null }} * @type {{ success: boolean, payload: import("../types/user.td").DATASQUIREL_LoggedInUser | null, userId?: number, msg?: string }}
*/ */
const httpResponse = await new Promise((resolve, reject) => { const httpResponse = await new Promise((resolve, reject) => {
const reqPayload = JSON.stringify({ const reqPayload = JSON.stringify({
@ -165,7 +152,7 @@ async function loginUser({ key, payload, database, additionalFields, response, e
const authKeyName = `datasquirel_${userId}_${database}_auth_key`; const authKeyName = `datasquirel_${userId}_${database}_auth_key`;
const csrfName = `datasquirel_${userId}_${database}_csrf`; const csrfName = `datasquirel_${userId}_${database}_csrf`;
response.setHeader("Set-Cookie", [`${authKeyName}=${encryptedPayload};samesite=strict;path=/;HttpOnly=true;Secure=true`, `${csrfName}=${httpResponse.payload.csrf_k};samesite=strict;path=/;HttpOnly=true`, `dsqluid=${userId};samesite=strict;path=/;HttpOnly=true`]); response.setHeader("Set-Cookie", [`${authKeyName}=${encryptedPayload};samesite=strict;path=/;HttpOnly=true;Secure=true`, `${csrfName}=${httpResponse.payload?.csrf_k};samesite=strict;path=/;HttpOnly=true`, `dsqluid=${userId};samesite=strict;path=/;HttpOnly=true`]);
} }
/** ********************************************** */ /** ********************************************** */

View File

@ -1,11 +1,14 @@
// @ts-check
const http = require("http");
const parseCookies = require("../utils/functions/parseCookies"); const parseCookies = require("../utils/functions/parseCookies");
/** /**
* Logout user * Logout user
* ============================================================================== * ==============================================================================
* @param {object} params - Single Param object containing params * @param {object} params - Single Param object containing params
* @param {object} params.request - Http request object * @param {http.IncomingMessage} params.request - Http request object
* @param {object} params.response - Http response object * @param {http.ServerResponse} params.response - Http response object
* @param {string} [params.database] - Target database name(slug): optional => If you don't * @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 * include this you will be logged out of all datasquirel websites instead of just the target
* database * database

View File

@ -1,8 +1,11 @@
// @ts-check
/** /**
* ============================================================================== * ==============================================================================
* Imports * Imports
* ============================================================================== * ==============================================================================
*/ */
const http = require("http");
const https = require("https"); const https = require("https");
const encrypt = require("../functions/encrypt"); const encrypt = require("../functions/encrypt");
@ -18,24 +21,7 @@ const userAuth = require("./user-auth");
/** /**
* @typedef {object} FunctionReturn * @typedef {object} FunctionReturn
* @property {boolean} success - Did the function run successfully? * @property {boolean} success - Did the function run successfully?
* @property {{ * @property {import("../types/user.td").DATASQUIREL_LoggedInUser | null} payload - Payload
* id: number,
* first_name: string,
* last_name: string,
* username: string,
* email: string,
* phone: string,
* social_id: [string],
* image: string,
* image_thumbnail: string,
* verification_status: [number=0],
* social_login: [number],
* social_platform: [string],
* csrf_k: string,
* more_data: [string],
* logged_in_status: boolean,
* date: string,
* }} payload - Payload
* @property {string} [msg] - Response Message * @property {string} [msg] - Response Message
* @property {number} [userId] - user ID * @property {number} [userId] - user ID
*/ */
@ -49,8 +35,8 @@ const userAuth = require("./user-auth");
* @param {object} params - Single Param object containing params * @param {object} params - Single Param object containing params
* @param {String} params.key - API Key * @param {String} params.key - API Key
* @param {String} params.database - Target Database * @param {String} params.database - Target Database
* @param {Object} params.response - Http response object * @param {http.ServerResponse} params.response - Http response object
* @param {Object} params.request - Http request object * @param {http.IncomingMessage} params.request - Http request object
* @param {string} params.level - Authentication level * @param {string} params.level - Authentication level
* @param {String} params.encryptionKey - Encryption Key * @param {String} params.encryptionKey - Encryption Key
* @param {String} params.encryptionSalt - Encryption Salt * @param {String} params.encryptionSalt - Encryption Salt

View File

@ -5,6 +5,7 @@
* Imports * Imports
* ============================================================================== * ==============================================================================
*/ */
const http = require("http");
const https = require("https"); const https = require("https");
const encrypt = require("../../functions/encrypt"); const encrypt = require("../../functions/encrypt");
@ -36,7 +37,7 @@ const encrypt = require("../../functions/encrypt");
* @param {string} params.database - Target database name(slug) * @param {string} params.database - Target database name(slug)
* @param {string} params.clientId - Github client id * @param {string} params.clientId - Github client id
* @param {string} params.clientSecret - Github client Secret * @param {string} params.clientSecret - Github client Secret
* @param {object} params.response - HTTPS response object * @param {http.ServerResponse} params.response - HTTPS response object
* @param {string} params.encryptionKey - Encryption key * @param {string} params.encryptionKey - Encryption key
* @param {string} params.encryptionSalt - Encryption salt * @param {string} params.encryptionSalt - Encryption salt
* @param {object} [params.additionalFields] - Additional Fields to be added to the user object * @param {object} [params.additionalFields] - Additional Fields to be added to the user object

View File

@ -1,8 +1,11 @@
// @ts-check
/** /**
* ============================================================================== * ==============================================================================
* Imports * Imports
* ============================================================================== * ==============================================================================
*/ */
const http = require("http");
const https = require("https"); const https = require("https");
const encrypt = require("../../functions/encrypt"); const encrypt = require("../../functions/encrypt");
@ -14,10 +17,10 @@ const encrypt = require("../../functions/encrypt");
/** ****************************************************************************** */ /** ****************************************************************************** */
/** /**
* @typedef {object} FunctionReturn * @typedef {object | null} FunctionReturn
* @property {boolean} success - Did the function run successfully? * @property {boolean} success - Did the function run successfully?
* @property {{id: number, first_name: string, last_name: string}|null} user - Returned User * @property {import("../../types/user.td").DATASQUIREL_LoggedInUser | null} user - Returned User
* @property {number} dsqlUserId - Dsql User Id * @property {number} [dsqlUserId] - Dsql User Id
* @property {string} [msg] - Response message * @property {string} [msg] - Response message
*/ */
@ -32,7 +35,7 @@ const encrypt = require("../../functions/encrypt");
* @param {string} params.token - Google access token gotten from the client side * @param {string} params.token - Google access token gotten from the client side
* @param {string} params.database - Target database name(slug) * @param {string} params.database - Target database name(slug)
* @param {string} params.clientId - Google client id * @param {string} params.clientId - Google client id
* @param {object} params.response - HTTPS response object * @param {http.ServerResponse} params.response - HTTPS response object
* @param {string} params.encryptionKey - Encryption key * @param {string} params.encryptionKey - Encryption key
* @param {string} params.encryptionSalt - Encryption salt * @param {string} params.encryptionSalt - Encryption salt
* @param {object} [params.additionalFields] - Additional Fields to be added to the user object * @param {object} [params.additionalFields] - Additional Fields to be added to the user object
@ -109,7 +112,7 @@ async function googleAuth({ key, token, database, clientId, response, encryption
* Make https request * Make https request
* *
* @description make a request to datasquirel.com * @description make a request to datasquirel.com
* @type {{ success: boolean, user: {id: number} | null, msg: string|null } | null} - Https response object * @type {{ success: boolean, user: import("../../types/user.td").DATASQUIREL_LoggedInUser | null, msg?: string, dsqlUserId?: number } | null } - Https response object
*/ */
const httpResponse = await new Promise((resolve, reject) => { const httpResponse = await new Promise((resolve, reject) => {
const reqPayload = JSON.stringify({ const reqPayload = JSON.stringify({

View File

@ -1,3 +1,5 @@
// @ts-check
/** /**
* ============================================================================== * ==============================================================================
* Imports * Imports
@ -16,24 +18,7 @@ const parseCookies = require("../utils/functions/parseCookies");
/** /**
* @typedef {object} AuthenticatedUserObject * @typedef {object} AuthenticatedUserObject
* @property {boolean} success - Did the function run successfully? * @property {boolean} success - Did the function run successfully?
* @property {{ * @property {import("../types/user.td").DATASQUIREL_LoggedInUser | null} payload - Payload
* id: number,
* first_name: string,
* last_name: string,
* username: string,
* email: string,
* phone: string,
* social_id: [string],
* image: string,
* image_thumbnail: string,
* verification_status: [number=0],
* social_login: [number],
* social_platform: [string],
* csrf_k: string,
* more_data: [string],
* logged_in_status: boolean,
* date: string,
* }} payload - Payload
* @property {string} [msg] - Response Message * @property {string} [msg] - Response Message
*/ */

View File

@ -15,7 +15,7 @@
* @param {object} params - main params object * @param {object} params - main params object
* @param {object} params.request - HTTPS request object * @param {object} params.request - HTTPS request object
* *
* @returns {{}|null} * @returns {object|null}
*/ */
module.exports = function ({ request }) { module.exports = function ({ request }) {
/** /**