@flareapp/js 2.9.0 → 2.11.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/README.md CHANGED
@@ -37,6 +37,49 @@ flare.setUser({
37
37
 
38
38
  Recognised fields: `id` (→ `user.id`), `email` (→ `user.email`), `fullName` (→ `user.full_name`), `ipAddress` (→ `client.address`). Any extra keys are collected under `user.attributes`. Pass `null` to clear the user on logout: `flare.setUser(null)`.
39
39
 
40
+ ## Cookie consent and GDPR
41
+
42
+ The client can run behind a consent tool. When consent is off, it sends nothing. Before consent, it does not even assemble a report.
43
+
44
+ The switch is one method:
45
+
46
+ ```javascript
47
+ flare.setConsent(true); // allow sending
48
+ flare.setConsent(false); // stop sending, and drop anything captured earlier
49
+ ```
50
+
51
+ Recommended flow: do not call `flare.light(key)` until consent is granted. With no key, nothing sends, so this covers the moment before your consent code runs. Use `setConsent` for withdrawal and re-grant, because once the key is set it is the only clean off switch.
52
+
53
+ ```javascript
54
+ import { flare } from '@flareapp/js';
55
+
56
+ // Cookiebot example. OneTrust exposes OptanonWrapper; the idea is the same.
57
+ window.addEventListener('CookiebotOnAccept', () => {
58
+ flare.light('your-project-key'); // first grant: start the client
59
+ flare.setConsent(true); // and allow sending
60
+ });
61
+
62
+ window.addEventListener('CookiebotOnDecline', () => {
63
+ flare.setConsent(false); // withdrawal: stop all sends, drop buffers
64
+ });
65
+ ```
66
+
67
+ If you set the key at boot instead of waiting, start with consent off, then turn it on when the user accepts:
68
+
69
+ ```javascript
70
+ import { flare } from '@flareapp/js';
71
+
72
+ flare.configure({ hasConsent: false }); // start off, before anything can send
73
+ flare.light('your-project-key');
74
+
75
+ window.addEventListener('CookiebotOnAccept', () => flare.setConsent(true));
76
+ window.addEventListener('CookiebotOnDecline', () => flare.setConsent(false));
77
+ ```
78
+
79
+ Put `configure({ hasConsent: false })` first, right after the import, so the gate is off before an early uncaught error can assemble a report.
80
+
81
+ Consent defaults to on, so setups without a consent tool are unchanged. `setConsent(false)` stops data leaving the browser. It does not remove the `fetch` and `XHR` patches that tracing and breadcrumbs install, because those only read in memory and never send on their own. To remove those too, call `flare.configure({ enableTracing: false, enableBreadcrumbs: false })`.
82
+
40
83
  ## Logging
41
84
 
42
85
  Beyond errors, the client can send structured logs. Logs are opt-in: enable them with `enableLogs`, then call any of
package/dist/browser.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_catchWindowErrors = require('./catchWindowErrors-cR2D7kju.cjs');
2
+ const require_catchWindowErrors = require('./catchWindowErrors-BgmDgTlR.cjs');
3
3
  let _flareapp_core = require("@flareapp/core");
4
4
 
5
5
  //#region src/browser.ts
package/dist/browser.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { C as currentHref, D as absoluteHref, E as routeName, O as absoluteUrl, S as registerNavigationSource, T as resolveHref, _ as BrowserFlushScheduler, a as recordComponentSpan, b as browserUrlContext, c as startBrowserTracing, d as instrumentOnce, f as insulate, g as collectBrowser, h as FetchFileReader, i as nowNano, l as stopBrowserTracing, m as CLIENT_VERSION, n as createFlareResolver, o as reserveSpanId, p as safeInvoke, r as activeComponentRoot, s as resolveComponentParent, t as catchWindowErrors, u as BrowserSpanType, v as startBreadcrumbs, w as currentPath, x as withRequestPatches, y as traceRequests } from "./catchWindowErrors-C0gSVGiF.mjs";
1
+ import { C as currentHref, D as absoluteHref, E as routeName, O as absoluteUrl, S as registerNavigationSource, T as resolveHref, _ as BrowserFlushScheduler, a as recordComponentSpan, b as browserUrlContext, c as startBrowserTracing, d as instrumentOnce, f as insulate, g as collectBrowser, h as FetchFileReader, i as nowNano, l as stopBrowserTracing, m as CLIENT_VERSION, n as createFlareResolver, o as reserveSpanId, p as safeInvoke, r as activeComponentRoot, s as resolveComponentParent, t as catchWindowErrors, u as BrowserSpanType, v as startBreadcrumbs, w as currentPath, x as withRequestPatches, y as traceRequests } from "./catchWindowErrors-I_8ksYoj.mjs";
2
2
  import { Api, Flare as Flare$1, FrameworkName, GlobalScopeProvider } from "@flareapp/core";
3
3
 
4
4
  //#region src/browser.ts
@@ -995,6 +995,86 @@ function cookie(denylist) {
995
995
  return { "http.request.cookies": cookies };
996
996
  }
997
997
 
998
+ //#endregion
999
+ //#region src/browser/context/deviceReaders.ts
1000
+ const EFFECTIVE_TYPES = [
1001
+ "slow-2g",
1002
+ "2g",
1003
+ "3g",
1004
+ "4g"
1005
+ ];
1006
+ function readScreen() {
1007
+ if (typeof screen === "undefined" || typeof screen.width !== "number" || typeof screen.height !== "number") return null;
1008
+ const scale = typeof devicePixelRatio === "number" ? devicePixelRatio : void 0;
1009
+ return scale != null ? {
1010
+ width: screen.width,
1011
+ height: screen.height,
1012
+ scale
1013
+ } : {
1014
+ width: screen.width,
1015
+ height: screen.height
1016
+ };
1017
+ }
1018
+ function readNetwork(nav) {
1019
+ const network = {};
1020
+ if (typeof nav.onLine === "boolean") network.online = nav.onLine;
1021
+ const connection = nav.connection;
1022
+ if (connection) {
1023
+ const { effectiveType, downlink, rtt } = connection;
1024
+ if (effectiveType && EFFECTIVE_TYPES.includes(effectiveType)) network.effectiveType = effectiveType;
1025
+ if (typeof downlink === "number") network.downlinkMbps = downlink;
1026
+ if (typeof rtt === "number") network.rttMs = rtt;
1027
+ }
1028
+ return Object.keys(network).length > 0 ? network : null;
1029
+ }
1030
+ function readTimezone() {
1031
+ try {
1032
+ return Intl.DateTimeFormat().resolvedOptions().timeZone || void 0;
1033
+ } catch {
1034
+ return;
1035
+ }
1036
+ }
1037
+
1038
+ //#endregion
1039
+ //#region src/browser/context/deviceInfo.ts
1040
+ /** Reads what the User-Agent lacks: hardware, screen, network. Static reads cached; screen and network per call. */
1041
+ var BrowserDeviceInfoProvider = class {
1042
+ staticInfo = null;
1043
+ collect() {
1044
+ if (typeof window === "undefined" || typeof navigator === "undefined") return {};
1045
+ const nav = navigator;
1046
+ const info = {};
1047
+ const staticInfo = this.readStatic(nav);
1048
+ const screen = readScreen();
1049
+ const device = {
1050
+ ...staticInfo.device,
1051
+ ...screen ? { screen } : {}
1052
+ };
1053
+ if (Object.keys(device).length > 0) info.device = device;
1054
+ if (staticInfo.locale) info.locale = staticInfo.locale;
1055
+ const network = readNetwork(nav);
1056
+ if (network) info.network = network;
1057
+ return info;
1058
+ }
1059
+ readStatic(nav) {
1060
+ if (this.staticInfo) return this.staticInfo;
1061
+ const device = {};
1062
+ if (typeof nav.deviceMemory === "number") device.memoryGb = nav.deviceMemory;
1063
+ if (typeof nav.hardwareConcurrency === "number") device.cpuCores = nav.hardwareConcurrency;
1064
+ const locale = {};
1065
+ if (nav.language) locale.language = nav.language;
1066
+ const timezone = readTimezone();
1067
+ if (timezone) locale.timezone = timezone;
1068
+ this.staticInfo = {
1069
+ device: Object.keys(device).length > 0 ? device : void 0,
1070
+ locale: Object.keys(locale).length > 0 ? locale : void 0
1071
+ };
1072
+ return this.staticInfo;
1073
+ }
1074
+ };
1075
+ /** Shared singleton so the static read is cached across reports. */
1076
+ const browserDeviceInfoProvider = new BrowserDeviceInfoProvider();
1077
+
998
1078
  //#endregion
999
1079
  //#region src/browser/context/request.ts
1000
1080
  /**
@@ -1030,6 +1110,7 @@ function browserEntryPoint(config, urlOverride) {
1030
1110
  }
1031
1111
  const collectBrowser = (config) => {
1032
1112
  const attrs = { ...browserEntryPoint(config) };
1113
+ Object.assign(attrs, (0, _flareapp_core.deviceInfoToAttributes)(browserDeviceInfoProvider.collect()));
1033
1114
  if (typeof window === "undefined") return attrs;
1034
1115
  if (window?.location?.hostname) attrs["host.name"] = window.location.hostname;
1035
1116
  Object.assign(attrs, request(config.urlDenylist));
@@ -1056,7 +1137,7 @@ var FetchFileReader = class {
1056
1137
 
1057
1138
  //#endregion
1058
1139
  //#region src/env/index.ts
1059
- const CLIENT_VERSION = typeof process !== "undefined" && true ? "2.9.0" : "?";
1140
+ const CLIENT_VERSION = typeof process !== "undefined" && true ? "2.11.0" : "?";
1060
1141
 
1061
1142
  //#endregion
1062
1143
  //#region src/tracing/utils/instrumentationGuard.ts
@@ -1113,12 +1194,10 @@ function instrumentOnce(target, install) {
1113
1194
  //#region src/browser/context/collectBrowserSpanContext.ts
1114
1195
  /**
1115
1196
  * Entry point plus request identity for a pageload/navigation root. Deliberately leaner than the report
1116
- * context: no cookies, no structured query params, no host.name (that is resource-level). Captured at
1117
- * span start, so a long-lived root reflects the page it represents rather than the page at close.
1197
+ * context. Captured at span start, so a long-lived root reflects the page it represents rather than the
1198
+ * page at close.
1118
1199
  *
1119
- * @param hrefOverride destination href for a router that reports where it is going before the URL
1120
- * commits. Only the URL-derived keys come from it; the rest always reflect the live document. An
1121
- * unparseable override falls back to the live location instead of throwing into root creation.
1200
+ * @param hrefOverride destination href for a router that reports where it is going before the URL commits.
1122
1201
  */
1123
1202
  function collectBrowserSpanContext(config, hrefOverride) {
1124
1203
  if (typeof window === "undefined") return {};
@@ -1131,12 +1210,6 @@ function collectBrowserSpanContext(config, hrefOverride) {
1131
1210
  /**
1132
1211
  * Updates a root's url after a redirect, or when a newer navigation replaces this one. The root opened
1133
1212
  * with the first destination, so without this it reports a page the user never reached.
1134
- *
1135
- * Does not touch `flare.entry_point.handler.identifier` or `http.route`. Those hold the route template,
1136
- * and reading them back from the href would turn `/product/[id]` into `/product/p01`.
1137
- *
1138
- * Always sets `url.query`, even to an empty string. You can overwrite a span attribute but not remove
1139
- * it, so going from `/a?x=1` to `/b` would otherwise keep the old query.
1140
1213
  */
1141
1214
  function browserSpanUrlAttributes(config, href) {
1142
1215
  if (typeof window === "undefined") return {};
@@ -1,4 +1,4 @@
1
- import { BrowserSpanEventType, BrowserSpanType, BrowserSpanType as BrowserSpanType$1, SpanStatusCode, breadcrumbUrl, buildTraceparent, defaultNowNano, redactUrlQuery, routeRejection, spanId, urlAttributes } from "@flareapp/core";
1
+ import { BrowserSpanEventType, BrowserSpanType, BrowserSpanType as BrowserSpanType$1, SpanStatusCode, breadcrumbUrl, buildTraceparent, defaultNowNano, deviceInfoToAttributes, redactUrlQuery, routeRejection, spanId, urlAttributes } from "@flareapp/core";
2
2
 
3
3
  //#region src/breadcrumbs/utils/documentEvent.ts
4
4
  function onDocumentEvent(name, handle) {
@@ -995,6 +995,86 @@ function cookie(denylist) {
995
995
  return { "http.request.cookies": cookies };
996
996
  }
997
997
 
998
+ //#endregion
999
+ //#region src/browser/context/deviceReaders.ts
1000
+ const EFFECTIVE_TYPES = [
1001
+ "slow-2g",
1002
+ "2g",
1003
+ "3g",
1004
+ "4g"
1005
+ ];
1006
+ function readScreen() {
1007
+ if (typeof screen === "undefined" || typeof screen.width !== "number" || typeof screen.height !== "number") return null;
1008
+ const scale = typeof devicePixelRatio === "number" ? devicePixelRatio : void 0;
1009
+ return scale != null ? {
1010
+ width: screen.width,
1011
+ height: screen.height,
1012
+ scale
1013
+ } : {
1014
+ width: screen.width,
1015
+ height: screen.height
1016
+ };
1017
+ }
1018
+ function readNetwork(nav) {
1019
+ const network = {};
1020
+ if (typeof nav.onLine === "boolean") network.online = nav.onLine;
1021
+ const connection = nav.connection;
1022
+ if (connection) {
1023
+ const { effectiveType, downlink, rtt } = connection;
1024
+ if (effectiveType && EFFECTIVE_TYPES.includes(effectiveType)) network.effectiveType = effectiveType;
1025
+ if (typeof downlink === "number") network.downlinkMbps = downlink;
1026
+ if (typeof rtt === "number") network.rttMs = rtt;
1027
+ }
1028
+ return Object.keys(network).length > 0 ? network : null;
1029
+ }
1030
+ function readTimezone() {
1031
+ try {
1032
+ return Intl.DateTimeFormat().resolvedOptions().timeZone || void 0;
1033
+ } catch {
1034
+ return;
1035
+ }
1036
+ }
1037
+
1038
+ //#endregion
1039
+ //#region src/browser/context/deviceInfo.ts
1040
+ /** Reads what the User-Agent lacks: hardware, screen, network. Static reads cached; screen and network per call. */
1041
+ var BrowserDeviceInfoProvider = class {
1042
+ staticInfo = null;
1043
+ collect() {
1044
+ if (typeof window === "undefined" || typeof navigator === "undefined") return {};
1045
+ const nav = navigator;
1046
+ const info = {};
1047
+ const staticInfo = this.readStatic(nav);
1048
+ const screen = readScreen();
1049
+ const device = {
1050
+ ...staticInfo.device,
1051
+ ...screen ? { screen } : {}
1052
+ };
1053
+ if (Object.keys(device).length > 0) info.device = device;
1054
+ if (staticInfo.locale) info.locale = staticInfo.locale;
1055
+ const network = readNetwork(nav);
1056
+ if (network) info.network = network;
1057
+ return info;
1058
+ }
1059
+ readStatic(nav) {
1060
+ if (this.staticInfo) return this.staticInfo;
1061
+ const device = {};
1062
+ if (typeof nav.deviceMemory === "number") device.memoryGb = nav.deviceMemory;
1063
+ if (typeof nav.hardwareConcurrency === "number") device.cpuCores = nav.hardwareConcurrency;
1064
+ const locale = {};
1065
+ if (nav.language) locale.language = nav.language;
1066
+ const timezone = readTimezone();
1067
+ if (timezone) locale.timezone = timezone;
1068
+ this.staticInfo = {
1069
+ device: Object.keys(device).length > 0 ? device : void 0,
1070
+ locale: Object.keys(locale).length > 0 ? locale : void 0
1071
+ };
1072
+ return this.staticInfo;
1073
+ }
1074
+ };
1075
+ /** Shared singleton so the static read is cached across reports. */
1076
+ const browserDeviceInfoProvider = new BrowserDeviceInfoProvider();
1077
+
998
1078
  //#endregion
999
1079
  //#region src/browser/context/request.ts
1000
1080
  /**
@@ -1030,6 +1110,7 @@ function browserEntryPoint(config, urlOverride) {
1030
1110
  }
1031
1111
  const collectBrowser = (config) => {
1032
1112
  const attrs = { ...browserEntryPoint(config) };
1113
+ Object.assign(attrs, deviceInfoToAttributes(browserDeviceInfoProvider.collect()));
1033
1114
  if (typeof window === "undefined") return attrs;
1034
1115
  if (window?.location?.hostname) attrs["host.name"] = window.location.hostname;
1035
1116
  Object.assign(attrs, request(config.urlDenylist));
@@ -1056,7 +1137,7 @@ var FetchFileReader = class {
1056
1137
 
1057
1138
  //#endregion
1058
1139
  //#region src/env/index.ts
1059
- const CLIENT_VERSION = typeof process !== "undefined" && true ? "2.9.0" : "?";
1140
+ const CLIENT_VERSION = typeof process !== "undefined" && true ? "2.11.0" : "?";
1060
1141
 
1061
1142
  //#endregion
1062
1143
  //#region src/tracing/utils/instrumentationGuard.ts
@@ -1113,12 +1194,10 @@ function instrumentOnce(target, install) {
1113
1194
  //#region src/browser/context/collectBrowserSpanContext.ts
1114
1195
  /**
1115
1196
  * Entry point plus request identity for a pageload/navigation root. Deliberately leaner than the report
1116
- * context: no cookies, no structured query params, no host.name (that is resource-level). Captured at
1117
- * span start, so a long-lived root reflects the page it represents rather than the page at close.
1197
+ * context. Captured at span start, so a long-lived root reflects the page it represents rather than the
1198
+ * page at close.
1118
1199
  *
1119
- * @param hrefOverride destination href for a router that reports where it is going before the URL
1120
- * commits. Only the URL-derived keys come from it; the rest always reflect the live document. An
1121
- * unparseable override falls back to the live location instead of throwing into root creation.
1200
+ * @param hrefOverride destination href for a router that reports where it is going before the URL commits.
1122
1201
  */
1123
1202
  function collectBrowserSpanContext(config, hrefOverride) {
1124
1203
  if (typeof window === "undefined") return {};
@@ -1131,12 +1210,6 @@ function collectBrowserSpanContext(config, hrefOverride) {
1131
1210
  /**
1132
1211
  * Updates a root's url after a redirect, or when a newer navigation replaces this one. The root opened
1133
1212
  * with the first destination, so without this it reports a page the user never reached.
1134
- *
1135
- * Does not touch `flare.entry_point.handler.identifier` or `http.route`. Those hold the route template,
1136
- * and reading them back from the href would turn `/product/[id]` into `/product/p01`.
1137
- *
1138
- * Always sets `url.query`, even to an empty string. You can overwrite a span attribute but not remove
1139
- * it, so going from `/a?x=1` to `/b` would otherwise keep the old query.
1140
1213
  */
1141
1214
  function browserSpanUrlAttributes(config, href) {
1142
1215
  if (typeof window === "undefined") return {};
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_catchWindowErrors = require('./catchWindowErrors-cR2D7kju.cjs');
2
+ const require_catchWindowErrors = require('./catchWindowErrors-BgmDgTlR.cjs');
3
3
  const require_browser = require('./browser.cjs');
4
4
  let _flareapp_core = require("@flareapp/core");
5
5
 
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as createFlareResolver, t as catchWindowErrors } from "./catchWindowErrors-C0gSVGiF.mjs";
1
+ import { n as createFlareResolver, t as catchWindowErrors } from "./catchWindowErrors-I_8ksYoj.mjs";
2
2
  import { Flare } from "./browser.mjs";
3
3
  import { DEFAULT_URL_DENYLIST, FrameworkName, GlobalScopeProvider, Logger, NullFileReader, Scope, convertToError, redactObjectValues, redactUrlQuery, redactUrlQuery as redactFullPath, resolveDenylist, toCustomContext } from "@flareapp/core";
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flareapp/js",
3
- "version": "2.9.0",
3
+ "version": "2.11.0",
4
4
  "description": "JavaScript client for flareapp.io",
5
5
  "homepage": "https://flareapp.io",
6
6
  "bugs": {
@@ -59,7 +59,7 @@
59
59
  "release": "release-it"
60
60
  },
61
61
  "dependencies": {
62
- "@flareapp/core": "2.9.0"
62
+ "@flareapp/core": "2.11.0"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@flareapp/test-helpers": "*",