poe-api-manager 1.2.19 → 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.
@@ -0,0 +1,77 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ - Demonstrating empathy and kindness toward other people
14
+ - Being respectful of differing opinions, viewpoints, and experiences
15
+ - Giving and gracefully accepting constructive feedback
16
+ - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ - Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ - The use of sexualized language or imagery, and sexual attention or advances of any kind
22
+ - Trolling, insulting or derogatory comments, and personal or political attacks
23
+ - Public or private harassment
24
+ - Publishing others’ private information, such as a physical or email address, without their explicit permission
25
+ - Other conduct which could reasonably be considered inappropriate in a professional setting
26
+
27
+ ## Enforcement Responsibilities
28
+
29
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
32
+
33
+ ## Scope
34
+
35
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
36
+
37
+ ## Enforcement
38
+
39
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [email@example.com](mailto:email@example.com). All complaints will be reviewed and investigated promptly and fairly.
40
+
41
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
42
+
43
+ ## Enforcement Guidelines
44
+
45
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
46
+
47
+ ### 1. Correction
48
+
49
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
50
+
51
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
52
+
53
+ ### 2. Warning
54
+
55
+ **Community Impact**: A violation through a single incident or series of actions.
56
+
57
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
58
+
59
+ ### 3. Temporary Ban
60
+
61
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
62
+
63
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
64
+
65
+ ### 4. Permanent Ban
66
+
67
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
68
+
69
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
70
+
71
+ ## Attribution
72
+
73
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html](https://www.contributor-covenant.org/version/2/0/code_of_conduct.html).
74
+
75
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
76
+
77
+ For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq). Translations are available at [https://www.contributor-covenant.org/translations](https://www.contributor-covenant.org/translations).
@@ -0,0 +1,56 @@
1
+ ### CONTRIBUTING.md
2
+
3
+ ```md
4
+ # Contributing to poe-api-manager
5
+
6
+ First off, thanks for taking the time to contribute! 🎉
7
+
8
+ The following is a set of guidelines for contributing to poe-api-manager. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
9
+
10
+ ## Code of Conduct
11
+
12
+ This project and everyone participating in it is governed by the [poe-api-manager Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to [ayberkgezer@outlook.com](mailto:ayberkgezer@outlook.com).
13
+
14
+ ## How Can I Contribute?
15
+
16
+ ### Reporting Bugs
17
+
18
+ This section guides you through submitting a bug report for poe-api-manager. Following these guidelines helps maintainers and the community understand your report, reproduce the behavior, and find related reports.
19
+
20
+ - **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/ayberkgezer/poe-api-manager/issues).
21
+ - If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/ayberkgezer/poe-api-manager/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
22
+
23
+ ### Suggesting Enhancements
24
+
25
+ This section guides you through submitting an enhancement suggestion for poe-api-manager, including completely new features and minor improvements to existing functionality.
26
+
27
+ - **Ensure the enhancement was not already suggested** by searching on GitHub under [Issues](https://github.com/ayberkgezer/poe-api-manager/issues).
28
+ - If you find an enhancement that matches your suggestion, feel free to add additional comments or ideas.
29
+ - If you cannot find an existing issue, [open a new one](https://github.com/ayberkgezer/poe-api-manager/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior.
30
+
31
+ ### Pull Requests
32
+
33
+ The process described here has several goals:
34
+
35
+ - Maintain poe-api-manager's quality
36
+ - Fix problems that are important to users
37
+ - Engage the community in working toward the best possible poe-api-manager
38
+ - Enable a sustainable system for poe-api-manager's maintainers to review contributions
39
+
40
+ Please follow these steps to have your contribution considered by the maintainers:
41
+
42
+ 1. Fork the repository and create your branch from `main`.
43
+ 2. If you've added code that should be tested, add tests.
44
+ 3. If you've changed APIs, update the documentation.
45
+ 4. Ensure the test suite passes.
46
+ 5. Make sure your code lints.
47
+ 6. Issue that pull request!
48
+
49
+ ### Coding Style
50
+
51
+ - Please follow the coding style used throughout the project.
52
+ - Ensure your code is properly formatted and linted.
53
+
54
+ ## License
55
+
56
+ By contributing to poe-api-manager, you agree that your contributions will be licensed under its MIT License.
package/Changelog.md CHANGED
@@ -1,4 +1,7 @@
1
- # Changelog
1
+ # CHANGELOG
2
+
3
+ ## 1.2.20
4
+ - 🚀[Added] CODE_OF_CONDUCT, CONTRIBUTING, and SECURITY policies.
2
5
 
3
6
  ## 1.2.19
4
7
  - 🚀[Added] poe.watch API with the following features:
package/SECURITY.md ADDED
@@ -0,0 +1,14 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ We release patches for security vulnerabilities. Which versions are eligible for receiving such patches depend on the CVSS v3.0 Rating:
6
+
7
+ | Version | Supported |
8
+ | ------- | ------------------ |
9
+ | 1.2.x | :white_check_mark: |
10
+ | < 1.2 | :x: |
11
+
12
+ ## Reporting a Vulnerability
13
+
14
+ If you discover a security vulnerability within this project, please send an email to Ayberk Gezer at [ayberkgezer@outlook.com](mailto:ayberkgezer@outlook.com) . All security vulnerabilities will be promptly addressed.
@@ -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
- throw new Error(`Error getData ${this.typeName} and ${this.type} data: ${error.message}`);
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
- throw new Error(`Error retrieving ${this.type} data: ${error.message}`);
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 = {};
@@ -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
- throw new Error(`Error fetching QuickCurrencyData ${this.type} and Currency Name:${currencyTypeName} data: ${error.message}`);
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
- 'Accept-Encoding': 'identity',
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 && response.data.lines && response.data.currencyDetails) {
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 Error(`Invalid response format from POE Ninja API CurrencyView Type:${type}`);
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 Error(`"Invalid response format from POE Ninja API ItemView Type:${type}`);
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 Error(`Invalid type: ${type}`);
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
- throw new Error(`Error fetching data: ${error.message} TypeName:${typeName} and Type:${type}`);
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 Error("Invalid response format from POE Watch API");
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
- throw new Error(axios_1.default.isAxiosError(error) && error.response
32
- ? `Error fetching data from poe.watch: ${error.response.data.error}, Code: ${error.response.data.code}`
33
- : `Error fetching data from poe.watch: ${error}`);
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
- const fetchedData = await (0, watchFetch_1.default)(league, type);
18
- // Validate category name
18
+ // Validate category name first
19
19
  if (!categoryName && categoryName !== "0") {
20
- throw new Error("Category name is required.");
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 Error(`No data found for category: ${categoryName}`);
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
- throw new Error(`Error fetching or filtering data for category: ${error.message}`);
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
- throw new Error(`Error fetching League Names: ${error.message}`);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-api-manager",
3
- "version": "1.2.19",
3
+ "version": "1.2.22",
4
4
  "description": "poe.ninja and poe.watch API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -46,4 +46,4 @@
46
46
  "dependencies": {
47
47
  "axios": "^1.6.8"
48
48
  }
49
- }
49
+ }