create-db 1.1.3 → 1.1.4-pr73-DR-6663-rate-limiting-import-20324781629.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.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { n as createDbCli } from "./src-1WiR7iEz.mjs";
2
+ import { n as createDbCli } from "./src-XorNtxX8.mjs";
3
3
 
4
4
  //#region src/cli.ts
5
5
  createDbCli().run();
package/dist/index.d.mts CHANGED
@@ -34,6 +34,11 @@ interface DatabaseError {
34
34
  raw?: string;
35
35
  details?: unknown;
36
36
  status?: number;
37
+ rateLimitInfo?: {
38
+ retryAfterMs: number;
39
+ currentCount: number;
40
+ maxRequests: number;
41
+ };
37
42
  }
38
43
  type CreateDatabaseResult = DatabaseResult | DatabaseError;
39
44
  declare function isDatabaseError(result: CreateDatabaseResult): result is DatabaseError;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import { a as isDatabaseError, i as RegionSchema, n as createDbCli, o as isDatabaseSuccess, r as regions, t as create } from "./src-1WiR7iEz.mjs";
2
+ import { a as isDatabaseError, i as RegionSchema, n as createDbCli, o as isDatabaseSuccess, r as regions, t as create } from "./src-XorNtxX8.mjs";
3
3
 
4
4
  export { RegionSchema, create, createDbCli, isDatabaseError, isDatabaseSuccess, regions };
@@ -301,6 +301,54 @@ async function validateRegion(region, workerUrl) {
301
301
  return region;
302
302
  }
303
303
 
304
+ //#endregion
305
+ //#region src/rate-limiter.ts
306
+ const MAX_REQUESTS = 5;
307
+ const WINDOW_MS = 6e4;
308
+ var RateLimiter = class {
309
+ requests = [];
310
+ /**
311
+ * Check if a new request is allowed under the rate limit
312
+ * @returns true if allowed, false if rate limit exceeded
313
+ */
314
+ checkLimit() {
315
+ const now = Date.now();
316
+ this.requests = this.requests.filter((record) => now - record.timestamp < WINDOW_MS);
317
+ if (this.requests.length >= MAX_REQUESTS) return false;
318
+ this.requests.push({ timestamp: now });
319
+ return true;
320
+ }
321
+ /**
322
+ * Get the time in milliseconds until the rate limit resets
323
+ */
324
+ getTimeUntilReset() {
325
+ if (this.requests.length === 0) return 0;
326
+ const oldestRequest = this.requests[0];
327
+ if (!oldestRequest) return 0;
328
+ const timeUntilReset = WINDOW_MS - (Date.now() - oldestRequest.timestamp);
329
+ return Math.max(0, timeUntilReset);
330
+ }
331
+ /**
332
+ * Get the current number of requests in the window
333
+ */
334
+ getCurrentCount() {
335
+ const now = Date.now();
336
+ this.requests = this.requests.filter((record) => now - record.timestamp < WINDOW_MS);
337
+ return this.requests.length;
338
+ }
339
+ /**
340
+ * Get the current configuration (read-only)
341
+ * @internal
342
+ */
343
+ getConfig() {
344
+ return {
345
+ maxRequests: MAX_REQUESTS,
346
+ windowMs: WINDOW_MS
347
+ };
348
+ }
349
+ };
350
+ const globalRateLimiter = new RateLimiter();
351
+
304
352
  //#endregion
305
353
  //#region src/index.ts
306
354
  dotenv.config({ quiet: true });
@@ -510,6 +558,21 @@ createRouterClient(router, { context: {} });
510
558
  * ```
511
559
  */
512
560
  async function create(options) {
561
+ if (!globalRateLimiter.checkLimit()) {
562
+ const retryAfterMs = globalRateLimiter.getTimeUntilReset();
563
+ const config = globalRateLimiter.getConfig();
564
+ const retryAfterSeconds = Math.ceil(retryAfterMs / 1e3);
565
+ return {
566
+ success: false,
567
+ error: "RATE_LIMIT_EXCEEDED",
568
+ message: `Rate limit exceeded. You can create up to ${config.maxRequests} databases per ${Math.ceil(config.windowMs / 1e3)} seconds. Please try again in ${retryAfterSeconds} seconds.`,
569
+ rateLimitInfo: {
570
+ retryAfterMs,
571
+ currentCount: globalRateLimiter.getCurrentCount(),
572
+ maxRequests: config.maxRequests
573
+ }
574
+ };
575
+ }
513
576
  return createDatabaseCoreWithUrl(options?.region || "us-east-1", options?.userAgent);
514
577
  }
515
578
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-db",
3
- "version": "1.1.3",
3
+ "version": "1.1.4-pr73-DR-6663-rate-limiting-import-20324781629.0",
4
4
  "description": "Instantly create a temporary Prisma Postgres database with one command, then claim and persist it in your Prisma Data Platform project when ready.",
5
5
  "type": "module",
6
6
  "exports": {