tfd-api
Version:
A simple API wrapper to interact with The First Descendant API
2 lines • 4.07 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _isomorphicunfetch = require('isomorphic-unfetch'); var _isomorphicunfetch2 = _interopRequireDefault(_isomorphicunfetch);function d(s){return{host:"https://open.api.nexon.com",default_language:_optionalChain([s, 'optionalAccess', _ => _.default_language])||"en",headers:{"x-nxopen-api-key":_optionalChain([s, 'optionalAccess', _2 => _2.api_key])}}}function a(s,t){let e=s;if(Object.keys(t).length>0){let n=new URLSearchParams;Object.entries(t).forEach(([p,u])=>n.append(p,u.toString())),e+=`?${n.toString()}`}return e}async function o(s,t){return await _isomorphicunfetch2.default.call(void 0, s,{method:"GET",headers:t}).then(e=>e.headers.get("Content-Type")&&_optionalChain([e, 'access', _3 => _3.headers, 'access', _4 => _4.get, 'call', _5 => _5("Content-Type"), 'optionalAccess', _6 => _6.includes, 'call', _7 => _7("application/json")])?e.json():{error:{name:"CUSTOMERROR",message:"Unable to parse API response"}}).catch(e=>(console.log(`[FETCHER//ERROR] ${e.message}`),null))}var r=class{constructor(t,e,n){this.url=t;this.headers=e;this.default_language=n;if(!e["x-nxopen-api-key"])throw Error("API Key is required")}getId(t){let e=a(`${this.url}/tfd/v1/id`,{user_name:t});return o(e,this.headers)}getUserBasic(t){let e=a(`${this.url}/tfd/v1/user/basic`,{ouid:t});return o(e,this.headers)}getUserDescendant(t){let e=a(`${this.url}/tfd/v1/user/descendant`,{ouid:t});return o(e,this.headers)}getUserWeapon(t,e=this.default_language){let n=a(`${this.url}/tfd/v1/user/weapon`,{ouid:t,language_code:e});return o(n,this.headers)}getUserReactor(t,e=this.default_language){let n=a(`${this.url}/tfd/v1/user/reactor`,{ouid:t,language_code:e});return o(n,this.headers)}getUserExternalComponent(t,e=this.default_language){let n=a(`${this.url}/tfd/v1/user/external-component`,{ouid:t,language_code:e});return o(n,this.headers)}getRecommendationModule(t,e,n,p){let u=a(`${this.url}/tfd/v1/recommendation/module`,{descendant_id:t,weapon_id:e,void_battle_id:n,period:p});return o(u,this.headers)}};var i=class{constructor(t,e){this.url=t;this.default_language=e}getDescendant(t=this.default_language){let e=`${this.url}/static/tfd/meta/${t}/descendant.json`;return o(e)}getWeapon(t=this.default_language){let e=`${this.url}/static/tfd/meta/${t}/weapon.json`;return o(e)}getModule(t=this.default_language){let e=`${this.url}/static/tfd/meta/${t}/module.json`;return o(e)}getReactor(t=this.default_language){let e=`${this.url}/static/tfd/meta/${t}/reactor.json`;return o(e)}getExternalComponent(t=this.default_language){let e=`${this.url}/static/tfd/meta/${t}/external-component.json`;return o(e)}getReward(t=this.default_language){let e=`${this.url}/static/tfd/meta/${t}/reward.json`;return o(e)}getStat(t=this.default_language){let e=`${this.url}/static/tfd/meta/${t}/stat.json`;return o(e)}getVoidBattle(t=this.default_language){let e=`${this.url}/static/tfd/meta/${t}/void-battle.json`;return o(e)}getTitle(t=this.default_language){let e=`${this.url}/static/tfd/meta/${t}/title.json`;return o(e)}};var l=class{constructor(t){this.options=d(t),this.account=new r(this.options.host,this.options.headers,this.options.default_language),this.metadata=new i(this.options.host,this.options.default_language)}};var g=(n=>(n[n.Last7Days=0]="Last7Days",n[n.Last30Days=1]="Last30Days",n[n.AllTime=2]="AllTime",n))(g||{});exports.QueryPeriod = g; exports.TFDApi = l;
//# sourceMappingURL=index.js.map