npm package: @package-uploader/core
Description: Patch and upload Rise courses to LMS platforms
Latest version: 1.11.11

# @package-uploader/core

Upload and manage Rise course packages on LMS platforms with a web UI and optional auto-patching.

## Features

- **Web UI**: Browse folders, upload courses, manage documents and shared links
- **Course upload**: Upload SCORM, cmi5, xAPI packages with drag-and-drop
- **Thin Pack links**: Auto-create LMS thin pack links on upload
- **Version management**: Upload new versions to existing documents
- **Auto-patching**: Automatically patch courses with @patch-adams/core
- **Feedback widget**: Inject feedback forms into patched courses

## Quick Start

### Run the Server

```bash
# Install globally
npm install -g @package-uploader/core

# Create .env file
cat > .env << EOF
UPLOADER_BASE_URL=https://your-lms.bravais.com
UPLOADER_USERNAME=your-username
UPLOADER_PASSWORD=your-password
PORT=3002
EOF

# Start the server
package-upload-server
```

Open http://localhost:3002 to access the web UI.

### Using npx (no install)

```bash
npx @package-uploader/core server
```

## Web UI Features

### Browse Page
- Navigate folder hierarchy
- View documents with metadata
- Expand documents to see details and shared links
- Create thin pack and shared links
- Copy launch URLs to clipboard

### Upload Modal
- Drag-and-drop file upload
- Auto-create LMS Thin Pack link (toggle, default ON)
- Auto-create Shared Link (toggle, default OFF)
- Custom link names with auto-generated slugs

## Configuration

### Environment Variables

```bash
# Required - Bravais LMS connection
UPLOADER_BASE_URL=https://your-lms.bravais.com
UPLOADER_USERNAME=your-username
UPLOADER_PASSWORD=your-password

# Optional - Server settings
PORT=3002
DEFAULT_FOLDER_ID=12345

# Optional - CORS for split-domain deployment
CORS_ORIGINS=https://company.com,https://www.company.com

# Optional - Auto-patching (requires @patch-adams/core)
PATCH_ENABLED=true
PATCH_REMOTE_DOMAIN=https://cdn.example.com/rise-overrides
```

### Auto-Patching with @patch-adams/core

Install the optional peer dependency to enable auto-patching:

```bash
npm install @patch-adams/core @patch-adams/plugin-feedback
```

When enabled, uploaded courses are automatically patched with:
- LRS bridge for xAPI tracking
- Feedback widget (configurable)
- Custom CSS/JS injections

## Split-Domain Deployment

For deploying the UI on a main domain with the API on a subdomain:

### 1. Build UI for Static Hosting

```bash
cd ui
VITE_API_URL=https://api.company.com/api npm run build
# Deploy ui/dist/ to your static host
```

### 2. Configure CORS on API Server

```bash
CORS_ORIGINS=https://company.com,https://www.company.com
```

## Programmatic Usage

```typescript
import { PackageUploaderClient } from '@package-uploader/core';

const client = new PackageUploaderClient({
  baseUrl: 'https://your-lms.bravais.com',
  username: 'your-username',
  password: 'your-password',
});

// Upload a course
const result = await client.uploadCourse(fileBuffer, 'course.zip', {
  folderId: '12345',
  title: 'My Course',
});

// Create a thin pack link
await client.createSharedLink(result.documentId, {
  name: 'My Course - LMS Thin Pack',
  isPublic: true,
  isForThinPackage: true,
});
```

## API Reference

### Folders

```typescript
client.listFolders()
client.getFolder(folderId)
client.listSubfolders(folderId)
```

### Documents

```typescript
client.listDocuments({ folderId, filterText })
client.getDocument(documentId)
client.getDocumentVersions(documentId)
```

### Shared Links

```typescript
client.listSharedLinks(documentId)
client.createSharedLink(documentId, {
  name: 'Link Name',
  isPublic: true,
  isForThinPackage: true,
})
```

### Upload

```typescript
client.uploadCourse(buffer, filename, { folderId, title })
client.uploadVersion(buffer, filename, { documentId, note })
```

## CLI Commands

```bash
# Start the web server
package-upload-server

# Upload a course (CLI)
package-upload upload course.zip --folder 12345

# Upload a new version
package-upload update course.zip --document-id 67890
```

## Development

```bash
# Clone and install
git clone https://github.com/npmbuilder/package-uploader.git
cd package-uploader
npm install

# Build UI
npm run build:ui

# Build TypeScript
npm run build

# Run server in development
npm run server
```

## License

MIT