arky-sdk 0.4.16 → 0.4.20

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/README.md CHANGED
@@ -69,9 +69,8 @@ const { items: products } = await arky.eshop.getProducts({
69
69
  // Get product details (like arky.io/products/guitar)
70
70
  const product = await arky.eshop.getProduct({ id: 'prod_123' });
71
71
 
72
- // Get price for user's market
73
- const price = arky.utils.getMarketPrice(product.variants[0].prices, 'US');
74
- console.log(`${arky.utils.formatMinor(price.amount, price.currency)}`); // "$29.99"
72
+ // Format price (uses currency from price object)
73
+ const formatted = arky.utils.formatPrice(product.variants[0].prices); // "$29.99"
75
74
  ```
76
75
 
77
76
  ### 3. Shop & Checkout
@@ -308,8 +307,8 @@ const forSubmit = arky.utils.prepareBlocksForSubmission(blocks)
308
307
  const formatted = arky.utils.formatMinor(999, 'usd') // "$9.99"
309
308
  const payment = arky.utils.formatPayment(paymentObject)
310
309
 
311
- // Get market prices
312
- const price = arky.utils.getMarketPrice(prices, 'US', markets)
310
+ // Format prices from array
311
+ const formatted = arky.utils.formatPrice(prices) // "$9.99"
313
312
  const amount = arky.utils.getPriceAmount(prices, 'US')
314
313
 
315
314
  // Currency
package/dist/index.cjs CHANGED
@@ -1497,39 +1497,27 @@ function formatPayment(payment, options = {}) {
1497
1497
  }
1498
1498
  return formatMinor(payment.total, payment.currency, { showSymbols, decimalPlaces });
1499
1499
  }
1500
- function getMarketPrice(prices, marketId, businessMarkets, options = {}) {
1500
+ function formatPrice(prices, options = {}) {
1501
1501
  if (!prices || prices.length === 0) return "";
1502
1502
  const {
1503
1503
  showSymbols = true,
1504
1504
  decimalPlaces = 2,
1505
1505
  showCompareAt = true,
1506
- fallbackMarket
1506
+ marketId
1507
1507
  } = options;
1508
- let price = prices.find((p) => p.market === marketId);
1509
- if (!price && fallbackMarket) {
1510
- price = prices.find((p) => p.market === fallbackMarket);
1511
- }
1508
+ let price = marketId ? prices.find((p) => p.market === marketId) : void 0;
1512
1509
  if (!price) {
1513
1510
  price = prices[0];
1514
1511
  }
1515
- if (!price) return "";
1516
- let currency;
1517
- let symbol;
1518
- if (businessMarkets) {
1519
- const marketData = businessMarkets.find((m) => m.id === price.market || m.code === price.market);
1520
- if (marketData?.currency) {
1521
- currency = marketData.currency;
1522
- symbol = getCurrencySymbol(currency);
1523
- }
1524
- }
1525
- if (!currency) return "";
1526
- const formattedPrice = formatMinor(price.amount ?? 0, currency, {
1512
+ if (!price || !price.currency) return "";
1513
+ const symbol = getCurrencySymbol(price.currency);
1514
+ const formattedPrice = formatMinor(price.amount ?? 0, price.currency, {
1527
1515
  showSymbols,
1528
1516
  decimalPlaces,
1529
1517
  customSymbol: symbol
1530
1518
  });
1531
1519
  if (showCompareAt && price.compareAt && price.compareAt > (price.amount ?? 0)) {
1532
- const formattedCompareAt = formatMinor(price.compareAt, currency, {
1520
+ const formattedCompareAt = formatMinor(price.compareAt, price.currency, {
1533
1521
  showSymbols,
1534
1522
  decimalPlaces,
1535
1523
  customSymbol: symbol
@@ -1763,7 +1751,7 @@ function track(eventName, params) {
1763
1751
  }
1764
1752
 
1765
1753
  // src/index.ts
1766
- var SDK_VERSION = "0.4.16";
1754
+ var SDK_VERSION = "0.4.20";
1767
1755
  var SUPPORTED_FRAMEWORKS = [
1768
1756
  "astro",
1769
1757
  "react",
@@ -1848,8 +1836,8 @@ async function createArkySDK(config) {
1848
1836
  formatBlockValue,
1849
1837
  prepareBlocksForSubmission,
1850
1838
  extractBlockValues,
1851
- getMarketPrice,
1852
- getPriceAmount,
1839
+ formatPrice: (prices, options = {}) => formatPrice(prices, { ...options, marketId: apiConfig.market }),
1840
+ getPriceAmount: (prices, fallbackMarket) => getPriceAmount(prices, apiConfig.market, fallbackMarket),
1853
1841
  formatPayment,
1854
1842
  formatMinor,
1855
1843
  createPaymentForCheckout,