Updates
This commit is contained in:
Vendored
+2
-22
@@ -1,19 +1,4 @@
|
||||
import { DSQLClientFetchHeader } from "../../package-shared/types";
|
||||
type FetchApiOptions<T extends {
|
||||
[k: string]: any;
|
||||
} = {
|
||||
[k: string]: any;
|
||||
}> = {
|
||||
method: "POST" | "GET" | "DELETE" | "PUT" | "PATCH" | "post" | "get" | "delete" | "put" | "patch";
|
||||
body?: T | string;
|
||||
headers?: DSQLClientFetchHeader;
|
||||
};
|
||||
export type FetchApiReturn = {
|
||||
success: boolean;
|
||||
payload: any;
|
||||
msg?: string;
|
||||
[key: string]: any;
|
||||
};
|
||||
import { DSQLFetchApiOptions } from "../../package-shared/types";
|
||||
/**
|
||||
* # Fetch API
|
||||
*/
|
||||
@@ -21,9 +6,4 @@ export default function fetchApi<T extends {
|
||||
[k: string]: any;
|
||||
} = {
|
||||
[k: string]: any;
|
||||
}, R extends any = any>(url: string, options?: FetchApiOptions<T>, csrf?: boolean,
|
||||
/**
|
||||
* Key to use to grab local Storage csrf value.
|
||||
*/
|
||||
localStorageCSRFKey?: string): Promise<R>;
|
||||
export {};
|
||||
}, R extends any = any>(url: string, options?: DSQLFetchApiOptions<T>): Promise<R>;
|
||||
|
||||
Vendored
+3
-9
@@ -17,20 +17,14 @@ const lodash_1 = __importDefault(require("lodash"));
|
||||
/**
|
||||
* # Fetch API
|
||||
*/
|
||||
function fetchApi(url, options, csrf,
|
||||
/**
|
||||
* Key to use to grab local Storage csrf value.
|
||||
*/
|
||||
localStorageCSRFKey) {
|
||||
function fetchApi(url, options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let data;
|
||||
const csrfKey = "x-dsql-csrf-key";
|
||||
const csrfValue = localStorage.getItem(localStorageCSRFKey || csrfKey);
|
||||
let finalHeaders = {
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
if (csrf && csrfValue) {
|
||||
finalHeaders[localStorageCSRFKey || csrfKey] = csrfValue;
|
||||
if ((options === null || options === void 0 ? void 0 : options.csrfKey) && options.csrfValue) {
|
||||
finalHeaders[options.csrfKey] = options.csrfValue;
|
||||
}
|
||||
if (typeof options === "string") {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user