Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { Client } from "../Client";
import { FACTOR_API_PATH, POST, SEARCH_API_PATH } from "../Constants";
import { FactorRequest, SearchRequest } from "../interfaces/Api";
import { FactorResponse } from "../interfaces/response/FactorResponse";
import { SearchResponse } from "../interfaces/response/SearchResponse";
import { makeApiRequest } from "../request";
/**
* Retrieves a factor details by making a POST request to the factor API endpoint.
*
* @export
* @param {FactorRequest} payload - The factor request data to be sent to the API
* @return {Promise<FactorResponse>} A promise that resolves to the FactorResponse returned by the API
* @throws {Error} May throw an error if the API request fails
*
* @example
* const factorRequest = {
"activity": {
"factorId": 12345
}
};
OR
const factorRequest = {
"time" : {
"date": "2025-01-04"
},
"location": {
"country": "usa",
"stateProvince": "new york"
},
"activity": {
"type":"natural gas"
},
"includeDetails": true
};
* const factor = await retrieveFactor(factorRequest);
*/
export async function retrieveFactor(
payload: FactorRequest
): Promise<FactorResponse> {
const client = Client.getInstance();
const url = client.getDomain() + FACTOR_API_PATH;
return makeApiRequest<FactorResponse>({
method: POST,
url,
data: payload,
});
}
/**
* Performs a search operation by making a POST request to the search API endpoint.
*
* @export
* @param {SearchRequest} payload - The search request data to be sent to the API
* @return {Promise<SearchResponse>} A promise that resolves to the search results returned by the API
* @throws {Error} May throw an error if the API request fails
*
* The API applies cross-encoder reranking by default. Set `enableReranker` to
* `false` to keep semantic similarity ordering without reranking.
*
* @example
* // Basic search
* const searchRequest = {
"time":{
"date": "2020-06-10"
},
"activity": {
"search" : "travel"
},
"location": {
"country": "USA"
}
};
* const results = await search(searchRequest);
*
* @example
* // Search without cross-encoder reranking
* const searchWithoutReranker = {
"time":{
"date": "2020-06-10"
},
"activity": {
"search" : "travel"
},
"location": {
"country": "USA"
},
"enableReranker": false
};
* const results = await search(searchWithoutReranker);
*
* @example
* // Search with optional unit parameter
* const searchWithUnit = {
"time":{
"date": "2020-06-10"
},
"activity": {
"search": "electricity",
"unit": "kWh"
},
"location": {
"country": "USA"
}
};
* const results = await search(searchWithUnit);
*
* @example
* // Search with optional scope parameter
* const searchWithScope = {
"time":{
"date": "2020-06-10"
},
"activity": {
"search": "natural gas",
"scope": "1"
},
"location": {
"country": "USA"
}
};
* const results = await search(searchWithScope);
*
* @example
* // Search with both unit and scope parameters
* const searchWithBoth = {
"time":{
"date": "2020-06-10"
},
"activity": {
"search": "electricity",
"unit": "MWh",
"scope": "2"
},
"location": {
"country": "USA",
"stateProvince": "california"
}
};
* const results = await search(searchWithBoth);
*/
export async function search(
payload: SearchRequest
): Promise<SearchResponse> {
const client = Client.getInstance();
const url = client.getDomain() + SEARCH_API_PATH;
return makeApiRequest<SearchResponse>({
method: POST,
url,
data: payload,
});
} |