Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nftx/query

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nftx/query - npm Package Compare versions

Comparing version 3.7.5 to 3.7.6

dist/ts/__tests__/query.test.d.ts

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

## [3.7.6](https://github.com/NFTX-project/nftxjs/compare/v3.7.5...v3.7.6) (2024-09-02)
### Bug Fixes
* **@nftx/query:** allow both data and query params in post requests ([3db0246](https://github.com/NFTX-project/nftxjs/commit/3db02463b671a7d4d4892928ce243c52d2ffa35b))
## [3.7.5](https://github.com/NFTX-project/nftxjs/compare/v3.7.4...v3.7.5) (2024-08-23)

@@ -8,0 +19,0 @@

67

dist/cjs/query.js

@@ -27,7 +27,6 @@ 'use strict';

const getBody = ({
method,
sourceData,
stringify
}) => {
if (method === 'GET') {
if (sourceData == null) {
return undefined;

@@ -43,28 +42,29 @@ }

};
const getSearchParams = (method, sourceData, search) => {
const getSearchParams = ({
search,
query: sourceData
}) => {
let searchParams = new URLSearchParams(search);
if (method === 'GET') {
if (typeof sourceData === 'string' && sourceData) {
if (sourceData.startsWith('?')) {
searchParams = new URLSearchParams(sourceData);
if (typeof sourceData === 'string' && sourceData) {
if (sourceData.startsWith('?')) {
searchParams = new URLSearchParams(sourceData);
} else {
searchParams = new URLSearchParams('?' + sourceData);
}
} else if (sourceData) {
Object.entries(sourceData).forEach(([key, value]) => {
if (value == null) {
return;
}
if (Array.isArray(value)) {
value.forEach(v => {
if (v == null) {
return;
}
searchParams.append(key, v);
});
} else {
searchParams = new URLSearchParams('?' + sourceData);
searchParams.set(key, value);
}
} else if (sourceData) {
Object.entries(sourceData).forEach(([key, value]) => {
if (value == null) {
return;
}
if (Array.isArray(value)) {
value.forEach(v => {
if (v == null) {
return;
}
searchParams.append(key, v);
});
} else {
searchParams.set(key, value);
}
});
}
});
}

@@ -85,12 +85,15 @@ return searchParams;

url: baseUrl,
data: sourceData,
headers = {},
method = 'GET',
maxAttempts = 3,
attempt = 0,
attempt = 1,
fetch = globalFetch,
parse = JSON.parse,
stringify = JSON.stringify,
data: _data,
query: _query,
...requestInit
} = args;
const sourceData = method === 'GET' ? undefined : _data;
const sourceQuery = method === 'GET' ? _query || _data : _query;
if (fetch == null) {

@@ -109,5 +112,7 @@ throw new Error('Could not find fetch api. You may need to import a polyfill');

}
uri.search = getSearchParams(method, sourceData, uri.search).toString();
uri.search = getSearchParams({
query: sourceQuery,
search: uri.search
}).toString();
const body = getBody({
method,
sourceData,

@@ -139,7 +144,7 @@ stringify

if (!response.ok) {
const text = await response.text();
if (contentType?.includes('application/json')) {
const json = await response.json();
const json = parse(text);
throw new QueryError(response, response.status, json, `Error fetching ${uri}`);
} else {
const text = await response.text();
throw new QueryError(response, response.status, {}, text);

@@ -146,0 +151,0 @@ }

@@ -23,7 +23,6 @@ /** Processes a graphql string

const getBody = ({
method,
sourceData,
stringify
}) => {
if (method === 'GET') {
if (sourceData == null) {
return undefined;

@@ -39,28 +38,29 @@ }

};
const getSearchParams = (method, sourceData, search) => {
const getSearchParams = ({
search,
query: sourceData
}) => {
let searchParams = new URLSearchParams(search);
if (method === 'GET') {
if (typeof sourceData === 'string' && sourceData) {
if (sourceData.startsWith('?')) {
searchParams = new URLSearchParams(sourceData);
if (typeof sourceData === 'string' && sourceData) {
if (sourceData.startsWith('?')) {
searchParams = new URLSearchParams(sourceData);
} else {
searchParams = new URLSearchParams('?' + sourceData);
}
} else if (sourceData) {
Object.entries(sourceData).forEach(([key, value]) => {
if (value == null) {
return;
}
if (Array.isArray(value)) {
value.forEach(v => {
if (v == null) {
return;
}
searchParams.append(key, v);
});
} else {
searchParams = new URLSearchParams('?' + sourceData);
searchParams.set(key, value);
}
} else if (sourceData) {
Object.entries(sourceData).forEach(([key, value]) => {
if (value == null) {
return;
}
if (Array.isArray(value)) {
value.forEach(v => {
if (v == null) {
return;
}
searchParams.append(key, v);
});
} else {
searchParams.set(key, value);
}
});
}
});
}

@@ -81,12 +81,15 @@ return searchParams;

url: baseUrl,
data: sourceData,
headers = {},
method = 'GET',
maxAttempts = 3,
attempt = 0,
attempt = 1,
fetch = globalFetch,
parse = JSON.parse,
stringify = JSON.stringify,
data: _data,
query: _query,
...requestInit
} = args;
const sourceData = method === 'GET' ? undefined : _data;
const sourceQuery = method === 'GET' ? _query || _data : _query;
if (fetch == null) {

@@ -105,5 +108,7 @@ throw new Error('Could not find fetch api. You may need to import a polyfill');

}
uri.search = getSearchParams(method, sourceData, uri.search).toString();
uri.search = getSearchParams({
query: sourceQuery,
search: uri.search
}).toString();
const body = getBody({
method,
sourceData,

@@ -135,7 +140,7 @@ stringify

if (!response.ok) {
const text = await response.text();
if (contentType?.includes('application/json')) {
const json = await response.json();
const json = parse(text);
throw new QueryError(response, response.status, json, `Error fetching ${uri}`);
} else {
const text = await response.text();
throw new QueryError(response, response.status, {}, text);

@@ -142,0 +147,0 @@ }

@@ -12,2 +12,3 @@ type Fetch = typeof fetch;

url: string | string[];
query?: Record<string, any> | string;
data?: Record<string, any> | string;

@@ -14,0 +15,0 @@ headers?: Record<string, string>;

import { QueryBase } from './createQuery';
import sendQuery from './query';
type Query = typeof sendQuery;
type SendQueryArgs = Omit<Parameters<Query>[0], 'data'>;
declare function queryGraph<Q extends QueryBase<any, any>>(args: SendQueryArgs & {
type SendQueryArgs = Omit<Parameters<typeof sendQuery>[0], 'query'>;
type BaseArgs = Omit<SendQueryArgs, 'data'>;
type Query = <T>(args: Omit<Parameters<typeof sendQuery>[0], 'query'>) => Promise<T>;
declare function queryGraph<Q extends QueryBase<any, any>>(args: BaseArgs & {
url: string | string[];

@@ -10,3 +11,3 @@ query: Q;

}): Promise<Q['__r']>;
declare function queryGraph<T>(args: SendQueryArgs & {
declare function queryGraph<T>(args: BaseArgs & {
url: string | string[];

@@ -13,0 +14,0 @@ query: string;

{
"name": "@nftx/query",
"version": "3.7.5",
"version": "3.7.6",
"description": "",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/NFTX-project/nftxjs",

@@ -19,2 +19,3 @@ type Fetch = typeof fetch;

url: string | string[];
query?: Record<string, any> | string;
data?: Record<string, any> | string;

@@ -31,11 +32,9 @@ headers?: Record<string, string>;

const getBody = ({
method,
sourceData,
stringify,
}: {
method: string;
sourceData: unknown;
stringify: Stringify;
}) => {
if (method === 'GET') {
if (sourceData == null) {
return undefined;

@@ -52,33 +51,33 @@ }

const getSearchParams = (
method: string,
sourceData: unknown,
search: string
) => {
const getSearchParams = ({
search,
query: sourceData,
}: {
query: unknown;
search: string;
}) => {
let searchParams = new URLSearchParams(search);
if (method === 'GET') {
if (typeof sourceData === 'string' && sourceData) {
if (sourceData.startsWith('?')) {
searchParams = new URLSearchParams(sourceData);
if (typeof sourceData === 'string' && sourceData) {
if (sourceData.startsWith('?')) {
searchParams = new URLSearchParams(sourceData);
} else {
searchParams = new URLSearchParams('?' + sourceData);
}
} else if (sourceData) {
Object.entries(sourceData).forEach(([key, value]) => {
if (value == null) {
return;
}
if (Array.isArray(value)) {
value.forEach((v) => {
if (v == null) {
return;
}
searchParams.append(key, v);
});
} else {
searchParams = new URLSearchParams('?' + sourceData);
searchParams.set(key, value);
}
} else if (sourceData) {
Object.entries(sourceData).forEach(([key, value]) => {
if (value == null) {
return;
}
if (Array.isArray(value)) {
value.forEach((v) => {
if (v == null) {
return;
}
searchParams.append(key, v);
});
} else {
searchParams.set(key, value);
}
});
}
});
}

@@ -102,13 +101,17 @@

url: baseUrl,
data: sourceData,
headers = {},
method = 'GET',
maxAttempts = 3,
attempt = 0,
attempt = 1,
fetch = globalFetch,
parse = JSON.parse,
stringify = JSON.stringify,
data: _data,
query: _query,
...requestInit
} = args;
const sourceData = method === 'GET' ? undefined : _data;
const sourceQuery = method === 'GET' ? _query || _data : _query;
if (fetch == null) {

@@ -132,5 +135,8 @@ throw new Error(

uri.search = getSearchParams(method, sourceData, uri.search).toString();
uri.search = getSearchParams({
query: sourceQuery,
search: uri.search,
}).toString();
const body = getBody({ method, sourceData, stringify });
const body = getBody({ sourceData, stringify });

@@ -164,4 +170,5 @@ if (!headers['Content-Type'] && method !== 'GET') {

if (!response.ok) {
const text = await response.text();
if (contentType?.includes('application/json')) {
const json = await response.json();
const json = parse(text);
throw new QueryError(

@@ -174,3 +181,2 @@ response,

} else {
const text = await response.text();
throw new QueryError(response, response.status, {}, text);

@@ -177,0 +183,0 @@ }

@@ -5,6 +5,9 @@ import { QueryBase } from './createQuery';

type Query = typeof sendQuery;
const defaultSendQuery = sendQuery;
type SendQueryArgs = Omit<Parameters<Query>[0], 'data'>;
type SendQueryArgs = Omit<Parameters<typeof sendQuery>[0], 'query'>;
type BaseArgs = Omit<SendQueryArgs, 'data'>;
type Query = <T>(
args: Omit<Parameters<typeof sendQuery>[0], 'query'>
) => Promise<T>;

@@ -55,3 +58,3 @@ const interpolateQuery = (query: string, variables: Record<string, any>) => {

...rest
}: SendQueryArgs & { query: string; sendQuery: Query }) => {
}: BaseArgs & { query: string; sendQuery: Query }) => {
const { data, errors } = await sendQuery<{

@@ -75,3 +78,3 @@ errors: { message: string }[] & { message: string };

async function queryGraph<Q extends QueryBase<any, any>>(
args: SendQueryArgs & {
args: BaseArgs & {
url: string | string[];

@@ -83,3 +86,3 @@ query: Q;

async function queryGraph<T>(
args: SendQueryArgs & {
args: BaseArgs & {
url: string | string[];

@@ -97,3 +100,3 @@ query: string;

...rest
}: SendQueryArgs & {
}: BaseArgs & {
url: string | string[];

@@ -100,0 +103,0 @@ query: any;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc