UNPKG

esiil

Version:

Minimalist library for EVE Online's ESI

128 lines 3.97 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const defaults_1 = __importDefault(require("../../defaults")); const Fetchd_1 = require("../../libs/Fetchd"); const coreHelper_1 = require("./coreHelper"); class CoreClass { constructor(cfg) { this.scopes = cfg.scopes || []; this.state = cfg.state || ''; this.callbackURL = cfg.callbackURL; this.userAgent = defaults_1.default.userAgent; this.clientID = defaults_1.default.clientID; this.clientSecret = defaults_1.default.clientSecret; this.domainAndVersion = defaults_1.default.domainAndVersion(); this.queryParamStart = defaults_1.default.queryParamStart(); this.ccpJwt = { alg: '', e: '', kid: '', kty: '', n: '', use: '', }; this.loadCcpJwt(); } defaultRequestURL(state) { return (0, coreHelper_1._buildRequestURL)({ scopes: this.scopes, state, callbackURL: this.callbackURL, clientID: this.clientID, }); } targetedRequestURL(state, scopes) { return (0, coreHelper_1._buildRequestURL)({ scopes, state, callbackURL: this.callbackURL, clientID: this.clientID, }); } async loadCcpJwt() { this.ccpJwt = await (0, coreHelper_1._loadCcpJwt)(); } clone() { return { scopes: this.scopes, state: this.state, callbackURL: this.callbackURL, }; } dataPack() { return { userAgent: this.userAgent, scopes: this.scopes, }; } } // **** FUNCTIONS **** \\ function _makePublicGet(path, extraParameters = {}) { return (0, Fetchd_1._basicGet)(path, extraParameters); } // TODO verify accuracy function _makePublicPost(path, payload, extraParameters = {}) { const options = { method: 'POST', headers: { 'Content-Type': 'application/json', }, }; return (0, Fetchd_1._sendPathRequest)(path, extraParameters, options, payload); } async function _makeAuthedGet(path, sessionToken, extraParameters = {}) { const options = { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${sessionToken}` }, }; return (0, Fetchd_1._sendPathRequest)(path, extraParameters, options); } async function _makeAuthedPost(path, sessionToken, payload, extraParameters = {}) { const options = { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${sessionToken}` }, }; return (0, Fetchd_1._sendPathRequest)(path, extraParameters, options, payload); } async function _makeAuthedPut(path, sessionToken, payload, extraParameters = {}) { const options = { method: 'PUT', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${sessionToken}` }, }; return (0, Fetchd_1._sendPathRequest)(path, extraParameters, options, payload); } //TODO finish real logic async function _makeAuthedDelete(path, sessionToken, extraParameters = {}) { const options = { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${sessionToken}` }, }; return (0, Fetchd_1._sendPathRequest)(path, extraParameters, options); } // **** END FUNCTIONS **** \\ // **** END CLASS **** \\ exports.default = { CoreClass, _makePublicGet, _makePublicPost, _makeAuthedGet, _makeAuthedPost, _makeAuthedPut, _makeAuthedDelete }; //# sourceMappingURL=index.js.map