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

@fragmentpay/server

v0.4.4

Published

Frag server SDK — accept crypto payments from any token, on any chain, settle in one asset.

Readme

@fragmentpay/server

Runtime-agnostic Frag SDK. Zero dependencies. Works in Node 18+, Bun, Deno, Cloudflare Workers, Vercel Edge, and every runtime with global fetch.

All inputs are validated at runtime — bad parameters throw FragValidationError with a clear path (e.g. [frag] createIntent.amount: min 0.01) before a network round-trip.

Install

npm install @fragmentpay/server
# or: bun add @fragmentpay/server
# or: pnpm add @fragmentpay/server

Required environment variables

| Name | Where | Example | | ------------------------ | ----------- | ------------------------------------------ | | FRAG_SECRET_KEY | server only | sk_live_… or sk_test_… | | FRAG_WEBHOOK_SECRET | server only | value shown when you create the webhook | | FRAG_BASE_URL (opt.) | server only | override host, default https://frag.cash |

Never expose sk_… in a browser bundle.

End-to-end example (copy-paste)

1. Create an intent from your backend

// server/frag.ts
import { Frag } from "@fragmentpay/server";

export const frag = new Frag({ secretKey: process.env.FRAG_SECRET_KEY! });

export async function startCheckout(orderId: string, cents: number, email: string) {
  const intent = await frag.paymentIntents.create({
    amount: cents / 100,
    currency: "USD",
    customerEmail: email,
    settlement: {
      chain: "base",
      token: "USDC",
      address: process.env.MERCHANT_USDC_ADDRESS!,
    },
    successUrl: "https://shop.example.com/thanks",
    cancelUrl: "https://shop.example.com/cart",
    metadata: { order_id: orderId },
    idempotencyKey: `order_${orderId}`,
  });
  return { intentId: intent.id, checkoutUrl: intent.checkout_url };
}

2. Verify inbound webhooks

// server/webhook.ts
import { verifyWebhook } from "@fragmentpay/server";

export async function POST(req: Request) {
  const payload = await req.text();
  const event = await verifyWebhook({
    payload,
    signature: req.headers.get("frag-signature"),
    secret: process.env.FRAG_WEBHOOK_SECRET!,
  });

  if (event.type === "payment_intent.settled") {
    await markOrderPaid(event.data as { id: string; metadata: { order_id: string } });
  }
  return new Response("ok");
}

3. React drop-in on the frontend — see @fragmentpay/react.

Advanced options

const frag = new Frag({
  secretKey: process.env.FRAG_SECRET_KEY!,
  baseUrl: "https://frag.cash", // default
  timeoutMs: 15_000, // per-request timeout
  maxRetries: 3, // retries on 5xx / network errors with Retry-After honored
  fetch: myCustomFetch, // inject a custom fetch (Workers, tracing, etc.)
});

Every method throws FragError on non-2xx responses. It carries status, code, message, and requestId for observability, plus the raw provider body when available.

Validation errors

Every method validates its arguments and throws a FragValidationError before touching the network:

frag.paymentIntents.create({ amount: -5 });
// FragValidationError: [frag] createIntent.amount: min 0.01

Public API surface

  • frag.paymentIntents.{create, retrieve, list, cancel, transactions, routing}
    • routing(id) returns router candidates evaluated for the intent (chosen + rejected with reasons). route(id) is kept as a deprecated alias.
  • frag.refunds.{create, retrieve, list, retry, status}retry(id, { destination }) requeues a failed refund, optionally to a different address
  • frag.payouts.{retrieve, list, replay}
  • frag.webhookEndpoints.{create, list, retrieve, update, delete, rotateSecret}
  • frag.tokens.list({ chain })
  • verifyWebhook({ payload, signature, secret })
  • FragError (HTTP + upstream) and FragValidationError (input)

Idempotency

Every POST accepts an optional Idempotency-Key header (SDK auto-sends it when you set idempotencyKey). Replays within 24h with the same body return the original response; a different body returns HTTP 409 with code: "idempotency_conflict".

Webhook events

The SDK's WebhookEventType union stays in sync with the API. Notable events: payment_intent.created, payment_intent.quoted, payment_intent.executing, payment_intent.settled, payment_intent.failed, payment_intent.expired, payment_intent.cancelled, payment_intent.refunded, payout.created, payout.paid, payout.failed, ping.

License

MIT