@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 683 lines 23.3 KB
Raw
1 import * as customHostnames from "@distilled.cloud/cloudflare/custom-hostnames";
2 import { Unowned } from "alchemy/AdoptPolicy";
3 import * as Provider from "alchemy/Provider";
4 import { Resource } from "alchemy/Resource";
5 import { arrayEqualsUnordered } from "alchemy/Util/equal";
6 import * as Effect from "effect/Effect";
7 import * as Predicate from "effect/Predicate";
8 import * as Stream from "effect/Stream";
9 import { CloudflareEnvironment } from "../CloudflareEnvironment.ts";
10 import type { Providers } from "../Providers.ts";
11 import { listAllZones } from "../Zone/lookup.ts";
12
13 /**
14 * Domain control validation (DCV) method used to prove control over the
15 * custom hostname before a certificate is issued.
16 */
17 export type DcvMethod = "http" | "txt" | "email";
18
19 /**
20 * Certificate authority that issues the managed certificate.
21 */
22 export type CertificateAuthority = "digicert" | "google" | "lets_encrypt" | "ssl_com";
23
24 /**
25 * Per-hostname TLS settings applied to the edge certificate.
26 */
27 export type SslSettings = {
28 /** Allowed cipher suites. */
29 ciphers?: string[];
30 /** Whether Early Hints (HTTP 103) is enabled. */
31 earlyHints?: "on" | "off";
32 /** Whether HTTP/2 is enabled. */
33 http2?: "on" | "off";
34 /** Minimum TLS version served for this hostname. */
35 minTlsVersion?: "1.0" | "1.1" | "1.2" | "1.3";
36 /** Whether TLS 1.3 is enabled. */
37 tls_1_3?: "on" | "off";
38 };
39
40 /**
41 * SSL configuration for a custom hostname's managed certificate.
42 */
43 export type Ssl = {
44 /**
45 * Domain control validation method.
46 * @default "txt"
47 */
48 method?: DcvMethod;
49 /**
50 * Level of validation for the certificate. Only domain validation
51 * (`dv`) is supported.
52 * @default "dv"
53 */
54 type?: "dv";
55 /**
56 * Certificate authority that issues the certificate. Omit to let
57 * Cloudflare choose.
58 */
59 certificateAuthority?: CertificateAuthority;
60 /**
61 * How the intermediate chain is bundled with the leaf certificate.
62 */
63 bundleMethod?: "ubiquitous" | "optimal" | "force";
64 /**
65 * Whether to add Cloudflare branding to the certificate (adds
66 * `sni.cloudflaressl.com` as the certificate common name).
67 */
68 cloudflareBranding?: boolean;
69 /**
70 * Whether the certificate also covers `*.hostname`. Toggling can
71 * trigger certificate reissuance, but is still an in-place update.
72 */
73 wildcard?: boolean;
74 /**
75 * Bring-your-own leaf certificate (PEM). Requires `customKey`.
76 */
77 customCertificate?: string;
78 /**
79 * Private key (PEM) for `customCertificate`.
80 */
81 customKey?: string;
82 /**
83 * Identifier of a previously generated custom CSR.
84 */
85 customCsrId?: string;
86 /**
87 * Per-hostname TLS settings.
88 */
89 settings?: SslSettings;
90 };
91
92 export interface Props {
93 /**
94 * Zone the custom hostname is onboarded onto (the SaaS zone). Stable —
95 * changing the zone triggers replacement.
96 */
97 zoneId: string;
98 /**
99 * The customer-owned hostname that will point at your zone via CNAME
100 * (e.g. `app.customer.com`).
101 *
102 * Stable — the hostname is the resource's identity and is not
103 * patchable; a rename is a delete + create. Declared as plain `string`
104 * (not `string`) so it is statically knowable inside `diff`.
105 */
106 hostname: string;
107 /**
108 * SSL configuration for the managed certificate. Mutable — patched in
109 * place (note that changing `ssl` can trigger certificate
110 * reissuance).
111 *
112 * @default { method: "txt", type: "dv" }
113 */
114 ssl?: Ssl;
115 /**
116 * Unique key/value metadata for this hostname, available to Workers
117 * via the request. Requires the Enterprise Cloudflare for SaaS
118 * entitlement — the API rejects it otherwise.
119 */
120 customMetadata?: Record<string, unknown>;
121 /**
122 * Origin server to route traffic for this hostname to, overriding the
123 * zone's fallback origin. Must be a DNS record within the zone.
124 * Requires the Enterprise Cloudflare for SaaS entitlement.
125 */
126 customOriginServer?: string;
127 /**
128 * SNI value sent to `customOriginServer` during the TLS handshake, or
129 * the literal `:request_host_header:`. Requires the Enterprise
130 * Cloudflare for SaaS entitlement.
131 */
132 customOriginSni?: string;
133 }
134
135 /**
136 * TXT record the customer must create to prove ownership of the
137 * hostname (pre-validation).
138 */
139 export interface OwnershipVerification {
140 /** TXT record name. */
141 name: string | undefined;
142 /** Record type (always `txt`). */
143 type: string | undefined;
144 /** TXT record value. */
145 value: string | undefined;
146 }
147
148 /**
149 * HTTP token alternative for ownership verification.
150 */
151 export interface OwnershipVerificationHttp {
152 /** URL the token must be served from. */
153 httpUrl: string | undefined;
154 /** Token body to serve. */
155 httpBody: string | undefined;
156 }
157
158 /**
159 * A DCV record the customer must create/serve for certificate
160 * validation.
161 */
162 export interface ValidationRecord {
163 /** CNAME validation record name. */
164 cname: string | undefined;
165 /** CNAME validation record target. */
166 cnameTarget: string | undefined;
167 /** Email addresses validation mail is sent to. */
168 emails: string[] | undefined;
169 /** HTTP validation token body. */
170 httpBody: string | undefined;
171 /** HTTP validation token URL. */
172 httpUrl: string | undefined;
173 /** Validation record status. */
174 status: string | undefined;
175 /** TXT validation record name. */
176 txtName: string | undefined;
177 /** TXT validation record value. */
178 txtValue: string | undefined;
179 }
180
181 export interface Attributes {
182 /** Cloudflare-assigned custom hostname UUID. */
183 customHostnameId: string;
184 /** Zone that owns this custom hostname. */
185 zoneId: string;
186 /** The customer-owned hostname. */
187 hostname: string;
188 /**
189 * Activation status of the hostname (`pending`, `active`, …). A
190 * hostname for a domain whose DNS the customer has not pointed yet
191 * stays `pending` — activation is asynchronous and not blocked on.
192 */
193 status: string | undefined;
194 /** Certificate status (`initializing`, `pending_validation`, `active`, …). */
195 sslStatus: string | undefined;
196 /** TXT record the customer must create to verify ownership. */
197 ownershipVerification: OwnershipVerification | undefined;
198 /** HTTP token alternative for ownership verification. */
199 ownershipVerificationHttp: OwnershipVerificationHttp | undefined;
200 /** DCV records the customer must satisfy for certificate issuance. */
201 validationRecords: ValidationRecord[] | undefined;
202 }
203
204 export type CustomHostname = Resource<
205 "Cloudflare.CustomHostname.CustomHostname",
206 Props,
207 Attributes,
208 never,
209 Providers
210 >;
211
212 /**
213 * A Cloudflare for SaaS custom hostname.
214 *
215 * Onboards a customer-owned hostname onto your zone with a managed TLS
216 * certificate. The customer points their DNS (CNAME) at your zone;
217 * Cloudflare validates ownership and issues a certificate
218 * asynchronously. The first 100 custom hostnames are free on any plan.
219 *
220 * Traffic for custom hostnames is routed to the zone's
221 * {@link FallbackOrigin} (or `customOriginServer` with the Enterprise
222 * entitlement), so a fallback origin should usually be deployed
223 * alongside.
224 *
225 * Safety: when there is no prior state, `read` scans the zone for an
226 * existing hostname match. Custom hostnames carry no ownership markers,
227 * so an existing match is reported as `Unowned` and the engine refuses
228 * to take it over unless `--adopt` (or `adopt(true)`) is set.
229 * ### Creating a Custom Hostname
230 * **Example:** Basic custom hostname with TXT validation
231 * ```typescript
232 * const hostname = yield* Cloudflare.CustomHostname.CustomHostname("CustomerApp", {
233 * zoneId: zone.zoneId,
234 * hostname: "app.customer.com",
235 * });
236 * // Hand these to the customer so they can verify ownership:
237 * // hostname.ownershipVerification?.name / .value
238 * ```
239 *
240 * **Example:** HTTP validation with a specific certificate authority
241 * ```typescript
242 * yield* Cloudflare.CustomHostname.CustomHostname("CustomerApp", {
243 * zoneId: zone.zoneId,
244 * hostname: "app.customer.com",
245 * ssl: {
246 * method: "http",
247 * type: "dv",
248 * certificateAuthority: "google",
249 * },
250 * });
251 * ```
252 *
253 * ### Pairing with a Fallback Origin
254 * **Example:** Route custom hostname traffic to your origin
255 * ```typescript
256 * const record = yield* Cloudflare.DNS.Record("Origin", {
257 * zoneId: zone.zoneId,
258 * name: "origin.my-saas.com",
259 * type: "A",
260 * content: "203.0.113.1",
261 * proxied: true,
262 * });
263 * yield* Cloudflare.CustomHostname.FallbackOrigin("Fallback", {
264 * zoneId: zone.zoneId,
265 * origin: record.name,
266 * });
267 * yield* Cloudflare.CustomHostname.CustomHostname("CustomerApp", {
268 * zoneId: zone.zoneId,
269 * hostname: "app.customer.com",
270 * });
271 * ```
272 *
273 * @resource
274 * @product Custom Hostnames
275 * @category Domains & DNS
276 */
277 export const CustomHostname = Resource<CustomHostname>("Cloudflare.CustomHostname.CustomHostname", {
278 aliases: ["Cloudflare.CustomHostname"],
279 });
280
281 export const isCustomHostname = (value: unknown): value is CustomHostname =>
282 Predicate.hasProperty(value, "Type") && value.Type === "Cloudflare.CustomHostname.CustomHostname";
283
284 export const CustomHostnameProvider = () =>
285 Provider.succeed(CustomHostname, {
286 stables: ["customHostnameId", "zoneId", "hostname"],
287
288 // Custom hostnames are a zone-scoped Cloudflare for SaaS feature. Fan out
289 // over every zone in the account, exhaustively paginate each zone's custom
290 // hostnames, and hydrate each into the same Attributes shape `read`
291 // produces. Zones without the SaaS entitlement reject with the typed
292 // `SaasQuotaNotAllocated`/`Forbidden` errors — skip them.
293 list: Effect.fn(function* () {
294 const { accountId } = yield* yield* CloudflareEnvironment;
295 const zones = yield* listAllZones(accountId);
296 const rows = yield* Effect.forEach(
297 zones,
298 (zone) =>
299 customHostnames.listCustomHostnames.pages({ zoneId: zone.id }).pipe(
300 Stream.runCollect,
301 Effect.map((chunk) =>
302 Array.from(chunk).flatMap((page) =>
303 (page.result ?? []).map((raw): Attributes =>
304 toAttributes(narrowHostname(raw), zone.id),
305 ),
306 ),
307 ),
308 Effect.catchTags({
309 SaasQuotaNotAllocated: () => Effect.succeed([]),
310 Forbidden: () => Effect.succeed([]),
311 }),
312 ),
313 { concurrency: 10 },
314 );
315 return rows.flat();
316 }),
317
318 diff: Effect.fn(function* ({ olds = {}, news }) {
319 const o = olds as Props;
320 const n = news as Props;
321 if (o.hostname !== undefined && o.hostname !== n.hostname) {
322 return { action: "replace" } as const;
323 }
324 // zoneId is Input<string>; compare only once both sides are
325 // concrete strings.
326 if (typeof o.zoneId === "string" && typeof n.zoneId === "string" && o.zoneId !== n.zoneId) {
327 return { action: "replace" } as const;
328 }
329 }),
330
331 reconcile: Effect.fn(function* ({ news, output }) {
332 // Inputs have been resolved to concrete strings by Plan.
333 const zoneId = news.zoneId as string;
334 const customOriginServer = news.customOriginServer as string | undefined;
335 const desiredSsl = buildSslBody(news.ssl);
336
337 // 1. Observe by cached id first.
338 let observed: ObservedHostname | undefined;
339 if (output?.customHostnameId) {
340 observed = yield* observeById(zoneId, output.customHostnameId);
341 }
342
343 // 2. Fall back to scanning the zone for the hostname (unique per
344 // zone). Ownership has already been verified upstream — `read`
345 // reports existing hostnames as `Unowned` and the engine gates
346 // takeover behind the adopt policy before reconcile runs.
347 if (!observed) {
348 observed = yield* findByHostname(zoneId, news.hostname);
349 }
350
351 // 3. Ensure. A create that races another writer (hostname already
352 // exists) is converged by re-observing; if the hostname still
353 // cannot be found the original error is re-raised.
354 let justCreated = false;
355 if (!observed) {
356 observed = yield* customHostnames
357 .createCustomHostname({
358 zoneId,
359 hostname: news.hostname,
360 ssl: desiredSsl,
361 customMetadata: news.customMetadata,
362 })
363 .pipe(
364 Effect.map(narrowHostname),
365 Effect.catch((originalError) =>
366 Effect.gen(function* () {
367 const existing = yield* findByHostname(zoneId, news.hostname).pipe(
368 Effect.orElseSucceed(() => undefined),
369 );
370 if (!existing) return yield* originalError;
371 return existing;
372 }),
373 ),
374 );
375 justCreated = true;
376 }
377
378 // 4. Sync — diff each mutable aspect against observed cloud state
379 // and PATCH only the delta. `ssl` is only sent when it actually
380 // differs because patching it can trigger certificate
381 // reissuance.
382 const patch: {
383 ssl?: ReturnType<typeof buildSslBody>;
384 customMetadata?: Record<string, unknown>;
385 customOriginServer?: string;
386 customOriginSni?: string;
387 } = {};
388 if (!justCreated && news.ssl !== undefined && !sslEqualsObserved(news.ssl, observed.ssl)) {
389 patch.ssl = desiredSsl;
390 }
391 if (
392 news.customMetadata !== undefined &&
393 !metadataEquals(news.customMetadata, observed.customMetadata)
394 ) {
395 patch.customMetadata = news.customMetadata;
396 }
397 if (customOriginServer !== undefined && customOriginServer !== observed.customOriginServer) {
398 patch.customOriginServer = customOriginServer;
399 }
400 if (news.customOriginSni !== undefined && news.customOriginSni !== observed.customOriginSni) {
401 patch.customOriginSni = news.customOriginSni;
402 }
403 if (Object.keys(patch).length > 0) {
404 observed = narrowHostname(
405 yield* customHostnames.patchCustomHostname({
406 zoneId,
407 customHostnameId: observed.id,
408 ...patch,
409 }),
410 );
411 }
412
413 // 5. Return fresh attributes.
414 return toAttributes(observed, zoneId);
415 }),
416
417 delete: Effect.fn(function* ({ output }) {
418 yield* customHostnames
419 .deleteCustomHostname({
420 zoneId: output.zoneId,
421 customHostnameId: output.customHostnameId,
422 })
423 .pipe(Effect.catchTag("CustomHostnameNotFound", () => Effect.void));
424 }),
425
426 read: Effect.fn(function* ({ output, olds }) {
427 // Owned path: we have persisted state (our own id) — refresh it.
428 if (output?.customHostnameId) {
429 const observed = yield* observeById(output.zoneId, output.customHostnameId);
430 if (observed) return toAttributes(observed, output.zoneId);
431 }
432 // Adoption path: no state of our own, but the hostname may already
433 // exist on the zone. Custom hostnames carry no ownership markers we
434 // can inspect, so brand any match `Unowned` — the engine refuses to
435 // take over unless `adopt` is set.
436 const zoneId = output?.zoneId ?? (typeof olds?.zoneId === "string" ? olds.zoneId : undefined);
437 const hostname = output?.hostname ?? olds?.hostname;
438 if (zoneId && hostname) {
439 const observed = yield* findByHostname(zoneId, hostname);
440 if (observed) return Unowned(toAttributes(observed, zoneId));
441 }
442 return undefined;
443 }),
444 });
445
446 // ---------------------------------------------------------------------------
447 // Observation
448 // ---------------------------------------------------------------------------
449
450 // A missing hostname is reported by the custom-hostnames API with code
451 // 1436 ("Custom hostname not found") on a 404 envelope — typed in the
452 // distilled union as `CustomHostnameNotFound`.
453 const observeById = (zoneId: string, customHostnameId: string) =>
454 customHostnames.getCustomHostname({ zoneId, customHostnameId }).pipe(
455 Effect.map(narrowHostname),
456 Effect.catchTag("CustomHostnameNotFound", () => Effect.undefined),
457 );
458
459 // Locate an existing custom hostname by exact hostname. The API only
460 // offers a `contain` filter, so an exact client-side match is applied on
461 // top.
462 const findByHostname = (zoneId: string, hostname: string) =>
463 customHostnames.listCustomHostnames.items({ zoneId, hostname: { contain: hostname } }).pipe(
464 Stream.runCollect,
465 Effect.map((chunk) => Array.from(chunk).find((h) => h.hostname === hostname)),
466 Effect.map((found) => (found === undefined ? undefined : narrowHostname(found))),
467 );
468
469 interface ObservedSsl {
470 readonly status?: string;
471 readonly method?: string;
472 readonly type?: string;
473 readonly wildcard?: boolean;
474 readonly bundleMethod?: string;
475 readonly certificateAuthority?: string;
476 readonly settings?: {
477 readonly ciphers?: ReadonlyArray<string>;
478 readonly earlyHints?: string;
479 readonly http2?: string;
480 readonly minTlsVersion?: string;
481 readonly tls_1_3?: string;
482 };
483 readonly validationRecords?: ReadonlyArray<{
484 readonly cname?: string;
485 readonly cnameTarget?: string;
486 readonly emails?: string[];
487 readonly httpBody?: string;
488 readonly httpUrl?: string;
489 readonly status?: string;
490 readonly txtName?: string;
491 readonly txtValue?: string;
492 }>;
493 }
494
495 interface ObservedHostname {
496 readonly id: string;
497 readonly hostname: string;
498 readonly status?: string;
499 readonly customMetadata?: Record<string, unknown>;
500 readonly customOriginServer?: string;
501 readonly customOriginSni?: string;
502 readonly ownershipVerification?: {
503 readonly name?: string;
504 readonly type?: string;
505 readonly value?: string;
506 };
507 readonly ownershipVerificationHttp?: {
508 readonly httpBody?: string;
509 readonly httpUrl?: string;
510 };
511 readonly ssl?: ObservedSsl;
512 }
513
514 const undef = <T>(v: T | null | undefined): T | undefined => (v == null ? undefined : v);
515
516 type RawHostname =
517 | customHostnames.GetCustomHostnameResponse
518 | customHostnames.CreateCustomHostnameResponse
519 | customHostnames.PatchCustomHostnameResponse
520 | customHostnames.ListCustomHostnamesResponse["result"][number];
521
522 const narrowHostname = (raw: RawHostname): ObservedHostname => ({
523 id: raw.id,
524 hostname: raw.hostname,
525 status: undef(raw.status),
526 customMetadata: undef(raw.customMetadata),
527 customOriginServer: undef(raw.customOriginServer),
528 customOriginSni: undef(raw.customOriginSni),
529 ownershipVerification:
530 raw.ownershipVerification == null
531 ? undefined
532 : {
533 name: undef(raw.ownershipVerification.name),
534 type: undef(raw.ownershipVerification.type),
535 value: undef(raw.ownershipVerification.value),
536 },
537 ownershipVerificationHttp:
538 raw.ownershipVerificationHttp == null
539 ? undefined
540 : {
541 httpBody: undef(raw.ownershipVerificationHttp.httpBody),
542 httpUrl: undef(raw.ownershipVerificationHttp.httpUrl),
543 },
544 ssl:
545 raw.ssl == null
546 ? undefined
547 : {
548 status: undef(raw.ssl.status),
549 method: undef(raw.ssl.method),
550 type: undef(raw.ssl.type),
551 wildcard: undef(raw.ssl.wildcard),
552 bundleMethod: undef(raw.ssl.bundleMethod),
553 certificateAuthority: undef(raw.ssl.certificateAuthority),
554 settings:
555 raw.ssl.settings == null
556 ? undefined
557 : {
558 ciphers: undef(raw.ssl.settings.ciphers),
559 earlyHints: undef(raw.ssl.settings.earlyHints),
560 http2: undef(raw.ssl.settings.http2),
561 minTlsVersion: undef(raw.ssl.settings.minTlsVersion),
562 tls_1_3: undef(raw.ssl.settings.tls_1_3),
563 },
564 validationRecords:
565 raw.ssl.validationRecords == null
566 ? undefined
567 : raw.ssl.validationRecords.map((r) => ({
568 cname: undef(r.cname),
569 cnameTarget: undef(r.cnameTarget),
570 emails: undef(r.emails),
571 httpBody: undef(r.httpBody),
572 httpUrl: undef(r.httpUrl),
573 status: undef(r.status),
574 txtName: undef(r.txtName),
575 txtValue: undef(r.txtValue),
576 })),
577 },
578 });
579
580 const toAttributes = (observed: ObservedHostname, zoneId: string): Attributes => ({
581 customHostnameId: observed.id,
582 zoneId,
583 hostname: observed.hostname,
584 status: observed.status,
585 sslStatus: observed.ssl?.status,
586 ownershipVerification:
587 observed.ownershipVerification === undefined
588 ? undefined
589 : {
590 name: observed.ownershipVerification.name,
591 type: observed.ownershipVerification.type,
592 value: observed.ownershipVerification.value,
593 },
594 ownershipVerificationHttp:
595 observed.ownershipVerificationHttp === undefined
596 ? undefined
597 : {
598 httpUrl: observed.ownershipVerificationHttp.httpUrl,
599 httpBody: observed.ownershipVerificationHttp.httpBody,
600 },
601 validationRecords:
602 observed.ssl?.validationRecords === undefined
603 ? undefined
604 : observed.ssl.validationRecords.map((r) => ({
605 cname: r.cname,
606 cnameTarget: r.cnameTarget,
607 emails: r.emails,
608 httpBody: r.httpBody,
609 httpUrl: r.httpUrl,
610 status: r.status,
611 txtName: r.txtName,
612 txtValue: r.txtValue,
613 })),
614 });
615
616 // ---------------------------------------------------------------------------
617 // Body construction + drift detection
618 // ---------------------------------------------------------------------------
619
620 const buildSslBody = (ssl: Ssl | undefined) => ({
621 method: ssl?.method ?? "txt",
622 type: ssl?.type ?? ("dv" as const),
623 certificateAuthority: ssl?.certificateAuthority,
624 bundleMethod: ssl?.bundleMethod,
625 cloudflareBranding: ssl?.cloudflareBranding,
626 wildcard: ssl?.wildcard,
627 customCertificate: ssl?.customCertificate,
628 customKey: ssl?.customKey,
629 customCsrId: ssl?.customCsrId,
630 settings: ssl?.settings,
631 });
632
633 /**
634 * Compare desired SSL config against observed cloud state, considering
635 * only fields the user actually set (Cloudflare echoes more fields than
636 * we manage, with defaults we should not fight). Returns `true` when no
637 * patch is needed.
638 */
639 const sslEqualsObserved = (desired: Ssl, observed: ObservedSsl | undefined): boolean => {
640 if (observed === undefined) return false;
641 if (desired.method !== undefined && desired.method !== observed.method) {
642 return false;
643 }
644 if (desired.type !== undefined && desired.type !== observed.type) {
645 return false;
646 }
647 if (desired.wildcard !== undefined && desired.wildcard !== (observed.wildcard ?? false)) {
648 return false;
649 }
650 if (desired.bundleMethod !== undefined && desired.bundleMethod !== observed.bundleMethod) {
651 return false;
652 }
653 if (
654 desired.certificateAuthority !== undefined &&
655 desired.certificateAuthority !== observed.certificateAuthority
656 ) {
657 return false;
658 }
659 const s = desired.settings;
660 if (s !== undefined) {
661 const o = observed.settings;
662 if (s.ciphers !== undefined && !arrayEqualsUnordered(s.ciphers, o?.ciphers)) return false;
663 if (s.earlyHints !== undefined && s.earlyHints !== o?.earlyHints) return false;
664 if (s.http2 !== undefined && s.http2 !== o?.http2) return false;
665 if (s.minTlsVersion !== undefined && s.minTlsVersion !== o?.minTlsVersion) return false;
666 if (s.tls_1_3 !== undefined && s.tls_1_3 !== o?.tls_1_3) return false;
667 }
668 return true;
669 };
670
671 const metadataEquals = (
672 desired: Record<string, unknown>,
673 observed: Record<string, unknown> | undefined,
674 ): boolean => {
675 const o = observed ?? {};
676 const dKeys = Object.keys(desired);
677 const oKeys = Object.keys(o);
678 if (dKeys.length !== oKeys.length) return false;
679 for (const k of dKeys) {
680 if (JSON.stringify(desired[k]) !== JSON.stringify(o[k])) return false;
681 }
682 return true;
683 };