@nordsym/apiclaw 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/README.md +15 -2
  2. package/dist/bin-http.js +0 -0
  3. package/dist/bin.bundled.js +79288 -0
  4. package/dist/gateway-client.d.ts.map +1 -1
  5. package/dist/gateway-client.js +24 -2
  6. package/dist/gateway-client.js.map +1 -1
  7. package/dist/index.bundled.js +61263 -0
  8. package/dist/index.js +2 -2
  9. package/dist/index.js.map +1 -1
  10. package/package.json +7 -2
  11. package/.claude/settings.local.json +0 -13
  12. package/.env.prod +0 -1
  13. package/apiclaw-README.md +0 -494
  14. package/convex/_generated/api.d.ts +0 -145
  15. package/convex/_generated/api.js +0 -23
  16. package/convex/_generated/dataModel.d.ts +0 -60
  17. package/convex/_generated/server.d.ts +0 -143
  18. package/convex/_generated/server.js +0 -93
  19. package/convex/_listWorkspaces.ts +0 -13
  20. package/convex/adminActivate.ts +0 -53
  21. package/convex/adminStats.ts +0 -306
  22. package/convex/agents.ts +0 -939
  23. package/convex/analytics.ts +0 -187
  24. package/convex/apiKeys.ts +0 -220
  25. package/convex/backfillAnalytics.ts +0 -272
  26. package/convex/backfillSearchLogs.ts +0 -35
  27. package/convex/billing.ts +0 -834
  28. package/convex/capabilities.ts +0 -157
  29. package/convex/chains.ts +0 -1318
  30. package/convex/credits.ts +0 -211
  31. package/convex/crons.ts +0 -65
  32. package/convex/debugFilestackLogs.ts +0 -16
  33. package/convex/debugGetToken.ts +0 -18
  34. package/convex/directCall.ts +0 -713
  35. package/convex/earnProgress.ts +0 -753
  36. package/convex/email.ts +0 -329
  37. package/convex/feedback.ts +0 -265
  38. package/convex/funnel.ts +0 -431
  39. package/convex/guards.ts +0 -174
  40. package/convex/http.ts +0 -3756
  41. package/convex/inbound.ts +0 -32
  42. package/convex/logs.ts +0 -701
  43. package/convex/migrateFilestack.ts +0 -81
  44. package/convex/migratePartnersProd.ts +0 -174
  45. package/convex/migratePratham.ts +0 -126
  46. package/convex/migrateProviderWorkspaces.ts +0 -175
  47. package/convex/mou.ts +0 -91
  48. package/convex/nurture.ts +0 -355
  49. package/convex/providerKeys.ts +0 -289
  50. package/convex/providers.ts +0 -1135
  51. package/convex/purchases.ts +0 -183
  52. package/convex/ratelimit.ts +0 -104
  53. package/convex/schema.ts +0 -926
  54. package/convex/searchLogs.ts +0 -265
  55. package/convex/seedAPILayerAPIs.ts +0 -191
  56. package/convex/seedDirectCallConfigs.ts +0 -336
  57. package/convex/seedPratham.ts +0 -149
  58. package/convex/spendAlerts.ts +0 -442
  59. package/convex/stripeActions.ts +0 -607
  60. package/convex/teams.ts +0 -243
  61. package/convex/telemetry.ts +0 -81
  62. package/convex/tsconfig.json +0 -25
  63. package/convex/updateAPIStatus.ts +0 -44
  64. package/convex/usage.ts +0 -260
  65. package/convex/usageReports.ts +0 -357
  66. package/convex/waitlist.ts +0 -55
  67. package/convex/webhooks.ts +0 -494
  68. package/convex/workspaceSettings.ts +0 -143
  69. package/convex/workspaces.ts +0 -1331
  70. package/convex.json +0 -3
  71. package/direct-test.mjs +0 -51
  72. package/email-templates/filestack-provider-outreach.html +0 -162
  73. package/email-templates/partnership-template.html +0 -116
  74. package/email-templates/pratham-draft-preview.txt +0 -57
  75. package/email-templates/pratham-partnership-draft.html +0 -141
  76. package/reports/APIClaw-Session-Report-2026-04-05.pdf +0 -0
  77. package/reports/pipeline/PIPELINE-REPORT.json +0 -153
  78. package/reports/pipeline/acquire_apisguru.json +0 -17
  79. package/reports/pipeline/capabilities.json +0 -38
  80. package/reports/pipeline/discover_azure_recursive.json +0 -1551
  81. package/reports/pipeline/discover_github.json +0 -25
  82. package/reports/pipeline/discover_github_repos.json +0 -49
  83. package/reports/pipeline/discover_swaggerhub.json +0 -24
  84. package/reports/pipeline/discover_well_known.json +0 -23
  85. package/reports/pipeline/fetch_specs.json +0 -19
  86. package/reports/pipeline/generate_providers.json +0 -14
  87. package/reports/pipeline/match_registry.json +0 -11
  88. package/reports/pipeline/parse_specs.json +0 -17
  89. package/reports/pipeline/promote_candidates.json +0 -34
  90. package/reports/pipeline/validate.json +0 -30
  91. package/reports/pipeline/validate_smoke_details.json +0 -3835
  92. package/reports/session-report-2026-04-05.html +0 -433
  93. package/seed-apis-direct.mjs +0 -106
  94. package/src/access-control.ts +0 -174
  95. package/src/adapters/base.ts +0 -364
  96. package/src/adapters/claude-desktop.ts +0 -41
  97. package/src/adapters/cline.ts +0 -88
  98. package/src/adapters/continue.ts +0 -91
  99. package/src/adapters/cursor.ts +0 -43
  100. package/src/adapters/custom.ts +0 -188
  101. package/src/adapters/detect.ts +0 -202
  102. package/src/adapters/index.ts +0 -47
  103. package/src/adapters/windsurf.ts +0 -44
  104. package/src/bin-http.ts +0 -45
  105. package/src/bin.ts +0 -34
  106. package/src/capability-router.ts +0 -331
  107. package/src/chainExecutor.ts +0 -730
  108. package/src/chainResolver.test.ts +0 -246
  109. package/src/chainResolver.ts +0 -658
  110. package/src/cli/commands/demo.ts +0 -109
  111. package/src/cli/commands/doctor.ts +0 -435
  112. package/src/cli/commands/index.ts +0 -9
  113. package/src/cli/commands/login.ts +0 -203
  114. package/src/cli/commands/mcp-install.ts +0 -373
  115. package/src/cli/commands/restore.ts +0 -333
  116. package/src/cli/commands/setup.ts +0 -297
  117. package/src/cli/commands/uninstall.ts +0 -240
  118. package/src/cli/index.ts +0 -148
  119. package/src/cli.ts +0 -370
  120. package/src/confirmation.ts +0 -296
  121. package/src/credentials.ts +0 -455
  122. package/src/credits.ts +0 -329
  123. package/src/crypto.ts +0 -75
  124. package/src/discovery.ts +0 -568
  125. package/src/enterprise/env.ts +0 -156
  126. package/src/enterprise/index.ts +0 -7
  127. package/src/enterprise/script-generator.ts +0 -481
  128. package/src/execute-dynamic.ts +0 -617
  129. package/src/execute.ts +0 -2386
  130. package/src/funnel-client.ts +0 -168
  131. package/src/funnel.test.ts +0 -187
  132. package/src/gateway-client.ts +0 -192
  133. package/src/hivr-whitelist.ts +0 -110
  134. package/src/http-api.ts +0 -286
  135. package/src/http-server-minimal.ts +0 -154
  136. package/src/index.ts +0 -2702
  137. package/src/intelligent-gateway.ts +0 -339
  138. package/src/mcp-analytics.ts +0 -156
  139. package/src/metered.ts +0 -149
  140. package/src/open-apis-generated.ts +0 -157
  141. package/src/open-apis.ts +0 -558
  142. package/src/postinstall.ts +0 -40
  143. package/src/product-whitelist.ts +0 -246
  144. package/src/proxy.ts +0 -36
  145. package/src/registration-guard.ts +0 -117
  146. package/src/session.ts +0 -129
  147. package/src/stripe.ts +0 -497
  148. package/src/telemetry.ts +0 -71
  149. package/src/test.ts +0 -135
  150. package/src/types/convex-api.d.ts +0 -20
  151. package/src/types/convex-api.ts +0 -21
  152. package/src/types.ts +0 -109
  153. package/src/ui/colors.ts +0 -219
  154. package/src/ui/errors.ts +0 -394
  155. package/src/ui/index.ts +0 -17
  156. package/src/ui/prompts.ts +0 -390
  157. package/src/ui/spinner.ts +0 -325
  158. package/src/utils/backup.ts +0 -224
  159. package/src/utils/config.ts +0 -318
  160. package/src/utils/os.ts +0 -124
  161. package/src/utils/paths.ts +0 -203
  162. package/src/webhook.ts +0 -107
  163. package/test-10-working.cjs +0 -97
  164. package/test-14-final.cjs +0 -96
  165. package/test-actual-handlers.ts +0 -92
  166. package/test-apilayer-all-14.ts +0 -249
  167. package/test-apilayer-fixed.ts +0 -248
  168. package/test-direct-endpoints.ts +0 -174
  169. package/test-exact-endpoints.ts +0 -144
  170. package/test-final.ts +0 -83
  171. package/test-full-routing.ts +0 -100
  172. package/test-handlers-correct.ts +0 -217
  173. package/test-numverify-key.ts +0 -41
  174. package/test-via-handlers.ts +0 -92
  175. package/test-worldnews.mjs +0 -26
  176. package/tsconfig.json +0 -20
