@behio/storefront-sdk 0.10.0 → 0.12.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
  }
package/dist/index.d.mts CHANGED
@@ -3,6 +3,14 @@ interface BehioStorefrontConfig {
3
3
  apiKey: string;
4
4
  /** Backend base URL. Default: https://api.behio.com */
5
5
  baseUrl?: string;
6
+ /**
7
+ * The domain this storefront is served on (e.g. "mujshop.cz"), sent as
8
+ * X-Shop-Domain. Only needed when ONE deployment serves several domains with
9
+ * a single "all domains" API key (e.g. a Vercel app behind mujshop.cz +
10
+ * mujshop.sk) AND there's no Origin header (server-side rendering). A
11
+ * domain-bound key, or a browser request (Origin), doesn't need it.
12
+ */
13
+ shopDomain?: string;
6
14
  /** Default locale for catalog requests. Default: none (uses shop default) */
7
15
  locale?: string;
8
16
  /** Default currency for price resolution. Default: none (uses shop default) */
@@ -886,6 +894,7 @@ interface SubmitQuoteInput {
886
894
  declare class BehioStorefront {
887
895
  private baseUrl;
888
896
  private apiKey;
897
+ private shopDomain?;
889
898
  private defaultLocale?;
890
899
  private defaultCurrency?;
891
900
  private fetchFn;
@@ -938,6 +947,19 @@ declare class BehioStorefront {
938
947
  getCartSession(): string | undefined;
939
948
  /** Clear cart session */
940
949
  clearCartSession(): void;
950
+ /**
951
+ * Set the default currency sent on every catalog request (unless a per-call
952
+ * `currency` overrides it). Read live at request time, so changing it takes
953
+ * effect immediately without rebuilding the client. Pass undefined to clear
954
+ * (falls back to the shop's default currency server-side).
955
+ */
956
+ setCurrency(currency: string | undefined): void;
957
+ /** Get the current default currency, if any. */
958
+ getCurrency(): string | undefined;
959
+ /** Set the default locale sent on every catalog request (per-call wins). */
960
+ setLocale(locale: string | undefined): void;
961
+ /** Get the current default locale, if any. */
962
+ getLocale(): string | undefined;
941
963
  /** Subscribe to SDK events. Returns an unsubscribe function. */
942
964
  on(event: BehioEventType, handler: BehioEventHandler): () => void;
943
965
  /** @internal Emit an event (fire-and-forget, handler errors are swallowed) */
package/dist/index.d.ts CHANGED
@@ -3,6 +3,14 @@ interface BehioStorefrontConfig {
3
3
  apiKey: string;
4
4
  /** Backend base URL. Default: https://api.behio.com */
5
5
  baseUrl?: string;
6
+ /**
7
+ * The domain this storefront is served on (e.g. "mujshop.cz"), sent as
8
+ * X-Shop-Domain. Only needed when ONE deployment serves several domains with
9
+ * a single "all domains" API key (e.g. a Vercel app behind mujshop.cz +
10
+ * mujshop.sk) AND there's no Origin header (server-side rendering). A
11
+ * domain-bound key, or a browser request (Origin), doesn't need it.
12
+ */
13
+ shopDomain?: string;
6
14
  /** Default locale for catalog requests. Default: none (uses shop default) */
7
15
  locale?: string;
8
16
  /** Default currency for price resolution. Default: none (uses shop default) */
@@ -886,6 +894,7 @@ interface SubmitQuoteInput {
886
894
  declare class BehioStorefront {
887
895
  private baseUrl;
888
896
  private apiKey;
897
+ private shopDomain?;
889
898
  private defaultLocale?;
890
899
  private defaultCurrency?;
891
900
  private fetchFn;
@@ -938,6 +947,19 @@ declare class BehioStorefront {
938
947
  getCartSession(): string | undefined;
939
948
  /** Clear cart session */
940
949
  clearCartSession(): void;
950
+ /**
951
+ * Set the default currency sent on every catalog request (unless a per-call
952
+ * `currency` overrides it). Read live at request time, so changing it takes
953
+ * effect immediately without rebuilding the client. Pass undefined to clear
954
+ * (falls back to the shop's default currency server-side).
955
+ */
956
+ setCurrency(currency: string | undefined): void;
957
+ /** Get the current default currency, if any. */
958
+ getCurrency(): string | undefined;
959
+ /** Set the default locale sent on every catalog request (per-call wins). */
960
+ setLocale(locale: string | undefined): void;
961
+ /** Get the current default locale, if any. */
962
+ getLocale(): string | undefined;
941
963
  /** Subscribe to SDK events. Returns an unsubscribe function. */
942
964
  on(event: BehioEventType, handler: BehioEventHandler): () => void;
943
965
  /** @internal Emit an event (fire-and-forget, handler errors are swallowed) */
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
 
13
- var _chunkLNSFBNPJjs = require('./chunk-LNSFBNPJ.js');
13
+ var _chunkGGUHYQNFjs = require('./chunk-GGUHYQNF.js');
14
14
 
15
15
 
16
16
 
@@ -23,4 +23,4 @@ var _chunkLNSFBNPJjs = require('./chunk-LNSFBNPJ.js');
23
23
 
24
24
 
25
25
 
26
- exports.AddressTypes = _chunkLNSFBNPJjs.AddressTypes; exports.BehioApiError = _chunkLNSFBNPJjs.BehioApiError; exports.BehioNetworkError = _chunkLNSFBNPJjs.BehioNetworkError; exports.BehioStorefront = _chunkLNSFBNPJjs.BehioStorefront; exports.FulfillmentStatuses = _chunkLNSFBNPJjs.FulfillmentStatuses; exports.OrderStatuses = _chunkLNSFBNPJjs.OrderStatuses; exports.PaymentStatuses = _chunkLNSFBNPJjs.PaymentStatuses; exports.ProductSort = _chunkLNSFBNPJjs.ProductSort; exports.err = _chunkLNSFBNPJjs.err; exports.ok = _chunkLNSFBNPJjs.ok; exports.toSdkError = _chunkLNSFBNPJjs.toSdkError;
26
+ exports.AddressTypes = _chunkGGUHYQNFjs.AddressTypes; exports.BehioApiError = _chunkGGUHYQNFjs.BehioApiError; exports.BehioNetworkError = _chunkGGUHYQNFjs.BehioNetworkError; exports.BehioStorefront = _chunkGGUHYQNFjs.BehioStorefront; exports.FulfillmentStatuses = _chunkGGUHYQNFjs.FulfillmentStatuses; exports.OrderStatuses = _chunkGGUHYQNFjs.OrderStatuses; exports.PaymentStatuses = _chunkGGUHYQNFjs.PaymentStatuses; exports.ProductSort = _chunkGGUHYQNFjs.ProductSort; exports.err = _chunkGGUHYQNFjs.err; exports.ok = _chunkGGUHYQNFjs.ok; exports.toSdkError = _chunkGGUHYQNFjs.toSdkError;
package/dist/index.mjs CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  err,
11
11
  ok,
12
12
  toSdkError
13
- } from "./chunk-O3IM7PAY.mjs";
13
+ } from "./chunk-XITY2WQN.mjs";
14
14
  export {
15
15
  AddressTypes,
16
16
  BehioApiError,
package/dist/next.d.mts CHANGED
@@ -3,6 +3,8 @@ import { BehioStorefrontConfig, BehioStorefront } from './index.mjs';
3
3
  interface GetBehioOptions extends Partial<BehioStorefrontConfig> {
4
4
  /** Override the cart session cookie name (default: "behio_cart_session"). */
5
5
  cartCookieName?: string;
6
+ /** Override the currency cookie name (default: "behio_currency"). */
7
+ currencyCookieName?: string;
6
8
  }
7
9
  /**
8
10
  * Returns a per-request bound BehioStorefront instance. Reads the cart
package/dist/next.d.ts CHANGED
@@ -3,6 +3,8 @@ import { BehioStorefrontConfig, BehioStorefront } from './index.js';
3
3
  interface GetBehioOptions extends Partial<BehioStorefrontConfig> {
4
4
  /** Override the cart session cookie name (default: "behio_cart_session"). */
5
5
  cartCookieName?: string;
6
+ /** Override the currency cookie name (default: "behio_currency"). */
7
+ currencyCookieName?: string;
6
8
  }
7
9
  /**
8
10
  * Returns a per-request bound BehioStorefront instance. Reads the cart
package/dist/next.js CHANGED
@@ -1,10 +1,11 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkLNSFBNPJjs = require('./chunk-LNSFBNPJ.js');
3
+ var _chunkGGUHYQNFjs = require('./chunk-GGUHYQNF.js');
4
4
 
5
5
  // src/next.ts
6
6
  var _headers = require('next/headers');
7
7
  var CART_COOKIE_NAME = "behio_cart_session";
8
+ var CURRENCY_COOKIE_NAME = "behio_currency";
8
9
  var CART_COOKIE_MAX_AGE = 60 * 60 * 24 * 30;
9
10
  async function getBehio(options = {}) {
10
11
  const apiKey = _nullishCoalesce(options.apiKey, () => ( process.env.BEHIO_API_KEY));
@@ -17,7 +18,7 @@ async function getBehio(options = {}) {
17
18
  const locale = _nullishCoalesce(options.locale, () => ( process.env.BEHIO_LOCALE));
18
19
  const currency = _nullishCoalesce(options.currency, () => ( process.env.BEHIO_CURRENCY));
19
20
  const cookieName = _nullishCoalesce(options.cartCookieName, () => ( CART_COOKIE_NAME));
20
- const client = new (0, _chunkLNSFBNPJjs.BehioStorefront)({
21
+ const client = new (0, _chunkGGUHYQNFjs.BehioStorefront)({
21
22
  apiKey,
22
23
  ...baseUrl ? { baseUrl } : {},
23
24
  ...locale ? { locale } : {},
@@ -29,6 +30,13 @@ async function getBehio(options = {}) {
29
30
  if (existing) {
30
31
  client.setCartSession(existing);
31
32
  }
33
+ if (!currency) {
34
+ const currencyCookieName = _nullishCoalesce(options.currencyCookieName, () => ( CURRENCY_COOKIE_NAME));
35
+ const chosenCurrency = _optionalChain([cookieStore, 'access', _4 => _4.get, 'call', _5 => _5(currencyCookieName), 'optionalAccess', _6 => _6.value]);
36
+ if (chosenCurrency) {
37
+ client.setCurrency(chosenCurrency);
38
+ }
39
+ }
32
40
  const originalSet = client.setCartSession.bind(client);
33
41
  const originalClear = client.clearCartSession.bind(client);
34
42
  client.setCartSession = (token) => {
package/dist/next.mjs CHANGED
@@ -1,10 +1,11 @@
1
1
  import {
2
2
  BehioStorefront
3
- } from "./chunk-O3IM7PAY.mjs";
3
+ } from "./chunk-XITY2WQN.mjs";
4
4
 
5
5
  // src/next.ts
6
6
  import { cookies } from "next/headers";
7
7
  var CART_COOKIE_NAME = "behio_cart_session";
8
+ var CURRENCY_COOKIE_NAME = "behio_currency";
8
9
  var CART_COOKIE_MAX_AGE = 60 * 60 * 24 * 30;
9
10
  async function getBehio(options = {}) {
10
11
  const apiKey = options.apiKey ?? process.env.BEHIO_API_KEY;
@@ -29,6 +30,13 @@ async function getBehio(options = {}) {
29
30
  if (existing) {
30
31
  client.setCartSession(existing);
31
32
  }
33
+ if (!currency) {
34
+ const currencyCookieName = options.currencyCookieName ?? CURRENCY_COOKIE_NAME;
35
+ const chosenCurrency = cookieStore.get(currencyCookieName)?.value;
36
+ if (chosenCurrency) {
37
+ client.setCurrency(chosenCurrency);
38
+ }
39
+ }
32
40
  const originalSet = client.setCartSession.bind(client);
33
41
  const originalClear = client.clearCartSession.bind(client);
34
42
  client.setCartSession = (token) => {