@logbrew/react-native 0.1.38 → 0.1.40

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 (104) hide show
  1. package/LogBrewReactNative.podspec +1 -1
  2. package/README.md +17 -15
  3. package/android-native-diagnostics.d.ts +15 -5
  4. package/android-native-diagnostics.js +170 -94
  5. package/apollo.cjs +435 -226
  6. package/apollo.d.cts +2 -70
  7. package/apollo.d.ts +24 -12
  8. package/apollo.js +438 -221
  9. package/apple-native-diagnostics-config.js +176 -0
  10. package/apple-native-diagnostics-context.js +232 -0
  11. package/apple-native-diagnostics-module.js +229 -0
  12. package/apple-native-diagnostics.d.ts +42 -11
  13. package/apple-native-diagnostics.js +60 -389
  14. package/expo.cjs +29 -16
  15. package/expo.d.ts +10 -9
  16. package/expo.js +4 -3
  17. package/fatal-admission.cjs +113 -0
  18. package/fatal-record.cjs +317 -0
  19. package/fatal-replay.cjs +297 -508
  20. package/global-errors-capture.cjs +369 -0
  21. package/global-errors-event.cjs +174 -0
  22. package/global-errors-support.cjs +128 -0
  23. package/global-errors.cjs +75 -351
  24. package/global-errors.d.cts +29 -278
  25. package/global-errors.d.ts +57 -27
  26. package/global-errors.js +7 -2
  27. package/global-errors.native.js +83 -48
  28. package/index-breadcrumbs.cjs +139 -0
  29. package/index-errors.cjs +167 -0
  30. package/index-events.cjs +365 -0
  31. package/index-navigation.cjs +327 -0
  32. package/index-random.cjs +120 -0
  33. package/index-react.cjs +189 -0
  34. package/index-spans.cjs +190 -0
  35. package/index-trace-fetch.cjs +322 -0
  36. package/index-trace.cjs +335 -0
  37. package/index-transport.cjs +201 -0
  38. package/index-values.cjs +232 -0
  39. package/index.cjs +95 -1220
  40. package/index.d.cts +2 -505
  41. package/index.d.ts +130 -469
  42. package/index.native.d.ts +146 -22
  43. package/index.native.js +184 -159
  44. package/instrumentation-fetch.cjs +113 -0
  45. package/instrumentation-install.cjs +241 -0
  46. package/instrumentation-runtime.cjs +65 -0
  47. package/instrumentation-teardown.cjs +93 -0
  48. package/instrumentation-values.cjs +282 -0
  49. package/instrumentation-xhr-request.cjs +298 -0
  50. package/instrumentation-xhr.cjs +233 -0
  51. package/instrumentation.cjs +110 -599
  52. package/instrumentation.d.cts +2 -84
  53. package/instrumentation.d.ts +22 -8
  54. package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +1 -1
  55. package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngine.swift +7 -1
  56. package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineAutomatic.swift +36 -4
  57. package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineQueue.swift +17 -0
  58. package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryLifecycle.swift +2 -0
  59. package/ios/GeneratedAppleDiagnostics/LogBrew/Transport.swift +41 -6
  60. package/ios/GeneratedAppleDiagnostics/SOURCE-MANIFEST.json +5 -5
  61. package/lifecycle.cjs +181 -78
  62. package/lifecycle.d.cts +1 -50
  63. package/lifecycle.d.ts +17 -6
  64. package/metadata.cjs +279 -114
  65. package/metro-debug-id.cjs +296 -0
  66. package/metro-serializer.cjs +219 -0
  67. package/metro.cjs +153 -297
  68. package/metro.d.cts +2 -57
  69. package/metro.d.ts +27 -13
  70. package/metro.js +2 -3
  71. package/native-bridge-async.cjs +165 -0
  72. package/native-bridge-scope.cjs +148 -0
  73. package/native-bridge.cjs +83 -186
  74. package/native-bridge.d.cts +2 -94
  75. package/native-bridge.d.ts +28 -15
  76. package/native-client-bindings.js +230 -0
  77. package/native-diagnostics-values.js +120 -0
  78. package/native-module-lookup.js +31 -0
  79. package/native-null.js +3 -0
  80. package/null-value.cjs +4 -0
  81. package/package.json +44 -2
  82. package/persistent-delivery-store.js +247 -0
  83. package/persistent-delivery.native.js +183 -261
  84. package/promise-rejection-handlers.cjs +368 -0
  85. package/promise-rejections.cjs +169 -361
  86. package/react-native.config.js +3 -1
  87. package/release-artifacts-files.cjs +94 -0
  88. package/release-artifacts-options.cjs +182 -0
  89. package/release-artifacts.cjs +278 -207
  90. package/release-artifacts.d.cts +2 -55
  91. package/release-artifacts.d.ts +18 -7
  92. package/release-artifacts.js +2 -4
  93. package/resource-fetch-graphql.cjs +265 -0
  94. package/resource-fetch-size.cjs +156 -0
  95. package/resource-fetch.cjs +227 -428
  96. package/resource-fetch.d.cts +1 -60
  97. package/resource-fetch.d.ts +17 -6
  98. package/scripts/sync-apple-native-sources.mjs +101 -53
  99. package/types/capture.d.ts +95 -0
  100. package/types/config.d.ts +85 -0
  101. package/types/defaults.d.ts +55 -0
  102. package/types/events.d.ts +203 -0
  103. package/types/provider.d.ts +81 -0
  104. package/types/trace.d.ts +104 -0
package/lifecycle.cjs CHANGED
@@ -1,13 +1,61 @@
1
1
  "use strict";
2
2
 
3
3
  const { SdkError } = require("@logbrew/sdk");
4
- const {
5
- createReactNativeSpanAttributes,
6
- createReactNativeTraceContext,
7
- getActiveLogBrewTrace,
8
- getReactNativeContext
9
- } = require("./index.cjs");
4
+ const { indexRuntime, isCallable, readField } = require("./instrumentation-values.cjs");
10
5
 
6
+ /**
7
+ * @import { LogBrewClient, Metadata, SpanAttributes } from "@logbrew/sdk"
8
+ * @import { ReactNativeSpanEvent } from "./index.cjs"
9
+ * @import { AppStateInput, PlatformInput, TraceInput } from "./instrumentation-values.cjs"
10
+ * @import { LifecycleListenerOptions } from "./instrumentation-runtime.cjs"
11
+ */
12
+
13
+ /**
14
+ * @typedef {{ readonly fromState: string | undefined, readonly screen: string | undefined, readonly toState: string | undefined }} LifecycleIdContext
15
+ * @typedef {{
16
+ * readonly appState?: AppStateInput | undefined,
17
+ * readonly durationMs?: number | undefined,
18
+ * readonly fromState?: unknown,
19
+ * readonly id?: string | undefined,
20
+ * readonly idFactory?: ((context: LifecycleIdContext) => string) | undefined,
21
+ * readonly metadata?: Readonly<Metadata> | undefined,
22
+ * readonly name?: string | undefined,
23
+ * readonly now?: (() => string) | undefined,
24
+ * readonly platform?: PlatformInput | undefined,
25
+ * readonly screen?: string | undefined,
26
+ * readonly sessionId?: string | undefined,
27
+ * readonly state?: unknown,
28
+ * readonly status?: SpanAttributes["status"] | undefined,
29
+ * readonly timestamp?: string | undefined,
30
+ * readonly toState?: unknown,
31
+ * readonly trace?: TraceInput | undefined
32
+ * }} LifecycleSpanInput
33
+ * @typedef {{
34
+ * readonly appState: AppStateInput,
35
+ * readonly client: LogBrewClient,
36
+ * readonly options: Readonly<{ metadata: Readonly<Metadata>, now: () => string, nowMs: () => number }> & LifecycleListenerOptions
37
+ * }} LifecycleContext
38
+ * @typedef {{ readonly changedAtMs: number, readonly state: string | undefined }} LifecycleMoment
39
+ */
40
+
41
+ const MIN_DURATION_MS = 0;
42
+
43
+ function defaultLifecycleSpanEventId() {
44
+ return `evt_native_lifecycle_${indexRuntime.createReactNativeTraceContext().traceId}`;
45
+ }
46
+
47
+ /**
48
+ * @param {unknown} state
49
+ * @returns {string | undefined}
50
+ */
51
+ function normalizeLifecycleState(state) {
52
+ return typeof state === "string" && state.trim() !== "" ? state.trim() : undefined;
53
+ }
54
+
55
+ /**
56
+ * @param {LifecycleSpanInput} [input]
57
+ * @returns {ReactNativeSpanEvent}
58
+ */
11
59
  function createReactNativeLifecycleSpanEvent({
12
60
  durationMs, fromState, id, idFactory = defaultLifecycleSpanEventId, metadata = {}, name,
13
61
  now = () => new Date().toISOString(), platform, appState, screen, sessionId, state, status = "ok",
@@ -15,32 +63,52 @@ function createReactNativeLifecycleSpanEvent({
15
63
  } = {}) {
16
64
  const safeFromState = normalizeLifecycleState(fromState);
17
65
  const safeToState = normalizeLifecycleState(toState ?? state);
18
- const transition = [safeFromState, safeToState].filter(Boolean).join("->");
19
- const spanName = name ?? `app_state:${transition || safeToState || safeFromState || "change"}`;
20
- const activeTrace = trace ?? getActiveLogBrewTrace() ?? createReactNativeTraceContext();
21
- return {
22
- id: id ?? idFactory({ fromState: safeFromState, screen, toState: safeToState }),
23
- timestamp: timestamp ?? now(),
24
- attributes: createReactNativeSpanAttributes({
25
- name: spanName,
26
- status,
66
+ const transition = [safeFromState, safeToState].filter(knownState => knownState !== undefined).join("->");
67
+ const spanName = name ?? `app_state:${transition === "" ? "change" : transition}`;
68
+ const activeTrace = trace ?? indexRuntime.getActiveLogBrewTrace() ?? indexRuntime.createReactNativeTraceContext();
69
+ const eventId = id ?? idFactory({ fromState: safeFromState, screen, toState: safeToState });
70
+ const eventTimestamp = timestamp ?? now();
71
+ const attributes = indexRuntime.createReactNativeSpanAttributes({
72
+ durationMs,
73
+ metadata: {
74
+ ...indexRuntime.getReactNativeContext({ appState, platform }),
75
+ source: "react-native.lifecycle",
76
+
77
+ appState: safeToState,
27
78
  durationMs,
28
- trace: activeTrace,
29
- metadata: {
30
- ...getReactNativeContext({ platform, appState }),
31
- source: "react-native.lifecycle",
32
- appState: safeToState,
33
- durationMs,
34
- fromAppState: safeFromState,
35
- screen,
36
- sessionId,
37
- toAppState: safeToState,
38
- ...metadata
39
- }
40
- })
79
+ fromAppState: safeFromState,
80
+ screen,
81
+ sessionId,
82
+ toAppState: safeToState,
83
+ ...metadata
84
+ },
85
+ name: spanName,
86
+ status,
87
+ trace: activeTrace
88
+ });
89
+ return {
90
+ id: eventId,
91
+ timestamp: eventTimestamp,
92
+
93
+ attributes
41
94
  };
42
95
  }
43
96
 
97
+ /**
98
+ * @param {LogBrewClient | null | undefined} client
99
+ * @returns {asserts client is LogBrewClient}
100
+ */
101
+ function requireClient(client) {
102
+ if (!client) {
103
+ throw new SdkError("configuration_error", "LogBrew React Native lifecycle helpers require a client");
104
+ }
105
+ }
106
+
107
+ /**
108
+ * @param {LogBrewClient | null | undefined} client
109
+ * @param {LifecycleSpanInput} [input]
110
+ * @returns {ReactNativeSpanEvent}
111
+ */
44
112
  function captureReactNativeLifecycleSpan(client, input = {}) {
45
113
  requireClient(client);
46
114
  const event = createReactNativeLifecycleSpanEvent(input);
@@ -48,71 +116,106 @@ function captureReactNativeLifecycleSpan(client, input = {}) {
48
116
  return event;
49
117
  }
50
118
 
51
- function createAppStateLifecycleSpanListener(client, appState, {
52
- captureInitialState = false, metadata = {}, now = () => new Date().toISOString(), nowMs = () => Date.now(),
53
- onError, platform, screen, sessionId, trace
54
- } = {}) {
55
- requireClient(client);
56
- if (!appState || typeof appState.addEventListener !== "function") {
57
- throw new SdkError("configuration_error", "createAppStateLifecycleSpanListener requires AppState.addEventListener");
119
+ /**
120
+ * @param {unknown} subscription
121
+ * @returns {() => unknown}
122
+ */
123
+ function subscriptionRemover(subscription) {
124
+ if (isCallable(subscription)) {
125
+ return subscription;
58
126
  }
127
+ if (isCallable(readField(subscription, "remove"))) {
128
+ return () => {
129
+ const remove = readField(subscription, "remove");
130
+ if (!isCallable(remove)) {
131
+ throw new TypeError("subscription.remove is not a function");
132
+ }
133
+ return Reflect.apply(remove, subscription, []);
134
+ };
135
+ }
136
+ return () => undefined;
137
+ }
59
138
 
60
- let previousState = normalizeLifecycleState(appState.currentState);
61
- let previousChangedAtMs = nowMs();
62
- if (captureInitialState && previousState !== undefined) {
63
- captureReactNativeLifecycleSpan(client, {
64
- appState, metadata, now, platform, screen, sessionId, toState: previousState, trace
65
- });
139
+ /**
140
+ * @param {LifecycleContext} context
141
+ * @param {LifecycleMoment} previous
142
+ * @param {LifecycleMoment} next
143
+ * @returns {LifecycleSpanInput}
144
+ */
145
+ function lifecycleChangeInput({ appState, options }, previous, next) {
146
+ return {
147
+ appState,
148
+ durationMs: previous.state === undefined ? undefined : Math.max(MIN_DURATION_MS, next.changedAtMs - previous.changedAtMs),
149
+ fromState: previous.state,
150
+ metadata: options.metadata,
151
+ now: options.now,
152
+ platform: options.platform,
153
+ screen: options.screen,
154
+ sessionId: options.sessionId,
155
+ timestamp: options.now(),
156
+ toState: next.state,
157
+ trace: options.trace
158
+ };
159
+ }
160
+
161
+ /**
162
+ * @param {((error: unknown) => void) | undefined} onError
163
+ * @param {unknown} error
164
+ * @returns {void}
165
+ */
166
+ function reportLifecycleError(onError, error) {
167
+ if (typeof onError === "function") {
168
+ onError(error);
169
+ } else {
170
+ throw error;
66
171
  }
172
+ }
67
173
 
68
- const subscription = appState.addEventListener("change", (nextState) => {
174
+ /**
175
+ * @param {LifecycleContext} context
176
+ * @param {LifecycleMoment} initial
177
+ * @returns {(nextState: string) => void}
178
+ */
179
+ function lifecycleChangeListener(context, initial) {
180
+ let previous = initial;
181
+ return (nextState) => {
69
182
  try {
70
183
  const safeNextState = normalizeLifecycleState(nextState);
71
184
  if (safeNextState === undefined) {
72
185
  return;
73
186
  }
74
- const changedAtMs = nowMs();
75
- const durationMs = previousState === undefined ? undefined : Math.max(0, changedAtMs - previousChangedAtMs);
76
- captureReactNativeLifecycleSpan(client, {
77
- appState, durationMs, fromState: previousState, metadata, now, platform, screen, sessionId,
78
- timestamp: now(), toState: safeNextState, trace
79
- });
80
- previousState = safeNextState;
81
- previousChangedAtMs = changedAtMs;
187
+ const next = { changedAtMs: context.options.nowMs(), state: safeNextState };
188
+ captureReactNativeLifecycleSpan(context.client, lifecycleChangeInput(context, previous, next));
189
+ previous = next;
82
190
  } catch (error) {
83
- if (typeof onError === "function") {
84
- onError(error);
85
- } else {
86
- throw error;
87
- }
191
+ reportLifecycleError(context.options.onError, error);
88
192
  }
89
- });
90
-
91
- return subscriptionRemover(subscription);
92
- }
93
-
94
- function requireClient(client) {
95
- if (!client) {
96
- throw new SdkError("configuration_error", "LogBrew React Native lifecycle helpers require a client");
97
- }
98
- }
99
-
100
- function defaultLifecycleSpanEventId() {
101
- return `evt_native_lifecycle_${createReactNativeTraceContext().traceId}`;
102
- }
103
-
104
- function normalizeLifecycleState(state) {
105
- return typeof state === "string" && state.trim() !== "" ? state.trim() : undefined;
193
+ };
106
194
  }
107
195
 
108
- function subscriptionRemover(subscription) {
109
- if (typeof subscription === "function") {
110
- return subscription;
196
+ /**
197
+ * @param {LogBrewClient | null | undefined} client
198
+ * @param {AppStateInput | null | undefined} appState
199
+ * @param {LifecycleListenerOptions} [options]
200
+ * @returns {() => unknown}
201
+ */
202
+ function createAppStateLifecycleSpanListener(client, appState, {
203
+ captureInitialState = false, metadata = {}, now = () => new Date().toISOString(), nowMs = () => Date.now(),
204
+ onError, platform, screen, sessionId, trace
205
+ } = {}) {
206
+ requireClient(client);
207
+ if (!appState || typeof appState.addEventListener !== "function") {
208
+ throw new SdkError("configuration_error", "createAppStateLifecycleSpanListener requires AppState.addEventListener");
111
209
  }
112
- if (subscription && typeof subscription.remove === "function") {
113
- return () => subscription.remove();
210
+ const options = { metadata, now, nowMs, onError, platform, screen, sessionId, trace };
211
+ const state = normalizeLifecycleState(appState.currentState);
212
+ const initial = { changedAtMs: nowMs(), state };
213
+ if (captureInitialState && state !== undefined) {
214
+ captureReactNativeLifecycleSpan(client, {
215
+ appState, metadata, now, platform, screen, sessionId, toState: state, trace
216
+ });
114
217
  }
115
- return () => {};
218
+ return subscriptionRemover(appState.addEventListener("change", lifecycleChangeListener({ appState, client, options }, initial)));
116
219
  }
117
220
 
118
221
  module.exports = {
package/lifecycle.d.cts CHANGED
@@ -1,50 +1 @@
1
- import type { LogBrewClient, Metadata, SpanAttributes } from "@logbrew/sdk";
2
- import type {
3
- ReactNativeAppStateLike,
4
- ReactNativeContextOptions,
5
- ReactNativeSpanEvent
6
- } from "./index.cjs";
7
-
8
- export type ReactNativeLifecycleSpanInput = ReactNativeContextOptions & {
9
- durationMs?: number;
10
- fromState?: string;
11
- id?: string;
12
- idFactory?: (context: ReactNativeLifecycleSpanIdFactoryContext) => string;
13
- name?: string;
14
- now?: () => string;
15
- screen?: string;
16
- sessionId?: string;
17
- state?: string;
18
- status?: SpanAttributes["status"];
19
- timestamp?: string;
20
- toState?: string;
21
- };
22
-
23
- export type ReactNativeLifecycleSpanIdFactoryContext = {
24
- fromState?: string;
25
- screen?: string;
26
- toState?: string;
27
- };
28
-
29
- export type AppStateLifecycleSpanListenerOptions = ReactNativeContextOptions & {
30
- captureInitialState?: boolean;
31
- metadata?: Metadata;
32
- now?: () => string;
33
- nowMs?: () => number;
34
- onError?: (error: unknown) => void;
35
- screen?: string;
36
- sessionId?: string;
37
- };
38
-
39
- export declare function createReactNativeLifecycleSpanEvent(
40
- input?: ReactNativeLifecycleSpanInput
41
- ): ReactNativeSpanEvent;
42
- export declare function captureReactNativeLifecycleSpan(
43
- client: LogBrewClient,
44
- input?: ReactNativeLifecycleSpanInput
45
- ): ReactNativeSpanEvent;
46
- export declare function createAppStateLifecycleSpanListener(
47
- client: LogBrewClient,
48
- appState: ReactNativeAppStateLike,
49
- options?: AppStateLifecycleSpanListenerOptions
50
- ): () => void;
1
+ export * from "./lifecycle.js";
package/lifecycle.d.ts CHANGED
@@ -5,7 +5,7 @@ import type {
5
5
  ReactNativeSpanEvent
6
6
  } from "./index.js";
7
7
 
8
- export type ReactNativeLifecycleSpanInput = ReactNativeContextOptions & {
8
+ type ReactNativeLifecycleSpanInput = ReactNativeContextOptions & {
9
9
  durationMs?: number;
10
10
  fromState?: string;
11
11
  id?: string;
@@ -20,13 +20,13 @@ export type ReactNativeLifecycleSpanInput = ReactNativeContextOptions & {
20
20
  toState?: string;
21
21
  };
22
22
 
23
- export type ReactNativeLifecycleSpanIdFactoryContext = {
23
+ type ReactNativeLifecycleSpanIdFactoryContext = {
24
24
  fromState?: string;
25
25
  screen?: string;
26
26
  toState?: string;
27
27
  };
28
28
 
29
- export type AppStateLifecycleSpanListenerOptions = ReactNativeContextOptions & {
29
+ type AppStateLifecycleSpanListenerOptions = ReactNativeContextOptions & {
30
30
  captureInitialState?: boolean;
31
31
  metadata?: Metadata;
32
32
  now?: () => string;
@@ -36,15 +36,26 @@ export type AppStateLifecycleSpanListenerOptions = ReactNativeContextOptions & {
36
36
  sessionId?: string;
37
37
  };
38
38
 
39
- export declare function createReactNativeLifecycleSpanEvent(
39
+ declare function createReactNativeLifecycleSpanEvent(
40
40
  input?: ReactNativeLifecycleSpanInput
41
41
  ): ReactNativeSpanEvent;
42
- export declare function captureReactNativeLifecycleSpan(
42
+ declare function captureReactNativeLifecycleSpan(
43
43
  client: LogBrewClient,
44
44
  input?: ReactNativeLifecycleSpanInput
45
45
  ): ReactNativeSpanEvent;
46
- export declare function createAppStateLifecycleSpanListener(
46
+ declare function createAppStateLifecycleSpanListener(
47
47
  client: LogBrewClient,
48
48
  appState: ReactNativeAppStateLike,
49
49
  options?: AppStateLifecycleSpanListenerOptions
50
50
  ): () => void;
51
+
52
+ export type {
53
+ AppStateLifecycleSpanListenerOptions,
54
+ ReactNativeLifecycleSpanIdFactoryContext,
55
+ ReactNativeLifecycleSpanInput
56
+ };
57
+ export {
58
+ createReactNativeLifecycleSpanEvent,
59
+ captureReactNativeLifecycleSpan,
60
+ createAppStateLifecycleSpanListener
61
+ };