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

medusa-plugin-unirate

v0.1.0

Published

UniRate API exchange-rate integration for Medusa v2 — currency service module, API proxy routes, and VAT rates. Zero runtime deps.

Downloads

162

Readme

medusa-plugin-unirate

npm ci

UniRate API exchange-rate integration for Medusa v2 — register a currency service module in your Medusa app to get real-time FX rates, currency conversion, historical rates (Pro), and VAT rates, with zero runtime dependencies.


Install

npm install medusa-plugin-unirate

Get a free API key at unirateapi.com.


Quick start

1. Register the module in medusa-config.ts

import { defineConfig } from "@medusajs/framework/utils"

export default defineConfig({
  // ... your existing config
  modules: [
    {
      resolve: "medusa-plugin-unirate",
      options: {
        apiKey: process.env.UNIRATE_API_KEY,
        baseCurrency: "USD",   // default base for getRates() calls
      },
    },
  ],
})

Or use the typed helper:

import { createUniRateModule } from "medusa-plugin-unirate"

export default defineConfig({
  modules: [
    createUniRateModule({ apiKey: process.env.UNIRATE_API_KEY }),
  ],
})

2. Use the service in a workflow or API route

import { UNIRATE_MODULE } from "medusa-plugin-unirate"
import type { UniRateCurrencyModuleService } from "medusa-plugin-unirate"

// In a Medusa workflow step:
export const convertCurrencyStep = createStep(
  "convert-currency",
  async (input: { amount: number; from: string; to: string }, { container }) => {
    const unirate = container.resolve<UniRateCurrencyModuleService>(UNIRATE_MODULE)
    const converted = await unirate.convert(input.amount, input.from, input.to)
    return new StepResponse({ converted })
  },
)

// In a custom API route:
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
  const unirate = req.scope.resolve<UniRateCurrencyModuleService>(UNIRATE_MODULE)
  const rates = await unirate.getRates("USD")
  res.json({ base: "USD", rates })
}

API reference

All methods are on UniRateCurrencyModuleService, resolved from Medusa's container via UNIRATE_MODULE.

Exchange rates

// All rates relative to a base currency (defaults to module's baseCurrency)
const rates: Record<string, number> = await unirate.getRates()
const rates: Record<string, number> = await unirate.getRates("EUR")

// Single currency pair
const rate: number = await unirate.getRate("USD", "EUR")  // e.g. 0.92

Conversion

// Convert an amount between two currencies
const result: number = await unirate.convert(100, "USD", "EUR")  // e.g. 92.00

Currencies

// List all supported currency codes
const currencies: string[] = await unirate.listCurrencies()
// ["USD", "EUR", "GBP", "JPY", ...]

Historical rates (Pro)

Historical endpoints require a UniRate Pro subscription.

// Single historical rate
const rate: number = await unirate.getHistoricalRate("2024-01-15", "USD", "EUR")

// All historical rates for a date
const rates: Record<string, number> = await unirate.getHistoricalRates("2024-01-15", "USD")

// Historical conversion
const result: number = await unirate.convertHistorical(500, "USD", "EUR", "2024-01-15")

// Date range series
const series: Record<string, Record<string, number>> = await unirate.getTimeSeries(
  "2024-01-01",
  "2024-01-07",
  "USD",          // base (optional, defaults to module's baseCurrency)
  ["EUR", "GBP"], // filter currencies (optional)
)

// Per-currency data availability
const limits = await unirate.getHistoricalLimits()

VAT rates

// All countries
const all = await unirate.getVatRates()
// { total_countries: 50, date: "...", vat_rates: { DE: { vat_rate: 19, ... }, ... } }

// Single country (ISO 3166-1 alpha-2)
const de = await unirate.getVatRates("DE")
// { country: "DE", vat_data: { country_code: "DE", country_name: "Germany", vat_rate: 19 } }

Configuration

| Option | Type | Default | Description | |---|---|---|---| | apiKey | string | UNIRATE_API_KEY env var | UniRate API key | | baseCurrency | string | "USD" | Default base for getRates() and time-series calls | | baseUrl | string | https://api.unirateapi.com | Override the API base URL | | timeoutMs | number | 30000 | Request timeout in milliseconds |


Error handling

All errors extend UniRateError. Specific subtypes:

| Class | HTTP status | When | |---|---|---| | AuthenticationError | 401 | Missing or invalid API key | | ProRequiredError | 403 | Endpoint requires a Pro subscription | | InvalidCurrencyError | 404 | Currency not found or no data | | InvalidRequestError | 400 | Invalid request parameters | | RateLimitError | 429 | Rate limit exceeded | | UniRateError | — | Network error or unexpected response |

import { ProRequiredError, UniRateError } from "medusa-plugin-unirate"

try {
  const rate = await unirate.getHistoricalRate("2024-01-01", "USD", "EUR")
} catch (err) {
  if (err instanceof ProRequiredError) {
    // endpoint needs Pro subscription
  } else if (err instanceof UniRateError) {
    console.error(err.status, err.message)
  }
}

Related UniRate packages

UniRate client libraries: Python · Node.js · Go · Rust · Ruby · PHP · Java · Swift · .NET

Framework integrations: Next.js · NestJS · SvelteKit · Nuxt · Vue · React · Astro · Eleventy · Hugo · Jekyll

Backend / data integrations: Django · FastAPI · Flask · Wagtail · LangChain · Airflow · dbt · Directus · Laravel

Money library adapters: Ruby Money gem

Tools: CLI · MCP server · VS Code · Obsidian · n8n


License

MIT — see LICENSE.