11import type { IncomingMessage } from 'http' ;
22import type { Agent } from 'https' ;
33import { request } from 'https' ;
4- import { parse , type UrlWithStringQuery } from 'url' ;
54import { ToolkitError } from '@aws-cdk/toolkit-lib' ;
65import { IoHelper } from '../../../api-private' ;
76import type { IIoHost } from '../../io-host' ;
@@ -39,12 +38,12 @@ export interface EndpointTelemetrySinkProps {
3938 */
4039export class EndpointTelemetrySink implements ITelemetrySink {
4140 private events : TelemetrySchema [ ] = [ ] ;
42- private endpoint : UrlWithStringQuery ;
41+ private endpoint : URL ;
4342 private ioHelper : IoHelper ;
4443 private agent ?: Agent ;
4544
4645 public constructor ( props : EndpointTelemetrySinkProps ) {
47- this . endpoint = parse ( props . endpoint ) ;
46+ this . endpoint = new URL ( props . endpoint ) ;
4847
4948 if ( ! this . endpoint . hostname || ! this . endpoint . pathname ) {
5049 throw new ToolkitError ( `Telemetry Endpoint malformed. Received hostname: ${ this . endpoint . hostname } , pathname: ${ this . endpoint . pathname } ` ) ;
@@ -91,7 +90,7 @@ export class EndpointTelemetrySink implements ITelemetrySink {
9190 * Returns true if telemetry successfully posted, false otherwise.
9291 */
9392 private async https (
94- url : UrlWithStringQuery ,
93+ url : URL ,
9594 body : { events : TelemetrySchema [ ] } ,
9695 ) : Promise < boolean > {
9796 try {
@@ -117,15 +116,15 @@ export class EndpointTelemetrySink implements ITelemetrySink {
117116 * A Promisified version of `https.request()`
118117 */
119118function doRequest (
120- url : UrlWithStringQuery ,
119+ url : URL ,
121120 data : { events : TelemetrySchema [ ] } ,
122121 agent ?: Agent ,
123122) {
124123 return new Promise < IncomingMessage > ( ( ok , ko ) => {
125124 const payload : string = JSON . stringify ( data ) ;
126125 const req = request ( {
127126 hostname : url . hostname ,
128- port : url . port ,
127+ port : url . port || null ,
129128 path : url . pathname ,
130129 method : 'POST' ,
131130 headers : {
0 commit comments