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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@isl-lang/stdlib-payments

v2.0.0

Published

ISL Payments Standard Library - PCI-compliant payment processing behaviors

Readme

@intentos/stdlib-payments

ISL Payments Standard Library - PCI-compliant payment processing behaviors for IntentOS.

Overview

This package provides a comprehensive payment processing library defined using ISL (Intent Specification Language) with TypeScript implementations. All behaviors include:

  • Formal specifications with preconditions, postconditions, and invariants
  • PCI DSS compliance requirements
  • Chaos engineering scenarios
  • Full observability (metrics, traces, logs)

Installation

pnpm add @intentos/stdlib-payments

Behaviors

CreatePayment

Initiate a new payment with idempotency guarantees.

import { createPayment, CreatePaymentConfig } from '@intentos/stdlib-payments';

const result = await createPayment({
  idempotencyKey: 'order-123-payment',
  amount: 99.99,
  currency: 'USD',
  paymentMethodToken: 'pm_card_xxx',
  capture: true,
}, config);

if (result.success) {
  console.log('Payment created:', result.data.id);
} else {
  console.error('Payment failed:', result.error.code);
}

CapturePayment

Complete an authorized payment.

import { capturePayment } from '@intentos/stdlib-payments';

const result = await capturePayment({
  paymentId: 'pay_xxx',
  idempotencyKey: 'capture-order-123',
  amount: 75.00, // Optional: partial capture
}, config);

RefundPayment

Issue a full or partial refund.

import { refundPayment } from '@intentos/stdlib-payments';

const result = await refundPayment({
  paymentId: 'pay_xxx',
  idempotencyKey: 'refund-order-123',
  amount: 25.00, // Optional: partial refund
  reason: 'Customer request',
}, config);

ProcessWebhook

Handle payment provider webhooks with signature verification.

import { processWebhook } from '@intentos/stdlib-payments';

const result = await processWebhook({
  provider: 'STRIPE',
  eventId: 'evt_xxx',
  eventType: 'payment_intent.succeeded',
  signature: req.headers['stripe-signature'],
  timestamp: new Date(),
  payload: req.body,
  headers: req.headers,
}, config);

Payment Providers

Supported providers:

  • Stripe - Full implementation
  • Braintree - Interface defined
  • Adyen - Interface defined
  • Square - Interface defined
import { StripeProvider, createProvider } from '@intentos/stdlib-payments';

const provider = new StripeProvider({
  secretKey: process.env.STRIPE_SECRET_KEY,
  webhookSecret: process.env.STRIPE_WEBHOOK_SECRET,
});

// Or use the factory
const provider = createProvider({
  type: 'stripe',
  config: { /* ... */ },
});

PCI Compliance

This library is designed for PCI DSS compliance:

  • No raw card data storage - Only tokenized payment methods
  • Audit logging - All operations are logged (without sensitive data)
  • Encryption - Sensitive data encrypted at rest
  • Signature verification - All webhooks verified before processing
import { PCICompliance, maskCardNumber } from '@intentos/stdlib-payments';

// Validate no raw card data in objects
const isCompliant = PCICompliance.validateNoRawCardData(logData);

// Mask card numbers for display
const masked = maskCardNumber('4242424242424242'); // ************4242

Idempotency

All write operations support idempotency keys:

import { IdempotencyManager, RedisIdempotencyManager } from '@intentos/stdlib-payments';

const idempotency = new RedisIdempotencyManager(redisClient, {
  prefix: 'payments:idem:',
  expirySeconds: 86400,
});

Fraud Detection

Built-in fraud detection with configurable rules:

import { createFraudDetector, defaultFraudRules } from '@intentos/stdlib-payments';

const fraudDetector = createFraudDetector(contextProvider, defaultFraudRules, {
  critical: 75, // Block transactions with risk score >= 75
  high: 50,
  medium: 25,
});

Metrics

Prometheus-compatible metrics:

import { MetricsCollector } from '@intentos/stdlib-payments';

const metrics = new MetricsCollector();

// After processing payments...
const prometheusOutput = metrics.toPrometheusFormat();

Available metrics:

  • payments_created_total - Counter by status, currency
  • payment_latency_ms - Histogram
  • payment_errors_total - Counter by error_code
  • captures_total - Counter by currency
  • refunds_total - Counter by currency
  • webhooks_received_total - Counter by provider, event_type
  • webhooks_processed_total - Counter by provider, event_type, success

ISL Specifications

The formal ISL specifications are in the intents/ directory:

intents/
├── domain.isl        # Type definitions, enums, compliance types
├── payment.isl       # Payment and Refund entities
└── behaviors/
    ├── create.isl    # CreatePayment behavior
    ├── capture.isl   # CapturePayment behavior
    ├── refund.isl    # RefundPayment behavior
    └── webhook.isl   # ProcessWebhook behavior

Each behavior specification includes:

  • Actors - Who can perform the action
  • Input/Output - Data contracts with constraints
  • Preconditions - What must be true before execution
  • Postconditions - What must be true after execution
  • Invariants - What must always be true
  • Temporal - SLA requirements
  • Security - Rate limits, authentication
  • Compliance - PCI DSS, SOC2 requirements
  • Scenarios - Test cases
  • Chaos - Failure scenarios

Testing

# Run tests
pnpm test

# Run with coverage
pnpm test:coverage

# Watch mode
pnpm test:watch

License

MIT