Updates
This commit is contained in:
parent
98aaa94b80
commit
b02399c64d
6
dist/index.d.ts
vendored
6
dist/index.d.ts
vendored
@ -73,12 +73,12 @@ declare const datasquirel: {
|
||||
post: typeof post;
|
||||
user: {
|
||||
auth: {
|
||||
login: (_: import("./package-shared/types").LoginUserParam) => Promise<import("./package-shared/types").APIResponseObject<import("./package-shared/types").DATASQUIREL_LoggedInUser | null>>;
|
||||
login: (_: import("./package-shared/types").LoginUserParam) => Promise<import("./package-shared/types").APIResponseObject>;
|
||||
get: (_: import("./package-shared/types").GetUserParams) => Promise<import("./package-shared/types").GetUserFunctionReturn>;
|
||||
signup: (_: import("./package-shared/types").AddUserParams) => Promise<import("./package-shared/types").APIResponseObject>;
|
||||
sendEmailCode: (_: import("./package-shared/types").SendEmailCodeParams) => Promise<import("./package-shared/types").APIResponseObject>;
|
||||
update: (_: import("./package-shared/types").UpdateUserParams) => Promise<import("./package-shared/types").UpdateUserFunctionReturn>;
|
||||
resetPassword: (_: import("./package-shared/types").ResetPasswordParams) => Promise<import("./package-shared/types").UpdateUserFunctionReturn>;
|
||||
update: (_: import("./package-shared/types").UpdateUserParams) => Promise<import("./package-shared/types").APIResponseObject>;
|
||||
resetPassword: (_: import("./package-shared/types").ResetPasswordParams) => Promise<import("./package-shared/types").APIResponseObject>;
|
||||
googleLogin: (_: import("./package-shared/types").GoogleAuthParams) => Promise<import("./package-shared/types").APIResponseObject>;
|
||||
logout: typeof import("./package-shared/actions/users/logout-user").default;
|
||||
auth: typeof import("./package-shared/actions/users/user-auth").default;
|
||||
|
||||
2
dist/package-shared/actions/get.d.ts
vendored
2
dist/package-shared/actions/get.d.ts
vendored
@ -20,5 +20,5 @@ export default function get<T extends {
|
||||
[k: string]: any;
|
||||
} = {
|
||||
[k: string]: any;
|
||||
}, R extends any = any>({ key, database, query, table, debug, useLocal, apiVersion, }: Param<T>): Promise<APIResponseObject<R>>;
|
||||
}>({ key, database, query, table, debug, useLocal, apiVersion, }: Param<T>): Promise<APIResponseObject>;
|
||||
export {};
|
||||
|
||||
@ -2,4 +2,4 @@ import { APIResponseObject, DATASQUIREL_LoggedInUser, LoginUserParam } from "../
|
||||
/**
|
||||
* # Login A user
|
||||
*/
|
||||
export default function loginUser<T extends DATASQUIREL_LoggedInUser = DATASQUIREL_LoggedInUser>({ apiKey, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, skipPassword, apiUserID, skipWriteAuthFile, dbUserId, debug, cleanupTokens, secureCookie, useLocal, apiVersion, }: LoginUserParam): Promise<APIResponseObject<T | null>>;
|
||||
export default function loginUser<T extends DATASQUIREL_LoggedInUser = DATASQUIREL_LoggedInUser>({ apiKey, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, skipPassword, apiUserID, skipWriteAuthFile, dbUserId, debug, cleanupTokens, secureCookie, useLocal, apiVersion, }: LoginUserParam): Promise<APIResponseObject>;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { ResetPasswordParams, UpdateUserFunctionReturn } from "../../types";
|
||||
import { APIResponseObject, ResetPasswordParams } from "../../types";
|
||||
/**
|
||||
* # Reset User Password
|
||||
*/
|
||||
export default function resetPassword(params: ResetPasswordParams): Promise<UpdateUserFunctionReturn>;
|
||||
export default function resetPassword(params: ResetPasswordParams): Promise<APIResponseObject>;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { UpdateUserFunctionReturn, UpdateUserParams } from "../../types";
|
||||
import { APIResponseObject, UpdateUserParams } from "../../types";
|
||||
import { DSQL_DATASQUIREL_USERS } from "../../types/dsql";
|
||||
/**
|
||||
* # Update User
|
||||
*/
|
||||
export default function updateUser<T extends DSQL_DATASQUIREL_USERS = DSQL_DATASQUIREL_USERS & {
|
||||
[k: string]: any;
|
||||
}>({ payload, database, updatedUserId, useLocal, apiKey, apiVersion, dbUserId, }: UpdateUserParams<T>): Promise<UpdateUserFunctionReturn>;
|
||||
}>({ payload, database, updatedUserId, useLocal, apiKey, apiVersion, dbUserId, }: UpdateUserParams<T>): Promise<APIResponseObject>;
|
||||
|
||||
4
dist/package-shared/api/crud/delete.d.ts
vendored
4
dist/package-shared/api/crud/delete.d.ts
vendored
@ -20,7 +20,5 @@ export default function apiCrudDELETE<T extends {
|
||||
[key: string]: any;
|
||||
} = {
|
||||
[key: string]: any;
|
||||
}>({ dbName, tableName, deleteSpec, targetID, apiKey, useDefault }: Params<T>): Promise<import("../../types").APIResponseObject<{
|
||||
[k: string]: any;
|
||||
}>>;
|
||||
}>({ dbName, tableName, deleteSpec, targetID, apiKey, useDefault }: Params<T>): Promise<import("../../types").APIResponseObject>;
|
||||
export {};
|
||||
|
||||
2
dist/package-shared/api/schema/get.d.ts
vendored
2
dist/package-shared/api/schema/get.d.ts
vendored
@ -9,5 +9,5 @@ type Params = {
|
||||
grabbedHostnames?: GrabHostNamesReturn;
|
||||
useDefault?: boolean;
|
||||
};
|
||||
export default function <T extends DSQL_DatabaseSchemaType | DSQL_TableSchemaType | DSQL_FieldSchemaType = DSQL_DatabaseSchemaType>({ dbName, tableName, apiKey, useDefault, fieldName, apiConnectionConfig, grabbedHostnames, }: Params): Promise<APIResponseObject<T>>;
|
||||
export default function <T extends DSQL_DatabaseSchemaType | DSQL_TableSchemaType | DSQL_FieldSchemaType = DSQL_DatabaseSchemaType>({ dbName, tableName, apiKey, useDefault, fieldName, apiConnectionConfig, grabbedHostnames, }: Params): Promise<APIResponseObject>;
|
||||
export {};
|
||||
|
||||
6
dist/package-shared/api/user/local-user.d.ts
vendored
6
dist/package-shared/api/user/local-user.d.ts
vendored
@ -4,12 +4,12 @@ import validateTempEmailCode from "../../actions/users/validate-temp-email-code"
|
||||
import { AddUserParams, GetUserParams, GoogleAuthParams, LoginUserParam, ResetPasswordParams, SendEmailCodeParams, UpdateUserParams } from "../../types";
|
||||
declare const localUser: {
|
||||
auth: {
|
||||
login: (_: LoginUserParam) => Promise<import("../../types").APIResponseObject<import("../../types").DATASQUIREL_LoggedInUser | null>>;
|
||||
login: (_: LoginUserParam) => Promise<import("../../types").APIResponseObject>;
|
||||
get: (_: GetUserParams) => Promise<import("../../types").GetUserFunctionReturn>;
|
||||
signup: (_: AddUserParams) => Promise<import("../../types").APIResponseObject>;
|
||||
sendEmailCode: (_: SendEmailCodeParams) => Promise<import("../../types").APIResponseObject>;
|
||||
update: (_: UpdateUserParams) => Promise<import("../../types").UpdateUserFunctionReturn>;
|
||||
resetPassword: (_: ResetPasswordParams) => Promise<import("../../types").UpdateUserFunctionReturn>;
|
||||
update: (_: UpdateUserParams) => Promise<import("../../types").APIResponseObject>;
|
||||
resetPassword: (_: ResetPasswordParams) => Promise<import("../../types").APIResponseObject>;
|
||||
googleLogin: (_: GoogleAuthParams) => Promise<import("../../types").APIResponseObject>;
|
||||
logout: typeof logoutUser;
|
||||
auth: typeof userAuth;
|
||||
|
||||
@ -17,7 +17,5 @@ type Param<T = {
|
||||
*/
|
||||
export default function queryDSQLAPI<T = {
|
||||
[k: string]: any;
|
||||
}, P = {
|
||||
[k: string]: any;
|
||||
}>({ body, query, useDefault, path: passedPath, method, apiKey, apiConnectionConfig, grabbedHostnames, }: Param<T>): Promise<APIResponseObject<P>>;
|
||||
}>({ body, query, useDefault, path: passedPath, method, apiKey, apiConnectionConfig, grabbedHostnames, }: Param<T>): Promise<APIResponseObject>;
|
||||
export {};
|
||||
|
||||
@ -121,8 +121,8 @@ function handleSocialDb(_a) {
|
||||
duplicateColumnValue: finalEmail,
|
||||
data: Object.assign(Object.assign({}, data), { email: finalEmail }),
|
||||
});
|
||||
if ((_b = newUser === null || newUser === void 0 ? void 0 : newUser.payload) === null || _b === void 0 ? void 0 : _b.insertId) {
|
||||
const newUserQueriedQuery = `SELECT * FROM users WHERE id='${newUser.payload.insertId}'`;
|
||||
if ((_b = newUser === null || newUser === void 0 ? void 0 : newUser.postInsertReturn) === null || _b === void 0 ? void 0 : _b.insertId) {
|
||||
const newUserQueriedQuery = `SELECT * FROM users WHERE id='${newUser.postInsertReturn.insertId}'`;
|
||||
const newUserQueried = (yield (0, dbHandler_1.default)({
|
||||
database: finalDbName,
|
||||
query: newUserQueriedQuery,
|
||||
@ -141,7 +141,7 @@ function handleSocialDb(_a) {
|
||||
*/
|
||||
let generatedToken = (0, encrypt_1.default)({
|
||||
data: JSON.stringify({
|
||||
id: newUser.payload.insertId,
|
||||
id: newUser.postInsertReturn.insertId,
|
||||
email: supEmail,
|
||||
dateCode: Date.now(),
|
||||
}),
|
||||
|
||||
@ -138,8 +138,8 @@ function apiCreateUser(_a) {
|
||||
"/images/user-preset.png", image_thumbnail: process.env.DSQL_DEFAULT_USER_IMAGE ||
|
||||
"/images/user-preset-thumbnail.png", verification_status: verify ? 1 : 0 }),
|
||||
});
|
||||
if ((_b = addUser === null || addUser === void 0 ? void 0 : addUser.payload) === null || _b === void 0 ? void 0 : _b.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 ((_b = addUser === null || addUser === void 0 ? void 0 : addUser.postInsertReturn) === null || _b === void 0 ? void 0 : _b.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 = (yield (0, dbHandler_1.default)({
|
||||
query: newlyAddedUserQuery,
|
||||
values: [],
|
||||
|
||||
@ -153,7 +153,7 @@ function apiLoginUser(_a) {
|
||||
const resposeObject = {
|
||||
success: true,
|
||||
msg: "Login Successful",
|
||||
payload: userPayload,
|
||||
singleRes: userPayload,
|
||||
userId: foundUser[0].id,
|
||||
csrf: csrfKey,
|
||||
};
|
||||
|
||||
@ -49,7 +49,7 @@ function apiResetUserPassword(_a) {
|
||||
});
|
||||
return {
|
||||
success: true,
|
||||
payload: updateUser,
|
||||
singleRes: updateUser,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ function apiUpdateUser(_a) {
|
||||
});
|
||||
return {
|
||||
success: true,
|
||||
payload: updateUser,
|
||||
singleRes: updateUser,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { APILoginFunctionReturn } from "../../../../types";
|
||||
import { APIResponseObject } from "../../../../types";
|
||||
type Param = {
|
||||
code?: string;
|
||||
clientId?: string;
|
||||
@ -13,5 +13,5 @@ type Param = {
|
||||
/**
|
||||
* # API Login with Github
|
||||
*/
|
||||
export default function apiGithubLogin({ code, clientId, clientSecret, database, additionalFields, email, additionalData, }: Param): Promise<APILoginFunctionReturn>;
|
||||
export default function apiGithubLogin({ code, clientId, clientSecret, database, additionalFields, email, additionalData, }: Param): Promise<APIResponseObject>;
|
||||
export {};
|
||||
|
||||
@ -20,7 +20,7 @@ function postLoginResponseHandler({ database, httpResponse, response, encryption
|
||||
const COOKIE_EXPIRY_DATE = (0, grab_cookie_expirt_date_1.default)();
|
||||
if (httpResponse === null || httpResponse === void 0 ? void 0 : httpResponse.success) {
|
||||
let encryptedPayload = (0, encrypt_1.default)({
|
||||
data: JSON.stringify(httpResponse.payload),
|
||||
data: JSON.stringify(httpResponse.singleRes),
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
});
|
||||
@ -35,8 +35,8 @@ function postLoginResponseHandler({ database, httpResponse, response, encryption
|
||||
database,
|
||||
});
|
||||
if (httpResponse.csrf && !skipWriteAuthFile) {
|
||||
(0, write_auth_files_1.writeAuthFile)(httpResponse.csrf, JSON.stringify(httpResponse.payload), cleanupTokens && ((_a = httpResponse.payload) === null || _a === void 0 ? void 0 : _a.id)
|
||||
? { userId: httpResponse.payload.id }
|
||||
(0, write_auth_files_1.writeAuthFile)(httpResponse.csrf, JSON.stringify(httpResponse.singleRes), cleanupTokens && ((_a = httpResponse.singleRes) === null || _a === void 0 ? void 0 : _a.id)
|
||||
? { userId: httpResponse.singleRes.id }
|
||||
: undefined);
|
||||
}
|
||||
httpResponse["cookieNames"] = cookieNames;
|
||||
@ -50,7 +50,7 @@ function postLoginResponseHandler({ database, httpResponse, response, encryption
|
||||
}
|
||||
response === null || response === void 0 ? void 0 : response.setHeader("Set-Cookie", [
|
||||
`${authKeyName}=${encryptedPayload};samesite=strict;path=/;HttpOnly=true;Expires=${COOKIE_EXPIRY_DATE}${secureCookie ? ";Secure=true" : ""}`,
|
||||
`${csrfName}=${(_b = httpResponse.payload) === null || _b === void 0 ? void 0 : _b.csrf_k};samesite=strict;path=/;HttpOnly=true;Expires=${COOKIE_EXPIRY_DATE}`,
|
||||
`${csrfName}=${(_b = httpResponse.singleRes) === null || _b === void 0 ? void 0 : _b.csrf_k};samesite=strict;path=/;HttpOnly=true;Expires=${COOKIE_EXPIRY_DATE}`,
|
||||
]);
|
||||
if (debug) {
|
||||
debugFn("Response Sent!");
|
||||
|
||||
@ -38,7 +38,7 @@ function suAddBackup(_a) {
|
||||
tableName: "backups",
|
||||
data: newBackup,
|
||||
});
|
||||
if (!((_b = newBackupEntry === null || newBackupEntry === void 0 ? void 0 : newBackupEntry.payload) === null || _b === void 0 ? void 0 : _b.insertId)) {
|
||||
if (!((_b = newBackupEntry === null || newBackupEntry === void 0 ? void 0 : newBackupEntry.postInsertReturn) === null || _b === void 0 ? void 0 : _b.insertId)) {
|
||||
return {
|
||||
success: false,
|
||||
msg: `Couldn't create new backup entry`,
|
||||
@ -46,7 +46,7 @@ function suAddBackup(_a) {
|
||||
}
|
||||
const { single: newlyAddedBackup } = yield (0, grab_user_resource_1.default)({
|
||||
tableName: "backups",
|
||||
targetID: (_c = newBackupEntry.payload) === null || _c === void 0 ? void 0 : _c.insertId,
|
||||
targetID: (_c = newBackupEntry.postInsertReturn) === null || _c === void 0 ? void 0 : _c.insertId,
|
||||
isSuperUser: true,
|
||||
});
|
||||
if (!(newlyAddedBackup === null || newlyAddedBackup === void 0 ? void 0 : newlyAddedBackup.id)) {
|
||||
|
||||
@ -53,7 +53,7 @@ function deleteDbEntry(_a) {
|
||||
*/
|
||||
return {
|
||||
success: Boolean(deletedEntry.affectedRows),
|
||||
payload: deletedEntry,
|
||||
postInsertReturn: deletedEntry,
|
||||
queryObject: {
|
||||
sql: (0, sql_formatter_1.format)(query),
|
||||
params: values,
|
||||
|
||||
@ -115,7 +115,7 @@ function updateDbEntry(_a) {
|
||||
*/
|
||||
return {
|
||||
success: Boolean(updatedEntry === null || updatedEntry === void 0 ? void 0 : updatedEntry.affectedRows),
|
||||
payload: updatedEntry,
|
||||
postInsertReturn: updatedEntry,
|
||||
queryObject: {
|
||||
sql: (0, sql_formatter_1.format)(query),
|
||||
params: updateValues,
|
||||
|
||||
@ -61,7 +61,9 @@ function handleMariadbUserRecord(_a) {
|
||||
query: {
|
||||
query: {
|
||||
id: {
|
||||
value: String((existingRecord === null || existingRecord === void 0 ? void 0 : existingRecord.id) || ((_d = record === null || record === void 0 ? void 0 : record.payload) === null || _d === void 0 ? void 0 : _d.insertId) || 0),
|
||||
value: String((existingRecord === null || existingRecord === void 0 ? void 0 : existingRecord.id) ||
|
||||
((_d = record === null || record === void 0 ? void 0 : record.postInsertReturn) === null || _d === void 0 ? void 0 : _d.insertId) ||
|
||||
0),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@ -52,7 +52,7 @@ function checkDbRecordCreateDbSchema(_a) {
|
||||
tableName: "user_databases",
|
||||
forceLocal: true,
|
||||
});
|
||||
if ((_b = newDbEntry.payload) === null || _b === void 0 ? void 0 : _b.insertId) {
|
||||
if ((_b = newDbEntry.postInsertReturn) === null || _b === void 0 ? void 0 : _b.insertId) {
|
||||
recordedDbEntryArray = (yield (0, dbHandler_1.default)({
|
||||
query: `SELECT * FROM datasquirel.user_databases WHERE db_full_name = ?`,
|
||||
values: [dbFullName || "NULL"],
|
||||
|
||||
@ -74,7 +74,7 @@ function checkTableRecordCreateDbSchema(_a) {
|
||||
dbContext: "Master",
|
||||
forceLocal: true,
|
||||
});
|
||||
if ((_b = newTableRecordEntry.payload) === null || _b === void 0 ? void 0 : _b.insertId) {
|
||||
if ((_b = newTableRecordEntry.postInsertReturn) === null || _b === void 0 ? void 0 : _b.insertId) {
|
||||
recordedTableEntryArray = (yield (0, dbHandler_1.default)({
|
||||
query: (queryObj === null || queryObj === void 0 ? void 0 : queryObj.string) || "",
|
||||
values: queryObj === null || queryObj === void 0 ? void 0 : queryObj.values,
|
||||
|
||||
@ -78,7 +78,7 @@ function createUser() {
|
||||
tableName: "users",
|
||||
data: Object.assign(Object.assign({}, userObj), { password: hashedPassword }),
|
||||
});
|
||||
if (!((_a = newUser === null || newUser === void 0 ? void 0 : newUser.payload) === null || _a === void 0 ? void 0 : _a.insertId))
|
||||
if (!((_a = newUser === null || newUser === void 0 ? void 0 : newUser.postInsertReturn) === null || _a === void 0 ? void 0 : _a.insertId))
|
||||
return false;
|
||||
const { STATIC_ROOT } = (0, grab_dir_names_1.default)();
|
||||
if (!STATIC_ROOT) {
|
||||
@ -90,17 +90,17 @@ function createUser() {
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/
|
||||
let newUserSchemaFolderPath = `${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${newUser.payload.insertId}`;
|
||||
let newUserMediaFolderPath = path_1.default.join(STATIC_ROOT, `images/user-images/user-${newUser.payload.insertId}`);
|
||||
let newUserSchemaFolderPath = `${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${newUser.postInsertReturn.insertId}`;
|
||||
let newUserMediaFolderPath = path_1.default.join(STATIC_ROOT, `images/user-images/user-${newUser.postInsertReturn.insertId}`);
|
||||
fs_1.default.mkdirSync(newUserSchemaFolderPath, { recursive: true });
|
||||
fs_1.default.mkdirSync(newUserMediaFolderPath, { recursive: true });
|
||||
fs_1.default.writeFileSync(`${newUserSchemaFolderPath}/main.json`, JSON.stringify([]), "utf8");
|
||||
const imageBasePath = path_1.default.join(STATIC_ROOT, `images/user-images/user-${newUser.payload.insertId}`);
|
||||
const imageBasePath = path_1.default.join(STATIC_ROOT, `images/user-images/user-${newUser.postInsertReturn.insertId}`);
|
||||
if (!fs_1.default.existsSync(imageBasePath)) {
|
||||
fs_1.default.mkdirSync(imageBasePath, { recursive: true });
|
||||
}
|
||||
let imagePath = path_1.default.join(STATIC_ROOT, `images/user-images/user-${newUser.payload.insertId}/user-${newUser.payload.insertId}-profile.jpg`);
|
||||
let imageThumbnailPath = path_1.default.join(STATIC_ROOT, `images/user-images/user-${newUser.payload.insertId}/user-${newUser.payload.insertId}-profile-thumbnail.jpg`);
|
||||
let imagePath = path_1.default.join(STATIC_ROOT, `images/user-images/user-${newUser.postInsertReturn.insertId}/user-${newUser.postInsertReturn.insertId}-profile.jpg`);
|
||||
let imageThumbnailPath = path_1.default.join(STATIC_ROOT, `images/user-images/user-${newUser.postInsertReturn.insertId}/user-${newUser.postInsertReturn.insertId}-profile-thumbnail.jpg`);
|
||||
let prodImageUrl = imagePath.replace(STATIC_ROOT, process.env.DSQL_STATIC_HOST || "");
|
||||
let prodImageThumbnailUrl = imageThumbnailPath.replace(STATIC_ROOT, process.env.DSQL_STATIC_HOST || "");
|
||||
fs_1.default.copyFileSync(path_1.default.join(ROOT_DIR, "/public/images/user-preset.png"), imagePath);
|
||||
@ -110,7 +110,7 @@ function createUser() {
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "users",
|
||||
identifierColumnName: "id",
|
||||
identifierValue: newUser.payload.insertId,
|
||||
identifierValue: newUser.postInsertReturn.insertId,
|
||||
data: {
|
||||
image: prodImageUrl,
|
||||
image_thumbnail: prodImageThumbnailUrl,
|
||||
|
||||
@ -85,8 +85,8 @@ function default_1(_a) {
|
||||
tableName: targetTableName,
|
||||
dbFullName: targetDatabase,
|
||||
});
|
||||
if ((_b = newTableEntryRes === null || newTableEntryRes === void 0 ? void 0 : newTableEntryRes.payload) === null || _b === void 0 ? void 0 : _b.insertId) {
|
||||
tableId = newTableEntryRes.payload.insertId;
|
||||
if ((_b = newTableEntryRes === null || newTableEntryRes === void 0 ? void 0 : newTableEntryRes.postInsertReturn) === null || _b === void 0 ? void 0 : _b.insertId) {
|
||||
tableId = newTableEntryRes.postInsertReturn.insertId;
|
||||
}
|
||||
}
|
||||
if (newTableSchema.tableNameOld) {
|
||||
|
||||
10
dist/package-shared/types/index.d.ts
vendored
10
dist/package-shared/types/index.d.ts
vendored
@ -1444,9 +1444,15 @@ export type ResponseQueryObject = {
|
||||
sql?: string;
|
||||
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;
|
||||
|
||||
@ -99,7 +99,7 @@ function dsqlCrud(params) {
|
||||
}));
|
||||
return {
|
||||
success: Boolean(res.affectedRows),
|
||||
payload: res,
|
||||
postInsertReturn: res,
|
||||
queryObject: {
|
||||
sql: (0, sql_formatter_1.format)((deleteQuery === null || deleteQuery === void 0 ? void 0 : deleteQuery.query) || ""),
|
||||
params: (deleteQuery === null || deleteQuery === void 0 ? void 0 : deleteQuery.values) || [],
|
||||
|
||||
@ -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 || [],
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/datasquirel",
|
||||
"version": "5.5.7",
|
||||
"version": "5.5.8",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user