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