twilio-sync
Advanced tools
Comparing version 0.3.3 to 0.3.4-build.154
@@ -43,4 +43,2 @@ 'use strict'; | ||
function Network(productId, clientInfo, config, transport) { | ||
var _this = this; | ||
(0, _classCallCheck3.default)(this, Network); | ||
@@ -51,3 +49,3 @@ | ||
_transport: { value: transport }, | ||
_headers: { get: function get() { | ||
_generateHeaders: { value: function value() { | ||
return { | ||
@@ -58,6 +56,5 @@ 'Content-Type': 'application/json', | ||
'X-Twilio-Product-Id': productId, | ||
'X-Twilio-Token': _this._config.token | ||
'X-Twilio-Token': this._config.token | ||
}; | ||
} | ||
} | ||
} } | ||
}); | ||
@@ -75,4 +72,5 @@ } | ||
value: function get(uri) { | ||
_logger2.default.debug('GET', uri, 'ID:', this._headers['Twilio-Request-Id']); | ||
return this._transport.get(uri, this._headers); | ||
var headers = this._generateHeaders(); | ||
_logger2.default.debug('GET', uri, 'ID:', headers['Twilio-Request-Id']); | ||
return this._transport.get(uri, headers); | ||
} | ||
@@ -82,3 +80,3 @@ }, { | ||
value: function post(uri, body, revision) { | ||
var headers = this._headers; | ||
var headers = this._generateHeaders(); | ||
if (typeof revision !== 'undefined') { | ||
@@ -88,3 +86,3 @@ headers['If-Match'] = revision; | ||
_logger2.default.debug('POST', uri, 'ID:', this._headers['Twilio-Request-Id']); | ||
_logger2.default.debug('POST', uri, 'ID:', headers['Twilio-Request-Id']); | ||
return this._transport.post(uri, headers, body); | ||
@@ -95,3 +93,3 @@ } | ||
value: function put(uri, body, revision) { | ||
var headers = this._headers; | ||
var headers = this._generateHeaders(); | ||
if (typeof revision !== 'undefined') { | ||
@@ -101,3 +99,3 @@ headers['If-Match'] = revision; | ||
_logger2.default.debug('PUT', uri, 'ID:', this._headers['Twilio-Request-Id']); | ||
_logger2.default.debug('PUT', uri, 'ID:', headers['Twilio-Request-Id']); | ||
return this._transport.put(uri, headers, body); | ||
@@ -108,4 +106,5 @@ } | ||
value: function _delete(uri) { | ||
_logger2.default.debug('DELETE', uri, 'ID:', this._headers['Twilio-Request-Id']); | ||
return this._transport.delete(uri, this._headers); | ||
var headers = this._generateHeaders(); | ||
_logger2.default.debug('DELETE', uri, 'ID:', headers['Twilio-Request-Id']); | ||
return this._transport.delete(uri, headers); | ||
} | ||
@@ -112,0 +111,0 @@ }]); |
@@ -157,4 +157,3 @@ 'use strict'; | ||
case 'document_removed': | ||
this.emit('removed', false); | ||
this.emit('removedRemotely'); | ||
this._onRemoved(false); | ||
} | ||
@@ -308,2 +307,8 @@ } | ||
return _this5; | ||
}).catch(function (err) { | ||
if (err.status === 404) { | ||
_this5._onRemoved(false); | ||
} else { | ||
_logger2.default.error('Can\'t get updates for ' + _this5.sid + ':', err); | ||
} | ||
}); | ||
@@ -365,2 +370,11 @@ } | ||
} | ||
}, { | ||
key: '_onRemoved', | ||
value: function _onRemoved(locally) { | ||
// Should also do some cleanup here | ||
this.emit('removed', locally); | ||
if (!locally) { | ||
this.emit('removedRemotely'); | ||
} | ||
} | ||
@@ -380,3 +394,3 @@ /** | ||
return this._network.delete(this.uri).then(function () { | ||
_this8.emit('removed', true); | ||
_this8._onRemoved(true); | ||
}); | ||
@@ -383,0 +397,0 @@ } |
@@ -151,3 +151,3 @@ 'use strict'; | ||
if (err.status === 412) { | ||
return _this2._softSync().then(function () { | ||
return _this2._queryEvents().then(function () { | ||
return _this2.get(item.index); | ||
@@ -438,5 +438,14 @@ }).then(function (result) { | ||
return this._deps.network.delete(this.uri).then(function () { | ||
_this12.emit('collectionRemoved', true); | ||
_this12._onRemoved(true); | ||
}); | ||
} | ||
}, { | ||
key: '_onRemoved', | ||
value: function _onRemoved(locally) { | ||
// Should also do some cleanup here | ||
this.emit('collectionRemoved', locally); | ||
if (!locally) { | ||
this.emit('collectionRemovedRemotely'); | ||
} | ||
} | ||
@@ -452,3 +461,11 @@ /** | ||
value: function _softSync() { | ||
return this._queryEvents(); | ||
var _this13 = this; | ||
return this._queryEvents().catch(function (err) { | ||
if (err.status === 404) { | ||
_this13._onRemoved(false); | ||
} else { | ||
_logger2.default.error('Can\'t get updates for ' + _this13.sid + ':', err); | ||
} | ||
}); | ||
} | ||
@@ -493,4 +510,3 @@ }, { | ||
{ | ||
this.emit('collectionRemoved', false); | ||
this.emit('collectionRemovedRemotely'); | ||
this._onRemoved(false); | ||
} | ||
@@ -497,0 +513,0 @@ break; |
@@ -165,3 +165,3 @@ 'use strict'; | ||
if (err.status === 412) { | ||
return _this2._softSync().then(function () { | ||
return _this2._queryEvents().then(function () { | ||
return _this2.get(keyValue.key); | ||
@@ -497,3 +497,11 @@ }).then(function (item) { | ||
value: function _softSync() { | ||
return this._queryEvents(); | ||
var _this11 = this; | ||
return this._queryEvents().catch(function (err) { | ||
if (err.status === 404) { | ||
_this11._onRemoved(false); | ||
} else { | ||
_logger2.default.error('Can\'t get updates for ' + _this11.sid + ':', err); | ||
} | ||
}); | ||
} | ||
@@ -512,7 +520,7 @@ | ||
value: function forEach(handler) { | ||
var _this11 = this; | ||
var _this12 = this; | ||
return new _promise2.default(function (resolve, reject) { | ||
if (_this11._cacheState.ensured) { | ||
_this11._items.forEach(handler); | ||
if (_this12._cacheState.ensured) { | ||
_this12._items.forEach(handler); | ||
resolve(); | ||
@@ -526,9 +534,9 @@ } else { | ||
var getFirstPage = function getFirstPage() { | ||
return _this11._query(firstPageQueryArgs); | ||
return _this12._query(firstPageQueryArgs); | ||
}; | ||
var handleEnd = function handleEnd() { | ||
_this11._cacheState.ensured = true; | ||
_this12._cacheState.ensured = true; | ||
resolve(); | ||
}; | ||
_this11._processPage(getFirstPage, handler, handleEnd).catch(reject); | ||
_this12._processPage(getFirstPage, handler, handleEnd).catch(reject); | ||
})(); | ||
@@ -546,3 +554,3 @@ } | ||
value: function _processPage(getPage, handleElement, handleEnd) { | ||
var _this12 = this; | ||
var _this13 = this; | ||
@@ -555,3 +563,3 @@ return getPage().then(function (page) { | ||
setTimeout(function () { | ||
return _this12._processPage(page.nextPage.bind(page), handleElement, handleEnd); | ||
return _this13._processPage(page.nextPage.bind(page), handleElement, handleEnd); | ||
}); | ||
@@ -600,4 +608,3 @@ } else { | ||
{ | ||
this.emit('collectionRemoved', false); | ||
this.emit('collectionRemovedRemotely'); | ||
this._onRemoved(false); | ||
} | ||
@@ -677,2 +684,11 @@ break; | ||
} | ||
}, { | ||
key: '_onRemoved', | ||
value: function _onRemoved(locally) { | ||
// Should also do some cleanup here | ||
this.emit('collectionRemoved', locally); | ||
if (!locally) { | ||
this.emit('collectionRemovedRemotely'); | ||
} | ||
} | ||
@@ -688,7 +704,7 @@ /** | ||
value: function removeMap() { | ||
var _this13 = this; | ||
var _this14 = this; | ||
this._onRemoveMap(this.sid); | ||
return this._deps.network.delete(this.uri).then(function () { | ||
_this13.emit('collectionRemoved', true); | ||
_this14._onRemoved(true); | ||
}); | ||
@@ -695,0 +711,0 @@ } |
{ | ||
"name": "twilio-sync", | ||
"version": "0.3.3", | ||
"version": "0.3.4-build.154", | ||
"description": "Twilio Sync client library", | ||
@@ -25,2 +25,3 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"async-test-tools": "^1.0.5", | ||
"babel-cli": "^6.14.0", | ||
@@ -27,0 +28,0 @@ "babel-eslint": "^7.0.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21553
1523997
39
62