Skip to content

Settings API (Pending)

Migration Pending

This API is pending migration to Cloudflare Workers.

The Settings API manages system configuration, feature flags, and organizational settings.

Planned Procedures

ProcedureTypeDescription
settings.getAllQueryGet all settings
settings.getByCategoryQueryGet settings by category
settings.updateMutationUpdate setting value
settings.resetMutationReset to defaults
settings.getFeatureFlagsQueryGet feature flags
settings.updateFeatureFlagMutationToggle feature
settings.getNotificationsQueryGet notification settings
settings.updateNotificationsMutationUpdate notifications

Data Model

Setting

typescript
interface Setting {
  id: string;
  key: string;
  value: any;
  type: SettingType;
  category: SettingCategory;
  label: string;
  description?: string;
  isPublic: boolean;
  isEditable: boolean;
  defaultValue: any;
  validation?: SettingValidation;
  updatedAt: Date;
  updatedBy?: string;
}

Setting Type

typescript
enum SettingType {
  STRING = "STRING",
  NUMBER = "NUMBER",
  BOOLEAN = "BOOLEAN",
  JSON = "JSON",
  SELECT = "SELECT",
  MULTI_SELECT = "MULTI_SELECT"
}

Setting Category

typescript
enum SettingCategory {
  GENERAL = "GENERAL",
  SECURITY = "SECURITY",
  NOTIFICATIONS = "NOTIFICATIONS",
  APPEARANCE = "APPEARANCE",
  INTEGRATIONS = "INTEGRATIONS",
  ADVANCED = "ADVANCED"
}

Settings Categories

General Settings

KeyTypeDefaultDescription
app.nameString"Smart City TVMS"Application name
app.logoStringnullCustom logo URL
app.languageSelect"en"Default language
app.timezoneString"Asia/Almaty"System timezone
app.dateFormatSelect"DD/MM/YYYY"Date format
app.timeFormatSelect"24h"Time format

Security Settings

KeyTypeDefaultDescription
security.sessionTimeoutNumber24Session timeout (hours)
security.maxLoginAttemptsNumber5Max failed logins
security.lockoutDurationNumber30Lockout time (minutes)
security.passwordExpiryNumber90Password expiry (days)
security.mfaEnabledBooleanfalseRequire MFA
security.ipWhitelistJSON[]Allowed IP ranges

Notification Settings

KeyTypeDefaultDescription
notify.email.enabledBooleantrueEmail notifications
notify.email.smtpJSON{}SMTP configuration
notify.sms.enabledBooleanfalseSMS notifications
notify.sms.providerSelectnullSMS provider
notify.webhook.enabledBooleanfalseWebhook notifications
notify.webhook.urlStringnullWebhook endpoint

Integration Settings

KeyTypeDefaultDescription
integration.mapbox.tokenStringnullMapbox API token
integration.analytics.enabledBooleantrueAnalytics tracking
integration.api.rateLimitNumber1000API rate limit/hour
integration.export.formatsMultiSelect["PDF","CSV"]Export formats

Planned Input Schemas

Update Setting

typescript
{
  key: string;                 // Setting key
  value: any;                  // New value
}

Update Multiple Settings

typescript
{
  settings: Array<{
    key: string;
    value: any;
  }>;
}

Get Settings by Category

typescript
{
  category: SettingCategory;
  includePrivate?: boolean;    // Admin only
}

Expected Responses

Get All Settings

json
{
  "settings": [
    {
      "key": "app.name",
      "value": "Smart City TVMS",
      "type": "STRING",
      "category": "GENERAL",
      "label": "Application Name",
      "description": "Name displayed in the header",
      "isPublic": true,
      "isEditable": true
    },
    {
      "key": "security.sessionTimeout",
      "value": 24,
      "type": "NUMBER",
      "category": "SECURITY",
      "label": "Session Timeout",
      "description": "Hours until session expires",
      "isPublic": false,
      "isEditable": true,
      "validation": {
        "min": 1,
        "max": 168
      }
    }
  ],
  "categories": ["GENERAL", "SECURITY", "NOTIFICATIONS", "APPEARANCE"]
}

Get Feature Flags

json
{
  "features": {
    "dashboard": {
      "enabled": true,
      "description": "Main dashboard"
    },
    "sensors": {
      "enabled": true,
      "description": "Sensor management"
    },
    "reports": {
      "enabled": true,
      "description": "Reports and analytics"
    },
    "incidents": {
      "enabled": true,
      "description": "Incident management"
    },
    "realtime": {
      "enabled": true,
      "description": "Real-time updates"
    },
    "aiAnalytics": {
      "enabled": false,
      "description": "AI-powered analytics (beta)"
    }
  }
}

Validation Rules

String Validation

typescript
{
  minLength?: number;
  maxLength?: number;
  pattern?: string;            // Regex pattern
}

Number Validation

typescript
{
  min?: number;
  max?: number;
  step?: number;
}

Select Validation

typescript
{
  options: Array<{
    value: string;
    label: string;
  }>;
}

D1 Schema

sql
CREATE TABLE settings (
  id TEXT PRIMARY KEY,
  key TEXT UNIQUE NOT NULL,
  value TEXT NOT NULL,
  type TEXT NOT NULL,
  category TEXT NOT NULL,
  label TEXT NOT NULL,
  description TEXT,
  isPublic INTEGER DEFAULT 1,
  isEditable INTEGER DEFAULT 1,
  defaultValue TEXT,
  validation TEXT,
  updatedAt TEXT NOT NULL,
  updatedBy TEXT,
  FOREIGN KEY (updatedBy) REFERENCES User(id)
);

CREATE INDEX idx_settings_key ON settings(key);
CREATE INDEX idx_settings_category ON settings(category);

-- Feature flags
CREATE TABLE feature_flags (
  id TEXT PRIMARY KEY,
  key TEXT UNIQUE NOT NULL,
  enabled INTEGER DEFAULT 0,
  description TEXT,
  metadata TEXT,
  updatedAt TEXT NOT NULL
);

Default Settings Initialization

On first deployment, seed default settings:

typescript
const defaultSettings = [
  {
    key: 'app.name',
    value: 'Smart City TVMS',
    type: 'STRING',
    category: 'GENERAL',
    label: 'Application Name',
    isPublic: true,
  },
  {
    key: 'app.timezone',
    value: 'Asia/Almaty',
    type: 'STRING',
    category: 'GENERAL',
    label: 'System Timezone',
    isPublic: true,
  },
  // ... more defaults
];

SCS Smart City - Traffic, Gateway, Camera, and NVR Platform