@positivegrid/pg-mongoose-schema 28.0.0-beta.7 → 28.0.0-beta.9
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 +39 -1
- package/dist/index.d.mts +9 -1
- package/dist/index.mjs +39 -1
- package/package.json +13 -15
package/dist/index.cjs
CHANGED
|
@@ -4339,6 +4339,32 @@ function buildToneThemeFeaturedList(mongoose) {
|
|
|
4339
4339
|
}
|
|
4340
4340
|
//#endregion
|
|
4341
4341
|
//#region src/models/user.ts
|
|
4342
|
+
/**
|
|
4343
|
+
* Map a reward-history `event` string to a UI-facing description.
|
|
4344
|
+
*
|
|
4345
|
+
* Event grammar (from pg-mongoose-helper):
|
|
4346
|
+
* order_reward:${shopifyOrderId}
|
|
4347
|
+
* order_refund:${shopifyOrderId}
|
|
4348
|
+
* register_product_reward:${productSn}
|
|
4349
|
+
* zero_data_reward:${uniqueKey}
|
|
4350
|
+
* admin_adjust:${timestamp}
|
|
4351
|
+
* redeem:${rewardId}:${timestamp}
|
|
4352
|
+
*/
|
|
4353
|
+
function _rewardHistoryDisplayText(event) {
|
|
4354
|
+
if (typeof event !== "string" || event.length === 0) return "";
|
|
4355
|
+
const colonIdx = event.indexOf(":");
|
|
4356
|
+
const prefix = colonIdx === -1 ? event : event.slice(0, colonIdx);
|
|
4357
|
+
const tail = colonIdx === -1 ? "" : event.slice(colonIdx + 1);
|
|
4358
|
+
switch (prefix) {
|
|
4359
|
+
case "order_reward": return tail ? `Reward points from Order #${tail}` : "Reward points from order";
|
|
4360
|
+
case "order_refund": return tail ? `Refund deduction for Order #${tail}` : "Refund deduction";
|
|
4361
|
+
case "register_product_reward": return tail ? `Reward points from product registration (${tail})` : "Reward points from product registration";
|
|
4362
|
+
case "zero_data_reward": return "Reward points from Zero-Party Data submission";
|
|
4363
|
+
case "admin_adjust": return "Admin adjustment";
|
|
4364
|
+
case "redeem": return "Reward redemption";
|
|
4365
|
+
default: return event;
|
|
4366
|
+
}
|
|
4367
|
+
}
|
|
4342
4368
|
const log$2 = (0, node_util.debuglog)("model:user");
|
|
4343
4369
|
/**
|
|
4344
4370
|
* Error thrown by User auth statics. Replaces the previous dependency on
|
|
@@ -4805,11 +4831,19 @@ function buildUser(mongoose) {
|
|
|
4805
4831
|
type: Date,
|
|
4806
4832
|
default: Date.now
|
|
4807
4833
|
}
|
|
4808
|
-
}, {
|
|
4834
|
+
}, {
|
|
4835
|
+
collection: "user_reward_history",
|
|
4836
|
+
toJSON: { virtuals: true },
|
|
4837
|
+
toObject: { virtuals: true }
|
|
4838
|
+
});
|
|
4809
4839
|
UserRewardHistorySchema.index({
|
|
4810
4840
|
user_point_id: 1,
|
|
4811
4841
|
event: 1
|
|
4812
4842
|
}, { unique: true });
|
|
4843
|
+
UserRewardHistorySchema.virtual("display_text").get(function() {
|
|
4844
|
+
return _rewardHistoryDisplayText(this.event ?? "");
|
|
4845
|
+
});
|
|
4846
|
+
UserRewardHistorySchema.plugin(mongoose_lean_virtuals.default);
|
|
4813
4847
|
const RewardPointsRedeemListSchema = new Schema({
|
|
4814
4848
|
name: {
|
|
4815
4849
|
type: String,
|
|
@@ -4821,6 +4855,10 @@ function buildUser(mongoose) {
|
|
|
4821
4855
|
default: []
|
|
4822
4856
|
},
|
|
4823
4857
|
collection_handle: { type: String },
|
|
4858
|
+
apply_to_all: {
|
|
4859
|
+
type: Boolean,
|
|
4860
|
+
default: false
|
|
4861
|
+
},
|
|
4824
4862
|
discount_percent: {
|
|
4825
4863
|
type: Number,
|
|
4826
4864
|
required: true
|
package/dist/index.d.mts
CHANGED
|
@@ -186,11 +186,19 @@ interface IUserRewardHistory {
|
|
|
186
186
|
created_on: Date;
|
|
187
187
|
updated_on: Date;
|
|
188
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Virtual fields surfaced on UserRewardHistory documents. Use
|
|
191
|
+
* `.lean({ virtuals: true })` or `toJSON: { virtuals: true }` to see them.
|
|
192
|
+
*/
|
|
193
|
+
interface IUserRewardHistoryVirtuals {
|
|
194
|
+
display_text: string;
|
|
195
|
+
}
|
|
189
196
|
interface IRewardPointsRedeemList {
|
|
190
197
|
name: string;
|
|
191
198
|
description?: string;
|
|
192
199
|
skus: string[];
|
|
193
200
|
collection_handle?: string;
|
|
201
|
+
apply_to_all: boolean;
|
|
194
202
|
discount_percent: number;
|
|
195
203
|
points_required: number;
|
|
196
204
|
created_on: Date;
|
|
@@ -1332,4 +1340,4 @@ type DemoUserTrackerDoc = HydratedDocument<IDemoUserTracker>;
|
|
|
1332
1340
|
type RegistryType = "account" | "hardware" | undefined;
|
|
1333
1341
|
declare function register(mongoose: Mongoose, type?: RegistryType): void;
|
|
1334
1342
|
//#endregion
|
|
1335
|
-
export { type AccessTokenModel, type ActivationStatusModel, type AdditionalPurchaseModel, AuthError, type AuthorizationCodeDoc, type AuthorizationCodeModel, type B2bDealerModel, type B2bRedeemModel, type B2bRedeemOrderModel, type BankListDoc, type BankListModel, type BankPresetsDoc, type BankPresetsModel, type BanksModels, type BcCartUpdateStatusModel, type CAMPAIGN_TYPE, type CnCouponDoc, type CnCouponMethods, type CnCouponModel, type CnSalesMetaModel, type CountryHardwareSkuModel, type CrashDataModel, type DataSourceType, type DemoUserTrackerDoc, type DemoUserTrackerModel, type DeviceDoc, type DeviceModel, type DeviceModels, type FLAG_EMAIL_EVENTS, type FeaturedListDoc, type FeaturedListModel, type FeaturedListModels, type FeaturedPresetModel, type GenericDataModel, type HardwareActivationConflictModel, type HardwareActivationMetaModel, type HardwareActivationRecordModel, type HardwareModels, type HardwareSeriesNumberModel, type HomeConfigDoc, type HomeConfigModel, type IAccessToken, type IActionButton, type IActivationStatus, type IApikey, type IAuthorizationCode, type IB2bDealer, type IB2bRedeem, type IB2bRedeemOrder, type IBankList, type IBankPresets, type ICampaignUserInfo, type ICnCoupon, type ICountryHardwareSku, type ICouponPromotion, type ICrashData, type IDataSource, type IDemoUserTracker, type IDevice, type IFeaturedList, type IFeaturedListVirtuals, type IFeaturedPreset, type IFreeTrial, type IGearTrialMeta, type IGearTrialRecord, type IGenericData, type IHardwareActivationConflict, type IHardwareActivationMeta, type IHardwareActivationRecord, type IHardwareSeriesNumber, type IHomeConfig, type IIapActivation, type IIapEvent, type IIasBuyOption, type IIasPromotion, type IIasStorePageMeta, type IIntermediateUserOrderReward, type IItemInventoryHistory, type IKeyValue, type ILicense, type ILicenseCampaignMeta, type ILicenseCampaignRecord, type ILicenseVirtuals, type IOauthClient, type IOemRedeemPromotion, type IPartnerCoupon, type IPartnerRedeem, type IPartnerSalesHistory, type IPartnerSalesMeta, type IPgConfig, type IPgLogging, type IPreset, type IPresetVirtuals, type IProduct, type IPromotion, type IPublicAnnouncement, type IPublicAnnouncementFreeTrial, type IPublicAnnouncementUserList, type IPublicAnnouncementUserListLog, type IRedeemCode, type IRefreshToken, type IRewardPointsRedeemList, type ISection, type ISpecialOffer, type ITierSalesMeta, type ITierSalesRules, type IToneTheme, type IToneThemeFeaturedList, type IToneThemeVirtuals, type IUser, type IUserAddress, type IUserAuth, type IUserEmailStatus, type IUserFollow, type IUserMetadata, type IUserMethods, type IUserPoints, type IUserProduct, type IUserProductTracker, type IUserProfile, type IUserRedeemRewardPointsRecord, type IUserReferral, type IUserRewardHistory, type IUserToken, type IUserVirtuals, type IWarehouseInventory, type IYotpoLoyalty, type IYotpoLoyaltyBackup, type IapActivationModel, type IapEventModel, type ItemInventoryHistoryModel, type KeyValueModel, type LICENSE_ADDITION, type LicenseAdditionKey, type LicenseDoc, type LicenseModel, type LicenseUpgradeMetaModel, type OEM_APOGEE_SUPPORT_LICENSE, type OEM_FOCUSRITE_SUPPORT_LICENSE, type OEM_PROMOTION_TYPE, type OEM_PROSONUS_SUPPORT_LICENSE, type OauthClientModel, type OauthModels, type OemRedeemPromotionModel, type PRODUCTS, type PURCHASE_ITEM_TYPE, type ParsedGenericSerialNumber, type ParsedSerialNumber, type ParsedSparkSerialNumber, type PartnerCouponModel, type PartnerModels, type PartnerRedeemModel, type PartnerSalesHistoryModel, type PartnerSalesMetaModel, type PaymentModels, type PgConfigDoc, type PgConfigModel, type PgConfigModels, type PgLoggingModel, type PresetCommentModel, type PresetDoc, type PresetLikeModel, type PresetModel, type PresetModels, type Product, type ProductModel, type PromotionModels, type PublicAnnouncementDoc, type PublicAnnouncementFreeTrialModel, type PublicAnnouncementModel, type PublicAnnouncementUserListModel, type RedeemCodeDoc, type RedeemCodeModel, type RefreshTokenModel, RegistryType, type SaveTrackInput, type SectionType, type SimpleModel, type ToneThemeDoc, type ToneThemeFeaturedListDoc, type ToneThemeFeaturedListModel, type ToneThemeModel, type UserDoc, type UserModel, type UserModels, type UserProductModel, type UserProfileDoc, type UserProfileModel, type UserTokenDoc, type UserTokenModel, type UserTrackModels, type WarehouseInventoryModel, type _buildLicenseTierQuery, type _buildPresetVersionQuery, type _buildSortQuery, type _filterKeyword, type _handlePresetVersion, type _identifyHardwareByModel, type _identifyItemTypeBySku, type _oemMetaToLicenseName, type _parseHardwareSerialNumber, type _parsePageParams, type _queryCompatibilityHandler, register as default, register };
|
|
1343
|
+
export { type AccessTokenModel, type ActivationStatusModel, type AdditionalPurchaseModel, AuthError, type AuthorizationCodeDoc, type AuthorizationCodeModel, type B2bDealerModel, type B2bRedeemModel, type B2bRedeemOrderModel, type BankListDoc, type BankListModel, type BankPresetsDoc, type BankPresetsModel, type BanksModels, type BcCartUpdateStatusModel, type CAMPAIGN_TYPE, type CnCouponDoc, type CnCouponMethods, type CnCouponModel, type CnSalesMetaModel, type CountryHardwareSkuModel, type CrashDataModel, type DataSourceType, type DemoUserTrackerDoc, type DemoUserTrackerModel, type DeviceDoc, type DeviceModel, type DeviceModels, type FLAG_EMAIL_EVENTS, type FeaturedListDoc, type FeaturedListModel, type FeaturedListModels, type FeaturedPresetModel, type GenericDataModel, type HardwareActivationConflictModel, type HardwareActivationMetaModel, type HardwareActivationRecordModel, type HardwareModels, type HardwareSeriesNumberModel, type HomeConfigDoc, type HomeConfigModel, type IAccessToken, type IActionButton, type IActivationStatus, type IApikey, type IAuthorizationCode, type IB2bDealer, type IB2bRedeem, type IB2bRedeemOrder, type IBankList, type IBankPresets, type ICampaignUserInfo, type ICnCoupon, type ICountryHardwareSku, type ICouponPromotion, type ICrashData, type IDataSource, type IDemoUserTracker, type IDevice, type IFeaturedList, type IFeaturedListVirtuals, type IFeaturedPreset, type IFreeTrial, type IGearTrialMeta, type IGearTrialRecord, type IGenericData, type IHardwareActivationConflict, type IHardwareActivationMeta, type IHardwareActivationRecord, type IHardwareSeriesNumber, type IHomeConfig, type IIapActivation, type IIapEvent, type IIasBuyOption, type IIasPromotion, type IIasStorePageMeta, type IIntermediateUserOrderReward, type IItemInventoryHistory, type IKeyValue, type ILicense, type ILicenseCampaignMeta, type ILicenseCampaignRecord, type ILicenseVirtuals, type IOauthClient, type IOemRedeemPromotion, type IPartnerCoupon, type IPartnerRedeem, type IPartnerSalesHistory, type IPartnerSalesMeta, type IPgConfig, type IPgLogging, type IPreset, type IPresetVirtuals, type IProduct, type IPromotion, type IPublicAnnouncement, type IPublicAnnouncementFreeTrial, type IPublicAnnouncementUserList, type IPublicAnnouncementUserListLog, type IRedeemCode, type IRefreshToken, type IRewardPointsRedeemList, type ISection, type ISpecialOffer, type ITierSalesMeta, type ITierSalesRules, type IToneTheme, type IToneThemeFeaturedList, type IToneThemeVirtuals, type IUser, type IUserAddress, type IUserAuth, type IUserEmailStatus, type IUserFollow, type IUserMetadata, type IUserMethods, type IUserPoints, type IUserProduct, type IUserProductTracker, type IUserProfile, type IUserRedeemRewardPointsRecord, type IUserReferral, type IUserRewardHistory, type IUserRewardHistoryVirtuals, type IUserToken, type IUserVirtuals, type IWarehouseInventory, type IYotpoLoyalty, type IYotpoLoyaltyBackup, type IapActivationModel, type IapEventModel, type ItemInventoryHistoryModel, type KeyValueModel, type LICENSE_ADDITION, type LicenseAdditionKey, type LicenseDoc, type LicenseModel, type LicenseUpgradeMetaModel, type OEM_APOGEE_SUPPORT_LICENSE, type OEM_FOCUSRITE_SUPPORT_LICENSE, type OEM_PROMOTION_TYPE, type OEM_PROSONUS_SUPPORT_LICENSE, type OauthClientModel, type OauthModels, type OemRedeemPromotionModel, type PRODUCTS, type PURCHASE_ITEM_TYPE, type ParsedGenericSerialNumber, type ParsedSerialNumber, type ParsedSparkSerialNumber, type PartnerCouponModel, type PartnerModels, type PartnerRedeemModel, type PartnerSalesHistoryModel, type PartnerSalesMetaModel, type PaymentModels, type PgConfigDoc, type PgConfigModel, type PgConfigModels, type PgLoggingModel, type PresetCommentModel, type PresetDoc, type PresetLikeModel, type PresetModel, type PresetModels, type Product, type ProductModel, type PromotionModels, type PublicAnnouncementDoc, type PublicAnnouncementFreeTrialModel, type PublicAnnouncementModel, type PublicAnnouncementUserListModel, type RedeemCodeDoc, type RedeemCodeModel, type RefreshTokenModel, RegistryType, type SaveTrackInput, type SectionType, type SimpleModel, type ToneThemeDoc, type ToneThemeFeaturedListDoc, type ToneThemeFeaturedListModel, type ToneThemeModel, type UserDoc, type UserModel, type UserModels, type UserProductModel, type UserProfileDoc, type UserProfileModel, type UserTokenDoc, type UserTokenModel, type UserTrackModels, type WarehouseInventoryModel, type _buildLicenseTierQuery, type _buildPresetVersionQuery, type _buildSortQuery, type _filterKeyword, type _handlePresetVersion, type _identifyHardwareByModel, type _identifyItemTypeBySku, type _oemMetaToLicenseName, type _parseHardwareSerialNumber, type _parsePageParams, type _queryCompatibilityHandler, register as default, register };
|
package/dist/index.mjs
CHANGED
|
@@ -4311,6 +4311,32 @@ function buildToneThemeFeaturedList(mongoose) {
|
|
|
4311
4311
|
}
|
|
4312
4312
|
//#endregion
|
|
4313
4313
|
//#region src/models/user.ts
|
|
4314
|
+
/**
|
|
4315
|
+
* Map a reward-history `event` string to a UI-facing description.
|
|
4316
|
+
*
|
|
4317
|
+
* Event grammar (from pg-mongoose-helper):
|
|
4318
|
+
* order_reward:${shopifyOrderId}
|
|
4319
|
+
* order_refund:${shopifyOrderId}
|
|
4320
|
+
* register_product_reward:${productSn}
|
|
4321
|
+
* zero_data_reward:${uniqueKey}
|
|
4322
|
+
* admin_adjust:${timestamp}
|
|
4323
|
+
* redeem:${rewardId}:${timestamp}
|
|
4324
|
+
*/
|
|
4325
|
+
function _rewardHistoryDisplayText(event) {
|
|
4326
|
+
if (typeof event !== "string" || event.length === 0) return "";
|
|
4327
|
+
const colonIdx = event.indexOf(":");
|
|
4328
|
+
const prefix = colonIdx === -1 ? event : event.slice(0, colonIdx);
|
|
4329
|
+
const tail = colonIdx === -1 ? "" : event.slice(colonIdx + 1);
|
|
4330
|
+
switch (prefix) {
|
|
4331
|
+
case "order_reward": return tail ? `Reward points from Order #${tail}` : "Reward points from order";
|
|
4332
|
+
case "order_refund": return tail ? `Refund deduction for Order #${tail}` : "Refund deduction";
|
|
4333
|
+
case "register_product_reward": return tail ? `Reward points from product registration (${tail})` : "Reward points from product registration";
|
|
4334
|
+
case "zero_data_reward": return "Reward points from Zero-Party Data submission";
|
|
4335
|
+
case "admin_adjust": return "Admin adjustment";
|
|
4336
|
+
case "redeem": return "Reward redemption";
|
|
4337
|
+
default: return event;
|
|
4338
|
+
}
|
|
4339
|
+
}
|
|
4314
4340
|
const log$2 = debuglog("model:user");
|
|
4315
4341
|
/**
|
|
4316
4342
|
* Error thrown by User auth statics. Replaces the previous dependency on
|
|
@@ -4777,11 +4803,19 @@ function buildUser(mongoose) {
|
|
|
4777
4803
|
type: Date,
|
|
4778
4804
|
default: Date.now
|
|
4779
4805
|
}
|
|
4780
|
-
}, {
|
|
4806
|
+
}, {
|
|
4807
|
+
collection: "user_reward_history",
|
|
4808
|
+
toJSON: { virtuals: true },
|
|
4809
|
+
toObject: { virtuals: true }
|
|
4810
|
+
});
|
|
4781
4811
|
UserRewardHistorySchema.index({
|
|
4782
4812
|
user_point_id: 1,
|
|
4783
4813
|
event: 1
|
|
4784
4814
|
}, { unique: true });
|
|
4815
|
+
UserRewardHistorySchema.virtual("display_text").get(function() {
|
|
4816
|
+
return _rewardHistoryDisplayText(this.event ?? "");
|
|
4817
|
+
});
|
|
4818
|
+
UserRewardHistorySchema.plugin(mongooseLeanVirtuals);
|
|
4785
4819
|
const RewardPointsRedeemListSchema = new Schema({
|
|
4786
4820
|
name: {
|
|
4787
4821
|
type: String,
|
|
@@ -4793,6 +4827,10 @@ function buildUser(mongoose) {
|
|
|
4793
4827
|
default: []
|
|
4794
4828
|
},
|
|
4795
4829
|
collection_handle: { type: String },
|
|
4830
|
+
apply_to_all: {
|
|
4831
|
+
type: Boolean,
|
|
4832
|
+
default: false
|
|
4833
|
+
},
|
|
4796
4834
|
discount_percent: {
|
|
4797
4835
|
type: Number,
|
|
4798
4836
|
required: true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@positivegrid/pg-mongoose-schema",
|
|
3
|
-
"version": "28.0.0-beta.
|
|
3
|
+
"version": "28.0.0-beta.9",
|
|
4
4
|
"description": "Positive Grid mongoose schema",
|
|
5
5
|
"author": "Ferrari Lee <shiyung@positivegrid.com>",
|
|
6
6
|
"homepage": "https://git.positivegrid.com:8443/backend/pg-mongoose-schema",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"url": "https://git.positivegrid.com:8443/backend/pg-mongoose-schema.git"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
|
-
"packageManager": "pnpm@11.1.2",
|
|
13
12
|
"engines": {
|
|
14
13
|
"node": ">=22"
|
|
15
14
|
},
|
|
@@ -36,18 +35,6 @@
|
|
|
36
35
|
"registry": "https://registry.npmjs.org/",
|
|
37
36
|
"access": "restricted"
|
|
38
37
|
},
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "tsdown",
|
|
41
|
-
"typecheck": "tsc --noEmit",
|
|
42
|
-
"lint": "oxlint",
|
|
43
|
-
"format": "oxfmt src test",
|
|
44
|
-
"_format_check_disabled": "oxfmt 0.1.0 is pre-release and mangles TypeScript syntax; re-enable when stable",
|
|
45
|
-
"test": "vitest run",
|
|
46
|
-
"test:watch": "vitest",
|
|
47
|
-
"test:cov": "vitest run --coverage",
|
|
48
|
-
"test:interop": "node --test test/interop/*.test.mjs test/interop/*.test.cjs",
|
|
49
|
-
"prepublishOnly": "pnpm lint && pnpm typecheck && pnpm test && pnpm build && pnpm test:interop"
|
|
50
|
-
},
|
|
51
38
|
"peerDependencies": {
|
|
52
39
|
"mongoose": ">=6"
|
|
53
40
|
},
|
|
@@ -71,5 +58,16 @@
|
|
|
71
58
|
"tsdown": "~0.22.0",
|
|
72
59
|
"typescript": "^5.7.0",
|
|
73
60
|
"vitest": "^2.1.0"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "tsdown",
|
|
64
|
+
"typecheck": "tsc --noEmit",
|
|
65
|
+
"lint": "oxlint",
|
|
66
|
+
"format": "oxfmt src test",
|
|
67
|
+
"_format_check_disabled": "oxfmt 0.1.0 is pre-release and mangles TypeScript syntax; re-enable when stable",
|
|
68
|
+
"test": "vitest run",
|
|
69
|
+
"test:watch": "vitest",
|
|
70
|
+
"test:cov": "vitest run --coverage",
|
|
71
|
+
"test:interop": "node --test test/interop/*.test.mjs test/interop/*.test.cjs"
|
|
74
72
|
}
|
|
75
|
-
}
|
|
73
|
+
}
|