@oh-my-pi/pi-utils 15.5.7 → 15.5.8

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.
@@ -11,7 +11,7 @@
11
11
  * - `Your quota will reset after 18h31m10s` / `10m15s` / `39s`
12
12
  * - `Please retry in 250ms` / `Please retry in 12s`
13
13
  * - `"retryDelay": "34.074824224s"` (JSON error detail field)
14
- * - `try again in 250ms` / `try again in 12s` / `try again in 12sec`
14
+ * - `try again in 250ms` / `try again in 12s` / `try again in 5 min` / `try again in ~158 min`
15
15
  *
16
16
  * Returns `undefined` if no signal is found.
17
17
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@oh-my-pi/pi-utils",
4
- "version": "15.5.7",
4
+ "version": "15.5.8",
5
5
  "description": "Shared utilities for pi packages",
6
6
  "homepage": "https://omp.sh",
7
7
  "author": "Can Boluk",
@@ -31,7 +31,7 @@
31
31
  "fmt": "biome format --write ."
32
32
  },
33
33
  "dependencies": {
34
- "@oh-my-pi/pi-natives": "15.5.7",
34
+ "@oh-my-pi/pi-natives": "15.5.8",
35
35
  "beautiful-mermaid": "^1.1.3",
36
36
  "handlebars": "^4.7.9",
37
37
  "winston": "^3.19.0",
@@ -6,8 +6,10 @@ const QUOTA_RESET_PATTERN = /reset after (?:(\d+)h)?(?:(\d+)m)?(\d+(?:\.\d+)?)s/
6
6
  const PLEASE_RETRY_PATTERN = /Please retry in ([0-9.]+)(ms|s)/i;
7
7
  // JSON field: "retryDelay": "34.074824224s"
8
8
  const RETRY_DELAY_FIELD_PATTERN = /"retryDelay":\s*"([0-9.]+)(ms|s)"/i;
9
- // "try again in 250ms" / "try again in 12s" / "try again in 12sec"
10
- const TRY_AGAIN_PATTERN = /try again in\s+(\d+(?:\.\d+)?)\s*(ms|s)(?:ec)?/i;
9
+ // "try again in 250ms" / "try again in 12s" / "try again in 12sec" /
10
+ // "try again in 5 min" / "try again in ~158 min." / "try again in 2h" /
11
+ // "try again in 90 minutes" / "try again in 1 hour"
12
+ const TRY_AGAIN_PATTERN = /try again in\s+~?\s*([0-9.]+)\s*(ms|sec|s|minutes?|mins?|m|hours?|hrs?|h)\b/i;
11
13
 
12
14
  /**
13
15
  * Server-suggested retry delay extraction. Merges the patterns historically used
@@ -22,7 +24,7 @@ const TRY_AGAIN_PATTERN = /try again in\s+(\d+(?:\.\d+)?)\s*(ms|s)(?:ec)?/i;
22
24
  * - `Your quota will reset after 18h31m10s` / `10m15s` / `39s`
23
25
  * - `Please retry in 250ms` / `Please retry in 12s`
24
26
  * - `"retryDelay": "34.074824224s"` (JSON error detail field)
25
- * - `try again in 250ms` / `try again in 12s` / `try again in 12sec`
27
+ * - `try again in 250ms` / `try again in 12s` / `try again in 5 min` / `try again in ~158 min`
26
28
  *
27
29
  * Returns `undefined` if no signal is found.
28
30
  */
@@ -68,13 +70,38 @@ export function extractRetryHint(source: Response | Headers | null | undefined,
68
70
  if (match?.[1]) {
69
71
  const value = Number.parseFloat(match[1]);
70
72
  if (Number.isFinite(value) && value > 0) {
71
- return match[2]!.toLowerCase() === "ms" ? value : value * 1000;
73
+ const unitMs = unitToMs(match[2]!);
74
+ if (unitMs !== undefined) return value * unitMs;
72
75
  }
73
76
  }
74
77
  }
75
78
  return undefined;
76
79
  }
77
80
 
81
+ function unitToMs(unit: string): number | undefined {
82
+ switch (unit.toLowerCase()) {
83
+ case "ms":
84
+ return 1;
85
+ case "s":
86
+ case "sec":
87
+ return 1000;
88
+ case "m":
89
+ case "min":
90
+ case "mins":
91
+ case "minute":
92
+ case "minutes":
93
+ return 60_000;
94
+ case "h":
95
+ case "hr":
96
+ case "hrs":
97
+ case "hour":
98
+ case "hours":
99
+ return 60 * 60_000;
100
+ default:
101
+ return undefined;
102
+ }
103
+ }
104
+
78
105
  export interface FetchWithRetryOptions extends RequestInit {
79
106
  /** Total fetch attempts (initial + retries). Default `5`. */
80
107
  maxAttempts?: number;