@diegotsi/flint-react 2.1.3 → 2.3.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 CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,27 +15,19 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
31
21
  var index_exports = {};
32
22
  __export(index_exports, {
33
- Flint: () => import_flint_core9.Flint,
23
+ Flint: () => import_flint_core6.Flint,
34
24
  FlintModal: () => FlintModal,
35
- FlintWidget: () => FlintWidget,
36
- flint: () => import_flint_core9.flint
25
+ FlintWidget: () => FlintWidget
37
26
  });
38
27
  module.exports = __toCommonJS(index_exports);
39
28
 
40
29
  // src/FlintModal.tsx
30
+ var import_flint_core3 = require("@diegotsi/flint-core");
41
31
  var import_react2 = require("react");
42
32
  var import_react_i18next = require("react-i18next");
43
33
 
@@ -235,8 +225,6 @@ function injectKeyframes() {
235
225
  document.head.appendChild(s);
236
226
  }
237
227
  function FlintModal({
238
- projectKey,
239
- serverUrl,
240
228
  user,
241
229
  meta,
242
230
  theme,
@@ -256,6 +244,8 @@ function FlintModal({
256
244
  onSuccess,
257
245
  onError
258
246
  }) {
247
+ const config = import_flint_core3.Flint.getConfig();
248
+ const { projectKey, serverUrl } = config;
259
249
  const { t } = (0, import_react_i18next.useTranslation)();
260
250
  const colors = (0, import_flint_core2.resolveTheme)(theme);
261
251
  const isDark = theme === "dark";
@@ -325,7 +315,8 @@ function FlintModal({
325
315
  severity: isText ? "P3" : severity,
326
316
  url: window.location.href,
327
317
  meta: collectedMeta,
328
- label: isText ? "TEXT" : void 0
318
+ label: isText ? "TEXT" : void 0,
319
+ source: isText ? "text_issue" : "widget"
329
320
  };
330
321
  if (onBeforeSubmit) {
331
322
  const proceed = await onBeforeSubmit(payload);
@@ -1181,25 +1172,13 @@ function CheckIcon({ size = 20 }) {
1181
1172
  }
1182
1173
 
1183
1174
  // src/FlintWidget.tsx
1184
- var import_flint_core10 = require("@diegotsi/flint-core");
1175
+ var import_flint_core7 = require("@diegotsi/flint-core");
1185
1176
  var import_react4 = require("react");
1186
1177
  var import_react_i18next3 = require("react-i18next");
1187
1178
 
1188
- // src/collectors/console.ts
1189
- var import_flint_core3 = require("@diegotsi/flint-core");
1190
-
1191
1179
  // src/collectors/environment.ts
1192
1180
  var import_flint_core4 = require("@diegotsi/flint-core");
1193
1181
 
1194
- // src/collectors/formErrors.ts
1195
- var import_flint_core5 = require("@diegotsi/flint-core");
1196
-
1197
- // src/collectors/frustration.ts
1198
- var import_flint_core6 = require("@diegotsi/flint-core");
1199
-
1200
- // src/collectors/network.ts
1201
- var import_flint_core7 = require("@diegotsi/flint-core");
1202
-
1203
1182
  // src/i18n/index.ts
1204
1183
  var import_i18next = require("i18next");
1205
1184
  var import_react_i18next2 = require("react-i18next");
@@ -1250,16 +1229,15 @@ widgetI18n.use(import_react_i18next2.initReactI18next).init({
1250
1229
  var i18n_default = widgetI18n;
1251
1230
 
1252
1231
  // src/store.ts
1253
- var import_flint_core8 = require("@diegotsi/flint-core");
1232
+ var import_flint_core5 = require("@diegotsi/flint-core");
1254
1233
  var import_react3 = require("react");
1255
- var import_flint_core9 = require("@diegotsi/flint-core");
1234
+ var import_flint_core6 = require("@diegotsi/flint-core");
1256
1235
  function useFlintStore() {
1257
- return (0, import_react3.useSyncExternalStore)(import_flint_core8.subscribe, import_flint_core8.getSnapshot);
1236
+ return (0, import_react3.useSyncExternalStore)(import_flint_core5.subscribe, import_flint_core5.getSnapshot);
1258
1237
  }
1259
1238
 
1260
1239
  // src/FlintWidget.tsx
1261
1240
  var import_jsx_runtime3 = require("react/jsx-runtime");
1262
- var REPLAY_WINDOW_MS = 6e4;
1263
1241
  function FlintWidget(props) {
1264
1242
  const { locale = "en-US" } = props;
1265
1243
  (0, import_react4.useEffect)(() => {
@@ -1268,52 +1246,24 @@ function FlintWidget(props) {
1268
1246
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_i18next3.I18nextProvider, { i18n: i18n_default, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(WidgetContent, { ...props }) });
1269
1247
  }
1270
1248
  function WidgetContent({
1271
- projectKey,
1272
- serverUrl,
1273
- user,
1274
- meta,
1275
- extraFields,
1276
1249
  buttonLabel,
1277
1250
  theme = "dark",
1278
1251
  zIndex = 9999,
1279
1252
  statusPageUrl,
1280
- datadogSite,
1281
- enableReplay = true,
1282
1253
  enableScreenshot = true,
1283
- enableConsole = true,
1284
- enableNetwork = true,
1285
1254
  enableTextIssues = true,
1286
- enableFormErrors = true,
1287
- enableFrustration = false,
1288
- autoReportFrustration = false,
1289
1255
  onBeforeSubmit,
1290
1256
  onSuccess,
1291
1257
  onError,
1292
1258
  onOpen,
1293
1259
  onClose
1294
1260
  }) {
1261
+ if (!import_flint_core7.Flint.isInitialized()) {
1262
+ throw new Error("[Flint] Call Flint.init() before mounting <FlintWidget />.");
1263
+ }
1264
+ const config = import_flint_core7.Flint.getConfig();
1295
1265
  const globalState = useFlintStore();
1296
- const resolvedUser = user ?? globalState.user;
1297
- const resolvedSessionReplay = extraFields?.sessionReplay ?? globalState.sessionReplay;
1298
- const getExternalReplayUrl = () => {
1299
- const src = resolvedSessionReplay;
1300
- const explicit = typeof src === "function" ? src() : src;
1301
- if (explicit) return explicit;
1302
- if (datadogSite) {
1303
- try {
1304
- const ddRum = window.DD_RUM;
1305
- const ctx = ddRum?.getInternalContext?.();
1306
- if (ctx?.session_id) {
1307
- const ts = bugTimestamp.current || Date.now();
1308
- const fromTs = ts - 3e4;
1309
- const toTs = ts + 5e3;
1310
- return `https://${datadogSite}/rum/replay/sessions/${ctx.session_id}?from_ts=${fromTs}&to_ts=${toTs}&tab=replay&live=false`;
1311
- }
1312
- } catch {
1313
- }
1314
- }
1315
- return void 0;
1316
- };
1266
+ const resolvedUser = globalState.user ?? config.user;
1317
1267
  const { t } = (0, import_react_i18next3.useTranslation)();
1318
1268
  const bugTimestamp = (0, import_react4.useRef)(0);
1319
1269
  const [open, setOpen] = (0, import_react4.useState)(false);
@@ -1363,92 +1313,11 @@ function WidgetContent({
1363
1313
  setOpen(true);
1364
1314
  onOpen?.();
1365
1315
  };
1366
- const globalInit = import_flint_core10.Flint.isInitialized();
1367
- const global = import_flint_core10.Flint.getInstance();
1368
- const consoleCollector = (0, import_react4.useRef)(null);
1369
- const networkCollector = (0, import_react4.useRef)(null);
1370
- const replayEvents = (0, import_react4.useRef)([]);
1371
- const stopReplay = (0, import_react4.useRef)(null);
1372
- const formErrorCollector = (0, import_react4.useRef)(null);
1373
- const frustrationCollector = (0, import_react4.useRef)(null);
1374
- if (!globalInit) {
1375
- if (enableConsole && !consoleCollector.current) {
1376
- consoleCollector.current = (0, import_flint_core3.createConsoleCollector)();
1377
- consoleCollector.current.start();
1378
- }
1379
- if (enableNetwork && !networkCollector.current) {
1380
- const flintHost = (() => {
1381
- try {
1382
- return new URL(serverUrl).hostname;
1383
- } catch {
1384
- return "";
1385
- }
1386
- })();
1387
- networkCollector.current = (0, import_flint_core7.createNetworkCollector)(flintHost ? [flintHost] : []);
1388
- networkCollector.current.start();
1389
- }
1390
- if (enableFormErrors && !formErrorCollector.current) {
1391
- formErrorCollector.current = (0, import_flint_core5.createFormErrorCollector)();
1392
- formErrorCollector.current.start();
1393
- (0, import_flint_core9._setFormErrorCollector)(formErrorCollector.current);
1394
- }
1395
- if (enableFrustration && !frustrationCollector.current) {
1396
- frustrationCollector.current = (0, import_flint_core6.createFrustrationCollector)();
1397
- frustrationCollector.current.start();
1398
- }
1316
+ const didInjectReplay = (0, import_react4.useRef)(false);
1317
+ if (!didInjectReplay.current && config.enableReplay && !import_flint_core7.Flint.getInstance()?.stopReplay) {
1318
+ didInjectReplay.current = true;
1399
1319
  }
1400
- (0, import_react4.useEffect)(() => {
1401
- if (globalInit) return;
1402
- let cancelled = false;
1403
- if (enableReplay) {
1404
- import("rrweb").then(({ record }) => {
1405
- if (cancelled) return;
1406
- const stopFn = record({
1407
- emit(event) {
1408
- replayEvents.current.push(event);
1409
- const cutoff = Date.now() - REPLAY_WINDOW_MS;
1410
- while (replayEvents.current.length > 0 && replayEvents.current[0].timestamp < cutoff) {
1411
- replayEvents.current.shift();
1412
- }
1413
- }
1414
- });
1415
- stopReplay.current = stopFn ?? null;
1416
- });
1417
- }
1418
- return () => {
1419
- cancelled = true;
1420
- consoleCollector.current?.stop();
1421
- networkCollector.current?.stop();
1422
- formErrorCollector.current?.stop();
1423
- (0, import_flint_core9._setFormErrorCollector)(null);
1424
- frustrationCollector.current?.stop();
1425
- stopReplay.current?.();
1426
- };
1427
- }, [enableReplay, globalInit]);
1428
- (0, import_react4.useEffect)(() => {
1429
- if (globalInit) return;
1430
- if (!enableFrustration || !autoReportFrustration || !frustrationCollector.current) return;
1431
- const unsubscribe = frustrationCollector.current.onFrustration(async (event) => {
1432
- const user2 = resolvedUser;
1433
- await (0, import_flint_core.submitReport)(serverUrl, projectKey, {
1434
- reporterId: user2?.id ?? "anonymous",
1435
- reporterName: user2?.name ?? "Anonymous",
1436
- reporterEmail: user2?.email,
1437
- description: `[Auto-detected] ${event.type.replace(/_/g, " ")}: ${event.details}`,
1438
- severity: event.type === "error_loop" ? "P1" : event.type === "rage_click" ? "P2" : "P3",
1439
- url: event.url,
1440
- meta: {
1441
- environment: (0, import_flint_core4.collectEnvironment)(),
1442
- consoleLogs: consoleCollector.current?.getEntries() ?? [],
1443
- networkErrors: networkCollector.current?.getEntries() ?? [],
1444
- formErrors: formErrorCollector.current?.getEntries() ?? [],
1445
- frustrationEvent: event
1446
- }
1447
- }).catch(() => {
1448
- });
1449
- });
1450
- return unsubscribe;
1451
- }, [enableFrustration, autoReportFrustration, globalInit, projectKey, resolvedUser, serverUrl]);
1320
+ const global = import_flint_core7.Flint.getInstance();
1452
1321
  const label = buttonLabel ?? t("buttonLabel");
1453
1322
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1454
1323
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
@@ -1535,10 +1404,8 @@ function WidgetContent({
1535
1404
  open && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1536
1405
  FlintModal,
1537
1406
  {
1538
- projectKey,
1539
- serverUrl,
1540
1407
  user: resolvedUser,
1541
- meta,
1408
+ meta: config.meta,
1542
1409
  theme,
1543
1410
  zIndex,
1544
1411
  onClose: () => {
@@ -1547,11 +1414,11 @@ function WidgetContent({
1547
1414
  pendingSelection.current = "";
1548
1415
  },
1549
1416
  getEnvironment: import_flint_core4.collectEnvironment,
1550
- getConsoleLogs: () => globalInit ? global?.console?.getEntries() ?? [] : consoleCollector.current?.getEntries() ?? [],
1551
- getNetworkErrors: () => globalInit ? global?.network?.getEntries() ?? [] : networkCollector.current?.getEntries() ?? [],
1552
- getFormErrors: () => globalInit ? global?.formErrors?.getEntries() ?? [] : formErrorCollector.current?.getEntries() ?? [],
1553
- getReplayEvents: () => globalInit ? import_flint_core10.Flint.getReplayEvents() : [...replayEvents.current],
1554
- getExternalReplayUrl,
1417
+ getConsoleLogs: () => global?.console?.getEntries() ?? [],
1418
+ getNetworkErrors: () => global?.network?.getEntries() ?? [],
1419
+ getFormErrors: () => global?.formErrors?.getEntries() ?? [],
1420
+ getReplayEvents: () => import_flint_core7.Flint.getReplayEvents(),
1421
+ getExternalReplayUrl: () => import_flint_core7.Flint.getExternalReplayUrl(),
1555
1422
  initialSelection: pendingSelection.current,
1556
1423
  enableScreenshot,
1557
1424
  enableTextIssues,
@@ -1606,7 +1473,6 @@ function SparkIcon2() {
1606
1473
  0 && (module.exports = {
1607
1474
  Flint,
1608
1475
  FlintModal,
1609
- FlintWidget,
1610
- flint
1476
+ FlintWidget
1611
1477
  });
1612
1478
  //# sourceMappingURL=index.cjs.map