From 27887ded410476a169614990aea318f327a138d4 Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Fri, 26 Dec 2025 13:16:11 +0100 Subject: [PATCH] Updates --- client/fetch/index.ts | 45 +++++----------------------- dist/client/fetch/index.d.ts | 24 ++------------- dist/client/fetch/index.js | 12 ++------ dist/package-shared/types/index.d.ts | 11 +++++++ package-shared/types/index.ts | 20 +++++++++++++ package.json | 2 +- 6 files changed, 44 insertions(+), 70 deletions(-) diff --git a/client/fetch/index.ts b/client/fetch/index.ts index c338ce0..670bd5c 100644 --- a/client/fetch/index.ts +++ b/client/fetch/index.ts @@ -1,28 +1,8 @@ import _ from "lodash"; -import { DSQLClientFetchHeader } from "../../package-shared/types"; - -type FetchApiOptions = { - 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 { + DSQLClientFetchHeader, + DSQLFetchApiOptions, +} from "../../package-shared/types"; /** * # Fetch API @@ -30,26 +10,15 @@ export type FetchApiReturn = { export default async function fetchApi< T extends { [k: string]: any } = { [k: string]: any }, R extends any = any ->( - url: string, - options?: FetchApiOptions, - csrf?: boolean, - /** - * Key to use to grab local Storage csrf value. - */ - localStorageCSRFKey?: string -): Promise { +>(url: string, options?: DSQLFetchApiOptions): Promise { let data; - const csrfKey = "x-dsql-csrf-key"; - const csrfValue = localStorage.getItem(localStorageCSRFKey || csrfKey); - let finalHeaders = { "Content-Type": "application/json", } as DSQLClientFetchHeader; - if (csrf && csrfValue) { - finalHeaders[localStorageCSRFKey || csrfKey] = csrfValue; + if (options?.csrfKey && options.csrfValue) { + finalHeaders[options.csrfKey] = options.csrfValue; } if (typeof options === "string") { diff --git a/dist/client/fetch/index.d.ts b/dist/client/fetch/index.d.ts index ba73f3a..5f9e7eb 100644 --- a/dist/client/fetch/index.d.ts +++ b/dist/client/fetch/index.d.ts @@ -1,19 +1,4 @@ -import { DSQLClientFetchHeader } from "../../package-shared/types"; -type FetchApiOptions = { - 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(url: string, options?: FetchApiOptions, csrf?: boolean, -/** - * Key to use to grab local Storage csrf value. - */ -localStorageCSRFKey?: string): Promise; -export {}; +}, R extends any = any>(url: string, options?: DSQLFetchApiOptions): Promise; diff --git a/dist/client/fetch/index.js b/dist/client/fetch/index.js index 1a68b22..28631df 100644 --- a/dist/client/fetch/index.js +++ b/dist/client/fetch/index.js @@ -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 { diff --git a/dist/package-shared/types/index.d.ts b/dist/package-shared/types/index.d.ts index 4f2c0b7..f79dd6c 100644 --- a/dist/package-shared/types/index.d.ts +++ b/dist/package-shared/types/index.d.ts @@ -2300,3 +2300,14 @@ export type ClientCrudFetchParams = { + method: "POST" | "GET" | "DELETE" | "PUT" | "PATCH" | "post" | "get" | "delete" | "put" | "patch"; + body?: T | string; + headers?: DSQLClientFetchHeader; + csrfValue?: string; + csrfKey?: string; +}; diff --git a/package-shared/types/index.ts b/package-shared/types/index.ts index 70c3e7c..a8d08d2 100644 --- a/package-shared/types/index.ts +++ b/package-shared/types/index.ts @@ -2961,3 +2961,23 @@ export type ClientCrudFetchParams< apiOrigin?: string; headers?: DSQLClientFetchHeader; }; + +export type DSQLFetchApiOptions< + T extends { [k: string]: any } = { [k: string]: any } +> = { + method: + | "POST" + | "GET" + | "DELETE" + | "PUT" + | "PATCH" + | "post" + | "get" + | "delete" + | "put" + | "patch"; + body?: T | string; + headers?: DSQLClientFetchHeader; + csrfValue?: string; + csrfKey?: string; +}; diff --git a/package.json b/package.json index 2e0efbe..7495c93 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/datasquirel", - "version": "5.6.3", + "version": "5.6.4", "description": "Cloud-based SQL data management tool", "main": "dist/index.js", "bin": {