@kargo-pulse/browser 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 ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v="[REDACTED]",p=/cookie|token|authorization|password|passwd|secret|credential|session/i;function b(){const e=Math.random().toString(36).slice(2,10);return`evt_${Date.now().toString(36)}_${e}`}function y(e){return e instanceof Error?{name:e.name,message:e.message,stack:e.stack}:typeof e=="string"?{name:"NonError",message:e}:{name:"NonError",message:L(e)}}function E(e,r){const n=y(e);return T({eventId:b(),type:"error",level:"error",appId:r.appId,env:r.env,release:r.release,timestamp:new Date().toISOString(),url:r.url,route:r.route,userAgent:r.userAgent,payload:{...n,source:r.source,component:r.component,handled:r.handled??!0},context:r.context,tags:r.tags,user:r.user})}function S(e=1){return e>=1?!0:e<=0?!1:Math.random()<e}function T(e){return g(e)}function j(e={}){const r=e.maxSize??100,n=[];return{push(t){n.push(t),n.length>r&&n.splice(0,n.length-r)},drain(){return n.splice(0,n.length)},size(){return n.length},async flush(t){if(n.length===0)return!0;const o=n.splice(0,n.length),s=await t(o);return s||n.unshift(...o),s}}}function g(e){if(Array.isArray(e))return e.map(r=>g(r));if(e&&typeof e=="object"){const r={};for(const[n,t]of Object.entries(e))r[n]=p.test(n)?v:g(t);return r}return e}function L(e){try{return JSON.stringify(e)}catch{return String(e)}}function w(e){const r=e.runtime??m(),n=e.transport??h(e.endpoint,r,e.fetcher),t=j({maxSize:e.batchSize??50}),o=e.autoCapture===!1?[]:x(r,a=>s(a.error,a.options));function s(a,c={}){var u,f;if(!S(e.sampleRate??1))return;const d=E(a,{appId:e.appId,env:e.env,release:e.release,url:(u=r.location)==null?void 0:u.href,route:e.route,userAgent:(f=r.navigator)==null?void 0:f.userAgent,source:c.source??"manual",component:c.component,handled:c.handled??!0,context:c.context,tags:c.tags,user:c.user}),i=e.beforeSend?e.beforeSend(d):d;i&&t.push(i)}async function l(a){return t.flush(c=>n.send(c,a))}return{captureException:s,flush:l,async close(){for(const a of o)a();return l({useBeacon:!0})}}}function h(e,r=m(),n=globalThis.fetch){return{async send(t,o){var l;if(t.length===0)return!0;const s=JSON.stringify({events:t});if(o!=null&&o.useBeacon&&((l=r.navigator)!=null&&l.sendBeacon)){const a=typeof Blob>"u"?s:new Blob([s],{type:"application/json"});return r.navigator.sendBeacon(e,a)}if(!n)return!1;try{return(await n(e,{method:"POST",headers:{"content-type":"application/json"},body:s,keepalive:o==null?void 0:o.useBeacon})).ok}catch{return!1}}}}function x(e,r){var s,l;const n=[],t=(s=e.addEventListener)==null?void 0:s.bind(globalThis),o=(l=e.removeEventListener)==null?void 0:l.bind(globalThis);if(t&&o){const a=i=>{const u=i;r({error:u.error??u.message,options:{source:"window.onerror",handled:!1}})},c=i=>{r({error:i.reason,options:{source:"unhandledrejection",handled:!1}})},d=i=>{const u=i.target,f=u&&"outerHTML"in u?u.outerHTML:"resource load failed";r({error:f,options:{source:"resource",handled:!1}})};t("error",a),t("unhandledrejection",c),t("error",d,!0),n.push(()=>o("error",a)),n.push(()=>o("unhandledrejection",c)),n.push(()=>o("error",d,!0))}return n}function m(){return{location:globalThis.location,navigator:globalThis.navigator,addEventListener:globalThis.addEventListener,removeEventListener:globalThis.removeEventListener,document:globalThis.document}}exports.createHttpTransport=h;exports.createKargoPulse=w;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,38 @@
1
+ import { type ErrorEventInput, type PulseEvent, type Transport, type TransportSendOptions } from '@kargo-pulse/core';
2
+ export interface BrowserRuntime {
3
+ location?: Pick<Location, 'href'>;
4
+ navigator?: Pick<Navigator, 'userAgent' | 'sendBeacon'>;
5
+ addEventListener?: Window['addEventListener'];
6
+ removeEventListener?: Window['removeEventListener'];
7
+ document?: Pick<Document, 'visibilityState' | 'addEventListener' | 'removeEventListener'>;
8
+ }
9
+ export interface CaptureOptions {
10
+ source?: string;
11
+ component?: string;
12
+ handled?: boolean;
13
+ context?: Record<string, unknown>;
14
+ tags?: Record<string, string>;
15
+ user?: ErrorEventInput['user'];
16
+ }
17
+ export interface KargoPulseOptions {
18
+ appId: string;
19
+ env: string;
20
+ release: string;
21
+ endpoint: string;
22
+ route?: string;
23
+ sampleRate?: number;
24
+ autoCapture?: boolean;
25
+ batchSize?: number;
26
+ transport?: Transport;
27
+ beforeSend?: (event: PulseEvent) => PulseEvent | null | undefined;
28
+ runtime?: BrowserRuntime;
29
+ fetcher?: typeof fetch;
30
+ }
31
+ export interface KargoPulseClient {
32
+ captureException(error: unknown, options?: CaptureOptions): void;
33
+ flush(options?: TransportSendOptions): Promise<boolean>;
34
+ close(): Promise<boolean>;
35
+ }
36
+ export declare function createKargoPulse(options: KargoPulseOptions): KargoPulseClient;
37
+ export declare function createHttpTransport(endpoint: string, runtime?: BrowserRuntime, fetcher?: typeof fetch): Transport;
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ var KargoPulse=(function(f){"use strict";const b="[REDACTED]",p=/cookie|token|authorization|password|passwd|secret|credential|session/i;function y(){const e=Math.random().toString(36).slice(2,10);return`evt_${Date.now().toString(36)}_${e}`}function E(e){return e instanceof Error?{name:e.name,message:e.message,stack:e.stack}:typeof e=="string"?{name:"NonError",message:e}:{name:"NonError",message:w(e)}}function S(e,r){const n=E(e);return j({eventId:y(),type:"error",level:"error",appId:r.appId,env:r.env,release:r.release,timestamp:new Date().toISOString(),url:r.url,route:r.route,userAgent:r.userAgent,payload:{...n,source:r.source,component:r.component,handled:r.handled??!0},context:r.context,tags:r.tags,user:r.user})}function T(e=1){return e>=1?!0:e<=0?!1:Math.random()<e}function j(e){return h(e)}function L(e={}){const r=e.maxSize??100,n=[];return{push(t){n.push(t),n.length>r&&n.splice(0,n.length-r)},drain(){return n.splice(0,n.length)},size(){return n.length},async flush(t){if(n.length===0)return!0;const o=n.splice(0,n.length),s=await t(o);return s||n.unshift(...o),s}}}function h(e){if(Array.isArray(e))return e.map(r=>h(r));if(e&&typeof e=="object"){const r={};for(const[n,t]of Object.entries(e))r[n]=p.test(n)?b:h(t);return r}return e}function w(e){try{return JSON.stringify(e)}catch{return String(e)}}function H(e){const r=e.runtime??v(),n=e.transport??m(e.endpoint,r,e.fetcher),t=L({maxSize:e.batchSize??50}),o=e.autoCapture===!1?[]:A(r,a=>s(a.error,a.options));function s(a,u={}){var c,g;if(!T(e.sampleRate??1))return;const d=S(a,{appId:e.appId,env:e.env,release:e.release,url:(c=r.location)==null?void 0:c.href,route:e.route,userAgent:(g=r.navigator)==null?void 0:g.userAgent,source:u.source??"manual",component:u.component,handled:u.handled??!0,context:u.context,tags:u.tags,user:u.user}),i=e.beforeSend?e.beforeSend(d):d;i&&t.push(i)}async function l(a){return t.flush(u=>n.send(u,a))}return{captureException:s,flush:l,async close(){for(const a of o)a();return l({useBeacon:!0})}}}function m(e,r=v(),n=globalThis.fetch){return{async send(t,o){var l;if(t.length===0)return!0;const s=JSON.stringify({events:t});if(o!=null&&o.useBeacon&&((l=r.navigator)!=null&&l.sendBeacon)){const a=typeof Blob>"u"?s:new Blob([s],{type:"application/json"});return r.navigator.sendBeacon(e,a)}if(!n)return!1;try{return(await n(e,{method:"POST",headers:{"content-type":"application/json"},body:s,keepalive:o==null?void 0:o.useBeacon})).ok}catch{return!1}}}}function A(e,r){var s,l;const n=[],t=(s=e.addEventListener)==null?void 0:s.bind(globalThis),o=(l=e.removeEventListener)==null?void 0:l.bind(globalThis);if(t&&o){const a=i=>{const c=i;r({error:c.error??c.message,options:{source:"window.onerror",handled:!1}})},u=i=>{r({error:i.reason,options:{source:"unhandledrejection",handled:!1}})},d=i=>{const c=i.target,g=c&&"outerHTML"in c?c.outerHTML:"resource load failed";r({error:g,options:{source:"resource",handled:!1}})};t("error",a),t("unhandledrejection",u),t("error",d,!0),n.push(()=>o("error",a)),n.push(()=>o("unhandledrejection",u)),n.push(()=>o("error",d,!0))}return n}function v(){return{location:globalThis.location,navigator:globalThis.navigator,addEventListener:globalThis.addEventListener,removeEventListener:globalThis.removeEventListener,document:globalThis.document}}return f.createHttpTransport=m,f.createKargoPulse=H,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"}),f})({});
2
+ //# sourceMappingURL=index.global.js.map
package/dist/index.js ADDED
@@ -0,0 +1,182 @@
1
+ const m = "[REDACTED]", v = /cookie|token|authorization|password|passwd|secret|credential|session/i;
2
+ function p() {
3
+ const e = Math.random().toString(36).slice(2, 10);
4
+ return `evt_${Date.now().toString(36)}_${e}`;
5
+ }
6
+ function b(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: j(e)
17
+ };
18
+ }
19
+ function E(e, r) {
20
+ const n = b(e);
21
+ return S({
22
+ eventId: p(),
23
+ type: "error",
24
+ level: "error",
25
+ appId: r.appId,
26
+ env: r.env,
27
+ release: r.release,
28
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
29
+ url: r.url,
30
+ route: r.route,
31
+ userAgent: r.userAgent,
32
+ payload: {
33
+ ...n,
34
+ source: r.source,
35
+ component: r.component,
36
+ handled: r.handled ?? !0
37
+ },
38
+ context: r.context,
39
+ tags: r.tags,
40
+ user: r.user
41
+ });
42
+ }
43
+ function y(e = 1) {
44
+ return e >= 1 ? !0 : e <= 0 ? !1 : Math.random() < e;
45
+ }
46
+ function S(e) {
47
+ return g(e);
48
+ }
49
+ function T(e = {}) {
50
+ const r = e.maxSize ?? 100, n = [];
51
+ return {
52
+ push(t) {
53
+ n.push(t), n.length > r && n.splice(0, n.length - r);
54
+ },
55
+ drain() {
56
+ return n.splice(0, n.length);
57
+ },
58
+ size() {
59
+ return n.length;
60
+ },
61
+ async flush(t) {
62
+ if (n.length === 0) return !0;
63
+ const o = n.splice(0, n.length), s = await t(o);
64
+ return s || n.unshift(...o), s;
65
+ }
66
+ };
67
+ }
68
+ function g(e) {
69
+ if (Array.isArray(e))
70
+ return e.map((r) => g(r));
71
+ if (e && typeof e == "object") {
72
+ const r = {};
73
+ for (const [n, t] of Object.entries(e))
74
+ r[n] = v.test(n) ? m : g(t);
75
+ return r;
76
+ }
77
+ return e;
78
+ }
79
+ function j(e) {
80
+ try {
81
+ return JSON.stringify(e);
82
+ } catch {
83
+ return String(e);
84
+ }
85
+ }
86
+ function x(e) {
87
+ const r = e.runtime ?? h(), n = e.transport ?? L(e.endpoint, r, e.fetcher), t = T({ maxSize: e.batchSize ?? 50 }), o = e.autoCapture === !1 ? [] : w(r, (a) => s(a.error, a.options));
88
+ function s(a, c = {}) {
89
+ var u, f;
90
+ if (!y(e.sampleRate ?? 1)) return;
91
+ const d = E(a, {
92
+ appId: e.appId,
93
+ env: e.env,
94
+ release: e.release,
95
+ url: (u = r.location) == null ? void 0 : u.href,
96
+ route: e.route,
97
+ userAgent: (f = r.navigator) == null ? void 0 : f.userAgent,
98
+ source: c.source ?? "manual",
99
+ component: c.component,
100
+ handled: c.handled ?? !0,
101
+ context: c.context,
102
+ tags: c.tags,
103
+ user: c.user
104
+ }), i = e.beforeSend ? e.beforeSend(d) : d;
105
+ i && t.push(i);
106
+ }
107
+ async function l(a) {
108
+ return t.flush((c) => n.send(c, a));
109
+ }
110
+ return {
111
+ captureException: s,
112
+ flush: l,
113
+ async close() {
114
+ for (const a of o) a();
115
+ return l({ useBeacon: !0 });
116
+ }
117
+ };
118
+ }
119
+ function L(e, r = h(), n = globalThis.fetch) {
120
+ return {
121
+ async send(t, o) {
122
+ var l;
123
+ if (t.length === 0) return !0;
124
+ const s = JSON.stringify({ events: t });
125
+ if (o != null && o.useBeacon && ((l = r.navigator) != null && l.sendBeacon)) {
126
+ const a = typeof Blob > "u" ? s : new Blob([s], { type: "application/json" });
127
+ return r.navigator.sendBeacon(e, a);
128
+ }
129
+ if (!n) return !1;
130
+ try {
131
+ return (await n(e, {
132
+ method: "POST",
133
+ headers: { "content-type": "application/json" },
134
+ body: s,
135
+ keepalive: o == null ? void 0 : o.useBeacon
136
+ })).ok;
137
+ } catch {
138
+ return !1;
139
+ }
140
+ }
141
+ };
142
+ }
143
+ function w(e, r) {
144
+ var s, l;
145
+ const n = [], t = (s = e.addEventListener) == null ? void 0 : s.bind(globalThis), o = (l = e.removeEventListener) == null ? void 0 : l.bind(globalThis);
146
+ if (t && o) {
147
+ const a = (i) => {
148
+ const u = i;
149
+ r({
150
+ error: u.error ?? u.message,
151
+ options: { source: "window.onerror", handled: !1 }
152
+ });
153
+ }, c = (i) => {
154
+ r({
155
+ error: i.reason,
156
+ options: { source: "unhandledrejection", handled: !1 }
157
+ });
158
+ }, d = (i) => {
159
+ const u = i.target, f = u && "outerHTML" in u ? u.outerHTML : "resource load failed";
160
+ r({
161
+ error: f,
162
+ options: { source: "resource", handled: !1 }
163
+ });
164
+ };
165
+ t("error", a), t("unhandledrejection", c), t("error", d, !0), n.push(() => o("error", a)), n.push(() => o("unhandledrejection", c)), n.push(() => o("error", d, !0));
166
+ }
167
+ return n;
168
+ }
169
+ function h() {
170
+ return {
171
+ location: globalThis.location,
172
+ navigator: globalThis.navigator,
173
+ addEventListener: globalThis.addEventListener,
174
+ removeEventListener: globalThis.removeEventListener,
175
+ document: globalThis.document
176
+ };
177
+ }
178
+ export {
179
+ L as createHttpTransport,
180
+ x as createKargoPulse
181
+ };
182
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@kargo-pulse/browser",
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
+ "dependencies": {
26
+ "@kargo-pulse/core": "0.1.0"
27
+ },
28
+ "devDependencies": {
29
+ "vite": "^6.2.2"
30
+ },
31
+ "scripts": {
32
+ "build": "vite build && tsc -p tsconfig.json --emitDeclarationOnly",
33
+ "typecheck": "tsc --noEmit"
34
+ }
35
+ }