@timardex/cluemart-server-shared 4.0.8 → 4.2.0
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-CpoM9_Bb.d.mts → Affiliate-Bilg9mgw.d.mts} +43 -4
- package/dist/{Affiliate-YoKkDGxN.d.ts → Affiliate-CfG8ctIo.d.ts} +43 -4
- package/dist/{chunk-TSKI3WB2.mjs → chunk-ABW2L2HY.mjs} +81 -2
- package/dist/chunk-ABW2L2HY.mjs.map +1 -0
- package/dist/index.cjs +665 -169
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +294 -10
- package/dist/index.d.ts +294 -10
- package/dist/index.mjs +558 -70
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +80 -1
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.d.mts +57 -9
- package/dist/mongoose/index.d.ts +57 -9
- package/dist/mongoose/index.mjs +3 -1
- package/dist/service/index.cjs +662 -168
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +200 -3
- package/dist/service/index.d.ts +200 -3
- package/dist/service/index.mjs +477 -68
- package/dist/service/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-TSKI3WB2.mjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
|
|
2
|
-
import { AdType, AdDailyPriceType, AdBookingType, AdMetricsType, ChatType, ParticipantType, ChatMessageType, NotificationType, CreateBulkNotificationInput, EnumUserRole, BillingCatalogEntryType, BillingCatalogPriceHistoryEntry, EnumBillingPeriod, EnumUserLicence, BILLING_CATALOG_KEYS, ReportChatUser, OwnerType, Category, ResourceContactDetailsType, ResourceImageType, RelatedPostType, SocialMediaType, PosterUsageType, SocialShareResourceType, TermsAgreement, DateTimeType, LocationGeoType, LocationType, UserLicenceType, GoogleImportedMarket, AiImportedMarket, EnumImportedMarketDeactivationReason, EnumAiImportRunStatus, AiImportUsage, ScrapeSite, PushTokenType, RelationType, RelationDate, ResourceActivityType, StripeSubscription, UserActivityEvent, UserType, VendorType, VendorProductList, VendorInfoType, UnregisteredVendorInvitationType, UnregisteredVendorType, EventType, EventInfoType, StallType, RefundPolicy, PartnerType, PostType, PostContentType, PostResource, AppSettingsType, GameDocType, GameType, SchoolType, AffiliateType, AffiliateResourceType, AffiliateRewardType, CouponType, CouponDataType, CouponParticipantUserType, EnumResourceType, PromoCodeType, EnumAffiliateRewardType, EnumPointType, UserOverallPointsEntry, EventListItemType, DateTimeWithPriceType, EnumNotificationResourceType, EnumNotificationType, LicenceExpiryDate } from '@timardex/cluemart-shared';
|
|
2
|
+
import { AdType, AdDailyPriceType, AdBookingType, AdMetricsType, ChatType, ParticipantType, ChatMessageType, NotificationType, CreateBulkNotificationInput, EnumUserRole, BillingCatalogEntryType, BillingCatalogPriceHistoryEntry, EnumBillingPeriod, EnumUserLicence, BILLING_CATALOG_KEYS, ReportChatUser, OwnerType, AssociateType, EnumAssociateStatus, Category, ResourceContactDetailsType, ResourceImageType, RelatedPostType, SocialMediaType, PosterUsageType, SocialShareResourceType, TermsAgreement, DateTimeType, LocationGeoType, LocationType, UserLicenceType, GoogleImportedMarket, AiImportedMarket, EnumImportedMarketDeactivationReason, EnumAiImportRunStatus, AiImportUsage, ScrapeSite, PushTokenType, RelationType, RelationDate, ResourceActivityType, StripeSubscription, UserActivityEvent, UserType, VendorType, VendorProductList, VendorInfoType, UnregisteredVendorInvitationType, UnregisteredVendorType, EventType, EventInfoType, StallType, RefundPolicy, PartnerType, PostType, PostContentType, PostResource, AppSettingsType, GameDocType, GameType, SchoolType, AffiliateType, AffiliateResourceType, AffiliateRewardType, CouponType, CouponDataType, CouponParticipantUserType, EnumResourceType, PromoCodeType, EnumAffiliateRewardType, EnumPointType, UserOverallPointsEntry, EventListItemType, DateTimeWithPriceType, EnumNotificationResourceType, EnumNotificationType, LicenceExpiryDate } from '@timardex/cluemart-shared';
|
|
3
3
|
export { updateSingleDateTimeStatus } from '@timardex/cluemart-shared';
|
|
4
4
|
import * as mongoose from 'mongoose';
|
|
5
5
|
import mongoose__default from 'mongoose';
|
|
@@ -196,6 +196,10 @@ type SchemaRelatedPostType = Omit<RelatedPostType, "postId"> & {
|
|
|
196
196
|
type SchemaOwnerType = Omit<OwnerType, "userId"> & {
|
|
197
197
|
userId: ObjectId;
|
|
198
198
|
};
|
|
199
|
+
type SchemaAssociateType = Omit<AssociateType, "userId" | "status"> & {
|
|
200
|
+
status: EnumAssociateStatus;
|
|
201
|
+
userId: ObjectId;
|
|
202
|
+
};
|
|
199
203
|
declare const OwnerTypeSchema: mongoose__default.Schema<SchemaOwnerType, mongoose__default.Model<SchemaOwnerType, any, any, any, mongoose__default.Document<unknown, any, SchemaOwnerType, any, {}> & Omit<OwnerType, "userId"> & {
|
|
200
204
|
userId: ObjectId;
|
|
201
205
|
} & {
|
|
@@ -207,6 +211,18 @@ declare const OwnerTypeSchema: mongoose__default.Schema<SchemaOwnerType, mongoos
|
|
|
207
211
|
} & {
|
|
208
212
|
__v: number;
|
|
209
213
|
}>;
|
|
214
|
+
declare const AssociateTypeSchema: mongoose__default.Schema<SchemaAssociateType, mongoose__default.Model<SchemaAssociateType, any, any, any, mongoose__default.Document<unknown, any, SchemaAssociateType, any, {}> & Omit<AssociateType, "status" | "userId"> & {
|
|
215
|
+
status: EnumAssociateStatus;
|
|
216
|
+
userId: ObjectId;
|
|
217
|
+
} & {
|
|
218
|
+
_id: mongoose__default.Types.ObjectId;
|
|
219
|
+
} & {
|
|
220
|
+
__v: number;
|
|
221
|
+
}, any>, {}, {}, {}, {}, mongoose__default.DefaultSchemaOptions, SchemaAssociateType, mongoose__default.Document<unknown, {}, mongoose__default.FlatRecord<SchemaAssociateType>, {}, mongoose__default.DefaultSchemaOptions> & mongoose__default.FlatRecord<SchemaAssociateType> & {
|
|
222
|
+
_id: mongoose__default.Types.ObjectId;
|
|
223
|
+
} & {
|
|
224
|
+
__v: number;
|
|
225
|
+
}>;
|
|
210
226
|
declare const SocialMediaTypeSchema: mongoose__default.Schema<SocialMediaType, mongoose__default.Model<SocialMediaType, any, any, any, mongoose__default.Document<unknown, any, SocialMediaType, any, {}> & SocialMediaType & {
|
|
211
227
|
_id: mongoose__default.Types.ObjectId;
|
|
212
228
|
} & {
|
|
@@ -326,6 +342,22 @@ declare const baseResourceFields: {
|
|
|
326
342
|
required: boolean;
|
|
327
343
|
type: DateConstructor;
|
|
328
344
|
};
|
|
345
|
+
associates: {
|
|
346
|
+
default: never[];
|
|
347
|
+
required: boolean;
|
|
348
|
+
type: mongoose__default.Schema<SchemaAssociateType, mongoose__default.Model<SchemaAssociateType, any, any, any, mongoose__default.Document<unknown, any, SchemaAssociateType, any, {}> & Omit<AssociateType, "status" | "userId"> & {
|
|
349
|
+
status: EnumAssociateStatus;
|
|
350
|
+
userId: ObjectId;
|
|
351
|
+
} & {
|
|
352
|
+
_id: mongoose__default.Types.ObjectId;
|
|
353
|
+
} & {
|
|
354
|
+
__v: number;
|
|
355
|
+
}, any>, {}, {}, {}, {}, mongoose__default.DefaultSchemaOptions, SchemaAssociateType, mongoose__default.Document<unknown, {}, mongoose__default.FlatRecord<SchemaAssociateType>, {}, mongoose__default.DefaultSchemaOptions> & mongoose__default.FlatRecord<SchemaAssociateType> & {
|
|
356
|
+
_id: mongoose__default.Types.ObjectId;
|
|
357
|
+
} & {
|
|
358
|
+
__v: number;
|
|
359
|
+
}>[];
|
|
360
|
+
};
|
|
329
361
|
contactDetails: {
|
|
330
362
|
required: boolean;
|
|
331
363
|
type: mongoose__default.Schema<ResourceContactDetailsType, mongoose__default.Model<ResourceContactDetailsType, any, any, any, mongoose__default.Document<unknown, any, ResourceContactDetailsType, any, {}> & ResourceContactDetailsType & {
|
|
@@ -528,6 +560,27 @@ type SchemaAiImportedMarket = Omit<AiImportedMarket, "eventId" | "claimedByUserI
|
|
|
528
560
|
duplicateHint?: string | null;
|
|
529
561
|
/** Fields still missing before the market can be approved. */
|
|
530
562
|
missingFields?: string[];
|
|
563
|
+
/**
|
|
564
|
+
* Set when an admin edits a queued candidate. The importer stops overwriting
|
|
565
|
+
* such a document's content on re-scrape (it only refreshes bookkeeping), so a
|
|
566
|
+
* reviewer's fix is never replaced by the source data; approval clears it.
|
|
567
|
+
*/
|
|
568
|
+
reviewerEditedAt?: Date | null;
|
|
569
|
+
/**
|
|
570
|
+
* True while the published listing's city is unknown: approval fell back to
|
|
571
|
+
* the region because the document never carried one. The duplicate matcher
|
|
572
|
+
* treats such a listing as matching any city, which the publication key alone
|
|
573
|
+
* cannot express, so approvals of the same name + region are serialised.
|
|
574
|
+
* Rewritten by every approval (with the key), so a value left on an
|
|
575
|
+
* unpublished document is stale but self-correcting.
|
|
576
|
+
*/
|
|
577
|
+
publicationCityUnknown?: boolean | null;
|
|
578
|
+
/**
|
|
579
|
+
* Normalized `region::name::city` key held only while the market is the
|
|
580
|
+
* published listing for that market. A unique partial index on it makes
|
|
581
|
+
* "one published listing per market" a durable constraint (see below).
|
|
582
|
+
*/
|
|
583
|
+
publicationKey?: string | null;
|
|
531
584
|
};
|
|
532
585
|
declare const AiImportedMarketModel: mongoose__default.Model<SchemaAiImportedMarket, {}, {}, {}, mongoose__default.Document<unknown, {}, SchemaAiImportedMarket, {}, {}> & Omit<AiImportedMarket, "eventId" | "claimedByUserId" | "reviewedByUserId"> & {
|
|
533
586
|
eventId?: mongoose__default.Types.ObjectId;
|
|
@@ -549,6 +602,27 @@ declare const AiImportedMarketModel: mongoose__default.Model<SchemaAiImportedMar
|
|
|
549
602
|
duplicateHint?: string | null;
|
|
550
603
|
/** Fields still missing before the market can be approved. */
|
|
551
604
|
missingFields?: string[];
|
|
605
|
+
/**
|
|
606
|
+
* Set when an admin edits a queued candidate. The importer stops overwriting
|
|
607
|
+
* such a document's content on re-scrape (it only refreshes bookkeeping), so a
|
|
608
|
+
* reviewer's fix is never replaced by the source data; approval clears it.
|
|
609
|
+
*/
|
|
610
|
+
reviewerEditedAt?: Date | null;
|
|
611
|
+
/**
|
|
612
|
+
* True while the published listing's city is unknown: approval fell back to
|
|
613
|
+
* the region because the document never carried one. The duplicate matcher
|
|
614
|
+
* treats such a listing as matching any city, which the publication key alone
|
|
615
|
+
* cannot express, so approvals of the same name + region are serialised.
|
|
616
|
+
* Rewritten by every approval (with the key), so a value left on an
|
|
617
|
+
* unpublished document is stale but self-correcting.
|
|
618
|
+
*/
|
|
619
|
+
publicationCityUnknown?: boolean | null;
|
|
620
|
+
/**
|
|
621
|
+
* Normalized `region::name::city` key held only while the market is the
|
|
622
|
+
* published listing for that market. A unique partial index on it makes
|
|
623
|
+
* "one published listing per market" a durable constraint (see below).
|
|
624
|
+
*/
|
|
625
|
+
publicationKey?: string | null;
|
|
552
626
|
} & Required<{
|
|
553
627
|
_id: string;
|
|
554
628
|
}> & {
|
|
@@ -697,9 +771,15 @@ declare const ResourceActivityModel: mongoose__default.Model<ResourceActivityTyp
|
|
|
697
771
|
type SchemaUserActivityEvent = Omit<UserActivityEvent, "resourceId"> & {
|
|
698
772
|
resourceId: ObjectId;
|
|
699
773
|
};
|
|
700
|
-
type
|
|
774
|
+
type SchemaUserAssociatedResourcesType = {
|
|
775
|
+
events: ObjectId[];
|
|
776
|
+
partners: ObjectId[];
|
|
777
|
+
vendors: ObjectId[];
|
|
778
|
+
};
|
|
779
|
+
type SchemaUserType = Omit<UserType, "vendor" | "coupon" | "events" | "partner" | "userActivity" | "_id" | "game" | "school" | "affiliate" | "associatedResources" | "permissions" | "stripe" | "totalOverallPoints"> & {
|
|
701
780
|
_id: ObjectId;
|
|
702
781
|
affiliate: ObjectId;
|
|
782
|
+
associatedResources?: SchemaUserAssociatedResourcesType | null;
|
|
703
783
|
coupon: ObjectId;
|
|
704
784
|
events: ObjectId[];
|
|
705
785
|
game: ObjectId;
|
|
@@ -741,9 +821,10 @@ type SchemaStripeSubscription = StripeSubscription & {
|
|
|
741
821
|
subscriptionMutationLockExpiresAt?: Date;
|
|
742
822
|
subscriptionMutationLockId?: string;
|
|
743
823
|
};
|
|
744
|
-
declare const UserModel: mongoose__default.Model<SchemaUserType, {}, {}, {}, mongoose__default.Document<unknown, {}, SchemaUserType, {}, {}> & Omit<UserType, "_id" | "vendor" | "coupon" | "events" | "partner" | "userActivity" | "game" | "school" | "affiliate" | "permissions" | "stripe" | "totalOverallPoints"> & {
|
|
824
|
+
declare const UserModel: mongoose__default.Model<SchemaUserType, {}, {}, {}, mongoose__default.Document<unknown, {}, SchemaUserType, {}, {}> & Omit<UserType, "_id" | "vendor" | "coupon" | "events" | "partner" | "userActivity" | "game" | "school" | "affiliate" | "associatedResources" | "permissions" | "stripe" | "totalOverallPoints"> & {
|
|
745
825
|
_id: ObjectId;
|
|
746
826
|
affiliate: ObjectId;
|
|
827
|
+
associatedResources?: SchemaUserAssociatedResourcesType | null;
|
|
747
828
|
coupon: ObjectId;
|
|
748
829
|
events: ObjectId[];
|
|
749
830
|
game: ObjectId;
|
|
@@ -796,8 +877,9 @@ declare const vendorProductTypeSchema: mongoose__default.Schema<VendorProductLis
|
|
|
796
877
|
}> & {
|
|
797
878
|
__v: number;
|
|
798
879
|
}>;
|
|
799
|
-
type SchemaVendorType = Omit<VendorType, "vendorInfoId" | "owner" | "adIds" | "unregisteredVendorId"> & {
|
|
880
|
+
type SchemaVendorType = Omit<VendorType, "vendorInfoId" | "owner" | "ownerLicenceType" | "adIds" | "associates" | "unregisteredVendorId"> & {
|
|
800
881
|
adIds?: ObjectId[];
|
|
882
|
+
associates?: SchemaAssociateType[] | null;
|
|
801
883
|
/** Mirror of `categories[].name` for $text search (see vendorSearch). */
|
|
802
884
|
categoriesNames?: string[];
|
|
803
885
|
owner: SchemaOwnerType;
|
|
@@ -806,8 +888,9 @@ type SchemaVendorType = Omit<VendorType, "vendorInfoId" | "owner" | "adIds" | "u
|
|
|
806
888
|
vendorInfoId: ObjectId;
|
|
807
889
|
unregisteredVendorId?: ObjectId | null;
|
|
808
890
|
};
|
|
809
|
-
declare const VendorModel: mongoose__default.Model<SchemaVendorType, {}, {}, {}, mongoose__default.Document<unknown, {}, SchemaVendorType, {}, {}> & Omit<VendorType, "adIds" | "owner" | "vendorInfoId" | "unregisteredVendorId"> & {
|
|
891
|
+
declare const VendorModel: mongoose__default.Model<SchemaVendorType, {}, {}, {}, mongoose__default.Document<unknown, {}, SchemaVendorType, {}, {}> & Omit<VendorType, "adIds" | "associates" | "owner" | "ownerLicenceType" | "vendorInfoId" | "unregisteredVendorId"> & {
|
|
810
892
|
adIds?: ObjectId[];
|
|
893
|
+
associates?: SchemaAssociateType[] | null;
|
|
811
894
|
/** Mirror of `categories[].name` for $text search (see vendorSearch). */
|
|
812
895
|
categoriesNames?: string[];
|
|
813
896
|
owner: SchemaOwnerType;
|
|
@@ -854,15 +937,17 @@ declare const UnregisteredVendorModel: mongoose__default.Model<SchemaUnregistere
|
|
|
854
937
|
__v: number;
|
|
855
938
|
}, any>;
|
|
856
939
|
|
|
857
|
-
type SchemaEventType = Omit<EventType, "eventInfoId" | "owner" | "adIds"> & {
|
|
940
|
+
type SchemaEventType = Omit<EventType, "eventInfoId" | "owner" | "ownerLicenceType" | "adIds" | "associates"> & {
|
|
858
941
|
adIds?: ObjectId[];
|
|
942
|
+
associates?: SchemaAssociateType[] | null;
|
|
859
943
|
eventInfoId: ObjectId;
|
|
860
944
|
owner: SchemaOwnerType;
|
|
861
945
|
/** Lowercase `name` mirror for prefix type-ahead (see searchNamePlugin). */
|
|
862
946
|
searchName?: string;
|
|
863
947
|
};
|
|
864
|
-
declare const EventModel: mongoose__default.Model<SchemaEventType, {}, {}, {}, mongoose__default.Document<unknown, {}, SchemaEventType, {}, {}> & Omit<EventType, "adIds" | "eventInfoId" | "owner"> & {
|
|
948
|
+
declare const EventModel: mongoose__default.Model<SchemaEventType, {}, {}, {}, mongoose__default.Document<unknown, {}, SchemaEventType, {}, {}> & Omit<EventType, "adIds" | "associates" | "eventInfoId" | "owner" | "ownerLicenceType"> & {
|
|
865
949
|
adIds?: ObjectId[];
|
|
950
|
+
associates?: SchemaAssociateType[] | null;
|
|
866
951
|
eventInfoId: ObjectId;
|
|
867
952
|
owner: SchemaOwnerType;
|
|
868
953
|
/** Lowercase `name` mirror for prefix type-ahead (see searchNamePlugin). */
|
|
@@ -912,14 +997,16 @@ declare const EventDateArchiveModel: mongoose__default.Model<SchemaEventDateArch
|
|
|
912
997
|
__v: number;
|
|
913
998
|
}, any>;
|
|
914
999
|
|
|
915
|
-
type SchemaPartnerType = Omit<PartnerType, "owner" | "adIds"> & {
|
|
1000
|
+
type SchemaPartnerType = Omit<PartnerType, "owner" | "ownerLicenceType" | "adIds" | "associates"> & {
|
|
916
1001
|
adIds?: ObjectId[];
|
|
1002
|
+
associates?: SchemaAssociateType[] | null;
|
|
917
1003
|
owner: SchemaOwnerType;
|
|
918
1004
|
/** Lowercase `name` mirror for prefix type-ahead (see searchNamePlugin). */
|
|
919
1005
|
searchName?: string;
|
|
920
1006
|
};
|
|
921
|
-
declare const PartnerModel: mongoose__default.Model<SchemaPartnerType, {}, {}, {}, mongoose__default.Document<unknown, {}, SchemaPartnerType, {}, {}> & Omit<PartnerType, "adIds" | "owner"> & {
|
|
1007
|
+
declare const PartnerModel: mongoose__default.Model<SchemaPartnerType, {}, {}, {}, mongoose__default.Document<unknown, {}, SchemaPartnerType, {}, {}> & Omit<PartnerType, "adIds" | "associates" | "owner" | "ownerLicenceType"> & {
|
|
922
1008
|
adIds?: ObjectId[];
|
|
1009
|
+
associates?: SchemaAssociateType[] | null;
|
|
923
1010
|
owner: SchemaOwnerType;
|
|
924
1011
|
/** Lowercase `name` mirror for prefix type-ahead (see searchNamePlugin). */
|
|
925
1012
|
searchName?: string;
|
|
@@ -1185,6 +1272,152 @@ declare function getSubscriptionRewardPeriodBounds(now?: Date): {
|
|
|
1185
1272
|
periodStart: Date;
|
|
1186
1273
|
};
|
|
1187
1274
|
|
|
1275
|
+
/**
|
|
1276
|
+
* Access-grant bookkeeping shared by `cluemart-server` (the mutations) and
|
|
1277
|
+
* `cluemart-server-cron` (the reconciliation job).
|
|
1278
|
+
*
|
|
1279
|
+
* `User.associatedResources` and the `ASSOCIATED_*` role are a cache derived
|
|
1280
|
+
* from the resource's `associates` array, which is the source of truth. The
|
|
1281
|
+
* helpers here apply that rule in one direction only: anything the resource no
|
|
1282
|
+
* longer lists as ACCEPTED is detached from the user. Because they read the
|
|
1283
|
+
* stored state instead of a caller's before/after snapshot, they can be retried
|
|
1284
|
+
* and they double as the periodic repair.
|
|
1285
|
+
*/
|
|
1286
|
+
type AssociableResourceType = EnumResourceType.EVENT | EnumResourceType.PARTNER | EnumResourceType.VENDOR;
|
|
1287
|
+
declare function isAssociableResourceType(resourceType: EnumResourceType): resourceType is AssociableResourceType;
|
|
1288
|
+
/**
|
|
1289
|
+
* The grant-relevant fields of an associable resource: where the user caches the
|
|
1290
|
+
* grant, and the role that cache implies.
|
|
1291
|
+
*
|
|
1292
|
+
* Deliberately free of models and notification enums so this package stays the
|
|
1293
|
+
* single source of truth for the mapping without owning either. `cluemart-server`
|
|
1294
|
+
* builds its richer `getResourceMeta` on top of it.
|
|
1295
|
+
*/
|
|
1296
|
+
declare function getAssociateAccessMeta(resourceType: AssociableResourceType): {
|
|
1297
|
+
associatedField: "events";
|
|
1298
|
+
associatedPath: string;
|
|
1299
|
+
associateRole: EnumUserRole;
|
|
1300
|
+
} | {
|
|
1301
|
+
associatedField: "partners";
|
|
1302
|
+
associatedPath: string;
|
|
1303
|
+
associateRole: EnumUserRole;
|
|
1304
|
+
} | {
|
|
1305
|
+
associatedField: "vendors";
|
|
1306
|
+
associatedPath: string;
|
|
1307
|
+
associateRole: EnumUserRole;
|
|
1308
|
+
};
|
|
1309
|
+
/** The users a resource currently grants associate access to. */
|
|
1310
|
+
declare function acceptedAssociateUserIds(associates?: SchemaAssociateType[] | null): ObjectId[];
|
|
1311
|
+
/**
|
|
1312
|
+
* Removes a resource from the given users' `associatedResources` and revokes
|
|
1313
|
+
* their `ASSOCIATED_EVENT` / `ASSOCIATED_VENDOR` role if they have no remaining
|
|
1314
|
+
* associated resources of that type.
|
|
1315
|
+
*
|
|
1316
|
+
* Both changes are applied in **one** document update (an aggregation pipeline,
|
|
1317
|
+
* the same technique `syncUserLicencesAfterExpiry` uses). Detaching and revoking
|
|
1318
|
+
* in separate updates leaves a window in which a concurrent accept adds another
|
|
1319
|
+
* resource of the same type: the revocation then re-checks the emptied path and
|
|
1320
|
+
* strips the role the user has just earned. With a single update the membership
|
|
1321
|
+
* change and the `$size` check are atomic per user — a concurrent addition either
|
|
1322
|
+
* lands before this write (the `$size` check sees it and the role stays) or after
|
|
1323
|
+
* it (`$addToSet` re-adds the role).
|
|
1324
|
+
*/
|
|
1325
|
+
declare function detachUsersFromResource({ resourceId, resourceType, userIds, }: {
|
|
1326
|
+
resourceId: ObjectId | string;
|
|
1327
|
+
resourceType: AssociableResourceType;
|
|
1328
|
+
userIds: ObjectId[];
|
|
1329
|
+
}): Promise<void>;
|
|
1330
|
+
/**
|
|
1331
|
+
* The single "grant" write: the resource id on `associatedResources` plus the
|
|
1332
|
+
* associate role, for one or many users.
|
|
1333
|
+
*
|
|
1334
|
+
* Accept, the accept repair and the detach compensation
|
|
1335
|
+
* (`detachUnlessStillAccepted`) all go through this one definition, so the three
|
|
1336
|
+
* cannot drift apart. `$addToSet` makes every caller idempotent — which is what
|
|
1337
|
+
* lets a retried accept and a restored grant both be safe.
|
|
1338
|
+
*
|
|
1339
|
+
* The role is **derived** from the accepted association: this write restores the
|
|
1340
|
+
* invariant "holds an accepted association ⇒ holds the role". A role removed
|
|
1341
|
+
* out-of-band while the resource still accepts the user is therefore re-added;
|
|
1342
|
+
* that state is unreachable through the API, which always removes the
|
|
1343
|
+
* association and the role together.
|
|
1344
|
+
*
|
|
1345
|
+
* **Revalidated against the resource first.** The grant is a write on a
|
|
1346
|
+
* different document than the acceptance, so a revoke that landed after the
|
|
1347
|
+
* caller's read has already finished its own detach — its candidate query could
|
|
1348
|
+
* not see a grant that did not exist yet — and an unconditioned `$addToSet`
|
|
1349
|
+
* would hand that access back for a resource that no longer accepts the user (or
|
|
1350
|
+
* no longer exists). Only users the resource accepts *right now* are granted, so
|
|
1351
|
+
* the cache can never be extended past a revocation the caller could not see.
|
|
1352
|
+
* The read/write gap that remains is closed by the caller's post-grant
|
|
1353
|
+
* verification (`withdrawGrantUnlessStillAccepted` in `cluemart-server`) and, for
|
|
1354
|
+
* a request that dies inside it, by the reconciliation sweep.
|
|
1355
|
+
*/
|
|
1356
|
+
declare function grantAssociateGrants({ resourceId, resourceType, userIds, }: {
|
|
1357
|
+
resourceId: ObjectId | string;
|
|
1358
|
+
resourceType: AssociableResourceType;
|
|
1359
|
+
userIds: Array<ObjectId | string>;
|
|
1360
|
+
}): Promise<void>;
|
|
1361
|
+
/**
|
|
1362
|
+
* Detaches every user whose `associatedResources` still points at `resourceId`
|
|
1363
|
+
* but who the resource no longer lists as `ACCEPTED` — and returns the ids it
|
|
1364
|
+
* detached.
|
|
1365
|
+
*
|
|
1366
|
+
* This is the **state-derived** half of a removal, deliberately not a diff of
|
|
1367
|
+
* the caller's `prevAssociates` / `nextAssociates` snapshot. The resource is
|
|
1368
|
+
* persisted before these side effects run, so a diff computed on retry reads
|
|
1369
|
+
* the new list and reports no removal: a detach that failed once would never be
|
|
1370
|
+
* retried, leaving the stale grant on the user forever. Reading the user side
|
|
1371
|
+
* instead makes the call idempotent and convergent — the same call repairs a
|
|
1372
|
+
* removal whose side effect was lost, whether it comes from a retry, the next
|
|
1373
|
+
* edit of the resource, or the cron reconciliation job.
|
|
1374
|
+
*/
|
|
1375
|
+
declare function detachStaleAssociateGrants({ acceptedUserIds, resourceId, resourceType, }: {
|
|
1376
|
+
/** Users the resource currently lists as `ACCEPTED`. */
|
|
1377
|
+
acceptedUserIds: ObjectId[] | string[];
|
|
1378
|
+
resourceId: ObjectId | string;
|
|
1379
|
+
resourceType: AssociableResourceType;
|
|
1380
|
+
}): Promise<ObjectId[]>;
|
|
1381
|
+
type DetachedAssociateGrants = {
|
|
1382
|
+
detachedUserIds: ObjectId[];
|
|
1383
|
+
resourceId: ObjectId | string;
|
|
1384
|
+
resourceType: AssociableResourceType;
|
|
1385
|
+
};
|
|
1386
|
+
/**
|
|
1387
|
+
* Detaches every grant held for a set of resources that are being destroyed, in
|
|
1388
|
+
* one query per resource type instead of one per resource.
|
|
1389
|
+
*
|
|
1390
|
+
* Used by account deletion, where a user can own hundreds of events: asking
|
|
1391
|
+
* `detachStaleAssociateGrants` per resource would issue one `User` read per
|
|
1392
|
+
* resource. The candidate read is the only part that can be shared — the detach
|
|
1393
|
+
* itself is per resource because the atomic pipeline removes a single id, and
|
|
1394
|
+
* the role that follows is per user.
|
|
1395
|
+
*
|
|
1396
|
+
* There is intentionally **no** verification/restore here: every resource in
|
|
1397
|
+
* `resources` is being hard-deleted, so "still accepted" is never true, and a
|
|
1398
|
+
* restore would hand back a grant for a document that no longer exists. Callers
|
|
1399
|
+
* must run the deletes before this call (see `deleteUser`), which also keeps the
|
|
1400
|
+
* concurrent-accept verification honest.
|
|
1401
|
+
*
|
|
1402
|
+
* The result is aligned with `resources`, so a caller can report the removals
|
|
1403
|
+
* per resource.
|
|
1404
|
+
*/
|
|
1405
|
+
declare function detachAssociateGrantsForResources({ resources, }: {
|
|
1406
|
+
resources: Array<{
|
|
1407
|
+
resourceId: ObjectId | string;
|
|
1408
|
+
resourceType: AssociableResourceType;
|
|
1409
|
+
}>;
|
|
1410
|
+
}): Promise<DetachedAssociateGrants[]>;
|
|
1411
|
+
type ReconcileAssociateGrantsResult = {
|
|
1412
|
+
/** Grants removed because the resource no longer lists them as accepted. */
|
|
1413
|
+
detachedGrants: number;
|
|
1414
|
+
/** User documents visited (each may hold resources of all three types). */
|
|
1415
|
+
scannedUsers: number;
|
|
1416
|
+
};
|
|
1417
|
+
declare function reconcileAssociateGrants({ batchSize, }?: {
|
|
1418
|
+
batchSize?: number;
|
|
1419
|
+
}): Promise<ReconcileAssociateGrantsResult>;
|
|
1420
|
+
|
|
1188
1421
|
/**
|
|
1189
1422
|
* Connect to MongoDB using Mongoose.
|
|
1190
1423
|
* Supports both local MongoDB (via MONGODB_URI) and MongoDB Atlas (via individual env vars).
|
|
@@ -1688,6 +1921,8 @@ declare const licenceCategoryMapping: Record<EnumUserLicence, LicenceCategory>;
|
|
|
1688
1921
|
declare const licencePriority: Record<EnumUserLicence, number>;
|
|
1689
1922
|
declare const standardLicences: readonly [EnumUserLicence.STANDARD_VENDOR, EnumUserLicence.STANDARD_EVENT, EnumUserLicence.STANDARD_PARTNER];
|
|
1690
1923
|
declare function isStandardLicence(licence: EnumUserLicence): licence is (typeof standardLicences)[number];
|
|
1924
|
+
declare const proLicences: readonly [EnumUserLicence.PRO_EVENT, EnumUserLicence.PRO_PLUS_EVENT, EnumUserLicence.PRO_VENDOR, EnumUserLicence.PRO_PLUS_VENDOR];
|
|
1925
|
+
declare function isProLicence(licence: EnumUserLicence): licence is (typeof proLicences)[number];
|
|
1691
1926
|
type LicenceUpgradeArgs = {
|
|
1692
1927
|
expiryDate: LicenceExpiryDate;
|
|
1693
1928
|
licenceType: EnumUserLicence;
|
|
@@ -1719,5 +1954,54 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
|
|
|
1719
1954
|
userId: ObjectId;
|
|
1720
1955
|
resourceType: EnumResourceType;
|
|
1721
1956
|
}): Promise<void>;
|
|
1957
|
+
/**
|
|
1958
|
+
* True while the owner's Stripe subscription still pays for `licenceType`: an
|
|
1959
|
+
* active subscription that has not ended, or the matched post-deletion payment
|
|
1960
|
+
* grace period. Licence *compliance* keeps a lapsed licence alive on this basis;
|
|
1961
|
+
* access checks never do (see {@link ActiveLicenceOptions}).
|
|
1962
|
+
*/
|
|
1963
|
+
declare function isProtectedByCurrentStripeSubscription(user: SchemaUserType, licenceType: EnumUserLicence, now: Dayjs): boolean;
|
|
1964
|
+
type ActiveLicenceOptions = {
|
|
1965
|
+
/**
|
|
1966
|
+
* Also count a lapsed licence that the owner's Stripe subscription still pays
|
|
1967
|
+
* for. Licence compliance keeps such a licence alive until Stripe ends it;
|
|
1968
|
+
* access checks must not, or a downgraded owner would keep their associates.
|
|
1969
|
+
*/
|
|
1970
|
+
includeStripeProtected?: boolean;
|
|
1971
|
+
now?: Date;
|
|
1972
|
+
};
|
|
1973
|
+
/**
|
|
1974
|
+
* Returns the owner's highest non-expired licence for an Event, Partner, or
|
|
1975
|
+
* Vendor, or `null` if the user has no active licence for that category.
|
|
1976
|
+
*/
|
|
1977
|
+
declare function getActiveLicenceForResource({ includeStripeProtected, userId, resourceType, now, }: {
|
|
1978
|
+
includeStripeProtected?: boolean;
|
|
1979
|
+
userId: ObjectId;
|
|
1980
|
+
resourceType: EnumResourceType;
|
|
1981
|
+
now?: Date;
|
|
1982
|
+
}): Promise<EnumUserLicence | null>;
|
|
1983
|
+
/**
|
|
1984
|
+
* Batch sibling of {@link hasActiveProLicenceForResource}: resolves, in a single
|
|
1985
|
+
* user query, which of the given owners still hold an active PRO / PRO_PLUS
|
|
1986
|
+
* licence for `resourceType`.
|
|
1987
|
+
*
|
|
1988
|
+
* List queries that include resources a user only *associates* on use this so a
|
|
1989
|
+
* downgraded owner revokes associate access everywhere at once — exactly as the
|
|
1990
|
+
* per-resource authorization check does — without an owner lookup per row.
|
|
1991
|
+
* Returns the matching owner ids in their string form.
|
|
1992
|
+
*/
|
|
1993
|
+
declare function getUserIdsWithActiveProLicence({ includeStripeProtected, resourceType, userIds, now, }: ActiveLicenceOptions & {
|
|
1994
|
+
resourceType: EnumResourceType;
|
|
1995
|
+
userIds: ObjectId[];
|
|
1996
|
+
}): Promise<Set<string>>;
|
|
1997
|
+
/**
|
|
1998
|
+
* True when the resource owner holds an active, non-expired PRO or PRO_PLUS
|
|
1999
|
+
* licence for the given resource type. Naturally false for Partner because
|
|
2000
|
+
* Partner only has STANDARD_PARTNER.
|
|
2001
|
+
*/
|
|
2002
|
+
declare function hasActiveProLicenceForResource({ includeStripeProtected, userId, resourceType, now, }: ActiveLicenceOptions & {
|
|
2003
|
+
userId: ObjectId;
|
|
2004
|
+
resourceType: EnumResourceType;
|
|
2005
|
+
}): Promise<boolean>;
|
|
1722
2006
|
|
|
1723
|
-
export { ACTIVE_NOT_DELETED_FILTER, AD_BILLING_CATALOG_COLLECTION_NAME, AI_IMPORT_RUN_LOCK_KEY, APP_SETTINGS_ID, AdBillingCatalogModel, AdBookingModel, AdMetricsModel, AdModel, AdPurchaseModel, AffiliateModel, AiImportRunLockModel, AiImportRunModel, type AiImportRunStatus, type AiImportSiteResult, AiImportedMarketModel, AppSettingModel, AuthHandoffTokenModel, type AuthHandoffTokenType, type AuthTokenClient, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, EnumPubSubEvents, EventDateArchiveModel, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, ImpersonationAuditModel, ImpersonationSessionModel, type IndexBuildFailure, type IndexableModel, LicenceCategory, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SCRAPE_SITES_CONFIG_ID, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaAiImportRun, type SchemaAiImportedMarket, type SchemaAppSettingsType, type SchemaBillingCatalogEntry, type SchemaBillingCatalogPriceHistoryEntry, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventDateArchiveType, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaImpersonationAuditType, type SchemaImpersonationSessionType, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaStripeSubscription, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, ScrapeSiteConfigModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, buildUserHasEnoughPointsFilter, buildUserPointAwardEntry, buildUserPointCreditFilter, buildUserPointDebitPipeline, buildUserPointEntryRemovalPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, dedupeArchivedSlotsByStartDateTime, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureDatabaseIndexes, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, schemaAdresource, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, splitEventDatesForArchive, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToCanceled, upgradeUserToLicence, userLicenseSchema, vendorOwnerHasProLicence, vendorProductTypeSchema };
|
|
2007
|
+
export { ACTIVE_NOT_DELETED_FILTER, AD_BILLING_CATALOG_COLLECTION_NAME, AI_IMPORT_RUN_LOCK_KEY, APP_SETTINGS_ID, type ActiveLicenceOptions, AdBillingCatalogModel, AdBookingModel, AdMetricsModel, AdModel, AdPurchaseModel, AffiliateModel, AiImportRunLockModel, AiImportRunModel, type AiImportRunStatus, type AiImportSiteResult, AiImportedMarketModel, AppSettingModel, type AssociableResourceType, AssociateTypeSchema, AuthHandoffTokenModel, type AuthHandoffTokenType, type AuthTokenClient, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, type DetachedAssociateGrants, EnumPubSubEvents, EventDateArchiveModel, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, ImpersonationAuditModel, ImpersonationSessionModel, type IndexBuildFailure, type IndexableModel, LicenceCategory, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, type ReconcileAssociateGrantsResult, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SCRAPE_SITES_CONFIG_ID, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaAiImportRun, type SchemaAiImportedMarket, type SchemaAppSettingsType, type SchemaAssociateType, type SchemaBillingCatalogEntry, type SchemaBillingCatalogPriceHistoryEntry, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventDateArchiveType, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaImpersonationAuditType, type SchemaImpersonationSessionType, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaStripeSubscription, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserAssociatedResourcesType, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, ScrapeSiteConfigModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, acceptedAssociateUserIds, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, buildUserHasEnoughPointsFilter, buildUserPointAwardEntry, buildUserPointCreditFilter, buildUserPointDebitPipeline, buildUserPointEntryRemovalPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, dedupeArchivedSlotsByStartDateTime, detachAssociateGrantsForResources, detachStaleAssociateGrants, detachUsersFromResource, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureDatabaseIndexes, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getActiveLicenceForResource, getAssociateAccessMeta, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getUserIdsWithActiveProLicence, getVendorResourceInfo, grantAssociateGrants, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasActiveProLicenceForResource, hasValidLicence, isAssociableResourceType, isProLicence, isProtectedByCurrentStripeSubscription, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, reconcileAssociateGrants, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, schemaAdresource, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, splitEventDatesForArchive, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToCanceled, upgradeUserToLicence, userLicenseSchema, vendorOwnerHasProLicence, vendorProductTypeSchema };
|