@extn/segi-js 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/LICENSE +37 -0
- package/README.md +54 -0
- package/dist/cdn.global.js +2 -0
- package/dist/index.d.mts +28 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +269 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +242 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
PROPRIETARY SOFTWARE LICENSE
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Extension Co., Ltd. All rights reserved.
|
|
4
|
+
|
|
5
|
+
This software and all associated files in this repository (the "Software") are
|
|
6
|
+
the proprietary and confidential property of Extension Co., Ltd. and are
|
|
7
|
+
protected by applicable copyright, trade secret, and other intellectual
|
|
8
|
+
property laws.
|
|
9
|
+
|
|
10
|
+
NO LICENSE IS GRANTED to any third party under this notice. Without prior
|
|
11
|
+
written consent from Extension Co., Ltd., no part of the Software may be:
|
|
12
|
+
|
|
13
|
+
(a) copied, reproduced, distributed, published, or transmitted in any form
|
|
14
|
+
or by any means;
|
|
15
|
+
(b) modified, adapted, translated, or used to create derivative works;
|
|
16
|
+
(c) reverse engineered, decompiled, disassembled, or otherwise analysed to
|
|
17
|
+
derive the source code, structure, sequence, or organisation of the
|
|
18
|
+
Software, except to the extent such activity is expressly permitted by
|
|
19
|
+
applicable law notwithstanding this restriction;
|
|
20
|
+
(d) sub-licensed, rented, leased, sold, or otherwise commercially exploited.
|
|
21
|
+
|
|
22
|
+
Customers who obtain a binary build or package of segi SDK components (e.g.
|
|
23
|
+
through a private package registry, npm, or a CDN URL operated by Extension
|
|
24
|
+
Co., Ltd.) are granted a limited, non-transferable, non-exclusive licence to
|
|
25
|
+
install and use those components solely for the purpose of integrating their
|
|
26
|
+
own applications with the segi monitoring service operated by Extension Co.,
|
|
27
|
+
Ltd., subject to a separate Terms of Service.
|
|
28
|
+
|
|
29
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
30
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
31
|
+
FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
32
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY,
|
|
33
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF,
|
|
34
|
+
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
35
|
+
SOFTWARE.
|
|
36
|
+
|
|
37
|
+
For licensing inquiries: agent@extn.ai
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @extn/segi-js
|
|
2
|
+
|
|
3
|
+
Browser JavaScript SDK for [segi](https://segi.extn.ai) — error monitoring for teams that ship.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @extn/segi-js
|
|
9
|
+
# or: npm install @extn/segi-js
|
|
10
|
+
# or: yarn add @extn/segi-js
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import Segi from "@extn/segi-js";
|
|
17
|
+
|
|
18
|
+
Segi.init({
|
|
19
|
+
publicKey: "segi_pk_live_...",
|
|
20
|
+
// optional
|
|
21
|
+
environment: "production",
|
|
22
|
+
release: "1.4.2",
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// anywhere
|
|
26
|
+
Segi.captureException(new Error("boom"));
|
|
27
|
+
Segi.captureMessage("checkout finished", { level: "info" });
|
|
28
|
+
Segi.setUser({ id: "user_123", email: "alice@example.com" });
|
|
29
|
+
Segi.addBreadcrumb({ type: "click", message: "checkout button", timestamp: new Date().toISOString() });
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`Segi.init()` is idempotent — calling it twice on the same bundle is a no-op. Pass `{ force: true }` to replace the running config.
|
|
33
|
+
|
|
34
|
+
## CDN
|
|
35
|
+
|
|
36
|
+
Drop a `<script>` tag and skip the bundler:
|
|
37
|
+
|
|
38
|
+
```html
|
|
39
|
+
<script src="https://cdn.extn.ai/segi/segi.min.js"></script>
|
|
40
|
+
<script>
|
|
41
|
+
Segi.init({ publicKey: "segi_pk_live_..." });
|
|
42
|
+
</script>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Docs
|
|
46
|
+
|
|
47
|
+
Full integration guide: <https://segi.extn.ai/docs>
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## Licence
|
|
51
|
+
|
|
52
|
+
Copyright (c) 2026 Extension Co., Ltd. All rights reserved. Use of this package
|
|
53
|
+
is governed by the LICENSE file in this package and the segi service Terms of
|
|
54
|
+
Service at https://segi.extn.ai/tnc — it is **not** open source.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var Segi=(()=>{var B=Object.create;var p=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var z=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var F=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var m=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),M=(t,e)=>{for(var n in e)p(t,n,{get:e[n],enumerable:!0})},w=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of C(e))!k.call(t,o)&&o!==n&&p(t,o,{get:()=>e[o],enumerable:!(r=P(e,o))||r.enumerable});return t};var q=(t,e,n)=>(n=t!=null?B(z(t)):{},w(e||!t||!t.__esModule?p(n,"default",{value:t,enumerable:!0}):n,t)),R=t=>w(p({},"__esModule",{value:!0}),t);var I=m(s=>{"use strict";Object.defineProperty(s,"__esModule",{value:!0});s.SEGI_DEFAULT_ADMIN_URL=s.SEGI_DEFAULT_CDN_URL=s.SEGI_DEFAULT_PM2_ENDPOINT=s.SEGI_DEFAULT_INGEST_ENDPOINT=void 0;s.SEGI_DEFAULT_INGEST_ENDPOINT="https://segiapi.extn.ai/api/ingest/events";s.SEGI_DEFAULT_PM2_ENDPOINT="https://segiapi.extn.ai/api/ingest/pm2";s.SEGI_DEFAULT_CDN_URL="https://cdn.extn.ai/segi/segi.min.js";s.SEGI_DEFAULT_ADMIN_URL="https://segi.extn.ai"});var N=m(g=>{"use strict";Object.defineProperty(g,"__esModule",{value:!0});g.scrubHeaders=A;g.scrubObject=d;g.scrubEvent=H;var G=new Set(["authorization","cookie","set-cookie","x-api-key","proxy-authorization"]),K=[/^password$/i,/^passwd$/i,/token/i,/secret/i,/api[-_]?key/i,/^authorization$/i,/card[-_]?number/i,/^rrn$/i,/^residentnumber$/i],O="[Filtered]";function A(t){if(!t)return t;let e={};for(let[n,r]of Object.entries(t))G.has(n.toLowerCase())?e[n]=O:e[n]=r;return e}function $(t){return K.some(e=>e.test(t))}function d(t,e=0){if(e>8||t==null)return t;if(Array.isArray(t))return t.map(n=>d(n,e+1));if(typeof t=="object"){let n={};for(let[r,o]of Object.entries(t))$(r)?n[r]=O:n[r]=d(o,e+1);return n}return t}function H(t){let e=JSON.parse(JSON.stringify(t));return e.request&&(e.request.headers=A(e.request.headers),e.request.body=d(e.request.body),e.request.query=d(e.request.query)),e.extra&&(e.extra=d(e.extra)),e.tags&&(e.tags=d(e.tags)),e}});var x=m(b=>{"use strict";Object.defineProperty(b,"__esModule",{value:!0});b.generateFingerprint=X;var J=F("crypto");function _(t){return t?t.replace(/0x[0-9a-fA-F]+/g,"0xX").replace(/\b\d{4,}\b/g,"N").replace(/[\r\n]+/g," ").trim().slice(0,500):""}function W(t){if(!t)return"";let e=t.split(`
|
|
2
|
+
`).map(r=>r.trim()).filter(Boolean),n=e.find(r=>r.startsWith("at "))??e[1]??"";return _(n)}function X(t){let e=[String(t.projectId),_(t.errorName??""),_(t.message??""),W(t.stack??"")];return(0,J.createHash)("sha256").update(e.join("|")).digest("hex")}});var T=m(a=>{"use strict";var V=a&&a.__createBinding||(Object.create?(function(t,e,n,r){r===void 0&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}):(function(t,e,n,r){r===void 0&&(r=n),t[r]=e[n]})),v=a&&a.__exportStar||function(t,e){for(var n in t)n!=="default"&&!Object.prototype.hasOwnProperty.call(e,n)&&V(e,t,n)};Object.defineProperty(a,"__esModule",{value:!0});v(I(),a);v(N(),a);v(x(),a)});var ee={};M(ee,{Segi:()=>c,default:()=>Z});function D(){return{options:{projectKey:"",endpoint:""},user:null,tags:{},breadcrumbs:[],initialized:!1}}function j(t,e){let n=t.options.maxBreadcrumbs??50;t.breadcrumbs.push(e),t.breadcrumbs.length>n&&t.breadcrumbs.splice(0,t.breadcrumbs.length-n)}function E(t,e){let n={type:e.type??"error",level:e.level??"error",message:e.message??"",errorName:e.errorName,stack:e.stack,platform:e.platform,runtime:e.runtime,environment:e.environment??t.options.environment,release:e.release??t.options.release,transaction:e.transaction,url:e.url,userAgent:e.userAgent,user:e.user??t.user??void 0,tags:{...t.tags,...e.tags??{}},extra:e.extra,breadcrumbs:t.breadcrumbs.slice(),request:e.request,timestamp:e.timestamp??new Date().toISOString()};if(t.options.beforeSend)try{let r=t.options.beforeSend(n);return r||{...n,_drop:!0}}catch{return n}return n}var L=q(T());function h(t,e,n){let r=t||L.SEGI_DEFAULT_INGEST_ENDPOINT;if(!(!r||!e)&&!n._drop)try{let o=JSON.stringify(n),l={"Content-Type":"application/json","X-Segi-Project-Key":e};if(typeof navigator<"u"&&typeof navigator.sendBeacon=="function"){let y=`${r}${r.includes("?")?"&":"?"}pk=${encodeURIComponent(e)}`,f=new Blob([o],{type:"application/json"});if(navigator.sendBeacon(y,f))return}typeof fetch=="function"&&fetch(r,{method:"POST",headers:l,body:o,keepalive:!0,mode:"cors",credentials:"omit"}).catch(()=>{})}catch{}}var i=D();function Y(t){try{if(t&&typeof t=="object"&&"stack"in t)return String(t.stack??"")}catch{}}function S(t){if(i.initialized)try{if(t instanceof ErrorEvent){let e=t.error,n=e?.message??t.message??"Error";c.captureException(e??new Error(n),{message:n,url:typeof location<"u"?location.href:void 0})}else if("reason"in t){let e=t.reason,n=e instanceof Error?e.message:typeof e=="string"?e:"Unhandled promise rejection";c.captureException(e,{message:n,url:typeof location<"u"?location.href:void 0})}}catch{}}function Q(){typeof window>"u"||(window.addEventListener("error",S,!0),window.addEventListener("unhandledrejection",S,!0))}function U(){typeof window>"u"||(window.removeEventListener("error",S,!0),window.removeEventListener("unhandledrejection",S,!0))}var c={init(t,e={}){try{let n=typeof window<"u"?window:null;if((i.initialized||n?.__segiInitialized===!0)&&!e.force){!e.silent&&typeof console<"u"&&console.warn("[segi] init() called more than once; ignoring. Pass { force: true } to override.");return}i.initialized&&U(),i.options={...t},i.initialized=!0,n&&(n.__segiInitialized=!0),Q()}catch{}},isInitialized(){return i.initialized},close(){try{if(U(),i.initialized=!1,i.user=null,i.tags={},i.breadcrumbs=[],typeof window<"u"){let t=window;t.__segiInitialized=!1}}catch{}},captureException(t,e={}){try{if(!i.initialized)return;let n=t instanceof Error?t:new Error(typeof t=="string"?t:JSON.stringify(t)),r=E(i,{type:"error",level:"error",message:n.message,errorName:n.name,stack:Y(n),platform:"javascript",runtime:"browser",url:e.url??(typeof location<"u"?location.href:void 0),userAgent:e.userAgent??(typeof navigator<"u"?navigator.userAgent:void 0),...e});h(i.options.endpoint,i.options.projectKey,r)}catch{}},captureMessage(t,e={}){try{if(!i.initialized)return;let n=E(i,{type:"message",level:e.level??"info",message:t,platform:"javascript",runtime:"browser",url:typeof location<"u"?location.href:void 0,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,...e});h(i.options.endpoint,i.options.projectKey,n)}catch{}},setUser(t){try{i.user=t}catch{}},setTag(t,e){try{i.tags[t]=e}catch{}},addBreadcrumb(t){try{j(i,{...t,timestamp:t.timestamp??new Date().toISOString()})}catch{}}};(function(){try{let e=window;if(e.__segiBundleLoaded){typeof console<"u"&&console.warn("[segi] segi.min.js loaded more than once; ignoring this load.");return}e.__segiBundleLoaded=!0;let n=e.SegiConfig??{},r={},o=document.getElementsByTagName("script");for(let f=o.length-1;f>=0;f--){let u=o[f];if(u.src&&/segi(\.min)?\.js/.test(u.src)){r={projectKey:u.dataset.projectKey,endpoint:u.dataset.endpoint,environment:u.dataset.environment,release:u.dataset.release};break}}let l=n.projectKey??r.projectKey,y=n.endpoint??r.endpoint;if(!l){e.Segi=c;return}c.init({projectKey:l,endpoint:y,environment:n.environment??r.environment,release:n.release??r.release}),e.Segi=c}catch{}})();var Z=c;return R(ee);})();
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SegiClientOptions, SegiEventDto, SegiUser, SegiBreadcrumb } from '@extn/segi-shared';
|
|
2
|
+
export { SegiBreadcrumb, SegiClientOptions, SegiEventDto, SegiUser } from '@extn/segi-shared';
|
|
3
|
+
|
|
4
|
+
interface InitOptions {
|
|
5
|
+
/** Re-initialize even if already initialized. Replaces config and listeners. */
|
|
6
|
+
force?: boolean;
|
|
7
|
+
/** Suppress the duplicate-init console warning. */
|
|
8
|
+
silent?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const Segi: {
|
|
11
|
+
/**
|
|
12
|
+
* Initialize the SDK. Idempotent: a second call is ignored unless
|
|
13
|
+
* `{ force: true }` is passed. Pass `{ silent: true }` to suppress
|
|
14
|
+
* the duplicate-init warning.
|
|
15
|
+
*/
|
|
16
|
+
init(options: SegiClientOptions, opts?: InitOptions): void;
|
|
17
|
+
/** True if init() has been called successfully on this bundle. */
|
|
18
|
+
isInitialized(): boolean;
|
|
19
|
+
/** Tear down listeners and reset state. Mostly for tests / hot-reload. */
|
|
20
|
+
close(): void;
|
|
21
|
+
captureException(error: unknown, context?: Partial<SegiEventDto>): void;
|
|
22
|
+
captureMessage(message: string, context?: Partial<SegiEventDto>): void;
|
|
23
|
+
setUser(user: SegiUser | null): void;
|
|
24
|
+
setTag(key: string, value: string): void;
|
|
25
|
+
addBreadcrumb(breadcrumb: SegiBreadcrumb): void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { type InitOptions, Segi, Segi as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SegiClientOptions, SegiEventDto, SegiUser, SegiBreadcrumb } from '@extn/segi-shared';
|
|
2
|
+
export { SegiBreadcrumb, SegiClientOptions, SegiEventDto, SegiUser } from '@extn/segi-shared';
|
|
3
|
+
|
|
4
|
+
interface InitOptions {
|
|
5
|
+
/** Re-initialize even if already initialized. Replaces config and listeners. */
|
|
6
|
+
force?: boolean;
|
|
7
|
+
/** Suppress the duplicate-init console warning. */
|
|
8
|
+
silent?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const Segi: {
|
|
11
|
+
/**
|
|
12
|
+
* Initialize the SDK. Idempotent: a second call is ignored unless
|
|
13
|
+
* `{ force: true }` is passed. Pass `{ silent: true }` to suppress
|
|
14
|
+
* the duplicate-init warning.
|
|
15
|
+
*/
|
|
16
|
+
init(options: SegiClientOptions, opts?: InitOptions): void;
|
|
17
|
+
/** True if init() has been called successfully on this bundle. */
|
|
18
|
+
isInitialized(): boolean;
|
|
19
|
+
/** Tear down listeners and reset state. Mostly for tests / hot-reload. */
|
|
20
|
+
close(): void;
|
|
21
|
+
captureException(error: unknown, context?: Partial<SegiEventDto>): void;
|
|
22
|
+
captureMessage(message: string, context?: Partial<SegiEventDto>): void;
|
|
23
|
+
setUser(user: SegiUser | null): void;
|
|
24
|
+
setTag(key: string, value: string): void;
|
|
25
|
+
addBreadcrumb(breadcrumb: SegiBreadcrumb): void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { type InitOptions, Segi, Segi as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Segi: () => Segi,
|
|
24
|
+
default: () => index_default
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/core.ts
|
|
29
|
+
var DEFAULT_MAX_BREADCRUMBS = 50;
|
|
30
|
+
function createState() {
|
|
31
|
+
return {
|
|
32
|
+
options: {
|
|
33
|
+
projectKey: "",
|
|
34
|
+
endpoint: ""
|
|
35
|
+
},
|
|
36
|
+
user: null,
|
|
37
|
+
tags: {},
|
|
38
|
+
breadcrumbs: [],
|
|
39
|
+
initialized: false
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function pushBreadcrumb(state2, breadcrumb) {
|
|
43
|
+
const max = state2.options.maxBreadcrumbs ?? DEFAULT_MAX_BREADCRUMBS;
|
|
44
|
+
state2.breadcrumbs.push(breadcrumb);
|
|
45
|
+
if (state2.breadcrumbs.length > max) {
|
|
46
|
+
state2.breadcrumbs.splice(0, state2.breadcrumbs.length - max);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function buildEvent(state2, base) {
|
|
50
|
+
const evt = {
|
|
51
|
+
type: base.type ?? "error",
|
|
52
|
+
level: base.level ?? "error",
|
|
53
|
+
message: base.message ?? "",
|
|
54
|
+
errorName: base.errorName,
|
|
55
|
+
stack: base.stack,
|
|
56
|
+
platform: base.platform,
|
|
57
|
+
runtime: base.runtime,
|
|
58
|
+
environment: base.environment ?? state2.options.environment,
|
|
59
|
+
release: base.release ?? state2.options.release,
|
|
60
|
+
transaction: base.transaction,
|
|
61
|
+
url: base.url,
|
|
62
|
+
userAgent: base.userAgent,
|
|
63
|
+
user: base.user ?? state2.user ?? void 0,
|
|
64
|
+
tags: { ...state2.tags, ...base.tags ?? {} },
|
|
65
|
+
extra: base.extra,
|
|
66
|
+
breadcrumbs: state2.breadcrumbs.slice(),
|
|
67
|
+
request: base.request,
|
|
68
|
+
timestamp: base.timestamp ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
69
|
+
};
|
|
70
|
+
if (state2.options.beforeSend) {
|
|
71
|
+
try {
|
|
72
|
+
const next = state2.options.beforeSend(evt);
|
|
73
|
+
if (!next) {
|
|
74
|
+
return { ...evt, _drop: true };
|
|
75
|
+
}
|
|
76
|
+
return next;
|
|
77
|
+
} catch {
|
|
78
|
+
return evt;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return evt;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/transport.ts
|
|
85
|
+
var import_segi_shared = require("@extn/segi-shared");
|
|
86
|
+
function send(endpoint, projectKey, event) {
|
|
87
|
+
const url = endpoint || import_segi_shared.SEGI_DEFAULT_INGEST_ENDPOINT;
|
|
88
|
+
if (!url || !projectKey) return;
|
|
89
|
+
if (event._drop) return;
|
|
90
|
+
try {
|
|
91
|
+
const body = JSON.stringify(event);
|
|
92
|
+
const headers = {
|
|
93
|
+
"Content-Type": "application/json",
|
|
94
|
+
"X-Segi-Project-Key": projectKey
|
|
95
|
+
};
|
|
96
|
+
if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
|
|
97
|
+
const beaconUrl = `${url}${url.includes("?") ? "&" : "?"}pk=${encodeURIComponent(
|
|
98
|
+
projectKey
|
|
99
|
+
)}`;
|
|
100
|
+
const blob = new Blob([body], { type: "application/json" });
|
|
101
|
+
const sent = navigator.sendBeacon(beaconUrl, blob);
|
|
102
|
+
if (sent) return;
|
|
103
|
+
}
|
|
104
|
+
if (typeof fetch === "function") {
|
|
105
|
+
void fetch(url, {
|
|
106
|
+
method: "POST",
|
|
107
|
+
headers,
|
|
108
|
+
body,
|
|
109
|
+
keepalive: true,
|
|
110
|
+
mode: "cors",
|
|
111
|
+
credentials: "omit"
|
|
112
|
+
}).catch(() => void 0);
|
|
113
|
+
}
|
|
114
|
+
} catch {
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/index.ts
|
|
119
|
+
var state = createState();
|
|
120
|
+
function safeStack(err) {
|
|
121
|
+
try {
|
|
122
|
+
if (err && typeof err === "object" && "stack" in err) {
|
|
123
|
+
return String(err.stack ?? "");
|
|
124
|
+
}
|
|
125
|
+
} catch {
|
|
126
|
+
}
|
|
127
|
+
return void 0;
|
|
128
|
+
}
|
|
129
|
+
function captureWindowError(event) {
|
|
130
|
+
if (!state.initialized) return;
|
|
131
|
+
try {
|
|
132
|
+
if (event instanceof ErrorEvent) {
|
|
133
|
+
const err = event.error;
|
|
134
|
+
const message = err?.message ?? event.message ?? "Error";
|
|
135
|
+
Segi.captureException(err ?? new Error(message), {
|
|
136
|
+
message,
|
|
137
|
+
url: typeof location !== "undefined" ? location.href : void 0
|
|
138
|
+
});
|
|
139
|
+
} else if ("reason" in event) {
|
|
140
|
+
const reason = event.reason;
|
|
141
|
+
const message = reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Unhandled promise rejection";
|
|
142
|
+
Segi.captureException(reason, {
|
|
143
|
+
message,
|
|
144
|
+
url: typeof location !== "undefined" ? location.href : void 0
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
} catch {
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function attachListeners() {
|
|
151
|
+
if (typeof window === "undefined") return;
|
|
152
|
+
window.addEventListener("error", captureWindowError, true);
|
|
153
|
+
window.addEventListener("unhandledrejection", captureWindowError, true);
|
|
154
|
+
}
|
|
155
|
+
function detachListeners() {
|
|
156
|
+
if (typeof window === "undefined") return;
|
|
157
|
+
window.removeEventListener("error", captureWindowError, true);
|
|
158
|
+
window.removeEventListener("unhandledrejection", captureWindowError, true);
|
|
159
|
+
}
|
|
160
|
+
var Segi = {
|
|
161
|
+
/**
|
|
162
|
+
* Initialize the SDK. Idempotent: a second call is ignored unless
|
|
163
|
+
* `{ force: true }` is passed. Pass `{ silent: true }` to suppress
|
|
164
|
+
* the duplicate-init warning.
|
|
165
|
+
*/
|
|
166
|
+
init(options, opts = {}) {
|
|
167
|
+
try {
|
|
168
|
+
const w = typeof window !== "undefined" ? window : null;
|
|
169
|
+
const already = state.initialized || w?.__segiInitialized === true;
|
|
170
|
+
if (already && !opts.force) {
|
|
171
|
+
if (!opts.silent && typeof console !== "undefined") {
|
|
172
|
+
console.warn(
|
|
173
|
+
"[segi] init() called more than once; ignoring. Pass { force: true } to override."
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (state.initialized) detachListeners();
|
|
179
|
+
state.options = { ...options };
|
|
180
|
+
state.initialized = true;
|
|
181
|
+
if (w) w.__segiInitialized = true;
|
|
182
|
+
attachListeners();
|
|
183
|
+
} catch {
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
/** True if init() has been called successfully on this bundle. */
|
|
187
|
+
isInitialized() {
|
|
188
|
+
return state.initialized;
|
|
189
|
+
},
|
|
190
|
+
/** Tear down listeners and reset state. Mostly for tests / hot-reload. */
|
|
191
|
+
close() {
|
|
192
|
+
try {
|
|
193
|
+
detachListeners();
|
|
194
|
+
state.initialized = false;
|
|
195
|
+
state.user = null;
|
|
196
|
+
state.tags = {};
|
|
197
|
+
state.breadcrumbs = [];
|
|
198
|
+
if (typeof window !== "undefined") {
|
|
199
|
+
const w = window;
|
|
200
|
+
w.__segiInitialized = false;
|
|
201
|
+
}
|
|
202
|
+
} catch {
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
captureException(error, context = {}) {
|
|
206
|
+
try {
|
|
207
|
+
if (!state.initialized) return;
|
|
208
|
+
const err = error instanceof Error ? error : new Error(typeof error === "string" ? error : JSON.stringify(error));
|
|
209
|
+
const evt = buildEvent(state, {
|
|
210
|
+
type: "error",
|
|
211
|
+
level: "error",
|
|
212
|
+
message: err.message,
|
|
213
|
+
errorName: err.name,
|
|
214
|
+
stack: safeStack(err),
|
|
215
|
+
platform: "javascript",
|
|
216
|
+
runtime: "browser",
|
|
217
|
+
url: context.url ?? (typeof location !== "undefined" ? location.href : void 0),
|
|
218
|
+
userAgent: context.userAgent ?? (typeof navigator !== "undefined" ? navigator.userAgent : void 0),
|
|
219
|
+
...context
|
|
220
|
+
});
|
|
221
|
+
send(state.options.endpoint, state.options.projectKey, evt);
|
|
222
|
+
} catch {
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
captureMessage(message, context = {}) {
|
|
226
|
+
try {
|
|
227
|
+
if (!state.initialized) return;
|
|
228
|
+
const evt = buildEvent(state, {
|
|
229
|
+
type: "message",
|
|
230
|
+
level: context.level ?? "info",
|
|
231
|
+
message,
|
|
232
|
+
platform: "javascript",
|
|
233
|
+
runtime: "browser",
|
|
234
|
+
url: typeof location !== "undefined" ? location.href : void 0,
|
|
235
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
236
|
+
...context
|
|
237
|
+
});
|
|
238
|
+
send(state.options.endpoint, state.options.projectKey, evt);
|
|
239
|
+
} catch {
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
setUser(user) {
|
|
243
|
+
try {
|
|
244
|
+
state.user = user;
|
|
245
|
+
} catch {
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
setTag(key, value) {
|
|
249
|
+
try {
|
|
250
|
+
state.tags[key] = value;
|
|
251
|
+
} catch {
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
addBreadcrumb(breadcrumb) {
|
|
255
|
+
try {
|
|
256
|
+
pushBreadcrumb(state, {
|
|
257
|
+
...breadcrumb,
|
|
258
|
+
timestamp: breadcrumb.timestamp ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
259
|
+
});
|
|
260
|
+
} catch {
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
var index_default = Segi;
|
|
265
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
266
|
+
0 && (module.exports = {
|
|
267
|
+
Segi
|
|
268
|
+
});
|
|
269
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/core.ts","../src/transport.ts"],"sourcesContent":["import type {\n SegiBreadcrumb,\n SegiClientOptions,\n SegiEventDto,\n SegiUser,\n} from \"@extn/segi-shared\";\nimport { buildEvent, createState, pushBreadcrumb } from \"./core\";\nimport { send } from \"./transport\";\n\nconst state = createState();\n\nfunction safeStack(err: unknown): string | undefined {\n try {\n if (err && typeof err === \"object\" && \"stack\" in err) {\n return String((err as { stack?: string }).stack ?? \"\");\n }\n } catch {\n /* ignore */\n }\n return undefined;\n}\n\nfunction captureWindowError(event: ErrorEvent | PromiseRejectionEvent | Event) {\n if (!state.initialized) return;\n try {\n if (event instanceof ErrorEvent) {\n const err = event.error;\n const message = err?.message ?? event.message ?? \"Error\";\n Segi.captureException(err ?? new Error(message), {\n message,\n url: typeof location !== \"undefined\" ? location.href : undefined,\n });\n } else if (\"reason\" in event) {\n const reason = (event as PromiseRejectionEvent).reason;\n const message =\n reason instanceof Error\n ? reason.message\n : typeof reason === \"string\"\n ? reason\n : \"Unhandled promise rejection\";\n Segi.captureException(reason, {\n message,\n url: typeof location !== \"undefined\" ? location.href : undefined,\n });\n }\n } catch {\n /* SDK must never throw */\n }\n}\n\nfunction attachListeners() {\n if (typeof window === \"undefined\") return;\n window.addEventListener(\"error\", captureWindowError, true);\n window.addEventListener(\"unhandledrejection\", captureWindowError, true);\n}\n\nfunction detachListeners() {\n if (typeof window === \"undefined\") return;\n window.removeEventListener(\"error\", captureWindowError, true);\n window.removeEventListener(\"unhandledrejection\", captureWindowError, true);\n}\n\nexport interface InitOptions {\n /** Re-initialize even if already initialized. Replaces config and listeners. */\n force?: boolean;\n /** Suppress the duplicate-init console warning. */\n silent?: boolean;\n}\n\nexport const Segi = {\n /**\n * Initialize the SDK. Idempotent: a second call is ignored unless\n * `{ force: true }` is passed. Pass `{ silent: true }` to suppress\n * the duplicate-init warning.\n */\n init(options: SegiClientOptions, opts: InitOptions = {}) {\n try {\n const w =\n typeof window !== \"undefined\"\n ? (window as unknown as { __segiInitialized?: boolean })\n : null;\n\n // Already initialized? Could be either:\n // - this same bundle (state.initialized), or\n // - a different segi bundle on the same page (w.__segiInitialized).\n const already = state.initialized || w?.__segiInitialized === true;\n\n if (already && !opts.force) {\n if (!opts.silent && typeof console !== \"undefined\") {\n console.warn(\n \"[segi] init() called more than once; ignoring. Pass { force: true } to override.\",\n );\n }\n return;\n }\n\n // Force re-init: detach old listeners owned by this bundle.\n if (state.initialized) detachListeners();\n\n state.options = { ...options };\n state.initialized = true;\n if (w) w.__segiInitialized = true;\n attachListeners();\n } catch {\n /* ignore */\n }\n },\n\n /** True if init() has been called successfully on this bundle. */\n isInitialized(): boolean {\n return state.initialized;\n },\n\n /** Tear down listeners and reset state. Mostly for tests / hot-reload. */\n close() {\n try {\n detachListeners();\n state.initialized = false;\n state.user = null;\n state.tags = {};\n state.breadcrumbs = [];\n if (typeof window !== \"undefined\") {\n const w = window as unknown as { __segiInitialized?: boolean };\n w.__segiInitialized = false;\n }\n } catch {\n /* ignore */\n }\n },\n\n captureException(error: unknown, context: Partial<SegiEventDto> = {}) {\n try {\n if (!state.initialized) return;\n const err =\n error instanceof Error\n ? error\n : new Error(typeof error === \"string\" ? error : JSON.stringify(error));\n const evt = buildEvent(state, {\n type: \"error\",\n level: \"error\",\n message: err.message,\n errorName: err.name,\n stack: safeStack(err),\n platform: \"javascript\",\n runtime: \"browser\",\n url:\n context.url ??\n (typeof location !== \"undefined\" ? location.href : undefined),\n userAgent:\n context.userAgent ??\n (typeof navigator !== \"undefined\" ? navigator.userAgent : undefined),\n ...context,\n });\n send(state.options.endpoint, state.options.projectKey, evt);\n } catch {\n /* SDK must never throw */\n }\n },\n\n captureMessage(message: string, context: Partial<SegiEventDto> = {}) {\n try {\n if (!state.initialized) return;\n const evt = buildEvent(state, {\n type: \"message\",\n level: context.level ?? \"info\",\n message,\n platform: \"javascript\",\n runtime: \"browser\",\n url: typeof location !== \"undefined\" ? location.href : undefined,\n userAgent: typeof navigator !== \"undefined\" ? navigator.userAgent : undefined,\n ...context,\n });\n send(state.options.endpoint, state.options.projectKey, evt);\n } catch {\n /* ignore */\n }\n },\n\n setUser(user: SegiUser | null) {\n try {\n state.user = user;\n } catch {\n /* ignore */\n }\n },\n\n setTag(key: string, value: string) {\n try {\n state.tags[key] = value;\n } catch {\n /* ignore */\n }\n },\n\n addBreadcrumb(breadcrumb: SegiBreadcrumb) {\n try {\n pushBreadcrumb(state, {\n ...breadcrumb,\n timestamp: breadcrumb.timestamp ?? new Date().toISOString(),\n });\n } catch {\n /* ignore */\n }\n },\n};\n\nexport type { SegiClientOptions, SegiEventDto, SegiBreadcrumb, SegiUser } from \"@extn/segi-shared\";\nexport default Segi;\n","import type {\n SegiBreadcrumb,\n SegiClientOptions,\n SegiEventDto,\n SegiUser,\n} from \"@extn/segi-shared\";\n\nexport interface SegiCoreState {\n options: SegiClientOptions;\n user: SegiUser | null;\n tags: Record<string, string>;\n breadcrumbs: SegiBreadcrumb[];\n initialized: boolean;\n}\n\nconst DEFAULT_MAX_BREADCRUMBS = 50;\n\nexport function createState(): SegiCoreState {\n return {\n options: {\n projectKey: \"\",\n endpoint: \"\",\n },\n user: null,\n tags: {},\n breadcrumbs: [],\n initialized: false,\n };\n}\n\nexport function pushBreadcrumb(\n state: SegiCoreState,\n breadcrumb: SegiBreadcrumb,\n) {\n const max = state.options.maxBreadcrumbs ?? DEFAULT_MAX_BREADCRUMBS;\n state.breadcrumbs.push(breadcrumb);\n if (state.breadcrumbs.length > max) {\n state.breadcrumbs.splice(0, state.breadcrumbs.length - max);\n }\n}\n\nexport function buildEvent(\n state: SegiCoreState,\n base: Partial<SegiEventDto>,\n): SegiEventDto {\n const evt: SegiEventDto = {\n type: base.type ?? \"error\",\n level: base.level ?? \"error\",\n message: base.message ?? \"\",\n errorName: base.errorName,\n stack: base.stack,\n platform: base.platform,\n runtime: base.runtime,\n environment: base.environment ?? state.options.environment,\n release: base.release ?? state.options.release,\n transaction: base.transaction,\n url: base.url,\n userAgent: base.userAgent,\n user: base.user ?? state.user ?? undefined,\n tags: { ...state.tags, ...(base.tags ?? {}) },\n extra: base.extra,\n breadcrumbs: state.breadcrumbs.slice(),\n request: base.request,\n timestamp: base.timestamp ?? new Date().toISOString(),\n };\n if (state.options.beforeSend) {\n try {\n const next = state.options.beforeSend(evt);\n if (!next) {\n return { ...evt, _drop: true } as unknown as SegiEventDto;\n }\n return next;\n } catch {\n return evt;\n }\n }\n return evt;\n}\n","import { SEGI_DEFAULT_INGEST_ENDPOINT, type SegiEventDto } from \"@extn/segi-shared\";\n\nexport function send(\n endpoint: string | undefined,\n projectKey: string,\n event: SegiEventDto,\n): void {\n const url = endpoint || SEGI_DEFAULT_INGEST_ENDPOINT;\n if (!url || !projectKey) return;\n if ((event as unknown as { _drop?: boolean })._drop) return;\n\n try {\n const body = JSON.stringify(event);\n const headers = {\n \"Content-Type\": \"application/json\",\n \"X-Segi-Project-Key\": projectKey,\n };\n\n if (\n typeof navigator !== \"undefined\" &&\n typeof navigator.sendBeacon === \"function\"\n ) {\n // sendBeacon doesn't allow custom headers; encode key into URL.\n const beaconUrl = `${url}${url.includes(\"?\") ? \"&\" : \"?\"}pk=${encodeURIComponent(\n projectKey,\n )}`;\n const blob = new Blob([body], { type: \"application/json\" });\n const sent = navigator.sendBeacon(beaconUrl, blob);\n if (sent) return;\n }\n\n if (typeof fetch === \"function\") {\n void fetch(url, {\n method: \"POST\",\n headers,\n body,\n keepalive: true,\n mode: \"cors\",\n credentials: \"omit\",\n }).catch(() => undefined);\n }\n } catch {\n // SDK must never throw\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACeA,IAAM,0BAA0B;AAEzB,SAAS,cAA6B;AAC3C,SAAO;AAAA,IACL,SAAS;AAAA,MACP,YAAY;AAAA,MACZ,UAAU;AAAA,IACZ;AAAA,IACA,MAAM;AAAA,IACN,MAAM,CAAC;AAAA,IACP,aAAa,CAAC;AAAA,IACd,aAAa;AAAA,EACf;AACF;AAEO,SAAS,eACdA,QACA,YACA;AACA,QAAM,MAAMA,OAAM,QAAQ,kBAAkB;AAC5C,EAAAA,OAAM,YAAY,KAAK,UAAU;AACjC,MAAIA,OAAM,YAAY,SAAS,KAAK;AAClC,IAAAA,OAAM,YAAY,OAAO,GAAGA,OAAM,YAAY,SAAS,GAAG;AAAA,EAC5D;AACF;AAEO,SAAS,WACdA,QACA,MACc;AACd,QAAM,MAAoB;AAAA,IACxB,MAAM,KAAK,QAAQ;AAAA,IACnB,OAAO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AACF;AAGA,IAAO,gBAAQ;","names":["state"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// src/core.ts
|
|
2
|
+
var DEFAULT_MAX_BREADCRUMBS = 50;
|
|
3
|
+
function createState() {
|
|
4
|
+
return {
|
|
5
|
+
options: {
|
|
6
|
+
projectKey: "",
|
|
7
|
+
endpoint: ""
|
|
8
|
+
},
|
|
9
|
+
user: null,
|
|
10
|
+
tags: {},
|
|
11
|
+
breadcrumbs: [],
|
|
12
|
+
initialized: false
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function pushBreadcrumb(state2, breadcrumb) {
|
|
16
|
+
const max = state2.options.maxBreadcrumbs ?? DEFAULT_MAX_BREADCRUMBS;
|
|
17
|
+
state2.breadcrumbs.push(breadcrumb);
|
|
18
|
+
if (state2.breadcrumbs.length > max) {
|
|
19
|
+
state2.breadcrumbs.splice(0, state2.breadcrumbs.length - max);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function buildEvent(state2, base) {
|
|
23
|
+
const evt = {
|
|
24
|
+
type: base.type ?? "error",
|
|
25
|
+
level: base.level ?? "error",
|
|
26
|
+
message: base.message ?? "",
|
|
27
|
+
errorName: base.errorName,
|
|
28
|
+
stack: base.stack,
|
|
29
|
+
platform: base.platform,
|
|
30
|
+
runtime: base.runtime,
|
|
31
|
+
environment: base.environment ?? state2.options.environment,
|
|
32
|
+
release: base.release ?? state2.options.release,
|
|
33
|
+
transaction: base.transaction,
|
|
34
|
+
url: base.url,
|
|
35
|
+
userAgent: base.userAgent,
|
|
36
|
+
user: base.user ?? state2.user ?? void 0,
|
|
37
|
+
tags: { ...state2.tags, ...base.tags ?? {} },
|
|
38
|
+
extra: base.extra,
|
|
39
|
+
breadcrumbs: state2.breadcrumbs.slice(),
|
|
40
|
+
request: base.request,
|
|
41
|
+
timestamp: base.timestamp ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
42
|
+
};
|
|
43
|
+
if (state2.options.beforeSend) {
|
|
44
|
+
try {
|
|
45
|
+
const next = state2.options.beforeSend(evt);
|
|
46
|
+
if (!next) {
|
|
47
|
+
return { ...evt, _drop: true };
|
|
48
|
+
}
|
|
49
|
+
return next;
|
|
50
|
+
} catch {
|
|
51
|
+
return evt;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return evt;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/transport.ts
|
|
58
|
+
import { SEGI_DEFAULT_INGEST_ENDPOINT } from "@extn/segi-shared";
|
|
59
|
+
function send(endpoint, projectKey, event) {
|
|
60
|
+
const url = endpoint || SEGI_DEFAULT_INGEST_ENDPOINT;
|
|
61
|
+
if (!url || !projectKey) return;
|
|
62
|
+
if (event._drop) return;
|
|
63
|
+
try {
|
|
64
|
+
const body = JSON.stringify(event);
|
|
65
|
+
const headers = {
|
|
66
|
+
"Content-Type": "application/json",
|
|
67
|
+
"X-Segi-Project-Key": projectKey
|
|
68
|
+
};
|
|
69
|
+
if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
|
|
70
|
+
const beaconUrl = `${url}${url.includes("?") ? "&" : "?"}pk=${encodeURIComponent(
|
|
71
|
+
projectKey
|
|
72
|
+
)}`;
|
|
73
|
+
const blob = new Blob([body], { type: "application/json" });
|
|
74
|
+
const sent = navigator.sendBeacon(beaconUrl, blob);
|
|
75
|
+
if (sent) return;
|
|
76
|
+
}
|
|
77
|
+
if (typeof fetch === "function") {
|
|
78
|
+
void fetch(url, {
|
|
79
|
+
method: "POST",
|
|
80
|
+
headers,
|
|
81
|
+
body,
|
|
82
|
+
keepalive: true,
|
|
83
|
+
mode: "cors",
|
|
84
|
+
credentials: "omit"
|
|
85
|
+
}).catch(() => void 0);
|
|
86
|
+
}
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/index.ts
|
|
92
|
+
var state = createState();
|
|
93
|
+
function safeStack(err) {
|
|
94
|
+
try {
|
|
95
|
+
if (err && typeof err === "object" && "stack" in err) {
|
|
96
|
+
return String(err.stack ?? "");
|
|
97
|
+
}
|
|
98
|
+
} catch {
|
|
99
|
+
}
|
|
100
|
+
return void 0;
|
|
101
|
+
}
|
|
102
|
+
function captureWindowError(event) {
|
|
103
|
+
if (!state.initialized) return;
|
|
104
|
+
try {
|
|
105
|
+
if (event instanceof ErrorEvent) {
|
|
106
|
+
const err = event.error;
|
|
107
|
+
const message = err?.message ?? event.message ?? "Error";
|
|
108
|
+
Segi.captureException(err ?? new Error(message), {
|
|
109
|
+
message,
|
|
110
|
+
url: typeof location !== "undefined" ? location.href : void 0
|
|
111
|
+
});
|
|
112
|
+
} else if ("reason" in event) {
|
|
113
|
+
const reason = event.reason;
|
|
114
|
+
const message = reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Unhandled promise rejection";
|
|
115
|
+
Segi.captureException(reason, {
|
|
116
|
+
message,
|
|
117
|
+
url: typeof location !== "undefined" ? location.href : void 0
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
} catch {
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function attachListeners() {
|
|
124
|
+
if (typeof window === "undefined") return;
|
|
125
|
+
window.addEventListener("error", captureWindowError, true);
|
|
126
|
+
window.addEventListener("unhandledrejection", captureWindowError, true);
|
|
127
|
+
}
|
|
128
|
+
function detachListeners() {
|
|
129
|
+
if (typeof window === "undefined") return;
|
|
130
|
+
window.removeEventListener("error", captureWindowError, true);
|
|
131
|
+
window.removeEventListener("unhandledrejection", captureWindowError, true);
|
|
132
|
+
}
|
|
133
|
+
var Segi = {
|
|
134
|
+
/**
|
|
135
|
+
* Initialize the SDK. Idempotent: a second call is ignored unless
|
|
136
|
+
* `{ force: true }` is passed. Pass `{ silent: true }` to suppress
|
|
137
|
+
* the duplicate-init warning.
|
|
138
|
+
*/
|
|
139
|
+
init(options, opts = {}) {
|
|
140
|
+
try {
|
|
141
|
+
const w = typeof window !== "undefined" ? window : null;
|
|
142
|
+
const already = state.initialized || w?.__segiInitialized === true;
|
|
143
|
+
if (already && !opts.force) {
|
|
144
|
+
if (!opts.silent && typeof console !== "undefined") {
|
|
145
|
+
console.warn(
|
|
146
|
+
"[segi] init() called more than once; ignoring. Pass { force: true } to override."
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (state.initialized) detachListeners();
|
|
152
|
+
state.options = { ...options };
|
|
153
|
+
state.initialized = true;
|
|
154
|
+
if (w) w.__segiInitialized = true;
|
|
155
|
+
attachListeners();
|
|
156
|
+
} catch {
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
/** True if init() has been called successfully on this bundle. */
|
|
160
|
+
isInitialized() {
|
|
161
|
+
return state.initialized;
|
|
162
|
+
},
|
|
163
|
+
/** Tear down listeners and reset state. Mostly for tests / hot-reload. */
|
|
164
|
+
close() {
|
|
165
|
+
try {
|
|
166
|
+
detachListeners();
|
|
167
|
+
state.initialized = false;
|
|
168
|
+
state.user = null;
|
|
169
|
+
state.tags = {};
|
|
170
|
+
state.breadcrumbs = [];
|
|
171
|
+
if (typeof window !== "undefined") {
|
|
172
|
+
const w = window;
|
|
173
|
+
w.__segiInitialized = false;
|
|
174
|
+
}
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
captureException(error, context = {}) {
|
|
179
|
+
try {
|
|
180
|
+
if (!state.initialized) return;
|
|
181
|
+
const err = error instanceof Error ? error : new Error(typeof error === "string" ? error : JSON.stringify(error));
|
|
182
|
+
const evt = buildEvent(state, {
|
|
183
|
+
type: "error",
|
|
184
|
+
level: "error",
|
|
185
|
+
message: err.message,
|
|
186
|
+
errorName: err.name,
|
|
187
|
+
stack: safeStack(err),
|
|
188
|
+
platform: "javascript",
|
|
189
|
+
runtime: "browser",
|
|
190
|
+
url: context.url ?? (typeof location !== "undefined" ? location.href : void 0),
|
|
191
|
+
userAgent: context.userAgent ?? (typeof navigator !== "undefined" ? navigator.userAgent : void 0),
|
|
192
|
+
...context
|
|
193
|
+
});
|
|
194
|
+
send(state.options.endpoint, state.options.projectKey, evt);
|
|
195
|
+
} catch {
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
captureMessage(message, context = {}) {
|
|
199
|
+
try {
|
|
200
|
+
if (!state.initialized) return;
|
|
201
|
+
const evt = buildEvent(state, {
|
|
202
|
+
type: "message",
|
|
203
|
+
level: context.level ?? "info",
|
|
204
|
+
message,
|
|
205
|
+
platform: "javascript",
|
|
206
|
+
runtime: "browser",
|
|
207
|
+
url: typeof location !== "undefined" ? location.href : void 0,
|
|
208
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
209
|
+
...context
|
|
210
|
+
});
|
|
211
|
+
send(state.options.endpoint, state.options.projectKey, evt);
|
|
212
|
+
} catch {
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
setUser(user) {
|
|
216
|
+
try {
|
|
217
|
+
state.user = user;
|
|
218
|
+
} catch {
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
setTag(key, value) {
|
|
222
|
+
try {
|
|
223
|
+
state.tags[key] = value;
|
|
224
|
+
} catch {
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
addBreadcrumb(breadcrumb) {
|
|
228
|
+
try {
|
|
229
|
+
pushBreadcrumb(state, {
|
|
230
|
+
...breadcrumb,
|
|
231
|
+
timestamp: breadcrumb.timestamp ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
232
|
+
});
|
|
233
|
+
} catch {
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
var index_default = Segi;
|
|
238
|
+
export {
|
|
239
|
+
Segi,
|
|
240
|
+
index_default as default
|
|
241
|
+
};
|
|
242
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core.ts","../src/transport.ts","../src/index.ts"],"sourcesContent":["import type {\n SegiBreadcrumb,\n SegiClientOptions,\n SegiEventDto,\n SegiUser,\n} from \"@extn/segi-shared\";\n\nexport interface SegiCoreState {\n options: SegiClientOptions;\n user: SegiUser | null;\n tags: Record<string, string>;\n breadcrumbs: SegiBreadcrumb[];\n initialized: boolean;\n}\n\nconst DEFAULT_MAX_BREADCRUMBS = 50;\n\nexport function createState(): SegiCoreState {\n return {\n options: {\n projectKey: \"\",\n endpoint: \"\",\n },\n user: null,\n tags: {},\n breadcrumbs: [],\n initialized: false,\n };\n}\n\nexport function pushBreadcrumb(\n state: SegiCoreState,\n breadcrumb: SegiBreadcrumb,\n) {\n const max = state.options.maxBreadcrumbs ?? DEFAULT_MAX_BREADCRUMBS;\n state.breadcrumbs.push(breadcrumb);\n if (state.breadcrumbs.length > max) {\n state.breadcrumbs.splice(0, state.breadcrumbs.length - max);\n }\n}\n\nexport function buildEvent(\n state: SegiCoreState,\n base: Partial<SegiEventDto>,\n): SegiEventDto {\n const evt: SegiEventDto = {\n type: base.type ?? \"error\",\n level: base.level ?? \"error\",\n message: base.message ?? \"\",\n errorName: base.errorName,\n stack: base.stack,\n platform: base.platform,\n runtime: base.runtime,\n environment: base.environment ?? state.options.environment,\n release: base.release ?? state.options.release,\n transaction: base.transaction,\n url: base.url,\n userAgent: base.userAgent,\n user: base.user ?? state.user ?? undefined,\n tags: { ...state.tags, ...(base.tags ?? {}) },\n extra: base.extra,\n breadcrumbs: state.breadcrumbs.slice(),\n request: base.request,\n timestamp: base.timestamp ?? new Date().toISOString(),\n };\n if (state.options.beforeSend) {\n try {\n const next = state.options.beforeSend(evt);\n if (!next) {\n return { ...evt, _drop: true } as unknown as SegiEventDto;\n }\n return next;\n } catch {\n return evt;\n }\n }\n return evt;\n}\n","import { SEGI_DEFAULT_INGEST_ENDPOINT, type SegiEventDto } from \"@extn/segi-shared\";\n\nexport function send(\n endpoint: string | undefined,\n projectKey: string,\n event: SegiEventDto,\n): void {\n const url = endpoint || SEGI_DEFAULT_INGEST_ENDPOINT;\n if (!url || !projectKey) return;\n if ((event as unknown as { _drop?: boolean })._drop) return;\n\n try {\n const body = JSON.stringify(event);\n const headers = {\n \"Content-Type\": \"application/json\",\n \"X-Segi-Project-Key\": projectKey,\n };\n\n if (\n typeof navigator !== \"undefined\" &&\n typeof navigator.sendBeacon === \"function\"\n ) {\n // sendBeacon doesn't allow custom headers; encode key into URL.\n const beaconUrl = `${url}${url.includes(\"?\") ? \"&\" : \"?\"}pk=${encodeURIComponent(\n projectKey,\n )}`;\n const blob = new Blob([body], { type: \"application/json\" });\n const sent = navigator.sendBeacon(beaconUrl, blob);\n if (sent) return;\n }\n\n if (typeof fetch === \"function\") {\n void fetch(url, {\n method: \"POST\",\n headers,\n body,\n keepalive: true,\n mode: \"cors\",\n credentials: \"omit\",\n }).catch(() => undefined);\n }\n } catch {\n // SDK must never throw\n }\n}\n","import type {\n SegiBreadcrumb,\n SegiClientOptions,\n SegiEventDto,\n SegiUser,\n} from \"@extn/segi-shared\";\nimport { buildEvent, createState, pushBreadcrumb } from \"./core\";\nimport { send } from \"./transport\";\n\nconst state = createState();\n\nfunction safeStack(err: unknown): string | undefined {\n try {\n if (err && typeof err === \"object\" && \"stack\" in err) {\n return String((err as { stack?: string }).stack ?? \"\");\n }\n } catch {\n /* ignore */\n }\n return undefined;\n}\n\nfunction captureWindowError(event: ErrorEvent | PromiseRejectionEvent | Event) {\n if (!state.initialized) return;\n try {\n if (event instanceof ErrorEvent) {\n const err = event.error;\n const message = err?.message ?? event.message ?? \"Error\";\n Segi.captureException(err ?? new Error(message), {\n message,\n url: typeof location !== \"undefined\" ? location.href : undefined,\n });\n } else if (\"reason\" in event) {\n const reason = (event as PromiseRejectionEvent).reason;\n const message =\n reason instanceof Error\n ? reason.message\n : typeof reason === \"string\"\n ? reason\n : \"Unhandled promise rejection\";\n Segi.captureException(reason, {\n message,\n url: typeof location !== \"undefined\" ? location.href : undefined,\n });\n }\n } catch {\n /* SDK must never throw */\n }\n}\n\nfunction attachListeners() {\n if (typeof window === \"undefined\") return;\n window.addEventListener(\"error\", captureWindowError, true);\n window.addEventListener(\"unhandledrejection\", captureWindowError, true);\n}\n\nfunction detachListeners() {\n if (typeof window === \"undefined\") return;\n window.removeEventListener(\"error\", captureWindowError, true);\n window.removeEventListener(\"unhandledrejection\", captureWindowError, true);\n}\n\nexport interface InitOptions {\n /** Re-initialize even if already initialized. Replaces config and listeners. */\n force?: boolean;\n /** Suppress the duplicate-init console warning. */\n silent?: boolean;\n}\n\nexport const Segi = {\n /**\n * Initialize the SDK. Idempotent: a second call is ignored unless\n * `{ force: true }` is passed. Pass `{ silent: true }` to suppress\n * the duplicate-init warning.\n */\n init(options: SegiClientOptions, opts: InitOptions = {}) {\n try {\n const w =\n typeof window !== \"undefined\"\n ? (window as unknown as { __segiInitialized?: boolean })\n : null;\n\n // Already initialized? Could be either:\n // - this same bundle (state.initialized), or\n // - a different segi bundle on the same page (w.__segiInitialized).\n const already = state.initialized || w?.__segiInitialized === true;\n\n if (already && !opts.force) {\n if (!opts.silent && typeof console !== \"undefined\") {\n console.warn(\n \"[segi] init() called more than once; ignoring. Pass { force: true } to override.\",\n );\n }\n return;\n }\n\n // Force re-init: detach old listeners owned by this bundle.\n if (state.initialized) detachListeners();\n\n state.options = { ...options };\n state.initialized = true;\n if (w) w.__segiInitialized = true;\n attachListeners();\n } catch {\n /* ignore */\n }\n },\n\n /** True if init() has been called successfully on this bundle. */\n isInitialized(): boolean {\n return state.initialized;\n },\n\n /** Tear down listeners and reset state. Mostly for tests / hot-reload. */\n close() {\n try {\n detachListeners();\n state.initialized = false;\n state.user = null;\n state.tags = {};\n state.breadcrumbs = [];\n if (typeof window !== \"undefined\") {\n const w = window as unknown as { __segiInitialized?: boolean };\n w.__segiInitialized = false;\n }\n } catch {\n /* ignore */\n }\n },\n\n captureException(error: unknown, context: Partial<SegiEventDto> = {}) {\n try {\n if (!state.initialized) return;\n const err =\n error instanceof Error\n ? error\n : new Error(typeof error === \"string\" ? error : JSON.stringify(error));\n const evt = buildEvent(state, {\n type: \"error\",\n level: \"error\",\n message: err.message,\n errorName: err.name,\n stack: safeStack(err),\n platform: \"javascript\",\n runtime: \"browser\",\n url:\n context.url ??\n (typeof location !== \"undefined\" ? location.href : undefined),\n userAgent:\n context.userAgent ??\n (typeof navigator !== \"undefined\" ? navigator.userAgent : undefined),\n ...context,\n });\n send(state.options.endpoint, state.options.projectKey, evt);\n } catch {\n /* SDK must never throw */\n }\n },\n\n captureMessage(message: string, context: Partial<SegiEventDto> = {}) {\n try {\n if (!state.initialized) return;\n const evt = buildEvent(state, {\n type: \"message\",\n level: context.level ?? \"info\",\n message,\n platform: \"javascript\",\n runtime: \"browser\",\n url: typeof location !== \"undefined\" ? location.href : undefined,\n userAgent: typeof navigator !== \"undefined\" ? navigator.userAgent : undefined,\n ...context,\n });\n send(state.options.endpoint, state.options.projectKey, evt);\n } catch {\n /* ignore */\n }\n },\n\n setUser(user: SegiUser | null) {\n try {\n state.user = user;\n } catch {\n /* ignore */\n }\n },\n\n setTag(key: string, value: string) {\n try {\n state.tags[key] = value;\n } catch {\n /* ignore */\n }\n },\n\n addBreadcrumb(breadcrumb: SegiBreadcrumb) {\n try {\n pushBreadcrumb(state, {\n ...breadcrumb,\n timestamp: breadcrumb.timestamp ?? new Date().toISOString(),\n });\n } catch {\n /* ignore */\n }\n },\n};\n\nexport type { SegiClientOptions, SegiEventDto, SegiBreadcrumb, SegiUser } from \"@extn/segi-shared\";\nexport default Segi;\n"],"mappings":";AAeA,IAAM,0BAA0B;AAEzB,SAAS,cAA6B;AAC3C,SAAO;AAAA,IACL,SAAS;AAAA,MACP,YAAY;AAAA,MACZ,UAAU;AAAA,IACZ;AAAA,IACA,MAAM;AAAA,IACN,MAAM,CAAC;AAAA,IACP,aAAa,CAAC;AAAA,IACd,aAAa;AAAA,EACf;AACF;AAEO,SAAS,eACdA,QACA,YACA;AACA,QAAM,MAAMA,OAAM,QAAQ,kBAAkB;AAC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,YAAM,KAAK,GAAG,IAAI;AAAA,IACpB,QAAQ;AAAA,IAER;AAAA,EACF;AAAA,EAEA,cAAc,YAA4B;AACxC,QAAI;AACF,qBAAe,OAAO;AAAA,QACpB,GAAG;AAAA,QACH,WAAW,WAAW,cAAa,oBAAI,KAAK,GAAE,YAAY;AAAA,MAC5D,CAAC;AAAA,IACH,QAAQ;AAAA,IAER;AAAA,EACF;AACF;AAGA,IAAO,gBAAQ;","names":["state"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@extn/segi-js",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Browser JavaScript SDK for the segi error monitoring service",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./cdn": "./dist/cdn.global.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "restricted"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@extn/segi-shared": "0.1.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"tsup": "^8.3.0",
|
|
30
|
+
"typescript": "^5.6.3"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup",
|
|
34
|
+
"dev": "tsup --watch",
|
|
35
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
36
|
+
"clean": "rm -rf dist"
|
|
37
|
+
}
|
|
38
|
+
}
|