@shopkit/data-layer 1.5.0 → 1.7.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.
- package/README.md +31 -0
- package/dist/adapters/index.js +27 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +27 -1
- package/dist/adapters/index.mjs.map +1 -1
- package/dist/index.d.mts +20 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.js +53 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -2
- package/dist/index.mjs.map +1 -1
- package/dist/models/index.d.mts +15 -4
- package/dist/models/index.d.ts +15 -4
- package/dist/static-params/index.js +7 -0
- package/dist/static-params/index.js.map +1 -1
- package/dist/static-params/index.mjs +7 -0
- package/dist/static-params/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -160,7 +160,7 @@ function createDomainLogger(domain, adapter, config = {}) {
|
|
|
160
160
|
function isUpstreamUnavailable(error) {
|
|
161
161
|
const status = error?.status;
|
|
162
162
|
if (typeof status !== "number") return true;
|
|
163
|
-
return status >= 500;
|
|
163
|
+
return status >= 500 || status === 429;
|
|
164
164
|
}
|
|
165
165
|
function formatResponse(params) {
|
|
166
166
|
const { success, message, data = null, error = null, meta = {} } = params;
|
|
@@ -4385,6 +4385,14 @@ var ProductService2 = class extends BaseCustomService {
|
|
|
4385
4385
|
async queryCollections(params, options) {
|
|
4386
4386
|
try {
|
|
4387
4387
|
const payload = buildCollectionsQueryPayload(params);
|
|
4388
|
+
if (selectedHandles(params)?.length === 0) {
|
|
4389
|
+
return formatResponse({
|
|
4390
|
+
success: true,
|
|
4391
|
+
message: "No collections selected.",
|
|
4392
|
+
data: [],
|
|
4393
|
+
meta: { pagination: { limit: 0, skip: 0, has_more: false, total: 0, next_cursor: null } }
|
|
4394
|
+
});
|
|
4395
|
+
}
|
|
4388
4396
|
const handles = handlesNamedBy(payload.filter);
|
|
4389
4397
|
const result = await this.request(
|
|
4390
4398
|
PRODUCT_ENDPOINTS.queryCollections(options?.version),
|
|
@@ -4478,12 +4486,30 @@ function buildCollectionsQueryPayload(params) {
|
|
|
4478
4486
|
if (source[key] !== void 0) payload[key] = source[key];
|
|
4479
4487
|
}
|
|
4480
4488
|
const filter = payload.filter && typeof payload.filter === "object" ? payload.filter : {};
|
|
4489
|
+
const handles = selectedHandles(params);
|
|
4490
|
+
if (handles) {
|
|
4491
|
+
payload.filter = { ...filter, handle: { $in: handles } };
|
|
4492
|
+
if (typeof payload.limit === "number" && payload.limit < handles.length) {
|
|
4493
|
+
payload.limit = handles.length;
|
|
4494
|
+
}
|
|
4495
|
+
return payload;
|
|
4496
|
+
}
|
|
4481
4497
|
const routeHandle = source.useRouteHandle === true ? source.handle : void 0;
|
|
4482
4498
|
if (typeof routeHandle === "string" && routeHandle.trim() !== "" && filter.handle === void 0) {
|
|
4483
4499
|
payload.filter = { ...filter, handle: routeHandle };
|
|
4484
4500
|
}
|
|
4485
4501
|
return payload;
|
|
4486
4502
|
}
|
|
4503
|
+
var MAX_COLLECTIONS_PER_QUERY = 10;
|
|
4504
|
+
function selectedHandles(params) {
|
|
4505
|
+
const source = params || {};
|
|
4506
|
+
if (!Array.isArray(source.handles)) return void 0;
|
|
4507
|
+
const filter = source.filter;
|
|
4508
|
+
if (filter && typeof filter === "object" && filter.handle !== void 0) {
|
|
4509
|
+
return void 0;
|
|
4510
|
+
}
|
|
4511
|
+
return source.handles.filter((h) => typeof h === "string").map((h) => h.trim()).filter((h) => h !== "").slice(0, MAX_COLLECTIONS_PER_QUERY);
|
|
4512
|
+
}
|
|
4487
4513
|
function handlesNamedBy(filter) {
|
|
4488
4514
|
const handle = filter?.handle;
|
|
4489
4515
|
const candidates = typeof handle === "string" ? [handle] : handle && typeof handle === "object" ? [
|
|
@@ -5224,6 +5250,23 @@ function createCommerceClient(clientConfig) {
|
|
|
5224
5250
|
}
|
|
5225
5251
|
}
|
|
5226
5252
|
|
|
5253
|
+
// src/core/shopper-ip.ts
|
|
5254
|
+
var IPV4 = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/;
|
|
5255
|
+
var IPV6 = /^(?=.*:)[0-9a-f:]{2,39}(\.\d{1,3}){0,3}$/i;
|
|
5256
|
+
function getShopperIp(headers, options) {
|
|
5257
|
+
const entries = (headers.get("x-forwarded-for") ?? "").split(",").map((entry2) => entry2.trim()).filter(Boolean);
|
|
5258
|
+
const entry = entries[entries.length - (options?.trustedHops ?? 1)];
|
|
5259
|
+
if (!entry) return null;
|
|
5260
|
+
const candidate = entry.match(/^\[([^\]]+)\](?::\d+)?$/)?.[1] ?? entry.match(/^(\d{1,3}(?:\.\d{1,3}){3}):\d+$/)?.[1] ?? entry;
|
|
5261
|
+
const ip = candidate.toLowerCase().startsWith("::ffff:") && IPV4.test(candidate.slice(7)) ? candidate.slice(7) : candidate;
|
|
5262
|
+
return IPV4.test(ip) || IPV6.test(ip) ? ip : null;
|
|
5263
|
+
}
|
|
5264
|
+
function shopperForwardHeaders(source, options) {
|
|
5265
|
+
const headers = source instanceof Headers ? source : source.headers;
|
|
5266
|
+
const ip = getShopperIp(headers, options);
|
|
5267
|
+
return ip ? { "x-forwarded-for": ip } : {};
|
|
5268
|
+
}
|
|
5269
|
+
|
|
5227
5270
|
// src/models/enums.ts
|
|
5228
5271
|
var EOrderStatus = /* @__PURE__ */ ((EOrderStatus2) => {
|
|
5229
5272
|
EOrderStatus2["PENDING"] = "PENDING";
|
|
@@ -5282,6 +5325,9 @@ var EFulfillmentStatus = /* @__PURE__ */ ((EFulfillmentStatus2) => {
|
|
|
5282
5325
|
|
|
5283
5326
|
// src/static-params/index.ts
|
|
5284
5327
|
var log = logger.child({ module: "static-params" });
|
|
5328
|
+
function skipBuildStaticParams() {
|
|
5329
|
+
return process.env.SKIP_BUILD_STATIC_PARAMS === "true";
|
|
5330
|
+
}
|
|
5285
5331
|
async function withConcurrency(thunks, limit) {
|
|
5286
5332
|
const results = new Array(thunks.length);
|
|
5287
5333
|
let next = 0;
|
|
@@ -5328,6 +5374,7 @@ async function traverseCollectionProducts(client, collectionsLimit, productsPerC
|
|
|
5328
5374
|
}
|
|
5329
5375
|
function createCollectionStaticParams(getClient, options) {
|
|
5330
5376
|
return async function generateStaticParams() {
|
|
5377
|
+
if (skipBuildStaticParams()) return [];
|
|
5331
5378
|
const limit = options?.limit ?? 250;
|
|
5332
5379
|
try {
|
|
5333
5380
|
const result = await getClient().getCollections({ first: limit });
|
|
@@ -5347,6 +5394,7 @@ function createCollectionStaticParams(getClient, options) {
|
|
|
5347
5394
|
}
|
|
5348
5395
|
function createProductStaticParams(getClient, options) {
|
|
5349
5396
|
return async function generateStaticParams() {
|
|
5397
|
+
if (skipBuildStaticParams()) return [];
|
|
5350
5398
|
const limit = options?.limit ?? 250;
|
|
5351
5399
|
try {
|
|
5352
5400
|
const result = await getClient().getProducts({ first: limit });
|
|
@@ -5366,6 +5414,7 @@ function createProductStaticParams(getClient, options) {
|
|
|
5366
5414
|
}
|
|
5367
5415
|
function createProductViaCollectionsStaticParams(getClient, options) {
|
|
5368
5416
|
return async function generateStaticParams() {
|
|
5417
|
+
if (skipBuildStaticParams()) return [];
|
|
5369
5418
|
try {
|
|
5370
5419
|
const pairs = await traverseCollectionProducts(
|
|
5371
5420
|
getClient(),
|
|
@@ -5387,6 +5436,7 @@ function createProductViaCollectionsStaticParams(getClient, options) {
|
|
|
5387
5436
|
}
|
|
5388
5437
|
function createCollectionProductStaticParams(getClient, options) {
|
|
5389
5438
|
return async function generateStaticParams() {
|
|
5439
|
+
if (skipBuildStaticParams()) return [];
|
|
5390
5440
|
try {
|
|
5391
5441
|
const pairs = await traverseCollectionProducts(
|
|
5392
5442
|
getClient(),
|
|
@@ -5411,6 +5461,6 @@ function createCollectionProductStaticParams(getClient, options) {
|
|
|
5411
5461
|
};
|
|
5412
5462
|
}
|
|
5413
5463
|
|
|
5414
|
-
export { DEFAULT_REQUEST_TIMEOUT_MS, EAvailability, ECollectionSortKey, EFulfillmentStatus, EOrderSortKey, EOrderStatus, EPaymentStatus, EProductSortKey, createCollectionProductStaticParams, createCollectionStaticParams, createCommerceClient, createCustomClient, createProductStaticParams, createProductViaCollectionsStaticParams, createShopifyClient, resolveRequestSignal };
|
|
5464
|
+
export { DEFAULT_REQUEST_TIMEOUT_MS, EAvailability, ECollectionSortKey, EFulfillmentStatus, EOrderSortKey, EOrderStatus, EPaymentStatus, EProductSortKey, createCollectionProductStaticParams, createCollectionStaticParams, createCommerceClient, createCustomClient, createProductStaticParams, createProductViaCollectionsStaticParams, createShopifyClient, getShopperIp, resolveRequestSignal, shopperForwardHeaders };
|
|
5415
5465
|
//# sourceMappingURL=index.mjs.map
|
|
5416
5466
|
//# sourceMappingURL=index.mjs.map
|