@timardex/cluemart-server-shared 1.1.21 → 1.1.24
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-3JRVRK2N.mjs → chunk-YILYRHDN.mjs} +63 -21
- package/dist/chunk-YILYRHDN.mjs.map +1 -0
- package/dist/index.cjs +117 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +30 -6
- package/dist/index.d.ts +30 -6
- package/dist/index.mjs +114 -41
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +39 -19
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.d.mts +6 -4
- package/dist/mongoose/index.d.ts +6 -4
- package/dist/mongoose/index.mjs +1 -1
- package/dist/service/index.cjs +117 -41
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +26 -4
- package/dist/service/index.d.ts +26 -4
- package/dist/service/index.mjs +56 -23
- package/dist/service/index.mjs.map +1 -1
- package/package.json +3 -2
- package/dist/chunk-3JRVRK2N.mjs.map +0 -1
package/dist/service/index.d.mts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as mongoose from 'mongoose';
|
|
2
2
|
import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
|
|
3
|
-
import { PromoCodeType,
|
|
3
|
+
import { PromoCodeType, EnumAffiliateRewardType, EnumUserLicence, DateTimeType, EventListItemType, DateTimeWithPriceType } from '@timardex/cluemart-shared';
|
|
4
4
|
import { n as SchemaAffiliateResourceType, S as SchemaOwnerType, i as SchemaRelationType } from '../Affiliate-B76iZ3fE.mjs';
|
|
5
|
-
import {
|
|
5
|
+
import { O as ObjectId, G as GraphQLContext, f as SchemaCreateBulkNotificationInput } from '../Chat-Wn7yfc3v.mjs';
|
|
6
6
|
import dayjs from 'dayjs';
|
|
7
7
|
import { DateTimeType as DateTimeType$1 } from '@timardex/cluemart-shared/types';
|
|
8
|
+
import { EnumUserLicence as EnumUserLicence$1 } from '@timardex/cluemart-shared/enums';
|
|
8
9
|
import 'express';
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -82,7 +83,7 @@ declare function normalizeAffiliatePromoCodes(promoCodes: PromoCodeType[] | null
|
|
|
82
83
|
* otherwise falls back to the Standard subscription reward.
|
|
83
84
|
* Returns `null` when no non-expired vendor licence applies.
|
|
84
85
|
*/
|
|
85
|
-
declare function mapVendorLicenceToSubscriptionRewardType(
|
|
86
|
+
declare function mapVendorLicenceToSubscriptionRewardType(userId: ObjectId | string, now?: Date): Promise<EnumAffiliateRewardType | null>;
|
|
86
87
|
/** Inclusive start / exclusive end of the UTC calendar month containing `now`. */
|
|
87
88
|
declare function getSubscriptionRewardPeriodBounds(now?: Date): {
|
|
88
89
|
periodEnd: Date;
|
|
@@ -190,4 +191,25 @@ declare function didRemoveAnyEventDates(previousDateTime: EventDateSlot[] | unde
|
|
|
190
191
|
*/
|
|
191
192
|
declare function updateRelationDatesToUnavailable(relationDates: SchemaRelationType["relationDates"], eventDateTime: DateTimeWithPriceType[] | undefined): SchemaRelationType["relationDates"];
|
|
192
193
|
|
|
193
|
-
|
|
194
|
+
type PayingStripeSubscriptionPlanResult = {
|
|
195
|
+
hasSubscription: boolean;
|
|
196
|
+
plan: EnumUserLicence$1 | null;
|
|
197
|
+
validTypes: Set<EnumUserLicence$1>;
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Returns the paying Stripe plan when `currentPlan` is any PRO plan
|
|
201
|
+
* (event or vendor) and the subscription is active/trialing.
|
|
202
|
+
*/
|
|
203
|
+
declare function getPayingStripeSubscriptionPlan(userId: ObjectId | string, now?: Date): Promise<PayingStripeSubscriptionPlanResult>;
|
|
204
|
+
/**
|
|
205
|
+
* Like {@link getPayingStripeSubscriptionPlan} but only treats a vendor PRO
|
|
206
|
+
* plan (`PRO_VENDOR` / `PRO_PLUS_VENDOR`) as paying.
|
|
207
|
+
*/
|
|
208
|
+
declare function getPayingVendorStripeSubscriptionPlan(userId: ObjectId | string, now?: Date): Promise<PayingStripeSubscriptionPlanResult>;
|
|
209
|
+
/**
|
|
210
|
+
* Like {@link getPayingStripeSubscriptionPlan} but only treats an event PRO
|
|
211
|
+
* plan (`PRO_EVENT` / `PRO_PLUS_EVENT`) as paying.
|
|
212
|
+
*/
|
|
213
|
+
declare function getPayingEventStripeSubscriptionPlan(userId: ObjectId | string, now?: Date): Promise<PayingStripeSubscriptionPlanResult>;
|
|
214
|
+
|
|
215
|
+
export { ACTIVE_NOT_DELETED_FILTER, type AwardAffiliateVendorSubscriptionRewardsResult, type NotificationPubSub, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, connectToDatabase, convertObjectIdsToStrings, didRemoveAnyEventDates, findAffiliateByPromoCode, findEventOrImportedMarketById, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, isValidObjectId, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, publishNotificationEvents, saveNotificationsInDb, sendPushNotifications, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus, updateVendorBasedOnUserLicense };
|
package/dist/service/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as mongoose from 'mongoose';
|
|
2
2
|
import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
|
|
3
|
-
import { PromoCodeType,
|
|
3
|
+
import { PromoCodeType, EnumAffiliateRewardType, EnumUserLicence, DateTimeType, EventListItemType, DateTimeWithPriceType } from '@timardex/cluemart-shared';
|
|
4
4
|
import { n as SchemaAffiliateResourceType, S as SchemaOwnerType, i as SchemaRelationType } from '../Affiliate-gqV1-654.js';
|
|
5
|
-
import {
|
|
5
|
+
import { O as ObjectId, G as GraphQLContext, f as SchemaCreateBulkNotificationInput } from '../Chat-Wn7yfc3v.js';
|
|
6
6
|
import dayjs from 'dayjs';
|
|
7
7
|
import { DateTimeType as DateTimeType$1 } from '@timardex/cluemart-shared/types';
|
|
8
|
+
import { EnumUserLicence as EnumUserLicence$1 } from '@timardex/cluemart-shared/enums';
|
|
8
9
|
import 'express';
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -82,7 +83,7 @@ declare function normalizeAffiliatePromoCodes(promoCodes: PromoCodeType[] | null
|
|
|
82
83
|
* otherwise falls back to the Standard subscription reward.
|
|
83
84
|
* Returns `null` when no non-expired vendor licence applies.
|
|
84
85
|
*/
|
|
85
|
-
declare function mapVendorLicenceToSubscriptionRewardType(
|
|
86
|
+
declare function mapVendorLicenceToSubscriptionRewardType(userId: ObjectId | string, now?: Date): Promise<EnumAffiliateRewardType | null>;
|
|
86
87
|
/** Inclusive start / exclusive end of the UTC calendar month containing `now`. */
|
|
87
88
|
declare function getSubscriptionRewardPeriodBounds(now?: Date): {
|
|
88
89
|
periodEnd: Date;
|
|
@@ -190,4 +191,25 @@ declare function didRemoveAnyEventDates(previousDateTime: EventDateSlot[] | unde
|
|
|
190
191
|
*/
|
|
191
192
|
declare function updateRelationDatesToUnavailable(relationDates: SchemaRelationType["relationDates"], eventDateTime: DateTimeWithPriceType[] | undefined): SchemaRelationType["relationDates"];
|
|
192
193
|
|
|
193
|
-
|
|
194
|
+
type PayingStripeSubscriptionPlanResult = {
|
|
195
|
+
hasSubscription: boolean;
|
|
196
|
+
plan: EnumUserLicence$1 | null;
|
|
197
|
+
validTypes: Set<EnumUserLicence$1>;
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Returns the paying Stripe plan when `currentPlan` is any PRO plan
|
|
201
|
+
* (event or vendor) and the subscription is active/trialing.
|
|
202
|
+
*/
|
|
203
|
+
declare function getPayingStripeSubscriptionPlan(userId: ObjectId | string, now?: Date): Promise<PayingStripeSubscriptionPlanResult>;
|
|
204
|
+
/**
|
|
205
|
+
* Like {@link getPayingStripeSubscriptionPlan} but only treats a vendor PRO
|
|
206
|
+
* plan (`PRO_VENDOR` / `PRO_PLUS_VENDOR`) as paying.
|
|
207
|
+
*/
|
|
208
|
+
declare function getPayingVendorStripeSubscriptionPlan(userId: ObjectId | string, now?: Date): Promise<PayingStripeSubscriptionPlanResult>;
|
|
209
|
+
/**
|
|
210
|
+
* Like {@link getPayingStripeSubscriptionPlan} but only treats an event PRO
|
|
211
|
+
* plan (`PRO_EVENT` / `PRO_PLUS_EVENT`) as paying.
|
|
212
|
+
*/
|
|
213
|
+
declare function getPayingEventStripeSubscriptionPlan(userId: ObjectId | string, now?: Date): Promise<PayingStripeSubscriptionPlanResult>;
|
|
214
|
+
|
|
215
|
+
export { ACTIVE_NOT_DELETED_FILTER, type AwardAffiliateVendorSubscriptionRewardsResult, type NotificationPubSub, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, connectToDatabase, convertObjectIdsToStrings, didRemoveAnyEventDates, findAffiliateByPromoCode, findEventOrImportedMarketById, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, isValidObjectId, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, publishNotificationEvents, saveNotificationsInDb, sendPushNotifications, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus, updateVendorBasedOnUserLicense };
|
package/dist/service/index.mjs
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
EnumResourceType,
|
|
15
15
|
EnumSubscriptionStatus,
|
|
16
16
|
EnumUserLicence,
|
|
17
|
+
EnumUserLicence2,
|
|
17
18
|
EventModel,
|
|
18
19
|
GoogleImportedMarketModel,
|
|
19
20
|
NotificationModel,
|
|
@@ -22,7 +23,7 @@ import {
|
|
|
22
23
|
VendorModel,
|
|
23
24
|
dateFormat,
|
|
24
25
|
timeFormat
|
|
25
|
-
} from "../chunk-
|
|
26
|
+
} from "../chunk-YILYRHDN.mjs";
|
|
26
27
|
import "../chunk-6PNG5BI5.mjs";
|
|
27
28
|
|
|
28
29
|
// src/service/promoCode/constants.ts
|
|
@@ -95,7 +96,7 @@ var SHARE_RESOURCE_LABEL = {
|
|
|
95
96
|
school: "School"
|
|
96
97
|
};
|
|
97
98
|
|
|
98
|
-
// node_modules/@timardex/cluemart-shared/dist/chunk-
|
|
99
|
+
// node_modules/@timardex/cluemart-shared/dist/chunk-5D2JVHC2.mjs
|
|
99
100
|
var PROMO_CODE_PREFIX = "CM-";
|
|
100
101
|
var OBJECT_ID_PATH_SEGMENT = "[a-f0-9]{24}";
|
|
101
102
|
var OBJECT_ID_PATH_SEGMENT_END = `${OBJECT_ID_PATH_SEGMENT}$`;
|
|
@@ -103,17 +104,17 @@ var gameScreenIdentifierList = [
|
|
|
103
104
|
{
|
|
104
105
|
clue: "Where your actions turn into a timeline.",
|
|
105
106
|
id: "activities",
|
|
106
|
-
match: "/profile/
|
|
107
|
+
match: "/profile/account/favourites"
|
|
107
108
|
},
|
|
108
109
|
{
|
|
109
110
|
clue: "Where conversations happen without speaking.",
|
|
110
111
|
id: "chat",
|
|
111
|
-
match: "/
|
|
112
|
+
match: "/chat"
|
|
112
113
|
},
|
|
113
114
|
{
|
|
114
115
|
clue: "The place to redefine who you are.",
|
|
115
116
|
id: "edit-profile",
|
|
116
|
-
match: "/profile/
|
|
117
|
+
match: "/profile/account"
|
|
117
118
|
},
|
|
118
119
|
{
|
|
119
120
|
clue: "A single moment worth showing up for.",
|
|
@@ -197,7 +198,7 @@ var gameScreenIdentifierList = [
|
|
|
197
198
|
}
|
|
198
199
|
];
|
|
199
200
|
|
|
200
|
-
// node_modules/@timardex/cluemart-shared/dist/chunk-
|
|
201
|
+
// node_modules/@timardex/cluemart-shared/dist/chunk-P4JLZCWZ.mjs
|
|
201
202
|
import dayjs2 from "dayjs";
|
|
202
203
|
var statusOptions = [
|
|
203
204
|
...Object.values(EnumInviteStatus2).map((status) => ({
|
|
@@ -1374,19 +1375,56 @@ async function sendPushNotifications({
|
|
|
1374
1375
|
}
|
|
1375
1376
|
}
|
|
1376
1377
|
|
|
1377
|
-
// src/service/
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1378
|
+
// src/service/license.ts
|
|
1379
|
+
var PRO_EVENT_PLANS = /* @__PURE__ */ new Set([
|
|
1380
|
+
EnumUserLicence2.PRO_EVENT,
|
|
1381
|
+
EnumUserLicence2.PRO_PLUS_EVENT
|
|
1382
|
+
]);
|
|
1383
|
+
var PRO_VENDOR_PLANS = /* @__PURE__ */ new Set([
|
|
1384
|
+
EnumUserLicence2.PRO_VENDOR,
|
|
1385
|
+
EnumUserLicence2.PRO_PLUS_VENDOR
|
|
1386
|
+
]);
|
|
1387
|
+
var PRO_PLANS = /* @__PURE__ */ new Set([
|
|
1388
|
+
...PRO_EVENT_PLANS,
|
|
1389
|
+
...PRO_VENDOR_PLANS
|
|
1390
|
+
]);
|
|
1391
|
+
async function getPayingStripePlanFor(userId, now, payingPlans) {
|
|
1392
|
+
const user = await UserModel.findById(userId).select("licences stripe").lean().exec();
|
|
1393
|
+
if (!user) {
|
|
1394
|
+
return { hasSubscription: false, plan: null, validTypes: /* @__PURE__ */ new Set() };
|
|
1395
|
+
}
|
|
1396
|
+
const stripe = user.stripe;
|
|
1397
|
+
const licences = user.licences ?? [];
|
|
1383
1398
|
const validTypes = new Set(
|
|
1384
|
-
|
|
1399
|
+
licences.filter(
|
|
1385
1400
|
(licence) => new Date(licence.expiryDate).getTime() > now.getTime()
|
|
1386
1401
|
).map((licence) => licence.licenceType)
|
|
1387
1402
|
);
|
|
1403
|
+
if (stripe == null || stripe.subscriptionId == null) {
|
|
1404
|
+
return { hasSubscription: false, plan: null, validTypes };
|
|
1405
|
+
}
|
|
1406
|
+
const hasActiveStatus = stripe.status === EnumSubscriptionStatus.ACTIVE || stripe.status === EnumSubscriptionStatus.TRIALING;
|
|
1407
|
+
if (!hasActiveStatus || stripe.currentPlan == null) {
|
|
1408
|
+
return { hasSubscription: false, plan: null, validTypes };
|
|
1409
|
+
}
|
|
1410
|
+
const plan = payingPlans.has(stripe.currentPlan) ? stripe.currentPlan : null;
|
|
1411
|
+
return { hasSubscription: plan != null, plan, validTypes };
|
|
1412
|
+
}
|
|
1413
|
+
async function getPayingStripeSubscriptionPlan(userId, now = /* @__PURE__ */ new Date()) {
|
|
1414
|
+
return getPayingStripePlanFor(userId, now, PRO_PLANS);
|
|
1415
|
+
}
|
|
1416
|
+
async function getPayingVendorStripeSubscriptionPlan(userId, now = /* @__PURE__ */ new Date()) {
|
|
1417
|
+
return getPayingStripePlanFor(userId, now, PRO_VENDOR_PLANS);
|
|
1418
|
+
}
|
|
1419
|
+
async function getPayingEventStripeSubscriptionPlan(userId, now = /* @__PURE__ */ new Date()) {
|
|
1420
|
+
return getPayingStripePlanFor(userId, now, PRO_EVENT_PLANS);
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
// src/service/affiliate/vendorSubscriptionRewards.ts
|
|
1424
|
+
async function mapVendorLicenceToSubscriptionRewardType(userId, now = /* @__PURE__ */ new Date()) {
|
|
1425
|
+
const { hasSubscription, validTypes } = await getPayingVendorStripeSubscriptionPlan(userId, now);
|
|
1388
1426
|
if (validTypes.has(EnumUserLicence.PRO_VENDOR) || validTypes.has(EnumUserLicence.PRO_PLUS_VENDOR)) {
|
|
1389
|
-
if (
|
|
1427
|
+
if (hasSubscription) {
|
|
1390
1428
|
return EnumAffiliateRewardType.ACTIVE_VENDOR_PRO_SUBSCRIPTION;
|
|
1391
1429
|
}
|
|
1392
1430
|
return EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
|
|
@@ -1434,14 +1472,6 @@ async function isEligibleReferredVendor({
|
|
|
1434
1472
|
}).exec();
|
|
1435
1473
|
return Boolean(match);
|
|
1436
1474
|
}
|
|
1437
|
-
async function resolveSubscriptionRewardTypeForVendorOwner(vendorOwnerUserId, now) {
|
|
1438
|
-
const vendorOwner = await UserModel.findById(vendorOwnerUserId).select("licences stripe").lean().exec();
|
|
1439
|
-
return mapVendorLicenceToSubscriptionRewardType(
|
|
1440
|
-
vendorOwner?.licences,
|
|
1441
|
-
now,
|
|
1442
|
-
vendorOwner?.stripe
|
|
1443
|
-
);
|
|
1444
|
-
}
|
|
1445
1475
|
async function notifyAffiliateOwnerOfSubscriptionReward({
|
|
1446
1476
|
affiliateId,
|
|
1447
1477
|
affiliateOwnerUserId,
|
|
@@ -1531,7 +1561,7 @@ async function processAffiliateVendorReferral({
|
|
|
1531
1561
|
if (!vendorEligible) {
|
|
1532
1562
|
return "skipped";
|
|
1533
1563
|
}
|
|
1534
|
-
const rewardType = await
|
|
1564
|
+
const rewardType = await mapVendorLicenceToSubscriptionRewardType(
|
|
1535
1565
|
resource.resourceOwner.userId,
|
|
1536
1566
|
now
|
|
1537
1567
|
);
|
|
@@ -1944,6 +1974,9 @@ export {
|
|
|
1944
1974
|
didRemoveAnyEventDates,
|
|
1945
1975
|
findAffiliateByPromoCode,
|
|
1946
1976
|
findEventOrImportedMarketById,
|
|
1977
|
+
getPayingEventStripeSubscriptionPlan,
|
|
1978
|
+
getPayingStripeSubscriptionPlan,
|
|
1979
|
+
getPayingVendorStripeSubscriptionPlan,
|
|
1947
1980
|
getSubscriptionRewardPeriodBounds,
|
|
1948
1981
|
isValidObjectId,
|
|
1949
1982
|
mapVendorLicenceToSubscriptionRewardType,
|