@zoxllc/shopify-checkout-extensions 0.0.8 → 0.1.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/CLAUDE.md +136 -0
- package/EXAMPLES.md +384 -0
- package/INTEGRATION.md +482 -0
- package/README.md +5 -1
- package/dist/common/AndSelector.d.ts +11 -0
- package/dist/common/AndSelector.d.ts.map +1 -0
- package/dist/common/AndSelector.js +30 -0
- package/dist/common/Campaign.d.ts +24 -0
- package/dist/common/Campaign.d.ts.map +1 -0
- package/dist/common/Campaign.js +41 -0
- package/dist/common/CampaignConfiguration.d.ts +10 -0
- package/dist/common/CampaignConfiguration.d.ts.map +1 -0
- package/dist/common/CampaignConfiguration.js +7 -0
- package/dist/common/CampaignFactory.d.ts +22 -0
- package/dist/common/CampaignFactory.d.ts.map +1 -0
- package/dist/common/CampaignFactory.js +95 -0
- package/dist/common/CartAmountQualifier.d.ts +22 -0
- package/dist/common/CartAmountQualifier.d.ts.map +1 -0
- package/dist/common/CartAmountQualifier.js +46 -0
- package/dist/common/CartHasItemQualifier.d.ts +21 -0
- package/dist/common/CartHasItemQualifier.d.ts.map +1 -0
- package/dist/common/CartHasItemQualifier.js +54 -0
- package/dist/common/CartQuantityQualifier.d.ts +22 -0
- package/dist/common/CartQuantityQualifier.d.ts.map +1 -0
- package/dist/common/CartQuantityQualifier.js +62 -0
- package/dist/common/ConfigSchema.d.ts +71 -0
- package/dist/common/ConfigSchema.d.ts.map +1 -0
- package/dist/common/ConfigSchema.js +69 -0
- package/dist/common/ConfigValidator.d.ts +29 -0
- package/dist/common/ConfigValidator.d.ts.map +1 -0
- package/dist/common/ConfigValidator.js +84 -0
- package/dist/common/CountryCodeQualifier.d.ts +15 -0
- package/dist/common/CountryCodeQualifier.d.ts.map +1 -0
- package/dist/common/CountryCodeQualifier.js +30 -0
- package/dist/common/CustomerEmailQualifier.d.ts +16 -0
- package/dist/common/CustomerEmailQualifier.d.ts.map +1 -0
- package/dist/common/CustomerEmailQualifier.js +52 -0
- package/dist/common/CustomerSubscriberQualifier.d.ts +18 -0
- package/dist/common/CustomerSubscriberQualifier.d.ts.map +1 -0
- package/dist/common/CustomerSubscriberQualifier.js +28 -0
- package/dist/common/CustomerTagQualifier.d.ts +16 -0
- package/dist/common/CustomerTagQualifier.d.ts.map +1 -0
- package/dist/common/CustomerTagQualifier.js +45 -0
- package/dist/common/DiscountCart.d.ts +23 -0
- package/dist/common/DiscountCart.d.ts.map +1 -0
- package/dist/common/DiscountCart.js +103 -0
- package/dist/common/DiscountInterface.d.ts +17 -0
- package/dist/common/DiscountInterface.d.ts.map +1 -0
- package/dist/common/DiscountInterface.js +2 -0
- package/dist/common/OrSelector.d.ts +11 -0
- package/dist/common/OrSelector.d.ts.map +1 -0
- package/dist/common/OrSelector.js +30 -0
- package/dist/common/PostCartAmountQualifier.d.ts +9 -0
- package/dist/common/PostCartAmountQualifier.d.ts.map +1 -0
- package/dist/common/PostCartAmountQualifier.js +17 -0
- package/dist/common/ProductHandleSelector.d.ts +8 -0
- package/dist/common/ProductHandleSelector.d.ts.map +1 -0
- package/dist/common/ProductHandleSelector.js +22 -0
- package/dist/common/ProductIdSelector.d.ts +8 -0
- package/dist/common/ProductIdSelector.d.ts.map +1 -0
- package/dist/common/ProductIdSelector.js +22 -0
- package/dist/common/ProductTagSelector.d.ts +10 -0
- package/dist/common/ProductTagSelector.d.ts.map +1 -0
- package/dist/common/ProductTagSelector.js +39 -0
- package/dist/common/ProductTypeSelector.d.ts +8 -0
- package/dist/common/ProductTypeSelector.d.ts.map +1 -0
- package/dist/common/ProductTypeSelector.js +25 -0
- package/dist/common/Qualifier.d.ts +30 -0
- package/dist/common/Qualifier.d.ts.map +1 -0
- package/dist/common/Qualifier.js +61 -0
- package/dist/common/SaleItemSelector.d.ts +11 -0
- package/dist/common/SaleItemSelector.d.ts.map +1 -0
- package/dist/common/SaleItemSelector.js +30 -0
- package/dist/common/Selector.d.ts +27 -0
- package/dist/common/Selector.d.ts.map +1 -0
- package/dist/common/Selector.js +51 -0
- package/dist/common/SubscriptionItemSelector.d.ts +7 -0
- package/dist/common/SubscriptionItemSelector.d.ts.map +1 -0
- package/dist/common/SubscriptionItemSelector.js +19 -0
- package/dist/form/CampaignForm.d.ts +1 -0
- package/dist/form/CampaignForm.d.ts.map +1 -0
- package/dist/form/CampaignForm.js +1 -0
- package/{src/index.ts → dist/index.d.ts} +22 -27
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/lineItem/BuyXGetY.d.ts +18 -0
- package/dist/lineItem/BuyXGetY.d.ts.map +1 -0
- package/dist/lineItem/BuyXGetY.js +85 -0
- package/dist/lineItem/ConditionalDiscount.d.ts +14 -0
- package/dist/lineItem/ConditionalDiscount.d.ts.map +1 -0
- package/dist/lineItem/ConditionalDiscount.js +81 -0
- package/dist/lineItem/FixedItemDiscount.d.ts +9 -0
- package/dist/lineItem/FixedItemDiscount.d.ts.map +1 -0
- package/dist/lineItem/FixedItemDiscount.js +35 -0
- package/dist/lineItem/PercentageDiscount.d.ts +8 -0
- package/dist/lineItem/PercentageDiscount.d.ts.map +1 -0
- package/dist/lineItem/PercentageDiscount.js +32 -0
- package/dist/lineItem/api.d.ts +2026 -0
- package/dist/lineItem/api.d.ts.map +1 -0
- package/dist/lineItem/api.js +1157 -0
- package/dist/shipping/FixedDiscount.d.ts +8 -0
- package/dist/shipping/FixedDiscount.d.ts.map +1 -0
- package/dist/shipping/FixedDiscount.js +30 -0
- package/dist/shipping/RateNameSelector.d.ts +10 -0
- package/dist/shipping/RateNameSelector.d.ts.map +1 -0
- package/dist/shipping/RateNameSelector.js +45 -0
- package/dist/shipping/ShippingDiscount.d.ts +14 -0
- package/dist/shipping/ShippingDiscount.d.ts.map +1 -0
- package/dist/shipping/ShippingDiscount.js +48 -0
- package/dist/shipping/api.d.ts +2019 -0
- package/dist/shipping/api.d.ts.map +1 -0
- package/dist/shipping/api.js +1147 -0
- package/package.json +26 -7
- package/migrate.ts +0 -64
- package/src/common/AndSelector.ts +0 -42
- package/src/common/Campaign.ts +0 -70
- package/src/common/CampaignConfiguration.ts +0 -10
- package/src/common/CampaignFactory.ts +0 -233
- package/src/common/CartAmountQualifier.ts +0 -64
- package/src/common/CartHasItemQualifier.ts +0 -80
- package/src/common/CartQuantityQualifier.ts +0 -94
- package/src/common/CountryCodeQualifier.ts +0 -49
- package/src/common/CustomerEmailQualifier.ts +0 -67
- package/src/common/CustomerSubscriberQualifier.ts +0 -32
- package/src/common/CustomerTagQualifier.ts +0 -69
- package/src/common/DiscountCart.ts +0 -161
- package/src/common/DiscountInterface.ts +0 -26
- package/src/common/OrSelector.ts +0 -40
- package/src/common/PostCartAmountQualifier.ts +0 -21
- package/src/common/ProductHandleSelector.ts +0 -32
- package/src/common/ProductIdSelector.ts +0 -34
- package/src/common/ProductTagSelector.ts +0 -63
- package/src/common/ProductTypeSelector.ts +0 -40
- package/src/common/Qualifier.ts +0 -67
- package/src/common/SaleItemSelector.ts +0 -36
- package/src/common/Selector.ts +0 -66
- package/src/common/SubscriptionItemSelector.ts +0 -23
- package/src/lineItem/BuyXGetY.ts +0 -131
- package/src/lineItem/ConditionalDiscount.ts +0 -102
- package/src/lineItem/FixedItemDiscount.ts +0 -51
- package/src/lineItem/PercentageDiscount.ts +0 -44
- package/src/lineItem/api.ts +0 -2103
- package/src/shipping/FixedDiscount.ts +0 -37
- package/src/shipping/RateNameSelector.ts +0 -54
- package/src/shipping/ShippingDiscount.ts +0 -75
- package/src/shipping/api.ts +0 -2014
- package/tests/AndSelector.test.ts +0 -27
- package/tests/CartQuantityQualifier.test.ts +0 -381
- package/tests/CountryCodeQualifier.test.ts +0 -55
- package/tests/CustomerSubscriberQualifier.test.ts +0 -101
- package/tests/CustomerTagQualifier.test.ts +0 -71
- package/tests/DiscountCart.test.ts +0 -115
- package/tests/OrSelector.test.ts +0 -27
- package/tests/ProductIdSelector.test.ts +0 -83
- package/tests/ProductTagSelector.test.ts +0 -75
- package/tests/Qualifier.test.ts +0 -193
- package/tests/RateNameSelector.test.ts +0 -107
- package/tests/SaleItemSelector.test.ts +0 -113
- package/tests/Selector.test.ts +0 -83
- package/tests/ShippingDiscount.test.ts +0 -147
- package/tsconfig.json +0 -25
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CampaignFactory = void 0;
|
|
4
|
+
const OrSelector_1 = require("./OrSelector");
|
|
5
|
+
const AndSelector_1 = require("./AndSelector");
|
|
6
|
+
const CartAmountQualifier_1 = require("./CartAmountQualifier");
|
|
7
|
+
const CartQuantityQualifier_1 = require("./CartQuantityQualifier");
|
|
8
|
+
const CustomerEmailQualifier_1 = require("./CustomerEmailQualifier");
|
|
9
|
+
const CustomerSubscriberQualifier_1 = require("./CustomerSubscriberQualifier");
|
|
10
|
+
const CustomerTagQualifier_1 = require("./CustomerTagQualifier");
|
|
11
|
+
const PostCartAmountQualifier_1 = require("./PostCartAmountQualifier");
|
|
12
|
+
const ProductIdSelector_1 = require("./ProductIdSelector");
|
|
13
|
+
const ProductTagSelector_1 = require("./ProductTagSelector");
|
|
14
|
+
const ProductTypeSelector_1 = require("./ProductTypeSelector");
|
|
15
|
+
const SaleItemSelector_1 = require("./SaleItemSelector");
|
|
16
|
+
const ConditionalDiscount_1 = require("../lineItem/ConditionalDiscount");
|
|
17
|
+
const FixedItemDiscount_1 = require("../lineItem/FixedItemDiscount");
|
|
18
|
+
const PercentageDiscount_1 = require("../lineItem/PercentageDiscount");
|
|
19
|
+
const BuyXGetY_1 = require("../lineItem/BuyXGetY");
|
|
20
|
+
const SubscriptionItemSelector_1 = require("./SubscriptionItemSelector");
|
|
21
|
+
const CountryCodeQualifier_1 = require("./CountryCodeQualifier");
|
|
22
|
+
const RateNameSelector_1 = require("../shipping/RateNameSelector");
|
|
23
|
+
const FixedDiscount_1 = require("../shipping/FixedDiscount");
|
|
24
|
+
const ShippingDiscount_1 = require("../shipping/ShippingDiscount");
|
|
25
|
+
class CampaignFactory {
|
|
26
|
+
static createFromConfig(config) {
|
|
27
|
+
return CampaignFactory.createInputsObject(config);
|
|
28
|
+
}
|
|
29
|
+
static parseInputConfig(input) {
|
|
30
|
+
if (typeof input == 'string' ||
|
|
31
|
+
typeof input == 'number' ||
|
|
32
|
+
typeof input == 'boolean' ||
|
|
33
|
+
input === null) {
|
|
34
|
+
return input;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return CampaignFactory.createInputsObject(input);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
static createInputsObject(config) {
|
|
41
|
+
const args = config.inputs.map((input) => {
|
|
42
|
+
if (Array.isArray(input)) {
|
|
43
|
+
return input.map((i) => CampaignFactory.parseInputConfig(i));
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return CampaignFactory.parseInputConfig(input);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
switch (config.__type) {
|
|
50
|
+
case 'ConditionalDiscount':
|
|
51
|
+
return new ConditionalDiscount_1.ConditionalDiscount(args[0], args[1], args[2], args[3], args[4]);
|
|
52
|
+
case 'BuyXGetY':
|
|
53
|
+
return new BuyXGetY_1.BuyXGetY(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);
|
|
54
|
+
case 'ShippingDiscount':
|
|
55
|
+
return new ShippingDiscount_1.ShippingDiscount(args[0], args[1], args[2], args[3]);
|
|
56
|
+
case 'AndSelector':
|
|
57
|
+
return new AndSelector_1.AndSelector([...args]);
|
|
58
|
+
case 'OrSelector':
|
|
59
|
+
return new OrSelector_1.OrSelector([...args]);
|
|
60
|
+
case 'PostCartAmountQualifier':
|
|
61
|
+
return new PostCartAmountQualifier_1.PostCartAmountQualifier(args[0], args[1]);
|
|
62
|
+
case 'CartAmountQualifier':
|
|
63
|
+
return new CartAmountQualifier_1.CartAmountQualifier(args[0], args[1], args[2]);
|
|
64
|
+
case 'CartQuantityQualifier':
|
|
65
|
+
return new CartQuantityQualifier_1.CartQuantityQualifier(args[0], args[1], args[2]);
|
|
66
|
+
case 'CountryCodeQualifier':
|
|
67
|
+
return new CountryCodeQualifier_1.CountryCodeQualifier(args[0], args[1]);
|
|
68
|
+
case 'SaleItemSelector':
|
|
69
|
+
return new SaleItemSelector_1.SaleItemSelector(args[0]);
|
|
70
|
+
case 'ProductIdSelector':
|
|
71
|
+
return new ProductIdSelector_1.ProductIdSelector(args[0], args[1]);
|
|
72
|
+
case 'ProductTypeSelector':
|
|
73
|
+
return new ProductTypeSelector_1.ProductTypeSelector(args[0], args[1]);
|
|
74
|
+
case 'ProductTagSelector':
|
|
75
|
+
return new ProductTagSelector_1.ProductTagSelector(args[0], args[1], args[2]);
|
|
76
|
+
case 'PercentageDiscount':
|
|
77
|
+
return new PercentageDiscount_1.PercentageDiscount(args[0], args[1]);
|
|
78
|
+
case 'FixedItemDiscount':
|
|
79
|
+
return new FixedItemDiscount_1.FixedItemDiscount(args[0], args[1], args[2]);
|
|
80
|
+
case 'FixedDiscount':
|
|
81
|
+
return new FixedDiscount_1.FixedDiscount(args[0], args[1]);
|
|
82
|
+
case 'SubscriptionItemSelector':
|
|
83
|
+
return new SubscriptionItemSelector_1.SubscriptionItemSelector(args[0]);
|
|
84
|
+
case 'RateNameSelector':
|
|
85
|
+
return new RateNameSelector_1.RateNameSelector(args[0], args[1], args[2]);
|
|
86
|
+
case 'CustomerSubscriberQualifier':
|
|
87
|
+
return new CustomerSubscriberQualifier_1.CustomerSubscriberQualifier(args[0]);
|
|
88
|
+
case 'CustomerEmailQualifier':
|
|
89
|
+
return new CustomerEmailQualifier_1.CustomerEmailQualifier(args[0], args[1], args[2]);
|
|
90
|
+
case 'CustomerTagQualifier':
|
|
91
|
+
return new CustomerTagQualifier_1.CustomerTagQualifier(args[0], args[1], args[2]);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.CampaignFactory = CampaignFactory;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { DiscountCart } from "./DiscountCart";
|
|
2
|
+
import { type NumericalComparisonType, Qualifier } from "./Qualifier";
|
|
3
|
+
import { type Selector } from "./Selector";
|
|
4
|
+
export declare enum CartAmountBehavior {
|
|
5
|
+
CART = ":cart",
|
|
6
|
+
ITEM = ":item",
|
|
7
|
+
DIFF_CART = ":diff_cart",
|
|
8
|
+
DIFF_ITEM = ":diff_item"
|
|
9
|
+
}
|
|
10
|
+
export declare class CartAmountQualifier extends Qualifier {
|
|
11
|
+
behavior: CartAmountBehavior;
|
|
12
|
+
comparisonType: NumericalComparisonType;
|
|
13
|
+
amount: number;
|
|
14
|
+
constructor(behavior: CartAmountBehavior, comparisonType: NumericalComparisonType, amount: number);
|
|
15
|
+
/**
|
|
16
|
+
* Determines if the carts amount
|
|
17
|
+
* @param cart
|
|
18
|
+
* @param selector
|
|
19
|
+
*/
|
|
20
|
+
match(discountCart: DiscountCart, selector?: Selector): boolean;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=CartAmountQualifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CartAmountQualifier.d.ts","sourceRoot":"","sources":["../../src/common/CartAmountQualifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,KAAK,uBAAuB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,oBAAY,kBAAkB;IAC5B,IAAI,UAAU;IACd,IAAI,UAAU;IACd,SAAS,eAAe;IACxB,SAAS,eAAe;CACzB;AAED,qBAAa,mBAAoB,SAAQ,SAAS;IAChD,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,cAAc,EAAE,uBAAuB,CAAC;IACxC,MAAM,EAAE,MAAM,CAAC;gBAGb,QAAQ,EAAE,kBAAkB,EAC5B,cAAc,EAAE,uBAAuB,EACvC,MAAM,EAAE,MAAM;IAQhB;;;;OAIG;IACH,KAAK,CAAC,YAAY,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,QAAQ;CA+BtD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CartAmountQualifier = exports.CartAmountBehavior = void 0;
|
|
4
|
+
const Qualifier_1 = require("./Qualifier");
|
|
5
|
+
var CartAmountBehavior;
|
|
6
|
+
(function (CartAmountBehavior) {
|
|
7
|
+
CartAmountBehavior["CART"] = ":cart";
|
|
8
|
+
CartAmountBehavior["ITEM"] = ":item";
|
|
9
|
+
CartAmountBehavior["DIFF_CART"] = ":diff_cart";
|
|
10
|
+
CartAmountBehavior["DIFF_ITEM"] = ":diff_item";
|
|
11
|
+
})(CartAmountBehavior || (exports.CartAmountBehavior = CartAmountBehavior = {}));
|
|
12
|
+
class CartAmountQualifier extends Qualifier_1.Qualifier {
|
|
13
|
+
behavior;
|
|
14
|
+
comparisonType;
|
|
15
|
+
amount;
|
|
16
|
+
constructor(behavior, comparisonType, amount) {
|
|
17
|
+
super();
|
|
18
|
+
this.behavior = behavior;
|
|
19
|
+
this.comparisonType = comparisonType;
|
|
20
|
+
this.amount = amount;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Determines if the carts amount
|
|
24
|
+
* @param cart
|
|
25
|
+
* @param selector
|
|
26
|
+
*/
|
|
27
|
+
match(discountCart, selector) {
|
|
28
|
+
let total = parseFloat(discountCart.cart.cost.subtotalAmount.amount) -
|
|
29
|
+
discountCart.appliedDiscountTotal;
|
|
30
|
+
switch (this.behavior) {
|
|
31
|
+
case CartAmountBehavior.CART:
|
|
32
|
+
case CartAmountBehavior.ITEM:
|
|
33
|
+
return this.compareAmounts(total, this.comparisonType, this.amount);
|
|
34
|
+
case CartAmountBehavior.DIFF_CART:
|
|
35
|
+
return this.compareAmounts(parseFloat(discountCart.cart.cost.subtotalAmount.amount) -
|
|
36
|
+
this.amount, this.comparisonType, total);
|
|
37
|
+
case CartAmountBehavior.DIFF_ITEM:
|
|
38
|
+
const originalLineTotal = discountCart.cart.lines.reduce((runningTotal, line) => {
|
|
39
|
+
runningTotal += parseFloat(line.cost.subtotalAmount.amount);
|
|
40
|
+
return runningTotal;
|
|
41
|
+
}, total);
|
|
42
|
+
return this.compareAmounts(originalLineTotal - this.amount, this.comparisonType, total);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.CartAmountQualifier = CartAmountQualifier;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DiscountCart } from './DiscountCart';
|
|
2
|
+
import { type NumericalComparisonType, Qualifier } from './Qualifier';
|
|
3
|
+
import { type Selector } from './Selector';
|
|
4
|
+
export declare enum CartHasItemBehavior {
|
|
5
|
+
QUANTITY = ":quantity",
|
|
6
|
+
SUBTOTAL = ":subtotal"
|
|
7
|
+
}
|
|
8
|
+
export declare class CartHasItemQualifier extends Qualifier {
|
|
9
|
+
quantityOrSubtotal: CartHasItemBehavior;
|
|
10
|
+
comparisonType: NumericalComparisonType;
|
|
11
|
+
amount: number;
|
|
12
|
+
itemSelector: Selector;
|
|
13
|
+
constructor(quantityOrSubtotal: CartHasItemBehavior, comparisonType: NumericalComparisonType, amount: number, itemSelector: Selector);
|
|
14
|
+
/**
|
|
15
|
+
* Determines if the carts amount
|
|
16
|
+
* @param cart
|
|
17
|
+
* @param selector
|
|
18
|
+
*/
|
|
19
|
+
match(discountCart: DiscountCart, selector?: Selector): boolean;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=CartHasItemQualifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CartHasItemQualifier.d.ts","sourceRoot":"","sources":["../../src/common/CartHasItemQualifier.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACL,KAAK,uBAAuB,EAC5B,SAAS,EACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,oBAAY,mBAAmB;IAC7B,QAAQ,cAAc;IACtB,QAAQ,cAAc;CACvB;AAED,qBAAa,oBAAqB,SAAQ,SAAS;IACjD,kBAAkB,EAAE,mBAAmB,CAAC;IACxC,cAAc,EAAE,uBAAuB,CAAC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,QAAQ,CAAC;gBAGrB,kBAAkB,EAAE,mBAAmB,EACvC,cAAc,EAAE,uBAAuB,EACvC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,QAAQ;IAaxB;;;;OAIG;IACH,KAAK,CAAC,YAAY,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,QAAQ;CAsCtD"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CartHasItemQualifier = exports.CartHasItemBehavior = void 0;
|
|
4
|
+
const Qualifier_1 = require("./Qualifier");
|
|
5
|
+
var CartHasItemBehavior;
|
|
6
|
+
(function (CartHasItemBehavior) {
|
|
7
|
+
CartHasItemBehavior["QUANTITY"] = ":quantity";
|
|
8
|
+
CartHasItemBehavior["SUBTOTAL"] = ":subtotal";
|
|
9
|
+
})(CartHasItemBehavior || (exports.CartHasItemBehavior = CartHasItemBehavior = {}));
|
|
10
|
+
class CartHasItemQualifier extends Qualifier_1.Qualifier {
|
|
11
|
+
quantityOrSubtotal;
|
|
12
|
+
comparisonType;
|
|
13
|
+
amount;
|
|
14
|
+
itemSelector;
|
|
15
|
+
constructor(quantityOrSubtotal, comparisonType, amount, itemSelector) {
|
|
16
|
+
super();
|
|
17
|
+
this.quantityOrSubtotal = quantityOrSubtotal;
|
|
18
|
+
this.comparisonType = comparisonType;
|
|
19
|
+
this.amount =
|
|
20
|
+
this.quantityOrSubtotal ==
|
|
21
|
+
CartHasItemBehavior.SUBTOTAL
|
|
22
|
+
? amount
|
|
23
|
+
: Math.floor(amount);
|
|
24
|
+
this.itemSelector = itemSelector;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Determines if the carts amount
|
|
28
|
+
* @param cart
|
|
29
|
+
* @param selector
|
|
30
|
+
*/
|
|
31
|
+
match(discountCart, selector) {
|
|
32
|
+
let total = 0;
|
|
33
|
+
switch (this.quantityOrSubtotal) {
|
|
34
|
+
case CartHasItemBehavior.QUANTITY:
|
|
35
|
+
total = discountCart.cart.lines.reduce((quantity, line) => {
|
|
36
|
+
return (quantity +
|
|
37
|
+
(this.itemSelector.match(line)
|
|
38
|
+
? line.quantity
|
|
39
|
+
: 0));
|
|
40
|
+
}, 0);
|
|
41
|
+
break;
|
|
42
|
+
case CartHasItemBehavior.SUBTOTAL:
|
|
43
|
+
total = discountCart.cart.lines.reduce((amount, line) => {
|
|
44
|
+
return (amount +
|
|
45
|
+
(this.itemSelector.match(line)
|
|
46
|
+
? line.cost.subtotalAmount.amount
|
|
47
|
+
: 0));
|
|
48
|
+
}, 0);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
return this.compareAmounts(total, this.comparisonType, this.amount);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.CartHasItemQualifier = CartHasItemQualifier;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { DiscountCart } from './DiscountCart';
|
|
2
|
+
import { type NumericalComparisonType, Qualifier } from './Qualifier';
|
|
3
|
+
import { type Selector } from './Selector';
|
|
4
|
+
export declare enum CartQuantityBehavior {
|
|
5
|
+
CART = ":cart",
|
|
6
|
+
ITEM = ":item",
|
|
7
|
+
LINE_ANY = ":line_any",
|
|
8
|
+
LINE_ALL = ":line_all"
|
|
9
|
+
}
|
|
10
|
+
export declare class CartQuantityQualifier extends Qualifier {
|
|
11
|
+
totalMethod: CartQuantityBehavior;
|
|
12
|
+
comparisonType: NumericalComparisonType;
|
|
13
|
+
quantity: number;
|
|
14
|
+
constructor(totalMethod: CartQuantityBehavior, comparisonType: NumericalComparisonType, quantity: number);
|
|
15
|
+
/**
|
|
16
|
+
* Determines if the carts amount
|
|
17
|
+
* @param cart
|
|
18
|
+
* @param selector
|
|
19
|
+
*/
|
|
20
|
+
match(discountCart: DiscountCart, selector?: Selector): boolean;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=CartQuantityQualifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CartQuantityQualifier.d.ts","sourceRoot":"","sources":["../../src/common/CartQuantityQualifier.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACL,KAAK,uBAAuB,EAC5B,SAAS,EACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,oBAAY,oBAAoB;IAC9B,IAAI,UAAU;IACd,IAAI,UAAU;IACd,QAAQ,cAAc;IACtB,QAAQ,cAAc;CACvB;AAED,qBAAa,qBAAsB,SAAQ,SAAS;IAClD,WAAW,EAAE,oBAAoB,CAAC;IAClC,cAAc,EAAE,uBAAuB,CAAC;IACxC,QAAQ,EAAE,MAAM,CAAC;gBAGf,WAAW,EAAE,oBAAoB,EACjC,cAAc,EAAE,uBAAuB,EACvC,QAAQ,EAAE,MAAM;IAQlB;;;;OAIG;IACH,KAAK,CAAC,YAAY,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,QAAQ;CAyDtD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CartQuantityQualifier = exports.CartQuantityBehavior = void 0;
|
|
4
|
+
const Qualifier_1 = require("./Qualifier");
|
|
5
|
+
var CartQuantityBehavior;
|
|
6
|
+
(function (CartQuantityBehavior) {
|
|
7
|
+
CartQuantityBehavior["CART"] = ":cart";
|
|
8
|
+
CartQuantityBehavior["ITEM"] = ":item";
|
|
9
|
+
CartQuantityBehavior["LINE_ANY"] = ":line_any";
|
|
10
|
+
CartQuantityBehavior["LINE_ALL"] = ":line_all";
|
|
11
|
+
})(CartQuantityBehavior || (exports.CartQuantityBehavior = CartQuantityBehavior = {}));
|
|
12
|
+
class CartQuantityQualifier extends Qualifier_1.Qualifier {
|
|
13
|
+
totalMethod;
|
|
14
|
+
comparisonType;
|
|
15
|
+
quantity;
|
|
16
|
+
constructor(totalMethod, comparisonType, quantity) {
|
|
17
|
+
super();
|
|
18
|
+
this.totalMethod = totalMethod;
|
|
19
|
+
this.comparisonType = comparisonType;
|
|
20
|
+
this.quantity = quantity;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Determines if the carts amount
|
|
24
|
+
* @param cart
|
|
25
|
+
* @param selector
|
|
26
|
+
*/
|
|
27
|
+
match(discountCart, selector) {
|
|
28
|
+
let total = 0;
|
|
29
|
+
switch (this.totalMethod) {
|
|
30
|
+
case CartQuantityBehavior.ITEM:
|
|
31
|
+
total = discountCart.cart.lines.reduce((totalQty, line) => {
|
|
32
|
+
return (totalQty +
|
|
33
|
+
((selector
|
|
34
|
+
? selector.match(line)
|
|
35
|
+
: true)
|
|
36
|
+
? line.quantity
|
|
37
|
+
: 0));
|
|
38
|
+
}, 0);
|
|
39
|
+
break;
|
|
40
|
+
case CartQuantityBehavior.CART:
|
|
41
|
+
total =
|
|
42
|
+
discountCart.totalLineItemQuantityExcludingGifts();
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
if (this.totalMethod == CartQuantityBehavior.LINE_ANY ||
|
|
46
|
+
this.totalMethod == CartQuantityBehavior.LINE_ALL) {
|
|
47
|
+
const qualifiedItems = discountCart.cart.lines
|
|
48
|
+
.filter((line) => selector ? selector.match(line) : true)
|
|
49
|
+
.map((line) => this.compareAmounts(line.quantity, this.comparisonType, this.quantity));
|
|
50
|
+
switch (this.totalMethod) {
|
|
51
|
+
case CartQuantityBehavior.LINE_ANY:
|
|
52
|
+
return qualifiedItems.indexOf(true) > -1;
|
|
53
|
+
case CartQuantityBehavior.LINE_ALL:
|
|
54
|
+
return qualifiedItems.indexOf(false) == -1;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return this.compareAmounts(total, this.comparisonType, this.quantity);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.CartQuantityQualifier = CartQuantityQualifier;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema definitions for campaign configurations.
|
|
3
|
+
* Use these schemas in your UI app to validate configurations before saving.
|
|
4
|
+
*/
|
|
5
|
+
export declare const CampaignConfigSchema: {
|
|
6
|
+
$schema: string;
|
|
7
|
+
type: string;
|
|
8
|
+
required: string[];
|
|
9
|
+
properties: {
|
|
10
|
+
__type: {
|
|
11
|
+
type: string;
|
|
12
|
+
enum: string[];
|
|
13
|
+
description: string;
|
|
14
|
+
};
|
|
15
|
+
label: {
|
|
16
|
+
type: string;
|
|
17
|
+
minLength: number;
|
|
18
|
+
maxLength: number;
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
active: {
|
|
22
|
+
type: string;
|
|
23
|
+
description: string;
|
|
24
|
+
};
|
|
25
|
+
description: {
|
|
26
|
+
type: string;
|
|
27
|
+
maxLength: number;
|
|
28
|
+
description: string;
|
|
29
|
+
};
|
|
30
|
+
inputs: {
|
|
31
|
+
type: string;
|
|
32
|
+
description: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export declare const QualifierBehaviorSchema: {
|
|
37
|
+
type: string;
|
|
38
|
+
enum: string[];
|
|
39
|
+
description: string;
|
|
40
|
+
};
|
|
41
|
+
export declare const MatchTypeSchema: {
|
|
42
|
+
type: string;
|
|
43
|
+
enum: string[];
|
|
44
|
+
description: string;
|
|
45
|
+
};
|
|
46
|
+
export declare const QualifierMatchTypeSchema: {
|
|
47
|
+
type: string;
|
|
48
|
+
enum: string[];
|
|
49
|
+
description: string;
|
|
50
|
+
};
|
|
51
|
+
export declare const NumericalComparisonSchema: {
|
|
52
|
+
type: string;
|
|
53
|
+
enum: string[];
|
|
54
|
+
description: string;
|
|
55
|
+
};
|
|
56
|
+
export declare const StringComparisonSchema: {
|
|
57
|
+
type: string;
|
|
58
|
+
enum: string[];
|
|
59
|
+
description: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Type definitions that match the schemas
|
|
63
|
+
*/
|
|
64
|
+
export type CampaignConfigSchemaType = {
|
|
65
|
+
__type: 'ConditionalDiscount' | 'BuyXGetY' | 'ShippingDiscount';
|
|
66
|
+
label: string;
|
|
67
|
+
active: boolean;
|
|
68
|
+
description?: string;
|
|
69
|
+
inputs: unknown[];
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=ConfigSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigSchema.d.ts","sourceRoot":"","sources":["../../src/common/ConfigSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BhC,CAAC;AAEF,eAAO,MAAM,uBAAuB;;;;CAInC,CAAC;AAEF,eAAO,MAAM,eAAe;;;;CAI3B,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;CAIpC,CAAC;AAEF,eAAO,MAAM,yBAAyB;;;;CAUrC,CAAC;AAEF,eAAO,MAAM,sBAAsB;;;;CAIlC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,EAAE,qBAAqB,GAAG,UAAU,GAAG,kBAAkB,CAAC;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,OAAO,EAAE,CAAC;CACnB,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* JSON Schema definitions for campaign configurations.
|
|
4
|
+
* Use these schemas in your UI app to validate configurations before saving.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.StringComparisonSchema = exports.NumericalComparisonSchema = exports.QualifierMatchTypeSchema = exports.MatchTypeSchema = exports.QualifierBehaviorSchema = exports.CampaignConfigSchema = void 0;
|
|
8
|
+
exports.CampaignConfigSchema = {
|
|
9
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
10
|
+
type: 'object',
|
|
11
|
+
required: ['__type', 'label', 'active', 'inputs'],
|
|
12
|
+
properties: {
|
|
13
|
+
__type: {
|
|
14
|
+
type: 'string',
|
|
15
|
+
enum: ['ConditionalDiscount', 'BuyXGetY', 'ShippingDiscount'],
|
|
16
|
+
description: 'The type of campaign to create',
|
|
17
|
+
},
|
|
18
|
+
label: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
minLength: 1,
|
|
21
|
+
maxLength: 100,
|
|
22
|
+
description: 'Human-readable label for the campaign',
|
|
23
|
+
},
|
|
24
|
+
active: {
|
|
25
|
+
type: 'boolean',
|
|
26
|
+
description: 'Whether this campaign is currently active',
|
|
27
|
+
},
|
|
28
|
+
description: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
maxLength: 500,
|
|
31
|
+
description: 'Optional description of what this campaign does',
|
|
32
|
+
},
|
|
33
|
+
inputs: {
|
|
34
|
+
type: 'array',
|
|
35
|
+
description: 'Constructor arguments for the campaign',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
exports.QualifierBehaviorSchema = {
|
|
40
|
+
type: 'string',
|
|
41
|
+
enum: [':all', ':any'],
|
|
42
|
+
description: 'How to combine multiple qualifiers (ALL must match, or ANY can match)',
|
|
43
|
+
};
|
|
44
|
+
exports.MatchTypeSchema = {
|
|
45
|
+
type: 'string',
|
|
46
|
+
enum: [':all', ':is_one', ':not_one', ':does', ':does_not'],
|
|
47
|
+
description: 'How to match items',
|
|
48
|
+
};
|
|
49
|
+
exports.QualifierMatchTypeSchema = {
|
|
50
|
+
type: 'string',
|
|
51
|
+
enum: [':does', ':does_not'],
|
|
52
|
+
description: 'Positive or negative matching',
|
|
53
|
+
};
|
|
54
|
+
exports.NumericalComparisonSchema = {
|
|
55
|
+
type: 'string',
|
|
56
|
+
enum: [
|
|
57
|
+
':greater_than',
|
|
58
|
+
':greater_than_or_equal',
|
|
59
|
+
':less_than',
|
|
60
|
+
':less_than_or_equal',
|
|
61
|
+
':equal_to',
|
|
62
|
+
],
|
|
63
|
+
description: 'How to compare numerical values',
|
|
64
|
+
};
|
|
65
|
+
exports.StringComparisonSchema = {
|
|
66
|
+
type: 'string',
|
|
67
|
+
enum: [':match', ':contains', ':start_with', ':end_with'],
|
|
68
|
+
description: 'How to compare string values',
|
|
69
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CampaignInputConfig } from './CampaignFactory';
|
|
2
|
+
export interface ValidationError {
|
|
3
|
+
field: string;
|
|
4
|
+
message: string;
|
|
5
|
+
value?: unknown;
|
|
6
|
+
}
|
|
7
|
+
export interface ValidationResult {
|
|
8
|
+
valid: boolean;
|
|
9
|
+
errors: ValidationError[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Validates campaign configurations.
|
|
13
|
+
* Use this in your UI app before saving configurations.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ConfigValidator {
|
|
16
|
+
/**
|
|
17
|
+
* Validates a campaign configuration
|
|
18
|
+
*/
|
|
19
|
+
static validate(config: unknown): ValidationResult;
|
|
20
|
+
/**
|
|
21
|
+
* Validates multiple configurations
|
|
22
|
+
*/
|
|
23
|
+
static validateAll(configs: unknown[]): ValidationResult;
|
|
24
|
+
/**
|
|
25
|
+
* Type guard to check if a config is valid
|
|
26
|
+
*/
|
|
27
|
+
static isValid(config: unknown): config is CampaignInputConfig;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=ConfigValidator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigValidator.d.ts","sourceRoot":"","sources":["../../src/common/ConfigValidator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B;AAED;;;GAGG;AACH,qBAAa,eAAe;IAC1B;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB;IAgDlD;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,gBAAgB;IA4BxD;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,mBAAmB;CAG/D"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConfigValidator = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Validates campaign configurations.
|
|
6
|
+
* Use this in your UI app before saving configurations.
|
|
7
|
+
*/
|
|
8
|
+
class ConfigValidator {
|
|
9
|
+
/**
|
|
10
|
+
* Validates a campaign configuration
|
|
11
|
+
*/
|
|
12
|
+
static validate(config) {
|
|
13
|
+
const errors = [];
|
|
14
|
+
// Check if config is an object
|
|
15
|
+
if (!config || typeof config !== 'object') {
|
|
16
|
+
return {
|
|
17
|
+
valid: false,
|
|
18
|
+
errors: [{ field: 'config', message: 'Configuration must be an object' }],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const cfg = config;
|
|
22
|
+
// Validate required fields
|
|
23
|
+
if (!cfg.__type) {
|
|
24
|
+
errors.push({ field: '__type', message: 'Campaign type is required' });
|
|
25
|
+
}
|
|
26
|
+
else if (!['ConditionalDiscount', 'BuyXGetY', 'ShippingDiscount'].includes(cfg.__type)) {
|
|
27
|
+
errors.push({
|
|
28
|
+
field: '__type',
|
|
29
|
+
message: 'Invalid campaign type',
|
|
30
|
+
value: cfg.__type,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (!cfg.label || typeof cfg.label !== 'string') {
|
|
34
|
+
errors.push({ field: 'label', message: 'Label is required and must be a string' });
|
|
35
|
+
}
|
|
36
|
+
else if (cfg.label.length === 0) {
|
|
37
|
+
errors.push({ field: 'label', message: 'Label cannot be empty' });
|
|
38
|
+
}
|
|
39
|
+
if (typeof cfg.active !== 'boolean') {
|
|
40
|
+
errors.push({ field: 'active', message: 'Active must be a boolean' });
|
|
41
|
+
}
|
|
42
|
+
if (!Array.isArray(cfg.inputs)) {
|
|
43
|
+
errors.push({ field: 'inputs', message: 'Inputs must be an array' });
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
valid: errors.length === 0,
|
|
47
|
+
errors,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Validates multiple configurations
|
|
52
|
+
*/
|
|
53
|
+
static validateAll(configs) {
|
|
54
|
+
const allErrors = [];
|
|
55
|
+
if (!Array.isArray(configs)) {
|
|
56
|
+
return {
|
|
57
|
+
valid: false,
|
|
58
|
+
errors: [{ field: 'configs', message: 'Configs must be an array' }],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
configs.forEach((config, index) => {
|
|
62
|
+
const result = ConfigValidator.validate(config);
|
|
63
|
+
if (!result.valid) {
|
|
64
|
+
result.errors.forEach((error) => {
|
|
65
|
+
allErrors.push({
|
|
66
|
+
...error,
|
|
67
|
+
field: `configs[${index}].${error.field}`,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
valid: allErrors.length === 0,
|
|
74
|
+
errors: allErrors,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Type guard to check if a config is valid
|
|
79
|
+
*/
|
|
80
|
+
static isValid(config) {
|
|
81
|
+
return ConfigValidator.validate(config).valid;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.ConfigValidator = ConfigValidator;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DiscountCart } from './DiscountCart';
|
|
2
|
+
import { QualifierMatchType, Qualifier } from './Qualifier';
|
|
3
|
+
import { type Selector } from './Selector';
|
|
4
|
+
export declare class CountryCodeQualifier extends Qualifier {
|
|
5
|
+
invert: boolean;
|
|
6
|
+
countryCodes: string[];
|
|
7
|
+
constructor(matchType: QualifierMatchType, countryCodes: string[]);
|
|
8
|
+
/**
|
|
9
|
+
* Determines if the customer has specified tags
|
|
10
|
+
* @param discountCart DiscountCart
|
|
11
|
+
* @param selector Selector
|
|
12
|
+
*/
|
|
13
|
+
match(discountCart: DiscountCart, selector?: Selector): boolean;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=CountryCodeQualifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CountryCodeQualifier.d.ts","sourceRoot":"","sources":["../../src/common/CountryCodeQualifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAEL,kBAAkB,EAClB,SAAS,EACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,qBAAa,oBAAqB,SAAQ,SAAS;IACjD,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,MAAM,EAAE,CAAC;gBAGrB,SAAS,EAAE,kBAAkB,EAC7B,YAAY,EAAE,MAAM,EAAE;IASxB;;;;OAIG;IACH,KAAK,CAAC,YAAY,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,QAAQ;CAoBtD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CountryCodeQualifier = void 0;
|
|
4
|
+
const Qualifier_1 = require("./Qualifier");
|
|
5
|
+
class CountryCodeQualifier extends Qualifier_1.Qualifier {
|
|
6
|
+
invert;
|
|
7
|
+
countryCodes;
|
|
8
|
+
constructor(matchType, countryCodes) {
|
|
9
|
+
super();
|
|
10
|
+
this.invert = matchType == Qualifier_1.QualifierMatchType.DOES_NOT;
|
|
11
|
+
this.countryCodes = countryCodes.map((e) => e.toLowerCase());
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Determines if the customer has specified tags
|
|
15
|
+
* @param discountCart DiscountCart
|
|
16
|
+
* @param selector Selector
|
|
17
|
+
*/
|
|
18
|
+
match(discountCart, selector) {
|
|
19
|
+
const matchResult = (discountCart.cart.deliveryGroups.filter((deliveryGroup) => {
|
|
20
|
+
const countryCode = deliveryGroup?.deliveryAddress?.countryCode?.toLowerCase() ||
|
|
21
|
+
'';
|
|
22
|
+
return this.countryCodes.includes(countryCode);
|
|
23
|
+
}) || []).length > 0;
|
|
24
|
+
if (this.invert) {
|
|
25
|
+
return !matchResult;
|
|
26
|
+
}
|
|
27
|
+
return matchResult;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.CountryCodeQualifier = CountryCodeQualifier;
|