@grafana/faro-react 1.7.0 → 1.7.2

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
@@ -67,6 +67,26 @@ additional React specific functionality like router instrumentation, a custom Er
67
67
 
68
68
  ### Router v6 with Data Router
69
69
 
70
+ ```ts
71
+ initializeFaro({
72
+ // ...
73
+
74
+ instrumentations: [
75
+ // Load the default Web instrumentations
76
+ ...getWebInstrumentations(),
77
+
78
+ new ReactIntegration({
79
+ router: {
80
+ version: ReactRouterVersion.V6_data_router,
81
+ dependencies: {
82
+ matchRoutes,
83
+ },
84
+ },
85
+ }),
86
+ ],
87
+ });
88
+ ```
89
+
70
90
  Instrument the routes from a React data router (`BrowserRouter`, `HashRouter`, or `MemoryRouter`).
71
91
 
72
92
  In the file you create your data router, often the App.\* file pass your data router to the Faro-React
@@ -204,6 +224,28 @@ In case of an error it sends a Faro error event which contains the error message
204
224
  stack of the component which contains the exception, and the name of name of the error boundary
205
225
  if configured.
206
226
 
227
+ ```ts
228
+ import { initializeFaro } from '@grafana/faro-react';
229
+
230
+ initializeFaro({
231
+ // required: the URL of the Grafana collector
232
+ url: 'my/collector/url',
233
+
234
+ // required: the identification label of your application
235
+ app: {
236
+ name: 'my-react-app',
237
+ },
238
+
239
+ instrumentations: [
240
+ // Load the default Web instrumentations
241
+ ...getWebInstrumentations(),
242
+
243
+ // Must be initialized to get FaroErrorBoundary support
244
+ new ReactIntegration(),
245
+ ],
246
+ });
247
+ ```
248
+
207
249
  ```tsx
208
250
  import { FaroErrorBoundary } from '@grafana/faro-react';
209
251
 
@@ -240,14 +282,6 @@ Lifecycle callbacks:
240
282
  object as a parameter
241
283
  - `onReset`: Executed when React calls resetErrorBoundary, with the Error object as a parameter
242
284
 
243
- ```tsx
244
- // ...
245
-
246
- <FaroErrorBoundary>
247
- <MyComponent />
248
- </FaroErrorBoundary>
249
- ```
250
-
251
285
  ```tsx
252
286
  import { FaroErrorBoundary, PushErrorOptions } from '@grafana/faro-react';
253
287
 
@@ -1,5 +1,20 @@
1
1
  import type { ReactElement, ReactNode } from 'react';
2
2
  import type { ReactRouterLocation } from '../types';
3
+ interface IndexRouteObjectV6DataRouter {
4
+ caseSensitive?: boolean;
5
+ children?: undefined;
6
+ element?: React.ReactNode | null;
7
+ index: true;
8
+ path?: string;
9
+ }
10
+ export interface NonIndexRouteObjectV6DataRouter {
11
+ caseSensitive?: boolean;
12
+ children?: RouteObjectV6DataRouter[];
13
+ element?: React.ReactNode | null;
14
+ index?: false;
15
+ path?: string;
16
+ }
17
+ export type RouteObjectV6DataRouter = IndexRouteObjectV6DataRouter | NonIndexRouteObjectV6DataRouter;
3
18
  export interface ReactRouterV6BaseRouteObject {
4
19
  action?: (...args: any[]) => any;
5
20
  caseSensitive?: boolean;
@@ -31,7 +46,7 @@ export interface ReactRouterV6RouteMatch<ParamKey extends string = string> {
31
46
  pathnameBase: string;
32
47
  route: ReactRouterV6RouteObject;
33
48
  }
34
- export type ReactRouterV6CreateRoutesFromChildren = (children: ReactNode) => ReactRouterV6RouteObject[];
49
+ export type ReactRouterV6CreateRoutesFromChildren = (children: ReactNode) => ReactRouterV6RouteObject[] | RouteObjectV6DataRouter[];
35
50
  export type ReactRouterV6MatchRoutes = (routes: ReactRouterV6RouteObject[], location: Partial<ReactRouterLocation> | string, basename?: string | undefined) => ReactRouterV6RouteMatch[] | null;
36
51
  export type ReactRouterV6RoutesShape = (props: ReactRouterV6RoutesProps) => ReactElement | null;
37
52
  export type ReactRouterV6UseLocation = () => ReactRouterLocation;
@@ -50,3 +65,4 @@ export type EventRouteTransitionAttributes = {
50
65
  fromRoute?: string;
51
66
  fromUrl?: string;
52
67
  };
68
+ export {};
@@ -1,12 +1,12 @@
1
1
  import { NavigationType, ReactRouterLocation } from '../types';
2
- import type { ReactRouterV6RouteObject } from './types';
2
+ import type { RouteObjectV6DataRouter } from './types';
3
3
  interface RouterState {
4
4
  historyAction: NavigationType | any;
5
5
  location: ReactRouterLocation;
6
6
  }
7
7
  interface Router {
8
8
  state: RouterState;
9
- routes: ReactRouterV6RouteObject[];
9
+ routes: RouteObjectV6DataRouter[];
10
10
  subscribe(fn: (state: RouterState) => void): () => void;
11
11
  }
12
12
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/router/v6/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ReactElement, ReactNode } from 'react';\n\nimport type { ReactRouterLocation } from '../types';\n\nexport interface ReactRouterV6BaseRouteObject {\n action?: (...args: any[]) => any;\n caseSensitive?: boolean;\n hasErrorBoundary?: boolean;\n handle?: any;\n id?: string;\n loader?: (...args: any[]) => any;\n path?: string;\n shouldRevalidate?: (...args: any[]) => any;\n}\n\nexport type ReactRouterV6RouteObject = ReactRouterV6BaseRouteObject &\n (\n | {\n children?: undefined;\n index: true;\n }\n | {\n children?: ReactRouterV6RouteObject[];\n index?: false;\n }\n );\n\nexport interface ReactRouterV6RoutesProps {\n children?: ReactNode;\n location?: Partial<ReactRouterLocation> | string;\n routesComponent?: ReactRouterV6RoutesShape;\n}\n\nexport type ReactRouterV6Params<Key extends string = string> = {\n readonly [key in Key]: string | undefined;\n};\n\nexport interface ReactRouterV6RouteMatch<ParamKey extends string = string> {\n params: ReactRouterV6Params<ParamKey>;\n pathname: string;\n pathnameBase: string;\n route: ReactRouterV6RouteObject;\n}\n\nexport type ReactRouterV6CreateRoutesFromChildren = (children: ReactNode) => ReactRouterV6RouteObject[];\n\nexport type ReactRouterV6MatchRoutes = (\n routes: ReactRouterV6RouteObject[],\n location: Partial<ReactRouterLocation> | string,\n basename?: string | undefined\n) => ReactRouterV6RouteMatch[] | null;\n\nexport type ReactRouterV6RoutesShape = (props: ReactRouterV6RoutesProps) => ReactElement | null;\n\nexport type ReactRouterV6UseLocation = () => ReactRouterLocation;\n\nexport type ReactRouterV6UseNavigationType = () => 'POP' | 'PUSH' | 'REPLACE';\n\nexport interface ReactRouterV6Dependencies {\n createRoutesFromChildren: ReactRouterV6CreateRoutesFromChildren;\n matchRoutes: ReactRouterV6MatchRoutes;\n Routes: ReactRouterV6RoutesShape;\n useLocation: ReactRouterV6UseLocation;\n useNavigationType: ReactRouterV6UseNavigationType;\n}\n\nexport interface ReactRouterV6DataRouterDependencies {\n matchRoutes: ReactRouterV6MatchRoutes;\n}\n\nexport type EventRouteTransitionAttributes = {\n fromRoute?: string;\n fromUrl?: string;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/router/v6/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ReactElement, ReactNode } from 'react';\n\nimport type { ReactRouterLocation } from '../types';\n\ninterface IndexRouteObjectV6DataRouter {\n caseSensitive?: boolean;\n children?: undefined;\n element?: React.ReactNode | null;\n index: true;\n path?: string;\n}\n\nexport interface NonIndexRouteObjectV6DataRouter {\n caseSensitive?: boolean;\n children?: RouteObjectV6DataRouter[];\n element?: React.ReactNode | null;\n index?: false;\n path?: string;\n}\n\nexport type RouteObjectV6DataRouter = IndexRouteObjectV6DataRouter | NonIndexRouteObjectV6DataRouter;\n\nexport interface ReactRouterV6BaseRouteObject {\n action?: (...args: any[]) => any;\n caseSensitive?: boolean;\n hasErrorBoundary?: boolean;\n handle?: any;\n id?: string;\n loader?: (...args: any[]) => any;\n path?: string;\n shouldRevalidate?: (...args: any[]) => any;\n}\n\nexport type ReactRouterV6RouteObject = ReactRouterV6BaseRouteObject &\n (\n | {\n children?: undefined;\n index: true;\n }\n | {\n children?: ReactRouterV6RouteObject[];\n index?: false;\n }\n );\n\nexport interface ReactRouterV6RoutesProps {\n children?: ReactNode;\n location?: Partial<ReactRouterLocation> | string;\n routesComponent?: ReactRouterV6RoutesShape;\n}\n\nexport type ReactRouterV6Params<Key extends string = string> = {\n readonly [key in Key]: string | undefined;\n};\n\nexport interface ReactRouterV6RouteMatch<ParamKey extends string = string> {\n params: ReactRouterV6Params<ParamKey>;\n pathname: string;\n pathnameBase: string;\n route: ReactRouterV6RouteObject;\n}\n\nexport type ReactRouterV6CreateRoutesFromChildren = (\n children: ReactNode\n) => ReactRouterV6RouteObject[] | RouteObjectV6DataRouter[];\n\nexport type ReactRouterV6MatchRoutes = (\n routes: ReactRouterV6RouteObject[],\n location: Partial<ReactRouterLocation> | string,\n basename?: string | undefined\n) => ReactRouterV6RouteMatch[] | null;\n\nexport type ReactRouterV6RoutesShape = (props: ReactRouterV6RoutesProps) => ReactElement | null;\n\nexport type ReactRouterV6UseLocation = () => ReactRouterLocation;\n\nexport type ReactRouterV6UseNavigationType = () => 'POP' | 'PUSH' | 'REPLACE';\n\nexport interface ReactRouterV6Dependencies {\n createRoutesFromChildren: ReactRouterV6CreateRoutesFromChildren;\n matchRoutes: ReactRouterV6MatchRoutes;\n Routes: ReactRouterV6RoutesShape;\n useLocation: ReactRouterV6UseLocation;\n useNavigationType: ReactRouterV6UseNavigationType;\n}\n\nexport interface ReactRouterV6DataRouterDependencies {\n matchRoutes: ReactRouterV6MatchRoutes;\n}\n\nexport type EventRouteTransitionAttributes = {\n fromRoute?: string;\n fromUrl?: string;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"withFaroRouterInstrumentation.js","sourceRoot":"","sources":["../../../../src/router/v6/withFaroRouterInstrumentation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAAyE;AAEzE,mDAAyC;AACzC,kCAA+D;AAE/D,2DAAqD;AAErD,iCAA+C;AAa/C;;GAEG;AACH,SAAgB,6BAA6B,CAA4B,MAAS;IAChF,IAAI,SAAS,GAAmC,EAAE,CAAC;IAEnD,MAAM,CAAC,SAAS,CAAC,UAAC,KAAK;;QACrB,IAAM,cAAc,GAAmB,KAAK,CAAC,aAAa,CAAC;QAC3D,IAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,IAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAE7B,IAAI,kCAAa,IAAI,CAAC,cAAc,KAAK,sBAAc,CAAC,IAAI,IAAI,cAAc,KAAK,sBAAc,CAAC,GAAG,CAAC,EAAE;YACtG,IAAM,KAAK,GAAG,IAAA,4BAAoB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACrD,IAAM,GAAG,GAAG,MAAA,2BAAY,CAAC,QAAQ,0CAAE,IAAI,CAAC;YAExC,kBAAG,CAAC,SAAS,CAAC,iCAAkB,aAC9B,OAAO,EAAE,KAAK,EACd,KAAK,EAAE,MAAA,2BAAY,CAAC,QAAQ,0CAAE,IAAI,IAC/B,SAAS,EACZ,CAAC;YAEH,SAAS,GAAG;gBACV,SAAS,EAAE,KAAK;gBAChB,OAAO,EAAE,GAAG;aACb,CAAC;SACH;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AA1BD,sEA0BC","sourcesContent":["import { EVENT_ROUTE_CHANGE, globalObject } from '@grafana/faro-web-sdk';\n\nimport { api } from '../../dependencies';\nimport { NavigationType, ReactRouterLocation } from '../types';\n\nimport { isInitialized } from './routerDependencies';\nimport type { EventRouteTransitionAttributes, ReactRouterV6RouteObject } from './types';\nimport { getRouteFromLocation } from './utils';\n\ninterface RouterState {\n historyAction: NavigationType | any;\n location: ReactRouterLocation;\n}\n\ninterface Router {\n state: RouterState;\n routes: ReactRouterV6RouteObject[];\n subscribe(fn: (state: RouterState) => void): () => void;\n}\n\n/**\n * To use with React Router 6.4 data APIs.\n */\nexport function withFaroRouterInstrumentation<R extends Router = Router>(router: R) {\n let lastRoute: EventRouteTransitionAttributes = {};\n\n router.subscribe((state) => {\n const navigationType: NavigationType = state.historyAction;\n const location = state.location;\n const routes = router.routes;\n\n if (isInitialized && (navigationType === NavigationType.Push || navigationType === NavigationType.Pop)) {\n const route = getRouteFromLocation(routes, location);\n const url = globalObject.location?.href;\n\n api.pushEvent(EVENT_ROUTE_CHANGE, {\n toRoute: route,\n toUrl: globalObject.location?.href,\n ...lastRoute,\n });\n\n lastRoute = {\n fromRoute: route,\n fromUrl: url,\n };\n }\n });\n\n return router;\n}\n"]}
1
+ {"version":3,"file":"withFaroRouterInstrumentation.js","sourceRoot":"","sources":["../../../../src/router/v6/withFaroRouterInstrumentation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAAyE;AAEzE,mDAAyC;AACzC,kCAA+D;AAE/D,2DAAqD;AAErD,iCAA+C;AAa/C;;GAEG;AACH,SAAgB,6BAA6B,CAA4B,MAAS;IAChF,IAAI,SAAS,GAAmC,EAAE,CAAC;IAEnD,MAAM,CAAC,SAAS,CAAC,UAAC,KAAK;;QACrB,IAAM,cAAc,GAAmB,KAAK,CAAC,aAAa,CAAC;QAC3D,IAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,IAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAE7B,IAAI,kCAAa,IAAI,CAAC,cAAc,KAAK,sBAAc,CAAC,IAAI,IAAI,cAAc,KAAK,sBAAc,CAAC,GAAG,CAAC,EAAE;YACtG,IAAM,KAAK,GAAG,IAAA,4BAAoB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACrD,IAAM,GAAG,GAAG,MAAA,2BAAY,CAAC,QAAQ,0CAAE,IAAI,CAAC;YAExC,kBAAG,CAAC,SAAS,CAAC,iCAAkB,aAC9B,OAAO,EAAE,KAAK,EACd,KAAK,EAAE,MAAA,2BAAY,CAAC,QAAQ,0CAAE,IAAI,IAC/B,SAAS,EACZ,CAAC;YAEH,SAAS,GAAG;gBACV,SAAS,EAAE,KAAK;gBAChB,OAAO,EAAE,GAAG;aACb,CAAC;SACH;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AA1BD,sEA0BC","sourcesContent":["import { EVENT_ROUTE_CHANGE, globalObject } from '@grafana/faro-web-sdk';\n\nimport { api } from '../../dependencies';\nimport { NavigationType, ReactRouterLocation } from '../types';\n\nimport { isInitialized } from './routerDependencies';\nimport type { EventRouteTransitionAttributes, RouteObjectV6DataRouter } from './types';\nimport { getRouteFromLocation } from './utils';\n\ninterface RouterState {\n historyAction: NavigationType | any;\n location: ReactRouterLocation;\n}\n\ninterface Router {\n state: RouterState;\n routes: RouteObjectV6DataRouter[];\n subscribe(fn: (state: RouterState) => void): () => void;\n}\n\n/**\n * To use with React Router 6.4 data APIs.\n */\nexport function withFaroRouterInstrumentation<R extends Router = Router>(router: R) {\n let lastRoute: EventRouteTransitionAttributes = {};\n\n router.subscribe((state) => {\n const navigationType: NavigationType = state.historyAction;\n const location = state.location;\n const routes = router.routes;\n\n if (isInitialized && (navigationType === NavigationType.Push || navigationType === NavigationType.Pop)) {\n const route = getRouteFromLocation(routes, location);\n const url = globalObject.location?.href;\n\n api.pushEvent(EVENT_ROUTE_CHANGE, {\n toRoute: route,\n toUrl: globalObject.location?.href,\n ...lastRoute,\n });\n\n lastRoute = {\n fromRoute: route,\n fromUrl: url,\n };\n }\n });\n\n return router;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/router/v6/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ReactElement, ReactNode } from 'react';\n\nimport type { ReactRouterLocation } from '../types';\n\nexport interface ReactRouterV6BaseRouteObject {\n action?: (...args: any[]) => any;\n caseSensitive?: boolean;\n hasErrorBoundary?: boolean;\n handle?: any;\n id?: string;\n loader?: (...args: any[]) => any;\n path?: string;\n shouldRevalidate?: (...args: any[]) => any;\n}\n\nexport type ReactRouterV6RouteObject = ReactRouterV6BaseRouteObject &\n (\n | {\n children?: undefined;\n index: true;\n }\n | {\n children?: ReactRouterV6RouteObject[];\n index?: false;\n }\n );\n\nexport interface ReactRouterV6RoutesProps {\n children?: ReactNode;\n location?: Partial<ReactRouterLocation> | string;\n routesComponent?: ReactRouterV6RoutesShape;\n}\n\nexport type ReactRouterV6Params<Key extends string = string> = {\n readonly [key in Key]: string | undefined;\n};\n\nexport interface ReactRouterV6RouteMatch<ParamKey extends string = string> {\n params: ReactRouterV6Params<ParamKey>;\n pathname: string;\n pathnameBase: string;\n route: ReactRouterV6RouteObject;\n}\n\nexport type ReactRouterV6CreateRoutesFromChildren = (children: ReactNode) => ReactRouterV6RouteObject[];\n\nexport type ReactRouterV6MatchRoutes = (\n routes: ReactRouterV6RouteObject[],\n location: Partial<ReactRouterLocation> | string,\n basename?: string | undefined\n) => ReactRouterV6RouteMatch[] | null;\n\nexport type ReactRouterV6RoutesShape = (props: ReactRouterV6RoutesProps) => ReactElement | null;\n\nexport type ReactRouterV6UseLocation = () => ReactRouterLocation;\n\nexport type ReactRouterV6UseNavigationType = () => 'POP' | 'PUSH' | 'REPLACE';\n\nexport interface ReactRouterV6Dependencies {\n createRoutesFromChildren: ReactRouterV6CreateRoutesFromChildren;\n matchRoutes: ReactRouterV6MatchRoutes;\n Routes: ReactRouterV6RoutesShape;\n useLocation: ReactRouterV6UseLocation;\n useNavigationType: ReactRouterV6UseNavigationType;\n}\n\nexport interface ReactRouterV6DataRouterDependencies {\n matchRoutes: ReactRouterV6MatchRoutes;\n}\n\nexport type EventRouteTransitionAttributes = {\n fromRoute?: string;\n fromUrl?: string;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/router/v6/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ReactElement, ReactNode } from 'react';\n\nimport type { ReactRouterLocation } from '../types';\n\ninterface IndexRouteObjectV6DataRouter {\n caseSensitive?: boolean;\n children?: undefined;\n element?: React.ReactNode | null;\n index: true;\n path?: string;\n}\n\nexport interface NonIndexRouteObjectV6DataRouter {\n caseSensitive?: boolean;\n children?: RouteObjectV6DataRouter[];\n element?: React.ReactNode | null;\n index?: false;\n path?: string;\n}\n\nexport type RouteObjectV6DataRouter = IndexRouteObjectV6DataRouter | NonIndexRouteObjectV6DataRouter;\n\nexport interface ReactRouterV6BaseRouteObject {\n action?: (...args: any[]) => any;\n caseSensitive?: boolean;\n hasErrorBoundary?: boolean;\n handle?: any;\n id?: string;\n loader?: (...args: any[]) => any;\n path?: string;\n shouldRevalidate?: (...args: any[]) => any;\n}\n\nexport type ReactRouterV6RouteObject = ReactRouterV6BaseRouteObject &\n (\n | {\n children?: undefined;\n index: true;\n }\n | {\n children?: ReactRouterV6RouteObject[];\n index?: false;\n }\n );\n\nexport interface ReactRouterV6RoutesProps {\n children?: ReactNode;\n location?: Partial<ReactRouterLocation> | string;\n routesComponent?: ReactRouterV6RoutesShape;\n}\n\nexport type ReactRouterV6Params<Key extends string = string> = {\n readonly [key in Key]: string | undefined;\n};\n\nexport interface ReactRouterV6RouteMatch<ParamKey extends string = string> {\n params: ReactRouterV6Params<ParamKey>;\n pathname: string;\n pathnameBase: string;\n route: ReactRouterV6RouteObject;\n}\n\nexport type ReactRouterV6CreateRoutesFromChildren = (\n children: ReactNode\n) => ReactRouterV6RouteObject[] | RouteObjectV6DataRouter[];\n\nexport type ReactRouterV6MatchRoutes = (\n routes: ReactRouterV6RouteObject[],\n location: Partial<ReactRouterLocation> | string,\n basename?: string | undefined\n) => ReactRouterV6RouteMatch[] | null;\n\nexport type ReactRouterV6RoutesShape = (props: ReactRouterV6RoutesProps) => ReactElement | null;\n\nexport type ReactRouterV6UseLocation = () => ReactRouterLocation;\n\nexport type ReactRouterV6UseNavigationType = () => 'POP' | 'PUSH' | 'REPLACE';\n\nexport interface ReactRouterV6Dependencies {\n createRoutesFromChildren: ReactRouterV6CreateRoutesFromChildren;\n matchRoutes: ReactRouterV6MatchRoutes;\n Routes: ReactRouterV6RoutesShape;\n useLocation: ReactRouterV6UseLocation;\n useNavigationType: ReactRouterV6UseNavigationType;\n}\n\nexport interface ReactRouterV6DataRouterDependencies {\n matchRoutes: ReactRouterV6MatchRoutes;\n}\n\nexport type EventRouteTransitionAttributes = {\n fromRoute?: string;\n fromUrl?: string;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"withFaroRouterInstrumentation.js","sourceRoot":"","sources":["../../../../src/router/v6/withFaroRouterInstrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEzE,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,cAAc,EAAuB,MAAM,UAAU,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAa/C;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAA4B,MAAS;IAChF,IAAI,SAAS,GAAmC,EAAE,CAAC;IAEnD,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;;QACzB,MAAM,cAAc,GAAmB,KAAK,CAAC,aAAa,CAAC;QAC3D,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAE7B,IAAI,aAAa,IAAI,CAAC,cAAc,KAAK,cAAc,CAAC,IAAI,IAAI,cAAc,KAAK,cAAc,CAAC,GAAG,CAAC,EAAE;YACtG,MAAM,KAAK,GAAG,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACrD,MAAM,GAAG,GAAG,MAAA,YAAY,CAAC,QAAQ,0CAAE,IAAI,CAAC;YAExC,GAAG,CAAC,SAAS,CAAC,kBAAkB,kBAC9B,OAAO,EAAE,KAAK,EACd,KAAK,EAAE,MAAA,YAAY,CAAC,QAAQ,0CAAE,IAAI,IAC/B,SAAS,EACZ,CAAC;YAEH,SAAS,GAAG;gBACV,SAAS,EAAE,KAAK;gBAChB,OAAO,EAAE,GAAG;aACb,CAAC;SACH;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { EVENT_ROUTE_CHANGE, globalObject } from '@grafana/faro-web-sdk';\n\nimport { api } from '../../dependencies';\nimport { NavigationType, ReactRouterLocation } from '../types';\n\nimport { isInitialized } from './routerDependencies';\nimport type { EventRouteTransitionAttributes, ReactRouterV6RouteObject } from './types';\nimport { getRouteFromLocation } from './utils';\n\ninterface RouterState {\n historyAction: NavigationType | any;\n location: ReactRouterLocation;\n}\n\ninterface Router {\n state: RouterState;\n routes: ReactRouterV6RouteObject[];\n subscribe(fn: (state: RouterState) => void): () => void;\n}\n\n/**\n * To use with React Router 6.4 data APIs.\n */\nexport function withFaroRouterInstrumentation<R extends Router = Router>(router: R) {\n let lastRoute: EventRouteTransitionAttributes = {};\n\n router.subscribe((state) => {\n const navigationType: NavigationType = state.historyAction;\n const location = state.location;\n const routes = router.routes;\n\n if (isInitialized && (navigationType === NavigationType.Push || navigationType === NavigationType.Pop)) {\n const route = getRouteFromLocation(routes, location);\n const url = globalObject.location?.href;\n\n api.pushEvent(EVENT_ROUTE_CHANGE, {\n toRoute: route,\n toUrl: globalObject.location?.href,\n ...lastRoute,\n });\n\n lastRoute = {\n fromRoute: route,\n fromUrl: url,\n };\n }\n });\n\n return router;\n}\n"]}
1
+ {"version":3,"file":"withFaroRouterInstrumentation.js","sourceRoot":"","sources":["../../../../src/router/v6/withFaroRouterInstrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEzE,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,cAAc,EAAuB,MAAM,UAAU,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAa/C;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAA4B,MAAS;IAChF,IAAI,SAAS,GAAmC,EAAE,CAAC;IAEnD,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;;QACzB,MAAM,cAAc,GAAmB,KAAK,CAAC,aAAa,CAAC;QAC3D,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAE7B,IAAI,aAAa,IAAI,CAAC,cAAc,KAAK,cAAc,CAAC,IAAI,IAAI,cAAc,KAAK,cAAc,CAAC,GAAG,CAAC,EAAE;YACtG,MAAM,KAAK,GAAG,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACrD,MAAM,GAAG,GAAG,MAAA,YAAY,CAAC,QAAQ,0CAAE,IAAI,CAAC;YAExC,GAAG,CAAC,SAAS,CAAC,kBAAkB,kBAC9B,OAAO,EAAE,KAAK,EACd,KAAK,EAAE,MAAA,YAAY,CAAC,QAAQ,0CAAE,IAAI,IAC/B,SAAS,EACZ,CAAC;YAEH,SAAS,GAAG;gBACV,SAAS,EAAE,KAAK;gBAChB,OAAO,EAAE,GAAG;aACb,CAAC;SACH;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { EVENT_ROUTE_CHANGE, globalObject } from '@grafana/faro-web-sdk';\n\nimport { api } from '../../dependencies';\nimport { NavigationType, ReactRouterLocation } from '../types';\n\nimport { isInitialized } from './routerDependencies';\nimport type { EventRouteTransitionAttributes, RouteObjectV6DataRouter } from './types';\nimport { getRouteFromLocation } from './utils';\n\ninterface RouterState {\n historyAction: NavigationType | any;\n location: ReactRouterLocation;\n}\n\ninterface Router {\n state: RouterState;\n routes: RouteObjectV6DataRouter[];\n subscribe(fn: (state: RouterState) => void): () => void;\n}\n\n/**\n * To use with React Router 6.4 data APIs.\n */\nexport function withFaroRouterInstrumentation<R extends Router = Router>(router: R) {\n let lastRoute: EventRouteTransitionAttributes = {};\n\n router.subscribe((state) => {\n const navigationType: NavigationType = state.historyAction;\n const location = state.location;\n const routes = router.routes;\n\n if (isInitialized && (navigationType === NavigationType.Push || navigationType === NavigationType.Pop)) {\n const route = getRouteFromLocation(routes, location);\n const url = globalObject.location?.href;\n\n api.pushEvent(EVENT_ROUTE_CHANGE, {\n toRoute: route,\n toUrl: globalObject.location?.href,\n ...lastRoute,\n });\n\n lastRoute = {\n fromRoute: route,\n fromUrl: url,\n };\n }\n });\n\n return router;\n}\n"]}
@@ -1,5 +1,20 @@
1
1
  import type { ReactElement, ReactNode } from 'react';
2
2
  import type { ReactRouterLocation } from '../types';
3
+ interface IndexRouteObjectV6DataRouter {
4
+ caseSensitive?: boolean;
5
+ children?: undefined;
6
+ element?: React.ReactNode | null;
7
+ index: true;
8
+ path?: string;
9
+ }
10
+ export interface NonIndexRouteObjectV6DataRouter {
11
+ caseSensitive?: boolean;
12
+ children?: RouteObjectV6DataRouter[];
13
+ element?: React.ReactNode | null;
14
+ index?: false;
15
+ path?: string;
16
+ }
17
+ export type RouteObjectV6DataRouter = IndexRouteObjectV6DataRouter | NonIndexRouteObjectV6DataRouter;
3
18
  export interface ReactRouterV6BaseRouteObject {
4
19
  action?: (...args: any[]) => any;
5
20
  caseSensitive?: boolean;
@@ -31,7 +46,7 @@ export interface ReactRouterV6RouteMatch<ParamKey extends string = string> {
31
46
  pathnameBase: string;
32
47
  route: ReactRouterV6RouteObject;
33
48
  }
34
- export type ReactRouterV6CreateRoutesFromChildren = (children: ReactNode) => ReactRouterV6RouteObject[];
49
+ export type ReactRouterV6CreateRoutesFromChildren = (children: ReactNode) => ReactRouterV6RouteObject[] | RouteObjectV6DataRouter[];
35
50
  export type ReactRouterV6MatchRoutes = (routes: ReactRouterV6RouteObject[], location: Partial<ReactRouterLocation> | string, basename?: string | undefined) => ReactRouterV6RouteMatch[] | null;
36
51
  export type ReactRouterV6RoutesShape = (props: ReactRouterV6RoutesProps) => ReactElement | null;
37
52
  export type ReactRouterV6UseLocation = () => ReactRouterLocation;
@@ -50,3 +65,4 @@ export type EventRouteTransitionAttributes = {
50
65
  fromRoute?: string;
51
66
  fromUrl?: string;
52
67
  };
68
+ export {};
@@ -1,12 +1,12 @@
1
1
  import { NavigationType, ReactRouterLocation } from '../types';
2
- import type { ReactRouterV6RouteObject } from './types';
2
+ import type { RouteObjectV6DataRouter } from './types';
3
3
  interface RouterState {
4
4
  historyAction: NavigationType | any;
5
5
  location: ReactRouterLocation;
6
6
  }
7
7
  interface Router {
8
8
  state: RouterState;
9
- routes: ReactRouterV6RouteObject[];
9
+ routes: RouteObjectV6DataRouter[];
10
10
  subscribe(fn: (state: RouterState) => void): () => void;
11
11
  }
12
12
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/faro-react",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "Faro package that enables easier integration in projects built with React.",
5
5
  "keywords": [
6
6
  "observability",
@@ -52,8 +52,8 @@
52
52
  "quality:circular-deps": "madge --circular ."
53
53
  },
54
54
  "dependencies": {
55
- "@grafana/faro-web-sdk": "^1.7.0",
56
- "@grafana/faro-web-tracing": "^1.7.0",
55
+ "@grafana/faro-web-sdk": "^1.7.2",
56
+ "@grafana/faro-web-tracing": "^1.7.2",
57
57
  "hoist-non-react-statics": "^3.3.2"
58
58
  },
59
59
  "devDependencies": {
@@ -71,5 +71,5 @@
71
71
  "publishConfig": {
72
72
  "access": "public"
73
73
  },
74
- "gitHead": "b06dd9c3b974d3d9103f7a045d1e86207ba007d0"
74
+ "gitHead": "1561e10c2a8e46fd765589d7aaf38e68731edd23"
75
75
  }