@logbrew/react-native 0.1.39 → 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/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 -1243
- 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/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 +43 -1
- 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
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
const { SdkError, TransportError } = require("@logbrew/sdk");
|
|
2
|
+
const { readField, textOf } = require("./index-values.cjs");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {{ readonly get: (name: string) => unknown }} HeadersLike
|
|
6
|
+
* @typedef {(endpoint: string, init: Readonly<Record<string, unknown>>) => unknown} FetchLike
|
|
7
|
+
* @typedef {{
|
|
8
|
+
* readonly endpoint?: unknown,
|
|
9
|
+
* readonly fetchImpl?: unknown,
|
|
10
|
+
* readonly headers?: unknown
|
|
11
|
+
* }} FetchTransportConfig
|
|
12
|
+
* @typedef {{
|
|
13
|
+
* statusCode: unknown,
|
|
14
|
+
* attempts: number,
|
|
15
|
+
* retryAfterMs?: number,
|
|
16
|
+
* errorCode?: string
|
|
17
|
+
* }} FetchTransportResponse
|
|
18
|
+
* @typedef {{ readonly send: (apiKey: string, body: string) => Promise<FetchTransportResponse> }} FetchTransport
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const DEFAULT_ENDPOINT = "https://api.logbrew.co/v1/events";
|
|
22
|
+
const RATE_LIMIT_BODY_LIMIT_BYTES = 4096;
|
|
23
|
+
const TOO_MANY_REQUESTS = 429;
|
|
24
|
+
const MS_PER_SECOND = 1000;
|
|
25
|
+
const NO_WAIT = 0;
|
|
26
|
+
const SINGLE_ATTEMPT = 1;
|
|
27
|
+
const RETRY_AFTER_SECONDS_RE = /^\d+$/u;
|
|
28
|
+
const HTTP_DATE_RE = /^[A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT$/u;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {unknown} value
|
|
32
|
+
* @returns {value is FetchLike}
|
|
33
|
+
*/
|
|
34
|
+
function isFetchLike(value) {
|
|
35
|
+
return typeof value === "function";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {unknown} value
|
|
40
|
+
* @returns {value is HeadersLike}
|
|
41
|
+
*/
|
|
42
|
+
function isHeadersLike(value) {
|
|
43
|
+
return typeof readField(value, "get") === "function";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param {unknown} value
|
|
48
|
+
* @returns {value is { readonly text: () => unknown }}
|
|
49
|
+
*/
|
|
50
|
+
function hasText(value) {
|
|
51
|
+
return typeof readField(value, "text") === "function";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @returns {FetchLike | undefined}
|
|
56
|
+
*/
|
|
57
|
+
function defaultFetch() {
|
|
58
|
+
return typeof globalThis.fetch === "function" ? globalThis.fetch.bind(globalThis) : undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {string} endpoint
|
|
63
|
+
* @returns {URL}
|
|
64
|
+
*/
|
|
65
|
+
function parseEndpointUrl(endpoint) {
|
|
66
|
+
try {
|
|
67
|
+
return new URL(endpoint);
|
|
68
|
+
} catch {
|
|
69
|
+
throw new SdkError("configuration_error", "createReactNativeFetchTransport endpoint must be an absolute URL");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @param {unknown} endpoint
|
|
75
|
+
* @returns {asserts endpoint is string}
|
|
76
|
+
*/
|
|
77
|
+
function validateDeliveryEndpoint(endpoint) {
|
|
78
|
+
if (typeof endpoint !== "string" || endpoint.trim() === "") {
|
|
79
|
+
throw new SdkError("configuration_error", "createReactNativeFetchTransport requires a non-empty endpoint");
|
|
80
|
+
}
|
|
81
|
+
const parsed = parseEndpointUrl(endpoint);
|
|
82
|
+
if (parsed.protocol !== "https:") {
|
|
83
|
+
throw new SdkError("configuration_error", "createReactNativeFetchTransport endpoint must use HTTPS");
|
|
84
|
+
}
|
|
85
|
+
if (endpoint !== `${parsed.origin}${parsed.pathname}`) {
|
|
86
|
+
throw new SdkError("configuration_error", "createReactNativeFetchTransport endpoint must be a plain HTTPS path");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param {unknown} value
|
|
92
|
+
* @param {number} [now]
|
|
93
|
+
* @returns {number | undefined}
|
|
94
|
+
*/
|
|
95
|
+
function retryAfterMsFromHeader(value, now = Date.now()) {
|
|
96
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
const trimmed = value.trim();
|
|
100
|
+
if (RETRY_AFTER_SECONDS_RE.test(trimmed)) {
|
|
101
|
+
const milliseconds = Number(trimmed) * MS_PER_SECOND;
|
|
102
|
+
return Number.isSafeInteger(milliseconds) ? milliseconds : undefined;
|
|
103
|
+
}
|
|
104
|
+
const timestamp = HTTP_DATE_RE.test(trimmed) ? Date.parse(trimmed) : Number.NaN;
|
|
105
|
+
return Number.isFinite(timestamp) ? Math.max(NO_WAIT, timestamp - now) : undefined;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @param {unknown} headers
|
|
110
|
+
* @returns {number | undefined}
|
|
111
|
+
*/
|
|
112
|
+
function retryAfterMsFromHeaders(headers) {
|
|
113
|
+
if (!isHeadersLike(headers)) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
return retryAfterMsFromHeader(headers.get("retry-after"));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @param {unknown} response
|
|
121
|
+
* @returns {number}
|
|
122
|
+
*/
|
|
123
|
+
function declaredContentLength(response) {
|
|
124
|
+
const headers = readField(response, "headers");
|
|
125
|
+
return Number(isHeadersLike(headers) ? headers.get("content-length") : undefined);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @param {unknown} text
|
|
130
|
+
* @returns {unknown}
|
|
131
|
+
*/
|
|
132
|
+
function rateLimitBodyCode(text) {
|
|
133
|
+
const textLength = typeof text === "string" ? text.length : readField(text, "length");
|
|
134
|
+
/** @type {unknown} */
|
|
135
|
+
const parsed = Number(textLength) <= RATE_LIMIT_BODY_LIMIT_BYTES ? JSON.parse(textOf(text)) : undefined;
|
|
136
|
+
return readField(parsed, "code");
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @param {unknown} response
|
|
141
|
+
* @returns {Promise<string | undefined>}
|
|
142
|
+
*/
|
|
143
|
+
async function rateLimitCode(response) {
|
|
144
|
+
try {
|
|
145
|
+
const length = declaredContentLength(response);
|
|
146
|
+
if (!Number.isSafeInteger(length) || length > RATE_LIMIT_BODY_LIMIT_BYTES || !hasText(response)) {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
const code = rateLimitBodyCode(await response.text());
|
|
150
|
+
return code === "rate_limited" || code === "usage_limit_exceeded" ? code : undefined;
|
|
151
|
+
} catch {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @param {FetchTransportConfig} [config]
|
|
158
|
+
* @returns {FetchTransport}
|
|
159
|
+
*/
|
|
160
|
+
function createReactNativeFetchTransport({
|
|
161
|
+
endpoint = DEFAULT_ENDPOINT,
|
|
162
|
+
fetchImpl = defaultFetch(),
|
|
163
|
+
headers = {}
|
|
164
|
+
} = {}) {
|
|
165
|
+
validateDeliveryEndpoint(endpoint);
|
|
166
|
+
if (!isFetchLike(fetchImpl)) {
|
|
167
|
+
throw new SdkError("configuration_error", "createReactNativeFetchTransport requires fetch");
|
|
168
|
+
}
|
|
169
|
+
if (headers === null || Array.isArray(headers) || typeof headers !== "object") {
|
|
170
|
+
throw new SdkError("configuration_error", "createReactNativeFetchTransport headers must be an object");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return Object.freeze({
|
|
174
|
+
async send(apiKey, body) {
|
|
175
|
+
try {
|
|
176
|
+
const response = await fetchImpl(endpoint, {
|
|
177
|
+
body,
|
|
178
|
+
headers: {
|
|
179
|
+
...headers,
|
|
180
|
+
authorization: `Bearer ${apiKey}`,
|
|
181
|
+
"content-type": "application/json"
|
|
182
|
+
},
|
|
183
|
+
method: "POST"
|
|
184
|
+
});
|
|
185
|
+
const retryAfterMs = retryAfterMsFromHeaders(readField(response, "headers"));
|
|
186
|
+
const errorCode = readField(response, "status") === TOO_MANY_REQUESTS ? await rateLimitCode(response) : undefined;
|
|
187
|
+
return {
|
|
188
|
+
statusCode: readField(response, "status"),
|
|
189
|
+
|
|
190
|
+
attempts: SINGLE_ATTEMPT,
|
|
191
|
+
...(retryAfterMs === undefined ? {} : { retryAfterMs }),
|
|
192
|
+
...(errorCode === undefined ? {} : { errorCode })
|
|
193
|
+
};
|
|
194
|
+
} catch {
|
|
195
|
+
throw TransportError.network("LogBrew React Native delivery failed");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
module.exports = { createReactNativeFetchTransport, defaultFetch };
|
package/index-values.cjs
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
const { SdkError } = require("@logbrew/sdk");
|
|
2
|
+
const { NULL_VALUE } = require("./null-value.cjs");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @import { Metadata, MetadataValue } from "@logbrew/sdk"
|
|
6
|
+
* @typedef {Readonly<Record<string, unknown>>} LooseRecord
|
|
7
|
+
* @typedef {{
|
|
8
|
+
* readonly OS?: unknown,
|
|
9
|
+
* readonly Version?: unknown,
|
|
10
|
+
* readonly isPad?: unknown,
|
|
11
|
+
* readonly constants?: { readonly isTesting?: unknown } | null | undefined
|
|
12
|
+
* }} PlatformLike
|
|
13
|
+
* @typedef {{
|
|
14
|
+
* readonly currentState?: unknown,
|
|
15
|
+
* readonly addEventListener?: unknown
|
|
16
|
+
* }} AppStateLike
|
|
17
|
+
* @typedef {{
|
|
18
|
+
* readonly traceId: string,
|
|
19
|
+
* readonly spanId: string,
|
|
20
|
+
* readonly parentSpanId: string | undefined,
|
|
21
|
+
* readonly traceFlags: string,
|
|
22
|
+
* readonly sampled: boolean
|
|
23
|
+
* }} TraceContext
|
|
24
|
+
* @typedef {{
|
|
25
|
+
* readonly traceId?: unknown,
|
|
26
|
+
* readonly spanId?: unknown,
|
|
27
|
+
* readonly parentSpanId?: unknown,
|
|
28
|
+
* readonly traceFlags?: unknown,
|
|
29
|
+
* readonly sampled?: unknown
|
|
30
|
+
* }} TraceObjectInput
|
|
31
|
+
* @typedef {TraceObjectInput | string | null | undefined} TraceInput
|
|
32
|
+
* @typedef {{
|
|
33
|
+
* readonly platform?: PlatformLike | null | undefined,
|
|
34
|
+
* readonly appState?: AppStateLike | null | undefined,
|
|
35
|
+
* readonly metadata?: LooseRecord | undefined
|
|
36
|
+
* }} ContextOptions
|
|
37
|
+
* @typedef {(id: string, timestamp: string, attributes: LooseRecord) => unknown} ClientEventMethod
|
|
38
|
+
* @typedef {{
|
|
39
|
+
* readonly action: ClientEventMethod,
|
|
40
|
+
* readonly span: ClientEventMethod,
|
|
41
|
+
* readonly issue: ClientEventMethod,
|
|
42
|
+
* readonly log: ClientEventMethod,
|
|
43
|
+
* readonly release: ClientEventMethod,
|
|
44
|
+
* readonly environment: ClientEventMethod,
|
|
45
|
+
* readonly flush: () => Promise<unknown>,
|
|
46
|
+
* readonly shutdown: () => Promise<unknown>,
|
|
47
|
+
* readonly deliveryHealth: () => unknown,
|
|
48
|
+
* readonly droppedEvents: () => unknown,
|
|
49
|
+
* readonly pendingBytes: () => unknown,
|
|
50
|
+
* readonly previewJson: () => unknown,
|
|
51
|
+
* readonly pendingEvents: () => unknown,
|
|
52
|
+
* readonly addBreadcrumb?: unknown
|
|
53
|
+
* }} ClientLike
|
|
54
|
+
* @typedef {(() => void) | { readonly remove?: unknown } | null | undefined} SubscriptionLike
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
const FIRST = 0;
|
|
58
|
+
const LIMIT_ONE = 1;
|
|
59
|
+
const MIN_FAILURE_STATUS = 400;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {unknown} value
|
|
63
|
+
* @returns {value is null | undefined}
|
|
64
|
+
*/
|
|
65
|
+
function isNullish(value) {
|
|
66
|
+
return value === undefined || value === null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {unknown} value
|
|
71
|
+
* @returns {string}
|
|
72
|
+
*/
|
|
73
|
+
function textOf(value) {
|
|
74
|
+
return typeof value === "string" ? value : String(value);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @param {unknown} value
|
|
79
|
+
* @returns {value is MetadataValue}
|
|
80
|
+
*/
|
|
81
|
+
function isMetadataValue(value) {
|
|
82
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @param {unknown} value
|
|
87
|
+
* @param {PropertyKey} key
|
|
88
|
+
* @returns {unknown}
|
|
89
|
+
*/
|
|
90
|
+
function readField(value, key) {
|
|
91
|
+
return (typeof value === "object" && value !== null) || typeof value === "function" ? Reflect.get(value, key) : undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @param {unknown} client
|
|
96
|
+
* @returns {void}
|
|
97
|
+
*/
|
|
98
|
+
function requireClient(client) {
|
|
99
|
+
const present = Boolean(client);
|
|
100
|
+
if (!present) {
|
|
101
|
+
throw new SdkError("configuration_error", "LogBrew React Native helpers require a client");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @param {string} label
|
|
107
|
+
* @param {unknown} value
|
|
108
|
+
* @returns {void}
|
|
109
|
+
*/
|
|
110
|
+
function requireNonEmpty(label, value) {
|
|
111
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
112
|
+
throw new SdkError("validation_error", `${label} must be non-empty`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @param {unknown} value
|
|
118
|
+
* @returns {MetadataValue}
|
|
119
|
+
*/
|
|
120
|
+
function normalizeMetadataValue(value) {
|
|
121
|
+
if (value === undefined) {
|
|
122
|
+
return NULL_VALUE;
|
|
123
|
+
}
|
|
124
|
+
return isMetadataValue(value) ? value : textOf(value);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @param {LooseRecord} metadata
|
|
129
|
+
* @returns {Metadata}
|
|
130
|
+
*/
|
|
131
|
+
function compactMetadata(metadata) {
|
|
132
|
+
/** @type {Metadata} */
|
|
133
|
+
const compacted = {};
|
|
134
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
135
|
+
if (isMetadataValue(value)) {
|
|
136
|
+
compacted[key] = value;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return compacted;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @param {unknown} value
|
|
144
|
+
* @returns {string | undefined}
|
|
145
|
+
*/
|
|
146
|
+
function stripQueryAndHash(value) {
|
|
147
|
+
return isNullish(value) ? undefined : textOf(value).split(/[?#]/u, LIMIT_ONE)[FIRST];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @param {unknown} statusCode
|
|
152
|
+
* @returns {"failure" | "success"}
|
|
153
|
+
*/
|
|
154
|
+
function statusFromStatusCode(statusCode) {
|
|
155
|
+
if (typeof statusCode === "number" && Number.isFinite(statusCode) && statusCode >= MIN_FAILURE_STATUS) {
|
|
156
|
+
return "failure";
|
|
157
|
+
}
|
|
158
|
+
return "success";
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @param {unknown} statusCode
|
|
163
|
+
* @returns {"error" | "ok"}
|
|
164
|
+
*/
|
|
165
|
+
function spanStatusFromStatusCode(statusCode) {
|
|
166
|
+
if (typeof statusCode === "number" && Number.isFinite(statusCode) && statusCode >= MIN_FAILURE_STATUS) {
|
|
167
|
+
return "error";
|
|
168
|
+
}
|
|
169
|
+
return "ok";
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @param {ContextOptions} [options]
|
|
174
|
+
* @returns {Record<string, unknown>}
|
|
175
|
+
*/
|
|
176
|
+
function getReactNativeContext({ platform, appState, metadata = {} } = {}) {
|
|
177
|
+
return {
|
|
178
|
+
platform: platform?.OS ?? "unknown",
|
|
179
|
+
platformVersion: normalizeMetadataValue(platform?.Version),
|
|
180
|
+
|
|
181
|
+
appState: normalizeMetadataValue(appState?.currentState),
|
|
182
|
+
isPad: normalizeMetadataValue(platform?.isPad),
|
|
183
|
+
isTesting: normalizeMetadataValue(platform?.constants?.isTesting),
|
|
184
|
+
...metadata
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @param {unknown} value
|
|
190
|
+
* @returns {value is () => unknown}
|
|
191
|
+
*/
|
|
192
|
+
function isRemover(value) {
|
|
193
|
+
return typeof value === "function";
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @param {unknown} value
|
|
198
|
+
* @returns {value is { readonly remove: () => unknown }}
|
|
199
|
+
*/
|
|
200
|
+
function hasRemove(value) {
|
|
201
|
+
return typeof readField(value, "remove") === "function";
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @param {unknown} subscription
|
|
206
|
+
* @returns {() => unknown}
|
|
207
|
+
*/
|
|
208
|
+
function subscriptionRemover(subscription) {
|
|
209
|
+
if (isRemover(subscription)) {
|
|
210
|
+
return subscription;
|
|
211
|
+
}
|
|
212
|
+
if (hasRemove(subscription)) {
|
|
213
|
+
return () => subscription.remove();
|
|
214
|
+
}
|
|
215
|
+
return () => undefined;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
module.exports = {
|
|
219
|
+
compactMetadata,
|
|
220
|
+
getReactNativeContext,
|
|
221
|
+
isMetadataValue,
|
|
222
|
+
isNullish,
|
|
223
|
+
normalizeMetadataValue,
|
|
224
|
+
readField,
|
|
225
|
+
requireClient,
|
|
226
|
+
requireNonEmpty,
|
|
227
|
+
spanStatusFromStatusCode,
|
|
228
|
+
statusFromStatusCode,
|
|
229
|
+
stripQueryAndHash,
|
|
230
|
+
subscriptionRemover,
|
|
231
|
+
textOf
|
|
232
|
+
};
|