sponsorsme

Lightweight package that lets you see who is sponsoring you.

Usage no npm install needed!

<script type="module">
  import sponsorsme from 'https://cdn.skypack.dev/sponsorsme';
</script>

README

sponsorsme

Test codecov npm version

A lightweight utility to check whether a user sponsors you.

This package lets you get paid for the work you do by leveraging the GitHub Sponsors community. It's meant to be used primarily with GitHub applications and other similar workflows, but is general enough to be used just about anywhere.

All you need to start using it is a token of your sponsored account.

Example

const sponsors = Sponsors({
  token: 'bearer <token>',
})

// Tells whether someone is in tiers above 10€
function isVIPSponsor(sponsorhip?: Sponsorship): boolean {
  return sponsorhip?.tier.monthlyPriceInCents >= 10 * 100
}

const sponsor = await sponsors.getInfo('maticzav')

if (isVIPSponsor(sponsor)) {
  // Do something special!!!
}

Installation

yarn add sponsorsme

You can get the token from GitHub. Make sure you check at least 'user' and 'read:org' in permissions list.

❗️ NOTE: The token you use to check whether someone is your sponsor is not the same as your GitHub application's key!

Docs

type SponsorsOptions = {
  /**
   * Whether the client should use internal cache or not.
   */
  cache?: boolean
  /**
   * Viewer's GitHub token used for authentication.
   * You should prefix the token with "bearer".
   */
  token: string
}

/**
 * Creates a Sponsors client that you can use to get sponsors information.
 */
class Sponsors {
  constructor(opts: SponsorsOptions): Sponsors
  /**
   * Returns information about the sponsor if it exists.
   */
  getInfo(login: string): Promise<Optional<Sponsorship>>

  /**
   * Tells whether there exists a sponsor with the given login.
   */
  isSponsor(login: string): Promise<boolean>

  /**
   * Clears the cache.
   */
  flush(): void
}

//
// Types
//

type Sponsorship = {
  id: string
  createdAt: string
  /**
   * Sponsor information.
   */
  sponsor: SponsorshipSponsor
  /**
   * Whether sponsorship is publicly visible.
   */
  public: boolean
  /**
   * Information about the tier.
   */
  tier: SponsorshipTier
}

type SponsorshipSponsor = {
  /**
   * Login handle of the sponsor.
   */
  login: string
  /**
   * Sponsor's email if available.
   */
  email?: string
}

type SponsorshipTier = {
  id: string
  createdAt: string
  /**
   * Information about the tier.
   */
  name: string
  description: string
  /**
   * The amount sponsoree receives each month.
   */
  monthlyPriceInCents: number
}

License

MIT @ Matic Zavadlal