Socket
Socket
Sign inDemoInstall

@twilio/notifications

Package Overview
Dependencies
Maintainers
3
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@twilio/notifications - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3-rc.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

### [1.0.3-rc.0](https://github.com/twilio/twilio-notifications.js/compare/@twilio/notifications@1.0.2...@twilio/notifications@1.0.3-rc.0) (2021-08-09)
### Bug Fixes
* Fix import module error ([85b352e](https://github.com/twilio/twilio-notifications.js/commit/85b352e09b627e4f7a1a6c210fcd8c39cc98fd53))
* Fix unit test mock ([d9dbd61](https://github.com/twilio/twilio-notifications.js/commit/d9dbd61e49bff1d37069f53a93f0d202eaea7f69))
* Make Notifications registrar API support multiproduct Twilsock ([b5bd9be](https://github.com/twilio/twilio-notifications.js/commit/b5bd9bea8611a5d36140eb02fdb5511ac5a2ef3e))
### [1.0.2](https://github.com/twilio/twilio-notifications.js/compare/@twilio/notifications@1.0.2-rc.7...@twilio/notifications@1.0.2) (2021-08-04)

@@ -8,0 +19,0 @@

403

dist/lib.js

@@ -60,3 +60,3 @@ /*

var logger = require('loglevel');
var twilsock_connector = require('./twilsock.connector');
var require$$0 = require('crypto');
var declarativeTypeValidator = require('@twilio/declarative-type-validator');

@@ -99,2 +99,3 @@

var logger__namespace = /*#__PURE__*/_interopNamespace(logger);
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);

@@ -182,5 +183,5 @@ function __decorate(decorators, target, key, desc) {

function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$2(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
function _createSuper$3(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$3(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _isNativeReflectConstruct$3() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

@@ -228,3 +229,3 @@ var RegistrationState = function RegistrationState() {

var _super = _createSuper$2(Connector);
var _super = _createSuper$3(Connector);

@@ -392,5 +393,5 @@ // @todo replace with FSM

function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$2(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
var retrierConfig = {

@@ -409,3 +410,3 @@ min: 2000,

var _super = _createSuper$1(RegistrarConnector);
var _super = _createSuper$2(RegistrarConnector);

@@ -442,3 +443,3 @@ /**

var registrarRequest, url, headers, response;
var registrarRequest, productId, url, headers, response;
return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {

@@ -477,3 +478,4 @@ while (1) {

};
url = "".concat(this.registrarUrl, "?productId=").concat(this.context.productId);
productId = this.context.productId;
url = "".concat(this.registrarUrl, "?productId=").concat(productId);
headers = {

@@ -484,25 +486,25 @@ "Content-Type": "application/json" // 'X-Twilio-Token': registration.token

logInstance.trace("Creating registration for channel ".concat(this.channelType));
_context.prev = 11;
_context.next = 14;
_context.prev = 12;
_context.next = 15;
return new operationRetrier.AsyncRetrier(retrierConfig).run(function () {
return _this2.twilsock.post(url, headers, registrarRequest);
return _this2.twilsock.post(url, headers, registrarRequest, productId);
});
case 14:
case 15:
response = _context.sent;
this.registrationId = response.body.id;
logInstance.debug("Registration created: ", response);
_context.next = 23;
_context.next = 24;
break;
case 19:
_context.prev = 19;
_context.t0 = _context["catch"](11);
case 20:
_context.prev = 20;
_context.t0 = _context["catch"](12);
logInstance.error("Registration failed: ", _context.t0);
throw _context.t0;
case 23:
case 24:
return _context.abrupt("return", registration);
case 24:
case 25:
case "end":

@@ -512,3 +514,3 @@ return _context.stop();

}
}, _callee, this, [[11, 19]]);
}, _callee, this, [[12, 20]]);
}));

@@ -528,3 +530,3 @@

var url, headers;
var productId, url, headers;
return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {

@@ -542,3 +544,4 @@ while (1) {

case 2:
url = "".concat(this.registrarUrl, "/").concat(this.registrationId, "?productId=").concat(this.context.productId);
productId = this.context.productId;
url = "".concat(this.registrarUrl, "/").concat(this.registrationId, "?productId=").concat(productId);
headers = {

@@ -549,22 +552,22 @@ "Content-Type": "application/json" // 'X-Twilio-Token': this.config.token

logInstance.trace("Removing registration for ".concat(this.channelType));
_context2.prev = 5;
_context2.next = 8;
_context2.prev = 6;
_context2.next = 9;
return new operationRetrier.AsyncRetrier(Object.assign(retrierConfig, {
maxAttemptsCount: 3
})).run(function () {
return _this3.twilsock.delete(url, headers);
return _this3.twilsock.delete(url, headers, {}, productId);
});
case 8:
case 9:
logInstance.debug("Registration removed for ".concat(this.channelType));
_context2.next = 15;
_context2.next = 16;
break;
case 11:
_context2.prev = 11;
_context2.t0 = _context2["catch"](5);
case 12:
_context2.prev = 12;
_context2.t0 = _context2["catch"](6);
logInstance.error("Failed to remove registration ", this.channelType, _context2.t0);
throw _context2.t0;
case 15:
case 16:
case "end":

@@ -574,3 +577,3 @@ return _context2.stop();

}
}, _callee2, this, [[5, 11]]);
}, _callee2, this, [[6, 12]]);
}));

@@ -590,3 +593,3 @@

var url, headers, payload;
var productId, url, headers, payload;
return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {

@@ -604,3 +607,4 @@ while (1) {

case 2:
url = "".concat(this.registrarUrl, "?productId=").concat(this.context.productId);
productId = this.context.productId;
url = "".concat(this.registrarUrl, "?productId=").concat(productId);
headers = {

@@ -614,23 +618,23 @@ "Content-Type": "application/json" // @todo Content-Length??

};
_context3.prev = 5;
_context3.prev = 6;
logInstance.trace("Removing old registrations for ".concat(this.channelType));
_context3.next = 9;
_context3.next = 10;
return new operationRetrier.AsyncRetrier(Object.assign(retrierConfig, {
maxAttemptsCount: 3
})).run(function () {
return _this4.twilsock.delete(url, headers, payload);
return _this4.twilsock.delete(url, headers, payload, productId);
});
case 9:
case 10:
logInstance.debug("Registration removed for ".concat(this.channelType));
_context3.next = 16;
_context3.next = 17;
break;
case 12:
_context3.prev = 12;
_context3.t0 = _context3["catch"](5);
case 13:
_context3.prev = 13;
_context3.t0 = _context3["catch"](6);
logInstance.error("Failed to remove registration ", this.channelType, _context3.t0);
throw _context3.t0;
case 16:
case 17:
case "end":

@@ -640,3 +644,3 @@ return _context3.stop();

}
}, _callee3, this, [[5, 12]]);
}, _callee3, this, [[6, 13]]);
}));

@@ -655,2 +659,311 @@

// this is pretty straight-forward - we use the crypto API.
var crypto = require$$0__default['default'];
var rng$2 = function nodeRNG() {
return crypto.randomBytes(16);
};
/**
* Convert array of 16 byte values to UUID string format of the form:
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
*/
var byteToHex = [];
for (var i = 0; i < 256; ++i) {
byteToHex[i] = (i + 0x100).toString(16).substr(1);
}
function bytesToUuid$2(buf, offset) {
var i = offset || 0;
var bth = byteToHex; // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
return [bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]]].join('');
}
var bytesToUuid_1 = bytesToUuid$2;
var rng$1 = rng$2;
var bytesToUuid$1 = bytesToUuid_1; // **`v1()` - Generate time-based UUID**
//
// Inspired by https://github.com/LiosK/UUID.js
// and http://docs.python.org/library/uuid.html
var _nodeId;
var _clockseq; // Previous uuid creation time
var _lastMSecs = 0;
var _lastNSecs = 0; // See https://github.com/uuidjs/uuid for API details
function v1$1(options, buf, offset) {
var i = buf && offset || 0;
var b = buf || [];
options = options || {};
var node = options.node || _nodeId;
var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq; // node and clockseq need to be initialized to random values if they're not
// specified. We do this lazily to minimize issues related to insufficient
// system entropy. See #189
if (node == null || clockseq == null) {
var seedBytes = rng$1();
if (node == null) {
// Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
node = _nodeId = [seedBytes[0] | 0x01, seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]];
}
if (clockseq == null) {
// Per 4.2.2, randomize (14 bit) clockseq
clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
}
} // UUID timestamps are 100 nano-second units since the Gregorian epoch,
// (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
// time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
// (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
var msecs = options.msecs !== undefined ? options.msecs : new Date().getTime(); // Per 4.2.1.2, use count of uuid's generated during the current clock
// cycle to simulate higher resolution clock
var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; // Time since last uuid creation (in msecs)
var dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000; // Per 4.2.1.2, Bump clockseq on clock regression
if (dt < 0 && options.clockseq === undefined) {
clockseq = clockseq + 1 & 0x3fff;
} // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
// time interval
if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
nsecs = 0;
} // Per 4.2.1.2 Throw error if too many uuids are requested
if (nsecs >= 10000) {
throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
}
_lastMSecs = msecs;
_lastNSecs = nsecs;
_clockseq = clockseq; // Per 4.1.4 - Convert from unix epoch to Gregorian epoch
msecs += 12219292800000; // `time_low`
var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
b[i++] = tl >>> 24 & 0xff;
b[i++] = tl >>> 16 & 0xff;
b[i++] = tl >>> 8 & 0xff;
b[i++] = tl & 0xff; // `time_mid`
var tmh = msecs / 0x100000000 * 10000 & 0xfffffff;
b[i++] = tmh >>> 8 & 0xff;
b[i++] = tmh & 0xff; // `time_high_and_version`
b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
b[i++] = tmh >>> 16 & 0xff; // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
b[i++] = clockseq >>> 8 | 0x80; // `clock_seq_low`
b[i++] = clockseq & 0xff; // `node`
for (var n = 0; n < 6; ++n) {
b[i + n] = node[n];
}
return buf ? buf : bytesToUuid$1(b);
}
var v1_1 = v1$1;
var rng = rng$2;
var bytesToUuid = bytesToUuid_1;
function v4$1(options, buf, offset) {
var i = buf && offset || 0;
if (typeof options == 'string') {
buf = options === 'binary' ? new Array(16) : null;
options = null;
}
options = options || {};
var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
rnds[6] = rnds[6] & 0x0f | 0x40;
rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
if (buf) {
for (var ii = 0; ii < 16; ++ii) {
buf[i + ii] = rnds[ii];
}
}
return buf || bytesToUuid(rnds);
}
var v4_1 = v4$1;
var v1 = v1_1;
var v4 = v4_1;
var uuid = v4;
uuid.v1 = v1;
uuid.v4 = v4;
var uuid_1 = uuid;
function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
/**
* Registrar connector implementation for twilsock -- @todo Drop twilsock.connector COMPLETELY?!
*/
var TwilsockConnector = /*#__PURE__*/function (_Connector) {
_inherits__default['default'](TwilsockConnector, _Connector);
var _super = _createSuper$1(TwilsockConnector);
/**
* Create twilsock registration connector.
* @param productId product ID
* @param platform platform ID string
* @param twilsock {TwilsockClient} connection transport.
*/
function TwilsockConnector(productId, platform, twilsock) {
var _this;
_classCallCheck__default['default'](this, TwilsockConnector);
_this = _super.call(this, "twilsock");
_defineProperty__default['default'](_assertThisInitialized__default['default'](_this), "contextId", uuid_1.v4());
_this.productId = productId;
_this.platform = platform;
_this.twilsock = twilsock;
return _this;
}
_createClass__default['default'](TwilsockConnector, [{
key: "updateRegistration",
value: function () {
var _updateRegistration = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(registration, reasons) {
var messageTypes, context;
return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (reasons.has("messageType")) {
_context.next = 2;
break;
}
return _context.abrupt("return", registration);
case 2:
messageTypes = Array.from(registration.messageTypes);
context = {
product_id: this.productId,
notification_protocol_version: 4,
endpoint_platform: this.platform,
message_types: messageTypes
};
_context.prev = 4;
_context.next = 7;
return this.twilsock.setNotificationsContext(this.contextId, context);
case 7:
_context.next = 13;
break;
case 9:
_context.prev = 9;
_context.t0 = _context["catch"](4);
logInstance.error("Failed to update twilsock notification context: ".concat(_context.t0));
throw _context.t0;
case 13:
return _context.abrupt("return", registration);
case 14:
case "end":
return _context.stop();
}
}
}, _callee, this, [[4, 9]]);
}));
function updateRegistration(_x, _x2) {
return _updateRegistration.apply(this, arguments);
}
return updateRegistration;
}()
}, {
key: "removeRegistration",
value: function () {
var _removeRegistration = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2() {
return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.prev = 0;
_context2.next = 3;
return this.twilsock.removeNotificationsContext(this.contextId);
case 3:
_context2.next = 9;
break;
case 5:
_context2.prev = 5;
_context2.t0 = _context2["catch"](0);
logInstance.error("Failed to remove twilsock notification context: ".concat(_context2.t0));
throw _context2.t0;
case 9:
case "end":
return _context2.stop();
}
}
}, _callee2, this, [[0, 5]]);
}));
function removeRegistration() {
return _removeRegistration.apply(this, arguments);
}
return removeRegistration;
}() // eslint-disable-next-line @typescript-eslint/no-unused-vars
}, {
key: "sendDeviceRemoveRequest",
value: function () {
var _sendDeviceRemoveRequest = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3(registrationId) {
return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
case "end":
return _context3.stop();
}
}
}, _callee3);
}));
function sendDeviceRemoveRequest(_x3) {
return _sendDeviceRemoveRequest.apply(this, arguments);
}
return sendDeviceRemoveRequest;
}()
}]);
return TwilsockConnector;
}(Connector);
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }

@@ -719,3 +1032,3 @@

_this.connectors.set("twilsock", new twilsock_connector.TwilsockConnector(productId, platform, twilsock$1));
_this.connectors.set("twilsock", new TwilsockConnector(productId, platform, twilsock$1));

@@ -722,0 +1035,0 @@ twilsock$1.on("stateChanged", function (state) {

4

package.json
{
"name": "@twilio/notifications",
"version": "1.0.2",
"version": "1.0.3-rc.0",
"description": "Client library for Twilio Notifications service",

@@ -44,3 +44,3 @@ "author": "Twilio",

"loglevel": "^1.6.3",
"twilsock": "^0.11.5"
"twilsock": "^0.11.6-rc.0"
},

@@ -47,0 +47,0 @@ "devDependencies": {

Sorry, the diff of this file is too big to display

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc