@flareapp/vue 2.4.0 → 2.5.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.mjs CHANGED
@@ -1,428 +1,8 @@
1
- import { convertToError, flare, redactFullPath, resolveDenylist } from "@flareapp/js";
2
- import { defineComponent, getCurrentInstance, onErrorCaptured, ref, watch } from "vue";
1
+ import { i as registerDefaultFlare, n as flareVue, r as DEFAULT_PROPS_DENYLIST, t as FlareErrorBoundary } from "./FlareErrorBoundary-9LmNTGFB.mjs";
2
+ import { flare } from "@flareapp/js";
3
3
 
4
- //#region src/constants.ts
5
- const PACKAGE_VERSION = typeof process !== "undefined" && typeof process.env?.PACKAGE_VERSION !== "undefined" ? process.env.PACKAGE_VERSION : "?";
6
- const MAX_HIERARCHY_DEPTH = 50;
7
- const DEFAULT_PROPS_DENYLIST = /password|passwd|pwd|token|secret|authorization|\bauth\b|bearer|oauth|credentials?|cookie|api[-_]?key|private[-_]?key|session|csrf|xsrf|\bpin\b|\bssn\b|card[-_]?number|\bcvv\b/i;
8
- function resolveDenylist$1(custom, replaceDefault = false) {
9
- return resolveDenylist(custom, replaceDefault, DEFAULT_PROPS_DENYLIST);
10
- }
11
- const MAX_PROP_STRING_LENGTH = 1e3;
12
- const MAX_PROP_ARRAY_LENGTH = 100;
13
- const MAX_PROP_OBJECT_KEYS = 100;
14
- const INFO_TO_ORIGIN = {
15
- "setup function": "setup",
16
- "render function": "render",
17
- "component update": "render",
18
- "watcher getter": "watcher",
19
- "watcher callback": "watcher",
20
- "watcher cleanup function": "watcher",
21
- "native event handler": "event",
22
- "component event handler": "event",
23
- "beforeCreate hook": "lifecycle",
24
- "created hook": "lifecycle",
25
- "beforeMount hook": "lifecycle",
26
- "mounted hook": "lifecycle",
27
- "beforeUpdate hook": "lifecycle",
28
- "updated hook": "lifecycle",
29
- "beforeUnmount hook": "lifecycle",
30
- "unmounted hook": "lifecycle",
31
- "activated hook": "lifecycle",
32
- "deactivated hook": "lifecycle",
33
- "errorCaptured hook": "lifecycle",
34
- "renderTracked hook": "lifecycle",
35
- "renderTriggered hook": "lifecycle",
36
- "serverPrefetch hook": "lifecycle",
37
- "vnode hook": "lifecycle",
38
- "directive hook": "lifecycle",
39
- "transition hook": "lifecycle",
40
- "ref function": "setup",
41
- "async component loader": "setup",
42
- "scheduler flush": "render",
43
- "app errorHandler": "lifecycle",
44
- "app warnHandler": "lifecycle",
45
- "app unmount cleanup function": "lifecycle",
46
- "0": "setup",
47
- "1": "render",
48
- "2": "watcher",
49
- "3": "watcher",
50
- "4": "watcher",
51
- "5": "event",
52
- "6": "event",
53
- "7": "lifecycle",
54
- "8": "lifecycle",
55
- "9": "lifecycle",
56
- "10": "lifecycle",
57
- "11": "lifecycle",
58
- "12": "setup",
59
- "13": "setup",
60
- "14": "render",
61
- "15": "render",
62
- "16": "lifecycle",
63
- "sp": "lifecycle",
64
- "bc": "lifecycle",
65
- "c": "lifecycle",
66
- "bm": "lifecycle",
67
- "m": "lifecycle",
68
- "bu": "lifecycle",
69
- "u": "lifecycle",
70
- "bum": "lifecycle",
71
- "um": "lifecycle",
72
- "a": "lifecycle",
73
- "da": "lifecycle",
74
- "ec": "lifecycle",
75
- "rtc": "lifecycle",
76
- "rtg": "lifecycle"
77
- };
78
-
79
- //#endregion
80
- //#region src/getComponentName.ts
81
- function getComponentName(instance) {
82
- if (!instance) return "AnonymousComponent";
83
- const options = instance.$options;
84
- return options.__name || options.name || "AnonymousComponent";
85
- }
86
-
87
- //#endregion
88
- //#region src/buildComponentHierarchy.ts
89
- function buildComponentHierarchy(instance) {
90
- const hierarchy = [];
91
- let current = instance;
92
- while (current && hierarchy.length < MAX_HIERARCHY_DEPTH) {
93
- hierarchy.push(getComponentName(current));
94
- current = current.$parent;
95
- }
96
- return hierarchy;
97
- }
98
-
99
- //#endregion
100
- //#region src/serializeProps.ts
101
- function serializeProps(value, maxDepth, denylist = DEFAULT_PROPS_DENYLIST) {
102
- return serialize(value, 0, maxDepth, /* @__PURE__ */ new WeakSet(), denylist);
103
- }
104
- function serialize(value, depth, maxDepth, seen, denylist) {
105
- if (value === null) return null;
106
- const type = typeof value;
107
- if (type === "function") return "[Function]";
108
- if (type === "symbol") return "[Symbol]";
109
- if (type === "bigint") return value.toString();
110
- if (type === "string") return truncateString(value);
111
- if (type !== "object") return value;
112
- if (seen.has(value)) return "[Circular]";
113
- if (Array.isArray(value)) {
114
- if (depth > maxDepth) return "[Array]";
115
- seen.add(value);
116
- const out = (value.length > MAX_PROP_ARRAY_LENGTH ? value.slice(0, MAX_PROP_ARRAY_LENGTH) : value).map((item) => serialize(item, depth + 1, maxDepth, seen, denylist));
117
- if (value.length > MAX_PROP_ARRAY_LENGTH) out.push(`[… ${value.length - MAX_PROP_ARRAY_LENGTH} more items]`);
118
- seen.delete(value);
119
- return out;
120
- }
121
- if (!isPlainObject(value)) return "[Object]";
122
- if (depth > maxDepth) return "[Object]";
123
- seen.add(value);
124
- const out = {};
125
- const keys = Object.keys(value);
126
- const limitedKeys = keys.length > MAX_PROP_OBJECT_KEYS ? keys.slice(0, MAX_PROP_OBJECT_KEYS) : keys;
127
- for (const key of limitedKeys) {
128
- if (denylist.test(key)) {
129
- out[key] = "[redacted]";
130
- continue;
131
- }
132
- out[key] = serialize(value[key], depth + 1, maxDepth, seen, denylist);
133
- }
134
- if (keys.length > MAX_PROP_OBJECT_KEYS) out["…"] = `[${keys.length - MAX_PROP_OBJECT_KEYS} more keys]`;
135
- seen.delete(value);
136
- return out;
137
- }
138
- function truncateString(value) {
139
- if (value.length <= MAX_PROP_STRING_LENGTH) return value;
140
- return `${value.slice(0, MAX_PROP_STRING_LENGTH)}…[truncated ${value.length - MAX_PROP_STRING_LENGTH} chars]`;
141
- }
142
- function isPlainObject(value) {
143
- if (value === null || typeof value !== "object") return false;
144
- const prototype = Object.getPrototypeOf(value);
145
- return prototype === null || prototype === Object.prototype;
146
- }
147
-
148
- //#endregion
149
- //#region src/buildComponentHierarchyFrames.ts
150
- function buildComponentHierarchyFrames(instance, options) {
151
- const frames = [];
152
- let current = instance;
153
- while (current && frames.length < MAX_HIERARCHY_DEPTH) {
154
- const frameOptions = current.$options;
155
- const frame = {
156
- component: getComponentName(current),
157
- file: frameOptions.__file ?? null
158
- };
159
- if (options.attachProps && current.$props) frame.props = serializeProps(current.$props, options.propsMaxDepth, options.propsDenylist);
160
- frames.push(frame);
161
- current = current.$parent;
162
- }
163
- return frames;
164
- }
165
-
166
- //#endregion
167
- //#region src/getErrorOrigin.ts
168
- function getErrorOrigin(info) {
169
- return INFO_TO_ORIGIN[info] ?? "unknown";
170
- }
171
-
172
- //#endregion
173
- //#region src/getRouteContext.ts
174
- const ROUTE_PARAMS_DEPTH = 2;
175
- function getRouteContext(router, options = {}) {
176
- if (!router || typeof router !== "object" || !("currentRoute" in router)) return null;
177
- const currentRouteRef = router.currentRoute;
178
- if (!currentRouteRef || typeof currentRouteRef !== "object" || !("value" in currentRouteRef)) return null;
179
- const route = currentRouteRef.value;
180
- if (!route || typeof route !== "object") return null;
181
- const r = route;
182
- const name = r.name;
183
- const denylist = options.denylist ?? DEFAULT_PROPS_DENYLIST;
184
- const params = r.params && typeof r.params === "object" ? r.params : {};
185
- const query = r.query && typeof r.query === "object" ? r.query : {};
186
- return {
187
- name: typeof name === "string" ? name : typeof name === "symbol" ? name.toString() : null,
188
- path: typeof r.path === "string" ? r.path : "",
189
- fullPath: typeof r.fullPath === "string" ? redactFullPath(r.fullPath, denylist) : "",
190
- params: serializeProps(params, ROUTE_PARAMS_DEPTH, denylist),
191
- query: serializeProps(query, ROUTE_PARAMS_DEPTH, denylist),
192
- hash: typeof r.hash === "string" ? r.hash : "",
193
- matched: Array.isArray(r.matched) ? r.matched.map((record) => {
194
- if (!record || typeof record !== "object") return "unknown";
195
- const n = record.name;
196
- return typeof n === "string" ? n : typeof n === "symbol" ? n.toString() : "unknown";
197
- }) : []
198
- };
199
- }
200
-
201
- //#endregion
202
- //#region src/flareVue.ts
203
- function vueContextToAttributes(context) {
204
- const vue = {
205
- info: context.vue.info,
206
- errorOrigin: context.vue.errorOrigin,
207
- componentName: context.vue.componentName,
208
- componentHierarchy: context.vue.componentHierarchy,
209
- componentHierarchyFrames: context.vue.componentHierarchyFrames
210
- };
211
- if (context.vue.componentProps) vue.componentProps = context.vue.componentProps;
212
- if (context.vue.route) vue.route = context.vue.route;
213
- return { "context.custom": { vue } };
214
- }
215
- function vueWarningContextToAttributes(context) {
216
- const vue = {
217
- type: context.vue.type,
218
- info: context.vue.info,
219
- componentName: context.vue.componentName,
220
- componentTrace: context.vue.componentTrace
221
- };
222
- if (context.vue.route) vue.route = context.vue.route;
223
- return { "context.custom": { vue } };
224
- }
225
- const installedApps = /* @__PURE__ */ new WeakSet();
226
- const flareVue = (app, options) => {
227
- if (installedApps.has(app)) return;
228
- installedApps.add(app);
229
- flare.setSdkInfo({
230
- name: "@flareapp/vue",
231
- version: PACKAGE_VERSION
232
- });
233
- flare.setFramework({
234
- name: "Vue",
235
- version: app.version
236
- });
237
- const attachProps = options?.attachProps ?? false;
238
- const propsMaxDepth = options?.propsMaxDepth ?? 2;
239
- const propsDenylist = resolveDenylist$1(options?.propsDenylist, options?.replaceDefaultDenylist);
240
- const initialErrorHandler = app.config.errorHandler;
241
- app.config.errorHandler = (error, instance, info) => {
242
- const errorToReport = convertToError(error);
243
- options?.beforeEvaluate?.({
244
- error: errorToReport,
245
- instance,
246
- info
247
- });
248
- const errorOrigin = getErrorOrigin(info);
249
- const componentName = getComponentName(instance);
250
- const componentProps = attachProps && instance?.$props ? serializeProps(instance.$props, propsMaxDepth, propsDenylist) : void 0;
251
- const componentHierarchy = buildComponentHierarchy(instance);
252
- const componentHierarchyFrames = buildComponentHierarchyFrames(instance, {
253
- attachProps,
254
- propsMaxDepth,
255
- propsDenylist
256
- });
257
- const route = getRouteContext(app.config.globalProperties.$router, { denylist: propsDenylist });
258
- const context = { vue: {
259
- info,
260
- errorOrigin,
261
- componentName,
262
- ...componentProps && { componentProps },
263
- componentHierarchy,
264
- componentHierarchyFrames,
265
- ...route && { route }
266
- } };
267
- const finalContext = options?.beforeSubmit?.({
268
- error: errorToReport,
269
- instance,
270
- info,
271
- context
272
- }) ?? context;
273
- flare.reportSilently(errorToReport, vueContextToAttributes(finalContext));
274
- options?.afterSubmit?.({
275
- error: errorToReport,
276
- instance,
277
- info,
278
- context: finalContext
279
- });
280
- if (typeof initialErrorHandler === "function") {
281
- initialErrorHandler(error, instance, info);
282
- return;
283
- }
284
- console.error(error);
285
- };
286
- if (options?.captureWarnings) {
287
- const initialWarnHandler = app.config.warnHandler;
288
- app.config.warnHandler = (msg, instance, trace) => {
289
- const componentName = getComponentName(instance);
290
- const route = getRouteContext(app.config.globalProperties.$router, { denylist: propsDenylist });
291
- const context = { vue: {
292
- type: "warning",
293
- info: msg,
294
- componentName,
295
- componentTrace: trace,
296
- ...route && { route }
297
- } };
298
- Promise.resolve(flare.reportMessage(msg, "warning", vueWarningContextToAttributes(context))).catch(() => {});
299
- if (typeof initialWarnHandler === "function") initialWarnHandler(msg, instance, trace);
300
- };
301
- }
302
- };
303
-
304
- //#endregion
305
- //#region src/FlareErrorBoundary.ts
306
- const FlareErrorBoundary = defineComponent({
307
- name: "FlareErrorBoundary",
308
- props: {
309
- beforeEvaluate: {
310
- type: Function,
311
- default: void 0
312
- },
313
- beforeSubmit: {
314
- type: Function,
315
- default: void 0
316
- },
317
- afterSubmit: {
318
- type: Function,
319
- default: void 0
320
- },
321
- onReset: {
322
- type: Function,
323
- default: void 0
324
- },
325
- resetKeys: {
326
- type: Array,
327
- default: void 0
328
- },
329
- attachProps: {
330
- type: Boolean,
331
- default: false
332
- },
333
- propsMaxDepth: {
334
- type: Number,
335
- default: 2
336
- },
337
- propsDenylist: {
338
- type: RegExp,
339
- default: void 0
340
- },
341
- replaceDefaultDenylist: {
342
- type: Boolean,
343
- default: false
344
- }
345
- },
346
- setup(props, { slots }) {
347
- const currentInstance = getCurrentInstance();
348
- const error = ref(null);
349
- const componentProps = ref(void 0);
350
- const componentHierarchy = ref([]);
351
- const componentHierarchyFrames = ref([]);
352
- const resetErrorBoundary = () => {
353
- props.onReset?.(error.value);
354
- error.value = null;
355
- componentProps.value = void 0;
356
- componentHierarchy.value = [];
357
- componentHierarchyFrames.value = [];
358
- };
359
- watch(() => props.resetKeys, (nextKeys, prevKeys) => {
360
- if (error.value === null || !nextKeys || !prevKeys) return;
361
- const lengthChanged = prevKeys.length !== nextKeys.length;
362
- const valuesChanged = nextKeys.some((key, i) => !Object.is(key, prevKeys[i]));
363
- if (lengthChanged || valuesChanged) resetErrorBoundary();
364
- });
365
- onErrorCaptured((currentError, instance, info) => {
366
- const errorToReport = convertToError(currentError);
367
- props.beforeEvaluate?.({
368
- error: errorToReport,
369
- instance,
370
- info
371
- });
372
- const resolvedDenylist = resolveDenylist$1(props.propsDenylist, props.replaceDefaultDenylist);
373
- const hierarchy = buildComponentHierarchy(instance);
374
- const hierarchyFrames = buildComponentHierarchyFrames(instance, {
375
- attachProps: props.attachProps,
376
- propsMaxDepth: props.propsMaxDepth,
377
- propsDenylist: resolvedDenylist
378
- });
379
- const componentName = getComponentName(instance);
380
- error.value = errorToReport;
381
- const instanceProps = props.attachProps && instance?.$props ? serializeProps(instance.$props, props.propsMaxDepth, resolvedDenylist) : void 0;
382
- const errorOrigin = getErrorOrigin(info);
383
- const route = getRouteContext(currentInstance?.appContext.config.globalProperties.$router, { denylist: resolvedDenylist });
384
- const context = { vue: {
385
- info,
386
- errorOrigin,
387
- ...route && { route },
388
- componentName,
389
- ...instanceProps && { componentProps: instanceProps },
390
- componentHierarchy: hierarchy,
391
- componentHierarchyFrames: hierarchyFrames
392
- } };
393
- const finalContext = props.beforeSubmit?.({
394
- error: errorToReport,
395
- instance,
396
- info,
397
- context
398
- }) ?? context;
399
- componentProps.value = finalContext.vue.componentProps;
400
- componentHierarchy.value = finalContext.vue.componentHierarchy;
401
- componentHierarchyFrames.value = finalContext.vue.componentHierarchyFrames;
402
- flare.reportSilently(errorToReport, vueContextToAttributes(finalContext));
403
- props.afterSubmit?.({
404
- error: errorToReport,
405
- instance,
406
- info,
407
- context: finalContext
408
- });
409
- return false;
410
- });
411
- return () => {
412
- if (error.value !== null) {
413
- if (slots.fallback) return slots.fallback({
414
- error: error.value,
415
- ...componentProps.value && { componentProps: componentProps.value },
416
- componentHierarchy: componentHierarchy.value,
417
- componentHierarchyFrames: componentHierarchyFrames.value,
418
- resetErrorBoundary
419
- });
420
- return null;
421
- }
422
- return slots.default?.();
423
- };
424
- }
425
- });
4
+ //#region src/index.ts
5
+ registerDefaultFlare(() => flare);
426
6
 
