@putiikkipalvelu/storefront-sdk 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +21 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -49
- package/dist/index.d.ts +22 -49
- package/dist/index.js +11 -44
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -620,76 +620,43 @@ function calculateCartWeight(items) {
|
|
|
620
620
|
function createShippingResource(fetcher) {
|
|
621
621
|
return {
|
|
622
622
|
/**
|
|
623
|
-
* Get
|
|
624
|
-
* Returns methods
|
|
623
|
+
* Get shipping options for a specific postal code.
|
|
624
|
+
* Returns home delivery methods and pickup locations.
|
|
625
625
|
*
|
|
626
|
+
* @param postalCode - Customer's postal code (e.g., "00100")
|
|
626
627
|
* @param options - Fetch options including optional cartItems for weight-based filtering
|
|
627
|
-
* @returns
|
|
628
|
+
* @returns Home delivery methods and pickup locations
|
|
628
629
|
*
|
|
629
630
|
* @example
|
|
630
631
|
* ```typescript
|
|
631
|
-
* const {
|
|
632
|
+
* const { homeDeliveryMethods, pickupLocations } = await client.shipping.getWithLocations("00100");
|
|
632
633
|
*
|
|
633
|
-
*
|
|
634
|
+
* // Show home delivery options
|
|
635
|
+
* homeDeliveryMethods.forEach(method => {
|
|
634
636
|
* console.log(`${method.name}: ${method.price / 100}€`);
|
|
635
637
|
* });
|
|
636
|
-
* ```
|
|
637
|
-
*
|
|
638
|
-
* @example Weight-based filtering
|
|
639
|
-
* ```typescript
|
|
640
|
-
* // Pass cart items - SDK calculates weight automatically
|
|
641
|
-
* const { shipmentMethods } = await client.shipping.getMethods({
|
|
642
|
-
* cartItems: cartItems
|
|
643
|
-
* });
|
|
644
|
-
* ```
|
|
645
|
-
*/
|
|
646
|
-
async getMethods(options) {
|
|
647
|
-
const params = new URLSearchParams();
|
|
648
|
-
if (_optionalChain([options, 'optionalAccess', _10 => _10.cartItems, 'optionalAccess', _11 => _11.length])) {
|
|
649
|
-
const cartWeight = calculateCartWeight(options.cartItems);
|
|
650
|
-
params.set("cartWeight", cartWeight.toString());
|
|
651
|
-
}
|
|
652
|
-
const queryString = params.toString();
|
|
653
|
-
const url = `/api/storefront/v1/shipment-methods${queryString ? `?${queryString}` : ""}`;
|
|
654
|
-
return fetcher.request(url, {
|
|
655
|
-
method: "GET",
|
|
656
|
-
...options
|
|
657
|
-
});
|
|
658
|
-
},
|
|
659
|
-
/**
|
|
660
|
-
* Get shipment methods with pickup locations for a specific postal code.
|
|
661
|
-
* Calls the Shipit API to fetch nearby pickup points (parcel lockers, etc.)
|
|
662
|
-
*
|
|
663
|
-
* @param postalCode - Customer's postal code (e.g., "00100")
|
|
664
|
-
* @param options - Fetch options including optional cartItems for weight-based filtering
|
|
665
|
-
* @returns Shipment methods and nearby pickup locations with pricing
|
|
666
|
-
*
|
|
667
|
-
* @example
|
|
668
|
-
* ```typescript
|
|
669
|
-
* const { shipmentMethods, pricedLocations } = await client.shipping.getWithLocations("00100");
|
|
670
638
|
*
|
|
671
639
|
* // Show pickup locations
|
|
672
|
-
*
|
|
640
|
+
* pickupLocations.forEach(location => {
|
|
673
641
|
* console.log(`${location.name} - ${location.carrier}`);
|
|
674
642
|
* console.log(` ${location.address1}, ${location.city}`);
|
|
675
643
|
* console.log(` ${location.distanceInKilometers.toFixed(1)} km away`);
|
|
676
|
-
* console.log(` Price: ${
|
|
644
|
+
* console.log(` Price: ${location.price / 100}€`);
|
|
677
645
|
* });
|
|
678
646
|
* ```
|
|
679
647
|
*
|
|
680
|
-
* @example Weight-based filtering
|
|
648
|
+
* @example Weight-based filtering
|
|
681
649
|
* ```typescript
|
|
682
|
-
* const {
|
|
650
|
+
* const { homeDeliveryMethods, pickupLocations } = await client.shipping.getWithLocations(
|
|
683
651
|
* "00100",
|
|
684
652
|
* { cartItems: cartItems }
|
|
685
653
|
* );
|
|
686
|
-
*
|
|
687
654
|
* // Only shows methods that support the cart's total weight
|
|
688
655
|
* ```
|
|
689
656
|
*/
|
|
690
657
|
async getWithLocations(postalCode, options) {
|
|
691
658
|
const params = new URLSearchParams();
|
|
692
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
659
|
+
if (_optionalChain([options, 'optionalAccess', _10 => _10.cartItems, 'optionalAccess', _11 => _11.length])) {
|
|
693
660
|
const cartWeight = calculateCartWeight(options.cartItems);
|
|
694
661
|
params.set("cartWeight", cartWeight.toString());
|
|
695
662
|
}
|
|
@@ -776,7 +743,7 @@ function createCustomerResource(fetcher) {
|
|
|
776
743
|
*/
|
|
777
744
|
async login(email, password, options, fetchOptions) {
|
|
778
745
|
const headers = {};
|
|
779
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
746
|
+
if (_optionalChain([options, 'optionalAccess', _12 => _12.cartId])) {
|
|
780
747
|
headers["x-cart-id"] = options.cartId;
|
|
781
748
|
}
|
|
782
749
|
return fetcher.request(
|
|
@@ -1245,10 +1212,10 @@ function createOrderResource(fetcher) {
|
|
|
1245
1212
|
function createCheckoutResource(fetcher) {
|
|
1246
1213
|
function buildCheckoutHeaders(options) {
|
|
1247
1214
|
const headers = {};
|
|
1248
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
1215
|
+
if (_optionalChain([options, 'optionalAccess', _13 => _13.cartId])) {
|
|
1249
1216
|
headers["x-cart-id"] = options.cartId;
|
|
1250
1217
|
}
|
|
1251
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
1218
|
+
if (_optionalChain([options, 'optionalAccess', _14 => _14.sessionId])) {
|
|
1252
1219
|
headers["x-session-id"] = options.sessionId;
|
|
1253
1220
|
}
|
|
1254
1221
|
return headers;
|
|
@@ -1312,7 +1279,7 @@ function createCheckoutResource(fetcher) {
|
|
|
1312
1279
|
method: "POST",
|
|
1313
1280
|
body,
|
|
1314
1281
|
headers: {
|
|
1315
|
-
..._optionalChain([options, 'optionalAccess',
|
|
1282
|
+
..._optionalChain([options, 'optionalAccess', _15 => _15.headers]),
|
|
1316
1283
|
...headers
|
|
1317
1284
|
},
|
|
1318
1285
|
...options
|
|
@@ -1390,7 +1357,7 @@ function createCheckoutResource(fetcher) {
|
|
|
1390
1357
|
method: "POST",
|
|
1391
1358
|
body,
|
|
1392
1359
|
headers: {
|
|
1393
|
-
..._optionalChain([options, 'optionalAccess',
|
|
1360
|
+
..._optionalChain([options, 'optionalAccess', _16 => _16.headers]),
|
|
1394
1361
|
...headers
|
|
1395
1362
|
},
|
|
1396
1363
|
...options
|
|
@@ -1483,7 +1450,7 @@ function calculateCartWithCampaigns(items, campaigns) {
|
|
|
1483
1450
|
minimumSpend: 0,
|
|
1484
1451
|
remainingAmount: 0
|
|
1485
1452
|
};
|
|
1486
|
-
if (!_optionalChain([buyXPayYCampaign, 'optionalAccess',
|
|
1453
|
+
if (!_optionalChain([buyXPayYCampaign, 'optionalAccess', _17 => _17.BuyXPayYCampaign])) {
|
|
1487
1454
|
const calculatedItems2 = items.map((item) => ({
|
|
1488
1455
|
item,
|
|
1489
1456
|
paidQuantity: item.cartQuantity,
|
|
@@ -1504,7 +1471,7 @@ function calculateCartWithCampaigns(items, campaigns) {
|
|
|
1504
1471
|
);
|
|
1505
1472
|
const eligibleUnits = items.flatMap((item) => {
|
|
1506
1473
|
const { product, variation } = item;
|
|
1507
|
-
const itemCategories = _optionalChain([product, 'access',
|
|
1474
|
+
const itemCategories = _optionalChain([product, 'access', _18 => _18.categories, 'optionalAccess', _19 => _19.map, 'call', _20 => _20((cat) => cat.id)]) || [];
|
|
1508
1475
|
const isEligible = itemCategories.some(
|
|
1509
1476
|
(id) => applicableCategoryIds.has(id)
|
|
1510
1477
|
);
|
|
@@ -1513,7 +1480,7 @@ function calculateCartWithCampaigns(items, campaigns) {
|
|
|
1513
1480
|
return Array.from({ length: item.cartQuantity }, () => ({
|
|
1514
1481
|
price: priceInfo.effectivePrice,
|
|
1515
1482
|
productId: product.id,
|
|
1516
|
-
variationId: _optionalChain([variation, 'optionalAccess',
|
|
1483
|
+
variationId: _optionalChain([variation, 'optionalAccess', _21 => _21.id]),
|
|
1517
1484
|
originalItem: item
|
|
1518
1485
|
}));
|
|
1519
1486
|
}
|
|
@@ -1547,7 +1514,7 @@ function calculateCartWithCampaigns(items, campaigns) {
|
|
|
1547
1514
|
freeCountMap.set(key, (freeCountMap.get(key) || 0) + 1);
|
|
1548
1515
|
}
|
|
1549
1516
|
const calculatedItems = items.map((item) => {
|
|
1550
|
-
const key = `${item.product.id}${_optionalChain([item, 'access',
|
|
1517
|
+
const key = `${item.product.id}${_optionalChain([item, 'access', _22 => _22.variation, 'optionalAccess', _23 => _23.id]) ? `_${item.variation.id}` : ""}`;
|
|
1551
1518
|
const freeQuantity = freeCountMap.get(key) || 0;
|
|
1552
1519
|
const paidQuantity = item.cartQuantity - freeQuantity;
|
|
1553
1520
|
return {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["d:\\Projektit\\Verkkokaupat\\putiikkipalvelu-sdk\\dist\\index.cjs"],"names":[],"mappings":"AAAA;AACA,IAAI,gBAAgB,EAAE,MAAM,iBAAiB,QAAQ,MAAM;AAC3D,EAAE,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE;AACrC,IAAI,KAAK,CAAC,OAAO,CAAC;AAClB,IAAI,IAAI,CAAC,KAAK,EAAE,iBAAiB;AACjC,IAAI,IAAI,CAAC,OAAO,EAAE,MAAM;AACxB,IAAI,IAAI,CAAC,KAAK,EAAE,IAAI;AACpB,IAAI,MAAM,iBAAiB,EAAE,KAAK;AAClC,IAAI,GAAG,CAAC,gBAAgB,CAAC,iBAAiB,EAAE;AAC5C,MAAM,gBAAgB,CAAC,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,CAAC;AAChE,IAAI;AACJ,EAAE;AACF,CAAC;AACD,IAAI,UAAU,EAAE,MAAM,QAAQ,gBAAgB;AAC9C,EAAE,WAAW,CAAC,QAAQ,EAAE,4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AACA,IAAA;AACA,IAAA;AACA,MAAA;AACA,IAAA;AACA,MAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA;AACA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA;AACA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,MAAA;AACA,IAAA;AACA,IAAA;AACA,MAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,YAAA;AACA,YAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,YAAA;AACA,YAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA;AACA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,IAAA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,MAAA;AACA,IAAA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,IAAA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"D:\\Projektit\\Verkkokaupat\\putiikkipalvelu-sdk\\dist\\index.cjs","sourcesContent":[null]}
|
|
1
|
+
{"version":3,"sources":["d:\\Projektit\\Verkkokaupat\\putiikkipalvelu-sdk\\dist\\index.cjs"],"names":[],"mappings":"AAAA;AACA,IAAI,gBAAgB,EAAE,MAAM,iBAAiB,QAAQ,MAAM;AAC3D,EAAE,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE;AACrC,IAAI,KAAK,CAAC,OAAO,CAAC;AAClB,IAAI,IAAI,CAAC,KAAK,EAAE,iBAAiB;AACjC,IAAI,IAAI,CAAC,OAAO,EAAE,MAAM;AACxB,IAAI,IAAI,CAAC,KAAK,EAAE,IAAI;AACpB,IAAI,MAAM,iBAAiB,EAAE,KAAK;AAClC,IAAI,GAAG,CAAC,gBAAgB,CAAC,iBAAiB,EAAE;AAC5C,MAAM,gBAAgB,CAAC,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,CAAC;AAChE,IAAI;AACJ,EAAE;AACF,CAAC;AACD,IAAI,UAAU,EAAE,MAAM,QAAQ,gBAAgB;AAC9C,EAAE,WAAW,CAAC,QAAQ,EAAE,4BAA4B,EAAE;AACtD,IAAI,KAAK,CAAC,OA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AA;AACA,MAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA;AACA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA;AACA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,MAAA;AACA,IAAA;AACA,IAAA;AACA,MAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,YAAA;AACA,YAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,YAAA;AACA,YAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA;AACA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,IAAA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,MAAA;AACA,IAAA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,IAAA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"D:\\Projektit\\Verkkokaupat\\putiikkipalvelu-sdk\\dist\\index.cjs","sourcesContent":[null]}
|
package/dist/index.d.cts
CHANGED
|
@@ -560,7 +560,7 @@ interface PickupLocationOpeningHours {
|
|
|
560
560
|
}
|
|
561
561
|
/**
|
|
562
562
|
* A pickup location (parcel locker, pickup point, etc.)
|
|
563
|
-
* Returned from Shipit API with
|
|
563
|
+
* Returned from Shipit API with shipmentMethodId and price attached
|
|
564
564
|
*/
|
|
565
565
|
interface PickupLocation {
|
|
566
566
|
/** Unique location ID from Shipit */
|
|
@@ -589,7 +589,7 @@ interface PickupLocation {
|
|
|
589
589
|
distanceInMeters: number;
|
|
590
590
|
/** Distance from postal code in kilometers */
|
|
591
591
|
distanceInKilometers: number;
|
|
592
|
-
/** Location type */
|
|
592
|
+
/** Location type (e.g., "parcel_locker", "service_point", "outdoor_parcel_locker") */
|
|
593
593
|
type?: string;
|
|
594
594
|
/** Structured opening hours */
|
|
595
595
|
openingHours?: PickupLocationOpeningHours | null;
|
|
@@ -597,25 +597,19 @@ interface PickupLocation {
|
|
|
597
597
|
openingHoursRaw?: string | null;
|
|
598
598
|
/** Additional metadata */
|
|
599
599
|
metadata?: unknown | null;
|
|
600
|
-
/**
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
* Response from GET /shipment-methods
|
|
605
|
-
*/
|
|
606
|
-
interface ShipmentMethodsResponse {
|
|
607
|
-
/** Available shipment methods */
|
|
608
|
-
shipmentMethods: ShipmentMethod[];
|
|
600
|
+
/** The shipment method ID this location belongs to */
|
|
601
|
+
shipmentMethodId: string;
|
|
602
|
+
/** Price in cents (from store settings) */
|
|
603
|
+
price: number;
|
|
609
604
|
}
|
|
610
605
|
/**
|
|
611
606
|
* Response from GET /shipment-methods/[postalCode]
|
|
612
|
-
* Includes pickup locations near the postal code
|
|
613
607
|
*/
|
|
614
608
|
interface ShipmentMethodsWithLocationsResponse {
|
|
615
|
-
/**
|
|
616
|
-
|
|
617
|
-
/** Pickup locations
|
|
618
|
-
|
|
609
|
+
/** Home delivery methods (custom methods + Shipit home delivery) */
|
|
610
|
+
homeDeliveryMethods: ShipmentMethod[];
|
|
611
|
+
/** Pickup locations with shipmentMethodId and price attached */
|
|
612
|
+
pickupLocations: PickupLocation[];
|
|
619
613
|
}
|
|
620
614
|
|
|
621
615
|
/**
|
|
@@ -1701,58 +1695,37 @@ interface GetMethodsOptions extends FetchOptions {
|
|
|
1701
1695
|
*/
|
|
1702
1696
|
declare function createShippingResource(fetcher: Fetcher): {
|
|
1703
1697
|
/**
|
|
1704
|
-
* Get
|
|
1705
|
-
* Returns methods
|
|
1698
|
+
* Get shipping options for a specific postal code.
|
|
1699
|
+
* Returns home delivery methods and pickup locations.
|
|
1706
1700
|
*
|
|
1701
|
+
* @param postalCode - Customer's postal code (e.g., "00100")
|
|
1707
1702
|
* @param options - Fetch options including optional cartItems for weight-based filtering
|
|
1708
|
-
* @returns
|
|
1703
|
+
* @returns Home delivery methods and pickup locations
|
|
1709
1704
|
*
|
|
1710
1705
|
* @example
|
|
1711
1706
|
* ```typescript
|
|
1712
|
-
* const {
|
|
1707
|
+
* const { homeDeliveryMethods, pickupLocations } = await client.shipping.getWithLocations("00100");
|
|
1713
1708
|
*
|
|
1714
|
-
*
|
|
1709
|
+
* // Show home delivery options
|
|
1710
|
+
* homeDeliveryMethods.forEach(method => {
|
|
1715
1711
|
* console.log(`${method.name}: ${method.price / 100}€`);
|
|
1716
1712
|
* });
|
|
1717
|
-
* ```
|
|
1718
|
-
*
|
|
1719
|
-
* @example Weight-based filtering
|
|
1720
|
-
* ```typescript
|
|
1721
|
-
* // Pass cart items - SDK calculates weight automatically
|
|
1722
|
-
* const { shipmentMethods } = await client.shipping.getMethods({
|
|
1723
|
-
* cartItems: cartItems
|
|
1724
|
-
* });
|
|
1725
|
-
* ```
|
|
1726
|
-
*/
|
|
1727
|
-
getMethods(options?: GetMethodsOptions): Promise<ShipmentMethodsResponse>;
|
|
1728
|
-
/**
|
|
1729
|
-
* Get shipment methods with pickup locations for a specific postal code.
|
|
1730
|
-
* Calls the Shipit API to fetch nearby pickup points (parcel lockers, etc.)
|
|
1731
|
-
*
|
|
1732
|
-
* @param postalCode - Customer's postal code (e.g., "00100")
|
|
1733
|
-
* @param options - Fetch options including optional cartItems for weight-based filtering
|
|
1734
|
-
* @returns Shipment methods and nearby pickup locations with pricing
|
|
1735
|
-
*
|
|
1736
|
-
* @example
|
|
1737
|
-
* ```typescript
|
|
1738
|
-
* const { shipmentMethods, pricedLocations } = await client.shipping.getWithLocations("00100");
|
|
1739
1713
|
*
|
|
1740
1714
|
* // Show pickup locations
|
|
1741
|
-
*
|
|
1715
|
+
* pickupLocations.forEach(location => {
|
|
1742
1716
|
* console.log(`${location.name} - ${location.carrier}`);
|
|
1743
1717
|
* console.log(` ${location.address1}, ${location.city}`);
|
|
1744
1718
|
* console.log(` ${location.distanceInKilometers.toFixed(1)} km away`);
|
|
1745
|
-
* console.log(` Price: ${
|
|
1719
|
+
* console.log(` Price: ${location.price / 100}€`);
|
|
1746
1720
|
* });
|
|
1747
1721
|
* ```
|
|
1748
1722
|
*
|
|
1749
|
-
* @example Weight-based filtering
|
|
1723
|
+
* @example Weight-based filtering
|
|
1750
1724
|
* ```typescript
|
|
1751
|
-
* const {
|
|
1725
|
+
* const { homeDeliveryMethods, pickupLocations } = await client.shipping.getWithLocations(
|
|
1752
1726
|
* "00100",
|
|
1753
1727
|
* { cartItems: cartItems }
|
|
1754
1728
|
* );
|
|
1755
|
-
*
|
|
1756
1729
|
* // Only shows methods that support the cart's total weight
|
|
1757
1730
|
* ```
|
|
1758
1731
|
*/
|
|
@@ -2472,4 +2445,4 @@ declare class VerificationRequiredError extends StorefrontError {
|
|
|
2472
2445
|
constructor(message: string, customerId: string);
|
|
2473
2446
|
}
|
|
2474
2447
|
|
|
2475
|
-
export { type AddToCartParams, type AddToWishlistResponse, AuthError, type BuyXPayYCampaign, type CalculatedCartItem, type Campaign, type CampaignType, type CartCalculationResult, type CartItem, type CartResponse, type CartSessionOptions, type CartValidationChanges, type CartValidationResponse, type Category, type CategoryReference, type CategoryResponse, type CheckoutCustomerData, type CheckoutErrorCode, type CheckoutErrorDetails, type CheckoutOptions, type CheckoutParams, type CheckoutShipmentMethod, type ConfirmationItemType, type ConfirmationOrderCustomerData, type ConfirmationOrderLineItem, type ConfirmationOrderShipmentMethod, type Customer, type CustomerOrder, type DeleteAccountResponse, type FeatureFlags, type FetchOptions, type ForgotPasswordResponse, type FreeShippingStatus, type GetOrdersResponse, type GetUserResponse, type LoginOptions, type LoginResponse, type LoginVerificationRequiredResponse, type LogoutResponse, NotFoundError, type Order, type OrderLineItem, type OrderProductInfo, type OrderShipmentMethod, type OrderStatus, type PaymentConfig, type PaytrailCheckoutResponse, type PaytrailGroup, type PaytrailProvider, type PickupLocation, type PriceInfo, type Product, type ProductCountResponse, type ProductDetail, type ProductListParams, type ProductListResponse, type ProductSortOption, type ProductVariation, type ProductVariationListing, RateLimitError, type RegisterData, type RegisterResponse, type RemoveFromCartParams, type RemoveFromWishlistResponse, type ResendVerificationResponse, type ResetPasswordResponse, type ShipitShippingMethod, type ShipmentMethod, type
|
|
2448
|
+
export { type AddToCartParams, type AddToWishlistResponse, AuthError, type BuyXPayYCampaign, type CalculatedCartItem, type Campaign, type CampaignType, type CartCalculationResult, type CartItem, type CartResponse, type CartSessionOptions, type CartValidationChanges, type CartValidationResponse, type Category, type CategoryReference, type CategoryResponse, type CheckoutCustomerData, type CheckoutErrorCode, type CheckoutErrorDetails, type CheckoutOptions, type CheckoutParams, type CheckoutShipmentMethod, type ConfirmationItemType, type ConfirmationOrderCustomerData, type ConfirmationOrderLineItem, type ConfirmationOrderShipmentMethod, type Customer, type CustomerOrder, type DeleteAccountResponse, type FeatureFlags, type FetchOptions, type ForgotPasswordResponse, type FreeShippingStatus, type GetOrdersResponse, type GetUserResponse, type LoginOptions, type LoginResponse, type LoginVerificationRequiredResponse, type LogoutResponse, NotFoundError, type Order, type OrderLineItem, type OrderProductInfo, type OrderShipmentMethod, type OrderStatus, type PaymentConfig, type PaytrailCheckoutResponse, type PaytrailGroup, type PaytrailProvider, type PickupLocation, type PriceInfo, type Product, type ProductCountResponse, type ProductDetail, type ProductListParams, type ProductListResponse, type ProductSortOption, type ProductVariation, type ProductVariationListing, RateLimitError, type RegisterData, type RegisterResponse, type RemoveFromCartParams, type RemoveFromWishlistResponse, type ResendVerificationResponse, type ResetPasswordResponse, type ShipitShippingMethod, type ShipmentMethod, type ShipmentMethodsWithLocationsResponse, type StoreConfig, type StoreInfo, type StoreSeo, type StorefrontClient, type StorefrontClientConfig, StorefrontError, type StripeCheckoutResponse, type UpdateCartQuantityParams, type UpdateProfileData, type UpdateProfileResponse, ValidationError, type VariationOption, VerificationRequiredError, type VerifyEmailResponse, type WishlistItem, type WishlistProduct, type WishlistResponse, type WishlistVariation, type WishlistVariationOption, calculateCartWithCampaigns, createStorefrontClient, getPriceInfo, isSaleActive };
|
package/dist/index.d.ts
CHANGED
|
@@ -560,7 +560,7 @@ interface PickupLocationOpeningHours {
|
|
|
560
560
|
}
|
|
561
561
|
/**
|
|
562
562
|
* A pickup location (parcel locker, pickup point, etc.)
|
|
563
|
-
* Returned from Shipit API with
|
|
563
|
+
* Returned from Shipit API with shipmentMethodId and price attached
|
|
564
564
|
*/
|
|
565
565
|
interface PickupLocation {
|
|
566
566
|
/** Unique location ID from Shipit */
|
|
@@ -589,7 +589,7 @@ interface PickupLocation {
|
|
|
589
589
|
distanceInMeters: number;
|
|
590
590
|
/** Distance from postal code in kilometers */
|
|
591
591
|
distanceInKilometers: number;
|
|
592
|
-
/** Location type */
|
|
592
|
+
/** Location type (e.g., "parcel_locker", "service_point", "outdoor_parcel_locker") */
|
|
593
593
|
type?: string;
|
|
594
594
|
/** Structured opening hours */
|
|
595
595
|
openingHours?: PickupLocationOpeningHours | null;
|
|
@@ -597,25 +597,19 @@ interface PickupLocation {
|
|
|
597
597
|
openingHoursRaw?: string | null;
|
|
598
598
|
/** Additional metadata */
|
|
599
599
|
metadata?: unknown | null;
|
|
600
|
-
/**
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
* Response from GET /shipment-methods
|
|
605
|
-
*/
|
|
606
|
-
interface ShipmentMethodsResponse {
|
|
607
|
-
/** Available shipment methods */
|
|
608
|
-
shipmentMethods: ShipmentMethod[];
|
|
600
|
+
/** The shipment method ID this location belongs to */
|
|
601
|
+
shipmentMethodId: string;
|
|
602
|
+
/** Price in cents (from store settings) */
|
|
603
|
+
price: number;
|
|
609
604
|
}
|
|
610
605
|
/**
|
|
611
606
|
* Response from GET /shipment-methods/[postalCode]
|
|
612
|
-
* Includes pickup locations near the postal code
|
|
613
607
|
*/
|
|
614
608
|
interface ShipmentMethodsWithLocationsResponse {
|
|
615
|
-
/**
|
|
616
|
-
|
|
617
|
-
/** Pickup locations
|
|
618
|
-
|
|
609
|
+
/** Home delivery methods (custom methods + Shipit home delivery) */
|
|
610
|
+
homeDeliveryMethods: ShipmentMethod[];
|
|
611
|
+
/** Pickup locations with shipmentMethodId and price attached */
|
|
612
|
+
pickupLocations: PickupLocation[];
|
|
619
613
|
}
|
|
620
614
|
|
|
621
615
|
/**
|
|
@@ -1701,58 +1695,37 @@ interface GetMethodsOptions extends FetchOptions {
|
|
|
1701
1695
|
*/
|
|
1702
1696
|
declare function createShippingResource(fetcher: Fetcher): {
|
|
1703
1697
|
/**
|
|
1704
|
-
* Get
|
|
1705
|
-
* Returns methods
|
|
1698
|
+
* Get shipping options for a specific postal code.
|
|
1699
|
+
* Returns home delivery methods and pickup locations.
|
|
1706
1700
|
*
|
|
1701
|
+
* @param postalCode - Customer's postal code (e.g., "00100")
|
|
1707
1702
|
* @param options - Fetch options including optional cartItems for weight-based filtering
|
|
1708
|
-
* @returns
|
|
1703
|
+
* @returns Home delivery methods and pickup locations
|
|
1709
1704
|
*
|
|
1710
1705
|
* @example
|
|
1711
1706
|
* ```typescript
|
|
1712
|
-
* const {
|
|
1707
|
+
* const { homeDeliveryMethods, pickupLocations } = await client.shipping.getWithLocations("00100");
|
|
1713
1708
|
*
|
|
1714
|
-
*
|
|
1709
|
+
* // Show home delivery options
|
|
1710
|
+
* homeDeliveryMethods.forEach(method => {
|
|
1715
1711
|
* console.log(`${method.name}: ${method.price / 100}€`);
|
|
1716
1712
|
* });
|
|
1717
|
-
* ```
|
|
1718
|
-
*
|
|
1719
|
-
* @example Weight-based filtering
|
|
1720
|
-
* ```typescript
|
|
1721
|
-
* // Pass cart items - SDK calculates weight automatically
|
|
1722
|
-
* const { shipmentMethods } = await client.shipping.getMethods({
|
|
1723
|
-
* cartItems: cartItems
|
|
1724
|
-
* });
|
|
1725
|
-
* ```
|
|
1726
|
-
*/
|
|
1727
|
-
getMethods(options?: GetMethodsOptions): Promise<ShipmentMethodsResponse>;
|
|
1728
|
-
/**
|
|
1729
|
-
* Get shipment methods with pickup locations for a specific postal code.
|
|
1730
|
-
* Calls the Shipit API to fetch nearby pickup points (parcel lockers, etc.)
|
|
1731
|
-
*
|
|
1732
|
-
* @param postalCode - Customer's postal code (e.g., "00100")
|
|
1733
|
-
* @param options - Fetch options including optional cartItems for weight-based filtering
|
|
1734
|
-
* @returns Shipment methods and nearby pickup locations with pricing
|
|
1735
|
-
*
|
|
1736
|
-
* @example
|
|
1737
|
-
* ```typescript
|
|
1738
|
-
* const { shipmentMethods, pricedLocations } = await client.shipping.getWithLocations("00100");
|
|
1739
1713
|
*
|
|
1740
1714
|
* // Show pickup locations
|
|
1741
|
-
*
|
|
1715
|
+
* pickupLocations.forEach(location => {
|
|
1742
1716
|
* console.log(`${location.name} - ${location.carrier}`);
|
|
1743
1717
|
* console.log(` ${location.address1}, ${location.city}`);
|
|
1744
1718
|
* console.log(` ${location.distanceInKilometers.toFixed(1)} km away`);
|
|
1745
|
-
* console.log(` Price: ${
|
|
1719
|
+
* console.log(` Price: ${location.price / 100}€`);
|
|
1746
1720
|
* });
|
|
1747
1721
|
* ```
|
|
1748
1722
|
*
|
|
1749
|
-
* @example Weight-based filtering
|
|
1723
|
+
* @example Weight-based filtering
|
|
1750
1724
|
* ```typescript
|
|
1751
|
-
* const {
|
|
1725
|
+
* const { homeDeliveryMethods, pickupLocations } = await client.shipping.getWithLocations(
|
|
1752
1726
|
* "00100",
|
|
1753
1727
|
* { cartItems: cartItems }
|
|
1754
1728
|
* );
|
|
1755
|
-
*
|
|
1756
1729
|
* // Only shows methods that support the cart's total weight
|
|
1757
1730
|
* ```
|
|
1758
1731
|
*/
|
|
@@ -2472,4 +2445,4 @@ declare class VerificationRequiredError extends StorefrontError {
|
|
|
2472
2445
|
constructor(message: string, customerId: string);
|
|
2473
2446
|
}
|
|
2474
2447
|
|
|
2475
|
-
export { type AddToCartParams, type AddToWishlistResponse, AuthError, type BuyXPayYCampaign, type CalculatedCartItem, type Campaign, type CampaignType, type CartCalculationResult, type CartItem, type CartResponse, type CartSessionOptions, type CartValidationChanges, type CartValidationResponse, type Category, type CategoryReference, type CategoryResponse, type CheckoutCustomerData, type CheckoutErrorCode, type CheckoutErrorDetails, type CheckoutOptions, type CheckoutParams, type CheckoutShipmentMethod, type ConfirmationItemType, type ConfirmationOrderCustomerData, type ConfirmationOrderLineItem, type ConfirmationOrderShipmentMethod, type Customer, type CustomerOrder, type DeleteAccountResponse, type FeatureFlags, type FetchOptions, type ForgotPasswordResponse, type FreeShippingStatus, type GetOrdersResponse, type GetUserResponse, type LoginOptions, type LoginResponse, type LoginVerificationRequiredResponse, type LogoutResponse, NotFoundError, type Order, type OrderLineItem, type OrderProductInfo, type OrderShipmentMethod, type OrderStatus, type PaymentConfig, type PaytrailCheckoutResponse, type PaytrailGroup, type PaytrailProvider, type PickupLocation, type PriceInfo, type Product, type ProductCountResponse, type ProductDetail, type ProductListParams, type ProductListResponse, type ProductSortOption, type ProductVariation, type ProductVariationListing, RateLimitError, type RegisterData, type RegisterResponse, type RemoveFromCartParams, type RemoveFromWishlistResponse, type ResendVerificationResponse, type ResetPasswordResponse, type ShipitShippingMethod, type ShipmentMethod, type
|
|
2448
|
+
export { type AddToCartParams, type AddToWishlistResponse, AuthError, type BuyXPayYCampaign, type CalculatedCartItem, type Campaign, type CampaignType, type CartCalculationResult, type CartItem, type CartResponse, type CartSessionOptions, type CartValidationChanges, type CartValidationResponse, type Category, type CategoryReference, type CategoryResponse, type CheckoutCustomerData, type CheckoutErrorCode, type CheckoutErrorDetails, type CheckoutOptions, type CheckoutParams, type CheckoutShipmentMethod, type ConfirmationItemType, type ConfirmationOrderCustomerData, type ConfirmationOrderLineItem, type ConfirmationOrderShipmentMethod, type Customer, type CustomerOrder, type DeleteAccountResponse, type FeatureFlags, type FetchOptions, type ForgotPasswordResponse, type FreeShippingStatus, type GetOrdersResponse, type GetUserResponse, type LoginOptions, type LoginResponse, type LoginVerificationRequiredResponse, type LogoutResponse, NotFoundError, type Order, type OrderLineItem, type OrderProductInfo, type OrderShipmentMethod, type OrderStatus, type PaymentConfig, type PaytrailCheckoutResponse, type PaytrailGroup, type PaytrailProvider, type PickupLocation, type PriceInfo, type Product, type ProductCountResponse, type ProductDetail, type ProductListParams, type ProductListResponse, type ProductSortOption, type ProductVariation, type ProductVariationListing, RateLimitError, type RegisterData, type RegisterResponse, type RemoveFromCartParams, type RemoveFromWishlistResponse, type ResendVerificationResponse, type ResetPasswordResponse, type ShipitShippingMethod, type ShipmentMethod, type ShipmentMethodsWithLocationsResponse, type StoreConfig, type StoreInfo, type StoreSeo, type StorefrontClient, type StorefrontClientConfig, StorefrontError, type StripeCheckoutResponse, type UpdateCartQuantityParams, type UpdateProfileData, type UpdateProfileResponse, ValidationError, type VariationOption, VerificationRequiredError, type VerifyEmailResponse, type WishlistItem, type WishlistProduct, type WishlistResponse, type WishlistVariation, type WishlistVariationOption, calculateCartWithCampaigns, createStorefrontClient, getPriceInfo, isSaleActive };
|
package/dist/index.js
CHANGED
|
@@ -620,70 +620,37 @@ function calculateCartWeight(items) {
|
|
|
620
620
|
function createShippingResource(fetcher) {
|
|
621
621
|
return {
|
|
622
622
|
/**
|
|
623
|
-
* Get
|
|
624
|
-
* Returns methods
|
|
623
|
+
* Get shipping options for a specific postal code.
|
|
624
|
+
* Returns home delivery methods and pickup locations.
|
|
625
625
|
*
|
|
626
|
+
* @param postalCode - Customer's postal code (e.g., "00100")
|
|
626
627
|
* @param options - Fetch options including optional cartItems for weight-based filtering
|
|
627
|
-
* @returns
|
|
628
|
+
* @returns Home delivery methods and pickup locations
|
|
628
629
|
*
|
|
629
630
|
* @example
|
|
630
631
|
* ```typescript
|
|
631
|
-
* const {
|
|
632
|
+
* const { homeDeliveryMethods, pickupLocations } = await client.shipping.getWithLocations("00100");
|
|
632
633
|
*
|
|
633
|
-
*
|
|
634
|
+
* // Show home delivery options
|
|
635
|
+
* homeDeliveryMethods.forEach(method => {
|
|
634
636
|
* console.log(`${method.name}: ${method.price / 100}€`);
|
|
635
637
|
* });
|
|
636
|
-
* ```
|
|
637
|
-
*
|
|
638
|
-
* @example Weight-based filtering
|
|
639
|
-
* ```typescript
|
|
640
|
-
* // Pass cart items - SDK calculates weight automatically
|
|
641
|
-
* const { shipmentMethods } = await client.shipping.getMethods({
|
|
642
|
-
* cartItems: cartItems
|
|
643
|
-
* });
|
|
644
|
-
* ```
|
|
645
|
-
*/
|
|
646
|
-
async getMethods(options) {
|
|
647
|
-
const params = new URLSearchParams();
|
|
648
|
-
if (options?.cartItems?.length) {
|
|
649
|
-
const cartWeight = calculateCartWeight(options.cartItems);
|
|
650
|
-
params.set("cartWeight", cartWeight.toString());
|
|
651
|
-
}
|
|
652
|
-
const queryString = params.toString();
|
|
653
|
-
const url = `/api/storefront/v1/shipment-methods${queryString ? `?${queryString}` : ""}`;
|
|
654
|
-
return fetcher.request(url, {
|
|
655
|
-
method: "GET",
|
|
656
|
-
...options
|
|
657
|
-
});
|
|
658
|
-
},
|
|
659
|
-
/**
|
|
660
|
-
* Get shipment methods with pickup locations for a specific postal code.
|
|
661
|
-
* Calls the Shipit API to fetch nearby pickup points (parcel lockers, etc.)
|
|
662
|
-
*
|
|
663
|
-
* @param postalCode - Customer's postal code (e.g., "00100")
|
|
664
|
-
* @param options - Fetch options including optional cartItems for weight-based filtering
|
|
665
|
-
* @returns Shipment methods and nearby pickup locations with pricing
|
|
666
|
-
*
|
|
667
|
-
* @example
|
|
668
|
-
* ```typescript
|
|
669
|
-
* const { shipmentMethods, pricedLocations } = await client.shipping.getWithLocations("00100");
|
|
670
638
|
*
|
|
671
639
|
* // Show pickup locations
|
|
672
|
-
*
|
|
640
|
+
* pickupLocations.forEach(location => {
|
|
673
641
|
* console.log(`${location.name} - ${location.carrier}`);
|
|
674
642
|
* console.log(` ${location.address1}, ${location.city}`);
|
|
675
643
|
* console.log(` ${location.distanceInKilometers.toFixed(1)} km away`);
|
|
676
|
-
* console.log(` Price: ${
|
|
644
|
+
* console.log(` Price: ${location.price / 100}€`);
|
|
677
645
|
* });
|
|
678
646
|
* ```
|
|
679
647
|
*
|
|
680
|
-
* @example Weight-based filtering
|
|
648
|
+
* @example Weight-based filtering
|
|
681
649
|
* ```typescript
|
|
682
|
-
* const {
|
|
650
|
+
* const { homeDeliveryMethods, pickupLocations } = await client.shipping.getWithLocations(
|
|
683
651
|
* "00100",
|
|
684
652
|
* { cartItems: cartItems }
|
|
685
653
|
* );
|
|
686
|
-
*
|
|
687
654
|
* // Only shows methods that support the cart's total weight
|
|
688
655
|
* ```
|
|
689
656
|
*/
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/errors.ts","../src/utils/fetch.ts","../src/resources/store.ts","../src/resources/products.ts","../src/resources/categories.ts","../src/resources/cart.ts","../src/resources/shipping.ts","../src/resources/customer.ts","../src/resources/order.ts","../src/resources/checkout.ts","../src/client.ts","../src/utils/pricing.ts","../src/utils/cart-calculations.ts"],"sourcesContent":["/**\n * Base error class for all Storefront API errors\n */\nexport class StorefrontError extends Error {\n public readonly status: number;\n public readonly code: string;\n\n constructor(message: string, status: number, code: string) {\n super(message);\n this.name = \"StorefrontError\";\n this.status = status;\n this.code = code;\n\n // Maintains proper stack trace in V8 environments\n const ErrorWithCapture = Error as typeof Error & {\n captureStackTrace?: (target: object, constructor: Function) => void;\n };\n if (ErrorWithCapture.captureStackTrace) {\n ErrorWithCapture.captureStackTrace(this, StorefrontError);\n }\n }\n}\n\n/**\n * Error thrown when API returns 401 Unauthorized\n */\nexport class AuthError extends StorefrontError {\n constructor(message: string = \"Invalid or missing API key\") {\n super(message, 401, \"UNAUTHORIZED\");\n this.name = \"AuthError\";\n }\n}\n\n/**\n * Error thrown when API returns 429 Too Many Requests\n */\nexport class RateLimitError extends StorefrontError {\n public readonly retryAfter: number | null;\n\n constructor(message: string = \"Rate limit exceeded\", retryAfter: number | null = null) {\n super(message, 429, \"RATE_LIMIT_EXCEEDED\");\n this.name = \"RateLimitError\";\n this.retryAfter = retryAfter;\n }\n}\n\n/**\n * Error thrown when a requested resource is not found (404)\n */\nexport class NotFoundError extends StorefrontError {\n constructor(message: string = \"Resource not found\") {\n super(message, 404, \"NOT_FOUND\");\n this.name = \"NotFoundError\";\n }\n}\n\n/**\n * Error thrown when request validation fails (400)\n */\nexport class ValidationError extends StorefrontError {\n constructor(message: string = \"Validation failed\") {\n super(message, 400, \"VALIDATION_ERROR\");\n this.name = \"ValidationError\";\n }\n}\n\n/**\n * Error thrown when login fails due to unverified email\n * Contains customerId for resending verification email\n */\nexport class VerificationRequiredError extends StorefrontError {\n public readonly requiresVerification: true = true;\n public readonly customerId: string;\n\n constructor(message: string, customerId: string) {\n super(message, 403, \"VERIFICATION_REQUIRED\");\n this.name = \"VerificationRequiredError\";\n this.customerId = customerId;\n }\n}\n","import type { FetchOptions } from \"../types/index.js\";\r\nimport {\r\n StorefrontError,\r\n AuthError,\r\n RateLimitError,\r\n NotFoundError,\r\n ValidationError,\r\n VerificationRequiredError,\r\n} from \"./errors.js\";\r\n\r\n// SDK version - will be replaced during build or read from package.json\r\nconst SDK_VERSION = \"0.1.0\";\r\n\r\nexport interface FetcherConfig {\r\n apiKey: string;\r\n baseUrl: string;\r\n timeout?: number;\r\n}\r\n\r\nexport interface RequestOptions extends FetchOptions {\r\n method?: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\r\n body?: unknown;\r\n params?: Record<string, string | number | boolean | undefined>;\r\n}\r\n\r\n/**\r\n * Fetcher instance type returned by createFetcher\r\n */\r\nexport type Fetcher = ReturnType<typeof createFetcher>;\r\n\r\n/**\r\n * Create a configured fetcher instance for making API requests\r\n */\r\nexport function createFetcher(config: FetcherConfig) {\r\n const { apiKey, baseUrl, timeout = 30000 } = config;\r\n\r\n /**\r\n * Make an authenticated request to the Storefront API\r\n */\r\n async function request<T>(endpoint: string, options: RequestOptions = {}): Promise<T> {\r\n const { method = \"GET\", body, params, signal, headers = {}, cache, ...frameworkOptions } = options;\r\n\r\n // Build URL with query parameters\r\n // Ensure baseUrl ends with / for proper URL resolution\r\n const normalizedBase = baseUrl.endsWith(\"/\") ? baseUrl : `${baseUrl}/`;\r\n // Remove leading slash from endpoint to avoid URL resolution issues\r\n const normalizedEndpoint = endpoint.startsWith(\"/\") ? endpoint.slice(1) : endpoint;\r\n const url = new URL(normalizedEndpoint, normalizedBase);\r\n\r\n if (params) {\r\n for (const [key, value] of Object.entries(params)) {\r\n if (value !== undefined) {\r\n url.searchParams.set(key, String(value));\r\n }\r\n }\r\n }\r\n\r\n // Create abort controller for timeout\r\n const controller = new AbortController();\r\n const timeoutId = setTimeout(() => controller.abort(), timeout);\r\n\r\n // Combine signals if provided\r\n const combinedSignal = signal\r\n ? AbortSignal.any([signal, controller.signal])\r\n : controller.signal;\r\n\r\n try {\r\n const fetchOptions: RequestInit & Record<string, unknown> = {\r\n method,\r\n headers: {\r\n \"Content-Type\": \"application/json\",\r\n \"x-api-key\": apiKey,\r\n \"x-sdk-version\": SDK_VERSION,\r\n ...headers,\r\n },\r\n body: body ? JSON.stringify(body) : undefined,\r\n signal: combinedSignal,\r\n cache,\r\n // Spread framework-specific options (e.g., Next.js `next`, or any other)\r\n ...frameworkOptions,\r\n };\r\n\r\n const response = await fetch(url.toString(), fetchOptions);\r\n\r\n clearTimeout(timeoutId);\r\n\r\n // Handle error responses\r\n if (!response.ok) {\r\n await handleErrorResponse(response);\r\n }\r\n\r\n // Parse response\r\n const data = await response.json();\r\n return data as T;\r\n } catch (error) {\r\n clearTimeout(timeoutId);\r\n\r\n // Re-throw SDK errors\r\n if (error instanceof StorefrontError) {\r\n throw error;\r\n }\r\n\r\n // Handle abort/timeout\r\n if (error instanceof Error && error.name === \"AbortError\") {\r\n throw new StorefrontError(\"Request timed out\", 408, \"TIMEOUT\");\r\n }\r\n\r\n // Handle network errors\r\n throw new StorefrontError(\r\n error instanceof Error ? error.message : \"Network error\",\r\n 0,\r\n \"NETWORK_ERROR\"\r\n );\r\n }\r\n }\r\n\r\n return { request };\r\n}\r\n\r\n/**\r\n * Error response JSON structure\r\n */\r\ninterface ErrorResponseJson {\r\n error?: string;\r\n requiresVerification?: boolean;\r\n customerId?: string;\r\n}\r\n\r\n/**\r\n * Handle non-2xx responses and throw appropriate errors\r\n */\r\nasync function handleErrorResponse(response: Response): Promise<never> {\r\n let errorData: ErrorResponseJson = {};\r\n\r\n try {\r\n const json: unknown = await response.json();\r\n if (json && typeof json === \"object\") {\r\n errorData = json as ErrorResponseJson;\r\n }\r\n } catch {\r\n // Response body is not JSON\r\n }\r\n\r\n const message = errorData.error || response.statusText || \"Request failed\";\r\n\r\n // Check for verification required error (can be 400 or 403)\r\n if (errorData.requiresVerification && errorData.customerId) {\r\n throw new VerificationRequiredError(message, errorData.customerId);\r\n }\r\n\r\n switch (response.status) {\r\n case 401:\r\n throw new AuthError(message);\r\n\r\n case 404:\r\n throw new NotFoundError(message);\r\n\r\n case 429: {\r\n const retryAfter = response.headers.get(\"Retry-After\");\r\n throw new RateLimitError(message, retryAfter ? parseInt(retryAfter, 10) : null);\r\n }\r\n\r\n case 400:\r\n throw new ValidationError(message);\r\n\r\n default:\r\n throw new StorefrontError(message, response.status, \"API_ERROR\");\r\n }\r\n}\r\n","import type { FetchOptions, StoreConfig } from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Store resource for fetching store configuration\r\n */\r\nexport function createStoreResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get the complete store configuration including settings, SEO, payments, campaigns, and features.\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const config = await client.store.getConfig();\r\n * console.log(config.store.name);\r\n * console.log(config.seo.seoTitle);\r\n * console.log(config.campaigns);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const config = await client.store.getConfig({\r\n * next: { revalidate: 300, tags: ['store-config'] }\r\n * });\r\n * ```\r\n *\r\n * @example Nuxt - wrap with useAsyncData\r\n * ```typescript\r\n * const { data: config } = await useAsyncData(\r\n * 'store-config',\r\n * () => client.store.getConfig()\r\n * );\r\n * ```\r\n *\r\n * @example Standard fetch caching\r\n * ```typescript\r\n * const config = await client.store.getConfig({\r\n * cache: 'force-cache'\r\n * });\r\n * ```\r\n */\r\n async getConfig(options?: FetchOptions): Promise<StoreConfig> {\r\n return fetcher.request<StoreConfig>(\"/api/storefront/v1/store-config\", {\r\n ...options,\r\n });\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the store resource\r\n */\r\nexport type StoreResource = ReturnType<typeof createStoreResource>;\r\n","import type {\r\n FetchOptions,\r\n Product,\r\n ProductDetail,\r\n ProductListResponse,\r\n ProductCountResponse,\r\n ProductListParams,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Products resource for fetching product data\r\n */\r\nexport function createProductsResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get latest products ordered by creation date (newest first).\r\n *\r\n * @param take - Number of products to return (required, must be >= 1)\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Array of products\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const products = await client.products.latest(6);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const products = await client.products.latest(6, {\r\n * next: { revalidate: 3600, tags: ['products'] }\r\n * });\r\n * ```\r\n */\r\n async latest(take: number, options?: FetchOptions): Promise<Product[]> {\r\n return fetcher.request<Product[]>(\"/api/storefront/v1/latest-products\", {\r\n params: { take },\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * Get a single product by its URL slug.\r\n *\r\n * @param slug - Product URL slug\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Full product details including categories and variations\r\n * @throws NotFoundError if product doesn't exist or is not visible\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const product = await client.products.getBySlug('my-product');\r\n * console.log(product.name, product.categories);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const product = await client.products.getBySlug('my-product', {\r\n * next: { revalidate: 3600, tags: ['product', 'my-product'] }\r\n * });\r\n * ```\r\n */\r\n async getBySlug(\r\n slug: string,\r\n options?: FetchOptions\r\n ): Promise<ProductDetail> {\r\n return fetcher.request<ProductDetail>(\r\n `/api/storefront/v1/product/${encodeURIComponent(slug)}`,\r\n {\r\n ...options,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Get total product count, optionally filtered by category.\r\n *\r\n * @param slugs - Optional category slugs to filter by\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Object with count property\r\n *\r\n * @example Get total count\r\n * ```typescript\r\n * const { count } = await client.products.count();\r\n * console.log(`Total products: ${count}`);\r\n * ```\r\n *\r\n * @example Get count for specific category\r\n * ```typescript\r\n * const { count } = await client.products.count(['shoes']);\r\n * console.log(`Products in shoes: ${count}`);\r\n * ```\r\n */\r\n async count(\r\n slugs?: string[],\r\n options?: FetchOptions\r\n ): Promise<ProductCountResponse> {\r\n const searchParams = new URLSearchParams();\r\n if (slugs?.length) {\r\n slugs.forEach((s) => searchParams.append(\"slugs\", s));\r\n }\r\n const query = searchParams.toString();\r\n const endpoint = `/api/storefront/v1/products-count${query ? `?${query}` : \"\"}`;\r\n\r\n return fetcher.request<ProductCountResponse>(endpoint, {\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * Get sorted products with pagination.\r\n * Uses optimized sorting with pre-computed effective prices.\r\n *\r\n * @param params - Query parameters (slugs, page, pageSize, sort)\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Products list with totalCount for pagination\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const { products, totalCount } = await client.products.sorted({\r\n * page: 1,\r\n * pageSize: 12,\r\n * sort: 'newest'\r\n * });\r\n * ```\r\n *\r\n * @example Filter by category\r\n * ```typescript\r\n * const { products, totalCount } = await client.products.sorted({\r\n * slugs: ['shoes', 'clothing'],\r\n * page: 1,\r\n * pageSize: 24,\r\n * sort: 'price_asc'\r\n * });\r\n * ```\r\n *\r\n * @example Real-time data (no cache)\r\n * ```typescript\r\n * const data = await client.products.sorted(\r\n * { page: 1, pageSize: 12 },\r\n * { cache: 'no-store' }\r\n * );\r\n * ```\r\n */\r\n async sorted(\r\n params: ProductListParams = {},\r\n options?: FetchOptions\r\n ): Promise<ProductListResponse> {\r\n const searchParams = new URLSearchParams();\r\n if (params.page) searchParams.set(\"page\", params.page.toString());\r\n if (params.pageSize)\r\n searchParams.set(\"pageSize\", params.pageSize.toString());\r\n if (params.sort) searchParams.set(\"sort\", params.sort);\r\n if (params.slugs?.length) {\r\n params.slugs.forEach((s) => searchParams.append(\"slugs\", s));\r\n }\r\n const query = searchParams.toString();\r\n const endpoint = `/api/storefront/v1/sorted-products${query ? `?${query}` : \"\"}`;\r\n\r\n return fetcher.request<ProductListResponse>(endpoint, {\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * Get filtered products with pagination.\r\n * Similar to sorted() but without totalCount in response.\r\n * Useful for sitemaps and bulk fetches.\r\n *\r\n * @param params - Query parameters (slugs, page, pageSize, sort)\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Products list with category name\r\n *\r\n * @example Fetch all products for sitemap\r\n * ```typescript\r\n * const { products } = await client.products.filtered({\r\n * slugs: ['all-products'],\r\n * page: 1,\r\n * pageSize: 1000\r\n * });\r\n * ```\r\n */\r\n async filtered(\r\n params: ProductListParams = {},\r\n options?: FetchOptions\r\n ): Promise<Omit<ProductListResponse, \"totalCount\">> {\r\n const searchParams = new URLSearchParams();\r\n if (params.page) searchParams.set(\"page\", params.page.toString());\r\n if (params.pageSize)\r\n searchParams.set(\"pageSize\", params.pageSize.toString());\r\n if (params.sort) searchParams.set(\"sort\", params.sort);\r\n if (params.slugs?.length) {\r\n params.slugs.forEach((s) => searchParams.append(\"slugs\", s));\r\n }\r\n const query = searchParams.toString();\r\n const endpoint = `/api/storefront/v1/filtered-products${query ? `?${query}` : \"\"}`;\r\n\r\n return fetcher.request<Omit<ProductListResponse, \"totalCount\">>(\r\n endpoint,\r\n {\r\n ...options,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the products resource\r\n */\r\nexport type ProductsResource = ReturnType<typeof createProductsResource>;\r\n","import type { FetchOptions, Category, CategoryResponse } from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Categories resource for fetching category data\r\n */\r\nexport function createCategoriesResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get all top-level categories with nested children.\r\n * Returns a hierarchical tree of categories (up to 5 levels deep).\r\n *\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Array of top-level categories with nested children\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const categories = await client.categories.list();\r\n * categories.forEach(cat => {\r\n * console.log(cat.name, cat.children.length);\r\n * });\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const categories = await client.categories.list({\r\n * next: { revalidate: 3600, tags: ['categories'] }\r\n * });\r\n * ```\r\n */\r\n async list(options?: FetchOptions): Promise<Category[]> {\r\n return fetcher.request<Category[]>(\"/api/storefront/v1/categories\", {\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * Get a single category by its URL slug.\r\n *\r\n * @param slug - Category URL slug\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Category data\r\n * @throws NotFoundError if category doesn't exist\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const { category } = await client.categories.getBySlug('shoes');\r\n * console.log(category.name);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const { category } = await client.categories.getBySlug('shoes', {\r\n * next: { revalidate: 86400, tags: ['category', 'shoes'] }\r\n * });\r\n * ```\r\n */\r\n async getBySlug(\r\n slug: string,\r\n options?: FetchOptions\r\n ): Promise<CategoryResponse> {\r\n return fetcher.request<CategoryResponse>(\r\n `/api/storefront/v1/categories/${encodeURIComponent(slug)}`,\r\n {\r\n ...options,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the categories resource\r\n */\r\nexport type CategoriesResource = ReturnType<typeof createCategoriesResource>;\r\n","/**\r\n * Cart Resource\r\n *\r\n * Methods for managing the shopping cart stored in Redis.\r\n * Supports both guest carts (via cartId) and authenticated user carts (via sessionId).\r\n */\r\n\r\nimport type {\r\n FetchOptions,\r\n CartResponse,\r\n CartValidationResponse,\r\n CartSessionOptions,\r\n AddToCartParams,\r\n UpdateCartQuantityParams,\r\n RemoveFromCartParams,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Build headers object for cart operations\r\n */\r\nfunction buildCartHeaders(options?: CartSessionOptions): Record<string, string> {\r\n const headers: Record<string, string> = {};\r\n if (options?.cartId) {\r\n headers[\"x-cart-id\"] = options.cartId;\r\n }\r\n if (options?.sessionId) {\r\n headers[\"x-session-id\"] = options.sessionId;\r\n }\r\n return headers;\r\n}\r\n\r\n/**\r\n * Cart resource for managing shopping cart\r\n */\r\nexport function createCartResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Fetch the current cart contents.\r\n *\r\n * @param options - Cart session options (cartId for guests, sessionId for logged-in users)\r\n * @param fetchOptions - Fetch options (caching, headers, etc.)\r\n * @returns Cart items and cartId (for guests)\r\n *\r\n * @example Guest user\r\n * ```typescript\r\n * const cartId = localStorage.getItem('cart-id');\r\n * const { items, cartId: newCartId } = await client.cart.get({ cartId });\r\n * ```\r\n *\r\n * @example Logged-in user\r\n * ```typescript\r\n * const { items } = await client.cart.get({ sessionId });\r\n * ```\r\n */\r\n async get(\r\n options?: CartSessionOptions,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartResponse> {\r\n return fetcher.request<CartResponse>(\"/api/storefront/v1/cart\", {\r\n method: \"GET\",\r\n headers: buildCartHeaders(options),\r\n ...fetchOptions,\r\n });\r\n },\r\n\r\n /**\r\n * Add an item to the cart.\r\n * If the item already exists, quantity is incremented.\r\n *\r\n * @param params - Add to cart parameters\r\n * @param fetchOptions - Fetch options\r\n * @returns Updated cart with new cartId for guests\r\n * @throws ValidationError if quantity exceeds available stock\r\n *\r\n * @example Add product\r\n * ```typescript\r\n * const { items, cartId } = await client.cart.addItem({\r\n * cartId: existingCartId,\r\n * productId: 'prod_123',\r\n * quantity: 2\r\n * });\r\n * // Save cartId for future requests\r\n * localStorage.setItem('cart-id', cartId);\r\n * ```\r\n *\r\n * @example Add product with variation\r\n * ```typescript\r\n * const { items, cartId } = await client.cart.addItem({\r\n * cartId,\r\n * productId: 'prod_123',\r\n * variationId: 'var_456',\r\n * quantity: 1\r\n * });\r\n * ```\r\n */\r\n async addItem(\r\n params: AddToCartParams,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartResponse> {\r\n const { cartId, sessionId, ...body } = params;\r\n return fetcher.request<CartResponse>(\"/api/storefront/v1/cart\", {\r\n method: \"POST\",\r\n headers: buildCartHeaders({ sessionId }),\r\n body: {\r\n cartId,\r\n ...body,\r\n },\r\n ...fetchOptions,\r\n });\r\n },\r\n\r\n /**\r\n * Update item quantity by delta (atomic operation).\r\n * Use positive delta to increase, negative to decrease.\r\n * Minimum quantity is 1 (use removeItem to delete).\r\n *\r\n * @param params - Update quantity parameters\r\n * @param fetchOptions - Fetch options\r\n * @returns Updated cart\r\n * @throws NotFoundError if item not in cart or quantity would go below 1\r\n *\r\n * @example Increment quantity\r\n * ```typescript\r\n * const { items } = await client.cart.updateQuantity({\r\n * cartId,\r\n * productId: 'prod_123',\r\n * delta: 1\r\n * });\r\n * ```\r\n *\r\n * @example Decrement quantity\r\n * ```typescript\r\n * const { items } = await client.cart.updateQuantity({\r\n * cartId,\r\n * productId: 'prod_123',\r\n * variationId: 'var_456',\r\n * delta: -1\r\n * });\r\n * ```\r\n */\r\n async updateQuantity(\r\n params: UpdateCartQuantityParams,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartResponse> {\r\n const { cartId, sessionId, ...body } = params;\r\n return fetcher.request<CartResponse>(\"/api/storefront/v1/cart\", {\r\n method: \"PATCH\",\r\n headers: buildCartHeaders({ sessionId }),\r\n body: {\r\n cartId,\r\n ...body,\r\n },\r\n ...fetchOptions,\r\n });\r\n },\r\n\r\n /**\r\n * Remove an item from the cart.\r\n *\r\n * @param params - Remove from cart parameters\r\n * @param fetchOptions - Fetch options\r\n * @returns Updated cart\r\n *\r\n * @example Remove product\r\n * ```typescript\r\n * const { items } = await client.cart.removeItem({\r\n * cartId,\r\n * productId: 'prod_123'\r\n * });\r\n * ```\r\n *\r\n * @example Remove variation\r\n * ```typescript\r\n * const { items } = await client.cart.removeItem({\r\n * cartId,\r\n * productId: 'prod_123',\r\n * variationId: 'var_456'\r\n * });\r\n * ```\r\n */\r\n async removeItem(\r\n params: RemoveFromCartParams,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartResponse> {\r\n const { cartId, sessionId, ...body } = params;\r\n return fetcher.request<CartResponse>(\"/api/storefront/v1/cart\", {\r\n method: \"DELETE\",\r\n headers: buildCartHeaders({ sessionId }),\r\n body: {\r\n cartId,\r\n ...body,\r\n },\r\n ...fetchOptions,\r\n });\r\n },\r\n\r\n /**\r\n * Validate cart before checkout.\r\n * Checks product availability, stock levels, and prices.\r\n * Auto-fixes issues (removes unavailable items, adjusts quantities).\r\n *\r\n * @param options - Cart session options\r\n * @param fetchOptions - Fetch options\r\n * @returns Validated cart with change metadata\r\n *\r\n * @example Validate before checkout\r\n * ```typescript\r\n * const { items, hasChanges, changes } = await client.cart.validate({ cartId });\r\n *\r\n * if (hasChanges) {\r\n * if (changes.removedItems > 0) {\r\n * notify('Some items were removed (out of stock)');\r\n * }\r\n * if (changes.quantityAdjusted > 0) {\r\n * notify('Some quantities were adjusted');\r\n * }\r\n * if (changes.priceChanged > 0) {\r\n * notify('Some prices have changed');\r\n * }\r\n * }\r\n * ```\r\n */\r\n async validate(\r\n options?: CartSessionOptions,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartValidationResponse> {\r\n return fetcher.request<CartValidationResponse>(\r\n \"/api/storefront/v1/cart/validate\",\r\n {\r\n method: \"GET\",\r\n headers: buildCartHeaders(options),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the cart resource\r\n */\r\nexport type CartResource = ReturnType<typeof createCartResource>;\r\n","/**\r\n * Shipping Resource\r\n *\r\n * Methods for fetching shipment methods and pickup locations.\r\n */\r\n\r\nimport type {\r\n FetchOptions,\r\n ShipmentMethodsResponse,\r\n ShipmentMethodsWithLocationsResponse,\r\n CartItem,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Calculate total cart weight from cart items\r\n */\r\nfunction calculateCartWeight(items: CartItem[]): number {\r\n return items.reduce((total, item) => {\r\n const itemWeight = item.variation?.weight ?? item.product.weight ?? 0.5;\r\n return total + itemWeight * item.cartQuantity;\r\n }, 0);\r\n}\r\n\r\n/**\r\n * Options for fetching shipment methods with weight-based filtering\r\n */\r\nexport interface GetMethodsOptions extends FetchOptions {\r\n /** Cart items - weight will be calculated automatically */\r\n cartItems?: CartItem[];\r\n}\r\n\r\n/**\r\n * Shipping resource for fetching shipment methods and pickup locations\r\n */\r\nexport function createShippingResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get all available shipment methods for the store.\r\n * Returns methods without pickup locations - use `getWithLocations` for postal code specific data.\r\n *\r\n * @param options - Fetch options including optional cartItems for weight-based filtering\r\n * @returns Available shipment methods\r\n *\r\n * @example\r\n * ```typescript\r\n * const { shipmentMethods } = await client.shipping.getMethods();\r\n *\r\n * shipmentMethods.forEach(method => {\r\n * console.log(`${method.name}: ${method.price / 100}€`);\r\n * });\r\n * ```\r\n *\r\n * @example Weight-based filtering\r\n * ```typescript\r\n * // Pass cart items - SDK calculates weight automatically\r\n * const { shipmentMethods } = await client.shipping.getMethods({\r\n * cartItems: cartItems\r\n * });\r\n * ```\r\n */\r\n async getMethods(\r\n options?: GetMethodsOptions\r\n ): Promise<ShipmentMethodsResponse> {\r\n const params = new URLSearchParams();\r\n if (options?.cartItems?.length) {\r\n const cartWeight = calculateCartWeight(options.cartItems);\r\n params.set(\"cartWeight\", cartWeight.toString());\r\n }\r\n const queryString = params.toString();\r\n const url = `/api/storefront/v1/shipment-methods${queryString ? `?${queryString}` : \"\"}`;\r\n\r\n return fetcher.request<ShipmentMethodsResponse>(url, {\r\n method: \"GET\",\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * Get shipment methods with pickup locations for a specific postal code.\r\n * Calls the Shipit API to fetch nearby pickup points (parcel lockers, etc.)\r\n *\r\n * @param postalCode - Customer's postal code (e.g., \"00100\")\r\n * @param options - Fetch options including optional cartItems for weight-based filtering\r\n * @returns Shipment methods and nearby pickup locations with pricing\r\n *\r\n * @example\r\n * ```typescript\r\n * const { shipmentMethods, pricedLocations } = await client.shipping.getWithLocations(\"00100\");\r\n *\r\n * // Show pickup locations\r\n * pricedLocations.forEach(location => {\r\n * console.log(`${location.name} - ${location.carrier}`);\r\n * console.log(` ${location.address1}, ${location.city}`);\r\n * console.log(` ${location.distanceInKilometers.toFixed(1)} km away`);\r\n * console.log(` Price: ${(location.merchantPrice ?? 0) / 100}€`);\r\n * });\r\n * ```\r\n *\r\n * @example Weight-based filtering with postal code\r\n * ```typescript\r\n * const { shipmentMethods, pricedLocations } = await client.shipping.getWithLocations(\r\n * \"00100\",\r\n * { cartItems: cartItems }\r\n * );\r\n *\r\n * // Only shows methods that support the cart's total weight\r\n * ```\r\n */\r\n async getWithLocations(\r\n postalCode: string,\r\n options?: GetMethodsOptions\r\n ): Promise<ShipmentMethodsWithLocationsResponse> {\r\n const params = new URLSearchParams();\r\n if (options?.cartItems?.length) {\r\n const cartWeight = calculateCartWeight(options.cartItems);\r\n params.set(\"cartWeight\", cartWeight.toString());\r\n }\r\n const queryString = params.toString();\r\n const url = `/api/storefront/v1/shipment-methods/${encodeURIComponent(postalCode)}${queryString ? `?${queryString}` : \"\"}`;\r\n\r\n return fetcher.request<ShipmentMethodsWithLocationsResponse>(url, {\r\n method: \"GET\",\r\n ...options,\r\n });\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the shipping resource\r\n */\r\nexport type ShippingResource = ReturnType<typeof createShippingResource>;\r\n","/**\r\n * Customer Resource\r\n *\r\n * Methods for customer authentication and account management.\r\n * Supports session-based authentication with the x-session-id header.\r\n */\r\n\r\nimport type {\r\n FetchOptions,\r\n RegisterData,\r\n RegisterResponse,\r\n LoginOptions,\r\n LoginResponse,\r\n LogoutResponse,\r\n GetUserResponse,\r\n VerifyEmailResponse,\r\n ResendVerificationResponse,\r\n UpdateProfileData,\r\n UpdateProfileResponse,\r\n DeleteAccountResponse,\r\n GetOrdersResponse,\r\n WishlistResponse,\r\n AddToWishlistResponse,\r\n RemoveFromWishlistResponse,\r\n ForgotPasswordResponse,\r\n ResetPasswordResponse,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Build headers for authenticated customer requests\r\n */\r\nfunction buildSessionHeaders(sessionId: string): Record<string, string> {\r\n return { \"x-session-id\": sessionId };\r\n}\r\n\r\n/**\r\n * Customer resource for authentication and account management\r\n */\r\nexport function createCustomerResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Register a new customer account.\r\n * A verification email is sent automatically by the server.\r\n * The customer must verify their email before logging in.\r\n *\r\n * @param data - Registration data (firstName, lastName, email, password)\r\n * @param fetchOptions - Fetch options\r\n * @returns Created customer data and success message\r\n *\r\n * @example\r\n * ```typescript\r\n * const { customer, message } = await client.customer.register({\r\n * firstName: 'John',\r\n * lastName: 'Doe',\r\n * email: 'john@example.com',\r\n * password: 'securePassword123'\r\n * });\r\n *\r\n * // Verification email is sent automatically by the server\r\n * console.log('Account created:', message);\r\n * ```\r\n */\r\n async register(\r\n data: RegisterData,\r\n fetchOptions?: FetchOptions\r\n ): Promise<RegisterResponse> {\r\n return fetcher.request<RegisterResponse>(\r\n \"/api/storefront/v1/customer/(auth)/register\",\r\n {\r\n method: \"POST\",\r\n body: data,\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Log in an existing customer.\r\n * Returns a session ID that must be stored and passed to authenticated endpoints.\r\n *\r\n * @param email - Customer's email address\r\n * @param password - Customer's password\r\n * @param options - Login options (optional cartId for cart merging)\r\n * @param fetchOptions - Fetch options\r\n * @returns Session ID and customer data\r\n * @throws ValidationError if email is not verified (check error for requiresVerification)\r\n *\r\n * @example\r\n * ```typescript\r\n * try {\r\n * const { sessionId, customer, expiresAt } = await client.customer.login(\r\n * 'john@example.com',\r\n * 'securePassword123',\r\n * { cartId: guestCartId } // Optional: merge guest cart\r\n * );\r\n *\r\n * // Store sessionId in a cookie\r\n * cookies().set('session-id', sessionId, {\r\n * httpOnly: true,\r\n * expires: new Date(expiresAt)\r\n * });\r\n * } catch (error) {\r\n * if (error.requiresVerification) {\r\n * // Prompt user to verify email\r\n * await client.customer.resendVerification(error.customerId);\r\n * }\r\n * }\r\n * ```\r\n */\r\n async login(\r\n email: string,\r\n password: string,\r\n options?: LoginOptions,\r\n fetchOptions?: FetchOptions\r\n ): Promise<LoginResponse> {\r\n const headers: Record<string, string> = {};\r\n if (options?.cartId) {\r\n headers[\"x-cart-id\"] = options.cartId;\r\n }\r\n\r\n return fetcher.request<LoginResponse>(\r\n \"/api/storefront/v1/customer/(auth)/login\",\r\n {\r\n method: \"POST\",\r\n body: { email, password },\r\n headers,\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Log out the current customer and invalidate their session.\r\n * If the customer had items in their cart, they are migrated to a new guest cart.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param fetchOptions - Fetch options\r\n * @returns Logout confirmation with optional new guest cart ID\r\n *\r\n * @example\r\n * ```typescript\r\n * const { cartId } = await client.customer.logout(sessionId);\r\n *\r\n * // Clear session cookie\r\n * cookies().delete('session-id');\r\n *\r\n * // If cart was migrated, store the new guest cart ID\r\n * if (cartId) {\r\n * cookies().set('cart-id', cartId);\r\n * }\r\n * ```\r\n */\r\n async logout(\r\n sessionId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<LogoutResponse> {\r\n return fetcher.request<LogoutResponse>(\r\n \"/api/storefront/v1/customer/(auth)/logout\",\r\n {\r\n method: \"POST\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Get the currently authenticated customer's profile.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param fetchOptions - Fetch options\r\n * @returns Current customer data\r\n * @throws AuthError if session is invalid or expired\r\n *\r\n * @example\r\n * ```typescript\r\n * const sessionId = cookies().get('session-id')?.value;\r\n * if (sessionId) {\r\n * const { customer } = await client.customer.getUser(sessionId);\r\n * console.log(`Welcome back, ${customer.firstName}!`);\r\n * }\r\n * ```\r\n */\r\n async getUser(\r\n sessionId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<GetUserResponse> {\r\n return fetcher.request<GetUserResponse>(\r\n \"/api/storefront/v1/customer/(auth)/get-user\",\r\n {\r\n method: \"GET\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Verify a customer's email address using the token sent during registration.\r\n *\r\n * @param token - Email verification token\r\n * @param fetchOptions - Fetch options\r\n * @returns Verification confirmation\r\n * @throws ValidationError if token is invalid or expired\r\n *\r\n * @example\r\n * ```typescript\r\n * // Token comes from the verification email link\r\n * const token = searchParams.get('token');\r\n *\r\n * const { message } = await client.customer.verifyEmail(token);\r\n * console.log(message); // \"Email verified successfully. You can now log in.\"\r\n * ```\r\n */\r\n async verifyEmail(\r\n token: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<VerifyEmailResponse> {\r\n return fetcher.request<VerifyEmailResponse>(\r\n \"/api/storefront/v1/customer/(auth)/verify-email\",\r\n {\r\n method: \"GET\",\r\n params: { token },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Resend the verification email for an unverified customer.\r\n * A new verification email is sent automatically by the server.\r\n *\r\n * @param customerId - The customer's ID (from failed login response)\r\n * @param fetchOptions - Fetch options\r\n * @returns Success message\r\n * @throws ValidationError if customer is already verified or not found\r\n *\r\n * @example\r\n * ```typescript\r\n * // After login fails with requiresVerification\r\n * const { message } = await client.customer.resendVerification(customerId);\r\n *\r\n * // Verification email is sent automatically by the server\r\n * console.log(message); // \"Verification email sent.\"\r\n * ```\r\n */\r\n async resendVerification(\r\n customerId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<ResendVerificationResponse> {\r\n return fetcher.request<ResendVerificationResponse>(\r\n \"/api/storefront/v1/customer/(auth)/resend-verification\",\r\n {\r\n method: \"POST\",\r\n body: { customerId },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Request a password reset for a customer account.\r\n * The server sends a password reset email directly to the customer.\r\n * Returns success even if email doesn't exist (to prevent email enumeration).\r\n *\r\n * Note: The reset token is never exposed to the client for security.\r\n * The email is sent server-side with the reset link.\r\n *\r\n * @param email - Customer's email address\r\n * @param fetchOptions - Fetch options\r\n * @returns Generic success message (same whether email exists or not)\r\n *\r\n * @example\r\n * ```typescript\r\n * const response = await client.customer.forgotPassword('john@example.com');\r\n *\r\n * // Always show same message to user (email sent server-side)\r\n * console.log(response.message);\r\n * // \"If an account exists with that email, password reset instructions have been sent.\"\r\n * ```\r\n */\r\n async forgotPassword(\r\n email: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<ForgotPasswordResponse> {\r\n return fetcher.request<ForgotPasswordResponse>(\r\n \"/api/storefront/v1/customer/(auth)/forgot-password\",\r\n {\r\n method: \"POST\",\r\n body: { email },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Reset a customer's password using a valid reset token.\r\n * The token is sent via email by the forgotPassword endpoint.\r\n * After successful reset, all existing sessions are invalidated.\r\n *\r\n * @param token - Password reset token (from email link)\r\n * @param password - New password (minimum 8 characters)\r\n * @param fetchOptions - Fetch options\r\n * @returns Success confirmation\r\n * @throws ValidationError if token is invalid or expired\r\n *\r\n * @example\r\n * ```typescript\r\n * // Token comes from the reset email link\r\n * const token = searchParams.get('token');\r\n *\r\n * try {\r\n * const { message } = await client.customer.resetPassword(token, newPassword);\r\n * console.log(message); // \"Password reset successful...\"\r\n *\r\n * // Redirect to login page\r\n * redirect('/login?reset=success');\r\n * } catch (error) {\r\n * if (error instanceof ValidationError) {\r\n * // Token invalid or expired\r\n * console.error('Please request a new password reset');\r\n * }\r\n * }\r\n * ```\r\n */\r\n async resetPassword(\r\n token: string,\r\n password: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<ResetPasswordResponse> {\r\n return fetcher.request<ResetPasswordResponse>(\r\n \"/api/storefront/v1/customer/(auth)/reset-password\",\r\n {\r\n method: \"POST\",\r\n body: { token, password },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n // =========================================================================\r\n // Profile Management Methods\r\n // =========================================================================\r\n\r\n /**\r\n * Update the authenticated customer's profile.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param data - Profile data to update (firstName, lastName, email)\r\n * @param fetchOptions - Fetch options\r\n * @returns Updated customer data\r\n * @throws AuthError if session is invalid\r\n * @throws ValidationError if email is already taken by another customer\r\n *\r\n * @example\r\n * ```typescript\r\n * const { customer } = await client.customer.updateProfile(sessionId, {\r\n * firstName: 'Jane',\r\n * lastName: 'Smith',\r\n * email: 'jane.smith@example.com'\r\n * });\r\n *\r\n * console.log('Profile updated:', customer.email);\r\n * ```\r\n */\r\n async updateProfile(\r\n sessionId: string,\r\n data: UpdateProfileData,\r\n fetchOptions?: FetchOptions\r\n ): Promise<UpdateProfileResponse> {\r\n return fetcher.request<UpdateProfileResponse>(\r\n \"/api/storefront/v1/customer/edit-user\",\r\n {\r\n method: \"PATCH\",\r\n headers: buildSessionHeaders(sessionId),\r\n body: data,\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Delete the authenticated customer's account.\r\n * This action is permanent and cannot be undone.\r\n * All associated data (sessions, wishlist, etc.) will be deleted.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param fetchOptions - Fetch options\r\n * @returns Deletion confirmation\r\n * @throws AuthError if session is invalid\r\n *\r\n * @example\r\n * ```typescript\r\n * // Confirm with user before calling\r\n * if (confirm('Are you sure you want to delete your account?')) {\r\n * await client.customer.deleteAccount(sessionId);\r\n *\r\n * // Clear session cookie\r\n * cookies().delete('session-id');\r\n *\r\n * // Redirect to home page\r\n * redirect('/');\r\n * }\r\n * ```\r\n */\r\n async deleteAccount(\r\n sessionId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<DeleteAccountResponse> {\r\n return fetcher.request<DeleteAccountResponse>(\r\n \"/api/storefront/v1/customer/delete-user\",\r\n {\r\n method: \"DELETE\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Get the customer's order history.\r\n * Returns all orders with line items and product details.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param customerId - The customer's ID\r\n * @param fetchOptions - Fetch options\r\n * @returns List of customer orders\r\n *\r\n * @example\r\n * ```typescript\r\n * const { orders } = await client.customer.getOrders(sessionId, customerId);\r\n *\r\n * orders.forEach(order => {\r\n * console.log(`Order #${order.orderNumber}: ${order.status}`);\r\n * order.OrderLineItems.forEach(item => {\r\n * console.log(` - ${item.name} x${item.quantity}`);\r\n * });\r\n * });\r\n * ```\r\n */\r\n async getOrders(\r\n sessionId: string,\r\n customerId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<GetOrdersResponse> {\r\n return fetcher.request<GetOrdersResponse>(\r\n `/api/storefront/v1/customer/get-orders/${customerId}`,\r\n {\r\n method: \"GET\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n // =========================================================================\r\n // Wishlist (Nested Resource)\r\n // =========================================================================\r\n\r\n /**\r\n * Wishlist management methods.\r\n * Access via `client.customer.wishlist.get()`, `.add()`, `.remove()`.\r\n */\r\n wishlist: {\r\n /**\r\n * Get the customer's wishlist.\r\n * Returns all wishlist items with product and variation details.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param fetchOptions - Fetch options\r\n * @returns Wishlist items with product details\r\n * @throws AuthError if session is invalid\r\n *\r\n * @example\r\n * ```typescript\r\n * const { items } = await client.customer.wishlist.get(sessionId);\r\n *\r\n * items.forEach(item => {\r\n * console.log(`${item.product.name} - $${item.product.price / 100}`);\r\n * if (item.variation) {\r\n * const options = item.variation.options\r\n * .map(o => `${o.optionType.name}: ${o.value}`)\r\n * .join(', ');\r\n * console.log(` Variant: ${options}`);\r\n * }\r\n * });\r\n * ```\r\n */\r\n async get(\r\n sessionId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<WishlistResponse> {\r\n return fetcher.request<WishlistResponse>(\r\n \"/api/storefront/v1/customer/wishlist\",\r\n {\r\n method: \"GET\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Add a product to the customer's wishlist.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param productId - The product ID to add\r\n * @param variationId - Optional variation ID (for products with variations)\r\n * @param fetchOptions - Fetch options\r\n * @returns Success message\r\n * @throws AuthError if session is invalid\r\n * @throws ValidationError if product already in wishlist\r\n *\r\n * @example\r\n * ```typescript\r\n * // Add a simple product\r\n * await client.customer.wishlist.add(sessionId, 'prod_123');\r\n *\r\n * // Add a product with a specific variation\r\n * await client.customer.wishlist.add(sessionId, 'prod_123', 'var_456');\r\n * ```\r\n */\r\n async add(\r\n sessionId: string,\r\n productId: string,\r\n variationId?: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<AddToWishlistResponse> {\r\n return fetcher.request<AddToWishlistResponse>(\r\n \"/api/storefront/v1/customer/wishlist\",\r\n {\r\n method: \"POST\",\r\n headers: buildSessionHeaders(sessionId),\r\n body: { productId, variationId },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Remove a product from the customer's wishlist.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param productId - The product ID to remove\r\n * @param variationId - Optional variation ID (must match if item was added with variation)\r\n * @param fetchOptions - Fetch options\r\n * @returns Success message\r\n * @throws AuthError if session is invalid\r\n * @throws NotFoundError if item not in wishlist\r\n *\r\n * @example\r\n * ```typescript\r\n * // Remove a simple product\r\n * await client.customer.wishlist.remove(sessionId, 'prod_123');\r\n *\r\n * // Remove a specific variation\r\n * await client.customer.wishlist.remove(sessionId, 'prod_123', 'var_456');\r\n * ```\r\n */\r\n async remove(\r\n sessionId: string,\r\n productId: string,\r\n variationId?: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<RemoveFromWishlistResponse> {\r\n return fetcher.request<RemoveFromWishlistResponse>(\r\n \"/api/storefront/v1/customer/wishlist\",\r\n {\r\n method: \"DELETE\",\r\n headers: buildSessionHeaders(sessionId),\r\n body: { productId, variationId },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the customer resource\r\n */\r\nexport type CustomerResource = ReturnType<typeof createCustomerResource>;\r\n","import type { FetchOptions, Order } from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Order resource for fetching order details\r\n *\r\n * Used for order confirmation pages and viewing order details.\r\n * For customer order history, use the customer.getOrders() method instead.\r\n */\r\nexport function createOrderResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get order details by ID.\r\n *\r\n * Retrieves complete order information including line items,\r\n * customer data, and shipment method with tracking info.\r\n *\r\n * @param orderId - The order ID to fetch\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Complete order details\r\n * @throws NotFoundError if order doesn't exist or belongs to different store\r\n *\r\n * @example Basic usage (order confirmation page)\r\n * ```typescript\r\n * const order = await client.order.get(orderId);\r\n * console.log(`Order #${order.orderNumber} - ${order.status}`);\r\n * console.log(`Total: ${order.totalAmount / 100} EUR`);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const order = await client.order.get(orderId, {\r\n * next: { revalidate: 60, tags: ['order', orderId] }\r\n * });\r\n * ```\r\n *\r\n * @example Display line items\r\n * ```typescript\r\n * const order = await client.order.get(orderId);\r\n * order.OrderLineItems.forEach(item => {\r\n * if (item.itemType !== 'SHIPPING') {\r\n * console.log(`${item.name} x${item.quantity} = ${item.totalAmount / 100} EUR`);\r\n * }\r\n * });\r\n * ```\r\n *\r\n * @example Show tracking info\r\n * ```typescript\r\n * const order = await client.order.get(orderId);\r\n * if (order.orderShipmentMethod?.trackingNumber) {\r\n * console.log(`Tracking: ${order.orderShipmentMethod.trackingNumber}`);\r\n * order.orderShipmentMethod.trackingUrls?.forEach(url => {\r\n * console.log(`Track at: ${url}`);\r\n * });\r\n * }\r\n * ```\r\n */\r\n async get(orderId: string, options?: FetchOptions): Promise<Order> {\r\n return fetcher.request<Order>(\r\n `/api/storefront/v1/order/${encodeURIComponent(orderId)}`,\r\n {\r\n ...options,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the order resource\r\n */\r\nexport type OrderResource = ReturnType<typeof createOrderResource>;\r\n","import type {\r\n FetchOptions,\r\n CheckoutParams,\r\n StripeCheckoutResponse,\r\n PaytrailCheckoutResponse,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Extended options for checkout requests\r\n *\r\n * Checkout requires cart and session context via headers.\r\n */\r\nexport interface CheckoutOptions extends FetchOptions {\r\n /**\r\n * Cart ID for guest checkout.\r\n * Pass this when the user is not logged in.\r\n */\r\n cartId?: string;\r\n /**\r\n * Session ID for authenticated checkout.\r\n * Pass this when the user is logged in.\r\n */\r\n sessionId?: string;\r\n}\r\n\r\n/**\r\n * Checkout resource for payment processing\r\n *\r\n * Handles both Stripe and Paytrail payment providers.\r\n */\r\nexport function createCheckoutResource(fetcher: Fetcher) {\r\n /**\r\n * Build headers with cart/session context\r\n */\r\n function buildCheckoutHeaders(options?: CheckoutOptions): Record<string, string> {\r\n const headers: Record<string, string> = {};\r\n if (options?.cartId) {\r\n headers[\"x-cart-id\"] = options.cartId;\r\n }\r\n if (options?.sessionId) {\r\n headers[\"x-session-id\"] = options.sessionId;\r\n }\r\n return headers;\r\n }\r\n\r\n /**\r\n * Build checkout request body\r\n */\r\n function buildCheckoutBody(params: CheckoutParams) {\r\n return {\r\n orderId: params.orderId,\r\n chosenShipmentMethod: params.shipmentMethod,\r\n customerData: params.customerData,\r\n successUrl: params.successUrl,\r\n cancelUrl: params.cancelUrl,\r\n };\r\n }\r\n\r\n return {\r\n /**\r\n * Create a Stripe checkout session.\r\n *\r\n * Redirects the user to Stripe's hosted checkout page.\r\n * Cart items are validated and stock is reserved on the server.\r\n *\r\n * @param params - Checkout parameters (customer data, shipping, URLs)\r\n * @param options - Checkout options including cart/session context\r\n * @returns URL to redirect user to Stripe checkout\r\n * @throws ValidationError for invalid data or empty cart\r\n * @throws StorefrontError for inventory issues\r\n *\r\n * @example Basic usage with redirect\r\n * ```typescript\r\n * const { url } = await client.checkout.stripe({\r\n * customerData: {\r\n * first_name: \"John\",\r\n * last_name: \"Doe\",\r\n * email: \"john@example.com\",\r\n * address: \"123 Main St\",\r\n * postal_code: \"00100\",\r\n * city: \"Helsinki\",\r\n * phone: \"+358401234567\"\r\n * },\r\n * shipmentMethod: {\r\n * shipmentMethodId: \"ship_123\",\r\n * pickupId: null\r\n * },\r\n * orderId: \"order_abc123\",\r\n * successUrl: \"https://mystore.com/success\",\r\n * cancelUrl: \"https://mystore.com/cancel\"\r\n * }, {\r\n * cartId: \"cart_xyz\", // For guest users\r\n * sessionId: \"sess_123\" // For logged-in users\r\n * });\r\n *\r\n * // Redirect to Stripe\r\n * window.location.href = url;\r\n * ```\r\n */\r\n async stripe(\r\n params: CheckoutParams,\r\n options?: CheckoutOptions\r\n ): Promise<StripeCheckoutResponse> {\r\n const headers = buildCheckoutHeaders(options);\r\n const body = buildCheckoutBody(params);\r\n\r\n return fetcher.request<StripeCheckoutResponse>(\r\n \"/api/storefront/v1/payments/stripe/checkout\",\r\n {\r\n method: \"POST\",\r\n body,\r\n headers: {\r\n ...options?.headers,\r\n ...headers,\r\n },\r\n ...options,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Create a Paytrail checkout session.\r\n *\r\n * Returns payment providers for Finnish payment methods.\r\n * Cart items are validated and stock is reserved on the server.\r\n *\r\n * @param params - Checkout parameters (customer data, shipping, URLs)\r\n * @param options - Checkout options including cart/session context\r\n * @returns Paytrail response with available payment providers\r\n * @throws ValidationError for invalid data or empty cart\r\n * @throws StorefrontError for inventory issues\r\n *\r\n * @example Display payment providers\r\n * ```typescript\r\n * const response = await client.checkout.paytrail({\r\n * customerData: {\r\n * first_name: \"Matti\",\r\n * last_name: \"Meikäläinen\",\r\n * email: \"matti@example.fi\",\r\n * address: \"Mannerheimintie 1\",\r\n * postal_code: \"00100\",\r\n * city: \"Helsinki\",\r\n * phone: \"+358401234567\"\r\n * },\r\n * shipmentMethod: {\r\n * shipmentMethodId: \"ship_123\",\r\n * pickupId: \"pickup_456\" // For pickup points\r\n * },\r\n * orderId: \"order_abc123\",\r\n * successUrl: \"https://mystore.com/success\",\r\n * cancelUrl: \"https://mystore.com/cancel\"\r\n * }, {\r\n * cartId: \"cart_xyz\"\r\n * });\r\n *\r\n * // Group providers by type\r\n * const banks = response.providers.filter(p => p.group === \"bank\");\r\n * const mobile = response.providers.filter(p => p.group === \"mobile\");\r\n * const cards = response.providers.filter(p => p.group === \"creditcard\");\r\n * ```\r\n *\r\n * @example Submit payment form\r\n * ```typescript\r\n * const provider = response.providers.find(p => p.id === \"nordea\");\r\n *\r\n * // Create and submit a form\r\n * const form = document.createElement(\"form\");\r\n * form.method = \"POST\";\r\n * form.action = provider.url;\r\n *\r\n * provider.parameters.forEach(({ name, value }) => {\r\n * const input = document.createElement(\"input\");\r\n * input.type = \"hidden\";\r\n * input.name = name;\r\n * input.value = value;\r\n * form.appendChild(input);\r\n * });\r\n *\r\n * document.body.appendChild(form);\r\n * form.submit();\r\n * ```\r\n */\r\n async paytrail(\r\n params: CheckoutParams,\r\n options?: CheckoutOptions\r\n ): Promise<PaytrailCheckoutResponse> {\r\n const headers = buildCheckoutHeaders(options);\r\n const body = buildCheckoutBody(params);\r\n\r\n return fetcher.request<PaytrailCheckoutResponse>(\r\n \"/api/storefront/v1/payments/paytrail/checkout\",\r\n {\r\n method: \"POST\",\r\n body,\r\n headers: {\r\n ...options?.headers,\r\n ...headers,\r\n },\r\n ...options,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the checkout resource\r\n */\r\nexport type CheckoutResource = ReturnType<typeof createCheckoutResource>;\r\n","import type { StorefrontClientConfig } from \"./types/index.js\";\nimport { createFetcher } from \"./utils/fetch.js\";\nimport { createStoreResource, type StoreResource } from \"./resources/store.js\";\nimport {\n createProductsResource,\n type ProductsResource,\n} from \"./resources/products.js\";\nimport {\n createCategoriesResource,\n type CategoriesResource,\n} from \"./resources/categories.js\";\nimport { createCartResource, type CartResource } from \"./resources/cart.js\";\nimport {\n createShippingResource,\n type ShippingResource,\n} from \"./resources/shipping.js\";\nimport {\n createCustomerResource,\n type CustomerResource,\n} from \"./resources/customer.js\";\nimport {\n createOrderResource,\n type OrderResource,\n} from \"./resources/order.js\";\nimport {\n createCheckoutResource,\n type CheckoutResource,\n} from \"./resources/checkout.js\";\n\n/**\n * The Storefront API client\n */\nexport interface StorefrontClient {\n /**\n * The base URL for API requests\n */\n readonly baseUrl: string;\n\n /**\n * Store configuration resource\n */\n readonly store: StoreResource;\n\n /**\n * Products resource\n */\n readonly products: ProductsResource;\n\n /**\n * Categories resource\n */\n readonly categories: CategoriesResource;\n\n /**\n * Cart resource\n */\n readonly cart: CartResource;\n\n /**\n * Shipping resource\n */\n readonly shipping: ShippingResource;\n\n /**\n * Customer authentication and account management resource\n */\n readonly customer: CustomerResource;\n\n /**\n * Order resource for fetching order details\n */\n readonly order: OrderResource;\n\n /**\n * Checkout resource for payment processing\n */\n readonly checkout: CheckoutResource;\n}\n\n/**\n * Create a new Storefront API client\n */\nexport function createStorefrontClient(config: StorefrontClientConfig): StorefrontClient {\n if (!config.apiKey) {\n throw new Error(\"apiKey is required\");\n }\n if (!config.baseUrl) {\n throw new Error(\"baseUrl is required\");\n }\n\n // Ensure baseUrl doesn't have trailing slash\n const baseUrl = config.baseUrl.replace(/\\/$/, \"\");\n\n // Create the fetcher for making authenticated requests\n const fetcher = createFetcher({\n apiKey: config.apiKey,\n baseUrl,\n timeout: config.timeout,\n });\n\n return {\n baseUrl,\n store: createStoreResource(fetcher),\n products: createProductsResource(fetcher),\n categories: createCategoriesResource(fetcher),\n cart: createCartResource(fetcher),\n shipping: createShippingResource(fetcher),\n customer: createCustomerResource(fetcher),\n order: createOrderResource(fetcher),\n checkout: createCheckoutResource(fetcher),\n };\n}\n","/**\r\n * Pricing Utilities\r\n *\r\n * Helper functions for calculating prices with sale logic.\r\n */\r\n\r\nimport type { ProductDetail, ProductVariation } from \"../types/products.js\";\r\nimport type { PriceInfo } from \"../types/cart.js\";\r\n\r\n/**\r\n * Check if a sale is currently active based on start and end dates.\r\n *\r\n * @param startDate - Sale start date (ISO string, Date, null, or undefined)\r\n * @param endDate - Sale end date (ISO string, Date, null, or undefined)\r\n * @returns true if the sale is currently active\r\n *\r\n * @example\r\n * ```typescript\r\n * // No dates = always active\r\n * isSaleActive(null, null); // true\r\n *\r\n * // Only start date = active if past start\r\n * isSaleActive(\"2024-01-01\", null); // true if today >= Jan 1\r\n *\r\n * // Both dates = active if within range\r\n * isSaleActive(\"2024-01-01\", \"2024-12-31\"); // true if within range\r\n * ```\r\n */\r\nexport function isSaleActive(\r\n startDate: Date | string | null | undefined,\r\n endDate: Date | string | null | undefined\r\n): boolean {\r\n // If no dates are set, sale is considered active\r\n if (!startDate && !endDate) {\r\n return true;\r\n }\r\n\r\n const now = new Date();\r\n const start = startDate ? new Date(startDate) : null;\r\n const end = endDate ? new Date(endDate) : null;\r\n\r\n // If only start date is set\r\n if (start && !end) {\r\n return now >= start;\r\n }\r\n\r\n // If only end date is set\r\n if (!start && end) {\r\n return now <= end;\r\n }\r\n\r\n // If both dates are set\r\n if (start && end) {\r\n return now >= start && now <= end;\r\n }\r\n\r\n return true;\r\n}\r\n\r\n/**\r\n * Get price information for a product or variation.\r\n * Returns the effective price (sale or regular) and sale status.\r\n * All prices are in cents.\r\n *\r\n * @param product - The product to get price info for\r\n * @param variation - Optional variation (takes precedence over product price)\r\n * @returns Price information with effective price, original price, and sale status\r\n *\r\n * @example\r\n * ```typescript\r\n * // Product without variation\r\n * const priceInfo = getPriceInfo(product);\r\n * console.log(priceInfo.effectivePrice); // 1990 (cents)\r\n * console.log(priceInfo.isOnSale); // true\r\n *\r\n * // Product with selected variation\r\n * const priceInfo = getPriceInfo(product, selectedVariation);\r\n * ```\r\n */\r\nexport function getPriceInfo(\r\n product: ProductDetail,\r\n variation?: ProductVariation\r\n): PriceInfo {\r\n if (variation) {\r\n // Use variation pricing\r\n const isOnSale =\r\n isSaleActive(variation.saleStartDate, variation.saleEndDate) &&\r\n variation.salePrice !== null;\r\n\r\n const originalPrice = variation.price ?? product.price;\r\n const effectivePrice = isOnSale\r\n ? (variation.salePrice ?? originalPrice)\r\n : originalPrice;\r\n\r\n return {\r\n effectivePrice,\r\n originalPrice,\r\n isOnSale,\r\n salePercent: isOnSale ? (variation.salePercent ?? null) : null,\r\n };\r\n }\r\n\r\n // Use product pricing\r\n const isOnSale =\r\n isSaleActive(product.saleStartDate, product.saleEndDate) &&\r\n product.salePrice !== null;\r\n\r\n const originalPrice = product.price;\r\n const effectivePrice = isOnSale\r\n ? (product.salePrice ?? originalPrice)\r\n : originalPrice;\r\n\r\n return {\r\n effectivePrice,\r\n originalPrice,\r\n isOnSale,\r\n salePercent: isOnSale ? (product.salePercent ?? null) : null,\r\n };\r\n}\r\n","/**\r\n * Cart Calculation Utilities\r\n *\r\n * Functions for calculating cart totals with campaign discounts.\r\n */\r\n\r\nimport type { CartItem } from \"../types/cart.js\";\r\nimport type { Campaign } from \"../types/storeconfig.js\";\r\nimport type {\r\n CalculatedCartItem,\r\n FreeShippingStatus,\r\n CartCalculationResult,\r\n} from \"../types/cart.js\";\r\nimport { getPriceInfo } from \"./pricing.js\";\r\n\r\n/**\r\n * Internal type for tracking eligible units in Buy X Pay Y campaigns\r\n */\r\ninterface EligibleUnit {\r\n price: number;\r\n productId: string;\r\n variationId?: string;\r\n originalItem: CartItem;\r\n}\r\n\r\n/**\r\n * Calculate cart totals with campaign discounts applied.\r\n *\r\n * Supports two campaign types:\r\n * - **FREE_SHIPPING**: Free shipping when cart total exceeds minimum spend\r\n * - **BUY_X_PAY_Y**: Buy X items, pay for Y (e.g., Buy 3 Pay 2 = 1 free item)\r\n *\r\n * @param items - Cart items to calculate\r\n * @param campaigns - Active campaigns to apply\r\n * @returns Calculation result with totals, savings, and free shipping status\r\n *\r\n * @example\r\n * ```typescript\r\n * const result = calculateCartWithCampaigns(cartItems, activeCampaigns);\r\n *\r\n * console.log(result.cartTotal); // 4990 (cents)\r\n * console.log(result.totalSavings); // 1990 (cents)\r\n * console.log(result.freeShipping.isEligible); // true\r\n *\r\n * // Render calculated items\r\n * result.calculatedItems.forEach(({ item, paidQuantity, freeQuantity }) => {\r\n * console.log(`${item.product.name}: ${paidQuantity} paid, ${freeQuantity} free`);\r\n * });\r\n * ```\r\n */\r\nexport function calculateCartWithCampaigns(\r\n items: CartItem[],\r\n campaigns: Campaign[]\r\n): CartCalculationResult {\r\n // Find applicable campaigns\r\n const buyXPayYCampaign = campaigns.find(\r\n (c) => c.type === \"BUY_X_PAY_Y\" && c.isActive\r\n );\r\n\r\n // Calculate original total (without campaign discounts)\r\n const originalTotal = items.reduce((total, { product, variation, cartQuantity }) => {\r\n const priceInfo = getPriceInfo(product, variation);\r\n return total + priceInfo.effectivePrice * cartQuantity;\r\n }, 0);\r\n\r\n // Default free shipping status (not eligible)\r\n const freeShipping: FreeShippingStatus = {\r\n isEligible: false,\r\n minimumSpend: 0,\r\n remainingAmount: 0,\r\n };\r\n\r\n // No Buy X Pay Y campaign - return items as-is\r\n if (!buyXPayYCampaign?.BuyXPayYCampaign) {\r\n const calculatedItems = items.map((item) => ({\r\n item,\r\n paidQuantity: item.cartQuantity,\r\n freeQuantity: 0,\r\n totalQuantity: item.cartQuantity,\r\n }));\r\n\r\n return {\r\n calculatedItems,\r\n cartTotal: originalTotal,\r\n originalTotal,\r\n totalSavings: 0,\r\n freeShipping,\r\n };\r\n }\r\n\r\n // Apply Buy X Pay Y campaign\r\n const { buyQuantity, payQuantity, applicableCategories } =\r\n buyXPayYCampaign.BuyXPayYCampaign;\r\n const applicableCategoryIds = new Set(\r\n applicableCategories.map((c) => c.id)\r\n );\r\n\r\n // Find all individual units eligible for the campaign\r\n const eligibleUnits: EligibleUnit[] = items.flatMap((item) => {\r\n const { product, variation } = item;\r\n const itemCategories = product.categories?.map((cat) => cat.id) || [];\r\n\r\n // Check if any of the product's categories are in the campaign's list\r\n const isEligible = itemCategories.some((id) =>\r\n applicableCategoryIds.has(id)\r\n );\r\n\r\n if (isEligible) {\r\n const priceInfo = getPriceInfo(product, variation);\r\n\r\n // Create an entry for each single unit of the item\r\n return Array.from({ length: item.cartQuantity }, () => ({\r\n price: priceInfo.effectivePrice,\r\n productId: product.id,\r\n variationId: variation?.id,\r\n originalItem: item,\r\n }));\r\n }\r\n\r\n return [];\r\n });\r\n\r\n // Not enough eligible items - return original quantities\r\n if (eligibleUnits.length < buyQuantity) {\r\n const calculatedItems = items.map((item) => ({\r\n item,\r\n paidQuantity: item.cartQuantity,\r\n freeQuantity: 0,\r\n totalQuantity: item.cartQuantity,\r\n }));\r\n\r\n return {\r\n calculatedItems,\r\n cartTotal: originalTotal,\r\n originalTotal,\r\n totalSavings: 0,\r\n freeShipping,\r\n };\r\n }\r\n\r\n // Sort by price to find the cheapest items to make free\r\n eligibleUnits.sort((a, b) => a.price - b.price);\r\n\r\n const numToMakeFree = buyQuantity - payQuantity;\r\n const itemsToMakeFree = eligibleUnits.slice(0, numToMakeFree);\r\n\r\n // Calculate total savings from free items\r\n const totalSavings = itemsToMakeFree.reduce(\r\n (sum, item) => sum + item.price,\r\n 0\r\n );\r\n\r\n // Create a map to count how many units of each product/variation should be free\r\n const freeCountMap = new Map<string, number>();\r\n for (const freebie of itemsToMakeFree) {\r\n const key = `${freebie.productId}${freebie.variationId ? `_${freebie.variationId}` : \"\"}`;\r\n freeCountMap.set(key, (freeCountMap.get(key) || 0) + 1);\r\n }\r\n\r\n // Calculate paid and free quantities for each item\r\n const calculatedItems: CalculatedCartItem[] = items.map((item) => {\r\n const key = `${item.product.id}${item.variation?.id ? `_${item.variation.id}` : \"\"}`;\r\n const freeQuantity = freeCountMap.get(key) || 0;\r\n const paidQuantity = item.cartQuantity - freeQuantity;\r\n\r\n return {\r\n item,\r\n paidQuantity: Math.max(0, paidQuantity),\r\n freeQuantity,\r\n totalQuantity: item.cartQuantity,\r\n };\r\n });\r\n\r\n // Calculate final cart total after Buy X Pay Y discounts\r\n const cartTotal = originalTotal - totalSavings;\r\n\r\n return {\r\n calculatedItems,\r\n cartTotal,\r\n originalTotal,\r\n totalSavings,\r\n freeShipping,\r\n };\r\n}\r\n"],"mappings":";AAGO,IAAM,kBAAN,MAAM,yBAAwB,MAAM;AAAA,EAIzC,YAAY,SAAiB,QAAgB,MAAc;AACzD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAGZ,UAAM,mBAAmB;AAGzB,QAAI,iBAAiB,mBAAmB;AACtC,uBAAiB,kBAAkB,MAAM,gBAAe;AAAA,IAC1D;AAAA,EACF;AACF;AAKO,IAAM,YAAN,cAAwB,gBAAgB;AAAA,EAC7C,YAAY,UAAkB,8BAA8B;AAC1D,UAAM,SAAS,KAAK,cAAc;AAClC,SAAK,OAAO;AAAA,EACd;AACF;AAKO,IAAM,iBAAN,cAA6B,gBAAgB;AAAA,EAGlD,YAAY,UAAkB,uBAAuB,aAA4B,MAAM;AACrF,UAAM,SAAS,KAAK,qBAAqB;AACzC,SAAK,OAAO;AACZ,SAAK,aAAa;AAAA,EACpB;AACF;AAKO,IAAM,gBAAN,cAA4B,gBAAgB;AAAA,EACjD,YAAY,UAAkB,sBAAsB;AAClD,UAAM,SAAS,KAAK,WAAW;AAC/B,SAAK,OAAO;AAAA,EACd;AACF;AAKO,IAAM,kBAAN,cAA8B,gBAAgB;AAAA,EACnD,YAAY,UAAkB,qBAAqB;AACjD,UAAM,SAAS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AAW;AAAA,MACX;AAAA,MACA,cAAc;AAAA,MACd;AAAA,IACF;AAAA,EACF;AAGA,gBAAc,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;AAE9C,QAAM,gBAAgB,cAAc;AACpC,QAAM,kBAAkB,cAAc,MAAM,GAAG,aAAa;AAG5D,QAAM,eAAe,gBAAgB;AAAA,IACnC,CAAC,KAAK,SAAS,MAAM,KAAK;AAAA,IAC1B;AAAA,EACF;AAGA,QAAM,eAAe,oBAAI,IAAoB;AAC7C,aAAW,WAAW,iBAAiB;AACrC,UAAM,MAAM,GAAG,QAAQ,SAAS,GAAG,QAAQ,cAAc,IAAI,QAAQ,WAAW,KAAK,EAAE;AACvF,iBAAa,IAAI,MAAM,aAAa,IAAI,GAAG,KAAK,KAAK,CAAC;AAAA,EACxD;AAGA,QAAM,kBAAwC,MAAM,IAAI,CAAC,SAAS;AAChE,UAAM,MAAM,GAAG,KAAK,QAAQ,EAAE,GAAG,KAAK,WAAW,KAAK,IAAI,KAAK,UAAU,EAAE,KAAK,EAAE;AAClF,UAAM,eAAe,aAAa,IAAI,GAAG,KAAK;AAC9C,UAAM,eAAe,KAAK,eAAe;AAEzC,WAAO;AAAA,MACL;AAAA,MACA,cAAc,KAAK,IAAI,GAAG,YAAY;AAAA,MACtC;AAAA,MACA,eAAe,KAAK;AAAA,IACtB;AAAA,EACF,CAAC;AAGD,QAAM,YAAY,gBAAgB;AAElC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["isOnSale","originalPrice","effectivePrice","calculatedItems"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/errors.ts","../src/utils/fetch.ts","../src/resources/store.ts","../src/resources/products.ts","../src/resources/categories.ts","../src/resources/cart.ts","../src/resources/shipping.ts","../src/resources/customer.ts","../src/resources/order.ts","../src/resources/checkout.ts","../src/client.ts","../src/utils/pricing.ts","../src/utils/cart-calculations.ts"],"sourcesContent":["/**\n * Base error class for all Storefront API errors\n */\nexport class StorefrontError extends Error {\n public readonly status: number;\n public readonly code: string;\n\n constructor(message: string, status: number, code: string) {\n super(message);\n this.name = \"StorefrontError\";\n this.status = status;\n this.code = code;\n\n // Maintains proper stack trace in V8 environments\n const ErrorWithCapture = Error as typeof Error & {\n captureStackTrace?: (target: object, constructor: Function) => void;\n };\n if (ErrorWithCapture.captureStackTrace) {\n ErrorWithCapture.captureStackTrace(this, StorefrontError);\n }\n }\n}\n\n/**\n * Error thrown when API returns 401 Unauthorized\n */\nexport class AuthError extends StorefrontError {\n constructor(message: string = \"Invalid or missing API key\") {\n super(message, 401, \"UNAUTHORIZED\");\n this.name = \"AuthError\";\n }\n}\n\n/**\n * Error thrown when API returns 429 Too Many Requests\n */\nexport class RateLimitError extends StorefrontError {\n public readonly retryAfter: number | null;\n\n constructor(message: string = \"Rate limit exceeded\", retryAfter: number | null = null) {\n super(message, 429, \"RATE_LIMIT_EXCEEDED\");\n this.name = \"RateLimitError\";\n this.retryAfter = retryAfter;\n }\n}\n\n/**\n * Error thrown when a requested resource is not found (404)\n */\nexport class NotFoundError extends StorefrontError {\n constructor(message: string = \"Resource not found\") {\n super(message, 404, \"NOT_FOUND\");\n this.name = \"NotFoundError\";\n }\n}\n\n/**\n * Error thrown when request validation fails (400)\n */\nexport class ValidationError extends StorefrontError {\n constructor(message: string = \"Validation failed\") {\n super(message, 400, \"VALIDATION_ERROR\");\n this.name = \"ValidationError\";\n }\n}\n\n/**\n * Error thrown when login fails due to unverified email\n * Contains customerId for resending verification email\n */\nexport class VerificationRequiredError extends StorefrontError {\n public readonly requiresVerification: true = true;\n public readonly customerId: string;\n\n constructor(message: string, customerId: string) {\n super(message, 403, \"VERIFICATION_REQUIRED\");\n this.name = \"VerificationRequiredError\";\n this.customerId = customerId;\n }\n}\n","import type { FetchOptions } from \"../types/index.js\";\r\nimport {\r\n StorefrontError,\r\n AuthError,\r\n RateLimitError,\r\n NotFoundError,\r\n ValidationError,\r\n VerificationRequiredError,\r\n} from \"./errors.js\";\r\n\r\n// SDK version - will be replaced during build or read from package.json\r\nconst SDK_VERSION = \"0.1.0\";\r\n\r\nexport interface FetcherConfig {\r\n apiKey: string;\r\n baseUrl: string;\r\n timeout?: number;\r\n}\r\n\r\nexport interface RequestOptions extends FetchOptions {\r\n method?: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\r\n body?: unknown;\r\n params?: Record<string, string | number | boolean | undefined>;\r\n}\r\n\r\n/**\r\n * Fetcher instance type returned by createFetcher\r\n */\r\nexport type Fetcher = ReturnType<typeof createFetcher>;\r\n\r\n/**\r\n * Create a configured fetcher instance for making API requests\r\n */\r\nexport function createFetcher(config: FetcherConfig) {\r\n const { apiKey, baseUrl, timeout = 30000 } = config;\r\n\r\n /**\r\n * Make an authenticated request to the Storefront API\r\n */\r\n async function request<T>(endpoint: string, options: RequestOptions = {}): Promise<T> {\r\n const { method = \"GET\", body, params, signal, headers = {}, cache, ...frameworkOptions } = options;\r\n\r\n // Build URL with query parameters\r\n // Ensure baseUrl ends with / for proper URL resolution\r\n const normalizedBase = baseUrl.endsWith(\"/\") ? baseUrl : `${baseUrl}/`;\r\n // Remove leading slash from endpoint to avoid URL resolution issues\r\n const normalizedEndpoint = endpoint.startsWith(\"/\") ? endpoint.slice(1) : endpoint;\r\n const url = new URL(normalizedEndpoint, normalizedBase);\r\n\r\n if (params) {\r\n for (const [key, value] of Object.entries(params)) {\r\n if (value !== undefined) {\r\n url.searchParams.set(key, String(value));\r\n }\r\n }\r\n }\r\n\r\n // Create abort controller for timeout\r\n const controller = new AbortController();\r\n const timeoutId = setTimeout(() => controller.abort(), timeout);\r\n\r\n // Combine signals if provided\r\n const combinedSignal = signal\r\n ? AbortSignal.any([signal, controller.signal])\r\n : controller.signal;\r\n\r\n try {\r\n const fetchOptions: RequestInit & Record<string, unknown> = {\r\n method,\r\n headers: {\r\n \"Content-Type\": \"application/json\",\r\n \"x-api-key\": apiKey,\r\n \"x-sdk-version\": SDK_VERSION,\r\n ...headers,\r\n },\r\n body: body ? JSON.stringify(body) : undefined,\r\n signal: combinedSignal,\r\n cache,\r\n // Spread framework-specific options (e.g., Next.js `next`, or any other)\r\n ...frameworkOptions,\r\n };\r\n\r\n const response = await fetch(url.toString(), fetchOptions);\r\n\r\n clearTimeout(timeoutId);\r\n\r\n // Handle error responses\r\n if (!response.ok) {\r\n await handleErrorResponse(response);\r\n }\r\n\r\n // Parse response\r\n const data = await response.json();\r\n return data as T;\r\n } catch (error) {\r\n clearTimeout(timeoutId);\r\n\r\n // Re-throw SDK errors\r\n if (error instanceof StorefrontError) {\r\n throw error;\r\n }\r\n\r\n // Handle abort/timeout\r\n if (error instanceof Error && error.name === \"AbortError\") {\r\n throw new StorefrontError(\"Request timed out\", 408, \"TIMEOUT\");\r\n }\r\n\r\n // Handle network errors\r\n throw new StorefrontError(\r\n error instanceof Error ? error.message : \"Network error\",\r\n 0,\r\n \"NETWORK_ERROR\"\r\n );\r\n }\r\n }\r\n\r\n return { request };\r\n}\r\n\r\n/**\r\n * Error response JSON structure\r\n */\r\ninterface ErrorResponseJson {\r\n error?: string;\r\n requiresVerification?: boolean;\r\n customerId?: string;\r\n}\r\n\r\n/**\r\n * Handle non-2xx responses and throw appropriate errors\r\n */\r\nasync function handleErrorResponse(response: Response): Promise<never> {\r\n let errorData: ErrorResponseJson = {};\r\n\r\n try {\r\n const json: unknown = await response.json();\r\n if (json && typeof json === \"object\") {\r\n errorData = json as ErrorResponseJson;\r\n }\r\n } catch {\r\n // Response body is not JSON\r\n }\r\n\r\n const message = errorData.error || response.statusText || \"Request failed\";\r\n\r\n // Check for verification required error (can be 400 or 403)\r\n if (errorData.requiresVerification && errorData.customerId) {\r\n throw new VerificationRequiredError(message, errorData.customerId);\r\n }\r\n\r\n switch (response.status) {\r\n case 401:\r\n throw new AuthError(message);\r\n\r\n case 404:\r\n throw new NotFoundError(message);\r\n\r\n case 429: {\r\n const retryAfter = response.headers.get(\"Retry-After\");\r\n throw new RateLimitError(message, retryAfter ? parseInt(retryAfter, 10) : null);\r\n }\r\n\r\n case 400:\r\n throw new ValidationError(message);\r\n\r\n default:\r\n throw new StorefrontError(message, response.status, \"API_ERROR\");\r\n }\r\n}\r\n","import type { FetchOptions, StoreConfig } from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Store resource for fetching store configuration\r\n */\r\nexport function createStoreResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get the complete store configuration including settings, SEO, payments, campaigns, and features.\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const config = await client.store.getConfig();\r\n * console.log(config.store.name);\r\n * console.log(config.seo.seoTitle);\r\n * console.log(config.campaigns);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const config = await client.store.getConfig({\r\n * next: { revalidate: 300, tags: ['store-config'] }\r\n * });\r\n * ```\r\n *\r\n * @example Nuxt - wrap with useAsyncData\r\n * ```typescript\r\n * const { data: config } = await useAsyncData(\r\n * 'store-config',\r\n * () => client.store.getConfig()\r\n * );\r\n * ```\r\n *\r\n * @example Standard fetch caching\r\n * ```typescript\r\n * const config = await client.store.getConfig({\r\n * cache: 'force-cache'\r\n * });\r\n * ```\r\n */\r\n async getConfig(options?: FetchOptions): Promise<StoreConfig> {\r\n return fetcher.request<StoreConfig>(\"/api/storefront/v1/store-config\", {\r\n ...options,\r\n });\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the store resource\r\n */\r\nexport type StoreResource = ReturnType<typeof createStoreResource>;\r\n","import type {\r\n FetchOptions,\r\n Product,\r\n ProductDetail,\r\n ProductListResponse,\r\n ProductCountResponse,\r\n ProductListParams,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Products resource for fetching product data\r\n */\r\nexport function createProductsResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get latest products ordered by creation date (newest first).\r\n *\r\n * @param take - Number of products to return (required, must be >= 1)\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Array of products\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const products = await client.products.latest(6);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const products = await client.products.latest(6, {\r\n * next: { revalidate: 3600, tags: ['products'] }\r\n * });\r\n * ```\r\n */\r\n async latest(take: number, options?: FetchOptions): Promise<Product[]> {\r\n return fetcher.request<Product[]>(\"/api/storefront/v1/latest-products\", {\r\n params: { take },\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * Get a single product by its URL slug.\r\n *\r\n * @param slug - Product URL slug\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Full product details including categories and variations\r\n * @throws NotFoundError if product doesn't exist or is not visible\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const product = await client.products.getBySlug('my-product');\r\n * console.log(product.name, product.categories);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const product = await client.products.getBySlug('my-product', {\r\n * next: { revalidate: 3600, tags: ['product', 'my-product'] }\r\n * });\r\n * ```\r\n */\r\n async getBySlug(\r\n slug: string,\r\n options?: FetchOptions\r\n ): Promise<ProductDetail> {\r\n return fetcher.request<ProductDetail>(\r\n `/api/storefront/v1/product/${encodeURIComponent(slug)}`,\r\n {\r\n ...options,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Get total product count, optionally filtered by category.\r\n *\r\n * @param slugs - Optional category slugs to filter by\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Object with count property\r\n *\r\n * @example Get total count\r\n * ```typescript\r\n * const { count } = await client.products.count();\r\n * console.log(`Total products: ${count}`);\r\n * ```\r\n *\r\n * @example Get count for specific category\r\n * ```typescript\r\n * const { count } = await client.products.count(['shoes']);\r\n * console.log(`Products in shoes: ${count}`);\r\n * ```\r\n */\r\n async count(\r\n slugs?: string[],\r\n options?: FetchOptions\r\n ): Promise<ProductCountResponse> {\r\n const searchParams = new URLSearchParams();\r\n if (slugs?.length) {\r\n slugs.forEach((s) => searchParams.append(\"slugs\", s));\r\n }\r\n const query = searchParams.toString();\r\n const endpoint = `/api/storefront/v1/products-count${query ? `?${query}` : \"\"}`;\r\n\r\n return fetcher.request<ProductCountResponse>(endpoint, {\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * Get sorted products with pagination.\r\n * Uses optimized sorting with pre-computed effective prices.\r\n *\r\n * @param params - Query parameters (slugs, page, pageSize, sort)\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Products list with totalCount for pagination\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const { products, totalCount } = await client.products.sorted({\r\n * page: 1,\r\n * pageSize: 12,\r\n * sort: 'newest'\r\n * });\r\n * ```\r\n *\r\n * @example Filter by category\r\n * ```typescript\r\n * const { products, totalCount } = await client.products.sorted({\r\n * slugs: ['shoes', 'clothing'],\r\n * page: 1,\r\n * pageSize: 24,\r\n * sort: 'price_asc'\r\n * });\r\n * ```\r\n *\r\n * @example Real-time data (no cache)\r\n * ```typescript\r\n * const data = await client.products.sorted(\r\n * { page: 1, pageSize: 12 },\r\n * { cache: 'no-store' }\r\n * );\r\n * ```\r\n */\r\n async sorted(\r\n params: ProductListParams = {},\r\n options?: FetchOptions\r\n ): Promise<ProductListResponse> {\r\n const searchParams = new URLSearchParams();\r\n if (params.page) searchParams.set(\"page\", params.page.toString());\r\n if (params.pageSize)\r\n searchParams.set(\"pageSize\", params.pageSize.toString());\r\n if (params.sort) searchParams.set(\"sort\", params.sort);\r\n if (params.slugs?.length) {\r\n params.slugs.forEach((s) => searchParams.append(\"slugs\", s));\r\n }\r\n const query = searchParams.toString();\r\n const endpoint = `/api/storefront/v1/sorted-products${query ? `?${query}` : \"\"}`;\r\n\r\n return fetcher.request<ProductListResponse>(endpoint, {\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * Get filtered products with pagination.\r\n * Similar to sorted() but without totalCount in response.\r\n * Useful for sitemaps and bulk fetches.\r\n *\r\n * @param params - Query parameters (slugs, page, pageSize, sort)\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Products list with category name\r\n *\r\n * @example Fetch all products for sitemap\r\n * ```typescript\r\n * const { products } = await client.products.filtered({\r\n * slugs: ['all-products'],\r\n * page: 1,\r\n * pageSize: 1000\r\n * });\r\n * ```\r\n */\r\n async filtered(\r\n params: ProductListParams = {},\r\n options?: FetchOptions\r\n ): Promise<Omit<ProductListResponse, \"totalCount\">> {\r\n const searchParams = new URLSearchParams();\r\n if (params.page) searchParams.set(\"page\", params.page.toString());\r\n if (params.pageSize)\r\n searchParams.set(\"pageSize\", params.pageSize.toString());\r\n if (params.sort) searchParams.set(\"sort\", params.sort);\r\n if (params.slugs?.length) {\r\n params.slugs.forEach((s) => searchParams.append(\"slugs\", s));\r\n }\r\n const query = searchParams.toString();\r\n const endpoint = `/api/storefront/v1/filtered-products${query ? `?${query}` : \"\"}`;\r\n\r\n return fetcher.request<Omit<ProductListResponse, \"totalCount\">>(\r\n endpoint,\r\n {\r\n ...options,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the products resource\r\n */\r\nexport type ProductsResource = ReturnType<typeof createProductsResource>;\r\n","import type { FetchOptions, Category, CategoryResponse } from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Categories resource for fetching category data\r\n */\r\nexport function createCategoriesResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get all top-level categories with nested children.\r\n * Returns a hierarchical tree of categories (up to 5 levels deep).\r\n *\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Array of top-level categories with nested children\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const categories = await client.categories.list();\r\n * categories.forEach(cat => {\r\n * console.log(cat.name, cat.children.length);\r\n * });\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const categories = await client.categories.list({\r\n * next: { revalidate: 3600, tags: ['categories'] }\r\n * });\r\n * ```\r\n */\r\n async list(options?: FetchOptions): Promise<Category[]> {\r\n return fetcher.request<Category[]>(\"/api/storefront/v1/categories\", {\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * Get a single category by its URL slug.\r\n *\r\n * @param slug - Category URL slug\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Category data\r\n * @throws NotFoundError if category doesn't exist\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const { category } = await client.categories.getBySlug('shoes');\r\n * console.log(category.name);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const { category } = await client.categories.getBySlug('shoes', {\r\n * next: { revalidate: 86400, tags: ['category', 'shoes'] }\r\n * });\r\n * ```\r\n */\r\n async getBySlug(\r\n slug: string,\r\n options?: FetchOptions\r\n ): Promise<CategoryResponse> {\r\n return fetcher.request<CategoryResponse>(\r\n `/api/storefront/v1/categories/${encodeURIComponent(slug)}`,\r\n {\r\n ...options,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the categories resource\r\n */\r\nexport type CategoriesResource = ReturnType<typeof createCategoriesResource>;\r\n","/**\r\n * Cart Resource\r\n *\r\n * Methods for managing the shopping cart stored in Redis.\r\n * Supports both guest carts (via cartId) and authenticated user carts (via sessionId).\r\n */\r\n\r\nimport type {\r\n FetchOptions,\r\n CartResponse,\r\n CartValidationResponse,\r\n CartSessionOptions,\r\n AddToCartParams,\r\n UpdateCartQuantityParams,\r\n RemoveFromCartParams,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Build headers object for cart operations\r\n */\r\nfunction buildCartHeaders(options?: CartSessionOptions): Record<string, string> {\r\n const headers: Record<string, string> = {};\r\n if (options?.cartId) {\r\n headers[\"x-cart-id\"] = options.cartId;\r\n }\r\n if (options?.sessionId) {\r\n headers[\"x-session-id\"] = options.sessionId;\r\n }\r\n return headers;\r\n}\r\n\r\n/**\r\n * Cart resource for managing shopping cart\r\n */\r\nexport function createCartResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Fetch the current cart contents.\r\n *\r\n * @param options - Cart session options (cartId for guests, sessionId for logged-in users)\r\n * @param fetchOptions - Fetch options (caching, headers, etc.)\r\n * @returns Cart items and cartId (for guests)\r\n *\r\n * @example Guest user\r\n * ```typescript\r\n * const cartId = localStorage.getItem('cart-id');\r\n * const { items, cartId: newCartId } = await client.cart.get({ cartId });\r\n * ```\r\n *\r\n * @example Logged-in user\r\n * ```typescript\r\n * const { items } = await client.cart.get({ sessionId });\r\n * ```\r\n */\r\n async get(\r\n options?: CartSessionOptions,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartResponse> {\r\n return fetcher.request<CartResponse>(\"/api/storefront/v1/cart\", {\r\n method: \"GET\",\r\n headers: buildCartHeaders(options),\r\n ...fetchOptions,\r\n });\r\n },\r\n\r\n /**\r\n * Add an item to the cart.\r\n * If the item already exists, quantity is incremented.\r\n *\r\n * @param params - Add to cart parameters\r\n * @param fetchOptions - Fetch options\r\n * @returns Updated cart with new cartId for guests\r\n * @throws ValidationError if quantity exceeds available stock\r\n *\r\n * @example Add product\r\n * ```typescript\r\n * const { items, cartId } = await client.cart.addItem({\r\n * cartId: existingCartId,\r\n * productId: 'prod_123',\r\n * quantity: 2\r\n * });\r\n * // Save cartId for future requests\r\n * localStorage.setItem('cart-id', cartId);\r\n * ```\r\n *\r\n * @example Add product with variation\r\n * ```typescript\r\n * const { items, cartId } = await client.cart.addItem({\r\n * cartId,\r\n * productId: 'prod_123',\r\n * variationId: 'var_456',\r\n * quantity: 1\r\n * });\r\n * ```\r\n */\r\n async addItem(\r\n params: AddToCartParams,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartResponse> {\r\n const { cartId, sessionId, ...body } = params;\r\n return fetcher.request<CartResponse>(\"/api/storefront/v1/cart\", {\r\n method: \"POST\",\r\n headers: buildCartHeaders({ sessionId }),\r\n body: {\r\n cartId,\r\n ...body,\r\n },\r\n ...fetchOptions,\r\n });\r\n },\r\n\r\n /**\r\n * Update item quantity by delta (atomic operation).\r\n * Use positive delta to increase, negative to decrease.\r\n * Minimum quantity is 1 (use removeItem to delete).\r\n *\r\n * @param params - Update quantity parameters\r\n * @param fetchOptions - Fetch options\r\n * @returns Updated cart\r\n * @throws NotFoundError if item not in cart or quantity would go below 1\r\n *\r\n * @example Increment quantity\r\n * ```typescript\r\n * const { items } = await client.cart.updateQuantity({\r\n * cartId,\r\n * productId: 'prod_123',\r\n * delta: 1\r\n * });\r\n * ```\r\n *\r\n * @example Decrement quantity\r\n * ```typescript\r\n * const { items } = await client.cart.updateQuantity({\r\n * cartId,\r\n * productId: 'prod_123',\r\n * variationId: 'var_456',\r\n * delta: -1\r\n * });\r\n * ```\r\n */\r\n async updateQuantity(\r\n params: UpdateCartQuantityParams,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartResponse> {\r\n const { cartId, sessionId, ...body } = params;\r\n return fetcher.request<CartResponse>(\"/api/storefront/v1/cart\", {\r\n method: \"PATCH\",\r\n headers: buildCartHeaders({ sessionId }),\r\n body: {\r\n cartId,\r\n ...body,\r\n },\r\n ...fetchOptions,\r\n });\r\n },\r\n\r\n /**\r\n * Remove an item from the cart.\r\n *\r\n * @param params - Remove from cart parameters\r\n * @param fetchOptions - Fetch options\r\n * @returns Updated cart\r\n *\r\n * @example Remove product\r\n * ```typescript\r\n * const { items } = await client.cart.removeItem({\r\n * cartId,\r\n * productId: 'prod_123'\r\n * });\r\n * ```\r\n *\r\n * @example Remove variation\r\n * ```typescript\r\n * const { items } = await client.cart.removeItem({\r\n * cartId,\r\n * productId: 'prod_123',\r\n * variationId: 'var_456'\r\n * });\r\n * ```\r\n */\r\n async removeItem(\r\n params: RemoveFromCartParams,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartResponse> {\r\n const { cartId, sessionId, ...body } = params;\r\n return fetcher.request<CartResponse>(\"/api/storefront/v1/cart\", {\r\n method: \"DELETE\",\r\n headers: buildCartHeaders({ sessionId }),\r\n body: {\r\n cartId,\r\n ...body,\r\n },\r\n ...fetchOptions,\r\n });\r\n },\r\n\r\n /**\r\n * Validate cart before checkout.\r\n * Checks product availability, stock levels, and prices.\r\n * Auto-fixes issues (removes unavailable items, adjusts quantities).\r\n *\r\n * @param options - Cart session options\r\n * @param fetchOptions - Fetch options\r\n * @returns Validated cart with change metadata\r\n *\r\n * @example Validate before checkout\r\n * ```typescript\r\n * const { items, hasChanges, changes } = await client.cart.validate({ cartId });\r\n *\r\n * if (hasChanges) {\r\n * if (changes.removedItems > 0) {\r\n * notify('Some items were removed (out of stock)');\r\n * }\r\n * if (changes.quantityAdjusted > 0) {\r\n * notify('Some quantities were adjusted');\r\n * }\r\n * if (changes.priceChanged > 0) {\r\n * notify('Some prices have changed');\r\n * }\r\n * }\r\n * ```\r\n */\r\n async validate(\r\n options?: CartSessionOptions,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartValidationResponse> {\r\n return fetcher.request<CartValidationResponse>(\r\n \"/api/storefront/v1/cart/validate\",\r\n {\r\n method: \"GET\",\r\n headers: buildCartHeaders(options),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the cart resource\r\n */\r\nexport type CartResource = ReturnType<typeof createCartResource>;\r\n","/**\r\n * Shipping Resource\r\n *\r\n * Methods for fetching shipment methods and pickup locations.\r\n */\r\n\r\nimport type {\r\n FetchOptions,\r\n ShipmentMethodsWithLocationsResponse,\r\n CartItem,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Calculate total cart weight from cart items\r\n */\r\nfunction calculateCartWeight(items: CartItem[]): number {\r\n return items.reduce((total, item) => {\r\n const itemWeight = item.variation?.weight ?? item.product.weight ?? 0.5;\r\n return total + itemWeight * item.cartQuantity;\r\n }, 0);\r\n}\r\n\r\n/**\r\n * Options for fetching shipment methods with weight-based filtering\r\n */\r\nexport interface GetMethodsOptions extends FetchOptions {\r\n /** Cart items - weight will be calculated automatically */\r\n cartItems?: CartItem[];\r\n}\r\n\r\n/**\r\n * Shipping resource for fetching shipment methods and pickup locations\r\n */\r\nexport function createShippingResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get shipping options for a specific postal code.\r\n * Returns home delivery methods and pickup locations.\r\n *\r\n * @param postalCode - Customer's postal code (e.g., \"00100\")\r\n * @param options - Fetch options including optional cartItems for weight-based filtering\r\n * @returns Home delivery methods and pickup locations\r\n *\r\n * @example\r\n * ```typescript\r\n * const { homeDeliveryMethods, pickupLocations } = await client.shipping.getWithLocations(\"00100\");\r\n *\r\n * // Show home delivery options\r\n * homeDeliveryMethods.forEach(method => {\r\n * console.log(`${method.name}: ${method.price / 100}€`);\r\n * });\r\n *\r\n * // Show pickup locations\r\n * pickupLocations.forEach(location => {\r\n * console.log(`${location.name} - ${location.carrier}`);\r\n * console.log(` ${location.address1}, ${location.city}`);\r\n * console.log(` ${location.distanceInKilometers.toFixed(1)} km away`);\r\n * console.log(` Price: ${location.price / 100}€`);\r\n * });\r\n * ```\r\n *\r\n * @example Weight-based filtering\r\n * ```typescript\r\n * const { homeDeliveryMethods, pickupLocations } = await client.shipping.getWithLocations(\r\n * \"00100\",\r\n * { cartItems: cartItems }\r\n * );\r\n * // Only shows methods that support the cart's total weight\r\n * ```\r\n */\r\n async getWithLocations(\r\n postalCode: string,\r\n options?: GetMethodsOptions\r\n ): Promise<ShipmentMethodsWithLocationsResponse> {\r\n const params = new URLSearchParams();\r\n if (options?.cartItems?.length) {\r\n const cartWeight = calculateCartWeight(options.cartItems);\r\n params.set(\"cartWeight\", cartWeight.toString());\r\n }\r\n const queryString = params.toString();\r\n const url = `/api/storefront/v1/shipment-methods/${encodeURIComponent(postalCode)}${queryString ? `?${queryString}` : \"\"}`;\r\n\r\n return fetcher.request<ShipmentMethodsWithLocationsResponse>(url, {\r\n method: \"GET\",\r\n ...options,\r\n });\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the shipping resource\r\n */\r\nexport type ShippingResource = ReturnType<typeof createShippingResource>;\r\n","/**\r\n * Customer Resource\r\n *\r\n * Methods for customer authentication and account management.\r\n * Supports session-based authentication with the x-session-id header.\r\n */\r\n\r\nimport type {\r\n FetchOptions,\r\n RegisterData,\r\n RegisterResponse,\r\n LoginOptions,\r\n LoginResponse,\r\n LogoutResponse,\r\n GetUserResponse,\r\n VerifyEmailResponse,\r\n ResendVerificationResponse,\r\n UpdateProfileData,\r\n UpdateProfileResponse,\r\n DeleteAccountResponse,\r\n GetOrdersResponse,\r\n WishlistResponse,\r\n AddToWishlistResponse,\r\n RemoveFromWishlistResponse,\r\n ForgotPasswordResponse,\r\n ResetPasswordResponse,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Build headers for authenticated customer requests\r\n */\r\nfunction buildSessionHeaders(sessionId: string): Record<string, string> {\r\n return { \"x-session-id\": sessionId };\r\n}\r\n\r\n/**\r\n * Customer resource for authentication and account management\r\n */\r\nexport function createCustomerResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Register a new customer account.\r\n * A verification email is sent automatically by the server.\r\n * The customer must verify their email before logging in.\r\n *\r\n * @param data - Registration data (firstName, lastName, email, password)\r\n * @param fetchOptions - Fetch options\r\n * @returns Created customer data and success message\r\n *\r\n * @example\r\n * ```typescript\r\n * const { customer, message } = await client.customer.register({\r\n * firstName: 'John',\r\n * lastName: 'Doe',\r\n * email: 'john@example.com',\r\n * password: 'securePassword123'\r\n * });\r\n *\r\n * // Verification email is sent automatically by the server\r\n * console.log('Account created:', message);\r\n * ```\r\n */\r\n async register(\r\n data: RegisterData,\r\n fetchOptions?: FetchOptions\r\n ): Promise<RegisterResponse> {\r\n return fetcher.request<RegisterResponse>(\r\n \"/api/storefront/v1/customer/(auth)/register\",\r\n {\r\n method: \"POST\",\r\n body: data,\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Log in an existing customer.\r\n * Returns a session ID that must be stored and passed to authenticated endpoints.\r\n *\r\n * @param email - Customer's email address\r\n * @param password - Customer's password\r\n * @param options - Login options (optional cartId for cart merging)\r\n * @param fetchOptions - Fetch options\r\n * @returns Session ID and customer data\r\n * @throws ValidationError if email is not verified (check error for requiresVerification)\r\n *\r\n * @example\r\n * ```typescript\r\n * try {\r\n * const { sessionId, customer, expiresAt } = await client.customer.login(\r\n * 'john@example.com',\r\n * 'securePassword123',\r\n * { cartId: guestCartId } // Optional: merge guest cart\r\n * );\r\n *\r\n * // Store sessionId in a cookie\r\n * cookies().set('session-id', sessionId, {\r\n * httpOnly: true,\r\n * expires: new Date(expiresAt)\r\n * });\r\n * } catch (error) {\r\n * if (error.requiresVerification) {\r\n * // Prompt user to verify email\r\n * await client.customer.resendVerification(error.customerId);\r\n * }\r\n * }\r\n * ```\r\n */\r\n async login(\r\n email: string,\r\n password: string,\r\n options?: LoginOptions,\r\n fetchOptions?: FetchOptions\r\n ): Promise<LoginResponse> {\r\n const headers: Record<string, string> = {};\r\n if (options?.cartId) {\r\n headers[\"x-cart-id\"] = options.cartId;\r\n }\r\n\r\n return fetcher.request<LoginResponse>(\r\n \"/api/storefront/v1/customer/(auth)/login\",\r\n {\r\n method: \"POST\",\r\n body: { email, password },\r\n headers,\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Log out the current customer and invalidate their session.\r\n * If the customer had items in their cart, they are migrated to a new guest cart.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param fetchOptions - Fetch options\r\n * @returns Logout confirmation with optional new guest cart ID\r\n *\r\n * @example\r\n * ```typescript\r\n * const { cartId } = await client.customer.logout(sessionId);\r\n *\r\n * // Clear session cookie\r\n * cookies().delete('session-id');\r\n *\r\n * // If cart was migrated, store the new guest cart ID\r\n * if (cartId) {\r\n * cookies().set('cart-id', cartId);\r\n * }\r\n * ```\r\n */\r\n async logout(\r\n sessionId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<LogoutResponse> {\r\n return fetcher.request<LogoutResponse>(\r\n \"/api/storefront/v1/customer/(auth)/logout\",\r\n {\r\n method: \"POST\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Get the currently authenticated customer's profile.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param fetchOptions - Fetch options\r\n * @returns Current customer data\r\n * @throws AuthError if session is invalid or expired\r\n *\r\n * @example\r\n * ```typescript\r\n * const sessionId = cookies().get('session-id')?.value;\r\n * if (sessionId) {\r\n * const { customer } = await client.customer.getUser(sessionId);\r\n * console.log(`Welcome back, ${customer.firstName}!`);\r\n * }\r\n * ```\r\n */\r\n async getUser(\r\n sessionId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<GetUserResponse> {\r\n return fetcher.request<GetUserResponse>(\r\n \"/api/storefront/v1/customer/(auth)/get-user\",\r\n {\r\n method: \"GET\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Verify a customer's email address using the token sent during registration.\r\n *\r\n * @param token - Email verification token\r\n * @param fetchOptions - Fetch options\r\n * @returns Verification confirmation\r\n * @throws ValidationError if token is invalid or expired\r\n *\r\n * @example\r\n * ```typescript\r\n * // Token comes from the verification email link\r\n * const token = searchParams.get('token');\r\n *\r\n * const { message } = await client.customer.verifyEmail(token);\r\n * console.log(message); // \"Email verified successfully. You can now log in.\"\r\n * ```\r\n */\r\n async verifyEmail(\r\n token: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<VerifyEmailResponse> {\r\n return fetcher.request<VerifyEmailResponse>(\r\n \"/api/storefront/v1/customer/(auth)/verify-email\",\r\n {\r\n method: \"GET\",\r\n params: { token },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Resend the verification email for an unverified customer.\r\n * A new verification email is sent automatically by the server.\r\n *\r\n * @param customerId - The customer's ID (from failed login response)\r\n * @param fetchOptions - Fetch options\r\n * @returns Success message\r\n * @throws ValidationError if customer is already verified or not found\r\n *\r\n * @example\r\n * ```typescript\r\n * // After login fails with requiresVerification\r\n * const { message } = await client.customer.resendVerification(customerId);\r\n *\r\n * // Verification email is sent automatically by the server\r\n * console.log(message); // \"Verification email sent.\"\r\n * ```\r\n */\r\n async resendVerification(\r\n customerId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<ResendVerificationResponse> {\r\n return fetcher.request<ResendVerificationResponse>(\r\n \"/api/storefront/v1/customer/(auth)/resend-verification\",\r\n {\r\n method: \"POST\",\r\n body: { customerId },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Request a password reset for a customer account.\r\n * The server sends a password reset email directly to the customer.\r\n * Returns success even if email doesn't exist (to prevent email enumeration).\r\n *\r\n * Note: The reset token is never exposed to the client for security.\r\n * The email is sent server-side with the reset link.\r\n *\r\n * @param email - Customer's email address\r\n * @param fetchOptions - Fetch options\r\n * @returns Generic success message (same whether email exists or not)\r\n *\r\n * @example\r\n * ```typescript\r\n * const response = await client.customer.forgotPassword('john@example.com');\r\n *\r\n * // Always show same message to user (email sent server-side)\r\n * console.log(response.message);\r\n * // \"If an account exists with that email, password reset instructions have been sent.\"\r\n * ```\r\n */\r\n async forgotPassword(\r\n email: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<ForgotPasswordResponse> {\r\n return fetcher.request<ForgotPasswordResponse>(\r\n \"/api/storefront/v1/customer/(auth)/forgot-password\",\r\n {\r\n method: \"POST\",\r\n body: { email },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Reset a customer's password using a valid reset token.\r\n * The token is sent via email by the forgotPassword endpoint.\r\n * After successful reset, all existing sessions are invalidated.\r\n *\r\n * @param token - Password reset token (from email link)\r\n * @param password - New password (minimum 8 characters)\r\n * @param fetchOptions - Fetch options\r\n * @returns Success confirmation\r\n * @throws ValidationError if token is invalid or expired\r\n *\r\n * @example\r\n * ```typescript\r\n * // Token comes from the reset email link\r\n * const token = searchParams.get('token');\r\n *\r\n * try {\r\n * const { message } = await client.customer.resetPassword(token, newPassword);\r\n * console.log(message); // \"Password reset successful...\"\r\n *\r\n * // Redirect to login page\r\n * redirect('/login?reset=success');\r\n * } catch (error) {\r\n * if (error instanceof ValidationError) {\r\n * // Token invalid or expired\r\n * console.error('Please request a new password reset');\r\n * }\r\n * }\r\n * ```\r\n */\r\n async resetPassword(\r\n token: string,\r\n password: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<ResetPasswordResponse> {\r\n return fetcher.request<ResetPasswordResponse>(\r\n \"/api/storefront/v1/customer/(auth)/reset-password\",\r\n {\r\n method: \"POST\",\r\n body: { token, password },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n // =========================================================================\r\n // Profile Management Methods\r\n // =========================================================================\r\n\r\n /**\r\n * Update the authenticated customer's profile.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param data - Profile data to update (firstName, lastName, email)\r\n * @param fetchOptions - Fetch options\r\n * @returns Updated customer data\r\n * @throws AuthError if session is invalid\r\n * @throws ValidationError if email is already taken by another customer\r\n *\r\n * @example\r\n * ```typescript\r\n * const { customer } = await client.customer.updateProfile(sessionId, {\r\n * firstName: 'Jane',\r\n * lastName: 'Smith',\r\n * email: 'jane.smith@example.com'\r\n * });\r\n *\r\n * console.log('Profile updated:', customer.email);\r\n * ```\r\n */\r\n async updateProfile(\r\n sessionId: string,\r\n data: UpdateProfileData,\r\n fetchOptions?: FetchOptions\r\n ): Promise<UpdateProfileResponse> {\r\n return fetcher.request<UpdateProfileResponse>(\r\n \"/api/storefront/v1/customer/edit-user\",\r\n {\r\n method: \"PATCH\",\r\n headers: buildSessionHeaders(sessionId),\r\n body: data,\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Delete the authenticated customer's account.\r\n * This action is permanent and cannot be undone.\r\n * All associated data (sessions, wishlist, etc.) will be deleted.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param fetchOptions - Fetch options\r\n * @returns Deletion confirmation\r\n * @throws AuthError if session is invalid\r\n *\r\n * @example\r\n * ```typescript\r\n * // Confirm with user before calling\r\n * if (confirm('Are you sure you want to delete your account?')) {\r\n * await client.customer.deleteAccount(sessionId);\r\n *\r\n * // Clear session cookie\r\n * cookies().delete('session-id');\r\n *\r\n * // Redirect to home page\r\n * redirect('/');\r\n * }\r\n * ```\r\n */\r\n async deleteAccount(\r\n sessionId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<DeleteAccountResponse> {\r\n return fetcher.request<DeleteAccountResponse>(\r\n \"/api/storefront/v1/customer/delete-user\",\r\n {\r\n method: \"DELETE\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Get the customer's order history.\r\n * Returns all orders with line items and product details.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param customerId - The customer's ID\r\n * @param fetchOptions - Fetch options\r\n * @returns List of customer orders\r\n *\r\n * @example\r\n * ```typescript\r\n * const { orders } = await client.customer.getOrders(sessionId, customerId);\r\n *\r\n * orders.forEach(order => {\r\n * console.log(`Order #${order.orderNumber}: ${order.status}`);\r\n * order.OrderLineItems.forEach(item => {\r\n * console.log(` - ${item.name} x${item.quantity}`);\r\n * });\r\n * });\r\n * ```\r\n */\r\n async getOrders(\r\n sessionId: string,\r\n customerId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<GetOrdersResponse> {\r\n return fetcher.request<GetOrdersResponse>(\r\n `/api/storefront/v1/customer/get-orders/${customerId}`,\r\n {\r\n method: \"GET\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n // =========================================================================\r\n // Wishlist (Nested Resource)\r\n // =========================================================================\r\n\r\n /**\r\n * Wishlist management methods.\r\n * Access via `client.customer.wishlist.get()`, `.add()`, `.remove()`.\r\n */\r\n wishlist: {\r\n /**\r\n * Get the customer's wishlist.\r\n * Returns all wishlist items with product and variation details.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param fetchOptions - Fetch options\r\n * @returns Wishlist items with product details\r\n * @throws AuthError if session is invalid\r\n *\r\n * @example\r\n * ```typescript\r\n * const { items } = await client.customer.wishlist.get(sessionId);\r\n *\r\n * items.forEach(item => {\r\n * console.log(`${item.product.name} - $${item.product.price / 100}`);\r\n * if (item.variation) {\r\n * const options = item.variation.options\r\n * .map(o => `${o.optionType.name}: ${o.value}`)\r\n * .join(', ');\r\n * console.log(` Variant: ${options}`);\r\n * }\r\n * });\r\n * ```\r\n */\r\n async get(\r\n sessionId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<WishlistResponse> {\r\n return fetcher.request<WishlistResponse>(\r\n \"/api/storefront/v1/customer/wishlist\",\r\n {\r\n method: \"GET\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Add a product to the customer's wishlist.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param productId - The product ID to add\r\n * @param variationId - Optional variation ID (for products with variations)\r\n * @param fetchOptions - Fetch options\r\n * @returns Success message\r\n * @throws AuthError if session is invalid\r\n * @throws ValidationError if product already in wishlist\r\n *\r\n * @example\r\n * ```typescript\r\n * // Add a simple product\r\n * await client.customer.wishlist.add(sessionId, 'prod_123');\r\n *\r\n * // Add a product with a specific variation\r\n * await client.customer.wishlist.add(sessionId, 'prod_123', 'var_456');\r\n * ```\r\n */\r\n async add(\r\n sessionId: string,\r\n productId: string,\r\n variationId?: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<AddToWishlistResponse> {\r\n return fetcher.request<AddToWishlistResponse>(\r\n \"/api/storefront/v1/customer/wishlist\",\r\n {\r\n method: \"POST\",\r\n headers: buildSessionHeaders(sessionId),\r\n body: { productId, variationId },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Remove a product from the customer's wishlist.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param productId - The product ID to remove\r\n * @param variationId - Optional variation ID (must match if item was added with variation)\r\n * @param fetchOptions - Fetch options\r\n * @returns Success message\r\n * @throws AuthError if session is invalid\r\n * @throws NotFoundError if item not in wishlist\r\n *\r\n * @example\r\n * ```typescript\r\n * // Remove a simple product\r\n * await client.customer.wishlist.remove(sessionId, 'prod_123');\r\n *\r\n * // Remove a specific variation\r\n * await client.customer.wishlist.remove(sessionId, 'prod_123', 'var_456');\r\n * ```\r\n */\r\n async remove(\r\n sessionId: string,\r\n productId: string,\r\n variationId?: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<RemoveFromWishlistResponse> {\r\n return fetcher.request<RemoveFromWishlistResponse>(\r\n \"/api/storefront/v1/customer/wishlist\",\r\n {\r\n method: \"DELETE\",\r\n headers: buildSessionHeaders(sessionId),\r\n body: { productId, variationId },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the customer resource\r\n */\r\nexport type CustomerResource = ReturnType<typeof createCustomerResource>;\r\n","import type { FetchOptions, Order } from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Order resource for fetching order details\r\n *\r\n * Used for order confirmation pages and viewing order details.\r\n * For customer order history, use the customer.getOrders() method instead.\r\n */\r\nexport function createOrderResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get order details by ID.\r\n *\r\n * Retrieves complete order information including line items,\r\n * customer data, and shipment method with tracking info.\r\n *\r\n * @param orderId - The order ID to fetch\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Complete order details\r\n * @throws NotFoundError if order doesn't exist or belongs to different store\r\n *\r\n * @example Basic usage (order confirmation page)\r\n * ```typescript\r\n * const order = await client.order.get(orderId);\r\n * console.log(`Order #${order.orderNumber} - ${order.status}`);\r\n * console.log(`Total: ${order.totalAmount / 100} EUR`);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const order = await client.order.get(orderId, {\r\n * next: { revalidate: 60, tags: ['order', orderId] }\r\n * });\r\n * ```\r\n *\r\n * @example Display line items\r\n * ```typescript\r\n * const order = await client.order.get(orderId);\r\n * order.OrderLineItems.forEach(item => {\r\n * if (item.itemType !== 'SHIPPING') {\r\n * console.log(`${item.name} x${item.quantity} = ${item.totalAmount / 100} EUR`);\r\n * }\r\n * });\r\n * ```\r\n *\r\n * @example Show tracking info\r\n * ```typescript\r\n * const order = await client.order.get(orderId);\r\n * if (order.orderShipmentMethod?.trackingNumber) {\r\n * console.log(`Tracking: ${order.orderShipmentMethod.trackingNumber}`);\r\n * order.orderShipmentMethod.trackingUrls?.forEach(url => {\r\n * console.log(`Track at: ${url}`);\r\n * });\r\n * }\r\n * ```\r\n */\r\n async get(orderId: string, options?: FetchOptions): Promise<Order> {\r\n return fetcher.request<Order>(\r\n `/api/storefront/v1/order/${encodeURIComponent(orderId)}`,\r\n {\r\n ...options,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the order resource\r\n */\r\nexport type OrderResource = ReturnType<typeof createOrderResource>;\r\n","import type {\r\n FetchOptions,\r\n CheckoutParams,\r\n StripeCheckoutResponse,\r\n PaytrailCheckoutResponse,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Extended options for checkout requests\r\n *\r\n * Checkout requires cart and session context via headers.\r\n */\r\nexport interface CheckoutOptions extends FetchOptions {\r\n /**\r\n * Cart ID for guest checkout.\r\n * Pass this when the user is not logged in.\r\n */\r\n cartId?: string;\r\n /**\r\n * Session ID for authenticated checkout.\r\n * Pass this when the user is logged in.\r\n */\r\n sessionId?: string;\r\n}\r\n\r\n/**\r\n * Checkout resource for payment processing\r\n *\r\n * Handles both Stripe and Paytrail payment providers.\r\n */\r\nexport function createCheckoutResource(fetcher: Fetcher) {\r\n /**\r\n * Build headers with cart/session context\r\n */\r\n function buildCheckoutHeaders(options?: CheckoutOptions): Record<string, string> {\r\n const headers: Record<string, string> = {};\r\n if (options?.cartId) {\r\n headers[\"x-cart-id\"] = options.cartId;\r\n }\r\n if (options?.sessionId) {\r\n headers[\"x-session-id\"] = options.sessionId;\r\n }\r\n return headers;\r\n }\r\n\r\n /**\r\n * Build checkout request body\r\n */\r\n function buildCheckoutBody(params: CheckoutParams) {\r\n return {\r\n orderId: params.orderId,\r\n chosenShipmentMethod: params.shipmentMethod,\r\n customerData: params.customerData,\r\n successUrl: params.successUrl,\r\n cancelUrl: params.cancelUrl,\r\n };\r\n }\r\n\r\n return {\r\n /**\r\n * Create a Stripe checkout session.\r\n *\r\n * Redirects the user to Stripe's hosted checkout page.\r\n * Cart items are validated and stock is reserved on the server.\r\n *\r\n * @param params - Checkout parameters (customer data, shipping, URLs)\r\n * @param options - Checkout options including cart/session context\r\n * @returns URL to redirect user to Stripe checkout\r\n * @throws ValidationError for invalid data or empty cart\r\n * @throws StorefrontError for inventory issues\r\n *\r\n * @example Basic usage with redirect\r\n * ```typescript\r\n * const { url } = await client.checkout.stripe({\r\n * customerData: {\r\n * first_name: \"John\",\r\n * last_name: \"Doe\",\r\n * email: \"john@example.com\",\r\n * address: \"123 Main St\",\r\n * postal_code: \"00100\",\r\n * city: \"Helsinki\",\r\n * phone: \"+358401234567\"\r\n * },\r\n * shipmentMethod: {\r\n * shipmentMethodId: \"ship_123\",\r\n * pickupId: null\r\n * },\r\n * orderId: \"order_abc123\",\r\n * successUrl: \"https://mystore.com/success\",\r\n * cancelUrl: \"https://mystore.com/cancel\"\r\n * }, {\r\n * cartId: \"cart_xyz\", // For guest users\r\n * sessionId: \"sess_123\" // For logged-in users\r\n * });\r\n *\r\n * // Redirect to Stripe\r\n * window.location.href = url;\r\n * ```\r\n */\r\n async stripe(\r\n params: CheckoutParams,\r\n options?: CheckoutOptions\r\n ): Promise<StripeCheckoutResponse> {\r\n const headers = buildCheckoutHeaders(options);\r\n const body = buildCheckoutBody(params);\r\n\r\n return fetcher.request<StripeCheckoutResponse>(\r\n \"/api/storefront/v1/payments/stripe/checkout\",\r\n {\r\n method: \"POST\",\r\n body,\r\n headers: {\r\n ...options?.headers,\r\n ...headers,\r\n },\r\n ...options,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Create a Paytrail checkout session.\r\n *\r\n * Returns payment providers for Finnish payment methods.\r\n * Cart items are validated and stock is reserved on the server.\r\n *\r\n * @param params - Checkout parameters (customer data, shipping, URLs)\r\n * @param options - Checkout options including cart/session context\r\n * @returns Paytrail response with available payment providers\r\n * @throws ValidationError for invalid data or empty cart\r\n * @throws StorefrontError for inventory issues\r\n *\r\n * @example Display payment providers\r\n * ```typescript\r\n * const response = await client.checkout.paytrail({\r\n * customerData: {\r\n * first_name: \"Matti\",\r\n * last_name: \"Meikäläinen\",\r\n * email: \"matti@example.fi\",\r\n * address: \"Mannerheimintie 1\",\r\n * postal_code: \"00100\",\r\n * city: \"Helsinki\",\r\n * phone: \"+358401234567\"\r\n * },\r\n * shipmentMethod: {\r\n * shipmentMethodId: \"ship_123\",\r\n * pickupId: \"pickup_456\" // For pickup points\r\n * },\r\n * orderId: \"order_abc123\",\r\n * successUrl: \"https://mystore.com/success\",\r\n * cancelUrl: \"https://mystore.com/cancel\"\r\n * }, {\r\n * cartId: \"cart_xyz\"\r\n * });\r\n *\r\n * // Group providers by type\r\n * const banks = response.providers.filter(p => p.group === \"bank\");\r\n * const mobile = response.providers.filter(p => p.group === \"mobile\");\r\n * const cards = response.providers.filter(p => p.group === \"creditcard\");\r\n * ```\r\n *\r\n * @example Submit payment form\r\n * ```typescript\r\n * const provider = response.providers.find(p => p.id === \"nordea\");\r\n *\r\n * // Create and submit a form\r\n * const form = document.createElement(\"form\");\r\n * form.method = \"POST\";\r\n * form.action = provider.url;\r\n *\r\n * provider.parameters.forEach(({ name, value }) => {\r\n * const input = document.createElement(\"input\");\r\n * input.type = \"hidden\";\r\n * input.name = name;\r\n * input.value = value;\r\n * form.appendChild(input);\r\n * });\r\n *\r\n * document.body.appendChild(form);\r\n * form.submit();\r\n * ```\r\n */\r\n async paytrail(\r\n params: CheckoutParams,\r\n options?: CheckoutOptions\r\n ): Promise<PaytrailCheckoutResponse> {\r\n const headers = buildCheckoutHeaders(options);\r\n const body = buildCheckoutBody(params);\r\n\r\n return fetcher.request<PaytrailCheckoutResponse>(\r\n \"/api/storefront/v1/payments/paytrail/checkout\",\r\n {\r\n method: \"POST\",\r\n body,\r\n headers: {\r\n ...options?.headers,\r\n ...headers,\r\n },\r\n ...options,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the checkout resource\r\n */\r\nexport type CheckoutResource = ReturnType<typeof createCheckoutResource>;\r\n","import type { StorefrontClientConfig } from \"./types/index.js\";\nimport { createFetcher } from \"./utils/fetch.js\";\nimport { createStoreResource, type StoreResource } from \"./resources/store.js\";\nimport {\n createProductsResource,\n type ProductsResource,\n} from \"./resources/products.js\";\nimport {\n createCategoriesResource,\n type CategoriesResource,\n} from \"./resources/categories.js\";\nimport { createCartResource, type CartResource } from \"./resources/cart.js\";\nimport {\n createShippingResource,\n type ShippingResource,\n} from \"./resources/shipping.js\";\nimport {\n createCustomerResource,\n type CustomerResource,\n} from \"./resources/customer.js\";\nimport {\n createOrderResource,\n type OrderResource,\n} from \"./resources/order.js\";\nimport {\n createCheckoutResource,\n type CheckoutResource,\n} from \"./resources/checkout.js\";\n\n/**\n * The Storefront API client\n */\nexport interface StorefrontClient {\n /**\n * The base URL for API requests\n */\n readonly baseUrl: string;\n\n /**\n * Store configuration resource\n */\n readonly store: StoreResource;\n\n /**\n * Products resource\n */\n readonly products: ProductsResource;\n\n /**\n * Categories resource\n */\n readonly categories: CategoriesResource;\n\n /**\n * Cart resource\n */\n readonly cart: CartResource;\n\n /**\n * Shipping resource\n */\n readonly shipping: ShippingResource;\n\n /**\n * Customer authentication and account management resource\n */\n readonly customer: CustomerResource;\n\n /**\n * Order resource for fetching order details\n */\n readonly order: OrderResource;\n\n /**\n * Checkout resource for payment processing\n */\n readonly checkout: CheckoutResource;\n}\n\n/**\n * Create a new Storefront API client\n */\nexport function createStorefrontClient(config: StorefrontClientConfig): StorefrontClient {\n if (!config.apiKey) {\n throw new Error(\"apiKey is required\");\n }\n if (!config.baseUrl) {\n throw new Error(\"baseUrl is required\");\n }\n\n // Ensure baseUrl doesn't have trailing slash\n const baseUrl = config.baseUrl.replace(/\\/$/, \"\");\n\n // Create the fetcher for making authenticated requests\n const fetcher = createFetcher({\n apiKey: config.apiKey,\n baseUrl,\n timeout: config.timeout,\n });\n\n return {\n baseUrl,\n store: createStoreResource(fetcher),\n products: createProductsResource(fetcher),\n categories: createCategoriesResource(fetcher),\n cart: createCartResource(fetcher),\n shipping: createShippingResource(fetcher),\n customer: createCustomerResource(fetcher),\n order: createOrderResource(fetcher),\n checkout: createCheckoutResource(fetcher),\n };\n}\n","/**\r\n * Pricing Utilities\r\n *\r\n * Helper functions for calculating prices with sale logic.\r\n */\r\n\r\nimport type { ProductDetail, ProductVariation } from \"../types/products.js\";\r\nimport type { PriceInfo } from \"../types/cart.js\";\r\n\r\n/**\r\n * Check if a sale is currently active based on start and end dates.\r\n *\r\n * @param startDate - Sale start date (ISO string, Date, null, or undefined)\r\n * @param endDate - Sale end date (ISO string, Date, null, or undefined)\r\n * @returns true if the sale is currently active\r\n *\r\n * @example\r\n * ```typescript\r\n * // No dates = always active\r\n * isSaleActive(null, null); // true\r\n *\r\n * // Only start date = active if past start\r\n * isSaleActive(\"2024-01-01\", null); // true if today >= Jan 1\r\n *\r\n * // Both dates = active if within range\r\n * isSaleActive(\"2024-01-01\", \"2024-12-31\"); // true if within range\r\n * ```\r\n */\r\nexport function isSaleActive(\r\n startDate: Date | string | null | undefined,\r\n endDate: Date | string | null | undefined\r\n): boolean {\r\n // If no dates are set, sale is considered active\r\n if (!startDate && !endDate) {\r\n return true;\r\n }\r\n\r\n const now = new Date();\r\n const start = startDate ? new Date(startDate) : null;\r\n const end = endDate ? new Date(endDate) : null;\r\n\r\n // If only start date is set\r\n if (start && !end) {\r\n return now >= start;\r\n }\r\n\r\n // If only end date is set\r\n if (!start && end) {\r\n return now <= end;\r\n }\r\n\r\n // If both dates are set\r\n if (start && end) {\r\n return now >= start && now <= end;\r\n }\r\n\r\n return true;\r\n}\r\n\r\n/**\r\n * Get price information for a product or variation.\r\n * Returns the effective price (sale or regular) and sale status.\r\n * All prices are in cents.\r\n *\r\n * @param product - The product to get price info for\r\n * @param variation - Optional variation (takes precedence over product price)\r\n * @returns Price information with effective price, original price, and sale status\r\n *\r\n * @example\r\n * ```typescript\r\n * // Product without variation\r\n * const priceInfo = getPriceInfo(product);\r\n * console.log(priceInfo.effectivePrice); // 1990 (cents)\r\n * console.log(priceInfo.isOnSale); // true\r\n *\r\n * // Product with selected variation\r\n * const priceInfo = getPriceInfo(product, selectedVariation);\r\n * ```\r\n */\r\nexport function getPriceInfo(\r\n product: ProductDetail,\r\n variation?: ProductVariation\r\n): PriceInfo {\r\n if (variation) {\r\n // Use variation pricing\r\n const isOnSale =\r\n isSaleActive(variation.saleStartDate, variation.saleEndDate) &&\r\n variation.salePrice !== null;\r\n\r\n const originalPrice = variation.price ?? product.price;\r\n const effectivePrice = isOnSale\r\n ? (variation.salePrice ?? originalPrice)\r\n : originalPrice;\r\n\r\n return {\r\n effectivePrice,\r\n originalPrice,\r\n isOnSale,\r\n salePercent: isOnSale ? (variation.salePercent ?? null) : null,\r\n };\r\n }\r\n\r\n // Use product pricing\r\n const isOnSale =\r\n isSaleActive(product.saleStartDate, product.saleEndDate) &&\r\n product.salePrice !== null;\r\n\r\n const originalPrice = product.price;\r\n const effectivePrice = isOnSale\r\n ? (product.salePrice ?? originalPrice)\r\n : originalPrice;\r\n\r\n return {\r\n effectivePrice,\r\n originalPrice,\r\n isOnSale,\r\n salePercent: isOnSale ? (product.salePercent ?? null) : null,\r\n };\r\n}\r\n","/**\r\n * Cart Calculation Utilities\r\n *\r\n * Functions for calculating cart totals with campaign discounts.\r\n */\r\n\r\nimport type { CartItem } from \"../types/cart.js\";\r\nimport type { Campaign } from \"../types/storeconfig.js\";\r\nimport type {\r\n CalculatedCartItem,\r\n FreeShippingStatus,\r\n CartCalculationResult,\r\n} from \"../types/cart.js\";\r\nimport { getPriceInfo } from \"./pricing.js\";\r\n\r\n/**\r\n * Internal type for tracking eligible units in Buy X Pay Y campaigns\r\n */\r\ninterface EligibleUnit {\r\n price: number;\r\n productId: string;\r\n variationId?: string;\r\n originalItem: CartItem;\r\n}\r\n\r\n/**\r\n * Calculate cart totals with campaign discounts applied.\r\n *\r\n * Supports two campaign types:\r\n * - **FREE_SHIPPING**: Free shipping when cart total exceeds minimum spend\r\n * - **BUY_X_PAY_Y**: Buy X items, pay for Y (e.g., Buy 3 Pay 2 = 1 free item)\r\n *\r\n * @param items - Cart items to calculate\r\n * @param campaigns - Active campaigns to apply\r\n * @returns Calculation result with totals, savings, and free shipping status\r\n *\r\n * @example\r\n * ```typescript\r\n * const result = calculateCartWithCampaigns(cartItems, activeCampaigns);\r\n *\r\n * console.log(result.cartTotal); // 4990 (cents)\r\n * console.log(result.totalSavings); // 1990 (cents)\r\n * console.log(result.freeShipping.isEligible); // true\r\n *\r\n * // Render calculated items\r\n * result.calculatedItems.forEach(({ item, paidQuantity, freeQuantity }) => {\r\n * console.log(`${item.product.name}: ${paidQuantity} paid, ${freeQuantity} free`);\r\n * });\r\n * ```\r\n */\r\nexport function calculateCartWithCampaigns(\r\n items: CartItem[],\r\n campaigns: Campaign[]\r\n): CartCalculationResult {\r\n // Find applicable campaigns\r\n const buyXPayYCampaign = campaigns.find(\r\n (c) => c.type === \"BUY_X_PAY_Y\" && c.isActive\r\n );\r\n\r\n // Calculate original total (without campaign discounts)\r\n const originalTotal = items.reduce((total, { product, variation, cartQuantity }) => {\r\n const priceInfo = getPriceInfo(product, variation);\r\n return total + priceInfo.effectivePrice * cartQuantity;\r\n }, 0);\r\n\r\n // Default free shipping status (not eligible)\r\n const freeShipping: FreeShippingStatus = {\r\n isEligible: false,\r\n minimumSpend: 0,\r\n remainingAmount: 0,\r\n };\r\n\r\n // No Buy X Pay Y campaign - return items as-is\r\n if (!buyXPayYCampaign?.BuyXPayYCampaign) {\r\n const calculatedItems = items.map((item) => ({\r\n item,\r\n paidQuantity: item.cartQuantity,\r\n freeQuantity: 0,\r\n totalQuantity: item.cartQuantity,\r\n }));\r\n\r\n return {\r\n calculatedItems,\r\n cartTotal: originalTotal,\r\n originalTotal,\r\n totalSavings: 0,\r\n freeShipping,\r\n };\r\n }\r\n\r\n // Apply Buy X Pay Y campaign\r\n const { buyQuantity, payQuantity, applicableCategories } =\r\n buyXPayYCampaign.BuyXPayYCampaign;\r\n const applicableCategoryIds = new Set(\r\n applicableCategories.map((c) => c.id)\r\n );\r\n\r\n // Find all individual units eligible for the campaign\r\n const eligibleUnits: EligibleUnit[] = items.flatMap((item) => {\r\n const { product, variation } = item;\r\n const itemCategories = product.categories?.map((cat) => cat.id) || [];\r\n\r\n // Check if any of the product's categories are in the campaign's list\r\n const isEligible = itemCategories.some((id) =>\r\n applicableCategoryIds.has(id)\r\n );\r\n\r\n if (isEligible) {\r\n const priceInfo = getPriceInfo(product, variation);\r\n\r\n // Create an entry for each single unit of the item\r\n return Array.from({ length: item.cartQuantity }, () => ({\r\n price: priceInfo.effectivePrice,\r\n productId: product.id,\r\n variationId: variation?.id,\r\n originalItem: item,\r\n }));\r\n }\r\n\r\n return [];\r\n });\r\n\r\n // Not enough eligible items - return original quantities\r\n if (eligibleUnits.length < buyQuantity) {\r\n const calculatedItems = items.map((item) => ({\r\n item,\r\n paidQuantity: item.cartQuantity,\r\n freeQuantity: 0,\r\n totalQuantity: item.cartQuantity,\r\n }));\r\n\r\n return {\r\n calculatedItems,\r\n cartTotal: originalTotal,\r\n originalTotal,\r\n totalSavings: 0,\r\n freeShipping,\r\n };\r\n }\r\n\r\n // Sort by price to find the cheapest items to make free\r\n eligibleUnits.sort((a, b) => a.price - b.price);\r\n\r\n const numToMakeFree = buyQuantity - payQuantity;\r\n const itemsToMakeFree = eligibleUnits.slice(0, numToMakeFree);\r\n\r\n // Calculate total savings from free items\r\n const totalSavings = itemsToMakeFree.reduce(\r\n (sum, item) => sum + item.price,\r\n 0\r\n );\r\n\r\n // Create a map to count how many units of each product/variation should be free\r\n const freeCountMap = new Map<string, number>();\r\n for (const freebie of itemsToMakeFree) {\r\n const key = `${freebie.productId}${freebie.variationId ? `_${freebie.variationId}` : \"\"}`;\r\n freeCountMap.set(key, (freeCountMap.get(key) || 0) + 1);\r\n }\r\n\r\n // Calculate paid and free quantities for each item\r\n const calculatedItems: CalculatedCartItem[] = items.map((item) => {\r\n const key = `${item.product.id}${item.variation?.id ? `_${item.variation.id}` : \"\"}`;\r\n const freeQuantity = freeCountMap.get(key) || 0;\r\n const paidQuantity = item.cartQuantity - freeQuantity;\r\n\r\n return {\r\n item,\r\n paidQuantity: Math.max(0, paidQuantity),\r\n freeQuantity,\r\n totalQuantity: item.cartQuantity,\r\n };\r\n });\r\n\r\n // Calculate final cart total after Buy X Pay Y discounts\r\n const cartTotal = originalTotal - totalSavings;\r\n\r\n return {\r\n calculatedItems,\r\n cartTotal,\r\n originalTotal,\r\n totalSavings,\r\n freeShipping,\r\n };\r\n}\r\n"],"mappings":";AAGO,IAAM,kBAAN,MAAM,yBAAwB,MAAM;AAAA,EAIzC,YAAY,SAAiB,QAAgB,MAAc;AACzD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAGZ,UAAM,mBAAmB;AAGzB,QAAI,iBAAiB,mBAAmB;AACtC,uBAAiB,kBAAkB,MAAM,gBAAe;AAAA,IAC1D;AAAA,EACF;AACF;AAKO,IAAM,YAAN,cAAwB,gBAAgB;AAAA,EAC7C,YAAY,UAAkB,8BAA8B;AAC1D,UAAM,SAAS,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