Skip to content

feat: Stripe Tax, Vercel Preview Protection, Supabase PITR Runbook, GitHub OAuth Scope Validation#700

Merged
temma02 merged 2 commits into
StellerCraft:mainfrom
Emmyt24:feat/issues-655-656-657-658
May 30, 2026
Merged

feat: Stripe Tax, Vercel Preview Protection, Supabase PITR Runbook, GitHub OAuth Scope Validation#700
temma02 merged 2 commits into
StellerCraft:mainfrom
Emmyt24:feat/issues-655-656-657-658

Conversation

@Emmyt24
Copy link
Copy Markdown
Contributor

@Emmyt24 Emmyt24 commented May 30, 2026

Summary

This PR implements four platform improvements spanning payments compliance, preview security, database resilience, and OAuth hardening.


#655 – Stripe Tax Rate Configuration for Regional Pricing Compliance

New files:

  • apps/backend/src/lib/stripe/tax.ts — tax configuration helpers (getTaxConfiguration, buildCheckoutTaxParams, buildTaxExemptUpdate, isTaxExempt)

Modified files:

  • apps/backend/src/services/payment.service.ts — integrates automatic_tax and tax_id_collection into createCheckoutSession; adds updateTaxExemptStatus for managing per-customer exemption (none | exempt | reverse)

Tax collection is gated on STRIPE_TAX_ENABLED=true so existing environments are unaffected. Tax-exempt customers (non-profits, B2B VAT reverse charge) are handled via the Stripe Customer tax_exempt field.


#656 – Vercel Deployment Protection Rules for Preview Access Control

New files:

  • apps/backend/src/lib/vercel/preview-protection.ts — HMAC-SHA256 bypass token issuance and validation (scoped to deployment ID, 1-hour TTL)
  • apps/backend/src/app/api/preview/access/route.ts — authenticated POST /api/preview/access endpoint; issues a token and returns a ready-to-use preview URL

Modified files:

  • vercel.json — adds deploymentProtection with standard protection for the preview environment and bypass token support enabled

Preview environments are protected by default. Unauthorized users receive a 401 from Vercel; authorised users access previews via a signed, time-limited bypass token.


#657 – Supabase Database Backup Strategy with Point-in-Time Recovery

New files:

  • docs/backup-recovery-runbook.md — full operational runbook: PITR configuration, step-by-step restore procedures, post-restore verification checklist, sensitive-column checks, RTO (< 30 min) / RPO (< 1 min) targets, and escalation guidance

Modified files:

  • docs/migration-procedures.md — new "Database Backup and Point-in-Time Recovery" section with pre-migration PITR checkpoints, recovery-point identification after a failed migration, idempotency requirements, and an RTO/RPO reference table

The runbook is referenced by the automated schema verification tests in supabase/tests/backup/recovery.test.ts.


#658 – GitHub OAuth Scope Validation for Required Repository Permissions

New files:

  • apps/backend/src/lib/github/scope-validator.tsfetchAndValidateScopes, validateScopes, parseGrantedScopes, buildMissingScopeMessage; handles GitHub's scope hierarchy (parent scope satisfies children)

Modified files:

  • apps/backend/src/app/api/auth/github/callback/route.ts — scope validation runs immediately after token exchange (step 4); tokens missing repo or read:user redirect to /app?github=error&reason=insufficient_scopes&missing=<scopes> to prompt re-authorization before any deployment work begins

Required scopes:

Scope Purpose
repo Create repos, push code, configure webhooks
read:user Read authenticated user profile during OAuth callback

