@kivia/sdk 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +4 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +7 -7
- package/dist/client.js.map +1 -1
- package/dist/fastify.d.ts +4 -4
- package/dist/fastify.d.ts.map +1 -1
- package/dist/fastify.js +5 -5
- package/dist/fastify.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +10 -2
- package/.github/workflows/release.yml +0 -28
- package/src/client.ts +0 -78
- package/src/fastify.ts +0 -11
- package/src/index.ts +0 -3
- package/src/types.ts +0 -16
- package/tsconfig.json +0 -18
package/dist/client.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class
|
|
1
|
+
import { KiviaClientOptions } from './types';
|
|
2
|
+
export declare class KiviaClient {
|
|
3
3
|
private apiKey;
|
|
4
4
|
private baseUrl;
|
|
5
|
-
constructor(options:
|
|
5
|
+
constructor(options: KiviaClientOptions);
|
|
6
6
|
/**
|
|
7
7
|
* Express/Connect middleware for automatically logging requests.
|
|
8
8
|
*/
|
|
9
9
|
logMiddleware(): (req: any, res: any, next: any) => void;
|
|
10
10
|
/**
|
|
11
11
|
* Fastify hook variant to be used with the 'onResponse' lifecycle hook.
|
|
12
|
-
* Usage: fastify.addHook('onResponse',
|
|
12
|
+
* Usage: fastify.addHook('onResponse', kiviaClient.logFastifyOnResponse());
|
|
13
13
|
*/
|
|
14
14
|
logFastifyOnResponse(): (request: any, reply: any) => Promise<void>;
|
|
15
15
|
private sendLog;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAO,MAAM,SAAS,CAAC;AAElD,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,kBAAkB;IAKvC;;OAEG;IACI,aAAa,KACV,KAAK,GAAG,EAAE,KAAK,GAAG,EAAE,MAAM,GAAG;IAsBvC;;;OAGG;IACI,oBAAoB,KACX,SAAS,GAAG,EAAE,OAAO,GAAG;YAgB1B,OAAO;CAmBtB"}
|
package/dist/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
class
|
|
3
|
+
exports.KiviaClient = void 0;
|
|
4
|
+
class KiviaClient {
|
|
5
5
|
constructor(options) {
|
|
6
6
|
this.apiKey = options.apiKey;
|
|
7
7
|
this.baseUrl = options.baseUrl || 'https://nginx-production-a9aa.up.railway.app/api/v1';
|
|
@@ -30,7 +30,7 @@ class DynoClient {
|
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Fastify hook variant to be used with the 'onResponse' lifecycle hook.
|
|
33
|
-
* Usage: fastify.addHook('onResponse',
|
|
33
|
+
* Usage: fastify.addHook('onResponse', kiviaClient.logFastifyOnResponse());
|
|
34
34
|
*/
|
|
35
35
|
logFastifyOnResponse() {
|
|
36
36
|
return async (request, reply) => {
|
|
@@ -53,19 +53,19 @@ class DynoClient {
|
|
|
53
53
|
method: 'POST',
|
|
54
54
|
headers: {
|
|
55
55
|
'Content-Type': 'application/json',
|
|
56
|
-
'X-
|
|
56
|
+
'X-kivia-api-key': this.apiKey,
|
|
57
57
|
},
|
|
58
58
|
body: JSON.stringify(logEntry),
|
|
59
59
|
});
|
|
60
60
|
if (!response.ok) {
|
|
61
61
|
const errBody = await response.text();
|
|
62
|
-
console.error(`
|
|
62
|
+
console.error(`kiviasdk: log rejected (${response.status}): ${errBody}`);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
catch (error) {
|
|
66
|
-
console.error('
|
|
66
|
+
console.error('kiviasdk: failed to send log:', error);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
exports.
|
|
70
|
+
exports.KiviaClient = KiviaClient;
|
|
71
71
|
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAEA,MAAa,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAEA,MAAa,WAAW;IAItB,YAAY,OAA2B;QACrC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,qDAAqD,CAAC;IAC1F,CAAC;IAED;;OAEG;IACI,aAAa;QAClB,OAAO,CAAC,GAAQ,EAAE,GAAQ,EAAE,IAAS,EAAE,EAAE;YACvC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAEzB,oCAAoC;YACpC,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;;gBACpB,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;gBAEnC,MAAM,QAAQ,GAAQ;oBACpB,IAAI,EAAE,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,GAAG;oBAChC,MAAM,EAAE,GAAG,CAAC,UAAU;oBACtB,UAAU,EAAE,GAAG,CAAC,EAAE,KAAI,MAAA,GAAG,CAAC,UAAU,0CAAE,aAAa,CAAA;oBACnD,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;oBACnC,OAAO;iBACR,CAAC;gBAEF,IAAI,CAA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MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACtC,OAAO,CAAC,KAAK,CAAC,2BAA2B,QAAQ,CAAC,MAAM,MAAM,OAAO,EAAE,CAAC,CAAC;YAC3E,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;CACF;AA3ED,kCA2EC"}
|
package/dist/fastify.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { KiviaClientOptions } from './types';
|
|
2
2
|
/**
|
|
3
|
-
* Fastify plugin for
|
|
4
|
-
* Usage: fastify.register(
|
|
3
|
+
* Fastify plugin for Kivia observability.
|
|
4
|
+
* Usage: fastify.register(kiviaFastifyPlugin, { apiKey: '...' })
|
|
5
5
|
*/
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function kiviaFastifyPlugin(fastify: any, options: KiviaClientOptions): Promise<void>;
|
|
7
7
|
//# sourceMappingURL=fastify.d.ts.map
|
package/dist/fastify.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,kBAAkB,iBAGjF"}
|
package/dist/fastify.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.kiviaFastifyPlugin = kiviaFastifyPlugin;
|
|
4
4
|
const client_1 = require("./client");
|
|
5
5
|
/**
|
|
6
|
-
* Fastify plugin for
|
|
7
|
-
* Usage: fastify.register(
|
|
6
|
+
* Fastify plugin for Kivia observability.
|
|
7
|
+
* Usage: fastify.register(kiviaFastifyPlugin, { apiKey: '...' })
|
|
8
8
|
*/
|
|
9
|
-
async function
|
|
10
|
-
const client = new client_1.
|
|
9
|
+
async function kiviaFastifyPlugin(fastify, options) {
|
|
10
|
+
const client = new client_1.KiviaClient(options);
|
|
11
11
|
fastify.addHook('onResponse', client.logFastifyOnResponse());
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=fastify.js.map
|
package/dist/fastify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastify.js","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":";;AAOA,
|
|
1
|
+
{"version":3,"file":"fastify.js","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":";;AAOA,gDAGC;AAVD,qCAAuC;AAGvC;;;GAGG;AACI,KAAK,UAAU,kBAAkB,CAAC,OAAY,EAAE,OAA2B;IAChF,MAAM,MAAM,GAAG,IAAI,oBAAW,CAAC,OAAO,CAAC,CAAC;IACxC,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,oBAAoB,EAAE,CAAC,CAAC;AAC/D,CAAC"}
|
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kivia/sdk",
|
|
3
|
-
"version": "0.1.0",
|
|
4
3
|
"description": "TypeScript SDK for the Kivia API observability platform",
|
|
5
4
|
"main": "dist/index.js",
|
|
6
5
|
"types": "dist/index.d.ts",
|
|
@@ -15,9 +14,18 @@
|
|
|
15
14
|
"sdk"
|
|
16
15
|
],
|
|
17
16
|
"author": "winnerx0",
|
|
17
|
+
"repository": {
|
|
18
|
+
"url": "https://github.com/kivia-observe/kivia-sdk-js"
|
|
19
|
+
},
|
|
18
20
|
"license": "MIT",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist/**/*",
|
|
23
|
+
"README.md",
|
|
24
|
+
"package.json"
|
|
25
|
+
],
|
|
19
26
|
"devDependencies": {
|
|
20
27
|
"@types/node": "^25.5.2",
|
|
21
28
|
"typescript": "^5.4.0"
|
|
22
|
-
}
|
|
29
|
+
},
|
|
30
|
+
"version": "0.1.1"
|
|
23
31
|
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
name: release
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
tags:
|
|
6
|
-
- "v*"
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
publish:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
permissions:
|
|
12
|
-
contents: write
|
|
13
|
-
id-token: write
|
|
14
|
-
steps:
|
|
15
|
-
- uses: actions/checkout@v4
|
|
16
|
-
- uses: actions/setup-node@v4
|
|
17
|
-
with:
|
|
18
|
-
node-version: "22"
|
|
19
|
-
registry-url: "https://registry.npmjs.org"
|
|
20
|
-
- run: npm ci
|
|
21
|
-
- run: npm run build
|
|
22
|
-
- run: npm publish --provenance --access public
|
|
23
|
-
env:
|
|
24
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
25
|
-
- name: Create GitHub Release
|
|
26
|
-
uses: softprops/action-gh-release@v2
|
|
27
|
-
with:
|
|
28
|
-
generate_release_notes: true
|
package/src/client.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { KiviaClientOptions, Log } from './types';
|
|
2
|
-
|
|
3
|
-
export class KiviaClient {
|
|
4
|
-
private apiKey: string;
|
|
5
|
-
private baseUrl: string;
|
|
6
|
-
|
|
7
|
-
constructor(options: KiviaClientOptions) {
|
|
8
|
-
this.apiKey = options.apiKey;
|
|
9
|
-
this.baseUrl = options.baseUrl || 'https://nginx-production-a9aa.up.railway.app/api/v1';
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Express/Connect middleware for automatically logging requests.
|
|
14
|
-
*/
|
|
15
|
-
public logMiddleware() {
|
|
16
|
-
return (req: any, res: any, next: any) => {
|
|
17
|
-
const start = Date.now();
|
|
18
|
-
|
|
19
|
-
// Listen for the response to finish
|
|
20
|
-
res.on('finish', () => {
|
|
21
|
-
const latency = Date.now() - start;
|
|
22
|
-
|
|
23
|
-
const logEntry: Log = {
|
|
24
|
-
path: req.originalUrl || req.url,
|
|
25
|
-
status: res.statusCode,
|
|
26
|
-
ip_address: req.ip || req.connection?.remoteAddress,
|
|
27
|
-
timestamp: new Date().toISOString(),
|
|
28
|
-
latency,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
this.sendLog(logEntry);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
next();
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Fastify hook variant to be used with the 'onResponse' lifecycle hook.
|
|
40
|
-
* Usage: fastify.addHook('onResponse', kiviaClient.logFastifyOnResponse());
|
|
41
|
-
*/
|
|
42
|
-
public logFastifyOnResponse() {
|
|
43
|
-
return async (request: any, reply: any) => {
|
|
44
|
-
// reply.getResponseTime() is available in Fastify to get latency in ms
|
|
45
|
-
const latency = reply.getResponseTime ? reply.getResponseTime() : 0;
|
|
46
|
-
|
|
47
|
-
const logEntry: Log = {
|
|
48
|
-
path: request.url || request.raw?.url,
|
|
49
|
-
status: reply.statusCode || reply.raw?.statusCode,
|
|
50
|
-
ip_address: request.ip || request.raw?.connection?.remoteAddress,
|
|
51
|
-
timestamp: new Date().toISOString(),
|
|
52
|
-
latency: Math.round(latency),
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
this.sendLog(logEntry);
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
private async sendLog(logEntry: Log): Promise<void> {
|
|
60
|
-
try {
|
|
61
|
-
const response = await fetch(`${this.baseUrl}/logs/create`, {
|
|
62
|
-
method: 'POST',
|
|
63
|
-
headers: {
|
|
64
|
-
'Content-Type': 'application/json',
|
|
65
|
-
'X-kivia-api-key': this.apiKey,
|
|
66
|
-
},
|
|
67
|
-
body: JSON.stringify(logEntry),
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
if (!response.ok) {
|
|
71
|
-
const errBody = await response.text();
|
|
72
|
-
console.error(`kiviasdk: log rejected (${response.status}): ${errBody}`);
|
|
73
|
-
}
|
|
74
|
-
} catch (error) {
|
|
75
|
-
console.error('kiviasdk: failed to send log:', error);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
package/src/fastify.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { KiviaClient } from './client';
|
|
2
|
-
import { KiviaClientOptions } from './types';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Fastify plugin for Kivia observability.
|
|
6
|
-
* Usage: fastify.register(kiviaFastifyPlugin, { apiKey: '...' })
|
|
7
|
-
*/
|
|
8
|
-
export async function kiviaFastifyPlugin(fastify: any, options: KiviaClientOptions) {
|
|
9
|
-
const client = new KiviaClient(options);
|
|
10
|
-
fastify.addHook('onResponse', client.logFastifyOnResponse());
|
|
11
|
-
}
|
package/src/index.ts
DELETED
package/src/types.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export interface Log {
|
|
2
|
-
id?: string;
|
|
3
|
-
path: string;
|
|
4
|
-
status: number;
|
|
5
|
-
ip_address?: string;
|
|
6
|
-
timestamp: string; // ISO 8601
|
|
7
|
-
latency: number; // milliseconds
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface KiviaClientOptions {
|
|
11
|
-
apiKey: string;
|
|
12
|
-
/**
|
|
13
|
-
* Override the default production base URL.
|
|
14
|
-
*/
|
|
15
|
-
baseUrl?: string;
|
|
16
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2018",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"lib": ["ES2022", "DOM"],
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"declarationMap": true,
|
|
8
|
-
"sourceMap": true,
|
|
9
|
-
"outDir": "./dist",
|
|
10
|
-
"rootDir": "./src",
|
|
11
|
-
"strict": true,
|
|
12
|
-
"esModuleInterop": true,
|
|
13
|
-
"skipLibCheck": true,
|
|
14
|
-
"forceConsistentCasingInFileNames": true
|
|
15
|
-
},
|
|
16
|
-
"include": ["src/**/*"],
|
|
17
|
-
"exclude": ["node_modules", "dist"]
|
|
18
|
-
}
|