@xylabs/api
Advanced tools
Comparing version 2.11.0 to 2.11.1
'use strict'; | ||
var axios = require('axios'); | ||
var ApiClient = require('./ApiClient.js'); | ||
var ApiEndpoint = require('./ApiEndpoint.js'); | ||
var ApiStage = require('./ApiStage.js'); | ||
var getApiStage = require('./getApiStage.js'); | ||
require('axios'); | ||
exports.ApiStage = void 0; | ||
(function (ApiStage) { | ||
ApiStage["Beta"] = "beta"; | ||
ApiStage["Local"] = "local"; | ||
ApiStage["Prod"] = "prod"; | ||
})(exports.ApiStage || (exports.ApiStage = {})); | ||
class ApiClient { | ||
token; | ||
stage; | ||
constructor(token, stage) { | ||
this.token = token; | ||
this.stage = stage; | ||
this.stage = stage ?? exports.ApiStage.Prod; | ||
this.token = token; | ||
} | ||
} | ||
class ApiEndpoint { | ||
_value; | ||
config; | ||
path; | ||
constructor(config, path) { | ||
this.config = config; | ||
this.path = path; | ||
} | ||
get value() { | ||
return this._value; | ||
} | ||
get headers() { | ||
return this.config.jwtToken ? { Authorization: this.config.jwtToken } : undefined; | ||
} | ||
get url() { | ||
return `${this.config.apiDomain}/${this.path}`; | ||
} | ||
async fetch() { | ||
const response = await axios.get(this.url, { headers: this.headers }); | ||
if (response.status === 200) { | ||
this._value = response.data; | ||
} | ||
else { | ||
throw Error('Unexpected Status Code'); | ||
} | ||
return this._value; | ||
} | ||
async get() { | ||
return this._value ?? (await this.fetch()); | ||
} | ||
async insert(value) { | ||
const response = await axios.post(this.url, value, { headers: this.headers }); | ||
if (response.status === 200) { | ||
this._value = response.data; | ||
} | ||
else { | ||
throw Error('Unexpected Status Code'); | ||
} | ||
return this._value; | ||
} | ||
} | ||
const getApiStage = (hostname) => { | ||
if (hostname.startsWith('localhost')) { | ||
return exports.ApiStage.Local; | ||
} | ||
else if (hostname.startsWith('beta.')) { | ||
return exports.ApiStage.Beta; | ||
} | ||
else { | ||
return exports.ApiStage.Prod; | ||
} | ||
}; | ||
exports.ApiClient = ApiClient; | ||
exports.ApiEndpoint = ApiEndpoint; | ||
exports.getApiStage = getApiStage; | ||
exports.ApiClient = ApiClient.ApiClient; | ||
exports.ApiEndpoint = ApiEndpoint.ApiEndpoint; | ||
Object.defineProperty(exports, 'ApiStage', { | ||
enumerable: true, | ||
get: function () { return ApiStage.ApiStage; } | ||
}); | ||
exports.getApiStage = getApiStage.getApiStage; | ||
//# sourceMappingURL=index.js.map |
@@ -57,4 +57,4 @@ { | ||
"devDependencies": { | ||
"@xylabs/ts-scripts-yarn3": "^3.0.0-rc.15", | ||
"@xylabs/tsconfig": "^3.0.0-rc.15" | ||
"@xylabs/ts-scripts-yarn3": "^3.0.0-rc.16", | ||
"@xylabs/tsconfig": "^3.0.0-rc.16" | ||
}, | ||
@@ -69,4 +69,4 @@ "publishConfig": { | ||
"sideEffects": false, | ||
"version": "2.11.0", | ||
"version": "2.11.1", | ||
"packageManager": "yarn@3.3.1" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25476
47
310
1