@nordsym/apiclaw 1.8.5 → 1.8.7
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 +4 -4
- package/apiclaw-README.md +12 -12
- package/convex/_generated/api.d.ts +16 -0
- package/convex/analytics.d.ts.map +1 -1
- package/convex/analytics.js.map +1 -1
- package/convex/analytics.ts +1 -0
- package/convex/apiKeys.ts +220 -0
- package/convex/backfillAnalytics.d.ts.map +1 -0
- package/convex/backfillAnalytics.js.map +1 -0
- package/convex/backfillAnalytics.ts +22 -0
- package/convex/backfillSearchLogs.d.ts.map +1 -0
- package/convex/backfillSearchLogs.js.map +1 -0
- package/convex/backfillSearchLogs.ts +35 -0
- package/convex/debugFilestackLogs.d.ts.map +1 -0
- package/convex/debugFilestackLogs.js.map +1 -0
- package/convex/debugFilestackLogs.ts +16 -0
- package/convex/debugGetToken.d.ts.map +1 -0
- package/convex/debugGetToken.js.map +1 -0
- package/convex/debugGetToken.ts +18 -0
- package/convex/directCall.ts +49 -14
- package/convex/email.ts +5 -5
- package/convex/http.d.ts.map +1 -1
- package/convex/http.js.map +1 -1
- package/convex/http.ts +611 -49
- package/convex/logs.ts +26 -22
- package/convex/migrateFilestack.d.ts.map +1 -1
- package/convex/migrateFilestack.js.map +1 -1
- package/convex/migrateFilestack.ts +65 -101
- package/convex/migratePartnersProd.d.ts.map +1 -0
- package/convex/migratePartnersProd.js.map +1 -0
- package/convex/migratePartnersProd.ts +174 -0
- package/convex/migrateProviderWorkspaces.d.ts.map +1 -0
- package/convex/migrateProviderWorkspaces.js.map +1 -0
- package/convex/migrateProviderWorkspaces.ts +175 -0
- package/convex/providers.js.map +1 -1
- package/convex/providers.ts +313 -203
- package/convex/schema.ts +50 -1
- package/convex/searchLogs.d.ts.map +1 -1
- package/convex/searchLogs.js.map +1 -1
- package/convex/searchLogs.ts +11 -3
- package/convex/seedPratham.ts +1 -1
- package/convex/spendAlerts.ts +2 -2
- package/convex/stripeActions.ts +1 -1
- package/convex/updateAPIStatus.ts +2 -3
- package/convex/workspaceSettings.ts +136 -0
- package/dist/bin-http.js +0 -0
- package/dist/bin.js +0 -0
- package/dist/cli/commands/demo.js +2 -2
- package/dist/cli/commands/doctor.js +1 -1
- package/dist/cli/commands/login.js +1 -1
- package/dist/cli/commands/setup.js +2 -2
- package/dist/discovery.js +1 -1
- package/dist/execute.js +3 -3
- package/dist/index.js +13 -13
- package/dist/registry/apis.json +1 -1
- package/dist/ui/errors.js +16 -16
- package/dist/ui/prompts.js +1 -1
- package/email-templates/filestack-provider-outreach.html +1 -1
- package/email-templates/partnership-template.html +1 -1
- package/email-templates/pratham-partnership-draft.html +2 -2
- package/package.json +2 -2
- package/reports/APIClaw-Session-Report-2026-04-05.pdf +0 -0
- package/reports/session-report-2026-04-05.html +433 -0
- package/src/cli/commands/demo.ts +2 -2
- package/src/cli/commands/doctor.ts +1 -1
- package/src/cli/commands/login.ts +1 -1
- package/src/cli/commands/setup.ts +2 -2
- package/src/discovery.ts +1 -1
- package/src/execute.ts +3 -3
- package/src/index.ts +14 -14
- package/src/registry/apis.json +1 -1
- package/src/ui/errors.ts +16 -16
- package/src/ui/prompts.ts +1 -1
- package/convex/adminActivate.d.ts +0 -3
- package/convex/adminActivate.js +0 -47
- package/convex/adminStats.d.ts +0 -9
- package/convex/adminStats.js +0 -280
- package/convex/agents.d.ts +0 -84
- package/convex/agents.js +0 -809
- package/convex/analytics.d.ts +0 -5
- package/convex/analytics.js +0 -166
- package/convex/billing.d.ts +0 -88
- package/convex/billing.js +0 -655
- package/convex/capabilities.d.ts +0 -9
- package/convex/capabilities.js +0 -145
- package/convex/chains.d.ts +0 -68
- package/convex/chains.js +0 -1105
- package/convex/credits.d.ts +0 -25
- package/convex/credits.js +0 -186
- package/convex/crons.d.ts +0 -3
- package/convex/crons.js +0 -17
- package/convex/directCall.d.ts +0 -72
- package/convex/directCall.js +0 -627
- package/convex/earnProgress.d.ts +0 -58
- package/convex/earnProgress.js +0 -649
- package/convex/email.d.ts +0 -14
- package/convex/email.js +0 -300
- package/convex/feedback.d.ts +0 -7
- package/convex/feedback.js +0 -227
- package/convex/http.d.ts +0 -3
- package/convex/http.js +0 -1405
- package/convex/inbound.d.ts +0 -2
- package/convex/inbound.js +0 -32
- package/convex/logs.d.ts +0 -48
- package/convex/logs.js +0 -621
- package/convex/migrateFilestack.d.ts +0 -2
- package/convex/migrateFilestack.js +0 -113
- package/convex/migratePratham.d.ts +0 -2
- package/convex/migratePratham.js +0 -121
- package/convex/mou.d.ts +0 -6
- package/convex/mou.js +0 -82
- package/convex/providerKeys.d.ts +0 -31
- package/convex/providerKeys.js +0 -257
- package/convex/providers.d.ts +0 -35
- package/convex/providers.js +0 -922
- package/convex/purchases.d.ts +0 -7
- package/convex/purchases.js +0 -157
- package/convex/ratelimit.d.ts +0 -4
- package/convex/ratelimit.js +0 -91
- package/convex/searchLogs.d.ts +0 -13
- package/convex/searchLogs.js +0 -232
- package/convex/seedAPILayerAPIs.d.ts +0 -7
- package/convex/seedAPILayerAPIs.js +0 -177
- package/convex/seedDirectCallConfigs.d.ts +0 -2
- package/convex/seedDirectCallConfigs.js +0 -324
- package/convex/seedPratham.d.ts +0 -6
- package/convex/seedPratham.js +0 -150
- package/convex/spendAlerts.d.ts +0 -36
- package/convex/spendAlerts.js +0 -380
- package/convex/stripeActions.d.ts +0 -19
- package/convex/stripeActions.js +0 -411
- package/convex/teams.d.ts +0 -21
- package/convex/teams.js +0 -215
- package/convex/telemetry.d.ts +0 -4
- package/convex/telemetry.js +0 -74
- package/convex/updateAPIStatus.d.ts +0 -6
- package/convex/updateAPIStatus.js +0 -40
- package/convex/usage.d.ts +0 -27
- package/convex/usage.js +0 -229
- package/convex/waitlist.d.ts +0 -4
- package/convex/waitlist.js +0 -49
- package/convex/webhooks.d.ts +0 -12
- package/convex/webhooks.js +0 -410
- package/convex/workspaces.d.ts +0 -33
- package/convex/workspaces.js +0 -991
package/convex/directCall.js
DELETED
|
@@ -1,627 +0,0 @@
|
|
|
1
|
-
import { v } from "convex/values";
|
|
2
|
-
import { mutation, query } from "./_generated/server";
|
|
3
|
-
// ============================================
|
|
4
|
-
// MUTATIONS
|
|
5
|
-
// ============================================
|
|
6
|
-
/**
|
|
7
|
-
* Save/update provider's Direct Call configuration
|
|
8
|
-
*/
|
|
9
|
-
export const saveDirectCallConfig = mutation({
|
|
10
|
-
args: {
|
|
11
|
-
id: v.optional(v.id("providerDirectCall")),
|
|
12
|
-
providerId: v.id("providers"),
|
|
13
|
-
apiId: v.optional(v.id("providerAPIs")),
|
|
14
|
-
baseUrl: v.string(),
|
|
15
|
-
authType: v.string(),
|
|
16
|
-
authHeader: v.string(),
|
|
17
|
-
authPrefix: v.string(),
|
|
18
|
-
encryptedMasterKey: v.string(),
|
|
19
|
-
rateLimitPerUser: v.number(),
|
|
20
|
-
rateLimitPerDay: v.number(),
|
|
21
|
-
pricePerRequest: v.number(),
|
|
22
|
-
},
|
|
23
|
-
handler: async (ctx, args) => {
|
|
24
|
-
const now = Date.now();
|
|
25
|
-
if (args.id) {
|
|
26
|
-
// Update existing
|
|
27
|
-
await ctx.db.patch(args.id, {
|
|
28
|
-
baseUrl: args.baseUrl,
|
|
29
|
-
authType: args.authType,
|
|
30
|
-
authHeader: args.authHeader,
|
|
31
|
-
authPrefix: args.authPrefix,
|
|
32
|
-
encryptedMasterKey: args.encryptedMasterKey,
|
|
33
|
-
rateLimitPerUser: args.rateLimitPerUser,
|
|
34
|
-
rateLimitPerDay: args.rateLimitPerDay,
|
|
35
|
-
pricePerRequest: args.pricePerRequest,
|
|
36
|
-
updatedAt: now,
|
|
37
|
-
});
|
|
38
|
-
return args.id;
|
|
39
|
-
}
|
|
40
|
-
// Create new
|
|
41
|
-
return await ctx.db.insert("providerDirectCall", {
|
|
42
|
-
providerId: args.providerId,
|
|
43
|
-
apiId: args.apiId,
|
|
44
|
-
baseUrl: args.baseUrl,
|
|
45
|
-
authType: args.authType,
|
|
46
|
-
authHeader: args.authHeader,
|
|
47
|
-
authPrefix: args.authPrefix,
|
|
48
|
-
encryptedMasterKey: args.encryptedMasterKey,
|
|
49
|
-
rateLimitPerUser: args.rateLimitPerUser,
|
|
50
|
-
rateLimitPerDay: args.rateLimitPerDay,
|
|
51
|
-
pricePerRequest: args.pricePerRequest,
|
|
52
|
-
status: "draft",
|
|
53
|
-
createdAt: now,
|
|
54
|
-
updatedAt: now,
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
/**
|
|
59
|
-
* Save Direct Call config with token auth (used by frontend)
|
|
60
|
-
*/
|
|
61
|
-
export const saveConfig = mutation({
|
|
62
|
-
args: {
|
|
63
|
-
token: v.string(),
|
|
64
|
-
config: v.object({
|
|
65
|
-
apiId: v.string(),
|
|
66
|
-
baseUrl: v.string(),
|
|
67
|
-
authType: v.string(),
|
|
68
|
-
authHeader: v.string(),
|
|
69
|
-
authPrefix: v.string(),
|
|
70
|
-
masterApiKey: v.optional(v.string()),
|
|
71
|
-
rateLimitPerUser: v.number(),
|
|
72
|
-
rateLimitPerDay: v.number(),
|
|
73
|
-
pricePerRequest: v.number(),
|
|
74
|
-
status: v.string(),
|
|
75
|
-
allowCustomerKeys: v.optional(v.boolean()),
|
|
76
|
-
requireCustomerKeys: v.optional(v.boolean()),
|
|
77
|
-
}),
|
|
78
|
-
},
|
|
79
|
-
handler: async (ctx, args) => {
|
|
80
|
-
// Verify session
|
|
81
|
-
const session = await ctx.db
|
|
82
|
-
.query("sessions")
|
|
83
|
-
.withIndex("by_token", (q) => q.eq("token", args.token))
|
|
84
|
-
.first();
|
|
85
|
-
if (!session || session.expiresAt < Date.now()) {
|
|
86
|
-
throw new Error("Invalid or expired session");
|
|
87
|
-
}
|
|
88
|
-
const now = Date.now();
|
|
89
|
-
const { config } = args;
|
|
90
|
-
// Check if config already exists for this API
|
|
91
|
-
const existing = await ctx.db
|
|
92
|
-
.query("providerDirectCall")
|
|
93
|
-
.filter((q) => q.eq(q.field("apiId"), config.apiId))
|
|
94
|
-
.first();
|
|
95
|
-
if (existing) {
|
|
96
|
-
// Update existing
|
|
97
|
-
const updateData = {
|
|
98
|
-
baseUrl: config.baseUrl,
|
|
99
|
-
authType: config.authType,
|
|
100
|
-
authHeader: config.authHeader,
|
|
101
|
-
authPrefix: config.authPrefix,
|
|
102
|
-
rateLimitPerUser: config.rateLimitPerUser,
|
|
103
|
-
rateLimitPerDay: config.rateLimitPerDay,
|
|
104
|
-
pricePerRequest: config.pricePerRequest,
|
|
105
|
-
status: config.status,
|
|
106
|
-
allowCustomerKeys: config.allowCustomerKeys ?? true,
|
|
107
|
-
requireCustomerKeys: config.requireCustomerKeys ?? false,
|
|
108
|
-
updatedAt: now,
|
|
109
|
-
};
|
|
110
|
-
// Only update master key if provided (not empty)
|
|
111
|
-
if (config.masterApiKey) {
|
|
112
|
-
updateData.encryptedMasterKey = config.masterApiKey; // In prod: encrypt this
|
|
113
|
-
}
|
|
114
|
-
await ctx.db.patch(existing._id, updateData);
|
|
115
|
-
return existing._id;
|
|
116
|
-
}
|
|
117
|
-
// Create new config
|
|
118
|
-
return await ctx.db.insert("providerDirectCall", {
|
|
119
|
-
providerId: session.providerId,
|
|
120
|
-
apiId: config.apiId,
|
|
121
|
-
baseUrl: config.baseUrl,
|
|
122
|
-
authType: config.authType,
|
|
123
|
-
authHeader: config.authHeader,
|
|
124
|
-
authPrefix: config.authPrefix,
|
|
125
|
-
encryptedMasterKey: config.masterApiKey || "",
|
|
126
|
-
rateLimitPerUser: config.rateLimitPerUser,
|
|
127
|
-
rateLimitPerDay: config.rateLimitPerDay,
|
|
128
|
-
pricePerRequest: config.pricePerRequest,
|
|
129
|
-
status: config.status,
|
|
130
|
-
allowCustomerKeys: config.allowCustomerKeys ?? true,
|
|
131
|
-
requireCustomerKeys: config.requireCustomerKeys ?? false,
|
|
132
|
-
createdAt: now,
|
|
133
|
-
updatedAt: now,
|
|
134
|
-
});
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
/**
|
|
138
|
-
* Create/update an action for a Direct Call config
|
|
139
|
-
*/
|
|
140
|
-
export const saveAction = mutation({
|
|
141
|
-
args: {
|
|
142
|
-
id: v.optional(v.id("providerActions")),
|
|
143
|
-
directCallId: v.id("providerDirectCall"),
|
|
144
|
-
name: v.string(),
|
|
145
|
-
displayName: v.string(),
|
|
146
|
-
description: v.string(),
|
|
147
|
-
method: v.string(),
|
|
148
|
-
path: v.string(),
|
|
149
|
-
params: v.array(v.object({
|
|
150
|
-
name: v.string(),
|
|
151
|
-
type: v.string(),
|
|
152
|
-
required: v.boolean(),
|
|
153
|
-
description: v.string(),
|
|
154
|
-
default: v.optional(v.any()),
|
|
155
|
-
in: v.string(),
|
|
156
|
-
})),
|
|
157
|
-
responseMapping: v.array(v.object({
|
|
158
|
-
name: v.string(),
|
|
159
|
-
path: v.string(),
|
|
160
|
-
})),
|
|
161
|
-
enabled: v.boolean(),
|
|
162
|
-
},
|
|
163
|
-
handler: async (ctx, args) => {
|
|
164
|
-
const now = Date.now();
|
|
165
|
-
if (args.id) {
|
|
166
|
-
// Update existing
|
|
167
|
-
await ctx.db.patch(args.id, {
|
|
168
|
-
name: args.name,
|
|
169
|
-
displayName: args.displayName,
|
|
170
|
-
description: args.description,
|
|
171
|
-
method: args.method,
|
|
172
|
-
path: args.path,
|
|
173
|
-
params: args.params,
|
|
174
|
-
responseMapping: args.responseMapping,
|
|
175
|
-
enabled: args.enabled,
|
|
176
|
-
updatedAt: now,
|
|
177
|
-
});
|
|
178
|
-
return args.id;
|
|
179
|
-
}
|
|
180
|
-
// Create new
|
|
181
|
-
return await ctx.db.insert("providerActions", {
|
|
182
|
-
directCallId: args.directCallId,
|
|
183
|
-
name: args.name,
|
|
184
|
-
displayName: args.displayName,
|
|
185
|
-
description: args.description,
|
|
186
|
-
method: args.method,
|
|
187
|
-
path: args.path,
|
|
188
|
-
params: args.params,
|
|
189
|
-
responseMapping: args.responseMapping,
|
|
190
|
-
enabled: args.enabled,
|
|
191
|
-
createdAt: now,
|
|
192
|
-
updatedAt: now,
|
|
193
|
-
});
|
|
194
|
-
},
|
|
195
|
-
});
|
|
196
|
-
/**
|
|
197
|
-
* Delete an action
|
|
198
|
-
*/
|
|
199
|
-
export const deleteAction = mutation({
|
|
200
|
-
args: {
|
|
201
|
-
id: v.id("providerActions"),
|
|
202
|
-
},
|
|
203
|
-
handler: async (ctx, args) => {
|
|
204
|
-
await ctx.db.delete(args.id);
|
|
205
|
-
return { success: true };
|
|
206
|
-
},
|
|
207
|
-
});
|
|
208
|
-
/**
|
|
209
|
-
* Publish Direct Call - set status to live
|
|
210
|
-
* Also marks apiListed earn progress for the provider's workspace
|
|
211
|
-
*/
|
|
212
|
-
export const publishDirectCall = mutation({
|
|
213
|
-
args: {
|
|
214
|
-
id: v.id("providerDirectCall"),
|
|
215
|
-
},
|
|
216
|
-
handler: async (ctx, args) => {
|
|
217
|
-
const now = Date.now();
|
|
218
|
-
// Get the direct call config to find the provider
|
|
219
|
-
const config = await ctx.db.get(args.id);
|
|
220
|
-
if (!config) {
|
|
221
|
-
throw new Error("Direct Call config not found");
|
|
222
|
-
}
|
|
223
|
-
await ctx.db.patch(args.id, {
|
|
224
|
-
status: "live",
|
|
225
|
-
publishedAt: now,
|
|
226
|
-
updatedAt: now,
|
|
227
|
-
});
|
|
228
|
-
// Try to mark apiListed for earn progress
|
|
229
|
-
// First, get the provider to find their session/workspace
|
|
230
|
-
const provider = await ctx.db.get(config.providerId);
|
|
231
|
-
if (provider) {
|
|
232
|
-
// Find workspace by provider email
|
|
233
|
-
const workspace = await ctx.db
|
|
234
|
-
.query("workspaces")
|
|
235
|
-
.withIndex("by_email", (q) => q.eq("email", provider.email))
|
|
236
|
-
.first();
|
|
237
|
-
if (workspace) {
|
|
238
|
-
// Update earn progress
|
|
239
|
-
const earnProgress = await ctx.db
|
|
240
|
-
.query("earnProgress")
|
|
241
|
-
.withIndex("by_workspaceId", (q) => q.eq("workspaceId", workspace._id))
|
|
242
|
-
.first();
|
|
243
|
-
if (earnProgress && !earnProgress.apiListed) {
|
|
244
|
-
const newTotal = calculateEarnTotal({ ...earnProgress, apiListed: true });
|
|
245
|
-
await ctx.db.patch(earnProgress._id, {
|
|
246
|
-
apiListed: true,
|
|
247
|
-
apiListedAt: now,
|
|
248
|
-
totalEarned: newTotal,
|
|
249
|
-
updatedAt: now,
|
|
250
|
-
});
|
|
251
|
-
// Add 10 calls to workspace limit
|
|
252
|
-
await ctx.db.patch(workspace._id, {
|
|
253
|
-
usageLimit: workspace.usageLimit + 10,
|
|
254
|
-
updatedAt: now,
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
else if (!earnProgress) {
|
|
258
|
-
// Create earn progress with apiListed
|
|
259
|
-
await ctx.db.insert("earnProgress", {
|
|
260
|
-
workspaceId: workspace._id,
|
|
261
|
-
firstDirectCall: false,
|
|
262
|
-
apisUsed: [],
|
|
263
|
-
apisUsedComplete: false,
|
|
264
|
-
agentListed: false,
|
|
265
|
-
apiListed: true,
|
|
266
|
-
apiListedAt: now,
|
|
267
|
-
byokSetup: false,
|
|
268
|
-
githubStarred: false,
|
|
269
|
-
twitterFollowed: false,
|
|
270
|
-
referralCount: 0,
|
|
271
|
-
totalEarned: 10,
|
|
272
|
-
createdAt: now,
|
|
273
|
-
updatedAt: now,
|
|
274
|
-
});
|
|
275
|
-
// Add 10 calls to workspace limit
|
|
276
|
-
await ctx.db.patch(workspace._id, {
|
|
277
|
-
usageLimit: workspace.usageLimit + 10,
|
|
278
|
-
updatedAt: now,
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
return { success: true, publishedAt: now };
|
|
284
|
-
},
|
|
285
|
-
});
|
|
286
|
-
// Helper to calculate earn total (duplicated to avoid circular import)
|
|
287
|
-
function calculateEarnTotal(progress) {
|
|
288
|
-
let total = 0;
|
|
289
|
-
if (progress.firstDirectCall)
|
|
290
|
-
total += 15;
|
|
291
|
-
if (progress.apisUsedComplete)
|
|
292
|
-
total += 10;
|
|
293
|
-
if (progress.agentListed)
|
|
294
|
-
total += 10;
|
|
295
|
-
if (progress.apiListed)
|
|
296
|
-
total += 10;
|
|
297
|
-
if (progress.byokSetup)
|
|
298
|
-
total += 5;
|
|
299
|
-
if (progress.githubStarred)
|
|
300
|
-
total += 10;
|
|
301
|
-
if (progress.twitterFollowed)
|
|
302
|
-
total += 5;
|
|
303
|
-
total += (progress.referralCount || 0) * 10;
|
|
304
|
-
return total;
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Set Direct Call status (draft, testing, live)
|
|
308
|
-
*/
|
|
309
|
-
export const setStatus = mutation({
|
|
310
|
-
args: {
|
|
311
|
-
id: v.id("providerDirectCall"),
|
|
312
|
-
status: v.string(),
|
|
313
|
-
},
|
|
314
|
-
handler: async (ctx, args) => {
|
|
315
|
-
const now = Date.now();
|
|
316
|
-
const update = {
|
|
317
|
-
status: args.status,
|
|
318
|
-
updatedAt: now,
|
|
319
|
-
};
|
|
320
|
-
if (args.status === "live") {
|
|
321
|
-
update.publishedAt = now;
|
|
322
|
-
}
|
|
323
|
-
await ctx.db.patch(args.id, update);
|
|
324
|
-
return { success: true };
|
|
325
|
-
},
|
|
326
|
-
});
|
|
327
|
-
// ============================================
|
|
328
|
-
// QUERIES
|
|
329
|
-
// ============================================
|
|
330
|
-
/**
|
|
331
|
-
* Get Direct Call config by providerId
|
|
332
|
-
*/
|
|
333
|
-
export const getDirectCallConfig = query({
|
|
334
|
-
args: {
|
|
335
|
-
providerId: v.id("providers"),
|
|
336
|
-
},
|
|
337
|
-
handler: async (ctx, args) => {
|
|
338
|
-
return await ctx.db
|
|
339
|
-
.query("providerDirectCall")
|
|
340
|
-
.withIndex("by_providerId", (q) => q.eq("providerId", args.providerId))
|
|
341
|
-
.first();
|
|
342
|
-
},
|
|
343
|
-
});
|
|
344
|
-
/**
|
|
345
|
-
* Get Direct Call config by ID
|
|
346
|
-
*/
|
|
347
|
-
export const getDirectCallConfigById = query({
|
|
348
|
-
args: {
|
|
349
|
-
id: v.id("providerDirectCall"),
|
|
350
|
-
},
|
|
351
|
-
handler: async (ctx, args) => {
|
|
352
|
-
return await ctx.db.get(args.id);
|
|
353
|
-
},
|
|
354
|
-
});
|
|
355
|
-
/**
|
|
356
|
-
* Get Direct Call config by API ID
|
|
357
|
-
*/
|
|
358
|
-
export const getDirectCallConfigByApiId = query({
|
|
359
|
-
args: {
|
|
360
|
-
apiId: v.string(), // Accept string since that's what frontend passes
|
|
361
|
-
},
|
|
362
|
-
handler: async (ctx, args) => {
|
|
363
|
-
return await ctx.db
|
|
364
|
-
.query("providerDirectCall")
|
|
365
|
-
.filter((q) => q.eq(q.field("apiId"), args.apiId))
|
|
366
|
-
.first();
|
|
367
|
-
},
|
|
368
|
-
});
|
|
369
|
-
/**
|
|
370
|
-
* Get all actions for a Direct Call config
|
|
371
|
-
*/
|
|
372
|
-
export const getActions = query({
|
|
373
|
-
args: {
|
|
374
|
-
directCallId: v.id("providerDirectCall"),
|
|
375
|
-
},
|
|
376
|
-
handler: async (ctx, args) => {
|
|
377
|
-
return await ctx.db
|
|
378
|
-
.query("providerActions")
|
|
379
|
-
.withIndex("by_directCallId", (q) => q.eq("directCallId", args.directCallId))
|
|
380
|
-
.collect();
|
|
381
|
-
},
|
|
382
|
-
});
|
|
383
|
-
/**
|
|
384
|
-
* Get single action by directCallId + name
|
|
385
|
-
*/
|
|
386
|
-
export const getActionByName = query({
|
|
387
|
-
args: {
|
|
388
|
-
directCallId: v.id("providerDirectCall"),
|
|
389
|
-
name: v.string(),
|
|
390
|
-
},
|
|
391
|
-
handler: async (ctx, args) => {
|
|
392
|
-
return await ctx.db
|
|
393
|
-
.query("providerActions")
|
|
394
|
-
.withIndex("by_directCallId_name", (q) => q.eq("directCallId", args.directCallId).eq("name", args.name))
|
|
395
|
-
.first();
|
|
396
|
-
},
|
|
397
|
-
});
|
|
398
|
-
/**
|
|
399
|
-
* Get action by ID
|
|
400
|
-
*/
|
|
401
|
-
export const getActionById = query({
|
|
402
|
-
args: {
|
|
403
|
-
id: v.id("providerActions"),
|
|
404
|
-
},
|
|
405
|
-
handler: async (ctx, args) => {
|
|
406
|
-
return await ctx.db.get(args.id);
|
|
407
|
-
},
|
|
408
|
-
});
|
|
409
|
-
/**
|
|
410
|
-
* DEBUG: Get all Direct Call configs
|
|
411
|
-
*/
|
|
412
|
-
export const getAllConfigs = query({
|
|
413
|
-
args: {},
|
|
414
|
-
handler: async (ctx) => {
|
|
415
|
-
return await ctx.db.query("providerDirectCall").collect();
|
|
416
|
-
},
|
|
417
|
-
});
|
|
418
|
-
/**
|
|
419
|
-
* Get all live Direct Call configs (for public API discovery)
|
|
420
|
-
*/
|
|
421
|
-
export const getLiveConfigs = query({
|
|
422
|
-
args: {},
|
|
423
|
-
handler: async (ctx) => {
|
|
424
|
-
return await ctx.db
|
|
425
|
-
.query("providerDirectCall")
|
|
426
|
-
.withIndex("by_status", (q) => q.eq("status", "live"))
|
|
427
|
-
.collect();
|
|
428
|
-
},
|
|
429
|
-
});
|
|
430
|
-
/**
|
|
431
|
-
* Get Direct Call config by API ID (for test console)
|
|
432
|
-
*/
|
|
433
|
-
export const getConfig = query({
|
|
434
|
-
args: {
|
|
435
|
-
apiId: v.string(),
|
|
436
|
-
},
|
|
437
|
-
handler: async (ctx, args) => {
|
|
438
|
-
// Try as providerAPIs ID first
|
|
439
|
-
const config = await ctx.db
|
|
440
|
-
.query("providerDirectCall")
|
|
441
|
-
.withIndex("by_apiId")
|
|
442
|
-
.filter((q) => q.eq(q.field("apiId"), args.apiId))
|
|
443
|
-
.first();
|
|
444
|
-
return config;
|
|
445
|
-
},
|
|
446
|
-
});
|
|
447
|
-
/**
|
|
448
|
-
* Get Direct Call config by API slug (for MCP/agent execution)
|
|
449
|
-
* Looks up API by name, then gets the Direct Call config
|
|
450
|
-
*/
|
|
451
|
-
export const getByApiSlug = query({
|
|
452
|
-
args: {
|
|
453
|
-
slug: v.string(),
|
|
454
|
-
},
|
|
455
|
-
handler: async (ctx, args) => {
|
|
456
|
-
// Normalize slug (lowercase, replace spaces/dashes)
|
|
457
|
-
const normalizedSlug = args.slug.toLowerCase().replace(/[\s-]/g, '_');
|
|
458
|
-
// Find API by name (case-insensitive match)
|
|
459
|
-
const apis = await ctx.db.query("providerAPIs").collect();
|
|
460
|
-
const api = apis.find(a => a.name.toLowerCase().replace(/[\s-]/g, '_') === normalizedSlug ||
|
|
461
|
-
a.name.toLowerCase() === args.slug.toLowerCase());
|
|
462
|
-
if (!api) {
|
|
463
|
-
return null;
|
|
464
|
-
}
|
|
465
|
-
// Get Direct Call config for this API
|
|
466
|
-
const config = await ctx.db
|
|
467
|
-
.query("providerDirectCall")
|
|
468
|
-
.withIndex("by_apiId")
|
|
469
|
-
.filter((q) => q.eq(q.field("apiId"), api._id))
|
|
470
|
-
.first();
|
|
471
|
-
if (!config || config.status !== 'live') {
|
|
472
|
-
return null;
|
|
473
|
-
}
|
|
474
|
-
return {
|
|
475
|
-
...config,
|
|
476
|
-
apiName: api.name,
|
|
477
|
-
apiSlug: normalizedSlug,
|
|
478
|
-
};
|
|
479
|
-
},
|
|
480
|
-
});
|
|
481
|
-
// ============================================
|
|
482
|
-
// TEST ACTION
|
|
483
|
-
// ============================================
|
|
484
|
-
/**
|
|
485
|
-
* Test an action by calling the actual provider API
|
|
486
|
-
* For V1: Provider passes their own test key
|
|
487
|
-
*/
|
|
488
|
-
export const testAction = mutation({
|
|
489
|
-
args: {
|
|
490
|
-
token: v.string(),
|
|
491
|
-
directCallId: v.id("providerDirectCall"),
|
|
492
|
-
actionId: v.id("providerActions"),
|
|
493
|
-
params: v.record(v.string(), v.any()),
|
|
494
|
-
testKey: v.optional(v.string()),
|
|
495
|
-
},
|
|
496
|
-
handler: async (ctx, args) => {
|
|
497
|
-
const startTime = Date.now();
|
|
498
|
-
// 1. Verify provider session
|
|
499
|
-
const session = await ctx.db
|
|
500
|
-
.query("sessions")
|
|
501
|
-
.withIndex("by_token", (q) => q.eq("token", args.token))
|
|
502
|
-
.first();
|
|
503
|
-
if (!session || session.expiresAt < Date.now()) {
|
|
504
|
-
return {
|
|
505
|
-
success: false,
|
|
506
|
-
error: "Unauthorized - invalid or expired session",
|
|
507
|
-
latencyMs: Date.now() - startTime,
|
|
508
|
-
};
|
|
509
|
-
}
|
|
510
|
-
// 2. Get directCallConfig
|
|
511
|
-
const config = await ctx.db.get(args.directCallId);
|
|
512
|
-
if (!config) {
|
|
513
|
-
return {
|
|
514
|
-
success: false,
|
|
515
|
-
error: "Direct Call config not found",
|
|
516
|
-
latencyMs: Date.now() - startTime,
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
// Verify ownership
|
|
520
|
-
if (config.providerId !== session.providerId) {
|
|
521
|
-
return {
|
|
522
|
-
success: false,
|
|
523
|
-
error: "Unauthorized - you don't own this config",
|
|
524
|
-
latencyMs: Date.now() - startTime,
|
|
525
|
-
};
|
|
526
|
-
}
|
|
527
|
-
// 3. Get action
|
|
528
|
-
const action = await ctx.db.get(args.actionId);
|
|
529
|
-
if (!action) {
|
|
530
|
-
return {
|
|
531
|
-
success: false,
|
|
532
|
-
error: "Action not found",
|
|
533
|
-
latencyMs: Date.now() - startTime,
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
// 4. Get API key (use testKey if provided, else use stored key)
|
|
537
|
-
// Note: For production, encryptedMasterKey would need server-side decryption
|
|
538
|
-
// For V1 test console, we use testKey directly
|
|
539
|
-
const apiKey = args.testKey || config.encryptedMasterKey;
|
|
540
|
-
if (!apiKey) {
|
|
541
|
-
return {
|
|
542
|
-
success: false,
|
|
543
|
-
error: "No API key provided. Add a test key or configure master key.",
|
|
544
|
-
latencyMs: Date.now() - startTime,
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
// 5. Build URL with path params
|
|
548
|
-
let path = action.path;
|
|
549
|
-
const queryParams = {};
|
|
550
|
-
const bodyParams = {};
|
|
551
|
-
for (const paramDef of action.params) {
|
|
552
|
-
const value = args.params[paramDef.name];
|
|
553
|
-
if (value === undefined || value === "")
|
|
554
|
-
continue;
|
|
555
|
-
if (paramDef.in === "path") {
|
|
556
|
-
// Replace {paramName} in path
|
|
557
|
-
path = path.replace(`{${paramDef.name}}`, String(value));
|
|
558
|
-
}
|
|
559
|
-
else if (paramDef.in === "query") {
|
|
560
|
-
queryParams[paramDef.name] = String(value);
|
|
561
|
-
}
|
|
562
|
-
else if (paramDef.in === "body") {
|
|
563
|
-
bodyParams[paramDef.name] = value;
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
// Build full URL
|
|
567
|
-
let url = config.baseUrl.replace(/\/$/, "") + path;
|
|
568
|
-
const queryString = new URLSearchParams(queryParams).toString();
|
|
569
|
-
if (queryString) {
|
|
570
|
-
url += (url.includes("?") ? "&" : "?") + queryString;
|
|
571
|
-
}
|
|
572
|
-
// 6. Build headers with auth
|
|
573
|
-
const headers = {
|
|
574
|
-
"Content-Type": "application/json",
|
|
575
|
-
"Accept": "application/json",
|
|
576
|
-
};
|
|
577
|
-
// Add auth header
|
|
578
|
-
if (config.authType !== "none" && apiKey) {
|
|
579
|
-
const authValue = config.authPrefix
|
|
580
|
-
? `${config.authPrefix}${apiKey}`
|
|
581
|
-
: apiKey;
|
|
582
|
-
headers[config.authHeader] = authValue;
|
|
583
|
-
}
|
|
584
|
-
// 7. Build fetch options
|
|
585
|
-
const fetchOptions = {
|
|
586
|
-
method: action.method,
|
|
587
|
-
headers,
|
|
588
|
-
};
|
|
589
|
-
// Add body for non-GET requests
|
|
590
|
-
if (action.method !== "GET" && Object.keys(bodyParams).length > 0) {
|
|
591
|
-
fetchOptions.body = JSON.stringify(bodyParams);
|
|
592
|
-
}
|
|
593
|
-
// 8. Execute request
|
|
594
|
-
try {
|
|
595
|
-
const response = await fetch(url, fetchOptions);
|
|
596
|
-
const latencyMs = Date.now() - startTime;
|
|
597
|
-
// Try to parse response as JSON, fallback to text
|
|
598
|
-
let data;
|
|
599
|
-
const contentType = response.headers.get("content-type") || "";
|
|
600
|
-
if (contentType.includes("application/json")) {
|
|
601
|
-
try {
|
|
602
|
-
data = await response.json();
|
|
603
|
-
}
|
|
604
|
-
catch {
|
|
605
|
-
data = await response.text();
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
else {
|
|
609
|
-
data = await response.text();
|
|
610
|
-
}
|
|
611
|
-
return {
|
|
612
|
-
success: response.ok,
|
|
613
|
-
status: response.status,
|
|
614
|
-
data,
|
|
615
|
-
latencyMs,
|
|
616
|
-
};
|
|
617
|
-
}
|
|
618
|
-
catch (error) {
|
|
619
|
-
return {
|
|
620
|
-
success: false,
|
|
621
|
-
error: error instanceof Error ? error.message : "Request failed",
|
|
622
|
-
latencyMs: Date.now() - startTime,
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
},
|
|
626
|
-
});
|
|
627
|
-
//# sourceMappingURL=directCall.js.map
|
package/convex/earnProgress.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get earn progress for a workspace (via session token)
|
|
3
|
-
*/
|
|
4
|
-
export declare const getEarnProgress: any;
|
|
5
|
-
/**
|
|
6
|
-
* Get earn progress by workspace ID (internal use)
|
|
7
|
-
*/
|
|
8
|
-
export declare const getByWorkspaceId: any;
|
|
9
|
-
/**
|
|
10
|
-
* Ensure workspace has a referral code (called on first earn page visit)
|
|
11
|
-
*/
|
|
12
|
-
export declare const ensureReferralCode: any;
|
|
13
|
-
/**
|
|
14
|
-
* Get earn progress with referral info (for UI)
|
|
15
|
-
*/
|
|
16
|
-
export declare const getByToken: any;
|
|
17
|
-
/**
|
|
18
|
-
* Get referral stats for a workspace
|
|
19
|
-
*/
|
|
20
|
-
export declare const getReferralStats: any;
|
|
21
|
-
/**
|
|
22
|
-
* Mark first direct call as complete
|
|
23
|
-
*/
|
|
24
|
-
export declare const markFirstDirectCall: any;
|
|
25
|
-
/**
|
|
26
|
-
* Track unique APIs used
|
|
27
|
-
*/
|
|
28
|
-
export declare const trackApiUsed: any;
|
|
29
|
-
/**
|
|
30
|
-
* Mark agent listed
|
|
31
|
-
*/
|
|
32
|
-
export declare const markAgentListed: any;
|
|
33
|
-
/**
|
|
34
|
-
* Mark API listed
|
|
35
|
-
*/
|
|
36
|
-
export declare const markApiListed: any;
|
|
37
|
-
/**
|
|
38
|
-
* Mark BYOK setup complete
|
|
39
|
-
*/
|
|
40
|
-
export declare const markByokSetup: any;
|
|
41
|
-
/**
|
|
42
|
-
* Claim GitHub star reward
|
|
43
|
-
*/
|
|
44
|
-
export declare const claimGithub: any;
|
|
45
|
-
/**
|
|
46
|
-
* Claim Twitter follow reward
|
|
47
|
-
*/
|
|
48
|
-
export declare const claimTwitter: any;
|
|
49
|
-
/**
|
|
50
|
-
* Increment referral count (called when someone signs up with referral code)
|
|
51
|
-
*/
|
|
52
|
-
export declare const incrementReferral: any;
|
|
53
|
-
/**
|
|
54
|
-
* Internal: Track API call for earn progress
|
|
55
|
-
* Called from usage tracking after successful API call
|
|
56
|
-
*/
|
|
57
|
-
export declare const trackApiCallInternal: any;
|
|
58
|
-
//# sourceMappingURL=earnProgress.d.ts.map
|