Updates
This commit is contained in:
@@ -22,8 +22,7 @@ export type ApiGetParams = Param;
|
||||
* # Make a get request to Datasquirel API
|
||||
*/
|
||||
export default async function get<
|
||||
T extends { [k: string]: any } = { [k: string]: any },
|
||||
R extends any = any
|
||||
T extends { [k: string]: any } = { [k: string]: any }
|
||||
>({
|
||||
key,
|
||||
database,
|
||||
@@ -32,7 +31,7 @@ export default async function get<
|
||||
debug,
|
||||
useLocal,
|
||||
apiVersion = "v1",
|
||||
}: Param<T>): Promise<APIResponseObject<R>> {
|
||||
}: Param<T>): Promise<APIResponseObject> {
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
|
||||
@@ -122,5 +121,5 @@ export default async function get<
|
||||
.end();
|
||||
});
|
||||
|
||||
return httpResponse as APIResponseObject<R>;
|
||||
return httpResponse as APIResponseObject;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ export default async function loginUser<
|
||||
secureCookie,
|
||||
useLocal,
|
||||
apiVersion = "v1",
|
||||
}: LoginUserParam): Promise<APIResponseObject<T | null>> {
|
||||
}: LoginUserParam): Promise<APIResponseObject> {
|
||||
const COOKIE_EXPIRY_DATE = grabCookieExpiryDate();
|
||||
|
||||
const defaultTempLoginFieldName = "temp_login_code";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ResetPasswordParams, UpdateUserFunctionReturn } from "../../types";
|
||||
import { APIResponseObject, ResetPasswordParams } from "../../types";
|
||||
import queryDSQLAPI from "../../functions/api/query-dsql-api";
|
||||
import grabUserDSQLAPIPath from "../../utils/backend/users/grab-api-path";
|
||||
import apiResetUserPassword from "../../functions/api/users/api-reset-user-password";
|
||||
@@ -8,7 +8,7 @@ import apiResetUserPassword from "../../functions/api/users/api-reset-user-passw
|
||||
*/
|
||||
export default async function resetPassword(
|
||||
params: ResetPasswordParams
|
||||
): Promise<UpdateUserFunctionReturn> {
|
||||
): Promise<APIResponseObject> {
|
||||
if (params.useLocal) {
|
||||
return await apiResetUserPassword(params);
|
||||
}
|
||||
@@ -25,5 +25,5 @@ export default async function resetPassword(
|
||||
method: "POST",
|
||||
});
|
||||
|
||||
return httpResponse as UpdateUserFunctionReturn;
|
||||
return httpResponse as APIResponseObject;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import apiUpdateUser from "../../functions/api/users/api-update-user";
|
||||
import {
|
||||
APIResponseObject,
|
||||
ApiUpdateUserParams,
|
||||
UpdateUserFunctionReturn,
|
||||
UpdateUserParams,
|
||||
@@ -23,7 +24,7 @@ export default async function updateUser<
|
||||
apiKey,
|
||||
apiVersion,
|
||||
dbUserId,
|
||||
}: UpdateUserParams<T>): Promise<UpdateUserFunctionReturn> {
|
||||
}: UpdateUserParams<T>): Promise<APIResponseObject> {
|
||||
const updateUserParams: ApiUpdateUserParams = {
|
||||
payload: payload,
|
||||
database,
|
||||
@@ -52,5 +53,5 @@ export default async function updateUser<
|
||||
method: "POST",
|
||||
});
|
||||
|
||||
return httpResponse as UpdateUserFunctionReturn;
|
||||
return httpResponse as APIResponseObject;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ export default async function <
|
||||
fieldName,
|
||||
apiConnectionConfig,
|
||||
grabbedHostnames,
|
||||
}: Params): Promise<APIResponseObject<T>> {
|
||||
}: Params): Promise<APIResponseObject> {
|
||||
const basePath = grabAPIBasePath({ paradigm: "schema" });
|
||||
|
||||
const finalPath = path.join(
|
||||
@@ -43,7 +43,7 @@ export default async function <
|
||||
fieldName || ""
|
||||
);
|
||||
|
||||
const GET_RES = await queryDSQLAPI<any, T>({
|
||||
const GET_RES = await queryDSQLAPI<T>({
|
||||
method: "GET",
|
||||
path: finalPath,
|
||||
apiKey,
|
||||
|
||||
@@ -30,10 +30,7 @@ type Param<T = { [k: string]: any }> = {
|
||||
/**
|
||||
* # Query DSQL API
|
||||
*/
|
||||
export default async function queryDSQLAPI<
|
||||
T = { [k: string]: any },
|
||||
P = { [k: string]: any }
|
||||
>({
|
||||
export default async function queryDSQLAPI<T = { [k: string]: any }>({
|
||||
body,
|
||||
query,
|
||||
useDefault,
|
||||
@@ -42,7 +39,7 @@ export default async function queryDSQLAPI<
|
||||
apiKey,
|
||||
apiConnectionConfig,
|
||||
grabbedHostnames,
|
||||
}: Param<T>): Promise<APIResponseObject<P>> {
|
||||
}: Param<T>): Promise<APIResponseObject> {
|
||||
const grabedHostNames =
|
||||
grabbedHostnames || grabHostNames({ useDefault, apiConnectionConfig });
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
@@ -168,7 +165,7 @@ export default async function queryDSQLAPI<
|
||||
httpsRequest.end();
|
||||
});
|
||||
|
||||
return httpResponse as APIResponseObject<P>;
|
||||
return httpResponse as APIResponseObject;
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
|
||||
@@ -152,8 +152,8 @@ export default async function handleSocialDb({
|
||||
},
|
||||
});
|
||||
|
||||
if (newUser?.payload?.insertId) {
|
||||
const newUserQueriedQuery = `SELECT * FROM users WHERE id='${newUser.payload.insertId}'`;
|
||||
if (newUser?.postInsertReturn?.insertId) {
|
||||
const newUserQueriedQuery = `SELECT * FROM users WHERE id='${newUser.postInsertReturn.insertId}'`;
|
||||
|
||||
const newUserQueried = (await dbHandler({
|
||||
database: finalDbName,
|
||||
@@ -175,7 +175,7 @@ export default async function handleSocialDb({
|
||||
*/
|
||||
let generatedToken = encrypt({
|
||||
data: JSON.stringify({
|
||||
id: newUser.payload.insertId,
|
||||
id: newUser.postInsertReturn.insertId,
|
||||
email: supEmail,
|
||||
dateCode: Date.now(),
|
||||
}),
|
||||
|
||||
@@ -163,8 +163,8 @@ export default async function apiCreateUser({
|
||||
},
|
||||
});
|
||||
|
||||
if (addUser?.payload?.insertId) {
|
||||
const newlyAddedUserQuery = `SELECT id,uuid,first_name,last_name,email,username,image,image_thumbnail,verification_status FROM ${dbFullName}.users WHERE id='${addUser.payload.insertId}'`;
|
||||
if (addUser?.postInsertReturn?.insertId) {
|
||||
const newlyAddedUserQuery = `SELECT id,uuid,first_name,last_name,email,username,image,image_thumbnail,verification_status FROM ${dbFullName}.users WHERE id='${addUser.postInsertReturn.insertId}'`;
|
||||
|
||||
const newlyAddedUser = (await dbHandler({
|
||||
query: newlyAddedUserQuery,
|
||||
|
||||
@@ -184,7 +184,7 @@ export default async function apiLoginUser({
|
||||
const resposeObject: APIResponseObject = {
|
||||
success: true,
|
||||
msg: "Login Successful",
|
||||
payload: userPayload,
|
||||
singleRes: userPayload,
|
||||
userId: foundUser[0].id,
|
||||
csrf: csrfKey,
|
||||
};
|
||||
|
||||
@@ -48,6 +48,6 @@ export default async function apiResetUserPassword({
|
||||
|
||||
return {
|
||||
success: true,
|
||||
payload: updateUser,
|
||||
singleRes: updateUser,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -81,6 +81,6 @@ export default async function apiUpdateUser({
|
||||
|
||||
return {
|
||||
success: true,
|
||||
payload: updateUser,
|
||||
singleRes: updateUser,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import handleSocialDb from "../../social-login/handleSocialDb";
|
||||
import githubLogin from "../../social-login/githubLogin";
|
||||
import camelJoinedtoCamelSpace from "../../../../utils/camelJoinedtoCamelSpace";
|
||||
import { APILoginFunctionReturn } from "../../../../types";
|
||||
import { APILoginFunctionReturn, APIResponseObject } from "../../../../types";
|
||||
|
||||
type Param = {
|
||||
code?: string;
|
||||
@@ -24,7 +24,7 @@ export default async function apiGithubLogin({
|
||||
additionalFields,
|
||||
email,
|
||||
additionalData,
|
||||
}: Param): Promise<APILoginFunctionReturn> {
|
||||
}: Param): Promise<APIResponseObject> {
|
||||
if (!code || !clientId || !clientSecret || !database) {
|
||||
return {
|
||||
success: false,
|
||||
|
||||
@@ -42,7 +42,7 @@ export default function postLoginResponseHandler({
|
||||
|
||||
if (httpResponse?.success) {
|
||||
let encryptedPayload = encrypt({
|
||||
data: JSON.stringify(httpResponse.payload),
|
||||
data: JSON.stringify(httpResponse.singleRes),
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
});
|
||||
@@ -61,9 +61,9 @@ export default function postLoginResponseHandler({
|
||||
if (httpResponse.csrf && !skipWriteAuthFile) {
|
||||
writeAuthFile(
|
||||
httpResponse.csrf,
|
||||
JSON.stringify(httpResponse.payload),
|
||||
cleanupTokens && httpResponse.payload?.id
|
||||
? { userId: httpResponse.payload.id }
|
||||
JSON.stringify(httpResponse.singleRes),
|
||||
cleanupTokens && httpResponse.singleRes?.id
|
||||
? { userId: httpResponse.singleRes.id }
|
||||
: undefined
|
||||
);
|
||||
}
|
||||
@@ -84,7 +84,7 @@ export default function postLoginResponseHandler({
|
||||
`${authKeyName}=${encryptedPayload};samesite=strict;path=/;HttpOnly=true;Expires=${COOKIE_EXPIRY_DATE}${
|
||||
secureCookie ? ";Secure=true" : ""
|
||||
}`,
|
||||
`${csrfName}=${httpResponse.payload?.csrf_k};samesite=strict;path=/;HttpOnly=true;Expires=${COOKIE_EXPIRY_DATE}`,
|
||||
`${csrfName}=${httpResponse.singleRes?.csrf_k};samesite=strict;path=/;HttpOnly=true;Expires=${COOKIE_EXPIRY_DATE}`,
|
||||
]);
|
||||
|
||||
if (debug) {
|
||||
|
||||
@@ -43,7 +43,7 @@ export default async function suAddBackup({
|
||||
data: newBackup,
|
||||
});
|
||||
|
||||
if (!newBackupEntry?.payload?.insertId) {
|
||||
if (!newBackupEntry?.postInsertReturn?.insertId) {
|
||||
return {
|
||||
success: false,
|
||||
msg: `Couldn't create new backup entry`,
|
||||
@@ -53,7 +53,7 @@ export default async function suAddBackup({
|
||||
const { single: newlyAddedBackup } =
|
||||
await dbGrabUserResource<DSQL_DATASQUIREL_BACKUPS>({
|
||||
tableName: "backups",
|
||||
targetID: newBackupEntry.payload?.insertId,
|
||||
targetID: newBackupEntry.postInsertReturn?.insertId,
|
||||
isSuperUser: true,
|
||||
});
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ export default async function deleteDbEntry<
|
||||
*/
|
||||
return {
|
||||
success: Boolean(deletedEntry.affectedRows),
|
||||
payload: deletedEntry,
|
||||
postInsertReturn: deletedEntry,
|
||||
queryObject: {
|
||||
sql: format(query),
|
||||
params: values,
|
||||
|
||||
@@ -161,7 +161,7 @@ export default async function updateDbEntry<
|
||||
*/
|
||||
return {
|
||||
success: Boolean(updatedEntry?.affectedRows),
|
||||
payload: updatedEntry,
|
||||
postInsertReturn: updatedEntry,
|
||||
queryObject: {
|
||||
sql: format(query),
|
||||
params: updateValues,
|
||||
|
||||
@@ -78,7 +78,9 @@ export default async function handleMariadbUserRecord({
|
||||
query: {
|
||||
id: {
|
||||
value: String(
|
||||
existingRecord?.id || record?.payload?.insertId || 0
|
||||
existingRecord?.id ||
|
||||
record?.postInsertReturn?.insertId ||
|
||||
0
|
||||
),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -64,7 +64,7 @@ export default async function checkDbRecordCreateDbSchema({
|
||||
forceLocal: true,
|
||||
});
|
||||
|
||||
if (newDbEntry.payload?.insertId) {
|
||||
if (newDbEntry.postInsertReturn?.insertId) {
|
||||
recordedDbEntryArray = (await dbHandler({
|
||||
query: `SELECT * FROM datasquirel.user_databases WHERE db_full_name = ?`,
|
||||
values: [dbFullName || "NULL"],
|
||||
|
||||
@@ -97,7 +97,7 @@ export default async function checkTableRecordCreateDbSchema({
|
||||
forceLocal: true,
|
||||
});
|
||||
|
||||
if (newTableRecordEntry.payload?.insertId) {
|
||||
if (newTableRecordEntry.postInsertReturn?.insertId) {
|
||||
recordedTableEntryArray = (await dbHandler({
|
||||
query: queryObj?.string || "",
|
||||
values: queryObj?.values,
|
||||
|
||||
@@ -77,7 +77,7 @@ async function createUser() {
|
||||
data: { ...userObj, password: hashedPassword },
|
||||
});
|
||||
|
||||
if (!newUser?.payload?.insertId) return false;
|
||||
if (!newUser?.postInsertReturn?.insertId) return false;
|
||||
|
||||
const { STATIC_ROOT } = grabDirNames();
|
||||
|
||||
@@ -91,10 +91,10 @@ async function createUser() {
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/
|
||||
let newUserSchemaFolderPath = `${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${newUser.payload.insertId}`;
|
||||
let newUserSchemaFolderPath = `${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${newUser.postInsertReturn.insertId}`;
|
||||
let newUserMediaFolderPath = path.join(
|
||||
STATIC_ROOT,
|
||||
`images/user-images/user-${newUser.payload.insertId}`
|
||||
`images/user-images/user-${newUser.postInsertReturn.insertId}`
|
||||
);
|
||||
|
||||
fs.mkdirSync(newUserSchemaFolderPath, { recursive: true });
|
||||
@@ -108,7 +108,7 @@ async function createUser() {
|
||||
|
||||
const imageBasePath = path.join(
|
||||
STATIC_ROOT,
|
||||
`images/user-images/user-${newUser.payload.insertId}`
|
||||
`images/user-images/user-${newUser.postInsertReturn.insertId}`
|
||||
);
|
||||
|
||||
if (!fs.existsSync(imageBasePath)) {
|
||||
@@ -117,12 +117,12 @@ async function createUser() {
|
||||
|
||||
let imagePath = path.join(
|
||||
STATIC_ROOT,
|
||||
`images/user-images/user-${newUser.payload.insertId}/user-${newUser.payload.insertId}-profile.jpg`
|
||||
`images/user-images/user-${newUser.postInsertReturn.insertId}/user-${newUser.postInsertReturn.insertId}-profile.jpg`
|
||||
);
|
||||
|
||||
let imageThumbnailPath = path.join(
|
||||
STATIC_ROOT,
|
||||
`images/user-images/user-${newUser.payload.insertId}/user-${newUser.payload.insertId}-profile-thumbnail.jpg`
|
||||
`images/user-images/user-${newUser.postInsertReturn.insertId}/user-${newUser.postInsertReturn.insertId}-profile-thumbnail.jpg`
|
||||
);
|
||||
|
||||
let prodImageUrl = imagePath.replace(
|
||||
@@ -149,7 +149,7 @@ async function createUser() {
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "users",
|
||||
identifierColumnName: "id",
|
||||
identifierValue: newUser.payload.insertId,
|
||||
identifierValue: newUser.postInsertReturn.insertId,
|
||||
data: {
|
||||
image: prodImageUrl,
|
||||
image_thumbnail: prodImageThumbnailUrl,
|
||||
|
||||
@@ -97,8 +97,8 @@ export default async function ({
|
||||
dbFullName: targetDatabase,
|
||||
});
|
||||
|
||||
if (newTableEntryRes?.payload?.insertId) {
|
||||
tableId = newTableEntryRes.payload.insertId;
|
||||
if (newTableEntryRes?.postInsertReturn?.insertId) {
|
||||
tableId = newTableEntryRes.postInsertReturn.insertId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1681,9 +1681,13 @@ export type ResponseQueryObject = {
|
||||
params?: (string | number)[];
|
||||
};
|
||||
|
||||
export type APIResponseObject<T extends any = any> = {
|
||||
export type APIResponseObject<
|
||||
T extends { [k: string]: any } = { [k: string]: any }
|
||||
> = {
|
||||
success: boolean;
|
||||
payload?: T;
|
||||
payload?: T[] | null;
|
||||
singleRes?: T | null;
|
||||
postInsertReturn?: PostInsertReturn | null;
|
||||
payloadBase64?: string;
|
||||
payloadThumbnailBase64?: string;
|
||||
payloadURL?: string;
|
||||
|
||||
@@ -127,7 +127,7 @@ export default async function dsqlCrud<
|
||||
|
||||
return {
|
||||
success: Boolean(res.affectedRows),
|
||||
payload: res,
|
||||
postInsertReturn: res,
|
||||
queryObject: {
|
||||
sql: format(deleteQuery?.query || ""),
|
||||
params: deleteQuery?.values || [],
|
||||
|
||||
Reference in New Issue
Block a user