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

@ecompaymentskw/typescript-sdk

v0.1.0

Published

Official TypeScript SDK for Ecom Payments

Readme

@ecompaymentskw/typescript-sdk

Server-side TypeScript SDK for Ecom Payments E_API, E_LINKS, refunds, and webhook verification. Requires Node.js 18 or newer.

Install

npm install @ecompaymentskw/typescript-sdk

Configure

import { Ecom } from "@ecompaymentskw/typescript-sdk";

const ecom = new Ecom({
  apiToken: process.env.ECOM_API_TOKEN!,
  merchantId: process.env.ECOM_MID!,
  environment: "sandbox", // or "production"
});

Keep the API token and webhook secret on your server. Do not expose them in browser code.

E_API charges

const charge = await ecom.eApi.createCharge({
  amount: { value: 10, currency: "KWD" },
  options: { mode: "INDIRECT", paymentMethod: "KNET" },
  urls: {
    successUrl: "https://example.com/payment/success",
    errorUrl: "https://example.com/payment/error",
  },
  customer: {
    fullName: "Ali",
    phoneCode: "+965",
    phoneNumber: "66778899",
  },
  language: "en",
});

console.log(charge.paymentUrl);

const details = await ecom.eApi.getCharge(charge.paymentToken);

E_LINKS invoices

const invoice = await ecom.eLinks.createInvoice({
  amount: { value: 25, currency: "KWD" },
  customer: {
    fullName: "Ali",
    phoneCode: "+965",
    phoneNumber: "66778899",
    email: "[email protected]",
  },
  notification: { email: true, sms: true },
  language: "en",
});

const page = await ecom.eLinks.listInvoices({
  page: 1,
  take: 10,
  order: "DESC",
});

await ecom.eLinks.sendInvoiceReminder(invoice.id, { email: true });
await ecom.eLinks.markInvoiceAsPaid(invoice.id, {
  paymentMethod: "CASH",
  notes: "Paid at the store",
});

Other invoice methods are getInvoice, getInvoiceByPaymentToken, and deleteInvoice.

Refunds

const refund = await ecom.refunds.createRefund({
  amount: 5,
  ecomId: details.id,
  merchantReference: "refund-order-123",
});

const refunds = await ecom.refunds.listRefunds({
  page: 1,
  take: 10,
  order: "DESC",
});

const refundDetails = await ecom.refunds.getRefund(refund.id);

Webhooks

Verify the event's data object against the X-Webhook-Signature header:

import type { WebhookEvent } from "@ecompaymentskw/typescript-sdk";

function handleWebhook(
  event: WebhookEvent,
  signature: string,
  webhookSecret: string,
) {
  if (!ecom.webhooks.verifySignature(event.data, signature, webhookSecret)) {
    throw new Error("Invalid Ecom webhook signature");
  }

  switch (event.eventType) {
    case "TRANSACTION_STATUS_CHANGED":
      console.log(event.data.paymentStatus);
      break;
    case "REFUND_STATUS_CHANGED":
      console.log(event.data.status);
      break;
  }
}

generateSignature(data, secret) is also exported for testing.

Errors

Non-successful responses throw EcomApiError:

import { EcomApiError } from "@ecompaymentskw/typescript-sdk";

try {
  await ecom.eApi.getCharge("payment-token");
} catch (error) {
  if (error instanceof EcomApiError) {
    console.error(error.status, error.apiError, error.message, error.body);
  }
}