|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + |
| 5 | + <meta charset="utf-8"> |
| 6 | + <title>constructor.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>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">constructor.js</h1> |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + <section> |
| 44 | + <article> |
| 45 | + <pre class="prettyprint source linenums"><code>import { $ecomConfig } from '@ecomplus/utils' |
| 46 | +import * as EventEmitter from 'eventemitter3' |
| 47 | + |
| 48 | +import login from './methods/login' |
| 49 | +import createEcomplusSession from './methods/create-ecomplus-session' |
| 50 | +import checkLogin from './methods/check-login' |
| 51 | +import logout from './methods/logout' |
| 52 | +import getAuthenticationId from './methods/get-authentication-id' |
| 53 | +import getSession from './methods/get-session' |
| 54 | +import setSession from './methods/set-session' |
| 55 | +import fetchAuthentication from './methods/fetch-authentication' |
| 56 | +import fetchStore from './methods/fetch-store' |
| 57 | +import requestApi from './methods/request-api' |
| 58 | + |
| 59 | +/** |
| 60 | + * Construct a new E-Com Plus admin account instance object. |
| 61 | + * @constructor |
| 62 | + * @param {number} [storeId=$ecomConfig.get('store_id')] - Preset Store ID number |
| 63 | + * @param {string} [lang] - Snake case language code |
| 64 | + * |
| 65 | + * @example |
| 66 | + |
| 67 | +// Default instance |
| 68 | +const ecomAuth = new EcomAuth() |
| 69 | + |
| 70 | + * @example |
| 71 | + |
| 72 | +// Optionally defining Store ID and language |
| 73 | +const storeId = 2000 |
| 74 | +const lang = 'en_us' |
| 75 | +const customEcomAuth = new EcomAuth(storeId, lang) |
| 76 | + |
| 77 | + */ |
| 78 | + |
| 79 | +const EcomAuth = function (storeId, lang) { |
| 80 | + const ecomAuth = this |
| 81 | + |
| 82 | + /** |
| 83 | + * Construct a new account instance object. |
| 84 | + * @memberof EcomAuth |
| 85 | + * @type {function} |
| 86 | + * @see EcomAuth |
| 87 | + */ |
| 88 | + ecomAuth.Constructor = EcomAuth |
| 89 | + |
| 90 | + /** |
| 91 | + * Respective Store ID number. |
| 92 | + * @memberof EcomAuth |
| 93 | + * @type {number} |
| 94 | + */ |
| 95 | + ecomAuth.storeId = storeId || $ecomConfig.get('store_id') |
| 96 | + |
| 97 | + /** |
| 98 | + * Instance language code. |
| 99 | + * @memberof EcomAuth |
| 100 | + * @type {string} |
| 101 | + */ |
| 102 | + ecomAuth.lang = lang |
| 103 | + |
| 104 | + /** |
| 105 | + * Authentication session object. |
| 106 | + * @memberof EcomAuth |
| 107 | + * @type {object} |
| 108 | + */ |
| 109 | + ecomAuth.session = { |
| 110 | + store_id: ecomAuth.storeId |
| 111 | + } |
| 112 | + |
| 113 | + const emitter = new EventEmitter() |
| 114 | + ;['on', 'off', 'once'].forEach(method => { |
| 115 | + ecomAuth[method] = (ev, fn) => { |
| 116 | + emitter[method](ev, fn) |
| 117 | + } |
| 118 | + }) |
| 119 | + |
| 120 | + this.login = (userOrEmail, password, isMd5Hash) => login(ecomAuth, userOrEmail, password, isMd5Hash) |
| 121 | + |
| 122 | + this.createEcomplusSession = () => createEcomplusSession(ecomAuth) |
| 123 | + |
| 124 | + this.checkLogin = () => checkLogin(ecomAuth) |
| 125 | + |
| 126 | + this.logout = () => logout(ecomAuth) |
| 127 | + |
| 128 | + this.getAuthenticationId = () => getAuthenticationId(ecomAuth) |
| 129 | + |
| 130 | + this.getSession = () => getSession(ecomAuth) |
| 131 | + |
| 132 | + this.setSession = newSession => setSession(ecomAuth, newSession) |
| 133 | + |
| 134 | + this.fetchAuthentication = mustSkipSession => fetchAuthentication(ecomAuth, mustSkipSession) |
| 135 | + |
| 136 | + this.fetchStore = mustSkipSession => fetchStore(ecomAuth, mustSkipSession) |
| 137 | + |
| 138 | + this.requestApi = (url, method, data, axiosConfig) => requestApi(ecomAuth, url, method, data, axiosConfig) |
| 139 | +} |
| 140 | + |
| 141 | +export default EcomAuth |
| 142 | +</code></pre> |
| 143 | + </article> |
| 144 | + </section> |
| 145 | + |
| 146 | + |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | + |
| 151 | +</div> |
| 152 | + |
| 153 | +<br class="clear"> |
| 154 | + |
| 155 | +<footer> |
| 156 | + Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Thu Jan 07 2021 20:11:40 GMT-0300 (Brasilia Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. |
| 157 | +</footer> |
| 158 | + |
| 159 | +<script>prettyPrint();</script> |
| 160 | +<script src="scripts/polyfill.js"></script> |
| 161 | +<script src="scripts/linenumber.js"></script> |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | +</body> |
| 166 | +</html> |
0 commit comments