@magicbell/core
Version:
Official MagicBell API wrapper
51 lines • 1.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const camelize_js_1 = tslib_1.__importDefault(require("../../lib/decorators/camelize.js"));
const ConfigRepository_js_1 = tslib_1.__importDefault(require("./ConfigRepository.js"));
/**
* A configuration object.
*
* @example
* const config = new Config({ apiKey, userEmail, userKey });
* config.fetch();
*/
class Config {
apiKey;
userEmail;
userExternalId;
userKey;
apiSecret;
ws;
inbox;
channels;
webPushNotifications;
repo;
xhrFetchState = 'idle';
constructor(args) {
this.set(args);
this.repo = new ConfigRepository_js_1.default();
}
/**
* Fetch the configuration for the current user from the MagicBell server.
*/
async fetch() {
this.xhrFetchState = 'pending';
try {
const data = await this.repo.get();
this.set(data);
this.xhrFetchState = 'success';
}
catch (error) {
this.xhrFetchState = 'failure';
}
}
set(json = {}) {
Object.assign(this, json);
}
}
exports.default = Config;
tslib_1.__decorate([
(0, camelize_js_1.default)()
], Config.prototype, "set", null);
//# sourceMappingURL=Config.js.map