@nagoorkani/session-capture-expo 0.1.1 → 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 CHANGED
@@ -12,12 +12,12 @@ the Vue SDK and bundled in here; this package is the React Native of it —
12
12
  ## Install
13
13
 
14
14
  ```bash
15
- npx expo install @nagoorkani/session-capture-expo @nagoorkani/session-capture-core
15
+ npx expo install @nagoorkani/session-capture-expo
16
16
  ```
17
17
 
18
- `-core` is bundled into this package, so nothing of it runs from the second
19
- install. It is there for its type declarations: `-expo` re-exports types from
20
- it, and without it those read as `any`.
18
+ This also installs `@nagoorkani/session-capture-core`. None of it runs from
19
+ there — it is bundled into this package — but the types this package
20
+ re-exports come from it.
21
21
 
22
22
  ## Setup
23
23
 
package/dist/index.js CHANGED
@@ -1130,21 +1130,33 @@ function installXhrCapture(xhr, options) {
1130
1130
  if (state.body !== void 0) {
1131
1131
  event.requestBody = state.body;
1132
1132
  }
1133
+ let deferred = null;
1133
1134
  if (status > 0) {
1134
1135
  event.status = status;
1135
1136
  const responseHeaders = parseResponseHeaders(request.getAllResponseHeaders());
1136
1137
  event.responseHeaders = redactHeaders(responseHeaders, options.maskedKeys);
1137
1138
  if (options.captureBodies) {
1138
- event.responseBody = readResponseBody(
1139
- request,
1140
- headerValue(responseHeaders ?? {}, "content-type"),
1141
- options.maskedKeys
1142
- );
1139
+ const contentType = headerValue(responseHeaders ?? {}, "content-type");
1140
+ deferred = readBlobBody(request, contentType);
1141
+ if (deferred) {
1142
+ deferred.then(
1143
+ (text) => {
1144
+ event.responseBody = captureBody(text, contentType, options.maskedKeys);
1145
+ report(options, event);
1146
+ },
1147
+ () => {
1148
+ event.responseBody = "[not captured: blob response]";
1149
+ report(options, event);
1150
+ }
1151
+ );
1152
+ } else {
1153
+ event.responseBody = readResponseBody(request, contentType, options.maskedKeys);
1154
+ }
1143
1155
  }
1144
1156
  } else {
1145
1157
  event.error = FAILURE_TEXT[state.reason ?? "error"];
1146
1158
  }
1147
- report(options, event);
1159
+ if (!deferred) report(options, event);
1148
1160
  } catch {
1149
1161
  }
1150
1162
  }
@@ -1227,9 +1239,7 @@ var MAX_CLONE_BYTES = 256 * 1024;
1227
1239
  function cloneForReading(response) {
1228
1240
  if (typeof response.clone !== "function") return null;
1229
1241
  const headers = readHeaders(response) ?? {};
1230
- const type = mediaType(headerValue(headers, "content-type"));
1231
- const redactable = type === "application/json" || type.endsWith("+json") || type === "application/x-www-form-urlencoded";
1232
- if (!redactable) return null;
1242
+ if (!isRedactable(mediaType(headerValue(headers, "content-type")))) return null;
1233
1243
  const declared = Number(headerValue(headers, "content-length"));
1234
1244
  if (Number.isFinite(declared) && declared > MAX_CLONE_BYTES) return null;
1235
1245
  try {
@@ -1238,6 +1248,31 @@ function cloneForReading(response) {
1238
1248
  return null;
1239
1249
  }
1240
1250
  }
1251
+ function isRedactable(type) {
1252
+ return type === "application/json" || type.endsWith("+json") || type === "application/x-www-form-urlencoded";
1253
+ }
1254
+ function readBlobBody(request, contentType) {
1255
+ if (request.responseType !== "blob") return null;
1256
+ if (!isRedactable(mediaType(contentType))) return null;
1257
+ const blob = request.response;
1258
+ if (!blob || typeof blob !== "object") return null;
1259
+ if (typeof blob.size === "number" && blob.size > MAX_CLONE_BYTES) return null;
1260
+ try {
1261
+ if (typeof blob.text === "function") {
1262
+ return blob.text.call(blob);
1263
+ }
1264
+ const Reader = globalThis.FileReader;
1265
+ if (!Reader) return null;
1266
+ return new Promise((resolve, reject) => {
1267
+ const reader = new Reader();
1268
+ reader.onload = () => resolve(typeof reader.result === "string" ? reader.result : "");
1269
+ reader.onerror = () => reject(reader.error);
1270
+ reader.readAsText(blob);
1271
+ });
1272
+ } catch {
1273
+ return null;
1274
+ }
1275
+ }
1241
1276
  function describeBody(body) {
1242
1277
  const name = body?.constructor?.name;
1243
1278
  return name ? name.toLowerCase() : typeof body;
package/dist/index.mjs CHANGED
@@ -1078,21 +1078,33 @@ function installXhrCapture(xhr, options) {
1078
1078
  if (state.body !== void 0) {
1079
1079
  event.requestBody = state.body;
1080
1080
  }
1081
+ let deferred = null;
1081
1082
  if (status > 0) {
1082
1083
  event.status = status;
1083
1084
  const responseHeaders = parseResponseHeaders(request.getAllResponseHeaders());
1084
1085
  event.responseHeaders = redactHeaders(responseHeaders, options.maskedKeys);
1085
1086
  if (options.captureBodies) {
1086
- event.responseBody = readResponseBody(
1087
- request,
1088
- headerValue(responseHeaders ?? {}, "content-type"),
1089
- options.maskedKeys
1090
- );
1087
+ const contentType = headerValue(responseHeaders ?? {}, "content-type");
1088
+ deferred = readBlobBody(request, contentType);
1089
+ if (deferred) {
1090
+ deferred.then(
1091
+ (text) => {
1092
+ event.responseBody = captureBody(text, contentType, options.maskedKeys);
1093
+ report(options, event);
1094
+ },
1095
+ () => {
1096
+ event.responseBody = "[not captured: blob response]";
1097
+ report(options, event);
1098
+ }
1099
+ );
1100
+ } else {
1101
+ event.responseBody = readResponseBody(request, contentType, options.maskedKeys);
1102
+ }
1091
1103
  }
1092
1104
  } else {
1093
1105
  event.error = FAILURE_TEXT[state.reason ?? "error"];
1094
1106
  }
1095
- report(options, event);
1107
+ if (!deferred) report(options, event);
1096
1108
  } catch {
1097
1109
  }
1098
1110
  }
@@ -1175,9 +1187,7 @@ var MAX_CLONE_BYTES = 256 * 1024;
1175
1187
  function cloneForReading(response) {
1176
1188
  if (typeof response.clone !== "function") return null;
1177
1189
  const headers = readHeaders(response) ?? {};
1178
- const type = mediaType(headerValue(headers, "content-type"));
1179
- const redactable = type === "application/json" || type.endsWith("+json") || type === "application/x-www-form-urlencoded";
1180
- if (!redactable) return null;
1190
+ if (!isRedactable(mediaType(headerValue(headers, "content-type")))) return null;
1181
1191
  const declared = Number(headerValue(headers, "content-length"));
1182
1192
  if (Number.isFinite(declared) && declared > MAX_CLONE_BYTES) return null;
1183
1193
  try {
@@ -1186,6 +1196,31 @@ function cloneForReading(response) {
1186
1196
  return null;
1187
1197
  }
1188
1198
  }
1199
+ function isRedactable(type) {
1200
+ return type === "application/json" || type.endsWith("+json") || type === "application/x-www-form-urlencoded";
1201
+ }
1202
+ function readBlobBody(request, contentType) {
1203
+ if (request.responseType !== "blob") return null;
1204
+ if (!isRedactable(mediaType(contentType))) return null;
1205
+ const blob = request.response;
1206
+ if (!blob || typeof blob !== "object") return null;
1207
+ if (typeof blob.size === "number" && blob.size > MAX_CLONE_BYTES) return null;
1208
+ try {
1209
+ if (typeof blob.text === "function") {
1210
+ return blob.text.call(blob);
1211
+ }
1212
+ const Reader = globalThis.FileReader;
1213
+ if (!Reader) return null;
1214
+ return new Promise((resolve, reject) => {
1215
+ const reader = new Reader();
1216
+ reader.onload = () => resolve(typeof reader.result === "string" ? reader.result : "");
1217
+ reader.onerror = () => reject(reader.error);
1218
+ reader.readAsText(blob);
1219
+ });
1220
+ } catch {
1221
+ return null;
1222
+ }
1223
+ }
1189
1224
  function describeBody(body) {
1190
1225
  const name = body?.constructor?.name;
1191
1226
  return name ? name.toLowerCase() : typeof body;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nagoorkani/session-capture-expo",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Lightweight session capture and observability for Expo / React Native",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/index.js",
@@ -20,7 +20,7 @@
20
20
  "analytics"
21
21
  ],
22
22
  "dependencies": {
23
- "@nagoorkani/session-capture-core": "^0.1.0"
23
+ "@nagoorkani/session-capture-core": "^0.1.1"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "expo": ">=50",