@extn/segi-js 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { SegiClientOptions, SegiEventDto, SegiUser, SegiBreadcrumb } from '@extn/segi-shared';
2
2
  export { SegiBreadcrumb, SegiClientOptions, SegiEventDto, SegiUser } from '@extn/segi-shared';
3
+ import { R as ReplayConfig } from './types-DfmnOA9D.mjs';
3
4
 
4
5
  interface InitOptions {
5
6
  /** Re-initialize even if already initialized. Replaces config and listeners. */
@@ -7,13 +8,37 @@ interface InitOptions {
7
8
  /** Suppress the duplicate-init console warning. */
8
9
  silent?: boolean;
9
10
  }
11
+ /**
12
+ * Optional replay activation token built by `withReplay()` from
13
+ * `@extn/segi-js/replay`. When present, Segi.init() dynamic-imports the
14
+ * replay module so apps that don't enable it pay zero bundle cost.
15
+ */
16
+ type SegiInitOptions = SegiClientOptions & {
17
+ replay?: ReplayConfig;
18
+ };
19
+ type ReplayApi = {
20
+ pause(): void;
21
+ resume(): void;
22
+ setUser(user: {
23
+ id?: string;
24
+ email?: string;
25
+ } | null): void;
26
+ event(name: string, meta?: Record<string, unknown>): void;
27
+ notifyRouteChange(url?: string, title?: string): void;
28
+ };
10
29
  declare const Segi: {
30
+ /**
31
+ * Replay namespace. No-op until `Segi.init({ replay: withReplay(...) })`
32
+ * resolves the dynamic-imported replay module. Methods are safe to call
33
+ * before init — they just do nothing.
34
+ */
35
+ replay: ReplayApi;
11
36
  /**
12
37
  * Initialize the SDK. Idempotent: a second call is ignored unless
13
38
  * `{ force: true }` is passed. Pass `{ silent: true }` to suppress
14
39
  * the duplicate-init warning.
15
40
  */
16
- init(options: SegiClientOptions, opts?: InitOptions): void;
41
+ init(options: SegiInitOptions, opts?: InitOptions): void;
17
42
  /** True if init() has been called successfully on this bundle. */
18
43
  isInitialized(): boolean;
19
44
  /** Tear down listeners and reset state. Mostly for tests / hot-reload. */
@@ -25,4 +50,4 @@ declare const Segi: {
25
50
  addBreadcrumb(breadcrumb: SegiBreadcrumb): void;
26
51
  };
27
52
 
28
- export { type InitOptions, Segi, Segi as default };
53
+ export { type InitOptions, Segi, type SegiInitOptions, Segi as default };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { SegiClientOptions, SegiEventDto, SegiUser, SegiBreadcrumb } from '@extn/segi-shared';
2
2
  export { SegiBreadcrumb, SegiClientOptions, SegiEventDto, SegiUser } from '@extn/segi-shared';
3
+ import { R as ReplayConfig } from './types-DfmnOA9D.js';
3
4
 
4
5
  interface InitOptions {
5
6
  /** Re-initialize even if already initialized. Replaces config and listeners. */
@@ -7,13 +8,37 @@ interface InitOptions {
7
8
  /** Suppress the duplicate-init console warning. */
8
9
  silent?: boolean;
9
10
  }
11
+ /**
12
+ * Optional replay activation token built by `withReplay()` from
13
+ * `@extn/segi-js/replay`. When present, Segi.init() dynamic-imports the
14
+ * replay module so apps that don't enable it pay zero bundle cost.
15
+ */
16
+ type SegiInitOptions = SegiClientOptions & {
17
+ replay?: ReplayConfig;
18
+ };
19
+ type ReplayApi = {
20
+ pause(): void;
21
+ resume(): void;
22
+ setUser(user: {
23
+ id?: string;
24
+ email?: string;
25
+ } | null): void;
26
+ event(name: string, meta?: Record<string, unknown>): void;
27
+ notifyRouteChange(url?: string, title?: string): void;
28
+ };
10
29
  declare const Segi: {
30
+ /**
31
+ * Replay namespace. No-op until `Segi.init({ replay: withReplay(...) })`
32
+ * resolves the dynamic-imported replay module. Methods are safe to call
33
+ * before init — they just do nothing.
34
+ */
35
+ replay: ReplayApi;
11
36
  /**
12
37
  * Initialize the SDK. Idempotent: a second call is ignored unless
13
38
  * `{ force: true }` is passed. Pass `{ silent: true }` to suppress
14
39
  * the duplicate-init warning.
15
40
  */
16
- init(options: SegiClientOptions, opts?: InitOptions): void;
41
+ init(options: SegiInitOptions, opts?: InitOptions): void;
17
42
  /** True if init() has been called successfully on this bundle. */
18
43
  isInitialized(): boolean;
19
44
  /** Tear down listeners and reset state. Mostly for tests / hot-reload. */
@@ -25,4 +50,4 @@ declare const Segi: {
25
50
  addBreadcrumb(breadcrumb: SegiBreadcrumb): void;
26
51
  };
27
52
 
28
- export { type InitOptions, Segi, Segi as default };
53
+ export { type InitOptions, Segi, type SegiInitOptions, Segi as default };
package/dist/index.js CHANGED
@@ -1,31 +1,4 @@
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
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/core.ts
29
2
  var DEFAULT_MAX_BREADCRUMBS = 50;
30
3
  function createState() {
31
4
  return {
@@ -40,7 +13,7 @@ function createState() {
40
13
  };
41
14
  }
42
15
  function pushBreadcrumb(state2, breadcrumb) {
43
- const max = state2.options.maxBreadcrumbs ?? DEFAULT_MAX_BREADCRUMBS;
16
+ const max = _nullishCoalesce(state2.options.maxBreadcrumbs, () => ( DEFAULT_MAX_BREADCRUMBS));
44
17
  state2.breadcrumbs.push(breadcrumb);
45
18
  if (state2.breadcrumbs.length > max) {
46
19
  state2.breadcrumbs.splice(0, state2.breadcrumbs.length - max);
@@ -48,24 +21,24 @@ function pushBreadcrumb(state2, breadcrumb) {
48
21
  }
49
22
  function buildEvent(state2, base) {
50
23
  const evt = {
51
- type: base.type ?? "error",
52
- level: base.level ?? "error",
53
- message: base.message ?? "",
24
+ type: _nullishCoalesce(base.type, () => ( "error")),
25
+ level: _nullishCoalesce(base.level, () => ( "error")),
26
+ message: _nullishCoalesce(base.message, () => ( "")),
54
27
  errorName: base.errorName,
55
28
  stack: base.stack,
56
29
  platform: base.platform,
57
30
  runtime: base.runtime,
58
- environment: base.environment ?? state2.options.environment,
59
- release: base.release ?? state2.options.release,
31
+ environment: _nullishCoalesce(base.environment, () => ( state2.options.environment)),
32
+ release: _nullishCoalesce(base.release, () => ( state2.options.release)),
60
33
  transaction: base.transaction,
61
34
  url: base.url,
62
35
  userAgent: base.userAgent,
63
- user: base.user ?? state2.user ?? void 0,
64
- tags: { ...state2.tags, ...base.tags ?? {} },
36
+ user: _nullishCoalesce(_nullishCoalesce(base.user, () => ( state2.user)), () => ( void 0)),
37
+ tags: { ...state2.tags, ..._nullishCoalesce(base.tags, () => ( {})) },
65
38
  extra: base.extra,
66
39
  breadcrumbs: state2.breadcrumbs.slice(),
67
40
  request: base.request,
68
- timestamp: base.timestamp ?? (/* @__PURE__ */ new Date()).toISOString()
41
+ timestamp: _nullishCoalesce(base.timestamp, () => ( (/* @__PURE__ */ new Date()).toISOString()))
69
42
  };
70
43
  if (state2.options.beforeSend) {
71
44
  try {
@@ -74,7 +47,7 @@ function buildEvent(state2, base) {
74
47
  return { ...evt, _drop: true };
75
48
  }
76
49
  return next;
77
- } catch {
50
+ } catch (e) {
78
51
  return evt;
79
52
  }
80
53
  }
@@ -82,10 +55,33 @@ function buildEvent(state2, base) {
82
55
  }
83
56
 
84
57
  // src/transport.ts
85
- var import_segi_shared = require("@extn/segi-shared");
58
+ var _segishared = require('@extn/segi-shared');
59
+ var warnedKeys = /* @__PURE__ */ new Set();
60
+ function warnOnce(key, message) {
61
+ if (warnedKeys.has(key)) return;
62
+ warnedKeys.add(key);
63
+ if (typeof console !== "undefined" && typeof console.warn === "function") {
64
+ console.warn(`[segi] ${message}`);
65
+ }
66
+ }
67
+ function describeStatus(status) {
68
+ if (status === 401 || status === 403)
69
+ return "ingest rejected the project key (check projectKey + endpoint region)";
70
+ if (status === 404) return "ingest endpoint not found (check endpoint URL)";
71
+ if (status === 413) return "event payload too large; dropped by ingest";
72
+ if (status === 429) return "ingest rate-limited (over plan quota or burst)";
73
+ if (status >= 500) return "ingest is returning 5xx \u2014 events may be lost";
74
+ return "ingest returned a non-2xx response";
75
+ }
86
76
  function send(endpoint, projectKey, event) {
87
- const url = endpoint || import_segi_shared.SEGI_DEFAULT_INGEST_ENDPOINT;
88
- if (!url || !projectKey) return;
77
+ const url = endpoint || _segishared.SEGI_DEFAULT_INGEST_ENDPOINT;
78
+ if (!url || !projectKey) {
79
+ warnOnce(
80
+ "missing-config",
81
+ !projectKey ? "init() called without a projectKey \u2014 events will not be sent" : "init() called without a valid endpoint \u2014 events will not be sent"
82
+ );
83
+ return;
84
+ }
89
85
  if (event._drop) return;
90
86
  try {
91
87
  const body = JSON.stringify(event);
@@ -93,25 +89,37 @@ function send(endpoint, projectKey, event) {
93
89
  "Content-Type": "application/json",
94
90
  "X-Segi-Project-Key": projectKey
95
91
  };
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
92
  if (typeof fetch === "function") {
105
- void fetch(url, {
93
+ fetch(url, {
106
94
  method: "POST",
107
95
  headers,
108
96
  body,
109
97
  keepalive: true,
110
98
  mode: "cors",
111
99
  credentials: "omit"
112
- }).catch(() => void 0);
100
+ }).then((res) => {
101
+ if (!res.ok) {
102
+ warnOnce(
103
+ `status-${res.status}`,
104
+ `${describeStatus(res.status)} (HTTP ${res.status} from ${url})`
105
+ );
106
+ }
107
+ }).catch((err) => {
108
+ warnOnce(
109
+ "network-error",
110
+ `network error reaching ${url} \u2014 events not delivered (${err instanceof Error ? err.message : String(err)})`
111
+ );
112
+ });
113
+ return;
113
114
  }
114
- } catch {
115
+ if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
116
+ const beaconUrl = `${url}${url.includes("?") ? "&" : "?"}pk=${encodeURIComponent(
117
+ projectKey
118
+ )}`;
119
+ const blob = new Blob([body], { type: "application/json" });
120
+ navigator.sendBeacon(beaconUrl, blob);
121
+ }
122
+ } catch (e2) {
115
123
  }
116
124
  }
117
125
 
@@ -120,9 +128,9 @@ var state = createState();
120
128
  function safeStack(err) {
121
129
  try {
122
130
  if (err && typeof err === "object" && "stack" in err) {
123
- return String(err.stack ?? "");
131
+ return String(_nullishCoalesce(err.stack, () => ( "")));
124
132
  }
125
- } catch {
133
+ } catch (e3) {
126
134
  }
127
135
  return void 0;
128
136
  }
@@ -131,8 +139,8 @@ function captureWindowError(event) {
131
139
  try {
132
140
  if (event instanceof ErrorEvent) {
133
141
  const err = event.error;
134
- const message = err?.message ?? event.message ?? "Error";
135
- Segi.captureException(err ?? new Error(message), {
142
+ const message = _nullishCoalesce(_nullishCoalesce(_optionalChain([err, 'optionalAccess', _ => _.message]), () => ( event.message)), () => ( "Error"));
143
+ Segi.captureException(_nullishCoalesce(err, () => ( new Error(message))), {
136
144
  message,
137
145
  url: typeof location !== "undefined" ? location.href : void 0
138
146
  });
@@ -144,7 +152,7 @@ function captureWindowError(event) {
144
152
  url: typeof location !== "undefined" ? location.href : void 0
145
153
  });
146
154
  }
147
- } catch {
155
+ } catch (e4) {
148
156
  }
149
157
  }
150
158
  function attachListeners() {
@@ -157,7 +165,25 @@ function detachListeners() {
157
165
  window.removeEventListener("error", captureWindowError, true);
158
166
  window.removeEventListener("unhandledrejection", captureWindowError, true);
159
167
  }
168
+ var noopReplay = {
169
+ pause() {
170
+ },
171
+ resume() {
172
+ },
173
+ setUser() {
174
+ },
175
+ event() {
176
+ },
177
+ notifyRouteChange() {
178
+ }
179
+ };
160
180
  var Segi = {
181
+ /**
182
+ * Replay namespace. No-op until `Segi.init({ replay: withReplay(...) })`
183
+ * resolves the dynamic-imported replay module. Methods are safe to call
184
+ * before init — they just do nothing.
185
+ */
186
+ replay: noopReplay,
161
187
  /**
162
188
  * Initialize the SDK. Idempotent: a second call is ignored unless
163
189
  * `{ force: true }` is passed. Pass `{ silent: true }` to suppress
@@ -166,7 +192,7 @@ var Segi = {
166
192
  init(options, opts = {}) {
167
193
  try {
168
194
  const w = typeof window !== "undefined" ? window : null;
169
- const already = state.initialized || w?.__segiInitialized === true;
195
+ const already = state.initialized || _optionalChain([w, 'optionalAccess', _2 => _2.__segiInitialized]) === true;
170
196
  if (already && !opts.force) {
171
197
  if (!opts.silent && typeof console !== "undefined") {
172
198
  console.warn(
@@ -176,11 +202,25 @@ var Segi = {
176
202
  return;
177
203
  }
178
204
  if (state.initialized) detachListeners();
179
- state.options = { ...options };
205
+ const { replay, ...core } = options;
206
+ state.options = { ...core };
180
207
  state.initialized = true;
181
208
  if (w) w.__segiInitialized = true;
182
209
  attachListeners();
183
- } catch {
210
+ if (_optionalChain([replay, 'optionalAccess', _3 => _3.__segi_replay])) {
211
+ void Promise.resolve().then(() => _interopRequireWildcard(require("./replay/index.js"))).then((mod) => {
212
+ Segi.replay = mod.replayApi;
213
+ return mod.activateReplay({
214
+ projectKey: core.projectKey,
215
+ // Empty/undefined here is fine — the replay transport falls
216
+ // back to https://segiapi.extn.ai when no endpoint is given.
217
+ endpoint: core.endpoint,
218
+ config: replay
219
+ });
220
+ }).catch(() => {
221
+ });
222
+ }
223
+ } catch (e5) {
184
224
  }
185
225
  },
186
226
  /** True if init() has been called successfully on this bundle. */
@@ -199,7 +239,7 @@ var Segi = {
199
239
  const w = window;
200
240
  w.__segiInitialized = false;
201
241
  }
202
- } catch {
242
+ } catch (e6) {
203
243
  }
204
244
  },
205
245
  captureException(error, context = {}) {
@@ -214,12 +254,12 @@ var Segi = {
214
254
  stack: safeStack(err),
215
255
  platform: "javascript",
216
256
  runtime: "browser",
217
- url: context.url ?? (typeof location !== "undefined" ? location.href : void 0),
218
- userAgent: context.userAgent ?? (typeof navigator !== "undefined" ? navigator.userAgent : void 0),
257
+ url: _nullishCoalesce(context.url, () => ( (typeof location !== "undefined" ? location.href : void 0))),
258
+ userAgent: _nullishCoalesce(context.userAgent, () => ( (typeof navigator !== "undefined" ? navigator.userAgent : void 0))),
219
259
  ...context
220
260
  });
221
261
  send(state.options.endpoint, state.options.projectKey, evt);
222
- } catch {
262
+ } catch (e7) {
223
263
  }
224
264
  },
225
265
  captureMessage(message, context = {}) {
@@ -227,7 +267,7 @@ var Segi = {
227
267
  if (!state.initialized) return;
228
268
  const evt = buildEvent(state, {
229
269
  type: "message",
230
- level: context.level ?? "info",
270
+ level: _nullishCoalesce(context.level, () => ( "info")),
231
271
  message,
232
272
  platform: "javascript",
233
273
  runtime: "browser",
@@ -236,33 +276,33 @@ var Segi = {
236
276
  ...context
237
277
  });
238
278
  send(state.options.endpoint, state.options.projectKey, evt);
239
- } catch {
279
+ } catch (e8) {
240
280
  }
241
281
  },
242
282
  setUser(user) {
243
283
  try {
244
284
  state.user = user;
245
- } catch {
285
+ } catch (e9) {
246
286
  }
247
287
  },
248
288
  setTag(key, value) {
249
289
  try {
250
290
  state.tags[key] = value;
251
- } catch {
291
+ } catch (e10) {
252
292
  }
253
293
  },
254
294
  addBreadcrumb(breadcrumb) {
255
295
  try {
256
296
  pushBreadcrumb(state, {
257
297
  ...breadcrumb,
258
- timestamp: breadcrumb.timestamp ?? (/* @__PURE__ */ new Date()).toISOString()
298
+ timestamp: _nullishCoalesce(breadcrumb.timestamp, () => ( (/* @__PURE__ */ new Date()).toISOString()))
259
299
  });
260
- } catch {
300
+ } catch (e11) {
261
301
  }
262
302
  }
263
303
  };
264
- var index_default = Segi;
265
- // Annotate the CommonJS export names for ESM import in node:
266
- 0 && (module.exports = {
267
- Segi
268
- });
304
+ var src_default = Segi;
305
+
306
+
307
+
308
+ exports.Segi = Segi; exports.default = src_default;
package/dist/index.mjs CHANGED
@@ -56,9 +56,32 @@ function buildEvent(state2, base) {
56
56
 
57
57
  // src/transport.ts
58
58
  import { SEGI_DEFAULT_INGEST_ENDPOINT } from "@extn/segi-shared";
59
+ var warnedKeys = /* @__PURE__ */ new Set();
60
+ function warnOnce(key, message) {
61
+ if (warnedKeys.has(key)) return;
62
+ warnedKeys.add(key);
63
+ if (typeof console !== "undefined" && typeof console.warn === "function") {
64
+ console.warn(`[segi] ${message}`);
65
+ }
66
+ }
67
+ function describeStatus(status) {
68
+ if (status === 401 || status === 403)
69
+ return "ingest rejected the project key (check projectKey + endpoint region)";
70
+ if (status === 404) return "ingest endpoint not found (check endpoint URL)";
71
+ if (status === 413) return "event payload too large; dropped by ingest";
72
+ if (status === 429) return "ingest rate-limited (over plan quota or burst)";
73
+ if (status >= 500) return "ingest is returning 5xx \u2014 events may be lost";
74
+ return "ingest returned a non-2xx response";
75
+ }
59
76
  function send(endpoint, projectKey, event) {
60
77
  const url = endpoint || SEGI_DEFAULT_INGEST_ENDPOINT;
61
- if (!url || !projectKey) return;
78
+ if (!url || !projectKey) {
79
+ warnOnce(
80
+ "missing-config",
81
+ !projectKey ? "init() called without a projectKey \u2014 events will not be sent" : "init() called without a valid endpoint \u2014 events will not be sent"
82
+ );
83
+ return;
84
+ }
62
85
  if (event._drop) return;
63
86
  try {
64
87
  const body = JSON.stringify(event);
@@ -66,23 +89,35 @@ function send(endpoint, projectKey, event) {
66
89
  "Content-Type": "application/json",
67
90
  "X-Segi-Project-Key": projectKey
68
91
  };
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
92
  if (typeof fetch === "function") {
78
- void fetch(url, {
93
+ fetch(url, {
79
94
  method: "POST",
80
95
  headers,
81
96
  body,
82
97
  keepalive: true,
83
98
  mode: "cors",
84
99
  credentials: "omit"
85
- }).catch(() => void 0);
100
+ }).then((res) => {
101
+ if (!res.ok) {
102
+ warnOnce(
103
+ `status-${res.status}`,
104
+ `${describeStatus(res.status)} (HTTP ${res.status} from ${url})`
105
+ );
106
+ }
107
+ }).catch((err) => {
108
+ warnOnce(
109
+ "network-error",
110
+ `network error reaching ${url} \u2014 events not delivered (${err instanceof Error ? err.message : String(err)})`
111
+ );
112
+ });
113
+ return;
114
+ }
115
+ if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
116
+ const beaconUrl = `${url}${url.includes("?") ? "&" : "?"}pk=${encodeURIComponent(
117
+ projectKey
118
+ )}`;
119
+ const blob = new Blob([body], { type: "application/json" });
120
+ navigator.sendBeacon(beaconUrl, blob);
86
121
  }
87
122
  } catch {
88
123
  }
@@ -130,7 +165,25 @@ function detachListeners() {
130
165
  window.removeEventListener("error", captureWindowError, true);
131
166
  window.removeEventListener("unhandledrejection", captureWindowError, true);
132
167
  }
168
+ var noopReplay = {
169
+ pause() {
170
+ },
171
+ resume() {
172
+ },
173
+ setUser() {
174
+ },
175
+ event() {
176
+ },
177
+ notifyRouteChange() {
178
+ }
179
+ };
133
180
  var Segi = {
181
+ /**
182
+ * Replay namespace. No-op until `Segi.init({ replay: withReplay(...) })`
183
+ * resolves the dynamic-imported replay module. Methods are safe to call
184
+ * before init — they just do nothing.
185
+ */
186
+ replay: noopReplay,
134
187
  /**
135
188
  * Initialize the SDK. Idempotent: a second call is ignored unless
136
189
  * `{ force: true }` is passed. Pass `{ silent: true }` to suppress
@@ -149,10 +202,24 @@ var Segi = {
149
202
  return;
150
203
  }
151
204
  if (state.initialized) detachListeners();
152
- state.options = { ...options };
205
+ const { replay, ...core } = options;
206
+ state.options = { ...core };
153
207
  state.initialized = true;
154
208
  if (w) w.__segiInitialized = true;
155
209
  attachListeners();
210
+ if (replay?.__segi_replay) {
211
+ void import("./replay/index.mjs").then((mod) => {
212
+ Segi.replay = mod.replayApi;
213
+ return mod.activateReplay({
214
+ projectKey: core.projectKey,
215
+ // Empty/undefined here is fine — the replay transport falls
216
+ // back to https://segiapi.extn.ai when no endpoint is given.
217
+ endpoint: core.endpoint,
218
+ config: replay
219
+ });
220
+ }).catch(() => {
221
+ });
222
+ }
156
223
  } catch {
157
224
  }
158
225
  },
@@ -234,8 +301,8 @@ var Segi = {
234
301
  }
235
302
  }
236
303
  };
237
- var index_default = Segi;
304
+ var src_default = Segi;
238
305
  export {
239
306
  Segi,
240
- index_default as default
307
+ src_default as default
241
308
  };
@@ -0,0 +1,61 @@
1
+ import { R as ReplayConfig, a as ReplayOptions } from '../types-DfmnOA9D.mjs';
2
+
3
+ /**
4
+ * Replay orchestrator. Exposed at `@extn/segi-js/replay`.
5
+ *
6
+ * Usage:
7
+ * import Segi from "@extn/segi-js";
8
+ * import { withReplay } from "@extn/segi-js/replay";
9
+ *
10
+ * Segi.init({
11
+ * projectKey: "segi_pk_live_...",
12
+ * endpoint: "https://segiapi.extn.ai",
13
+ * replay: withReplay({ enabled: true, sample: 100 }),
14
+ * });
15
+ *
16
+ * // anywhere after init:
17
+ * Segi.replay.pause();
18
+ * Segi.replay.setUser({ id: "u_123" });
19
+ * Segi.replay.event("checkout_started", { amount: 9900 });
20
+ * Segi.replay.notifyRouteChange();
21
+ *
22
+ * Activation is async because:
23
+ * - we POST /api/trace/session/start before any heatmap listener attaches,
24
+ * so the server can short-circuit a recording-off project
25
+ * - this also lets the client honor the project-level recording toggle
26
+ * without redeploying the SDK
27
+ *
28
+ * No rrweb in this pass. DOM replay lands when the server-side /api/trace/
29
+ * replay path (currently 501) gets its S3 backend.
30
+ */
31
+
32
+ declare function withReplay(options?: ReplayOptions): ReplayConfig;
33
+ /**
34
+ * Internal entry-point invoked by Segi.init() when a ReplayConfig was
35
+ * passed. Not part of the public surface.
36
+ */
37
+ declare function activateReplay(args: {
38
+ projectKey: string;
39
+ /** Optional — replay transport defaults to https://segiapi.extn.ai. */
40
+ endpoint?: string;
41
+ config: ReplayConfig;
42
+ }): Promise<void>;
43
+ /** Public Segi.replay namespace, attached by the main index.ts. */
44
+ declare const replayApi: {
45
+ pause(): void;
46
+ resume(): void;
47
+ setUser(user: {
48
+ id?: string;
49
+ email?: string;
50
+ } | null): void;
51
+ event(name: string, meta?: Record<string, unknown>): void;
52
+ /**
53
+ * Call this on SPA route changes (e.g. from a Next.js usePathname() effect).
54
+ * Bumps the page-views counter and emits a fresh page_view event.
55
+ */
56
+ notifyRouteChange(url?: string, title?: string): void;
57
+ /** Test seam: returns null when replay was not activated for this session. */
58
+ _sessionUid(): string | null;
59
+ };
60
+
61
+ export { ReplayConfig, ReplayOptions, activateReplay, replayApi, withReplay };