Major refactoring: Add user id to API routes
This commit is contained in:
parent
a529d0bd08
commit
b047d6557c
@ -41,9 +41,12 @@ const getData = await datasquirel.get({
|
|||||||
key: "aldhkf89asdflksdafh908asdfjkhasdf", // Readonly API Key
|
key: "aldhkf89asdflksdafh908asdfjkhasdf", // Readonly API Key
|
||||||
db: "my_database", // Database name slug (Eg. Db Name => My Database, Db Slug => my_database)
|
db: "my_database", // Database name slug (Eg. Db Name => My Database, Db Slug => my_database)
|
||||||
query: "SELECT * FROM blog_posts", // SQL Query
|
query: "SELECT * FROM blog_posts", // SQL Query
|
||||||
|
user_id: 129, // Your User Id: check settings page
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> NOTE: You can skip the `user_id` parameter by adding an environment variable named `DSQL_API_USER_ID`
|
||||||
|
|
||||||
Datasquirel uses all conventional SQL query commands. However you can only use the `SELECT` command when using a readonly API key.
|
Datasquirel uses all conventional SQL query commands. However you can only use the `SELECT` command when using a readonly API key.
|
||||||
|
|
||||||
### Post Data
|
### Post Data
|
||||||
@ -63,6 +66,7 @@ const postData = await datasquirel.post({
|
|||||||
user_last_name: "Doe",
|
user_last_name: "Doe",
|
||||||
},
|
},
|
||||||
table: "users",
|
table: "users",
|
||||||
|
user_id: 271,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
@ -75,6 +79,7 @@ const datasquirel = require("@moduletrace/datasquirel");
|
|||||||
const postData = await datasquirel.post({
|
const postData = await datasquirel.post({
|
||||||
key: process.env.FULL_ACCESS_API_KEY,
|
key: process.env.FULL_ACCESS_API_KEY,
|
||||||
payload: "SELECT * FROM blog_posts WHERE user_id='as09d7nasd90'",
|
payload: "SELECT * FROM blog_posts WHERE user_id='as09d7nasd90'",
|
||||||
|
user_id: 271,
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -90,6 +95,7 @@ const postData = await datasquirel.post({
|
|||||||
condition: `WHERE user_id='21adwei9jewr' AND type='buyers'`,
|
condition: `WHERE user_id='21adwei9jewr' AND type='buyers'`,
|
||||||
table: "users",
|
table: "users",
|
||||||
},
|
},
|
||||||
|
user_id: 271,
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -110,6 +116,7 @@ const postData = await datasquirel.post({
|
|||||||
last_name: "Spencer",
|
last_name: "Spencer",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
user_id: 271,
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -128,6 +135,7 @@ const postData = await datasquirel.uploadImage({
|
|||||||
mimeType: "jpg", // optional
|
mimeType: "jpg", // optional
|
||||||
thumbnailSize: 120, // optional === This measurement is in pixels(px)
|
thumbnailSize: 120, // optional === This measurement is in pixels(px)
|
||||||
},
|
},
|
||||||
|
user_id: 271,
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ async function updateApiSchemaFromLocalDb() {
|
|||||||
const key = process.env.DSQL_KEY || "";
|
const key = process.env.DSQL_KEY || "";
|
||||||
|
|
||||||
const dbSchema = JSON.parse(fs.readFileSync(dbSchemaPath, "utf8"));
|
const dbSchema = JSON.parse(fs.readFileSync(dbSchemaPath, "utf8"));
|
||||||
const { host, port, scheme } = grabHostNames();
|
const { host, port, scheme, user_id } = grabHostNames();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make https request
|
* Make https request
|
||||||
@ -79,7 +79,7 @@ async function updateApiSchemaFromLocalDb() {
|
|||||||
},
|
},
|
||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
path: `/api/query/update-schema-from-single-database`,
|
path: `/api/query/${user_id}/update-schema-from-single-database`,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -178,7 +178,11 @@ function sqlGenerator({ tableName, genObject }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (genObject.order)
|
if (genObject.order)
|
||||||
queryString += ` ORDER BY ${genObject.order.field} ${genObject.order.strategy}`;
|
queryString += ` ORDER BY ${
|
||||||
|
genObject.join
|
||||||
|
? `${tableName}.${genObject.order.field}`
|
||||||
|
: genObject.order.field
|
||||||
|
} ${genObject.order.strategy}`;
|
||||||
if (genObject.limit) queryString += ` LIMIT ${genObject.limit}`;
|
if (genObject.limit) queryString += ` LIMIT ${genObject.limit}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -4,8 +4,9 @@ const fs = require("fs");
|
|||||||
const decrypt = require("./decrypt");
|
const decrypt = require("./decrypt");
|
||||||
|
|
||||||
/** @type {import("../../types").CheckApiCredentialsFn} */
|
/** @type {import("../../types").CheckApiCredentialsFn} */
|
||||||
const grabApiCred = ({ key, database, table }) => {
|
const grabApiCred = ({ key, database, table, user_id }) => {
|
||||||
if (!key) return null;
|
if (!key) return null;
|
||||||
|
if (!user_id) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const allowedKeysPath = process.env.DSQL_API_KEYS_PATH;
|
const allowedKeysPath = process.env.DSQL_API_KEYS_PATH;
|
||||||
@ -22,6 +23,8 @@ const grabApiCred = ({ key, database, table }) => {
|
|||||||
`${allowedKeysPath}/${ApiObject.sign}`
|
`${allowedKeysPath}/${ApiObject.sign}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (String(ApiObject.user_id) !== String(user_id)) return null;
|
||||||
|
|
||||||
if (!isApiKeyValid) return null;
|
if (!isApiKeyValid) return null;
|
||||||
if (!ApiObject.target_database) return ApiObject;
|
if (!ApiObject.target_database) return ApiObject;
|
||||||
if (!database && ApiObject.target_database) return null;
|
if (!database && ApiObject.target_database) return null;
|
||||||
|
11
package-shared/types/index.d.ts
vendored
11
package-shared/types/index.d.ts
vendored
@ -335,6 +335,7 @@ export interface GetSchemaRequestQuery {
|
|||||||
database?: string;
|
database?: string;
|
||||||
table?: string;
|
table?: string;
|
||||||
field?: string;
|
field?: string;
|
||||||
|
user_id?: string | number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetSchemaAPICredentialsParam {
|
export interface GetSchemaAPICredentialsParam {
|
||||||
@ -1095,6 +1096,7 @@ export type CheckApiCredentialsFnParam = {
|
|||||||
key?: string;
|
key?: string;
|
||||||
database?: string;
|
database?: string;
|
||||||
table?: string;
|
table?: string;
|
||||||
|
user_id?: string | number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FetchApiFn = (
|
export type FetchApiFn = (
|
||||||
@ -1218,3 +1220,12 @@ export type SqlGeneratorFn = (Param0: {
|
|||||||
values: string[];
|
values: string[];
|
||||||
}
|
}
|
||||||
| undefined;
|
| undefined;
|
||||||
|
|
||||||
|
export type ApiConnectBody = {
|
||||||
|
url: string;
|
||||||
|
key: string;
|
||||||
|
database: DSQL_MYSQL_user_databases_Type;
|
||||||
|
dbSchema: DSQL_DatabaseSchemaType;
|
||||||
|
type: "pull" | "push";
|
||||||
|
user_id?: string | number;
|
||||||
|
};
|
||||||
|
@ -8,6 +8,7 @@ const http = require("http");
|
|||||||
* @property {string} host
|
* @property {string} host
|
||||||
* @property {number | string} port
|
* @property {number | string} port
|
||||||
* @property {typeof http | typeof https} scheme
|
* @property {typeof http | typeof https} scheme
|
||||||
|
* @property {string | number} user_id
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,6 +30,7 @@ function grabHostNames() {
|
|||||||
host: remoteHost || localHost || "datasquirel.com",
|
host: remoteHost || localHost || "datasquirel.com",
|
||||||
port: remoteHostPort || localHostPort || 443,
|
port: remoteHostPort || localHostPort || 443,
|
||||||
scheme: scheme?.match(/^http$/i) ? http : https,
|
scheme: scheme?.match(/^http$/i) ? http : https,
|
||||||
|
user_id: String(process.env.DSQL_API_USER_ID || 0),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "2.7.3",
|
"version": "2.7.4",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
@ -12,12 +12,13 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
|||||||
* ==============================================================================
|
* ==============================================================================
|
||||||
* @async
|
* @async
|
||||||
*
|
*
|
||||||
* @param {object} props - Single object passed
|
* @param {object} param - Single object passed
|
||||||
* @param {string} props.key - FULL ACCESS API Key
|
* @param {string} param.key - FULL ACCESS API Key
|
||||||
* @param {string} props.database - Database Name
|
* @param {string} param.database - Database Name
|
||||||
* @param {import("../package-shared/types").UserDataPayload} props.payload - User Data Payload
|
* @param {import("../package-shared/types").UserDataPayload} param.payload - User Data Payload
|
||||||
* @param {string} props.encryptionKey
|
* @param {string} param.encryptionKey
|
||||||
* @param {string} [props.encryptionSalt]
|
* @param {string} [param.encryptionSalt]
|
||||||
|
* @param {boolean} [param.user_id] - User ID
|
||||||
*
|
*
|
||||||
* @returns { Promise<import("../package-shared/types").AddUserFunctionReturn> }
|
* @returns { Promise<import("../package-shared/types").AddUserFunctionReturn> }
|
||||||
*/
|
*/
|
||||||
@ -27,6 +28,7 @@ async function addUser({
|
|||||||
database,
|
database,
|
||||||
encryptionKey,
|
encryptionKey,
|
||||||
encryptionSalt,
|
encryptionSalt,
|
||||||
|
user_id,
|
||||||
}) {
|
}) {
|
||||||
/**
|
/**
|
||||||
* Check for local DB settings
|
* Check for local DB settings
|
||||||
@ -43,7 +45,8 @@ async function addUser({
|
|||||||
DSQL_FULL_SYNC,
|
DSQL_FULL_SYNC,
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
const { host, port, scheme } = grabHostNames();
|
const grabedHostNames = grabHostNames();
|
||||||
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
DSQL_HOST?.match(/./) &&
|
DSQL_HOST?.match(/./) &&
|
||||||
@ -97,7 +100,9 @@ async function addUser({
|
|||||||
},
|
},
|
||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
path: `/api/user/add-user`,
|
path: `/api/user/${
|
||||||
|
user_id || grabedHostNames.user_id
|
||||||
|
}/add-user`,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,10 +30,11 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
|||||||
* @param {String} params.database - Target Database
|
* @param {String} params.database - Target Database
|
||||||
* @param {number} params.userId - user id
|
* @param {number} params.userId - user id
|
||||||
* @param {string[]} [params.fields] - fields to select
|
* @param {string[]} [params.fields] - fields to select
|
||||||
|
* @param {boolean} [params.user_id] - User ID
|
||||||
*
|
*
|
||||||
* @returns { Promise<import("../package-shared/types").GetUserFunctionReturn>}
|
* @returns { Promise<import("../package-shared/types").GetUserFunctionReturn>}
|
||||||
*/
|
*/
|
||||||
async function getUser({ key, userId, database, fields }) {
|
async function getUser({ key, userId, database, fields, user_id }) {
|
||||||
/**
|
/**
|
||||||
* Initialize
|
* Initialize
|
||||||
*/
|
*/
|
||||||
@ -63,7 +64,8 @@ async function getUser({ key, userId, database, fields }) {
|
|||||||
fields: [...new Set(updatedFields)],
|
fields: [...new Set(updatedFields)],
|
||||||
});
|
});
|
||||||
|
|
||||||
const { host, port, scheme } = grabHostNames();
|
const grabedHostNames = grabHostNames();
|
||||||
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for local DB settings
|
* Check for local DB settings
|
||||||
@ -125,7 +127,9 @@ async function getUser({ key, userId, database, fields }) {
|
|||||||
},
|
},
|
||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
path: `/api/user/get-user`,
|
path: `/api/user/${
|
||||||
|
user_id || grabedHostNames.user_id
|
||||||
|
}/get-user`,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,6 +41,7 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
|||||||
* @param {string} [params.email_login_code] - Email login code
|
* @param {string} [params.email_login_code] - Email login code
|
||||||
* @param {string} [params.temp_code_field] - Database table field name for temporary code
|
* @param {string} [params.temp_code_field] - Database table field name for temporary code
|
||||||
* @param {boolean} [params.token] - Send access key as part of response body?
|
* @param {boolean} [params.token] - Send access key as part of response body?
|
||||||
|
* @param {boolean} [params.user_id] - User ID
|
||||||
*
|
*
|
||||||
* @returns { Promise<import("../package-shared/types").AuthenticatedUser>}
|
* @returns { Promise<import("../package-shared/types").AuthenticatedUser>}
|
||||||
*/
|
*/
|
||||||
@ -56,8 +57,10 @@ async function loginUser({
|
|||||||
email_login_code,
|
email_login_code,
|
||||||
temp_code_field,
|
temp_code_field,
|
||||||
token,
|
token,
|
||||||
|
user_id,
|
||||||
}) {
|
}) {
|
||||||
const { host, port, scheme } = grabHostNames();
|
const grabedHostNames = grabHostNames();
|
||||||
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
|
||||||
const defaultTempLoginFieldName = "temp_login_code";
|
const defaultTempLoginFieldName = "temp_login_code";
|
||||||
const emailLoginTempCodeFieldName = email_login
|
const emailLoginTempCodeFieldName = email_login
|
||||||
@ -183,7 +186,9 @@ async function loginUser({
|
|||||||
},
|
},
|
||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
path: `/api/user/login-user`,
|
path: `/api/user/${
|
||||||
|
user_id || grabedHostNames.user_id
|
||||||
|
}/login-user`,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,6 +38,7 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
|||||||
* @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 {string} [params.token] - access token to use instead of getting from cookie header
|
* @param {string} [params.token] - access token to use instead of getting from cookie header
|
||||||
|
* @param {boolean} [params.user_id] - User ID
|
||||||
*
|
*
|
||||||
* @returns { Promise<import("../package-shared/types").ReauthUserFunctionReturn> }
|
* @returns { Promise<import("../package-shared/types").ReauthUserFunctionReturn> }
|
||||||
*/
|
*/
|
||||||
@ -51,13 +52,15 @@ async function reauthUser({
|
|||||||
encryptionSalt,
|
encryptionSalt,
|
||||||
additionalFields,
|
additionalFields,
|
||||||
token,
|
token,
|
||||||
|
user_id,
|
||||||
}) {
|
}) {
|
||||||
/**
|
/**
|
||||||
* Check Encryption Keys
|
* Check Encryption Keys
|
||||||
*
|
*
|
||||||
* @description Check Encryption Keys
|
* @description Check Encryption Keys
|
||||||
*/
|
*/
|
||||||
const { host, port, scheme } = grabHostNames();
|
const grabedHostNames = grabHostNames();
|
||||||
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
|
||||||
const existingUser = userAuth({
|
const existingUser = userAuth({
|
||||||
database,
|
database,
|
||||||
@ -146,7 +149,9 @@ async function reauthUser({
|
|||||||
},
|
},
|
||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
path: `/api/user/reauth-user`,
|
path: `/api/user/${
|
||||||
|
user_id || grabedHostNames.user_id
|
||||||
|
}/reauth-user`,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,6 +39,7 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
|||||||
* @param {string} [params.mail_password]
|
* @param {string} [params.mail_password]
|
||||||
* @param {number} [params.mail_port]
|
* @param {number} [params.mail_port]
|
||||||
* @param {string} [params.sender]
|
* @param {string} [params.sender]
|
||||||
|
* @param {boolean} [params.user_id] - User ID
|
||||||
*
|
*
|
||||||
* @returns { Promise<boolean>}
|
* @returns { Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
@ -54,8 +55,10 @@ async function sendEmailCode({
|
|||||||
mail_username,
|
mail_username,
|
||||||
mail_port,
|
mail_port,
|
||||||
sender,
|
sender,
|
||||||
|
user_id,
|
||||||
}) {
|
}) {
|
||||||
const { host, port, scheme } = grabHostNames();
|
const grabedHostNames = grabHostNames();
|
||||||
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
|
||||||
const defaultTempLoginFieldName = "temp_login_code";
|
const defaultTempLoginFieldName = "temp_login_code";
|
||||||
const emailLoginTempCodeFieldName = temp_code_field
|
const emailLoginTempCodeFieldName = temp_code_field
|
||||||
@ -176,7 +179,9 @@ async function sendEmailCode({
|
|||||||
},
|
},
|
||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
path: `/api/user/send-email-code`,
|
path: `/api/user/${
|
||||||
|
user_id || grabedHostNames.user_id
|
||||||
|
}/send-email-code`,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,6 +45,7 @@ const grabHostNames = require("../../package-shared/utils/grab-host-names");
|
|||||||
* @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
|
||||||
|
* @param {boolean} [params.user_id] - User ID
|
||||||
*
|
*
|
||||||
* @returns { Promise<FunctionReturn | undefined> }
|
* @returns { Promise<FunctionReturn | undefined> }
|
||||||
*/
|
*/
|
||||||
@ -59,13 +60,15 @@ async function githubAuth({
|
|||||||
encryptionKey,
|
encryptionKey,
|
||||||
encryptionSalt,
|
encryptionSalt,
|
||||||
additionalFields,
|
additionalFields,
|
||||||
|
user_id,
|
||||||
}) {
|
}) {
|
||||||
/**
|
/**
|
||||||
* Check inputs
|
* Check inputs
|
||||||
*
|
*
|
||||||
* @description Check inputs
|
* @description Check inputs
|
||||||
*/
|
*/
|
||||||
const { host, port, scheme } = grabHostNames();
|
const grabedHostNames = grabHostNames();
|
||||||
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
|
||||||
if (!key || key?.match(/ /)) {
|
if (!key || key?.match(/ /)) {
|
||||||
return {
|
return {
|
||||||
@ -205,7 +208,9 @@ async function githubAuth({
|
|||||||
},
|
},
|
||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
path: `/api/user/github-login`,
|
path: `/api/user/${
|
||||||
|
user_id || grabedHostNames.user_id
|
||||||
|
}/github-login`,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,6 +43,7 @@ const grabHostNames = require("../../package-shared/utils/grab-host-names");
|
|||||||
* @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
|
||||||
|
* @param {boolean} [params.user_id] - User ID
|
||||||
*
|
*
|
||||||
* @returns { Promise<FunctionReturn> }
|
* @returns { Promise<FunctionReturn> }
|
||||||
*/
|
*/
|
||||||
@ -55,8 +56,10 @@ async function googleAuth({
|
|||||||
encryptionKey,
|
encryptionKey,
|
||||||
encryptionSalt,
|
encryptionSalt,
|
||||||
additionalFields,
|
additionalFields,
|
||||||
|
user_id,
|
||||||
}) {
|
}) {
|
||||||
const { host, port, scheme } = grabHostNames();
|
const grabedHostNames = grabHostNames();
|
||||||
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check inputs
|
* Check inputs
|
||||||
@ -201,7 +204,9 @@ async function googleAuth({
|
|||||||
},
|
},
|
||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
path: `/api/user/google-login`,
|
path: `/api/user/${
|
||||||
|
user_id || grabedHostNames.user_id
|
||||||
|
}/google-login`,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,10 +15,11 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
|||||||
* @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 {{ id: number } & Object.<string, any>} params.payload - User Object: ID is required
|
* @param {{ id: number } & Object.<string, any>} params.payload - User Object: ID is required
|
||||||
|
* @param {boolean} [params.user_id] - User ID
|
||||||
*
|
*
|
||||||
* @returns { Promise<import("../package-shared/types").UpdateUserFunctionReturn>}
|
* @returns { Promise<import("../package-shared/types").UpdateUserFunctionReturn>}
|
||||||
*/
|
*/
|
||||||
async function updateUser({ key, payload, database }) {
|
async function updateUser({ key, payload, database, user_id }) {
|
||||||
/**
|
/**
|
||||||
* Check for local DB settings
|
* Check for local DB settings
|
||||||
*
|
*
|
||||||
@ -34,7 +35,8 @@ async function updateUser({ key, payload, database }) {
|
|||||||
DSQL_FULL_SYNC,
|
DSQL_FULL_SYNC,
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
const { host, port, scheme } = grabHostNames();
|
const grabedHostNames = grabHostNames();
|
||||||
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
DSQL_HOST?.match(/./) &&
|
DSQL_HOST?.match(/./) &&
|
||||||
@ -85,7 +87,9 @@ async function updateUser({ key, payload, database }) {
|
|||||||
},
|
},
|
||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
path: `/api/user/update-user`,
|
path: `/api/user/${
|
||||||
|
user_id || grabedHostNames.user_id
|
||||||
|
}/update-user`,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,11 +21,13 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
|||||||
* @param {Object} params - Single Param object containing params
|
* @param {Object} params - Single Param object containing params
|
||||||
* @param {String} params.key - *FULL ACCESS API Key
|
* @param {String} params.key - *FULL ACCESS API Key
|
||||||
* @param { string } params.url - File URL
|
* @param { string } params.url - File URL
|
||||||
|
* @param { string | number } [params.user_id]
|
||||||
*
|
*
|
||||||
* @returns { Promise<FunctionReturn> } - Image Url
|
* @returns { Promise<FunctionReturn> } - Image Url
|
||||||
*/
|
*/
|
||||||
async function uploadImage({ key, url }) {
|
async function deleteFile({ key, url, user_id }) {
|
||||||
const { host, port, scheme } = grabHostNames();
|
const grabedHostNames = grabHostNames();
|
||||||
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/**
|
/**
|
||||||
@ -49,7 +51,9 @@ async function uploadImage({ key, url }) {
|
|||||||
},
|
},
|
||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
path: `/api/query/delete-file`,
|
path: `/api/query/${
|
||||||
|
user_id || grabedHostNames.user_id
|
||||||
|
}/delete-file`,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,4 +94,4 @@ async function uploadImage({ key, url }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = uploadImage;
|
module.exports = deleteFile;
|
||||||
|
@ -16,8 +16,9 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
|||||||
*
|
*
|
||||||
* @returns { Promise<GetSchemaReturn> } - Return Object
|
* @returns { Promise<GetSchemaReturn> } - Return Object
|
||||||
*/
|
*/
|
||||||
async function getSchema({ key, database, field, table }) {
|
async function getSchema({ key, database, field, table, user_id }) {
|
||||||
const { host, port, scheme } = grabHostNames();
|
const grabedHostNames = grabHostNames();
|
||||||
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make https request
|
* Make https request
|
||||||
@ -48,8 +49,9 @@ async function getSchema({ key, database, field, table }) {
|
|||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
path:
|
path:
|
||||||
"/api/query/get-schema" +
|
`/api/query/${
|
||||||
(query?.match(/./) ? `?${query}` : ""),
|
user_id || grabedHostNames.user_id
|
||||||
|
}/get-schema` + (query?.match(/./) ? `?${query}` : ""),
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
18
utils/get.js
18
utils/get.js
@ -20,11 +20,21 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
|||||||
* @param {string[]} [params.queryValues] - An array of query values if using "?" placeholders
|
* @param {string[]} [params.queryValues] - An array of query values if using "?" placeholders
|
||||||
* @param {string} [params.tableName] - Name of the table to query
|
* @param {string} [params.tableName] - Name of the table to query
|
||||||
* @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
|
||||||
|
* @param {boolean} [params.user_id] - User ID
|
||||||
*
|
*
|
||||||
* @returns { Promise<import("../package-shared/types").GetReturn> } - Return Object
|
* @returns { Promise<import("../package-shared/types").GetReturn> } - Return Object
|
||||||
*/
|
*/
|
||||||
async function get({ key, db, query, queryValues, tableName, useLocal }) {
|
async function get({
|
||||||
const { host, port, scheme } = grabHostNames();
|
key,
|
||||||
|
db,
|
||||||
|
query,
|
||||||
|
queryValues,
|
||||||
|
tableName,
|
||||||
|
useLocal,
|
||||||
|
user_id,
|
||||||
|
}) {
|
||||||
|
const grabedHostNames = grabHostNames();
|
||||||
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for local DB settings
|
* Check for local DB settings
|
||||||
@ -83,7 +93,9 @@ async function get({ key, db, query, queryValues, tableName, useLocal }) {
|
|||||||
|
|
||||||
const queryString = serializeQuery({ query: queryObject });
|
const queryString = serializeQuery({ query: queryObject });
|
||||||
|
|
||||||
let path = `/api/query/get${queryString}`;
|
let path = `/api/query/${
|
||||||
|
user_id || grabedHostNames.user_id
|
||||||
|
}/get${queryString}`;
|
||||||
|
|
||||||
/** @type {https.RequestOptions} */
|
/** @type {https.RequestOptions} */
|
||||||
const requestObject = {
|
const requestObject = {
|
||||||
|
@ -16,6 +16,7 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
|||||||
* @param {any[]} [params.queryValues] - Query Values if using "?" placeholders
|
* @param {any[]} [params.queryValues] - Query Values if using "?" placeholders
|
||||||
* @param {string} [params.tableName] - Name of the table to query
|
* @param {string} [params.tableName] - Name of the table to query
|
||||||
* @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
|
||||||
|
* @param {boolean} [params.user_id] - User ID
|
||||||
*
|
*
|
||||||
* @returns { Promise<import("../package-shared/types").PostReturn> } - Return Object
|
* @returns { Promise<import("../package-shared/types").PostReturn> } - Return Object
|
||||||
*/
|
*/
|
||||||
@ -26,8 +27,10 @@ async function post({
|
|||||||
database,
|
database,
|
||||||
tableName,
|
tableName,
|
||||||
useLocal,
|
useLocal,
|
||||||
|
user_id,
|
||||||
}) {
|
}) {
|
||||||
const { host, port, scheme } = grabHostNames();
|
const grabedHostNames = grabHostNames();
|
||||||
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for local DB settings
|
* Check for local DB settings
|
||||||
@ -106,7 +109,7 @@ async function post({
|
|||||||
},
|
},
|
||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
path: `/api/query/post`,
|
path: `/api/query/${user_id || grabedHostNames.user_id}/post`,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,13 +24,15 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
|||||||
* fileName: string,
|
* fileName: string,
|
||||||
* mimeType?: string,
|
* mimeType?: string,
|
||||||
* folder?: string,
|
* folder?: string,
|
||||||
* isPrivate?: boolean,
|
* isPrivate?: boolean
|
||||||
* }} params.payload - Image Data Eg.
|
* }} params.payload - Image Data Eg.
|
||||||
|
* @param {boolean} [params.user_id] - User ID
|
||||||
*
|
*
|
||||||
* @returns { Promise<FunctionReturn> } - Return Object
|
* @returns { Promise<FunctionReturn> } - Return Object
|
||||||
*/
|
*/
|
||||||
async function uploadImage({ key, payload }) {
|
async function uploadImage({ key, payload, user_id }) {
|
||||||
const { host, port, scheme } = grabHostNames();
|
const grabedHostNames = grabHostNames();
|
||||||
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/**
|
/**
|
||||||
@ -54,7 +56,9 @@ async function uploadImage({ key, payload }) {
|
|||||||
},
|
},
|
||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
path: `/api/query/add-file`,
|
path: `/api/query/${
|
||||||
|
user_id || grabedHostNames.user_id
|
||||||
|
}/add-file`,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,11 +28,13 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
|||||||
* folder?: string,
|
* folder?: string,
|
||||||
* isPrivate?: boolean,
|
* isPrivate?: boolean,
|
||||||
* }} params.payload - Image Data Eg.
|
* }} params.payload - Image Data Eg.
|
||||||
|
* @param {boolean} [params.user_id] - User ID
|
||||||
*
|
*
|
||||||
* @returns { Promise<FunctionReturn> } - Return Object
|
* @returns { Promise<FunctionReturn> } - Return Object
|
||||||
*/
|
*/
|
||||||
async function uploadImage({ key, payload }) {
|
async function uploadImage({ key, payload, user_id }) {
|
||||||
const { host, port, scheme } = grabHostNames();
|
const grabedHostNames = grabHostNames();
|
||||||
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/**
|
/**
|
||||||
@ -56,7 +58,9 @@ async function uploadImage({ key, payload }) {
|
|||||||
},
|
},
|
||||||
port,
|
port,
|
||||||
hostname: host,
|
hostname: host,
|
||||||
path: `/api/query/add-image`,
|
path: `/api/query/${
|
||||||
|
user_id || grabedHostNames.user_id
|
||||||
|
}/add-image`,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user