The best way to control Claude Code, Codex and more from any computer or phone

main
ts 631 lines 23.1 KB
Raw
1 import * as zeroTrust from "@distilled.cloud/cloudflare/zero-trust";
2 import { Unowned } from "alchemy/AdoptPolicy";
3 import { createPhysicalName } from "alchemy/PhysicalName";
4 import * as Provider from "alchemy/Provider";
5 import { Resource } from "alchemy/Resource";
6 import * as Data from "effect/Data";
7 import * as Effect from "effect/Effect";
8 import * as Predicate from "effect/Predicate";
9 import * as Stream from "effect/Stream";
10 import { CloudflareEnvironment } from "../CloudflareEnvironment.ts";
11 import type { Providers } from "../Providers.ts";
12 import type { DeviceDefaultProfile } from "./DefaultProfile.ts";
13
14 export class CustomProfileUnexpectedResponse extends Data.TaggedError(
15 "CustomProfileUnexpectedResponse",
16 )<{
17 readonly message: string;
18 readonly cause?: unknown;
19 }> {}
20
21 const TypeId = "Cloudflare.Devices.CustomProfile" as const;
22 type TypeId = typeof TypeId;
23
24 /**
25 * Configuration for a WARP custom device profile.
26 *
27 * A custom profile applies its settings to the subset of devices matched
28 * by the `match` wirefilter expression, evaluated in ascending
29 * `precedence` order. Devices not matched by any custom profile fall back
30 * to the account's default profile.
31 */
32 export interface DeviceCustomProfileProps {
33 /**
34 * Name of the device settings profile. If omitted, a unique name is
35 * generated from the app, stage, and logical ID.
36 * @default ${app}-${stage}-${id}
37 */
38 name?: string;
39 /**
40 * The wirefilter expression to match devices, e.g.
41 * `identity.email == "user@example.com"` or `os.name == "windows"`.
42 * Mutable — patched in place.
43 */
44 match: string;
45 /**
46 * The precedence of the profile. Lower values indicate higher
47 * precedence; profiles are evaluated in ascending order. Must be
48 * unique within the account.
49 */
50 precedence: number;
51 /**
52 * Whether the profile is applied to matching devices.
53 * @default true
54 */
55 enabled?: boolean;
56 /**
57 * A human-readable description of the profile.
58 */
59 description?: string;
60 /**
61 * Routes that WARP will tunnel for matched devices. Mutually exclusive
62 * with {@link exclude}. Pushed to the per-profile include list endpoint.
63 */
64 include?: DeviceDefaultProfile.SplitTunnelEntry[];
65 /**
66 * Routes that WARP will bypass for matched devices. Mutually exclusive
67 * with {@link include}. Pushed to the per-profile exclude list endpoint.
68 */
69 exclude?: DeviceDefaultProfile.SplitTunnelEntry[];
70 /**
71 * Local-fallback DNS suffixes for matched devices. For each suffix,
72 * WARP resolves matching names via the given DNS servers.
73 */
74 fallbackDomains?: DeviceDefaultProfile.FallbackDomain[];
75 /**
76 * Seconds to wait before activating the captive-portal bypass. A value
77 * of `0` disables the bypass.
78 */
79 captivePortal?: number;
80 /**
81 * Seconds to wait before WARP reconnects after the user disables it.
82 * `0` keeps WARP disabled until the user re-enables it.
83 */
84 autoConnect?: number;
85 /**
86 * Whether the user is allowed to remove the device from the team.
87 */
88 allowedToLeave?: boolean;
89 /**
90 * Whether the user is allowed to switch WARP between Gateway-with-WARP
91 * and other modes.
92 */
93 allowModeSwitch?: boolean;
94 /**
95 * Whether WARP should surface available client updates to the user.
96 */
97 allowUpdates?: boolean;
98 /**
99 * When `true`, fallback domains without an explicit `dnsServer` are NOT
100 * resolved via the system resolver — WARP refuses to resolve them.
101 */
102 disableAutoFallback?: boolean;
103 /**
104 * When `true`, Microsoft 365 service IP ranges are added to the
105 * split-tunnel exclude list automatically.
106 */
107 excludeOfficeIps?: boolean;
108 /**
109 * When `true`, the user cannot turn the WARP switch off.
110 */
111 switchLocked?: boolean;
112 /**
113 * Selects WARP's tunneling behavior: `"warp"` for the full WireGuard
114 * tunnel, `"proxy"` for a local SOCKS proxy on the chosen `port`.
115 */
116 serviceModeV2?: DeviceDefaultProfile.ServiceModeV2;
117 /**
118 * Minutes of LAN access permitted after a WARP reconnect. `0` means
119 * unrestricted until the next WARP cycle.
120 */
121 lanAllowMinutes?: number;
122 /**
123 * Prefix length of the LAN subnet that {@link lanAllowMinutes} applies
124 * to (e.g. `24` for a `/24`).
125 */
126 lanAllowSubnetSize?: number;
127 /**
128 * When `true`, the OS registers WARP's local interface IP with the
129 * on-premises DNS server.
130 */
131 registerInterfaceIpWithDns?: boolean;
132 /**
133 * When `true`, WARP signals SCCM that the device is inside a VPN
134 * boundary. Windows only.
135 */
136 sccmVpnBoundarySupport?: boolean;
137 /**
138 * URL launched when the user clicks "Send Feedback" in the client.
139 */
140 supportUrl?: string;
141 /**
142 * Which underlying tunnel protocol WARP should use (e.g. `"wireguard"`,
143 * `"masque"`).
144 */
145 tunnelProtocol?: string;
146 }
147
148 export type DeviceCustomProfileAttributes = {
149 /** API UUID of the profile. */
150 policyId: string;
151 /** Account that owns the profile. */
152 accountId: string;
153 /** Observed profile name. */
154 name: string;
155 /** Observed wirefilter match expression. */
156 match: string | undefined;
157 /** Observed precedence. */
158 precedence: number | undefined;
159 /** Whether the profile is applied to matching devices. */
160 enabled: boolean | undefined;
161 /** Observed description. */
162 description: string | undefined;
163 /** Always `false` — custom profiles are never the default profile. */
164 default: boolean;
165 /** Observed per-profile split-tunnel include list. */
166 include: DeviceDefaultProfile.SplitTunnelEntry[];
167 /** Observed per-profile split-tunnel exclude list. */
168 exclude: DeviceDefaultProfile.SplitTunnelEntry[];
169 /** Observed per-profile fallback domains. */
170 fallbackDomains: DeviceDefaultProfile.FallbackDomain[];
171 /** Observed captive-portal timeout (seconds). */
172 captivePortal: number | undefined;
173 /** Observed auto-connect timeout (seconds). */
174 autoConnect: number | undefined;
175 /** Whether devices are allowed to leave the organization. */
176 allowedToLeave: boolean | undefined;
177 /** Whether the user may switch WARP modes. */
178 allowModeSwitch: boolean | undefined;
179 /** Whether update notifications are shown. */
180 allowUpdates: boolean | undefined;
181 /** Whether auto-fallback to system DNS is disabled. */
182 disableAutoFallback: boolean | undefined;
183 /** Whether Microsoft IPs are auto-excluded. */
184 excludeOfficeIps: boolean | undefined;
185 /** Whether the WARP switch is locked on. */
186 switchLocked: boolean | undefined;
187 /** Tunneling mode configuration. */
188 serviceModeV2: DeviceDefaultProfile.ServiceModeV2 | undefined;
189 /** Whether the WARP IP is registered with the on-prem DNS server. */
190 registerInterfaceIpWithDns: boolean | undefined;
191 /** Whether SCCM VPN-boundary support is enabled. */
192 sccmVpnBoundarySupport: boolean | undefined;
193 /** Send-Feedback URL. */
194 supportUrl: string | undefined;
195 /** Tunnel protocol selection. */
196 tunnelProtocol: string | undefined;
197 };
198
199 export type DeviceCustomProfile = Resource<
200 TypeId,
201 DeviceCustomProfileProps,
202 DeviceCustomProfileAttributes,
203 never,
204 Providers
205 >;
206
207 /**
208 * A Cloudflare WARP **custom device profile** — a settings profile applied
209 * to the subset of devices matched by a wirefilter `match` expression at a
210 * given `precedence`.
211 *
212 * All properties are mutable in place: the profile itself is patched, and
213 * the per-profile split-tunnel include/exclude and fallback-domain lists
214 * are replaced via their dedicated endpoints. Deleting the resource
215 * deletes the profile; matched devices fall back to the account's default
216 * profile.
217 * ### Creating a profile
218 * **Example:** Profile for a user group
219 * ```typescript
220 * const profile = yield* Cloudflare.Devices.DeviceCustomProfile("Contractors", {
221 * match: 'identity.groups.name == "contractors"',
222 * precedence: 100,
223 * description: "Locked-down profile for contractors",
224 * switchLocked: true,
225 * });
226 * ```
227 *
228 * ### Split tunneling
229 * **Example:** Exclude internal ranges from the tunnel
230 * ```typescript
231 * yield* Cloudflare.Devices.DeviceCustomProfile("Engineering", {
232 * match: 'identity.groups.name == "engineering"',
233 * precedence: 50,
234 * exclude: [
235 * { address: "10.0.0.0/8", description: "RFC1918" },
236 * ],
237 * });
238 * ```
239 *
240 * ### Fallback domains
241 * **Example:** Resolve a private suffix via an on-prem DNS server
242 * ```typescript
243 * yield* Cloudflare.Devices.DeviceCustomProfile("CorpDns", {
244 * match: 'identity.email matches ".*@corp.example.com"',
245 * precedence: 10,
246 * fallbackDomains: [
247 * { suffix: "corp.example.com", dnsServer: ["10.0.0.53"] },
248 * ],
249 * });
250 * ```
251 *
252 * @see https://developers.cloudflare.com/cloudflare-one/connections/connect-devices/warp/configure-warp/device-profiles/
253 *
254 * @resource
255 * @product Devices
256 * @category Cloudflare One (Zero Trust)
257 */
258 export const DeviceCustomProfile = Resource<DeviceCustomProfile>(TypeId);
259
260 /**
261 * Returns true if the given value is a DeviceCustomProfile resource.
262 */
263 export const isDeviceCustomProfile = (value: unknown): value is DeviceCustomProfile =>
264 Predicate.hasProperty(value, "Type") && value.Type === TypeId;
265
266 export const DeviceCustomProfileProvider = () =>
267 Provider.succeed(DeviceCustomProfile, {
268 stables: ["policyId", "accountId", "default"],
269
270 read: Effect.fn(function* ({ id, output, olds }) {
271 const { accountId } = yield* yield* CloudflareEnvironment;
272 const acct = output?.accountId ?? accountId;
273
274 // Owned path: refresh by our persisted policy id.
275 if (output?.policyId) {
276 const observed = yield* observeProfile(acct, output.policyId);
277 return observed ? yield* buildAttrs(acct, observed) : undefined;
278 }
279
280 // Cold lookup: recover from lost state by exact name. Profile names
281 // carry no ownership markers, so brand the match `Unowned` and let
282 // the engine gate takeover behind the adopt policy.
283 const name = yield* createProfileName(id, olds?.name);
284 const match = yield* findByName(acct, name);
285 if (match?.policyId) {
286 const observed = yield* observeProfile(acct, match.policyId);
287 if (observed) return Unowned(yield* buildAttrs(acct, observed));
288 }
289 return undefined;
290 }),
291
292 reconcile: Effect.fn(function* ({ id, news, output }) {
293 const { accountId } = yield* yield* CloudflareEnvironment;
294 const name = yield* createProfileName(id, news.name);
295
296 // 1. Observe — the policy id cached on `output` is a hint, not a
297 // guarantee: a missing profile falls through to create.
298 let observed = output?.policyId
299 ? yield* observeProfile(accountId, output.policyId)
300 : undefined;
301
302 // 2. Ensure — create when missing. Names are not unique on
303 // Cloudflare's side, so there is no AlreadyExists race; a
304 // precedence collision is a real validation error and propagates.
305 if (!observed) {
306 const created = yield* zeroTrust.createDevicePolicyCustom({
307 accountId,
308 name,
309 match: news.match,
310 precedence: news.precedence,
311 enabled: news.enabled,
312 description: news.description,
313 include: news.include?.map(encodeSplit),
314 exclude: news.exclude?.map(encodeSplit),
315 captivePortal: news.captivePortal,
316 autoConnect: news.autoConnect,
317 allowedToLeave: news.allowedToLeave,
318 allowModeSwitch: news.allowModeSwitch,
319 allowUpdates: news.allowUpdates,
320 disableAutoFallback: news.disableAutoFallback,
321 excludeOfficeIps: news.excludeOfficeIps,
322 switchLocked: news.switchLocked,
323 serviceModeV2: news.serviceModeV2,
324 lanAllowMinutes: news.lanAllowMinutes,
325 lanAllowSubnetSize: news.lanAllowSubnetSize,
326 registerInterfaceIpWithDns: news.registerInterfaceIpWithDns,
327 sccmVpnBoundarySupport: news.sccmVpnBoundarySupport,
328 supportUrl: news.supportUrl,
329 tunnelProtocol: news.tunnelProtocol,
330 });
331 const policyId = created?.policyId;
332 if (!policyId) {
333 return yield* new CustomProfileUnexpectedResponse({
334 message: "Cloudflare did not return a policy id for the created custom device profile",
335 });
336 }
337 observed = yield* observeProfile(accountId, policyId);
338 if (!observed) {
339 return yield* new CustomProfileUnexpectedResponse({
340 message: `custom device profile ${policyId} disappeared right after create`,
341 });
342 }
343 }
344 const policyId = observed.policyId!;
345
346 // 3. Sync (a) — patch the profile body with only the changed fields.
347 const patch: zeroTrust.PatchDevicePolicyCustomRequest = {
348 accountId,
349 policyId,
350 };
351 let dirty = false;
352 const setIf = <
353 K extends Exclude<keyof zeroTrust.PatchDevicePolicyCustomRequest, "accountId" | "policyId">,
354 >(
355 key: K,
356 desired: zeroTrust.PatchDevicePolicyCustomRequest[K],
357 observedValue: unknown,
358 ) => {
359 if (desired === undefined) return;
360 if (!sameJSON(desired, observedValue)) {
361 patch[key] = desired;
362 dirty = true;
363 }
364 };
365 setIf("name", name, observed.name ?? undefined);
366 setIf("match", news.match, denull(observed.match));
367 setIf("precedence", news.precedence, denull(observed.precedence));
368 setIf("enabled", news.enabled, denull(observed.enabled));
369 setIf("description", news.description, denull(observed.description));
370 setIf("captivePortal", news.captivePortal, denull(observed.captivePortal));
371 setIf("autoConnect", news.autoConnect, denull(observed.autoConnect));
372 setIf("allowedToLeave", news.allowedToLeave, denull(observed.allowedToLeave));
373 setIf("allowModeSwitch", news.allowModeSwitch, denull(observed.allowModeSwitch));
374 setIf("allowUpdates", news.allowUpdates, denull(observed.allowUpdates));
375 setIf("disableAutoFallback", news.disableAutoFallback, denull(observed.disableAutoFallback));
376 setIf("excludeOfficeIps", news.excludeOfficeIps, denull(observed.excludeOfficeIps));
377 setIf("switchLocked", news.switchLocked, denull(observed.switchLocked));
378 setIf(
379 "registerInterfaceIpWithDns",
380 news.registerInterfaceIpWithDns,
381 denull(observed.registerInterfaceIpWithDns),
382 );
383 setIf(
384 "sccmVpnBoundarySupport",
385 news.sccmVpnBoundarySupport,
386 denull(observed.sccmVpnBoundarySupport),
387 );
388 setIf("supportUrl", news.supportUrl, denull(observed.supportUrl));
389 setIf("tunnelProtocol", news.tunnelProtocol, denull(observed.tunnelProtocol));
390 if (
391 news.serviceModeV2 !== undefined &&
392 !sameJSON(news.serviceModeV2, normalizeServiceMode(observed.serviceModeV2))
393 ) {
394 patch.serviceModeV2 = news.serviceModeV2;
395 dirty = true;
396 }
397 // lanAllow* are accepted by PATCH but not reliably echoed on GET,
398 // so push them whenever the user sets them — the API is idempotent.
399 if (news.lanAllowMinutes !== undefined) {
400 patch.lanAllowMinutes = news.lanAllowMinutes;
401 dirty = true;
402 }
403 if (news.lanAllowSubnetSize !== undefined) {
404 patch.lanAllowSubnetSize = news.lanAllowSubnetSize;
405 dirty = true;
406 }
407 if (dirty) {
408 yield* zeroTrust.patchDevicePolicyCustom(patch);
409 }
410
411 // 3. Sync (b) — replace the per-profile lists when they differ from
412 // the observed cloud state.
413 const lists = yield* observeLists(accountId, policyId);
414 if (news.include !== undefined && !sameJSON(news.include, lists.include)) {
415 yield* zeroTrust.putDevicePolicyCustomInclude({
416 accountId,
417 policyId,
418 body: news.include.map(encodeSplit),
419 });
420 }
421 if (news.exclude !== undefined && !sameJSON(news.exclude, lists.exclude)) {
422 yield* zeroTrust.putDevicePolicyCustomExclude({
423 accountId,
424 policyId,
425 body: news.exclude.map(encodeSplit),
426 });
427 }
428 if (
429 news.fallbackDomains !== undefined &&
430 !sameJSON(news.fallbackDomains, lists.fallbackDomains)
431 ) {
432 yield* zeroTrust.putDevicePolicyCustomFallbackDomain({
433 accountId,
434 policyId,
435 domains: news.fallbackDomains.map(encodeFallback),
436 });
437 }
438
439 // 4. Return — re-read so attrs reflect post-sync truth.
440 const final = yield* observeProfile(accountId, policyId);
441 if (!final) {
442 return yield* new CustomProfileUnexpectedResponse({
443 message: `custom device profile ${policyId} disappeared during reconcile`,
444 });
445 }
446 return yield* buildAttrs(accountId, final);
447 }),
448
449 delete: Effect.fn(function* ({ output }) {
450 yield* zeroTrust
451 .deleteDevicePolicyCustom({
452 accountId: output.accountId,
453 policyId: output.policyId,
454 })
455 .pipe(Effect.catchTag("DevicePolicyNotFound", () => Effect.void));
456 }),
457
458 // Account collection: enumerate every custom device profile in the
459 // ambient account, then hydrate each into the exact `read` Attributes
460 // shape (same `observeProfile` + `buildAttrs` path read uses, so the
461 // per-profile split-tunnel/fallback lists are fetched too). Bounded
462 // concurrency keeps the fan-out polite; a profile that vanishes
463 // mid-enumeration is dropped via the typed `DevicePolicyNotFound` map.
464 list: Effect.fn(function* () {
465 const { accountId } = yield* yield* CloudflareEnvironment;
466 const items = yield* zeroTrust.listDevicePolicyCustoms.pages({ accountId }).pipe(
467 Stream.runCollect,
468 Effect.map((chunk) => Array.from(chunk).flatMap((page) => page.result ?? [])),
469 );
470 const rows = yield* Effect.forEach(
471 items.filter((p) => p.policyId != null),
472 (p) =>
473 Effect.gen(function* () {
474 const observed = yield* observeProfile(accountId, p.policyId!);
475 return observed ? yield* buildAttrs(accountId, observed) : undefined;
476 }),
477 { concurrency: 10 },
478 );
479 return rows.filter((row): row is DeviceCustomProfileAttributes => row !== undefined);
480 }),
481 });
482
483 type ObservedProfile = NonNullable<zeroTrust.GetDevicePolicyCustomResponse>;
484
485 /**
486 * Read a custom profile by id, mapping "gone" (`DevicePolicyNotFound`,
487 * Cloudflare error code 2052) to `undefined`.
488 */
489 const observeProfile = (accountId: string, policyId: string) =>
490 zeroTrust.getDevicePolicyCustom({ accountId, policyId }).pipe(
491 Effect.map((p): ObservedProfile | undefined => p ?? undefined),
492 Effect.catchTag("DevicePolicyNotFound", () => Effect.undefined),
493 );
494
495 /**
496 * Read the three per-profile list endpoints.
497 */
498 const observeLists = Effect.fn(function* (accountId: string, policyId: string) {
499 const [include, exclude, fallback] = yield* Effect.all(
500 [
501 zeroTrust.getDevicePolicyCustomInclude({ accountId, policyId }),
502 zeroTrust.getDevicePolicyCustomExclude({ accountId, policyId }),
503 zeroTrust.getDevicePolicyCustomFallbackDomain({ accountId, policyId }),
504 ],
505 { concurrency: "unbounded" },
506 );
507 return {
508 include: (include.result ?? []).map(normalizeSplit),
509 exclude: (exclude.result ?? []).map(normalizeSplit),
510 fallbackDomains: (fallback.result ?? []).map(normalizeFallback),
511 };
512 });
513
514 /**
515 * Find a profile by exact name via the list endpoint (oldest-id-first for
516 * determinism when names collide).
517 */
518 const findByName = (accountId: string, name: string) =>
519 zeroTrust.listDevicePolicyCustoms.items({ accountId }).pipe(
520 Stream.filter((p) => p.name === name && p.policyId != null),
521 Stream.runCollect,
522 Effect.map((chunk) =>
523 Array.from(chunk)
524 .sort((a, b) => (a.policyId ?? "").localeCompare(b.policyId ?? ""))
525 .at(0),
526 ),
527 );
528
529 const createProfileName = (id: string, name: string | undefined) =>
530 Effect.gen(function* () {
531 return name ?? (yield* createPhysicalName({ id, lowercase: true }));
532 });
533
534 const buildAttrs = Effect.fn(function* (accountId: string, profile: ObservedProfile) {
535 const policyId = profile.policyId!;
536 const lists = yield* observeLists(accountId, policyId);
537 const attrs: DeviceCustomProfileAttributes = {
538 policyId,
539 accountId,
540 name: profile.name ?? "",
541 match: denull(profile.match),
542 precedence: denull(profile.precedence),
543 enabled: denull(profile.enabled),
544 description: denull(profile.description),
545 default: profile.default ?? false,
546 include: lists.include,
547 exclude: lists.exclude,
548 fallbackDomains: lists.fallbackDomains,
549 captivePortal: denull(profile.captivePortal),
550 autoConnect: denull(profile.autoConnect),
551 allowedToLeave: denull(profile.allowedToLeave),
552 allowModeSwitch: denull(profile.allowModeSwitch),
553 allowUpdates: denull(profile.allowUpdates),
554 disableAutoFallback: denull(profile.disableAutoFallback),
555 excludeOfficeIps: denull(profile.excludeOfficeIps),
556 switchLocked: denull(profile.switchLocked),
557 serviceModeV2: normalizeServiceMode(profile.serviceModeV2),
558 registerInterfaceIpWithDns: denull(profile.registerInterfaceIpWithDns),
559 sccmVpnBoundarySupport: denull(profile.sccmVpnBoundarySupport),
560 supportUrl: denull(profile.supportUrl),
561 tunnelProtocol: denull(profile.tunnelProtocol),
562 };
563 return attrs;
564 });
565
566 /**
567 * Strip Cloudflare's `null` echoes to `undefined` so structural equality
568 * (`JSON.stringify`) works.
569 */
570 const denull = <T>(v: T | null | undefined): T | undefined => (v == null ? undefined : v);
571
572 const normalizeServiceMode = (
573 sm: { mode?: string | null; port?: number | null } | null | undefined,
574 ): DeviceDefaultProfile.ServiceModeV2 | undefined =>
575 sm && sm.mode != null
576 ? {
577 mode: (sm.mode === "proxy" ? "proxy" : "warp") as "warp" | "proxy",
578 port: denull(sm.port),
579 }
580 : undefined;
581
582 const normalizeSplit = (
583 entry:
584 | { address: string; description?: string | null }
585 | { host: string; description?: string | null },
586 ): DeviceDefaultProfile.SplitTunnelEntry => ({
587 address: "address" in entry ? entry.address : "",
588 host: "host" in entry ? entry.host : undefined,
589 description: denull(entry.description),
590 });
591
592 const normalizeFallback = (entry: {
593 suffix: string;
594 description?: string | null;
595 dnsServer?: string[] | null;
596 }): DeviceDefaultProfile.FallbackDomain => ({
597 suffix: entry.suffix,
598 description: denull(entry.description),
599 dnsServer: denull(entry.dnsServer),
600 });
601
602 /**
603 * Encode a SplitTunnelEntry for the API's union shape (`address` OR `host`).
604 * Prefers `host` when set since the address would otherwise be empty.
605 */
606 const encodeSplit = (
607 e: DeviceDefaultProfile.SplitTunnelEntry,
608 ): { address: string; description?: string } | { host: string; description?: string } => {
609 if (e.host && !e.address) {
610 return e.description !== undefined
611 ? { host: e.host, description: e.description }
612 : { host: e.host };
613 }
614 return e.description !== undefined
615 ? { address: e.address, description: e.description }
616 : { address: e.address };
617 };
618
619 const encodeFallback = (
620 d: DeviceDefaultProfile.FallbackDomain,
621 ): { suffix: string; description?: string; dnsServer?: string[] } => {
622 const out: { suffix: string; description?: string; dnsServer?: string[] } = {
623 suffix: d.suffix,
624 };
625 if (d.description !== undefined) out.description = d.description;
626 if (d.dnsServer !== undefined) out.dnsServer = d.dnsServer;
627 return out;
628 };
629
630 /** Structural deep-equality via canonical JSON. */
631 const sameJSON = (a: unknown, b: unknown): boolean => JSON.stringify(a) === JSON.stringify(b);