@putiikkipalvelu/storefront-sdk 0.2.3 → 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 +28 -90
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -75
- package/dist/index.d.ts +32 -75
- package/dist/index.js +18 -80
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -91,7 +91,7 @@ interface FeatureFlags {
|
|
|
91
91
|
reviewsEnabled: boolean;
|
|
92
92
|
}
|
|
93
93
|
/** Campaign type */
|
|
94
|
-
type CampaignType = "
|
|
94
|
+
type CampaignType = "BUY_X_PAY_Y";
|
|
95
95
|
/**
|
|
96
96
|
* Store campaign (promotion)
|
|
97
97
|
*/
|
|
@@ -116,24 +116,9 @@ interface Campaign {
|
|
|
116
116
|
createdAt: string;
|
|
117
117
|
/** Last update timestamp (ISO 8601) */
|
|
118
118
|
updatedAt: string;
|
|
119
|
-
/** Free shipping campaign details (if type is FREE_SHIPPING) */
|
|
120
|
-
FreeShippingCampaign: FreeShippingCampaign | null;
|
|
121
119
|
/** Buy X Pay Y campaign details (if type is BUY_X_PAY_Y) */
|
|
122
120
|
BuyXPayYCampaign: BuyXPayYCampaign | null;
|
|
123
121
|
}
|
|
124
|
-
/**
|
|
125
|
-
* Free shipping campaign details
|
|
126
|
-
*/
|
|
127
|
-
interface FreeShippingCampaign {
|
|
128
|
-
/** Unique identifier */
|
|
129
|
-
id: string;
|
|
130
|
-
/** Parent campaign ID */
|
|
131
|
-
campaignId: string;
|
|
132
|
-
/** Minimum spend in cents to qualify for free shipping */
|
|
133
|
-
minimumSpend: number;
|
|
134
|
-
/** Shipping methods eligible for free shipping */
|
|
135
|
-
shipmentMethods: ShipmentMethod[];
|
|
136
|
-
}
|
|
137
122
|
/**
|
|
138
123
|
* Buy X Pay Y campaign details (e.g., "Buy 3, Pay 2")
|
|
139
124
|
*/
|
|
@@ -152,18 +137,19 @@ interface BuyXPayYCampaign {
|
|
|
152
137
|
/**
|
|
153
138
|
* Shipit shipping method details
|
|
154
139
|
* Represents a shipping service synced from the Shipit API
|
|
140
|
+
* Supports multiple carriers in a single method for multi-carrier shipping
|
|
155
141
|
*/
|
|
156
142
|
interface ShipitShippingMethod {
|
|
157
143
|
/** Unique ID */
|
|
158
144
|
id: string;
|
|
159
|
-
/** Shipit service
|
|
160
|
-
|
|
145
|
+
/** Shipit service identifiers for all selected carriers */
|
|
146
|
+
serviceIds: string[];
|
|
161
147
|
/** Service name */
|
|
162
148
|
name: string;
|
|
163
|
-
/** Carrier
|
|
164
|
-
|
|
165
|
-
/** Carrier logo
|
|
166
|
-
|
|
149
|
+
/** Carrier names (e.g., ["Posti", "Matkahuolto"]) */
|
|
150
|
+
carriers: string[];
|
|
151
|
+
/** Carrier logo URLs */
|
|
152
|
+
logos: string[];
|
|
167
153
|
/** Whether pickup is included */
|
|
168
154
|
pickUpIncluded: boolean;
|
|
169
155
|
/** Whether home delivery is available */
|
|
@@ -192,10 +178,8 @@ interface ShipitShippingMethod {
|
|
|
192
178
|
type: string;
|
|
193
179
|
/** Shipit price in cents */
|
|
194
180
|
price: number;
|
|
195
|
-
/** Whether pickup point
|
|
196
|
-
|
|
197
|
-
/** Whether only parcel locker delivery is available */
|
|
198
|
-
onlyParchelLocker: boolean;
|
|
181
|
+
/** Whether to show pickup point selector (true) or home delivery only (false) */
|
|
182
|
+
showPickupPoints: boolean;
|
|
199
183
|
/** Reference to parent shipment method */
|
|
200
184
|
shipmentMethodId: string;
|
|
201
185
|
/** Created timestamp */
|
|
@@ -576,7 +560,7 @@ interface PickupLocationOpeningHours {
|
|
|
576
560
|
}
|
|
577
561
|
/**
|
|
578
562
|
* A pickup location (parcel locker, pickup point, etc.)
|
|
579
|
-
* Returned from Shipit API with
|
|
563
|
+
* Returned from Shipit API with shipmentMethodId and price attached
|
|
580
564
|
*/
|
|
581
565
|
interface PickupLocation {
|
|
582
566
|
/** Unique location ID from Shipit */
|
|
@@ -605,7 +589,7 @@ interface PickupLocation {
|
|
|
605
589
|
distanceInMeters: number;
|
|
606
590
|
/** Distance from postal code in kilometers */
|
|
607
591
|
distanceInKilometers: number;
|
|
608
|
-
/** Location type */
|
|
592
|
+
/** Location type (e.g., "parcel_locker", "service_point", "outdoor_parcel_locker") */
|
|
609
593
|
type?: string;
|
|
610
594
|
/** Structured opening hours */
|
|
611
595
|
openingHours?: PickupLocationOpeningHours | null;
|
|
@@ -613,25 +597,19 @@ interface PickupLocation {
|
|
|
613
597
|
openingHoursRaw?: string | null;
|
|
614
598
|
/** Additional metadata */
|
|
615
599
|
metadata?: unknown | null;
|
|
616
|
-
/**
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
* Response from GET /shipment-methods
|
|
621
|
-
*/
|
|
622
|
-
interface ShipmentMethodsResponse {
|
|
623
|
-
/** Available shipment methods */
|
|
624
|
-
shipmentMethods: ShipmentMethod[];
|
|
600
|
+
/** The shipment method ID this location belongs to */
|
|
601
|
+
shipmentMethodId: string;
|
|
602
|
+
/** Price in cents (from store settings) */
|
|
603
|
+
price: number;
|
|
625
604
|
}
|
|
626
605
|
/**
|
|
627
606
|
* Response from GET /shipment-methods/[postalCode]
|
|
628
|
-
* Includes pickup locations near the postal code
|
|
629
607
|
*/
|
|
630
608
|
interface ShipmentMethodsWithLocationsResponse {
|
|
631
|
-
/**
|
|
632
|
-
|
|
633
|
-
/** Pickup locations
|
|
634
|
-
|
|
609
|
+
/** Home delivery methods (custom methods + Shipit home delivery) */
|
|
610
|
+
homeDeliveryMethods: ShipmentMethod[];
|
|
611
|
+
/** Pickup locations with shipmentMethodId and price attached */
|
|
612
|
+
pickupLocations: PickupLocation[];
|
|
635
613
|
}
|
|
636
614
|
|
|
637
615
|
/**
|
|
@@ -1717,58 +1695,37 @@ interface GetMethodsOptions extends FetchOptions {
|
|
|
1717
1695
|
*/
|
|
1718
1696
|
declare function createShippingResource(fetcher: Fetcher): {
|
|
1719
1697
|
/**
|
|
1720
|
-
* Get
|
|
1721
|
-
* Returns methods
|
|
1698
|
+
* Get shipping options for a specific postal code.
|
|
1699
|
+
* Returns home delivery methods and pickup locations.
|
|
1722
1700
|
*
|
|
1701
|
+
* @param postalCode - Customer's postal code (e.g., "00100")
|
|
1723
1702
|
* @param options - Fetch options including optional cartItems for weight-based filtering
|
|
1724
|
-
* @returns
|
|
1703
|
+
* @returns Home delivery methods and pickup locations
|
|
1725
1704
|
*
|
|
1726
1705
|
* @example
|
|
1727
1706
|
* ```typescript
|
|
1728
|
-
* const {
|
|
1707
|
+
* const { homeDeliveryMethods, pickupLocations } = await client.shipping.getWithLocations("00100");
|
|
1729
1708
|
*
|
|
1730
|
-
*
|
|
1709
|
+
* // Show home delivery options
|
|
1710
|
+
* homeDeliveryMethods.forEach(method => {
|
|
1731
1711
|
* console.log(`${method.name}: ${method.price / 100}€`);
|
|
1732
1712
|
* });
|
|
1733
|
-
* ```
|
|
1734
|
-
*
|
|
1735
|
-
* @example Weight-based filtering
|
|
1736
|
-
* ```typescript
|
|
1737
|
-
* // Pass cart items - SDK calculates weight automatically
|
|
1738
|
-
* const { shipmentMethods } = await client.shipping.getMethods({
|
|
1739
|
-
* cartItems: cartItems
|
|
1740
|
-
* });
|
|
1741
|
-
* ```
|
|
1742
|
-
*/
|
|
1743
|
-
getMethods(options?: GetMethodsOptions): Promise<ShipmentMethodsResponse>;
|
|
1744
|
-
/**
|
|
1745
|
-
* Get shipment methods with pickup locations for a specific postal code.
|
|
1746
|
-
* Calls the Shipit API to fetch nearby pickup points (parcel lockers, etc.)
|
|
1747
|
-
*
|
|
1748
|
-
* @param postalCode - Customer's postal code (e.g., "00100")
|
|
1749
|
-
* @param options - Fetch options including optional cartItems for weight-based filtering
|
|
1750
|
-
* @returns Shipment methods and nearby pickup locations with pricing
|
|
1751
|
-
*
|
|
1752
|
-
* @example
|
|
1753
|
-
* ```typescript
|
|
1754
|
-
* const { shipmentMethods, pricedLocations } = await client.shipping.getWithLocations("00100");
|
|
1755
1713
|
*
|
|
1756
1714
|
* // Show pickup locations
|
|
1757
|
-
*
|
|
1715
|
+
* pickupLocations.forEach(location => {
|
|
1758
1716
|
* console.log(`${location.name} - ${location.carrier}`);
|
|
1759
1717
|
* console.log(` ${location.address1}, ${location.city}`);
|
|
1760
1718
|
* console.log(` ${location.distanceInKilometers.toFixed(1)} km away`);
|
|
1761
|
-
* console.log(` Price: ${
|
|
1719
|
+
* console.log(` Price: ${location.price / 100}€`);
|
|
1762
1720
|
* });
|
|
1763
1721
|
* ```
|
|
1764
1722
|
*
|
|
1765
|
-
* @example Weight-based filtering
|
|
1723
|
+
* @example Weight-based filtering
|
|
1766
1724
|
* ```typescript
|
|
1767
|
-
* const {
|
|
1725
|
+
* const { homeDeliveryMethods, pickupLocations } = await client.shipping.getWithLocations(
|
|
1768
1726
|
* "00100",
|
|
1769
1727
|
* { cartItems: cartItems }
|
|
1770
1728
|
* );
|
|
1771
|
-
*
|
|
1772
1729
|
* // Only shows methods that support the cart's total weight
|
|
1773
1730
|
* ```
|
|
1774
1731
|
*/
|
|
@@ -2488,4 +2445,4 @@ declare class VerificationRequiredError extends StorefrontError {
|
|
|
2488
2445
|
constructor(message: string, customerId: string);
|
|
2489
2446
|
}
|
|
2490
2447
|
|
|
2491
|
-
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
|
|
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
|
*/
|
|
@@ -1471,9 +1438,6 @@ function getPriceInfo(product, variation) {
|
|
|
1471
1438
|
|
|
1472
1439
|
// src/utils/cart-calculations.ts
|
|
1473
1440
|
function calculateCartWithCampaigns(items, campaigns) {
|
|
1474
|
-
const freeShippingCampaign = campaigns.find(
|
|
1475
|
-
(c) => c.type === "FREE_SHIPPING" && c.isActive
|
|
1476
|
-
);
|
|
1477
1441
|
const buyXPayYCampaign = campaigns.find(
|
|
1478
1442
|
(c) => c.type === "BUY_X_PAY_Y" && c.isActive
|
|
1479
1443
|
);
|
|
@@ -1481,6 +1445,11 @@ function calculateCartWithCampaigns(items, campaigns) {
|
|
|
1481
1445
|
const priceInfo = getPriceInfo(product, variation);
|
|
1482
1446
|
return total + priceInfo.effectivePrice * cartQuantity;
|
|
1483
1447
|
}, 0);
|
|
1448
|
+
const freeShipping = {
|
|
1449
|
+
isEligible: false,
|
|
1450
|
+
minimumSpend: 0,
|
|
1451
|
+
remainingAmount: 0
|
|
1452
|
+
};
|
|
1484
1453
|
if (!buyXPayYCampaign?.BuyXPayYCampaign) {
|
|
1485
1454
|
const calculatedItems2 = items.map((item) => ({
|
|
1486
1455
|
item,
|
|
@@ -1488,16 +1457,12 @@ function calculateCartWithCampaigns(items, campaigns) {
|
|
|
1488
1457
|
freeQuantity: 0,
|
|
1489
1458
|
totalQuantity: item.cartQuantity
|
|
1490
1459
|
}));
|
|
1491
|
-
const freeShipping2 = calculateFreeShipping(
|
|
1492
|
-
originalTotal,
|
|
1493
|
-
freeShippingCampaign
|
|
1494
|
-
);
|
|
1495
1460
|
return {
|
|
1496
1461
|
calculatedItems: calculatedItems2,
|
|
1497
1462
|
cartTotal: originalTotal,
|
|
1498
1463
|
originalTotal,
|
|
1499
1464
|
totalSavings: 0,
|
|
1500
|
-
freeShipping
|
|
1465
|
+
freeShipping
|
|
1501
1466
|
};
|
|
1502
1467
|
}
|
|
1503
1468
|
const { buyQuantity, payQuantity, applicableCategories } = buyXPayYCampaign.BuyXPayYCampaign;
|
|
@@ -1528,16 +1493,12 @@ function calculateCartWithCampaigns(items, campaigns) {
|
|
|
1528
1493
|
freeQuantity: 0,
|
|
1529
1494
|
totalQuantity: item.cartQuantity
|
|
1530
1495
|
}));
|
|
1531
|
-
const freeShipping2 = calculateFreeShipping(
|
|
1532
|
-
originalTotal,
|
|
1533
|
-
freeShippingCampaign
|
|
1534
|
-
);
|
|
1535
1496
|
return {
|
|
1536
1497
|
calculatedItems: calculatedItems2,
|
|
1537
1498
|
cartTotal: originalTotal,
|
|
1538
1499
|
originalTotal,
|
|
1539
1500
|
totalSavings: 0,
|
|
1540
|
-
freeShipping
|
|
1501
|
+
freeShipping
|
|
1541
1502
|
};
|
|
1542
1503
|
}
|
|
1543
1504
|
eligibleUnits.sort((a, b) => a.price - b.price);
|
|
@@ -1564,7 +1525,6 @@ function calculateCartWithCampaigns(items, campaigns) {
|
|
|
1564
1525
|
};
|
|
1565
1526
|
});
|
|
1566
1527
|
const cartTotal = originalTotal - totalSavings;
|
|
1567
|
-
const freeShipping = calculateFreeShipping(cartTotal, freeShippingCampaign);
|
|
1568
1528
|
return {
|
|
1569
1529
|
calculatedItems,
|
|
1570
1530
|
cartTotal,
|
|
@@ -1573,28 +1533,6 @@ function calculateCartWithCampaigns(items, campaigns) {
|
|
|
1573
1533
|
freeShipping
|
|
1574
1534
|
};
|
|
1575
1535
|
}
|
|
1576
|
-
function calculateFreeShipping(cartTotal, campaign) {
|
|
1577
|
-
if (!campaign?.FreeShippingCampaign) {
|
|
1578
|
-
return {
|
|
1579
|
-
isEligible: false,
|
|
1580
|
-
minimumSpend: 0,
|
|
1581
|
-
remainingAmount: 0
|
|
1582
|
-
};
|
|
1583
|
-
}
|
|
1584
|
-
const minimumSpend = campaign.FreeShippingCampaign.minimumSpend;
|
|
1585
|
-
const isEligible = cartTotal >= minimumSpend;
|
|
1586
|
-
const remainingAmount = isEligible ? 0 : minimumSpend - cartTotal;
|
|
1587
|
-
const eligibleShipmentMethodIds = campaign.FreeShippingCampaign.shipmentMethods?.map(
|
|
1588
|
-
(method) => method.id
|
|
1589
|
-
);
|
|
1590
|
-
return {
|
|
1591
|
-
isEligible,
|
|
1592
|
-
minimumSpend,
|
|
1593
|
-
remainingAmount,
|
|
1594
|
-
campaignName: campaign.name,
|
|
1595
|
-
eligibleShipmentMethodIds
|
|
1596
|
-
};
|
|
1597
|
-
}
|
|
1598
1536
|
export {
|
|
1599
1537
|
AuthError,
|
|
1600
1538
|
NotFoundError,
|