Skip to content

Commit fdd3062

Browse files
committed
version 0.0.2-alpha
1 parent fa25fbb commit fdd3062

19 files changed

Lines changed: 368 additions & 333 deletions

File tree

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
2-
build/
3-
41
# dependencies
52
node_modules/
63
packages/*/dist/
@@ -37,3 +34,6 @@ ui-debug.log
3734

3835
.vscode
3936
.idea
37+
38+
#tarballs
39+
*.tgz

.npmignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is written to be a whitelist instead of a blacklist. Start by
2+
# ignoring everything, then add back the files we want to be included in the
3+
# final NPM package.
4+
*
5+
6+
# And these are the files that are allowed.
7+
!/CHANGELOG.md
8+
!/LICENSE
9+
!/README.md
10+
!/VERSION
11+
!/package.json
12+
!/build/**/*

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# CHANGELOG
22

3+
## 0.0.2-alpha - 2022-03-23
4+
- Migration from monorepo in lerna to single monolith
5+
- Bugfixes
6+
- Using rollup.js
7+
- First working version
8+
-
9+
310
## 0.0.1-alpha - 2022-03-22
411
- Initial release with base client library

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.1-alpha
1+
0.0.2-alpha

index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

lerna.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
{
22
"name": "klepper",
3-
"version": "0.0.1",
3+
"version": "0.0.25-alpha",
44
"license": "MIT",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"files": [
88
"dist"
99
],
1010
"scripts": {
11-
"dev": "rollup -c -w",
12-
"build": "rollup -c",
13-
"prebuild:types": "rimraf ./build",
14-
"build:types": "tsc -p ./tsconfig.json --outDir build --declaration true && api-extractor run",
15-
"predocs": "rimraf ./docs",
16-
"clean": "rimraf ./build ./dist ./docs",
17-
"test": "jest"
11+
"build": "yarn prebuild && tsc -p ./tsconfig.json --outDir dist",
12+
"prebuild": "rimraf ./dist",
13+
"lint": "run-s lint:prettier",
14+
"lint:prettier": "prettier */**/*.{js,ts} --write",
15+
"prepack": "yarn lint",
16+
"package": "yarn build && npm pack",
17+
"test": "jest",
18+
"test:watch": "jest --watch --notify"
1819
},
1920
"dependencies": {},
2021
"devDependencies": {

src/core/global.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import { KlepperGlobal } from "../transport";
2-
3-
/**
4-
* Using internal NodeJS global object to persist information
5-
*
6-
* @returns {KlepperGlobal}
7-
*/
8-
export const getGlobalClientData = (): KlepperGlobal => global.__KLEPPER__ || {};
9-
10-
export const setGlobalClientData = (data: KlepperGlobal): void => {
11-
global.__KLEPPER__ = { ...data };
12-
}
13-
14-
export const clearGlobalClientData = (): void => {
15-
setGlobalClientData({
16-
environment: undefined,
17-
privateKey: undefined
18-
})
19-
}
1+
import { KlepperGlobal } from "../transport";
2+
3+
/**
4+
* Using internal NodeJS global object to persist information
5+
*
6+
* @returns {KlepperGlobal}
7+
*/
8+
export const getGlobalClientData = (): KlepperGlobal =>
9+
global.__KLEPPER__ || {};
10+
11+
export const setGlobalClientData = (data: KlepperGlobal): void => {
12+
global.__KLEPPER__ = { ...data };
13+
};
14+
15+
export const clearGlobalClientData = (): void => {
16+
setGlobalClientData({
17+
environment: undefined,
18+
privateKey: undefined,
19+
});
20+
};

src/core/http.ts

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1-
import { RequestPayload, RequestOptions, KlepperResponse, KlepperIncomingMessage, RequestStatus } from "../transport";
1+
import {
2+
RequestPayload,
3+
RequestOptions,
4+
KlepperResponse,
5+
KlepperIncomingMessage,
6+
RequestStatus,
7+
} from "../transport";
28
import * as http from "http";
39
import { getGlobalClientData } from "./global";
410

511
const KLEPPER_HOST = process.env.KLEPPER_HOST || "localhost";
612
const KLEPPER_API = process.env.KLEPPER_API || "/test";
7-
const KLEPPER_PORT = process.env.KLEPPER_PORT || 3000;
13+
const KLEPPER_PORT = process.env.KLEPPER_PORT || 3000;
814

915
const createHttpOptions = (payload: RequestPayload): http.RequestOptions => {
1016
const client = getGlobalClientData();
17+
1118
const { privateKey } = client;
1219
const { data } = payload;
1320
const baseOptions: RequestOptions = {
1421
hostname: KLEPPER_HOST,
1522
port: +KLEPPER_PORT,
16-
method: 'POST',
23+
method: "POST",
1724
headers: {
18-
'Content-Type': 'application/json',
19-
'Content-Length': `${Buffer.byteLength(JSON.stringify(data))}`,
20-
'Klepper-Project-Key': privateKey as string
21-
}
25+
"Content-Type": "application/json",
26+
"Content-Length": `${Buffer.byteLength(JSON.stringify(data))}`,
27+
"Klepper-Project-Key": privateKey as string,
28+
},
2229
};
2330

2431
return {
@@ -27,63 +34,62 @@ const createHttpOptions = (payload: RequestPayload): http.RequestOptions => {
2734
};
2835
};
2936

30-
const statusFromCode = (code: number) => code >= 200 && code <= 299 ? RequestStatus.SUCCESS : RequestStatus.ERROR;
37+
const statusFromCode = (code: number) =>
38+
code >= 200 && code <= 299 ? RequestStatus.SUCCESS : RequestStatus.ERROR;
3139

3240
/**
3341
* Send data to Klepper server
34-
*
35-
* @param payload
42+
*
43+
* @param payload
3644
*/
37-
export const sendEvent = async (payload: RequestPayload): Promise<KlepperResponse> => {
45+
export const sendEvent = async (
46+
payload: RequestPayload
47+
): Promise<KlepperResponse> => {
3848
const { data } = payload;
3949

40-
// global.Object = Object({ test: "test" })
41-
// console.log("GLOBAL: ", global.Object);
42-
43-
/**
44-
* IMPORTANT TO HANDLE GLOBAL DATA
45-
*/
46-
4750
try {
4851
return new Promise<KlepperResponse>((resolve, reject) => {
4952
const httpOptions = createHttpOptions(payload);
5053
const client = getGlobalClientData();
5154

5255
if (!httpOptions) {
53-
reject(new Error("NO HTTP OPTIONS"))
56+
reject(new Error("NO HTTP OPTIONS"));
5457
}
5558

5659
if (!client) {
57-
reject(new Error("NO CLIENT DATA IN GLOBAL OBJECT"))
60+
reject(new Error("NO CLIENT DATA IN GLOBAL OBJECT"));
5861
}
5962

60-
const request = http.request(httpOptions, (res: KlepperIncomingMessage) => {
61-
res.setEncoding("utf8");
63+
const request = http.request(
64+
httpOptions,
65+
(res: KlepperIncomingMessage) => {
66+
res.setEncoding("utf8");
6267

63-
const status = statusFromCode(res?.statusCode as number);
64-
const isSuccess = status === RequestStatus.SUCCESS;
68+
const status = statusFromCode(res?.statusCode as number);
69+
const isSuccess = status === RequestStatus.SUCCESS;
6570

66-
if (!isSuccess) {
67-
reject(new Error("HTTP ERROR: ${res.statusCode}"))
68-
} else {
69-
resolve({
70-
statusCode: res?.statusCode as number,
71-
statusMessage: "Event successfully sended to Klepper"
72-
})
71+
if (!isSuccess) {
72+
reject(new Error("HTTP ERROR: ${res.statusCode}"));
73+
} else {
74+
resolve({
75+
statusCode: res?.statusCode as number,
76+
statusMessage: "Event successfully sended to Klepper",
77+
});
78+
}
79+
80+
res.on("error", reject);
7381
}
74-
75-
res.on("error", reject);
76-
});
82+
);
7783
request.on("error", reject);
7884

79-
request.on('timeout', () => {
80-
request.destroy()
85+
request.on("timeout", () => {
86+
request.destroy();
8187
reject(new Error("TIMEOUT"));
82-
})
88+
});
8389

8490
request.write(JSON.stringify(data));
8591
request.end();
86-
})
92+
});
8793
} catch (error) {
8894
throw new Error(""); //to properly handling
8995
}

src/core/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as http from "./http";
2-
import * as global from "./global";
3-
4-
export { http, global };
1+
import * as http from "./http";
2+
import * as global from "./global";
3+
4+
export { http, global };

0 commit comments

Comments
 (0)