@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.
- package/CHANGELOG.md +17 -0
- package/dist/agent-jobs/jobs.js +33 -26
- package/dist/agent-jobs/node.d.ts +14 -0
- package/dist/agent-jobs/node.js +8 -3
- package/dist/checks/coverage/diff.js +21 -10
- package/dist/checks/coverage/disk.js +20 -13
- package/dist/checks/coverage/integrity.js +44 -39
- package/dist/checks/hardwiring-node.js +89 -73
- package/dist/checks/hardwiring.d.ts +5 -0
- package/dist/checks/hardwiring.js +75 -48
- package/dist/checks/node.js +6 -1
- package/dist/checks/published-types/index.js +30 -15
- package/dist/core/artifact-store.d.ts +35 -0
- package/dist/core/artifact-store.js +2 -0
- package/dist/deploy/host-kit.d.ts +3 -0
- package/dist/deploy/index.d.ts +1 -0
- package/dist/deploy/node.d.ts +10 -0
- package/dist/deploy/node.js +11 -3
- package/dist/deploy/reachability.d.ts +2 -2
- package/dist/deploy/reachability.js +164 -117
- package/dist/dns/approval.d.ts +61 -0
- package/dist/dns/approval.js +48 -0
- package/dist/dns/contract.d.ts +206 -0
- package/dist/dns/contract.js +30 -0
- package/dist/dns/delegation.d.ts +36 -0
- package/dist/dns/delegation.js +44 -0
- package/dist/dns/index.d.ts +15 -0
- package/dist/dns/index.js +15 -0
- package/dist/dns/manual.d.ts +28 -0
- package/dist/dns/manual.js +140 -0
- package/dist/dns/node/index.d.ts +8 -0
- package/dist/dns/node/index.js +8 -0
- package/dist/dns/node/resolver.d.ts +35 -0
- package/dist/dns/node/resolver.js +155 -0
- package/dist/dns/node/udp.d.ts +27 -0
- package/dist/dns/node/udp.js +39 -0
- package/dist/dns/node/wire.d.ts +36 -0
- package/dist/dns/node/wire.js +90 -0
- package/dist/dns/plan.d.ts +34 -0
- package/dist/dns/plan.js +242 -0
- package/dist/dns/records.d.ts +67 -0
- package/dist/dns/records.js +144 -0
- package/dist/dns/registry.d.ts +26 -0
- package/dist/dns/registry.js +59 -0
- package/dist/dns/spf.d.ts +23 -0
- package/dist/dns/spf.js +35 -0
- package/dist/dns/verify.d.ts +61 -0
- package/dist/dns/verify.js +109 -0
- package/dist/local-dev/index.js +36 -20
- package/dist/packaging/electron/archive.d.ts +7 -4
- package/dist/packaging/electron/archive.js +32 -25
- package/dist/packaging/electron/imports.d.ts +1 -1
- package/dist/packaging/electron/imports.js +39 -23
- package/dist/packaging/electron/staging.js +68 -47
- package/dist/source-control/commit.js +36 -18
- package/dist/source-control/registry.js +95 -59
- package/dist/static-export/node-adapters.js +26 -17
- package/dist/static-export/runner.js +185 -103
- package/dist/static-export/transforms.js +26 -23
- package/package.json +19 -7
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The generic DNS provider contract (lots D1–D3 of the domains & DNS design).
|
|
3
|
+
*
|
|
4
|
+
* Records are modelled as RRsets (`name` + `type` + `values[]`), because every DNS API and the
|
|
5
|
+
* wire protocol itself treat the set as the unit of change: two TXT values at one name are one
|
|
6
|
+
* record set, and replacing "the" A record of a name means replacing the set. Planning,
|
|
7
|
+
* verification and approval are provider-neutral and live beside this file; a provider only
|
|
8
|
+
* finds zones, lists records and (later, D4) applies changes.
|
|
9
|
+
*
|
|
10
|
+
* The requirement shapes (`DomainRequirement`) and the provider registry are shared with mail and
|
|
11
|
+
* hosting providers in `@jini-ai/core/provider-registry`; they are reused, never redefined here.
|
|
12
|
+
*/
|
|
13
|
+
import type { HttpClientPort } from '@jini-ai/core/primitives';
|
|
14
|
+
import type { DnsRecordType as CoreDnsRecordType, DomainRequirement, ProviderContext, ProviderResult } from '@jini-ai/core/provider-registry';
|
|
15
|
+
/** Core record types plus `ALIAS` (apex flattening / provider alias targets), a DNS-host concept. */
|
|
16
|
+
export type DnsRecordType = CoreDnsRecordType | 'ALIAS';
|
|
17
|
+
/** Address records: at most one of these families may own a name (CNAME excludes everything). */
|
|
18
|
+
export declare const DNS_ADDRESS_TYPES: ReadonlySet<DnsRecordType>;
|
|
19
|
+
/** TTL used when neither a requirement nor a provider supplies one. */
|
|
20
|
+
export declare const DEFAULT_DNS_TTL = 300;
|
|
21
|
+
/** RFC 1035 character-string limit for one TXT chunk, in bytes. */
|
|
22
|
+
export declare const TXT_CHUNK_BYTES = 255;
|
|
23
|
+
export interface MxValue {
|
|
24
|
+
readonly priority: number;
|
|
25
|
+
/** Normalized host name: lowercase, no trailing dot. */
|
|
26
|
+
readonly exchange: string;
|
|
27
|
+
}
|
|
28
|
+
export type CaaTag = 'issue' | 'issuewild' | 'iodef';
|
|
29
|
+
export interface CaaValue {
|
|
30
|
+
readonly flags: number;
|
|
31
|
+
readonly tag: CaaTag;
|
|
32
|
+
readonly value: string;
|
|
33
|
+
}
|
|
34
|
+
export type DnsRecordValue = string | MxValue | CaaValue;
|
|
35
|
+
interface DnsRecordBase {
|
|
36
|
+
/** Fully-qualified, normalized name (lowercase, no trailing dot). */
|
|
37
|
+
readonly name: string;
|
|
38
|
+
readonly ttl: number;
|
|
39
|
+
/** Provider proxy flag (e.g. a CDN reverse proxy); only meaningful when `capabilities.proxy`. */
|
|
40
|
+
readonly proxied?: boolean;
|
|
41
|
+
/** Provider-native alias target (e.g. a cloud load balancer) instead of literal values. */
|
|
42
|
+
readonly providerAlias?: {
|
|
43
|
+
readonly target: string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* `self` marks a record this engine created for the host; anything else is someone else's record.
|
|
47
|
+
* (Neutral on purpose: product names belong to the host, never the engine.)
|
|
48
|
+
*/
|
|
49
|
+
readonly managedBy?: 'self' | 'other';
|
|
50
|
+
/** Opaque provider handle for later apply calls. Never shown to an operator. */
|
|
51
|
+
readonly providerRef?: string;
|
|
52
|
+
}
|
|
53
|
+
/** A/AAAA/CNAME/ALIAS/NS/SRV carry plain strings; TXT carries the LOGICAL (unchunked) string. */
|
|
54
|
+
export interface DnsPlainRecord extends DnsRecordBase {
|
|
55
|
+
readonly type: Exclude<DnsRecordType, 'MX' | 'CAA'>;
|
|
56
|
+
readonly values: readonly string[];
|
|
57
|
+
}
|
|
58
|
+
export interface DnsMxRecord extends DnsRecordBase {
|
|
59
|
+
readonly type: 'MX';
|
|
60
|
+
readonly values: readonly MxValue[];
|
|
61
|
+
}
|
|
62
|
+
export interface DnsCaaRecord extends DnsRecordBase {
|
|
63
|
+
readonly type: 'CAA';
|
|
64
|
+
readonly values: readonly CaaValue[];
|
|
65
|
+
}
|
|
66
|
+
/** One RRset. */
|
|
67
|
+
export type DnsRecord = DnsPlainRecord | DnsMxRecord | DnsCaaRecord;
|
|
68
|
+
/** A shared requirement, optionally naming the CA the target will use so a CAA set can be checked. */
|
|
69
|
+
export type DnsPlanRequirement = DomainRequirement & {
|
|
70
|
+
readonly caa?: {
|
|
71
|
+
readonly issuer: string;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* How much of the zone the provider could see. Only `complete` may ever lead to a mutation:
|
|
76
|
+
* a plan over a partial view could delete or shadow a record nobody looked at.
|
|
77
|
+
*/
|
|
78
|
+
export type DnsInventory = 'complete' | 'partial' | 'unknown';
|
|
79
|
+
export interface DnsChange {
|
|
80
|
+
readonly op: 'create' | 'update' | 'delete';
|
|
81
|
+
readonly before?: DnsRecord;
|
|
82
|
+
readonly after?: DnsRecord;
|
|
83
|
+
readonly reason: string;
|
|
84
|
+
}
|
|
85
|
+
export type DnsPlanBlockerCode = 'inventory_incomplete' | 'cname_coexistence' | 'apex_cname' | 'caa_excludes_issuer' | 'multiple_spf' | 'unsupported_record_type' | 'invalid_requirement'
|
|
86
|
+
/** An address record not marked `managedBy: 'self'` would have been replaced or deleted. */
|
|
87
|
+
| 'record_not_owned';
|
|
88
|
+
export interface DnsPlanBlocker {
|
|
89
|
+
readonly code: DnsPlanBlockerCode;
|
|
90
|
+
/** The record name the blocker is about (the zone for plan-wide blockers). */
|
|
91
|
+
readonly name: string;
|
|
92
|
+
readonly message: string;
|
|
93
|
+
readonly suggestion?: string;
|
|
94
|
+
}
|
|
95
|
+
export interface DnsChangePlan {
|
|
96
|
+
readonly providerId: string;
|
|
97
|
+
readonly zone: string;
|
|
98
|
+
/** Ordered: deletes, then updates, then creates. */
|
|
99
|
+
readonly changes: readonly DnsChange[];
|
|
100
|
+
/** Disclosed and untouched (wildcards, mail, TXT, CAA, unrelated records). */
|
|
101
|
+
readonly preserved: readonly DnsRecord[];
|
|
102
|
+
readonly inventory: DnsInventory;
|
|
103
|
+
/** Any blocker makes the plan unapprovable. */
|
|
104
|
+
readonly blockers: readonly DnsPlanBlocker[];
|
|
105
|
+
/** sha-256 over the canonical plan; the approval binds to it. */
|
|
106
|
+
readonly fingerprint: string;
|
|
107
|
+
}
|
|
108
|
+
/** Everything a provider call may use. Credentials are pre-resolved by the host. */
|
|
109
|
+
export interface DnsProviderContext extends ProviderContext {
|
|
110
|
+
readonly credentials: Readonly<Record<string, string>>;
|
|
111
|
+
readonly httpClient: HttpClientPort;
|
|
112
|
+
readonly now: () => number;
|
|
113
|
+
}
|
|
114
|
+
export interface DnsZone {
|
|
115
|
+
/** Normalized zone apex, e.g. `example.com` or a delegated subzone `dev.example.com`. */
|
|
116
|
+
readonly zone: string;
|
|
117
|
+
/** Opaque provider zone handle. */
|
|
118
|
+
readonly ref: string;
|
|
119
|
+
}
|
|
120
|
+
export interface DnsProviderCapabilities {
|
|
121
|
+
/** False: the provider cannot write (it emits instructions instead) and must omit `apply`. */
|
|
122
|
+
readonly automatic: boolean;
|
|
123
|
+
readonly recordTypes: readonly DnsRecordType[];
|
|
124
|
+
/** True when a CNAME at the zone apex is flattened by the host. */
|
|
125
|
+
readonly apexFlattening: boolean;
|
|
126
|
+
readonly proxy: boolean;
|
|
127
|
+
}
|
|
128
|
+
export interface DnsInstructionRow {
|
|
129
|
+
readonly action: 'add' | 'change' | 'remove';
|
|
130
|
+
readonly type: DnsRecordType;
|
|
131
|
+
/** Fully-qualified record name. */
|
|
132
|
+
readonly name: string;
|
|
133
|
+
/** Name relative to the zone, `@` for the apex — what most DNS host forms ask for. */
|
|
134
|
+
readonly host: string;
|
|
135
|
+
readonly value: string;
|
|
136
|
+
readonly ttl: number;
|
|
137
|
+
readonly priority?: number;
|
|
138
|
+
}
|
|
139
|
+
export interface DnsInstructions {
|
|
140
|
+
readonly zone: string;
|
|
141
|
+
readonly rows: readonly DnsInstructionRow[];
|
|
142
|
+
readonly notes: readonly string[];
|
|
143
|
+
}
|
|
144
|
+
export interface DnsProvider {
|
|
145
|
+
readonly id: string;
|
|
146
|
+
readonly label: string;
|
|
147
|
+
readonly credentialKeys: readonly string[];
|
|
148
|
+
readonly capabilities: DnsProviderCapabilities;
|
|
149
|
+
/** The zone (possibly a delegated subzone) serving `hostname`; `null` when the provider has none. */
|
|
150
|
+
findZone(ctx: DnsProviderContext, required: {
|
|
151
|
+
readonly hostname: string;
|
|
152
|
+
}): Promise<ProviderResult<DnsZone | null>>;
|
|
153
|
+
listRecords(ctx: DnsProviderContext, required: {
|
|
154
|
+
readonly zoneRef: string;
|
|
155
|
+
readonly names: readonly string[];
|
|
156
|
+
}): Promise<ProviderResult<{
|
|
157
|
+
readonly records: readonly DnsRecord[];
|
|
158
|
+
readonly inventory: DnsInventory;
|
|
159
|
+
}>>;
|
|
160
|
+
/** Declared for D4; unused in v1. Providers with `automatic: false` omit it. */
|
|
161
|
+
apply?(ctx: DnsProviderContext, required: {
|
|
162
|
+
readonly zoneRef: string;
|
|
163
|
+
readonly change: DnsChange;
|
|
164
|
+
readonly idempotencyKey: string;
|
|
165
|
+
}): Promise<ProviderResult<{
|
|
166
|
+
readonly record?: DnsRecord;
|
|
167
|
+
}>>;
|
|
168
|
+
/** Copy-pasteable steps for a human; `requirements` lets a blocked plan still show what is needed. */
|
|
169
|
+
instructions?(required: {
|
|
170
|
+
readonly plan: DnsChangePlan;
|
|
171
|
+
}, optional?: {
|
|
172
|
+
readonly requirements?: readonly DnsPlanRequirement[];
|
|
173
|
+
}): DnsInstructions;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Queries a zone's authoritative servers directly, never through a caching recursive resolver,
|
|
177
|
+
* so "propagated" means the source of truth answers, not one resolver's cache.
|
|
178
|
+
*
|
|
179
|
+
* Result convention: `ok` with an empty list is NODATA; `rejected` with `not_found` is NXDOMAIN;
|
|
180
|
+
* `unknown` is a transport failure. A thrown error is treated as `unknown` by every caller.
|
|
181
|
+
*/
|
|
182
|
+
export interface AuthoritativeDnsPort {
|
|
183
|
+
/** The NS set delegated to `zone` by its parent (what the registrar published). */
|
|
184
|
+
queryNs(required: {
|
|
185
|
+
readonly zone: string;
|
|
186
|
+
}): Promise<ProviderResult<readonly string[]>>;
|
|
187
|
+
/** Records of exactly `type` at `name`, asked of `nameserver`; answers in presentation format. */
|
|
188
|
+
query(required: {
|
|
189
|
+
readonly name: string;
|
|
190
|
+
readonly type: DnsRecordType;
|
|
191
|
+
readonly nameserver: string;
|
|
192
|
+
}): Promise<ProviderResult<{
|
|
193
|
+
readonly answers: readonly string[];
|
|
194
|
+
readonly ttl?: number;
|
|
195
|
+
}>>;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Split a logical TXT value into ≤255-byte character-strings without splitting a UTF-8 sequence.
|
|
199
|
+
* An empty value is one empty chunk (a TXT record always has at least one character-string).
|
|
200
|
+
* @complexity O(n) in the value length.
|
|
201
|
+
*/
|
|
202
|
+
export declare function chunkTxt(required: {
|
|
203
|
+
readonly value: string;
|
|
204
|
+
}, _optional?: {}): string[];
|
|
205
|
+
export {};
|
|
206
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Address records: at most one of these families may own a name (CNAME excludes everything). */
|
|
2
|
+
export const DNS_ADDRESS_TYPES = new Set(['A', 'AAAA', 'CNAME', 'ALIAS']);
|
|
3
|
+
/** TTL used when neither a requirement nor a provider supplies one. */
|
|
4
|
+
export const DEFAULT_DNS_TTL = 300;
|
|
5
|
+
/** RFC 1035 character-string limit for one TXT chunk, in bytes. */
|
|
6
|
+
export const TXT_CHUNK_BYTES = 255;
|
|
7
|
+
/**
|
|
8
|
+
* Split a logical TXT value into ≤255-byte character-strings without splitting a UTF-8 sequence.
|
|
9
|
+
* An empty value is one empty chunk (a TXT record always has at least one character-string).
|
|
10
|
+
* @complexity O(n) in the value length.
|
|
11
|
+
*/
|
|
12
|
+
export function chunkTxt(required, _optional = {}) {
|
|
13
|
+
const encoder = new TextEncoder();
|
|
14
|
+
const chunks = [];
|
|
15
|
+
let current = '';
|
|
16
|
+
let size = 0;
|
|
17
|
+
for (const char of required.value) {
|
|
18
|
+
const bytes = encoder.encode(char).length;
|
|
19
|
+
if (size + bytes > TXT_CHUNK_BYTES) {
|
|
20
|
+
chunks.push(current);
|
|
21
|
+
current = '';
|
|
22
|
+
size = 0;
|
|
23
|
+
}
|
|
24
|
+
current += char;
|
|
25
|
+
size += bytes;
|
|
26
|
+
}
|
|
27
|
+
chunks.push(current);
|
|
28
|
+
return chunks;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file NS delegation check. The registrar (who publishes the NS set in the parent zone) and the
|
|
3
|
+
* DNS host (who serves the records) are often different companies; planning against a host the
|
|
4
|
+
* zone is not delegated to edits records nobody resolves. This only READS the delegation —
|
|
5
|
+
* registrar writes are out of scope.
|
|
6
|
+
*/
|
|
7
|
+
import { type ProviderResult } from '@jini-ai/core/provider-registry';
|
|
8
|
+
import type { AuthoritativeDnsPort } from './contract.js';
|
|
9
|
+
export type DelegationState = 'delegated' | 'not_delegated' | 'unknown';
|
|
10
|
+
export interface DelegationCheck {
|
|
11
|
+
readonly zone: string;
|
|
12
|
+
readonly state: DelegationState;
|
|
13
|
+
/** The NS set the parent publishes (normalized, sorted). */
|
|
14
|
+
readonly nameservers: readonly string[];
|
|
15
|
+
/** Expected nameservers absent from the delegation. */
|
|
16
|
+
readonly missing: readonly string[];
|
|
17
|
+
/** Delegated nameservers the caller did not expect (e.g. the previous DNS host's). */
|
|
18
|
+
readonly unexpected: readonly string[];
|
|
19
|
+
readonly reason: string;
|
|
20
|
+
}
|
|
21
|
+
/** Call a port method, turning a thrown error into the `unknown` outcome it really is. */
|
|
22
|
+
export declare function settlePort<T>(required: {
|
|
23
|
+
readonly call: () => Promise<ProviderResult<T>>;
|
|
24
|
+
}, _optional?: {}): Promise<ProviderResult<T>>;
|
|
25
|
+
/**
|
|
26
|
+
* Read the NS delegation of `zone`. With `expectedNameservers` the delegation must match that set
|
|
27
|
+
* exactly: a leftover nameserver of the previous host would answer some queries with old data.
|
|
28
|
+
* A transport failure is `unknown`, never `not_delegated`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function checkDelegation(required: {
|
|
31
|
+
readonly zone: string;
|
|
32
|
+
readonly expectedNameservers?: readonly string[];
|
|
33
|
+
}, ports: {
|
|
34
|
+
readonly resolver: AuthoritativeDnsPort;
|
|
35
|
+
}): Promise<DelegationCheck>;
|
|
36
|
+
//# sourceMappingURL=delegation.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file NS delegation check. The registrar (who publishes the NS set in the parent zone) and the
|
|
3
|
+
* DNS host (who serves the records) are often different companies; planning against a host the
|
|
4
|
+
* zone is not delegated to edits records nobody resolves. This only READS the delegation —
|
|
5
|
+
* registrar writes are out of scope.
|
|
6
|
+
*/
|
|
7
|
+
import { providerUnknown } from '@jini-ai/core/provider-registry';
|
|
8
|
+
import { normalizeDnsName } from './records.js';
|
|
9
|
+
/** Call a port method, turning a thrown error into the `unknown` outcome it really is. */
|
|
10
|
+
export async function settlePort(required, _optional = {}) {
|
|
11
|
+
try {
|
|
12
|
+
return await required.call();
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return providerUnknown({ code: 'network', message: 'The DNS query failed before an answer arrived.' });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function compare(actual, expected) {
|
|
19
|
+
return { missing: expected.filter(ns => !actual.includes(ns)), unexpected: actual.filter(ns => !expected.includes(ns)) };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Read the NS delegation of `zone`. With `expectedNameservers` the delegation must match that set
|
|
23
|
+
* exactly: a leftover nameserver of the previous host would answer some queries with old data.
|
|
24
|
+
* A transport failure is `unknown`, never `not_delegated`.
|
|
25
|
+
*/
|
|
26
|
+
export async function checkDelegation(required, ports) {
|
|
27
|
+
const zone = normalizeDnsName({ name: required.zone });
|
|
28
|
+
const result = await settlePort({ call: () => ports.resolver.queryNs({ zone }) });
|
|
29
|
+
const empty = { zone, nameservers: [], missing: [], unexpected: [] };
|
|
30
|
+
if (result.status === 'unknown')
|
|
31
|
+
return { ...empty, state: 'unknown', reason: `The delegation of ${zone} could not be read: ${result.error.message}` };
|
|
32
|
+
if (result.status === 'rejected' && result.error.code !== 'not_found')
|
|
33
|
+
return { ...empty, state: 'unknown', reason: `The delegation of ${zone} could not be read: ${result.error.message}` };
|
|
34
|
+
const nameservers = result.status === 'ok' ? [...new Set(result.value.map(name => normalizeDnsName({ name })))].sort() : [];
|
|
35
|
+
if (nameservers.length === 0)
|
|
36
|
+
return { ...empty, state: 'not_delegated', reason: `${zone} has no NS delegation in its parent zone.` };
|
|
37
|
+
const expected = (required.expectedNameservers ?? []).map(name => normalizeDnsName({ name }));
|
|
38
|
+
const { missing, unexpected } = compare(nameservers, expected);
|
|
39
|
+
if (expected.length > 0 && missing.length + unexpected.length > 0) {
|
|
40
|
+
return { zone, nameservers, missing, unexpected, state: 'not_delegated', reason: `${zone} is delegated to ${nameservers.join(', ')}, not to ${expected.join(', ')}; change the nameservers at the registrar.` };
|
|
41
|
+
}
|
|
42
|
+
return { zone, nameservers, missing: [], unexpected: [], state: 'delegated', reason: `${zone} is delegated to ${nameservers.join(', ')}.` };
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=delegation.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@jini-ai/devops/dns` — the generic DNS kernel: RRset contract, pure planner + fingerprint,
|
|
3
|
+
* NS delegation check, authoritative propagation verification, approval binding and the built-in
|
|
4
|
+
* `manual` provider. Applying changes (D4) and vendor providers live elsewhere.
|
|
5
|
+
*/
|
|
6
|
+
export * from './contract.js';
|
|
7
|
+
export * from './records.js';
|
|
8
|
+
export * from './spf.js';
|
|
9
|
+
export * from './plan.js';
|
|
10
|
+
export * from './delegation.js';
|
|
11
|
+
export * from './verify.js';
|
|
12
|
+
export * from './approval.js';
|
|
13
|
+
export * from './manual.js';
|
|
14
|
+
export * from './registry.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@jini-ai/devops/dns` — the generic DNS kernel: RRset contract, pure planner + fingerprint,
|
|
3
|
+
* NS delegation check, authoritative propagation verification, approval binding and the built-in
|
|
4
|
+
* `manual` provider. Applying changes (D4) and vendor providers live elsewhere.
|
|
5
|
+
*/
|
|
6
|
+
export * from './contract.js';
|
|
7
|
+
export * from './records.js';
|
|
8
|
+
export * from './spf.js';
|
|
9
|
+
export * from './plan.js';
|
|
10
|
+
export * from './delegation.js';
|
|
11
|
+
export * from './verify.js';
|
|
12
|
+
export * from './approval.js';
|
|
13
|
+
export * from './manual.js';
|
|
14
|
+
export * from './registry.js';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type AuthoritativeDnsPort, type DnsChangePlan, type DnsInstructions, type DnsPlanRequirement, type DnsProvider } from './contract.js';
|
|
2
|
+
export declare const MANUAL_DNS_PROVIDER_ID = "manual";
|
|
3
|
+
export interface ManualDnsProviderOptions {
|
|
4
|
+
readonly label?: string;
|
|
5
|
+
/** Public-suffix check (e.g. `co.uk`), so a zone is never guessed at a suffix. */
|
|
6
|
+
readonly isPublicSuffix?: (required: {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
}) => boolean;
|
|
9
|
+
}
|
|
10
|
+
/** `www.example.com` in `example.com` → `www`; the apex is `@`. */
|
|
11
|
+
export declare function relativeHost(required: {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly zone: string;
|
|
14
|
+
}, _optional?: {}): string;
|
|
15
|
+
/** Copy-pasteable rows (type/name/value/TTL/priority) for a plan. */
|
|
16
|
+
export declare function renderDnsInstructions(required: {
|
|
17
|
+
readonly plan: DnsChangePlan;
|
|
18
|
+
}, optional?: {
|
|
19
|
+
readonly requirements?: readonly DnsPlanRequirement[];
|
|
20
|
+
}): DnsInstructions;
|
|
21
|
+
/**
|
|
22
|
+
* Create the manual provider over an authoritative resolver.
|
|
23
|
+
* @param required.resolver - Queries the zone's own nameservers (see {@link AuthoritativeDnsPort}).
|
|
24
|
+
*/
|
|
25
|
+
export declare function createManualDnsProvider(required: {
|
|
26
|
+
readonly resolver: AuthoritativeDnsPort;
|
|
27
|
+
}, optional?: ManualDnsProviderOptions): DnsProvider;
|
|
28
|
+
//# sourceMappingURL=manual.d.ts.map
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The built-in default DNS provider, `manual`: no API and no credentials. It reads the zone
|
|
3
|
+
* through the authoritative nameservers and turns a plan into copy-pasteable rows a person enters
|
|
4
|
+
* at any DNS host. It works for every registrar out of the box, including delegated subzones.
|
|
5
|
+
*
|
|
6
|
+
* What it cannot read stays `unknown` — it never invents a CONFLICT or an empty zone.
|
|
7
|
+
*/
|
|
8
|
+
import { providerOk } from '@jini-ai/core/provider-registry';
|
|
9
|
+
import { DEFAULT_DNS_TTL, chunkTxt, } from './contract.js';
|
|
10
|
+
import { settlePort } from './delegation.js';
|
|
11
|
+
import { buildRecord, isMxValue, normalizeDnsName, parseAnswerValue, requirementValue } from './records.js';
|
|
12
|
+
export const MANUAL_DNS_PROVIDER_ID = 'manual';
|
|
13
|
+
/**
|
|
14
|
+
* Every type this provider can serve (ALIAS is a host feature, not a served type); a name answering
|
|
15
|
+
* all of these is fully known. NS and SRV matter for conflicts (a delegated child, a CNAME beside them).
|
|
16
|
+
*/
|
|
17
|
+
const QUERIED_TYPES = ['A', 'AAAA', 'CNAME', 'TXT', 'MX', 'CAA', 'NS', 'SRV'];
|
|
18
|
+
/** `www.example.com` in `example.com` → `www`; the apex is `@`. */
|
|
19
|
+
export function relativeHost(required, _optional = {}) {
|
|
20
|
+
const { name, zone } = required;
|
|
21
|
+
if (name === zone)
|
|
22
|
+
return '@';
|
|
23
|
+
return name.endsWith(`.${zone}`) ? name.slice(0, -(zone.length + 1)) : name;
|
|
24
|
+
}
|
|
25
|
+
function valueText(type, value) {
|
|
26
|
+
const input = { value };
|
|
27
|
+
if (isMxValue(input))
|
|
28
|
+
return input.value.exchange;
|
|
29
|
+
// MX returned above; a type guard on `input` does not narrow `value`.
|
|
30
|
+
if (typeof value !== 'string')
|
|
31
|
+
return `${value.flags} ${value.tag} "${value.value}"`;
|
|
32
|
+
// Long TXT values must be entered as several quoted strings on most DNS hosts.
|
|
33
|
+
if (type === 'TXT' && new TextEncoder().encode(value).length > 255)
|
|
34
|
+
return chunkTxt({ value }).map(chunk => `"${chunk}"`).join(' ');
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
function rowsFor(record, action, zone) {
|
|
38
|
+
const values = record.values;
|
|
39
|
+
return values.map(value => {
|
|
40
|
+
const input = { value };
|
|
41
|
+
return {
|
|
42
|
+
action, type: record.type, name: record.name, host: relativeHost({ name: record.name, zone }),
|
|
43
|
+
value: valueText(record.type, value), ttl: record.ttl,
|
|
44
|
+
...(isMxValue(input) ? { priority: input.value.priority } : {}),
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const ACTION = { create: 'add', update: 'change', delete: 'remove' };
|
|
49
|
+
function changeRows(change, zone) {
|
|
50
|
+
const record = (change.after ?? change.before);
|
|
51
|
+
return rowsFor(record, ACTION[change.op], zone);
|
|
52
|
+
}
|
|
53
|
+
/** When the plan could not be computed, show what is required so a person can still act. */
|
|
54
|
+
function requirementRows(requirements, zone) {
|
|
55
|
+
return requirements.flatMap(requirement => requirement.records).flatMap(record => {
|
|
56
|
+
const value = requirementValue({ record });
|
|
57
|
+
if (value === undefined)
|
|
58
|
+
return [];
|
|
59
|
+
return rowsFor(buildRecord({ name: normalizeDnsName({ name: record.name }), type: record.type, ttl: record.ttl ?? DEFAULT_DNS_TTL, values: [value] }), 'add', zone);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function instructionNotes(plan, rows) {
|
|
63
|
+
const notes = [`Make these changes at the DNS host that serves ${plan.zone} (check its NS records if unsure).`];
|
|
64
|
+
if (rows.some(row => row.host === '@' && (row.type === 'CNAME' || row.type === 'ALIAS'))) {
|
|
65
|
+
notes.push('At the zone apex many DNS hosts refuse a CNAME: use their ALIAS/ANAME/flattening option, or A/AAAA records.');
|
|
66
|
+
}
|
|
67
|
+
if (rows.some(row => row.action === 'change'))
|
|
68
|
+
notes.push('"change" rows list the complete final set of values for that name and type.');
|
|
69
|
+
if (plan.inventory !== 'complete')
|
|
70
|
+
notes.push(`The existing records could not be read; first check ${plan.zone} for records at these names that conflict.`);
|
|
71
|
+
for (const blocker of plan.blockers)
|
|
72
|
+
notes.push(['Blocked:', blocker.message, ...(blocker.suggestion ? [blocker.suggestion] : [])].join(' '));
|
|
73
|
+
return notes;
|
|
74
|
+
}
|
|
75
|
+
/** Copy-pasteable rows (type/name/value/TTL/priority) for a plan. */
|
|
76
|
+
export function renderDnsInstructions(required, optional = {}) {
|
|
77
|
+
const { plan } = required;
|
|
78
|
+
const fallback = plan.inventory !== 'complete' && optional.requirements !== undefined;
|
|
79
|
+
const rows = fallback ? requirementRows(optional.requirements, plan.zone) : plan.changes.flatMap(change => changeRows(change, plan.zone));
|
|
80
|
+
return { zone: plan.zone, rows, notes: instructionNotes(plan, rows) };
|
|
81
|
+
}
|
|
82
|
+
async function lookup(resolver, required) {
|
|
83
|
+
const result = await settlePort({ call: () => resolver.query(required) });
|
|
84
|
+
if (result.status === 'rejected' && result.error.code === 'not_found')
|
|
85
|
+
return { kind: 'none' };
|
|
86
|
+
if (result.status !== 'ok')
|
|
87
|
+
return { kind: 'unknown' };
|
|
88
|
+
const parsed = result.value.answers.map(text => parseAnswerValue({ type: required.type, text }));
|
|
89
|
+
// An answer we cannot represent is data we would silently drop from the plan: not known.
|
|
90
|
+
if (parsed.includes(undefined))
|
|
91
|
+
return { kind: 'unknown' };
|
|
92
|
+
const values = parsed;
|
|
93
|
+
if (values.length === 0)
|
|
94
|
+
return { kind: 'none' };
|
|
95
|
+
return { kind: 'found', record: buildRecord({ name: required.name, type: required.type, ttl: result.value.ttl ?? DEFAULT_DNS_TTL, values }) };
|
|
96
|
+
}
|
|
97
|
+
/** Candidate zones for a host name, most specific first, never a bare TLD or a public suffix. */
|
|
98
|
+
function zoneCandidates(hostname, isPublicSuffix) {
|
|
99
|
+
const labels = normalizeDnsName({ name: hostname }).split('.');
|
|
100
|
+
return labels.slice(0, -1).map((_, index) => labels.slice(index).join('.')).filter(name => !isPublicSuffix?.({ name }));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Create the manual provider over an authoritative resolver.
|
|
104
|
+
* @param required.resolver - Queries the zone's own nameservers (see {@link AuthoritativeDnsPort}).
|
|
105
|
+
*/
|
|
106
|
+
export function createManualDnsProvider(required, optional = {}) {
|
|
107
|
+
const { resolver } = required;
|
|
108
|
+
return {
|
|
109
|
+
id: MANUAL_DNS_PROVIDER_ID,
|
|
110
|
+
label: optional.label ?? 'Manual (any DNS host)',
|
|
111
|
+
credentialKeys: [],
|
|
112
|
+
capabilities: { automatic: false, recordTypes: ['A', 'AAAA', 'CNAME', 'ALIAS', 'TXT', 'MX', 'CAA', 'NS', 'SRV'], apexFlattening: false, proxy: false },
|
|
113
|
+
// The most specific name with its own NS delegation is the zone, so a delegated subzone
|
|
114
|
+
// (`dev.example.com` served elsewhere) is found before its parent.
|
|
115
|
+
async findZone(_ctx, { hostname }) {
|
|
116
|
+
for (const zone of zoneCandidates(hostname, optional.isPublicSuffix)) {
|
|
117
|
+
const result = await settlePort({ call: () => resolver.queryNs({ zone }) });
|
|
118
|
+
if (result.status === 'unknown')
|
|
119
|
+
return result;
|
|
120
|
+
if (result.status === 'ok' && result.value.length > 0)
|
|
121
|
+
return providerOk({ value: { zone, ref: zone } });
|
|
122
|
+
}
|
|
123
|
+
return providerOk({ value: null });
|
|
124
|
+
},
|
|
125
|
+
// Complete only for the requested names and the planner's types; any unread answer makes the
|
|
126
|
+
// whole inventory unknown, which the planner turns into zero changes.
|
|
127
|
+
async listRecords(_ctx, { zoneRef, names }) {
|
|
128
|
+
const ns = await settlePort({ call: () => resolver.queryNs({ zone: zoneRef }) });
|
|
129
|
+
const nameserver = ns.status === 'ok' ? ns.value[0] : undefined;
|
|
130
|
+
if (nameserver === undefined)
|
|
131
|
+
return providerOk({ value: { records: [], inventory: 'unknown' } });
|
|
132
|
+
const lookups = await Promise.all(names.flatMap(name => QUERIED_TYPES.map(type => lookup(resolver, { name: normalizeDnsName({ name }), type, nameserver }))));
|
|
133
|
+
const records = lookups.flatMap(found => (found.kind === 'found' ? [found.record] : []));
|
|
134
|
+
const inventory = lookups.some(found => found.kind === 'unknown') ? 'unknown' : 'complete';
|
|
135
|
+
return providerOk({ value: { records, inventory } });
|
|
136
|
+
},
|
|
137
|
+
instructions: (instructionsRequired, instructionsOptional = {}) => renderDnsInstructions(instructionsRequired, instructionsOptional),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=manual.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@jini-ai/devops/dns/node` — the `node:dns` authoritative resolver for the DNS kernel, kept off
|
|
3
|
+
* the pure `./dns` entry so planning and verification never pull in sockets.
|
|
4
|
+
*/
|
|
5
|
+
export * from './resolver.js';
|
|
6
|
+
export * from './udp.js';
|
|
7
|
+
export * from './wire.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@jini-ai/devops/dns/node` — the `node:dns` authoritative resolver for the DNS kernel, kept off
|
|
3
|
+
* the pure `./dns` entry so planning and verification never pull in sockets.
|
|
4
|
+
*/
|
|
5
|
+
export * from './resolver.js';
|
|
6
|
+
export * from './udp.js';
|
|
7
|
+
export * from './wire.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Resolver } from 'node:dns/promises';
|
|
2
|
+
import type { AuthoritativeDnsPort } from '../contract.js';
|
|
3
|
+
import { type DnsExchange } from './udp.js';
|
|
4
|
+
/** The `node:dns/promises` Resolver surface this adapter uses; tests inject a fake. */
|
|
5
|
+
export type DnsResolverLike = Pick<Resolver, 'setServers' | 'resolve4' | 'resolve6' | 'resolveCname' | 'resolveTxt' | 'resolveMx' | 'resolveCaa' | 'resolveNs' | 'resolveSrv'>;
|
|
6
|
+
/** One c-ares try per query: a slow server is `unknown` quickly and the verifier retries later. */
|
|
7
|
+
export declare const AUTHORITATIVE_DNS_TIMEOUT_MS = 5000;
|
|
8
|
+
export interface NodeAuthoritativeDnsResolverOptions {
|
|
9
|
+
/** Resolver factory (default `new Resolver(options)`). */
|
|
10
|
+
readonly createResolver?: (options: {
|
|
11
|
+
timeout: number;
|
|
12
|
+
tries: number;
|
|
13
|
+
}) => DnsResolverLike;
|
|
14
|
+
/** Recursive servers for nameserver-address and parent-server reads; default the system's. */
|
|
15
|
+
readonly bootstrapServers?: string[];
|
|
16
|
+
/** Per-query timeout; default {@link AUTHORITATIVE_DNS_TIMEOUT_MS}. */
|
|
17
|
+
readonly timeoutMs?: number;
|
|
18
|
+
/** Raw DNS exchange for the parent delegation read; default UDP port 53. */
|
|
19
|
+
readonly exchange?: DnsExchange;
|
|
20
|
+
/** Query id source (16-bit); default a CSPRNG, so an off-path reply cannot be guessed. */
|
|
21
|
+
readonly randomId?: () => number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Build the adapter.
|
|
25
|
+
* @param required.isPublicAddress - Host address policy: only addresses it accepts are queried.
|
|
26
|
+
* @complexity O(1) setup; each `query` is ≤ 3 DNS round trips (NS address A + AAAA, then the
|
|
27
|
+
* record); each `queryNs` walks up to the closest enclosing zone, then asks its servers in turn.
|
|
28
|
+
* @example createNodeAuthoritativeDnsResolver({ isPublicAddress: ({ address }) => policy(address) })
|
|
29
|
+
*/
|
|
30
|
+
export declare function createNodeAuthoritativeDnsResolver(required: {
|
|
31
|
+
readonly isPublicAddress: (required: {
|
|
32
|
+
readonly address: string;
|
|
33
|
+
}) => boolean;
|
|
34
|
+
}, optional?: NodeAuthoritativeDnsResolverOptions): AuthoritativeDnsPort;
|
|
35
|
+
//# sourceMappingURL=resolver.d.ts.map
|