Skip to content

Latest commit

Β 

History

History
594 lines (481 loc) Β· 14.6 KB

File metadata and controls

594 lines (481 loc) Β· 14.6 KB

Enterprise API endpoints that allow enterprise users to request and manage synq keys using their enterprise API key:

πŸ”‘ Enterprise API Endpoints

Base URL

Production: https://startsynqing.com/api
Development: http://localhost:3000/api  

Authentication

All enterprise endpoints require the Enterprise API Key in the header:

X-Enterprise-API-Key: your-enterprise-api-key
Content-Type: application/json

πŸ“‹ Available Enterprise Endpoints

1. Create New Synchronizer (Generate Synq Key)

Creates a named synchronizer with a unique synq key

POST /synq-keys/enterprise/synchronizer

Headers:

X-Enterprise-API-Key: your-enterprise-api-key
Content-Type: application/json

Request Body:

{
  "name": "Production Server 1"
}

Response (201 Created):

{
  "success": true,
  "message": "Successfully generated synchronizer",
  "synchronizer": {
    "id": "uuid-here",
    "key": "b1df0d63-83b3-478d-a55f-a6c402e74185",
    "name": "Production Server 1"
  }
}

cURL Example:

curl -X POST https://startsynqing.com/api/synq-keys/enterprise/synchronizer \
  -H "X-Enterprise-API-Key: your-api-key-here" \
  -H "Content-Type: application/json" \
  -d '{"name": "Production Server 1"}'

2. Get Enterprise Preferences

Retrieve user preferences for automatic CLI configuration

GET /synq-keys/enterprise/preferences

Headers:

X-Enterprise-API-Key: your-enterprise-api-key

Response (200 OK):

{
  "success": true,
  "message": "Preferences retrieved successfully",
  "preferences": {
    "walletAddress": "0x1234...abcd", 
    "dashboardPassword": "β€’β€’β€’β€’β€’β€’β€’β€’",
    "defaultAction": "service",
    "web": true,
  },
  "owner": {
    "walletAddress": "0x1234...abcd"
  }
}

cURL Example:

curl -X GET https://startsynqing.com/api/synq-keys/enterprise/preferences \
  -H "X-Enterprise-API-Key: your-api-key-here"

**Preference Fields:**
- `walletAddress`: Default wallet address for automatic CLI setup
- `dashboardPassword`: Default dashboard password (masked for security)
- `defaultAction`: Default action to execute (start/service/web)
- `web`: Boolean to automatically start web dashboard if true

3. List All Synchronizers

Get all synq keys/synchronizers for your enterprise account

GET /synq-keys/enterprise/synchronizers

Headers:

X-Enterprise-API-Key: your-enterprise-api-key

Response (200 OK):

{
  "success": true,
  "synchronizers": [
    {
      "id": "uuid-1",
      "key": "b1df0d63-83b3-478d-a55f-a6c402e74185",
      "name": "Production Server 1",
      "isEnabled": true,
      "createdAt": "2024-01-15T10:30:00Z"
    },
    {
      "id": "uuid-2", 
      "key": "c2ef1e74-94c4-589e-b66g-b7d513f85296",
      "name": "Staging Server",
      "isEnabled": false,
      "createdAt": "2024-01-16T14:20:00Z"
    }
  ]
}

cURL Example:

curl -X GET https://startsynqing.com/api/synq-keys/enterprise/synchronizers \
  -H "X-Enterprise-API-Key: your-api-key-here"

4. Enable/Disable Synchronizer

Toggle a synchronizer's enabled status

PUT /synq-keys/enterprise/synchronizer/:id/toggle

Headers:

X-Enterprise-API-Key: your-enterprise-api-key
Content-Type: application/json

Request Body:

{
  "isEnabled": true
}

Response (200 OK):

{
  "success": true,
  "message": "Synchronizer enabled successfully",
  "synchronizer": {
    "id": "uuid-here",
    "key": "b1df0d63-83b3-478d-a55f-a6c402e74185", 
    "name": "Production Server 1",
    "isEnabled": true
  }
}

cURL Example:

curl -X PUT https://startsynqing.com/api/synq-keys/enterprise/synchronizer/uuid-here/toggle \
  -H "X-Enterprise-API-Key: your-api-key-here" \
  -H "Content-Type: application/json" \
  -d '{"isEnabled": false}'

πŸ–₯️ CLI Enterprise Integration

The Synchronizer CLI provides seamless integration with the Enterprise API for automated deployment and management.

Installation

npm install -g synchronizer-cli

Enterprise CLI Commands

1. Interactive Enterprise Setup

Guided setup with prompts for enterprise users

synchronize api

Features:

  • βœ… Prompts for Enterprise API Key
  • βœ… Optional synchronizer name input
  • βœ… Wallet address configuration
  • βœ… Dashboard password setup
  • βœ… Action selection (Start/Service/Web/Quit)
  • βœ… Automatic synq key generation
  • βœ… Complete CLI configuration

Example Flow:

$ synchronize api
🏒 Enterprise API Setup
Automatically provision a synq key via Enterprise API

