@sudobility/ratelimit_service 1.0.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/CLAUDE.md +160 -0
- package/dist/helpers/EntitlementHelper.cjs +75 -0
- package/dist/helpers/EntitlementHelper.d.ts +52 -0
- package/dist/helpers/EntitlementHelper.d.ts.map +1 -0
- package/dist/helpers/EntitlementHelper.js +75 -0
- package/dist/helpers/EntitlementHelper.js.map +1 -0
- package/dist/helpers/RateLimitChecker.cjs +264 -0
- package/dist/helpers/RateLimitChecker.d.ts +90 -0
- package/dist/helpers/RateLimitChecker.d.ts.map +1 -0
- package/dist/helpers/RateLimitChecker.js +264 -0
- package/dist/helpers/RateLimitChecker.js.map +1 -0
- package/dist/helpers/RateLimitRouteHandler.cjs +191 -0
- package/dist/helpers/RateLimitRouteHandler.d.ts +70 -0
- package/dist/helpers/RateLimitRouteHandler.d.ts.map +1 -0
- package/dist/helpers/RateLimitRouteHandler.js +191 -0
- package/dist/helpers/RateLimitRouteHandler.js.map +1 -0
- package/dist/helpers/RevenueCatHelper.cjs +96 -0
- package/dist/helpers/RevenueCatHelper.d.ts +51 -0
- package/dist/helpers/RevenueCatHelper.d.ts.map +1 -0
- package/dist/helpers/RevenueCatHelper.js +96 -0
- package/dist/helpers/RevenueCatHelper.js.map +1 -0
- package/dist/helpers/index.cjs +10 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +10 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/index.cjs +36 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/hono.cjs +94 -0
- package/dist/middleware/hono.d.ts +63 -0
- package/dist/middleware/hono.d.ts.map +1 -0
- package/dist/middleware/hono.js +94 -0
- package/dist/middleware/hono.js.map +1 -0
- package/dist/schema/rate-limits.cjs +136 -0
- package/dist/schema/rate-limits.d.ts +333 -0
- package/dist/schema/rate-limits.d.ts.map +1 -0
- package/dist/schema/rate-limits.js +136 -0
- package/dist/schema/rate-limits.js.map +1 -0
- package/dist/types/entitlements.cjs +9 -0
- package/dist/types/entitlements.d.ts +29 -0
- package/dist/types/entitlements.d.ts.map +1 -0
- package/dist/types/entitlements.js +9 -0
- package/dist/types/entitlements.js.map +1 -0
- package/dist/types/index.cjs +20 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +20 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/rate-limits.cjs +3 -0
- package/dist/types/rate-limits.d.ts +34 -0
- package/dist/types/rate-limits.d.ts.map +1 -0
- package/dist/types/rate-limits.js +3 -0
- package/dist/types/rate-limits.js.map +1 -0
- package/dist/types/responses.cjs +13 -0
- package/dist/types/responses.d.ts +85 -0
- package/dist/types/responses.d.ts.map +1 -0
- package/dist/types/responses.js +13 -0
- package/dist/types/responses.js.map +1 -0
- package/dist/utils/time.cjs +180 -0
- package/dist/utils/time.d.ts +80 -0
- package/dist/utils/time.d.ts.map +1 -0
- package/dist/utils/time.js +180 -0
- package/dist/utils/time.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drizzle schema and database initialization for rate limit tracking.
|
|
3
|
+
*
|
|
4
|
+
* Provides:
|
|
5
|
+
* - createRateLimitCountersTable: Factory for Drizzle table with custom schema
|
|
6
|
+
* - initRateLimitTable: SQL initialization for the table
|
|
7
|
+
* - Default rateLimitCounters table for public schema
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Create a rate limit counters table for a specific PostgreSQL schema.
|
|
11
|
+
*
|
|
12
|
+
* @param schema - The Drizzle pgSchema object (e.g., pgSchema("shapeshyft"))
|
|
13
|
+
* @param indexPrefix - Prefix for index names to avoid conflicts
|
|
14
|
+
* @returns Drizzle table definition
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { pgSchema } from "drizzle-orm/pg-core";
|
|
19
|
+
* import { createRateLimitCountersTable } from "@sudobility/ratelimit_service";
|
|
20
|
+
*
|
|
21
|
+
* const mySchema = pgSchema("myapp");
|
|
22
|
+
* export const rateLimitCounters = createRateLimitCountersTable(mySchema, "myapp");
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function createRateLimitCountersTable(schema: any, indexPrefix: string): any;
|
|
26
|
+
/**
|
|
27
|
+
* Create a rate limit counters table for the public schema.
|
|
28
|
+
*
|
|
29
|
+
* @param indexPrefix - Prefix for index names
|
|
30
|
+
* @returns Drizzle table definition
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { createRateLimitCountersTablePublic } from "@sudobility/ratelimit_service";
|
|
35
|
+
*
|
|
36
|
+
* export const rateLimitCounters = createRateLimitCountersTablePublic("sudojo");
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function createRateLimitCountersTablePublic(indexPrefix: string): import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
40
|
+
name: "rate_limit_counters";
|
|
41
|
+
schema: undefined;
|
|
42
|
+
columns: {
|
|
43
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
44
|
+
name: "id";
|
|
45
|
+
tableName: "rate_limit_counters";
|
|
46
|
+
dataType: "string";
|
|
47
|
+
columnType: "PgUUID";
|
|
48
|
+
data: string;
|
|
49
|
+
driverParam: string;
|
|
50
|
+
notNull: true;
|
|
51
|
+
hasDefault: true;
|
|
52
|
+
isPrimaryKey: true;
|
|
53
|
+
isAutoincrement: false;
|
|
54
|
+
hasRuntimeDefault: false;
|
|
55
|
+
enumValues: undefined;
|
|
56
|
+
baseColumn: never;
|
|
57
|
+
identity: undefined;
|
|
58
|
+
generated: undefined;
|
|
59
|
+
}, {}, {}>;
|
|
60
|
+
user_id: import("drizzle-orm/pg-core").PgColumn<{
|
|
61
|
+
name: "user_id";
|
|
62
|
+
tableName: "rate_limit_counters";
|
|
63
|
+
dataType: "string";
|
|
64
|
+
columnType: "PgVarchar";
|
|
65
|
+
data: string;
|
|
66
|
+
driverParam: string;
|
|
67
|
+
notNull: true;
|
|
68
|
+
hasDefault: false;
|
|
69
|
+
isPrimaryKey: false;
|
|
70
|
+
isAutoincrement: false;
|
|
71
|
+
hasRuntimeDefault: false;
|
|
72
|
+
enumValues: [string, ...string[]];
|
|
73
|
+
baseColumn: never;
|
|
74
|
+
identity: undefined;
|
|
75
|
+
generated: undefined;
|
|
76
|
+
}, {}, {
|
|
77
|
+
length: 128;
|
|
78
|
+
}>;
|
|
79
|
+
period_type: import("drizzle-orm/pg-core").PgColumn<{
|
|
80
|
+
name: "period_type";
|
|
81
|
+
tableName: "rate_limit_counters";
|
|
82
|
+
dataType: "string";
|
|
83
|
+
columnType: "PgVarchar";
|
|
84
|
+
data: string;
|
|
85
|
+
driverParam: string;
|
|
86
|
+
notNull: true;
|
|
87
|
+
hasDefault: false;
|
|
88
|
+
isPrimaryKey: false;
|
|
89
|
+
isAutoincrement: false;
|
|
90
|
+
hasRuntimeDefault: false;
|
|
91
|
+
enumValues: [string, ...string[]];
|
|
92
|
+
baseColumn: never;
|
|
93
|
+
identity: undefined;
|
|
94
|
+
generated: undefined;
|
|
95
|
+
}, {}, {
|
|
96
|
+
length: 16;
|
|
97
|
+
}>;
|
|
98
|
+
period_start: import("drizzle-orm/pg-core").PgColumn<{
|
|
99
|
+
name: "period_start";
|
|
100
|
+
tableName: "rate_limit_counters";
|
|
101
|
+
dataType: "date";
|
|
102
|
+
columnType: "PgTimestamp";
|
|
103
|
+
data: Date;
|
|
104
|
+
driverParam: string;
|
|
105
|
+
notNull: true;
|
|
106
|
+
hasDefault: false;
|
|
107
|
+
isPrimaryKey: false;
|
|
108
|
+
isAutoincrement: false;
|
|
109
|
+
hasRuntimeDefault: false;
|
|
110
|
+
enumValues: undefined;
|
|
111
|
+
baseColumn: never;
|
|
112
|
+
identity: undefined;
|
|
113
|
+
generated: undefined;
|
|
114
|
+
}, {}, {}>;
|
|
115
|
+
request_count: import("drizzle-orm/pg-core").PgColumn<{
|
|
116
|
+
name: "request_count";
|
|
117
|
+
tableName: "rate_limit_counters";
|
|
118
|
+
dataType: "number";
|
|
119
|
+
columnType: "PgInteger";
|
|
120
|
+
data: number;
|
|
121
|
+
driverParam: string | number;
|
|
122
|
+
notNull: true;
|
|
123
|
+
hasDefault: true;
|
|
124
|
+
isPrimaryKey: false;
|
|
125
|
+
isAutoincrement: false;
|
|
126
|
+
hasRuntimeDefault: false;
|
|
127
|
+
enumValues: undefined;
|
|
128
|
+
baseColumn: never;
|
|
129
|
+
identity: undefined;
|
|
130
|
+
generated: undefined;
|
|
131
|
+
}, {}, {}>;
|
|
132
|
+
created_at: import("drizzle-orm/pg-core").PgColumn<{
|
|
133
|
+
name: "created_at";
|
|
134
|
+
tableName: "rate_limit_counters";
|
|
135
|
+
dataType: "date";
|
|
136
|
+
columnType: "PgTimestamp";
|
|
137
|
+
data: Date;
|
|
138
|
+
driverParam: string;
|
|
139
|
+
notNull: false;
|
|
140
|
+
hasDefault: true;
|
|
141
|
+
isPrimaryKey: false;
|
|
142
|
+
isAutoincrement: false;
|
|
143
|
+
hasRuntimeDefault: false;
|
|
144
|
+
enumValues: undefined;
|
|
145
|
+
baseColumn: never;
|
|
146
|
+
identity: undefined;
|
|
147
|
+
generated: undefined;
|
|
148
|
+
}, {}, {}>;
|
|
149
|
+
updated_at: import("drizzle-orm/pg-core").PgColumn<{
|
|
150
|
+
name: "updated_at";
|
|
151
|
+
tableName: "rate_limit_counters";
|
|
152
|
+
dataType: "date";
|
|
153
|
+
columnType: "PgTimestamp";
|
|
154
|
+
data: Date;
|
|
155
|
+
driverParam: string;
|
|
156
|
+
notNull: false;
|
|
157
|
+
hasDefault: true;
|
|
158
|
+
isPrimaryKey: false;
|
|
159
|
+
isAutoincrement: false;
|
|
160
|
+
hasRuntimeDefault: false;
|
|
161
|
+
enumValues: undefined;
|
|
162
|
+
baseColumn: never;
|
|
163
|
+
identity: undefined;
|
|
164
|
+
generated: undefined;
|
|
165
|
+
}, {}, {}>;
|
|
166
|
+
};
|
|
167
|
+
dialect: "pg";
|
|
168
|
+
}>;
|
|
169
|
+
/**
|
|
170
|
+
* Default rate limit counters table for public schema.
|
|
171
|
+
* Use createRateLimitCountersTable for custom schemas.
|
|
172
|
+
*/
|
|
173
|
+
export declare const rateLimitCounters: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
174
|
+
name: "rate_limit_counters";
|
|
175
|
+
schema: undefined;
|
|
176
|
+
columns: {
|
|
177
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
178
|
+
name: "id";
|
|
179
|
+
tableName: "rate_limit_counters";
|
|
180
|
+
dataType: "string";
|
|
181
|
+
columnType: "PgUUID";
|
|
182
|
+
data: string;
|
|
183
|
+
driverParam: string;
|
|
184
|
+
notNull: true;
|
|
185
|
+
hasDefault: true;
|
|
186
|
+
isPrimaryKey: true;
|
|
187
|
+
isAutoincrement: false;
|
|
188
|
+
hasRuntimeDefault: false;
|
|
189
|
+
enumValues: undefined;
|
|
190
|
+
baseColumn: never;
|
|
191
|
+
identity: undefined;
|
|
192
|
+
generated: undefined;
|
|
193
|
+
}, {}, {}>;
|
|
194
|
+
user_id: import("drizzle-orm/pg-core").PgColumn<{
|
|
195
|
+
name: "user_id";
|
|
196
|
+
tableName: "rate_limit_counters";
|
|
197
|
+
dataType: "string";
|
|
198
|
+
columnType: "PgVarchar";
|
|
199
|
+
data: string;
|
|
200
|
+
driverParam: string;
|
|
201
|
+
notNull: true;
|
|
202
|
+
hasDefault: false;
|
|
203
|
+
isPrimaryKey: false;
|
|
204
|
+
isAutoincrement: false;
|
|
205
|
+
hasRuntimeDefault: false;
|
|
206
|
+
enumValues: [string, ...string[]];
|
|
207
|
+
baseColumn: never;
|
|
208
|
+
identity: undefined;
|
|
209
|
+
generated: undefined;
|
|
210
|
+
}, {}, {
|
|
211
|
+
length: 128;
|
|
212
|
+
}>;
|
|
213
|
+
period_type: import("drizzle-orm/pg-core").PgColumn<{
|
|
214
|
+
name: "period_type";
|
|
215
|
+
tableName: "rate_limit_counters";
|
|
216
|
+
dataType: "string";
|
|
217
|
+
columnType: "PgVarchar";
|
|
218
|
+
data: string;
|
|
219
|
+
driverParam: string;
|
|
220
|
+
notNull: true;
|
|
221
|
+
hasDefault: false;
|
|
222
|
+
isPrimaryKey: false;
|
|
223
|
+
isAutoincrement: false;
|
|
224
|
+
hasRuntimeDefault: false;
|
|
225
|
+
enumValues: [string, ...string[]];
|
|
226
|
+
baseColumn: never;
|
|
227
|
+
identity: undefined;
|
|
228
|
+
generated: undefined;
|
|
229
|
+
}, {}, {
|
|
230
|
+
length: 16;
|
|
231
|
+
}>;
|
|
232
|
+
period_start: import("drizzle-orm/pg-core").PgColumn<{
|
|
233
|
+
name: "period_start";
|
|
234
|
+
tableName: "rate_limit_counters";
|
|
235
|
+
dataType: "date";
|
|
236
|
+
columnType: "PgTimestamp";
|
|
237
|
+
data: Date;
|
|
238
|
+
driverParam: string;
|
|
239
|
+
notNull: true;
|
|
240
|
+
hasDefault: false;
|
|
241
|
+
isPrimaryKey: false;
|
|
242
|
+
isAutoincrement: false;
|
|
243
|
+
hasRuntimeDefault: false;
|
|
244
|
+
enumValues: undefined;
|
|
245
|
+
baseColumn: never;
|
|
246
|
+
identity: undefined;
|
|
247
|
+
generated: undefined;
|
|
248
|
+
}, {}, {}>;
|
|
249
|
+
request_count: import("drizzle-orm/pg-core").PgColumn<{
|
|
250
|
+
name: "request_count";
|
|
251
|
+
tableName: "rate_limit_counters";
|
|
252
|
+
dataType: "number";
|
|
253
|
+
columnType: "PgInteger";
|
|
254
|
+
data: number;
|
|
255
|
+
driverParam: string | number;
|
|
256
|
+
notNull: true;
|
|
257
|
+
hasDefault: true;
|
|
258
|
+
isPrimaryKey: false;
|
|
259
|
+
isAutoincrement: false;
|
|
260
|
+
hasRuntimeDefault: false;
|
|
261
|
+
enumValues: undefined;
|
|
262
|
+
baseColumn: never;
|
|
263
|
+
identity: undefined;
|
|
264
|
+
generated: undefined;
|
|
265
|
+
}, {}, {}>;
|
|
266
|
+
created_at: import("drizzle-orm/pg-core").PgColumn<{
|
|
267
|
+
name: "created_at";
|
|
268
|
+
tableName: "rate_limit_counters";
|
|
269
|
+
dataType: "date";
|
|
270
|
+
columnType: "PgTimestamp";
|
|
271
|
+
data: Date;
|
|
272
|
+
driverParam: string;
|
|
273
|
+
notNull: false;
|
|
274
|
+
hasDefault: true;
|
|
275
|
+
isPrimaryKey: false;
|
|
276
|
+
isAutoincrement: false;
|
|
277
|
+
hasRuntimeDefault: false;
|
|
278
|
+
enumValues: undefined;
|
|
279
|
+
baseColumn: never;
|
|
280
|
+
identity: undefined;
|
|
281
|
+
generated: undefined;
|
|
282
|
+
}, {}, {}>;
|
|
283
|
+
updated_at: import("drizzle-orm/pg-core").PgColumn<{
|
|
284
|
+
name: "updated_at";
|
|
285
|
+
tableName: "rate_limit_counters";
|
|
286
|
+
dataType: "date";
|
|
287
|
+
columnType: "PgTimestamp";
|
|
288
|
+
data: Date;
|
|
289
|
+
driverParam: string;
|
|
290
|
+
notNull: false;
|
|
291
|
+
hasDefault: true;
|
|
292
|
+
isPrimaryKey: false;
|
|
293
|
+
isAutoincrement: false;
|
|
294
|
+
hasRuntimeDefault: false;
|
|
295
|
+
enumValues: undefined;
|
|
296
|
+
baseColumn: never;
|
|
297
|
+
identity: undefined;
|
|
298
|
+
generated: undefined;
|
|
299
|
+
}, {}, {}>;
|
|
300
|
+
};
|
|
301
|
+
dialect: "pg";
|
|
302
|
+
}>;
|
|
303
|
+
/**
|
|
304
|
+
* TypeScript type for the rate_limit_counters table row (select)
|
|
305
|
+
*/
|
|
306
|
+
export type RateLimitCounterRecord = typeof rateLimitCounters.$inferSelect;
|
|
307
|
+
/**
|
|
308
|
+
* TypeScript type for inserting into rate_limit_counters table
|
|
309
|
+
*/
|
|
310
|
+
export type NewRateLimitCounterRecord = typeof rateLimitCounters.$inferInsert;
|
|
311
|
+
/**
|
|
312
|
+
* Initialize the rate limit counters table in the database.
|
|
313
|
+
*
|
|
314
|
+
* @param client - postgres-js client instance
|
|
315
|
+
* @param schemaName - PostgreSQL schema name (e.g., "shapeshyft", "whisperly", or null for public)
|
|
316
|
+
* @param indexPrefix - Prefix for index names to avoid conflicts
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```typescript
|
|
320
|
+
* import postgres from "postgres";
|
|
321
|
+
* import { initRateLimitTable } from "@sudobility/ratelimit_service";
|
|
322
|
+
*
|
|
323
|
+
* const client = postgres(connectionString);
|
|
324
|
+
*
|
|
325
|
+
* // For public schema
|
|
326
|
+
* await initRateLimitTable(client, null, "sudojo");
|
|
327
|
+
*
|
|
328
|
+
* // For custom schema
|
|
329
|
+
* await initRateLimitTable(client, "shapeshyft", "shapeshyft");
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
export declare function initRateLimitTable(client: ReturnType<typeof import("postgres")>, schemaName: string | null, indexPrefix: string): Promise<void>;
|
|
333
|
+
//# sourceMappingURL=rate-limits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limits.d.ts","sourceRoot":"","sources":["../../src/schema/rate-limits.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAYH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,GAAG,EACX,WAAW,EAAE,MAAM,OAyBpB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kCAAkC,CAAC,WAAW,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwBrE;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsB7B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,OAAO,iBAAiB,CAAC,YAAY,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,OAAO,iBAAiB,CAAC,YAAY,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,UAAU,CAAC,cAAc,UAAU,CAAC,CAAC,EAC7C,UAAU,EAAE,MAAM,GAAG,IAAI,EACzB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CA6Bf"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Drizzle schema and database initialization for rate limit tracking.
|
|
4
|
+
*
|
|
5
|
+
* Provides:
|
|
6
|
+
* - createRateLimitCountersTable: Factory for Drizzle table with custom schema
|
|
7
|
+
* - initRateLimitTable: SQL initialization for the table
|
|
8
|
+
* - Default rateLimitCounters table for public schema
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.rateLimitCounters = void 0;
|
|
12
|
+
exports.createRateLimitCountersTable = createRateLimitCountersTable;
|
|
13
|
+
exports.createRateLimitCountersTablePublic = createRateLimitCountersTablePublic;
|
|
14
|
+
exports.initRateLimitTable = initRateLimitTable;
|
|
15
|
+
const pg_core_1 = require("drizzle-orm/pg-core");
|
|
16
|
+
/**
|
|
17
|
+
* Create a rate limit counters table for a specific PostgreSQL schema.
|
|
18
|
+
*
|
|
19
|
+
* @param schema - The Drizzle pgSchema object (e.g., pgSchema("shapeshyft"))
|
|
20
|
+
* @param indexPrefix - Prefix for index names to avoid conflicts
|
|
21
|
+
* @returns Drizzle table definition
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { pgSchema } from "drizzle-orm/pg-core";
|
|
26
|
+
* import { createRateLimitCountersTable } from "@sudobility/ratelimit_service";
|
|
27
|
+
*
|
|
28
|
+
* const mySchema = pgSchema("myapp");
|
|
29
|
+
* export const rateLimitCounters = createRateLimitCountersTable(mySchema, "myapp");
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
function createRateLimitCountersTable(schema, indexPrefix) {
|
|
33
|
+
return schema.table("rate_limit_counters", {
|
|
34
|
+
id: (0, pg_core_1.uuid)("id").primaryKey().defaultRandom(),
|
|
35
|
+
user_id: (0, pg_core_1.varchar)("user_id", { length: 128 }).notNull(),
|
|
36
|
+
period_type: (0, pg_core_1.varchar)("period_type", { length: 16 }).notNull(),
|
|
37
|
+
period_start: (0, pg_core_1.timestamp)("period_start", { withTimezone: true }).notNull(),
|
|
38
|
+
request_count: (0, pg_core_1.integer)("request_count").notNull().default(0),
|
|
39
|
+
created_at: (0, pg_core_1.timestamp)("created_at", { withTimezone: true }).defaultNow(),
|
|
40
|
+
updated_at: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true }).defaultNow(),
|
|
41
|
+
}, (table) => ({
|
|
42
|
+
userPeriodUniqueIdx: (0, pg_core_1.uniqueIndex)(`${indexPrefix}_rate_limit_user_period_idx`).on(table.user_id, table.period_type, table.period_start),
|
|
43
|
+
userTypeIdx: (0, pg_core_1.index)(`${indexPrefix}_rate_limit_user_type_idx`).on(table.user_id, table.period_type),
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create a rate limit counters table for the public schema.
|
|
48
|
+
*
|
|
49
|
+
* @param indexPrefix - Prefix for index names
|
|
50
|
+
* @returns Drizzle table definition
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { createRateLimitCountersTablePublic } from "@sudobility/ratelimit_service";
|
|
55
|
+
*
|
|
56
|
+
* export const rateLimitCounters = createRateLimitCountersTablePublic("sudojo");
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
function createRateLimitCountersTablePublic(indexPrefix) {
|
|
60
|
+
return (0, pg_core_1.pgTable)("rate_limit_counters", {
|
|
61
|
+
id: (0, pg_core_1.uuid)("id").primaryKey().defaultRandom(),
|
|
62
|
+
user_id: (0, pg_core_1.varchar)("user_id", { length: 128 }).notNull(),
|
|
63
|
+
period_type: (0, pg_core_1.varchar)("period_type", { length: 16 }).notNull(),
|
|
64
|
+
period_start: (0, pg_core_1.timestamp)("period_start", { withTimezone: true }).notNull(),
|
|
65
|
+
request_count: (0, pg_core_1.integer)("request_count").notNull().default(0),
|
|
66
|
+
created_at: (0, pg_core_1.timestamp)("created_at", { withTimezone: true }).defaultNow(),
|
|
67
|
+
updated_at: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true }).defaultNow(),
|
|
68
|
+
}, table => ({
|
|
69
|
+
userPeriodUniqueIdx: (0, pg_core_1.uniqueIndex)(`${indexPrefix}_rate_limit_user_period_idx`).on(table.user_id, table.period_type, table.period_start),
|
|
70
|
+
userTypeIdx: (0, pg_core_1.index)(`${indexPrefix}_rate_limit_user_type_idx`).on(table.user_id, table.period_type),
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Default rate limit counters table for public schema.
|
|
75
|
+
* Use createRateLimitCountersTable for custom schemas.
|
|
76
|
+
*/
|
|
77
|
+
exports.rateLimitCounters = (0, pg_core_1.pgTable)("rate_limit_counters", {
|
|
78
|
+
id: (0, pg_core_1.uuid)("id").primaryKey().defaultRandom(),
|
|
79
|
+
user_id: (0, pg_core_1.varchar)("user_id", { length: 128 }).notNull(),
|
|
80
|
+
period_type: (0, pg_core_1.varchar)("period_type", { length: 16 }).notNull(),
|
|
81
|
+
period_start: (0, pg_core_1.timestamp)("period_start", { withTimezone: true }).notNull(),
|
|
82
|
+
request_count: (0, pg_core_1.integer)("request_count").notNull().default(0),
|
|
83
|
+
created_at: (0, pg_core_1.timestamp)("created_at", { withTimezone: true }).defaultNow(),
|
|
84
|
+
updated_at: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true }).defaultNow(),
|
|
85
|
+
}, table => ({
|
|
86
|
+
userPeriodUniqueIdx: (0, pg_core_1.uniqueIndex)("rate_limit_counters_user_period_idx").on(table.user_id, table.period_type, table.period_start),
|
|
87
|
+
userTypeIdx: (0, pg_core_1.index)("rate_limit_counters_user_type_idx").on(table.user_id, table.period_type),
|
|
88
|
+
}));
|
|
89
|
+
/**
|
|
90
|
+
* Initialize the rate limit counters table in the database.
|
|
91
|
+
*
|
|
92
|
+
* @param client - postgres-js client instance
|
|
93
|
+
* @param schemaName - PostgreSQL schema name (e.g., "shapeshyft", "whisperly", or null for public)
|
|
94
|
+
* @param indexPrefix - Prefix for index names to avoid conflicts
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* import postgres from "postgres";
|
|
99
|
+
* import { initRateLimitTable } from "@sudobility/ratelimit_service";
|
|
100
|
+
*
|
|
101
|
+
* const client = postgres(connectionString);
|
|
102
|
+
*
|
|
103
|
+
* // For public schema
|
|
104
|
+
* await initRateLimitTable(client, null, "sudojo");
|
|
105
|
+
*
|
|
106
|
+
* // For custom schema
|
|
107
|
+
* await initRateLimitTable(client, "shapeshyft", "shapeshyft");
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
async function initRateLimitTable(client, schemaName, indexPrefix) {
|
|
111
|
+
const tableName = schemaName
|
|
112
|
+
? `${schemaName}.rate_limit_counters`
|
|
113
|
+
: "rate_limit_counters";
|
|
114
|
+
const uniqueIdxName = `${indexPrefix}_rate_limit_user_period_idx`;
|
|
115
|
+
const typeIdxName = `${indexPrefix}_rate_limit_user_type_idx`;
|
|
116
|
+
await client.unsafe(`
|
|
117
|
+
CREATE TABLE IF NOT EXISTS ${tableName} (
|
|
118
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
119
|
+
user_id VARCHAR(128) NOT NULL,
|
|
120
|
+
period_type VARCHAR(16) NOT NULL,
|
|
121
|
+
period_start TIMESTAMPTZ NOT NULL,
|
|
122
|
+
request_count INTEGER NOT NULL DEFAULT 0,
|
|
123
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
124
|
+
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
125
|
+
)
|
|
126
|
+
`);
|
|
127
|
+
await client.unsafe(`
|
|
128
|
+
CREATE UNIQUE INDEX IF NOT EXISTS ${uniqueIdxName}
|
|
129
|
+
ON ${tableName} (user_id, period_type, period_start)
|
|
130
|
+
`);
|
|
131
|
+
await client.unsafe(`
|
|
132
|
+
CREATE INDEX IF NOT EXISTS ${typeIdxName}
|
|
133
|
+
ON ${tableName} (user_id, period_type)
|
|
134
|
+
`);
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=rate-limits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limits.js","sourceRoot":"","sources":["../../src/schema/rate-limits.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AA4BH,oEA2BC;AAeD,gFAwBC;AA6DD,gDAiCC;AA1LD,iDAQ6B;AAE7B;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,4BAA4B,CAC1C,MAAW,EACX,WAAmB;IAEnB,OAAO,MAAM,CAAC,KAAK,CACjB,qBAAqB,EACrB;QACE,EAAE,EAAE,IAAA,cAAI,EAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC,aAAa,EAAE;QAC3C,OAAO,EAAE,IAAA,iBAAO,EAAC,SAAS,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE;QACtD,WAAW,EAAE,IAAA,iBAAO,EAAC,aAAa,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|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NONE_ENTITLEMENT = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The special entitlement name for users without any subscription.
|
|
6
|
+
* This is returned when a user has no active entitlements in RevenueCat.
|
|
7
|
+
*/
|
|
8
|
+
exports.NONE_ENTITLEMENT = "none";
|
|
9
|
+
//# sourceMappingURL=entitlements.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The special entitlement name for users without any subscription.
|
|
3
|
+
* This is returned when a user has no active entitlements in RevenueCat.
|
|
4
|
+
*/
|
|
5
|
+
export declare const NONE_ENTITLEMENT: "none";
|
|
6
|
+
/**
|
|
7
|
+
* RevenueCat entitlement information from the subscriber API.
|
|
8
|
+
*/
|
|
9
|
+
export interface RevenueCatEntitlement {
|
|
10
|
+
/** Expiration date in ISO format, or null if lifetime */
|
|
11
|
+
expires_date: string | null;
|
|
12
|
+
/** Grace period expiration date */
|
|
13
|
+
grace_period_expires_date: string | null;
|
|
14
|
+
/** Product identifier in the app store */
|
|
15
|
+
product_identifier: string;
|
|
16
|
+
/** Purchase date in ISO format */
|
|
17
|
+
purchase_date: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Response shape from RevenueCat's GET /subscribers/{user_id} endpoint.
|
|
21
|
+
*/
|
|
22
|
+
export interface RevenueCatSubscriberResponse {
|
|
23
|
+
subscriber: {
|
|
24
|
+
entitlements: {
|
|
25
|
+
[key: string]: RevenueCatEntitlement;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=entitlements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlements.d.ts","sourceRoot":"","sources":["../../src/types/entitlements.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAG,MAAe,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,yDAAyD;IACzD,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,mCAAmC;IACnC,yBAAyB,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,0CAA0C;IAC1C,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kCAAkC;IAClC,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,UAAU,EAAE;QACV,YAAY,EAAE;YACZ,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB,CAAC;SACtC,CAAC;KACH,CAAC;CACH"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NONE_ENTITLEMENT = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The special entitlement name for users without any subscription.
|
|
6
|
+
* This is returned when a user has no active entitlements in RevenueCat.
|
|
7
|
+
*/
|
|
8
|
+
exports.NONE_ENTITLEMENT = "none";
|
|
9
|
+
//# sourceMappingURL=entitlements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlements.js","sourceRoot":"","sources":["../../src/types/entitlements.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,gBAAgB,GAAG,MAAe,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./rate-limits"), exports);
|
|
18
|
+
__exportStar(require("./entitlements"), exports);
|
|
19
|
+
__exportStar(require("./responses"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./rate-limits"), exports);
|
|
18
|
+
__exportStar(require("./entitlements"), exports);
|
|
19
|
+
__exportStar(require("./responses"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,iDAA+B;AAC/B,8CAA4B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rate limits for a single time period.
|
|
3
|
+
* undefined means unlimited for that period.
|
|
4
|
+
*/
|
|
5
|
+
export interface RateLimits {
|
|
6
|
+
/** Requests allowed per hour. undefined = unlimited */
|
|
7
|
+
hourly?: number;
|
|
8
|
+
/** Requests allowed per day. undefined = unlimited */
|
|
9
|
+
daily?: number;
|
|
10
|
+
/** Requests allowed per month. undefined = unlimited */
|
|
11
|
+
monthly?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Configuration mapping entitlement names to their rate limits.
|
|
15
|
+
* The key "none" is required and applies to users without any subscription.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const config: RateLimitsConfig = {
|
|
20
|
+
* none: { hourly: 2, daily: 5, monthly: 20 },
|
|
21
|
+
* starter: { hourly: 10, daily: 50, monthly: 500 },
|
|
22
|
+
* pro: { hourly: 100, daily: undefined, monthly: undefined },
|
|
23
|
+
* enterprise: { hourly: undefined, daily: undefined, monthly: undefined },
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export type RateLimitsConfig = {
|
|
28
|
+
/** Rate limits for users without any entitlement (required) */
|
|
29
|
+
none: RateLimits;
|
|
30
|
+
} & {
|
|
31
|
+
/** Rate limits for each entitlement name */
|
|
32
|
+
[entitlement: string]: RateLimits;
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=rate-limits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limits.d.ts","sourceRoot":"","sources":["../../src/types/rate-limits.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,+DAA+D;IAC/D,IAAI,EAAE,UAAU,CAAC;CAClB,GAAG;IACF,4CAA4C;IAC5C,CAAC,WAAW,EAAE,MAAM,GAAG,UAAU,CAAC;CACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limits.js","sourceRoot":"","sources":["../../src/types/rate-limits.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PeriodType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Valid period types for rate limiting.
|
|
6
|
+
*/
|
|
7
|
+
var PeriodType;
|
|
8
|
+
(function (PeriodType) {
|
|
9
|
+
PeriodType["HOURLY"] = "hourly";
|
|
10
|
+
PeriodType["DAILY"] = "daily";
|
|
11
|
+
PeriodType["MONTHLY"] = "monthly";
|
|
12
|
+
})(PeriodType || (exports.PeriodType = PeriodType = {}));
|
|
13
|
+
//# sourceMappingURL=responses.js.map
|