@shopkit/data-layer 1.6.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/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;
@@ -5250,6 +5250,23 @@ function createCommerceClient(clientConfig) {
5250
5250
  }
5251
5251
  }
5252
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
+
5253
5270
  // src/models/enums.ts
5254
5271
  var EOrderStatus = /* @__PURE__ */ ((EOrderStatus2) => {
5255
5272
  EOrderStatus2["PENDING"] = "PENDING";
@@ -5308,6 +5325,9 @@ var EFulfillmentStatus = /* @__PURE__ */ ((EFulfillmentStatus2) => {
5308
5325
 
5309
5326
  // src/static-params/index.ts
5310
5327
  var log = logger.child({ module: "static-params" });
5328
+ function skipBuildStaticParams() {
5329
+ return process.env.SKIP_BUILD_STATIC_PARAMS === "true";
5330
+ }
5311
5331
  async function withConcurrency(thunks, limit) {
5312
5332
  const results = new Array(thunks.length);
5313
5333
  let next = 0;
@@ -5354,6 +5374,7 @@ async function traverseCollectionProducts(client, collectionsLimit, productsPerC
5354
5374
  }
5355
5375
  function createCollectionStaticParams(getClient, options) {
5356
5376
  return async function generateStaticParams() {
5377
+ if (skipBuildStaticParams()) return [];
5357
5378
  const limit = options?.limit ?? 250;
5358
5379
  try {
5359
5380
  const result = await getClient().getCollections({ first: limit });
@@ -5373,6 +5394,7 @@ function createCollectionStaticParams(getClient, options) {
5373
5394
  }
5374
5395
  function createProductStaticParams(getClient, options) {
5375
5396
  return async function generateStaticParams() {
5397
+ if (skipBuildStaticParams()) return [];
5376
5398
  const limit = options?.limit ?? 250;
5377
5399
  try {
5378
5400
  const result = await getClient().getProducts({ first: limit });
@@ -5392,6 +5414,7 @@ function createProductStaticParams(getClient, options) {
5392
5414
  }
5393
5415
  function createProductViaCollectionsStaticParams(getClient, options) {
5394
5416
  return async function generateStaticParams() {
5417
+ if (skipBuildStaticParams()) return [];
5395
5418
  try {
5396
5419
  const pairs = await traverseCollectionProducts(
5397
5420
  getClient(),
@@ -5413,6 +5436,7 @@ function createProductViaCollectionsStaticParams(getClient, options) {
5413
5436
  }
5414
5437
  function createCollectionProductStaticParams(getClient, options) {
5415
5438
  return async function generateStaticParams() {
5439
+ if (skipBuildStaticParams()) return [];
5416
5440
  try {
5417
5441
  const pairs = await traverseCollectionProducts(
5418
5442
  getClient(),
@@ -5437,6 +5461,6 @@ function createCollectionProductStaticParams(getClient, options) {
5437
5461
  };
5438
5462
  }
5439
5463
 
5440
- 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 };
5441
5465
  //# sourceMappingURL=index.mjs.map
5442
5466
  //# sourceMappingURL=index.mjs.map