@formless63/dns-plan 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +21 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/diff.d.ts +69 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +139 -0
- package/dist/diff.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/records.d.ts +88 -0
- package/dist/records.d.ts.map +1 -0
- package/dist/records.js +58 -0
- package/dist/records.js.map +1 -0
- package/package.json +39 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 formless63
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @formless63/dns-plan
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A provider-neutral DNS record model with a diff and planner that will not touch records it does not own.
|
|
4
|
+
No dependencies, no I/O.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
const diff = diffRecords(desired, observed); // missing, modified, unexpected, unchanged
|
|
8
|
+
const plan = planOperations(diff, { remove }); // creates, updates, explicit removals
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
- **Unexpected records are never deleted.** Deletes come only from `remove`.
|
|
12
|
+
- **Another record is never overwritten by guesswork.** A desired TXT beside an unrelated verification TXT is
|
|
13
|
+
added, not swapped in. Replacement needs certainty: the same `recordId`, a single-valued type, one address on
|
|
14
|
+
each side, or the same TXT version tag. `pairing: "positional"` opts out.
|
|
15
|
+
- **`managed: false`** records are compared and reported, never written.
|
|
16
|
+
- Equivalent spellings (case, trailing dots, IPv6 forms, quoted TXT) are not drift.
|
|
17
|
+
|
|
18
|
+
Because an unmatched desired record is added, check for a second SPF or DMARC record when you take over an
|
|
19
|
+
existing zone; those two are paired by version tag.
|
|
20
|
+
|
|
21
|
+
Implement `DnsProvider` to add a host. Names are zone-relative (`@`, `*`, `www`); `ttlSeconds: null` means the
|
|
22
|
+
provider default.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"7.0.2","root":[[64,66]],"packageJsons":["../package.json"],"fileNames":["lib.es5.d.ts","lib.es2015.d.ts","lib.es2016.d.ts","lib.es2017.d.ts","lib.es2018.d.ts","lib.es2019.d.ts","lib.es2020.d.ts","lib.es2021.d.ts","lib.es2022.d.ts","lib.es2023.d.ts","lib.dom.d.ts","lib.dom.iterable.d.ts","lib.es2015.core.d.ts","lib.es2015.collection.d.ts","lib.es2015.generator.d.ts","lib.es2015.iterable.d.ts","lib.es2015.promise.d.ts","lib.es2015.proxy.d.ts","lib.es2015.reflect.d.ts","lib.es2015.symbol.d.ts","lib.es2015.symbol.wellknown.d.ts","lib.es2016.array.include.d.ts","lib.es2016.intl.d.ts","lib.es2017.arraybuffer.d.ts","lib.es2017.date.d.ts","lib.es2017.object.d.ts","lib.es2017.sharedmemory.d.ts","lib.es2017.string.d.ts","lib.es2017.intl.d.ts","lib.es2017.typedarrays.d.ts","lib.es2018.asyncgenerator.d.ts","lib.es2018.asynciterable.d.ts","lib.es2018.intl.d.ts","lib.es2018.promise.d.ts","lib.es2018.regexp.d.ts","lib.es2019.array.d.ts","lib.es2019.object.d.ts","lib.es2019.string.d.ts","lib.es2019.symbol.d.ts","lib.es2019.intl.d.ts","lib.es2020.bigint.d.ts","lib.es2020.date.d.ts","lib.es2020.promise.d.ts","lib.es2020.sharedmemory.d.ts","lib.es2020.string.d.ts","lib.es2020.symbol.wellknown.d.ts","lib.es2020.intl.d.ts","lib.es2020.number.d.ts","lib.es2021.promise.d.ts","lib.es2021.string.d.ts","lib.es2021.weakref.d.ts","lib.es2021.intl.d.ts","lib.es2022.array.d.ts","lib.es2022.error.d.ts","lib.es2022.intl.d.ts","lib.es2022.object.d.ts","lib.es2022.string.d.ts","lib.es2022.regexp.d.ts","lib.es2023.array.d.ts","lib.es2023.collection.d.ts","lib.es2023.intl.d.ts","lib.decorators.d.ts","lib.decorators.legacy.d.ts","../src/records.ts","../src/diff.ts","../src/index.ts"],"fileInfos":[{"version":"16934abaab7026ac114da441aabea1a0","affectsGlobalScope":true,"impliedNodeFormat":1},"d4306fb2e47f74835e8674ffac07d76f","e437c5c1302869326c3bb93da85bbbcf","e4324975a566567b21d350615f1fc6ac","333b1b9a2a9ac3b8497dba5c63b5ba50","6cffacd662b6eb5fa7a36aa2ea366bfa","b4c34f9c23304dbef2d23698637ed638","e5cb86a5fc491796ecd1d2dd348d208f","feb6c6fb19cdb246a5d8acb36a6901c7","9443a7f109277ffaa79d893ed2549995",{"version":"aae8996e8b5684814785a42cbbefcd79","affectsGlobalScope":true,"impliedNodeFormat":1},"abad6dd56cc8caf095c165df8124d237",{"version":"926204c28cd3d073865348473ae28d2e","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"f25e42c801b2cb3cf2b39792006a9beb","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"6344b55f26a4e81d9608777dbfb877dd","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"3c0ed28e53d3695b363e256ec1c023fd","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4c2761daba7f17141c25baa0821ac5da","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b87656acabd63e69379ff6ffcfe52fc7","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"597469522da047a5af5222cc6989f405","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"1708ea4d34dc37fadadc63ca01127e80","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"55d97a8c6fbf34a30450a7b1e5f7a298","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"0ee05eb59426d33e374226d8dcfa708b","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"e347c14030993906efcfbb88915b6a05","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b0231263857c9b6a03641acdc9280ceb","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"3b15c4a83b598cacb4067676e6f0abed","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b417d97b7934cef63b1889abec0bbfbf","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"09a6cf4032ebba60ce22a501e663f881","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"2b056277dd138e8f5650fc04e20eaa8d","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"e22cc07e3f3cc242ba52fa3f8ea1fc58","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"2c45da767a1bfbb220848df1bc4029e4","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b44c3e0fbaf2130cdcf6ac38b120ffa1","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b612fb5cf8e5d964b92063a75207632a","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"02705151a5e1551b9162a9ed8ab763f7","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"41025e398be9215d32e4337335da8f0b","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"52684c2b1f353a5538e4f275182a54cd","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"6dedb6a4f90d1df3a6fbe5693e44886c","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"ca3f36fe3562c07e0f0d71c2bebd3f6d","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"409974d6129befbb8226ddd1c6558568","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4d9cfde2a1ae1b4925f1f9bc10848e5d","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"7e1daecc66dd564144e3bb1a0266b5fd","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"a8e1d9bb35fd0637f2f9fd2b2a54f2ec","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4f168501772a6543182765bfd5f2fbfe","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"a19c80aad1b2162103496f5ba293a732","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b69afa63cd5d059851c78adb2856ee09","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"ae2fc5d954e9b0f5feee3d481b953c27","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"1cfd3091a071d8b6feec15277643bafe","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"1da2c1f258970fd3cc91184f69e91a9d","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"a0d87491913d843139e0c993650a3235","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4ef72aa378127e7b7abba915b0110b1e","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"3ec74c6a7d4463f0254db3a74cf75646","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"84c2bdfa470d075526cce6322d81b0b6","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"0b3844c2b8c73e4e1ab91431411cad11","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4fc71cf4a15b8d99675a31df77f26e07","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"d1b49564ddaeca3df5b6dbae925d2242","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"6a25be566d60ccfc2d6e8b7bfdeefa83","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"8a20e27646985dfd58c57ca6566553dd","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"9969f02ad3cdcbf4f709405cda44167f","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"9c9be4792a7a4f42c15ae7360bf28779","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"8cf777fe00349b71ee9c4b6f3fe7fd19","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"74f96bc192530c9723f572bfff3d3078","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"1df91c56b25955c56387426f378173c5","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"f64453cbf9671f28158677fa5c43967a","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"33f317af5428801f944a478d2c1e38e5","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"0a010ad077c95d88b71bcd1042fa22a8","signature":"a644b5302762e708d5905f403b26d444","impliedNodeFormat":99},{"version":"97c7b7ccf47c315cd2bdbe1416ccbb94","signature":"351f2624cf1dab8db3348272751e57d0","impliedNodeFormat":99},{"version":"f49517e6ddc649cf6785af18423804e0","impliedNodeFormat":99}],"fileIdsList":[[64],[64,65]],"options":{"allowImportingTsExtensions":true,"composite":true,"declaration":true,"declarationMap":true,"erasableSyntaxOnly":true,"exactOptionalPropertyTypes":true,"module":199,"noUncheckedIndexedAccess":true,"outDir":"./","rewriteRelativeImportExtensions":true,"rootDir":"../src","skipLibCheck":true,"strict":true,"sourceMap":true,"target":10,"tsBuildInfoFile":"./.tsbuildinfo","verbatimModuleSyntax":true},"referencedMap":[[65,1],[66,2]],"latestChangedDtsFile":"./index.d.ts"}
|
package/dist/diff.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type DnsOperation, type DnsRecord, type ObservedRecord } from './records.ts';
|
|
2
|
+
/** A record that should exist. */
|
|
3
|
+
export interface DesiredRecord extends DnsRecord {
|
|
4
|
+
/** `false` means compare it but never write it (a hand-maintained record). Default true. */
|
|
5
|
+
managed?: boolean;
|
|
6
|
+
/** The provider id last seen for this record, when known. Pairs it exactly. */
|
|
7
|
+
recordId?: string | null;
|
|
8
|
+
}
|
|
9
|
+
export type RecordAttribute = 'content' | 'proxied' | 'ttlSeconds' | 'priority';
|
|
10
|
+
export interface MissingRecord<D extends DesiredRecord = DesiredRecord> {
|
|
11
|
+
kind: 'missing';
|
|
12
|
+
desired: D;
|
|
13
|
+
}
|
|
14
|
+
export interface ModifiedRecord<D extends DesiredRecord = DesiredRecord> {
|
|
15
|
+
kind: 'modified';
|
|
16
|
+
desired: D;
|
|
17
|
+
observed: ObservedRecord;
|
|
18
|
+
changed: RecordAttribute[];
|
|
19
|
+
}
|
|
20
|
+
export interface UnexpectedRecord {
|
|
21
|
+
kind: 'unexpected';
|
|
22
|
+
observed: ObservedRecord;
|
|
23
|
+
}
|
|
24
|
+
export interface UnchangedRecord<D extends DesiredRecord = DesiredRecord> {
|
|
25
|
+
kind: 'unchanged';
|
|
26
|
+
desired: D;
|
|
27
|
+
observed: ObservedRecord;
|
|
28
|
+
}
|
|
29
|
+
export interface DnsDiff<D extends DesiredRecord = DesiredRecord> {
|
|
30
|
+
missing: MissingRecord<D>[];
|
|
31
|
+
modified: ModifiedRecord<D>[];
|
|
32
|
+
/** At the provider but not described. Never deleted or rewritten by a plan. */
|
|
33
|
+
unexpected: UnexpectedRecord[];
|
|
34
|
+
unchanged: UnchangedRecord<D>[];
|
|
35
|
+
}
|
|
36
|
+
export interface DiffOptions {
|
|
37
|
+
/**
|
|
38
|
+
* How a desired record with new content finds the record it replaces.
|
|
39
|
+
*
|
|
40
|
+
* `safe` (default) pairs only where the match is certain: the same recordId,
|
|
41
|
+
* single-valued types, one address each side, or the same TXT version tag
|
|
42
|
+
* (`v=spf1`, `v=DMARC1`). Otherwise it adds a record and reports the other as
|
|
43
|
+
* unexpected, so somebody else's record is never overwritten.
|
|
44
|
+
*
|
|
45
|
+
* `positional` pairs leftovers of a (type, name) in order. Use it only when
|
|
46
|
+
* the desired set is known to be complete for every name it mentions.
|
|
47
|
+
*/
|
|
48
|
+
pairing?: 'safe' | 'positional';
|
|
49
|
+
normalize?: (type: string, content: string) => string;
|
|
50
|
+
}
|
|
51
|
+
/** Compares desired records with observed ones. Pure: no network, no clock. */
|
|
52
|
+
export declare function diffRecords<D extends DesiredRecord>(desired: readonly D[], observed: readonly ObservedRecord[], options?: DiffOptions): DnsDiff<D>;
|
|
53
|
+
export interface PlanOptions {
|
|
54
|
+
/** Records to remove, each as it was observed. The only source of deletes. */
|
|
55
|
+
remove?: readonly ObservedRecord[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The operations a diff implies: creates, then updates, then explicit removals.
|
|
59
|
+
* Unmanaged records and unexpected records never produce an operation. A
|
|
60
|
+
* removal that would block a create (a CNAME cannot coexist with other records
|
|
61
|
+
* at its name) comes first.
|
|
62
|
+
*/
|
|
63
|
+
export declare function planOperations(diff: DnsDiff, { remove }?: PlanOptions): DnsOperation[];
|
|
64
|
+
/**
|
|
65
|
+
* Throws if a plan deletes a record the diff found unexpected, other than those
|
|
66
|
+
* the caller explicitly listed in `remove`. A guard for hand-assembled plans.
|
|
67
|
+
*/
|
|
68
|
+
export declare function assertNoUnexpectedDeletes(diff: DnsDiff, operations: readonly DnsOperation[], { remove }?: PlanOptions): void;
|
|
69
|
+
//# sourceMappingURL=diff.d.ts.map
|
|
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AAC;IAC/B,SAAS,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;CACjC;AAED,MAAM,WAAW,WAAW;IAC1B;;;;;;;;;;OAUG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IAChC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CACvD;AAsBD,+EAA+E;AAC/E,wBAAgB,WAAW,CAAC,CAAC,SAAS,aAAa,EACjD,OAAO,EAAE,SAAS,CAAC,EAAE,EACrB,QAAQ,EAAE,SAAS,cAAc,EAAE,EACnC,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,CAAC,CAAC,CAkEZ;AAED,MAAM,WAAW,WAAW;IAC1B,8EAA8E;IAC9E,MAAM,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;CACpC;AAWD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,MAAW,EAAE,GAAE,WAAgB,GAAG,YAAY,EAAE,CAuB/F;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,OAAO,EACb,UAAU,EAAE,SAAS,YAAY,EAAE,EACnC,EAAE,MAAW,EAAE,GAAE,WAAgB,GAChC,IAAI,CAQN"}
|
package/dist/diff.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { normalizeContent } from './records.js';
|
|
2
|
+
const SINGLE_VALUED = new Set(['CNAME', 'SOA', 'ALIAS', 'ANAME', 'DNAME']);
|
|
3
|
+
const ADDRESS = new Set(['A', 'AAAA']);
|
|
4
|
+
const keyOf = (record) => `${record.type.toUpperCase()} ${record.name.trim().toLowerCase().replace(/\.$/, '')}`;
|
|
5
|
+
function txtTag(content) {
|
|
6
|
+
return /^(v=[A-Za-z0-9]+)/.exec(content)?.[1]?.toLowerCase() ?? null;
|
|
7
|
+
}
|
|
8
|
+
function groupBy(items, key) {
|
|
9
|
+
const groups = new Map();
|
|
10
|
+
for (const item of items) {
|
|
11
|
+
const group = groups.get(key(item));
|
|
12
|
+
if (group)
|
|
13
|
+
group.push(item);
|
|
14
|
+
else
|
|
15
|
+
groups.set(key(item), [item]);
|
|
16
|
+
}
|
|
17
|
+
return groups;
|
|
18
|
+
}
|
|
19
|
+
/** Compares desired records with observed ones. Pure: no network, no clock. */
|
|
20
|
+
export function diffRecords(desired, observed, options = {}) {
|
|
21
|
+
const normalize = options.normalize ?? normalizeContent;
|
|
22
|
+
const pairing = options.pairing ?? 'safe';
|
|
23
|
+
const diff = { missing: [], modified: [], unexpected: [], unchanged: [] };
|
|
24
|
+
const pair = (want, have) => {
|
|
25
|
+
const changed = [];
|
|
26
|
+
if (normalize(want.type, want.content) !== normalize(have.type, have.content))
|
|
27
|
+
changed.push('content');
|
|
28
|
+
if (want.proxied !== have.proxied)
|
|
29
|
+
changed.push('proxied');
|
|
30
|
+
if (want.ttlSeconds !== have.ttlSeconds)
|
|
31
|
+
changed.push('ttlSeconds');
|
|
32
|
+
if ((want.priority ?? null) !== (have.priority ?? null))
|
|
33
|
+
changed.push('priority');
|
|
34
|
+
if (changed.length === 0)
|
|
35
|
+
diff.unchanged.push({ kind: 'unchanged', desired: want, observed: have });
|
|
36
|
+
else
|
|
37
|
+
diff.modified.push({ kind: 'modified', desired: want, observed: have, changed });
|
|
38
|
+
};
|
|
39
|
+
const observedGroups = groupBy(observed, keyOf);
|
|
40
|
+
for (const [key, wants] of groupBy(desired, keyOf)) {
|
|
41
|
+
const pool = [...(observedGroups.get(key) ?? [])];
|
|
42
|
+
observedGroups.delete(key);
|
|
43
|
+
let open = [...wants];
|
|
44
|
+
const match = (find) => {
|
|
45
|
+
open = open.filter((want) => {
|
|
46
|
+
const index = find(want);
|
|
47
|
+
if (index < 0)
|
|
48
|
+
return true;
|
|
49
|
+
pair(want, pool.splice(index, 1)[0]);
|
|
50
|
+
return false;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
// Equal content (and priority, for repeated targets) first, so an unchanged
|
|
54
|
+
// member of a multi-valued set never reads as drift.
|
|
55
|
+
const sameContent = (want, have) => normalize(want.type, want.content) === normalize(have.type, have.content);
|
|
56
|
+
match((want) => pool.findIndex((have) => sameContent(want, have) && (want.priority ?? null) === (have.priority ?? null)));
|
|
57
|
+
match((want) => pool.findIndex((have) => sameContent(want, have)));
|
|
58
|
+
match((want) => (want.recordId ? pool.findIndex((have) => have.recordId === want.recordId) : -1));
|
|
59
|
+
const type = key.split(' ')[0];
|
|
60
|
+
const managed = (want) => want.managed !== false;
|
|
61
|
+
if (pairing === 'positional') {
|
|
62
|
+
match(() => (pool.length > 0 ? 0 : -1));
|
|
63
|
+
}
|
|
64
|
+
else if (SINGLE_VALUED.has(type)) {
|
|
65
|
+
match((want) => (managed(want) && pool.length > 0 ? 0 : -1));
|
|
66
|
+
}
|
|
67
|
+
else if (ADDRESS.has(type) && wants.length === 1 && open.length === 1 && pool.length === 1) {
|
|
68
|
+
match((want) => (managed(want) ? 0 : -1));
|
|
69
|
+
}
|
|
70
|
+
else if (type === 'TXT') {
|
|
71
|
+
match((want) => {
|
|
72
|
+
const tag = txtTag(normalize(want.type, want.content));
|
|
73
|
+
if (tag === null || !managed(want))
|
|
74
|
+
return -1;
|
|
75
|
+
return pool.findIndex((have) => txtTag(normalize(have.type, have.content)) === tag);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
// Unmanaged records are never written, so claiming any leftover is harmless
|
|
79
|
+
// and reports a hand edit as a change rather than as two findings.
|
|
80
|
+
match((want) => (!managed(want) && pool.length > 0 ? 0 : -1));
|
|
81
|
+
for (const want of open)
|
|
82
|
+
diff.missing.push({ kind: 'missing', desired: want });
|
|
83
|
+
for (const have of pool)
|
|
84
|
+
diff.unexpected.push({ kind: 'unexpected', observed: have });
|
|
85
|
+
}
|
|
86
|
+
for (const group of observedGroups.values()) {
|
|
87
|
+
for (const have of group)
|
|
88
|
+
diff.unexpected.push({ kind: 'unexpected', observed: have });
|
|
89
|
+
}
|
|
90
|
+
return diff;
|
|
91
|
+
}
|
|
92
|
+
const payload = (record) => ({
|
|
93
|
+
type: record.type,
|
|
94
|
+
name: record.name,
|
|
95
|
+
content: record.content,
|
|
96
|
+
ttlSeconds: record.ttlSeconds,
|
|
97
|
+
priority: record.priority,
|
|
98
|
+
proxied: record.proxied
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* The operations a diff implies: creates, then updates, then explicit removals.
|
|
102
|
+
* Unmanaged records and unexpected records never produce an operation. A
|
|
103
|
+
* removal that would block a create (a CNAME cannot coexist with other records
|
|
104
|
+
* at its name) comes first.
|
|
105
|
+
*/
|
|
106
|
+
export function planOperations(diff, { remove = [] } = {}) {
|
|
107
|
+
const creates = diff.missing
|
|
108
|
+
.filter(({ desired }) => desired.managed !== false)
|
|
109
|
+
.map(({ desired }) => ({ kind: 'create', record: payload(desired) }));
|
|
110
|
+
const updates = diff.modified
|
|
111
|
+
.filter(({ desired }) => desired.managed !== false)
|
|
112
|
+
.map(({ desired, observed }) => ({
|
|
113
|
+
kind: 'update',
|
|
114
|
+
recordId: observed.recordId,
|
|
115
|
+
record: payload(desired)
|
|
116
|
+
}));
|
|
117
|
+
const blocking = [];
|
|
118
|
+
const trailing = [];
|
|
119
|
+
for (const { recordId, type, name, content } of remove) {
|
|
120
|
+
const blocks = creates.some(({ record }) => record.name === name && record.type !== type && (record.type === 'CNAME' || type === 'CNAME'));
|
|
121
|
+
(blocks ? blocking : trailing).push({ kind: 'delete', recordId, record: { type, name, content } });
|
|
122
|
+
}
|
|
123
|
+
return [...blocking, ...creates, ...updates, ...trailing];
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Throws if a plan deletes a record the diff found unexpected, other than those
|
|
127
|
+
* the caller explicitly listed in `remove`. A guard for hand-assembled plans.
|
|
128
|
+
*/
|
|
129
|
+
export function assertNoUnexpectedDeletes(diff, operations, { remove = [] } = {}) {
|
|
130
|
+
const unexpected = new Set(diff.unexpected.map(({ observed }) => observed.recordId));
|
|
131
|
+
for (const { recordId } of remove)
|
|
132
|
+
unexpected.delete(recordId);
|
|
133
|
+
for (const operation of operations) {
|
|
134
|
+
if (operation.kind === 'delete' && unexpected.has(operation.recordId)) {
|
|
135
|
+
throw new Error('refusing to delete an unexpected provider record');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=diff.js.map
|
package/dist/diff.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA0D,MAAM,cAAc,CAAC;AAwDxG,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AAC3E,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;AAEvC,MAAM,KAAK,GAAG,CAAC,MAAiB,EAAU,EAAE,CAC1C,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC;AAExF,SAAS,MAAM,CAAC,OAAe;IAC7B,OAAO,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,IAAI,CAAC;AACvE,CAAC;AAED,SAAS,OAAO,CAAI,KAAmB,EAAE,GAAwB;IAC/D,MAAM,MAAM,GAAG,IAAI,GAAG,EAAe,CAAC;IACtC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,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EjC,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;IACrF,KAAK,MAAM,EAAE,QAAQ,EAAE,IAAI,MAAM;QAAE,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/D,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,SAAS,CAAC,IAAI,KAAK,QAAQ,IAAI,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtE,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** A DNS record in provider-neutral form. */
|
|
2
|
+
export interface DnsRecord {
|
|
3
|
+
type: string;
|
|
4
|
+
/** Zone-relative: `@`, `*`, `www`, `key1._domainkey`. */
|
|
5
|
+
name: string;
|
|
6
|
+
content: string;
|
|
7
|
+
/** `null` means the provider's default. */
|
|
8
|
+
ttlSeconds: number | null;
|
|
9
|
+
priority: number | null;
|
|
10
|
+
/** The provider answers for the name and forwards to the origin. */
|
|
11
|
+
proxied: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** A record as it exists at a provider. */
|
|
14
|
+
export interface ObservedRecord extends DnsRecord {
|
|
15
|
+
recordId: string;
|
|
16
|
+
proxiable: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface DnsZone {
|
|
19
|
+
zoneId: string;
|
|
20
|
+
name: string;
|
|
21
|
+
/** The provider's own status word, verbatim. */
|
|
22
|
+
status: string;
|
|
23
|
+
nameservers: string[];
|
|
24
|
+
}
|
|
25
|
+
export type DnsOperation = {
|
|
26
|
+
kind: 'create';
|
|
27
|
+
record: DnsRecord;
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'update';
|
|
30
|
+
recordId: string;
|
|
31
|
+
record: DnsRecord;
|
|
32
|
+
} | {
|
|
33
|
+
kind: 'delete';
|
|
34
|
+
recordId: string;
|
|
35
|
+
record: Pick<DnsRecord, 'type' | 'name' | 'content'>;
|
|
36
|
+
};
|
|
37
|
+
export interface DnsOperationResult {
|
|
38
|
+
kind: DnsOperation['kind'];
|
|
39
|
+
type: string;
|
|
40
|
+
name: string;
|
|
41
|
+
/** The `already_*` outcomes let a retried plan converge instead of failing. */
|
|
42
|
+
status: 'applied' | 'already_present' | 'already_absent';
|
|
43
|
+
recordId: string | null;
|
|
44
|
+
}
|
|
45
|
+
export interface DnsCapabilities {
|
|
46
|
+
proxying: boolean;
|
|
47
|
+
proxiableTypes: readonly string[];
|
|
48
|
+
proxiedWildcards: boolean;
|
|
49
|
+
wildcardRecords: boolean;
|
|
50
|
+
automaticTtl: boolean;
|
|
51
|
+
minTtlSeconds: number;
|
|
52
|
+
maxTtlSeconds: number;
|
|
53
|
+
}
|
|
54
|
+
export interface ZoneRef {
|
|
55
|
+
zoneId: string;
|
|
56
|
+
zoneName: string;
|
|
57
|
+
}
|
|
58
|
+
export interface RequestOptions {
|
|
59
|
+
signal?: AbortSignal;
|
|
60
|
+
}
|
|
61
|
+
/** What a DNS host adapter implements. */
|
|
62
|
+
export interface DnsProvider {
|
|
63
|
+
readonly id: string;
|
|
64
|
+
readonly label: string;
|
|
65
|
+
capabilities(): DnsCapabilities;
|
|
66
|
+
findZone(name: string, options?: RequestOptions): Promise<DnsZone | null>;
|
|
67
|
+
/** Every record in the zone, or an error: never a silently truncated list. */
|
|
68
|
+
listRecords(zone: ZoneRef, options?: RequestOptions): Promise<ObservedRecord[]>;
|
|
69
|
+
/** Applies in order; rejects at the first failure. See `DnsApplyError`. */
|
|
70
|
+
apply(zone: ZoneRef, operations: readonly DnsOperation[], options?: RequestOptions): Promise<DnsOperationResult[]>;
|
|
71
|
+
}
|
|
72
|
+
/** The part of a plan that succeeded before `cause` stopped it. */
|
|
73
|
+
export declare class DnsApplyError extends Error {
|
|
74
|
+
readonly completed: readonly DnsOperationResult[];
|
|
75
|
+
readonly failed: DnsOperation;
|
|
76
|
+
constructor(completed: readonly DnsOperationResult[], failed: DnsOperation, cause: unknown);
|
|
77
|
+
}
|
|
78
|
+
/** A zone-relative name as a fully qualified one. Already-qualified names pass through. */
|
|
79
|
+
export declare function toFqdn(name: string, zoneName: string): string;
|
|
80
|
+
/** A fully qualified name as a zone-relative one. */
|
|
81
|
+
export declare function toRelativeName(name: string, zoneName: string): string;
|
|
82
|
+
/**
|
|
83
|
+
* Content in a comparable form: host names lose case and the trailing dot, and
|
|
84
|
+
* IPv6 addresses are compressed. Without this a correct zone can report drift
|
|
85
|
+
* forever. TXT content is compared without surrounding quotes.
|
|
86
|
+
*/
|
|
87
|
+
export declare function normalizeContent(type: string, content: string): string;
|
|
88
|
+
//# sourceMappingURL=records.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../src/records.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAA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EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAkBtE"}
|
package/dist/records.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** The part of a plan that succeeded before `cause` stopped it. */
|
|
2
|
+
export class DnsApplyError extends Error {
|
|
3
|
+
completed;
|
|
4
|
+
failed;
|
|
5
|
+
constructor(completed, failed, cause) {
|
|
6
|
+
super(`DNS ${failed.kind} of ${failed.record.type} ${failed.record.name} failed after ${completed.length} change(s)`, {
|
|
7
|
+
cause
|
|
8
|
+
});
|
|
9
|
+
this.name = 'DnsApplyError';
|
|
10
|
+
this.completed = completed;
|
|
11
|
+
this.failed = failed;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const clean = (name) => name.trim().toLowerCase().replace(/\.$/, '');
|
|
15
|
+
/** A zone-relative name as a fully qualified one. Already-qualified names pass through. */
|
|
16
|
+
export function toFqdn(name, zoneName) {
|
|
17
|
+
const relative = clean(name);
|
|
18
|
+
const zone = clean(zoneName);
|
|
19
|
+
if (relative === '' || relative === '@' || relative === zone)
|
|
20
|
+
return zone;
|
|
21
|
+
return relative.endsWith(`.${zone}`) ? relative : `${relative}.${zone}`;
|
|
22
|
+
}
|
|
23
|
+
/** A fully qualified name as a zone-relative one. */
|
|
24
|
+
export function toRelativeName(name, zoneName) {
|
|
25
|
+
const fqdn = clean(name);
|
|
26
|
+
const zone = clean(zoneName);
|
|
27
|
+
if (fqdn === zone)
|
|
28
|
+
return '@';
|
|
29
|
+
return fqdn.endsWith(`.${zone}`) ? fqdn.slice(0, -(zone.length + 1)) : fqdn;
|
|
30
|
+
}
|
|
31
|
+
const HOST_CONTENT = new Set(['CNAME', 'NS', 'MX', 'PTR', 'ALIAS', 'ANAME']);
|
|
32
|
+
/**
|
|
33
|
+
* Content in a comparable form: host names lose case and the trailing dot, and
|
|
34
|
+
* IPv6 addresses are compressed. Without this a correct zone can report drift
|
|
35
|
+
* forever. TXT content is compared without surrounding quotes.
|
|
36
|
+
*/
|
|
37
|
+
export function normalizeContent(type, content) {
|
|
38
|
+
const kind = type.toUpperCase();
|
|
39
|
+
if (HOST_CONTENT.has(kind))
|
|
40
|
+
return clean(content);
|
|
41
|
+
if (kind === 'AAAA') {
|
|
42
|
+
try {
|
|
43
|
+
return new URL(`http://[${content.trim()}]`).hostname.slice(1, -1);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return content.trim().toLowerCase();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (kind === 'TXT') {
|
|
50
|
+
const text = content.trim();
|
|
51
|
+
const parts = text.match(/^"(?:[^"\\]|\\.)*"(?:\s+"(?:[^"\\]|\\.)*")*$/)
|
|
52
|
+
? [...text.matchAll(/"((?:[^"\\]|\\.)*)"/g)].map((match) => match[1].replace(/\\(.)/g, '$1'))
|
|
53
|
+
: null;
|
|
54
|
+
return parts ? parts.join('') : text;
|
|
55
|
+
}
|
|
56
|
+
return content.trim();
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=records.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"records.js","sourceRoot":"","sources":["../src/records.ts"],"names":[],"mappings":"AA4EA,mEAAmE;AACnE,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,SAAS,CAAgC;IACzC,MAAM,CAAe;IAE9B,YAAY,SAAwC,EAAE,MAAoB,EAAE,KAAc;QACxF,KAAK,CAAC,OAAO,MAAM,CAAC,IAAI,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,iBAAiB,SAAS,CAAC,MAAM,YAAY,EAAE;YACpH,KAAK;SACN,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,MAAM,KAAK,GAAG,CAAC,IAAY,EAAU,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,CAAC;IAChC,IAAI,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC;IAClD,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACpB,IAAI,CAAC;YACH,OAAO,IAAI,GAAG,CAAC,WAAW,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACrE,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACtC,CAAC;IACH,CAAC;IACD,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QACnB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,8CAA8C,CAAC;YACtE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YAC9F,CAAC,CAAC,IAAI,CAAC;QACT,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACvC,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;AACxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formless63/dns-plan",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Provider-neutral DNS record model, safe diff and change planning.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"dns",
|
|
7
|
+
"reconcile",
|
|
8
|
+
"diff",
|
|
9
|
+
"zone"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/formless63/netlibs.git",
|
|
15
|
+
"directory": "packages/dns-plan"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/formless63/netlibs/tree/main/packages/dns-plan#readme",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/formless63/netlibs/issues"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"LICENSE",
|
|
29
|
+
"README.md"
|
|
30
|
+
],
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
}
|
|
41
|
+
}
|