You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

jsql-api

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsql-api - npm Package Compare versions

Comparing version

to
0.0.56

dist/src/types/http/method.d.ts

10

dist/src/functions/fetchJsqlApi.d.ts

@@ -1,7 +0,7 @@

import * as axios from "axios";
import { IQuery } from "../types/abstract/IQuery";
import { IEntity } from "../types/abstract/IEntity";
import { Method } from "../types/http/method";
interface IFetchSqlApiProps<Query extends IQuery> {
path: string;
method: axios.Method;
method: Method;
body?: Query;

@@ -29,3 +29,7 @@ params: {

*/
export declare function fetchJsqlApi<Query extends IQuery, Table extends IEntity = any>({ path, method, body, params, headers, isLocal }: IFetchSqlApiProps<Query>): Promise<axios.AxiosResponse<Table, any>>;
export declare function fetchJsqlApi<Query extends IQuery, Table extends IEntity = any>({ path, method, body, params, headers, isLocal }: IFetchSqlApiProps<Query>): Promise<{
data: Table;
status: number;
headers: Headers;
}>;
export {};

@@ -1,3 +0,1 @@

import * as axios from "axios";
import { isAxiosError } from "axios";
/**

@@ -13,24 +11,35 @@ * Make a query to the database

*/
export async function fetchJsqlApi({ path, method = 'GET', body, params, headers = {
export async function fetchJsqlApi({ path, method = 'get', body, params, headers = {
'Content-Type': 'application/json'
}, isLocal }) {
const config = {
const baseUrl = `http${isLocal ? '' : 's'}://${isLocal ? `localhost:${isLocal}` : 'jsql-api'}/${path}`;
const url = new URL(baseUrl);
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined) {
url.searchParams.append(key, value);
}
});
const fetchOptions = {
method,
url: `http${isLocal ? '' : 's'}://${isLocal ? `localhost:${isLocal}` : 'jsql-api'}/${path}`,
headers: headers,
params: params,
data: body
headers,
body: method !== 'get' && body ? JSON.stringify(body) : undefined
};
try {
const response = await axios.default(config);
return response;
const response = await fetch(url.toString(), fetchOptions);
if (!response.ok) {
const errorBody = await response.text();
console.error("Jsql Api Error:", errorBody);
throw new Error(`Error ${response.status}: ${response.statusText}`);
}
const data = await response.json();
return {
data,
status: response.status,
headers: response.headers
};
}
catch (error) {
if (isAxiosError(error)) {
console.error("Jsql Api Error:", error.response?.data || error.message);
throw error;
}
console.error('Jsql Api Unknown Error:', error);
console.error("Jsql Api Unknown Error:", error.message || error);
throw error;
}
}
{
"name": "jsql-api",
"version": "0.0.55",
"version": "0.0.56",
"main": "dist/index.d.ts",

@@ -25,3 +25,2 @@ "types": "dist/index.d.ts",

"dependencies": {
"axios": "^1.9.0",
"typescript": "^5.8.3"

@@ -28,0 +27,0 @@ },