@saptools/cf-inspector 0.3.7 → 0.3.9

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/dist/index.d.ts CHANGED
@@ -245,6 +245,7 @@ declare function getProperties(session: InspectorSession, objectId: string): Pro
245
245
  interface CaptureSnapshotOptions {
246
246
  readonly captures?: readonly string[];
247
247
  readonly includeScopes?: boolean;
248
+ readonly maxValueLength?: number;
248
249
  }
249
250
  declare function captureSnapshot(session: InspectorSession, pause: PauseEvent, options?: CaptureSnapshotOptions): Promise<SnapshotCaptureResult>;
250
251
 
package/dist/index.js CHANGED
@@ -923,12 +923,12 @@ async function getProperties(session, objectId) {
923
923
  }
924
924
 
925
925
  // src/snapshot.ts
926
+ init_types();
926
927
  var MAX_SCOPES = 3;
927
928
  var MAX_SCOPE_VARIABLES = 20;
928
929
  var MAX_CHILD_VARIABLES = 8;
929
930
  var MAX_VARIABLE_DEPTH = 2;
930
- var MAX_VALUE_LENGTH = 240;
931
- var SENSITIVE_NAME_REGEX = /(pass(?:word)?|credentials?|creds?|token|secret|api[_-]?key|authorization|cookie|session|private[_-]?key)/i;
931
+ var DEFAULT_MAX_VALUE_LENGTH = 4096;
932
932
  var PRIORITY_BY_TYPE = {
933
933
  local: 0,
934
934
  arguments: 1,
@@ -989,37 +989,43 @@ function formatPrimitive(value) {
989
989
  }
990
990
  return String(value);
991
991
  }