? Enterprise API Key: β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’
? Synchronizer name (optional): Production-Server-1
βœ… Synchronizer created successfully!
   ID: uuid-12345
   Name: Production-Server-1
   Synq Key: b1df0d63-83b3-478d-a55f-a6c402e74185

? Wallet address: 0x1234567890abcdef...
? Set a password for the web dashboard? Yes
? Dashboard password: β€’β€’β€’β€’β€’β€’β€’β€’
? What would you like to do next? [S]tart, Se[R]vice, [W]eb, [Q]uit: R

πŸŽ‰ Enterprise API setup complete!
βš™οΈ Generating systemd service...

2. Automatic Enterprise Setup

Hands-free setup using API preferences (recommended for automation)

synchronize --api <enterprise-api-key>

Features:

  • βœ… Zero prompts - completely automatic
  • βœ… Uses API preferences for wallet, password, and default action
  • βœ… Immediate execution of configured default action
  • βœ… Perfect for scripts and automated deployments
  • βœ… Fallback support if preferences not set

Example:

$ synchronize --api your-enterprise-api-key-here
🏒 Automatic Enterprise API Setup
Using API preferences for hands-free configuration

πŸ”„ Fetching preferences from Enterprise API...
βœ… Preferences retrieved successfully!
   Wallet: 0x1234...abcd
   Password: β€’β€’β€’β€’β€’β€’β€’β€’
   Default Action: service

πŸ”„ Creating synchronizer via Enterprise API...
βœ… Synchronizer created successfully!
   ID: uuid-67890
   Name: auto-generated-name
   Synq Key: c2ef1e74-94c4-589e-b66g-b7d513f85296

πŸŽ‰ Automatic Enterprise API setup complete!
πŸ’° Wallet: 0x1234567890abcdef...
πŸ”’ Dashboard password protection enabled

πŸš€ Executing default action: service
βš™οΈ Generating systemd service...
βœ… Service file generated successfully!

Enterprise Deployment Scenarios

Scenario 1: Manual Server Setup

# SSH into server
ssh user@production-server-1

# Install CLI globally
npm install -g synchronizer-cli

# Interactive enterprise setup
synchronize api
# Follow prompts, choose "Service" to generate systemd service

# Install and start service
sudo cp ~/.synchronizer-cli/synchronizer-cli.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable synchronizer-cli
sudo systemctl start synchronizer-cli

Scenario 2: Automated Deployment Script

#!/bin/bash
# deploy-synchronizer.sh

SERVER=$1
API_KEY=$2

if [ -z "$SERVER" ] || [ -z "$API_KEY" ]; then
  echo "Usage: $0 <server> <enterprise-api-key>"
  exit 1
fi

echo "Deploying synchronizer to $SERVER..."

ssh $SERVER << EOF
  # Install CLI
  npm install -g synchronizer-cli
  
  # Automatic setup with API preferences
  synchronize --api $API_KEY
  
  # Service is automatically generated and configuration is complete
  echo "Synchronizer deployed successfully!"
EOF

Scenario 3: Docker Deployment

FROM node:20-alpine

# Install CLI globally
RUN npm install -g synchronizer-cli

# Copy enterprise API key (use secrets in production)
ARG ENTERPRISE_API_KEY
ENV ENTERPRISE_API_KEY=$ENTERPRISE_API_KEY

# Setup and run
CMD ["sh", "-c", "synchronize --api $ENTERPRISE_API_KEY"]

Scenario 4: Kubernetes Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: synchronizer-enterprise
spec:
  replicas: 3
  selector:
    matchLabels:
      app: synchronizer
  template:
    metadata:
      labels:
        app: synchronizer
    spec:
      containers:
      - name: synchronizer
        image: node:20-alpine
        command: ["/bin/sh"]
        args: ["-c", "npm install -g synchronizer-cli && synchronize --api $ENTERPRISE_API_KEY"]
        env:
        - name: ENTERPRISE_API_KEY
          valueFrom:
            secretKeyRef:
              name: enterprise-secrets
              key: api-key

Scenario 5: Ready-to-Deploy Cloud Script

Use the included startup-synchronizer.sh script for instant cloud deployment

The synchronizer-cli package includes a production-ready startup script specifically designed for cloud instances:

πŸ“„ File: startup-synchronizer.sh (included in npm package)

Features:

  • βœ… Complete automation - zero manual steps required
  • βœ… Multi-cloud support - AWS EC2, DigitalOcean, Google Cloud, Azure
  • βœ… Enterprise API integration - uses synchronize --api for hands-free setup
  • βœ… Error handling - exits on any failure for reliable deployments
  • βœ… Progress indicators - visual feedback during installation
  • βœ… User management - configurable for different cloud providers

Quick Deployment:

# Download and customize the script
curl -o startup-synchronizer.sh https://raw.githubusercontent.com/multisynq/synchronizer-cli/main/startup-synchronizer.sh

# Replace API key placeholder
sed -i 's/\[your-api-key\]/your-actual-enterprise-api-key-here/g' startup-synchronizer.sh

