@shopkit/data-layer 1.6.0 → 1.8.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/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { I as ICommerceClient } from './interface-CgPiwpPe.mjs';
2
- import { I as IShopifyConfig, L as LoggerConfig, a as ICustomConfig, C as CustomBackendClient, S as ShopifyCommerceClient } from './service-BPzeuSLS.mjs';
3
- export { EAvailability, ECollectionSortKey, EFulfillmentStatus, EOrderSortKey, EOrderStatus, EPaymentStatus, EProductSortKey, IAddToCartRequest, IAddress, IArticleByHandleRequest, IBaseQueryParams, IBlogArticleRequest, ICartItemRequest, ICollectionFilterRequest, ICollectionQueryRequest, ICollectionsByhandlesRequest, ICreateCheckoutRequest, ICustomerQueryRequest, ICustomerRequest, IFetchRequest, IGetArticleRequest, IGraphqlRequest, IImage, IMetafield, IMoney, IOptionsRequest, IOrderByIdRequest, IOrderHistoryRequest, IOrderQueryRequest, IOrderRequest, IPaginationParams, IProductFilters, IProductQueryReqest, IProductRecommendationsRequest, IProductsByHandlesRequest, IQueryCollectionsInclude, IQueryCollectionsRequest, IRemoveFromCartRequest, IResponse, IResponseMeta, ISeo, ISingleCartRequest, ISingleCollectionRequest, ISingleCustomerRequest, ISingleOrderRequest, ISingleProductRequest, ITrendingArticleRequest, IUpdateCartRequest, IUpdateCustomerRequest, IUpdateOrderRequest, QueryCollectionsErrorCode, QuerySortDirection } from './models/index.mjs';
1
+ import { I as ICommerceClient } from './interface-D4gQCRsx.mjs';
2
+ import { I as IShopifyConfig, L as LoggerConfig, a as ICustomConfig, C as CustomBackendClient, S as ShopifyCommerceClient } from './service-BEiNHL9V.mjs';
3
+ export { CollectionVariantCardsErrorCode, CollectionVariantCardsSortKey, EAvailability, ECollectionSortKey, EFulfillmentStatus, EOrderSortKey, EOrderStatus, EPaymentStatus, EProductSortKey, IAddToCartRequest, IAddress, IArticleByHandleRequest, IBaseQueryParams, IBlogArticleRequest, ICartItemRequest, ICollectionFilterRequest, ICollectionQueryRequest, ICollectionsByhandlesRequest, ICreateCheckoutRequest, ICustomerQueryRequest, ICustomerRequest, IFetchRequest, IGetArticleRequest, IGetCollectionVariantCardsRequest, IGraphqlRequest, IImage, IMetafield, IMoney, IOptionsRequest, IOrderByIdRequest, IOrderHistoryRequest, IOrderQueryRequest, IOrderRequest, IPaginationParams, IProductFilters, IProductQueryReqest, IProductRecommendationsRequest, IProductsByHandlesRequest, IQueryCollectionsInclude, IQueryCollectionsRequest, IRemoveFromCartRequest, IResponse, IResponseMeta, ISeo, ISingleCartRequest, ISingleCollectionRequest, ISingleCustomerRequest, ISingleOrderRequest, ISingleProductRequest, ITrendingArticleRequest, IUpdateCartRequest, IUpdateCustomerRequest, IUpdateOrderRequest, PriceRangeDto, ProductCardDto, ProductCardImageDto, QueryCollectionsErrorCode, QuerySortDirection, VariantCardDto, VariantCardImageDto, VariantCardOptionDto, VariantCardsPageDto } from './models/index.mjs';
4
4
  export { createCollectionProductStaticParams, createCollectionStaticParams, createProductStaticParams, createProductViaCollectionsStaticParams } from './static-params/index.mjs';
5
5
 
