1.1.0 • Published 4 months ago

sjm v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

SJM

npm version Node.js versions License

Official Node.js client for the SJM (Snap Job Model) API - a powerful AI-driven freelancer matching and recruitment system.

🚀 Features

  • Freelancer Matching: Find the perfect talent for your projects with advanced AI matching
  • Skills Verification: Validate and verify skills against our extensive database
  • AI-Powered Interviews: Conduct automated interviews with robust evaluation
  • Comprehensive client: Clean, TypeScript interface to all SJM API endpoints
  • Command-line interface: Access SJM capabilities from your terminal
  • Robust error handling: Detailed exceptions with comprehensive information

🏠 Installation

# Install as a dependency in your project
npm install sjm

# Install globally for CLI access
npm install -g sjm

🔑 Authentication

To use the SJM client, you'll need an API key from SnapJobsAI. Contact us to obtain your API key.

📚 Quick Start

import { SJM } from 'sjm';

// Initialize client with your API key
const client = new SJM({ apiKey: "your_api_key" });

// Check API health
async function checkHealth() {
  try {
    const health = await client.health();
    console.log(`API Status: ${health.status}`);
  } catch (error) {
    console.error(`Error: ${error.message}`);
  }
}

// Match freelancers to a project
async function findMatches() {
  try {
    const result = await client.match({
      description: "Build a modern web application with React and Node.js",
      required_skills: ["React.js", "Node.js", "TypeScript"],
      budget_range: [5000, 10000],
      complexity: "medium",
      timeline: 30
    });
    
    // Display top matches
    for (const match of result.matches.slice(0, 3)) {
      const freelancer = match.freelancer;
      console.log(`Match: ${freelancer.name} (${freelancer.job_title})`);
      console.log(`Score: ${match.score.toFixed(2)}`);
      console.log(`Matching Skills: ${match.matching_skills}`);
      console.log(`Hourly Rate: $${freelancer.hourly_rate}/hr`);
      console.log("---");
    }
  } catch (error) {
    console.error(`Error: ${error.message}`);
  }
}

// Run our functions
(async () => {
  await checkHealth();
  await findMatches();
})();

📋 Example: AI Interviews

import { SJM } from 'sjm';
import * as readline from 'readline';

const client = new SJM({ apiKey: "your_api_key" });

// Create readline interface for user input
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

// Promisify the question method
function question(query: string): Promise<string> {
  return new Promise(resolve => {
    rl.question(query, resolve);
  });
}

async function conductInterview() {
  try {
    // Generate interview questions
    const interview = await client.interview({
      freelancer_id: "f123",
      project_description: "Build a modern web application with React",
      required_skills: ["React.js", "Node.js", "TypeScript"],
      job_title: "Full Stack Developer",
      mode: "ai_questions"
    });
    
    // Get session ID and questions
    const session_id = interview.data.session_id;
    const questions = interview.data.interview_data.questions;
    
    // Display questions to collect answers
    const answers = [];
    for (let i = 0; i < questions.length; i++) {
      console.log(`Q${i+1}: ${questions[i].text}`);
      const answer = await question("Answer: ");
      answers.push(answer);
    }
    
    // Submit answers for evaluation
    const evaluation = await client.interview({
      freelancer_id: "f123",
      project_description: "Build a modern web application with React",
      required_skills: ["React.js", "Node.js", "TypeScript"],
      job_title: "Full Stack Developer",
      mode: "ai_full",
      session_id: session_id,
      provided_answers: answers
    });
    
    // Display evaluation results
    if (evaluation.data.evaluation) {
      const eval_data = evaluation.data.evaluation;
      console.log(`Overall Score: ${eval_data.overall_score}/100`);
      console.log(`Strengths: ${eval_data.strengths.join(', ')}`);
      console.log(`Areas for Improvement: ${eval_data.areas_for_improvement.join(', ')}`);
      console.log(`Hiring Recommendation: ${eval_data.hiring_recommendation ? 'Yes' : 'No'}`);
    }
    
    rl.close();
  } catch (error) {
    console.error(`Error: ${error.message}`);
    rl.close();
  }
}

conductInterview();

🖥️ Command Line Interface

The package includes a CLI for convenient access to SJM API functionality:

# Set your API key as an environment variable (recommended)
export SJM_API_KEY="your_api_key"

# Check API health
sjm health

# Match freelancers to a project
sjm match --description "Web development project" --skills "React.js,Node.js,TypeScript"

# Verify if a skill exists in the database
sjm verify-skill "React.js"

# Conduct an interview
sjm interview --freelancer f123 --description "Web development project" --skills "React.js,Node.js"

# Generate test data
sjm generate-test-data --number 10

# Start interactive mode
sjm interactive

# Display help
sjm --help

📖 API Reference

Client Initialization

import { SJM } from 'sjm';

// Basic initialization
const client = new SJM({ apiKey: "your_api_key" });

// Custom base URL (if needed)
const client = new SJM({
  apiKey: "your_api_key",
  baseUrl: "https://your-custom-endpoint.com/api/v1/docker"
});

Available Methods

MethodDescription
health()Check the health status of the SJM API
match(params)Match freelancers to a project
verifySkill(keyword)Verify if a skill exists in the database
interview(params)Conduct an AI interview
generateTestData(num_freelancers)Generate test freelancer data

For detailed documentation on each method, please refer to the full API documentation.

Method Parameters

match(params)

interface MatchParams {
  description: string;            // Project description
  required_skills: string[];      // Array of required skills
  budget_range?: [number, number]; // Optional budget range [min, max]
  complexity?: 'low' | 'medium' | 'high'; // Optional project complexity
  timeline?: number;              // Optional project timeline in days
}

interview(params)

interface InterviewParams {
  freelancer_id: string;          // ID of the freelancer
  project_description: string;    // Project description
  required_skills: string[];      // Required skills
  job_title: string;              // Job title
  mode?: 'ai_full' | 'ai_questions' | 'custom_full' | 'hybrid'; // Interview mode
  session_id?: string;            // Optional session ID for continuing interviews
  provided_answers?: string[];    // Optional answers for evaluation
  custom_questions?: any[];       // Optional custom questions
  scoring_criteria?: Record<string, number>; // Optional custom scoring criteria
}

⚙️ Error Handling

The client provides detailed exception handling for different error scenarios:

import { SJM } from 'sjm';

const client = new SJM({ apiKey: "your_api_key" });

async function handleErrors() {
  try {
    const result = await client.match({
      description: "Project description",
      required_skills: ["React.js", "Node.js"]
    });
  } catch (error) {
    if (error.message.includes('Authentication failed')) {
      console.log(`Authentication error: ${error.message}`);
    } else if (error.message.includes('Rate limit exceeded')) {
      console.log(`Rate limit error: ${error.message}`);
    } else {
      console.log(`API error: ${error.message}`);
    }
  }
}

🔒 Authentication & Rate Limiting

  • API keys are required for all requests
  • Rate limiting applies based on your plan:
    • Freelancer: Limited requests
    • Professional: Higher limits
    • Enterprise: Unlimited access
  • The client automatically handles rate limit headers and provides appropriate error messages

📦 TypeScript Support

The SJM client includes TypeScript definitions for all methods and parameters, providing excellent IDE support and type safety.

import { SJM, SJMConfig, Freelancer, MatchResult } from 'sjm';

// All types are exported for your convenience
const config: SJMConfig = {
  apiKey: "your_api_key",
  timeout: 60000
};

const client = new SJM(config);

📞 Support

For questions, issues, or feature requests, please contact support@snapjobsai.com or visit our website.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

1.1.0

4 months ago

1.0.5

5 months ago

1.0.4

5 months ago