@nordsym/apiclaw 1.8.7 → 1.8.9
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/README.md +58 -30
- package/convex/adminActivate.d.ts +3 -0
- package/convex/adminActivate.d.ts.map +1 -1
- package/convex/adminActivate.js +46 -0
- package/convex/adminActivate.js.map +1 -1
- package/convex/adminActivate.ts +1 -2
- package/convex/adminStats.d.ts +9 -0
- package/convex/adminStats.d.ts.map +1 -1
- package/convex/adminStats.js +282 -0
- package/convex/adminStats.js.map +1 -1
- package/convex/adminStats.ts +5 -3
- package/convex/agents.d.ts +84 -0
- package/convex/agents.js +809 -0
- package/convex/analytics.d.ts +5 -0
- package/convex/analytics.js +167 -0
- package/convex/apiKeys.d.ts +6 -0
- package/convex/apiKeys.d.ts.map +1 -0
- package/convex/apiKeys.js +186 -0
- package/convex/apiKeys.js.map +1 -0
- package/convex/backfillAnalytics.d.ts +2 -0
- package/convex/backfillAnalytics.js +20 -0
- package/convex/backfillSearchLogs.d.ts +2 -0
- package/convex/backfillSearchLogs.js +29 -0
- package/convex/billing.d.ts +88 -0
- package/convex/billing.d.ts.map +1 -1
- package/convex/billing.js +643 -0
- package/convex/billing.js.map +1 -1
- package/convex/billing.ts +2 -14
- package/convex/capabilities.d.ts +9 -0
- package/convex/capabilities.js +145 -0
- package/convex/chains.d.ts +68 -0
- package/convex/chains.js +1105 -0
- package/convex/credits.d.ts +25 -0
- package/convex/credits.js +186 -0
- package/convex/crons.d.ts +3 -0
- package/convex/crons.js +17 -0
- package/convex/debugFilestackLogs.d.ts +2 -0
- package/convex/debugFilestackLogs.js +17 -0
- package/convex/debugGetToken.d.ts +2 -0
- package/convex/debugGetToken.js +18 -0
- package/convex/directCall.d.ts +72 -0
- package/convex/directCall.d.ts.map +1 -1
- package/convex/directCall.js +663 -0
- package/convex/directCall.js.map +1 -1
- package/convex/earnProgress.d.ts +58 -0
- package/convex/earnProgress.js +649 -0
- package/convex/email.d.ts +14 -0
- package/convex/email.js +300 -0
- package/convex/email.js.map +1 -1
- package/convex/feedback.d.ts +7 -0
- package/convex/feedback.js +227 -0
- package/convex/http.d.ts +3 -0
- package/convex/http.d.ts.map +1 -1
- package/convex/http.js +2135 -0
- package/convex/http.js.map +1 -1
- package/convex/http.ts +275 -3
- package/convex/inbound.d.ts +2 -0
- package/convex/inbound.js +32 -0
- package/convex/logs.d.ts +48 -0
- package/convex/logs.d.ts.map +1 -1
- package/convex/logs.js +623 -0
- package/convex/logs.js.map +1 -1
- package/convex/migrateFilestack.d.ts +2 -0
- package/convex/migrateFilestack.js +74 -0
- package/convex/migratePartnersProd.d.ts +8 -0
- package/convex/migratePartnersProd.js +165 -0
- package/convex/migratePratham.d.ts +2 -0
- package/convex/migratePratham.js +121 -0
- package/convex/migrateProviderWorkspaces.d.ts +13 -0
- package/convex/migrateProviderWorkspaces.d.ts.map +1 -1
- package/convex/migrateProviderWorkspaces.js +141 -0
- package/convex/migrateProviderWorkspaces.js.map +1 -1
- package/convex/mou.d.ts +6 -0
- package/convex/mou.js +82 -0
- package/convex/providerKeys.d.ts +31 -0
- package/convex/providerKeys.js +257 -0
- package/convex/providers.d.ts +35 -0
- package/convex/providers.d.ts.map +1 -1
- package/convex/providers.js +1027 -0
- package/convex/providers.js.map +1 -1
- package/convex/purchases.d.ts +7 -0
- package/convex/purchases.js +157 -0
- package/convex/ratelimit.d.ts +4 -0
- package/convex/ratelimit.js +91 -0
- package/convex/schema.ts +4 -4
- package/convex/searchLogs.d.ts +13 -0
- package/convex/searchLogs.d.ts.map +1 -1
- package/convex/searchLogs.js +241 -0
- package/convex/searchLogs.js.map +1 -1
- package/convex/seedAPILayerAPIs.d.ts +7 -0
- package/convex/seedAPILayerAPIs.js +177 -0
- package/convex/seedDirectCallConfigs.d.ts +2 -0
- package/convex/seedDirectCallConfigs.js +324 -0
- package/convex/seedPratham.d.ts +6 -0
- package/convex/seedPratham.d.ts.map +1 -1
- package/convex/seedPratham.js +149 -0
- package/convex/seedPratham.js.map +1 -1
- package/convex/seedPratham.ts +1 -2
- package/convex/spendAlerts.d.ts +36 -0
- package/convex/spendAlerts.js +380 -0
- package/convex/spendAlerts.js.map +1 -1
- package/convex/stripeActions.d.ts +19 -0
- package/convex/stripeActions.d.ts.map +1 -1
- package/convex/stripeActions.js +432 -0
- package/convex/stripeActions.js.map +1 -1
- package/convex/stripeActions.ts +25 -3
- package/convex/teams.d.ts +21 -0
- package/convex/teams.js +215 -0
- package/convex/telemetry.d.ts +4 -0
- package/convex/telemetry.js +74 -0
- package/convex/updateAPIStatus.d.ts +6 -0
- package/convex/updateAPIStatus.d.ts.map +1 -1
- package/convex/updateAPIStatus.js +39 -0
- package/convex/updateAPIStatus.js.map +1 -1
- package/convex/usage.d.ts +27 -0
- package/convex/usage.js +229 -0
- package/convex/waitlist.d.ts +4 -0
- package/convex/waitlist.js +49 -0
- package/convex/webhooks.d.ts +12 -0
- package/convex/webhooks.js +410 -0
- package/convex/workspaceSettings.d.ts +7 -0
- package/convex/workspaceSettings.d.ts.map +1 -0
- package/convex/workspaceSettings.js +128 -0
- package/convex/workspaceSettings.js.map +1 -0
- package/convex/workspaces.d.ts +33 -0
- package/convex/workspaces.d.ts.map +1 -1
- package/convex/workspaces.js +989 -0
- package/convex/workspaces.js.map +1 -1
- package/convex/workspaces.ts +18 -20
- package/dist/bin.js +0 -0
- package/dist/cli/commands/demo.js +1 -1
- package/dist/cli/commands/demo.js.map +1 -1
- package/dist/cli/commands/doctor.js.map +1 -1
- package/dist/cli/commands/login.js.map +1 -1
- package/dist/cli/commands/setup.js.map +1 -1
- package/dist/credentials.d.ts.map +1 -1
- package/dist/credentials.js +15 -0
- package/dist/credentials.js.map +1 -1
- package/dist/discovery.js.map +1 -1
- package/dist/execute.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp-analytics.js +1 -1
- package/dist/mcp-analytics.js.map +1 -1
- package/dist/open-apis.d.ts.map +1 -1
- package/dist/open-apis.js +94 -2
- package/dist/open-apis.js.map +1 -1
- package/dist/ui/errors.js.map +1 -1
- package/dist/ui/prompts.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/commands/demo.ts +1 -1
- package/src/credentials.ts +16 -0
- package/src/index.ts +1 -1
- package/src/mcp-analytics.ts +1 -1
- package/src/open-apis.ts +114 -4
- package/src/types/convex-api.d.ts +20 -0
package/convex/teams.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { mutation, query } from "./_generated/server";
|
|
3
|
+
// ============================================
|
|
4
|
+
// HELPER FUNCTIONS
|
|
5
|
+
// ============================================
|
|
6
|
+
function generateToken() {
|
|
7
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
8
|
+
let result = "";
|
|
9
|
+
for (let i = 0; i < 32; i++) {
|
|
10
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
// ============================================
|
|
15
|
+
// TEAM QUERIES
|
|
16
|
+
// ============================================
|
|
17
|
+
/**
|
|
18
|
+
* Get team members for a workspace
|
|
19
|
+
*/
|
|
20
|
+
export const getMembers = query({
|
|
21
|
+
args: { token: v.string() },
|
|
22
|
+
handler: async (ctx, { token }) => {
|
|
23
|
+
const session = await ctx.db
|
|
24
|
+
.query("agentSessions")
|
|
25
|
+
.withIndex("by_sessionToken", (q) => q.eq("sessionToken", token))
|
|
26
|
+
.first();
|
|
27
|
+
if (!session)
|
|
28
|
+
return [];
|
|
29
|
+
const workspace = await ctx.db.get(session.workspaceId);
|
|
30
|
+
if (!workspace)
|
|
31
|
+
return [];
|
|
32
|
+
const members = await ctx.db
|
|
33
|
+
.query("workspaceMembers")
|
|
34
|
+
.withIndex("by_workspaceId", (q) => q.eq("workspaceId", session.workspaceId))
|
|
35
|
+
.collect();
|
|
36
|
+
// Add owner as first member
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
email: workspace.email,
|
|
40
|
+
role: "owner",
|
|
41
|
+
status: "active",
|
|
42
|
+
isOwner: true,
|
|
43
|
+
createdAt: workspace.createdAt,
|
|
44
|
+
},
|
|
45
|
+
...members.map((m) => ({
|
|
46
|
+
id: m._id,
|
|
47
|
+
email: m.email,
|
|
48
|
+
role: m.role,
|
|
49
|
+
status: m.status,
|
|
50
|
+
isOwner: false,
|
|
51
|
+
invitedBy: m.invitedBy,
|
|
52
|
+
createdAt: m.createdAt,
|
|
53
|
+
acceptedAt: m.acceptedAt,
|
|
54
|
+
})),
|
|
55
|
+
];
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
// ============================================
|
|
59
|
+
// TEAM MUTATIONS
|
|
60
|
+
// ============================================
|
|
61
|
+
/**
|
|
62
|
+
* Invite a member to the workspace (creates pending invite)
|
|
63
|
+
*/
|
|
64
|
+
export const inviteMember = mutation({
|
|
65
|
+
args: {
|
|
66
|
+
token: v.string(),
|
|
67
|
+
email: v.string(),
|
|
68
|
+
role: v.union(v.literal("admin"), v.literal("member")),
|
|
69
|
+
},
|
|
70
|
+
handler: async (ctx, { token, email, role }) => {
|
|
71
|
+
const session = await ctx.db
|
|
72
|
+
.query("agentSessions")
|
|
73
|
+
.withIndex("by_sessionToken", (q) => q.eq("sessionToken", token))
|
|
74
|
+
.first();
|
|
75
|
+
if (!session)
|
|
76
|
+
throw new Error("Invalid session");
|
|
77
|
+
const workspace = await ctx.db.get(session.workspaceId);
|
|
78
|
+
if (!workspace)
|
|
79
|
+
throw new Error("Workspace not found");
|
|
80
|
+
// Normalize email
|
|
81
|
+
const normalizedEmail = email.toLowerCase().trim();
|
|
82
|
+
// Can't invite yourself
|
|
83
|
+
if (normalizedEmail === workspace.email.toLowerCase()) {
|
|
84
|
+
throw new Error("Cannot invite yourself");
|
|
85
|
+
}
|
|
86
|
+
// Check if already member
|
|
87
|
+
const existing = await ctx.db
|
|
88
|
+
.query("workspaceMembers")
|
|
89
|
+
.withIndex("by_workspaceId_email", (q) => q.eq("workspaceId", session.workspaceId).eq("email", normalizedEmail))
|
|
90
|
+
.first();
|
|
91
|
+
if (existing) {
|
|
92
|
+
if (existing.status === "active") {
|
|
93
|
+
throw new Error("Already a team member");
|
|
94
|
+
}
|
|
95
|
+
if (existing.status === "pending") {
|
|
96
|
+
throw new Error("Invite already pending");
|
|
97
|
+
}
|
|
98
|
+
// If revoked, we can re-invite - update existing record
|
|
99
|
+
const inviteToken = generateToken();
|
|
100
|
+
await ctx.db.patch(existing._id, {
|
|
101
|
+
role,
|
|
102
|
+
invitedBy: workspace.email,
|
|
103
|
+
inviteToken,
|
|
104
|
+
status: "pending",
|
|
105
|
+
createdAt: Date.now(),
|
|
106
|
+
acceptedAt: undefined,
|
|
107
|
+
});
|
|
108
|
+
return { id: existing._id, inviteToken };
|
|
109
|
+
}
|
|
110
|
+
// Generate invite token
|
|
111
|
+
const inviteToken = generateToken();
|
|
112
|
+
const id = await ctx.db.insert("workspaceMembers", {
|
|
113
|
+
workspaceId: session.workspaceId,
|
|
114
|
+
email: normalizedEmail,
|
|
115
|
+
role,
|
|
116
|
+
invitedBy: workspace.email,
|
|
117
|
+
inviteToken,
|
|
118
|
+
status: "pending",
|
|
119
|
+
createdAt: Date.now(),
|
|
120
|
+
});
|
|
121
|
+
return { id, inviteToken };
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
/**
|
|
125
|
+
* Accept an invite
|
|
126
|
+
*/
|
|
127
|
+
export const acceptInvite = mutation({
|
|
128
|
+
args: { inviteToken: v.string() },
|
|
129
|
+
handler: async (ctx, { inviteToken }) => {
|
|
130
|
+
const member = await ctx.db
|
|
131
|
+
.query("workspaceMembers")
|
|
132
|
+
.withIndex("by_inviteToken", (q) => q.eq("inviteToken", inviteToken))
|
|
133
|
+
.first();
|
|
134
|
+
if (!member)
|
|
135
|
+
throw new Error("Invalid invite token");
|
|
136
|
+
if (member.status !== "pending")
|
|
137
|
+
throw new Error("Invite already used or revoked");
|
|
138
|
+
await ctx.db.patch(member._id, {
|
|
139
|
+
status: "active",
|
|
140
|
+
acceptedAt: Date.now(),
|
|
141
|
+
inviteToken: undefined, // Clear token after use
|
|
142
|
+
});
|
|
143
|
+
// Get workspace info for response
|
|
144
|
+
const workspace = await ctx.db.get(member.workspaceId);
|
|
145
|
+
return {
|
|
146
|
+
success: true,
|
|
147
|
+
workspaceId: member.workspaceId,
|
|
148
|
+
workspaceEmail: workspace?.email,
|
|
149
|
+
role: member.role,
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
/**
|
|
154
|
+
* Remove a member from the workspace
|
|
155
|
+
*/
|
|
156
|
+
export const removeMember = mutation({
|
|
157
|
+
args: {
|
|
158
|
+
token: v.string(),
|
|
159
|
+
memberEmail: v.string(),
|
|
160
|
+
},
|
|
161
|
+
handler: async (ctx, { token, memberEmail }) => {
|
|
162
|
+
const session = await ctx.db
|
|
163
|
+
.query("agentSessions")
|
|
164
|
+
.withIndex("by_sessionToken", (q) => q.eq("sessionToken", token))
|
|
165
|
+
.first();
|
|
166
|
+
if (!session)
|
|
167
|
+
throw new Error("Invalid session");
|
|
168
|
+
const workspace = await ctx.db.get(session.workspaceId);
|
|
169
|
+
if (!workspace)
|
|
170
|
+
throw new Error("Workspace not found");
|
|
171
|
+
const normalizedEmail = memberEmail.toLowerCase().trim();
|
|
172
|
+
// Cannot remove owner
|
|
173
|
+
if (normalizedEmail === workspace.email.toLowerCase()) {
|
|
174
|
+
throw new Error("Cannot remove workspace owner");
|
|
175
|
+
}
|
|
176
|
+
const member = await ctx.db
|
|
177
|
+
.query("workspaceMembers")
|
|
178
|
+
.withIndex("by_workspaceId_email", (q) => q.eq("workspaceId", session.workspaceId).eq("email", normalizedEmail))
|
|
179
|
+
.first();
|
|
180
|
+
if (!member)
|
|
181
|
+
throw new Error("Member not found");
|
|
182
|
+
// Set status to revoked instead of deleting
|
|
183
|
+
await ctx.db.patch(member._id, {
|
|
184
|
+
status: "revoked",
|
|
185
|
+
inviteToken: undefined,
|
|
186
|
+
});
|
|
187
|
+
return { success: true };
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
/**
|
|
191
|
+
* Get invite details (public, for invite acceptance page)
|
|
192
|
+
*/
|
|
193
|
+
export const getInviteDetails = query({
|
|
194
|
+
args: { inviteToken: v.string() },
|
|
195
|
+
handler: async (ctx, { inviteToken }) => {
|
|
196
|
+
const member = await ctx.db
|
|
197
|
+
.query("workspaceMembers")
|
|
198
|
+
.withIndex("by_inviteToken", (q) => q.eq("inviteToken", inviteToken))
|
|
199
|
+
.first();
|
|
200
|
+
if (!member)
|
|
201
|
+
return null;
|
|
202
|
+
if (member.status !== "pending")
|
|
203
|
+
return null;
|
|
204
|
+
const workspace = await ctx.db.get(member.workspaceId);
|
|
205
|
+
if (!workspace)
|
|
206
|
+
return null;
|
|
207
|
+
return {
|
|
208
|
+
email: member.email,
|
|
209
|
+
role: member.role,
|
|
210
|
+
invitedBy: member.invitedBy,
|
|
211
|
+
workspaceEmail: workspace.email,
|
|
212
|
+
};
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
//# sourceMappingURL=teams.js.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { mutation, query } from "./_generated/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
export const track = mutation({
|
|
4
|
+
args: {
|
|
5
|
+
event: v.object({
|
|
6
|
+
type: v.string(),
|
|
7
|
+
query: v.optional(v.string()),
|
|
8
|
+
apiId: v.optional(v.string()),
|
|
9
|
+
resultCount: v.optional(v.number()),
|
|
10
|
+
responseTimeMs: v.optional(v.number()),
|
|
11
|
+
version: v.optional(v.string()),
|
|
12
|
+
platform: v.optional(v.string()),
|
|
13
|
+
nodeVersion: v.optional(v.string()),
|
|
14
|
+
timestamp: v.optional(v.number()),
|
|
15
|
+
}),
|
|
16
|
+
},
|
|
17
|
+
handler: async (ctx, { event }) => {
|
|
18
|
+
await ctx.db.insert("telemetry", {
|
|
19
|
+
type: event.type,
|
|
20
|
+
query: event.query,
|
|
21
|
+
apiId: event.apiId,
|
|
22
|
+
resultCount: event.resultCount,
|
|
23
|
+
responseTimeMs: event.responseTimeMs,
|
|
24
|
+
version: event.version || "unknown",
|
|
25
|
+
platform: event.platform || "unknown",
|
|
26
|
+
nodeVersion: event.nodeVersion || "unknown",
|
|
27
|
+
timestamp: event.timestamp || Date.now(),
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
export const getStats = query({
|
|
32
|
+
args: {},
|
|
33
|
+
handler: async (ctx) => {
|
|
34
|
+
const events = await ctx.db.query("telemetry").collect();
|
|
35
|
+
const startups = events.filter(e => e.type === "startup").length;
|
|
36
|
+
const searches = events.filter(e => e.type === "search").length;
|
|
37
|
+
const executes = events.filter(e => e.type === "execute").length;
|
|
38
|
+
const uniqueUsers = new Set(events.map(e => `${e.platform}-${e.nodeVersion}`)).size;
|
|
39
|
+
const topQueries = events
|
|
40
|
+
.filter(e => e.type === "search" && e.query)
|
|
41
|
+
.reduce((acc, e) => {
|
|
42
|
+
acc[e.query] = (acc[e.query] || 0) + 1;
|
|
43
|
+
return acc;
|
|
44
|
+
}, {});
|
|
45
|
+
const topAPIs = events
|
|
46
|
+
.filter(e => e.type === "execute" && e.apiId)
|
|
47
|
+
.reduce((acc, e) => {
|
|
48
|
+
acc[e.apiId] = (acc[e.apiId] || 0) + 1;
|
|
49
|
+
return acc;
|
|
50
|
+
}, {});
|
|
51
|
+
return {
|
|
52
|
+
totalStartups: startups,
|
|
53
|
+
totalSearches: searches,
|
|
54
|
+
totalExecutes: executes,
|
|
55
|
+
estimatedUniqueUsers: uniqueUsers,
|
|
56
|
+
topQueries: Object.entries(topQueries)
|
|
57
|
+
.sort(([, a], [, b]) => b - a)
|
|
58
|
+
.slice(0, 10),
|
|
59
|
+
topAPIs: Object.entries(topAPIs)
|
|
60
|
+
.sort(([, a], [, b]) => b - a)
|
|
61
|
+
.slice(0, 10),
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
export const getRecent = query({
|
|
66
|
+
args: { limit: v.optional(v.number()) },
|
|
67
|
+
handler: async (ctx, { limit = 50 }) => {
|
|
68
|
+
return await ctx.db
|
|
69
|
+
.query("telemetry")
|
|
70
|
+
.order("desc")
|
|
71
|
+
.take(limit);
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=telemetry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateAPIStatus.d.ts","sourceRoot":"","sources":["updateAPIStatus.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"updateAPIStatus.d.ts","sourceRoot":"","sources":["updateAPIStatus.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,MAAM,KAqCjB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { mutation } from "./_generated/server";
|
|
2
|
+
/**
|
|
3
|
+
* Update providerAPIs status to reflect actual Direct Call status
|
|
4
|
+
* Run: npx convex run updateAPIStatus:update
|
|
5
|
+
*/
|
|
6
|
+
export const update = mutation({
|
|
7
|
+
args: {},
|
|
8
|
+
handler: async (ctx) => {
|
|
9
|
+
const providerId = "k97cvcvadnyz8x8m4we7xqmh1s83p0ph"; // APILayer
|
|
10
|
+
const apis = await ctx.db
|
|
11
|
+
.query("providerAPIs")
|
|
12
|
+
.withIndex("by_providerId", (q) => q.eq("providerId", providerId))
|
|
13
|
+
.collect();
|
|
14
|
+
// APIs that are blocked by subscription tier
|
|
15
|
+
const blocked = ["Number Verification API", "World News API", "Image Crop API", "Form API"];
|
|
16
|
+
// PDF Layer is rate limited
|
|
17
|
+
const rateLimited = ["PDF Layer"];
|
|
18
|
+
let updated = 0;
|
|
19
|
+
for (const api of apis) {
|
|
20
|
+
let newStatus = "approved"; // default = live
|
|
21
|
+
let hasDirectCall = true;
|
|
22
|
+
if (blocked.includes(api.name)) {
|
|
23
|
+
newStatus = "blocked";
|
|
24
|
+
hasDirectCall = false;
|
|
25
|
+
}
|
|
26
|
+
else if (rateLimited.includes(api.name)) {
|
|
27
|
+
newStatus = "rate_limited";
|
|
28
|
+
}
|
|
29
|
+
if (api.status !== newStatus || api.hasDirectCall !== hasDirectCall) {
|
|
30
|
+
await ctx.db.patch(api._id, {
|
|
31
|
+
status: newStatus,
|
|
32
|
+
});
|
|
33
|
+
updated++;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return { success: true, updated, total: apis.length };
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=updateAPIStatus.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateAPIStatus.js","sourceRoot":"","sources":["updateAPIStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC;IAC7B,IAAI,EAAE,EAAE;IACR,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QACrB,MAAM,UAAU,GAAG,kCAAyC,CAAC,CAAC,WAAW;QAEzE,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,EAAE;aACtB,KAAK,CAAC,cAAc,CAAC;aACrB,SAAS,CAAC,eAAe,EAAE,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;aACtE,OAAO,EAAE,CAAC;QAEb,6CAA6C;QAC7C,MAAM,OAAO,GAAG,CAAC,yBAAyB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,UAAU,CAAC,CAAC;QAC5F,4BAA4B;QAC5B,MAAM,WAAW,GAAG,CAAC,WAAW,CAAC,CAAC;QAElC,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,IAAI,SAAS,GAAG,UAAU,CAAC,CAAC,iBAAiB;YAC7C,IAAI,aAAa,GAAG,IAAI,CAAC;YAEzB,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC/B,SAAS,GAAG,SAAS,CAAC;gBACtB,aAAa,GAAG,KAAK,CAAC;YACxB,CAAC;iBAAM,IAAI,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC1C,SAAS,GAAG,cAAc,CAAC;YAC7B,CAAC;YAED,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"updateAPIStatus.js","sourceRoot":"","sources":["updateAPIStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC;IAC7B,IAAI,EAAE,EAAE;IACR,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QACrB,MAAM,UAAU,GAAG,kCAAyC,CAAC,CAAC,WAAW;QAEzE,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,EAAE;aACtB,KAAK,CAAC,cAAc,CAAC;aACrB,SAAS,CAAC,eAAe,EAAE,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;aACtE,OAAO,EAAE,CAAC;QAEb,6CAA6C;QAC7C,MAAM,OAAO,GAAG,CAAC,yBAAyB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,UAAU,CAAC,CAAC;QAC5F,4BAA4B;QAC5B,MAAM,WAAW,GAAG,CAAC,WAAW,CAAC,CAAC;QAElC,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,IAAI,SAAS,GAAG,UAAU,CAAC,CAAC,iBAAiB;YAC7C,IAAI,aAAa,GAAG,IAAI,CAAC;YAEzB,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC/B,SAAS,GAAG,SAAS,CAAC;gBACtB,aAAa,GAAG,KAAK,CAAC;YACxB,CAAC;iBAAM,IAAI,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC1C,SAAS,GAAG,cAAc,CAAC;YAC7B,CAAC;YAED,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,IAAK,GAAW,CAAC,aAAa,KAAK,aAAa,EAAE,CAAC;gBAC7E,MAAM,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;oBAC1B,MAAM,EAAE,SAAS;iBACX,CAAC,CAAC;gBACV,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;IACxD,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log an API call usage
|
|
3
|
+
*/
|
|
4
|
+
export declare const logUsage: any;
|
|
5
|
+
/**
|
|
6
|
+
* Get user usage stats for rate limiting
|
|
7
|
+
* Returns counts for last minute and last day
|
|
8
|
+
*/
|
|
9
|
+
export declare const getUserUsage: any;
|
|
10
|
+
/**
|
|
11
|
+
* Get provider usage stats for analytics
|
|
12
|
+
*/
|
|
13
|
+
export declare const getProviderUsage: any;
|
|
14
|
+
/**
|
|
15
|
+
* Get Direct Call specific usage stats
|
|
16
|
+
*/
|
|
17
|
+
export declare const getDirectCallUsage: any;
|
|
18
|
+
/**
|
|
19
|
+
* Get recent usage logs (for dashboard/debugging)
|
|
20
|
+
*/
|
|
21
|
+
export declare const getRecentLogs: any;
|
|
22
|
+
/**
|
|
23
|
+
* Check if user is within rate limits
|
|
24
|
+
* Returns { allowed: boolean, reason?: string }
|
|
25
|
+
*/
|
|
26
|
+
export declare const checkRateLimit: any;
|
|
27
|
+
//# sourceMappingURL=usage.d.ts.map
|
package/convex/usage.js
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { mutation, query } from "./_generated/server";
|
|
3
|
+
// ============================================
|
|
4
|
+
// MUTATIONS
|
|
5
|
+
// ============================================
|
|
6
|
+
/**
|
|
7
|
+
* Log an API call usage
|
|
8
|
+
*/
|
|
9
|
+
export const logUsage = mutation({
|
|
10
|
+
args: {
|
|
11
|
+
userId: v.string(),
|
|
12
|
+
providerId: v.id("providers"),
|
|
13
|
+
directCallId: v.id("providerDirectCall"),
|
|
14
|
+
actionName: v.string(),
|
|
15
|
+
success: v.boolean(),
|
|
16
|
+
latencyMs: v.number(),
|
|
17
|
+
creditsUsed: v.number(),
|
|
18
|
+
errorMessage: v.optional(v.string()),
|
|
19
|
+
},
|
|
20
|
+
handler: async (ctx, args) => {
|
|
21
|
+
return await ctx.db.insert("usageLog", {
|
|
22
|
+
userId: args.userId,
|
|
23
|
+
providerId: args.providerId,
|
|
24
|
+
directCallId: args.directCallId,
|
|
25
|
+
actionName: args.actionName,
|
|
26
|
+
timestamp: Date.now(),
|
|
27
|
+
success: args.success,
|
|
28
|
+
latencyMs: args.latencyMs,
|
|
29
|
+
creditsUsed: args.creditsUsed,
|
|
30
|
+
errorMessage: args.errorMessage,
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
// ============================================
|
|
35
|
+
// QUERIES
|
|
36
|
+
// ============================================
|
|
37
|
+
/**
|
|
38
|
+
* Get user usage stats for rate limiting
|
|
39
|
+
* Returns counts for last minute and last day
|
|
40
|
+
*/
|
|
41
|
+
export const getUserUsage = query({
|
|
42
|
+
args: {
|
|
43
|
+
userId: v.string(),
|
|
44
|
+
providerId: v.id("providers"),
|
|
45
|
+
},
|
|
46
|
+
handler: async (ctx, args) => {
|
|
47
|
+
const now = Date.now();
|
|
48
|
+
const oneMinuteAgo = now - 60 * 1000;
|
|
49
|
+
const oneDayAgo = now - 24 * 60 * 60 * 1000;
|
|
50
|
+
// Get all usage for this user + provider in the last 24h
|
|
51
|
+
const recentUsage = await ctx.db
|
|
52
|
+
.query("usageLog")
|
|
53
|
+
.withIndex("by_userId_providerId", (q) => q.eq("userId", args.userId).eq("providerId", args.providerId))
|
|
54
|
+
.filter((q) => q.gte(q.field("timestamp"), oneDayAgo))
|
|
55
|
+
.collect();
|
|
56
|
+
// Calculate counts
|
|
57
|
+
const minuteCount = recentUsage.filter((u) => u.timestamp >= oneMinuteAgo).length;
|
|
58
|
+
const dayCount = recentUsage.length;
|
|
59
|
+
const totalCredits = recentUsage.reduce((sum, u) => sum + u.creditsUsed, 0);
|
|
60
|
+
return {
|
|
61
|
+
minute: minuteCount,
|
|
62
|
+
day: dayCount,
|
|
63
|
+
totalCreditsUsed: totalCredits,
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* Get provider usage stats for analytics
|
|
69
|
+
*/
|
|
70
|
+
export const getProviderUsage = query({
|
|
71
|
+
args: {
|
|
72
|
+
providerId: v.id("providers"),
|
|
73
|
+
periodDays: v.optional(v.number()), // default 30
|
|
74
|
+
},
|
|
75
|
+
handler: async (ctx, args) => {
|
|
76
|
+
const periodDays = args.periodDays ?? 30;
|
|
77
|
+
const now = Date.now();
|
|
78
|
+
const periodStart = now - periodDays * 24 * 60 * 60 * 1000;
|
|
79
|
+
const usage = await ctx.db
|
|
80
|
+
.query("usageLog")
|
|
81
|
+
.withIndex("by_providerId", (q) => q.eq("providerId", args.providerId))
|
|
82
|
+
.filter((q) => q.gte(q.field("timestamp"), periodStart))
|
|
83
|
+
.collect();
|
|
84
|
+
// Aggregate stats
|
|
85
|
+
const totalCalls = usage.length;
|
|
86
|
+
const successfulCalls = usage.filter((u) => u.success).length;
|
|
87
|
+
const failedCalls = totalCalls - successfulCalls;
|
|
88
|
+
const totalCredits = usage.reduce((sum, u) => sum + u.creditsUsed, 0);
|
|
89
|
+
const totalLatency = usage.reduce((sum, u) => sum + u.latencyMs, 0);
|
|
90
|
+
const avgLatency = totalCalls > 0 ? Math.round(totalLatency / totalCalls) : 0;
|
|
91
|
+
// Group by action
|
|
92
|
+
const byAction = {};
|
|
93
|
+
for (const u of usage) {
|
|
94
|
+
if (!byAction[u.actionName]) {
|
|
95
|
+
byAction[u.actionName] = { calls: 0, credits: 0 };
|
|
96
|
+
}
|
|
97
|
+
byAction[u.actionName].calls++;
|
|
98
|
+
byAction[u.actionName].credits += u.creditsUsed;
|
|
99
|
+
}
|
|
100
|
+
// Group by day for chart
|
|
101
|
+
const byDay = {};
|
|
102
|
+
for (const u of usage) {
|
|
103
|
+
const day = new Date(u.timestamp).toISOString().split("T")[0];
|
|
104
|
+
if (!byDay[day]) {
|
|
105
|
+
byDay[day] = { calls: 0, credits: 0 };
|
|
106
|
+
}
|
|
107
|
+
byDay[day].calls++;
|
|
108
|
+
byDay[day].credits += u.creditsUsed;
|
|
109
|
+
}
|
|
110
|
+
// Unique users
|
|
111
|
+
const uniqueUsers = new Set(usage.map((u) => u.userId)).size;
|
|
112
|
+
return {
|
|
113
|
+
periodDays,
|
|
114
|
+
totalCalls,
|
|
115
|
+
successfulCalls,
|
|
116
|
+
failedCalls,
|
|
117
|
+
successRate: totalCalls > 0 ? (successfulCalls / totalCalls) * 100 : 0,
|
|
118
|
+
totalCredits,
|
|
119
|
+
avgLatencyMs: avgLatency,
|
|
120
|
+
uniqueUsers,
|
|
121
|
+
byAction,
|
|
122
|
+
byDay,
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
/**
|
|
127
|
+
* Get Direct Call specific usage stats
|
|
128
|
+
*/
|
|
129
|
+
export const getDirectCallUsage = query({
|
|
130
|
+
args: {
|
|
131
|
+
directCallId: v.id("providerDirectCall"),
|
|
132
|
+
periodDays: v.optional(v.number()),
|
|
133
|
+
},
|
|
134
|
+
handler: async (ctx, args) => {
|
|
135
|
+
const periodDays = args.periodDays ?? 30;
|
|
136
|
+
const now = Date.now();
|
|
137
|
+
const periodStart = now - periodDays * 24 * 60 * 60 * 1000;
|
|
138
|
+
const usage = await ctx.db
|
|
139
|
+
.query("usageLog")
|
|
140
|
+
.withIndex("by_directCallId", (q) => q.eq("directCallId", args.directCallId))
|
|
141
|
+
.filter((q) => q.gte(q.field("timestamp"), periodStart))
|
|
142
|
+
.collect();
|
|
143
|
+
const totalCalls = usage.length;
|
|
144
|
+
const successfulCalls = usage.filter((u) => u.success).length;
|
|
145
|
+
const totalCredits = usage.reduce((sum, u) => sum + u.creditsUsed, 0);
|
|
146
|
+
const totalLatency = usage.reduce((sum, u) => sum + u.latencyMs, 0);
|
|
147
|
+
return {
|
|
148
|
+
periodDays,
|
|
149
|
+
totalCalls,
|
|
150
|
+
successfulCalls,
|
|
151
|
+
failedCalls: totalCalls - successfulCalls,
|
|
152
|
+
successRate: totalCalls > 0 ? (successfulCalls / totalCalls) * 100 : 0,
|
|
153
|
+
totalCredits,
|
|
154
|
+
avgLatencyMs: totalCalls > 0 ? Math.round(totalLatency / totalCalls) : 0,
|
|
155
|
+
uniqueUsers: new Set(usage.map((u) => u.userId)).size,
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
/**
|
|
160
|
+
* Get recent usage logs (for dashboard/debugging)
|
|
161
|
+
*/
|
|
162
|
+
export const getRecentLogs = query({
|
|
163
|
+
args: {
|
|
164
|
+
providerId: v.optional(v.id("providers")),
|
|
165
|
+
directCallId: v.optional(v.id("providerDirectCall")),
|
|
166
|
+
limit: v.optional(v.number()),
|
|
167
|
+
},
|
|
168
|
+
handler: async (ctx, args) => {
|
|
169
|
+
const limit = args.limit ?? 50;
|
|
170
|
+
const { directCallId, providerId } = args;
|
|
171
|
+
if (directCallId !== undefined) {
|
|
172
|
+
return await ctx.db
|
|
173
|
+
.query("usageLog")
|
|
174
|
+
.withIndex("by_directCallId", (q) => q.eq("directCallId", directCallId))
|
|
175
|
+
.order("desc")
|
|
176
|
+
.take(limit);
|
|
177
|
+
}
|
|
178
|
+
if (providerId !== undefined) {
|
|
179
|
+
return await ctx.db
|
|
180
|
+
.query("usageLog")
|
|
181
|
+
.withIndex("by_providerId", (q) => q.eq("providerId", providerId))
|
|
182
|
+
.order("desc")
|
|
183
|
+
.take(limit);
|
|
184
|
+
}
|
|
185
|
+
return await ctx.db
|
|
186
|
+
.query("usageLog")
|
|
187
|
+
.withIndex("by_timestamp")
|
|
188
|
+
.order("desc")
|
|
189
|
+
.take(limit);
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
/**
|
|
193
|
+
* Check if user is within rate limits
|
|
194
|
+
* Returns { allowed: boolean, reason?: string }
|
|
195
|
+
*/
|
|
196
|
+
export const checkRateLimit = query({
|
|
197
|
+
args: {
|
|
198
|
+
userId: v.string(),
|
|
199
|
+
providerId: v.id("providers"),
|
|
200
|
+
rateLimitPerUser: v.number(),
|
|
201
|
+
rateLimitPerDay: v.number(),
|
|
202
|
+
},
|
|
203
|
+
handler: async (ctx, args) => {
|
|
204
|
+
const now = Date.now();
|
|
205
|
+
const oneMinuteAgo = now - 60 * 1000;
|
|
206
|
+
const oneDayAgo = now - 24 * 60 * 60 * 1000;
|
|
207
|
+
const recentUsage = await ctx.db
|
|
208
|
+
.query("usageLog")
|
|
209
|
+
.withIndex("by_userId_providerId", (q) => q.eq("userId", args.userId).eq("providerId", args.providerId))
|
|
210
|
+
.filter((q) => q.gte(q.field("timestamp"), oneDayAgo))
|
|
211
|
+
.collect();
|
|
212
|
+
const minuteCount = recentUsage.filter((u) => u.timestamp >= oneMinuteAgo).length;
|
|
213
|
+
const dayCount = recentUsage.length;
|
|
214
|
+
if (minuteCount >= args.rateLimitPerUser) {
|
|
215
|
+
return {
|
|
216
|
+
allowed: false,
|
|
217
|
+
reason: `Rate limit exceeded: ${minuteCount}/${args.rateLimitPerUser} requests per minute`,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
if (dayCount >= args.rateLimitPerDay) {
|
|
221
|
+
return {
|
|
222
|
+
allowed: false,
|
|
223
|
+
reason: `Daily limit exceeded: ${dayCount}/${args.rateLimitPerDay} requests per day`,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
return { allowed: true };
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
//# sourceMappingURL=usage.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { mutation, query } from "./_generated/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
export const join = mutation({
|
|
4
|
+
args: {
|
|
5
|
+
email: v.string(),
|
|
6
|
+
type: v.optional(v.string()),
|
|
7
|
+
source: v.optional(v.string()),
|
|
8
|
+
},
|
|
9
|
+
handler: async (ctx, args) => {
|
|
10
|
+
const email = args.email.toLowerCase().trim();
|
|
11
|
+
// Check if already on waitlist
|
|
12
|
+
const existing = await ctx.db
|
|
13
|
+
.query("waitlist")
|
|
14
|
+
.withIndex("by_email", (q) => q.eq("email", email))
|
|
15
|
+
.first();
|
|
16
|
+
if (existing) {
|
|
17
|
+
return { success: true, alreadyExists: true };
|
|
18
|
+
}
|
|
19
|
+
await ctx.db.insert("waitlist", {
|
|
20
|
+
email,
|
|
21
|
+
type: args.type || "provider",
|
|
22
|
+
source: args.source || "landing",
|
|
23
|
+
createdAt: Date.now(),
|
|
24
|
+
});
|
|
25
|
+
return { success: true, alreadyExists: false };
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
export const count = query({
|
|
29
|
+
args: {},
|
|
30
|
+
handler: async (ctx) => {
|
|
31
|
+
const all = await ctx.db.query("waitlist").collect();
|
|
32
|
+
return all.length;
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
export const list = query({
|
|
36
|
+
args: {
|
|
37
|
+
type: v.optional(v.string()),
|
|
38
|
+
},
|
|
39
|
+
handler: async (ctx, args) => {
|
|
40
|
+
if (args.type) {
|
|
41
|
+
return await ctx.db
|
|
42
|
+
.query("waitlist")
|
|
43
|
+
.withIndex("by_type", (q) => q.eq("type", args.type))
|
|
44
|
+
.collect();
|
|
45
|
+
}
|
|
46
|
+
return await ctx.db.query("waitlist").collect();
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=waitlist.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const WEBHOOK_EVENTS: readonly ["usage.threshold.80", "usage.threshold.100", "api.error", "agent.connected", "agent.revoked"];
|
|
2
|
+
export declare const getWebhooks: any;
|
|
3
|
+
export declare const createWebhook: any;
|
|
4
|
+
export declare const updateWebhook: any;
|
|
5
|
+
export declare const deleteWebhook: any;
|
|
6
|
+
export declare const regenerateSecret: any;
|
|
7
|
+
export declare const testWebhook: any;
|
|
8
|
+
export declare const triggerWebhooks: any;
|
|
9
|
+
export declare const getWebhookInternal: any;
|
|
10
|
+
export declare const getWebhooksForEvent: any;
|
|
11
|
+
export declare const updateWebhookStatus: any;
|
|
12
|
+
//# sourceMappingURL=webhooks.d.ts.map
|