@aptos-labs/ts-sdk
Version:
Aptos TypeScript SDK
151 lines • 6.29 kB
JavaScript
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0
import { aptosRequest } from "./core.js";
import { AptosApiType } from "../utils/const.js";
/**
* Executes a POST request to the specified URL with the provided options.
*
* @param options - The options for the POST request.
* @param options.type - The type of the request.
* @param options.originMethod - The original method that initiated the request.
* @param options.path - The path for the request.
* @param options.body - The body content to be sent with the request.
* @param options.acceptType - The type of response expected from the server.
* @param options.contentType - The content type of the request body.
* @param options.params - Additional parameters to include in the request.
* @param options.aptosConfig - Configuration settings for the Aptos request.
* @param options.overrides - Any overrides for the default request behavior.
* @returns The response from the POST request.
* @group Implementation
* @category Client
*/
export async function post(options) {
const { type, originMethod, path, body, acceptType, contentType, params, aptosConfig, overrides } = options;
const url = aptosConfig.getRequestUrl(type);
return aptosRequest({
url,
method: "POST",
originMethod,
path,
body,
contentType,
acceptType,
params,
overrides,
}, aptosConfig, options.type);
}
/**
* Sends a request to the Aptos full node using the specified options.
* This function allows you to interact with the Aptos blockchain by sending requests to the full node.
*
* @param options - The options for the request.
* @param options.aptosConfig - Configuration settings for the Aptos client.
* @param options.aptosConfig.clientConfig - Client-specific configuration settings.
* @param options.aptosConfig.fullnodeConfig - Full node-specific configuration settings.
* @param options.overrides - Additional overrides for the request.
* @group Implementation
* @category Client
*/
export async function postAptosFullNode(options) {
const { aptosConfig } = options;
return post({
...options,
type: AptosApiType.FULLNODE,
overrides: {
...aptosConfig.clientConfig,
...aptosConfig.fullnodeConfig,
...options.overrides,
HEADERS: { ...aptosConfig.clientConfig?.HEADERS, ...aptosConfig.fullnodeConfig?.HEADERS },
},
});
}
/**
* Sends a request to the Aptos indexer with the specified options.
* This function allows you to interact with the Aptos indexer and customize the request using various configurations.
*
* @param options - The options for the request to the Aptos indexer.
* @param options.aptosConfig - Configuration settings specific to the Aptos client and indexer.
* @param options.aptosConfig.clientConfig - The client configuration settings.
* @param options.aptosConfig.indexerConfig - The indexer configuration settings.
* @param options.overrides - Additional overrides for the request.
* @param options.overrides.HEADERS - Custom headers to include in the request.
* @group Implementation
* @category Client
*/
export async function postAptosIndexer(options) {
const { aptosConfig } = options;
return post({
...options,
type: AptosApiType.INDEXER,
overrides: {
...aptosConfig.clientConfig,
...aptosConfig.indexerConfig,
...options.overrides,
HEADERS: { ...aptosConfig.clientConfig?.HEADERS, ...aptosConfig.indexerConfig?.HEADERS },
},
});
}
/**
* Sends a request to the Aptos faucet to obtain test tokens.
* This function modifies the provided configuration to ensure that the API_KEY is not included in the request.
*
* Note that only devnet has a publicly accessible faucet. For testnet, you must use
* the minting page at https://aptos.dev/network/faucet.
*
* @param options - The options for the request.
* @param options.aptosConfig - The configuration settings for the Aptos client.
* @param options.aptosConfig.clientConfig - The client-specific configuration settings.
* @param options.aptosConfig.clientConfig.HEADERS - Optional headers to include in the request.
* @param options.aptosConfig.faucetConfig - The configuration settings specific to the faucet.
* @param options.overrides - Additional overrides for the request configuration.
* @group Implementation
* @category Client
*/
export async function postAptosFaucet(options) {
const { aptosConfig } = options;
// Faucet does not support API_KEY
// Create a new object with the desired modification
const modifiedAptosConfig = {
...aptosConfig,
clientConfig: { ...aptosConfig.clientConfig },
};
// Delete API_KEY config
delete modifiedAptosConfig?.clientConfig?.API_KEY;
return post({
...options,
type: AptosApiType.FAUCET,
overrides: {
...modifiedAptosConfig.clientConfig,
...modifiedAptosConfig.faucetConfig,
...options.overrides,
HEADERS: { ...modifiedAptosConfig.clientConfig?.HEADERS, ...modifiedAptosConfig.faucetConfig?.HEADERS },
},
});
}
/**
* Makes a post request to the pepper service.
*
* @param options - The options for the request.
* @param options.url - The URL to which the request is sent.
* @param options.headers - The headers to include in the request.
* @param options.body - The body of the request.
* @returns A promise that resolves to the response from the pepper service.
* @group Implementation
* @category Client
*/
export async function postAptosPepperService(options) {
return post({ ...options, type: AptosApiType.PEPPER });
}
/**
* Sends a request to the Aptos proving service with the specified options.
*
* @param options - The options for the request to the Aptos proving service.
* @param options.type - The type of the request, which should be set to AptosApiType.PROVER.
* @param options.data - The data to be included in the request.
* @group Implementation
* @category Client
*/
export async function postAptosProvingService(options) {
return post({ ...options, type: AptosApiType.PROVER });
}
//# sourceMappingURL=post.js.map