Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

cl-host-app-api

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cl-host-app-api

Api for Host Client App (Dashboard)

latest
npmnpm
Version
1.3.1
Version published
Maintainers
1
Created
Source

Host App Client

Client library for interacting with Host App Api. For use in dashboard browser/mobile app.

Terminology

Host

Host is a container with a dedicated IP address. Each user can have multiple containers. Containers have different sizes (cpu, mem, disk).

Host Application

Host Application provides user interface for project management and monitoring of host resources (cpu, mem, disk).

Project

Project is a cluster of services (Docker containers) linked together in an isolated network. Each project must have it's unique slug name. Slug is a value at least 3 characters long and can only contain -[a-z0-9] (for example my-project-1).

Project Service

Project service is a docker container running a specific image (for example node:4, or mysql, etc.). Each service can have defined specific configuration (for example {"rootPassword": "test1234", "defaultDatabase": "test"}) and port forwarding (host port to container port). Multiple ports can be assigned to each service but no two services can share the same source port (host port).

Usage

Local dev

For local development use DummyHostAppClient to simulate real client behaviour without running entire infrastructure.

Basic usage

/*
  NOTE: `HostAppApi` is for example showcase only and should be replaced with relative path or else 
*/
import { DummyHostAppClient } from 'HostAppApi'
import {
  Project,
  createProjectSlug,
  createProjectName,
  createServiceCode,
  createNetworkPort,
  ClientEvents,
  ProjectState
} from 'HostAppApi'

const client = new DummyHostAppClient()

client.on(ClientEvents.ProjectAdded, project => {
  console.log('project added', project)
})

client.on(ClientEvents.ProjectUpdated, project => {
  console.log('project updated', project)
})

client.on(ClientEvents.ProjectRemoved, project => {
  console.log('project removed', project)
})

const testProject1 = {
  slug: createProjectSlug('project-1'),
  name: createProjectName('Test Project 1'),
  services: [
    {
      service: createServiceCode('node:4'),
      base: true,
      ports: [
        {
          source: createNetworkPort(2000),
          destination: createNetworkPort(3000)
        }
      ]
    } 
  ]
}

client.createProject(testProject1)

testProject1.name = createProjectName('Test Project 1 Updated')
client.updateProject(testProject1)

client.startProject(testProject1)
client.stopProject(testProject1)

client.deleteProject(testProject1)

Dummy Client specific methods

Call these methods for local tests

  • initTestData - Auto generates predefined projects (to simulate existing projects on real host)
  • startSysUsageGenerator - Starts hardware usage events simulation (cpu, mem, disk usage events)
  • endSysUsageGenerator - Stops hardware usage events simulation. Use this method to clear interval timer (needed to finish tests, etc., use in afterAll method for example)

For example

client.initTestData()
client.startSysUsageGenerator()

FAQs

Package last updated on 18 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts