@timardex/cluemart-server-shared 1.0.300 → 1.0.301
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/{chunk-6WS5FH7A.mjs → chunk-LOZFYYVW.mjs} +2 -1
- package/dist/index.cjs +15 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.mjs +15 -4
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.mjs +1 -1
- package/dist/service/index.cjs +15 -4
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +7 -4
- package/dist/service/index.d.ts +7 -4
- package/dist/service/index.mjs +17 -5
- package/dist/service/index.mjs.map +1 -1
- package/package.json +1 -1
- /package/dist/{chunk-6WS5FH7A.mjs.map → chunk-LOZFYYVW.mjs.map} +0 -0
package/dist/index.d.mts
CHANGED
|
@@ -764,8 +764,9 @@ type AwardAffiliateVendorSubscriptionRewardsResult = {
|
|
|
764
764
|
* - Vendor is active, not deleted, and `promoCodes` includes the affiliate code
|
|
765
765
|
* - Vendor owner has a non-expired Standard / Pro / Pro+ vendor licence
|
|
766
766
|
*
|
|
767
|
-
* Reward type follows the owner's highest valid licence:
|
|
768
|
-
* - Pro / Pro+ → `ACTIVE_VENDOR_PRO_SUBSCRIPTION` (3 pts)
|
|
767
|
+
* Reward type follows the owner's highest valid licence + Stripe paying status:
|
|
768
|
+
* - Pro / Pro+ with active Stripe → `ACTIVE_VENDOR_PRO_SUBSCRIPTION` (3 pts)
|
|
769
|
+
* - Pro / Pro+ without paying Stripe → `ACTIVE_VENDOR_STANDARD_SUBSCRIPTION` (1 pt)
|
|
769
770
|
* - Standard → `ACTIVE_VENDOR_STANDARD_SUBSCRIPTION` (1 pt)
|
|
770
771
|
*
|
|
771
772
|
* Idempotent per affiliate + vendor + reward type + calendar month.
|
|
@@ -846,9 +847,11 @@ declare function normalizeAffiliatePromoCodes(promoCodes: PromoCodeType[] | null
|
|
|
846
847
|
* Maps a vendor owner's highest valid vendor licence to a monthly subscription reward.
|
|
847
848
|
*
|
|
848
849
|
* Prefer Pro / Pro+ over Standard when both are valid.
|
|
850
|
+
* Pro / Pro+ only yields the Pro reward when the owner has an active Stripe subscription;
|
|
851
|
+
* otherwise falls back to the Standard subscription reward.
|
|
849
852
|
* Returns `null` when no non-expired vendor licence applies.
|
|
850
853
|
*/
|
|
851
|
-
declare function mapVendorLicenceToSubscriptionRewardType(licences: UserLicenceType[] | null | undefined, now?: Date): EnumAffiliateRewardType | null;
|
|
854
|
+
declare function mapVendorLicenceToSubscriptionRewardType(licences: UserLicenceType[] | null | undefined, now?: Date, stripe?: UserType["stripe"] | null): EnumAffiliateRewardType | null;
|
|
852
855
|
/** Inclusive start / exclusive end of the UTC calendar month containing `now`. */
|
|
853
856
|
declare function getSubscriptionRewardPeriodBounds(now?: Date): {
|
|
854
857
|
periodEnd: Date;
|
package/dist/index.d.ts
CHANGED
|
@@ -764,8 +764,9 @@ type AwardAffiliateVendorSubscriptionRewardsResult = {
|
|
|
764
764
|
* - Vendor is active, not deleted, and `promoCodes` includes the affiliate code
|
|
765
765
|
* - Vendor owner has a non-expired Standard / Pro / Pro+ vendor licence
|
|
766
766
|
*
|
|
767
|
-
* Reward type follows the owner's highest valid licence:
|
|
768
|
-
* - Pro / Pro+ → `ACTIVE_VENDOR_PRO_SUBSCRIPTION` (3 pts)
|
|
767
|
+
* Reward type follows the owner's highest valid licence + Stripe paying status:
|
|
768
|
+
* - Pro / Pro+ with active Stripe → `ACTIVE_VENDOR_PRO_SUBSCRIPTION` (3 pts)
|
|
769
|
+
* - Pro / Pro+ without paying Stripe → `ACTIVE_VENDOR_STANDARD_SUBSCRIPTION` (1 pt)
|
|
769
770
|
* - Standard → `ACTIVE_VENDOR_STANDARD_SUBSCRIPTION` (1 pt)
|
|
770
771
|
*
|
|
771
772
|
* Idempotent per affiliate + vendor + reward type + calendar month.
|
|
@@ -846,9 +847,11 @@ declare function normalizeAffiliatePromoCodes(promoCodes: PromoCodeType[] | null
|
|
|
846
847
|
* Maps a vendor owner's highest valid vendor licence to a monthly subscription reward.
|
|
847
848
|
*
|
|
848
849
|
* Prefer Pro / Pro+ over Standard when both are valid.
|
|
850
|
+
* Pro / Pro+ only yields the Pro reward when the owner has an active Stripe subscription;
|
|
851
|
+
* otherwise falls back to the Standard subscription reward.
|
|
849
852
|
* Returns `null` when no non-expired vendor licence applies.
|
|
850
853
|
*/
|
|
851
|
-
declare function mapVendorLicenceToSubscriptionRewardType(licences: UserLicenceType[] | null | undefined, now?: Date): EnumAffiliateRewardType | null;
|
|
854
|
+
declare function mapVendorLicenceToSubscriptionRewardType(licences: UserLicenceType[] | null | undefined, now?: Date, stripe?: UserType["stripe"] | null): EnumAffiliateRewardType | null;
|
|
852
855
|
/** Inclusive start / exclusive end of the UTC calendar month containing `now`. */
|
|
853
856
|
declare function getSubscriptionRewardPeriodBounds(now?: Date): {
|
|
854
857
|
periodEnd: Date;
|
package/dist/index.mjs
CHANGED
|
@@ -9356,14 +9356,21 @@ function createAffiliateReward(rewardType, createdAt) {
|
|
|
9356
9356
|
}
|
|
9357
9357
|
|
|
9358
9358
|
// src/service/affiliate/vendorSubscriptionRewards.ts
|
|
9359
|
-
function
|
|
9359
|
+
function isPayingStripeSubscription(stripe) {
|
|
9360
|
+
if (!stripe?.subscriptionId) return false;
|
|
9361
|
+
return stripe.status === EnumSubscriptionStatus.ACTIVE || stripe.status === EnumSubscriptionStatus.TRIALING;
|
|
9362
|
+
}
|
|
9363
|
+
function mapVendorLicenceToSubscriptionRewardType(licences, now = /* @__PURE__ */ new Date(), stripe) {
|
|
9360
9364
|
const validTypes = new Set(
|
|
9361
9365
|
(licences ?? []).filter(
|
|
9362
9366
|
(licence) => new Date(licence.expiryDate).getTime() > now.getTime()
|
|
9363
9367
|
).map((licence) => licence.licenceType)
|
|
9364
9368
|
);
|
|
9365
9369
|
if (validTypes.has(EnumUserLicence.PRO_VENDOR) || validTypes.has(EnumUserLicence.PRO_PLUS_VENDOR)) {
|
|
9366
|
-
|
|
9370
|
+
if (isPayingStripeSubscription(stripe)) {
|
|
9371
|
+
return EnumAffiliateRewardType.ACTIVE_VENDOR_PRO_SUBSCRIPTION;
|
|
9372
|
+
}
|
|
9373
|
+
return EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
|
|
9367
9374
|
}
|
|
9368
9375
|
if (validTypes.has(EnumUserLicence.STANDARD_VENDOR)) {
|
|
9369
9376
|
return EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
|
|
@@ -9405,8 +9412,12 @@ async function findEligibleReferredVendor(resourceId, affiliateCode) {
|
|
|
9405
9412
|
}).select("_id name owner.userId").lean().exec();
|
|
9406
9413
|
}
|
|
9407
9414
|
async function resolveSubscriptionRewardTypeForVendorOwner(vendorOwnerUserId, now) {
|
|
9408
|
-
const vendorOwner = await UserModel.findById(vendorOwnerUserId).select("licences").lean().exec();
|
|
9409
|
-
return mapVendorLicenceToSubscriptionRewardType(
|
|
9415
|
+
const vendorOwner = await UserModel.findById(vendorOwnerUserId).select("licences stripe").lean().exec();
|
|
9416
|
+
return mapVendorLicenceToSubscriptionRewardType(
|
|
9417
|
+
vendorOwner?.licences,
|
|
9418
|
+
now,
|
|
9419
|
+
vendorOwner?.stripe
|
|
9420
|
+
);
|
|
9410
9421
|
}
|
|
9411
9422
|
async function notifyAffiliateOwnerOfSubscriptionReward({
|
|
9412
9423
|
affiliateId,
|