node-opcua-client 2.166.0 → 2.168.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.
Files changed (102) hide show
  1. package/dist/alarms_and_conditions/client_alarm_tools.d.ts +1 -1
  2. package/dist/alarms_and_conditions/client_alarm_tools.js +2 -2
  3. package/dist/alarms_and_conditions/client_alarm_tools.js.map +1 -1
  4. package/dist/alarms_and_conditions/client_tools.d.ts +3 -0
  5. package/dist/alarms_and_conditions/client_tools.js +2 -2
  6. package/dist/alarms_and_conditions/client_tools.js.map +1 -1
  7. package/dist/client_base.d.ts +47 -40
  8. package/dist/client_base.js +5 -6
  9. package/dist/client_base.js.map +1 -1
  10. package/dist/client_monitored_item.d.ts +7 -7
  11. package/dist/client_monitored_item.js.map +1 -1
  12. package/dist/client_monitored_item_base.d.ts +12 -13
  13. package/dist/client_monitored_item_group.d.ts +5 -5
  14. package/dist/client_monitored_item_toolbox.d.ts +6 -7
  15. package/dist/client_monitored_item_toolbox.js.map +1 -1
  16. package/dist/client_session.d.ts +19 -23
  17. package/dist/client_session.js.map +1 -1
  18. package/dist/client_session_keepalive_manager.d.ts +1 -1
  19. package/dist/client_session_keepalive_manager.js +6 -6
  20. package/dist/client_session_keepalive_manager.js.map +1 -1
  21. package/dist/client_subscription.d.ts +11 -12
  22. package/dist/client_subscription.js.map +1 -1
  23. package/dist/client_utils.d.ts +3 -3
  24. package/dist/client_utils.js.map +1 -1
  25. package/dist/common.d.ts +12 -12
  26. package/dist/index.d.ts +26 -27
  27. package/dist/index.js +65 -66
  28. package/dist/index.js.map +1 -1
  29. package/dist/opcua_client.d.ts +17 -19
  30. package/dist/opcua_client.js.map +1 -1
  31. package/dist/private/client_base_impl.d.ts +19 -18
  32. package/dist/private/client_base_impl.js +220 -192
  33. package/dist/private/client_base_impl.js.map +1 -1
  34. package/dist/private/client_monitored_item_group_impl.d.ts +4 -5
  35. package/dist/private/client_monitored_item_group_impl.js +1 -1
  36. package/dist/private/client_monitored_item_group_impl.js.map +1 -1
  37. package/dist/private/client_monitored_item_impl.d.ts +9 -10
  38. package/dist/private/client_monitored_item_impl.js.map +1 -1
  39. package/dist/private/client_publish_engine.d.ts +3 -3
  40. package/dist/private/client_publish_engine.js +6 -7
  41. package/dist/private/client_publish_engine.js.map +1 -1
  42. package/dist/private/client_session_impl.d.ts +24 -25
  43. package/dist/private/client_session_impl.js +14 -10
  44. package/dist/private/client_session_impl.js.map +1 -1
  45. package/dist/private/client_subscription_impl.d.ts +10 -11
  46. package/dist/private/client_subscription_impl.js +12 -11
  47. package/dist/private/client_subscription_impl.js.map +1 -1
  48. package/dist/private/i_private_client.d.ts +7 -7
  49. package/dist/private/opcua_client_impl.d.ts +12 -9
  50. package/dist/private/opcua_client_impl.js +58 -48
  51. package/dist/private/opcua_client_impl.js.map +1 -1
  52. package/dist/private/performance.js.map +1 -1
  53. package/dist/private/reconnection/client_publish_engine_reconnection.d.ts +1 -1
  54. package/dist/private/reconnection/client_publish_engine_reconnection.js +54 -43
  55. package/dist/private/reconnection/client_publish_engine_reconnection.js.map +1 -1
  56. package/dist/private/reconnection/client_reconnection.d.ts +1 -1
  57. package/dist/private/reconnection/client_subscription_reconnection.d.ts +1 -1
  58. package/dist/private/reconnection/client_subscription_reconnection.js +2 -2
  59. package/dist/private/reconnection/client_subscription_reconnection.js.map +1 -1
  60. package/dist/private/reconnection/reconnection.d.ts +4 -4
  61. package/dist/private/reconnection/reconnection.js +200 -281
  62. package/dist/private/reconnection/reconnection.js.map +1 -1
  63. package/dist/tools/findservers.d.ts +7 -2
  64. package/dist/tools/findservers.js +41 -53
  65. package/dist/tools/findservers.js.map +1 -1
  66. package/dist/tools/read_history_server_capabilities.d.ts +1 -1
  67. package/dist/tools/read_history_server_capabilities.js +9 -8
  68. package/dist/tools/read_history_server_capabilities.js.map +1 -1
  69. package/dist/user_identity_info.d.ts +1 -1
  70. package/dist/verify.js.map +1 -1
  71. package/package.json +45 -45
  72. package/source/alarms_and_conditions/client_alarm_tools.ts +14 -8
  73. package/source/alarms_and_conditions/client_tools.ts +7 -6
  74. package/source/client_base.ts +93 -79
  75. package/source/client_monitored_item.ts +7 -8
  76. package/source/client_monitored_item_base.ts +12 -14
  77. package/source/client_monitored_item_group.ts +5 -5
  78. package/source/client_monitored_item_toolbox.ts +13 -14
  79. package/source/client_session.ts +37 -40
  80. package/source/client_session_keepalive_manager.ts +7 -10
  81. package/source/client_subscription.ts +11 -12
  82. package/source/client_utils.ts +6 -6
  83. package/source/common.ts +12 -12
  84. package/source/index.ts +44 -40
  85. package/source/opcua_client.ts +24 -23
  86. package/source/private/client_base_impl.ts +329 -290
  87. package/source/private/client_monitored_item_group_impl.ts +10 -14
  88. package/source/private/client_monitored_item_impl.ts +17 -17
  89. package/source/private/client_publish_engine.ts +11 -12
  90. package/source/private/client_session_impl.ts +85 -82
  91. package/source/private/client_subscription_impl.ts +42 -41
  92. package/source/private/i_private_client.ts +8 -8
  93. package/source/private/opcua_client_impl.ts +118 -97
  94. package/source/private/performance.ts +2 -3
  95. package/source/private/reconnection/client_publish_engine_reconnection.ts +76 -68
  96. package/source/private/reconnection/client_reconnection.ts +1 -1
  97. package/source/private/reconnection/client_subscription_reconnection.ts +16 -13
  98. package/source/private/reconnection/reconnection.ts +307 -301
  99. package/source/tools/findservers.ts +43 -62
  100. package/source/tools/read_history_server_capabilities.ts +20 -22
  101. package/source/user_identity_info.ts +5 -5
  102. package/source/verify.ts +25 -25
