@kivia/sdk 0.1.0 → 0.1.2
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/README.md +20 -1
- package/dist/client.d.ts +11 -5
- package/dist/client.js +32 -8
- package/dist/fastify.d.ts +4 -5
- package/dist/fastify.js +5 -6
- package/dist/hono.d.ts +12 -0
- package/dist/hono.js +18 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/types.d.ts +1 -2
- package/dist/types.js +0 -1
- package/package.json +10 -2
- package/.github/workflows/release.yml +0 -28
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/fastify.d.ts.map +0 -1
- package/dist/fastify.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- 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/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Kivia TypeScript SDK
|
|
2
2
|
|
|
3
|
-
The Kivia TypeScript SDK is the official Node.js client for the Kivia observability platform. It allows Node.js developers using Express or
|
|
3
|
+
The Kivia TypeScript SDK is the official Node.js client for the Kivia observability platform. It allows Node.js developers using Express, Fastify, or Hono to instantly track API request metrics, response times, and paths.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -76,3 +76,22 @@ fastify.get('/hello', async (request, reply) => {
|
|
|
76
76
|
|
|
77
77
|
fastify.listen({ port: 3000 });
|
|
78
78
|
```
|
|
79
|
+
|
|
80
|
+
## Quick Start (with Hono)
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { Hono } from 'hono';
|
|
84
|
+
import { kiviaHonoMiddleware } from '@kivia/sdk';
|
|
85
|
+
|
|
86
|
+
const app = new Hono();
|
|
87
|
+
|
|
88
|
+
app.use('*', kiviaHonoMiddleware({
|
|
89
|
+
apiKey: 'YOUR_KIVIA_API_KEY',
|
|
90
|
+
}));
|
|
91
|
+
|
|
92
|
+
app.get('/hello', (c) => {
|
|
93
|
+
return c.json({ message: 'Hello from Kivia TS SDK using Hono!' });
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
export default app;
|
|
97
|
+
```
|
package/dist/client.d.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
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
|
+
/**
|
|
16
|
+
* Hono middleware for automatically logging requests.
|
|
17
|
+
*
|
|
18
|
+
* Usage with Hono:
|
|
19
|
+
* app.use('*', kiviaClient.logHono());
|
|
20
|
+
*/
|
|
21
|
+
logHono(): (c: any, next: any) => Promise<void>;
|
|
15
22
|
private sendLog;
|
|
16
23
|
}
|
|
17
|
-
//# sourceMappingURL=client.d.ts.map
|
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) => {
|
|
@@ -47,25 +47,49 @@ class DynoClient {
|
|
|
47
47
|
this.sendLog(logEntry);
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Hono middleware for automatically logging requests.
|
|
52
|
+
*
|
|
53
|
+
* Usage with Hono:
|
|
54
|
+
* app.use('*', kiviaClient.logHono());
|
|
55
|
+
*/
|
|
56
|
+
logHono() {
|
|
57
|
+
return async (c, next) => {
|
|
58
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
59
|
+
const start = Date.now();
|
|
60
|
+
await next();
|
|
61
|
+
const latency = Date.now() - start;
|
|
62
|
+
const logEntry = {
|
|
63
|
+
path: c.req.path || c.req.url,
|
|
64
|
+
status: c.res.status,
|
|
65
|
+
ip_address: ((_b = (_a = c.req).header) === null || _b === void 0 ? void 0 : _b.call(_a, 'x-forwarded-for')) ||
|
|
66
|
+
((_d = (_c = c.req).header) === null || _d === void 0 ? void 0 : _d.call(_c, 'x-real-ip')) ||
|
|
67
|
+
((_f = (_e = c.req.raw) === null || _e === void 0 ? void 0 : _e.headers) === null || _f === void 0 ? void 0 : _f['x-forwarded-for']) ||
|
|
68
|
+
((_h = (_g = c.req.raw) === null || _g === void 0 ? void 0 : _g.socket) === null || _h === void 0 ? void 0 : _h.remoteAddress),
|
|
69
|
+
timestamp: new Date().toISOString(),
|
|
70
|
+
latency,
|
|
71
|
+
};
|
|
72
|
+
this.sendLog(logEntry);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
50
75
|
async sendLog(logEntry) {
|
|
51
76
|
try {
|
|
52
77
|
const response = await fetch(`${this.baseUrl}/logs/create`, {
|
|
53
78
|
method: 'POST',
|
|
54
79
|
headers: {
|
|
55
80
|
'Content-Type': 'application/json',
|
|
56
|
-
'X-
|
|
81
|
+
'X-kivia-api-key': this.apiKey,
|
|
57
82
|
},
|
|
58
83
|
body: JSON.stringify(logEntry),
|
|
59
84
|
});
|
|
60
85
|
if (!response.ok) {
|
|
61
86
|
const errBody = await response.text();
|
|
62
|
-
console.error(`
|
|
87
|
+
console.error(`kiviasdk: log rejected (${response.status}): ${errBody}`);
|
|
63
88
|
}
|
|
64
89
|
}
|
|
65
90
|
catch (error) {
|
|
66
|
-
console.error('
|
|
91
|
+
console.error('kiviasdk: failed to send log:', error);
|
|
67
92
|
}
|
|
68
93
|
}
|
|
69
94
|
}
|
|
70
|
-
exports.
|
|
71
|
-
//# sourceMappingURL=client.js.map
|
|
95
|
+
exports.KiviaClient = KiviaClient;
|
package/dist/fastify.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
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
|
|
7
|
-
//# sourceMappingURL=fastify.d.ts.map
|
|
6
|
+
export declare function kiviaFastifyPlugin(fastify: any, options: KiviaClientOptions): Promise<void>;
|
package/dist/fastify.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
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
|
-
//# sourceMappingURL=fastify.js.map
|
package/dist/hono.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { KiviaClientOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Hono middleware factory for Kivia observability.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* import { Hono } from 'hono';
|
|
7
|
+
* import { kiviaHonoMiddleware } from '@kivia/sdk';
|
|
8
|
+
*
|
|
9
|
+
* const app = new Hono();
|
|
10
|
+
* app.use('*', kiviaHonoMiddleware({ apiKey: 'YOUR_KIVIA_API_KEY' }));
|
|
11
|
+
*/
|
|
12
|
+
export declare function kiviaHonoMiddleware(options: KiviaClientOptions): (c: any, next: any) => Promise<void>;
|
package/dist/hono.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.kiviaHonoMiddleware = kiviaHonoMiddleware;
|
|
4
|
+
const client_1 = require("./client");
|
|
5
|
+
/**
|
|
6
|
+
* Hono middleware factory for Kivia observability.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import { Hono } from 'hono';
|
|
10
|
+
* import { kiviaHonoMiddleware } from '@kivia/sdk';
|
|
11
|
+
*
|
|
12
|
+
* const app = new Hono();
|
|
13
|
+
* app.use('*', kiviaHonoMiddleware({ apiKey: 'YOUR_KIVIA_API_KEY' }));
|
|
14
|
+
*/
|
|
15
|
+
function kiviaHonoMiddleware(options) {
|
|
16
|
+
const client = new client_1.KiviaClient(options);
|
|
17
|
+
return client.logHono();
|
|
18
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -17,4 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./types"), exports);
|
|
18
18
|
__exportStar(require("./client"), exports);
|
|
19
19
|
__exportStar(require("./fastify"), exports);
|
|
20
|
-
|
|
20
|
+
__exportStar(require("./hono"), exports);
|
package/dist/types.d.ts
CHANGED
|
@@ -6,11 +6,10 @@ export interface Log {
|
|
|
6
6
|
timestamp: string;
|
|
7
7
|
latency: number;
|
|
8
8
|
}
|
|
9
|
-
export interface
|
|
9
|
+
export interface KiviaClientOptions {
|
|
10
10
|
apiKey: string;
|
|
11
11
|
/**
|
|
12
12
|
* Override the default production base URL.
|
|
13
13
|
*/
|
|
14
14
|
baseUrl?: string;
|
|
15
15
|
}
|
|
16
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.js
CHANGED
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.2"
|
|
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/dist/client.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAO,MAAM,SAAS,CAAC;AAEjD,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,iBAAiB;IAKtC;;OAEG;IACI,aAAa,KACV,KAAK,GAAG,EAAE,KAAK,GAAG,EAAE,MAAM,GAAG;IAsBvC;;;OAGG;IACI,oBAAoB,KACX,SAAS,GAAG,EAAE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ED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5C;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,iBAAiB,iBAG/E"}
|
package/dist/fastify.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fastify.js","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":";;AAOA,8CAGC;AAVD,qCAAsC;AAGtC;;;GAGG;AACI,KAAK,UAAU,iBAAiB,CAAC,OAAY,EAAE,OAA0B;IAC9E,MAAM,MAAM,GAAG,IAAI,mBAAU,CAAC,OAAO,CAAC,CAAC;IACvC,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,oBAAoB,EAAE,CAAC,CAAC;AAC/D,CAAC"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,2CAAyB;AACzB,4CAA0B"}
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
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
|
-
}
|