npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

payrolla

v0.2.4

Published

Official TypeScript/JavaScript client for Payrolla Payroll Calculation Service

Readme

Payrolla Node.js Client

Official TypeScript/JavaScript client for the Payrolla Payroll Calculation Service.

npm version License: MIT

Features

  • Fluent API - Three ergonomic API surfaces for different use cases
  • Type-safe - Full TypeScript support with comprehensive type definitions
  • Modern - Built with native fetch API (Node.js 16+)
  • Zero dependencies - Lightweight with no external dependencies
  • Secure - Built-in API key and token authentication
  • TR-focused - Optimized for Turkish payroll calculations
  • Well-documented - Comprehensive JSDoc comments and examples

Installation

npm install payrolla

Requirements

  • Node.js 16.0.0 or higher (for native fetch support)

Quick Start

import { PayrollaClient } from 'payrolla';

// Create client with API key
const client = new PayrollaClient({
  apiKey: 'pk_live_xxxxx', // Get from your Payrolla dashboard
});

// Calculate net monthly payroll (Primary TR DSL - Recommended)
const result = await client
  .netMonthly(100_000)              // Net monthly wage
  .forPeriod(2025, 1)               // January 2025
  .regularDays(26, { name: 'Mesai' })
  .overtime(10, 1.5)                // 10 hours with 1.5x coefficient
  .calculate();

console.log('Total cost:', result.totalcost);
console.log('Net wage:', result.payrolls[0].payrollResult.totalNet);

Authentication

The client uses API key authentication via the x-api-key header.

const client = new PayrollaClient({
  apiKey: 'pk_live_xxxxx', // Get from your Payrolla dashboard
});

All requests automatically go to https://api.payrolla.app and include your API key in the headers.

API Surfaces

Payrolla client provides three API surfaces to match your coding style and use case:

1. Primary TR DSL (Recommended)

Opinionated, concise, Turkey-focused API. Best for most use cases.

// Net monthly wage
await client
  .netMonthly(100_000)
  .forPeriod(2025, 1)
  .calculate();

// Gross daily wage
await client
  .grossDaily(3_500)
  .forPeriod(2025, 1)
  .regularDays(22)
  .calculate();

// Net hourly wage
await client
  .netHourly(450)
  .forPeriod(2025, 1)
  .regularHours(160)
  .calculate();

2. Staged Builder (Power Users)

More explicit control over all parameters.

await client
  .newCalculation()
  .setMonthlyWage(100_000, 'Net')
  .forPeriod(2025, 1)
  .withMinWageExemption(true)
  .use30DayMonth()
  .calculate();

3. Raw Call (Full Control)

Direct API access with complete WageCalculationModel.

await client.calculate({
  calcDate: '2025-01-01',
  wageAmount: 100_000,
  cumulativeIncomeTaxBase: 0,
  cumulativeMinWageIncomeTaxBase: 0,
  ssiType: SSIType.S4A,
  wageCalculationType: CalculationType.Net,
  wagePeriodType: PaymentPeriodType.Monthly,
  periodCount: 1,
  periodLengthType: PeriodLengthType.Month,
  // ... other fields
});

Examples

Multi-line Regular Payments

const result = await client
  .netMonthly(100_000)
  .forPeriod(2025, 1)
  .regularDays(26, { name: 'Mesai', ref: '1' })
  .regularDays(5, { name: 'Hafta sonu', ref: '2' })
  .extraPayNet(50_000, { name: 'Bonus', ref: '3' })
  .calculate();

With Transferred SSI Base

const result = await client
  .grossMonthly(150_000)
  .forPeriod(2025, 1)
  .withTransferredSSI({ base1: 40000, base2: 200000 })
  .calculate();

Social Aid with Date-aware Exemptions

import { Predefined } from 'payrolla';

const result = await client
  .netMonthly(60_000)
  .forPeriod(2025, 1)
  .socialAid(3_000, Predefined.ChildAid) // Exemptions resolved by date
  .calculate();

30-day Month Calculation

const result = await client
  .netMonthly(100_000)
  .forPeriod(2025, 1)
  .use30DayMonth() // Use 30-day month instead of calendar days
  .calculate();

Validation Before Calculation

const builder = client
  .netMonthly(100_000)
  .forPeriod(2025, 1);

// Validate without executing
const validation = builder.validate();
if (!validation.isValid) {
  console.error('Validation errors:', validation.errors);
  return;
}

// Execute calculation
const result = await builder.calculate();

Build Model Without Execution

// Get the model synchronously without making API call
const model = client
  .netMonthly(100_000)
  .forPeriod(2025, 1)
  .build();

console.log('Model:', model);
// Use the model later or pass it to another function

Configuration

Client Options

const client = new PayrollaClient({
  apiKey: 'pk_live_xxxxx',  // API key (required)
  timeout: 60000,           // Optional timeout in ms (default: 30000)
});

Debug Mode

Enable debug logging for troubleshooting:

# Set environment variable
export PAYROLLA_DEBUG=true

# Or in .env file
PAYROLLA_DEBUG=true

Builder API Reference

Initialization Methods

  • netMonthly(amount) - Start with net monthly wage
  • grossMonthly(amount) - Start with gross monthly wage
  • netDaily(amount) - Start with net daily wage
  • grossDaily(amount) - Start with gross daily wage
  • netHourly(amount) - Start with net hourly wage
  • grossHourly(amount) - Start with gross hourly wage
  • newCalculation() - Start with empty builder

Configuration Methods

  • forPeriod(year, month) - Set calculation period
  • withSSIType(type) - Set SSI type (S4A, S4B, S4C)
  • withMinWageExemption(enabled?) - Enable/disable min wage exemption
  • withTransferredSSI({ base1?, base2? }) - Set transferred SSI bases
  • withDisabilityDiscount(amount) - Set disability discount
  • use30DayMonth() - Use 30-day month
  • useCalendarDayMonth() - Use calendar day month

Payment Methods

  • regularDays(days, opts?) - Add regular payment by days
  • regularHours(hours, opts?) - Add regular payment by hours
  • overtime(hours, coeff?, opts?) - Add overtime payment
  • extraPayNet(amount, opts?) - Add extra net payment
  • extraPayGross(amount, opts?) - Add extra gross payment
  • socialAid(amount, predefined?, opts?) - Add social aid

Execution Methods

  • validate() - Validate builder state (synchronous)
  • build() - Build WageCalculationModel (synchronous)
  • calculate() - Execute calculation (async)

Type Exports

All TypeScript types and enums are exported:

import {
  PayrollaClient,
  SSIType,
  CalculationType,
  PaymentPeriodType,
  PaymentType,
  PaymentDetailType,
  MonthDayCount,
  Predefined,
  WageCalculationModel,
  WageResultModel,
  // ... and more
} from 'payrolla';

Error Handling

import { ApiError, AuthenticationError, NetworkError } from 'payrolla';

try {
  const result = await client
    .netMonthly(100_000)
    .forPeriod(2025, 1)
    .calculate();
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error('Authentication failed:', error.message);
  } else if (error instanceof ApiError) {
    console.error('API error:', error.message, error.statusCode);
  } else if (error instanceof NetworkError) {
    console.error('Network error:', error.message);
  } else {
    console.error('Unknown error:', error);
  }
}

Support

For issues and questions, please visit: https://github.com/runpayrolla/payrolla-node/issues

License

MIT License - see LICENSE file for details