@@ -1,17 +1,29 @@
1
1
  /**
2
2
  * @module node-opcua-client
3
3
  */
4
- import async from "async";
5
4
 
6
- import { ErrorCallback } from "node-opcua-status-code";
7
- import { ServerOnNetwork } from "node-opcua-service-discovery";
8
- import { ApplicationDescription, EndpointDescription } from "node-opcua-service-endpoints";
5
+ import type { ServerOnNetwork } from "node-opcua-service-discovery";
6
+ import type { ApplicationDescription, EndpointDescription } from "node-opcua-service-endpoints";
7
+
8
+
9
9
  import { ClientBaseImpl } from "../private/client_base_impl";
10
10
 
11
11
  export interface FindServerResults {
12
12
  servers: ApplicationDescription[];
13
13
  endpoints: EndpointDescription[];
14
14
  }
15
+ export async function findServersAsync(discoveryServerEndpointUri: string): Promise<FindServerResults> {
16
+ const client = new ClientBaseImpl({ connectionStrategy: { maxRetry: 3 } });
17
+ try {
18
+ await client.connect(discoveryServerEndpointUri);
19
+ const servers = await client.findServers();
20
+ const endpoints = await client.getEndpoints({ endpointUrl: undefined });
21
+ return { servers, endpoints };
22
+ } finally {
23
+ await client.disconnect();
24
+ }
25
+ }
26
+
15
27
  /**
16
28
  * extract the server endpoints exposed by a discovery server
17
29
  */
