@kargo-pulse/core 0.1.0
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/index.cjs +2 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.js +94 -0
- package/package.json +32 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=100,d="[REDACTED]",l=/cookie|token|authorization|password|passwd|secret|credential|session/i;function c(){const e=Math.random().toString(36).slice(2,10);return`evt_${Date.now().toString(36)}_${e}`}function i(e){return e instanceof Error?{name:e.name,message:e.message,stack:e.stack}:typeof e=="string"?{name:"NonError",message:e}:{name:"NonError",message:h(e)}}function g(e,t){const r=i(e);return u({eventId:c(),type:"error",level:"error",appId:t.appId,env:t.env,release:t.release,timestamp:new Date().toISOString(),url:t.url,route:t.route,userAgent:t.userAgent,payload:{...r,source:t.source,component:t.component,handled:t.handled??!0},context:t.context,tags:t.tags,user:t.user})}function E(e=1){return e>=1?!0:e<=0?!1:Math.random()<e}function u(e){return o(e)}function m(e={}){const t=e.maxSize??f,r=[];return{push(n){r.push(n),r.length>t&&r.splice(0,r.length-t)},drain(){return r.splice(0,r.length)},size(){return r.length},async flush(n){if(r.length===0)return!0;const s=r.splice(0,r.length),a=await n(s);return a||r.unshift(...s),a}}}function o(e){if(Array.isArray(e))return e.map(t=>o(t));if(e&&typeof e=="object"){const t={};for(const[r,n]of Object.entries(e))t[r]=l.test(r)?d:o(n);return t}return e}function h(e){try{return JSON.stringify(e)}catch{return String(e)}}exports.createErrorEvent=g;exports.createEventId=c;exports.createMemoryQueue=m;exports.redactSensitiveData=u;exports.serializeError=i;exports.shouldSample=E;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export type PulseEventType = 'error' | 'click' | 'api' | 'performance';
|
|
2
|
+
export type PulseLevel = 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
3
|
+
export interface PulseUser {
|
|
4
|
+
id?: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
email?: string;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
export interface ErrorPayload {
|
|
10
|
+
message: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
stack?: string;
|
|
13
|
+
source?: string;
|
|
14
|
+
component?: string;
|
|
15
|
+
handled?: boolean;
|
|
16
|
+
resolvedStack?: ResolvedStackFrame[];
|
|
17
|
+
}
|
|
18
|
+
export interface ResolvedStackFrame {
|
|
19
|
+
generatedFile: string;
|
|
20
|
+
generatedLine: number;
|
|
21
|
+
generatedColumn: number;
|
|
22
|
+
source?: string;
|
|
23
|
+
line?: number;
|
|
24
|
+
column?: number;
|
|
25
|
+
name?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface PulseEvent<TPayload = unknown> {
|
|
28
|
+
eventId: string;
|
|
29
|
+
type: PulseEventType;
|
|
30
|
+
level: PulseLevel;
|
|
31
|
+
appId: string;
|
|
32
|
+
env: string;
|
|
33
|
+
release: string;
|
|
34
|
+
timestamp: string;
|
|
35
|
+
url?: string;
|
|
36
|
+
route?: string;
|
|
37
|
+
userAgent?: string;
|
|
38
|
+
payload: TPayload;
|
|
39
|
+
context?: Record<string, unknown>;
|
|
40
|
+
tags?: Record<string, string>;
|
|
41
|
+
user?: PulseUser;
|
|
42
|
+
}
|
|
43
|
+
export interface ErrorEventInput {
|
|
44
|
+
appId: string;
|
|
45
|
+
env: string;
|
|
46
|
+
release: string;
|
|
47
|
+
url?: string;
|
|
48
|
+
route?: string;
|
|
49
|
+
userAgent?: string;
|
|
50
|
+
source?: string;
|
|
51
|
+
component?: string;
|
|
52
|
+
handled?: boolean;
|
|
53
|
+
context?: Record<string, unknown>;
|
|
54
|
+
tags?: Record<string, string>;
|
|
55
|
+
user?: PulseUser;
|
|
56
|
+
}
|
|
57
|
+
export interface Transport {
|
|
58
|
+
send(events: PulseEvent[], options?: TransportSendOptions): Promise<boolean>;
|
|
59
|
+
}
|
|
60
|
+
export interface TransportSendOptions {
|
|
61
|
+
useBeacon?: boolean;
|
|
62
|
+
}
|
|
63
|
+
export interface LogSink {
|
|
64
|
+
write(events: PulseEvent[]): Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
export interface ClsSinkConfig {
|
|
67
|
+
region: string;
|
|
68
|
+
topicId: string;
|
|
69
|
+
secretId?: string;
|
|
70
|
+
secretKey?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface MemoryQueueOptions {
|
|
73
|
+
maxSize?: number;
|
|
74
|
+
maxRetries?: number;
|
|
75
|
+
}
|
|
76
|
+
export interface MemoryQueue<T> {
|
|
77
|
+
push(item: T): void;
|
|
78
|
+
drain(): T[];
|
|
79
|
+
size(): number;
|
|
80
|
+
flush(sender: (items: T[]) => Promise<boolean>): Promise<boolean>;
|
|
81
|
+
}
|
|
82
|
+
export declare function createEventId(): string;
|
|
83
|
+
export declare function serializeError(error: unknown): ErrorPayload;
|
|
84
|
+
export declare function createErrorEvent(error: unknown, input: ErrorEventInput): PulseEvent<ErrorPayload>;
|
|
85
|
+
export declare function shouldSample(sampleRate?: number): boolean;
|
|
86
|
+
export declare function redactSensitiveData<T>(value: T): T;
|
|
87
|
+
export declare function createMemoryQueue<T>(options?: MemoryQueueOptions): MemoryQueue<T>;
|
|
88
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const c = "[REDACTED]", i = /cookie|token|authorization|password|passwd|secret|credential|session/i;
|
|
2
|
+
function u() {
|
|
3
|
+
const e = Math.random().toString(36).slice(2, 10);
|
|
4
|
+
return `evt_${Date.now().toString(36)}_${e}`;
|
|
5
|
+
}
|
|
6
|
+
function f(e) {
|
|
7
|
+
return e instanceof Error ? {
|
|
8
|
+
name: e.name,
|
|
9
|
+
message: e.message,
|
|
10
|
+
stack: e.stack
|
|
11
|
+
} : typeof e == "string" ? {
|
|
12
|
+
name: "NonError",
|
|
13
|
+
message: e
|
|
14
|
+
} : {
|
|
15
|
+
name: "NonError",
|
|
16
|
+
message: d(e)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function g(e, t) {
|
|
20
|
+
const r = f(e);
|
|
21
|
+
return E({
|
|
22
|
+
eventId: u(),
|
|
23
|
+
type: "error",
|
|
24
|
+
level: "error",
|
|
25
|
+
appId: t.appId,
|
|
26
|
+
env: t.env,
|
|
27
|
+
release: t.release,
|
|
28
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
29
|
+
url: t.url,
|
|
30
|
+
route: t.route,
|
|
31
|
+
userAgent: t.userAgent,
|
|
32
|
+
payload: {
|
|
33
|
+
...r,
|
|
34
|
+
source: t.source,
|
|
35
|
+
component: t.component,
|
|
36
|
+
handled: t.handled ?? !0
|
|
37
|
+
},
|
|
38
|
+
context: t.context,
|
|
39
|
+
tags: t.tags,
|
|
40
|
+
user: t.user
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function l(e = 1) {
|
|
44
|
+
return e >= 1 ? !0 : e <= 0 ? !1 : Math.random() < e;
|
|
45
|
+
}
|
|
46
|
+
function E(e) {
|
|
47
|
+
return s(e);
|
|
48
|
+
}
|
|
49
|
+
function m(e = {}) {
|
|
50
|
+
const t = e.maxSize ?? 100, r = [];
|
|
51
|
+
return {
|
|
52
|
+
push(n) {
|
|
53
|
+
r.push(n), r.length > t && r.splice(0, r.length - t);
|
|
54
|
+
},
|
|
55
|
+
drain() {
|
|
56
|
+
return r.splice(0, r.length);
|
|
57
|
+
},
|
|
58
|
+
size() {
|
|
59
|
+
return r.length;
|
|
60
|
+
},
|
|
61
|
+
async flush(n) {
|
|
62
|
+
if (r.length === 0) return !0;
|
|
63
|
+
const o = r.splice(0, r.length), a = await n(o);
|
|
64
|
+
return a || r.unshift(...o), a;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function s(e) {
|
|
69
|
+
if (Array.isArray(e))
|
|
70
|
+
return e.map((t) => s(t));
|
|
71
|
+
if (e && typeof e == "object") {
|
|
72
|
+
const t = {};
|
|
73
|
+
for (const [r, n] of Object.entries(e))
|
|
74
|
+
t[r] = i.test(r) ? c : s(n);
|
|
75
|
+
return t;
|
|
76
|
+
}
|
|
77
|
+
return e;
|
|
78
|
+
}
|
|
79
|
+
function d(e) {
|
|
80
|
+
try {
|
|
81
|
+
return JSON.stringify(e);
|
|
82
|
+
} catch {
|
|
83
|
+
return String(e);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
g as createErrorEvent,
|
|
88
|
+
u as createEventId,
|
|
89
|
+
m as createMemoryQueue,
|
|
90
|
+
E as redactSensitiveData,
|
|
91
|
+
f as serializeError,
|
|
92
|
+
l as shouldSample
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kargo-pulse/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"license": "UNLICENSED",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist/**/*.js",
|
|
14
|
+
"dist/**/*.cjs",
|
|
15
|
+
"dist/**/*.d.ts",
|
|
16
|
+
"package.json"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"vite": "^6.2.2"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "vite build && tsc -p tsconfig.json --emitDeclarationOnly",
|
|
30
|
+
"typecheck": "tsc --noEmit"
|
|
31
|
+
}
|
|
32
|
+
}
|