@behio/storefront-sdk 0.10.0 → 0.13.0

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.
@@ -123,6 +123,7 @@ var BehioStorefront = class {
123
123
  this.rateLimitReset = null;
124
124
  this.baseUrl = (config.baseUrl || "https://api.behio.com").replace(/\/$/, "");
125
125
  this.apiKey = config.apiKey;
126
+ this.shopDomain = config.shopDomain;
126
127
  this.defaultLocale = config.locale;
127
128
  this.defaultCurrency = config.currency;
128
129
  this.fetchFn = config.fetch || globalThis.fetch.bind(globalThis);
@@ -185,6 +186,28 @@ var BehioStorefront = class {
185
186
  clearCartSession() {
186
187
  this.cartSession = void 0;
187
188
  }
189
+ // --- Default currency / locale (runtime-switchable) ---
190
+ /**
191
+ * Set the default currency sent on every catalog request (unless a per-call
192
+ * `currency` overrides it). Read live at request time, so changing it takes
193
+ * effect immediately without rebuilding the client. Pass undefined to clear
194
+ * (falls back to the shop's default currency server-side).
195
+ */
196
+ setCurrency(currency) {
197
+ this.defaultCurrency = currency || void 0;
198
+ }
199
+ /** Get the current default currency, if any. */
200
+ getCurrency() {
201
+ return this.defaultCurrency;
202
+ }
203
+ /** Set the default locale sent on every catalog request (per-call wins). */
204
+ setLocale(locale) {
205
+ this.defaultLocale = locale || void 0;
206
+ }
207
+ /** Get the current default locale, if any. */
208
+ getLocale() {
209
+ return this.defaultLocale;
210
+ }
188
211
  // --- Event emitter ---
189
212
  /** Subscribe to SDK events. Returns an unsubscribe function. */
190
213
  on(event, handler) {
@@ -301,6 +324,9 @@ var BehioStorefront = class {
301
324
  "X-Api-Key": this.apiKey,
302
325
  "Content-Type": "application/json"
303
326
  };
327
+ if (this.shopDomain) {
328
+ headers["X-Shop-Domain"] = this.shopDomain;
329
+ }
304
330
  if (this.accessToken && _optionalChain([options, 'optionalAccess', _13 => _13.auth]) !== false) {
305
331
  headers["Authorization"] = `Bearer ${this.accessToken}`;
306
332
  }
@@ -123,6 +123,7 @@ var BehioStorefront = class {
123
123
  this.rateLimitReset = null;
124
124
  this.baseUrl = (config.baseUrl || "https://api.behio.com").replace(/\/$/, "");
125
125
  this.apiKey = config.apiKey;
126
+ this.shopDomain = config.shopDomain;
126
127
  this.defaultLocale = config.locale;
127
128
  this.defaultCurrency = config.currency;
128
129
  this.fetchFn = config.fetch || globalThis.fetch.bind(globalThis);
@@ -185,6 +186,28 @@ var BehioStorefront = class {
185
186
  clearCartSession() {
186
187
  this.cartSession = void 0;
187
188
  }
189
+ // --- Default currency / locale (runtime-switchable) ---
190
+ /**
191
+ * Set the default currency sent on every catalog request (unless a per-call
192
+ * `currency` overrides it). Read live at request time, so changing it takes
193
+ * effect immediately without rebuilding the client. Pass undefined to clear
194
+ * (falls back to the shop's default currency server-side).
195
+ */
196
+ setCurrency(currency) {
197
+ this.defaultCurrency = currency || void 0;
198
+ }
199
+ /** Get the current default currency, if any. */
200
+ getCurrency() {
201
+ return this.defaultCurrency;
202
+ }
203
+ /** Set the default locale sent on every catalog request (per-call wins). */
204
+ setLocale(locale) {
205
+ this.defaultLocale = locale || void 0;
206
+ }
207
+ /** Get the current default locale, if any. */
208
+ getLocale() {
209
+ return this.defaultLocale;
210
+ }
188
211
  // --- Event emitter ---
189
212
  /** Subscribe to SDK events. Returns an unsubscribe function. */
190
213
  on(event, handler) {
@@ -301,6 +324,9 @@ var BehioStorefront = class {
301
324
  "X-Api-Key": this.apiKey,
302
325
  "Content-Type": "application/json"
303
326
  };
327
+ if (this.shopDomain) {
328
+ headers["X-Shop-Domain"] = this.shopDomain;
329
+ }
304
330
  if (this.accessToken && options?.auth !== false) {
305
331
  headers["Authorization"] = `Bearer ${this.accessToken}`;
306
332
  }
@@ -0,0 +1,18 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/react/utils/format-price.ts
2
+ function formatPrice(amount, currency, locale) {
3
+ const resolvedLocale = _nullishCoalesce(locale, () => ( "cs"));
4
+ try {
5
+ return new Intl.NumberFormat(resolvedLocale, {
6
+ style: "currency",
7
+ currency,
8
+ minimumFractionDigits: Number.isInteger(amount) ? 0 : 2,
9
+ maximumFractionDigits: 2
10
+ }).format(amount);
11
+ } catch (e) {
12
+ return `${amount} ${currency}`;
13
+ }
14
+ }
15
+
16
+
17
+
18
+ exports.formatPrice = formatPrice;
@@ -0,0 +1,18 @@
1
+ // src/react/utils/format-price.ts
2
+ function formatPrice(amount, currency, locale) {
3
+ const resolvedLocale = locale ?? "cs";
4
+ try {
5
+ return new Intl.NumberFormat(resolvedLocale, {
6
+ style: "currency",
7
+ currency,
8
+ minimumFractionDigits: Number.isInteger(amount) ? 0 : 2,
9
+ maximumFractionDigits: 2
10
+ }).format(amount);
11
+ } catch {
12
+ return `${amount} ${currency}`;
13
+ }
14
+ }
15
+
16
+ export {
17
+ formatPrice
18
+ };