tonicpow-js
Version:
TonicPow API Library in JS - https://docs.tonicpow.com
91 lines (62 loc) • 1.8 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;// Config for the API instance, environment, url, etc
class Config{
constructor(a,b){
// List of supported environments for the TonicPow API
this.environments={
Live:{
name:"live",
url:"https://api.tonicpow.com/"},
Local:{
name:"local",
url:"http://localhost:3000/"},
Mock:{
name:"mock",
url:"http://d9116720-5ac6-4c7f-a370-4ea578c63a66.mock.pstmn.io"},
Staging:{
name:"staging",
url:"https://api.staging.tonicpow.com/"}},
this.apiKey=a,
b&&
b.hasOwnProperty("environment")&&(
this.environment=b.environment),
this.environment||(
this.environment=this.environments.Live.name);
}
// Our internal API key for creating a new session
get apiKey(){
return this._apiKey;
}
set apiKey(a){
if(!a||30>a.length)
throw Error("invalid api key");
this._apiKey=a;
}
// The current api url that this application is using
get apiUrl(){
return this._apiUrl;
}
set apiUrl(a){
if(
a!==this.environments.Live.url&&
a!==this.environments.Local.url&&
a!==this.environments.Mock.url&&
a!==this.environments.Staging.url)
throw Error("invalid api url");
this._apiUrl=a;
}
// The current environment that this application is using
get environment(){
return this._environment;
}
set environment(a){
if("object"==typeof a?a=a.name:"string"==typeof a&&(a=a.toLowerCase()),a===this.environments.Local.name)
this.apiUrl=this.environments.Local.url;else
if(a===this.environments.Staging.name)
this.apiUrl=this.environments.Staging.url;else
if(a===this.environments.Mock.name)
this.apiUrl=this.environments.Mock.url;else
if(a===this.environments.Live.name)
this.apiUrl=this.environments.Live.url;else
throw Error("invalid environment");
this._environment=a;
}}exports.default=Config,module.exports=exports.default;