Workflow Overview

OK!Gotcha provides flexible approval workflows that can be tailored to your specific business needs. From simple single-approver processes to complex multi-stage approval chains with conditional logic, our platform supports a wide range of approval scenarios.

Workflow Types

Single Approver

Simple workflows where approval from a single person is required.

Multi-Approver

Workflows requiring approval from multiple individuals (all or a subset).

Sequential Approval

Multi-stage workflows where approvals must happen in a specific order.

Conditional Workflows

Workflows with branching logic based on parameters or previous outcomes.

Basic Configuration

The simplest approval workflow requires specifying approvers:

import { OkGotcha } from '@okgotcha/sdk';

const ok = OkGotcha();

// Simple single-approver workflow
const secureAction = ok.requireApproval({
  title: "Important Action",
  description: "This action requires approval",
  approvers: ["user_123"] // User ID of the approver
})(async () => {
  // Function implementation
  return true;
});

Advanced Workflow Configurations

Team-Based Approval

Assign approvals to entire teams rather than specific individuals:

// Team-based approval
const secureAction = ok.requireApproval({
  title: "Security Change",
  description: "Update to security settings",
  approvers: ["security-team"] // Team ID
})(async () => {
  // Function implementation
  return true;
});

Multi-Approver Workflows

Require approval from multiple individuals:

// Multiple approvers required
const criticalAction = ok.requireApproval({
  title: "Critical System Change",
  description: "Update to core system settings",
  approvers: ["user_123", "user_456", "security-team"],
  minApprovals: 3 // Minimum number of approvals required
})(async () => {
  // Function implementation
  return true;
});

Sequential Approval Chains

Create workflows where approvals must happen in a specific sequence:

// Sequential approval chain
const sequentialApproval = ok.requireSequentialApproval([
  {
    title: "Manager Approval",
    description: "First-level approval by manager",
    approvers: ["manager-team"]
  },
  {
    title: "Security Review",
    description: "Security team review",
    approvers: ["security-team"]
  },
  {
    title: "Executive Sign-off",
    description: "Final executive approval",
    approvers: ["executive-team"]
  }
])(async () => {
  // Function implementation
  return true;
});

Conditional Approval Requirements

Create workflows with dynamic approval requirements based on parameters:

// Conditional approval requirements
const transferFunds = ok.requireApprovalIf({
  condition: (fromAccount, toAccount, amount) => amount > 10000,
  config: {
    title: "High-Value Transfer",
    description: "Transfer exceeding $10,000",
    approvers: ["finance-team", "security-team"],
    minApprovals: 2
  },
  elseConfig: {
    title: "Standard Transfer",
    description: "Regular fund transfer",
    approvers: ["finance-team"],
    minApprovals: 1
  }
})(async (fromAccount, toAccount, amount) => {
  // Transfer implementation
  return true;
});

Time-Based Expiration

Set expiration times for approval requests:

// Approval request with expiration
const timeConstrainedAction = ok.requireApproval({
  title: "Time-Sensitive Action",
  description: "Must be approved within 1 hour",
  approvers: ["operations-team"],
  expiresIn: 60 * 60 // 1 hour in seconds
})(async () => {
  // Function implementation
  return true;
});

Escalation Paths

Configure automatic escalation when approvals aren’t addressed in time:

// Approval with escalation path
const actionWithEscalation = ok.requireApproval({
  title: "Critical Fix",
  description: "Apply critical system fix",
  approvers: ["on-call-team"],
  escalation: {
    afterMinutes: 15,
    to: ["manager-team"],
    afterMinutes2: 30,
    to2: ["executive-team"]
  }
})(async () => {
  // Function implementation
  return true;
});

Advanced Workflow Customization

Custom Approval Logic

Implement custom approval logic with JavaScript/TypeScript:

// Custom approval logic
const customLogicApproval = ok.requireCustomApproval({
  title: "Complex Decision",
  description: "Requires custom approval logic",
  logic: async (context) => {
    // Get current time (hour)
    const hour = new Date().getHours();
    
    // During business hours, require manager approval
    if (hour >= 9 && hour <= 17) {
      return {
        approvers: ["manager-team"],
        minApprovals: 1
      };
    }
    
    // Outside business hours, require both on-call and manager approval
    return {
      approvers: ["on-call-team", "manager-team"],
      minApprovals: 2
    };
  }
})(async () => {
  // Function implementation
  return true;
});

Approval with Context

Provide additional context to help approvers make informed decisions:

// Approval with rich context
const contextualApproval = ok.requireApproval({
  title: "Database Schema Change",
  description: "Update to production database schema",
  approvers: ["database-team"],
  context: {
    changes: [
      { table: "users", action: "add_column", column: "last_login_date" },
      { table: "sessions", action: "add_index", columns: ["user_id", "created_at"] }
    ],
    impact: "Low - No downtime required",
    rollback: "Automatic rollback script included",
    jiraTicket: "PROJ-123"
  }
})(async () => {
  // Function implementation
  return true;
});

Implementation Patterns

Using with External Systems

Connect approval workflows to external systems:

// Integration with external ticketing system
const createJiraIssue = ok.requireApproval({
  title: "Create Jira Issue",
  description: "Create new high-priority issue in Jira",
  approvers: ["project-managers"],
  onApproved: async (result, context) => {
    // Create record in external system
    await externalSystems.jira.createAuditRecord({
      action: "issue_created",
      approvedBy: context.approvers,
      timestamp: new Date()
    });
    return result;
  }
})(async (issueData) => {
  // Implementation
  return jiraClient.createIssue(issueData);
});

Custom UI Components

Create custom UI components for specific approval types:

// Approval with custom UI component
const deployToProduction = ok.requireApproval({
  title: "Production Deployment",
  description: "Deploy new version to production",
  approvers: ["release-managers"],
  uiComponent: "DeploymentApprovalForm", // Custom component in your dashboard
  uiConfig: {
    showDiff: true,
    showTests: true,
    allowPartialApproval: false
  }
})(async (version, environment) => {
  // Implementation
  return deploymentSystem.deploy(version, environment);
});

Next Steps