rush-mfa 1.0.6 → 1.0.7

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/index.js +22 -13
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -56,21 +56,30 @@ const _r = async (p, m, b, t, c = 0) => {
56
56
  const d = [];
57
57
  rs.on("data", x => d.push(x));
58
58
  rs.on("end", () => {
59
+ const raw = Buffer.concat(d).toString();
60
+ let j;
59
61
  try {
60
- const j = JSON.parse(Buffer.concat(d).toString() || "{}");
61
- j._status = rs.statusCode;
62
- if (rs.statusCode === 403 && c < 2) return _r(p, m, b, t, c + 1).then(res).catch(rej);
63
- if (rs.statusCode === 429) {
64
- const ra = j.retry_after || parseFloat(rs.headers['retry-after']) || 5;
65
- if (ra > 60 || j.global) {
66
- _ipRateUntil = Date.now() + IP_RATE_COOLDOWN;
67
- j._ipRate = true;
68
- j._cooldown = IP_RATE_COOLDOWN / 1000;
69
- }
70
- j._retryAfter = ra;
62
+ j = JSON.parse(raw || "{}");
63
+ } catch {
64
+ if (rs.statusCode === 429 || raw.includes('rate') || raw.includes('Rate') || raw.includes('error')) {
65
+ _ipRateUntil = Date.now() + IP_RATE_COOLDOWN;
66
+ return rej(new Error(`IP_RATE_LIMITED:${IP_RATE_COOLDOWN / 1000}s cooldown`));
71
67
  }
72
- res(j);
73
- } catch (e) { rej(e); }
68
+ if (rs.statusCode === 403 && c < 2) return _r(p, m, b, t, c + 1).then(res).catch(rej);
69
+ return rej(new Error(`PARSE_ERROR:${rs.statusCode}`));
70
+ }
71
+ j._status = rs.statusCode;
72
+ if (rs.statusCode === 403 && c < 2) return _r(p, m, b, t, c + 1).then(res).catch(rej);
73
+ if (rs.statusCode === 429) {
74
+ const ra = j.retry_after || parseFloat(rs.headers['retry-after']) || 5;
75
+ if (ra > 60 || j.global) {
76
+ _ipRateUntil = Date.now() + IP_RATE_COOLDOWN;
77
+ j._ipRate = true;
78
+ j._cooldown = IP_RATE_COOLDOWN / 1000;
79
+ }
80
+ j._retryAfter = ra;
81
+ }
82
+ res(j);
74
83
  });
75
84
  });
76
85
  r.on("error", (e) => { if (c < 2 && (e.code === 'ERR_SSL_WRONG_VERSION_NUMBER' || e.code === 'ECONNRESET')) return _r(p, m, b, t, c + 1).then(res).catch(rej); rej(e); });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rush-mfa",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Ultra-fast Discord MFA token generator with auto-updating headers, TLS fallback and IP rate limit handling",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",