@attraccess/plugin-wago 0.1.0-nightly.1112.1 → 0.1.0-nightly.1140.3

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.js CHANGED
@@ -52,9 +52,9 @@ var __decorateClass = (decorators, target, key, kind) => {
52
52
  var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
53
53
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
54
54
 
55
- // ../../../node_modules/.pnpm/ipaddr.js@2.4.0/node_modules/ipaddr.js/lib/ipaddr.js
55
+ // ../../../node_modules/.pnpm/ipaddr.js@2.5.0/node_modules/ipaddr.js/lib/ipaddr.js
56
56
  var require_ipaddr = __commonJS({
57
- "../../../node_modules/.pnpm/ipaddr.js@2.4.0/node_modules/ipaddr.js/lib/ipaddr.js"(exports2, module2) {
57
+ "../../../node_modules/.pnpm/ipaddr.js@2.5.0/node_modules/ipaddr.js/lib/ipaddr.js"(exports2, module2) {
58
58
  (function(root) {
59
59
  "use strict";
60
60
  const ipv4Part = "(0?\\d+|0x[a-f0-9]+)";
@@ -95,7 +95,7 @@ var require_ipaddr = __commonJS({
95
95
  if (string.substr(-2, 2) === "::") {
96
96
  colonCount--;
97
97
  }
98
- if (colonCount > parts) {
98
+ if (colonCount >= parts) {
99
99
  return null;
100
100
  }
101
101
  replacementCount = parts - colonCount;
@@ -114,7 +114,7 @@ var require_ipaddr = __commonJS({
114
114
  const ref = string.split(":");
115
115
  const results = [];
116
116
  for (let i = 0; i < ref.length; i++) {
117
- results.push(parseInt(ref[i], 16));
117
+ results.push(ref[i].length > 4 ? NaN : parseInt(ref[i], 16));
118
118
  }
119
119
  return results;
120
120
  })();
@@ -289,7 +289,7 @@ var require_ipaddr = __commonJS({
289
289
  }
290
290
  return new this(octets);
291
291
  } catch (e) {
292
- throw new Error("ipaddr: the address does not have IPv4 CIDR format");
292
+ throw new Error("ipaddr: the address does not have IPv4 CIDR format", { cause: e });
293
293
  }
294
294
  };
295
295
  ipaddr2.IPv4.isIPv4 = function(string) {
@@ -299,7 +299,7 @@ var require_ipaddr = __commonJS({
299
299
  try {
300
300
  new this(this.parser(string));
301
301
  return true;
302
- } catch (e) {
302
+ } catch {
303
303
  return false;
304
304
  }
305
305
  };
@@ -307,7 +307,7 @@ var require_ipaddr = __commonJS({
307
307
  try {
308
308
  this.parseCIDR(string);
309
309
  return true;
310
- } catch (e) {
310
+ } catch {
311
311
  return false;
312
312
  }
313
313
  };
@@ -339,7 +339,7 @@ var require_ipaddr = __commonJS({
339
339
  }
340
340
  return new this(octets);
341
341
  } catch (e) {
342
- throw new Error("ipaddr: the address does not have IPv4 CIDR format");
342
+ throw new Error("ipaddr: the address does not have IPv4 CIDR format", { cause: e });
343
343
  }
344
344
  };
345
345
  ipaddr2.IPv4.parse = function(string) {
@@ -424,7 +424,7 @@ var require_ipaddr = __commonJS({
424
424
  };
425
425
  ipaddr2.IPv4.subnetMaskFromPrefixLength = function(prefix) {
426
426
  prefix = parseInt(prefix);
427
- if (prefix < 0 || prefix > 32) {
427
+ if (Number.isNaN(prefix) || prefix < 0 || prefix > 32) {
428
428
  throw new Error("ipaddr: invalid IPv4 prefix length");
429
429
  }
430
430
  const octets = [0, 0, 0, 0];
@@ -624,20 +624,28 @@ var require_ipaddr = __commonJS({
624
624
  };
625
625
  IPv6.prototype.toRFC5952String = function() {
626
626
  const regex = /((^|:)(0(:|$)){2,})/g;
627
- const string = this.toNormalizedString();
627
+ let suffix = "";
628
+ if (this.zoneId) {
629
+ suffix = `%${this.zoneId}`;
630
+ }
631
+ const normalized = this.toNormalizedString();
632
+ const string = normalized.slice(0, normalized.length - suffix.length);
628
633
  let bestMatchIndex = 0;
629
634
  let bestMatchLength = -1;
635
+ let bestMatchGroups = -1;
630
636
  let match;
631
637
  while (match = regex.exec(string)) {
632
- if (match[0].length > bestMatchLength) {
638
+ const groups = (match[0].match(/0/g) || []).length;
639
+ if (groups > bestMatchGroups) {
640
+ bestMatchGroups = groups;
633
641
  bestMatchIndex = match.index;
634
642
  bestMatchLength = match[0].length;
635
643
  }
636
644
  }
637
645
  if (bestMatchLength < 0) {
638
- return string;
646
+ return string + suffix;
639
647
  }
640
- return `${string.substring(0, bestMatchIndex)}::${string.substring(bestMatchIndex + bestMatchLength)}`;
648
+ return `${string.substring(0, bestMatchIndex)}::${string.substring(bestMatchIndex + bestMatchLength)}${suffix}`;
641
649
  };
642
650
  IPv6.prototype.toString = function() {
643
651
  return this.toRFC5952String();
@@ -657,7 +665,7 @@ var require_ipaddr = __commonJS({
657
665
  }
658
666
  return new this(octets);
659
667
  } catch (e) {
660
- throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${e})`);
668
+ throw new Error("ipaddr: the address does not have IPv6 CIDR format", { cause: e });
661
669
  }
662
670
  };
663
671
  ipaddr2.IPv6.isIPv6 = function(string) {
@@ -671,7 +679,7 @@ var require_ipaddr = __commonJS({
671
679
  const addr = this.parser(string);
672
680
  new this(addr.parts, addr.zoneId);
673
681
  return true;
674
- } catch (e) {
682
+ } catch {
675
683
  return false;
676
684
  }
677
685
  };
@@ -682,7 +690,7 @@ var require_ipaddr = __commonJS({
682
690
  try {
683
691
  this.parseCIDR(string);
684
692
  return true;
685
- } catch (e) {
693
+ } catch {
686
694
  return false;
687
695
  }
688
696
  };
@@ -700,12 +708,12 @@ var require_ipaddr = __commonJS({
700
708
  }
701
709
  return new this(octets);
702
710
  } catch (e) {
703
- throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${e})`);
711
+ throw new Error("ipaddr: the address does not have IPv6 CIDR format", { cause: e });
704
712
  }
705
713
  };
706
714
  ipaddr2.IPv6.parse = function(string) {
707
715
  const addr = this.parser(string);
708
- if (addr.parts === null) {
716
+ if (addr === null) {
709
717
  throw new Error("ipaddr: string is not formatted like an IPv6 Address");
710
718
  }
711
719
  return new this(addr.parts, addr.zoneId);
@@ -741,7 +749,7 @@ var require_ipaddr = __commonJS({
741
749
  addr = addr.slice(0, -1);
742
750
  }
743
751
  addr = expandIPv6(addr + zoneId, 6);
744
- if (addr.parts) {
752
+ if (addr && addr.parts) {
745
753
  octets = [
746
754
  parseInt(match[2]),
747
755
  parseInt(match[3]),
@@ -766,7 +774,7 @@ var require_ipaddr = __commonJS({
766
774
  };
767
775
  ipaddr2.IPv6.subnetMaskFromPrefixLength = function(prefix) {
768
776
  prefix = parseInt(prefix);
769
- if (prefix < 0 || prefix > 128) {
777
+ if (Number.isNaN(prefix) || prefix < 0 || prefix > 128) {
770
778
  throw new Error("ipaddr: invalid IPv6 prefix length");
771
779
  }
772
780
  const octets = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
@@ -809,11 +817,11 @@ var require_ipaddr = __commonJS({
809
817
  ipaddr2.parseCIDR = function(string) {
810
818
  try {
811
819
  return ipaddr2.IPv6.parseCIDR(string);
812
- } catch (e) {
820
+ } catch {
813
821
  try {
814
822
  return ipaddr2.IPv4.parseCIDR(string);
815
- } catch (e2) {
816
- throw new Error("ipaddr: the address has neither IPv6 nor IPv4 CIDR format");
823
+ } catch (e) {
824
+ throw new Error("ipaddr: the address has neither IPv6 nor IPv4 CIDR format", { cause: e });
817
825
  }
818
826
  }
819
827
  };
@@ -3929,7 +3937,7 @@ async function configurationFlowImpacts(context, controllerId, previous, current
3929
3937
  impacts.push({ channelId: channel.id, message: "An input used by this channel as a guard or feedback changed." });
3930
3938
  }
3931
3939
  }
3932
- const nodes = await context.dataSource.getRepository(import_plugins_backend_sdk.ResourceFlowNode).createQueryBuilder("node").select(["node.id", "node.resourceId", "node.type", "node.data"]).where("node.type LIKE :type", { type: "plugin.wago.%" }).andWhere("node.data ->> 'controllerId' = :controllerId", { controllerId }).getMany();
3940
+ const nodes = await context.dataSource.getRepository(import_plugins_backend_sdk.ResourceFlowNode).createQueryBuilder("node").select(["node.id", "node.resourceId", "node.flowId", "node.type", "node.data"]).leftJoin("node.flow", "flow").addSelect(["flow.id", "flow.name"]).where("node.type LIKE :type", { type: "plugin.wago.%" }).andWhere("node.data ->> 'controllerId' = :controllerId", { controllerId }).getMany();
3933
3941
  for (const node of nodes) {
3934
3942
  const channelId2 = node.data?.channelId;
3935
3943
  if (String(node.type) !== "plugin.wago.command" || typeof channelId2 !== "string" || !channelId2) continue;
@@ -3941,7 +3949,13 @@ async function configurationFlowImpacts(context, controllerId, previous, current
3941
3949
  }
3942
3950
  return impacts.map((impact) => ({
3943
3951
  ...impact,
3944
- references: nodes.filter((node) => node.data?.channelId === impact.channelId).map((node) => ({ resourceId: node.resourceId, nodeId: node.id, nodeType: node.type }))
3952
+ references: nodes.filter((node) => node.data?.channelId === impact.channelId).map((node) => ({
3953
+ resourceId: node.resourceId ?? null,
3954
+ flowId: node.flowId ?? null,
3955
+ flowName: node.flowId != null ? node.flow?.name ?? null : null,
3956
+ nodeId: node.id,
3957
+ nodeType: node.type
3958
+ }))
3945
3959
  }));
3946
3960
  }
3947
3961
 
@@ -4288,9 +4302,21 @@ var WagoCommandHandler = class {
4288
4302
  }
4289
4303
  };
4290
4304
  }
4291
- async references(controllerId, channelId2, resourceId) {
4292
- const nodes = await this.dependencies.context.dataSource.getRepository(import_plugins_backend_sdk5.ResourceFlowNode).createQueryBuilder("node").select(["node.id", "node.resourceId"]).where("node.type = :type", { type: "plugin.wago.command" }).andWhere("node.resourceId <> :resourceId", { resourceId }).andWhere("node.data ->> 'controllerId' = :controllerId", { controllerId }).andWhere("node.data ->> 'channelId' = :channelId", { channelId: channelId2 }).getMany();
4293
- return nodes.map((node) => `resource ${node.resourceId} / node ${node.id}`);
4305
+ /**
4306
+ * Lists command nodes of other owners that control the same channel. A resource flow is owned by its
4307
+ * resource, a global flow by itself. NULL owner columns must be matched explicitly: `<>` skips them.
4308
+ */
4309
+ async references(controllerId, channelId2, resourceId, flowId = null) {
4310
+ const query = this.dependencies.context.dataSource.getRepository(import_plugins_backend_sdk5.ResourceFlowNode).createQueryBuilder("node").select(["node.id", "node.resourceId", "node.flowId"]).leftJoin("node.flow", "flow").addSelect(["flow.id", "flow.name"]).where("node.type = :type", { type: "plugin.wago.command" }).andWhere("node.data ->> 'controllerId' = :controllerId", { controllerId }).andWhere("node.data ->> 'channelId' = :channelId", { channelId: channelId2 });
4311
+ if (flowId !== null) {
4312
+ query.andWhere("(node.flowId IS NULL OR node.flowId <> :flowId)", { flowId });
4313
+ } else if (resourceId !== null) {
4314
+ query.andWhere("(node.resourceId IS NULL OR node.resourceId <> :resourceId)", { resourceId });
4315
+ }
4316
+ const nodes = await query.getMany();
4317
+ return nodes.map(
4318
+ (node) => node.flowId !== null && node.flowId !== void 0 ? `global flow ${node.flow?.name ? JSON.stringify(node.flow.name) : node.flowId} / node ${node.id}` : `resource ${node.resourceId} / node ${node.id}`
4319
+ );
4294
4320
  }
4295
4321
  destroy() {
4296
4322
  for (const [id, pending] of this.pending) {
@@ -4423,7 +4449,7 @@ var WagoCommandHandler = class {
4423
4449
  ];
4424
4450
  return [];
4425
4451
  }
4426
- async schema(config, resourceId, previewOnly = false) {
4452
+ async schema(config, resourceId, previewOnly = false, flowId = null) {
4427
4453
  const controllerId = positiveInteger2(config.controllerId);
4428
4454
  const controllers = previewOnly && !controllerId ? [] : await this.dependencies.controllers().find({
4429
4455
  where: { trustState: "claimed", ...previewOnly ? { id: controllerId } : {} },
@@ -4448,7 +4474,7 @@ var WagoCommandHandler = class {
4448
4474
  )
4449
4475
  };
4450
4476
  const channel = outputChannels.find((item) => item.id === channelId2);
4451
- const references = channelId2 && controllerId ? await this.references(controllerId, channelId2, resourceId) : [];
4477
+ const references = channelId2 && controllerId ? await this.references(controllerId, channelId2, resourceId, flowId) : [];
4452
4478
  const properties = {
4453
4479
  controllerId: {
4454
4480
  type: "number",
@@ -4471,7 +4497,7 @@ var WagoCommandHandler = class {
4471
4497
  title: typeof names[item.id] === "string" ? names[item.id] : `${item.id} (${item.profile})`
4472
4498
  })),
4473
4499
  refreshesSchema: true,
4474
- description: references.length ? `Also controlled by resource flow node${references.length === 1 ? "" : "s"}: ${references.join(", ")}. Reuse is allowed.` : outputChannels.length ? void 0 : "This applied configuration has no output channels. Add an output and publish it first."
4500
+ description: references.length ? `Also controlled by flow node${references.length === 1 ? "" : "s"}: ${references.join(", ")}. Reuse is allowed.` : outputChannels.length ? void 0 : "This applied configuration has no output channels. Add an output and publish it first."
4475
4501
  };
4476
4502
  }
4477
4503
  if (channel) {
@@ -4857,8 +4883,8 @@ var WagoRegistry = class extends WagoServiceState {
4857
4883
  async validateCommandConfig(config, validationContext = /* @__PURE__ */ new Map()) {
4858
4884
  return this.commands.validate(config, validationContext);
4859
4885
  }
4860
- async commandSchema(config, resourceId, previewOnly = false) {
4861
- return this.commands.schema(config, resourceId, previewOnly);
4886
+ async commandSchema(config, resourceId, previewOnly = false, flowId = null) {
4887
+ return this.commands.schema(config, resourceId, previewOnly, flowId);
4862
4888
  }
4863
4889
  onModuleDestroy() {
4864
4890
  this.destroyed = true;
@@ -7087,15 +7113,33 @@ wago_probe_privileges`;
7087
7113
  // backend/runtime/supervisor.ts
7088
7114
  function wagoRuntimeSupervisorLaunchShell() {
7089
7115
  return `${wagoShellStat()}
7116
+ # A live supervisor publishes ready into every supervisor-start.* that lacks it.
7117
+ # Removing a request in place races that: rm unlinks ready, the supervisor
7118
+ # writes it again, and rmdir fails with "Directory not empty". Move the request
7119
+ # out of that name first. Writers address it by its old path, so they now fail
7120
+ # instead of refilling the directory that is being removed. The destination is
7121
+ # reserved before the request exists: a same-directory rename and removal need
7122
+ # no new inode, so a full configuration filesystem cannot strand the request.
7123
+ retire_runtime_supervisor_request() {
7124
+ mv "$supervisor_launch" "$supervisor_retired/request" || return 1
7125
+ rm -rf "$supervisor_retired"
7126
+ }
7090
7127
  launch_runtime_supervisor() {
7091
7128
  supervisor_failure_stage=prerequisites
7092
7129
  command -v nohup >/dev/null && command -v sleep >/dev/null || return 1
7093
7130
  test -f "$hook" && test ! -L "$hook" &&
7094
7131
  test "$(stat -c '%u:%g:%a:%h' "$hook")" = 0:0:700:1 || return 1
7095
- supervisor_launch=$(mktemp -d "$config/supervisor-start.XXXXXX") || return 1
7132
+ supervisor_retired=$(mktemp -d "$config/supervisor-retired.XXXXXX") || return 1
7133
+ if ! supervisor_launch=$(mktemp -d "$config/supervisor-start.XXXXXX"); then
7134
+ rm -rf "$supervisor_retired"
7135
+ return 1
7136
+ fi
7096
7137
  # Caller rollback must never run without its transaction lock. Retain its
7097
7138
  # traps privately and restore them only after reacquiring that same lock.
7098
- trap > "$supervisor_launch/traps" || return 1
7139
+ if ! trap > "$supervisor_launch/traps"; then
7140
+ retire_runtime_supervisor_request
7141
+ return 1
7142
+ fi
7099
7143
  trap - EXIT
7100
7144
  supervisor_interrupted=0
7101
7145
  # Defer a catchable interruption until rollback can again own install.lock.
@@ -7132,7 +7176,7 @@ launch_runtime_supervisor() {
7132
7176
  supervisor_wait_remaining=300
7133
7177
  if ! { test -f "$config/install.lock" && test ! -L "$config/install.lock" &&
7134
7178
  test "$(stat -c '%u:%g:%a:%h' "$config/install.lock")" = 0:0:600:1; }; then
7135
- rm -rf "$supervisor_launch"
7179
+ retire_runtime_supervisor_request
7136
7180
  trap - EXIT HUP INT TERM
7137
7181
  echo 'Runtime supervisor handoff lock unverified; recovery required' >&2
7138
7182
  exit 75
@@ -7140,7 +7184,7 @@ launch_runtime_supervisor() {
7140
7184
  exec 9<>"$config/install.lock"
7141
7185
  until flock -n 9; do
7142
7186
  if test "$supervisor_wait_remaining" -le 0 || ! sleep 2; then
7143
- rm -rf "$supervisor_launch"
7187
+ retire_runtime_supervisor_request
7144
7188
  # Leave recovery ownership intact. Neither the caller nor its outer boot
7145
7189
  # wrapper may roll back a different transaction while this lock is held.
7146
7190
  trap - EXIT HUP INT TERM
@@ -7168,7 +7212,7 @@ launch_runtime_supervisor() {
7168
7212
  (exec 8<>"$config/supervisor.lock"; ! flock -n 8); then supervisor_live=1; fi ;;
7169
7213
  esac
7170
7214
  fi
7171
- rm -rf "$supervisor_launch" || return 1
7215
+ retire_runtime_supervisor_request || return 1
7172
7216
  test "$supervisor_live" = 1
7173
7217
  }
7174
7218
  launch_runtime_supervisor || fail "Runtime supervisor launch unverified: $supervisor_failure_stage"`;
@@ -10130,7 +10174,7 @@ async function processOutput(command, args, input, signal, environment = {}, fil
10130
10174
  if (errorBytes > 16384) stop();
10131
10175
  else errors.push(chunk);
10132
10176
  });
10133
- child.stdin.on("error", () => stop());
10177
+ child.stdin.on("error", () => void 0);
10134
10178
  let stream;
10135
10179
  child.stdin.write(input, () => {
10136
10180
  if (file && !failed) {
@@ -15039,26 +15083,35 @@ function configurationSummary(draft, latest, applied, runtime, revisionMismatch)
15039
15083
  function own(values, key) {
15040
15084
  return Object.prototype.hasOwnProperty.call(values, key) ? values[key] : void 0;
15041
15085
  }
15086
+ function referenceOwner(node) {
15087
+ return node.flowId != null ? `flow ${node.flowId}` : `resource ${node.resourceId}`;
15088
+ }
15042
15089
  function diagnosticReferences(nodes, channelIds, revision2, capabilities) {
15043
15090
  return nodes.map((node) => {
15044
15091
  const channelId2 = typeof node.data.channelId === "string" ? node.data.channelId : "";
15045
15092
  const control = node.type === "plugin.wago.command";
15046
- const conflictResourceIds = control ? [
15047
- ...new Set(
15048
- nodes.filter(
15049
- (other) => other.type === "plugin.wago.command" && other.resourceId !== node.resourceId && other.data.channelId === channelId2
15050
- ).map((other) => other.resourceId)
15051
- )
15052
- ] : [];
15093
+ const conflicting = control ? nodes.filter(
15094
+ (other) => other.type === "plugin.wago.command" && referenceOwner(other) !== referenceOwner(node) && other.data.channelId === channelId2
15095
+ ) : [];
15096
+ const flowId = node.flowId ?? null;
15097
+ const conflictResourceIds = [
15098
+ ...new Set(conflicting.map((other) => other.resourceId).filter((id) => id != null))
15099
+ ];
15100
+ const conflictFlowIds = [
15101
+ ...new Set(conflicting.map((other) => other.flowId).filter((id) => id != null))
15102
+ ];
15053
15103
  return {
15054
15104
  nodeId: node.id,
15055
- resourceId: node.resourceId,
15105
+ resourceId: node.resourceId ?? null,
15106
+ flowId,
15107
+ flowName: flowId !== null ? node.flow?.name ?? null : null,
15056
15108
  channelId: channelId2,
15057
15109
  control,
15058
- href: `/resources/${node.resourceId}/flows?node=${encodeURIComponent(node.id)}`,
15110
+ href: flowId !== null ? `/devices/flows/${flowId}?node=${encodeURIComponent(node.id)}` : `/resources/${node.resourceId}/flows?node=${encodeURIComponent(node.id)}`,
15059
15111
  invalid: !channelIds.includes(channelId2) || control && (node.data.expectedConfigurationRevision !== revision2 || capabilities && (!own(capabilities, channelId2)?.includes("output") || node.data.action === "pulse" && !own(capabilities, channelId2)?.includes("pulse"))),
15060
- conflict: conflictResourceIds.length > 0,
15061
- conflictResourceIds
15112
+ conflict: conflicting.length > 0,
15113
+ conflictResourceIds,
15114
+ conflictFlowIds
15062
15115
  };
15063
15116
  });
15064
15117
  }
@@ -15086,7 +15139,7 @@ var WagoDiagnosticsService = class {
15086
15139
  this.context.getRepository(WagoConfigurationDraft).findOneBy({ controllerId }),
15087
15140
  this.context.getRepository(WagoConfigurationRevision).findOne({ where: { controllerId }, order: { revision: "DESC" } }),
15088
15141
  this.context.getRepository(WagoConfigurationRevision).findOne({ where: { controllerId, state: "applied" }, order: { revision: "DESC" } }),
15089
- this.context.dataSource.getRepository(import_plugins_backend_sdk18.ResourceFlowNode).createQueryBuilder("node").where("node.type LIKE :type", { type: "plugin.wago.%" }).andWhere("node.data ->> 'controllerId' = :controllerId", { controllerId }).take(1001).getMany()
15142
+ this.context.dataSource.getRepository(import_plugins_backend_sdk18.ResourceFlowNode).createQueryBuilder("node").leftJoin("node.flow", "flow").addSelect(["flow.id", "flow.name"]).where("node.type LIKE :type", { type: "plugin.wago.%" }).andWhere("node.data ->> 'controllerId' = :controllerId", { controllerId }).take(1001).getMany()
15090
15143
  ]);
15091
15144
  const runtime = this.wago.diagnostics.read(controllerId);
15092
15145
  const runtimeUpdate = this.wago.isRuntimeUpdateRequired?.(controllerId) ?? false;
@@ -15196,7 +15249,7 @@ var WagoDiagnosticsService = class {
15196
15249
  this.context.getRepository(WagoConfigurationRevision).createQueryBuilder("revision").select(["revision.controllerId", "revision.revision", "revision.snapshot"]).where("revision.controllerId IN (:...controllerIds)", { controllerIds: selectedControllerIds }).andWhere("revision.state = :state", { state: "applied" }).andWhere(
15197
15250
  "revision.revision = (SELECT MAX(applied.revision) FROM plugin_wago_configuration_revisions applied WHERE applied.controller_id = revision.controller_id AND applied.state = :state)"
15198
15251
  ).orderBy("revision.controllerId", "ASC").addOrderBy("revision.revision", "DESC").getMany(),
15199
- localChannelIds.length ? this.context.dataSource.getRepository(import_plugins_backend_sdk18.ResourceFlowNode).createQueryBuilder("node").where("node.data ->> 'controllerId' IN (:...controllerIds)", { controllerIds: controllerIdsForQuery }).andWhere("node.data ->> 'channelId' IN (:...channelIds)", { channelIds: localChannelIds }).andWhere("node.type = :type", { type: "plugin.wago.command" }).take(1001).getMany() : Promise.resolve([])
15252
+ localChannelIds.length ? this.context.dataSource.getRepository(import_plugins_backend_sdk18.ResourceFlowNode).createQueryBuilder("node").leftJoin("node.flow", "flow").addSelect(["flow.id", "flow.name"]).where("node.data ->> 'controllerId' IN (:...controllerIds)", { controllerIds: controllerIdsForQuery }).andWhere("node.data ->> 'channelId' IN (:...channelIds)", { channelIds: localChannelIds }).andWhere("node.type = :type", { type: "plugin.wago.command" }).take(1001).getMany() : Promise.resolve([])
15200
15253
  ]);
15201
15254
  const controllersById = new Map(controllers.map((controller) => [controller.id, controller]));
15202
15255
  const appliedByControllerId = new Map(appliedRevisions.map((revision2) => [revision2.controllerId, revision2]));
@@ -15210,9 +15263,17 @@ var WagoDiagnosticsService = class {
15210
15263
  matchingNodes.push(node);
15211
15264
  conflictNodesByControllerId.set(controllerId, matchingNodes);
15212
15265
  }
15213
- const conflictResourceIds = [...new Set([...conflictNodesByControllerId.values()].flat().map((n) => n.resourceId))];
15266
+ const conflictResourceIds = [
15267
+ ...new Set(
15268
+ [...conflictNodesByControllerId.values()].flat().map((n) => n.resourceId).filter((id) => id != null)
15269
+ )
15270
+ ];
15214
15271
  const conflictResources = conflictResourceIds.length ? await this.context.dataSource.getRepository(import_plugins_backend_sdk18.Resource).createQueryBuilder("resource").select(["resource.id", "resource.name"]).where("resource.id IN (:...ids)", { ids: conflictResourceIds }).getMany() : [];
15215
15272
  const resourceNames = new Map(conflictResources.map((resource) => [resource.id, resource.name]));
15273
+ const flowNames = /* @__PURE__ */ new Map();
15274
+ for (const node of conflictNodes) {
15275
+ if (node.flowId != null && node.flow?.name) flowNames.set(node.flowId, node.flow.name);
15276
+ }
15216
15277
  const controllersResult = selectedControllerIds.map((controllerId) => {
15217
15278
  const controller = controllersById.get(controllerId);
15218
15279
  if (!controller)
@@ -15234,12 +15295,14 @@ var WagoDiagnosticsService = class {
15234
15295
  Object.fromEntries(
15235
15296
  appliedSnapshot?.logicalChannels.map((channel) => [channel.id, channel.capabilities]) ?? []
15236
15297
  )
15237
- ).filter((reference) => reference.resourceId === resourceId).map((reference) => ({
15298
+ ).filter((reference) => reference.flowId === null && reference.resourceId === resourceId).map((reference) => ({
15238
15299
  ...reference,
15239
15300
  conflictResources: reference.conflictResourceIds.map((id) => ({
15240
15301
  id,
15241
15302
  name: resourceNames.get(id) ?? `Resource ${id}`
15242
- }))
15303
+ })),
15304
+ // The frontend names a flow without a loaded name by its id, in the user's language.
15305
+ conflictFlows: reference.conflictFlowIds.map((id) => ({ id, name: flowNames.get(id) ?? null }))
15243
15306
  }));
15244
15307
  return {
15245
15308
  controllerId,
@@ -15307,7 +15370,13 @@ function createWagoCommandNode(service) {
15307
15370
  inputs: ["input"],
15308
15371
  outputs: ["output", "failure"],
15309
15372
  isOutput: true,
15310
- resolveConfigSchema: (config, schemaContext) => service().commandSchema(config, schemaContext.resourceId, schemaContext.purpose === "preview"),
15373
+ flowScopes: ["resource", "global"],
15374
+ resolveConfigSchema: (config, schemaContext) => service().commandSchema(
15375
+ config,
15376
+ schemaContext.flowScope === "global" ? null : schemaContext.resourceId,
15377
+ schemaContext.purpose === "preview",
15378
+ schemaContext.flowScope === "global" ? schemaContext.flowId : null
15379
+ ),
15311
15380
  validateConfig: (config, validationContext) => service().validateCommandConfig(config, validationContext),
15312
15381
  getFailureBehavior: (config) => service().commandFailureBehavior(config),
15313
15382
  getFailureKind: (error) => service().commandFailureKind(error),
@@ -15345,6 +15414,7 @@ function createWagoStateNodes(service) {
15345
15414
  description: "Start a flow when a channel reports state, a measurement, or a fault. Data is available in wago.",
15346
15415
  configSchema: WAGO_FLOW_PREVIEW_SCHEMA,
15347
15416
  isInput: true,
15417
+ flowScopes: ["resource", "global"],
15348
15418
  inputs: [],
15349
15419
  outputs: ["output"],
15350
15420
  resolveConfigSchema: (config, context) => service().resolveConfigSchema(config, "event", void 0, context.purpose === "preview"),
@@ -15355,6 +15425,7 @@ function createWagoStateNodes(service) {
15355
15425
  label: "WAGO read state",
15356
15426
  description: "Read the latest channel state or measurement into wago. Unavailable data uses the unavailable output.",
15357
15427
  configSchema: WAGO_FLOW_PREVIEW_SCHEMA,
15428
+ flowScopes: ["resource", "global"],
15358
15429
  inputs: ["input"],
15359
15430
  outputs: ["output", "unavailable"],
15360
15431
  resolveConfigSchema: (config, context) => service().resolveConfigSchema(config, "read", void 0, context.purpose === "preview"),
@@ -15370,6 +15441,7 @@ function createWagoStateNodes(service) {
15370
15441
  label: "WAGO wait for state",
15371
15442
  description: "Wait for an available channel value to match, then continue with the value in wago.",
15372
15443
  configSchema: WAGO_FLOW_PREVIEW_SCHEMA,
15444
+ flowScopes: ["resource", "global"],
15373
15445
  inputs: ["input"],
15374
15446
  outputs: ["output", "timeout"],
15375
15447
  resolveConfigSchema: (config, context) => service().resolveConfigSchema(config, "wait", void 0, context.purpose === "preview"),
@@ -1379,7 +1379,8 @@ var editor_de_default = {
1379
1379
  };
1380
1380
  var revisions_en_default = {
1381
1381
  impacts: "Potential flow impacts",
1382
- impactDescription: "Publishing can change or break these channel references. Check the listed resource flows before forcing publication.",
1382
+ impactDescription: "Publishing can change or break these channel references. Check the listed resource flows and global flows before forcing publication.",
1383
+ globalReference: "Global flow \"{{flow}}\", node {{node}} ({{type}})",
1383
1384
  reference: "Resource {{resource}}, node {{node}} ({{type}})",
1384
1385
  noReferences: "No saved WAGO flow nodes reference this channel.",
1385
1386
  accept: "I checked the affected channel references and accept these changes",
@@ -1423,7 +1424,8 @@ var revisions_en_default = {
1423
1424
  };
1424
1425
  var revisions_de_default = {
1425
1426
  impacts: "Mögliche Auswirkungen auf Abläufe",
1426
- impactDescription: "Die Veröffentlichung kann diese Kanalreferenzen verändern oder ungültig machen. Prüfe die aufgeführten Ressourcenabläufe vor einer erzwungenen Veröffentlichung.",
1427
+ impactDescription: "Die Veröffentlichung kann diese Kanalreferenzen verändern oder ungültig machen. Prüfe die aufgeführten Ressourcenabläufe und globalen Abläufe vor einer erzwungenen Veröffentlichung.",
1428
+ globalReference: "Globaler Ablauf „{{flow}}“, Knoten {{node}} ({{type}})",
1427
1429
  reference: "Ressource {{resource}}, Knoten {{node}} ({{type}})",
1428
1430
  noReferences: "Keine gespeicherten WAGO-Ablaufknoten verweisen auf diesen Kanal.",
1429
1431
  accept: "Ich habe die betroffenen Kanalreferenzen geprüft und akzeptiere diese Änderungen",
@@ -1534,6 +1536,8 @@ var diagnostics_en_default = {
1534
1536
  references: "Flow references",
1535
1537
  referenceWarning: "Warnings do not block resource usage. Required flow nodes determine gating.",
1536
1538
  noReferences: "No references found.",
1539
+ globalFlow: "{{flow}} (global flow)",
1540
+ globalReference: "Global flow \"{{flow}}\", node {{node}}",
1537
1541
  reference: "Resource {{resource}}, node {{node}}",
1538
1542
  control: "control",
1539
1543
  readEvent: "read/event",
@@ -1610,6 +1614,8 @@ var diagnostics_de_default = {
1610
1614
  references: "Ablaufreferenzen",
1611
1615
  referenceWarning: "Warnungen blockieren die Ressourcennutzung nicht. Erforderliche Ablaufknoten bestimmen die Freigabe.",
1612
1616
  noReferences: "Keine Referenzen gefunden.",
1617
+ globalFlow: "{{flow}} (globaler Ablauf)",
1618
+ globalReference: "Globaler Ablauf „{{flow}}“, Knoten {{node}}",
1613
1619
  reference: "Ressource {{resource}}, Knoten {{node}}",
1614
1620
  control: "Steuerung",
1615
1621
  readEvent: "Lesen/Ereignis",
@@ -6612,7 +6618,7 @@ function digitalTerminalLabel(channel) {
6612
6618
  while ((lastColon = string.indexOf(":", lastColon + 1)) >= 0) colonCount++;
6613
6619
  if (string.substr(0, 2) === "::") colonCount--;
6614
6620
  if (string.substr(-2, 2) === "::") colonCount--;
6615
- if (colonCount > parts) return null;
6621
+ if (colonCount >= parts) return null;
6616
6622
  replacementCount = parts - colonCount;
6617
6623
  replacement = ":";
6618
6624
  while (replacementCount--) replacement += "0:";
@@ -6622,7 +6628,7 @@ function digitalTerminalLabel(channel) {
6622
6628
  parts = (function() {
6623
6629
  const ref = string.split(":");
6624
6630
  const results = [];
6625
- for (let i = 0; i < ref.length; i++) results.push(parseInt(ref[i], 16));
6631
+ for (let i = 0; i < ref.length; i++) results.push(ref[i].length > 4 ? NaN : parseInt(ref[i], 16));
6626
6632
  return results;
6627
6633
  })();
6628
6634
  return {
@@ -6854,7 +6860,7 @@ function digitalTerminalLabel(channel) {
6854
6860
  }
6855
6861
  return new this(octets);
6856
6862
  } catch (e) {
6857
- throw new Error("ipaddr: the address does not have IPv4 CIDR format");
6863
+ throw new Error("ipaddr: the address does not have IPv4 CIDR format", { cause: e });
6858
6864
  }
6859
6865
  };
6860
6866
  ipaddr.IPv4.isIPv4 = function(string) {
@@ -6864,7 +6870,7 @@ function digitalTerminalLabel(channel) {
6864
6870
  try {
6865
6871
  new this(this.parser(string));
6866
6872
  return true;
6867
- } catch (e) {
6873
+ } catch {
6868
6874
  return false;
6869
6875
  }
6870
6876
  };
@@ -6872,7 +6878,7 @@ function digitalTerminalLabel(channel) {
6872
6878
  try {
6873
6879
  this.parseCIDR(string);
6874
6880
  return true;
6875
- } catch (e) {
6881
+ } catch {
6876
6882
  return false;
6877
6883
  }
6878
6884
  };
@@ -6899,7 +6905,7 @@ function digitalTerminalLabel(channel) {
6899
6905
  }
6900
6906
  return new this(octets);
6901
6907
  } catch (e) {
6902
- throw new Error("ipaddr: the address does not have IPv4 CIDR format");
6908
+ throw new Error("ipaddr: the address does not have IPv4 CIDR format", { cause: e });
6903
6909
  }
6904
6910
  };
6905
6911
  ipaddr.IPv4.parse = function(string) {
@@ -6967,7 +6973,7 @@ function digitalTerminalLabel(channel) {
6967
6973
  };
6968
6974
  ipaddr.IPv4.subnetMaskFromPrefixLength = function(prefix) {
6969
6975
  prefix = parseInt(prefix);
6970
- if (prefix < 0 || prefix > 32) throw new Error("ipaddr: invalid IPv4 prefix length");
6976
+ if (Number.isNaN(prefix) || prefix < 0 || prefix > 32) throw new Error("ipaddr: invalid IPv4 prefix length");
6971
6977
  const octets = [
6972
6978
  0,
6973
6979
  0,
@@ -7337,16 +7343,24 @@ function digitalTerminalLabel(channel) {
7337
7343
  };
7338
7344
  IPv6.prototype.toRFC5952String = function() {
7339
7345
  const regex = /((^|:)(0(:|$)){2,})/g;
7340
- const string = this.toNormalizedString();
7346
+ let suffix = "";
7347
+ if (this.zoneId) suffix = `%${this.zoneId}`;
7348
+ const normalized = this.toNormalizedString();
7349
+ const string = normalized.slice(0, normalized.length - suffix.length);
7341
7350
  let bestMatchIndex = 0;
7342
7351
  let bestMatchLength = -1;
7352
+ let bestMatchGroups = -1;
7343
7353
  let match;
7344
- while (match = regex.exec(string)) if (match[0].length > bestMatchLength) {
7345
- bestMatchIndex = match.index;
7346
- bestMatchLength = match[0].length;
7354
+ while (match = regex.exec(string)) {
7355
+ const groups = (match[0].match(/0/g) || []).length;
7356
+ if (groups > bestMatchGroups) {
7357
+ bestMatchGroups = groups;
7358
+ bestMatchIndex = match.index;
7359
+ bestMatchLength = match[0].length;
7360
+ }
7347
7361
  }
7348
- if (bestMatchLength < 0) return string;
7349
- return `${string.substring(0, bestMatchIndex)}::${string.substring(bestMatchIndex + bestMatchLength)}`;
7362
+ if (bestMatchLength < 0) return string + suffix;
7363
+ return `${string.substring(0, bestMatchIndex)}::${string.substring(bestMatchIndex + bestMatchLength)}${suffix}`;
7350
7364
  };
7351
7365
  IPv6.prototype.toString = function() {
7352
7366
  return this.toRFC5952String();
@@ -7366,7 +7380,7 @@ function digitalTerminalLabel(channel) {
7366
7380
  }
7367
7381
  return new this(octets);
7368
7382
  } catch (e) {
7369
- throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${e})`);
7383
+ throw new Error("ipaddr: the address does not have IPv6 CIDR format", { cause: e });
7370
7384
  }
7371
7385
  };
7372
7386
  ipaddr.IPv6.isIPv6 = function(string) {
@@ -7378,7 +7392,7 @@ function digitalTerminalLabel(channel) {
7378
7392
  const addr = this.parser(string);
7379
7393
  new this(addr.parts, addr.zoneId);
7380
7394
  return true;
7381
- } catch (e) {
7395
+ } catch {
7382
7396
  return false;
7383
7397
  }
7384
7398
  };
@@ -7387,7 +7401,7 @@ function digitalTerminalLabel(channel) {
7387
7401
  try {
7388
7402
  this.parseCIDR(string);
7389
7403
  return true;
7390
- } catch (e) {
7404
+ } catch {
7391
7405
  return false;
7392
7406
  }
7393
7407
  };
@@ -7405,12 +7419,12 @@ function digitalTerminalLabel(channel) {
7405
7419
  }
7406
7420
  return new this(octets);
7407
7421
  } catch (e) {
7408
- throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${e})`);
7422
+ throw new Error("ipaddr: the address does not have IPv6 CIDR format", { cause: e });
7409
7423
  }
7410
7424
  };
7411
7425
  ipaddr.IPv6.parse = function(string) {
7412
7426
  const addr = this.parser(string);
7413
- if (addr.parts === null) throw new Error("ipaddr: string is not formatted like an IPv6 Address");
7427
+ if (addr === null) throw new Error("ipaddr: string is not formatted like an IPv6 Address");
7414
7428
  return new this(addr.parts, addr.zoneId);
7415
7429
  };
7416
7430
  ipaddr.IPv6.parseCIDR = function(string) {
@@ -7436,7 +7450,7 @@ function digitalTerminalLabel(channel) {
7436
7450
  addr = match[1];
7437
7451
  if (!match[1].endsWith("::")) addr = addr.slice(0, -1);
7438
7452
  addr = expandIPv6(addr + zoneId, 6);
7439
- if (addr.parts) {
7453
+ if (addr && addr.parts) {
7440
7454
  octets = [
7441
7455
  parseInt(match[2]),
7442
7456
  parseInt(match[3]),
@@ -7459,7 +7473,7 @@ function digitalTerminalLabel(channel) {
7459
7473
  };
7460
7474
  ipaddr.IPv6.subnetMaskFromPrefixLength = function(prefix) {
7461
7475
  prefix = parseInt(prefix);
7462
- if (prefix < 0 || prefix > 128) throw new Error("ipaddr: invalid IPv6 prefix length");
7476
+ if (Number.isNaN(prefix) || prefix < 0 || prefix > 128) throw new Error("ipaddr: invalid IPv6 prefix length");
7463
7477
  const octets = [
7464
7478
  0,
7465
7479
  0,
@@ -7507,11 +7521,11 @@ function digitalTerminalLabel(channel) {
7507
7521
  ipaddr.parseCIDR = function(string) {
7508
7522
  try {
7509
7523
  return ipaddr.IPv6.parseCIDR(string);
7510
- } catch (e) {
7524
+ } catch {
7511
7525
  try {
7512
7526
  return ipaddr.IPv4.parseCIDR(string);
7513
- } catch (e2) {
7514
- throw new Error("ipaddr: the address has neither IPv6 nor IPv4 CIDR format");
7527
+ } catch (e) {
7528
+ throw new Error("ipaddr: the address has neither IPv6 nor IPv4 CIDR format", { cause: e });
7515
7529
  }
7516
7530
  }
7517
7531
  };
@@ -11094,7 +11108,11 @@ function ImpactWarning({ impacts, names, acknowledged, onChange }) {
11094
11108
  names[impact.channelId] ?? impact.channelId,
11095
11109
  ": ",
11096
11110
  tBackendMessage(impact.message),
11097
- impact.references.length ? impact.references.map((reference) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: t("revisions.reference", {
11111
+ impact.references.length ? impact.references.map((reference) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: reference.flowId != null ? t("revisions.globalReference", {
11112
+ flow: reference.flowName ?? `#${reference.flowId}`,
11113
+ node: reference.nodeId,
11114
+ type: reference.nodeType
11115
+ }) : t("revisions.reference", {
11098
11116
  resource: reference.resourceId,
11099
11117
  node: reference.nodeId,
11100
11118
  type: reference.nodeType
@@ -11456,7 +11474,11 @@ function ResourceDiagnosticsContent({ resourceId }) {
11456
11474
  node.conflictResources.map((resource, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [index > 0 && ", ", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, {
11457
11475
  href: `/resources/${resource.id}`,
11458
11476
  children: resource.name
11459
- })] }, resource.id))
11477
+ })] }, resource.id)),
11478
+ node.conflictFlows.map((flow, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [(index > 0 || node.conflictResources.length > 0) && ", ", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, {
11479
+ href: `/devices/flows/${flow.id}`,
11480
+ children: t("diagnostics.globalFlow", { flow: flow.name ?? `#${flow.id}` })
11481
+ })] }, `flow-${flow.id}`))
11460
11482
  ] })
11461
11483
  ] }, node.nodeId))
11462
11484
  })
@@ -75,7 +75,7 @@ var exportSet = /* @__PURE__ */ new Set([
75
75
  ]);
76
76
  var moduleMap = { "./plugin": () => {
77
77
  dynamicLoadingCss(["style.css"], false, "./plugin");
78
- return __federation_import("./__federation_expose_Plugin-jiEVEykA.js").then((module) => Object.keys(module).every((item) => exportSet.has(item)) ? () => module.default : () => module);
78
+ return __federation_import("./__federation_expose_Plugin-DgZ_VWDg.js").then((module) => Object.keys(module).every((item) => exportSet.has(item)) ? () => module.default : () => module);
79
79
  } };
80
80
  var seen = {};
81
81
  var dynamicLoadingCss = (cssFilePaths, dontAppendStylesToHead, exposeItemName) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@attraccess/plugin-wago",
3
- "version": "0.1.0-nightly.1112.1",
3
+ "version": "0.1.0-nightly.1140.3",
4
4
  "description": "Attraccess integration for WAGO CC100 controllers. Operational control only: not a safety function, and not yet qualified for physical use.",
5
5
  "keywords": [
6
6
  "attraccess-plugin",
@@ -44,6 +44,8 @@
44
44
  "sdk": {
45
45
  "backend": "^1.9.0",
46
46
  "frontend": "^1.9.0"
47
- }
48
- }
47
+ },
48
+ "publishedCommit": "80ee2abd88110158a732c5230194ea75ac6a0f0c"
49
+ },
50
+ "gitHead": "80ee2abd88110158a732c5230194ea75ac6a0f0c"
49
51
  }