@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,299 +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
- });
@@ -1,226 +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
- });