@downcity/services

Install one Downcity package for accounts, balance, usage, Stripe payment, and Creem payment services.

@downcity/services combines the official Downcity services into one package while keeping the capability boundaries clear.

With one installation, you can opt into:

  • AccountsService for registration, login, OAuth, sessions, and user_token
  • BalanceService for global wallet, ledger, topups, and redeem codes
  • PaymentService for exposing which payment methods the current City supports, together with providers like stripePaymentProvider and creemPaymentProvider
  • UsageService for real user-side service-call facts

Install

pnpm add @downcity/services

Minimal setup

import { Federation } from "@downcity/city";
import {
  AccountsService,
  BalanceService,
  creemPaymentProvider,
  PaymentService,
  stripePaymentProvider,
  UsageService,
} from "@downcity/services";

const base = new Federation({ db });
const balance = new BalanceService();

base.use(new AccountsService());
base.use(balance);
base.use(new PaymentService({
  readTopup: async (topup_id) => await balance.readTopup(topup_id),
  finishTopup: async (topup_id, extra) => await balance.finishTopup(topup_id, extra),
  providers: [
    stripePaymentProvider(),
    creemPaymentProvider(),
  ],
}));
base.use(new UsageService());

On the product side, the usual first call is:

const methods = await guest.service("payment").get("methods");

Then the frontend can choose the concrete method from methods.items, such as stripe or creem.

Read by capability

  1. For auth, read Accounts Service
  2. For wallet flows, read Balance Service
  3. For usage events, read Usage Service
  4. For Stripe topups, read Stripe Payment Service
  5. For Creem topups, read Creem Payment Service