UNPKG

typerinth

Version:

A TypeScript library for interacting with the Modrinth API.

43 lines (42 loc) 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const url_1 = require("url"); const Route_1 = require("../Route"); const errors_1 = require("../../errors"); const requestbody_1 = require("../../util/requestbody"); class GetTokenRoute extends Route_1.Route { code; clientId; redirectUri; constructor(baseUrl, ua, cacheManager, authorization, code, clientId, redirectUri) { super(baseUrl, ua, cacheManager, authorization); this.code = code; this.clientId = clientId; this.redirectUri = redirectUri; } getCacheKey() { return null; } getUrl() { return Route_1.Route.addPathSegment(new url_1.URL('https://api.modrinth.com'), '/_internal/oauth/token'); } getFetchMethod() { return 'POST'; } getFetchBody() { return new requestbody_1.UrlEncodedRequestBody({ code: this.code, client_id: this.clientId, redirect_uri: this.redirectUri, grant_type: 'authorization_code', }); } parseData(data) { if (!data) throw new errors_1.UnexpectedApiError('Unexpected empty response'); if (data.error) throw new errors_1.ApiError(data.error, data.description); return data; } } exports.default = GetTokenRoute;