@scryan7371/sdr-subscription
v0.1.5
Published
Reusable Stripe-only subscription capability for API and app clients.
Readme
sdr-subscription
Reusable Stripe-only subscription capability for API and app clients.
Scope
This package is intentionally split into two surfaces:
api: shared domain contracts + Stripe status mapping helpers.app: typed client for subscription endpoints used by mobile/web app frontends.nest: reusable Nest module/service/controllers/entity for API projects.
Package Layout
src/api/contracts.ts: canonical request/response and status/provider types.src/api/stripe.ts: Stripe-to-domain status mapping.src/app/client.ts: client methods for user/admin subscription API calls.src/nest/*: Nest module + service + controllers + entity for subscription operations.
API Integration (Nest)
In your API project:
- Import the shared Nest surface:
import { SubscriptionModule } from "@scryan7371/sdr-subscription/nest";- Register it in your API module:
SubscriptionModule.forRoot({
stripeSecretKey: process.env.STRIPE_SECRET_KEY,
stripeWebhookSecret: process.env.STRIPE_WEBHOOK_SECRET,
});- Apply your app-specific guards/auth policies in your API app where needed.
App Integration (React Native / Web)
In your app project:
- Build client once:
import { app as sdrSubscription } from "@scryan7371/sdr-subscription";
const subscriptionClient = sdrSubscription.createSubscriptionClient({
baseUrl,
getAccessToken: () => accessToken,
});- Use methods in screens/services:
getMySubscriptionStatus()getMySubscriptions()cancelMySubscription(subscriptionId)cancelSubscriptionAsAdmin(subscriptionId)reactivateSubscriptionAsAdmin(subscriptionId)
Notes
- This is Stripe-only by design.
- Keep versions pinned in consumers.
Database Integration Tests
Real database tests are available with:
npm run test:dbThe test loader reads DB values from .env.test or .env.dev (current dir first, then project root), using either:
SUBSCRIPTION_TEST_DATABASE_URL(or fallbackDATABASE_URL), or- component vars:
DB_HOST,DB_PORT,DB_USER,DB_PASSWORD,DB_NAME.
Debug schema helpers:
npm run test:db:keep
npm run test:db:teardowntest:db:keepkeeps schemasdr_subscription_it_debugafter the run.test:db:teardownruns against the same schema and tears it down.
Publish (npmjs)
- Configure project-local npm auth (
.npmrc):
registry=https://registry.npmjs.org/
@scryan7371:registry=https://registry.npmjs.org/
//registry.npmjs.org/:_authToken=${NPM_TOKEN}- Set token, bump version, and publish:
export NPM_TOKEN=xxxx
npm version patch
npm publish --access public --registry=https://registry.npmjs.org --userconfig .npmrc- Push commit and tags:
git push
git push --tagsRelease Process
Use the built-in release scripts (recommended):
npm run release:patch
npm run release:minor
npm run release:majorEach release script:
- Validates git working tree is clean.
- Runs tests.
- Builds the package.
- Bumps
package.json/package-lock.json. - Commits as
chore(release): vX.Y.Z. - Creates tag
sdr-subscription-vX.Y.Z. - Pushes commit and tag.
Tag pushes (sdr-subscription-v*) trigger publish workflow in GitHub Actions.
CI Publish (GitHub Actions)
Tag pushes like sdr-subscription-v* trigger .github/workflows/publish.yml.
Required repo secret:
NPM_TOKEN(npm granular token with read/write + bypass 2FA for automation).
Install
Install a pinned version:
npm install @scryan7371/[email protected]