@nordsym/apiclaw 1.2.2 → 1.2.3
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/AGENTS.md +50 -33
- package/README.md +22 -12
- package/SOUL.md +60 -19
- package/STATUS.md +91 -169
- package/convex/_generated/api.d.ts +6 -0
- package/convex/directCall.ts +598 -0
- package/convex/providers.ts +341 -26
- package/convex/schema.ts +87 -0
- package/convex/usage.ts +260 -0
- package/convex/waitlist.ts +55 -0
- package/data/combined-02-26.json +22102 -0
- package/data/night-expansion-02-26-06-batch2.json +1898 -0
- package/data/night-expansion-02-26-06-batch3.json +1410 -0
- package/data/night-expansion-02-26-06.json +3146 -0
- package/data/night-expansion-02-26-full.json +9726 -0
- package/data/night-expansion-02-26-v2.json +330 -0
- package/data/night-expansion-02-26.json +171 -0
- package/dist/crypto.d.ts +7 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +67 -0
- package/dist/crypto.js.map +1 -0
- package/dist/execute-dynamic.d.ts +116 -0
- package/dist/execute-dynamic.d.ts.map +1 -0
- package/dist/execute-dynamic.js +456 -0
- package/dist/execute-dynamic.js.map +1 -0
- package/dist/execute.d.ts +2 -1
- package/dist/execute.d.ts.map +1 -1
- package/dist/execute.js +35 -5
- package/dist/execute.js.map +1 -1
- package/dist/index.js +33 -4
- package/dist/index.js.map +1 -1
- package/dist/registry/apis.json +2081 -3
- package/docs/PRD-customer-key-passthrough.md +184 -0
- package/landing/public/badges/available-on-apiclaw.svg +14 -0
- package/landing/scripts/generate-stats.js +75 -4
- package/landing/src/app/admin/page.tsx +1 -1
- package/landing/src/app/api/auth/magic-link/route.ts +1 -1
- package/landing/src/app/api/auth/session/route.ts +1 -1
- package/landing/src/app/api/auth/verify/route.ts +1 -1
- package/landing/src/app/api/og/route.tsx +5 -3
- package/landing/src/app/docs/page.tsx +5 -4
- package/landing/src/app/earn/page.tsx +14 -11
- package/landing/src/app/globals.css +16 -15
- package/landing/src/app/layout.tsx +2 -2
- package/landing/src/app/page.tsx +425 -254
- package/landing/src/app/providers/dashboard/[apiId]/actions/[actionId]/edit/page.tsx +600 -0
- package/landing/src/app/providers/dashboard/[apiId]/actions/new/page.tsx +583 -0
- package/landing/src/app/providers/dashboard/[apiId]/actions/page.tsx +301 -0
- package/landing/src/app/providers/dashboard/[apiId]/direct-call/page.tsx +659 -0
- package/landing/src/app/providers/dashboard/[apiId]/page.tsx +381 -0
- package/landing/src/app/providers/dashboard/[apiId]/test/page.tsx +418 -0
- package/landing/src/app/providers/dashboard/layout.tsx +292 -0
- package/landing/src/app/providers/dashboard/page.tsx +353 -290
- package/landing/src/app/providers/register/page.tsx +87 -10
- package/landing/src/components/AiClientDropdown.tsx +85 -0
- package/landing/src/components/ConfigHelperModal.tsx +113 -0
- package/landing/src/components/HeroTabs.tsx +187 -0
- package/landing/src/components/ShareIntegrationModal.tsx +198 -0
- package/landing/src/hooks/useDashboardData.ts +53 -1
- package/landing/src/lib/apis.json +46554 -174
- package/landing/src/lib/convex-client.ts +22 -3
- package/landing/src/lib/stats.json +4 -4
- package/landing/tsconfig.tsbuildinfo +1 -1
- package/night-expansion-02-26-06-batch2.py +368 -0
- package/night-expansion-02-26-06-batch3.py +299 -0
- package/night-expansion-02-26-06.py +756 -0
- package/package.json +1 -1
- package/scripts/bulk-add-public-apis-v2.py +418 -0
- package/scripts/night-expansion-02-26-v2.py +296 -0
- package/scripts/night-expansion-02-26.py +890 -0
- package/scripts/seed-complete-api.js +181 -0
- package/scripts/seed-demo-api.sh +44 -0
- package/src/crypto.ts +75 -0
- package/src/execute-dynamic.ts +589 -0
- package/src/execute.ts +41 -5
- package/src/index.ts +38 -4
- package/src/registry/apis.json +2081 -3
package/convex/usage.ts
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { mutation, query } from "./_generated/server";
|
|
3
|
+
|
|
4
|
+
// ============================================
|
|
5
|
+
// MUTATIONS
|
|
6
|
+
// ============================================
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Log an API call usage
|
|
10
|
+
*/
|
|
11
|
+
export const logUsage = mutation({
|
|
12
|
+
args: {
|
|
13
|
+
userId: v.string(),
|
|
14
|
+
providerId: v.id("providers"),
|
|
15
|
+
directCallId: v.id("providerDirectCall"),
|
|
16
|
+
actionName: v.string(),
|
|
17
|
+
success: v.boolean(),
|
|
18
|
+
latencyMs: v.number(),
|
|
19
|
+
creditsUsed: v.number(),
|
|
20
|
+
errorMessage: v.optional(v.string()),
|
|
21
|
+
},
|
|
22
|
+
handler: async (ctx, args) => {
|
|
23
|
+
return await ctx.db.insert("usageLog", {
|
|
24
|
+
userId: args.userId,
|
|
25
|
+
providerId: args.providerId,
|
|
26
|
+
directCallId: args.directCallId,
|
|
27
|
+
actionName: args.actionName,
|
|
28
|
+
timestamp: Date.now(),
|
|
29
|
+
success: args.success,
|
|
30
|
+
latencyMs: args.latencyMs,
|
|
31
|
+
creditsUsed: args.creditsUsed,
|
|
32
|
+
errorMessage: args.errorMessage,
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// ============================================
|
|
38
|
+
// QUERIES
|
|
39
|
+
// ============================================
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get user usage stats for rate limiting
|
|
43
|
+
* Returns counts for last minute and last day
|
|
44
|
+
*/
|
|
45
|
+
export const getUserUsage = query({
|
|
46
|
+
args: {
|
|
47
|
+
userId: v.string(),
|
|
48
|
+
providerId: v.id("providers"),
|
|
49
|
+
},
|
|
50
|
+
handler: async (ctx, args) => {
|
|
51
|
+
const now = Date.now();
|
|
52
|
+
const oneMinuteAgo = now - 60 * 1000;
|
|
53
|
+
const oneDayAgo = now - 24 * 60 * 60 * 1000;
|
|
54
|
+
|
|
55
|
+
// Get all usage for this user + provider in the last 24h
|
|
56
|
+
const recentUsage = await ctx.db
|
|
57
|
+
.query("usageLog")
|
|
58
|
+
.withIndex("by_userId_providerId", (q) =>
|
|
59
|
+
q.eq("userId", args.userId).eq("providerId", args.providerId)
|
|
60
|
+
)
|
|
61
|
+
.filter((q) => q.gte(q.field("timestamp"), oneDayAgo))
|
|
62
|
+
.collect();
|
|
63
|
+
|
|
64
|
+
// Calculate counts
|
|
65
|
+
const minuteCount = recentUsage.filter((u) => u.timestamp >= oneMinuteAgo).length;
|
|
66
|
+
const dayCount = recentUsage.length;
|
|
67
|
+
const totalCredits = recentUsage.reduce((sum, u) => sum + u.creditsUsed, 0);
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
minute: minuteCount,
|
|
71
|
+
day: dayCount,
|
|
72
|
+
totalCreditsUsed: totalCredits,
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Get provider usage stats for analytics
|
|
79
|
+
*/
|
|
80
|
+
export const getProviderUsage = query({
|
|
81
|
+
args: {
|
|
82
|
+
providerId: v.id("providers"),
|
|
83
|
+
periodDays: v.optional(v.number()), // default 30
|
|
84
|
+
},
|
|
85
|
+
handler: async (ctx, args) => {
|
|
86
|
+
const periodDays = args.periodDays ?? 30;
|
|
87
|
+
const now = Date.now();
|
|
88
|
+
const periodStart = now - periodDays * 24 * 60 * 60 * 1000;
|
|
89
|
+
|
|
90
|
+
const usage = await ctx.db
|
|
91
|
+
.query("usageLog")
|
|
92
|
+
.withIndex("by_providerId", (q) => q.eq("providerId", args.providerId))
|
|
93
|
+
.filter((q) => q.gte(q.field("timestamp"), periodStart))
|
|
94
|
+
.collect();
|
|
95
|
+
|
|
96
|
+
// Aggregate stats
|
|
97
|
+
const totalCalls = usage.length;
|
|
98
|
+
const successfulCalls = usage.filter((u) => u.success).length;
|
|
99
|
+
const failedCalls = totalCalls - successfulCalls;
|
|
100
|
+
const totalCredits = usage.reduce((sum, u) => sum + u.creditsUsed, 0);
|
|
101
|
+
const totalLatency = usage.reduce((sum, u) => sum + u.latencyMs, 0);
|
|
102
|
+
const avgLatency = totalCalls > 0 ? Math.round(totalLatency / totalCalls) : 0;
|
|
103
|
+
|
|
104
|
+
// Group by action
|
|
105
|
+
const byAction: Record<string, { calls: number; credits: number }> = {};
|
|
106
|
+
for (const u of usage) {
|
|
107
|
+
if (!byAction[u.actionName]) {
|
|
108
|
+
byAction[u.actionName] = { calls: 0, credits: 0 };
|
|
109
|
+
}
|
|
110
|
+
byAction[u.actionName].calls++;
|
|
111
|
+
byAction[u.actionName].credits += u.creditsUsed;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Group by day for chart
|
|
115
|
+
const byDay: Record<string, { calls: number; credits: number }> = {};
|
|
116
|
+
for (const u of usage) {
|
|
117
|
+
const day = new Date(u.timestamp).toISOString().split("T")[0];
|
|
118
|
+
if (!byDay[day]) {
|
|
119
|
+
byDay[day] = { calls: 0, credits: 0 };
|
|
120
|
+
}
|
|
121
|
+
byDay[day].calls++;
|
|
122
|
+
byDay[day].credits += u.creditsUsed;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Unique users
|
|
126
|
+
const uniqueUsers = new Set(usage.map((u) => u.userId)).size;
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
periodDays,
|
|
130
|
+
totalCalls,
|
|
131
|
+
successfulCalls,
|
|
132
|
+
failedCalls,
|
|
133
|
+
successRate: totalCalls > 0 ? (successfulCalls / totalCalls) * 100 : 0,
|
|
134
|
+
totalCredits,
|
|
135
|
+
avgLatencyMs: avgLatency,
|
|
136
|
+
uniqueUsers,
|
|
137
|
+
byAction,
|
|
138
|
+
byDay,
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Get Direct Call specific usage stats
|
|
145
|
+
*/
|
|
146
|
+
export const getDirectCallUsage = query({
|
|
147
|
+
args: {
|
|
148
|
+
directCallId: v.id("providerDirectCall"),
|
|
149
|
+
periodDays: v.optional(v.number()),
|
|
150
|
+
},
|
|
151
|
+
handler: async (ctx, args) => {
|
|
152
|
+
const periodDays = args.periodDays ?? 30;
|
|
153
|
+
const now = Date.now();
|
|
154
|
+
const periodStart = now - periodDays * 24 * 60 * 60 * 1000;
|
|
155
|
+
|
|
156
|
+
const usage = await ctx.db
|
|
157
|
+
.query("usageLog")
|
|
158
|
+
.withIndex("by_directCallId", (q) => q.eq("directCallId", args.directCallId))
|
|
159
|
+
.filter((q) => q.gte(q.field("timestamp"), periodStart))
|
|
160
|
+
.collect();
|
|
161
|
+
|
|
162
|
+
const totalCalls = usage.length;
|
|
163
|
+
const successfulCalls = usage.filter((u) => u.success).length;
|
|
164
|
+
const totalCredits = usage.reduce((sum, u) => sum + u.creditsUsed, 0);
|
|
165
|
+
const totalLatency = usage.reduce((sum, u) => sum + u.latencyMs, 0);
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
periodDays,
|
|
169
|
+
totalCalls,
|
|
170
|
+
successfulCalls,
|
|
171
|
+
failedCalls: totalCalls - successfulCalls,
|
|
172
|
+
successRate: totalCalls > 0 ? (successfulCalls / totalCalls) * 100 : 0,
|
|
173
|
+
totalCredits,
|
|
174
|
+
avgLatencyMs: totalCalls > 0 ? Math.round(totalLatency / totalCalls) : 0,
|
|
175
|
+
uniqueUsers: new Set(usage.map((u) => u.userId)).size,
|
|
176
|
+
};
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Get recent usage logs (for dashboard/debugging)
|
|
182
|
+
*/
|
|
183
|
+
export const getRecentLogs = query({
|
|
184
|
+
args: {
|
|
185
|
+
providerId: v.optional(v.id("providers")),
|
|
186
|
+
directCallId: v.optional(v.id("providerDirectCall")),
|
|
187
|
+
limit: v.optional(v.number()),
|
|
188
|
+
},
|
|
189
|
+
handler: async (ctx, args) => {
|
|
190
|
+
const limit = args.limit ?? 50;
|
|
191
|
+
const { directCallId, providerId } = args;
|
|
192
|
+
|
|
193
|
+
if (directCallId !== undefined) {
|
|
194
|
+
return await ctx.db
|
|
195
|
+
.query("usageLog")
|
|
196
|
+
.withIndex("by_directCallId", (q) => q.eq("directCallId", directCallId))
|
|
197
|
+
.order("desc")
|
|
198
|
+
.take(limit);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (providerId !== undefined) {
|
|
202
|
+
return await ctx.db
|
|
203
|
+
.query("usageLog")
|
|
204
|
+
.withIndex("by_providerId", (q) => q.eq("providerId", providerId))
|
|
205
|
+
.order("desc")
|
|
206
|
+
.take(limit);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return await ctx.db
|
|
210
|
+
.query("usageLog")
|
|
211
|
+
.withIndex("by_timestamp")
|
|
212
|
+
.order("desc")
|
|
213
|
+
.take(limit);
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Check if user is within rate limits
|
|
219
|
+
* Returns { allowed: boolean, reason?: string }
|
|
220
|
+
*/
|
|
221
|
+
export const checkRateLimit = query({
|
|
222
|
+
args: {
|
|
223
|
+
userId: v.string(),
|
|
224
|
+
providerId: v.id("providers"),
|
|
225
|
+
rateLimitPerUser: v.number(),
|
|
226
|
+
rateLimitPerDay: v.number(),
|
|
227
|
+
},
|
|
228
|
+
handler: async (ctx, args) => {
|
|
229
|
+
const now = Date.now();
|
|
230
|
+
const oneMinuteAgo = now - 60 * 1000;
|
|
231
|
+
const oneDayAgo = now - 24 * 60 * 60 * 1000;
|
|
232
|
+
|
|
233
|
+
const recentUsage = await ctx.db
|
|
234
|
+
.query("usageLog")
|
|
235
|
+
.withIndex("by_userId_providerId", (q) =>
|
|
236
|
+
q.eq("userId", args.userId).eq("providerId", args.providerId)
|
|
237
|
+
)
|
|
238
|
+
.filter((q) => q.gte(q.field("timestamp"), oneDayAgo))
|
|
239
|
+
.collect();
|
|
240
|
+
|
|
241
|
+
const minuteCount = recentUsage.filter((u) => u.timestamp >= oneMinuteAgo).length;
|
|
242
|
+
const dayCount = recentUsage.length;
|
|
243
|
+
|
|
244
|
+
if (minuteCount >= args.rateLimitPerUser) {
|
|
245
|
+
return {
|
|
246
|
+
allowed: false,
|
|
247
|
+
reason: `Rate limit exceeded: ${minuteCount}/${args.rateLimitPerUser} requests per minute`,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (dayCount >= args.rateLimitPerDay) {
|
|
252
|
+
return {
|
|
253
|
+
allowed: false,
|
|
254
|
+
reason: `Daily limit exceeded: ${dayCount}/${args.rateLimitPerDay} requests per day`,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return { allowed: true };
|
|
259
|
+
},
|
|
260
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { mutation, query } from "./_generated/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
|
|
4
|
+
export const join = mutation({
|
|
5
|
+
args: {
|
|
6
|
+
email: v.string(),
|
|
7
|
+
type: v.optional(v.string()),
|
|
8
|
+
source: v.optional(v.string()),
|
|
9
|
+
},
|
|
10
|
+
handler: async (ctx, args) => {
|
|
11
|
+
const email = args.email.toLowerCase().trim();
|
|
12
|
+
|
|
13
|
+
// Check if already on waitlist
|
|
14
|
+
const existing = await ctx.db
|
|
15
|
+
.query("waitlist")
|
|
16
|
+
.withIndex("by_email", (q) => q.eq("email", email))
|
|
17
|
+
.first();
|
|
18
|
+
|
|
19
|
+
if (existing) {
|
|
20
|
+
return { success: true, alreadyExists: true };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
await ctx.db.insert("waitlist", {
|
|
24
|
+
email,
|
|
25
|
+
type: args.type || "provider",
|
|
26
|
+
source: args.source || "landing",
|
|
27
|
+
createdAt: Date.now(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return { success: true, alreadyExists: false };
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export const count = query({
|
|
35
|
+
args: {},
|
|
36
|
+
handler: async (ctx) => {
|
|
37
|
+
const all = await ctx.db.query("waitlist").collect();
|
|
38
|
+
return all.length;
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export const list = query({
|
|
43
|
+
args: {
|
|
44
|
+
type: v.optional(v.string()),
|
|
45
|
+
},
|
|
46
|
+
handler: async (ctx, args) => {
|
|
47
|
+
if (args.type) {
|
|
48
|
+
return await ctx.db
|
|
49
|
+
.query("waitlist")
|
|
50
|
+
.withIndex("by_type", (q) => q.eq("type", args.type!))
|
|
51
|
+
.collect();
|
|
52
|
+
}
|
|
53
|
+
return await ctx.db.query("waitlist").collect();
|
|
54
|
+
},
|
|
55
|
+
});
|