@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.
- package/LogBrewReactNative.podspec +1 -1
- package/README.md +17 -15
- package/android-native-diagnostics.d.ts +15 -5
- package/android-native-diagnostics.js +170 -94
- package/apollo.cjs +435 -226
- package/apollo.d.cts +2 -70
- package/apollo.d.ts +24 -12
- package/apollo.js +438 -221
- package/apple-native-diagnostics-config.js +176 -0
- package/apple-native-diagnostics-context.js +232 -0
- package/apple-native-diagnostics-module.js +229 -0
- package/apple-native-diagnostics.d.ts +42 -11
- package/apple-native-diagnostics.js +60 -389
- package/expo.cjs +29 -16
- package/expo.d.ts +10 -9
- package/expo.js +4 -3
- package/fatal-admission.cjs +113 -0
- package/fatal-record.cjs +317 -0
- package/fatal-replay.cjs +297 -508
- package/global-errors-capture.cjs +369 -0
- package/global-errors-event.cjs +174 -0
- package/global-errors-support.cjs +128 -0
- package/global-errors.cjs +75 -351
- package/global-errors.d.cts +29 -278
- package/global-errors.d.ts +57 -27
- package/global-errors.js +7 -2
- package/global-errors.native.js +83 -48
- package/index-breadcrumbs.cjs +139 -0
- package/index-errors.cjs +167 -0
- package/index-events.cjs +365 -0
- package/index-navigation.cjs +327 -0
- package/index-random.cjs +120 -0
- package/index-react.cjs +189 -0
- package/index-spans.cjs +190 -0
- package/index-trace-fetch.cjs +322 -0
- package/index-trace.cjs +335 -0
- package/index-transport.cjs +201 -0
- package/index-values.cjs +232 -0
- package/index.cjs +95 -1220
- package/index.d.cts +2 -505
- package/index.d.ts +130 -469
- package/index.native.d.ts +146 -22
- package/index.native.js +184 -159
- package/instrumentation-fetch.cjs +113 -0
- package/instrumentation-install.cjs +241 -0
- package/instrumentation-runtime.cjs +65 -0
- package/instrumentation-teardown.cjs +93 -0
- package/instrumentation-values.cjs +282 -0
- package/instrumentation-xhr-request.cjs +298 -0
- package/instrumentation-xhr.cjs +233 -0
- package/instrumentation.cjs +110 -599
- package/instrumentation.d.cts +2 -84
- package/instrumentation.d.ts +22 -8
- package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +1 -1
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngine.swift +7 -1
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineAutomatic.swift +36 -4
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineQueue.swift +17 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryLifecycle.swift +2 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/Transport.swift +41 -6
- package/ios/GeneratedAppleDiagnostics/SOURCE-MANIFEST.json +5 -5
- package/lifecycle.cjs +181 -78
- package/lifecycle.d.cts +1 -50
- package/lifecycle.d.ts +17 -6
- package/metadata.cjs +279 -114
- package/metro-debug-id.cjs +296 -0
- package/metro-serializer.cjs +219 -0
- package/metro.cjs +153 -297
- package/metro.d.cts +2 -57
- package/metro.d.ts +27 -13
- package/metro.js +2 -3
- package/native-bridge-async.cjs +165 -0
- package/native-bridge-scope.cjs +148 -0
- package/native-bridge.cjs +83 -186
- package/native-bridge.d.cts +2 -94
- package/native-bridge.d.ts +28 -15
- package/native-client-bindings.js +230 -0
- package/native-diagnostics-values.js +120 -0
- package/native-module-lookup.js +31 -0
- package/native-null.js +3 -0
- package/null-value.cjs +4 -0
- package/package.json +44 -2
- package/persistent-delivery-store.js +247 -0
- package/persistent-delivery.native.js +183 -261
- package/promise-rejection-handlers.cjs +368 -0
- package/promise-rejections.cjs +169 -361
- package/react-native.config.js +3 -1
- package/release-artifacts-files.cjs +94 -0
- package/release-artifacts-options.cjs +182 -0
- package/release-artifacts.cjs +278 -207
- package/release-artifacts.d.cts +2 -55
- package/release-artifacts.d.ts +18 -7
- package/release-artifacts.js +2 -4
- package/resource-fetch-graphql.cjs +265 -0
- package/resource-fetch-size.cjs +156 -0
- package/resource-fetch.cjs +227 -428
- package/resource-fetch.d.cts +1 -60
- package/resource-fetch.d.ts +17 -6
- package/scripts/sync-apple-native-sources.mjs +101 -53
- package/types/capture.d.ts +95 -0
- package/types/config.d.ts +85 -0
- package/types/defaults.d.ts +55 -0
- package/types/events.d.ts +203 -0
- package/types/provider.d.ts +81 -0
- package/types/trace.d.ts +104 -0
|
@@ -8,7 +8,7 @@ Pod::Spec.new do |spec|
|
|
|
8
8
|
spec.summary = package["description"]
|
|
9
9
|
spec.homepage = "https://github.com/LogBrewCo/sdk"
|
|
10
10
|
spec.license = package["license"]
|
|
11
|
-
spec.authors = { "LogBrew" => "
|
|
11
|
+
spec.authors = { "LogBrew" => "support@logbrew.co" }
|
|
12
12
|
spec.platforms = { :ios => "13.0" }
|
|
13
13
|
spec.source = {
|
|
14
14
|
:git => "https://github.com/LogBrewCo/sdk.git",
|
package/README.md
CHANGED
|
@@ -84,8 +84,8 @@ Supplying `transport` enables the core SDK's bounded automatic delivery. On
|
|
|
84
84
|
mobile it sends 5 seconds after the first queued event or at 50 queued events,
|
|
85
85
|
which saves battery and radio wakeups; set `deliveryIntervalMs` to change it. It
|
|
86
86
|
coalesces concurrent work, retries transient failures, retains rejected
|
|
87
|
-
batches,
|
|
88
|
-
or non-retryable failures. Do not add a second app-owned flush interval.
|
|
87
|
+
batches, waits out short rate limits on its own, and pauses repeated automatic
|
|
88
|
+
sends after authentication, usage-limit, or non-retryable failures. Do not add a second app-owned flush interval.
|
|
89
89
|
`flushOnBackground: true` requests one final flush when AppState becomes
|
|
90
90
|
`inactive` or `background`; a failure never escapes the AppState callback.
|
|
91
91
|
Helpers generate a fresh opaque event ID by default. Explicit `id` and
|
|
@@ -96,7 +96,7 @@ Helpers generate a fresh opaque event ID by default. Explicit `id` and
|
|
|
96
96
|
Call `verifyLogBrewSetup()` once from a development-only button or setup
|
|
97
97
|
screen. A returned `hosted_accepted` receipt means the configured HTTPS intake
|
|
98
98
|
accepted every batch in that flush. Then use an authenticated CLI session to
|
|
99
|
-
confirm that
|
|
99
|
+
confirm that LogBrew stored the event for the intended project:
|
|
100
100
|
|
|
101
101
|
```bash
|
|
102
102
|
logbrew read logs --project <project_id> \
|
|
@@ -118,9 +118,12 @@ Use `client.deliveryHealth()` for content-free queue and delivery state. In
|
|
|
118
118
|
particular, inspect `deliveryState`, `lastOutcome`, `lastStatusClass`,
|
|
119
119
|
`pausedReason`, `queueEvents`, and `acceptedEvents`. A `401` pauses automatic
|
|
120
120
|
delivery with `pausedReason: "authentication"`; rotate or correct the public
|
|
121
|
-
client key before creating a new client. A `429` preserves the queue
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
client key before creating a new client. A `429` always preserves the queue.
|
|
122
|
+
When it carries `Retry-After` or `code: "rate_limited"`, delivery waits that
|
|
123
|
+
long (1 second to 1 hour, plus a little jitter) and then resends on its own,
|
|
124
|
+
with `deliveryState: "retrying"`. A `429` with `code: "usage_limit_exceeded"`,
|
|
125
|
+
or with neither signal, reports `pausedReason: "rate_limit"` until a
|
|
126
|
+
successful `flush()`.
|
|
124
127
|
|
|
125
128
|
## Read Events Back
|
|
126
129
|
|
|
@@ -377,8 +380,8 @@ Otherwise the crash is recorded as usual.
|
|
|
377
380
|
handlers, stops the watchdog, and leaves queued events available. After closing
|
|
378
381
|
the client, purge only for an explicit discard. Upload exact-release Android
|
|
379
382
|
symbols with `logbrew debug-artifacts upload`, require build-ID/architecture
|
|
380
|
-
lookup
|
|
381
|
-
replay, hang capture, and symbolicated
|
|
383
|
+
lookup. Keep your existing crash reporter until you have confirmed crash
|
|
384
|
+
replay, hang capture, and symbolicated issues in LogBrew.
|
|
382
385
|
|
|
383
386
|
For Expo prebuild or development builds, add the config plugin:
|
|
384
387
|
|
|
@@ -442,8 +445,8 @@ void replayLogBrewAppleNativeDiagnostics().catch((error) => {
|
|
|
442
445
|
```
|
|
443
446
|
|
|
444
447
|
`fatalHandlerOwnership: "logbrew"` is an explicit process-lifetime ownership
|
|
445
|
-
claim. Do not install these diagnostics while
|
|
446
|
-
owns the native fatal signal or Mach exception handlers. Linking both SDKs is
|
|
448
|
+
claim. Do not install these diagnostics while another crash reporter or
|
|
449
|
+
integration owns the native fatal signal or Mach exception handlers. Linking both SDKs is
|
|
447
450
|
allowed, but only one integration may install native fatal capture in a given
|
|
448
451
|
process. LogBrew cannot transfer or remove that ownership before process
|
|
449
452
|
restart.
|
|
@@ -542,8 +545,8 @@ reading the rejection value or emitting the runtime rejection identifier.
|
|
|
542
545
|
`rejectionHealth()` returns bounded duplicate, eviction, and later-handled
|
|
543
546
|
counters.
|
|
544
547
|
|
|
545
|
-
Do not install this helper while
|
|
546
|
-
tracker slot. Use the app-owned callback composition below when another
|
|
548
|
+
Do not install this helper while another crash reporter or integration owns
|
|
549
|
+
the same tracker slot. Use the app-owned callback composition below when another
|
|
547
550
|
integration must remain the owner. Hermes does not expose a previous-owner
|
|
548
551
|
restoration API. `deactivate()` therefore stops LogBrew capture through its
|
|
549
552
|
installed callbacks but cannot reinstate an earlier tracker. Install
|
|
@@ -650,8 +653,7 @@ when available. It strips query strings, hashes, hosts, and local absolute
|
|
|
650
653
|
paths from React Native frame data. Grouping keeps an informative sanitized
|
|
651
654
|
path, or falls back to a safe function name and then generated position for a
|
|
652
655
|
root-only runtime URL; raw stack text is still opt-in with `includeStack: true`.
|
|
653
|
-
|
|
654
|
-
uploaded release artifact.
|
|
656
|
+
LogBrew resolves source maps from the matching uploaded release artifact.
|
|
655
657
|
|
|
656
658
|
## Provider And Hooks
|
|
657
659
|
|
|
@@ -697,7 +699,7 @@ export function App({ client }) {
|
|
|
697
699
|
}
|
|
698
700
|
```
|
|
699
701
|
|
|
700
|
-
Screen views carry the versioned `screen_view` analytics classification, and explicit product actions carry `interaction`. The SDK uses the app-owned screen name as a bounded surface and does not inspect view hierarchies, selectors, or input values. Caller metadata cannot replace the reserved classification. See the repository [product analytics capture contract](../../
|
|
702
|
+
Screen views carry the versioned `screen_view` analytics classification, and explicit product actions carry `interaction`. The SDK uses the app-owned screen name as a bounded surface and does not inspect view hierarchies, selectors, or input values. Caller metadata cannot replace the reserved classification. See the repository [product analytics capture contract](../../README.md#product-analytics-capture).
|
|
701
703
|
|
|
702
704
|
The package ships a `react-native` entry that binds platform state and linked native services for Metro, while the default server entry accepts runtime dependencies explicitly. That keeps mobile setup explicit without treating a server process as a native runtime.
|
|
703
705
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type LogBrewAndroidNativeDiagnosticsConfiguration = Readonly<{
|
|
2
2
|
anrThresholdMs?: number;
|
|
3
3
|
clientKey: string;
|
|
4
4
|
environment: string;
|
|
@@ -8,7 +8,7 @@ export type LogBrewAndroidNativeDiagnosticsConfiguration = Readonly<{
|
|
|
8
8
|
service: string;
|
|
9
9
|
}>;
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
type LogBrewAndroidNativeDiagnosticsReceipt = Readonly<{
|
|
12
12
|
pending: number;
|
|
13
13
|
status:
|
|
14
14
|
| "already_installed"
|
|
@@ -18,12 +18,22 @@ export type LogBrewAndroidNativeDiagnosticsReceipt = Readonly<{
|
|
|
18
18
|
| "uninstalled";
|
|
19
19
|
}>;
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
declare function installLogBrewAndroidNativeDiagnostics(
|
|
22
22
|
configuration: LogBrewAndroidNativeDiagnosticsConfiguration
|
|
23
23
|
): LogBrewAndroidNativeDiagnosticsReceipt;
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
declare function getLogBrewAndroidNativeDiagnosticsStatus():
|
|
26
26
|
LogBrewAndroidNativeDiagnosticsReceipt;
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
declare function uninstallLogBrewAndroidNativeDiagnostics():
|
|
29
29
|
LogBrewAndroidNativeDiagnosticsReceipt;
|
|
30
|
+
|
|
31
|
+
export type {
|
|
32
|
+
LogBrewAndroidNativeDiagnosticsConfiguration,
|
|
33
|
+
LogBrewAndroidNativeDiagnosticsReceipt
|
|
34
|
+
};
|
|
35
|
+
export {
|
|
36
|
+
installLogBrewAndroidNativeDiagnostics,
|
|
37
|
+
getLogBrewAndroidNativeDiagnosticsStatus,
|
|
38
|
+
uninstallLogBrewAndroidNativeDiagnostics
|
|
39
|
+
};
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import { hasControlCharacter, isCount, isRecord, nativeMethod, utf8Length } from "./native-diagnostics-values.js";
|
|
2
|
+
import { lookupNativeModule, platformOS } from "./native-module-lookup.js";
|
|
1
3
|
import { SdkError } from "@logbrew/sdk";
|
|
2
|
-
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @import { LogBrewAndroidNativeDiagnosticsReceipt } from "./android-native-diagnostics.js"
|
|
7
|
+
* @typedef {LogBrewAndroidNativeDiagnosticsReceipt["status"]} ReceiptStatus
|
|
8
|
+
*/
|
|
3
9
|
|
|
4
10
|
const INSTALL_KEYS = new Set([
|
|
5
11
|
"anrThresholdMs",
|
|
@@ -11,36 +17,85 @@ const INSTALL_KEYS = new Set([
|
|
|
11
17
|
"service"
|
|
12
18
|
]);
|
|
13
19
|
const RECEIPT_KEYS = new Set(["pending", "status"]);
|
|
20
|
+
/** @type {ReadonlySet<string>} */
|
|
21
|
+
const INSTALL_STATUSES = new Set(["already_installed", "installed"]);
|
|
22
|
+
/** @type {ReadonlySet<string>} */
|
|
23
|
+
const STATUS_STATUSES = new Set(["not_installed", "ready"]);
|
|
24
|
+
/** @type {ReadonlySet<string>} */
|
|
25
|
+
const UNINSTALL_STATUSES = new Set(["not_installed", "uninstalled"]);
|
|
26
|
+
const PROJECT_ID_PATTERN = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/u;
|
|
27
|
+
const SCOPE_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._/-]{0,127}$/u;
|
|
28
|
+
const ERROR_CODE_PATTERN = /^[a-z0-9_]{1,128}$/u;
|
|
29
|
+
const DEFAULT_ANR_THRESHOLD_MS = 5000;
|
|
30
|
+
const MIN_ANR_THRESHOLD_MS = 2000;
|
|
31
|
+
const MAX_ANR_THRESHOLD_MS = 60_000;
|
|
32
|
+
const PROJECT_ID_BYTES = 64;
|
|
33
|
+
const CLIENT_KEY_BYTES = 4096;
|
|
34
|
+
const ENVIRONMENT_BYTES = 128;
|
|
35
|
+
const RELEASE_BYTES = 256;
|
|
36
|
+
const SCOPE_BYTES = 128;
|
|
37
|
+
const EMPTY_LENGTH = 0;
|
|
14
38
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
);
|
|
39
|
+
/**
|
|
40
|
+
* @param {string} message
|
|
41
|
+
* @returns {SdkError}
|
|
42
|
+
*/
|
|
43
|
+
function configurationError(message) {
|
|
44
|
+
return new SdkError("configuration_error", `LogBrew Android native diagnostics ${message}`);
|
|
22
45
|
}
|
|
23
46
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
47
|
+
/**
|
|
48
|
+
* @param {unknown} value
|
|
49
|
+
* @param {number} maximumBytes
|
|
50
|
+
* @param {string} name
|
|
51
|
+
* @returns {string}
|
|
52
|
+
*/
|
|
53
|
+
function exactText(value, maximumBytes, name) {
|
|
54
|
+
if (typeof value !== "string"
|
|
55
|
+
|| value.length === EMPTY_LENGTH
|
|
56
|
+
|| value.trim() !== value
|
|
57
|
+
|| hasControlCharacter(value)
|
|
58
|
+
|| utf8Length(value) > maximumBytes) {
|
|
59
|
+
throw configurationError(`${name} must be a bounded non-empty string`);
|
|
60
|
+
}
|
|
61
|
+
return value;
|
|
31
62
|
}
|
|
32
63
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
);
|
|
64
|
+
/**
|
|
65
|
+
* @param {unknown} value
|
|
66
|
+
* @param {string} name
|
|
67
|
+
* @returns {string}
|
|
68
|
+
*/
|
|
69
|
+
function exactScope(value, name) {
|
|
70
|
+
const text = exactText(value, SCOPE_BYTES, name);
|
|
71
|
+
if (!SCOPE_PATTERN.test(text)
|
|
72
|
+
|| text.includes("..")
|
|
73
|
+
|| text.includes("//")) {
|
|
74
|
+
throw configurationError(`${name} must be a bounded deployment identifier`);
|
|
75
|
+
}
|
|
76
|
+
return text;
|
|
40
77
|
}
|
|
41
78
|
|
|
42
|
-
|
|
43
|
-
|
|
79
|
+
/**
|
|
80
|
+
* @param {unknown} threshold
|
|
81
|
+
* @returns {number}
|
|
82
|
+
*/
|
|
83
|
+
function anrThreshold(threshold) {
|
|
84
|
+
if (typeof threshold !== "number"
|
|
85
|
+
|| !Number.isSafeInteger(threshold)
|
|
86
|
+
|| threshold < MIN_ANR_THRESHOLD_MS
|
|
87
|
+
|| threshold > MAX_ANR_THRESHOLD_MS) {
|
|
88
|
+
throw configurationError("anrThresholdMs must be an integer from 2000 through 60000");
|
|
89
|
+
}
|
|
90
|
+
return threshold;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {unknown} value
|
|
95
|
+
* @returns {Readonly<Record<string, unknown>>}
|
|
96
|
+
*/
|
|
97
|
+
function knownConfiguration(value) {
|
|
98
|
+
if (!isRecord(value)) {
|
|
44
99
|
throw configurationError("configuration must be an object");
|
|
45
100
|
}
|
|
46
101
|
for (const key of Object.keys(value)) {
|
|
@@ -48,53 +103,38 @@ function normalizeConfiguration(value) {
|
|
|
48
103
|
throw configurationError("configuration contains an unsupported key");
|
|
49
104
|
}
|
|
50
105
|
}
|
|
51
|
-
if (value
|
|
106
|
+
if (value["fatalHandlerOwnership"] !== "logbrew") {
|
|
52
107
|
throw configurationError(
|
|
53
108
|
"fatalHandlerOwnership must be logbrew after removing every other Android fatal handler"
|
|
54
109
|
);
|
|
55
110
|
}
|
|
56
|
-
|
|
57
|
-
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @param {unknown} configuration
|
|
116
|
+
* @returns {Record<string, unknown>}
|
|
117
|
+
*/
|
|
118
|
+
function normalizeConfiguration(configuration) {
|
|
119
|
+
const value = knownConfiguration(configuration);
|
|
120
|
+
const projectId = exactText(value["projectId"], PROJECT_ID_BYTES, "projectId");
|
|
121
|
+
if (!PROJECT_ID_PATTERN.test(projectId)) {
|
|
58
122
|
throw configurationError("projectId must be a lowercase UUID");
|
|
59
123
|
}
|
|
60
|
-
const threshold = value
|
|
61
|
-
if (!Number.isSafeInteger(threshold) || threshold < 2000 || threshold > 60000) {
|
|
62
|
-
throw configurationError("anrThresholdMs must be an integer from 2000 through 60000");
|
|
63
|
-
}
|
|
124
|
+
const threshold = anrThreshold(value["anrThresholdMs"] ?? DEFAULT_ANR_THRESHOLD_MS);
|
|
64
125
|
return {
|
|
65
126
|
anrThresholdMs: threshold,
|
|
66
|
-
clientKey: exactText(value
|
|
67
|
-
environment: exactText(value
|
|
127
|
+
clientKey: exactText(value["clientKey"], CLIENT_KEY_BYTES, "clientKey"),
|
|
128
|
+
environment: exactText(value["environment"], ENVIRONMENT_BYTES, "environment"),
|
|
68
129
|
fatalHandlerOwnership: "logbrew",
|
|
69
130
|
projectId,
|
|
70
|
-
release: exactText(value
|
|
71
|
-
service: exactScope(value
|
|
131
|
+
release: exactText(value["release"], RELEASE_BYTES, "release"),
|
|
132
|
+
service: exactScope(value["service"], "service")
|
|
72
133
|
};
|
|
73
134
|
}
|
|
74
135
|
|
|
75
|
-
function exactScope(value, name) {
|
|
76
|
-
const text = exactText(value, 128, name);
|
|
77
|
-
if (!/^[A-Za-z0-9][A-Za-z0-9._/-]{0,127}$/u.test(text)
|
|
78
|
-
|| text.includes("..")
|
|
79
|
-
|| text.includes("//")) {
|
|
80
|
-
throw configurationError(`${name} must be a bounded deployment identifier`);
|
|
81
|
-
}
|
|
82
|
-
return text;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function exactText(value, maximumBytes, name) {
|
|
86
|
-
if (typeof value !== "string"
|
|
87
|
-
|| value.length === 0
|
|
88
|
-
|| value.trim() !== value
|
|
89
|
-
|| controlCharacter(value)
|
|
90
|
-
|| utf8Length(value) > maximumBytes) {
|
|
91
|
-
throw configurationError(`${name} must be a bounded non-empty string`);
|
|
92
|
-
}
|
|
93
|
-
return value;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
136
|
function requireAndroid() {
|
|
97
|
-
if (
|
|
137
|
+
if (platformOS() !== "android") {
|
|
98
138
|
throw new SdkError(
|
|
99
139
|
"unsupported_platform",
|
|
100
140
|
"LogBrew Android native diagnostics require an Android native build"
|
|
@@ -102,22 +142,32 @@ function requireAndroid() {
|
|
|
102
142
|
}
|
|
103
143
|
}
|
|
104
144
|
|
|
105
|
-
|
|
106
|
-
|
|
145
|
+
/**
|
|
146
|
+
* @returns {unknown}
|
|
147
|
+
*/
|
|
148
|
+
function fatalStoreModule() {
|
|
107
149
|
try {
|
|
108
|
-
|
|
109
|
-
?? NativeModules?.LogBrewFatalStore;
|
|
150
|
+
return lookupNativeModule("LogBrewFatalStore");
|
|
110
151
|
} catch {
|
|
111
|
-
|
|
152
|
+
return undefined;
|
|
112
153
|
}
|
|
113
|
-
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @param {string} method
|
|
158
|
+
* @param {readonly unknown[]} args
|
|
159
|
+
* @returns {unknown}
|
|
160
|
+
*/
|
|
161
|
+
function call(method, ...args) {
|
|
162
|
+
const native = nativeMethod(fatalStoreModule(), method, args);
|
|
163
|
+
if (!native.found) {
|
|
114
164
|
throw new SdkError(
|
|
115
165
|
"native_diagnostics_unavailable",
|
|
116
166
|
`linked LogBrew Android diagnostics do not implement ${method}`
|
|
117
167
|
);
|
|
118
168
|
}
|
|
119
169
|
try {
|
|
120
|
-
return
|
|
170
|
+
return native.call();
|
|
121
171
|
} catch {
|
|
122
172
|
throw new SdkError(
|
|
123
173
|
"native_diagnostics_failed",
|
|
@@ -126,23 +176,38 @@ function call(method, ...args) {
|
|
|
126
176
|
}
|
|
127
177
|
}
|
|
128
178
|
|
|
179
|
+
/**
|
|
180
|
+
* @param {unknown} value
|
|
181
|
+
* @param {Readonly<ReadonlySet<string>>} statuses
|
|
182
|
+
* @returns {value is Readonly<{ pending: number, status: ReceiptStatus }>}
|
|
183
|
+
*/
|
|
184
|
+
function isReceipt(value, statuses) {
|
|
185
|
+
if (!isRecord(value)) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
const keys = Object.keys(value);
|
|
189
|
+
return keys.length === RECEIPT_KEYS.size
|
|
190
|
+
&& keys.every(key => RECEIPT_KEYS.has(key))
|
|
191
|
+
&& typeof value["status"] === "string"
|
|
192
|
+
&& statuses.has(value["status"])
|
|
193
|
+
&& isCount(value["pending"]);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @param {string} operation
|
|
198
|
+
* @param {unknown} value
|
|
199
|
+
* @param {Readonly<ReadonlySet<string>>} statuses
|
|
200
|
+
* @returns {LogBrewAndroidNativeDiagnosticsReceipt}
|
|
201
|
+
*/
|
|
129
202
|
function receipt(operation, value, statuses) {
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
132
|
-
&& value.status === "error"
|
|
133
|
-
&& typeof value.code === "string"
|
|
134
|
-
&& /^[a-z0-9_]{1,128}$/u.test(value.code)) {
|
|
203
|
+
const code = isRecord(value) && value["status"] === "error" ? value["code"] : undefined;
|
|
204
|
+
if (typeof code === "string" && ERROR_CODE_PATTERN.test(code)) {
|
|
135
205
|
throw new SdkError(
|
|
136
|
-
|
|
137
|
-
`LogBrew Android native diagnostics ${operation} failed with ${
|
|
206
|
+
code,
|
|
207
|
+
`LogBrew Android native diagnostics ${operation} failed with ${code}`
|
|
138
208
|
);
|
|
139
209
|
}
|
|
140
|
-
if (!
|
|
141
|
-
|| keys.length !== RECEIPT_KEYS.size
|
|
142
|
-
|| !keys.every((key) => RECEIPT_KEYS.has(key))
|
|
143
|
-
|| !statuses.has(value.status)
|
|
144
|
-
|| !Number.isSafeInteger(value.pending)
|
|
145
|
-
|| value.pending < 0) {
|
|
210
|
+
if (!isReceipt(value, statuses)) {
|
|
146
211
|
throw new SdkError(
|
|
147
212
|
"native_diagnostics_invalid_response",
|
|
148
213
|
`LogBrew Android native diagnostics ${operation} returned an invalid response`
|
|
@@ -151,26 +216,37 @@ function receipt(operation, value, statuses) {
|
|
|
151
216
|
return Object.freeze({ pending: value.pending, status: value.status });
|
|
152
217
|
}
|
|
153
218
|
|
|
154
|
-
|
|
155
|
-
|
|
219
|
+
/**
|
|
220
|
+
* @param {unknown} [configuration]
|
|
221
|
+
* @returns {LogBrewAndroidNativeDiagnosticsReceipt}
|
|
222
|
+
*/
|
|
223
|
+
function installLogBrewAndroidNativeDiagnostics(configuration = {}) {
|
|
224
|
+
requireAndroid();
|
|
225
|
+
return receipt(
|
|
226
|
+
"install",
|
|
227
|
+
call("installAndroidDiagnostics", normalizeConfiguration(configuration)),
|
|
228
|
+
INSTALL_STATUSES
|
|
229
|
+
);
|
|
156
230
|
}
|
|
157
231
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
232
|
+
/**
|
|
233
|
+
* @returns {LogBrewAndroidNativeDiagnosticsReceipt}
|
|
234
|
+
*/
|
|
235
|
+
function getLogBrewAndroidNativeDiagnosticsStatus() {
|
|
236
|
+
requireAndroid();
|
|
237
|
+
return receipt("status", call("androidDiagnosticsStatus"), STATUS_STATUSES);
|
|
163
238
|
}
|
|
164
239
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return length;
|
|
240
|
+
/**
|
|
241
|
+
* @returns {LogBrewAndroidNativeDiagnosticsReceipt}
|
|
242
|
+
*/
|
|
243
|
+
function uninstallLogBrewAndroidNativeDiagnostics() {
|
|
244
|
+
requireAndroid();
|
|
245
|
+
return receipt("uninstall", call("uninstallAndroidDiagnostics"), UNINSTALL_STATUSES);
|
|
172
246
|
}
|
|
173
247
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
248
|
+
export {
|
|
249
|
+
getLogBrewAndroidNativeDiagnosticsStatus,
|
|
250
|
+
installLogBrewAndroidNativeDiagnostics,
|
|
251
|
+
uninstallLogBrewAndroidNativeDiagnostics
|
|
252
|
+
};
|