427
7
  //#endregion
428
8
  export { DEFAULT_PROPS_DENYLIST, FlareErrorBoundary, flareVue };
@@ -0,0 +1,6 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_FlareErrorBoundary = require('./FlareErrorBoundary-G0Jqt8zN.cjs');
3
+
4
+ exports.DEFAULT_PROPS_DENYLIST = require_FlareErrorBoundary.DEFAULT_PROPS_DENYLIST;
5
+ exports.FlareErrorBoundary = require_FlareErrorBoundary.FlareErrorBoundary;
6
+ exports.flareVue = require_FlareErrorBoundary.flareVue;
@@ -0,0 +1,2 @@
1
+ import { a as ErrorOrigin, c as FlareVueContext, d as RouteContext, f as RouteParamValue, i as ComponentHierarchyFrame, l as FlareVueOptions, n as flareVue, o as FlareErrorBoundaryFallbackProps, p as RouteQueryValue, r as FlareErrorBoundary, s as FlareErrorBoundaryHookParams, t as DEFAULT_PROPS_DENYLIST, u as FlareVueWarningContext } from "./constants-B6O_8KY6.cjs";
2
+ export { type ComponentHierarchyFrame, DEFAULT_PROPS_DENYLIST, type ErrorOrigin, FlareErrorBoundary, type FlareErrorBoundaryFallbackProps, type FlareErrorBoundaryHookParams, type FlareVueContext, type FlareVueOptions, type FlareVueWarningContext, type RouteContext, type RouteParamValue, type RouteQueryValue, flareVue };
@@ -0,0 +1,2 @@
1
+ import { a as ErrorOrigin, c as FlareVueContext, d as RouteContext, f as RouteParamValue, i as ComponentHierarchyFrame, l as FlareVueOptions, n as flareVue, o as FlareErrorBoundaryFallbackProps, p as RouteQueryValue, r as FlareErrorBoundary, s as FlareErrorBoundaryHookParams, t as DEFAULT_PROPS_DENYLIST, u as FlareVueWarningContext } from "./constants-DCI9dIQ_.mjs";
2
+ export { type ComponentHierarchyFrame, DEFAULT_PROPS_DENYLIST, type ErrorOrigin, FlareErrorBoundary, type FlareErrorBoundaryFallbackProps, type FlareErrorBoundaryHookParams, type FlareVueContext, type FlareVueOptions, type FlareVueWarningContext, type RouteContext, type RouteParamValue, type RouteQueryValue, flareVue };
@@ -0,0 +1,3 @@
1
+ import { n as flareVue, r as DEFAULT_PROPS_DENYLIST, t as FlareErrorBoundary } from "./FlareErrorBoundary-9LmNTGFB.mjs";
2
+
3
+ export { DEFAULT_PROPS_DENYLIST, FlareErrorBoundary, flareVue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flareapp/vue",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Vue client for flareapp.io",
5
5
  "homepage": "https://flareapp.io",
6
6
  "bugs": "https://github.com/spatie/flare-client-js/issues",
@@ -24,6 +24,10 @@
24
24
  "files": [
25
25
  "dist"
26
26
  ],
27
+ "sideEffects": [
28
+ "./dist/index.cjs",
29
+ "./dist/index.mjs"
30
+ ],
27
31
  "main": "./dist/index.cjs",
28
32
  "module": "./dist/index.mjs",
29
33
  "types": "./dist/index.d.cts",
@@ -37,16 +41,31 @@
37
41
  "types": "./dist/index.d.cts",
38
42
  "default": "./dist/index.cjs"
39
43
  }
