@zoxllc/shopify-checkout-extensions 0.0.7 → 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 -234
- 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 -31
- 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,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Qualifier = exports.QualifierBehavior = exports.NumericalComparisonType = exports.StringComparisonType = exports.QualifierMatchType = void 0;
|
|
4
|
+
var QualifierMatchType;
|
|
5
|
+
(function (QualifierMatchType) {
|
|
6
|
+
QualifierMatchType["DOES"] = ":does";
|
|
7
|
+
QualifierMatchType["DOES_NOT"] = ":does_not";
|
|
8
|
+
})(QualifierMatchType || (exports.QualifierMatchType = QualifierMatchType = {}));
|
|
9
|
+
var StringComparisonType;
|
|
10
|
+
(function (StringComparisonType) {
|
|
11
|
+
StringComparisonType["MATCH"] = ":match";
|
|
12
|
+
StringComparisonType["CONTAINS"] = ":contains";
|
|
13
|
+
StringComparisonType["START_WITH"] = ":start_with";
|
|
14
|
+
StringComparisonType["END_WITH"] = ":end_with";
|
|
15
|
+
})(StringComparisonType || (exports.StringComparisonType = StringComparisonType = {}));
|
|
16
|
+
var NumericalComparisonType;
|
|
17
|
+
(function (NumericalComparisonType) {
|
|
18
|
+
NumericalComparisonType["GREATER_THAN"] = ":greater_than";
|
|
19
|
+
NumericalComparisonType["GREATER_THAN_OR_EQUAL"] = ":greater_than_or_equal";
|
|
20
|
+
NumericalComparisonType["LESS_THAN"] = ":less_than";
|
|
21
|
+
NumericalComparisonType["LESS_THAN_OR_EQUAL"] = ":less_than_or_equal";
|
|
22
|
+
NumericalComparisonType["EQUAL_TO"] = ":equal_to";
|
|
23
|
+
})(NumericalComparisonType || (exports.NumericalComparisonType = NumericalComparisonType = {}));
|
|
24
|
+
// export enum ComparisonType {
|
|
25
|
+
// GREATER_THAN = ":greater_than",
|
|
26
|
+
// GREATER_THAN_OR_EQUAL = ":greater_than_or_equal",
|
|
27
|
+
// LESS_THAN = ":less_than",
|
|
28
|
+
// LESS_THAN_OR_EQUAL = ":less_than_or_equal",
|
|
29
|
+
// EQUAL_TO = ":equal_to",
|
|
30
|
+
// }
|
|
31
|
+
var QualifierBehavior;
|
|
32
|
+
(function (QualifierBehavior) {
|
|
33
|
+
QualifierBehavior["ALL"] = ":all";
|
|
34
|
+
QualifierBehavior["ANY"] = ":any";
|
|
35
|
+
})(QualifierBehavior || (exports.QualifierBehavior = QualifierBehavior = {}));
|
|
36
|
+
class Qualifier {
|
|
37
|
+
is_a;
|
|
38
|
+
constructor() {
|
|
39
|
+
this.is_a = 'Qualifier';
|
|
40
|
+
}
|
|
41
|
+
compareAmounts(compare, comparisonType, compareTo) {
|
|
42
|
+
switch (comparisonType) {
|
|
43
|
+
case NumericalComparisonType.GREATER_THAN:
|
|
44
|
+
return compare > compareTo;
|
|
45
|
+
case NumericalComparisonType.GREATER_THAN_OR_EQUAL:
|
|
46
|
+
return compare >= compareTo;
|
|
47
|
+
case NumericalComparisonType.LESS_THAN:
|
|
48
|
+
return compare < compareTo;
|
|
49
|
+
case NumericalComparisonType.LESS_THAN_OR_EQUAL:
|
|
50
|
+
return compare <= compareTo;
|
|
51
|
+
case NumericalComparisonType.EQUAL_TO:
|
|
52
|
+
return compare == compareTo;
|
|
53
|
+
default:
|
|
54
|
+
throw new Error('Invalid comparison type');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
match(discountCart, selector) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.Qualifier = Qualifier;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Selector } from './Selector';
|
|
2
|
+
export declare enum SaleItemSelectorMatchType {
|
|
3
|
+
IS = ":is",
|
|
4
|
+
NOT = ":not"
|
|
5
|
+
}
|
|
6
|
+
export declare class SaleItemSelector extends Selector {
|
|
7
|
+
invert: boolean;
|
|
8
|
+
constructor(matchType: SaleItemSelectorMatchType);
|
|
9
|
+
match(subject: unknown): boolean;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=SaleItemSelector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SaleItemSelector.d.ts","sourceRoot":"","sources":["../../src/common/SaleItemSelector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,oBAAY,yBAAyB;IACnC,EAAE,QAAQ;IACV,GAAG,SAAS;CACb;AAED,qBAAa,gBAAiB,SAAQ,QAAQ;IAC5C,MAAM,EAAE,OAAO,CAAC;gBAEJ,SAAS,EAAE,yBAAyB;IAOhD,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;CAiBjC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SaleItemSelector = exports.SaleItemSelectorMatchType = void 0;
|
|
4
|
+
const Selector_1 = require("./Selector");
|
|
5
|
+
var SaleItemSelectorMatchType;
|
|
6
|
+
(function (SaleItemSelectorMatchType) {
|
|
7
|
+
SaleItemSelectorMatchType["IS"] = ":is";
|
|
8
|
+
SaleItemSelectorMatchType["NOT"] = ":not";
|
|
9
|
+
})(SaleItemSelectorMatchType || (exports.SaleItemSelectorMatchType = SaleItemSelectorMatchType = {}));
|
|
10
|
+
class SaleItemSelector extends Selector_1.Selector {
|
|
11
|
+
invert;
|
|
12
|
+
constructor(matchType) {
|
|
13
|
+
super();
|
|
14
|
+
// Unlike other common scenarios, we invert if we pass an :IS
|
|
15
|
+
// because it is easier to figure out of the item is NOT on sale.
|
|
16
|
+
this.invert = matchType == SaleItemSelectorMatchType.IS;
|
|
17
|
+
}
|
|
18
|
+
match(lineItem) {
|
|
19
|
+
// Check to see if the item is NOT on sale
|
|
20
|
+
const matchResult = !lineItem.cost.compareAtAmountPerQuantity ||
|
|
21
|
+
parseFloat(lineItem.cost.compareAtAmountPerQuantity.amount) <=
|
|
22
|
+
parseFloat(lineItem.cost.amountPerQuantity.amount);
|
|
23
|
+
// If we want to check that the item IS on sale, we'll invert the result
|
|
24
|
+
if (this.invert) {
|
|
25
|
+
return !matchResult;
|
|
26
|
+
}
|
|
27
|
+
return matchResult;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.SaleItemSelector = SaleItemSelector;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CartDeliveryOption } from '../shipping/api';
|
|
2
|
+
import type { CartLine } from '../lineItem/api';
|
|
3
|
+
import { StringComparisonType } from './Qualifier';
|
|
4
|
+
export declare enum MatchType {
|
|
5
|
+
'ALL' = ":all",
|
|
6
|
+
'IS_ONE' = ":is_one",
|
|
7
|
+
'NOT_ONE' = ":not_one",
|
|
8
|
+
'DOES' = ":does",
|
|
9
|
+
'DOES_NOT' = ":does_not"
|
|
10
|
+
}
|
|
11
|
+
export type SelectorInterface = {
|
|
12
|
+
match(subject: CartLine): boolean;
|
|
13
|
+
match(subject: CartDeliveryOption): boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare class Selector implements SelectorInterface {
|
|
16
|
+
match(subject: CartLine): boolean;
|
|
17
|
+
match(subject: CartDeliveryOption): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Checks each member of the subject array for possible matches. Returns true when any possible match is made.
|
|
20
|
+
* @param matchType StringComparisonType
|
|
21
|
+
* @param itemInfo string | string[]
|
|
22
|
+
* @param possibleMatches string[]
|
|
23
|
+
* @returns boolean
|
|
24
|
+
*/
|
|
25
|
+
partialMatch(matchType: StringComparisonType.CONTAINS | StringComparisonType.START_WITH | StringComparisonType.END_WITH, itemInfo: string | string[], possibleMatches: string[]): boolean;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=Selector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Selector.d.ts","sourceRoot":"","sources":["../../src/common/Selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,oBAAY,SAAS;IACnB,KAAK,SAAS;IACd,QAAQ,YAAY;IACpB,SAAS,aAAa;IACtB,MAAM,UAAU;IAChB,UAAU,cAAc;CACzB;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC;IAClC,KAAK,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC;CAC7C,CAAC;AAEF,qBAAa,QAAS,YAAW,iBAAiB;IAChD,KAAK,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO;IACjC,KAAK,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO;IAK3C;;;;;;OAMG;IACH,YAAY,CACV,SAAS,EACL,oBAAoB,CAAC,QAAQ,GAC7B,oBAAoB,CAAC,UAAU,GAC/B,oBAAoB,CAAC,QAAQ,EACjC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,EAC3B,eAAe,EAAE,MAAM,EAAE;CA4B5B"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Selector = exports.MatchType = void 0;
|
|
4
|
+
const Qualifier_1 = require("./Qualifier");
|
|
5
|
+
var MatchType;
|
|
6
|
+
(function (MatchType) {
|
|
7
|
+
MatchType["ALL"] = ":all";
|
|
8
|
+
MatchType["IS_ONE"] = ":is_one";
|
|
9
|
+
MatchType["NOT_ONE"] = ":not_one";
|
|
10
|
+
MatchType["DOES"] = ":does";
|
|
11
|
+
MatchType["DOES_NOT"] = ":does_not";
|
|
12
|
+
})(MatchType || (exports.MatchType = MatchType = {}));
|
|
13
|
+
class Selector {
|
|
14
|
+
match(subject) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Checks each member of the subject array for possible matches. Returns true when any possible match is made.
|
|
19
|
+
* @param matchType StringComparisonType
|
|
20
|
+
* @param itemInfo string | string[]
|
|
21
|
+
* @param possibleMatches string[]
|
|
22
|
+
* @returns boolean
|
|
23
|
+
*/
|
|
24
|
+
partialMatch(matchType, itemInfo, possibleMatches) {
|
|
25
|
+
// Convert to an array if it isn't one
|
|
26
|
+
const subject = Array.isArray(itemInfo)
|
|
27
|
+
? itemInfo
|
|
28
|
+
: [itemInfo];
|
|
29
|
+
let foundMatch = false;
|
|
30
|
+
possibleMatches.forEach((possibility) => {
|
|
31
|
+
subject.forEach((search) => {
|
|
32
|
+
switch (matchType) {
|
|
33
|
+
case Qualifier_1.StringComparisonType.CONTAINS:
|
|
34
|
+
if (search.search(possibility) > -1)
|
|
35
|
+
foundMatch = true;
|
|
36
|
+
break;
|
|
37
|
+
case Qualifier_1.StringComparisonType.START_WITH:
|
|
38
|
+
if (search.startsWith(possibility))
|
|
39
|
+
foundMatch = true;
|
|
40
|
+
break;
|
|
41
|
+
case Qualifier_1.StringComparisonType.END_WITH:
|
|
42
|
+
if (search.endsWith(possibility))
|
|
43
|
+
foundMatch = true;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
return foundMatch;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.Selector = Selector;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MatchType, Selector } from './Selector';
|
|
2
|
+
export declare class SubscriptionItemSelector extends Selector {
|
|
3
|
+
invert: boolean;
|
|
4
|
+
constructor(matchType: MatchType);
|
|
5
|
+
match(subject: unknown): boolean;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=SubscriptionItemSelector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubscriptionItemSelector.d.ts","sourceRoot":"","sources":["../../src/common/SubscriptionItemSelector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEjD,qBAAa,wBAAyB,SAAQ,QAAQ;IACpD,MAAM,EAAE,OAAO,CAAC;gBAEJ,SAAS,EAAE,SAAS;IAKhC,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;CAWjC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SubscriptionItemSelector = void 0;
|
|
4
|
+
const Selector_1 = require("./Selector");
|
|
5
|
+
class SubscriptionItemSelector extends Selector_1.Selector {
|
|
6
|
+
invert;
|
|
7
|
+
constructor(matchType) {
|
|
8
|
+
super();
|
|
9
|
+
this.invert = matchType == Selector_1.MatchType.NOT_ONE;
|
|
10
|
+
}
|
|
11
|
+
match(lineItem) {
|
|
12
|
+
const matchResult = lineItem.sellingPlanAllocation !== undefined;
|
|
13
|
+
if (this.invert) {
|
|
14
|
+
return !matchResult;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.SubscriptionItemSelector = SubscriptionItemSelector;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=CampaignForm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CampaignForm.d.ts","sourceRoot":"","sources":["../../src/form/CampaignForm.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -1,38 +1,33 @@
|
|
|
1
1
|
export { ConditionalDiscount } from './lineItem/ConditionalDiscount';
|
|
2
|
-
export { FixedItemDiscount } from './lineItem/FixedItemDiscount';
|
|
3
|
-
export { PercentageDiscount } from './lineItem/PercentageDiscount';
|
|
4
|
-
export { AndSelector } from './common/AndSelector';
|
|
5
2
|
export { BuyXGetY } from './lineItem/BuyXGetY';
|
|
3
|
+
export { ShippingDiscount } from './shipping/ShippingDiscount';
|
|
6
4
|
export { Campaign } from './common/Campaign';
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from './common/CampaignConfiguration';
|
|
11
|
-
export {
|
|
12
|
-
CampaignFactory,
|
|
13
|
-
type InputConfig,
|
|
14
|
-
} from './common/CampaignFactory';
|
|
15
|
-
export { CartAmountQualifier } from './common/CartAmountQualifier';
|
|
16
|
-
export { CartHasItemQualifier } from './common/CartHasItemQualifier';
|
|
17
|
-
export { CartQuantityQualifier } from './common/CartQuantityQualifier';
|
|
18
|
-
export { CustomerEmailQualifier } from './common/CustomerEmailQualifier';
|
|
19
|
-
export { CustomerSubscriberQualifier } from './common/CustomerSubscriberQualifier';
|
|
20
|
-
export { CustomerTagQualifier } from './common/CustomerTagQualifier';
|
|
21
|
-
export { DiscountCart } from './common/DiscountCart';
|
|
5
|
+
export { FixedItemDiscount } from './lineItem/FixedItemDiscount';
|
|
6
|
+
export { PercentageDiscount } from './lineItem/PercentageDiscount';
|
|
7
|
+
export { FixedDiscount } from './shipping/FixedDiscount';
|
|
22
8
|
export type { DiscountInterface } from './common/DiscountInterface';
|
|
9
|
+
export { AndSelector } from './common/AndSelector';
|
|
23
10
|
export { OrSelector } from './common/OrSelector';
|
|
24
|
-
export {
|
|
11
|
+
export { Selector } from './common/Selector';
|
|
25
12
|
export { ProductHandleSelector } from './common/ProductHandleSelector';
|
|
26
13
|
export { ProductIdSelector } from './common/ProductIdSelector';
|
|
27
14
|
export { ProductTagSelector } from './common/ProductTagSelector';
|
|
28
15
|
export { ProductTypeSelector } from './common/ProductTypeSelector';
|
|
29
|
-
export {
|
|
30
|
-
Qualifier,
|
|
31
|
-
QualifierBehavior,
|
|
32
|
-
QualifierMatchType,
|
|
33
|
-
NumericalComparisonType,
|
|
34
|
-
StringComparisonType,
|
|
35
|
-
} from './common/Qualifier';
|
|
36
16
|
export { SaleItemSelector } from './common/SaleItemSelector';
|
|
37
|
-
export { Selector } from './common/Selector';
|
|
38
17
|
export { SubscriptionItemSelector } from './common/SubscriptionItemSelector';
|
|
18
|
+
export { RateNameSelector } from './shipping/RateNameSelector';
|
|
19
|
+
export { Qualifier, QualifierBehavior, QualifierMatchType, NumericalComparisonType, StringComparisonType, } from './common/Qualifier';
|
|
20
|
+
export { CartAmountQualifier } from './common/CartAmountQualifier';
|
|
21
|
+
export { CartHasItemQualifier } from './common/CartHasItemQualifier';
|
|
22
|
+
export { CartQuantityQualifier } from './common/CartQuantityQualifier';
|
|
23
|
+
export { CustomerEmailQualifier } from './common/CustomerEmailQualifier';
|
|
24
|
+
export { CustomerSubscriberQualifier } from './common/CustomerSubscriberQualifier';
|
|
25
|
+
export { CustomerTagQualifier } from './common/CustomerTagQualifier';
|
|
26
|
+
export { PostCartAmountQualifier } from './common/PostCartAmountQualifier';
|
|
27
|
+
export { CountryCodeQualifier } from './common/CountryCodeQualifier';
|
|
28
|
+
export { DiscountCart } from './common/DiscountCart';
|
|
29
|
+
export { CampaignFactory, type InputConfig, type CampaignInputConfig, } from './common/CampaignFactory';
|
|
30
|
+
export { ConfigValidator, type ValidationError, type ValidationResult, } from './common/ConfigValidator';
|
|
31
|
+
export { CampaignConfigSchema, QualifierBehaviorSchema, MatchTypeSchema, QualifierMatchTypeSchema, NumericalComparisonSchema, StringComparisonSchema, type CampaignConfigSchemaType, } from './common/ConfigSchema';
|
|
32
|
+
export type { CampaignType, CampaignConfiguration, } from './common/CampaignConfiguration';
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,YAAY,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAGpE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAG/D,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAGrE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EACL,eAAe,EACf,KAAK,WAAW,EAChB,KAAK,mBAAmB,GACzB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,eAAe,EACf,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EACtB,KAAK,wBAAwB,GAC9B,MAAM,uBAAuB,CAAC;AAG/B,YAAY,EACV,YAAY,EACZ,qBAAqB,GACtB,MAAM,gCAAgC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StringComparisonSchema = exports.NumericalComparisonSchema = exports.QualifierMatchTypeSchema = exports.MatchTypeSchema = exports.QualifierBehaviorSchema = exports.CampaignConfigSchema = exports.ConfigValidator = exports.CampaignFactory = exports.DiscountCart = exports.CountryCodeQualifier = exports.PostCartAmountQualifier = exports.CustomerTagQualifier = exports.CustomerSubscriberQualifier = exports.CustomerEmailQualifier = exports.CartQuantityQualifier = exports.CartHasItemQualifier = exports.CartAmountQualifier = exports.StringComparisonType = exports.NumericalComparisonType = exports.QualifierMatchType = exports.QualifierBehavior = exports.Qualifier = exports.RateNameSelector = exports.SubscriptionItemSelector = exports.SaleItemSelector = exports.ProductTypeSelector = exports.ProductTagSelector = exports.ProductIdSelector = exports.ProductHandleSelector = exports.Selector = exports.OrSelector = exports.AndSelector = exports.FixedDiscount = exports.PercentageDiscount = exports.FixedItemDiscount = exports.Campaign = exports.ShippingDiscount = exports.BuyXGetY = exports.ConditionalDiscount = void 0;
|
|
4
|
+
// Campaign Types
|
|
5
|
+
var ConditionalDiscount_1 = require("./lineItem/ConditionalDiscount");
|
|
6
|
+
Object.defineProperty(exports, "ConditionalDiscount", { enumerable: true, get: function () { return ConditionalDiscount_1.ConditionalDiscount; } });
|
|
7
|
+
var BuyXGetY_1 = require("./lineItem/BuyXGetY");
|
|
8
|
+
Object.defineProperty(exports, "BuyXGetY", { enumerable: true, get: function () { return BuyXGetY_1.BuyXGetY; } });
|
|
9
|
+
var ShippingDiscount_1 = require("./shipping/ShippingDiscount");
|
|
10
|
+
Object.defineProperty(exports, "ShippingDiscount", { enumerable: true, get: function () { return ShippingDiscount_1.ShippingDiscount; } });
|
|
11
|
+
var Campaign_1 = require("./common/Campaign");
|
|
12
|
+
Object.defineProperty(exports, "Campaign", { enumerable: true, get: function () { return Campaign_1.Campaign; } });
|
|
13
|
+
// Discount Types
|
|
14
|
+
var FixedItemDiscount_1 = require("./lineItem/FixedItemDiscount");
|
|
15
|
+
Object.defineProperty(exports, "FixedItemDiscount", { enumerable: true, get: function () { return FixedItemDiscount_1.FixedItemDiscount; } });
|
|
16
|
+
var PercentageDiscount_1 = require("./lineItem/PercentageDiscount");
|
|
17
|
+
Object.defineProperty(exports, "PercentageDiscount", { enumerable: true, get: function () { return PercentageDiscount_1.PercentageDiscount; } });
|
|
18
|
+
var FixedDiscount_1 = require("./shipping/FixedDiscount");
|
|
19
|
+
Object.defineProperty(exports, "FixedDiscount", { enumerable: true, get: function () { return FixedDiscount_1.FixedDiscount; } });
|
|
20
|
+
// Selectors
|
|
21
|
+
var AndSelector_1 = require("./common/AndSelector");
|
|
22
|
+
Object.defineProperty(exports, "AndSelector", { enumerable: true, get: function () { return AndSelector_1.AndSelector; } });
|
|
23
|
+
var OrSelector_1 = require("./common/OrSelector");
|
|
24
|
+
Object.defineProperty(exports, "OrSelector", { enumerable: true, get: function () { return OrSelector_1.OrSelector; } });
|
|
25
|
+
var Selector_1 = require("./common/Selector");
|
|
26
|
+
Object.defineProperty(exports, "Selector", { enumerable: true, get: function () { return Selector_1.Selector; } });
|
|
27
|
+
var ProductHandleSelector_1 = require("./common/ProductHandleSelector");
|
|
28
|
+
Object.defineProperty(exports, "ProductHandleSelector", { enumerable: true, get: function () { return ProductHandleSelector_1.ProductHandleSelector; } });
|
|
29
|
+
var ProductIdSelector_1 = require("./common/ProductIdSelector");
|
|
30
|
+
Object.defineProperty(exports, "ProductIdSelector", { enumerable: true, get: function () { return ProductIdSelector_1.ProductIdSelector; } });
|
|
31
|
+
var ProductTagSelector_1 = require("./common/ProductTagSelector");
|
|
32
|
+
Object.defineProperty(exports, "ProductTagSelector", { enumerable: true, get: function () { return ProductTagSelector_1.ProductTagSelector; } });
|
|
33
|
+
var ProductTypeSelector_1 = require("./common/ProductTypeSelector");
|
|
34
|
+
Object.defineProperty(exports, "ProductTypeSelector", { enumerable: true, get: function () { return ProductTypeSelector_1.ProductTypeSelector; } });
|
|
35
|
+
var SaleItemSelector_1 = require("./common/SaleItemSelector");
|
|
36
|
+
Object.defineProperty(exports, "SaleItemSelector", { enumerable: true, get: function () { return SaleItemSelector_1.SaleItemSelector; } });
|
|
37
|
+
var SubscriptionItemSelector_1 = require("./common/SubscriptionItemSelector");
|
|
38
|
+
Object.defineProperty(exports, "SubscriptionItemSelector", { enumerable: true, get: function () { return SubscriptionItemSelector_1.SubscriptionItemSelector; } });
|
|
39
|
+
var RateNameSelector_1 = require("./shipping/RateNameSelector");
|
|
40
|
+
Object.defineProperty(exports, "RateNameSelector", { enumerable: true, get: function () { return RateNameSelector_1.RateNameSelector; } });
|
|
41
|
+
// Qualifiers
|
|
42
|
+
var Qualifier_1 = require("./common/Qualifier");
|
|
43
|
+
Object.defineProperty(exports, "Qualifier", { enumerable: true, get: function () { return Qualifier_1.Qualifier; } });
|
|
44
|
+
Object.defineProperty(exports, "QualifierBehavior", { enumerable: true, get: function () { return Qualifier_1.QualifierBehavior; } });
|
|
45
|
+
Object.defineProperty(exports, "QualifierMatchType", { enumerable: true, get: function () { return Qualifier_1.QualifierMatchType; } });
|
|
46
|
+
Object.defineProperty(exports, "NumericalComparisonType", { enumerable: true, get: function () { return Qualifier_1.NumericalComparisonType; } });
|
|
47
|
+
Object.defineProperty(exports, "StringComparisonType", { enumerable: true, get: function () { return Qualifier_1.StringComparisonType; } });
|
|
48
|
+
var CartAmountQualifier_1 = require("./common/CartAmountQualifier");
|
|
49
|
+
Object.defineProperty(exports, "CartAmountQualifier", { enumerable: true, get: function () { return CartAmountQualifier_1.CartAmountQualifier; } });
|
|
50
|
+
var CartHasItemQualifier_1 = require("./common/CartHasItemQualifier");
|
|
51
|
+
Object.defineProperty(exports, "CartHasItemQualifier", { enumerable: true, get: function () { return CartHasItemQualifier_1.CartHasItemQualifier; } });
|
|
52
|
+
var CartQuantityQualifier_1 = require("./common/CartQuantityQualifier");
|
|
53
|
+
Object.defineProperty(exports, "CartQuantityQualifier", { enumerable: true, get: function () { return CartQuantityQualifier_1.CartQuantityQualifier; } });
|
|
54
|
+
var CustomerEmailQualifier_1 = require("./common/CustomerEmailQualifier");
|
|
55
|
+
Object.defineProperty(exports, "CustomerEmailQualifier", { enumerable: true, get: function () { return CustomerEmailQualifier_1.CustomerEmailQualifier; } });
|
|
56
|
+
var CustomerSubscriberQualifier_1 = require("./common/CustomerSubscriberQualifier");
|
|
57
|
+
Object.defineProperty(exports, "CustomerSubscriberQualifier", { enumerable: true, get: function () { return CustomerSubscriberQualifier_1.CustomerSubscriberQualifier; } });
|
|
58
|
+
var CustomerTagQualifier_1 = require("./common/CustomerTagQualifier");
|
|
59
|
+
Object.defineProperty(exports, "CustomerTagQualifier", { enumerable: true, get: function () { return CustomerTagQualifier_1.CustomerTagQualifier; } });
|
|
60
|
+
var PostCartAmountQualifier_1 = require("./common/PostCartAmountQualifier");
|
|
61
|
+
Object.defineProperty(exports, "PostCartAmountQualifier", { enumerable: true, get: function () { return PostCartAmountQualifier_1.PostCartAmountQualifier; } });
|
|
62
|
+
var CountryCodeQualifier_1 = require("./common/CountryCodeQualifier");
|
|
63
|
+
Object.defineProperty(exports, "CountryCodeQualifier", { enumerable: true, get: function () { return CountryCodeQualifier_1.CountryCodeQualifier; } });
|
|
64
|
+
// Core Utilities
|
|
65
|
+
var DiscountCart_1 = require("./common/DiscountCart");
|
|
66
|
+
Object.defineProperty(exports, "DiscountCart", { enumerable: true, get: function () { return DiscountCart_1.DiscountCart; } });
|
|
67
|
+
var CampaignFactory_1 = require("./common/CampaignFactory");
|
|
68
|
+
Object.defineProperty(exports, "CampaignFactory", { enumerable: true, get: function () { return CampaignFactory_1.CampaignFactory; } });
|
|
69
|
+
// Configuration & Validation (for UI apps)
|
|
70
|
+
var ConfigValidator_1 = require("./common/ConfigValidator");
|
|
71
|
+
Object.defineProperty(exports, "ConfigValidator", { enumerable: true, get: function () { return ConfigValidator_1.ConfigValidator; } });
|
|
72
|
+
var ConfigSchema_1 = require("./common/ConfigSchema");
|
|
73
|
+
Object.defineProperty(exports, "CampaignConfigSchema", { enumerable: true, get: function () { return ConfigSchema_1.CampaignConfigSchema; } });
|
|
74
|
+
Object.defineProperty(exports, "QualifierBehaviorSchema", { enumerable: true, get: function () { return ConfigSchema_1.QualifierBehaviorSchema; } });
|
|
75
|
+
Object.defineProperty(exports, "MatchTypeSchema", { enumerable: true, get: function () { return ConfigSchema_1.MatchTypeSchema; } });
|
|
76
|
+
Object.defineProperty(exports, "QualifierMatchTypeSchema", { enumerable: true, get: function () { return ConfigSchema_1.QualifierMatchTypeSchema; } });
|
|
77
|
+
Object.defineProperty(exports, "NumericalComparisonSchema", { enumerable: true, get: function () { return ConfigSchema_1.NumericalComparisonSchema; } });
|
|
78
|
+
Object.defineProperty(exports, "StringComparisonSchema", { enumerable: true, get: function () { return ConfigSchema_1.StringComparisonSchema; } });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Campaign } from '../common/Campaign';
|
|
2
|
+
import type { AndSelector } from '../common/AndSelector';
|
|
3
|
+
import type { DiscountCart } from '../common/DiscountCart';
|
|
4
|
+
import type { DiscountInterface } from '../common/DiscountInterface';
|
|
5
|
+
import type { OrSelector } from '../common/OrSelector';
|
|
6
|
+
import type { Qualifier, QualifierBehavior } from '../common/Qualifier';
|
|
7
|
+
import type { Selector } from '../common/Selector';
|
|
8
|
+
export declare class BuyXGetY extends Campaign {
|
|
9
|
+
lineItemSelector?: Selector;
|
|
10
|
+
getItemSelector?: Selector;
|
|
11
|
+
discount: DiscountInterface;
|
|
12
|
+
buyX: number;
|
|
13
|
+
getY: number;
|
|
14
|
+
maxSets?: number;
|
|
15
|
+
constructor(behavior: QualifierBehavior, conditions: [AndSelector | OrSelector | Qualifier], discount: DiscountInterface, buyItemSelector: Selector, getItemSelector: Selector, buyX: number, getY: number, maxSets?: number);
|
|
16
|
+
run(discountCart: DiscountCart): DiscountCart;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=BuyXGetY.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuyXGetY.d.ts","sourceRoot":"","sources":["../../src/lineItem/BuyXGetY.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAEV,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EACV,SAAS,EACT,iBAAiB,EAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,qBAAa,QAAS,SAAQ,QAAQ;IACpC,gBAAgB,CAAC,EAAE,QAAQ,CAAC;IAC5B,eAAe,CAAC,EAAE,QAAQ,CAAC;IAC3B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;gBAGf,QAAQ,EAAE,iBAAiB,EAC3B,UAAU,EAAE,CAAC,WAAW,GAAG,UAAU,GAAG,SAAS,CAAC,EAClD,QAAQ,EAAE,iBAAiB,EAC3B,eAAe,EAAE,QAAQ,EACzB,eAAe,EAAE,QAAQ,EACzB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM;IAWlB,GAAG,CAAC,YAAY,EAAE,YAAY;CAyF/B"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BuyXGetY = void 0;
|
|
4
|
+
const Campaign_1 = require("../common/Campaign");
|
|
5
|
+
class BuyXGetY extends Campaign_1.Campaign {
|
|
6
|
+
lineItemSelector;
|
|
7
|
+
getItemSelector;
|
|
8
|
+
discount;
|
|
9
|
+
buyX;
|
|
10
|
+
getY;
|
|
11
|
+
maxSets;
|
|
12
|
+
constructor(behavior, conditions, discount, buyItemSelector, getItemSelector, buyX, getY, maxSets) {
|
|
13
|
+
super(behavior, conditions);
|
|
14
|
+
this.lineItemSelector = buyItemSelector;
|
|
15
|
+
this.getItemSelector = getItemSelector;
|
|
16
|
+
this.discount = discount;
|
|
17
|
+
this.buyX = buyX;
|
|
18
|
+
this.getY = getY;
|
|
19
|
+
this.maxSets = maxSets;
|
|
20
|
+
}
|
|
21
|
+
run(discountCart) {
|
|
22
|
+
if (this.qualifies(discountCart)) {
|
|
23
|
+
// Find the items that qualify for buyX
|
|
24
|
+
let applicableBuyItems = discountCart.cart.lines;
|
|
25
|
+
if (this.lineItemSelector) {
|
|
26
|
+
const selector = this.lineItemSelector;
|
|
27
|
+
applicableBuyItems = discountCart.cart.lines.filter((lineItem) => {
|
|
28
|
+
return selector.match(lineItem);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (applicableBuyItems.reduce((qty, item) => (qty += item.quantity), 0) < this.buyX) {
|
|
32
|
+
return discountCart;
|
|
33
|
+
}
|
|
34
|
+
// Find the items that qualify for getX
|
|
35
|
+
let eligibleGetItems = discountCart.cart.lines;
|
|
36
|
+
if (this.getItemSelector) {
|
|
37
|
+
const selector = this.getItemSelector;
|
|
38
|
+
eligibleGetItems = discountCart.cart.lines.filter((lineItem) => {
|
|
39
|
+
return selector.match(lineItem);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
// Check if cart qualifies for discounts and limit the discount sets
|
|
43
|
+
const purchasedQuantity = applicableBuyItems.reduce((total, item) => (total += item.quantity), 0);
|
|
44
|
+
const discountableSets = this.maxSets
|
|
45
|
+
? [
|
|
46
|
+
purchasedQuantity / this.buyX,
|
|
47
|
+
this.maxSets,
|
|
48
|
+
].sort((a, b) => a - b)[0]
|
|
49
|
+
: Math.floor(purchasedQuantity / this.buyX);
|
|
50
|
+
if (discountableSets > 0) {
|
|
51
|
+
let discountableQuantity = discountableSets *
|
|
52
|
+
(this.getY
|
|
53
|
+
? this.getY
|
|
54
|
+
: discountCart.totalLineItemQuantity());
|
|
55
|
+
// Apply the discounts (sort to discount lower priced items first)
|
|
56
|
+
eligibleGetItems = eligibleGetItems.sort((item) => item.cost.amountPerQuantity.amount);
|
|
57
|
+
const itemsToApplyDiscounts = [];
|
|
58
|
+
eligibleGetItems.forEach((lineItem) => {
|
|
59
|
+
if (discountableQuantity == 0) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (lineItem.quantity <= discountableQuantity) {
|
|
63
|
+
itemsToApplyDiscounts.push({
|
|
64
|
+
lineItem,
|
|
65
|
+
});
|
|
66
|
+
discountableQuantity -= lineItem.quantity;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
itemsToApplyDiscounts.push({
|
|
70
|
+
lineItem,
|
|
71
|
+
maxDiscounts: discountableQuantity,
|
|
72
|
+
});
|
|
73
|
+
discountableQuantity = 0;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
if (itemsToApplyDiscounts.length) {
|
|
77
|
+
const discount = this.discount.apply(itemsToApplyDiscounts);
|
|
78
|
+
discountCart.addDiscount(discount);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return discountCart;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.BuyXGetY = BuyXGetY;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Campaign } from '../common/Campaign';
|
|
2
|
+
import type { DiscountCart } from '../common/DiscountCart';
|
|
3
|
+
import type { DiscountInterface } from '../common/DiscountInterface';
|
|
4
|
+
import type { QualifierBehavior, Qualifier } from '../common/Qualifier';
|
|
5
|
+
import type { Selector } from '../common/Selector';
|
|
6
|
+
import type { AndSelector } from '../common/AndSelector';
|
|
7
|
+
import type { OrSelector } from '../common/OrSelector';
|
|
8
|
+
export declare class ConditionalDiscount extends Campaign {
|
|
9
|
+
discount: DiscountInterface;
|
|
10
|
+
itemsToDiscount?: number;
|
|
11
|
+
constructor(behavior: QualifierBehavior, qualifiers: [Qualifier | AndSelector | OrSelector], discount: DiscountInterface, lineItemSelector?: Selector, maxDiscounts?: number);
|
|
12
|
+
run(discountCart: DiscountCart): DiscountCart;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=ConditionalDiscount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConditionalDiscount.d.ts","sourceRoot":"","sources":["../../src/lineItem/ConditionalDiscount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAEV,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EACV,iBAAiB,EACjB,SAAS,EACV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,qBAAa,mBAAoB,SAAQ,QAAQ;IAC/C,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;gBAGvB,QAAQ,EAAE,iBAAiB,EAC3B,UAAU,EAAE,CAAC,SAAS,GAAG,WAAW,GAAG,UAAU,CAAC,EAClD,QAAQ,EAAE,iBAAiB,EAC3B,gBAAgB,CAAC,EAAE,QAAQ,EAC3B,YAAY,CAAC,EAAE,MAAM;IASvB,GAAG,CAAC,YAAY,EAAE,YAAY;CAuE/B"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConditionalDiscount = void 0;
|
|
4
|
+
const Campaign_1 = require("../common/Campaign");
|
|
5
|
+
class ConditionalDiscount extends Campaign_1.Campaign {
|
|
6
|
+
discount;
|
|
7
|
+
itemsToDiscount;
|
|
8
|
+
constructor(behavior, qualifiers, discount, lineItemSelector, maxDiscounts) {
|
|
9
|
+
super(behavior, qualifiers);
|
|
10
|
+
this.discount = discount;
|
|
11
|
+
this.lineItemSelector = lineItemSelector;
|
|
12
|
+
this.itemsToDiscount =
|
|
13
|
+
maxDiscounts == 0 ? undefined : maxDiscounts;
|
|
14
|
+
}
|
|
15
|
+
run(discountCart) {
|
|
16
|
+
// First we see if this cart qualifies for this discount
|
|
17
|
+
if (this.qualifies(discountCart)) {
|
|
18
|
+
// Now that it qualifies, we can determine the applicableLineItems
|
|
19
|
+
// to apply discounts to
|
|
20
|
+
// figure out applicable lineItems...
|
|
21
|
+
const applicableLineItems = discountCart.cart.lines
|
|
22
|
+
.filter((lineItem) => {
|
|
23
|
+
if (this.lineItemSelector === undefined) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
return this.lineItemSelector.match(lineItem);
|
|
27
|
+
})
|
|
28
|
+
.sort((a, b) => {
|
|
29
|
+
const priceA = a.cost.amountPerQuantity
|
|
30
|
+
.amount;
|
|
31
|
+
const priceB = b.cost.amountPerQuantity
|
|
32
|
+
.amount;
|
|
33
|
+
if (priceA < priceB)
|
|
34
|
+
return -1;
|
|
35
|
+
if (priceA == priceB)
|
|
36
|
+
return 0;
|
|
37
|
+
return 1;
|
|
38
|
+
});
|
|
39
|
+
const itemsToApplyDiscounts = [];
|
|
40
|
+
// Use a local variable to avoid mutating the instance property
|
|
41
|
+
let remainingDiscounts = this.itemsToDiscount;
|
|
42
|
+
// Loop over the applicable line items and deduct the itemsToDiscount count
|
|
43
|
+
// as they are applied to not exceed a maximum.
|
|
44
|
+
applicableLineItems.forEach((lineItem) => {
|
|
45
|
+
// If there are no more items to discount, return/skip
|
|
46
|
+
if (remainingDiscounts === 0)
|
|
47
|
+
return;
|
|
48
|
+
// If items to discount is not undefined, apply as many as possible
|
|
49
|
+
if (remainingDiscounts !== undefined) {
|
|
50
|
+
// There are more than enough qty to apply, apply the maximum
|
|
51
|
+
if (lineItem.quantity >= remainingDiscounts) {
|
|
52
|
+
itemsToApplyDiscounts.push({
|
|
53
|
+
lineItem,
|
|
54
|
+
maxDiscounts: remainingDiscounts,
|
|
55
|
+
});
|
|
56
|
+
remainingDiscounts = 0;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
itemsToApplyDiscounts.push({
|
|
60
|
+
lineItem,
|
|
61
|
+
});
|
|
62
|
+
remainingDiscounts -= lineItem.quantity;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// items to discount is undefined, so apply to entire item count
|
|
67
|
+
itemsToApplyDiscounts.push({
|
|
68
|
+
lineItem,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
if (itemsToApplyDiscounts.length) {
|
|
73
|
+
// append the discount to the discountCart singleton
|
|
74
|
+
const discount = this.discount.apply(itemsToApplyDiscounts);
|
|
75
|
+
discountCart.addDiscount(discount);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return discountCart;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.ConditionalDiscount = ConditionalDiscount;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ApplyDiscount, Discount, DiscountInterface } from '../common/DiscountInterface';
|
|
2
|
+
export declare class FixedItemDiscount implements DiscountInterface {
|
|
3
|
+
amount: number;
|
|
4
|
+
appliesToEachItem: boolean;
|
|
5
|
+
message: string;
|
|
6
|
+
constructor(amount: number, appliesToEachItem: boolean, message: string);
|
|
7
|
+
apply(items: ApplyDiscount[]): Discount;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=FixedItemDiscount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FixedItemDiscount.d.ts","sourceRoot":"","sources":["../../src/lineItem/FixedItemDiscount.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EACb,QAAQ,EACR,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AAErC,qBAAa,iBACX,YAAW,iBAAiB;IAE5B,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,EAAE,OAAO,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;gBAGd,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,OAAO,EAC1B,OAAO,EAAE,MAAM;IAOjB,KAAK,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,QAAQ;CA0BxC"}
|