sn-templates
v1.0.0
Published
Internal module
Readme
@pocketsync/templates
One-click app templates for Senate PaaS.
Installation
npm install github:SenateStack/senate-templatesUsage
Loading Templates
import { setTemplates, getAllTemplates, getTemplateBySlug } from '@pocketsync/templates';
// Load templates from JSON files (Node.js)
import fs from 'fs';
import path from 'path';
const templatesDir = path.join(require.resolve('@pocketsync/templates'), '..', '..', 'templates');
const files = fs.readdirSync(templatesDir).filter(f => f.endsWith('.json'));
const templates = files.map(f => JSON.parse(fs.readFileSync(path.join(templatesDir, f), 'utf-8')));
setTemplates(templates);
// Now you can use the utilities
const allTemplates = getAllTemplates();
const postgres = getTemplateBySlug('postgres');Resolving Templates
import { resolveTemplate, validateRequest, toServicePayload } from '@pocketsync/templates/resolve';
// Validate user input
const errors = validateRequest(template, 'my-postgres', {
pg_user: 'admin',
pg_pass: 'secret123',
});
if (errors.length > 0) {
console.error('Validation errors:', errors);
}
// Resolve template with variables
const resolved = resolveTemplate(template, 'my-postgres', {
pg_user: 'admin',
pg_pass: 'secret123',
postgres_version: '15',
});
// Convert to service creation payload
const payload = toServicePayload(resolved, 'machine-id-123');Icons
Icons are included in the icons/ directory. Copy them to your public folder:
// next.config.mjs
import { cpSync, existsSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
const templatesPath = dirname(require.resolve('@pocketsync/templates'));
const iconsSource = join(templatesPath, 'icons');
const iconsDest = './public/images/templates';
if (existsSync(iconsSource)) {
cpSync(iconsSource, iconsDest, { recursive: true });
}Package Structure
senate-templates/
├── src/
│ ├── index.ts # Main exports
│ ├── types.ts # TypeScript types
│ ├── categories.ts # Category definitions
│ ├── utils.ts # Utility functions
│ └── resolve.ts # Variable resolution & compose generation
├── templates/ # JSON template files
├── icons/ # PNG icon files
└── converter/ # (Future) Template conversion toolsTypes
Template
interface Template {
id: string; // "caprover.postgres"
slug: string; // "postgres"
name: string; // "PostgreSQL"
description: string;
version: string;
logo: string; // "postgres.png"
categories: string[]; // ["database"]
official: boolean;
documentation: string;
services: Record<string, ServiceDef>;
variables: Variable[];
instructions: Instructions;
}Variable
interface Variable {
id: string;
label: string;
description?: string;
type: 'string' | 'password' | 'number' | 'boolean' | 'select' | 'text';
default?: string;
options?: string[];
required: boolean;
valid_regex?: string;
generate?: string; // "random_hex:32", "random_password:16"
}License
MIT
