@wtree/payload-ecommerce-coupon 3.77.3 → 3.77.5
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/client/hooks.d.ts +1 -1
- package/dist/client/hooks.d.ts.map +1 -1
- package/dist/client/index.d.ts +6 -6
- package/dist/client/index.d.ts.map +1 -1
- package/dist/collections/createCouponsCollection.d.ts +2 -2
- package/dist/collections/createCouponsCollection.d.ts.map +1 -1
- package/dist/collections/createReferralCodesCollection.d.ts +2 -2
- package/dist/collections/createReferralCodesCollection.d.ts.map +1 -1
- package/dist/collections/createReferralProgramsCollection.d.ts +2 -2
- package/dist/collections/createReferralProgramsCollection.d.ts.map +1 -1
- package/dist/components/PartnerDashboard/EarningsSummary.d.ts +2 -2
- package/dist/components/PartnerDashboard/EarningsSummary.d.ts.map +1 -1
- package/dist/components/PartnerDashboard/RecentReferrals.d.ts +3 -3
- package/dist/components/PartnerDashboard/RecentReferrals.d.ts.map +1 -1
- package/dist/components/PartnerDashboard/ReferralCodes.d.ts +3 -3
- package/dist/components/PartnerDashboard/ReferralCodes.d.ts.map +1 -1
- package/dist/components/PartnerDashboard/ReferralPerformance.d.ts +2 -2
- package/dist/components/PartnerDashboard/ReferralPerformance.d.ts.map +1 -1
- package/dist/components/PartnerDashboard/index.d.ts +2 -2
- package/dist/components/PartnerDashboard/index.d.ts.map +1 -1
- package/dist/endpoints/applyCoupon.d.ts +2 -2
- package/dist/endpoints/applyCoupon.d.ts.map +1 -1
- package/dist/endpoints/partnerStats.d.ts +2 -2
- package/dist/endpoints/partnerStats.d.ts.map +1 -1
- package/dist/endpoints/validateCoupon.d.ts +2 -2
- package/dist/endpoints/validateCoupon.d.ts.map +1 -1
- package/dist/hooks/recalculateCart.d.ts +2 -2
- package/dist/hooks/recalculateCart.d.ts.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -19
- package/dist/index.mjs.map +1 -1
- package/dist/plugin.d.ts +2 -2
- package/dist/plugin.d.ts.map +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/utilities/calculateValues.d.ts +2 -2
- package/dist/utilities/calculateValues.d.ts.map +1 -1
- package/dist/utilities/getCartTotalWithDiscounts.d.ts.map +1 -1
- package/dist/utilities/migrateReferralRulesV2.d.ts.map +1 -1
- package/dist/utilities/pricing.d.ts.map +1 -1
- package/dist/utilities/pushTypeScriptProperties.d.ts +1 -1
- package/dist/utilities/pushTypeScriptProperties.d.ts.map +1 -1
- package/dist/utilities/recordCouponUsageForOrder.d.ts +2 -2
- package/dist/utilities/recordCouponUsageForOrder.d.ts.map +1 -1
- package/dist/utilities/sanitizePluginConfig.d.ts +1 -1
- package/dist/utilities/sanitizePluginConfig.d.ts.map +1 -1
- package/dist/utilities/userRoles.d.ts +3 -3
- package/dist/utilities/userRoles.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -333,7 +333,11 @@ const createReferralCodesCollection = (pluginConfig) => {
|
|
|
333
333
|
function toNumber(value) {
|
|
334
334
|
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
335
335
|
}
|
|
336
|
-
const deriveCustomerSplit = (partnerSplit) => {
|
|
336
|
+
const deriveCustomerSplit = (partnerSplit, totalCommission) => {
|
|
337
|
+
if (totalCommission?.type === "fixed" && totalCommission.value == null) {
|
|
338
|
+
const partner = toNumber(partnerSplit);
|
|
339
|
+
return partner != null ? partner : 0;
|
|
340
|
+
}
|
|
337
341
|
const partner = toNumber(partnerSplit);
|
|
338
342
|
if (partner == null) return 0;
|
|
339
343
|
if (partner < 0) return 100;
|
|
@@ -367,16 +371,23 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
367
371
|
if (!r.totalCommission) throw new Error(`Commission rule ${index + 1}: Total Commission is required`);
|
|
368
372
|
if (!r.totalCommission.type || !allowedTotalCommissionTypes.includes(r.totalCommission.type)) throw new Error(`Commission rule ${index + 1}: Total Commission type must be one of ${allowedTotalCommissionTypes.join(", ")}`);
|
|
369
373
|
const totalValue = toNumber(r.totalCommission.value);
|
|
370
|
-
if (totalValue == null || totalValue < 0) throw new Error(`Commission rule ${index + 1}: Total Commission value must be a non-negative number`);
|
|
371
|
-
if (r.totalCommission.type === "percentage" && totalValue > 100) throw new Error(`Commission rule ${index + 1}: Percentage Total Commission cannot exceed 100`);
|
|
374
|
+
if (r.totalCommission.type === "percentage" && (totalValue == null || totalValue < 0)) throw new Error(`Commission rule ${index + 1}: Total Commission value must be a non-negative number`);
|
|
375
|
+
if (r.totalCommission.type === "percentage" && totalValue && totalValue > 100) throw new Error(`Commission rule ${index + 1}: Percentage Total Commission cannot exceed 100`);
|
|
372
376
|
const maxAmount = toNumber(r.totalCommission.maxAmount);
|
|
373
377
|
if (maxAmount != null && maxAmount < 0) throw new Error(`Commission rule ${index + 1}: Max Amount must be a non-negative number`);
|
|
374
378
|
const appliesTo = r.appliesTo ?? "all";
|
|
375
379
|
if (appliesTo === "products" && (!r.products || r.products.length === 0)) throw new Error(`Commission rule ${index + 1}: At least one product is required`);
|
|
376
380
|
if ((appliesTo === "segments" || appliesTo === "categories") && (!r.categories || r.categories.length === 0) && (!r.tags || r.tags.length === 0)) throw new Error(`Commission rule ${index + 1}: At least one category or tag is required`);
|
|
377
381
|
const partnerSplit = toNumber(r.partnerSplit);
|
|
378
|
-
if (partnerSplit == null || partnerSplit < 0
|
|
379
|
-
const
|
|
382
|
+
if (partnerSplit == null || partnerSplit < 0) throw new Error(`Commission rule ${index + 1}: Partner Split must be a non-negative number`);
|
|
383
|
+
const hasFixedValue = r.totalCommission.type === "fixed" && toNumber(r.totalCommission.value) != null;
|
|
384
|
+
if (!hasFixedValue && r.totalCommission.type !== "fixed" && partnerSplit > 100) throw new Error(`Commission rule ${index + 1}: Partner Split must be between 0 and 100`);
|
|
385
|
+
if (hasFixedValue && partnerSplit > 100) throw new Error(`Commission rule ${index + 1}: Partner Split must be between 0 and 100`);
|
|
386
|
+
let customerSplit = null;
|
|
387
|
+
if (r.totalCommission.type === "fixed" && !hasFixedValue) {
|
|
388
|
+
customerSplit = toNumber(r.customerSplit);
|
|
389
|
+
if (customerSplit == null || customerSplit < 0) throw new Error(`Commission rule ${index + 1}: For fixed commissions with no value, both partnerSplit and customerSplit must be non-negative numbers`);
|
|
390
|
+
} else customerSplit = 100 - partnerSplit;
|
|
380
391
|
const minOrderAmount = toNumber(r.minOrderAmount);
|
|
381
392
|
if (minOrderAmount != null && minOrderAmount < 0) throw new Error(`Commission rule ${index + 1}: Minimum Order Amount must be a non-negative number`);
|
|
382
393
|
return {
|
|
@@ -488,9 +499,11 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
488
499
|
{
|
|
489
500
|
name: "value",
|
|
490
501
|
type: "number",
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
502
|
+
admin: {
|
|
503
|
+
condition: ({ siblingData }) => siblingData?.type === "percentage",
|
|
504
|
+
description: "Total commission value (shown for percentage rules; ignored when using fixed split amounts)"
|
|
505
|
+
},
|
|
506
|
+
min: 0
|
|
494
507
|
},
|
|
495
508
|
{
|
|
496
509
|
name: "maxAmount",
|
|
@@ -505,9 +518,7 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
505
518
|
type: "number",
|
|
506
519
|
required: true,
|
|
507
520
|
min: 0,
|
|
508
|
-
|
|
509
|
-
defaultValue: referralConfig.defaultPartnerSplit,
|
|
510
|
-
admin: { description: "Percentage of total commission given to Partner (0-100)" }
|
|
521
|
+
admin: { description: "For percentage rules this is the percent that goes to the partner; when using fixed type it becomes the literal amount per item" }
|
|
511
522
|
},
|
|
512
523
|
{
|
|
513
524
|
name: "minOrderAmount",
|
|
@@ -519,15 +530,14 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
519
530
|
name: "customerSplit",
|
|
520
531
|
type: "number",
|
|
521
532
|
min: 0,
|
|
522
|
-
max: 100,
|
|
523
|
-
hooks: {
|
|
524
|
-
beforeValidate: [({ siblingData }) => deriveCustomerSplit(siblingData?.partnerSplit)],
|
|
525
|
-
beforeChange: [({ siblingData }) => deriveCustomerSplit(siblingData?.partnerSplit)]
|
|
526
|
-
},
|
|
527
533
|
admin: {
|
|
528
|
-
|
|
529
|
-
description: "
|
|
530
|
-
}
|
|
534
|
+
condition: ({ siblingData }) => siblingData?.totalCommission?.type !== "fixed",
|
|
535
|
+
description: "When using percentage rules this is auto-calculated; for fixed-type rules you may enter a literal amount"
|
|
536
|
+
},
|
|
537
|
+
hooks: { beforeValidate: [({ siblingData }) => {
|
|
538
|
+
if (!siblingData) return 0;
|
|
539
|
+
return deriveCustomerSplit(siblingData.partnerSplit, siblingData.totalCommission);
|
|
540
|
+
}] }
|
|
531
541
|
}
|
|
532
542
|
]
|
|
533
543
|
}
|
|
@@ -618,6 +628,15 @@ function calculateItemRewardByRule({ rule, itemTotal, quantity, allowedTotalComm
|
|
|
618
628
|
const allowedTypes = allowedCommissionTypesSet(allowedTotalCommissionTypes);
|
|
619
629
|
if (rule.totalCommission) {
|
|
620
630
|
if (!allowedTypes.has(rule.totalCommission.type)) return null;
|
|
631
|
+
if (rule.totalCommission.type === "fixed" && rule.totalCommission.value == null) {
|
|
632
|
+
const partnerAmt = typeof rule.partnerSplit === "number" ? rule.partnerSplit : null;
|
|
633
|
+
const customerAmt = typeof rule.customerSplit === "number" ? rule.customerSplit : null;
|
|
634
|
+
if (partnerAmt == null || customerAmt == null) return null;
|
|
635
|
+
return {
|
|
636
|
+
partner: partnerAmt * quantity,
|
|
637
|
+
customer: customerAmt * quantity
|
|
638
|
+
};
|
|
639
|
+
}
|
|
621
640
|
const splits = getRuleSplits(rule);
|
|
622
641
|
if (!splits) return null;
|
|
623
642
|
let totalPot = 0;
|