@ordinatio/billing 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -308,4 +308,17 @@ declare function paddleTransactionBody(items: ReadonlyArray<{
308
308
  quantity: number;
309
309
  }>, organizationId: string): TransactionBody;
310
310
 
311
- export { type Access, type Band, type BillingRecord, type CanStartCheckout, type CheckoutRecord, DAY_MS, type Interval, InvalidPricePlanError, type LockCandidate, type LockDecision, PENDING_CHECKOUT_MS, type PaddleCatalog, type PaddleCatalogOptions, type PaddleCatalogPort, type PaddleExistingPrice, type PaddleItems, type PaddlePriceSpec, type PaddleSyncResult, type PlanStatus, type PlanUpdate, type Price, type PriceLine, type PricePlan, type PricePlanInput, type SeatCheck, type SeatSubscription, type SignatureInput, type SignatureResult, type SubscriptionReading, type TransactionBody, type TransactionCompleted, accessFor, averagePerSeatCents, canAddSeat, canStartCheckout, checkoutKey, decideLock, definePricePlan, formatCents, isLocked, mustCheckOnRenew, paddleCatalog, paddleItems, paddleTransactionBody, priceFor, readPaddleSubscription, readPaddleTransaction, reusableCheckout, seatLimitFor, seatsUsed, syncPaddleCatalog, trialEndFrom, verifyPaddleSignature };
311
+ type ManageRecord = {
312
+ status: string;
313
+ currentPeriodEnd: Date | null;
314
+ } | null;
315
+ interface ManageActions {
316
+ state: 'active' | 'past_due' | 'ends_on' | 'pauses_on' | 'ended' | 'none';
317
+ /** The date a scheduled end or pause takes effect; null in every other state. */
318
+ endsAt: Date | null;
319
+ updatePayment: boolean;
320
+ cancel: boolean;
321
+ }
322
+ declare function manageActionsFor(record: ManageRecord, now: Date): ManageActions;
323
+
324
+ export { type Access, type Band, type BillingRecord, type CanStartCheckout, type CheckoutRecord, DAY_MS, type Interval, InvalidPricePlanError, type LockCandidate, type LockDecision, type ManageActions, type ManageRecord, PENDING_CHECKOUT_MS, type PaddleCatalog, type PaddleCatalogOptions, type PaddleCatalogPort, type PaddleExistingPrice, type PaddleItems, type PaddlePriceSpec, type PaddleSyncResult, type PlanStatus, type PlanUpdate, type Price, type PriceLine, type PricePlan, type PricePlanInput, type SeatCheck, type SeatSubscription, type SignatureInput, type SignatureResult, type SubscriptionReading, type TransactionBody, type TransactionCompleted, accessFor, averagePerSeatCents, canAddSeat, canStartCheckout, checkoutKey, decideLock, definePricePlan, formatCents, isLocked, manageActionsFor, mustCheckOnRenew, paddleCatalog, paddleItems, paddleTransactionBody, priceFor, readPaddleSubscription, readPaddleTransaction, reusableCheckout, seatLimitFor, seatsUsed, syncPaddleCatalog, trialEndFrom, verifyPaddleSignature };
package/dist/index.js CHANGED
@@ -317,6 +317,20 @@ function paddleTransactionBody(items, organizationId) {
317
317
  }
318
318
  return { items: items.map((item) => ({ price_id: item.priceId, quantity: item.quantity })), custom_data: { organization_id: organizationId }, collection_mode: "automatic" };
319
319
  }
320
+
321
+ // src/manage.ts
322
+ var NOTHING = { state: "none", endsAt: null, updatePayment: false, cancel: false };
323
+ function manageActionsFor(record, now) {
324
+ if (record === null) return NOTHING;
325
+ if (record.status === "active") return { state: "active", endsAt: null, updatePayment: true, cancel: true };
326
+ if (record.status === "past_due") return { state: "past_due", endsAt: null, updatePayment: true, cancel: true };
327
+ if (record.status === "canceled" || record.status === "paused") {
328
+ const end = record.currentPeriodEnd;
329
+ if (end !== null && now.getTime() < end.getTime()) return { state: record.status === "canceled" ? "ends_on" : "pauses_on", endsAt: end, updatePayment: false, cancel: false };
330
+ return { state: "ended", endsAt: null, updatePayment: false, cancel: false };
331
+ }
332
+ return NOTHING;
333
+ }
320
334
  export {
321
335
  DAY_MS,
322
336
  InvalidPricePlanError,
@@ -330,6 +344,7 @@ export {
330
344
  definePricePlan,
331
345
  formatCents,
332
346
  isLocked,
347
+ manageActionsFor,
333
348
  mustCheckOnRenew,
334
349
  paddleCatalog,
335
350
  paddleItems,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ordinatio/billing",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "Billing rules for any subscription product, pure and with no database: graduated seat pricing from a plan you pass in (validated once, in integer cents), the trial / paying / locked state machine, which team to use when one is locked, and seat counting with the can-add-a-seat rule",