@sudobility/ratelimit_service 1.0.27 → 1.0.28
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 +79 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# @sudobility/ratelimit_service
|
|
2
|
+
|
|
3
|
+
Shared rate limiting backend library based on RevenueCat entitlements with Hono middleware and Drizzle ORM schema.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @sudobility/ratelimit_service
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Peer Dependencies
|
|
12
|
+
|
|
13
|
+
- `drizzle-orm`
|
|
14
|
+
- `hono`
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import {
|
|
20
|
+
RevenueCatHelper,
|
|
21
|
+
EntitlementHelper,
|
|
22
|
+
RateLimitChecker,
|
|
23
|
+
createRateLimitMiddleware,
|
|
24
|
+
} from '@sudobility/ratelimit_service';
|
|
25
|
+
import { rateLimitCounters } from '@sudobility/ratelimit_service/schema';
|
|
26
|
+
|
|
27
|
+
// Middleware setup
|
|
28
|
+
const middleware = createRateLimitMiddleware({
|
|
29
|
+
revenueCatApiKey: process.env.REVENUECAT_API_KEY!,
|
|
30
|
+
rateLimitsConfig: {
|
|
31
|
+
none: { hourly: 5, daily: 20, monthly: 100 },
|
|
32
|
+
pro: { hourly: undefined, daily: undefined, monthly: undefined },
|
|
33
|
+
},
|
|
34
|
+
db,
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## API
|
|
39
|
+
|
|
40
|
+
### Key Classes
|
|
41
|
+
|
|
42
|
+
| Class | Purpose | Key Method |
|
|
43
|
+
|-------|---------|------------|
|
|
44
|
+
| `RevenueCatHelper` | Fetch user entitlements from RevenueCat API | `getSubscriptionInfo(userId)` |
|
|
45
|
+
| `EntitlementHelper` | Map entitlements to rate limits | `getRateLimits(entitlements)` |
|
|
46
|
+
| `RateLimitChecker` | Check limits and increment DB counters | `checkAndIncrement(userId, limits, subscriptionStartedAt)` |
|
|
47
|
+
| `RateLimitRouteHandler` | HTTP route handler for rate limit queries | Configured via `RateLimitRouteHandlerConfig` |
|
|
48
|
+
|
|
49
|
+
### Middleware
|
|
50
|
+
|
|
51
|
+
`createRateLimitMiddleware(config)` -- Hono middleware factory
|
|
52
|
+
|
|
53
|
+
### Schema
|
|
54
|
+
|
|
55
|
+
`rateLimitCounters` -- Drizzle schema template (consumers copy to their own `db/schema.ts`)
|
|
56
|
+
|
|
57
|
+
### Sub-path Exports
|
|
58
|
+
|
|
59
|
+
- `@sudobility/ratelimit_service` -- main entry (classes, types, utilities)
|
|
60
|
+
- `@sudobility/ratelimit_service/middleware/hono` -- middleware only
|
|
61
|
+
- `@sudobility/ratelimit_service/schema` -- Drizzle schema
|
|
62
|
+
|
|
63
|
+
### Key Types
|
|
64
|
+
|
|
65
|
+
`RateLimits`, `RateLimitsConfig`, `RateLimitCheckResult`, `PeriodType`
|
|
66
|
+
|
|
67
|
+
## Development
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
bun run verify # All checks + build (typecheck -> lint -> test -> build)
|
|
71
|
+
bun test # Run tests
|
|
72
|
+
bun run lint # ESLint
|
|
73
|
+
bun run typecheck # TypeScript check
|
|
74
|
+
bun run build # Build ESM + CJS
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
BUSL-1.1
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sudobility/ratelimit_service",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.28",
|
|
4
4
|
"description": "Shared rate limiting library based on RevenueCat entitlements",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -48,14 +48,14 @@
|
|
|
48
48
|
"author": "Sudobility",
|
|
49
49
|
"license": "BUSL-1.1",
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@sudobility/types": "^1.9.
|
|
51
|
+
"@sudobility/types": "^1.9.57",
|
|
52
52
|
"drizzle-orm": "^0.45.0",
|
|
53
53
|
"hono": "^4.0.0",
|
|
54
54
|
"postgres": "^3.4.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"vitest": "^4.0.4",
|
|
58
|
-
"@sudobility/types": "^1.9.
|
|
58
|
+
"@sudobility/types": "^1.9.57",
|
|
59
59
|
"@types/bun": "latest",
|
|
60
60
|
"@types/node": "^24.10.1",
|
|
61
61
|
"@typescript-eslint/eslint-plugin": "^8.50.0",
|