@vite-hub/rate-limit 0.4.1 → 0.5.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/README.md +7 -3
- package/dist/{cli-szm60zN5.d.ts → cli-B77bo6ii.d.ts} +1 -6
- package/dist/cli.d.ts +2 -4
- package/dist/cli.js +5 -7
- 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-D4LANMAi.js → counters-dyc0Q_HL.js} +3 -6
- 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 -12
- package/dist/drivers/memory.d.ts +2 -4
- package/dist/drivers/memory.js +13 -7
- 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 +36 -13
- package/dist/{inspect-B6gTdgy9.js → inspect-Dqvi9vUt.js} +2 -4
- package/dist/{kv-Cw_jK6Gu.d.ts → kv-DldoJary.d.ts} +1 -4
- package/dist/{kv-provider-DlgNQC-o.js → kv-provider-DAq-42o6.js} +4 -6
- package/dist/{operation-definition-nmRu_O3V.d.ts → operation-definition-CqZkx1Rm.d.ts} +8 -6
- package/dist/{operations-B1MnA9cW.js → operations-BuAYwMe4.js} +4 -6
- package/dist/{operations-q0ieloSJ.js → operations-DWWMHBWt.js} +46 -27
- 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-Fq3rGFO3.js → state-BXD6-GFo.js} +4 -6
- package/dist/{types-OzukEqHf.d.ts → types-Bw8vrrVF.d.ts} +0 -2
- package/dist/vite.d.ts +5 -15
- package/dist/vite.js +41 -51
- package/package.json +7 -6
|
@@ -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",
|
|
@@ -32,7 +32,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
32
32
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
33
33
|
},
|
|
34
34
|
INTERNAL_R0022: {
|
|
35
|
-
fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
|
|
35
|
+
fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields, and the list_operations tool of the ViteHub MCP gives the input schema of each operation.",
|
|
36
36
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
37
37
|
},
|
|
38
38
|
INTERNAL_R0024: {
|
|
@@ -251,6 +251,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
251
251
|
why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
|
|
252
252
|
fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
|
|
253
253
|
},
|
|
254
|
+
INTERNAL_RUNTIME_PACKAGE_VERSION_CONFLICT: {
|
|
255
|
+
why: ({ first, name, second }) => `[vitehub] One server function needs ${name} from two installations: ${first} and ${second}.`,
|
|
256
|
+
fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`, then build again."
|
|
257
|
+
},
|
|
254
258
|
INTERNAL_SECRET_PURPOSE_MISSING: {
|
|
255
259
|
why: "[vitehub] A derived secret requires a purpose.",
|
|
256
260
|
fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
|
|
@@ -259,6 +263,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
259
263
|
why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
|
|
260
264
|
fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
|
|
261
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
|
+
},
|
|
262
270
|
INTERNAL_SQLITE_ARGUMENT_INVALID: {
|
|
263
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",
|
|
264
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."
|
|
@@ -273,8 +281,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
273
281
|
}
|
|
274
282
|
}
|
|
275
283
|
});
|
|
276
|
-
|
|
277
|
-
//#region ../internal/src/object.ts
|
|
284
|
+
// ../internal/src/object.ts
|
|
278
285
|
/** A non-null object that is not an array. Functions do not pass. */
|
|
279
286
|
function isRecord(value) {
|
|
280
287
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -382,8 +389,7 @@ function findViteHubDevServerUrl(roots, env) {
|
|
|
382
389
|
}
|
|
383
390
|
return env["VITEHUB_DEV_SERVER_URL"] || void 0;
|
|
384
391
|
}
|
|
385
|
-
|
|
386
|
-
//#region ../internal/src/build/vite.ts
|
|
392
|
+
// ../internal/src/build/vite.ts
|
|
387
393
|
const projectRootDirectoryMarkers = [
|
|
388
394
|
["server", "agents"],
|
|
389
395
|
["server", "channels"],
|
|
@@ -465,7 +471,7 @@ function hasProjectRootDirectoryMarker(root) {
|
|
|
465
471
|
for (const marker of projectRootDirectoryMarkers) try {
|
|
466
472
|
if (statSync(resolve(root, ...marker)).isDirectory()) return true;
|
|
467
473
|
} catch (error) {
|
|
468
|
-
if (error
|
|
474
|
+
if (!isMissingProjectMarker(error)) throw error;
|
|
469
475
|
}
|
|
470
476
|
return false;
|
|
471
477
|
}
|
|
@@ -479,13 +485,16 @@ function hasProjectRootFileMarker(root, markers) {
|
|
|
479
485
|
try {
|
|
480
486
|
if (statSync(resolve(root, ...path)).isFile()) return true;
|
|
481
487
|
} catch (error) {
|
|
482
|
-
if (error
|
|
488
|
+
if (!isMissingProjectMarker(error)) throw error;
|
|
483
489
|
}
|
|
484
490
|
}
|
|
485
491
|
return false;
|
|
486
492
|
}
|
|
487
|
-
|
|
488
|
-
|
|
493
|
+
function isMissingProjectMarker(error) {
|
|
494
|
+
const code = error.code;
|
|
495
|
+
return code === "ENOENT" || code === "ENOTDIR";
|
|
496
|
+
}
|
|
497
|
+
// ../internal/src/invariant.ts
|
|
489
498
|
const invariantDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
490
499
|
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
491
500
|
codes: { INTERNAL_INVARIANT_FAILED: {
|
|
@@ -504,8 +513,7 @@ function invariantError(what) {
|
|
|
504
513
|
function invariant(condition, what) {
|
|
505
514
|
if (!condition) throw invariantError(what);
|
|
506
515
|
}
|
|
507
|
-
|
|
508
|
-
//#region ../internal/src/operation-rpc.ts
|
|
516
|
+
// ../internal/src/operation-rpc.ts
|
|
509
517
|
/** Path of the operation RPC under the app. Dev servers and deployed apps serve it the same way, one birpc call per POST. */
|
|
510
518
|
const operationRpcPath = "/_vitehub/rpc";
|
|
511
519
|
const maximumIdLength = 128;
|
|
@@ -658,8 +666,7 @@ async function callOperationRpc(name, input, send) {
|
|
|
658
666
|
};
|
|
659
667
|
}
|
|
660
668
|
}
|
|
661
|
-
|
|
662
|
-
//#region ../internal/src/console-signature.ts
|
|
669
|
+
// ../internal/src/console-signature.ts
|
|
663
670
|
/**
|
|
664
671
|
* Signed requests to the Console endpoint of an app, `POST /_vitehub/rpc`. Each caller, such as one Console link or one
|
|
665
672
|
* CI job, has an Ed25519 key pair. The app keeps only the public keys, in `VITEHUB_CONSOLE_KEY_<NAME>`, so a copy of
|
|
@@ -788,8 +795,7 @@ function readConsoleSigningKey(env) {
|
|
|
788
795
|
privateKey
|
|
789
796
|
};
|
|
790
797
|
}
|
|
791
|
-
|
|
792
|
-
//#region ../internal/src/standard-schema.ts
|
|
798
|
+
// ../internal/src/standard-schema.ts
|
|
793
799
|
function readOwn(value, key) {
|
|
794
800
|
if (value === null || Object(value) !== value) return;
|
|
795
801
|
try {
|
|
@@ -818,8 +824,7 @@ function standardJsonSchema(schema, direction, target = "draft-2020-12", library
|
|
|
818
824
|
return;
|
|
819
825
|
}
|
|
820
826
|
}
|
|
821
|
-
|
|
822
|
-
//#region ../internal/src/valibot.ts
|
|
827
|
+
// ../internal/src/valibot.ts
|
|
823
828
|
const valibotTargets = /* @__PURE__ */ new Set([
|
|
824
829
|
"draft-07",
|
|
825
830
|
"draft-2020-12",
|
|
@@ -860,8 +865,7 @@ function withValibotJsonSchema(schema, options = {}) {
|
|
|
860
865
|
}
|
|
861
866
|
};
|
|
862
867
|
}
|
|
863
|
-
|
|
864
|
-
//#region ../internal/src/operation-definition.ts
|
|
868
|
+
// ../internal/src/operation-definition.ts
|
|
865
869
|
const nameFormat = /^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*$/;
|
|
866
870
|
const kinds = /* @__PURE__ */ new Set([
|
|
867
871
|
"read",
|
|
@@ -951,8 +955,7 @@ function isSectionId(section) {
|
|
|
951
955
|
function operationInputJsonSchema(operation) {
|
|
952
956
|
return standardJsonSchema(operation.input, "input") ?? { type: "object" };
|
|
953
957
|
}
|
|
954
|
-
|
|
955
|
-
//#region ../internal/src/operations.ts
|
|
958
|
+
// ../internal/src/operations.ts
|
|
956
959
|
/** Header that proves the caller is not a browser page. A foreign page cannot send it without a CORS preflight. */
|
|
957
960
|
const operationRpcHeader = "x-vitehub-console";
|
|
958
961
|
/** Response header of the local dev RPC. Its value is {@link projectRootHash} of the project that the server runs. */
|
|
@@ -1019,11 +1022,16 @@ function operationsOf(value) {
|
|
|
1019
1022
|
/** The CLI namespace and command of an operation. Defaults: the section (or the name prefix) and the verb. */
|
|
1020
1023
|
function operationCliPath(operation) {
|
|
1021
1024
|
const dot = operation.name.indexOf(".");
|
|
1025
|
+
const cli = operationCliOptions(operation);
|
|
1022
1026
|
return {
|
|
1023
|
-
command:
|
|
1024
|
-
namespace:
|
|
1027
|
+
command: cli?.command ?? operation.name.slice(dot + 1),
|
|
1028
|
+
namespace: cli?.namespace ?? (typeof operation.section === "string" ? operation.section : operation.name.slice(0, dot))
|
|
1025
1029
|
};
|
|
1026
1030
|
}
|
|
1031
|
+
/** The CLI options of an operation, or undefined for an operation without options or with `cli: false`. */
|
|
1032
|
+
function operationCliOptions(operation) {
|
|
1033
|
+
return operation.cli || void 0;
|
|
1034
|
+
}
|
|
1027
1035
|
/**
|
|
1028
1036
|
* The MCP tool name of an operation: every character outside `[a-zA-Z0-9_-]` becomes `_`, since clients such as
|
|
1029
1037
|
* Claude reject a dot in a tool name. `content.publish` is `content_publish`.
|
|
@@ -1048,6 +1056,7 @@ function createOperationRegistry(sources) {
|
|
|
1048
1056
|
const operations = [...byName.values()].map((entry) => entry.operation).sort((left, right) => left.name.localeCompare(right.name));
|
|
1049
1057
|
const commands = /* @__PURE__ */ new Map();
|
|
1050
1058
|
for (const operation of operations) {
|
|
1059
|
+
if (operation.cli === false) continue;
|
|
1051
1060
|
const { command, namespace } = operationCliPath(operation);
|
|
1052
1061
|
if (reservedOperationNamespaces.includes(namespace)) throw invalidDefinition(operation.name, `the CLI namespace ${JSON.stringify(namespace)} is reserved for built-in commands. Set cli.namespace to another name.`);
|
|
1053
1062
|
const key = `${namespace} ${command}`;
|
|
@@ -1075,12 +1084,23 @@ function describeInputIssues(issues) {
|
|
|
1075
1084
|
return path ? `${path}: ${issue.message}` : issue.message;
|
|
1076
1085
|
}).join(" ");
|
|
1077
1086
|
}
|
|
1087
|
+
function describeInputFields(schema) {
|
|
1088
|
+
const shapes = (Array.isArray(schema.anyOf) ? schema.anyOf : [schema]).map((shape) => {
|
|
1089
|
+
if (!isRecordOrFunction(shape) || !isRecordOrFunction(shape.properties)) return void 0;
|
|
1090
|
+
const required = Array.isArray(shape.required) ? shape.required : [];
|
|
1091
|
+
const fields = Object.keys(shape.properties).map((field) => required.includes(field) ? field : `${field}?`);
|
|
1092
|
+
return fields.length ? `{ ${fields.join(", ")} }` : "{}";
|
|
1093
|
+
});
|
|
1094
|
+
return shapes.every((shape) => shape !== void 0) ? shapes.join(" or ") : void 0;
|
|
1095
|
+
}
|
|
1078
1096
|
/** Validate `input` with the schema of the operation. Throws `INTERNAL_R0022` with `status: 400`. */
|
|
1079
1097
|
async function parseOperationInput(operation, input) {
|
|
1080
1098
|
const result = await operation.input["~standard"].validate(input ?? {});
|
|
1081
1099
|
if (!result.issues) return result.value;
|
|
1082
|
-
const
|
|
1083
|
-
|
|
1100
|
+
const fields = describeInputFields(operationInputJsonSchema(operation));
|
|
1101
|
+
const issues = describeInputIssues(result.issues);
|
|
1102
|
+
const message = `Invalid input for ${operation.name}. ${issues}${fields ? `${/[.!?]$/.test(issues) ? "" : "."} ${operation.name} takes ${fields}.` : ""}`;
|
|
1103
|
+
throw Object.assign(internalErrorDiagnostics.INTERNAL_R0022({ message }), { status: 400 });
|
|
1084
1104
|
}
|
|
1085
1105
|
/**
|
|
1086
1106
|
* The section that grants a call, or `false` for any Console user. `undefined` means the input names no valid section.
|
|
@@ -1362,5 +1382,4 @@ function table(rows) {
|
|
|
1362
1382
|
const widths = rows[0].map((_, column) => Math.max(...rows.map((row) => row[column].length)));
|
|
1363
1383
|
return rows.map((row) => row.map((cell, column) => column === row.length - 1 ? cell : cell.padEnd(widths[column])).join(" ")).join("\n");
|
|
1364
1384
|
}
|
|
1365
|
-
//#endregion
|
|
1366
1385
|
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 };
|
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-DWWMHBWt.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-B1MnA9cW.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,15 +1,14 @@
|
|
|
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;
|
|
11
11
|
const runtimeLimiters = /* @__PURE__ */ new Map();
|
|
12
|
-
/** The counters of this process, or in app tests the counters of the current test. */
|
|
13
12
|
function limiters() {
|
|
14
13
|
const test = getViteHubTestMode();
|
|
15
14
|
return test ? test.backend("rate-limit", () => /* @__PURE__ */ new Map()) : runtimeLimiters;
|
|
@@ -82,5 +81,4 @@ function getRuntimeRateLimiter(driver, name, policy) {
|
|
|
82
81
|
function listRuntimeRateLimiters(name) {
|
|
83
82
|
return [...limiters().get(name)?.values() ?? []];
|
|
84
83
|
}
|
|
85
|
-
//#endregion
|
|
86
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;
|
|
@@ -76,6 +73,8 @@ interface ViteHubResourceSummary {
|
|
|
76
73
|
owner: string;
|
|
77
74
|
/** Absent when no id is known yet. */
|
|
78
75
|
source?: ViteHubResourceIdSource;
|
|
76
|
+
/** The resource is in the Wrangler config of a standalone Provider Output Worker, not in Nitro's. */
|
|
77
|
+
standalone?: boolean;
|
|
79
78
|
}
|
|
80
79
|
interface ViteHubInspectionContributor {
|
|
81
80
|
definitions?: readonly ViteHubDefinitionInspector[];
|
|
@@ -86,15 +85,11 @@ type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor |
|
|
|
86
85
|
interface ViteHubInspectionPluginMetadata {
|
|
87
86
|
inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
|
|
88
87
|
}
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/discovery.d.ts
|
|
91
88
|
interface RateLimitDiscoveryOptions {
|
|
92
89
|
rootDir: string;
|
|
93
90
|
scanDirs?: string[];
|
|
94
91
|
}
|
|
95
92
|
export declare function discoverRateLimitDeclarations(options: RateLimitDiscoveryOptions): RateLimitDeclaration[];
|
|
96
|
-
//#endregion
|
|
97
|
-
//#region ../internal/src/console.d.ts
|
|
98
93
|
type MaybePromise<T> = T | Promise<T>;
|
|
99
94
|
/** Lists discovered Definitions in a sidebar and shows the selected Definition's fields. */
|
|
100
95
|
interface ViteHubConsoleDefinitionCatalogView {
|
|
@@ -426,8 +421,6 @@ interface ViteHubConsoleDocumentSetup {
|
|
|
426
421
|
*/
|
|
427
422
|
schedule?: ViteHubConsoleDocumentHint;
|
|
428
423
|
}
|
|
429
|
-
//#endregion
|
|
430
|
-
//#region src/inspect.d.ts
|
|
431
424
|
interface RateLimitInspectionOptions {
|
|
432
425
|
projectRoot: string;
|
|
433
426
|
rootDir: string;
|
|
@@ -437,8 +430,6 @@ interface RateLimitInspectionOptions {
|
|
|
437
430
|
export declare function inspectRateLimitDefinitions(options: RateLimitInspectionOptions): ViteHubDefinitionSummary[];
|
|
438
431
|
/** Console section that lists discovered Rate Limit Definitions. `vitehub inspect definitions` reads the same data. */
|
|
439
432
|
export declare const rateLimitConsoleSection: ViteHubConsoleSectionContribution<RateLimitInspectionOptions>;
|
|
440
|
-
//#endregion
|
|
441
|
-
//#region src/vite.d.ts
|
|
442
433
|
export type RateLimitVitePluginOptions = RateLimitOptions;
|
|
443
434
|
export type RateLimitVitePlugin = Plugin & {
|
|
444
435
|
vitehub: ViteHubCliPluginMetadata & ViteHubInspectionPluginMetadata & DurabilityPluginMetadata & {
|
|
@@ -446,5 +437,4 @@ export type RateLimitVitePlugin = Plugin & {
|
|
|
446
437
|
};
|
|
447
438
|
};
|
|
448
439
|
export declare function hubRateLimit(options?: RateLimitVitePluginOptions): RateLimitVitePlugin;
|
|
449
|
-
//#endregion
|
|
450
440
|
export type { RateLimitInspectionOptions };
|