Test plan

  • Stripe Tax: set STRIPE_TAX_ENABLED=true, create a checkout session, confirm automatic_tax.enabled in Stripe dashboard
  • Stripe Tax exempt: call updateTaxExemptStatus(userId, 'exempt'), verify customer tax_exempt field in Stripe
  • Preview protection: call POST /api/preview/access with a deployment ID, confirm token is returned and bypass URL is valid
  • Preview protection: attempt to access a preview URL without a token, confirm 401
  • Scope validation: authenticate with a GitHub token missing repo, confirm redirect to insufficient_scopes
  • Scope validation: authenticate with all required scopes, confirm normal connected redirect
  • PITR runbook: follow docs/backup-recovery-runbook.md restore checklist against a test Supabase project

Closes #655
Closes #656
Closes #657
Closes #658

…ithub oauth scope validation

## StellerCraft#655 – Stripe Tax Rate Configuration for Regional Pricing Compliance

- Added `apps/backend/src/lib/stripe/tax.ts` with `getTaxConfiguration`,
  `buildCheckoutTaxParams`, `buildTaxExemptUpdate`, and `isTaxExempt` helpers.
- Integrated automatic Stripe Tax into `PaymentService.createCheckoutSession`
  via the new `buildCheckoutTaxParams` helper — tax collection is gated on the
  `STRIPE_TAX_ENABLED=true` env var so non-tax environments are unaffected.
- Added optional `tax_id_collection` for checkout sessions when
  `STRIPE_TAX_COLLECT_ID=true`.
- Added `PaymentService.updateTaxExemptStatus` to set a customer's
  `tax_exempt` field (`none` | `exempt` | `reverse`) on their Stripe Customer
  record, supporting non-profit, government, and B2B VAT reverse-charge cases.

## StellerCraft#656 – Vercel Deployment Protection Rules for Preview Access Control

- Updated `vercel.json` with `deploymentProtection` config scoped to the
  `preview` environment — standard protection enabled with bypass token support.
- Added `apps/backend/src/lib/vercel/preview-protection.ts` with
  `issueBypassToken` and `validateBypassToken` using HMAC-SHA256 signatures
  scoped to a single deployment ID with a 1-hour TTL.
- Added `apps/backend/src/app/api/preview/access/route.ts`
  (`POST /api/preview/access`) — authenticated endpoint to issue a bypass token
  for a given deployment ID; returns the token, expiry, and ready-to-use
  preview URL with the query parameter appended.

## StellerCraft#657 – Supabase Database Backup Strategy with Point-in-Time Recovery

- Created `docs/backup-recovery-runbook.md` — full PITR operational runbook
  covering backup configuration, step-by-step restore procedures, post-restore
  verification checklist, sensitive-column checks, RTO/RPO targets, and
  escalation guidance. Referenced by the existing test suite in
  `supabase/tests/backup/recovery.test.ts`.
- Updated `docs/migration-procedures.md` with a new "Database Backup and
  Point-in-Time Recovery" section documenting pre-migration PITR checkpoints,
  recovery-point identification after a failed migration, idempotency
  requirements, and an RTO/RPO reference table.

## StellerCraft#658 – GitHub OAuth Scope Validation for Required Repository Permissions

- Added `apps/backend/src/lib/github/scope-validator.ts` with
  `fetchAndValidateScopes`, `validateScopes`, `parseGrantedScopes`, and
  `buildMissingScopeMessage`. Validates `repo` and `read:user` scopes using the
  `X-OAuth-Scopes` response header; handles scope hierarchy so that a parent
  scope (e.g. `user`) satisfies narrower children (e.g. `read:user`).
- Updated `apps/backend/src/app/api/auth/github/callback/route.ts` to run scope
  validation immediately after the token exchange (step 4 of the OAuth flow).
  Tokens with missing scopes redirect to
  `/app?github=error&reason=insufficient_scopes&missing=<scopes>` with a clear
  list of missing scopes, prompting the user to re-authorize rather than failing
  mid-deployment.

Closes StellerCraft#655
Closes StellerCraft#656
Closes StellerCraft#657
Closes StellerCraft#658
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 30, 2026

@Emmyt24 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@temma02 temma02 merged commit 2bf371b into StellerCraft:main May 30, 2026
0 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment