@nordsym/apiclaw 2.1.0 → 2.2.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.
Files changed (185) hide show
  1. package/README.md +15 -2
  2. package/dist/bin-http.js +0 -0
  3. package/dist/bin.bundled.js +79288 -0
  4. package/dist/funnel-client.d.ts +24 -0
  5. package/dist/funnel-client.d.ts.map +1 -0
  6. package/dist/funnel-client.js +131 -0
  7. package/dist/funnel-client.js.map +1 -0
  8. package/dist/funnel.test.d.ts +2 -0
  9. package/dist/funnel.test.d.ts.map +1 -0
  10. package/dist/funnel.test.js +145 -0
  11. package/dist/funnel.test.js.map +1 -0
  12. package/dist/gateway-client.d.ts.map +1 -1
  13. package/dist/gateway-client.js +24 -2
  14. package/dist/gateway-client.js.map +1 -1
  15. package/dist/index.bundled.js +61263 -0
  16. package/dist/index.js +161 -74
  17. package/dist/index.js.map +1 -1
  18. package/dist/postinstall.d.ts +0 -5
  19. package/dist/postinstall.d.ts.map +1 -1
  20. package/dist/postinstall.js +24 -3
  21. package/dist/postinstall.js.map +1 -1
  22. package/dist/registration-guard.d.ts +29 -0
  23. package/dist/registration-guard.d.ts.map +1 -0
  24. package/dist/registration-guard.js +87 -0
  25. package/dist/registration-guard.js.map +1 -0
  26. package/package.json +7 -2
  27. package/.claude/settings.local.json +0 -9
  28. package/.env.prod +0 -1
  29. package/apiclaw-README.md +0 -494
  30. package/convex/_generated/api.d.ts +0 -137
  31. package/convex/_generated/api.js +0 -23
  32. package/convex/_generated/dataModel.d.ts +0 -60
  33. package/convex/_generated/server.d.ts +0 -143
  34. package/convex/_generated/server.js +0 -93
  35. package/convex/adminActivate.ts +0 -53
  36. package/convex/adminStats.ts +0 -306
  37. package/convex/agents.ts +0 -939
  38. package/convex/analytics.ts +0 -187
  39. package/convex/apiKeys.ts +0 -220
  40. package/convex/backfillAnalytics.ts +0 -272
  41. package/convex/backfillSearchLogs.ts +0 -35
  42. package/convex/billing.ts +0 -834
  43. package/convex/capabilities.ts +0 -157
  44. package/convex/chains.ts +0 -1318
  45. package/convex/credits.ts +0 -211
  46. package/convex/crons.ts +0 -50
  47. package/convex/debugFilestackLogs.ts +0 -16
  48. package/convex/debugGetToken.ts +0 -18
  49. package/convex/directCall.ts +0 -713
  50. package/convex/earnProgress.ts +0 -753
  51. package/convex/email.ts +0 -329
  52. package/convex/feedback.ts +0 -265
  53. package/convex/http.ts +0 -3430
  54. package/convex/inbound.ts +0 -32
  55. package/convex/logs.ts +0 -701
  56. package/convex/migrateFilestack.ts +0 -81
  57. package/convex/migratePartnersProd.ts +0 -174
  58. package/convex/migratePratham.ts +0 -126
  59. package/convex/migrateProviderWorkspaces.ts +0 -175
  60. package/convex/mou.ts +0 -91
  61. package/convex/providerKeys.ts +0 -289
  62. package/convex/providers.ts +0 -1135
  63. package/convex/purchases.ts +0 -183
  64. package/convex/ratelimit.ts +0 -104
  65. package/convex/schema.ts +0 -869
  66. package/convex/searchLogs.ts +0 -265
  67. package/convex/seedAPILayerAPIs.ts +0 -191
  68. package/convex/seedDirectCallConfigs.ts +0 -336
  69. package/convex/seedPratham.ts +0 -149
  70. package/convex/spendAlerts.ts +0 -442
  71. package/convex/stripeActions.ts +0 -607
  72. package/convex/teams.ts +0 -243
  73. package/convex/telemetry.ts +0 -81
  74. package/convex/tsconfig.json +0 -25
  75. package/convex/updateAPIStatus.ts +0 -44
  76. package/convex/usage.ts +0 -260
  77. package/convex/usageReports.ts +0 -357
  78. package/convex/waitlist.ts +0 -55
  79. package/convex/webhooks.ts +0 -494
  80. package/convex/workspaceSettings.ts +0 -143
  81. package/convex/workspaces.ts +0 -1331
  82. package/convex.json +0 -3
  83. package/direct-test.mjs +0 -51
  84. package/email-templates/filestack-provider-outreach.html +0 -162
  85. package/email-templates/partnership-template.html +0 -116
  86. package/email-templates/pratham-draft-preview.txt +0 -57
  87. package/email-templates/pratham-partnership-draft.html +0 -141
  88. package/reports/APIClaw-Session-Report-2026-04-05.pdf +0 -0
  89. package/reports/pipeline/PIPELINE-REPORT.json +0 -153
  90. package/reports/pipeline/acquire_apisguru.json +0 -17
  91. package/reports/pipeline/capabilities.json +0 -38
  92. package/reports/pipeline/discover_azure_recursive.json +0 -1551
  93. package/reports/pipeline/discover_github.json +0 -25
  94. package/reports/pipeline/discover_github_repos.json +0 -49
  95. package/reports/pipeline/discover_swaggerhub.json +0 -24
  96. package/reports/pipeline/discover_well_known.json +0 -23
  97. package/reports/pipeline/fetch_specs.json +0 -19
  98. package/reports/pipeline/generate_providers.json +0 -14
  99. package/reports/pipeline/match_registry.json +0 -11
  100. package/reports/pipeline/parse_specs.json +0 -17
  101. package/reports/pipeline/promote_candidates.json +0 -34
  102. package/reports/pipeline/validate.json +0 -30
  103. package/reports/pipeline/validate_smoke_details.json +0 -3835
  104. package/reports/session-report-2026-04-05.html +0 -433
  105. package/seed-apis-direct.mjs +0 -106
  106. package/src/access-control.ts +0 -174
  107. package/src/adapters/base.ts +0 -364
  108. package/src/adapters/claude-desktop.ts +0 -41
  109. package/src/adapters/cline.ts +0 -88
  110. package/src/adapters/continue.ts +0 -91
  111. package/src/adapters/cursor.ts +0 -43
  112. package/src/adapters/custom.ts +0 -188
  113. package/src/adapters/detect.ts +0 -202
  114. package/src/adapters/index.ts +0 -47
  115. package/src/adapters/windsurf.ts +0 -44
  116. package/src/bin-http.ts +0 -45
  117. package/src/bin.ts +0 -34
  118. package/src/capability-router.ts +0 -331
  119. package/src/chainExecutor.ts +0 -730
  120. package/src/chainResolver.test.ts +0 -246
  121. package/src/chainResolver.ts +0 -658
  122. package/src/cli/commands/demo.ts +0 -109
  123. package/src/cli/commands/doctor.ts +0 -435
  124. package/src/cli/commands/index.ts +0 -9
  125. package/src/cli/commands/login.ts +0 -203
  126. package/src/cli/commands/mcp-install.ts +0 -373
  127. package/src/cli/commands/restore.ts +0 -333
  128. package/src/cli/commands/setup.ts +0 -297
  129. package/src/cli/commands/uninstall.ts +0 -240
  130. package/src/cli/index.ts +0 -148
  131. package/src/cli.ts +0 -370
  132. package/src/confirmation.ts +0 -296
  133. package/src/credentials.ts +0 -455
  134. package/src/credits.ts +0 -329
  135. package/src/crypto.ts +0 -75
  136. package/src/discovery.ts +0 -568
  137. package/src/enterprise/env.ts +0 -156
  138. package/src/enterprise/index.ts +0 -7
  139. package/src/enterprise/script-generator.ts +0 -481
  140. package/src/execute-dynamic.ts +0 -617
  141. package/src/execute.ts +0 -2386
  142. package/src/gateway-client.ts +0 -192
  143. package/src/hivr-whitelist.ts +0 -110
  144. package/src/http-api.ts +0 -286
  145. package/src/http-server-minimal.ts +0 -154
  146. package/src/index.ts +0 -2611
  147. package/src/intelligent-gateway.ts +0 -339
  148. package/src/mcp-analytics.ts +0 -156
  149. package/src/metered.ts +0 -149
  150. package/src/open-apis-generated.ts +0 -157
  151. package/src/open-apis.ts +0 -558
  152. package/src/postinstall.ts +0 -18
  153. package/src/product-whitelist.ts +0 -246
  154. package/src/proxy.ts +0 -36
  155. package/src/session.ts +0 -129
  156. package/src/stripe.ts +0 -497
  157. package/src/telemetry.ts +0 -71
  158. package/src/test.ts +0 -135
  159. package/src/types/convex-api.d.ts +0 -20
  160. package/src/types/convex-api.ts +0 -21
  161. package/src/types.ts +0 -109
  162. package/src/ui/colors.ts +0 -219
  163. package/src/ui/errors.ts +0 -394
  164. package/src/ui/index.ts +0 -17
  165. package/src/ui/prompts.ts +0 -390
  166. package/src/ui/spinner.ts +0 -325
  167. package/src/utils/backup.ts +0 -224
  168. package/src/utils/config.ts +0 -318
  169. package/src/utils/os.ts +0 -124
  170. package/src/utils/paths.ts +0 -203
  171. package/src/webhook.ts +0 -107
  172. package/test-10-working.cjs +0 -97
  173. package/test-14-final.cjs +0 -96
  174. package/test-actual-handlers.ts +0 -92
  175. package/test-apilayer-all-14.ts +0 -249
  176. package/test-apilayer-fixed.ts +0 -248
  177. package/test-direct-endpoints.ts +0 -174
  178. package/test-exact-endpoints.ts +0 -144
  179. package/test-final.ts +0 -83
  180. package/test-full-routing.ts +0 -100
  181. package/test-handlers-correct.ts +0 -217
  182. package/test-numverify-key.ts +0 -41
  183. package/test-via-handlers.ts +0 -92
  184. package/test-worldnews.mjs +0 -26
  185. package/tsconfig.json +0 -20
package/src/credits.ts DELETED
@@ -1,329 +0,0 @@
1
- // Credit system for APIClaw
2
- // Supports both in-memory (dev) and Convex (production) backends
3
-
4
- import { AgentCredits, Purchase, APICredentials, UsageRecord } from './types.js';
5
- import { getCredentials, hasRealCredentials } from './credentials.js';
6
- import { randomUUID } from 'crypto';
7
-
8
- // Storage backend type
9
- type StorageBackend = 'memory' | 'convex';
10
-
11
- // Configuration
12
- const BACKEND: StorageBackend = process.env.APICLAW_BACKEND === 'convex' ? 'convex' : 'memory';
13
- const CONVEX_URL = process.env.CONVEX_URL || '';
14
- const CONVEX_DEPLOY_KEY = process.env.CONVEX_DEPLOY_KEY || '';
15
-
16
- // In-memory stores (for local development)
17
- const agentCreditsStore: Map<string, AgentCredits> = new Map();
18
- const purchasesStore: Map<string, Purchase> = new Map();
19
- const usageStore: Map<string, UsageRecord> = new Map();
20
-
21
- // Provider that have real credentials available
22
- const REAL_CREDENTIAL_PROVIDERS = ['46elks', 'twilio'];
23
-
24
- // Credits per dollar by provider
25
- const CREDITS_PER_DOLLAR: Record<string, number> = {
26
- '46elks': 30, // ~30 SMS per dollar
27
- 'twilio': 25, // ~25 SMS per dollar
28
- 'resend': 1000, // ~1000 emails per dollar
29
- 'brave_search': 200, // ~200 searches per dollar
30
- 'openrouter': 100, // ~100k tokens per dollar (varies by model)
31
- 'elevenlabs': 3333 // ~3333 characters per dollar
32
- };
33
-
34
- /**
35
- * Calculate credits based on provider pricing
36
- */
37
- function calculateCredits(providerId: string, amountUsd: number): number {
38
- return Math.floor(amountUsd * (CREDITS_PER_DOLLAR[providerId] || 100));
39
- }
40
-
41
- /**
42
- * Generate credentials for a provider
43
- * Returns real credentials for supported providers, mock for others
44
- */
45
- function generateCredentials(providerId: string): APICredentials {
46
- // Try to get real credentials first
47
- const realCreds = getCredentials(providerId);
48
- if (realCreds && hasRealCredentials(providerId)) {
49
- console.log(`[APIClaw] Using REAL credentials for ${providerId}`);
50
- return realCreds;
51
- }
52
-
53
- // Fall back to mock credentials
54
- console.log(`[APIClaw] Using MOCK credentials for ${providerId}`);
55
- return realCreds || {
56
- type: 'api_key',
57
- api_key: `mock_${providerId}_${randomUUID().slice(0, 8)}`
58
- };
59
- }
60
-
61
- // =============================================================================
62
- // In-Memory Backend (for development)
63
- // =============================================================================
64
-
65
- /**
66
- * Get or create agent credits account
67
- */
68
- export function getAgentCredits(agentId: string): AgentCredits {
69
- if (!agentCreditsStore.has(agentId)) {
70
- agentCreditsStore.set(agentId, {
71
- agent_id: agentId,
72
- balance_usd: 0,
73
- currency: 'USD',
74
- created_at: new Date().toISOString(),
75
- updated_at: new Date().toISOString()
76
- });
77
- }
78
- return agentCreditsStore.get(agentId)!;
79
- }
80
-
81
- /**
82
- * Add credits to an agent's account
83
- */
84
- export function addCredits(agentId: string, amountUsd: number): AgentCredits {
85
- const credits = getAgentCredits(agentId);
86
- credits.balance_usd += amountUsd;
87
- credits.updated_at = new Date().toISOString();
88
- return credits;
89
- }
90
-
91
- /**
92
- * Purchase API access
93
- * Returns real credentials for 46elks and Twilio
94
- */
95
- export function purchaseAPIAccess(
96
- agentId: string,
97
- providerId: string,
98
- amountUsd: number
99
- ): { success: boolean; purchase?: Purchase; error?: string } {
100
- const credits = getAgentCredits(agentId);
101
-
102
- // Check balance
103
- if (credits.balance_usd < amountUsd) {
104
- return {
105
- success: false,
106
- error: `Insufficient balance. Have $${credits.balance_usd.toFixed(2)}, need $${amountUsd.toFixed(2)}`
107
- };
108
- }
109
-
110
- // Check if provider is supported
111
- const providerCredentials = getCredentials(providerId);
112
- if (!providerCredentials) {
113
- return {
114
- success: false,
115
- error: `Unknown provider: ${providerId}. Supported: ${Object.keys(CREDITS_PER_DOLLAR).join(', ')}`
116
- };
117
- }
118
-
119
- // Deduct credits
120
- credits.balance_usd -= amountUsd;
121
- credits.updated_at = new Date().toISOString();
122
-
123
- // Generate credentials (real for 46elks/twilio, mock for others)
124
- const credentials = generateCredentials(providerId);
125
-
126
- // Create purchase record
127
- const purchaseId = `pur_${randomUUID().slice(0, 12)}`;
128
- const purchase: Purchase = {
129
- id: purchaseId,
130
- agent_id: agentId,
131
- provider_id: providerId,
132
- amount_usd: amountUsd,
133
- credits_purchased: calculateCredits(providerId, amountUsd),
134
- status: 'active',
135
- credentials,
136
- created_at: new Date().toISOString()
137
- };
138
-
139
- purchasesStore.set(purchaseId, purchase);
140
-
141
- // Initialize usage tracking
142
- usageStore.set(purchaseId, {
143
- purchase_id: purchaseId,
144
- provider_id: providerId,
145
- units_used: 0,
146
- units_remaining: purchase.credits_purchased,
147
- cost_incurred_usd: 0,
148
- last_used_at: new Date().toISOString()
149
- });
150
-
151
- // Flag if using real credentials
152
- const isRealCredentials = hasRealCredentials(providerId);
153
- console.log(`[APIClaw] Purchase complete: ${providerId} ($${amountUsd}) - Real credentials: ${isRealCredentials}`);
154
-
155
- return { success: true, purchase };
156
- }
157
-
158
- /**
159
- * Get all purchases for an agent
160
- */
161
- export function getAgentPurchases(agentId: string): Purchase[] {
162
- return Array.from(purchasesStore.values()).filter(p => p.agent_id === agentId);
163
- }
164
-
165
- /**
166
- * Get usage for a purchase
167
- */
168
- export function getUsage(purchaseId: string): UsageRecord | null {
169
- return usageStore.get(purchaseId) || null;
170
- }
171
-
172
- /**
173
- * Record usage (call this when API is used)
174
- */
175
- export function recordUsage(purchaseId: string, unitsUsed: number, costUsd: number): UsageRecord | null {
176
- const record = usageStore.get(purchaseId);
177
- if (!record) return null;
178
-
179
- record.units_used += unitsUsed;
180
- record.units_remaining = Math.max(0, record.units_remaining - unitsUsed);
181
- record.cost_incurred_usd += costUsd;
182
- record.last_used_at = new Date().toISOString();
183
-
184
- // Update purchase status if depleted
185
- if (record.units_remaining === 0) {
186
- const purchase = purchasesStore.get(purchaseId);
187
- if (purchase) purchase.status = 'exhausted';
188
- }
189
-
190
- return record;
191
- }
192
-
193
- /**
194
- * Get full balance summary for an agent
195
- */
196
- export function getBalanceSummary(agentId: string): {
197
- credits: AgentCredits;
198
- active_purchases: Purchase[];
199
- total_spent_usd: number;
200
- real_credentials_available: string[];
201
- } {
202
- const credits = getAgentCredits(agentId);
203
- const agentPurchases = getAgentPurchases(agentId);
204
- const activePurchases = agentPurchases.filter(p => p.status === 'active');
205
- const totalSpent = agentPurchases.reduce((sum, p) => sum + p.amount_usd, 0);
206
-
207
- // List providers with real credentials
208
- const realCredentialProviders = REAL_CREDENTIAL_PROVIDERS.filter(p => hasRealCredentials(p));
209
-
210
- return {
211
- credits,
212
- active_purchases: activePurchases,
213
- total_spent_usd: totalSpent,
214
- real_credentials_available: realCredentialProviders
215
- };
216
- }
217
-
218
- /**
219
- * Check which providers have real credentials
220
- */
221
- export function getProvidersWithRealCredentials(): string[] {
222
- return REAL_CREDENTIAL_PROVIDERS.filter(p => hasRealCredentials(p));
223
- }
224
-
225
- // =============================================================================
226
- // Convex Backend (for production) - HTTP API calls
227
- // =============================================================================
228
-
229
- interface ConvexResponse<T> {
230
- data?: T;
231
- error?: string;
232
- }
233
-
234
- async function convexQuery<T>(path: string, args: Record<string, unknown>): Promise<ConvexResponse<T>> {
235
- if (!CONVEX_URL) {
236
- return { error: 'Convex URL not configured' };
237
- }
238
-
239
- try {
240
- const response = await fetch(`${CONVEX_URL}/api/query`, {
241
- method: 'POST',
242
- headers: {
243
- 'Content-Type': 'application/json',
244
- ...(CONVEX_DEPLOY_KEY ? { 'Authorization': `Convex ${CONVEX_DEPLOY_KEY}` } : {}),
245
- },
246
- body: JSON.stringify({ path, args }),
247
- });
248
-
249
- const result = await response.json() as T;
250
- return { data: result };
251
- } catch (error) {
252
- return { error: error instanceof Error ? error.message : 'Convex query failed' };
253
- }
254
- }
255
-
256
- async function convexMutation<T>(path: string, args: Record<string, unknown>): Promise<ConvexResponse<T>> {
257
- if (!CONVEX_URL) {
258
- return { error: 'Convex URL not configured' };
259
- }
260
-
261
- try {
262
- const response = await fetch(`${CONVEX_URL}/api/mutation`, {
263
- method: 'POST',
264
- headers: {
265
- 'Content-Type': 'application/json',
266
- ...(CONVEX_DEPLOY_KEY ? { 'Authorization': `Convex ${CONVEX_DEPLOY_KEY}` } : {}),
267
- },
268
- body: JSON.stringify({ path, args }),
269
- });
270
-
271
- const result = await response.json() as T;
272
- return { data: result };
273
- } catch (error) {
274
- return { error: error instanceof Error ? error.message : 'Convex mutation failed' };
275
- }
276
- }
277
-
278
- // Convex-backed versions (async)
279
- export async function getAgentCreditsAsync(agentId: string): Promise<AgentCredits | null> {
280
- if (BACKEND === 'memory') {
281
- return getAgentCredits(agentId);
282
- }
283
-
284
- const result = await convexQuery<AgentCredits>('credits:getAgentCredits', { agentId });
285
- return result.data || null;
286
- }
287
-
288
- export async function addCreditsAsync(agentId: string, amountUsd: number): Promise<AgentCredits | null> {
289
- if (BACKEND === 'memory') {
290
- return addCredits(agentId, amountUsd);
291
- }
292
-
293
- const result = await convexMutation<AgentCredits>('credits:addCredits', { agentId, amountUsd });
294
- return result.data || null;
295
- }
296
-
297
- export async function purchaseAPIAccessAsync(
298
- agentId: string,
299
- providerId: string,
300
- amountUsd: number
301
- ): Promise<{ success: boolean; purchase?: Purchase; error?: string }> {
302
- if (BACKEND === 'memory') {
303
- return purchaseAPIAccess(agentId, providerId, amountUsd);
304
- }
305
-
306
- // Generate credentials server-side
307
- const credentials = generateCredentials(providerId);
308
-
309
- const result = await convexMutation<Purchase>('purchases:purchaseAccess', {
310
- agentId,
311
- providerId,
312
- amountUsd,
313
- credentials,
314
- });
315
-
316
- if (result.error) {
317
- return { success: false, error: result.error };
318
- }
319
-
320
- return { success: true, purchase: result.data };
321
- }
322
-
323
- // Export backend info
324
- export function getBackendInfo(): { type: StorageBackend; convexUrl: string | null } {
325
- return {
326
- type: BACKEND,
327
- convexUrl: BACKEND === 'convex' ? CONVEX_URL : null,
328
- };
329
- }
package/src/crypto.ts DELETED
@@ -1,75 +0,0 @@
1
- import { createCipheriv, createDecipheriv, randomBytes } from 'crypto';
2
-
3
- const ENCRYPTION_KEY = process.env.APICLAW_KEY_ENCRYPTION_SECRET;
4
-
5
- // Validate key exists and is correct length
6
- function getKey(): Buffer {
7
- if (!ENCRYPTION_KEY) {
8
- throw new Error('APICLAW_KEY_ENCRYPTION_SECRET not set');
9
- }
10
- // Key should be 32 bytes for AES-256
11
- const key = Buffer.from(ENCRYPTION_KEY, 'hex');
12
- if (key.length !== 32) {
13
- throw new Error('APICLAW_KEY_ENCRYPTION_SECRET must be 64 hex chars (32 bytes)');
14
- }
15
- return key;
16
- }
17
-
18
- export function encryptKey(plainKey: string): string {
19
- const key = getKey();
20
- const iv = randomBytes(16);
21
- const cipher = createCipheriv('aes-256-gcm', key, iv);
22
- const encrypted = Buffer.concat([cipher.update(plainKey, 'utf8'), cipher.final()]);
23
- const tag = cipher.getAuthTag();
24
- return `${iv.toString('hex')}:${tag.toString('hex')}:${encrypted.toString('hex')}`;
25
- }
26
-
27
- export function decryptKey(encryptedKey: string): string {
28
- const key = getKey();
29
- const [ivHex, tagHex, dataHex] = encryptedKey.split(':');
30
- if (!ivHex || !tagHex || !dataHex) {
31
- throw new Error('Invalid encrypted key format');
32
- }
33
- const decipher = createDecipheriv('aes-256-gcm', key, Buffer.from(ivHex, 'hex'));
34
- decipher.setAuthTag(Buffer.from(tagHex, 'hex'));
35
- const decrypted = Buffer.concat([
36
- decipher.update(Buffer.from(dataHex, 'hex')),
37
- decipher.final()
38
- ]);
39
- return decrypted.toString('utf8');
40
- }
41
-
42
- // SSRF Prevention
43
- export function validateBaseUrl(url: string): { valid: boolean; error?: string } {
44
- try {
45
- const parsed = new URL(url);
46
-
47
- if (parsed.protocol !== 'https:') {
48
- return { valid: false, error: 'URL must use HTTPS' };
49
- }
50
-
51
- const host = parsed.hostname.toLowerCase();
52
-
53
- const blockedPatterns = [
54
- /^127\./,
55
- /^10\./,
56
- /^192\.168\./,
57
- /^172\.(1[6-9]|2[0-9]|3[0-1])\./,
58
- /^localhost$/,
59
- /^0\.0\.0\.0$/,
60
- /^::1$/,
61
- /\.local$/,
62
- /\.internal$/,
63
- ];
64
-
65
- for (const pattern of blockedPatterns) {
66
- if (pattern.test(host)) {
67
- return { valid: false, error: 'Internal/private URLs not allowed' };
68
- }
69
- }
70
-
71
- return { valid: true };
72
- } catch {
73
- return { valid: false, error: 'Invalid URL format' };
74
- }
75
- }