@nordsym/apiclaw 1.0.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/.github/ISSUE_TEMPLATE/add-api.yml +123 -0
- package/BRIEFING.md +30 -0
- package/CONCEPT.md +494 -0
- package/README.md +272 -0
- package/backend/convex/README.md +90 -0
- package/backend/convex/_generated/api.d.ts +55 -0
- package/backend/convex/_generated/api.js +23 -0
- package/backend/convex/_generated/dataModel.d.ts +60 -0
- package/backend/convex/_generated/server.d.ts +143 -0
- package/backend/convex/_generated/server.js +93 -0
- package/backend/convex/apiKeys.ts +75 -0
- package/backend/convex/purchases.ts +74 -0
- package/backend/convex/schema.ts +45 -0
- package/backend/convex/transactions.ts +57 -0
- package/backend/convex/tsconfig.json +25 -0
- package/backend/convex/users.ts +94 -0
- package/backend/package-lock.json +521 -0
- package/backend/package.json +15 -0
- package/dist/credits.d.ts +54 -0
- package/dist/credits.d.ts.map +1 -0
- package/dist/credits.js +209 -0
- package/dist/credits.js.map +1 -0
- package/dist/discovery.d.ts +37 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +109 -0
- package/dist/discovery.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +355 -0
- package/dist/index.js.map +1 -0
- package/dist/registry/apis.json +20894 -0
- package/dist/registry/parse_apis.py +146 -0
- package/dist/revenuecat.d.ts +61 -0
- package/dist/revenuecat.d.ts.map +1 -0
- package/dist/revenuecat.js +166 -0
- package/dist/revenuecat.js.map +1 -0
- package/dist/test.d.ts +6 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +81 -0
- package/dist/test.js.map +1 -0
- package/dist/types.d.ts +96 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/webhooks/revenuecat.d.ts +48 -0
- package/dist/webhooks/revenuecat.d.ts.map +1 -0
- package/dist/webhooks/revenuecat.js +119 -0
- package/dist/webhooks/revenuecat.js.map +1 -0
- package/docs/revenuecat-setup.md +89 -0
- package/landing/next-env.d.ts +5 -0
- package/landing/next.config.mjs +6 -0
- package/landing/package-lock.json +1666 -0
- package/landing/package.json +27 -0
- package/landing/postcss.config.js +6 -0
- package/landing/src/app/api/keys/route.ts +71 -0
- package/landing/src/app/api/log/route.ts +37 -0
- package/landing/src/app/api/stats/route.ts +37 -0
- package/landing/src/app/globals.css +261 -0
- package/landing/src/app/layout.tsx +37 -0
- package/landing/src/app/page.tsx +753 -0
- package/landing/src/app/page.tsx.bak +567 -0
- package/landing/src/components/AddKeyModal.tsx +159 -0
- package/landing/tailwind.config.ts +34 -0
- package/landing/tsconfig.json +20 -0
- package/newsletter-template.html +71 -0
- package/outreach/OUTREACH-SYSTEM.md +211 -0
- package/outreach/email-template.html +179 -0
- package/outreach/targets.md +133 -0
- package/package.json +39 -0
- package/src/credits.ts +261 -0
- package/src/discovery.ts +147 -0
- package/src/index.ts +396 -0
- package/src/registry/apis.json +20894 -0
- package/src/registry/parse_apis.py +146 -0
- package/src/revenuecat.ts +239 -0
- package/src/test.ts +97 -0
- package/src/types.ts +110 -0
- package/src/webhooks/revenuecat.ts +187 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Parse public-apis README and convert to APIClaw registry format
|
|
4
|
+
"""
|
|
5
|
+
import re
|
|
6
|
+
import json
|
|
7
|
+
import hashlib
|
|
8
|
+
|
|
9
|
+
# Read the README content
|
|
10
|
+
with open('/tmp/public-apis-readme.md', 'r') as f:
|
|
11
|
+
content = f.read()
|
|
12
|
+
|
|
13
|
+
apis = []
|
|
14
|
+
current_category = None
|
|
15
|
+
|
|
16
|
+
# Split by lines
|
|
17
|
+
lines = content.split('\n')
|
|
18
|
+
|
|
19
|
+
for i, line in enumerate(lines):
|
|
20
|
+
# Check for category headers (### Animals, ### Anime, etc.)
|
|
21
|
+
if line.startswith('### ') and not line.startswith('### API'):
|
|
22
|
+
current_category = line[4:].strip()
|
|
23
|
+
continue
|
|
24
|
+
|
|
25
|
+
# Skip non-table rows
|
|
26
|
+
if not line.startswith('|'):
|
|
27
|
+
continue
|
|
28
|
+
|
|
29
|
+
# Skip header rows and separator rows
|
|
30
|
+
if '---' in line or 'API | Description' in line or 'API|Description' in line:
|
|
31
|
+
continue
|
|
32
|
+
|
|
33
|
+
# Parse table row
|
|
34
|
+
# Format: | [Name](url) | Description | Auth | HTTPS | CORS |
|
|
35
|
+
parts = line.split('|')
|
|
36
|
+
if len(parts) < 5:
|
|
37
|
+
continue
|
|
38
|
+
|
|
39
|
+
# Extract API info
|
|
40
|
+
api_cell = parts[1].strip() if len(parts) > 1 else ''
|
|
41
|
+
desc_cell = parts[2].strip() if len(parts) > 2 else ''
|
|
42
|
+
auth_cell = parts[3].strip() if len(parts) > 3 else ''
|
|
43
|
+
https_cell = parts[4].strip() if len(parts) > 4 else ''
|
|
44
|
+
cors_cell = parts[5].strip() if len(parts) > 5 else ''
|
|
45
|
+
|
|
46
|
+
# Extract name and link from markdown link format [Name](url)
|
|
47
|
+
link_match = re.match(r'\[([^\]]+)\]\(([^)]+)\)', api_cell)
|
|
48
|
+
if not link_match:
|
|
49
|
+
continue
|
|
50
|
+
|
|
51
|
+
name = link_match.group(1)
|
|
52
|
+
link = link_match.group(2)
|
|
53
|
+
|
|
54
|
+
# Generate slug ID
|
|
55
|
+
slug = re.sub(r'[^a-z0-9]+', '-', name.lower()).strip('-')
|
|
56
|
+
|
|
57
|
+
# Parse auth type
|
|
58
|
+
auth = 'None'
|
|
59
|
+
if '`apiKey`' in auth_cell or 'apiKey' in auth_cell:
|
|
60
|
+
auth = 'apiKey'
|
|
61
|
+
elif '`OAuth`' in auth_cell or 'OAuth' in auth_cell:
|
|
62
|
+
auth = 'OAuth'
|
|
63
|
+
elif '`X-Mashape-Key`' in auth_cell:
|
|
64
|
+
auth = 'apiKey'
|
|
65
|
+
elif '`User-Agent`' in auth_cell:
|
|
66
|
+
auth = 'User-Agent'
|
|
67
|
+
elif 'No' in auth_cell:
|
|
68
|
+
auth = 'None'
|
|
69
|
+
|
|
70
|
+
# Parse HTTPS
|
|
71
|
+
https = 'Yes' in https_cell
|
|
72
|
+
|
|
73
|
+
# Parse CORS
|
|
74
|
+
cors = 'unknown'
|
|
75
|
+
if 'Yes' in cors_cell:
|
|
76
|
+
cors = 'yes'
|
|
77
|
+
elif 'No' in cors_cell:
|
|
78
|
+
cors = 'no'
|
|
79
|
+
|
|
80
|
+
# Generate keywords from category and description
|
|
81
|
+
keywords = []
|
|
82
|
+
if current_category:
|
|
83
|
+
keywords.append(current_category.lower().replace(' & ', '-').replace(' ', '-'))
|
|
84
|
+
|
|
85
|
+
# Add some common keywords from description
|
|
86
|
+
desc_lower = desc_cell.lower()
|
|
87
|
+
for keyword in ['data', 'api', 'free', 'real-time', 'json', 'rest', 'graphql']:
|
|
88
|
+
if keyword in desc_lower:
|
|
89
|
+
keywords.append(keyword)
|
|
90
|
+
|
|
91
|
+
api_entry = {
|
|
92
|
+
"id": slug,
|
|
93
|
+
"name": name,
|
|
94
|
+
"description": desc_cell,
|
|
95
|
+
"category": current_category or "Uncategorized",
|
|
96
|
+
"auth": auth,
|
|
97
|
+
"https": https,
|
|
98
|
+
"cors": cors,
|
|
99
|
+
"link": link,
|
|
100
|
+
"pricing": "unknown", # public-apis doesn't have pricing info
|
|
101
|
+
"keywords": list(set(keywords))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
apis.append(api_entry)
|
|
105
|
+
|
|
106
|
+
# Remove duplicates by ID (keep first occurrence)
|
|
107
|
+
seen_ids = set()
|
|
108
|
+
unique_apis = []
|
|
109
|
+
for api in apis:
|
|
110
|
+
if api['id'] not in seen_ids:
|
|
111
|
+
seen_ids.add(api['id'])
|
|
112
|
+
unique_apis.append(api)
|
|
113
|
+
else:
|
|
114
|
+
# Make ID unique by appending category
|
|
115
|
+
cat_slug = re.sub(r'[^a-z0-9]+', '-', api['category'].lower()).strip('-')
|
|
116
|
+
new_id = f"{api['id']}-{cat_slug}"
|
|
117
|
+
if new_id not in seen_ids:
|
|
118
|
+
api['id'] = new_id
|
|
119
|
+
seen_ids.add(new_id)
|
|
120
|
+
unique_apis.append(api)
|
|
121
|
+
|
|
122
|
+
print(f"Parsed {len(unique_apis)} unique APIs")
|
|
123
|
+
|
|
124
|
+
# Write to JSON
|
|
125
|
+
output = {
|
|
126
|
+
"version": "1.0.0",
|
|
127
|
+
"source": "https://github.com/public-apis/public-apis",
|
|
128
|
+
"lastUpdated": "2026-02-16",
|
|
129
|
+
"count": len(unique_apis),
|
|
130
|
+
"apis": unique_apis
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
with open('/Users/gustavhemmingsson/clawd/products/api-discovery/src/registry/apis.json', 'w') as f:
|
|
134
|
+
json.dump(output, f, indent=2)
|
|
135
|
+
|
|
136
|
+
print(f"Wrote to apis.json")
|
|
137
|
+
|
|
138
|
+
# Print some stats
|
|
139
|
+
categories = {}
|
|
140
|
+
for api in unique_apis:
|
|
141
|
+
cat = api['category']
|
|
142
|
+
categories[cat] = categories.get(cat, 0) + 1
|
|
143
|
+
|
|
144
|
+
print("\nAPIs per category:")
|
|
145
|
+
for cat, count in sorted(categories.items(), key=lambda x: -x[1]):
|
|
146
|
+
print(f" {cat}: {count}")
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// RevenueCat integration for APIClaw
|
|
2
|
+
// Handles Pro subscription checking and fee calculation
|
|
3
|
+
|
|
4
|
+
const REVENUECAT_API_URL = 'https://api.revenuecat.com/v1';
|
|
5
|
+
const PROJECT_ID = '0d074df4';
|
|
6
|
+
|
|
7
|
+
// Entitlement identifiers
|
|
8
|
+
export const ENTITLEMENTS = {
|
|
9
|
+
PRO: 'pro',
|
|
10
|
+
} as const;
|
|
11
|
+
|
|
12
|
+
// Product identifiers
|
|
13
|
+
export const PRODUCTS = {
|
|
14
|
+
PRO_MONTHLY: 'apiclaw_pro_monthly',
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
// Fee structure
|
|
18
|
+
const FEES = {
|
|
19
|
+
FREE: 0.05, // 5% transaction fee
|
|
20
|
+
PRO: 0.02, // 2% transaction fee
|
|
21
|
+
} as const;
|
|
22
|
+
|
|
23
|
+
interface RevenueCatSubscriber {
|
|
24
|
+
subscriber: {
|
|
25
|
+
entitlements: Record<string, {
|
|
26
|
+
product_identifier: string;
|
|
27
|
+
expires_date: string | null;
|
|
28
|
+
purchase_date: string;
|
|
29
|
+
}>;
|
|
30
|
+
subscriptions: Record<string, {
|
|
31
|
+
expires_date: string | null;
|
|
32
|
+
purchase_date: string;
|
|
33
|
+
product_plan_identifier?: string;
|
|
34
|
+
billing_issues_detected_at?: string | null;
|
|
35
|
+
unsubscribe_detected_at?: string | null;
|
|
36
|
+
}>;
|
|
37
|
+
non_subscriptions: Record<string, unknown>;
|
|
38
|
+
first_seen: string;
|
|
39
|
+
original_app_user_id: string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get RevenueCat API key from environment
|
|
45
|
+
*/
|
|
46
|
+
function getApiKey(): string {
|
|
47
|
+
const key = process.env.REVENUECAT_SECRET_KEY;
|
|
48
|
+
if (!key) {
|
|
49
|
+
throw new Error('REVENUECAT_SECRET_KEY not set');
|
|
50
|
+
}
|
|
51
|
+
return key;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Fetch subscriber info from RevenueCat
|
|
56
|
+
*/
|
|
57
|
+
async function getSubscriber(userId: string): Promise<RevenueCatSubscriber | null> {
|
|
58
|
+
try {
|
|
59
|
+
const response = await fetch(
|
|
60
|
+
`${REVENUECAT_API_URL}/subscribers/${encodeURIComponent(userId)}`,
|
|
61
|
+
{
|
|
62
|
+
headers: {
|
|
63
|
+
'Authorization': `Bearer ${getApiKey()}`,
|
|
64
|
+
'Content-Type': 'application/json',
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
if (response.status === 404) {
|
|
70
|
+
return null; // User doesn't exist in RevenueCat
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!response.ok) {
|
|
74
|
+
throw new Error(`RevenueCat API error: ${response.status}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return await response.json() as RevenueCatSubscriber;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error('Error fetching subscriber:', error);
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Check if a user has Pro subscription
|
|
86
|
+
*/
|
|
87
|
+
export async function hasProSubscription(userId: string): Promise<boolean> {
|
|
88
|
+
const subscriber = await getSubscriber(userId);
|
|
89
|
+
|
|
90
|
+
if (!subscriber) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const proEntitlement = subscriber.subscriber.entitlements[ENTITLEMENTS.PRO];
|
|
95
|
+
|
|
96
|
+
if (!proEntitlement) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Check if entitlement is active (not expired)
|
|
101
|
+
if (proEntitlement.expires_date) {
|
|
102
|
+
const expiresAt = new Date(proEntitlement.expires_date);
|
|
103
|
+
if (expiresAt < new Date()) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Get all entitlements for a user
|
|
113
|
+
*/
|
|
114
|
+
export async function getEntitlements(userId: string): Promise<{
|
|
115
|
+
pro: boolean;
|
|
116
|
+
expiresAt: string | null;
|
|
117
|
+
purchaseDate: string | null;
|
|
118
|
+
}> {
|
|
119
|
+
const subscriber = await getSubscriber(userId);
|
|
120
|
+
|
|
121
|
+
const result = {
|
|
122
|
+
pro: false,
|
|
123
|
+
expiresAt: null as string | null,
|
|
124
|
+
purchaseDate: null as string | null,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
if (!subscriber) {
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const proEntitlement = subscriber.subscriber.entitlements[ENTITLEMENTS.PRO];
|
|
132
|
+
|
|
133
|
+
if (proEntitlement) {
|
|
134
|
+
const expiresAt = proEntitlement.expires_date
|
|
135
|
+
? new Date(proEntitlement.expires_date)
|
|
136
|
+
: null;
|
|
137
|
+
|
|
138
|
+
result.pro = !expiresAt || expiresAt > new Date();
|
|
139
|
+
result.expiresAt = proEntitlement.expires_date;
|
|
140
|
+
result.purchaseDate = proEntitlement.purchase_date;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Get fee percentage based on subscription status
|
|
148
|
+
* Pro = 2%, Free = 5%
|
|
149
|
+
*/
|
|
150
|
+
export async function getFeePercentage(userId: string): Promise<number> {
|
|
151
|
+
const isPro = await hasProSubscription(userId);
|
|
152
|
+
return isPro ? FEES.PRO : FEES.FREE;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Calculate platform fee for a transaction
|
|
157
|
+
*/
|
|
158
|
+
export async function calculateFee(userId: string, amountUsd: number): Promise<{
|
|
159
|
+
feePercentage: number;
|
|
160
|
+
feeAmount: number;
|
|
161
|
+
netAmount: number;
|
|
162
|
+
isPro: boolean;
|
|
163
|
+
}> {
|
|
164
|
+
const isPro = await hasProSubscription(userId);
|
|
165
|
+
const feePercentage = isPro ? FEES.PRO : FEES.FREE;
|
|
166
|
+
const feeAmount = amountUsd * feePercentage;
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
feePercentage,
|
|
170
|
+
feeAmount: Math.round(feeAmount * 100) / 100, // Round to 2 decimals
|
|
171
|
+
netAmount: Math.round((amountUsd - feeAmount) * 100) / 100,
|
|
172
|
+
isPro,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Create or update subscriber attributes
|
|
178
|
+
*/
|
|
179
|
+
export async function setSubscriberAttributes(
|
|
180
|
+
userId: string,
|
|
181
|
+
attributes: Record<string, string>
|
|
182
|
+
): Promise<boolean> {
|
|
183
|
+
try {
|
|
184
|
+
const formattedAttributes: Record<string, { value: string }> = {};
|
|
185
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
186
|
+
formattedAttributes[`$${key}`] = { value };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const response = await fetch(
|
|
190
|
+
`${REVENUECAT_API_URL}/subscribers/${encodeURIComponent(userId)}/attributes`,
|
|
191
|
+
{
|
|
192
|
+
method: 'POST',
|
|
193
|
+
headers: {
|
|
194
|
+
'Authorization': `Bearer ${getApiKey()}`,
|
|
195
|
+
'Content-Type': 'application/json',
|
|
196
|
+
},
|
|
197
|
+
body: JSON.stringify({ attributes: formattedAttributes }),
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
return response.ok;
|
|
202
|
+
} catch (error) {
|
|
203
|
+
console.error('Error setting subscriber attributes:', error);
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Grant promotional entitlement (for testing/promos)
|
|
210
|
+
*/
|
|
211
|
+
export async function grantPromoEntitlement(
|
|
212
|
+
userId: string,
|
|
213
|
+
durationDays: number = 30
|
|
214
|
+
): Promise<boolean> {
|
|
215
|
+
try {
|
|
216
|
+
const response = await fetch(
|
|
217
|
+
`${REVENUECAT_API_URL}/subscribers/${encodeURIComponent(userId)}/entitlements/${ENTITLEMENTS.PRO}/promotional`,
|
|
218
|
+
{
|
|
219
|
+
method: 'POST',
|
|
220
|
+
headers: {
|
|
221
|
+
'Authorization': `Bearer ${getApiKey()}`,
|
|
222
|
+
'Content-Type': 'application/json',
|
|
223
|
+
},
|
|
224
|
+
body: JSON.stringify({
|
|
225
|
+
duration: 'daily',
|
|
226
|
+
duration_count: durationDays,
|
|
227
|
+
}),
|
|
228
|
+
}
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
return response.ok;
|
|
232
|
+
} catch (error) {
|
|
233
|
+
console.error('Error granting promo entitlement:', error);
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Export types for use elsewhere
|
|
239
|
+
export type { RevenueCatSubscriber };
|
package/src/test.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test script for APIvault
|
|
3
|
+
* Run: pnpm test
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { discoverAPIs, getAPIDetails, getCategories, getAllAPIs, getAPICount } from './discovery.js';
|
|
7
|
+
import { addCredits, purchaseAPIAccess, getBalanceSummary } from './credits.js';
|
|
8
|
+
|
|
9
|
+
console.log('š APIvault Test Suite\n');
|
|
10
|
+
console.log('='.repeat(50));
|
|
11
|
+
|
|
12
|
+
// Test 1: API Count
|
|
13
|
+
console.log('\nš Test 1: API Registry');
|
|
14
|
+
console.log('-'.repeat(40));
|
|
15
|
+
console.log(`Total APIs loaded: ${getAPICount()}`);
|
|
16
|
+
|
|
17
|
+
// Test 2: Discovery
|
|
18
|
+
console.log('\nš” Test 2: API Discovery');
|
|
19
|
+
console.log('-'.repeat(40));
|
|
20
|
+
|
|
21
|
+
const smsResults = discoverAPIs('SMS');
|
|
22
|
+
console.log(`Query: "SMS"`);
|
|
23
|
+
console.log(`Results: ${smsResults.length}`);
|
|
24
|
+
smsResults.slice(0, 5).forEach(r => {
|
|
25
|
+
console.log(` - ${r.api.name} (score: ${r.relevance_score})`);
|
|
26
|
+
console.log(` ${r.api.description.slice(0, 60)}...`);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const weatherResults = discoverAPIs('weather');
|
|
30
|
+
console.log(`\nQuery: "weather"`);
|
|
31
|
+
console.log(`Results: ${weatherResults.length}`);
|
|
32
|
+
weatherResults.slice(0, 5).forEach(r => {
|
|
33
|
+
console.log(` - ${r.api.name} (score: ${r.relevance_score})`);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const paymentResults = discoverAPIs('payment');
|
|
37
|
+
console.log(`\nQuery: "payment"`);
|
|
38
|
+
console.log(`Results: ${paymentResults.length}`);
|
|
39
|
+
paymentResults.slice(0, 5).forEach(r => {
|
|
40
|
+
console.log(` - ${r.api.name} (score: ${r.relevance_score})`);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Test 3: Get API Details
|
|
44
|
+
console.log('\nš Test 3: API Details');
|
|
45
|
+
console.log('-'.repeat(40));
|
|
46
|
+
|
|
47
|
+
const stripe = getAPIDetails('stripe');
|
|
48
|
+
if (stripe) {
|
|
49
|
+
console.log(`\n${stripe.name}:`);
|
|
50
|
+
console.log(` Category: ${stripe.category}`);
|
|
51
|
+
console.log(` Auth: ${stripe.auth}`);
|
|
52
|
+
console.log(` HTTPS: ${stripe.https}`);
|
|
53
|
+
console.log(` Link: ${stripe.link}`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Test 4: Categories
|
|
57
|
+
console.log('\nš Test 4: Categories');
|
|
58
|
+
console.log('-'.repeat(40));
|
|
59
|
+
|
|
60
|
+
const categories = getCategories();
|
|
61
|
+
console.log(`Total categories: ${categories.length}`);
|
|
62
|
+
console.log(`Sample: ${categories.slice(0, 10).join(', ')}...`);
|
|
63
|
+
|
|
64
|
+
// Test 5: Credits System
|
|
65
|
+
console.log('\nš° Test 5: Credit System');
|
|
66
|
+
console.log('-'.repeat(40));
|
|
67
|
+
|
|
68
|
+
const testAgent = 'agent_test_123';
|
|
69
|
+
|
|
70
|
+
// Check initial balance
|
|
71
|
+
let balance = getBalanceSummary(testAgent);
|
|
72
|
+
console.log(`Initial balance: $${balance.credits.balance_usd}`);
|
|
73
|
+
|
|
74
|
+
// Add credits
|
|
75
|
+
addCredits(testAgent, 50);
|
|
76
|
+
balance = getBalanceSummary(testAgent);
|
|
77
|
+
console.log(`After adding $50: $${balance.credits.balance_usd}`);
|
|
78
|
+
|
|
79
|
+
// Purchase API access
|
|
80
|
+
console.log('\nš Purchasing stripe access for $10...');
|
|
81
|
+
const purchase = purchaseAPIAccess(testAgent, 'stripe', 10);
|
|
82
|
+
if (purchase.success) {
|
|
83
|
+
console.log(` ā
Purchase successful!`);
|
|
84
|
+
console.log(` Purchase ID: ${purchase.purchase!.id}`);
|
|
85
|
+
console.log(` Credits received: ${purchase.purchase!.credits_purchased}`);
|
|
86
|
+
} else {
|
|
87
|
+
console.log(` ā Purchase failed: ${purchase.error}`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Check updated balance
|
|
91
|
+
balance = getBalanceSummary(testAgent);
|
|
92
|
+
console.log(`\nFinal balance: $${balance.credits.balance_usd}`);
|
|
93
|
+
console.log(`Total spent: $${balance.total_spent_usd}`);
|
|
94
|
+
console.log(`Active purchases: ${balance.active_purchases.length}`);
|
|
95
|
+
|
|
96
|
+
console.log('\n' + '='.repeat(50));
|
|
97
|
+
console.log('ā
All tests completed!\n');
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Core types for APIvault
|
|
2
|
+
|
|
3
|
+
// Simplified API from public-apis import
|
|
4
|
+
export interface SimpleAPI {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
category: string;
|
|
9
|
+
auth: string;
|
|
10
|
+
https: boolean;
|
|
11
|
+
cors: string;
|
|
12
|
+
link: string;
|
|
13
|
+
pricing: string;
|
|
14
|
+
keywords: string[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Full API provider (for detailed/curated APIs)
|
|
18
|
+
export interface APIProvider {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
category: string;
|
|
23
|
+
capabilities: string[];
|
|
24
|
+
keywords: string[];
|
|
25
|
+
pricing: APIPricing;
|
|
26
|
+
auth_type: string; // api_key, basic, oauth, bearer
|
|
27
|
+
docs_url: string;
|
|
28
|
+
base_url: string;
|
|
29
|
+
endpoints: APIEndpoint[];
|
|
30
|
+
features: string[];
|
|
31
|
+
compliance: string[];
|
|
32
|
+
regions: string[];
|
|
33
|
+
agent_success_rate: number;
|
|
34
|
+
avg_latency_ms: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface APIPricing {
|
|
38
|
+
model: string; // per_unit, per_query, per_token, per_character, subscription
|
|
39
|
+
free_tier: boolean;
|
|
40
|
+
minimum_purchase: number | null;
|
|
41
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface APIEndpoint {
|
|
45
|
+
name: string;
|
|
46
|
+
method: string;
|
|
47
|
+
path: string;
|
|
48
|
+
params: string[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface SearchResult {
|
|
52
|
+
provider: APIProvider;
|
|
53
|
+
relevance_score: number;
|
|
54
|
+
match_reasons: string[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface AgentCredits {
|
|
58
|
+
agent_id: string;
|
|
59
|
+
balance_usd: number;
|
|
60
|
+
currency: string;
|
|
61
|
+
created_at: string;
|
|
62
|
+
updated_at: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface Purchase {
|
|
66
|
+
id: string;
|
|
67
|
+
agent_id: string;
|
|
68
|
+
provider_id: string;
|
|
69
|
+
amount_usd: number;
|
|
70
|
+
credits_purchased: number;
|
|
71
|
+
status: 'pending' | 'active' | 'exhausted' | 'refunded';
|
|
72
|
+
credentials?: APICredentials;
|
|
73
|
+
created_at: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface APICredentials {
|
|
77
|
+
type: string; // api_key, basic, bearer
|
|
78
|
+
api_key?: string;
|
|
79
|
+
username?: string;
|
|
80
|
+
password?: string;
|
|
81
|
+
expires_at?: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface UsageRecord {
|
|
85
|
+
purchase_id: string;
|
|
86
|
+
provider_id: string;
|
|
87
|
+
units_used: number;
|
|
88
|
+
units_remaining: number;
|
|
89
|
+
cost_incurred_usd: number;
|
|
90
|
+
last_used_at: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Subscription types
|
|
94
|
+
export interface UserSubscription {
|
|
95
|
+
user_id: string;
|
|
96
|
+
tier: 'free' | 'pro';
|
|
97
|
+
status: 'active' | 'cancelled' | 'expired' | 'paused' | 'billing_issue';
|
|
98
|
+
product_id: string | null;
|
|
99
|
+
expires_at: string | null;
|
|
100
|
+
fee_percentage: number; // 0.05 for free, 0.02 for pro
|
|
101
|
+
updated_at: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface TransactionFee {
|
|
105
|
+
amount_usd: number;
|
|
106
|
+
fee_percentage: number;
|
|
107
|
+
fee_amount_usd: number;
|
|
108
|
+
net_amount_usd: number;
|
|
109
|
+
tier: 'free' | 'pro';
|
|
110
|
+
}
|