Repository files navigation

miningos-app-node

Table of Contents

  1. Overview
  2. Architecture
  3. Quick Start
  4. Configuration
  5. API Reference

Overview

Purpose

miningos-app-node serves as the HTTP API gateway for MiningOS.

Key Features

  • HTTP API Gateway - RESTful fastify APIs
  • OAuth2 Authentication (Google) with token-based authorization
  • Role-Based Access Control (RBAC) - Multiple user roles with granular permissions
  • Multi-Cluster RPC - Communicates with multiple orchestrator clusters via DHT-based RPC
  • Request Caching - Configurable LRU caching (10s, 15s, 30s, 15m TTLs)
  • Request Deduplication - Prevents duplicate concurrent requests
  • Audit Logging - Comprehensive logging of user management and security events
  • Schema Validation - JSON Schema validation for all endpoints (Fastify)

Architecture

Technology Stack

ComponentTechnologyPurpose
RuntimeNode.js ≥20JavaScript execution environment
Base Frameworktether-wrk-baseP2P networking and storage foundation
Web FrameworkFastifyHigh-performance HTTP server
P2P NetworkHyperswarmDHT-based peer-to-peer networking
P2P StorageHyperbeeDistributed append-only B-tree
Authenticationsvc-facs-auth + OAuth2Token-based auth with Google OAuth
Local DBSQLite (bfx-facs-db-sqlite)User management and session storage
CachingLRU (bfx-facs-lru)In-memory request caching
LoggingPino (svc-facs-logging)Structured JSON logging with transport
TestingBrittleModern TAP test runner

Data Flow

  1. Client Request → HTTP API (Fastify)
  2. Authentication → Token validation (cached, 1-minute TTL)
  3. Authorization → Permission check (role + capability)
  4. Cache Check → LRU cache lookup (if applicable)
  5. Request Deduplication → Queue identical concurrent requests
  6. RPC Aggregation → Parallel DHT-based RPC requests to ORK clusters (max 2 concurrent)
  7. Response Aggregation → Merge results from multiple ORKs
  8. Cache Update → Store result in LRU cache
  9. Audit Log → Log sensitive operations (if enabled)
  10. Response → JSON response to client

Quick Start

Prerequisites

  • Node.js ≥20.0
  • npm
  • Git

Installation

# Clone the repository
git clone https://github.com/tetherto/miningos-app-node.git
cd miningos-app-node
# Install dependencies
npm install
# Setup configuration files
./setup-config.sh
# (Optional) Include test configuration
./setup-config.sh --test

Basic Configuration

1. Common Configuration

Edit config/common.json:

{
"dir_log": "logs",
"debug": 0,
"site": "production-site-01",
"ttl": 300,
"staticRootPath": "/path/to/mos-app-ui/build/",
"orks": {
"cluster-1": {
"rpcPublicKey": "YOUR_ORK_RPC_PUBLIC_KEY_HERE"
},
"cluster-2": {
"rpcPublicKey": "YOUR_ORK_RPC_PUBLIC_KEY_HERE"
}
},
"cacheTiming": {
"/auth/list-things": "30s",
"/auth/tail-log": "15s",
"/auth/global/data": "15m",
"/auth/actions": "10s"
},
"featureConfig": {}
}

Configuration Notes:

  • dir_log: Directory for log files (required)
  • ttl: Token time-to-live in seconds (default: 300 = 5 minutes)
  • staticRootPath: Path to the UI build directory (required if serving frontend)
  • cacheTiming: Per-endpoint cache TTL values (available: "10s", "15s", "30s", "15m")
  • featureConfig: Feature flags (see config/common.json.example for all available options)

2. OAuth2 Configuration

Edit config/facs/httpd-oauth2.config.json:

{
"h0": {
"method": "google",
"credentials": {
"client": {
"id": "YOUR_GOOGLE_CLIENT_ID",
"secret": "YOUR_GOOGLE_CLIENT_SECRET"
}
},
"users": [
{ "email": "admin@yourcompany.com", "write": true },
{ "email": "operator@yourcompany.com", "write": true },
{ "email": "viewer@yourcompany.com", "write": false }
]
}
}

3. Authentication & Roles Configuration

Set superAdmin email in config/facs/auth.config.json (see full example in Configuration section)

Running the Service

# Development mode
node worker.js --wtype wrk-node-http --env development --port 3000
# Production mode
node worker.js --wtype wrk-node-http --env production --port 3000
# With debug logging
DEBUG="*" node worker.js --wtype wrk-node-http --env development --port 3000

Configuration

Note: Configuration files are created by running ./setup-config.sh, which copies .example files to actual config files.

Configuration Details

config/common.json

{
"debug": 0,
"site": "production-site-01",
"staticRootPath": "/home/user/dev/mos-app-ui/build/",
"ttl": 300,
"dir_log": "logs",
"orks": {
"cluster-1": { "rpcPublicKey": "abc123..." },
"cluster-2": { "rpcPublicKey": "def456..." }
},
"cacheTiming": {
"/auth/list-things": "15s",
"/auth/tail-log": "15s",
"/auth/actions/batch": "30s",
"/auth/actions/:type": "30s",
"/auth/actions/:type/:id": "30s",
"/auth/global/data": "30s"
},
"featureConfig": {
"comments": true,
"inventory": false,
"lvCabinetWidgets": true,
"poolStats": true,
"powerAvailable": true,
"reporting": true,
"settings": true,
"isOneMinItvEnabled": false,
"powerModeTimeline": false,
"totalSystemConsumptionChart": false,
"exportHistKpiDashboard": false,
"showMinerConsumptionDashboard": false,
"totalSystemConsumptionHeader": false,
"energyProvision": true
}
}

Fields:

  • debug: Debug level (0 = info, 1+ = debug)
  • site: Site identifier for this node
  • staticRootPath: Path to static UI files served by HTTP server
  • ttl: Authentication token TTL in seconds (default: 300)
  • dir_log: Log directory path
  • orks: Map of ORK cluster names to RPC public keys
  • cacheTiming: Cache TTL per endpoint (available TTLs: 10s, 15s, 30s, 15m)
  • featureConfig: Static feature flags for enabling/disabling UI features

Cache Timing Notes:

  • Use endpoint paths as keys (e.g., /auth/list-things)
  • Supported TTL values: 10s, 15s, 30s, 15m
  • Unspecified endpoints default to 30s

config/facs/auth.config.json

{
"a0": {
"superAdmin": "superadmin@company.com",
"ttl": 86400,
"saltRounds": 10,
"superAdminPerms": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"features:rw",
"revenue:rw",
"users:rw",
"actions:rw",
"production:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw",
"forecast:rw"
],
"roles": {
"admin": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"features:rw",
"revenue:rw",
"users:rw",
"actions:rw",
"production:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw",
"forecast:rw"
],
"reporting_tool_manager": [
"revenue:rw",
"production:rw",
"reporting:rw",
"settings:r",
"forecast:r"
],
"site_manager": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"actions:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw"
],
"site_operator": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"actions:rw",
"electricity:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"cabinets:rw",
"comments:rw",
"settings:rw",
"ticket:rw",
"alerts:rw"
],
"field_operator": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:r",
"inventory:r",
"reporting:r",
"cabinets:r",
"comments:rw",
"settings:r",
"ticket:r",
"alerts:r"
],
"repair_technician": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"actions:rw",
"electricity:r",
"explorer:r",
"inventory:rw",
"cabinets:r",
"comments:rw",
"settings:r",
"ticket:r",
"alerts:r"
],
"read_only_user": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:r",
"inventory:r",
"reporting:r",
"cabinets:r",
"comments:r",
"settings:r",
"ticket:r",
"alerts:r"
],
"dev": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"cabinets:rw",
"comments:rw",
"settings:rw",
"ticket:rw",
"alerts:rw"
]
},
"roleManagement": {
"admin": [
"site_manager",
"site_operator",
"reporting_tool_manager",
"field_operator",
"repair_technician",
"read_only_user",
"dev"
]
}
}
}

Fields:

  • superAdmin: Email of the super administrator (cannot be modified/deleted)
  • ttl: Token time-to-live in seconds (default: 86400 = 24 hours)
  • saltRounds: BCrypt salt rounds for password hashing
  • superAdminPerms: Permissions granted to super administrator
  • roles: Role definitions with their associated permissions
  • roleManagement: Defines which roles can manage other roles

Permission Format:

  • Permissions use format resource:access where access can be:
    • r = read-only
    • rw = read and write
  • Example: "miner:rw" grants read and write access to miner resources

Available Roles:

  • admin - Full administrative access, can manage all other roles
  • reporting_tool_manager - Access to revenue, production, and reporting features
  • site_manager - Full site operations without user/feature management
  • site_operator - Day-to-day mining operations
  • field_operator - Read-only access with comment/ticket creation
  • repair_technician - Read access with action/inventory/comment management
  • read_only_user - Read-only access to all resources
  • dev - Developer access with elevated explorer/inventory/settings permissions

Role Management Rules:

  • superAdmin: Designated user with all permissions, cannot be modified/deleted via API
  • admin: Can manage all roles listed in roleManagement.admin array
  • Other roles: Cannot manage users (not present in roleManagement object)

config/facs/httpd-oauth2.config.json

{
"h0": {
"method": "google",
"credentials": {
"client": {
"id": "<CLIENT_ID>",
"secret": "<CLIENT_SECRET>"
}
},
"startRedirectPath": "/oauth/google",
"callbackUri": "http://localhost:3000/oauth/google/callback",
"callbackUriUI": "http://localhost:3030"
}
}

Fields:

  • method: OAuth provider (currently only "google" supported)
  • credentials.client.id: Google OAuth2 client ID
  • credentials.client.secret: Google OAuth2 client secret
  • startRedirectPath: Initiation path for OAuth flow
  • callbackUri: OAuth callback URL (must match Google Console configuration)
  • callbackUriUI: Frontend redirect URL after authentication

Capability Codes:

  • m = miner
  • c = container
  • mp = minerpool
  • p = powermeter
  • t = temperature
  • e = electricity
  • f = features
  • r = revenue

OAuth Flow:

  1. User visits /oauth/google on the app-node
  2. Redirected to Google authentication
  3. After auth, Google redirects to callbackUri
  4. App-node issues token and redirects to callbackUriUI

API Reference

API

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

miningos-app-node

