Skip to content
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

expose metadata refresh methods #915

Merged
merged 5 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions packages/blockchain-data/sdk/src/blockchain-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class BlockchainData {

private readonly tokens: mr.TokensApi;

private readonly metadata: mr.MetadataApi;

constructor(moduleConfig: BlockchainDataModuleConfiguration) {
this.config = new BlockchainDataConfiguration(moduleConfig);

Expand All @@ -29,6 +31,7 @@ export class BlockchainData {
this.nfts = new mr.NftsApi(this.config.apiConfig);
this.nftOwners = new mr.NftOwnersApi(this.config.apiConfig);
this.tokens = new mr.TokensApi(this.config.apiConfig);
this.metadata = new mr.MetadataApi(this.config.apiConfig);
}

/**
Expand Down Expand Up @@ -234,4 +237,55 @@ export class BlockchainData {
throw formatError(err);
});
}

/**
* Refresh collection metadata
* @param request - the request object containing the parameters to be provided in the API request
* @returns a promise that resolves with the updated collection
* @throws {@link index.APIError}
*/
public async refreshCollectionMetadata(
request: mr.CollectionsApiRefreshCollectionMetadataRequest,
): Promise<mr.RefreshCollectionMetadataResult> {
return await this.collections
.refreshCollectionMetadata(request)
.then((res) => res.data)
.catch((err) => {
throw formatError(err);
});
}

/**
* Refresh metadata for specific NFTs
* @param request - the request object containing the parameters to be provided in the API request
* @returns a promise that resolves with the remaining rate limits
* @throws {@link index.APIError}
*/
public async refreshNFTMetadata(
request: mr.MetadataApiRefreshNFTMetadataByTokenIDRequest,
): Promise<mr.MetadataRefreshRateLimitResult> {
return await this.metadata
.refreshNFTMetadataByTokenID(request)
.then((res) => res.data)
.catch((err) => {
throw formatError(err);
});
}

/**
* Refresh metadata by ID. This will refresh metadata for all NFTs that reference the given metadata ID.
* @param request - the request object containing the parameters to be provided in the API request
* @returns a promise that resolves with the remaining rate limits
* @throws {@link index.APIError}
*/
public async refreshStackedMetadata(
request: mr.MetadataApiRefreshMetadataByIDRequest,
): Promise<mr.MetadataRefreshRateLimitResult> {
return await this.metadata
.refreshMetadataByID(request)
.then((res) => res.data)
.catch((err) => {
throw formatError(err);
});
}
}
28 changes: 15 additions & 13 deletions packages/blockchain-data/sdk/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ const defaultHeaders = {
export interface APIConfigurationParams {
basePath: string;
headers?: Record<string, string>;
baseConfig?: ImmutableConfiguration;
}

/**
* createAPIConfiguration to create a custom Configuration
* other than the production and sandbox defined below.
*/
export const createAPIConfiguration = ({
baseConfig,
basePath,
headers: baseHeaders,
}: APIConfigurationParams): mr.Configuration => {
Expand All @@ -29,23 +31,14 @@ export const createAPIConfiguration = ({

const headers = { ...(baseHeaders || {}), ...defaultHeaders };
const configParams: mr.ConfigurationParameters = {
...baseConfig,
basePath,
baseOptions: { headers },
};

return new mr.Configuration(configParams);
};

const production = (): mr.Configuration =>
createAPIConfiguration({
basePath: 'https://indexer-mr.imtbl.com',
});

const sandbox = (): mr.Configuration =>
createAPIConfiguration({
basePath: 'https://api.sandbox.immutable.com',
});

export interface BlockchainDataModuleConfiguration
extends ModuleConfiguration<APIConfigurationParams> {}

Expand All @@ -62,15 +55,24 @@ export class BlockchainDataConfiguration {
} else {
switch (baseConfig.environment) {
case Environment.SANDBOX: {
this.apiConfig = sandbox();
this.apiConfig = createAPIConfiguration({
basePath: 'https://api.sandbox.immutable.com',
baseConfig,
});
break;
}
case Environment.PRODUCTION: {
this.apiConfig = production();
this.apiConfig = createAPIConfiguration({
basePath: 'https://indexer-mr.imtbl.com',
baseConfig,
});
break;
}
default: {
this.apiConfig = sandbox();
this.apiConfig = createAPIConfiguration({
basePath: 'https://api.sandbox.immutable.com',
baseConfig,
});
}
}
}
Expand Down
167 changes: 164 additions & 3 deletions packages/internal/generated-clients/src/mr-openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,16 @@
},
"imx-remaining-refreshes": {
"$ref": "#/components/headers/MetadataRefreshLimitRemaining"
},
"retry-after": {
"$ref": "#/components/headers/MetadataRefreshRetryAfter"
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MetadataRefreshRateLimitResult"
}
}
}
},
Expand All @@ -746,7 +756,7 @@
"$ref": "#/components/responses/NotFound"
},
"429": {
"$ref": "#/components/responses/TooManyRequests"
"$ref": "#/components/responses/TooManyMetadataRefreshes"
},
"500": {
"$ref": "#/components/responses/InternalServerError"
Expand Down Expand Up @@ -1165,6 +1175,99 @@
}
}
},
"/v1/chains/{chain_name}/collections/{contract_address}/nfts/refresh-metadata": {
"post": {
"description": "refresh metadata of a list of nfts",
"tags": [
"metadata"
],
"operationId": "RefreshNFTMetadataByTokenID",
"summary": "refresh the metedata data of a list of nfts by token id",
"security": [
{
"ImmutableApiKey": [
"refresh:metadata"
]
}
],
"parameters": [
{
"name": "contract_address",
"in": "path",
"description": "The address of contract",
"required": true,
"schema": {
"type": "string"
},
"example": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e"
},
{
"name": "chain_name",
"description": "The name of chain",
"in": "path",
"required": true,
"schema": {
"$ref": "#/components/schemas/ChainName"
}
}
],
"requestBody": {
"description": "the request body",
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RefreshNFTMetadataByTokenIDRequest"
}
}
}
},
"responses": {
"202": {
"description": "Accepted",
"headers": {
"imx-refreshes-limit": {
"$ref": "#/components/headers/MetadataRefreshLimit"
},
"imx-refresh-limit-reset": {
"$ref": "#/components/headers/MetadataRefreshLimitReset"
},
"imx-remaining-refreshes": {
"$ref": "#/components/headers/MetadataRefreshLimitRemaining"
},
"retry-after": {
"$ref": "#/components/headers/MetadataRefreshRetryAfter"
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MetadataRefreshRateLimitResult"
}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
},
"401": {
"$ref": "#/components/responses/UnauthorisedRequest"
},
"403": {
"$ref": "#/components/responses/ForbiddenRequest"
},
"404": {
"$ref": "#/components/responses/NotFound"
},
"429": {
"$ref": "#/components/responses/TooManyMetadataRefreshes"
},
"500": {
"$ref": "#/components/responses/InternalServerError"
}
}
}
},
"/v1/chains/{chain_name}/orders/listings": {
"get": {
"tags": [
Expand Down Expand Up @@ -1897,14 +2000,28 @@
}
}
},
"TooManyRequests": {
"description": "Too Many Requests (429)",
"TooManyMetadataRefreshes": {
"description": "Too Many Metadata refreshes (429)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/APIError429"
}
}
},
"headers": {
"imx-refreshes-limit": {
"$ref": "#/components/headers/MetadataRefreshLimit"
},
"imx-refresh-limit-reset": {
"$ref": "#/components/headers/MetadataRefreshLimitReset"
},
"imx-remaining-refreshes": {
"$ref": "#/components/headers/MetadataRefreshLimitRemaining"
},
"retry-after": {
"$ref": "#/components/headers/MetadataRefreshRetryAfter"
}
}
},
"InternalServerError": {
Expand Down Expand Up @@ -1936,6 +2053,12 @@
"schema": {
"type": "string"
}
},
"MetadataRefreshRetryAfter": {
"description": "The number of seconds until the next refresh request can be made.",
"schema": {
"type": "string"
}
}
},
"schemas": {
Expand Down Expand Up @@ -3118,6 +3241,21 @@
"attributes"
]
},
"RefreshNFTMetadataByTokenIDRequest": {
"type": "object",
"properties": {
"nft_metadata": {
"type": "array",
"description": "List of nft metadata to be refreshed",
"items": {
"$ref": "#/components/schemas/RefreshMetadataByTokenID"
}
}
},
"required": [
"nft_metadata"
]
},
"Token": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -3256,6 +3394,29 @@
"collection_metadata"
]
},
"MetadataRefreshRateLimitResult": {
"type": "object",
"properties": {
"imx_refreshes_limit": {
"type": "string"
},
"imx_refresh_limit_reset": {
"type": "string"
},
"imx_remaining_refreshes": {
"type": "string"
},
"retry_after": {
"type": "string"
}
},
"required": [
"imx_refreshes_limit",
"imx_refresh_limit_reset",
"imx_remaining_refreshes",
"retry_after"
]
},
"BasicAPIError": {
"type": "object",
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ models/list-nfts-result.ts
models/list-tokens-result.ts
models/list-trade-result.ts
models/listing-result.ts
models/metadata-refresh-rate-limit-result.ts
models/metadata.ts
models/mint.ts
models/native-item.ts
Expand All @@ -93,6 +94,7 @@ models/refresh-metadata-by-idall-of.ts
models/refresh-metadata-by-idrequest.ts
models/refresh-metadata-by-token-id.ts
models/refresh-metadata-by-token-idall-of.ts
models/refresh-nftmetadata-by-token-idrequest.ts
models/refreshable-nftattributes.ts
models/sale-fee.ts
models/sale-payment-token.ts
Expand Down
Loading