Skip to content

MET-685: Add new parameters #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 8, 2025
379 changes: 202 additions & 177 deletions clients/js/src/decorator.ts

Large diffs are not rendered by default.

147 changes: 127 additions & 20 deletions clients/js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,38 @@ import { Nullable, PublicKey } from '@metaplex-foundation/umi';
// RPC input. //
// ---------------------------------------- //

/**
* Display options for asset queries
*/
export type DisplayOptions = {
/**
* Whether to show unverified collections
*/
showUnverifiedCollections?: boolean;
/**
* Whether to show collection metadata
*/
showCollectionMetadata?: boolean;
/**
* Whether to show fungible assets
*/
showFungible?: boolean;
/**
* Whether to show inscription data
*/
showInscription?: boolean;
};

export type GetAssetsByAuthorityRpcInput = {
/**
* The address of the authority of the assets.
*/
authority: PublicKey;

/**
* Display options for the query
*/
displayOptions?: DisplayOptions;
} & Pagination;

export type GetAssetsByCreatorRpcInput = {
Expand All @@ -21,6 +48,11 @@ export type GetAssetsByCreatorRpcInput = {
* Indicates whether to retrieve only verified assets or not.
*/
onlyVerified: boolean;

/**
* Display options for the query
*/
displayOptions?: DisplayOptions;
} & Pagination;

export type GetAssetsByGroupRpcInput = {
Expand All @@ -33,65 +65,75 @@ export type GetAssetsByGroupRpcInput = {
* The value of the group
*/
groupValue: string;

/**
* Display options for the query
*/
displayOptions?: DisplayOptions;
} & Pagination;

export type GetAssetsByOwnerRpcInput = {
/**
* The address of the owner of the assets.
*/
owner: PublicKey;

/**
* Display options for the query
*/
displayOptions?: DisplayOptions;
} & Pagination;

export type SearchAssetsRpcInput = {
/**
* Indicates whether the search criteria should be inverted or not.
* The address of the authority.
*/
negate?: Nullable<boolean>;
authority?: Nullable<PublicKey>;

/**
* Indicates whether to retrieve all or any asset that matches the search criteria.
* The address of the creator.
*/
conditionType?: Nullable<'all' | 'any'>;
creator?: Nullable<PublicKey>;

/**
* The interface value of the asset.
* Indicates whether the creator must be verified or not.
*/
interface?: Nullable<DasApiAssetInterface>;
creatorVerified?: Nullable<boolean>;

/**
* The value for the JSON URI.
* The grouping (`key`, `value`) pair.
*/
jsonUri?: Nullable<string>;
grouping?: Nullable<[string, string]>;

/**
* The address of the owner.
* The interface value of the asset.
*/
owner?: Nullable<PublicKey>;
interface?: Nullable<DasApiAssetInterface>;

/**
* Type of ownership.
* Indicates whether the search criteria should be inverted or not.
*/
ownerType?: Nullable<'single' | 'token'>;
negate?: Nullable<boolean>;

/**
* The address of the creator.
* The name of the asset.
*/
creator?: Nullable<PublicKey>;
name?: Nullable<string>;

/**
* Indicates whether the creator must be verified or not.
* Indicates whether to retrieve all or any asset that matches the search criteria.
*/
creatorVerified?: Nullable<boolean>;
conditionType?: Nullable<'all' | 'any'>;

/**
* The address of the authority.
* The address of the owner.
*/
authority?: Nullable<PublicKey>;
owner?: Nullable<PublicKey>;

/**
* The grouping (`key`, `value`) pair.
* Type of ownership.
*/
grouping?: Nullable<[string, string]>;
ownerType?: Nullable<'single' | 'token'>;

/**
* The address of the delegate.
Expand All @@ -113,6 +155,11 @@ export type SearchAssetsRpcInput = {
*/
supplyMint?: Nullable<PublicKey>;

/**
* The type of token to search for.
*/
tokenType?: Nullable<TokenType>;

/**
* Indicates whether the asset is compressed or not.
*/
Expand Down Expand Up @@ -142,8 +189,48 @@ export type SearchAssetsRpcInput = {
* Indicates whether the asset is burnt or not.
*/
burnt?: Nullable<boolean>;

/**
* The value for the JSON URI.
*/
jsonUri?: Nullable<string>;

/**
* Display options for the query
*/
displayOptions?: DisplayOptions;
} & Pagination;

/**
* Input parameters for getAsset RPC call
*/
export type GetAssetRpcInput = {
/**
* The asset ID to fetch
*/
assetId: PublicKey;

/**
* Display options for the query
*/
displayOptions?: DisplayOptions;
};

/**
* Input parameters for getAssets RPC call
*/
export type GetAssetsRpcInput = {
/**
* Array of asset IDs to fetch
*/
assetIds: PublicKey[];

/**
* Display options for the query
*/
displayOptions?: DisplayOptions;
};

// ---------------------------------------- //
// Result types. //
// ---------------------------------------- //
Expand Down Expand Up @@ -321,6 +408,11 @@ type Pagination = {
* Retrieve assets after the specified `ID` value.
*/
after?: Nullable<string>;

/**
*
*/
cursor?: Nullable<string>;
};

/**
Expand All @@ -337,6 +429,7 @@ export type DasApiAssetInterface =
| 'LEGACY_NFT'
| 'V2_NFT'
| 'FungibleAsset'
| 'FungibleToken'
| 'Custom'
| 'Identity'
| 'Executable'
Expand Down Expand Up @@ -407,6 +500,13 @@ export type DasApiPropGroupKey = 'collection';
export type DasApiAssetGrouping = {
group_key: DasApiPropGroupKey;
group_value: string;
verified?: boolean;
collection_metadata?: {
name: string;
symbol: string;
description: string;
image: string;
};
};

export type DasApiAuthorityScope =
Expand Down Expand Up @@ -531,3 +631,10 @@ export type GetAssetSignaturesRpcResponse = {
*/
items: DasApiTransactionSignature[];
};

export type TokenType =
| 'Fungible'
| 'NonFungible'
| 'regularNFT'
| 'compressedNFT'
| 'All';
6 changes: 4 additions & 2 deletions clients/js/test/_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ export const DAS_API_ENDPOINTS: { name: string; url: string }[] = [];
Object.keys(process.env).forEach(function (key) {
if (key.startsWith('DAS_API_')) {
const name = key.substring('DAS_API_'.length);
const url = process.env[key]!;
DAS_API_ENDPOINTS.push({ name, url });
const url = process.env[key];
if (url) {
DAS_API_ENDPOINTS.push({ name, url });
}
}
});

Expand Down
54 changes: 48 additions & 6 deletions clients/js/test/getAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ DAS_API_ENDPOINTS.forEach((endpoint) => {
test(`it can fetch a regular asset by ID (${endpoint.name})`, async (t) => {
// Given a minted NFT.
const umi = createUmi(endpoint.url);
const assetId = publicKey('8bFQbnBrzeiYQabEJ1ghy5T7uFpqFzPjUGsVi3SzSMHB');
const assetId = publicKey('Hu9vvgNjVDxRo6F8iTEo6sRJikhqoM2zVswR86WAf4C');

// When we fetch the asset using its ID.
const asset = await umi.rpc.getAsset(assetId);

// Then we expect the following data.
t.like(asset, <DasApiAsset>{
interface: 'ProgrammableNFT',
interface: 'V1_NFT',
id: assetId,
content: {
metadata: {
Expand All @@ -66,12 +66,54 @@ DAS_API_ENDPOINTS.forEach((endpoint) => {
t.like(asset.compression, <DasApiAssetCompression>{
compressed: false,
});
t.deepEqual(asset.grouping.length, 1);
t.deepEqual(asset.mutable, true);
t.deepEqual(asset.burnt, false);
});

test(`it can fetch a regular asset by ID not showing unverified collection data using showUnverifiedCollections false (${endpoint.name})`, async (t) => {
// Given a minted NFT.
const umi = createUmi(endpoint.url);
const assetId = publicKey('5smGnzgaMsQ3JV7jWCvSxnRkHjP2dJoi1uczHTx87tji');

// When we fetch the asset using its ID with display options.
await t.throwsAsync(
async () => {
await umi.rpc.getAsset({
assetId,
displayOptions: { showUnverifiedCollections: false },
});
},
{
message: /Asset not found/,
}
);
});

test(`it can fetch a regular asset by ID with unverified collection data using showUnverifiedCollections true (${endpoint.name})`, async (t) => {
// Given a minted NFT.
const umi = createUmi(endpoint.url);
const assetId = publicKey('5smGnzgaMsQ3JV7jWCvSxnRkHjP2dJoi1uczHTx87tji');

// When we fetch the asset using its ID.
const asset = await umi.rpc.getAsset({
assetId,
displayOptions: { showUnverifiedCollections: true },
});

t.like(asset, <DasApiAsset>{
interface: 'V1_NFT',
id: assetId,
content: {
metadata: {
name: 'unverified Azure 55',
},
},
});
t.is(asset.grouping.length, 1);
t.like(asset.grouping[0], {
group_key: 'collection',
group_value: '5RT4e9uHUgG9h13cSc3L4YvkDc9qXSznoLaX4Tx8cpWS',
group_value: '5g2h8NuNNdb2riSuAKC3JJrrJKGJUH9dxM23fqdYgGt2',
verified: false,
});
t.deepEqual(asset.mutable, true);
t.deepEqual(asset.burnt, false);
});
});
Loading