node-opcua-client 2.126.0 → 2.127.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-opcua-client",
3
- "version": "2.126.0",
3
+ "version": "2.127.0",
4
4
  "description": "pure nodejs OPCUA SDK - module client",
5
5
  "scripts": {
6
6
  "clean": "npx rimraf node_modules dist *.tsbuildinfo certificates",
@@ -17,12 +17,12 @@
17
17
  "@types/async": "^3.2.24",
18
18
  "async": "^3.2.5",
19
19
  "chalk": "4.1.2",
20
- "node-opcua-alarm-condition": "2.126.0",
20
+ "node-opcua-alarm-condition": "2.127.0",
21
21
  "node-opcua-assert": "2.120.0",
22
22
  "node-opcua-basic-types": "2.126.0",
23
23
  "node-opcua-buffer-utils": "2.125.0",
24
24
  "node-opcua-certificate-manager": "2.125.0",
25
- "node-opcua-client-dynamic-extension-object": "2.126.0",
25
+ "node-opcua-client-dynamic-extension-object": "2.127.0",
26
26
  "node-opcua-common": "2.126.0",
27
27
  "node-opcua-constants": "2.125.0",
28
28
  "node-opcua-crypto": "4.8.0",
@@ -35,7 +35,7 @@
35
35
  "node-opcua-nodeid": "2.125.0",
36
36
  "node-opcua-object-registry": "2.125.0",
37
37
  "node-opcua-pki": "4.10.0",
38
- "node-opcua-pseudo-session": "2.126.0",
38
+ "node-opcua-pseudo-session": "2.127.0",
39
39
  "node-opcua-schemas": "2.126.0",
40
40
  "node-opcua-secure-channel": "2.126.0",
41
41
  "node-opcua-service-browse": "2.126.0",
@@ -62,7 +62,7 @@
62
62
  "@types/underscore": "^1.11.15",
63
63
  "dequeue": "^1.0.5",
64
64
  "mocha": "^10.4.0",
65
- "node-opcua-address-space": "2.126.0",
65
+ "node-opcua-address-space": "2.127.0",
66
66
  "node-opcua-binary-stream": "2.125.0",
67
67
  "node-opcua-factory": "2.126.0",
68
68
  "node-opcua-leak-detector": "2.125.0",
@@ -91,7 +91,7 @@
91
91
  "internet of things"
92
92
  ],
93
93
  "homepage": "http://node-opcua.github.io/",
94
- "gitHead": "81b467f284c41813ab8caf17f6d20322d4734fdc",
94
+ "gitHead": "29da2933b3dbe51c9ca124a26655e346e6e9dcdc",
95
95
  "files": [
96
96
  "dist",
97
97
  "source"
@@ -199,10 +199,10 @@ function __findEndpoint(this: ClientBaseImpl, endpointUrl: string, params: FindE
199
199
  return callback(
200
200
  new Error(
201
201
  "Cannot find an Endpoint matching " +
202
- " security mode: " +
203
- securityMode.toString() +
204
- " policy: " +
205
- securityPolicy.toString()
202
+ " security mode: " +
203
+ securityMode.toString() +
204
+ " policy: " +
205
+ securityPolicy.toString()
206
206
  )
207
207
  );
208
208
  }
@@ -634,8 +634,8 @@ export class ClientBaseImpl extends OPCUASecureObject implements OPCUAClientBase
634
634
  const newServerCertificate = this.serverCertificate!;
635
635
  warningLog("new server certificate ", makeSHA1Thumbprint(newServerCertificate).toString("hex"));
636
636
 
637
- const sha1Old = makeSHA1Thumbprint(oldServerCertificate!);
638
- const sha1New = makeSHA1Thumbprint(newServerCertificate);
637
+ const sha1Old = oldServerCertificate ? makeSHA1Thumbprint(oldServerCertificate!) : null;
638
+ const sha1New = newServerCertificate ? makeSHA1Thumbprint(newServerCertificate) : null;
639
639
  if (sha1Old === sha1New) {
640
640
  warningLog("server certificate has not changed, but was expected to have changed");
641
641
  return _failAndRetry(
@@ -824,8 +824,8 @@ export class ClientBaseImpl extends OPCUASecureObject implements OPCUAClientBase
824
824
  // disconnect
825
825
  errorLog(
826
826
  "[NODE-OPCUA-E08] initializeCM: clientCertificateManager is null\n" +
827
- " This happen when you disconnected the client, to free resources.\n" +
828
- " Please create a new OPCUAClient instance if you want to reconnect"
827
+ " This happen when you disconnected the client, to free resources.\n" +
828
+ " Please create a new OPCUAClient instance if you want to reconnect"
829
829
  );
830
830
  return;
831
831
  }
@@ -961,12 +961,12 @@ export class ClientBaseImpl extends OPCUASecureObject implements OPCUAClientBase
961
961
  debugLog(chalk.yellow("- The client cannot to :" + endpointUrl + ". Server is not reachable."));
962
962
  err = new Error(
963
963
  "The connection cannot be established with server " +
964
- endpointUrl +
965
- " .\n" +
966
- "Please check that the server is up and running or your network configuration.\n" +
967
- "Err = (" +
968
- err.message +
969
- ")"
964
+ endpointUrl +
965
+ " .\n" +
966
+ "Please check that the server is up and running or your network configuration.\n" +
967
+ "Err = (" +
968
+ err.message +
969
+ ")"
970
970
  );
971
971
  this._handleUnrecoverableConnectionFailure(err, callback);
972
972
  } else if (err.message.match(/disconnecting/)) {
@@ -1001,9 +1001,9 @@ export class ClientBaseImpl extends OPCUASecureObject implements OPCUAClientBase
1001
1001
  return callback(
1002
1002
  new Error(
1003
1003
  "performMessageTransaction: Invalid client state = " +
1004
- this._internalState +
1005
- " while performing a transaction " +
1006
- request.schema.name
1004
+ this._internalState +
1005
+ " while performing a transaction " +
1006
+ request.schema.name
1007
1007
  )
1008
1008
  );
1009
1009
  }
@@ -1427,9 +1427,9 @@ export class ClientBaseImpl extends OPCUASecureObject implements OPCUAClientBase
1427
1427
  // no matching end point can be found ...
1428
1428
  const err1 = new Error(
1429
1429
  "cannot find endpoint for securityMode=" +
1430
- MessageSecurityMode[this.securityMode] +
1431
- " policy = " +
1432
- this.securityPolicy
1430
+ MessageSecurityMode[this.securityMode] +
1431
+ " policy = " +
1432
+ this.securityPolicy
1433
1433
  );
1434
1434
  return callback(err1);
1435
1435
  }
