Skip to content

feat: add subscription billing foundation (schema, types, repository)#674

Closed
Ferryx349 wants to merge 2 commits into
cameri:mainfrom
Ferryx349:Billing
Closed

feat: add subscription billing foundation (schema, types, repository)#674
Ferryx349 wants to merge 2 commits into
cameri:mainfrom
Ferryx349:Billing

Conversation

@Ferryx349

Copy link
Copy Markdown
Collaborator

Description

Groundwork for subscription-based relay billing. Adds database schema, TypeScript types, settings shape, and repository layer only, no enforcement, workers, or payment flow changes. One-time admission billing remains unchanged.
Follows the same pattern as NIP-43 invite codes (#650): migration + types + repository + tests, nothing wired into runtime behavior yet.

Changes

Database

  • New user_subscriptions table (pubkey PK, stable id UUID for invoice FK)
    • plan_id, status, period timestamps, grace_until, cancel_at_period_end
    • Index on (status, current_period_end) for future worker queries
  • Extended invoices with nullable columns:
    • fee_schedule (admission | subscription | publication, default admission)
    • plan_id, subscription_id, period_start, period_end
      Plans live in settings (payments.subscriptionPlans[]), not a DB table.

Related Issue

Part of :- #673

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Non-functional change (docs, style, minor refactor)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my code changes.
  • I added a changeset, or this is docs-only and I added an empty changeset.
  • All new and existing tests passed.

Signed-off-by: ABHAY PANDEY <pandeyabhay967@gmail.com>
@changeset-bot

changeset-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2452287

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
nostream Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds the initial data-layer foundation for subscription-based relay billing (schema, settings/types, and repositories) without wiring any runtime enforcement or payment flow changes, aligning with the prior “foundation-only” pattern used for invite codes.

Changes:

  • Introduces user_subscriptions persistence + repository methods for lookup/upsert and future renewal/expiry queries.
  • Extends invoices with subscription billing fields (fee_schedule, plan_id, subscription_id, period_start/end) and updates invoice mapping/upsert behavior plus tests.
  • Adds settings/types/docs support for payments.subscriptionPlans[] and a changeset for the feature flag groundwork.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/unit/repositories/user-subscription-repository.spec.ts Adds unit coverage for the new subscription repository behaviors.
test/unit/repositories/invoice-repository.spec.ts Extends invoice repository tests for new subscription-related columns and defaults.
src/utils/transform.ts Maps new invoice DB columns onto the Invoice domain type.
src/repositories/user-subscription-repository.ts New repository implementing subscription CRUD/query primitives.
src/repositories/invoice-repository.ts Adds fee_schedule defaulting and includes new subscription columns in invoice upsert row shape.
src/@types/user-subscription.ts Introduces subscription domain/DB row types and SubscriptionStatus enum.
src/@types/settings.ts Adds subscription plan type definitions to settings schema.
src/@types/repositories.ts Exposes IUserSubscriptionRepository interface.
src/@types/invoice.ts Adds InvoiceFeeSchedule and optional subscription invoice fields.
resources/default-settings.yaml Adds payments.subscriptionPlans default; removes an admin TTL entry (see comment).
migrations/20260708_120000_create_subscription_billing_foundation.js Creates user_subscriptions, adds indexes/FKs, and extends invoices with subscription columns.
CONFIGURATION.md Documents the new payments.subscriptionPlans[] settings surface.
.changeset/subscription-billing-foundation.md Declares a minor release changeset for the new foundation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/repositories/invoice-repository.ts
Comment thread resources/default-settings.yaml
Signed-off-by: ABHAY PANDEY <pandeyabhay967@gmail.com>
@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 67.762% (+0.02%) from 67.747% — Ferryx349:Billing into cameri:main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants