@sentry/react 7.0.0-alpha.1 → 7.0.0-beta.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.
Files changed (92) hide show
  1. package/README.md +2 -3
  2. package/cjs/constants.js +12 -5
  3. package/cjs/constants.js.map +1 -1
  4. package/cjs/errorboundary.js +139 -112
  5. package/cjs/errorboundary.js.map +1 -1
  6. package/cjs/flags.js +7 -3
  7. package/cjs/flags.js.map +1 -1
  8. package/cjs/index.js +30 -21
  9. package/cjs/index.js.map +1 -1
  10. package/cjs/profiler.js +178 -147
  11. package/cjs/profiler.js.map +1 -1
  12. package/cjs/reactrouter.js +147 -100
  13. package/cjs/reactrouter.js.map +1 -1
  14. package/cjs/reactrouterv3.js +107 -83
  15. package/cjs/reactrouterv3.js.map +1 -1
  16. package/cjs/reactrouterv6.js +163 -0
  17. package/cjs/reactrouterv6.js.map +1 -0
  18. package/cjs/redux.js +51 -42
  19. package/cjs/redux.js.map +1 -1
  20. package/cjs/sdk.js +18 -15
  21. package/cjs/sdk.js.map +1 -1
  22. package/esm/constants.js +8 -4
  23. package/esm/constants.js.map +1 -1
  24. package/esm/errorboundary.js +124 -107
  25. package/esm/errorboundary.js.map +1 -1
  26. package/esm/flags.js +5 -2
  27. package/esm/flags.js.map +1 -1
  28. package/esm/index.js +8 -7
  29. package/esm/index.js.map +1 -1
  30. package/esm/profiler.js +161 -140
  31. package/esm/profiler.js.map +1 -1
  32. package/esm/reactrouter.js +133 -94
  33. package/esm/reactrouter.js.map +1 -1
  34. package/esm/reactrouterv3.js +103 -79
  35. package/esm/reactrouterv3.js.map +1 -1
  36. package/esm/reactrouterv6.js +153 -0
  37. package/esm/reactrouterv6.js.map +1 -0
  38. package/esm/redux.js +49 -41
  39. package/esm/redux.js.map +1 -1
  40. package/esm/sdk.js +17 -14
  41. package/esm/sdk.js.map +1 -1
  42. package/package.json +5 -5
  43. package/types/errorboundary.d.ts +1 -0
  44. package/types/errorboundary.d.ts.map +1 -1
  45. package/types/index.d.ts +1 -0
  46. package/types/index.d.ts.map +1 -1
  47. package/types/reactrouterv6.d.ts +27 -0
  48. package/types/reactrouterv6.d.ts.map +1 -0
  49. package/cjs/constants.d.ts +0 -4
  50. package/cjs/constants.d.ts.map +0 -1
  51. package/cjs/errorboundary.d.ts +0 -62
  52. package/cjs/errorboundary.d.ts.map +0 -1
  53. package/cjs/flags.d.ts +0 -3
  54. package/cjs/flags.d.ts.map +0 -1
  55. package/cjs/index.d.ts +0 -8
  56. package/cjs/index.d.ts.map +0 -1
  57. package/cjs/profiler.d.ts +0 -54
  58. package/cjs/profiler.d.ts.map +0 -1
  59. package/cjs/reactrouter.d.ts +0 -25
  60. package/cjs/reactrouter.d.ts.map +0 -1
  61. package/cjs/reactrouterv3.d.ts +0 -26
  62. package/cjs/reactrouterv3.d.ts.map +0 -1
  63. package/cjs/redux.d.ts +0 -33
  64. package/cjs/redux.d.ts.map +0 -1
  65. package/cjs/sdk.d.ts +0 -6
  66. package/cjs/sdk.d.ts.map +0 -1
  67. package/cjs/types.d.ts +0 -8
  68. package/cjs/types.d.ts.map +0 -1
  69. package/cjs/types.js +0 -2
  70. package/cjs/types.js.map +0 -1
  71. package/esm/constants.d.ts +0 -4
  72. package/esm/constants.d.ts.map +0 -1
  73. package/esm/errorboundary.d.ts +0 -62
  74. package/esm/errorboundary.d.ts.map +0 -1
  75. package/esm/flags.d.ts +0 -3
  76. package/esm/flags.d.ts.map +0 -1
  77. package/esm/index.d.ts +0 -8
  78. package/esm/index.d.ts.map +0 -1
  79. package/esm/profiler.d.ts +0 -54
  80. package/esm/profiler.d.ts.map +0 -1
  81. package/esm/reactrouter.d.ts +0 -25
  82. package/esm/reactrouter.d.ts.map +0 -1
  83. package/esm/reactrouterv3.d.ts +0 -26
  84. package/esm/reactrouterv3.d.ts.map +0 -1
  85. package/esm/redux.d.ts +0 -33
  86. package/esm/redux.d.ts.map +0 -1
  87. package/esm/sdk.d.ts +0 -6
  88. package/esm/sdk.d.ts.map +0 -1
  89. package/esm/types.d.ts +0 -8
  90. package/esm/types.d.ts.map +0 -1
  91. package/esm/types.js +0 -1
  92. package/esm/types.js.map +0 -1
