@nordsym/apiclaw 1.5.9 โ 1.5.11
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/APILAYER_STATUS_2026-03-24.md +38 -0
- package/CHANGELOG-WHITELIST-V2.md +269 -0
- package/HIVR-INTEGRATION.md +281 -0
- package/HIVR-WHITELIST-STATUS.md +205 -0
- package/HIVR-WHITELIST.md +148 -0
- package/TERMINOLOGY-AUDIT.md +99 -0
- package/TERMINOLOGY-FIXED.md +74 -0
- package/VIDEO-DEMO-GUIDE.md +82 -0
- package/WHITELIST-ARCHITECTURE.md +379 -0
- package/api/discover.ts +71 -0
- package/api/health.ts +20 -0
- package/convex/http.d.ts.map +1 -1
- package/convex/http.js +8 -0
- package/convex/http.js.map +1 -1
- package/convex/http.ts +8 -0
- package/direct-test.mjs +51 -0
- package/dist/access-control.d.ts +45 -0
- package/dist/access-control.d.ts.map +1 -0
- package/dist/access-control.js +142 -0
- package/dist/access-control.js.map +1 -0
- package/dist/analytics.d.ts +4 -0
- package/dist/analytics.d.ts.map +1 -1
- package/dist/analytics.js +1 -0
- package/dist/analytics.js.map +1 -1
- package/dist/cli/commands/mcp-install.d.ts.map +1 -1
- package/dist/cli/commands/mcp-install.js +55 -40
- package/dist/cli/commands/mcp-install.js.map +1 -1
- package/dist/credentials.d.ts.map +1 -1
- package/dist/credentials.js +148 -0
- package/dist/credentials.js.map +1 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +191 -82
- package/dist/discovery.js.map +1 -1
- package/dist/execute.d.ts.map +1 -1
- package/dist/execute.js +274 -0
- package/dist/execute.js.map +1 -1
- package/dist/hivr-whitelist.d.ts +18 -0
- package/dist/hivr-whitelist.d.ts.map +1 -0
- package/dist/hivr-whitelist.js +95 -0
- package/dist/hivr-whitelist.js.map +1 -0
- package/dist/http-api.d.ts.map +1 -1
- package/dist/http-api.js +17 -33
- package/dist/http-api.js.map +1 -1
- package/dist/http-server-minimal.d.ts +7 -0
- package/dist/http-server-minimal.d.ts.map +1 -0
- package/dist/http-server-minimal.js +126 -0
- package/dist/http-server-minimal.js.map +1 -0
- package/dist/product-whitelist.d.ts +37 -0
- package/dist/product-whitelist.d.ts.map +1 -0
- package/dist/product-whitelist.js +203 -0
- package/dist/product-whitelist.js.map +1 -0
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +1 -1
- package/dist/proxy.js.map +1 -1
- package/email-templates/README.md +104 -0
- package/email-templates/partnership-template.html +116 -0
- package/landing/next-env.d.ts +1 -0
- package/landing/pages/api/discover.ts +43 -0
- package/landing/pages/api/health.ts +20 -0
- package/landing/src/app/api/auth/magic-link/route.ts +1 -1
- package/landing/src/app/auth/verify/page.tsx +6 -0
- package/landing/src/app/dashboard/verify/page.tsx +6 -0
- package/landing/src/app/join/page.tsx +6 -0
- package/landing/src/app/layout.tsx +2 -2
- package/landing/src/app/login/page.tsx +1 -1
- package/landing/src/app/mou/[partnerId]/page.tsx +6 -0
- package/landing/src/app/page.tsx +39 -18
- package/landing/src/app/providers/dashboard/[apiId]/actions/[actionId]/edit/page.tsx +6 -0
- package/landing/src/app/providers/dashboard/[apiId]/actions/new/page.tsx +5 -0
- package/landing/src/app/providers/dashboard/[apiId]/actions/page.tsx +5 -0
- package/landing/src/app/providers/dashboard/[apiId]/direct-call/page.tsx +6 -1
- package/landing/src/app/providers/dashboard/[apiId]/page.tsx +5 -0
- package/landing/src/app/providers/dashboard/[apiId]/test/page.tsx +5 -0
- package/landing/src/app/providers/dashboard/layout.tsx +6 -6
- package/landing/src/app/providers/dashboard/login/page.tsx +1 -1
- package/landing/src/app/providers/dashboard/page.tsx +1 -1
- package/landing/src/app/providers/dashboard/verify/page.tsx +6 -0
- package/landing/src/app/providers/layout.tsx +1 -1
- package/landing/src/app/upgrade/page.tsx +6 -0
- package/landing/src/app/workspace/page.tsx +6 -0
- package/landing/src/components/HeroTabs.tsx +2 -2
- package/landing/src/components/VideoDemo.tsx +94 -0
- package/landing/src/components/{ProviderDashboard.tsx โ Workspace.tsx} +2 -2
- package/landing/src/lib/mock-data.ts +1 -1
- package/landing/src/lib/stats.json +1 -1
- package/package.json +4 -2
- package/scripts/test-whitelist-v2.sh +128 -0
- package/src/access-control.ts +174 -0
- package/src/analytics.ts +5 -0
- package/src/cli/commands/mcp-install.ts +14 -4
- package/src/credentials.ts +156 -0
- package/src/discovery.ts +191 -82
- package/src/execute.ts +274 -0
- package/src/hivr-whitelist.ts +110 -0
- package/src/http-api.ts +18 -34
- package/src/http-server-minimal.ts +154 -0
- package/src/product-whitelist.ts +246 -0
- package/src/proxy.ts +1 -1
- package/test-actual-handlers.ts +92 -0
- package/test-apilayer-all-14.ts +249 -0
- package/test-apilayer-fixed.ts +248 -0
- package/test-direct-endpoints.ts +174 -0
- package/test-exact-endpoints.ts +144 -0
- package/test-final.ts +83 -0
- package/test-full-routing.ts +100 -0
- package/test-handlers-correct.ts +217 -0
- package/test-numverify-key.ts +41 -0
- package/test-via-handlers.ts +92 -0
- package/test-worldnews.mjs +26 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-Product Whitelist System
|
|
3
|
+
* Supports multiple products (Hivr, NordSym, partners) with namespaced agentIds
|
|
4
|
+
*
|
|
5
|
+
* Format: product:agentId
|
|
6
|
+
* Examples: hivr:bytebee, nordsym:mollebot, partner_x:agent1
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
interface ProductSource {
|
|
10
|
+
name: string;
|
|
11
|
+
convexUrl: string;
|
|
12
|
+
queryPath: string;
|
|
13
|
+
agentIdField: string;
|
|
14
|
+
authToken?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Product sources configuration
|
|
18
|
+
const PRODUCT_SOURCES: ProductSource[] = [
|
|
19
|
+
{
|
|
20
|
+
name: 'hivr',
|
|
21
|
+
convexUrl: 'https://sensible-quail-275.convex.cloud',
|
|
22
|
+
queryPath: 'agents:list',
|
|
23
|
+
agentIdField: 'handle', // โ
Fixed: Hivr agents use 'handle', not 'agentId'
|
|
24
|
+
},
|
|
25
|
+
// Add more products here as needed
|
|
26
|
+
// {
|
|
27
|
+
// name: 'nordsym',
|
|
28
|
+
// convexUrl: 'https://nordsym-deployment.convex.cloud',
|
|
29
|
+
// queryPath: 'team:listAgents',
|
|
30
|
+
// agentIdField: 'memberId',
|
|
31
|
+
// },
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
// Fallback static whitelist (emergency only)
|
|
35
|
+
const STATIC_WHITELIST = [
|
|
36
|
+
'hivr:bytebee',
|
|
37
|
+
'hivr:analyzerbee',
|
|
38
|
+
'hivr:buildbee',
|
|
39
|
+
'hivr:buzzwriter',
|
|
40
|
+
'hivr:hivemind',
|
|
41
|
+
'hivr:hivesage',
|
|
42
|
+
'hivr:symbot',
|
|
43
|
+
'hivr:hivrqueen',
|
|
44
|
+
'hivr:marketmaven',
|
|
45
|
+
'hivr:reconbee',
|
|
46
|
+
'hivr:sprintbee',
|
|
47
|
+
'hivr:quillbee',
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
// Cache per product (5 minutes TTL)
|
|
51
|
+
interface ProductCache {
|
|
52
|
+
agents: string[];
|
|
53
|
+
expiresAt: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const cache = new Map<string, ProductCache>();
|
|
57
|
+
const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Fetch agents from a single product source
|
|
61
|
+
*/
|
|
62
|
+
async function fetchFromProduct(source: ProductSource): Promise<string[]> {
|
|
63
|
+
try {
|
|
64
|
+
const headers: Record<string, string> = {
|
|
65
|
+
'Content-Type': 'application/json',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
if (source.authToken) {
|
|
69
|
+
headers['Authorization'] = `Bearer ${source.authToken}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const response = await fetch(`${source.convexUrl}/api/query`, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
headers,
|
|
75
|
+
body: JSON.stringify({
|
|
76
|
+
path: source.queryPath,
|
|
77
|
+
args: {},
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
console.warn(`[Whitelist] ${source.name}: HTTP ${response.status}`);
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const result = await response.json() as any;
|
|
87
|
+
|
|
88
|
+
// Convex HTTP API returns { status: "success", value: [...] }
|
|
89
|
+
const data = result.value || result;
|
|
90
|
+
|
|
91
|
+
if (!Array.isArray(data)) {
|
|
92
|
+
console.warn(`[Whitelist] ${source.name}: Invalid response format`, typeof data);
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Extract agentIds and add namespace
|
|
97
|
+
const agents = data
|
|
98
|
+
.map((item: any) => {
|
|
99
|
+
const agentId = item[source.agentIdField];
|
|
100
|
+
if (!agentId) return null;
|
|
101
|
+
return `${source.name}:${String(agentId).toLowerCase().trim()}`;
|
|
102
|
+
})
|
|
103
|
+
.filter((id): id is string => id !== null && id.length > 0);
|
|
104
|
+
|
|
105
|
+
console.log(`[Whitelist] ${source.name}: Fetched ${agents.length} agents`);
|
|
106
|
+
return agents;
|
|
107
|
+
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error(`[Whitelist] ${source.name}: Fetch failed`, error);
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Fetch and merge agents from all product sources
|
|
116
|
+
*/
|
|
117
|
+
async function fetchAllProducts(): Promise<string[]> {
|
|
118
|
+
const results = await Promise.allSettled(
|
|
119
|
+
PRODUCT_SOURCES.map(source => fetchFromProduct(source))
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const allAgents: string[] = [];
|
|
123
|
+
|
|
124
|
+
for (const result of results) {
|
|
125
|
+
if (result.status === 'fulfilled') {
|
|
126
|
+
allAgents.push(...result.value);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// If no products returned data, use static fallback
|
|
131
|
+
if (allAgents.length === 0) {
|
|
132
|
+
console.warn('[Whitelist] All sources failed, using static fallback');
|
|
133
|
+
return STATIC_WHITELIST;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return allAgents;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Get current whitelist (cached or fresh)
|
|
141
|
+
*/
|
|
142
|
+
export async function getWhitelist(): Promise<string[]> {
|
|
143
|
+
const now = Date.now();
|
|
144
|
+
|
|
145
|
+
// Check if any cache entry is still valid
|
|
146
|
+
const validCaches: string[] = [];
|
|
147
|
+
for (const [product, cached] of cache.entries()) {
|
|
148
|
+
if (now < cached.expiresAt) {
|
|
149
|
+
validCaches.push(...cached.agents);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// If all caches valid, return merged
|
|
154
|
+
if (validCaches.length > 0 && cache.size === PRODUCT_SOURCES.length) {
|
|
155
|
+
return validCaches;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Fetch fresh data
|
|
159
|
+
const agents = await fetchAllProducts();
|
|
160
|
+
|
|
161
|
+
// Update cache per product
|
|
162
|
+
const agentsByProduct = new Map<string, string[]>();
|
|
163
|
+
for (const agent of agents) {
|
|
164
|
+
const [product] = agent.split(':');
|
|
165
|
+
if (!agentsByProduct.has(product)) {
|
|
166
|
+
agentsByProduct.set(product, []);
|
|
167
|
+
}
|
|
168
|
+
agentsByProduct.get(product)!.push(agent);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
for (const [product, productAgents] of agentsByProduct.entries()) {
|
|
172
|
+
cache.set(product, {
|
|
173
|
+
agents: productAgents,
|
|
174
|
+
expiresAt: now + CACHE_TTL,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return agents;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Check if agentId is authorized
|
|
183
|
+
* Supports both namespaced (product:agent) and legacy (agent) formats
|
|
184
|
+
*/
|
|
185
|
+
export async function isAuthorized(agentId: string | undefined): Promise<boolean> {
|
|
186
|
+
if (!agentId) return false;
|
|
187
|
+
|
|
188
|
+
const normalized = agentId.toLowerCase().trim();
|
|
189
|
+
const whitelist = await getWhitelist();
|
|
190
|
+
|
|
191
|
+
// Check exact match (namespaced)
|
|
192
|
+
if (whitelist.includes(normalized)) {
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Legacy support: check if agentId matches any product's agent (without namespace)
|
|
197
|
+
// e.g., "bytebee" matches "hivr:bytebee"
|
|
198
|
+
if (!normalized.includes(':')) {
|
|
199
|
+
const legacyMatch = whitelist.some(entry => {
|
|
200
|
+
const [, agent] = entry.split(':');
|
|
201
|
+
return agent === normalized;
|
|
202
|
+
});
|
|
203
|
+
if (legacyMatch) {
|
|
204
|
+
console.log(`[Whitelist] Legacy match for ${normalized}`);
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Extract product name from agentId
|
|
214
|
+
*/
|
|
215
|
+
export function getProduct(agentId: string): string | null {
|
|
216
|
+
const [product] = agentId.split(':');
|
|
217
|
+
return product || null;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Force refresh whitelist (call after adding new agent)
|
|
222
|
+
*/
|
|
223
|
+
export function invalidateCache(product?: string): void {
|
|
224
|
+
if (product) {
|
|
225
|
+
cache.delete(product);
|
|
226
|
+
console.log(`[Whitelist] Cache invalidated for ${product}`);
|
|
227
|
+
} else {
|
|
228
|
+
cache.clear();
|
|
229
|
+
console.log('[Whitelist] All caches invalidated');
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Add new product source dynamically
|
|
235
|
+
*/
|
|
236
|
+
export function addProductSource(source: ProductSource): void {
|
|
237
|
+
const existing = PRODUCT_SOURCES.find(s => s.name === source.name);
|
|
238
|
+
if (existing) {
|
|
239
|
+
console.warn(`[Whitelist] Product ${source.name} already exists, updating`);
|
|
240
|
+
Object.assign(existing, source);
|
|
241
|
+
} else {
|
|
242
|
+
PRODUCT_SOURCES.push(source);
|
|
243
|
+
console.log(`[Whitelist] Added product source: ${source.name}`);
|
|
244
|
+
}
|
|
245
|
+
invalidateCache(source.name);
|
|
246
|
+
}
|
package/src/proxy.ts
CHANGED
|
@@ -33,4 +33,4 @@ export async function callProxy(provider: string, params: any): Promise<any> {
|
|
|
33
33
|
return response.json();
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export const PROXY_PROVIDERS = ["openrouter", "brave_search", "resend", "elevenlabs", "46elks", "twilio", "replicate", "firecrawl", "e2b", "groq", "deepgram", "serper", "mistral", "cohere", "together", "stability", "assemblyai", "github"];
|
|
36
|
+
export const PROXY_PROVIDERS = ["openrouter", "brave_search", "resend", "elevenlabs", "46elks", "twilio", "replicate", "firecrawl", "e2b", "groq", "deepgram", "serper", "mistral", "cohere", "together", "stability", "assemblyai", "github", "apilayer"];
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
import { executeAPICall } from './src/execute.js';
|
|
5
|
+
|
|
6
|
+
interface TestResult {
|
|
7
|
+
name: string;
|
|
8
|
+
success: boolean;
|
|
9
|
+
error?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Load credentials
|
|
13
|
+
function loadEnv(): Record<string, string> {
|
|
14
|
+
const envPath = path.join(homedir(), '.secrets', 'apilayer.env');
|
|
15
|
+
const content = fs.readFileSync(envPath, 'utf-8');
|
|
16
|
+
const vars: Record<string, string> = {};
|
|
17
|
+
for (const line of content.split('\n')) {
|
|
18
|
+
const match = line.match(/^([^=]+)=(.*)$/);
|
|
19
|
+
if (match) {
|
|
20
|
+
vars[match[1].trim()] = match[2].trim();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return vars;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const env = loadEnv();
|
|
27
|
+
|
|
28
|
+
const tests: Array<{ name: string; action: string; params: Record<string, unknown> }> = [
|
|
29
|
+
{ name: 'ExchangeRate API', action: 'exchange_rates', params: {} },
|
|
30
|
+
{ name: 'AviationStack API', action: 'aviation', params: {} },
|
|
31
|
+
{ name: 'ScreenshotLayer API', action: 'screenshot', params: { url: 'https://example.com' } },
|
|
32
|
+
{ name: 'Number Verification API', action: 'verify_number', params: { number: '+46701234567' } },
|
|
33
|
+
{ name: 'Email Verification API', action: 'verify_email', params: { email: 'test@example.com' } },
|
|
34
|
+
{ name: 'Marketstack API', action: 'market_data', params: { symbols: 'AAPL' } },
|
|
35
|
+
{ name: 'VAT Layer API', action: 'vat_check', params: { vat_number: 'SE556012345601' } },
|
|
36
|
+
{ name: 'Finance News API', action: 'finance_news', params: { tickers: 'AAPL' } },
|
|
37
|
+
{ name: 'Image Crop API', action: 'image_crop', params: { url: 'https://example.com/image.jpg' } },
|
|
38
|
+
{ name: 'Advanced Scraper API', action: 'scrape', params: { url: 'https://example.com' } },
|
|
39
|
+
{ name: 'PDF Generate API', action: 'pdf_generate', params: { document_url: 'https://example.com' } },
|
|
40
|
+
{ name: 'World News API', action: 'world_news', params: { url: 'https://example.com' } },
|
|
41
|
+
{ name: 'Skills API', action: 'skills', params: { q: 'machine learning' } },
|
|
42
|
+
{ name: 'Form API', action: 'form_submit', params: { endpoint: 'test' } },
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
async function runTests() {
|
|
46
|
+
console.log('๐งช Testing all 14 APILayer handlers via executeAPICall()\n');
|
|
47
|
+
|
|
48
|
+
const results: TestResult[] = [];
|
|
49
|
+
let working = 0;
|
|
50
|
+
|
|
51
|
+
for (const test of tests) {
|
|
52
|
+
try {
|
|
53
|
+
const result = await executeAPICall('apilayer', test.action, test.params);
|
|
54
|
+
const success = result.success === true;
|
|
55
|
+
|
|
56
|
+
if (success) {
|
|
57
|
+
working++;
|
|
58
|
+
console.log(`โ
${test.name}`);
|
|
59
|
+
} else {
|
|
60
|
+
console.log(`โ ${test.name}: ${result.error || 'unknown error'}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
results.push({
|
|
64
|
+
name: test.name,
|
|
65
|
+
success,
|
|
66
|
+
error: result.error,
|
|
67
|
+
});
|
|
68
|
+
} catch (err) {
|
|
69
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
70
|
+
console.log(`โ ${test.name}: ${errorMsg}`);
|
|
71
|
+
results.push({
|
|
72
|
+
name: test.name,
|
|
73
|
+
success: false,
|
|
74
|
+
error: errorMsg,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
console.log('\n' + '='.repeat(60));
|
|
80
|
+
console.log('๐ FINAL RESULTS');
|
|
81
|
+
console.log('='.repeat(60));
|
|
82
|
+
console.log(`\nโ
WORKING: ${working}/14`);
|
|
83
|
+
console.log(`โ NOT WORKING: ${14 - working}/14\n`);
|
|
84
|
+
|
|
85
|
+
const failed = results.filter(r => !r.success);
|
|
86
|
+
if (failed.length > 0) {
|
|
87
|
+
console.log('Failed services:');
|
|
88
|
+
failed.forEach(r => console.log(` โข ${r.name}: ${r.error}`));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
runTests().catch(console.error);
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
|
|
5
|
+
interface TestResult {
|
|
6
|
+
name: string;
|
|
7
|
+
endpoint: string;
|
|
8
|
+
status: number | string;
|
|
9
|
+
success: boolean;
|
|
10
|
+
error?: string;
|
|
11
|
+
responseTime: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const results: TestResult[] = [];
|
|
15
|
+
|
|
16
|
+
// Load credentials
|
|
17
|
+
function loadEnvFile(): Record<string, string> {
|
|
18
|
+
const envPath = path.join(homedir(), '.secrets', 'apilayer.env');
|
|
19
|
+
if (!fs.existsSync(envPath)) {
|
|
20
|
+
console.error(`โ No credentials file at ${envPath}`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const content = fs.readFileSync(envPath, 'utf-8');
|
|
25
|
+
const vars: Record<string, string> = {};
|
|
26
|
+
for (const line of content.split('\n')) {
|
|
27
|
+
const match = line.match(/^([^=]+)=(.*)$/);
|
|
28
|
+
if (match) {
|
|
29
|
+
vars[match[1].trim()] = match[2].trim().replace(/^['""]|["'"]$/g, '');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return vars;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const env = loadEnvFile();
|
|
36
|
+
|
|
37
|
+
// Test configurations - ALL 14 APIs
|
|
38
|
+
const tests = [
|
|
39
|
+
{
|
|
40
|
+
name: 'ExchangeRate API',
|
|
41
|
+
url: (key: string) => `https://api.apilayer.com/exchangerate?apikey=${key}`,
|
|
42
|
+
key: env.APILAYER_EXCHANGERATE_KEY,
|
|
43
|
+
method: 'GET',
|
|
44
|
+
authType: 'query'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'AviationStack API',
|
|
48
|
+
url: (key: string) => `https://api.apilayer.com/aviationstack?access_key=${key}`,
|
|
49
|
+
key: env.APILAYER_AVIATIONSTACK_KEY,
|
|
50
|
+
method: 'GET',
|
|
51
|
+
authType: 'query'
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'PDF Layer API',
|
|
55
|
+
url: (key: string) => `https://api.apilayer.com/pdf?url=https://example.com`,
|
|
56
|
+
key: env.APILAYER_PDFLAYER_KEY,
|
|
57
|
+
method: 'GET',
|
|
58
|
+
authType: 'header'
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'Screenshot Layer API',
|
|
62
|
+
url: (key: string) => `https://api.apilayer.com/screenshot?url=https://example.com&access_key=${key}`,
|
|
63
|
+
key: env.APILAYER_SCREENSHOTLAYER_KEY,
|
|
64
|
+
method: 'GET',
|
|
65
|
+
authType: 'query'
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'SkillAPI',
|
|
69
|
+
url: (key: string) => `https://api.promptapi.com/skills?q=test`,
|
|
70
|
+
key: env.APILAYER_SKILLAPI_KEY,
|
|
71
|
+
method: 'GET',
|
|
72
|
+
authType: 'header',
|
|
73
|
+
domain: 'promptapi.com'
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'Image Crop API',
|
|
77
|
+
url: (key: string) => `https://api.apilayer.com/crop?url=https://example.com/image.jpg`,
|
|
78
|
+
key: env.APILAYER_IMAGECROP_KEY,
|
|
79
|
+
method: 'GET',
|
|
80
|
+
authType: 'header'
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: 'Form API',
|
|
84
|
+
url: (key: string) => `https://api.apilayer.com/form`,
|
|
85
|
+
key: env.APILAYER_FORMAPI_KEY,
|
|
86
|
+
method: 'POST',
|
|
87
|
+
authType: 'header',
|
|
88
|
+
body: 'Test Form'
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: 'Number Verification API',
|
|
92
|
+
url: (key: string) => `https://api.apilayer.com/validate?number=1234567890&access_key=${key}`,
|
|
93
|
+
key: env.APILAYER_NUMVERIFY_KEY,
|
|
94
|
+
method: 'GET',
|
|
95
|
+
authType: 'query'
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'Email Verification API',
|
|
99
|
+
url: (key: string) => `https://api.apilayer.com/check?email=test@example.com&access_key=${key}`,
|
|
100
|
+
key: env.APILAYER_EMAILVERIFY_KEY,
|
|
101
|
+
method: 'GET',
|
|
102
|
+
authType: 'query'
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'Marketstack API',
|
|
106
|
+
url: (key: string) => `https://api.apilayer.com/eod?symbols=AAPL&access_key=${key}`,
|
|
107
|
+
key: env.APILAYER_MARKETSTACK_KEY,
|
|
108
|
+
method: 'GET',
|
|
109
|
+
authType: 'query'
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: 'World News API',
|
|
113
|
+
url: (key: string) => `https://api.apilayer.com/worldnews?keywords=test`,
|
|
114
|
+
key: env.APILAYER_WORLDNEWS_KEY,
|
|
115
|
+
method: 'GET',
|
|
116
|
+
authType: 'header'
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: 'Advanced Scraper API',
|
|
120
|
+
url: (key: string) => `https://api.apilayer.com/scraper?url=https://example.com`,
|
|
121
|
+
key: env.APILAYER_SCRAPER_KEY,
|
|
122
|
+
method: 'GET',
|
|
123
|
+
authType: 'header'
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: 'Finance News API',
|
|
127
|
+
url: (key: string) => `https://api.apilayer.com/news?limit=5`,
|
|
128
|
+
key: env.APILAYER_FINANCENEWS_KEY,
|
|
129
|
+
method: 'GET',
|
|
130
|
+
authType: 'header'
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: 'VAT Layer API',
|
|
134
|
+
url: (key: string) => `https://api.apilayer.com/validate?country_code=SE&access_key=${key}`,
|
|
135
|
+
key: env.APILAYER_VATLAYER_KEY,
|
|
136
|
+
method: 'GET',
|
|
137
|
+
authType: 'query'
|
|
138
|
+
}
|
|
139
|
+
];
|
|
140
|
+
|
|
141
|
+
async function runTests() {
|
|
142
|
+
console.log('๐งช Testing all 14 APILayer services...\n');
|
|
143
|
+
|
|
144
|
+
for (const test of tests) {
|
|
145
|
+
if (!test.key) {
|
|
146
|
+
results.push({
|
|
147
|
+
name: test.name,
|
|
148
|
+
endpoint: 'N/A',
|
|
149
|
+
status: 'NO KEY',
|
|
150
|
+
success: false,
|
|
151
|
+
responseTime: 0
|
|
152
|
+
});
|
|
153
|
+
console.log(`โ ${test.name}: NO API KEY FOUND`);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
const startTime = Date.now();
|
|
159
|
+
const url = test.url(test.key);
|
|
160
|
+
|
|
161
|
+
const headers: Record<string, string> = {
|
|
162
|
+
'Content-Type': 'application/json'
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// Add API key as header if needed
|
|
166
|
+
if (test.authType === 'header') {
|
|
167
|
+
headers['apikey'] = test.key;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const options: RequestInit = {
|
|
171
|
+
method: test.method,
|
|
172
|
+
headers
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
if (test.body) {
|
|
176
|
+
options.body = test.body;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const response = await fetch(url, options);
|
|
180
|
+
const responseTime = Date.now() - startTime;
|
|
181
|
+
|
|
182
|
+
let success = false;
|
|
183
|
+
let error: string | undefined;
|
|
184
|
+
|
|
185
|
+
if (response.ok) {
|
|
186
|
+
success = true;
|
|
187
|
+
console.log(`โ
${test.name}: ${response.status} (${responseTime}ms)`);
|
|
188
|
+
} else {
|
|
189
|
+
let errorMsg = `HTTP ${response.status}`;
|
|
190
|
+
try {
|
|
191
|
+
const body = await response.json();
|
|
192
|
+
if (body.message) {
|
|
193
|
+
errorMsg += ` - ${body.message}`;
|
|
194
|
+
}
|
|
195
|
+
} catch {
|
|
196
|
+
// body not JSON
|
|
197
|
+
}
|
|
198
|
+
error = errorMsg;
|
|
199
|
+
console.log(`โ ${test.name}: ${errorMsg} (${responseTime}ms)`);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
results.push({
|
|
203
|
+
name: test.name,
|
|
204
|
+
endpoint: url.split('?')[0],
|
|
205
|
+
status: response.status,
|
|
206
|
+
success,
|
|
207
|
+
error,
|
|
208
|
+
responseTime
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
} catch (err) {
|
|
212
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
213
|
+
console.log(`โ ${test.name}: ${errorMsg}`);
|
|
214
|
+
|
|
215
|
+
results.push({
|
|
216
|
+
name: test.name,
|
|
217
|
+
endpoint: 'N/A',
|
|
218
|
+
status: 'ERROR',
|
|
219
|
+
success: false,
|
|
220
|
+
error: errorMsg,
|
|
221
|
+
responseTime: 0
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Summary
|
|
227
|
+
console.log('\n' + '='.repeat(60));
|
|
228
|
+
console.log('๐ SUMMARY');
|
|
229
|
+
console.log('='.repeat(60));
|
|
230
|
+
|
|
231
|
+
const working = results.filter(r => r.success);
|
|
232
|
+
const failed = results.filter(r => !r.success);
|
|
233
|
+
|
|
234
|
+
console.log(`\nโ
Working (${working.length}):`);
|
|
235
|
+
working.forEach(r => {
|
|
236
|
+
console.log(` โข ${r.name}`);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
if (failed.length > 0) {
|
|
240
|
+
console.log(`\nโ Failed (${failed.length}):`);
|
|
241
|
+
failed.forEach(r => {
|
|
242
|
+
console.log(` โข ${r.name}: ${r.error}`);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
console.log(`\n๐ Success rate: ${working.length}/${results.length} (${Math.round(working.length / results.length * 100)}%)`);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
runTests().catch(console.error);
|