6
6
  /**
@@ -122,4 +122,23 @@ declare function resolveRequestSignal(options?: {
122
122
  timeoutMs?: number;
123
123
  }, defaultMs?: number): AbortSignal;
124
124
 
125
- export { DEFAULT_REQUEST_TIMEOUT_MS, type IClientConfig, ICommerceClient, ICustomConfig, IShopifyConfig, createCommerceClient, createCustomClient, createShopifyClient, resolveRequestSignal };
125
+ /**
126
+ * The shopper's IP, for forwarding to the OS API gateway (per-shopper rate limits).
127
+ *
128
+ * Read from the RIGHT of X-Forwarded-For: our load balancer appends the TCP peer
129
+ * it saw, so the entry `trustedHops` from the end is the one the shopper cannot
130
+ * forge. Entries to its left, and cf-connecting-ip / true-client-ip / x-real-ip,
131
+ * come from the shopper verbatim (no CDN in front of our pods overwrites them).
132
+ *
133
+ * Only for UNCACHED fetches: Next.js keys its fetch cache on request headers, so a
134
+ * per-shopper header on a cached fetch creates one cache entry per IP.
135
+ */
136
+ interface ShopperIpOptions {
137
+ /** Proxies we run in front of the app that append to X-Forwarded-For. Default 1 (the ALB). */
138
+ trustedHops?: number;
139
+ }
140
+ declare function getShopperIp(headers: Headers, options?: ShopperIpOptions): string | null;
141
+ /** `{ "x-forwarded-for": <shopper IP> }` to spread into an uncached upstream fetch, or `{}`. */
142
+ declare function shopperForwardHeaders(source: Request | Headers, options?: ShopperIpOptions): Record<string, string>;
143
+
144
+ export { DEFAULT_REQUEST_TIMEOUT_MS, type IClientConfig, ICommerceClient, ICustomConfig, IShopifyConfig, type ShopperIpOptions, createCommerceClient, createCustomClient, createShopifyClient, getShopperIp, resolveRequestSignal, shopperForwardHeaders };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { I as ICommerceClient } from './interface-BGV7d5F8.js';
2
- import { I as IShopifyConfig, L as LoggerConfig, a as ICustomConfig, C as CustomBackendClient, S as ShopifyCommerceClient } from './service-Cb074q9F.js';
3
- export { EAvailability, ECollectionSortKey, EFulfillmentStatus, EOrderSortKey, EOrderStatus, EPaymentStatus, EProductSortKey, IAddToCartRequest, IAddress, IArticleByHandleRequest, IBaseQueryParams, IBlogArticleRequest, ICartItemRequest, ICollectionFilterRequest, ICollectionQueryRequest, ICollectionsByhandlesRequest, ICreateCheckoutRequest, ICustomerQueryRequest, ICustomerRequest, IFetchRequest, IGetArticleRequest, IGraphqlRequest, IImage, IMetafield, IMoney, IOptionsRequest, IOrderByIdRequest, IOrderHistoryRequest, IOrderQueryRequest, IOrderRequest, IPaginationParams, IProductFilters, IProductQueryReqest, IProductRecommendationsRequest, IProductsByHandlesRequest, IQueryCollectionsInclude, IQueryCollectionsRequest, IRemoveFromCartRequest, IResponse, IResponseMeta, ISeo, ISingleCartRequest, ISingleCollectionRequest, ISingleCustomerRequest, ISingleOrderRequest, ISingleProductRequest, ITrendingArticleRequest, IUpdateCartRequest, IUpdateCustomerRequest, IUpdateOrderRequest, QueryCollectionsErrorCode, QuerySortDirection } from './models/index.js';
1
+ import { I as ICommerceClient } from './interface-CWuOTUIW.js';
2
+ import { I as IShopifyConfig, L as LoggerConfig, a as ICustomConfig, C as CustomBackendClient, S as ShopifyCommerceClient } from './service-C4eDXKmf.js';
3
+ export { CollectionVariantCardsErrorCode, CollectionVariantCardsSortKey, EAvailability, ECollectionSortKey, EFulfillmentStatus, EOrderSortKey, EOrderStatus, EPaymentStatus, EProductSortKey, IAddToCartRequest, IAddress, IArticleByHandleRequest, IBaseQueryParams, IBlogArticleRequest, ICartItemRequest, ICollectionFilterRequest, ICollectionQueryRequest, ICollectionsByhandlesRequest, ICreateCheckoutRequest, ICustomerQueryRequest, ICustomerRequest, IFetchRequest, IGetArticleRequest, IGetCollectionVariantCardsRequest, IGraphqlRequest, IImage, IMetafield, IMoney, IOptionsRequest, IOrderByIdRequest, IOrderHistoryRequest, IOrderQueryRequest, IOrderRequest, IPaginationParams, IProductFilters, IProductQueryReqest, IProductRecommendationsRequest, IProductsByHandlesRequest, IQueryCollectionsInclude, IQueryCollectionsRequest, IRemoveFromCartRequest, IResponse, IResponseMeta, ISeo, ISingleCartRequest, ISingleCollectionRequest, ISingleCustomerRequest, ISingleOrderRequest, ISingleProductRequest, ITrendingArticleRequest, IUpdateCartRequest, IUpdateCustomerRequest, IUpdateOrderRequest, PriceRangeDto, ProductCardDto, ProductCardImageDto, QueryCollectionsErrorCode, QuerySortDirection, VariantCardDto, VariantCardImageDto, VariantCardOptionDto, VariantCardsPageDto } from './models/index.js';
4
4
  export { createCollectionProductStaticParams, createCollectionStaticParams, createProductStaticParams, createProductViaCollectionsStaticParams } from './static-params/index.js';
5
5
 
6
6
  /**
@@ -122,4 +122,23 @@ declare function resolveRequestSignal(options?: {
122
122
  timeoutMs?: number;
123
123
  }, defaultMs?: number): AbortSignal;
124
124
 
125
- export { DEFAULT_REQUEST_TIMEOUT_MS, type IClientConfig, ICommerceClient, ICustomConfig, IShopifyConfig, createCommerceClient, createCustomClient, createShopifyClient, resolveRequestSignal };
125
+ /**
126
+ * The shopper's IP, for forwarding to the OS API gateway (per-shopper rate limits).
127
+ *
128
+ * Read from the RIGHT of X-Forwarded-For: our load balancer appends the TCP peer
129
+ * it saw, so the entry `trustedHops` from the end is the one the shopper cannot
130
+ * forge. Entries to its left, and cf-connecting-ip / true-client-ip / x-real-ip,
131
+ * come from the shopper verbatim (no CDN in front of our pods overwrites them).
132
+ *
133
+ * Only for UNCACHED fetches: Next.js keys its fetch cache on request headers, so a
134
+ * per-shopper header on a cached fetch creates one cache entry per IP.
135
+ */
136
+ interface ShopperIpOptions {
137
+ /** Proxies we run in front of the app that append to X-Forwarded-For. Default 1 (the ALB). */
138
+ trustedHops?: number;
139
+ }
140
+ declare function getShopperIp(headers: Headers, options?: ShopperIpOptions): string | null;
141
+ /** `{ "x-forwarded-for": <shopper IP> }` to spread into an uncached upstream fetch, or `{}`. */
142
+ declare function shopperForwardHeaders(source: Request | Headers, options?: ShopperIpOptions): Record<string, string>;
143
+
144
+ export { DEFAULT_REQUEST_TIMEOUT_MS, type IClientConfig, ICommerceClient, ICustomConfig, IShopifyConfig, type ShopperIpOptions, createCommerceClient, createCustomClient, createShopifyClient, getShopperIp, resolveRequestSignal, shopperForwardHeaders };
package/dist/index.js CHANGED
@@ -162,7 +162,7 @@ function createDomainLogger(domain, adapter, config = {}) {
162
162
  function isUpstreamUnavailable(error) {
163
163
  const status = error?.status;
164
164
  if (typeof status !== "number") return true;
165
- return status >= 500;
165
+ return status >= 500 || status === 429;
166
166
  }
167
167
  function formatResponse(params) {
168
168
  const { success, message, data = null, error = null, meta = {} } = params;
@@ -308,6 +308,16 @@ var BaseCommerceClient = class {
308
308
  queryCollections(params, options) {
309
309
  this.throwNotImplemented("queryCollections");
310
310
  }
311
+ /**
312
+ * Read a page of a collection's products, with one card per matching variant
313
+ * @param params - Handle plus page/per_page, sort, filter, fields
314
+ * @param options - Request options (headers, timeout, etc.)
315
+ * @returns Promise resolving to a VariantCardsPageDto
316
+ * @throws NotImplementedError if not implemented in adapter (custom backend only)
317
+ */
318
+ getCollectionVariantCards(params, options) {
319
+ this.throwNotImplemented("getCollectionVariantCards");
320
+ }
311
321
  // ========================================
312
322
  // ORDER OPERATIONS
313
323
  // ========================================
@@ -3802,7 +3812,8 @@ var PRODUCT_ENDPOINTS = {
3802
3812
  getCollectionById: (v = DEFAULT_VERSION, id) => `/api/${v}/collections/${encodeURIComponent(id)}`,
3803
3813
  getCollectionsByHandles: (v = DEFAULT_VERSION) => `/api/${v}/collections/details`,
3804
3814
  getCollectionFilters: (v = DEFAULT_VERSION, collectionHandle) => `/api/${v}/storefront/collections/${encodeURIComponent(collectionHandle)}/filters`,
3805
- queryCollections: (v = DEFAULT_VERSION) => `/api/${v}/collections/query`
3815
+ queryCollections: (v = DEFAULT_VERSION) => `/api/${v}/collections/query`,
3816
+ collectionVariants: (v = DEFAULT_VERSION, handle) => `/api/${v}/collections/${encodeURIComponent(handle)}/variants`
3806
3817
  };
3807
3818
 
3808
3819
  // src/adapters/custom/product/service.ts
@@ -4467,7 +4478,268 @@ var ProductService2 = class extends BaseCustomService {
4467
4478
  });
4468
4479
  }
4469
4480
  }
4481
+ /**
4482
+ * A page of a collection's products, with one card per matching variant
4483
+ * (POST /api/v1/collections/{handle}/variants). A POST because filters are
4484
+ * nested; it is still a read and answers 200.
4485
+ *
4486
+ * With `allVariants: true`, follows `next_cursor` (same body + `after`,
4487
+ * 100 cards per call) and returns the whole page's variants in one result.
4488
+ * The result is complete or it is a failure — never a partial page, which
4489
+ * would be cached as if it were complete. It fails (`UPSTREAM_UNAVAILABLE`)
4490
+ * when a follow-up call fails, when the cursor repeats, or when the page is
4491
+ * not done within ALL_VARIANTS_MAX_CALLS calls or ALL_VARIANTS_DEADLINE_MS.
4492
+ */
4493
+ async getCollectionVariantCards(params, options) {
4494
+ const handle = typeof params?.handle === "string" ? params.handle.trim() : "";
4495
+ if (!handle) {
4496
+ return formatResponse({
4497
+ success: false,
4498
+ message: "Missing required variable: 'handle'",
4499
+ error: {
4500
+ code: "QUERY_REJECTED",
4501
+ message: "handle: is required"
4502
+ }
4503
+ });
4504
+ }
4505
+ if (handle.includes("/") || handle === "." || handle === "..") {
4506
+ return formatResponse({
4507
+ success: false,
4508
+ message: "Collection not found.",
4509
+ error: {
4510
+ code: "NOT_FOUND",
4511
+ message: `No collection with handle ${handle}`
4512
+ }
4513
+ });
4514
+ }
4515
+ const payload = buildCollectionVariantsPayload(params);
4516
+ const requestOptions = {
4517
+ ...options || {},
4518
+ // Same coverage as queryCollections: the broad tag for catalog-wide
4519
+ // purges plus the collection's own, which product.updated /
4520
+ // collection.updated webhooks already purge. No `revalidate`.
4521
+ next: {
4522
+ ...options?.next || {},
4523
+ tags: [
4524
+ cacheTags.CacheTags.collections(),
4525
+ cacheTags.CacheTags.collection(handle),
4526
+ ...options?.next?.tags || []
4527
+ ]
4528
+ }
4529
+ };
4530
+ const endpoint = PRODUCT_ENDPOINTS.collectionVariants(
4531
+ options?.version,
4532
+ handle
4533
+ );
4534
+ const allVariants = params.allVariants === true;
4535
+ const deadline = allVariants ? AbortSignal.timeout(ALL_VARIANTS_DEADLINE_MS) : void 0;
4536
+ const callOptions = () => deadline ? {
4537
+ ...requestOptions,
4538
+ signal: anySignal([
4539
+ deadline,
4540
+ options?.signal ?? AbortSignal.timeout(options?.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS)
4541
+ ])
4542
+ } : requestOptions;
4543
+ let followUp = false;
4544
+ try {
4545
+ let result = await this.request(endpoint, "POST", payload, callOptions());
4546
+ if (!result?.data) return noVariantCardsData(result?.request_id);
4547
+ const page = {
4548
+ ...result.data,
4549
+ variants: Array.isArray(result.data.variants) ? result.data.variants : []
4550
+ };
4551
+ const errors = Array.isArray(result.errors) ? [...result.errors] : [];
4552
+ if (allVariants) {
4553
+ followUp = true;
4554
+ const variants = [];
4555
+ const seenIds = /* @__PURE__ */ new Set();
4556
+ const addCards = (cards) => {
4557
+ for (const card of Array.isArray(cards) ? cards : []) {
4558
+ if (typeof card?.id === "string") {
4559
+ if (seenIds.has(card.id)) continue;
4560
+ seenIds.add(card.id);
4561
+ }
4562
+ variants.push(card);
4563
+ }
4564
+ };
4565
+ addCards(page.variants);
4566
+ const seenCursors = new Set(
4567
+ typeof payload.after === "string" ? [payload.after] : []
4568
+ );
4569
+ let cursor = page.next_cursor;
4570
+ let calls = 1;
4571
+ while (cursor) {
4572
+ if (seenCursors.has(cursor)) {
4573
+ return incompleteVariantCards(
4574
+ "the backend returned a cursor it had already sent",
4575
+ result.request_id,
4576
+ this.logger
4577
+ );
4578
+ }
4579
+ if (calls >= ALL_VARIANTS_MAX_CALLS) {
4580
+ return incompleteVariantCards(
4581
+ `the page has more cards than ${ALL_VARIANTS_MAX_CALLS} calls of ${MAX_VARIANT_CARDS_PER_CALL} hold`,
4582
+ result.request_id,
4583
+ this.logger
4584
+ );
4585
+ }
4586
+ seenCursors.add(cursor);
4587
+ result = await this.request(
4588
+ endpoint,
4589
+ "POST",
4590
+ { ...payload, after: cursor },
4591
+ callOptions()
4592
+ );
4593
+ calls++;
4594
+ if (!result?.data) return noVariantCardsData(result?.request_id);
4595
+ addCards(result.data.variants);
4596
+ if (Array.isArray(result.errors)) errors.push(...result.errors);
4597
+ cursor = result.data.next_cursor;
4598
+ }
4599
+ page.variants = variants;
4600
+ page.next_cursor = null;
4601
+ }
4602
+ const distinctErrors = dedupeErrors(errors);
4603
+ return formatResponse({
4604
+ success: true,
4605
+ message: "Collection variants retrieved successfully.",
4606
+ data: page,
4607
+ meta: {
4608
+ requestId: result.request_id,
4609
+ ...distinctErrors.length > 0 ? { errors: distinctErrors } : {}
4610
+ }
4611
+ });
4612
+ } catch (error) {
4613
+ this.logger.error("Error in getCollectionVariantCards", void 0, {
4614
+ error
4615
+ });
4616
+ const body = error?.body;
4617
+ if (deadline?.aborted) {
4618
+ return incompleteVariantCards(
4619
+ `the page was not complete within ${ALL_VARIANTS_DEADLINE_MS / 1e3}s`,
4620
+ body?.request_id,
4621
+ this.logger
4622
+ );
4623
+ }
4624
+ if (isUpstreamUnavailable(error)) {
4625
+ return formatResponse({
4626
+ success: false,
4627
+ message: "An error occurred while processing the request.",
4628
+ error: {
4629
+ code: "UPSTREAM_UNAVAILABLE",
4630
+ message: typeof error?.status === "number" ? `Request failed: ${error.status}` : "Collection variants request did not complete."
4631
+ },
4632
+ meta: { requestId: body?.request_id }
4633
+ });
4634
+ }
4635
+ const upstreamErrors = Array.isArray(body?.errors) ? body.errors : [];
4636
+ if (error?.status === 404) {
4637
+ if (!followUp && upstreamErrors[0]?.code === "NOT_FOUND") {
4638
+ return formatResponse({
4639
+ success: false,
4640
+ message: "Collection not found.",
4641
+ error: {
4642
+ code: "NOT_FOUND",
4643
+ message: upstreamErrors[0]?.message || `No collection with handle ${handle}`
4644
+ },
4645
+ meta: { requestId: body?.request_id }
4646
+ });
4647
+ }
4648
+ return formatResponse({
4649
+ success: false,
4650
+ message: "An error occurred while processing the request.",
4651
+ error: {
4652
+ code: "UPSTREAM_UNAVAILABLE",
4653
+ message: "Request failed: 404"
4654
+ },
4655
+ meta: { requestId: body?.request_id }
4656
+ });
4657
+ }
4658
+ return formatResponse({
4659
+ success: false,
4660
+ message: "The collection variants request was rejected.",
4661
+ error: {
4662
+ code: "QUERY_REJECTED",
4663
+ message: upstreamErrors[0]?.message || error.message,
4664
+ details: upstreamErrors
4665
+ },
4666
+ meta: { requestId: body?.request_id }
4667
+ });
4668
+ }
4669
+ }
4470
4670
  };
4671
+ function incompleteVariantCards(reason, requestId, logger2) {
4672
+ logger2.warn(`getCollectionVariantCards allVariants incomplete: ${reason}`);
4673
+ return formatResponse({
4674
+ success: false,
4675
+ message: "Collection variants page is incomplete.",
4676
+ error: {
4677
+ code: "UPSTREAM_UNAVAILABLE",
4678
+ message: `allVariants: ${reason}; not returning a partial page.`
4679
+ },
4680
+ meta: { requestId }
4681
+ });
4682
+ }
4683
+ function dedupeErrors(errors) {
4684
+ const seen = /* @__PURE__ */ new Set();
4685
+ return errors.filter((e) => {
4686
+ const err = e;
4687
+ const key = JSON.stringify([err?.code, err?.message]);
4688
+ if (seen.has(key)) return false;
4689
+ seen.add(key);
4690
+ return true;
4691
+ });
4692
+ }
4693
+ function anySignal(signals) {
4694
+ const controller = new AbortController();
4695
+ for (const signal of signals) {
4696
+ if (signal.aborted) {
4697
+ controller.abort(signal.reason);
4698
+ break;
4699
+ }
4700
+ signal.addEventListener("abort", () => controller.abort(signal.reason), {
4701
+ once: true
4702
+ });
4703
+ }
4704
+ return controller.signal;
4705
+ }
4706
+ function noVariantCardsData(requestId) {
4707
+ return formatResponse({
4708
+ success: false,
4709
+ message: "Collection variants request returned no data.",
4710
+ error: {
4711
+ code: "UPSTREAM_UNAVAILABLE",
4712
+ message: "No data in collection variants response."
4713
+ },
4714
+ meta: { requestId }
4715
+ });
4716
+ }
4717
+ var COLLECTION_VARIANTS_KEYS = [
4718
+ "filter",
4719
+ "fields",
4720
+ "product",
4721
+ "sort",
4722
+ "page",
4723
+ "per_page",
4724
+ "limit",
4725
+ "after",
4726
+ "ratings",
4727
+ "metafields"
4728
+ ];
4729
+ var MAX_VARIANT_CARDS_PER_CALL = 100;
4730
+ var ALL_VARIANTS_MAX_CALLS = 20;
4731
+ var ALL_VARIANTS_DEADLINE_MS = 15e3;
4732
+ function buildCollectionVariantsPayload(params) {
4733
+ const source = params || {};
4734
+ const payload = {};
4735
+ for (const key of COLLECTION_VARIANTS_KEYS) {
4736
+ if (source[key] !== void 0) payload[key] = source[key];
4737
+ }
4738
+ if (source.allVariants === true) {
4739
+ payload.limit = MAX_VARIANT_CARDS_PER_CALL;
4740
+ }
4741
+ return payload;
4742
+ }
4471
4743
  var COLLECTIONS_QUERY_KEYS = [
4472
4744
  "filter",
4473
4745
  "fields",
@@ -5109,6 +5381,12 @@ var CustomBackendClient = class extends BaseCommerceClient {
5109
5381
  filterRestOptions(options)
5110
5382
  );
5111
5383
  }
5384
+ async getCollectionVariantCards(params, options) {
5385
+ return this.productService.getCollectionVariantCards(
5386
+ params,
5387
+ filterRestOptions(options)
5388
+ );
5389
+ }
5112
5390
  // ========================================
5113
5391
  // CART OPERATIONS
5114
5392
  // ========================================
@@ -5252,6 +5530,23 @@ function createCommerceClient(clientConfig) {
5252
5530
  }
5253
5531
  }
5254
5532
 
5533
+ // src/core/shopper-ip.ts
5534
+ 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}$/;
5535
+ var IPV6 = /^(?=.*:)[0-9a-f:]{2,39}(\.\d{1,3}){0,3}$/i;
5536
+ function getShopperIp(headers, options) {
5537
+ const entries = (headers.get("x-forwarded-for") ?? "").split(",").map((entry2) => entry2.trim()).filter(Boolean);
5538
+ const entry = entries[entries.length - (options?.trustedHops ?? 1)];
5539
+ if (!entry) return null;
5540
+ const candidate = entry.match(/^\[([^\]]+)\](?::\d+)?$/)?.[1] ?? entry.match(/^(\d{1,3}(?:\.\d{1,3}){3}):\d+$/)?.[1] ?? entry;
5541
+ const ip = candidate.toLowerCase().startsWith("::ffff:") && IPV4.test(candidate.slice(7)) ? candidate.slice(7) : candidate;
5542
+ return IPV4.test(ip) || IPV6.test(ip) ? ip : null;
5543
+ }
5544
+ function shopperForwardHeaders(source, options) {
5545
+ const headers = source instanceof Headers ? source : source.headers;
5546
+ const ip = getShopperIp(headers, options);
5547
+ return ip ? { "x-forwarded-for": ip } : {};
5548
+ }
5549
+
5255
5550
  // src/models/enums.ts
5256
5551
  var EOrderStatus = /* @__PURE__ */ ((EOrderStatus2) => {
5257
5552
  EOrderStatus2["PENDING"] = "PENDING";
@@ -5310,6 +5605,9 @@ var EFulfillmentStatus = /* @__PURE__ */ ((EFulfillmentStatus2) => {
5310
5605
 
5311
5606
  // src/static-params/index.ts
5312
5607
  var log = logger.child({ module: "static-params" });
5608
+ function skipBuildStaticParams() {
5609
+ return process.env.SKIP_BUILD_STATIC_PARAMS === "true";
5610
+ }
5313
5611
  async function withConcurrency(thunks, limit) {
5314
5612
  const results = new Array(thunks.length);
5315
5613
  let next = 0;
@@ -5356,6 +5654,7 @@ async function traverseCollectionProducts(client, collectionsLimit, productsPerC
5356
5654
  }
5357
5655
  function createCollectionStaticParams(getClient, options) {
5358
5656
  return async function generateStaticParams() {
5657
+ if (skipBuildStaticParams()) return [];
5359
5658
  const limit = options?.limit ?? 250;
5360
5659
  try {
5361
5660
  const result = await getClient().getCollections({ first: limit });
@@ -5375,6 +5674,7 @@ function createCollectionStaticParams(getClient, options) {
5375
5674
  }
5376
5675
  function createProductStaticParams(getClient, options) {
5377
5676
  return async function generateStaticParams() {
5677
+ if (skipBuildStaticParams()) return [];
5378
5678
  const limit = options?.limit ?? 250;
5379
5679
  try {
5380
5680
  const result = await getClient().getProducts({ first: limit });
@@ -5394,6 +5694,7 @@ function createProductStaticParams(getClient, options) {
5394
5694
  }
5395
5695
  function createProductViaCollectionsStaticParams(getClient, options) {
5396
5696
  return async function generateStaticParams() {
5697
+ if (skipBuildStaticParams()) return [];
5397
5698
  try {
5398
5699
  const pairs = await traverseCollectionProducts(
5399
5700
  getClient(),
@@ -5415,6 +5716,7 @@ function createProductViaCollectionsStaticParams(getClient, options) {
5415
5716
  }
5416
5717
  function createCollectionProductStaticParams(getClient, options) {
5417
5718
  return async function generateStaticParams() {
5719
+ if (skipBuildStaticParams()) return [];
5418
5720
  try {
5419
5721
  const pairs = await traverseCollectionProducts(
5420
5722
  getClient(),
@@ -5454,6 +5756,8 @@ exports.createCustomClient = createCustomClient;
5454
5756
  exports.createProductStaticParams = createProductStaticParams;
5455
5757
  exports.createProductViaCollectionsStaticParams = createProductViaCollectionsStaticParams;
5456
5758
  exports.createShopifyClient = createShopifyClient;
5759
+ exports.getShopperIp = getShopperIp;
5457
5760
  exports.resolveRequestSignal = resolveRequestSignal;
5761
+ exports.shopperForwardHeaders = shopperForwardHeaders;
5458
5762
  //# sourceMappingURL=index.js.map
5459
5763
  //# sourceMappingURL=index.js.map