@betterstore/sdk 0.3.18 → 0.3.19

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,11 @@
1
1
  # @betterstore/sdk
2
2
 
3
+ ## 0.3.19
4
+
5
+ ### Patch Changes
6
+
7
+ - exchange rate external api
8
+
3
9
  ## 0.3.18
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -215,6 +215,13 @@ declare class Customer {
215
215
  delete(customerId: string): Promise<void>;
216
216
  }
217
217
 
218
+ declare class Helpers {
219
+ private apiClient;
220
+ constructor(apiKey: string, proxy?: string);
221
+ formatPrice(priceInCents: number, currency: string, exchangeRate?: number): string;
222
+ getExchangeRate(baseCurrency: string, targetCurrency: string): Promise<number>;
223
+ }
224
+
218
225
  declare class Products {
219
226
  private apiClient;
220
227
  constructor(apiKey: string, proxy?: string);
@@ -229,6 +236,7 @@ declare function betterStore(config: {
229
236
  checkout: Checkout;
230
237
  products: Products;
231
238
  customer: Customer;
239
+ helpers: Helpers;
232
240
  };
233
241
  declare function createStoreClient(config: {
234
242
  proxy?: string;
package/dist/index.d.ts CHANGED
@@ -215,6 +215,13 @@ declare class Customer {
215
215
  delete(customerId: string): Promise<void>;
216
216
  }
217
217
 
218
+ declare class Helpers {
219
+ private apiClient;
220
+ constructor(apiKey: string, proxy?: string);
221
+ formatPrice(priceInCents: number, currency: string, exchangeRate?: number): string;
222
+ getExchangeRate(baseCurrency: string, targetCurrency: string): Promise<number>;
223
+ }
224
+
218
225
  declare class Products {
219
226
  private apiClient;
220
227
  constructor(apiKey: string, proxy?: string);
@@ -229,6 +236,7 @@ declare function betterStore(config: {
229
236
  checkout: Checkout;
230
237
  products: Products;
231
238
  customer: Customer;
239
+ helpers: Helpers;
232
240
  };
233
241
  declare function createStoreClient(config: {
234
242
  proxy?: string;
package/dist/index.js CHANGED
@@ -310,6 +310,38 @@ var Customer = class {
310
310
  };
311
311
  var customer_default = Customer;
312
312
 
313
+ // src/helpers/index.ts
314
+ var import_axios5 = __toESM(require("axios"));
315
+ var Helpers = class {
316
+ constructor(apiKey, proxy) {
317
+ this.apiClient = createApiClient(apiKey, proxy);
318
+ }
319
+ formatPrice(priceInCents, currency, exchangeRate) {
320
+ const amount = priceInCents / 100 * (exchangeRate != null ? exchangeRate : 1);
321
+ const isWhole = amount % 1 === 0;
322
+ const formattedPrice = new Intl.NumberFormat(void 0, {
323
+ style: "currency",
324
+ currency,
325
+ minimumFractionDigits: isWhole ? 0 : 2,
326
+ maximumFractionDigits: isWhole ? 0 : 2
327
+ }).format(amount);
328
+ return formattedPrice;
329
+ }
330
+ getExchangeRate(baseCurrency, targetCurrency) {
331
+ return __async(this, null, function* () {
332
+ const { data } = yield import_axios5.default.get(
333
+ `https://api.exchangerate-api.com/v4/latest/${baseCurrency}`
334
+ );
335
+ const rate = data.rates[targetCurrency];
336
+ if (!rate) {
337
+ throw new Error("Could not get exchange rate for target currency");
338
+ }
339
+ return rate;
340
+ });
341
+ }
342
+ };
343
+ var helpers_default = Helpers;
344
+
313
345
  // src/products/index.ts
314
346
  var Products = class {
315
347
  constructor(apiKey, proxy) {
@@ -352,7 +384,8 @@ function betterStore(config) {
352
384
  return {
353
385
  checkout: new checkout_default(config.apiKey, config.proxy),
354
386
  products: new products_default(config.apiKey, config.proxy),
355
- customer: new customer_default(config.apiKey, config.proxy)
387
+ customer: new customer_default(config.apiKey, config.proxy),
388
+ helpers: new helpers_default(config.apiKey, config.proxy)
356
389
  };
357
390
  }
358
391
  function createStoreClient(config) {
package/dist/index.mjs CHANGED
@@ -272,6 +272,38 @@ var Customer = class {
272
272
  };
273
273
  var customer_default = Customer;
274
274
 
275
+ // src/helpers/index.ts
276
+ import axios2 from "axios";
277
+ var Helpers = class {
278
+ constructor(apiKey, proxy) {
279
+ this.apiClient = createApiClient(apiKey, proxy);
280
+ }
281
+ formatPrice(priceInCents, currency, exchangeRate) {
282
+ const amount = priceInCents / 100 * (exchangeRate != null ? exchangeRate : 1);
283
+ const isWhole = amount % 1 === 0;
284
+ const formattedPrice = new Intl.NumberFormat(void 0, {
285
+ style: "currency",
286
+ currency,
287
+ minimumFractionDigits: isWhole ? 0 : 2,
288
+ maximumFractionDigits: isWhole ? 0 : 2
289
+ }).format(amount);
290
+ return formattedPrice;
291
+ }
292
+ getExchangeRate(baseCurrency, targetCurrency) {
293
+ return __async(this, null, function* () {
294
+ const { data } = yield axios2.get(
295
+ `https://api.exchangerate-api.com/v4/latest/${baseCurrency}`
296
+ );
297
+ const rate = data.rates[targetCurrency];
298
+ if (!rate) {
299
+ throw new Error("Could not get exchange rate for target currency");
300
+ }
301
+ return rate;
302
+ });
303
+ }
304
+ };
305
+ var helpers_default = Helpers;
306
+
275
307
  // src/products/index.ts
276
308
  var Products = class {
277
309
  constructor(apiKey, proxy) {
@@ -314,7 +346,8 @@ function betterStore(config) {
314
346
  return {
315
347
  checkout: new checkout_default(config.apiKey, config.proxy),
316
348
  products: new products_default(config.apiKey, config.proxy),
317
- customer: new customer_default(config.apiKey, config.proxy)
349
+ customer: new customer_default(config.apiKey, config.proxy),
350
+ helpers: new helpers_default(config.apiKey, config.proxy)
318
351
  };
319
352
  }
320
353
  function createStoreClient(config) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betterstore/sdk",
3
- "version": "0.3.18",
3
+ "version": "0.3.19",
4
4
  "description": "E-commerce for Developers",
5
5
  "private": false,
6
6
  "publishConfig": {