@vitrine-kit/core 0.2.2 → 0.3.1
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.ts +17 -2
- package/dist/index.js +24 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { S as SlotRegistry, c as createSlotRegistry, g as getSlotMounts, r as registerSlot, s as slotRegistry } from './registry-CfORxf9H.js';
|
|
2
2
|
import { Backend, SiteConfig, CatalogSource, CommerceBackend, Cart, Order, Money, CurrencyCode, OrderStatus } from '@vitrine-kit/contracts';
|
|
3
3
|
|
|
4
|
-
declare const CORE_VERSION: "0.
|
|
4
|
+
declare const CORE_VERSION: "0.3.1";
|
|
5
5
|
|
|
6
6
|
interface AdapterFactory {
|
|
7
7
|
backend: Backend;
|
|
@@ -143,4 +143,19 @@ interface BuildOrderOptions {
|
|
|
143
143
|
/** Snapshots the cart into an order (after payment). Totals come from the cart — not recomputed. */
|
|
144
144
|
declare function buildOrderFromCart(cart: Cart, opts: BuildOrderOptions): Order;
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
interface RateLimitOptions {
|
|
147
|
+
/** Max requests allowed within the window. */
|
|
148
|
+
limit: number;
|
|
149
|
+
/** Window size in milliseconds. */
|
|
150
|
+
windowMs: number;
|
|
151
|
+
}
|
|
152
|
+
interface RateLimitResult {
|
|
153
|
+
allowed: boolean;
|
|
154
|
+
/** Milliseconds until the caller may retry — present only when !allowed. */
|
|
155
|
+
retryAfterMs?: number;
|
|
156
|
+
}
|
|
157
|
+
declare function checkRateLimit(key: string, { limit, windowMs }: RateLimitOptions): RateLimitResult;
|
|
158
|
+
/** Best-effort client IP from standard proxy headers (Web Fetch API `Headers`). */
|
|
159
|
+
declare function clientIpFromHeaders(headers: Headers): string;
|
|
160
|
+
|
|
161
|
+
export { type AdapterFactory, type AdapterRegistry, type BuildOrderOptions, CORE_VERSION, type CreateCheckoutArgs, type NewLineInput, type NormalizedPaymentEvent, type OrderCreationGuard, type OrderPipelineContext, type OrderStage, type PaymentProvider, type PaymentProviderName, type PaymentRegistry, type PaymentWebhookHandlers, type PaymentWebhookRequest, type PaymentWebhookResult, type RateLimitOptions, type RateLimitResult, adapters, addCartLine, buildOrderFromCart, cartItemCount, checkRateLimit, clientIpFromHeaders, computeLineTotal, createAdapterRegistry, createPaymentRegistry, emptyCart, handlePaymentWebhook, payments, recalcCart, removeCartLine, runPipeline, setCartLineQty, shouldCreateOrder };
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "./chunk-BQVNYHVU.js";
|
|
7
7
|
|
|
8
8
|
// src/version.generated.ts
|
|
9
|
-
var CORE_VERSION = "0.
|
|
9
|
+
var CORE_VERSION = "0.3.1";
|
|
10
10
|
|
|
11
11
|
// src/adapter/resolver.ts
|
|
12
12
|
function createAdapterRegistry() {
|
|
@@ -186,12 +186,35 @@ function buildOrderFromCart(cart, opts) {
|
|
|
186
186
|
createdAt: opts.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
|
+
|
|
190
|
+
// src/security/rate-limit.ts
|
|
191
|
+
var buckets = /* @__PURE__ */ new Map();
|
|
192
|
+
function checkRateLimit(key, { limit, windowMs }) {
|
|
193
|
+
const now = Date.now();
|
|
194
|
+
const bucket = buckets.get(key);
|
|
195
|
+
if (!bucket || bucket.resetAt <= now) {
|
|
196
|
+
buckets.set(key, { count: 1, resetAt: now + windowMs });
|
|
197
|
+
return { allowed: true };
|
|
198
|
+
}
|
|
199
|
+
if (bucket.count >= limit) {
|
|
200
|
+
return { allowed: false, retryAfterMs: bucket.resetAt - now };
|
|
201
|
+
}
|
|
202
|
+
bucket.count += 1;
|
|
203
|
+
return { allowed: true };
|
|
204
|
+
}
|
|
205
|
+
function clientIpFromHeaders(headers) {
|
|
206
|
+
const forwarded = headers.get("x-forwarded-for");
|
|
207
|
+
const first = forwarded?.split(",")[0]?.trim();
|
|
208
|
+
return first || headers.get("x-real-ip") || "unknown";
|
|
209
|
+
}
|
|
189
210
|
export {
|
|
190
211
|
CORE_VERSION,
|
|
191
212
|
adapters,
|
|
192
213
|
addCartLine,
|
|
193
214
|
buildOrderFromCart,
|
|
194
215
|
cartItemCount,
|
|
216
|
+
checkRateLimit,
|
|
217
|
+
clientIpFromHeaders,
|
|
195
218
|
computeLineTotal,
|
|
196
219
|
createAdapterRegistry,
|
|
197
220
|
createPaymentRegistry,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitrine-kit/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Vitrine core — slot/adapter runtime, order pipeline, provider-neutral payment webhook dispatch. Critical logic (a bug = an incident for everyone).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"directory": "packages/core"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@vitrine-kit/contracts": "1.2.
|
|
36
|
+
"@vitrine-kit/contracts": "1.2.2"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"react": ">=18.0.0"
|