@timardex/cluemart-server-shared 1.0.299 → 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/index.cjs CHANGED
@@ -63,7 +63,6 @@ __export(index_exports, {
63
63
  VendorModel: () => VendorModel,
64
64
  VerificationTokenModel: () => VerificationTokenModel,
65
65
  activeAffiliateCodeExists: () => activeAffiliateCodeExists,
66
- associatesSchema: () => associatesSchema,
67
66
  awardAffiliateVendorSubscriptionRewards: () => awardAffiliateVendorSubscriptionRewards,
68
67
  baseResourceFields: () => baseResourceFields,
69
68
  connectToDatabase: () => connectToDatabase,
@@ -3380,9 +3379,6 @@ var EnumRelationResource = /* @__PURE__ */ ((EnumRelationResource22) => {
3380
3379
  return EnumRelationResource22;
3381
3380
  })(EnumRelationResource || {});
3382
3381
  var EnumNotificationResourceType = /* @__PURE__ */ ((EnumNotificationResourceType22) => {
3383
- EnumNotificationResourceType22["ADDED_AS_ASSOCIATE_EVENT"] = "added_as_associate_event";
3384
- EnumNotificationResourceType22["ADDED_AS_ASSOCIATE_PARTNER"] = "added_as_associate_partner";
3385
- EnumNotificationResourceType22["ADDED_AS_ASSOCIATE_VENDOR"] = "added_as_associate_vendor";
3386
3382
  EnumNotificationResourceType22["APPROVED_AFFILIATE"] = "approved_affiliate";
3387
3383
  EnumNotificationResourceType22["AFFILIATE_REWARD_RECEIVED"] = "affiliate_reward_received";
3388
3384
  EnumNotificationResourceType22["APPROVED_EVENT"] = "approved_event";
@@ -5046,17 +5042,6 @@ var LICENCE_FIELDS_FRAGMENT = gql`
5046
5042
  prevLicenceType
5047
5043
  }
5048
5044
  `;
5049
- var ASSOCIATES_FIELDS_FRAGMENT = gql`
5050
- fragment AssociatesFields on AssociateType {
5051
- email
5052
- resourceId
5053
- resourceType
5054
- licence {
5055
- ...LicenceFields
5056
- }
5057
- }
5058
- ${LICENCE_FIELDS_FRAGMENT}
5059
- `;
5060
5045
  var TERMS_AGREEMENT_FIELDS_FRAGMENT = gql`
5061
5046
  fragment TermsAgreementFields on TermsAgreementType {
5062
5047
  appBuildNumber
@@ -5147,9 +5132,6 @@ var USER_FIELDS_FRAGMENT = gql`
5147
5132
  fragment UserFields on UserType {
5148
5133
  _id
5149
5134
  active
5150
- associates {
5151
- ...AssociatesFields
5152
- }
5153
5135
  affiliate
5154
5136
  avatar {
5155
5137
  ...ResourceImageFields
@@ -5189,7 +5171,6 @@ var USER_FIELDS_FRAGMENT = gql`
5189
5171
  updatedAt
5190
5172
  }
5191
5173
  ${RESOURCE_IMAGE_FIELDS_FRAGMENT}
5192
- ${ASSOCIATES_FIELDS_FRAGMENT}
5193
5174
  ${TERMS_AGREEMENT_FIELDS_FRAGMENT}
5194
5175
  ${USER_ACTIVITY_FIELDS_FRAGMENT}
5195
5176
  ${LICENCE_FIELDS_FRAGMENT}
@@ -5335,9 +5316,6 @@ var EVENT = gql`
5335
5316
  fragment EventFields on EventType {
5336
5317
  _id
5337
5318
  active
5338
- associates {
5339
- ...AssociatesFields
5340
- }
5341
5319
  adIds
5342
5320
  approvedAt
5343
5321
  cover {
@@ -5410,7 +5388,6 @@ var EVENT = gql`
5410
5388
  ${RESOURCE_IMAGE_FIELDS_FRAGMENT}
5411
5389
  ${SOCIAL_MEDIA_FIELDS_FRAGMENT}
5412
5390
  ${POSTER_USAGE_FIELDS_FRAGMENT}
5413
- ${ASSOCIATES_FIELDS_FRAGMENT}
5414
5391
  ${CONTACT_DETAILS_FIELDS_FRAGMENT}
5415
5392
  ${TERMS_AGREEMENT_FIELDS_FRAGMENT}
5416
5393
  ${RELATION_DATES_FRAGMENT}
@@ -5523,9 +5500,6 @@ var VENDOR = gql`
5523
5500
  fragment VendorFields on VendorType {
5524
5501
  _id
5525
5502
  active
5526
- associates {
5527
- ...AssociatesFields
5528
- }
5529
5503
  adIds
5530
5504
  approvedAt
5531
5505
  availability {
@@ -5616,7 +5590,6 @@ var VENDOR = gql`
5616
5590
  ${RESOURCE_IMAGE_FIELDS_FRAGMENT}
5617
5591
  ${SOCIAL_MEDIA_FIELDS_FRAGMENT}
5618
5592
  ${POSTER_USAGE_FIELDS_FRAGMENT}
5619
- ${ASSOCIATES_FIELDS_FRAGMENT}
5620
5593
  ${VENDOR_PRODUCT_LIST_FIELDS_FRAGMENT}
5621
5594
  ${CONTACT_DETAILS_FIELDS_FRAGMENT}
5622
5595
  ${TERMS_AGREEMENT_FIELDS_FRAGMENT}
@@ -5769,9 +5742,6 @@ var PARTNER = gql`
5769
5742
  fragment PartnerFields on PartnerType {
5770
5743
  _id
5771
5744
  active
5772
- associates {
5773
- ...AssociatesFields
5774
- }
5775
5745
  adIds
5776
5746
  approvedAt
5777
5747
  cover {
@@ -5822,7 +5792,6 @@ var PARTNER = gql`
5822
5792
  ${TERMS_AGREEMENT_FIELDS_FRAGMENT}
5823
5793
  ${LOCATION_FIELDS_FRAGMENT}
5824
5794
  ${OWNER_FIELDS_FRAGMENT}
5825
- ${ASSOCIATES_FIELDS_FRAGMENT}
5826
5795
  ${RESOURCE_IMAGE_FIELDS_FRAGMENT}
5827
5796
  ${POSTER_USAGE_FIELDS_FRAGMENT}
5828
5797
  ${SOCIAL_MEDIA_FIELDS_FRAGMENT}
@@ -6269,7 +6238,6 @@ var CHAT_MESSAGE_FIELDS_FRAGMENT = gql`
6269
6238
  var CHAT_PARTICIPANT = gql`
6270
6239
  fragment ChatParticipantFields on ChatParticipantType {
6271
6240
  active
6272
- isAssociate
6273
6241
  userAvatar
6274
6242
  userEmail
6275
6243
  userId
@@ -7747,7 +7715,6 @@ var MessageSchema = new MongooseSchema2(
7747
7715
  var ParticipantSchema = new MongooseSchema2(
7748
7716
  {
7749
7717
  active: { default: true, required: true, type: Boolean },
7750
- isAssociate: { default: null, required: false, type: Boolean },
7751
7718
  userAvatar: { required: false, type: String },
7752
7719
  userEmail: { required: true, type: String },
7753
7720
  userId: {
@@ -8072,26 +8039,6 @@ var userLicenseSchema = new MongooseSchema6(
8072
8039
  },
8073
8040
  { _id: false, timestamps: false }
8074
8041
  );
8075
- var associatesSchema = new MongooseSchema6(
8076
- {
8077
- email: { required: true, type: String },
8078
- licence: {
8079
- required: true,
8080
- type: userLicenseSchema
8081
- },
8082
- resourceId: {
8083
- required: true,
8084
- type: String
8085
- },
8086
- resourceType: {
8087
- enum: Object.values(EnumResourceType),
8088
- required: true,
8089
- type: String
8090
- }
8091
- },
8092
- { _id: false }
8093
- // Prevents Mongoose from creating an additional _id field for subdocuments
8094
- );
8095
8042
  var ContactDetailsSchema = new MongooseSchema6(
8096
8043
  {
8097
8044
  email: { required: false, type: String },
@@ -8207,10 +8154,6 @@ var baseResourceFields = {
8207
8154
  type: [import_mongoose6.default.Schema.Types.ObjectId]
8208
8155
  },
8209
8156
  approvedAt: { default: null, required: false, type: Date },
8210
- associates: {
8211
- required: false,
8212
- type: [associatesSchema]
8213
- },
8214
8157
  contactDetails: { required: false, type: ContactDetailsSchema },
8215
8158
  cover: {
8216
8159
  required: true,
@@ -8354,7 +8297,7 @@ schema4.index({ isRead: 1, userId: 1 });
8354
8297
  schema4.index({ createdAt: -1, userId: 1 });
8355
8298
  var NotificationModel = import_mongoose8.default.models.Notification || import_mongoose8.default.model("Notification", schema4);
8356
8299
 
8357
- // node_modules/@timardex/cluemart-shared/dist/chunk-VR3TDBJL.mjs
8300
+ // node_modules/@timardex/cluemart-shared/dist/chunk-X3OLM35T.mjs
8358
8301
  var EnumOSPlatform2 = /* @__PURE__ */ ((EnumOSPlatform22) => {
8359
8302
  EnumOSPlatform22["ANDROID"] = "android";
8360
8303
  EnumOSPlatform22["IOS"] = "ios";
@@ -8515,10 +8458,6 @@ var schema7 = new MongooseSchema11(
8515
8458
  required: false,
8516
8459
  type: import_mongoose11.default.Schema.Types.ObjectId
8517
8460
  },
8518
- associates: {
8519
- required: false,
8520
- type: [associatesSchema]
8521
- },
8522
8461
  avatar: {
8523
8462
  required: false,
8524
8463
  type: ResourceImageTypeSchema
@@ -8618,7 +8557,6 @@ var schema7 = new MongooseSchema11(
8618
8557
  },
8619
8558
  { strict: false, timestamps: true }
8620
8559
  );
8621
- schema7.index({ "associates.email": 1 });
8622
8560
  schema7.index({ "licences.expiryDate": 1 });
8623
8561
  schema7.index({ "licences.licenceType": 1 });
8624
8562
  var UserModel = import_mongoose11.default.models.User || import_mongoose11.default.model("User", schema7);
@@ -8736,7 +8674,6 @@ schema9.index({ name: 1 });
8736
8674
  schema9.index({ description: 1 });
8737
8675
  schema9.index({ region: 1 });
8738
8676
  schema9.index({ "categories.name": 1 });
8739
- schema9.index({ "associates.email": 1 });
8740
8677
  schema9.index({ slug: 1 });
8741
8678
  var VendorModel = import_mongoose13.default.models.Vendor || import_mongoose13.default.model("Vendor", schema9);
8742
8679
 
@@ -8875,7 +8812,6 @@ schema12.index({ description: 1 });
8875
8812
  schema12.index({ region: 1 });
8876
8813
  schema12.index({ "location.geo": "2dsphere" });
8877
8814
  schema12.index({ tags: 1 });
8878
- schema12.index({ "associates.email": 1 });
8879
8815
  schema12.index({ deletedAt: 1 });
8880
8816
  schema12.index({ "dateTime.dateStatus": 1 });
8881
8817
  schema12.index({ slug: 1 });
@@ -8904,7 +8840,6 @@ schema13.index({ name: 1 });
8904
8840
  schema13.index({ description: 1 });
8905
8841
  schema13.index({ region: 1 });
8906
8842
  schema13.index({ "location.geo": "2dsphere" });
8907
- schema13.index({ "associates.email": 1 });
8908
8843
  schema13.index({ slug: 1 });
8909
8844
  var PartnerModel = import_mongoose17.default.models.Partner || import_mongoose17.default.model("Partner", schema13);
8910
8845
 
@@ -9522,14 +9457,21 @@ function createAffiliateReward(rewardType, createdAt) {
9522
9457
  }
9523
9458
 
9524
9459
  // src/service/affiliate/vendorSubscriptionRewards.ts
9525
- function mapVendorLicenceToSubscriptionRewardType(licences, now = /* @__PURE__ */ new Date()) {
9460
+ function isPayingStripeSubscription(stripe) {
9461
+ if (!stripe?.subscriptionId) return false;
9462
+ return stripe.status === EnumSubscriptionStatus.ACTIVE || stripe.status === EnumSubscriptionStatus.TRIALING;
9463
+ }
9464
+ function mapVendorLicenceToSubscriptionRewardType(licences, now = /* @__PURE__ */ new Date(), stripe) {
9526
9465
  const validTypes = new Set(
9527
9466
  (licences ?? []).filter(
9528
9467
  (licence) => new Date(licence.expiryDate).getTime() > now.getTime()
9529
9468
  ).map((licence) => licence.licenceType)
9530
9469
  );
9531
9470
  if (validTypes.has(EnumUserLicence.PRO_VENDOR) || validTypes.has(EnumUserLicence.PRO_PLUS_VENDOR)) {
9532
- return EnumAffiliateRewardType.ACTIVE_VENDOR_PRO_SUBSCRIPTION;
9471
+ if (isPayingStripeSubscription(stripe)) {
9472
+ return EnumAffiliateRewardType.ACTIVE_VENDOR_PRO_SUBSCRIPTION;
9473
+ }
9474
+ return EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
9533
9475
  }
9534
9476
  if (validTypes.has(EnumUserLicence.STANDARD_VENDOR)) {
9535
9477
  return EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
@@ -9571,8 +9513,12 @@ async function findEligibleReferredVendor(resourceId, affiliateCode) {
9571
9513
  }).select("_id name owner.userId").lean().exec();
9572
9514
  }
9573
9515
  async function resolveSubscriptionRewardTypeForVendorOwner(vendorOwnerUserId, now) {
9574
- const vendorOwner = await UserModel.findById(vendorOwnerUserId).select("licences").lean().exec();
9575
- return mapVendorLicenceToSubscriptionRewardType(vendorOwner?.licences, now);
9516
+ const vendorOwner = await UserModel.findById(vendorOwnerUserId).select("licences stripe").lean().exec();
9517
+ return mapVendorLicenceToSubscriptionRewardType(
9518
+ vendorOwner?.licences,
9519
+ now,
9520
+ vendorOwner?.stripe
9521
+ );
9576
9522
  }
9577
9523
  async function notifyAffiliateOwnerOfSubscriptionReward({
9578
9524
  affiliateId,
@@ -9853,112 +9799,6 @@ async function updateAdStatuses() {
9853
9799
  );
9854
9800
  }
9855
9801
 
9856
- // src/service/associate.ts
9857
- var import_mongoose32 = __toESM(require("mongoose"));
9858
- function normalizeObjectId(id) {
9859
- return typeof id === "string" ? new import_mongoose32.default.Types.ObjectId(id) : id;
9860
- }
9861
- async function getAssociateEmailsForResource({
9862
- normalizedResourceId,
9863
- resourceType
9864
- }) {
9865
- const usersWithAssociates = await UserModel.find(
9866
- {
9867
- associates: {
9868
- $elemMatch: {
9869
- resourceId: normalizedResourceId,
9870
- resourceType
9871
- }
9872
- }
9873
- },
9874
- {
9875
- associates: 1
9876
- }
9877
- ).lean();
9878
- return [
9879
- ...new Set(
9880
- usersWithAssociates.flatMap(
9881
- (user) => (user.associates ?? []).filter(
9882
- (associate) => associate.resourceId === normalizedResourceId && associate.resourceType === resourceType
9883
- ).map((associate) => associate.email)
9884
- )
9885
- )
9886
- ];
9887
- }
9888
- async function pullAssociatesFromUsers({
9889
- normalizedResourceId,
9890
- resourceType
9891
- }) {
9892
- await UserModel.updateMany(
9893
- {
9894
- associates: {
9895
- $elemMatch: {
9896
- resourceId: normalizedResourceId,
9897
- resourceType
9898
- }
9899
- }
9900
- },
9901
- {
9902
- $pull: {
9903
- associates: {
9904
- resourceId: normalizedResourceId,
9905
- resourceType
9906
- }
9907
- }
9908
- }
9909
- );
9910
- }
9911
- async function pullAssociateParticipantsFromChats(resourceOwnerId, associateEmails) {
9912
- await ChatModel.updateMany(
9913
- {
9914
- active: true,
9915
- chatType: EnumChatType.RELATION,
9916
- deletedAt: null,
9917
- participants: {
9918
- $elemMatch: {
9919
- userId: resourceOwnerId
9920
- }
9921
- }
9922
- },
9923
- {
9924
- $pull: {
9925
- participants: {
9926
- isAssociate: true,
9927
- userEmail: {
9928
- $in: associateEmails
9929
- }
9930
- }
9931
- }
9932
- }
9933
- );
9934
- }
9935
- async function removeAssociateFromResource({
9936
- resourceId,
9937
- resourceOwnerId,
9938
- resourceType
9939
- }) {
9940
- try {
9941
- const scope = {
9942
- normalizedResourceId: resourceId.toString(),
9943
- resourceType
9944
- };
9945
- const associateEmails = await getAssociateEmailsForResource(scope);
9946
- if (associateEmails.length === 0) {
9947
- return;
9948
- }
9949
- await pullAssociatesFromUsers(scope);
9950
- await pullAssociateParticipantsFromChats(
9951
- normalizeObjectId(resourceOwnerId),
9952
- associateEmails
9953
- );
9954
- } catch (error) {
9955
- console.error(
9956
- `[removeAssociateFromResource] Failed for resourceId=${resourceId}, resourceType=${resourceType}`,
9957
- error
9958
- );
9959
- }
9960
- }
9961
-
9962
9802
  // src/service/vendor.ts
9963
9803
  async function updateVendorBasedOnUserLicense(userId, licenceType) {
9964
9804
  try {
@@ -9975,7 +9815,6 @@ async function updateVendorBasedOnUserLicense(userId, licenceType) {
9975
9815
  const updateData = {};
9976
9816
  const isStandardVendor = licenceType === EnumUserLicence.STANDARD_VENDOR;
9977
9817
  if (isStandardVendor) {
9978
- updateData.associates = [];
9979
9818
  updateData.availability = {
9980
9819
  corporate: false,
9981
9820
  private: false,
@@ -9995,25 +9834,18 @@ async function updateVendorBasedOnUserLicense(userId, licenceType) {
9995
9834
  active: isStandardVendor ? index < 6 : true
9996
9835
  }));
9997
9836
  await VendorModel.updateOne({ _id: vendor._id }, { $set: updateData });
9998
- if (isStandardVendor) {
9999
- await removeAssociateFromResource({
10000
- resourceId: vendor._id,
10001
- resourceOwnerId: vendor.owner.userId,
10002
- resourceType: EnumResourceType.VENDOR
10003
- });
10004
- }
10005
9837
  } catch (error) {
10006
9838
  console.error("[updateVendorBasedOnUserLicense] Failed:", error);
10007
9839
  }
10008
9840
  }
10009
9841
 
10010
9842
  // src/service/objectIdToString.ts
10011
- var import_mongoose35 = __toESM(require("mongoose"));
9843
+ var import_mongoose33 = __toESM(require("mongoose"));
10012
9844
  function convertObjectIdsToStrings(obj) {
10013
9845
  if (obj === null || obj === void 0) {
10014
9846
  return obj;
10015
9847
  }
10016
- if (obj instanceof import_mongoose35.default.Types.ObjectId) {
9848
+ if (obj instanceof import_mongoose33.default.Types.ObjectId) {
10017
9849
  return obj.toString();
10018
9850
  }
10019
9851
  if (obj instanceof Date) {
@@ -10229,7 +10061,6 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
10229
10061
  VendorModel,
10230
10062
  VerificationTokenModel,
10231
10063
  activeAffiliateCodeExists,
10232
- associatesSchema,
10233
10064
  awardAffiliateVendorSubscriptionRewards,
10234
10065
  baseResourceFields,
10235
10066
  connectToDatabase,