UNPKG

@magicbell/react-headless

Version:
42 lines 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const humps_1 = tslib_1.__importDefault(require("humps")); const ajax_js_1 = require("../../lib/ajax.js"); /** * Class to interact with the notification preferences API endpoints. * * @example * const repo = new NotificationPreferencesRepository(); * const preferences = repo.get(); */ class NotificationPreferencesRepository { remotePathOrUrl; constructor(remotePathOrUrl = '/notification_preferences') { this.remotePathOrUrl = remotePathOrUrl; } /** * Get the user preferences from the API server. Object properties will be camelized. * Wrapping of message to server is handled for us (Design Principle: The Principle of Least * Knowledge). */ async get() { const url = this.remotePathOrUrl; const json = await (0, ajax_js_1.fetchAPI)(url); return humps_1.default.camelizeKeys(json); } /** * Update user preferences in the API server. Object properties will be decamelized before * being send to the server. * * @param data Preferences to send to the server. */ async update(data) { const url = this.remotePathOrUrl; const payload = humps_1.default.decamelizeKeys({ notificationPreferences: data }); const json = await (0, ajax_js_1.putAPI)(url, payload); return humps_1.default.camelizeKeys(json); } } exports.default = NotificationPreferencesRepository; //# sourceMappingURL=NotificationPreferencesRepository.js.map