Skip to content

warengonzaga/buymeacoffee.js

BuyMeaCoffee.JS

created by release star npm downloads license

repo banner

A simple and lightweight community-made Bun-first client for the Buy Me A Coffee API with Node.js compatibility.

⚑ Features

  • Bun-first developer experience
  • TypeScript typings included
  • Supporters, subscriptions, and extras endpoints
  • Pagination and subscription status filters
  • By-id lookup methods for documented read endpoints
  • Supports Bun and Node.js

πŸ“¦ Installation

bun add buymeacoffee.js
npm install buymeacoffee.js

🧩 Usage

import BMC from "buymeacoffee.js";

const client = new BMC(process.env.BMC_ACCESS_TOKEN!);

const supporters = await client.Supporters();
const activeSubscriptions = await client.Subscriptions({ status: "active" });
const supporter = await client.Supporter(245731);
const extra = await client.Extra(30);

Method Examples

import BMC from "buymeacoffee.js";

const client = new BMC(process.env.BMC_ACCESS_TOKEN!);

const supporters = await client.Supporters();
const supportersPageTwo = await client.Supporters({ page: 2 });

const supporter = await client.Supporter(245731);

const subscriptions = await client.Subscriptions();
const activeSubscriptions = await client.Subscriptions({ status: "active" });
const inactiveSubscriptionsPageTwo = await client.Subscriptions({
  page: 2,
  status: "inactive",
});

const subscription = await client.Subscription(10647);

const extras = await client.Extras();
const extrasPageTwo = await client.Extras({ page: 2 });

const extra = await client.Extra(30);

Error Handling

import BMC, { BMCError } from "buymeacoffee.js";

const client = new BMC(process.env.BMC_ACCESS_TOKEN!);

try {
  await client.Subscriptions({ status: "active" });
} catch (error) {
  if (error instanceof BMCError) {
    console.error(error.status, error.endpoint, error.responseData);
  }
}

API Surface

Method Description
Supporters() Get the first page of supporters
Supporters({ page }) Get a specific supporters page
Supporter(id) Get a supporter by ID
Subscriptions() Get the first page of subscriptions
Subscriptions({ page, status }) Filter subscriptions by page and status
Subscription(id) Get a subscription by ID
Extras() Get the first page of extras
Extras({ page }) Get a specific extras page
Extra(id) Get an extra purchase by ID

πŸš€ Development

This project now uses Bun as the primary package manager, test runner, and local workflow.

bun install
bun run lint
bun test
bun run build

If you need a Node.js-only install for compatibility checks, npm install and npm run build still work.

The published package now includes declaration files for TypeScript consumers.

πŸ“– Documentation

Check out the official and complete documentation here.

docs

🌏 Community

Join to the official Buy Me a Coffee Discord community server!

BMC Community

Join to my growing tech community and get the latest updates!

community

🎯 Contributing

Contributions are welcome, create a pull request to this repo and I will review your code. Please consider to submit your pull request to the dev branch. Thank you!

Read the project's contributing guide for more info.

πŸ’¬ Discussions

For any questions, suggestions, ideas, or simply you want to share your experience in using this project, feel free to share and discuss it to the community!

πŸ› Issues

Please report any issues and bugs by creating a new issue here, also make sure you're reporting an issue that doesn't exist. Any help to improve the project would be appreciated. Thanks! πŸ™βœ¨

πŸ™ Sponsor

Like this project? Leave a star! ⭐⭐⭐⭐⭐

Want to support my work and get some perks? Become a sponsor! πŸ’–

Or, you just love what I do? Buy me a coffee! β˜•

Recognized my open-source contributions? Nominate me as GitHub Star! πŸ’«

πŸ“‹ Code of Conduct

Read the project's code of conduct.

πŸ“ƒ License

This project is licensed under MIT License.

πŸ“ Author

This project is created by Waren Gonzaga, with the help of awesome contributors.

contributors


πŸ’»πŸ’–β˜• by Waren Gonzaga | YHWH πŸ™ - Without Him, none of this exists, even me.

About

Simple and lightweight community contributed JavaScript SDK for Buy Me a Coffee REST API. πŸ’»β˜•βš‘

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  

Contributors