Updates
This commit is contained in:
+5
-2
@@ -1,4 +1,5 @@
|
||||
import { APIResponseObject, DataCrudRequestMethods, DataCrudRequestMethodsLowerCase } from "../../types";
|
||||
import { APIConnectionOptions, APIResponseObject, DataCrudRequestMethods, DataCrudRequestMethodsLowerCase } from "../../types";
|
||||
import { GrabHostNamesReturn } from "../../utils/grab-host-names";
|
||||
type Param<T = {
|
||||
[k: string]: any;
|
||||
}> = {
|
||||
@@ -8,6 +9,8 @@ type Param<T = {
|
||||
path: string;
|
||||
method?: (typeof DataCrudRequestMethods)[number] | (typeof DataCrudRequestMethodsLowerCase)[number];
|
||||
apiKey?: string;
|
||||
apiConnectionConfig?: APIConnectionOptions;
|
||||
grabbedHostnames?: GrabHostNamesReturn;
|
||||
};
|
||||
/**
|
||||
* # Query DSQL API
|
||||
@@ -16,5 +19,5 @@ export default function queryDSQLAPI<T = {
|
||||
[k: string]: any;
|
||||
}, P = {
|
||||
[k: string]: any;
|
||||
}>({ body, query, useDefault, path: passedPath, method, apiKey, }: Param<T>): Promise<APIResponseObject<P>>;
|
||||
}>({ body, query, useDefault, path: passedPath, method, apiKey, apiConnectionConfig, grabbedHostnames, }: Param<T>): Promise<APIResponseObject<P>>;
|
||||
export {};
|
||||
|
||||
+10
-8
@@ -21,9 +21,16 @@ const lodash_1 = __importDefault(require("lodash"));
|
||||
* # Query DSQL API
|
||||
*/
|
||||
function queryDSQLAPI(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ body, query, useDefault, path: passedPath, method, apiKey, }) {
|
||||
const grabedHostNames = (0, grab_host_names_1.default)({ useDefault });
|
||||
return __awaiter(this, arguments, void 0, function* ({ body, query, useDefault, path: passedPath, method, apiKey, apiConnectionConfig, grabbedHostnames, }) {
|
||||
const grabedHostNames = grabbedHostnames || (0, grab_host_names_1.default)({ useDefault, apiConnectionConfig });
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
const finalAPIKey = apiKey ||
|
||||
(apiConnectionConfig === null || apiConnectionConfig === void 0 ? void 0 : apiConnectionConfig.apiKey) ||
|
||||
(!method || method == "GET" || method == "get"
|
||||
? process.env.DSQL_READ_ONLY_API_KEY
|
||||
: undefined) ||
|
||||
process.env.DSQL_FULL_ACCESS_API_KEY ||
|
||||
process.env.DSQL_API_KEY;
|
||||
try {
|
||||
/**
|
||||
* Make https request
|
||||
@@ -34,12 +41,7 @@ function queryDSQLAPI(_a) {
|
||||
const reqPayload = body ? JSON.stringify(body) : undefined;
|
||||
let headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: apiKey ||
|
||||
(!method || method == "GET" || method == "get"
|
||||
? process.env.DSQL_READ_ONLY_API_KEY
|
||||
: undefined) ||
|
||||
process.env.DSQL_FULL_ACCESS_API_KEY ||
|
||||
process.env.DSQL_API_KEY,
|
||||
Authorization: finalAPIKey,
|
||||
};
|
||||
if (reqPayload) {
|
||||
headers["Content-Length"] = Buffer.from(reqPayload).length;
|
||||
|
||||
Reference in New Issue
Block a user