UNPKG

@magicbell/core

Version:

Official MagicBell API wrapper

55 lines 1.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ajax_js_1 = require("../lib/ajax.js"); /** * Class to represent a client that interacts with the MagicBell API. * * @example * class NotificationRepo extends RemoteRepository<Notification> {} */ class RemoteRepository { remotePathOrUrl; constructor(remotePathOrUrl) { this.remotePathOrUrl = remotePathOrUrl; } /** * Get an element from the API server by ID. * * @example * const notification = await repo.get('3df592eb-5f09dd6b'); */ get(id) { const url = `${this.remotePathOrUrl}/${id}`; return (0, ajax_js_1.fetchAPI)(url); } /** * Get elements that match params from the API server. * * @example * const notifications = await repo.findBy({ unread: true }); */ findBy(queryParams) { return (0, ajax_js_1.fetchAPI)(this.remotePathOrUrl, queryParams); } create(item) { return (0, ajax_js_1.postAPI)(this.remotePathOrUrl, item); } update(id, item) { const url = `${this.remotePathOrUrl}/${id}`; return (0, ajax_js_1.putAPI)(url, item); } /** * Delete an element by ID from the API server. * * @example * const deleted = await repo.delete('3df592eb-5f09dd6b'); */ delete(id) { const url = `${this.remotePathOrUrl}/${id}`; return (0, ajax_js_1.deleteAPI)(url) .then(() => true) .catch(() => false); } } exports.default = RemoteRepository; //# sourceMappingURL=RemoteRepository.js.map