This commit is contained in:
Benjamin Toby 2024-12-28 08:03:57 +01:00
parent d2ff524d86
commit e7fafc1bb6
10 changed files with 41 additions and 46 deletions

View File

@ -1,11 +1,12 @@
declare function _exports({ code, clientId, clientSecret, database, additionalFields, res, email, userId, }: { declare function _exports({ code, clientId, clientSecret, database, additionalFields, email, additionalData, }: {
code?: string; code?: string;
clientId?: string; clientId?: string;
clientSecret?: string; clientSecret?: string;
database?: string; database?: string;
additionalFields?: string[]; additionalFields?: string[];
res?: any; additionalData?: {
[x: string]: string | number;
};
email?: string; email?: string;
userId?: string | number;
}): Promise<import("../../../../types").APILoginFunctionReturn>; }): Promise<import("../../../../types").APILoginFunctionReturn>;
export = _exports; export = _exports;

View File

@ -12,9 +12,8 @@ const camelJoinedtoCamelSpace = require("../../../../utils/camelJoinedtoCamelSpa
* @param {string} [param.clientSecret] * @param {string} [param.clientSecret]
* @param {string} [param.database] * @param {string} [param.database]
* @param {string[]} [param.additionalFields] * @param {string[]} [param.additionalFields]
* @param {any} [param.res] * @param {Object<string,string|number>} [param.additionalData]
* @param {string} [param.email] * @param {string} [param.email]
* @param {string | number} [param.userId]
* *
* @returns {Promise<import("../../../../types").APILoginFunctionReturn>} * @returns {Promise<import("../../../../types").APILoginFunctionReturn>}
*/ */
@ -24,9 +23,8 @@ module.exports = async function apiGithubLogin({
clientSecret, clientSecret,
database, database,
additionalFields, additionalFields,
res,
email, email,
userId, additionalData,
}) { }) {
if (!code || !clientId || !clientSecret || !database) { if (!code || !clientId || !clientSecret || !database) {
return { return {
@ -73,7 +71,7 @@ module.exports = async function apiGithubLogin({
? targetName?.split("-") ? targetName?.split("-")
: [targetName]; : [targetName];
const payload = { let payload = {
email: gitHubUser.email, email: gitHubUser.email,
first_name: camelJoinedtoCamelSpace(nameArray[0]), first_name: camelJoinedtoCamelSpace(nameArray[0]),
last_name: camelJoinedtoCamelSpace(nameArray[1]), last_name: camelJoinedtoCamelSpace(nameArray[1]),
@ -84,10 +82,14 @@ module.exports = async function apiGithubLogin({
username: "github-user-" + socialId, username: "github-user-" + socialId,
}; };
if (additionalData) {
payload = { ...payload, ...additionalData };
}
const loggedInGithubUser = await handleSocialDb({ const loggedInGithubUser = await handleSocialDb({
database, database,
email: gitHubUser.email, email: gitHubUser.email,
payload: payload, payload,
social_platform: "github", social_platform: "github",
social_id: socialId, social_id: socialId,
supEmail: email, supEmail: email,

View File

@ -9,6 +9,7 @@ module.exports = async function apiGoogleLogin({
token, token,
database, database,
additionalFields, additionalFields,
additionalData,
}) { }) {
try { try {
/** @type {import("../../../../types").GoogleOauth2User | undefined} */ /** @type {import("../../../../types").GoogleOauth2User | undefined} */
@ -59,7 +60,7 @@ module.exports = async function apiGoogleLogin({
const { given_name, family_name, email, sub, picture } = gUser; const { given_name, family_name, email, sub, picture } = gUser;
/** @type {Object<string, any>} */ /** @type {Object<string, any>} */
const payloadObject = { let payloadObject = {
email: email, email: email,
first_name: given_name, first_name: given_name,
last_name: family_name, last_name: family_name,
@ -70,6 +71,10 @@ module.exports = async function apiGoogleLogin({
username: `google-user-${sub}`, username: `google-user-${sub}`,
}; };
if (additionalData) {
payloadObject = { ...payloadObject, ...additionalData };
}
const loggedInGoogleUser = await handleSocialDb({ const loggedInGoogleUser = await handleSocialDb({
database, database,
email: email || "", email: email || "",

View File

@ -1057,6 +1057,9 @@ export type APIGoogleLoginFunctionParams = {
token: string; token: string;
database: string; database: string;
additionalFields?: string[]; additionalFields?: string[];
additionalData?: {
[key: string]: string | number;
};
}; };
export type APIGoogleLoginFunction = (params: APIGoogleLoginFunctionParams) => Promise<APILoginFunctionReturn>; export type APIGoogleLoginFunction = (params: APIGoogleLoginFunctionParams) => Promise<APILoginFunctionReturn>;
/** /**

View File

@ -1265,6 +1265,7 @@ export type APIGoogleLoginFunctionParams = {
token: string; token: string;
database: string; database: string;
additionalFields?: string[]; additionalFields?: string[];
additionalData?: { [key: string]: string | number };
}; };
export type APIGoogleLoginFunction = ( export type APIGoogleLoginFunction = (

View File

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

View File

@ -29,11 +29,12 @@ export = githubAuth;
* @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 {Object<string,string|number>} [params.additionalData] - Additional Data to by added on creation of User
* @param {boolean} [params.user_id] - User ID * @param {boolean} [params.user_id] - User ID
* *
* @returns { Promise<FunctionReturn | undefined> } * @returns { Promise<FunctionReturn | undefined> }
*/ */
declare function githubAuth({ key, code, email, database, clientId, clientSecret, response, encryptionKey, encryptionSalt, additionalFields, user_id, }: { declare function githubAuth({ key, code, email, database, clientId, clientSecret, response, encryptionKey, encryptionSalt, additionalFields, user_id, additionalData, }: {
key: string; key: string;
code: string; code: string;
email: string | null; email: string | null;
@ -44,6 +45,9 @@ declare function githubAuth({ key, code, email, database, clientId, clientSecret
encryptionKey: string; encryptionKey: string;
encryptionSalt: string; encryptionSalt: string;
additionalFields?: string[]; additionalFields?: string[];
additionalData?: {
[x: string]: string | number;
};
user_id?: boolean; user_id?: boolean;
}): Promise<FunctionReturn | undefined>; }): Promise<FunctionReturn | undefined>;
declare namespace githubAuth { declare namespace githubAuth {

View File

@ -45,6 +45,7 @@ const apiGithubLogin = require("../../package-shared/functions/api/users/social/
* @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 {Object<string,string|number>} [params.additionalData] - Additional Data to by added on creation of User
* @param {boolean} [params.user_id] - User ID * @param {boolean} [params.user_id] - User ID
* *
* @returns { Promise<FunctionReturn | undefined> } * @returns { Promise<FunctionReturn | undefined> }
@ -61,6 +62,7 @@ async function githubAuth({
encryptionSalt, encryptionSalt,
additionalFields, additionalFields,
user_id, user_id,
additionalData,
}) { }) {
/** /**
* Check inputs * Check inputs
@ -70,14 +72,6 @@ async function githubAuth({
const grabedHostNames = grabHostNames(); const grabedHostNames = grabHostNames();
const { host, port, scheme } = grabedHostNames; const { host, port, scheme } = grabedHostNames;
if (!key || key?.match(/ /)) {
return {
success: false,
user: null,
msg: "Please enter API full access Key",
};
}
if (!code || code?.match(/ /)) { if (!code || code?.match(/ /)) {
return { return {
success: false, success: false,
@ -102,30 +96,6 @@ async function githubAuth({
}; };
} }
if (!response || !response?.setHeader) {
return {
success: false,
user: null,
msg: "Please provide a valid HTTPS response object",
};
}
if (!encryptionKey || encryptionKey?.match(/ /)) {
return {
success: false,
user: null,
msg: "Please provide a valid encryption key",
};
}
if (!encryptionSalt || encryptionSalt?.match(/ /)) {
return {
success: false,
user: null,
msg: "Please provide a valid encryption salt",
};
}
//////////////////////////////////////// ////////////////////////////////////////
//////////////////////////////////////// ////////////////////////////////////////
//////////////////////////////////////// ////////////////////////////////////////
@ -173,8 +143,8 @@ async function githubAuth({
clientId, clientId,
clientSecret, clientSecret,
additionalFields, additionalFields,
res: response,
database: DSQL_DB_NAME, database: DSQL_DB_NAME,
additionalData,
}); });
} else { } else {
/** /**
@ -191,6 +161,7 @@ async function githubAuth({
clientSecret, clientSecret,
database, database,
additionalFields, additionalFields,
additionalData,
}); });
const httpsRequest = scheme.request( const httpsRequest = scheme.request(

View File

@ -13,12 +13,13 @@ export = googleAuth;
* @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 {Object<string,string|number>} [params.additionalData] - Additional Data to by added on creation of User
* @param {string | number} [params.apiUserID] - API user ID * @param {string | number} [params.apiUserID] - API user ID
* @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<import("../../package-shared/types").APILoginFunctionReturn> } * @returns { Promise<import("../../package-shared/types").APILoginFunctionReturn> }
*/ */
declare function googleAuth({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, apiUserID, useLocal, }: { declare function googleAuth({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, useLocal, }: {
key?: string; key?: string;
token: string; token: string;
database?: string; database?: string;
@ -26,6 +27,9 @@ declare function googleAuth({ key, token, database, response, encryptionKey, enc
encryptionKey?: string; encryptionKey?: string;
encryptionSalt?: string; encryptionSalt?: string;
additionalFields?: string[]; additionalFields?: string[];
additionalData?: {
[x: string]: string | number;
};
apiUserID?: string | number; apiUserID?: string | number;
useLocal?: boolean; useLocal?: boolean;
}): Promise<import("../../package-shared/types").APILoginFunctionReturn>; }): Promise<import("../../package-shared/types").APILoginFunctionReturn>;

View File

@ -23,6 +23,7 @@ const {
* @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 {Object<string,string|number>} [params.additionalData] - Additional Data to by added on creation of User
* @param {string | number} [params.apiUserID] - API user ID * @param {string | number} [params.apiUserID] - API user ID
* @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
* *
@ -36,6 +37,7 @@ async function googleAuth({
encryptionKey, encryptionKey,
encryptionSalt, encryptionSalt,
additionalFields, additionalFields,
additionalData,
apiUserID, apiUserID,
useLocal, useLocal,
}) { }) {
@ -106,6 +108,7 @@ async function googleAuth({
token, token,
additionalFields, additionalFields,
database: DSQL_DB_NAME, database: DSQL_DB_NAME,
additionalData,
}); });
} else { } else {
/** /**
@ -119,6 +122,7 @@ async function googleAuth({
token, token,
database, database,
additionalFields, additionalFields,
additionalData,
}); });
const httpsRequest = scheme.request( const httpsRequest = scheme.request(