992
- function isSensitiveName(name) {
993
- return SENSITIVE_NAME_REGEX.test(name);
994
- }
995
- function sanitizeValue(name, raw) {
996
- if (isSensitiveName(name)) {
997
- return "[REDACTED]";
992
+ function resolveMaxValueLength(value) {
993
+ if (value === void 0) {
994
+ return DEFAULT_MAX_VALUE_LENGTH;
995
+ }
996
+ if (!Number.isInteger(value) || value <= 0) {
997
+ throw new CfInspectorError(
998
+ "INVALID_ARGUMENT",
999
+ `Invalid maxValueLength: ${value.toString()} \u2014 expected a positive integer`
1000
+ );
998
1001
  }
999
- if (raw.length <= MAX_VALUE_LENGTH) {
1002
+ return value;
1003
+ }
1004
+ function limitValueLength(raw, maxValueLength = DEFAULT_MAX_VALUE_LENGTH) {
1005
+ if (raw.length <= maxValueLength) {
1000
1006
  return raw;
1001
1007
  }
1002
- return `${raw.slice(0, MAX_VALUE_LENGTH)}...`;
1008
+ return `${raw.slice(0, maxValueLength)}...`;
1003
1009
  }
1004
1010
  function isExpandable(type) {
1005
1011
  return type === "object" || type === "function";
1006
1012
  }
1007
- async function captureProperties(session, objectId, limit, depth) {
1013
+ async function captureProperties(session, objectId, limit, depth, maxValueLength) {
1008
1014
  const properties = await getProperties(session, objectId);
1009
1015
  const limited = properties.slice(0, limit);
1010
1016
  const variables = await Promise.all(
1011
1017
  limited.map(async (prop) => {
1012
1018
  const name = typeof prop.name === "string" ? prop.name : "?";
1013
1019
  const described = describeProperty(prop);
1014
- const sensitive = isSensitiveName(name);
1015
1020
  let children;
1016
- if (!sensitive && depth > 0 && described.objectId !== void 0 && isExpandable(described.type)) {
1021
+ if (depth > 0 && described.objectId !== void 0 && isExpandable(described.type)) {
1017
1022
  try {
1018
1023
  const nested = await captureProperties(
1019
1024
  session,
1020
1025
  described.objectId,
1021
1026
  MAX_CHILD_VARIABLES,
1022
- depth - 1
1027
+ depth - 1,
1028
+ maxValueLength
1023
1029
  );
1024
1030
  if (nested.length > 0) {
1025
1031
  children = nested;
@@ -1027,7 +1033,7 @@ async function captureProperties(session, objectId, limit, depth) {
1027
1033
  } catch {
1028
1034
  }
1029
1035
  }
1030
- const sanitizedValue = sensitive ? "[REDACTED]" : sanitizeValue(name, described.value);
1036
+ const sanitizedValue = limitValueLength(described.value, maxValueLength);
1031
1037
  const base = { name, value: sanitizedValue };
1032
1038
  const withType = described.type === void 0 ? base : { ...base, type: described.type };
1033
1039
  return children === void 0 ? withType : { ...withType, children };
@@ -1042,7 +1048,7 @@ function selectScopes(scopeChain) {
1042
1048
  function priorityOf(type) {
1043
1049
  return PRIORITY_BY_TYPE[type] ?? Number.MAX_SAFE_INTEGER;
1044
1050
  }
1045
- async function captureScopes(session, frame) {
1051
+ async function captureScopes(session, frame, maxValueLength) {
1046
1052
  const scopes = selectScopes(frame.scopeChain);
1047
1053
  return await Promise.all(
1048
1054
  scopes.map(async (scope) => {
@@ -1051,7 +1057,13 @@ async function captureScopes(session, frame) {
1051
1057
  return { type: scope.type, variables: [] };
1052
1058
  }
1053
1059
  try {
1054
- const variables = await captureProperties(session, objectId, MAX_SCOPE_VARIABLES, MAX_VARIABLE_DEPTH);
1060
+ const variables = await captureProperties(
1061
+ session,
1062
+ objectId,
1063
+ MAX_SCOPE_VARIABLES,
1064
+ MAX_VARIABLE_DEPTH,
1065
+ maxValueLength
1066
+ );
1055
1067
  return { type: scope.type, variables };
1056
1068
  } catch {
1057
1069
  return { type: scope.type, variables: [] };
@@ -1059,10 +1071,10 @@ async function captureScopes(session, frame) {
1059
1071
  })
1060
1072
  );
1061
1073
  }
1062
- function evalResultToCaptured(expression, result) {
1074
+ function evalResultToCaptured(expression, result, maxValueLength = DEFAULT_MAX_VALUE_LENGTH) {
1063
1075
  if (result.exceptionDetails !== void 0) {
1064
1076
  const text = typeof result.exceptionDetails.exception?.description === "string" ? result.exceptionDetails.exception.description : typeof result.exceptionDetails.text === "string" ? result.exceptionDetails.text : "evaluation failed";
1065
- return { expression, error: sanitizeValue(expression, text) };
1077
+ return { expression, error: limitValueLength(text, maxValueLength) };
1066
1078
  }
1067
1079
  const inner = result.result;
1068
1080
  if (!inner) {
@@ -1070,7 +1082,7 @@ function evalResultToCaptured(expression, result) {
1070
1082
  }
1071
1083
  const type = typeof inner.type === "string" ? inner.type : void 0;
1072
1084
  const buildCaptured = (rendered) => {
1073
- const sanitized = sanitizeValue(expression, rendered);
1085
+ const sanitized = limitValueLength(rendered, maxValueLength);
1074
1086
  const base = { expression, value: sanitized };
1075
1087
  return type === void 0 ? base : { ...base, type };
1076
1088
  };
@@ -1165,9 +1177,15 @@ function toStructuredValue(variable) {
1165
1177
  }
1166
1178
  return out;
1167
1179
  }
1168
- async function renderObjectCapture(session, objectId) {
1180
+ async function renderObjectCapture(session, objectId, maxValueLength) {
1169
1181
  try {
1170
- const properties = await captureProperties(session, objectId, MAX_SCOPE_VARIABLES, MAX_VARIABLE_DEPTH);
1182
+ const properties = await captureProperties(
1183
+ session,
1184
+ objectId,
1185
+ MAX_SCOPE_VARIABLES,
1186
+ MAX_VARIABLE_DEPTH,
1187
+ maxValueLength
1188
+ );
1171
1189
  const structured = {};
1172
1190
  for (const variable of properties) {
1173
1191
  structured[variable.name] = toStructuredValue(variable);
@@ -1186,7 +1204,7 @@ function normalizeRenderedObjectCapture(rendered, original) {
1186
1204
  }
1187
1205
  return rendered;
1188
1206
  }
1189
- async function withSerializedObjectCapture(session, expression, evalResult, captured) {
1207
+ async function withSerializedObjectCapture(session, expression, evalResult, captured, maxValueLength) {
1190
1208
  if (captured.error !== void 0 || captured.value === void 0) {
1191
1209
  return captured;
1192
1210
  }
@@ -1194,7 +1212,7 @@ async function withSerializedObjectCapture(session, expression, evalResult, capt
1194
1212
  if (objectId === void 0) {
1195
1213
  return captured;
1196
1214
  }
1197
- const rendered = await renderObjectCapture(session, objectId);
1215
+ const rendered = await renderObjectCapture(session, objectId, maxValueLength);
1198
1216
  if (rendered === void 0) {
1199
1217
  return captured;
1200
1218
  }
@@ -1202,10 +1220,11 @@ async function withSerializedObjectCapture(session, expression, evalResult, capt
1202
1220
  if (normalized === void 0) {
1203
1221
  return captured;
1204
1222
  }
1205
- const value = sanitizeValue(expression, normalized);
1223
+ const value = limitValueLength(normalized, maxValueLength);
1206
1224
  return captured.type === void 0 ? { expression, value } : { expression, value, type: captured.type };
1207
1225
  }
1208
1226
  async function captureSnapshot(session, pause, options = {}) {
1227
+ const maxValueLength = resolveMaxValueLength(options.maxValueLength);
1209
1228
  const top = pause.callFrames[0];
1210
1229
  let topFrame;
1211
1230
  let captures = [];
@@ -1217,7 +1236,7 @@ async function captureSnapshot(session, pause, options = {}) {
1217
1236
  column: top.columnNumber + 1
1218
1237
  };
1219
1238
  if (options.includeScopes === true) {
1220
- const scopes = await captureScopes(session, top);
1239
+ const scopes = await captureScopes(session, top, maxValueLength);
1221
1240
  topFrame = { ...topFrame, scopes };
1222
1241
  }
1223
1242
  if (options.captures !== void 0 && options.captures.length > 0) {
@@ -1225,11 +1244,17 @@ async function captureSnapshot(session, pause, options = {}) {
1225
1244
  options.captures.map(async (expression) => {
1226
1245
  try {
1227
1246
  const result = await evaluateOnFrame(session, top.callFrameId, expression);
1228
- const captured = evalResultToCaptured(expression, result);
1229
- return await withSerializedObjectCapture(session, expression, result, captured);
1247
+ const captured = evalResultToCaptured(expression, result, maxValueLength);
1248
+ return await withSerializedObjectCapture(
1249
+ session,
1250
+ expression,
1251
+ result,
1252
+ captured,
1253
+ maxValueLength
1254
+ );
1230
1255
  } catch (err) {
1231
1256
  const message = err instanceof Error ? err.message : String(err);
1232
- return { expression, error: message };
1257
+ return { expression, error: limitValueLength(message, maxValueLength) };
1233
1258
  }
1234
1259
  })
1235
1260
  );