@tdxvolt/volt-client-grpc 0.14.58 → 0.14.60

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/lib/index.cjs CHANGED
@@ -603,6 +603,7 @@ class VoltCredential {
603
603
  aud: audience,
604
604
  iat: Math.floor(Date.now() / 1000) - ttl,
605
605
  exp: Math.floor(Date.now() / 1000) + ttl,
606
+ sub: this._cryptoCache.client_id,
606
607
  };
607
608
 
608
609
  let sharedKey;
@@ -1082,50 +1083,55 @@ class GRPCCall extends EventEmitter__default["default"] {
1082
1083
  const log$2 = debug__default["default"]("volt-client-grpc:volt-connection");
1083
1084
 
1084
1085
  function _cleanUp(immediateReconnect) {
1085
- this._session = false;
1086
-
1087
- if (this._pingTimer) {
1088
- clearTimeout(this._pingTimer);
1089
- this._pingTimer = 0;
1090
- }
1091
-
1092
- if (this._pingTimeoutTimer) {
1093
- clearTimeout(this._pingTimeoutTimer);
1094
- this._pingTimeoutTimer = 0;
1095
- }
1096
-
1097
- if (
1098
- !this._dying &&
1099
- (immediateReconnect || (this._autoRetry && !this._reconnectTimer))
1100
- ) {
1101
- this._reconnectTimer = setTimeout(
1102
- () => {
1103
- this._reconnectTimer = 0;
1104
- _doConnect.call(this);
1105
- },
1106
- immediateReconnect ? 0 : this._reconnectInterval,
1107
- );
1108
- }
1109
-
1110
- if (this.call?.writable) {
1111
- this.call.end();
1112
- }
1086
+ this._connectionId = "";
1087
+
1088
+ if (this._pingTimer) {
1089
+ clearTimeout(this._pingTimer);
1090
+ this._pingTimer = 0;
1091
+ }
1092
+
1093
+ if (this._pingTimeoutTimer) {
1094
+ clearTimeout(this._pingTimeoutTimer);
1095
+ this._pingTimeoutTimer = 0;
1096
+ }
1097
+
1098
+ if (
1099
+ !this._dying &&
1100
+ (immediateReconnect || (this._autoRetry && !this._reconnectTimer))
1101
+ ) {
1102
+ this._reconnectTimer = setTimeout(
1103
+ () => {
1104
+ this._reconnectTimer = 0;
1105
+ _doConnect.call(this, this._helloPayload);
1106
+ },
1107
+ immediateReconnect ? 0 : this._reconnectInterval,
1108
+ );
1109
+ }
1110
+
1111
+ if (this.call?.writable) {
1112
+ this.call.end();
1113
+ }
1113
1114
  }
1114
1115
 
1115
1116
  function _connectionTimeoutHandler() {
1116
- log$2("server timed out");
1117
- this.emit("connected", false);
1118
- _cleanUp.call(this);
1117
+ log$2("server timed out");
1118
+ this.emit("connected", false);
1119
+ _cleanUp.call(this);
1119
1120
  }
1120
1121
 
1121
- function _doConnect() {
1122
- this.call = new GRPCCall(this._voltClient, "Connect", "METHOD_TYPE_BIDI");
1122
+ function _doConnect(connectHello) {
1123
+ this.call = new GRPCCall(this._voltClient, "Connect", "METHOD_TYPE_BIDI");
1124
+
1125
+ const grpcClient = this._voltClient.getVoltAPIClient();
1126
+
1127
+ let helloPayload = connectHello;
1128
+ if (!connectHello) {
1129
+ log$2("defaulting hello payload");
1130
+ helloPayload = {
1131
+ hello: {},
1132
+ };
1133
+ }
1123
1134
 
1124
- const grpcClient = this._voltClient.getVoltAPIClient();
1125
- const helloPayload = {
1126
- hello: {},
1127
- };
1128
-
1129
1135
  this.call.on("error", (err) => {
1130
1136
  log$2("error on connection stream [%s]", err.message);
1131
1137
  _cleanUp.call(this);
@@ -1146,10 +1152,11 @@ function _doConnect() {
1146
1152
  _startPingTimer.call(this);
1147
1153
  break;
1148
1154
  }
1149
- case "hello": {
1150
- if (!this._session) {
1151
- this._session = true;
1152
- this.emit("connected", this._session);
1155
+ case "acknowledge": {
1156
+ if (!this._connectionId) {
1157
+ this._connectionId = response.acknowledge.connection_id;
1158
+ log$2("connection id is %s", this._connectionId);
1159
+ this.emit("connected", this._connectionId);
1153
1160
  }
1154
1161
  break;
1155
1162
  }
@@ -1165,74 +1172,76 @@ function _doConnect() {
1165
1172
  });
1166
1173
 
1167
1174
  this.call.on("end", () => {
1168
- if (this._session) {
1175
+ if (this._connectionId) {
1169
1176
  this.emit("connected", false);
1170
1177
  }
1171
1178
  _cleanUp.call(this);
1172
1179
  });
1173
1180
 
1174
- this.call.start(grpcClient, helloPayload);
1181
+ this.call.start(grpcClient, helloPayload);
1175
1182
 
1176
- _startPingTimer.call(this);
1183
+ _startPingTimer.call(this);
1177
1184
  }
1178
1185
 
1179
1186
  function _startPingTimer() {
1180
- if (this._pingTimer) {
1181
- log$2("ping timer running");
1182
- return;
1183
- }
1184
-
1185
- this._pingTimer = setTimeout(() => {
1186
- // Send next ping to server.
1187
- const request = { ping: { timestamp: Date.now() } };
1188
-
1189
- log$2("pinging Volt");
1190
- this.call.write(request);
1191
-
1192
- this._pingTimer = 0;
1193
-
1194
- // Schedule a timeout if we don't hear back from the server.
1195
- if (this._pingTimeoutTimer) {
1196
- clearTimeout(this._pingTimeoutTimer);
1197
- }
1198
-
1199
- this._pingTimeoutTimer = setTimeout(
1200
- _connectionTimeoutHandler.bind(this),
1201
- this._timeoutInterval,
1202
- );
1203
- }, this._pingInterval);
1187
+ if (this._pingTimer) {
1188
+ log$2("ping timer running");
1189
+ return;
1190
+ }
1191
+
1192
+ this._pingTimer = setTimeout(() => {
1193
+ // Send next ping to server.
1194
+ const request = { ping: { timestamp: Date.now() } };
1195
+
1196
+ log$2("pinging Volt");
1197
+ this.call.write(request);
1198
+
1199
+ this._pingTimer = 0;
1200
+
1201
+ // Schedule a timeout if we don't hear back from the server.
1202
+ if (this._pingTimeoutTimer) {
1203
+ clearTimeout(this._pingTimeoutTimer);
1204
+ }
1205
+
1206
+ this._pingTimeoutTimer = setTimeout(
1207
+ _connectionTimeoutHandler.bind(this),
1208
+ this._timeoutInterval,
1209
+ );
1210
+ }, this._pingInterval);
1204
1211
  }
1205
1212
 
1206
1213
  class VoltConnection extends EventEmitter__default["default"] {
1207
- constructor(voltClient, grpc) {
1208
- super();
1209
-
1210
- const config = voltClient.config;
1211
- this._grpc = grpc;
1212
- this._autoRetry =
1213
- config.autoReconnect === undefined ? true : !!config.autoReconnect;
1214
- this._dying = false;
1215
- this._voltClient = voltClient;
1216
- this._pingTimer = 0;
1217
- this._pingTimeoutTimer = 0;
1218
- this._session = false;
1219
- this._pingInterval = config.pingInterval || 10000;
1220
- this._reconnectInterval = config.reconnectInterval || 5000;
1221
- this._timeoutInterval = config.timeoutInterval || 60000;
1222
- }
1223
-
1224
- connect(throwOnFail) {
1225
- if (throwOnFail) {
1226
- return _doConnect.call(this);
1227
- } else {
1228
- return Promise.resolve(_cleanUp.call(this, true));
1229
- }
1230
- }
1231
-
1232
- disconnect() {
1233
- this._dying = true;
1234
- _cleanUp.call(this);
1235
- }
1214
+ constructor(voltClient, grpc) {
1215
+ super();
1216
+
1217
+ const config = voltClient.config;
1218
+ this._grpc = grpc;
1219
+ this._autoRetry =
1220
+ config.autoReconnect === undefined ? true : !!config.autoReconnect;
1221
+ this._dying = false;
1222
+ this._voltClient = voltClient;
1223
+ this._pingTimer = 0;
1224
+ this._pingTimeoutTimer = 0;
1225
+ this._connectionId = "";
1226
+ this._pingInterval = config.pingInterval || 10000;
1227
+ this._reconnectInterval = config.reconnectInterval || 5000;
1228
+ this._timeoutInterval = config.timeoutInterval || 60000;
1229
+ this._helloPayload = undefined;
1230
+ }
1231
+
1232
+ connect(helloPayload, throwOnFail) {
1233
+ this._helloPayload = helloPayload;
1234
+ if (throwOnFail) {
1235
+ return _doConnect.call(this, this._helloPayload);
1236
+ } else {
1237
+ return Promise.resolve(_cleanUp.call(this, true));
1238
+ }
1239
+ }
1240
+
1241
+ disconnect() {
1242
+ this._dying = true;
1243
+ _cleanUp.call(this);
1244
+ }
1236
1245
  }
1237
1246
 
1238
1247
  /* eslint-disable no-underscore-dangle */
@@ -1413,7 +1422,7 @@ async function bindInternal() {
1413
1422
  }
1414
1423
  }
1415
1424
 
1416
- function connectInternal() {
1425
+ function connectInternal(helloPayload) {
1417
1426
  try {
1418
1427
  if (this._voltConnection) {
1419
1428
  log$1("connectInternal - Volt connection already exists");
@@ -1443,7 +1452,7 @@ function connectInternal() {
1443
1452
  if (!this._connected) {
1444
1453
  onDisconnected();
1445
1454
  }
1446
- this.emit("connected", !!session);
1455
+ this.emit("connected", session);
1447
1456
  });
1448
1457
 
1449
1458
  this._voltConnection.on("error", (err) => {
@@ -1459,7 +1468,7 @@ function connectInternal() {
1459
1468
  this.emit("evt", evt);
1460
1469
  });
1461
1470
 
1462
- return this._voltConnection.connect();
1471
+ return this._voltConnection.connect(helloPayload);
1463
1472
  } catch (err) {
1464
1473
  log$1("connect - error [%s]", err.message);
1465
1474
  throw err;
@@ -1758,10 +1767,10 @@ class VoltClient extends EventEmitter__default["default"] {
1758
1767
  }
1759
1768
  }
1760
1769
 
1761
- initialiseAndConnect(configPath, extras = {}) {
1770
+ initialiseAndConnect(configPath, helloPayload = undefined, extras = {}) {
1762
1771
  return this.initialise(configPath, extras)
1763
1772
  .then(() => {
1764
- return connectInternal.call(this);
1773
+ return connectInternal.call(this, helloPayload);
1765
1774
  })
1766
1775
  .catch((err) => {
1767
1776
  log("initialiseAndConnect failure: %s", err.message);
@@ -1834,8 +1843,8 @@ class VoltClient extends EventEmitter__default["default"] {
1834
1843
  return this.isRemote && !this._voltConfig?.relay.cloud;
1835
1844
  }
1836
1845
 
1837
- connect() {
1838
- return connectInternal.call(this);
1846
+ connect(helloPayload) {
1847
+ return connectInternal.call(this, helloPayload);
1839
1848
  }
1840
1849
 
1841
1850
  disconnect() {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.14.58",
6
+ "version": "0.14.60",
7
7
  "description": "tdx Volt library for nodejs clients",
8
8
  "type": "module",
9
9
  "exports": {
@@ -48,4 +48,4 @@
48
48
  "node-forge": "^0.9.0",
49
49
  "uuid": "^8.1.0"
50
50
  }
51
- }
51
+ }
@@ -187,7 +187,7 @@ export async function bindInternal() {
187
187
  }
188
188
  }
189
189
 
190
- export function connectInternal() {
190
+ export function connectInternal(helloPayload) {
191
191
  try {
192
192
  if (this._voltConnection) {
193
193
  log("connectInternal - Volt connection already exists");
@@ -217,7 +217,7 @@ export function connectInternal() {
217
217
  if (!this._connected) {
218
218
  onDisconnected();
219
219
  }
220
- this.emit("connected", !!session);
220
+ this.emit("connected", session);
221
221
  });
222
222
 
223
223
  this._voltConnection.on("error", (err) => {
@@ -233,7 +233,7 @@ export function connectInternal() {
233
233
  this.emit("evt", evt);
234
234
  });
235
235
 
236
- return this._voltConnection.connect();
236
+ return this._voltConnection.connect(helloPayload);
237
237
  } catch (err) {
238
238
  log("connect - error [%s]", err.message);
239
239
  throw err;
@@ -189,10 +189,10 @@ export class VoltClient extends EventEmitter {
189
189
  }
190
190
  }
191
191
 
192
- initialiseAndConnect(configPath, extras = {}) {
192
+ initialiseAndConnect(configPath, helloPayload = undefined, extras = {}) {
193
193
  return this.initialise(configPath, extras)
194
194
  .then(() => {
195
- return connectInternal.call(this);
195
+ return connectInternal.call(this, helloPayload);
196
196
  })
197
197
  .catch((err) => {
198
198
  log("initialiseAndConnect failure: %s", err.message);
@@ -265,8 +265,8 @@ export class VoltClient extends EventEmitter {
265
265
  return this.isRemote && !this._voltConfig?.relay.cloud;
266
266
  }
267
267
 
268
- connect() {
269
- return connectInternal.call(this);
268
+ connect(helloPayload) {
269
+ return connectInternal.call(this, helloPayload);
270
270
  }
271
271
 
272
272
  disconnect() {
@@ -7,50 +7,55 @@ import GRPCCall from "./grpc-call.js";
7
7
  const log = debug("volt-client-grpc:volt-connection");
8
8
 
9
9
  function _cleanUp(immediateReconnect) {
10
- this._session = false;
11
-
12
- if (this._pingTimer) {
13
- clearTimeout(this._pingTimer);
14
- this._pingTimer = 0;
15
- }
16
-
17
- if (this._pingTimeoutTimer) {
18
- clearTimeout(this._pingTimeoutTimer);
19
- this._pingTimeoutTimer = 0;
20
- }
21
-
22
- if (
23
- !this._dying &&
24
- (immediateReconnect || (this._autoRetry && !this._reconnectTimer))
25
- ) {
26
- this._reconnectTimer = setTimeout(
27
- () => {
28
- this._reconnectTimer = 0;
29
- _doConnect.call(this);
30
- },
31
- immediateReconnect ? 0 : this._reconnectInterval,
32
- );
33
- }
34
-
35
- if (this.call?.writable) {
36
- this.call.end();
37
- }
10
+ this._connectionId = "";
11
+
12
+ if (this._pingTimer) {
13
+ clearTimeout(this._pingTimer);
14
+ this._pingTimer = 0;
15
+ }
16
+
17
+ if (this._pingTimeoutTimer) {
18
+ clearTimeout(this._pingTimeoutTimer);
19
+ this._pingTimeoutTimer = 0;
20
+ }
21
+
22
+ if (
23
+ !this._dying &&
24
+ (immediateReconnect || (this._autoRetry && !this._reconnectTimer))
25
+ ) {
26
+ this._reconnectTimer = setTimeout(
27
+ () => {
28
+ this._reconnectTimer = 0;
29
+ _doConnect.call(this, this._helloPayload);
30
+ },
31
+ immediateReconnect ? 0 : this._reconnectInterval,
32
+ );
33
+ }
34
+
35
+ if (this.call?.writable) {
36
+ this.call.end();
37
+ }
38
38
  }
39
39
 
40
40
  function _connectionTimeoutHandler() {
41
- log("server timed out");
42
- this.emit("connected", false);
43
- _cleanUp.call(this);
41
+ log("server timed out");
42
+ this.emit("connected", false);
43
+ _cleanUp.call(this);
44
44
  }
45
45
 
46
- function _doConnect() {
47
- this.call = new GRPCCall(this._voltClient, "Connect", "METHOD_TYPE_BIDI");
46
+ function _doConnect(connectHello) {
47
+ this.call = new GRPCCall(this._voltClient, "Connect", "METHOD_TYPE_BIDI");
48
+
49
+ const grpcClient = this._voltClient.getVoltAPIClient();
50
+
51
+ let helloPayload = connectHello;
52
+ if (!connectHello) {
53
+ log("defaulting hello payload");
54
+ helloPayload = {
55
+ hello: {},
56
+ };
57
+ }
48
58
 
49
- const grpcClient = this._voltClient.getVoltAPIClient();
50
- const helloPayload = {
51
- hello: {},
52
- };
53
-
54
59
  this.call.on("error", (err) => {
55
60
  log("error on connection stream [%s]", err.message);
56
61
  _cleanUp.call(this);
@@ -71,10 +76,11 @@ function _doConnect() {
71
76
  _startPingTimer.call(this);
72
77
  break;
73
78
  }
74
- case "hello": {
75
- if (!this._session) {
76
- this._session = true;
77
- this.emit("connected", this._session);
79
+ case "acknowledge": {
80
+ if (!this._connectionId) {
81
+ this._connectionId = response.acknowledge.connection_id;
82
+ log("connection id is %s", this._connectionId);
83
+ this.emit("connected", this._connectionId);
78
84
  }
79
85
  break;
80
86
  }
@@ -90,72 +96,74 @@ function _doConnect() {
90
96
  });
91
97
 
92
98
  this.call.on("end", () => {
93
- if (this._session) {
99
+ if (this._connectionId) {
94
100
  this.emit("connected", false);
95
101
  }
96
102
  _cleanUp.call(this);
97
103
  });
98
104
 
99
- this.call.start(grpcClient, helloPayload);
105
+ this.call.start(grpcClient, helloPayload);
100
106
 
101
- _startPingTimer.call(this);
107
+ _startPingTimer.call(this);
102
108
  }
103
109
 
104
110
  function _startPingTimer() {
105
- if (this._pingTimer) {
106
- log("ping timer running");
107
- return;
108
- }
109
-
110
- this._pingTimer = setTimeout(() => {
111
- // Send next ping to server.
112
- const request = { ping: { timestamp: Date.now() } };
113
-
114
- log("pinging Volt");
115
- this.call.write(request);
116
-
117
- this._pingTimer = 0;
118
-
119
- // Schedule a timeout if we don't hear back from the server.
120
- if (this._pingTimeoutTimer) {
121
- clearTimeout(this._pingTimeoutTimer);
122
- }
123
-
124
- this._pingTimeoutTimer = setTimeout(
125
- _connectionTimeoutHandler.bind(this),
126
- this._timeoutInterval,
127
- );
128
- }, this._pingInterval);
111
+ if (this._pingTimer) {
112
+ log("ping timer running");
113
+ return;
114
+ }
115
+
116
+ this._pingTimer = setTimeout(() => {
117
+ // Send next ping to server.
118
+ const request = { ping: { timestamp: Date.now() } };
119
+
120
+ log("pinging Volt");
121
+ this.call.write(request);
122
+
123
+ this._pingTimer = 0;
124
+
125
+ // Schedule a timeout if we don't hear back from the server.
126
+ if (this._pingTimeoutTimer) {
127
+ clearTimeout(this._pingTimeoutTimer);
128
+ }
129
+
130
+ this._pingTimeoutTimer = setTimeout(
131
+ _connectionTimeoutHandler.bind(this),
132
+ this._timeoutInterval,
133
+ );
134
+ }, this._pingInterval);
129
135
  }
130
136
 
131
137
  export default class VoltConnection extends EventEmitter {
132
- constructor(voltClient, grpc) {
133
- super();
134
-
135
- const config = voltClient.config;
136
- this._grpc = grpc;
137
- this._autoRetry =
138
- config.autoReconnect === undefined ? true : !!config.autoReconnect;
139
- this._dying = false;
140
- this._voltClient = voltClient;
141
- this._pingTimer = 0;
142
- this._pingTimeoutTimer = 0;
143
- this._session = false;
144
- this._pingInterval = config.pingInterval || 10000;
145
- this._reconnectInterval = config.reconnectInterval || 5000;
146
- this._timeoutInterval = config.timeoutInterval || 60000;
147
- }
148
-
149
- connect(throwOnFail) {
150
- if (throwOnFail) {
151
- return _doConnect.call(this);
152
- } else {
153
- return Promise.resolve(_cleanUp.call(this, true));
154
- }
155
- }
156
-
157
- disconnect() {
158
- this._dying = true;
159
- _cleanUp.call(this);
160
- }
138
+ constructor(voltClient, grpc) {
139
+ super();
140
+
141
+ const config = voltClient.config;
142
+ this._grpc = grpc;
143
+ this._autoRetry =
144
+ config.autoReconnect === undefined ? true : !!config.autoReconnect;
145
+ this._dying = false;
146
+ this._voltClient = voltClient;
147
+ this._pingTimer = 0;
148
+ this._pingTimeoutTimer = 0;
149
+ this._connectionId = "";
150
+ this._pingInterval = config.pingInterval || 10000;
151
+ this._reconnectInterval = config.reconnectInterval || 5000;
152
+ this._timeoutInterval = config.timeoutInterval || 60000;
153
+ this._helloPayload = undefined;
154
+ }
155
+
156
+ connect(helloPayload, throwOnFail) {
157
+ this._helloPayload = helloPayload;
158
+ if (throwOnFail) {
159
+ return _doConnect.call(this, this._helloPayload);
160
+ } else {
161
+ return Promise.resolve(_cleanUp.call(this, true));
162
+ }
163
+ }
164
+
165
+ disconnect() {
166
+ this._dying = true;
167
+ _cleanUp.call(this);
168
+ }
161
169
  }
@@ -149,6 +149,7 @@ export class VoltCredential {
149
149
  aud: audience,
150
150
  iat: Math.floor(Date.now() / 1000) - ttl,
151
151
  exp: Math.floor(Date.now() / 1000) + ttl,
152
+ sub: this._cryptoCache.client_id,
152
153
  };
153
154
 
154
155
  let sharedKey;