44
+ },
45
+ "./inject": {
46
+ "import": {
47
+ "types": "./dist/inject.d.mts",
48
+ "default": "./dist/inject.mjs"
49
+ },
50
+ "require": {
51
+ "types": "./dist/inject.d.cts",
52
+ "default": "./dist/inject.cjs"
53
+ }
40
54
  }
41
55
  },
42
56
  "scripts": {
43
57
  "prepublishOnly": "npm run build",
44
- "build": "tsdown src/index.ts --format cjs,esm --dts --env.PACKAGE_VERSION=\"$(node -p \"require('./package.json').version\")\" --clean",
58
+ "build": "tsdown src/index.ts src/inject.ts --format cjs,esm --dts --env.PACKAGE_VERSION=\"$(node -p \"require('./package.json').version\")\" --clean",
45
59
  "typescript": "tsc --noEmit",
46
60
  "release": "release-it",
47
- "test": "vitest run"
61
+ "test": "vitest run",
62
+ "verify:inject": "node scripts/verify-inject-no-root.mjs"
63
+ },
64
+ "dependencies": {
65
+ "@flareapp/core": "2.5.0"
48
66
  },
49
67
  "devDependencies": {
68
+ "@flareapp/electron": "file:../electron",
50
69
  "@flareapp/js": "file:../js",
51
70
  "@vue/test-utils": "^2.4.0",
52
71
  "jsdom": "^26.1.0",
@@ -57,7 +76,7 @@
57
76
  "vue-router": "^5.0.0"
58
77
  },
59
78
  "peerDependencies": {
60
- "@flareapp/js": "^2.4.0",
79
+ "@flareapp/js": "^2.5.0",
61
80
  "vue": "^3.0.0",
62
81
  "vue-router": "^4.0.0 || ^5.0.0"
63
82
  },