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

@zoralabs/nft-hooks

Package Overview
Dependencies
Maintainers
22
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zoralabs/nft-hooks - npm Package Compare versions

Comparing version 1.1.4 to 1.1.5

4

dist/backends/ether-actor/EtherActorDataSource.d.ts

@@ -5,3 +5,3 @@ import DataLoader from 'dataloader';

import { NFTIdentifier, NFTObject } from '../../types/NFTInterface';
import { NFTQuery } from '../../types/NFTQuery';
import { NFTQuery, NFTQueryResult } from '../../types/NFTQuery';
export declare class EtherActorDataSource implements EtherActorDataInterface {

@@ -17,3 +17,3 @@ nftsLoader: DataLoader<string, EtherActorServerResponse | Error>;

fetchNFTsEtherActor: (nftAddressesAndTokens: readonly string[]) => Promise<(Error | EtherActorServerResponse)[]>;
queryNFTs(_: NFTQuery): Promise<Error | EtherActorServerResponse[]>;
queryNFTs(_: NFTQuery): Promise<NFTQueryResult>;
}
import DataLoader from 'dataloader';
import { NFTQuery } from '../../types/NFTQuery';
import { NFTQuery, NFTQueryResult } from '../../types/NFTQuery';
import { NetworkIDs } from '../../constants/networks';

@@ -17,3 +17,3 @@ import { NFTIdentifier, NFTObject } from '../../types/NFTInterface';

fetchNFTsOpensea: (nftAddressesAndTokens: readonly string[]) => Promise<(Error | OpenseaAsset)[]>;
queryNFTs(_: NFTQuery): Promise<Error | OpenseaAsset[]>;
queryNFTs(_: NFTQuery): Promise<NFTQueryResult>;
}
import { NetworkIDs, NFTObject } from '../..';
import { SharedTokenResponse, ZDKDataInterface } from './ZDKDataInterface';
import { ZDK } from '@zoralabs/zdk/dist/index';
import { Chain, MarketType as ZDKMarketType, Network } from '@zoralabs/zdk/dist/queries/queries-sdk';
import { MarketType as ZDKMarketType, Network } from '@zoralabs/zdk/dist/queries/queries-sdk';
import { NFTQuery } from '../../types/NFTQuery';
import { NFTIdentifier } from '../../types';
import { NotFoundError } from '../../fetcher/ErrorUtils';
import DataLoader from 'dataloader';
export { QuerySort, MarketType, ViewType, SortDirection, NFTQuery, } from '../../types/NFTQuery';

@@ -11,8 +13,8 @@ export declare function transformNFTZDK(tokenResponse: SharedTokenResponse, object?: NFTObject): NFTObject;

