@jini-ai/devops 0.5.5 → 0.6.10

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 (60) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/agent-jobs/jobs.js +33 -26
  3. package/dist/agent-jobs/node.d.ts +14 -0
  4. package/dist/agent-jobs/node.js +8 -3
  5. package/dist/checks/coverage/diff.js +21 -10
  6. package/dist/checks/coverage/disk.js +20 -13
  7. package/dist/checks/coverage/integrity.js +44 -39
  8. package/dist/checks/hardwiring-node.js +89 -73
  9. package/dist/checks/hardwiring.d.ts +5 -0
  10. package/dist/checks/hardwiring.js +75 -48
  11. package/dist/checks/node.js +6 -1
  12. package/dist/checks/published-types/index.js +30 -15
  13. package/dist/core/artifact-store.d.ts +35 -0
  14. package/dist/core/artifact-store.js +2 -0
  15. package/dist/deploy/host-kit.d.ts +3 -0
  16. package/dist/deploy/index.d.ts +1 -0
  17. package/dist/deploy/node.d.ts +10 -0
  18. package/dist/deploy/node.js +11 -3
  19. package/dist/deploy/reachability.d.ts +2 -2
  20. package/dist/deploy/reachability.js +164 -117
  21. package/dist/dns/approval.d.ts +61 -0
  22. package/dist/dns/approval.js +48 -0
  23. package/dist/dns/contract.d.ts +206 -0
  24. package/dist/dns/contract.js +30 -0
  25. package/dist/dns/delegation.d.ts +36 -0
  26. package/dist/dns/delegation.js +44 -0
  27. package/dist/dns/index.d.ts +15 -0
  28. package/dist/dns/index.js +15 -0
  29. package/dist/dns/manual.d.ts +28 -0
  30. package/dist/dns/manual.js +140 -0
  31. package/dist/dns/node/index.d.ts +8 -0
  32. package/dist/dns/node/index.js +8 -0
  33. package/dist/dns/node/resolver.d.ts +35 -0
  34. package/dist/dns/node/resolver.js +155 -0
  35. package/dist/dns/node/udp.d.ts +27 -0
  36. package/dist/dns/node/udp.js +39 -0
  37. package/dist/dns/node/wire.d.ts +36 -0
  38. package/dist/dns/node/wire.js +90 -0
  39. package/dist/dns/plan.d.ts +34 -0
  40. package/dist/dns/plan.js +242 -0
  41. package/dist/dns/records.d.ts +67 -0
  42. package/dist/dns/records.js +144 -0
  43. package/dist/dns/registry.d.ts +26 -0
  44. package/dist/dns/registry.js +59 -0
  45. package/dist/dns/spf.d.ts +23 -0
  46. package/dist/dns/spf.js +35 -0
  47. package/dist/dns/verify.d.ts +61 -0
  48. package/dist/dns/verify.js +109 -0
  49. package/dist/local-dev/index.js +36 -20
  50. package/dist/packaging/electron/archive.d.ts +7 -4
  51. package/dist/packaging/electron/archive.js +32 -25
  52. package/dist/packaging/electron/imports.d.ts +1 -1
  53. package/dist/packaging/electron/imports.js +39 -23
  54. package/dist/packaging/electron/staging.js +68 -47
  55. package/dist/source-control/commit.js +36 -18
  56. package/dist/source-control/registry.js +95 -59
  57. package/dist/static-export/node-adapters.js +26 -17
  58. package/dist/static-export/runner.js +185 -103
  59. package/dist/static-export/transforms.js +26 -23
  60. package/package.json +19 -7
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @file Pure value helpers shared by the planner, the verifier and the manual provider: name
3
+ * normalization, presentation-format parsing and a canonical value key for set comparison.
4
+ */
5
+ import type { DomainRecordRequirement } from '@jini-ai/core/provider-registry';
6
+ import type { CaaValue, DnsRecord, DnsRecordType, DnsRecordValue, MxValue } from './contract.js';
7
+ /** Used when an MX requirement names no priority; 10 is the conventional single-MX value. */
8
+ export declare const DEFAULT_MX_PRIORITY = 10;
9
+ /** Lowercase, trimmed, without the trailing root dot. */
10
+ export declare function normalizeDnsName(required: {
11
+ readonly name: string;
12
+ }, _optional?: {}): string;
13
+ /** True when the value is an MX value (narrows `required.value`). */
14
+ export declare function isMxValue(required: {
15
+ readonly value: DnsRecordValue;
16
+ }, _optional?: {}): required is {
17
+ readonly value: MxValue;
18
+ };
19
+ /**
20
+ * RFC 5952 text of a valid IPv6 address (lowercase, no leading zeros, the first longest zero run
21
+ * as `::`), so equivalent spellings compare equal; undefined when the text is not an IPv6 address.
22
+ * @complexity O(1) — an address has eight groups.
23
+ */
24
+ export declare function canonicalIpv6(required: {
25
+ readonly address: string;
26
+ }, _optional?: {}): string | undefined;
27
+ /** A stable string per value, so RRset membership is a string-set comparison. */
28
+ export declare function dnsValueKey(required: {
29
+ readonly value: DnsRecordValue;
30
+ }, _optional?: {}): string;
31
+ /** `10 mx.example.com.` → MX value. */
32
+ export declare function parseMxText(required: {
33
+ readonly text: string;
34
+ }, _optional?: {}): MxValue | undefined;
35
+ /** `0 issue "letsencrypt.org"` → CAA value (quotes optional). */
36
+ export declare function parseCaaText(required: {
37
+ readonly text: string;
38
+ }, _optional?: {}): CaaValue | undefined;
39
+ /** Join quoted character-strings (`"a" "b"` → `ab`); an unquoted value is already logical. */
40
+ export declare function unquoteTxt(required: {
41
+ readonly text: string;
42
+ }, _optional?: {}): string;
43
+ /** One presentation-format answer (what a DNS query returns) as a typed value. */
44
+ export declare function parseAnswerValue(required: {
45
+ readonly type: DnsRecordType;
46
+ readonly text: string;
47
+ }, _optional?: {}): DnsRecordValue | undefined;
48
+ /** The value a requirement asks for; undefined when it is malformed (e.g. an unparseable CAA). */
49
+ export declare function requirementValue(required: {
50
+ readonly record: DomainRecordRequirement;
51
+ }, _optional?: {}): DnsRecordValue | undefined;
52
+ /**
53
+ * Build an RRset from values already checked against `type`. The union cannot be narrowed from a
54
+ * runtime `type` string, so this is the single place the value array is asserted to fit it.
55
+ */
56
+ export declare function buildRecord(required: {
57
+ readonly name: string;
58
+ readonly type: DnsRecordType;
59
+ readonly ttl: number;
60
+ readonly values: readonly DnsRecordValue[];
61
+ }, _optional?: {}): DnsRecord;
62
+ /** True when both sets hold the same values (order-insensitive). */
63
+ export declare function sameValueSet(required: {
64
+ readonly left: readonly DnsRecordValue[];
65
+ readonly right: readonly DnsRecordValue[];
66
+ }, _optional?: {}): boolean;
67
+ //# sourceMappingURL=records.d.ts.map
@@ -0,0 +1,144 @@
1
+ /** Used when an MX requirement names no priority; 10 is the conventional single-MX value. */
2
+ export const DEFAULT_MX_PRIORITY = 10;
3
+ /** Types whose values are host names and therefore compare case- and trailing-dot-insensitively. */
4
+ const HOST_VALUE_TYPES = new Set(['CNAME', 'ALIAS', 'NS']);
5
+ /** Lowercase, trimmed, without the trailing root dot. */
6
+ export function normalizeDnsName(required, _optional = {}) {
7
+ return required.name.trim().toLowerCase().replace(/\.$/, '');
8
+ }
9
+ /** True when the value is an MX value (narrows `required.value`). */
10
+ export function isMxValue(required, _optional = {}) {
11
+ return typeof required.value === 'object' && 'exchange' in required.value;
12
+ }
13
+ const IPV6_GROUP = /^[0-9a-f]{1,4}$/;
14
+ const IPV4_TAIL = /^(.*:)(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
15
+ /** A trailing dotted IPv4 (`::ffff:192.0.2.1`) as its two hex groups; undefined when out of range. */
16
+ function expandIpv4Tail(text) {
17
+ const match = IPV4_TAIL.exec(text);
18
+ if (!match)
19
+ return text;
20
+ const octets = match.slice(2).map(Number);
21
+ if (octets.some(octet => octet > 255))
22
+ return undefined;
23
+ const [a, b, c, d] = octets;
24
+ return `${match[1]}${((a << 8) | b).toString(16)}:${((c << 8) | d).toString(16)}`;
25
+ }
26
+ function parseGroups(text) {
27
+ const groups = text === '' ? [] : text.split(':');
28
+ return groups.every(group => IPV6_GROUP.test(group)) ? groups.map(group => parseInt(group, 16)) : undefined;
29
+ }
30
+ /** The eight 16-bit groups of an IPv6 address; undefined when the text is not one. */
31
+ function ipv6Groups(text) {
32
+ const halves = text.split('::');
33
+ if (halves.length > 2)
34
+ return undefined;
35
+ const head = parseGroups(halves[0]);
36
+ const tail = halves.length === 2 ? parseGroups(halves[1]) : [];
37
+ if (head === undefined || tail === undefined)
38
+ return undefined;
39
+ const missing = 8 - head.length - tail.length;
40
+ if (halves.length === 1 ? missing !== 0 : missing < 1)
41
+ return undefined;
42
+ return [...head, ...Array.from({ length: missing }, () => 0), ...tail];
43
+ }
44
+ /** Each run of zero groups as [start, length], in order. */
45
+ function zeroRuns(groups) {
46
+ const runs = [];
47
+ groups.forEach((group, index) => {
48
+ if (group !== 0)
49
+ return;
50
+ const last = runs[runs.length - 1];
51
+ if (last !== undefined && last[0] + last[1] === index)
52
+ last[1] += 1;
53
+ else
54
+ runs.push([index, 1]);
55
+ });
56
+ return runs;
57
+ }
58
+ /** The first longest run of two or more zero groups, as [start, length]; length 0 when none. */
59
+ function longestZeroRun(groups) {
60
+ return zeroRuns(groups).reduce((best, run) => (run[1] >= 2 && run[1] > best[1] ? run : best), [0, 0]);
61
+ }
62
+ /**
63
+ * RFC 5952 text of a valid IPv6 address (lowercase, no leading zeros, the first longest zero run
64
+ * as `::`), so equivalent spellings compare equal; undefined when the text is not an IPv6 address.
65
+ * @complexity O(1) — an address has eight groups.
66
+ */
67
+ export function canonicalIpv6(required, _optional = {}) {
68
+ const expanded = expandIpv4Tail(required.address.trim().toLowerCase());
69
+ const groups = expanded === undefined ? undefined : ipv6Groups(expanded);
70
+ if (groups === undefined)
71
+ return undefined;
72
+ const [start, length] = longestZeroRun(groups);
73
+ const hex = groups.map(group => group.toString(16));
74
+ if (length === 0)
75
+ return hex.join(':');
76
+ return `${hex.slice(0, start).join(':')}::${hex.slice(start + length).join(':')}`;
77
+ }
78
+ /** A stable string per value, so RRset membership is a string-set comparison. */
79
+ export function dnsValueKey(required, _optional = {}) {
80
+ const { value } = required;
81
+ if (typeof value === 'string')
82
+ return value;
83
+ if (isMxValue(required))
84
+ return `${required.value.priority} ${required.value.exchange}`;
85
+ // Strings and MX values returned above; a type guard on `required` does not narrow `value`.
86
+ const caa = value;
87
+ return `${caa.flags} ${caa.tag} "${caa.value}"`;
88
+ }
89
+ /** `10 mx.example.com.` → MX value. */
90
+ export function parseMxText(required, _optional = {}) {
91
+ const match = /^(\d+)\s+(\S+)$/.exec(required.text.trim());
92
+ return match ? { priority: Number(match[1]), exchange: normalizeDnsName({ name: match[2] }) } : undefined;
93
+ }
94
+ /** `0 issue "letsencrypt.org"` → CAA value (quotes optional). */
95
+ export function parseCaaText(required, _optional = {}) {
96
+ const match = /^(\d+)\s+(issue|issuewild|iodef)\s+"?([^"]*)"?$/i.exec(required.text.trim());
97
+ if (!match)
98
+ return undefined;
99
+ return { flags: Number(match[1]), tag: match[2].toLowerCase(), value: match[3] };
100
+ }
101
+ /** Join quoted character-strings (`"a" "b"` → `ab`); an unquoted value is already logical. */
102
+ export function unquoteTxt(required, _optional = {}) {
103
+ const segments = [...required.text.matchAll(/"((?:[^"\\]|\\.)*)"/g)].map(match => match[1].replace(/\\(.)/g, '$1'));
104
+ return segments.length > 0 ? segments.join('') : required.text;
105
+ }
106
+ function plainValue(required) {
107
+ if (HOST_VALUE_TYPES.has(required.type))
108
+ return normalizeDnsName({ name: required.text });
109
+ const text = required.text.trim().toLowerCase();
110
+ // Expanded and compressed IPv6 spellings are the same address; an invalid one is kept as typed.
111
+ return required.type === 'AAAA' ? (canonicalIpv6({ address: text }) ?? text) : text;
112
+ }
113
+ /** One presentation-format answer (what a DNS query returns) as a typed value. */
114
+ export function parseAnswerValue(required, _optional = {}) {
115
+ const { type, text } = required;
116
+ if (type === 'MX')
117
+ return parseMxText({ text });
118
+ if (type === 'CAA')
119
+ return parseCaaText({ text });
120
+ if (type === 'TXT')
121
+ return unquoteTxt({ text });
122
+ return plainValue({ type, text });
123
+ }
124
+ /** The value a requirement asks for; undefined when it is malformed (e.g. an unparseable CAA). */
125
+ export function requirementValue(required, _optional = {}) {
126
+ const { record } = required;
127
+ if (record.type === 'MX')
128
+ return { priority: record.priority ?? DEFAULT_MX_PRIORITY, exchange: normalizeDnsName({ name: record.value }) };
129
+ return parseAnswerValue({ type: record.type, text: record.value });
130
+ }
131
+ /**
132
+ * Build an RRset from values already checked against `type`. The union cannot be narrowed from a
133
+ * runtime `type` string, so this is the single place the value array is asserted to fit it.
134
+ */
135
+ export function buildRecord(required, _optional = {}) {
136
+ return { name: required.name, type: required.type, ttl: required.ttl, values: required.values };
137
+ }
138
+ /** True when both sets hold the same values (order-insensitive). */
139
+ export function sameValueSet(required, _optional = {}) {
140
+ const left = new Set(required.left.map(value => dnsValueKey({ value })));
141
+ const right = new Set(required.right.map(value => dnsValueKey({ value })));
142
+ return left.size === right.size && [...left].every(key => right.has(key));
143
+ }
144
+ //# sourceMappingURL=records.js.map
@@ -0,0 +1,26 @@
1
+ import { type ProviderDefinition, type ProviderRegistry } from '@jini-ai/core/provider-registry';
2
+ import type { AuthoritativeDnsPort, DnsProvider } from './contract.js';
3
+ export declare const DNS_PROVIDER_CONTRACT = "dns";
4
+ export type DnsProviderRegistry = ProviderRegistry<DnsProvider>;
5
+ /** Composition token for the instance's DNS provider registry. */
6
+ export declare const DnsProviderRegistryToken: import("@jini-ai/core").Token<DnsProviderRegistry, string>;
7
+ /** Composition token for the authoritative resolver the manual provider and the verifier share. */
8
+ export declare const AuthoritativeDnsToken: import("@jini-ai/core").Token<AuthoritativeDnsPort, string>;
9
+ /** @returns Why `provider` is not a DnsProvider, or undefined when it is one. */
10
+ export declare function dnsProviderShapeError(required: {
11
+ readonly provider: unknown;
12
+ }, _optional?: {}): string | undefined;
13
+ /** A registry definition whose id and label come from the provider itself. */
14
+ export declare function dnsProviderDefinition(required: {
15
+ readonly provider: DnsProvider;
16
+ }, _optional?: {}): ProviderDefinition<DnsProvider>;
17
+ /**
18
+ * Build the DNS provider registry with `manual` registered and set as the default.
19
+ * @param optional.seed - Further built-in providers, registered after `manual` (throwing policy).
20
+ */
21
+ export declare function createDnsProviderRegistry(required: {
22
+ readonly resolver: AuthoritativeDnsPort;
23
+ }, optional?: {
24
+ readonly seed?: readonly DnsProvider[];
25
+ }): DnsProviderRegistry;
26
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @file The DNS provider registry: the shared core registry (`contract: 'dns'`) seeded with the
3
+ * built-in `manual` provider as default, plus a shape check so a malformed plugin contribution is
4
+ * refused instead of failing at first use.
5
+ */
6
+ import { token } from '@jini-ai/core';
7
+ import { createProviderRegistry } from '@jini-ai/core/provider-registry';
8
+ import { createManualDnsProvider, MANUAL_DNS_PROVIDER_ID } from './manual.js';
9
+ export const DNS_PROVIDER_CONTRACT = 'dns';
10
+ /** Composition token for the instance's DNS provider registry. */
11
+ export const DnsProviderRegistryToken = token({ id: 'jini.dnsProviderRegistry' });
12
+ /** Composition token for the authoritative resolver the manual provider and the verifier share. */
13
+ export const AuthoritativeDnsToken = token({ id: 'jini.authoritativeDns' });
14
+ function isObject(value) {
15
+ return value !== null && typeof value === 'object';
16
+ }
17
+ function isStringList(value) {
18
+ return Array.isArray(value) && value.every(entry => typeof entry === 'string');
19
+ }
20
+ function capabilitiesValid(value) {
21
+ return isObject(value) && typeof value.automatic === 'boolean' && isStringList(value.recordTypes)
22
+ && typeof value.apexFlattening === 'boolean' && typeof value.proxy === 'boolean';
23
+ }
24
+ function optionalFunction(value) {
25
+ return value === undefined || typeof value === 'function';
26
+ }
27
+ /** Ordered checks; each runs only after every earlier one passed. */
28
+ const SHAPE_CHECKS = [
29
+ [provider => typeof provider.label === 'string' && provider.label.trim() !== '', 'label must be a non-empty string'],
30
+ [provider => isStringList(provider.credentialKeys), 'credentialKeys must be a list of strings'],
31
+ [provider => capabilitiesValid(provider.capabilities), 'capabilities must declare automatic, recordTypes, apexFlattening and proxy'],
32
+ [provider => typeof provider.findZone === 'function' && typeof provider.listRecords === 'function', 'findZone and listRecords must be functions'],
33
+ [provider => optionalFunction(provider.apply) && optionalFunction(provider.instructions), 'apply and instructions must be functions when present'],
34
+ [provider => provider.capabilities.automatic === (provider.apply !== undefined), 'automatic providers must implement apply and manual ones must omit it'],
35
+ ];
36
+ /** @returns Why `provider` is not a DnsProvider, or undefined when it is one. */
37
+ export function dnsProviderShapeError(required, _optional = {}) {
38
+ const { provider } = required;
39
+ if (!isObject(provider))
40
+ return 'provider must be an object';
41
+ return SHAPE_CHECKS.find(([passes]) => !passes(provider))?.[1];
42
+ }
43
+ /** A registry definition whose id and label come from the provider itself. */
44
+ export function dnsProviderDefinition(required, _optional = {}) {
45
+ return { id: required.provider.id, label: required.provider.label, provider: required.provider };
46
+ }
47
+ /**
48
+ * Build the DNS provider registry with `manual` registered and set as the default.
49
+ * @param optional.seed - Further built-in providers, registered after `manual` (throwing policy).
50
+ */
51
+ export function createDnsProviderRegistry(required, optional = {}) {
52
+ const manual = createManualDnsProvider({ resolver: required.resolver });
53
+ return createProviderRegistry({ contract: DNS_PROVIDER_CONTRACT }, {
54
+ defaultProviderId: MANUAL_DNS_PROVIDER_ID,
55
+ validate: ({ provider }) => dnsProviderShapeError({ provider }),
56
+ seed: [manual, ...(optional.seed ?? [])].map(provider => dnsProviderDefinition({ provider })),
57
+ });
58
+ }
59
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @file SPF merging. A name may carry only ONE `v=spf1` TXT value — a second one makes every SPF
3
+ * check return PermError — so a requirement's mechanisms are merged into the existing record
4
+ * instead of being added beside it.
5
+ */
6
+ export declare function isSpfValue(required: {
7
+ readonly value: string;
8
+ }, _optional?: {}): boolean;
9
+ /**
10
+ * Merge `addition`'s mechanisms into `base`, keeping base's order and its `all` qualifier last.
11
+ * When base has no `all`, the addition's (if any) is used. Duplicates compare case-insensitively.
12
+ * @complexity O(n·m) over term counts (both tiny in practice).
13
+ */
14
+ export declare function mergeSpf(required: {
15
+ readonly base: string;
16
+ readonly addition: string;
17
+ }, _optional?: {}): string;
18
+ /** True when `actual` already contains every non-`all` mechanism `wanted` asks for. */
19
+ export declare function spfSatisfies(required: {
20
+ readonly actual: string;
21
+ readonly wanted: string;
22
+ }, _optional?: {}): boolean;
23
+ //# sourceMappingURL=spf.d.ts.map
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @file SPF merging. A name may carry only ONE `v=spf1` TXT value — a second one makes every SPF
3
+ * check return PermError — so a requirement's mechanisms are merged into the existing record
4
+ * instead of being added beside it.
5
+ */
6
+ /** The `all` mechanism with an optional qualifier; it must stay the last term. */
7
+ const ALL_TERM = /^[+\-~?]?all$/i;
8
+ export function isSpfValue(required, _optional = {}) {
9
+ return /^v=spf1(\s|$)/i.test(required.value.trim());
10
+ }
11
+ function spfTerms(value) {
12
+ return value.trim().split(/\s+/).slice(1);
13
+ }
14
+ /**
15
+ * Merge `addition`'s mechanisms into `base`, keeping base's order and its `all` qualifier last.
16
+ * When base has no `all`, the addition's (if any) is used. Duplicates compare case-insensitively.
17
+ * @complexity O(n·m) over term counts (both tiny in practice).
18
+ */
19
+ export function mergeSpf(required, _optional = {}) {
20
+ const baseTerms = spfTerms(required.base);
21
+ const additionTerms = spfTerms(required.addition);
22
+ const allTerm = baseTerms.find(term => ALL_TERM.test(term)) ?? additionTerms.find(term => ALL_TERM.test(term));
23
+ const body = baseTerms.filter(term => !ALL_TERM.test(term));
24
+ for (const term of additionTerms) {
25
+ if (!ALL_TERM.test(term) && !body.some(existing => existing.toLowerCase() === term.toLowerCase()))
26
+ body.push(term);
27
+ }
28
+ return ['v=spf1', ...body, ...(allTerm === undefined ? [] : [allTerm])].join(' ');
29
+ }
30
+ /** True when `actual` already contains every non-`all` mechanism `wanted` asks for. */
31
+ export function spfSatisfies(required, _optional = {}) {
32
+ const have = new Set(spfTerms(required.actual).map(term => term.toLowerCase()));
33
+ return spfTerms(required.wanted).every(term => ALL_TERM.test(term) || have.has(term.toLowerCase()));
34
+ }
35
+ //# sourceMappingURL=spf.js.map
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @file Propagation verification against the zone's AUTHORITATIVE nameservers — every one of them,
3
+ * not a single recursive DoH cache, so "propagated" means the source of truth answers correctly
4
+ * and a nameserver still serving old data is noticed.
5
+ *
6
+ * A transport error is `unknown` (retry later), never a failure: slow DNS is not a broken domain.
7
+ */
8
+ import type { DomainRecordRequirement } from '@jini-ai/core/provider-registry';
9
+ import { type AuthoritativeDnsPort } from './contract.js';
10
+ import type { DnsPlanRequirement } from './contract.js';
11
+ export type PropagationState = 'propagated' | 'pending' | 'mismatch' | 'unknown';
12
+ export interface NameserverObservation {
13
+ readonly nameserver: string;
14
+ readonly state: PropagationState;
15
+ readonly answers: readonly string[];
16
+ }
17
+ export interface RecordVerification {
18
+ readonly record: DomainRecordRequirement;
19
+ readonly state: PropagationState;
20
+ readonly byNameserver: readonly NameserverObservation[];
21
+ }
22
+ export interface DnsVerification {
23
+ readonly zone: string;
24
+ readonly state: PropagationState;
25
+ readonly nameservers: readonly string[];
26
+ readonly records: readonly RecordVerification[];
27
+ readonly reason?: string;
28
+ }
29
+ /** First re-check after 30s, doubling, never more than 10 minutes apart. */
30
+ export declare const FIRST_CHECK_DELAY_MS = 30000;
31
+ export declare const MAX_CHECK_DELAY_MS = 600000;
32
+ /** Give up (report, don't fail silently) after 48 hours — the outer bound of NS/TTL caching. */
33
+ export declare const PROPAGATION_CAP_MS: number;
34
+ /** Delay before check number `attempt` (0-based). @complexity O(1). */
35
+ export declare function nextCheckDelayMs(required: {
36
+ readonly attempt: number;
37
+ }, _optional?: {}): number;
38
+ export declare function isExpired(required: {
39
+ readonly startedAt: number;
40
+ readonly now: number;
41
+ }, _optional?: {}): boolean;
42
+ /** True when one presentation-format answer satisfies the required record. */
43
+ export declare function answerMatches(required: {
44
+ readonly record: DomainRecordRequirement;
45
+ readonly answer: string;
46
+ }, _optional?: {}): boolean;
47
+ /** Overall: a mismatch is the actionable signal, so it outranks unknown and pending. */
48
+ export declare function aggregatePropagation(required: {
49
+ readonly states: readonly PropagationState[];
50
+ }, _optional?: {}): PropagationState;
51
+ /**
52
+ * Check every requirement record on every authoritative nameserver of `zone`.
53
+ * @complexity O(records · nameservers) queries, issued concurrently.
54
+ */
55
+ export declare function verifyRequirements(required: {
56
+ readonly zone: string;
57
+ readonly requirements: readonly DnsPlanRequirement[];
58
+ }, ports: {
59
+ readonly resolver: AuthoritativeDnsPort;
60
+ }): Promise<DnsVerification>;
61
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +1,109 @@
1
+ import { DNS_ADDRESS_TYPES } from './contract.js';
2
+ import { settlePort } from './delegation.js';
3
+ import { dnsValueKey, isMxValue, normalizeDnsName, parseAnswerValue, requirementValue } from './records.js';
4
+ import { isSpfValue, spfSatisfies } from './spf.js';
5
+ /** First re-check after 30s, doubling, never more than 10 minutes apart. */
6
+ export const FIRST_CHECK_DELAY_MS = 30_000;
7
+ export const MAX_CHECK_DELAY_MS = 600_000;
8
+ /** Give up (report, don't fail silently) after 48 hours — the outer bound of NS/TTL caching. */
9
+ export const PROPAGATION_CAP_MS = 48 * 60 * 60 * 1000;
10
+ /** Delay before check number `attempt` (0-based). @complexity O(1). */
11
+ export function nextCheckDelayMs(required, _optional = {}) {
12
+ const attempt = Math.max(0, Math.floor(required.attempt));
13
+ return Math.min(MAX_CHECK_DELAY_MS, FIRST_CHECK_DELAY_MS * 2 ** Math.min(attempt, 10));
14
+ }
15
+ export function isExpired(required, _optional = {}) {
16
+ return required.now - required.startedAt >= PROPAGATION_CAP_MS;
17
+ }
18
+ /** True when one presentation-format answer satisfies the required record. */
19
+ export function answerMatches(required, _optional = {}) {
20
+ const { record } = required;
21
+ const actual = parseAnswerValue({ type: record.type, text: required.answer });
22
+ const expected = requirementValue({ record });
23
+ if (actual === undefined || expected === undefined)
24
+ return false;
25
+ // An MX requirement without a priority accepts any priority for its exchange.
26
+ const have = { value: actual };
27
+ const want = { value: expected };
28
+ if (record.priority === undefined && isMxValue(have) && isMxValue(want))
29
+ return have.value.exchange === want.value.exchange;
30
+ return typeof actual === 'string' && typeof expected === 'string' ? textMatches(actual, expected) : dnsValueKey({ value: actual }) === dnsValueKey({ value: expected });
31
+ }
32
+ /** SPF requirements are merged into the zone's single SPF record, so containment is the test. */
33
+ function textMatches(actual, expected) {
34
+ if (!isSpfValue({ value: expected }))
35
+ return actual === expected;
36
+ return isSpfValue({ value: actual }) && spfSatisfies({ actual, wanted: expected });
37
+ }
38
+ /** True when a TXT answer or requirement value is an SPF (`v=spf1`) record. */
39
+ function isSpfText(type, text) {
40
+ const value = parseAnswerValue({ type, text });
41
+ return type === 'TXT' && typeof value === 'string' && isSpfValue({ value });
42
+ }
43
+ /**
44
+ * Answers that make an RRset wrong even though one of them matches: an address RRset must hold
45
+ * only required values (an obsolete IP still receives traffic), and a name may publish only one
46
+ * SPF record (a second makes every SPF check a PermError).
47
+ */
48
+ function invalidRrset(record, answers, siblings) {
49
+ if (DNS_ADDRESS_TYPES.has(record.type))
50
+ return answers.some(answer => !siblings.some(sibling => answerMatches({ record: sibling, answer })));
51
+ return isSpfText(record.type, record.value) && answers.filter(answer => isSpfText(record.type, answer)).length > 1;
52
+ }
53
+ async function observe(record, nameserver, ports) {
54
+ const name = normalizeDnsName({ name: record.name });
55
+ const result = await settlePort({ call: () => ports.resolver.query({ name, type: record.type, nameserver }) });
56
+ if (result.status === 'unknown')
57
+ return { nameserver, state: 'unknown', answers: [] };
58
+ if (result.status === 'rejected')
59
+ return { nameserver, state: result.error.code === 'not_found' ? 'pending' : 'unknown', answers: [] };
60
+ const { answers } = result.value;
61
+ if (!answers.some(answer => answerMatches({ record, answer })))
62
+ return { nameserver, state: answers.length === 0 ? 'pending' : 'mismatch', answers };
63
+ return { nameserver, state: invalidRrset(record, answers, ports.siblings) ? 'mismatch' : 'propagated', answers };
64
+ }
65
+ /** Requirement records at the same name and type: together they are the RRset a server must serve. */
66
+ function sameRrset(records, record) {
67
+ const name = normalizeDnsName({ name: record.name });
68
+ return records.filter(other => other.type === record.type && normalizeDnsName({ name: other.name }) === name);
69
+ }
70
+ /** Per record: all nameservers agree → propagated; some do → still pending between servers. */
71
+ function recordState(states) {
72
+ if (states.every(state => state === 'propagated'))
73
+ return 'propagated';
74
+ if (states.includes('unknown'))
75
+ return 'unknown';
76
+ if (states.includes('propagated'))
77
+ return 'pending';
78
+ return states.includes('mismatch') ? 'mismatch' : 'pending';
79
+ }
80
+ /** Overall: a mismatch is the actionable signal, so it outranks unknown and pending. */
81
+ export function aggregatePropagation(required, _optional = {}) {
82
+ const { states } = required;
83
+ if (states.every(state => state === 'propagated'))
84
+ return 'propagated';
85
+ if (states.includes('mismatch'))
86
+ return 'mismatch';
87
+ return states.includes('unknown') ? 'unknown' : 'pending';
88
+ }
89
+ /**
90
+ * Check every requirement record on every authoritative nameserver of `zone`.
91
+ * @complexity O(records · nameservers) queries, issued concurrently.
92
+ */
93
+ export async function verifyRequirements(required, ports) {
94
+ const zone = normalizeDnsName({ name: required.zone });
95
+ const records = required.requirements.flatMap(requirement => requirement.records);
96
+ const ns = await settlePort({ call: () => ports.resolver.queryNs({ zone }) });
97
+ const nameservers = ns.status === 'ok' ? [...new Set(ns.value.map(name => normalizeDnsName({ name })))] : [];
98
+ if (nameservers.length === 0) {
99
+ const reason = ns.status === 'ok' ? `${zone} has no authoritative nameservers.` : `The nameservers of ${zone} could not be read.`;
100
+ return { zone, state: 'unknown', nameservers, reason, records: records.map(record => ({ record, state: 'unknown', byNameserver: [] })) };
101
+ }
102
+ const verified = await Promise.all(records.map(async (record) => {
103
+ const siblings = sameRrset(records, record);
104
+ const byNameserver = await Promise.all(nameservers.map(nameserver => observe(record, nameserver, { resolver: ports.resolver, siblings })));
105
+ return { record, state: recordState(byNameserver.map(observation => observation.state)), byNameserver };
106
+ }));
107
+ return { zone, nameservers, records: verified, state: aggregatePropagation({ states: verified.map(record => record.state) }) };
108
+ }
109
+ //# sourceMappingURL=verify.js.map
@@ -34,35 +34,51 @@ export async function listenersOn({ port, runner, listenerCommand }) {
34
34
  return [];
35
35
  }
