@faststore/api 3.0.74 → 3.0.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/__generated__/schema.d.ts +6 -0
- package/dist/cjs/src/__generated__/schema.js.map +1 -1
- package/dist/cjs/src/platforms/vtex/resolvers/aggregateOffer.js +21 -9
- package/dist/cjs/src/platforms/vtex/resolvers/aggregateOffer.js.map +1 -1
- package/dist/cjs/src/platforms/vtex/resolvers/offer.js +19 -0
- package/dist/cjs/src/platforms/vtex/resolvers/offer.js.map +1 -1
- package/dist/cjs/src/platforms/vtex/utils/taxes.d.ts +1 -0
- package/dist/cjs/src/platforms/vtex/utils/taxes.js +9 -0
- package/dist/cjs/src/platforms/vtex/utils/taxes.js.map +1 -0
- package/dist/cjs/src/typeDefs/aggregateOffer.graphql +4 -0
- package/dist/cjs/src/typeDefs/offer.graphql +8 -0
- package/dist/esm/package.json +1 -1
- package/dist/esm/src/__generated__/schema.d.ts +6 -0
- package/dist/esm/src/__generated__/schema.js.map +1 -1
- package/dist/esm/src/platforms/vtex/resolvers/aggregateOffer.js +21 -9
- package/dist/esm/src/platforms/vtex/resolvers/aggregateOffer.js.map +1 -1
- package/dist/esm/src/platforms/vtex/resolvers/offer.js +19 -0
- package/dist/esm/src/platforms/vtex/resolvers/offer.js.map +1 -1
- package/dist/esm/src/platforms/vtex/utils/taxes.d.ts +1 -0
- package/dist/esm/src/platforms/vtex/utils/taxes.js +5 -0
- package/dist/esm/src/platforms/vtex/utils/taxes.js.map +1 -0
- package/dist/esm/src/typeDefs/aggregateOffer.graphql +4 -0
- package/dist/esm/src/typeDefs/offer.graphql +8 -0
- package/package.json +2 -2
- package/src/__generated__/schema.ts +6 -0
- package/src/platforms/vtex/resolvers/aggregateOffer.ts +37 -15
- package/src/platforms/vtex/resolvers/offer.ts +23 -0
- package/src/platforms/vtex/utils/taxes.ts +9 -0
- package/src/typeDefs/aggregateOffer.graphql +4 -0
- package/src/typeDefs/offer.graphql +8 -0
package/dist/cjs/package.json
CHANGED
|
@@ -573,6 +573,8 @@ export type StoreAggregateOffer = {
|
|
|
573
573
|
highPrice: Scalars['Float'];
|
|
574
574
|
/** Lowest price among all sellers. */
|
|
575
575
|
lowPrice: Scalars['Float'];
|
|
576
|
+
/** Lowest price among all sellers with current taxes. */
|
|
577
|
+
lowPriceWithTaxes: Scalars['Float'];
|
|
576
578
|
/** Number of sellers selling this SKU. */
|
|
577
579
|
offerCount: Scalars['Int'];
|
|
578
580
|
/** Array with information on each available offer. */
|
|
@@ -798,12 +800,16 @@ export type StoreOffer = {
|
|
|
798
800
|
itemOffered: StoreProduct;
|
|
799
801
|
/** This is displayed as the "from" price in the context of promotions' price comparison. This may change before it reaches the shelf. */
|
|
800
802
|
listPrice: Scalars['Float'];
|
|
803
|
+
/** List price among with current taxes. */
|
|
804
|
+
listPriceWithTaxes: Scalars['Float'];
|
|
801
805
|
/** Also known as spot price. */
|
|
802
806
|
price: Scalars['Float'];
|
|
803
807
|
/** ISO code of the currency used for the offer prices. */
|
|
804
808
|
priceCurrency: Scalars['String'];
|
|
805
809
|
/** Next date in which price is scheduled to change. If there is no scheduled change, this will be set a year in the future from current time. */
|
|
806
810
|
priceValidUntil: Scalars['String'];
|
|
811
|
+
/** Also known as spot price with taxes. */
|
|
812
|
+
priceWithTaxes: Scalars['Float'];
|
|
807
813
|
/** Number of items offered. */
|
|
808
814
|
quantity: Scalars['Int'];
|
|
809
815
|
/** Seller responsible for the offer. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/__generated__/schema.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/__generated__/schema.ts"],"names":[],"mappings":";;AAkvBC,CAAC;AA+DD,CAAC;AA6TD,CAAC;AAOD,CAAC"}
|
|
@@ -2,16 +2,28 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StoreAggregateOffer = void 0;
|
|
4
4
|
const productStock_1 = require("../utils/productStock");
|
|
5
|
+
const taxes_1 = require("../utils/taxes");
|
|
6
|
+
const getHighPrice = (offers, options = { includeTaxes: false }) => {
|
|
7
|
+
const availableOffers = offers.filter(productStock_1.inStock);
|
|
8
|
+
const highOffer = availableOffers[availableOffers.length - 1];
|
|
9
|
+
const highPrice = highOffer ? (0, productStock_1.price)(highOffer) : 0;
|
|
10
|
+
if (!options.includeTaxes) {
|
|
11
|
+
return highPrice;
|
|
12
|
+
}
|
|
13
|
+
return (0, taxes_1.withTax)(highPrice, highOffer?.Tax, highOffer?.product?.unitMultiplier);
|
|
14
|
+
};
|
|
15
|
+
const getLowPrice = (offers, options = { includeTaxes: false }) => {
|
|
16
|
+
const [lowOffer] = offers.filter(productStock_1.inStock);
|
|
17
|
+
const lowPrice = lowOffer ? (0, productStock_1.price)(lowOffer) : 0;
|
|
18
|
+
if (!options.includeTaxes) {
|
|
19
|
+
return lowPrice;
|
|
20
|
+
}
|
|
21
|
+
return (0, taxes_1.withTax)(lowPrice, lowOffer?.Tax, lowOffer?.product?.unitMultiplier);
|
|
22
|
+
};
|
|
5
23
|
exports.StoreAggregateOffer = {
|
|
6
|
-
highPrice: (offers) =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return highOffer != null ? (0, productStock_1.price)(highOffer) : 0;
|
|
10
|
-
},
|
|
11
|
-
lowPrice: (offers) => {
|
|
12
|
-
const [lowOffer] = offers.filter(productStock_1.inStock);
|
|
13
|
-
return lowOffer ? (0, productStock_1.price)(lowOffer) : 0;
|
|
14
|
-
},
|
|
24
|
+
highPrice: (offers) => getHighPrice(offers),
|
|
25
|
+
lowPrice: (offers) => getLowPrice(offers),
|
|
26
|
+
lowPriceWithTaxes: (offers) => getLowPrice(offers, { includeTaxes: true }),
|
|
15
27
|
offerCount: (offers) => offers.length,
|
|
16
28
|
priceCurrency: async (_, __, ctx) => {
|
|
17
29
|
const { loaders: { salesChannelLoader }, storage: { channel } } = ctx;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregateOffer.js","sourceRoot":"","sources":["../../../../../../src/platforms/vtex/resolvers/aggregateOffer.ts"],"names":[],"mappings":";;;AAAA,wDAAsD;
|
|
1
|
+
{"version":3,"file":"aggregateOffer.js","sourceRoot":"","sources":["../../../../../../src/platforms/vtex/resolvers/aggregateOffer.ts"],"names":[],"mappings":";;;AAAA,wDAAsD;AAItD,0CAAwC;AAIxC,MAAM,YAAY,GAAG,CACnB,MAAY,EACZ,UAAqC,EAAE,YAAY,EAAE,KAAK,EAAE,EAC5D,EAAE;IACF,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,sBAAO,CAAC,CAAA;IAC9C,MAAM,SAAS,GAAG,eAAe,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAC7D,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,IAAA,oBAAK,EAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAClD,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;QAC1B,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,OAAO,IAAA,eAAO,EAAC,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,CAAC,CAAA;AAC/E,CAAC,CAAA;AAED,MAAM,WAAW,GAAG,CAClB,MAAY,EACZ,UAAqC,EAAE,YAAY,EAAE,KAAK,EAAE,EAC5D,EAAE;IACF,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,sBAAO,CAAC,CAAA;IAEzC,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAA,oBAAK,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAE/C,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;QAC1B,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,OAAO,IAAA,eAAO,EAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,CAAC,CAAA;AAC5E,CAAC,CAAA;AAEY,QAAA,mBAAmB,GAE5B;IACF,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC;IAC3C,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC;IACzC,iBAAiB,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IAC1E,UAAU,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM;IACrC,aAAa,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE;QAClC,MAAM,EACJ,OAAO,EAAE,EAAE,kBAAkB,EAAE,EAC/B,OAAO,EAAE,EAAE,OAAO,EAAE,EACrB,GAAG,GAAG,CAAA;QAEP,MAAM,EAAE,GAAG,MAAM,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAE/D,OAAO,EAAE,CAAC,YAAY,IAAI,EAAE,CAAC;IAC/B,CAAC;IACD,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;CAC3B,CAAA"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StoreOffer = void 0;
|
|
4
4
|
const productStock_1 = require("../utils/productStock");
|
|
5
|
+
const taxes_1 = require("../utils/taxes");
|
|
5
6
|
const isSearchItem = (item) => 'Price' in item && 'seller' in item && 'product' in item;
|
|
6
7
|
const isOrderFormItem = (item) => 'skuName' in item;
|
|
7
8
|
exports.StoreOffer = {
|
|
@@ -51,6 +52,15 @@ exports.StoreOffer = {
|
|
|
51
52
|
}
|
|
52
53
|
return null;
|
|
53
54
|
},
|
|
55
|
+
priceWithTaxes: (root) => {
|
|
56
|
+
if (isSearchItem(root)) {
|
|
57
|
+
return (0, taxes_1.withTax)((0, productStock_1.price)(root), root?.Tax, root.product.unitMultiplier);
|
|
58
|
+
}
|
|
59
|
+
if (isOrderFormItem(root)) {
|
|
60
|
+
return (0, taxes_1.withTax)(root.sellingPrice / 1e2, root.tax / 1e2, root.unitMultiplier);
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
},
|
|
54
64
|
sellingPrice: (root) => {
|
|
55
65
|
if (isSearchItem(root)) {
|
|
56
66
|
return (0, productStock_1.sellingPrice)(root);
|
|
@@ -69,6 +79,15 @@ exports.StoreOffer = {
|
|
|
69
79
|
}
|
|
70
80
|
return null;
|
|
71
81
|
},
|
|
82
|
+
listPriceWithTaxes: (root) => {
|
|
83
|
+
if (isSearchItem(root)) {
|
|
84
|
+
return (0, taxes_1.withTax)(root.ListPrice ?? 0, root?.Tax, root.product.unitMultiplier);
|
|
85
|
+
}
|
|
86
|
+
if (isOrderFormItem(root)) {
|
|
87
|
+
return (0, taxes_1.withTax)(root.listPrice / 1e2, root.tax / 1e2, root.unitMultiplier);
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
},
|
|
72
91
|
itemOffered: (root) => {
|
|
73
92
|
if (isSearchItem(root)) {
|
|
74
93
|
return root.product;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"offer.js","sourceRoot":"","sources":["../../../../../../src/platforms/vtex/resolvers/offer.ts"],"names":[],"mappings":";;;AAAA,wDAM8B;
|
|
1
|
+
{"version":3,"file":"offer.js","sourceRoot":"","sources":["../../../../../../src/platforms/vtex/resolvers/offer.ts"],"names":[],"mappings":";;;AAAA,wDAM8B;AAM9B,0CAAwC;AAQxC,MAAM,YAAY,GAAG,CAAC,IAAU,EAAyB,EAAE,CACzD,OA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ACpC,CAAA;QACH,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;IACD,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE;QACjB,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC,iBAAiB,IAAI,CAAC,CAAA;QACpC,CAAC;QAED,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC,QAAQ,CAAA;QACtB,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const withTax: (price: number, tax?: number, unitMultiplier?: number) => number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withTax = void 0;
|
|
4
|
+
const withTax = (price, tax = 0, unitMultiplier = 1) => {
|
|
5
|
+
const unitTax = tax / unitMultiplier;
|
|
6
|
+
return Math.round((price + unitTax) * 100) / 100;
|
|
7
|
+
};
|
|
8
|
+
exports.withTax = withTax;
|
|
9
|
+
//# sourceMappingURL=taxes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"taxes.js","sourceRoot":"","sources":["../../../../../../src/platforms/vtex/utils/taxes.ts"],"names":[],"mappings":";;;AAAO,MAAM,OAAO,GAAG,CACrB,KAAa,EACb,MAAc,CAAC,EACf,iBAAyB,CAAC,EAC1B,EAAE;IACF,MAAM,OAAO,GAAG,GAAG,GAAG,cAAc,CAAA;IAEpC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAA;AAClD,CAAC,CAAA;AARY,QAAA,OAAO,WAQnB"}
|
|
@@ -7,6 +7,10 @@ type StoreOffer {
|
|
|
7
7
|
"""
|
|
8
8
|
listPrice: Float!
|
|
9
9
|
"""
|
|
10
|
+
List price among with current taxes.
|
|
11
|
+
"""
|
|
12
|
+
listPriceWithTaxes: Float!
|
|
13
|
+
"""
|
|
10
14
|
Computed price before applying coupons, taxes or benefits. This may change before it reaches the shelf.
|
|
11
15
|
"""
|
|
12
16
|
sellingPrice: Float!
|
|
@@ -19,6 +23,10 @@ type StoreOffer {
|
|
|
19
23
|
"""
|
|
20
24
|
price: Float!
|
|
21
25
|
"""
|
|
26
|
+
Also known as spot price with taxes.
|
|
27
|
+
"""
|
|
28
|
+
priceWithTaxes: Float!
|
|
29
|
+
"""
|
|
22
30
|
Next date in which price is scheduled to change. If there is no scheduled change, this will be set a year in the future from current time.
|
|
23
31
|
"""
|
|
24
32
|
priceValidUntil: String!
|
package/dist/esm/package.json
CHANGED
|
@@ -573,6 +573,8 @@ export type StoreAggregateOffer = {
|
|
|
573
573
|
highPrice: Scalars['Float'];
|
|
574
574
|
/** Lowest price among all sellers. */
|
|
575
575
|
lowPrice: Scalars['Float'];
|
|
576
|
+
/** Lowest price among all sellers with current taxes. */
|
|
577
|
+
lowPriceWithTaxes: Scalars['Float'];
|
|
576
578
|
/** Number of sellers selling this SKU. */
|
|
577
579
|
offerCount: Scalars['Int'];
|
|
578
580
|
/** Array with information on each available offer. */
|
|
@@ -798,12 +800,16 @@ export type StoreOffer = {
|
|
|
798
800
|
itemOffered: StoreProduct;
|
|
799
801
|
/** This is displayed as the "from" price in the context of promotions' price comparison. This may change before it reaches the shelf. */
|
|
800
802
|
listPrice: Scalars['Float'];
|
|
803
|
+
/** List price among with current taxes. */
|
|
804
|
+
listPriceWithTaxes: Scalars['Float'];
|
|
801
805
|
/** Also known as spot price. */
|
|
802
806
|
price: Scalars['Float'];
|
|
803
807
|
/** ISO code of the currency used for the offer prices. */
|
|
804
808
|
priceCurrency: Scalars['String'];
|
|
805
809
|
/** Next date in which price is scheduled to change. If there is no scheduled change, this will be set a year in the future from current time. */
|
|
806
810
|
priceValidUntil: Scalars['String'];
|
|
811
|
+
/** Also known as spot price with taxes. */
|
|
812
|
+
priceWithTaxes: Scalars['Float'];
|
|
807
813
|
/** Number of items offered. */
|
|
808
814
|
quantity: Scalars['Int'];
|
|
809
815
|
/** Seller responsible for the offer. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/__generated__/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/__generated__/schema.ts"],"names":[],"mappings":"AAkvBC,CAAC;AA+DD,CAAC;AA6TD,CAAC;AAOD,CAAC"}
|
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
import { inStock, price } from '../utils/productStock';
|
|
2
|
+
import { withTax } from '../utils/taxes';
|
|
3
|
+
const getHighPrice = (offers, options = { includeTaxes: false }) => {
|
|
4
|
+
const availableOffers = offers.filter(inStock);
|
|
5
|
+
const highOffer = availableOffers[availableOffers.length - 1];
|
|
6
|
+
const highPrice = highOffer ? price(highOffer) : 0;
|
|
7
|
+
if (!options.includeTaxes) {
|
|
8
|
+
return highPrice;
|
|
9
|
+
}
|
|
10
|
+
return withTax(highPrice, highOffer?.Tax, highOffer?.product?.unitMultiplier);
|
|
11
|
+
};
|
|
12
|
+
const getLowPrice = (offers, options = { includeTaxes: false }) => {
|
|
13
|
+
const [lowOffer] = offers.filter(inStock);
|
|
14
|
+
const lowPrice = lowOffer ? price(lowOffer) : 0;
|
|
15
|
+
if (!options.includeTaxes) {
|
|
16
|
+
return lowPrice;
|
|
17
|
+
}
|
|
18
|
+
return withTax(lowPrice, lowOffer?.Tax, lowOffer?.product?.unitMultiplier);
|
|
19
|
+
};
|
|
2
20
|
export const StoreAggregateOffer = {
|
|
3
|
-
highPrice: (offers) =>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return highOffer != null ? price(highOffer) : 0;
|
|
7
|
-
},
|
|
8
|
-
lowPrice: (offers) => {
|
|
9
|
-
const [lowOffer] = offers.filter(inStock);
|
|
10
|
-
return lowOffer ? price(lowOffer) : 0;
|
|
11
|
-
},
|
|
21
|
+
highPrice: (offers) => getHighPrice(offers),
|
|
22
|
+
lowPrice: (offers) => getLowPrice(offers),
|
|
23
|
+
lowPriceWithTaxes: (offers) => getLowPrice(offers, { includeTaxes: true }),
|
|
12
24
|
offerCount: (offers) => offers.length,
|
|
13
25
|
priceCurrency: async (_, __, ctx) => {
|
|
14
26
|
const { loaders: { salesChannelLoader }, storage: { channel } } = ctx;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregateOffer.js","sourceRoot":"","sources":["../../../../../../src/platforms/vtex/resolvers/aggregateOffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"aggregateOffer.js","sourceRoot":"","sources":["../../../../../../src/platforms/vtex/resolvers/aggregateOffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAItD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAIxC,MAAM,YAAY,GAAG,CACnB,MAAY,EACZ,UAAqC,EAAE,YAAY,EAAE,KAAK,EAAE,EAC5D,EAAE;IACF,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAC9C,MAAM,SAAS,GAAG,eAAe,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAC7D,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAClD,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;QAC1B,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,OAAO,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,CAAC,CAAA;AAC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E,EAAE,CAAC,MAAM;CAC3B,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { availability, inStock, inStockOrderFormItem, price, sellingPrice, } from '../utils/productStock';
|
|
2
|
+
import { withTax } from '../utils/taxes';
|
|
2
3
|
const isSearchItem = (item) => 'Price' in item && 'seller' in item && 'product' in item;
|
|
3
4
|
const isOrderFormItem = (item) => 'skuName' in item;
|
|
4
5
|
export const StoreOffer = {
|
|
@@ -48,6 +49,15 @@ export const StoreOffer = {
|
|
|
48
49
|
}
|
|
49
50
|
return null;
|
|
50
51
|
},
|
|
52
|
+
priceWithTaxes: (root) => {
|
|
53
|
+
if (isSearchItem(root)) {
|
|
54
|
+
return withTax(price(root), root?.Tax, root.product.unitMultiplier);
|
|
55
|
+
}
|
|
56
|
+
if (isOrderFormItem(root)) {
|
|
57
|
+
return withTax(root.sellingPrice / 1e2, root.tax / 1e2, root.unitMultiplier);
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
},
|
|
51
61
|
sellingPrice: (root) => {
|
|
52
62
|
if (isSearchItem(root)) {
|
|
53
63
|
return sellingPrice(root);
|
|
@@ -66,6 +76,15 @@ export const StoreOffer = {
|
|
|
66
76
|
}
|
|
67
77
|
return null;
|
|
68
78
|
},
|
|
79
|
+
listPriceWithTaxes: (root) => {
|
|
80
|
+
if (isSearchItem(root)) {
|
|
81
|
+
return withTax(root.ListPrice ?? 0, root?.Tax, root.product.unitMultiplier);
|
|
82
|
+
}
|
|
83
|
+
if (isOrderFormItem(root)) {
|
|
84
|
+
return withTax(root.listPrice / 1e2, root.tax / 1e2, root.unitMultiplier);
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
},
|
|
69
88
|
itemOffered: (root) => {
|
|
70
89
|
if (isSearchItem(root)) {
|
|
71
90
|
return root.product;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"offer.js","sourceRoot":"","sources":["../../../../../../src/platforms/vtex/resolvers/offer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,OAAO,EACP,oBAAoB,EACpB,KAAK,EACL,YAAY,GACb,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"offer.js","sourceRoot":"","sources":["../../../../../../src/platforms/vtex/resolvers/offer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,OAAO,EACP,oBAAoB,EACpB,KAAK,EACL,YAAY,GACb,MAAM,uBAAuB,CAAA;AAM9B,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAQxC,MAAM,YAAY,GAAG,CAAC,IAAU,EAAyB,EAAE,CACzD,OAAO,IAAI,IAAI,IAAI,QAAQ,IAAI,IAAI,IAAI,SAAS,IAAI,IAAI,CAAA;AAE1D,MAAM,eAAe,GAAG,CAAC,IAAU,EAA4B,EAAE,CAC/D,SAAS,IAAI,IAAI,CAAA;AAEnB,MAAM,CAAC,MAAM,UAAU,GAAmC;IACxD,aAAa,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE;QAClC,MAAM,EACJ,OAAO,EAAE,EAAE,kBAAkB,EAAE,EAC/B,OAAO,EAAE,EAAE,OAAO,EAAE,EACrB,GAAG,GAAG,CAAA;QAEP,MAAM,EAAE,GAAG,MAAM,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAE/D,OAAO,EAAE,CAAC,YAAY,IAAI,EAAE,CAAC;IAC/B,CAAC;IACD,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE;QACxB,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC,eAAe,IAAI,EAAE,CAAA;QACnC,CAAC;QAED,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC,eAAe,IAAI,EAAE,CAAA;QACnC,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;IACD,a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EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;QAC3E,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;IACD,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE;QACpB,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC,OAAO,CAAA;QACrB,CAAC;QAED,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,OAAO;gBACL,GAAG,IAAI,CAAC,OAAO;gBACf,iBAAiB,EAAE,IAAI,CAAC,WAAW;aACpC,CAAA;QACH,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;IACD,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE;QACjB,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC,iBAAiB,IAAI,CAAC,CAAA;QACpC,CAAC;QAED,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC,QAAQ,CAAA;QACtB,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const withTax: (price: number, tax?: number, unitMultiplier?: number) => number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"taxes.js","sourceRoot":"","sources":["../../../../../../src/platforms/vtex/utils/taxes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,KAAa,EACb,MAAc,CAAC,EACf,iBAAyB,CAAC,EAC1B,EAAE;IACF,MAAM,OAAO,GAAG,GAAG,GAAG,cAAc,CAAA;IAEpC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAA;AAClD,CAAC,CAAA"}
|
|
@@ -7,6 +7,10 @@ type StoreOffer {
|
|
|
7
7
|
"""
|
|
8
8
|
listPrice: Float!
|
|
9
9
|
"""
|
|
10
|
+
List price among with current taxes.
|
|
11
|
+
"""
|
|
12
|
+
listPriceWithTaxes: Float!
|
|
13
|
+
"""
|
|
10
14
|
Computed price before applying coupons, taxes or benefits. This may change before it reaches the shelf.
|
|
11
15
|
"""
|
|
12
16
|
sellingPrice: Float!
|
|
@@ -19,6 +23,10 @@ type StoreOffer {
|
|
|
19
23
|
"""
|
|
20
24
|
price: Float!
|
|
21
25
|
"""
|
|
26
|
+
Also known as spot price with taxes.
|
|
27
|
+
"""
|
|
28
|
+
priceWithTaxes: Float!
|
|
29
|
+
"""
|
|
22
30
|
Next date in which price is scheduled to change. If there is no scheduled change, this will be set a year in the future from current time.
|
|
23
31
|
"""
|
|
24
32
|
priceValidUntil: String!
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/api",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.76",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/cjs/src/index.js",
|
|
6
6
|
"typings": "dist/esm/src/index.d.ts",
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
"volta": {
|
|
80
80
|
"extends": "../../package.json"
|
|
81
81
|
},
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "7ccc25f3f85801d3de3c0fef231dfbcf1468d016"
|
|
83
83
|
}
|
|
@@ -627,6 +627,8 @@ export type StoreAggregateOffer = {
|
|
|
627
627
|
highPrice: Scalars['Float'];
|
|
628
628
|
/** Lowest price among all sellers. */
|
|
629
629
|
lowPrice: Scalars['Float'];
|
|
630
|
+
/** Lowest price among all sellers with current taxes. */
|
|
631
|
+
lowPriceWithTaxes: Scalars['Float'];
|
|
630
632
|
/** Number of sellers selling this SKU. */
|
|
631
633
|
offerCount: Scalars['Int'];
|
|
632
634
|
/** Array with information on each available offer. */
|
|
@@ -877,12 +879,16 @@ export type StoreOffer = {
|
|
|
877
879
|
itemOffered: StoreProduct;
|
|
878
880
|
/** This is displayed as the "from" price in the context of promotions' price comparison. This may change before it reaches the shelf. */
|
|
879
881
|
listPrice: Scalars['Float'];
|
|
882
|
+
/** List price among with current taxes. */
|
|
883
|
+
listPriceWithTaxes: Scalars['Float'];
|
|
880
884
|
/** Also known as spot price. */
|
|
881
885
|
price: Scalars['Float'];
|
|
882
886
|
/** ISO code of the currency used for the offer prices. */
|
|
883
887
|
priceCurrency: Scalars['String'];
|
|
884
888
|
/** Next date in which price is scheduled to change. If there is no scheduled change, this will be set a year in the future from current time. */
|
|
885
889
|
priceValidUntil: Scalars['String'];
|
|
890
|
+
/** Also known as spot price with taxes. */
|
|
891
|
+
priceWithTaxes: Scalars['Float'];
|
|
886
892
|
/** Number of items offered. */
|
|
887
893
|
quantity: Scalars['Int'];
|
|
888
894
|
/** Seller responsible for the offer. */
|
|
@@ -2,32 +2,54 @@ import { inStock, price } from '../utils/productStock'
|
|
|
2
2
|
import type { StoreProduct } from './product'
|
|
3
3
|
import type { PromiseType } from '../../../typings'
|
|
4
4
|
import type { Resolver } from '..'
|
|
5
|
+
import { withTax } from '../utils/taxes'
|
|
5
6
|
|
|
6
7
|
export type Root = PromiseType<ReturnType<typeof StoreProduct.offers>>
|
|
7
8
|
|
|
9
|
+
const getHighPrice = (
|
|
10
|
+
offers: Root,
|
|
11
|
+
options: { includeTaxes: boolean } = { includeTaxes: false }
|
|
12
|
+
) => {
|
|
13
|
+
const availableOffers = offers.filter(inStock)
|
|
14
|
+
const highOffer = availableOffers[availableOffers.length - 1]
|
|
15
|
+
const highPrice = highOffer ? price(highOffer) : 0
|
|
16
|
+
if (!options.includeTaxes) {
|
|
17
|
+
return highPrice
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return withTax(highPrice, highOffer?.Tax, highOffer?.product?.unitMultiplier)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const getLowPrice = (
|
|
24
|
+
offers: Root,
|
|
25
|
+
options: { includeTaxes: boolean } = { includeTaxes: false }
|
|
26
|
+
) => {
|
|
27
|
+
const [lowOffer] = offers.filter(inStock)
|
|
28
|
+
|
|
29
|
+
const lowPrice = lowOffer ? price(lowOffer) : 0
|
|
30
|
+
|
|
31
|
+
if (!options.includeTaxes) {
|
|
32
|
+
return lowPrice
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return withTax(lowPrice, lowOffer?.Tax, lowOffer?.product?.unitMultiplier)
|
|
36
|
+
}
|
|
37
|
+
|
|
8
38
|
export const StoreAggregateOffer: Record<string, Resolver<Root>> & {
|
|
9
39
|
offers: Resolver<Root, any, Root>
|
|
10
40
|
} = {
|
|
11
|
-
highPrice: (offers) =>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return highOffer != null ? price(highOffer) : 0
|
|
16
|
-
},
|
|
17
|
-
lowPrice: (offers) => {
|
|
18
|
-
const [lowOffer] = offers.filter(inStock)
|
|
19
|
-
|
|
20
|
-
return lowOffer ? price(lowOffer) : 0
|
|
21
|
-
},
|
|
41
|
+
highPrice: (offers) => getHighPrice(offers),
|
|
42
|
+
lowPrice: (offers) => getLowPrice(offers),
|
|
43
|
+
lowPriceWithTaxes: (offers) => getLowPrice(offers, { includeTaxes: true }),
|
|
22
44
|
offerCount: (offers) => offers.length,
|
|
23
45
|
priceCurrency: async (_, __, ctx) => {
|
|
24
|
-
const {
|
|
25
|
-
loaders: { salesChannelLoader },
|
|
26
|
-
storage: { channel }
|
|
46
|
+
const {
|
|
47
|
+
loaders: { salesChannelLoader },
|
|
48
|
+
storage: { channel }
|
|
27
49
|
} = ctx
|
|
28
50
|
|
|
29
51
|
const sc = await salesChannelLoader.load(channel.salesChannel);
|
|
30
|
-
|
|
52
|
+
|
|
31
53
|
return sc.CurrencyCode ?? '';
|
|
32
54
|
},
|
|
33
55
|
offers: (offers) => offers,
|
|
@@ -10,6 +10,7 @@ import type { StoreAggregateOffer } from './aggregateOffer'
|
|
|
10
10
|
import type { ArrayElementType } from '../../../typings'
|
|
11
11
|
import type { EnhancedSku } from '../utils/enhanceSku'
|
|
12
12
|
import type { OrderFormItem } from '../clients/commerce/types/OrderForm'
|
|
13
|
+
import { withTax } from '../utils/taxes'
|
|
13
14
|
|
|
14
15
|
type OrderFormProduct = OrderFormItem & { product: EnhancedSku }
|
|
15
16
|
type SearchProduct = ArrayElementType<
|
|
@@ -83,6 +84,17 @@ export const StoreOffer: Record<string, Resolver<Root>> = {
|
|
|
83
84
|
|
|
84
85
|
return null
|
|
85
86
|
},
|
|
87
|
+
priceWithTaxes: (root) => {
|
|
88
|
+
if (isSearchItem(root)) {
|
|
89
|
+
return withTax(price(root), root?.Tax, root.product.unitMultiplier)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (isOrderFormItem(root)) {
|
|
93
|
+
return withTax(root.sellingPrice / 1e2, root.tax / 1e2, root.unitMultiplier)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return null
|
|
97
|
+
},
|
|
86
98
|
sellingPrice: (root) => {
|
|
87
99
|
if (isSearchItem(root)) {
|
|
88
100
|
return sellingPrice(root)
|
|
@@ -105,6 +117,17 @@ export const StoreOffer: Record<string, Resolver<Root>> = {
|
|
|
105
117
|
|
|
106
118
|
return null
|
|
107
119
|
},
|
|
120
|
+
listPriceWithTaxes: (root) => {
|
|
121
|
+
if (isSearchItem(root)) {
|
|
122
|
+
return withTax(root.ListPrice ?? 0, root?.Tax, root.product.unitMultiplier)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (isOrderFormItem(root)) {
|
|
126
|
+
return withTax(root.listPrice / 1e2, root.tax / 1e2, root.unitMultiplier)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return null
|
|
130
|
+
},
|
|
108
131
|
itemOffered: (root) => {
|
|
109
132
|
if (isSearchItem(root)) {
|
|
110
133
|
return root.product
|
|
@@ -7,6 +7,10 @@ type StoreOffer {
|
|
|
7
7
|
"""
|
|
8
8
|
listPrice: Float!
|
|
9
9
|
"""
|
|
10
|
+
List price among with current taxes.
|
|
11
|
+
"""
|
|
12
|
+
listPriceWithTaxes: Float!
|
|
13
|
+
"""
|
|
10
14
|
Computed price before applying coupons, taxes or benefits. This may change before it reaches the shelf.
|
|
11
15
|
"""
|
|
12
16
|
sellingPrice: Float!
|
|
@@ -19,6 +23,10 @@ type StoreOffer {
|
|
|
19
23
|
"""
|
|
20
24
|
price: Float!
|
|
21
25
|
"""
|
|
26
|
+
Also known as spot price with taxes.
|
|
27
|
+
"""
|
|
28
|
+
priceWithTaxes: Float!
|
|
29
|
+
"""
|
|
22
30
|
Next date in which price is scheduled to change. If there is no scheduled change, this will be set a year in the future from current time.
|
|
23
31
|
"""
|
|
24
32
|
priceValidUntil: String!
|