@behio/storefront-sdk 0.1.0 → 0.1.1

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.
@@ -91,7 +91,7 @@ var BehioStorefront = class {
91
91
  this.apiKey = config.apiKey;
92
92
  this.defaultLocale = config.locale;
93
93
  this.defaultCurrency = config.currency;
94
- this.fetchFn = config.fetch || globalThis.fetch;
94
+ this.fetchFn = config.fetch || globalThis.fetch.bind(globalThis);
95
95
  this.timeout = config.timeout ?? 3e4;
96
96
  this.retries = config.retries ?? 1;
97
97
  this.retryDelay = config.retryDelay ?? 1e3;
@@ -201,20 +201,22 @@ var BehioStorefront = class {
201
201
  // --- Internal fetch ---
202
202
  /** @internal */
203
203
  async request(method, path, options) {
204
- const url = new URL(`${this.baseUrl}/storefront/v1${path}`);
204
+ const params = new URLSearchParams();
205
205
  if (options?.query) {
206
206
  for (const [key, value] of Object.entries(options.query)) {
207
207
  if (value !== void 0 && value !== null && value !== "") {
208
- url.searchParams.set(key, String(value));
208
+ params.set(key, String(value));
209
209
  }
210
210
  }
211
211
  }
212
- if (this.defaultLocale && !url.searchParams.has("locale")) {
213
- url.searchParams.set("locale", this.defaultLocale);
212
+ if (this.defaultLocale && !params.has("locale")) {
213
+ params.set("locale", this.defaultLocale);
214
214
  }
215
- if (this.defaultCurrency && !url.searchParams.has("currency")) {
216
- url.searchParams.set("currency", this.defaultCurrency);
215
+ if (this.defaultCurrency && !params.has("currency")) {
216
+ params.set("currency", this.defaultCurrency);
217
217
  }
218
+ const qs = params.toString();
219
+ const url = `${this.baseUrl}/storefront/v1${path}${qs ? `?${qs}` : ""}`;
218
220
  const headers = {
219
221
  "X-Api-Key": this.apiKey,
220
222
  "Content-Type": "application/json"
@@ -227,7 +229,7 @@ var BehioStorefront = class {
227
229
  }
228
230
  const bodyStr = options?.body ? JSON.stringify(options.body) : void 0;
229
231
  let interceptedConfig = {
230
- url: url.toString(),
232
+ url,
231
233
  method,
232
234
  headers,
233
235
  body: bodyStr
@@ -91,7 +91,7 @@ var BehioStorefront = class {
91
91
  this.apiKey = config.apiKey;
92
92
  this.defaultLocale = config.locale;
93
93
  this.defaultCurrency = config.currency;
94
- this.fetchFn = config.fetch || globalThis.fetch;
94
+ this.fetchFn = config.fetch || globalThis.fetch.bind(globalThis);
95
95
  this.timeout = _nullishCoalesce(config.timeout, () => ( 3e4));
96
96
  this.retries = _nullishCoalesce(config.retries, () => ( 1));
97
97
  this.retryDelay = _nullishCoalesce(config.retryDelay, () => ( 1e3));
@@ -201,20 +201,22 @@ var BehioStorefront = class {
201
201
  // --- Internal fetch ---
202
202
  /** @internal */
203
203
  async request(method, path, options) {
204
- const url = new URL(`${this.baseUrl}/storefront/v1${path}`);
204
+ const params = new URLSearchParams();
205
205
  if (_optionalChain([options, 'optionalAccess', _12 => _12.query])) {
206
206
  for (const [key, value] of Object.entries(options.query)) {
207
207
  if (value !== void 0 && value !== null && value !== "") {
208
- url.searchParams.set(key, String(value));
208
+ params.set(key, String(value));
209
209
  }
210
210
  }
211
211
  }
212
- if (this.defaultLocale && !url.searchParams.has("locale")) {
213
- url.searchParams.set("locale", this.defaultLocale);
212
+ if (this.defaultLocale && !params.has("locale")) {
213
+ params.set("locale", this.defaultLocale);
214
214
  }
215
- if (this.defaultCurrency && !url.searchParams.has("currency")) {
216
- url.searchParams.set("currency", this.defaultCurrency);
215
+ if (this.defaultCurrency && !params.has("currency")) {
216
+ params.set("currency", this.defaultCurrency);
217
217
  }
218
+ const qs = params.toString();
219
+ const url = `${this.baseUrl}/storefront/v1${path}${qs ? `?${qs}` : ""}`;
218
220
  const headers = {
219
221
  "X-Api-Key": this.apiKey,
220
222
  "Content-Type": "application/json"
@@ -227,7 +229,7 @@ var BehioStorefront = class {
227
229
  }
228
230
  const bodyStr = _optionalChain([options, 'optionalAccess', _14 => _14.body]) ? JSON.stringify(options.body) : void 0;
229
231
  let interceptedConfig = {
230
- url: url.toString(),
232
+ url,
231
233
  method,
232
234
  headers,
233
235
  body: bodyStr
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
 
9
9
 
10
- var _chunk26WZOAWPjs = require('./chunk-26WZOAWP.js');
10
+ var _chunkSNODOM7Ljs = require('./chunk-SNODOM7L.js');
11
11
 
12
12
 
13
13
 
@@ -17,4 +17,4 @@ var _chunk26WZOAWPjs = require('./chunk-26WZOAWP.js');
17
17
 
18
18
 
19
19
 
20
- exports.AddressTypes = _chunk26WZOAWPjs.AddressTypes; exports.BehioApiError = _chunk26WZOAWPjs.BehioApiError; exports.BehioNetworkError = _chunk26WZOAWPjs.BehioNetworkError; exports.BehioStorefront = _chunk26WZOAWPjs.BehioStorefront; exports.FulfillmentStatuses = _chunk26WZOAWPjs.FulfillmentStatuses; exports.OrderStatuses = _chunk26WZOAWPjs.OrderStatuses; exports.PaymentStatuses = _chunk26WZOAWPjs.PaymentStatuses; exports.ProductSort = _chunk26WZOAWPjs.ProductSort;
20
+ exports.AddressTypes = _chunkSNODOM7Ljs.AddressTypes; exports.BehioApiError = _chunkSNODOM7Ljs.BehioApiError; exports.BehioNetworkError = _chunkSNODOM7Ljs.BehioNetworkError; exports.BehioStorefront = _chunkSNODOM7Ljs.BehioStorefront; exports.FulfillmentStatuses = _chunkSNODOM7Ljs.FulfillmentStatuses; exports.OrderStatuses = _chunkSNODOM7Ljs.OrderStatuses; exports.PaymentStatuses = _chunkSNODOM7Ljs.PaymentStatuses; exports.ProductSort = _chunkSNODOM7Ljs.ProductSort;
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  OrderStatuses,
8
8
  PaymentStatuses,
9
9
  ProductSort
10
- } from "./chunk-3OJEEMLI.mjs";
10
+ } from "./chunk-DBZPF3IR.mjs";
11
11
  export {
12
12
  AddressTypes,
13
13
  BehioApiError,
package/dist/react.js CHANGED
@@ -1,6 +1,6 @@
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 _chunk26WZOAWPjs = require('./chunk-26WZOAWP.js');
3
+ var _chunkSNODOM7Ljs = require('./chunk-SNODOM7L.js');
4
4
 
5
5
  // src/react/provider.tsx
6
6
  var _react = require('react');
@@ -114,7 +114,7 @@ function BehioProvider({
114
114
  const storageAdapter = _react.useMemo.call(void 0, () => resolveStorage(storageOption), [storageOption]);
115
115
  const clientRef = _react.useRef.call(void 0, null);
116
116
  if (!clientRef.current) {
117
- clientRef.current = new (0, _chunk26WZOAWPjs.BehioStorefront)({
117
+ clientRef.current = new (0, _chunkSNODOM7Ljs.BehioStorefront)({
118
118
  apiKey,
119
119
  baseUrl,
120
120
  locale,
package/dist/react.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BehioStorefront
3
- } from "./chunk-3OJEEMLI.mjs";
3
+ } from "./chunk-DBZPF3IR.mjs";
4
4
 
5
5
  // src/react/provider.tsx
6
6
  import { useRef, useEffect, useMemo } from "react";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@behio/storefront-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "TypeScript SDK for Behio Headless E-Shop — core client + React hooks",
5
5
  "author": "Behio",
6
6
  "license": "MIT",