diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..7209452 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,26 @@ +name: Testing +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Setup repo + uses: actions/checkout@v4 + + - name: Setup Bun + uses: oven-sh/setup-bun@v2 + + - name: Run linter + run: bun ci + + - name: Run tests + run: bun test diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..750946b --- /dev/null +++ b/biome.json @@ -0,0 +1,34 @@ +{ + "$schema": "https://biomejs.dev/schemas/2.3.11/schema.json", + "vcs": { + "enabled": true, + "clientKind": "git", + "useIgnoreFile": true + }, + "files": { + "ignoreUnknown": false + }, + "formatter": { + "enabled": true, + "indentStyle": "tab" + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true + } + }, + "javascript": { + "formatter": { + "quoteStyle": "double" + } + }, + "assist": { + "enabled": true, + "actions": { + "source": { + "organizeImports": "on" + } + } + } +} diff --git a/bun.lock b/bun.lock new file mode 100644 index 0000000..8221974 --- /dev/null +++ b/bun.lock @@ -0,0 +1,71 @@ +{ + "lockfileVersion": 1, + "configVersion": 0, + "workspaces": { + "": { + "name": "mcprofile", + "dependencies": { + "node-fetch": "^3.3.2", + }, + "devDependencies": { + "@biomejs/biome": "2.3.11", + "bun": "^1.3.5", + }, + }, + }, + "packages": { + "@biomejs/biome": ["@biomejs/biome@2.3.11", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "2.3.11", "@biomejs/cli-darwin-x64": "2.3.11", "@biomejs/cli-linux-arm64": "2.3.11", "@biomejs/cli-linux-arm64-musl": "2.3.11", "@biomejs/cli-linux-x64": "2.3.11", "@biomejs/cli-linux-x64-musl": "2.3.11", "@biomejs/cli-win32-arm64": "2.3.11", "@biomejs/cli-win32-x64": "2.3.11" }, "bin": { "biome": "bin/biome" } }, "sha512-/zt+6qazBWguPG6+eWmiELqO+9jRsMZ/DBU3lfuU2ngtIQYzymocHhKiZRyrbra4aCOoyTg/BmY+6WH5mv9xmQ=="], + + "@biomejs/cli-darwin-arm64": ["@biomejs/cli-darwin-arm64@2.3.11", "", { "os": "darwin", "cpu": "arm64" }, "sha512-/uXXkBcPKVQY7rc9Ys2CrlirBJYbpESEDme7RKiBD6MmqR2w3j0+ZZXRIL2xiaNPsIMMNhP1YnA+jRRxoOAFrA=="], + + "@biomejs/cli-darwin-x64": ["@biomejs/cli-darwin-x64@2.3.11", "", { "os": "darwin", "cpu": "x64" }, "sha512-fh7nnvbweDPm2xEmFjfmq7zSUiox88plgdHF9OIW4i99WnXrAC3o2P3ag9judoUMv8FCSUnlwJCM1B64nO5Fbg=="], + + "@biomejs/cli-linux-arm64": ["@biomejs/cli-linux-arm64@2.3.11", "", { "os": "linux", "cpu": "arm64" }, "sha512-l4xkGa9E7Uc0/05qU2lMYfN1H+fzzkHgaJoy98wO+b/7Gl78srbCRRgwYSW+BTLixTBrM6Ede5NSBwt7rd/i6g=="], + + "@biomejs/cli-linux-arm64-musl": ["@biomejs/cli-linux-arm64-musl@2.3.11", "", { "os": "linux", "cpu": "arm64" }, "sha512-XPSQ+XIPZMLaZ6zveQdwNjbX+QdROEd1zPgMwD47zvHV+tCGB88VH+aynyGxAHdzL+Tm/+DtKST5SECs4iwCLg=="], + + "@biomejs/cli-linux-x64": ["@biomejs/cli-linux-x64@2.3.11", "", { "os": "linux", "cpu": "x64" }, "sha512-/1s9V/H3cSe0r0Mv/Z8JryF5x9ywRxywomqZVLHAoa/uN0eY7F8gEngWKNS5vbbN/BsfpCG5yeBT5ENh50Frxg=="], + + "@biomejs/cli-linux-x64-musl": ["@biomejs/cli-linux-x64-musl@2.3.11", "", { "os": "linux", "cpu": "x64" }, "sha512-vU7a8wLs5C9yJ4CB8a44r12aXYb8yYgBn+WeyzbMjaCMklzCv1oXr8x+VEyWodgJt9bDmhiaW/I0RHbn7rsNmw=="], + + "@biomejs/cli-win32-arm64": ["@biomejs/cli-win32-arm64@2.3.11", "", { "os": "win32", "cpu": "arm64" }, "sha512-PZQ6ElCOnkYapSsysiTy0+fYX+agXPlWugh6+eQ6uPKI3vKAqNp6TnMhoM3oY2NltSB89hz59o8xIfOdyhi9Iw=="], + + "@biomejs/cli-win32-x64": ["@biomejs/cli-win32-x64@2.3.11", "", { "os": "win32", "cpu": "x64" }, "sha512-43VrG813EW+b5+YbDbz31uUsheX+qFKCpXeY9kfdAx+ww3naKxeVkTD9zLIWxUPfJquANMHrmW3wbe/037G0Qg=="], + + "@oven/bun-darwin-aarch64": ["@oven/bun-darwin-aarch64@1.3.5", "", { "os": "darwin", "cpu": "arm64" }, "sha512-8GvNtMo0NINM7Emk9cNAviCG3teEgr3BUX9be0+GD029zIagx2Sf54jMui1Eu1IpFm7nWHODuLEefGOQNaJ0gQ=="], + + "@oven/bun-darwin-x64": ["@oven/bun-darwin-x64@1.3.5", "", { "os": "darwin", "cpu": "x64" }, "sha512-r33eHQOHAwkuiBJIwmkXIyqONQOQMnd1GMTpDzaxx9vf9+svby80LZO9Hcm1ns6KT/TBRFyODC/0loA7FAaffg=="], + + "@oven/bun-darwin-x64-baseline": ["@oven/bun-darwin-x64-baseline@1.3.5", "", { "os": "darwin", "cpu": "x64" }, "sha512-p5q3rJk48qhLuLBOFehVc+kqCE03YrswTc6NCxbwsxiwfySXwcAvpF2KWKF/ZZObvvR8hCCvqe1F81b2p5r2dg=="], + + "@oven/bun-linux-aarch64": ["@oven/bun-linux-aarch64@1.3.5", "", { "os": "linux", "cpu": "arm64" }, "sha512-zkcHPI23QxJ1TdqafhgkXt1NOEN8o5C460sVeNnrhfJ43LwZgtfcvcQE39x/pBedu67fatY8CU0iY00nOh46ZQ=="], + + "@oven/bun-linux-aarch64-musl": ["@oven/bun-linux-aarch64-musl@1.3.5", "", { "os": "linux", "cpu": "arm64" }, "sha512-HKBeUlJdNduRkzJKZ5DXM+pPqntfC50/Hu2X65jVX0Y7hu/6IC8RaUTqpr8FtCZqqmc9wDK0OTL+Mbi9UQIKYQ=="], + + "@oven/bun-linux-x64": ["@oven/bun-linux-x64@1.3.5", "", { "os": "linux", "cpu": "x64" }, "sha512-n7zhKTSDZS0yOYg5Rq8easZu5Y/o47sv0c7yGr2ciFdcie9uYV55fZ7QMqhWMGK33ezCSikh5EDkUMCIvfWpjA=="], + + "@oven/bun-linux-x64-baseline": ["@oven/bun-linux-x64-baseline@1.3.5", "", { "os": "linux", "cpu": "x64" }, "sha512-FeCQyBU62DMuB0nn01vPnf3McXrKOsrK9p7sHaBFYycw0mmoU8kCq/WkBkGMnLuvQljJSyen8QBTx+fXdNupWg=="], + + "@oven/bun-linux-x64-musl": ["@oven/bun-linux-x64-musl@1.3.5", "", { "os": "linux", "cpu": "x64" }, "sha512-XkCCHkByYn8BIDvoxnny898znju4xnW2kvFE8FT5+0Y62cWdcBGMZ9RdsEUTeRz16k8hHtJpaSfLcEmNTFIwRQ=="], + + "@oven/bun-linux-x64-musl-baseline": ["@oven/bun-linux-x64-musl-baseline@1.3.5", "", { "os": "linux", "cpu": "x64" }, "sha512-TJiYC7KCr0XxFTsxgwQOeE7dncrEL/RSyL0EzSL3xRkrxJMWBCvCSjQn7LV1i6T7hFst0+3KoN3VWvD5BinqHA=="], + + "@oven/bun-windows-x64": ["@oven/bun-windows-x64@1.3.5", "", { "os": "win32", "cpu": "x64" }, "sha512-T3xkODItb/0ftQPFsZDc7EAX2D6A4TEazQ2YZyofZToO8Q7y8YT8ooWdhd0BQiTCd66uEvgE1DCZetynwg2IoA=="], + + "@oven/bun-windows-x64-baseline": ["@oven/bun-windows-x64-baseline@1.3.5", "", { "os": "win32", "cpu": "x64" }, "sha512-rtVQB9/1XK8FWJgFtsOthbPifRMYypgJwxu+pK3NHx8WvFKmq7HcPDqNr8xLzGULjQEO7eAo2aOZfONOwYz+5g=="], + + "bun": ["bun@1.3.5", "", { "optionalDependencies": { "@oven/bun-darwin-aarch64": "1.3.5", "@oven/bun-darwin-x64": "1.3.5", "@oven/bun-darwin-x64-baseline": "1.3.5", "@oven/bun-linux-aarch64": "1.3.5", "@oven/bun-linux-aarch64-musl": "1.3.5", "@oven/bun-linux-x64": "1.3.5", "@oven/bun-linux-x64-baseline": "1.3.5", "@oven/bun-linux-x64-musl": "1.3.5", "@oven/bun-linux-x64-musl-baseline": "1.3.5", "@oven/bun-windows-x64": "1.3.5", "@oven/bun-windows-x64-baseline": "1.3.5" }, "os": [ "linux", "win32", "darwin", ], "cpu": [ "x64", "arm64", ], "bin": { "bun": "bin/bun.exe", "bunx": "bin/bunx.exe" } }, "sha512-c1YHIGUfgvYPJmLug5QiLzNWlX2Dg7X/67JWu1Va+AmMXNXzC/KQn2lgQ7rD+n1u1UqDpJMowVGGxTNpbPydNw=="], + + "data-uri-to-buffer": ["data-uri-to-buffer@4.0.1", "", {}, "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A=="], + + "fetch-blob": ["fetch-blob@3.2.0", "", { "dependencies": { "node-domexception": "^1.0.0", "web-streams-polyfill": "^3.0.3" } }, "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ=="], + + "formdata-polyfill": ["formdata-polyfill@4.0.10", "", { "dependencies": { "fetch-blob": "^3.1.2" } }, "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g=="], + + "node-domexception": ["node-domexception@1.0.0", "", {}, "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ=="], + + "node-fetch": ["node-fetch@3.3.2", "", { "dependencies": { "data-uri-to-buffer": "^4.0.0", "fetch-blob": "^3.1.4", "formdata-polyfill": "^4.0.10" } }, "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA=="], + + "web-streams-polyfill": ["web-streams-polyfill@3.3.3", "", {}, "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw=="], + } +} diff --git a/index.d.ts b/index.d.ts index 3d2783b..e0fa66b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,35 +1,35 @@ export interface JavaUser { - username: string, - uuid: string, - skin: string, - cape: string, - linked: boolean, - bedrock_gamertag?: string, - bedrock_xuid?: number, - bedrock_fuid?: string + username: string; + uuid: string; + skin: string; + cape: string; + linked: boolean; + bedrock_gamertag?: string; + bedrock_xuid?: number; + bedrock_fuid?: string; } export interface BedrockUser { - gamertag: string, - xuid: string, - floodgateuid: string, - icon: string, - gamescore: string, - accounttier: string, - textureid: string, - skin: string, - linked: boolean, - java_uuid?: string, - java_name?: string + gamertag: string; + xuid: string; + floodgateuid: string; + icon: string; + gamescore: string; + accounttier: string; + textureid: string; + skin: string; + linked: boolean; + java_uuid?: string; + java_name?: string; } export const java: { - getPlayerByUsername(username: string): Promise; - getPlayerByUUID(uuid: string): Promise; + getPlayerByUsername(username: string): Promise; + getPlayerByUUID(uuid: string): Promise; }; export const bedrock: { - getPlayerByUsername(gamertag: string): Promise; - getPlayerByXUID(xuid: string): Promise; - getPlayerByFUID(fuid: string): Promise; + getPlayerByUsername(gamertag: string): Promise; + getPlayerByXUID(xuid: string): Promise; + getPlayerByFUID(fuid: string): Promise; }; diff --git a/index.js b/index.js index f682cbd..aeb6e26 100644 --- a/index.js +++ b/index.js @@ -1,35 +1,46 @@ -import fetch from 'node-fetch'; -const BASE = 'https://mcprofile.io/api/v1'; +import fetch from "node-fetch"; + +const BASE = "https://mcprofile.io/api/v1"; export const java = { - getPlayerByUsername: async function(username) { - const response = await fetch(`${BASE}/java/username/${encodeURIComponent(username)}`); - if (!response.ok) throw new Error('Failed to fetch profile'); - return response.json(); - }, - getPlayerByUUID: async function(uuid) { - const response = await fetch(`${BASE}/java/uuid/${encodeURIComponent(uuid)}`); - if (!response.ok) throw new Error('Failed to fetch profile'); - return response.json(); - } -} + getPlayerByUsername: async (username) => { + const response = await fetch( + `${BASE}/java/username/${encodeURIComponent(username)}`, + ); + if (!response.ok) throw new Error("Failed to fetch profile"); + return response.json(); + }, + getPlayerByUUID: async (uuid) => { + const response = await fetch( + `${BASE}/java/uuid/${encodeURIComponent(uuid)}`, + ); + if (!response.ok) throw new Error("Failed to fetch profile"); + return response.json(); + }, +}; export const bedrock = { - getPlayerByUsername: async function(gamertag) { - const response = await fetch(`${BASE}/bedrock/gamertag/${encodeURIComponent(gamertag)}`); - if (!response.ok) throw new Error('Failed to fetch profile'); - return response.json(); - }, - getPlayerByXUID: async function(xuid) { - const response = await fetch(`${BASE}/bedrock/xuid/${encodeURIComponent(xuid)}`); - if (!response.ok) throw new Error('Failed to fetch profile'); - return response.json(); - }, - getPlayerByFUID: async function(xuid) { - const response = await fetch(`${BASE}/bedrock/fuid/${encodeURIComponent(fuid)}`); - if (!response.ok) throw new Error('Failed to fetch profile'); - return response.json(); - } -} + getPlayerByUsername: async (gamertag) => { + const response = await fetch( + `${BASE}/bedrock/gamertag/${encodeURIComponent(gamertag)}`, + ); + if (!response.ok) throw new Error("Failed to fetch profile"); + return response.json(); + }, + getPlayerByXUID: async (xuid) => { + const response = await fetch( + `${BASE}/bedrock/xuid/${encodeURIComponent(xuid)}`, + ); + if (!response.ok) throw new Error("Failed to fetch profile"); + return response.json(); + }, + getPlayerByFUID: async (fuid) => { + const response = await fetch( + `${BASE}/bedrock/fuid/${encodeURIComponent(fuid)}`, + ); + if (!response.ok) throw new Error("Failed to fetch profile"); + return response.json(); + }, +}; -export default {java, bedrock} \ No newline at end of file +export default { java, bedrock }; diff --git a/mcprofile.test.js b/mcprofile.test.js new file mode 100644 index 0000000..06b2c5f --- /dev/null +++ b/mcprofile.test.js @@ -0,0 +1,32 @@ +import { expect, test } from "bun:test" +import MCProfile from "./index.js"; + +test("getPlayerByUsername - Java", async () => { + const profile = await MCProfile.java.getPlayerByUsername("Notch"); + expect(profile.username).toBe("Notch"); + expect(profile.uuid).toBe("069a79f4-44e9-4726-a5be-fca90e38aaf5"); +}); + +test("getPlayerByUUID - Java", async () => { + const profile = await MCProfile.java.getPlayerByUUID("069a79f4-44e9-4726-a5be-fca90e38aaf5"); + expect(profile.username).toBe("Notch"); + expect(profile.uuid).toBe("069a79f4-44e9-4726-a5be-fca90e38aaf5"); +}); + +test("getPlayerByGamertag - Bedrock", async () => { + const profile = await MCProfile.bedrock.getPlayerByUsername("Notch"); + expect(profile.gamertag).toBe("Notch"); + expect(profile.xuid).toBe("2535453759792258"); +}); + +test("getPlayerByXUID - Bedrock", async () => { + const profile = await MCProfile.bedrock.getPlayerByXUID("2535453759792258"); + expect(profile.gamertag).toBe("Notch"); + expect(profile.xuid).toBe("2535453759792258"); +}); + +test("getPlayerByFUID - Bedrock", async () => { + const profile = await MCProfile.bedrock.getPlayerByFUID("00000000-0000-0000-0009-01fb54b26482"); + expect(profile.floodgateuid).toBe("00000000-0000-0000-0009-01fb54b26482"); + expect(profile.gamertag).toBe("Notch"); +}); \ No newline at end of file diff --git a/package.json b/package.json index e843b9c..e0b9453 100644 --- a/package.json +++ b/package.json @@ -1,27 +1,34 @@ { - "name": "mcprofile", - "version": "1.0.1", - "description": "Connect to mcprofile.io", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/profilelag/mcprofile.git" - }, - "keywords": [ - "minecraft" - ], - "author": "Nicholas Keller", - "license": "MIT", - "bugs": { - "url": "https://github.com/profilelag/mcprofile/issues" - }, - "homepage": "https://github.com/profilelag/mcprofile#readme", - "type": "module", - "dependencies": { - "node-fetch": "^3.3.2" - }, - "types": "index.d.ts" + "name": "mcprofile", + "version": "1.0.1", + "description": "Connect to mcprofile.io", + "main": "index.js", + "scripts": { + "ci": "biome ci", + "lint": "biome lint", + "test": "bun test" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/profilelag/mcprofile.git" + }, + "keywords": [ + "minecraft", + "mcprofile" + ], + "author": "Nicholas Keller", + "license": "MIT", + "bugs": { + "url": "https://github.com/profilelag/mcprofile/issues" + }, + "homepage": "https://github.com/profilelag/mcprofile#readme", + "type": "module", + "dependencies": { + "node-fetch": "^3.3.2" + }, + "types": "index.d.ts", + "devDependencies": { + "@biomejs/biome": "2.3.11", + "bun": "^1.3.5" + } }