Table of Contents

  1. Overview
  2. Architecture
  3. Quick Start
  4. Configuration
  5. API Reference

Overview

Purpose

miningos-app-node serves as the HTTP API gateway for MiningOS.

Key Features

  • HTTP API Gateway - RESTful fastify APIs
  • OAuth2 Authentication (Google) with token-based authorization
  • Role-Based Access Control (RBAC) - Multiple user roles with granular permissions
  • Multi-Cluster RPC - Communicates with multiple orchestrator clusters via DHT-based RPC
  • Request Caching - Configurable LRU caching (10s, 15s, 30s, 15m TTLs)
  • Request Deduplication - Prevents duplicate concurrent requests
  • Audit Logging - Comprehensive logging of user management and security events
  • Schema Validation - JSON Schema validation for all endpoints (Fastify)

Architecture

Technology Stack

ComponentTechnologyPurpose
RuntimeNode.js ≥20JavaScript execution environment
Base Frameworktether-wrk-baseP2P networking and storage foundation
Web FrameworkFastifyHigh-performance HTTP server
P2P NetworkHyperswarmDHT-based peer-to-peer networking
P2P StorageHyperbeeDistributed append-only B-tree
Authenticationsvc-facs-auth + OAuth2Token-based auth with Google OAuth
Local DBSQLite (bfx-facs-db-sqlite)User management and session storage
CachingLRU (bfx-facs-lru)In-memory request caching
LoggingPino (svc-facs-logging)Structured JSON logging with transport
TestingBrittleModern TAP test runner

Data Flow

  1. Client Request → HTTP API (Fastify)
  2. Authentication → Token validation (cached, 1-minute TTL)
  3. Authorization → Permission check (role + capability)
  4. Cache Check → LRU cache lookup (if applicable)
  5. Request Deduplication → Queue identical concurrent requests
  6. RPC Aggregation → Parallel DHT-based RPC requests to ORK clusters (max 2 concurrent)
  7. Response Aggregation → Merge results from multiple ORKs
  8. Cache Update → Store result in LRU cache
  9. Audit Log → Log sensitive operations (if enabled)
  10. Response → JSON response to client

Quick Start

Prerequisites

  • Node.js ≥20.0
  • npm
  • Git

Installation

# Clone the repository
git clone https://github.com/tetherto/miningos-app-node.git
cd miningos-app-node
# Install dependencies
npm install
# Setup configuration files
./setup-config.sh
# (Optional) Include test configuration
./setup-config.sh --test

Basic Configuration

1. Common Configuration

Edit config/common.json:

{
"dir_log": "logs",
"debug": 0,
"site": "production-site-01",
"ttl": 300,
"staticRootPath": "/path/to/mos-app-ui/build/",
"orks": {
"cluster-1": {
"rpcPublicKey": "YOUR_ORK_RPC_PUBLIC_KEY_HERE"
},
"cluster-2": {
"rpcPublicKey": "YOUR_ORK_RPC_PUBLIC_KEY_HERE"
}
},
"cacheTiming": {
"/auth/list-things": "30s",
"/auth/tail-log": "15s",
"/auth/global/data": "15m",
"/auth/actions": "10s"
},
"featureConfig": {}
}

Configuration Notes:

  • dir_log: Directory for log files (required)
  • ttl: Token time-to-live in seconds (default: 300 = 5 minutes)
  • staticRootPath: Path to the UI build directory (required if serving frontend)
  • cacheTiming: Per-endpoint cache TTL values (available: "10s", "15s", "30s", "15m")
  • featureConfig: Feature flags (see config/common.json.example for all available options)

2. OAuth2 Configuration

Edit config/facs/httpd-oauth2.config.json:

{
"h0": {
"method": "google",
"credentials": {
"client": {
"id": "YOUR_GOOGLE_CLIENT_ID",
"secret": "YOUR_GOOGLE_CLIENT_SECRET"
}
},
"users": [
{ "email": "admin@yourcompany.com", "write": true },
{ "email": "operator@yourcompany.com", "write": true },
{ "email": "viewer@yourcompany.com", "write": false }
]
}
}

3. Authentication & Roles Configuration

Set superAdmin email in config/facs/auth.config.json (see full example in Configuration section)

Running the Service

# Development mode
node worker.js --wtype wrk-node-http --env development --port 3000
# Production mode
node worker.js --wtype wrk-node-http --env production --port 3000
# With debug logging
DEBUG="*" node worker.js --wtype wrk-node-http --env development --port 3000

Configuration

Note: Configuration files are created by running ./setup-config.sh, which copies .example files to actual config files.

Configuration Details

config/common.json

{
"debug": 0,
"site": "production-site-01",
"staticRootPath": "/home/user/dev/mos-app-ui/build/",
"ttl": 300,
"dir_log": "logs",
"orks": {
"cluster-1": { "rpcPublicKey": "abc123..." },
"cluster-2": { "rpcPublicKey": "def456..." }
},
"cacheTiming": {
"/auth/list-things": "15s",
"/auth/tail-log": "15s",
"/auth/actions/batch": "30s",
"/auth/actions/:type": "30s",
"/auth/actions/:type/:id": "30s",
"/auth/global/data": "30s"
},
"featureConfig": {
"comments": true,
"inventory": false,
"lvCabinetWidgets": true,
"poolStats": true,
"powerAvailable": true,
"reporting": true,
"settings": true,
"isOneMinItvEnabled": false,
"powerModeTimeline": false,
"totalSystemConsumptionChart": false,
"exportHistKpiDashboard": false,
"showMinerConsumptionDashboard": false,
"totalSystemConsumptionHeader": false,
"energyProvision": true
}
}

Fields:

  • debug: Debug level (0 = info, 1+ = debug)
  • site: Site identifier for this node
  • staticRootPath: Path to static UI files served by HTTP server
  • ttl: Authentication token TTL in seconds (default: 300)
  • dir_log: Log directory path
  • orks: Map of ORK cluster names to RPC public keys
  • cacheTiming: Cache TTL per endpoint (available TTLs: 10s, 15s, 30s, 15m)
  • featureConfig: Static feature flags for enabling/disabling UI features

Cache Timing Notes:

  • Use endpoint paths as keys (e.g., /auth/list-things)
  • Supported TTL values: 10s, 15s, 30s, 15m
  • Unspecified endpoints default to 30s

config/facs/auth.config.json

{
"a0": {
"superAdmin": "superadmin@company.com",
"ttl": 86400,
"saltRounds": 10,
"superAdminPerms": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"features:rw",
"revenue:rw",
"users:rw",
"actions:rw",
"production:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw",
"forecast:rw"
],
"roles": {
"admin": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"features:rw",
"revenue:rw",
"users:rw",
"actions:rw",
"production:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw",
"forecast:rw"
],
"reporting_tool_manager": [
"revenue:rw",
"production:rw",
"reporting:rw",
"settings:r",
"forecast:r"
],
"site_manager": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"actions:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw"
],
"site_operator": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"actions:rw",
"electricity:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"cabinets:rw",
"comments:rw",
"settings:rw",
"ticket:rw",
"alerts:rw"
],
"field_operator": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:r",
"inventory:r",
"reporting:r",
"cabinets:r",
"comments:rw",
"settings:r",
"ticket:r",
"alerts:r"
],
"repair_technician": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"actions:rw",
"electricity:r",
"explorer:r",
"inventory:rw",
"cabinets:r",
"comments:rw",
"settings:r",
"ticket:r",
"alerts:r"
],
"read_only_user": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:r",
"inventory:r",
"reporting:r",
"cabinets:r",
"comments:r",
"settings:r",
"ticket:r",
"alerts:r"
],
"dev": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"cabinets:rw",
"comments:rw",
"settings:rw",
"ticket:rw",
"alerts:rw"
]
},
"roleManagement": {
"admin": [
"site_manager",
"site_operator",
"reporting_tool_manager",
"field_operator",
"repair_technician",
"read_only_user",
"dev"
]
}
}
}

Fields:

  • superAdmin: Email of the super administrator (cannot be modified/deleted)
  • ttl: Token time-to-live in seconds (default: 86400 = 24 hours)
  • saltRounds: BCrypt salt rounds for password hashing
  • superAdminPerms: Permissions granted to super administrator
  • roles: Role definitions with their associated permissions
  • roleManagement: Defines which roles can manage other roles

Permission Format:

  • Permissions use format resource:access where access can be:
    • r = read-only
    • rw = read and write
  • Example: "miner:rw" grants read and write access to miner resources

Available Roles:

  • admin - Full administrative access, can manage all other roles
  • reporting_tool_manager - Access to revenue, production, and reporting features
  • site_manager - Full site operations without user/feature management
  • site_operator - Day-to-day mining operations
  • field_operator - Read-only access with comment/ticket creation
  • repair_technician - Read access with action/inventory/comment management
  • read_only_user - Read-only access to all resources
  • dev - Developer access with elevated explorer/inventory/settings permissions

Role Management Rules:

  • superAdmin: Designated user with all permissions, cannot be modified/deleted via API
  • admin: Can manage all roles listed in roleManagement.admin array
  • Other roles: Cannot manage users (not present in roleManagement object)

config/facs/httpd-oauth2.config.json

{
"h0": {
"method": "google",
"credentials": {
"client": {
"id": "<CLIENT_ID>",
"secret": "<CLIENT_SECRET>"
}
},
"startRedirectPath": "/oauth/google",
"callbackUri": "http://localhost:3000/oauth/google/callback",
"callbackUriUI": "http://localhost:3030"
}
}

Fields:

  • method: OAuth provider (currently only "google" supported)
  • credentials.client.id: Google OAuth2 client ID
  • credentials.client.secret: Google OAuth2 client secret
  • startRedirectPath: Initiation path for OAuth flow
  • callbackUri: OAuth callback URL (must match Google Console configuration)
  • callbackUriUI: Frontend redirect URL after authentication

Capability Codes:

  • m = miner
  • c = container
  • mp = minerpool
  • p = powermeter
  • t = temperature
  • e = electricity
  • f = features
  • r = revenue

OAuth Flow:

  1. User visits /oauth/google on the app-node
  2. Redirected to Google authentication
  3. After auth, Google redirects to callbackUri
  4. App-node issues token and redirects to callbackUriUI

API Reference

API

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

miningos-app-node

Table of Contents

  1. Overview
  2. Architecture
  3. Quick Start
  4. Configuration
  5. API Reference

