All files / src/entities/core project-response.ts

100% Statements 19/19
100% Branches 10/10
100% Functions 3/3
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27      33x 95x 95x 20190x 20190x 20184x 20184x 20184x 20184x 20440x 20439x 20439x     95x       33x     122x    
import type { EnhancedToolDefinition } from '../../types';
 
/** Remove credentials from owned project/group JSON, including nested projects and lists. */
export function stripProjectSecrets(data: unknown): unknown {
  const pending: unknown[] = [data];
  while (pending.length > 0) {
    const value = pending.pop();
    if (value === null || typeof value !== 'object') continue;
    const record = value as Record<string, unknown>;
    delete record.runners_token;
    delete record.import_url;
    for (const key in record) {
      if (!Object.hasOwn(record, key)) continue;
      const child = record[key];
      if (child !== null && typeof child === 'object') pending.push(child);
    }
  }
  return data;
}
 
/** Filter every successful metadata result after action-specific validation and augmentation. */
export function withSafeProjectResponse(
  handler: EnhancedToolDefinition['handler'],
): EnhancedToolDefinition['handler'] {
  return async (args) => stripProjectSecrets(await handler(args));
}