{"version":3,"file":"impl-0Wi7NRgY.mjs","names":[],"sources":["../src/lib/code-scanning/findFilesToScan.ts","../src/commands/inventory/discover-silos/impl.ts"],"sourcesContent":["import fastGlob from 'fast-glob';\n\nimport { logger } from '../../logger.js';\nimport { CodeScanningConfig } from './types.js';\n\nexport interface SiloDiscoveryRawResults {\n  /** The name of the potential data silo entry */\n  name: string;\n  /** A unique UUID (represents the same resource across different silo discovery runs) */\n  resourceId: string;\n  /** Any hosts associated with the entry */\n  host?: string;\n  /** Type of data silo */\n  type?: string | undefined;\n}\n\n/**\n * Helper to scan for data silos in all package.json files that it can find in a directory\n *\n * @deprecated TODO: https://transcend.height.app/T-32325 - use code scanning instead\n * @param options - Options\n * @returns the list of integrations\n */\nexport async function findFilesToScan({\n  scanPath,\n  fileGlobs,\n  ignoreDirs,\n  config,\n}: {\n  /** Where to look for package.json files */\n  scanPath: string;\n  /** Globs to look for */\n  fileGlobs: string;\n  /** The directories to ignore (excludes node_modules and serverless-build) */\n  ignoreDirs: string;\n  /** Silo Discovery configuration */\n  config: CodeScanningConfig;\n}): Promise<SiloDiscoveryRawResults[]> {\n  const { ignoreDirs: IGNORE_DIRS, supportedFiles, scanFunction } = config;\n  const globsToSupport =\n    fileGlobs === '' ? supportedFiles : supportedFiles.concat(fileGlobs.split(','));\n  const dirsToIgnore = [...ignoreDirs.split(','), ...IGNORE_DIRS].filter((dir) => dir.length > 0);\n  try {\n    const filesToScan: string[] = await fastGlob(`${scanPath}/**/${globsToSupport.join('|')}`, {\n      ignore: dirsToIgnore.map((dir: string) => `${scanPath}/**/${dir}`),\n      unique: true,\n      onlyFiles: true,\n    });\n    logger.info(`Scanning: ${filesToScan.length} files`);\n    const allPackages = filesToScan.map((filePath: string) => scanFunction(filePath)).flat();\n    const allSdks = allPackages\n      .map((appPackage) => appPackage.softwareDevelopmentKits || [])\n      .flat();\n    const uniqueDeps = new Set(allSdks.map((sdk) => sdk.name));\n    const deps = [...uniqueDeps];\n    logger.info(`Found: ${deps.length} unique dependencies`);\n    return deps.map((dep) => ({\n      name: dep,\n      resourceId: `${scanPath}/**/${dep}`,\n      useStrictClassifier: true,\n    }));\n  } catch (error) {\n    throw new Error(`Error scanning globs ${findFilesToScan} with error: ${error}`);\n  }\n}\n","import {\n  buildTranscendGraphQLClient,\n  fetchActiveSiloDiscoPlugin,\n  uploadSiloDiscoveryResults,\n} from '@transcend-io/sdk';\nimport colors from 'colors';\nimport { stringify } from 'query-string';\n\nimport { ADMIN_DASH } from '../../../constants.js';\nimport type { LocalContext } from '../../../context.js';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation.js';\nimport { findFilesToScan } from '../../../lib/code-scanning/findFilesToScan.js';\nimport { SILO_DISCOVERY_CONFIGS } from '../../../lib/code-scanning/index.js';\nimport { logger } from '../../../logger.js';\n\nexport interface DiscoverSilosCommandFlags {\n  scanPath: string;\n  dataSiloId: string;\n  auth: string;\n  fileGlobs: string;\n  ignoreDirs: string;\n  transcendUrl: string;\n}\n\nexport async function discoverSilos(\n  this: LocalContext,\n  { scanPath, dataSiloId, auth, fileGlobs, ignoreDirs, transcendUrl }: DiscoverSilosCommandFlags,\n): Promise<void> {\n  doneInputValidation(this.process.exit);\n\n  // Create a GraphQL client\n  const client = buildTranscendGraphQLClient(transcendUrl, auth);\n\n  const plugin = await fetchActiveSiloDiscoPlugin(client, {\n    logger,\n    filterBy: { dataSiloId },\n  });\n\n  const config = SILO_DISCOVERY_CONFIGS[plugin.dataSilo.type];\n  if (!config) {\n    logger.error(\n      colors.red(\n        `This plugin \"${plugin.dataSilo.type}\" is not supported for offline silo discovery.`,\n      ),\n    );\n    this.process.exit(1);\n  }\n\n  const results = await findFilesToScan({\n    scanPath,\n    fileGlobs,\n    ignoreDirs,\n    config,\n  });\n\n  await uploadSiloDiscoveryResults(client, {\n    pluginId: plugin.id,\n    results,\n    logger,\n  });\n\n  const newUrl = new URL(ADMIN_DASH);\n  newUrl.pathname = '/data-map/data-inventory/silo-discovery/triage';\n  newUrl.search = stringify({\n    filters: JSON.stringify({ pluginIds: [plugin.id] }),\n  });\n\n  // Indicate success\n  logger.info(\n    colors.green(\n      `Scan found ${results.length} potential data silos at ${scanPath}! ` +\n        `View at '${newUrl.href}' ` +\n        '\\n\\n NOTE: it may take 2-3 minutes for scan results to appear in the UI.',\n    ),\n  );\n}\n"],"mappings":"gZAuBA,eAAsB,EAAgB,CACpC,WACA,YACA,aACA,UAUqC,CACrC,GAAM,CAAE,WAAY,EAAa,iBAAgB,gBAAiB,EAC5D,EACJ,IAAc,GAAK,EAAiB,EAAe,OAAO,EAAU,MAAM,IAAI,CAAC,CAC3E,EAAe,CAAC,GAAG,EAAW,MAAM,IAAI,CAAE,GAAG,EAAY,CAAC,OAAQ,GAAQ,EAAI,OAAS,EAAE,CAC/F,GAAI,CACF,IAAM,EAAwB,MAAM,EAAS,GAAG,EAAS,MAAM,EAAe,KAAK,IAAI,GAAI,CACzF,OAAQ,EAAa,IAAK,GAAgB,GAAG,EAAS,MAAM,IAAM,CAClE,OAAQ,GACR,UAAW,GACZ,CAAC,CACF,EAAO,KAAK,aAAa,EAAY,OAAO,QAAQ,CAEpD,IAAM,EADc,EAAY,IAAK,GAAqB,EAAa,EAAS,CAAC,CAAC,MACvD,CACxB,IAAK,GAAe,EAAW,yBAA2B,EAAE,CAAC,CAC7D,MAAM,CAEH,EAAO,CAAC,GAAG,IADM,IAAI,EAAQ,IAAK,GAAQ,EAAI,KAAK,CAC9B,CAAC,CAE5B,OADA,EAAO,KAAK,UAAU,EAAK,OAAO,sBAAsB,CACjD,EAAK,IAAK,IAAS,CACxB,KAAM,EACN,WAAY,GAAG,EAAS,MAAM,IAC9B,oBAAqB,GACtB,EAAE,OACI,EAAO,CACd,MAAU,MAAM,wBAAwB,EAAgB,eAAe,IAAQ,ECtCnF,eAAsB,EAEpB,CAAE,WAAU,aAAY,OAAM,YAAW,aAAY,gBACtC,CACf,EAAoB,KAAK,QAAQ,KAAK,CAGtC,IAAM,EAAS,EAA4B,EA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