node-opcua-server 2.149.0 → 2.151.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.
@@ -4,7 +4,7 @@
4
4
  import { EventEmitter } from "events";
5
5
  import chalk from "chalk";
6
6
  import { assert } from "node-opcua-assert";
7
- import { ISessionContext } from "node-opcua-address-space-base";
7
+ import { ISessionContext, UAMethod, UAObject } from "node-opcua-address-space-base";
8
8
  import { BaseNode, IEventData, makeAttributeEventName, SessionContext, UAVariable, AddressSpace } from "node-opcua-address-space";
9
9
  import { extractEventFields } from "node-opcua-service-filter";
10
10
  import { DateTime, UInt32 } from "node-opcua-basic-types";
@@ -56,6 +56,7 @@ import { appendToTimer, removeFromTimer } from "./node_sampler";
56
56
  import { validateFilter } from "./validate_filter";
57
57
  import { checkWhereClauseOnAdressSpace as checkWhereClauseOnAddressSpace } from "./filter/check_where_clause_on_address_space";
58
58
  import { SamplingFunc } from "./sampling_func";
59
+ import { MonitoredItemBase } from "./server_subscription";
59
60
 
60
61
  const errorLog = make_errorLog(__filename);
61
62
 
@@ -374,12 +375,12 @@ const badDataUnavailable = new DataValue({ statusCode: StatusCodes.BadDataUnavai
374
375
  * - It is up to the event receiver to call {{#crossLink "MonitoredItem/recordValue:method"}}{{/crossLink}}.
375
376
  *
376
377
  */
377
- export class MonitoredItem extends EventEmitter {
378
- public get node(): BaseNode | null {
378
+ export class MonitoredItem extends EventEmitter implements MonitoredItemBase {
379
+ public get node(): UAVariable | UAObject | UAMethod |null {
379
380
  return this._node;
380
381
  }
381
382
 
382
- public set node(someNode: BaseNode | null) {
383
+ public set node(someNode: UAVariable | UAObject | UAMethod | null) {
383
384
  throw new Error("Unexpected way to set node");
384
385
  }
385
386
 
@@ -403,7 +404,7 @@ export class MonitoredItem extends EventEmitter {
403
404
  public _samplingId?: NodeJS.Timeout | string;
404
405
  public samplingFunc: SamplingFunc | null = null;
405
406
 
406
- private _node: BaseNode | null;
407
+ private _node: UAVariable | UAObject | UAMethod | null;
407
408
  public queue: QueueItem[];
408
409
  private _semantic_version: number;
409
410
  private _is_sampling = false;
@@ -455,12 +456,12 @@ export class MonitoredItem extends EventEmitter {
455
456
  MonitoredItem.registry.register(this);
456
457
  }
457
458
 
458
- public setNode(node: BaseNode): void {
459
+ public setNode(node: UAVariable | UAObject | UAMethod): void {
459
460
  assert(!this.node || this.node === node, "node already set");
460
461
  this._node = node;
461
462
  this._semantic_version = (node as any).semantic_version;
462
463
  this._on_node_disposed_listener = () => this._on_node_disposed(this._node!);
463
- this._node.on("dispose", this._on_node_disposed_listener);
464
+ (this._node as BaseNode).on("dispose", this._on_node_disposed_listener);
464
465
  }
465
466
 
466
467
  public setMonitoringMode(monitoringMode: MonitoringMode): void {
@@ -1096,7 +1097,9 @@ export class MonitoredItem extends EventEmitter {
1096
1097
  if (!this._on_opcua_event_received_callback) {
1097
1098
  // we are monitoring OPCUA Event
1098
1099
  this._on_opcua_event_received_callback = this._on_opcua_event.bind(this);
1099
- this.node.on("event", this._on_opcua_event_received_callback);
1100
+ if (this.node && this.node.nodeClass == NodeClass.Object) {
1101
+ this.node.on("event", this._on_opcua_event_received_callback);
1102
+ }
1100
1103
  }
1101
1104
  return;
1102
1105
  }
@@ -1108,7 +1111,7 @@ export class MonitoredItem extends EventEmitter {
1108
1111
  if (!this._attribute_changed_callback) {
1109
1112
  this._attribute_changed_callback = this._on_value_changed.bind(this);
1110
1113
  const event_name = makeAttributeEventName(this.itemToMonitor.attributeId);
1111
- this.node.on(event_name, this._attribute_changed_callback);
1114
+ (this.node as BaseNode).on(event_name, this._attribute_changed_callback);
1112
1115
  }
1113
1116
 
1114
1117
  if (recordInitialValue) {
@@ -1126,8 +1129,10 @@ export class MonitoredItem extends EventEmitter {
1126
1129
  assert(!this._semantic_changed_callback);
1127
1130
  this._value_changed_callback = this._on_value_changed.bind(this);
1128
1131
  this._semantic_changed_callback = this._on_semantic_changed.bind(this);
1129
- this.node.on("value_changed", this._value_changed_callback);
1130
- this.node.on("semantic_changed", this._semantic_changed_callback);
1132
+ if (this.node.nodeClass == NodeClass.Variable) {
1133
+ this.node.on("value_changed", this._value_changed_callback);
1134
+ this.node.on("semantic_changed", this._semantic_changed_callback);
1135
+ }
1131
1136
  }
1132
1137
 
1133
1138
  // initiate first read
@@ -3620,10 +3620,17 @@ export class OPCUAServer extends OPCUABaseServer {
3620
3620
  }
3621
3621
  }
3622
3622
 
3623
- const userIdentityTokenPasswordRemoved = (userIdentityToken: any) => {
3624
- const a = userIdentityToken.clone();
3625
- // remove password
3626
- a.password = "*************";
3623
+ const userIdentityTokenPasswordRemoved = (userIdentityToken?: UserIdentityToken): UserIdentityToken => {
3624
+ if (!userIdentityToken) return new AnonymousIdentityToken();
3625
+ const a: UserIdentityToken = userIdentityToken.clone();
3626
+ // For Username/Password tokens the password shall not be included.
3627
+ if (a instanceof UserNameIdentityToken) {
3628
+ // remove password
3629
+ a.password = Buffer.from("*************","ascii");
3630
+ }
3631
+ // if (a instanceof X509IdentityToken) {
3632
+ // a.certificateData = Buffer.alloc(0);
3633
+ // }
3627
3634
  return a;
3628
3635
  };
3629
3636
 
@@ -574,6 +574,7 @@ export class ServerEngine extends EventEmitter implements IAddressSpaceAccessor
574
574
  for (const task of this._shutdownTasks) {
575
575
  await task.call(this);
576
576
  }
577
+ this.setServerState(ServerState.Invalid);
577
578
 
578
579
  this.dispose();
579
580
  }
@@ -13,7 +13,10 @@ import {
13
13
  Duration,
14
14
  UAObjectType,
15
15
  ISessionContext,
16
- IAddressSpace
16
+ IAddressSpace,
17
+ UAVariable,
18
+ UAObject,
19
+ UAMethod
17
20
  } from "node-opcua-address-space";
18
21
  import { assert } from "node-opcua-assert";
19
22
  import { Byte, UInt32 } from "node-opcua-basic-types";
@@ -40,7 +43,7 @@ import {
40
43
  MonitoredItemCreateRequest
41
44
  } from "node-opcua-service-subscription";
42
45
  import { StatusCode, StatusCodes } from "node-opcua-status-code";
43
- import { AggregateFilterResult, ContentFilterResult, EventFieldList, EventFilterResult, NotificationData } from "node-opcua-types";
46
+ import { AggregateFilterResult, ContentFilterResult, EventFieldList, EventFilterResult, MonitoringFilter, NotificationData } from "node-opcua-types";
44
47
  import { Queue } from "./queue";
45
48
 
46
49
  import { MonitoredItem, MonitoredItemOptions, QueueItem } from "./monitored_item";
@@ -465,7 +468,14 @@ export interface InternalCreateMonitoredItemResult {
465
468
  }
466
469
 
467
470
  export interface MonitoredItemBase {
468
- node: any | null;
471
+ node: UAVariable | UAObject | UAMethod | null;
472
+ // from monitoring parameters
473
+ filter: MonitoringFilter | null;
474
+ monitoringMode: MonitoringMode;
475
+ timestampsToReturn: TimestampsToReturn;
476
+ discardOldest: boolean;
477
+ queueSize: number;
478
+ clientHandle: UInt32;
469
479
  }
470
480
  export type CreateMonitoredItemHook = (subscription: Subscription, monitoredItem: MonitoredItemBase) => Promise<StatusCode>;
471
481
  export type DeleteMonitoredItemHook = (subscription: Subscription, monitoredItem: MonitoredItemBase) => Promise<StatusCode>;
@@ -1030,8 +1040,8 @@ export class Subscription extends EventEmitter {
1030
1040
 
1031
1041
  const itemToMonitor = monitoredItemCreateRequest.itemToMonitor;
1032
1042
 
1033
- const node = addressSpace.findNode(itemToMonitor.nodeId);
1034
- if (!node) {
1043
+ const node = addressSpace.findNode(itemToMonitor.nodeId) as UAObject | UAVariable | UAMethod;
1044
+ if (!node || (node.nodeClass !== NodeClass.Variable && node.nodeClass !== NodeClass.Object && node.nodeClass !== NodeClass.Method)) {
1035
1045
  return handle_error(StatusCodes.BadNodeIdUnknown);
1036
1046
  }
1037
1047