|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + |
| 5 | + <meta charset="utf-8"> |
| 6 | + <title>lib/fetch-and-cache.js - Documentation</title> |
| 7 | + |
| 8 | + |
| 9 | + <script src="scripts/prettify/prettify.js"></script> |
| 10 | + <script src="scripts/prettify/lang-css.js"></script> |
| 11 | + <!--[if lt IE 9]> |
| 12 | + <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> |
| 13 | + <![endif]--> |
| 14 | + <link type="text/css" rel="stylesheet" href="styles/prettify.css"> |
| 15 | + <link type="text/css" rel="stylesheet" href="styles/jsdoc.css"> |
| 16 | + <script src="scripts/nav.js" defer></script> |
| 17 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 18 | +</head> |
| 19 | +<body> |
| 20 | + |
| 21 | +<input type="checkbox" id="nav-trigger" class="nav-trigger" /> |
| 22 | +<label for="nav-trigger" class="navicon-button x"> |
| 23 | + <div class="navicon"></div> |
| 24 | +</label> |
| 25 | + |
| 26 | +<label for="nav-trigger" class="overlay"></label> |
| 27 | + |
| 28 | +<nav > |
| 29 | + |
| 30 | + <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="EcomAuth.html">EcomAuth</a><ul class='methods'><li data-type='method'><a href="EcomAuth.html#checkLogin">checkLogin</a></li><li data-type='method'><a href="EcomAuth.html#createEcomplusSession">createEcomplusSession</a></li><li data-type='method'><a href="EcomAuth.html#fetchAuthentication">fetchAuthentication</a></li><li data-type='method'><a href="EcomAuth.html#fetchStore">fetchStore</a></li><li data-type='method'><a href="EcomAuth.html#getAuthenticationId">getAuthenticationId</a></li><li data-type='method'><a href="EcomAuth.html#getSession">getSession</a></li><li data-type='method'><a href="EcomAuth.html#login">login</a></li><li data-type='method'><a href="EcomAuth.html#logout">logout</a></li><li data-type='method'><a href="EcomAuth.html#requestApi">requestApi</a></li><li data-type='method'><a href="EcomAuth.html#setSession">setSession</a></li></ul></li></ul><h3>Modules</h3><ul><li><a href="module-@ecomplus_auth.html">@ecomplus/auth</a></li></ul><h3>Events</h3><ul><li><a href="EcomAuth.html#event:login">login</a></li><li><a href="EcomAuth.html#event:logout">logout</a></li><li><a href="EcomAuth.html#event:updateAuthentication">updateAuthentication</a></li><li><a href="EcomAuth.html#event:updateStore">updateStore</a></li></ul><h3>Global</h3><ul><li><a href="global.html#ecomAuth">ecomAuth</a></li></ul> |
| 31 | +</nav> |
| 32 | + |
| 33 | +<div id="main"> |
| 34 | + |
| 35 | + <h1 class="page-title">lib/fetch-and-cache.js</h1> |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + <section> |
| 44 | + <article> |
| 45 | + <pre class="prettyprint source linenums"><code>export default (args, url, mustSkipSession, sessionField = 'authentication') => { |
| 46 | + const [self, session, emitter] = args |
| 47 | + |
| 48 | + if (!mustSkipSession && session[sessionField] && session[sessionField]._id) { |
| 49 | + return Promise.resolve(session[sessionField]) |
| 50 | + } |
| 51 | + |
| 52 | + return self.requestApi(url).then(({ data }) => { |
| 53 | + session[sessionField] = data |
| 54 | + |
| 55 | + /** |
| 56 | + * @event EcomAuth#updateAuthentication |
| 57 | + * @type {object} |
| 58 | + * @property {object} self |
| 59 | + * @example ecomAuth.on('updateAuthentication', console.log) |
| 60 | + */ |
| 61 | + |
| 62 | + /** |
| 63 | + * @event EcomAuth#updateStore |
| 64 | + * @type {object} |
| 65 | + * @property {object} self |
| 66 | + * @example ecomAuth.on('updateStore', console.log) |
| 67 | + */ |
| 68 | + emitter.emit(`update${sessionField.charAt(0).toUpperCase()}${sessionField.substring(1)}`, self) |
| 69 | + |
| 70 | + const timerField = `__session_${sessionField}_timer` |
| 71 | + clearTimeout(session[timerField]) |
| 72 | + session[timerField] = setTimeout(() => { |
| 73 | + session[sessionField] = null |
| 74 | + }, 30000) |
| 75 | + |
| 76 | + return data |
| 77 | + }) |
| 78 | +} |
| 79 | +</code></pre> |
| 80 | + </article> |
| 81 | + </section> |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | +</div> |
| 89 | + |
| 90 | +<br class="clear"> |
| 91 | + |
| 92 | +<footer> |
| 93 | + Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Wed Jan 20 2021 15:54:44 GMT-0300 (Brasilia Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. |
| 94 | +</footer> |
| 95 | + |
| 96 | +<script>prettyPrint();</script> |
| 97 | +<script src="scripts/polyfill.js"></script> |
| 98 | +<script src="scripts/linenumber.js"></script> |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | +</body> |
| 103 | +</html> |
0 commit comments