36
36
  }
37
+ function validListenRange(required) {
38
+ const { port, attempts } = required;
39
+ return Number.isInteger(attempts) && attempts >= 1 && Number.isInteger(port) && port >= 0 && port + attempts - 1 <= 65535;
40
+ }
41
+ /** One bind attempt; both one-shot handlers are removed however it ends, including a synchronous throw. */
42
+ function bindOnce(required, optional) {
43
+ const { server, port } = required;
44
+ return new Promise((resolve, reject) => {
45
+ const cleanup = () => { server.off('error', onError); server.off('listening', onListening); };
46
+ const onError = (error) => { cleanup(); reject(error); };
47
+ const onListening = () => { cleanup(); resolve(); };
48
+ server.once('error', onError);
49
+ server.once('listening', onListening);
50
+ try {
51
+ server.listen({ port, ...(optional.host === undefined ? {} : { host: optional.host }) });
52
+ }
53
+ catch (error) {
54
+ onError(error);
55
+ }
56
+ });
57
+ }
58
+ function addressInUse(error) {
59
+ return error?.code === 'EADDRINUSE';
60
+ }
61
+ /** Bind once at `port`; the listener's reported port wins over the requested one (port 0, retries). */
62
+ async function bindAndReport(required, optional) {
63
+ await bindOnce(required, optional);
64
+ const address = required.server.address();
65
+ return typeof address === 'object' && address !== null ? address.port : required.port;
66
+ }
37
67
  /** Bind the actual listener, retaining it across boot. Only address collisions may try the next
38
68
  * port; explicit addresses use the default single attempt. No probe/release/bind race. */
