@@ -25,6 +25,7 @@ import { EnvironmentRegistry } from "@t3tools/client-runtime/connection";
2525import { request , runStream } from "@t3tools/client-runtime/rpc" ;
2626import { makeEnvironmentHttpApiClient } from "@t3tools/client-runtime/rpc" ;
2727import { ManagedRelay } from "@t3tools/client-runtime/relay" ;
28+ import { getUrlDiagnostics } from "@t3tools/shared/urlDiagnostics" ;
2829
2930import {
3031 readPrimaryEnvironmentDescriptor ,
@@ -61,6 +62,26 @@ const EnvironmentCloudApiError = Schema.Union([
6162type EnvironmentCloudApiError = typeof EnvironmentCloudApiError . Type ;
6263const isEnvironmentCloudApiError = Schema . is ( EnvironmentCloudApiError ) ;
6364
65+ function relayUrlDiagnosticFields ( relayUrl : string | undefined ) {
66+ if ( relayUrl === undefined ) return { } ;
67+ const diagnostics = getUrlDiagnostics ( relayUrl ) ;
68+ return {
69+ relayUrlInputLength : diagnostics . inputLength ,
70+ ...( diagnostics . protocol === undefined ? { } : { relayUrlProtocol : diagnostics . protocol } ) ,
71+ ...( diagnostics . hostname === undefined ? { } : { relayUrlHostname : diagnostics . hostname } ) ,
72+ } ;
73+ }
74+
75+ function httpBaseUrlDiagnosticFields ( httpBaseUrl : string | undefined ) {
76+ if ( httpBaseUrl === undefined ) return { } ;
77+ const diagnostics = getUrlDiagnostics ( httpBaseUrl ) ;
78+ return {
79+ httpBaseUrlInputLength : diagnostics . inputLength ,
80+ ...( diagnostics . protocol === undefined ? { } : { httpBaseUrlProtocol : diagnostics . protocol } ) ,
81+ ...( diagnostics . hostname === undefined ? { } : { httpBaseUrlHostname : diagnostics . hostname } ) ,
82+ } ;
83+ }
84+
6485export const CloudEnvironmentLinkAction = Schema . Literals ( [
6586 "check relay client availability" ,
6687 "confirm relay client installation" ,
@@ -85,8 +106,12 @@ export class CloudEnvironmentLinkOperationError extends Schema.TaggedErrorClass<
85106 {
86107 action : CloudEnvironmentLinkAction ,
87108 environmentId : Schema . optionalKey ( Schema . String ) ,
88- relayUrl : Schema . optionalKey ( Schema . String ) ,
89- httpBaseUrl : Schema . optionalKey ( Schema . String ) ,
109+ relayUrlInputLength : Schema . optionalKey ( Schema . Number ) ,
110+ relayUrlProtocol : Schema . optionalKey ( Schema . String ) ,
111+ relayUrlHostname : Schema . optionalKey ( Schema . String ) ,
112+ httpBaseUrlInputLength : Schema . optionalKey ( Schema . Number ) ,
113+ httpBaseUrlProtocol : Schema . optionalKey ( Schema . String ) ,
114+ httpBaseUrlHostname : Schema . optionalKey ( Schema . String ) ,
90115 traceId : Schema . optionalKey ( Schema . String ) ,
91116 relayError : Schema . optionalKey ( RelayProtectedError ) ,
92117 environmentError : Schema . optionalKey ( EnvironmentCloudApiError ) ,
@@ -106,8 +131,8 @@ export class CloudEnvironmentLinkOperationError extends Schema.TaggedErrorClass<
106131 action : input . action ,
107132 cause : input . cause ,
108133 ...( input . environmentId === undefined ? { } : { environmentId : input . environmentId } ) ,
109- ...( input . relayUrl === undefined ? { } : { relayUrl : input . relayUrl } ) ,
110- ...( input . httpBaseUrl === undefined ? { } : { httpBaseUrl : input . httpBaseUrl } ) ,
134+ ...relayUrlDiagnosticFields ( input . relayUrl ) ,
135+ ...httpBaseUrlDiagnosticFields ( input . httpBaseUrl ) ,
111136 ...( requestFailure ?. traceId === undefined ? { } : { traceId : requestFailure . traceId } ) ,
112137 ...( requestFailure ?. relayError === undefined
113138 ? { }
@@ -127,7 +152,7 @@ export class CloudEnvironmentLinkOperationError extends Schema.TaggedErrorClass<
127152 return new CloudEnvironmentLinkOperationError ( {
128153 action : input . action ,
129154 environmentId : input . environmentId ,
130- httpBaseUrl : input . httpBaseUrl ,
155+ ... httpBaseUrlDiagnosticFields ( input . httpBaseUrl ) ,
131156 cause : input . cause ,
132157 ...( environmentError === undefined ? { } : { environmentError } ) ,
133158 } ) ;
@@ -339,7 +364,7 @@ function endpointOrigin(input: { readonly environmentId: string; readonly httpBa
339364 new CloudEnvironmentLinkOperationError ( {
340365 action : "derive the environment endpoint origin" ,
341366 environmentId : input . environmentId ,
342- httpBaseUrl : input . httpBaseUrl ,
367+ ... httpBaseUrlDiagnosticFields ( input . httpBaseUrl ) ,
343368 cause,
344369 } ) ,
345370 } ) ;
@@ -355,7 +380,7 @@ function makeCloudEnvironmentHttpApiClient(input: {
355380 new CloudEnvironmentLinkOperationError ( {
356381 action : "initialize the environment HTTP client" ,
357382 environmentId : input . environmentId ,
358- httpBaseUrl : input . httpBaseUrl ,
383+ ... httpBaseUrlDiagnosticFields ( input . httpBaseUrl ) ,
359384 cause,
360385 } ) ,
361386 } ) . pipe ( Effect . flatten ) ;
0 commit comments