EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
programServices.js
Go to the documentation of this file.
1/**
2 * @file Installed Programs Data Access Service
3 * @description
4 * Provides database query functions for retrieving installed software inventory from
5 * remote agents. This module serves as the data access layer for the agent_programs table,
6 * which stores Windows program lists collected by RMM agents via registry scanning or WMI queries.
7 *
8 * Key features:
9 * - **Software inventory**: Retrieve complete list of installed programs per agent
10 * - **Alphabetical sorting**: Programs returned in A-Z order by name
11 * - **Bulk data**: Typically 50-500+ programs per Windows machine
12 *
13 * Typical use cases:
14 * - Software asset management and license compliance
15 * - Security audits for unauthorized software
16 * - Patch management and version verification
17 * - Software deployment validation
18 * - IT inventory reporting
19 *
20 * Database schema:
21 * - Table: `agent_programs`
22 * - Key columns: agent_uuid, name, version, publisher, install_date, install_location
23 * - Indexed on: agent_uuid for efficient lookups
24 * - Data source: Windows Registry (HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall)
25 * @module services/programServices
26 * @requires ./db - PostgreSQL database pool
27 * @note This file is in routes/ directory but should be in services/ directory (organizational issue)
28 */
29
30const pool = require('./db');
31
32/**
33 * Retrieves list of all installed programs/software for a specific agent.
34 *
35 * Returns complete software inventory collected from agent's Windows registry. Programs
36 * are sorted alphabetically by name for easy browsing. Includes version numbers, publishers,
37 * install dates, and installation paths when available. Typical Windows machine returns
38 * 100-300 programs (applications, updates, drivers, system components).
39 * @async
40 * @function getInstalledPrograms
41 * @param {string} agent_uuid - Unique identifier of the agent (UUID format)
42 * @returns {Promise<object[]>} Array of installed program objects, empty array if no programs found
43 * @property {string} agent_uuid - Agent UUID (matches input parameter)
44 * @property {string} name - Program name (e.g., "Google Chrome", "Microsoft Office 365")
45 * @property {string} version - Version string (e.g., "120.0.6099.71", "16.0.16827.20166")
46 * @property {string} publisher - Software publisher/vendor (e.g., "Google LLC", "Microsoft Corporation")
47 * @property {Date} install_date - Installation date (may be null for some programs)
48 * @property {string} install_location - Installation directory path (e.g., "C:\\Program Files\\Google\\Chrome")
49 * @property {string} uninstall_string - Command to uninstall program (registry UninstallString)
50 * @example
51 * const programs = await getInstalledPrograms('550e8400-e29b-41d4-a716-446655440000');
52 * console.log(`Found ${programs.length} installed programs`);
53 * programs.forEach(p => console.log(`${p.name} v${p.version} by ${p.publisher}`));
54 * // Output:
55 * // Found 187 installed programs
56 * // 7-Zip v23.01 by Igor Pavlov
57 * // Adobe Acrobat Reader DC v24.001.20604 by Adobe Inc.
58 * // Google Chrome v120.0.6099.71 by Google LLC
59 */
60
61/**
62 *
63 * @param agent_uuid
64 */
65async function getInstalledPrograms(agent_uuid) {
66 const res = await pool.query(
67 `SELECT *
68 FROM agent_programs
69 WHERE agent_uuid = $1
70 ORDER BY name ASC`,
71 [agent_uuid]
72 );
73
74 return res.rows;
75}
76
77module.exports = { getInstalledPrograms };