@vite-hub/rate-limit 0.5.0 → 0.6.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/{cli-ITt8egpW.d.ts → cli-B77bo6ii.d.ts} +0 -6
- package/dist/cli.d.ts +2 -4
- package/dist/cli.js +5 -6
- package/dist/{cloudflare-_Tz3DcpB.js → cloudflare-CWK4wJ9b.js} +4 -7
- package/dist/{counters-d8FaLiE1.d.ts → counters-BCNUEaDn.d.ts} +1 -3
- package/dist/{counters-CwyRigdy.js → counters-dyc0Q_HL.js} +3 -4
- package/dist/{dev-peer-CHafxbtj.js → dev-peer-D0vOxmrD.js} +1 -2
- package/dist/drivers/cloudflare.d.ts +2 -6
- package/dist/drivers/cloudflare.js +1 -2
- package/dist/drivers/kv.d.ts +1 -1
- package/dist/drivers/kv.js +2 -3
- package/dist/drivers/memory.d.ts +2 -4
- package/dist/drivers/memory.js +2 -3
- package/dist/durability.d.ts +1 -3
- package/dist/durability.js +1 -2
- package/dist/{error-diagnostics-DRuEG4wu.js → error-diagnostics-ulOX0clN.js} +1 -2
- package/dist/index.d.ts +2 -6
- package/dist/index.js +9 -12
- package/dist/{inspect-B6gTdgy9.js → inspect-Dqvi9vUt.js} +2 -4
- package/dist/{kv-NA_0qogC.d.ts → kv-DldoJary.d.ts} +1 -3
- package/dist/{kv-provider-DlgNQC-o.js → kv-provider-DAq-42o6.js} +4 -6
- package/dist/{operation-definition-CI2PJGqu.d.ts → operation-definition-CqZkx1Rm.d.ts} +0 -4
- package/dist/{operations-C6npllas.js → operations-BZsu-Ssx.js} +23 -25
- package/dist/{operations-DcgGebib.js → operations-BuAYwMe4.js} +4 -5
- package/dist/operations.d.ts +2 -6
- package/dist/operations.js +7 -11
- package/dist/{policy-BeyQ0vnc.js → policy-CMsNKnqo.js} +2 -3
- package/dist/runtime.d.ts +2 -4
- package/dist/runtime.js +1 -2
- package/dist/{state-D0GPlkS7.js → state-BXD6-GFo.js} +4 -5
- package/dist/{types-OzukEqHf.d.ts → types-Bw8vrrVF.d.ts} +0 -2
- package/dist/vite.d.ts +4 -16
- package/dist/vite.js +28 -40
- package/package.json +7 -7
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Diagnostic } from "nostics";
|
|
2
|
-
//#region ../internal/src/host-credentials.d.ts
|
|
3
2
|
interface HostCliRunResult {
|
|
4
3
|
exitCode: number | null;
|
|
5
4
|
stdout: string;
|
|
@@ -11,8 +10,6 @@ type HostCliRun = (command: string, args: readonly string[], options: {
|
|
|
11
10
|
env: NodeJS.ProcessEnv;
|
|
12
11
|
signal?: AbortSignal;
|
|
13
12
|
}) => Promise<HostCliRunResult>;
|
|
14
|
-
//#endregion
|
|
15
|
-
//#region ../internal/src/provision.d.ts
|
|
16
13
|
type ProvisionProvider = "cloudflare" | "vercel";
|
|
17
14
|
interface ProvisionLogger {
|
|
18
15
|
log: (message: string) => void;
|
|
@@ -64,8 +61,6 @@ interface ProvisionStep {
|
|
|
64
61
|
/** Describes the Provision State this step records. Runs without network access, also without credentials. */
|
|
65
62
|
recordedState?: (context: Pick<ProvisionContext, "env">) => ProvisionStateCategory[];
|
|
66
63
|
}
|
|
67
|
-
//#endregion
|
|
68
|
-
//#region ../internal/src/cli.d.ts
|
|
69
64
|
interface ViteHubCliStreams {
|
|
70
65
|
stderr: {
|
|
71
66
|
write: (chunk: string | Uint8Array, encoding?: BufferEncoding | StdoutWriteCallback, callback?: StdoutWriteCallback) => unknown;
|
|
@@ -160,5 +155,4 @@ interface ViteHubCliPluginMetadata {
|
|
|
160
155
|
cli?: ViteHubCliContributor | ViteHubCliContributorFactory;
|
|
161
156
|
}
|
|
162
157
|
type StdoutWriteCallback = (error?: Error | null) => void;
|
|
163
|
-
//#endregion
|
|
164
158
|
export { ViteHubCliStreams as i, ViteHubCliContributor as n, ViteHubCliPluginMetadata as r, ViteHubCliContext as t };
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { i as ViteHubCliStreams, n as ViteHubCliContributor, t as ViteHubCliContext } from "./cli-
|
|
2
|
-
//#region src/cli.d.ts
|
|
1
|
+
import { i as ViteHubCliStreams, n as ViteHubCliContributor, t as ViteHubCliContext } from "./cli-B77bo6ii.js";
|
|
3
2
|
export type RateLimitCliContext = Pick<ViteHubCliContext, "cwd" | "env" | "fetch" | "rootDir"> & ViteHubCliStreams;
|
|
4
3
|
export interface RateLimitCliOptions {
|
|
5
4
|
/** Asks whether `reset` may delete a counter. Defaults to a prompt on a terminal, and refuses without one. */
|
|
@@ -12,5 +11,4 @@ export interface RateLimitCliOptions {
|
|
|
12
11
|
* `args[0]` is the command name, `peek` or `reset`.
|
|
13
12
|
*/
|
|
14
13
|
export declare function runRateLimitCli(args: string[], context: RateLimitCliContext, options?: RateLimitCliOptions): Promise<number>;
|
|
15
|
-
export declare function createRateLimitCliContributor(options?: RateLimitCliOptions): ViteHubCliContributor;
|
|
16
|
-
//#endregion
|
|
14
|
+
export declare function createRateLimitCliContributor(options?: RateLimitCliOptions): ViteHubCliContributor;
|
package/dist/cli.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as
|
|
4
|
-
import {
|
|
1
|
+
import { A as writeCliFailure, E as askOnTerminal, O as readViteHubDevTargetOption, n as callOperationFromCli, u as table } from "./operations-BZsu-Ssx.js";
|
|
2
|
+
import { t as redactInspectionText } from "./inspect-Dqvi9vUt.js";
|
|
3
|
+
import { t as rateLimitErrorDiagnostics } from "./error-diagnostics-ulOX0clN.js";
|
|
4
|
+
import { r as parseRateLimitWindow } from "./policy-CMsNKnqo.js";
|
|
5
5
|
import * as v from "valibot";
|
|
6
|
-
|
|
6
|
+
// src/cli.ts
|
|
7
7
|
const rateLimitDevTargetErrors = {
|
|
8
8
|
invalidInlineTimeout: (message) => rateLimitErrorDiagnostics.RATE_LIMIT_R0041({ message }),
|
|
9
9
|
invalidTimeout: (message) => rateLimitErrorDiagnostics.RATE_LIMIT_R0041({ message }),
|
|
@@ -264,5 +264,4 @@ function createRateLimitCliContributor(options = {}) {
|
|
|
264
264
|
name: "rate-limit"
|
|
265
265
|
}] };
|
|
266
266
|
}
|
|
267
|
-
//#endregion
|
|
268
267
|
export { createRateLimitCliContributor, runRateLimitCli };
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { t as rateLimitErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { t as rateLimitErrorDiagnostics } from "./error-diagnostics-ulOX0clN.js";
|
|
2
2
|
import { toResultError } from "@vite-hub/runtime";
|
|
3
|
-
|
|
3
|
+
// ../internal/src/integrations/hex.ts
|
|
4
4
|
const textEncoder = new TextEncoder();
|
|
5
5
|
new TextDecoder();
|
|
6
6
|
function encodeNameHex(name) {
|
|
7
7
|
return [...textEncoder.encode(name)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
//#region src/integrations/cloudflare.ts
|
|
9
|
+
// src/integrations/cloudflare.ts
|
|
11
10
|
const bindingPrefix = "RATE_LIMIT";
|
|
12
11
|
function getCloudflareRateLimitBindingName(name) {
|
|
13
12
|
const encoded = encodeNameHex(name).toUpperCase();
|
|
@@ -20,8 +19,7 @@ function getCloudflareRateLimitBindingName(name) {
|
|
|
20
19
|
function isCloudflareRateLimitWindow(windowMs) {
|
|
21
20
|
return windowMs === 1e4 || windowMs === 6e4;
|
|
22
21
|
}
|
|
23
|
-
|
|
24
|
-
//#region src/drivers/cloudflare.ts
|
|
22
|
+
// src/drivers/cloudflare.ts
|
|
25
23
|
function isBinding(value) {
|
|
26
24
|
return Boolean(value) && typeof value === "object" && typeof value.limit === "function";
|
|
27
25
|
}
|
|
@@ -50,5 +48,4 @@ function cloudflareRateLimitDriver(options) {
|
|
|
50
48
|
name: "cloudflare"
|
|
51
49
|
};
|
|
52
50
|
}
|
|
53
|
-
//#endregion
|
|
54
51
|
export { getCloudflareRateLimitBindingName as n, isCloudflareRateLimitWindow as r, cloudflareRateLimitDriver as t };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { O as RateLimitRuntimeConfig, a as RateLimitCounterScope } from "./types-
|
|
1
|
+
import { O as RateLimitRuntimeConfig, a as RateLimitCounterScope } from "./types-Bw8vrrVF.js";
|
|
2
2
|
import { Duration } from "@vite-hub/runtime";
|
|
3
|
-
//#region src/counters.d.ts
|
|
4
3
|
type RateLimitRuntimeDriver = RateLimitRuntimeConfig["driver"];
|
|
5
4
|
/** Counter of one key for one policy. `peekRateLimit()` reads it without consuming a token. */
|
|
6
5
|
interface RateLimitCounterSnapshot {
|
|
@@ -44,5 +43,4 @@ declare function peekRateLimit(name: string, key: string): Promise<RateLimitPeek
|
|
|
44
43
|
* `reset`. The result reports `unsupported` when the configured provider cannot reset counters.
|
|
45
44
|
*/
|
|
46
45
|
declare function resetRateLimit(name: string, key: string): Promise<RateLimitResetInspection>;
|
|
47
|
-
//#endregion
|
|
48
46
|
export { resetRateLimit as a, peekRateLimit as i, RateLimitPeekInspection as n, RateLimitResetInspection as r, RateLimitCounterSnapshot as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as rateLimitErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
-
import { i as resolveRateLimitDriver, r as listRuntimeRateLimiters } from "./state-
|
|
1
|
+
import { t as rateLimitErrorDiagnostics } from "./error-diagnostics-ulOX0clN.js";
|
|
2
|
+
import { i as resolveRateLimitDriver, r as listRuntimeRateLimiters } from "./state-BXD6-GFo.js";
|
|
3
3
|
import * as v from "valibot";
|
|
4
|
-
|
|
4
|
+
// src/counters.ts
|
|
5
5
|
const cloudflareRateLimitCounterUnsupportedReason = "The Cloudflare Rate Limiting binding exposes only limit(), which consumes a token. It cannot read or reset a counter.";
|
|
6
6
|
const unusedReason = "No request used this Rate Limit in this process since it started, so no counter exists.";
|
|
7
7
|
const unusedKVReason = "No request used this Rate Limit in this process since it started, so this process does not know its window. Other processes can still have a counter.";
|
|
@@ -108,5 +108,4 @@ async function resetRateLimit(name, key) {
|
|
|
108
108
|
status: "reset"
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
|
-
//#endregion
|
|
112
111
|
export { resetRateLimit as n, peekRateLimit as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// ../internal/src/dev-peer.ts
|
|
2
2
|
/**
|
|
3
3
|
* Proof that a development request came from this machine, for dev servers that run the app behind a proxy.
|
|
4
4
|
*
|
|
@@ -234,5 +234,4 @@ function addViteHubDevPeerDevHandler(devHandlers) {
|
|
|
234
234
|
devHandlers.unshift({ handler: devHandler });
|
|
235
235
|
}
|
|
236
236
|
readViteHubDevPeerKey();
|
|
237
|
-
//#endregion
|
|
238
237
|
export { isViteHubLoopbackPeer as n, addViteHubDevPeerDevHandler as t };
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { c as RateLimitDriver } from "../types-
|
|
2
|
-
//#region src/integrations/cloudflare.d.ts
|
|
1
|
+
import { c as RateLimitDriver } from "../types-Bw8vrrVF.js";
|
|
3
2
|
export declare function getCloudflareRateLimitBindingName(name: string): string;
|
|
4
|
-
//#endregion
|
|
5
|
-
//#region src/drivers/cloudflare.d.ts
|
|
6
3
|
export interface CloudflareRateLimitBinding {
|
|
7
4
|
limit(input: {
|
|
8
5
|
key: string;
|
|
@@ -13,5 +10,4 @@ export interface CloudflareRateLimitBinding {
|
|
|
13
10
|
export interface CloudflareRateLimitDriverOptions {
|
|
14
11
|
binding: CloudflareRateLimitBinding;
|
|
15
12
|
}
|
|
16
|
-
export declare function cloudflareRateLimitDriver(options: CloudflareRateLimitDriverOptions): RateLimitDriver;
|
|
17
|
-
//#endregion
|
|
13
|
+
export declare function cloudflareRateLimitDriver(options: CloudflareRateLimitDriverOptions): RateLimitDriver;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { cloudflareRateLimitDriver, getCloudflareRateLimitBindingName };
|
|
1
|
+
export { t as cloudflareRateLimitDriver, n as getCloudflareRateLimitBindingName } from "../cloudflare-CWK4wJ9b.js";
|
package/dist/drivers/kv.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as kvRateLimitDriver, n as KVRateLimitDriverOptions, r as RateLimitKVStorage, t as KVRateLimitDriver } from "../kv-
|
|
1
|
+
import { i as kvRateLimitDriver, n as KVRateLimitDriverOptions, r as RateLimitKVStorage, t as KVRateLimitDriver } from "../kv-DldoJary.js";
|
|
2
2
|
export { KVRateLimitDriver, KVRateLimitDriverOptions, RateLimitKVStorage, kvRateLimitDriver };
|
package/dist/drivers/kv.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as rateLimitErrorDiagnostics } from "../error-diagnostics-
|
|
1
|
+
import { t as rateLimitErrorDiagnostics } from "../error-diagnostics-ulOX0clN.js";
|
|
2
2
|
import { toResultError } from "@vite-hub/runtime";
|
|
3
|
-
|
|
3
|
+
// src/drivers/kv.ts
|
|
4
4
|
function isStorage(value) {
|
|
5
5
|
if (!value || typeof value !== "object") return false;
|
|
6
6
|
return typeof Reflect.get(value, "increment") === "function" && typeof Reflect.get(value, "get") === "function";
|
|
@@ -118,5 +118,4 @@ function kvRateLimitDriver(options) {
|
|
|
118
118
|
}
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
|
-
//#endregion
|
|
122
121
|
export { kvRateLimitDriver };
|
package/dist/drivers/memory.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { c as RateLimitDriver } from "../types-
|
|
2
|
-
//#region src/drivers/memory.d.ts
|
|
1
|
+
import { c as RateLimitDriver } from "../types-Bw8vrrVF.js";
|
|
3
2
|
export interface MemoryRateLimitDriverOptions {
|
|
4
3
|
maxEntries?: number;
|
|
5
4
|
now?: () => number;
|
|
@@ -11,5 +10,4 @@ export interface MemoryRateLimitDriver extends RateLimitDriver {
|
|
|
11
10
|
reset: NonNullable<RateLimitDriver["reset"]>;
|
|
12
11
|
size: () => number;
|
|
13
12
|
}
|
|
14
|
-
export declare function memoryRateLimitDriver(options?: MemoryRateLimitDriverOptions): MemoryRateLimitDriver;
|
|
15
|
-
//#endregion
|
|
13
|
+
export declare function memoryRateLimitDriver(options?: MemoryRateLimitDriverOptions): MemoryRateLimitDriver;
|
package/dist/drivers/memory.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as rateLimitErrorDiagnostics } from "../error-diagnostics-
|
|
2
|
-
|
|
1
|
+
import { t as rateLimitErrorDiagnostics } from "../error-diagnostics-ulOX0clN.js";
|
|
2
|
+
// src/drivers/memory.ts
|
|
3
3
|
const defaultMaxEntries = 1e5;
|
|
4
4
|
function entryKey(input) {
|
|
5
5
|
return JSON.stringify([
|
|
@@ -88,5 +88,4 @@ function memoryRateLimitDriver(options = {}) {
|
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
-
//#endregion
|
|
92
91
|
export { memoryRateLimitDriver };
|
package/dist/durability.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Durability, DurabilityContext } from "@vite-hub/runtime/durability";
|
|
2
|
-
//#region src/durability.d.ts
|
|
3
2
|
/** What the build passes to `rateLimitDurability()`. */
|
|
4
3
|
export interface RateLimitDurabilityInput {
|
|
5
4
|
driver: string;
|
|
@@ -8,5 +7,4 @@ export interface RateLimitDurabilityInput {
|
|
|
8
7
|
* The durability of Rate Limit counters, from the driver. The `kv` driver counts in the default KV store when that
|
|
9
8
|
* store is a database, Redis, or Upstash store, and falls back to memory otherwise.
|
|
10
9
|
*/
|
|
11
|
-
export declare function rateLimitDurability(input: RateLimitDurabilityInput, context: DurabilityContext): Durability[];
|
|
12
|
-
//#endregion
|
|
10
|
+
export declare function rateLimitDurability(input: RateLimitDurabilityInput, context: DurabilityContext): Durability[];
|
package/dist/durability.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/durability.ts
|
|
2
2
|
const memory = {
|
|
3
3
|
primitive: "rate-limit",
|
|
4
4
|
store: "memory",
|
|
@@ -31,5 +31,4 @@ function rateLimitDurability(input, context) {
|
|
|
31
31
|
...kv.fix ? { fix: kv.fix } : {}
|
|
32
32
|
}];
|
|
33
33
|
}
|
|
34
|
-
//#endregion
|
|
35
34
|
export { rateLimitDurability };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineDiagnostics } from "nostics";
|
|
2
|
-
|
|
2
|
+
// src/error-diagnostics.ts
|
|
3
3
|
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
4
4
|
const rateLimitErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
5
5
|
docsBase: "https://vitehub.dev/docs/rate-limit/diagnostics",
|
|
@@ -234,5 +234,4 @@ const rateLimitErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
});
|
|
237
|
-
//#endregion
|
|
238
237
|
export { rateLimitErrorDiagnostics as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { A as RefundRateLimitErrorCode, C as RateLimitRefundResult, D as RateLimitResetResult, E as RateLimitRequestEvent, M as ResolvedRateLimitPolicy, O as RateLimitRuntimeConfig, S as RateLimitPolicy, T as RateLimitRequest, _ as RateLimitDriverResult, a as RateLimitCounterScope, b as RateLimitOptions, c as RateLimitDriver, d as RateLimitDriverName, f as RateLimitDriverOutcome, g as RateLimitDriverResetOutcome, h as RateLimitDriverRefundOutcome, i as RateLimitConsumeInput, j as RequireRateLimitOptions, k as RateLimiter, l as RateLimitDriverCapabilities, m as RateLimitDriverPeekResult, n as CheckRateLimitOptions, o as RateLimitDecision, p as RateLimitDriverPeekOutcome, r as CreateRateLimiterOptions, s as RateLimitDeclaration, t as CheckRateLimitErrorCode, u as RateLimitDriverInput, v as RateLimitEnforcement, w as RateLimitRejectedAttemptBehavior, x as RateLimitPeekResult, y as RateLimitFailurePolicy } from "./types-
|
|
2
|
-
import { a as resetRateLimit, i as peekRateLimit, n as RateLimitPeekInspection, r as RateLimitResetInspection, t as RateLimitCounterSnapshot } from "./counters-
|
|
1
|
+
import { A as RefundRateLimitErrorCode, C as RateLimitRefundResult, D as RateLimitResetResult, E as RateLimitRequestEvent, M as ResolvedRateLimitPolicy, O as RateLimitRuntimeConfig, S as RateLimitPolicy, T as RateLimitRequest, _ as RateLimitDriverResult, a as RateLimitCounterScope, b as RateLimitOptions, c as RateLimitDriver, d as RateLimitDriverName, f as RateLimitDriverOutcome, g as RateLimitDriverResetOutcome, h as RateLimitDriverRefundOutcome, i as RateLimitConsumeInput, j as RequireRateLimitOptions, k as RateLimiter, l as RateLimitDriverCapabilities, m as RateLimitDriverPeekResult, n as CheckRateLimitOptions, o as RateLimitDecision, p as RateLimitDriverPeekOutcome, r as CreateRateLimiterOptions, s as RateLimitDeclaration, t as CheckRateLimitErrorCode, u as RateLimitDriverInput, v as RateLimitEnforcement, w as RateLimitRejectedAttemptBehavior, x as RateLimitPeekResult, y as RateLimitFailurePolicy } from "./types-Bw8vrrVF.js";
|
|
2
|
+
import { a as resetRateLimit, i as peekRateLimit, n as RateLimitPeekInspection, r as RateLimitResetInspection, t as RateLimitCounterSnapshot } from "./counters-BCNUEaDn.js";
|
|
3
3
|
import { Result } from "@vite-hub/runtime";
|
|
4
|
-
//#region src/limiter.d.ts
|
|
5
4
|
export declare function createRateLimiter(options: CreateRateLimiterOptions): RateLimiter;
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region src/guard.d.ts
|
|
8
5
|
/**
|
|
9
6
|
* Consumes one request from a managed Rate Limit and returns `[error, decision]`. Use it when a limited request still
|
|
10
7
|
* gets an answer, such as a cheaper fallback. `decision.reason` is `limited` or `unavailable` when not allowed.
|
|
@@ -27,5 +24,4 @@ export declare function refundRateLimit(event: RateLimitRequestEvent, name: stri
|
|
|
27
24
|
* `checkRateLimit()` returns.
|
|
28
25
|
*/
|
|
29
26
|
export declare function requireRateLimit(event: RateLimitRequestEvent, name: string, options: RequireRateLimitOptions): Promise<void>;
|
|
30
|
-
//#endregion
|
|
31
27
|
export { type CheckRateLimitErrorCode, type CheckRateLimitOptions, type CreateRateLimiterOptions, type RateLimitConsumeInput, type RateLimitCounterScope, type RateLimitCounterSnapshot, type RateLimitDecision, type RateLimitDeclaration, type RateLimitDriver, type RateLimitDriverCapabilities, type RateLimitDriverInput, type RateLimitDriverName, type RateLimitDriverOutcome, type RateLimitDriverPeekOutcome, type RateLimitDriverPeekResult, type RateLimitDriverRefundOutcome, type RateLimitDriverResetOutcome, type RateLimitDriverResult, type RateLimitEnforcement, type RateLimitFailurePolicy, type RateLimitOptions, type RateLimitPeekInspection, type RateLimitPeekResult, type RateLimitPolicy, type RateLimitRefundResult, type RateLimitRejectedAttemptBehavior, type RateLimitRequest, type RateLimitRequestEvent, type RateLimitResetInspection, type RateLimitResetResult, type RateLimitRuntimeConfig, type RateLimiter, type RefundRateLimitErrorCode, type RequireRateLimitOptions, type ResolvedRateLimitPolicy, peekRateLimit, resetRateLimit };
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { n as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { n as createRateLimiter } from "./kv-provider-DAq-42o6.js";
|
|
2
|
+
import { n as resetRateLimit, t as peekRateLimit } from "./counters-dyc0Q_HL.js";
|
|
3
|
+
import { n as getCloudflareRateLimitBindingName, r as isCloudflareRateLimitWindow, t as cloudflareRateLimitDriver } from "./cloudflare-CWK4wJ9b.js";
|
|
4
|
+
import { a as rateLimitPolicyKeys, n as normalizeRateLimitPolicy, t as declaredRateLimitPolicy } from "./policy-CMsNKnqo.js";
|
|
5
|
+
import { i as resolveRateLimitDriver, n as getRuntimeRateLimiter } from "./state-BXD6-GFo.js";
|
|
6
|
+
import { t as rateLimitErrorDiagnostics } from "./error-diagnostics-ulOX0clN.js";
|
|
7
7
|
import { toResultError } from "@vite-hub/runtime";
|
|
8
8
|
import { getViteHubTestMode } from "@vite-hub/runtime/internal/test-mode";
|
|
9
9
|
import { getStandardContext } from "@vite-hub/runtime/internal/h3";
|
|
10
10
|
import { createError } from "nitro/h3";
|
|
11
|
-
|
|
11
|
+
// ../internal/src/runtime/cloudflare-env-lookup.ts
|
|
12
12
|
/** The key of the AsyncLocalStorage store on `globalThis`. Every bundled copy of this module shares the store. */
|
|
13
13
|
const activeEnvStorageKey = Symbol.for("vitehub.cloudflare.env-storage");
|
|
14
14
|
let activeEnv;
|
|
@@ -22,8 +22,7 @@ function getActiveCloudflareEnv() {
|
|
|
22
22
|
const host = globalThis;
|
|
23
23
|
return Object.hasOwn(host, "__env__") && host.__env__ !== void 0 ? host.__env__ : activeEnv;
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
//#region ../internal/src/runtime/request-log.ts
|
|
25
|
+
// ../internal/src/runtime/request-log.ts
|
|
27
26
|
function isRequestLog(value) {
|
|
28
27
|
return value !== null && typeof value === "object" && typeof Reflect.get(value, "set") === "function" && typeof Reflect.get(value, "warn") === "function" && typeof Reflect.get(value, "error") === "function";
|
|
29
28
|
}
|
|
@@ -39,8 +38,7 @@ function requestLog(input) {
|
|
|
39
38
|
const log = contextLog(input !== null && typeof input === "object" ? Reflect.get(input, "req") : void 0) ?? contextLog(input);
|
|
40
39
|
return isRequestLog(log) ? log : void 0;
|
|
41
40
|
}
|
|
42
|
-
|
|
43
|
-
//#region src/guard.ts
|
|
41
|
+
// src/guard.ts
|
|
44
42
|
const guardOptionKeys = {
|
|
45
43
|
checkRateLimit: /* @__PURE__ */ new Set([...rateLimitPolicyKeys, "key"]),
|
|
46
44
|
refundRateLimit: /* @__PURE__ */ new Set([...rateLimitPolicyKeys, "key"]),
|
|
@@ -194,5 +192,4 @@ async function requireRateLimit(event, name, options) {
|
|
|
194
192
|
statusText: "Too Many Requests"
|
|
195
193
|
});
|
|
196
194
|
}
|
|
197
|
-
//#endregion
|
|
198
195
|
export { checkRateLimit, createRateLimiter, peekRateLimit, refundRateLimit, requireRateLimit, resetRateLimit };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
|
|
2
2
|
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
3
3
|
function normalizeWindowsPath(input = "") {
|
|
4
4
|
if (!input) return input;
|
|
@@ -95,8 +95,7 @@ const dirname = function(p) {
|
|
|
95
95
|
if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
|
|
96
96
|
return segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
|
97
97
|
};
|
|
98
|
-
|
|
99
|
-
//#region ../internal/src/inspect.ts
|
|
98
|
+
// ../internal/src/inspect.ts
|
|
100
99
|
function relativeDefinitionFile(projectRoot, file) {
|
|
101
100
|
return relative(projectRoot, file).replaceAll("\\", "/");
|
|
102
101
|
}
|
|
@@ -114,5 +113,4 @@ const embeddedSecretAssignmentPattern = new RegExp(String.raw`\b([\w-]*(?:${secr
|
|
|
114
113
|
function redactInspectionText(value) {
|
|
115
114
|
return value.replace(embeddedUrlCredentialPattern, `$1${redactedInspectionValue}@`).replace(embeddedAuthorizationPattern, `$1${redactedInspectionValue}`).replace(embeddedCookiePattern, `$1${redactedInspectionValue}`).replace(embeddedBearerPattern, `Bearer ${redactedInspectionValue}`).replace(embeddedSecretAssignmentPattern, `$1${redactedInspectionValue}`);
|
|
116
115
|
}
|
|
117
|
-
//#endregion
|
|
118
116
|
export { resolve as i, relativeDefinitionFile as n, dirname as r, redactInspectionText as t };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { c as RateLimitDriver } from "./types-
|
|
1
|
+
import { c as RateLimitDriver } from "./types-Bw8vrrVF.js";
|
|
2
2
|
import { Result } from "@vite-hub/runtime";
|
|
3
|
-
//#region src/drivers/kv.d.ts
|
|
4
3
|
type KVOperationResult<T> = Result<T>;
|
|
5
4
|
/**
|
|
6
5
|
* The KV operations that the driver uses. `kv` and `kv.store(name)` from `@vite-hub/kv` match it. `increment` must be
|
|
@@ -27,5 +26,4 @@ interface KVRateLimitDriver extends RateLimitDriver {
|
|
|
27
26
|
* `refund()` increments a second counter, and `consume()` reads it only when the first counter passes the limit.
|
|
28
27
|
*/
|
|
29
28
|
declare function kvRateLimitDriver(options: KVRateLimitDriverOptions): KVRateLimitDriver;
|
|
30
|
-
//#endregion
|
|
31
29
|
export { kvRateLimitDriver as i, KVRateLimitDriverOptions as n, RateLimitKVStorage as r, KVRateLimitDriver as t };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as rateLimitErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
-
import { n as normalizeRateLimitPolicy } from "./policy-
|
|
1
|
+
import { t as rateLimitErrorDiagnostics } from "./error-diagnostics-ulOX0clN.js";
|
|
2
|
+
import { n as normalizeRateLimitPolicy } from "./policy-CMsNKnqo.js";
|
|
3
3
|
import * as v from "valibot";
|
|
4
4
|
import { Diagnostic } from "nostics";
|
|
5
|
-
|
|
5
|
+
// src/limiter.ts
|
|
6
6
|
const driverErrorSchema = v.custom((value) => {
|
|
7
7
|
return ("isError" in Error && v.is(v.function(), Error.isError) ? Error.isError(value) === true : v.is(v.instance(Error), value) || v.is(v.object({}), value) && Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null && Object.prototype.toString.call(value) === "[object Error]") && v.is(v.object({
|
|
8
8
|
message: v.string(),
|
|
@@ -254,11 +254,9 @@ function createRateLimiter(options) {
|
|
|
254
254
|
}
|
|
255
255
|
};
|
|
256
256
|
}
|
|
257
|
-
|
|
258
|
-
//#region src/internal/kv-provider.ts
|
|
257
|
+
// src/internal/kv-provider.ts
|
|
259
258
|
/** KV drivers with a shared atomic increment, as required by the KV Rate Limit driver. */
|
|
260
259
|
function resolveKVRateLimitDriver(driver) {
|
|
261
260
|
return driver === "database" || driver === "redis" || driver === "upstash" ? "kv" : "memory";
|
|
262
261
|
}
|
|
263
|
-
//#endregion
|
|
264
262
|
export { createRateLimiter as n, resolveKVRateLimitDriver as t };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/@standard-schema+spec@1.1.0/node_modules/@standard-schema/spec/dist/index.d.ts
|
|
2
1
|
/** The Standard Typed interface. This is a base type extended by other specs. */
|
|
3
2
|
interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
4
3
|
/** The Standard properties. */
|
|
@@ -74,8 +73,6 @@ declare namespace StandardSchemaV1 {
|
|
|
74
73
|
/** Infers the output type of a Standard. */
|
|
75
74
|
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
76
75
|
}
|
|
77
|
-
//#endregion
|
|
78
|
-
//#region ../internal/src/operation-definition.d.ts
|
|
79
76
|
/** `read` never changes state. `write` changes state. `destructive` deletes or publishes. */
|
|
80
77
|
type OperationKind = "read" | "write" | "destructive";
|
|
81
78
|
/** The signed-in user of a call. */
|
|
@@ -241,5 +238,4 @@ interface OperationContributionEntry {
|
|
|
241
238
|
/** `false`: the app already has these operations at runtime. Only tools such as the CLI and `vitehub inspect` read the entry. */
|
|
242
239
|
runtime?: false;
|
|
243
240
|
}
|
|
244
|
-
//#endregion
|
|
245
241
|
export { OperationContributionEntry as n, AnyOperation as t };
|
|
@@ -6,7 +6,7 @@ import { tmpdir } from "node:os";
|
|
|
6
6
|
import "node:url";
|
|
7
7
|
import { createBirpc } from "birpc";
|
|
8
8
|
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
9
|
-
|
|
9
|
+
// ../internal/src/error-diagnostics.ts
|
|
10
10
|
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
11
11
|
const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
12
12
|
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
@@ -263,6 +263,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
263
263
|
why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
|
|
264
264
|
fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
|
|
265
265
|
},
|
|
266
|
+
INTERNAL_SITE_TOKEN_TOO_LONG: {
|
|
267
|
+
why: ({ length, maximum }) => `The Site access token is ${length} characters, and an app accepts ${maximum}.`,
|
|
268
|
+
fix: "Open the app with a shorter path, or give the person and the project shorter names, so that the Site access token fits."
|
|
269
|
+
},
|
|
266
270
|
INTERNAL_SQLITE_ARGUMENT_INVALID: {
|
|
267
271
|
why: ({ value }) => value === "undefined" ? "undefined cannot be passed as argument to the database" : "Only finite numbers (not Infinity or NaN) can be passed as arguments",
|
|
268
272
|
fix: "Pass query arguments as finite numbers, strings, booleans, bigints, dates, byte arrays, or null. Replace undefined with null, and check numbers with `Number.isFinite()` before the query."
|
|
@@ -277,8 +281,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
277
281
|
}
|
|
278
282
|
}
|
|
279
283
|
});
|
|
280
|
-
|
|
281
|
-
//#region ../internal/src/object.ts
|
|
284
|
+
// ../internal/src/object.ts
|
|
282
285
|
/** A non-null object that is not an array. Functions do not pass. */
|
|
283
286
|
function isRecord(value) {
|
|
284
287
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -386,8 +389,7 @@ function findViteHubDevServerUrl(roots, env) {
|
|
|
386
389
|
}
|
|
387
390
|
return env["VITEHUB_DEV_SERVER_URL"] || void 0;
|
|
388
391
|
}
|
|
389
|
-
|
|
390
|
-
//#region ../internal/src/build/vite.ts
|
|
392
|
+
// ../internal/src/build/vite.ts
|
|
391
393
|
const projectRootDirectoryMarkers = [
|
|
392
394
|
["server", "agents"],
|
|
393
395
|
["server", "channels"],
|
|
@@ -492,8 +494,7 @@ function isMissingProjectMarker(error) {
|
|
|
492
494
|
const code = error.code;
|
|
493
495
|
return code === "ENOENT" || code === "ENOTDIR";
|
|
494
496
|
}
|
|
495
|
-
|
|
496
|
-
//#region ../internal/src/invariant.ts
|
|
497
|
+
// ../internal/src/invariant.ts
|
|
497
498
|
const invariantDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
498
499
|
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
499
500
|
codes: { INTERNAL_INVARIANT_FAILED: {
|
|
@@ -512,8 +513,7 @@ function invariantError(what) {
|
|
|
512
513
|
function invariant(condition, what) {
|
|
513
514
|
if (!condition) throw invariantError(what);
|
|
514
515
|
}
|
|
515
|
-
|
|
516
|
-
//#region ../internal/src/operation-rpc.ts
|
|
516
|
+
// ../internal/src/operation-rpc.ts
|
|
517
517
|
/** Path of the operation RPC under the app. Dev servers and deployed apps serve it the same way, one birpc call per POST. */
|
|
518
518
|
const operationRpcPath = "/_vitehub/rpc";
|
|
519
519
|
const maximumIdLength = 128;
|
|
@@ -666,8 +666,7 @@ async function callOperationRpc(name, input, send) {
|
|
|
666
666
|
};
|
|
667
667
|
}
|
|
668
668
|
}
|
|
669
|
-
|
|
670
|
-
//#region ../internal/src/console-signature.ts
|
|
669
|
+
// ../internal/src/console-signature.ts
|
|
671
670
|
/**
|
|
672
671
|
* Signed requests to the Console endpoint of an app, `POST /_vitehub/rpc`. Each caller, such as one Console link or one
|
|
673
672
|
* CI job, has an Ed25519 key pair. The app keeps only the public keys, in `VITEHUB_CONSOLE_KEY_<NAME>`, so a copy of
|
|
@@ -796,8 +795,7 @@ function readConsoleSigningKey(env) {
|
|
|
796
795
|
privateKey
|
|
797
796
|
};
|
|
798
797
|
}
|
|
799
|
-
|
|
800
|
-
//#region ../internal/src/standard-schema.ts
|
|
798
|
+
// ../internal/src/standard-schema.ts
|
|
801
799
|
function readOwn(value, key) {
|
|
802
800
|
if (value === null || Object(value) !== value) return;
|
|
803
801
|
try {
|
|
@@ -826,8 +824,7 @@ function standardJsonSchema(schema, direction, target = "draft-2020-12", library
|
|
|
826
824
|
return;
|
|
827
825
|
}
|
|
828
826
|
}
|
|
829
|
-
|
|
830
|
-
//#region ../internal/src/valibot.ts
|
|
827
|
+
// ../internal/src/valibot.ts
|
|
831
828
|
const valibotTargets = /* @__PURE__ */ new Set([
|
|
832
829
|
"draft-07",
|
|
833
830
|
"draft-2020-12",
|
|
@@ -868,8 +865,7 @@ function withValibotJsonSchema(schema, options = {}) {
|
|
|
868
865
|
}
|
|
869
866
|
};
|
|
870
867
|
}
|
|
871
|
-
|
|
872
|
-
//#region ../internal/src/operation-definition.ts
|
|
868
|
+
// ../internal/src/operation-definition.ts
|
|
873
869
|
const nameFormat = /^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*$/;
|
|
874
870
|
const kinds = /* @__PURE__ */ new Set([
|
|
875
871
|
"read",
|
|
@@ -918,7 +914,8 @@ const reservedOperationNamespaces = [
|
|
|
918
914
|
"login",
|
|
919
915
|
"logout",
|
|
920
916
|
"update",
|
|
921
|
-
"whoami"
|
|
917
|
+
"whoami",
|
|
918
|
+
"apps"
|
|
922
919
|
]
|
|
923
920
|
];
|
|
924
921
|
/** Input keys that the generated CLI commands read themselves. */
|
|
@@ -959,8 +956,7 @@ function isSectionId(section) {
|
|
|
959
956
|
function operationInputJsonSchema(operation) {
|
|
960
957
|
return standardJsonSchema(operation.input, "input") ?? { type: "object" };
|
|
961
958
|
}
|
|
962
|
-
|
|
963
|
-
//#region ../internal/src/operations.ts
|
|
959
|
+
// ../internal/src/operations.ts
|
|
964
960
|
/** Header that proves the caller is not a browser page. A foreign page cannot send it without a CORS preflight. */
|
|
965
961
|
const operationRpcHeader = "x-vitehub-console";
|
|
966
962
|
/** Response header of the local dev RPC. Its value is {@link projectRootHash} of the project that the server runs. */
|
|
@@ -1291,7 +1287,7 @@ async function callOperation(target, name, input) {
|
|
|
1291
1287
|
const url = new URL(operationRpcPath.slice(1), base);
|
|
1292
1288
|
origin = url.origin;
|
|
1293
1289
|
const env = target.roots?.length ? {} : target.env;
|
|
1294
|
-
try {
|
|
1290
|
+
if (!target.authorization) try {
|
|
1295
1291
|
readConsoleSigningKey(env);
|
|
1296
1292
|
} catch (error) {
|
|
1297
1293
|
return {
|
|
@@ -1303,15 +1299,18 @@ async function callOperation(target, name, input) {
|
|
|
1303
1299
|
};
|
|
1304
1300
|
}
|
|
1305
1301
|
const outcome = await callOperationRpc(name, input ?? {}, async (body) => {
|
|
1306
|
-
const
|
|
1302
|
+
const signal = target.signal ?? AbortSignal.timeout(target.timeout ?? 3e4);
|
|
1303
|
+
const headers = target.authorization ? operationHeaders() : await signedOperationHeaders(env, url, body);
|
|
1304
|
+
if (target.authorization) headers.set("authorization", target.authorization);
|
|
1307
1305
|
if (target.confirmed !== void 0) headers.set(operationConfirmationHeader, target.confirmed ? "confirmed" : "required");
|
|
1308
1306
|
if (target.roots?.length) headers.set(operationExpectedRootsHeader, target.roots.map(projectRootHash).join(","));
|
|
1307
|
+
signal.throwIfAborted();
|
|
1309
1308
|
const response = await (target.fetch ?? fetch)(url.href, {
|
|
1310
1309
|
body,
|
|
1311
1310
|
headers,
|
|
1312
1311
|
method: "POST",
|
|
1313
1312
|
redirect: "manual",
|
|
1314
|
-
signal
|
|
1313
|
+
signal
|
|
1315
1314
|
});
|
|
1316
1315
|
const text = await response.text();
|
|
1317
1316
|
let json;
|
|
@@ -1348,7 +1347,7 @@ async function callOperation(target, name, input) {
|
|
|
1348
1347
|
} : void 0);
|
|
1349
1348
|
if (failure) {
|
|
1350
1349
|
if (target.roots?.length && failure.status === 401) failure.fix = `Pass --url ${base.href.slice(0, -1)} to send credentials. A command sends none to the dev server that it finds. ${failure.fix ?? "Set VITEHUB_CONSOLE_PRIVATE_KEY_<NAME> to a private key that `vitehub secret console-key` printed, and its public key in VITEHUB_CONSOLE_KEY_<NAME> on the app."}`;
|
|
1351
|
-
if ((failure.status === 401 || failure.status === 403) && !hasCredentials(env) && !failure.fix) failure.fix = target.roots?.length ? `Pass --url <origin> to send deployment credentials. ${operationCredentialHint}` : operationCredentialHint;
|
|
1350
|
+
if ((failure.status === 401 || failure.status === 403) && !target.authorization && !hasCredentials(env) && !failure.fix) failure.fix = target.roots?.length ? `Pass --url <origin> to send deployment credentials. ${operationCredentialHint}` : operationCredentialHint;
|
|
1352
1351
|
return {
|
|
1353
1352
|
ok: false,
|
|
1354
1353
|
...failure
|
|
@@ -1387,5 +1386,4 @@ function table(rows) {
|
|
|
1387
1386
|
const widths = rows[0].map((_, column) => Math.max(...rows.map((row) => row[column].length)));
|
|
1388
1387
|
return rows.map((row) => row.map((cell, column) => column === row.length - 1 ? cell : cell.padEnd(widths[column])).join(" ")).join("\n");
|
|
1389
1388
|
}
|
|
1390
|
-
//#endregion
|
|
1391
1389
|
export { writeCliFailure as A, isServerEnvironment as C, readViteHubDevServerFile as D, askOnTerminal as E, internalErrorDiagnostics as F, cloneRecord as M, isRecord as N, readViteHubDevTargetOption as O, isRecordOrFunction as P, getResolvedFeatureOptions as S, shouldSkipViteProviderBuild as T, invariant as _, operationRootHeader as a, createNoExternalAddition as b, projectRootHash as c, toOperationFailure as d, defineOperation as f, readOperationRpcCall as g, operationRpcRefusal as h, createOperationRegistry as i, writeViteHubDevServerFile as j, removeViteHubDevServerFile as k, runOperation as l, operationRpcPath as m, callOperationFromCli as n, operationRpcHeader as o, answerOperationRpc as p, collectOperationContributions as r, operationsOf as s, assertOperationProject as t, table as u, VITEHUB_PREPARE as v, resolveViteHubProjectRoot as w, getDeploymentHost as x, VITEHUB_PROJECT_ROOT as y };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { n as resetRateLimit, t as peekRateLimit } from "./counters-
|
|
3
|
-
import { t as
|
|
4
|
-
|
|
1
|
+
import { t as redactInspectionText } from "./inspect-Dqvi9vUt.js";
|
|
2
|
+
import { n as resetRateLimit, t as peekRateLimit } from "./counters-dyc0Q_HL.js";
|
|
3
|
+
import { t as rateLimitErrorDiagnostics } from "./error-diagnostics-ulOX0clN.js";
|
|
4
|
+
// src/runtime/operations.ts
|
|
5
5
|
function redact(result) {
|
|
6
6
|
return {
|
|
7
7
|
...result,
|
|
@@ -28,5 +28,4 @@ async function peekRateLimitOperation(name, key) {
|
|
|
28
28
|
async function resetRateLimitOperation(name, key) {
|
|
29
29
|
return await guarded(() => resetRateLimit(name, key));
|
|
30
30
|
}
|
|
31
|
-
//#endregion
|
|
32
31
|
export { peekRateLimitOperation, resetRateLimitOperation };
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
//#region ../internal/src/operations-dev.d.ts
|
|
1
|
+
import { t as AnyOperation } from "./operation-definition-CqZkx1Rm.js";
|
|
2
|
+
import { n as RateLimitPeekInspection, r as RateLimitResetInspection } from "./counters-BCNUEaDn.js";
|
|
4
3
|
/**
|
|
5
4
|
* Bundled into owner packages and used only by their serve-only generated Nitro route. Operations get the Request as
|
|
6
5
|
* `context.event`, so owner hooks such as `identify` of Comments read its Standard Context.
|
|
@@ -11,9 +10,6 @@ export declare function createStandaloneOperationHandler(sources: {
|
|
|
11
10
|
}[], root: string): {
|
|
12
11
|
fetch(request: Request): Promise<Response>;
|
|
13
12
|
};
|
|
14
|
-
//#endregion
|
|
15
|
-
//#region src/operations.d.ts
|
|
16
13
|
/** The `rate-limit.*` operations: peek and reset. The Console, `vitehub rate-limit`, and agents run them. */
|
|
17
14
|
export declare const rateLimitOperations: readonly AnyOperation[];
|
|
18
|
-
//#endregion
|
|
19
15
|
export type { RateLimitPeekInspection, RateLimitResetInspection };
|
package/dist/operations.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { F as internalErrorDiagnostics, a as operationRootHeader, c as projectRootHash, d as toOperationFailure, f as defineOperation, g as readOperationRpcCall, h as operationRpcRefusal, i as createOperationRegistry, l as runOperation, o as operationRpcHeader, p as answerOperationRpc, s as operationsOf, t as assertOperationProject } from "./operations-
|
|
2
|
-
import { n as isViteHubLoopbackPeer } from "./dev-peer-
|
|
1
|
+
import { F as internalErrorDiagnostics, a as operationRootHeader, c as projectRootHash, d as toOperationFailure, f as defineOperation, g as readOperationRpcCall, h as operationRpcRefusal, i as createOperationRegistry, l as runOperation, o as operationRpcHeader, p as answerOperationRpc, s as operationsOf, t as assertOperationProject } from "./operations-BZsu-Ssx.js";
|
|
2
|
+
import { n as isViteHubLoopbackPeer } from "./dev-peer-D0vOxmrD.js";
|
|
3
3
|
import * as v from "valibot";
|
|
4
|
-
|
|
4
|
+
// ../internal/src/secret.ts
|
|
5
5
|
const secretEncoder = new TextEncoder();
|
|
6
6
|
/**
|
|
7
7
|
* Compares a request value with an expected secret in constant time for the length of `expected`. Returns `false`
|
|
@@ -16,8 +16,7 @@ function isViteHubSecretEqual(actual, expected) {
|
|
|
16
16
|
return difference === 0;
|
|
17
17
|
}
|
|
18
18
|
Object.freeze({ prefix: "sha256=" });
|
|
19
|
-
|
|
20
|
-
//#region ../internal/src/dev-endpoint.ts
|
|
19
|
+
// ../internal/src/dev-endpoint.ts
|
|
21
20
|
const viteHubDevRequestGrantBrand = Symbol("vitehub.devRequestGrant");
|
|
22
21
|
const devRequestGrants = /* @__PURE__ */ new WeakMap();
|
|
23
22
|
function grantDevRequest(request, label) {
|
|
@@ -97,8 +96,7 @@ async function validateViteHubNitroDevRequest(request, guard) {
|
|
|
97
96
|
const rejection = await guard.authorize?.(request);
|
|
98
97
|
return rejection ? rejectDevRequest(rejection) : grantDevRequest(request, guard.label);
|
|
99
98
|
}
|
|
100
|
-
|
|
101
|
-
//#region ../internal/src/operations-dev.ts
|
|
99
|
+
// ../internal/src/operations-dev.ts
|
|
102
100
|
function readPath(value, ...path) {
|
|
103
101
|
for (const key of path) value = value !== null && typeof value === "object" ? Reflect.get(value, key) : void 0;
|
|
104
102
|
return value;
|
|
@@ -235,9 +233,8 @@ function createStandaloneOperationHandler(sources, root) {
|
|
|
235
233
|
}
|
|
236
234
|
} };
|
|
237
235
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const runtime = () => import("./operations-DcgGebib.js");
|
|
236
|
+
// src/operations.ts
|
|
237
|
+
const runtime = () => import("./operations-BuAYwMe4.js");
|
|
241
238
|
const target = v.object({
|
|
242
239
|
key: v.pipe(v.string(), v.minLength(1, "Name the limited key, for example a client IP or user ID.")),
|
|
243
240
|
name: v.pipe(v.string(), v.check((name) => name.trim() !== "", "Name the stable ID of `requireRateLimit()`."))
|
|
@@ -269,5 +266,4 @@ const rateLimitOperations = [defineRateLimitOperation({
|
|
|
269
266
|
name: "rate-limit.reset",
|
|
270
267
|
run: async (input) => await (await runtime()).resetRateLimitOperation(input.name, input.key)
|
|
271
268
|
})];
|
|
272
|
-
//#endregion
|
|
273
269
|
export { createStandaloneOperationHandler, rateLimitOperations };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as rateLimitErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { t as rateLimitErrorDiagnostics } from "./error-diagnostics-ulOX0clN.js";
|
|
2
2
|
import { parseDuration } from "@vite-hub/runtime";
|
|
3
|
-
|
|
3
|
+
// src/policy.ts
|
|
4
4
|
const rateLimitPolicyKeys = /* @__PURE__ */ new Set([
|
|
5
5
|
"enforcement",
|
|
6
6
|
"failure",
|
|
@@ -47,5 +47,4 @@ function declaredRateLimitPolicy(policy) {
|
|
|
47
47
|
window: policy.window
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
-
//#endregion
|
|
51
50
|
export { rateLimitPolicyKeys as a, rateLimitPolicyKey as i, normalizeRateLimitPolicy as n, parseRateLimitWindow as r, declaredRateLimitPolicy as t };
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
//#region src/runtime/state.d.ts
|
|
1
|
+
import { r as RateLimitKVStorage } from "./kv-DldoJary.js";
|
|
2
|
+
import { O as RateLimitRuntimeConfig } from "./types-Bw8vrrVF.js";
|
|
4
3
|
/** The KV store of the `kv` driver. The generated Nitro plugin passes it from `@vite-hub/kv`. */
|
|
5
4
|
interface RateLimitKVRuntime {
|
|
6
5
|
/** The KV driver that the store uses in this process, for example `getKVStoreDriver()` of `@vite-hub/kv`. */
|
|
@@ -19,5 +18,4 @@ export declare function getRateLimitRuntimeConfig(): RateLimitRuntimeConfig;
|
|
|
19
18
|
* The generated Nitro plugin calls it at boot.
|
|
20
19
|
*/
|
|
21
20
|
export declare function resolveRateLimitDriver(): Promise<RateLimitRuntimeConfig["driver"]>;
|
|
22
|
-
//#endregion
|
|
23
21
|
export type { RateLimitKVRuntime };
|
package/dist/runtime.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { getRateLimitRuntimeConfig, resolveRateLimitDriver, setRateLimitRuntimeConfig };
|
|
1
|
+
export { t as getRateLimitRuntimeConfig, i as resolveRateLimitDriver, a as setRateLimitRuntimeConfig } from "./state-BXD6-GFo.js";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { t as rateLimitErrorDiagnostics } from "./error-diagnostics-DRuEG4wu.js";
|
|
2
|
-
import { i as rateLimitPolicyKey } from "./policy-BeyQ0vnc.js";
|
|
3
|
-
import { n as createRateLimiter, t as resolveKVRateLimitDriver } from "./kv-provider-DlgNQC-o.js";
|
|
4
1
|
import { kvRateLimitDriver } from "./drivers/kv.js";
|
|
5
2
|
import { memoryRateLimitDriver } from "./drivers/memory.js";
|
|
3
|
+
import { t as rateLimitErrorDiagnostics } from "./error-diagnostics-ulOX0clN.js";
|
|
4
|
+
import { n as createRateLimiter, t as resolveKVRateLimitDriver } from "./kv-provider-DAq-42o6.js";
|
|
5
|
+
import { i as rateLimitPolicyKey } from "./policy-CMsNKnqo.js";
|
|
6
6
|
import { getViteHubTestMode } from "@vite-hub/runtime/internal/test-mode";
|
|
7
|
-
|
|
7
|
+
// src/runtime/state.ts
|
|
8
8
|
let runtimeConfig = { driver: "memory" };
|
|
9
9
|
let kvRuntime;
|
|
10
10
|
let activeDriver;
|
|
@@ -81,5 +81,4 @@ function getRuntimeRateLimiter(driver, name, policy) {
|
|
|
81
81
|
function listRuntimeRateLimiters(name) {
|
|
82
82
|
return [...limiters().get(name)?.values() ?? []];
|
|
83
83
|
}
|
|
84
|
-
//#endregion
|
|
85
84
|
export { setRateLimitRuntimeConfig as a, resolveRateLimitDriver as i, getRuntimeRateLimiter as n, listRuntimeRateLimiters as r, getRateLimitRuntimeConfig as t };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Duration, Result, ViteHubContext } from "@vite-hub/runtime";
|
|
2
|
-
//#region src/types.d.ts
|
|
3
2
|
type MaybePromise<T> = Promise<T> | T;
|
|
4
3
|
type RateLimitEnforcement = "best-effort" | "strict";
|
|
5
4
|
type RateLimitFailurePolicy = "allow" | "deny";
|
|
@@ -201,5 +200,4 @@ interface RateLimitRuntimeConfig {
|
|
|
201
200
|
*/
|
|
202
201
|
memoryFallback?: boolean;
|
|
203
202
|
}
|
|
204
|
-
//#endregion
|
|
205
203
|
export { RefundRateLimitErrorCode as A, RateLimitRefundResult as C, RateLimitResetResult as D, RateLimitRequestEvent as E, ResolvedRateLimitPolicy as M, RateLimitRuntimeConfig as O, RateLimitPolicy as S, RateLimitRequest as T, RateLimitDriverResult as _, RateLimitCounterScope as a, RateLimitOptions as b, RateLimitDriver as c, RateLimitDriverName as d, RateLimitDriverOutcome as f, RateLimitDriverResetOutcome as g, RateLimitDriverRefundOutcome as h, RateLimitConsumeInput as i, RequireRateLimitOptions as j, RateLimiter as k, RateLimitDriverCapabilities as l, RateLimitDriverPeekResult as m, CheckRateLimitOptions as n, RateLimitDecision as o, RateLimitDriverPeekOutcome as p, CreateRateLimiterOptions as r, RateLimitDeclaration as s, CheckRateLimitErrorCode as t, RateLimitDriverInput as u, RateLimitEnforcement as v, RateLimitRejectedAttemptBehavior as w, RateLimitPeekResult as x, RateLimitFailurePolicy as y };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { r as ViteHubCliPluginMetadata } from "./cli-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { r as ViteHubCliPluginMetadata } from "./cli-B77bo6ii.js";
|
|
2
|
+
import { n as OperationContributionEntry } from "./operation-definition-CqZkx1Rm.js";
|
|
3
|
+
import { b as RateLimitOptions, s as RateLimitDeclaration } from "./types-Bw8vrrVF.js";
|
|
4
4
|
import { Plugin } from "vite";
|
|
5
|
-
//#region ../internal/src/durability.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* One durability reporter that a primitive's Vite plugin contributes through `vitehub.durability`. The Node server
|
|
8
7
|
* imports `export` from `module` at boot and calls it with `input` and the server environment. It returns the
|
|
@@ -25,8 +24,6 @@ interface DurabilityPluginMetadata {
|
|
|
25
24
|
/** Called after Vite resolves the config. Return an empty list when the primitive is off. */
|
|
26
25
|
durability?: () => readonly DurabilityContribution[];
|
|
27
26
|
}
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region ../internal/src/inspect.d.ts
|
|
30
27
|
interface ViteHubDefinitionField {
|
|
31
28
|
label: string;
|
|
32
29
|
value: string;
|
|
@@ -88,15 +85,11 @@ type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor |
|
|
|
88
85
|
interface ViteHubInspectionPluginMetadata {
|
|
89
86
|
inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
|
|
90
87
|
}
|
|
91
|
-
//#endregion
|
|
92
|
-
//#region src/discovery.d.ts
|
|
93
88
|
interface RateLimitDiscoveryOptions {
|
|
94
89
|
rootDir: string;
|
|
95
90
|
scanDirs?: string[];
|
|
96
91
|
}
|
|
97
92
|
export declare function discoverRateLimitDeclarations(options: RateLimitDiscoveryOptions): RateLimitDeclaration[];
|
|
98
|
-
//#endregion
|
|
99
|
-
//#region ../internal/src/console.d.ts
|
|
100
93
|
type MaybePromise<T> = T | Promise<T>;
|
|
101
94
|
/** Lists discovered Definitions in a sidebar and shows the selected Definition's fields. */
|
|
102
95
|
interface ViteHubConsoleDefinitionCatalogView {
|
|
@@ -165,7 +158,7 @@ interface ViteHubConsoleOperationAction {
|
|
|
165
158
|
operation: string;
|
|
166
159
|
input: Readonly<Record<string, string>>;
|
|
167
160
|
/**
|
|
168
|
-
* The result is `{ url }`, such as a
|
|
161
|
+
* The result is `{ url }`, such as a provider sign-in: the Console opens it in a new tab, and loads
|
|
169
162
|
* the list again when the person comes back. The URL must be `https:`, or `http:` on a loopback host.
|
|
170
163
|
*/
|
|
171
164
|
tab?: true;
|
|
@@ -428,8 +421,6 @@ interface ViteHubConsoleDocumentSetup {
|
|
|
428
421
|
*/
|
|
429
422
|
schedule?: ViteHubConsoleDocumentHint;
|
|
430
423
|
}
|
|
431
|
-
//#endregion
|
|
432
|
-
//#region src/inspect.d.ts
|
|
433
424
|
interface RateLimitInspectionOptions {
|
|
434
425
|
projectRoot: string;
|
|
435
426
|
rootDir: string;
|
|
@@ -439,8 +430,6 @@ interface RateLimitInspectionOptions {
|
|
|
439
430
|
export declare function inspectRateLimitDefinitions(options: RateLimitInspectionOptions): ViteHubDefinitionSummary[];
|
|
440
431
|
/** Console section that lists discovered Rate Limit Definitions. `vitehub inspect definitions` reads the same data. */
|
|
441
432
|
export declare const rateLimitConsoleSection: ViteHubConsoleSectionContribution<RateLimitInspectionOptions>;
|
|
442
|
-
//#endregion
|
|
443
|
-
//#region src/vite.d.ts
|
|
444
433
|
export type RateLimitVitePluginOptions = RateLimitOptions;
|
|
445
434
|
export type RateLimitVitePlugin = Plugin & {
|
|
446
435
|
vitehub: ViteHubCliPluginMetadata & ViteHubInspectionPluginMetadata & DurabilityPluginMetadata & {
|
|
@@ -448,5 +437,4 @@ export type RateLimitVitePlugin = Plugin & {
|
|
|
448
437
|
};
|
|
449
438
|
};
|
|
450
439
|
export declare function hubRateLimit(options?: RateLimitVitePluginOptions): RateLimitVitePlugin;
|
|
451
|
-
//#endregion
|
|
452
440
|
export type { RateLimitInspectionOptions };
|
package/dist/vite.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { C as isServerEnvironment, D as readViteHubDevServerFile, F as internalErrorDiagnostics, M as cloneRecord, N as isRecord, P as isRecordOrFunction, S as getResolvedFeatureOptions, T as shouldSkipViteProviderBuild, _ as invariant, b as createNoExternalAddition, j as writeViteHubDevServerFile, k as removeViteHubDevServerFile, m as operationRpcPath, r as collectOperationContributions, w as resolveViteHubProjectRoot, x as getDeploymentHost, y as VITEHUB_PROJECT_ROOT } from "./operations-BZsu-Ssx.js";
|
|
2
|
+
import { i as resolve$1, n as relativeDefinitionFile, r as dirname$1 } from "./inspect-Dqvi9vUt.js";
|
|
3
|
+
import { t as addViteHubDevPeerDevHandler } from "./dev-peer-D0vOxmrD.js";
|
|
4
|
+
import { a as rateLimitPolicyKeys, i as rateLimitPolicyKey, n as normalizeRateLimitPolicy, t as declaredRateLimitPolicy } from "./policy-CMsNKnqo.js";
|
|
5
|
+
import { t as rateLimitErrorDiagnostics } from "./error-diagnostics-ulOX0clN.js";
|
|
6
|
+
import { n as getCloudflareRateLimitBindingName, r as isCloudflareRateLimitWindow, t as cloudflareRateLimitDriver } from "./cloudflare-CWK4wJ9b.js";
|
|
4
7
|
import { kvRateLimitDriver } from "./drivers/kv.js";
|
|
5
8
|
import { memoryRateLimitDriver } from "./drivers/memory.js";
|
|
6
|
-
import { n as
|
|
7
|
-
import { i as resolve$1, n as relativeDefinitionFile, r as dirname$1 } from "./inspect-B6gTdgy9.js";
|
|
8
|
-
import { C as isServerEnvironment, D as readViteHubDevServerFile, F as internalErrorDiagnostics, M as cloneRecord, N as isRecord, P as isRecordOrFunction, S as getResolvedFeatureOptions, T as shouldSkipViteProviderBuild, _ as invariant, b as createNoExternalAddition, j as writeViteHubDevServerFile, k as removeViteHubDevServerFile, m as operationRpcPath, r as collectOperationContributions, w as resolveViteHubProjectRoot, x as getDeploymentHost, y as VITEHUB_PROJECT_ROOT } from "./operations-C6npllas.js";
|
|
9
|
-
import { t as addViteHubDevPeerDevHandler } from "./dev-peer-CHafxbtj.js";
|
|
9
|
+
import { n as createRateLimiter, t as resolveKVRateLimitDriver } from "./kv-provider-DAq-42o6.js";
|
|
10
10
|
import { formatDiagnostic } from "nostics";
|
|
11
11
|
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
12
12
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
13
13
|
import { basename, dirname, relative, resolve } from "node:path";
|
|
14
14
|
import { fileURLToPath } from "node:url";
|
|
15
15
|
import { Visitor, parseSync } from "vite";
|
|
16
|
-
|
|
16
|
+
// ../internal/src/hints.ts
|
|
17
17
|
/**
|
|
18
18
|
* The file that lists the hints of the last build or dev server, relative to the project root. A hint is a warning
|
|
19
19
|
* about something that works now and fails later, such as counts that stay in one server's memory. Agents and CI read
|
|
@@ -91,8 +91,7 @@ function startViteHubHints(config, owner = config) {
|
|
|
91
91
|
started.add(owner);
|
|
92
92
|
write(startRun(config));
|
|
93
93
|
}
|
|
94
|
-
|
|
95
|
-
//#region ../internal/src/build/paths.ts
|
|
94
|
+
// ../internal/src/build/paths.ts
|
|
96
95
|
function resolveRuntimeModule(packageDir, modulePath) {
|
|
97
96
|
const distFile = resolve$1(packageDir, "dist", `${modulePath}.js`);
|
|
98
97
|
return existsSync(distFile) ? distFile : resolve$1(packageDir, "src", `${modulePath}.ts`);
|
|
@@ -119,8 +118,7 @@ function findPackageDir(file) {
|
|
|
119
118
|
function ownModule(importMetaUrl, modulePath) {
|
|
120
119
|
return resolveRuntimeModule(findPackageDir(fileURLToPath(importMetaUrl)), modulePath);
|
|
121
120
|
}
|
|
122
|
-
|
|
123
|
-
//#region ../internal/src/definition-catalog.ts
|
|
121
|
+
// ../internal/src/definition-catalog.ts
|
|
124
122
|
const sourceFilePattern = /\.(?:c|m)?[jt]sx?$/i;
|
|
125
123
|
const declarationFilePattern = /\.d\.(?:c|m)?[jt]sx?$/i;
|
|
126
124
|
const testFilePattern = /\.(?:test|spec)\.(?:c|m)?[jt]sx?$/i;
|
|
@@ -212,8 +210,7 @@ function createNitroServerKit(value = {}) {
|
|
|
212
210
|
}
|
|
213
211
|
};
|
|
214
212
|
}
|
|
215
|
-
|
|
216
|
-
//#region ../internal/src/contributions.ts
|
|
213
|
+
// ../internal/src/contributions.ts
|
|
217
214
|
function isThenable(value) {
|
|
218
215
|
return typeof value.then === "function";
|
|
219
216
|
}
|
|
@@ -240,8 +237,7 @@ async function flattenPluginOptions(plugins) {
|
|
|
240
237
|
await flattenPlugins(plugins ?? [], flattened, /* @__PURE__ */ new Set());
|
|
241
238
|
return flattened;
|
|
242
239
|
}
|
|
243
|
-
|
|
244
|
-
//#region ../internal/src/operations-vite.ts
|
|
240
|
+
// ../internal/src/operations-vite.ts
|
|
245
241
|
const owners = /* @__PURE__ */ new Set([
|
|
246
242
|
"@vite-hub/kv/vite",
|
|
247
243
|
"@vite-hub/blob/vite",
|
|
@@ -309,14 +305,12 @@ async function installStandaloneOperationRpc(config, command, module) {
|
|
|
309
305
|
kit.config.devHandlers = signed;
|
|
310
306
|
Reflect.set(config, "nitro", kit.config);
|
|
311
307
|
}
|
|
312
|
-
|
|
313
|
-
//#region ../internal/src/durability.ts
|
|
308
|
+
// ../internal/src/durability.ts
|
|
314
309
|
/** The `durability` module next to the Vite plugin module at `importMetaUrl`, in source and in `dist`. */
|
|
315
310
|
function durabilityModuleFile(importMetaUrl) {
|
|
316
311
|
return fileURLToPath(new URL(importMetaUrl.endsWith(".ts") ? "./durability.ts" : "./durability.js", importMetaUrl));
|
|
317
312
|
}
|
|
318
|
-
|
|
319
|
-
//#region ../internal/src/build/provider-output-config.ts
|
|
313
|
+
// ../internal/src/build/provider-output-config.ts
|
|
320
314
|
function isProviderJsonArray(value, ancestors) {
|
|
321
315
|
if (Object.getPrototypeOf(value) !== Array.prototype || ancestors.has(value)) return false;
|
|
322
316
|
if (Reflect.ownKeys(value).length !== value.length + 1) return false;
|
|
@@ -403,19 +397,21 @@ function mergeProviderOutputConfig(existing, value, ownership = {}) {
|
|
|
403
397
|
...mergeOwnedArrays(existing, value, ownership.arrays)
|
|
404
398
|
};
|
|
405
399
|
}
|
|
406
|
-
|
|
407
|
-
//#region ../internal/src/build/bundle-options.ts
|
|
400
|
+
// ../internal/src/build/bundle-options.ts
|
|
408
401
|
/** Select the runtime constants from one resolved Vite configuration. */
|
|
409
402
|
function resolveViteHubBundleDefines(config) {
|
|
410
403
|
const defines = {};
|
|
411
|
-
for (const name of [
|
|
404
|
+
for (const name of [
|
|
405
|
+
"__VITEHUB_PUBLIC_URL__",
|
|
406
|
+
"__VITEHUB_APP_BASE_URL__",
|
|
407
|
+
"__VITEHUB_CONSOLE_URL__"
|
|
408
|
+
]) {
|
|
412
409
|
const value = config.define?.[name];
|
|
413
410
|
if (typeof value === "string") defines[name] = value;
|
|
414
411
|
}
|
|
415
412
|
return defines;
|
|
416
413
|
}
|
|
417
|
-
|
|
418
|
-
//#region ../internal/src/build/cloudflare-provider-output.ts
|
|
414
|
+
// ../internal/src/build/cloudflare-provider-output.ts
|
|
419
415
|
function isDeepStrictEqual(left, right) {
|
|
420
416
|
if (Object.is(left, right)) return true;
|
|
421
417
|
if (!left || !right || typeof left !== "object" || typeof right !== "object") return false;
|
|
@@ -594,8 +590,7 @@ function composeNitroCloudflareProviderOutput(catalog, value, inheritedValue = v
|
|
|
594
590
|
associateProviderOutputCatalog(output, catalog);
|
|
595
591
|
return output;
|
|
596
592
|
}
|
|
597
|
-
|
|
598
|
-
//#region ../internal/src/build/provider-output-catalog.ts
|
|
593
|
+
// ../internal/src/build/provider-output-catalog.ts
|
|
599
594
|
var ProviderOutputCatalog = class {
|
|
600
595
|
bundleDefines = {};
|
|
601
596
|
#appliedCloudflareContributions = /* @__PURE__ */ new Map();
|
|
@@ -837,8 +832,7 @@ function hostFromNitroPreset(value) {
|
|
|
837
832
|
if (normalized === "node" || normalized.startsWith("node-")) return "node";
|
|
838
833
|
if (normalized.startsWith("vercel")) return "vercel";
|
|
839
834
|
}
|
|
840
|
-
|
|
841
|
-
//#region ../internal/src/hosting.ts
|
|
835
|
+
// ../internal/src/hosting.ts
|
|
842
836
|
/**
|
|
843
837
|
* Returns the Nitro preset name that this build targets, as the developer wrote it.
|
|
844
838
|
* The order is `nitro.preset`, `hosting`, `NITRO_PRESET`, `SERVER_PRESET`, then `VITEHUB_HOST`.
|
|
@@ -864,8 +858,7 @@ function getHostingProvider(hosting) {
|
|
|
864
858
|
const host = hostFromNitroPreset(hosting);
|
|
865
859
|
if (host === "cloudflare" || host === "netlify" || host === "vercel") return host;
|
|
866
860
|
}
|
|
867
|
-
|
|
868
|
-
//#region src/discovery.ts
|
|
861
|
+
// src/discovery.ts
|
|
869
862
|
const rateLimitImports = /* @__PURE__ */ new Set(["@vite-hub/rate-limit", "vite-hub/rate-limit"]);
|
|
870
863
|
const rateLimitGuards = [
|
|
871
864
|
"checkRateLimit",
|
|
@@ -1305,8 +1298,7 @@ function discoverRateLimitCatalog(options, snapshots = /* @__PURE__ */ new Map()
|
|
|
1305
1298
|
function discoverRateLimitDeclarations(options) {
|
|
1306
1299
|
return discoverRateLimitCatalog(options).declarations;
|
|
1307
1300
|
}
|
|
1308
|
-
|
|
1309
|
-
//#region src/inspect.ts
|
|
1301
|
+
// src/inspect.ts
|
|
1310
1302
|
function summarizeRateLimitDeclaration(projectRoot, declaration) {
|
|
1311
1303
|
return {
|
|
1312
1304
|
fields: [
|
|
@@ -1355,8 +1347,7 @@ const rateLimitConsoleSection = {
|
|
|
1355
1347
|
notice: "The page lists the policies. Enter a key to read its live counter or to reset it. Counters depend on the provider: a Cloudflare binding cannot be read or reset, a memory counter exists only in this server process, and a kv counter is shared by every process that uses the KV store."
|
|
1356
1348
|
}
|
|
1357
1349
|
};
|
|
1358
|
-
|
|
1359
|
-
//#region src/internal/cloudflare-bindings.ts
|
|
1350
|
+
// src/internal/cloudflare-bindings.ts
|
|
1360
1351
|
function namespaceId(namespace, rateLimitId) {
|
|
1361
1352
|
let hash = 2166136261;
|
|
1362
1353
|
for (const character of `${namespace}:${rateLimitId}`) {
|
|
@@ -1399,8 +1390,7 @@ function createCloudflareRateLimitBindings(declarations, namespace) {
|
|
|
1399
1390
|
simple: cloudflareSimpleLimit(declaration)
|
|
1400
1391
|
}));
|
|
1401
1392
|
}
|
|
1402
|
-
|
|
1403
|
-
//#region src/internal/manifest.ts
|
|
1393
|
+
// src/internal/manifest.ts
|
|
1404
1394
|
const rateLimitManifestPath = ".vitehub/rate-limit/manifest.json";
|
|
1405
1395
|
const unusedResult = async () => [void 0, void 0];
|
|
1406
1396
|
function resolveProviderCapabilities(provider) {
|
|
@@ -1432,8 +1422,7 @@ async function writeRateLimitManifest(rootDir, declarations, provider) {
|
|
|
1432
1422
|
const manifest = createRateLimitManifest(declarations, provider);
|
|
1433
1423
|
await writeFileIfChanged(resolve(rootDir, rateLimitManifestPath), `${JSON.stringify(manifest, null, 2)}\n`);
|
|
1434
1424
|
}
|
|
1435
|
-
|
|
1436
|
-
//#region src/vite.ts
|
|
1425
|
+
// src/vite.ts
|
|
1437
1426
|
const operationsModule = ownModule(import.meta.url, "operations");
|
|
1438
1427
|
const runtimeModule = ownModule(import.meta.url, "runtime");
|
|
1439
1428
|
const packageName = "@vite-hub/rate-limit";
|
|
@@ -1686,5 +1675,4 @@ function hubRateLimit(options = {}) {
|
|
|
1686
1675
|
}
|
|
1687
1676
|
};
|
|
1688
1677
|
}
|
|
1689
|
-
//#endregion
|
|
1690
1678
|
export { discoverRateLimitDeclarations, hubRateLimit, inspectRateLimitDefinitions, rateLimitConsoleSection };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/rate-limit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Provider-neutral Rate Limit primitives and Vite deployment integration for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -67,22 +67,22 @@
|
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@valibot/to-json-schema": "^1.8.0",
|
|
70
|
-
"@vite-hub/runtime": "0.
|
|
70
|
+
"@vite-hub/runtime": "0.6.0",
|
|
71
71
|
"birpc": "^4.2.0",
|
|
72
72
|
"h3": "^2.0.8",
|
|
73
73
|
"nostics": "1.4.0",
|
|
74
74
|
"valibot": "^1.5.0"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@types/node": "^24.19.
|
|
77
|
+
"@types/node": "^24.19.2",
|
|
78
78
|
"@vite-hub/internal": "0.0.1",
|
|
79
|
-
"evlog": "2.
|
|
79
|
+
"evlog": "2.37.1",
|
|
80
80
|
"nitro": "^3.0.261103-rc",
|
|
81
81
|
"publint": "^0.3.25",
|
|
82
82
|
"typescript": "^6.0.3",
|
|
83
|
-
"vite": "^8.
|
|
84
|
-
"vite-plus": "^
|
|
85
|
-
"vitest": "
|
|
83
|
+
"vite": "^8.3.8",
|
|
84
|
+
"vite-plus": "^1.7.0",
|
|
85
|
+
"vitest": "5.1.0"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
88
|
"nitro": "3.0.261102-rc || ^3.0.261103-rc",
|