@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.
- package/README.md +15 -2
- package/dist/bin-http.js +0 -0
- package/dist/bin.bundled.js +79288 -0
- package/dist/gateway-client.d.ts.map +1 -1
- package/dist/gateway-client.js +24 -2
- package/dist/gateway-client.js.map +1 -1
- package/dist/index.bundled.js +61263 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +7 -2
- package/.claude/settings.local.json +0 -13
- package/.env.prod +0 -1
- package/apiclaw-README.md +0 -494
- package/convex/_generated/api.d.ts +0 -145
- package/convex/_generated/api.js +0 -23
- package/convex/_generated/dataModel.d.ts +0 -60
- package/convex/_generated/server.d.ts +0 -143
- package/convex/_generated/server.js +0 -93
- package/convex/_listWorkspaces.ts +0 -13
- package/convex/adminActivate.ts +0 -53
- package/convex/adminStats.ts +0 -306
- package/convex/agents.ts +0 -939
- package/convex/analytics.ts +0 -187
- package/convex/apiKeys.ts +0 -220
- package/convex/backfillAnalytics.ts +0 -272
- package/convex/backfillSearchLogs.ts +0 -35
- package/convex/billing.ts +0 -834
- package/convex/capabilities.ts +0 -157
- package/convex/chains.ts +0 -1318
- package/convex/credits.ts +0 -211
- package/convex/crons.ts +0 -65
- package/convex/debugFilestackLogs.ts +0 -16
- package/convex/debugGetToken.ts +0 -18
- package/convex/directCall.ts +0 -713
- package/convex/earnProgress.ts +0 -753
- package/convex/email.ts +0 -329
- package/convex/feedback.ts +0 -265
- package/convex/funnel.ts +0 -431
- package/convex/guards.ts +0 -174
- package/convex/http.ts +0 -3756
- package/convex/inbound.ts +0 -32
- package/convex/logs.ts +0 -701
- package/convex/migrateFilestack.ts +0 -81
- package/convex/migratePartnersProd.ts +0 -174
- package/convex/migratePratham.ts +0 -126
- package/convex/migrateProviderWorkspaces.ts +0 -175
- package/convex/mou.ts +0 -91
- package/convex/nurture.ts +0 -355
- package/convex/providerKeys.ts +0 -289
- package/convex/providers.ts +0 -1135
- package/convex/purchases.ts +0 -183
- package/convex/ratelimit.ts +0 -104
- package/convex/schema.ts +0 -926
- package/convex/searchLogs.ts +0 -265
- package/convex/seedAPILayerAPIs.ts +0 -191
- package/convex/seedDirectCallConfigs.ts +0 -336
- package/convex/seedPratham.ts +0 -149
- package/convex/spendAlerts.ts +0 -442
- package/convex/stripeActions.ts +0 -607
- package/convex/teams.ts +0 -243
- package/convex/telemetry.ts +0 -81
- package/convex/tsconfig.json +0 -25
- package/convex/updateAPIStatus.ts +0 -44
- package/convex/usage.ts +0 -260
- package/convex/usageReports.ts +0 -357
- package/convex/waitlist.ts +0 -55
- package/convex/webhooks.ts +0 -494
- package/convex/workspaceSettings.ts +0 -143
- package/convex/workspaces.ts +0 -1331
- package/convex.json +0 -3
- package/direct-test.mjs +0 -51
- package/email-templates/filestack-provider-outreach.html +0 -162
- package/email-templates/partnership-template.html +0 -116
- package/email-templates/pratham-draft-preview.txt +0 -57
- package/email-templates/pratham-partnership-draft.html +0 -141
- package/reports/APIClaw-Session-Report-2026-04-05.pdf +0 -0
- package/reports/pipeline/PIPELINE-REPORT.json +0 -153
- package/reports/pipeline/acquire_apisguru.json +0 -17
- package/reports/pipeline/capabilities.json +0 -38
- package/reports/pipeline/discover_azure_recursive.json +0 -1551
- package/reports/pipeline/discover_github.json +0 -25
- package/reports/pipeline/discover_github_repos.json +0 -49
- package/reports/pipeline/discover_swaggerhub.json +0 -24
- package/reports/pipeline/discover_well_known.json +0 -23
- package/reports/pipeline/fetch_specs.json +0 -19
- package/reports/pipeline/generate_providers.json +0 -14
- package/reports/pipeline/match_registry.json +0 -11
- package/reports/pipeline/parse_specs.json +0 -17
- package/reports/pipeline/promote_candidates.json +0 -34
- package/reports/pipeline/validate.json +0 -30
- package/reports/pipeline/validate_smoke_details.json +0 -3835
- package/reports/session-report-2026-04-05.html +0 -433
- package/seed-apis-direct.mjs +0 -106
- package/src/access-control.ts +0 -174
- package/src/adapters/base.ts +0 -364
- package/src/adapters/claude-desktop.ts +0 -41
- package/src/adapters/cline.ts +0 -88
- package/src/adapters/continue.ts +0 -91
- package/src/adapters/cursor.ts +0 -43
- package/src/adapters/custom.ts +0 -188
- package/src/adapters/detect.ts +0 -202
- package/src/adapters/index.ts +0 -47
- package/src/adapters/windsurf.ts +0 -44
- package/src/bin-http.ts +0 -45
- package/src/bin.ts +0 -34
- package/src/capability-router.ts +0 -331
- package/src/chainExecutor.ts +0 -730
- package/src/chainResolver.test.ts +0 -246
- package/src/chainResolver.ts +0 -658
- package/src/cli/commands/demo.ts +0 -109
- package/src/cli/commands/doctor.ts +0 -435
- package/src/cli/commands/index.ts +0 -9
- package/src/cli/commands/login.ts +0 -203
- package/src/cli/commands/mcp-install.ts +0 -373
- package/src/cli/commands/restore.ts +0 -333
- package/src/cli/commands/setup.ts +0 -297
- package/src/cli/commands/uninstall.ts +0 -240
- package/src/cli/index.ts +0 -148
- package/src/cli.ts +0 -370
- package/src/confirmation.ts +0 -296
- package/src/credentials.ts +0 -455
- package/src/credits.ts +0 -329
- package/src/crypto.ts +0 -75
- package/src/discovery.ts +0 -568
- package/src/enterprise/env.ts +0 -156
- package/src/enterprise/index.ts +0 -7
- package/src/enterprise/script-generator.ts +0 -481
- package/src/execute-dynamic.ts +0 -617
- package/src/execute.ts +0 -2386
- package/src/funnel-client.ts +0 -168
- package/src/funnel.test.ts +0 -187
- package/src/gateway-client.ts +0 -192
- package/src/hivr-whitelist.ts +0 -110
- package/src/http-api.ts +0 -286
- package/src/http-server-minimal.ts +0 -154
- package/src/index.ts +0 -2702
- package/src/intelligent-gateway.ts +0 -339
- package/src/mcp-analytics.ts +0 -156
- package/src/metered.ts +0 -149
- package/src/open-apis-generated.ts +0 -157
- package/src/open-apis.ts +0 -558
- package/src/postinstall.ts +0 -40
- package/src/product-whitelist.ts +0 -246
- package/src/proxy.ts +0 -36
- package/src/registration-guard.ts +0 -117
- package/src/session.ts +0 -129
- package/src/stripe.ts +0 -497
- package/src/telemetry.ts +0 -71
- package/src/test.ts +0 -135
- package/src/types/convex-api.d.ts +0 -20
- package/src/types/convex-api.ts +0 -21
- package/src/types.ts +0 -109
- package/src/ui/colors.ts +0 -219
- package/src/ui/errors.ts +0 -394
- package/src/ui/index.ts +0 -17
- package/src/ui/prompts.ts +0 -390
- package/src/ui/spinner.ts +0 -325
- package/src/utils/backup.ts +0 -224
- package/src/utils/config.ts +0 -318
- package/src/utils/os.ts +0 -124
- package/src/utils/paths.ts +0 -203
- package/src/webhook.ts +0 -107
- package/test-10-working.cjs +0 -97
- package/test-14-final.cjs +0 -96
- package/test-actual-handlers.ts +0 -92
- package/test-apilayer-all-14.ts +0 -249
- package/test-apilayer-fixed.ts +0 -248
- package/test-direct-endpoints.ts +0 -174
- package/test-exact-endpoints.ts +0 -144
- package/test-final.ts +0 -83
- package/test-full-routing.ts +0 -100
- package/test-handlers-correct.ts +0 -217
- package/test-numverify-key.ts +0 -41
- package/test-via-handlers.ts +0 -92
- package/test-worldnews.mjs +0 -26
- package/tsconfig.json +0 -20
package/convex/usageReports.ts
DELETED
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
import { v } from "convex/values";
|
|
2
|
-
import { internalAction, internalQuery } from "./_generated/server";
|
|
3
|
-
import { internal } from "./_generated/api";
|
|
4
|
-
|
|
5
|
-
const EMAIL_FROM = "APIClaw <noreply@apiclaw.cloud>";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Get usage data for a workspace over a date range
|
|
9
|
-
*/
|
|
10
|
-
export const getUsageForPeriod = internalQuery({
|
|
11
|
-
args: {
|
|
12
|
-
workspaceId: v.id("workspaces"),
|
|
13
|
-
startDate: v.string(), // "2026-04-01"
|
|
14
|
-
endDate: v.string(), // "2026-04-11"
|
|
15
|
-
},
|
|
16
|
-
handler: async (ctx, args) => {
|
|
17
|
-
const records = await ctx.db
|
|
18
|
-
.query("usageRecords")
|
|
19
|
-
.withIndex("by_workspaceId", (q) => q.eq("workspaceId", args.workspaceId))
|
|
20
|
-
.collect();
|
|
21
|
-
|
|
22
|
-
const periodRecords = records.filter(
|
|
23
|
-
(r) => r.date >= args.startDate && r.date <= args.endDate
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
const totalCalls = periodRecords.reduce((sum, r) => sum + r.callCount, 0);
|
|
27
|
-
const totalProviderCost = periodRecords.reduce((sum, r) => sum + (r.providerCostUsd || 0), 0);
|
|
28
|
-
const totalApiclawCost = periodRecords.reduce((sum, r) => sum + (r.apiclawCostUsd || 0), 0);
|
|
29
|
-
const margin = totalApiclawCost - totalProviderCost;
|
|
30
|
-
|
|
31
|
-
// Daily breakdown
|
|
32
|
-
const dailyBreakdown = periodRecords
|
|
33
|
-
.sort((a, b) => a.date.localeCompare(b.date))
|
|
34
|
-
.map((r) => ({
|
|
35
|
-
date: r.date,
|
|
36
|
-
calls: r.callCount,
|
|
37
|
-
providerCost: r.providerCostUsd || 0,
|
|
38
|
-
totalCost: r.apiclawCostUsd || 0,
|
|
39
|
-
}));
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
totalCalls,
|
|
43
|
-
totalProviderCost,
|
|
44
|
-
totalApiclawCost,
|
|
45
|
-
margin,
|
|
46
|
-
dailyBreakdown,
|
|
47
|
-
daysWithActivity: periodRecords.filter((r) => r.callCount > 0).length,
|
|
48
|
-
avgCallsPerDay: periodRecords.length > 0 ? totalCalls / periodRecords.length : 0,
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Get all workspaces with their emails for reporting
|
|
55
|
-
*/
|
|
56
|
-
export const getReportableWorkspaces = internalQuery({
|
|
57
|
-
args: {},
|
|
58
|
-
handler: async (ctx) => {
|
|
59
|
-
const workspaces = await ctx.db.query("workspaces").collect();
|
|
60
|
-
return workspaces
|
|
61
|
-
.filter((w) => w.email)
|
|
62
|
-
.map((w) => ({
|
|
63
|
-
id: w._id,
|
|
64
|
-
email: w.email,
|
|
65
|
-
tier: (w as any).tier || "free",
|
|
66
|
-
name: w.email?.split("@")[0] || "User",
|
|
67
|
-
}));
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Get API logs breakdown by provider/model for a workspace
|
|
73
|
-
*/
|
|
74
|
-
export const getProviderBreakdown = internalQuery({
|
|
75
|
-
args: {
|
|
76
|
-
workspaceId: v.string(),
|
|
77
|
-
startDate: v.number(), // timestamp ms
|
|
78
|
-
endDate: v.number(),
|
|
79
|
-
},
|
|
80
|
-
handler: async (ctx, args) => {
|
|
81
|
-
const logs = await ctx.db
|
|
82
|
-
.query("apiLogs")
|
|
83
|
-
.withIndex("by_workspaceId", (q) => q.eq("workspaceId", args.workspaceId as any))
|
|
84
|
-
.collect();
|
|
85
|
-
|
|
86
|
-
const periodLogs = logs.filter(
|
|
87
|
-
(l) => l.createdAt >= args.startDate && l.createdAt <= args.endDate
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
// Group by provider
|
|
91
|
-
const byProvider: Record<string, { calls: number; errors: number; avgLatency: number; latencies: number[] }> = {};
|
|
92
|
-
for (const log of periodLogs) {
|
|
93
|
-
const key = log.provider || "unknown";
|
|
94
|
-
if (!byProvider[key]) {
|
|
95
|
-
byProvider[key] = { calls: 0, errors: 0, avgLatency: 0, latencies: [] };
|
|
96
|
-
}
|
|
97
|
-
byProvider[key].calls += 1;
|
|
98
|
-
if (log.status === "error") byProvider[key].errors += 1;
|
|
99
|
-
if (log.latencyMs) byProvider[key].latencies.push(log.latencyMs);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Calculate avg latency
|
|
103
|
-
for (const key of Object.keys(byProvider)) {
|
|
104
|
-
const lats = byProvider[key].latencies;
|
|
105
|
-
byProvider[key].avgLatency = lats.length > 0
|
|
106
|
-
? Math.round(lats.reduce((a, b) => a + b, 0) / lats.length)
|
|
107
|
-
: 0;
|
|
108
|
-
delete (byProvider[key] as any).latencies;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return byProvider;
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Generate and send usage report for a single workspace
|
|
117
|
-
*/
|
|
118
|
-
export const sendUsageReport = internalAction({
|
|
119
|
-
args: {
|
|
120
|
-
workspaceId: v.id("workspaces"),
|
|
121
|
-
email: v.string(),
|
|
122
|
-
tier: v.string(),
|
|
123
|
-
name: v.string(),
|
|
124
|
-
period: v.union(v.literal("weekly"), v.literal("monthly")),
|
|
125
|
-
},
|
|
126
|
-
handler: async (ctx, args): Promise<{ success: boolean; calls?: number; error?: string }> => {
|
|
127
|
-
const RESEND_API_KEY = process.env.RESEND_API_KEY;
|
|
128
|
-
if (!RESEND_API_KEY) {
|
|
129
|
-
console.error("RESEND_API_KEY not configured");
|
|
130
|
-
return { success: false, error: "Email not configured" };
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Calculate date range
|
|
134
|
-
const now = new Date();
|
|
135
|
-
let startDate: string;
|
|
136
|
-
let endDate: string;
|
|
137
|
-
let periodLabel: string;
|
|
138
|
-
|
|
139
|
-
if (args.period === "weekly") {
|
|
140
|
-
const start = new Date(now);
|
|
141
|
-
start.setDate(start.getDate() - 7);
|
|
142
|
-
startDate = start.toISOString().split("T")[0];
|
|
143
|
-
endDate = now.toISOString().split("T")[0];
|
|
144
|
-
periodLabel = `${startDate} to ${endDate}`;
|
|
145
|
-
} else {
|
|
146
|
-
const start = new Date(now.getFullYear(), now.getMonth() - 1, 1);
|
|
147
|
-
const end = new Date(now.getFullYear(), now.getMonth(), 0);
|
|
148
|
-
startDate = start.toISOString().split("T")[0];
|
|
149
|
-
endDate = end.toISOString().split("T")[0];
|
|
150
|
-
periodLabel = start.toLocaleString("en", { month: "long", year: "numeric" });
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Get usage data
|
|
154
|
-
const usage: any = await ctx.runQuery(internal.usageReports.getUsageForPeriod, {
|
|
155
|
-
workspaceId: args.workspaceId,
|
|
156
|
-
startDate,
|
|
157
|
-
endDate,
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
// Get provider breakdown
|
|
161
|
-
const startMs = new Date(startDate).getTime();
|
|
162
|
-
const endMs = new Date(endDate + "T23:59:59Z").getTime();
|
|
163
|
-
const providers: any = await ctx.runQuery(internal.usageReports.getProviderBreakdown, {
|
|
164
|
-
workspaceId: args.workspaceId as string,
|
|
165
|
-
startDate: startMs,
|
|
166
|
-
endDate: endMs,
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
// Build email
|
|
170
|
-
const isFounder = args.tier === "founder" || args.tier === "partner";
|
|
171
|
-
const costLabel = isFounder ? "Provider cost (not billed)" : "Billed amount";
|
|
172
|
-
|
|
173
|
-
// Provider rows
|
|
174
|
-
let providerRows = "";
|
|
175
|
-
const sortedProviders: Array<[string, any]> = Object.entries(providers).sort((a: any, b: any) => b[1].calls - a[1].calls);
|
|
176
|
-
for (const [name, data] of sortedProviders) {
|
|
177
|
-
const successRate = data.calls > 0 ? Math.round(((data.calls - data.errors) / data.calls) * 100) : 0;
|
|
178
|
-
providerRows += `<tr>
|
|
179
|
-
<td style="padding:8px 12px;border-bottom:1px solid #f0f0f0;">${name}</td>
|
|
180
|
-
<td style="padding:8px 12px;border-bottom:1px solid #f0f0f0;text-align:right;">${data.calls}</td>
|
|
181
|
-
<td style="padding:8px 12px;border-bottom:1px solid #f0f0f0;text-align:right;">${successRate}%</td>
|
|
182
|
-
<td style="padding:8px 12px;border-bottom:1px solid #f0f0f0;text-align:right;">${data.avgLatency}ms</td>
|
|
183
|
-
</tr>`;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// Daily chart (simple text sparkline)
|
|
187
|
-
let dailyRows = "";
|
|
188
|
-
for (const day of usage.dailyBreakdown.slice(-7)) {
|
|
189
|
-
const bar = "█".repeat(Math.min(Math.ceil(day.calls / 5), 20)) || "░";
|
|
190
|
-
dailyRows += `<tr>
|
|
191
|
-
<td style="padding:4px 12px;border-bottom:1px solid #f5f5f5;font-size:13px;">${day.date}</td>
|
|
192
|
-
<td style="padding:4px 12px;border-bottom:1px solid #f5f5f5;text-align:right;font-size:13px;">${day.calls}</td>
|
|
193
|
-
<td style="padding:4px 12px;border-bottom:1px solid #f5f5f5;font-size:13px;color:#ef4444;font-family:monospace;">${bar}</td>
|
|
194
|
-
</tr>`;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const html: string = `<!DOCTYPE html>
|
|
198
|
-
<html><head><meta charset="utf-8"></head>
|
|
199
|
-
<body style="margin:0;padding:0;background:#fafafa;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;">
|
|
200
|
-
<table width="100%" cellpadding="0" cellspacing="0"><tr><td align="center" style="padding:40px 20px;">
|
|
201
|
-
<table width="600" cellpadding="0" cellspacing="0" style="background:white;border-radius:12px;overflow:hidden;box-shadow:0 1px 3px rgba(0,0,0,0.1);">
|
|
202
|
-
|
|
203
|
-
<!-- Header -->
|
|
204
|
-
<tr><td style="background:#1a1a1a;padding:32px 40px;">
|
|
205
|
-
<div style="font-size:24px;margin-bottom:4px;">🦞</div>
|
|
206
|
-
<h1 style="margin:0;color:white;font-size:20px;font-weight:600;">APIClaw ${args.period === "weekly" ? "Weekly" : "Monthly"} Report</h1>
|
|
207
|
-
<p style="margin:4px 0 0;color:#a3a3a3;font-size:14px;">${periodLabel}</p>
|
|
208
|
-
</td></tr>
|
|
209
|
-
|
|
210
|
-
<!-- Summary -->
|
|
211
|
-
<tr><td style="padding:32px 40px;">
|
|
212
|
-
<table width="100%" cellpadding="0" cellspacing="0">
|
|
213
|
-
<tr>
|
|
214
|
-
<td style="padding:16px;background:#f9fafb;border-radius:8px;text-align:center;width:33%;">
|
|
215
|
-
<div style="font-size:28px;font-weight:700;color:#1a1a1a;">${usage.totalCalls.toLocaleString()}</div>
|
|
216
|
-
<div style="font-size:12px;color:#737373;margin-top:4px;">API Calls</div>
|
|
217
|
-
</td>
|
|
218
|
-
<td width="12"></td>
|
|
219
|
-
<td style="padding:16px;background:#f9fafb;border-radius:8px;text-align:center;width:33%;">
|
|
220
|
-
<div style="font-size:28px;font-weight:700;color:#1a1a1a;">$${usage.totalProviderCost.toFixed(2)}</div>
|
|
221
|
-
<div style="font-size:12px;color:#737373;margin-top:4px;">Provider Cost</div>
|
|
222
|
-
</td>
|
|
223
|
-
<td width="12"></td>
|
|
224
|
-
<td style="padding:16px;background:#f9fafb;border-radius:8px;text-align:center;width:33%;">
|
|
225
|
-
<div style="font-size:28px;font-weight:700;color:${isFounder ? "#16a34a" : "#1a1a1a"};">${isFounder ? "$0.00" : "$" + usage.totalApiclawCost.toFixed(2)}</div>
|
|
226
|
-
<div style="font-size:12px;color:#737373;margin-top:4px;">${costLabel}</div>
|
|
227
|
-
</td>
|
|
228
|
-
</tr>
|
|
229
|
-
</table>
|
|
230
|
-
|
|
231
|
-
${isFounder ? `<p style="margin:16px 0 0;padding:12px 16px;background:#f0fdf4;border-radius:8px;color:#166534;font-size:13px;">Founder tier: unlimited calls, no billing. Provider cost shown for transparency.</p>` : ""}
|
|
232
|
-
|
|
233
|
-
<p style="margin:24px 0 8px;color:#525252;font-size:13px;">${usage.daysWithActivity} active days | ${Math.round(usage.avgCallsPerDay)} avg calls/day</p>
|
|
234
|
-
</td></tr>
|
|
235
|
-
|
|
236
|
-
<!-- Provider Breakdown -->
|
|
237
|
-
${sortedProviders.length > 0 ? `
|
|
238
|
-
<tr><td style="padding:0 40px 24px;">
|
|
239
|
-
<h2 style="margin:0 0 12px;font-size:16px;color:#1a1a1a;">By Provider</h2>
|
|
240
|
-
<table width="100%" cellpadding="0" cellspacing="0" style="border:1px solid #e5e5e5;border-radius:8px;overflow:hidden;">
|
|
241
|
-
<tr style="background:#f9fafb;">
|
|
242
|
-
<th style="padding:10px 12px;text-align:left;font-size:12px;color:#737373;font-weight:600;">Provider</th>
|
|
243
|
-
<th style="padding:10px 12px;text-align:right;font-size:12px;color:#737373;font-weight:600;">Calls</th>
|
|
244
|
-
<th style="padding:10px 12px;text-align:right;font-size:12px;color:#737373;font-weight:600;">Success</th>
|
|
245
|
-
<th style="padding:10px 12px;text-align:right;font-size:12px;color:#737373;font-weight:600;">Avg Latency</th>
|
|
246
|
-
</tr>
|
|
247
|
-
${providerRows}
|
|
248
|
-
</table>
|
|
249
|
-
</td></tr>` : ""}
|
|
250
|
-
|
|
251
|
-
<!-- Daily Activity -->
|
|
252
|
-
${dailyRows ? `
|
|
253
|
-
<tr><td style="padding:0 40px 32px;">
|
|
254
|
-
<h2 style="margin:0 0 12px;font-size:16px;color:#1a1a1a;">Daily Activity</h2>
|
|
255
|
-
<table width="100%" cellpadding="0" cellspacing="0" style="border:1px solid #e5e5e5;border-radius:8px;overflow:hidden;">
|
|
256
|
-
<tr style="background:#f9fafb;">
|
|
257
|
-
<th style="padding:8px 12px;text-align:left;font-size:12px;color:#737373;">Date</th>
|
|
258
|
-
<th style="padding:8px 12px;text-align:right;font-size:12px;color:#737373;">Calls</th>
|
|
259
|
-
<th style="padding:8px 12px;text-align:left;font-size:12px;color:#737373;">Volume</th>
|
|
260
|
-
</tr>
|
|
261
|
-
${dailyRows}
|
|
262
|
-
</table>
|
|
263
|
-
</td></tr>` : ""}
|
|
264
|
-
|
|
265
|
-
<!-- Footer -->
|
|
266
|
-
<tr><td style="padding:24px 40px;background:#f9fafb;border-top:1px solid #e5e5e5;">
|
|
267
|
-
<p style="margin:0;font-size:12px;color:#a3a3a3;">APIClaw - The API Layer for AI Agents</p>
|
|
268
|
-
<p style="margin:4px 0 0;font-size:12px;color:#a3a3a3;"><a href="https://apiclaw.cloud/workspace" style="color:#ef4444;text-decoration:none;">View workspace</a></p>
|
|
269
|
-
</td></tr>
|
|
270
|
-
|
|
271
|
-
</table>
|
|
272
|
-
</td></tr></table></body></html>`;
|
|
273
|
-
|
|
274
|
-
const subject: string = args.period === "weekly"
|
|
275
|
-
? `APIClaw Weekly: ${usage.totalCalls} calls | $${usage.totalProviderCost.toFixed(2)} provider cost`
|
|
276
|
-
: `APIClaw ${periodLabel}: ${usage.totalCalls} calls | $${usage.totalProviderCost.toFixed(2)} provider cost`;
|
|
277
|
-
|
|
278
|
-
const response: Response = await fetch("https://api.resend.com/emails", {
|
|
279
|
-
method: "POST",
|
|
280
|
-
headers: {
|
|
281
|
-
"Authorization": "Bearer " + RESEND_API_KEY,
|
|
282
|
-
"Content-Type": "application/json",
|
|
283
|
-
},
|
|
284
|
-
body: JSON.stringify({
|
|
285
|
-
from: EMAIL_FROM,
|
|
286
|
-
to: args.email,
|
|
287
|
-
subject,
|
|
288
|
-
html,
|
|
289
|
-
}),
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
if (!response.ok) {
|
|
293
|
-
const errorText: string = await response.text();
|
|
294
|
-
console.error("Failed to send usage report:", errorText);
|
|
295
|
-
return { success: false, error: errorText };
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
console.log(`Sent ${args.period} report to ${args.email}: ${usage.totalCalls} calls`);
|
|
299
|
-
return { success: true, calls: usage.totalCalls };
|
|
300
|
-
},
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Send weekly reports to all workspaces with activity
|
|
305
|
-
*/
|
|
306
|
-
export const sendWeeklyReports = internalAction({
|
|
307
|
-
args: {},
|
|
308
|
-
handler: async (ctx) => {
|
|
309
|
-
const workspaces = await ctx.runQuery(internal.usageReports.getReportableWorkspaces, {});
|
|
310
|
-
|
|
311
|
-
let sent = 0;
|
|
312
|
-
for (const ws of workspaces) {
|
|
313
|
-
try {
|
|
314
|
-
const result = await ctx.runAction(internal.usageReports.sendUsageReport, {
|
|
315
|
-
workspaceId: ws.id,
|
|
316
|
-
email: ws.email,
|
|
317
|
-
tier: ws.tier,
|
|
318
|
-
name: ws.name,
|
|
319
|
-
period: "weekly",
|
|
320
|
-
});
|
|
321
|
-
if (result.success && (result as any).calls > 0) sent++;
|
|
322
|
-
} catch (e: any) {
|
|
323
|
-
console.error(`Failed to send weekly report to ${ws.email}:`, e.message);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
console.log(`[Cron] Sent ${sent} weekly reports`);
|
|
328
|
-
},
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Send monthly reports to all workspaces
|
|
333
|
-
*/
|
|
334
|
-
export const sendMonthlyReports = internalAction({
|
|
335
|
-
args: {},
|
|
336
|
-
handler: async (ctx) => {
|
|
337
|
-
const workspaces = await ctx.runQuery(internal.usageReports.getReportableWorkspaces, {});
|
|
338
|
-
|
|
339
|
-
let sent = 0;
|
|
340
|
-
for (const ws of workspaces) {
|
|
341
|
-
try {
|
|
342
|
-
const result = await ctx.runAction(internal.usageReports.sendUsageReport, {
|
|
343
|
-
workspaceId: ws.id,
|
|
344
|
-
email: ws.email,
|
|
345
|
-
tier: ws.tier,
|
|
346
|
-
name: ws.name,
|
|
347
|
-
period: "monthly",
|
|
348
|
-
});
|
|
349
|
-
if (result.success) sent++;
|
|
350
|
-
} catch (e: any) {
|
|
351
|
-
console.error(`Failed to send monthly report to ${ws.email}:`, e.message);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
console.log(`[Cron] Sent ${sent} monthly reports`);
|
|
356
|
-
},
|
|
357
|
-
});
|
package/convex/waitlist.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { mutation, query } from "./_generated/server";
|
|
2
|
-
import { v } from "convex/values";
|
|
3
|
-
|
|
4
|
-
export const join = mutation({
|
|
5
|
-
args: {
|
|
6
|
-
email: v.string(),
|
|
7
|
-
type: v.optional(v.string()),
|
|
8
|
-
source: v.optional(v.string()),
|
|
9
|
-
},
|
|
10
|
-
handler: async (ctx, args) => {
|
|
11
|
-
const email = args.email.toLowerCase().trim();
|
|
12
|
-
|
|
13
|
-
// Check if already on waitlist
|
|
14
|
-
const existing = await ctx.db
|
|
15
|
-
.query("waitlist")
|
|
16
|
-
.withIndex("by_email", (q) => q.eq("email", email))
|
|
17
|
-
.first();
|
|
18
|
-
|
|
19
|
-
if (existing) {
|
|
20
|
-
return { success: true, alreadyExists: true };
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
await ctx.db.insert("waitlist", {
|
|
24
|
-
email,
|
|
25
|
-
type: args.type || "provider",
|
|
26
|
-
source: args.source || "landing",
|
|
27
|
-
createdAt: Date.now(),
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return { success: true, alreadyExists: false };
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
export const count = query({
|
|
35
|
-
args: {},
|
|
36
|
-
handler: async (ctx) => {
|
|
37
|
-
const all = await ctx.db.query("waitlist").collect();
|
|
38
|
-
return all.length;
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
export const list = query({
|
|
43
|
-
args: {
|
|
44
|
-
type: v.optional(v.string()),
|
|
45
|
-
},
|
|
46
|
-
handler: async (ctx, args) => {
|
|
47
|
-
if (args.type) {
|
|
48
|
-
return await ctx.db
|
|
49
|
-
.query("waitlist")
|
|
50
|
-
.withIndex("by_type", (q) => q.eq("type", args.type!))
|
|
51
|
-
.collect();
|
|
52
|
-
}
|
|
53
|
-
return await ctx.db.query("waitlist").collect();
|
|
54
|
-
},
|
|
55
|
-
});
|