@nordsym/apiclaw 1.5.17 → 1.5.19

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.
Files changed (228) hide show
  1. package/convex/http.js.map +1 -1
  2. package/convex/http.ts +516 -0
  3. package/dist/analytics.d.ts +0 -4
  4. package/dist/analytics.d.ts.map +1 -1
  5. package/dist/analytics.js +0 -1
  6. package/dist/analytics.js.map +1 -1
  7. package/dist/bin.js +1 -1
  8. package/dist/cli/commands/mcp-install.d.ts.map +1 -1
  9. package/dist/cli/commands/mcp-install.js +8 -87
  10. package/dist/cli/commands/mcp-install.js.map +1 -1
  11. package/dist/cli/index.js +0 -7
  12. package/dist/credentials.d.ts.map +1 -1
  13. package/dist/credentials.js +38 -43
  14. package/dist/credentials.js.map +1 -1
  15. package/dist/discovery.d.ts.map +1 -1
  16. package/dist/discovery.js +82 -191
  17. package/dist/discovery.js.map +1 -1
  18. package/dist/http-api.d.ts.map +1 -1
  19. package/dist/http-api.js +33 -17
  20. package/dist/http-api.js.map +1 -1
  21. package/dist/proxy.js +1 -1
  22. package/dist/proxy.js.map +1 -1
  23. package/landing/next-env.d.ts +0 -1
  24. package/landing/src/app/api/auth/magic-link/route.ts +1 -1
  25. package/landing/src/app/auth/verify/page.tsx +0 -6
  26. package/landing/src/app/dashboard/verify/page.tsx +0 -6
  27. package/landing/src/app/join/page.tsx +0 -6
  28. package/landing/src/app/layout.tsx +2 -2
  29. package/landing/src/app/login/page.tsx +1 -1
  30. package/landing/src/app/mou/[partnerId]/page.tsx +0 -6
  31. package/landing/src/app/page.tsx +18 -39
  32. package/landing/src/app/providers/dashboard/[apiId]/actions/[actionId]/edit/page.tsx +0 -6
  33. package/landing/src/app/providers/dashboard/[apiId]/actions/new/page.tsx +0 -5
  34. package/landing/src/app/providers/dashboard/[apiId]/actions/page.tsx +0 -5
  35. package/landing/src/app/providers/dashboard/[apiId]/direct-call/page.tsx +1 -6
  36. package/landing/src/app/providers/dashboard/[apiId]/page.tsx +0 -5
  37. package/landing/src/app/providers/dashboard/[apiId]/test/page.tsx +0 -5
  38. package/landing/src/app/providers/dashboard/layout.tsx +6 -6
  39. package/landing/src/app/providers/dashboard/login/page.tsx +1 -1
  40. package/landing/src/app/providers/dashboard/page.tsx +1 -1
  41. package/landing/src/app/providers/dashboard/verify/page.tsx +0 -6
  42. package/landing/src/app/providers/layout.tsx +1 -1
  43. package/landing/src/app/upgrade/page.tsx +0 -6
  44. package/landing/src/app/workspace/page.tsx +0 -6
  45. package/landing/src/components/HeroTabs.tsx +2 -2
  46. package/landing/src/components/{Workspace.tsx → ProviderDashboard.tsx} +2 -2
  47. package/landing/src/components/VideoDemo.tsx +10 -21
  48. package/landing/src/lib/mock-data.ts +1 -1
  49. package/landing/src/lib/stats.json +1 -1
  50. package/package.json +3 -8
  51. package/src/analytics.ts +0 -5
  52. package/src/bin.ts +1 -1
  53. package/src/cli/commands/mcp-install.ts +8 -90
  54. package/src/cli/index.ts +0 -8
  55. package/src/credentials.ts +39 -44
  56. package/src/discovery.ts +82 -191
  57. package/src/http-api.ts +34 -18
  58. package/src/proxy.ts +1 -1
  59. package/APILAYER_STATUS_2026-03-24.md +0 -38
  60. package/CHANGELOG-WHITELIST-V2.md +0 -269
  61. package/HIVR-WHITELIST-STATUS.md +0 -205
  62. package/HIVR-WHITELIST.md +0 -148
  63. package/TERMINOLOGY-AUDIT.md +0 -99
  64. package/TERMINOLOGY-FIXED.md +0 -74
  65. package/VIDEO-DEMO-GUIDE.md +0 -82
  66. package/WHITELIST-ARCHITECTURE.md +0 -379
  67. package/api/discover.ts +0 -71
  68. package/api/health.ts +0 -20
  69. package/convex/adminActivate.d.ts +0 -3
  70. package/convex/adminActivate.js +0 -47
  71. package/convex/adminStats.d.ts +0 -3
  72. package/convex/adminStats.js +0 -42
  73. package/convex/agents.d.ts +0 -54
  74. package/convex/agents.js +0 -499
  75. package/convex/analytics.d.ts +0 -5
  76. package/convex/analytics.js +0 -166
  77. package/convex/billing.d.ts +0 -88
  78. package/convex/billing.js +0 -655
  79. package/convex/capabilities.d.ts +0 -9
  80. package/convex/capabilities.js +0 -145
  81. package/convex/chains.d.ts +0 -67
  82. package/convex/chains.js +0 -1042
  83. package/convex/credits.d.ts +0 -25
  84. package/convex/credits.js +0 -186
  85. package/convex/crons.d.ts +0 -3
  86. package/convex/crons.js +0 -17
  87. package/convex/directCall.d.ts +0 -72
  88. package/convex/directCall.js +0 -627
  89. package/convex/earnProgress.d.ts +0 -58
  90. package/convex/earnProgress.js +0 -649
  91. package/convex/email.d.ts +0 -14
  92. package/convex/email.js +0 -300
  93. package/convex/feedback.d.ts +0 -7
  94. package/convex/feedback.js +0 -227
  95. package/convex/http.d.ts +0 -3
  96. package/convex/http.js +0 -910
  97. package/convex/logs.d.ts +0 -38
  98. package/convex/logs.js +0 -487
  99. package/convex/mou.d.ts +0 -6
  100. package/convex/mou.js +0 -82
  101. package/convex/providerKeys.d.ts +0 -31
  102. package/convex/providerKeys.js +0 -257
  103. package/convex/providers.d.ts +0 -29
  104. package/convex/providers.js +0 -756
  105. package/convex/purchases.d.ts +0 -7
  106. package/convex/purchases.js +0 -157
  107. package/convex/ratelimit.d.ts +0 -4
  108. package/convex/ratelimit.js +0 -91
  109. package/convex/searchLogs.d.ts +0 -4
  110. package/convex/searchLogs.js +0 -129
  111. package/convex/spendAlerts.d.ts +0 -36
  112. package/convex/spendAlerts.js +0 -380
  113. package/convex/stripeActions.d.ts +0 -19
  114. package/convex/stripeActions.js +0 -411
  115. package/convex/teams.d.ts +0 -21
  116. package/convex/teams.js +0 -215
  117. package/convex/telemetry.d.ts +0 -4
  118. package/convex/telemetry.js +0 -74
  119. package/convex/usage.d.ts +0 -27
  120. package/convex/usage.js +0 -229
  121. package/convex/waitlist.d.ts +0 -4
  122. package/convex/waitlist.js +0 -49
  123. package/convex/webhooks.d.ts +0 -12
  124. package/convex/webhooks.js +0 -410
  125. package/convex/workspaces.d.ts +0 -29
  126. package/convex/workspaces.js +0 -880
  127. package/direct-test.mjs +0 -51
  128. package/dist/access-control.d.ts +0 -45
  129. package/dist/access-control.d.ts.map +0 -1
  130. package/dist/access-control.js +0 -142
  131. package/dist/access-control.js.map +0 -1
  132. package/dist/chain-types.d.ts +0 -187
  133. package/dist/chain-types.d.ts.map +0 -1
  134. package/dist/chain-types.js +0 -33
  135. package/dist/chain-types.js.map +0 -1
  136. package/dist/convex/adminActivate.js +0 -46
  137. package/dist/convex/adminStats.js +0 -41
  138. package/dist/convex/agents.js +0 -498
  139. package/dist/convex/analytics.js +0 -165
  140. package/dist/convex/billing.js +0 -654
  141. package/dist/convex/capabilities.js +0 -144
  142. package/dist/convex/chains.js +0 -1041
  143. package/dist/convex/credits.js +0 -185
  144. package/dist/convex/crons.js +0 -16
  145. package/dist/convex/directCall.js +0 -626
  146. package/dist/convex/earnProgress.js +0 -648
  147. package/dist/convex/email.js +0 -299
  148. package/dist/convex/feedback.js +0 -226
  149. package/dist/convex/http.js +0 -909
  150. package/dist/convex/logs.js +0 -486
  151. package/dist/convex/mou.js +0 -81
  152. package/dist/convex/providerKeys.js +0 -256
  153. package/dist/convex/providers.js +0 -755
  154. package/dist/convex/purchases.js +0 -156
  155. package/dist/convex/ratelimit.js +0 -90
  156. package/dist/convex/schema.js +0 -709
  157. package/dist/convex/searchLogs.js +0 -128
  158. package/dist/convex/spendAlerts.js +0 -379
  159. package/dist/convex/stripeActions.js +0 -410
  160. package/dist/convex/teams.js +0 -214
  161. package/dist/convex/telemetry.js +0 -73
  162. package/dist/convex/usage.js +0 -228
  163. package/dist/convex/waitlist.js +0 -48
  164. package/dist/convex/webhooks.js +0 -409
  165. package/dist/convex/workspaces.js +0 -879
  166. package/dist/hivr-whitelist.d.ts +0 -18
  167. package/dist/hivr-whitelist.d.ts.map +0 -1
  168. package/dist/hivr-whitelist.js +0 -95
  169. package/dist/hivr-whitelist.js.map +0 -1
  170. package/dist/http-server-minimal.d.ts +0 -7
  171. package/dist/http-server-minimal.d.ts.map +0 -1
  172. package/dist/http-server-minimal.js +0 -126
  173. package/dist/http-server-minimal.js.map +0 -1
  174. package/dist/product-whitelist.d.ts +0 -37
  175. package/dist/product-whitelist.d.ts.map +0 -1
  176. package/dist/product-whitelist.js +0 -203
  177. package/dist/product-whitelist.js.map +0 -1
  178. package/dist/src/analytics.js +0 -129
  179. package/dist/src/bin.js +0 -17
  180. package/dist/src/capability-router.js +0 -240
  181. package/dist/src/chainExecutor.js +0 -451
  182. package/dist/src/chainResolver.js +0 -518
  183. package/dist/src/cli/commands/doctor.js +0 -324
  184. package/dist/src/cli/commands/mcp-install.js +0 -255
  185. package/dist/src/cli/commands/restore.js +0 -259
  186. package/dist/src/cli/commands/setup.js +0 -205
  187. package/dist/src/cli/commands/uninstall.js +0 -188
  188. package/dist/src/cli/index.js +0 -111
  189. package/dist/src/cli.js +0 -302
  190. package/dist/src/confirmation.js +0 -240
  191. package/dist/src/credentials.js +0 -357
  192. package/dist/src/credits.js +0 -260
  193. package/dist/src/crypto.js +0 -66
  194. package/dist/src/discovery.js +0 -504
  195. package/dist/src/enterprise/env.js +0 -123
  196. package/dist/src/enterprise/script-generator.js +0 -460
  197. package/dist/src/execute-dynamic.js +0 -473
  198. package/dist/src/execute.js +0 -1727
  199. package/dist/src/index.js +0 -2062
  200. package/dist/src/metered.js +0 -80
  201. package/dist/src/open-apis.js +0 -276
  202. package/dist/src/proxy.js +0 -28
  203. package/dist/src/session.js +0 -86
  204. package/dist/src/stripe.js +0 -407
  205. package/dist/src/telemetry.js +0 -49
  206. package/dist/src/types.js +0 -2
  207. package/dist/src/utils/backup.js +0 -181
  208. package/dist/src/utils/config.js +0 -220
  209. package/dist/src/utils/os.js +0 -105
  210. package/dist/src/utils/paths.js +0 -159
  211. package/landing/pages/api/discover.ts +0 -43
  212. package/landing/pages/api/health.ts +0 -20
  213. package/scripts/test-whitelist-v2.sh +0 -128
  214. package/src/access-control.ts +0 -174
  215. package/src/hivr-whitelist.ts +0 -110
  216. package/src/http-server-minimal.ts +0 -154
  217. package/src/product-whitelist.ts +0 -246
  218. package/test-actual-handlers.ts +0 -92
  219. package/test-apilayer-all-14.ts +0 -249
  220. package/test-apilayer-fixed.ts +0 -248
  221. package/test-direct-endpoints.ts +0 -174
  222. package/test-exact-endpoints.ts +0 -144
  223. package/test-final.ts +0 -83
  224. package/test-full-routing.ts +0 -100
  225. package/test-handlers-correct.ts +0 -217
  226. package/test-numverify-key.ts +0 -41
  227. package/test-via-handlers.ts +0 -92
  228. package/test-worldnews.mjs +0 -26
@@ -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
@@ -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