pmcf 2.2.0 → 2.3.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.2.0",
3
+ "version": "2.3.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/dns-utils.mjs CHANGED
@@ -31,7 +31,7 @@ export function DNSRecord(key, type, ...values) {
31
31
 
32
32
  return {
33
33
  key,
34
- toString: (maxKeyLength, ttl) =>
34
+ toString: (maxKeyLength = 0, ttl = "1W") =>
35
35
  `${key.padEnd(maxKeyLength, " ")} ${ttl} IN ${type.padEnd(
36
36
  5,
37
37
  " "
package/src/service.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Base } from "./base.mjs";
2
2
  import { addType } from "./types.mjs";
3
- import { asArray,isLocalhost } from "./utils.mjs";
3
+ import { asArray, isLocalhost } from "./utils.mjs";
4
4
  import { networkAddressProperties } from "./network-support.mjs";
5
5
  import {
6
6
  DNSRecord,
@@ -11,38 +11,43 @@ import {
11
11
  import { DHCPService, DNSService, NTPService } from "./module.mjs";
12
12
 
13
13
  const ServiceTypes = {
14
- ntp: { protocol: "udp", port: 123, tls: false },
15
- dns: { protocol: "udp", port: 53, tls: false },
16
- ldap: { protocol: "tcp", port: 389, tls: false },
17
- ldaps: { protocol: "tcp", port: 636, tls: true },
18
- http: { protocol: "tcp", port: 80, tls: false },
14
+ ntp: { endpoints: [{ protocol: "udp", port: 123, tls: false }] },
15
+ dns: { endpoints: [{ protocol: "udp", port: 53, tls: false }] },
16
+ ldap: { endpoints: [{ protocol: "tcp", port: 389, tls: false }] },
17
+ ldaps: { endpoints: [{ protocol: "tcp", port: 636, tls: true }] },
18
+ http: { endpoints: [{ protocol: "tcp", port: 80, tls: false }] },
19
19
  https: {
20
- protocol: "tcp",
21
- port: 443,
22
- tls: true,
20
+ endpoints: [{ protocol: "tcp", port: 443, tls: true }],
23
21
  dnsRecord: { type: "HTTPS", parameters: { alpn: "h2" } }
24
22
  },
25
23
  http3: {
26
24
  type: "https",
27
- protocol: "tcp",
28
- port: 443,
29
- tls: true,
25
+ endpoints: [{ protocol: "tcp", port: 443, tls: true }],
30
26
  dnsRecord: {
31
27
  type: "HTTPS",
32
28
  parameters: { "no-default-alpn": undefined, alpn: "h3" }
33
29
  }
34
30
  },
35
- rtsp: { protocol: "tcp", port: 554, tls: false },
36
- smtp: { protocol: "tcp", port: 25, tls: false, dnsRecord: { type: "MX" } },
37
- ssh: { protocol: "tcp", port: 22, tls: false },
38
- imap: { protocol: "tcp", port: 143, tls: false },
39
- imaps: { protocol: "tcp", port: 993, tls: true },
40
- dhcp: { tls: false },
41
- smb: { protocol: "tcp", port: 445, tls: false },
31
+ rtsp: { endpoints: [{ protocol: "tcp", port: 554, tls: false }] },
32
+ smtp: {
33
+ endpoints: [{ protocol: "tcp", port: 25, tls: false }],
34
+ dnsRecord: { type: "MX" }
35
+ },
36
+ ssh: { endpoints: [{ protocol: "tcp", port: 22, tls: false }] },
37
+ imap: { endpoints: [{ protocol: "tcp", port: 143, tls: false }] },
38
+ imaps: { endpoints: [{ protocol: "tcp", port: 993, tls: true }] },
39
+ dhcp: { endpoints: [{ port: 547, tls: false }] },
40
+ "dhcpv6-client": {
41
+ endpoints: [
42
+ { protocol: "tcp", port: 546, tls: false },
43
+ { protocol: "udp", port: 546, tls: false }
44
+ ]
45
+ },
46
+ "dhcpv6-server": { endpoints: [{ port: 547, tls: false }] },
47
+ smb: { endpoints: [{ protocol: "tcp", port: 445, tls: false }] },
42
48
  timemachine: {
43
49
  type: "adisk",
44
- protocol: "tcp",
45
- tls: false,
50
+ endpoints: [{ protocol: "tcp", tls: false }],
46
51
  dnsRecord: {
47
52
  type: "TXT",
48
53
  parameters: {
@@ -86,7 +91,6 @@ export const ServiceTypeDefinition = {
86
91
  alias: { type: "string", collection: false, writeable: true },
87
92
  type: { type: "string", collection: false, writeable: true },
88
93
  weight: { type: "number", collection: false, writeable: true },
89
- srvPrefix: { type: "string", collection: false, writeable: false },
90
94
  tls: { type: "string", collection: false, writeable: false },
91
95
  systemd: { type: "string", collection: true, writeable: true }
92
96
  }
@@ -145,12 +149,22 @@ export class Service extends Base {
145
149
  return this.rawAddresses.map(a => `${a}:${this.port}`);
146
150
  }
147
151
 
152
+ get endpoints() {
153
+ if (this._port !== undefined) {
154
+ return [
155
+ { protocol: this.protocol, address: this.rawAddress, port: this._port }
156
+ ];
157
+ }
158
+
159
+ return ServiceTypes[this.type]?.endpoints || [];
160
+ }
161
+
148
162
  set port(value) {
149
163
  this._port = value;
150
164
  }
151
165
 
152
166
  get port() {
153
- return this._port || ServiceTypes[this.type]?.port;
167
+ return this._port || ServiceTypes[this.type]?.endpoints[0].port;
154
168
  }
155
169
 
156
170
  set weight(value) {
@@ -178,7 +192,7 @@ export class Service extends Base {
178
192
  }
179
193
 
180
194
  get protocol() {
181
- return ServiceTypes[this.type]?.protocol;
195
+ return ServiceTypes[this.type]?.endpoints[0].protocol;
182
196
  }
183
197
 
184
198
  get tls() {
@@ -189,30 +203,29 @@ export class Service extends Base {
189
203
  return this._systemd;
190
204
  }
191
205
 
192
- get srvPrefix() {
193
- const st = ServiceTypes[this.type];
194
- if (st?.protocol) {
195
- return `_${st.type || this.type}._${st.protocol}`;
196
- }
197
- }
198
-
199
206
  dnsRecordsForDomainName(domainName, hasSVRRecords) {
200
207
  const records = [];
201
208
  if (this.priority <= 1 && this.alias) {
202
209
  records.push(DNSRecord(this.alias, "CNAME", dnsFullName(domainName)));
203
210
  }
204
211
 
205
- if (hasSVRRecords && this.srvPrefix) {
206
- records.push(
207
- DNSRecord(
208
- dnsFullName(`${this.srvPrefix}.${domainName}`),
209
- "SRV",
210
- this.priority || 10,
211
- this.weight,
212
- this.port,
213
- dnsFullName(this.domainName)
214
- )
215
- );
212
+ if (hasSVRRecords) {
213
+ for (const ep of this.endpoints.filter(e => e.protocol)) {
214
+ records.push(
215
+ DNSRecord(
216
+ dnsFullName(
217
+ `_${ServiceTypes[this.type]?.type || this.type}._${
218
+ ep.protocol
219
+ }.${domainName}`
220
+ ),
221
+ "SRV",
222
+ this.priority === undefined ? 10 : this.priority,
223
+ this.weight,
224
+ ep.port,
225
+ dnsFullName(this.domainName)
226
+ )
227
+ );
228
+ }
216
229
  }
217
230
 
218
231
  const dnsRecord = ServiceTypes[this.type]?.dnsRecord;
@@ -234,7 +247,7 @@ export class Service extends Base {
234
247
  DNSRecord(
235
248
  dnsFullName(domainName),
236
249
  dnsRecord.type,
237
- this.priority || 10,
250
+ this.priority === undefined ? 10 : this.priority,
238
251
  ".",
239
252
  dnsFormatParameters(parameters)
240
253
  )
@@ -256,12 +269,13 @@ export function serviceAddresses(
256
269
  sources,
257
270
  filter,
258
271
  addressType = "rawAddresses",
259
- addressFilter = a=>!isLocalhost(a)
272
+ addressFilter = a => !isLocalhost(a)
260
273
  ) {
261
274
  return asArray(sources)
262
275
  .map(ft => Array.from(ft.findServices(filter)))
263
276
  .flat()
264
277
  .sort(sortByPriority)
265
278
  .map(s => s[addressType])
266
- .flat().filter(addressFilter);
279
+ .flat()
280
+ .filter(addressFilter);
267
281
  }
@@ -1,7 +1,7 @@
1
1
  export function dnsFullName(name: any): any;
2
2
  export function DNSRecord(key: any, type: any, ...values: any[]): {
3
3
  key: any;
4
- toString: (maxKeyLength: any, ttl: any) => string;
4
+ toString: (maxKeyLength?: number, ttl?: string) => string;
5
5
  };
6
6
  export function dnsFormatParameters(parameters: any): string;
7
7
  export function dnsMergeParameters(a: any, b: any): {
@@ -98,11 +98,6 @@ export class ExtraSourceService extends Service {
98
98
  collection: boolean;
99
99
  writeable: boolean;
100
100
  };
101
- srvPrefix: {
102
- type: string;
103
- collection: boolean;
104
- writeable: boolean;
105
- };
106
101
  tls: {
107
102
  type: string;
108
103
  collection: boolean;
@@ -83,11 +83,6 @@ export namespace ServiceTypeDefinition {
83
83
  collection: boolean;
84
84
  writeable: boolean;
85
85
  };
86
- srvPrefix: {
87
- type: string;
88
- collection: boolean;
89
- writeable: boolean;
90
- };
91
86
  tls: {
92
87
  type: string;
93
88
  collection: boolean;
@@ -209,11 +204,6 @@ export class Service extends Base {
209
204
  collection: boolean;
210
205
  writeable: boolean;
211
206
  };
212
- srvPrefix: {
213
- type: string;
214
- collection: boolean;
215
- writeable: boolean;
216
- };
217
207
  tls: {
218
208
  type: string;
219
209
  collection: boolean;
@@ -264,6 +254,7 @@ export class Service extends Base {
264
254
  get rawAddress(): any;
265
255
  set ipAddresses(value: any);
266
256
  get addresses(): any;
257
+ get endpoints(): any;
267
258
  set port(value: any);
268
259
  get port(): any;
269
260
  set weight(value: any);
@@ -273,10 +264,9 @@ export class Service extends Base {
273
264
  get protocol(): any;
274
265
  get tls(): any;
275
266
  get systemdServices(): any;
276
- get srvPrefix(): string;
277
267
  dnsRecordsForDomainName(domainName: any, hasSVRRecords: any): {
278
268
  key: any;
279
- toString: (maxKeyLength: any, ttl: any) => string;
269
+ toString: (maxKeyLength?: number, ttl?: string) => string;
280
270
  }[];
281
271
  }
282
272
  export function sortByPriority(a: any, b: any): number;
@@ -85,11 +85,6 @@ export class DHCPService extends Service {
85
85
  collection: boolean;
86
86
  writeable: boolean;
87
87
  };
88
- srvPrefix: {
89
- type: string;
90
- collection: boolean;
91
- writeable: boolean;
92
- };
93
88
  tls: {
94
89
  type: string;
95
90
  collection: boolean;
@@ -90,11 +90,6 @@ export class DNSService extends ExtraSourceService {
90
90
  collection: boolean;
91
91
  writeable: boolean;
92
92
  };
93
- srvPrefix: {
94
- type: string;
95
- collection: boolean;
96
- writeable: boolean;
97
- };
98
93
  tls: {
99
94
  type: string;
100
95
  collection: boolean;
@@ -88,11 +88,6 @@ export class NTPService extends ExtraSourceService {
88
88
  collection: boolean;
89
89
  writeable: boolean;
90
90
  };
91
- srvPrefix: {
92
- type: string;
93
- collection: boolean;
94
- writeable: boolean;
95
- };
96
91
  tls: {
97
92
  type: string;
98
93
  collection: boolean;