@shopkit/data-layer 1.4.4 → 1.4.6

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/dist/index.js CHANGED
@@ -3780,10 +3780,10 @@ var PRODUCT_ENDPOINTS = {
3780
3780
  getProduct: (v = DEFAULT_VERSION) => `/api/${v}/product/details`,
3781
3781
  getProductsByHandles: (v = DEFAULT_VERSION) => `/api/${v}/product/details`,
3782
3782
  getCollections: (v = DEFAULT_VERSION) => `/api/${v}/collections`,
3783
- getCollectionByHandle: (v = DEFAULT_VERSION, h) => `/api/${v}/collections/handle/${h}`,
3784
- getCollectionById: (v = DEFAULT_VERSION, id) => `/api/${v}/collections/${id}`,
3783
+ getCollectionByHandle: (v = DEFAULT_VERSION, h) => `/api/${v}/collections/handle/${encodeURIComponent(h)}`,
3784
+ getCollectionById: (v = DEFAULT_VERSION, id) => `/api/${v}/collections/${encodeURIComponent(id)}`,
3785
3785
  getCollectionsByHandles: (v = DEFAULT_VERSION) => `/api/${v}/collections/details`,
3786
- getCollectionFilters: (v = DEFAULT_VERSION, collectionHandle) => `/api/${v}/storefront/collections/${collectionHandle}/filters`
3786
+ getCollectionFilters: (v = DEFAULT_VERSION, collectionHandle) => `/api/${v}/storefront/collections/${encodeURIComponent(collectionHandle)}/filters`
3787
3787
  };
3788
3788
 
3789
3789
  // src/adapters/custom/product/service.ts
@@ -4187,9 +4187,12 @@ var ProductService2 = class extends BaseCustomService {
4187
4187
  }
4188
4188
  const payload = {
4189
4189
  storeId: this.config.storeId,
4190
- available: params.filters?.[0]?.available ?? true,
4191
4190
  collectionHandles: handles
4192
4191
  };
4192
+ const availability = params.filters?.[0]?.available;
4193
+ if (typeof availability === "boolean") {
4194
+ payload.available = availability;
4195
+ }
4193
4196
  if (params.filters && params.filters.length > 0) {
4194
4197
  const filter = params.filters[0];
4195
4198
  if (filter.price?.min !== void 0) {
@@ -5007,12 +5010,69 @@ var CustomBackendClient = class extends BaseCommerceClient {
5007
5010
  }
5008
5011
  };
5009
5012
 
5013
+ // src/core/normalize-handle.ts
5014
+ function isUnsafeHandle(value) {
5015
+ for (const char of value) {
5016
+ const code = char.codePointAt(0) ?? 0;
5017
+ if (code < 32 || code === 127) {
5018
+ return true;
5019
+ }
5020
+ if (char === "/" || char === "\\" || char === "?" || char === "#" || char === '"') {
5021
+ return true;
5022
+ }
5023
+ }
5024
+ return false;
5025
+ }
5026
+ function decodeHandle(value) {
5027
+ let decoded;
5028
+ try {
5029
+ decoded = decodeURIComponent(value);
5030
+ } catch {
5031
+ return value;
5032
+ }
5033
+ return isUnsafeHandle(decoded) ? value : decoded;
5034
+ }
5035
+ function normalizeParams(params) {
5036
+ if (!params || typeof params !== "object") {
5037
+ return params;
5038
+ }
5039
+ const { handle, handles } = params;
5040
+ const hasHandle = typeof handle === "string";
5041
+ const hasHandles = Array.isArray(handles);
5042
+ if (!hasHandle && !hasHandles) {
5043
+ return params;
5044
+ }
5045
+ const next = { ...params };
5046
+ if (hasHandle) {
5047
+ next.handle = decodeHandle(handle);
5048
+ }
5049
+ if (hasHandles) {
5050
+ next.handles = handles.map(
5051
+ (h) => typeof h === "string" ? decodeHandle(h) : h
5052
+ );
5053
+ }
5054
+ return next;
5055
+ }
5056
+ function withHandleNormalization(client) {
5057
+ return new Proxy(client, {
5058
+ get(target, prop) {
5059
+ const value = Reflect.get(target, prop);
5060
+ if (typeof value !== "function") {
5061
+ return value;
5062
+ }
5063
+ return function(params, ...rest) {
5064
+ return value.call(target, normalizeParams(params), ...rest);
5065
+ };
5066
+ }
5067
+ });
5068
+ }
5069
+
5010
5070
  // src/core/init.ts
5011
5071
  function createShopifyClient(config, logging) {
5012
- return new ShopifyCommerceClient(config, logging);
5072
+ return withHandleNormalization(new ShopifyCommerceClient(config, logging));
5013
5073
  }
5014
5074
  function createCustomClient(config, logging) {
5015
- return new CustomBackendClient(config, logging);
5075
+ return withHandleNormalization(new CustomBackendClient(config, logging));
5016
5076
  }
5017
5077
  function createCommerceClient(clientConfig) {
5018
5078
  switch (clientConfig.type) {