@magicbell/core
Version:
Official MagicBell API wrapper
48 lines • 1.12 kB
JavaScript
import { __decorate } from "tslib";
import camelize from '../../lib/decorators/camelize.js';
import ConfigRepository from './ConfigRepository.js';
/**
* A configuration object.
*
* @example
* const config = new Config({ apiKey, userEmail, userKey });
* config.fetch();
*/
export default class Config {
apiKey;
userEmail;
userExternalId;
userKey;
apiSecret;
ws;
inbox;
channels;
webPushNotifications;
repo;
xhrFetchState = 'idle';
constructor(args) {
this.set(args);
this.repo = new ConfigRepository();
}
/**
* 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);
}
}
__decorate([
camelize()
], Config.prototype, "set", null);
//# sourceMappingURL=Config.js.map