Overview

Purpose

miningos-app-node serves as the HTTP API gateway for MiningOS.

Key Features

  • HTTP API Gateway - RESTful fastify APIs
  • OAuth2 Authentication (Google) with token-based authorization
  • Role-Based Access Control (RBAC) - Multiple user roles with granular permissions
  • Multi-Cluster RPC - Communicates with multiple orchestrator clusters via DHT-based RPC
  • Request Caching - Configurable LRU caching (10s, 15s, 30s, 15m TTLs)
  • Request Deduplication - Prevents duplicate concurrent requests
  • Audit Logging - Comprehensive logging of user management and security events
  • Schema Validation - JSON Schema validation for all endpoints (Fastify)

Architecture

Technology Stack

ComponentTechnologyPurpose
RuntimeNode.js ≥20JavaScript execution environment
Base Frameworktether-wrk-baseP2P networking and storage foundation
Web FrameworkFastifyHigh-performance HTTP server
P2P NetworkHyperswarmDHT-based peer-to-peer networking
P2P StorageHyperbeeDistributed append-only B-tree
Authenticationsvc-facs-auth + OAuth2Token-based auth with Google OAuth
Local DBSQLite (bfx-facs-db-sqlite)User management and session storage
CachingLRU (bfx-facs-lru)In-memory request caching
LoggingPino (svc-facs-logging)Structured JSON logging with transport
TestingBrittleModern TAP test runner

Data Flow

  1. Client Request → HTTP API (Fastify)
  2. Authentication → Token validation (cached, 1-minute TTL)
  3. Authorization → Permission check (role + capability)
  4. Cache Check → LRU cache lookup (if applicable)
  5. Request Deduplication → Queue identical concurrent requests
  6. RPC Aggregation → Parallel DHT-based RPC requests to ORK clusters (max 2 concurrent)
  7. Response Aggregation → Merge results from multiple ORKs
  8. Cache Update → Store result in LRU cache
  9. Audit Log → Log sensitive operations (if enabled)
  10. Response → JSON response to client

Quick Start

Prerequisites

  • Node.js ≥20.0
  • npm
  • Git

Installation

# Clone the repository
git clone https://github.com/tetherto/miningos-app-node.git
cd miningos-app-node
# Install dependencies
npm install
# Setup configuration files
./setup-config.sh
# (Optional) Include test configuration
./setup-config.sh --test

Basic Configuration

1. Common Configuration

Edit config/common.json:

{
"dir_log": "logs",
"debug": 0,
"site": "production-site-01",
"ttl": 300,
"staticRootPath": "/path/to/mos-app-ui/build/",
"orks": {
"cluster-1": {
"rpcPublicKey": "YOUR_ORK_RPC_PUBLIC_KEY_HERE"
},
"cluster-2": {
"rpcPublicKey": "YOUR_ORK_RPC_PUBLIC_KEY_HERE"
}
},
"cacheTiming": {
"/auth/list-things": "30s",
"/auth/tail-log": "15s",
"/auth/global/data": "15m",
"/auth/actions": "10s"
},
"featureConfig": {}
}

Configuration Notes:

  • dir_log: Directory for log files (required)
  • ttl: Token time-to-live in seconds (default: 300 = 5 minutes)
  • staticRootPath: Path to the UI build directory (required if serving frontend)
  • cacheTiming: Per-endpoint cache TTL values (available: "10s", "15s", "30s", "15m")
  • featureConfig: Feature flags (see config/common.json.example for all available options)

2. OAuth2 Configuration

Edit config/facs/httpd-oauth2.config.json:

{
"h0": {
"method": "google",
"credentials": {
"client": {
"id": "YOUR_GOOGLE_CLIENT_ID",
"secret": "YOUR_GOOGLE_CLIENT_SECRET"
}
},
"users": [
{ "email": "admin@yourcompany.com", "write": true },
{ "email": "operator@yourcompany.com", "write": true },
{ "email": "viewer@yourcompany.com", "write": false }
]
}
}

3. Authentication & Roles Configuration

Set superAdmin email in config/facs/auth.config.json (see full example in Configuration section)

Running the Service

# Development mode
node worker.js --wtype wrk-node-http --env development --port 3000
# Production mode
node worker.js --wtype wrk-node-http --env production --port 3000
# With debug logging
DEBUG="*" node worker.js --wtype wrk-node-http --env development --port 3000

Configuration

Note: Configuration files are created by running ./setup-config.sh, which copies .example files to actual config files.

Configuration Details

config/common.json

{
"debug": 0,
"site": "production-site-01",
"staticRootPath": "/home/user/dev/mos-app-ui/build/",
"ttl": 300,
"dir_log": "logs",
"orks": {
"cluster-1": { "rpcPublicKey": "abc123..." },
"cluster-2": { "rpcPublicKey": "def456..." }
},
"cacheTiming": {
"/auth/list-things": "15s",
"/auth/tail-log": "15s",
"/auth/actions/batch": "30s",
"/auth/actions/:type": "30s",
"/auth/actions/:type/:id": "30s",
"/auth/global/data": "30s"
},
"featureConfig": {
"comments": true,
"inventory": false,
"lvCabinetWidgets": true,
"poolStats": true,
"powerAvailable": true,
"reporting": true,
"settings": true,
"isOneMinItvEnabled": false,
"powerModeTimeline": false,
"totalSystemConsumptionChart": false,
"exportHistKpiDashboard": false,
"showMinerConsumptionDashboard": false,
"totalSystemConsumptionHeader": false,
"energyProvision": true
}
}

Fields:

  • debug: Debug level (0 = info, 1+ = debug)
  • site: Site identifier for this node
  • staticRootPath: Path to static UI files served by HTTP server
  • ttl: Authentication token TTL in seconds (default: 300)
  • dir_log: Log directory path
  • orks: Map of ORK cluster names to RPC public keys
  • cacheTiming: Cache TTL per endpoint (available TTLs: 10s, 15s, 30s, 15m)
  • featureConfig: Static feature flags for enabling/disabling UI features

Cache Timing Notes:

  • Use endpoint paths as keys (e.g., /auth/list-things)
  • Supported TTL values: 10s, 15s, 30s, 15m
  • Unspecified endpoints default to 30s

config/facs/auth.config.json

{
"a0": {
"superAdmin": "superadmin@company.com",
"ttl": 86400,
"saltRounds": 10,
"superAdminPerms": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"features:rw",
"revenue:rw",
"users:rw",
"actions:rw",
"production:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw",
"forecast:rw"
],
"roles": {
"admin": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"features:rw",
"revenue:rw",
"users:rw",
"actions:rw",
"production:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw",
"forecast:rw"
],
"reporting_tool_manager": [
"revenue:rw",
"production:rw",
"reporting:rw",
"settings:r",
"forecast:r"
],
"site_manager": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"actions:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw"
],
"site_operator": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"actions:rw",
"electricity:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"cabinets:rw",
"comments:rw",
"settings:rw",
"ticket:rw",
"alerts:rw"
],
"field_operator": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:r",
"inventory:r",
"reporting:r",
"cabinets:r",
"comments:rw",
"settings:r",
"ticket:r",
"alerts:r"
],
"repair_technician": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"actions:rw",
"electricity:r",
"explorer:r",
"inventory:rw",
"cabinets:r",
"comments:rw",
"settings:r",
"ticket:r",
"alerts:r"
],
"read_only_user": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:r",
"inventory:r",
"reporting:r",
"cabinets:r",
"comments:r",
"settings:r",
"ticket:r",
"alerts:r"
],
"dev": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"cabinets:rw",
"comments:rw",
"settings:rw",
"ticket:rw",
"alerts:rw"
]
},
"roleManagement": {
"admin": [
"site_manager",
"site_operator",
"reporting_tool_manager",
"field_operator",
"repair_technician",
"read_only_user",
"dev"
]
}
}
}

Fields:

  • superAdmin: Email of the super administrator (cannot be modified/deleted)
  • ttl: Token time-to-live in seconds (default: 86400 = 24 hours)
  • saltRounds: BCrypt salt rounds for password hashing
  • superAdminPerms: Permissions granted to super administrator
  • roles: Role definitions with their associated permissions
  • roleManagement: Defines which roles can manage other roles

Permission Format:

  • Permissions use format resource:access where access can be:
    • r = read-only
    • rw = read and write
  • Example: "miner:rw" grants read and write access to miner resources

Available Roles:

  • admin - Full administrative access, can manage all other roles
  • reporting_tool_manager - Access to revenue, production, and reporting features
  • site_manager - Full site operations without user/feature management
  • site_operator - Day-to-day mining operations
  • field_operator - Read-only access with comment/ticket creation
  • repair_technician - Read access with action/inventory/comment management
  • read_only_user - Read-only access to all resources
  • dev - Developer access with elevated explorer/inventory/settings permissions

Role Management Rules:

  • superAdmin: Designated user with all permissions, cannot be modified/deleted via API
  • admin: Can manage all roles listed in roleManagement.admin array
  • Other roles: Cannot manage users (not present in roleManagement object)

config/facs/httpd-oauth2.config.json

{
"h0": {
"method": "google",
"credentials": {
"client": {
"id": "<CLIENT_ID>",
"secret": "<CLIENT_SECRET>"
}
},
"startRedirectPath": "/oauth/google",
"callbackUri": "http://localhost:3000/oauth/google/callback",
"callbackUriUI": "http://localhost:3030"
}
}

Fields:

  • method: OAuth provider (currently only "google" supported)
  • credentials.client.id: Google OAuth2 client ID
  • credentials.client.secret: Google OAuth2 client secret
  • startRedirectPath: Initiation path for OAuth flow
  • callbackUri: OAuth callback URL (must match Google Console configuration)
  • callbackUriUI: Frontend redirect URL after authentication

Capability Codes:

  • m = miner
  • c = container
  • mp = minerpool
  • p = powermeter
  • t = temperature
  • e = electricity
  • f = features
  • r = revenue

OAuth Flow:

  1. User visits /oauth/google on the app-node
  2. Redirected to Google authentication
  3. After auth, Google redirects to callbackUri
  4. App-node issues token and redirects to callbackUriUI

API Reference

API

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

miningos-app-node

Table of Contents

  1. Overview
  2. Architecture
  3. Quick Start
  4. Configuration
  5. API Reference

Overview

