@monterosa/sdk-enmasse-kit 0.19.0-rc.6 → 2.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index.esm.js → index.js} +189 -110
- package/dist/index.js.map +1 -0
- package/package.json +20 -14
- package/dist/index.cjs.js +0 -2115
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js.map +0 -1
|
@@ -1,8 +1,77 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { checkAvailability, getItem, Emitter, getGlobal, getErrorMessage } from '@monterosa/sdk-util';
|
|
2
|
+
import { storageRead, storageWrite, storageRemove } from '@monterosa/sdk-storage-kit';
|
|
3
|
+
import { getParentApplication } from '@monterosa/sdk-launcher-kit';
|
|
4
|
+
|
|
5
|
+
function _arrayLikeToArray(r, a) {
|
|
6
|
+
(null == a || a > r.length) && (a = r.length);
|
|
7
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
8
|
+
return n;
|
|
9
|
+
}
|
|
10
|
+
function _arrayWithHoles(r) {
|
|
11
|
+
if (Array.isArray(r)) return r;
|
|
12
|
+
}
|
|
13
|
+
function _defineProperty(e, r, t) {
|
|
14
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
15
|
+
value: t,
|
|
16
|
+
enumerable: !0,
|
|
17
|
+
configurable: !0,
|
|
18
|
+
writable: !0
|
|
19
|
+
}) : e[r] = t, e;
|
|
20
|
+
}
|
|
21
|
+
function _iterableToArrayLimit(r, l) {
|
|
22
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
23
|
+
if (null != t) {
|
|
24
|
+
var e,
|
|
25
|
+
n,
|
|
26
|
+
i,
|
|
27
|
+
u,
|
|
28
|
+
a = [],
|
|
29
|
+
f = !0,
|
|
30
|
+
o = !1;
|
|
31
|
+
try {
|
|
32
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
33
|
+
if (Object(t) !== t) return;
|
|
34
|
+
f = !1;
|
|
35
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
36
|
+
} catch (r) {
|
|
37
|
+
o = !0, n = r;
|
|
38
|
+
} finally {
|
|
39
|
+
try {
|
|
40
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
41
|
+
} finally {
|
|
42
|
+
if (o) throw n;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return a;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function _nonIterableRest() {
|
|
49
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
50
|
+
}
|
|
51
|
+
function _slicedToArray(r, e) {
|
|
52
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
53
|
+
}
|
|
54
|
+
function _toPrimitive(t, r) {
|
|
55
|
+
if ("object" != typeof t || !t) return t;
|
|
56
|
+
var e = t[Symbol.toPrimitive];
|
|
57
|
+
if (void 0 !== e) {
|
|
58
|
+
var i = e.call(t, r || "default");
|
|
59
|
+
if ("object" != typeof i) return i;
|
|
60
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
61
|
+
}
|
|
62
|
+
return ("string" === r ? String : Number)(t);
|
|
63
|
+
}
|
|
64
|
+
function _toPropertyKey(t) {
|
|
65
|
+
var i = _toPrimitive(t, "string");
|
|
66
|
+
return "symbol" == typeof i ? i : i + "";
|
|
67
|
+
}
|
|
68
|
+
function _unsupportedIterableToArray(r, a) {
|
|
69
|
+
if (r) {
|
|
70
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
71
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
72
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
6
75
|
|
|
7
76
|
var ARG_OVERRIDE_METHODS = 'enmasse_override_methods';
|
|
8
77
|
var ARG_DEBUG = 'enmasse_debug';
|
|
@@ -41,7 +110,7 @@ var getSettingFor = name => {
|
|
|
41
110
|
};
|
|
42
111
|
var getSettingForMethods = () => {
|
|
43
112
|
var value = getSettingFor(ARG_OVERRIDE_METHODS);
|
|
44
|
-
if (value
|
|
113
|
+
if (typeof value === 'string') {
|
|
45
114
|
return value.split(',');
|
|
46
115
|
}
|
|
47
116
|
return undefined;
|
|
@@ -50,7 +119,7 @@ var ENMASSE_OVERRIDE_METHODS = getSettingForMethods();
|
|
|
50
119
|
var ENMASSE_DEBUG = getSettingFor(ARG_DEBUG);
|
|
51
120
|
var ENMASSE_CONFIG = getSettingFor(ARG_CONFIG);
|
|
52
121
|
|
|
53
|
-
var version = "0.
|
|
122
|
+
var version = "2.0.0-rc.2";
|
|
54
123
|
|
|
55
124
|
/* eslint no-bitwise: "off" */
|
|
56
125
|
var TYPE_PROTOCOL = 1; // 0000 0000 0001
|
|
@@ -1250,21 +1319,56 @@ var Enmasse = (() => {
|
|
|
1250
1319
|
* Private methods
|
|
1251
1320
|
*/
|
|
1252
1321
|
|
|
1253
|
-
var storeSession = id => {
|
|
1254
|
-
|
|
1255
|
-
|
|
1322
|
+
var storeSession = async id => {
|
|
1323
|
+
try {
|
|
1324
|
+
await storageWrite(PARAM_SESSION_ID, id);
|
|
1325
|
+
} catch (err) {
|
|
1326
|
+
console.error("Failed to persist session to shared storage: ".concat(getErrorMessage(err)));
|
|
1256
1327
|
}
|
|
1257
1328
|
};
|
|
1258
|
-
var
|
|
1259
|
-
|
|
1260
|
-
|
|
1329
|
+
var restoreSession = async () => {
|
|
1330
|
+
var restoredId = null;
|
|
1331
|
+
|
|
1332
|
+
// Read session from shared storage
|
|
1333
|
+
try {
|
|
1334
|
+
restoredId = await storageRead(PARAM_SESSION_ID);
|
|
1335
|
+
} catch (err) {
|
|
1336
|
+
console.error("Failed to read session from shared storage: ".concat(getErrorMessage(err)));
|
|
1261
1337
|
}
|
|
1262
|
-
|
|
1338
|
+
if (restoredId !== null) {
|
|
1339
|
+
return restoredId;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
/**
|
|
1343
|
+
* Further down is a special case when we try to restore session id from the
|
|
1344
|
+
* local storage and save it to the shared storage. This could happen in
|
|
1345
|
+
* previous versions of the SDK when we didn't have a shared storage.
|
|
1346
|
+
*/
|
|
1347
|
+
|
|
1348
|
+
if (getParentApplication() === null) {
|
|
1349
|
+
return null;
|
|
1350
|
+
}
|
|
1351
|
+
try {
|
|
1352
|
+
restoredId = getItem(PARAM_SESSION_ID);
|
|
1353
|
+
} catch (err) {
|
|
1354
|
+
console.error("Failed to read local session during migration: ".concat(getErrorMessage(err)));
|
|
1355
|
+
}
|
|
1356
|
+
if (restoredId === null) {
|
|
1357
|
+
return null;
|
|
1358
|
+
}
|
|
1359
|
+
try {
|
|
1360
|
+
await storageWrite(PARAM_SESSION_ID, restoredId);
|
|
1361
|
+
} catch (err) {
|
|
1362
|
+
console.error("Failed to persist session to shared storage during migration: ".concat(getErrorMessage(err)));
|
|
1363
|
+
}
|
|
1364
|
+
return restoredId;
|
|
1263
1365
|
};
|
|
1264
|
-
var resetSession = () => {
|
|
1366
|
+
var resetSession = async () => {
|
|
1265
1367
|
sessionId = null;
|
|
1266
|
-
|
|
1267
|
-
|
|
1368
|
+
try {
|
|
1369
|
+
await storageRemove(PARAM_SESSION_ID);
|
|
1370
|
+
} catch (err) {
|
|
1371
|
+
console.error("Failed to remove session from shared storage: ".concat(getErrorMessage(err)));
|
|
1268
1372
|
}
|
|
1269
1373
|
};
|
|
1270
1374
|
var validateSession = id =>
|
|
@@ -1366,7 +1470,7 @@ var Enmasse = (() => {
|
|
|
1366
1470
|
break;
|
|
1367
1471
|
}
|
|
1368
1472
|
};
|
|
1369
|
-
var handleConnectionManagerMessage = message => {
|
|
1473
|
+
var handleConnectionManagerMessage = async message => {
|
|
1370
1474
|
log(TYPE_PROTOCOL, 'Enmasse::handleConnectionManagerMessage', message);
|
|
1371
1475
|
var data = parseSSCP(message);
|
|
1372
1476
|
switch (data.klass) {
|
|
@@ -1385,7 +1489,7 @@ var Enmasse = (() => {
|
|
|
1385
1489
|
if (sessionId === null) {
|
|
1386
1490
|
var _data$body = _slicedToArray(data.body, 1);
|
|
1387
1491
|
sessionId = _data$body[0];
|
|
1388
|
-
storeSession(sessionId);
|
|
1492
|
+
await storeSession(sessionId);
|
|
1389
1493
|
}
|
|
1390
1494
|
setTime(time);
|
|
1391
1495
|
queue.stash();
|
|
@@ -1435,6 +1539,16 @@ var Enmasse = (() => {
|
|
|
1435
1539
|
self.send(channel, 'avgcounter', data);
|
|
1436
1540
|
};
|
|
1437
1541
|
|
|
1542
|
+
/**
|
|
1543
|
+
* @internal
|
|
1544
|
+
*/
|
|
1545
|
+
self.PARAM_SESSION_ID = PARAM_SESSION_ID;
|
|
1546
|
+
|
|
1547
|
+
/**
|
|
1548
|
+
* @internal
|
|
1549
|
+
*/
|
|
1550
|
+
self.resetSession = resetSession;
|
|
1551
|
+
|
|
1438
1552
|
/*
|
|
1439
1553
|
* Public methods
|
|
1440
1554
|
*/
|
|
@@ -1493,99 +1607,64 @@ var Enmasse = (() => {
|
|
|
1493
1607
|
}
|
|
1494
1608
|
self.send(sysChannel, SSCP_KLASS_LOGOUT);
|
|
1495
1609
|
};
|
|
1496
|
-
self.init =
|
|
1497
|
-
var
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
_args = arguments;
|
|
1505
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
1506
|
-
while (1) {
|
|
1507
|
-
switch (_context.prev = _context.next) {
|
|
1508
|
-
case 0:
|
|
1509
|
-
config = _args.length > 0 && _args[0] !== undefined ? _args[0] : () => {};
|
|
1510
|
-
// config file is passed either as GET parameter or via constructor
|
|
1511
|
-
configFile = !ENMASSE_CONFIG ? config.config || null : ENMASSE_CONFIG;
|
|
1512
|
-
info = config.info || [];
|
|
1513
|
-
sessionId = recoverSession();
|
|
1514
|
-
if (typeof config.forceSecure === 'boolean') {
|
|
1515
|
-
forceSecure = config.forceSecure;
|
|
1516
|
-
}
|
|
1517
|
-
if (!(configFile === null)) {
|
|
1518
|
-
_context.next = 7;
|
|
1519
|
-
break;
|
|
1520
|
-
}
|
|
1521
|
-
throw 'EnMasse config file is not set';
|
|
1522
|
-
case 7:
|
|
1523
|
-
// If session id has invalid format
|
|
1524
|
-
if (sessionId !== null && !validateSession(sessionId)) {
|
|
1525
|
-
resetSession();
|
|
1526
|
-
}
|
|
1527
|
-
queue = new Queue({
|
|
1528
|
-
runner
|
|
1529
|
-
});
|
|
1530
|
-
TransportManager$1.bind(TransportManager$1.ON_READY, handleTransportManagerReady);
|
|
1531
|
-
ConnectionManager.bind(ConnectionManager.ON_STATE, handleConnectionManagerState);
|
|
1532
|
-
ConnectionManager.bind(ConnectionManager.ON_MESSAGE, handleConnectionManagerMessage);
|
|
1533
|
-
Demographics$1.bind(Demographics$1.ON_ADD_COUNTER, handleDemographicsCounter);
|
|
1534
|
-
_context.prev = 13;
|
|
1535
|
-
_context.next = 16;
|
|
1536
|
-
return fetch(configFile);
|
|
1537
|
-
case 16:
|
|
1538
|
-
response = _context.sent;
|
|
1539
|
-
status = response.status, text = response.statusText;
|
|
1540
|
-
_context.prev = 18;
|
|
1541
|
-
_context.next = 21;
|
|
1542
|
-
return response.json();
|
|
1543
|
-
case 21:
|
|
1544
|
-
data = _context.sent;
|
|
1545
|
-
_context.next = 28;
|
|
1546
|
-
break;
|
|
1547
|
-
case 24:
|
|
1548
|
-
_context.prev = 24;
|
|
1549
|
-
_context.t0 = _context["catch"](18);
|
|
1550
|
-
self.trigger(self.ON_ERROR, "Invalid JSON from config ".concat(configFile));
|
|
1551
|
-
return _context.abrupt("return");
|
|
1552
|
-
case 28:
|
|
1553
|
-
isSuccess = status >= 200 && status <= 300 ||
|
|
1554
|
-
// If you conclude with an XMLHttpRequest receiving status=0 and
|
|
1555
|
-
// statusText=null, this means the request was not allowed to be
|
|
1556
|
-
// performed.
|
|
1557
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#xmlhttprequests_being_stopped
|
|
1558
|
-
status === 0 && !!text || status === '';
|
|
1559
|
-
data.forceSecure = forceSecure;
|
|
1560
|
-
if (data.background_timeout === undefined) {
|
|
1561
|
-
data.background_timeout = 0;
|
|
1562
|
-
}
|
|
1563
|
-
if (isSuccess) {
|
|
1564
|
-
ConnectionManager.init(data);
|
|
1565
|
-
TransportManager$1.init(data);
|
|
1566
|
-
} else {
|
|
1567
|
-
self.trigger(self.ON_ERROR, "Failed to load config ".concat(configFile));
|
|
1568
|
-
}
|
|
1569
|
-
_context.next = 37;
|
|
1570
|
-
break;
|
|
1571
|
-
case 34:
|
|
1572
|
-
_context.prev = 34;
|
|
1573
|
-
_context.t1 = _context["catch"](13);
|
|
1574
|
-
self.trigger(self.ON_ERROR, "Error loading config: ".concat(_context.t1.message));
|
|
1575
|
-
case 37:
|
|
1576
|
-
case "end":
|
|
1577
|
-
return _context.stop();
|
|
1578
|
-
}
|
|
1579
|
-
}
|
|
1580
|
-
}, _callee, null, [[13, 34], [18, 24]]);
|
|
1581
|
-
}));
|
|
1582
|
-
function init() {
|
|
1583
|
-
return _init.apply(this, arguments);
|
|
1610
|
+
self.init = async function init() {
|
|
1611
|
+
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : () => {};
|
|
1612
|
+
// config file is passed either as GET parameter or via constructor
|
|
1613
|
+
configFile = !ENMASSE_CONFIG ? config.config || null : ENMASSE_CONFIG;
|
|
1614
|
+
info = config.info || [];
|
|
1615
|
+
sessionId = await restoreSession();
|
|
1616
|
+
if (typeof config.forceSecure === 'boolean') {
|
|
1617
|
+
forceSecure = config.forceSecure;
|
|
1584
1618
|
}
|
|
1585
|
-
|
|
1586
|
-
|
|
1619
|
+
if (configFile === null) {
|
|
1620
|
+
// eslint-disable-next-line
|
|
1621
|
+
throw 'EnMasse config file is not set';
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
// If session id has invalid format
|
|
1625
|
+
if (sessionId !== null && !validateSession(sessionId)) {
|
|
1626
|
+
await resetSession();
|
|
1627
|
+
}
|
|
1628
|
+
queue = new Queue({
|
|
1629
|
+
runner
|
|
1630
|
+
});
|
|
1631
|
+
TransportManager$1.bind(TransportManager$1.ON_READY, handleTransportManagerReady);
|
|
1632
|
+
ConnectionManager.bind(ConnectionManager.ON_STATE, handleConnectionManagerState);
|
|
1633
|
+
ConnectionManager.bind(ConnectionManager.ON_MESSAGE, handleConnectionManagerMessage);
|
|
1634
|
+
Demographics$1.bind(Demographics$1.ON_ADD_COUNTER, handleDemographicsCounter);
|
|
1635
|
+
try {
|
|
1636
|
+
var response = await fetch(configFile);
|
|
1637
|
+
var status = response.status,
|
|
1638
|
+
text = response.statusText;
|
|
1639
|
+
var data;
|
|
1640
|
+
try {
|
|
1641
|
+
data = await response.json();
|
|
1642
|
+
} catch (jsonErr) {
|
|
1643
|
+
self.trigger(self.ON_ERROR, "Invalid JSON from config ".concat(configFile));
|
|
1644
|
+
return;
|
|
1645
|
+
}
|
|
1646
|
+
var isSuccess = status >= 200 && status <= 300 ||
|
|
1647
|
+
// If you conclude with an XMLHttpRequest receiving status=0 and
|
|
1648
|
+
// statusText=null, this means the request was not allowed to be
|
|
1649
|
+
// performed.
|
|
1650
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#xmlhttprequests_being_stopped
|
|
1651
|
+
status === 0 && !!text || status === '';
|
|
1652
|
+
data.forceSecure = forceSecure;
|
|
1653
|
+
if (data.background_timeout === undefined) {
|
|
1654
|
+
data.background_timeout = 0;
|
|
1655
|
+
}
|
|
1656
|
+
if (isSuccess) {
|
|
1657
|
+
ConnectionManager.init(data);
|
|
1658
|
+
TransportManager$1.init(data);
|
|
1659
|
+
} else {
|
|
1660
|
+
self.trigger(self.ON_ERROR, "Failed to load config ".concat(configFile));
|
|
1661
|
+
}
|
|
1662
|
+
} catch (err) {
|
|
1663
|
+
self.trigger(self.ON_ERROR, "Error loading config: ".concat(err.message));
|
|
1664
|
+
}
|
|
1665
|
+
};
|
|
1587
1666
|
return self;
|
|
1588
1667
|
})();
|
|
1589
1668
|
|
|
1590
1669
|
export { Enmasse as default };
|
|
1591
|
-
//# sourceMappingURL=index.
|
|
1670
|
+
//# sourceMappingURL=index.js.map
|