@discordanalytics/core 2.6.2 → 2.7.0

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.
Files changed (2) hide show
  1. package/dist/index.js +16 -30
  2. package/package.json +1 -5
package/dist/index.js CHANGED
@@ -13,13 +13,9 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
16
  Object.defineProperty(exports, "__esModule", { value: true });
20
17
  exports.CustomEvent = exports.AnalyticsBase = void 0;
21
18
  const types_1 = require("./types");
22
- const node_fetch_1 = __importDefault(require("node-fetch"));
23
19
  /**
24
20
  * DiscordAnalytics Base Class
25
21
  * @class AnalyticsBase
@@ -136,37 +132,27 @@ class AnalyticsBase {
136
132
  * @param body The body to send (optional)
137
133
  * @param max_retries The maximum number of retries (default: 5)
138
134
  * @param backoff_factor The backoff factor to use (default: 0.5)
139
- * @returns {Promise<void | fetch.Response>} The response from the API
135
+ * @returns {Promise<void | Response>} The response from the API
140
136
  */
141
137
  async api_call_with_retries(method, url, body, max_retries = 5, backoff_factor = 0.5) {
142
138
  let retries = 0;
143
139
  let response;
144
140
  while (retries < max_retries) {
145
- try {
146
- response = await (0, node_fetch_1.default)(url, {
147
- method,
148
- headers: this._headers,
149
- body,
150
- });
151
- if (response.ok)
152
- return response;
153
- else if (response.status === 401)
154
- return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.INVALID_API_TOKEN}`);
155
- else if (response.status === 423)
156
- return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.SUSPENDED_BOT}`);
157
- else if (response.status === 404 && url.includes('events'))
158
- return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.INVALID_EVENT_KEY}`, true);
159
- else if (response.status !== 200)
160
- return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.INVALID_RESPONSE}`);
161
- }
162
- catch (error) {
163
- retries++;
164
- const retry_after = Math.pow(2, retries) * backoff_factor;
165
- this.error(`[DISCORDANALYTICS] Error: ${error}. Retrying in ${retry_after} seconds...`);
166
- if (retries >= max_retries)
167
- return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.MAX_RETRIES_EXCEEDED}`);
168
- await new Promise((resolve) => setTimeout(resolve, retry_after * 1000));
169
- }
141
+ response = await fetch(url, {
142
+ method,
143
+ headers: this._headers,
144
+ body,
145
+ });
146
+ if (response.ok)
147
+ return response;
148
+ else if (response.status === 401)
149
+ return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.INVALID_API_TOKEN}`);
150
+ else if (response.status === 423)
151
+ return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.SUSPENDED_BOT}`);
152
+ else if (response.status === 404 && url.includes('events'))
153
+ return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.INVALID_EVENT_KEY}`, true);
154
+ else if (response.status !== 200)
155
+ return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.INVALID_RESPONSE}`);
170
156
  }
171
157
  }
172
158
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discordanalytics/core",
3
- "version": "2.6.2",
3
+ "version": "2.7.0",
4
4
  "description": "Core package to work with Discord Analytics",
5
5
  "main": "dist/index.js",
6
6
  "author": "Discord Analytics",
@@ -13,10 +13,6 @@
13
13
  "bugs": {
14
14
  "url": "https://github.com/DiscordAnalytics/node-package/issues"
15
15
  },
16
- "dependencies": {
17
- "@types/node-fetch": "^2.6.13",
18
- "node-fetch": "^2.7.0"
19
- },
20
16
  "devDependencies": {
21
17
  "@types/node": "*",
22
18
  "typescript": "*"