@betterstore/sdk 0.3.18 → 0.3.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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +38 -1
- package/dist/index.mjs +36 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
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
|
+
proxy?: string;
|
|
220
|
+
constructor(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);
|
|
@@ -233,5 +240,8 @@ declare function betterStore(config: {
|
|
|
233
240
|
declare function createStoreClient(config: {
|
|
234
241
|
proxy?: string;
|
|
235
242
|
}): Client;
|
|
243
|
+
declare function createStoreHelpers(config: {
|
|
244
|
+
proxy?: string;
|
|
245
|
+
}): Helpers;
|
|
236
246
|
|
|
237
|
-
export { type Address, type CheckoutCreateParams, type CheckoutSession, type CheckoutUpdateParams, type Currency, type Customer$1 as Customer, type CustomerCreateParams, type CustomerUpdateParams, type LineItem, type Product, type ProductOption, ProductStatus, type ProductVariant, type VariantOption, createStoreClient, betterStore as default };
|
|
247
|
+
export { type Address, type CheckoutCreateParams, type CheckoutSession, type CheckoutUpdateParams, type Currency, type Customer$1 as Customer, type CustomerCreateParams, type CustomerUpdateParams, type LineItem, type Product, type ProductOption, ProductStatus, type ProductVariant, type VariantOption, createStoreClient, createStoreHelpers, betterStore as default };
|
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
|
+
proxy?: string;
|
|
220
|
+
constructor(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);
|
|
@@ -233,5 +240,8 @@ declare function betterStore(config: {
|
|
|
233
240
|
declare function createStoreClient(config: {
|
|
234
241
|
proxy?: string;
|
|
235
242
|
}): Client;
|
|
243
|
+
declare function createStoreHelpers(config: {
|
|
244
|
+
proxy?: string;
|
|
245
|
+
}): Helpers;
|
|
236
246
|
|
|
237
|
-
export { type Address, type CheckoutCreateParams, type CheckoutSession, type CheckoutUpdateParams, type Currency, type Customer$1 as Customer, type CustomerCreateParams, type CustomerUpdateParams, type LineItem, type Product, type ProductOption, ProductStatus, type ProductVariant, type VariantOption, createStoreClient, betterStore as default };
|
|
247
|
+
export { type Address, type CheckoutCreateParams, type CheckoutSession, type CheckoutUpdateParams, type Currency, type Customer$1 as Customer, type CustomerCreateParams, type CustomerUpdateParams, type LineItem, type Product, type ProductOption, ProductStatus, type ProductVariant, type VariantOption, createStoreClient, createStoreHelpers, betterStore as default };
|
package/dist/index.js
CHANGED
|
@@ -53,6 +53,7 @@ __export(index_exports, {
|
|
|
53
53
|
ProductStatus: () => ProductStatus,
|
|
54
54
|
ShippingRate: () => import_shippo.Rate,
|
|
55
55
|
createStoreClient: () => createStoreClient,
|
|
56
|
+
createStoreHelpers: () => createStoreHelpers,
|
|
56
57
|
default: () => betterStore
|
|
57
58
|
});
|
|
58
59
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -310,6 +311,38 @@ var Customer = class {
|
|
|
310
311
|
};
|
|
311
312
|
var customer_default = Customer;
|
|
312
313
|
|
|
314
|
+
// src/helpers/index.ts
|
|
315
|
+
var import_axios5 = __toESM(require("axios"));
|
|
316
|
+
var Helpers = class {
|
|
317
|
+
constructor(proxy) {
|
|
318
|
+
this.proxy = proxy;
|
|
319
|
+
}
|
|
320
|
+
formatPrice(priceInCents, currency, exchangeRate) {
|
|
321
|
+
const amount = priceInCents / 100 * (exchangeRate != null ? exchangeRate : 1);
|
|
322
|
+
const isWhole = amount % 1 === 0;
|
|
323
|
+
const formattedPrice = new Intl.NumberFormat(void 0, {
|
|
324
|
+
style: "currency",
|
|
325
|
+
currency,
|
|
326
|
+
minimumFractionDigits: isWhole ? 0 : 2,
|
|
327
|
+
maximumFractionDigits: isWhole ? 0 : 2
|
|
328
|
+
}).format(amount);
|
|
329
|
+
return formattedPrice;
|
|
330
|
+
}
|
|
331
|
+
getExchangeRate(baseCurrency, targetCurrency) {
|
|
332
|
+
return __async(this, null, function* () {
|
|
333
|
+
const { data } = yield import_axios5.default.get(
|
|
334
|
+
`https://api.exchangerate-api.com/v4/latest/${baseCurrency}`
|
|
335
|
+
);
|
|
336
|
+
const rate = data.rates[targetCurrency];
|
|
337
|
+
if (!rate) {
|
|
338
|
+
throw new Error("Could not get exchange rate for target currency");
|
|
339
|
+
}
|
|
340
|
+
return rate;
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
var helpers_default = Helpers;
|
|
345
|
+
|
|
313
346
|
// src/products/index.ts
|
|
314
347
|
var Products = class {
|
|
315
348
|
constructor(apiKey, proxy) {
|
|
@@ -358,9 +391,13 @@ function betterStore(config) {
|
|
|
358
391
|
function createStoreClient(config) {
|
|
359
392
|
return new client_default(config.proxy);
|
|
360
393
|
}
|
|
394
|
+
function createStoreHelpers(config) {
|
|
395
|
+
return new helpers_default(config.proxy);
|
|
396
|
+
}
|
|
361
397
|
// Annotate the CommonJS export names for ESM import in node:
|
|
362
398
|
0 && (module.exports = {
|
|
363
399
|
ProductStatus,
|
|
364
400
|
ShippingRate,
|
|
365
|
-
createStoreClient
|
|
401
|
+
createStoreClient,
|
|
402
|
+
createStoreHelpers
|
|
366
403
|
});
|
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(proxy) {
|
|
279
|
+
this.proxy = 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) {
|
|
@@ -320,9 +352,13 @@ function betterStore(config) {
|
|
|
320
352
|
function createStoreClient(config) {
|
|
321
353
|
return new client_default(config.proxy);
|
|
322
354
|
}
|
|
355
|
+
function createStoreHelpers(config) {
|
|
356
|
+
return new helpers_default(config.proxy);
|
|
357
|
+
}
|
|
323
358
|
export {
|
|
324
359
|
ProductStatus,
|
|
325
360
|
Rate as ShippingRate,
|
|
326
361
|
createStoreClient,
|
|
362
|
+
createStoreHelpers,
|
|
327
363
|
betterStore as default
|
|
328
364
|
};
|