Updates
This commit is contained in:
@@ -2,11 +2,14 @@ import path from "path";
|
||||
|
||||
import { OutgoingHttpHeaders } from "http";
|
||||
import {
|
||||
APIConnectionOptions,
|
||||
APIResponseObject,
|
||||
DataCrudRequestMethods,
|
||||
DataCrudRequestMethodsLowerCase,
|
||||
} from "../../types";
|
||||
import grabHostNames from "../../utils/grab-host-names";
|
||||
import grabHostNames, {
|
||||
GrabHostNamesReturn,
|
||||
} from "../../utils/grab-host-names";
|
||||
import serializeQuery from "../../utils/serialize-query";
|
||||
import { RequestOptions } from "https";
|
||||
import _ from "lodash";
|
||||
@@ -20,6 +23,8 @@ type Param<T = { [k: string]: any }> = {
|
||||
| (typeof DataCrudRequestMethods)[number]
|
||||
| (typeof DataCrudRequestMethodsLowerCase)[number];
|
||||
apiKey?: string;
|
||||
apiConnectionConfig?: APIConnectionOptions;
|
||||
grabbedHostnames?: GrabHostNamesReturn;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -35,10 +40,22 @@ export default async function queryDSQLAPI<
|
||||
path: passedPath,
|
||||
method,
|
||||
apiKey,
|
||||
apiConnectionConfig,
|
||||
grabbedHostnames,
|
||||
}: Param<T>): Promise<APIResponseObject<P>> {
|
||||
const grabedHostNames = grabHostNames({ useDefault });
|
||||
const grabedHostNames =
|
||||
grabbedHostnames || grabHostNames({ useDefault, apiConnectionConfig });
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
|
||||
const finalAPIKey =
|
||||
apiKey ||
|
||||
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
|
||||
@@ -50,13 +67,7 @@ export default async function queryDSQLAPI<
|
||||
|
||||
let headers: OutgoingHttpHeaders = {
|
||||
"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) {
|
||||
|
||||
Reference in New Issue
Block a user