backend-manager 5.0.142 → 5.0.144
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/CHANGELOG.md +9 -0
- package/package.json +1 -1
- package/src/manager/helpers/user.js +30 -0
package/CHANGELOG.md
CHANGED
|
@@ -14,6 +14,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
|
14
14
|
- `Fixed` for any bug fixes.
|
|
15
15
|
- `Security` in case of vulnerabilities.
|
|
16
16
|
|
|
17
|
+
# [5.0.144] - 2026-03-13
|
|
18
|
+
### Added
|
|
19
|
+
- `User.resolveSubscription()` static method that derives calculated subscription fields (plan, active, trialing, cancelling) from raw user data
|
|
20
|
+
|
|
21
|
+
# [5.0.143] - 2026-03-13
|
|
22
|
+
### Changed
|
|
23
|
+
- `sendOrderEmail()` now accepts a `copy` parameter to control whether admin receives a copy (defaults to `true` for backward compat)
|
|
24
|
+
- Abandoned cart reminder emails no longer send admin copies (`copy: false`) to reduce inbox noise
|
|
25
|
+
|
|
17
26
|
# [5.0.140] - 2026-03-12
|
|
18
27
|
### Fixed
|
|
19
28
|
- Chargebee meta_data backfill not including `orderId`, causing `getOrderId()` to fail on future webhooks
|
package/package.json
CHANGED
|
@@ -345,4 +345,34 @@ function User(Manager, settings) {
|
|
|
345
345
|
return self;
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
+
// Resolves calculated subscription fields that require derivation logic
|
|
349
|
+
// Raw data (product.id, status, trial, cancellation) is on the user object directly
|
|
350
|
+
// Returns: { plan, active, trialing, cancelling }
|
|
351
|
+
// - plan: the plan ID the user effectively has access to RIGHT NOW ('basic' if cancelled/suspended)
|
|
352
|
+
// - active: user has active access (active, trialing, or cancelling)
|
|
353
|
+
// - trialing: user is in an active trial (status is 'active' but trial hasn't expired)
|
|
354
|
+
// - cancelling: cancellation is pending (status is 'active' but cancellation.pending is true)
|
|
355
|
+
User.resolveSubscription = function resolveSubscription(account) {
|
|
356
|
+
const subscription = (account?.subscription || account?.properties?.subscription) || {};
|
|
357
|
+
const productId = subscription.product?.id || 'basic';
|
|
358
|
+
|
|
359
|
+
let trialing = false;
|
|
360
|
+
let cancelling = false;
|
|
361
|
+
|
|
362
|
+
if (productId !== 'basic' && subscription.status === 'active') {
|
|
363
|
+
trialing = !!(subscription.trial?.claimed
|
|
364
|
+
&& subscription.trial?.expires?.timestampUNIX > Math.floor(Date.now() / 1000));
|
|
365
|
+
cancelling = !trialing && !!subscription.cancellation?.pending;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const active = (productId !== 'basic' && subscription.status === 'active');
|
|
369
|
+
|
|
370
|
+
return {
|
|
371
|
+
plan: active ? productId : 'basic',
|
|
372
|
+
active,
|
|
373
|
+
trialing,
|
|
374
|
+
cancelling,
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
|
|
348
378
|
module.exports = User;
|