Purpose

miningos-app-node serves as the HTTP API gateway for MiningOS.

Key Features

  • HTTP API Gateway - RESTful fastify APIs
  • OAuth2 Authentication (Google) with token-based authorization
  • Role-Based Access Control (RBAC) - Multiple user roles with granular permissions
  • Multi-Cluster RPC - Communicates with multiple orchestrator clusters via DHT-based RPC
  • Request Caching - Configurable LRU caching (10s, 15s, 30s, 15m TTLs)
  • Request Deduplication - Prevents duplicate concurrent requests
  • Audit Logging - Comprehensive logging of user management and security events
  • Schema Validation - JSON Schema validation for all endpoints (Fastify)

Architecture

Technology Stack

ComponentTechnologyPurpose
RuntimeNode.js ≥20JavaScript execution environment
Base Frameworktether-wrk-baseP2P networking and storage foundation
Web FrameworkFastifyHigh-performance HTTP server
P2P NetworkHyperswarmDHT-based peer-to-peer networking
P2P StorageHyperbeeDistributed append-only B-tree
Authenticationsvc-facs-auth + OAuth2Token-based auth with Google OAuth
Local DBSQLite (bfx-facs-db-sqlite)User management and session storage
CachingLRU (bfx-facs-lru)In-memory request caching
LoggingPino (svc-facs-logging)Structured JSON logging with transport
TestingBrittleModern TAP test runner

Data Flow

  1. Client Request → HTTP API (Fastify)
  2. Authentication → Token validation (cached, 1-minute TTL)
  3. Authorization → Permission check (role + capability)
  4. Cache Check → LRU cache lookup (if applicable)
  5. Request Deduplication → Queue identical concurrent requests
  6. RPC Aggregation → Parallel DHT-based RPC requests to ORK clusters (max 2 concurrent)
  7. Response Aggregation → Merge results from multiple ORKs
  8. Cache Update → Store result in LRU cache
  9. Audit Log → Log sensitive operations (if enabled)
  10. Response → JSON response to client

Quick Start

Prerequisites

  • Node.js ≥20.0
  • npm
  • Git

Installation

# Clone the repository
git clone https://github.com/tetherto/miningos-app-node.git
cd miningos-app-node
# Install dependencies
npm install
# Setup configuration files
./setup-config.sh
# (Optional) Include test configuration
./setup-config.sh --test

Basic Configuration

1. Common Configuration

Edit config/common.json:

{
"dir_log": "logs",
"debug": 0,
"site": "production-site-01",
"ttl": 300,
"staticRootPath": "/path/to/mos-app-ui/build/",
"orks": {
"cluster-1": {
"rpcPublicKey": "YOUR_ORK_RPC_PUBLIC_KEY_HERE"
},
"cluster-2": {
"rpcPublicKey": "YOUR_ORK_RPC_PUBLIC_KEY_HERE"
}
},
"cacheTiming": {
"/auth/list-things": "30s",
"/auth/tail-log": "15s",
"/auth/global/data": "15m",
"/auth/actions": "10s"
},
"featureConfig": {}
}

Configuration Notes:

  • dir_log: Directory for log files (required)
  • ttl: Token time-to-live in seconds (default: 300 = 5 minutes)
  • staticRootPath: Path to the UI build directory (required if serving frontend)
  • cacheTiming: Per-endpoint cache TTL values (available: "10s", "15s", "30s", "15m")
  • featureConfig: Feature flags (see config/common.json.example for all available options)

2. OAuth2 Configuration

Edit config/facs/httpd-oauth2.config.json:

{
"h0": {
"method": "google",
"credentials": {
"client": {
"id": "YOUR_GOOGLE_CLIENT_ID",
"secret": "YOUR_GOOGLE_CLIENT_SECRET"
}
},
"users": [
{ "email": "admin@yourcompany.com", "write": true },
{ "email": "operator@yourcompany.com", "write": true },
{ "email": "viewer@yourcompany.com", "write": false }
]
}
}

3. Authentication & Roles Configuration

Set superAdmin email in config/facs/auth.config.json (see full example in Configuration section)

Running the Service

# Development mode
node worker.js --wtype wrk-node-http --env development --port 3000
# Production mode
node worker.js --wtype wrk-node-http --env production --port 3000
# With debug logging
DEBUG="*" node worker.js --wtype wrk-node-http --env development --port 3000

Configuration

Note: Configuration files are created by running ./setup-config.sh, which copies .example files to actual config files.

Configuration Details

config/common.json

{
"debug": 0,
"site": "production-site-01",
"staticRootPath": "/home/user/dev/mos-app-ui/build/",
"ttl": 300,
"dir_log": "logs",
"orks": {
"cluster-1": { "rpcPublicKey": "abc123..." },
"cluster-2": { "rpcPublicKey": "def456..." }
},
"cacheTiming": {
"/auth/list-things": "15s",
"/auth/tail-log": "15s",
"/auth/actions/batch": "30s",
"/auth/actions/:type": "30s",
"/auth/actions/:type/:id": "30s",
"/auth/global/data": "30s"
},
"featureConfig": {
"comments": true,
"inventory": false,
"lvCabinetWidgets": true,
"poolStats": true,
"powerAvailable": true,
"reporting": true,
"settings": true,
"isOneMinItvEnabled": false,
"powerModeTimeline": false,
"totalSystemConsumptionChart": false,
"exportHistKpiDashboard": false,
"showMinerConsumptionDashboard": false,
"totalSystemConsumptionHeader": false,
"energyProvision": true
}
}

Fields:

  • debug: Debug level (0 = info, 1+ = debug)
  • site: Site identifier for this node
  • staticRootPath: Path to static UI files served by HTTP server
  • ttl: Authentication token TTL in seconds (default: 300)
  • dir_log: Log directory path
  • orks: Map of ORK cluster names to RPC public keys
  • cacheTiming: Cache TTL per endpoint (available TTLs: 10s, 15s, 30s, 15m)
  • featureConfig: Static feature flags for enabling/disabling UI features

Cache Timing Notes:

  • Use endpoint paths as keys (e.g., /auth/list-things)
  • Supported TTL values: 10s, 15s, 30s, 15m
  • Unspecified endpoints default to 30s

config/facs/auth.config.json

{
"a0": {
"superAdmin": "superadmin@company.com",
"ttl": 86400,
"saltRounds": 10,
"superAdminPerms": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"features:rw",
"revenue:rw",
"users:rw",
"actions:rw",
"production:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw",
"forecast:rw"
],
"roles": {
"admin": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"features:rw",
"revenue:rw",
"users:rw",
"actions:rw",
"production:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw",
"forecast:rw"
],
"reporting_tool_manager": [
"revenue:rw",
"production:rw",
"reporting:rw",
"settings:r",
"forecast:r"
],
"site_manager": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"actions:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw"
],
"site_operator": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"actions:rw",
"electricity:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"cabinets:rw",
"comments:rw",
"settings:rw",
"ticket:rw",
"alerts:rw"
],
"field_operator": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:r",
"inventory:r",
"reporting:r",
"cabinets:r",
"comments:rw",
"settings:r",
"ticket:r",
"alerts:r"
],
"repair_technician": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"actions:rw",
"electricity:r",
"explorer:r",
"inventory:rw",
"cabinets:r",
"comments:rw",
"settings:r",
"ticket:r",
"alerts:r"
],
"read_only_user": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:r",
"inventory:r",
"reporting:r",
"cabinets:r",
"comments:r",
"settings:r",
"ticket:r",
"alerts:r"
],
"dev": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"cabinets:rw",
"comments:rw",
"settings:rw",
"ticket:rw",
"alerts:rw"
]
},
"roleManagement": {
"admin": [
"site_manager",
"site_operator",
"reporting_tool_manager",
"field_operator",
"repair_technician",
"read_only_user",
"dev"
]
}
}
}

Fields:

  • superAdmin: Email of the super administrator (cannot be modified/deleted)
  • ttl: Token time-to-live in seconds (default: 86400 = 24 hours)
  • saltRounds: BCrypt salt rounds for password hashing
  • superAdminPerms: Permissions granted to super administrator
  • roles: Role definitions with their associated permissions
  • roleManagement: Defines which roles can manage other roles

Permission Format:

  • Permissions use format resource:access where access can be:
    • r = read-only
    • rw = read and write
  • Example: "miner:rw" grants read and write access to miner resources

Available Roles:

  • admin - Full administrative access, can manage all other roles
  • reporting_tool_manager - Access to revenue, production, and reporting features
  • site_manager - Full site operations without user/feature management
  • site_operator - Day-to-day mining operations
  • field_operator - Read-only access with comment/ticket creation
  • repair_technician - Read access with action/inventory/comment management
  • read_only_user - Read-only access to all resources
  • dev - Developer access with elevated explorer/inventory/settings permissions

Role Management Rules:

  • superAdmin: Designated user with all permissions, cannot be modified/deleted via API
  • admin: Can manage all roles listed in roleManagement.admin array
  • Other roles: Cannot manage users (not present in roleManagement object)

config/facs/httpd-oauth2.config.json

{
"h0": {
"method": "google",
"credentials": {
"client": {
"id": "<CLIENT_ID>",
"secret": "<CLIENT_SECRET>"
}
},
"startRedirectPath": "/oauth/google",
"callbackUri": "http://localhost:3000/oauth/google/callback",
"callbackUriUI": "http://localhost:3030"
}
}

Fields:

  • method: OAuth provider (currently only "google" supported)
  • credentials.client.id: Google OAuth2 client ID
  • credentials.client.secret: Google OAuth2 client secret
  • startRedirectPath: Initiation path for OAuth flow
  • callbackUri: OAuth callback URL (must match Google Console configuration)
  • callbackUriUI: Frontend redirect URL after authentication

Capability Codes:

  • m = miner
  • c = container
  • mp = minerpool
  • p = powermeter
  • t = temperature
  • e = electricity
  • f = features
  • r = revenue

OAuth Flow:

  1. User visits /oauth/google on the app-node
  2. Redirected to Google authentication
  3. After auth, Google redirects to callbackUri
  4. App-node issues token and redirects to callbackUriUI

API Reference

API

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

miningos-app-node

Table of Contents

  1. Overview
  2. Architecture
  3. Quick Start
  4. Configuration
  5. API Reference

Overview

Purpose

miningos-app-node serves as the HTTP API gateway for MiningOS.

