@p2psats/shared

v3.0.0

Published

Shared types, alert matcher, and NIP-69 helpers for p2psats

Readme

@p2psats/shared

Shared types, alert matcher, and NIP-69 helpers for the p2psats project. This package is the single source of truth consumed by both the Vue 3 frontend and the NestJS backend. It ships as a dual ESM + CommonJS package and has zero runtime dependencies.

Scope

The library ships the minimum surface needed to keep matching logic consistent across consumers:

  • Order, Alert, Side, Currency, SourceId, PaymentMethod, RepProps, CrossedPair, CrossResult types
  • matchesRule(order, alert) — the alert matcher
  • DEFAULT_RULE — the default rule template
  • parseOrder(event) — NIP-69 event → RawNip69Order (accepts any {id, pubkey, created_at, tags} shape; no nostr-tools runtime dep)

The relay list (which Nostr relays to subscribe to) is not shipped here — that's operational config and each consumer owns its own copy. UI-flavored helpers (orderAdapter, data.ts catalogs of currencies, payment methods, BTC reference rates) also stay in the frontend; the backend implements its own minimal adapter producing the Order fields the matcher actually reads.

Install

npm install @p2psats/shared

Usage

import { matchesRule } from '@p2psats/shared'

const matched = matchesRule(order, alert)
import { parseOrder } from '@p2psats/shared/nip69/parseOrder'

const raw = parseOrder(event) // or null on shape mismatch

Versioning policy

Any change to the shape of Alert or Order, or to the semantics of matchesRule, is a major version bump. Consumers (frontend and backend) must update in lockstep. Minor bumps add backward-compatible exports; patch bumps fix bugs without observable behavior changes.

Local dev

To test an unpublished build in a consumer project:

# Option 1 — npm link (symlink, fastest iteration)
cd p2psats-shared && npm run build && npm link
cd ../p2psats && npm link @p2psats/shared

# Option 2 — pack + local install (closest to real publish)
cd p2psats-shared && npm run build && npm pack
cd ../p2psats && npm install ../p2psats-shared/p2psats-shared-2.0.0.tgz