package/convex/email.ts DELETED
@@ -1,329 +0,0 @@
1
- import { v } from "convex/values";
2
- import { action, internalAction } from "./_generated/server";
3
-
4
- // ============================================
5
- // EMAIL TEMPLATES
6
- // ============================================
7
-
8
- const EMAIL_FROM = "APIClaw <noreply@apiclaw.cloud>";
9
- const APP_URL = "https://apiclaw.cloud";
10
-
11
- // Base email wrapper - using string concat for Convex compatibility
12
- function wrapEmail(content: string): string {
13
- const year = new Date().getFullYear();
14
- return [
15
- '<!DOCTYPE html>',
16
- '<html>',
17
- '<head>',
18
- '<meta charset="utf-8">',
19
- '<meta name="viewport" content="width=device-width, initial-scale=1.0">',
20
- '</head>',
21
- '<body style="margin: 0; padding: 0; background-color: #f5f5f5; font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial, sans-serif;">',
22
- '<table width="100%" cellpadding="0" cellspacing="0" style="background-color: #f5f5f5; padding: 40px 20px;">',
23
- '<tr>',
24
- '<td align="center">',
25
- '<table width="100%" cellpadding="0" cellspacing="0" style="max-width: 500px; background-color: #ffffff; border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.1);">',
26
- '<tr>',
27
- '<td style="padding: 32px 32px 24px; text-align: center; border-bottom: 1px solid #f0f0f0;">',
28
- '<span style="font-size: 48px;">🦞</span>',
29
- '<h1 style="margin: 16px 0 0; font-size: 24px; font-weight: 700; color: #0a0a0a;">APIClaw</h1>',
30
- '</td>',
31
- '</tr>',
32
- '<tr>',
33
- '<td style="padding: 32px;">',
34
- content,
35
- '</td>',
36
- '</tr>',
37
- '<tr>',
38
- '<td style="padding: 24px 32px; background-color: #fafafa; border-top: 1px solid #f0f0f0;">',
39
- '<p style="margin: 0; font-size: 12px; color: #737373; text-align: center;">',
40
- '<a href="https://apiclaw.cloud" style="color: #ef4444; text-decoration: none;">APIClaw</a> — The API Layer for AI Agents',
41
- '</p>',
42
- '<p style="margin: 8px 0 0; font-size: 12px; color: #a3a3a3; text-align: center;">',
43
- '© ' + year + ' NordSym. Stockholm, Sweden.',
44
- '</p>',
45
- '</td>',
46
- '</tr>',
47
- '</table>',
48
- '</td>',
49
- '</tr>',
50
- '</table>',
51
- '</body>',
52
- '</html>',
53
- ].join('');
54
- }
55
-
56
- // Magic link email template - ultra simple for Convex
57
- function magicLinkEmailTemplate(verifyUrl: string): string {
58
- // Simple inline HTML - no arrays, no template literals
59
- var html = "<!DOCTYPE html><html><head><meta charset='utf-8'></head>";
60
- html += "<body style='margin:0;padding:40px;background:#f5f5f5;font-family:Arial,sans-serif;'>";
61
- html += "<table width='100%' cellpadding='0' cellspacing='0'><tr><td align='center'>";
62
- html += "<table width='500' cellpadding='0' cellspacing='0' style='background:#fff;border-radius:12px;'>";
63
- html += "<tr><td style='padding:32px;text-align:center;'>";
64
- html += "<div style='font-size:48px;'>🦞</div>";
65
- html += "<h1 style='margin:16px 0;color:#0a0a0a;'>APIClaw</h1>";
66
- html += "<h2 style='margin:0 0 16px;font-size:20px;color:#0a0a0a;'>An AI Agent Wants to Connect</h2>";
67
- html += "<p style='margin:0 0 24px;color:#525252;'>Click below to verify your email and activate your workspace.</p>";
68
- html += "<a href='" + verifyUrl + "' style='display:inline-block;background:#ef4444;color:white;padding:14px 32px;border-radius:8px;text-decoration:none;font-weight:600;'>Verify Email</a>";
69
- html += "<p style='margin:24px 0 0;font-size:13px;color:#737373;'>Free tier: 50 API calls. This link expires in 1 hour.</p>";
70
- html += "</td></tr></table>";
71
- html += "</td></tr></table></body></html>";
72
- return html;
73
- }
74
-
75
- // Reminder email template
76
- function reminderEmailTemplate(verifyUrl: string): string {
77
- return wrapEmail(`
78
- <h2 style="margin: 0 0 16px; font-size: 20px; font-weight: 600; color: #0a0a0a; text-align: center;">
79
- Still Waiting for You 👋
80
- </h2>
81
-
82
- <p style="margin: 0 0 24px; font-size: 16px; line-height: 1.6; color: #525252; text-align: center;">
83
- Your AI agent is patiently waiting for you to verify your email.
84
- Click below to activate your workspace and let it get to work!
85
- </p>
86
-
87
- <table width="100%" cellpadding="0" cellspacing="0">
88
- <tr>
89
- <td align="center" style="padding: 8px 0 24px;">
90
- <a href="${verifyUrl}" style="display: inline-block; background: #ef4444; color: white; text-decoration: none; padding: 14px 32px; border-radius: 8px; font-weight: 600; font-size: 16px;">
91
- Verify & Get Started
92
- </a>
93
- </td>
94
- </tr>
95
- </table>
96
-
97
- <p style="margin: 0; font-size: 13px; color: #737373; text-align: center;">
98
- This link expires in 1 hour.
99
- </p>
100
- `);
101
- }
102
-
103
- // Limit reached email template
104
- function limitReachedEmailTemplate(upgradeUrl: string): string {
105
- return wrapEmail(`
106
- <h2 style="margin: 0 0 16px; font-size: 20px; font-weight: 600; color: #0a0a0a; text-align: center;">
107
- Free Tier Limit Reached
108
- </h2>
109
-
110
- <p style="margin: 0 0 24px; font-size: 16px; line-height: 1.6; color: #525252; text-align: center;">
111
- Your AI agent has used all 100 free API calls. Add a payment method to continue using APIClaw.
112
- </p>
113
-
114
- <div style="background: #f5f5f5; border-radius: 8px; padding: 20px; margin-bottom: 24px;">
115
- <p style="margin: 0 0 8px; font-size: 14px; font-weight: 600; color: #0a0a0a;">Pro Plan — $10/month</p>
116
- <ul style="margin: 0; padding: 0 0 0 20px; font-size: 14px; color: #525252; line-height: 1.8;">
117
- <li>10,000 API calls/month</li>
118
- <li>Priority support</li>
119
- <li>Usage analytics</li>
120
- </ul>
121
- </div>
122
-
123
- <table width="100%" cellpadding="0" cellspacing="0">
124
- <tr>
125
- <td align="center" style="padding: 8px 0 24px;">
126
- <a href="${upgradeUrl}" style="display: inline-block; background: #ef4444; color: white; text-decoration: none; padding: 14px 32px; border-radius: 8px; font-weight: 600; font-size: 16px;">
127
- Upgrade Now
128
- </a>
129
- </td>
130
- </tr>
131
- </table>
132
-
133
- <p style="margin: 0; font-size: 13px; color: #737373; text-align: center;">
134
- Questions? Reply to this email.
135
- </p>
136
- `);
137
- }
138
-
139
- // ============================================
140
- // EMAIL SENDING ACTIONS
141
- // ============================================
142
-
143
- /**
144
- * Send magic link email
145
- */
146
- export const sendMagicLinkEmail = action({
147
- args: {
148
- email: v.string(),
149
- token: v.string(),
150
- },
151
- handler: async (ctx, args) => {
152
- const RESEND_API_KEY = process.env.RESEND_API_KEY;
153
- if (!RESEND_API_KEY) {
154
- throw new Error("RESEND_API_KEY not configured");
155
- }
156
-
157
- var verifyUrl = APP_URL + "/auth/verify?token=" + args.token;
158
-
159
- // Generate HTML inline (same approach as debug that works)
160
- var html = "<!DOCTYPE html><html><head><meta charset='utf-8'></head>";
161
- html += "<body style='margin:0;padding:40px;background:#f5f5f5;font-family:Arial,sans-serif;'>";
162
- html += "<table width='100%' cellpadding='0' cellspacing='0'><tr><td align='center'>";
163
- html += "<table width='500' cellpadding='0' cellspacing='0' style='background:#fff;border-radius:12px;'>";
164
- html += "<tr><td style='padding:32px;text-align:center;'>";
165
- html += "<div style='font-size:48px;'>🦞</div>";
166
- html += "<h1 style='margin:16px 0;color:#0a0a0a;'>APIClaw</h1>";
167
- html += "<h2 style='margin:0 0 16px;font-size:20px;color:#0a0a0a;'>An AI Agent Wants to Connect</h2>";
168
- html += "<p style='margin:0 0 24px;color:#525252;'>Click below to verify your email and activate your workspace.</p>";
169
- html += "<a href='" + verifyUrl + "' style='display:inline-block;background:#ef4444;color:white;padding:14px 32px;border-radius:8px;text-decoration:none;font-weight:600;'>Verify Email</a>";
170
- html += "<p style='margin:24px 0 0;font-size:13px;color:#737373;'>Free tier: 50 API calls. This link expires in 1 hour.</p>";
171
- html += "</td></tr></table>";
172
- html += "</td></tr></table></body></html>";
173
-
174
- var textContent = "APIClaw - An AI Agent Wants to Connect\n\n";
175
- textContent += "Click the link: " + verifyUrl + "\n\n";
176
- textContent += "Free tier: 50 API calls. Expires in 1 hour.";
177
-
178
- var response = await fetch("https://api.resend.com/emails", {
179
- method: "POST",
180
- headers: {
181
- "Authorization": "Bearer " + RESEND_API_KEY,
182
- "Content-Type": "application/json",
183
- },
184
- body: JSON.stringify({
185
- from: EMAIL_FROM,
186
- to: args.email,
187
- subject: "🦞 An AI Agent Wants to Connect — Verify Your Email",
188
- html: html,
189
- text: textContent,
190
- }),
191
- });
192
-
193
- if (!response.ok) {
194
- var errorText = await response.text();
195
- throw new Error("Failed to send email: " + errorText);
196
- }
197
-
198
- return { success: true };
199
- },
200
- });
201
-
202
- /**
203
- * Send reminder email
204
- */
205
- export const sendReminderEmail = action({
206
- args: {
207
- email: v.string(),
208
- token: v.string(),
209
- },
210
- handler: async (ctx, args) => {
211
- const RESEND_API_KEY = process.env.RESEND_API_KEY;
212
- if (!RESEND_API_KEY) {
213
- throw new Error("RESEND_API_KEY not configured");
214
- }
215
-
216
- const verifyUrl = `${APP_URL}/auth/verify?token=${args.token}`;
217
- const html = reminderEmailTemplate(verifyUrl);
218
-
219
- const response = await fetch("https://api.resend.com/emails", {
220
- method: "POST",
221
- headers: {
222
- "Authorization": `Bearer ${RESEND_API_KEY}`,
223
- "Content-Type": "application/json",
224
- },
225
- body: JSON.stringify({
226
- from: EMAIL_FROM,
227
- to: args.email,
228
- subject: "🦞 Your Agent is Still Waiting — Verify Your Email",
229
- html,
230
- }),
231
- });
232
-
233
- if (!response.ok) {
234
- const error = await response.text();
235
- throw new Error(`Failed to send email: ${error}`);
236
- }
237
-
238
- return { success: true };
239
- },
240
- });
241
-
242
- /**
243
- * Send limit reached email
244
- */
245
- export const sendLimitReachedEmail = action({
246
- args: {
247
- email: v.string(),
248
- },
249
- handler: async (ctx, args) => {
250
- const RESEND_API_KEY = process.env.RESEND_API_KEY;
251
- if (!RESEND_API_KEY) {
252
- throw new Error("RESEND_API_KEY not configured");
253
- }
254
-
255
- const upgradeUrl = `${APP_URL}/upgrade`;
256
- const html = limitReachedEmailTemplate(upgradeUrl);
257
-
258
- const response = await fetch("https://api.resend.com/emails", {
259
- method: "POST",
260
- headers: {
261
- "Authorization": `Bearer ${RESEND_API_KEY}`,
262
- "Content-Type": "application/json",
263
- },
264
- body: JSON.stringify({
265
- from: EMAIL_FROM,
266
- to: args.email,
267
- subject: "🦞 Free Tier Limit Reached — Upgrade to Continue",
268
- html,
269
- }),
270
- });
271
-
272
- if (!response.ok) {
273
- const error = await response.text();
274
- throw new Error(`Failed to send email: ${error}`);
275
- }
276
-
277
- return { success: true };
278
- },
279
- });
280
-
281
- // Debug: Test email template generation
282
- export const debugEmailTemplate = action({
283
- args: { email: v.string() },
284
- handler: async (ctx, { email }) => {
285
- const RESEND_API_KEY = process.env.RESEND_API_KEY;
286
- const testUrl = "https://apiclaw.cloud/auth/verify?token=DEBUG_TEST";
287
-
288
- // Generate HTML using the template
289
- var html = "<!DOCTYPE html><html><head><meta charset='utf-8'></head>";
290
- html += "<body style='margin:0;padding:40px;background:#f5f5f5;font-family:Arial,sans-serif;'>";
291
- html += "<table width='100%' cellpadding='0' cellspacing='0'><tr><td align='center'>";
292
- html += "<table width='500' cellpadding='0' cellspacing='0' style='background:#fff;border-radius:12px;'>";
293
- html += "<tr><td style='padding:32px;text-align:center;'>";
294
- html += "<div style='font-size:48px;'>🦞</div>";
295
- html += "<h1 style='margin:16px 0;color:#0a0a0a;'>APIClaw DEBUG</h1>";
296
- html += "<h2 style='margin:0 0 16px;font-size:20px;color:#0a0a0a;'>Debug Email Test</h2>";
297
- html += "<p style='margin:0 0 24px;color:#525252;'>This is a debug test email.</p>";
298
- html += "<a href='" + testUrl + "' style='display:inline-block;background:#ef4444;color:white;padding:14px 32px;border-radius:8px;text-decoration:none;font-weight:600;'>Test Link</a>";
299
- html += "</td></tr></table>";
300
- html += "</td></tr></table></body></html>";
301
-
302
- console.log("[Debug] HTML length:", html.length);
303
- console.log("[Debug] HTML:", html);
304
-
305
- const response = await fetch("https://api.resend.com/emails", {
306
- method: "POST",
307
- headers: {
308
- "Authorization": "Bearer " + RESEND_API_KEY,
309
- "Content-Type": "application/json",
310
- },
311
- body: JSON.stringify({
312
- from: "APIClaw <noreply@apiclaw.cloud>",
313
- to: email,
314
- subject: "DEBUG EMAIL FROM CONVEX",
315
- html: html,
316
- }),
317
- });
318
-
319
- const result = await response.text();
320
- console.log("[Debug] Response:", response.status, result);
321
-
322
- return {
323
- htmlLength: html.length,
324
- htmlPreview: html.substring(0, 200),
325
- resendStatus: response.status,
326
- resendResult: result
327
- };
328
- },
329
- });
@@ -1,265 +0,0 @@
1
- import { v } from "convex/values";
2
- import { mutation, query } from "./_generated/server";
3
-
4
- // ============================================
5
- // SUBMIT FEEDBACK
6
- // ============================================
7
-
8
- export const submitFeedback = mutation({
9
- args: {
10
- token: v.string(),
11
- type: v.union(v.literal("bug"), v.literal("feature"), v.literal("general")),
12
- content: v.string(),
13
- },
14
- handler: async (ctx, args) => {
15
- // Verify session
16
- const session = await ctx.db
17
- .query("agentSessions")
18
- .withIndex("by_sessionToken", (q) => q.eq("sessionToken", args.token))
19
- .first();
20
-
21
- if (!session) {
22
- throw new Error("Invalid session");
23
- }
24
-
25
- // Create feedback entry
26
- const feedbackId = await ctx.db.insert("feedback", {
27
- workspaceId: session.workspaceId,
28
- type: args.type,
29
- content: args.content,
30
- votes: 0,
31
- votedBy: [],
32
- status: "new",
33
- createdAt: Date.now(),
34
- });
35
-
36
- return { success: true, feedbackId };
37
- },
38
- });
39
-
40
- // ============================================
41
- // VOTE ON FEEDBACK
42
- // ============================================
43
-
44
- export const voteFeedback = mutation({
45
- args: {
46
- token: v.string(),
47
- feedbackId: v.id("feedback"),
48
- direction: v.union(v.literal("up"), v.literal("down")),
49
- },
50
- handler: async (ctx, args) => {
51
- // Verify session
52
- const session = await ctx.db
53
- .query("agentSessions")
54
- .withIndex("by_sessionToken", (q) => q.eq("sessionToken", args.token))
55
- .first();
56
-
57
- if (!session) {
58
- throw new Error("Invalid session");
59
- }
60
-
61
- // Get feedback
62
- const feedback = await ctx.db.get(args.feedbackId);
63
- if (!feedback) {
64
- throw new Error("Feedback not found");
65
- }
66
-
67
- const workspaceIdStr = session.workspaceId.toString();
68
- const hasVoted = feedback.votedBy.includes(workspaceIdStr);
69
-
70
- // Calculate new vote count and votedBy array
71
- let newVotes = feedback.votes;
72
- let newVotedBy = [...feedback.votedBy];
73
-
74
- if (args.direction === "up") {
75
- if (hasVoted) {
76
- // Already voted, remove vote
77
- newVotes -= 1;
78
- newVotedBy = newVotedBy.filter((id) => id !== workspaceIdStr);
79
- } else {
80
- // Add upvote
81
- newVotes += 1;
82
- newVotedBy.push(workspaceIdStr);
83
- }
84
- } else {
85
- // Downvote
86
- if (hasVoted) {
87
- // Already voted up, switch to down (remove 2)
88
- newVotes -= 2;
89
- newVotedBy = newVotedBy.filter((id) => id !== workspaceIdStr);
90
- } else {
91
- // Downvote
92
- newVotes -= 1;
93
- }
94
- }
95
-
96
- // Update feedback
97
- await ctx.db.patch(args.feedbackId, {
98
- votes: newVotes,
99
- votedBy: newVotedBy,
100
- });
101
-
102
- return { success: true, votes: newVotes, hasVoted: newVotedBy.includes(workspaceIdStr) };
103
- },
104
- });
105
-
106
- // ============================================
107
- // GET FEEDBACK (with filters and sorting)
108
- // ============================================
109
-
110
- export const getFeedback = query({
111
- args: {
112
- token: v.string(),
113
- filterType: v.optional(v.union(v.literal("bug"), v.literal("feature"), v.literal("general"))),
114
- filterStatus: v.optional(v.union(v.literal("new"), v.literal("reviewing"), v.literal("planned"), v.literal("shipped"))),
115
- sortBy: v.optional(v.union(v.literal("votes"), v.literal("recent"))),
116
- limit: v.optional(v.number()),
117
- },
118
- handler: async (ctx, args) => {
119
- // Verify session
120
- const session = await ctx.db
121
- .query("agentSessions")
122
- .withIndex("by_sessionToken", (q) => q.eq("sessionToken", args.token))
123
- .first();
124
-
125
- if (!session) {
126
- return { error: "Invalid session" };
127
- }
128
-
129
- const workspaceIdStr = session.workspaceId.toString();
130
- const limit = args.limit || 50;
131
-
132
- // Get all feedback
133
- let feedbackList = await ctx.db.query("feedback").collect();
134
-
135
- // Apply filters
136
- if (args.filterType) {
137
- feedbackList = feedbackList.filter((f) => f.type === args.filterType);
138
- }
139
- if (args.filterStatus) {
140
- feedbackList = feedbackList.filter((f) => f.status === args.filterStatus);
141
- }
142
-
143
- // Sort
144
- if (args.sortBy === "votes" || !args.sortBy) {
145
- feedbackList.sort((a, b) => b.votes - a.votes);
146
- } else if (args.sortBy === "recent") {
147
- feedbackList.sort((a, b) => b.createdAt - a.createdAt);
148
- }
149
-
150
- // Limit
151
- feedbackList = feedbackList.slice(0, limit);
152
-
153
- // Add hasVoted flag for current user
154
- const result = feedbackList.map((f) => ({
155
- ...f,
156
- hasVoted: f.votedBy.includes(workspaceIdStr),
157
- isOwn: f.workspaceId.toString() === workspaceIdStr,
158
- }));
159
-
160
- return { feedback: result };
161
- },
162
- });
163
-
164
- // ============================================
165
- // GET MY FEEDBACK
166
- // ============================================
167
-
168
- export const getMyFeedback = query({
169
- args: {
170
- token: v.string(),
171
- },
172
- handler: async (ctx, args) => {
173
- // Verify session
174
- const session = await ctx.db
175
- .query("agentSessions")
176
- .withIndex("by_sessionToken", (q) => q.eq("sessionToken", args.token))
177
- .first();
178
-
179
- if (!session) {
180
- return { error: "Invalid session" };
181
- }
182
-
183
- const feedbackList = await ctx.db
184
- .query("feedback")
185
- .withIndex("by_workspaceId", (q) => q.eq("workspaceId", session.workspaceId))
186
- .collect();
187
-
188
- // Sort by created date (most recent first)
189
- feedbackList.sort((a, b) => b.createdAt - a.createdAt);
190
-
191
- return { feedback: feedbackList };
192
- },
193
- });
194
-
195
- // ============================================
196
- // ADMIN: UPDATE FEEDBACK STATUS
197
- // ============================================
198
-
199
- export const updateFeedbackStatus = mutation({
200
- args: {
201
- token: v.string(),
202
- feedbackId: v.id("feedback"),
203
- status: v.union(v.literal("new"), v.literal("reviewing"), v.literal("planned"), v.literal("shipped")),
204
- },
205
- handler: async (ctx, args) => {
206
- // Verify session
207
- const session = await ctx.db
208
- .query("agentSessions")
209
- .withIndex("by_sessionToken", (q) => q.eq("sessionToken", args.token))
210
- .first();
211
-
212
- if (!session) {
213
- throw new Error("Invalid session");
214
- }
215
-
216
- // For now, allow workspace owners to update status
217
- // In future, add admin check
218
- const feedback = await ctx.db.get(args.feedbackId);
219
- if (!feedback) {
220
- throw new Error("Feedback not found");
221
- }
222
-
223
- await ctx.db.patch(args.feedbackId, {
224
- status: args.status,
225
- });
226
-
227
- return { success: true };
228
- },
229
- });
230
-
231
- // ============================================
232
- // DELETE FEEDBACK (own only)
233
- // ============================================
234
-
235
- export const deleteFeedback = mutation({
236
- args: {
237
- token: v.string(),
238
- feedbackId: v.id("feedback"),
239
- },
240
- handler: async (ctx, args) => {
241
- // Verify session
242
- const session = await ctx.db
243
- .query("agentSessions")
244
- .withIndex("by_sessionToken", (q) => q.eq("sessionToken", args.token))
245
- .first();
246
-
247
- if (!session) {
248
- throw new Error("Invalid session");
249
- }
250
-
251
- const feedback = await ctx.db.get(args.feedbackId);
252
- if (!feedback) {
253
- throw new Error("Feedback not found");
254
- }
255
-
256
- // Only allow owner to delete
257
- if (feedback.workspaceId.toString() !== session.workspaceId.toString()) {
258
- throw new Error("Not authorized");
259
- }
260
-
261
- await ctx.db.delete(args.feedbackId);
262
-
263
- return { success: true };
264
- },
265
- });