@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,16 @@
|
|
|
1
|
+
import type { DiscountCart } from './DiscountCart';
|
|
2
|
+
import { StringComparisonType, QualifierMatchType, Qualifier } from './Qualifier';
|
|
3
|
+
import { type Selector } from './Selector';
|
|
4
|
+
export declare class CustomerEmailQualifier extends Qualifier {
|
|
5
|
+
invert: boolean;
|
|
6
|
+
matchCondition: StringComparisonType;
|
|
7
|
+
emails: string[];
|
|
8
|
+
constructor(matchType: QualifierMatchType, matchCondition: StringComparisonType, emails: string[]);
|
|
9
|
+
/**
|
|
10
|
+
* Determines if the customer's email matches
|
|
11
|
+
* @param discountCart DiscountCart
|
|
12
|
+
* @param selector Selector
|
|
13
|
+
*/
|
|
14
|
+
match(discountCart: DiscountCart, selector?: Selector): boolean;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=CustomerEmailQualifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomerEmailQualifier.d.ts","sourceRoot":"","sources":["../../src/common/CustomerEmailQualifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,SAAS,EACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,qBAAa,sBAAuB,SAAQ,SAAS;IACnD,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,EAAE,oBAAoB,CAAC;IACrC,MAAM,EAAE,MAAM,EAAE,CAAC;gBAGf,SAAS,EAAE,kBAAkB,EAC7B,cAAc,EAAE,oBAAoB,EACpC,MAAM,EAAE,MAAM,EAAE;IAQlB;;;;OAIG;IACH,KAAK,CAAC,YAAY,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,QAAQ;CAqCtD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomerEmailQualifier = void 0;
|
|
4
|
+
const Qualifier_1 = require("./Qualifier");
|
|
5
|
+
class CustomerEmailQualifier extends Qualifier_1.Qualifier {
|
|
6
|
+
invert;
|
|
7
|
+
matchCondition;
|
|
8
|
+
emails;
|
|
9
|
+
constructor(matchType, matchCondition, emails) {
|
|
10
|
+
super();
|
|
11
|
+
this.invert = matchType == Qualifier_1.QualifierMatchType.DOES_NOT;
|
|
12
|
+
this.matchCondition = matchCondition;
|
|
13
|
+
this.emails = emails.map((e) => e.toLowerCase());
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Determines if the customer's email matches
|
|
17
|
+
* @param discountCart DiscountCart
|
|
18
|
+
* @param selector Selector
|
|
19
|
+
*/
|
|
20
|
+
match(discountCart, selector) {
|
|
21
|
+
if (!discountCart.cart.buyerIdentity?.customer?.email) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
let matchResult = false;
|
|
25
|
+
const email = discountCart.cart.buyerIdentity.customer.email.toLowerCase();
|
|
26
|
+
switch (this.matchCondition) {
|
|
27
|
+
case Qualifier_1.StringComparisonType.MATCH:
|
|
28
|
+
matchResult = this.emails.includes(email);
|
|
29
|
+
break;
|
|
30
|
+
case Qualifier_1.StringComparisonType.CONTAINS:
|
|
31
|
+
matchResult =
|
|
32
|
+
this.emails.filter((e) => email.includes(e))
|
|
33
|
+
.length > 0;
|
|
34
|
+
break;
|
|
35
|
+
case Qualifier_1.StringComparisonType.START_WITH:
|
|
36
|
+
matchResult =
|
|
37
|
+
this.emails.filter((e) => email.startsWith(e))
|
|
38
|
+
.length > 0;
|
|
39
|
+
break;
|
|
40
|
+
case Qualifier_1.StringComparisonType.END_WITH:
|
|
41
|
+
matchResult =
|
|
42
|
+
this.emails.filter((e) => email.endsWith(e))
|
|
43
|
+
.length > 0;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
if (this.invert) {
|
|
47
|
+
return !matchResult;
|
|
48
|
+
}
|
|
49
|
+
return matchResult;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.CustomerEmailQualifier = CustomerEmailQualifier;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DiscountCart } from "./DiscountCart";
|
|
2
|
+
import { QualifierMatchType, Qualifier } from "./Qualifier";
|
|
3
|
+
import { type Selector } from "./Selector";
|
|
4
|
+
export declare class CustomerSubscriberQualifier extends Qualifier {
|
|
5
|
+
invert: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Whether the customer contains an active subscription or not.
|
|
8
|
+
* @param matchType Pass :DOES or :DOES_NOT respectively
|
|
9
|
+
*/
|
|
10
|
+
constructor(matchType: QualifierMatchType);
|
|
11
|
+
/**
|
|
12
|
+
* Determines if the customer has specified tags
|
|
13
|
+
* @param discountCart DiscountCart
|
|
14
|
+
* @param selector Selector
|
|
15
|
+
*/
|
|
16
|
+
match(discountCart: DiscountCart, selector?: Selector): boolean;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=CustomerSubscriberQualifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomerSubscriberQualifier.d.ts","sourceRoot":"","sources":["../../src/common/CustomerSubscriberQualifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,qBAAa,2BAA4B,SAAQ,SAAS;IACxD,MAAM,EAAE,OAAO,CAAC;IAEhB;;;OAGG;gBACS,SAAS,EAAE,kBAAkB;IAKzC;;;;OAIG;IACH,KAAK,CAAC,YAAY,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,QAAQ;CAUtD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomerSubscriberQualifier = void 0;
|
|
4
|
+
const Qualifier_1 = require("./Qualifier");
|
|
5
|
+
class CustomerSubscriberQualifier extends Qualifier_1.Qualifier {
|
|
6
|
+
invert;
|
|
7
|
+
/**
|
|
8
|
+
* Whether the customer contains an active subscription or not.
|
|
9
|
+
* @param matchType Pass :DOES or :DOES_NOT respectively
|
|
10
|
+
*/
|
|
11
|
+
constructor(matchType) {
|
|
12
|
+
super();
|
|
13
|
+
this.invert = matchType == Qualifier_1.QualifierMatchType.DOES_NOT;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Determines if the customer has specified tags
|
|
17
|
+
* @param discountCart DiscountCart
|
|
18
|
+
* @param selector Selector
|
|
19
|
+
*/
|
|
20
|
+
match(discountCart, selector) {
|
|
21
|
+
const matchResult = discountCart.cart.buyerIdentity?.customer?.isActiveSubscriber || false;
|
|
22
|
+
if (this.invert) {
|
|
23
|
+
return !matchResult;
|
|
24
|
+
}
|
|
25
|
+
return matchResult;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.CustomerSubscriberQualifier = CustomerSubscriberQualifier;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DiscountCart } from './DiscountCart';
|
|
2
|
+
import { StringComparisonType, QualifierMatchType, Qualifier } from './Qualifier';
|
|
3
|
+
import { type Selector } from './Selector';
|
|
4
|
+
export declare class CustomerTagQualifier extends Qualifier {
|
|
5
|
+
invert: boolean;
|
|
6
|
+
matchCondition: StringComparisonType;
|
|
7
|
+
tags: string[];
|
|
8
|
+
constructor(matchType: QualifierMatchType, matchCondition: StringComparisonType, tags: string[]);
|
|
9
|
+
/**
|
|
10
|
+
* Determines if the customer has specified tags
|
|
11
|
+
* @param discountCart DiscountCart
|
|
12
|
+
* @param selector Selector
|
|
13
|
+
*/
|
|
14
|
+
match(discountCart: DiscountCart, selector?: Selector): boolean;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=CustomerTagQualifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomerTagQualifier.d.ts","sourceRoot":"","sources":["../../src/common/CustomerTagQualifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACL,oBAAoB,EACpB,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,cAAc,EAAE,oBAAoB,CAAC;IACrC,IAAI,EAAE,MAAM,EAAE,CAAC;gBAGb,SAAS,EAAE,kBAAkB,EAC7B,cAAc,EAAE,oBAAoB,EACpC,IAAI,EAAE,MAAM,EAAE;IAQhB;;;;OAIG;IACH,KAAK,CAAC,YAAY,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,QAAQ;CAuCtD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomerTagQualifier = void 0;
|
|
4
|
+
const Qualifier_1 = require("./Qualifier");
|
|
5
|
+
class CustomerTagQualifier extends Qualifier_1.Qualifier {
|
|
6
|
+
invert;
|
|
7
|
+
matchCondition;
|
|
8
|
+
tags;
|
|
9
|
+
constructor(matchType, matchCondition, tags) {
|
|
10
|
+
super();
|
|
11
|
+
this.invert = matchType == Qualifier_1.QualifierMatchType.DOES_NOT;
|
|
12
|
+
this.matchCondition = matchCondition;
|
|
13
|
+
this.tags = tags.map((e) => e.toLowerCase());
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Determines if the customer has specified tags
|
|
17
|
+
* @param discountCart DiscountCart
|
|
18
|
+
* @param selector Selector
|
|
19
|
+
*/
|
|
20
|
+
match(discountCart, selector) {
|
|
21
|
+
const matchResult = (discountCart.cart.buyerIdentity?.customer?.hasTags.filter((t) => {
|
|
22
|
+
if (t.hasTag) {
|
|
23
|
+
const tag = t.tag.toLowerCase();
|
|
24
|
+
switch (this.matchCondition) {
|
|
25
|
+
case Qualifier_1.StringComparisonType.MATCH:
|
|
26
|
+
return this.tags.includes(tag);
|
|
27
|
+
case Qualifier_1.StringComparisonType.CONTAINS:
|
|
28
|
+
return (this.tags.filter((e) => tag.includes(e))
|
|
29
|
+
.length > 0);
|
|
30
|
+
case Qualifier_1.StringComparisonType.START_WITH:
|
|
31
|
+
return (this.tags.filter((e) => tag.startsWith(e)).length > 0);
|
|
32
|
+
case Qualifier_1.StringComparisonType.END_WITH:
|
|
33
|
+
return (this.tags.filter((e) => tag.endsWith(e))
|
|
34
|
+
.length > 0);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}) || []).length > 0;
|
|
39
|
+
if (this.invert) {
|
|
40
|
+
return !matchResult;
|
|
41
|
+
}
|
|
42
|
+
return matchResult;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.CustomerTagQualifier = CustomerTagQualifier;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RunInput as LineItemRunInput, Discount as DiscountItem } from '../lineItem/api';
|
|
2
|
+
import type { RunInput as ShippingRunInput, Discount as DiscountShipping } from '../shipping/api';
|
|
3
|
+
import { Discount } from './DiscountInterface';
|
|
4
|
+
type RunInput = {
|
|
5
|
+
cart: LineItemRunInput['cart'] & ShippingRunInput['cart'];
|
|
6
|
+
};
|
|
7
|
+
export declare class DiscountCart {
|
|
8
|
+
cart: RunInput['cart'];
|
|
9
|
+
subtotalAmount: number;
|
|
10
|
+
appliedDiscountTotal: number;
|
|
11
|
+
discounts: Discount[];
|
|
12
|
+
constructor(cart: RunInput['cart']);
|
|
13
|
+
subtotalExcludingVariants(variants: string[]): number;
|
|
14
|
+
private subtotalExcludingGifts;
|
|
15
|
+
totalLineItemQuantity(): number;
|
|
16
|
+
totalLineItemQuantityExcludingGifts(): number;
|
|
17
|
+
private setupCart;
|
|
18
|
+
addShippingDiscount(discount: DiscountShipping): void;
|
|
19
|
+
addDiscount(discount: DiscountItem): void;
|
|
20
|
+
reset(): void;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=DiscountCart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DiscountCart.d.ts","sourceRoot":"","sources":["../../src/common/DiscountCart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,IAAI,gBAAgB,EAC5B,QAAQ,IAAI,YAAY,EACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EACV,QAAQ,IAAI,gBAAgB,EAC5B,QAAQ,IAAI,gBAAgB,EAC7B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,KAAK,QAAQ,GAAG;IACd,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;CAC3D,CAAC;AAEF,qBAAa,YAAY;IACvB,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,SAAS,EAAE,QAAQ,EAAE,CAAC;gBAEV,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC;IASlC,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE;IAY5C,OAAO,CAAC,sBAAsB;IAgB9B,qBAAqB;IAIrB,mCAAmC;IAenC,OAAO,CAAC,SAAS;IAQjB,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB;IAI9C,WAAW,CAAC,QAAQ,EAAE,YAAY;IA8ClC,KAAK;CAGN"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DiscountCart = void 0;
|
|
4
|
+
class DiscountCart {
|
|
5
|
+
cart;
|
|
6
|
+
subtotalAmount;
|
|
7
|
+
appliedDiscountTotal;
|
|
8
|
+
discounts;
|
|
9
|
+
constructor(cart) {
|
|
10
|
+
this.cart = cart;
|
|
11
|
+
this.subtotalAmount = 0;
|
|
12
|
+
this.appliedDiscountTotal = 0;
|
|
13
|
+
this.discounts = [];
|
|
14
|
+
this.setupCart(cart);
|
|
15
|
+
}
|
|
16
|
+
subtotalExcludingVariants(variants) {
|
|
17
|
+
return this.cart.lines.reduce((prev, curr) => {
|
|
18
|
+
if (curr.merchandise.__typename == 'ProductVariant') {
|
|
19
|
+
if (variants.indexOf(curr.merchandise.id) > -1) {
|
|
20
|
+
return prev - curr.cost.subtotalAmount.amount;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return prev;
|
|
24
|
+
}, this.subtotalExcludingGifts());
|
|
25
|
+
}
|
|
26
|
+
subtotalExcludingGifts() {
|
|
27
|
+
return this.cart.lines.reduce((prev, curr) => {
|
|
28
|
+
if (curr.merchandise.__typename == 'ProductVariant') {
|
|
29
|
+
if (curr.merchandise.product.hasTags.filter((t) => t.hasTag && t.tag == 'meta-exclude-gift').length) {
|
|
30
|
+
return prev - curr.cost.subtotalAmount.amount;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return prev;
|
|
34
|
+
}, this.subtotalAmount);
|
|
35
|
+
}
|
|
36
|
+
totalLineItemQuantity() {
|
|
37
|
+
return this.cart.lines.reduce((total, item) => total + item.quantity, 0);
|
|
38
|
+
}
|
|
39
|
+
totalLineItemQuantityExcludingGifts() {
|
|
40
|
+
return this.cart.lines.reduce((total, item) => {
|
|
41
|
+
if (item.merchandise.__typename == 'ProductVariant') {
|
|
42
|
+
if (item.merchandise.product.hasTags.filter((t) => t.hasTag && t.tag == 'meta-exclude-gift').length) {
|
|
43
|
+
return total;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return total + item.quantity;
|
|
47
|
+
}, 0);
|
|
48
|
+
}
|
|
49
|
+
setupCart(cart) {
|
|
50
|
+
this.subtotalAmount = cart.cost.subtotalAmount.amount;
|
|
51
|
+
// Adjust the subtotal amount by excluding the value from gift items
|
|
52
|
+
this.subtotalAmount = this.subtotalExcludingGifts();
|
|
53
|
+
this.appliedDiscountTotal = 0;
|
|
54
|
+
this.discounts = [];
|
|
55
|
+
}
|
|
56
|
+
addShippingDiscount(discount) {
|
|
57
|
+
this.discounts.push(discount);
|
|
58
|
+
}
|
|
59
|
+
addDiscount(discount) {
|
|
60
|
+
// Figure out how much discount has been applied
|
|
61
|
+
const totalDiscounts = discount.targets.reduce((total, target) => {
|
|
62
|
+
// gather target lineItem
|
|
63
|
+
const lineItems = this.cart.lines.filter((line) => line.merchandise.__typename == 'ProductVariant'
|
|
64
|
+
? line.merchandise.id == target.productVariant.id
|
|
65
|
+
: false);
|
|
66
|
+
// loop over the line items and do maths
|
|
67
|
+
lineItems.forEach((line) => {
|
|
68
|
+
let discountableItems = target.productVariant.quantity
|
|
69
|
+
? target.productVariant.quantity
|
|
70
|
+
: line.quantity;
|
|
71
|
+
const lineItemCost = parseFloat(line.cost.amountPerQuantity.amount);
|
|
72
|
+
// When it's a fixed amount, calculate the items per but only if it applies to each individual item...
|
|
73
|
+
if (discount.value.fixedAmount) {
|
|
74
|
+
if (discount.value.fixedAmount.appliesToEachItem) {
|
|
75
|
+
total +=
|
|
76
|
+
lineItemCost - discount.value.fixedAmount?.amount > 0
|
|
77
|
+
? discount.value.fixedAmount?.amount * discountableItems
|
|
78
|
+
: lineItemCost * discountableItems;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
total +=
|
|
82
|
+
lineItemCost - discount.value.fixedAmount?.amount > 0
|
|
83
|
+
? discount.value.fixedAmount?.amount
|
|
84
|
+
: lineItemCost;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else if (discount.value.percentage) {
|
|
88
|
+
total +=
|
|
89
|
+
lineItemCost *
|
|
90
|
+
(discount.value.percentage?.value / 100) *
|
|
91
|
+
discountableItems;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return total;
|
|
95
|
+
}, 0);
|
|
96
|
+
this.appliedDiscountTotal += totalDiscounts;
|
|
97
|
+
this.discounts.push(discount);
|
|
98
|
+
}
|
|
99
|
+
reset() {
|
|
100
|
+
this.setupCart(this.cart);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.DiscountCart = DiscountCart;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CartDeliveryOption, CartLine } from '../lineItem/api';
|
|
2
|
+
import type { Discount as DiscountItem } from '../lineItem/api';
|
|
3
|
+
import type { Discount as DiscountShipping } from '../shipping/api';
|
|
4
|
+
export type Discount = DiscountItem & DiscountShipping;
|
|
5
|
+
type ApplyLineItemDiscount = {
|
|
6
|
+
lineItem: CartLine;
|
|
7
|
+
maxDiscounts?: number;
|
|
8
|
+
};
|
|
9
|
+
type ApplyShippingDiscount = {
|
|
10
|
+
deliveryOption: CartDeliveryOption;
|
|
11
|
+
};
|
|
12
|
+
export type ApplyDiscount = ApplyLineItemDiscount & ApplyShippingDiscount;
|
|
13
|
+
export interface DiscountInterface {
|
|
14
|
+
apply(items: ApplyDiscount[]): Discount;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=DiscountInterface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DiscountInterface.d.ts","sourceRoot":"","sources":["../../src/common/DiscountInterface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,QAAQ,EACT,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,KAAK,EAAE,QAAQ,IAAI,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEpE,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,gBAAgB,CAAC;AAGvD,KAAK,qBAAqB,GAAG;IAC3B,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,cAAc,EAAE,kBAAkB,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,qBAAqB,GAC/C,qBAAqB,CAAC;AAExB,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,QAAQ,CAAC;CACzC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DiscountCart } from './DiscountCart';
|
|
2
|
+
import type { Qualifier } from './Qualifier';
|
|
3
|
+
import type { Selector } from './Selector';
|
|
4
|
+
import type { CartLine } from '../lineItem/api';
|
|
5
|
+
export declare class OrSelector {
|
|
6
|
+
is_a: 'OrSelector';
|
|
7
|
+
conditions: (Selector | Qualifier)[];
|
|
8
|
+
constructor(conditions: (Selector | Qualifier)[]);
|
|
9
|
+
match(item: CartLine | DiscountCart, selector?: Selector): boolean;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=OrSelector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OrSelector.d.ts","sourceRoot":"","sources":["../../src/common/OrSelector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,UAAU;IACrB,IAAI,EAAE,YAAY,CAAC;IACnB,UAAU,EAAE,CAAC,QAAQ,GAAG,SAAS,CAAC,EAAE,CAAC;gBAEzB,UAAU,EAAE,CAAC,QAAQ,GAAG,SAAS,CAAC,EAAE;IAKhD,KAAK,CACH,IAAI,EAAE,QAAQ,GAAG,YAAY,EAC7B,QAAQ,CAAC,EAAE,QAAQ;CAuBtB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OrSelector = void 0;
|
|
4
|
+
class OrSelector {
|
|
5
|
+
is_a;
|
|
6
|
+
conditions;
|
|
7
|
+
constructor(conditions) {
|
|
8
|
+
this.is_a = 'OrSelector';
|
|
9
|
+
this.conditions = conditions;
|
|
10
|
+
}
|
|
11
|
+
match(item, selector) {
|
|
12
|
+
try {
|
|
13
|
+
const conditionsResult = this.conditions
|
|
14
|
+
.map((condition) => {
|
|
15
|
+
if (selector) {
|
|
16
|
+
return condition.match(item, selector);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return condition.match(item);
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
.filter((result) => result === true);
|
|
23
|
+
return conditionsResult.length > 0;
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.OrSelector = OrSelector;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DiscountCart } from "./DiscountCart";
|
|
2
|
+
import { type NumericalComparisonType, Qualifier } from "./Qualifier";
|
|
3
|
+
export declare class PostCartAmountQualifier extends Qualifier {
|
|
4
|
+
comparisonType: NumericalComparisonType;
|
|
5
|
+
amount: number;
|
|
6
|
+
constructor(comparisonType: NumericalComparisonType, amount: number);
|
|
7
|
+
match(discountCart: DiscountCart): boolean;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=PostCartAmountQualifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PostCartAmountQualifier.d.ts","sourceRoot":"","sources":["../../src/common/PostCartAmountQualifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,KAAK,uBAAuB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEtE,qBAAa,uBAAwB,SAAQ,SAAS;IACpD,cAAc,EAAE,uBAAuB,CAAC;IACxC,MAAM,EAAE,MAAM,CAAC;gBAEH,cAAc,EAAE,uBAAuB,EAAE,MAAM,EAAE,MAAM;IAMnE,KAAK,CAAC,YAAY,EAAE,YAAY;CAOjC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PostCartAmountQualifier = void 0;
|
|
4
|
+
const Qualifier_1 = require("./Qualifier");
|
|
5
|
+
class PostCartAmountQualifier extends Qualifier_1.Qualifier {
|
|
6
|
+
comparisonType;
|
|
7
|
+
amount;
|
|
8
|
+
constructor(comparisonType, amount) {
|
|
9
|
+
super();
|
|
10
|
+
this.comparisonType = comparisonType;
|
|
11
|
+
this.amount = amount;
|
|
12
|
+
}
|
|
13
|
+
match(discountCart) {
|
|
14
|
+
return this.compareAmounts(discountCart.subtotalAmount - discountCart.appliedDiscountTotal, this.comparisonType, this.amount);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.PostCartAmountQualifier = PostCartAmountQualifier;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MatchType, Selector } from './Selector';
|
|
2
|
+
export declare class ProductHandleSelector extends Selector {
|
|
3
|
+
invert: boolean;
|
|
4
|
+
handles: string[];
|
|
5
|
+
constructor(matchType: MatchType, handles: string[]);
|
|
6
|
+
match(lineItem: unknown): boolean;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=ProductHandleSelector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProductHandleSelector.d.ts","sourceRoot":"","sources":["../../src/common/ProductHandleSelector.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEjD,qBAAa,qBAAsB,SAAQ,QAAQ;IACjD,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;gBAEN,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE;IAMnD,KAAK,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO;CAelC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProductHandleSelector = void 0;
|
|
4
|
+
const Selector_1 = require("./Selector");
|
|
5
|
+
class ProductHandleSelector extends Selector_1.Selector {
|
|
6
|
+
invert;
|
|
7
|
+
handles;
|
|
8
|
+
constructor(matchType, handles) {
|
|
9
|
+
super();
|
|
10
|
+
this.invert = matchType == Selector_1.MatchType.NOT_ONE;
|
|
11
|
+
this.handles = handles.map((t) => t.toLowerCase());
|
|
12
|
+
}
|
|
13
|
+
match(lineItem) {
|
|
14
|
+
const variant = lineItem.merchandise;
|
|
15
|
+
const matchResult = this.handles.indexOf(variant.product.handle.toLowerCase()) > -1;
|
|
16
|
+
if (this.invert) {
|
|
17
|
+
return !matchResult;
|
|
18
|
+
}
|
|
19
|
+
return matchResult;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.ProductHandleSelector = ProductHandleSelector;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MatchType, Selector } from './Selector';
|
|
2
|
+
export declare class ProductIdSelector extends Selector {
|
|
3
|
+
invert: boolean;
|
|
4
|
+
productIds: string[];
|
|
5
|
+
constructor(matchType: MatchType.IS_ONE | MatchType.NOT_ONE, productIds: string[]);
|
|
6
|
+
match(subject: unknown): boolean;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=ProductIdSelector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProductIdSelector.d.ts","sourceRoot":"","sources":["../../src/common/ProductIdSelector.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEjD,qBAAa,iBAAkB,SAAQ,QAAQ;IAC7C,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;gBAGnB,SAAS,EAAE,SAAS,CAAC,MAAM,GAAG,SAAS,CAAC,OAAO,EAC/C,UAAU,EAAE,MAAM,EAAE;IAOtB,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;CAcjC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProductIdSelector = void 0;
|
|
4
|
+
const Selector_1 = require("./Selector");
|
|
5
|
+
class ProductIdSelector extends Selector_1.Selector {
|
|
6
|
+
invert;
|
|
7
|
+
productIds;
|
|
8
|
+
constructor(matchType, productIds) {
|
|
9
|
+
super();
|
|
10
|
+
this.invert = matchType == Selector_1.MatchType.NOT_ONE;
|
|
11
|
+
this.productIds = productIds;
|
|
12
|
+
}
|
|
13
|
+
match(lineItem) {
|
|
14
|
+
const variant = lineItem.merchandise;
|
|
15
|
+
const matchResult = this.productIds.includes(variant.product.id);
|
|
16
|
+
if (this.invert) {
|
|
17
|
+
return !matchResult;
|
|
18
|
+
}
|
|
19
|
+
return matchResult;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.ProductIdSelector = ProductIdSelector;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Selector } from './Selector';
|
|
2
|
+
import { QualifierMatchType, StringComparisonType } from './Qualifier';
|
|
3
|
+
export declare class ProductTagSelector extends Selector {
|
|
4
|
+
invert: boolean;
|
|
5
|
+
matchCondition: StringComparisonType;
|
|
6
|
+
tags: string[];
|
|
7
|
+
constructor(matchType: QualifierMatchType, matchCondition: StringComparisonType, tags: string[]);
|
|
8
|
+
match(subject: unknown): boolean;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=ProductTagSelector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProductTagSelector.d.ts","sourceRoot":"","sources":["../../src/common/ProductTagSelector.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAErB,qBAAa,kBAAmB,SAAQ,QAAQ;IAC9C,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,EAAE,oBAAoB,CAAC;IACrC,IAAI,EAAE,MAAM,EAAE,CAAC;gBAGb,SAAS,EAAE,kBAAkB,EAC7B,cAAc,EAAE,oBAAoB,EACpC,IAAI,EAAE,MAAM,EAAE;IAQhB,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;CAoCjC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProductTagSelector = void 0;
|
|
4
|
+
const Selector_1 = require("./Selector");
|
|
5
|
+
const Qualifier_1 = require("./Qualifier");
|
|
6
|
+
class ProductTagSelector extends Selector_1.Selector {
|
|
7
|
+
invert;
|
|
8
|
+
matchCondition;
|
|
9
|
+
tags;
|
|
10
|
+
constructor(matchType, matchCondition, tags) {
|
|
11
|
+
super();
|
|
12
|
+
this.matchCondition = matchCondition;
|
|
13
|
+
this.invert = matchType == Qualifier_1.QualifierMatchType.DOES_NOT;
|
|
14
|
+
this.tags = tags.map((t) => t.toLowerCase());
|
|
15
|
+
}
|
|
16
|
+
match(lineItem) {
|
|
17
|
+
const variant = lineItem.merchandise;
|
|
18
|
+
const productTags = variant.product.hasTags.reduce((tags, t) => {
|
|
19
|
+
if (t.hasTag) {
|
|
20
|
+
tags.push(t.tag.toLowerCase());
|
|
21
|
+
}
|
|
22
|
+
return tags;
|
|
23
|
+
}, []);
|
|
24
|
+
let matchResult;
|
|
25
|
+
switch (this.matchCondition) {
|
|
26
|
+
case Qualifier_1.StringComparisonType.MATCH:
|
|
27
|
+
matchResult =
|
|
28
|
+
productTags.filter((tag) => this.tags.includes(tag)).length > 0;
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
matchResult = this.partialMatch(this.matchCondition, productTags, this.tags);
|
|
32
|
+
}
|
|
33
|
+
if (this.invert) {
|
|
34
|
+
return !matchResult;
|
|
35
|
+
}
|
|
36
|
+
return matchResult;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.ProductTagSelector = ProductTagSelector;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MatchType, Selector } from './Selector';
|
|
2
|
+
export declare class ProductTypeSelector extends Selector {
|
|
3
|
+
invert: boolean;
|
|
4
|
+
productTypes: string[];
|
|
5
|
+
constructor(matchType: MatchType, productTypes: string[]);
|
|
6
|
+
match(subject: unknown): boolean;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=ProductTypeSelector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProductTypeSelector.d.ts","sourceRoot":"","sources":["../../src/common/ProductTypeSelector.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEjD,qBAAa,mBAAoB,SAAQ,QAAQ;IAC/C,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,MAAM,EAAE,CAAC;gBAGrB,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,MAAM,EAAE;IASxB,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;CAkBjC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProductTypeSelector = void 0;
|
|
4
|
+
const Selector_1 = require("./Selector");
|
|
5
|
+
class ProductTypeSelector extends Selector_1.Selector {
|
|
6
|
+
invert;
|
|
7
|
+
productTypes;
|
|
8
|
+
constructor(matchType, productTypes) {
|
|
9
|
+
super();
|
|
10
|
+
this.invert = matchType == Selector_1.MatchType.NOT_ONE;
|
|
11
|
+
this.productTypes = productTypes.map((item) => item.toLowerCase());
|
|
12
|
+
}
|
|
13
|
+
match(lineItem) {
|
|
14
|
+
const variant = lineItem.merchandise;
|
|
15
|
+
if (variant.product.productType) {
|
|
16
|
+
const matchResult = this.productTypes.includes(variant.product.productType.toLowerCase());
|
|
17
|
+
if (this.invert) {
|
|
18
|
+
return !matchResult;
|
|
19
|
+
}
|
|
20
|
+
return matchResult;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.ProductTypeSelector = ProductTypeSelector;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DiscountCart } from './DiscountCart';
|
|
2
|
+
import type { Selector } from './Selector';
|
|
3
|
+
export declare enum QualifierMatchType {
|
|
4
|
+
DOES = ":does",
|
|
5
|
+
DOES_NOT = ":does_not"
|
|
6
|
+
}
|
|
7
|
+
export declare enum StringComparisonType {
|
|
8
|
+
MATCH = ":match",
|
|
9
|
+
CONTAINS = ":contains",
|
|
10
|
+
START_WITH = ":start_with",
|
|
11
|
+
END_WITH = ":end_with"
|
|
12
|
+
}
|
|
13
|
+
export declare enum NumericalComparisonType {
|
|
14
|
+
GREATER_THAN = ":greater_than",
|
|
15
|
+
GREATER_THAN_OR_EQUAL = ":greater_than_or_equal",
|
|
16
|
+
LESS_THAN = ":less_than",
|
|
17
|
+
LESS_THAN_OR_EQUAL = ":less_than_or_equal",
|
|
18
|
+
EQUAL_TO = ":equal_to"
|
|
19
|
+
}
|
|
20
|
+
export declare enum QualifierBehavior {
|
|
21
|
+
ALL = ":all",
|
|
22
|
+
ANY = ":any"
|
|
23
|
+
}
|
|
24
|
+
export declare class Qualifier {
|
|
25
|
+
is_a: 'Qualifier';
|
|
26
|
+
constructor();
|
|
27
|
+
compareAmounts(compare: number, comparisonType: NumericalComparisonType, compareTo: number): boolean;
|
|
28
|
+
match(discountCart: DiscountCart, selector?: Selector): boolean;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=Qualifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Qualifier.d.ts","sourceRoot":"","sources":["../../src/common/Qualifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,oBAAY,kBAAkB;IAC5B,IAAI,UAAU;IACd,QAAQ,cAAc;CACvB;AAED,oBAAY,oBAAoB;IAC9B,KAAK,WAAW;IAChB,QAAQ,cAAc;IACtB,UAAU,gBAAgB;IAC1B,QAAQ,cAAc;CACvB;AAED,oBAAY,uBAAuB;IACjC,YAAY,kBAAkB;IAC9B,qBAAqB,2BAA2B;IAChD,SAAS,eAAe;IACxB,kBAAkB,wBAAwB;IAC1C,QAAQ,cAAc;CACvB;AAUD,oBAAY,iBAAiB;IAC3B,GAAG,SAAS;IACZ,GAAG,SAAS;CACb;AACD,qBAAa,SAAS;IACpB,IAAI,EAAE,WAAW,CAAC;;IAMlB,cAAc,CACZ,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,uBAAuB,EACvC,SAAS,EAAE,MAAM;IAkBnB,KAAK,CAAC,YAAY,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,QAAQ;CAGtD"}
|