@goweekdays/core 2.11.11 → 2.11.12
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 +6 -0
- package/dist/index.js +71 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -6020,7 +6020,7 @@ var schemaSubscriptionTransaction = import_joi22.default.object({
|
|
|
6020
6020
|
"promo-expired",
|
|
6021
6021
|
"promo-updated"
|
|
6022
6022
|
).required(),
|
|
6023
|
-
description: import_joi22.default.string().
|
|
6023
|
+
description: import_joi22.default.string().optional().allow("", null),
|
|
6024
6024
|
createdBy: import_joi22.default.string().hex().length(24).required(),
|
|
6025
6025
|
createdByName: import_joi22.default.string().optional().allow("", null)
|
|
6026
6026
|
});
|
|
@@ -8425,13 +8425,42 @@ function useSubscriptionService() {
|
|
|
8425
8425
|
case "fixed":
|
|
8426
8426
|
return Math.min(seats, limit) * (promo.fixedRate ?? 0) + Math.max(seats - limit, 0) * planPrice;
|
|
8427
8427
|
case "flat":
|
|
8428
|
-
return (promo.flatRate ?? 0) + Math.max(seats - limit
|
|
8428
|
+
return (promo.flatRate ?? 0) + Math.max(0, seats - limit) * planPrice;
|
|
8429
8429
|
case "volume":
|
|
8430
8430
|
return promo.tiers?.length ? calculateVolumeTierAmount(promo.tiers, 1, seats, planPrice) : planPrice * seats;
|
|
8431
8431
|
default:
|
|
8432
8432
|
return planPrice * seats;
|
|
8433
8433
|
}
|
|
8434
8434
|
}
|
|
8435
|
+
function computeAdditionalSeatAmount(additionalSeats, planPrice, promo, paidSeats) {
|
|
8436
|
+
if (additionalSeats <= 0)
|
|
8437
|
+
return 0;
|
|
8438
|
+
if (!promo) {
|
|
8439
|
+
return additionalSeats * planPrice;
|
|
8440
|
+
}
|
|
8441
|
+
const limit = promo.seats && promo.seats > 0 ? promo.seats : Infinity;
|
|
8442
|
+
switch (promo.type) {
|
|
8443
|
+
case "flat": {
|
|
8444
|
+
const chargeableSeats = Math.max(0, paidSeats + additionalSeats - limit) - Math.max(0, paidSeats - limit);
|
|
8445
|
+
return chargeableSeats * planPrice;
|
|
8446
|
+
}
|
|
8447
|
+
case "fixed": {
|
|
8448
|
+
const promoSeatsLeft = Math.max(0, limit - paidSeats);
|
|
8449
|
+
const promoSeats = Math.min(additionalSeats, promoSeatsLeft);
|
|
8450
|
+
const normalSeats = additionalSeats - promoSeats;
|
|
8451
|
+
return promoSeats * (promo.fixedRate ?? 0) + normalSeats * planPrice;
|
|
8452
|
+
}
|
|
8453
|
+
case "volume":
|
|
8454
|
+
return promo.tiers?.length ? calculateVolumeTierAmount(
|
|
8455
|
+
promo.tiers,
|
|
8456
|
+
paidSeats + 1,
|
|
8457
|
+
additionalSeats,
|
|
8458
|
+
planPrice
|
|
8459
|
+
) : additionalSeats * planPrice;
|
|
8460
|
+
default:
|
|
8461
|
+
return additionalSeats * planPrice;
|
|
8462
|
+
}
|
|
8463
|
+
}
|
|
8435
8464
|
function computeProration(subscription, seats, plan, promo) {
|
|
8436
8465
|
const additionalSeats = Math.max(0, seats - subscription.paidSeats);
|
|
8437
8466
|
if (additionalSeats === 0)
|
|
@@ -8445,10 +8474,11 @@ function useSubscriptionService() {
|
|
|
8445
8474
|
const cycleDays = plan.billingCycle === "yearly" ? 365 : 30;
|
|
8446
8475
|
if (daysRemaining === 0)
|
|
8447
8476
|
return 0;
|
|
8448
|
-
const additionalAmount =
|
|
8477
|
+
const additionalAmount = computeAdditionalSeatAmount(
|
|
8449
8478
|
additionalSeats,
|
|
8450
8479
|
plan.price,
|
|
8451
|
-
promo
|
|
8480
|
+
promo,
|
|
8481
|
+
subscription.paidSeats
|
|
8452
8482
|
);
|
|
8453
8483
|
return additionalAmount / cycleDays * daysRemaining;
|
|
8454
8484
|
}
|
|
@@ -8464,7 +8494,6 @@ function useSubscriptionService() {
|
|
|
8464
8494
|
const isNew = !existingSubscription;
|
|
8465
8495
|
const isPromoChange = !!existingSubscription && value.promoCode !== void 0 && value.promoCode !== existingSubscription.promoCode;
|
|
8466
8496
|
const isSeatIncrease = !!existingSubscription && value.seats > existingSubscription.seats;
|
|
8467
|
-
const isSeatDecrease = !!existingSubscription && value.seats < existingSubscription.seats;
|
|
8468
8497
|
if (isPromoChange && isSeatIncrease) {
|
|
8469
8498
|
throw new import_utils44.BadRequestError(
|
|
8470
8499
|
"Cannot change promo code while increasing seats. Perform actions separately."
|
|
@@ -8733,6 +8762,9 @@ function useSubscriptionService() {
|
|
|
8733
8762
|
if (subscription.promoCode) {
|
|
8734
8763
|
await updatePromoUsageStatusByOrgId(value.org, "inactive", session);
|
|
8735
8764
|
}
|
|
8765
|
+
let description = `Promo code updated to ${value.promoCode ?? "none"}. At the time of update, ${(0, import_utils44.formatNumber)(subscription.paidSeats, {
|
|
8766
|
+
decimalPlaces: 0
|
|
8767
|
+
})} seat(s) were already included in the subscription.`;
|
|
8736
8768
|
if (promo && promo._id) {
|
|
8737
8769
|
await addPromoUsage(
|
|
8738
8770
|
{
|
|
@@ -8742,11 +8774,44 @@ function useSubscriptionService() {
|
|
|
8742
8774
|
},
|
|
8743
8775
|
session
|
|
8744
8776
|
);
|
|
8777
|
+
const additionalDescription = `${promo.seats ? `Seats beyond ${(0, import_utils44.formatNumber)(promo.seats, {
|
|
8778
|
+
decimalPlaces: 0
|
|
8779
|
+
})} are charged at the standard rate.` : ""}`;
|
|
8780
|
+
if (promo.type === "flat") {
|
|
8781
|
+
description += ` ${(0, import_utils44.formatNumber)(promo.flatRate ?? 0, {
|
|
8782
|
+
currency,
|
|
8783
|
+
useSymbol: true
|
|
8784
|
+
})} ${promo.seats ? `limited to ${(0, import_utils44.formatNumber)(promo.seats, {
|
|
8785
|
+
decimalPlaces: 0
|
|
8786
|
+
})} seat(s)` : " for all seats"}. ${additionalDescription}`;
|
|
8787
|
+
}
|
|
8788
|
+
if (promo.type === "fixed") {
|
|
8789
|
+
description += ` ${(0, import_utils44.formatNumber)(promo.fixedRate ?? 0, {
|
|
8790
|
+
currency,
|
|
8791
|
+
useSymbol: true
|
|
8792
|
+
})} per seat${promo.seats ? `, limited to ${(0, import_utils44.formatNumber)(promo.seats, {
|
|
8793
|
+
decimalPlaces: 0
|
|
8794
|
+
})} seat(s)` : ""}. ${additionalDescription}`;
|
|
8795
|
+
}
|
|
8796
|
+
if (promo.type === "volume") {
|
|
8797
|
+
if (promo.tiers && promo.tiers.length > 0) {
|
|
8798
|
+
const tierDescriptions = promo.tiers.map((tier) => {
|
|
8799
|
+
const maxSeatsDesc = tier.maxSeats === 0 ? "and above" : `to ${(0, import_utils44.formatNumber)(tier.maxSeats, { decimalPlaces: 0 })}`;
|
|
8800
|
+
return `${(0, import_utils44.formatNumber)(tier.minSeats, {
|
|
8801
|
+
decimalPlaces: 0
|
|
8802
|
+
})} ${maxSeatsDesc} ${(0, import_utils44.formatNumber)(tier.rate, {
|
|
8803
|
+
currency,
|
|
8804
|
+
useSymbol: true
|
|
8805
|
+
})} per seat`;
|
|
8806
|
+
}).join(", ");
|
|
8807
|
+
description += ` Volume tiers, ${tierDescriptions}.`;
|
|
8808
|
+
}
|
|
8809
|
+
}
|
|
8745
8810
|
}
|
|
8746
8811
|
await addTransaction(
|
|
8747
8812
|
{
|
|
8748
8813
|
type: "promo-updated",
|
|
8749
|
-
description
|
|
8814
|
+
description,
|
|
8750
8815
|
amount: 0,
|
|
8751
8816
|
currency,
|
|
8752
8817
|
subscription: subscription._id?.toString() ?? "",
|