docs: add CONTRIBUTING.md, CHANGELOG.md, and JSDoc to entire codebase
CI / Build & Test (push) Successful in 2m54s
CI / Build & Test (push) Successful in 2m54s
Add docs/CONTRIBUTING.md covering the build system, dev workflow, all npm scripts, how to add new native host message types, code style, and debugging guidance. Add CHANGELOG.md at the project root documenting all features and fixes across the 1.0.0 release. Add JSDoc (@param, @returns) to all previously undocumented exported functions across 35 JS files: - native-host/holesail-manager/ (index, virtual-hosts, service-tunnels, servers, port-allocator) - native-host top-level managers (startup, connect-proxy, https-proxy, certificate-authority, ssh-manager, rdp-manager) - extension/background/ (logs, native-messaging, proxy, message-router) - extension/dashboard/core/ (utils, navigation, init) - extension/dashboard/ui/ (modal, toast, state-tag) - extension/dashboard/pages/ (all 10 page files) - extension/dashboard/refresh.js, events.js - extension/dashboard/data/hostname-validator.js - scripts/ (build-host, run-install)
This commit is contained in:
@@ -20,11 +20,22 @@ let nextServerId = 0;
|
||||
let _saveState = null;
|
||||
let _getReadyTimeoutMs = null;
|
||||
|
||||
/**
|
||||
* Inject shared dependencies from the parent holesail-manager.
|
||||
* Must be called once before any other function in this module.
|
||||
* @param {Function} saveStateFn - Callback that persists the current state to disk.
|
||||
* @param {Function} getReadyTimeoutMsFn - Returns the configured ready-timeout in ms (0 = no timeout).
|
||||
*/
|
||||
function init(saveStateFn, getReadyTimeoutMsFn) {
|
||||
_saveState = saveStateFn;
|
||||
_getReadyTimeoutMs = getReadyTimeoutMsFn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Advance the server ID counter to be at least as high as the persisted value,
|
||||
* ensuring IDs generated after a restart do not collide with existing ones.
|
||||
* @param {number} loadedNextServerId - The `nextServerId` value read from state.json.
|
||||
*/
|
||||
function applyLoaded(loadedNextServerId) {
|
||||
if (loadedNextServerId > nextServerId) nextServerId = loadedNextServerId;
|
||||
}
|
||||
@@ -58,6 +69,17 @@ function readyWithTimeout(hs, label) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a Holesail server tunnel, exposing a local port to the P2P network.
|
||||
* @param {object} payload
|
||||
* @param {number} [payload.port=3000] - Local TCP port to expose.
|
||||
* @param {string} [payload.host='127.0.0.1'] - Local host to bind.
|
||||
* @param {boolean} [payload.secure=true] - Whether to use an encrypted (private) tunnel.
|
||||
* @param {boolean} [payload.udp=false] - Whether to use UDP mode.
|
||||
* @param {string} [payload.label=''] - Human-readable label for the UI.
|
||||
* @param {string} [payload.serverId] - Optional explicit ID; auto-generated if omitted.
|
||||
* @returns {Promise<{ok: boolean, serverId?: string, url?: string, port?: number, host?: string, secure?: boolean, udp?: boolean, label?: string, error?: string}>}
|
||||
*/
|
||||
async function startServer(payload) {
|
||||
if (!Holesail) return { ok: false, error: 'Holesail module not installed' };
|
||||
const port = payload.port || 3000;
|
||||
@@ -90,6 +112,12 @@ async function startServer(payload) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop a running server tunnel and remove it from state.
|
||||
* @param {object} payload
|
||||
* @param {string} payload.serverId - ID of the server tunnel to stop.
|
||||
* @returns {Promise<{ok: boolean, error?: string}>}
|
||||
*/
|
||||
async function stopServer(payload) {
|
||||
const serverId = payload.serverId;
|
||||
debugLog('stopServer: serverId=', serverId);
|
||||
@@ -104,6 +132,10 @@ async function stopServer(payload) {
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a snapshot of all active server tunnels.
|
||||
* @returns {Array<{id: string, serverId: string, port: number, host: string, url: string, secure: boolean, udp: boolean, label: string, createdAt: number}>}
|
||||
*/
|
||||
function getServers() {
|
||||
const list = [];
|
||||
for (const [id, s] of servers) {
|
||||
@@ -114,6 +146,10 @@ function getServers() {
|
||||
|
||||
function getNextServerId() { return nextServerId; }
|
||||
|
||||
/**
|
||||
* Close all active server tunnels. Called during native host shutdown.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function cleanupServers() {
|
||||
for (const [, s] of servers) {
|
||||
try { await s.holesail.close(); } catch (_) {}
|
||||
|
||||
Reference in New Issue
Block a user