@@ -19,52 +31,34 @@ export function findServers(
19
31
  discoveryServerEndpointUri: string,
20
32
  callback: (err: Error | null, result?: FindServerResults) => void
21
33
  ): void;
22
- export async function findServers(discoveryServerEndpointUri: string): Promise<FindServerResults>;
34
+ export function findServers(discoveryServerEndpointUri: string): Promise<FindServerResults>;
23
35
  export function findServers(
24
36
  discoveryServerEndpointUri: string,
25
37
  callback?: (err: Error | null, result?: FindServerResults) => void
26
- ): any {
38
+ ): Promise<FindServerResults> | undefined {
39
+ if (!callback) {
40
+ return findServersAsync(discoveryServerEndpointUri);
41
+ }
42
+ findServersAsync(discoveryServerEndpointUri)
43
+ .then((result) => callback(null, result))
44
+ .catch((err) => callback(err));
45
+ return undefined;
46
+ }
47
+ export async function findServersOnNetworkAsync(discoveryServerEndpointUri: string): Promise<ServerOnNetwork[]> {
27
48
  const client = new ClientBaseImpl({ connectionStrategy: { maxRetry: 3 } });
28
-
29
- let servers: ApplicationDescription[] = [];
30
- let endpoints: EndpointDescription[] = [];
31
-
32
- async.series(
33
- [
34
- (innerCallback: ErrorCallback) => {
35
- client.connect(discoveryServerEndpointUri, innerCallback);
36
- },
37
-
38
- (innerCallback: ErrorCallback) => {
39
- client.findServers((err: Error | null, _servers?: ApplicationDescription[]) => {
40
- if (_servers) {
41
- servers = _servers;
42
- }
43
- innerCallback(err ? err : undefined);
44
- });
45
- },
46
-
47
- (innerCallback: ErrorCallback) => {
48
- client.getEndpoints({ endpointUrl: undefined }, (err: Error | null, _endpoints?: EndpointDescription[]) => {
49
- if (_endpoints) {
50
- endpoints = _endpoints;
51
- }
52
- innerCallback(err ? err : undefined);
53
- });
54
- }
55
- ],
56
- (err) => {
57
- client.disconnect(() => {
58
- callback!(err ? err : null, { servers, endpoints });
59
- });
60
- }
61
- );
49
+ try {
50
+ await client.connect(discoveryServerEndpointUri);
51
+ const servers = await client.findServersOnNetwork();
52
+ return servers;
53
+ } finally {
54
+ await client.disconnect();
55
+ }
62
56
  }
63
57
 
64
58
  /**
65
59
  * extract the server endpoints exposed by a discovery server
66
60
  */
