@timardex/cluemart-server-shared 1.0.304 → 1.0.306
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/{Affiliate-BxNv9k41.d.mts → Affiliate-B76iZ3fE.d.mts} +2 -1
- package/dist/{Affiliate-DRuifOv4.d.ts → Affiliate-gqV1-654.d.ts} +2 -1
- package/dist/{chunk-GQWLGM2W.mjs → chunk-SY7T26IW.mjs} +11 -1
- package/dist/chunk-SY7T26IW.mjs.map +1 -0
- package/dist/index.cjs +37 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.mjs +37 -25
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +10 -0
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.d.mts +2 -2
- package/dist/mongoose/index.d.ts +2 -2
- package/dist/mongoose/index.mjs +1 -1
- package/dist/service/index.cjs +37 -25
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +4 -3
- package/dist/service/index.d.ts +4 -3
- package/dist/service/index.mjs +28 -26
- package/dist/service/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-GQWLGM2W.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -724,8 +724,9 @@ declare const SchoolModel: mongoose__default.Model<SchoolDocument, {}, {}, {}, m
|
|
|
724
724
|
}, any>;
|
|
725
725
|
|
|
726
726
|
type SchemaAffiliateReward = AffiliateRewardType;
|
|
727
|
-
type SchemaAffiliateResourceType = Omit<AffiliateResourceType, "resourceId"> & {
|
|
727
|
+
type SchemaAffiliateResourceType = Omit<AffiliateResourceType, "resourceId" | "resourceOwner"> & {
|
|
728
728
|
resourceId: ObjectId;
|
|
729
|
+
resourceOwner: SchemaOwnerType;
|
|
729
730
|
};
|
|
730
731
|
type AffiliateDocument = Omit<AffiliateType, "_id" | "owner" | "affiliateResources"> & {
|
|
731
732
|
affiliateResources: SchemaAffiliateResourceType[];
|
|
@@ -761,8 +762,9 @@ type AwardAffiliateVendorSubscriptionRewardsResult = {
|
|
|
761
762
|
* Eligibility per affiliate resource:
|
|
762
763
|
* - Affiliate is not soft-deleted
|
|
763
764
|
* - Linked `affiliateResources` entry is vendor, `resourceActive`, and not deleted
|
|
764
|
-
* - Vendor is active, not deleted,
|
|
765
|
-
*
|
|
765
|
+
* - Vendor is active, not deleted, has the affiliate promo code, and
|
|
766
|
+
* `owner.userId` matches `affiliateResources.resourceOwner.userId`
|
|
767
|
+
* - `affiliateResources.resourceOwner` has a non-expired Standard / Pro / Pro+ vendor licence
|
|
766
768
|
*
|
|
767
769
|
* Reward type follows the owner's highest valid licence + Stripe paying status:
|
|
768
770
|
* - Pro / Pro+ with paying Stripe (ACTIVE/TRIALING) → `ACTIVE_VENDOR_PRO_SUBSCRIPTION` (3 pts)
|
package/dist/index.d.ts
CHANGED
|
@@ -724,8 +724,9 @@ declare const SchoolModel: mongoose__default.Model<SchoolDocument, {}, {}, {}, m
|
|
|
724
724
|
}, any>;
|
|
725
725
|
|
|
726
726
|
type SchemaAffiliateReward = AffiliateRewardType;
|
|
727
|
-
type SchemaAffiliateResourceType = Omit<AffiliateResourceType, "resourceId"> & {
|
|
727
|
+
type SchemaAffiliateResourceType = Omit<AffiliateResourceType, "resourceId" | "resourceOwner"> & {
|
|
728
728
|
resourceId: ObjectId;
|
|
729
|
+
resourceOwner: SchemaOwnerType;
|
|
729
730
|
};
|
|
730
731
|
type AffiliateDocument = Omit<AffiliateType, "_id" | "owner" | "affiliateResources"> & {
|
|
731
732
|
affiliateResources: SchemaAffiliateResourceType[];
|
|
@@ -761,8 +762,9 @@ type AwardAffiliateVendorSubscriptionRewardsResult = {
|
|
|
761
762
|
* Eligibility per affiliate resource:
|
|
762
763
|
* - Affiliate is not soft-deleted
|
|
763
764
|
* - Linked `affiliateResources` entry is vendor, `resourceActive`, and not deleted
|
|
764
|
-
* - Vendor is active, not deleted,
|
|
765
|
-
*
|
|
765
|
+
* - Vendor is active, not deleted, has the affiliate promo code, and
|
|
766
|
+
* `owner.userId` matches `affiliateResources.resourceOwner.userId`
|
|
767
|
+
* - `affiliateResources.resourceOwner` has a non-expired Standard / Pro / Pro+ vendor licence
|
|
766
768
|
*
|
|
767
769
|
* Reward type follows the owner's highest valid licence + Stripe paying status:
|
|
768
770
|
* - Pro / Pro+ with paying Stripe (ACTIVE/TRIALING) → `ACTIVE_VENDOR_PRO_SUBSCRIPTION` (3 pts)
|
package/dist/index.mjs
CHANGED
|
@@ -7282,12 +7282,16 @@ var AFFILIATE_RESOURCE_FIELDS_FRAGMENT = gql`
|
|
|
7282
7282
|
resourceDeletedAt
|
|
7283
7283
|
resourceId
|
|
7284
7284
|
resourceName
|
|
7285
|
+
resourceOwner {
|
|
7286
|
+
...OwnerFields
|
|
7287
|
+
}
|
|
7285
7288
|
resourceType
|
|
7286
7289
|
rewards {
|
|
7287
7290
|
...AffiliateRewardFields
|
|
7288
7291
|
}
|
|
7289
7292
|
}
|
|
7290
7293
|
${AFFILIATE_REWARD_FIELDS_FRAGMENT}
|
|
7294
|
+
${OWNER_FIELDS_FRAGMENT}
|
|
7291
7295
|
`;
|
|
7292
7296
|
var AFFILIATE_BANK_ACCOUNT_DETAILS_FIELDS_FRAGMENT = gql`
|
|
7293
7297
|
fragment AffiliateBankAccountDetailsFields on AffiliateBankAccountDetailsType {
|
|
@@ -7342,6 +7346,7 @@ var AFFILIATE_FIELDS_FRAGMENT = gql`
|
|
|
7342
7346
|
createdAt
|
|
7343
7347
|
deletedAt
|
|
7344
7348
|
redeemHistory {
|
|
7349
|
+
paidAt
|
|
7345
7350
|
redeemedAt
|
|
7346
7351
|
rewardValue
|
|
7347
7352
|
}
|
|
@@ -9148,6 +9153,10 @@ var affiliateResourceSchema = new MongooseSchema25(
|
|
|
9148
9153
|
type: mongoose25.Schema.Types.ObjectId
|
|
9149
9154
|
},
|
|
9150
9155
|
resourceName: { required: true, type: String },
|
|
9156
|
+
resourceOwner: {
|
|
9157
|
+
required: true,
|
|
9158
|
+
type: OwnerTypeSchema
|
|
9159
|
+
},
|
|
9151
9160
|
resourceType: {
|
|
9152
9161
|
enum: Object.values(EnumResourceType),
|
|
9153
9162
|
required: true,
|
|
@@ -9199,6 +9208,7 @@ var affiliateDetailsSchema = new MongooseSchema25(
|
|
|
9199
9208
|
);
|
|
9200
9209
|
var redeemHistorySchema = new MongooseSchema25(
|
|
9201
9210
|
{
|
|
9211
|
+
paidAt: { default: null, required: false, type: Date },
|
|
9202
9212
|
redeemedAt: { required: true, type: Date },
|
|
9203
9213
|
rewardValue: { required: true, type: Number }
|
|
9204
9214
|
},
|
|
@@ -9313,7 +9323,7 @@ var SHARE_RESOURCE_LABEL2 = {
|
|
|
9313
9323
|
school: "School"
|
|
9314
9324
|
};
|
|
9315
9325
|
|
|
9316
|
-
// node_modules/@timardex/cluemart-shared/dist/chunk-
|
|
9326
|
+
// node_modules/@timardex/cluemart-shared/dist/chunk-OBZTGPBJ.mjs
|
|
9317
9327
|
var PROMO_CODE_PREFIX2 = "CM-";
|
|
9318
9328
|
var OBJECT_ID_PATH_SEGMENT2 = "[a-f0-9]{24}";
|
|
9319
9329
|
var OBJECT_ID_PATH_SEGMENT_END2 = `${OBJECT_ID_PATH_SEGMENT2}$`;
|
|
@@ -9415,7 +9425,7 @@ var gameScreenIdentifierList2 = [
|
|
|
9415
9425
|
}
|
|
9416
9426
|
];
|
|
9417
9427
|
|
|
9418
|
-
// node_modules/@timardex/cluemart-shared/dist/chunk-
|
|
9428
|
+
// node_modules/@timardex/cluemart-shared/dist/chunk-QBU7N4P2.mjs
|
|
9419
9429
|
import dayjs4 from "dayjs";
|
|
9420
9430
|
var statusOptions2 = [
|
|
9421
9431
|
...Object.values(EnumInviteStatus2).map((status) => ({
|
|
@@ -10646,13 +10656,19 @@ async function findAffiliatesWithActiveVendorReferrals() {
|
|
|
10646
10656
|
deletedAt: null
|
|
10647
10657
|
}).select("_id affiliateCode affiliateResources owner").lean().exec();
|
|
10648
10658
|
}
|
|
10649
|
-
async function
|
|
10650
|
-
|
|
10659
|
+
async function isEligibleReferredVendor({
|
|
10660
|
+
affiliateCode,
|
|
10661
|
+
resourceId,
|
|
10662
|
+
resourceOwnerUserId
|
|
10663
|
+
}) {
|
|
10664
|
+
const match = await VendorModel.exists({
|
|
10651
10665
|
_id: resourceId,
|
|
10652
10666
|
active: true,
|
|
10653
10667
|
deletedAt: null,
|
|
10668
|
+
"owner.userId": resourceOwnerUserId,
|
|
10654
10669
|
promoCodes: affiliateCode
|
|
10655
|
-
}).
|
|
10670
|
+
}).exec();
|
|
10671
|
+
return Boolean(match);
|
|
10656
10672
|
}
|
|
10657
10673
|
async function resolveSubscriptionRewardTypeForVendorOwner(vendorOwnerUserId, now) {
|
|
10658
10674
|
const vendorOwner = await UserModel.findById(vendorOwnerUserId).select("licences stripe").lean().exec();
|
|
@@ -10694,8 +10710,7 @@ async function tryAwardSubscriptionReward({
|
|
|
10694
10710
|
createdAt,
|
|
10695
10711
|
period,
|
|
10696
10712
|
resource,
|
|
10697
|
-
rewardType
|
|
10698
|
-
vendor
|
|
10713
|
+
rewardType
|
|
10699
10714
|
}) {
|
|
10700
10715
|
const reward = createAffiliateReward(rewardType, createdAt);
|
|
10701
10716
|
const updateResult = await AffiliateModel.updateOne(
|
|
@@ -10705,7 +10720,7 @@ async function tryAwardSubscriptionReward({
|
|
|
10705
10720
|
$elemMatch: {
|
|
10706
10721
|
resourceActive: true,
|
|
10707
10722
|
resourceDeletedAt: null,
|
|
10708
|
-
resourceId:
|
|
10723
|
+
resourceId: resource.resourceId,
|
|
10709
10724
|
resourceType: EnumResourceType.VENDOR,
|
|
10710
10725
|
rewards: {
|
|
10711
10726
|
$not: {
|
|
@@ -10730,15 +10745,12 @@ async function tryAwardSubscriptionReward({
|
|
|
10730
10745
|
if (updateResult.modifiedCount === 0) {
|
|
10731
10746
|
return "skipped";
|
|
10732
10747
|
}
|
|
10733
|
-
|
|
10734
|
-
|
|
10735
|
-
|
|
10736
|
-
|
|
10737
|
-
|
|
10738
|
-
|
|
10739
|
-
rewardValue: reward.rewardValue
|
|
10740
|
-
});
|
|
10741
|
-
}
|
|
10748
|
+
await notifyAffiliateOwnerOfSubscriptionReward({
|
|
10749
|
+
affiliateId: affiliate._id,
|
|
10750
|
+
affiliateOwnerUserId: affiliate.owner.userId,
|
|
10751
|
+
resourceName: resource.resourceName,
|
|
10752
|
+
rewardValue: reward.rewardValue
|
|
10753
|
+
});
|
|
10742
10754
|
return "awarded";
|
|
10743
10755
|
}
|
|
10744
10756
|
async function processAffiliateVendorReferral({
|
|
@@ -10749,15 +10761,16 @@ async function processAffiliateVendorReferral({
|
|
|
10749
10761
|
period,
|
|
10750
10762
|
resource
|
|
10751
10763
|
}) {
|
|
10752
|
-
const
|
|
10753
|
-
|
|
10754
|
-
|
|
10755
|
-
|
|
10756
|
-
|
|
10764
|
+
const vendorEligible = await isEligibleReferredVendor({
|
|
10765
|
+
affiliateCode,
|
|
10766
|
+
resourceId: resource.resourceId,
|
|
10767
|
+
resourceOwnerUserId: resource.resourceOwner.userId
|
|
10768
|
+
});
|
|
10769
|
+
if (!vendorEligible) {
|
|
10757
10770
|
return "skipped";
|
|
10758
10771
|
}
|
|
10759
10772
|
const rewardType = await resolveSubscriptionRewardTypeForVendorOwner(
|
|
10760
|
-
|
|
10773
|
+
resource.resourceOwner.userId,
|
|
10761
10774
|
now
|
|
10762
10775
|
);
|
|
10763
10776
|
if (!rewardType) {
|
|
@@ -10768,8 +10781,7 @@ async function processAffiliateVendorReferral({
|
|
|
10768
10781
|
createdAt,
|
|
10769
10782
|
period,
|
|
10770
10783
|
resource,
|
|
10771
|
-
rewardType
|
|
10772
|
-
vendor
|
|
10784
|
+
rewardType
|
|
10773
10785
|
});
|
|
10774
10786
|
}
|
|
10775
10787
|
async function awardAffiliateVendorSubscriptionRewards(now = /* @__PURE__ */ new Date()) {
|