@nagoorkani/session-capture-expo 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 +4 -0
- package/dist/index.js +44 -9
- package/dist/index.mjs +44 -9
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -15,6 +15,10 @@ the Vue SDK and bundled in here; this package is the React Native of it —
|
|
|
15
15
|
npx expo install @nagoorkani/session-capture-expo
|
|
16
16
|
```
|
|
17
17
|
|
|
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
|
+
|
|
18
22
|
## Setup
|
|
19
23
|
|
|
20
24
|
Create a project in the dashboard to get its ID and an ingestion key. The key
|
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
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
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
|
-
|
|
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.
|
|
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",
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
"session-replay",
|
|
20
20
|
"analytics"
|
|
21
21
|
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@nagoorkani/session-capture-core": "^0.1.1"
|
|
24
|
+
},
|
|
22
25
|
"peerDependencies": {
|
|
23
26
|
"expo": ">=50",
|
|
24
27
|
"expo-file-system": "*",
|
|
@@ -28,8 +31,7 @@
|
|
|
28
31
|
"@types/node": "^22.0.0",
|
|
29
32
|
"esbuild": "^0.24.2",
|
|
30
33
|
"typescript": "^5.6.0",
|
|
31
|
-
"expo-file-system": "~57.0.2"
|
|
32
|
-
"@nagoorkani/session-capture-core": "0.1.0"
|
|
34
|
+
"expo-file-system": "~57.0.2"
|
|
33
35
|
},
|
|
34
36
|
"engines": {
|
|
35
37
|
"node": ">=18"
|