@betterstore/sdk 0.3.22 → 0.3.24

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @betterstore/sdk
2
2
 
3
+ ## 0.3.24
4
+
5
+ ### Patch Changes
6
+
7
+ - exchange rates different calculation steps
8
+
9
+ ## 0.3.23
10
+
11
+ ### Patch Changes
12
+
13
+ - currency formatting
14
+
3
15
  ## 0.3.22
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -312,17 +312,83 @@ var Customer = class {
312
312
  var customer_default = Customer;
313
313
 
314
314
  // src/helpers/index.ts
315
- var import_axios5 = __toESM(require("axios"));
316
315
  var Helpers = class {
317
316
  constructor(proxy) {
318
317
  this.proxy = proxy;
319
318
  }
320
319
  formatPrice(priceInCents, currency, exchangeRate) {
320
+ var _a;
321
321
  const amount = priceInCents / 100 * (exchangeRate != null ? exchangeRate : 1);
322
322
  const isWhole = amount % 1 === 0;
323
- const formattedPrice = new Intl.NumberFormat(void 0, {
323
+ const currencyLocales = {
324
+ CZK: "cs-CZ",
325
+ // Czech Koruna
326
+ USD: "en-US",
327
+ // US Dollar
328
+ EUR: "de-DE",
329
+ // Euro (Germany locale)
330
+ GBP: "en-GB",
331
+ // British Pound
332
+ JPY: "ja-JP",
333
+ // Japanese Yen
334
+ AUD: "en-AU",
335
+ // Australian Dollar
336
+ CAD: "en-CA",
337
+ // Canadian Dollar
338
+ NZD: "en-NZ",
339
+ // New Zealand Dollar
340
+ SEK: "sv-SE",
341
+ // Swedish Krona
342
+ NOK: "nb-NO",
343
+ // Norwegian Krone
344
+ DKK: "da-DK",
345
+ // Danish Krone
346
+ CHF: "de-CH",
347
+ // Swiss Franc (German Switzerland)
348
+ HUF: "hu-HU",
349
+ // Hungarian Forint
350
+ PLN: "pl-PL",
351
+ // Polish Zloty
352
+ BGN: "bg-BG",
353
+ // Bulgarian Lev
354
+ RON: "ro-RO",
355
+ // Romanian Leu
356
+ RUB: "ru-RU",
357
+ // Russian Ruble
358
+ CNY: "zh-CN",
359
+ // Chinese Yuan
360
+ INR: "en-IN",
361
+ // Indian Rupee
362
+ BRL: "pt-BR",
363
+ // Brazilian Real
364
+ MXN: "es-MX",
365
+ // Mexican Peso
366
+ ZAR: "en-ZA",
367
+ // South African Rand
368
+ KRW: "ko-KR",
369
+ // South Korean Won
370
+ MYR: "ms-MY",
371
+ // Malaysian Ringgit
372
+ SGD: "en-SG",
373
+ // Singapore Dollar
374
+ TWD: "zh-TW",
375
+ // Taiwanese Dollar
376
+ THB: "th-TH",
377
+ // Thai Baht
378
+ IDR: "id-ID",
379
+ // Indonesian Rupiah
380
+ AED: "ar-AE",
381
+ // UAE Dirham
382
+ SAR: "ar-SA",
383
+ // Saudi Riyal
384
+ TRY: "tr-TR"
385
+ // Turkish Lira
386
+ };
387
+ const locale = (_a = currencyLocales[currency]) != null ? _a : void 0;
388
+ const formattedPrice = new Intl.NumberFormat(locale, {
324
389
  style: "currency",
325
390
  currency,
391
+ currencyDisplay: "symbol",
326
392
  minimumFractionDigits: isWhole ? 0 : 2,
327
393
  maximumFractionDigits: isWhole ? 0 : 2
328
394
  }).format(amount);
@@ -330,9 +396,8 @@ var Helpers = class {
330
396
  }
331
397
  getExchangeRate(baseCurrency, targetCurrency) {
332
398
  return __async(this, null, function* () {
333
- const { data } = yield import_axios5.default.get(
334
- `https://api.exchangerate-api.com/v4/latest/${baseCurrency}`
335
- );
399
+ const apiClient = createApiClient("", this.proxy);
400
+ const { data } = yield apiClient.get(`/helpers/rates/${baseCurrency}`);
336
401
  const rate = data.rates[targetCurrency];
337
402
  if (!rate) {
338
403
  throw new Error("Could not get exchange rate for target currency");
package/dist/index.mjs CHANGED
@@ -273,17 +273,83 @@ var Customer = class {
273
273
  var customer_default = Customer;
274
274
 
275
275
  // src/helpers/index.ts
276
- import axios2 from "axios";
277
276
  var Helpers = class {
278
277
  constructor(proxy) {
279
278
  this.proxy = proxy;
280
279
  }
281
280
  formatPrice(priceInCents, currency, exchangeRate) {
281
+ var _a;
282
282
  const amount = priceInCents / 100 * (exchangeRate != null ? exchangeRate : 1);
283
283
  const isWhole = amount % 1 === 0;
284
- const formattedPrice = new Intl.NumberFormat(void 0, {
284
+ const currencyLocales = {
285
+ CZK: "cs-CZ",
286
+ // Czech Koruna
287
+ USD: "en-US",
288
+ // US Dollar
289
+ EUR: "de-DE",
290
+ // Euro (Germany locale)
291
+ GBP: "en-GB",
292
+ // British Pound
293
+ JPY: "ja-JP",
294
+ // Japanese Yen
295
+ AUD: "en-AU",
296
+ // Australian Dollar
297
+ CAD: "en-CA",
298
+ // Canadian Dollar
299
+ NZD: "en-NZ",
300
+ // New Zealand Dollar
301
+ SEK: "sv-SE",
302
+ // Swedish Krona
303
+ NOK: "nb-NO",
304
+ // Norwegian Krone
305
+ DKK: "da-DK",
306
+ // Danish Krone
307
+ CHF: "de-CH",
308
+ // Swiss Franc (German Switzerland)
309
+ HUF: "hu-HU",
310
+ // Hungarian Forint
311
+ PLN: "pl-PL",
312
+ // Polish Zloty
313
+ BGN: "bg-BG",
314
+ // Bulgarian Lev
315
+ RON: "ro-RO",
316
+ // Romanian Leu
317
+ RUB: "ru-RU",
318
+ // Russian Ruble
319
+ CNY: "zh-CN",
320
+ // Chinese Yuan
321
+ INR: "en-IN",
322
+ // Indian Rupee
323
+ BRL: "pt-BR",
324
+ // Brazilian Real
325
+ MXN: "es-MX",
326
+ // Mexican Peso
327
+ ZAR: "en-ZA",
328
+ // South African Rand
329
+ KRW: "ko-KR",
330
+ // South Korean Won
331
+ MYR: "ms-MY",
332
+ // Malaysian Ringgit
333
+ SGD: "en-SG",
334
+ // Singapore Dollar
335
+ TWD: "zh-TW",
336
+ // Taiwanese Dollar
337
+ THB: "th-TH",
338
+ // Thai Baht
339
+ IDR: "id-ID",
340
+ // Indonesian Rupiah
341
+ AED: "ar-AE",
342
+ // UAE Dirham
343
+ SAR: "ar-SA",
344
+ // Saudi Riyal
345
+ TRY: "tr-TR"
346
+ // Turkish Lira
347
+ };
348
+ const locale = (_a = currencyLocales[currency]) != null ? _a : void 0;
349
+ const formattedPrice = new Intl.NumberFormat(locale, {
285
350
  style: "currency",
286
351
  currency,
352
+ currencyDisplay: "symbol",
287
353
  minimumFractionDigits: isWhole ? 0 : 2,
288
354
  maximumFractionDigits: isWhole ? 0 : 2
289
355
  }).format(amount);
@@ -291,9 +357,8 @@ var Helpers = class {
291
357
  }
292
358
  getExchangeRate(baseCurrency, targetCurrency) {
293
359
  return __async(this, null, function* () {
294
- const { data } = yield axios2.get(
295
- `https://api.exchangerate-api.com/v4/latest/${baseCurrency}`
296
- );
360
+ const apiClient = createApiClient("", this.proxy);
361
+ const { data } = yield apiClient.get(`/helpers/rates/${baseCurrency}`);
297
362
  const rate = data.rates[targetCurrency];
298
363
  if (!rate) {
299
364
  throw new Error("Could not get exchange rate for target currency");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betterstore/sdk",
3
- "version": "0.3.22",
3
+ "version": "0.3.24",
4
4
  "description": "E-commerce for Developers",
5
5
  "private": false,
6
6
  "publishConfig": {