Updates
This commit is contained in:
parent
f95cf21ffd
commit
5caa604b8f
@ -19,6 +19,7 @@ export default async function clientCrudFetch<
|
|||||||
targetId,
|
targetId,
|
||||||
method = "GET",
|
method = "GET",
|
||||||
apiOrigin,
|
apiOrigin,
|
||||||
|
headers,
|
||||||
}: ClientCrudFetchParams<T, P>) {
|
}: ClientCrudFetchParams<T, P>) {
|
||||||
try {
|
try {
|
||||||
let pathname = basePath || ``;
|
let pathname = basePath || ``;
|
||||||
@ -43,6 +44,7 @@ export default async function clientCrudFetch<
|
|||||||
>(pathname, {
|
>(pathname, {
|
||||||
method,
|
method,
|
||||||
body,
|
body,
|
||||||
|
headers,
|
||||||
});
|
});
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
import { DSQLClientFetchHeader } from "../../package-shared/types";
|
||||||
|
|
||||||
type FetchApiOptions<T extends { [k: string]: any } = { [k: string]: any }> = {
|
type FetchApiOptions<T extends { [k: string]: any } = { [k: string]: any }> = {
|
||||||
method:
|
method:
|
||||||
@ -13,11 +14,7 @@ type FetchApiOptions<T extends { [k: string]: any } = { [k: string]: any }> = {
|
|||||||
| "put"
|
| "put"
|
||||||
| "patch";
|
| "patch";
|
||||||
body?: T | string;
|
body?: T | string;
|
||||||
headers?: FetchHeader;
|
headers?: DSQLClientFetchHeader;
|
||||||
};
|
|
||||||
|
|
||||||
type FetchHeader = HeadersInit & {
|
|
||||||
[key: string]: string | null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FetchApiReturn = {
|
export type FetchApiReturn = {
|
||||||
@ -40,12 +37,7 @@ export default async function fetchApi<
|
|||||||
/**
|
/**
|
||||||
* Key to use to grab local Storage csrf value.
|
* Key to use to grab local Storage csrf value.
|
||||||
*/
|
*/
|
||||||
localStorageCSRFKey?: string,
|
localStorageCSRFKey?: string
|
||||||
/**
|
|
||||||
* Key with which to set the request header csrf
|
|
||||||
* value
|
|
||||||
*/
|
|
||||||
csrfHeaderKey?: string
|
|
||||||
): Promise<R> {
|
): Promise<R> {
|
||||||
let data;
|
let data;
|
||||||
|
|
||||||
@ -54,7 +46,7 @@ export default async function fetchApi<
|
|||||||
|
|
||||||
let finalHeaders = {
|
let finalHeaders = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
} as FetchHeader;
|
} as DSQLClientFetchHeader;
|
||||||
|
|
||||||
if (csrf && csrfValue) {
|
if (csrf && csrfValue) {
|
||||||
finalHeaders[localStorageCSRFKey || csrfKey] = csrfValue;
|
finalHeaders[localStorageCSRFKey || csrfKey] = csrfValue;
|
||||||
|
|||||||
2
dist/client/crud-fetch/index.d.ts
vendored
2
dist/client/crud-fetch/index.d.ts
vendored
@ -7,4 +7,4 @@ export default function clientCrudFetch<T extends {
|
|||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
} = {
|
} = {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}>({ table, basePath, body, query, targetId, method, apiOrigin, }: ClientCrudFetchParams<T, P>): Promise<APIResponseObject<PostInsertReturn | R[]>>;
|
}>({ table, basePath, body, query, targetId, method, apiOrigin, headers, }: ClientCrudFetchParams<T, P>): Promise<APIResponseObject<PostInsertReturn | R[]>>;
|
||||||
|
|||||||
3
dist/client/crud-fetch/index.js
vendored
3
dist/client/crud-fetch/index.js
vendored
@ -17,7 +17,7 @@ const path_1 = __importDefault(require("path"));
|
|||||||
const serialize_query_1 = __importDefault(require("../../package-shared/utils/serialize-query"));
|
const serialize_query_1 = __importDefault(require("../../package-shared/utils/serialize-query"));
|
||||||
const fetch_1 = __importDefault(require("../fetch"));
|
const fetch_1 = __importDefault(require("../fetch"));
|
||||||
function clientCrudFetch(_a) {
|
function clientCrudFetch(_a) {
|
||||||
return __awaiter(this, arguments, void 0, function* ({ table, basePath, body, query, targetId, method = "GET", apiOrigin, }) {
|
return __awaiter(this, arguments, void 0, function* ({ table, basePath, body, query, targetId, method = "GET", apiOrigin, headers, }) {
|
||||||
try {
|
try {
|
||||||
let pathname = basePath || ``;
|
let pathname = basePath || ``;
|
||||||
pathname = path_1.default.join(pathname, String(table));
|
pathname = path_1.default.join(pathname, String(table));
|
||||||
@ -33,6 +33,7 @@ function clientCrudFetch(_a) {
|
|||||||
const res = yield (0, fetch_1.default)(pathname, {
|
const res = yield (0, fetch_1.default)(pathname, {
|
||||||
method,
|
method,
|
||||||
body,
|
body,
|
||||||
|
headers,
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
13
dist/client/fetch/index.d.ts
vendored
13
dist/client/fetch/index.d.ts
vendored
@ -1,3 +1,4 @@
|
|||||||
|
import { DSQLClientFetchHeader } from "../../package-shared/types";
|
||||||
type FetchApiOptions<T extends {
|
type FetchApiOptions<T extends {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
} = {
|
} = {
|
||||||
@ -5,10 +6,7 @@ type FetchApiOptions<T extends {
|
|||||||
}> = {
|
}> = {
|
||||||
method: "POST" | "GET" | "DELETE" | "PUT" | "PATCH" | "post" | "get" | "delete" | "put" | "patch";
|
method: "POST" | "GET" | "DELETE" | "PUT" | "PATCH" | "post" | "get" | "delete" | "put" | "patch";
|
||||||
body?: T | string;
|
body?: T | string;
|
||||||
headers?: FetchHeader;
|
headers?: DSQLClientFetchHeader;
|
||||||
};
|
|
||||||
type FetchHeader = HeadersInit & {
|
|
||||||
[key: string]: string | null;
|
|
||||||
};
|
};
|
||||||
export type FetchApiReturn = {
|
export type FetchApiReturn = {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
@ -27,10 +25,5 @@ export default function fetchApi<T extends {
|
|||||||
/**
|
/**
|
||||||
* Key to use to grab local Storage csrf value.
|
* Key to use to grab local Storage csrf value.
|
||||||
*/
|
*/
|
||||||
localStorageCSRFKey?: string,
|
localStorageCSRFKey?: string): Promise<R>;
|
||||||
/**
|
|
||||||
* Key with which to set the request header csrf
|
|
||||||
* value
|
|
||||||
*/
|
|
||||||
csrfHeaderKey?: string): Promise<R>;
|
|
||||||
export {};
|
export {};
|
||||||
|
|||||||
7
dist/client/fetch/index.js
vendored
7
dist/client/fetch/index.js
vendored
@ -21,12 +21,7 @@ function fetchApi(url, options, csrf,
|
|||||||
/**
|
/**
|
||||||
* Key to use to grab local Storage csrf value.
|
* Key to use to grab local Storage csrf value.
|
||||||
*/
|
*/
|
||||||
localStorageCSRFKey,
|
localStorageCSRFKey) {
|
||||||
/**
|
|
||||||
* Key with which to set the request header csrf
|
|
||||||
* value
|
|
||||||
*/
|
|
||||||
csrfHeaderKey) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let data;
|
let data;
|
||||||
const csrfKey = "x-dsql-csrf-key";
|
const csrfKey = "x-dsql-csrf-key";
|
||||||
|
|||||||
6
dist/package-shared/types/index.d.ts
vendored
6
dist/package-shared/types/index.d.ts
vendored
@ -792,12 +792,12 @@ export type FetchApiFn = (url: string, options?: FetchApiOptions, csrf?: boolean
|
|||||||
export type FetchApiOptions = RequestInit & {
|
export type FetchApiOptions = RequestInit & {
|
||||||
method: (typeof DataCrudRequestMethods)[number] | (typeof DataCrudRequestMethodsLowerCase)[number];
|
method: (typeof DataCrudRequestMethods)[number] | (typeof DataCrudRequestMethodsLowerCase)[number];
|
||||||
body?: object | string;
|
body?: object | string;
|
||||||
headers?: FetchHeader;
|
headers?: DSQLClientFetchHeader;
|
||||||
query?: {
|
query?: {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
type FetchHeader = HeadersInit & {
|
export type DSQLClientFetchHeader = HeadersInit & {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
export type FetchApiReturn = {
|
export type FetchApiReturn = {
|
||||||
@ -2298,5 +2298,5 @@ export type ClientCrudFetchParams<T extends {
|
|||||||
basePath?: string;
|
basePath?: string;
|
||||||
targetId?: string | number | null;
|
targetId?: string | number | null;
|
||||||
apiOrigin?: string;
|
apiOrigin?: string;
|
||||||
|
headers?: DSQLClientFetchHeader;
|
||||||
};
|
};
|
||||||
export {};
|
|
||||||
|
|||||||
@ -953,11 +953,11 @@ export type FetchApiOptions = RequestInit & {
|
|||||||
| (typeof DataCrudRequestMethods)[number]
|
| (typeof DataCrudRequestMethods)[number]
|
||||||
| (typeof DataCrudRequestMethodsLowerCase)[number];
|
| (typeof DataCrudRequestMethodsLowerCase)[number];
|
||||||
body?: object | string;
|
body?: object | string;
|
||||||
headers?: FetchHeader;
|
headers?: DSQLClientFetchHeader;
|
||||||
query?: { [key: string]: any };
|
query?: { [key: string]: any };
|
||||||
};
|
};
|
||||||
|
|
||||||
type FetchHeader = HeadersInit & {
|
export type DSQLClientFetchHeader = HeadersInit & {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2959,4 +2959,5 @@ export type ClientCrudFetchParams<
|
|||||||
basePath?: string;
|
basePath?: string;
|
||||||
targetId?: string | number | null;
|
targetId?: string | number | null;
|
||||||
apiOrigin?: string;
|
apiOrigin?: string;
|
||||||
|
headers?: DSQLClientFetchHeader;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "5.6.1",
|
"version": "5.6.2",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user