mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-28 03:00:29 -04:00
* improvement(repo): restructuring to make realtime image narrower scoped * improvements * chore(repo): rebase fixes and quality improvements for realtime split Addresses merge-time issues and gaps from the realtime app split: - Retarget stale vi.mock paths to @sim/workflow-persistence/subblocks - Restore README branding, fix AGENTS.md script reference - Restore TSDoc on workflow-persistence subblocks helpers - Use toError() from @sim/utils/errors in save.ts - Add vitest config + local mocks so @sim/audit tests run standalone - Move socket.io-client to devDependencies in apps/realtime - Add missing package COPY steps to docker/app.Dockerfile - Add check:boundaries/check:realtime-prune scripts and wire into CI Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * refactor(security): consolidate crypto primitives into @sim/security Move general-purpose crypto primitives out of apps/sim into the @sim/security package so both apps/sim and apps/realtime can share them. @sim/security exports (all pure, dependency-free): ./compare safeCompare (constant-time HMAC-wrapped equality) ./encryption encrypt/decrypt (AES-256-GCM, iv:cipher:tag format) ./hash sha256Hex ./tokens generateSecureToken (base64url) Migrate apps/sim call sites to use these + @sim/utils helpers: crypto.randomUUID() -> generateId() from @sim/utils/id createHash('sha256').digest -> sha256Hex timingSafeEqual on hashed hex -> safeCompare new Promise(setTimeout) -> sleep from @sim/utils/helpers No behavior change: encryption format, digest output, and token length are preserved exactly. * refactor(copilot): use toError in remaining otel/finalize sites Replace the last two `error instanceof Error ? error : new Error(String(error))` patterns with toError from @sim/utils/errors. Completes the sweep of clean candidates — no behavior change. * refactor(security): consolidate HMAC-SHA256 primitives into @sim/security Adds hmacSha256Hex and hmacSha256Base64 to @sim/security/hmac and migrates 15 webhook providers plus 5 other hot paths (deployment token signing, outbound webhook requests, workspace notification delivery, notification test route, Shopify OAuth callback) off bare `createHmac` calls. Secret parameter accepts `string | Buffer` to cover base64-decoded Svix-style secrets (Resend) and MS Teams' HMAC scheme. AWS SigV4 signing in S3 and Textract tools intentionally retains direct `createHmac` usage — its multi-step key derivation chain doesn't fit a generic helper. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * chore(packages): post-audit test + packaging polish - Add safeCompare unit tests (identity, length mismatch, hex-nibble diff). - Add Buffer-secret cases to hmac tests to lock in Svix/MS-Teams contract. - Declare `reactflow` as a peerDependency on @sim/workflow-types — only used for type imports. - Add a barrel export to @sim/workflow-persistence for consumers that prefer package-level imports; subpath exports retained. - Document the data-field invariant in load.ts for loop/parallel subflow patching. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * chore(realtime): address PR review feedback - Remove redundant SOCKET_PORT=3002 env from Dockerfile runner stage (env.PORT already defaults to 3002 via zod schema). - Reorder PORT fallback so an explicitly-set SOCKET_PORT wins over the schema default for PORT; keeps SOCKET_PORT functional as an override instead of dead code. - Add dedicated type-check CI step for @sim/realtime so TS errors surface pre-deploy (the Dockerfile runs source TS via Bun and has no implicit build-time type check). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * chore(realtime): remove unused SOCKET_PORT env var SOCKET_PORT has lived in the socket server since the June 2025 refactor but was never actually set in any deploy config — docker-compose.prod, helm values/templates, .env.example, and docs all use PORT or the 3002 default exclusively. No self-hoster was ever pointed at SOCKET_PORT, so removing it is safe. Simplifies realtime port resolution to `env.PORT` (zod-validated with a 3002 default) and drops the orphaned sim-side schema entry. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Waleed Latif <walif6@gmail.com> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
138 lines
5.0 KiB
Bash
Executable File
138 lines
5.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Exit on error, but with some error handling
|
|
set -e
|
|
|
|
echo "🔧 Setting up Sim development environment..."
|
|
|
|
# Change to the workspace root directory
|
|
cd /workspace
|
|
|
|
# Install global packages for development (done at runtime, not build time)
|
|
echo "📦 Installing global development tools..."
|
|
bun install -g turbo drizzle-kit typescript @types/node 2>/dev/null || {
|
|
echo "⚠️ Some global packages may already be installed, continuing..."
|
|
}
|
|
|
|
# Set up bun completions (with proper shell detection)
|
|
echo "🔧 Setting up shell completions..."
|
|
if [ -n "$SHELL" ] && [ -f "$SHELL" ]; then
|
|
SHELL=/bin/bash bun completions 2>/dev/null | sudo tee /etc/bash_completion.d/bun > /dev/null || {
|
|
echo "⚠️ Could not install bun completions, but continuing..."
|
|
}
|
|
fi
|
|
|
|
# Add project commands to shell profile
|
|
echo "📄 Setting up project commands..."
|
|
# Add sourcing of sim-commands.sh to user's shell config files if they exist
|
|
for rcfile in ~/.bashrc ~/.zshrc; do
|
|
if [ -f "$rcfile" ]; then
|
|
# Check if already added
|
|
if ! grep -q "sim-commands.sh" "$rcfile"; then
|
|
echo "" >> "$rcfile"
|
|
echo "# Sim project commands" >> "$rcfile"
|
|
echo "if [ -f /workspace/.devcontainer/sim-commands.sh ]; then" >> "$rcfile"
|
|
echo " source /workspace/.devcontainer/sim-commands.sh" >> "$rcfile"
|
|
echo "fi" >> "$rcfile"
|
|
fi
|
|
fi
|
|
done
|
|
|
|
# If no rc files exist yet, create a minimal one
|
|
if [ ! -f ~/.bashrc ] && [ ! -f ~/.zshrc ]; then
|
|
echo "# Source Sim project commands" > ~/.bashrc
|
|
echo "if [ -f /workspace/.devcontainer/sim-commands.sh ]; then" >> ~/.bashrc
|
|
echo " source /workspace/.devcontainer/sim-commands.sh" >> ~/.bashrc
|
|
echo "fi" >> ~/.bashrc
|
|
fi
|
|
|
|
# Clean and reinstall dependencies to ensure platform compatibility
|
|
echo "📦 Cleaning and reinstalling dependencies..."
|
|
if [ -d "node_modules" ]; then
|
|
echo "Removing existing node_modules to ensure platform compatibility..."
|
|
rm -rf node_modules
|
|
rm -rf apps/sim/node_modules
|
|
rm -rf apps/docs/node_modules
|
|
fi
|
|
|
|
# Ensure Bun cache directory exists and has correct permissions
|
|
mkdir -p ~/.bun/cache
|
|
chmod 700 ~/.bun ~/.bun/cache
|
|
|
|
# Install dependencies with platform-specific binaries
|
|
echo "Installing dependencies with Bun..."
|
|
bun install
|
|
|
|
# Check for native dependencies
|
|
echo "Checking for native dependencies compatibility..."
|
|
if grep -q '"trustedDependencies"' apps/sim/package.json 2>/dev/null; then
|
|
echo "⚠️ Native dependencies detected. Bun will handle compatibility during install."
|
|
fi
|
|
|
|
# Set up environment variables if .env doesn't exist for the sim app
|
|
if [ ! -f "apps/sim/.env" ]; then
|
|
echo "📄 Creating apps/sim/.env from template..."
|
|
if [ -f "apps/sim/.env.example" ]; then
|
|
cp apps/sim/.env.example apps/sim/.env
|
|
else
|
|
echo "DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio" > apps/sim/.env
|
|
fi
|
|
fi
|
|
|
|
# Set up env for the realtime server (must match the shared values in apps/sim/.env)
|
|
if [ ! -f "apps/realtime/.env" ] && [ -f "apps/realtime/.env.example" ]; then
|
|
echo "📄 Creating apps/realtime/.env from template..."
|
|
cp apps/realtime/.env.example apps/realtime/.env
|
|
fi
|
|
|
|
# Set up packages/db/.env for drizzle-kit and migration scripts
|
|
if [ ! -f "packages/db/.env" ] && [ -f "packages/db/.env.example" ]; then
|
|
echo "📄 Creating packages/db/.env from template..."
|
|
cp packages/db/.env.example packages/db/.env
|
|
fi
|
|
|
|
# Generate schema and run database migrations
|
|
echo "🗃️ Running database schema generation and migrations..."
|
|
echo "Generating schema..."
|
|
cd apps/sim
|
|
bunx drizzle-kit generate
|
|
cd ../..
|
|
|
|
echo "Waiting for database to be ready..."
|
|
# Try to connect to the database, but don't fail the script if it doesn't work
|
|
(
|
|
timeout=60
|
|
while [ $timeout -gt 0 ]; do
|
|
if PGPASSWORD=postgres psql -h db -U postgres -c '\q' 2>/dev/null; then
|
|
echo "Database is ready!"
|
|
cd apps/sim
|
|
DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio bunx drizzle-kit push
|
|
cd ../..
|
|
break
|
|
fi
|
|
echo "Database is unavailable - sleeping (${timeout}s remaining)"
|
|
sleep 5
|
|
timeout=$((timeout - 5))
|
|
done
|
|
|
|
if [ $timeout -le 0 ]; then
|
|
echo "⚠️ Database connection timed out, skipping migrations"
|
|
fi
|
|
) || echo "⚠️ Database setup had issues but continuing..."
|
|
|
|
# Clear the welcome message flag to ensure it shows after setup
|
|
unset SIM_WELCOME_SHOWN
|
|
|
|
echo ""
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "✅ Sim development environment setup complete!"
|
|
echo ""
|
|
echo "Your environment is now ready. A new terminal session will show"
|
|
echo "available commands. You can start the development server with:"
|
|
echo ""
|
|
echo " sim-start"
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo ""
|
|
|
|
# Exit successfully regardless of any previous errors
|
|
exit 0 |