@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.
Files changed (145) hide show
  1. package/README.md +4 -4
  2. package/apiclaw-README.md +12 -12
  3. package/convex/_generated/api.d.ts +16 -0
  4. package/convex/analytics.d.ts.map +1 -1
  5. package/convex/analytics.js.map +1 -1
  6. package/convex/analytics.ts +1 -0
  7. package/convex/apiKeys.ts +220 -0
  8. package/convex/backfillAnalytics.d.ts.map +1 -0
  9. package/convex/backfillAnalytics.js.map +1 -0
  10. package/convex/backfillAnalytics.ts +22 -0
  11. package/convex/backfillSearchLogs.d.ts.map +1 -0
  12. package/convex/backfillSearchLogs.js.map +1 -0
  13. package/convex/backfillSearchLogs.ts +35 -0
  14. package/convex/debugFilestackLogs.d.ts.map +1 -0
  15. package/convex/debugFilestackLogs.js.map +1 -0
  16. package/convex/debugFilestackLogs.ts +16 -0
  17. package/convex/debugGetToken.d.ts.map +1 -0
  18. package/convex/debugGetToken.js.map +1 -0
  19. package/convex/debugGetToken.ts +18 -0
  20. package/convex/directCall.ts +49 -14
  21. package/convex/email.ts +5 -5
  22. package/convex/http.d.ts.map +1 -1
  23. package/convex/http.js.map +1 -1
  24. package/convex/http.ts +611 -49
  25. package/convex/logs.ts +26 -22
  26. package/convex/migrateFilestack.d.ts.map +1 -1
  27. package/convex/migrateFilestack.js.map +1 -1
  28. package/convex/migrateFilestack.ts +65 -101
  29. package/convex/migratePartnersProd.d.ts.map +1 -0
  30. package/convex/migratePartnersProd.js.map +1 -0
  31. package/convex/migratePartnersProd.ts +174 -0
  32. package/convex/migrateProviderWorkspaces.d.ts.map +1 -0
  33. package/convex/migrateProviderWorkspaces.js.map +1 -0
  34. package/convex/migrateProviderWorkspaces.ts +175 -0
  35. package/convex/providers.js.map +1 -1
  36. package/convex/providers.ts +313 -203
  37. package/convex/schema.ts +50 -1
  38. package/convex/searchLogs.d.ts.map +1 -1
  39. package/convex/searchLogs.js.map +1 -1
  40. package/convex/searchLogs.ts +11 -3
  41. package/convex/seedPratham.ts +1 -1
  42. package/convex/spendAlerts.ts +2 -2
  43. package/convex/stripeActions.ts +1 -1
  44. package/convex/updateAPIStatus.ts +2 -3
  45. package/convex/workspaceSettings.ts +136 -0
  46. package/dist/bin-http.js +0 -0
  47. package/dist/bin.js +0 -0
  48. package/dist/cli/commands/demo.js +2 -2
  49. package/dist/cli/commands/doctor.js +1 -1
  50. package/dist/cli/commands/login.js +1 -1
  51. package/dist/cli/commands/setup.js +2 -2
  52. package/dist/discovery.js +1 -1
  53. package/dist/execute.js +3 -3
  54. package/dist/index.js +13 -13
  55. package/dist/registry/apis.json +1 -1
  56. package/dist/ui/errors.js +16 -16
  57. package/dist/ui/prompts.js +1 -1
  58. package/email-templates/filestack-provider-outreach.html +1 -1
  59. package/email-templates/partnership-template.html +1 -1
  60. package/email-templates/pratham-partnership-draft.html +2 -2
  61. package/package.json +2 -2
  62. package/reports/APIClaw-Session-Report-2026-04-05.pdf +0 -0
  63. package/reports/session-report-2026-04-05.html +433 -0
  64. package/src/cli/commands/demo.ts +2 -2
  65. package/src/cli/commands/doctor.ts +1 -1
  66. package/src/cli/commands/login.ts +1 -1
  67. package/src/cli/commands/setup.ts +2 -2
  68. package/src/discovery.ts +1 -1
  69. package/src/execute.ts +3 -3
  70. package/src/index.ts +14 -14
  71. package/src/registry/apis.json +1 -1
  72. package/src/ui/errors.ts +16 -16
  73. package/src/ui/prompts.ts +1 -1
  74. package/convex/adminActivate.d.ts +0 -3
  75. package/convex/adminActivate.js +0 -47
  76. package/convex/adminStats.d.ts +0 -9
  77. package/convex/adminStats.js +0 -280
  78. package/convex/agents.d.ts +0 -84
  79. package/convex/agents.js +0 -809
  80. package/convex/analytics.d.ts +0 -5
  81. package/convex/analytics.js +0 -166
  82. package/convex/billing.d.ts +0 -88
  83. package/convex/billing.js +0 -655
  84. package/convex/capabilities.d.ts +0 -9
  85. package/convex/capabilities.js +0 -145
  86. package/convex/chains.d.ts +0 -68
  87. package/convex/chains.js +0 -1105
  88. package/convex/credits.d.ts +0 -25
  89. package/convex/credits.js +0 -186
  90. package/convex/crons.d.ts +0 -3
  91. package/convex/crons.js +0 -17
  92. package/convex/directCall.d.ts +0 -72
  93. package/convex/directCall.js +0 -627
  94. package/convex/earnProgress.d.ts +0 -58
  95. package/convex/earnProgress.js +0 -649
  96. package/convex/email.d.ts +0 -14
  97. package/convex/email.js +0 -300
  98. package/convex/feedback.d.ts +0 -7
  99. package/convex/feedback.js +0 -227
  100. package/convex/http.d.ts +0 -3
  101. package/convex/http.js +0 -1405
  102. package/convex/inbound.d.ts +0 -2
  103. package/convex/inbound.js +0 -32
  104. package/convex/logs.d.ts +0 -48
  105. package/convex/logs.js +0 -621
  106. package/convex/migrateFilestack.d.ts +0 -2
  107. package/convex/migrateFilestack.js +0 -113
  108. package/convex/migratePratham.d.ts +0 -2
  109. package/convex/migratePratham.js +0 -121
  110. package/convex/mou.d.ts +0 -6
  111. package/convex/mou.js +0 -82
  112. package/convex/providerKeys.d.ts +0 -31
  113. package/convex/providerKeys.js +0 -257
  114. package/convex/providers.d.ts +0 -35
  115. package/convex/providers.js +0 -922
  116. package/convex/purchases.d.ts +0 -7
  117. package/convex/purchases.js +0 -157
  118. package/convex/ratelimit.d.ts +0 -4
  119. package/convex/ratelimit.js +0 -91
  120. package/convex/searchLogs.d.ts +0 -13
  121. package/convex/searchLogs.js +0 -232
  122. package/convex/seedAPILayerAPIs.d.ts +0 -7
  123. package/convex/seedAPILayerAPIs.js +0 -177
  124. package/convex/seedDirectCallConfigs.d.ts +0 -2
  125. package/convex/seedDirectCallConfigs.js +0 -324
  126. package/convex/seedPratham.d.ts +0 -6
  127. package/convex/seedPratham.js +0 -150
  128. package/convex/spendAlerts.d.ts +0 -36
  129. package/convex/spendAlerts.js +0 -380
  130. package/convex/stripeActions.d.ts +0 -19
  131. package/convex/stripeActions.js +0 -411
  132. package/convex/teams.d.ts +0 -21
  133. package/convex/teams.js +0 -215
  134. package/convex/telemetry.d.ts +0 -4
  135. package/convex/telemetry.js +0 -74
  136. package/convex/updateAPIStatus.d.ts +0 -6
  137. package/convex/updateAPIStatus.js +0 -40
  138. package/convex/usage.d.ts +0 -27
  139. package/convex/usage.js +0 -229
  140. package/convex/waitlist.d.ts +0 -4
  141. package/convex/waitlist.js +0 -49
  142. package/convex/webhooks.d.ts +0 -12
  143. package/convex/webhooks.js +0 -410
  144. package/convex/workspaces.d.ts +0 -33
  145. package/convex/workspaces.js +0 -991
package/convex/email.js DELETED
@@ -1,300 +0,0 @@
1
- import { v } from "convex/values";
2
- import { action } from "./_generated/server";
3
- // ============================================
4
- // EMAIL TEMPLATES
5
- // ============================================
6
- const EMAIL_FROM = "APIClaw <noreply@apiclaw.nordsym.com>";
7
- const APP_URL = "https://apiclaw.nordsym.com";
8
- // Base email wrapper - using string concat for Convex compatibility
9
- function wrapEmail(content) {
10
- const year = new Date().getFullYear();
11
- return [
12
- '<!DOCTYPE html>',
13
- '<html>',
14
- '<head>',
15
- '<meta charset="utf-8">',
16
- '<meta name="viewport" content="width=device-width, initial-scale=1.0">',
17
- '</head>',
18
- '<body style="margin: 0; padding: 0; background-color: #f5f5f5; font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial, sans-serif;">',
19
- '<table width="100%" cellpadding="0" cellspacing="0" style="background-color: #f5f5f5; padding: 40px 20px;">',
20
- '<tr>',
21
- '<td align="center">',
22
- '<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);">',
23
- '<tr>',
24
- '<td style="padding: 32px 32px 24px; text-align: center; border-bottom: 1px solid #f0f0f0;">',
25
- '<span style="font-size: 48px;">🦞</span>',
26
- '<h1 style="margin: 16px 0 0; font-size: 24px; font-weight: 700; color: #0a0a0a;">APIClaw</h1>',
27
- '</td>',
28
- '</tr>',
29
- '<tr>',
30
- '<td style="padding: 32px;">',
31
- content,
32
- '</td>',
33
- '</tr>',
34
- '<tr>',
35
- '<td style="padding: 24px 32px; background-color: #fafafa; border-top: 1px solid #f0f0f0;">',
36
- '<p style="margin: 0; font-size: 12px; color: #737373; text-align: center;">',
37
- '<a href="https://apiclaw.nordsym.com" style="color: #ef4444; text-decoration: none;">APIClaw</a> — The API Layer for AI Agents',
38
- '</p>',
39
- '<p style="margin: 8px 0 0; font-size: 12px; color: #a3a3a3; text-align: center;">',
40
- '© ' + year + ' NordSym. Stockholm, Sweden.',
41
- '</p>',
42
- '</td>',
43
- '</tr>',
44
- '</table>',
45
- '</td>',
46
- '</tr>',
47
- '</table>',
48
- '</body>',
49
- '</html>',
50
- ].join('');
51
- }
52
- // Magic link email template - ultra simple for Convex
53
- function magicLinkEmailTemplate(verifyUrl) {
54
- // Simple inline HTML - no arrays, no template literals
55
- var html = "<!DOCTYPE html><html><head><meta charset='utf-8'></head>";
56
- html += "<body style='margin:0;padding:40px;background:#f5f5f5;font-family:Arial,sans-serif;'>";
57
- html += "<table width='100%' cellpadding='0' cellspacing='0'><tr><td align='center'>";
58
- html += "<table width='500' cellpadding='0' cellspacing='0' style='background:#fff;border-radius:12px;'>";
59
- html += "<tr><td style='padding:32px;text-align:center;'>";
60
- html += "<div style='font-size:48px;'>🦞</div>";
61
- html += "<h1 style='margin:16px 0;color:#0a0a0a;'>APIClaw</h1>";
62
- html += "<h2 style='margin:0 0 16px;font-size:20px;color:#0a0a0a;'>An AI Agent Wants to Connect</h2>";
63
- html += "<p style='margin:0 0 24px;color:#525252;'>Click below to verify your email and activate your workspace.</p>";
64
- 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>";
65
- html += "<p style='margin:24px 0 0;font-size:13px;color:#737373;'>Free tier: 50 API calls. This link expires in 1 hour.</p>";
66
- html += "</td></tr></table>";
67
- html += "</td></tr></table></body></html>";
68
- return html;
69
- }
70
- // Reminder email template
71
- function reminderEmailTemplate(verifyUrl) {
72
- return wrapEmail(`
73
- <h2 style="margin: 0 0 16px; font-size: 20px; font-weight: 600; color: #0a0a0a; text-align: center;">
74
- Still Waiting for You 👋
75
- </h2>
76
-
77
- <p style="margin: 0 0 24px; font-size: 16px; line-height: 1.6; color: #525252; text-align: center;">
78
- Your AI agent is patiently waiting for you to verify your email.
79
- Click below to activate your workspace and let it get to work!
80
- </p>
81
-
82
- <table width="100%" cellpadding="0" cellspacing="0">
83
- <tr>
84
- <td align="center" style="padding: 8px 0 24px;">
85
- <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;">
86
- Verify & Get Started
87
- </a>
88
- </td>
89
- </tr>
90
- </table>
91
-
92
- <p style="margin: 0; font-size: 13px; color: #737373; text-align: center;">
93
- This link expires in 1 hour.
94
- </p>
95
- `);
96
- }
97
- // Limit reached email template
98
- function limitReachedEmailTemplate(upgradeUrl) {
99
- return wrapEmail(`
100
- <h2 style="margin: 0 0 16px; font-size: 20px; font-weight: 600; color: #0a0a0a; text-align: center;">
101
- Free Tier Limit Reached
102
- </h2>
103
-
104
- <p style="margin: 0 0 24px; font-size: 16px; line-height: 1.6; color: #525252; text-align: center;">
105
- Your AI agent has used all 100 free API calls. Add a payment method to continue using APIClaw.
106
- </p>
107
-
108
- <div style="background: #f5f5f5; border-radius: 8px; padding: 20px; margin-bottom: 24px;">
109
- <p style="margin: 0 0 8px; font-size: 14px; font-weight: 600; color: #0a0a0a;">Pro Plan — $10/month</p>
110
- <ul style="margin: 0; padding: 0 0 0 20px; font-size: 14px; color: #525252; line-height: 1.8;">
111
- <li>10,000 API calls/month</li>
112
- <li>Priority support</li>
113
- <li>Usage analytics</li>
114
- </ul>
115
- </div>
116
-
117
- <table width="100%" cellpadding="0" cellspacing="0">
118
- <tr>
119
- <td align="center" style="padding: 8px 0 24px;">
120
- <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;">
121
- Upgrade Now
122
- </a>
123
- </td>
124
- </tr>
125
- </table>
126
-
127
- <p style="margin: 0; font-size: 13px; color: #737373; text-align: center;">
128
- Questions? Reply to this email.
129
- </p>
130
- `);
131
- }
132
- // ============================================
133
- // EMAIL SENDING ACTIONS
134
- // ============================================
135
- /**
136
- * Send magic link email
137
- */
138
- export const sendMagicLinkEmail = action({
139
- args: {
140
- email: v.string(),
141
- token: v.string(),
142
- },
143
- handler: async (ctx, args) => {
144
- const RESEND_API_KEY = process.env.RESEND_API_KEY;
145
- if (!RESEND_API_KEY) {
146
- throw new Error("RESEND_API_KEY not configured");
147
- }
148
- var verifyUrl = APP_URL + "/auth/verify?token=" + args.token;
149
- // Generate HTML inline (same approach as debug that works)
150
- var html = "<!DOCTYPE html><html><head><meta charset='utf-8'></head>";
151
- html += "<body style='margin:0;padding:40px;background:#f5f5f5;font-family:Arial,sans-serif;'>";
152
- html += "<table width='100%' cellpadding='0' cellspacing='0'><tr><td align='center'>";
153
- html += "<table width='500' cellpadding='0' cellspacing='0' style='background:#fff;border-radius:12px;'>";
154
- html += "<tr><td style='padding:32px;text-align:center;'>";
155
- html += "<div style='font-size:48px;'>🦞</div>";
156
- html += "<h1 style='margin:16px 0;color:#0a0a0a;'>APIClaw</h1>";
157
- html += "<h2 style='margin:0 0 16px;font-size:20px;color:#0a0a0a;'>An AI Agent Wants to Connect</h2>";
158
- html += "<p style='margin:0 0 24px;color:#525252;'>Click below to verify your email and activate your workspace.</p>";
159
- 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>";
160
- html += "<p style='margin:24px 0 0;font-size:13px;color:#737373;'>Free tier: 50 API calls. This link expires in 1 hour.</p>";
161
- html += "</td></tr></table>";
162
- html += "</td></tr></table></body></html>";
163
- var textContent = "APIClaw - An AI Agent Wants to Connect\n\n";
164
- textContent += "Click the link: " + verifyUrl + "\n\n";
165
- textContent += "Free tier: 50 API calls. Expires in 1 hour.";
166
- var response = await fetch("https://api.resend.com/emails", {
167
- method: "POST",
168
- headers: {
169
- "Authorization": "Bearer " + RESEND_API_KEY,
170
- "Content-Type": "application/json",
171
- },
172
- body: JSON.stringify({
173
- from: EMAIL_FROM,
174
- to: args.email,
175
- subject: "🦞 An AI Agent Wants to Connect — Verify Your Email",
176
- html: html,
177
- text: textContent,
178
- }),
179
- });
180
- if (!response.ok) {
181
- var errorText = await response.text();
182
- throw new Error("Failed to send email: " + errorText);
183
- }
184
- return { success: true };
185
- },
186
- });
187
- /**
188
- * Send reminder email
189
- */
190
- export const sendReminderEmail = action({
191
- args: {
192
- email: v.string(),
193
- token: v.string(),
194
- },
195
- handler: async (ctx, args) => {
196
- const RESEND_API_KEY = process.env.RESEND_API_KEY;
197
- if (!RESEND_API_KEY) {
198
- throw new Error("RESEND_API_KEY not configured");
199
- }
200
- const verifyUrl = `${APP_URL}/auth/verify?token=${args.token}`;
201
- const html = reminderEmailTemplate(verifyUrl);
202
- const response = await fetch("https://api.resend.com/emails", {
203
- method: "POST",
204
- headers: {
205
- "Authorization": `Bearer ${RESEND_API_KEY}`,
206
- "Content-Type": "application/json",
207
- },
208
- body: JSON.stringify({
209
- from: EMAIL_FROM,
210
- to: args.email,
211
- subject: "🦞 Your Agent is Still Waiting — Verify Your Email",
212
- html,
213
- }),
214
- });
215
- if (!response.ok) {
216
- const error = await response.text();
217
- throw new Error(`Failed to send email: ${error}`);
218
- }
219
- return { success: true };
220
- },
221
- });
222
- /**
223
- * Send limit reached email
224
- */
225
- export const sendLimitReachedEmail = action({
226
- args: {
227
- email: v.string(),
228
- },
229
- handler: async (ctx, args) => {
230
- const RESEND_API_KEY = process.env.RESEND_API_KEY;
231
- if (!RESEND_API_KEY) {
232
- throw new Error("RESEND_API_KEY not configured");
233
- }
234
- const upgradeUrl = `${APP_URL}/upgrade`;
235
- const html = limitReachedEmailTemplate(upgradeUrl);
236
- const response = await fetch("https://api.resend.com/emails", {
237
- method: "POST",
238
- headers: {
239
- "Authorization": `Bearer ${RESEND_API_KEY}`,
240
- "Content-Type": "application/json",
241
- },
242
- body: JSON.stringify({
243
- from: EMAIL_FROM,
244
- to: args.email,
245
- subject: "🦞 Free Tier Limit Reached — Upgrade to Continue",
246
- html,
247
- }),
248
- });
249
- if (!response.ok) {
250
- const error = await response.text();
251
- throw new Error(`Failed to send email: ${error}`);
252
- }
253
- return { success: true };
254
- },
255
- });
256
- // Debug: Test email template generation
257
- export const debugEmailTemplate = action({
258
- args: { email: v.string() },
259
- handler: async (ctx, { email }) => {
260
- const RESEND_API_KEY = process.env.RESEND_API_KEY;
261
- const testUrl = "https://apiclaw.nordsym.com/auth/verify?token=DEBUG_TEST";
262
- // Generate HTML using the template
263
- var html = "<!DOCTYPE html><html><head><meta charset='utf-8'></head>";
264
- html += "<body style='margin:0;padding:40px;background:#f5f5f5;font-family:Arial,sans-serif;'>";
265
- html += "<table width='100%' cellpadding='0' cellspacing='0'><tr><td align='center'>";
266
- html += "<table width='500' cellpadding='0' cellspacing='0' style='background:#fff;border-radius:12px;'>";
267
- html += "<tr><td style='padding:32px;text-align:center;'>";
268
- html += "<div style='font-size:48px;'>🦞</div>";
269
- html += "<h1 style='margin:16px 0;color:#0a0a0a;'>APIClaw DEBUG</h1>";
270
- html += "<h2 style='margin:0 0 16px;font-size:20px;color:#0a0a0a;'>Debug Email Test</h2>";
271
- html += "<p style='margin:0 0 24px;color:#525252;'>This is a debug test email.</p>";
272
- 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>";
273
- html += "</td></tr></table>";
274
- html += "</td></tr></table></body></html>";
275
- console.log("[Debug] HTML length:", html.length);
276
- console.log("[Debug] HTML:", html);
277
- const response = await fetch("https://api.resend.com/emails", {
278
- method: "POST",
279
- headers: {
280
- "Authorization": "Bearer " + RESEND_API_KEY,
281
- "Content-Type": "application/json",
282
- },
283
- body: JSON.stringify({
284
- from: "APIClaw <noreply@apiclaw.nordsym.com>",
285
- to: email,
286
- subject: "DEBUG EMAIL FROM CONVEX",
287
- html: html,
288
- }),
289
- });
290
- const result = await response.text();
291
- console.log("[Debug] Response:", response.status, result);
292
- return {
293
- htmlLength: html.length,
294
- htmlPreview: html.substring(0, 200),
295
- resendStatus: response.status,
296
- resendResult: result
297
- };
298
- },
299
- });
300
- //# sourceMappingURL=email.js.map
@@ -1,7 +0,0 @@
1
- export declare const submitFeedback: any;
2
- export declare const voteFeedback: any;
3
- export declare const getFeedback: any;
4
- export declare const getMyFeedback: any;
5
- export declare const updateFeedbackStatus: any;
6
- export declare const deleteFeedback: any;
7
- //# sourceMappingURL=feedback.d.ts.map
@@ -1,227 +0,0 @@
1
- import { v } from "convex/values";
2
- import { mutation, query } from "./_generated/server";
3
- // ============================================
4
- // SUBMIT FEEDBACK
5
- // ============================================
6
- export const submitFeedback = mutation({
7
- args: {
8
- token: v.string(),
9
- type: v.union(v.literal("bug"), v.literal("feature"), v.literal("general")),
10
- content: v.string(),
11
- },
12
- handler: async (ctx, args) => {
13
- // Verify session
14
- const session = await ctx.db
15
- .query("agentSessions")
16
- .withIndex("by_sessionToken", (q) => q.eq("sessionToken", args.token))
17
- .first();
18
- if (!session) {
19
- throw new Error("Invalid session");
20
- }
21
- // Create feedback entry
22
- const feedbackId = await ctx.db.insert("feedback", {
23
- workspaceId: session.workspaceId,
24
- type: args.type,
25
- content: args.content,
26
- votes: 0,
27
- votedBy: [],
28
- status: "new",
29
- createdAt: Date.now(),
30
- });
31
- return { success: true, feedbackId };
32
- },
33
- });
34
- // ============================================
35
- // VOTE ON FEEDBACK
36
- // ============================================
37
- export const voteFeedback = mutation({
38
- args: {
39
- token: v.string(),
40
- feedbackId: v.id("feedback"),
41
- direction: v.union(v.literal("up"), v.literal("down")),
42
- },
43
- handler: async (ctx, args) => {
44
- // Verify session
45
- const session = await ctx.db
46
- .query("agentSessions")
47
- .withIndex("by_sessionToken", (q) => q.eq("sessionToken", args.token))
48
- .first();
49
- if (!session) {
50
- throw new Error("Invalid session");
51
- }
52
- // Get feedback
53
- const feedback = await ctx.db.get(args.feedbackId);
54
- if (!feedback) {
55
- throw new Error("Feedback not found");
56
- }
57
- const workspaceIdStr = session.workspaceId.toString();
58
- const hasVoted = feedback.votedBy.includes(workspaceIdStr);
59
- // Calculate new vote count and votedBy array
60
- let newVotes = feedback.votes;
61
- let newVotedBy = [...feedback.votedBy];
62
- if (args.direction === "up") {
63
- if (hasVoted) {
64
- // Already voted, remove vote
65
- newVotes -= 1;
66
- newVotedBy = newVotedBy.filter((id) => id !== workspaceIdStr);
67
- }
68
- else {
69
- // Add upvote
70
- newVotes += 1;
71
- newVotedBy.push(workspaceIdStr);
72
- }
73
- }
74
- else {
75
- // Downvote
76
- if (hasVoted) {
77
- // Already voted up, switch to down (remove 2)
78
- newVotes -= 2;
79
- newVotedBy = newVotedBy.filter((id) => id !== workspaceIdStr);
80
- }
81
- else {
82
- // Downvote
83
- newVotes -= 1;
84
- }
85
- }
86
- // Update feedback
87
- await ctx.db.patch(args.feedbackId, {
88
- votes: newVotes,
89
- votedBy: newVotedBy,
90
- });
91
- return { success: true, votes: newVotes, hasVoted: newVotedBy.includes(workspaceIdStr) };
92
- },
93
- });
94
- // ============================================
95
- // GET FEEDBACK (with filters and sorting)
96
- // ============================================
97
- export const getFeedback = query({
98
- args: {
99
- token: v.string(),
100
- filterType: v.optional(v.union(v.literal("bug"), v.literal("feature"), v.literal("general"))),
101
- filterStatus: v.optional(v.union(v.literal("new"), v.literal("reviewing"), v.literal("planned"), v.literal("shipped"))),
102
- sortBy: v.optional(v.union(v.literal("votes"), v.literal("recent"))),
103
- limit: v.optional(v.number()),
104
- },
105
- handler: async (ctx, args) => {
106
- // Verify session
107
- const session = await ctx.db
108
- .query("agentSessions")
109
- .withIndex("by_sessionToken", (q) => q.eq("sessionToken", args.token))
110
- .first();
111
- if (!session) {
112
- return { error: "Invalid session" };
113
- }
114
- const workspaceIdStr = session.workspaceId.toString();
115
- const limit = args.limit || 50;
116
- // Get all feedback
117
- let feedbackList = await ctx.db.query("feedback").collect();
118
- // Apply filters
119
- if (args.filterType) {
120
- feedbackList = feedbackList.filter((f) => f.type === args.filterType);
121
- }
122
- if (args.filterStatus) {
123
- feedbackList = feedbackList.filter((f) => f.status === args.filterStatus);
124
- }
125
- // Sort
126
- if (args.sortBy === "votes" || !args.sortBy) {
127
- feedbackList.sort((a, b) => b.votes - a.votes);
128
- }
129
- else if (args.sortBy === "recent") {
130
- feedbackList.sort((a, b) => b.createdAt - a.createdAt);
131
- }
132
- // Limit
133
- feedbackList = feedbackList.slice(0, limit);
134
- // Add hasVoted flag for current user
135
- const result = feedbackList.map((f) => ({
136
- ...f,
137
- hasVoted: f.votedBy.includes(workspaceIdStr),
138
- isOwn: f.workspaceId.toString() === workspaceIdStr,
139
- }));
140
- return { feedback: result };
141
- },
142
- });
143
- // ============================================
144
- // GET MY FEEDBACK
145
- // ============================================
146
- export const getMyFeedback = query({
147
- args: {
148
- token: v.string(),
149
- },
150
- handler: async (ctx, args) => {
151
- // Verify session
152
- const session = await ctx.db
153
- .query("agentSessions")
154
- .withIndex("by_sessionToken", (q) => q.eq("sessionToken", args.token))
155
- .first();
156
- if (!session) {
157
- return { error: "Invalid session" };
158
- }
159
- const feedbackList = await ctx.db
160
- .query("feedback")
161
- .withIndex("by_workspaceId", (q) => q.eq("workspaceId", session.workspaceId))
162
- .collect();
163
- // Sort by created date (most recent first)
164
- feedbackList.sort((a, b) => b.createdAt - a.createdAt);
165
- return { feedback: feedbackList };
166
- },
167
- });
168
- // ============================================
169
- // ADMIN: UPDATE FEEDBACK STATUS
170
- // ============================================
171
- export const updateFeedbackStatus = mutation({
172
- args: {
173
- token: v.string(),
174
- feedbackId: v.id("feedback"),
175
- status: v.union(v.literal("new"), v.literal("reviewing"), v.literal("planned"), v.literal("shipped")),
176
- },
177
- handler: async (ctx, args) => {
178
- // Verify session
179
- const session = await ctx.db
180
- .query("agentSessions")
181
- .withIndex("by_sessionToken", (q) => q.eq("sessionToken", args.token))
182
- .first();
183
- if (!session) {
184
- throw new Error("Invalid session");
185
- }
186
- // For now, allow workspace owners to update status
187
- // In future, add admin check
188
- const feedback = await ctx.db.get(args.feedbackId);
189
- if (!feedback) {
190
- throw new Error("Feedback not found");
191
- }
192
- await ctx.db.patch(args.feedbackId, {
193
- status: args.status,
194
- });
195
- return { success: true };
196
- },
197
- });
198
- // ============================================
199
- // DELETE FEEDBACK (own only)
200
- // ============================================
201
- export const deleteFeedback = mutation({
202
- args: {
203
- token: v.string(),
204
- feedbackId: v.id("feedback"),
205
- },
206
- handler: async (ctx, args) => {
207
- // Verify session
208
- const session = await ctx.db
209
- .query("agentSessions")
210
- .withIndex("by_sessionToken", (q) => q.eq("sessionToken", args.token))
211
- .first();
212
- if (!session) {
213
- throw new Error("Invalid session");
214
- }
215
- const feedback = await ctx.db.get(args.feedbackId);
216
- if (!feedback) {
217
- throw new Error("Feedback not found");
218
- }
219
- // Only allow owner to delete
220
- if (feedback.workspaceId.toString() !== session.workspaceId.toString()) {
221
- throw new Error("Not authorized");
222
- }
223
- await ctx.db.delete(args.feedbackId);
224
- return { success: true };
225
- },
226
- });
227
- //# sourceMappingURL=feedback.js.map
package/convex/http.d.ts DELETED
@@ -1,3 +0,0 @@
1
- declare const http: import("convex/server").HttpRouter;
2
- export default http;
3
- //# sourceMappingURL=http.d.ts.map