@@ -1453,7 +1453,7 @@ export class ClientBaseImpl extends OPCUASecureObject implements OPCUAClientBase
1453
1453
  if (chain.length > 1) {
1454
1454
  warningLog(
1455
1455
  " verify also that the issuer certificate is trusted and the issuer's certificate is present in the issuer.cert folder\n" +
1456
- " of the client certificate manager located in ",
1456
+ " of the client certificate manager located in ",
1457
1457
  this.clientCertificateManager.rootDir
1458
1458
  );
1459
1459
  } else {
@@ -28,4 +28,6 @@ export interface IClientBase {
28
28
  getTransportSettings(): IBasicTransportSettings;
29
29
 
30
30
  isUnusable(): boolean;
31
+
32
+ beforeSubscriptionRecreate?: (session: ClientSession) => Promise<Error | undefined>
31
33
  }
@@ -54,7 +54,7 @@ import { AnonymousIdentity, UserIdentityInfo, UserIdentityInfoUserName, UserIden
54
54
  import { repair_client_sessions } from "./reconnection/reconnection";
55
55
  import { ClientBaseImpl } from "./client_base_impl";
56
56
  import { ClientSessionImpl } from "./client_session_impl";
57
- import { ClientSubscriptionImpl } from "./client_subscription_impl";
57
+ import { IClientBase } from "./i_private_client";
58
58
 
59
59
  interface TokenAndSignature {
60
60
  userIdentityToken: UserIdentityToken | null;
@@ -108,7 +108,7 @@ const ordered: string[] = [
108
108
  SecurityPolicy.Basic256Sha256,
109
109
 
110
110
 
111
-
111
+
112
112
  SecurityPolicy.Aes128_Sha256_RsaOaep,
113
113
  SecurityPolicy.Aes256_Sha256_RsaPss
114
114
  ];
@@ -655,6 +655,12 @@ export class OPCUAClientImpl extends ClientBaseImpl implements OPCUAClient {
655
655
  ): Promise<T> {
656
656
  return await this.withSessionAsync(connectionPoint, async (session: ClientSession) => {
657
657
  assert(session, " session must exist");
658
+
659
+ const client1 = this as IClientBase;
660
+ if (client1.beforeSubscriptionRecreate) {
661
+ await client1.beforeSubscriptionRecreate(session);
662
+ }
663
+
658
664
  const subscription = await session.createSubscription2(parameters);
659
665
  try {
660
666
  const result = await func(session, subscription);
@@ -689,11 +695,11 @@ export class OPCUAClientImpl extends ClientBaseImpl implements OPCUAClient {
689
695
  return callback!(
690
696
  new Error(
691
697
  " End point must exist " +
692
- this._secureChannel!.endpointUrl +
693
- " securityMode = " +
694
- MessageSecurityMode[this.securityMode] +
695
- " securityPolicy = " +
696
- this.securityPolicy
698
+ this._secureChannel!.endpointUrl +
699
+ " securityMode = " +
700
+ MessageSecurityMode[this.securityMode] +
701
+ " securityPolicy = " +
702
+ this.securityPolicy
697
703
  )
698
704
  );
699
705
  }
@@ -1109,11 +1115,11 @@ export class OPCUAClientImpl extends ClientBaseImpl implements OPCUAClient {
1109
1115
  return callback(
1110
1116
  new Error(
1111
1117
  " End point must exist " +
1112
- this._secureChannel!.endpointUrl +
1113
- " securityMode = " +
1114
- MessageSecurityMode[this.securityMode] +
1115
- " securityPolicy = " +
1116
- this.securityPolicy
1118
+ this._secureChannel!.endpointUrl +
1119
+ " securityMode = " +
1120
+ MessageSecurityMode[this.securityMode] +
1121
+ " securityPolicy = " +
1122
+ this.securityPolicy
1117
1123
  )
1118
1124
  );
1119
1125
  }
@@ -33,14 +33,13 @@ async function createMonitoredItemsAndRespectOperationalLimits(
33
33
  }
34
34
 
35
35
  async function adjustMonitoredItemNodeIds(subscription: ClientSubscription, oldMonitoredItems: any) {
36
- // to Do
36
+ // to Do
37
37
  }
38
38
  /**
39
39
  * utility function to recreate new subscription
40
40
  * @method recreateSubscriptionAndMonitoredItem
41
41
  */
42
- export async function recreateSubscriptionAndMonitoredItem(_subscription: ClientSubscription): Promise<void>
43
- {
42
+ export async function recreateSubscriptionAndMonitoredItem(_subscription: ClientSubscription): Promise<void> {
44
43
  debugLog("recreateSubscriptionAndMonitoredItem", _subscription.subscriptionId.toString());
45
44
 
46
45
  const subscription = _subscription as ClientSubscriptionImpl;
@@ -55,14 +54,14 @@ export async function recreateSubscriptionAndMonitoredItem(_subscription: Client
55
54
  subscription.publishEngine.unregisterSubscription(oldSubscriptionId);
56
55
 
57
56
  await promisify(__create_subscription)(subscription);
58
-
59
- const _err = _shouldNotContinue(subscription.session);
60
- if (_err) { throw _err; }
57
+
58
+ const _err = _shouldNotContinue(subscription.session);
59
+ if (_err) { throw _err; }
61
60
 
62
61
  const test = subscription.publishEngine.getSubscription(subscription.subscriptionId);
63
62
 
64
63
  debugLog("recreating ", Object.keys(oldMonitoredItems).length, " monitored Items");
65
- // re-create monitored items
64
+ // re-create monitored items
66
65
  const itemsToCreate: MonitoredItemCreateRequestOptions[] = [];
67
66
 
68
67
  await adjustMonitoredItemNodeIds(subscription, oldMonitoredItems);
@@ -91,8 +90,8 @@ export async function recreateSubscriptionAndMonitoredItem(_subscription: Client
91
90
  debugLog("Recreating ", itemsToCreate.length, " monitored items");
92
91
 
93
92
  const response = await createMonitoredItemsAndRespectOperationalLimits(
94
- session,
95
- createMonitorItemsRequest);
93
+ session,
94
+ createMonitorItemsRequest);
96
95
  const monitoredItemResults = response.results || [];
97
96
 
98
97
  let _errCount = 0;
@@ -306,6 +306,24 @@ function repair_client_session_by_recreating_a_new_session(
306
306
  );
307
307
  },
308
308
 
309
+ function beforeSubscriptionRepair(innerCallback: ErrorCallback) {
310
+ if (!client.beforeSubscriptionRecreate) {
311
+ innerCallback();
312
+ return;
313
+
314
+ }
315
+ client.beforeSubscriptionRecreate(newSession)
316
+ .then((err) => {
317
+ { const err = _shouldNotContinue(session); if (err) { return innerCallback(err); } }
318
+ if (!err) {
319
+ innerCallback();
320
+ } else {
321
+ innerCallback(err);
322
+ }
323
+ })
324
+ .catch((err) => { innerCallback(err) });
325
+ },
326
+
309
327
  function attempt_subscription_transfer(innerCallback: ErrorCallback) {
310
328
  // prettier-ignore
311
329
  { const err = _shouldNotContinue(session); if (err) { return innerCallback(err); } }