new EcomAuth(storeIdopt, langopt)
- Source:
 
    Construct a new E-Com Plus admin account instance object.
    Examples
// Default instance
const ecomAuth = new EcomAuth()
    // Optionally defining Store ID and language
const storeId = 2000
const lang = 'en_us'
const customEcomAuth = new EcomAuth(storeId, lang)
    Parameters:
| Name | Type | Attributes | Default | Description | 
|---|---|---|---|---|
storeId | 
            
            number | 
                
                    <optional> | 
            
            
                
                
                    $ecomConfig.get('store_id')
                
                 | 
            
            Preset Store ID number | 
lang | 
            
            string | 
                
                    <optional> | 
            
            
                Snake case language code | 
Members
(static) ecomAuth.Constructor :function
- Source:
 - See:
 
    Construct a new account instance object.
    Type:
- function
 
(static) ecomAuth.lang :string
- Source:
 
    Instance language code.
    Type:
- string
 
(static) ecomAuth.storeId :number
- Source:
 
    Respective Store ID number.
    Type:
- number
 
Methods
checkLogin() → {boolean}
- Source:
 
    Check if admin is logged and access token is not expired.
    Example
if (ecomAuth.checkLogin()) {
  console.log('Logged')
}
Returns:
- Type
 - boolean
 
createEcomplusSession() → {Promise.<(response|error)>}
- Source:
 
    Try set E-Com Plus cross domain session after login.
    Example
ecomAuth.createEcomplusSession().then(() => console.log('User session created'))
Returns:
- Type
 - Promise.<(response|error)>
 
fetchAuthentication(mustSkipSessionopt) → {Promise.<(authentication|error)>}
- Source:
 
    Fetch current user authentication object from Store API.
    Example
ecomAuth.fetchAuthentication().then(authentication => {
  console.log(authentication._id)
})
    Parameters:
| Name | Type | Attributes | Default | Description | 
|---|---|---|---|---|
mustSkipSession | 
            
            boolean | 
                
                    <optional> | 
            
            
                
                
                    false
                
                 | 
            
            Skips previously fetched result (refresh cache) | 
Returns:
- Type
 - Promise.<(authentication|error)>
 
fetchStore(mustSkipSessionopt) → {Promise.<(store|error)>}
- Source:
 
    Fetch current store object from Store API.
    Example
ecomAuth.fetchStore().then(store => {
  console.log(store._id)
})
    Parameters:
| Name | Type | Attributes | Default | Description | 
|---|---|---|---|---|
mustSkipSession | 
            
            boolean | 
                
                    <optional> | 
            
            
                
                
                    false
                
                 | 
            
            Skips previously fetched result (refresh cache) | 
Returns:
- Type
 - Promise.<(store|error)>
 
getAuthenticationId() → {string|null}
- Source:
 
    Returns current session authentication ID.
    Example
console.log(ecomAuth.getAuthenticationId())
Returns:
- Type
 - string | null
 
getSession() → {object}
- Source:
 
    Returns current session object (without token).
    Example
const session = ecomAuth.getSession()
console.log(session.my_id, session.store_id)
Returns:
- Type
 - object
 
login(userOrEmail, password, isMd5Hashopt) → {Promise.<(self|error)>}
- Source:
 
    Try to login and authenticate admin with email or username and password.
    Example
ecomAuth.login('leo', '1234567890').then(() => {
  console.log(ecomAuth.getSession())
})
    Parameters:
| Name | Type | Attributes | Default | Description | 
|---|---|---|---|---|
userOrEmail | 
            
            string | Admin username or email address | ||
password | 
            
            string | Password or MD5 hash | ||
isMd5Hash | 
            
            boolean | 
                
                    <optional> | 
            
            
                
                
                    false
                
                 | 
            
            If password argument is already the MD5 hash string | 
Returns:
- Type
 - Promise.<(self|error)>
 
logout() → {self}
- Source:
 
    Reset admin session object.
    Example
ecomAuth.logout()
Returns:
- Type
 - self
 
requestApi(url, method, dataopt, axiosConfigopt) → {Promise.<(response|error)>}
- Source:
 
    Send authenticated request to E-Com Plus Store API (or another).
    Example
ecomAuth.requestApi('/orders/123456789012345678901234.json', 'patch', {
  status: 'closed'
}).then(({ status }) => {
  console.log(status)
})
    Parameters:
| Name | Type | Attributes | Description | 
|---|---|---|---|
url | 
            
            string | Store API endpoint or full URL | |
method | 
            
            string | Request HTTP method | |
data | 
            
            object | 
                
                    <optional> | 
            
            
            Request body | 
axiosConfig | 
            
            object | 
                
                    <optional> | 
            
            
            Additional axios config settings | 
Returns:
- Type
 - Promise.<(response|error)>
 
setSession(newSession) → {self}
- Source:
 
    Set instance session object.
    Example
ecomAuth.setSession(session)
    Parameters:
| Name | Type | Description | 
|---|---|---|
newSession | 
            
            object | Session object to save | 
Returns:
- Type
 - self
 
Events
login
- Source:
 
Properties:
| Name | Type | Description | 
|---|---|---|
self | 
            
            object | 
Type:
- object
 
Example
ecomAuth.on('login', console.log)
        
            
    
    logout
- Source:
 
Properties:
| Name | Type | Description | 
|---|---|---|
self | 
            
            object | 
Type:
- object
 
Example
ecomAuth.on('logout', console.log)
        
            
    
    updateAuthentication
- Source:
 
Properties:
| Name | Type | Description | 
|---|---|---|
self | 
            
            object | 
Type:
- object
 
Example
ecomAuth.on('updateAuthentication', self => {
  console.log('Session Authentication object from `fetchAuthentication` was updated')
})
        
            
    
    updateStore
- Source:
 
Properties:
| Name | Type | Description | 
|---|---|---|
self | 
            
            object | 
Type:
- object
 
Example
ecomAuth.on('updateAuthentication', self => {
  console.log('Session Store object from `fetchStore` was updated')
})