All files / src/methods/init index.js

0% Statements 0/16
0% Branches 0/12
100% Functions 0/0
0% Lines 0/16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92                                                                                                                                                                                       
import { closeUserFeedback } from '../../popupManager';
import config from '../../config';
import global from '../../global';
 
/**
 * @memberOf Useris
 * @function init
 * @description Initialization method of Useris.
 * Please note thtat this method has to be called
 * before any other methods and you should pass a configuration object.
 *
 * @param {Object} options configuration object
 * @param {Object} [options.regexObject]
 * Contains all the regular expressions for input validation
 * (msisdn, pin, email, password and generic regex are allowed)
 * @param {Object} [options.logger] A different logger by console (optional)
 * @param {string} [options.domain=''] webapp domain
 * @param {string} [options.country=''] country of the webapp
 * @param {boolean} [options.enableAliasCheck=0] to activate the alias features (INDIAN case)
 * @param {string} [options.aliasCheckUrl=''] api url of the alias
 * @param {boolean} [options.disablePinInput=0] enable/disable the input PIN for the login (PT case)
 * @param {boolean} [options.hybridnews=0] used in hybrid environment
 * @param {string} [options.store_type=''] used in hybrid environment
 * @param {string} [options.apikey=''] api key of the webapp
 * @param {boolean} [options.enableGoogleCheckbox=0]
 * enable/disable the Google Checkbox during the login flow
 * @param {boolean} [options.identityFbEnabled=0] enable/disable Facebook users
 * @param {boolean} [options.emailIdentityEnabled=0] enable/disable the email identity
 * @param {boolean} [options.redirectRegisterToMipAtStart=0]
 * enable/disable the smstemplate on addidentity
 * @param {boolean} [options.operatorList=0] enable/disable the operator login selection
 * @param {boolean} [options.addUsernameEnabled=0] enable/disable the add username feature
 *
 * @example
 *      Useris.init({
 *          domain: 'www.domain.com',
 *          country: 'ww',
 *          enableAliasCheck: 0,
 *          aliasCheckUrl: 'http://www.aliascheckurl.api/',
 *          disablePinInput: 0,
 *          hybridnews: 0,
 *          store_type: 'itunes',
 *          apikey: api_key,
 *          enableGoogleCheckbox: 0,
 *          emailIdentityEnabled: 1,
 *          identityFbEnabled: 1,
 *          redirectToMipRegisterAtStart: 0,
 *          logger: console,
 *          regexObject: {
 *              msisdn: '.',
 *              pin: '.',
 *              email: '.',
 *              password: '.',
 *              generic: '.',
 *              genericPassword: '.'
 *          }
 *      });
 */
export default (options) => {
    const regexObject = {
        msisdn: '.',
        pin: '.',
        email: '.',
        password: '.',
        generic: '.',
        genericPassword: '.'
    };
 
    const popupClose = document.getElementById('user-feedback-close');
 
    if (popupClose) {
        popupClose.addEventListener('click', closeUserFeedback);
    }
 
    if (typeof options !== 'undefined') {
        if (typeof options.regexObject === 'undefined') {
            options.regexObject = regexObject;
        }
 
        if (typeof options.aliasCheckUrl !== 'undefined') {
            if (options.aliasCheckUrl.indexOf('?') > 0) {
                options.aliasCheckUrl = options.aliasCheckUrl.split('?')[0]; // eslint-disable-line prefer-destructuring
            }
        }
 
        if (typeof options.logger !== 'undefined') {
            global.setLogger(options.logger);
        }
    }
    config.init(options);
};