pmcf 2.1.3 → 2.2.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": "pmcf",
3
- "version": "2.1.3",
3
+ "version": "2.2.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/dns-utils.mjs CHANGED
@@ -1,11 +1,29 @@
1
- import { asArray, asIterator } from "./utils.mjs";
1
+ import {
2
+ asIterator,
3
+ decodeIPv6,
4
+ encodeIPv6,
5
+ normalizeIPAddress
6
+ } from "./utils.mjs";
2
7
 
3
8
  export function dnsFullName(name) {
4
9
  return name.endsWith(".") ? name : name + ".";
5
10
  }
6
11
 
7
12
  export function DNSRecord(key, type, ...values) {
8
- const pad = type === "MX" ? " " : "";
13
+ let pad = "";
14
+
15
+ switch (type) {
16
+ case "MX":
17
+ pad = " ";
18
+ break;
19
+
20
+ case "A":
21
+ values[0] = normalizeIPAddress(values[0]);
22
+ break;
23
+ case "AAAA":
24
+ values[0] = decodeIPv6(encodeIPv6(values[0]));
25
+ break;
26
+ }
9
27
 
10
28
  values = values.map(v =>
11
29
  typeof v === "number" ? String(v).padStart(3) + pad : v
@@ -5,16 +5,16 @@ import {
5
5
  writeLines,
6
6
  isIPv6Address,
7
7
  normalizeIPAddress,
8
- isLinkLocal
8
+ isLinkLocal,
9
+ isLocalhost
9
10
  } from "../utils.mjs";
10
11
  import { DNSRecord, dnsFullName } from "../dns-utils.mjs";
11
12
  import { addType } from "../types.mjs";
13
+ import { ServiceTypeDefinition, serviceAddresses } from "../service.mjs";
12
14
  import {
13
- Service,
14
- ServiceTypeDefinition,
15
- serviceAddresses
16
- } from "../service.mjs";
17
- import { ExtraSourceService, ExtraSourceServiceTypeDefinition } from "../extra-source-service.mjs";
15
+ ExtraSourceService,
16
+ ExtraSourceServiceTypeDefinition
17
+ } from "../extra-source-service.mjs";
18
18
  import { subnets } from "../subnet.mjs";
19
19
 
20
20
  const DNSServiceTypeDefinition = {
@@ -262,15 +262,14 @@ async function generateZoneDefs(dns, location, packageData) {
262
262
  };
263
263
  configs.push(config);
264
264
 
265
+ zone.records.add(DNSRecord("location", "TXT", host.location.name));
266
+
265
267
  for (const address of host.rawAddresses) {
266
- zone.records.add(
267
- DNSRecord(
268
- "@",
269
- isIPv6Address(address) ? "AAAA" : "A",
270
- normalizeIPAddress(address)
271
- )
272
- );
273
- zone.records.add(DNSRecord("location", "TXT", host.location.name));
268
+ if (!isLocalhost(address)) {
269
+ zone.records.add(
270
+ DNSRecord("@", isIPv6Address(address) ? "AAAA" : "A", address)
271
+ );
272
+ }
274
273
  }
275
274
  }
276
275
  }
@@ -335,7 +334,7 @@ async function generateZoneDefs(dns, location, packageData) {
335
334
  DNSRecord(
336
335
  dnsFullName(domainName),
337
336
  isIPv6Address(address) ? "AAAA" : "A",
338
- normalizeIPAddress(address)
337
+ address
339
338
  )
340
339
  );
341
340
  }
package/src/utils.mjs CHANGED
@@ -96,7 +96,15 @@ export function isIPv6Address(address) {
96
96
  }
97
97
 
98
98
  export function isLinkLocal(address) {
99
- return address.startsWith("fe80");
99
+ switch (typeof address) {
100
+ case "string":
101
+ return address.startsWith("fe80");
102
+
103
+ case "bigint":
104
+ return ((address >> 112n) & 0xffffn) === 0xfe80n;
105
+ }
106
+
107
+ return false;
100
108
  }
101
109
 
102
110
  export function isLocalhost(address) {
@@ -136,6 +144,10 @@ const ipv6 = {
136
144
  };
137
145
 
138
146
  function _decode(definition, address, length = definition.length) {
147
+ if (typeof address === "string") {
148
+ return address;
149
+ }
150
+
139
151
  let result = "";
140
152
  let compressed = 0;
141
153
  let shift = definition.length;
@@ -58,7 +58,7 @@ export class DNSService extends ExtraSourceService {
58
58
  };
59
59
  };
60
60
  };
61
- factoryFor(value: any): typeof Service | typeof DNSService | typeof import("./ntp.mjs").NTPService | typeof import("./dhcp.mjs").DHCPService;
61
+ factoryFor(value: any): typeof import("../service.mjs").Service | typeof DNSService | typeof import("./ntp.mjs").NTPService | typeof import("./dhcp.mjs").DHCPService;
62
62
  properties: {
63
63
  ipAddresses: {
64
64
  type: string;
@@ -264,4 +264,3 @@ export class DNSService extends ExtraSourceService {
264
264
  }, void, unknown>;
265
265
  }
266
266
  import { ExtraSourceService } from "../extra-source-service.mjs";
267
- import { Service } from "../service.mjs";
@@ -27,7 +27,7 @@ export class Subnet extends Base {
27
27
  networks: Set<any>;
28
28
  get fullName(): string;
29
29
  matchesAddress(address: any): any;
30
- get isLinkLocal(): any;
30
+ get isLinkLocal(): boolean;
31
31
  get prefix(): string;
32
32
  get prefixLength(): number;
33
33
  get address(): string;
package/types/utils.d.mts CHANGED
@@ -8,7 +8,7 @@ export function asIterator(value: any): any;
8
8
  export function isIPv4Address(address: any): boolean;
9
9
  export function generateEU64(mac: any): void;
10
10
  export function isIPv6Address(address: any): boolean;
11
- export function isLinkLocal(address: any): any;
11
+ export function isLinkLocal(address: any): boolean;
12
12
  export function isLocalhost(address: any): boolean;
13
13
  export function normalizeIPAddress(address: any): any;
14
14
  export function _encode(definition: any, address: any): any;
@@ -28,7 +28,7 @@ export function normalizeCIDR(address: any): {
28
28
  prefixLength: any;
29
29
  cidr: string;
30
30
  };
31
- export function hasWellKnownSubnet(address: any): any;
31
+ export function hasWellKnownSubnet(address: any): boolean;
32
32
  export const IPV4_LOCALHOST: any;
33
33
  export const IPV6_LOCALHOST: any;
34
34
  export const IPV6_LINK_LOCAL_BROADCAST: any;