UNPKG

@textback/notification-widget

Version:

TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.

49 lines (37 loc) 935 B
'use strict'; import apiErrorHandler from './apiErrorHandler.js'; const cache = {}; export const deeplinkUpdater = (apiPath, deeplink) => { let _promises = []; return data => { Promise.all(_promises).then(() => { let _data = JSON.stringify({ id: deeplink, insecureContext: { data: data } }); let _promise = fetch( `${apiPath}/endUserNotifications/deepLinks`, { method: 'PATCH', body: _data } ); _promises.push(_promise); return _promises; }); }; }; export default function loadDeepLink(apiPath, options = {}) { const body = JSON.stringify(options); if (cache[body]) { return cache[body]; } cache[body] = fetch(`${apiPath}/endUserNotifications/deepLinks`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body }).then(apiErrorHandler); return cache[body]; };