@magicbell/react-headless
Version:
Hooks to build a notification inbox
51 lines • 1.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const user_client_1 = require("magicbell/user-client");
const vanilla_1 = require("zustand/vanilla");
const pkg_js_1 = require("../lib/pkg.js");
/**
* Store for the configuration of this MagicBell client. It contains all
* settings required to make a request to the MagicBell server.
*
* @example
* const { apiKey } = clientSettings.getState()
*/
const clientSettings = (0, vanilla_1.createStore)((set, get) => {
let _client = null;
let _key = '';
return {
apiKey: '',
userEmail: undefined,
userExternalId: undefined,
userKey: undefined,
token: undefined,
clientId: Math.random().toString(36).substring(2) + Date.now(),
serverURL: 'https://api.magicbell.com',
appInfo: undefined,
network: {},
getClient() {
const state = get();
const key = JSON.stringify([state.apiKey, state.userEmail, state.userExternalId, state.userKey, state.token]);
if (key !== _key) {
_key = key;
_client = new user_client_1.UserClient({
userExternalId: state.userExternalId,
userEmail: state.userEmail,
userHmac: state.userKey,
apiKey: state.apiKey,
token: state.token,
host: state.serverURL,
appInfo: state.appInfo || {
name: pkg_js_1.pkg.name,
version: pkg_js_1.pkg.version,
},
cacheTTL: state.network?.cacheTTL,
maxRetries: state.network?.maxRetries,
});
}
return _client;
},
};
});
exports.default = clientSettings;
//# sourceMappingURL=clientSettings.js.map