@@ -1,115 +1,154 @@
1
- import { __assign } from "tslib";
2
1
  import { getGlobalObject } from '@sentry/utils';
3
2
  import hoistNonReactStatics from 'hoist-non-react-statics';
4
3
  import * as React from 'react';
5
- /* eslint-enable @typescript-eslint/no-explicit-any */
4
+
5
+ var _jsxFileName = "/home/runner/work/sentry-javascript/sentry-javascript/packages/react/src/reactrouter.tsx";
6
+
7
+ // We need to disable eslint no-explict-any because any is required for the
8
+ // react-router typings.
9
+
6
10
  var global = getGlobalObject();
7
- var activeTransaction;
8
- export function reactRouterV4Instrumentation(history, routes, matchPath) {
9
- return createReactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);
11
+
12
+ let activeTransaction;
13
+
14
+ function reactRouterV4Instrumentation(
15
+ history,
16
+ routes,
17
+ matchPath,
18
+ ) {
19
+ return createReactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);
10
20
  }
11
- export function reactRouterV5Instrumentation(history, routes, matchPath) {
12
- return createReactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);
21
+
22
+ function reactRouterV5Instrumentation(
23
+ history,
24
+ routes,
25
+ matchPath,
26
+ ) {
27
+ return createReactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);
13
28
  }