67
- export async function findServersOnNetwork(discoveryServerEndpointUri: string): Promise<ServerOnNetwork[]>;
61
+ export function findServersOnNetwork(discoveryServerEndpointUri: string): Promise<ServerOnNetwork[]>;
68
62
  export function findServersOnNetwork(
69
63
  discoveryServerEndpointUri: string,
70
64
  callback: (err: Error | null, servers?: ServerOnNetwork[]) => void
@@ -72,25 +66,12 @@ export function findServersOnNetwork(
72
66
  export function findServersOnNetwork(
73
67
  discoveryServerEndpointUri: string,
74
68
  callback?: (err: Error | null, servers?: ServerOnNetwork[]) => void
75
- ): any {
76
- const client = new ClientBaseImpl({ connectionStrategy: { maxRetry: 3 } });
77
-
78
- client.connect(discoveryServerEndpointUri, (err?: Error) => {
79
- if (!err) {
80
- client.findServersOnNetwork((err1, servers) => {
81
- client.disconnect(() => {
82
- callback!(err1, servers);
83
- });
84
- });
85
- } else {
86
- client.disconnect(() => {
87
- callback!(err);
88
- });
89
- }
90
- });
69
+ ): Promise<ServerOnNetwork[]> | undefined {
70
+ if (!callback) {
71
+ return findServersOnNetworkAsync(discoveryServerEndpointUri);
72
+ }
73
+ findServersOnNetworkAsync(discoveryServerEndpointUri)
74
+ .then((servers) => callback(null, servers))
75
+ .catch((err) => callback(err));
76
+ return undefined;
91
77
  }
92
-
93
- // tslint:disable:no-var-requires
94
- import { withCallback } from "thenify-ex";
95
- (module.exports as any).findServersOnNetwork = withCallback((module.exports as any).findServersOnNetwork);
96
- (module.exports as any).findServers = withCallback((module.exports as any).findServers);
@@ -4,15 +4,15 @@
4
4
  import { assert } from "node-opcua-assert";
5
5
  import { ObjectIds } from "node-opcua-constants";
6
6
  import { AttributeIds } from "node-opcua-data-model";
7
- import { DataValue } from "node-opcua-data-value";
7
+ import type { DataValue } from "node-opcua-data-value";
8
8
  import { NodeId } from "node-opcua-nodeid";
9
- import { ReadValueIdOptions } from "node-opcua-service-read";
10
- import { BrowsePath, BrowsePathResult, makeBrowsePath } from "node-opcua-service-translate-browse-path";
9
+ import type { ReadValueIdOptions } from "node-opcua-service-read";
10
+ import { type BrowsePath, type BrowsePathResult, makeBrowsePath } from "node-opcua-service-translate-browse-path";
11
11
  import { StatusCodes } from "node-opcua-status-code";
12
12
  import { lowerFirstLetter } from "node-opcua-utils";
13
- import { Variant } from "node-opcua-variant";
13
+ import type { Variant } from "node-opcua-variant";
14
14
 
15
- import { ClientSession } from "../client_session";
15
+ import type { ClientSession } from "../client_session";
16
16
 
17
17
  export interface HistoryServerCapabilities {
18
18
  [key: string]: any;
@@ -28,7 +28,14 @@ export function readHistoryServerCapabilities(
28
28
  callback?: (err: Error | null, capabilities?: HistoryServerCapabilities) => void
29
29
  ): any {
30
30
  if (!callback) {
31
- throw new Error("Internal error");
31
+ return new Promise<HistoryServerCapabilities>((resolve, reject) => {
32
+ readHistoryServerCapabilities(session, (err, capabilities) => {
33
+ if (err) {
34
+ return reject(err);
35
+ }
36
+ resolve(capabilities!);
37
+ });
38
+ });
32
39
  }
33
40
  // display HistoryCapabilities of server
34
41
  const browsePath: BrowsePath = makeBrowsePath(ObjectIds.ObjectsFolder, "/Server/ServerCapabilities.HistoryServerCapabilities");
@@ -55,24 +62,24 @@ export function readHistoryServerCapabilities(
55
62
  const properties = [
56
63
  "AccessHistoryDataCapability",
57
64
  "AccessHistoryEventsCapability",
58
-
65
+
59
66
  "DeleteAtTimeCapability",
60
67
  "DeleteRawCapability",
61
68
  "DeleteEventCapability",
62
-
69
+
63
70
  "InsertAnnotationCapability",
64
71
  "InsertDataCapability",
65
72
  "InsertEventCapability",
66
-
73
+
67
74
  "ReplaceDataCapability",
68
75
  "ReplaceEventCapability",
69
-
76
+
70
77
  "UpdateDataCapability",
71
78
  "UpdateEventCapability",
72
-
79
+
73
80
  "MaxReturnDataValues",
74
81
  "MaxReturnEventValues",
75
-
82
+
76
83
  "AggregateFunctions/AnnotationCount",
77
84
  "AggregateFunctions/Average",
78
85
  "AggregateFunctions/Count",
@@ -95,9 +102,7 @@ export function readHistoryServerCapabilities(
95
102
  }
96
103
 
97
104
  const nodeIds = results.map((innerResult: BrowsePathResult) =>
98
- innerResult.statusCode.isGood() && innerResult.targets
99
- ? innerResult.targets[0].targetId
100
- : new NodeId()
105
+ innerResult.statusCode.isGood() && innerResult.targets ? innerResult.targets[0].targetId : new NodeId()
101
106
  );
102
107
 
103
108
  const nodesToRead: ReadValueIdOptions[] = nodeIds.map((nodeId: NodeId) => ({
@@ -125,10 +130,3 @@ export function readHistoryServerCapabilities(
125
130
  });
126
131
  });
127
132
  }
128
- // tslint:disable:no-var-requires
129
- import { withCallback } from "thenify-ex";
130
- const opts = { multiArgs: false };
131
- (module as any).exports.readHistoryServerCapabilities = withCallback(
132
- (module as any).exports.readHistoryServerCapabilities,
133
- opts
134
- );
@@ -1,6 +1,6 @@
1
- export {
2
- UserIdentityInfoUserName,
3
- UserIdentityInfoX509,
4
- AnonymousIdentity,
5
- UserIdentityInfo
1
+ export {
2
+ AnonymousIdentity,
3
+ UserIdentityInfo,
4
+ UserIdentityInfoUserName,
5
+ UserIdentityInfoX509
6
6
  } from "node-opcua-pseudo-session";
package/source/verify.ts CHANGED
@@ -24,8 +24,8 @@ export function verifyIsOPCUAValidCertificate(
24
24
  // certificate is not active yet
25
25
  warningLog(
26
26
  `[NODE-OPCUA-W02] The certificate is not active yet\n` +
27
- `notBefore ${certificateInfo.tbsCertificate.validity.notBefore.toISOString()}\n` +
28
- `certificateFile ${certificateFile}`
27
+ `notBefore ${certificateInfo.tbsCertificate.validity.notBefore.toISOString()}\n` +
28
+ `certificateFile ${certificateFile}`
29
29
  );
30
30
  }
31
31
  // check that certificate has not expired
@@ -33,9 +33,9 @@ export function verifyIsOPCUAValidCertificate(
33
33
  // certificate is obsolete
34
34
  warningLog(
35
35
  `[NODE-OPCUA-W03] The certificate has expired\n` +
36
- `Please regenerate a valid certificate\n` +
37
- `notAfter = ${certificateInfo.tbsCertificate.validity.notAfter.toISOString()}\n` +
38
- `certificateFile= ${certificateFile}`
36
+ `Please regenerate a valid certificate\n` +
37
+ `notAfter = ${certificateInfo.tbsCertificate.validity.notAfter.toISOString()}\n` +
38
+ `certificateFile= ${certificateFile}`
39
39
  );
40
40
  } else {
41
41
  const tenDays = 10 * 24 * 60 * 60 * 1000;
@@ -43,9 +43,9 @@ export function verifyIsOPCUAValidCertificate(
43
43
  // certificate is going to expired very soon
44
44
  warningLog(
45
45
  `[NODE-OPCUA-W05] The certificate is about to expire in less than 10 days.\n` +
46
- `Please regenerate a valid certificate as soon as possible\n` +
47
- `notAfter = ${certificateInfo.tbsCertificate.validity.notAfter.toISOString()}\n` +
48
- `certificateFile= ${certificateFile}\n`
46
+ `Please regenerate a valid certificate as soon as possible\n` +
47
+ `notAfter = ${certificateInfo.tbsCertificate.validity.notAfter.toISOString()}\n` +
48
+ `certificateFile= ${certificateFile}\n`
49
49
  );
50
50
  }
51
51
  }
@@ -54,18 +54,18 @@ export function verifyIsOPCUAValidCertificate(
54
54
  if (!uniformResourceIdentifier) {
55
55
  warningLog(
56
56
  `[NODE-OPCUA-W14] The certificate subjectAltName uniformResourceIdentifier is missing.\n` +
57
- `Please regenerate a specific certificate with a uniformResourceIdentifier that matches your ${type} applicationUri\n` +
58
- `applicationUri = ${applicationUri}\n` +
59
- `certificateFile = ${certificateFile}\n`
57
+ `Please regenerate a specific certificate with a uniformResourceIdentifier that matches your ${type} applicationUri\n` +
58
+ `applicationUri = ${applicationUri}\n` +
59
+ `certificateFile = ${certificateFile}\n`
60
60
  );
61
61
  return;
62
62
  } else if (uniformResourceIdentifier[0] !== applicationUri) {
63
63
  warningLog(
64
64
  `[NODE-OPCUA-W06] The certificate subjectAltName does not match the ${type} applicationUri\n` +
65
- `Please regenerate a specific certificate that matches your ${type} applicationUri\n` +
66
- `certificate subjectAltName = ${uniformResourceIdentifier[0]}\n` +
67
- `${type} applicationUri = ${applicationUri}\n` +
68
- `certificateFile = ${certificateFile}\n`
65
+ `Please regenerate a specific certificate that matches your ${type} applicationUri\n` +
66
+ `certificate subjectAltName = ${uniformResourceIdentifier[0]}\n` +
67
+ `${type} applicationUri = ${applicationUri}\n` +
68
+ `certificateFile = ${certificateFile}\n`
69
69
  );
70
70
  }
71
71
  const keyUsage = certificateInfo.tbsCertificate.extensions?.keyUsage;
@@ -77,8 +77,8 @@ export function verifyIsOPCUAValidCertificate(
77
77
  if (!keyUsage.digitalSignature || !keyUsage.nonRepudiation || !keyUsage.keyEncipherment || !keyUsage.dataEncipherment) {
78
78
  warningLog(
79
79
  `[NODE-OPCUA-W16] The certificate keyUsage must include digitalSignature, nonRepudiation, keyEncipherment and dataEncipherment.\n` +
80
- `see https://reference.opcfoundation.org/v104/Core/docs/Part6/6.2.2/\n` +
81
- `certificateFile = ${certificateFile}`
80
+ `see https://reference.opcfoundation.org/v104/Core/docs/Part6/6.2.2/\n` +
81
+ `certificateFile = ${certificateFile}`
82
82
  );
83
83
  warningLog(`keyUsage = ${JSON.stringify(keyUsage, null, " ")}`);
84
84
  }
@@ -92,8 +92,8 @@ export function verifyIsOPCUAValidCertificate(
92
92
  if (!extKeyUsage.clientAuth && !extKeyUsage.serverAuth) {
93
93
  warningLog(
94
94
  `[NODE-OPCUA-W18] The certificate extKeyUsage must include clientAuth and/or serverAuth.\n` +
95
- `see https://reference.opcfoundation.org/v104/Core/docs/Part6/6.2.2/\n` +
96
- `certificateFile = ${certificateFile}`
95
+ `see https://reference.opcfoundation.org/v104/Core/docs/Part6/6.2.2/\n` +
96
+ `certificateFile = ${certificateFile}`
97
97
  );
98
98
  }
99
99
  }
@@ -102,14 +102,14 @@ export function verifyIsOPCUAValidCertificate(
102
102
  if (keyLengthInBits < 1024) {
103
103
  errorLog(
104
104
  `[NODE-OPCUA-W19] The public key length shall be greater than or equal to 1024 bits. key length is ${keyLengthInBits}.\n` +
105
- `see https://reference.opcfoundation.org/v104/GDS/docs/7.6.3/\n` +
106
- `certificateFile = ${certificateFile}`
105
+ `see https://reference.opcfoundation.org/v104/GDS/docs/7.6.3/\n` +
106
+ `certificateFile = ${certificateFile}`
107
107
  );
108
108
  } else if (keyLengthInBits < 2048) {
109
109
  warningLog(
110
110
  `[NODE-OPCUA-W23] key lengths less than 2048 are considered insecure. key length is ${keyLengthInBits}\n` +
111
- `see https://reference.opcfoundation.org/v104/Core/docs/Part2/6.8/\n` +
112
- `certificateFile = ${certificateFile}`
111
+ `see https://reference.opcfoundation.org/v104/Core/docs/Part2/6.8/\n` +
112
+ `certificateFile = ${certificateFile}`
113
113
  );
114
114
  }
115
115
  }
@@ -140,8 +140,8 @@ export async function performCertificateSanityCheck(
140
140
  if (keyLengthInBits <= 1024) {
141
141
  warningLog(
142
142
  `[NODE-OPCUA-W04] The public/private key pair uses a key length which is equal or lower than 1024 bits. ( key length was ${keyLengthInBits} )\n` +
143
- `OPCUA version 1.04 requires that security key length are greater or equal to 2048 bits.\n` +
144
- `The ${serverOrClient} is operating at risk. `
143
+ `OPCUA version 1.04 requires that security key length are greater or equal to 2048 bits.\n` +
144
+ `The ${serverOrClient} is operating at risk. `
145
145
  );
146
146
  }
147
147