@zabaca/zbc 0.21.1 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zabaca/zbc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "Zabaca stack CLI — scaffold and deploy infrastructure",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Zabaca/zbc.git",
|
|
9
|
+
"directory": "packages/cli"
|
|
10
|
+
},
|
|
6
11
|
"type": "module",
|
|
7
12
|
"bin": {
|
|
8
13
|
"zbc": "./bin/zbc.js"
|
|
@@ -138,6 +138,26 @@ const recordSchema = z.discriminatedUnion('type', [
|
|
|
138
138
|
ttl: ttlField,
|
|
139
139
|
})
|
|
140
140
|
.strict(),
|
|
141
|
+
/**
|
|
142
|
+
* Declared as its four fields rather than as one `content` string, because
|
|
143
|
+
* no single string means the same thing on both sides: the dashboard shows
|
|
144
|
+
* `priority weight port target`, while the API's `content` is
|
|
145
|
+
* `weight port target` with priority in a field of its own. A copied
|
|
146
|
+
* dashboard value would shift every number one place. See `desiredRecord`.
|
|
147
|
+
*/
|
|
148
|
+
z
|
|
149
|
+
.object({
|
|
150
|
+
type: z.literal('SRV'),
|
|
151
|
+
/** The `_service._proto` label, e.g. `_autodiscover._tcp`. */
|
|
152
|
+
name: z.string(),
|
|
153
|
+
priority: z.number().int().min(0).max(65535),
|
|
154
|
+
weight: z.number().int().min(0).max(65535),
|
|
155
|
+
port: z.number().int().min(0).max(65535),
|
|
156
|
+
/** The host the service lives on. */
|
|
157
|
+
target: z.string().min(1),
|
|
158
|
+
ttl: ttlField,
|
|
159
|
+
})
|
|
160
|
+
.strict(),
|
|
141
161
|
])
|
|
142
162
|
|
|
143
163
|
export type RecordConfig = z.infer<typeof recordSchema>
|
|
@@ -234,6 +254,9 @@ export function fqdn(name: string, zone: string): string {
|
|
|
234
254
|
* Comparable form of a record's content. Cloudflare round-trips TXT values
|
|
235
255
|
* with surrounding quotes in some API versions and normalises hostname targets
|
|
236
256
|
* to lowercase without a trailing dot; neither difference is a change.
|
|
257
|
+
*
|
|
258
|
+
* An SRV's content is `weight port target`, and only the target is a hostname:
|
|
259
|
+
* the numbers compare as written, the last token as any other hostname does.
|
|
237
260
|
*/
|
|
238
261
|
export function normalizeContent(type: string, content: string): string {
|
|
239
262
|
const value = content.trim()
|
|
@@ -245,9 +268,22 @@ export function normalizeContent(type: string, content: string): string {
|
|
|
245
268
|
if (type === 'CNAME' || type === 'MX' || type === 'NS' || type === 'AAAA') {
|
|
246
269
|
return value.replace(/\.$/, '').toLowerCase()
|
|
247
270
|
}
|
|
271
|
+
if (type === 'SRV') {
|
|
272
|
+
const tokens = value.split(/\s+/)
|
|
273
|
+
const target = tokens.pop() ?? ''
|
|
274
|
+
return [...tokens, target.replace(/\.$/, '').toLowerCase()].join(' ')
|
|
275
|
+
}
|
|
248
276
|
return value
|
|
249
277
|
}
|
|
250
278
|
|
|
279
|
+
/** What Cloudflare's create and PATCH take for an SRV, in place of `content`. */
|
|
280
|
+
export interface SrvData {
|
|
281
|
+
priority: number
|
|
282
|
+
weight: number
|
|
283
|
+
port: number
|
|
284
|
+
target: string
|
|
285
|
+
}
|
|
286
|
+
|
|
251
287
|
export interface DesiredRecord {
|
|
252
288
|
type: string
|
|
253
289
|
/** Always an FQDN by the time it gets here. */
|
|
@@ -256,6 +292,38 @@ export interface DesiredRecord {
|
|
|
256
292
|
ttl: number
|
|
257
293
|
proxied?: boolean
|
|
258
294
|
priority?: number
|
|
295
|
+
/** SRV only: the fields `content` and `priority` were derived from. */
|
|
296
|
+
data?: SrvData
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* One declared record in the shape the live one is compared against. For an
|
|
301
|
+
* SRV that is the API's shape, not the dashboard's: `content` is
|
|
302
|
+
* `weight port target` and priority rides alongside, exactly as
|
|
303
|
+
* `GET /dns_records` returns it, so `sameValue` and `differs` need no SRV case.
|
|
304
|
+
* `data` is carried too, because it and not `content` is what the write sends.
|
|
305
|
+
*/
|
|
306
|
+
export function desiredRecord(record: RecordConfig, zone: string): DesiredRecord {
|
|
307
|
+
const name = fqdn(record.name, zone)
|
|
308
|
+
if (record.type === 'SRV') {
|
|
309
|
+
const { priority, weight, port, target } = record
|
|
310
|
+
return {
|
|
311
|
+
type: record.type,
|
|
312
|
+
name,
|
|
313
|
+
content: `${weight} ${port} ${target}`,
|
|
314
|
+
ttl: record.ttl,
|
|
315
|
+
priority,
|
|
316
|
+
data: { priority, weight, port, target },
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return {
|
|
320
|
+
type: record.type,
|
|
321
|
+
name,
|
|
322
|
+
content: record.content,
|
|
323
|
+
ttl: record.ttl,
|
|
324
|
+
...('proxied' in record ? { proxied: record.proxied } : {}),
|
|
325
|
+
...('priority' in record ? { priority: record.priority } : {}),
|
|
326
|
+
}
|
|
259
327
|
}
|
|
260
328
|
|
|
261
329
|
export interface ActualRecord extends DesiredRecord {
|
|
@@ -323,7 +391,15 @@ function differs(desired: DesiredRecord, actual: DesiredRecord): boolean {
|
|
|
323
391
|
return false
|
|
324
392
|
}
|
|
325
393
|
|
|
326
|
-
|
|
394
|
+
/**
|
|
395
|
+
* An SRV is printed `priority weight port target`, the order the dashboard and
|
|
396
|
+
* a zone file use. Its `content` alone omits priority, and a drift line is what
|
|
397
|
+
* an operator copies into an instance, so it has to carry all four numbers.
|
|
398
|
+
*/
|
|
399
|
+
export const describeRecord = (r: DesiredRecord) =>
|
|
400
|
+
r.type === 'SRV'
|
|
401
|
+
? `${r.type} ${r.name} -> ${r.priority ?? 0} ${r.content}`
|
|
402
|
+
: `${r.type} ${r.name} -> ${r.content}`
|
|
327
403
|
|
|
328
404
|
export interface ZonePlan {
|
|
329
405
|
create: DesiredRecord[]
|
|
@@ -562,6 +638,11 @@ async function listRecords(token: string, zoneId: string): Promise<ActualRecord[
|
|
|
562
638
|
|
|
563
639
|
/** The request body Cloudflare wants for one declared record. */
|
|
564
640
|
function recordBody(record: DesiredRecord): Record<string, unknown> {
|
|
641
|
+
// An SRV is written as its fields; `content` is what Cloudflare derives from
|
|
642
|
+
// them, and priority lives only inside `data`.
|
|
643
|
+
if (record.data) {
|
|
644
|
+
return { type: record.type, name: record.name, ttl: record.ttl, data: record.data }
|
|
645
|
+
}
|
|
565
646
|
const body: Record<string, unknown> = {
|
|
566
647
|
type: record.type,
|
|
567
648
|
name: record.name,
|
|
@@ -617,14 +698,7 @@ export const cloudflareZoneModule = defineModule({
|
|
|
617
698
|
}
|
|
618
699
|
|
|
619
700
|
// 2. Diff the whole zone before mutating any of it.
|
|
620
|
-
const desired = config.records.map((record) => (
|
|
621
|
-
type: record.type,
|
|
622
|
-
name: fqdn(record.name, config.zone),
|
|
623
|
-
content: record.content,
|
|
624
|
-
ttl: record.ttl,
|
|
625
|
-
...('proxied' in record ? { proxied: record.proxied } : {}),
|
|
626
|
-
...('priority' in record ? { priority: record.priority } : {}),
|
|
627
|
-
}))
|
|
701
|
+
const desired = config.records.map((record) => desiredRecord(record, config.zone))
|
|
628
702
|
const actual = await listRecords(token, zone.id)
|
|
629
703
|
const plan = planZone({ desired, actual })
|
|
630
704
|
|