Use Got instead of Axios.

The lack of maintainers on Axios is worrying. Got seems like a more solid option.
This commit is contained in:
Daniel Scalzi 2020-04-17 23:50:18 -04:00
parent 75a7e0f713
commit 8764c52fcc
No known key found for this signature in database
GPG Key ID: D18EA3FB4B142A57
5 changed files with 474 additions and 164 deletions

528
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "helioslauncher", "name": "helioslauncher",
"version": "1.7.0", "version": "2.0.0-alpha.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -1367,19 +1367,6 @@
"sumchecker": "^3.0.1" "sumchecker": "^3.0.1"
}, },
"dependencies": { "dependencies": {
"fs-extra": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
"integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",
"dev": true,
"requires": {
"graceful-fs": "^4.2.0",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
}
}
},
"@sindresorhus/is": { "@sindresorhus/is": {
"version": "0.14.0", "version": "0.14.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz",
@ -1395,6 +1382,146 @@
"defer-to-connect": "^1.0.1" "defer-to-connect": "^1.0.1"
} }
}, },
"cacheable-request": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.1.0.tgz",
"integrity": "sha512-Oj3cAGPCqOZX7Rz64Uny2GYAZNliQSqfbePrgAQ1wKAihYmCUnraBtJtKcGR4xz7wF+LoJC+ssFZvv5BgF9Igg==",
"dev": true,
"requires": {
"clone-response": "^1.0.2",
"get-stream": "^5.1.0",
"http-cache-semantics": "^4.0.0",
"keyv": "^3.0.0",
"lowercase-keys": "^2.0.0",
"normalize-url": "^4.1.0",
"responselike": "^1.0.2"
},
"dependencies": {
"get-stream": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz",
"integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==",
"dev": true,
"requires": {
"pump": "^3.0.0"
}
},
"lowercase-keys": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz",
"integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==",
"dev": true
}
}
},
"decompress-response": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz",
"integrity": "sha1-gKTdMjdIOEv6JICDYirt7Jgq3/M=",
"dev": true,
"requires": {
"mimic-response": "^1.0.0"
}
},
"defer-to-connect": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-1.1.3.tgz",
"integrity": "sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ==",
"dev": true
},
"fs-extra": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
"integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",
"dev": true,
"requires": {
"graceful-fs": "^4.2.0",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
},
"got": {
"version": "9.6.0",
"resolved": "https://registry.npmjs.org/got/-/got-9.6.0.tgz",
"integrity": "sha512-R7eWptXuGYxwijs0eV+v3o6+XH1IqVK8dJOEecQfTmkncw9AV4dcw/Dhxi8MdlqPthxxpZyizMzyg8RTmEsG+Q==",
"dev": true,
"requires": {
"@sindresorhus/is": "^0.14.0",
"@szmarczak/http-timer": "^1.1.2",
"cacheable-request": "^6.0.0",
"decompress-response": "^3.3.0",
"duplexer3": "^0.1.4",
"get-stream": "^4.1.0",
"lowercase-keys": "^1.0.1",
"mimic-response": "^1.0.1",
"p-cancelable": "^1.0.0",
"to-readable-stream": "^1.0.0",
"url-parse-lax": "^3.0.0"
}
},
"json-buffer": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz",
"integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=",
"dev": true
},
"keyv": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/keyv/-/keyv-3.1.0.tgz",
"integrity": "sha512-9ykJ/46SN/9KPM/sichzQ7OvXyGDYKGTaDlKMGCAlg2UK8KRy4jb0d8sFc+0Tt0YYnThq8X2RZgCg74RPxgcVA==",
"dev": true,
"requires": {
"json-buffer": "3.0.0"
}
},
"lowercase-keys": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz",
"integrity": "sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==",
"dev": true
},
"mimic-response": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz",
"integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==",
"dev": true
},
"p-cancelable": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.1.0.tgz",
"integrity": "sha512-s73XxOZ4zpt1edZYZzvhqFa6uvQc1vwUa0K0BdtIZgQMAJj9IbebH+JkgKZc9h+B05PKHLOTl4ajG1BmNrVZlw==",
"dev": true
},
"responselike": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/responselike/-/responselike-1.0.2.tgz",
"integrity": "sha1-kYcg7ztjHFZCvgaPFa3lpG9Loec=",
"dev": true,
"requires": {
"lowercase-keys": "^1.0.0"
}
},
"to-readable-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/to-readable-stream/-/to-readable-stream-1.0.0.tgz",
"integrity": "sha512-Iq25XBt6zD5npPhlLVXGFN3/gyR2/qODcKNNyTMd4vbm39HUaOiAM4PMq0eMVC/Tkxz+Zjdsc55g9yyz+Yq00Q==",
"dev": true
}
}
},
"@sindresorhus/is": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-2.1.0.tgz",
"integrity": "sha512-lXKXfypKo644k4Da4yXkPCrwcvn6SlUW2X2zFbuflKHNjf0w9htru01bo26uMhleMXsDmnZ12eJLdrAZa9MANg=="
},
"@szmarczak/http-timer": {
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.5.tgz",
"integrity": "sha512-PyRA9sm1Yayuj5OIoJ1hGt2YISX45w9WcFbh6ddT0Z/0yaFxOtGLInr4jUfU1EAFVs0Yfyfev4RNwBlUaHdlDQ==",
"requires": {
"defer-to-connect": "^2.0.0"
}
},
"@types/adm-zip": { "@types/adm-zip": {
"version": "0.4.33", "version": "0.4.33",
"resolved": "https://registry.npmjs.org/@types/adm-zip/-/adm-zip-0.4.33.tgz", "resolved": "https://registry.npmjs.org/@types/adm-zip/-/adm-zip-0.4.33.tgz",
@ -1416,6 +1543,17 @@
"integrity": "sha512-7dhGj2u7hS+Y/NPxFDaTL/kbTvVjOKvZmD+GZp0jGGOLvnakomncrqSReX+xPAGGZuCUSUsXXy9I9pEpSwxpKA==", "integrity": "sha512-7dhGj2u7hS+Y/NPxFDaTL/kbTvVjOKvZmD+GZp0jGGOLvnakomncrqSReX+xPAGGZuCUSUsXXy9I9pEpSwxpKA==",
"dev": true "dev": true
}, },
"@types/cacheable-request": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.1.tgz",
"integrity": "sha512-ykFq2zmBGOCbpIXtoVbz4SKY5QriWPh3AjyU4G74RYbtt5yOc5OfaY75ftjg7mikMOla1CTGpX3lLbuJh8DTrQ==",
"requires": {
"@types/http-cache-semantics": "*",
"@types/keyv": "*",
"@types/node": "*",
"@types/responselike": "*"
}
},
"@types/caseless": { "@types/caseless": {
"version": "0.12.2", "version": "0.12.2",
"resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.2.tgz", "resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.2.tgz",
@ -1478,6 +1616,11 @@
"integrity": "sha512-q95SP4FdkmF0CwO0F2q0H6ZgudsApaY/yCtAQNRn1gduef5fGpyEphzy0YCq/N0UFvDSnLg5V8jFK/YGXlDiCw==", "integrity": "sha512-q95SP4FdkmF0CwO0F2q0H6ZgudsApaY/yCtAQNRn1gduef5fGpyEphzy0YCq/N0UFvDSnLg5V8jFK/YGXlDiCw==",
"dev": true "dev": true
}, },
"@types/http-cache-semantics": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.0.tgz",
"integrity": "sha512-c3Xy026kOF7QOTn00hbIllV1dLR9hG9NkSrLQgCVs8NF6sBU+VGWjD3wLPhmh1TYAc7ugCFsvHYMN4VcBN1U1A=="
},
"@types/jquery": { "@types/jquery": {
"version": "3.3.34", "version": "3.3.34",
"resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.3.34.tgz", "resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.3.34.tgz",
@ -1487,6 +1630,14 @@
"@types/sizzle": "*" "@types/sizzle": "*"
} }
}, },
"@types/keyv": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.1.tgz",
"integrity": "sha512-MPtoySlAZQ37VoLaPcTHCu1RWJ4llDkULYZIzOYxlhxBqYPB0RsRlmMU0R6tahtFe27mIdkHV+551ZWV4PLmVw==",
"requires": {
"@types/node": "*"
}
},
"@types/minimatch": { "@types/minimatch": {
"version": "3.0.3", "version": "3.0.3",
"resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz",
@ -1554,6 +1705,14 @@
} }
} }
}, },
"@types/responselike": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz",
"integrity": "sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==",
"requires": {
"@types/node": "*"
}
},
"@types/semver": { "@types/semver": {
"version": "7.1.0", "version": "7.1.0",
"resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.1.0.tgz", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.1.0.tgz",
@ -2260,37 +2419,6 @@
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz", "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz",
"integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==" "integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug=="
}, },
"axios": {
"version": "0.19.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
"integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
"requires": {
"follow-redirects": "1.5.10"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
},
"follow-redirects": {
"version": "1.5.10",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
"requires": {
"debug": "=3.1.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
}
}
},
"babel-code-frame": { "babel-code-frame": {
"version": "6.26.0", "version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz",
@ -3074,35 +3202,36 @@
"unset-value": "^1.0.0" "unset-value": "^1.0.0"
} }
}, },
"cacheable-lookup": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-2.0.1.tgz",
"integrity": "sha512-EMMbsiOTcdngM/K6gV/OxF2x0t07+vMOWxZNSCRQMjO2MY2nhZQ6OYhOOpyQrbhqsgtvKGI7hcq6xjnA92USjg==",
"requires": {
"@types/keyv": "^3.1.1",
"keyv": "^4.0.0"
}
},
"cacheable-request": { "cacheable-request": {
"version": "6.1.0", "version": "7.0.1",
"resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.1.0.tgz", "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-7.0.1.tgz",
"integrity": "sha512-Oj3cAGPCqOZX7Rz64Uny2GYAZNliQSqfbePrgAQ1wKAihYmCUnraBtJtKcGR4xz7wF+LoJC+ssFZvv5BgF9Igg==", "integrity": "sha512-lt0mJ6YAnsrBErpTMWeu5kl/tg9xMAWjavYTN6VQXM1A/teBITuNcccXsCxF0tDQQJf9DfAaX5O4e0zp0KlfZw==",
"dev": true,
"requires": { "requires": {
"clone-response": "^1.0.2", "clone-response": "^1.0.2",
"get-stream": "^5.1.0", "get-stream": "^5.1.0",
"http-cache-semantics": "^4.0.0", "http-cache-semantics": "^4.0.0",
"keyv": "^3.0.0", "keyv": "^4.0.0",
"lowercase-keys": "^2.0.0", "lowercase-keys": "^2.0.0",
"normalize-url": "^4.1.0", "normalize-url": "^4.1.0",
"responselike": "^1.0.2" "responselike": "^2.0.0"
}, },
"dependencies": { "dependencies": {
"get-stream": { "get-stream": {
"version": "5.1.0", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz",
"integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==", "integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==",
"dev": true,
"requires": { "requires": {
"pump": "^3.0.0" "pump": "^3.0.0"
} }
},
"lowercase-keys": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz",
"integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==",
"dev": true
} }
} }
}, },
@ -3330,9 +3459,15 @@
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz", "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz",
"integrity": "sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws=", "integrity": "sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws=",
"dev": true,
"requires": { "requires": {
"mimic-response": "^1.0.0" "mimic-response": "^1.0.0"
},
"dependencies": {
"mimic-response": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz",
"integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ=="
}
} }
}, },
"code-point-at": { "code-point-at": {
@ -3950,12 +4085,11 @@
"dev": true "dev": true
}, },
"decompress-response": { "decompress-response": {
"version": "3.3.0", "version": "5.0.0",
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz", "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-5.0.0.tgz",
"integrity": "sha1-gKTdMjdIOEv6JICDYirt7Jgq3/M=", "integrity": "sha512-TLZWWybuxWgoW7Lykv+gq9xvzOsUjQ9tF09Tj6NSTYGMTCHNXzrPnD6Hi+TgZq19PyTAGH4Ll/NIM/eTGglnMw==",
"dev": true,
"requires": { "requires": {
"mimic-response": "^1.0.0" "mimic-response": "^2.0.0"
} }
}, },
"deep-eql": { "deep-eql": {
@ -4040,10 +4174,9 @@
} }
}, },
"defer-to-connect": { "defer-to-connect": {
"version": "1.1.3", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-1.1.3.tgz", "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-2.0.0.tgz",
"integrity": "sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ==", "integrity": "sha512-bYL2d05vOSf1JEZNx5vSAtPuBMkX8K9EUutg7zlKvTqKXHt7RhWJFbmd7qakVuf13i+IkGmp6FwSsONOf6VYIg=="
"dev": true
}, },
"define-properties": { "define-properties": {
"version": "1.1.3", "version": "1.1.3",
@ -4383,8 +4516,7 @@
"duplexer3": { "duplexer3": {
"version": "0.1.4", "version": "0.1.4",
"resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz", "resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz",
"integrity": "sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI=", "integrity": "sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI="
"dev": true
}, },
"duplexify": { "duplexify": {
"version": "3.7.1", "version": "3.7.1",
@ -6945,22 +7077,40 @@
} }
}, },
"got": { "got": {
"version": "9.6.0", "version": "10.7.0",
"resolved": "https://registry.npmjs.org/got/-/got-9.6.0.tgz", "resolved": "https://registry.npmjs.org/got/-/got-10.7.0.tgz",
"integrity": "sha512-R7eWptXuGYxwijs0eV+v3o6+XH1IqVK8dJOEecQfTmkncw9AV4dcw/Dhxi8MdlqPthxxpZyizMzyg8RTmEsG+Q==", "integrity": "sha512-aWTDeNw9g+XqEZNcTjMMZSy7B7yE9toWOFYip7ofFTLleJhvZwUxxTxkTpKvF+p1SAA4VHmuEy7PiHTHyq8tJg==",
"dev": true,
"requires": { "requires": {
"@sindresorhus/is": "^0.14.0", "@sindresorhus/is": "^2.0.0",
"@szmarczak/http-timer": "^1.1.2", "@szmarczak/http-timer": "^4.0.0",
"cacheable-request": "^6.0.0", "@types/cacheable-request": "^6.0.1",
"decompress-response": "^3.3.0", "cacheable-lookup": "^2.0.0",
"cacheable-request": "^7.0.1",
"decompress-response": "^5.0.0",
"duplexer3": "^0.1.4", "duplexer3": "^0.1.4",
"get-stream": "^4.1.0", "get-stream": "^5.0.0",
"lowercase-keys": "^1.0.1", "lowercase-keys": "^2.0.0",
"mimic-response": "^1.0.1", "mimic-response": "^2.1.0",
"p-cancelable": "^1.0.0", "p-cancelable": "^2.0.0",
"to-readable-stream": "^1.0.0", "p-event": "^4.0.0",
"url-parse-lax": "^3.0.0" "responselike": "^2.0.0",
"to-readable-stream": "^2.0.0",
"type-fest": "^0.10.0"
},
"dependencies": {
"get-stream": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz",
"integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==",
"requires": {
"pump": "^3.0.0"
}
},
"type-fest": {
"version": "0.10.0",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.10.0.tgz",
"integrity": "sha512-EUV9jo4sffrwlg8s0zDhP0T2WD3pru5Xi0+HTE3zTUmBaZNhfkite9PdSJwdXLwPVW0jnAHT56pZHIOYckPEiw=="
}
} }
}, },
"graceful-fs": { "graceful-fs": {
@ -7335,8 +7485,7 @@
"http-cache-semantics": { "http-cache-semantics": {
"version": "4.1.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz",
"integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==", "integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ=="
"dev": true
}, },
"http-deceiver": { "http-deceiver": {
"version": "1.2.7", "version": "1.2.7",
@ -7945,10 +8094,9 @@
"dev": true "dev": true
}, },
"json-buffer": { "json-buffer": {
"version": "3.0.0", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz",
"integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=", "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ=="
"dev": true
}, },
"json-parse-better-errors": { "json-parse-better-errors": {
"version": "1.0.2", "version": "1.0.2",
@ -8020,12 +8168,11 @@
} }
}, },
"keyv": { "keyv": {
"version": "3.1.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/keyv/-/keyv-3.1.0.tgz", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.0.0.tgz",
"integrity": "sha512-9ykJ/46SN/9KPM/sichzQ7OvXyGDYKGTaDlKMGCAlg2UK8KRy4jb0d8sFc+0Tt0YYnThq8X2RZgCg74RPxgcVA==", "integrity": "sha512-U7ioE8AimvRVLfw4LffyOIRhL2xVgmE8T22L6i0BucSnBUyv4w+I7VN/zVZwRKHOI6ZRUcdMdWHQ8KSUvGpEog==",
"dev": true,
"requires": { "requires": {
"json-buffer": "3.0.0" "json-buffer": "3.0.1"
} }
}, },
"killable": { "killable": {
@ -8187,10 +8334,9 @@
} }
}, },
"lowercase-keys": { "lowercase-keys": {
"version": "1.0.1", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz", "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz",
"integrity": "sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==", "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA=="
"dev": true
}, },
"lru-cache": { "lru-cache": {
"version": "5.1.1", "version": "5.1.1",
@ -8404,10 +8550,9 @@
"dev": true "dev": true
}, },
"mimic-response": { "mimic-response": {
"version": "1.0.1", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz",
"integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==", "integrity": "sha512-wXqjST+SLt7R009ySCglWBCFpjUygmCIfD790/kVbiGmUgfYGuB14PiTd5DwVxSV4NcYHjzMkoj5LjQZwTQLEA=="
"dev": true
}, },
"min-document": { "min-document": {
"version": "2.19.0", "version": "2.19.0",
@ -9106,8 +9251,7 @@
"normalize-url": { "normalize-url": {
"version": "4.5.0", "version": "4.5.0",
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz", "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz",
"integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ==", "integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ=="
"dev": true
}, },
"npm-conf": { "npm-conf": {
"version": "1.1.3", "version": "1.1.3",
@ -9388,10 +9532,9 @@
"dev": true "dev": true
}, },
"p-cancelable": { "p-cancelable": {
"version": "1.1.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.1.0.tgz", "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.0.0.tgz",
"integrity": "sha512-s73XxOZ4zpt1edZYZzvhqFa6uvQc1vwUa0K0BdtIZgQMAJj9IbebH+JkgKZc9h+B05PKHLOTl4ajG1BmNrVZlw==", "integrity": "sha512-wvPXDmbMmu2ksjkB4Z3nZWTSkJEb9lqVdMaCKpZUGJG9TMiNp9XcbG3fn9fPKjem04fJMJnXoyFPk2FmgiaiNg=="
"dev": true
}, },
"p-defer": { "p-defer": {
"version": "1.0.0", "version": "1.0.0",
@ -9399,11 +9542,18 @@
"integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=", "integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=",
"dev": true "dev": true
}, },
"p-event": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/p-event/-/p-event-4.1.0.tgz",
"integrity": "sha512-4vAd06GCsgflX4wHN1JqrMzBh/8QZ4j+rzp0cd2scXRwuBEv+QR3wrVA5aLhWDLw4y2WgDKvzWF3CCLmVM1UgA==",
"requires": {
"p-timeout": "^2.0.1"
}
},
"p-finally": { "p-finally": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",
"integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=", "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4="
"dev": true
}, },
"p-is-promise": { "p-is-promise": {
"version": "2.1.0", "version": "2.1.0",
@ -9461,6 +9611,14 @@
"retry": "^0.12.0" "retry": "^0.12.0"
} }
}, },
"p-timeout": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-2.0.1.tgz",
"integrity": "sha512-88em58dDVB/KzPEx1X0N3LwFfYZPyDc4B6eF38M1rk9VTZMbxXXgjugz8mmwpS9Ox4BDZ+t6t3QP5+/gazweIA==",
"requires": {
"p-finally": "^1.0.0"
}
},
"p-try": { "p-try": {
"version": "2.2.0", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
@ -9479,11 +9637,140 @@
"semver": "^6.2.0" "semver": "^6.2.0"
}, },
"dependencies": { "dependencies": {
"@sindresorhus/is": {
"version": "0.14.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz",
"integrity": "sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ==",
"dev": true
},
"@szmarczak/http-timer": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-1.1.2.tgz",
"integrity": "sha512-XIB2XbzHTN6ieIjfIMV9hlVcfPU26s2vafYWQcZHWXHOxiaRZYEDKEwdl129Zyg50+foYV2jCgtrqSA6qNuNSA==",
"dev": true,
"requires": {
"defer-to-connect": "^1.0.1"
}
},
"cacheable-request": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.1.0.tgz",
"integrity": "sha512-Oj3cAGPCqOZX7Rz64Uny2GYAZNliQSqfbePrgAQ1wKAihYmCUnraBtJtKcGR4xz7wF+LoJC+ssFZvv5BgF9Igg==",
"dev": true,
"requires": {
"clone-response": "^1.0.2",
"get-stream": "^5.1.0",
"http-cache-semantics": "^4.0.0",
"keyv": "^3.0.0",
"lowercase-keys": "^2.0.0",
"normalize-url": "^4.1.0",
"responselike": "^1.0.2"
},
"dependencies": {
"get-stream": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz",
"integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==",
"dev": true,
"requires": {
"pump": "^3.0.0"
}
},
"lowercase-keys": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz",
"integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==",
"dev": true
}
}
},
"decompress-response": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz",
"integrity": "sha1-gKTdMjdIOEv6JICDYirt7Jgq3/M=",
"dev": true,
"requires": {
"mimic-response": "^1.0.0"
}
},
"defer-to-connect": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-1.1.3.tgz",
"integrity": "sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ==",
"dev": true
},
"got": {
"version": "9.6.0",
"resolved": "https://registry.npmjs.org/got/-/got-9.6.0.tgz",
"integrity": "sha512-R7eWptXuGYxwijs0eV+v3o6+XH1IqVK8dJOEecQfTmkncw9AV4dcw/Dhxi8MdlqPthxxpZyizMzyg8RTmEsG+Q==",
"dev": true,
"requires": {
"@sindresorhus/is": "^0.14.0",
"@szmarczak/http-timer": "^1.1.2",
"cacheable-request": "^6.0.0",
"decompress-response": "^3.3.0",
"duplexer3": "^0.1.4",
"get-stream": "^4.1.0",
"lowercase-keys": "^1.0.1",
"mimic-response": "^1.0.1",
"p-cancelable": "^1.0.0",
"to-readable-stream": "^1.0.0",
"url-parse-lax": "^3.0.0"
}
},
"json-buffer": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz",
"integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=",
"dev": true
},
"keyv": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/keyv/-/keyv-3.1.0.tgz",
"integrity": "sha512-9ykJ/46SN/9KPM/sichzQ7OvXyGDYKGTaDlKMGCAlg2UK8KRy4jb0d8sFc+0Tt0YYnThq8X2RZgCg74RPxgcVA==",
"dev": true,
"requires": {
"json-buffer": "3.0.0"
}
},
"lowercase-keys": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz",
"integrity": "sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==",
"dev": true
},
"mimic-response": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz",
"integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==",
"dev": true
},
"p-cancelable": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.1.0.tgz",
"integrity": "sha512-s73XxOZ4zpt1edZYZzvhqFa6uvQc1vwUa0K0BdtIZgQMAJj9IbebH+JkgKZc9h+B05PKHLOTl4ajG1BmNrVZlw==",
"dev": true
},
"responselike": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/responselike/-/responselike-1.0.2.tgz",
"integrity": "sha1-kYcg7ztjHFZCvgaPFa3lpG9Loec=",
"dev": true,
"requires": {
"lowercase-keys": "^1.0.0"
}
},
"semver": { "semver": {
"version": "6.3.0", "version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true "dev": true
},
"to-readable-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/to-readable-stream/-/to-readable-stream-1.0.0.tgz",
"integrity": "sha512-Iq25XBt6zD5npPhlLVXGFN3/gyR2/qODcKNNyTMd4vbm39HUaOiAM4PMq0eMVC/Tkxz+Zjdsc55g9yyz+Yq00Q==",
"dev": true
} }
} }
}, },
@ -10534,12 +10821,11 @@
"dev": true "dev": true
}, },
"responselike": { "responselike": {
"version": "1.0.2", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/responselike/-/responselike-1.0.2.tgz", "resolved": "https://registry.npmjs.org/responselike/-/responselike-2.0.0.tgz",
"integrity": "sha1-kYcg7ztjHFZCvgaPFa3lpG9Loec=", "integrity": "sha512-xH48u3FTB9VsZw7R+vvgaKeLKzT6jOogbQhEe/jewwnZgzPcnyWui2Av6JpoYZF/91uueC+lqhWqeURw5/qhCw==",
"dev": true,
"requires": { "requires": {
"lowercase-keys": "^1.0.0" "lowercase-keys": "^2.0.0"
} }
}, },
"restore-cursor": { "restore-cursor": {
@ -11777,10 +12063,9 @@
} }
}, },
"to-readable-stream": { "to-readable-stream": {
"version": "1.0.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/to-readable-stream/-/to-readable-stream-1.0.0.tgz", "resolved": "https://registry.npmjs.org/to-readable-stream/-/to-readable-stream-2.1.0.tgz",
"integrity": "sha512-Iq25XBt6zD5npPhlLVXGFN3/gyR2/qODcKNNyTMd4vbm39HUaOiAM4PMq0eMVC/Tkxz+Zjdsc55g9yyz+Yq00Q==", "integrity": "sha512-o3Qa6DGg1CEXshSdvWNX2sN4QHqg03SPq7U6jPXRahlQdl5dK8oXjkU/2/sGrnOZKeGV1zLSO8qPwyKklPPE7w=="
"dev": true
}, },
"to-regex": { "to-regex": {
"version": "3.0.2", "version": "3.0.2",
@ -12640,7 +12925,8 @@
}, },
"minimist": { "minimist": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
"dev": true "dev": true
}, },
"p-locate": { "p-locate": {

View File

@ -31,11 +31,11 @@
"dependencies": { "dependencies": {
"adm-zip": "^0.4.14", "adm-zip": "^0.4.14",
"async": "^3.2.0", "async": "^3.2.0",
"axios": "^0.19.2",
"discord-rpc": "3.1.0", "discord-rpc": "3.1.0",
"electron-updater": "^4.2.4", "electron-updater": "^4.2.4",
"fs-extra": "^9.0.0", "fs-extra": "^9.0.0",
"github-syntax-dark": "^0.5.0", "github-syntax-dark": "^0.5.0",
"got": "^10.7.0",
"jquery": "^3.5.0", "jquery": "^3.5.0",
"moment": "^2.24.0", "moment": "^2.24.0",
"request": "^2.88.2", "request": "^2.88.2",

View File

@ -1,4 +1,4 @@
import { AxiosError } from "axios" import { GotError } from "got/dist/source"
/** /**
* @see https://wiki.vg/Authentication#Errors * @see https://wiki.vg/Authentication#Errors
@ -22,12 +22,18 @@ export interface MojangResponse<T> {
data: T data: T
responseCode: MojangResponseCode responseCode: MojangResponseCode
error?: AxiosError error?: GotError
isInternalError?: boolean isInternalError?: boolean
} }
export function deciperResponseCode(body: { error: string, errorMessage: string, cause?: string }): MojangResponseCode { export interface MojangErrorBody {
error: string
errorMessage: string
cause?: string
}
export function deciperResponseCode(body: MojangErrorBody): MojangResponseCode {
if(body.error === 'Method Not Allowed') { if(body.error === 'Method Not Allowed') {
return MojangResponseCode.ERROR_METHOD_NOT_ALLOWED return MojangResponseCode.ERROR_METHOD_NOT_ALLOWED

View File

@ -1,10 +1,10 @@
import { LoggerUtil } from '../logging/loggerutil' import { LoggerUtil } from '../logging/loggerutil'
import { Agent } from './model/auth/Agent' import { Agent } from './model/auth/Agent'
import { Status, StatusColor } from './model/internal/Status' import { Status, StatusColor } from './model/internal/Status'
import axios, { AxiosError } from 'axios' import got, { RequestError, HTTPError, TimeoutError, GotError, ParseError } from 'got'
import { Session } from './model/auth/Session' import { Session } from './model/auth/Session'
import { AuthPayload } from './model/auth/AuthPayload' import { AuthPayload } from './model/auth/AuthPayload'
import { MojangResponse, MojangResponseCode, deciperResponseCode, isInternalError } from './model/internal/Response' import { MojangResponse, MojangResponseCode, deciperResponseCode, isInternalError, MojangErrorBody } from './model/internal/Response'
export class Mojang { export class Mojang {
@ -13,7 +13,18 @@ export class Mojang {
private static readonly TIMEOUT = 2500 private static readonly TIMEOUT = 2500
public static readonly AUTH_ENDPOINT = 'https://authserver.mojang.com' public static readonly AUTH_ENDPOINT = 'https://authserver.mojang.com'
public static readonly STATUS_ENDPOINT = 'https://status.mojang.com/check' public static readonly STATUS_ENDPOINT = 'https://status.mojang.com'
private static authClient = got.extend({
prefixUrl: Mojang.AUTH_ENDPOINT,
responseType: 'json',
retry: 0
})
private static statusClient = got.extend({
prefixUrl: Mojang.STATUS_ENDPOINT,
responseType: 'json',
retry: 0
})
public static readonly MINECRAFT_AGENT: Agent = { public static readonly MINECRAFT_AGENT: Agent = {
name: 'Minecraft', name: 'Minecraft',
@ -78,24 +89,30 @@ export class Mojang {
} }
} }
private static handleAxiosError<T>(operation: string, error: AxiosError, dataProvider: () => T): MojangResponse<T> { private static handleGotError<T>(operation: string, error: GotError, dataProvider: () => T): MojangResponse<T> {
const response: MojangResponse<T> = { const response: MojangResponse<T> = {
data: dataProvider(), data: dataProvider(),
responseCode: MojangResponseCode.ERROR, responseCode: MojangResponseCode.ERROR,
error error
} }
if(error.response) { if(error instanceof HTTPError) {
response.responseCode = deciperResponseCode(error.response.data) response.responseCode = deciperResponseCode(error.response.body as MojangErrorBody)
Mojang.logger.error(`Error during ${operation} request (HTTP Response ${error.response.status})`, error) Mojang.logger.error(`Error during ${operation} request (HTTP Response ${error.response.statusCode})`, error)
Mojang.logger.debug('Response Details:') Mojang.logger.debug('Response Details:')
Mojang.logger.debug('Data:', error.response.data) Mojang.logger.debug('Body:', error.response.body)
Mojang.logger.debug('Headers:', error.response.headers) Mojang.logger.debug('Headers:', error.response.headers)
} else if(error.request) { } else if(error instanceof RequestError) {
Mojang.logger.error(`${operation} request recieved no response.`, error) Mojang.logger.error(`${operation} request recieved no response (${error.code}).`, error)
} else if(error instanceof TimeoutError) {
Mojang.logger.error(`${operation} request timed out (${error.timings.phases.total}ms).`)
} else if(error instanceof ParseError) {
Mojang.logger.error(`${operation} request recieved unexepected body (Parse Error).`)
} else { } else {
// CacheError, ReadError, MaxRedirectsError, UnsupportedProtocolError, CancelError
Mojang.logger.error(`Error during ${operation} request.`, error) Mojang.logger.error(`Error during ${operation} request.`, error)
} }
response.isInternalError = isInternalError(response.responseCode) response.isInternalError = isInternalError(response.responseCode)
return response return response
@ -118,11 +135,11 @@ export class Mojang {
public static async status(): Promise<MojangResponse<Status[]>>{ public static async status(): Promise<MojangResponse<Status[]>>{
try { try {
const res = await axios.get<{[service: string]: StatusColor}[]>(Mojang.STATUS_ENDPOINT, { timeout: Mojang.TIMEOUT }) const res = await Mojang.statusClient.get<{[service: string]: StatusColor}[]>('check')
Mojang.expectSpecificSuccess('Mojang Status', 200, res.status) Mojang.expectSpecificSuccess('Mojang Status', 200, res.statusCode)
res.data.forEach(status => { res.body.forEach(status => {
const entry = Object.entries(status)[0] const entry = Object.entries(status)[0]
for(let i=0; i<Mojang.statuses.length; i++) { for(let i=0; i<Mojang.statuses.length; i++) {
if(Mojang.statuses[i].service === entry[0]) { if(Mojang.statuses[i].service === entry[0]) {
@ -139,7 +156,7 @@ export class Mojang {
} catch(error) { } catch(error) {
return Mojang.handleAxiosError('Mojang Status', error as AxiosError, () => { return Mojang.handleGotError('Mojang Status', error as GotError, () => {
for(let i=0; i<Mojang.statuses.length; i++){ for(let i=0; i<Mojang.statuses.length; i++){
Mojang.statuses[i].status = StatusColor.GREY Mojang.statuses[i].status = StatusColor.GREY
} }
@ -170,25 +187,25 @@ export class Mojang {
try { try {
const data: AuthPayload = { const json: AuthPayload = {
agent, agent,
username, username,
password, password,
requestUser requestUser
} }
if(clientToken != null){ if(clientToken != null){
data.clientToken = clientToken json.clientToken = clientToken
} }
const res = await axios.post<Session>(`${Mojang.AUTH_ENDPOINT}/authenticate`, data) const res = await Mojang.authClient.post<Session>('authenticate', { json })
Mojang.expectSpecificSuccess('Mojang Authenticate', 200, res.status) Mojang.expectSpecificSuccess('Mojang Authenticate', 200, res.statusCode)
return { return {
data: res.data, data: res.body,
responseCode: MojangResponseCode.SUCCESS responseCode: MojangResponseCode.SUCCESS
} }
} catch(err) { } catch(err) {
return Mojang.handleAxiosError('Mojang Authenticate', err, () => null) return Mojang.handleGotError('Mojang Authenticate', err as GotError, () => null)
} }
} }
@ -206,27 +223,27 @@ export class Mojang {
try { try {
const data = { const json = {
accessToken, accessToken,
clientToken clientToken
} }
const res = await axios.post(`${Mojang.AUTH_ENDPOINT}/validate`, data) const res = await Mojang.authClient.post('validate', { json })
Mojang.expectSpecificSuccess('Mojang Validate', 204, res.status) Mojang.expectSpecificSuccess('Mojang Validate', 204, res.statusCode)
return { return {
data: res.status === 204, data: res.statusCode === 204,
responseCode: MojangResponseCode.SUCCESS responseCode: MojangResponseCode.SUCCESS
} }
} catch(err) { } catch(err) {
if(err.response && err.response.status === 403) { if(err instanceof HTTPError && err.response.statusCode === 403) {
return { return {
data: false, data: false,
responseCode: MojangResponseCode.SUCCESS responseCode: MojangResponseCode.SUCCESS
} }
} }
return Mojang.handleAxiosError('Mojang Validate', err, () => false) return Mojang.handleGotError('Mojang Validate', err as GotError, () => false)
} }
} }
@ -244,13 +261,13 @@ export class Mojang {
try { try {
const data = { const json = {
accessToken, accessToken,
clientToken clientToken
} }
const res = await axios.post(`${Mojang.AUTH_ENDPOINT}/invalidate`, data) const res = await Mojang.authClient.post('invalidate', { json })
Mojang.expectSpecificSuccess('Mojang Invalidate', 204, res.status) Mojang.expectSpecificSuccess('Mojang Invalidate', 204, res.statusCode)
return { return {
data: undefined, data: undefined,
@ -258,7 +275,7 @@ export class Mojang {
} }
} catch(err) { } catch(err) {
return Mojang.handleAxiosError('Mojang Invalidate', err, () => undefined) return Mojang.handleGotError('Mojang Invalidate', err as GotError, () => undefined)
} }
} }
@ -278,22 +295,22 @@ export class Mojang {
try { try {
const data = { const json = {
accessToken, accessToken,
clientToken, clientToken,
requestUser requestUser
} }
const res = await axios.post<Session>(`${Mojang.AUTH_ENDPOINT}/refresh`, data) const res = await Mojang.authClient.post<Session>('refresh', { json })
Mojang.expectSpecificSuccess('Mojang Refresh', 200, res.status) Mojang.expectSpecificSuccess('Mojang Refresh', 200, res.statusCode)
return { return {
data: res.data, data: res.body,
responseCode: MojangResponseCode.SUCCESS responseCode: MojangResponseCode.SUCCESS
} }
} catch(err) { } catch(err) {
return Mojang.handleAxiosError('Mojang Refresh', err, () => null) return Mojang.handleGotError('Mojang Refresh', err as GotError, () => null)
} }
} }

View File

@ -1,7 +1,6 @@
import { Mojang } from "../../src/main/mojang/mojang" import { Mojang } from "../../src/main/mojang/mojang"
import { expect } from 'chai' import { expect } from 'chai'
import nock from 'nock' import nock from 'nock'
import { URL } from 'url'
import { Session } from "../../src/main/mojang/model/auth/Session" import { Session } from "../../src/main/mojang/model/auth/Session"
import { MojangResponseCode } from "../../src/main/mojang/model/internal/Response" import { MojangResponseCode } from "../../src/main/mojang/model/internal/Response"
@ -18,13 +17,16 @@ function expectMojangResponse(res: any, responseCode: MojangResponseCode, negate
describe('Mojang Errors', () => { describe('Mojang Errors', () => {
after(() => {
nock.cleanAll()
})
it('Status (Offline)', async () => { it('Status (Offline)', async () => {
const defStatusHack = Mojang['statuses'] const defStatusHack = Mojang['statuses']
const url = new URL(Mojang.STATUS_ENDPOINT)
nock(url.origin) nock(Mojang.STATUS_ENDPOINT)
.get(url.pathname) .get('/check')
.reply(500, 'Service temprarily offline.') .reply(500, 'Service temprarily offline.')
const res = await Mojang.status(); const res = await Mojang.status();
@ -58,10 +60,9 @@ describe('Mojang Status', () => {
it('Status (Online)', async () => { it('Status (Online)', async () => {
const defStatusHack = Mojang['statuses'] const defStatusHack = Mojang['statuses']
const url = new URL(Mojang.STATUS_ENDPOINT)
nock(url.origin) nock(Mojang.STATUS_ENDPOINT)
.get(url.pathname) .get('/check')
.reply(200, defStatusHack) .reply(200, defStatusHack)
const res = await Mojang.status(); const res = await Mojang.status();