Skip to content

Commit f00623a

Browse files
committed
removed release feature, added SDK version, improvements and code cleanup
1 parent 672d38b commit f00623a

7 files changed

Lines changed: 26 additions & 50 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "traceo-sdk",
3-
"version": "0.0.78-alpha",
3+
"version": "0.0.82-alpha",
44
"license": "MIT",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/core/http.ts

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,52 @@
11
import * as http from "http";
22
import { sanitizeDsn } from "../node/helpers";
33
import { RequestStatus } from "../transport/enums";
4-
import {
5-
EventResponse,
6-
TraceoEvent,
7-
TraceoReleaseEvent,
8-
} from "../transport/events";
4+
import { EventResponse, TraceoEvent } from "../transport/events";
95
import { TraceoIncomingMessage, RequestOptions } from "../transport/http";
106
import { getGlobalClientData } from "./global";
117
import { isClientConnected } from "./is";
8+
import { TRACEO_SDK_VERSION } from "./version";
129

1310
const createHttpOptions = ({
1411
event,
15-
api,
1612
}: {
17-
event?: TraceoEvent | TraceoReleaseEvent;
18-
api?: string;
13+
event?: TraceoEvent;
1914
}): http.RequestOptions => {
2015
const client = getGlobalClientData();
2116

2217
const { dsn } = client;
2318
const { host, secretKey, appId } = sanitizeDsn(dsn);
2419

25-
api = api === "release" ? `/release/${appId}` : `/${appId}`;
26-
2720
const baseOptions: RequestOptions = {
2821
hostname: host,
2922
method: "POST",
3023
headers: {
3124
"Content-Type": "application/json",
3225
"Content-Length": `${Buffer.byteLength(JSON.stringify(event))}`,
33-
"traceo-secret-key": secretKey,
26+
"Traceo-Secret-Key": secretKey,
3427
},
3528
};
3629

3730
return {
38-
path: api,
31+
path: `/${appId}`,
3932
...baseOptions,
4033
};
4134
};
4235

4336
const statusFromCode = (code: number) =>
4437
code >= 200 && code <= 299 ? RequestStatus.SUCCESS : RequestStatus.ERROR;
4538

46-
export const sendRelease = (connectionData: TraceoReleaseEvent): void => {
47-
const httpOptions = createHttpOptions({
48-
event: connectionData,
49-
api: "release",
50-
});
39+
export const sendEvent = async (
40+
event: TraceoEvent
41+
): Promise<EventResponse | void> => {
42+
const { environment, dsn } = getGlobalClientData();
5143

52-
const request = http.request(httpOptions, (res: TraceoIncomingMessage) => {
53-
res.setEncoding("utf8");
54-
});
55-
request.write(JSON.stringify(connectionData));
56-
request.end();
57-
};
44+
if (!environment || !dsn) {
45+
return;
46+
}
5847

59-
export const sendEvent = async (event: TraceoEvent): Promise<EventResponse> => {
60-
const client = getGlobalClientData();
61-
62-
const baseData = {
63-
version: client?.version,
64-
};
48+
const version = TRACEO_SDK_VERSION;
49+
const baseData = { version, env: environment };
6550

6651
const payload = Object.assign(event, baseData);
6752

src/core/version.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const TRACEO_SDK_VERSION = "0.0.82-alpha";

src/node/sdk.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { setGlobalClientData } from "../core/global";
2-
import { sendRelease } from "../core/http";
32
import { isClientConnected } from "../core/is";
4-
import { TraceoReleaseEvent } from "../transport/events";
53
import { TraceoOptions } from "../transport/options";
6-
import { getOsPlatform } from "./helpers";
74

85
/**
96
*
@@ -18,17 +15,16 @@ export const init = (options: TraceoOptions): void => {
1815
return;
1916
}
2017

18+
if (!options.environment) {
19+
console.warn(
20+
"Traceo SDK: Empty environment property. Please set current env or use use offline mode."
21+
);
22+
return;
23+
}
24+
2125
if (!isClientConnected()) {
2226
setGlobalClientData({
2327
...options,
2428
});
2529
}
26-
27-
const conn: TraceoReleaseEvent = {
28-
env: options?.environment,
29-
version: options?.version,
30-
os: getOsPlatform(),
31-
};
32-
33-
sendRelease(conn);
3430
};

src/transport/base.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import { Environment } from "./types";
2+
13
export interface BaseObject {
24
[key: string]: any;
35
}
46

57
export interface TraceoGlobal {
68
dsn: string;
79
appId?: string;
8-
version?: string;
10+
environment: Environment;
911
}
1012

1113
export interface TraceoError extends Error {}

src/transport/events.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,9 @@ export interface TraceoEvent {
3030
requestData?: TraceoRequest;
3131
catchType?: CatchType;
3232
env?: Environment;
33-
version?: string;
3433
platform: Platform;
3534
}
3635

37-
export interface TraceoReleaseEvent {
38-
version?: string;
39-
env?: Environment;
40-
os: Platform;
41-
}
42-
4336
export interface Platform {
4437
arch: string;
4538
platform: string;

src/transport/options.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Environment } from "./types";
22

33
export interface TraceoOptions {
4-
version?: string;
54
offline?: boolean;
65
environment: Environment;
76
dsn: string;

0 commit comments

Comments
 (0)