14
- function createReactRouterInstrumentation(history, name, allRoutes, matchPath) {
15
- if (allRoutes === void 0) { allRoutes = []; }
16
- function getInitPathName() {
17
- if (history && history.location) {
18
- return history.location.pathname;
19
- }
20
- if (global && global.location) {
21
- return global.location.pathname;
22
- }
23
- return undefined;
29
+
30
+ function createReactRouterInstrumentation(
31
+ history,
32
+ name,
33
+ allRoutes = [],
34
+ matchPath,
35
+ ) {
36
+ function getInitPathName() {
37
+ if (history && history.location) {
38
+ return history.location.pathname;
24
39
  }
25
- function getTransactionName(pathname) {
26
- if (allRoutes.length === 0 || !matchPath) {
27
- return pathname;
28
- }
29
- var branches = matchRoutes(allRoutes, pathname, matchPath);
30
- // eslint-disable-next-line @typescript-eslint/prefer-for-of
31
- for (var x = 0; x < branches.length; x++) {
32
- if (branches[x].match.isExact) {
33
- return branches[x].match.path;
34
- }
35
- }
36
- return pathname;
40
+
41
+ if (global && global.location) {
42
+ return global.location.pathname;
37
43
  }
38
- return function (customStartTransaction, startTransactionOnPageLoad, startTransactionOnLocationChange) {
39
- if (startTransactionOnPageLoad === void 0) { startTransactionOnPageLoad = true; }
40
- if (startTransactionOnLocationChange === void 0) { startTransactionOnLocationChange = true; }
41
- var initPathName = getInitPathName();
42
- if (startTransactionOnPageLoad && initPathName) {
43
- activeTransaction = customStartTransaction({
44
- name: getTransactionName(initPathName),
45
- op: 'pageload',
46
- tags: {
47
- 'routing.instrumentation': name,
48
- },
49
- });
50
- }
51
- if (startTransactionOnLocationChange && history.listen) {
52
- history.listen(function (location, action) {
53
- if (action && (action === 'PUSH' || action === 'POP')) {
54
- if (activeTransaction) {
55
- activeTransaction.finish();
56
- }
57
- var tags = {
58
- 'routing.instrumentation': name,
59
- };
60
- activeTransaction = customStartTransaction({
61
- name: getTransactionName(location.pathname),
62
- op: 'navigation',
63
- tags: tags,
64
- });
65
- }
66
- });
44
+
45
+ return undefined;
46
+ }
47
+
48
+ function getTransactionName(pathname) {
49
+ if (allRoutes.length === 0 || !matchPath) {
50
+ return pathname;
51
+ }
52
+
53
+ var branches = matchRoutes(allRoutes, pathname, matchPath);
54
+ for (let x = 0; x < branches.length; x++) {
55
+ if (branches[x].match.isExact) {
56
+ return branches[x].match.path;
57
+ }
58
+ }
59
+
60
+ return pathname;
61
+ }
62
+
63
+ return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true) => {
64
+ var initPathName = getInitPathName();
65
+ if (startTransactionOnPageLoad && initPathName) {
66
+ activeTransaction = customStartTransaction({
67
+ name: getTransactionName(initPathName),
68
+ op: 'pageload',
69
+ tags: {
70
+ 'routing.instrumentation': name,
71
+ },
72
+ });
73
+ }
74
+
75
+ if (startTransactionOnLocationChange && history.listen) {
76
+ history.listen((location, action) => {
77
+ if (action && (action === 'PUSH' || action === 'POP')) {
78
+ if (activeTransaction) {
79
+ activeTransaction.finish();
80
+ }
81
+ var tags = {
82
+ 'routing.instrumentation': name,
83
+ };
84
+
85
+ activeTransaction = customStartTransaction({
86
+ name: getTransactionName(location.pathname),
87
+ op: 'navigation',
88
+ tags,
89
+ });
67
90
  }
68
- };
91
+ });
92
+ }
93
+ };
69
94
  }
95
+
70
96
  /**
71
97
  * Matches a set of routes to a pathname
72
98
  * Based on implementation from
73
99
  */
74
- function matchRoutes(routes, pathname, matchPath, branch) {
75
- if (branch === void 0) { branch = []; }
76
- routes.some(function (route) {
77
- var match = route.path
78
- ? matchPath(pathname, route)
79
- : branch.length
80
- ? branch[branch.length - 1].match // use parent match
81
- : computeRootMatch(pathname); // use default "root" match
82
- if (match) {
83
- branch.push({ route: route, match: match });
84
- if (route.routes) {
85
- matchRoutes(route.routes, pathname, matchPath, branch);
86
- }
87
- }
88
- return !!match;
89
- });
90
- return branch;
100
+ function matchRoutes(
101
+ routes,
102
+ pathname,
103
+ matchPath,
104
+ branch = [],
105
+ ) {
106
+ routes.some(route => {
107
+ var match = route.path
108
+ ? matchPath(pathname, route)
109
+ : branch.length
110
+ ? branch[branch.length - 1].match // use parent match
111
+ : computeRootMatch(pathname); // use default "root" match
112
+
113
+ if (match) {
114
+ branch.push({ route, match });
115
+
116
+ if (route.routes) {
117
+ matchRoutes(route.routes, pathname, matchPath, branch);
118
+ }
119
+ }
120
+
121
+ return !!match;
122
+ });
123
+
124
+ return branch;
91
125
  }
126
+
92
127
  function computeRootMatch(pathname) {
93
- return { path: '/', url: '/', params: {}, isExact: pathname === '/' };
128
+ return { path: '/', url: '/', params: {}, isExact: pathname === '/' };
94
129
  }
95
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
96
- export function withSentryRouting(Route) {
97
- var componentDisplayName = Route.displayName || Route.name;
98
- var WrappedRoute = function (props) {
99
- if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {
100
- activeTransaction.setName(props.computedMatch.path);
101
- }
102
- // @ts-ignore Setting more specific React Component typing for `R` generic above
103
- // will break advanced type inference done by react router params:
104
- // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
105
- return React.createElement(Route, __assign({}, props));
106
- };
107
- WrappedRoute.displayName = "sentryRoute(" + componentDisplayName + ")";
108
- hoistNonReactStatics(WrappedRoute, Route);
130
+
131
+ function withSentryRouting(Route) {
132
+ var componentDisplayName = (Route ).displayName || (Route ).name;
133
+
134
+ var WrappedRoute = (props) => {
135
+ if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {
136
+ activeTransaction.setName(props.computedMatch.path);
137
+ }
138
+
109
139
  // @ts-ignore Setting more specific React Component typing for `R` generic above
110
140
  // will break advanced type inference done by react router params:
111
141
  // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
112
- return WrappedRoute;
142
+ return React.createElement(Route, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 163}} );
143
+ };
144
+
145
+ WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;
146
+ hoistNonReactStatics(WrappedRoute, Route);
147
+ // @ts-ignore Setting more specific React Component typing for `R` generic above
148
+ // will break advanced type inference done by react router params:
149
+ // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
150
+ return WrappedRoute;
113
151
  }
114
- /* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
115
- //# sourceMappingURL=reactrouter.js.map
152
+
153
+ export { reactRouterV4Instrumentation, reactRouterV5Instrumentation, withSentryRouting };
154
+ //# sourceMappingURL=reactrouter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reactrouter.js","sourceRoot":"","sources":["../../src/reactrouter.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAuB/B,sDAAsD;AAEtD,IAAM,MAAM,GAAG,eAAe,EAAU,CAAC;AAEzC,IAAI,iBAA0C,CAAC;AAE/C,MAAM,UAAU,4BAA4B,CAC1C,OAAsB,EACtB,MAAsB,EACtB,SAAqB;IAErB,OAAO,gCAAgC,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AACzF,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC1C,OAAsB,EACtB,MAAsB,EACtB,SAAqB;IAErB,OAAO,gCAAgC,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AACzF,CAAC;AAED,SAAS,gCAAgC,CACvC,OAAsB,EACtB,IAAY,EACZ,SAA6B,EAC7B,SAAqB;IADrB,0BAAA,EAAA,cAA6B;IAG7B,SAAS,eAAe;QACtB,IAAI,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE;YAC/B,OAAO,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;SAClC;QAED,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,EAAE;YAC7B,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;SACjC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,SAAS,kBAAkB,CAAC,QAAgB;QAC1C,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE;YACxC,OAAO,QAAQ,CAAC;SACjB;QAED,IAAM,QAAQ,GAAG,WAAW,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,CA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AAE;YACpF,iBAAiB,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;SACrD;QAED,gFAAgF;QAChF,kEAAkE;QAClE,2IAA2I;QAC3I,OAAO,oBAAC,KAAK,eAAK,KAAK,EAAI,CAAC;IAC9B,CAAC,CAAC;IAEF,YAAY,CAAC,WAAW,GAAG,iBAAe,oBAAoB,MAAG,CAAC;IAClE,oBAAoB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IAC1C,gFAAgF;IAChF,kEAAkE;IAClE,2IAA2I;IAC3I,OAAO,YAAY,CAAC;AACtB,CAAC;AACD,kGAAkG","sourcesContent":["import { Transaction } from '@sentry/types';\nimport { getGlobalObject } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { Action, Location, ReactRouterInstrumentation } from './types';\n\n// We need to disable eslint no-explict-any because any is required for the\n// react-router typings.\n/* eslint-disable @typescript-eslint/no-explicit-any */\ntype Match = { path: string; url: string; params: Record<string, any>; isExact: boolean };\n\nexport type RouterHistory = {\n location?: Location;\n listen?(cb: (location: Location, action: Action) => void): void;\n} & Record<string, any>;\n\nexport type RouteConfig = {\n [propName: string]: any;\n path?: string | string[];\n exact?: boolean;\n component?: JSX.Element;\n routes?: RouteConfig[];\n};\n\ntype MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null;\n/* eslint-enable @typescript-eslint/no-explicit-any */\n\nconst global = getGlobalObject<Window>();\n\nlet activeTransaction: Transaction | undefined;\n\nexport function reactRouterV4Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);\n}\n\nexport function reactRouterV5Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);\n}\n\nfunction createReactRouterInstrumentation(\n history: RouterHistory,\n name: string,\n allRoutes: RouteConfig[] = [],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n function getInitPathName(): string | undefined {\n if (history && history.location) {\n return history.location.pathname;\n }\n\n if (global && global.location) {\n return global.location.pathname;\n }\n\n return undefined;\n }\n\n function getTransactionName(pathname: string): string {\n if (allRoutes.length === 0 || !matchPath) {\n return pathname;\n }\n\n const branches = matchRoutes(allRoutes, pathname, matchPath);\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let x = 0; x < branches.length; x++) {\n if (branches[x].match.isExact) {\n return branches[x].match.path;\n }\n }\n\n return pathname;\n }\n\n return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true): void => {\n const initPathName = getInitPathName();\n if (startTransactionOnPageLoad && initPathName) {\n activeTransaction = customStartTransaction({\n name: getTransactionName(initPathName),\n op: 'pageload',\n tags: {\n 'routing.instrumentation': name,\n },\n });\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen((location, action) => {\n if (action && (action === 'PUSH' || action === 'POP')) {\n if (activeTransaction) {\n activeTransaction.finish();\n }\n const tags = {\n 'routing.instrumentation': name,\n };\n\n activeTransaction = customStartTransaction({\n name: getTransactionName(location.pathname),\n op: 'navigation',\n tags,\n });\n }\n });\n }\n };\n}\n\n/**\n * Matches a set of routes to a pathname\n * Based on implementation from\n */\nfunction matchRoutes(\n routes: RouteConfig[],\n pathname: string,\n matchPath: MatchPath,\n branch: Array<{ route: RouteConfig; match: Match }> = [],\n): Array<{ route: RouteConfig; match: Match }> {\n routes.some(route => {\n const match = route.path\n ? matchPath(pathname, route)\n : branch.length\n ? branch[branch.length - 1].match // use parent match\n : computeRootMatch(pathname); // use default \"root\" match\n\n if (match) {\n branch.push({ route, match });\n\n if (route.routes) {\n matchRoutes(route.routes, pathname, matchPath, branch);\n }\n }\n\n return !!match;\n });\n\n return branch;\n}\n\nfunction computeRootMatch(pathname: string): Match {\n return { path: '/', url: '/', params: {}, isExact: pathname === '/' };\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\nexport function withSentryRouting<P extends Record<string, any>, R extends React.ComponentType<P>>(Route: R): R {\n const componentDisplayName = (Route as any).displayName || (Route as any).name;\n\n const WrappedRoute: React.FC<P> = (props: P) => {\n if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {\n activeTransaction.setName(props.computedMatch.path);\n }\n\n // @ts-ignore Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return <Route {...props} />;\n };\n\n WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;\n hoistNonReactStatics(WrappedRoute, Route);\n // @ts-ignore Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return WrappedRoute;\n}\n/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\n"]}
1
+ {"version":3,"file":"reactrouter.js","sources":["../../src/reactrouter.tsx"],"sourcesContent":["import { Transaction } from '@sentry/types';\nimport { getGlobalObject } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { Action, Location, ReactRouterInstrumentation } from './types';\n\n// We need to disable eslint no-explict-any because any is required for the\n// react-router typings.\n/* eslint-disable @typescript-eslint/no-explicit-any */\ntype Match = { path: string; url: string; params: Record<string, any>; isExact: boolean };\n\nexport type RouterHistory = {\n location?: Location;\n listen?(cb: (location: Location, action: Action) => void): void;\n} & Record<string, any>;\n\nexport type RouteConfig = {\n [propName: string]: any;\n path?: string | string[];\n exact?: boolean;\n component?: JSX.Element;\n routes?: RouteConfig[];\n};\n\ntype MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null;\n/* eslint-enable @typescript-eslint/no-explicit-any */\n\nconst global = getGlobalObject<Window>();\n\nlet activeTransaction: Transaction | undefined;\n\nexport function reactRouterV4Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);\n}\n\nexport function reactRouterV5Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);\n}\n\nfunction createReactRouterInstrumentation(\n history: RouterHistory,\n name: string,\n allRoutes: RouteConfig[] = [],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n function getInitPathName(): string | undefined {\n if (history && history.location) {\n return history.location.pathname;\n }\n\n if (global && global.location) {\n return global.location.pathname;\n }\n\n return undefined;\n }\n\n function getTransactionName(pathname: string): string {\n if (allRoutes.length === 0 || !matchPath) {\n return pathname;\n }\n\n const branches = matchRoutes(allRoutes, pathname, matchPath);\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let x = 0; x < branches.length; x++) {\n if (branches[x].match.isExact) {\n return branches[x].match.path;\n }\n }\n\n return pathname;\n }\n\n return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true): void => {\n const initPathName = getInitPathName();\n if (startTransactionOnPageLoad && initPathName) {\n activeTransaction = customStartTransaction({\n name: getTransactionName(initPathName),\n op: 'pageload',\n tags: {\n 'routing.instrumentation': name,\n },\n });\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen((location, action) => {\n if (action && (action === 'PUSH' || action === 'POP')) {\n if (activeTransaction) {\n activeTransaction.finish();\n }\n const tags = {\n 'routing.instrumentation': name,\n };\n\n activeTransaction = customStartTransaction({\n name: getTransactionName(location.pathname),\n op: 'navigation',\n tags,\n });\n }\n });\n }\n };\n}\n\n/**\n * Matches a set of routes to a pathname\n * Based on implementation from\n */\nfunction matchRoutes(\n routes: RouteConfig[],\n pathname: string,\n matchPath: MatchPath,\n branch: Array<{ route: RouteConfig; match: Match }> = [],\n): Array<{ route: RouteConfig; match: Match }> {\n routes.some(route => {\n const match = route.path\n ? matchPath(pathname, route)\n : branch.length\n ? branch[branch.length - 1].match // use parent match\n : computeRootMatch(pathname); // use default \"root\" match\n\n if (match) {\n branch.push({ route, match });\n\n if (route.routes) {\n matchRoutes(route.routes, pathname, matchPath, branch);\n }\n }\n\n return !!match;\n });\n\n return branch;\n}\n\nfunction computeRootMatch(pathname: string): Match {\n return { path: '/', url: '/', params: {}, isExact: pathname === '/' };\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\nexport function withSentryRouting<P extends Record<string, any>, R extends React.ComponentType<P>>(Route: R): R {\n const componentDisplayName = (Route as any).displayName || (Route as any).name;\n\n const WrappedRoute: React.FC<P> = (props: P) => {\n if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {\n activeTransaction.setName(props.computedMatch.path);\n }\n\n // @ts-ignore Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return <Route {...props} />;\n };\n\n WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;\n hoistNonReactStatics(WrappedRoute, Route);\n // @ts-ignore Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return WrappedRoute;\n}\n/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\n"],"names":[],"mappings":";;;;AAAA;;AAOA;AACA;;AAoBA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;"}
@@ -1,5 +1,10 @@
1
1
  import { getGlobalObject } from '@sentry/utils';
2
+
3
+ // Many of the types below had to be mocked out to prevent typescript issues
4
+ // these types are required for correct functionality.
5
+
2
6
  var global = getGlobalObject();
7
+
3
8
  /**
4
9
  * Creates routing instrumentation for React Router v3
5
10
  * Works for React Router >= 3.2.0 and < 4.0.0
@@ -8,96 +13,115 @@ var global = getGlobalObject();
8
13
  * @param routes a list of all routes, should be
9
14
  * @param match `Router.match` utility
10
15
  */
11
- export function reactRouterV3Instrumentation(history, routes, match) {
12
- return function (startTransaction, startTransactionOnPageLoad, startTransactionOnLocationChange) {
13
- if (startTransactionOnPageLoad === void 0) { startTransactionOnPageLoad = true; }
14
- if (startTransactionOnLocationChange === void 0) { startTransactionOnLocationChange = true; }
15
- var activeTransaction;
16
- var prevName;
17
- // Have to use global.location because history.location might not be defined.
18
- if (startTransactionOnPageLoad && global && global.location) {
19
- normalizeTransactionName(routes, global.location, match, function (localName) {
20
- prevName = localName;
21
- activeTransaction = startTransaction({
22
- name: prevName,
23
- op: 'pageload',
24
- tags: {
25
- 'routing.instrumentation': 'react-router-v3',
26
- },
27
- });
28
- });
29
- }
30
- if (startTransactionOnLocationChange && history.listen) {
31
- history.listen(function (location) {
32
- if (location.action === 'PUSH' || location.action === 'POP') {
33
- if (activeTransaction) {
34
- activeTransaction.finish();
35
- }
36
- var tags_1 = {
37
- 'routing.instrumentation': 'react-router-v3',
38
- };
39
- if (prevName) {
40
- tags_1.from = prevName;
41
- }
42
- normalizeTransactionName(routes, location, match, function (localName) {
43
- prevName = localName;
44
- activeTransaction = startTransaction({
45
- name: prevName,
46
- op: 'navigation',
47
- tags: tags_1,
48
- });
49
- });
50
- }
16
+ function reactRouterV3Instrumentation(
17
+ history,
18
+ routes,
19
+ match,
20
+ ) {
21
+ return (
22
+ startTransaction,
23
+ startTransactionOnPageLoad = true,
24
+ startTransactionOnLocationChange = true,
25
+ ) => {
26
+ let activeTransaction;
27
+ let prevName;
28
+
29
+ // Have to use global.location because history.location might not be defined.
30
+ if (startTransactionOnPageLoad && global && global.location) {
31
+ normalizeTransactionName(routes, global.location , match, (localName) => {
32
+ prevName = localName;
33
+ activeTransaction = startTransaction({
34
+ name: prevName,
35
+ op: 'pageload',
36
+ tags: {
37
+ 'routing.instrumentation': 'react-router-v3',
38
+ },
39
+ });
40
+ });
41
+ }
42
+
43
+ if (startTransactionOnLocationChange && history.listen) {
44
+ history.listen(location => {
45
+ if (location.action === 'PUSH' || location.action === 'POP') {
46
+ if (activeTransaction) {
47
+ activeTransaction.finish();
48
+ }
49
+ var tags = {
50
+ 'routing.instrumentation': 'react-router-v3',
51
+ };
52
+ if (prevName) {
53
+ tags.from = prevName;
54
+ }
55
+ normalizeTransactionName(routes, location, match, (localName) => {
56
+ prevName = localName;
57
+ activeTransaction = startTransaction({
58
+ name: prevName,
59
+ op: 'navigation',
60
+ tags,
51
61
  });
62
+ });
52
63
  }
53
- };
64
+ });
65
+ }
66
+ };
54
67
  }
68
+
55
69
  /**
56
70
  * Normalize transaction names using `Router.match`
57
71
  */
58
- function normalizeTransactionName(appRoutes, location, match, callback) {
59
- var name = location.pathname;
60
- match({
61
- location: location,
62
- routes: appRoutes,
63
- }, function (error, _redirectLocation, renderProps) {
64
- if (error || !renderProps) {
65
- return callback(name);
66
- }
67
- var routePath = getRouteStringFromRoutes(renderProps.routes || []);
68
- if (routePath.length === 0 || routePath === '/*') {
69
- return callback(name);
70
- }
71
- name = routePath;
72
+ function normalizeTransactionName(
73
+ appRoutes,
74
+ location,
75
+ match,
76
+ callback,
77
+ ) {
78
+ let name = location.pathname;
79
+ match(
80
+ {
81
+ location,
82
+ routes: appRoutes,
83
+ },
84
+ (error, _redirectLocation, renderProps) => {
85
+ if (error || !renderProps) {
86
+ return callback(name);
87
+ }
88
+
89
+ var routePath = getRouteStringFromRoutes(renderProps.routes || []);
90
+ if (routePath.length === 0 || routePath === '/*') {
72
91
  return callback(name);
73
- });
92
+ }
93
+
94
+ name = routePath;
95
+ return callback(name);
96
+ },
97
+ );
74
98
  }
99
+
75
100
  /**
76
101
  * Generate route name from array of routes
77
102
  */
78
103
  function getRouteStringFromRoutes(routes) {
79
- if (!Array.isArray(routes) || routes.length === 0) {
80
- return '';
81
- }
82
- var routesWithPaths = routes.filter(function (route) { return !!route.path; });
83
- var index = -1;
84
- for (var x = routesWithPaths.length - 1; x >= 0; x--) {
85
- var route = routesWithPaths[x];
86
- if (route.path && route.path.startsWith('/')) {
87
- index = x;
88
- break;
89
- }
104
+ if (!Array.isArray(routes) || routes.length === 0) {
105
+ return '';
106
+ }
107
+
108
+ var routesWithPaths = routes.filter((route) => !!route.path);
109
+
110
+ let index = -1;
111
+ for (let x = routesWithPaths.length - 1; x >= 0; x--) {
112
+ var route = routesWithPaths[x];
113
+ if (route.path && route.path.startsWith('/')) {
114
+ index = x;
115
+ break;
90
116
  }
91
- return routesWithPaths
92
- .slice(index)
93
- .filter(function (_a) {
94
- var path = _a.path;
95
- return !!path;
96
- })
97
- .map(function (_a) {
98
- var path = _a.path;
99
- return path;
100
- })
101
- .join('');
117
+ }
118
+
119
+ return routesWithPaths
120
+ .slice(index)
121
+ .filter(({ path }) => !!path)
122
+ .map(({ path }) => path)
123
+ .join('');
102
124
  }
103
- //# sourceMappingURL=reactrouterv3.js.map
125
+
126
+ export { reactRouterV3Instrumentation };
127
+ //# sourceMappingURL=reactrouterv3.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reactrouterv3.js","sourceRoot":"","sources":["../../src/reactrouterv3.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAoBhD,IAAM,MAAM,GAAG,eAAe,EAAU,CAAC;AAEzC;;;;;;;GAOG;AACH,MAAM,UAAU,4BAA4B,CAC1C,OAAkB,EAClB,MAAe,EACf,KAAY;IAEZ,OAAO,UACL,gBAA0E,EAC1E,0BAA0C,EAC1C,gCAAgD;QADhD,2CAAA,EAAA,iCAA0C;QAC1C,iDAAA,EAAA,uCAAgD;QAEhD,IAAI,iBAA0C,CAAC;QAC/C,IAAI,QAA4B,CAAC;QAEjC,6EAA6E;QAC7E,IAAI,0BAA0B,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,EAAE;YAC3D,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,QAA+B,EAAE,KAAK,EAAE,UAAC,SAAiB;gBAChG,QAAQ,GAAG,SAAS,CAAC;gBACrB,iBAAiB,GAAG,gBAAgB,CAAC;oBACnC,IAAI,EAAE,QAAQ;oBACd,EAAE,EAAE,UAAU;oBACd,IAAI,EAAE;wBACJ,yBAAyB,EAAE,iBAAiB;qBAC7C;iBACF,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;SACJ;QAED,IAAI,gCAAgC,IAAI,OAAO,CAAC,MAAM,EAAE;YACtD,OAAO,CAAC,MAAM,CAAC,UAAA,QAAQ;gBACrB,IAAI,QAAQ,CAAC,MAAM,KAAK,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;AAED;;GAEG;AACH,SAAS,wBAAwB,CAAC,MAAe;IAC/C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACjD,OAAO,EAAE,CAAC;KACX;IAED,IAAM,eAAe,GAAY,MAAM,CAAC,MAAM,CAAC,UAAC,KAAY,IAAK,OAAA,CAAC,CAAC,KAAK,CAAC,IAAI,EAAZ,CAAY,CAAC,CAAC;IAE/E,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;QACpD,IAAM,KAAK,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YAC5C,KAAK,GAAG,CAAC,CAAC;YACV,MAAM;SACP;KACF;IAED,OAAO,eAAe;SACnB,KAAK,CAAC,KAAK,CAAC;SACZ,MAAM,CAAC,UAAC,EAAQ;YAAN,cAAI;QAAO,OAAA,CAAC,CAAC,IAAI;IAAN,CAAM,CAAC;SAC5B,GAAG,CAAC,UAAC,EAAQ;YAAN,cAAI;QAAO,OAAA,IAAI;IAAJ,CAAI,CAAC;SACvB,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC","sourcesContent":["import { Primitive, Transaction, TransactionContext } from '@sentry/types';\nimport { getGlobalObject } from '@sentry/utils';\n\nimport { Location, ReactRouterInstrumentation } from './types';\n\n// Many of the types below had to be mocked out to prevent typescript issues\n// these types are required for correct functionality.\n\ntype HistoryV3 = {\n location?: Location;\n listen?(cb: (location: Location) => void): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n} & Record<string, any>;\n\nexport type Route = { path?: string; childRoutes?: Route[] };\n\nexport type Match = (\n props: { location: Location; routes: Route[] },\n cb: (error?: Error, _redirectLocation?: Location, renderProps?: { routes?: Route[] }) => void,\n) => void;\n\nconst global = getGlobalObject<Window>();\n\n/**\n * Creates routing instrumentation for React Router v3\n * Works for React Router >= 3.2.0 and < 4.0.0\n *\n * @param history object from the `history` library\n * @param routes a list of all routes, should be\n * @param match `Router.match` utility\n */\nexport function reactRouterV3Instrumentation(\n history: HistoryV3,\n routes: Route[],\n match: Match,\n): ReactRouterInstrumentation {\n return (\n startTransaction: (context: TransactionContext) => Transaction | undefined,\n startTransactionOnPageLoad: boolean = true,\n startTransactionOnLocationChange: boolean = true,\n ) => {\n let activeTransaction: Transaction | undefined;\n let prevName: string | undefined;\n\n // Have to use global.location because history.location might not be defined.\n if (startTransactionOnPageLoad && global && global.location) {\n normalizeTransactionName(routes, global.location as unknown as Location, match, (localName: string) => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'pageload',\n tags: {\n 'routing.instrumentation': 'react-router-v3',\n },\n });\n });\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen(location => {\n if (location.action === 'PUSH' || location.action === 'POP') {\n if (activeTransaction) {\n activeTransaction.finish();\n }\n const tags: Record<string, Primitive> = {\n 'routing.instrumentation': 'react-router-v3',\n };\n if (prevName) {\n tags.from = prevName;\n }\n normalizeTransactionName(routes, location, match, (localName: string) => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'navigation',\n tags,\n });\n });\n }\n });\n }\n };\n}\n\n/**\n * Normalize transaction names using `Router.match`\n */\nfunction normalizeTransactionName(\n appRoutes: Route[],\n location: Location,\n match: Match,\n callback: (pathname: string) => void,\n): void {\n let name = location.pathname;\n match(\n {\n location,\n routes: appRoutes,\n },\n (error, _redirectLocation, renderProps) => {\n if (error || !renderProps) {\n return callback(name);\n }\n\n const routePath = getRouteStringFromRoutes(renderProps.routes || []);\n if (routePath.length === 0 || routePath === '/*') {\n return callback(name);\n }\n\n name = routePath;\n return callback(name);\n },\n );\n}\n\n/**\n * Generate route name from array of routes\n */\nfunction getRouteStringFromRoutes(routes: Route[]): string {\n if (!Array.isArray(routes) || routes.length === 0) {\n return '';\n }\n\n const routesWithPaths: Route[] = routes.filter((route: Route) => !!route.path);\n\n let index = -1;\n for (let x = routesWithPaths.length - 1; x >= 0; x--) {\n const route = routesWithPaths[x];\n if (route.path && route.path.startsWith('/')) {\n index = x;\n break;\n }\n }\n\n return routesWithPaths\n .slice(index)\n .filter(({ path }) => !!path)\n .map(({ path }) => path)\n .join('');\n}\n"]}
1
+ {"version":3,"file":"reactrouterv3.js","sources":["../../src/reactrouterv3.ts"],"sourcesContent":["import { Primitive, Transaction, TransactionContext } from '@sentry/types';\nimport { getGlobalObject } from '@sentry/utils';\n\nimport { Location, ReactRouterInstrumentation } from './types';\n\n// Many of the types below had to be mocked out to prevent typescript issues\n// these types are required for correct functionality.\n\ntype HistoryV3 = {\n location?: Location;\n listen?(cb: (location: Location) => void): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n} & Record<string, any>;\n\nexport type Route = { path?: string; childRoutes?: Route[] };\n\nexport type Match = (\n props: { location: Location; routes: Route[] },\n cb: (error?: Error, _redirectLocation?: Location, renderProps?: { routes?: Route[] }) => void,\n) => void;\n\nconst global = getGlobalObject<Window>();\n\n/**\n * Creates routing instrumentation for React Router v3\n * Works for React Router >= 3.2.0 and < 4.0.0\n *\n * @param history object from the `history` library\n * @param routes a list of all routes, should be\n * @param match `Router.match` utility\n */\nexport function reactRouterV3Instrumentation(\n history: HistoryV3,\n routes: Route[],\n match: Match,\n): ReactRouterInstrumentation {\n return (\n startTransaction: (context: TransactionContext) => Transaction | undefined,\n startTransactionOnPageLoad: boolean = true,\n startTransactionOnLocationChange: boolean = true,\n ) => {\n let activeTransaction: Transaction | undefined;\n let prevName: string | undefined;\n\n // Have to use global.location because history.location might not be defined.\n if (startTransactionOnPageLoad && global && global.location) {\n normalizeTransactionName(routes, global.location as unknown as Location, match, (localName: string) => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'pageload',\n tags: {\n 'routing.instrumentation': 'react-router-v3',\n },\n });\n });\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen(location => {\n if (location.action === 'PUSH' || location.action === 'POP') {\n if (activeTransaction) {\n activeTransaction.finish();\n }\n const tags: Record<string, Primitive> = {\n 'routing.instrumentation': 'react-router-v3',\n };\n if (prevName) {\n tags.from = prevName;\n }\n normalizeTransactionName(routes, location, match, (localName: string) => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'navigation',\n tags,\n });\n });\n }\n });\n }\n };\n}\n\n/**\n * Normalize transaction names using `Router.match`\n */\nfunction normalizeTransactionName(\n appRoutes: Route[],\n location: Location,\n match: Match,\n callback: (pathname: string) => void,\n): void {\n let name = location.pathname;\n match(\n {\n location,\n routes: appRoutes,\n },\n (error, _redirectLocation, renderProps) => {\n if (error || !renderProps) {\n return callback(name);\n }\n\n const routePath = getRouteStringFromRoutes(renderProps.routes || []);\n if (routePath.length === 0 || routePath === '/*') {\n return callback(name);\n }\n\n name = routePath;\n return callback(name);\n },\n );\n}\n\n/**\n * Generate route name from array of routes\n */\nfunction getRouteStringFromRoutes(routes: Route[]): string {\n if (!Array.isArray(routes) || routes.length === 0) {\n return '';\n }\n\n const routesWithPaths: Route[] = routes.filter((route: Route) => !!route.path);\n\n let index = -1;\n for (let x = routesWithPaths.length - 1; x >= 0; x--) {\n const route = routesWithPaths[x];\n if (route.path && route.path.startsWith('/')) {\n index = x;\n break;\n }\n }\n\n return routesWithPaths\n .slice(index)\n .filter(({ path }) => !!path)\n .map(({ path }) => path)\n .join('');\n}\n"],"names":[],"mappings":";;AAKA;AACA;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;"}