aboutsummaryrefslogtreecommitdiff
path: root/src/mojang.ts
diff options
context:
space:
mode:
authordependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2021-09-06 21:06:22 +0000
committerGitHub <noreply@github.com>2021-09-06 21:06:22 +0000
commit487f208565894f332ca58c13e1b208c3beb9c8c6 (patch)
treeb3209e94cc63658b5430bc1949b80140cc27efe4 /src/mojang.ts
parent4f03cb71b30978b277ff292dbddeba182117a7cb (diff)
downloadskyblock-api-487f208565894f332ca58c13e1b208c3beb9c8c6.tar.gz
skyblock-api-487f208565894f332ca58c13e1b208c3beb9c8c6.tar.bz2
skyblock-api-487f208565894f332ca58c13e1b208c3beb9c8c6.zip
Bump node-fetch from 2.6.1 to 3.0.0 (#116)
* Bump node-fetch from 2.6.1 to 3.0.0 Bumps [node-fetch](https://github.com/node-fetch/node-fetch) from 2.6.1 to 3.0.0. - [Release notes](https://github.com/node-fetch/node-fetch/releases) - [Changelog](https://github.com/node-fetch/node-fetch/blob/main/docs/CHANGELOG.md) - [Commits](https://github.com/node-fetch/node-fetch/compare/v2.6.1...v3.0.0) --- updated-dependencies: - dependency-name: node-fetch dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix issues with node fetch 3.0 * change module to esnext instead of commonjs * fix imports and tests * fix package-lock.json Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: mat <github@matdoes.dev> Co-authored-by: mat <27899617+mat-1@users.noreply.github.com>
Diffstat (limited to 'src/mojang.ts')
-rw-r--r--src/mojang.ts16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/mojang.ts b/src/mojang.ts
index 84c8c7d..9b224d6 100644
--- a/src/mojang.ts
+++ b/src/mojang.ts
@@ -2,10 +2,10 @@
* Fetch the Mojang username API through api.ashcon.app
*/
-import fetch from 'node-fetch'
+import { isUuid, undashUuid } from './util.js'
import * as nodeFetch from 'node-fetch'
+import fetch from 'node-fetch'
import { Agent } from 'https'
-import { isUuid, undashUuid } from './util'
// We need to create an agent to prevent memory leaks
const httpsAgent = new Agent({
@@ -21,7 +21,7 @@ interface MojangApiResponse {
/**
* Get mojang api data from the session server
*/
-export async function profileFromUuid(uuid: string): Promise<MojangApiResponse> {
+export let profileFromUuid = async function profileFromUuid(uuid: string): Promise<MojangApiResponse> {
let fetchResponse: nodeFetch.Response
try {
@@ -56,7 +56,7 @@ export async function profileFromUuid(uuid: string): Promise<MojangApiResponse>
}
-export async function profileFromUsername(username: string): Promise<MojangApiResponse> {
+export let profileFromUsername = async function profileFromUsername(username: string): Promise<MojangApiResponse> {
// since we don't care about anything other than the uuid, we can use /uuid/ instead of /user/
let fetchResponse: nodeFetch.Response
@@ -118,9 +118,15 @@ export async function profileFromUsernameAlternative(username: string): Promise<
}
}
-export async function profileFromUser(user: string): Promise<MojangApiResponse> {
+export let profileFromUser = async function profileFromUser(user: string): Promise<MojangApiResponse> {
if (isUuid(user)) {
return await profileFromUuid(user)
} else
return await profileFromUsername(user)
}
+
+
+// this is necessary for mocking in the tests because es6
+export function mockProfileFromUuid($value) { profileFromUuid = $value }
+export function mockProfileFromUsername($value) { profileFromUsername = $value }
+export function mockProfileFromUser($value) { profileFromUser = $value }