CalOohPay API Documentation - v2.1.0
    Preparing search index...

    Class InputValidator

    Centralized input validation module for CalOohPay application.

    Provides consistent validation rules and error messages across all parts of the application. All validation methods throw descriptive errors with context when validation fails.

    Index

    Constructors

    Methods - Other

    • Sanitizes a string input by trimming whitespace.

      Parameters

      • input: string

        The string to sanitize

      • defaultValue: string = ''

        Optional default value if input is empty after trimming

      Returns string

      Sanitized string

      InputValidator.sanitizeString('  test  ');        // 'test'
      InputValidator.sanitizeString(' ', 'default'); // 'default'
    • Validates an API token format.

      Basic validation for PagerDuty API tokens. Real validation happens when making API calls, but this catches obvious issues early.

      Parameters

      • token: string

        API token to validate

      Returns void

      If token is missing or appears invalid

      InputValidator.validateApiToken('u+ABC123xyz789');  // OK
      InputValidator.validateApiToken(''); // throws Error
    • Validates a date range ensuring 'since' is not greater than 'until'.

      Parameters

      • since: string

        Start date string (ISO format)

      • until: string

        End date string (ISO format)

      Returns void

      If since > until or if dates are invalid

      InputValidator.validateDateRange('2024-01-01', '2024-01-31'); // OK
      InputValidator.validateDateRange('2024-02-01', '2024-01-01'); // throws Error
    • Validates a date string can be parsed as a valid date.

      Parameters

      • dateString: string

        The date string to validate

      • fieldName: string

        Name of the field being validated (for error messages)

      Returns void

      If date string is invalid or cannot be parsed

      InputValidator.validateDateString('2024-01-15', 'since'); // OK
      InputValidator.validateDateString('invalid', 'since'); // throws Error
    • Validates a file path for output.

      Basic validation to ensure path is not empty and doesn't contain obviously invalid characters.

      Parameters

      • filePath: string

        The file path to validate

      Returns void

      If file path is invalid

      InputValidator.validateFilePath('./output/report.csv');  // OK
      InputValidator.validateFilePath(''); // throws Error
    • Validates an OnCallUser object for payment calculations.

      Ensures the user has all required data for accurate payment calculation.

      Parameters

      • onCallUser: OnCallUser | null | undefined

        The user object to validate

      Returns void

      If user is undefined, missing required fields, or has no on-call periods

      const user = new OnCallUser('PXXXXXX', 'John Doe', [period]);
      InputValidator.validateOnCallUser(user); // OK

      InputValidator.validateOnCallUser(null); // throws Error
    • Validates PagerDuty schedule ID format.

      PagerDuty schedule IDs typically start with 'P' followed by alphanumeric characters. This validates basic format and non-empty strings.

      Parameters

      • scheduleId: string

        The schedule ID to validate

      Returns void

      If schedule ID is invalid

      InputValidator.validateScheduleId('PXXXXXX');  // OK
      InputValidator.validateScheduleId(''); // throws Error
      InputValidator.validateScheduleId(' '); // throws Error
    • Validates a comma-separated list of schedule IDs.

      Parameters

      • scheduleIds: string

        Comma-separated schedule IDs

      Returns string[]

      Array of validated and trimmed schedule IDs

      If any schedule ID is invalid

      const ids = InputValidator.validateScheduleIds('PXXXXXX,PYYYYYY');
      // Returns: ['PXXXXXX', 'PYYYYYY']
    • Validates an IANA timezone identifier.

      Note: This performs basic validation. For comprehensive timezone validation, use Luxon's DateTime.local().setZone() and check if zone.isValid.

      Parameters

      • timezone: string

        IANA timezone identifier (e.g., 'Europe/London', 'America/New_York')

      Returns void

      If timezone is invalid or unsupported

      InputValidator.validateTimezone('Europe/London');      // OK
      InputValidator.validateTimezone('Invalid/Timezone'); // throws Error

    Methods - Validation

    • Validates that a string is non-empty (after trimming whitespace).

      Used for validating required string fields like currency codes.

      Parameters

      • value: string

        The string to validate

      • fieldName: string

        Name of the field being validated (for error messages)

      Returns void

      If value is not a string or is empty after trimming

      InputValidator.validateNonEmptyString('GBP', 'currency');      // OK
      InputValidator.validateNonEmptyString(' USD ', 'currency'); // OK (trimmed)
      InputValidator.validateNonEmptyString('', 'currency'); // throws Error
      InputValidator.validateNonEmptyString(' ', 'currency'); // throws Error
    • Validates that a number is positive (greater than 0).

      Used for validating configuration values that must be positive, such as compensation rates.

      Parameters

      • value: number

        The number to validate

      • fieldName: string

        Name of the field being validated (for error messages)

      Returns void

      If value is not a number, NaN, or not positive

      InputValidator.validatePositiveNumber(50, 'weekdayRate');     // OK
      InputValidator.validatePositiveNumber(0, 'weekdayRate'); // throws Error
      InputValidator.validatePositiveNumber(-10, 'weekdayRate'); // throws Error
      InputValidator.validatePositiveNumber(NaN, 'weekdayRate'); // throws Error