11import * as http from "http" ;
2+ import { sanitizeDsn } from "../node/helpers" ;
23import { RequestStatus } from "../transport/enums" ;
34import {
45 EventResponse ,
5- KlepperEvent ,
6- KlepperReleaseEvent ,
6+ TraceoEvent ,
7+ TraceoReleaseEvent ,
78} from "../transport/events" ;
8- import { KlepperIncomingMessage , RequestOptions } from "../transport/http" ;
9+ import { TraceoIncomingMessage , RequestOptions } from "../transport/http" ;
910import { getGlobalClientData } from "./global" ;
1011import { isClientConnected } from "./is" ;
1112
12- const KLEPPER_HOST = process . env . KLEPPER_HOST || "localhost" ;
13- const KLEPPER_API = process . env . KLEPPER_API || "/sdk/incident" ;
14- const KLEPPER_PORT = process . env . KLEPPER_PORT || 8080 ;
15-
1613const createHttpOptions = ( {
1714 event,
18- api = KLEPPER_API ,
15+ api,
1916} : {
20- event ?: KlepperEvent | KlepperReleaseEvent ;
17+ event ?: TraceoEvent | TraceoReleaseEvent ;
2118 api ?: string ;
2219} ) : http . RequestOptions => {
2320 const client = getGlobalClientData ( ) ;
2421
25- const { privateKey, appId } = client ;
22+ const { dsn } = client ;
23+ const { host, secretKey, appId } = sanitizeDsn ( dsn ) ;
24+
25+ api = api === "release" ? `/release/${ appId } ` : `/${ appId } ` ;
26+
2627 const baseOptions : RequestOptions = {
27- hostname : KLEPPER_HOST ,
28- port : + KLEPPER_PORT ,
28+ hostname : host ,
2929 method : "POST" ,
3030 headers : {
3131 "Content-Type" : "application/json" ,
3232 "Content-Length" : `${ Buffer . byteLength ( JSON . stringify ( event ) ) } ` ,
33- "klepper-private-key" : String ( privateKey ) ,
34- "klepper-app-id" : String ( appId ) ,
33+ "traceo-secret-key" : secretKey
3534 } ,
3635 } ;
3736
@@ -44,26 +43,25 @@ const createHttpOptions = ({
4443const statusFromCode = ( code : number ) =>
4544 code >= 200 && code <= 299 ? RequestStatus . SUCCESS : RequestStatus . ERROR ;
4645
47- export const sendConnection = ( connectionData : KlepperReleaseEvent ) : void => {
46+ export const sendConnection = ( connectionData : TraceoReleaseEvent ) : void => {
4847 const httpOptions = createHttpOptions ( {
4948 event : connectionData ,
50- api : "/sdk/ release" ,
49+ api : "release" ,
5150 } ) ;
5251
53- const request = http . request ( httpOptions , ( res : KlepperIncomingMessage ) => {
52+ const request = http . request ( httpOptions , ( res : TraceoIncomingMessage ) => {
5453 res . setEncoding ( "utf8" ) ;
5554 } ) ;
5655 request . write ( JSON . stringify ( connectionData ) ) ;
5756 request . end ( ) ;
5857} ;
5958
6059export const sendEvent = async (
61- event : KlepperEvent
60+ event : TraceoEvent
6261) : Promise < EventResponse > => {
6362 const client = getGlobalClientData ( ) ;
6463
6564 const baseData = {
66- env : client ?. environment ,
6765 version : client ?. version ,
6866 } ;
6967
@@ -75,19 +73,19 @@ export const sendEvent = async (
7573 reject ( {
7674 statusCode : 400 ,
7775 statusMessage :
78- "[Klepper ] Error during sending event to Klepper . No HTTP options." ,
76+ "[Traceo ] Error during sending event to Traceo . No HTTP options." ,
7977 } ) ;
8078 }
8179
8280 if ( ! isClientConnected ( ) ) {
8381 reject ( {
8482 statusCode : 400 ,
8583 statusMessage :
86- "[Klepper ] Error during sending event to Klepper . No client global data in NodeJS scope." ,
84+ "[Traceo ] Error during sending event to Traceo . No client global data in NodeJS scope." ,
8785 } ) ;
8886 }
8987
90- const request = http . request ( httpOptions , ( res : KlepperIncomingMessage ) => {
88+ const request = http . request ( httpOptions , ( res : TraceoIncomingMessage ) => {
9189 res . setEncoding ( "utf8" ) ;
9290
9391 const status = statusFromCode ( res ?. statusCode as number ) ;
@@ -96,12 +94,12 @@ export const sendEvent = async (
9694 if ( ! isSuccess ) {
9795 reject ( {
9896 statusCode : res ?. statusCode as number ,
99- statusMessage : "[KLEPPER ] Error during sending event to Klepper ." ,
97+ statusMessage : "[Traceo ] Error during sending event to Traceo ." ,
10098 } ) ;
10199 } else {
102100 resolve ( {
103101 statusCode : res ?. statusCode as number ,
104- statusMessage : "[KLEPPER ] Event successfully sended to Klepper ." ,
102+ statusMessage : "[Traceo ] Event successfully sended to Traceo ." ,
105103 } ) ;
106104 }
107105
@@ -115,7 +113,7 @@ export const sendEvent = async (
115113 reject ( {
116114 statusCode : 400 ,
117115 statusMessage :
118- "[Klepper ] Error during sending event to Klepper . Connection timeout." ,
116+ "[Traceo ] Error during sending event to Traceo . Connection timeout." ,
119117 } ) ;
120118 } ) ;
121119
0 commit comments