@orpc/experimental-ratelimit 0.0.1 → 1.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -12,6 +12,12 @@ interface RatelimitHandlerPluginContext {
12
12
  ratelimitResult?: RatelimiterLimitResult;
13
13
  };
14
14
  }
15
+ /**
16
+ * Automatically adds HTTP rate-limiting headers (RateLimit-* and Retry-After) to responses
17
+ * when used with middleware created by createRatelimitMiddleware.
18
+ *
19
+ * @see {@link https://orpc.unnoq.com/docs/helpers/ratelimit#handler-plugin Ratelimit handler plugin}
20
+ */
15
21
  declare class RatelimitHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
16
22
  init(options: StandardHandlerOptions<T>): void;
17
23
  }
@@ -47,6 +53,12 @@ interface CreateRatelimitMiddlewareOptions<TInContext extends Context, TInput, T
47
53
  */
48
54
  dedupe?: boolean;
49
55
  }
56
+ /**
57
+ * Creates a middleware that enforces rate limits in oRPC procedures.
58
+ * Supports per-request deduplication and integrates with the ratelimit handler plugin.
59
+ *
60
+ * @see {@link https://orpc.unnoq.com/docs/helpers/ratelimit#createratelimitmiddleware Ratelimit middleware}
61
+ */
50
62
  declare function createRatelimitMiddleware<TInContext extends Context, TInput = unknown, TMeta extends Meta = Record<never, never>>({ dedupe, ...options }: CreateRatelimitMiddlewareOptions<TInContext, TInput, TMeta>): Middleware<TInContext, Record<never, never>, TInput, any, any, TMeta>;
51
63
 
52
64
  export { RATELIMIT_HANDLER_CONTEXT_SYMBOL, RATELIMIT_MIDDLEWARE_CONTEXT_SYMBOL, RatelimitHandlerPlugin, Ratelimiter, RatelimiterLimitResult, createRatelimitMiddleware };
package/dist/index.d.ts CHANGED
@@ -12,6 +12,12 @@ interface RatelimitHandlerPluginContext {
12
12
  ratelimitResult?: RatelimiterLimitResult;
13
13
  };
14
14
  }
15
+ /**
16
+ * Automatically adds HTTP rate-limiting headers (RateLimit-* and Retry-After) to responses
17
+ * when used with middleware created by createRatelimitMiddleware.
18
+ *
19
+ * @see {@link https://orpc.unnoq.com/docs/helpers/ratelimit#handler-plugin Ratelimit handler plugin}
20
+ */
15
21
  declare class RatelimitHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
16
22
  init(options: StandardHandlerOptions<T>): void;
17
23
  }
@@ -47,6 +53,12 @@ interface CreateRatelimitMiddlewareOptions<TInContext extends Context, TInput, T
47
53
  */
48
54
  dedupe?: boolean;
49
55
  }
56
+ /**
57
+ * Creates a middleware that enforces rate limits in oRPC procedures.
58
+ * Supports per-request deduplication and integrates with the ratelimit handler plugin.
59
+ *
60
+ * @see {@link https://orpc.unnoq.com/docs/helpers/ratelimit#createratelimitmiddleware Ratelimit middleware}
61
+ */
50
62
  declare function createRatelimitMiddleware<TInContext extends Context, TInput = unknown, TMeta extends Meta = Record<never, never>>({ dedupe, ...options }: CreateRatelimitMiddlewareOptions<TInContext, TInput, TMeta>): Middleware<TInContext, Record<never, never>, TInput, any, any, TMeta>;
51
63
 
52
64
  export { RATELIMIT_HANDLER_CONTEXT_SYMBOL, RATELIMIT_MIDDLEWARE_CONTEXT_SYMBOL, RatelimitHandlerPlugin, Ratelimiter, RatelimiterLimitResult, createRatelimitMiddleware };
package/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { COMMON_ORPC_ERROR_DEFS } from '@orpc/client';
1
2
  import { ORPCError } from '@orpc/server';
2
3
  import { value, toArray } from '@orpc/shared';
3
4
 
@@ -24,7 +25,7 @@ class RatelimitHandlerPlugin {
24
25
  "ratelimit-limit": handlerContext.ratelimitResult.limit?.toString(),
25
26
  "ratelimit-remaining": handlerContext.ratelimitResult.remaining?.toString(),
26
27
  "ratelimit-reset": handlerContext.ratelimitResult.reset?.toString(),
27
- "retry-after": !handlerContext.ratelimitResult.success && result.response.status === 429 && handlerContext.ratelimitResult.reset !== void 0 ? Math.ceil((handlerContext.ratelimitResult.reset - Date.now()) / 1e3).toString() : void 0
28
+ "retry-after": !handlerContext.ratelimitResult.success && result.response.status === COMMON_ORPC_ERROR_DEFS.TOO_MANY_REQUESTS.status && handlerContext.ratelimitResult.reset !== void 0 ? Math.max(0, Math.ceil((handlerContext.ratelimitResult.reset - Date.now()) / 1e3)).toString() : void 0
28
29
  }
29
30
  }
30
31
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/experimental-ratelimit",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "1.11.1",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -47,10 +47,10 @@
47
47
  }
48
48
  },
49
49
  "dependencies": {
50
- "@orpc/client": "1.10.3",
51
- "@orpc/server": "1.10.3",
52
- "@orpc/standard-server": "1.10.3",
53
- "@orpc/shared": "1.10.3"
50
+ "@orpc/client": "1.11.1",
51
+ "@orpc/shared": "1.11.1",
52
+ "@orpc/standard-server": "1.11.1",
53
+ "@orpc/server": "1.11.1"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@upstash/ratelimit": "^2.0.7",