zdk: ZDK;
nftDataLoader: DataLoader<NFTIdentifier, SharedTokenResponse>;
constructor(chainId: NetworkIDs, endpoint?: string);
canLoadNFT(_: NFTIdentifier): boolean;
transformNFT(token: SharedTokenResponse, object?: NFTObject): NFTObject;
loadNFT: ({ contract, id, }: NFTIdentifier) => Promise<SharedTokenResponse | Error>;
loadNFTs: (nfts: readonly NFTIdentifier[]) => Promise<(Error | SharedTokenResponse)[]>;
queryNFTs: (query: NFTQuery) => Promise<{
fetchNFTs: (mediaIds: readonly NFTIdentifier[]) => Promise<({
__typename: "TokenWithMarketsSummary";

@@ -59,3 +61,3 @@ marketsSummary: {

__typename?: "NetworkInfo" | undefined;
chain: Chain;
chain: import("@zoralabs/zdk/dist/index").ZDKChain;
network: Network;

@@ -407,3 +409,3 @@ };

toAddress: string;
fee: {
price: {
__typename?: "PriceAtTime" | undefined;

@@ -852,3 +854,11 @@ blockNumber: number;

}[];
}[]>;
} | NotFoundError)[]>;
loadNFT: ({ contract, id, }: NFTIdentifier) => Promise<SharedTokenResponse | Error>;
queryNFTs: (query: NFTQuery) => Promise<{
pageInfo: {
limit?: number | undefined;
last?: string | undefined;
};
results: NFTObject[];
}>;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZDKDataSource = exports.transformNFTZDK = exports.SortDirection = exports.ViewType = exports.MarketType = void 0;
const tslib_1 = require("tslib");
const index_1 = require("@zoralabs/zdk/dist/index");

@@ -14,2 +15,3 @@ const queries_sdk_1 = require("@zoralabs/zdk/dist/queries/queries-sdk");

const getChainFromNetwork_1 = require("./utils/getChainFromNetwork");
const dataloader_1 = tslib_1.__importDefault(require("dataloader"));
// this enums are params for useNFTQuery()

@@ -140,26 +142,30 @@ var NFTQuery_2 = require("../../types/NFTQuery");

constructor(chainId, endpoint) {
this.loadNFT = async ({ contract, id, }) => {
const response = await this.zdk.token({
network: { network: queries_sdk_1.Network.Ethereum, chain: queries_sdk_1.Chain.Mainnet },
this.loadNFTs = async (nfts) => {
return await this.nftDataLoader.loadMany(nfts);
};
this.fetchNFTs = async (mediaIds) => {
const response = await this.zdk.tokens({
includeFullDetails: true,
token: {
tokenId: id,
address: contract,
where: {
tokens: mediaIds.map((mediaId) => {
return {
tokenId: mediaId.id,
address: mediaId.contract,
};
}),
},
});
if (!response.token) {
throw new ErrorUtils_1.NotFoundError('Cannot find token entity');
}
return response.token;
return mediaIds.map((key) => {
return (response.tokens.nodes.find((token) => token.token.tokenId === key.id &&
token.token.collectionAddress === key.contract) || new ErrorUtils_1.NotFoundError('Missing record'));
});
};
this.loadNFTs = async (nfts) => {
const tokens = await this.zdk.tokens({
where: {
tokens: nfts.map((item) => ({
address: item.contract,
tokenId: item.id,
})),
this.loadNFT = async ({ contract, id, }) => {
const nfts = await this.loadNFTs([
{
contract,
id,
},
});
return tokens.tokens.nodes;
]);
return nfts[0];
};

@@ -209,2 +215,11 @@ this.queryNFTs = async (query) => {

}
let pagination = {};
if (query.pagination) {
if (query.pagination.limit) {
pagination.limit = query.pagination.limit;
}
if (query.pagination.after) {
pagination.after = query.pagination.after;
}
}
const results = await this.zdk.tokens({

@@ -215,9 +230,19 @@ where: marketsQuery,

includeFullDetails: true,
pagination,
includeSalesHistory: !!query.additional.includeSaleHistory,
});
let paginationResult = {};
if (results.tokens.nodes) {
return results.tokens.nodes;
if (results.tokens.nodes.length) {
paginationResult.last = results.tokens.pageInfo.endCursor || undefined;
paginationResult.limit = results.tokens.pageInfo.limit;
}
return {
pageInfo: paginationResult,
results: results.tokens.nodes.map((nft) => this.transformNFT(nft)),
};
}
return [];
return { results: [], pageInfo: paginationResult };
};
this.nftDataLoader = new dataloader_1.default(this.fetchNFTs);
this.zdk = new index_1.ZDK(endpoint, [

@@ -224,0 +249,0 @@ { network: queries_sdk_1.Network.Ethereum, chain: (0, getChainFromNetwork_1.getChainFromNetwork)(chainId) },

@@ -8,3 +8,3 @@ import DataLoader from 'dataloader';

import { GenericMediaInterface } from '../generic-media/GenericMediaInterface';
import { NFTQuery } from '../../types/NFTQuery';
import { NFTQuery, NFTQueryResult } from '../../types/NFTQuery';
export declare function transformNFTZoraGraph(mediaContractAddress: string, { asset, metadata }: {

@@ -123,92 +123,3 @@ asset: NftMediaFullDataFragment;

})[]>;
queryNFTs: ({ query, sort, pagination, additional }: NFTQuery) => Promise<{
asset: {
__typename?: "Media" | undefined;
} & {
__typename?: "Media" | undefined;
} & {
currentBids?: import("./zora-graph-types").Maybe<({
__typename?: "Bid" | undefined;
} & {
__typename?: "Bid" | undefined;
} & Pick<import("./zora-graph-types").Bid, "id" | "amount" | "createdAtTimestamp" | "transactionHash" | "createdAtBlockNumber"> & {
bidder: {
__typename?: "User" | undefined;
} & Pick<import("./zora-graph-types").User, "id">;
currency: {
__typename?: "Currency" | undefined;
} & {
__typename?: "Currency" | undefined;
} & Pick<import("./zora-graph-types").Currency, "symbol" | "id" | "name" | "decimals">;
})[]> | undefined;
transfers?: import("./zora-graph-types").Maybe<({
__typename?: "Transfer" | undefined;
} & {
__typename?: "Transfer" | undefined;
} & Pick<import("./zora-graph-types").Transfer, "id" | "createdAtTimestamp" | "transactionHash" | "createdAtBlockNumber"> & {
from: {
__typename?: "User" | undefined;
} & Pick<import("./zora-graph-types").User, "id">;
to: {
__typename?: "User" | undefined;
} & Pick<import("./zora-graph-types").User, "id">;
})[]> | undefined;
reserveAuctions?: import("./zora-graph-types").Maybe<({
__typename?: "ReserveAuction" | undefined;
} & {
__typename?: "ReserveAuction" | undefined;
} & Pick<import("./zora-graph-types").ReserveAuction, "id" | "status" | "token" | "tokenId" | "duration" | "reservePrice" | "firstBidTime" | "createdAtTimestamp" | "transactionHash" | "createdAtBlockNumber" | "approved" | "tokenContract" | "approvedTimestamp" | "curatorFeePercentage" | "expectedEndTimestamp" | "finalizedAtTimestamp"> & {
curator: {
__typename?: "User" | undefined;
} & Pick<import("./zora-graph-types").User, "id">;
tokenOwner: {
__typename?: "User" | undefined;
} & Pick<import("./zora-graph-types").User, "id">;
auctionCurrency: {
__typename?: "Currency" | undefined;
} & {
__typename?: "Currency" | undefined;
} & Pick<import("./zora-graph-types").Currency, "symbol" | "id" | "name" | "decimals">;
currentBid?: import("./zora-graph-types").Maybe<{
__typename?: "ReserveAuctionBid" | undefined;
} & {
__typename?: "ReserveAuctionBid" | undefined;
} & Pick<import("./zora-graph-types").ReserveAuctionBid, "amount" | "createdAtTimestamp" | "transactionHash" | "bidType"> & {
bidder: {
__typename?: "User" | undefined;
} & Pick<import("./zora-graph-types").User, "id">;
}> | undefined;
previousBids?: import("./zora-graph-types").Maybe<({
__typename?: "InactiveReserveAuctionBid" | undefined;
} & {
__typename?: "InactiveReserveAuctionBid" | undefined;
} & Pick<import("./zora-graph-types").InactiveReserveAuctionBid, "id" | "amount" | "createdAtTimestamp" | "transactionHash" | "bidType" | "bidInactivatedAtTimestamp" | "bidInactivatedAtBlockNumber"> & {
bidder: {
__typename?: "User" | undefined;
} & Pick<import("./zora-graph-types").User, "id">;
})[]> | undefined;
})[]> | undefined;
} & {
__typename?: "Media" | undefined;
} & Pick<import("./zora-graph-types").Media, "id" | "metadataURI" | "contentURI" | "createdAtTimestamp" | "creatorBidShare" | "ownerBidShare" | "metadataHash" | "contentHash"> & {
owner: {
__typename?: "User" | undefined;
} & Pick<import("./zora-graph-types").User, "id">;
creator: {
__typename?: "User" | undefined;
} & Pick<import("./zora-graph-types").User, "id">;
currentAsk?: import("./zora-graph-types").Maybe<{
__typename?: "Ask" | undefined;
} & {
__typename?: "Ask" | undefined;
} & Pick<import("./zora-graph-types").Ask, "id" | "amount" | "createdAtTimestamp"> & {
currency: {
__typename?: "Currency" | undefined;
} & {
__typename?: "Currency" | undefined;
} & Pick<import("./zora-graph-types").Currency, "symbol" | "id" | "name" | "decimals">;
}> | undefined;
};
metadata: any;
}[]>;
queryNFTs: ({ query, sort, pagination, additional, }: NFTQuery) => Promise<NFTQueryResult>;
/**

@@ -215,0 +126,0 @@ * Un-batched fetch function to fetch a group of ZNFT data

@@ -90,3 +90,3 @@ "use strict";

};
this.queryNFTs = async ({ query, sort, pagination, additional }) => {
this.queryNFTs = async ({ query, sort, pagination, additional, }) => {
const userQuery = {};

@@ -130,4 +130,4 @@ if (query.minters) {

let limit = 100;
if (pagination === null || pagination === void 0 ? void 0 : pagination.offset) {
offset = pagination === null || pagination === void 0 ? void 0 : pagination.offset;
if (pagination === null || pagination === void 0 ? void 0 : pagination.after) {
offset = parseInt(pagination === null || pagination === void 0 ? void 0 : pagination.after, 10);
}

@@ -150,6 +150,11 @@ if (pagination === null || pagination === void 0 ? void 0 : pagination.limit) {

: medias.map(() => { });
return medias.map((_, indx) => ({
asset: response.medias[indx],
metadata: metadatas[indx],
}));
return {
results: medias
.map((_, indx) => ({
asset: response.medias[indx],
metadata: metadatas[indx],
}))
.map((nft) => this.transformNFT(nft)),
pageInfo: { limit: limit, last: (limit + medias.length).toString() }
};
};

@@ -156,0 +161,0 @@ this.endpoint = endpoint;

@@ -86,3 +86,9 @@ import DataLoader from 'dataloader';

}))[]>;
queryNFTs: ({ query, sort, pagination, additional }: NFTQuery) => Promise<IndexerTokenWithAuctionFragment[]>;
queryNFTs: ({ query, sort, pagination, additional }: NFTQuery) => Promise<{
pageInfo: {
limit?: number | undefined;
last?: string | undefined;
};
results: NFTObject[];
}>;
/**

@@ -89,0 +95,0 @@ * Un-batched fetch function to fetch a group of NFT data from the zora indexer

@@ -436,4 +436,4 @@ "use strict";

let limit = 100;
if (pagination === null || pagination === void 0 ? void 0 : pagination.offset) {
offset = pagination.offset;
if (pagination === null || pagination === void 0 ? void 0 : pagination.after) {
offset = parseInt(pagination.after, 10);
}

@@ -450,3 +450,9 @@ if (pagination === null || pagination === void 0 ? void 0 : pagination.limit) {

const tokens = result.Token;
return tokens;
let pageInfo = {};
pageInfo.last = (offset + limit).toString();
pageInfo.limit = limit;
return {
pageInfo,
results: tokens.map((nft) => this.transformNFT(nft)),
};
};

@@ -473,5 +479,3 @@ /**

const tokens = response.Token;
return tokens.map((result) => this.transformNFT(result, {
rawData: {},
}));
return tokens.map((result) => this.transformNFT(result));
};

@@ -514,3 +518,3 @@ this.nftGraphDataLoader = new dataloader_1.default(this.fetchNFTs);

const tokens = response.Token;
return tokens.map((token) => this.transformNFT(token, { rawData: {} }));
return tokens.map((token) => this.transformNFT(token));
}

@@ -517,0 +521,0 @@ getClient() {

import { SWRConfiguration } from 'swr';
import { NFTObject } from '../types';
import { NFTQuery } from '../types/NFTQuery';
import { NFTQuery, NFTQueryResult } from '../types/NFTQuery';
export declare type useNFTQueryType = {
data?: NFTObject[];
data?: NFTQueryResult;
error: Error;

@@ -15,2 +14,2 @@ };

*/
export declare function useNFTQuery(query: NFTQuery, options: SWRConfiguration<NFTObject[]>): useNFTQueryType;
export declare function useNFTQuery(query: NFTQuery, options: SWRConfiguration<NFTQueryResult>): useNFTQueryType;
import { NetworkIDs } from 'src';
import { NFTObject } from '../types/NFTInterface';
import { NFTQuery } from '../types/NFTQuery';
import { NFTQuery, NFTQueryResult } from '../types/NFTQuery';
declare type FetchInfo = {

@@ -12,3 +12,3 @@ contract: string;

abstract fetchNFT(contract: string, id: string): Promise<NFTObject>;
abstract queryNFTs(query: NFTQuery): Promise<NFTObject[]>;
abstract queryNFTs(query: NFTQuery): Promise<NFTQueryResult>;
hasSecondaryData: (_: FetchInfo) => boolean;

@@ -15,0 +15,0 @@ fetchSecondaryData(contract: string, id: string, _?: NFTObject): Promise<NFTObject>;

@@ -12,3 +12,3 @@ import { NFTQuery } from '../types/NFTQuery';

fetchSecondaryData: (contract: string, id: string) => Promise<import("..").NFTObject>;
queryNFTs: (query: NFTQuery) => Promise<import("..").NFTObject[]>;
queryNFTs: (query: NFTQuery) => Promise<import("../types/NFTQuery").NFTQueryResult>;
}

@@ -14,3 +14,3 @@ "use strict";

}
return this.openseaBackend.transformNFT(openseaNFT, {});
return this.openseaBackend.transformNFT(openseaNFT);
};

@@ -22,7 +22,3 @@ this.hasSecondaryData = () => true;

this.queryNFTs = async (query) => {
const response = await this.openseaBackend.queryNFTs(query);
if (response instanceof Error) {
throw response;
}
return response.map((item) => this.openseaBackend.transformNFT(item, { rawData: {} }));
return await this.openseaBackend.queryNFTs(query);
};

@@ -29,0 +25,0 @@ this.auctionBackend = new backends_1.GraphAuctionDataSource(networkId);

import { NetworkIDs, NFTObject } from '..';
import { NFTStrategy } from '.';
import { ZDKDataSource } from '../backends';
import { NFTQuery } from '../types/NFTQuery';
import { NFTQuery, NFTQueryResult } from '../types/NFTQuery';
export declare class ZDKFetchStrategy extends NFTStrategy {

@@ -9,3 +9,3 @@ source: ZDKDataSource;

fetchNFT: (contract: string, id: string) => Promise<NFTObject>;
queryNFTs: (_: NFTQuery) => Promise<NFTObject[]>;
queryNFTs: (query: NFTQuery) => Promise<NFTQueryResult>;
}

@@ -14,6 +14,6 @@ "use strict";

}
return this.source.transformNFT(result, { rawData: {} });
return this.source.transformNFT(result);
};
this.queryNFTs = async (_) => {
throw new Error('Not implemented');
this.queryNFTs = async (query) => {
return await this.source.queryNFTs(query);
};

@@ -20,0 +20,0 @@ this.source = new backends_1.ZDKDataSource(networkId, endpoint);

import { EtherActorDataSource, GraphAuctionDataSource } from '../backends';
import { NetworkIDs } from '../constants/networks';
import { NFTStrategy } from './NFTStrategy';
import { NFTObject } from '../types/NFTInterface';
import { NFTQuery } from '../types/NFTQuery';
import { NFTQuery, NFTQueryResult } from '../types/NFTQuery';
export declare class ZoraGraphEtherActorStrategy extends NFTStrategy {

@@ -10,6 +9,6 @@ graphAuctionData: GraphAuctionDataSource;

constructor(networkId: NetworkIDs, timeout?: number);
fetchNFT: (contract: string, id: string) => Promise<NFTObject>;
fetchNFT: (contract: string, id: string) => Promise<import("..").NFTObject>;
hasSecondaryData: () => boolean;
fetchMarket: (contract: string, id: string) => Promise<NFTObject>;
queryNFTs: (_: NFTQuery) => Promise<NFTObject[]>;
fetchMarket: (contract: string, id: string) => Promise<import("..").NFTObject>;
queryNFTs: (_: NFTQuery) => Promise<NFTQueryResult>;
}
import { ZoraGraphDataInterface } from '../backends';
import { NetworkIDs } from '../constants/networks';
import { NFTQuery } from '../types/NFTQuery';
import { NFTObject } from '../types/NFTInterface';
import { NFTQuery, NFTQueryResult } from '../types/NFTQuery';
import { NFTStrategy } from './NFTStrategy';

@@ -9,4 +8,4 @@ export declare class ZoraGraphStrategy extends NFTStrategy {

constructor(networkId: NetworkIDs, timeout?: number, mediaContractAddress?: string);
fetchNFT: (contract: string, id: string) => Promise<NFTObject>;
queryNFTs: (query: NFTQuery) => Promise<NFTObject[]>;
fetchNFT: (contract: string, id: string) => Promise<import("..").NFTObject>;
queryNFTs: (query: NFTQuery) => Promise<NFTQueryResult>;
}

@@ -14,10 +14,6 @@ "use strict";

}
return this.graphDataSource.transformNFT(response, {});
return this.graphDataSource.transformNFT(response);
};
this.queryNFTs = async (query) => {
const response = await this.graphDataSource.queryNFTs(query);
if (response instanceof Error) {
throw response;
}
return response.map((object) => this.graphDataSource.transformNFT(object, { rawData: {} }));
return await this.graphDataSource.queryNFTs(query);
};

@@ -24,0 +20,0 @@ this.graphDataSource = new backends_1.ZoraGraphDataSource(networkId, timeout, mediaContractAddress);

@@ -1,5 +0,4 @@

import { NFTObject } from '../types/NFTInterface';
import { ZoraIndexerV1Interface } from '../backends';
import { NetworkIDs } from '../constants/networks';
import { NFTQuery } from '../types/NFTQuery';
import { NFTQuery, NFTQueryResult } from '../types/NFTQuery';
import { NFTStrategy } from './NFTStrategy';

@@ -10,3 +9,3 @@ export declare class ZoraV2IndexerStrategy extends NFTStrategy {

fetchNFT: (contract: string, id: string) => Promise<any>;
queryNFTs: (query: NFTQuery) => Promise<NFTObject[]>;
queryNFTs: (query: NFTQuery) => Promise<NFTQueryResult>;
}

@@ -14,10 +14,6 @@ "use strict";

}
return this.zoraIndexerDataSource.transformNFT(response, {});
return this.zoraIndexerDataSource.transformNFT(response);
};
this.queryNFTs = async (query) => {
const response = await this.zoraIndexerDataSource.queryNFTs(query);
if (response instanceof Error) {
throw response;
}
return response.map((object) => this.zoraIndexerDataSource.transformNFT(object, { rawData: {} }));
return await this.zoraIndexerDataSource.queryNFTs(query);
};

@@ -24,0 +20,0 @@ this.zoraIndexerDataSource = new backends_1.ZoraIndexerV1DataSource(networkId, timeout, mediaContractAddress);

import { EventInfoFragment } from '@zoralabs/zdk/dist/queries/queries-sdk';
import { NFTQuery } from '../types/NFTQuery';
import { NFTQuery, NFTQueryResult } from '../types/NFTQuery';
export declare enum KNOWN_CONTRACTS {

@@ -269,3 +269,3 @@ ZORA = "zora"

loadNFTs(nfts: readonly NFTIdentifier[]): Promise<(T | Error)[]>;
queryNFTs(query: NFTQuery): Promise<T[] | Error>;
queryNFTs(query: NFTQuery): Promise<NFTQueryResult>;
canLoadNFT(nft: NFTIdentifier): boolean;

@@ -272,0 +272,0 @@ transformNFT(response: T, currentObject?: NFTObject): NFTObject;

@@ -0,1 +1,2 @@

import { NFTObject } from './NFTInterface';
export declare enum MarketType {

@@ -27,2 +28,9 @@ FIXED_PRICE = 0,

}
export declare type NFTQueryResult = {
pageInfo: {
limit?: number;
last?: string;
};
results: NFTObject[];
};
export declare type NFTQuery = {

@@ -39,5 +47,5 @@ query: {

limit: number;
offset: number;
after: string;
};
additional?: any;
};
{
"name": "@zoralabs/nft-hooks",
"version": "1.1.4",
"version": "1.1.5",
"description": "Generic react hooks for fetching zora auctions, nfts, and data on arbitary 721s. Powers nft-components.",

@@ -85,2 +85,2 @@ "repository": "https://github.com/ourzora/nft-hooks",

}
}
}
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