poe-api-manager 1.2.20 → 1.2.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/AbstractClass/PoeNinja.js +7 -1
- package/dist/lib/AbstractClass/PoeWatch.js +7 -1
- package/dist/lib/mainfunctions/propertyFilter.js +15 -0
- package/dist/lib/modules/poe.ninja/currencyView/currencySubModules/submodules/CurrencyModule.js +12 -1
- package/dist/lib/modules/poe.ninja/fetch/fetchData.js +23 -6
- package/dist/lib/modules/poe.watch/fetch/watchFetch.js +25 -4
- package/dist/lib/modules/poe.watch/func/getCategory.js +17 -6
- package/dist/lib/modules/utils/getLeagues.js +14 -1
- package/package.json +1 -1
|
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const getData_1 = __importDefault(require("../modules/poe.ninja/func/getData"));
|
|
7
|
+
const CustomError_1 = __importDefault(require("../errors/CustomError"));
|
|
8
|
+
const ApiError_1 = __importDefault(require("../errors/ApiError"));
|
|
7
9
|
/**
|
|
8
10
|
* Abstract class representing a PoeNinja.
|
|
9
11
|
* @abstract
|
|
@@ -37,7 +39,11 @@ class PoeNinja {
|
|
|
37
39
|
return (0, getData_1.default)(this.league, this.typeName, this.type, requestedProperties);
|
|
38
40
|
}
|
|
39
41
|
catch (error) {
|
|
40
|
-
|
|
42
|
+
// Pass through custom errors
|
|
43
|
+
if (error instanceof CustomError_1.default) {
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
throw new ApiError_1.default(`Error getData ${this.typeName} and ${this.type} data: ${error.message}`, 500, { league: this.league, typeName: this.typeName, type: this.type });
|
|
41
47
|
}
|
|
42
48
|
}
|
|
43
49
|
}
|
|
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const getData_1 = __importDefault(require("../modules/poe.watch/func/getData"));
|
|
7
|
+
const CustomError_1 = __importDefault(require("../errors/CustomError"));
|
|
8
|
+
const ApiError_1 = __importDefault(require("../errors/ApiError"));
|
|
7
9
|
/**
|
|
8
10
|
* Represents an abstract class for interacting with the PoeWatch API.
|
|
9
11
|
* @abstract
|
|
@@ -33,7 +35,11 @@ class PoeWatch {
|
|
|
33
35
|
return (0, getData_1.default)(this.league, this.type, requestedProperties);
|
|
34
36
|
}
|
|
35
37
|
catch (error) {
|
|
36
|
-
|
|
38
|
+
// Pass through custom errors
|
|
39
|
+
if (error instanceof CustomError_1.default) {
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
throw new ApiError_1.default(`Error retrieving ${this.type} data: ${error.message}`, 500, { league: this.league, type: this.type });
|
|
37
43
|
}
|
|
38
44
|
}
|
|
39
45
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ValidationError_js_1 = __importDefault(require("../errors/ValidationError.js"));
|
|
3
7
|
/**
|
|
4
8
|
* Filters properties of objects in an array based on the specified properties.
|
|
5
9
|
* @param {Record<string, any> []} data The array of objects to filter.
|
|
@@ -7,6 +11,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
11
|
* @returns {object[]} An array of objects with only the specified properties.
|
|
8
12
|
*/
|
|
9
13
|
function filterProperties(data, requestedProperties) {
|
|
14
|
+
// Validate input first
|
|
15
|
+
if (!Array.isArray(data)) {
|
|
16
|
+
throw new ValidationError_js_1.default("Input data must be an array", 400, {
|
|
17
|
+
providedType: typeof data,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
if (!Array.isArray(requestedProperties)) {
|
|
21
|
+
throw new ValidationError_js_1.default("requestedProperties must be an array", 400, {
|
|
22
|
+
providedType: typeof requestedProperties,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
10
25
|
const result = [];
|
|
11
26
|
data.forEach((item) => {
|
|
12
27
|
const itemResult = {};
|
package/dist/lib/modules/poe.ninja/currencyView/currencySubModules/submodules/CurrencyModule.js
CHANGED
|
@@ -5,6 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const PoeNinja_1 = __importDefault(require("../../../../../AbstractClass/PoeNinja"));
|
|
7
7
|
const getQuickCurrency_1 = __importDefault(require("../../../func/getQuickCurrency"));
|
|
8
|
+
const CustomError_1 = __importDefault(require("../../../../../errors/CustomError"));
|
|
9
|
+
const ApiError_1 = __importDefault(require("../../../../../errors/ApiError"));
|
|
8
10
|
/**
|
|
9
11
|
* Represents a module for retrieving currency data from the PoeNinja API.
|
|
10
12
|
*/
|
|
@@ -33,7 +35,16 @@ class CurrencyModule extends PoeNinja_1.default {
|
|
|
33
35
|
return await (0, getQuickCurrency_1.default)(this.league, this.typeName, this.type, currencyTypeName);
|
|
34
36
|
}
|
|
35
37
|
catch (error) {
|
|
36
|
-
|
|
38
|
+
// Pass through custom errors
|
|
39
|
+
if (error instanceof CustomError_1.default) {
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
throw new ApiError_1.default(`Error fetching QuickCurrencyData ${this.type} and Currency Name:${currencyTypeName} data: ${error.message}`, 500, {
|
|
43
|
+
league: this.league,
|
|
44
|
+
typeName: this.typeName,
|
|
45
|
+
type: this.type,
|
|
46
|
+
currencyTypeName,
|
|
47
|
+
});
|
|
37
48
|
}
|
|
38
49
|
}
|
|
39
50
|
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
7
|
const mergeData_1 = __importDefault(require("./merge/mergeData"));
|
|
8
8
|
const urlGenerator_1 = __importDefault(require("../func/urlGenerator"));
|
|
9
|
+
const ApiError_1 = __importDefault(require("../../../errors/ApiError"));
|
|
9
10
|
/**
|
|
10
11
|
* Fetches data from a specified API endpoint, merges relevant data, and returns the result.
|
|
11
12
|
* @param league The game league for which to fetch data.
|
|
@@ -21,20 +22,22 @@ async function fetchData(league, typeName, type) {
|
|
|
21
22
|
//axios.get(url) is a promise
|
|
22
23
|
const response = await axios_1.default.get(url, {
|
|
23
24
|
headers: {
|
|
24
|
-
|
|
25
|
+
"Accept-Encoding": "identity",
|
|
25
26
|
},
|
|
26
27
|
});
|
|
27
28
|
//typwName is either currencyoverview or itemoverview
|
|
28
29
|
if (typeName == "currencyoverview") {
|
|
29
30
|
//if the response has data and lines and currencyDetails
|
|
30
|
-
if (response.data &&
|
|
31
|
+
if (response.data &&
|
|
32
|
+
response.data.lines &&
|
|
33
|
+
response.data.currencyDetails) {
|
|
31
34
|
const lines = response.data.lines;
|
|
32
35
|
const currencyDetails = response.data.currencyDetails;
|
|
33
36
|
//the join data is the currencyDetails
|
|
34
37
|
return (0, mergeData_1.default)(lines, currencyDetails);
|
|
35
38
|
}
|
|
36
39
|
else {
|
|
37
|
-
throw new
|
|
40
|
+
throw new ApiError_1.default(`Invalid response format from POE Ninja API CurrencyView Type:${type}`, 400, { league, typeName, type });
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
43
|
else if (typeName == "itemoverview") {
|
|
@@ -43,15 +46,29 @@ async function fetchData(league, typeName, type) {
|
|
|
43
46
|
return response.data.lines;
|
|
44
47
|
}
|
|
45
48
|
else {
|
|
46
|
-
throw new
|
|
49
|
+
throw new ApiError_1.default(`Invalid response format from POE Ninja API ItemView Type:${type}`, 400, { league, typeName, type });
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
52
|
else {
|
|
50
|
-
throw new
|
|
53
|
+
throw new ApiError_1.default(`Invalid type: ${type}`, 400, {
|
|
54
|
+
league,
|
|
55
|
+
typeName,
|
|
56
|
+
type,
|
|
57
|
+
});
|
|
51
58
|
}
|
|
52
59
|
}
|
|
53
60
|
catch (error) {
|
|
54
|
-
|
|
61
|
+
// If it's already an ApiError, pass it through
|
|
62
|
+
if (error instanceof ApiError_1.default) {
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
// Handle axios errors with more context
|
|
66
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
67
|
+
const statusCode = error.response?.status || 500;
|
|
68
|
+
throw new ApiError_1.default(`Error fetching data: ${error.message} TypeName:${typeName} and Type:${type}`, statusCode, { url: error.config?.url, league, typeName, type });
|
|
69
|
+
}
|
|
70
|
+
// General error case
|
|
71
|
+
throw new ApiError_1.default(`Error fetching data: ${error.message} TypeName:${typeName} and Type:${type}`, 500, { league, typeName, type });
|
|
55
72
|
}
|
|
56
73
|
}
|
|
57
74
|
exports.default = fetchData;
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
const ApiError_1 = __importDefault(require("../../../errors/ApiError"));
|
|
7
8
|
const WatchUrlGenerator_1 = __importDefault(require("../func/WatchUrlGenerator"));
|
|
8
9
|
/**
|
|
9
10
|
* Fetches data from the POE Watch API based on the provided query URL.
|
|
@@ -24,13 +25,33 @@ async function fetchData(league, type) {
|
|
|
24
25
|
return response.data;
|
|
25
26
|
}
|
|
26
27
|
else {
|
|
27
|
-
throw new
|
|
28
|
+
throw new ApiError_1.default("Invalid response format from POE Watch API", 400, {
|
|
29
|
+
league,
|
|
30
|
+
type,
|
|
31
|
+
});
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
34
|
catch (error) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
// If it's already an ApiError, pass it through
|
|
36
|
+
if (error instanceof ApiError_1.default) {
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
// Handle axios errors
|
|
40
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
41
|
+
const statusCode = error.response?.status || 500;
|
|
42
|
+
const errorDetails = error.response?.data || {};
|
|
43
|
+
throw new ApiError_1.default(`Error fetching data from poe.watch: ${errorDetails.error || error.message}`, statusCode, {
|
|
44
|
+
code: errorDetails.code,
|
|
45
|
+
league,
|
|
46
|
+
type,
|
|
47
|
+
url: error.config?.url,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
// General error case
|
|
51
|
+
throw new ApiError_1.default(`Error fetching data from poe.watch: ${error}`, 500, {
|
|
52
|
+
league,
|
|
53
|
+
type,
|
|
54
|
+
});
|
|
34
55
|
}
|
|
35
56
|
}
|
|
36
57
|
exports.default = fetchData;
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const watchFetch_1 = __importDefault(require("../fetch/watchFetch"));
|
|
7
|
+
const ValidationError_1 = __importDefault(require("../../../errors/ValidationError"));
|
|
7
8
|
/**
|
|
8
9
|
* Fetches data based on the provided query URL and filters it by category name.
|
|
9
10
|
* @param league - The league to fetch the data from.
|
|
@@ -14,22 +15,32 @@ const watchFetch_1 = __importDefault(require("../fetch/watchFetch"));
|
|
|
14
15
|
*/
|
|
15
16
|
async function getCategory(league, type, categoryName) {
|
|
16
17
|
try {
|
|
17
|
-
|
|
18
|
-
// Validate category name
|
|
18
|
+
// Validate category name first
|
|
19
19
|
if (!categoryName && categoryName !== "0") {
|
|
20
|
-
throw new
|
|
20
|
+
throw new ValidationError_1.default("Category name is required.", 400, {
|
|
21
|
+
league,
|
|
22
|
+
type,
|
|
23
|
+
});
|
|
21
24
|
}
|
|
25
|
+
const fetchedData = await (0, watchFetch_1.default)(league, type);
|
|
22
26
|
// Filter data by category name
|
|
23
27
|
const filteredData = fetchedData.filter((item) => item.group === categoryName);
|
|
24
28
|
// Check if filtered data is empty
|
|
25
29
|
if (filteredData.length === 0) {
|
|
26
|
-
throw new
|
|
30
|
+
throw new ValidationError_1.default(`No data found for category: ${categoryName}`, 404, {
|
|
31
|
+
league,
|
|
32
|
+
type,
|
|
33
|
+
categoryName,
|
|
34
|
+
});
|
|
27
35
|
}
|
|
28
36
|
return filteredData;
|
|
29
37
|
}
|
|
30
38
|
catch (error) {
|
|
31
|
-
|
|
39
|
+
// If it's already a custom error, pass it through
|
|
40
|
+
if (error instanceof ValidationError_1.default) {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
throw new ValidationError_1.default(`Error fetching or filtering data for category: ${error.message}`, 400, { league, type, categoryName });
|
|
32
44
|
}
|
|
33
45
|
}
|
|
34
|
-
;
|
|
35
46
|
exports.default = getCategory;
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ApiError_1 = __importDefault(require("../../errors/ApiError"));
|
|
6
7
|
const fetchData_1 = __importDefault(require("./fetchData/fetchData"));
|
|
7
8
|
/**
|
|
8
9
|
* Fetches league names from the provided URL.
|
|
@@ -18,11 +19,23 @@ async function getLeagues() {
|
|
|
18
19
|
const url = "https://api.poe.watch/leagues";
|
|
19
20
|
try {
|
|
20
21
|
const { data } = await (0, fetchData_1.default)(url);
|
|
22
|
+
if (!data || !Array.isArray(data)) {
|
|
23
|
+
throw new ApiError_1.default("Invalid response format from leagues API", 400, {
|
|
24
|
+
url,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
21
27
|
const names = data.map((item) => item.name);
|
|
28
|
+
if (names.length === 0) {
|
|
29
|
+
throw new ApiError_1.default("No leagues found in response", 404, { url });
|
|
30
|
+
}
|
|
22
31
|
return names;
|
|
23
32
|
}
|
|
24
33
|
catch (error) {
|
|
25
|
-
|
|
34
|
+
// Pass through ApiError instances
|
|
35
|
+
if (error instanceof ApiError_1.default) {
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
throw new ApiError_1.default(`Error fetching League Names: ${error.message}`, 500, { url });
|
|
26
39
|
}
|
|
27
40
|
}
|
|
28
41
|
exports.default = getLeagues;
|