@lookiero/checkout 0.6.0-beta.32 → 0.6.0-beta.34

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.
@@ -3,11 +3,18 @@ import { ReactNativeClient, Hub, ErrorBoundary, wrap as sentryWrap, ReactNativeT
3
3
  import { makeReactNativeTransport } from "@sentry/react-native/dist/js/transports/native";
4
4
  import { NATIVE } from "@sentry/react-native/dist/js/wrapper";
5
5
  import { useEffect } from "react";
6
- import { useLocation, useNavigationType } from "react-router-native";
6
+ import { useLocation } from "react-router-native";
7
7
  import { matchRoutes } from "./matchRoutes";
8
- import { ReactRouterV6Instrumentation } from "./reactRouterV6Instrumentation.native";
9
- const transport = (options, nativeFetch) => NATIVE.isNativeTransportAvailable() ? makeReactNativeTransport(options) : makeFetchTransport(options, nativeFetch);
10
- const routingInstrumentation = new ReactRouterV6Instrumentation(useEffect, useLocation, useNavigationType, matchRoutes);
8
+ import { ReactRouterV6Instrumentation } from "./reactRouterV6Instrumentation/reactRouterV6Instrumentation.native";
9
+ const transport = (options, nativeFetch) => {
10
+ console.log("NATIVE.isNativeTransportAvailable()", NATIVE.isNativeTransportAvailable());
11
+ console.log(makeReactNativeTransport(options));
12
+ console.log(makeFetchTransport(options, nativeFetch));
13
+ return NATIVE.isNativeTransportAvailable()
14
+ ? makeReactNativeTransport(options)
15
+ : makeFetchTransport(options, nativeFetch);
16
+ };
17
+ const routingInstrumentation = new ReactRouterV6Instrumentation(useEffect, useLocation, matchRoutes);
11
18
  const integrations = [new ReactNativeTracing({ routingInstrumentation })];
12
19
  const wrapComponent = (Component) => sentryWrap(Component);
13
20
  const wrapUseRoutes = routingInstrumentation.wrapUseRoutes.bind(routingInstrumentation);
@@ -2,7 +2,7 @@ import { ComponentType } from "react";
2
2
  import { Platform } from "react-native";
3
3
  interface SentryLoggerFunctionArgs {
4
4
  readonly publicKey: string;
5
- readonly environment: `${typeof Platform.OS}-${"DEV" | "PROD"}`;
5
+ readonly environment: `${typeof Platform.OS}-${"DEV" | "PROD" | "EXPO"}`;
6
6
  readonly release: string;
7
7
  readonly project: string;
8
8
  }
@@ -0,0 +1,12 @@
1
+ import { RouteMatch, RouteObject } from "react-router-native";
2
+ import { Location } from "../types";
3
+ interface NormalizedNameAndMatchForLocationFunctionArgs {
4
+ readonly routes: RouteObject[];
5
+ readonly location: Location;
6
+ readonly branches: RouteMatch[];
7
+ }
8
+ interface NormalizedNameAndMatchForLocationFunction {
9
+ (args: NormalizedNameAndMatchForLocationFunctionArgs): [string, RouteMatch | null];
10
+ }
11
+ declare const normalizedNameAndMatchForLocation: NormalizedNameAndMatchForLocationFunction;
12
+ export { normalizedNameAndMatchForLocation };
@@ -0,0 +1,34 @@
1
+ import { getNumberOfUrlSegments } from "@sentry/utils";
2
+ const normalizedNameAndMatchForLocation = ({ routes, location, branches, }) => {
3
+ if (!routes || routes.length === 0) {
4
+ return [location.pathname, null];
5
+ }
6
+ let pathBuilder = "";
7
+ if (branches) {
8
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
9
+ for (let x = 0; x < branches.length; x++) {
10
+ const branch = branches[x];
11
+ const route = branch.route;
12
+ if (route) {
13
+ // Early return if index route
14
+ if (route.index) {
15
+ return [branch.pathname, branch];
16
+ }
17
+ const path = route.path;
18
+ if (path) {
19
+ const newPath = path[0] === "/" || pathBuilder[pathBuilder.length - 1] === "/" ? path : `/${path}`;
20
+ pathBuilder += newPath;
21
+ if (branch.pathname === location.pathname) {
22
+ if (getNumberOfUrlSegments(pathBuilder) !== getNumberOfUrlSegments(branch.pathname) &&
23
+ pathBuilder.slice(-2) !== "/*") {
24
+ return [newPath, branch];
25
+ }
26
+ return [pathBuilder, branch];
27
+ }
28
+ }
29
+ }
30
+ }
31
+ }
32
+ return [location.pathname, null];
33
+ };
34
+ export { normalizedNameAndMatchForLocation };
@@ -0,0 +1,22 @@
1
+ import { RoutingInstrumentation } from "@sentry/react-native";
2
+ import { OnConfirmRoute, TransactionCreator } from "@sentry/react-native/dist/js/tracing/routingInstrumentation";
3
+ import { BeforeNavigate } from "@sentry/react-native/dist/js/tracing/types";
4
+ import { MatchRoutes, UseEffect, UseLocation, WrapUseRoutes } from "../types";
5
+ declare class ReactRouterV6Instrumentation extends RoutingInstrumentation {
6
+ static instrumentationName: string;
7
+ private useEffect;
8
+ private useLocation;
9
+ private matchRoutes;
10
+ private prevRoute?;
11
+ private recentRouteKeys;
12
+ private latestTransaction?;
13
+ private readonly maxRecentRouteLen;
14
+ constructor(useEffect: UseEffect, useLocation: UseLocation, matchRoutes: MatchRoutes);
15
+ registerRoutingInstrumentation(listener: TransactionCreator, beforeNavigate: BeforeNavigate, onConfirmRoute: OnConfirmRoute): void;
16
+ private onRouteChange;
17
+ private currentRouteFromLocation;
18
+ private pushRecentRouteKey;
19
+ private onBeforeNavigateNotSampled;
20
+ wrapUseRoutes: WrapUseRoutes;
21
+ }
22
+ export { ReactRouterV6Instrumentation };
@@ -0,0 +1,124 @@
1
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
2
+ import { RoutingInstrumentation } from "@sentry/react-native";
3
+ import { logger } from "@sentry/utils";
4
+ import React from "react";
5
+ import { normalizedNameAndMatchForLocation } from "./normalizedNameAndMatchForLocation";
6
+ import { transactionContext } from "./transactionContext";
7
+ class ReactRouterV6Instrumentation extends RoutingInstrumentation {
8
+ static instrumentationName = "react-router-v6";
9
+ useEffect;
10
+ useLocation;
11
+ matchRoutes;
12
+ prevRoute;
13
+ recentRouteKeys = [];
14
+ latestTransaction;
15
+ maxRecentRouteLen = 200;
16
+ constructor(useEffect, useLocation, matchRoutes) {
17
+ super();
18
+ this.useEffect = useEffect;
19
+ this.useLocation = useLocation;
20
+ this.matchRoutes = matchRoutes;
21
+ }
22
+ registerRoutingInstrumentation(listener, beforeNavigate, onConfirmRoute) {
23
+ super.registerRoutingInstrumentation(listener, beforeNavigate, onConfirmRoute);
24
+ this.latestTransaction = this.onRouteWillChange(INITIAL_TRANSACTION_CONTEXT);
25
+ }
26
+ onRouteChange(location, routes, updateLatestTransaction = false) {
27
+ const currentRoute = this.currentRouteFromLocation(location, routes);
28
+ if (!currentRoute || (this.prevRoute && currentRoute.key === this.prevRoute.key)) {
29
+ return;
30
+ }
31
+ const originalContext = transactionContext({
32
+ instrumentationName: ReactRouterV6Instrumentation.instrumentationName,
33
+ route: currentRoute,
34
+ previousRoute: this.prevRoute,
35
+ });
36
+ let finalContext = this._beforeNavigate?.(originalContext);
37
+ if (!finalContext) {
38
+ logger.error(`[ReactRouterV6Instrumentation] beforeNavigate returned ${finalContext}, return context.sampled = false to not send transaction.`);
39
+ finalContext = { ...originalContext, sampled: false };
40
+ }
41
+ if (finalContext.sampled === false) {
42
+ this.onBeforeNavigateNotSampled(finalContext.name);
43
+ }
44
+ if (updateLatestTransaction && this.latestTransaction) {
45
+ this.latestTransaction.updateWithContext(finalContext);
46
+ }
47
+ else {
48
+ this.latestTransaction = this.onRouteWillChange(finalContext);
49
+ }
50
+ this.pushRecentRouteKey(currentRoute.key);
51
+ this.prevRoute = currentRoute;
52
+ }
53
+ currentRouteFromLocation(location, routes) {
54
+ const branches = this.matchRoutes(routes, location);
55
+ if (!branches) {
56
+ return null;
57
+ }
58
+ const [normalizedName, match] = normalizedNameAndMatchForLocation({ location, routes, branches });
59
+ if (!match) {
60
+ return {
61
+ name: normalizedName,
62
+ key: normalizedName,
63
+ params: {},
64
+ hasBeenSeen: this.recentRouteKeys.includes(normalizedName),
65
+ };
66
+ }
67
+ const name = match.route.path;
68
+ const key = match.route.id ?? name;
69
+ return {
70
+ name,
71
+ key,
72
+ params: match.params,
73
+ hasBeenSeen: this.recentRouteKeys.includes(key),
74
+ };
75
+ }
76
+ pushRecentRouteKey(key) {
77
+ this.recentRouteKeys.push(key);
78
+ if (this.recentRouteKeys.length > this.maxRecentRouteLen) {
79
+ this.recentRouteKeys = this.recentRouteKeys.slice(this.recentRouteKeys.length - this.maxRecentRouteLen);
80
+ }
81
+ }
82
+ onBeforeNavigateNotSampled(transactionName) {
83
+ logger.log(`[ReactRouterV6Instrumentation] Will not send transaction "${transactionName}" due to beforeNavigate.`);
84
+ }
85
+ wrapUseRoutes = (origUseRoutes) => {
86
+ if (!this.useEffect || !this.useLocation || !this.matchRoutes) {
87
+ __DEBUG_BUILD__ &&
88
+ logger.warn("ReactRouterV6Instrumentation was unable to wrap `useRoutes` because of one or more missing parameters.");
89
+ return origUseRoutes;
90
+ }
91
+ let isMountRenderPass = true;
92
+ const useRoutes = (routes, locationArg) => {
93
+ const SentryRoutes = () => {
94
+ const Routes = origUseRoutes(routes, locationArg);
95
+ const location = this.useLocation();
96
+ const stableLocationParam = typeof locationArg === "string" || (locationArg && locationArg.pathname)
97
+ ? locationArg
98
+ : location;
99
+ this.useEffect(() => {
100
+ const normalizedLocation = typeof stableLocationParam === "string" ? { pathname: stableLocationParam } : stableLocationParam;
101
+ if (isMountRenderPass) {
102
+ this.onRouteChange(normalizedLocation, routes, true);
103
+ isMountRenderPass = false;
104
+ }
105
+ else {
106
+ this.onRouteChange(normalizedLocation, routes);
107
+ }
108
+ }, [stableLocationParam]);
109
+ return Routes;
110
+ };
111
+ return React.createElement(SentryRoutes, null);
112
+ };
113
+ return useRoutes;
114
+ };
115
+ }
116
+ const INITIAL_TRANSACTION_CONTEXT = {
117
+ name: "App Launch",
118
+ op: "navigation",
119
+ tags: {
120
+ ["routing.instrumentation"]: ReactRouterV6Instrumentation.instrumentationName,
121
+ },
122
+ data: {},
123
+ };
124
+ export { ReactRouterV6Instrumentation };
@@ -0,0 +1,22 @@
1
+ import { TransactionContext } from "@sentry/types";
2
+ import { NavigationCurrentRoute, NavigationRoute } from "./types";
3
+ interface NavigationTransactionContext extends TransactionContext {
4
+ readonly tags: {
5
+ readonly ["routing.instrumentation"]: string;
6
+ readonly ["routing.route.name"]: string;
7
+ };
8
+ readonly data: {
9
+ readonly route: NavigationCurrentRoute;
10
+ readonly previousRoute: NavigationRoute | null;
11
+ };
12
+ }
13
+ interface TransactionContextFunctionArgs {
14
+ readonly instrumentationName: string;
15
+ readonly route: NavigationCurrentRoute;
16
+ readonly previousRoute?: NavigationRoute;
17
+ }
18
+ interface TransactionContextFunction {
19
+ (args: TransactionContextFunctionArgs): NavigationTransactionContext;
20
+ }
21
+ declare const transactionContext: TransactionContextFunction;
22
+ export { transactionContext };
@@ -0,0 +1,15 @@
1
+ const transactionContext = ({ instrumentationName, route, previousRoute = null, }) => {
2
+ return {
3
+ name: route.name,
4
+ op: "navigation",
5
+ tags: {
6
+ ["routing.instrumentation"]: instrumentationName,
7
+ ["routing.route.name"]: route.name,
8
+ },
9
+ data: {
10
+ route,
11
+ previousRoute,
12
+ },
13
+ };
14
+ };
15
+ export { transactionContext };
@@ -0,0 +1,9 @@
1
+ interface NavigationRoute {
2
+ readonly name: string;
3
+ readonly key: string;
4
+ readonly params: Record<string, unknown>;
5
+ }
6
+ interface NavigationCurrentRoute extends NavigationRoute {
7
+ readonly hasBeenSeen: boolean;
8
+ }
9
+ export type { NavigationRoute, NavigationCurrentRoute };
@@ -1,8 +1,10 @@
1
1
  import { ComponentType, useEffect } from "react";
2
2
  import { matchRoutes, RouteObject, useLocation } from "react-router-native";
3
+ interface Location {
4
+ readonly pathname: string;
5
+ }
3
6
  type UseEffect = typeof useEffect;
4
7
  type UseLocation = typeof useLocation;
5
- type UseNavigationType = () => "PUSH" | "REPLACE" | "POP";
6
8
  type MatchRoutes = typeof matchRoutes;
7
9
  type UseRoutes = (routes: RouteObject[], locationArg?: Partial<Location> | string) => React.ReactElement | null;
8
10
  interface WrapUseRoutes {
@@ -11,4 +13,4 @@ interface WrapUseRoutes {
11
13
  interface WrapComponent {
12
14
  <P>(Component: ComponentType<P>): ComponentType<P>;
13
15
  }
14
- export type { UseEffect, UseLocation, UseNavigationType, MatchRoutes, WrapUseRoutes, WrapComponent };
16
+ export type { Location, UseEffect, UseLocation, MatchRoutes, UseRoutes, WrapUseRoutes, WrapComponent };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookiero/checkout",
3
- "version": "0.6.0-beta.32",
3
+ "version": "0.6.0-beta.34",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [