This commit is contained in:
Benjamin Toby 2024-12-10 19:44:11 +01:00
parent b3b906ba8c
commit 8fe65e5c8d
3 changed files with 13 additions and 50 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@moduletrace/datasquirel", "name": "@moduletrace/datasquirel",
"version": "2.9.0", "version": "2.9.1",
"description": "Cloud-based SQL data management tool", "description": "Cloud-based SQL data management tool",
"main": "index.js", "main": "index.js",
"bin": { "bin": {

View File

@ -1,10 +1,4 @@
export = googleAuth; export = googleAuth;
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** /**
* @typedef {object | null} FunctionReturn * @typedef {object | null} FunctionReturn
* @property {boolean} success - Did the function run successfully? * @property {boolean} success - Did the function run successfully?
@ -21,26 +15,24 @@ export = googleAuth;
* @param {object} params - main params object * @param {object} params - main params object
* @param {string} [params.key] - API full access key * @param {string} [params.key] - API full access key
* @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
* @param {http.ServerResponse} [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 {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 {boolean} [params.user_id] - User ID * @param {string | number} [params.apiUserID] - API user ID
* @param {string | number} [params.apiUserID] - Required for setting of cookies
* @param {boolean} [params.useLocal] - Whether to use a remote database instead of API * @param {boolean} [params.useLocal] - Whether to use a remote database instead of API
* *
* @returns { Promise<FunctionReturn> } * @returns { Promise<FunctionReturn> }
*/ */
declare function googleAuth({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, user_id, apiUserID, useLocal, }: { declare function googleAuth({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, apiUserID, useLocal, }: {
key?: string; key?: string;
token: string; token: string;
database: string; database?: string;
response?: http.ServerResponse; response?: http.ServerResponse;
encryptionKey?: string; encryptionKey?: string;
encryptionSalt?: string; encryptionSalt?: string;
additionalFields?: string[]; additionalFields?: string[];
user_id?: boolean;
apiUserID?: string | number; apiUserID?: string | number;
useLocal?: boolean; useLocal?: boolean;
}): Promise<FunctionReturn>; }): Promise<FunctionReturn>;

View File

@ -1,10 +1,5 @@
// @ts-check // @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const http = require("http"); const http = require("http");
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
@ -16,13 +11,6 @@ const {
writeAuthFile, writeAuthFile,
} = require("../../package-shared/functions/backend/auth/write-auth-files"); } = require("../../package-shared/functions/backend/auth/write-auth-files");
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** /**
* @typedef {object | null} FunctionReturn * @typedef {object | null} FunctionReturn
* @property {boolean} success - Did the function run successfully? * @property {boolean} success - Did the function run successfully?
@ -40,13 +28,12 @@ const {
* @param {object} params - main params object * @param {object} params - main params object
* @param {string} [params.key] - API full access key * @param {string} [params.key] - API full access key
* @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
* @param {http.ServerResponse} [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 {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 {boolean} [params.user_id] - User ID * @param {string | number} [params.apiUserID] - API user ID
* @param {string | number} [params.apiUserID] - Required for setting of cookies
* @param {boolean} [params.useLocal] - Whether to use a remote database instead of API * @param {boolean} [params.useLocal] - Whether to use a remote database instead of API
* *
* @returns { Promise<FunctionReturn> } * @returns { Promise<FunctionReturn> }
@ -59,7 +46,6 @@ async function googleAuth({
encryptionKey, encryptionKey,
encryptionSalt, encryptionSalt,
additionalFields, additionalFields,
user_id,
apiUserID, apiUserID,
useLocal, useLocal,
}) { }) {
@ -134,24 +120,11 @@ async function googleAuth({
DSQL_DB_NAME?.match(/./) && DSQL_DB_NAME?.match(/./) &&
useLocal useLocal
) { ) {
/** @type {import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined | undefined} */ httpResponse = await apiGoogleLogin({
let dbSchema; token,
additionalFields,
try { database: DSQL_DB_NAME,
const localDbSchemaPath = path.resolve( });
process.cwd(),
"dsql.schema.json"
);
dbSchema = JSON.parse(fs.readFileSync(localDbSchemaPath, "utf8"));
} catch (error) {}
if (dbSchema && apiUserID) {
httpResponse = await apiGoogleLogin({
token,
additionalFields,
database: DSQL_DB_NAME,
});
}
} else { } else {
/** /**
* Make https request * Make https request
@ -180,7 +153,7 @@ async function googleAuth({
port, port,
hostname: host, hostname: host,
path: `/api/user/${ path: `/api/user/${
user_id || grabedHostNames.user_id apiUserID || grabedHostNames.user_id
}/google-login`, }/google-login`,
}, },
@ -227,8 +200,6 @@ async function googleAuth({
userId: apiUserID || process.env.DSQL_API_USER_ID, userId: apiUserID || process.env.DSQL_API_USER_ID,
}); });
console.log("apiUserID", apiUserID);
if (httpResponse.csrf) { if (httpResponse.csrf) {
writeAuthFile( writeAuthFile(
httpResponse.csrf, httpResponse.csrf,