'use strict';
import InsalesApi from 'insales';
import { createDir } from './file-system/dir';
import { _watch,
         watcher } from './file-system/watch';
import { getAsset,
         getAssets,
         upadeteAssets,
         uploadAsset,
         removeAsset,
         editAsset } from './request/asset';
import { instance } from './instance';

class InSalesUploader {
  constructor(options){
    const self = this;
    self.options = options || {};
    if (!self.options.id) throw new Error('Missing app id');
    if (!self.options.token) throw new Error('Missing app token');
    if (!self.options.url) throw new Error('Missing app url');
    self.options.protocol = (self.options.http) ? 'http://' : 'https://';

    self.instance = instance(self)

    self.assets = {};
    self.state = {};
    self.downloadList = [];

    self.insales = InsalesApi({
      id: this.options.id,
      secret: this.options.token,
      http: this.options.http
    });
  }


  createDir(owner, action) {
    return createDir(this, action);
  }

  getAsset(owner,_asset) {
    return getAsset(this, _asset);
  }

  getAssets(owner, action) {
    return getAssets(this, action);
  }

  upadeteAssets(owner) {
    return upadeteAssets(this);
  }

  uploadAsset(owner, _asset, _path) {
    return uploadAsset(this, _asset, _path);
  }

  removeAsset(owner, _assetId, _path, _name) {
    return removeAsset(this, _assetId, _path, _name);
  }

  editAsset(owner, _asset, assetId, path) {
    return editAsset(this, _asset, assetId, path);
  }

  watcher(owner) {
    return watcher(this);
  }

  _watch(owner, event, path) {
    return _watch(this, event, path);
  }

  _download () {
    var self = this;
    return new Promise(function (resolve, reject) {
      var action = {
        method: 'download'
      }
      self.createDir(self, action);
      self.upadeteAssets(self).then(function() {
        getAssets(self, action).then(function() {
          resolve()
        });
      });
    });
  }

  download () {
    return Promise.all([
      this._download()
    ])
  }

  _backup () {
    var self = this;
    return new Promise(function (resolve, reject) {
      var action = {
        method: 'backup'
      }
      self.createDir(self, action);
      self.upadeteAssets(self).then(function() {
        getAssets(self, action).then(function() {
          resolve()
          return;
        });
      });
    });
  }

  backup () {
    return Promise.all([
      this._backup()
    ])
  }

  _stream () {
    var self = this;
    return new Promise(function (resolve, reject) {
      self.upadeteAssets(self).then(function () {
        resolve()
        return watcher(self)
      })
    });
  }
  stream () {
    return Promise.all([
      this._stream()
    ]).then(function() {
      setTimeout(function () {
        console.info('Start watch')
      }, 500);
    })
  }
}

export default options => new InSalesUploader(options);

@@ -1000,16 +1000,29 @@
  return 
+Promise.all(%5B
 createDi
@@ -1028,32 +1028,34 @@
 ir(this, action)
+%5D)
 ;%0A  %7D%0A%0A  getAsse
@@ -1838,32 +1838,51 @@
 elf, action)
-;%0A
+.then(function() %7B%0A 
       
+ 
 self.upadete
@@ -1912,32 +1912,34 @@
 ion() %7B%0A        
+  
 getAssets(self, 
@@ -1956,32 +1956,34 @@
 en(function() %7B%0A
+  
           resolv
@@ -1978,32 +1978,46 @@
       resolve()%0A
+          %7D);%0A
         %7D);%0A    
@@ -2287,18 +2287,37 @@
  action)
-;%0A
+.then(function() %7B%0A  
       se
@@ -2357,32 +2357,34 @@
 ion() %7B%0A        
+  
 getAssets(self, 
@@ -2411,32 +2411,34 @@
 n() %7B%0A          
+  
 resolve()%0A      
@@ -2445,16 +2445,18 @@
     
+  
 return;%0A
     
@@ -2451,16 +2451,30 @@
 return;%0A
+          %7D);%0A
         

Update app.js