# Deploy to EC2 instance (as User Data)
aws ec2 run-instances \
  --image-id ami-0abcdef1234567890 \
  --instance-type t3.micro \
  --user-data file://startup-synchronizer.sh

# Or deploy to DigitalOcean droplet
doctl compute droplet create synchronizer-node \
  --size s-1vcpu-1gb \
  --image ubuntu-20-04-x64 \
  --user-data-file startup-synchronizer.sh

Script Contents Preview:

#!/bin/bash
# startup-synchronizer.sh - Ready-to-deploy cloud startup script
set -e  # Exit on any error

echo "πŸš€ Starting Synchronizer Cloud Instance Setup..."

# Update package list and install dependencies
apt-get update -y
apt-get install -y curl wget

# Configure for your cloud provider
USERNAME="ubuntu"  # Change to "root" for DigitalOcean

# Install Node.js via NVM and synchronizer-cli
su - $USERNAME -c "
  curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
  export NVM_DIR=\"/home/$USERNAME/.nvm\"
  [ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\"
  nvm install --lts
  npm install -g synchronizer-cli
  synchronize --api [your-api-key]  # Replace with your Enterprise API key
"

echo "βœ… Synchronizer cloud instance setup complete!"

Cloud Provider Customization:

  • AWS EC2: Use as-is (username: ubuntu)
  • DigitalOcean: Change USERNAME="ubuntu" to USERNAME="root"
  • Google Cloud: Use as-is (username: ubuntu)
  • Azure: Use as-is (username: azureuser) or customize as needed

Enterprise CLI Features

Configuration Management

  • βœ… Automatic config generation from Enterprise API
  • βœ… Secure credential storage in ~/.synchronizer-cli/config.json
  • βœ… Enterprise API key persistence for future operations
  • βœ… Synchronizer ID tracking for management

Service Integration

  • βœ… Systemd service generation for headless operation
  • βœ… Auto-restart capabilities with proper error handling
  • βœ… Docker container management with platform detection
  • βœ… Web dashboard setup with password protection

Monitoring & Management

  • βœ… Real-time status checking via synchronize status
  • βœ… Points tracking via synchronize points
  • βœ… Container logs access via synchronize web
  • βœ… Update monitoring via synchronize check-updates

πŸ”’ Security & Access Control

Enterprise API Key Requirements:

  • βœ… Must be a valid enterprise user (isEnterprise: true)
  • βœ… API key must exist in the database
  • βœ… User must own the synchronizers they're modifying
  • βœ… Keys are automatically associated with the enterprise user

CLI Security Features:

  • βœ… Password masking in terminal input
  • βœ… Secure config storage with proper file permissions
  • βœ… API key encryption in local storage
  • βœ… Dashboard authentication with configurable passwords

Error Responses:

// 401 Unauthorized
{
  "success": false,
  "message": "Unauthorized"
}

// 400 Bad Request  
{
  "success": false,
  "message": "Synchronizer name is required"
}

// 404 Not Found
{
  "success": false,
  "message": "Synchronizer not found"
}

// 403 Forbidden
{
  "success": false,
  "message": "You can only modify your own synchronizers"
}

πŸ› οΈ Integration Examples

Node.js/JavaScript:

const API_BASE = 'https://startsynqing.com/api';
const ENTERPRISE_API_KEY = 'your-enterprise-api-key';

// Create a new synchronizer
async function createSynchronizer(name) {
  const response = await fetch(`${API_BASE}/synq-keys/enterprise/synchronizer`, {
    method: 'POST',
    headers: {
      'X-Enterprise-API-Key': ENTERPRISE_API_KEY,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ name })
  });
  
  return await response.json();
}

// List all synchronizers
async function listSynchronizers() {
  const response = await fetch(`${API_BASE}/synq-keys/enterprise/synchronizers`, {
    headers: {
      'X-Enterprise-API-Key': ENTERPRISE_API_KEY
    }
  });
  
  return await response.json();
}

// Toggle synchronizer
async function toggleSynchronizer(id, isEnabled) {
  const response = await fetch(`${API_BASE}/synq-keys/enterprise/synchronizer/${id}/toggle`, {
    method: 'PUT',
    headers: {
      'X-Enterprise-API-Key': ENTERPRISE_API_KEY,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ isEnabled })
  });
  
  return await response.json();
}

Python:

import requests

API_BASE = 'https://startsynqing.com/api'
HEADERS = {
    'X-Enterprise-API-Key': 'your-enterprise-api-key',
    'Content-Type': 'application/json'
}

# Create synchronizer
def create_synchronizer(name):
    response = requests.post(
        f'{API_BASE}/synq-keys/enterprise/synchronizer',
        headers=HEADERS,
        json={'name': name}
    )
    return response.json()

# List synchronizers  
def list_synchronizers():
    response = requests.get(
        f'{API_BASE}/synq-keys/enterprise/synchronizers',
        headers={'X-Enterprise-API-Key': HEADERS['X-Enterprise-API-Key']}
    )
    return response.json()

These endpoints allow enterprise users to programmatically manage their synq keys for automated deployment and scaling! πŸš€