Key Features

  • HTTP API Gateway - RESTful fastify APIs
  • OAuth2 Authentication (Google) with token-based authorization
  • Role-Based Access Control (RBAC) - Multiple user roles with granular permissions
  • Multi-Cluster RPC - Communicates with multiple orchestrator clusters via DHT-based RPC
  • Request Caching - Configurable LRU caching (10s, 15s, 30s, 15m TTLs)
  • Request Deduplication - Prevents duplicate concurrent requests
  • Audit Logging - Comprehensive logging of user management and security events
  • Schema Validation - JSON Schema validation for all endpoints (Fastify)

Architecture

Technology Stack

ComponentTechnologyPurpose
RuntimeNode.js ≥20JavaScript execution environment
Base Frameworktether-wrk-baseP2P networking and storage foundation
Web FrameworkFastifyHigh-performance HTTP server
P2P NetworkHyperswarmDHT-based peer-to-peer networking
P2P StorageHyperbeeDistributed append-only B-tree
Authenticationsvc-facs-auth + OAuth2Token-based auth with Google OAuth
Local DBSQLite (bfx-facs-db-sqlite)User management and session storage
CachingLRU (bfx-facs-lru)In-memory request caching
LoggingPino (svc-facs-logging)Structured JSON logging with transport
TestingBrittleModern TAP test runner

Data Flow

  1. Client Request → HTTP API (Fastify)
  2. Authentication → Token validation (cached, 1-minute TTL)
  3. Authorization → Permission check (role + capability)
  4. Cache Check → LRU cache lookup (if applicable)
  5. Request Deduplication → Queue identical concurrent requests
  6. RPC Aggregation → Parallel DHT-based RPC requests to ORK clusters (max 2 concurrent)
  7. Response Aggregation → Merge results from multiple ORKs
  8. Cache Update → Store result in LRU cache
  9. Audit Log → Log sensitive operations (if enabled)
  10. Response → JSON response to client

Quick Start

Prerequisites

  • Node.js ≥20.0
  • npm
  • Git

Installation

# Clone the repository
git clone https://github.com/tetherto/miningos-app-node.git
cd miningos-app-node
# Install dependencies
npm install
# Setup configuration files
./setup-config.sh
# (Optional) Include test configuration
./setup-config.sh --test

Basic Configuration

1. Common Configuration

Edit config/common.json:

{
"dir_log": "logs",
"debug": 0,
"site": "production-site-01",
"ttl": 300,
"staticRootPath": "/path/to/mos-app-ui/build/",
"orks": {
"cluster-1": {
"rpcPublicKey": "YOUR_ORK_RPC_PUBLIC_KEY_HERE"
},
"cluster-2": {
"rpcPublicKey": "YOUR_ORK_RPC_PUBLIC_KEY_HERE"
}
},
"cacheTiming": {
"/auth/list-things": "30s",
"/auth/tail-log": "15s",
"/auth/global/data": "15m",
"/auth/actions": "10s"
},
"featureConfig": {}
}

Configuration Notes:

  • dir_log: Directory for log files (required)
  • ttl: Token time-to-live in seconds (default: 300 = 5 minutes)
  • staticRootPath: Path to the UI build directory (required if serving frontend)
  • cacheTiming: Per-endpoint cache TTL values (available: "10s", "15s", "30s", "15m")
  • featureConfig: Feature flags (see config/common.json.example for all available options)

2. OAuth2 Configuration

Edit config/facs/httpd-oauth2.config.json:

{
"h0": {
"method": "google",
"credentials": {
"client": {
"id": "YOUR_GOOGLE_CLIENT_ID",
"secret": "YOUR_GOOGLE_CLIENT_SECRET"
}
},
"users": [
{ "email": "admin@yourcompany.com", "write": true },
{ "email": "operator@yourcompany.com", "write": true },
{ "email": "viewer@yourcompany.com", "write": false }
]
}
}

3. Authentication & Roles Configuration

Set superAdmin email in config/facs/auth.config.json (see full example in Configuration section)

Running the Service

# Development mode
node worker.js --wtype wrk-node-http --env development --port 3000
# Production mode
node worker.js --wtype wrk-node-http --env production --port 3000
# With debug logging
DEBUG="*" node worker.js --wtype wrk-node-http --env development --port 3000

Configuration

Note: Configuration files are created by running ./setup-config.sh, which copies .example files to actual config files.

Configuration Details

config/common.json

{
"debug": 0,
"site": "production-site-01",
"staticRootPath": "/home/user/dev/mos-app-ui/build/",
"ttl": 300,
"dir_log": "logs",
"orks": {
"cluster-1": { "rpcPublicKey": "abc123..." },
"cluster-2": { "rpcPublicKey": "def456..." }
},
"cacheTiming": {
"/auth/list-things": "15s",
"/auth/tail-log": "15s",
"/auth/actions/batch": "30s",
"/auth/actions/:type": "30s",
"/auth/actions/:type/:id": "30s",
"/auth/global/data": "30s"
},
"featureConfig": {
"comments": true,
"inventory": false,
"lvCabinetWidgets": true,
"poolStats": true,
"powerAvailable": true,
"reporting": true,
"settings": true,
"isOneMinItvEnabled": false,
"powerModeTimeline": false,
"totalSystemConsumptionChart": false,
"exportHistKpiDashboard": false,
"showMinerConsumptionDashboard": false,
"totalSystemConsumptionHeader": false,
"energyProvision": true
}
}

Fields:

  • debug: Debug level (0 = info, 1+ = debug)
  • site: Site identifier for this node
  • staticRootPath: Path to static UI files served by HTTP server
  • ttl: Authentication token TTL in seconds (default: 300)
  • dir_log: Log directory path
  • orks: Map of ORK cluster names to RPC public keys
  • cacheTiming: Cache TTL per endpoint (available TTLs: 10s, 15s, 30s, 15m)
  • featureConfig: Static feature flags for enabling/disabling UI features

Cache Timing Notes:

  • Use endpoint paths as keys (e.g., /auth/list-things)
  • Supported TTL values: 10s, 15s, 30s, 15m
  • Unspecified endpoints default to 30s

config/facs/auth.config.json

{
"a0": {
"superAdmin": "superadmin@company.com",
"ttl": 86400,
"saltRounds": 10,
"superAdminPerms": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"features:rw",
"revenue:rw",
"users:rw",
"actions:rw",
"production:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw",
"forecast:rw"
],
"roles": {
"admin": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"features:rw",
"revenue:rw",
"users:rw",
"actions:rw",
"production:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw",
"forecast:rw"
],
"reporting_tool_manager": [
"revenue:rw",
"production:rw",
"reporting:rw",
"settings:r",
"forecast:r"
],
"site_manager": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"actions:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw"
],
"site_operator": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"actions:rw",
"electricity:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"cabinets:rw",
"comments:rw",
"settings:rw",
"ticket:rw",
"alerts:rw"
],
"field_operator": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:r",
"inventory:r",
"reporting:r",
"cabinets:r",
"comments:rw",
"settings:r",
"ticket:r",
"alerts:r"
],
"repair_technician": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"actions:rw",
"electricity:r",
"explorer:r",
"inventory:rw",
"cabinets:r",
"comments:rw",
"settings:r",
"ticket:r",
"alerts:r"
],
"read_only_user": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:r",
"inventory:r",
"reporting:r",
"cabinets:r",
"comments:r",
"settings:r",
"ticket:r",
"alerts:r"
],
"dev": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"cabinets:rw",
"comments:rw",
"settings:rw",
"ticket:rw",
"alerts:rw"
]
},
"roleManagement": {
"admin": [
"site_manager",
"site_operator",
"reporting_tool_manager",
"field_operator",
"repair_technician",
"read_only_user",
"dev"
]
}
}
}

Fields:

  • superAdmin: Email of the super administrator (cannot be modified/deleted)
  • ttl: Token time-to-live in seconds (default: 86400 = 24 hours)
  • saltRounds: BCrypt salt rounds for password hashing
  • superAdminPerms: Permissions granted to super administrator
  • roles: Role definitions with their associated permissions
  • roleManagement: Defines which roles can manage other roles

Permission Format:

  • Permissions use format resource:access where access can be:
    • r = read-only
    • rw = read and write
  • Example: "miner:rw" grants read and write access to miner resources

Available Roles:

  • admin - Full administrative access, can manage all other roles
  • reporting_tool_manager - Access to revenue, production, and reporting features
  • site_manager - Full site operations without user/feature management
  • site_operator - Day-to-day mining operations
  • field_operator - Read-only access with comment/ticket creation
  • repair_technician - Read access with action/inventory/comment management
  • read_only_user - Read-only access to all resources
  • dev - Developer access with elevated explorer/inventory/settings permissions

Role Management Rules:

  • superAdmin: Designated user with all permissions, cannot be modified/deleted via API
  • admin: Can manage all roles listed in roleManagement.admin array
  • Other roles: Cannot manage users (not present in roleManagement object)

config/facs/httpd-oauth2.config.json

{
"h0": {
"method": "google",
"credentials": {
"client": {
"id": "<CLIENT_ID>",
"secret": "<CLIENT_SECRET>"
}
},
"startRedirectPath": "/oauth/google",
"callbackUri": "http://localhost:3000/oauth/google/callback",
"callbackUriUI": "http://localhost:3030"
}
}

Fields:

  • method: OAuth provider (currently only "google" supported)
  • credentials.client.id: Google OAuth2 client ID
  • credentials.client.secret: Google OAuth2 client secret
  • startRedirectPath: Initiation path for OAuth flow
  • callbackUri: OAuth callback URL (must match Google Console configuration)
  • callbackUriUI: Frontend redirect URL after authentication

Capability Codes:

  • m = miner
  • c = container
  • mp = minerpool
  • p = powermeter
  • t = temperature
  • e = electricity
  • f = features
  • r = revenue

OAuth Flow:

  1. User visits /oauth/google on the app-node
  2. Redirected to Google authentication
  3. After auth, Google redirects to callbackUri
  4. App-node issues token and redirects to callbackUriUI

API Reference

API

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

miningos-app-node

Table of Contents

  1. Overview
  2. Architecture
  3. Quick Start
  4. Configuration
  5. API Reference

Overview

Purpose

miningos-app-node serves as the HTTP API gateway for MiningOS.

Key Features

  • HTTP API Gateway - RESTful fastify APIs
  • OAuth2 Authentication (Google) with token-based authorization
  • Role-Based Access Control (RBAC) - Multiple user roles with granular permissions
  • Multi-Cluster RPC - Communicates with multiple orchestrator clusters via DHT-based RPC
  • Request Caching - Configurable LRU caching (10s, 15s, 30s, 15m TTLs)
  • Request Deduplication - Prevents duplicate concurrent requests
  • Audit Logging - Comprehensive logging of user management and security events
  • Schema Validation - JSON Schema validation for all endpoints (Fastify)

Architecture

Technology Stack

ComponentTechnologyPurpose
RuntimeNode.js ≥20JavaScript execution environment
Base Frameworktether-wrk-baseP2P networking and storage foundation
Web FrameworkFastifyHigh-performance HTTP server
P2P NetworkHyperswarmDHT-based peer-to-peer networking
P2P StorageHyperbeeDistributed append-only B-tree
Authenticationsvc-facs-auth + OAuth2Token-based auth with Google OAuth
Local DBSQLite (bfx-facs-db-sqlite)User management and session storage
CachingLRU (bfx-facs-lru)In-memory request caching
LoggingPino (svc-facs-logging)Structured JSON logging with transport
TestingBrittleModern TAP test runner

Data Flow

  1. Client Request → HTTP API (Fastify)
  2. Authentication → Token validation (cached, 1-minute TTL)
  3. Authorization → Permission check (role + capability)
  4. Cache Check → LRU cache lookup (if applicable)
  5. Request Deduplication → Queue identical concurrent requests
  6. RPC Aggregation → Parallel DHT-based RPC requests to ORK clusters (max 2 concurrent)
  7. Response Aggregation → Merge results from multiple ORKs
  8. Cache Update → Store result in LRU cache
  9. Audit Log → Log sensitive operations (if enabled)
  10. Response → JSON response to client

Quick Start

Prerequisites

  • Node.js ≥20.0
  • npm
  • Git

Installation

# Clone the repository
git clone https://github.com/tetherto/miningos-app-node.git
cd miningos-app-node
# Install dependencies
npm install
# Setup configuration files
./setup-config.sh
# (Optional) Include test configuration
./setup-config.sh --test

Basic Configuration

1. Common Configuration

Edit config/common.json:

{
"dir_log": "logs",
"debug": 0,
"site": "production-site-01",
"ttl": 300,
"staticRootPath": "/path/to/mos-app-ui/build/",
"orks": {
"cluster-1": {
"rpcPublicKey": "YOUR_ORK_RPC_PUBLIC_KEY_HERE"
},
"cluster-2": {
"rpcPublicKey": "YOUR_ORK_RPC_PUBLIC_KEY_HERE"
}
},
"cacheTiming": {
"/auth/list-things": "30s",
"/auth/tail-log": "15s",
"/auth/global/data": "15m",
"/auth/actions": "10s"
},
"featureConfig": {}
}

Configuration Notes:

  • dir_log: Directory for log files (required)
  • ttl: Token time-to-live in seconds (default: 300 = 5 minutes)
  • staticRootPath: Path to the UI build directory (required if serving frontend)
  • cacheTiming: Per-endpoint cache TTL values (available: "10s", "15s", "30s", "15m")
  • featureConfig: Feature flags (see config/common.json.example for all available options)

2. OAuth2 Configuration

Edit config/facs/httpd-oauth2.config.json:

{
"h0": {
"method": "google",
"credentials": {
"client": {
"id": "YOUR_GOOGLE_CLIENT_ID",
"secret": "YOUR_GOOGLE_CLIENT_SECRET"
}
},
"users": [
{ "email": "admin@yourcompany.com", "write": true },
{ "email": "operator@yourcompany.com", "write": true },
{ "email": "viewer@yourcompany.com", "write": false }
]
}
}

3. Authentication & Roles Configuration

Set superAdmin email in config/facs/auth.config.json (see full example in Configuration section)

Running the Service

# Development mode
node worker.js --wtype wrk-node-http --env development --port 3000
# Production mode
node worker.js --wtype wrk-node-http --env production --port 3000
# With debug logging
DEBUG="*" node worker.js --wtype wrk-node-http --env development --port 3000

Configuration

Note: Configuration files are created by running ./setup-config.sh, which copies .example files to actual config files.

Configuration Details

config/common.json

{
"debug": 0,
"site": "production-site-01",
"staticRootPath": "/home/user/dev/mos-app-ui/build/",
"ttl": 300,
"dir_log": "logs",
"orks": {
"cluster-1": { "rpcPublicKey": "abc123..." },
"cluster-2": { "rpcPublicKey": "def456..." }
},
"cacheTiming": {
"/auth/list-things": "15s",
"/auth/tail-log": "15s",
"/auth/actions/batch": "30s",
"/auth/actions/:type": "30s",
"/auth/actions/:type/:id": "30s",
"/auth/global/data": "30s"
},
"featureConfig": {
"comments": true,
"inventory": false,
"lvCabinetWidgets": true,
"poolStats": true,
"powerAvailable": true,
"reporting": true,
"settings": true,
"isOneMinItvEnabled": false,
"powerModeTimeline": false,
"totalSystemConsumptionChart": false,
"exportHistKpiDashboard": false,
"showMinerConsumptionDashboard": false,
"totalSystemConsumptionHeader": false,
"energyProvision": true
}
}

Fields:

  • debug: Debug level (0 = info, 1+ = debug)
  • site: Site identifier for this node
  • staticRootPath: Path to static UI files served by HTTP server
  • ttl: Authentication token TTL in seconds (default: 300)
  • dir_log: Log directory path
  • orks: Map of ORK cluster names to RPC public keys
  • cacheTiming: Cache TTL per endpoint (available TTLs: 10s, 15s, 30s, 15m)
  • featureConfig: Static feature flags for enabling/disabling UI features

Cache Timing Notes:

  • Use endpoint paths as keys (e.g., /auth/list-things)
  • Supported TTL values: 10s, 15s, 30s, 15m
  • Unspecified endpoints default to 30s

config/facs/auth.config.json

{
"a0": {
"superAdmin": "superadmin@company.com",
"ttl": 86400,
"saltRounds": 10,
"superAdminPerms": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"features:rw",
"revenue:rw",
"users:rw",
"actions:rw",
"production:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw",
"forecast:rw"
],
"roles": {
"admin": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"features:rw",
"revenue:rw",
"users:rw",
"actions:rw",
"production:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw",
"forecast:rw"
],
"reporting_tool_manager": [
"revenue:rw",
"production:rw",
"reporting:rw",
"settings:r",
"forecast:r"
],
"site_manager": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"actions:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw"
],
"site_operator": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"actions:rw",
"electricity:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"cabinets:rw",
"comments:rw",
"settings:rw",
"ticket:rw",
"alerts:rw"
],
"field_operator": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:r",
"inventory:r",
"reporting:r",
"cabinets:r",
"comments:rw",
"settings:r",
"ticket:r",
"alerts:r"
],
"repair_technician": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"actions:rw",
"electricity:r",
"explorer:r",
"inventory:rw",
"cabinets:r",
"comments:rw",
"settings:r",
"ticket:r",
"alerts:r"
],
"read_only_user": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:r",
"inventory:r",
"reporting:r",
"cabinets:r",
"comments:r",
"settings:r",
"ticket:r",
"alerts:r"
],
"dev": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"cabinets:rw",
"comments:rw",
"settings:rw",
"ticket:rw",
"alerts:rw"
]
},
"roleManagement": {
"admin": [
"site_manager",
"site_operator",
"reporting_tool_manager",
"field_operator",
"repair_technician",
"read_only_user",
"dev"
]
}
}
}

Fields:

  • superAdmin: Email of the super administrator (cannot be modified/deleted)
  • ttl: Token time-to-live in seconds (default: 86400 = 24 hours)
  • saltRounds: BCrypt salt rounds for password hashing
  • superAdminPerms: Permissions granted to super administrator
  • roles: Role definitions with their associated permissions
  • roleManagement: Defines which roles can manage other roles

Permission Format:

  • Permissions use format resource:access where access can be:
    • r = read-only
    • rw = read and write
  • Example: "miner:rw" grants read and write access to miner resources

Available Roles:

  • admin - Full administrative access, can manage all other roles
  • reporting_tool_manager - Access to revenue, production, and reporting features
  • site_manager - Full site operations without user/feature management
  • site_operator - Day-to-day mining operations
  • field_operator - Read-only access with comment/ticket creation
  • repair_technician - Read access with action/inventory/comment management
  • read_only_user - Read-only access to all resources
  • dev - Developer access with elevated explorer/inventory/settings permissions

Role Management Rules:

  • superAdmin: Designated user with all permissions, cannot be modified/deleted via API
  • admin: Can manage all roles listed in roleManagement.admin array
  • Other roles: Cannot manage users (not present in roleManagement object)

config/facs/httpd-oauth2.config.json

{
"h0": {
"method": "google",
"credentials": {
"client": {
"id": "<CLIENT_ID>",
"secret": "<CLIENT_SECRET>"
}
},
"startRedirectPath": "/oauth/google",
"callbackUri": "http://localhost:3000/oauth/google/callback",
"callbackUriUI": "http://localhost:3030"
}
}

Fields:

  • method: OAuth provider (currently only "google" supported)
  • credentials.client.id: Google OAuth2 client ID
  • credentials.client.secret: Google OAuth2 client secret
  • startRedirectPath: Initiation path for OAuth flow
  • callbackUri: OAuth callback URL (must match Google Console configuration)
  • callbackUriUI: Frontend redirect URL after authentication

Capability Codes:

  • m = miner
  • c = container
  • mp = minerpool
  • p = powermeter
  • t = temperature
  • e = electricity
  • f = features
  • r = revenue

OAuth Flow:

  1. User visits /oauth/google on the app-node
  2. Redirected to Google authentication
  3. After auth, Google redirects to callbackUri
  4. App-node issues token and redirects to callbackUriUI

API Reference

API

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

miningos-app-node

Table of Contents

  1. Overview
  2. Architecture
  3. Quick Start
  4. Configuration
  5. API Reference

Overview

Purpose

miningos-app-node serves as the HTTP API gateway for MiningOS.

Key Features

  • HTTP API Gateway - RESTful fastify APIs
  • OAuth2 Authentication (Google) with token-based authorization
  • Role-Based Access Control (RBAC) - Multiple user roles with granular permissions
  • Multi-Cluster RPC - Communicates with multiple orchestrator clusters via DHT-based RPC
  • Request Caching - Configurable LRU caching (10s, 15s, 30s, 15m TTLs)
  • Request Deduplication - Prevents duplicate concurrent requests
  • Audit Logging - Comprehensive logging of user management and security events
  • Schema Validation - JSON Schema validation for all endpoints (Fastify)

Architecture

Technology Stack

ComponentTechnologyPurpose
RuntimeNode.js ≥20JavaScript execution environment
Base Frameworktether-wrk-baseP2P networking and storage foundation
Web FrameworkFastifyHigh-performance HTTP server
P2P NetworkHyperswarmDHT-based peer-to-peer networking
P2P StorageHyperbeeDistributed append-only B-tree
Authenticationsvc-facs-auth + OAuth2Token-based auth with Google OAuth
Local DBSQLite (bfx-facs-db-sqlite)User management and session storage
CachingLRU (bfx-facs-lru)In-memory request caching
LoggingPino (svc-facs-logging)Structured JSON logging with transport
TestingBrittleModern TAP test runner

Data Flow

  1. Client Request → HTTP API (Fastify)
  2. Authentication → Token validation (cached, 1-minute TTL)
  3. Authorization → Permission check (role + capability)
  4. Cache Check → LRU cache lookup (if applicable)
  5. Request Deduplication → Queue identical concurrent requests
  6. RPC Aggregation → Parallel DHT-based RPC requests to ORK clusters (max 2 concurrent)
  7. Response Aggregation → Merge results from multiple ORKs
  8. Cache Update → Store result in LRU cache
  9. Audit Log → Log sensitive operations (if enabled)
  10. Response → JSON response to client

Quick Start

Prerequisites

  • Node.js ≥20.0
  • npm
  • Git

Installation

# Clone the repository
git clone https://github.com/tetherto/miningos-app-node.git
cd miningos-app-node
# Install dependencies
npm install
# Setup configuration files
./setup-config.sh
# (Optional) Include test configuration
./setup-config.sh --test

Basic Configuration

1. Common Configuration

Edit config/common.json:

{
"dir_log": "logs",
"debug": 0,
"site": "production-site-01",
"ttl": 300,
"staticRootPath": "/path/to/mos-app-ui/build/",
"orks": {
"cluster-1": {
"rpcPublicKey": "YOUR_ORK_RPC_PUBLIC_KEY_HERE"
},
"cluster-2": {
"rpcPublicKey": "YOUR_ORK_RPC_PUBLIC_KEY_HERE"
}
},
"cacheTiming": {
"/auth/list-things": "30s",
"/auth/tail-log": "15s",
"/auth/global/data": "15m",
"/auth/actions": "10s"
},
"featureConfig": {}
}

Configuration Notes:

  • dir_log: Directory for log files (required)
  • ttl: Token time-to-live in seconds (default: 300 = 5 minutes)
  • staticRootPath: Path to the UI build directory (required if serving frontend)
  • cacheTiming: Per-endpoint cache TTL values (available: "10s", "15s", "30s", "15m")
  • featureConfig: Feature flags (see config/common.json.example for all available options)

2. OAuth2 Configuration

Edit config/facs/httpd-oauth2.config.json:

{
"h0": {
"method": "google",
"credentials": {
"client": {
"id": "YOUR_GOOGLE_CLIENT_ID",
"secret": "YOUR_GOOGLE_CLIENT_SECRET"
}
},
"users": [
{ "email": "admin@yourcompany.com", "write": true },
{ "email": "operator@yourcompany.com", "write": true },
{ "email": "viewer@yourcompany.com", "write": false }
]
}
}

3. Authentication & Roles Configuration

Set superAdmin email in config/facs/auth.config.json (see full example in Configuration section)

Running the Service

# Development mode
node worker.js --wtype wrk-node-http --env development --port 3000
# Production mode
node worker.js --wtype wrk-node-http --env production --port 3000
# With debug logging
DEBUG="*" node worker.js --wtype wrk-node-http --env development --port 3000

Configuration

Note: Configuration files are created by running ./setup-config.sh, which copies .example files to actual config files.

Configuration Details

config/common.json

{
"debug": 0,
"site": "production-site-01",
"staticRootPath": "/home/user/dev/mos-app-ui/build/",
"ttl": 300,
"dir_log": "logs",
"orks": {
"cluster-1": { "rpcPublicKey": "abc123..." },
"cluster-2": { "rpcPublicKey": "def456..." }
},
"cacheTiming": {
"/auth/list-things": "15s",
"/auth/tail-log": "15s",
"/auth/actions/batch": "30s",
"/auth/actions/:type": "30s",
"/auth/actions/:type/:id": "30s",
"/auth/global/data": "30s"
},
"featureConfig": {
"comments": true,
"inventory": false,
"lvCabinetWidgets": true,
"poolStats": true,
"powerAvailable": true,
"reporting": true,
"settings": true,
"isOneMinItvEnabled": false,
"powerModeTimeline": false,
"totalSystemConsumptionChart": false,
"exportHistKpiDashboard": false,
"showMinerConsumptionDashboard": false,
"totalSystemConsumptionHeader": false,
"energyProvision": true
}
}

Fields:

  • debug: Debug level (0 = info, 1+ = debug)
  • site: Site identifier for this node
  • staticRootPath: Path to static UI files served by HTTP server
  • ttl: Authentication token TTL in seconds (default: 300)
  • dir_log: Log directory path
  • orks: Map of ORK cluster names to RPC public keys
  • cacheTiming: Cache TTL per endpoint (available TTLs: 10s, 15s, 30s, 15m)
  • featureConfig: Static feature flags for enabling/disabling UI features

Cache Timing Notes:

  • Use endpoint paths as keys (e.g., /auth/list-things)
  • Supported TTL values: 10s, 15s, 30s, 15m
  • Unspecified endpoints default to 30s

config/facs/auth.config.json

{
"a0": {
"superAdmin": "superadmin@company.com",
"ttl": 86400,
"saltRounds": 10,
"superAdminPerms": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"features:rw",
"revenue:rw",
"users:rw",
"actions:rw",
"production:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw",
"forecast:rw"
],
"roles": {
"admin": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"features:rw",
"revenue:rw",
"users:rw",
"actions:rw",
"production:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw",
"forecast:rw"
],
"reporting_tool_manager": [
"revenue:rw",
"production:rw",
"reporting:rw",
"settings:r",
"forecast:r"
],
"site_manager": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"actions:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw"
],
"site_operator": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"actions:rw",
"electricity:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"cabinets:rw",
"comments:rw",
"settings:rw",
"ticket:rw",
"alerts:rw"
],
"field_operator": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:r",
"inventory:r",
"reporting:r",
"cabinets:r",
"comments:rw",
"settings:r",
"ticket:r",
"alerts:r"
],
"repair_technician": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"actions:rw",
"electricity:r",
"explorer:r",
"inventory:rw",
"cabinets:r",
"comments:rw",
"settings:r",
"ticket:r",
"alerts:r"
],
"read_only_user": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:r",
"inventory:r",
"reporting:r",
"cabinets:r",
"comments:r",
"settings:r",
"ticket:r",
"alerts:r"
],
"dev": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"cabinets:rw",
"comments:rw",
"settings:rw",
"ticket:rw",
"alerts:rw"
]
},
"roleManagement": {
"admin": [
"site_manager",
"site_operator",
"reporting_tool_manager",
"field_operator",
"repair_technician",
"read_only_user",
"dev"
]
}
}
}

Fields:

  • superAdmin: Email of the super administrator (cannot be modified/deleted)
  • ttl: Token time-to-live in seconds (default: 86400 = 24 hours)
  • saltRounds: BCrypt salt rounds for password hashing
  • superAdminPerms: Permissions granted to super administrator
  • roles: Role definitions with their associated permissions
  • roleManagement: Defines which roles can manage other roles

Permission Format:

  • Permissions use format resource:access where access can be:
    • r = read-only
    • rw = read and write
  • Example: "miner:rw" grants read and write access to miner resources

Available Roles:

  • admin - Full administrative access, can manage all other roles
  • reporting_tool_manager - Access to revenue, production, and reporting features
  • site_manager - Full site operations without user/feature management
  • site_operator - Day-to-day mining operations
  • field_operator - Read-only access with comment/ticket creation
  • repair_technician - Read access with action/inventory/comment management
  • read_only_user - Read-only access to all resources
  • dev - Developer access with elevated explorer/inventory/settings permissions

Role Management Rules:

  • superAdmin: Designated user with all permissions, cannot be modified/deleted via API
  • admin: Can manage all roles listed in roleManagement.admin array
  • Other roles: Cannot manage users (not present in roleManagement object)

config/facs/httpd-oauth2.config.json

{
"h0": {
"method": "google",
"credentials": {
"client": {
"id": "<CLIENT_ID>",
"secret": "<CLIENT_SECRET>"
}
},
"startRedirectPath": "/oauth/google",
"callbackUri": "http://localhost:3000/oauth/google/callback",
"callbackUriUI": "http://localhost:3030"
}
}

Fields:

  • method: OAuth provider (currently only "google" supported)
  • credentials.client.id: Google OAuth2 client ID
  • credentials.client.secret: Google OAuth2 client secret
  • startRedirectPath: Initiation path for OAuth flow
  • callbackUri: OAuth callback URL (must match Google Console configuration)
  • callbackUriUI: Frontend redirect URL after authentication

Capability Codes:

  • m = miner
  • c = container
  • mp = minerpool
  • p = powermeter
  • t = temperature
  • e = electricity
  • f = features
  • r = revenue

OAuth Flow:

  1. User visits /oauth/google on the app-node
  2. Redirected to Google authentication
  3. After auth, Google redirects to callbackUri
  4. App-node issues token and redirects to callbackUriUI

API Reference

API

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

miningos-app-node

Table of Contents

  1. Overview
  2. Architecture
  3. Quick Start
  4. Configuration
  5. API Reference

Overview

Purpose

miningos-app-node serves as the HTTP API gateway for MiningOS.

Key Features

  • HTTP API Gateway - RESTful fastify APIs
  • OAuth2 Authentication (Google) with token-based authorization
  • Role-Based Access Control (RBAC) - Multiple user roles with granular permissions
  • Multi-Cluster RPC - Communicates with multiple orchestrator clusters via DHT-based RPC
  • Request Caching - Configurable LRU caching (10s, 15s, 30s, 15m TTLs)
  • Request Deduplication - Prevents duplicate concurrent requests
  • Audit Logging - Comprehensive logging of user management and security events
  • Schema Validation - JSON Schema validation for all endpoints (Fastify)

Architecture

Technology Stack

ComponentTechnologyPurpose
RuntimeNode.js ≥20JavaScript execution environment
Base Frameworktether-wrk-baseP2P networking and storage foundation
Web FrameworkFastifyHigh-performance HTTP server
P2P NetworkHyperswarmDHT-based peer-to-peer networking
P2P StorageHyperbeeDistributed append-only B-tree
Authenticationsvc-facs-auth + OAuth2Token-based auth with Google OAuth
Local DBSQLite (bfx-facs-db-sqlite)User management and session storage
CachingLRU (bfx-facs-lru)In-memory request caching
LoggingPino (svc-facs-logging)Structured JSON logging with transport
TestingBrittleModern TAP test runner

Data Flow

  1. Client Request → HTTP API (Fastify)
  2. Authentication → Token validation (cached, 1-minute TTL)
  3. Authorization → Permission check (role + capability)
  4. Cache Check → LRU cache lookup (if applicable)
  5. Request Deduplication → Queue identical concurrent requests
  6. RPC Aggregation → Parallel DHT-based RPC requests to ORK clusters (max 2 concurrent)
  7. Response Aggregation → Merge results from multiple ORKs
  8. Cache Update → Store result in LRU cache
  9. Audit Log → Log sensitive operations (if enabled)
  10. Response → JSON response to client

Quick Start

Prerequisites

  • Node.js ≥20.0
  • npm
  • Git

Installation

# Clone the repository
git clone https://github.com/tetherto/miningos-app-node.git
cd miningos-app-node
# Install dependencies
npm install
# Setup configuration files
./setup-config.sh
# (Optional) Include test configuration
./setup-config.sh --test

Basic Configuration

1. Common Configuration

Edit config/common.json:

{
"dir_log": "logs",
"debug": 0,
"site": "production-site-01",
"ttl": 300,
"staticRootPath": "/path/to/mos-app-ui/build/",
"orks": {
"cluster-1": {
"rpcPublicKey": "YOUR_ORK_RPC_PUBLIC_KEY_HERE"
},
"cluster-2": {
"rpcPublicKey": "YOUR_ORK_RPC_PUBLIC_KEY_HERE"
}
},
"cacheTiming": {
"/auth/list-things": "30s",
"/auth/tail-log": "15s",
"/auth/global/data": "15m",
"/auth/actions": "10s"
},
"featureConfig": {}
}

Configuration Notes:

  • dir_log: Directory for log files (required)
  • ttl: Token time-to-live in seconds (default: 300 = 5 minutes)
  • staticRootPath: Path to the UI build directory (required if serving frontend)
  • cacheTiming: Per-endpoint cache TTL values (available: "10s", "15s", "30s", "15m")
  • featureConfig: Feature flags (see config/common.json.example for all available options)

2. OAuth2 Configuration

Edit config/facs/httpd-oauth2.config.json:

{
"h0": {
"method": "google",
"credentials": {
"client": {
"id": "YOUR_GOOGLE_CLIENT_ID",
"secret": "YOUR_GOOGLE_CLIENT_SECRET"
}
},
"users": [
{ "email": "admin@yourcompany.com", "write": true },
{ "email": "operator@yourcompany.com", "write": true },
{ "email": "viewer@yourcompany.com", "write": false }
]
}
}

3. Authentication & Roles Configuration

Set superAdmin email in config/facs/auth.config.json (see full example in Configuration section)

Running the Service

# Development mode
node worker.js --wtype wrk-node-http --env development --port 3000
# Production mode
node worker.js --wtype wrk-node-http --env production --port 3000
# With debug logging
DEBUG="*" node worker.js --wtype wrk-node-http --env development --port 3000

Configuration

Note: Configuration files are created by running ./setup-config.sh, which copies .example files to actual config files.

Configuration Details

config/common.json

{
"debug": 0,
"site": "production-site-01",
"staticRootPath": "/home/user/dev/mos-app-ui/build/",
"ttl": 300,
"dir_log": "logs",
"orks": {
"cluster-1": { "rpcPublicKey": "abc123..." },
"cluster-2": { "rpcPublicKey": "def456..." }
},
"cacheTiming": {
"/auth/list-things": "15s",
"/auth/tail-log": "15s",
"/auth/actions/batch": "30s",
"/auth/actions/:type": "30s",
"/auth/actions/:type/:id": "30s",
"/auth/global/data": "30s"
},
"featureConfig": {
"comments": true,
"inventory": false,
"lvCabinetWidgets": true,
"poolStats": true,
"powerAvailable": true,
"reporting": true,
"settings": true,
"isOneMinItvEnabled": false,
"powerModeTimeline": false,
"totalSystemConsumptionChart": false,
"exportHistKpiDashboard": false,
"showMinerConsumptionDashboard": false,
"totalSystemConsumptionHeader": false,
"energyProvision": true
}
}

Fields:

  • debug: Debug level (0 = info, 1+ = debug)
  • site: Site identifier for this node
  • staticRootPath: Path to static UI files served by HTTP server
  • ttl: Authentication token TTL in seconds (default: 300)
  • dir_log: Log directory path
  • orks: Map of ORK cluster names to RPC public keys
  • cacheTiming: Cache TTL per endpoint (available TTLs: 10s, 15s, 30s, 15m)
  • featureConfig: Static feature flags for enabling/disabling UI features

Cache Timing Notes:

  • Use endpoint paths as keys (e.g., /auth/list-things)
  • Supported TTL values: 10s, 15s, 30s, 15m
  • Unspecified endpoints default to 30s

config/facs/auth.config.json

{
"a0": {
"superAdmin": "superadmin@company.com",
"ttl": 86400,
"saltRounds": 10,
"superAdminPerms": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"features:rw",
"revenue:rw",
"users:rw",
"actions:rw",
"production:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw",
"forecast:rw"
],
"roles": {
"admin": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"features:rw",
"revenue:rw",
"users:rw",
"actions:rw",
"production:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw",
"forecast:rw"
],
"reporting_tool_manager": [
"revenue:rw",
"production:rw",
"reporting:rw",
"settings:r",
"forecast:r"
],
"site_manager": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"electricity:rw",
"actions:rw",
"alerts:rw",
"cabinets:rw",
"comments:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"settings:rw",
"ticket:rw"
],
"site_operator": [
"miner:rw",
"container:rw",
"minerpool:rw",
"powermeter:rw",
"temp:rw",
"actions:rw",
"electricity:rw",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"cabinets:rw",
"comments:rw",
"settings:rw",
"ticket:rw",
"alerts:rw"
],
"field_operator": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:r",
"inventory:r",
"reporting:r",
"cabinets:r",
"comments:rw",
"settings:r",
"ticket:r",
"alerts:r"
],
"repair_technician": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"actions:rw",
"electricity:r",
"explorer:r",
"inventory:rw",
"cabinets:r",
"comments:rw",
"settings:r",
"ticket:r",
"alerts:r"
],
"read_only_user": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:r",
"inventory:r",
"reporting:r",
"cabinets:r",
"comments:r",
"settings:r",
"ticket:r",
"alerts:r"
],
"dev": [
"miner:r",
"container:r",
"minerpool:r",
"powermeter:r",
"temp:r",
"electricity:r",
"explorer:rw",
"inventory:rw",
"reporting:rw",
"cabinets:rw",
"comments:rw",
"settings:rw",
"ticket:rw",
"alerts:rw"
]
},
"roleManagement": {
"admin": [
"site_manager",
"site_operator",
"reporting_tool_manager",
"field_operator",
"repair_technician",
"read_only_user",
"dev"
]
}
}
}

Fields:

  • superAdmin: Email of the super administrator (cannot be modified/deleted)
  • ttl: Token time-to-live in seconds (default: 86400 = 24 hours)
  • saltRounds: BCrypt salt rounds for password hashing
  • superAdminPerms: Permissions granted to super administrator
  • roles: Role definitions with their associated permissions
  • roleManagement: Defines which roles can manage other roles

Permission Format:

  • Permissions use format resource:access where access can be:
    • r = read-only
    • rw = read and write
  • Example: "miner:rw" grants read and write access to miner resources

Available Roles:

  • admin - Full administrative access, can manage all other roles
  • reporting_tool_manager - Access to revenue, production, and reporting features
  • site_manager - Full site operations without user/feature management
  • site_operator - Day-to-day mining operations
  • field_operator - Read-only access with comment/ticket creation
  • repair_technician - Read access with action/inventory/comment management
  • read_only_user - Read-only access to all resources
  • dev - Developer access with elevated explorer/inventory/settings permissions

Role Management Rules:

  • superAdmin: Designated user with all permissions, cannot be modified/deleted via API
  • admin: Can manage all roles listed in roleManagement.admin array
  • Other roles: Cannot manage users (not present in roleManagement object)

config/facs/httpd-oauth2.config.json

{
"h0": {
"method": "google",
"credentials": {
"client": {
"id": "<CLIENT_ID>",
"secret": "<CLIENT_SECRET>"
}
},
"startRedirectPath": "/oauth/google",
"callbackUri": "http://localhost:3000/oauth/google/callback",
"callbackUriUI": "http://localhost:3030"
}
}

Fields:

  • method: OAuth provider (currently only "google" supported)
  • credentials.client.id: Google OAuth2 client ID
  • credentials.client.secret: Google OAuth2 client secret
  • startRedirectPath: Initiation path for OAuth flow
  • callbackUri: OAuth callback URL (must match Google Console configuration)
  • callbackUriUI: Frontend redirect URL after authentication

Capability Codes:

  • m = miner
  • c = container
  • mp = minerpool
  • p = powermeter
  • t = temperature
  • e = electricity
  • f = features
  • r = revenue

OAuth Flow:

  1. User visits /oauth/google on the app-node
  2. Redirected to Google authentication
  3. After auth, Google redirects to callbackUri
  4. App-node issues token and redirects to callbackUriUI

API Reference

API

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages