@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/README.md +31 -0
- package/dist/adapters/index.js +1 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +1 -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 +27 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -2
- package/dist/index.mjs.map +1 -1
- package/dist/models/index.d.mts +4 -4
- package/dist/models/index.d.ts +4 -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/README.md
CHANGED
|
@@ -5,6 +5,7 @@ A comprehensive, production-ready data layer package for e-commerce applications
|
|
|
5
5
|
## Table of Contents
|
|
6
6
|
|
|
7
7
|
- [Features](#features)
|
|
8
|
+
- [API Gateway Rate Limits](#api-gateway-rate-limits-shopper-ip)
|
|
8
9
|
- [Installation](#installation)
|
|
9
10
|
- [Quick Start](#quick-start)
|
|
10
11
|
- [Configuration](#configuration)
|
|
@@ -80,6 +81,36 @@ export const generateStaticParams = createCollectionProductStaticParams(
|
|
|
80
81
|
);
|
|
81
82
|
```
|
|
82
83
|
|
|
84
|
+
**Skipping build-time prerendering.** Set `SKIP_BUILD_STATIC_PARAMS=true` at build time and every
|
|
85
|
+
factory returns `[]` without calling the API; pages render on their first request instead
|
|
86
|
+
(`dynamicParams`). Use it when the API gateway rate-limits the build host: a 429 fails a page render
|
|
87
|
+
(so ISR keeps the last good page), which would otherwise fail a large build.
|
|
88
|
+
|
|
89
|
+
## API Gateway Rate Limits (shopper IP)
|
|
90
|
+
|
|
91
|
+
The OS API gateway rate-limits per shopper IP and per merchant (`gk-merchant-id`, which the custom
|
|
92
|
+
adapter already sends). A call a storefront server makes **for a shopper** must say who the shopper is,
|
|
93
|
+
or every shopper looks like one client:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { shopperForwardHeaders } from "@shopkit/data-layer";
|
|
97
|
+
|
|
98
|
+
// In an uncached route handler, e.g. a search proxy:
|
|
99
|
+
const res = await fetch(url, {
|
|
100
|
+
cache: "no-store",
|
|
101
|
+
headers: { "gk-merchant-id": merchantId, ...shopperForwardHeaders(request) },
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
- `getShopperIp(headers, { trustedHops })` reads the **right-most** `x-forwarded-for` entry — the one our
|
|
106
|
+
load balancer appends (`trustedHops`, default 1). Entries to its left and `cf-connecting-ip` /
|
|
107
|
+
`true-client-ip` / `x-real-ip` come from the shopper and are ignored. A client port is stripped.
|
|
108
|
+
- `shopperForwardHeaders(request)` returns `{ "x-forwarded-for": ip }`, or `{}` when no IP resolves.
|
|
109
|
+
- **Uncached fetches only.** Next.js keys its fetch cache on request headers, so a per-shopper header on a
|
|
110
|
+
cached fetch (`next: { revalidate, tags }`) stores one entry per IP. ISR renders send no shopper IP.
|
|
111
|
+
- A gateway 429 counts as "backend unavailable", like a 5xx: `getProduct` / `getCollection` return
|
|
112
|
+
`success: false` rather than "not found", so a page can keep its last good copy.
|
|
113
|
+
|
|
83
114
|
## Installation
|
|
84
115
|
|
|
85
116
|
```bash
|
package/dist/adapters/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;
|