@nagoorkani/session-capture-core 0.1.0 → 0.1.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.
- package/README.md +2 -2
- package/dist/core.d.ts +9 -1
- package/dist/core.js +9 -1
- package/dist/network.d.ts +2 -0
- package/dist/network.js +74 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @nagoorkani/session-capture-core
|
|
2
2
|
|
|
3
|
-
Everything the SDK does that is not about a platform.
|
|
4
|
-
|
|
3
|
+
Everything the SDK does that is not about a platform. Published, but not meant
|
|
4
|
+
to be installed directly — `@nagoorkani/session-capture-expo` and
|
|
5
5
|
`@nagoorkani/session-capture-vue` are the packages an application uses.
|
|
6
6
|
|
|
7
7
|
## What is in here
|
package/dist/core.d.ts
CHANGED
|
@@ -9,7 +9,15 @@ import { type CapturedError } from './errors.ts';
|
|
|
9
9
|
import type { NetworkEvent } from './network.ts';
|
|
10
10
|
import { type SessionState } from './session.ts';
|
|
11
11
|
import { type CaptureEvent, type EventBatch, type EventType, type InitOptions, type RemoteConfig } from './types.ts';
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* What every batch reports as `sdkVersion`, and what ingestion logs per batch.
|
|
14
|
+
*
|
|
15
|
+
* Core's package version, by hand, with a test that fails when the two drift.
|
|
16
|
+
* It sat at 0.1.0 through two releases, and the cost was real: a device that
|
|
17
|
+
* still showed a bug fixed in 0.1.1 could not be told apart from one that had
|
|
18
|
+
* never been updated, from the dashboard or from the logs.
|
|
19
|
+
*/
|
|
20
|
+
export declare const SDK_VERSION = "0.1.2";
|
|
13
21
|
/**
|
|
14
22
|
* Idle bound. Nothing for this long and the next event opens a new session.
|
|
15
23
|
*
|
package/dist/core.js
CHANGED
|
@@ -13,7 +13,15 @@ import { measure, timeToReady, mark } from "./performance.js";
|
|
|
13
13
|
import { redact } from "./redact.js";
|
|
14
14
|
import { SessionManager } from "./session.js";
|
|
15
15
|
import { DEFAULT_CONFIG, SCHEMA_VERSION, } from "./types.js";
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* What every batch reports as `sdkVersion`, and what ingestion logs per batch.
|
|
18
|
+
*
|
|
19
|
+
* Core's package version, by hand, with a test that fails when the two drift.
|
|
20
|
+
* It sat at 0.1.0 through two releases, and the cost was real: a device that
|
|
21
|
+
* still showed a bug fixed in 0.1.1 could not be told apart from one that had
|
|
22
|
+
* never been updated, from the dashboard or from the logs.
|
|
23
|
+
*/
|
|
24
|
+
export const SDK_VERSION = '0.1.2';
|
|
17
25
|
/**
|
|
18
26
|
* Idle bound. Nothing for this long and the next event opens a new session.
|
|
19
27
|
*
|
package/dist/network.d.ts
CHANGED
|
@@ -90,6 +90,8 @@ export interface XhrLike {
|
|
|
90
90
|
readonly status: number;
|
|
91
91
|
readonly responseType: string;
|
|
92
92
|
readonly responseText: string;
|
|
93
|
+
/** The parsed body for a non-text `responseType` — a Blob on React Native. */
|
|
94
|
+
readonly response?: unknown;
|
|
93
95
|
}
|
|
94
96
|
export interface NetworkOptions {
|
|
95
97
|
/** Requests to this origin are never captured. */
|
package/dist/network.js
CHANGED
|
@@ -195,18 +195,35 @@ function installXhrCapture(xhr, options) {
|
|
|
195
195
|
if (state.body !== undefined) {
|
|
196
196
|
event.requestBody = state.body;
|
|
197
197
|
}
|
|
198
|
+
let deferred = null;
|
|
198
199
|
if (status > 0) {
|
|
199
200
|
event.status = status;
|
|
200
201
|
const responseHeaders = parseResponseHeaders(request.getAllResponseHeaders());
|
|
201
202
|
event.responseHeaders = redactHeaders(responseHeaders, options.maskedKeys);
|
|
202
203
|
if (options.captureBodies) {
|
|
203
|
-
|
|
204
|
+
const contentType = headerValue(responseHeaders ?? {}, 'content-type');
|
|
205
|
+
deferred = readBlobBody(request, contentType);
|
|
206
|
+
if (deferred) {
|
|
207
|
+
// Reported when the read lands, the way the fetch path reports
|
|
208
|
+
// after its clone resolves. The app already has its response.
|
|
209
|
+
deferred.then((text) => {
|
|
210
|
+
event.responseBody = captureBody(text, contentType, options.maskedKeys);
|
|
211
|
+
report(options, event);
|
|
212
|
+
}, () => {
|
|
213
|
+
event.responseBody = '[not captured: blob response]';
|
|
214
|
+
report(options, event);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
event.responseBody = readResponseBody(request, contentType, options.maskedKeys);
|
|
219
|
+
}
|
|
204
220
|
}
|
|
205
221
|
}
|
|
206
222
|
else {
|
|
207
223
|
event.error = FAILURE_TEXT[state.reason ?? 'error'];
|
|
208
224
|
}
|
|
209
|
-
|
|
225
|
+
if (!deferred)
|
|
226
|
+
report(options, event);
|
|
210
227
|
}
|
|
211
228
|
catch {
|
|
212
229
|
// As above.
|
|
@@ -343,11 +360,7 @@ function cloneForReading(response) {
|
|
|
343
360
|
if (typeof response.clone !== 'function')
|
|
344
361
|
return null;
|
|
345
362
|
const headers = readHeaders(response) ?? {};
|
|
346
|
-
|
|
347
|
-
const redactable = type === 'application/json' ||
|
|
348
|
-
type.endsWith('+json') ||
|
|
349
|
-
type === 'application/x-www-form-urlencoded';
|
|
350
|
-
if (!redactable)
|
|
363
|
+
if (!isRedactable(mediaType(headerValue(headers, 'content-type'))))
|
|
351
364
|
return null;
|
|
352
365
|
const declared = Number(headerValue(headers, 'content-length'));
|
|
353
366
|
if (Number.isFinite(declared) && declared > MAX_CLONE_BYTES)
|
|
@@ -359,19 +372,66 @@ function cloneForReading(response) {
|
|
|
359
372
|
return null;
|
|
360
373
|
}
|
|
361
374
|
}
|
|
375
|
+
/** The shapes `captureBody` can walk by key. Anything else is named, not read. */
|
|
376
|
+
function isRedactable(type) {
|
|
377
|
+
return (type === 'application/json' ||
|
|
378
|
+
type.endsWith('+json') ||
|
|
379
|
+
type === 'application/x-www-form-urlencoded');
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* A promise for a blob response's text, or null when there is nothing to
|
|
383
|
+
* read that way.
|
|
384
|
+
*
|
|
385
|
+
* React Native's `fetch` is a polyfill over XHR that sets `responseType` to
|
|
386
|
+
* `'blob'`, so on a phone *every* `fetch()` response arrives here as a Blob
|
|
387
|
+
* and `responseText` throws. Reading it is an async round-trip, which is why
|
|
388
|
+
* the first version named it instead — and why every JSON response in a
|
|
389
|
+
* mobile session came back as `[not captured: blob response]`. Same rule as
|
|
390
|
+
* the fetch clone: only a type the deny-list can walk, only under the size
|
|
391
|
+
* cap, and never anything that could throw into the host.
|
|
392
|
+
*
|
|
393
|
+
* `Blob.text()` where it exists; React Native's Blob has no `text()`, but it
|
|
394
|
+
* ships a `FileReader`, and that is the path that runs on a device.
|
|
395
|
+
*/
|
|
396
|
+
function readBlobBody(request, contentType) {
|
|
397
|
+
if (request.responseType !== 'blob')
|
|
398
|
+
return null;
|
|
399
|
+
if (!isRedactable(mediaType(contentType)))
|
|
400
|
+
return null;
|
|
401
|
+
const blob = request.response;
|
|
402
|
+
if (!blob || typeof blob !== 'object')
|
|
403
|
+
return null;
|
|
404
|
+
if (typeof blob.size === 'number' && blob.size > MAX_CLONE_BYTES)
|
|
405
|
+
return null;
|
|
406
|
+
try {
|
|
407
|
+
if (typeof blob.text === 'function') {
|
|
408
|
+
return blob.text.call(blob);
|
|
409
|
+
}
|
|
410
|
+
const Reader = globalThis.FileReader;
|
|
411
|
+
if (!Reader)
|
|
412
|
+
return null;
|
|
413
|
+
return new Promise((resolve, reject) => {
|
|
414
|
+
const reader = new Reader();
|
|
415
|
+
reader.onload = () => resolve(typeof reader.result === 'string' ? reader.result : '');
|
|
416
|
+
reader.onerror = () => reject(reader.error);
|
|
417
|
+
reader.readAsText(blob);
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
catch {
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
362
424
|
function describeBody(body) {
|
|
363
425
|
const name = body?.constructor?.name;
|
|
364
426
|
return name ? name.toLowerCase() : typeof body;
|
|
365
427
|
}
|
|
366
428
|
/**
|
|
367
|
-
* Read
|
|
429
|
+
* Read a text response body synchronously.
|
|
368
430
|
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
* the event past `loadend`; that is the upgrade path if it turns out to
|
|
374
|
-
* matter.
|
|
431
|
+
* `responseText` throws unless `responseType` is `''` or `'text'`. A blob
|
|
432
|
+
* with a walkable content type has already gone through [`readBlobBody`] by
|
|
433
|
+
* the time this runs; what reaches here as a blob is one that could not be
|
|
434
|
+
* read that way, and is named rather than read.
|
|
375
435
|
*/
|
|
376
436
|
function readResponseBody(request, contentType, maskedKeys) {
|
|
377
437
|
// A host XHR that does not implement responseType at all reads as text,
|