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

@bayar-sdk/core

v0.0.1

Published

Core contract, types, errors and provider contract tests for bayar-sdk — an unofficial multi-provider payment gateway SDK (TypeScript) for Midtrans & Xendit.

Readme

@bayar-sdk/core

Contract inti multi-provider payment gateway untuk bayar-sdk. Semua tipe publik, error, dan aturan idempotency didefinisikan di package ini — adapter provider (@bayar-sdk/midtrans, @bayar-sdk/xendit) hanya mengimplementasikan contract-nya. Dependency selalu satu arah: provider → core, core tidak pernah import provider.

Instalasi

bun add @bayar-sdk/core

Contract PaymentProvider

interface PaymentProvider {
	createCharge(req, opts: { idempotencyKey }): Promise<ChargeResult>;
	getCharge(chargeId: string): Promise<ChargeResult>;
	refund(req, opts: { idempotencyKey }): Promise<RefundResult>;
	parseWebhook(payload: unknown, headers: Headers): Promise<WebhookEvent>;
	capturePayment?(chargeId: string): Promise<ChargeResult>; // opsional
}

capturePayment opsional — provider yang tidak mendukungnya melempar CAPTURE_NOT_SUPPORTED.

Tipe utama

ChargeRequest

interface ChargeRequest {
	amount: number; // integer minor unit, contoh 50000 = Rp50.000
	currency: string;
	paymentMethod: PaymentMethodInput;
	referenceId: string; // id transaksi di aplikasi consumer
	customer?: { name?; email?; phone? };
	description?: string;
	metadata?: Record<string, string>;
}

paymentMethod adalah discriminated union:

type PaymentMethodInput =
	| { type: "virtual_account"; bank: string }
	| { type: "qris" }
	| { type: "ewallet"; channel: string }
	| { type: "card"; token: string };

card menerima token hasil tokenisasi client-side — raw card data (PAN/CVV) tidak pernah diproses di repo ini.

PaymentStatus (state machine)

pendingpaid | failed | expired | cancelled, lalu dari paid bisa refunded / partially_refunded / disputed. Nilai unknown untuk status provider yang belum dikenal. Tidak ada transisi paid → pending.

Idempotency

createCharge dan refund wajib menerima idempotencyKey. assertIdempotencyKey() melempar INVALID_REQUEST untuk key kosong atau > 128 karakter. Provider menyimpan hasil per key; key sama + payload sama dikembalikan idempotent, key sama + payload beda → DUPLICATE_IDEMPOTENCY_KEY.

Error PaymentSDKError

Semua error provider dinormalisasi ke satu class:

class PaymentSDKError extends Error {
	code: PaymentErrorCode;
	provider: string;
	providerErrorCode?: string;
	retryable: boolean;
}

| code | retryable | | ---------------------------- | --------- | | INVALID_REQUEST | no | | AUTH_FAILED | no | | INSUFFICIENT_BALANCE | no | | CHARGE_DECLINED | no | | CHARGE_NOT_FOUND | no | | DUPLICATE_IDEMPOTENCY_KEY | no | | REFUND_EXCEEDS_CHARGE_AMOUNT | no | | REFUND_NOT_ALLOWED | no | | CAPTURE_NOT_SUPPORTED | no | | WEBHOOK_SIGNATURE_INVALID | no | | PROVIDER_RATE_LIMITED | yes | | PROVIDER_UNAVAILABLE | yes | | UNKNOWN | no |

Helper: isPaymentSDKError(err) (duck-typing — aman walau ada dua salinan package), isRetryable(err).

Webhook

Provider wajib memverifikasi signature di dalam parseWebhook() sebelum mengembalikan WebhookEvent; signature invalid melempar WEBHOOK_SIGNATURE_INVALID. Payload yang tidak lolos verifikasi tidak pernah menjadi event.

Testing utilities

@bayar-sdk/core/testing menyediakan runProviderContractTests() — satu suite contract yang memastikan adapter mematuhi PaymentProvider, termasuk status state machine dan idempotency. Provider baru wajib lolos suite ini.

Dokumen