39
69
  export async function listenServer({ server, port }, { host, attempts = 1 } = {}) {
40
- if (!Number.isInteger(attempts) || attempts < 1 || !Number.isInteger(port) || port < 0 || port + attempts - 1 > 65535) {
70
+ if (!validListenRange({ port, attempts }))
41
71
  throw new RangeError('Invalid listener port or attempt range');
42
- }
43
- for (let offset = 0; offset < attempts; offset++) {
72
+ for (let offset = 0; offset < attempts - 1; offset++) {
44
73
  try {
45
- await new Promise((resolve, reject) => {
46
- const cleanup = () => { server.off('error', onError); server.off('listening', onListening); };
47
- const onError = (error) => { cleanup(); reject(error); };
48
- const onListening = () => { cleanup(); resolve(); };
49
- server.once('error', onError);
50
- server.once('listening', onListening);
51
- try {
52
- server.listen({ port: port + offset, ...(host === undefined ? {} : { host }) });
53
- }
54
- catch (error) {
55
- onError(error);
56
- }
57
- });
58
- const address = server.address();
59
- return typeof address === 'object' && address !== null ? address.port : port + offset;
74
+ return await bindAndReport({ server, port: port + offset }, { host });
60
75
  }
61
76
  catch (error) {
62
- if (error?.code !== 'EADDRINUSE' || offset === attempts - 1)
77
+ if (!addressInUse(error))
63
78
  throw error;
64
79
  }
65
80
  }
66
- throw new Error('Listener range exhausted');
81
+ // The final attempt's error, whatever it is, propagates unchanged.
82
+ return bindAndReport({ server, port: port + attempts - 1 }, { host });
67
83
  }
68
84
  //# sourceMappingURL=index.js.map
@@ -43,20 +43,22 @@ export declare function toArchiveEntryPath({ relPath, separator }: {
43
43
  relPath: string;
44
44
  separator: string;
45
45
  }): string;
46
- /** Compare actual content: equal sizes and an archive's own hash cannot detect shifted offsets. */
47
- export declare function verifyAsarAgainstSource(required: {
46
+ type VerifyRequired = {
48
47
  archivePath: string;
49
48
  sourceRoot: string;
50
49
  prefixes: readonly string[];
51
50
  separator: string;
52
51
  fs: PackagingFilesystemPort;
53
52
  archive: ArchiveReaderPort;
54
- }, optional?: {
53
+ };
54
+ type VerifyOptional = {
55
55
  readFailureMessage?: (required: {
56
56
  error: unknown;
57
57
  }) => string;
58
58
  contentMismatchMessage?: string;
59
- }): AsarVerification;
59
+ };
60
+ /** Compare actual content: equal sizes and an archive's own hash cannot detect shifted offsets. */
61
+ export declare function verifyAsarAgainstSource(required: VerifyRequired, optional?: VerifyOptional): AsarVerification;
60
62
  /**
61
63
  * `checkedCount === 0` is never a clean pass — the walk found nothing to compare at all, which
62
64
  * almost always means a path-separator mismatch (see {@link toArchiveEntryPath}) or a stale
@@ -79,4 +81,5 @@ export declare function bundledNpmFailures(required: {
79
81
  requiredFiles: readonly string[];
80
82
  fs: PackagingFilesystemPort;
81
83
  }): string[];
84
+ export {};
82
85
  //# sourceMappingURL=archive.d.ts.map